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