]>
Commit | Line | Data |
---|---|---|
239eaa41 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/common/datavcmn.cpp | |
3 | // Purpose: wxDataViewCtrl base classes and common parts | |
4 | // Author: Robert Roebling | |
5 | // Created: 2006/02/20 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2006, Robert Roebling | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // For compilers that support precompilation, includes "wx.h". | |
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
8045736e RR |
18 | #if wxUSE_DATAVIEWCTRL |
19 | ||
e7445ff8 | 20 | #include "wx/dataview.h" |
52e750fc | 21 | #include "wx/spinctrl.h" |
7448d67c | 22 | #include "wx/choice.h" |
52e750fc | 23 | |
c232dfe5 RR |
24 | #include "wx/weakref.h" |
25 | ||
f554a14b | 26 | #ifndef WX_PRECOMP |
c3c62822 PC |
27 | #include "wx/dc.h" |
28 | #include "wx/settings.h" | |
f554a14b | 29 | #include "wx/log.h" |
e94d0c1e | 30 | #include "wx/icon.h" |
c3c62822 | 31 | #include "wx/crt.h" |
f554a14b WS |
32 | #endif |
33 | ||
23318a53 | 34 | const char wxDataViewCtrlNameStr[] = "dataviewCtrl"; |
239eaa41 | 35 | |
239eaa41 | 36 | |
d5025dc0 RR |
37 | bool operator == (const wxDataViewItem &left, const wxDataViewItem &right) |
38 | { | |
39 | return (left.GetID() == right.GetID() ); | |
40 | } | |
41 | ||
c3c62822 PC |
42 | #ifdef __WXDEBUG__ |
43 | void wxDataViewItem::Print(const wxString& text) const | |
44 | { | |
e913be34 | 45 | wxPrintf(wxT("item %s: %lu\n"), text.GetData(), wxPtrToUInt(m_id)); |
c3c62822 PC |
46 | } |
47 | #endif | |
d5025dc0 | 48 | |
f554a14b | 49 | // --------------------------------------------------------- |
854cdb09 | 50 | // wxDataViewModelNotifier |
f554a14b | 51 | // --------------------------------------------------------- |
239eaa41 | 52 | |
8ab03001 | 53 | #include "wx/listimpl.cpp" |
a76c2f37 | 54 | WX_DEFINE_LIST(wxDataViewModelNotifiers) |
9d8fe14a | 55 | |
854cdb09 RR |
56 | bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items ) |
57 | { | |
58 | size_t count = items.GetCount(); | |
59 | size_t i; | |
60 | for (i = 0; i < count; i++) | |
61 | if (!ItemAdded( parent, items[i] )) return false; | |
b5ec7dd6 | 62 | |
854cdb09 RR |
63 | return true; |
64 | } | |
65 | ||
66 | bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items ) | |
67 | { | |
68 | size_t count = items.GetCount(); | |
69 | size_t i; | |
70 | for (i = 0; i < count; i++) | |
71 | if (!ItemDeleted( parent, items[i] )) return false; | |
b5ec7dd6 | 72 | |
854cdb09 RR |
73 | return true; |
74 | } | |
75 | ||
76 | bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray &items ) | |
77 | { | |
78 | size_t count = items.GetCount(); | |
79 | size_t i; | |
80 | for (i = 0; i < count; i++) | |
81 | if (!ItemChanged( items[i] )) return false; | |
b5ec7dd6 | 82 | |
854cdb09 RR |
83 | return true; |
84 | } | |
85 | ||
86 | // --------------------------------------------------------- | |
87 | // wxDataViewModel | |
88 | // --------------------------------------------------------- | |
89 | ||
e0062c04 | 90 | wxDataViewModel::wxDataViewModel() |
239eaa41 | 91 | { |
8f850e28 | 92 | m_notifiers.DeleteContents( true ); |
239eaa41 RR |
93 | } |
94 | ||
e0062c04 | 95 | bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) |
239eaa41 | 96 | { |
8f850e28 RR |
97 | bool ret = true; |
98 | ||
9d8fe14a RR |
99 | wxDataViewModelNotifiers::iterator iter; |
100 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
8f850e28 | 101 | { |
9d8fe14a | 102 | wxDataViewModelNotifier* notifier = *iter; |
e0062c04 | 103 | if (!notifier->ItemAdded( parent, item )) |
8f850e28 | 104 | ret = false; |
8f850e28 | 105 | } |
f554a14b | 106 | |
8f850e28 | 107 | return ret; |
239eaa41 RR |
108 | } |
109 | ||
469d3e9b | 110 | bool wxDataViewModel::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) |
239eaa41 | 111 | { |
8f850e28 RR |
112 | bool ret = true; |
113 | ||
9d8fe14a RR |
114 | wxDataViewModelNotifiers::iterator iter; |
115 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
8f850e28 | 116 | { |
9d8fe14a | 117 | wxDataViewModelNotifier* notifier = *iter; |
469d3e9b | 118 | if (!notifier->ItemDeleted( parent, item )) |
8f850e28 | 119 | ret = false; |
8f850e28 | 120 | } |
f554a14b | 121 | |
8f850e28 | 122 | return ret; |
239eaa41 RR |
123 | } |
124 | ||
e0062c04 | 125 | bool wxDataViewModel::ItemChanged( const wxDataViewItem &item ) |
239eaa41 | 126 | { |
8f850e28 RR |
127 | bool ret = true; |
128 | ||
9d8fe14a RR |
129 | wxDataViewModelNotifiers::iterator iter; |
130 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
8f850e28 | 131 | { |
9d8fe14a | 132 | wxDataViewModelNotifier* notifier = *iter; |
e0062c04 | 133 | if (!notifier->ItemChanged( item )) |
8f850e28 | 134 | ret = false; |
8f850e28 | 135 | } |
f554a14b | 136 | |
8f850e28 | 137 | return ret; |
239eaa41 RR |
138 | } |
139 | ||
854cdb09 RR |
140 | bool wxDataViewModel::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items ) |
141 | { | |
142 | bool ret = true; | |
143 | ||
144 | wxDataViewModelNotifiers::iterator iter; | |
145 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
146 | { | |
147 | wxDataViewModelNotifier* notifier = *iter; | |
148 | if (!notifier->ItemsAdded( parent, items )) | |
149 | ret = false; | |
150 | } | |
151 | ||
152 | return ret; | |
153 | } | |
154 | ||
155 | bool wxDataViewModel::ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items ) | |
156 | { | |
157 | bool ret = true; | |
158 | ||
159 | wxDataViewModelNotifiers::iterator iter; | |
160 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
161 | { | |
162 | wxDataViewModelNotifier* notifier = *iter; | |
163 | if (!notifier->ItemsDeleted( parent, items )) | |
164 | ret = false; | |
165 | } | |
166 | ||
167 | return ret; | |
168 | } | |
169 | ||
170 | bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray &items ) | |
171 | { | |
172 | bool ret = true; | |
173 | ||
174 | wxDataViewModelNotifiers::iterator iter; | |
175 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
176 | { | |
177 | wxDataViewModelNotifier* notifier = *iter; | |
178 | if (!notifier->ItemsChanged( items )) | |
179 | ret = false; | |
180 | } | |
181 | ||
182 | return ret; | |
183 | } | |
184 | ||
e0062c04 | 185 | bool wxDataViewModel::ValueChanged( const wxDataViewItem &item, unsigned int col ) |
239eaa41 | 186 | { |
8f850e28 | 187 | bool ret = true; |
b5d777c7 | 188 | |
9d8fe14a RR |
189 | wxDataViewModelNotifiers::iterator iter; |
190 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
b5d777c7 | 191 | { |
9d8fe14a | 192 | wxDataViewModelNotifier* notifier = *iter; |
e0062c04 | 193 | if (!notifier->ValueChanged( item, col )) |
8f850e28 | 194 | ret = false; |
b5d777c7 | 195 | } |
f554a14b | 196 | |
b5d777c7 | 197 | return ret; |
239eaa41 RR |
198 | } |
199 | ||
e0062c04 | 200 | bool wxDataViewModel::Cleared() |
4eccd3a1 RR |
201 | { |
202 | bool ret = true; | |
203 | ||
9d8fe14a RR |
204 | wxDataViewModelNotifiers::iterator iter; |
205 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
4eccd3a1 | 206 | { |
9d8fe14a | 207 | wxDataViewModelNotifier* notifier = *iter; |
8f850e28 RR |
208 | if (!notifier->Cleared()) |
209 | ret = false; | |
8f850e28 | 210 | } |
f554a14b | 211 | |
8f850e28 | 212 | return ret; |
239eaa41 RR |
213 | } |
214 | ||
ef427989 RR |
215 | void wxDataViewModel::Resort() |
216 | { | |
9d8fe14a RR |
217 | wxDataViewModelNotifiers::iterator iter; |
218 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
ef427989 | 219 | { |
9d8fe14a | 220 | wxDataViewModelNotifier* notifier = *iter; |
ef427989 | 221 | notifier->Resort(); |
ef427989 RR |
222 | } |
223 | } | |
224 | ||
e0062c04 | 225 | void wxDataViewModel::AddNotifier( wxDataViewModelNotifier *notifier ) |
239eaa41 | 226 | { |
9d8fe14a | 227 | m_notifiers.push_back( notifier ); |
8f850e28 | 228 | notifier->SetOwner( this ); |
239eaa41 RR |
229 | } |
230 | ||
e0062c04 | 231 | void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier ) |
239eaa41 | 232 | { |
8f850e28 | 233 | m_notifiers.DeleteObject( notifier ); |
239eaa41 RR |
234 | } |
235 | ||
7ee7191c RR |
236 | int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, |
237 | unsigned int column, bool ascending ) | |
ef427989 | 238 | { |
cf283a47 | 239 | // sort branches before leaves |
ed903e42 RR |
240 | bool item1_is_container = IsContainer(item1); |
241 | bool item2_is_container = IsContainer(item2); | |
900af470 | 242 | |
ed903e42 | 243 | if (item1_is_container && !item2_is_container) |
cf283a47 | 244 | return 1; |
ed903e42 | 245 | if (item2_is_container && !item1_is_container) |
cf283a47 | 246 | return -1; |
900af470 | 247 | |
ef427989 | 248 | wxVariant value1,value2; |
7ee7191c RR |
249 | GetValue( value1, item1, column ); |
250 | GetValue( value2, item2, column ); | |
251 | ||
252 | if (!ascending) | |
253 | { | |
254 | wxVariant temp = value1; | |
255 | value1 = value2; | |
256 | value2 = temp; | |
257 | } | |
cf283a47 | 258 | |
ef427989 RR |
259 | if (value1.GetType() == wxT("string")) |
260 | { | |
261 | wxString str1 = value1.GetString(); | |
262 | wxString str2 = value2.GetString(); | |
0be79c8a | 263 | int res = str1.Cmp( str2 ); |
777f9cef VZ |
264 | if (res) |
265 | return res; | |
266 | } | |
267 | else if (value1.GetType() == wxT("long")) | |
ef427989 RR |
268 | { |
269 | long l1 = value1.GetLong(); | |
270 | long l2 = value2.GetLong(); | |
cf283a47 | 271 | long res = l1-l2; |
777f9cef VZ |
272 | if (res) |
273 | return res; | |
274 | } | |
275 | else if (value1.GetType() == wxT("double")) | |
ef427989 RR |
276 | { |
277 | double d1 = value1.GetDouble(); | |
278 | double d2 = value2.GetDouble(); | |
777f9cef VZ |
279 | if (d1 < d2) |
280 | return 1; | |
281 | if (d1 > d2) | |
282 | return -1; | |
283 | } | |
284 | else if (value1.GetType() == wxT("datetime")) | |
ef427989 RR |
285 | { |
286 | wxDateTime dt1 = value1.GetDateTime(); | |
287 | wxDateTime dt2 = value2.GetDateTime(); | |
777f9cef VZ |
288 | if (dt1.IsEarlierThan(dt2)) |
289 | return 1; | |
290 | if (dt2.IsEarlierThan(dt1)) | |
291 | return -11; | |
ef427989 RR |
292 | } |
293 | ||
cf283a47 | 294 | // items must be different |
777f9cef VZ |
295 | wxUIntPtr id1 = wxPtrToUInt(item1.GetID()), |
296 | id2 = wxPtrToUInt(item2.GetID()); | |
b7fe2261 | 297 | |
777f9cef | 298 | return ascending ? id1 - id2 : id2 - id1; |
ef427989 RR |
299 | } |
300 | ||
c534e696 RR |
301 | // --------------------------------------------------------- |
302 | // wxDataViewIndexListModel | |
303 | // --------------------------------------------------------- | |
304 | ||
e39de702 | 305 | static int my_sort( int *v1, int *v2 ) |
c534e696 | 306 | { |
e39de702 RR |
307 | return *v2-*v1; |
308 | } | |
517166e6 | 309 | |
e39de702 RR |
310 | |
311 | wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size ) | |
312 | { | |
313 | // IDs are ordered until an item gets deleted or inserted | |
314 | m_ordered = true; | |
777f9cef | 315 | |
e39de702 RR |
316 | // build initial index |
317 | unsigned int i; | |
318 | for (i = 1; i < initial_size+1; i++) | |
777f9cef | 319 | m_hash.Add( wxUIntToPtr(i) ); |
e39de702 | 320 | m_lastIndex = initial_size + 1; |
c534e696 RR |
321 | } |
322 | ||
323 | wxDataViewIndexListModel::~wxDataViewIndexListModel() | |
324 | { | |
325 | } | |
326 | ||
33ba5a05 RR |
327 | void wxDataViewIndexListModel::Reset( unsigned int new_size ) |
328 | { | |
e39de702 | 329 | m_hash.Clear(); |
777f9cef | 330 | |
e39de702 RR |
331 | // IDs are ordered until an item gets deleted or inserted |
332 | m_ordered = true; | |
777f9cef | 333 | |
e39de702 RR |
334 | // build initial index |
335 | unsigned int i; | |
336 | for (i = 1; i < new_size+1; i++) | |
777f9cef | 337 | m_hash.Add( wxUIntToPtr(i) ); |
e39de702 | 338 | m_lastIndex = new_size + 1; |
777f9cef | 339 | |
33ba5a05 RR |
340 | wxDataViewModel::Cleared(); |
341 | } | |
342 | ||
c534e696 RR |
343 | void wxDataViewIndexListModel::RowPrepended() |
344 | { | |
e39de702 | 345 | m_ordered = false; |
777f9cef | 346 | |
e39de702 | 347 | unsigned int id = m_lastIndex++; |
777f9cef VZ |
348 | m_hash.Insert( wxUIntToPtr(id), 0 ); |
349 | wxDataViewItem item( wxUIntToPtr(id) ); | |
e39de702 | 350 | ItemAdded( wxDataViewItem(0), item ); |
c534e696 RR |
351 | } |
352 | ||
353 | void wxDataViewIndexListModel::RowInserted( unsigned int before ) | |
354 | { | |
e39de702 | 355 | m_ordered = false; |
777f9cef | 356 | |
e39de702 | 357 | unsigned int id = m_lastIndex++; |
777f9cef VZ |
358 | m_hash.Insert( wxUIntToPtr(id), before ); |
359 | wxDataViewItem item( wxUIntToPtr(id) ); | |
e39de702 | 360 | ItemAdded( wxDataViewItem(0), item ); |
c534e696 RR |
361 | } |
362 | ||
363 | void wxDataViewIndexListModel::RowAppended() | |
364 | { | |
e39de702 | 365 | unsigned int id = m_lastIndex++; |
777f9cef VZ |
366 | m_hash.Add( wxUIntToPtr(id) ); |
367 | wxDataViewItem item( wxUIntToPtr(id) ); | |
e39de702 | 368 | ItemAdded( wxDataViewItem(0), item ); |
c534e696 RR |
369 | } |
370 | ||
371 | void wxDataViewIndexListModel::RowDeleted( unsigned int row ) | |
372 | { | |
e39de702 | 373 | m_ordered = false; |
777f9cef | 374 | |
e39de702 RR |
375 | wxDataViewItem item( m_hash[row] ); |
376 | wxDataViewModel::ItemDeleted( wxDataViewItem(0), item ); | |
377 | m_hash.RemoveAt( row ); | |
8b6cf9bf RR |
378 | } |
379 | ||
380 | void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt &rows ) | |
381 | { | |
382 | wxArrayInt sorted = rows; | |
383 | sorted.Sort( my_sort ); | |
777f9cef | 384 | |
e39de702 | 385 | m_ordered = false; |
777f9cef | 386 | |
e39de702 RR |
387 | wxDataViewItemArray array; |
388 | unsigned int i; | |
389 | for (i = 0; i < rows.GetCount(); i++) | |
390 | { | |
8b6cf9bf RR |
391 | wxDataViewItem item( m_hash[rows[i]] ); |
392 | array.Add( item ); | |
e39de702 RR |
393 | } |
394 | wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array ); | |
777f9cef | 395 | |
e39de702 | 396 | for (i = 0; i < sorted.GetCount(); i++) |
8b6cf9bf | 397 | m_hash.RemoveAt( sorted[i] ); |
8b6cf9bf RR |
398 | } |
399 | ||
c534e696 RR |
400 | void wxDataViewIndexListModel::RowChanged( unsigned int row ) |
401 | { | |
402 | wxDataViewModel::ItemChanged( GetItem(row) ); | |
403 | } | |
404 | ||
405 | void wxDataViewIndexListModel::RowValueChanged( unsigned int row, unsigned int col ) | |
406 | { | |
407 | wxDataViewModel::ValueChanged( GetItem(row), col ); | |
408 | } | |
409 | ||
410 | unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const | |
411 | { | |
e39de702 | 412 | if (m_ordered) |
517166e6 | 413 | { |
2056dede RR |
414 | unsigned int pos = wxPtrToUInt( item.GetID() ); |
415 | return pos-1; | |
2056dede | 416 | } |
777f9cef | 417 | |
e39de702 RR |
418 | // assert for not found |
419 | return (unsigned int) m_hash.Index( item.GetID() ); | |
c534e696 RR |
420 | } |
421 | ||
422 | wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const | |
423 | { | |
e39de702 RR |
424 | wxASSERT( row < m_hash.GetCount() ); |
425 | return wxDataViewItem( m_hash[row] ); | |
c534e696 RR |
426 | } |
427 | ||
517166e6 | 428 | bool wxDataViewIndexListModel::HasDefaultCompare() const |
777f9cef | 429 | { |
517166e6 RR |
430 | return !m_ordered; |
431 | } | |
432 | ||
b7fe2261 VZ |
433 | int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1, |
434 | const wxDataViewItem& item2, | |
435 | unsigned int WXUNUSED(column), | |
436 | bool ascending) | |
c534e696 | 437 | { |
e39de702 | 438 | if (m_ordered) |
517166e6 | 439 | { |
ec935ba8 PC |
440 | unsigned int pos1 = wxPtrToUInt(item1.GetID()); |
441 | unsigned int pos2 = wxPtrToUInt(item2.GetID()); | |
777f9cef | 442 | |
517166e6 RR |
443 | if (ascending) |
444 | return pos1 - pos2; | |
777f9cef | 445 | else |
517166e6 RR |
446 | return pos2 - pos1; |
447 | } | |
777f9cef | 448 | |
7ee7191c RR |
449 | if (ascending) |
450 | return GetRow(item1) - GetRow(item2); | |
b7fe2261 | 451 | |
7ee7191c | 452 | return GetRow(item2) - GetRow(item1); |
c534e696 RR |
453 | } |
454 | ||
900af470 | 455 | void wxDataViewIndexListModel::GetValue( wxVariant &variant, |
c534e696 RR |
456 | const wxDataViewItem &item, unsigned int col ) const |
457 | { | |
900af470 | 458 | GetValue( variant, GetRow(item), col ); |
c534e696 RR |
459 | } |
460 | ||
900af470 | 461 | bool wxDataViewIndexListModel::SetValue( const wxVariant &variant, |
c534e696 RR |
462 | const wxDataViewItem &item, unsigned int col ) |
463 | { | |
464 | return SetValue( variant, GetRow(item), col ); | |
465 | } | |
466 | ||
4264606e RR |
467 | bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr ) |
468 | { | |
469 | return GetAttr( GetRow(item), col, attr ); | |
470 | } | |
471 | ||
900af470 | 472 | wxDataViewItem wxDataViewIndexListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const |
c534e696 RR |
473 | { |
474 | return wxDataViewItem(0); | |
475 | } | |
476 | ||
477 | bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem &item ) const | |
478 | { | |
479 | // only the invisible root item has children | |
480 | if (!item.IsOk()) | |
481 | return true; | |
900af470 | 482 | |
c534e696 RR |
483 | return false; |
484 | } | |
485 | ||
74fe973b | 486 | unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const |
c534e696 | 487 | { |
74fe973b RR |
488 | if (item.IsOk()) |
489 | return 0; | |
c534e696 | 490 | |
74fe973b | 491 | children = m_hash; |
777f9cef | 492 | |
74fe973b | 493 | return m_hash.GetCount(); |
c534e696 RR |
494 | } |
495 | ||
e39de702 RR |
496 | // --------------------------------------------------------- |
497 | // wxDataViewVirtualListModel | |
498 | // --------------------------------------------------------- | |
499 | ||
500 | #ifndef __WXMAC__ | |
501 | ||
502 | wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size ) | |
503 | { | |
504 | m_lastIndex = initial_size-1; | |
505 | } | |
506 | ||
507 | wxDataViewVirtualListModel::~wxDataViewVirtualListModel() | |
508 | { | |
509 | } | |
510 | ||
511 | void wxDataViewVirtualListModel::Reset( unsigned int new_size ) | |
512 | { | |
513 | m_lastIndex = new_size-1; | |
777f9cef | 514 | |
e39de702 RR |
515 | wxDataViewModel::Cleared(); |
516 | } | |
517 | ||
518 | void wxDataViewVirtualListModel::RowPrepended() | |
519 | { | |
520 | m_lastIndex++; | |
777f9cef | 521 | wxDataViewItem item( NULL ); |
e39de702 RR |
522 | ItemAdded( wxDataViewItem(0), item ); |
523 | } | |
524 | ||
525 | void wxDataViewVirtualListModel::RowInserted( unsigned int before ) | |
526 | { | |
527 | m_lastIndex++; | |
777f9cef | 528 | wxDataViewItem item( wxUIntToPtr(before) ); |
e39de702 RR |
529 | ItemAdded( wxDataViewItem(0), item ); |
530 | } | |
531 | ||
532 | void wxDataViewVirtualListModel::RowAppended() | |
533 | { | |
534 | m_lastIndex++; | |
777f9cef | 535 | wxDataViewItem item( wxUIntToPtr(m_lastIndex) ); |
e39de702 RR |
536 | ItemAdded( wxDataViewItem(0), item ); |
537 | } | |
538 | ||
539 | void wxDataViewVirtualListModel::RowDeleted( unsigned int row ) | |
540 | { | |
777f9cef | 541 | wxDataViewItem item( wxUIntToPtr(row) ); |
e39de702 RR |
542 | wxDataViewModel::ItemDeleted( wxDataViewItem(0), item ); |
543 | m_lastIndex++; | |
544 | } | |
545 | ||
546 | void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows ) | |
547 | { | |
548 | wxArrayInt sorted = rows; | |
549 | sorted.Sort( my_sort ); | |
777f9cef | 550 | |
e39de702 RR |
551 | wxDataViewItemArray array; |
552 | unsigned int i; | |
553 | for (i = 0; i < sorted.GetCount(); i++) | |
554 | { | |
777f9cef | 555 | wxDataViewItem item( wxUIntToPtr(sorted[i]) ); |
e39de702 RR |
556 | array.Add( item ); |
557 | } | |
558 | wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array ); | |
777f9cef | 559 | |
e39de702 RR |
560 | m_lastIndex -= rows.GetCount(); |
561 | } | |
562 | ||
563 | void wxDataViewVirtualListModel::RowChanged( unsigned int row ) | |
564 | { | |
565 | wxDataViewModel::ItemChanged( GetItem(row) ); | |
566 | } | |
567 | ||
568 | void wxDataViewVirtualListModel::RowValueChanged( unsigned int row, unsigned int col ) | |
569 | { | |
570 | wxDataViewModel::ValueChanged( GetItem(row), col ); | |
571 | } | |
572 | ||
573 | unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem &item ) const | |
574 | { | |
575 | return wxPtrToUInt( item.GetID() ); | |
576 | } | |
577 | ||
578 | wxDataViewItem wxDataViewVirtualListModel::GetItem( unsigned int row ) const | |
579 | { | |
777f9cef | 580 | return wxDataViewItem( wxUIntToPtr(row) ); |
e39de702 RR |
581 | } |
582 | ||
583 | bool wxDataViewVirtualListModel::HasDefaultCompare() const | |
777f9cef | 584 | { |
e39de702 RR |
585 | return true; |
586 | } | |
587 | ||
588 | int wxDataViewVirtualListModel::Compare(const wxDataViewItem& item1, | |
589 | const wxDataViewItem& item2, | |
590 | unsigned int WXUNUSED(column), | |
591 | bool ascending) | |
592 | { | |
593 | unsigned int pos1 = wxPtrToUInt(item1.GetID()); | |
594 | unsigned int pos2 = wxPtrToUInt(item2.GetID()); | |
777f9cef | 595 | |
e39de702 RR |
596 | if (ascending) |
597 | return pos1 - pos2; | |
777f9cef | 598 | else |
e39de702 RR |
599 | return pos2 - pos1; |
600 | } | |
601 | ||
602 | void wxDataViewVirtualListModel::GetValue( wxVariant &variant, | |
603 | const wxDataViewItem &item, unsigned int col ) const | |
604 | { | |
605 | GetValue( variant, GetRow(item), col ); | |
606 | } | |
607 | ||
608 | bool wxDataViewVirtualListModel::SetValue( const wxVariant &variant, | |
609 | const wxDataViewItem &item, unsigned int col ) | |
610 | { | |
611 | return SetValue( variant, GetRow(item), col ); | |
612 | } | |
613 | ||
614 | bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr ) | |
615 | { | |
616 | return GetAttr( GetRow(item), col, attr ); | |
617 | } | |
618 | ||
619 | wxDataViewItem wxDataViewVirtualListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const | |
620 | { | |
621 | return wxDataViewItem(0); | |
622 | } | |
623 | ||
624 | bool wxDataViewVirtualListModel::IsContainer( const wxDataViewItem &item ) const | |
625 | { | |
626 | // only the invisible root item has children | |
627 | if (!item.IsOk()) | |
628 | return true; | |
629 | ||
630 | return false; | |
631 | } | |
632 | ||
633 | unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem &WXUNUSED(item), wxDataViewItemArray &WXUNUSED(children) ) const | |
634 | { | |
635 | return 0; // should we report an error ? | |
636 | } | |
637 | ||
638 | #endif // __WXMAC__ | |
639 | ||
89352653 RR |
640 | //----------------------------------------------------------------------------- |
641 | // wxDataViewIconText | |
642 | //----------------------------------------------------------------------------- | |
643 | ||
644 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText,wxObject) | |
645 | ||
d350fbec | 646 | IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV) |
89352653 RR |
647 | |
648 | bool operator == (const wxDataViewIconText &one, const wxDataViewIconText &two) | |
649 | { | |
650 | if (one.GetText() != two.GetText()) return false; | |
651 | if (one.IsSameAs(two)) return false; | |
652 | return true; | |
653 | } | |
654 | ||
f554a14b | 655 | // --------------------------------------------------------- |
baa9ebc4 | 656 | // wxDataViewRendererBase |
f554a14b | 657 | // --------------------------------------------------------- |
6842a71a | 658 | |
baa9ebc4 | 659 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase, wxObject) |
6842a71a | 660 | |
900af470 | 661 | wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype, |
9861f022 RR |
662 | wxDataViewCellMode WXUNUSED(mode), |
663 | int WXUNUSED(align) ) | |
6842a71a RR |
664 | { |
665 | m_variantType = varianttype; | |
f2b7492a | 666 | m_owner = NULL; |
9861f022 RR |
667 | } |
668 | ||
c232dfe5 RR |
669 | wxDataViewRendererBase::~wxDataViewRendererBase() |
670 | { | |
671 | } | |
672 | ||
9861f022 RR |
673 | const wxDataViewCtrl* wxDataViewRendererBase::GetView() const |
674 | { | |
5c33522f | 675 | return const_cast<wxDataViewRendererBase*>(this)->GetOwner()->GetOwner(); |
6842a71a | 676 | } |
f554a14b | 677 | |
c232dfe5 | 678 | class wxKillRef: public wxWindowRef |
777f9cef VZ |
679 | { |
680 | public: | |
c232dfe5 RR |
681 | wxKillRef( wxWindow *win ) : wxWindowRef( win ) { } |
682 | virtual void OnObjectDestroy() | |
683 | { | |
684 | get()->PopEventHandler( true ); | |
095a3221 | 685 | m_pobj = NULL; |
c232dfe5 RR |
686 | delete this; |
687 | } | |
688 | }; | |
689 | ||
e0062c04 | 690 | bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect ) |
1e510b1e | 691 | { |
e0062c04 | 692 | m_item = item; // remember for later |
900af470 | 693 | |
1e510b1e RR |
694 | unsigned int col = GetOwner()->GetModelColumn(); |
695 | wxVariant value; | |
e0062c04 | 696 | GetOwner()->GetOwner()->GetModel()->GetValue( value, item, col ); |
900af470 | 697 | |
1e510b1e | 698 | m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value ); |
c232dfe5 | 699 | (void) new wxKillRef( m_editorCtrl.get() ); |
900af470 JS |
700 | |
701 | wxDataViewEditorCtrlEvtHandler *handler = | |
30715fa1 | 702 | new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this ); |
900af470 | 703 | |
30715fa1 | 704 | m_editorCtrl->PushEventHandler( handler ); |
900af470 | 705 | |
30715fa1 RR |
706 | #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL) |
707 | handler->SetFocusOnIdle(); | |
708 | #else | |
1e510b1e | 709 | m_editorCtrl->SetFocus(); |
30715fa1 RR |
710 | #endif |
711 | ||
afebb87b RR |
712 | // Now we should send Editing Started event |
713 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, GetOwner()->GetOwner()->GetId() ); | |
714 | event.SetDataViewColumn( GetOwner() ); | |
715 | event.SetModel( GetOwner()->GetOwner()->GetModel() ); | |
716 | event.SetItem( item ); | |
afebb87b RR |
717 | GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event ); |
718 | ||
1e510b1e RR |
719 | return true; |
720 | } | |
721 | ||
722 | void wxDataViewRendererBase::CancelEditing() | |
723 | { | |
33a1719a | 724 | if (!m_editorCtrl) return; |
23318a53 | 725 | |
1e510b1e | 726 | GetOwner()->GetOwner()->GetMainWindow()->SetFocus(); |
777f9cef | 727 | |
c232dfe5 RR |
728 | m_editorCtrl->Hide(); |
729 | wxPendingDelete.Append( m_editorCtrl ); | |
1e510b1e RR |
730 | } |
731 | ||
732 | bool wxDataViewRendererBase::FinishEditing() | |
733 | { | |
33a1719a RR |
734 | if (!m_editorCtrl) return true; |
735 | ||
1e510b1e RR |
736 | wxVariant value; |
737 | GetValueFromEditorCtrl( m_editorCtrl, value ); | |
738 | ||
1e510b1e | 739 | GetOwner()->GetOwner()->GetMainWindow()->SetFocus(); |
900af470 | 740 | |
c232dfe5 RR |
741 | m_editorCtrl->Hide(); |
742 | wxPendingDelete.Append( m_editorCtrl ); | |
777f9cef | 743 | |
1e510b1e RR |
744 | if (!Validate(value)) |
745 | return false; | |
900af470 | 746 | |
1e510b1e | 747 | unsigned int col = GetOwner()->GetModelColumn(); |
e0062c04 RR |
748 | GetOwner()->GetOwner()->GetModel()->SetValue( value, m_item, col ); |
749 | GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item, col ); | |
900af470 | 750 | |
afebb87b RR |
751 | // Now we should send Editing Done event |
752 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, GetOwner()->GetOwner()->GetId() ); | |
753 | event.SetDataViewColumn( GetOwner() ); | |
754 | event.SetModel( GetOwner()->GetOwner()->GetModel() ); | |
8fdaf7de | 755 | event.SetItem( m_item ); |
afebb87b | 756 | GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event ); |
900af470 | 757 | |
1e510b1e RR |
758 | return true; |
759 | } | |
760 | ||
761 | //----------------------------------------------------------------------------- | |
762 | // wxDataViewEditorCtrlEvtHandler | |
763 | //----------------------------------------------------------------------------- | |
764 | ||
765 | BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler) | |
766 | EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar) | |
767 | EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus) | |
30715fa1 | 768 | EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle) |
724852da | 769 | EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter) |
1e510b1e RR |
770 | END_EVENT_TABLE() |
771 | ||
772 | wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler( | |
773 | wxControl *editorCtrl, | |
774 | wxDataViewRenderer *owner ) | |
775 | { | |
776 | m_owner = owner; | |
777 | m_editorCtrl = editorCtrl; | |
778 | ||
779 | m_finished = false; | |
780 | } | |
781 | ||
30715fa1 RR |
782 | void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event ) |
783 | { | |
784 | if (m_focusOnIdle) | |
785 | { | |
786 | m_focusOnIdle = false; | |
787 | if (wxWindow::FindFocus() != m_editorCtrl) | |
788 | m_editorCtrl->SetFocus(); | |
789 | } | |
900af470 | 790 | |
30715fa1 RR |
791 | event.Skip(); |
792 | } | |
793 | ||
724852da RR |
794 | void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent &WXUNUSED(event) ) |
795 | { | |
796 | m_finished = true; | |
797 | m_owner->FinishEditing(); | |
798 | } | |
799 | ||
1e510b1e RR |
800 | void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event ) |
801 | { | |
802 | switch ( event.m_keyCode ) | |
803 | { | |
804 | case WXK_RETURN: | |
805 | m_finished = true; | |
806 | m_owner->FinishEditing(); | |
807 | break; | |
808 | ||
809 | case WXK_ESCAPE: | |
724852da | 810 | { |
1e510b1e RR |
811 | m_finished = true; |
812 | m_owner->CancelEditing(); | |
813 | break; | |
724852da | 814 | } |
1e510b1e RR |
815 | default: |
816 | event.Skip(); | |
817 | } | |
818 | } | |
819 | ||
820 | void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event ) | |
821 | { | |
822 | if (!m_finished) | |
823 | { | |
824 | m_finished = true; | |
825 | m_owner->FinishEditing(); | |
826 | } | |
827 | ||
1e510b1e RR |
828 | event.Skip(); |
829 | } | |
830 | ||
f554a14b | 831 | // --------------------------------------------------------- |
fa28826d | 832 | // wxDataViewColumnBase |
f554a14b | 833 | // --------------------------------------------------------- |
fa28826d RR |
834 | |
835 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject) | |
836 | ||
56873923 | 837 | wxDataViewColumnBase::wxDataViewColumnBase(const wxString& title, |
baa9ebc4 | 838 | wxDataViewRenderer *renderer, |
0a71f9e9 | 839 | unsigned int model_column, |
56873923 VZ |
840 | int width, |
841 | wxAlignment align, | |
842 | int flags) | |
843 | #ifdef wxHAS_GENERIC_DATAVIEWCTRL | |
844 | : wxHeaderColumn(title, width, align, flags) | |
845 | #endif | |
fa28826d | 846 | { |
baa9ebc4 | 847 | m_renderer = renderer; |
6842a71a | 848 | m_model_column = model_column; |
6842a71a | 849 | m_owner = NULL; |
baa9ebc4 | 850 | m_renderer->SetOwner( (wxDataViewColumn*) this ); |
9861f022 RR |
851 | |
852 | // NOTE: the wxDataViewColumn's ctor must store the width, align, flags | |
853 | // parameters inside the native control! | |
6842a71a RR |
854 | } |
855 | ||
07a84e7b RR |
856 | wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap& bitmap, |
857 | wxDataViewRenderer *renderer, | |
858 | unsigned int model_column, | |
56873923 VZ |
859 | int width, |
860 | wxAlignment align, | |
861 | int flags) | |
862 | #ifdef wxHAS_GENERIC_DATAVIEWCTRL | |
863 | : wxHeaderColumn(bitmap, width, align, flags) | |
864 | #else | |
865 | : m_bitmap(bitmap) | |
866 | #endif | |
07a84e7b RR |
867 | { |
868 | m_renderer = renderer; | |
869 | m_model_column = model_column; | |
07a84e7b RR |
870 | m_owner = NULL; |
871 | m_renderer->SetOwner( (wxDataViewColumn*) this ); | |
872 | } | |
873 | ||
6842a71a RR |
874 | wxDataViewColumnBase::~wxDataViewColumnBase() |
875 | { | |
56873923 | 876 | delete m_renderer; |
07a84e7b RR |
877 | } |
878 | ||
f554a14b | 879 | // --------------------------------------------------------- |
239eaa41 | 880 | // wxDataViewCtrlBase |
f554a14b | 881 | // --------------------------------------------------------- |
239eaa41 RR |
882 | |
883 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl) | |
884 | ||
885 | wxDataViewCtrlBase::wxDataViewCtrlBase() | |
886 | { | |
887 | m_model = NULL; | |
3b6280be RR |
888 | m_expander_column = 0; |
889 | m_indent = 8; | |
239eaa41 RR |
890 | } |
891 | ||
892 | wxDataViewCtrlBase::~wxDataViewCtrlBase() | |
893 | { | |
87f0efe2 RR |
894 | if (m_model) |
895 | { | |
896 | m_model->DecRef(); | |
897 | m_model = NULL; | |
898 | } | |
239eaa41 RR |
899 | } |
900 | ||
e0062c04 | 901 | bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model ) |
239eaa41 | 902 | { |
1821abd1 RR |
903 | if (m_model) |
904 | { | |
87f0efe2 | 905 | m_model->DecRef(); // discard old model, if any |
1821abd1 | 906 | } |
87f0efe2 RR |
907 | |
908 | // add our own reference to the new model: | |
239eaa41 | 909 | m_model = model; |
1821abd1 RR |
910 | if (m_model) |
911 | { | |
900af470 | 912 | m_model->IncRef(); |
1821abd1 | 913 | } |
f554a14b | 914 | |
239eaa41 RR |
915 | return true; |
916 | } | |
917 | ||
e0062c04 | 918 | wxDataViewModel* wxDataViewCtrlBase::GetModel() |
239eaa41 RR |
919 | { |
920 | return m_model; | |
921 | } | |
922 | ||
a75124d0 RR |
923 | const wxDataViewModel* wxDataViewCtrlBase::GetModel() const |
924 | { | |
925 | return m_model; | |
926 | } | |
927 | ||
c7074d44 RR |
928 | wxDataViewColumn * |
929 | wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 930 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
fa28826d | 931 | { |
c7074d44 | 932 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
f2b7492a | 933 | new wxDataViewTextRenderer( wxT("string"), mode ), |
c7074d44 RR |
934 | model_column, width, align, flags ); |
935 | AppendColumn( ret ); | |
936 | return ret; | |
fa28826d RR |
937 | } |
938 | ||
b04fcede RR |
939 | wxDataViewColumn * |
940 | wxDataViewCtrlBase::AppendIconTextColumn( const wxString &label, unsigned int model_column, | |
941 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
942 | { | |
943 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
f2b7492a | 944 | new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ), |
b04fcede RR |
945 | model_column, width, align, flags ); |
946 | AppendColumn( ret ); | |
947 | return ret; | |
948 | } | |
949 | ||
c7074d44 RR |
950 | wxDataViewColumn * |
951 | wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 952 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
605c2c4a | 953 | { |
b7fe2261 | 954 | |
c7074d44 | 955 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
f2b7492a | 956 | new wxDataViewToggleRenderer( wxT("bool"), mode ), |
c7074d44 RR |
957 | model_column, width, align, flags ); |
958 | AppendColumn( ret ); | |
959 | return ret; | |
605c2c4a RR |
960 | } |
961 | ||
c7074d44 RR |
962 | wxDataViewColumn * |
963 | wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 964 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
ad63bf41 | 965 | { |
c7074d44 | 966 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
f2b7492a | 967 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ), |
c7074d44 RR |
968 | model_column, width, align, flags ); |
969 | AppendColumn( ret ); | |
970 | return ret; | |
ad63bf41 RR |
971 | } |
972 | ||
c7074d44 RR |
973 | wxDataViewColumn * |
974 | wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 975 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
4d496ecb | 976 | { |
c7074d44 | 977 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
f2b7492a | 978 | new wxDataViewDateRenderer( wxT("datetime"), mode ), |
c7074d44 RR |
979 | model_column, width, align, flags ); |
980 | AppendColumn( ret ); | |
981 | return ret; | |
4d496ecb RR |
982 | } |
983 | ||
c7074d44 RR |
984 | wxDataViewColumn * |
985 | wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 986 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 987 | { |
c7074d44 | 988 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
f2b7492a | 989 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ), |
c7074d44 RR |
990 | model_column, width, align, flags ); |
991 | AppendColumn( ret ); | |
992 | return ret; | |
07a84e7b RR |
993 | } |
994 | ||
c7074d44 RR |
995 | wxDataViewColumn * |
996 | wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 997 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 998 | { |
c7074d44 | 999 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
f2b7492a | 1000 | new wxDataViewTextRenderer( wxT("string"), mode ), |
c7074d44 RR |
1001 | model_column, width, align, flags ); |
1002 | AppendColumn( ret ); | |
1003 | return ret; | |
b04fcede RR |
1004 | } |
1005 | ||
1006 | wxDataViewColumn * | |
1007 | wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap &label, unsigned int model_column, | |
1008 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1009 | { | |
1010 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
f2b7492a | 1011 | new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ), |
b04fcede RR |
1012 | model_column, width, align, flags ); |
1013 | AppendColumn( ret ); | |
1014 | return ret; | |
07a84e7b RR |
1015 | } |
1016 | ||
c7074d44 RR |
1017 | wxDataViewColumn * |
1018 | wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 1019 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 1020 | { |
c7074d44 | 1021 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
f2b7492a | 1022 | new wxDataViewToggleRenderer( wxT("bool"), mode ), |
c7074d44 RR |
1023 | model_column, width, align, flags ); |
1024 | AppendColumn( ret ); | |
1025 | return ret; | |
07a84e7b RR |
1026 | } |
1027 | ||
c7074d44 RR |
1028 | wxDataViewColumn * |
1029 | wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 1030 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 1031 | { |
c7074d44 | 1032 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
f2b7492a | 1033 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ), |
c7074d44 RR |
1034 | model_column, width, align, flags ); |
1035 | AppendColumn( ret ); | |
1036 | return ret; | |
07a84e7b RR |
1037 | } |
1038 | ||
c7074d44 RR |
1039 | wxDataViewColumn * |
1040 | wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 1041 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 1042 | { |
c7074d44 | 1043 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
f2b7492a | 1044 | new wxDataViewDateRenderer( wxT("datetime"), mode ), |
c7074d44 RR |
1045 | model_column, width, align, flags ); |
1046 | AppendColumn( ret ); | |
1047 | return ret; | |
07a84e7b RR |
1048 | } |
1049 | ||
c7074d44 RR |
1050 | wxDataViewColumn * |
1051 | wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 1052 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 1053 | { |
c7074d44 | 1054 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
f2b7492a | 1055 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ), |
c7074d44 RR |
1056 | model_column, width, align, flags ); |
1057 | AppendColumn( ret ); | |
1058 | return ret; | |
07a84e7b RR |
1059 | } |
1060 | ||
736fe67c RR |
1061 | wxDataViewColumn * |
1062 | wxDataViewCtrlBase::PrependTextColumn( const wxString &label, unsigned int model_column, | |
1063 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1064 | { | |
1065 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
f2b7492a | 1066 | new wxDataViewTextRenderer( wxT("string"), mode ), |
736fe67c RR |
1067 | model_column, width, align, flags ); |
1068 | PrependColumn( ret ); | |
1069 | return ret; | |
1070 | } | |
1071 | ||
1072 | wxDataViewColumn * | |
1073 | wxDataViewCtrlBase::PrependIconTextColumn( const wxString &label, unsigned int model_column, | |
1074 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1075 | { | |
1076 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
f2b7492a | 1077 | new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ), |
736fe67c RR |
1078 | model_column, width, align, flags ); |
1079 | PrependColumn( ret ); | |
1080 | return ret; | |
1081 | } | |
1082 | ||
1083 | wxDataViewColumn * | |
1084 | wxDataViewCtrlBase::PrependToggleColumn( const wxString &label, unsigned int model_column, | |
1085 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1086 | { | |
1087 | ||
1088 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
f2b7492a | 1089 | new wxDataViewToggleRenderer( wxT("bool"), mode ), |
736fe67c RR |
1090 | model_column, width, align, flags ); |
1091 | PrependColumn( ret ); | |
1092 | return ret; | |
1093 | } | |
1094 | ||
1095 | wxDataViewColumn * | |
1096 | wxDataViewCtrlBase::PrependProgressColumn( const wxString &label, unsigned int model_column, | |
1097 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1098 | { | |
1099 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
f2b7492a | 1100 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ), |
736fe67c RR |
1101 | model_column, width, align, flags ); |
1102 | PrependColumn( ret ); | |
1103 | return ret; | |
1104 | } | |
1105 | ||
1106 | wxDataViewColumn * | |
1107 | wxDataViewCtrlBase::PrependDateColumn( const wxString &label, unsigned int model_column, | |
1108 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1109 | { | |
1110 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
f2b7492a | 1111 | new wxDataViewDateRenderer( wxT("datetime"), mode ), |
736fe67c RR |
1112 | model_column, width, align, flags ); |
1113 | PrependColumn( ret ); | |
1114 | return ret; | |
1115 | } | |
1116 | ||
1117 | wxDataViewColumn * | |
1118 | wxDataViewCtrlBase::PrependBitmapColumn( const wxString &label, unsigned int model_column, | |
1119 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1120 | { | |
1121 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
f2b7492a | 1122 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ), |
736fe67c RR |
1123 | model_column, width, align, flags ); |
1124 | PrependColumn( ret ); | |
1125 | return ret; | |
1126 | } | |
1127 | ||
1128 | wxDataViewColumn * | |
1129 | wxDataViewCtrlBase::PrependTextColumn( const wxBitmap &label, unsigned int model_column, | |
1130 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1131 | { | |
1132 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
f2b7492a | 1133 | new wxDataViewTextRenderer( wxT("string"), mode ), |
736fe67c RR |
1134 | model_column, width, align, flags ); |
1135 | PrependColumn( ret ); | |
1136 | return ret; | |
1137 | } | |
1138 | ||
1139 | wxDataViewColumn * | |
1140 | wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap &label, unsigned int model_column, | |
1141 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1142 | { | |
1143 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
f2b7492a | 1144 | new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ), |
736fe67c RR |
1145 | model_column, width, align, flags ); |
1146 | PrependColumn( ret ); | |
1147 | return ret; | |
1148 | } | |
1149 | ||
1150 | wxDataViewColumn * | |
1151 | wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap &label, unsigned int model_column, | |
1152 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1153 | { | |
1154 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
f2b7492a | 1155 | new wxDataViewToggleRenderer( wxT("bool"), mode ), |
736fe67c RR |
1156 | model_column, width, align, flags ); |
1157 | PrependColumn( ret ); | |
1158 | return ret; | |
1159 | } | |
1160 | ||
1161 | wxDataViewColumn * | |
1162 | wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap &label, unsigned int model_column, | |
1163 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1164 | { | |
1165 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
f2b7492a | 1166 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ), |
736fe67c RR |
1167 | model_column, width, align, flags ); |
1168 | PrependColumn( ret ); | |
1169 | return ret; | |
1170 | } | |
1171 | ||
1172 | wxDataViewColumn * | |
1173 | wxDataViewCtrlBase::PrependDateColumn( const wxBitmap &label, unsigned int model_column, | |
1174 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1175 | { | |
1176 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
f2b7492a | 1177 | new wxDataViewDateRenderer( wxT("datetime"), mode ), |
736fe67c RR |
1178 | model_column, width, align, flags ); |
1179 | PrependColumn( ret ); | |
1180 | return ret; | |
1181 | } | |
1182 | ||
1183 | wxDataViewColumn * | |
1184 | wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap &label, unsigned int model_column, | |
1185 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1186 | { | |
1187 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
f2b7492a | 1188 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ), |
736fe67c RR |
1189 | model_column, width, align, flags ); |
1190 | PrependColumn( ret ); | |
1191 | return ret; | |
1192 | } | |
1193 | ||
c7074d44 RR |
1194 | bool |
1195 | wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col ) | |
fa28826d | 1196 | { |
6842a71a | 1197 | col->SetOwner( (wxDataViewCtrl*) this ); |
fa28826d RR |
1198 | return true; |
1199 | } | |
1200 | ||
736fe67c RR |
1201 | bool |
1202 | wxDataViewCtrlBase::PrependColumn( wxDataViewColumn *col ) | |
1203 | { | |
1204 | col->SetOwner( (wxDataViewCtrl*) this ); | |
1205 | return true; | |
1206 | } | |
1207 | ||
23318a53 | 1208 | bool |
19723525 RR |
1209 | wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos), wxDataViewColumn *col ) |
1210 | { | |
1211 | col->SetOwner( (wxDataViewCtrl*) this ); | |
1212 | return true; | |
1213 | } | |
1214 | ||
eb7f97f8 RR |
1215 | // --------------------------------------------------------- |
1216 | // wxDataViewEvent | |
1217 | // --------------------------------------------------------- | |
1218 | ||
1219 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent) | |
1220 | ||
d86c1870 RR |
1221 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED) |
1222 | ||
e0062c04 | 1223 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED) |
6977c3bf | 1224 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING) |
3ecb8a53 | 1225 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED) |
6977c3bf | 1226 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING) |
3ecb8a53 | 1227 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED) |
e0000f94 RR |
1228 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED) |
1229 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE) | |
6608fdab | 1230 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED) |
e0000f94 | 1231 | |
63779a3d RR |
1232 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU) |
1233 | ||
31fb32e1 RR |
1234 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK) |
1235 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK) | |
c0a66d92 | 1236 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED) |
e483dfcb | 1237 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED) |
eb7f97f8 | 1238 | |
52e750fc RR |
1239 | |
1240 | // ------------------------------------- | |
1241 | // wxDataViewSpinRenderer | |
1242 | // ------------------------------------- | |
1243 | ||
1244 | wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min, int max, wxDataViewCellMode mode, int alignment ) : | |
99c75ebc | 1245 | wxDataViewCustomRenderer(wxT("long"), mode, alignment ) |
b5ec7dd6 | 1246 | { |
52e750fc RR |
1247 | m_min = min; |
1248 | m_max = max; | |
1249 | } | |
b5ec7dd6 | 1250 | |
52e750fc | 1251 | wxControl* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ) |
b5ec7dd6 | 1252 | { |
52e750fc | 1253 | long l = value; |
659fb68d RR |
1254 | wxSize size = labelRect.GetSize(); |
1255 | #ifdef __WXMAC__ | |
1256 | size = wxSize( wxMax(70,labelRect.width ), -1 ); | |
1257 | #endif | |
1258 | wxString str; | |
2ddfe921 | 1259 | str.Printf( wxT("%d"), (int) l ); |
659fb68d | 1260 | wxSpinCtrl *sc = new wxSpinCtrl( parent, wxID_ANY, str, |
724852da | 1261 | labelRect.GetTopLeft(), size, wxSP_ARROW_KEYS|wxTE_PROCESS_ENTER, m_min, m_max, l ); |
659fb68d RR |
1262 | #ifdef __WXMAC__ |
1263 | size = sc->GetSize(); | |
1264 | wxPoint pt = sc->GetPosition(); | |
1265 | sc->SetSize( pt.x - 4, pt.y - 4, size.x, size.y ); | |
1266 | #endif | |
777f9cef | 1267 | |
659fb68d | 1268 | return sc; |
52e750fc | 1269 | } |
b5ec7dd6 | 1270 | |
52e750fc | 1271 | bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ) |
b5ec7dd6 | 1272 | { |
52e750fc RR |
1273 | wxSpinCtrl *sc = (wxSpinCtrl*) editor; |
1274 | long l = sc->GetValue(); | |
1275 | value = l; | |
1276 | return true; | |
1277 | } | |
b5ec7dd6 | 1278 | |
52e750fc RR |
1279 | bool wxDataViewSpinRenderer::Render( wxRect rect, wxDC *dc, int state ) |
1280 | { | |
1281 | wxString str; | |
99c75ebc | 1282 | str.Printf(wxT("%d"), (int) m_data ); |
52e750fc RR |
1283 | RenderText( str, 0, rect, dc, state ); |
1284 | return true; | |
1285 | } | |
b5ec7dd6 | 1286 | |
52e750fc RR |
1287 | wxSize wxDataViewSpinRenderer::GetSize() const |
1288 | { | |
1289 | return wxSize(80,16); | |
1290 | } | |
b5ec7dd6 | 1291 | |
52e750fc RR |
1292 | bool wxDataViewSpinRenderer::SetValue( const wxVariant &value ) |
1293 | { | |
1294 | m_data = value.GetLong(); | |
1295 | return true; | |
1296 | } | |
b5ec7dd6 | 1297 | |
52e750fc RR |
1298 | bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const |
1299 | { | |
1300 | value = m_data; | |
1301 | return true; | |
1302 | } | |
1303 | ||
7448d67c RR |
1304 | // ------------------------------------- |
1305 | // wxDataViewChoiceRenderer | |
1306 | // ------------------------------------- | |
1307 | ||
1308 | #ifndef __WXGTK20__ | |
1309 | ||
1310 | wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString& choices, wxDataViewCellMode mode, int alignment ) : | |
1311 | wxDataViewCustomRenderer(wxT("string"), mode, alignment ) | |
1312 | { | |
1313 | m_choices = choices; | |
1314 | } | |
1315 | ||
1316 | wxControl* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ) | |
1317 | { | |
1318 | wxString s = value; | |
1319 | wxSize size = labelRect.GetSize(); | |
1320 | #ifdef __WXMAC__ | |
1321 | size = wxSize( wxMax(70,labelRect.width ), -1 ); | |
1322 | #endif | |
1323 | wxChoice *c = new wxChoice( parent, wxID_ANY, labelRect.GetTopLeft(), size, m_choices ); | |
1324 | c->SetStringSelection( value.GetString() ); | |
1325 | ||
1326 | return c; | |
1327 | } | |
1328 | ||
1329 | bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ) | |
1330 | { | |
1331 | wxChoice *c = (wxChoice*) editor; | |
1332 | wxString s = c->GetStringSelection(); | |
1333 | value = s; | |
1334 | return true; | |
1335 | } | |
1336 | ||
1337 | bool wxDataViewChoiceRenderer::Render( wxRect rect, wxDC *dc, int state ) | |
1338 | { | |
1339 | RenderText( m_data, 0, rect, dc, state ); | |
1340 | return true; | |
1341 | } | |
1342 | ||
1343 | wxSize wxDataViewChoiceRenderer::GetSize() const | |
1344 | { | |
1345 | return wxSize(80,16); | |
1346 | } | |
1347 | ||
1348 | bool wxDataViewChoiceRenderer::SetValue( const wxVariant &value ) | |
1349 | { | |
1350 | m_data = value.GetString(); | |
1351 | return true; | |
1352 | } | |
1353 | ||
1354 | bool wxDataViewChoiceRenderer::GetValue( wxVariant &value ) const | |
1355 | { | |
1356 | value = m_data; | |
1357 | return true; | |
1358 | } | |
1359 | ||
1360 | #endif | |
1361 | ||
e94d0c1e RR |
1362 | //----------------------------------------------------------------------------- |
1363 | // wxDataViewTreeStore | |
1364 | //----------------------------------------------------------------------------- | |
1365 | ||
b5ec7dd6 VZ |
1366 | wxDataViewTreeStoreNode::wxDataViewTreeStoreNode( |
1367 | wxDataViewTreeStoreNode *parent, | |
e94d0c1e RR |
1368 | const wxString &text, const wxIcon &icon, wxClientData *data ) |
1369 | { | |
1370 | m_parent = parent; | |
1371 | m_text = text; | |
1372 | m_icon = icon; | |
1373 | m_data = data; | |
1374 | } | |
1375 | ||
1376 | wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode() | |
1377 | { | |
1378 | if (m_data) | |
1379 | delete m_data; | |
1380 | } | |
b5ec7dd6 | 1381 | |
e94d0c1e | 1382 | #include "wx/listimpl.cpp" |
a76c2f37 | 1383 | WX_DEFINE_LIST(wxDataViewTreeStoreNodeList) |
e94d0c1e | 1384 | |
b5ec7dd6 VZ |
1385 | wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode( |
1386 | wxDataViewTreeStoreNode *parent, const wxString &text, | |
e94d0c1e RR |
1387 | const wxIcon &icon, const wxIcon &expanded, wxClientData *data ) : |
1388 | wxDataViewTreeStoreNode( parent, text, icon, data ) | |
1389 | { | |
1390 | m_iconExpanded = expanded; | |
a75124d0 | 1391 | m_isExpanded = false; |
e94d0c1e RR |
1392 | m_children.DeleteContents(true); |
1393 | } | |
1394 | ||
1395 | wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode() | |
1396 | { | |
1397 | } | |
1398 | ||
1399 | //----------------------------------------------------------------------------- | |
1400 | ||
1401 | wxDataViewTreeStore::wxDataViewTreeStore() | |
1402 | { | |
1403 | m_root = new wxDataViewTreeStoreContainerNode( NULL, wxEmptyString ); | |
1404 | } | |
1405 | ||
1406 | wxDataViewTreeStore::~wxDataViewTreeStore() | |
1407 | { | |
1408 | delete m_root; | |
1409 | } | |
1410 | ||
b5ec7dd6 | 1411 | wxDataViewItem wxDataViewTreeStore::AppendItem( const wxDataViewItem& parent, |
e94d0c1e RR |
1412 | const wxString &text, const wxIcon &icon, wxClientData *data ) |
1413 | { | |
1414 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1415 | if (!parent_node) return wxDataViewItem(0); | |
b5ec7dd6 VZ |
1416 | |
1417 | wxDataViewTreeStoreNode *node = | |
e94d0c1e RR |
1418 | new wxDataViewTreeStoreNode( parent_node, text, icon, data ); |
1419 | parent_node->GetChildren().Append( node ); | |
b5ec7dd6 | 1420 | |
e94d0c1e RR |
1421 | // notify control |
1422 | ItemAdded( parent, node->GetItem() ); | |
b5ec7dd6 | 1423 | |
e94d0c1e RR |
1424 | return node->GetItem(); |
1425 | } | |
1426 | ||
1427 | wxDataViewItem wxDataViewTreeStore::PrependItem( const wxDataViewItem& parent, | |
1428 | const wxString &text, const wxIcon &icon, wxClientData *data ) | |
1429 | { | |
1430 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1431 | if (!parent_node) return wxDataViewItem(0); | |
b5ec7dd6 VZ |
1432 | |
1433 | wxDataViewTreeStoreNode *node = | |
e94d0c1e RR |
1434 | new wxDataViewTreeStoreNode( parent_node, text, icon, data ); |
1435 | parent_node->GetChildren().Insert( node ); | |
b5ec7dd6 | 1436 | |
e94d0c1e RR |
1437 | // notify control |
1438 | ItemAdded( parent, node->GetItem() ); | |
b5ec7dd6 | 1439 | |
e94d0c1e RR |
1440 | return node->GetItem(); |
1441 | } | |
1442 | ||
b5ec7dd6 VZ |
1443 | wxDataViewItem |
1444 | wxDataViewTreeStore::InsertItem(const wxDataViewItem& WXUNUSED(parent), | |
1445 | const wxDataViewItem& WXUNUSED(previous), | |
1446 | const wxString& WXUNUSED(text), | |
1447 | const wxIcon& WXUNUSED(icon), | |
1448 | wxClientData * WXUNUSED(data)) | |
e94d0c1e RR |
1449 | { |
1450 | return wxDataViewItem(0); | |
1451 | } | |
1452 | ||
b5ec7dd6 VZ |
1453 | wxDataViewItem wxDataViewTreeStore::PrependContainer( const wxDataViewItem& parent, |
1454 | const wxString &text, const wxIcon &icon, const wxIcon &expanded, | |
e94d0c1e RR |
1455 | wxClientData *data ) |
1456 | { | |
1457 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1458 | if (!parent_node) return wxDataViewItem(0); | |
b5ec7dd6 VZ |
1459 | |
1460 | wxDataViewTreeStoreContainerNode *node = | |
e94d0c1e RR |
1461 | new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data ); |
1462 | parent_node->GetChildren().Insert( node ); | |
b5ec7dd6 | 1463 | |
e94d0c1e RR |
1464 | // notify control |
1465 | ItemAdded( parent, node->GetItem() ); | |
b5ec7dd6 | 1466 | |
e94d0c1e RR |
1467 | return node->GetItem(); |
1468 | } | |
1469 | ||
b5ec7dd6 VZ |
1470 | wxDataViewItem |
1471 | wxDataViewTreeStore::AppendContainer(const wxDataViewItem& parent, | |
1472 | const wxString &text, | |
1473 | const wxIcon& icon, | |
1474 | const wxIcon& expanded, | |
1475 | wxClientData * data) | |
e94d0c1e RR |
1476 | { |
1477 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1478 | if (!parent_node) return wxDataViewItem(0); | |
b5ec7dd6 VZ |
1479 | |
1480 | wxDataViewTreeStoreContainerNode *node = | |
e94d0c1e RR |
1481 | new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data ); |
1482 | parent_node->GetChildren().Append( node ); | |
b5ec7dd6 | 1483 | |
e94d0c1e RR |
1484 | // notify control |
1485 | ItemAdded( parent, node->GetItem() ); | |
b5ec7dd6 | 1486 | |
e94d0c1e RR |
1487 | return node->GetItem(); |
1488 | } | |
1489 | ||
b5ec7dd6 VZ |
1490 | wxDataViewItem |
1491 | wxDataViewTreeStore::InsertContainer(const wxDataViewItem& WXUNUSED(parent), | |
1492 | const wxDataViewItem& WXUNUSED(previous), | |
1493 | const wxString& WXUNUSED(text), | |
1494 | const wxIcon& WXUNUSED(icon), | |
1495 | const wxIcon& WXUNUSED(expanded), | |
1496 | wxClientData * WXUNUSED(data)) | |
e94d0c1e RR |
1497 | { |
1498 | return wxDataViewItem(0); | |
1499 | } | |
1500 | ||
1501 | wxDataViewItem wxDataViewTreeStore::GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const | |
1502 | { | |
1503 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1504 | if (!parent_node) return wxDataViewItem(0); | |
b5ec7dd6 | 1505 | |
e94d0c1e RR |
1506 | wxDataViewTreeStoreNodeList::compatibility_iterator node = parent_node->GetChildren().Item( pos ); |
1507 | if (node) | |
1508 | return node->GetData(); | |
b5ec7dd6 | 1509 | |
e94d0c1e RR |
1510 | return wxDataViewItem(0); |
1511 | } | |
1512 | ||
1513 | int wxDataViewTreeStore::GetChildCount( const wxDataViewItem& parent ) const | |
1514 | { | |
1515 | wxDataViewTreeStoreNode *node = FindNode( parent ); | |
1516 | if (!node) return -1; | |
b5ec7dd6 | 1517 | |
e94d0c1e RR |
1518 | if (!node->IsContainer()) |
1519 | return 0; | |
b5ec7dd6 | 1520 | |
e94d0c1e | 1521 | wxDataViewTreeStoreContainerNode *container_node = (wxDataViewTreeStoreContainerNode*) node; |
b5ec7dd6 | 1522 | return (int) container_node->GetChildren().GetCount(); |
e94d0c1e RR |
1523 | } |
1524 | ||
1525 | void wxDataViewTreeStore::SetItemText( const wxDataViewItem& item, const wxString &text ) | |
1526 | { | |
1527 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1528 | if (!node) return; | |
b5ec7dd6 | 1529 | |
e94d0c1e | 1530 | node->SetText( text ); |
b5ec7dd6 | 1531 | |
e94d0c1e RR |
1532 | // notify control |
1533 | ValueChanged( item, 0 ); | |
1534 | } | |
1535 | ||
1536 | wxString wxDataViewTreeStore::GetItemText( const wxDataViewItem& item ) const | |
1537 | { | |
1538 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1539 | if (!node) return wxEmptyString; | |
b5ec7dd6 | 1540 | |
e94d0c1e RR |
1541 | return node->GetText(); |
1542 | } | |
1543 | ||
1544 | void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon ) | |
1545 | { | |
1546 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1547 | if (!node) return; | |
b5ec7dd6 | 1548 | |
e94d0c1e | 1549 | node->SetIcon( icon ); |
b5ec7dd6 | 1550 | |
e94d0c1e RR |
1551 | // notify control |
1552 | ValueChanged( item, 0 ); | |
1553 | } | |
1554 | ||
1555 | const wxIcon &wxDataViewTreeStore::GetItemIcon( const wxDataViewItem& item ) const | |
1556 | { | |
1557 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1558 | if (!node) return wxNullIcon; | |
b5ec7dd6 | 1559 | |
e94d0c1e RR |
1560 | return node->GetIcon(); |
1561 | } | |
1562 | ||
1563 | void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon ) | |
1564 | { | |
1565 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1566 | if (!node) return; | |
b5ec7dd6 | 1567 | |
e94d0c1e | 1568 | node->SetExpandedIcon( icon ); |
b5ec7dd6 | 1569 | |
e94d0c1e RR |
1570 | // notify control |
1571 | ValueChanged( item, 0 ); | |
1572 | } | |
1573 | ||
1574 | const wxIcon &wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem& item ) const | |
1575 | { | |
1576 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1577 | if (!node) return wxNullIcon; | |
b5ec7dd6 | 1578 | |
e94d0c1e RR |
1579 | return node->GetExpandedIcon(); |
1580 | } | |
1581 | ||
1582 | void wxDataViewTreeStore::SetItemData( const wxDataViewItem& item, wxClientData *data ) | |
1583 | { | |
1584 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1585 | if (!node) return; | |
b5ec7dd6 | 1586 | |
e94d0c1e | 1587 | node->SetData( data ); |
b5ec7dd6 | 1588 | |
e94d0c1e RR |
1589 | // notify control? only sensible when sorting on client data |
1590 | // ValueChanged( item, 0 ); | |
1591 | } | |
1592 | ||
1593 | wxClientData *wxDataViewTreeStore::GetItemData( const wxDataViewItem& item ) const | |
1594 | { | |
1595 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1596 | if (!node) return NULL; | |
b5ec7dd6 | 1597 | |
e94d0c1e RR |
1598 | return node->GetData(); |
1599 | } | |
1600 | ||
1601 | void wxDataViewTreeStore::DeleteItem( const wxDataViewItem& item ) | |
1602 | { | |
1603 | if (!item.IsOk()) return; | |
1604 | ||
1605 | wxDataViewItem parent_item = GetParent( item ); | |
1606 | ||
1607 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent_item ); | |
1608 | if (!parent_node) return; | |
b5ec7dd6 | 1609 | |
e94d0c1e RR |
1610 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); |
1611 | if (!node) return; | |
b5ec7dd6 | 1612 | |
e94d0c1e | 1613 | parent_node->GetChildren().DeleteObject( node ); |
b5ec7dd6 | 1614 | |
e94d0c1e RR |
1615 | // notify control |
1616 | ItemDeleted( parent_item, item ); | |
1617 | } | |
1618 | ||
1619 | void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem& item ) | |
1620 | { | |
1621 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1622 | if (!node) return; | |
b5ec7dd6 | 1623 | |
e94d0c1e RR |
1624 | wxDataViewItemArray array; |
1625 | wxDataViewTreeStoreNodeList::iterator iter; | |
1626 | for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++) | |
1627 | { | |
1628 | wxDataViewTreeStoreNode* child = *iter; | |
1629 | array.Add( child->GetItem() ); | |
1630 | } | |
b5ec7dd6 | 1631 | |
e94d0c1e | 1632 | node->GetChildren().clear(); |
b5ec7dd6 | 1633 | |
e94d0c1e RR |
1634 | // notify control |
1635 | ItemsDeleted( item, array ); | |
1636 | } | |
1637 | ||
1638 | void wxDataViewTreeStore::DeleteAllItems() | |
1639 | { | |
1640 | // TODO | |
1641 | } | |
1642 | ||
b5ec7dd6 VZ |
1643 | void |
1644 | wxDataViewTreeStore::GetValue(wxVariant &variant, | |
1645 | const wxDataViewItem &item, | |
1646 | unsigned int WXUNUSED(col)) const | |
e94d0c1e RR |
1647 | { |
1648 | // if (col != 0) return; | |
b5ec7dd6 | 1649 | |
e94d0c1e RR |
1650 | wxDataViewTreeStoreNode *node = FindNode( item ); |
1651 | if (!node) return; | |
b5ec7dd6 | 1652 | |
a75124d0 RR |
1653 | wxIcon icon( node->GetIcon()); |
1654 | if (node->IsContainer()) | |
1655 | { | |
1656 | wxDataViewTreeStoreContainerNode *container = (wxDataViewTreeStoreContainerNode*) node; | |
1657 | if (container->IsExpanded() && container->GetExpandedIcon().IsOk()) | |
1658 | icon = container->GetExpandedIcon(); | |
1659 | } | |
777f9cef | 1660 | |
a75124d0 | 1661 | wxDataViewIconText data( node->GetText(), icon ); |
b5ec7dd6 | 1662 | |
e94d0c1e RR |
1663 | variant << data; |
1664 | } | |
1665 | ||
b5ec7dd6 VZ |
1666 | bool |
1667 | wxDataViewTreeStore::SetValue(const wxVariant& variant, | |
1668 | const wxDataViewItem& item, | |
1669 | unsigned int WXUNUSED(col)) | |
e94d0c1e RR |
1670 | { |
1671 | // if (col != 0) return false; | |
b5ec7dd6 | 1672 | |
e94d0c1e RR |
1673 | wxDataViewTreeStoreNode *node = FindNode( item ); |
1674 | if (!node) return false; | |
b5ec7dd6 | 1675 | |
e94d0c1e | 1676 | wxDataViewIconText data; |
b5ec7dd6 | 1677 | |
e94d0c1e | 1678 | data << variant; |
b5ec7dd6 | 1679 | |
e94d0c1e RR |
1680 | node->SetText( data.GetText() ); |
1681 | node->SetIcon( data.GetIcon() ); | |
b5ec7dd6 | 1682 | |
e94d0c1e RR |
1683 | return true; |
1684 | } | |
1685 | ||
1686 | wxDataViewItem wxDataViewTreeStore::GetParent( const wxDataViewItem &item ) const | |
1687 | { | |
1688 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1689 | if (!node) return wxDataViewItem(0); | |
b5ec7dd6 | 1690 | |
e94d0c1e RR |
1691 | wxDataViewTreeStoreNode *parent = node->GetParent(); |
1692 | if (!parent) return wxDataViewItem(0); | |
b5ec7dd6 | 1693 | |
e94d0c1e RR |
1694 | if (parent == m_root) |
1695 | return wxDataViewItem(0); | |
b5ec7dd6 | 1696 | |
e94d0c1e RR |
1697 | return parent->GetItem(); |
1698 | } | |
1699 | ||
1700 | bool wxDataViewTreeStore::IsContainer( const wxDataViewItem &item ) const | |
1701 | { | |
1702 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1703 | if (!node) return false; | |
b5ec7dd6 | 1704 | |
e94d0c1e RR |
1705 | return node->IsContainer(); |
1706 | } | |
1707 | ||
1708 | unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const | |
1709 | { | |
1710 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1711 | if (!node) return 0; | |
1712 | ||
1713 | wxDataViewTreeStoreNodeList::iterator iter; | |
1714 | for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++) | |
1715 | { | |
1716 | wxDataViewTreeStoreNode* child = *iter; | |
1717 | children.Add( child->GetItem() ); | |
1718 | } | |
b5ec7dd6 | 1719 | |
e94d0c1e RR |
1720 | return node->GetChildren().GetCount(); |
1721 | } | |
1722 | ||
b5ec7dd6 | 1723 | int wxDataViewTreeStore::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, |
e94d0c1e RR |
1724 | unsigned int WXUNUSED(column), bool WXUNUSED(ascending) ) |
1725 | { | |
1726 | wxDataViewTreeStoreNode *node1 = FindNode( item1 ); | |
1727 | wxDataViewTreeStoreNode *node2 = FindNode( item2 ); | |
b5ec7dd6 | 1728 | |
e94d0c1e RR |
1729 | if (!node1 || !node2) |
1730 | return 0; | |
b5ec7dd6 VZ |
1731 | |
1732 | wxDataViewTreeStoreContainerNode* parent1 = | |
e94d0c1e | 1733 | (wxDataViewTreeStoreContainerNode*) node1->GetParent(); |
b5ec7dd6 | 1734 | wxDataViewTreeStoreContainerNode* parent2 = |
e94d0c1e | 1735 | (wxDataViewTreeStoreContainerNode*) node2->GetParent(); |
b5ec7dd6 | 1736 | |
e94d0c1e RR |
1737 | if (parent1 != parent2) |
1738 | { | |
1739 | wxLogError( wxT("Comparing items with different parent.") ); | |
1740 | return 0; | |
1741 | } | |
b5ec7dd6 | 1742 | |
e94d0c1e RR |
1743 | if (node1->IsContainer() && !!node2->IsContainer()) |
1744 | return 1; | |
b5ec7dd6 | 1745 | |
e94d0c1e RR |
1746 | if (node2->IsContainer() && !!node1->IsContainer()) |
1747 | return -1; | |
b5ec7dd6 | 1748 | |
e94d0c1e RR |
1749 | return parent1->GetChildren().IndexOf( node1 ) - parent1->GetChildren().IndexOf( node2 ); |
1750 | } | |
1751 | ||
1752 | wxDataViewTreeStoreNode *wxDataViewTreeStore::FindNode( const wxDataViewItem &item ) const | |
1753 | { | |
1754 | if (!item.IsOk()) | |
1755 | return m_root; | |
b5ec7dd6 | 1756 | |
e94d0c1e RR |
1757 | return (wxDataViewTreeStoreNode*) item.GetID(); |
1758 | } | |
1759 | ||
1760 | wxDataViewTreeStoreContainerNode *wxDataViewTreeStore::FindContainerNode( const wxDataViewItem &item ) const | |
1761 | { | |
1762 | if (!item.IsOk()) | |
1763 | return (wxDataViewTreeStoreContainerNode*) m_root; | |
1764 | ||
1765 | wxDataViewTreeStoreNode* node = (wxDataViewTreeStoreNode*) item.GetID(); | |
b5ec7dd6 | 1766 | |
e94d0c1e RR |
1767 | if (!node->IsContainer()) |
1768 | return NULL; | |
b5ec7dd6 | 1769 | |
e94d0c1e RR |
1770 | return (wxDataViewTreeStoreContainerNode*) node; |
1771 | } | |
1772 | ||
a75124d0 RR |
1773 | //----------------------------------------------------------------------------- |
1774 | // wxDataViewTreeCtrl | |
1775 | //----------------------------------------------------------------------------- | |
1776 | ||
1777 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl,wxDataViewCtrl) | |
1778 | ||
1779 | BEGIN_EVENT_TABLE(wxDataViewTreeCtrl,wxDataViewCtrl) | |
1780 | EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded) | |
1781 | EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed) | |
9c150d5f | 1782 | EVT_SIZE( wxDataViewTreeCtrl::OnSize ) |
a75124d0 RR |
1783 | END_EVENT_TABLE() |
1784 | ||
1785 | wxDataViewTreeCtrl::wxDataViewTreeCtrl() | |
1786 | { | |
1787 | m_imageList = NULL; | |
1788 | } | |
1789 | ||
1790 | wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow *parent, wxWindowID id, | |
777f9cef | 1791 | const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator ) |
a75124d0 RR |
1792 | { |
1793 | m_imageList = NULL; | |
1794 | Create( parent, id, pos, size, style, validator ); | |
777f9cef | 1795 | |
a75124d0 RR |
1796 | wxDataViewTreeStore *store = new wxDataViewTreeStore; |
1797 | AssociateModel( store ); | |
1798 | store->DecRef(); | |
777f9cef | 1799 | |
ad386793 | 1800 | AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT,-1); |
a75124d0 RR |
1801 | } |
1802 | ||
1803 | wxDataViewTreeCtrl::~wxDataViewTreeCtrl() | |
1804 | { | |
1805 | if (m_imageList) | |
1806 | delete m_imageList; | |
1807 | } | |
1808 | ||
1809 | bool wxDataViewTreeCtrl::Create( wxWindow *parent, wxWindowID id, | |
1810 | const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator ) | |
1811 | { | |
1812 | return wxDataViewCtrl::Create( parent, id, pos, size, style, validator ); | |
1813 | } | |
1814 | ||
1815 | void wxDataViewTreeCtrl::SetImageList( wxImageList *imagelist ) | |
1816 | { | |
1817 | if (m_imageList) | |
1818 | delete m_imageList; | |
1819 | ||
777f9cef | 1820 | m_imageList = imagelist; |
a75124d0 | 1821 | } |
777f9cef | 1822 | |
a75124d0 RR |
1823 | wxDataViewItem wxDataViewTreeCtrl::AppendItem( const wxDataViewItem& parent, |
1824 | const wxString &text, int iconIndex, wxClientData *data ) | |
1825 | { | |
1826 | wxIcon icon = wxNullIcon; | |
1827 | if (m_imageList && (iconIndex != -1)) | |
1828 | icon = m_imageList->GetIcon( iconIndex ); | |
777f9cef | 1829 | |
a75124d0 RR |
1830 | return GetStore()->AppendItem( parent, text, icon, data ); |
1831 | } | |
1832 | ||
1833 | wxDataViewItem wxDataViewTreeCtrl::PrependItem( const wxDataViewItem& parent, | |
1834 | const wxString &text, int iconIndex, wxClientData *data ) | |
1835 | { | |
1836 | wxIcon icon = wxNullIcon; | |
1837 | if (m_imageList && (iconIndex != -1)) | |
1838 | icon = m_imageList->GetIcon( iconIndex ); | |
777f9cef | 1839 | |
a75124d0 RR |
1840 | return GetStore()->PrependItem( parent, text, icon, data ); |
1841 | } | |
1842 | ||
1843 | wxDataViewItem wxDataViewTreeCtrl::InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous, | |
1844 | const wxString &text, int iconIndex, wxClientData *data ) | |
1845 | { | |
1846 | wxIcon icon = wxNullIcon; | |
1847 | if (m_imageList && (iconIndex != -1)) | |
1848 | icon = m_imageList->GetIcon( iconIndex ); | |
777f9cef | 1849 | |
a75124d0 RR |
1850 | return GetStore()->InsertItem( parent, previous, text, icon, data ); |
1851 | } | |
1852 | ||
1853 | wxDataViewItem wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem& parent, | |
1854 | const wxString &text, int iconIndex, int expandedIndex, wxClientData *data ) | |
1855 | { | |
1856 | wxIcon icon = wxNullIcon; | |
1857 | if (m_imageList && (iconIndex != -1)) | |
1858 | icon = m_imageList->GetIcon( iconIndex ); | |
777f9cef | 1859 | |
a75124d0 RR |
1860 | wxIcon expanded = wxNullIcon; |
1861 | if (m_imageList && (expandedIndex != -1)) | |
1862 | expanded = m_imageList->GetIcon( expandedIndex ); | |
777f9cef | 1863 | |
a75124d0 RR |
1864 | return GetStore()->PrependContainer( parent, text, icon, expanded, data ); |
1865 | } | |
1866 | ||
1867 | wxDataViewItem wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem& parent, | |
1868 | const wxString &text, int iconIndex, int expandedIndex, wxClientData *data ) | |
1869 | { | |
1870 | wxIcon icon = wxNullIcon; | |
1871 | if (m_imageList && (iconIndex != -1)) | |
1872 | icon = m_imageList->GetIcon( iconIndex ); | |
777f9cef | 1873 | |
a75124d0 RR |
1874 | wxIcon expanded = wxNullIcon; |
1875 | if (m_imageList && (expandedIndex != -1)) | |
1876 | expanded = m_imageList->GetIcon( expandedIndex ); | |
777f9cef | 1877 | |
a75124d0 RR |
1878 | return GetStore()->AppendContainer( parent, text, icon, expanded, data ); |
1879 | } | |
1880 | ||
1881 | wxDataViewItem wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous, | |
1882 | const wxString &text, int iconIndex, int expandedIndex, wxClientData *data ) | |
1883 | { | |
1884 | wxIcon icon = wxNullIcon; | |
1885 | if (m_imageList && (iconIndex != -1)) | |
1886 | icon = m_imageList->GetIcon( iconIndex ); | |
777f9cef | 1887 | |
a75124d0 RR |
1888 | wxIcon expanded = wxNullIcon; |
1889 | if (m_imageList && (expandedIndex != -1)) | |
1890 | expanded = m_imageList->GetIcon( expandedIndex ); | |
777f9cef | 1891 | |
a75124d0 RR |
1892 | return GetStore()->InsertContainer( parent, previous, text, icon, expanded, data ); |
1893 | } | |
1894 | ||
a75124d0 RR |
1895 | void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent &event ) |
1896 | { | |
1897 | if (m_imageList) return; | |
777f9cef | 1898 | |
a75124d0 RR |
1899 | wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() ); |
1900 | if (!container) return; | |
777f9cef | 1901 | |
a75124d0 RR |
1902 | container->SetExpanded( true ); |
1903 | GetStore()->ItemChanged( event.GetItem() ); | |
1904 | } | |
1905 | ||
1906 | void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent &event ) | |
1907 | { | |
1908 | if (m_imageList) return; | |
777f9cef | 1909 | |
a75124d0 RR |
1910 | wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() ); |
1911 | if (!container) return; | |
777f9cef | 1912 | |
a75124d0 RR |
1913 | container->SetExpanded( false ); |
1914 | GetStore()->ItemChanged( event.GetItem() ); | |
1915 | } | |
1916 | ||
a6aaf49f | 1917 | void wxDataViewTreeCtrl::OnSize( wxSizeEvent &event ) |
1a07a730 | 1918 | { |
ad386793 | 1919 | #if defined(wxUSE_GENERICDATAVIEWCTRL) |
9c150d5f RR |
1920 | wxSize size = GetClientSize(); |
1921 | wxDataViewColumn *col = GetColumn( 0 ); | |
777f9cef | 1922 | if (col) |
ad386793 | 1923 | col->SetWidth( size.x ); |
1a07a730 | 1924 | #endif |
a6aaf49f | 1925 | event.Skip( true ); |
1a07a730 | 1926 | } |
a75124d0 | 1927 | |
b5ec7dd6 | 1928 | #endif // wxUSE_DATAVIEWCTRL |
e0000f94 | 1929 |