1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDataViewCtrl wxWidgets sample
4 // Author: Robert Roebling
5 // Modified by: Francesco Montorsi, Bo Yang
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
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"
32 #include "../sample.xpm"
38 static const char *small1_xpm
[] = {
39 /* columns rows colors chars-per-pixel */
68 #define DEFAULT_ALIGN wxALIGN_LEFT
69 #define DATAVIEW_DEFAULT_STYLE (wxDV_MULTIPLE|wxDV_HORIZ_RULES|wxDV_VERT_RULES)
72 // -------------------------------------
74 // -------------------------------------
77 Implement this data model
79 -------------------------------------------------------------
82 3: You are not alone Michael Jackson 1995
83 4: Take a bow Madonna 1994
85 6: Ninth Symphony Ludwig v. Beethoven 1824
86 7: German Requiem Johannes Brahms 1868
91 class MyMusicModelNode
;
92 WX_DEFINE_ARRAY_PTR( MyMusicModelNode
*, MyMusicModelNodes
);
94 class MyMusicModelNode
97 MyMusicModelNode( MyMusicModelNode
* parent
,
98 const wxString
&title
, const wxString
&artist
, int year
)
104 m_isContainer
= false;
107 MyMusicModelNode( MyMusicModelNode
* parent
,
108 const wxString
&branch
)
113 m_isContainer
= true;
118 size_t count
= m_children
.GetCount();
120 for (i
= 0; i
< count
; i
++)
122 MyMusicModelNode
*child
= m_children
[i
];
127 bool IsContainer() { return m_isContainer
; }
129 MyMusicModelNode
* GetParent() { return m_parent
; }
130 MyMusicModelNodes
&GetChildren() { return m_children
; }
131 MyMusicModelNode
* GetNthChild( unsigned int n
) { return m_children
.Item( n
); }
132 void Insert( MyMusicModelNode
* child
, unsigned int n
) { m_children
.Insert( child
, n
); }
133 void Append( MyMusicModelNode
* child
) { m_children
.Add( child
); }
134 unsigned int GetChildCount() { return m_children
.GetCount(); }
142 MyMusicModelNode
*m_parent
;
143 MyMusicModelNodes m_children
;
148 class MyMusicModel
: public wxDataViewModel
156 m_root
= new MyMusicModelNode( NULL
, wxT("My Music" ));
157 m_pop
= new MyMusicModelNode( m_root
, wxT("Pop music") );
158 m_root
->Append( m_pop
);
159 m_pop
->Append( new MyMusicModelNode( m_pop
,
160 wxT("You are not alone"), wxT("Michael Jackson"), 1995 ) );
161 m_pop
->Append( new MyMusicModelNode( m_pop
,
162 wxT("Take a bow"), wxT("Madonna"), 1994 ) );
163 m_classical
= new MyMusicModelNode( m_root
, wxT("Classical music") );
164 m_root
->Append( m_classical
);
165 m_classical
->Append( new MyMusicModelNode( m_classical
,
166 wxT("Ninth symphony"), wxT("Ludwig van Beethoven"), 1824 ) );
167 m_classical
->Append( new MyMusicModelNode( m_classical
,
168 wxT("German Requiem"), wxT("Johannes Brahms"), 1868 ) );
169 m_classicalMusicIsKnownToControl
= false;
177 // helper method for wxLog
179 wxString
GetTitle( const wxDataViewItem
&item
)
181 MyMusicModelNode
*node
= (MyMusicModelNode
*) item
.GetID();
183 return wxEmptyString
;
185 return node
->m_title
;
188 // helper methods to change the model
190 void AddToClassical( const wxString
&title
, const wxString
&artist
, int year
)
193 MyMusicModelNode
*child_node
=
194 new MyMusicModelNode( m_classical
, title
, artist
, year
);
196 m_classical
->Append( child_node
);
198 if (m_classicalMusicIsKnownToControl
)
201 wxDataViewItem
child( (void*) child_node
);
202 wxDataViewItem
parent( (void*) m_classical
);
203 ItemAdded( parent
, child
);
207 void Delete( const wxDataViewItem
&item
)
209 MyMusicModelNode
*node
= (MyMusicModelNode
*) item
.GetID();
210 wxDataViewItem
parent( node
->GetParent() );
212 node
->GetParent()->GetChildren().Remove( node
);
216 ItemDeleted( parent
, item
);
219 // override sorting to always sort branches ascendingly
221 int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
222 unsigned int column
, bool ascending
)
224 if (IsContainer(item1
) && IsContainer(item2
))
226 wxVariant value1
,value2
;
227 GetValue( value1
, item1
, 0 );
228 GetValue( value2
, item2
, 0 );
230 wxString str1
= value1
.GetString();
231 wxString str2
= value2
.GetString();
232 int res
= str1
.Cmp( str2
);
235 // items must be different
236 unsigned long litem1
= (unsigned long) item1
.GetID();
237 unsigned long litem2
= (unsigned long) item2
.GetID();
239 return litem1
-litem2
;
242 return wxDataViewModel::Compare( item1
, item2
, column
, ascending
);
245 // implementation of base class virtuals to define model
247 virtual unsigned int GetColumnCount() const
252 virtual wxString
GetColumnType( unsigned int col
) const
257 return wxT("string");
260 virtual void GetValue( wxVariant
&variant
,
261 const wxDataViewItem
&item
, unsigned int col
) const
263 MyMusicModelNode
*node
= (MyMusicModelNode
*) item
.GetID();
266 case 0: variant
= node
->m_title
; break;
267 case 1: variant
= node
->m_artist
; break;
268 case 2: variant
= (long) node
->m_year
; break;
271 wxLogError( wxT("MyMusicModel::GetValue: wrong column" ));
273 // provoke a crash when mouse button down
274 wxMouseState state
= wxGetMouseState();
275 if (state
.ShiftDown())
284 virtual bool SetValue( const wxVariant
&variant
,
285 const wxDataViewItem
&item
, unsigned int col
)
287 MyMusicModelNode
*node
= (MyMusicModelNode
*) item
.GetID();
290 case 0: node
->m_title
= variant
.GetString(); return true;
291 case 1: node
->m_artist
= variant
.GetString(); return true;
292 case 2: node
->m_year
= variant
.GetLong(); return true;
293 default: wxLogError( wxT("MyMusicModel::SetValue: wrong column") );
298 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const
300 // the invisble root node has no parent
302 return wxDataViewItem(0);
304 MyMusicModelNode
*node
= (MyMusicModelNode
*) item
.GetID();
306 // "MyMusic" also has no parent
308 return wxDataViewItem(0);
310 return wxDataViewItem( (void*) node
->GetParent() );
313 virtual bool IsContainer( const wxDataViewItem
&item
) const
315 // the invisble root node can have children (in
316 // our model always "MyMusic")
320 MyMusicModelNode
*node
= (MyMusicModelNode
*) item
.GetID();
321 return node
->IsContainer();
324 virtual unsigned int GetChildren( const wxDataViewItem
&parent
, wxDataViewItemArray
&array
) const
326 MyMusicModelNode
*node
= (MyMusicModelNode
*) parent
.GetID();
329 array
.Add( wxDataViewItem( (void*) m_root
) );
333 if (node
== m_classical
)
335 MyMusicModel
*model
= (MyMusicModel
*)(const MyMusicModel
*) this;
336 model
->m_classicalMusicIsKnownToControl
= true;
339 if (node
->GetChildCount() == 0)
344 unsigned int count
= node
->GetChildren().GetCount();
346 for (pos
= 0; pos
< count
; pos
++)
348 MyMusicModelNode
*child
= node
->GetChildren().Item( pos
);
349 array
.Add( wxDataViewItem( (void*) child
) );
356 virtual bool IsDraggable( const wxDataViewItem
&item
)
359 return (!IsContainer(item
));
362 virtual size_t GetDragDataSize( const wxDataViewItem
&item
, const wxDataFormat
&WXUNUSED(format
) )
364 wxPrintf( "GetDragDataSize\n" );
366 MyMusicModelNode
*node
= (MyMusicModelNode
*) item
.GetID();
368 data
+= node
->m_title
; data
+= wxT(" ");
369 data
+= node
->m_artist
;
370 return strlen( data
.utf8_str() ) + 1;
372 virtual bool GetDragData( const wxDataViewItem
&item
, const wxDataFormat
&WXUNUSED(format
),
373 void* dest
, size_t WXUNUSED(size
) )
375 wxPrintf( "GetDragData\n" );
377 MyMusicModelNode
*node
= (MyMusicModelNode
*) item
.GetID();
379 data
+= node
->m_title
; data
+= wxT(" ");
380 data
+= node
->m_artist
;
381 wxCharBuffer
buffer( data
.utf8_str() );
382 memcpy( dest
, buffer
, strlen(buffer
)+1 );
387 MyMusicModelNode
* m_root
;
388 MyMusicModelNode
* m_pop
;
389 MyMusicModelNode
* m_classical
;
390 bool m_classicalMusicIsKnownToControl
;
394 static int my_sort_reverse( int *v1
, int *v2
)
399 static int my_sort( int *v1
, int *v2
)
404 class MyListModel
: public wxDataViewIndexListModel
409 wxDataViewIndexListModel( 1000 + 100 )
411 wxDataViewIndexListModel( 100000 + 100 )
415 m_virtualItems
= 1000;
417 m_virtualItems
= 100000;
421 for (i
= 0; i
< 100; i
++)
424 str
.Printf( wxT("row number %d"), i
);
428 m_icon
= wxIcon( null_xpm
);
431 // helper methods to change the model
433 void Prepend( const wxString
&text
)
435 m_array
.Insert( text
, 0 );
439 void DeleteItem( const wxDataViewItem
&item
)
441 unsigned int row
= GetRow( item
);
442 if (row
>= m_array
.GetCount())
445 m_array
.RemoveAt( row
);
449 void DeleteItems( const wxDataViewItemArray
&items
)
453 for (i
= 0; i
< items
.GetCount(); i
++)
455 unsigned int row
= GetRow( items
[i
] );
456 if (row
< m_array
.GetCount())
460 // Sort in descending order so that the last
461 // row will be deleted first. Otherwise the
462 // remaining indeces would all be wrong.
463 rows
.Sort( my_sort_reverse
);
464 for (i
= 0; i
< rows
.GetCount(); i
++)
465 m_array
.RemoveAt( rows
[i
] );
467 // This is just to test if wxDataViewCtrl can
468 // cope with removing rows not sorted in
470 rows
.Sort( my_sort
);
476 m_virtualItems
+= 1000;
477 Reset( m_array
.GetCount() + m_virtualItems
);
480 // implementation of base class virtuals to define model
482 virtual unsigned int GetColumnCount() const
487 virtual wxString
GetColumnType( unsigned int col
) const
490 return wxT("wxDataViewIconText");
492 return wxT("string");
495 virtual unsigned int GetRowCount()
497 return m_array
.GetCount();
500 virtual void GetValue( wxVariant
&variant
,
501 unsigned int row
, unsigned int col
) const
505 if (row
>= m_array
.GetCount())
508 str
.Printf(wxT("row %d"), row
- m_array
.GetCount() );
513 variant
= m_array
[ row
];
518 wxDataViewIconText
data( wxT("test"), m_icon
);
523 if (row
>= m_array
.GetCount())
524 variant
= wxT("plain");
526 variant
= wxT("blue");
530 virtual bool GetAttr( unsigned int row
, unsigned int col
, wxDataViewItemAttr
&attr
)
535 if (row
< m_array
.GetCount())
537 attr
.SetColour( *wxBLUE
);
538 attr
.SetItalic( true );
544 virtual bool SetValue( const wxVariant
&variant
,
545 unsigned int row
, unsigned int col
)
549 if (row
>= m_array
.GetCount())
552 m_array
[row
] = variant
.GetString();
559 wxArrayString m_array
;
564 // -------------------------------------
566 // -------------------------------------
568 class MyApp
: public wxApp
575 // -------------------------------------
577 // -------------------------------------
579 class MyFrame
: public wxFrame
582 MyFrame(wxFrame
*frame
, const wxString
&title
, int x
, int y
, int w
, int h
);
586 void OnQuit(wxCommandEvent
& event
);
587 void OnAbout(wxCommandEvent
& event
);
589 void OnAddMozart(wxCommandEvent
& event
);
590 void OnDeleteMusic(wxCommandEvent
& event
);
591 void OnDeleteYear(wxCommandEvent
& event
);
593 void OnPrependList(wxCommandEvent
& event
);
594 void OnDeleteList(wxCommandEvent
& event
);
596 void OnValueChanged( wxDataViewEvent
&event
);
598 void OnActivated( wxDataViewEvent
&event
);
599 void OnExpanding( wxDataViewEvent
&event
);
600 void OnExpanded( wxDataViewEvent
&event
);
601 void OnCollapsing( wxDataViewEvent
&event
);
602 void OnCollapsed( wxDataViewEvent
&event
);
603 void OnSelectionChanged( wxDataViewEvent
&event
);
605 void OnEditingStarted( wxDataViewEvent
&event
);
606 void OnEditingDone( wxDataViewEvent
&event
);
608 void OnHeaderClick( wxDataViewEvent
&event
);
609 void OnHeaderRightClick( wxDataViewEvent
&event
);
610 void OnSorted( wxDataViewEvent
&event
);
612 void OnContextMenu( wxDataViewEvent
&event
);
614 void OnRightClick( wxMouseEvent
&event
);
615 void OnGoto( wxCommandEvent
&event
);
616 void OnAddMany( wxCommandEvent
&event
);
619 wxDataViewCtrl
* m_musicCtrl
;
620 wxObjectDataPtr
<MyMusicModel
> m_music_model
;
622 wxDataViewCtrl
* m_listCtrl
;
623 wxObjectDataPtr
<MyListModel
> m_list_model
;
625 wxDataViewColumn
* m_col
;
631 DECLARE_EVENT_TABLE()
634 // -------------------------------------
636 // -------------------------------------
640 bool MyApp::OnInit(void)
642 if ( !wxApp::OnInit() )
645 // build the first frame
647 new MyFrame(NULL
, wxT("wxDataViewCtrl feature test"), 40, 40, 800, 540);
660 // -------------------------------------
662 // -------------------------------------
667 ID_ABOUT
= wxID_ABOUT
,
673 ID_DELETE_MUSIC
= 101,
674 ID_DELETE_YEAR
= 102,
676 ID_PREPEND_LIST
= 200,
677 ID_DELETE_LIST
= 201,
682 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
683 EVT_MENU( ID_ABOUT
, MyFrame::OnAbout
)
684 EVT_MENU( ID_EXIT
, MyFrame::OnQuit
)
685 EVT_BUTTON( ID_ADD_MOZART
, MyFrame::OnAddMozart
)
686 EVT_BUTTON( ID_DELETE_MUSIC
, MyFrame::OnDeleteMusic
)
687 EVT_BUTTON( ID_DELETE_YEAR
, MyFrame::OnDeleteYear
)
688 EVT_BUTTON( ID_PREPEND_LIST
, MyFrame::OnPrependList
)
689 EVT_BUTTON( ID_DELETE_LIST
, MyFrame::OnDeleteList
)
690 EVT_BUTTON( ID_GOTO
, MyFrame::OnGoto
)
691 EVT_BUTTON( ID_ADD_MANY
, MyFrame::OnAddMany
)
693 EVT_DATAVIEW_ITEM_VALUE_CHANGED( ID_MUSIC_CTRL
, MyFrame::OnValueChanged
)
695 EVT_DATAVIEW_ITEM_ACTIVATED(ID_MUSIC_CTRL
, MyFrame::OnActivated
)
696 EVT_DATAVIEW_ITEM_EXPANDING(ID_MUSIC_CTRL
, MyFrame::OnExpanding
)
697 EVT_DATAVIEW_ITEM_EXPANDED(ID_MUSIC_CTRL
, MyFrame::OnExpanded
)
698 EVT_DATAVIEW_ITEM_COLLAPSING(ID_MUSIC_CTRL
, MyFrame::OnCollapsing
)
699 EVT_DATAVIEW_ITEM_COLLAPSED(ID_MUSIC_CTRL
, MyFrame::OnCollapsed
)
700 EVT_DATAVIEW_SELECTION_CHANGED(ID_MUSIC_CTRL
, MyFrame::OnSelectionChanged
)
702 EVT_DATAVIEW_ITEM_EDITING_STARTED(ID_MUSIC_CTRL
, MyFrame::OnEditingStarted
)
703 EVT_DATAVIEW_ITEM_EDITING_DONE(ID_MUSIC_CTRL
, MyFrame::OnEditingDone
)
705 EVT_DATAVIEW_COLUMN_HEADER_CLICK(ID_MUSIC_CTRL
, MyFrame::OnHeaderClick
)
706 EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(ID_MUSIC_CTRL
, MyFrame::OnHeaderRightClick
)
707 EVT_DATAVIEW_COLUMN_SORTED(ID_MUSIC_CTRL
, MyFrame::OnSorted
)
709 EVT_DATAVIEW_ITEM_CONTEXT_MENU(ID_MUSIC_CTRL
, MyFrame::OnContextMenu
)
711 EVT_RIGHT_UP(MyFrame::OnRightClick
)
714 MyFrame::MyFrame(wxFrame
*frame
, const wxString
&title
, int x
, int y
, int w
, int h
):
715 wxFrame(frame
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(w
, h
))
720 SetIcon(wxICON(sample
));
724 wxMenu
*file_menu
= new wxMenu
;
725 file_menu
->Append(ID_ABOUT
, wxT("&About"));
726 file_menu
->AppendSeparator();
727 file_menu
->Append(ID_EXIT
, wxT("E&xit"));
729 wxMenuBar
*menu_bar
= new wxMenuBar
;
730 menu_bar
->Append(file_menu
, wxT("&File"));
732 SetMenuBar(menu_bar
);
735 wxBoxSizer
*main_sizer
= new wxBoxSizer( wxVERTICAL
);
737 wxBoxSizer
*data_sizer
= new wxBoxSizer( wxHORIZONTAL
);
741 m_musicCtrl
= new wxDataViewCtrl( this, ID_MUSIC_CTRL
, wxDefaultPosition
,
742 wxDefaultSize
, wxDV_MULTIPLE
);
744 m_music_model
= new MyMusicModel
;
745 m_musicCtrl
->AssociateModel( m_music_model
.get() );
748 // Call this and sorting is enabled
749 // immediatly upon start up.
750 wxDataViewColumn
*col
= m_musicCtrl
->AppendTextColumn( wxT("Title"), 0, wxDATAVIEW_CELL_INERT
, 200,
751 DEFAULT_ALIGN
, wxDATAVIEW_COL_SORTABLE
| wxDATAVIEW_COL_REORDERABLE
);
752 col
->SetSortOrder( true );
754 m_musicCtrl
->AppendTextColumn(wxT("Title"),0,wxDATAVIEW_CELL_INERT
,200,DEFAULT_ALIGN
,wxDATAVIEW_COL_SORTABLE
| wxDATAVIEW_COL_REORDERABLE
);
757 m_musicCtrl
->AppendTextColumn( wxT("Artist"), 1, wxDATAVIEW_CELL_EDITABLE
, 150,
758 DEFAULT_ALIGN
, wxDATAVIEW_COL_SORTABLE
| wxDATAVIEW_COL_REORDERABLE
);
760 wxDataViewSpinRenderer
*sr
= new wxDataViewSpinRenderer( 0, 2010 );
761 wxDataViewColumn
*column
= new wxDataViewColumn( wxT("year"), sr
, 2, -1, wxALIGN_CENTRE
, wxDATAVIEW_COL_SORTABLE
| wxDATAVIEW_COL_REORDERABLE
);
762 m_musicCtrl
->AppendColumn( column
);
764 data_sizer
->Add( m_musicCtrl
, 3, wxGROW
);
770 m_listCtrl
= new wxDataViewCtrl( this, wxID_ANY
, wxDefaultPosition
,
771 wxDefaultSize
, wxDV_MULTIPLE
| wxDV_ROW_LINES
);
773 m_list_model
= new MyListModel
;
774 m_listCtrl
->AssociateModel( m_list_model
.get() );
776 m_listCtrl
->AppendTextColumn (wxT("editable string"), 0, wxDATAVIEW_CELL_EDITABLE
, 120 );
777 m_listCtrl
->AppendIconTextColumn(wxT("icon"), 1, wxDATAVIEW_CELL_INERT
, 60 );
779 wxDataViewTextRendererAttr
*ra
= new wxDataViewTextRendererAttr
;
780 column
= new wxDataViewColumn(wxT("attributes"), ra
, 2 );
781 m_listCtrl
->AppendColumn( column
);
783 data_sizer
->Add( m_listCtrl
, 2, wxGROW
);
787 main_sizer
->Add( data_sizer
, 2, wxGROW
);
789 wxBoxSizer
*button_sizer
= new wxBoxSizer( wxHORIZONTAL
);
791 button_sizer
->Add( new wxButton( this, ID_ADD_MOZART
, _("Add Mozart")), 0, wxALL
, 10 );
792 button_sizer
->Add( new wxButton( this, ID_DELETE_MUSIC
,_("Delete selected")), 0, wxALL
, 10 );
793 button_sizer
->Add( new wxButton( this, ID_DELETE_YEAR
, _("Delete \"Year\" column")), 0, wxALL
, 10 );
794 button_sizer
->Add( 10, 10, 1 );
795 wxFlexGridSizer
*grid_sizer
= new wxFlexGridSizer( 2, 2 );
796 grid_sizer
->Add( new wxButton( this, ID_PREPEND_LIST
,_("Prepend")), 0, wxALL
, 2 );
797 grid_sizer
->Add( new wxButton( this, ID_DELETE_LIST
, _("Delete selected")), 0, wxALL
, 2 );
798 grid_sizer
->Add( new wxButton( this, ID_GOTO
, _("Goto 50")), 0, wxALL
, 2 );
799 grid_sizer
->Add( new wxButton( this, ID_ADD_MANY
, _("Add 1000")), 0, wxALL
, 2 );
800 button_sizer
->Add( grid_sizer
, 0, wxALL
, 10 );
802 main_sizer
->Add( button_sizer
, 0, wxGROW
, 0 );
804 wxBoxSizer
*bottom_sizer
= new wxBoxSizer( wxHORIZONTAL
);
806 m_log
= new wxTextCtrl( this, -1,wxString(), wxDefaultPosition
, wxDefaultSize
, wxTE_MULTILINE
);
807 m_logOld
= wxLog::SetActiveTarget(new wxLogTextCtrl(m_log
));
808 wxLogMessage(_("This is the log window"));
810 bottom_sizer
->Add( m_log
, 1, wxGROW
);
812 // wxDataViewTreeStore
814 wxDataViewCtrl
*treectrl
= new wxDataViewCtrl( this, -1,
815 wxDefaultPosition
, wxSize(300,200), wxDV_NO_HEADER
);
817 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
818 wxDataViewItem parent
= store
->AppendContainer( wxDataViewItem(0),wxT("Root 1"), wxIcon(small1_xpm
) );
819 wxDataViewItem child
= store
->AppendItem( parent
,wxT("Child 1"), wxIcon(small1_xpm
) );
820 child
= store
->AppendItem( parent
,wxT("Child 2"), wxIcon(small1_xpm
) );
821 child
= store
->AppendItem( parent
,wxT("Child 3"), wxIcon(small1_xpm
) );
822 treectrl
->AssociateModel( store
);
825 treectrl
->AppendIconTextColumn(wxT("no label"), 0, wxDATAVIEW_CELL_INERT
, 200 );
827 bottom_sizer
->Add( treectrl
);
829 // wxDataViewTreeCtrl
831 wxDataViewTreeCtrl
*treectrl2
= new wxDataViewTreeCtrl( this, -1, wxDefaultPosition
, wxSize(300,200) );
833 wxImageList
*ilist
= new wxImageList( 16, 16 );
834 ilist
->Add( wxIcon(small1_xpm
) );
835 treectrl2
->SetImageList( ilist
);
837 parent
= treectrl2
->AppendContainer( wxDataViewItem(0),wxT("Root 1"), 0 );
838 child
= treectrl2
->AppendItem( parent
,wxT("Child 1"), 0 );
839 child
= treectrl2
->AppendItem( parent
,wxT("Child 2"), 0 );
840 child
= treectrl2
->AppendItem( parent
,wxT("Child 3"), 0 );
842 bottom_sizer
->Add( treectrl2
);
846 main_sizer
->Add( bottom_sizer
, 0, wxGROW
);
848 SetSizer( main_sizer
);
853 delete wxLog::SetActiveTarget(m_logOld
);
856 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
) )
861 void MyFrame::OnAddMozart(wxCommandEvent
& WXUNUSED(event
) )
863 m_music_model
->AddToClassical( wxT("Kleine Nachtmusik"), wxT("Wolfgang Mozart"), 1787 );
866 void MyFrame::OnDeleteMusic(wxCommandEvent
& WXUNUSED(event
) )
868 wxDataViewItemArray items
;
869 int len
= m_musicCtrl
->GetSelections( items
);
870 for( int i
= 0; i
< len
; i
++ )
872 m_music_model
->Delete( items
[i
] );
875 void MyFrame::OnDeleteYear( wxCommandEvent
& WXUNUSED(event
) )
877 m_musicCtrl
->DeleteColumn( m_musicCtrl
->GetColumn( 2 ) );
878 FindWindow( ID_DELETE_YEAR
)->Disable();
881 void MyFrame::OnPrependList( wxCommandEvent
& WXUNUSED(event
) )
883 m_list_model
->Prepend(wxT("Test"));
886 void MyFrame::OnDeleteList( wxCommandEvent
& WXUNUSED(event
) )
888 wxDataViewItemArray items
;
889 int len
= m_listCtrl
->GetSelections( items
);
891 m_list_model
->DeleteItems( items
);
894 void MyFrame::OnValueChanged( wxDataViewEvent
&event
)
899 wxLogMessage( wxT("EVT_DATAVIEW_ITEM_VALUE_CHANGED, Item Id: %d; Column: %d"), event
.GetItem().GetID(), event
.GetColumn() );
902 void MyFrame::OnActivated( wxDataViewEvent
&event
)
907 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
908 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item: %s"), title
.GetData());
911 void MyFrame::OnSelectionChanged( wxDataViewEvent
&event
)
916 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
920 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, First selected Item: %s"), title
.GetData() );
923 void MyFrame::OnExpanding( wxDataViewEvent
&event
)
928 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
929 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, Item: %s"), title
.GetData() );
933 void MyFrame::OnEditingStarted( wxDataViewEvent
&event
)
938 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
939 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, Item: %s"), title
.GetData() );
942 void MyFrame::OnEditingDone( wxDataViewEvent
&event
)
947 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
948 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, Item: %s"), title
.GetData() );
951 void MyFrame::OnExpanded( wxDataViewEvent
&event
)
956 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
957 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, Item: %s"), title
.GetData() );
960 void MyFrame::OnCollapsing( wxDataViewEvent
&event
)
965 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
966 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, Item: %s"), title
.GetData() );
969 void MyFrame::OnCollapsed( wxDataViewEvent
&event
)
974 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
975 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, Item: %s"),title
.GetData());
978 void MyFrame::OnContextMenu( wxDataViewEvent
&event
)
983 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
984 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s"),title
.GetData());
987 void MyFrame::OnHeaderClick( wxDataViewEvent
&event
)
992 int pos
= m_musicCtrl
->GetColumnPosition( event
.GetDataViewColumn() );
994 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, Column position: %d"), pos
);
997 void MyFrame::OnHeaderRightClick( wxDataViewEvent
&event
)
1002 int pos
= m_musicCtrl
->GetColumnPosition( event
.GetDataViewColumn() );
1004 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, Column position: %d"), pos
);
1007 void MyFrame::OnSorted( wxDataViewEvent
&event
)
1012 int pos
= m_musicCtrl
->GetColumnPosition( event
.GetDataViewColumn() );
1014 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, Column position: %d"), pos
);
1017 void MyFrame::OnRightClick( wxMouseEvent
&event
)
1022 wxLogMessage(wxT("wxEVT_MOUSE_RIGHT_UP, Click Point is X: %d, Y: %d"), event
.GetX(), event
.GetY());
1025 void MyFrame::OnGoto(wxCommandEvent
& WXUNUSED(event
))
1027 wxDataViewItem item
= m_list_model
->GetItem( 50 );
1028 m_listCtrl
->EnsureVisible(item
,m_col
);
1031 void MyFrame::OnAddMany(wxCommandEvent
& WXUNUSED(event
))
1033 m_list_model
->AddMany();
1037 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
1039 wxAboutDialogInfo info
;
1040 info
.SetName(_("DataView sample"));
1041 info
.SetDescription(_("This sample demonstrates the dataview control handling"));
1042 info
.SetCopyright(_T("(C) 2007 Robert Roebling"));