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 // ============================================================================
14 // ============================================================================
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/dataview.h"
28 #include "wx/datetime.h"
29 #include "wx/splitter.h"
30 #include "wx/aboutdlg.h"
31 #include "wx/choicdlg.h"
32 #include "wx/numdlg.h"
33 #include "wx/spinctrl.h"
34 #include "wx/imaglist.h"
35 #include "wx/notebook.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
44 #include "../sample.xpm"
47 #include "wx_small.xpm"
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 class MyApp
: public wxApp
56 virtual bool OnInit();
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 class MyFrame
: public wxFrame
66 MyFrame(wxFrame
*frame
, const wxString
&title
, int x
, int y
, int w
, int h
);
70 void OnQuit(wxCommandEvent
& event
);
71 void OnAbout(wxCommandEvent
& event
);
73 void OnAddMozart(wxCommandEvent
& event
);
74 void OnDeleteMusic(wxCommandEvent
& event
);
75 void OnDeleteYear(wxCommandEvent
& event
);
76 void OnSelectNinth(wxCommandEvent
& event
);
78 void OnPrependList(wxCommandEvent
& event
);
79 void OnDeleteList(wxCommandEvent
& event
);
81 void OnValueChanged( wxDataViewEvent
&event
);
83 void OnActivated( wxDataViewEvent
&event
);
84 void OnExpanding( wxDataViewEvent
&event
);
85 void OnExpanded( wxDataViewEvent
&event
);
86 void OnCollapsing( wxDataViewEvent
&event
);
87 void OnCollapsed( wxDataViewEvent
&event
);
88 void OnSelectionChanged( wxDataViewEvent
&event
);
90 void OnEditingStarted( wxDataViewEvent
&event
);
91 void OnEditingDone( wxDataViewEvent
&event
);
93 void OnHeaderClick( wxDataViewEvent
&event
);
94 void OnHeaderRightClick( wxDataViewEvent
&event
);
95 void OnSorted( wxDataViewEvent
&event
);
97 void OnContextMenu( wxDataViewEvent
&event
);
99 void OnRightClick( wxMouseEvent
&event
);
100 void OnGoto( wxCommandEvent
&event
);
101 void OnAddMany( wxCommandEvent
&event
);
103 void OnBeginDrag( wxDataViewEvent
&event
);
104 void OnDropPossible( wxDataViewEvent
&event
);
105 void OnDrop( wxDataViewEvent
&event
);
108 wxNotebook
* m_notebook
;
110 // the controls stored in the various tabs of the main notebook:
112 wxDataViewCtrl
* m_myMusicModelViewCtrl
;
113 wxObjectDataPtr
<MyMusicTreeModel
> m_music_model
;
115 wxDataViewCtrl
* m_myListModelViewCtrl
;
116 wxObjectDataPtr
<MyListModel
> m_list_model
;
118 wxDataViewListCtrl
* m_listctrl
;
119 wxDataViewTreeCtrl
* m_treectrl
;
123 wxDataViewColumn
* m_col
;
129 DECLARE_EVENT_TABLE()
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 class MyCustomRenderer
: public wxDataViewCustomRenderer
140 MyCustomRenderer( wxDataViewCellMode mode
, int alignment
) :
141 wxDataViewCustomRenderer( wxString("long"), mode
, alignment
)
144 virtual bool Render( wxRect rect
, wxDC
*dc
, int WXUNUSED(state
) )
146 dc
->SetBrush( *wxRED_BRUSH
);
147 dc
->SetPen( *wxTRANSPARENT_PEN
);
148 dc
->DrawRectangle( rect
);
153 virtual bool Activate( wxRect
WXUNUSED(cell
),
154 wxDataViewModel
*WXUNUSED(model
),
155 const wxDataViewItem
&WXUNUSED(item
),
156 unsigned int WXUNUSED(col
) )
158 wxLogMessage( wxT("MyCustomRenderer Activate()") );
162 virtual bool LeftClick( wxPoint cursor
, wxRect
WXUNUSED(cell
),
163 wxDataViewModel
*WXUNUSED(model
),
164 const wxDataViewItem
&WXUNUSED(item
),
165 unsigned int WXUNUSED(col
) )
167 wxLogMessage( wxT("MyCustomRenderer LeftClick( %d, %d )"), cursor
.x
, cursor
.y
);
171 virtual wxSize
GetSize() const
173 //return wxSize(60,m_height);
174 return wxSize(60,20);
177 virtual bool SetValue( const wxVariant
&value
)
183 virtual bool GetValue( wxVariant
&WXUNUSED(value
) ) const { return true; }
190 // ============================================================================
192 // ============================================================================
194 // ----------------------------------------------------------------------------
196 // ----------------------------------------------------------------------------
202 if ( !wxApp::OnInit() )
206 new MyFrame(NULL
, wxT("wxDataViewCtrl sample"), 40, 40, 1000, 540);
214 // ----------------------------------------------------------------------------
216 // ----------------------------------------------------------------------------
221 ID_ABOUT
= wxID_ABOUT
,
227 ID_DELETE_MUSIC
= 101,
228 ID_DELETE_YEAR
= 102,
229 ID_SELECT_NINTH
= 103,
231 ID_PREPEND_LIST
= 200,
232 ID_DELETE_LIST
= 201,
237 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
238 EVT_MENU( ID_ABOUT
, MyFrame::OnAbout
)
239 EVT_MENU( ID_EXIT
, MyFrame::OnQuit
)
240 EVT_BUTTON( ID_ADD_MOZART
, MyFrame::OnAddMozart
)
241 EVT_BUTTON( ID_DELETE_MUSIC
, MyFrame::OnDeleteMusic
)
242 EVT_BUTTON( ID_DELETE_YEAR
, MyFrame::OnDeleteYear
)
243 EVT_BUTTON( ID_SELECT_NINTH
, MyFrame::OnSelectNinth
)
244 EVT_BUTTON( ID_PREPEND_LIST
, MyFrame::OnPrependList
)
245 EVT_BUTTON( ID_DELETE_LIST
, MyFrame::OnDeleteList
)
246 EVT_BUTTON( ID_GOTO
, MyFrame::OnGoto
)
247 EVT_BUTTON( ID_ADD_MANY
, MyFrame::OnAddMany
)
249 EVT_DATAVIEW_ITEM_VALUE_CHANGED( ID_MUSIC_CTRL
, MyFrame::OnValueChanged
)
251 EVT_DATAVIEW_ITEM_ACTIVATED(ID_MUSIC_CTRL
, MyFrame::OnActivated
)
252 EVT_DATAVIEW_ITEM_EXPANDING(ID_MUSIC_CTRL
, MyFrame::OnExpanding
)
253 EVT_DATAVIEW_ITEM_EXPANDED(ID_MUSIC_CTRL
, MyFrame::OnExpanded
)
254 EVT_DATAVIEW_ITEM_COLLAPSING(ID_MUSIC_CTRL
, MyFrame::OnCollapsing
)
255 EVT_DATAVIEW_ITEM_COLLAPSED(ID_MUSIC_CTRL
, MyFrame::OnCollapsed
)
256 EVT_DATAVIEW_SELECTION_CHANGED(ID_MUSIC_CTRL
, MyFrame::OnSelectionChanged
)
258 EVT_DATAVIEW_ITEM_EDITING_STARTED(ID_MUSIC_CTRL
, MyFrame::OnEditingStarted
)
259 EVT_DATAVIEW_ITEM_EDITING_DONE(ID_MUSIC_CTRL
, MyFrame::OnEditingDone
)
261 EVT_DATAVIEW_COLUMN_HEADER_CLICK(ID_MUSIC_CTRL
, MyFrame::OnHeaderClick
)
262 EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(ID_MUSIC_CTRL
, MyFrame::OnHeaderRightClick
)
263 EVT_DATAVIEW_COLUMN_SORTED(ID_MUSIC_CTRL
, MyFrame::OnSorted
)
265 EVT_DATAVIEW_ITEM_CONTEXT_MENU(ID_MUSIC_CTRL
, MyFrame::OnContextMenu
)
267 EVT_DATAVIEW_ITEM_BEGIN_DRAG( ID_MUSIC_CTRL
, MyFrame::OnBeginDrag
)
268 EVT_DATAVIEW_ITEM_DROP_POSSIBLE( ID_MUSIC_CTRL
, MyFrame::OnDropPossible
)
269 EVT_DATAVIEW_ITEM_DROP( ID_MUSIC_CTRL
, MyFrame::OnDrop
)
271 EVT_RIGHT_UP(MyFrame::OnRightClick
)
274 MyFrame::MyFrame(wxFrame
*frame
, const wxString
&title
, int x
, int y
, int w
, int h
):
275 wxFrame(frame
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(w
, h
))
280 SetIcon(wxICON(sample
));
286 wxMenu
*file_menu
= new wxMenu
;
287 file_menu
->Append(ID_ABOUT
, wxT("&About"));
288 file_menu
->AppendSeparator();
289 file_menu
->Append(ID_EXIT
, wxT("E&xit"));
291 wxMenuBar
*menu_bar
= new wxMenuBar
;
292 menu_bar
->Append(file_menu
, wxT("&File"));
294 SetMenuBar(menu_bar
);
298 // first page of the notebook
299 // --------------------------
301 m_notebook
= new wxNotebook( this, wxID_ANY
);
303 wxPanel
*firstPanel
= new wxPanel( m_notebook
, wxID_ANY
);
304 m_myMusicModelViewCtrl
=
305 new wxDataViewCtrl( firstPanel
, ID_MUSIC_CTRL
, wxDefaultPosition
,
306 wxDefaultSize
, wxDV_MULTIPLE
|wxDV_VARIABLE_LINE_HEIGHT
);
308 m_music_model
= new MyMusicTreeModel
;
309 m_myMusicModelViewCtrl
->AssociateModel( m_music_model
.get() );
311 m_myMusicModelViewCtrl
->EnableDragSource( wxDF_UNICODETEXT
);
312 m_myMusicModelViewCtrl
->EnableDropTarget( wxDF_UNICODETEXT
);
314 // column 0 of the view control:
316 wxDataViewTextRenderer
*tr
=
317 new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_INERT
);
318 wxDataViewColumn
*column0
=
319 new wxDataViewColumn( wxT("title"), tr
, 0, 200, wxALIGN_LEFT
,
320 wxDATAVIEW_COL_SORTABLE
| wxDATAVIEW_COL_RESIZABLE
);
321 m_myMusicModelViewCtrl
->AppendColumn( column0
);
323 // Call this and sorting is enabled
324 // immediatly upon start up.
325 column0
->SetAsSortKey();
328 // column 1 of the view control:
330 tr
= new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE
);
331 wxDataViewColumn
*column1
=
332 new wxDataViewColumn( wxT("artist"), tr
, 1, 150, wxALIGN_LEFT
,
333 wxDATAVIEW_COL_SORTABLE
| wxDATAVIEW_COL_REORDERABLE
|
334 wxDATAVIEW_COL_RESIZABLE
);
335 column1
->SetMinWidth(150); // this column can't be resized to be smaller
336 m_myMusicModelViewCtrl
->AppendColumn( column1
);
338 // column 2 of the view control:
340 wxDataViewSpinRenderer
*sr
=
341 new wxDataViewSpinRenderer( 0, 2010, wxDATAVIEW_CELL_EDITABLE
, wxALIGN_RIGHT
);
342 wxDataViewColumn
*column2
=
343 new wxDataViewColumn( wxT("year"), sr
, 2, 60, wxALIGN_LEFT
,
344 wxDATAVIEW_COL_SORTABLE
| wxDATAVIEW_COL_REORDERABLE
);
345 m_myMusicModelViewCtrl
->AppendColumn( column2
);
347 // column 3 of the view control:
349 wxArrayString choices
;
350 choices
.Add( "good" );
351 choices
.Add( "bad" );
352 choices
.Add( "lousy" );
353 wxDataViewChoiceRenderer
*c
=
354 new wxDataViewChoiceRenderer( choices
, wxDATAVIEW_CELL_EDITABLE
, wxALIGN_RIGHT
);
355 wxDataViewColumn
*column3
=
356 new wxDataViewColumn( wxT("rating"), c
, 3, 100, wxALIGN_LEFT
,
357 wxDATAVIEW_COL_REORDERABLE
| wxDATAVIEW_COL_RESIZABLE
);
358 m_myMusicModelViewCtrl
->AppendColumn( column3
);
360 // column 4 of the view control:
362 m_myMusicModelViewCtrl
->AppendProgressColumn( wxT("popularity"), 4, wxDATAVIEW_CELL_INERT
, 80 );
364 // column 5 of the view control:
366 MyCustomRenderer
*cr
= new MyCustomRenderer( wxDATAVIEW_CELL_ACTIVATABLE
, wxALIGN_RIGHT
);
367 wxDataViewColumn
*column5
=
368 new wxDataViewColumn( wxT("custom"), cr
, 5, -1, wxALIGN_LEFT
,
369 wxDATAVIEW_COL_RESIZABLE
);
370 m_myMusicModelViewCtrl
->AppendColumn( column5
);
372 // complete this page:
374 wxBoxSizer
*button_sizer
= new wxBoxSizer( wxHORIZONTAL
);
375 button_sizer
->Add( new wxButton( firstPanel
, ID_ADD_MOZART
, _("Add Mozart")), 0, wxALL
, 10 );
376 button_sizer
->Add( new wxButton( firstPanel
, ID_DELETE_MUSIC
,_("Delete selected")), 0, wxALL
, 10 );
377 button_sizer
->Add( new wxButton( firstPanel
, ID_DELETE_YEAR
, _("Delete \"Year\" column")), 0, wxALL
, 10 );
378 button_sizer
->Add( new wxButton( firstPanel
, ID_SELECT_NINTH
,_("Select Ninth")), 0, wxALL
, 10 );
380 wxSizer
*firstPanelSz
= new wxBoxSizer( wxVERTICAL
);
381 m_myMusicModelViewCtrl
->SetMinSize(wxSize(-1, 200));
382 firstPanelSz
->Add(m_myMusicModelViewCtrl
, 1, wxGROW
|wxALL
, 5);
383 firstPanelSz
->Add(button_sizer
);
384 firstPanel
->SetSizerAndFit(firstPanelSz
);
387 // second page of the notebook
388 // ---------------------------
390 wxPanel
*secondPanel
= new wxPanel( m_notebook
, wxID_ANY
);
392 m_myListModelViewCtrl
= new wxDataViewCtrl( secondPanel
, wxID_ANY
, wxDefaultPosition
,
393 wxDefaultSize
, wxDV_MULTIPLE
| wxDV_ROW_LINES
);
395 m_list_model
= new MyListModel
;
396 m_myListModelViewCtrl
->AssociateModel( m_list_model
.get() );
398 // the various columns
400 m_myListModelViewCtrl
->AppendTextColumn (wxT("editable string"), 0, wxDATAVIEW_CELL_EDITABLE
, 120 );
401 m_myListModelViewCtrl
->AppendIconTextColumn(wxIcon(wx_small_xpm
), 1, wxDATAVIEW_CELL_INERT
)->SetTitle( wxT("icon") );
403 m_myListModelViewCtrl
->AppendTextColumn (wxT("editable string"), 0, wxDATAVIEW_CELL_EDITABLE
);
404 m_myListModelViewCtrl
->AppendIconTextColumn(wxT("icon"), 1, wxDATAVIEW_CELL_INERT
);
406 m_myListModelViewCtrl
->AppendColumn(
407 new wxDataViewColumn(wxT("attributes"), new wxDataViewTextRendererAttr
, 2 ));
409 // complete this page:
411 wxBoxSizer
*button_sizer2
= new wxBoxSizer( wxHORIZONTAL
);
412 button_sizer2
->Add( new wxButton( secondPanel
, ID_PREPEND_LIST
,_("Prepend")), 0, wxALL
, 10 );
413 button_sizer2
->Add( new wxButton( secondPanel
, ID_DELETE_LIST
, _("Delete selected")), 0, wxALL
, 10 );
414 button_sizer2
->Add( new wxButton( secondPanel
, ID_GOTO
, _("Goto 50")), 0, wxALL
, 10 );
415 button_sizer2
->Add( new wxButton( secondPanel
, ID_ADD_MANY
, _("Add 1000")), 0, wxALL
, 10 );
417 wxSizer
*secondPanelSz
= new wxBoxSizer( wxVERTICAL
);
418 secondPanelSz
->Add(m_myListModelViewCtrl
, 1, wxGROW
|wxALL
, 5);
419 secondPanelSz
->Add(button_sizer2
);
420 secondPanel
->SetSizerAndFit(secondPanelSz
);
424 // third page of the notebook
425 // ---------------------------
427 wxPanel
*thirdPanel
= new wxPanel( m_notebook
, wxID_ANY
);
429 m_listctrl
= new wxDataViewListCtrl( thirdPanel
, wxID_ANY
);
430 m_listctrl
->AppendToggleColumn( wxT("Toggle") );
431 m_listctrl
->AppendTextColumn( wxT("Text") );
433 wxVector
<wxVariant
> data
;
434 data
.push_back( true );
435 data
.push_back( "row 1" );
436 m_listctrl
->AppendItem( data
);
439 data
.push_back( false );
440 data
.push_back( "row 3" );
441 m_listctrl
->AppendItem( data
);
443 // complete this page:
445 wxSizer
*thirdPanelSz
= new wxBoxSizer( wxVERTICAL
);
446 thirdPanelSz
->Add(m_listctrl
, 1, wxGROW
|wxALL
, 5);
447 thirdPanel
->SetSizerAndFit(thirdPanelSz
);
450 // fourth page of the notebook
451 // ---------------------------
453 wxPanel
*fourthPanel
= new wxPanel( m_notebook
, wxID_ANY
);
455 m_treectrl
= new wxDataViewTreeCtrl( fourthPanel
, wxID_ANY
);
457 wxImageList
*ilist
= new wxImageList( 16, 16 );
458 ilist
->Add( wxIcon(wx_small_xpm
) );
459 m_treectrl
->SetImageList( ilist
);
461 wxDataViewItem parent2
= m_treectrl
->AppendContainer( wxDataViewItem(0),wxT("Root 1"), 0 );
462 m_treectrl
->AppendItem( parent2
, wxT("Child 1"), 0 );
463 m_treectrl
->AppendItem( parent2
, wxT("Child 2"), 0 );
464 m_treectrl
->AppendItem( parent2
, wxT("Child 3, very long, long, long, long"), 0 );
466 // complete this page:
468 wxSizer
*fourthPanelSz
= new wxBoxSizer( wxVERTICAL
);
469 fourthPanelSz
->Add(m_treectrl
, 1, wxGROW
|wxALL
, 5);
470 fourthPanel
->SetSizerAndFit(fourthPanelSz
);
477 m_notebook
->AddPage(firstPanel
, "MyMusicTreeModel");
478 m_notebook
->AddPage(secondPanel
, "MyListModel");
479 m_notebook
->AddPage(thirdPanel
, "wxDataViewListCtrl");
480 m_notebook
->AddPage(fourthPanel
, "wxDataViewTreeCtrl");
482 wxSizer
* mainSizer
= new wxBoxSizer(wxVERTICAL
);
484 m_log
= new wxTextCtrl( this, wxID_ANY
, wxString(), wxDefaultPosition
,
485 wxDefaultSize
, wxTE_MULTILINE
);
486 m_log
->SetMinSize(wxSize(-1, 100));
487 m_logOld
= wxLog::SetActiveTarget(new wxLogTextCtrl(m_log
));
488 wxLogMessage(_("This is the log window"));
490 mainSizer
->Add( m_notebook
, 1, wxGROW
);
491 mainSizer
->Add( m_log
, 0, wxGROW
);
493 SetSizerAndFit(mainSizer
);
498 delete wxLog::SetActiveTarget(m_logOld
);
501 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
) )
506 void MyFrame::OnAddMozart(wxCommandEvent
& WXUNUSED(event
) )
508 m_music_model
->AddToClassical( wxT("Kleine Nachtmusik"), wxT("Wolfgang Mozart"), 1787 );
511 void MyFrame::OnDeleteMusic(wxCommandEvent
& WXUNUSED(event
) )
513 wxDataViewItemArray items
;
514 int len
= m_myMusicModelViewCtrl
->GetSelections( items
);
515 for( int i
= 0; i
< len
; i
++ )
517 m_music_model
->Delete( items
[i
] );
520 void MyFrame::OnDeleteYear( wxCommandEvent
& WXUNUSED(event
) )
522 m_myMusicModelViewCtrl
->DeleteColumn( m_myMusicModelViewCtrl
->GetColumn( 2 ) );
523 FindWindow( ID_DELETE_YEAR
)->Disable();
526 void MyFrame::OnSelectNinth( wxCommandEvent
& WXUNUSED(event
) )
528 m_myMusicModelViewCtrl
->Select( m_music_model
->GetNinthItem() );
531 void MyFrame::OnPrependList( wxCommandEvent
& WXUNUSED(event
) )
533 m_list_model
->Prepend(wxT("Test"));
536 void MyFrame::OnDeleteList( wxCommandEvent
& WXUNUSED(event
) )
538 wxDataViewItemArray items
;
539 int len
= m_myListModelViewCtrl
->GetSelections( items
);
541 m_list_model
->DeleteItems( items
);
544 void MyFrame::OnValueChanged( wxDataViewEvent
&event
)
549 wxLogMessage( wxT("EVT_DATAVIEW_ITEM_VALUE_CHANGED, Item Id: %d; Column: %d"),
550 event
.GetItem().GetID(), event
.GetColumn() );
553 void MyFrame::OnActivated( wxDataViewEvent
&event
)
558 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
559 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item: %s"), title
);
561 if (m_myMusicModelViewCtrl
->IsExpanded( event
.GetItem() ))
562 wxLogMessage(wxT("Item: %s is expanded"), title
);
565 void MyFrame::OnSelectionChanged( wxDataViewEvent
&event
)
570 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
574 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, First selected Item: %s"), title
);
577 void MyFrame::OnExpanding( wxDataViewEvent
&event
)
582 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
583 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, Item: %s"), title
);
587 void MyFrame::OnEditingStarted( wxDataViewEvent
&event
)
592 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
593 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, Item: %s"), title
);
596 void MyFrame::OnEditingDone( wxDataViewEvent
&event
)
601 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
602 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, Item: %s"), title
);
605 void MyFrame::OnExpanded( wxDataViewEvent
&event
)
610 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
611 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, Item: %s"), title
);
614 void MyFrame::OnCollapsing( wxDataViewEvent
&event
)
619 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
620 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, Item: %s"), title
);
623 void MyFrame::OnCollapsed( wxDataViewEvent
&event
)
628 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
629 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, Item: %s"),title
);
632 void MyFrame::OnContextMenu( wxDataViewEvent
&event
)
637 wxString title
= m_music_model
->GetTitle( event
.GetItem() );
638 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s"),title
);
641 menu
.Append( 1, wxT("entry 1") );
642 menu
.Append( 2, wxT("entry 2") );
643 menu
.Append( 3, wxT("entry 3") );
645 m_myMusicModelViewCtrl
->PopupMenu(&menu
);
647 // wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s Value: %s"),
648 // title.GetData(), event.GetValue().GetString());
651 void MyFrame::OnHeaderClick( wxDataViewEvent
&event
)
653 // we need to skip the event to let the default behaviour of sorting by
654 // this column when it is clicked to take place
660 int pos
= m_myMusicModelViewCtrl
->GetColumnPosition( event
.GetDataViewColumn() );
662 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, Column position: %d"), pos
);
665 void MyFrame::OnHeaderRightClick( wxDataViewEvent
&event
)
670 int pos
= m_myMusicModelViewCtrl
->GetColumnPosition( event
.GetDataViewColumn() );
672 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, Column position: %d"), pos
);
675 void MyFrame::OnSorted( wxDataViewEvent
&event
)
680 int pos
= m_myMusicModelViewCtrl
->GetColumnPosition( event
.GetDataViewColumn() );
682 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, Column position: %d"), pos
);
685 void MyFrame::OnRightClick( wxMouseEvent
&event
)
690 wxLogMessage(wxT("wxEVT_MOUSE_RIGHT_UP, Click Point is X: %d, Y: %d"),
691 event
.GetX(), event
.GetY());
694 void MyFrame::OnGoto(wxCommandEvent
& WXUNUSED(event
))
696 wxDataViewItem item
= m_list_model
->GetItem( 50 );
697 m_myListModelViewCtrl
->EnsureVisible(item
,m_col
);
700 void MyFrame::OnAddMany(wxCommandEvent
& WXUNUSED(event
))
702 m_list_model
->AddMany();
706 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
708 wxAboutDialogInfo info
;
709 info
.SetName(_("DataView sample"));
710 info
.SetDescription(_("This sample demonstrates wxDataViewCtrl"));
711 info
.SetCopyright(_T("(C) 2007-2009 Robert Roebling"));
712 info
.AddDeveloper("Robert Roebling");
713 info
.AddDeveloper("Francesco Montorsi");
718 void MyFrame::OnBeginDrag( wxDataViewEvent
&event
)
720 wxDataViewItem
item( event
.GetItem() );
722 // only allow drags for item, not containers
723 if (m_music_model
->IsContainer( item
) )
729 MyMusicTreeModelNode
*node
= (MyMusicTreeModelNode
*) item
.GetID();
730 wxTextDataObject
*obj
= new wxTextDataObject
;
731 obj
->SetText( node
->m_title
);
732 event
.SetDataObject( obj
);
735 void MyFrame::OnDropPossible( wxDataViewEvent
&event
)
737 wxDataViewItem
item( event
.GetItem() );
739 // only allow drags for item, not containers
740 if (m_music_model
->IsContainer( item
) )
743 if (event
.GetDataFormat() != wxDF_UNICODETEXT
)
747 void MyFrame::OnDrop( wxDataViewEvent
&event
)
749 wxDataViewItem
item( event
.GetItem() );
751 // only allow drops for item, not containers
752 if (m_music_model
->IsContainer( item
) )
758 if (event
.GetDataFormat() != wxDF_UNICODETEXT
)
764 wxTextDataObject obj
;
765 obj
.SetData( wxDF_TEXT
, event
.GetDataSize(), event
.GetDataBuffer() );
767 wxLogMessage(wxT("Text dropped: %s"), obj
.GetText() );