wxDataViewCtrl can show tree/list music sample.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47154 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2007-07-05 19:55:00 +00:00
parent d2505ba254
commit fc5eacdb48
2 changed files with 20 additions and 26 deletions

View File

@@ -65,7 +65,7 @@ public:
virtual unsigned int GetColumnCount() const virtual unsigned int GetColumnCount() const
{ {
return 2; return 3;
} }
virtual wxString GetColumnType( unsigned int col ) const virtual wxString GetColumnType( unsigned int col ) const
@@ -76,19 +76,20 @@ public:
virtual void GetValue( wxVariant &variant, virtual void GetValue( wxVariant &variant,
const wxDataViewItem &item, unsigned int col ) const const wxDataViewItem &item, unsigned int col ) const
{ {
variant = wxString("");
int ID = item.GetID(); int ID = item.GetID();
switch (ID) switch (ID)
{ {
case 1: variant = "My Music"; break; case 1: if (col == 0) variant = wxString("My Music"); break;
case 2: variant = "Pop music"; break; case 2: if (col == 0) variant = wxString("Pop music"); break;
case 5: variant = "Classical music"; break; case 5: if (col == 0) variant = wxString("Classical music"); break;
case 3: case 3:
{ {
switch (col) switch (col)
{ {
case 0: variant = "You are not alone"; break; case 0: variant = wxString("You are not alone"); break;
case 1: variant = "Michael Jackson"; break; case 1: variant = wxString("Michael Jackson"); break;
case 2: variant = "1995"; case 2: variant = wxString("1995");
} }
} }
break; break;
@@ -96,9 +97,9 @@ public:
{ {
switch (col) switch (col)
{ {
case 0: variant = "Take a bow"; break; case 0: variant = wxString("Take a bow"); break;
case 1: variant = "Madonna"; break; case 1: variant = wxString("Madonna"); break;
case 2: variant = "1994"; case 2: variant = wxString("1994");
} }
} }
break; break;
@@ -106,9 +107,9 @@ public:
{ {
switch (col) switch (col)
{ {
case 0: variant = "Ninth symphony"; break; case 0: variant = wxString("Ninth symphony"); break;
case 1: variant = "Ludwig v. Beethoven"; break; case 1: variant = wxString("Ludwig v. Beethoven"); break;
case 2: variant = "1824"; case 2: variant = wxString("1824");
} }
} }
break; break;
@@ -116,9 +117,9 @@ public:
{ {
switch (col) switch (col)
{ {
case 0: variant = "German requiem"; break; case 0: variant = wxString("German requiem"); break;
case 1: variant = "Johannes Brahms"; break; case 1: variant = wxString("Johannes Brahms"); break;
case 2: variant = "1868"; case 2: variant = wxString("1868");
} }
} }
break; break;
@@ -324,11 +325,11 @@ MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
wxObjectDataPtr<MyMusicModel> model(new MyMusicModel); wxObjectDataPtr<MyMusicModel> model(new MyMusicModel);
m_dataview->AssociateModel( model.get() ); m_dataview->AssociateModel( model.get() );
m_dataview->AppendTextColumn( "Title", 0, wxDATAVIEW_CELL_INERT, -1, m_dataview->AppendTextColumn( "Title", 0, wxDATAVIEW_CELL_INERT, 200,
DEFAULT_ALIGN ); DEFAULT_ALIGN );
m_dataview->AppendTextColumn( "Artist", 1, wxDATAVIEW_CELL_INERT, -1, m_dataview->AppendTextColumn( "Artist", 1, wxDATAVIEW_CELL_INERT, 200,
DEFAULT_ALIGN ); DEFAULT_ALIGN );
m_dataview->AppendTextColumn( "Year", 1, wxDATAVIEW_CELL_INERT, -1, m_dataview->AppendTextColumn( "Year", 2, wxDATAVIEW_CELL_INERT, 50,
DEFAULT_ALIGN ); DEFAULT_ALIGN );
} }

View File

@@ -267,21 +267,14 @@ wxgtk_tree_model_get_iter (GtkTreeModel *tree_model,
wxDataViewItem item; wxDataViewItem item;
wxPrintf( "get_iter depth: %d\n", depth );
int i; int i;
for (i = 0; i < depth; i++) for (i = 0; i < depth; i++)
{ {
gint pos = gtk_tree_path_get_indices (path)[i]; gint pos = gtk_tree_path_get_indices (path)[i];
item = model->GetNthChild( item, (unsigned int) pos ); item = model->GetNthChild( item, (unsigned int) pos );
wxPrintf( "pos %d\n", pos );
if (!item.IsOk()) if (!item.IsOk())
{
wxPrintf( "wrong item from path\n" );
return FALSE; return FALSE;
}
} }
iter->stamp = wxtree_model->stamp; iter->stamp = wxtree_model->stamp;