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