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:
Robert Roebling
2009-01-16 15:04:00 +00:00
parent b619c109e6
commit dc813e6c7e
3 changed files with 187 additions and 32 deletions

View File

@@ -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:

View File

@@ -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() );
@@ -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
wxDataViewCtrl *treectrl = new wxDataViewCtrl( panel, -1, wxDataViewListCtrl *listctrl = new wxDataViewListCtrl( panel, -1,
wxDefaultPosition, wxSize(100,200), wxDV_NO_HEADER ); wxDefaultPosition, wxSize(100,200) );
wxDataViewTreeStore *store = new wxDataViewTreeStore; listctrl->AppendToggleCol( wxT("Toggle") );
wxDataViewItem parent = store->AppendContainer( wxDataViewItem(0),wxT("Root 1"), wxIcon(small1_xpm) ); listctrl->AppendTextCol( wxT("Text") );
wxDataViewItem child = store->AppendItem( parent,wxT("Child 1"), wxIcon(small1_xpm) );
child = store->AppendItem( parent,wxT("Child 2"), wxIcon(small1_xpm) );
child = store->AppendItem( parent,wxT("Child 3, very long, long, long, long"), wxIcon(small1_xpm) );
treectrl->AssociateModel( store );
store->DecRef();
treectrl->AppendIconTextColumn( wxT("no label"), 0, wxDATAVIEW_CELL_INERT, -1, (wxAlignment) 0, wxVector<wxVariant> data;
wxDATAVIEW_COL_RESIZABLE ); data.push_back( true );
data.push_back( "row 1" );
listctrl->AppendItem( data );
data.clear();
data.push_back( false );
data.push_back( "row 3" );
listctrl->AppendItem( data );
bottom_sizer->Add( listctrl, 1 );
bottom_sizer->Add( treectrl, 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

View File

@@ -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
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------