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