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