]> git.saurik.com Git - wxWidgets.git/blame - samples/dataview/dataview.cpp
reset deferred position/size if the window was moved immediately (#10073)
[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
77 Title Artist Year
78-------------------------------------------------------------
791: 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
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;
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
135public:
136 wxString m_title;
137 wxString m_artist;
405a351f 138 int m_year;
1c3e52af 139
1e08ad10
RR
140private:
141 MyMusicModelNode *m_parent;
1c3e52af 142 MyMusicModelNodes m_children;
1e08ad10
RR
143 bool m_isContainer;
144};
145
1c3e52af 146
5debbdcf 147class MyMusicModel: public wxDataViewModel
bd6169a6
RR
148{
149public:
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 414private:
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
423static int my_sort_reverse( int *v1, int *v2 )
424{
425 return *v2-*v1;
426}
427
428static int my_sort( int *v1, int *v2 )
429{
430 return *v1-*v2;
431}
432
e39de702 433class MyListModel: public wxDataViewVirtualListModel
c534e696
RR
434{
435public:
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
597class MyCustomRenderer: public wxDataViewCustomRenderer
598{
599public:
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
640private:
641 long m_height;
0bdfa388
RR
642};
643
362d7fb9
RR
644// -------------------------------------
645// MyApp
646// -------------------------------------
bd6169a6
RR
647
648class MyApp: public wxApp
649{
650public:
651 bool OnInit(void);
87f0efe2 652 int OnExit();
bd6169a6
RR
653};
654
362d7fb9
RR
655// -------------------------------------
656// MyFrame
657// -------------------------------------
658
87f0efe2 659class MyFrame : public wxFrame
bd6169a6
RR
660{
661public:
e94d0c1e 662 MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int h);
e39d30c0 663 ~MyFrame();
bd6169a6
RR
664
665public:
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 699private:
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 711private:
abd6692c 712 DECLARE_EVENT_TABLE()
241cb04b
RR
713};
714
362d7fb9
RR
715// -------------------------------------
716// MyApp
717// -------------------------------------
718
87f0efe2 719IMPLEMENT_APP(MyApp)
bd6169a6 720
bd6169a6
RR
721bool 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
735int MyApp::OnExit()
736{
737 return 0;
738}
739
740
bd6169a6
RR
741// -------------------------------------
742// MyFrame
743// -------------------------------------
744
87f0efe2
RR
745enum
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
764BEGIN_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
795END_EVENT_TABLE()
796
e94d0c1e 797MyFrame::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();
bd6169a6 817
1e08ad10
RR
818 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
819
c534e696 820 wxBoxSizer *data_sizer = new wxBoxSizer( wxHORIZONTAL );
bd6169a6 821
c534e696 822 // MyMusic
b910a8ad 823
d8331a01 824 m_musicCtrl = new wxDataViewCtrl( this, ID_MUSIC_CTRL, wxDefaultPosition,
04aac2dd 825 wxSize(400,200), wxDV_MULTIPLE|wxDV_VARIABLE_LINE_HEIGHT );
99c75ebc 826
c534e696
RR
827 m_music_model = new MyMusicModel;
828 m_musicCtrl->AssociateModel( m_music_model.get() );
829
419a3607 830 wxDataViewTextRenderer *tr = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_INERT );
1c3e52af 831 wxDataViewColumn *column0 = new wxDataViewColumn( wxT("title"), tr, 0, 200, wxALIGN_LEFT,
f593b0b9
RR
832 wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
833 m_musicCtrl->AppendColumn( column0 );
1c3e52af 834#if 0
0bd26819 835 // Call this and sorting is enabled
1c3e52af 836 // immediatly upon start up.
f593b0b9 837 column0->SetSortOrder( true );
0bd26819 838#endif
1c3e52af 839
f2b7492a 840 tr = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
04aac2dd 841 wxDataViewColumn *column1 = new wxDataViewColumn( wxT("artist"), tr, 1, 150, wxALIGN_LEFT,
0bdfa388
RR
842 wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
843 m_musicCtrl->AppendColumn( column1 );
844
04aac2dd 845#if 1
a39d7501 846 wxDataViewSpinRenderer *sr = new wxDataViewSpinRenderer( 0, 2010, wxDATAVIEW_CELL_EDITABLE, wxALIGN_RIGHT );
1c3e52af 847 wxDataViewColumn *column2 = new wxDataViewColumn( wxT("year"), sr, 2, 80, wxALIGN_LEFT,
a39d7501
RR
848 wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE );
849 m_musicCtrl->AppendColumn( column2 );
850
fbfecac9
RR
851 m_musicCtrl->AppendProgressColumn( wxT("popularity"), 3, wxDATAVIEW_CELL_INERT, 80 );
852
f593b0b9 853 MyCustomRenderer *cr = new MyCustomRenderer( wxDATAVIEW_CELL_ACTIVATABLE, wxALIGN_RIGHT );
1c3e52af 854 wxDataViewColumn *column3 = new wxDataViewColumn( wxT("custom"), cr, 4, -1, wxALIGN_LEFT,
0bdfa388 855 wxDATAVIEW_COL_RESIZABLE );
a39d7501 856 m_musicCtrl->AppendColumn( column3 );
04aac2dd 857#endif
1e08ad10 858
c534e696 859 data_sizer->Add( m_musicCtrl, 3, wxGROW );
1c3e52af 860
c534e696 861 // MyList
1c3e52af 862
c534e696 863 m_listCtrl = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition,
04aac2dd 864 wxSize(400,200), wxDV_MULTIPLE | wxDV_ROW_LINES);
1c3e52af 865
c534e696
RR
866 m_list_model = new MyListModel;
867 m_listCtrl->AssociateModel( m_list_model.get() );
83087c60
RR
868
869#if 1
0c8ed3eb
RR
870 m_listCtrl->AppendTextColumn (wxT("editable string"), 0, wxDATAVIEW_CELL_EDITABLE, 120 );
871 m_listCtrl->AppendIconTextColumn(wxIcon(small1_xpm), 1, wxDATAVIEW_CELL_INERT )->SetTitle( wxT("icon") );
83087c60
RR
872#else
873 m_listCtrl->AppendTextColumn (wxT("editable string"), 0, wxDATAVIEW_CELL_EDITABLE );
874 m_listCtrl->AppendIconTextColumn(wxT("icon"), 1, wxDATAVIEW_CELL_INERT );
875#endif
876
4264606e 877 wxDataViewTextRendererAttr *ra = new wxDataViewTextRendererAttr;
a39d7501
RR
878 wxDataViewColumn *column4 = new wxDataViewColumn(wxT("attributes"), ra, 2 );
879 m_listCtrl->AppendColumn( column4 );
1c3e52af 880
c534e696 881 data_sizer->Add( m_listCtrl, 2, wxGROW );
1c3e52af 882
c534e696 883 main_sizer->Add( data_sizer, 2, wxGROW );
1c3e52af 884
1e08ad10 885 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
1c3e52af 886
99c75ebc
RR
887 button_sizer->Add( new wxButton( this, ID_ADD_MOZART, _("Add Mozart")), 0, wxALL, 10 );
888 button_sizer->Add( new wxButton( this, ID_DELETE_MUSIC,_("Delete selected")), 0, wxALL, 10 );
889 button_sizer->Add( new wxButton( this, ID_DELETE_YEAR, _("Delete \"Year\" column")), 0, wxALL, 10 );
a400d56b 890 button_sizer->Add( new wxButton( this, ID_SELECT_NINTH, _("Select Ninth")), 0, wxALL, 10 );
c534e696 891 button_sizer->Add( 10, 10, 1 );
8b6cf9bf 892 wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 2 );
99c75ebc
RR
893 grid_sizer->Add( new wxButton( this, ID_PREPEND_LIST,_("Prepend")), 0, wxALL, 2 );
894 grid_sizer->Add( new wxButton( this, ID_DELETE_LIST, _("Delete selected")), 0, wxALL, 2 );
895 grid_sizer->Add( new wxButton( this, ID_GOTO, _("Goto 50")), 0, wxALL, 2 );
896 grid_sizer->Add( new wxButton( this, ID_ADD_MANY, _("Add 1000")), 0, wxALL, 2 );
8b6cf9bf 897 button_sizer->Add( grid_sizer, 0, wxALL, 10 );
1c3e52af 898
c534e696 899 main_sizer->Add( button_sizer, 0, wxGROW, 0 );
a75124d0
RR
900
901 wxBoxSizer *bottom_sizer = new wxBoxSizer( wxHORIZONTAL );
1c3e52af 902
ad386793 903 m_log = new wxTextCtrl( this, -1, wxString(), wxDefaultPosition, wxSize(100,200), wxTE_MULTILINE );
b7e9f8b1 904 m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_log));
99c75ebc 905 wxLogMessage(_("This is the log window"));
b7e9f8b1 906
a75124d0 907 bottom_sizer->Add( m_log, 1, wxGROW );
1c3e52af 908
04aac2dd 909#if 1
a75124d0 910 // wxDataViewTreeStore
e94d0c1e 911
1c3e52af 912 wxDataViewCtrl *treectrl = new wxDataViewCtrl( this, -1,
ad386793 913 wxDefaultPosition, wxSize(100,200), wxDV_NO_HEADER );
1c3e52af 914
e94d0c1e 915 wxDataViewTreeStore *store = new wxDataViewTreeStore;
99c75ebc
RR
916 wxDataViewItem parent = store->AppendContainer( wxDataViewItem(0),wxT("Root 1"), wxIcon(small1_xpm) );
917 wxDataViewItem child = store->AppendItem( parent,wxT("Child 1"), wxIcon(small1_xpm) );
918 child = store->AppendItem( parent,wxT("Child 2"), wxIcon(small1_xpm) );
ad386793 919 child = store->AppendItem( parent,wxT("Child 3, very long, long, long, long"), wxIcon(small1_xpm) );
e94d0c1e 920 treectrl->AssociateModel( store );
e94d0c1e 921 store->DecRef();
b89cac3f 922
1c3e52af 923 treectrl->AppendIconTextColumn( wxT("no label"), 0, wxDATAVIEW_CELL_INERT, -1, (wxAlignment) 0,
0bdfa388 924 wxDATAVIEW_COL_RESIZABLE );
672e58d9 925
ad386793 926 bottom_sizer->Add( treectrl, 1 );
672e58d9 927
a75124d0
RR
928 // wxDataViewTreeCtrl
929
ad386793 930 wxDataViewTreeCtrl *treectrl2 = new wxDataViewTreeCtrl( this, -1, wxDefaultPosition, wxSize(100,200) );
1c3e52af 931
75a2e426 932 wxImageList *ilist = new wxImageList( 16, 16 );
a75124d0 933 ilist->Add( wxIcon(small1_xpm) );
83aa1cf4 934 treectrl2->SetImageList( ilist );
1c3e52af 935
99c75ebc
RR
936 parent = treectrl2->AppendContainer( wxDataViewItem(0),wxT("Root 1"), 0 );
937 child = treectrl2->AppendItem( parent,wxT("Child 1"), 0 );
938 child = treectrl2->AppendItem( parent,wxT("Child 2"), 0 );
ad386793 939 child = treectrl2->AppendItem( parent,wxT("Child 3, very long, long, long, long"), 0 );
e39d30c0 940
ad386793 941 bottom_sizer->Add( treectrl2, 1 );
04aac2dd 942#endif
1c3e52af 943
a75124d0 944 // main sizer
1c3e52af 945
a75124d0 946 main_sizer->Add( bottom_sizer, 0, wxGROW );
1c3e52af 947
a75124d0
RR
948 SetSizer( main_sizer );
949}
950
e39d30c0
RR
951MyFrame::~MyFrame()
952{
953 delete wxLog::SetActiveTarget(m_logOld);
954}
955
a75124d0
RR
956void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
957{
958 Close(true);
e94d0c1e
RR
959}
960
c534e696
RR
961void MyFrame::OnAddMozart(wxCommandEvent& WXUNUSED(event) )
962{
99c75ebc 963 m_music_model->AddToClassical( wxT("Kleine Nachtmusik"), wxT("Wolfgang Mozart"), 1787 );
c534e696
RR
964}
965
966void MyFrame::OnDeleteMusic(wxCommandEvent& WXUNUSED(event) )
1e08ad10 967{
b7e9f8b1
RR
968 wxDataViewItemArray items;
969 int len = m_musicCtrl->GetSelections( items );
970 for( int i = 0; i < len; i ++ )
971 if (items[i].IsOk())
972 m_music_model->Delete( items[i] );
e63807a8
RR
973}
974
736fe67c
RR
975void MyFrame::OnDeleteYear( wxCommandEvent& WXUNUSED(event) )
976{
977 m_musicCtrl->DeleteColumn( m_musicCtrl->GetColumn( 2 ) );
978 FindWindow( ID_DELETE_YEAR )->Disable();
979}
980
a400d56b
RR
981void MyFrame::OnSelectNinth( wxCommandEvent& WXUNUSED(event) )
982{
983 m_musicCtrl->Select( m_music_model->GetNinthItem() );
984}
985
c534e696 986void MyFrame::OnPrependList( wxCommandEvent& WXUNUSED(event) )
e63807a8 987{
99c75ebc 988 m_list_model->Prepend(wxT("Test"));
c534e696
RR
989}
990
991void MyFrame::OnDeleteList( wxCommandEvent& WXUNUSED(event) )
992{
b7e9f8b1
RR
993 wxDataViewItemArray items;
994 int len = m_listCtrl->GetSelections( items );
8b6cf9bf
RR
995 if (len > 0)
996 m_list_model->DeleteItems( items );
1e08ad10
RR
997}
998
d8331a01
RR
999void MyFrame::OnValueChanged( wxDataViewEvent &event )
1000{
1001 if (!m_log)
1002 return;
1c3e52af 1003
99c75ebc 1004 wxLogMessage( wxT("EVT_DATAVIEW_ITEM_VALUE_CHANGED, Item Id: %d; Column: %d"), event.GetItem().GetID(), event.GetColumn() );
b7e9f8b1
RR
1005}
1006
1007void MyFrame::OnActivated( wxDataViewEvent &event )
1008{
1009 if(!m_log)
1010 return;
1011
d32332aa 1012 wxString title = m_music_model->GetTitle( event.GetItem() );
99c75ebc 1013 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item: %s"), title.GetData());
b7e9f8b1
RR
1014}
1015
aed836f3 1016void MyFrame::OnSelectionChanged( wxDataViewEvent &event )
6848478c
RR
1017{
1018 if(!m_log)
1019 return;
1020
d32332aa
RR
1021 wxString title = m_music_model->GetTitle( event.GetItem() );
1022 if (title.empty())
99c75ebc 1023 title = wxT("None");
1c3e52af 1024
99c75ebc 1025 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, First selected Item: %s"), title.GetData() );
6848478c
RR
1026}
1027
718fd180
RR
1028void MyFrame::OnExpanding( wxDataViewEvent &event )
1029{
1030 if (!m_log)
1031 return;
1c3e52af 1032
d32332aa 1033 wxString title = m_music_model->GetTitle( event.GetItem() );
99c75ebc 1034 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, Item: %s"), title.GetData() );
718fd180
RR
1035}
1036
d14e1c3a
RR
1037
1038void MyFrame::OnEditingStarted( wxDataViewEvent &event )
1039{
1040 if (!m_log)
1041 return;
1c3e52af 1042
d32332aa 1043 wxString title = m_music_model->GetTitle( event.GetItem() );
99c75ebc 1044 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, Item: %s"), title.GetData() );
d14e1c3a
RR
1045}
1046
1047void MyFrame::OnEditingDone( wxDataViewEvent &event )
1048{
1049 if (!m_log)
1050 return;
1c3e52af 1051
d32332aa 1052 wxString title = m_music_model->GetTitle( event.GetItem() );
99c75ebc 1053 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, Item: %s"), title.GetData() );
d14e1c3a
RR
1054}
1055
718fd180
RR
1056void MyFrame::OnExpanded( wxDataViewEvent &event )
1057{
1058 if (!m_log)
1059 return;
1c3e52af 1060
d32332aa 1061 wxString title = m_music_model->GetTitle( event.GetItem() );
99c75ebc 1062 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, Item: %s"), title.GetData() );
718fd180
RR
1063}
1064
1065void MyFrame::OnCollapsing( wxDataViewEvent &event )
1066{
1067 if (!m_log)
1068 return;
1c3e52af 1069
d32332aa 1070 wxString title = m_music_model->GetTitle( event.GetItem() );
99c75ebc 1071 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, Item: %s"), title.GetData() );
718fd180
RR
1072}
1073
1074void MyFrame::OnCollapsed( wxDataViewEvent &event )
1075{
1076 if (!m_log)
1077 return;
1c3e52af 1078
d32332aa 1079 wxString title = m_music_model->GetTitle( event.GetItem() );
99c75ebc 1080 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, Item: %s"),title.GetData());
718fd180
RR
1081}
1082
74dea0de
RR
1083void MyFrame::OnContextMenu( wxDataViewEvent &event )
1084{
1085 if (!m_log)
1086 return;
1c3e52af 1087
74dea0de 1088 wxString title = m_music_model->GetTitle( event.GetItem() );
99c75ebc 1089 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s"),title.GetData());
1c3e52af
VZ
1090
1091 wxMenu menu;
1092 menu.Append( 1, wxT("entry 1") );
1093 menu.Append( 2, wxT("entry 2") );
1094 menu.Append( 3, wxT("entry 3") );
1095
1096 m_musicCtrl->PopupMenu(&menu);
1097
0bdfa388 1098// wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, Item: %s Value: %s"),title.GetData(), event.GetValue().GetString());
74dea0de
RR
1099}
1100
b7e9f8b1
RR
1101void MyFrame::OnHeaderClick( wxDataViewEvent &event )
1102{
1103 if(!m_log)
1104 return;
1c3e52af 1105
aed836f3 1106 int pos = m_musicCtrl->GetColumnPosition( event.GetDataViewColumn() );
b7e9f8b1 1107
99c75ebc 1108 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, Column position: %d"), pos );
b7e9f8b1
RR
1109}
1110
1111void MyFrame::OnHeaderRightClick( wxDataViewEvent &event )
1112{
1113 if(!m_log)
1114 return;
1115
dadc879e
RR
1116 int pos = m_musicCtrl->GetColumnPosition( event.GetDataViewColumn() );
1117
99c75ebc 1118 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, Column position: %d"), pos );
b7e9f8b1
RR
1119}
1120
1121void MyFrame::OnSorted( wxDataViewEvent &event )
1122{
1123 if(!m_log)
1124 return;
1125
d32332aa
RR
1126 int pos = m_musicCtrl->GetColumnPosition( event.GetDataViewColumn() );
1127
99c75ebc 1128 wxLogMessage(wxT("wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, Column position: %d"), pos );
b7e9f8b1
RR
1129}
1130
1131void MyFrame::OnRightClick( wxMouseEvent &event )
1132{
1133 if(!m_log)
1134 return;
1135
99c75ebc 1136 wxLogMessage(wxT("wxEVT_MOUSE_RIGHT_UP, Click Point is X: %d, Y: %d"), event.GetX(), event.GetY());
b7e9f8b1
RR
1137}
1138
d5ef211f 1139void MyFrame::OnGoto(wxCommandEvent& WXUNUSED(event))
b7e9f8b1 1140{
718fd180 1141 wxDataViewItem item = m_list_model->GetItem( 50 );
fbda518c 1142 m_listCtrl->EnsureVisible(item,m_col);
d8331a01
RR
1143}
1144
8b6cf9bf
RR
1145void MyFrame::OnAddMany(wxCommandEvent& WXUNUSED(event))
1146{
1147 m_list_model->AddMany();
1148}
1149
1150
bd6169a6
RR
1151void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
1152{
87f0efe2
RR
1153 wxAboutDialogInfo info;
1154 info.SetName(_("DataView sample"));
1155 info.SetDescription(_("This sample demonstrates the dataview control handling"));
1156 info.SetCopyright(_T("(C) 2007 Robert Roebling"));
bd6169a6 1157
87f0efe2 1158 wxAboutBox(info);
bd6169a6
RR
1159}
1160