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