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