]> git.saurik.com Git - wxWidgets.git/blob - samples/dataview/dataview.cpp
WinCE build fix.
[wxWidgets.git] / samples / dataview / dataview.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dataview.cpp
3 // Purpose: DataVewCtrl wxWidgets sample
4 // Author: Robert Roebling
5 // Modified by:
6 // Created: 06/01/06
7 // RCS-ID: $Id$
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/wx.h"
21 #endif
22
23 #include "wx/datetime.h"
24
25 #ifndef __WXMSW__
26 #include "../sample.xpm"
27 #endif
28
29 #include "null.xpm"
30
31 #include "wx/dataview.h"
32
33 // -------------------------------------
34 // MyTextModel
35 // -------------------------------------
36
37 WX_DECLARE_LIST(wxDateTime,wxArrayDate);
38 #include <wx/listimpl.cpp>
39 WX_DEFINE_LIST(wxArrayDate)
40
41 class MyTextModel: public wxDataViewListModel
42 {
43 public:
44 MyTextModel()
45 {
46 unsigned int i;
47 for (i = 0; i < 1000; i++)
48 m_list.Add( wxT("Test") );
49 for (i = 0; i < 500; i++)
50 { m_bools.Add( 0 ); m_bools.Add( 1 ); }
51 for (i = 0; i < 500; i++)
52 { m_colours.Add( wxT("red") ); m_colours.Add( wxT("green") ); }
53 for (i = 0; i < 1000; i++)
54 { m_progress.Add( i/10 ); }
55 for (i = 0; i < 1000; i++)
56 {
57 wxDateTime *date = new wxDateTime( wxDateTime::Now() );
58 m_dates.Append( date );
59 }
60 }
61
62 virtual unsigned int GetNumberOfRows()
63 { return 1000; }
64 virtual unsigned int GetNumberOfCols()
65 { return 7; }
66
67 // as reported by wxVariant
68 virtual wxString GetColType( unsigned int col )
69 {
70 if (col == 6)
71 return wxT("datetime");
72
73 if (col == 5)
74 return wxT("long");
75
76 if (col == 3)
77 return wxT("bool");
78
79 return wxT("string");
80 }
81
82 virtual void GetValue( wxVariant &variant, unsigned int col, unsigned int row )
83 {
84 if (col == 6)
85 {
86 variant = (wxDateTime) *m_dates[row];
87 } else
88 if (col == 5)
89 {
90 variant = (long) m_progress[row];
91 } else
92 if (col == 4)
93 {
94 variant = m_colours[row];
95 } else
96 if (col == 3)
97 {
98 variant = (bool) m_bools[row];
99 } else
100 if (col == 2)
101 {
102 variant = m_list[row];
103 }
104 else
105 {
106 wxString tmp;
107 tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col );
108 variant = tmp;
109 }
110 }
111 virtual bool SetValue( wxVariant &value, unsigned int col, unsigned int row )
112 {
113 if (col == 6)
114 {
115 *m_dates[row] = value.GetDateTime();
116 } else
117 if (col == 3)
118 {
119 m_bools[row] = (int) value.GetBool();
120 } else
121 if (col == 2)
122 {
123 m_list[row] = value.GetString();
124 }
125 return true;
126 }
127
128 wxArrayString m_list;
129 wxArrayInt m_bools;
130 wxArrayString m_colours;
131 wxArrayInt m_progress;
132 wxArrayDate m_dates;
133 };
134
135 // -------------------------------------
136 // MyCustomRenderer
137 // -------------------------------------
138
139 class MyCustomRenderer: public wxDataViewCustomRenderer
140 {
141 public:
142 MyCustomRenderer() :
143 wxDataViewCustomRenderer( wxT("string"), wxDATAVIEW_CELL_ACTIVATABLE )
144 {
145 m_colour = wxT("black");
146 }
147 bool SetValue( const wxVariant &value )
148 {
149 m_colour = value.GetString();
150 return true;
151 }
152 bool Render( wxRect rect, wxDC *dc, int WXUNUSED(state) )
153 {
154 dc->SetPen( *wxBLACK_PEN );
155 if (m_colour == wxT("red"))
156 dc->SetBrush( *wxRED_BRUSH );
157 else if (m_colour == wxT("green"))
158 dc->SetBrush( *wxGREEN_BRUSH );
159 else
160 dc->SetBrush( *wxBLACK_BRUSH );
161 dc->DrawRectangle( rect );
162 return true;
163 }
164 wxSize GetSize()
165 {
166 return wxSize(20,8);
167 }
168 bool Activate( wxRect WXUNUSED(rect),
169 wxDataViewListModel *WXUNUSED(model),
170 unsigned int WXUNUSED(col),
171 unsigned int WXUNUSED(row) )
172 {
173 return false;
174 }
175
176 private:
177 wxString m_colour;
178 };
179
180 // -------------------------------------
181 // MyUnsortedTextModel
182 // -------------------------------------
183
184 class MyUnsortedTextModel: public wxDataViewListModel
185 {
186 public:
187 MyUnsortedTextModel()
188 {
189 m_list.Add( wxT("This") );
190 m_list.Add( wxT("is") );
191 m_list.Add( wxT("an") );
192 m_list.Add( wxT("unsorted") );
193 m_list.Add( wxT("list") );
194 m_list.Add( wxT("of") );
195 m_list.Add( wxT("words.") );
196
197 m_bitmap = wxBitmap( null_xpm );
198 }
199
200 virtual unsigned int GetNumberOfRows() { return m_list.GetCount(); }
201 virtual unsigned int GetNumberOfCols() { return 2; }
202 virtual wxString GetColType( unsigned int WXUNUSED(col) ) { return wxT("string"); }
203 virtual void GetValue( wxVariant &variant, unsigned int col, unsigned int row )
204 {
205 if (col == 0)
206 {
207 variant = m_list[row];
208 return;
209 }
210 if ((col == 2) || (col == 3))
211 {
212 variant << m_bitmap;
213 return;
214 }
215 wxString tmp;
216 tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col );
217 variant = tmp;
218 }
219 virtual bool SetValue( wxVariant &variant, unsigned int col, unsigned int row )
220 {
221 if (col == 0)
222 {
223 m_list[row] = variant.GetString();
224 return true;
225 }
226 return false;
227
228 }
229
230 void AppendRow( const wxString &text )
231 {
232 m_list.Add( text );
233 RowAppended();
234 }
235
236 void PrependRow( const wxString &text )
237 {
238 m_list.Insert( text, 0 );
239 RowPrepended();
240 }
241
242 void InsertRowAt1( const wxString &text )
243 {
244 m_list.Insert( text, 1 );
245 RowInserted( 1 );
246 }
247
248 void DeleteRow( unsigned int index )
249 {
250 m_list.RemoveAt( index );
251 RowDeleted( index );
252 }
253
254 wxArrayString m_list;
255 wxBitmap m_bitmap;
256 };
257
258 // -------------------------------------
259 // MyApp
260 // -------------------------------------
261
262 class MyApp: public wxApp
263 {
264 public:
265 bool OnInit(void);
266 };
267
268 // -------------------------------------
269 // MyFrame
270 // -------------------------------------
271
272 class MyFrame: public wxFrame
273 {
274 public:
275 MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h);
276
277 public:
278 void OnQuit(wxCommandEvent& event);
279 void OnAbout(wxCommandEvent& event);
280
281 private:
282 wxDataViewCtrl* dataview_left;
283 wxDataViewCtrl* dataview_right;
284 };
285
286 // -------------------------------------
287 // MySortingFrame
288 // -------------------------------------
289
290 enum my_events
291 {
292 ID_APPEND_ROW_LEFT = 1000,
293 ID_PREPEND_ROW_LEFT,
294 ID_INSERT_ROW_LEFT,
295 ID_DELETE_ROW_LEFT,
296 ID_EDIT_ROW_LEFT,
297
298 ID_SELECT,
299 ID_UNSELECT_ALL,
300
301 ID_APPEND_ROW_RIGHT,
302 ID_PREPEND_ROW_RIGHT,
303 ID_INSERT_ROW_RIGHT,
304 ID_DELETE_ROW_RIGHT,
305 ID_EDIT_ROW_RIGHT,
306
307 ID_SORTED,
308 ID_UNSORTED,
309 ID_ACTIVATED
310 };
311
312 class MySortingFrame: public wxFrame
313 {
314 public:
315 MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h);
316 ~MySortingFrame();
317
318 public:
319 void OnQuit(wxCommandEvent& event);
320 void OnAbout(wxCommandEvent& event);
321
322 void OnAppendRowLeft(wxCommandEvent& event);
323 void OnPrependRowLeft(wxCommandEvent& event);
324 void OnInsertRowLeft(wxCommandEvent& event);
325 void OnDeleteRowLeft(wxCommandEvent& event);
326 void OnEditRowLeft(wxCommandEvent& event);
327
328 void OnAppendRowRight(wxCommandEvent& event);
329 void OnPrependRowRight(wxCommandEvent& event);
330 void OnInsertRowRight(wxCommandEvent& event);
331 void OnDeleteRowRight(wxCommandEvent& event);
332 void OnEditRowRight(wxCommandEvent& event);
333
334 void OnSelect(wxCommandEvent& event);
335 void OnUnselectAll(wxCommandEvent& event);
336
337 void OnSelectedUnsorted(wxDataViewEvent &event);
338 void OnSelectedSorted(wxDataViewEvent &event);
339 void OnActivatedUnsorted(wxDataViewEvent &event);
340
341 void OnHeaderClickSorted(wxDataViewEvent &event);
342 void OnHeaderClickUnsorted(wxDataViewEvent &event);
343
344 private:
345 wxDataViewCtrl* dataview_left;
346 wxDataViewCtrl* dataview_right;
347
348 wxLog *m_logOld;
349 wxTextCtrl *m_logWindow;
350
351 MyUnsortedTextModel *m_unsorted_model;
352 wxDataViewSortedListModel *m_sorted_model;
353
354 DECLARE_EVENT_TABLE()
355 };
356
357 // -------------------------------------
358 // MyApp
359 // -------------------------------------
360
361 #define DYNAMIC_QUIT wxID_EXIT
362 #define DYNAMIC_ABOUT wxID_ABOUT
363
364 IMPLEMENT_APP (MyApp)
365
366 bool MyApp::OnInit(void)
367 {
368 if ( !wxApp::OnInit() )
369 return false;
370
371 MyFrame *frame = new MyFrame(NULL, wxT("wxDataViewCtrl feature test"), 10, 10, 800, 340);
372 frame->Show(true);
373
374 MySortingFrame *frame2 = new MySortingFrame(NULL, wxT("wxDataViewCtrl sorting test"), 10, 150, 600, 500);
375 frame2->Show(true);
376
377 SetTopWindow(frame);
378
379 return true;
380 }
381
382 // -------------------------------------
383 // MyFrame
384 // -------------------------------------
385
386 MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
387 wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
388 {
389 SetIcon(wxICON(sample));
390
391 wxMenu *file_menu = new wxMenu;
392
393 file_menu->Append(DYNAMIC_ABOUT, _T("&About"));
394 file_menu->Append(DYNAMIC_QUIT, _T("E&xit"));
395 wxMenuBar *menu_bar = new wxMenuBar;
396 menu_bar->Append(file_menu, _T("&File"));
397 SetMenuBar(menu_bar);
398
399 // You used to have to do some casting for param 4, but now there are type-safe handlers
400 Connect( DYNAMIC_QUIT, wxID_ANY,
401 wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnQuit) );
402 Connect( DYNAMIC_ABOUT, wxID_ANY,
403 wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnAbout) );
404
405 CreateStatusBar();
406
407 wxPanel *panel = new wxPanel( this, wxID_ANY );
408
409
410 // Left wxDataViewCtrl
411 dataview_left = new wxDataViewCtrl( panel, wxID_ANY );
412
413 MyTextModel *model = new MyTextModel;
414 dataview_left->AssociateModel( model );
415
416 dataview_left->AppendTextColumn( wxT("first"), 0 );
417 dataview_left->AppendTextColumn( wxT("second"), 1 );
418
419 wxDataViewTextRenderer *text_renderer = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
420 wxDataViewColumn *column = new wxDataViewColumn( wxT("editable"), text_renderer, 2 );
421 dataview_left->AppendColumn( column );
422
423 dataview_left->AppendToggleColumn( wxT("fourth"), 3 );
424
425 MyCustomRenderer *custom_renderer = new MyCustomRenderer;
426 column = new wxDataViewColumn( wxT("custom"), custom_renderer, 4 );
427 dataview_left->AppendColumn( column );
428
429 dataview_left->AppendProgressColumn( wxT("progress"), 5 );
430
431 dataview_left->AppendDateColumn( wxT("date"), 6 );
432
433 // Right wxDataViewCtrl using the same model
434 dataview_right = new wxDataViewCtrl( panel, wxID_ANY );
435 dataview_right->AssociateModel( model );
436
437 text_renderer = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
438 column = new wxDataViewColumn( wxT("editable"), text_renderer, 2 );
439 dataview_right->AppendColumn( column );
440 dataview_right->AppendTextColumn( wxT("first"), 0 );
441 dataview_right->AppendTextColumn( wxT("second"), 1 );
442 wxDataViewToggleRenderer *toggle_renderer = new wxDataViewToggleRenderer( wxT("bool"), wxDATAVIEW_CELL_ACTIVATABLE );
443 column = new wxDataViewColumn( wxT("bool"), toggle_renderer, 3, 30 );
444 dataview_right->AppendColumn( column );
445
446 dataview_right->AppendDateColumn( wxT("date"), 6 );
447
448 // layout dataview controls.
449
450 wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
451 sizer->Add( dataview_left, 3, wxGROW );
452 sizer->Add(10,10);
453 sizer->Add( dataview_right, 2, wxGROW );
454 panel->SetSizer( sizer );
455 }
456
457 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
458 {
459 Close(true);
460 }
461
462 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
463 {
464 wxMessageDialog dialog(this, _T("This demonstrates the dataview control handling"),
465 _T("About DataView"), wxOK);
466
467 dialog.ShowModal();
468 }
469
470 // -------------------------------------
471 // MySortingFrame
472 // -------------------------------------
473
474 BEGIN_EVENT_TABLE(MySortingFrame,wxFrame)
475 EVT_BUTTON( ID_APPEND_ROW_LEFT, MySortingFrame::OnAppendRowLeft )
476 EVT_BUTTON( ID_PREPEND_ROW_LEFT, MySortingFrame::OnPrependRowLeft )
477 EVT_BUTTON( ID_INSERT_ROW_LEFT, MySortingFrame::OnInsertRowLeft )
478 EVT_BUTTON( ID_DELETE_ROW_LEFT, MySortingFrame::OnDeleteRowLeft )
479 EVT_BUTTON( ID_SELECT, MySortingFrame::OnSelect )
480 EVT_BUTTON( ID_UNSELECT_ALL, MySortingFrame::OnUnselectAll )
481 EVT_DATAVIEW_ROW_SELECTED( ID_SORTED, MySortingFrame::OnSelectedSorted )
482 EVT_DATAVIEW_ROW_SELECTED( ID_UNSORTED, MySortingFrame::OnSelectedUnsorted )
483 EVT_DATAVIEW_ROW_ACTIVATED( ID_UNSORTED, MySortingFrame::OnActivatedUnsorted )
484 EVT_DATAVIEW_COLUMN_HEADER_CLICK( ID_SORTED, MySortingFrame::OnHeaderClickSorted )
485 EVT_DATAVIEW_COLUMN_HEADER_CLICK( ID_UNSORTED, MySortingFrame::OnHeaderClickUnsorted )
486 END_EVENT_TABLE()
487
488 MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
489 wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
490 {
491 m_logOld = NULL;
492
493 SetIcon(wxICON(sample));
494
495 wxMenu *file_menu = new wxMenu;
496
497 file_menu->Append(DYNAMIC_ABOUT, _T("&About"));
498 file_menu->Append(DYNAMIC_QUIT, _T("E&xit"));
499 wxMenuBar *menu_bar = new wxMenuBar;
500 menu_bar->Append(file_menu, _T("&File"));
501 SetMenuBar(menu_bar);
502
503 // You used to have to do some casting for param 4, but now there are type-safe handlers
504 Connect( DYNAMIC_QUIT, wxID_ANY,
505 wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MySortingFrame::OnQuit) );
506 Connect( DYNAMIC_ABOUT, wxID_ANY,
507 wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MySortingFrame::OnAbout) );
508
509 CreateStatusBar();
510
511
512 // Left wxDataViewCtrl
513 dataview_left = new wxDataViewCtrl( this, ID_UNSORTED, wxDefaultPosition, wxDefaultSize, wxDV_MULTIPLE );
514
515 m_unsorted_model = new MyUnsortedTextModel;
516 dataview_left->AssociateModel( m_unsorted_model );
517 wxDataViewTextRenderer *text_renderer = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
518 wxDataViewColumn *column = new wxDataViewColumn( wxT("editable"), text_renderer, 0 );
519 dataview_left->AppendColumn( column );
520 dataview_left->AppendTextColumn( wxT("second"), 1 );
521 dataview_left->AppendColumn( new wxDataViewColumn( wxBitmap(null_xpm), new wxDataViewBitmapRenderer, 2, 25 ) );
522 dataview_left->AppendColumn( new wxDataViewColumn( wxT("icon"), new wxDataViewBitmapRenderer, 3, 25 ) );
523
524 // Right wxDataViewCtrl using the sorting model
525 dataview_right = new wxDataViewCtrl( this, ID_SORTED );
526
527 m_sorted_model = new wxDataViewSortedListModel( m_unsorted_model );
528 dataview_right->AssociateModel( m_sorted_model );
529 text_renderer = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
530 column = new wxDataViewColumn( wxT("editable"), text_renderer, 0, -1, wxDATAVIEW_COL_SORTABLE|wxDATAVIEW_COL_RESIZABLE );
531 dataview_right->AppendColumn( column );
532
533 dataview_right->AppendTextColumn( wxT("second"), 1 );
534
535 // layout dataview controls.
536
537 wxBoxSizer *top_sizer = new wxBoxSizer( wxHORIZONTAL );
538 top_sizer->Add( dataview_left, 1, wxGROW );
539 top_sizer->Add(10,10);
540 top_sizer->Add( dataview_right, 1, wxGROW );
541
542 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
543 button_sizer->Add( 10, 10, 1 );
544 wxFlexGridSizer *left_sizer = new wxFlexGridSizer( 2 );
545 left_sizer->Add( new wxButton( this, ID_APPEND_ROW_LEFT, wxT("Append") ), 0, wxALL, 5 );
546 left_sizer->Add( new wxButton( this, ID_PREPEND_ROW_LEFT, wxT("Prepend") ), 0, wxALL, 5 );
547 left_sizer->Add( new wxButton( this, ID_INSERT_ROW_LEFT, wxT("Insert") ), 0, wxALL, 5 );
548 left_sizer->Add( new wxButton( this, ID_DELETE_ROW_LEFT, wxT("Delete second") ), 0, wxALL, 5 );
549 left_sizer->Add( new wxButton( this, ID_EDIT_ROW_LEFT, wxT("Edit") ), 0, wxALL, 5 );
550 left_sizer->Add( 5,5 );
551 left_sizer->Add( new wxButton( this, ID_SELECT, wxT("Select third") ), 0, wxALL, 5 );
552 left_sizer->Add( new wxButton( this, ID_UNSELECT_ALL, wxT("Unselect all") ), 0, wxALL, 5 );
553 button_sizer->Add( left_sizer );
554 button_sizer->Add( 10, 10, 2 );
555 wxFlexGridSizer *right_sizer = new wxFlexGridSizer( 2 );
556 right_sizer->Add( new wxButton( this, ID_APPEND_ROW_RIGHT, wxT("Append") ), 0, wxALL, 5 );
557 right_sizer->Add( new wxButton( this, ID_PREPEND_ROW_RIGHT, wxT("Prepend") ), 0, wxALL, 5 );
558 right_sizer->Add( new wxButton( this, ID_INSERT_ROW_RIGHT, wxT("Insert") ), 0, wxALL, 5 );
559 right_sizer->Add( new wxButton( this, ID_DELETE_ROW_RIGHT, wxT("Delete second") ), 0, wxALL, 5 );
560 right_sizer->Add( new wxButton( this, ID_EDIT_ROW_RIGHT, wxT("Edit") ), 0, wxALL, 5 );
561 button_sizer->Add( right_sizer );
562 button_sizer->Add( 10, 10, 1 );
563
564 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
565 main_sizer->Add( top_sizer, 1, wxGROW );
566 main_sizer->Add( button_sizer, 0, wxGROW );
567
568 m_logWindow = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
569 wxDefaultPosition, wxDefaultSize,
570 wxTE_MULTILINE | wxSUNKEN_BORDER);
571 main_sizer->Add( 20,20 );
572 main_sizer->Add( m_logWindow, 1, wxGROW );
573
574 m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_logWindow));
575
576 SetSizer( main_sizer );
577 }
578
579 MySortingFrame::~MySortingFrame()
580 {
581 delete wxLog::SetActiveTarget(m_logOld);
582 }
583
584 void MySortingFrame::OnSelectedUnsorted(wxDataViewEvent &event)
585 {
586 int row = event.GetRow();
587 wxLogMessage( wxT("OnSelected from unsorted list, selected %d"), row );
588 if (row >= 0)
589 wxLogMessage( wxT("wxDataViewCtrl::IsSelected( %d ): %d (as int)"),
590 row, (int) dataview_right->IsSelected( row ) );
591 }
592
593 void MySortingFrame::OnSelectedSorted(wxDataViewEvent &event)
594 {
595 wxLogMessage( wxT("OnSelected from sorted list, selected %d"), (int) event.GetRow() );
596 }
597
598 void MySortingFrame::OnActivatedUnsorted(wxDataViewEvent &event)
599 {
600 wxLogMessage( wxT("OnActivated from unsorted list, activated %d"), (int) event.GetRow() );
601 }
602
603 void MySortingFrame::OnHeaderClickSorted(wxDataViewEvent &event)
604 {
605 wxDataViewColumn *col = event.GetDataViewColumn();
606 wxLogMessage( wxT("OnHeaderClick from sorted list, column %s"), col->GetTitle().c_str() );
607
608 if (col->GetTitle() == wxT("editable"))
609 {
610 // this is the sorting column
611 if (col->IsSortOrderAscending())
612 {
613 col->SetSortOrder( false );
614 m_sorted_model->SetAscending( false );
615 m_sorted_model->Resort();
616 }
617 else
618 {
619 col->SetSortOrder( true );
620 m_sorted_model->SetAscending( true );
621 m_sorted_model->Resort();
622 }
623 }
624 }
625
626 void MySortingFrame::OnHeaderClickUnsorted(wxDataViewEvent &event)
627 {
628 wxLogMessage( wxT("OnHeaderClick from unsorted list, column %s"), event.GetDataViewColumn()->GetTitle().c_str() );
629 }
630
631 void MySortingFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
632 {
633 Close(true);
634 }
635
636 void MySortingFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
637 {
638 wxMessageDialog dialog(this, _T("This demonstrates the dataview control sorting"),
639 _T("About DataView"), wxOK);
640
641 dialog.ShowModal();
642 }
643
644 void MySortingFrame::OnSelect(wxCommandEvent& WXUNUSED(event))
645 {
646 dataview_left->SetSelection( 2 );
647 }
648
649 void MySortingFrame::OnUnselectAll(wxCommandEvent& WXUNUSED(event))
650 {
651 dataview_left->ClearSelection();
652 }
653
654 void MySortingFrame::OnAppendRowLeft(wxCommandEvent& WXUNUSED(event))
655 {
656 wxTextEntryDialog dialog( this, wxT("Enter text to append") );
657 if (dialog.ShowModal() == wxID_OK)
658 {
659 wxString value = dialog.GetValue();
660 if (!value.empty())
661 m_unsorted_model->AppendRow( value );
662 }
663 }
664
665 void MySortingFrame::OnPrependRowLeft(wxCommandEvent& WXUNUSED(event))
666 {
667 wxTextEntryDialog dialog( this, wxT("Enter text to prepend") );
668 if (dialog.ShowModal() == wxID_OK)
669 {
670 wxString value = dialog.GetValue();
671 if (!value.empty())
672 m_unsorted_model->PrependRow( value );
673 }
674 }
675
676 void MySortingFrame::OnInsertRowLeft(wxCommandEvent& WXUNUSED(event))
677 {
678 wxTextEntryDialog dialog( this, wxT("Enter text to insert before second") );
679 if (dialog.ShowModal() == wxID_OK)
680 {
681 wxString value = dialog.GetValue();
682 if (!value.empty())
683 m_unsorted_model->InsertRowAt1( value );
684 }
685 }
686
687 void MySortingFrame::OnDeleteRowLeft(wxCommandEvent& WXUNUSED(event))
688 {
689 m_unsorted_model->DeleteRow( 1 );
690 }
691
692 void MySortingFrame::OnEditRowLeft(wxCommandEvent& WXUNUSED(event))
693 {
694 }
695
696 void MySortingFrame::OnAppendRowRight(wxCommandEvent& WXUNUSED(event))
697 {
698 }
699
700 void MySortingFrame::OnPrependRowRight(wxCommandEvent& WXUNUSED(event))
701 {
702 }
703
704 void MySortingFrame::OnInsertRowRight(wxCommandEvent& WXUNUSED(event))
705 {
706 }
707
708 void MySortingFrame::OnDeleteRowRight(wxCommandEvent& WXUNUSED(event))
709 {
710 }
711
712 void MySortingFrame::OnEditRowRight(wxCommandEvent& WXUNUSED(event))
713 {
714 }
715