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