X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0fdc2321bc8a1ccf967c26b656b207cae9d03925..c7e4ff14979261fc37380c7fbfae837eaffb6c71:/samples/dataview/dataview.cpp diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index c66602fa80..0f96a10c0d 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -17,11 +17,13 @@ #endif #ifndef WX_PRECOMP -#include "wx/wx.h" + #include "wx/wx.h" #endif +#include "wx/datetime.h" + #ifndef __WXMSW__ -#include "mondrian.xpm" + #include "../sample.xpm" #endif #include "wx/dataview.h" @@ -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,32 +51,32 @@ 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 void GetValue( wxVariant &variant, size_t col, size_t row ) { if (col == 6) @@ -92,15 +94,15 @@ public: if (col == 3) { variant = (bool) m_bools[row]; - } else + } else if (col == 2) { variant = m_list[row]; } else { - wxString tmp; - tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col ); + wxString tmp; + tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col ); variant = tmp; } } @@ -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,7 +195,7 @@ 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 wxString GetColType( size_t WXUNUSED(col) ) { return wxT("string"); } virtual void GetValue( wxVariant &variant, size_t col, size_t row ) { if (col == 0) @@ -200,7 +204,7 @@ public: return; } wxString tmp; - tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col ); + tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col ); variant = tmp; } virtual bool SetValue( wxVariant &variant, size_t col, size_t row ) @@ -211,7 +215,7 @@ public: return true; } return false; - + } wxArrayString m_list; @@ -239,7 +243,7 @@ public: public: void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); - + private: wxDataViewCtrl* dataview_left; wxDataViewCtrl* dataview_right; @@ -256,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, @@ -272,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() }; @@ -321,11 +325,7 @@ bool MyApp::OnInit(void) MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h): wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)) { -#ifdef __WXMSW__ - SetIcon(wxIcon(_T("mondrian"))); -#else - SetIcon(wxIcon(mondrian_xpm)); -#endif + SetIcon(wxICON(sample)); wxMenu *file_menu = new wxMenu; @@ -342,33 +342,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, wxID_ANY ); + + // 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 ); @@ -377,18 +379,18 @@ MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h): dataview_right->AppendTextColumn( wxT("first"), 0 ); dataview_right->AppendTextColumn( wxT("second"), 1 ); wxDataViewToggleCell *toggle_cell = new wxDataViewToggleCell( wxT("bool"), wxDATAVIEW_CELL_ACTIVATABLE ); - column = new wxDataViewColumn( wxT("bool"), toggle_cell, 3 ); + 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) ) @@ -415,11 +417,7 @@ END_EVENT_TABLE() MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h): wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)) { -#ifdef __WXMSW__ - SetIcon(wxIcon(_T("mondrian"))); -#else - SetIcon(wxIcon(mondrian_xpm)); -#endif + SetIcon(wxICON(sample)); wxMenu *file_menu = new wxMenu; @@ -436,10 +434,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 ); @@ -447,10 +445,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 ); @@ -459,12 +457,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 ); @@ -483,11 +481,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 ); } @@ -504,43 +502,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)) { }