]> git.saurik.com Git - wxWidgets.git/blame - samples/dataview/dataview.cpp
distribute only the extra, free, space according to the items proportions in wxBoxSiz...
[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
9861f022 5// Modified by: Francesco Montorsi
bd6169a6
RR
6// Created: 06/01/06
7// RCS-ID: $Id$
8// Copyright: (c) Robert Roebling
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx/wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
0bcd4039 20 #include "wx/wx.h"
bd6169a6
RR
21#endif
22
b910a8ad 23#include "wx/datetime.h"
87f0efe2
RR
24#include "wx/splitter.h"
25#include "wx/aboutdlg.h"
9861f022
RR
26#include "wx/choicdlg.h"
27#include "wx/numdlg.h"
28#include "wx/dataview.h"
1e510b1e 29#include "wx/spinctrl.h"
b910a8ad 30
bd6169a6 31#ifndef __WXMSW__
0bcd4039 32 #include "../sample.xpm"
bd6169a6
RR
33#endif
34
cbc9145c
RR
35#include "null.xpm"
36
9861f022
RR
37
38#define DEFAULT_ALIGN wxALIGN_LEFT
39#define DATAVIEW_DEFAULT_STYLE (wxDV_MULTIPLE|wxDV_HORIZ_RULES|wxDV_VERT_RULES)
40
41
bd6169a6 42
362d7fb9
RR
43// -------------------------------------
44// MyTextModel
45// -------------------------------------
bd6169a6 46
87f0efe2
RR
47WX_DECLARE_OBJARRAY(wxDateTime,wxArrayDate);
48#include <wx/arrimpl.cpp>
49WX_DEFINE_OBJARRAY(wxArrayDate)
4d496ecb 50
362d7fb9 51class MyTextModel: public wxDataViewListModel
bd6169a6
RR
52{
53public:
b910a8ad 54 MyTextModel()
a7f61f76 55 {
0a71f9e9 56 unsigned int i;
a7f61f76
RR
57 for (i = 0; i < 1000; i++)
58 m_list.Add( wxT("Test") );
605c2c4a
RR
59 for (i = 0; i < 500; i++)
60 { m_bools.Add( 0 ); m_bools.Add( 1 ); }
e152afc3
RR
61 for (i = 0; i < 500; i++)
62 { m_colours.Add( wxT("red") ); m_colours.Add( wxT("green") ); }
ad63bf41
RR
63 for (i = 0; i < 1000; i++)
64 { m_progress.Add( i/10 ); }
4d496ecb 65 for (i = 0; i < 1000; i++)
b910a8ad 66 {
87f0efe2
RR
67 wxDateTime date( wxDateTime::Now() );
68 m_dates.Add( date );
4d496ecb 69 }
a7f61f76 70 }
b910a8ad 71
9861f022 72 virtual unsigned int GetRowCount() const
362d7fb9 73 { return 1000; }
9861f022 74 virtual unsigned int GetColumnCount() const
4d496ecb 75 { return 7; }
b910a8ad 76
362d7fb9 77 // as reported by wxVariant
9861f022 78 virtual wxString GetColumnType( unsigned int col ) const
605c2c4a 79 {
4d496ecb
RR
80 if (col == 6)
81 return wxT("datetime");
b910a8ad 82
ad63bf41
RR
83 if (col == 5)
84 return wxT("long");
b910a8ad 85
605c2c4a
RR
86 if (col == 3)
87 return wxT("bool");
b910a8ad
JS
88
89 return wxT("string");
605c2c4a 90 }
b910a8ad 91
9861f022 92 virtual void GetValue( wxVariant &variant, unsigned int col, unsigned int row ) const
605c2c4a 93 {
4d496ecb
RR
94 if (col == 6)
95 {
87f0efe2 96 variant = (wxDateTime) m_dates[row];
4d496ecb 97 } else
ad63bf41 98 if (col == 5)
605c2c4a 99 {
3f3af7e7 100 variant = (long) m_progress[row];
ad63bf41 101 } else
e152afc3
RR
102 if (col == 4)
103 {
3f3af7e7 104 variant = m_colours[row];
ad63bf41
RR
105 } else
106 if (col == 3)
107 {
87f0efe2 108 variant = (bool) (m_bools[row] != 0);
b910a8ad 109 } else
a7f61f76
RR
110 if (col == 2)
111 {
3f3af7e7 112 variant = m_list[row];
a7f61f76
RR
113 }
114 else
115 {
b910a8ad
JS
116 wxString tmp;
117 tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col );
3f3af7e7 118 variant = tmp;
a7f61f76 119 }
362d7fb9 120 }
0a71f9e9 121 virtual bool SetValue( wxVariant &value, unsigned int col, unsigned int row )
a7f61f76 122 {
4d496ecb
RR
123 if (col == 6)
124 {
87f0efe2 125 m_dates[row] = value.GetDateTime();
4d496ecb 126 } else
605c2c4a
RR
127 if (col == 3)
128 {
129 m_bools[row] = (int) value.GetBool();
130 } else
a7f61f76
RR
131 if (col == 2)
132 {
133 m_list[row] = value.GetString();
134 }
135 return true;
136 }
b910a8ad 137
a7f61f76 138 wxArrayString m_list;
605c2c4a 139 wxArrayInt m_bools;
e152afc3 140 wxArrayString m_colours;
ad63bf41 141 wxArrayInt m_progress;
4d496ecb 142 wxArrayDate m_dates;
e152afc3
RR
143};
144
47c94466
RR
145// -------------------------------------
146// MyTextRenderer
147// -------------------------------------
148
149class MyTextRenderer: public wxDataViewTextRenderer
150{
151public:
152 MyTextRenderer( const wxString varianttype = wxT("string"),
153 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT )
154 : wxDataViewTextRenderer( varianttype, mode ) { }
155
156 virtual bool Validate( wxVariant &value )
157 {
158 wxString str = value;
159 if (str.Length() > 10)
160 {
161 wxMessageDialog dlg( NULL, wxT("string too long") , wxT("Error") );
162 dlg.ShowModal();
47c94466
RR
163 return false;
164 }
165
166 return true;
167 }
168};
169
170
e152afc3 171// -------------------------------------
baa9ebc4 172// MyCustomRenderer
e152afc3
RR
173// -------------------------------------
174
baa9ebc4 175class MyCustomRenderer: public wxDataViewCustomRenderer
e152afc3
RR
176{
177public:
baa9ebc4
RR
178 MyCustomRenderer() :
179 wxDataViewCustomRenderer( wxT("string"), wxDATAVIEW_CELL_ACTIVATABLE )
b910a8ad
JS
180 {
181 m_colour = wxT("black");
e152afc3
RR
182 }
183 bool SetValue( const wxVariant &value )
184 {
185 m_colour = value.GetString();
186 return true;
187 }
9861f022
RR
188
189 bool GetValue( wxVariant &value ) const
190 {
191 value = m_colour;
192 return true;
193 }
194
f554a14b 195 bool Render( wxRect rect, wxDC *dc, int WXUNUSED(state) )
b910a8ad 196 {
e152afc3
RR
197 dc->SetPen( *wxBLACK_PEN );
198 if (m_colour == wxT("red"))
199 dc->SetBrush( *wxRED_BRUSH );
200 else if (m_colour == wxT("green"))
201 dc->SetBrush( *wxGREEN_BRUSH );
b910a8ad 202 else
e152afc3
RR
203 dc->SetBrush( *wxBLACK_BRUSH );
204 dc->DrawRectangle( rect );
205 return true;
206 }
9861f022 207 wxSize GetSize() const
e152afc3
RR
208 {
209 return wxSize(20,8);
210 }
f554a14b
WS
211 bool Activate( wxRect WXUNUSED(rect),
212 wxDataViewListModel *WXUNUSED(model),
0a71f9e9
RR
213 unsigned int WXUNUSED(col),
214 unsigned int WXUNUSED(row) )
553f7d8f 215 {
553f7d8f
RR
216 return false;
217 }
e152afc3
RR
218
219private:
b910a8ad 220 wxString m_colour;
0313c114 221};
bd6169a6 222
1e510b1e
RR
223// -------------------------------------
224// MySpinCtrlInPlaceRenderer
225// -------------------------------------
226
227class MySpinCtrlInPlaceRenderer: public wxDataViewCustomRenderer
228{
229public:
230 MySpinCtrlInPlaceRenderer() :
231 wxDataViewCustomRenderer( wxT("long"), wxDATAVIEW_CELL_EDITABLE ) { }
232
233
234 virtual bool HasEditorCtrl()
235 {
236 return true;
237 }
238 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
239 {
240 long l = value;
241 return new wxSpinCtrl( parent, wxID_ANY, wxEmptyString,
242 labelRect.GetTopLeft(), labelRect.GetSize(), 0, 0, 100, l );
243 }
244 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value )
245 {
246 wxSpinCtrl *sc = (wxSpinCtrl*) editor;
247 long l = sc->GetValue();
248 value = l;
249 return true;
250 }
251
252 bool Render( wxRect rect, wxDC *dc, int WXUNUSED(state) )
253 {
254 wxString str;
255 str.Printf( wxT("%d"), (int) m_data );
256 dc->SetTextForeground( *wxBLACK );
257 dc->DrawText( str, rect.x, rect.y );
258 return true;
259 }
260 wxSize GetSize() const
261 {
262 return wxSize(80,16);
263 }
264 bool SetValue( const wxVariant &value )
265 {
266 m_data = value.GetLong();
267 return true;
268 }
269 bool GetValue( wxVariant &value ) const
270 {
271 value = m_data;
272 return true;
273 }
274
275
276private:
277 long m_data;
278};
279
241cb04b
RR
280// -------------------------------------
281// MyUnsortedTextModel
282// -------------------------------------
283
284class MyUnsortedTextModel: public wxDataViewListModel
285{
286public:
287 MyUnsortedTextModel()
288 {
289 m_list.Add( wxT("This") );
290 m_list.Add( wxT("is") );
291 m_list.Add( wxT("an") );
292 m_list.Add( wxT("unsorted") );
293 m_list.Add( wxT("list") );
294 m_list.Add( wxT("of") );
295 m_list.Add( wxT("words.") );
cbc9145c 296
1e510b1e
RR
297 m_ilist.Add( 0 );
298 m_ilist.Add( 1);
299 m_ilist.Add( 2 );
300 m_ilist.Add( 3 );
301 m_ilist.Add( 4 );
302 m_ilist.Add( 5 );
303 m_ilist.Add( 6 );
304
cbc9145c 305 m_bitmap = wxBitmap( null_xpm );
241cb04b
RR
306 }
307
9861f022
RR
308 virtual unsigned int GetRowCount() const
309 {
310 return m_list.GetCount();
311 }
312
313 virtual unsigned int GetColumnCount() const
314 {
1e510b1e 315 return 4;
9861f022
RR
316 }
317
318 virtual wxString GetColumnType( unsigned int WXUNUSED(col) ) const
319 {
320 return wxT("string");
321 }
322
323 virtual void GetValue( wxVariant &variant, unsigned int col, unsigned int row ) const
241cb04b
RR
324 {
325 if (col == 0)
3f3af7e7
RR
326 {
327 variant = m_list[row];
328 return;
1e510b1e 329 } else
979f71a3 330 if ((col == 2) || (col == 3))
cbc9145c 331 {
979f71a3 332 variant << m_bitmap;
cbc9145c 333 return;
1e510b1e
RR
334 } else
335 if (col == 4)
336 {
337 variant = (long) m_ilist[row];
338 return;
cbc9145c 339 }
1e510b1e 340
241cb04b 341 wxString tmp;
b910a8ad 342 tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col );
3f3af7e7 343 variant = tmp;
241cb04b 344 }
9861f022 345
0a71f9e9 346 virtual bool SetValue( wxVariant &variant, unsigned int col, unsigned int row )
241cb04b
RR
347 {
348 if (col == 0)
349 {
350 m_list[row] = variant.GetString();
351 return true;
1e510b1e
RR
352 } else
353 if (col == 4)
354 {
355 m_ilist[row] = variant.GetLong();
356 return true;
241cb04b
RR
357 }
358 return false;
b910a8ad 359
241cb04b
RR
360 }
361
4627af27
RR
362 void AppendRow( const wxString &text )
363 {
364 m_list.Add( text );
1e510b1e 365 m_ilist.Add( 0 );
4627af27
RR
366 RowAppended();
367 }
368
369 void PrependRow( const wxString &text )
370 {
371 m_list.Insert( text, 0 );
1e510b1e 372 m_ilist.Insert( 0, 0 );
4627af27
RR
373 RowPrepended();
374 }
375
376 void InsertRowAt1( const wxString &text )
377 {
378 m_list.Insert( text, 1 );
1e510b1e 379 m_ilist.Insert( 0, 1 );
4627af27
RR
380 RowInserted( 1 );
381 }
382
0a71f9e9 383 void DeleteRow( unsigned int index )
4627af27
RR
384 {
385 m_list.RemoveAt( index );
1e510b1e 386 m_ilist.RemoveAt( index );
4627af27
RR
387 RowDeleted( index );
388 }
389
241cb04b 390 wxArrayString m_list;
1e510b1e 391 wxArrayInt m_ilist;
cbc9145c 392 wxBitmap m_bitmap;
241cb04b
RR
393};
394
362d7fb9
RR
395// -------------------------------------
396// MyApp
397// -------------------------------------
bd6169a6
RR
398
399class MyApp: public wxApp
400{
401public:
402 bool OnInit(void);
87f0efe2 403 int OnExit();
bd6169a6
RR
404};
405
362d7fb9
RR
406// -------------------------------------
407// MyFrame
408// -------------------------------------
409
87f0efe2 410class MyFrame : public wxFrame
bd6169a6
RR
411{
412public:
413 MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h);
414
415public:
416 void OnQuit(wxCommandEvent& event);
417 void OnAbout(wxCommandEvent& event);
87f0efe2
RR
418 void OnNewSortingFrame(wxCommandEvent& event);
419
9861f022
RR
420 void OnStyleChange(wxCommandEvent& event);
421 void OnColumnSetting(wxCommandEvent& event);
b910a8ad 422
bd6169a6 423private:
a7f61f76
RR
424 wxDataViewCtrl* dataview_left;
425 wxDataViewCtrl* dataview_right;
87f0efe2 426 wxSplitterWindow *m_splitter;
9861f022
RR
427 wxPanel *m_panelLeft, *m_panelRight;
428
429 // utilities:
87f0efe2 430
9861f022 431 void CreateDataViewControls();
87f0efe2 432
9861f022
RR
433 wxArrayInt GetFlaggedColumns(int flag);
434 wxAlignment ChooseAlign(const wxString &msg, bool onlyHorizontal);
435 void SetFlag(const wxArrayInt &idx, int flag);
436 void SetAlignment(const wxArrayInt &idx, bool header, wxAlignment align);
437 void SetWidth(const wxArrayInt &idx, bool minwidth, int width);
87f0efe2
RR
438
439private:
440 DECLARE_EVENT_TABLE()
bd6169a6
RR
441};
442
241cb04b
RR
443// -------------------------------------
444// MySortingFrame
445// -------------------------------------
446
abd6692c
RR
447enum my_events
448{
449 ID_APPEND_ROW_LEFT = 1000,
450 ID_PREPEND_ROW_LEFT,
451 ID_INSERT_ROW_LEFT,
452 ID_DELETE_ROW_LEFT,
453 ID_EDIT_ROW_LEFT,
fc211fe5
RR
454
455 ID_SELECT,
456 ID_UNSELECT_ALL,
b910a8ad 457
abd6692c
RR
458 ID_APPEND_ROW_RIGHT,
459 ID_PREPEND_ROW_RIGHT,
460 ID_INSERT_ROW_RIGHT,
461 ID_DELETE_ROW_RIGHT,
eb7f97f8
RR
462 ID_EDIT_ROW_RIGHT,
463
464 ID_SORTED,
f828871d
RR
465 ID_UNSORTED,
466 ID_ACTIVATED
abd6692c
RR
467};
468
241cb04b
RR
469class MySortingFrame: public wxFrame
470{
471public:
472 MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h);
eb7f97f8 473 ~MySortingFrame();
241cb04b
RR
474
475public:
476 void OnQuit(wxCommandEvent& event);
477 void OnAbout(wxCommandEvent& event);
b910a8ad 478
abd6692c
RR
479 void OnAppendRowLeft(wxCommandEvent& event);
480 void OnPrependRowLeft(wxCommandEvent& event);
481 void OnInsertRowLeft(wxCommandEvent& event);
482 void OnDeleteRowLeft(wxCommandEvent& event);
483 void OnEditRowLeft(wxCommandEvent& event);
b910a8ad 484
abd6692c
RR
485 void OnAppendRowRight(wxCommandEvent& event);
486 void OnPrependRowRight(wxCommandEvent& event);
487 void OnInsertRowRight(wxCommandEvent& event);
488 void OnDeleteRowRight(wxCommandEvent& event);
489 void OnEditRowRight(wxCommandEvent& event);
b910a8ad 490
fc211fe5
RR
491 void OnSelect(wxCommandEvent& event);
492 void OnUnselectAll(wxCommandEvent& event);
493
eb7f97f8
RR
494 void OnSelectedUnsorted(wxDataViewEvent &event);
495 void OnSelectedSorted(wxDataViewEvent &event);
f828871d 496 void OnActivatedUnsorted(wxDataViewEvent &event);
eb7f97f8 497
31fb32e1
RR
498 void OnHeaderClickSorted(wxDataViewEvent &event);
499 void OnHeaderClickUnsorted(wxDataViewEvent &event);
500
241cb04b
RR
501private:
502 wxDataViewCtrl* dataview_left;
503 wxDataViewCtrl* dataview_right;
eb7f97f8
RR
504
505 wxLog *m_logOld;
506 wxTextCtrl *m_logWindow;
b910a8ad 507
9861f022
RR
508 wxObjectDataPtr<MyUnsortedTextModel> m_unsorted_model;
509 wxObjectDataPtr<wxDataViewSortedListModel> m_sorted_model;
4627af27 510
abd6692c 511 DECLARE_EVENT_TABLE()
241cb04b
RR
512};
513
362d7fb9
RR
514// -------------------------------------
515// MyApp
516// -------------------------------------
517
87f0efe2 518IMPLEMENT_APP(MyApp)
bd6169a6 519
bd6169a6
RR
520bool MyApp::OnInit(void)
521{
45e6e6f8
VZ
522 if ( !wxApp::OnInit() )
523 return false;
524
87f0efe2
RR
525 // build the first frame
526 MyFrame *frame =
527 new MyFrame(NULL, wxT("wxDataViewCtrl feature test"), 10, 10, 800, 340);
bd6169a6
RR
528 frame->Show(true);
529
530 SetTopWindow(frame);
bd6169a6
RR
531 return true;
532}
533
87f0efe2
RR
534int MyApp::OnExit()
535{
536 return 0;
537}
538
539
bd6169a6
RR
540// -------------------------------------
541// MyFrame
542// -------------------------------------
543
87f0efe2
RR
544enum
545{
546 // file menu
547 ID_ABOUT = wxID_ABOUT,
9861f022 548 ID_NEW_SORT_FRAME = wxID_HIGHEST+1,
87f0efe2
RR
549 ID_EXIT = wxID_EXIT,
550
551 // dataviewctrl menu
9861f022 552 ID_SINGLE_SEL_MODE = wxID_HIGHEST+2,
87f0efe2 553 ID_MULTIPLE_SEL_MODE,
9861f022
RR
554 ID_NO_HEADER_MODE,
555 ID_HORIZ_RULES_MODE,
556 ID_VERT_RULES_MODE,
87f0efe2
RR
557
558 ID_RESIZEABLE_COLUMNS,
559 ID_SORTABLE_COLUMNS,
560 ID_HIDDEN_COLUMNS,
561
9861f022
RR
562 ID_CHOOSE_COLUMN_ALIGNMENT,
563 ID_CHOOSE_CONTENTS_ALIGNMENT,
564
565 ID_SET_MINWIDTH,
566 ID_SET_WIDTH
87f0efe2
RR
567};
568
569BEGIN_EVENT_TABLE(MyFrame, wxFrame)
570
571 // file menu
572 EVT_MENU( ID_ABOUT, MyFrame::OnAbout )
573 EVT_MENU( ID_NEW_SORT_FRAME, MyFrame::OnNewSortingFrame )
574 EVT_MENU( ID_EXIT, MyFrame::OnQuit )
575
576 // dataviewctrl menu
9861f022
RR
577 EVT_COMMAND_RANGE( ID_SINGLE_SEL_MODE, ID_VERT_RULES_MODE,
578 wxEVT_COMMAND_MENU_SELECTED, MyFrame::OnStyleChange )
87f0efe2 579
9861f022
RR
580 EVT_COMMAND_RANGE( ID_RESIZEABLE_COLUMNS, ID_SET_WIDTH,
581 wxEVT_COMMAND_MENU_SELECTED, MyFrame::OnColumnSetting )
87f0efe2
RR
582
583END_EVENT_TABLE()
584
bd6169a6
RR
585MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
586 wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
587{
0bcd4039 588 SetIcon(wxICON(sample));
bd6169a6 589
87f0efe2
RR
590 // build the menus:
591
bd6169a6 592 wxMenu *file_menu = new wxMenu;
87f0efe2
RR
593 file_menu->Append(ID_NEW_SORT_FRAME, _T("&New sorting frame"));
594 file_menu->AppendSeparator();
595 file_menu->Append(ID_ABOUT, _T("&About"));
596 file_menu->AppendSeparator();
597 file_menu->Append(ID_EXIT, _T("E&xit"));
598
599 wxMenu *data_menu = new wxMenu;
600 data_menu->AppendRadioItem(ID_SINGLE_SEL_MODE, _T("&Single selection mode"));
601 data_menu->AppendRadioItem(ID_MULTIPLE_SEL_MODE, _T("&Multiple selection mode"));
602 data_menu->AppendSeparator();
9861f022
RR
603 data_menu->AppendCheckItem(ID_NO_HEADER_MODE, _T("No header mode"));
604 data_menu->AppendCheckItem(ID_HORIZ_RULES_MODE, _T("Horizontal rules"));
605 data_menu->AppendCheckItem(ID_VERT_RULES_MODE, _T("Vertical rules"));
87f0efe2 606 data_menu->AppendSeparator();
9861f022
RR
607 data_menu->Append(ID_RESIZEABLE_COLUMNS, _T("Set column(s) as resizeable..."));
608 data_menu->Append(ID_SORTABLE_COLUMNS, _T("Set column(s) as sortable..."));
609 data_menu->Append(ID_HIDDEN_COLUMNS, _T("Set column(s) as hidden..."));
610 data_menu->AppendSeparator();
611 data_menu->Append(ID_CHOOSE_COLUMN_ALIGNMENT, _T("Set column(s) title alignment..."));
612 data_menu->Append(ID_CHOOSE_CONTENTS_ALIGNMENT, _T("Set column(s) contents alignment..."));
613 data_menu->AppendSeparator();
614 data_menu->Append(ID_SET_MINWIDTH, _T("Set column(s) minimal width..."));
615 data_menu->Append(ID_SET_WIDTH, _T("Set column(s) width..."));
bd6169a6 616
bd6169a6
RR
617 wxMenuBar *menu_bar = new wxMenuBar;
618 menu_bar->Append(file_menu, _T("&File"));
87f0efe2
RR
619 menu_bar->Append(data_menu, _T("&DataViewCtrl"));
620
bd6169a6 621 SetMenuBar(menu_bar);
87f0efe2 622 CreateStatusBar();
bd6169a6 623
bd6169a6 624
9861f022
RR
625 // check the menus for the default wxDataViewCtrl style
626 data_menu->Check(ID_MULTIPLE_SEL_MODE, (DATAVIEW_DEFAULT_STYLE & wxDV_MULTIPLE) != 0);
627 data_menu->Check(ID_NO_HEADER_MODE, (DATAVIEW_DEFAULT_STYLE & wxDV_NO_HEADER) != 0);
628 data_menu->Check(ID_HORIZ_RULES_MODE, (DATAVIEW_DEFAULT_STYLE & wxDV_HORIZ_RULES) != 0);
629 data_menu->Check(ID_VERT_RULES_MODE, (DATAVIEW_DEFAULT_STYLE & wxDV_VERT_RULES) != 0);
630
631
87f0efe2 632 // build the other controls:
b910a8ad 633
87f0efe2
RR
634 m_splitter = new wxSplitterWindow( this, wxID_ANY );
635 m_splitter->SetSashGravity(0.5);
636
9861f022
RR
637 m_panelLeft = new wxPanel( m_splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize,
638 wxNO_BORDER );
639 m_panelRight = new wxPanel( m_splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize,
640 wxNO_BORDER );
641 wxSizer *szLeft = new wxBoxSizer(wxVERTICAL);
642 wxSizer *szRight = new wxBoxSizer(wxVERTICAL);
643
644 dataview_left = NULL;
645 dataview_right = NULL;
646 CreateDataViewControls();
647
648 // left panel
649 szLeft->Add( dataview_left, 1, wxGROW|wxALL, 5 );
650 m_panelLeft->SetSizerAndFit(szLeft);
651
652 // right panel
653 wxStaticText *stattext =
654 new wxStaticText(m_panelRight, wxID_ANY,
655 wxT("This is another wxDataViewCtrl using the same wxDataViewModel ")
656 wxT("of the wxDataViewCtrl on the left but, unlike it, this window ")
657 wxT("won't react to the style/column changes done through the ")
658 wxT("'DataViewCtrl' menu"));
659 stattext->Wrap(GetClientSize().GetWidth() / 2);
660
661 szRight->Add( stattext, 0, wxALL, 5 );
662 szRight->Add( dataview_right, 1, wxGROW|wxALL, 5 );
663 m_panelRight->SetSizerAndFit(szRight);
664
665 // split the two panels
666 m_splitter->SplitVertically(m_panelLeft, m_panelRight);
667 this->SetMinSize(m_splitter->GetBestSize());
87f0efe2
RR
668}
669
9861f022 670void MyFrame::CreateDataViewControls()
87f0efe2
RR
671{
672 wxDataViewCtrl *old1 = NULL, *old2 = NULL;
673
674 if (dataview_left)
675 old1 = dataview_left;
676 if (dataview_right)
677 old2 = dataview_right;
678
679 // styles:
87f0efe2
RR
680 long style = 0;
681 if (GetMenuBar()->FindItem(ID_MULTIPLE_SEL_MODE)->IsChecked())
682 style |= wxDV_MULTIPLE;
9861f022
RR
683 if (GetMenuBar()->FindItem(ID_NO_HEADER_MODE)->IsChecked())
684 style |= wxDV_NO_HEADER;
685 if (GetMenuBar()->FindItem(ID_HORIZ_RULES_MODE)->IsChecked())
686 style |= wxDV_HORIZ_RULES;
687 if (GetMenuBar()->FindItem(ID_VERT_RULES_MODE)->IsChecked())
688 style |= wxDV_VERT_RULES;
b6339e0b 689
b910a8ad 690
a7f61f76 691 // Left wxDataViewCtrl
9861f022 692 dataview_left = new wxDataViewCtrl( m_panelLeft, wxID_ANY, wxDefaultPosition,
87f0efe2 693 wxDefaultSize, style );
b910a8ad 694
b910a8ad 695
9861f022
RR
696 wxObjectDataPtr<MyTextModel> model(new MyTextModel);
697 dataview_left->AssociateModel( model.get() );
698
699 dataview_left->AppendTextColumn( wxT("First"), 0, wxDATAVIEW_CELL_INERT, -1,
700 DEFAULT_ALIGN );
701 dataview_left->AppendTextColumn( wxT("Second"), 1, wxDATAVIEW_CELL_INERT, -1,
702 DEFAULT_ALIGN );
553f7d8f 703
87f0efe2
RR
704 wxDataViewTextRenderer *text_renderer =
705 new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
706 wxDataViewColumn *column = new wxDataViewColumn( wxT("editable"), text_renderer, 2,
9861f022 707 -1, DEFAULT_ALIGN );
a7f61f76 708 dataview_left->AppendColumn( column );
b910a8ad 709
9861f022
RR
710 dataview_left->AppendToggleColumn( wxT("fourth"), 3, wxDATAVIEW_CELL_INERT, -1,
711 DEFAULT_ALIGN );
b910a8ad 712
baa9ebc4 713 MyCustomRenderer *custom_renderer = new MyCustomRenderer;
9861f022 714 column = new wxDataViewColumn( wxT("custom"), custom_renderer, 4, -1, DEFAULT_ALIGN );
e152afc3 715 dataview_left->AppendColumn( column );
b910a8ad 716
9861f022
RR
717 dataview_left->AppendProgressColumn( wxT("progress"), 5, wxDATAVIEW_CELL_INERT, -1,
718 DEFAULT_ALIGN );
87f0efe2 719
9861f022 720 dataview_left->AppendDateColumn( wxT("date"), 6, wxDATAVIEW_CELL_INERT, -1, DEFAULT_ALIGN );
b910a8ad 721
b910a8ad 722
a7f61f76 723 // Right wxDataViewCtrl using the same model
9861f022
RR
724 dataview_right = new wxDataViewCtrl( m_panelRight, wxID_ANY );
725 dataview_right->AssociateModel( model.get() );
553f7d8f 726
baa9ebc4
RR
727 text_renderer = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
728 column = new wxDataViewColumn( wxT("editable"), text_renderer, 2 );
605c2c4a
RR
729 dataview_right->AppendColumn( column );
730 dataview_right->AppendTextColumn( wxT("first"), 0 );
731 dataview_right->AppendTextColumn( wxT("second"), 1 );
87f0efe2
RR
732 wxDataViewToggleRenderer *toggle_renderer =
733 new wxDataViewToggleRenderer( wxT("bool"), wxDATAVIEW_CELL_ACTIVATABLE );
baa9ebc4 734 column = new wxDataViewColumn( wxT("bool"), toggle_renderer, 3, 30 );
a7f61f76 735 dataview_right->AppendColumn( column );
553f7d8f 736
7ea3a0de 737 dataview_right->AppendDateColumn( wxT("date"), 6 );
b910a8ad 738
9861f022
RR
739
740 // layout the new dataview controls
87f0efe2
RR
741 if (old1)
742 {
9861f022 743 m_panelLeft->GetSizer()->Replace(old1, dataview_left);
87f0efe2 744 delete old1;
9861f022
RR
745
746 m_panelLeft->Layout();
87f0efe2 747 }
b910a8ad 748
87f0efe2
RR
749 if (old2)
750 {
9861f022 751 m_panelRight->GetSizer()->Replace(old2, dataview_right);
87f0efe2 752 delete old2;
9861f022
RR
753
754 m_panelRight->Layout();
87f0efe2 755 }
bd6169a6
RR
756}
757
758void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
759{
760 Close(true);
761}
762
763void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
764{
87f0efe2
RR
765 wxAboutDialogInfo info;
766 info.SetName(_("DataView sample"));
767 info.SetDescription(_("This sample demonstrates the dataview control handling"));
768 info.SetCopyright(_T("(C) 2007 Robert Roebling"));
bd6169a6 769
87f0efe2 770 wxAboutBox(info);
bd6169a6
RR
771}
772
87f0efe2
RR
773void MyFrame::OnNewSortingFrame(wxCommandEvent& WXUNUSED(event) )
774{
775 MySortingFrame *frame2 =
776 new MySortingFrame(NULL, wxT("wxDataViewCtrl sorting test"), 10, 150, 600, 500);
777 frame2->Show(true);
778}
779
9861f022 780void MyFrame::OnStyleChange(wxCommandEvent& WXUNUSED(event) )
87f0efe2 781{
9861f022
RR
782 // recreate the wxDataViewCtrl:
783 CreateDataViewControls();
87f0efe2
RR
784}
785
9861f022 786void MyFrame::OnColumnSetting(wxCommandEvent& event)
87f0efe2 787{
9861f022
RR
788 wxArrayInt columns;
789 int flag = 0;
790 bool header = false, minwidth = false;
791 wxString msg;
87f0efe2 792
9861f022
RR
793 switch (event.GetId())
794 {
795 case ID_RESIZEABLE_COLUMNS:
796 flag = wxDATAVIEW_COL_RESIZABLE;
797 columns = GetFlaggedColumns(flag);
798 break;
799 case ID_SORTABLE_COLUMNS:
800 flag = wxDATAVIEW_COL_SORTABLE;
801 columns = GetFlaggedColumns(flag);
802 break;
803 case ID_HIDDEN_COLUMNS:
804 flag = wxDATAVIEW_COL_HIDDEN;
805 columns = GetFlaggedColumns(flag);
806 break;
807
808 case ID_CHOOSE_COLUMN_ALIGNMENT:
809 msg = wxT("Select the columns whose headers' alignment will be modified.");
810 header = true;
811 break;
812 case ID_CHOOSE_CONTENTS_ALIGNMENT:
813 msg = wxT("Select the columns whose contents' alignment will be modified.");
814 header = false;
815 break;
816
817 case ID_SET_MINWIDTH:
818 msg = wxT("Please provide the new minimal width:");
819 minwidth = true;
820 break;
821 case ID_SET_WIDTH:
822 msg = wxT("Please provide the new width:");
823 minwidth = false;
824 break;
825 }
87f0efe2 826
9861f022 827 // get column titles:
87f0efe2 828
9861f022
RR
829 wxArrayString choices;
830 for (size_t i=0; i<dataview_left->GetColumnCount(); i++)
831 choices.Add(dataview_left->GetColumn(i)->GetTitle());
832
833 // ask the user
834 wxGetMultipleChoices(
835 columns,
836 wxT("Choose the columns to which apply the change."),
837 wxT("Choose the column"),
838 choices,
839 this);
840
841 switch (event.GetId())
842 {
843 case ID_RESIZEABLE_COLUMNS:
844 case ID_SORTABLE_COLUMNS:
845 case ID_HIDDEN_COLUMNS:
846 SetFlag(columns, flag);
847 break;
848
849 case ID_CHOOSE_COLUMN_ALIGNMENT:
850 case ID_CHOOSE_CONTENTS_ALIGNMENT:
851 SetAlignment(columns, header, ChooseAlign(msg, header));
852 break;
853
854 case ID_SET_MINWIDTH:
855 case ID_SET_WIDTH:
856 {
857 int def = minwidth ? wxDVC_DEFAULT_MINWIDTH : wxDVC_DEFAULT_WIDTH;
858
859 msg << wxT("\nNOTE: all non-selected columns will be reset to a width of ")
860 << def << wxT(" pixels.");
861
862 long ret =
863 wxGetNumberFromUser(msg, wxT("New value:"), wxT("Modify width"),
864 def, 0, 300, this);
865
866 if (ret != -1)
867 SetWidth(columns, minwidth, ret);
868 }
869 break;
870 }
871
872 dataview_left->Refresh();
87f0efe2
RR
873}
874
9861f022 875wxAlignment MyFrame::ChooseAlign(const wxString &msg, bool onlyHorizontal)
87f0efe2
RR
876{
877 const wxString choices[] =
878 {
879 wxT("Left"),
880 wxT("Center horizontally"),
881 wxT("Right"),
882 wxT("Top"),
883 wxT("Center vertically"),
884 wxT("Bottom"),
885 wxT("Center")
886 };
887
888 wxAlignment flags[] =
889 {
890 wxALIGN_LEFT,
891 wxALIGN_CENTER_HORIZONTAL,
892 wxALIGN_RIGHT,
893 wxALIGN_TOP,
894 wxALIGN_CENTER_VERTICAL,
895 wxALIGN_BOTTOM,
896 wxALIGN_CENTER
897 };
898
9861f022
RR
899 int n = WXSIZEOF(choices);
900 if (onlyHorizontal)
901 n = 3; // show only the first three choices
902
87f0efe2 903 int choice = wxGetSingleChoiceIndex(
9861f022 904 msg + wxT("\nNOTE: _all_ non-selected column's alignment will be reset to wxALIGN_LEFT!"),
87f0efe2 905 wxT("Alignment"),
9861f022 906 n, choices,
87f0efe2
RR
907 this);
908
909 if (choice == wxNOT_FOUND)
9861f022
RR
910 return wxALIGN_LEFT;
911
912 return flags[choice];
913}
914
915void MyFrame::SetFlag(const wxArrayInt &idx, int toadd)
916{
917 for (size_t i=0; i<dataview_left->GetColumnCount(); i++)
918 {
919 int current = dataview_left->GetColumn(i)->GetFlags();
920
921 if (idx.Index(i) != wxNOT_FOUND)
922 dataview_left->GetColumn(i)->SetFlags(current | toadd);
923 else
924 dataview_left->GetColumn(i)->SetFlags(current & ~toadd);
925 }
926}
927
928wxArrayInt MyFrame::GetFlaggedColumns(int flag)
929{
930 wxArrayInt ret;
931 for (size_t i=0; i<dataview_left->GetColumnCount(); i++)
932 if (dataview_left->GetColumn(i)->GetFlags() & flag)
933 ret.Add(i);
934 return ret;
935}
87f0efe2 936
9861f022
RR
937void MyFrame::SetAlignment(const wxArrayInt &idx, bool header, wxAlignment align)
938{
939 // set to DEFAULT_ALIGN all columns except those
940 // contained in 'idx' which are set to 'align'
941
942 for (size_t i=0; i<dataview_left->GetColumnCount(); i++)
943 {
944 wxAlignment toset = DEFAULT_ALIGN;
945 if (idx.Index(i) != wxNOT_FOUND)
946 toset = align;
947
948 if (header)
949 dataview_left->GetColumn(i)->SetAlignment(toset);
950 else
951 dataview_left->GetColumn(i)->GetRenderer()->SetAlignment(toset);
952 }
953}
954
955void MyFrame::SetWidth(const wxArrayInt &idx, bool minwidth, int width)
956{
957 // set to wxDVC_DEFAULT_WIDTH wide all columns except those
958 // contained in 'idx' which are set to 'width'
959
960 for (size_t i=0; i<dataview_left->GetColumnCount(); i++)
961 {
962 int toset = minwidth ? wxDVC_DEFAULT_MINWIDTH : wxDVC_DEFAULT_WIDTH;
963 if (idx.Index(i) != wxNOT_FOUND)
964 toset = width;
965
966 if (minwidth)
967 dataview_left->GetColumn(i)->SetMinWidth(toset);
968 else
969 dataview_left->GetColumn(i)->SetWidth(toset);
970 }
87f0efe2
RR
971}
972
973
241cb04b
RR
974// -------------------------------------
975// MySortingFrame
976// -------------------------------------
977
abd6692c
RR
978BEGIN_EVENT_TABLE(MySortingFrame,wxFrame)
979 EVT_BUTTON( ID_APPEND_ROW_LEFT, MySortingFrame::OnAppendRowLeft )
4627af27
RR
980 EVT_BUTTON( ID_PREPEND_ROW_LEFT, MySortingFrame::OnPrependRowLeft )
981 EVT_BUTTON( ID_INSERT_ROW_LEFT, MySortingFrame::OnInsertRowLeft )
982 EVT_BUTTON( ID_DELETE_ROW_LEFT, MySortingFrame::OnDeleteRowLeft )
fc211fe5
RR
983 EVT_BUTTON( ID_SELECT, MySortingFrame::OnSelect )
984 EVT_BUTTON( ID_UNSELECT_ALL, MySortingFrame::OnUnselectAll )
eb7f97f8
RR
985 EVT_DATAVIEW_ROW_SELECTED( ID_SORTED, MySortingFrame::OnSelectedSorted )
986 EVT_DATAVIEW_ROW_SELECTED( ID_UNSORTED, MySortingFrame::OnSelectedUnsorted )
f828871d 987 EVT_DATAVIEW_ROW_ACTIVATED( ID_UNSORTED, MySortingFrame::OnActivatedUnsorted )
31fb32e1
RR
988 EVT_DATAVIEW_COLUMN_HEADER_CLICK( ID_SORTED, MySortingFrame::OnHeaderClickSorted )
989 EVT_DATAVIEW_COLUMN_HEADER_CLICK( ID_UNSORTED, MySortingFrame::OnHeaderClickUnsorted )
abd6692c
RR
990END_EVENT_TABLE()
991
241cb04b
RR
992MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
993 wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
994{
eb7f97f8
RR
995 m_logOld = NULL;
996
0bcd4039 997 SetIcon(wxICON(sample));
241cb04b 998 CreateStatusBar();
b910a8ad 999
87f0efe2 1000 wxPanel *main = new wxPanel(this);
b910a8ad 1001
241cb04b 1002 // Left wxDataViewCtrl
87f0efe2
RR
1003 dataview_left = new wxDataViewCtrl( main, ID_UNSORTED, wxDefaultPosition,
1004 wxDefaultSize, wxDV_MULTIPLE );
241cb04b 1005
9861f022
RR
1006 m_unsorted_model.reset(new MyUnsortedTextModel);
1007 dataview_left->AssociateModel( m_unsorted_model.get() );
87f0efe2
RR
1008
1009 wxDataViewTextRenderer *text_renderer =
47c94466 1010 new MyTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
baa9ebc4 1011 wxDataViewColumn *column = new wxDataViewColumn( wxT("editable"), text_renderer, 0 );
241cb04b
RR
1012 dataview_left->AppendColumn( column );
1013 dataview_left->AppendTextColumn( wxT("second"), 1 );
87f0efe2
RR
1014 dataview_left->AppendColumn( new wxDataViewColumn( wxBitmap(null_xpm),
1015 new wxDataViewBitmapRenderer, 2, 25 ) );
1016 dataview_left->AppendColumn( new wxDataViewColumn( wxT("icon"),
1017 new wxDataViewBitmapRenderer, 3, 25 ) );
b910a8ad 1018
241cb04b 1019 // Right wxDataViewCtrl using the sorting model
87f0efe2 1020 dataview_right = new wxDataViewCtrl( main, ID_SORTED );
979f71a3 1021
9861f022
RR
1022 m_sorted_model.reset(new wxDataViewSortedListModel( m_unsorted_model.get() ));
1023 dataview_right->AssociateModel( m_sorted_model.get() );
87f0efe2 1024
baa9ebc4 1025 text_renderer = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
87f0efe2
RR
1026 column = new wxDataViewColumn( wxT("editable"), text_renderer, 0, -1,
1027 wxALIGN_CENTER,
1028 wxDATAVIEW_COL_SORTABLE|wxDATAVIEW_COL_RESIZABLE );
241cb04b 1029 dataview_right->AppendColumn( column );
979f71a3 1030
241cb04b 1031 dataview_right->AppendTextColumn( wxT("second"), 1 );
1e510b1e
RR
1032
1033 MySpinCtrlInPlaceRenderer *sr = new MySpinCtrlInPlaceRenderer;
1034 column = new wxDataViewColumn( wxT("spin"), sr, 4, -1, wxALIGN_CENTER );
1035 dataview_right->AppendColumn( column );
241cb04b
RR
1036
1037 // layout dataview controls.
b910a8ad 1038
abd6692c
RR
1039 wxBoxSizer *top_sizer = new wxBoxSizer( wxHORIZONTAL );
1040 top_sizer->Add( dataview_left, 1, wxGROW );
1041 top_sizer->Add(10,10);
1042 top_sizer->Add( dataview_right, 1, wxGROW );
b910a8ad 1043
abd6692c
RR
1044 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
1045 button_sizer->Add( 10, 10, 1 );
1046 wxFlexGridSizer *left_sizer = new wxFlexGridSizer( 2 );
87f0efe2
RR
1047 left_sizer->Add( new wxButton( main, ID_APPEND_ROW_LEFT, wxT("Append") ), 0, wxALL, 5 );
1048 left_sizer->Add( new wxButton( main, ID_PREPEND_ROW_LEFT, wxT("Prepend") ), 0, wxALL, 5 );
1049 left_sizer->Add( new wxButton( main, ID_INSERT_ROW_LEFT, wxT("Insert") ), 0, wxALL, 5 );
1050 left_sizer->Add( new wxButton( main, ID_DELETE_ROW_LEFT, wxT("Delete second") ), 0, wxALL, 5 );
1051 left_sizer->Add( new wxButton( main, ID_EDIT_ROW_LEFT, wxT("Edit") ), 0, wxALL, 5 );
fc211fe5 1052 left_sizer->Add( 5,5 );
87f0efe2
RR
1053 left_sizer->Add( new wxButton( main, ID_SELECT, wxT("Select third") ), 0, wxALL, 5 );
1054 left_sizer->Add( new wxButton( main, ID_UNSELECT_ALL, wxT("Unselect all") ), 0, wxALL, 5 );
abd6692c
RR
1055 button_sizer->Add( left_sizer );
1056 button_sizer->Add( 10, 10, 2 );
1057 wxFlexGridSizer *right_sizer = new wxFlexGridSizer( 2 );
87f0efe2
RR
1058 right_sizer->Add( new wxButton( main, ID_APPEND_ROW_RIGHT, wxT("Append") ), 0, wxALL, 5 );
1059 right_sizer->Add( new wxButton( main, ID_PREPEND_ROW_RIGHT, wxT("Prepend") ), 0, wxALL, 5 );
1060 right_sizer->Add( new wxButton( main, ID_INSERT_ROW_RIGHT, wxT("Insert") ), 0, wxALL, 5 );
1061 right_sizer->Add( new wxButton( main, ID_DELETE_ROW_RIGHT, wxT("Delete second") ), 0, wxALL, 5 );
1062 right_sizer->Add( new wxButton( main, ID_EDIT_ROW_RIGHT, wxT("Edit") ), 0, wxALL, 5 );
abd6692c
RR
1063 button_sizer->Add( right_sizer );
1064 button_sizer->Add( 10, 10, 1 );
b910a8ad 1065
abd6692c
RR
1066 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
1067 main_sizer->Add( top_sizer, 1, wxGROW );
1068 main_sizer->Add( button_sizer, 0, wxGROW );
eb7f97f8 1069
87f0efe2 1070 m_logWindow = new wxTextCtrl(main, wxID_ANY, wxEmptyString,
eb7f97f8
RR
1071 wxDefaultPosition, wxDefaultSize,
1072 wxTE_MULTILINE | wxSUNKEN_BORDER);
1073 main_sizer->Add( 20,20 );
1074 main_sizer->Add( m_logWindow, 1, wxGROW );
1075
1076 m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_logWindow));
b910a8ad 1077
87f0efe2 1078 main->SetSizer( main_sizer );
241cb04b
RR
1079}
1080
eb7f97f8
RR
1081MySortingFrame::~MySortingFrame()
1082{
1083 delete wxLog::SetActiveTarget(m_logOld);
1084}
1085
1086void MySortingFrame::OnSelectedUnsorted(wxDataViewEvent &event)
1087{
fc211fe5
RR
1088 int row = event.GetRow();
1089 wxLogMessage( wxT("OnSelected from unsorted list, selected %d"), row );
1090 if (row >= 0)
1091 wxLogMessage( wxT("wxDataViewCtrl::IsSelected( %d ): %d (as int)"),
1092 row, (int) dataview_right->IsSelected( row ) );
eb7f97f8
RR
1093}
1094
1095void MySortingFrame::OnSelectedSorted(wxDataViewEvent &event)
1096{
1097 wxLogMessage( wxT("OnSelected from sorted list, selected %d"), (int) event.GetRow() );
1098}
1099
f828871d
RR
1100void MySortingFrame::OnActivatedUnsorted(wxDataViewEvent &event)
1101{
1102 wxLogMessage( wxT("OnActivated from unsorted list, activated %d"), (int) event.GetRow() );
1103}
1104
31fb32e1
RR
1105void MySortingFrame::OnHeaderClickSorted(wxDataViewEvent &event)
1106{
1107 wxDataViewColumn *col = event.GetDataViewColumn();
1108 wxLogMessage( wxT("OnHeaderClick from sorted list, column %s"), col->GetTitle().c_str() );
1109
1110 if (col->GetTitle() == wxT("editable"))
1111 {
1112 // this is the sorting column
1113 if (col->IsSortOrderAscending())
1114 {
1115 col->SetSortOrder( false );
1116 m_sorted_model->SetAscending( false );
1117 m_sorted_model->Resort();
1118 }
1119 else
1120 {
1121 col->SetSortOrder( true );
1122 m_sorted_model->SetAscending( true );
1123 m_sorted_model->Resort();
1124 }
1125 }
1126}
1127
1128void MySortingFrame::OnHeaderClickUnsorted(wxDataViewEvent &event)
1129{
87f0efe2
RR
1130 wxLogMessage( wxT("OnHeaderClick from unsorted list, column %s"),
1131 event.GetDataViewColumn()->GetTitle().c_str() );
31fb32e1
RR
1132}
1133
241cb04b
RR
1134void MySortingFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
1135{
1136 Close(true);
1137}
1138
1139void MySortingFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
1140{
1141 wxMessageDialog dialog(this, _T("This demonstrates the dataview control sorting"),
1142 _T("About DataView"), wxOK);
1143
1144 dialog.ShowModal();
1145}
bd6169a6 1146
fc211fe5
RR
1147void MySortingFrame::OnSelect(wxCommandEvent& WXUNUSED(event))
1148{
1149 dataview_left->SetSelection( 2 );
1150}
1151
1152void MySortingFrame::OnUnselectAll(wxCommandEvent& WXUNUSED(event))
1153{
1154 dataview_left->ClearSelection();
1155}
1156
f554a14b 1157void MySortingFrame::OnAppendRowLeft(wxCommandEvent& WXUNUSED(event))
abd6692c 1158{
4627af27
RR
1159 wxTextEntryDialog dialog( this, wxT("Enter text to append") );
1160 if (dialog.ShowModal() == wxID_OK)
1161 {
1162 wxString value = dialog.GetValue();
1163 if (!value.empty())
1164 m_unsorted_model->AppendRow( value );
1165 }
abd6692c
RR
1166}
1167
f554a14b 1168void MySortingFrame::OnPrependRowLeft(wxCommandEvent& WXUNUSED(event))
abd6692c 1169{
4627af27
RR
1170 wxTextEntryDialog dialog( this, wxT("Enter text to prepend") );
1171 if (dialog.ShowModal() == wxID_OK)
1172 {
1173 wxString value = dialog.GetValue();
1174 if (!value.empty())
1175 m_unsorted_model->PrependRow( value );
1176 }
abd6692c
RR
1177}
1178
f554a14b 1179void MySortingFrame::OnInsertRowLeft(wxCommandEvent& WXUNUSED(event))
abd6692c 1180{
cbc9145c 1181 wxTextEntryDialog dialog( this, wxT("Enter text to insert before second") );
4627af27
RR
1182 if (dialog.ShowModal() == wxID_OK)
1183 {
1184 wxString value = dialog.GetValue();
1185 if (!value.empty())
1186 m_unsorted_model->InsertRowAt1( value );
1187 }
abd6692c
RR
1188}
1189
f554a14b 1190void MySortingFrame::OnDeleteRowLeft(wxCommandEvent& WXUNUSED(event))
abd6692c 1191{
4627af27 1192 m_unsorted_model->DeleteRow( 1 );
abd6692c
RR
1193}
1194
f554a14b 1195void MySortingFrame::OnEditRowLeft(wxCommandEvent& WXUNUSED(event))
abd6692c
RR
1196{
1197}
1198
f554a14b 1199void MySortingFrame::OnAppendRowRight(wxCommandEvent& WXUNUSED(event))
abd6692c
RR
1200{
1201}
1202
f554a14b 1203void MySortingFrame::OnPrependRowRight(wxCommandEvent& WXUNUSED(event))
abd6692c
RR
1204{
1205}
1206
f554a14b 1207void MySortingFrame::OnInsertRowRight(wxCommandEvent& WXUNUSED(event))
abd6692c
RR
1208{
1209}
1210
f554a14b 1211void MySortingFrame::OnDeleteRowRight(wxCommandEvent& WXUNUSED(event))
abd6692c
RR
1212{
1213}
1214
f554a14b 1215void MySortingFrame::OnEditRowRight(wxCommandEvent& WXUNUSED(event))
abd6692c
RR
1216{
1217}
1218