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