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