]>
Commit | Line | Data |
---|---|---|
bd6169a6 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dataview.cpp | |
9861f022 | 3 | // Purpose: wxDataViewCtrl wxWidgets sample |
bd6169a6 | 4 | // Author: Robert Roebling |
b7e9f8b1 | 5 | // Modified by: Francesco Montorsi, Bo Yang |
bd6169a6 RR |
6 | // Created: 06/01/06 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Robert Roebling | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
bf19b714 FM |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
bd6169a6 RR |
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 | |
0bcd4039 | 24 | #include "wx/wx.h" |
bd6169a6 RR |
25 | #endif |
26 | ||
8c2654ce | 27 | #include "wx/dataview.h" |
b910a8ad | 28 | #include "wx/datetime.h" |
87f0efe2 RR |
29 | #include "wx/splitter.h" |
30 | #include "wx/aboutdlg.h" | |
bb58fa37 | 31 | #include "wx/colordlg.h" |
9861f022 RR |
32 | #include "wx/choicdlg.h" |
33 | #include "wx/numdlg.h" | |
1e510b1e | 34 | #include "wx/spinctrl.h" |
8c2654ce | 35 | #include "wx/imaglist.h" |
bf19b714 FM |
36 | #include "wx/notebook.h" |
37 | ||
38 | #include "mymodels.h" | |
39 | ||
40 | // ---------------------------------------------------------------------------- | |
41 | // resources | |
42 | // ---------------------------------------------------------------------------- | |
ad386793 | 43 | |
bd6169a6 | 44 | #ifndef __WXMSW__ |
0bcd4039 | 45 | #include "../sample.xpm" |
bd6169a6 RR |
46 | #endif |
47 | ||
bf19b714 | 48 | #include "wx_small.xpm" |
1e08ad10 | 49 | |
bf19b714 FM |
50 | // ---------------------------------------------------------------------------- |
51 | // MyApp | |
52 | // ---------------------------------------------------------------------------- | |
1e08ad10 | 53 | |
bf19b714 | 54 | class MyApp: public wxApp |
1e08ad10 RR |
55 | { |
56 | public: | |
bf19b714 | 57 | virtual bool OnInit(); |
1e08ad10 RR |
58 | }; |
59 | ||
bf19b714 FM |
60 | // ---------------------------------------------------------------------------- |
61 | // MyFrame | |
62 | // ---------------------------------------------------------------------------- | |
1c3e52af | 63 | |
bf19b714 | 64 | class MyFrame : public wxFrame |
bd6169a6 RR |
65 | { |
66 | public: | |
bf19b714 FM |
67 | MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int h); |
68 | ~MyFrame(); | |
e63807a8 | 69 | |
ecad59d8 FM |
70 | void BuildDataViewCtrl(wxPanel* parent, |
71 | unsigned int nPanel, | |
81c3f0fc FM |
72 | unsigned long style = 0); |
73 | ||
74 | public: // event handlers | |
75 | ||
76 | void OnStyleChange(wxCommandEvent& event); | |
bb58fa37 VZ |
77 | void OnSetBackgroundColour(wxCommandEvent& event); |
78 | void OnSetForegroundColour(wxCommandEvent& event); | |
bf19b714 FM |
79 | void OnQuit(wxCommandEvent& event); |
80 | void OnAbout(wxCommandEvent& event); | |
1c3e52af | 81 | |
ecad59d8 | 82 | void OnClearLog(wxCommandEvent& event); |
81c3f0fc FM |
83 | void OnPageChanged(wxBookCtrlEvent& event); |
84 | ||
bf19b714 FM |
85 | void OnAddMozart(wxCommandEvent& event); |
86 | void OnDeleteMusic(wxCommandEvent& event); | |
87 | void OnDeleteYear(wxCommandEvent& event); | |
88 | void OnSelectNinth(wxCommandEvent& event); | |
d2ee27fe RR |
89 | void OnCollapse(wxCommandEvent& event); |
90 | void OnExpand(wxCommandEvent& event); | |
cf283a47 | 91 | |
bf19b714 FM |
92 | void OnPrependList(wxCommandEvent& event); |
93 | void OnDeleteList(wxCommandEvent& event); | |
a46a47a3 RR |
94 | // Fourth page. |
95 | void OnDeleteTreeItem(wxCommandEvent& event); | |
96 | void OnDeleteAllTreeItems(wxCommandEvent& event); | |
97 | void OnAddTreeItem(wxCommandEvent& event); | |
98 | void OnAddTreeContainerItem(wxCommandEvent& event); | |
1c3e52af | 99 | |
bf19b714 | 100 | void OnValueChanged( wxDataViewEvent &event ); |
cf283a47 | 101 | |
bf19b714 FM |
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 ); | |
1c3e52af | 108 | |
ecc32226 | 109 | void OnStartEditing( wxDataViewEvent &event ); |
bf19b714 FM |
110 | void OnEditingStarted( wxDataViewEvent &event ); |
111 | void OnEditingDone( wxDataViewEvent &event ); | |
b910a8ad | 112 | |
bf19b714 | 113 | void OnHeaderClick( wxDataViewEvent &event ); |
5d9e1605 | 114 | void OnAttrHeaderClick( wxDataViewEvent &event ); |
bf19b714 FM |
115 | void OnHeaderRightClick( wxDataViewEvent &event ); |
116 | void OnSorted( wxDataViewEvent &event ); | |
1c3e52af | 117 | |
bf19b714 | 118 | void OnContextMenu( wxDataViewEvent &event ); |
b910a8ad | 119 | |
bf19b714 FM |
120 | void OnRightClick( wxMouseEvent &event ); |
121 | void OnGoto( wxCommandEvent &event); | |
122 | void OnAddMany( wxCommandEvent &event); | |
5d9e1605 RR |
123 | void OnHideAttributes( wxCommandEvent &event); |
124 | void OnShowAttributes( wxCommandEvent &event); | |
9861f022 | 125 | |
bf19b714 FM |
126 | void OnBeginDrag( wxDataViewEvent &event ); |
127 | void OnDropPossible( wxDataViewEvent &event ); | |
128 | void OnDrop( wxDataViewEvent &event ); | |
9861f022 | 129 | |
bf19b714 FM |
130 | private: |
131 | wxNotebook* m_notebook; | |
1c3e52af | 132 | |
bf19b714 | 133 | // the controls stored in the various tabs of the main notebook: |
1c3e52af | 134 | |
81c3f0fc | 135 | wxDataViewCtrl* m_ctrl[4]; |
1c3e52af | 136 | |
81c3f0fc | 137 | // the models associated with the first two DVC: |
ed903e42 | 138 | |
81c3f0fc FM |
139 | wxObjectDataPtr<MyMusicTreeModel> m_music_model; |
140 | wxObjectDataPtr<MyListModel> m_list_model; | |
1c3e52af | 141 | |
bf19b714 | 142 | // other data: |
1c3e52af | 143 | |
bf19b714 | 144 | wxDataViewColumn* m_col; |
5d9e1605 | 145 | wxDataViewColumn* m_attributes; |
1c3e52af | 146 | |
bf19b714 FM |
147 | wxTextCtrl* m_log; |
148 | wxLog *m_logOld; | |
1c3e52af | 149 | |
1e08ad10 | 150 | private: |
bf19b714 | 151 | DECLARE_EVENT_TABLE() |
241cb04b RR |
152 | }; |
153 | ||
8b6cf9bf | 154 | |
bf19b714 | 155 | // ---------------------------------------------------------------------------- |
0bdfa388 | 156 | // MyCustomRenderer |
bf19b714 | 157 | // ---------------------------------------------------------------------------- |
0bdfa388 RR |
158 | |
159 | class MyCustomRenderer: public wxDataViewCustomRenderer | |
160 | { | |
161 | public: | |
ef6833f9 VZ |
162 | MyCustomRenderer() |
163 | : wxDataViewCustomRenderer("string", | |
164 | wxDATAVIEW_CELL_ACTIVATABLE, | |
165 | wxALIGN_CENTER) | |
166 | { } | |
1c3e52af | 167 | |
ef6833f9 | 168 | virtual bool Render( wxRect rect, wxDC *dc, int state ) |
0bdfa388 | 169 | { |
ef6833f9 | 170 | dc->SetBrush( *wxLIGHT_GREY_BRUSH ); |
0bdfa388 | 171 | dc->SetPen( *wxTRANSPARENT_PEN ); |
ef6833f9 VZ |
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); | |
0bdfa388 RR |
181 | return true; |
182 | } | |
183 | ||
0bdfa388 | 184 | virtual bool Activate( wxRect WXUNUSED(cell), |
ecad59d8 FM |
185 | wxDataViewModel *WXUNUSED(model), |
186 | const wxDataViewItem &WXUNUSED(item), | |
bf19b714 | 187 | unsigned int WXUNUSED(col) ) |
1c3e52af | 188 | { |
81c3f0fc | 189 | wxLogMessage( "MyCustomRenderer Activate()" ); |
0bdfa388 RR |
190 | return false; |
191 | } | |
192 | ||
1c3e52af | 193 | virtual bool LeftClick( wxPoint cursor, wxRect WXUNUSED(cell), |
ecad59d8 FM |
194 | wxDataViewModel *WXUNUSED(model), |
195 | const wxDataViewItem &WXUNUSED(item), | |
bf19b714 | 196 | unsigned int WXUNUSED(col) ) |
1c3e52af | 197 | { |
81c3f0fc | 198 | wxLogMessage( "MyCustomRenderer LeftClick( %d, %d )", cursor.x, cursor.y ); |
0bdfa388 RR |
199 | return false; |
200 | } | |
1c3e52af | 201 | |
0bdfa388 | 202 | virtual wxSize GetSize() const |
1c3e52af | 203 | { |
7448d67c | 204 | return wxSize(60,20); |
a7a27e86 | 205 | } |
1c3e52af VZ |
206 | |
207 | virtual bool SetValue( const wxVariant &value ) | |
208 | { | |
ef6833f9 | 209 | m_value = value.GetString(); |
a7a27e86 | 210 | return true; |
0bdfa388 | 211 | } |
1c3e52af | 212 | |
0bdfa388 | 213 | virtual bool GetValue( wxVariant &WXUNUSED(value) ) const { return true; } |
1c3e52af | 214 | |
a7a27e86 | 215 | private: |
ef6833f9 | 216 | wxString m_value; |
0bdfa388 RR |
217 | }; |
218 | ||
1c3e52af | 219 | |
bf19b714 FM |
220 | // ============================================================================ |
221 | // implementation | |
222 | // ============================================================================ | |
8c2654ce | 223 | |
bf19b714 | 224 | // ---------------------------------------------------------------------------- |
362d7fb9 | 225 | // MyApp |
bf19b714 | 226 | // ---------------------------------------------------------------------------- |
362d7fb9 | 227 | |
87f0efe2 | 228 | IMPLEMENT_APP(MyApp) |
bd6169a6 | 229 | |
bf19b714 | 230 | bool MyApp::OnInit() |
bd6169a6 | 231 | { |
45e6e6f8 VZ |
232 | if ( !wxApp::OnInit() ) |
233 | return false; | |
234 | ||
1c3e52af | 235 | MyFrame *frame = |
ecad59d8 | 236 | new MyFrame(NULL, "wxDataViewCtrl sample", 40, 40, 1000, 540); |
bd6169a6 | 237 | SetTopWindow(frame); |
bd6169a6 | 238 | |
bf19b714 FM |
239 | frame->Show(true); |
240 | return true; | |
87f0efe2 RR |
241 | } |
242 | ||
243 | ||
bf19b714 | 244 | // ---------------------------------------------------------------------------- |
bd6169a6 | 245 | // MyFrame |
bf19b714 | 246 | // ---------------------------------------------------------------------------- |
bd6169a6 | 247 | |
87f0efe2 RR |
248 | enum |
249 | { | |
ecad59d8 | 250 | ID_CLEARLOG = wxID_HIGHEST+1, |
bb58fa37 VZ |
251 | ID_BACKGROUND_COLOUR, |
252 | ID_FOREGROUND_COLOUR, | |
ecad59d8 | 253 | ID_STYLE_MENU, |
81c3f0fc | 254 | |
87f0efe2 | 255 | // file menu |
81c3f0fc FM |
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 | ||
87f0efe2 | 262 | ID_EXIT = wxID_EXIT, |
1c3e52af | 263 | |
81c3f0fc FM |
264 | // about menu |
265 | ID_ABOUT = wxID_ABOUT, | |
266 | ||
267 | ||
268 | // control IDs | |
269 | ||
d8331a01 | 270 | ID_MUSIC_CTRL = 50, |
5d9e1605 | 271 | ID_ATTR_CTRL = 51, |
1c3e52af | 272 | |
c534e696 RR |
273 | ID_ADD_MOZART = 100, |
274 | ID_DELETE_MUSIC = 101, | |
736fe67c | 275 | ID_DELETE_YEAR = 102, |
a400d56b | 276 | ID_SELECT_NINTH = 103, |
d2ee27fe RR |
277 | ID_COLLAPSE = 104, |
278 | ID_EXPAND = 105, | |
1c3e52af | 279 | |
c534e696 | 280 | ID_PREPEND_LIST = 200, |
b7e9f8b1 | 281 | ID_DELETE_LIST = 201, |
8b6cf9bf | 282 | ID_GOTO = 202, |
a46a47a3 | 283 | ID_ADD_MANY = 203, |
5d9e1605 RR |
284 | ID_HIDE_ATTRIBUTES = 204, |
285 | ID_SHOW_ATTRIBUTES = 205, | |
286 | ||
a46a47a3 RR |
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 | |
87f0efe2 RR |
292 | }; |
293 | ||
294 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
81c3f0fc | 295 | EVT_MENU_RANGE( ID_MULTIPLE, ID_VERT_RULES, MyFrame::OnStyleChange ) |
87f0efe2 | 296 | EVT_MENU( ID_EXIT, MyFrame::OnQuit ) |
81c3f0fc | 297 | EVT_MENU( ID_ABOUT, MyFrame::OnAbout ) |
ecad59d8 | 298 | EVT_MENU( ID_CLEARLOG, MyFrame::OnClearLog ) |
81c3f0fc | 299 | |
bb58fa37 VZ |
300 | EVT_MENU( ID_FOREGROUND_COLOUR, MyFrame::OnSetForegroundColour ) |
301 | EVT_MENU( ID_BACKGROUND_COLOUR, MyFrame::OnSetBackgroundColour ) | |
302 | ||
81c3f0fc FM |
303 | EVT_NOTEBOOK_PAGE_CHANGED( wxID_ANY, MyFrame::OnPageChanged ) |
304 | ||
c534e696 RR |
305 | EVT_BUTTON( ID_ADD_MOZART, MyFrame::OnAddMozart ) |
306 | EVT_BUTTON( ID_DELETE_MUSIC, MyFrame::OnDeleteMusic ) | |
736fe67c | 307 | EVT_BUTTON( ID_DELETE_YEAR, MyFrame::OnDeleteYear ) |
a400d56b | 308 | EVT_BUTTON( ID_SELECT_NINTH, MyFrame::OnSelectNinth ) |
d2ee27fe RR |
309 | EVT_BUTTON( ID_COLLAPSE, MyFrame::OnCollapse ) |
310 | EVT_BUTTON( ID_EXPAND, MyFrame::OnExpand ) | |
ecad59d8 | 311 | |
c534e696 RR |
312 | EVT_BUTTON( ID_PREPEND_LIST, MyFrame::OnPrependList ) |
313 | EVT_BUTTON( ID_DELETE_LIST, MyFrame::OnDeleteList ) | |
b7e9f8b1 | 314 | EVT_BUTTON( ID_GOTO, MyFrame::OnGoto) |
8b6cf9bf | 315 | EVT_BUTTON( ID_ADD_MANY, MyFrame::OnAddMany) |
5d9e1605 RR |
316 | EVT_BUTTON( ID_HIDE_ATTRIBUTES, MyFrame::OnHideAttributes) |
317 | EVT_BUTTON( ID_SHOW_ATTRIBUTES, MyFrame::OnShowAttributes) | |
a46a47a3 RR |
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 ) | |
1c3e52af | 323 | |
0376cc52 | 324 | EVT_DATAVIEW_ITEM_VALUE_CHANGED( ID_MUSIC_CTRL, MyFrame::OnValueChanged ) |
1c3e52af | 325 | |
b7e9f8b1 | 326 | EVT_DATAVIEW_ITEM_ACTIVATED(ID_MUSIC_CTRL, MyFrame::OnActivated ) |
718fd180 RR |
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) | |
aed836f3 | 331 | EVT_DATAVIEW_SELECTION_CHANGED(ID_MUSIC_CTRL, MyFrame::OnSelectionChanged) |
1c3e52af | 332 | |
ecc32226 | 333 | EVT_DATAVIEW_ITEM_START_EDITING(ID_MUSIC_CTRL, MyFrame::OnStartEditing) |
d14e1c3a RR |
334 | EVT_DATAVIEW_ITEM_EDITING_STARTED(ID_MUSIC_CTRL, MyFrame::OnEditingStarted) |
335 | EVT_DATAVIEW_ITEM_EDITING_DONE(ID_MUSIC_CTRL, MyFrame::OnEditingDone) | |
1c3e52af | 336 | |
b7e9f8b1 RR |
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) | |
74dea0de RR |
340 | |
341 | EVT_DATAVIEW_ITEM_CONTEXT_MENU(ID_MUSIC_CTRL, MyFrame::OnContextMenu) | |
8c2654ce | 342 | |
591cc82d | 343 | EVT_DATAVIEW_ITEM_BEGIN_DRAG( ID_MUSIC_CTRL, MyFrame::OnBeginDrag ) |
e4de825e RR |
344 | EVT_DATAVIEW_ITEM_DROP_POSSIBLE( ID_MUSIC_CTRL, MyFrame::OnDropPossible ) |
345 | EVT_DATAVIEW_ITEM_DROP( ID_MUSIC_CTRL, MyFrame::OnDrop ) | |
1c3e52af | 346 | |
b7e9f8b1 | 347 | EVT_RIGHT_UP(MyFrame::OnRightClick) |
5d9e1605 RR |
348 | |
349 | EVT_DATAVIEW_COLUMN_HEADER_CLICK(ID_ATTR_CTRL, MyFrame::OnAttrHeaderClick) | |
350 | ||
87f0efe2 RR |
351 | END_EVENT_TABLE() |
352 | ||
e94d0c1e | 353 | MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int h): |
bd6169a6 RR |
354 | wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)) |
355 | { | |
d8331a01 | 356 | m_log = NULL; |
fbda518c | 357 | m_col = NULL; |
d8331a01 | 358 | |
81c3f0fc FM |
359 | m_ctrl[0] = NULL; |
360 | m_ctrl[1] = NULL; | |
361 | m_ctrl[2] = NULL; | |
362 | m_ctrl[3] = NULL; | |
363 | ||
0bcd4039 | 364 | SetIcon(wxICON(sample)); |
bd6169a6 | 365 | |
bf19b714 FM |
366 | |
367 | // build the menus | |
368 | // ---------------- | |
87f0efe2 | 369 | |
81c3f0fc | 370 | wxMenu *style_menu = new wxMenu; |
ecad59d8 FM |
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"); | |
81c3f0fc | 376 | |
bd6169a6 | 377 | wxMenu *file_menu = new wxMenu; |
bb58fa37 | 378 | file_menu->Append(ID_CLEARLOG, "&Clear log\tCtrl-L"); |
1e21d0ef | 379 | file_menu->Append(ID_FOREGROUND_COLOUR, "Set &foreground colour...\tCtrl-S"); |
bb58fa37 | 380 | file_menu->Append(ID_BACKGROUND_COLOUR, "Set &background colour...\tCtrl-B"); |
ecad59d8 | 381 | file_menu->Append(ID_STYLE_MENU, "&Style", style_menu); |
87f0efe2 | 382 | file_menu->AppendSeparator(); |
ecad59d8 | 383 | file_menu->Append(ID_EXIT, "E&xit"); |
bd6169a6 | 384 | |
81c3f0fc | 385 | wxMenu *about_menu = new wxMenu; |
ecad59d8 | 386 | about_menu->Append(ID_ABOUT, "&About"); |
81c3f0fc | 387 | |
bd6169a6 | 388 | wxMenuBar *menu_bar = new wxMenuBar; |
ecad59d8 FM |
389 | menu_bar->Append(file_menu, "&File"); |
390 | menu_bar->Append(about_menu, "&About"); | |
87f0efe2 | 391 | |
bd6169a6 | 392 | SetMenuBar(menu_bar); |
87f0efe2 | 393 | CreateStatusBar(); |
8c2654ce | 394 | |
1e08ad10 | 395 | |
bf19b714 FM |
396 | // first page of the notebook |
397 | // -------------------------- | |
ecad59d8 | 398 | |
bf19b714 | 399 | m_notebook = new wxNotebook( this, wxID_ANY ); |
bd6169a6 | 400 | |
bf19b714 | 401 | wxPanel *firstPanel = new wxPanel( m_notebook, wxID_ANY ); |
bf19b714 | 402 | |
81c3f0fc | 403 | BuildDataViewCtrl(firstPanel, 0); // sets m_ctrl[0] |
1c3e52af | 404 | |
bf19b714 | 405 | wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL ); |
ecad59d8 FM |
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 ); | |
1c3e52af | 412 | |
bf19b714 | 413 | wxSizer *firstPanelSz = new wxBoxSizer( wxVERTICAL ); |
81c3f0fc FM |
414 | m_ctrl[0]->SetMinSize(wxSize(-1, 200)); |
415 | firstPanelSz->Add(m_ctrl[0], 1, wxGROW|wxALL, 5); | |
416 | firstPanelSz->Add( | |
ecad59d8 | 417 | new wxStaticText(firstPanel, wxID_ANY, "Most of the cells above are editable!"), |
81c3f0fc | 418 | 0, wxGROW|wxALL, 5); |
bf19b714 FM |
419 | firstPanelSz->Add(button_sizer); |
420 | firstPanel->SetSizerAndFit(firstPanelSz); | |
1c3e52af | 421 | |
83087c60 | 422 | |
bf19b714 FM |
423 | // second page of the notebook |
424 | // --------------------------- | |
83087c60 | 425 | |
bf19b714 | 426 | wxPanel *secondPanel = new wxPanel( m_notebook, wxID_ANY ); |
1c3e52af | 427 | |
81c3f0fc | 428 | BuildDataViewCtrl(secondPanel, 1); // sets m_ctrl[1] |
1c3e52af | 429 | |
bf19b714 | 430 | wxBoxSizer *button_sizer2 = new wxBoxSizer( wxHORIZONTAL ); |
5d9e1605 RR |
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 ); | |
a75124d0 | 437 | |
bf19b714 | 438 | wxSizer *secondPanelSz = new wxBoxSizer( wxVERTICAL ); |
81c3f0fc | 439 | secondPanelSz->Add(m_ctrl[1], 1, wxGROW|wxALL, 5); |
bf19b714 FM |
440 | secondPanelSz->Add(button_sizer2); |
441 | secondPanel->SetSizerAndFit(secondPanelSz); | |
1c3e52af | 442 | |
b7e9f8b1 | 443 | |
bf19b714 FM |
444 | // third page of the notebook |
445 | // --------------------------- | |
8c2654ce | 446 | |
bf19b714 | 447 | wxPanel *thirdPanel = new wxPanel( m_notebook, wxID_ANY ); |
8c2654ce | 448 | |
81c3f0fc | 449 | BuildDataViewCtrl(thirdPanel, 2); // sets m_ctrl[2] |
8c2654ce | 450 | |
bf19b714 | 451 | wxSizer *thirdPanelSz = new wxBoxSizer( wxVERTICAL ); |
81c3f0fc | 452 | thirdPanelSz->Add(m_ctrl[2], 1, wxGROW|wxALL, 5); |
bf19b714 | 453 | thirdPanel->SetSizerAndFit(thirdPanelSz); |
8c2654ce | 454 | |
672e58d9 | 455 | |
bf19b714 FM |
456 | // fourth page of the notebook |
457 | // --------------------------- | |
ecad59d8 | 458 | |
bf19b714 | 459 | wxPanel *fourthPanel = new wxPanel( m_notebook, wxID_ANY ); |
a75124d0 | 460 | |
81c3f0fc | 461 | BuildDataViewCtrl(fourthPanel, 3); // sets m_ctrl[3] |
a46a47a3 RR |
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 ); | |
1c3e52af | 468 | |
bf19b714 | 469 | wxSizer *fourthPanelSz = new wxBoxSizer( wxVERTICAL ); |
81c3f0fc | 470 | fourthPanelSz->Add(m_ctrl[3], 1, wxGROW|wxALL, 5); |
a46a47a3 | 471 | fourthPanelSz->Add(button_sizer4); |
bf19b714 | 472 | fourthPanel->SetSizerAndFit(fourthPanelSz); |
e39d30c0 | 473 | |
1c3e52af | 474 | |
ecad59d8 | 475 | |
bf19b714 FM |
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); | |
ecad59d8 FM |
485 | |
486 | m_log = new wxTextCtrl( this, wxID_ANY, wxString(), wxDefaultPosition, | |
bf19b714 FM |
487 | wxDefaultSize, wxTE_MULTILINE ); |
488 | m_log->SetMinSize(wxSize(-1, 100)); | |
489 | m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_log)); | |
ecad59d8 | 490 | wxLogMessage( "This is the log window" ); |
1c3e52af | 491 | |
bf19b714 FM |
492 | mainSizer->Add( m_notebook, 1, wxGROW ); |
493 | mainSizer->Add( m_log, 0, wxGROW ); | |
43b2d5e7 | 494 | |
bf19b714 | 495 | SetSizerAndFit(mainSizer); |
a75124d0 RR |
496 | } |
497 | ||
e39d30c0 RR |
498 | MyFrame::~MyFrame() |
499 | { | |
500 | delete wxLog::SetActiveTarget(m_logOld); | |
501 | } | |
502 | ||
81c3f0fc FM |
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); | |
ecad59d8 | 510 | m_ctrl[0] = |
81c3f0fc FM |
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 | ||
ecad59d8 FM |
522 | wxDataViewTextRenderer *tr = |
523 | new wxDataViewTextRenderer( "string", wxDATAVIEW_CELL_INERT ); | |
524 | wxDataViewColumn *column0 = | |
525 | new wxDataViewColumn( "title", tr, 0, 200, wxALIGN_LEFT, | |
81c3f0fc FM |
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 | ||
ecad59d8 FM |
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 | | |
81c3f0fc FM |
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 | ||
ecad59d8 | 546 | wxDataViewSpinRenderer *sr = |
81c3f0fc | 547 | new wxDataViewSpinRenderer( 0, 2010, wxDATAVIEW_CELL_EDITABLE, wxALIGN_RIGHT ); |
ecad59d8 FM |
548 | wxDataViewColumn *column2 = |
549 | new wxDataViewColumn( "year", sr, 2, 60, wxALIGN_LEFT, | |
81c3f0fc FM |
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" ); | |
ecad59d8 | 559 | wxDataViewChoiceRenderer *c = |
81c3f0fc | 560 | new wxDataViewChoiceRenderer( choices, wxDATAVIEW_CELL_EDITABLE, wxALIGN_RIGHT ); |
ecad59d8 FM |
561 | wxDataViewColumn *column3 = |
562 | new wxDataViewColumn( "rating", c, 3, 100, wxALIGN_LEFT, | |
81c3f0fc FM |
563 | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE ); |
564 | m_ctrl[0]->AppendColumn( column3 ); | |
565 | ||
566 | // column 4 of the view control: | |
567 | ||
ecad59d8 | 568 | m_ctrl[0]->AppendProgressColumn( "popularity", 4, wxDATAVIEW_CELL_INERT, 80 ); |
81c3f0fc FM |
569 | |
570 | // column 5 of the view control: | |
571 | ||
ef6833f9 | 572 | MyCustomRenderer *cr = new MyCustomRenderer; |
ecad59d8 FM |
573 | wxDataViewColumn *column5 = |
574 | new wxDataViewColumn( "custom", cr, 5, -1, wxALIGN_LEFT, | |
81c3f0fc FM |
575 | wxDATAVIEW_COL_RESIZABLE ); |
576 | m_ctrl[0]->AppendColumn( column5 ); | |
ecad59d8 | 577 | |
81c3f0fc FM |
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); | |
5d9e1605 | 587 | m_ctrl[1] = new wxDataViewCtrl( parent, ID_ATTR_CTRL, wxDefaultPosition, |
81c3f0fc FM |
588 | wxDefaultSize, style ); |
589 | ||
590 | m_list_model = new MyListModel; | |
591 | m_ctrl[1]->AssociateModel( m_list_model.get() ); | |
592 | ||
593 | // the various columns | |
2746bccf VZ |
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); | |
5d9e1605 RR |
600 | |
601 | m_attributes = | |
2746bccf VZ |
602 | new wxDataViewColumn("attributes", |
603 | new wxDataViewTextRenderer, | |
5d9e1605 RR |
604 | MyListModel::Col_TextWithAttr, |
605 | 80, | |
606 | wxALIGN_RIGHT, | |
607 | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE ); | |
608 | m_ctrl[1]->AppendColumn( m_attributes ); | |
ef6833f9 VZ |
609 | |
610 | m_ctrl[1]->AppendColumn( | |
611 | new wxDataViewColumn("custom renderer", | |
612 | new MyCustomRenderer, | |
613 | MyListModel::Col_Custom) | |
614 | ); | |
81c3f0fc FM |
615 | } |
616 | break; | |
617 | ||
618 | case 2: | |
619 | { | |
620 | wxASSERT(!m_ctrl[2]); | |
ecad59d8 | 621 | wxDataViewListCtrl* lc = |
81c3f0fc FM |
622 | new wxDataViewListCtrl( parent, wxID_ANY, wxDefaultPosition, |
623 | wxDefaultSize, style ); | |
624 | m_ctrl[2] = lc; | |
625 | ||
ecad59d8 FM |
626 | lc->AppendToggleColumn( "Toggle" ); |
627 | lc->AppendTextColumn( "Text" ); | |
628 | lc->AppendProgressColumn( "Progress" ); | |
81c3f0fc FM |
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]); | |
ecad59d8 | 646 | wxDataViewTreeCtrl* tc = |
81c3f0fc | 647 | new wxDataViewTreeCtrl( parent, wxID_ANY, wxDefaultPosition, |
a35169b6 | 648 | wxDefaultSize, style | wxDV_NO_HEADER ); |
81c3f0fc FM |
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 | ||
ecad59d8 FM |
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 ); | |
81c3f0fc FM |
660 | |
661 | wxDataViewItem cont = | |
ecad59d8 FM |
662 | tc->AppendContainer( parent, "Container child", 0 ); |
663 | tc->AppendItem( cont, "Child 4", 0 ); | |
664 | tc->AppendItem( cont, "Child 5", 0 ); | |
81c3f0fc FM |
665 | |
666 | tc->Expand(cont); | |
ecad59d8 | 667 | } |
81c3f0fc FM |
668 | break; |
669 | } | |
670 | } | |
671 | ||
672 | ||
673 | // ---------------------------------------------------------------------------- | |
674 | // MyFrame - generic event handlers | |
675 | // ---------------------------------------------------------------------------- | |
676 | ||
ecad59d8 FM |
677 | void MyFrame::OnClearLog( wxCommandEvent& WXUNUSED(event) ) |
678 | { | |
679 | m_log->Clear(); | |
680 | } | |
681 | ||
bb58fa37 VZ |
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 | ||
ecad59d8 | 704 | void MyFrame::OnPageChanged( wxBookCtrlEvent& WXUNUSED(event) ) |
81c3f0fc FM |
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 | ||
ecad59d8 | 739 | void MyFrame::OnStyleChange( wxCommandEvent& WXUNUSED(event) ) |
81c3f0fc FM |
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) ) | |
a75124d0 RR |
776 | { |
777 | Close(true); | |
e94d0c1e RR |
778 | } |
779 | ||
ecad59d8 | 780 | void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) ) |
81c3f0fc FM |
781 | { |
782 | wxAboutDialogInfo info; | |
783 | info.SetName(_("DataView sample")); | |
784 | info.SetDescription(_("This sample demonstrates wxDataViewCtrl")); | |
9a83f860 | 785 | info.SetCopyright(wxT("(C) 2007-2009 Robert Roebling")); |
81c3f0fc FM |
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 | ||
ecad59d8 | 846 | wxLogMessage( "Text dropped: %s", obj.GetText() ); |
81c3f0fc FM |
847 | } |
848 | ||
849 | void MyFrame::OnAddMozart( wxCommandEvent& WXUNUSED(event) ) | |
c534e696 | 850 | { |
ecad59d8 | 851 | m_music_model->AddToClassical( "Kleine Nachtmusik", "Wolfgang Mozart", 1787 ); |
c534e696 RR |
852 | } |
853 | ||
81c3f0fc | 854 | void MyFrame::OnDeleteMusic( wxCommandEvent& WXUNUSED(event) ) |
1e08ad10 | 855 | { |
b7e9f8b1 | 856 | wxDataViewItemArray items; |
81c3f0fc | 857 | int len = m_ctrl[0]->GetSelections( items ); |
b7e9f8b1 RR |
858 | for( int i = 0; i < len; i ++ ) |
859 | if (items[i].IsOk()) | |
860 | m_music_model->Delete( items[i] ); | |
e63807a8 RR |
861 | } |
862 | ||
736fe67c RR |
863 | void MyFrame::OnDeleteYear( wxCommandEvent& WXUNUSED(event) ) |
864 | { | |
81c3f0fc | 865 | m_ctrl[0]->DeleteColumn( m_ctrl[0]->GetColumn( 2 ) ); |
736fe67c RR |
866 | FindWindow( ID_DELETE_YEAR )->Disable(); |
867 | } | |
868 | ||
a400d56b RR |
869 | void MyFrame::OnSelectNinth( wxCommandEvent& WXUNUSED(event) ) |
870 | { | |
ecad59d8 FM |
871 | if (!m_music_model->GetNinthItem().IsOk()) |
872 | { | |
873 | wxLogError( "Cannot select the ninth symphony: it was removed!" ); | |
874 | return; | |
875 | } | |
876 | ||
81c3f0fc | 877 | m_ctrl[0]->Select( m_music_model->GetNinthItem() ); |
1e08ad10 RR |
878 | } |
879 | ||
d2ee27fe RR |
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 | ||
d8331a01 RR |
894 | void MyFrame::OnValueChanged( wxDataViewEvent &event ) |
895 | { | |
896 | if (!m_log) | |
897 | return; | |
1c3e52af | 898 | |
a8fde0a8 RR |
899 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
900 | wxLogMessage( "wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, Item Id: %s; Column: %d", | |
901 | title, event.GetColumn() ); | |
b7e9f8b1 RR |
902 | } |
903 | ||
904 | void MyFrame::OnActivated( wxDataViewEvent &event ) | |
905 | { | |
906 | if(!m_log) | |
907 | return; | |
908 | ||
d32332aa | 909 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
ecad59d8 | 910 | wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item: %s", title ); |
8c2654ce | 911 | |
81c3f0fc | 912 | if (m_ctrl[0]->IsExpanded( event.GetItem() )) |
43b2d5e7 | 913 | { |
ecad59d8 | 914 | wxLogMessage( "Item: %s is expanded", title ); |
43b2d5e7 | 915 | } |
b7e9f8b1 RR |
916 | } |
917 | ||
aed836f3 | 918 | void MyFrame::OnSelectionChanged( wxDataViewEvent &event ) |
6848478c RR |
919 | { |
920 | if(!m_log) | |
921 | return; | |
922 | ||
d32332aa RR |
923 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
924 | if (title.empty()) | |
ecad59d8 | 925 | title = "None"; |
1c3e52af | 926 | |
ecad59d8 | 927 | wxLogMessage( "wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, First selected Item: %s", title ); |
6848478c RR |
928 | } |
929 | ||
718fd180 RR |
930 | void MyFrame::OnExpanding( wxDataViewEvent &event ) |
931 | { | |
932 | if (!m_log) | |
933 | return; | |
1c3e52af | 934 | |
d32332aa | 935 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
ecad59d8 | 936 | wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, Item: %s", title ); |
718fd180 RR |
937 | } |
938 | ||
d14e1c3a | 939 | |
ecc32226 RR |
940 | void MyFrame::OnStartEditing( wxDataViewEvent &event ) |
941 | { | |
942 | wxString artist = m_music_model->GetArtist( event.GetItem() ); | |
943 | if (artist == "Ludwig van Beethoven") | |
944 | { | |
945 | event.Veto(); | |
43b2d5e7 | 946 | |
ecc32226 RR |
947 | if (!m_log) |
948 | return; | |
43b2d5e7 | 949 | |
0a807957 | 950 | wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING vetoed. Artist: %s", artist ); |
ecc32226 | 951 | } |
0a807957 RR |
952 | else |
953 | wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING not vetoed. Artist: %s", artist ); | |
43b2d5e7 | 954 | |
ecc32226 RR |
955 | } |
956 | ||
d14e1c3a RR |
957 | void MyFrame::OnEditingStarted( wxDataViewEvent &event ) |
958 | { | |
959 | if (!m_log) | |
960 | return; | |
1c3e52af | 961 | |
d32332aa | 962 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
ecad59d8 | 963 | wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, Item: %s", title ); |
d14e1c3a RR |
964 | } |
965 | ||
966 | void MyFrame::OnEditingDone( wxDataViewEvent &event ) | |
967 | { | |
968 | if (!m_log) | |
969 | return; | |
1c3e52af | 970 | |
d32332aa | 971 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
ecad59d8 | 972 | wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, Item: %s", title ); |
d14e1c3a RR |
973 | } |
974 | ||
718fd180 RR |
975 | void MyFrame::OnExpanded( wxDataViewEvent &event ) |
976 | { | |
977 | if (!m_log) | |
978 | return; | |
1c3e52af | 979 | |
d32332aa | 980 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
ecad59d8 | 981 | wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, Item: %s", title ); |
718fd180 RR |
982 | } |
983 | ||
984 | void MyFrame::OnCollapsing( wxDataViewEvent &event ) | |
985 | { | |
986 | if (!m_log) | |
987 | return; | |
1c3e52af | 988 | |
d32332aa | 989 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
ecad59d8 | 990 | wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, Item: %s", title ); |
718fd180 RR |
991 | } |
992 | ||
993 | void MyFrame::OnCollapsed( wxDataViewEvent &event ) | |
994 | { | |
995 | if (!m_log) | |
996 | return; | |
1c3e52af | 997 | |
d32332aa | 998 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
ecad59d8 | 999 | wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, Item: %s", title ); |
718fd180 RR |
1000 | } |
1001 | ||
74dea0de RR |
1002 | void MyFrame::OnContextMenu( wxDataViewEvent &event ) |
1003 | { | |
1004 | if (!m_log) | |
1005 | return; | |
1c3e52af | 1006 | |
74dea0de | 1007 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
ecad59d8 | 1008 | wxLogMessage( "wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s", title ); |
1c3e52af VZ |
1009 | |
1010 | wxMenu menu; | |
ecad59d8 FM |
1011 | menu.Append( 1, "menuitem 1" ); |
1012 | menu.Append( 2, "menuitem 2" ); | |
1013 | menu.Append( 3, "menuitem 3" ); | |
1c3e52af | 1014 | |
81c3f0fc | 1015 | m_ctrl[0]->PopupMenu(&menu); |
74dea0de RR |
1016 | } |
1017 | ||
5d9e1605 RR |
1018 | void MyFrame::OnAttrHeaderClick( wxDataViewEvent &event ) |
1019 | { | |
1020 | // we need to skip the event to let the default behaviour of sorting by | |
1021 | // this column when it is clicked to take place | |
1022 | event.Skip(); | |
1023 | ||
1024 | if (!m_log) | |
1025 | return; | |
1026 | ||
1027 | int pos = m_ctrl[1]->GetColumnPosition( event.GetDataViewColumn() ); | |
1028 | ||
1029 | wxLogMessage( "wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, Column position: %d", pos ); | |
1030 | wxLogMessage( "Column title: %s Column width: %d", event.GetDataViewColumn()->GetTitle(), event.GetDataViewColumn()->GetWidth() ); | |
1031 | } | |
1032 | ||
b7e9f8b1 RR |
1033 | void MyFrame::OnHeaderClick( wxDataViewEvent &event ) |
1034 | { | |
fba41cf3 VZ |
1035 | // we need to skip the event to let the default behaviour of sorting by |
1036 | // this column when it is clicked to take place | |
1037 | event.Skip(); | |
1038 | ||
81c3f0fc | 1039 | if (!m_log) |
b7e9f8b1 | 1040 | return; |
1c3e52af | 1041 | |
81c3f0fc | 1042 | int pos = m_ctrl[0]->GetColumnPosition( event.GetDataViewColumn() ); |
b7e9f8b1 | 1043 | |
ecad59d8 | 1044 | wxLogMessage( "wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, Column position: %d", pos ); |
1c958845 | 1045 | wxLogMessage( "Column width: %d", event.GetDataViewColumn()->GetWidth() ); |
b7e9f8b1 RR |
1046 | } |
1047 | ||
1048 | void MyFrame::OnHeaderRightClick( wxDataViewEvent &event ) | |
1049 | { | |
1050 | if(!m_log) | |
1051 | return; | |
1052 | ||
81c3f0fc | 1053 | int pos = m_ctrl[0]->GetColumnPosition( event.GetDataViewColumn() ); |
dadc879e | 1054 | |
ecad59d8 | 1055 | wxLogMessage( "wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, Column position: %d", pos ); |
b7e9f8b1 RR |
1056 | } |
1057 | ||
1058 | void MyFrame::OnSorted( wxDataViewEvent &event ) | |
1059 | { | |
1060 | if(!m_log) | |
1061 | return; | |
1062 | ||
81c3f0fc | 1063 | int pos = m_ctrl[0]->GetColumnPosition( event.GetDataViewColumn() ); |
d32332aa | 1064 | |
ecad59d8 | 1065 | wxLogMessage( "wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, Column position: %d", pos ); |
b7e9f8b1 RR |
1066 | } |
1067 | ||
1068 | void MyFrame::OnRightClick( wxMouseEvent &event ) | |
1069 | { | |
1070 | if(!m_log) | |
1071 | return; | |
1072 | ||
ecad59d8 FM |
1073 | wxLogMessage( "wxEVT_MOUSE_RIGHT_UP, Click Point is X: %d, Y: %d", |
1074 | event.GetX(), event.GetY() ); | |
b7e9f8b1 RR |
1075 | } |
1076 | ||
8b6cf9bf | 1077 | |
81c3f0fc FM |
1078 | // ---------------------------------------------------------------------------- |
1079 | // MyFrame - event handlers for the second page | |
1080 | // ---------------------------------------------------------------------------- | |
8b6cf9bf | 1081 | |
81c3f0fc | 1082 | void MyFrame::OnPrependList( wxCommandEvent& WXUNUSED(event) ) |
bd6169a6 | 1083 | { |
ecad59d8 | 1084 | m_list_model->Prepend("Test"); |
bd6169a6 RR |
1085 | } |
1086 | ||
81c3f0fc | 1087 | void MyFrame::OnDeleteList( wxCommandEvent& WXUNUSED(event) ) |
15cac64f | 1088 | { |
81c3f0fc FM |
1089 | wxDataViewItemArray items; |
1090 | int len = m_ctrl[1]->GetSelections( items ); | |
1091 | if (len > 0) | |
1092 | m_list_model->DeleteItems( items ); | |
15cac64f | 1093 | } |
e4de825e | 1094 | |
81c3f0fc | 1095 | void MyFrame::OnGoto(wxCommandEvent& WXUNUSED(event)) |
e4de825e | 1096 | { |
81c3f0fc FM |
1097 | wxDataViewItem item = m_list_model->GetItem( 50 ); |
1098 | m_ctrl[1]->EnsureVisible(item,m_col); | |
e4de825e RR |
1099 | } |
1100 | ||
81c3f0fc | 1101 | void MyFrame::OnAddMany(wxCommandEvent& WXUNUSED(event)) |
e4de825e | 1102 | { |
81c3f0fc | 1103 | m_list_model->AddMany(); |
e4de825e RR |
1104 | } |
1105 | ||
5d9e1605 RR |
1106 | void MyFrame::OnHideAttributes(wxCommandEvent& WXUNUSED(event)) |
1107 | { | |
1108 | m_attributes->SetHidden(true); | |
1109 | } | |
1110 | ||
1111 | void MyFrame::OnShowAttributes(wxCommandEvent& WXUNUSED(event)) | |
1112 | { | |
1113 | m_attributes->SetHidden(false); | |
1114 | } | |
1115 | ||
a46a47a3 RR |
1116 | // ---------------------------------------------------------------------------- |
1117 | // MyFrame - event handlers for the fourth page | |
1118 | // ---------------------------------------------------------------------------- | |
a53f722f RR |
1119 | |
1120 | void MyFrame::OnDeleteTreeItem(wxCommandEvent& WXUNUSED(event)) | |
1121 | { | |
a46a47a3 RR |
1122 | wxDataViewTreeCtrl* ctrl = (wxDataViewTreeCtrl*) m_ctrl[3]; |
1123 | wxDataViewItem selected = ctrl->GetSelection(); | |
a53f722f | 1124 | if (!selected.IsOk()) |
a46a47a3 | 1125 | return; |
a53f722f | 1126 | |
a46a47a3 RR |
1127 | ctrl->DeleteItem(selected); |
1128 | } | |
1129 | ||
a53f722f RR |
1130 | void MyFrame::OnDeleteAllTreeItems(wxCommandEvent& WXUNUSED(event)) |
1131 | { | |
a46a47a3 RR |
1132 | wxDataViewTreeCtrl* ctrl = (wxDataViewTreeCtrl*) m_ctrl[3]; |
1133 | ctrl->DeleteAllItems(); | |
1134 | } | |
1135 | ||
a53f722f RR |
1136 | void MyFrame::OnAddTreeItem(wxCommandEvent& WXUNUSED(event)) |
1137 | { | |
a46a47a3 RR |
1138 | wxDataViewTreeCtrl* ctrl = (wxDataViewTreeCtrl*) m_ctrl[3]; |
1139 | wxDataViewItem selected = ctrl->GetSelection(); | |
8ddda15b RR |
1140 | if (ctrl->IsContainer(selected)) |
1141 | ctrl->AppendItem( selected, "Item", 0 ); | |
a46a47a3 RR |
1142 | } |
1143 | ||
a53f722f RR |
1144 | void MyFrame::OnAddTreeContainerItem(wxCommandEvent& WXUNUSED(event)) |
1145 | { | |
a46a47a3 RR |
1146 | wxDataViewTreeCtrl* ctrl = (wxDataViewTreeCtrl*) m_ctrl[3]; |
1147 | wxDataViewItem selected = ctrl->GetSelection(); | |
8ddda15b RR |
1148 | if (ctrl->IsContainer(selected)) |
1149 | ctrl->AppendContainer(selected, "Container", 0 ); | |
a46a47a3 RR |
1150 | } |
1151 |