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