Make ::SetValue return a bool
[wxWidgets.git] / samples / dataview / dataview.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dataview.cpp
3 // Purpose: wxDataViewCtrl wxWidgets sample
4 // Author: Robert Roebling
5 // Modified by: Francesco Montorsi, Bo Yang
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 #include "wx/splitter.h"
25 #include "wx/aboutdlg.h"
26 #include "wx/choicdlg.h"
27 #include "wx/numdlg.h"
28 #include "wx/dataview.h"
29 #include "wx/spinctrl.h"
30
31 #ifndef __WXMSW__
32 #include "../sample.xpm"
33 #endif
34
35 #include "null.xpm"
36
37
38 #define DEFAULT_ALIGN wxALIGN_LEFT
39 #define DATAVIEW_DEFAULT_STYLE (wxDV_MULTIPLE|wxDV_HORIZ_RULES|wxDV_VERT_RULES)
40
41
42
43 // -------------------------------------
44 // MyMusicModel
45 // -------------------------------------
46
47 /*
48 Implement this data model
49 Title Artist Year
50 -------------------------------------------------------------
51 1: My Music:
52 2: Pop music
53 3: You are not alone Michael Jackson 1995
54 4: Take a bow Madonna 1994
55 5: Classical music
56 6: Ninth Symphony Ludwig v. Beethoven 1824
57 7: German Requiem Johannes Brahms 1868
58 */
59
60
61
62 class MyMusicModelNode;
63 WX_DEFINE_ARRAY_PTR( MyMusicModelNode*, MyMusicModelNodes );
64
65 class MyMusicModelNode
66 {
67 public:
68 MyMusicModelNode( MyMusicModelNode* parent,
69 const wxString &title, const wxString &artist, const wxString &year )
70 {
71 m_parent = parent;
72 m_title = title;
73 m_artist = artist;
74 m_year = year;
75 m_isContainer = false;
76 }
77
78 MyMusicModelNode( MyMusicModelNode* parent,
79 const wxString &branch )
80 {
81 m_parent = parent;
82 m_title = branch;
83 m_isContainer = true;
84 }
85
86 ~MyMusicModelNode()
87 {
88 size_t count = m_children.GetCount();
89 size_t i;
90 for (i = 0; i < count; i++)
91 {
92 MyMusicModelNode *child = m_children[i];
93 delete child;
94 }
95 }
96
97 bool IsContainer() { return m_isContainer; }
98
99 MyMusicModelNode* GetParent() { return m_parent; }
100 MyMusicModelNodes &GetChildren() { return m_children; }
101 MyMusicModelNode* GetNthChild( unsigned int n ) { return m_children.Item( n ); }
102 void Insert( MyMusicModelNode* child, unsigned int n) { m_children.Insert( child, n); }
103 void Append( MyMusicModelNode* child ) { m_children.Add( child ); }
104 unsigned int GetChildCount() { return m_children.GetCount(); }
105
106 public:
107 wxString m_title;
108 wxString m_artist;
109 wxString m_year;
110
111 private:
112 MyMusicModelNode *m_parent;
113 MyMusicModelNodes m_children;
114 bool m_isContainer;
115 };
116
117
118 class MyMusicModel: public wxDataViewModel
119 {
120 public:
121
122 // constructor
123
124 MyMusicModel()
125 {
126 m_root = new MyMusicModelNode( NULL, "My Music" );
127 m_pop = new MyMusicModelNode( m_root, "Pop music" );
128 m_root->Append( m_pop );
129 m_pop->Append( new MyMusicModelNode( m_pop,
130 "You are not alone", "Michael Jackson", "1995" ) );
131 m_pop->Append( new MyMusicModelNode( m_pop,
132 "Take a bow", "Madonna", "1994" ) );
133 m_classical = new MyMusicModelNode( m_root, "Classical music" );
134 m_root->Append( m_classical );
135 m_classical->Append( new MyMusicModelNode( m_classical,
136 "Ninth symphony", "Ludwig van Beethoven", "1824" ) );
137 m_classical->Append( new MyMusicModelNode( m_classical,
138 "German Requiem", "Johannes Brahms", "1868" ) );
139 m_classicalMusicIsKnownToControl = false;
140 }
141
142 // helper methods to change the model
143
144 void AddToClassical( const wxString &title, const wxString &artist, const wxString &year )
145 {
146 // add to data
147 MyMusicModelNode *child_node =
148 new MyMusicModelNode( m_classical, title, artist, year );
149
150 m_classical->Append( child_node );
151
152 if (m_classicalMusicIsKnownToControl)
153 {
154 // notify control
155 wxDataViewItem child( (void*) child_node );
156 wxDataViewItem parent( (void*) m_classical );
157 ItemAdded( parent, child );
158 }
159 }
160
161 void Delete( const wxDataViewItem &item )
162 {
163 MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
164 wxDataViewItem parent( node->GetParent() );
165
166 // notify control
167 ItemDeleted( parent, item );
168 //We must delete the node after we call ItemDeleted
169 //The reason is that:
170 //When we use wxSortedArray, the array find a node through binary search for speed.
171 //And when the array is searching for some node, it call the model's compare function.
172 //The compare function need the node to be compared. So we should delete the node later, here.
173 node->GetParent()->GetChildren().Remove( node );
174 delete node;
175 }
176
177 // override sorting to always sort branches ascendingly
178
179 int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
180 unsigned int column, bool ascending )
181 {
182 if (IsContainer(item1) && IsContainer(item2))
183 {
184 wxVariant value1,value2;
185 GetValue( value1, item1, 0 );
186 GetValue( value2, item2, 0 );
187
188 wxString str1 = value1.GetString();
189 wxString str2 = value2.GetString();
190 int res = str1.Cmp( str2 );
191 if (res) return res;
192
193 // items must be different
194 unsigned long litem1 = (unsigned long) item1.GetID();
195 unsigned long litem2 = (unsigned long) item2.GetID();
196
197 return litem1-litem2;
198 }
199
200 return wxDataViewModel::Compare( item1, item2, column, ascending );
201 }
202
203 // implementation of base class virtuals to define model
204
205 virtual unsigned int GetColumnCount() const
206 {
207 return 3;
208 }
209
210 virtual wxString GetColumnType( unsigned int col ) const
211 {
212 return "string";
213 }
214
215 virtual void GetValue( wxVariant &variant,
216 const wxDataViewItem &item, unsigned int col ) const
217 {
218 MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
219 switch (col)
220 {
221 case 0: variant = node->m_title; break;
222 case 1: variant = node->m_artist; break;
223 case 2: variant = node->m_year; break;
224 default:
225 {
226 wxLogError( "MyMusicModel::GetValue: wrong column" );
227 wxMouseState state = wxGetMouseState();
228 if (state.ShiftDown())
229 {
230 char *crash = 0;
231 *crash = 0;
232 }
233 }
234 }
235 }
236
237 virtual bool SetValue( const wxVariant &variant,
238 const wxDataViewItem &item, unsigned int col )
239 {
240 MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
241 switch (col)
242 {
243 case 0: node->m_title = variant.GetString(); return true;
244 case 1: node->m_artist = variant.GetString(); return true;
245 case 2: node->m_year = variant.GetString(); return true;
246 default: wxLogError( "MyMusicModel::SetValue: wrong column" );
247 }
248 return false;
249 }
250
251 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const
252 {
253 // the invisble root node has no parent
254 if (!item.IsOk())
255 return wxDataViewItem(0);
256
257 MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
258
259 // "MyMusic" also has no parent
260 if (node == m_root)
261 return wxDataViewItem(0);
262
263 return wxDataViewItem( (void*) node->GetParent() );
264 }
265
266 virtual bool IsContainer( const wxDataViewItem &item ) const
267 {
268 // the invisble root node can have children (in
269 // our model always "MyMusic")
270 if (!item.IsOk())
271 return true;
272
273 MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
274 return node->IsContainer();
275 }
276
277 virtual wxDataViewItem GetFirstChild( const wxDataViewItem &parent ) const
278 {
279 MyMusicModelNode *node = (MyMusicModelNode*) parent.GetID();
280 if (!node)
281 return wxDataViewItem( (void*) m_root );
282
283 if (node->GetChildCount() == 0)
284 return wxDataViewItem( 0 );
285
286 if (node == m_classical)
287 {
288 MyMusicModel *model = (MyMusicModel*)(const MyMusicModel*) this;
289 model->m_classicalMusicIsKnownToControl = true;
290 }
291
292 MyMusicModelNode *first_child = node->GetChildren().Item( 0 );
293 return wxDataViewItem( (void*) first_child );
294 }
295
296 virtual wxDataViewItem GetNextSibling( const wxDataViewItem &item ) const
297 {
298 MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
299
300 // "MyMusic" has no siblings in our model
301 if (node == m_root)
302 return wxDataViewItem(0);
303
304 MyMusicModelNode *parent = node->GetParent();
305 int pos = parent->GetChildren().Index( node );
306
307 // Something went wrong
308 if (pos == wxNOT_FOUND)
309 return wxDataViewItem(0);
310
311 // No more children
312 if (pos == parent->GetChildCount()-1)
313 return wxDataViewItem(0);
314
315 node = parent->GetChildren().Item( pos+1 );
316 return wxDataViewItem( (void*) node );
317 }
318
319 private:
320 MyMusicModelNode* m_root;
321 MyMusicModelNode* m_pop;
322 MyMusicModelNode* m_classical;
323 bool m_classicalMusicIsKnownToControl;
324 };
325
326 class MyListModel: public wxDataViewIndexListModel
327 {
328 public:
329 MyListModel() :
330 wxDataViewIndexListModel( 100 )
331 {
332 unsigned int i;
333 for (i = 0; i < 100; i++)
334 {
335 wxString str;
336 str.Printf( "row number %d", i );
337 m_array.Add( str );
338 }
339 }
340
341 // helper methods to change the model
342
343 void Prepend( const wxString &text )
344 {
345 m_array.Insert( text, 0 );
346 RowPrepended();
347 }
348
349 void DeleteItem( const wxDataViewItem &item )
350 {
351 unsigned int row = GetRow( item );
352 m_array.RemoveAt( row );
353 RowDeleted( row );
354 }
355
356 // implementation of base class virtuals to define model
357
358 virtual unsigned int GetColumnCount() const
359 {
360 return 2;
361 }
362
363 virtual wxString GetColumnType( unsigned int col ) const
364 {
365 return "string";
366 }
367
368 virtual unsigned int GetRowCount()
369 {
370 return m_array.GetCount();
371 }
372
373 virtual void GetValue( wxVariant &variant,
374 unsigned int row, unsigned int col ) const
375 {
376 if (col==0)
377 {
378 variant = m_array[ row ];
379 }
380 else
381 {
382 wxString str;
383 str.Printf( "row %d col %d", row, col );
384 variant = str;
385 }
386 }
387
388 virtual bool SetValue( const wxVariant &variant,
389 unsigned int row, unsigned int col )
390 {
391 if (col == 0)
392 {
393 m_array[row] = variant.GetString();
394 return true;
395 }
396
397 return false;
398 }
399
400 wxArrayString m_array;
401 };
402
403 // -------------------------------------
404 // MyApp
405 // -------------------------------------
406
407 class MyApp: public wxApp
408 {
409 public:
410 bool OnInit(void);
411 int OnExit();
412 };
413
414 // -------------------------------------
415 // MyFrame
416 // -------------------------------------
417
418 class MyFrame : public wxFrame
419 {
420 public:
421 MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h);
422
423 public:
424 void OnQuit(wxCommandEvent& event);
425 void OnAbout(wxCommandEvent& event);
426
427 void OnAddMozart(wxCommandEvent& event);
428 void OnDeleteMusic(wxCommandEvent& event);
429
430 void OnPrependList(wxCommandEvent& event);
431 void OnDeleteList(wxCommandEvent& event);
432
433 void OnValueChanged( wxDataViewEvent &event );
434 void OnItemAdded( wxDataViewEvent &event );
435 void OnItemDeleted( wxDataViewEvent &event );
436
437 void OnActivated( wxDataViewEvent &event );
438 void OnExpanding( wxDataViewEvent &event );
439 void OnExpanded( wxDataViewEvent &event );
440 void OnCollapsing( wxDataViewEvent &event );
441 void OnCollapsed( wxDataViewEvent &event );
442 void OnSelected( wxDataViewEvent &event );
443
444 void OnHeaderClick( wxDataViewEvent &event );
445 void OnHeaderRightClick( wxDataViewEvent &event );
446 void OnSorted( wxDataViewEvent &event );
447
448 void OnRightClick( wxMouseEvent &event );
449 void OnGoto( wxCommandEvent &event);
450
451 private:
452 wxDataViewCtrl* m_musicCtrl;
453 wxObjectDataPtr<MyMusicModel> m_music_model;
454
455 wxDataViewCtrl* m_listCtrl;
456 wxObjectDataPtr<MyListModel> m_list_model;
457
458 wxTextCtrl * m_log;
459 wxLog *m_logOld;
460
461 private:
462 DECLARE_EVENT_TABLE()
463 };
464
465 // -------------------------------------
466 // MyApp
467 // -------------------------------------
468
469 IMPLEMENT_APP(MyApp)
470
471 bool MyApp::OnInit(void)
472 {
473 if ( !wxApp::OnInit() )
474 return false;
475
476 // build the first frame
477 MyFrame *frame =
478 new MyFrame(NULL, wxT("wxDataViewCtrl feature test"), 40, 40, 700, 440);
479 frame->Show(true);
480
481 SetTopWindow(frame);
482 return true;
483 }
484
485 int MyApp::OnExit()
486 {
487 return 0;
488 }
489
490
491 // -------------------------------------
492 // MyFrame
493 // -------------------------------------
494
495 enum
496 {
497 // file menu
498 ID_ABOUT = wxID_ABOUT,
499 ID_EXIT = wxID_EXIT,
500
501 ID_MUSIC_CTRL = 50,
502
503 ID_ADD_MOZART = 100,
504 ID_DELETE_MUSIC = 101,
505
506 ID_PREPEND_LIST = 200,
507 ID_DELETE_LIST = 201,
508 ID_GOTO = 202
509 };
510
511 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
512 EVT_MENU( ID_ABOUT, MyFrame::OnAbout )
513 EVT_MENU( ID_EXIT, MyFrame::OnQuit )
514 EVT_BUTTON( ID_ADD_MOZART, MyFrame::OnAddMozart )
515 EVT_BUTTON( ID_DELETE_MUSIC, MyFrame::OnDeleteMusic )
516 EVT_BUTTON( ID_PREPEND_LIST, MyFrame::OnPrependList )
517 EVT_BUTTON( ID_DELETE_LIST, MyFrame::OnDeleteList )
518 EVT_BUTTON( ID_GOTO, MyFrame::OnGoto)
519
520 EVT_DATAVIEW_MODEL_ITEM_ADDED( ID_MUSIC_CTRL, MyFrame::OnItemAdded )
521 EVT_DATAVIEW_MODEL_ITEM_DELETED( ID_MUSIC_CTRL, MyFrame::OnItemDeleted )
522 EVT_DATAVIEW_MODEL_VALUE_CHANGED( ID_MUSIC_CTRL, MyFrame::OnValueChanged )
523 EVT_DATAVIEW_MODEL_ITEM_CHANGED( ID_MUSIC_CTRL, MyFrame::OnValueChanged )
524
525 EVT_DATAVIEW_ITEM_ACTIVATED(ID_MUSIC_CTRL, MyFrame::OnActivated )
526 EVT_DATAVIEW_ITEM_EXPANDING(ID_MUSIC_CTRL, MyFrame::OnExpanding)
527 EVT_DATAVIEW_ITEM_EXPANDED(ID_MUSIC_CTRL, MyFrame::OnExpanded)
528 EVT_DATAVIEW_ITEM_COLLAPSING(ID_MUSIC_CTRL, MyFrame::OnCollapsing)
529 EVT_DATAVIEW_ITEM_COLLAPSED(ID_MUSIC_CTRL, MyFrame::OnCollapsed)
530 EVT_DATAVIEW_ITEM_SELECTED(ID_MUSIC_CTRL, MyFrame::OnSelected)
531
532 EVT_DATAVIEW_COLUMN_HEADER_CLICK(ID_MUSIC_CTRL, MyFrame::OnHeaderClick)
533 EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(ID_MUSIC_CTRL, MyFrame::OnHeaderRightClick)
534 EVT_DATAVIEW_COLUMN_SORTED(ID_MUSIC_CTRL, MyFrame::OnSorted)
535
536 EVT_RIGHT_UP(MyFrame::OnRightClick)
537 END_EVENT_TABLE()
538
539 MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
540 wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
541 {
542 m_log = NULL;
543
544 SetIcon(wxICON(sample));
545
546 // build the menus:
547
548 wxMenu *file_menu = new wxMenu;
549 file_menu->Append(ID_ABOUT, "&About");
550 file_menu->AppendSeparator();
551 file_menu->Append(ID_EXIT, "E&xit");
552
553 wxMenuBar *menu_bar = new wxMenuBar;
554 menu_bar->Append(file_menu, "&File");
555
556 SetMenuBar(menu_bar);
557 CreateStatusBar();
558
559 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
560
561 wxBoxSizer *data_sizer = new wxBoxSizer( wxHORIZONTAL );
562
563 // MyMusic
564
565 m_musicCtrl = new wxDataViewCtrl( this, ID_MUSIC_CTRL, wxDefaultPosition,
566 wxDefaultSize, wxDV_MULTIPLE );
567
568 m_music_model = new MyMusicModel;
569 m_musicCtrl->AssociateModel( m_music_model.get() );
570
571 wxDataViewColumn *col = m_musicCtrl->AppendTextColumn( "Title", 0, wxDATAVIEW_CELL_INERT, 200,
572 DEFAULT_ALIGN, wxDATAVIEW_COL_SORTABLE );
573 #if 0
574 // Call this and sorting is enabled
575 // immediatly upon start up.
576 col->SetSortOrder( true );
577 #endif
578
579 m_musicCtrl->AppendTextColumn( "Artist", 1, wxDATAVIEW_CELL_EDITABLE, 200,
580 DEFAULT_ALIGN, wxDATAVIEW_COL_SORTABLE );
581 m_musicCtrl->AppendTextColumn( "Year", 2, wxDATAVIEW_CELL_INERT, 50,
582 DEFAULT_ALIGN );
583
584 data_sizer->Add( m_musicCtrl, 3, wxGROW );
585
586 #if 1
587
588 // MyList
589
590 m_listCtrl = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition,
591 wxDefaultSize, wxDV_MULTIPLE );
592
593 m_list_model = new MyListModel;
594 m_listCtrl->AssociateModel( m_list_model.get() );
595
596 m_listCtrl->AppendTextColumn( "editable string", 0, wxDATAVIEW_CELL_EDITABLE, 120 );
597 m_listCtrl->AppendTextColumn( "index", 1, wxDATAVIEW_CELL_INERT, 120 );
598
599 data_sizer->Add( m_listCtrl, 2, wxGROW );
600
601 #endif
602
603 main_sizer->Add( data_sizer, 2, wxGROW );
604
605 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
606
607 button_sizer->Add( new wxButton( this, ID_ADD_MOZART, "Add Mozart"), 0, wxALL, 10 );
608 button_sizer->Add( new wxButton( this, ID_DELETE_MUSIC, "Delete selected"), 0, wxALL, 10 );
609 button_sizer->Add( 10, 10, 1 );
610 button_sizer->Add( new wxButton( this, ID_PREPEND_LIST, "Prepend"), 0, wxALL, 10 );
611 button_sizer->Add( new wxButton( this, ID_DELETE_LIST, "Delete selected"), 0, wxALL, 10 );
612 button_sizer->Add( new wxButton( this, ID_GOTO, "Goto 50"), 0, wxALL, 10 );
613
614 main_sizer->Add( button_sizer, 0, wxGROW, 0 );
615
616 m_log = new wxTextCtrl( this, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
617 m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_log));
618 wxLogMessage("This is the log window");
619
620 main_sizer->Add( m_log, 1, wxGROW );
621
622 SetSizer( main_sizer );
623 }
624
625 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
626 {
627 Close(true);
628 }
629
630 void MyFrame::OnAddMozart(wxCommandEvent& WXUNUSED(event) )
631 {
632 m_music_model->AddToClassical( "Kleine Nachtmusik", "Wolfgang Mozart", "1787" );
633 }
634
635 void MyFrame::OnDeleteMusic(wxCommandEvent& WXUNUSED(event) )
636 {
637 wxDataViewItemArray items;
638 int len = m_musicCtrl->GetSelections( items );
639 for( int i = 0; i < len; i ++ )
640 if (items[i].IsOk())
641 m_music_model->Delete( items[i] );
642 }
643
644 void MyFrame::OnPrependList( wxCommandEvent& WXUNUSED(event) )
645 {
646 m_list_model->Prepend( "Test" );
647 }
648
649 void MyFrame::OnDeleteList( wxCommandEvent& WXUNUSED(event) )
650 {
651 wxDataViewItemArray items;
652 int len = m_listCtrl->GetSelections( items );
653 for( int i = 0; i < len; i ++ )
654 if (items[i].IsOk())
655 m_list_model->DeleteItem( items[i] );
656 }
657
658 void MyFrame::OnItemAdded( wxDataViewEvent &event )
659 {
660 if (!m_log)
661 return;
662
663 wxLogMessage("wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED, Item Id: %d",event.GetItem().GetID());
664 }
665
666 void MyFrame::OnItemDeleted( wxDataViewEvent &event )
667 {
668 if (!m_log)
669 return;
670
671 wxLogMessage( "EVT_DATAVIEW_MODEL_ITEM_DELETED, Item Id: %d", event.GetItem().GetID() );
672 }
673
674 void MyFrame::OnValueChanged( wxDataViewEvent &event )
675 {
676 if (!m_log)
677 return;
678
679 wxLogMessage( "EVT_DATAVIEW_MODEL_VALUE_CHANGED, Item Id: %d; Column: %d", event.GetItem().GetID(), event.GetColumn() );
680 }
681
682 void MyFrame::OnActivated( wxDataViewEvent &event )
683 {
684 if(!m_log)
685 return;
686
687 wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item Id: %d; Column: %d", event.GetItem().GetID(), event.GetColumn());
688 }
689
690 void MyFrame::OnSelected( wxDataViewEvent &event )
691 {
692 if(!m_log)
693 return;
694
695 wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED, Item Id: %d", event.GetItem().GetID() );
696 }
697
698 void MyFrame::OnExpanding( wxDataViewEvent &event )
699 {
700 if (!m_log)
701 return;
702
703 wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, Item Id: %d", event.GetItem().GetID() );
704 }
705
706 void MyFrame::OnExpanded( wxDataViewEvent &event )
707 {
708 if (!m_log)
709 return;
710
711 wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, Item Id: %d", event.GetItem().GetID() );
712 }
713
714 void MyFrame::OnCollapsing( wxDataViewEvent &event )
715 {
716 if (!m_log)
717 return;
718
719 wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, Item Id: %d", event.GetItem().GetID() );
720 }
721
722 void MyFrame::OnCollapsed( wxDataViewEvent &event )
723 {
724 if (!m_log)
725 return;
726
727 wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, Item Id: %d", event.GetItem().GetID() );
728 }
729
730 void MyFrame::OnHeaderClick( wxDataViewEvent &event )
731 {
732 if(!m_log)
733 return;
734
735 wxLogMessage("wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, Column: %d", event.GetColumn());
736 }
737
738 void MyFrame::OnHeaderRightClick( wxDataViewEvent &event )
739 {
740 if(!m_log)
741 return;
742
743 wxLogMessage("wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, Column: %d", event.GetColumn());
744 }
745
746 void MyFrame::OnSorted( wxDataViewEvent &event )
747 {
748 if(!m_log)
749 return;
750
751 wxLogMessage("wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, Column: %d", event.GetColumn());
752 }
753
754 void MyFrame::OnRightClick( wxMouseEvent &event )
755 {
756 if(!m_log)
757 return;
758
759 wxLogMessage("wxEVT_MOUSE_RIGHT_UP, Click Point is X: %d, Y: %d", event.GetX(), event.GetY());
760 }
761
762 void MyFrame::OnGoto( wxCommandEvent &event)
763 {
764 wxDataViewItem item = m_list_model->GetItem( 50 );
765 m_listCtrl->EnsureVisible(item);
766 }
767
768 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
769 {
770 wxAboutDialogInfo info;
771 info.SetName(_("DataView sample"));
772 info.SetDescription(_("This sample demonstrates the dataview control handling"));
773 info.SetCopyright(_T("(C) 2007 Robert Roebling"));
774
775 wxAboutBox(info);
776 }
777