Added wxDataViewListCtrl, use it in the sample
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58136 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -959,11 +959,6 @@ public:
|
|||||||
void DeleteItem( unsigned pos );
|
void DeleteItem( unsigned pos );
|
||||||
void DeleteAllItems();
|
void DeleteAllItems();
|
||||||
|
|
||||||
void SetStringValue( const wxString &value, unsigned int row, unsigned int col )
|
|
||||||
{ SetValueByRow( value, row, col ); }
|
|
||||||
wxString GetStringValue( unsigned int row, unsigned int col )
|
|
||||||
{ wxVariant value; GetValueByRow( value, row, col ); return value.GetString(); }
|
|
||||||
|
|
||||||
// override base virtuals
|
// override base virtuals
|
||||||
|
|
||||||
virtual unsigned int GetColumnCount() const;
|
virtual unsigned int GetColumnCount() const;
|
||||||
@@ -982,6 +977,75 @@ public:
|
|||||||
wxArrayString m_cols;
|
wxArrayString m_cols;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class WXDLLIMPEXP_ADV wxDataViewListCtrl: public wxDataViewCtrl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxDataViewListCtrl();
|
||||||
|
wxDataViewListCtrl( wxWindow *parent, wxWindowID id,
|
||||||
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize, long style = wxDV_ROW_LINES,
|
||||||
|
const wxValidator& validator = wxDefaultValidator );
|
||||||
|
~wxDataViewListCtrl();
|
||||||
|
|
||||||
|
bool Create( wxWindow *parent, wxWindowID id,
|
||||||
|
const wxPoint& pos = wxDefaultPosition,
|
||||||
|
const wxSize& size = wxDefaultSize, long style = wxDV_ROW_LINES,
|
||||||
|
const wxValidator& validator = wxDefaultValidator );
|
||||||
|
|
||||||
|
wxDataViewListStore *GetStore()
|
||||||
|
{ return (wxDataViewListStore*) GetModel(); }
|
||||||
|
const wxDataViewListStore *GetStore() const
|
||||||
|
{ return (const wxDataViewListStore*) GetModel(); }
|
||||||
|
|
||||||
|
void AppendCol( wxDataViewColumn *column, const wxString &varianttype );
|
||||||
|
void PrependCol( wxDataViewColumn *column, const wxString &varianttype );
|
||||||
|
void InsertCol( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype );
|
||||||
|
|
||||||
|
wxDataViewColumn *AppendTextCol( const wxString &label,
|
||||||
|
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
|
||||||
|
int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
|
||||||
|
wxDataViewColumn *AppendToggleCol( const wxString &label,
|
||||||
|
wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
|
||||||
|
int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
|
||||||
|
wxDataViewColumn *AppendProgressCol( const wxString &label,
|
||||||
|
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
|
||||||
|
int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
|
||||||
|
wxDataViewColumn *AppendIconTextCol( const wxString &label,
|
||||||
|
wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
|
||||||
|
int width = -1, wxAlignment align = wxALIGN_LEFT, int flags = wxDATAVIEW_COL_RESIZABLE );
|
||||||
|
|
||||||
|
void AppendItem( const wxVector<wxVariant> &values, wxClientData *data = NULL )
|
||||||
|
{ GetStore()->AppendItem( values, data ); }
|
||||||
|
void PrependItem( const wxVector<wxVariant> &values, wxClientData *data = NULL )
|
||||||
|
{ GetStore()->PrependItem( values, data ); }
|
||||||
|
void InsertItem( unsigned int row, const wxVector<wxVariant> &values, wxClientData *data = NULL )
|
||||||
|
{ GetStore()->InsertItem( row, values, data ); }
|
||||||
|
void DeleteItem( unsigned row )
|
||||||
|
{ GetStore()->DeleteItem( row ); }
|
||||||
|
void DeleteAllItems()
|
||||||
|
{ GetStore()->DeleteAllItems(); }
|
||||||
|
|
||||||
|
void SetValue( const wxVariant &value, unsigned int row, unsigned int col )
|
||||||
|
{ GetStore()->SetValueByRow( value, row, col ); }
|
||||||
|
|
||||||
|
void SetTextValue( const wxString &value, unsigned int row, unsigned int col )
|
||||||
|
{ GetStore()->SetValueByRow( value, row, col ); }
|
||||||
|
wxString GetTextValue( unsigned int row, unsigned int col ) const
|
||||||
|
{ wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetString(); }
|
||||||
|
|
||||||
|
void SetToggleValue( bool value, unsigned int row, unsigned int col )
|
||||||
|
{ GetStore()->SetValueByRow( value, row, col ); }
|
||||||
|
bool GetToggleValue( unsigned int row, unsigned int col ) const
|
||||||
|
{ wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetBool(); }
|
||||||
|
|
||||||
|
void OnSize( wxSizeEvent &event );
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_EVENT_TABLE()
|
||||||
|
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewListCtrl)
|
||||||
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxDataViewTreeStore
|
// wxDataViewTreeStore
|
||||||
@@ -1127,6 +1191,8 @@ public:
|
|||||||
wxDataViewTreeStoreNode *m_root;
|
wxDataViewTreeStoreNode *m_root;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl
|
class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@@ -331,7 +331,7 @@ public:
|
|||||||
MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
|
MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
|
||||||
|
|
||||||
// "MyMusic" also has no parent
|
// "MyMusic" also has no parent
|
||||||
if (node == m_root || node == NULL)
|
if (node == m_root)
|
||||||
return wxDataViewItem(0);
|
return wxDataViewItem(0);
|
||||||
|
|
||||||
return wxDataViewItem( (void*) node->GetParent() );
|
return wxDataViewItem( (void*) node->GetParent() );
|
||||||
@@ -409,7 +409,7 @@ public:
|
|||||||
memcpy( dest, buffer, strlen(buffer)+1 );
|
memcpy( dest, buffer, strlen(buffer)+1 );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataViewItem GetNinthItem()
|
wxDataViewItem GetNinthItem()
|
||||||
{
|
{
|
||||||
return wxDataViewItem( m_ninth );
|
return wxDataViewItem( m_ninth );
|
||||||
@@ -819,7 +819,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
|
|||||||
|
|
||||||
SetMenuBar(menu_bar);
|
SetMenuBar(menu_bar);
|
||||||
CreateStatusBar();
|
CreateStatusBar();
|
||||||
|
|
||||||
wxPanel *panel = new wxPanel( this, -1 );
|
wxPanel *panel = new wxPanel( this, -1 );
|
||||||
|
|
||||||
wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
|
wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
|
||||||
@@ -921,24 +921,26 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
|
|||||||
|
|
||||||
bottom_sizer->Add( m_log, 1, wxGROW );
|
bottom_sizer->Add( m_log, 1, wxGROW );
|
||||||
|
|
||||||
#if 1
|
// wxDataViewListCtrl
|
||||||
// wxDataViewTreeStore
|
|
||||||
|
wxDataViewListCtrl *listctrl = new wxDataViewListCtrl( panel, -1,
|
||||||
wxDataViewCtrl *treectrl = new wxDataViewCtrl( panel, -1,
|
wxDefaultPosition, wxSize(100,200) );
|
||||||
wxDefaultPosition, wxSize(100,200), wxDV_NO_HEADER );
|
|
||||||
|
listctrl->AppendToggleCol( wxT("Toggle") );
|
||||||
wxDataViewTreeStore *store = new wxDataViewTreeStore;
|
listctrl->AppendTextCol( wxT("Text") );
|
||||||
wxDataViewItem parent = store->AppendContainer( wxDataViewItem(0),wxT("Root 1"), wxIcon(small1_xpm) );
|
|
||||||
wxDataViewItem child = store->AppendItem( parent,wxT("Child 1"), wxIcon(small1_xpm) );
|
wxVector<wxVariant> data;
|
||||||
child = store->AppendItem( parent,wxT("Child 2"), wxIcon(small1_xpm) );
|
data.push_back( true );
|
||||||
child = store->AppendItem( parent,wxT("Child 3, very long, long, long, long"), wxIcon(small1_xpm) );
|
data.push_back( "row 1" );
|
||||||
treectrl->AssociateModel( store );
|
listctrl->AppendItem( data );
|
||||||
store->DecRef();
|
|
||||||
|
data.clear();
|
||||||
treectrl->AppendIconTextColumn( wxT("no label"), 0, wxDATAVIEW_CELL_INERT, -1, (wxAlignment) 0,
|
data.push_back( false );
|
||||||
wxDATAVIEW_COL_RESIZABLE );
|
data.push_back( "row 3" );
|
||||||
|
listctrl->AppendItem( data );
|
||||||
bottom_sizer->Add( treectrl, 1 );
|
|
||||||
|
bottom_sizer->Add( listctrl, 1 );
|
||||||
|
|
||||||
|
|
||||||
// wxDataViewTreeCtrl
|
// wxDataViewTreeCtrl
|
||||||
|
|
||||||
@@ -948,13 +950,12 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
|
|||||||
ilist->Add( wxIcon(small1_xpm) );
|
ilist->Add( wxIcon(small1_xpm) );
|
||||||
treectrl2->SetImageList( ilist );
|
treectrl2->SetImageList( ilist );
|
||||||
|
|
||||||
parent = treectrl2->AppendContainer( wxDataViewItem(0),wxT("Root 1"), 0 );
|
wxDataViewItem parent2 = treectrl2->AppendContainer( wxDataViewItem(0),wxT("Root 1"), 0 );
|
||||||
child = treectrl2->AppendItem( parent,wxT("Child 1"), 0 );
|
wxDataViewItem child2 = treectrl2->AppendItem( parent2, wxT("Child 1"), 0 );
|
||||||
child = treectrl2->AppendItem( parent,wxT("Child 2"), 0 );
|
child2 = treectrl2->AppendItem( parent2, wxT("Child 2"), 0 );
|
||||||
child = treectrl2->AppendItem( parent,wxT("Child 3, very long, long, long, long"), 0 );
|
child2 = treectrl2->AppendItem( parent2, wxT("Child 3, very long, long, long, long"), 0 );
|
||||||
|
|
||||||
bottom_sizer->Add( treectrl2, 1 );
|
bottom_sizer->Add( treectrl2, 1 );
|
||||||
#endif
|
|
||||||
|
|
||||||
// main sizer
|
// main sizer
|
||||||
|
|
||||||
@@ -1026,7 +1027,7 @@ void MyFrame::OnActivated( wxDataViewEvent &event )
|
|||||||
|
|
||||||
wxString title = m_music_model->GetTitle( event.GetItem() );
|
wxString title = m_music_model->GetTitle( event.GetItem() );
|
||||||
wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item: %s"), title );
|
wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item: %s"), title );
|
||||||
|
|
||||||
if (m_musicCtrl->IsExpanded( event.GetItem() ))
|
if (m_musicCtrl->IsExpanded( event.GetItem() ))
|
||||||
wxLogMessage(wxT("Item: %s is expanded"), title );
|
wxLogMessage(wxT("Item: %s is expanded"), title );
|
||||||
}
|
}
|
||||||
|
@@ -1458,6 +1458,94 @@ bool wxDataViewListStore::SetValueByRow( const wxVariant &value, unsigned int ro
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// wxDataViewListCtrl
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl,wxDataViewCtrl)
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(wxDataViewListCtrl,wxDataViewCtrl)
|
||||||
|
EVT_SIZE( wxDataViewListCtrl::OnSize )
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
wxDataViewListCtrl::wxDataViewListCtrl()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDataViewListCtrl::wxDataViewListCtrl( wxWindow *parent, wxWindowID id,
|
||||||
|
const wxPoint& pos, const wxSize& size, long style,
|
||||||
|
const wxValidator& validator )
|
||||||
|
{
|
||||||
|
Create( parent, id, pos, size, style, validator );
|
||||||
|
|
||||||
|
wxDataViewListStore *store = new wxDataViewListStore;
|
||||||
|
AssociateModel( store );
|
||||||
|
store->DecRef();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDataViewListCtrl::~wxDataViewListCtrl()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool wxDataViewListCtrl::Create( wxWindow *parent, wxWindowID id,
|
||||||
|
const wxPoint& pos, const wxSize& size, long style,
|
||||||
|
const wxValidator& validator )
|
||||||
|
{
|
||||||
|
return wxDataViewCtrl::Create( parent, id, pos, size, style, validator );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewListCtrl::AppendCol( wxDataViewColumn *column, const wxString &varianttype )
|
||||||
|
{
|
||||||
|
GetStore()->AppendColumn( varianttype );
|
||||||
|
AppendColumn( column );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewListCtrl::PrependCol( wxDataViewColumn *column, const wxString &varianttype )
|
||||||
|
{
|
||||||
|
GetStore()->PrependColumn( varianttype );
|
||||||
|
PrependColumn( column );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewListCtrl::InsertCol( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype )
|
||||||
|
{
|
||||||
|
GetStore()->InsertColumn( pos, varianttype );
|
||||||
|
InsertColumn( pos, column );
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDataViewColumn *wxDataViewListCtrl::AppendTextCol( const wxString &label,
|
||||||
|
wxDataViewCellMode mode, int width, wxAlignment align, int flags )
|
||||||
|
{
|
||||||
|
GetStore()->AppendColumn( wxT("string") );
|
||||||
|
return AppendTextColumn( label, GetStore()->GetColumnCount()-1, mode, width, align, flags );
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDataViewColumn *wxDataViewListCtrl::AppendToggleCol( const wxString &label,
|
||||||
|
wxDataViewCellMode mode, int width, wxAlignment align, int flags )
|
||||||
|
{
|
||||||
|
GetStore()->AppendColumn( wxT("bool") );
|
||||||
|
return AppendToggleColumn( label, GetStore()->GetColumnCount()-1, mode, width, align, flags );
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDataViewColumn *wxDataViewListCtrl::AppendProgressCol( const wxString &label,
|
||||||
|
wxDataViewCellMode mode, int width, wxAlignment align, int flags )
|
||||||
|
{
|
||||||
|
GetStore()->AppendColumn( wxT("long") );
|
||||||
|
return AppendProgressColumn( label, GetStore()->GetColumnCount()-1, mode, width, align, flags );
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDataViewColumn *wxDataViewListCtrl::AppendIconTextCol( const wxString &label,
|
||||||
|
wxDataViewCellMode mode, int width, wxAlignment align, int flags )
|
||||||
|
{
|
||||||
|
GetStore()->AppendColumn( wxT("wxDataViewIconText") );
|
||||||
|
return AppendIconTextColumn( label, GetStore()->GetColumnCount()-1, mode, width, align, flags );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewListCtrl::OnSize( wxSizeEvent &event )
|
||||||
|
{
|
||||||
|
event.Skip( true );
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxDataViewTreeStore
|
// wxDataViewTreeStore
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user