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