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