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