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