]> git.saurik.com Git - wxWidgets.git/blob - samples/dataview/dataview.cpp
Don't ask for wxTextAttr colour if it doesn't have any in text sample.
[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 licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 #include "wx/dataview.h"
28 #include "wx/datetime.h"
29 #include "wx/splitter.h"
30 #include "wx/aboutdlg.h"
31 #include "wx/colordlg.h"
32 #include "wx/choicdlg.h"
33 #include "wx/numdlg.h"
34 #include "wx/spinctrl.h"
35 #include "wx/imaglist.h"
36 #include "wx/notebook.h"
37
38 #include "mymodels.h"
39
40 // ----------------------------------------------------------------------------
41 // resources
42 // ----------------------------------------------------------------------------
43
44 #ifndef __WXMSW__
45 #include "../sample.xpm"
46 #endif
47
48 #include "wx_small.xpm"
49
50 // ----------------------------------------------------------------------------
51 // MyApp
52 // ----------------------------------------------------------------------------
53
54 class MyApp: public wxApp
55 {
56 public:
57 virtual bool OnInit();
58 };
59
60 // ----------------------------------------------------------------------------
61 // MyFrame
62 // ----------------------------------------------------------------------------
63
64 class MyFrame : public wxFrame
65 {
66 public:
67 MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int h);
68 ~MyFrame();
69
70 void BuildDataViewCtrl(wxPanel* parent,
71 unsigned int nPanel,
72 unsigned long style = 0);
73
74 private:
75 // event handlers
76 void OnStyleChange(wxCommandEvent& event);
77 void OnSetBackgroundColour(wxCommandEvent& event);
78 void OnSetForegroundColour(wxCommandEvent& event);
79 void OnQuit(wxCommandEvent& event);
80 void OnAbout(wxCommandEvent& event);
81
82 void OnClearLog(wxCommandEvent& event);
83 void OnPageChanged(wxBookCtrlEvent& event);
84
85 void OnAddMozart(wxCommandEvent& event);
86 void OnDeleteSelected(wxCommandEvent& event);
87 void OnDeleteYear(wxCommandEvent& event);
88 void OnSelectNinth(wxCommandEvent& event);
89 void OnCollapse(wxCommandEvent& event);
90 void OnExpand(wxCommandEvent& event);
91 void OnShowCurrent(wxCommandEvent& event);
92 void OnSetNinthCurrent(wxCommandEvent& event);
93
94 void OnPrependList(wxCommandEvent& event);
95 void OnDeleteList(wxCommandEvent& event);
96 // Fourth page.
97 void OnDeleteTreeItem(wxCommandEvent& event);
98 void OnDeleteAllTreeItems(wxCommandEvent& event);
99 void OnAddTreeItem(wxCommandEvent& event);
100 void OnAddTreeContainerItem(wxCommandEvent& event);
101
102 void OnValueChanged( wxDataViewEvent &event );
103
104 void OnActivated( wxDataViewEvent &event );
105 void OnExpanding( wxDataViewEvent &event );
106 void OnExpanded( wxDataViewEvent &event );
107 void OnCollapsing( wxDataViewEvent &event );
108 void OnCollapsed( wxDataViewEvent &event );
109 void OnSelectionChanged( wxDataViewEvent &event );
110
111 void OnStartEditing( wxDataViewEvent &event );
112 void OnEditingStarted( wxDataViewEvent &event );
113 void OnEditingDone( wxDataViewEvent &event );
114
115 void OnHeaderClick( wxDataViewEvent &event );
116 void OnAttrHeaderClick( wxDataViewEvent &event );
117 void OnHeaderRightClick( wxDataViewEvent &event );
118 void OnSorted( wxDataViewEvent &event );
119
120 void OnContextMenu( wxDataViewEvent &event );
121
122 void OnGoto( wxCommandEvent &event);
123 void OnAddMany( wxCommandEvent &event);
124 void OnHideAttributes( wxCommandEvent &event);
125 void OnShowAttributes( wxCommandEvent &event);
126
127 #if wxUSE_DRAG_AND_DROP
128 void OnBeginDrag( wxDataViewEvent &event );
129 void OnDropPossible( wxDataViewEvent &event );
130 void OnDrop( wxDataViewEvent &event );
131 #endif // wxUSE_DRAG_AND_DROP
132
133 void OnDataViewChar(wxKeyEvent& event);
134
135 // helper used by both OnDeleteSelected() and OnDataViewChar()
136 void DeleteSelectedItems();
137
138
139 wxNotebook* m_notebook;
140
141 // the controls stored in the various tabs of the main notebook:
142
143 wxDataViewCtrl* m_ctrl[4];
144
145 // the models associated with the first two DVC:
146
147 wxObjectDataPtr<MyMusicTreeModel> m_music_model;
148 wxObjectDataPtr<MyListModel> m_list_model;
149
150 // other data:
151
152 wxDataViewColumn* m_col;
153 wxDataViewColumn* m_attributes;
154
155 wxTextCtrl* m_log;
156 wxLog *m_logOld;
157
158 private:
159 DECLARE_EVENT_TABLE()
160 };
161
162
163 // ----------------------------------------------------------------------------
164 // MyCustomRenderer
165 // ----------------------------------------------------------------------------
166
167 class MyCustomRenderer: public wxDataViewCustomRenderer
168 {
169 public:
170 MyCustomRenderer()
171 : wxDataViewCustomRenderer("string",
172 wxDATAVIEW_CELL_ACTIVATABLE,
173 wxALIGN_CENTER)
174 { }
175
176 virtual bool Render( wxRect rect, wxDC *dc, int state )
177 {
178 dc->SetBrush( *wxLIGHT_GREY_BRUSH );
179 dc->SetPen( *wxTRANSPARENT_PEN );
180
181 rect.Deflate(2);
182 dc->DrawRoundedRectangle( rect, 5 );
183
184 RenderText(m_value,
185 0, // no offset
186 wxRect(dc->GetTextExtent(m_value)).CentreIn(rect),
187 dc,
188 state);
189 return true;
190 }
191
192 virtual bool Activate( wxRect WXUNUSED(cell),
193 wxDataViewModel *WXUNUSED(model),
194 const wxDataViewItem &WXUNUSED(item),
195 unsigned int WXUNUSED(col) )
196 {
197 wxLogMessage( "MyCustomRenderer Activate()" );
198 return false;
199 }
200
201 virtual bool LeftClick( wxPoint cursor, wxRect WXUNUSED(cell),
202 wxDataViewModel *WXUNUSED(model),
203 const wxDataViewItem &WXUNUSED(item),
204 unsigned int WXUNUSED(col) )
205 {
206 wxLogMessage( "MyCustomRenderer LeftClick( %d, %d )", cursor.x, cursor.y );
207 return false;
208 }
209
210 virtual wxSize GetSize() const
211 {
212 return wxSize(60,20);
213 }
214
215 virtual bool SetValue( const wxVariant &value )
216 {
217 m_value = value.GetString();
218 return true;
219 }
220
221 virtual bool GetValue( wxVariant &WXUNUSED(value) ) const { return true; }
222
223 private:
224 wxString m_value;
225 };
226
227
228 // ============================================================================
229 // implementation
230 // ============================================================================
231
232 // ----------------------------------------------------------------------------
233 // MyApp
234 // ----------------------------------------------------------------------------
235
236 IMPLEMENT_APP(MyApp)
237
238 bool MyApp::OnInit()
239 {
240 if ( !wxApp::OnInit() )
241 return false;
242
243 MyFrame *frame =
244 new MyFrame(NULL, "wxDataViewCtrl sample", 40, 40, 1000, 540);
245
246 frame->Show(true);
247 return true;
248 }
249
250
251 // ----------------------------------------------------------------------------
252 // MyFrame
253 // ----------------------------------------------------------------------------
254
255 enum
256 {
257 ID_CLEARLOG = wxID_HIGHEST+1,
258 ID_BACKGROUND_COLOUR,
259 ID_FOREGROUND_COLOUR,
260 ID_STYLE_MENU,
261
262 // file menu
263 //ID_SINGLE, wxDV_SINGLE==0 so it's always present
264 ID_MULTIPLE,
265 ID_ROW_LINES,
266 ID_HORIZ_RULES,
267 ID_VERT_RULES,
268
269 ID_EXIT = wxID_EXIT,
270
271 // about menu
272 ID_ABOUT = wxID_ABOUT,
273
274
275 // control IDs
276
277 ID_MUSIC_CTRL = 50,
278 ID_ATTR_CTRL = 51,
279
280 ID_ADD_MOZART = 100,
281 ID_DELETE_SEL = 101,
282 ID_DELETE_YEAR = 102,
283 ID_SELECT_NINTH = 103,
284 ID_COLLAPSE = 104,
285 ID_EXPAND = 105,
286 ID_SHOW_CURRENT,
287 ID_SET_NINTH_CURRENT,
288
289 ID_PREPEND_LIST = 200,
290 ID_DELETE_LIST = 201,
291 ID_GOTO = 202,
292 ID_ADD_MANY = 203,
293 ID_HIDE_ATTRIBUTES = 204,
294 ID_SHOW_ATTRIBUTES = 205,
295
296 // Fourth page.
297 ID_DELETE_TREE_ITEM = 400,
298 ID_DELETE_ALL_TREE_ITEMS = 401,
299 ID_ADD_TREE_ITEM = 402,
300 ID_ADD_TREE_CONTAINER_ITEM = 403
301 };
302
303 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
304 EVT_MENU_RANGE( ID_MULTIPLE, ID_VERT_RULES, MyFrame::OnStyleChange )
305 EVT_MENU( ID_EXIT, MyFrame::OnQuit )
306 EVT_MENU( ID_ABOUT, MyFrame::OnAbout )
307 EVT_MENU( ID_CLEARLOG, MyFrame::OnClearLog )
308
309 EVT_MENU( ID_FOREGROUND_COLOUR, MyFrame::OnSetForegroundColour )
310 EVT_MENU( ID_BACKGROUND_COLOUR, MyFrame::OnSetBackgroundColour )
311
312 EVT_NOTEBOOK_PAGE_CHANGED( wxID_ANY, MyFrame::OnPageChanged )
313
314 EVT_BUTTON( ID_ADD_MOZART, MyFrame::OnAddMozart )
315 EVT_BUTTON( ID_DELETE_SEL, MyFrame::OnDeleteSelected )
316 EVT_BUTTON( ID_DELETE_YEAR, MyFrame::OnDeleteYear )
317 EVT_BUTTON( ID_SELECT_NINTH, MyFrame::OnSelectNinth )
318 EVT_BUTTON( ID_COLLAPSE, MyFrame::OnCollapse )
319 EVT_BUTTON( ID_EXPAND, MyFrame::OnExpand )
320 EVT_BUTTON( ID_SHOW_CURRENT, MyFrame::OnShowCurrent )
321 EVT_BUTTON( ID_SET_NINTH_CURRENT, MyFrame::OnSetNinthCurrent )
322
323 EVT_BUTTON( ID_PREPEND_LIST, MyFrame::OnPrependList )
324 EVT_BUTTON( ID_DELETE_LIST, MyFrame::OnDeleteList )
325 EVT_BUTTON( ID_GOTO, MyFrame::OnGoto)
326 EVT_BUTTON( ID_ADD_MANY, MyFrame::OnAddMany)
327 EVT_BUTTON( ID_HIDE_ATTRIBUTES, MyFrame::OnHideAttributes)
328 EVT_BUTTON( ID_SHOW_ATTRIBUTES, MyFrame::OnShowAttributes)
329 // Fourth page.
330 EVT_BUTTON( ID_DELETE_TREE_ITEM, MyFrame::OnDeleteTreeItem )
331 EVT_BUTTON( ID_DELETE_ALL_TREE_ITEMS, MyFrame::OnDeleteAllTreeItems )
332 EVT_BUTTON( ID_ADD_TREE_ITEM, MyFrame::OnAddTreeItem )
333 EVT_BUTTON( ID_ADD_TREE_CONTAINER_ITEM, MyFrame::OnAddTreeContainerItem )
334
335 EVT_DATAVIEW_ITEM_VALUE_CHANGED( ID_MUSIC_CTRL, MyFrame::OnValueChanged )
336
337 EVT_DATAVIEW_ITEM_ACTIVATED(ID_MUSIC_CTRL, MyFrame::OnActivated )
338 EVT_DATAVIEW_ITEM_EXPANDING(ID_MUSIC_CTRL, MyFrame::OnExpanding)
339 EVT_DATAVIEW_ITEM_EXPANDED(ID_MUSIC_CTRL, MyFrame::OnExpanded)
340 EVT_DATAVIEW_ITEM_COLLAPSING(ID_MUSIC_CTRL, MyFrame::OnCollapsing)
341 EVT_DATAVIEW_ITEM_COLLAPSED(ID_MUSIC_CTRL, MyFrame::OnCollapsed)
342 EVT_DATAVIEW_SELECTION_CHANGED(ID_MUSIC_CTRL, MyFrame::OnSelectionChanged)
343
344 EVT_DATAVIEW_ITEM_START_EDITING(ID_MUSIC_CTRL, MyFrame::OnStartEditing)
345 EVT_DATAVIEW_ITEM_EDITING_STARTED(ID_MUSIC_CTRL, MyFrame::OnEditingStarted)
346 EVT_DATAVIEW_ITEM_EDITING_DONE(ID_MUSIC_CTRL, MyFrame::OnEditingDone)
347
348 EVT_DATAVIEW_COLUMN_HEADER_CLICK(ID_MUSIC_CTRL, MyFrame::OnHeaderClick)
349 EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(ID_MUSIC_CTRL, MyFrame::OnHeaderRightClick)
350 EVT_DATAVIEW_COLUMN_SORTED(ID_MUSIC_CTRL, MyFrame::OnSorted)
351
352 EVT_DATAVIEW_ITEM_CONTEXT_MENU(ID_MUSIC_CTRL, MyFrame::OnContextMenu)
353
354 #if wxUSE_DRAG_AND_DROP
355 EVT_DATAVIEW_ITEM_BEGIN_DRAG( ID_MUSIC_CTRL, MyFrame::OnBeginDrag )
356 EVT_DATAVIEW_ITEM_DROP_POSSIBLE( ID_MUSIC_CTRL, MyFrame::OnDropPossible )
357 EVT_DATAVIEW_ITEM_DROP( ID_MUSIC_CTRL, MyFrame::OnDrop )
358 #endif // wxUSE_DRAG_AND_DROP
359
360 EVT_DATAVIEW_COLUMN_HEADER_CLICK(ID_ATTR_CTRL, MyFrame::OnAttrHeaderClick)
361
362 END_EVENT_TABLE()
363
364 MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int h):
365 wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
366 {
367 m_log = NULL;
368 m_col = NULL;
369
370 m_ctrl[0] = NULL;
371 m_ctrl[1] = NULL;
372 m_ctrl[2] = NULL;
373 m_ctrl[3] = NULL;
374
375 SetIcon(wxICON(sample));
376
377
378 // build the menus
379 // ----------------
380
381 wxMenu *style_menu = new wxMenu;
382 //style_menu->AppendCheckItem(ID_SINGLE, "Single selection"));
383 style_menu->AppendCheckItem(ID_MULTIPLE, "Multiple selection");
384 style_menu->AppendCheckItem(ID_ROW_LINES, "Alternating colours");
385 style_menu->AppendCheckItem(ID_HORIZ_RULES, "Display horizontal rules");
386 style_menu->AppendCheckItem(ID_VERT_RULES, "Display vertical rules");
387
388 wxMenu *file_menu = new wxMenu;
389 file_menu->Append(ID_CLEARLOG, "&Clear log\tCtrl-L");
390 file_menu->Append(ID_FOREGROUND_COLOUR, "Set &foreground colour...\tCtrl-S");
391 file_menu->Append(ID_BACKGROUND_COLOUR, "Set &background colour...\tCtrl-B");
392 file_menu->Append(ID_STYLE_MENU, "&Style", style_menu);
393 file_menu->AppendSeparator();
394 file_menu->Append(ID_EXIT, "E&xit");
395
396 wxMenu *about_menu = new wxMenu;
397 about_menu->Append(ID_ABOUT, "&About");
398
399 wxMenuBar *menu_bar = new wxMenuBar;
400 menu_bar->Append(file_menu, "&File");
401 menu_bar->Append(about_menu, "&About");
402
403 SetMenuBar(menu_bar);
404 CreateStatusBar();
405
406
407 // redirect logs from our event handlers to text control
408 m_log = new wxTextCtrl( this, wxID_ANY, wxString(), wxDefaultPosition,
409 wxDefaultSize, wxTE_MULTILINE );
410 m_log->SetMinSize(wxSize(-1, 100));
411 m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_log));
412 wxLogMessage( "This is the log window" );
413
414
415 // first page of the notebook
416 // --------------------------
417
418 m_notebook = new wxNotebook( this, wxID_ANY );
419
420 wxPanel *firstPanel = new wxPanel( m_notebook, wxID_ANY );
421
422 BuildDataViewCtrl(firstPanel, 0); // sets m_ctrl[0]
423
424 const wxSizerFlags border = wxSizerFlags().DoubleBorder();
425
426 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
427 button_sizer->Add( new wxButton( firstPanel, ID_ADD_MOZART, "Add Mozart"), border );
428 button_sizer->Add( new wxButton( firstPanel, ID_DELETE_SEL, "Delete selected"), border );
429 button_sizer->Add( new wxButton( firstPanel, ID_DELETE_YEAR, "Delete \"Year\" column"), border );
430 button_sizer->Add( new wxButton( firstPanel, ID_SELECT_NINTH,"Select ninth symphony"), border );
431 button_sizer->Add( new wxButton( firstPanel, ID_COLLAPSE, "Collapse"), border );
432 button_sizer->Add( new wxButton( firstPanel, ID_EXPAND, "Expand"), border );
433
434 wxBoxSizer *sizerCurrent = new wxBoxSizer(wxHORIZONTAL);
435 sizerCurrent->Add(new wxButton(firstPanel, ID_SHOW_CURRENT,
436 "&Show current"), border);
437 sizerCurrent->Add(new wxButton(firstPanel, ID_SET_NINTH_CURRENT,
438 "Make &ninth symphony current"), border);
439
440 wxSizer *firstPanelSz = new wxBoxSizer( wxVERTICAL );
441 m_ctrl[0]->SetMinSize(wxSize(-1, 200));
442 firstPanelSz->Add(m_ctrl[0], 1, wxGROW|wxALL, 5);
443 firstPanelSz->Add(
444 new wxStaticText(firstPanel, wxID_ANY, "Most of the cells above are editable!"),
445 0, wxGROW|wxALL, 5);
446 firstPanelSz->Add(button_sizer);
447 firstPanelSz->Add(sizerCurrent);
448 firstPanel->SetSizerAndFit(firstPanelSz);
449
450
451 // second page of the notebook
452 // ---------------------------
453
454 wxPanel *secondPanel = new wxPanel( m_notebook, wxID_ANY );
455
456 BuildDataViewCtrl(secondPanel, 1); // sets m_ctrl[1]
457
458 wxBoxSizer *button_sizer2 = new wxBoxSizer( wxHORIZONTAL );
459 button_sizer2->Add( new wxButton( secondPanel, ID_PREPEND_LIST,"Prepend"), 0, wxALL, 10 );
460 button_sizer2->Add( new wxButton( secondPanel, ID_DELETE_LIST, "Delete selected"), 0, wxALL, 10 );
461 button_sizer2->Add( new wxButton( secondPanel, ID_GOTO, "Goto 50"), 0, wxALL, 10 );
462 button_sizer2->Add( new wxButton( secondPanel, ID_ADD_MANY, "Add 1000"), 0, wxALL, 10 );
463 button_sizer2->Add( new wxButton( secondPanel, ID_HIDE_ATTRIBUTES, "Hide attributes"), 0, wxALL, 10 );
464 button_sizer2->Add( new wxButton( secondPanel, ID_SHOW_ATTRIBUTES, "Show attributes"), 0, wxALL, 10 );
465
466 wxSizer *secondPanelSz = new wxBoxSizer( wxVERTICAL );
467 secondPanelSz->Add(m_ctrl[1], 1, wxGROW|wxALL, 5);
468 secondPanelSz->Add(button_sizer2);
469 secondPanel->SetSizerAndFit(secondPanelSz);
470
471
472 // third page of the notebook
473 // ---------------------------
474
475 wxPanel *thirdPanel = new wxPanel( m_notebook, wxID_ANY );
476
477 BuildDataViewCtrl(thirdPanel, 2); // sets m_ctrl[2]
478
479 wxSizer *thirdPanelSz = new wxBoxSizer( wxVERTICAL );
480 thirdPanelSz->Add(m_ctrl[2], 1, wxGROW|wxALL, 5);
481 thirdPanel->SetSizerAndFit(thirdPanelSz);
482
483
484 // fourth page of the notebook
485 // ---------------------------
486
487 wxPanel *fourthPanel = new wxPanel( m_notebook, wxID_ANY );
488
489 BuildDataViewCtrl(fourthPanel, 3); // sets m_ctrl[3]
490 // Buttons
491 wxBoxSizer *button_sizer4 = new wxBoxSizer( wxHORIZONTAL );
492 button_sizer4->Add( new wxButton( fourthPanel, ID_DELETE_TREE_ITEM, "Delete Selected"), 0, wxALL, 10 );
493 button_sizer4->Add( new wxButton( fourthPanel, ID_DELETE_ALL_TREE_ITEMS, "Delete All"), 0, wxALL, 10 );
494 button_sizer4->Add( new wxButton( fourthPanel, ID_ADD_TREE_ITEM, "Add Item"), 0, wxALL, 10 );
495 button_sizer4->Add( new wxButton( fourthPanel, ID_ADD_TREE_CONTAINER_ITEM, "Add Container"), 0, wxALL, 10 );
496
497 wxSizer *fourthPanelSz = new wxBoxSizer( wxVERTICAL );
498 fourthPanelSz->Add(m_ctrl[3], 1, wxGROW|wxALL, 5);
499 fourthPanelSz->Add(button_sizer4);
500 fourthPanel->SetSizerAndFit(fourthPanelSz);
501
502
503
504 // complete GUI
505 // ------------
506
507 m_notebook->AddPage(firstPanel, "MyMusicTreeModel");
508 m_notebook->AddPage(secondPanel, "MyListModel");
509 m_notebook->AddPage(thirdPanel, "wxDataViewListCtrl");
510 m_notebook->AddPage(fourthPanel, "wxDataViewTreeCtrl");
511
512 wxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
513
514 mainSizer->Add( m_notebook, 1, wxGROW );
515 mainSizer->Add( m_log, 0, wxGROW );
516
517 SetSizerAndFit(mainSizer);
518 }
519
520 MyFrame::~MyFrame()
521 {
522 delete wxLog::SetActiveTarget(m_logOld);
523 }
524
525 void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned long style)
526 {
527 switch (nPanel)
528 {
529 case 0:
530 {
531 wxASSERT(!m_ctrl[0] && !m_music_model);
532 m_ctrl[0] =
533 new wxDataViewCtrl( parent, ID_MUSIC_CTRL, wxDefaultPosition,
534 wxDefaultSize, style );
535 m_ctrl[0]->Connect(wxEVT_CHAR,
536 wxKeyEventHandler(MyFrame::OnDataViewChar),
537 NULL, this);
538
539 m_music_model = new MyMusicTreeModel;
540 m_ctrl[0]->AssociateModel( m_music_model.get() );
541
542 #if wxUSE_DRAG_AND_DROP
543 m_ctrl[0]->EnableDragSource( wxDF_UNICODETEXT );
544 m_ctrl[0]->EnableDropTarget( wxDF_UNICODETEXT );
545 #endif // wxUSE_DRAG_AND_DROP
546
547 // column 0 of the view control:
548
549 wxDataViewTextRenderer *tr =
550 new wxDataViewTextRenderer( "string", wxDATAVIEW_CELL_INERT );
551 wxDataViewColumn *column0 =
552 new wxDataViewColumn( "title", tr, 0, 200, wxALIGN_LEFT,
553 wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_RESIZABLE );
554 m_ctrl[0]->AppendColumn( column0 );
555 #if 0
556 // Call this and sorting is enabled
557 // immediatly upon start up.
558 column0->SetAsSortKey();
559 #endif
560
561 // column 1 of the view control:
562
563 tr = new wxDataViewTextRenderer( "string", wxDATAVIEW_CELL_EDITABLE );
564 wxDataViewColumn *column1 =
565 new wxDataViewColumn( "artist", tr, 1, 150, wxALIGN_LEFT,
566 wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE |
567 wxDATAVIEW_COL_RESIZABLE );
568 column1->SetMinWidth(150); // this column can't be resized to be smaller
569 m_ctrl[0]->AppendColumn( column1 );
570
571 // column 2 of the view control:
572
573 wxDataViewSpinRenderer *sr =
574 new wxDataViewSpinRenderer( 0, 2010, wxDATAVIEW_CELL_EDITABLE, wxALIGN_RIGHT );
575 wxDataViewColumn *column2 =
576 new wxDataViewColumn( "year", sr, 2, 60, wxALIGN_LEFT,
577 wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE );
578 m_ctrl[0]->AppendColumn( column2 );
579
580 // column 3 of the view control:
581
582 wxArrayString choices;
583 choices.Add( "good" );
584 choices.Add( "bad" );
585 choices.Add( "lousy" );
586 wxDataViewChoiceRenderer *c =
587 new wxDataViewChoiceRenderer( choices, wxDATAVIEW_CELL_EDITABLE, wxALIGN_RIGHT );
588 wxDataViewColumn *column3 =
589 new wxDataViewColumn( "rating", c, 3, 100, wxALIGN_LEFT,
590 wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
591 m_ctrl[0]->AppendColumn( column3 );
592
593 // column 4 of the view control:
594
595 m_ctrl[0]->AppendProgressColumn( "popularity", 4, wxDATAVIEW_CELL_INERT, 80 );
596
597 // column 5 of the view control:
598
599 MyCustomRenderer *cr = new MyCustomRenderer;
600 wxDataViewColumn *column5 =
601 new wxDataViewColumn( "custom", cr, 5, -1, wxALIGN_LEFT,
602 wxDATAVIEW_COL_RESIZABLE );
603 m_ctrl[0]->AppendColumn( column5 );
604
605
606 // select initially the ninth symphony:
607 m_ctrl[0]->Select(m_music_model->GetNinthItem());
608 }
609 break;
610
611 case 1:
612 {
613 wxASSERT(!m_ctrl[1] && !m_list_model);
614 m_ctrl[1] = new wxDataViewCtrl( parent, ID_ATTR_CTRL, wxDefaultPosition,
615 wxDefaultSize, style );
616
617 m_list_model = new MyListModel;
618 m_ctrl[1]->AssociateModel( m_list_model.get() );
619
620 // the various columns
621 m_ctrl[1]->AppendTextColumn("editable string",
622 MyListModel::Col_EditableText,
623 wxDATAVIEW_CELL_EDITABLE,
624 wxCOL_WIDTH_AUTOSIZE);
625 m_ctrl[1]->AppendIconTextColumn("icon",
626 MyListModel::Col_IconText,
627 wxDATAVIEW_CELL_EDITABLE,
628 wxCOL_WIDTH_AUTOSIZE);
629
630 m_attributes =
631 new wxDataViewColumn("attributes",
632 new wxDataViewTextRenderer,
633 MyListModel::Col_TextWithAttr,
634 wxCOL_WIDTH_AUTOSIZE,
635 wxALIGN_RIGHT,
636 wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
637 m_ctrl[1]->AppendColumn( m_attributes );
638
639 m_ctrl[1]->AppendColumn(
640 new wxDataViewColumn("custom renderer",
641 new MyCustomRenderer,
642 MyListModel::Col_Custom)
643 );
644 }
645 break;
646
647 case 2:
648 {
649 wxASSERT(!m_ctrl[2]);
650 wxDataViewListCtrl* lc =
651 new wxDataViewListCtrl( parent, wxID_ANY, wxDefaultPosition,
652 wxDefaultSize, style );
653 m_ctrl[2] = lc;
654
655 MyListStoreDerivedModel* page2_model = new MyListStoreDerivedModel();
656 lc->AssociateModel(page2_model);
657 page2_model->DecRef();
658
659 lc->AppendToggleColumn( "Toggle" );
660 lc->AppendTextColumn( "Text" );
661 lc->AppendProgressColumn( "Progress" );
662
663 wxVector<wxVariant> data;
664 for (unsigned int i=0; i<10; i++)
665 {
666 data.clear();
667 data.push_back( (i%3) == 0 );
668 data.push_back( wxString::Format("row %d", i) );
669 data.push_back( long(5*i) );
670
671 lc->AppendItem( data );
672 }
673 }
674 break;
675
676 case 3:
677 {
678 wxASSERT(!m_ctrl[3]);
679 wxDataViewTreeCtrl* tc =
680 new wxDataViewTreeCtrl( parent, wxID_ANY, wxDefaultPosition,
681 wxDefaultSize, style | wxDV_NO_HEADER );
682 m_ctrl[3] = tc;
683
684 wxImageList *ilist = new wxImageList( 16, 16 );
685 ilist->Add( wxIcon(wx_small_xpm) );
686 tc->SetImageList( ilist );
687
688 wxDataViewItem parent =
689 tc->AppendContainer( wxDataViewItem(0), "The Root", 0 );
690 tc->AppendItem( parent, "Child 1", 0 );
691 tc->AppendItem( parent, "Child 2", 0 );
692 tc->AppendItem( parent, "Child 3, very long, long, long, long", 0 );
693
694 wxDataViewItem cont =
695 tc->AppendContainer( parent, "Container child", 0 );
696 tc->AppendItem( cont, "Child 4", 0 );
697 tc->AppendItem( cont, "Child 5", 0 );
698
699 tc->Expand(cont);
700 }
701 break;
702 }
703 }
704
705
706 // ----------------------------------------------------------------------------
707 // MyFrame - generic event handlers
708 // ----------------------------------------------------------------------------
709
710 void MyFrame::OnClearLog( wxCommandEvent& WXUNUSED(event) )
711 {
712 m_log->Clear();
713 }
714
715 void MyFrame::OnSetForegroundColour(wxCommandEvent& WXUNUSED(event))
716 {
717 wxDataViewCtrl * const dvc = m_ctrl[m_notebook->GetSelection()];
718 wxColour col = wxGetColourFromUser(this, dvc->GetForegroundColour());
719 if ( col.IsOk() )
720 {
721 dvc->SetForegroundColour(col);
722 Refresh();
723 }
724 }
725
726 void MyFrame::OnSetBackgroundColour(wxCommandEvent& WXUNUSED(event))
727 {
728 wxDataViewCtrl * const dvc = m_ctrl[m_notebook->GetSelection()];
729 wxColour col = wxGetColourFromUser(this, dvc->GetBackgroundColour());
730 if ( col.IsOk() )
731 {
732 dvc->SetBackgroundColour(col);
733 Refresh();
734 }
735 }
736
737 void MyFrame::OnPageChanged( wxBookCtrlEvent& WXUNUSED(event) )
738 {
739 unsigned int nPanel = m_notebook->GetSelection();
740
741 GetMenuBar()->FindItem(ID_STYLE_MENU)->SetItemLabel(
742 wxString::Format("Style of panel #%d", nPanel+1));
743
744 for (unsigned int id = ID_MULTIPLE; id <= ID_VERT_RULES; id++)
745 {
746 unsigned long style = 0;
747 switch (id)
748 {
749 /*case ID_SINGLE:
750 style = wxDV_SINGLE;
751 break;*/
752 case ID_MULTIPLE:
753 style = wxDV_MULTIPLE;
754 break;
755 case ID_ROW_LINES:
756 style = wxDV_ROW_LINES;
757 break;
758 case ID_HORIZ_RULES:
759 style = wxDV_HORIZ_RULES;
760 break;
761 case ID_VERT_RULES:
762 style = wxDV_VERT_RULES;
763 break;
764 default:
765 wxFAIL;
766 }
767
768 GetMenuBar()->FindItem(id)->Check( m_ctrl[nPanel]->HasFlag(style) );
769 }
770 }
771
772 void MyFrame::OnStyleChange( wxCommandEvent& WXUNUSED(event) )
773 {
774 unsigned int nPanel = m_notebook->GetSelection();
775
776 // build the style
777 unsigned long style = 0;
778 /*if (GetMenuBar()->FindItem(ID_SINGLE)->IsChecked())
779 style |= wxDV_SINGLE;*/
780 if (GetMenuBar()->FindItem(ID_MULTIPLE)->IsChecked())
781 style |= wxDV_MULTIPLE;
782 if (GetMenuBar()->FindItem(ID_ROW_LINES)->IsChecked())
783 style |= wxDV_ROW_LINES;
784 if (GetMenuBar()->FindItem(ID_HORIZ_RULES)->IsChecked())
785 style |= wxDV_HORIZ_RULES;
786 if (GetMenuBar()->FindItem(ID_VERT_RULES)->IsChecked())
787 style |= wxDV_VERT_RULES;
788
789 wxSizer* sz = m_ctrl[nPanel]->GetContainingSizer();
790 wxASSERT(sz);
791
792 sz->Detach(m_ctrl[nPanel]);
793 wxDELETE(m_ctrl[nPanel]);
794 m_ctrl[nPanel] = NULL;
795
796 if (nPanel == 0)
797 m_music_model.reset(NULL);
798 else if (nPanel == 1)
799 m_list_model.reset(NULL);
800
801 // rebuild the DVC for the selected panel:
802 BuildDataViewCtrl((wxPanel*)m_notebook->GetPage(nPanel), nPanel, style);
803
804 sz->Prepend(m_ctrl[nPanel], 1, wxGROW|wxALL, 5);
805 sz->Layout();
806 }
807
808 void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )
809 {
810 Close(true);
811 }
812
813 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
814 {
815 wxAboutDialogInfo info;
816 info.SetName(_("DataView sample"));
817 info.SetDescription(_("This sample demonstrates wxDataViewCtrl"));
818 info.SetCopyright(wxT("(C) 2007-2009 Robert Roebling"));
819 info.AddDeveloper("Robert Roebling");
820 info.AddDeveloper("Francesco Montorsi");
821
822 wxAboutBox(info);
823 }
824
825
826 // ----------------------------------------------------------------------------
827 // MyFrame - event handlers for the first page
828 // ----------------------------------------------------------------------------
829
830 #if wxUSE_DRAG_AND_DROP
831
832 void MyFrame::OnBeginDrag( wxDataViewEvent &event )
833 {
834 wxDataViewItem item( event.GetItem() );
835
836 // only allow drags for item, not containers
837 if (m_music_model->IsContainer( item ) )
838 {
839 event.Veto();
840 return;
841 }
842
843 MyMusicTreeModelNode *node = (MyMusicTreeModelNode*) item.GetID();
844 wxTextDataObject *obj = new wxTextDataObject;
845 obj->SetText( node->m_title );
846 event.SetDataObject( obj );
847 }
848
849 void MyFrame::OnDropPossible( wxDataViewEvent &event )
850 {
851 wxDataViewItem item( event.GetItem() );
852
853 // only allow drags for item, not containers
854 if (m_music_model->IsContainer( item ) )
855 event.Veto();
856
857 if (event.GetDataFormat() != wxDF_UNICODETEXT)
858 event.Veto();
859 }
860
861 void MyFrame::OnDrop( wxDataViewEvent &event )
862 {
863 wxDataViewItem item( event.GetItem() );
864
865 // only allow drops for item, not containers
866 if (m_music_model->IsContainer( item ) )
867 {
868 event.Veto();
869 return;
870 }
871
872 if (event.GetDataFormat() != wxDF_UNICODETEXT)
873 {
874 event.Veto();
875 return;
876 }
877
878 wxTextDataObject obj;
879 obj.SetData( wxDF_UNICODETEXT, event.GetDataSize(), event.GetDataBuffer() );
880
881 wxLogMessage( "Text dropped: %s", obj.GetText() );
882 }
883
884 #endif // wxUSE_DRAG_AND_DROP
885
886 void MyFrame::OnAddMozart( wxCommandEvent& WXUNUSED(event) )
887 {
888 m_music_model->AddToClassical( "Eine kleine Nachtmusik", "Wolfgang Mozart", 1787 );
889 }
890
891 void MyFrame::DeleteSelectedItems()
892 {
893 wxDataViewItemArray items;
894 int len = m_ctrl[0]->GetSelections( items );
895 for( int i = 0; i < len; i ++ )
896 if (items[i].IsOk())
897 m_music_model->Delete( items[i] );
898 }
899
900 void MyFrame::OnDeleteSelected( wxCommandEvent& WXUNUSED(event) )
901 {
902 DeleteSelectedItems();
903 }
904
905 void MyFrame::OnDeleteYear( wxCommandEvent& WXUNUSED(event) )
906 {
907 m_ctrl[0]->DeleteColumn( m_ctrl[0]->GetColumn( 2 ) );
908 FindWindow( ID_DELETE_YEAR )->Disable();
909 }
910
911 void MyFrame::OnSelectNinth( wxCommandEvent& WXUNUSED(event) )
912 {
913 if (!m_music_model->GetNinthItem().IsOk())
914 {
915 wxLogError( "Cannot select the ninth symphony: it was removed!" );
916 return;
917 }
918
919 m_ctrl[0]->Select( m_music_model->GetNinthItem() );
920 }
921
922 void MyFrame::OnCollapse( wxCommandEvent& WXUNUSED(event) )
923 {
924 wxDataViewItem item = m_ctrl[0]->GetSelection();
925 if (item.IsOk())
926 m_ctrl[0]->Collapse( item );
927 }
928
929 void MyFrame::OnExpand( wxCommandEvent& WXUNUSED(event) )
930 {
931 wxDataViewItem item = m_ctrl[0]->GetSelection();
932 if (item.IsOk())
933 m_ctrl[0]->Expand( item );
934 }
935
936 void MyFrame::OnShowCurrent(wxCommandEvent& WXUNUSED(event))
937 {
938 wxDataViewItem item = m_ctrl[0]->GetCurrentItem();
939 if ( item.IsOk() )
940 {
941 wxLogMessage("Current item: \"%s\" by %s",
942 m_music_model->GetTitle(item),
943 m_music_model->GetArtist(item));
944 }
945 else
946 {
947 wxLogMessage("There is no current item.");
948 }
949 }
950
951 void MyFrame::OnSetNinthCurrent(wxCommandEvent& WXUNUSED(event))
952 {
953 wxDataViewItem item(m_music_model->GetNinthItem());
954 if ( !item.IsOk() )
955 {
956 wxLogError( "Cannot make the ninth symphony current: it was removed!" );
957 return;
958 }
959
960 m_ctrl[0]->SetCurrentItem(item);
961 }
962
963 void MyFrame::OnValueChanged( wxDataViewEvent &event )
964 {
965 wxString title = m_music_model->GetTitle( event.GetItem() );
966 wxLogMessage( "wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, Item Id: %s; Column: %d",
967 title, event.GetColumn() );
968 }
969
970 void MyFrame::OnActivated( wxDataViewEvent &event )
971 {
972 wxString title = m_music_model->GetTitle( event.GetItem() );
973 wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item: %s", title );
974
975 if (m_ctrl[0]->IsExpanded( event.GetItem() ))
976 {
977 wxLogMessage( "Item: %s is expanded", title );
978 }
979 }
980
981 void MyFrame::OnSelectionChanged( wxDataViewEvent &event )
982 {
983 wxString title = m_music_model->GetTitle( event.GetItem() );
984 if (title.empty())
985 title = "None";
986
987 wxLogMessage( "wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, First selected Item: %s", title );
988 }
989
990 void MyFrame::OnExpanding( wxDataViewEvent &event )
991 {
992 wxString title = m_music_model->GetTitle( event.GetItem() );
993 wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, Item: %s", title );
994 }
995
996
997 void MyFrame::OnStartEditing( wxDataViewEvent &event )
998 {
999 wxString artist = m_music_model->GetArtist( event.GetItem() );
1000 if (artist == "Ludwig van Beethoven")
1001 {
1002 event.Veto();
1003
1004 wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING vetoed. Artist: %s", artist );
1005 }
1006 else
1007 wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING not vetoed. Artist: %s", artist );
1008
1009 }
1010
1011 void MyFrame::OnEditingStarted( wxDataViewEvent &event )
1012 {
1013 wxString title = m_music_model->GetTitle( event.GetItem() );
1014 wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, Item: %s", title );
1015 }
1016
1017 void MyFrame::OnEditingDone( wxDataViewEvent &event )
1018 {
1019 wxString title = m_music_model->GetTitle( event.GetItem() );
1020 wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, Item: %s", title );
1021 }
1022
1023 void MyFrame::OnExpanded( wxDataViewEvent &event )
1024 {
1025 wxString title = m_music_model->GetTitle( event.GetItem() );
1026 wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, Item: %s", title );
1027 }
1028
1029 void MyFrame::OnCollapsing( wxDataViewEvent &event )
1030 {
1031 wxString title = m_music_model->GetTitle( event.GetItem() );
1032 wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, Item: %s", title );
1033 }
1034
1035 void MyFrame::OnCollapsed( wxDataViewEvent &event )
1036 {
1037 wxString title = m_music_model->GetTitle( event.GetItem() );
1038 wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, Item: %s", title );
1039 }
1040
1041 void MyFrame::OnContextMenu( wxDataViewEvent &event )
1042 {
1043 wxString title = m_music_model->GetTitle( event.GetItem() );
1044 wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s", title );
1045
1046 wxMenu menu;
1047 menu.Append( 1, "menuitem 1" );
1048 menu.Append( 2, "menuitem 2" );
1049 menu.Append( 3, "menuitem 3" );
1050
1051 m_ctrl[0]->PopupMenu(&menu);
1052 }
1053
1054 void MyFrame::OnAttrHeaderClick( wxDataViewEvent &event )
1055 {
1056 // we need to skip the event to let the default behaviour of sorting by
1057 // this column when it is clicked to take place
1058 event.Skip();
1059
1060 int pos = m_ctrl[1]->GetColumnPosition( event.GetDataViewColumn() );
1061
1062 wxLogMessage( "wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, Column position: %d", pos );
1063 wxLogMessage( "Column title: %s Column width: %d", event.GetDataViewColumn()->GetTitle(), event.GetDataViewColumn()->GetWidth() );
1064 }
1065
1066 void MyFrame::OnHeaderClick( wxDataViewEvent &event )
1067 {
1068 // we need to skip the event to let the default behaviour of sorting by
1069 // this column when it is clicked to take place
1070 event.Skip();
1071
1072 int pos = m_ctrl[0]->GetColumnPosition( event.GetDataViewColumn() );
1073
1074 wxLogMessage( "wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, Column position: %d", pos );
1075 wxLogMessage( "Column width: %d", event.GetDataViewColumn()->GetWidth() );
1076 }
1077
1078 void MyFrame::OnHeaderRightClick( wxDataViewEvent &event )
1079 {
1080 int pos = m_ctrl[0]->GetColumnPosition( event.GetDataViewColumn() );
1081
1082 wxLogMessage( "wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, Column position: %d", pos );
1083 }
1084
1085 void MyFrame::OnSorted( wxDataViewEvent &event )
1086 {
1087 int pos = m_ctrl[0]->GetColumnPosition( event.GetDataViewColumn() );
1088
1089 wxLogMessage( "wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, Column position: %d", pos );
1090 }
1091
1092 void MyFrame::OnDataViewChar(wxKeyEvent& event)
1093 {
1094 if ( event.GetKeyCode() == WXK_DELETE )
1095 DeleteSelectedItems();
1096 else
1097 event.Skip();
1098 }
1099
1100 // ----------------------------------------------------------------------------
1101 // MyFrame - event handlers for the second page
1102 // ----------------------------------------------------------------------------
1103
1104 void MyFrame::OnPrependList( wxCommandEvent& WXUNUSED(event) )
1105 {
1106 m_list_model->Prepend("Test");
1107 }
1108
1109 void MyFrame::OnDeleteList( wxCommandEvent& WXUNUSED(event) )
1110 {
1111 wxDataViewItemArray items;
1112 int len = m_ctrl[1]->GetSelections( items );
1113 if (len > 0)
1114 m_list_model->DeleteItems( items );
1115 }
1116
1117 void MyFrame::OnGoto(wxCommandEvent& WXUNUSED(event))
1118 {
1119 wxDataViewItem item = m_list_model->GetItem( 50 );
1120 m_ctrl[1]->EnsureVisible(item,m_col);
1121 }
1122
1123 void MyFrame::OnAddMany(wxCommandEvent& WXUNUSED(event))
1124 {
1125 m_list_model->AddMany();
1126 }
1127
1128 void MyFrame::OnHideAttributes(wxCommandEvent& WXUNUSED(event))
1129 {
1130 m_attributes->SetHidden(true);
1131 }
1132
1133 void MyFrame::OnShowAttributes(wxCommandEvent& WXUNUSED(event))
1134 {
1135 m_attributes->SetHidden(false);
1136 }
1137
1138 // ----------------------------------------------------------------------------
1139 // MyFrame - event handlers for the fourth page
1140 // ----------------------------------------------------------------------------
1141
1142 void MyFrame::OnDeleteTreeItem(wxCommandEvent& WXUNUSED(event))
1143 {
1144 wxDataViewTreeCtrl* ctrl = (wxDataViewTreeCtrl*) m_ctrl[3];
1145 wxDataViewItem selected = ctrl->GetSelection();
1146 if (!selected.IsOk())
1147 return;
1148
1149 ctrl->DeleteItem(selected);
1150 }
1151
1152 void MyFrame::OnDeleteAllTreeItems(wxCommandEvent& WXUNUSED(event))
1153 {
1154 wxDataViewTreeCtrl* ctrl = (wxDataViewTreeCtrl*) m_ctrl[3];
1155 ctrl->DeleteAllItems();
1156 }
1157
1158 void MyFrame::OnAddTreeItem(wxCommandEvent& WXUNUSED(event))
1159 {
1160 wxDataViewTreeCtrl* ctrl = (wxDataViewTreeCtrl*) m_ctrl[3];
1161 wxDataViewItem selected = ctrl->GetSelection();
1162 if (ctrl->IsContainer(selected))
1163 ctrl->AppendItem( selected, "Item", 0 );
1164 }
1165
1166 void MyFrame::OnAddTreeContainerItem(wxCommandEvent& WXUNUSED(event))
1167 {
1168 wxDataViewTreeCtrl* ctrl = (wxDataViewTreeCtrl*) m_ctrl[3];
1169 wxDataViewItem selected = ctrl->GetSelection();
1170 if (ctrl->IsContainer(selected))
1171 ctrl->AppendContainer(selected, "Container", 0 );
1172 }
1173