]> git.saurik.com Git - wxWidgets.git/blame - samples/dataview/dataview.cpp
move m_sizeSet out of wxWindow
[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 }
2fa73716 121 virtual bool SetValue( const 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
2fa73716 346 virtual bool SetValue( const 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;
2fa73716 685#if 0
9861f022
RR
686 if (GetMenuBar()->FindItem(ID_HORIZ_RULES_MODE)->IsChecked())
687 style |= wxDV_HORIZ_RULES;
688 if (GetMenuBar()->FindItem(ID_VERT_RULES_MODE)->IsChecked())
689 style |= wxDV_VERT_RULES;
2fa73716 690#endif
b6339e0b 691
b910a8ad 692
a7f61f76 693 // Left wxDataViewCtrl
9861f022 694 dataview_left = new wxDataViewCtrl( m_panelLeft, wxID_ANY, wxDefaultPosition,
87f0efe2 695 wxDefaultSize, style );
b910a8ad 696
b910a8ad 697
2fa73716
RR
698 wxDataViewTextRenderer *text_renderer;
699 wxDataViewColumn *column;
700
9861f022
RR
701 wxObjectDataPtr<MyTextModel> model(new MyTextModel);
702 dataview_left->AssociateModel( model.get() );
703
704 dataview_left->AppendTextColumn( wxT("First"), 0, wxDATAVIEW_CELL_INERT, -1,
705 DEFAULT_ALIGN );
706 dataview_left->AppendTextColumn( wxT("Second"), 1, wxDATAVIEW_CELL_INERT, -1,
707 DEFAULT_ALIGN );
553f7d8f 708
2fa73716
RR
709 text_renderer = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
710 column = new wxDataViewColumn( wxT("editable"), text_renderer, 2, -1, DEFAULT_ALIGN );
a7f61f76 711 dataview_left->AppendColumn( column );
b910a8ad 712
9861f022
RR
713 dataview_left->AppendToggleColumn( wxT("fourth"), 3, wxDATAVIEW_CELL_INERT, -1,
714 DEFAULT_ALIGN );
b910a8ad 715
baa9ebc4 716 MyCustomRenderer *custom_renderer = new MyCustomRenderer;
9861f022 717 column = new wxDataViewColumn( wxT("custom"), custom_renderer, 4, -1, DEFAULT_ALIGN );
e152afc3 718 dataview_left->AppendColumn( column );
b910a8ad 719
9861f022
RR
720 dataview_left->AppendProgressColumn( wxT("progress"), 5, wxDATAVIEW_CELL_INERT, -1,
721 DEFAULT_ALIGN );
87f0efe2 722
9861f022 723 dataview_left->AppendDateColumn( wxT("date"), 6, wxDATAVIEW_CELL_INERT, -1, DEFAULT_ALIGN );
b910a8ad 724
a7f61f76 725 // Right wxDataViewCtrl using the same model
9861f022
RR
726 dataview_right = new wxDataViewCtrl( m_panelRight, wxID_ANY );
727 dataview_right->AssociateModel( model.get() );
553f7d8f 728
baa9ebc4
RR
729 text_renderer = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
730 column = new wxDataViewColumn( wxT("editable"), text_renderer, 2 );
605c2c4a
RR
731 dataview_right->AppendColumn( column );
732 dataview_right->AppendTextColumn( wxT("first"), 0 );
733 dataview_right->AppendTextColumn( wxT("second"), 1 );
87f0efe2
RR
734 wxDataViewToggleRenderer *toggle_renderer =
735 new wxDataViewToggleRenderer( wxT("bool"), wxDATAVIEW_CELL_ACTIVATABLE );
baa9ebc4 736 column = new wxDataViewColumn( wxT("bool"), toggle_renderer, 3, 30 );
a7f61f76 737 dataview_right->AppendColumn( column );
553f7d8f 738
7ea3a0de 739 dataview_right->AppendDateColumn( wxT("date"), 6 );
b910a8ad 740
9861f022
RR
741
742 // layout the new dataview controls
87f0efe2
RR
743 if (old1)
744 {
9861f022 745 m_panelLeft->GetSizer()->Replace(old1, dataview_left);
87f0efe2 746 delete old1;
9861f022
RR
747
748 m_panelLeft->Layout();
87f0efe2 749 }
b910a8ad 750
87f0efe2
RR
751 if (old2)
752 {
9861f022 753 m_panelRight->GetSizer()->Replace(old2, dataview_right);
87f0efe2 754 delete old2;
9861f022
RR
755
756 m_panelRight->Layout();
87f0efe2 757 }
bd6169a6
RR
758}
759
760void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
761{
762 Close(true);
763}
764
765void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
766{
87f0efe2
RR
767 wxAboutDialogInfo info;
768 info.SetName(_("DataView sample"));
769 info.SetDescription(_("This sample demonstrates the dataview control handling"));
770 info.SetCopyright(_T("(C) 2007 Robert Roebling"));
bd6169a6 771
87f0efe2 772 wxAboutBox(info);
bd6169a6
RR
773}
774
87f0efe2
RR
775void MyFrame::OnNewSortingFrame(wxCommandEvent& WXUNUSED(event) )
776{
777 MySortingFrame *frame2 =
778 new MySortingFrame(NULL, wxT("wxDataViewCtrl sorting test"), 10, 150, 600, 500);
779 frame2->Show(true);
780}
781
9861f022 782void MyFrame::OnStyleChange(wxCommandEvent& WXUNUSED(event) )
87f0efe2 783{
9861f022
RR
784 // recreate the wxDataViewCtrl:
785 CreateDataViewControls();
87f0efe2
RR
786}
787
9861f022 788void MyFrame::OnColumnSetting(wxCommandEvent& event)
87f0efe2 789{
9861f022
RR
790 wxArrayInt columns;
791 int flag = 0;
792 bool header = false, minwidth = false;
793 wxString msg;
87f0efe2 794
9861f022
RR
795 switch (event.GetId())
796 {
797 case ID_RESIZEABLE_COLUMNS:
798 flag = wxDATAVIEW_COL_RESIZABLE;
799 columns = GetFlaggedColumns(flag);
800 break;
801 case ID_SORTABLE_COLUMNS:
802 flag = wxDATAVIEW_COL_SORTABLE;
803 columns = GetFlaggedColumns(flag);
804 break;
805 case ID_HIDDEN_COLUMNS:
806 flag = wxDATAVIEW_COL_HIDDEN;
807 columns = GetFlaggedColumns(flag);
808 break;
809
810 case ID_CHOOSE_COLUMN_ALIGNMENT:
811 msg = wxT("Select the columns whose headers' alignment will be modified.");
812 header = true;
813 break;
814 case ID_CHOOSE_CONTENTS_ALIGNMENT:
815 msg = wxT("Select the columns whose contents' alignment will be modified.");
816 header = false;
817 break;
818
819 case ID_SET_MINWIDTH:
820 msg = wxT("Please provide the new minimal width:");
821 minwidth = true;
822 break;
823 case ID_SET_WIDTH:
824 msg = wxT("Please provide the new width:");
825 minwidth = false;
826 break;
827 }
87f0efe2 828
9861f022 829 // get column titles:
87f0efe2 830
9861f022
RR
831 wxArrayString choices;
832 for (size_t i=0; i<dataview_left->GetColumnCount(); i++)
833 choices.Add(dataview_left->GetColumn(i)->GetTitle());
834
835 // ask the user
836 wxGetMultipleChoices(
837 columns,
838 wxT("Choose the columns to which apply the change."),
839 wxT("Choose the column"),
840 choices,
841 this);
842
843 switch (event.GetId())
844 {
845 case ID_RESIZEABLE_COLUMNS:
846 case ID_SORTABLE_COLUMNS:
847 case ID_HIDDEN_COLUMNS:
848 SetFlag(columns, flag);
849 break;
850
851 case ID_CHOOSE_COLUMN_ALIGNMENT:
852 case ID_CHOOSE_CONTENTS_ALIGNMENT:
853 SetAlignment(columns, header, ChooseAlign(msg, header));
854 break;
855
856 case ID_SET_MINWIDTH:
857 case ID_SET_WIDTH:
858 {
859 int def = minwidth ? wxDVC_DEFAULT_MINWIDTH : wxDVC_DEFAULT_WIDTH;
860
861 msg << wxT("\nNOTE: all non-selected columns will be reset to a width of ")
862 << def << wxT(" pixels.");
863
864 long ret =
865 wxGetNumberFromUser(msg, wxT("New value:"), wxT("Modify width"),
866 def, 0, 300, this);
867
868 if (ret != -1)
869 SetWidth(columns, minwidth, ret);
870 }
871 break;
872 }
873
874 dataview_left->Refresh();
87f0efe2
RR
875}
876
9861f022 877wxAlignment MyFrame::ChooseAlign(const wxString &msg, bool onlyHorizontal)
87f0efe2
RR
878{
879 const wxString choices[] =
880 {
881 wxT("Left"),
882 wxT("Center horizontally"),
883 wxT("Right"),
884 wxT("Top"),
885 wxT("Center vertically"),
886 wxT("Bottom"),
887 wxT("Center")
888 };
889
890 wxAlignment flags[] =
891 {
892 wxALIGN_LEFT,
893 wxALIGN_CENTER_HORIZONTAL,
894 wxALIGN_RIGHT,
895 wxALIGN_TOP,
896 wxALIGN_CENTER_VERTICAL,
897 wxALIGN_BOTTOM,
898 wxALIGN_CENTER
899 };
900
9861f022
RR
901 int n = WXSIZEOF(choices);
902 if (onlyHorizontal)
903 n = 3; // show only the first three choices
904
87f0efe2 905 int choice = wxGetSingleChoiceIndex(
9861f022 906 msg + wxT("\nNOTE: _all_ non-selected column's alignment will be reset to wxALIGN_LEFT!"),
87f0efe2 907 wxT("Alignment"),
9861f022 908 n, choices,
87f0efe2
RR
909 this);
910
911 if (choice == wxNOT_FOUND)
9861f022
RR
912 return wxALIGN_LEFT;
913
914 return flags[choice];
915}
916
917void MyFrame::SetFlag(const wxArrayInt &idx, int toadd)
918{
919 for (size_t i=0; i<dataview_left->GetColumnCount(); i++)
920 {
921 int current = dataview_left->GetColumn(i)->GetFlags();
922
923 if (idx.Index(i) != wxNOT_FOUND)
924 dataview_left->GetColumn(i)->SetFlags(current | toadd);
925 else
926 dataview_left->GetColumn(i)->SetFlags(current & ~toadd);
927 }
928}
929
930wxArrayInt MyFrame::GetFlaggedColumns(int flag)
931{
932 wxArrayInt ret;
933 for (size_t i=0; i<dataview_left->GetColumnCount(); i++)
934 if (dataview_left->GetColumn(i)->GetFlags() & flag)
935 ret.Add(i);
936 return ret;
937}
87f0efe2 938
9861f022
RR
939void MyFrame::SetAlignment(const wxArrayInt &idx, bool header, wxAlignment align)
940{
941 // set to DEFAULT_ALIGN all columns except those
942 // contained in 'idx' which are set to 'align'
943
944 for (size_t i=0; i<dataview_left->GetColumnCount(); i++)
945 {
946 wxAlignment toset = DEFAULT_ALIGN;
947 if (idx.Index(i) != wxNOT_FOUND)
948 toset = align;
949
950 if (header)
951 dataview_left->GetColumn(i)->SetAlignment(toset);
952 else
953 dataview_left->GetColumn(i)->GetRenderer()->SetAlignment(toset);
954 }
955}
956
957void MyFrame::SetWidth(const wxArrayInt &idx, bool minwidth, int width)
958{
959 // set to wxDVC_DEFAULT_WIDTH wide all columns except those
960 // contained in 'idx' which are set to 'width'
961
962 for (size_t i=0; i<dataview_left->GetColumnCount(); i++)
963 {
964 int toset = minwidth ? wxDVC_DEFAULT_MINWIDTH : wxDVC_DEFAULT_WIDTH;
965 if (idx.Index(i) != wxNOT_FOUND)
966 toset = width;
967
968 if (minwidth)
969 dataview_left->GetColumn(i)->SetMinWidth(toset);
970 else
971 dataview_left->GetColumn(i)->SetWidth(toset);
972 }
87f0efe2
RR
973}
974
975
241cb04b
RR
976// -------------------------------------
977// MySortingFrame
978// -------------------------------------
979
abd6692c
RR
980BEGIN_EVENT_TABLE(MySortingFrame,wxFrame)
981 EVT_BUTTON( ID_APPEND_ROW_LEFT, MySortingFrame::OnAppendRowLeft )
4627af27
RR
982 EVT_BUTTON( ID_PREPEND_ROW_LEFT, MySortingFrame::OnPrependRowLeft )
983 EVT_BUTTON( ID_INSERT_ROW_LEFT, MySortingFrame::OnInsertRowLeft )
984 EVT_BUTTON( ID_DELETE_ROW_LEFT, MySortingFrame::OnDeleteRowLeft )
fc211fe5
RR
985 EVT_BUTTON( ID_SELECT, MySortingFrame::OnSelect )
986 EVT_BUTTON( ID_UNSELECT_ALL, MySortingFrame::OnUnselectAll )
eb7f97f8
RR
987 EVT_DATAVIEW_ROW_SELECTED( ID_SORTED, MySortingFrame::OnSelectedSorted )
988 EVT_DATAVIEW_ROW_SELECTED( ID_UNSORTED, MySortingFrame::OnSelectedUnsorted )
f828871d 989 EVT_DATAVIEW_ROW_ACTIVATED( ID_UNSORTED, MySortingFrame::OnActivatedUnsorted )
31fb32e1
RR
990 EVT_DATAVIEW_COLUMN_HEADER_CLICK( ID_SORTED, MySortingFrame::OnHeaderClickSorted )
991 EVT_DATAVIEW_COLUMN_HEADER_CLICK( ID_UNSORTED, MySortingFrame::OnHeaderClickUnsorted )
abd6692c
RR
992END_EVENT_TABLE()
993
241cb04b
RR
994MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
995 wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
996{
eb7f97f8
RR
997 m_logOld = NULL;
998
0bcd4039 999 SetIcon(wxICON(sample));
241cb04b 1000 CreateStatusBar();
b910a8ad 1001
87f0efe2 1002 wxPanel *main = new wxPanel(this);
b910a8ad 1003
241cb04b 1004 // Left wxDataViewCtrl
87f0efe2
RR
1005 dataview_left = new wxDataViewCtrl( main, ID_UNSORTED, wxDefaultPosition,
1006 wxDefaultSize, wxDV_MULTIPLE );
241cb04b 1007
9861f022
RR
1008 m_unsorted_model.reset(new MyUnsortedTextModel);
1009 dataview_left->AssociateModel( m_unsorted_model.get() );
87f0efe2
RR
1010
1011 wxDataViewTextRenderer *text_renderer =
47c94466 1012 new MyTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
baa9ebc4 1013 wxDataViewColumn *column = new wxDataViewColumn( wxT("editable"), text_renderer, 0 );
241cb04b
RR
1014 dataview_left->AppendColumn( column );
1015 dataview_left->AppendTextColumn( wxT("second"), 1 );
87f0efe2
RR
1016 dataview_left->AppendColumn( new wxDataViewColumn( wxBitmap(null_xpm),
1017 new wxDataViewBitmapRenderer, 2, 25 ) );
1018 dataview_left->AppendColumn( new wxDataViewColumn( wxT("icon"),
1019 new wxDataViewBitmapRenderer, 3, 25 ) );
b910a8ad 1020
241cb04b 1021 // Right wxDataViewCtrl using the sorting model
87f0efe2 1022 dataview_right = new wxDataViewCtrl( main, ID_SORTED );
979f71a3 1023
9861f022
RR
1024 m_sorted_model.reset(new wxDataViewSortedListModel( m_unsorted_model.get() ));
1025 dataview_right->AssociateModel( m_sorted_model.get() );
87f0efe2 1026
baa9ebc4 1027 text_renderer = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
87f0efe2
RR
1028 column = new wxDataViewColumn( wxT("editable"), text_renderer, 0, -1,
1029 wxALIGN_CENTER,
1030 wxDATAVIEW_COL_SORTABLE|wxDATAVIEW_COL_RESIZABLE );
241cb04b 1031 dataview_right->AppendColumn( column );
979f71a3 1032
241cb04b 1033 dataview_right->AppendTextColumn( wxT("second"), 1 );
1e510b1e
RR
1034
1035 MySpinCtrlInPlaceRenderer *sr = new MySpinCtrlInPlaceRenderer;
1036 column = new wxDataViewColumn( wxT("spin"), sr, 4, -1, wxALIGN_CENTER );
1037 dataview_right->AppendColumn( column );
241cb04b
RR
1038
1039 // layout dataview controls.
b910a8ad 1040
abd6692c
RR
1041 wxBoxSizer *top_sizer = new wxBoxSizer( wxHORIZONTAL );
1042 top_sizer->Add( dataview_left, 1, wxGROW );
1043 top_sizer->Add(10,10);
1044 top_sizer->Add( dataview_right, 1, wxGROW );
b910a8ad 1045
abd6692c
RR
1046 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
1047 button_sizer->Add( 10, 10, 1 );
1048 wxFlexGridSizer *left_sizer = new wxFlexGridSizer( 2 );
87f0efe2
RR
1049 left_sizer->Add( new wxButton( main, ID_APPEND_ROW_LEFT, wxT("Append") ), 0, wxALL, 5 );
1050 left_sizer->Add( new wxButton( main, ID_PREPEND_ROW_LEFT, wxT("Prepend") ), 0, wxALL, 5 );
1051 left_sizer->Add( new wxButton( main, ID_INSERT_ROW_LEFT, wxT("Insert") ), 0, wxALL, 5 );
1052 left_sizer->Add( new wxButton( main, ID_DELETE_ROW_LEFT, wxT("Delete second") ), 0, wxALL, 5 );
1053 left_sizer->Add( new wxButton( main, ID_EDIT_ROW_LEFT, wxT("Edit") ), 0, wxALL, 5 );
fc211fe5 1054 left_sizer->Add( 5,5 );
87f0efe2
RR
1055 left_sizer->Add( new wxButton( main, ID_SELECT, wxT("Select third") ), 0, wxALL, 5 );
1056 left_sizer->Add( new wxButton( main, ID_UNSELECT_ALL, wxT("Unselect all") ), 0, wxALL, 5 );
abd6692c
RR
1057 button_sizer->Add( left_sizer );
1058 button_sizer->Add( 10, 10, 2 );
1059 wxFlexGridSizer *right_sizer = new wxFlexGridSizer( 2 );
87f0efe2
RR
1060 right_sizer->Add( new wxButton( main, ID_APPEND_ROW_RIGHT, wxT("Append") ), 0, wxALL, 5 );
1061 right_sizer->Add( new wxButton( main, ID_PREPEND_ROW_RIGHT, wxT("Prepend") ), 0, wxALL, 5 );
1062 right_sizer->Add( new wxButton( main, ID_INSERT_ROW_RIGHT, wxT("Insert") ), 0, wxALL, 5 );
1063 right_sizer->Add( new wxButton( main, ID_DELETE_ROW_RIGHT, wxT("Delete second") ), 0, wxALL, 5 );
1064 right_sizer->Add( new wxButton( main, ID_EDIT_ROW_RIGHT, wxT("Edit") ), 0, wxALL, 5 );
abd6692c
RR
1065 button_sizer->Add( right_sizer );
1066 button_sizer->Add( 10, 10, 1 );
b910a8ad 1067
abd6692c
RR
1068 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
1069 main_sizer->Add( top_sizer, 1, wxGROW );
1070 main_sizer->Add( button_sizer, 0, wxGROW );
eb7f97f8 1071
87f0efe2 1072 m_logWindow = new wxTextCtrl(main, wxID_ANY, wxEmptyString,
eb7f97f8
RR
1073 wxDefaultPosition, wxDefaultSize,
1074 wxTE_MULTILINE | wxSUNKEN_BORDER);
1075 main_sizer->Add( 20,20 );
1076 main_sizer->Add( m_logWindow, 1, wxGROW );
1077
1078 m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_logWindow));
b910a8ad 1079
87f0efe2 1080 main->SetSizer( main_sizer );
241cb04b
RR
1081}
1082
eb7f97f8
RR
1083MySortingFrame::~MySortingFrame()
1084{
1085 delete wxLog::SetActiveTarget(m_logOld);
1086}
1087
1088void MySortingFrame::OnSelectedUnsorted(wxDataViewEvent &event)
1089{
fc211fe5
RR
1090 int row = event.GetRow();
1091 wxLogMessage( wxT("OnSelected from unsorted list, selected %d"), row );
1092 if (row >= 0)
1093 wxLogMessage( wxT("wxDataViewCtrl::IsSelected( %d ): %d (as int)"),
1094 row, (int) dataview_right->IsSelected( row ) );
eb7f97f8
RR
1095}
1096
1097void MySortingFrame::OnSelectedSorted(wxDataViewEvent &event)
1098{
1099 wxLogMessage( wxT("OnSelected from sorted list, selected %d"), (int) event.GetRow() );
1100}
1101
f828871d
RR
1102void MySortingFrame::OnActivatedUnsorted(wxDataViewEvent &event)
1103{
1104 wxLogMessage( wxT("OnActivated from unsorted list, activated %d"), (int) event.GetRow() );
1105}
1106
31fb32e1
RR
1107void MySortingFrame::OnHeaderClickSorted(wxDataViewEvent &event)
1108{
1109 wxDataViewColumn *col = event.GetDataViewColumn();
1110 wxLogMessage( wxT("OnHeaderClick from sorted list, column %s"), col->GetTitle().c_str() );
1111
1112 if (col->GetTitle() == wxT("editable"))
1113 {
1114 // this is the sorting column
1115 if (col->IsSortOrderAscending())
1116 {
1117 col->SetSortOrder( false );
1118 m_sorted_model->SetAscending( false );
1119 m_sorted_model->Resort();
1120 }
1121 else
1122 {
1123 col->SetSortOrder( true );
1124 m_sorted_model->SetAscending( true );
1125 m_sorted_model->Resort();
1126 }
1127 }
1128}
1129
1130void MySortingFrame::OnHeaderClickUnsorted(wxDataViewEvent &event)
1131{
87f0efe2
RR
1132 wxLogMessage( wxT("OnHeaderClick from unsorted list, column %s"),
1133 event.GetDataViewColumn()->GetTitle().c_str() );
31fb32e1
RR
1134}
1135
241cb04b
RR
1136void MySortingFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
1137{
1138 Close(true);
1139}
1140
1141void MySortingFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
1142{
1143 wxMessageDialog dialog(this, _T("This demonstrates the dataview control sorting"),
1144 _T("About DataView"), wxOK);
1145
1146 dialog.ShowModal();
1147}
bd6169a6 1148
fc211fe5
RR
1149void MySortingFrame::OnSelect(wxCommandEvent& WXUNUSED(event))
1150{
1151 dataview_left->SetSelection( 2 );
1152}
1153
1154void MySortingFrame::OnUnselectAll(wxCommandEvent& WXUNUSED(event))
1155{
1156 dataview_left->ClearSelection();
1157}
1158
f554a14b 1159void MySortingFrame::OnAppendRowLeft(wxCommandEvent& WXUNUSED(event))
abd6692c 1160{
4627af27
RR
1161 wxTextEntryDialog dialog( this, wxT("Enter text to append") );
1162 if (dialog.ShowModal() == wxID_OK)
1163 {
1164 wxString value = dialog.GetValue();
1165 if (!value.empty())
1166 m_unsorted_model->AppendRow( value );
1167 }
abd6692c
RR
1168}
1169
f554a14b 1170void MySortingFrame::OnPrependRowLeft(wxCommandEvent& WXUNUSED(event))
abd6692c 1171{
4627af27
RR
1172 wxTextEntryDialog dialog( this, wxT("Enter text to prepend") );
1173 if (dialog.ShowModal() == wxID_OK)
1174 {
1175 wxString value = dialog.GetValue();
1176 if (!value.empty())
1177 m_unsorted_model->PrependRow( value );
1178 }
abd6692c
RR
1179}
1180
f554a14b 1181void MySortingFrame::OnInsertRowLeft(wxCommandEvent& WXUNUSED(event))
abd6692c 1182{
cbc9145c 1183 wxTextEntryDialog dialog( this, wxT("Enter text to insert before second") );
4627af27
RR
1184 if (dialog.ShowModal() == wxID_OK)
1185 {
1186 wxString value = dialog.GetValue();
1187 if (!value.empty())
1188 m_unsorted_model->InsertRowAt1( value );
1189 }
abd6692c
RR
1190}
1191
f554a14b 1192void MySortingFrame::OnDeleteRowLeft(wxCommandEvent& WXUNUSED(event))
abd6692c 1193{
4627af27 1194 m_unsorted_model->DeleteRow( 1 );
abd6692c
RR
1195}
1196
f554a14b 1197void MySortingFrame::OnEditRowLeft(wxCommandEvent& WXUNUSED(event))
abd6692c
RR
1198{
1199}
1200
f554a14b 1201void MySortingFrame::OnAppendRowRight(wxCommandEvent& WXUNUSED(event))
abd6692c
RR
1202{
1203}
1204
f554a14b 1205void MySortingFrame::OnPrependRowRight(wxCommandEvent& WXUNUSED(event))
abd6692c
RR
1206{
1207}
1208
f554a14b 1209void MySortingFrame::OnInsertRowRight(wxCommandEvent& WXUNUSED(event))
abd6692c
RR
1210{
1211}
1212
f554a14b 1213void MySortingFrame::OnDeleteRowRight(wxCommandEvent& WXUNUSED(event))
abd6692c
RR
1214{
1215}
1216
f554a14b 1217void MySortingFrame::OnEditRowRight(wxCommandEvent& WXUNUSED(event))
abd6692c
RR
1218{
1219}
1220