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