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