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