]>
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 PC |
20 | #include "wx/dataview.h" |
21 | ||
52e750fc | 22 | #include "wx/spinctrl.h" |
52e750fc | 23 | |
f554a14b | 24 | #ifndef WX_PRECOMP |
c3c62822 PC |
25 | #include "wx/dc.h" |
26 | #include "wx/settings.h" | |
f554a14b | 27 | #include "wx/log.h" |
e94d0c1e | 28 | #include "wx/icon.h" |
c3c62822 | 29 | #include "wx/crt.h" |
f554a14b WS |
30 | #endif |
31 | ||
4a2e5ee8 | 32 | const wxChar wxDataViewCtrlNameStr[] = wxT("dataviewCtrl"); |
239eaa41 | 33 | |
239eaa41 | 34 | |
d5025dc0 RR |
35 | bool operator == (const wxDataViewItem &left, const wxDataViewItem &right) |
36 | { | |
37 | return (left.GetID() == right.GetID() ); | |
38 | } | |
39 | ||
c3c62822 PC |
40 | #ifdef __WXDEBUG__ |
41 | void wxDataViewItem::Print(const wxString& text) const | |
42 | { | |
43 | wxPrintf("item %s: %l\n", text, (long)m_id); | |
44 | } | |
45 | #endif | |
d5025dc0 | 46 | |
f554a14b | 47 | // --------------------------------------------------------- |
854cdb09 | 48 | // wxDataViewModelNotifier |
f554a14b | 49 | // --------------------------------------------------------- |
239eaa41 | 50 | |
8ab03001 | 51 | #include "wx/listimpl.cpp" |
a76c2f37 | 52 | WX_DEFINE_LIST(wxDataViewModelNotifiers) |
9d8fe14a | 53 | |
854cdb09 RR |
54 | bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items ) |
55 | { | |
56 | size_t count = items.GetCount(); | |
57 | size_t i; | |
58 | for (i = 0; i < count; i++) | |
59 | if (!ItemAdded( parent, items[i] )) return false; | |
b5ec7dd6 | 60 | |
854cdb09 RR |
61 | return true; |
62 | } | |
63 | ||
64 | bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items ) | |
65 | { | |
66 | size_t count = items.GetCount(); | |
67 | size_t i; | |
68 | for (i = 0; i < count; i++) | |
69 | if (!ItemDeleted( parent, items[i] )) return false; | |
b5ec7dd6 | 70 | |
854cdb09 RR |
71 | return true; |
72 | } | |
73 | ||
74 | bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray &items ) | |
75 | { | |
76 | size_t count = items.GetCount(); | |
77 | size_t i; | |
78 | for (i = 0; i < count; i++) | |
79 | if (!ItemChanged( items[i] )) return false; | |
b5ec7dd6 | 80 | |
854cdb09 RR |
81 | return true; |
82 | } | |
83 | ||
84 | // --------------------------------------------------------- | |
85 | // wxDataViewModel | |
86 | // --------------------------------------------------------- | |
87 | ||
e0062c04 | 88 | wxDataViewModel::wxDataViewModel() |
239eaa41 | 89 | { |
8f850e28 | 90 | m_notifiers.DeleteContents( true ); |
239eaa41 RR |
91 | } |
92 | ||
e0062c04 | 93 | bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) |
239eaa41 | 94 | { |
8f850e28 RR |
95 | bool ret = true; |
96 | ||
9d8fe14a RR |
97 | wxDataViewModelNotifiers::iterator iter; |
98 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
8f850e28 | 99 | { |
9d8fe14a | 100 | wxDataViewModelNotifier* notifier = *iter; |
e0062c04 | 101 | if (!notifier->ItemAdded( parent, item )) |
8f850e28 | 102 | ret = false; |
8f850e28 | 103 | } |
f554a14b | 104 | |
8f850e28 | 105 | return ret; |
239eaa41 RR |
106 | } |
107 | ||
469d3e9b | 108 | bool wxDataViewModel::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) |
239eaa41 | 109 | { |
8f850e28 RR |
110 | bool ret = true; |
111 | ||
9d8fe14a RR |
112 | wxDataViewModelNotifiers::iterator iter; |
113 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
8f850e28 | 114 | { |
9d8fe14a | 115 | wxDataViewModelNotifier* notifier = *iter; |
469d3e9b | 116 | if (!notifier->ItemDeleted( parent, item )) |
8f850e28 | 117 | ret = false; |
8f850e28 | 118 | } |
f554a14b | 119 | |
8f850e28 | 120 | return ret; |
239eaa41 RR |
121 | } |
122 | ||
e0062c04 | 123 | bool wxDataViewModel::ItemChanged( const wxDataViewItem &item ) |
239eaa41 | 124 | { |
8f850e28 RR |
125 | bool ret = true; |
126 | ||
9d8fe14a RR |
127 | wxDataViewModelNotifiers::iterator iter; |
128 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
8f850e28 | 129 | { |
9d8fe14a | 130 | wxDataViewModelNotifier* notifier = *iter; |
e0062c04 | 131 | if (!notifier->ItemChanged( item )) |
8f850e28 | 132 | ret = false; |
8f850e28 | 133 | } |
f554a14b | 134 | |
8f850e28 | 135 | return ret; |
239eaa41 RR |
136 | } |
137 | ||
854cdb09 RR |
138 | bool wxDataViewModel::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items ) |
139 | { | |
140 | bool ret = true; | |
141 | ||
142 | wxDataViewModelNotifiers::iterator iter; | |
143 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
144 | { | |
145 | wxDataViewModelNotifier* notifier = *iter; | |
146 | if (!notifier->ItemsAdded( parent, items )) | |
147 | ret = false; | |
148 | } | |
149 | ||
150 | return ret; | |
151 | } | |
152 | ||
153 | bool wxDataViewModel::ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items ) | |
154 | { | |
155 | bool ret = true; | |
156 | ||
157 | wxDataViewModelNotifiers::iterator iter; | |
158 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
159 | { | |
160 | wxDataViewModelNotifier* notifier = *iter; | |
161 | if (!notifier->ItemsDeleted( parent, items )) | |
162 | ret = false; | |
163 | } | |
164 | ||
165 | return ret; | |
166 | } | |
167 | ||
168 | bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray &items ) | |
169 | { | |
170 | bool ret = true; | |
171 | ||
172 | wxDataViewModelNotifiers::iterator iter; | |
173 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
174 | { | |
175 | wxDataViewModelNotifier* notifier = *iter; | |
176 | if (!notifier->ItemsChanged( items )) | |
177 | ret = false; | |
178 | } | |
179 | ||
180 | return ret; | |
181 | } | |
182 | ||
e0062c04 | 183 | bool wxDataViewModel::ValueChanged( const wxDataViewItem &item, unsigned int col ) |
239eaa41 | 184 | { |
8f850e28 | 185 | bool ret = true; |
b5d777c7 | 186 | |
9d8fe14a RR |
187 | wxDataViewModelNotifiers::iterator iter; |
188 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
b5d777c7 | 189 | { |
9d8fe14a | 190 | wxDataViewModelNotifier* notifier = *iter; |
e0062c04 | 191 | if (!notifier->ValueChanged( item, col )) |
8f850e28 | 192 | ret = false; |
b5d777c7 | 193 | } |
f554a14b | 194 | |
b5d777c7 | 195 | return ret; |
239eaa41 RR |
196 | } |
197 | ||
e0062c04 | 198 | bool wxDataViewModel::Cleared() |
4eccd3a1 RR |
199 | { |
200 | bool ret = true; | |
201 | ||
9d8fe14a RR |
202 | wxDataViewModelNotifiers::iterator iter; |
203 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
4eccd3a1 | 204 | { |
9d8fe14a | 205 | wxDataViewModelNotifier* notifier = *iter; |
8f850e28 RR |
206 | if (!notifier->Cleared()) |
207 | ret = false; | |
8f850e28 | 208 | } |
f554a14b | 209 | |
8f850e28 | 210 | return ret; |
239eaa41 RR |
211 | } |
212 | ||
ef427989 RR |
213 | void wxDataViewModel::Resort() |
214 | { | |
9d8fe14a RR |
215 | wxDataViewModelNotifiers::iterator iter; |
216 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
ef427989 | 217 | { |
9d8fe14a | 218 | wxDataViewModelNotifier* notifier = *iter; |
ef427989 | 219 | notifier->Resort(); |
ef427989 RR |
220 | } |
221 | } | |
222 | ||
e0062c04 | 223 | void wxDataViewModel::AddNotifier( wxDataViewModelNotifier *notifier ) |
239eaa41 | 224 | { |
9d8fe14a | 225 | m_notifiers.push_back( notifier ); |
8f850e28 | 226 | notifier->SetOwner( this ); |
239eaa41 RR |
227 | } |
228 | ||
e0062c04 | 229 | void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier ) |
239eaa41 | 230 | { |
8f850e28 | 231 | m_notifiers.DeleteObject( notifier ); |
239eaa41 RR |
232 | } |
233 | ||
7ee7191c RR |
234 | int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, |
235 | unsigned int column, bool ascending ) | |
ef427989 | 236 | { |
cf283a47 | 237 | // sort branches before leaves |
ed903e42 RR |
238 | bool item1_is_container = IsContainer(item1); |
239 | bool item2_is_container = IsContainer(item2); | |
900af470 | 240 | |
ed903e42 | 241 | if (item1_is_container && !item2_is_container) |
cf283a47 | 242 | return 1; |
ed903e42 | 243 | if (item2_is_container && !item1_is_container) |
cf283a47 | 244 | return -1; |
900af470 | 245 | |
ef427989 | 246 | wxVariant value1,value2; |
7ee7191c RR |
247 | GetValue( value1, item1, column ); |
248 | GetValue( value2, item2, column ); | |
249 | ||
250 | if (!ascending) | |
251 | { | |
252 | wxVariant temp = value1; | |
253 | value1 = value2; | |
254 | value2 = temp; | |
255 | } | |
cf283a47 | 256 | |
ef427989 RR |
257 | if (value1.GetType() == wxT("string")) |
258 | { | |
259 | wxString str1 = value1.GetString(); | |
260 | wxString str2 = value2.GetString(); | |
0be79c8a | 261 | int res = str1.Cmp( str2 ); |
cf283a47 RR |
262 | if (res) return res; |
263 | } else | |
ef427989 RR |
264 | if (value1.GetType() == wxT("long")) |
265 | { | |
266 | long l1 = value1.GetLong(); | |
267 | long l2 = value2.GetLong(); | |
cf283a47 RR |
268 | long res = l1-l2; |
269 | if (res) return res; | |
270 | } else | |
ef427989 RR |
271 | if (value1.GetType() == wxT("double")) |
272 | { | |
273 | double d1 = value1.GetDouble(); | |
274 | double d2 = value2.GetDouble(); | |
ef427989 | 275 | if (d1 < d2) return 1; |
cf283a47 RR |
276 | if (d1 > d2) return -1; |
277 | } else | |
ef427989 RR |
278 | if (value1.GetType() == wxT("datetime")) |
279 | { | |
280 | wxDateTime dt1 = value1.GetDateTime(); | |
281 | wxDateTime dt2 = value2.GetDateTime(); | |
ef427989 | 282 | if (dt1.IsEarlierThan(dt2)) return 1; |
cf283a47 | 283 | if (dt2.IsEarlierThan(dt1)) return -11; |
ef427989 RR |
284 | } |
285 | ||
cf283a47 | 286 | // items must be different |
900af470 JS |
287 | unsigned long litem1 = (unsigned long) item1.GetID(); |
288 | unsigned long litem2 = (unsigned long) item2.GetID(); | |
b7fe2261 | 289 | |
7ee7191c RR |
290 | if (!ascending) |
291 | return litem2-litem2; | |
cf283a47 | 292 | |
cf283a47 | 293 | return litem1-litem2; |
ef427989 RR |
294 | } |
295 | ||
c534e696 RR |
296 | // --------------------------------------------------------- |
297 | // wxDataViewIndexListModel | |
298 | // --------------------------------------------------------- | |
299 | ||
300 | wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size ) | |
301 | { | |
a3cc79d9 | 302 | #ifndef __WXMAC__ |
2056dede RR |
303 | m_useHash = false; |
304 | #else | |
305 | m_useHash = true; | |
306 | #endif | |
517166e6 | 307 | |
2056dede RR |
308 | if (m_useHash) |
309 | { | |
310 | // IDs are ordered until an item gets deleted or inserted | |
311 | m_ordered = true; | |
312 | ||
313 | // build initial index | |
314 | unsigned int i; | |
315 | for (i = 1; i < initial_size+1; i++) | |
316 | m_hash.Add( (void*) i ); | |
317 | m_lastIndex = initial_size + 1; | |
318 | } | |
319 | else | |
320 | { | |
321 | m_lastIndex = initial_size-1; | |
322 | } | |
c534e696 RR |
323 | } |
324 | ||
325 | wxDataViewIndexListModel::~wxDataViewIndexListModel() | |
326 | { | |
327 | } | |
328 | ||
329 | void wxDataViewIndexListModel::RowPrepended() | |
330 | { | |
2056dede RR |
331 | if (m_useHash) |
332 | { | |
333 | m_ordered = false; | |
f8cad1a1 | 334 | |
2056dede RR |
335 | unsigned int id = m_lastIndex++; |
336 | m_hash.Insert( (void*) id, 0 ); | |
337 | wxDataViewItem item( (void*) id ); | |
338 | ItemAdded( wxDataViewItem(0), item ); | |
339 | } | |
340 | else | |
341 | { | |
342 | m_lastIndex++; | |
343 | wxDataViewItem item( (void*) 0 ); | |
344 | ItemAdded( wxDataViewItem(0), item ); | |
345 | } | |
c534e696 RR |
346 | } |
347 | ||
348 | void wxDataViewIndexListModel::RowInserted( unsigned int before ) | |
349 | { | |
2056dede RR |
350 | if (m_useHash) |
351 | { | |
352 | m_ordered = false; | |
f8cad1a1 | 353 | |
2056dede RR |
354 | unsigned int id = m_lastIndex++; |
355 | m_hash.Insert( (void*) id, before ); | |
356 | wxDataViewItem item( (void*) id ); | |
357 | ItemAdded( wxDataViewItem(0), item ); | |
358 | } | |
359 | else | |
360 | { | |
361 | m_lastIndex++; | |
362 | wxDataViewItem item( (void*) before ); | |
363 | ItemAdded( wxDataViewItem(0), item ); | |
364 | } | |
c534e696 RR |
365 | } |
366 | ||
367 | void wxDataViewIndexListModel::RowAppended() | |
368 | { | |
2056dede RR |
369 | if (m_useHash) |
370 | { | |
371 | unsigned int id = m_lastIndex++; | |
372 | m_hash.Add( (void*) id ); | |
373 | wxDataViewItem item( (void*) id ); | |
374 | ItemAdded( wxDataViewItem(0), item ); | |
375 | } | |
376 | else | |
377 | { | |
378 | m_lastIndex++; | |
379 | wxDataViewItem item( (void*) m_lastIndex ); | |
380 | ItemAdded( wxDataViewItem(0), item ); | |
381 | } | |
c534e696 RR |
382 | } |
383 | ||
384 | void wxDataViewIndexListModel::RowDeleted( unsigned int row ) | |
385 | { | |
2056dede RR |
386 | if (m_useHash) |
387 | { | |
388 | wxDataViewItem item( m_hash[row] ); | |
389 | wxDataViewModel::ItemDeleted( wxDataViewItem(0), item ); | |
390 | m_hash.RemoveAt( row ); | |
391 | } | |
392 | else | |
393 | { | |
394 | wxDataViewItem item( (void*) row ); | |
395 | wxDataViewModel::ItemDeleted( wxDataViewItem(0), item ); | |
396 | m_lastIndex++; | |
397 | } | |
c534e696 RR |
398 | } |
399 | ||
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 | { | |
2056dede | 412 | if (m_useHash) |
517166e6 | 413 | { |
2056dede RR |
414 | if (m_ordered) |
415 | { | |
416 | unsigned int pos = wxPtrToUInt( item.GetID() ); | |
417 | return pos-1; | |
418 | } | |
517166e6 | 419 | |
2056dede RR |
420 | // assert for not found |
421 | return (unsigned int) m_hash.Index( item.GetID() ); | |
422 | } | |
423 | else | |
424 | { | |
425 | return wxPtrToUInt( item.GetID() ); | |
426 | } | |
c534e696 RR |
427 | } |
428 | ||
429 | wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const | |
430 | { | |
2056dede RR |
431 | if (m_useHash) |
432 | { | |
433 | wxASSERT( row < m_hash.GetCount() ); | |
434 | return wxDataViewItem( m_hash[row] ); | |
435 | } | |
436 | else | |
437 | { | |
438 | return wxDataViewItem( (void*) row ); | |
439 | } | |
c534e696 RR |
440 | } |
441 | ||
517166e6 RR |
442 | bool wxDataViewIndexListModel::HasDefaultCompare() const |
443 | { | |
444 | return !m_ordered; | |
445 | } | |
446 | ||
b7fe2261 VZ |
447 | int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1, |
448 | const wxDataViewItem& item2, | |
449 | unsigned int WXUNUSED(column), | |
450 | bool ascending) | |
c534e696 | 451 | { |
2056dede | 452 | if (m_ordered || !m_useHash) |
517166e6 | 453 | { |
ec935ba8 PC |
454 | unsigned int pos1 = wxPtrToUInt(item1.GetID()); |
455 | unsigned int pos2 = wxPtrToUInt(item2.GetID()); | |
517166e6 RR |
456 | |
457 | if (ascending) | |
458 | return pos1 - pos2; | |
459 | else | |
460 | return pos2 - pos1; | |
461 | } | |
462 | ||
7ee7191c RR |
463 | if (ascending) |
464 | return GetRow(item1) - GetRow(item2); | |
b7fe2261 | 465 | |
7ee7191c | 466 | return GetRow(item2) - GetRow(item1); |
c534e696 RR |
467 | } |
468 | ||
900af470 | 469 | void wxDataViewIndexListModel::GetValue( wxVariant &variant, |
c534e696 RR |
470 | const wxDataViewItem &item, unsigned int col ) const |
471 | { | |
900af470 | 472 | GetValue( variant, GetRow(item), col ); |
c534e696 RR |
473 | } |
474 | ||
900af470 | 475 | bool wxDataViewIndexListModel::SetValue( const wxVariant &variant, |
c534e696 RR |
476 | const wxDataViewItem &item, unsigned int col ) |
477 | { | |
478 | return SetValue( variant, GetRow(item), col ); | |
479 | } | |
480 | ||
4264606e RR |
481 | bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr ) |
482 | { | |
483 | return GetAttr( GetRow(item), col, attr ); | |
484 | } | |
485 | ||
900af470 | 486 | wxDataViewItem wxDataViewIndexListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const |
c534e696 RR |
487 | { |
488 | return wxDataViewItem(0); | |
489 | } | |
490 | ||
491 | bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem &item ) const | |
492 | { | |
493 | // only the invisible root item has children | |
494 | if (!item.IsOk()) | |
495 | return true; | |
900af470 | 496 | |
c534e696 RR |
497 | return false; |
498 | } | |
499 | ||
74fe973b | 500 | unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const |
c534e696 | 501 | { |
eff112a6 | 502 | if (!m_useHash) |
2056dede RR |
503 | return 0; // error |
504 | ||
74fe973b RR |
505 | if (item.IsOk()) |
506 | return 0; | |
c534e696 | 507 | |
74fe973b | 508 | children = m_hash; |
b7fe2261 | 509 | |
74fe973b | 510 | return m_hash.GetCount(); |
c534e696 RR |
511 | } |
512 | ||
89352653 RR |
513 | //----------------------------------------------------------------------------- |
514 | // wxDataViewIconText | |
515 | //----------------------------------------------------------------------------- | |
516 | ||
517 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText,wxObject) | |
518 | ||
d350fbec | 519 | IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV) |
89352653 RR |
520 | |
521 | bool operator == (const wxDataViewIconText &one, const wxDataViewIconText &two) | |
522 | { | |
523 | if (one.GetText() != two.GetText()) return false; | |
524 | if (one.IsSameAs(two)) return false; | |
525 | return true; | |
526 | } | |
527 | ||
f554a14b | 528 | // --------------------------------------------------------- |
baa9ebc4 | 529 | // wxDataViewRendererBase |
f554a14b | 530 | // --------------------------------------------------------- |
6842a71a | 531 | |
baa9ebc4 | 532 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase, wxObject) |
6842a71a | 533 | |
900af470 | 534 | wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype, |
9861f022 RR |
535 | wxDataViewCellMode WXUNUSED(mode), |
536 | int WXUNUSED(align) ) | |
6842a71a RR |
537 | { |
538 | m_variantType = varianttype; | |
1e510b1e | 539 | m_editorCtrl = NULL; |
9861f022 RR |
540 | } |
541 | ||
542 | const wxDataViewCtrl* wxDataViewRendererBase::GetView() const | |
543 | { | |
544 | return wx_const_cast(wxDataViewRendererBase*, this)->GetOwner()->GetOwner(); | |
6842a71a | 545 | } |
f554a14b | 546 | |
e0062c04 | 547 | bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect ) |
1e510b1e | 548 | { |
e0062c04 | 549 | m_item = item; // remember for later |
900af470 | 550 | |
1e510b1e RR |
551 | unsigned int col = GetOwner()->GetModelColumn(); |
552 | wxVariant value; | |
e0062c04 | 553 | GetOwner()->GetOwner()->GetModel()->GetValue( value, item, col ); |
900af470 | 554 | |
1e510b1e | 555 | m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value ); |
900af470 JS |
556 | |
557 | wxDataViewEditorCtrlEvtHandler *handler = | |
30715fa1 | 558 | new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this ); |
900af470 | 559 | |
30715fa1 | 560 | m_editorCtrl->PushEventHandler( handler ); |
900af470 | 561 | |
30715fa1 RR |
562 | #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL) |
563 | handler->SetFocusOnIdle(); | |
564 | #else | |
1e510b1e | 565 | m_editorCtrl->SetFocus(); |
30715fa1 RR |
566 | #endif |
567 | ||
afebb87b RR |
568 | // Now we should send Editing Started event |
569 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, GetOwner()->GetOwner()->GetId() ); | |
570 | event.SetDataViewColumn( GetOwner() ); | |
571 | event.SetModel( GetOwner()->GetOwner()->GetModel() ); | |
572 | event.SetItem( item ); | |
afebb87b RR |
573 | GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event ); |
574 | ||
1e510b1e RR |
575 | return true; |
576 | } | |
577 | ||
578 | void wxDataViewRendererBase::CancelEditing() | |
579 | { | |
2fa73716 | 580 | wxPendingDelete.Append( m_editorCtrl ); |
900af470 | 581 | |
1e510b1e | 582 | GetOwner()->GetOwner()->GetMainWindow()->SetFocus(); |
900af470 | 583 | |
2fa73716 | 584 | // m_editorCtrl->PopEventHandler( true ); |
1e510b1e RR |
585 | } |
586 | ||
587 | bool wxDataViewRendererBase::FinishEditing() | |
588 | { | |
1e510b1e RR |
589 | wxVariant value; |
590 | GetValueFromEditorCtrl( m_editorCtrl, value ); | |
591 | ||
2fa73716 | 592 | wxPendingDelete.Append( m_editorCtrl ); |
900af470 | 593 | |
1e510b1e | 594 | GetOwner()->GetOwner()->GetMainWindow()->SetFocus(); |
900af470 | 595 | |
1e510b1e RR |
596 | if (!Validate(value)) |
597 | return false; | |
900af470 | 598 | |
1e510b1e | 599 | unsigned int col = GetOwner()->GetModelColumn(); |
e0062c04 RR |
600 | GetOwner()->GetOwner()->GetModel()->SetValue( value, m_item, col ); |
601 | GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item, col ); | |
900af470 | 602 | |
2fa73716 | 603 | // m_editorCtrl->PopEventHandler( true ); |
b7fe2261 | 604 | |
afebb87b RR |
605 | // Now we should send Editing Done event |
606 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, GetOwner()->GetOwner()->GetId() ); | |
607 | event.SetDataViewColumn( GetOwner() ); | |
608 | event.SetModel( GetOwner()->GetOwner()->GetModel() ); | |
8fdaf7de | 609 | event.SetItem( m_item ); |
afebb87b | 610 | GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event ); |
900af470 | 611 | |
1e510b1e RR |
612 | return true; |
613 | } | |
614 | ||
615 | //----------------------------------------------------------------------------- | |
616 | // wxDataViewEditorCtrlEvtHandler | |
617 | //----------------------------------------------------------------------------- | |
618 | ||
619 | BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler) | |
620 | EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar) | |
621 | EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus) | |
30715fa1 | 622 | EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle) |
1e510b1e RR |
623 | END_EVENT_TABLE() |
624 | ||
625 | wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler( | |
626 | wxControl *editorCtrl, | |
627 | wxDataViewRenderer *owner ) | |
628 | { | |
629 | m_owner = owner; | |
630 | m_editorCtrl = editorCtrl; | |
631 | ||
632 | m_finished = false; | |
633 | } | |
634 | ||
30715fa1 RR |
635 | void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event ) |
636 | { | |
637 | if (m_focusOnIdle) | |
638 | { | |
639 | m_focusOnIdle = false; | |
640 | if (wxWindow::FindFocus() != m_editorCtrl) | |
641 | m_editorCtrl->SetFocus(); | |
642 | } | |
900af470 | 643 | |
30715fa1 RR |
644 | event.Skip(); |
645 | } | |
646 | ||
1e510b1e RR |
647 | void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event ) |
648 | { | |
649 | switch ( event.m_keyCode ) | |
650 | { | |
651 | case WXK_RETURN: | |
652 | m_finished = true; | |
653 | m_owner->FinishEditing(); | |
654 | break; | |
655 | ||
656 | case WXK_ESCAPE: | |
657 | m_finished = true; | |
658 | m_owner->CancelEditing(); | |
659 | break; | |
660 | ||
661 | default: | |
662 | event.Skip(); | |
663 | } | |
664 | } | |
665 | ||
666 | void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event ) | |
667 | { | |
668 | if (!m_finished) | |
669 | { | |
670 | m_finished = true; | |
671 | m_owner->FinishEditing(); | |
672 | } | |
673 | ||
1e510b1e RR |
674 | event.Skip(); |
675 | } | |
676 | ||
f554a14b | 677 | // --------------------------------------------------------- |
fa28826d | 678 | // wxDataViewColumnBase |
f554a14b | 679 | // --------------------------------------------------------- |
fa28826d RR |
680 | |
681 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject) | |
682 | ||
9861f022 | 683 | wxDataViewColumnBase::wxDataViewColumnBase(const wxString& WXUNUSED(title), |
baa9ebc4 | 684 | wxDataViewRenderer *renderer, |
0a71f9e9 | 685 | unsigned int model_column, |
008b5a66 | 686 | int WXUNUSED(width), |
87f0efe2 | 687 | wxAlignment WXUNUSED(align), |
900af470 | 688 | int WXUNUSED(flags)) |
fa28826d | 689 | { |
baa9ebc4 | 690 | m_renderer = renderer; |
6842a71a | 691 | m_model_column = model_column; |
6842a71a | 692 | m_owner = NULL; |
baa9ebc4 | 693 | m_renderer->SetOwner( (wxDataViewColumn*) this ); |
9861f022 RR |
694 | |
695 | // NOTE: the wxDataViewColumn's ctor must store the width, align, flags | |
696 | // parameters inside the native control! | |
6842a71a RR |
697 | } |
698 | ||
07a84e7b RR |
699 | wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap& bitmap, |
700 | wxDataViewRenderer *renderer, | |
701 | unsigned int model_column, | |
702 | int WXUNUSED(width), | |
87f0efe2 | 703 | wxAlignment WXUNUSED(align), |
900af470 | 704 | int WXUNUSED(flags) ) |
07a84e7b RR |
705 | { |
706 | m_renderer = renderer; | |
707 | m_model_column = model_column; | |
07a84e7b RR |
708 | m_bitmap = bitmap; |
709 | m_owner = NULL; | |
710 | m_renderer->SetOwner( (wxDataViewColumn*) this ); | |
711 | } | |
712 | ||
6842a71a RR |
713 | wxDataViewColumnBase::~wxDataViewColumnBase() |
714 | { | |
baa9ebc4 RR |
715 | if (m_renderer) |
716 | delete m_renderer; | |
fa28826d RR |
717 | } |
718 | ||
9861f022 | 719 | int wxDataViewColumnBase::GetFlags() const |
fa28826d | 720 | { |
9861f022 | 721 | int ret = 0; |
fa28826d | 722 | |
9861f022 RR |
723 | if (IsSortable()) |
724 | ret |= wxDATAVIEW_COL_SORTABLE; | |
725 | if (IsResizeable()) | |
726 | ret |= wxDATAVIEW_COL_RESIZABLE; | |
727 | if (IsHidden()) | |
728 | ret |= wxDATAVIEW_COL_HIDDEN; | |
fa28826d | 729 | |
9861f022 | 730 | return ret; |
07a84e7b RR |
731 | } |
732 | ||
9861f022 | 733 | void wxDataViewColumnBase::SetFlags(int flags) |
07a84e7b | 734 | { |
9861f022 RR |
735 | SetSortable((flags & wxDATAVIEW_COL_SORTABLE) != 0); |
736 | SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0); | |
737 | SetHidden((flags & wxDATAVIEW_COL_HIDDEN) != 0); | |
07a84e7b RR |
738 | } |
739 | ||
f554a14b | 740 | // --------------------------------------------------------- |
239eaa41 | 741 | // wxDataViewCtrlBase |
f554a14b | 742 | // --------------------------------------------------------- |
239eaa41 RR |
743 | |
744 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl) | |
745 | ||
746 | wxDataViewCtrlBase::wxDataViewCtrlBase() | |
747 | { | |
748 | m_model = NULL; | |
3b6280be RR |
749 | m_expander_column = 0; |
750 | m_indent = 8; | |
239eaa41 RR |
751 | } |
752 | ||
753 | wxDataViewCtrlBase::~wxDataViewCtrlBase() | |
754 | { | |
87f0efe2 RR |
755 | if (m_model) |
756 | { | |
757 | m_model->DecRef(); | |
758 | m_model = NULL; | |
759 | } | |
239eaa41 RR |
760 | } |
761 | ||
e0062c04 | 762 | bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model ) |
239eaa41 | 763 | { |
1821abd1 RR |
764 | if (m_model) |
765 | { | |
87f0efe2 | 766 | m_model->DecRef(); // discard old model, if any |
1821abd1 | 767 | } |
87f0efe2 RR |
768 | |
769 | // add our own reference to the new model: | |
239eaa41 | 770 | m_model = model; |
1821abd1 RR |
771 | if (m_model) |
772 | { | |
900af470 | 773 | m_model->IncRef(); |
1821abd1 | 774 | } |
f554a14b | 775 | |
239eaa41 RR |
776 | return true; |
777 | } | |
778 | ||
e0062c04 | 779 | wxDataViewModel* wxDataViewCtrlBase::GetModel() |
239eaa41 RR |
780 | { |
781 | return m_model; | |
782 | } | |
783 | ||
c7074d44 RR |
784 | wxDataViewColumn * |
785 | wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 786 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
fa28826d | 787 | { |
c7074d44 | 788 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 789 | new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), |
c7074d44 RR |
790 | model_column, width, align, flags ); |
791 | AppendColumn( ret ); | |
792 | return ret; | |
fa28826d RR |
793 | } |
794 | ||
b04fcede RR |
795 | wxDataViewColumn * |
796 | wxDataViewCtrlBase::AppendIconTextColumn( const wxString &label, unsigned int model_column, | |
797 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
798 | { | |
799 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
800 | new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), | |
801 | model_column, width, align, flags ); | |
802 | AppendColumn( ret ); | |
803 | return ret; | |
804 | } | |
805 | ||
c7074d44 RR |
806 | wxDataViewColumn * |
807 | wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 808 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
605c2c4a | 809 | { |
b7fe2261 | 810 | |
c7074d44 | 811 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 812 | new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), |
c7074d44 RR |
813 | model_column, width, align, flags ); |
814 | AppendColumn( ret ); | |
815 | return ret; | |
605c2c4a RR |
816 | } |
817 | ||
c7074d44 RR |
818 | wxDataViewColumn * |
819 | wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 820 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
ad63bf41 | 821 | { |
c7074d44 | 822 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 823 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), |
c7074d44 RR |
824 | model_column, width, align, flags ); |
825 | AppendColumn( ret ); | |
826 | return ret; | |
ad63bf41 RR |
827 | } |
828 | ||
c7074d44 RR |
829 | wxDataViewColumn * |
830 | wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 831 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
4d496ecb | 832 | { |
c7074d44 | 833 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 834 | new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), |
c7074d44 RR |
835 | model_column, width, align, flags ); |
836 | AppendColumn( ret ); | |
837 | return ret; | |
4d496ecb RR |
838 | } |
839 | ||
c7074d44 RR |
840 | wxDataViewColumn * |
841 | wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 842 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 843 | { |
c7074d44 | 844 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 845 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), |
c7074d44 RR |
846 | model_column, width, align, flags ); |
847 | AppendColumn( ret ); | |
848 | return ret; | |
07a84e7b RR |
849 | } |
850 | ||
c7074d44 RR |
851 | wxDataViewColumn * |
852 | wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 853 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 854 | { |
c7074d44 | 855 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 856 | new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), |
c7074d44 RR |
857 | model_column, width, align, flags ); |
858 | AppendColumn( ret ); | |
859 | return ret; | |
b04fcede RR |
860 | } |
861 | ||
862 | wxDataViewColumn * | |
863 | wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap &label, unsigned int model_column, | |
864 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
865 | { | |
866 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
867 | new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), | |
868 | model_column, width, align, flags ); | |
869 | AppendColumn( ret ); | |
870 | return ret; | |
07a84e7b RR |
871 | } |
872 | ||
c7074d44 RR |
873 | wxDataViewColumn * |
874 | wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 875 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 876 | { |
c7074d44 | 877 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 878 | new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), |
c7074d44 RR |
879 | model_column, width, align, flags ); |
880 | AppendColumn( ret ); | |
881 | return ret; | |
07a84e7b RR |
882 | } |
883 | ||
c7074d44 RR |
884 | wxDataViewColumn * |
885 | wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 886 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 887 | { |
c7074d44 | 888 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 889 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), |
c7074d44 RR |
890 | model_column, width, align, flags ); |
891 | AppendColumn( ret ); | |
892 | return ret; | |
07a84e7b RR |
893 | } |
894 | ||
c7074d44 RR |
895 | wxDataViewColumn * |
896 | wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 897 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 898 | { |
c7074d44 | 899 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 900 | new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), |
c7074d44 RR |
901 | model_column, width, align, flags ); |
902 | AppendColumn( ret ); | |
903 | return ret; | |
07a84e7b RR |
904 | } |
905 | ||
c7074d44 RR |
906 | wxDataViewColumn * |
907 | wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 908 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 909 | { |
c7074d44 | 910 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 911 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), |
c7074d44 RR |
912 | model_column, width, align, flags ); |
913 | AppendColumn( ret ); | |
914 | return ret; | |
07a84e7b RR |
915 | } |
916 | ||
736fe67c RR |
917 | wxDataViewColumn * |
918 | wxDataViewCtrlBase::PrependTextColumn( const wxString &label, unsigned int model_column, | |
919 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
920 | { | |
921 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
922 | new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), | |
923 | model_column, width, align, flags ); | |
924 | PrependColumn( ret ); | |
925 | return ret; | |
926 | } | |
927 | ||
928 | wxDataViewColumn * | |
929 | wxDataViewCtrlBase::PrependIconTextColumn( const wxString &label, unsigned int model_column, | |
930 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
931 | { | |
932 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
933 | new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), | |
934 | model_column, width, align, flags ); | |
935 | PrependColumn( ret ); | |
936 | return ret; | |
937 | } | |
938 | ||
939 | wxDataViewColumn * | |
940 | wxDataViewCtrlBase::PrependToggleColumn( const wxString &label, unsigned int model_column, | |
941 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
942 | { | |
943 | ||
944 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
945 | new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), | |
946 | model_column, width, align, flags ); | |
947 | PrependColumn( ret ); | |
948 | return ret; | |
949 | } | |
950 | ||
951 | wxDataViewColumn * | |
952 | wxDataViewCtrlBase::PrependProgressColumn( const wxString &label, unsigned int model_column, | |
953 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
954 | { | |
955 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
956 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), | |
957 | model_column, width, align, flags ); | |
958 | PrependColumn( ret ); | |
959 | return ret; | |
960 | } | |
961 | ||
962 | wxDataViewColumn * | |
963 | wxDataViewCtrlBase::PrependDateColumn( const wxString &label, unsigned int model_column, | |
964 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
965 | { | |
966 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
967 | new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), | |
968 | model_column, width, align, flags ); | |
969 | PrependColumn( ret ); | |
970 | return ret; | |
971 | } | |
972 | ||
973 | wxDataViewColumn * | |
974 | wxDataViewCtrlBase::PrependBitmapColumn( const wxString &label, unsigned int model_column, | |
975 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
976 | { | |
977 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
978 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), | |
979 | model_column, width, align, flags ); | |
980 | PrependColumn( ret ); | |
981 | return ret; | |
982 | } | |
983 | ||
984 | wxDataViewColumn * | |
985 | wxDataViewCtrlBase::PrependTextColumn( const wxBitmap &label, unsigned int model_column, | |
986 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
987 | { | |
988 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
989 | new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), | |
990 | model_column, width, align, flags ); | |
991 | PrependColumn( ret ); | |
992 | return ret; | |
993 | } | |
994 | ||
995 | wxDataViewColumn * | |
996 | wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap &label, unsigned int model_column, | |
997 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
998 | { | |
999 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
1000 | new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), | |
1001 | model_column, width, align, flags ); | |
1002 | PrependColumn( ret ); | |
1003 | return ret; | |
1004 | } | |
1005 | ||
1006 | wxDataViewColumn * | |
1007 | wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap &label, unsigned int model_column, | |
1008 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1009 | { | |
1010 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
1011 | new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), | |
1012 | model_column, width, align, flags ); | |
1013 | PrependColumn( ret ); | |
1014 | return ret; | |
1015 | } | |
1016 | ||
1017 | wxDataViewColumn * | |
1018 | wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap &label, unsigned int model_column, | |
1019 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1020 | { | |
1021 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
1022 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), | |
1023 | model_column, width, align, flags ); | |
1024 | PrependColumn( ret ); | |
1025 | return ret; | |
1026 | } | |
1027 | ||
1028 | wxDataViewColumn * | |
1029 | wxDataViewCtrlBase::PrependDateColumn( const wxBitmap &label, unsigned int model_column, | |
1030 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1031 | { | |
1032 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
1033 | new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), | |
1034 | model_column, width, align, flags ); | |
1035 | PrependColumn( ret ); | |
1036 | return ret; | |
1037 | } | |
1038 | ||
1039 | wxDataViewColumn * | |
1040 | wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap &label, unsigned int model_column, | |
1041 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1042 | { | |
1043 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
1044 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), | |
1045 | model_column, width, align, flags ); | |
1046 | PrependColumn( ret ); | |
1047 | return ret; | |
1048 | } | |
1049 | ||
c7074d44 RR |
1050 | bool |
1051 | wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col ) | |
fa28826d | 1052 | { |
6842a71a | 1053 | col->SetOwner( (wxDataViewCtrl*) this ); |
fa28826d RR |
1054 | return true; |
1055 | } | |
1056 | ||
736fe67c RR |
1057 | bool |
1058 | wxDataViewCtrlBase::PrependColumn( wxDataViewColumn *col ) | |
1059 | { | |
1060 | col->SetOwner( (wxDataViewCtrl*) this ); | |
1061 | return true; | |
1062 | } | |
1063 | ||
eb7f97f8 RR |
1064 | // --------------------------------------------------------- |
1065 | // wxDataViewEvent | |
1066 | // --------------------------------------------------------- | |
1067 | ||
1068 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent) | |
1069 | ||
d86c1870 RR |
1070 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED) |
1071 | ||
e0062c04 | 1072 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED) |
6977c3bf | 1073 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING) |
3ecb8a53 | 1074 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED) |
6977c3bf | 1075 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING) |
3ecb8a53 | 1076 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED) |
e0000f94 RR |
1077 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED) |
1078 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE) | |
6608fdab | 1079 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED) |
e0000f94 | 1080 | |
31fb32e1 RR |
1081 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK) |
1082 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK) | |
c0a66d92 | 1083 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED) |
eb7f97f8 | 1084 | |
52e750fc RR |
1085 | |
1086 | // ------------------------------------- | |
1087 | // wxDataViewSpinRenderer | |
1088 | // ------------------------------------- | |
1089 | ||
1090 | wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min, int max, wxDataViewCellMode mode, int alignment ) : | |
b5ec7dd6 VZ |
1091 | wxDataViewCustomRenderer( "long", mode, alignment ) |
1092 | { | |
52e750fc RR |
1093 | m_min = min; |
1094 | m_max = max; | |
1095 | } | |
b5ec7dd6 | 1096 | |
52e750fc | 1097 | wxControl* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ) |
b5ec7dd6 | 1098 | { |
52e750fc | 1099 | long l = value; |
b5ec7dd6 | 1100 | return new wxSpinCtrl( parent, wxID_ANY, wxEmptyString, |
52e750fc RR |
1101 | labelRect.GetTopLeft(), labelRect.GetSize(), wxSP_ARROW_KEYS, m_min, m_max, l ); |
1102 | } | |
b5ec7dd6 | 1103 | |
52e750fc | 1104 | bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ) |
b5ec7dd6 | 1105 | { |
52e750fc RR |
1106 | wxSpinCtrl *sc = (wxSpinCtrl*) editor; |
1107 | long l = sc->GetValue(); | |
1108 | value = l; | |
1109 | return true; | |
1110 | } | |
b5ec7dd6 | 1111 | |
52e750fc RR |
1112 | bool wxDataViewSpinRenderer::Render( wxRect rect, wxDC *dc, int state ) |
1113 | { | |
1114 | wxString str; | |
1115 | str.Printf( "%d", (int) m_data ); | |
1116 | RenderText( str, 0, rect, dc, state ); | |
1117 | return true; | |
1118 | } | |
b5ec7dd6 | 1119 | |
52e750fc RR |
1120 | wxSize wxDataViewSpinRenderer::GetSize() const |
1121 | { | |
1122 | return wxSize(80,16); | |
1123 | } | |
b5ec7dd6 | 1124 | |
52e750fc RR |
1125 | bool wxDataViewSpinRenderer::SetValue( const wxVariant &value ) |
1126 | { | |
1127 | m_data = value.GetLong(); | |
1128 | return true; | |
1129 | } | |
b5ec7dd6 | 1130 | |
52e750fc RR |
1131 | bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const |
1132 | { | |
1133 | value = m_data; | |
1134 | return true; | |
1135 | } | |
1136 | ||
e94d0c1e RR |
1137 | //----------------------------------------------------------------------------- |
1138 | // wxDataViewTreeStore | |
1139 | //----------------------------------------------------------------------------- | |
1140 | ||
b5ec7dd6 VZ |
1141 | wxDataViewTreeStoreNode::wxDataViewTreeStoreNode( |
1142 | wxDataViewTreeStoreNode *parent, | |
e94d0c1e RR |
1143 | const wxString &text, const wxIcon &icon, wxClientData *data ) |
1144 | { | |
1145 | m_parent = parent; | |
1146 | m_text = text; | |
1147 | m_icon = icon; | |
1148 | m_data = data; | |
1149 | } | |
1150 | ||
1151 | wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode() | |
1152 | { | |
1153 | if (m_data) | |
1154 | delete m_data; | |
1155 | } | |
b5ec7dd6 | 1156 | |
e94d0c1e | 1157 | #include "wx/listimpl.cpp" |
a76c2f37 | 1158 | WX_DEFINE_LIST(wxDataViewTreeStoreNodeList) |
e94d0c1e | 1159 | |
b5ec7dd6 VZ |
1160 | wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode( |
1161 | wxDataViewTreeStoreNode *parent, const wxString &text, | |
e94d0c1e RR |
1162 | const wxIcon &icon, const wxIcon &expanded, wxClientData *data ) : |
1163 | wxDataViewTreeStoreNode( parent, text, icon, data ) | |
1164 | { | |
1165 | m_iconExpanded = expanded; | |
1166 | m_children.DeleteContents(true); | |
1167 | } | |
1168 | ||
1169 | wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode() | |
1170 | { | |
1171 | } | |
1172 | ||
1173 | //----------------------------------------------------------------------------- | |
1174 | ||
1175 | wxDataViewTreeStore::wxDataViewTreeStore() | |
1176 | { | |
1177 | m_root = new wxDataViewTreeStoreContainerNode( NULL, wxEmptyString ); | |
1178 | } | |
1179 | ||
1180 | wxDataViewTreeStore::~wxDataViewTreeStore() | |
1181 | { | |
1182 | delete m_root; | |
1183 | } | |
1184 | ||
b5ec7dd6 | 1185 | wxDataViewItem wxDataViewTreeStore::AppendItem( const wxDataViewItem& parent, |
e94d0c1e RR |
1186 | const wxString &text, const wxIcon &icon, wxClientData *data ) |
1187 | { | |
1188 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1189 | if (!parent_node) return wxDataViewItem(0); | |
b5ec7dd6 VZ |
1190 | |
1191 | wxDataViewTreeStoreNode *node = | |
e94d0c1e RR |
1192 | new wxDataViewTreeStoreNode( parent_node, text, icon, data ); |
1193 | parent_node->GetChildren().Append( node ); | |
b5ec7dd6 | 1194 | |
e94d0c1e RR |
1195 | // notify control |
1196 | ItemAdded( parent, node->GetItem() ); | |
b5ec7dd6 | 1197 | |
e94d0c1e RR |
1198 | return node->GetItem(); |
1199 | } | |
1200 | ||
1201 | wxDataViewItem wxDataViewTreeStore::PrependItem( const wxDataViewItem& parent, | |
1202 | const wxString &text, const wxIcon &icon, wxClientData *data ) | |
1203 | { | |
1204 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1205 | if (!parent_node) return wxDataViewItem(0); | |
b5ec7dd6 VZ |
1206 | |
1207 | wxDataViewTreeStoreNode *node = | |
e94d0c1e RR |
1208 | new wxDataViewTreeStoreNode( parent_node, text, icon, data ); |
1209 | parent_node->GetChildren().Insert( node ); | |
b5ec7dd6 | 1210 | |
e94d0c1e RR |
1211 | // notify control |
1212 | ItemAdded( parent, node->GetItem() ); | |
b5ec7dd6 | 1213 | |
e94d0c1e RR |
1214 | return node->GetItem(); |
1215 | } | |
1216 | ||
b5ec7dd6 VZ |
1217 | wxDataViewItem |
1218 | wxDataViewTreeStore::InsertItem(const wxDataViewItem& WXUNUSED(parent), | |
1219 | const wxDataViewItem& WXUNUSED(previous), | |
1220 | const wxString& WXUNUSED(text), | |
1221 | const wxIcon& WXUNUSED(icon), | |
1222 | wxClientData * WXUNUSED(data)) | |
e94d0c1e RR |
1223 | { |
1224 | return wxDataViewItem(0); | |
1225 | } | |
1226 | ||
b5ec7dd6 VZ |
1227 | wxDataViewItem wxDataViewTreeStore::PrependContainer( const wxDataViewItem& parent, |
1228 | const wxString &text, const wxIcon &icon, const wxIcon &expanded, | |
e94d0c1e RR |
1229 | wxClientData *data ) |
1230 | { | |
1231 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1232 | if (!parent_node) return wxDataViewItem(0); | |
b5ec7dd6 VZ |
1233 | |
1234 | wxDataViewTreeStoreContainerNode *node = | |
e94d0c1e RR |
1235 | new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data ); |
1236 | parent_node->GetChildren().Insert( node ); | |
b5ec7dd6 | 1237 | |
e94d0c1e RR |
1238 | // notify control |
1239 | ItemAdded( parent, node->GetItem() ); | |
b5ec7dd6 | 1240 | |
e94d0c1e RR |
1241 | return node->GetItem(); |
1242 | } | |
1243 | ||
b5ec7dd6 VZ |
1244 | wxDataViewItem |
1245 | wxDataViewTreeStore::AppendContainer(const wxDataViewItem& parent, | |
1246 | const wxString &text, | |
1247 | const wxIcon& icon, | |
1248 | const wxIcon& expanded, | |
1249 | wxClientData * data) | |
e94d0c1e RR |
1250 | { |
1251 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1252 | if (!parent_node) return wxDataViewItem(0); | |
b5ec7dd6 VZ |
1253 | |
1254 | wxDataViewTreeStoreContainerNode *node = | |
e94d0c1e RR |
1255 | new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data ); |
1256 | parent_node->GetChildren().Append( node ); | |
b5ec7dd6 | 1257 | |
e94d0c1e RR |
1258 | // notify control |
1259 | ItemAdded( parent, node->GetItem() ); | |
b5ec7dd6 | 1260 | |
e94d0c1e RR |
1261 | return node->GetItem(); |
1262 | } | |
1263 | ||
b5ec7dd6 VZ |
1264 | wxDataViewItem |
1265 | wxDataViewTreeStore::InsertContainer(const wxDataViewItem& WXUNUSED(parent), | |
1266 | const wxDataViewItem& WXUNUSED(previous), | |
1267 | const wxString& WXUNUSED(text), | |
1268 | const wxIcon& WXUNUSED(icon), | |
1269 | const wxIcon& WXUNUSED(expanded), | |
1270 | wxClientData * WXUNUSED(data)) | |
e94d0c1e RR |
1271 | { |
1272 | return wxDataViewItem(0); | |
1273 | } | |
1274 | ||
1275 | wxDataViewItem wxDataViewTreeStore::GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const | |
1276 | { | |
1277 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1278 | if (!parent_node) return wxDataViewItem(0); | |
b5ec7dd6 | 1279 | |
e94d0c1e RR |
1280 | wxDataViewTreeStoreNodeList::compatibility_iterator node = parent_node->GetChildren().Item( pos ); |
1281 | if (node) | |
1282 | return node->GetData(); | |
b5ec7dd6 | 1283 | |
e94d0c1e RR |
1284 | return wxDataViewItem(0); |
1285 | } | |
1286 | ||
1287 | int wxDataViewTreeStore::GetChildCount( const wxDataViewItem& parent ) const | |
1288 | { | |
1289 | wxDataViewTreeStoreNode *node = FindNode( parent ); | |
1290 | if (!node) return -1; | |
b5ec7dd6 | 1291 | |
e94d0c1e RR |
1292 | if (!node->IsContainer()) |
1293 | return 0; | |
b5ec7dd6 | 1294 | |
e94d0c1e | 1295 | wxDataViewTreeStoreContainerNode *container_node = (wxDataViewTreeStoreContainerNode*) node; |
b5ec7dd6 | 1296 | return (int) container_node->GetChildren().GetCount(); |
e94d0c1e RR |
1297 | } |
1298 | ||
1299 | void wxDataViewTreeStore::SetItemText( const wxDataViewItem& item, const wxString &text ) | |
1300 | { | |
1301 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1302 | if (!node) return; | |
b5ec7dd6 | 1303 | |
e94d0c1e | 1304 | node->SetText( text ); |
b5ec7dd6 | 1305 | |
e94d0c1e RR |
1306 | // notify control |
1307 | ValueChanged( item, 0 ); | |
1308 | } | |
1309 | ||
1310 | wxString wxDataViewTreeStore::GetItemText( const wxDataViewItem& item ) const | |
1311 | { | |
1312 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1313 | if (!node) return wxEmptyString; | |
b5ec7dd6 | 1314 | |
e94d0c1e RR |
1315 | return node->GetText(); |
1316 | } | |
1317 | ||
1318 | void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon ) | |
1319 | { | |
1320 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1321 | if (!node) return; | |
b5ec7dd6 | 1322 | |
e94d0c1e | 1323 | node->SetIcon( icon ); |
b5ec7dd6 | 1324 | |
e94d0c1e RR |
1325 | // notify control |
1326 | ValueChanged( item, 0 ); | |
1327 | } | |
1328 | ||
1329 | const wxIcon &wxDataViewTreeStore::GetItemIcon( const wxDataViewItem& item ) const | |
1330 | { | |
1331 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1332 | if (!node) return wxNullIcon; | |
b5ec7dd6 | 1333 | |
e94d0c1e RR |
1334 | return node->GetIcon(); |
1335 | } | |
1336 | ||
1337 | void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon ) | |
1338 | { | |
1339 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1340 | if (!node) return; | |
b5ec7dd6 | 1341 | |
e94d0c1e | 1342 | node->SetExpandedIcon( icon ); |
b5ec7dd6 | 1343 | |
e94d0c1e RR |
1344 | // notify control |
1345 | ValueChanged( item, 0 ); | |
1346 | } | |
1347 | ||
1348 | const wxIcon &wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem& item ) const | |
1349 | { | |
1350 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1351 | if (!node) return wxNullIcon; | |
b5ec7dd6 | 1352 | |
e94d0c1e RR |
1353 | return node->GetExpandedIcon(); |
1354 | } | |
1355 | ||
1356 | void wxDataViewTreeStore::SetItemData( const wxDataViewItem& item, wxClientData *data ) | |
1357 | { | |
1358 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1359 | if (!node) return; | |
b5ec7dd6 | 1360 | |
e94d0c1e | 1361 | node->SetData( data ); |
b5ec7dd6 | 1362 | |
e94d0c1e RR |
1363 | // notify control? only sensible when sorting on client data |
1364 | // ValueChanged( item, 0 ); | |
1365 | } | |
1366 | ||
1367 | wxClientData *wxDataViewTreeStore::GetItemData( const wxDataViewItem& item ) const | |
1368 | { | |
1369 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1370 | if (!node) return NULL; | |
b5ec7dd6 | 1371 | |
e94d0c1e RR |
1372 | return node->GetData(); |
1373 | } | |
1374 | ||
1375 | void wxDataViewTreeStore::DeleteItem( const wxDataViewItem& item ) | |
1376 | { | |
1377 | if (!item.IsOk()) return; | |
1378 | ||
1379 | wxDataViewItem parent_item = GetParent( item ); | |
1380 | ||
1381 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent_item ); | |
1382 | if (!parent_node) return; | |
b5ec7dd6 | 1383 | |
e94d0c1e RR |
1384 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); |
1385 | if (!node) return; | |
b5ec7dd6 | 1386 | |
e94d0c1e | 1387 | parent_node->GetChildren().DeleteObject( node ); |
b5ec7dd6 | 1388 | |
e94d0c1e RR |
1389 | // notify control |
1390 | ItemDeleted( parent_item, item ); | |
1391 | } | |
1392 | ||
1393 | void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem& item ) | |
1394 | { | |
1395 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1396 | if (!node) return; | |
b5ec7dd6 | 1397 | |
e94d0c1e RR |
1398 | wxDataViewItemArray array; |
1399 | wxDataViewTreeStoreNodeList::iterator iter; | |
1400 | for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++) | |
1401 | { | |
1402 | wxDataViewTreeStoreNode* child = *iter; | |
1403 | array.Add( child->GetItem() ); | |
1404 | } | |
b5ec7dd6 | 1405 | |
e94d0c1e | 1406 | node->GetChildren().clear(); |
b5ec7dd6 | 1407 | |
e94d0c1e RR |
1408 | // notify control |
1409 | ItemsDeleted( item, array ); | |
1410 | } | |
1411 | ||
1412 | void wxDataViewTreeStore::DeleteAllItems() | |
1413 | { | |
1414 | // TODO | |
1415 | } | |
1416 | ||
b5ec7dd6 VZ |
1417 | void |
1418 | wxDataViewTreeStore::GetValue(wxVariant &variant, | |
1419 | const wxDataViewItem &item, | |
1420 | unsigned int WXUNUSED(col)) const | |
e94d0c1e RR |
1421 | { |
1422 | // if (col != 0) return; | |
b5ec7dd6 | 1423 | |
e94d0c1e RR |
1424 | wxDataViewTreeStoreNode *node = FindNode( item ); |
1425 | if (!node) return; | |
b5ec7dd6 | 1426 | |
e94d0c1e | 1427 | wxDataViewIconText data( node->GetText(), node->GetIcon() ); |
b5ec7dd6 | 1428 | |
e94d0c1e RR |
1429 | variant << data; |
1430 | } | |
1431 | ||
b5ec7dd6 VZ |
1432 | bool |
1433 | wxDataViewTreeStore::SetValue(const wxVariant& variant, | |
1434 | const wxDataViewItem& item, | |
1435 | unsigned int WXUNUSED(col)) | |
e94d0c1e RR |
1436 | { |
1437 | // if (col != 0) return false; | |
b5ec7dd6 | 1438 | |
e94d0c1e RR |
1439 | wxDataViewTreeStoreNode *node = FindNode( item ); |
1440 | if (!node) return false; | |
b5ec7dd6 | 1441 | |
e94d0c1e | 1442 | wxDataViewIconText data; |
b5ec7dd6 | 1443 | |
e94d0c1e | 1444 | data << variant; |
b5ec7dd6 | 1445 | |
e94d0c1e RR |
1446 | node->SetText( data.GetText() ); |
1447 | node->SetIcon( data.GetIcon() ); | |
b5ec7dd6 | 1448 | |
e94d0c1e RR |
1449 | return true; |
1450 | } | |
1451 | ||
1452 | wxDataViewItem wxDataViewTreeStore::GetParent( const wxDataViewItem &item ) const | |
1453 | { | |
1454 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1455 | if (!node) return wxDataViewItem(0); | |
b5ec7dd6 | 1456 | |
e94d0c1e RR |
1457 | wxDataViewTreeStoreNode *parent = node->GetParent(); |
1458 | if (!parent) return wxDataViewItem(0); | |
b5ec7dd6 | 1459 | |
e94d0c1e RR |
1460 | if (parent == m_root) |
1461 | return wxDataViewItem(0); | |
b5ec7dd6 | 1462 | |
e94d0c1e RR |
1463 | return parent->GetItem(); |
1464 | } | |
1465 | ||
1466 | bool wxDataViewTreeStore::IsContainer( const wxDataViewItem &item ) const | |
1467 | { | |
1468 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1469 | if (!node) return false; | |
b5ec7dd6 | 1470 | |
e94d0c1e RR |
1471 | return node->IsContainer(); |
1472 | } | |
1473 | ||
1474 | unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const | |
1475 | { | |
1476 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1477 | if (!node) return 0; | |
1478 | ||
1479 | wxDataViewTreeStoreNodeList::iterator iter; | |
1480 | for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++) | |
1481 | { | |
1482 | wxDataViewTreeStoreNode* child = *iter; | |
1483 | children.Add( child->GetItem() ); | |
1484 | } | |
b5ec7dd6 | 1485 | |
e94d0c1e RR |
1486 | return node->GetChildren().GetCount(); |
1487 | } | |
1488 | ||
b5ec7dd6 | 1489 | int wxDataViewTreeStore::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, |
e94d0c1e RR |
1490 | unsigned int WXUNUSED(column), bool WXUNUSED(ascending) ) |
1491 | { | |
1492 | wxDataViewTreeStoreNode *node1 = FindNode( item1 ); | |
1493 | wxDataViewTreeStoreNode *node2 = FindNode( item2 ); | |
b5ec7dd6 | 1494 | |
e94d0c1e RR |
1495 | if (!node1 || !node2) |
1496 | return 0; | |
b5ec7dd6 VZ |
1497 | |
1498 | wxDataViewTreeStoreContainerNode* parent1 = | |
e94d0c1e | 1499 | (wxDataViewTreeStoreContainerNode*) node1->GetParent(); |
b5ec7dd6 | 1500 | wxDataViewTreeStoreContainerNode* parent2 = |
e94d0c1e | 1501 | (wxDataViewTreeStoreContainerNode*) node2->GetParent(); |
b5ec7dd6 | 1502 | |
e94d0c1e RR |
1503 | if (parent1 != parent2) |
1504 | { | |
1505 | wxLogError( wxT("Comparing items with different parent.") ); | |
1506 | return 0; | |
1507 | } | |
b5ec7dd6 | 1508 | |
e94d0c1e RR |
1509 | if (node1->IsContainer() && !!node2->IsContainer()) |
1510 | return 1; | |
b5ec7dd6 | 1511 | |
e94d0c1e RR |
1512 | if (node2->IsContainer() && !!node1->IsContainer()) |
1513 | return -1; | |
b5ec7dd6 | 1514 | |
e94d0c1e RR |
1515 | return parent1->GetChildren().IndexOf( node1 ) - parent1->GetChildren().IndexOf( node2 ); |
1516 | } | |
1517 | ||
1518 | wxDataViewTreeStoreNode *wxDataViewTreeStore::FindNode( const wxDataViewItem &item ) const | |
1519 | { | |
1520 | if (!item.IsOk()) | |
1521 | return m_root; | |
b5ec7dd6 | 1522 | |
e94d0c1e RR |
1523 | return (wxDataViewTreeStoreNode*) item.GetID(); |
1524 | } | |
1525 | ||
1526 | wxDataViewTreeStoreContainerNode *wxDataViewTreeStore::FindContainerNode( const wxDataViewItem &item ) const | |
1527 | { | |
1528 | if (!item.IsOk()) | |
1529 | return (wxDataViewTreeStoreContainerNode*) m_root; | |
1530 | ||
1531 | wxDataViewTreeStoreNode* node = (wxDataViewTreeStoreNode*) item.GetID(); | |
b5ec7dd6 | 1532 | |
e94d0c1e RR |
1533 | if (!node->IsContainer()) |
1534 | return NULL; | |
b5ec7dd6 | 1535 | |
e94d0c1e RR |
1536 | return (wxDataViewTreeStoreContainerNode*) node; |
1537 | } | |
1538 | ||
b5ec7dd6 | 1539 | #endif // wxUSE_DATAVIEWCTRL |
e0000f94 | 1540 |