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