X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b89cac3f09e84f94bea292a8534feda3830ecfb1..35bb3cb155917b4287fb2a3841bea22919a3d499:/samples/dataview/dataview.cpp diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index e560e6d58d..62077163fa 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -39,64 +39,6 @@ #define DATAVIEW_DEFAULT_STYLE (wxDV_MULTIPLE|wxDV_HORIZ_RULES|wxDV_VERT_RULES) -// ------------------------------------- -// MySpinCtrlInPlaceRenderer -// ------------------------------------- - -class MySpinCtrlInPlaceRenderer: public wxDataViewCustomRenderer -{ -public: - MySpinCtrlInPlaceRenderer() : - wxDataViewCustomRenderer( wxT("long"), wxDATAVIEW_CELL_EDITABLE ) { } - - - virtual bool HasEditorCtrl() - { - return true; - } - virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ) - { - long l = value; - return new wxSpinCtrl( parent, wxID_ANY, wxEmptyString, - labelRect.GetTopLeft(), labelRect.GetSize(), -0, -1, 2010, l ); - } - virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ) - { - wxSpinCtrl *sc = (wxSpinCtrl*) editor; - long l = sc->GetValue(); - value = l; - return true; - } - - bool Render( wxRect rect, wxDC *dc, int WXUNUSED(state) ) - { - wxString str; - str.Printf( wxT("%d"), (int) m_data ); - dc->SetTextForeground( *wxBLACK ); - dc->DrawText( str, rect.x, rect.y ); - return true; - } - wxSize GetSize() const - { - return wxSize(80,16); - } - bool SetValue( const wxVariant &value ) - { - m_data = value.GetLong(); - return true; - } - bool GetValue( wxVariant &value ) const - { - value = m_data; - return true; - } - -private: - long m_data; -}; - - - // ------------------------------------- // MyMusicModel // ------------------------------------- @@ -444,14 +386,28 @@ public: { wxDataViewIconText data( "test", m_icon ); variant << data; - } - else + } else + if (col==2) { - wxString str; - str.Printf( "row %d col %d", row, col ); - variant = str; + if ((row % 2) == 1) + variant = "Blue"; + else + variant = "Italic"; } } + + virtual bool GetAttr( unsigned int row, unsigned int col, wxDataViewItemAttr &attr ) + { + if (col != 2) + return false; + + if ((row % 2) == 1) + attr.SetColour( *wxBLUE ); + else + attr.SetItalic( true ); + + return true; + } virtual bool SetValue( const wxVariant &variant, unsigned int row, unsigned int col ) @@ -497,6 +453,7 @@ public: void OnAddMozart(wxCommandEvent& event); void OnDeleteMusic(wxCommandEvent& event); + void OnDeleteYear(wxCommandEvent& event); void OnPrependList(wxCommandEvent& event); void OnDeleteList(wxCommandEvent& event); @@ -578,6 +535,7 @@ enum ID_ADD_MOZART = 100, ID_DELETE_MUSIC = 101, + ID_DELETE_YEAR = 102, ID_PREPEND_LIST = 200, ID_DELETE_LIST = 201, @@ -590,6 +548,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU( ID_EXIT, MyFrame::OnQuit ) EVT_BUTTON( ID_ADD_MOZART, MyFrame::OnAddMozart ) EVT_BUTTON( ID_DELETE_MUSIC, MyFrame::OnDeleteMusic ) + EVT_BUTTON( ID_DELETE_YEAR, MyFrame::OnDeleteYear ) EVT_BUTTON( ID_PREPEND_LIST, MyFrame::OnPrependList ) EVT_BUTTON( ID_DELETE_LIST, MyFrame::OnDeleteList ) EVT_BUTTON( ID_GOTO, MyFrame::OnGoto) @@ -648,7 +607,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int m_music_model = new MyMusicModel; m_musicCtrl->AssociateModel( m_music_model.get() ); - wxDataViewColumn *col = m_musicCtrl->AppendTextColumn( "Title", 0, wxDATAVIEW_CELL_INERT, 200, + /* wxDataViewColumn *col = */ m_musicCtrl->AppendTextColumn( "Title", 0, wxDATAVIEW_CELL_INERT, 200, DEFAULT_ALIGN, wxDATAVIEW_COL_SORTABLE ); #if 0 // Call this and sorting is enabled @@ -659,7 +618,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int m_musicCtrl->AppendTextColumn( "Artist", 1, wxDATAVIEW_CELL_EDITABLE, 150, DEFAULT_ALIGN, wxDATAVIEW_COL_SORTABLE ); - MySpinCtrlInPlaceRenderer *sr = new MySpinCtrlInPlaceRenderer; + wxDataViewSpinRenderer *sr = new wxDataViewSpinRenderer( 0, 2010 ); wxDataViewColumn *column = new wxDataViewColumn( "year", sr, 2, -1, wxALIGN_CENTRE, wxDATAVIEW_COL_SORTABLE ); m_musicCtrl->AppendColumn( column ); @@ -677,7 +636,10 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int m_listCtrl->AppendTextColumn( "editable string", 0, wxDATAVIEW_CELL_EDITABLE, 120 ); m_listCtrl->AppendIconTextColumn( "icon", 1, wxDATAVIEW_CELL_INERT, 60 ); - m_listCtrl->AppendTextColumn( "index", 2, wxDATAVIEW_CELL_INERT, 120 ); + + wxDataViewTextRendererAttr *ra = new wxDataViewTextRendererAttr; + column = new wxDataViewColumn( "attributes", ra, 2 ); + m_listCtrl->AppendColumn( column ); data_sizer->Add( m_listCtrl, 2, wxGROW ); @@ -689,6 +651,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int 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( 10, 10, 1 ); button_sizer->Add( new wxButton( this, ID_PREPEND_LIST, "Prepend"), 0, wxALL, 10 ); button_sizer->Add( new wxButton( this, ID_DELETE_LIST, "Delete selected"), 0, wxALL, 10 ); @@ -712,7 +675,7 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) ) /* XPM */ -static char *small1_xpm[] = { +static const char *small1_xpm[] = { /* columns rows colors chars-per-pixel */ "16 16 6 1", ". c Black", @@ -748,20 +711,20 @@ void MyFrame::OnTestTreeCtrl(wxCommandEvent& WXUNUSED(event) ) wxDataViewCtrl *treectrl = new wxDataViewCtrl( &dialog, -1, wxDefaultPosition, wxSize(300,200), wxDV_NO_HEADER ); - treectrl->AppendIconTextColumn( "no label", 0, wxDATAVIEW_CELL_INERT, 200 ); - main_sizer->Add( treectrl, 1, wxGROW ); - wxDataViewTreeStore *store = new wxDataViewTreeStore; wxDataViewItem parent = store->AppendContainer( wxDataViewItem(0), "Root 1", wxIcon(small1_xpm) ); wxDataViewItem child = store->AppendItem( parent, "Child 1", wxIcon(small1_xpm) ); child = store->AppendItem( parent, "Child 2", wxIcon(small1_xpm) ); child = store->AppendItem( parent, "Child 3", wxIcon(small1_xpm) ); - treectrl->AssociateModel( store ); - store->DecRef(); + treectrl->AppendIconTextColumn( "no label", 0, wxDATAVIEW_CELL_INERT, 200 ); + + main_sizer->Add( treectrl, 1, wxGROW ); + + wxSizer *button_sizer = dialog.CreateButtonSizer( wxOK ); if (button_sizer) main_sizer->Add( button_sizer, 0, wxGROW|wxALL, 10 ); @@ -786,6 +749,12 @@ void MyFrame::OnDeleteMusic(wxCommandEvent& WXUNUSED(event) ) m_music_model->Delete( items[i] ); } +void MyFrame::OnDeleteYear( wxCommandEvent& WXUNUSED(event) ) +{ + m_musicCtrl->DeleteColumn( m_musicCtrl->GetColumn( 2 ) ); + FindWindow( ID_DELETE_YEAR )->Disable(); +} + void MyFrame::OnPrependList( wxCommandEvent& WXUNUSED(event) ) { m_list_model->Prepend( "Test" ); @@ -922,7 +891,7 @@ void MyFrame::OnRightClick( wxMouseEvent &event ) wxLogMessage("wxEVT_MOUSE_RIGHT_UP, Click Point is X: %d, Y: %d", event.GetX(), event.GetY()); } -void MyFrame::OnGoto( wxCommandEvent &event) +void MyFrame::OnGoto(wxCommandEvent& WXUNUSED(event)) { wxDataViewItem item = m_list_model->GetItem( 50 ); m_listCtrl->EnsureVisible(item,m_col);