X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/abd6692ca8b91b072068bf3e1f80e68afb62fe53..bacd54f604fe87c622d4ab57070759ad6f1791a7:/samples/dataview/dataview.cpp?ds=inline diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index a58827d5de..be407a5b51 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -20,6 +20,8 @@ #include "wx/wx.h" #endif +#include "wx/datetime.h" + #ifndef __WXMSW__ #include "mondrian.xpm" #endif @@ -37,7 +39,7 @@ WX_DEFINE_LIST(wxArrayDate); class MyTextModel: public wxDataViewListModel { public: - MyTextModel() + MyTextModel() { size_t i; for (i = 0; i < 1000; i++) @@ -49,59 +51,59 @@ public: for (i = 0; i < 1000; i++) { m_progress.Add( i/10 ); } for (i = 0; i < 1000; i++) - { + { wxDateTime *date = new wxDateTime( wxDateTime::Now() ); - m_dates.Append( date ); + m_dates.Append( date ); } } - - virtual size_t GetNumberOfRows() + + virtual size_t GetNumberOfRows() { return 1000; } virtual size_t GetNumberOfCols() { return 7; } - + // as reported by wxVariant virtual wxString GetColType( size_t col ) { if (col == 6) return wxT("datetime"); - + if (col == 5) return wxT("long"); - + if (col == 3) return wxT("bool"); - - return wxT("string"); + + return wxT("string"); } - - virtual wxVariant GetValue( size_t col, size_t row ) + + virtual void GetValue( wxVariant &variant, size_t col, size_t row ) { if (col == 6) { - return (wxDateTime) *m_dates[row]; + variant = (wxDateTime) *m_dates[row]; } else if (col == 5) { - return (long) m_progress[row]; + variant = (long) m_progress[row]; } else if (col == 4) { - return m_colours[row]; + variant = m_colours[row]; } else if (col == 3) { - return (bool) m_bools[row]; - } else + variant = (bool) m_bools[row]; + } else if (col == 2) { - return m_list[row]; + variant = m_list[row]; } else { - wxString tmp; - tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col ); - return tmp; + wxString tmp; + tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col ); + variant = tmp; } } virtual bool SetValue( wxVariant &value, size_t col, size_t row ) @@ -120,7 +122,7 @@ public: } return true; } - + wxArrayString m_list; wxArrayInt m_bools; wxArrayString m_colours; @@ -136,23 +138,23 @@ class MyCustomCell: public wxDataViewCustomCell { public: MyCustomCell() : - wxDataViewCustomCell( wxT("string"), wxDATAVIEW_CELL_ACTIVATABLE ) - { - m_colour = wxT("black"); + wxDataViewCustomCell( wxT("string"), wxDATAVIEW_CELL_ACTIVATABLE ) + { + m_colour = wxT("black"); } bool SetValue( const wxVariant &value ) { m_colour = value.GetString(); return true; } - bool Render( wxRect rect, wxDC *dc, int state ) - { + bool Render( wxRect rect, wxDC *dc, int WXUNUSED(state) ) + { dc->SetPen( *wxBLACK_PEN ); if (m_colour == wxT("red")) dc->SetBrush( *wxRED_BRUSH ); else if (m_colour == wxT("green")) dc->SetBrush( *wxGREEN_BRUSH ); - else + else dc->SetBrush( *wxBLACK_BRUSH ); dc->DrawRectangle( rect ); return true; @@ -161,14 +163,16 @@ public: { return wxSize(20,8); } - bool Activate( wxRect rect, - wxDataViewListModel *model, size_t col, size_t row ) + bool Activate( wxRect WXUNUSED(rect), + wxDataViewListModel *WXUNUSED(model), + size_t WXUNUSED(col), + size_t WXUNUSED(row) ) { return false; } private: - wxString m_colour; + wxString m_colour; }; // ------------------------------------- @@ -191,14 +195,17 @@ public: virtual size_t GetNumberOfRows() { return m_list.GetCount(); } virtual size_t GetNumberOfCols() { return 2; } - virtual wxString GetColType( size_t col ) { return wxT("string"); } - virtual wxVariant GetValue( size_t col, size_t row ) + virtual wxString GetColType( size_t WXUNUSED(col) ) { return wxT("string"); } + virtual void GetValue( wxVariant &variant, size_t col, size_t row ) { if (col == 0) - return m_list[row]; + { + variant = m_list[row]; + return; + } wxString tmp; - tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col ); - return tmp; + tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col ); + variant = tmp; } virtual bool SetValue( wxVariant &variant, size_t col, size_t row ) { @@ -208,7 +215,7 @@ public: return true; } return false; - + } wxArrayString m_list; @@ -236,7 +243,7 @@ public: public: void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); - + private: wxDataViewCtrl* dataview_left; wxDataViewCtrl* dataview_right; @@ -253,7 +260,7 @@ enum my_events ID_INSERT_ROW_LEFT, ID_DELETE_ROW_LEFT, ID_EDIT_ROW_LEFT, - + ID_APPEND_ROW_RIGHT, ID_PREPEND_ROW_RIGHT, ID_INSERT_ROW_RIGHT, @@ -269,23 +276,23 @@ public: public: void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); - + void OnAppendRowLeft(wxCommandEvent& event); void OnPrependRowLeft(wxCommandEvent& event); void OnInsertRowLeft(wxCommandEvent& event); void OnDeleteRowLeft(wxCommandEvent& event); void OnEditRowLeft(wxCommandEvent& event); - + void OnAppendRowRight(wxCommandEvent& event); void OnPrependRowRight(wxCommandEvent& event); void OnInsertRowRight(wxCommandEvent& event); void OnDeleteRowRight(wxCommandEvent& event); void OnEditRowRight(wxCommandEvent& event); - + private: wxDataViewCtrl* dataview_left; wxDataViewCtrl* dataview_right; - + DECLARE_EVENT_TABLE() }; @@ -339,33 +346,35 @@ MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h): wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnAbout) ); CreateStatusBar(); - - + + wxPanel *panel = new wxPanel( this, -1 ); + + // Left wxDataViewCtrl - dataview_left = new wxDataViewCtrl( this, -1 ); - + dataview_left = new wxDataViewCtrl( panel, wxID_ANY ); + MyTextModel *model = new MyTextModel; dataview_left->AssociateModel( model ); - + dataview_left->AppendTextColumn( wxT("first"), 0 ); dataview_left->AppendTextColumn( wxT("second"), 1 ); wxDataViewTextCell *text_cell = new wxDataViewTextCell( wxT("string"), wxDATAVIEW_CELL_EDITABLE ); wxDataViewColumn *column = new wxDataViewColumn( wxT("editable"), text_cell, 2 ); dataview_left->AppendColumn( column ); - + dataview_left->AppendToggleColumn( wxT("fourth"), 3 ); - + MyCustomCell *custom_cell = new MyCustomCell; column = new wxDataViewColumn( wxT("custom"), custom_cell, 4 ); dataview_left->AppendColumn( column ); - + dataview_left->AppendProgressColumn( wxT("progress"), 5 ); - + dataview_left->AppendDateColumn( wxT("date"), 6 ); - + // Right wxDataViewCtrl using the same model - dataview_right = new wxDataViewCtrl( this, -1 ); + dataview_right = new wxDataViewCtrl( panel, wxID_ANY ); dataview_right->AssociateModel( model ); text_cell = new wxDataViewTextCell( wxT("string"), wxDATAVIEW_CELL_EDITABLE ); @@ -373,19 +382,19 @@ MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h): dataview_right->AppendColumn( column ); dataview_right->AppendTextColumn( wxT("first"), 0 ); dataview_right->AppendTextColumn( wxT("second"), 1 ); - wxDataViewToggleCell *toggle_cell = new wxDataViewToggleCell( wxT("bool"), wxDATAVIEW_CELL_EDITABLE ); - column = new wxDataViewColumn( wxT("bool"), toggle_cell, 3 ); + wxDataViewToggleCell *toggle_cell = new wxDataViewToggleCell( wxT("bool"), wxDATAVIEW_CELL_ACTIVATABLE ); + column = new wxDataViewColumn( wxT("bool"), toggle_cell, 3, 30 ); dataview_right->AppendColumn( column ); dataview_right->AppendDateColumn( wxT("date"), 6 ); - + // layout dataview controls. - + wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL ); sizer->Add( dataview_left, 3, wxGROW ); sizer->Add(10,10); sizer->Add( dataview_right, 2, wxGROW ); - SetSizer( sizer ); + panel->SetSizer( sizer ); } void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) ) @@ -433,10 +442,10 @@ MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MySortingFrame::OnAbout) ); CreateStatusBar(); - - + + // Left wxDataViewCtrl - dataview_left = new wxDataViewCtrl( this, -1 ); + dataview_left = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_MULTIPLE ); MyUnsortedTextModel *model = new MyUnsortedTextModel; dataview_left->AssociateModel( model ); @@ -444,10 +453,10 @@ MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int wxDataViewColumn *column = new wxDataViewColumn( wxT("editable"), text_cell, 0 ); dataview_left->AppendColumn( column ); dataview_left->AppendTextColumn( wxT("second"), 1 ); - + // Right wxDataViewCtrl using the sorting model - dataview_right = new wxDataViewCtrl( this, -1 ); - wxDataViewSortedListModel *sorted_model = + dataview_right = new wxDataViewCtrl( this, wxID_ANY ); + wxDataViewSortedListModel *sorted_model = new wxDataViewSortedListModel( model ); dataview_right->AssociateModel( sorted_model ); text_cell = new wxDataViewTextCell( wxT("string"), wxDATAVIEW_CELL_EDITABLE ); @@ -456,12 +465,12 @@ MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int dataview_right->AppendTextColumn( wxT("second"), 1 ); // layout dataview controls. - + wxBoxSizer *top_sizer = new wxBoxSizer( wxHORIZONTAL ); top_sizer->Add( dataview_left, 1, wxGROW ); top_sizer->Add(10,10); top_sizer->Add( dataview_right, 1, wxGROW ); - + wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL ); button_sizer->Add( 10, 10, 1 ); wxFlexGridSizer *left_sizer = new wxFlexGridSizer( 2 ); @@ -480,11 +489,11 @@ MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int right_sizer->Add( new wxButton( this, ID_EDIT_ROW_RIGHT, wxT("Edit") ), 0, wxALL, 5 ); button_sizer->Add( right_sizer ); button_sizer->Add( 10, 10, 1 ); - + wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL ); main_sizer->Add( top_sizer, 1, wxGROW ); main_sizer->Add( button_sizer, 0, wxGROW ); - + SetSizer( main_sizer ); } @@ -501,43 +510,43 @@ void MySortingFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) dialog.ShowModal(); } -void MySortingFrame::OnAppendRowLeft(wxCommandEvent& event) +void MySortingFrame::OnAppendRowLeft(wxCommandEvent& WXUNUSED(event)) { } -void MySortingFrame::OnPrependRowLeft(wxCommandEvent& event) +void MySortingFrame::OnPrependRowLeft(wxCommandEvent& WXUNUSED(event)) { } -void MySortingFrame::OnInsertRowLeft(wxCommandEvent& event) +void MySortingFrame::OnInsertRowLeft(wxCommandEvent& WXUNUSED(event)) { } -void MySortingFrame::OnDeleteRowLeft(wxCommandEvent& event) +void MySortingFrame::OnDeleteRowLeft(wxCommandEvent& WXUNUSED(event)) { } -void MySortingFrame::OnEditRowLeft(wxCommandEvent& event) +void MySortingFrame::OnEditRowLeft(wxCommandEvent& WXUNUSED(event)) { } -void MySortingFrame::OnAppendRowRight(wxCommandEvent& event) +void MySortingFrame::OnAppendRowRight(wxCommandEvent& WXUNUSED(event)) { } -void MySortingFrame::OnPrependRowRight(wxCommandEvent& event) +void MySortingFrame::OnPrependRowRight(wxCommandEvent& WXUNUSED(event)) { } -void MySortingFrame::OnInsertRowRight(wxCommandEvent& event) +void MySortingFrame::OnInsertRowRight(wxCommandEvent& WXUNUSED(event)) { } -void MySortingFrame::OnDeleteRowRight(wxCommandEvent& event) +void MySortingFrame::OnDeleteRowRight(wxCommandEvent& WXUNUSED(event)) { } -void MySortingFrame::OnEditRowRight(wxCommandEvent& event) +void MySortingFrame::OnEditRowRight(wxCommandEvent& WXUNUSED(event)) { }