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