X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a400d56be15766ffa9d0eec0eff87d9109d2d4a6..66034aba2e3aecd6f1af6803d44befe611191399:/samples/dataview/dataview.cpp diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index f1df8ceeb8..fe45436b30 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -74,15 +74,15 @@ static const char *small1_xpm[] = { /* Implement this data model - Title Artist Year -------------------------------------------------------------- + Title Artist Year Judgement +-------------------------------------------------------------------------- 1: My Music: 2: Pop music - 3: You are not alone Michael Jackson 1995 - 4: Take a bow Madonna 1994 + 3: You are not alone Michael Jackson 1995 good + 4: Take a bow Madonna 1994 good 5: Classical music - 6: Ninth Symphony Ludwig v. Beethoven 1824 - 7: German Requiem Johannes Brahms 1868 + 6: Ninth Symphony Ludwig v. Beethoven 1824 good + 7: German Requiem Johannes Brahms 1868 good */ @@ -100,6 +100,7 @@ public: m_title = title; m_artist = artist; m_year = year; + m_quality = "good"; m_isContainer = false; } @@ -136,6 +137,7 @@ public: wxString m_title; wxString m_artist; int m_year; + wxString m_quality; private: MyMusicModelNode *m_parent; @@ -255,7 +257,7 @@ public: virtual unsigned int GetColumnCount() const { - return 5; + return 6; } virtual wxString GetColumnType( unsigned int col ) const @@ -275,14 +277,15 @@ public: case 0: variant = node->m_title; break; case 1: variant = node->m_artist; break; case 2: variant = (long) node->m_year; break; - case 3: + case 3: variant = node->m_quality; break; + case 4: // wxMac doesn't conceal the popularity progress renderer, return 0 for containers if (IsContainer(item)) variant = (long) 0; else variant = (long) 80; // all music is very 80% popular break; - case 4: + case 5: // Make size of red square depend on year if (GetYear(item) < 1900) variant = (long) 35; @@ -313,6 +316,7 @@ public: case 0: node->m_title = variant.GetString(); return true; case 1: node->m_artist = variant.GetString(); return true; case 2: node->m_year = variant.GetLong(); return true; + case 3: node->m_quality = variant.GetString(); return true; default: wxLogError( wxT("MyMusicModel::SetValue: wrong column") ); } return false; @@ -626,7 +630,8 @@ public: virtual wxSize GetSize() const { - return wxSize(60,m_height); + //return wxSize(60,m_height); + return wxSize(60,20); } virtual bool SetValue( const wxVariant &value ) @@ -814,6 +819,8 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int SetMenuBar(menu_bar); CreateStatusBar(); + + wxPanel *panel = new wxPanel( this, -1 ); wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL ); @@ -821,47 +828,55 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int // MyMusic - m_musicCtrl = new wxDataViewCtrl( this, ID_MUSIC_CTRL, wxDefaultPosition, - wxDefaultSize, wxDV_MULTIPLE|wxDV_VARIABLE_LINE_HEIGHT ); + m_musicCtrl = new wxDataViewCtrl( panel, ID_MUSIC_CTRL, wxDefaultPosition, + wxSize(400,200), wxDV_MULTIPLE|wxDV_VARIABLE_LINE_HEIGHT ); m_music_model = new MyMusicModel; m_musicCtrl->AssociateModel( m_music_model.get() ); wxDataViewTextRenderer *tr = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_INERT ); wxDataViewColumn *column0 = new wxDataViewColumn( wxT("title"), tr, 0, 200, wxALIGN_LEFT, - wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE ); + wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_RESIZABLE ); m_musicCtrl->AppendColumn( column0 ); #if 0 // Call this and sorting is enabled // immediatly upon start up. - column0->SetSortOrder( true ); + column0->SetAsSortKey(); #endif tr = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE ); - wxDataViewColumn *column1 = new wxDataViewColumn( wxT("artist"), tr, 1, 150, wxALIGN_RIGHT, + wxDataViewColumn *column1 = new wxDataViewColumn( wxT("artist"), tr, 1, 150, wxALIGN_LEFT, wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE ); + column1->SetMinWidth(150); // this column can't be resized to be smaller m_musicCtrl->AppendColumn( column1 ); wxDataViewSpinRenderer *sr = new wxDataViewSpinRenderer( 0, 2010, wxDATAVIEW_CELL_EDITABLE, wxALIGN_RIGHT ); - wxDataViewColumn *column2 = new wxDataViewColumn( wxT("year"), sr, 2, 80, wxALIGN_LEFT, - wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE ); + wxDataViewColumn *column2 = new wxDataViewColumn( wxT("year"), sr, 2, 60, wxALIGN_LEFT, + wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE ); m_musicCtrl->AppendColumn( column2 ); - m_musicCtrl->AppendProgressColumn( wxT("popularity"), 3, wxDATAVIEW_CELL_INERT, 80 ); + wxArrayString choices; + choices.Add( "good" ); + choices.Add( "bad" ); + choices.Add( "lousy" ); + wxDataViewChoiceRenderer *c = new wxDataViewChoiceRenderer( choices, wxDATAVIEW_CELL_EDITABLE, wxALIGN_RIGHT ); + wxDataViewColumn *column3 = new wxDataViewColumn( wxT("rating"), c, 3, 100, wxALIGN_LEFT, + wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE ); + m_musicCtrl->AppendColumn( column3 ); + + m_musicCtrl->AppendProgressColumn( wxT("popularity"), 4, wxDATAVIEW_CELL_INERT, 80 ); MyCustomRenderer *cr = new MyCustomRenderer( wxDATAVIEW_CELL_ACTIVATABLE, wxALIGN_RIGHT ); - wxDataViewColumn *column3 = new wxDataViewColumn( wxT("custom"), cr, 4, -1, wxALIGN_LEFT, + wxDataViewColumn *column4 = new wxDataViewColumn( wxT("custom"), cr, 5, -1, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE ); - m_musicCtrl->AppendColumn( column3 ); + m_musicCtrl->AppendColumn( column4 ); data_sizer->Add( m_musicCtrl, 3, wxGROW ); -#if 1 - // MyList - m_listCtrl = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, - wxDefaultSize, wxDV_MULTIPLE | wxDV_ROW_LINES); + m_listCtrl = new wxDataViewCtrl( panel, wxID_ANY, wxDefaultPosition, + wxSize(400,200), wxDV_MULTIPLE | wxDV_ROW_LINES); m_list_model = new MyListModel; m_listCtrl->AssociateModel( m_list_model.get() ); @@ -875,42 +890,41 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int #endif wxDataViewTextRendererAttr *ra = new wxDataViewTextRendererAttr; - wxDataViewColumn *column4 = new wxDataViewColumn(wxT("attributes"), ra, 2 ); - m_listCtrl->AppendColumn( column4 ); + wxDataViewColumn *column5 = new wxDataViewColumn(wxT("attributes"), ra, 2 ); + m_listCtrl->AppendColumn( column5 ); data_sizer->Add( m_listCtrl, 2, wxGROW ); -#endif - main_sizer->Add( data_sizer, 2, wxGROW ); wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL ); - button_sizer->Add( new wxButton( this, ID_ADD_MOZART, _("Add Mozart")), 0, wxALL, 10 ); - button_sizer->Add( new wxButton( this, ID_DELETE_MUSIC,_("Delete selected")), 0, wxALL, 10 ); - button_sizer->Add( new wxButton( this, ID_DELETE_YEAR, _("Delete \"Year\" column")), 0, wxALL, 10 ); - button_sizer->Add( new wxButton( this, ID_SELECT_NINTH, _("Select Ninth")), 0, wxALL, 10 ); + button_sizer->Add( new wxButton( panel, ID_ADD_MOZART, _("Add Mozart")), 0, wxALL, 10 ); + button_sizer->Add( new wxButton( panel, ID_DELETE_MUSIC,_("Delete selected")), 0, wxALL, 10 ); + button_sizer->Add( new wxButton( panel, ID_DELETE_YEAR, _("Delete \"Year\" column")), 0, wxALL, 10 ); + button_sizer->Add( new wxButton( panel, ID_SELECT_NINTH, _("Select Ninth")), 0, wxALL, 10 ); button_sizer->Add( 10, 10, 1 ); wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 2 ); - grid_sizer->Add( new wxButton( this, ID_PREPEND_LIST,_("Prepend")), 0, wxALL, 2 ); - grid_sizer->Add( new wxButton( this, ID_DELETE_LIST, _("Delete selected")), 0, wxALL, 2 ); - grid_sizer->Add( new wxButton( this, ID_GOTO, _("Goto 50")), 0, wxALL, 2 ); - grid_sizer->Add( new wxButton( this, ID_ADD_MANY, _("Add 1000")), 0, wxALL, 2 ); + grid_sizer->Add( new wxButton( panel, ID_PREPEND_LIST,_("Prepend")), 0, wxALL, 2 ); + grid_sizer->Add( new wxButton( panel, ID_DELETE_LIST, _("Delete selected")), 0, wxALL, 2 ); + grid_sizer->Add( new wxButton( panel, ID_GOTO, _("Goto 50")), 0, wxALL, 2 ); + grid_sizer->Add( new wxButton( panel, ID_ADD_MANY, _("Add 1000")), 0, wxALL, 2 ); button_sizer->Add( grid_sizer, 0, wxALL, 10 ); main_sizer->Add( button_sizer, 0, wxGROW, 0 ); wxBoxSizer *bottom_sizer = new wxBoxSizer( wxHORIZONTAL ); - m_log = new wxTextCtrl( this, -1, wxString(), wxDefaultPosition, wxSize(100,200), wxTE_MULTILINE ); + m_log = new wxTextCtrl( panel, -1, wxString(), wxDefaultPosition, wxSize(100,200), wxTE_MULTILINE ); m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_log)); wxLogMessage(_("This is the log window")); bottom_sizer->Add( m_log, 1, wxGROW ); +#if 1 // wxDataViewTreeStore - wxDataViewCtrl *treectrl = new wxDataViewCtrl( this, -1, + wxDataViewCtrl *treectrl = new wxDataViewCtrl( panel, -1, wxDefaultPosition, wxSize(100,200), wxDV_NO_HEADER ); wxDataViewTreeStore *store = new wxDataViewTreeStore; @@ -928,7 +942,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int // wxDataViewTreeCtrl - wxDataViewTreeCtrl *treectrl2 = new wxDataViewTreeCtrl( this, -1, wxDefaultPosition, wxSize(100,200) ); + wxDataViewTreeCtrl *treectrl2 = new wxDataViewTreeCtrl( panel, -1, wxDefaultPosition, wxSize(100,200) ); wxImageList *ilist = new wxImageList( 16, 16 ); ilist->Add( wxIcon(small1_xpm) ); @@ -940,12 +954,13 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int child = treectrl2->AppendItem( parent,wxT("Child 3, very long, long, long, long"), 0 ); bottom_sizer->Add( treectrl2, 1 ); +#endif // main sizer main_sizer->Add( bottom_sizer, 0, wxGROW ); - SetSizer( main_sizer ); + panel->SetSizer( main_sizer ); } MyFrame::~MyFrame() @@ -1010,7 +1025,10 @@ void MyFrame::OnActivated( wxDataViewEvent &event ) return; wxString title = m_music_model->GetTitle( event.GetItem() ); - wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item: %s"), title.GetData()); + wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item: %s"), title ); + + if (m_musicCtrl->IsExpanded( event.GetItem() )) + wxLogMessage(wxT("Item: %s is expanded"), title ); } void MyFrame::OnSelectionChanged( wxDataViewEvent &event ) @@ -1022,7 +1040,7 @@ void MyFrame::OnSelectionChanged( wxDataViewEvent &event ) if (title.empty()) title = wxT("None"); - wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, First selected Item: %s"), title.GetData() ); + wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, First selected Item: %s"), title ); } void MyFrame::OnExpanding( wxDataViewEvent &event ) @@ -1031,7 +1049,7 @@ void MyFrame::OnExpanding( wxDataViewEvent &event ) return; wxString title = m_music_model->GetTitle( event.GetItem() ); - wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, Item: %s"), title.GetData() ); + wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, Item: %s"), title ); } @@ -1041,7 +1059,7 @@ void MyFrame::OnEditingStarted( wxDataViewEvent &event ) return; wxString title = m_music_model->GetTitle( event.GetItem() ); - wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, Item: %s"), title.GetData() ); + wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, Item: %s"), title ); } void MyFrame::OnEditingDone( wxDataViewEvent &event ) @@ -1050,7 +1068,7 @@ void MyFrame::OnEditingDone( wxDataViewEvent &event ) return; wxString title = m_music_model->GetTitle( event.GetItem() ); - wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, Item: %s"), title.GetData() ); + wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, Item: %s"), title ); } void MyFrame::OnExpanded( wxDataViewEvent &event ) @@ -1059,7 +1077,7 @@ void MyFrame::OnExpanded( wxDataViewEvent &event ) return; wxString title = m_music_model->GetTitle( event.GetItem() ); - wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, Item: %s"), title.GetData() ); + wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, Item: %s"), title ); } void MyFrame::OnCollapsing( wxDataViewEvent &event ) @@ -1068,7 +1086,7 @@ void MyFrame::OnCollapsing( wxDataViewEvent &event ) return; wxString title = m_music_model->GetTitle( event.GetItem() ); - wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, Item: %s"), title.GetData() ); + wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, Item: %s"), title ); } void MyFrame::OnCollapsed( wxDataViewEvent &event ) @@ -1077,7 +1095,7 @@ void MyFrame::OnCollapsed( wxDataViewEvent &event ) return; wxString title = m_music_model->GetTitle( event.GetItem() ); - wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, Item: %s"),title.GetData()); + wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, Item: %s"),title); } void MyFrame::OnContextMenu( wxDataViewEvent &event ) @@ -1086,7 +1104,7 @@ void MyFrame::OnContextMenu( wxDataViewEvent &event ) return; wxString title = m_music_model->GetTitle( event.GetItem() ); - wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s"),title.GetData()); + wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s"),title ); wxMenu menu; menu.Append( 1, wxT("entry 1") ); @@ -1100,6 +1118,10 @@ void MyFrame::OnContextMenu( wxDataViewEvent &event ) void MyFrame::OnHeaderClick( wxDataViewEvent &event ) { + // we need to skip the event to let the default behaviour of sorting by + // this column when it is clicked to take place + event.Skip(); + if(!m_log) return;