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