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