]>
Commit | Line | Data |
---|---|---|
bd6169a6 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dataview.cpp | |
9861f022 | 3 | // Purpose: wxDataViewCtrl wxWidgets sample |
bd6169a6 | 4 | // Author: Robert Roebling |
b7e9f8b1 | 5 | // Modified by: Francesco Montorsi, Bo Yang |
bd6169a6 RR |
6 | // Created: 06/01/06 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Robert Roebling | |
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 | |
ad386793 RR |
31 | #include "wx/ptr_shrd.h" |
32 | #include "wx/vector.h" | |
33 | ||
bd6169a6 | 34 | #ifndef __WXMSW__ |
0bcd4039 | 35 | #include "../sample.xpm" |
bd6169a6 RR |
36 | #endif |
37 | ||
cbc9145c RR |
38 | #include "null.xpm" |
39 | ||
a75124d0 RR |
40 | /* XPM */ |
41 | static const char *small1_xpm[] = { | |
42 | /* columns rows colors chars-per-pixel */ | |
43 | "16 16 6 1", | |
44 | ". c Black", | |
45 | "o c #FFFFFF", | |
46 | "X c #000080", | |
47 | "O c #FFFF00", | |
48 | " c None", | |
49 | "+ c #FF0000", | |
50 | /* pixels */ | |
51 | " ", | |
52 | " ", | |
53 | " ", | |
54 | " ....... ", | |
55 | " .XXXXX. ", | |
56 | " .oXXXX. ", | |
57 | " .oXXX.......", | |
58 | ".....oXXX.OOOOO.", | |
59 | ".+++.XXXX.oOOOO.", | |
60 | ".o++......oOOOO.", | |
61 | ".o++++. .oOOOO.", | |
62 | ".o++++. .OOOOO.", | |
63 | ".+++++. .......", | |
64 | "....... ", | |
65 | " ", | |
66 | " " | |
67 | }; | |
68 | ||
69 | ||
9861f022 RR |
70 | #define DEFAULT_ALIGN wxALIGN_LEFT |
71 | #define DATAVIEW_DEFAULT_STYLE (wxDV_MULTIPLE|wxDV_HORIZ_RULES|wxDV_VERT_RULES) | |
72 | ||
362d7fb9 | 73 | // ------------------------------------- |
5debbdcf | 74 | // MyMusicModel |
362d7fb9 | 75 | // ------------------------------------- |
bd6169a6 | 76 | |
5debbdcf RR |
77 | /* |
78 | Implement this data model | |
79 | Title Artist Year | |
80 | ------------------------------------------------------------- | |
81 | 1: My Music: | |
82 | 2: Pop music | |
83 | 3: You are not alone Michael Jackson 1995 | |
84 | 4: Take a bow Madonna 1994 | |
85 | 5: Classical music | |
86 | 6: Ninth Symphony Ludwig v. Beethoven 1824 | |
87 | 7: German Requiem Johannes Brahms 1868 | |
88 | */ | |
4d496ecb | 89 | |
1e08ad10 RR |
90 | |
91 | ||
92 | class MyMusicModelNode; | |
93 | WX_DEFINE_ARRAY_PTR( MyMusicModelNode*, MyMusicModelNodes ); | |
94 | ||
95 | class MyMusicModelNode | |
96 | { | |
97 | public: | |
b5fce9e2 | 98 | MyMusicModelNode( MyMusicModelNode* parent, |
405a351f | 99 | const wxString &title, const wxString &artist, int year ) |
1e08ad10 RR |
100 | { |
101 | m_parent = parent; | |
1e08ad10 RR |
102 | m_title = title; |
103 | m_artist = artist; | |
104 | m_year = year; | |
105 | m_isContainer = false; | |
106 | } | |
107 | ||
b5fce9e2 | 108 | MyMusicModelNode( MyMusicModelNode* parent, |
1e08ad10 RR |
109 | const wxString &branch ) |
110 | { | |
111 | m_parent = parent; | |
1e08ad10 | 112 | m_title = branch; |
405a351f | 113 | m_year = -1; |
1e08ad10 RR |
114 | m_isContainer = true; |
115 | } | |
116 | ||
117 | ~MyMusicModelNode() | |
118 | { | |
119 | size_t count = m_children.GetCount(); | |
120 | size_t i; | |
121 | for (i = 0; i < count; i++) | |
122 | { | |
123 | MyMusicModelNode *child = m_children[i]; | |
124 | delete child; | |
125 | } | |
126 | } | |
127 | ||
1e08ad10 RR |
128 | bool IsContainer() { return m_isContainer; } |
129 | ||
130 | MyMusicModelNode* GetParent() { return m_parent; } | |
131 | MyMusicModelNodes &GetChildren() { return m_children; } | |
132 | MyMusicModelNode* GetNthChild( unsigned int n ) { return m_children.Item( n ); } | |
133 | void Insert( MyMusicModelNode* child, unsigned int n) { m_children.Insert( child, n); } | |
134 | void Append( MyMusicModelNode* child ) { m_children.Add( child ); } | |
135 | unsigned int GetChildCount() { return m_children.GetCount(); } | |
136 | ||
137 | public: | |
138 | wxString m_title; | |
139 | wxString m_artist; | |
405a351f | 140 | int m_year; |
1e08ad10 RR |
141 | |
142 | private: | |
143 | MyMusicModelNode *m_parent; | |
144 | MyMusicModelNodes m_children; | |
1e08ad10 RR |
145 | bool m_isContainer; |
146 | }; | |
147 | ||
aba9bfd0 | 148 | |
5debbdcf | 149 | class MyMusicModel: public wxDataViewModel |
bd6169a6 RR |
150 | { |
151 | public: | |
e63807a8 RR |
152 | |
153 | // constructor | |
154 | ||
1e08ad10 RR |
155 | MyMusicModel() |
156 | { | |
99c75ebc RR |
157 | m_root = new MyMusicModelNode( NULL, wxT("My Music" )); |
158 | m_pop = new MyMusicModelNode( m_root, wxT("Pop music") ); | |
1e08ad10 | 159 | m_root->Append( m_pop ); |
b5fce9e2 | 160 | m_pop->Append( new MyMusicModelNode( m_pop, |
99c75ebc | 161 | wxT("You are not alone"), wxT("Michael Jackson"), 1995 ) ); |
b5fce9e2 | 162 | m_pop->Append( new MyMusicModelNode( m_pop, |
99c75ebc RR |
163 | wxT("Take a bow"), wxT("Madonna"), 1994 ) ); |
164 | m_classical = new MyMusicModelNode( m_root, wxT("Classical music") ); | |
1e08ad10 | 165 | m_root->Append( m_classical ); |
b5fce9e2 | 166 | m_classical->Append( new MyMusicModelNode( m_classical, |
99c75ebc | 167 | wxT("Ninth symphony"), wxT("Ludwig van Beethoven"), 1824 ) ); |
b5fce9e2 | 168 | m_classical->Append( new MyMusicModelNode( m_classical, |
99c75ebc | 169 | wxT("German Requiem"), wxT("Johannes Brahms"), 1868 ) ); |
befa9b61 | 170 | m_classicalMusicIsKnownToControl = false; |
1e08ad10 | 171 | } |
e39d30c0 RR |
172 | |
173 | ~MyMusicModel() | |
174 | { | |
175 | delete m_root; | |
176 | } | |
1e08ad10 | 177 | |
d32332aa RR |
178 | // helper method for wxLog |
179 | ||
180 | wxString GetTitle( const wxDataViewItem &item ) | |
181 | { | |
182 | MyMusicModelNode *node = (MyMusicModelNode*) item.GetID(); | |
183 | if (!node) | |
184 | return wxEmptyString; | |
185 | ||
186 | return node->m_title; | |
187 | } | |
188 | ||
e63807a8 RR |
189 | // helper methods to change the model |
190 | ||
405a351f | 191 | void AddToClassical( const wxString &title, const wxString &artist, int year ) |
1e08ad10 RR |
192 | { |
193 | // add to data | |
194 | MyMusicModelNode *child_node = | |
b5fce9e2 | 195 | new MyMusicModelNode( m_classical, title, artist, year ); |
b7e9f8b1 | 196 | |
1e08ad10 RR |
197 | m_classical->Append( child_node ); |
198 | ||
befa9b61 RR |
199 | if (m_classicalMusicIsKnownToControl) |
200 | { | |
201 | // notify control | |
b5fce9e2 RR |
202 | wxDataViewItem child( (void*) child_node ); |
203 | wxDataViewItem parent( (void*) m_classical ); | |
befa9b61 RR |
204 | ItemAdded( parent, child ); |
205 | } | |
1e08ad10 | 206 | } |
e63807a8 RR |
207 | |
208 | void Delete( const wxDataViewItem &item ) | |
209 | { | |
b5fce9e2 | 210 | MyMusicModelNode *node = (MyMusicModelNode*) item.GetID(); |
9d8fe14a | 211 | wxDataViewItem parent( node->GetParent() ); |
e63807a8 | 212 | |
d3f00f59 VZ |
213 | node->GetParent()->GetChildren().Remove( node ); |
214 | delete node; | |
405a351f RR |
215 | |
216 | // notify control | |
217 | ItemDeleted( parent, item ); | |
e63807a8 RR |
218 | } |
219 | ||
cf283a47 RR |
220 | // override sorting to always sort branches ascendingly |
221 | ||
7ee7191c RR |
222 | int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, |
223 | unsigned int column, bool ascending ) | |
cf283a47 | 224 | { |
ed903e42 | 225 | if (IsContainer(item1) && IsContainer(item2)) |
cf283a47 RR |
226 | { |
227 | wxVariant value1,value2; | |
228 | GetValue( value1, item1, 0 ); | |
229 | GetValue( value2, item2, 0 ); | |
230 | ||
231 | wxString str1 = value1.GetString(); | |
232 | wxString str2 = value2.GetString(); | |
233 | int res = str1.Cmp( str2 ); | |
234 | if (res) return res; | |
235 | ||
236 | // items must be different | |
237 | unsigned long litem1 = (unsigned long) item1.GetID(); | |
238 | unsigned long litem2 = (unsigned long) item2.GetID(); | |
239 | ||
240 | return litem1-litem2; | |
241 | } | |
242 | ||
7ee7191c | 243 | return wxDataViewModel::Compare( item1, item2, column, ascending ); |
cf283a47 RR |
244 | } |
245 | ||
e63807a8 | 246 | // implementation of base class virtuals to define model |
5debbdcf RR |
247 | |
248 | virtual unsigned int GetColumnCount() const | |
a7f61f76 | 249 | { |
fc5eacdb | 250 | return 3; |
a7f61f76 | 251 | } |
b910a8ad | 252 | |
9861f022 | 253 | virtual wxString GetColumnType( unsigned int col ) const |
5debbdcf | 254 | { |
405a351f | 255 | if (col == 2) |
99c75ebc | 256 | return wxT("long"); |
405a351f | 257 | |
99c75ebc | 258 | return wxT("string"); |
5debbdcf | 259 | } |
b910a8ad | 260 | |
5debbdcf RR |
261 | virtual void GetValue( wxVariant &variant, |
262 | const wxDataViewItem &item, unsigned int col ) const | |
263 | { | |
b5fce9e2 | 264 | MyMusicModelNode *node = (MyMusicModelNode*) item.GetID(); |
1e08ad10 | 265 | switch (col) |
605c2c4a | 266 | { |
1e08ad10 RR |
267 | case 0: variant = node->m_title; break; |
268 | case 1: variant = node->m_artist; break; | |
405a351f | 269 | case 2: variant = (long) node->m_year; break; |
0bd26819 RR |
270 | default: |
271 | { | |
99c75ebc | 272 | wxLogError( wxT("MyMusicModel::GetValue: wrong column" )); |
405a351f RR |
273 | |
274 | // provoke a crash when mouse button down | |
0bd26819 RR |
275 | wxMouseState state = wxGetMouseState(); |
276 | if (state.ShiftDown()) | |
277 | { | |
278 | char *crash = 0; | |
279 | *crash = 0; | |
280 | } | |
281 | } | |
a7f61f76 | 282 | } |
e152afc3 | 283 | } |
9861f022 | 284 | |
5debbdcf RR |
285 | virtual bool SetValue( const wxVariant &variant, |
286 | const wxDataViewItem &item, unsigned int col ) | |
9861f022 | 287 | { |
b5fce9e2 | 288 | MyMusicModelNode *node = (MyMusicModelNode*) item.GetID(); |
1e08ad10 RR |
289 | switch (col) |
290 | { | |
c2a92c80 RR |
291 | case 0: node->m_title = variant.GetString(); return true; |
292 | case 1: node->m_artist = variant.GetString(); return true; | |
293 | case 2: node->m_year = variant.GetLong(); return true; | |
99c75ebc | 294 | default: wxLogError( wxT("MyMusicModel::SetValue: wrong column") ); |
1e08ad10 | 295 | } |
c2a92c80 | 296 | return false; |
9861f022 RR |
297 | } |
298 | ||
ed903e42 | 299 | virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const |
b910a8ad | 300 | { |
ed903e42 RR |
301 | // the invisble root node has no parent |
302 | if (!item.IsOk()) | |
303 | return wxDataViewItem(0); | |
304 | ||
b5fce9e2 | 305 | MyMusicModelNode *node = (MyMusicModelNode*) item.GetID(); |
ed903e42 RR |
306 | |
307 | // "MyMusic" also has no parent | |
308 | if (node == m_root) | |
309 | return wxDataViewItem(0); | |
310 | ||
311 | return wxDataViewItem( (void*) node->GetParent() ); | |
312 | } | |
313 | ||
314 | virtual bool IsContainer( const wxDataViewItem &item ) const | |
315 | { | |
316 | // the invisble root node can have children (in | |
317 | // our model always "MyMusic") | |
318 | if (!item.IsOk()) | |
1e08ad10 RR |
319 | return true; |
320 | ||
ed903e42 | 321 | MyMusicModelNode *node = (MyMusicModelNode*) item.GetID(); |
1e08ad10 | 322 | return node->IsContainer(); |
e152afc3 | 323 | } |
5debbdcf | 324 | |
74fe973b | 325 | virtual unsigned int GetChildren( const wxDataViewItem &parent, wxDataViewItemArray &array ) const |
1e510b1e | 326 | { |
b5fce9e2 RR |
327 | MyMusicModelNode *node = (MyMusicModelNode*) parent.GetID(); |
328 | if (!node) | |
74fe973b RR |
329 | { |
330 | array.Add( wxDataViewItem( (void*) m_root ) ); | |
331 | return 1; | |
332 | } | |
1e08ad10 | 333 | |
befa9b61 RR |
334 | if (node == m_classical) |
335 | { | |
336 | MyMusicModel *model = (MyMusicModel*)(const MyMusicModel*) this; | |
337 | model->m_classicalMusicIsKnownToControl = true; | |
338 | } | |
1e510b1e | 339 | |
74fe973b RR |
340 | if (node->GetChildCount() == 0) |
341 | { | |
342 | return 0; | |
343 | } | |
344 | ||
345 | unsigned int count = node->GetChildren().GetCount(); | |
346 | unsigned int pos; | |
347 | for (pos = 0; pos < count; pos++) | |
348 | { | |
349 | MyMusicModelNode *child = node->GetChildren().Item( pos ); | |
350 | array.Add( wxDataViewItem( (void*) child ) ); | |
351 | } | |
352 | return count; | |
9861f022 | 353 | } |
1e08ad10 | 354 | |
f6f0ef85 RR |
355 | // DnD |
356 | ||
357 | virtual bool IsDraggable( const wxDataViewItem &item ) | |
358 | { | |
359 | // only drag items | |
360 | return (!IsContainer(item)); | |
361 | } | |
362 | ||
363 | virtual size_t GetDragDataSize( const wxDataViewItem &item, const wxDataFormat &WXUNUSED(format) ) | |
364 | { | |
365 | wxPrintf( "GetDragDataSize\n" ); | |
366 | ||
367 | MyMusicModelNode *node = (MyMusicModelNode*) item.GetID(); | |
368 | wxString data; | |
369 | data += node->m_title; data += wxT(" "); | |
370 | data += node->m_artist; | |
371 | return strlen( data.utf8_str() ) + 1; | |
372 | } | |
373 | virtual bool GetDragData( const wxDataViewItem &item, const wxDataFormat &WXUNUSED(format), | |
374 | void* dest, size_t WXUNUSED(size) ) | |
375 | { | |
376 | wxPrintf( "GetDragData\n" ); | |
377 | ||
378 | MyMusicModelNode *node = (MyMusicModelNode*) item.GetID(); | |
379 | wxString data; | |
380 | data += node->m_title; data += wxT(" "); | |
381 | data += node->m_artist; | |
382 | wxCharBuffer buffer( data.utf8_str() ); | |
383 | memcpy( dest, buffer, strlen(buffer)+1 ); | |
384 | return true; | |
385 | } | |
386 | ||
1e08ad10 | 387 | private: |
1e08ad10 RR |
388 | MyMusicModelNode* m_root; |
389 | MyMusicModelNode* m_pop; | |
390 | MyMusicModelNode* m_classical; | |
befa9b61 | 391 | bool m_classicalMusicIsKnownToControl; |
241cb04b RR |
392 | }; |
393 | ||
8b6cf9bf RR |
394 | |
395 | static int my_sort_reverse( int *v1, int *v2 ) | |
396 | { | |
397 | return *v2-*v1; | |
398 | } | |
399 | ||
400 | static int my_sort( int *v1, int *v2 ) | |
401 | { | |
402 | return *v1-*v2; | |
403 | } | |
404 | ||
e39de702 | 405 | class MyListModel: public wxDataViewVirtualListModel |
c534e696 RR |
406 | { |
407 | public: | |
408 | MyListModel() : | |
a75124d0 | 409 | #ifdef __WXMAC__ |
e39de702 | 410 | wxDataViewVirtualListModel( 1000 + 100 ) |
a75124d0 | 411 | #else |
e39de702 | 412 | wxDataViewVirtualListModel( 100000 + 100 ) |
a75124d0 | 413 | #endif |
c534e696 | 414 | { |
33ba5a05 RR |
415 | #ifdef __WXMAC__ |
416 | m_virtualItems = 1000; | |
417 | #else | |
418 | m_virtualItems = 100000; | |
419 | #endif | |
420 | ||
c534e696 RR |
421 | unsigned int i; |
422 | for (i = 0; i < 100; i++) | |
423 | { | |
424 | wxString str; | |
99c75ebc | 425 | str.Printf( wxT("row number %d"), i ); |
c534e696 RR |
426 | m_array.Add( str ); |
427 | } | |
c9c13e70 RR |
428 | |
429 | m_icon = wxIcon( null_xpm ); | |
c534e696 RR |
430 | } |
431 | ||
432 | // helper methods to change the model | |
433 | ||
434 | void Prepend( const wxString &text ) | |
435 | { | |
436 | m_array.Insert( text, 0 ); | |
437 | RowPrepended(); | |
438 | } | |
439 | ||
440 | void DeleteItem( const wxDataViewItem &item ) | |
441 | { | |
442 | unsigned int row = GetRow( item ); | |
33ba5a05 RR |
443 | if (row >= m_array.GetCount()) |
444 | return; | |
445 | ||
c534e696 RR |
446 | m_array.RemoveAt( row ); |
447 | RowDeleted( row ); | |
448 | } | |
8b6cf9bf RR |
449 | |
450 | void DeleteItems( const wxDataViewItemArray &items ) | |
451 | { | |
452 | wxArrayInt rows; | |
453 | unsigned int i; | |
454 | for (i = 0; i < items.GetCount(); i++) | |
455 | { | |
456 | unsigned int row = GetRow( items[i] ); | |
33ba5a05 RR |
457 | if (row < m_array.GetCount()) |
458 | rows.Add( row ); | |
8b6cf9bf RR |
459 | } |
460 | ||
461 | // Sort in descending order so that the last | |
462 | // row will be deleted first. Otherwise the | |
463 | // remaining indeces would all be wrong. | |
464 | rows.Sort( my_sort_reverse ); | |
465 | for (i = 0; i < rows.GetCount(); i++) | |
466 | m_array.RemoveAt( rows[i] ); | |
467 | ||
468 | // This is just to test if wxDataViewCtrl can | |
469 | // cope with removing rows not sorted in | |
470 | // descending order | |
471 | rows.Sort( my_sort ); | |
472 | RowsDeleted( rows ); | |
473 | } | |
474 | ||
475 | void AddMany() | |
476 | { | |
33ba5a05 RR |
477 | m_virtualItems += 1000; |
478 | Reset( m_array.GetCount() + m_virtualItems ); | |
8b6cf9bf | 479 | } |
c534e696 RR |
480 | |
481 | // implementation of base class virtuals to define model | |
482 | ||
483 | virtual unsigned int GetColumnCount() const | |
484 | { | |
c9c13e70 | 485 | return 3; |
c534e696 RR |
486 | } |
487 | ||
488 | virtual wxString GetColumnType( unsigned int col ) const | |
489 | { | |
c9c13e70 | 490 | if (col == 1) |
99c75ebc | 491 | return wxT("wxDataViewIconText"); |
c9c13e70 | 492 | |
99c75ebc RR |
493 | return wxT("string"); |
494 | } | |
495 | ||
496 | virtual unsigned int GetRowCount() | |
497 | { | |
498 | return m_array.GetCount(); | |
c534e696 RR |
499 | } |
500 | ||
c534e696 RR |
501 | virtual void GetValue( wxVariant &variant, |
502 | unsigned int row, unsigned int col ) const | |
503 | { | |
504 | if (col==0) | |
505 | { | |
a75124d0 RR |
506 | if (row >= m_array.GetCount()) |
507 | { | |
508 | wxString str; | |
99c75ebc | 509 | str.Printf(wxT("row %d"), row - m_array.GetCount() ); |
a75124d0 RR |
510 | variant = str; |
511 | } | |
512 | else | |
513 | { | |
514 | variant = m_array[ row ]; | |
515 | } | |
c9c13e70 RR |
516 | } else |
517 | if (col==1) | |
518 | { | |
99c75ebc | 519 | wxDataViewIconText data( wxT("test"), m_icon ); |
c9c13e70 | 520 | variant << data; |
4264606e RR |
521 | } else |
522 | if (col==2) | |
c534e696 | 523 | { |
33ba5a05 | 524 | if (row >= m_array.GetCount()) |
99c75ebc | 525 | variant = wxT("plain"); |
4264606e | 526 | else |
99c75ebc | 527 | variant = wxT("blue"); |
c534e696 RR |
528 | } |
529 | } | |
4264606e RR |
530 | |
531 | virtual bool GetAttr( unsigned int row, unsigned int col, wxDataViewItemAttr &attr ) | |
532 | { | |
533 | if (col != 2) | |
534 | return false; | |
535 | ||
33ba5a05 RR |
536 | if (row < m_array.GetCount()) |
537 | { | |
4264606e | 538 | attr.SetColour( *wxBLUE ); |
4264606e | 539 | attr.SetItalic( true ); |
33ba5a05 | 540 | } |
4264606e RR |
541 | |
542 | return true; | |
543 | } | |
c534e696 RR |
544 | |
545 | virtual bool SetValue( const wxVariant &variant, | |
546 | unsigned int row, unsigned int col ) | |
547 | { | |
548 | if (col == 0) | |
549 | { | |
a75124d0 RR |
550 | if (row >= m_array.GetCount()) |
551 | return false; | |
552 | ||
c534e696 RR |
553 | m_array[row] = variant.GetString(); |
554 | return true; | |
555 | } | |
556 | ||
557 | return false; | |
558 | } | |
559 | ||
560 | wxArrayString m_array; | |
c9c13e70 | 561 | wxIcon m_icon; |
33ba5a05 | 562 | int m_virtualItems; |
c534e696 RR |
563 | }; |
564 | ||
0bdfa388 RR |
565 | // ------------------------------------- |
566 | // MyCustomRenderer | |
567 | // ------------------------------------- | |
568 | ||
569 | class MyCustomRenderer: public wxDataViewCustomRenderer | |
570 | { | |
571 | public: | |
f593b0b9 | 572 | MyCustomRenderer( wxDataViewCellMode mode, int alignment ) : |
0bdfa388 RR |
573 | wxDataViewCustomRenderer( wxString("long"), mode, alignment ) { } |
574 | ||
575 | virtual bool Render( wxRect rect, wxDC *dc, int WXUNUSED(state) ) | |
576 | { | |
577 | dc->SetBrush( *wxRED_BRUSH ); | |
578 | dc->SetPen( *wxTRANSPARENT_PEN ); | |
579 | dc->DrawRectangle( rect ); | |
580 | return true; | |
581 | } | |
582 | ||
583 | ||
584 | virtual bool Activate( wxRect WXUNUSED(cell), | |
585 | wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) ) | |
586 | { | |
587 | wxLogMessage( wxT("MyCustomRenderer Activate()") ); | |
588 | return false; | |
589 | } | |
590 | ||
591 | virtual bool LeftClick( wxPoint cursor, wxRect WXUNUSED(cell), | |
592 | wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) ) | |
593 | { | |
594 | wxLogMessage( wxT("MyCustomRenderer LeftClick( %d, %d )"), cursor.x, cursor.y ); | |
595 | return false; | |
596 | } | |
597 | ||
598 | virtual wxSize GetSize() const | |
599 | { | |
83087c60 | 600 | return wxSize(60,20); |
0bdfa388 RR |
601 | } |
602 | ||
603 | virtual bool SetValue( const wxVariant &WXUNUSED(value) ) { return true; } | |
604 | virtual bool GetValue( wxVariant &WXUNUSED(value) ) const { return true; } | |
605 | }; | |
606 | ||
362d7fb9 RR |
607 | // ------------------------------------- |
608 | // MyApp | |
609 | // ------------------------------------- | |
bd6169a6 RR |
610 | |
611 | class MyApp: public wxApp | |
612 | { | |
613 | public: | |
614 | bool OnInit(void); | |
87f0efe2 | 615 | int OnExit(); |
bd6169a6 RR |
616 | }; |
617 | ||
362d7fb9 RR |
618 | // ------------------------------------- |
619 | // MyFrame | |
620 | // ------------------------------------- | |
621 | ||
87f0efe2 | 622 | class MyFrame : public wxFrame |
bd6169a6 RR |
623 | { |
624 | public: | |
e94d0c1e | 625 | MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int h); |
e39d30c0 | 626 | ~MyFrame(); |
bd6169a6 RR |
627 | |
628 | public: | |
629 | void OnQuit(wxCommandEvent& event); | |
630 | void OnAbout(wxCommandEvent& event); | |
c534e696 RR |
631 | |
632 | void OnAddMozart(wxCommandEvent& event); | |
633 | void OnDeleteMusic(wxCommandEvent& event); | |
736fe67c | 634 | void OnDeleteYear(wxCommandEvent& event); |
c534e696 RR |
635 | |
636 | void OnPrependList(wxCommandEvent& event); | |
637 | void OnDeleteList(wxCommandEvent& event); | |
b910a8ad | 638 | |
d8331a01 | 639 | void OnValueChanged( wxDataViewEvent &event ); |
718fd180 | 640 | |
b7e9f8b1 | 641 | void OnActivated( wxDataViewEvent &event ); |
718fd180 RR |
642 | void OnExpanding( wxDataViewEvent &event ); |
643 | void OnExpanded( wxDataViewEvent &event ); | |
644 | void OnCollapsing( wxDataViewEvent &event ); | |
645 | void OnCollapsed( wxDataViewEvent &event ); | |
aed836f3 | 646 | void OnSelectionChanged( wxDataViewEvent &event ); |
718fd180 | 647 | |
d14e1c3a RR |
648 | void OnEditingStarted( wxDataViewEvent &event ); |
649 | void OnEditingDone( wxDataViewEvent &event ); | |
650 | ||
b7e9f8b1 RR |
651 | void OnHeaderClick( wxDataViewEvent &event ); |
652 | void OnHeaderRightClick( wxDataViewEvent &event ); | |
653 | void OnSorted( wxDataViewEvent &event ); | |
654 | ||
74dea0de RR |
655 | void OnContextMenu( wxDataViewEvent &event ); |
656 | ||
b7e9f8b1 RR |
657 | void OnRightClick( wxMouseEvent &event ); |
658 | void OnGoto( wxCommandEvent &event); | |
8b6cf9bf | 659 | void OnAddMany( wxCommandEvent &event); |
d8331a01 | 660 | |
bd6169a6 | 661 | private: |
c534e696 RR |
662 | wxDataViewCtrl* m_musicCtrl; |
663 | wxObjectDataPtr<MyMusicModel> m_music_model; | |
664 | ||
665 | wxDataViewCtrl* m_listCtrl; | |
666 | wxObjectDataPtr<MyListModel> m_list_model; | |
fbda518c RR |
667 | |
668 | wxDataViewColumn * m_col; | |
c534e696 | 669 | |
1e08ad10 | 670 | wxTextCtrl * m_log; |
b7e9f8b1 | 671 | wxLog *m_logOld; |
31fb32e1 | 672 | |
241cb04b | 673 | private: |
abd6692c | 674 | DECLARE_EVENT_TABLE() |
241cb04b RR |
675 | }; |
676 | ||
362d7fb9 RR |
677 | // ------------------------------------- |
678 | // MyApp | |
679 | // ------------------------------------- | |
680 | ||
87f0efe2 | 681 | IMPLEMENT_APP(MyApp) |
bd6169a6 | 682 | |
bd6169a6 RR |
683 | bool MyApp::OnInit(void) |
684 | { | |
45e6e6f8 VZ |
685 | if ( !wxApp::OnInit() ) |
686 | return false; | |
687 | ||
87f0efe2 RR |
688 | // build the first frame |
689 | MyFrame *frame = | |
0bdfa388 | 690 | new MyFrame(NULL, wxT("wxDataViewCtrl feature test"), 40, 40, 1000, 540); |
bd6169a6 RR |
691 | frame->Show(true); |
692 | ||
693 | SetTopWindow(frame); | |
bd6169a6 RR |
694 | return true; |
695 | } | |
696 | ||
87f0efe2 RR |
697 | int MyApp::OnExit() |
698 | { | |
699 | return 0; | |
700 | } | |
701 | ||
702 | ||
bd6169a6 RR |
703 | // ------------------------------------- |
704 | // MyFrame | |
705 | // ------------------------------------- | |
706 | ||
87f0efe2 RR |
707 | enum |
708 | { | |
709 | // file menu | |
710 | ID_ABOUT = wxID_ABOUT, | |
87f0efe2 | 711 | ID_EXIT = wxID_EXIT, |
1e08ad10 | 712 | |
d8331a01 RR |
713 | ID_MUSIC_CTRL = 50, |
714 | ||
c534e696 RR |
715 | ID_ADD_MOZART = 100, |
716 | ID_DELETE_MUSIC = 101, | |
736fe67c | 717 | ID_DELETE_YEAR = 102, |
c534e696 RR |
718 | |
719 | ID_PREPEND_LIST = 200, | |
b7e9f8b1 | 720 | ID_DELETE_LIST = 201, |
8b6cf9bf RR |
721 | ID_GOTO = 202, |
722 | ID_ADD_MANY = 203 | |
87f0efe2 RR |
723 | }; |
724 | ||
725 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
87f0efe2 | 726 | EVT_MENU( ID_ABOUT, MyFrame::OnAbout ) |
87f0efe2 | 727 | EVT_MENU( ID_EXIT, MyFrame::OnQuit ) |
c534e696 RR |
728 | EVT_BUTTON( ID_ADD_MOZART, MyFrame::OnAddMozart ) |
729 | EVT_BUTTON( ID_DELETE_MUSIC, MyFrame::OnDeleteMusic ) | |
736fe67c | 730 | EVT_BUTTON( ID_DELETE_YEAR, MyFrame::OnDeleteYear ) |
c534e696 RR |
731 | EVT_BUTTON( ID_PREPEND_LIST, MyFrame::OnPrependList ) |
732 | EVT_BUTTON( ID_DELETE_LIST, MyFrame::OnDeleteList ) | |
b7e9f8b1 | 733 | EVT_BUTTON( ID_GOTO, MyFrame::OnGoto) |
8b6cf9bf | 734 | EVT_BUTTON( ID_ADD_MANY, MyFrame::OnAddMany) |
718fd180 | 735 | |
0376cc52 | 736 | EVT_DATAVIEW_ITEM_VALUE_CHANGED( ID_MUSIC_CTRL, MyFrame::OnValueChanged ) |
718fd180 | 737 | |
b7e9f8b1 | 738 | EVT_DATAVIEW_ITEM_ACTIVATED(ID_MUSIC_CTRL, MyFrame::OnActivated ) |
718fd180 RR |
739 | EVT_DATAVIEW_ITEM_EXPANDING(ID_MUSIC_CTRL, MyFrame::OnExpanding) |
740 | EVT_DATAVIEW_ITEM_EXPANDED(ID_MUSIC_CTRL, MyFrame::OnExpanded) | |
741 | EVT_DATAVIEW_ITEM_COLLAPSING(ID_MUSIC_CTRL, MyFrame::OnCollapsing) | |
742 | EVT_DATAVIEW_ITEM_COLLAPSED(ID_MUSIC_CTRL, MyFrame::OnCollapsed) | |
aed836f3 | 743 | EVT_DATAVIEW_SELECTION_CHANGED(ID_MUSIC_CTRL, MyFrame::OnSelectionChanged) |
718fd180 | 744 | |
d14e1c3a RR |
745 | EVT_DATAVIEW_ITEM_EDITING_STARTED(ID_MUSIC_CTRL, MyFrame::OnEditingStarted) |
746 | EVT_DATAVIEW_ITEM_EDITING_DONE(ID_MUSIC_CTRL, MyFrame::OnEditingDone) | |
747 | ||
b7e9f8b1 RR |
748 | EVT_DATAVIEW_COLUMN_HEADER_CLICK(ID_MUSIC_CTRL, MyFrame::OnHeaderClick) |
749 | EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(ID_MUSIC_CTRL, MyFrame::OnHeaderRightClick) | |
750 | EVT_DATAVIEW_COLUMN_SORTED(ID_MUSIC_CTRL, MyFrame::OnSorted) | |
74dea0de RR |
751 | |
752 | EVT_DATAVIEW_ITEM_CONTEXT_MENU(ID_MUSIC_CTRL, MyFrame::OnContextMenu) | |
718fd180 | 753 | |
b7e9f8b1 | 754 | EVT_RIGHT_UP(MyFrame::OnRightClick) |
87f0efe2 RR |
755 | END_EVENT_TABLE() |
756 | ||
e94d0c1e | 757 | MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int h): |
bd6169a6 RR |
758 | wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)) |
759 | { | |
d8331a01 | 760 | m_log = NULL; |
fbda518c | 761 | m_col = NULL; |
d8331a01 | 762 | |
0bcd4039 | 763 | SetIcon(wxICON(sample)); |
bd6169a6 | 764 | |
87f0efe2 RR |
765 | // build the menus: |
766 | ||
bd6169a6 | 767 | wxMenu *file_menu = new wxMenu; |
99c75ebc | 768 | file_menu->Append(ID_ABOUT, wxT("&About")); |
87f0efe2 | 769 | file_menu->AppendSeparator(); |
99c75ebc | 770 | file_menu->Append(ID_EXIT, wxT("E&xit")); |
bd6169a6 | 771 | |
bd6169a6 | 772 | wxMenuBar *menu_bar = new wxMenuBar; |
99c75ebc | 773 | menu_bar->Append(file_menu, wxT("&File")); |
87f0efe2 | 774 | |
bd6169a6 | 775 | SetMenuBar(menu_bar); |
87f0efe2 | 776 | CreateStatusBar(); |
bd6169a6 | 777 | |
1e08ad10 RR |
778 | wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL ); |
779 | ||
c534e696 | 780 | wxBoxSizer *data_sizer = new wxBoxSizer( wxHORIZONTAL ); |
bd6169a6 | 781 | |
c534e696 | 782 | // MyMusic |
b910a8ad | 783 | |
d8331a01 | 784 | m_musicCtrl = new wxDataViewCtrl( this, ID_MUSIC_CTRL, wxDefaultPosition, |
b7e9f8b1 | 785 | wxDefaultSize, wxDV_MULTIPLE ); |
99c75ebc | 786 | |
c534e696 RR |
787 | m_music_model = new MyMusicModel; |
788 | m_musicCtrl->AssociateModel( m_music_model.get() ); | |
789 | ||
f593b0b9 | 790 | wxDataViewTextRenderer *tr = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_INERT, wxALIGN_RIGHT ); |
a39d7501 | 791 | wxDataViewColumn *column0 = new wxDataViewColumn( wxT("title"), tr, 0, 200, wxALIGN_LEFT, |
f593b0b9 RR |
792 | wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE ); |
793 | m_musicCtrl->AppendColumn( column0 ); | |
0bd26819 RR |
794 | #if 0 |
795 | // Call this and sorting is enabled | |
796 | // immediatly upon start up. | |
f593b0b9 | 797 | column0->SetSortOrder( true ); |
0bd26819 RR |
798 | #endif |
799 | ||
a39d7501 RR |
800 | tr = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE, wxALIGN_RIGHT ); |
801 | wxDataViewColumn *column1 = new wxDataViewColumn( wxT("artist"), tr, 1, 150, wxALIGN_LEFT, | |
0bdfa388 RR |
802 | wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE ); |
803 | m_musicCtrl->AppendColumn( column1 ); | |
804 | ||
a39d7501 RR |
805 | wxDataViewSpinRenderer *sr = new wxDataViewSpinRenderer( 0, 2010, wxDATAVIEW_CELL_EDITABLE, wxALIGN_RIGHT ); |
806 | wxDataViewColumn *column2 = new wxDataViewColumn( wxT("year"), sr, 2, 80, wxALIGN_LEFT, | |
807 | wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE ); | |
808 | m_musicCtrl->AppendColumn( column2 ); | |
809 | ||
f593b0b9 | 810 | MyCustomRenderer *cr = new MyCustomRenderer( wxDATAVIEW_CELL_ACTIVATABLE, wxALIGN_RIGHT ); |
a39d7501 | 811 | wxDataViewColumn *column3 = new wxDataViewColumn( wxT("custom"), cr, 2, -1, wxALIGN_LEFT, |
0bdfa388 | 812 | wxDATAVIEW_COL_RESIZABLE ); |
a39d7501 | 813 | m_musicCtrl->AppendColumn( column3 ); |
1e08ad10 | 814 | |
c534e696 RR |
815 | data_sizer->Add( m_musicCtrl, 3, wxGROW ); |
816 | ||
817 | #if 1 | |
818 | ||
819 | // MyList | |
820 | ||
821 | m_listCtrl = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, | |
99c75ebc | 822 | wxDefaultSize, wxDV_MULTIPLE | wxDV_ROW_LINES); |
c534e696 RR |
823 | |
824 | m_list_model = new MyListModel; | |
825 | m_listCtrl->AssociateModel( m_list_model.get() ); | |
83087c60 RR |
826 | |
827 | #if 1 | |
e39de702 | 828 | m_listCtrl->AppendTextColumn (wxT("editable string"), 0, wxDATAVIEW_CELL_EDITABLE, 120, wxALIGN_RIGHT ); |
99c75ebc | 829 | m_listCtrl->AppendIconTextColumn(wxT("icon"), 1, wxDATAVIEW_CELL_INERT, 60 ); |
83087c60 RR |
830 | #else |
831 | m_listCtrl->AppendTextColumn (wxT("editable string"), 0, wxDATAVIEW_CELL_EDITABLE ); | |
832 | m_listCtrl->AppendIconTextColumn(wxT("icon"), 1, wxDATAVIEW_CELL_INERT ); | |
833 | #endif | |
834 | ||
4264606e | 835 | wxDataViewTextRendererAttr *ra = new wxDataViewTextRendererAttr; |
a39d7501 RR |
836 | wxDataViewColumn *column4 = new wxDataViewColumn(wxT("attributes"), ra, 2 ); |
837 | m_listCtrl->AppendColumn( column4 ); | |
c534e696 RR |
838 | |
839 | data_sizer->Add( m_listCtrl, 2, wxGROW ); | |
840 | ||
841 | #endif | |
842 | ||
843 | main_sizer->Add( data_sizer, 2, wxGROW ); | |
1e08ad10 RR |
844 | |
845 | wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL ); | |
846 | ||
99c75ebc RR |
847 | button_sizer->Add( new wxButton( this, ID_ADD_MOZART, _("Add Mozart")), 0, wxALL, 10 ); |
848 | button_sizer->Add( new wxButton( this, ID_DELETE_MUSIC,_("Delete selected")), 0, wxALL, 10 ); | |
849 | button_sizer->Add( new wxButton( this, ID_DELETE_YEAR, _("Delete \"Year\" column")), 0, wxALL, 10 ); | |
c534e696 | 850 | button_sizer->Add( 10, 10, 1 ); |
8b6cf9bf | 851 | wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 2 ); |
99c75ebc RR |
852 | grid_sizer->Add( new wxButton( this, ID_PREPEND_LIST,_("Prepend")), 0, wxALL, 2 ); |
853 | grid_sizer->Add( new wxButton( this, ID_DELETE_LIST, _("Delete selected")), 0, wxALL, 2 ); | |
854 | grid_sizer->Add( new wxButton( this, ID_GOTO, _("Goto 50")), 0, wxALL, 2 ); | |
855 | grid_sizer->Add( new wxButton( this, ID_ADD_MANY, _("Add 1000")), 0, wxALL, 2 ); | |
8b6cf9bf | 856 | button_sizer->Add( grid_sizer, 0, wxALL, 10 ); |
1e08ad10 | 857 | |
c534e696 | 858 | main_sizer->Add( button_sizer, 0, wxGROW, 0 ); |
a75124d0 RR |
859 | |
860 | wxBoxSizer *bottom_sizer = new wxBoxSizer( wxHORIZONTAL ); | |
1e08ad10 | 861 | |
ad386793 | 862 | m_log = new wxTextCtrl( this, -1, wxString(), wxDefaultPosition, wxSize(100,200), wxTE_MULTILINE ); |
b7e9f8b1 | 863 | m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_log)); |
99c75ebc | 864 | wxLogMessage(_("This is the log window")); |
b7e9f8b1 | 865 | |
a75124d0 RR |
866 | bottom_sizer->Add( m_log, 1, wxGROW ); |
867 | ||
868 | // wxDataViewTreeStore | |
e94d0c1e | 869 | |
a75124d0 | 870 | wxDataViewCtrl *treectrl = new wxDataViewCtrl( this, -1, |
ad386793 | 871 | wxDefaultPosition, wxSize(100,200), wxDV_NO_HEADER ); |
e94d0c1e | 872 | |
e94d0c1e | 873 | wxDataViewTreeStore *store = new wxDataViewTreeStore; |
99c75ebc RR |
874 | wxDataViewItem parent = store->AppendContainer( wxDataViewItem(0),wxT("Root 1"), wxIcon(small1_xpm) ); |
875 | wxDataViewItem child = store->AppendItem( parent,wxT("Child 1"), wxIcon(small1_xpm) ); | |
876 | child = store->AppendItem( parent,wxT("Child 2"), wxIcon(small1_xpm) ); | |
ad386793 | 877 | child = store->AppendItem( parent,wxT("Child 3, very long, long, long, long"), wxIcon(small1_xpm) ); |
e94d0c1e | 878 | treectrl->AssociateModel( store ); |
e94d0c1e | 879 | store->DecRef(); |
b89cac3f | 880 | |
0bdfa388 RR |
881 | treectrl->AppendIconTextColumn( wxT("no label"), 0, wxDATAVIEW_CELL_INERT, -1, (wxAlignment) 0, |
882 | wxDATAVIEW_COL_RESIZABLE ); | |
672e58d9 | 883 | |
ad386793 | 884 | bottom_sizer->Add( treectrl, 1 ); |
672e58d9 | 885 | |
a75124d0 RR |
886 | // wxDataViewTreeCtrl |
887 | ||
ad386793 | 888 | wxDataViewTreeCtrl *treectrl2 = new wxDataViewTreeCtrl( this, -1, wxDefaultPosition, wxSize(100,200) ); |
83aa1cf4 | 889 | |
75a2e426 | 890 | wxImageList *ilist = new wxImageList( 16, 16 ); |
a75124d0 | 891 | ilist->Add( wxIcon(small1_xpm) ); |
83aa1cf4 RR |
892 | treectrl2->SetImageList( ilist ); |
893 | ||
99c75ebc RR |
894 | parent = treectrl2->AppendContainer( wxDataViewItem(0),wxT("Root 1"), 0 ); |
895 | child = treectrl2->AppendItem( parent,wxT("Child 1"), 0 ); | |
896 | child = treectrl2->AppendItem( parent,wxT("Child 2"), 0 ); | |
ad386793 | 897 | child = treectrl2->AppendItem( parent,wxT("Child 3, very long, long, long, long"), 0 ); |
e39d30c0 | 898 | |
ad386793 | 899 | bottom_sizer->Add( treectrl2, 1 ); |
a75124d0 RR |
900 | |
901 | // main sizer | |
902 | ||
903 | main_sizer->Add( bottom_sizer, 0, wxGROW ); | |
e94d0c1e | 904 | |
a75124d0 RR |
905 | SetSizer( main_sizer ); |
906 | } | |
907 | ||
e39d30c0 RR |
908 | MyFrame::~MyFrame() |
909 | { | |
910 | delete wxLog::SetActiveTarget(m_logOld); | |
911 | } | |
912 | ||
a75124d0 RR |
913 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) ) |
914 | { | |
915 | Close(true); | |
e94d0c1e RR |
916 | } |
917 | ||
c534e696 RR |
918 | void MyFrame::OnAddMozart(wxCommandEvent& WXUNUSED(event) ) |
919 | { | |
99c75ebc | 920 | m_music_model->AddToClassical( wxT("Kleine Nachtmusik"), wxT("Wolfgang Mozart"), 1787 ); |
c534e696 RR |
921 | } |
922 | ||
923 | void MyFrame::OnDeleteMusic(wxCommandEvent& WXUNUSED(event) ) | |
1e08ad10 | 924 | { |
b7e9f8b1 RR |
925 | wxDataViewItemArray items; |
926 | int len = m_musicCtrl->GetSelections( items ); | |
927 | for( int i = 0; i < len; i ++ ) | |
928 | if (items[i].IsOk()) | |
929 | m_music_model->Delete( items[i] ); | |
e63807a8 RR |
930 | } |
931 | ||
736fe67c RR |
932 | void MyFrame::OnDeleteYear( wxCommandEvent& WXUNUSED(event) ) |
933 | { | |
934 | m_musicCtrl->DeleteColumn( m_musicCtrl->GetColumn( 2 ) ); | |
935 | FindWindow( ID_DELETE_YEAR )->Disable(); | |
936 | } | |
937 | ||
c534e696 | 938 | void MyFrame::OnPrependList( wxCommandEvent& WXUNUSED(event) ) |
e63807a8 | 939 | { |
99c75ebc | 940 | m_list_model->Prepend(wxT("Test")); |
c534e696 RR |
941 | } |
942 | ||
943 | void MyFrame::OnDeleteList( wxCommandEvent& WXUNUSED(event) ) | |
944 | { | |
b7e9f8b1 RR |
945 | wxDataViewItemArray items; |
946 | int len = m_listCtrl->GetSelections( items ); | |
8b6cf9bf RR |
947 | if (len > 0) |
948 | m_list_model->DeleteItems( items ); | |
1e08ad10 RR |
949 | } |
950 | ||
d8331a01 RR |
951 | void MyFrame::OnValueChanged( wxDataViewEvent &event ) |
952 | { | |
953 | if (!m_log) | |
954 | return; | |
955 | ||
99c75ebc | 956 | wxLogMessage( wxT("EVT_DATAVIEW_ITEM_VALUE_CHANGED, Item Id: %d; Column: %d"), event.GetItem().GetID(), event.GetColumn() ); |
b7e9f8b1 RR |
957 | } |
958 | ||
959 | void MyFrame::OnActivated( wxDataViewEvent &event ) | |
960 | { | |
961 | if(!m_log) | |
962 | return; | |
963 | ||
d32332aa | 964 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
99c75ebc | 965 | wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item: %s"), title.GetData()); |
b7e9f8b1 RR |
966 | } |
967 | ||
aed836f3 | 968 | void MyFrame::OnSelectionChanged( wxDataViewEvent &event ) |
6848478c RR |
969 | { |
970 | if(!m_log) | |
971 | return; | |
972 | ||
d32332aa RR |
973 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
974 | if (title.empty()) | |
99c75ebc | 975 | title = wxT("None"); |
d32332aa | 976 | |
99c75ebc | 977 | wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, First selected Item: %s"), title.GetData() ); |
6848478c RR |
978 | } |
979 | ||
718fd180 RR |
980 | void MyFrame::OnExpanding( wxDataViewEvent &event ) |
981 | { | |
982 | if (!m_log) | |
983 | return; | |
984 | ||
d32332aa | 985 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
99c75ebc | 986 | wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, Item: %s"), title.GetData() ); |
718fd180 RR |
987 | } |
988 | ||
d14e1c3a RR |
989 | |
990 | void MyFrame::OnEditingStarted( wxDataViewEvent &event ) | |
991 | { | |
992 | if (!m_log) | |
993 | return; | |
994 | ||
d32332aa | 995 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
99c75ebc | 996 | wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, Item: %s"), title.GetData() ); |
d14e1c3a RR |
997 | } |
998 | ||
999 | void MyFrame::OnEditingDone( wxDataViewEvent &event ) | |
1000 | { | |
1001 | if (!m_log) | |
1002 | return; | |
1003 | ||
d32332aa | 1004 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
99c75ebc | 1005 | wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, Item: %s"), title.GetData() ); |
d14e1c3a RR |
1006 | } |
1007 | ||
718fd180 RR |
1008 | void MyFrame::OnExpanded( wxDataViewEvent &event ) |
1009 | { | |
1010 | if (!m_log) | |
1011 | return; | |
1012 | ||
d32332aa | 1013 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
99c75ebc | 1014 | wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, Item: %s"), title.GetData() ); |
718fd180 RR |
1015 | } |
1016 | ||
1017 | void MyFrame::OnCollapsing( wxDataViewEvent &event ) | |
1018 | { | |
1019 | if (!m_log) | |
1020 | return; | |
1021 | ||
d32332aa | 1022 | wxString title = m_music_model->GetTitle( event.GetItem() ); |
99c75ebc | 1023 | wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, Item: %s"), title.GetData() ); |
718fd180 RR |
1024 | } |
1025 | ||
1026 | void MyFrame::OnCollapsed( wxDataViewEvent &event ) | |
1027 | { | |
1028 | if (!m_log) | |
1029 | return; | |
d32332aa RR |
1030 | |
1031 | wxString title = m_music_model->GetTitle( event.GetItem() ); | |
99c75ebc | 1032 | wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, Item: %s"),title.GetData()); |
718fd180 RR |
1033 | } |
1034 | ||
74dea0de RR |
1035 | void MyFrame::OnContextMenu( wxDataViewEvent &event ) |
1036 | { | |
1037 | if (!m_log) | |
1038 | return; | |
1039 | ||
1040 | wxString title = m_music_model->GetTitle( event.GetItem() ); | |
99c75ebc | 1041 | wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s"),title.GetData()); |
0bdfa388 | 1042 | // wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s Value: %s"),title.GetData(), event.GetValue().GetString()); |
74dea0de RR |
1043 | } |
1044 | ||
b7e9f8b1 RR |
1045 | void MyFrame::OnHeaderClick( wxDataViewEvent &event ) |
1046 | { | |
1047 | if(!m_log) | |
1048 | return; | |
aed836f3 RR |
1049 | |
1050 | int pos = m_musicCtrl->GetColumnPosition( event.GetDataViewColumn() ); | |
b7e9f8b1 | 1051 | |
99c75ebc | 1052 | wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, Column position: %d"), pos ); |
b7e9f8b1 RR |
1053 | } |
1054 | ||
1055 | void MyFrame::OnHeaderRightClick( wxDataViewEvent &event ) | |
1056 | { | |
1057 | if(!m_log) | |
1058 | return; | |
1059 | ||
dadc879e RR |
1060 | int pos = m_musicCtrl->GetColumnPosition( event.GetDataViewColumn() ); |
1061 | ||
99c75ebc | 1062 | wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, Column position: %d"), pos ); |
b7e9f8b1 RR |
1063 | } |
1064 | ||
1065 | void MyFrame::OnSorted( wxDataViewEvent &event ) | |
1066 | { | |
1067 | if(!m_log) | |
1068 | return; | |
1069 | ||
d32332aa RR |
1070 | int pos = m_musicCtrl->GetColumnPosition( event.GetDataViewColumn() ); |
1071 | ||
99c75ebc | 1072 | wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, Column position: %d"), pos ); |
b7e9f8b1 RR |
1073 | } |
1074 | ||
1075 | void MyFrame::OnRightClick( wxMouseEvent &event ) | |
1076 | { | |
1077 | if(!m_log) | |
1078 | return; | |
1079 | ||
99c75ebc | 1080 | wxLogMessage(wxT("wxEVT_MOUSE_RIGHT_UP, Click Point is X: %d, Y: %d"), event.GetX(), event.GetY()); |
b7e9f8b1 RR |
1081 | } |
1082 | ||
d5ef211f | 1083 | void MyFrame::OnGoto(wxCommandEvent& WXUNUSED(event)) |
b7e9f8b1 | 1084 | { |
718fd180 | 1085 | wxDataViewItem item = m_list_model->GetItem( 50 ); |
fbda518c | 1086 | m_listCtrl->EnsureVisible(item,m_col); |
d8331a01 RR |
1087 | } |
1088 | ||
8b6cf9bf RR |
1089 | void MyFrame::OnAddMany(wxCommandEvent& WXUNUSED(event)) |
1090 | { | |
1091 | m_list_model->AddMany(); | |
1092 | } | |
1093 | ||
1094 | ||
bd6169a6 RR |
1095 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) |
1096 | { | |
87f0efe2 RR |
1097 | wxAboutDialogInfo info; |
1098 | info.SetName(_("DataView sample")); | |
1099 | info.SetDescription(_("This sample demonstrates the dataview control handling")); | |
1100 | info.SetCopyright(_T("(C) 2007 Robert Roebling")); | |
bd6169a6 | 1101 | |
87f0efe2 | 1102 | wxAboutBox(info); |
bd6169a6 RR |
1103 | } |
1104 |