]>
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 | ||
a75124d0 RR |
784 | const wxDataViewModel* wxDataViewCtrlBase::GetModel() const |
785 | { | |
786 | return m_model; | |
787 | } | |
788 | ||
c7074d44 RR |
789 | wxDataViewColumn * |
790 | wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 791 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
fa28826d | 792 | { |
c7074d44 | 793 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 794 | new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), |
c7074d44 RR |
795 | model_column, width, align, flags ); |
796 | AppendColumn( ret ); | |
797 | return ret; | |
fa28826d RR |
798 | } |
799 | ||
b04fcede RR |
800 | wxDataViewColumn * |
801 | wxDataViewCtrlBase::AppendIconTextColumn( const wxString &label, unsigned int model_column, | |
802 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
803 | { | |
804 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
805 | new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), | |
806 | model_column, width, align, flags ); | |
807 | AppendColumn( ret ); | |
808 | return ret; | |
809 | } | |
810 | ||
c7074d44 RR |
811 | wxDataViewColumn * |
812 | wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 813 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
605c2c4a | 814 | { |
b7fe2261 | 815 | |
c7074d44 | 816 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 817 | new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), |
c7074d44 RR |
818 | model_column, width, align, flags ); |
819 | AppendColumn( ret ); | |
820 | return ret; | |
605c2c4a RR |
821 | } |
822 | ||
c7074d44 RR |
823 | wxDataViewColumn * |
824 | wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 825 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
ad63bf41 | 826 | { |
c7074d44 | 827 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 828 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), |
c7074d44 RR |
829 | model_column, width, align, flags ); |
830 | AppendColumn( ret ); | |
831 | return ret; | |
ad63bf41 RR |
832 | } |
833 | ||
c7074d44 RR |
834 | wxDataViewColumn * |
835 | wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 836 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
4d496ecb | 837 | { |
c7074d44 | 838 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 839 | new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), |
c7074d44 RR |
840 | model_column, width, align, flags ); |
841 | AppendColumn( ret ); | |
842 | return ret; | |
4d496ecb RR |
843 | } |
844 | ||
c7074d44 RR |
845 | wxDataViewColumn * |
846 | wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 847 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 848 | { |
c7074d44 | 849 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 850 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), |
c7074d44 RR |
851 | model_column, width, align, flags ); |
852 | AppendColumn( ret ); | |
853 | return ret; | |
07a84e7b RR |
854 | } |
855 | ||
c7074d44 RR |
856 | wxDataViewColumn * |
857 | wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 858 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 859 | { |
c7074d44 | 860 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 861 | new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), |
c7074d44 RR |
862 | model_column, width, align, flags ); |
863 | AppendColumn( ret ); | |
864 | return ret; | |
b04fcede RR |
865 | } |
866 | ||
867 | wxDataViewColumn * | |
868 | wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap &label, unsigned int model_column, | |
869 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
870 | { | |
871 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
872 | new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), | |
873 | model_column, width, align, flags ); | |
874 | AppendColumn( ret ); | |
875 | return ret; | |
07a84e7b RR |
876 | } |
877 | ||
c7074d44 RR |
878 | wxDataViewColumn * |
879 | wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 880 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 881 | { |
c7074d44 | 882 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 883 | new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), |
c7074d44 RR |
884 | model_column, width, align, flags ); |
885 | AppendColumn( ret ); | |
886 | return ret; | |
07a84e7b RR |
887 | } |
888 | ||
c7074d44 RR |
889 | wxDataViewColumn * |
890 | wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 891 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 892 | { |
c7074d44 | 893 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 894 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), |
c7074d44 RR |
895 | model_column, width, align, flags ); |
896 | AppendColumn( ret ); | |
897 | return ret; | |
07a84e7b RR |
898 | } |
899 | ||
c7074d44 RR |
900 | wxDataViewColumn * |
901 | wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 902 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 903 | { |
c7074d44 | 904 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 905 | new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), |
c7074d44 RR |
906 | model_column, width, align, flags ); |
907 | AppendColumn( ret ); | |
908 | return ret; | |
07a84e7b RR |
909 | } |
910 | ||
c7074d44 RR |
911 | wxDataViewColumn * |
912 | wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 913 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 914 | { |
c7074d44 | 915 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 916 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), |
c7074d44 RR |
917 | model_column, width, align, flags ); |
918 | AppendColumn( ret ); | |
919 | return ret; | |
07a84e7b RR |
920 | } |
921 | ||
736fe67c RR |
922 | wxDataViewColumn * |
923 | wxDataViewCtrlBase::PrependTextColumn( const wxString &label, unsigned int model_column, | |
924 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
925 | { | |
926 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
927 | new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), | |
928 | model_column, width, align, flags ); | |
929 | PrependColumn( ret ); | |
930 | return ret; | |
931 | } | |
932 | ||
933 | wxDataViewColumn * | |
934 | wxDataViewCtrlBase::PrependIconTextColumn( const wxString &label, unsigned int model_column, | |
935 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
936 | { | |
937 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
938 | new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), | |
939 | model_column, width, align, flags ); | |
940 | PrependColumn( ret ); | |
941 | return ret; | |
942 | } | |
943 | ||
944 | wxDataViewColumn * | |
945 | wxDataViewCtrlBase::PrependToggleColumn( const wxString &label, unsigned int model_column, | |
946 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
947 | { | |
948 | ||
949 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
950 | new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), | |
951 | model_column, width, align, flags ); | |
952 | PrependColumn( ret ); | |
953 | return ret; | |
954 | } | |
955 | ||
956 | wxDataViewColumn * | |
957 | wxDataViewCtrlBase::PrependProgressColumn( const wxString &label, unsigned int model_column, | |
958 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
959 | { | |
960 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
961 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), | |
962 | model_column, width, align, flags ); | |
963 | PrependColumn( ret ); | |
964 | return ret; | |
965 | } | |
966 | ||
967 | wxDataViewColumn * | |
968 | wxDataViewCtrlBase::PrependDateColumn( const wxString &label, unsigned int model_column, | |
969 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
970 | { | |
971 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
972 | new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), | |
973 | model_column, width, align, flags ); | |
974 | PrependColumn( ret ); | |
975 | return ret; | |
976 | } | |
977 | ||
978 | wxDataViewColumn * | |
979 | wxDataViewCtrlBase::PrependBitmapColumn( const wxString &label, unsigned int model_column, | |
980 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
981 | { | |
982 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
983 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), | |
984 | model_column, width, align, flags ); | |
985 | PrependColumn( ret ); | |
986 | return ret; | |
987 | } | |
988 | ||
989 | wxDataViewColumn * | |
990 | wxDataViewCtrlBase::PrependTextColumn( const wxBitmap &label, unsigned int model_column, | |
991 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
992 | { | |
993 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
994 | new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), | |
995 | model_column, width, align, flags ); | |
996 | PrependColumn( ret ); | |
997 | return ret; | |
998 | } | |
999 | ||
1000 | wxDataViewColumn * | |
1001 | wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap &label, unsigned int model_column, | |
1002 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1003 | { | |
1004 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
1005 | new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), | |
1006 | model_column, width, align, flags ); | |
1007 | PrependColumn( ret ); | |
1008 | return ret; | |
1009 | } | |
1010 | ||
1011 | wxDataViewColumn * | |
1012 | wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap &label, unsigned int model_column, | |
1013 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1014 | { | |
1015 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
1016 | new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), | |
1017 | model_column, width, align, flags ); | |
1018 | PrependColumn( ret ); | |
1019 | return ret; | |
1020 | } | |
1021 | ||
1022 | wxDataViewColumn * | |
1023 | wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap &label, unsigned int model_column, | |
1024 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1025 | { | |
1026 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
1027 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), | |
1028 | model_column, width, align, flags ); | |
1029 | PrependColumn( ret ); | |
1030 | return ret; | |
1031 | } | |
1032 | ||
1033 | wxDataViewColumn * | |
1034 | wxDataViewCtrlBase::PrependDateColumn( const wxBitmap &label, unsigned int model_column, | |
1035 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1036 | { | |
1037 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
1038 | new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), | |
1039 | model_column, width, align, flags ); | |
1040 | PrependColumn( ret ); | |
1041 | return ret; | |
1042 | } | |
1043 | ||
1044 | wxDataViewColumn * | |
1045 | wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap &label, unsigned int model_column, | |
1046 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1047 | { | |
1048 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
1049 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), | |
1050 | model_column, width, align, flags ); | |
1051 | PrependColumn( ret ); | |
1052 | return ret; | |
1053 | } | |
1054 | ||
c7074d44 RR |
1055 | bool |
1056 | wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col ) | |
fa28826d | 1057 | { |
6842a71a | 1058 | col->SetOwner( (wxDataViewCtrl*) this ); |
fa28826d RR |
1059 | return true; |
1060 | } | |
1061 | ||
736fe67c RR |
1062 | bool |
1063 | wxDataViewCtrlBase::PrependColumn( wxDataViewColumn *col ) | |
1064 | { | |
1065 | col->SetOwner( (wxDataViewCtrl*) this ); | |
1066 | return true; | |
1067 | } | |
1068 | ||
eb7f97f8 RR |
1069 | // --------------------------------------------------------- |
1070 | // wxDataViewEvent | |
1071 | // --------------------------------------------------------- | |
1072 | ||
1073 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent) | |
1074 | ||
d86c1870 RR |
1075 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED) |
1076 | ||
e0062c04 | 1077 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED) |
6977c3bf | 1078 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING) |
3ecb8a53 | 1079 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED) |
6977c3bf | 1080 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING) |
3ecb8a53 | 1081 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED) |
e0000f94 RR |
1082 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED) |
1083 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE) | |
6608fdab | 1084 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED) |
e0000f94 | 1085 | |
31fb32e1 RR |
1086 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK) |
1087 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK) | |
c0a66d92 | 1088 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED) |
eb7f97f8 | 1089 | |
52e750fc RR |
1090 | |
1091 | // ------------------------------------- | |
1092 | // wxDataViewSpinRenderer | |
1093 | // ------------------------------------- | |
1094 | ||
1095 | wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min, int max, wxDataViewCellMode mode, int alignment ) : | |
b5ec7dd6 VZ |
1096 | wxDataViewCustomRenderer( "long", mode, alignment ) |
1097 | { | |
52e750fc RR |
1098 | m_min = min; |
1099 | m_max = max; | |
1100 | } | |
b5ec7dd6 | 1101 | |
52e750fc | 1102 | wxControl* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ) |
b5ec7dd6 | 1103 | { |
52e750fc | 1104 | long l = value; |
b5ec7dd6 | 1105 | return new wxSpinCtrl( parent, wxID_ANY, wxEmptyString, |
52e750fc RR |
1106 | labelRect.GetTopLeft(), labelRect.GetSize(), wxSP_ARROW_KEYS, m_min, m_max, l ); |
1107 | } | |
b5ec7dd6 | 1108 | |
52e750fc | 1109 | bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ) |
b5ec7dd6 | 1110 | { |
52e750fc RR |
1111 | wxSpinCtrl *sc = (wxSpinCtrl*) editor; |
1112 | long l = sc->GetValue(); | |
1113 | value = l; | |
1114 | return true; | |
1115 | } | |
b5ec7dd6 | 1116 | |
52e750fc RR |
1117 | bool wxDataViewSpinRenderer::Render( wxRect rect, wxDC *dc, int state ) |
1118 | { | |
1119 | wxString str; | |
1120 | str.Printf( "%d", (int) m_data ); | |
1121 | RenderText( str, 0, rect, dc, state ); | |
1122 | return true; | |
1123 | } | |
b5ec7dd6 | 1124 | |
52e750fc RR |
1125 | wxSize wxDataViewSpinRenderer::GetSize() const |
1126 | { | |
1127 | return wxSize(80,16); | |
1128 | } | |
b5ec7dd6 | 1129 | |
52e750fc RR |
1130 | bool wxDataViewSpinRenderer::SetValue( const wxVariant &value ) |
1131 | { | |
1132 | m_data = value.GetLong(); | |
1133 | return true; | |
1134 | } | |
b5ec7dd6 | 1135 | |
52e750fc RR |
1136 | bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const |
1137 | { | |
1138 | value = m_data; | |
1139 | return true; | |
1140 | } | |
1141 | ||
e94d0c1e RR |
1142 | //----------------------------------------------------------------------------- |
1143 | // wxDataViewTreeStore | |
1144 | //----------------------------------------------------------------------------- | |
1145 | ||
b5ec7dd6 VZ |
1146 | wxDataViewTreeStoreNode::wxDataViewTreeStoreNode( |
1147 | wxDataViewTreeStoreNode *parent, | |
e94d0c1e RR |
1148 | const wxString &text, const wxIcon &icon, wxClientData *data ) |
1149 | { | |
1150 | m_parent = parent; | |
1151 | m_text = text; | |
1152 | m_icon = icon; | |
1153 | m_data = data; | |
1154 | } | |
1155 | ||
1156 | wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode() | |
1157 | { | |
1158 | if (m_data) | |
1159 | delete m_data; | |
1160 | } | |
b5ec7dd6 | 1161 | |
e94d0c1e | 1162 | #include "wx/listimpl.cpp" |
a76c2f37 | 1163 | WX_DEFINE_LIST(wxDataViewTreeStoreNodeList) |
e94d0c1e | 1164 | |
b5ec7dd6 VZ |
1165 | wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode( |
1166 | wxDataViewTreeStoreNode *parent, const wxString &text, | |
e94d0c1e RR |
1167 | const wxIcon &icon, const wxIcon &expanded, wxClientData *data ) : |
1168 | wxDataViewTreeStoreNode( parent, text, icon, data ) | |
1169 | { | |
1170 | m_iconExpanded = expanded; | |
a75124d0 | 1171 | m_isExpanded = false; |
e94d0c1e RR |
1172 | m_children.DeleteContents(true); |
1173 | } | |
1174 | ||
1175 | wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode() | |
1176 | { | |
1177 | } | |
1178 | ||
1179 | //----------------------------------------------------------------------------- | |
1180 | ||
1181 | wxDataViewTreeStore::wxDataViewTreeStore() | |
1182 | { | |
1183 | m_root = new wxDataViewTreeStoreContainerNode( NULL, wxEmptyString ); | |
1184 | } | |
1185 | ||
1186 | wxDataViewTreeStore::~wxDataViewTreeStore() | |
1187 | { | |
1188 | delete m_root; | |
1189 | } | |
1190 | ||
b5ec7dd6 | 1191 | wxDataViewItem wxDataViewTreeStore::AppendItem( const wxDataViewItem& parent, |
e94d0c1e RR |
1192 | const wxString &text, const wxIcon &icon, wxClientData *data ) |
1193 | { | |
1194 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1195 | if (!parent_node) return wxDataViewItem(0); | |
b5ec7dd6 VZ |
1196 | |
1197 | wxDataViewTreeStoreNode *node = | |
e94d0c1e RR |
1198 | new wxDataViewTreeStoreNode( parent_node, text, icon, data ); |
1199 | parent_node->GetChildren().Append( node ); | |
b5ec7dd6 | 1200 | |
e94d0c1e RR |
1201 | // notify control |
1202 | ItemAdded( parent, node->GetItem() ); | |
b5ec7dd6 | 1203 | |
e94d0c1e RR |
1204 | return node->GetItem(); |
1205 | } | |
1206 | ||
1207 | wxDataViewItem wxDataViewTreeStore::PrependItem( const wxDataViewItem& parent, | |
1208 | const wxString &text, const wxIcon &icon, wxClientData *data ) | |
1209 | { | |
1210 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1211 | if (!parent_node) return wxDataViewItem(0); | |
b5ec7dd6 VZ |
1212 | |
1213 | wxDataViewTreeStoreNode *node = | |
e94d0c1e RR |
1214 | new wxDataViewTreeStoreNode( parent_node, text, icon, data ); |
1215 | parent_node->GetChildren().Insert( node ); | |
b5ec7dd6 | 1216 | |
e94d0c1e RR |
1217 | // notify control |
1218 | ItemAdded( parent, node->GetItem() ); | |
b5ec7dd6 | 1219 | |
e94d0c1e RR |
1220 | return node->GetItem(); |
1221 | } | |
1222 | ||
b5ec7dd6 VZ |
1223 | wxDataViewItem |
1224 | wxDataViewTreeStore::InsertItem(const wxDataViewItem& WXUNUSED(parent), | |
1225 | const wxDataViewItem& WXUNUSED(previous), | |
1226 | const wxString& WXUNUSED(text), | |
1227 | const wxIcon& WXUNUSED(icon), | |
1228 | wxClientData * WXUNUSED(data)) | |
e94d0c1e RR |
1229 | { |
1230 | return wxDataViewItem(0); | |
1231 | } | |
1232 | ||
b5ec7dd6 VZ |
1233 | wxDataViewItem wxDataViewTreeStore::PrependContainer( const wxDataViewItem& parent, |
1234 | const wxString &text, const wxIcon &icon, const wxIcon &expanded, | |
e94d0c1e RR |
1235 | wxClientData *data ) |
1236 | { | |
1237 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1238 | if (!parent_node) return wxDataViewItem(0); | |
b5ec7dd6 VZ |
1239 | |
1240 | wxDataViewTreeStoreContainerNode *node = | |
e94d0c1e RR |
1241 | new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data ); |
1242 | parent_node->GetChildren().Insert( node ); | |
b5ec7dd6 | 1243 | |
e94d0c1e RR |
1244 | // notify control |
1245 | ItemAdded( parent, node->GetItem() ); | |
b5ec7dd6 | 1246 | |
e94d0c1e RR |
1247 | return node->GetItem(); |
1248 | } | |
1249 | ||
b5ec7dd6 VZ |
1250 | wxDataViewItem |
1251 | wxDataViewTreeStore::AppendContainer(const wxDataViewItem& parent, | |
1252 | const wxString &text, | |
1253 | const wxIcon& icon, | |
1254 | const wxIcon& expanded, | |
1255 | wxClientData * data) | |
e94d0c1e RR |
1256 | { |
1257 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1258 | if (!parent_node) return wxDataViewItem(0); | |
b5ec7dd6 VZ |
1259 | |
1260 | wxDataViewTreeStoreContainerNode *node = | |
e94d0c1e RR |
1261 | new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data ); |
1262 | parent_node->GetChildren().Append( node ); | |
b5ec7dd6 | 1263 | |
e94d0c1e RR |
1264 | // notify control |
1265 | ItemAdded( parent, node->GetItem() ); | |
b5ec7dd6 | 1266 | |
e94d0c1e RR |
1267 | return node->GetItem(); |
1268 | } | |
1269 | ||
b5ec7dd6 VZ |
1270 | wxDataViewItem |
1271 | wxDataViewTreeStore::InsertContainer(const wxDataViewItem& WXUNUSED(parent), | |
1272 | const wxDataViewItem& WXUNUSED(previous), | |
1273 | const wxString& WXUNUSED(text), | |
1274 | const wxIcon& WXUNUSED(icon), | |
1275 | const wxIcon& WXUNUSED(expanded), | |
1276 | wxClientData * WXUNUSED(data)) | |
e94d0c1e RR |
1277 | { |
1278 | return wxDataViewItem(0); | |
1279 | } | |
1280 | ||
1281 | wxDataViewItem wxDataViewTreeStore::GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const | |
1282 | { | |
1283 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1284 | if (!parent_node) return wxDataViewItem(0); | |
b5ec7dd6 | 1285 | |
e94d0c1e RR |
1286 | wxDataViewTreeStoreNodeList::compatibility_iterator node = parent_node->GetChildren().Item( pos ); |
1287 | if (node) | |
1288 | return node->GetData(); | |
b5ec7dd6 | 1289 | |
e94d0c1e RR |
1290 | return wxDataViewItem(0); |
1291 | } | |
1292 | ||
1293 | int wxDataViewTreeStore::GetChildCount( const wxDataViewItem& parent ) const | |
1294 | { | |
1295 | wxDataViewTreeStoreNode *node = FindNode( parent ); | |
1296 | if (!node) return -1; | |
b5ec7dd6 | 1297 | |
e94d0c1e RR |
1298 | if (!node->IsContainer()) |
1299 | return 0; | |
b5ec7dd6 | 1300 | |
e94d0c1e | 1301 | wxDataViewTreeStoreContainerNode *container_node = (wxDataViewTreeStoreContainerNode*) node; |
b5ec7dd6 | 1302 | return (int) container_node->GetChildren().GetCount(); |
e94d0c1e RR |
1303 | } |
1304 | ||
1305 | void wxDataViewTreeStore::SetItemText( const wxDataViewItem& item, const wxString &text ) | |
1306 | { | |
1307 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1308 | if (!node) return; | |
b5ec7dd6 | 1309 | |
e94d0c1e | 1310 | node->SetText( text ); |
b5ec7dd6 | 1311 | |
e94d0c1e RR |
1312 | // notify control |
1313 | ValueChanged( item, 0 ); | |
1314 | } | |
1315 | ||
1316 | wxString wxDataViewTreeStore::GetItemText( const wxDataViewItem& item ) const | |
1317 | { | |
1318 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1319 | if (!node) return wxEmptyString; | |
b5ec7dd6 | 1320 | |
e94d0c1e RR |
1321 | return node->GetText(); |
1322 | } | |
1323 | ||
1324 | void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon ) | |
1325 | { | |
1326 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1327 | if (!node) return; | |
b5ec7dd6 | 1328 | |
e94d0c1e | 1329 | node->SetIcon( icon ); |
b5ec7dd6 | 1330 | |
e94d0c1e RR |
1331 | // notify control |
1332 | ValueChanged( item, 0 ); | |
1333 | } | |
1334 | ||
1335 | const wxIcon &wxDataViewTreeStore::GetItemIcon( const wxDataViewItem& item ) const | |
1336 | { | |
1337 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1338 | if (!node) return wxNullIcon; | |
b5ec7dd6 | 1339 | |
e94d0c1e RR |
1340 | return node->GetIcon(); |
1341 | } | |
1342 | ||
1343 | void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon ) | |
1344 | { | |
1345 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1346 | if (!node) return; | |
b5ec7dd6 | 1347 | |
e94d0c1e | 1348 | node->SetExpandedIcon( icon ); |
b5ec7dd6 | 1349 | |
e94d0c1e RR |
1350 | // notify control |
1351 | ValueChanged( item, 0 ); | |
1352 | } | |
1353 | ||
1354 | const wxIcon &wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem& item ) const | |
1355 | { | |
1356 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1357 | if (!node) return wxNullIcon; | |
b5ec7dd6 | 1358 | |
e94d0c1e RR |
1359 | return node->GetExpandedIcon(); |
1360 | } | |
1361 | ||
1362 | void wxDataViewTreeStore::SetItemData( const wxDataViewItem& item, wxClientData *data ) | |
1363 | { | |
1364 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1365 | if (!node) return; | |
b5ec7dd6 | 1366 | |
e94d0c1e | 1367 | node->SetData( data ); |
b5ec7dd6 | 1368 | |
e94d0c1e RR |
1369 | // notify control? only sensible when sorting on client data |
1370 | // ValueChanged( item, 0 ); | |
1371 | } | |
1372 | ||
1373 | wxClientData *wxDataViewTreeStore::GetItemData( const wxDataViewItem& item ) const | |
1374 | { | |
1375 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1376 | if (!node) return NULL; | |
b5ec7dd6 | 1377 | |
e94d0c1e RR |
1378 | return node->GetData(); |
1379 | } | |
1380 | ||
1381 | void wxDataViewTreeStore::DeleteItem( const wxDataViewItem& item ) | |
1382 | { | |
1383 | if (!item.IsOk()) return; | |
1384 | ||
1385 | wxDataViewItem parent_item = GetParent( item ); | |
1386 | ||
1387 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent_item ); | |
1388 | if (!parent_node) return; | |
b5ec7dd6 | 1389 | |
e94d0c1e RR |
1390 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); |
1391 | if (!node) return; | |
b5ec7dd6 | 1392 | |
e94d0c1e | 1393 | parent_node->GetChildren().DeleteObject( node ); |
b5ec7dd6 | 1394 | |
e94d0c1e RR |
1395 | // notify control |
1396 | ItemDeleted( parent_item, item ); | |
1397 | } | |
1398 | ||
1399 | void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem& item ) | |
1400 | { | |
1401 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1402 | if (!node) return; | |
b5ec7dd6 | 1403 | |
e94d0c1e RR |
1404 | wxDataViewItemArray array; |
1405 | wxDataViewTreeStoreNodeList::iterator iter; | |
1406 | for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++) | |
1407 | { | |
1408 | wxDataViewTreeStoreNode* child = *iter; | |
1409 | array.Add( child->GetItem() ); | |
1410 | } | |
b5ec7dd6 | 1411 | |
e94d0c1e | 1412 | node->GetChildren().clear(); |
b5ec7dd6 | 1413 | |
e94d0c1e RR |
1414 | // notify control |
1415 | ItemsDeleted( item, array ); | |
1416 | } | |
1417 | ||
1418 | void wxDataViewTreeStore::DeleteAllItems() | |
1419 | { | |
1420 | // TODO | |
1421 | } | |
1422 | ||
b5ec7dd6 VZ |
1423 | void |
1424 | wxDataViewTreeStore::GetValue(wxVariant &variant, | |
1425 | const wxDataViewItem &item, | |
1426 | unsigned int WXUNUSED(col)) const | |
e94d0c1e RR |
1427 | { |
1428 | // if (col != 0) return; | |
b5ec7dd6 | 1429 | |
e94d0c1e RR |
1430 | wxDataViewTreeStoreNode *node = FindNode( item ); |
1431 | if (!node) return; | |
b5ec7dd6 | 1432 | |
a75124d0 RR |
1433 | wxIcon icon( node->GetIcon()); |
1434 | if (node->IsContainer()) | |
1435 | { | |
1436 | wxDataViewTreeStoreContainerNode *container = (wxDataViewTreeStoreContainerNode*) node; | |
1437 | if (container->IsExpanded() && container->GetExpandedIcon().IsOk()) | |
1438 | icon = container->GetExpandedIcon(); | |
1439 | } | |
1440 | ||
1441 | wxDataViewIconText data( node->GetText(), icon ); | |
b5ec7dd6 | 1442 | |
e94d0c1e RR |
1443 | variant << data; |
1444 | } | |
1445 | ||
b5ec7dd6 VZ |
1446 | bool |
1447 | wxDataViewTreeStore::SetValue(const wxVariant& variant, | |
1448 | const wxDataViewItem& item, | |
1449 | unsigned int WXUNUSED(col)) | |
e94d0c1e RR |
1450 | { |
1451 | // if (col != 0) return false; | |
b5ec7dd6 | 1452 | |
e94d0c1e RR |
1453 | wxDataViewTreeStoreNode *node = FindNode( item ); |
1454 | if (!node) return false; | |
b5ec7dd6 | 1455 | |
e94d0c1e | 1456 | wxDataViewIconText data; |
b5ec7dd6 | 1457 | |
e94d0c1e | 1458 | data << variant; |
b5ec7dd6 | 1459 | |
e94d0c1e RR |
1460 | node->SetText( data.GetText() ); |
1461 | node->SetIcon( data.GetIcon() ); | |
b5ec7dd6 | 1462 | |
e94d0c1e RR |
1463 | return true; |
1464 | } | |
1465 | ||
1466 | wxDataViewItem wxDataViewTreeStore::GetParent( const wxDataViewItem &item ) const | |
1467 | { | |
1468 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1469 | if (!node) return wxDataViewItem(0); | |
b5ec7dd6 | 1470 | |
e94d0c1e RR |
1471 | wxDataViewTreeStoreNode *parent = node->GetParent(); |
1472 | if (!parent) return wxDataViewItem(0); | |
b5ec7dd6 | 1473 | |
e94d0c1e RR |
1474 | if (parent == m_root) |
1475 | return wxDataViewItem(0); | |
b5ec7dd6 | 1476 | |
e94d0c1e RR |
1477 | return parent->GetItem(); |
1478 | } | |
1479 | ||
1480 | bool wxDataViewTreeStore::IsContainer( const wxDataViewItem &item ) const | |
1481 | { | |
1482 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1483 | if (!node) return false; | |
b5ec7dd6 | 1484 | |
e94d0c1e RR |
1485 | return node->IsContainer(); |
1486 | } | |
1487 | ||
1488 | unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const | |
1489 | { | |
1490 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1491 | if (!node) return 0; | |
1492 | ||
1493 | wxDataViewTreeStoreNodeList::iterator iter; | |
1494 | for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++) | |
1495 | { | |
1496 | wxDataViewTreeStoreNode* child = *iter; | |
1497 | children.Add( child->GetItem() ); | |
1498 | } | |
b5ec7dd6 | 1499 | |
e94d0c1e RR |
1500 | return node->GetChildren().GetCount(); |
1501 | } | |
1502 | ||
b5ec7dd6 | 1503 | int wxDataViewTreeStore::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, |
e94d0c1e RR |
1504 | unsigned int WXUNUSED(column), bool WXUNUSED(ascending) ) |
1505 | { | |
1506 | wxDataViewTreeStoreNode *node1 = FindNode( item1 ); | |
1507 | wxDataViewTreeStoreNode *node2 = FindNode( item2 ); | |
b5ec7dd6 | 1508 | |
e94d0c1e RR |
1509 | if (!node1 || !node2) |
1510 | return 0; | |
b5ec7dd6 VZ |
1511 | |
1512 | wxDataViewTreeStoreContainerNode* parent1 = | |
e94d0c1e | 1513 | (wxDataViewTreeStoreContainerNode*) node1->GetParent(); |
b5ec7dd6 | 1514 | wxDataViewTreeStoreContainerNode* parent2 = |
e94d0c1e | 1515 | (wxDataViewTreeStoreContainerNode*) node2->GetParent(); |
b5ec7dd6 | 1516 | |
e94d0c1e RR |
1517 | if (parent1 != parent2) |
1518 | { | |
1519 | wxLogError( wxT("Comparing items with different parent.") ); | |
1520 | return 0; | |
1521 | } | |
b5ec7dd6 | 1522 | |
e94d0c1e RR |
1523 | if (node1->IsContainer() && !!node2->IsContainer()) |
1524 | return 1; | |
b5ec7dd6 | 1525 | |
e94d0c1e RR |
1526 | if (node2->IsContainer() && !!node1->IsContainer()) |
1527 | return -1; | |
b5ec7dd6 | 1528 | |
e94d0c1e RR |
1529 | return parent1->GetChildren().IndexOf( node1 ) - parent1->GetChildren().IndexOf( node2 ); |
1530 | } | |
1531 | ||
1532 | wxDataViewTreeStoreNode *wxDataViewTreeStore::FindNode( const wxDataViewItem &item ) const | |
1533 | { | |
1534 | if (!item.IsOk()) | |
1535 | return m_root; | |
b5ec7dd6 | 1536 | |
e94d0c1e RR |
1537 | return (wxDataViewTreeStoreNode*) item.GetID(); |
1538 | } | |
1539 | ||
1540 | wxDataViewTreeStoreContainerNode *wxDataViewTreeStore::FindContainerNode( const wxDataViewItem &item ) const | |
1541 | { | |
1542 | if (!item.IsOk()) | |
1543 | return (wxDataViewTreeStoreContainerNode*) m_root; | |
1544 | ||
1545 | wxDataViewTreeStoreNode* node = (wxDataViewTreeStoreNode*) item.GetID(); | |
b5ec7dd6 | 1546 | |
e94d0c1e RR |
1547 | if (!node->IsContainer()) |
1548 | return NULL; | |
b5ec7dd6 | 1549 | |
e94d0c1e RR |
1550 | return (wxDataViewTreeStoreContainerNode*) node; |
1551 | } | |
1552 | ||
a75124d0 RR |
1553 | //----------------------------------------------------------------------------- |
1554 | // wxDataViewTreeCtrl | |
1555 | //----------------------------------------------------------------------------- | |
1556 | ||
1557 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl,wxDataViewCtrl) | |
1558 | ||
1559 | BEGIN_EVENT_TABLE(wxDataViewTreeCtrl,wxDataViewCtrl) | |
1560 | EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded) | |
1561 | EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed) | |
1562 | END_EVENT_TABLE() | |
1563 | ||
1564 | wxDataViewTreeCtrl::wxDataViewTreeCtrl() | |
1565 | { | |
1566 | m_imageList = NULL; | |
1567 | } | |
1568 | ||
1569 | wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow *parent, wxWindowID id, | |
1570 | const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator ) | |
1571 | { | |
1572 | m_imageList = NULL; | |
1573 | Create( parent, id, pos, size, style, validator ); | |
1574 | ||
1575 | wxDataViewTreeStore *store = new wxDataViewTreeStore; | |
1576 | AssociateModel( store ); | |
1577 | store->DecRef(); | |
1578 | AppendIconTextColumn( "", 0, wxDATAVIEW_CELL_INERT, 200 ); | |
1579 | } | |
1580 | ||
1581 | wxDataViewTreeCtrl::~wxDataViewTreeCtrl() | |
1582 | { | |
1583 | if (m_imageList) | |
1584 | delete m_imageList; | |
1585 | } | |
1586 | ||
1587 | bool wxDataViewTreeCtrl::Create( wxWindow *parent, wxWindowID id, | |
1588 | const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator ) | |
1589 | { | |
1590 | return wxDataViewCtrl::Create( parent, id, pos, size, style, validator ); | |
1591 | } | |
1592 | ||
1593 | void wxDataViewTreeCtrl::SetImageList( wxImageList *imagelist ) | |
1594 | { | |
1595 | if (m_imageList) | |
1596 | delete m_imageList; | |
1597 | ||
1598 | m_imageList = imagelist; | |
1599 | } | |
1600 | ||
1601 | wxDataViewItem wxDataViewTreeCtrl::AppendItem( const wxDataViewItem& parent, | |
1602 | const wxString &text, int iconIndex, wxClientData *data ) | |
1603 | { | |
1604 | wxIcon icon = wxNullIcon; | |
1605 | if (m_imageList && (iconIndex != -1)) | |
1606 | icon = m_imageList->GetIcon( iconIndex ); | |
1607 | ||
1608 | return GetStore()->AppendItem( parent, text, icon, data ); | |
1609 | } | |
1610 | ||
1611 | wxDataViewItem wxDataViewTreeCtrl::PrependItem( const wxDataViewItem& parent, | |
1612 | const wxString &text, int iconIndex, wxClientData *data ) | |
1613 | { | |
1614 | wxIcon icon = wxNullIcon; | |
1615 | if (m_imageList && (iconIndex != -1)) | |
1616 | icon = m_imageList->GetIcon( iconIndex ); | |
1617 | ||
1618 | return GetStore()->PrependItem( parent, text, icon, data ); | |
1619 | } | |
1620 | ||
1621 | wxDataViewItem wxDataViewTreeCtrl::InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous, | |
1622 | const wxString &text, int iconIndex, wxClientData *data ) | |
1623 | { | |
1624 | wxIcon icon = wxNullIcon; | |
1625 | if (m_imageList && (iconIndex != -1)) | |
1626 | icon = m_imageList->GetIcon( iconIndex ); | |
1627 | ||
1628 | return GetStore()->InsertItem( parent, previous, text, icon, data ); | |
1629 | } | |
1630 | ||
1631 | wxDataViewItem wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem& parent, | |
1632 | const wxString &text, int iconIndex, int expandedIndex, wxClientData *data ) | |
1633 | { | |
1634 | wxIcon icon = wxNullIcon; | |
1635 | if (m_imageList && (iconIndex != -1)) | |
1636 | icon = m_imageList->GetIcon( iconIndex ); | |
1637 | ||
1638 | wxIcon expanded = wxNullIcon; | |
1639 | if (m_imageList && (expandedIndex != -1)) | |
1640 | expanded = m_imageList->GetIcon( expandedIndex ); | |
1641 | ||
1642 | return GetStore()->PrependContainer( parent, text, icon, expanded, data ); | |
1643 | } | |
1644 | ||
1645 | wxDataViewItem wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem& parent, | |
1646 | const wxString &text, int iconIndex, int expandedIndex, wxClientData *data ) | |
1647 | { | |
1648 | wxIcon icon = wxNullIcon; | |
1649 | if (m_imageList && (iconIndex != -1)) | |
1650 | icon = m_imageList->GetIcon( iconIndex ); | |
1651 | ||
1652 | wxIcon expanded = wxNullIcon; | |
1653 | if (m_imageList && (expandedIndex != -1)) | |
1654 | expanded = m_imageList->GetIcon( expandedIndex ); | |
1655 | ||
1656 | return GetStore()->AppendContainer( parent, text, icon, expanded, data ); | |
1657 | } | |
1658 | ||
1659 | wxDataViewItem wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous, | |
1660 | const wxString &text, int iconIndex, int expandedIndex, wxClientData *data ) | |
1661 | { | |
1662 | wxIcon icon = wxNullIcon; | |
1663 | if (m_imageList && (iconIndex != -1)) | |
1664 | icon = m_imageList->GetIcon( iconIndex ); | |
1665 | ||
1666 | wxIcon expanded = wxNullIcon; | |
1667 | if (m_imageList && (expandedIndex != -1)) | |
1668 | expanded = m_imageList->GetIcon( expandedIndex ); | |
1669 | ||
1670 | return GetStore()->InsertContainer( parent, previous, text, icon, expanded, data ); | |
1671 | } | |
1672 | ||
1673 | ||
1674 | void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent &event ) | |
1675 | { | |
1676 | if (m_imageList) return; | |
1677 | ||
1678 | wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() ); | |
1679 | if (!container) return; | |
1680 | ||
1681 | container->SetExpanded( true ); | |
1682 | GetStore()->ItemChanged( event.GetItem() ); | |
1683 | } | |
1684 | ||
1685 | void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent &event ) | |
1686 | { | |
1687 | if (m_imageList) return; | |
1688 | ||
1689 | wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() ); | |
1690 | if (!container) return; | |
1691 | ||
1692 | container->SetExpanded( false ); | |
1693 | GetStore()->ItemChanged( event.GetItem() ); | |
1694 | } | |
1695 | ||
1696 | ||
b5ec7dd6 | 1697 | #endif // wxUSE_DATAVIEWCTRL |
e0000f94 | 1698 |