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