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