]>
Commit | Line | Data |
---|---|---|
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 | ||
18 | #if wxUSE_DATAVIEWCTRL | |
19 | ||
20 | #include "wx/dataview.h" | |
21 | ||
22 | #include "wx/spinctrl.h" | |
23 | ||
24 | #ifndef WX_PRECOMP | |
25 | #include "wx/dc.h" | |
26 | #include "wx/settings.h" | |
27 | #include "wx/log.h" | |
28 | #include "wx/icon.h" | |
29 | #include "wx/crt.h" | |
30 | #endif | |
31 | ||
32 | const wxChar wxDataViewCtrlNameStr[] = wxT("dataviewCtrl"); | |
33 | ||
34 | ||
35 | bool operator == (const wxDataViewItem &left, const wxDataViewItem &right) | |
36 | { | |
37 | return (left.GetID() == right.GetID() ); | |
38 | } | |
39 | ||
40 | #ifdef __WXDEBUG__ | |
41 | void wxDataViewItem::Print(const wxString& text) const | |
42 | { | |
43 | wxPrintf("item %s: %l\n", text, (long)m_id); | |
44 | } | |
45 | #endif | |
46 | ||
47 | // --------------------------------------------------------- | |
48 | // wxDataViewModelNotifier | |
49 | // --------------------------------------------------------- | |
50 | ||
51 | #include "wx/listimpl.cpp" | |
52 | WX_DEFINE_LIST(wxDataViewModelNotifiers) | |
53 | ||
54 | bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items ) | |
55 | { | |
56 | size_t count = items.GetCount(); | |
57 | size_t i; | |
58 | for (i = 0; i < count; i++) | |
59 | if (!ItemAdded( parent, items[i] )) return false; | |
60 | ||
61 | return true; | |
62 | } | |
63 | ||
64 | bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items ) | |
65 | { | |
66 | size_t count = items.GetCount(); | |
67 | size_t i; | |
68 | for (i = 0; i < count; i++) | |
69 | if (!ItemDeleted( parent, items[i] )) return false; | |
70 | ||
71 | return true; | |
72 | } | |
73 | ||
74 | bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray &items ) | |
75 | { | |
76 | size_t count = items.GetCount(); | |
77 | size_t i; | |
78 | for (i = 0; i < count; i++) | |
79 | if (!ItemChanged( items[i] )) return false; | |
80 | ||
81 | return true; | |
82 | } | |
83 | ||
84 | // --------------------------------------------------------- | |
85 | // wxDataViewModel | |
86 | // --------------------------------------------------------- | |
87 | ||
88 | wxDataViewModel::wxDataViewModel() | |
89 | { | |
90 | m_notifiers.DeleteContents( true ); | |
91 | } | |
92 | ||
93 | bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) | |
94 | { | |
95 | bool ret = true; | |
96 | ||
97 | wxDataViewModelNotifiers::iterator iter; | |
98 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
99 | { | |
100 | wxDataViewModelNotifier* notifier = *iter; | |
101 | if (!notifier->ItemAdded( parent, item )) | |
102 | ret = false; | |
103 | } | |
104 | ||
105 | return ret; | |
106 | } | |
107 | ||
108 | bool wxDataViewModel::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) | |
109 | { | |
110 | bool ret = true; | |
111 | ||
112 | wxDataViewModelNotifiers::iterator iter; | |
113 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
114 | { | |
115 | wxDataViewModelNotifier* notifier = *iter; | |
116 | if (!notifier->ItemDeleted( parent, item )) | |
117 | ret = false; | |
118 | } | |
119 | ||
120 | return ret; | |
121 | } | |
122 | ||
123 | bool wxDataViewModel::ItemChanged( const wxDataViewItem &item ) | |
124 | { | |
125 | bool ret = true; | |
126 | ||
127 | wxDataViewModelNotifiers::iterator iter; | |
128 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
129 | { | |
130 | wxDataViewModelNotifier* notifier = *iter; | |
131 | if (!notifier->ItemChanged( item )) | |
132 | ret = false; | |
133 | } | |
134 | ||
135 | return ret; | |
136 | } | |
137 | ||
138 | bool wxDataViewModel::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items ) | |
139 | { | |
140 | bool ret = true; | |
141 | ||
142 | wxDataViewModelNotifiers::iterator iter; | |
143 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
144 | { | |
145 | wxDataViewModelNotifier* notifier = *iter; | |
146 | if (!notifier->ItemsAdded( parent, items )) | |
147 | ret = false; | |
148 | } | |
149 | ||
150 | return ret; | |
151 | } | |
152 | ||
153 | bool wxDataViewModel::ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items ) | |
154 | { | |
155 | bool ret = true; | |
156 | ||
157 | wxDataViewModelNotifiers::iterator iter; | |
158 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
159 | { | |
160 | wxDataViewModelNotifier* notifier = *iter; | |
161 | if (!notifier->ItemsDeleted( parent, items )) | |
162 | ret = false; | |
163 | } | |
164 | ||
165 | return ret; | |
166 | } | |
167 | ||
168 | bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray &items ) | |
169 | { | |
170 | bool ret = true; | |
171 | ||
172 | wxDataViewModelNotifiers::iterator iter; | |
173 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
174 | { | |
175 | wxDataViewModelNotifier* notifier = *iter; | |
176 | if (!notifier->ItemsChanged( items )) | |
177 | ret = false; | |
178 | } | |
179 | ||
180 | return ret; | |
181 | } | |
182 | ||
183 | bool wxDataViewModel::ValueChanged( const wxDataViewItem &item, unsigned int col ) | |
184 | { | |
185 | bool ret = true; | |
186 | ||
187 | wxDataViewModelNotifiers::iterator iter; | |
188 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
189 | { | |
190 | wxDataViewModelNotifier* notifier = *iter; | |
191 | if (!notifier->ValueChanged( item, col )) | |
192 | ret = false; | |
193 | } | |
194 | ||
195 | return ret; | |
196 | } | |
197 | ||
198 | bool wxDataViewModel::Cleared() | |
199 | { | |
200 | bool ret = true; | |
201 | ||
202 | wxDataViewModelNotifiers::iterator iter; | |
203 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
204 | { | |
205 | wxDataViewModelNotifier* notifier = *iter; | |
206 | if (!notifier->Cleared()) | |
207 | ret = false; | |
208 | } | |
209 | ||
210 | return ret; | |
211 | } | |
212 | ||
213 | void wxDataViewModel::Resort() | |
214 | { | |
215 | wxDataViewModelNotifiers::iterator iter; | |
216 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
217 | { | |
218 | wxDataViewModelNotifier* notifier = *iter; | |
219 | notifier->Resort(); | |
220 | } | |
221 | } | |
222 | ||
223 | void wxDataViewModel::AddNotifier( wxDataViewModelNotifier *notifier ) | |
224 | { | |
225 | m_notifiers.push_back( notifier ); | |
226 | notifier->SetOwner( this ); | |
227 | } | |
228 | ||
229 | void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier ) | |
230 | { | |
231 | m_notifiers.DeleteObject( notifier ); | |
232 | } | |
233 | ||
234 | int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, | |
235 | unsigned int column, bool ascending ) | |
236 | { | |
237 | // sort branches before leaves | |
238 | bool item1_is_container = IsContainer(item1); | |
239 | bool item2_is_container = IsContainer(item2); | |
240 | ||
241 | if (item1_is_container && !item2_is_container) | |
242 | return 1; | |
243 | if (item2_is_container && !item1_is_container) | |
244 | return -1; | |
245 | ||
246 | wxVariant value1,value2; | |
247 | GetValue( value1, item1, column ); | |
248 | GetValue( value2, item2, column ); | |
249 | ||
250 | if (!ascending) | |
251 | { | |
252 | wxVariant temp = value1; | |
253 | value1 = value2; | |
254 | value2 = temp; | |
255 | } | |
256 | ||
257 | if (value1.GetType() == wxT("string")) | |
258 | { | |
259 | wxString str1 = value1.GetString(); | |
260 | wxString str2 = value2.GetString(); | |
261 | int res = str1.Cmp( str2 ); | |
262 | if (res) return res; | |
263 | } else | |
264 | if (value1.GetType() == wxT("long")) | |
265 | { | |
266 | long l1 = value1.GetLong(); | |
267 | long l2 = value2.GetLong(); | |
268 | long res = l1-l2; | |
269 | if (res) return res; | |
270 | } else | |
271 | if (value1.GetType() == wxT("double")) | |
272 | { | |
273 | double d1 = value1.GetDouble(); | |
274 | double d2 = value2.GetDouble(); | |
275 | if (d1 < d2) return 1; | |
276 | if (d1 > d2) return -1; | |
277 | } else | |
278 | if (value1.GetType() == wxT("datetime")) | |
279 | { | |
280 | wxDateTime dt1 = value1.GetDateTime(); | |
281 | wxDateTime dt2 = value2.GetDateTime(); | |
282 | if (dt1.IsEarlierThan(dt2)) return 1; | |
283 | if (dt2.IsEarlierThan(dt1)) return -11; | |
284 | } | |
285 | ||
286 | // items must be different | |
287 | unsigned long litem1 = (unsigned long) item1.GetID(); | |
288 | unsigned long litem2 = (unsigned long) item2.GetID(); | |
289 | ||
290 | if (!ascending) | |
291 | return litem2-litem2; | |
292 | ||
293 | return litem1-litem2; | |
294 | } | |
295 | ||
296 | // --------------------------------------------------------- | |
297 | // wxDataViewIndexListModel | |
298 | // --------------------------------------------------------- | |
299 | ||
300 | wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size ) | |
301 | { | |
302 | #ifndef __WXMAC__ | |
303 | m_useHash = false; | |
304 | #else | |
305 | m_useHash = true; | |
306 | #endif | |
307 | ||
308 | if (m_useHash) | |
309 | { | |
310 | // IDs are ordered until an item gets deleted or inserted | |
311 | m_ordered = true; | |
312 | ||
313 | // build initial index | |
314 | unsigned int i; | |
315 | for (i = 1; i < initial_size+1; i++) | |
316 | m_hash.Add( (void*) i ); | |
317 | m_lastIndex = initial_size + 1; | |
318 | } | |
319 | else | |
320 | { | |
321 | m_lastIndex = initial_size-1; | |
322 | } | |
323 | } | |
324 | ||
325 | wxDataViewIndexListModel::~wxDataViewIndexListModel() | |
326 | { | |
327 | } | |
328 | ||
329 | void wxDataViewIndexListModel::RowPrepended() | |
330 | { | |
331 | if (m_useHash) | |
332 | { | |
333 | m_ordered = false; | |
334 | ||
335 | unsigned int id = m_lastIndex++; | |
336 | m_hash.Insert( (void*) id, 0 ); | |
337 | wxDataViewItem item( (void*) id ); | |
338 | ItemAdded( wxDataViewItem(0), item ); | |
339 | } | |
340 | else | |
341 | { | |
342 | m_lastIndex++; | |
343 | wxDataViewItem item( (void*) 0 ); | |
344 | ItemAdded( wxDataViewItem(0), item ); | |
345 | } | |
346 | } | |
347 | ||
348 | void wxDataViewIndexListModel::RowInserted( unsigned int before ) | |
349 | { | |
350 | if (m_useHash) | |
351 | { | |
352 | m_ordered = false; | |
353 | ||
354 | unsigned int id = m_lastIndex++; | |
355 | m_hash.Insert( (void*) id, before ); | |
356 | wxDataViewItem item( (void*) id ); | |
357 | ItemAdded( wxDataViewItem(0), item ); | |
358 | } | |
359 | else | |
360 | { | |
361 | m_lastIndex++; | |
362 | wxDataViewItem item( (void*) before ); | |
363 | ItemAdded( wxDataViewItem(0), item ); | |
364 | } | |
365 | } | |
366 | ||
367 | void wxDataViewIndexListModel::RowAppended() | |
368 | { | |
369 | if (m_useHash) | |
370 | { | |
371 | unsigned int id = m_lastIndex++; | |
372 | m_hash.Add( (void*) id ); | |
373 | wxDataViewItem item( (void*) id ); | |
374 | ItemAdded( wxDataViewItem(0), item ); | |
375 | } | |
376 | else | |
377 | { | |
378 | m_lastIndex++; | |
379 | wxDataViewItem item( (void*) m_lastIndex ); | |
380 | ItemAdded( wxDataViewItem(0), item ); | |
381 | } | |
382 | } | |
383 | ||
384 | void wxDataViewIndexListModel::RowDeleted( unsigned int row ) | |
385 | { | |
386 | if (m_useHash) | |
387 | { | |
388 | wxDataViewItem item( m_hash[row] ); | |
389 | wxDataViewModel::ItemDeleted( wxDataViewItem(0), item ); | |
390 | m_hash.RemoveAt( row ); | |
391 | } | |
392 | else | |
393 | { | |
394 | wxDataViewItem item( (void*) row ); | |
395 | wxDataViewModel::ItemDeleted( wxDataViewItem(0), item ); | |
396 | m_lastIndex++; | |
397 | } | |
398 | } | |
399 | ||
400 | void wxDataViewIndexListModel::RowChanged( unsigned int row ) | |
401 | { | |
402 | wxDataViewModel::ItemChanged( GetItem(row) ); | |
403 | } | |
404 | ||
405 | void wxDataViewIndexListModel::RowValueChanged( unsigned int row, unsigned int col ) | |
406 | { | |
407 | wxDataViewModel::ValueChanged( GetItem(row), col ); | |
408 | } | |
409 | ||
410 | unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const | |
411 | { | |
412 | if (m_useHash) | |
413 | { | |
414 | if (m_ordered) | |
415 | { | |
416 | unsigned int pos = wxPtrToUInt( item.GetID() ); | |
417 | return pos-1; | |
418 | } | |
419 | ||
420 | // assert for not found | |
421 | return (unsigned int) m_hash.Index( item.GetID() ); | |
422 | } | |
423 | else | |
424 | { | |
425 | return wxPtrToUInt( item.GetID() ); | |
426 | } | |
427 | } | |
428 | ||
429 | wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const | |
430 | { | |
431 | if (m_useHash) | |
432 | { | |
433 | wxASSERT( row < m_hash.GetCount() ); | |
434 | return wxDataViewItem( m_hash[row] ); | |
435 | } | |
436 | else | |
437 | { | |
438 | return wxDataViewItem( (void*) row ); | |
439 | } | |
440 | } | |
441 | ||
442 | bool wxDataViewIndexListModel::HasDefaultCompare() const | |
443 | { | |
444 | return !m_ordered; | |
445 | } | |
446 | ||
447 | int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1, | |
448 | const wxDataViewItem& item2, | |
449 | unsigned int WXUNUSED(column), | |
450 | bool ascending) | |
451 | { | |
452 | if (m_ordered || !m_useHash) | |
453 | { | |
454 | unsigned int pos1 = wxPtrToUInt(item1.GetID()); | |
455 | unsigned int pos2 = wxPtrToUInt(item2.GetID()); | |
456 | ||
457 | if (ascending) | |
458 | return pos1 - pos2; | |
459 | else | |
460 | return pos2 - pos1; | |
461 | } | |
462 | ||
463 | if (ascending) | |
464 | return GetRow(item1) - GetRow(item2); | |
465 | ||
466 | return GetRow(item2) - GetRow(item1); | |
467 | } | |
468 | ||
469 | void wxDataViewIndexListModel::GetValue( wxVariant &variant, | |
470 | const wxDataViewItem &item, unsigned int col ) const | |
471 | { | |
472 | GetValue( variant, GetRow(item), col ); | |
473 | } | |
474 | ||
475 | bool wxDataViewIndexListModel::SetValue( const wxVariant &variant, | |
476 | const wxDataViewItem &item, unsigned int col ) | |
477 | { | |
478 | return SetValue( variant, GetRow(item), col ); | |
479 | } | |
480 | ||
481 | bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr ) | |
482 | { | |
483 | return GetAttr( GetRow(item), col, attr ); | |
484 | } | |
485 | ||
486 | wxDataViewItem wxDataViewIndexListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const | |
487 | { | |
488 | return wxDataViewItem(0); | |
489 | } | |
490 | ||
491 | bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem &item ) const | |
492 | { | |
493 | // only the invisible root item has children | |
494 | if (!item.IsOk()) | |
495 | return true; | |
496 | ||
497 | return false; | |
498 | } | |
499 | ||
500 | unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const | |
501 | { | |
502 | if (!m_useHash) | |
503 | return 0; // error | |
504 | ||
505 | if (item.IsOk()) | |
506 | return 0; | |
507 | ||
508 | children = m_hash; | |
509 | ||
510 | return m_hash.GetCount(); | |
511 | } | |
512 | ||
513 | //----------------------------------------------------------------------------- | |
514 | // wxDataViewIconText | |
515 | //----------------------------------------------------------------------------- | |
516 | ||
517 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText,wxObject) | |
518 | ||
519 | IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV) | |
520 | ||
521 | bool operator == (const wxDataViewIconText &one, const wxDataViewIconText &two) | |
522 | { | |
523 | if (one.GetText() != two.GetText()) return false; | |
524 | if (one.IsSameAs(two)) return false; | |
525 | return true; | |
526 | } | |
527 | ||
528 | // --------------------------------------------------------- | |
529 | // wxDataViewRendererBase | |
530 | // --------------------------------------------------------- | |
531 | ||
532 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase, wxObject) | |
533 | ||
534 | wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype, | |
535 | wxDataViewCellMode WXUNUSED(mode), | |
536 | int WXUNUSED(align) ) | |
537 | { | |
538 | m_variantType = varianttype; | |
539 | m_editorCtrl = NULL; | |
540 | } | |
541 | ||
542 | const wxDataViewCtrl* wxDataViewRendererBase::GetView() const | |
543 | { | |
544 | return wx_const_cast(wxDataViewRendererBase*, this)->GetOwner()->GetOwner(); | |
545 | } | |
546 | ||
547 | bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect ) | |
548 | { | |
549 | m_item = item; // remember for later | |
550 | ||
551 | unsigned int col = GetOwner()->GetModelColumn(); | |
552 | wxVariant value; | |
553 | GetOwner()->GetOwner()->GetModel()->GetValue( value, item, col ); | |
554 | ||
555 | m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value ); | |
556 | ||
557 | wxDataViewEditorCtrlEvtHandler *handler = | |
558 | new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this ); | |
559 | ||
560 | m_editorCtrl->PushEventHandler( handler ); | |
561 | ||
562 | #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL) | |
563 | handler->SetFocusOnIdle(); | |
564 | #else | |
565 | m_editorCtrl->SetFocus(); | |
566 | #endif | |
567 | ||
568 | // Now we should send Editing Started event | |
569 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, GetOwner()->GetOwner()->GetId() ); | |
570 | event.SetDataViewColumn( GetOwner() ); | |
571 | event.SetModel( GetOwner()->GetOwner()->GetModel() ); | |
572 | event.SetItem( item ); | |
573 | GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event ); | |
574 | ||
575 | return true; | |
576 | } | |
577 | ||
578 | void wxDataViewRendererBase::CancelEditing() | |
579 | { | |
580 | wxPendingDelete.Append( m_editorCtrl ); | |
581 | ||
582 | GetOwner()->GetOwner()->GetMainWindow()->SetFocus(); | |
583 | ||
584 | // m_editorCtrl->PopEventHandler( true ); | |
585 | } | |
586 | ||
587 | bool wxDataViewRendererBase::FinishEditing() | |
588 | { | |
589 | wxVariant value; | |
590 | GetValueFromEditorCtrl( m_editorCtrl, value ); | |
591 | ||
592 | wxPendingDelete.Append( m_editorCtrl ); | |
593 | ||
594 | GetOwner()->GetOwner()->GetMainWindow()->SetFocus(); | |
595 | ||
596 | if (!Validate(value)) | |
597 | return false; | |
598 | ||
599 | unsigned int col = GetOwner()->GetModelColumn(); | |
600 | GetOwner()->GetOwner()->GetModel()->SetValue( value, m_item, col ); | |
601 | GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item, col ); | |
602 | ||
603 | // m_editorCtrl->PopEventHandler( true ); | |
604 | ||
605 | // Now we should send Editing Done event | |
606 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, GetOwner()->GetOwner()->GetId() ); | |
607 | event.SetDataViewColumn( GetOwner() ); | |
608 | event.SetModel( GetOwner()->GetOwner()->GetModel() ); | |
609 | event.SetItem( m_item ); | |
610 | GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event ); | |
611 | ||
612 | return true; | |
613 | } | |
614 | ||
615 | //----------------------------------------------------------------------------- | |
616 | // wxDataViewEditorCtrlEvtHandler | |
617 | //----------------------------------------------------------------------------- | |
618 | ||
619 | BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler) | |
620 | EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar) | |
621 | EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus) | |
622 | EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle) | |
623 | END_EVENT_TABLE() | |
624 | ||
625 | wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler( | |
626 | wxControl *editorCtrl, | |
627 | wxDataViewRenderer *owner ) | |
628 | { | |
629 | m_owner = owner; | |
630 | m_editorCtrl = editorCtrl; | |
631 | ||
632 | m_finished = false; | |
633 | } | |
634 | ||
635 | void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event ) | |
636 | { | |
637 | if (m_focusOnIdle) | |
638 | { | |
639 | m_focusOnIdle = false; | |
640 | if (wxWindow::FindFocus() != m_editorCtrl) | |
641 | m_editorCtrl->SetFocus(); | |
642 | } | |
643 | ||
644 | event.Skip(); | |
645 | } | |
646 | ||
647 | void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event ) | |
648 | { | |
649 | switch ( event.m_keyCode ) | |
650 | { | |
651 | case WXK_RETURN: | |
652 | m_finished = true; | |
653 | m_owner->FinishEditing(); | |
654 | break; | |
655 | ||
656 | case WXK_ESCAPE: | |
657 | m_finished = true; | |
658 | m_owner->CancelEditing(); | |
659 | break; | |
660 | ||
661 | default: | |
662 | event.Skip(); | |
663 | } | |
664 | } | |
665 | ||
666 | void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event ) | |
667 | { | |
668 | if (!m_finished) | |
669 | { | |
670 | m_finished = true; | |
671 | m_owner->FinishEditing(); | |
672 | } | |
673 | ||
674 | event.Skip(); | |
675 | } | |
676 | ||
677 | // --------------------------------------------------------- | |
678 | // wxDataViewColumnBase | |
679 | // --------------------------------------------------------- | |
680 | ||
681 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject) | |
682 | ||
683 | wxDataViewColumnBase::wxDataViewColumnBase(const wxString& WXUNUSED(title), | |
684 | wxDataViewRenderer *renderer, | |
685 | unsigned int model_column, | |
686 | int WXUNUSED(width), | |
687 | wxAlignment WXUNUSED(align), | |
688 | int WXUNUSED(flags)) | |
689 | { | |
690 | m_renderer = renderer; | |
691 | m_model_column = model_column; | |
692 | m_owner = NULL; | |
693 | m_renderer->SetOwner( (wxDataViewColumn*) this ); | |
694 | ||
695 | // NOTE: the wxDataViewColumn's ctor must store the width, align, flags | |
696 | // parameters inside the native control! | |
697 | } | |
698 | ||
699 | wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap& bitmap, | |
700 | wxDataViewRenderer *renderer, | |
701 | unsigned int model_column, | |
702 | int WXUNUSED(width), | |
703 | wxAlignment WXUNUSED(align), | |
704 | int WXUNUSED(flags) ) | |
705 | { | |
706 | m_renderer = renderer; | |
707 | m_model_column = model_column; | |
708 | m_bitmap = bitmap; | |
709 | m_owner = NULL; | |
710 | m_renderer->SetOwner( (wxDataViewColumn*) this ); | |
711 | } | |
712 | ||
713 | wxDataViewColumnBase::~wxDataViewColumnBase() | |
714 | { | |
715 | if (m_renderer) | |
716 | delete m_renderer; | |
717 | } | |
718 | ||
719 | int wxDataViewColumnBase::GetFlags() const | |
720 | { | |
721 | int ret = 0; | |
722 | ||
723 | if (IsSortable()) | |
724 | ret |= wxDATAVIEW_COL_SORTABLE; | |
725 | if (IsResizeable()) | |
726 | ret |= wxDATAVIEW_COL_RESIZABLE; | |
727 | if (IsHidden()) | |
728 | ret |= wxDATAVIEW_COL_HIDDEN; | |
729 | ||
730 | return ret; | |
731 | } | |
732 | ||
733 | void wxDataViewColumnBase::SetFlags(int flags) | |
734 | { | |
735 | SetSortable((flags & wxDATAVIEW_COL_SORTABLE) != 0); | |
736 | SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0); | |
737 | SetHidden((flags & wxDATAVIEW_COL_HIDDEN) != 0); | |
738 | } | |
739 | ||
740 | // --------------------------------------------------------- | |
741 | // wxDataViewCtrlBase | |
742 | // --------------------------------------------------------- | |
743 | ||
744 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl) | |
745 | ||
746 | wxDataViewCtrlBase::wxDataViewCtrlBase() | |
747 | { | |
748 | m_model = NULL; | |
749 | m_expander_column = 0; | |
750 | m_indent = 8; | |
751 | } | |
752 | ||
753 | wxDataViewCtrlBase::~wxDataViewCtrlBase() | |
754 | { | |
755 | if (m_model) | |
756 | { | |
757 | m_model->DecRef(); | |
758 | m_model = NULL; | |
759 | } | |
760 | } | |
761 | ||
762 | bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model ) | |
763 | { | |
764 | if (m_model) | |
765 | { | |
766 | m_model->DecRef(); // discard old model, if any | |
767 | } | |
768 | ||
769 | // add our own reference to the new model: | |
770 | m_model = model; | |
771 | if (m_model) | |
772 | { | |
773 | m_model->IncRef(); | |
774 | } | |
775 | ||
776 | return true; | |
777 | } | |
778 | ||
779 | wxDataViewModel* wxDataViewCtrlBase::GetModel() | |
780 | { | |
781 | return m_model; | |
782 | } | |
783 | ||
784 | const wxDataViewModel* wxDataViewCtrlBase::GetModel() const | |
785 | { | |
786 | return m_model; | |
787 | } | |
788 | ||
789 | wxDataViewColumn * | |
790 | wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column, | |
791 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
792 | { | |
793 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
794 | new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), | |
795 | model_column, width, align, flags ); | |
796 | AppendColumn( ret ); | |
797 | return ret; | |
798 | } | |
799 | ||
800 | wxDataViewColumn * | |
801 | wxDataViewCtrlBase::AppendIconTextColumn( const wxString &label, unsigned int model_column, | |
802 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
803 | { | |
804 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
805 | new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), | |
806 | model_column, width, align, flags ); | |
807 | AppendColumn( ret ); | |
808 | return ret; | |
809 | } | |
810 | ||
811 | wxDataViewColumn * | |
812 | wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column, | |
813 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
814 | { | |
815 | ||
816 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
817 | new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), | |
818 | model_column, width, align, flags ); | |
819 | AppendColumn( ret ); | |
820 | return ret; | |
821 | } | |
822 | ||
823 | wxDataViewColumn * | |
824 | wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column, | |
825 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
826 | { | |
827 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
828 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), | |
829 | model_column, width, align, flags ); | |
830 | AppendColumn( ret ); | |
831 | return ret; | |
832 | } | |
833 | ||
834 | wxDataViewColumn * | |
835 | wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column, | |
836 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
837 | { | |
838 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
839 | new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), | |
840 | model_column, width, align, flags ); | |
841 | AppendColumn( ret ); | |
842 | return ret; | |
843 | } | |
844 | ||
845 | wxDataViewColumn * | |
846 | wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column, | |
847 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
848 | { | |
849 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
850 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), | |
851 | model_column, width, align, flags ); | |
852 | AppendColumn( ret ); | |
853 | return ret; | |
854 | } | |
855 | ||
856 | wxDataViewColumn * | |
857 | wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column, | |
858 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
859 | { | |
860 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
861 | new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), | |
862 | model_column, width, align, flags ); | |
863 | AppendColumn( ret ); | |
864 | return ret; | |
865 | } | |
866 | ||
867 | wxDataViewColumn * | |
868 | wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap &label, unsigned int model_column, | |
869 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
870 | { | |
871 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
872 | new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), | |
873 | model_column, width, align, flags ); | |
874 | AppendColumn( ret ); | |
875 | return ret; | |
876 | } | |
877 | ||
878 | wxDataViewColumn * | |
879 | wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column, | |
880 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
881 | { | |
882 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
883 | new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), | |
884 | model_column, width, align, flags ); | |
885 | AppendColumn( ret ); | |
886 | return ret; | |
887 | } | |
888 | ||
889 | wxDataViewColumn * | |
890 | wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column, | |
891 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
892 | { | |
893 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
894 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), | |
895 | model_column, width, align, flags ); | |
896 | AppendColumn( ret ); | |
897 | return ret; | |
898 | } | |
899 | ||
900 | wxDataViewColumn * | |
901 | wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column, | |
902 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
903 | { | |
904 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
905 | new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), | |
906 | model_column, width, align, flags ); | |
907 | AppendColumn( ret ); | |
908 | return ret; | |
909 | } | |
910 | ||
911 | wxDataViewColumn * | |
912 | wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column, | |
913 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
914 | { | |
915 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
916 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), | |
917 | model_column, width, align, flags ); | |
918 | AppendColumn( ret ); | |
919 | return ret; | |
920 | } | |
921 | ||
922 | wxDataViewColumn * | |
923 | wxDataViewCtrlBase::PrependTextColumn( const wxString &label, unsigned int model_column, | |
924 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
925 | { | |
926 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
927 | new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), | |
928 | model_column, width, align, flags ); | |
929 | PrependColumn( ret ); | |
930 | return ret; | |
931 | } | |
932 | ||
933 | wxDataViewColumn * | |
934 | wxDataViewCtrlBase::PrependIconTextColumn( const wxString &label, unsigned int model_column, | |
935 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
936 | { | |
937 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
938 | new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), | |
939 | model_column, width, align, flags ); | |
940 | PrependColumn( ret ); | |
941 | return ret; | |
942 | } | |
943 | ||
944 | wxDataViewColumn * | |
945 | wxDataViewCtrlBase::PrependToggleColumn( const wxString &label, unsigned int model_column, | |
946 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
947 | { | |
948 | ||
949 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
950 | new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), | |
951 | model_column, width, align, flags ); | |
952 | PrependColumn( ret ); | |
953 | return ret; | |
954 | } | |
955 | ||
956 | wxDataViewColumn * | |
957 | wxDataViewCtrlBase::PrependProgressColumn( const wxString &label, unsigned int model_column, | |
958 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
959 | { | |
960 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
961 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), | |
962 | model_column, width, align, flags ); | |
963 | PrependColumn( ret ); | |
964 | return ret; | |
965 | } | |
966 | ||
967 | wxDataViewColumn * | |
968 | wxDataViewCtrlBase::PrependDateColumn( const wxString &label, unsigned int model_column, | |
969 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
970 | { | |
971 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
972 | new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), | |
973 | model_column, width, align, flags ); | |
974 | PrependColumn( ret ); | |
975 | return ret; | |
976 | } | |
977 | ||
978 | wxDataViewColumn * | |
979 | wxDataViewCtrlBase::PrependBitmapColumn( const wxString &label, unsigned int model_column, | |
980 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
981 | { | |
982 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
983 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), | |
984 | model_column, width, align, flags ); | |
985 | PrependColumn( ret ); | |
986 | return ret; | |
987 | } | |
988 | ||
989 | wxDataViewColumn * | |
990 | wxDataViewCtrlBase::PrependTextColumn( const wxBitmap &label, unsigned int model_column, | |
991 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
992 | { | |
993 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
994 | new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), | |
995 | model_column, width, align, flags ); | |
996 | PrependColumn( ret ); | |
997 | return ret; | |
998 | } | |
999 | ||
1000 | wxDataViewColumn * | |
1001 | wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap &label, unsigned int model_column, | |
1002 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1003 | { | |
1004 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
1005 | new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), | |
1006 | model_column, width, align, flags ); | |
1007 | PrependColumn( ret ); | |
1008 | return ret; | |
1009 | } | |
1010 | ||
1011 | wxDataViewColumn * | |
1012 | wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap &label, unsigned int model_column, | |
1013 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1014 | { | |
1015 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
1016 | new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), | |
1017 | model_column, width, align, flags ); | |
1018 | PrependColumn( ret ); | |
1019 | return ret; | |
1020 | } | |
1021 | ||
1022 | wxDataViewColumn * | |
1023 | wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap &label, unsigned int model_column, | |
1024 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1025 | { | |
1026 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
1027 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), | |
1028 | model_column, width, align, flags ); | |
1029 | PrependColumn( ret ); | |
1030 | return ret; | |
1031 | } | |
1032 | ||
1033 | wxDataViewColumn * | |
1034 | wxDataViewCtrlBase::PrependDateColumn( const wxBitmap &label, unsigned int model_column, | |
1035 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1036 | { | |
1037 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
1038 | new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), | |
1039 | model_column, width, align, flags ); | |
1040 | PrependColumn( ret ); | |
1041 | return ret; | |
1042 | } | |
1043 | ||
1044 | wxDataViewColumn * | |
1045 | wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap &label, unsigned int model_column, | |
1046 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) | |
1047 | { | |
1048 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
1049 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), | |
1050 | model_column, width, align, flags ); | |
1051 | PrependColumn( ret ); | |
1052 | return ret; | |
1053 | } | |
1054 | ||
1055 | bool | |
1056 | wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col ) | |
1057 | { | |
1058 | col->SetOwner( (wxDataViewCtrl*) this ); | |
1059 | return true; | |
1060 | } | |
1061 | ||
1062 | bool | |
1063 | wxDataViewCtrlBase::PrependColumn( wxDataViewColumn *col ) | |
1064 | { | |
1065 | col->SetOwner( (wxDataViewCtrl*) this ); | |
1066 | return true; | |
1067 | } | |
1068 | ||
1069 | // --------------------------------------------------------- | |
1070 | // wxDataViewEvent | |
1071 | // --------------------------------------------------------- | |
1072 | ||
1073 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent) | |
1074 | ||
1075 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED) | |
1076 | ||
1077 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED) | |
1078 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING) | |
1079 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED) | |
1080 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING) | |
1081 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED) | |
1082 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED) | |
1083 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE) | |
1084 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED) | |
1085 | ||
1086 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU) | |
1087 | ||
1088 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK) | |
1089 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK) | |
1090 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED) | |
1091 | ||
1092 | ||
1093 | // ------------------------------------- | |
1094 | // wxDataViewSpinRenderer | |
1095 | // ------------------------------------- | |
1096 | ||
1097 | wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min, int max, wxDataViewCellMode mode, int alignment ) : | |
1098 | wxDataViewCustomRenderer( "long", mode, alignment ) | |
1099 | { | |
1100 | m_min = min; | |
1101 | m_max = max; | |
1102 | } | |
1103 | ||
1104 | wxControl* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ) | |
1105 | { | |
1106 | long l = value; | |
1107 | return new wxSpinCtrl( parent, wxID_ANY, wxEmptyString, | |
1108 | labelRect.GetTopLeft(), labelRect.GetSize(), wxSP_ARROW_KEYS, m_min, m_max, l ); | |
1109 | } | |
1110 | ||
1111 | bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ) | |
1112 | { | |
1113 | wxSpinCtrl *sc = (wxSpinCtrl*) editor; | |
1114 | long l = sc->GetValue(); | |
1115 | value = l; | |
1116 | return true; | |
1117 | } | |
1118 | ||
1119 | bool wxDataViewSpinRenderer::Render( wxRect rect, wxDC *dc, int state ) | |
1120 | { | |
1121 | wxString str; | |
1122 | str.Printf( "%d", (int) m_data ); | |
1123 | RenderText( str, 0, rect, dc, state ); | |
1124 | return true; | |
1125 | } | |
1126 | ||
1127 | wxSize wxDataViewSpinRenderer::GetSize() const | |
1128 | { | |
1129 | return wxSize(80,16); | |
1130 | } | |
1131 | ||
1132 | bool wxDataViewSpinRenderer::SetValue( const wxVariant &value ) | |
1133 | { | |
1134 | m_data = value.GetLong(); | |
1135 | return true; | |
1136 | } | |
1137 | ||
1138 | bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const | |
1139 | { | |
1140 | value = m_data; | |
1141 | return true; | |
1142 | } | |
1143 | ||
1144 | //----------------------------------------------------------------------------- | |
1145 | // wxDataViewTreeStore | |
1146 | //----------------------------------------------------------------------------- | |
1147 | ||
1148 | wxDataViewTreeStoreNode::wxDataViewTreeStoreNode( | |
1149 | wxDataViewTreeStoreNode *parent, | |
1150 | const wxString &text, const wxIcon &icon, wxClientData *data ) | |
1151 | { | |
1152 | m_parent = parent; | |
1153 | m_text = text; | |
1154 | m_icon = icon; | |
1155 | m_data = data; | |
1156 | } | |
1157 | ||
1158 | wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode() | |
1159 | { | |
1160 | if (m_data) | |
1161 | delete m_data; | |
1162 | } | |
1163 | ||
1164 | #include "wx/listimpl.cpp" | |
1165 | WX_DEFINE_LIST(wxDataViewTreeStoreNodeList) | |
1166 | ||
1167 | wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode( | |
1168 | wxDataViewTreeStoreNode *parent, const wxString &text, | |
1169 | const wxIcon &icon, const wxIcon &expanded, wxClientData *data ) : | |
1170 | wxDataViewTreeStoreNode( parent, text, icon, data ) | |
1171 | { | |
1172 | m_iconExpanded = expanded; | |
1173 | m_isExpanded = false; | |
1174 | m_children.DeleteContents(true); | |
1175 | } | |
1176 | ||
1177 | wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode() | |
1178 | { | |
1179 | } | |
1180 | ||
1181 | //----------------------------------------------------------------------------- | |
1182 | ||
1183 | wxDataViewTreeStore::wxDataViewTreeStore() | |
1184 | { | |
1185 | m_root = new wxDataViewTreeStoreContainerNode( NULL, wxEmptyString ); | |
1186 | } | |
1187 | ||
1188 | wxDataViewTreeStore::~wxDataViewTreeStore() | |
1189 | { | |
1190 | delete m_root; | |
1191 | } | |
1192 | ||
1193 | wxDataViewItem wxDataViewTreeStore::AppendItem( const wxDataViewItem& parent, | |
1194 | const wxString &text, const wxIcon &icon, wxClientData *data ) | |
1195 | { | |
1196 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1197 | if (!parent_node) return wxDataViewItem(0); | |
1198 | ||
1199 | wxDataViewTreeStoreNode *node = | |
1200 | new wxDataViewTreeStoreNode( parent_node, text, icon, data ); | |
1201 | parent_node->GetChildren().Append( node ); | |
1202 | ||
1203 | // notify control | |
1204 | ItemAdded( parent, node->GetItem() ); | |
1205 | ||
1206 | return node->GetItem(); | |
1207 | } | |
1208 | ||
1209 | wxDataViewItem wxDataViewTreeStore::PrependItem( const wxDataViewItem& parent, | |
1210 | const wxString &text, const wxIcon &icon, wxClientData *data ) | |
1211 | { | |
1212 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1213 | if (!parent_node) return wxDataViewItem(0); | |
1214 | ||
1215 | wxDataViewTreeStoreNode *node = | |
1216 | new wxDataViewTreeStoreNode( parent_node, text, icon, data ); | |
1217 | parent_node->GetChildren().Insert( node ); | |
1218 | ||
1219 | // notify control | |
1220 | ItemAdded( parent, node->GetItem() ); | |
1221 | ||
1222 | return node->GetItem(); | |
1223 | } | |
1224 | ||
1225 | wxDataViewItem | |
1226 | wxDataViewTreeStore::InsertItem(const wxDataViewItem& WXUNUSED(parent), | |
1227 | const wxDataViewItem& WXUNUSED(previous), | |
1228 | const wxString& WXUNUSED(text), | |
1229 | const wxIcon& WXUNUSED(icon), | |
1230 | wxClientData * WXUNUSED(data)) | |
1231 | { | |
1232 | return wxDataViewItem(0); | |
1233 | } | |
1234 | ||
1235 | wxDataViewItem wxDataViewTreeStore::PrependContainer( const wxDataViewItem& parent, | |
1236 | const wxString &text, const wxIcon &icon, const wxIcon &expanded, | |
1237 | wxClientData *data ) | |
1238 | { | |
1239 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1240 | if (!parent_node) return wxDataViewItem(0); | |
1241 | ||
1242 | wxDataViewTreeStoreContainerNode *node = | |
1243 | new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data ); | |
1244 | parent_node->GetChildren().Insert( node ); | |
1245 | ||
1246 | // notify control | |
1247 | ItemAdded( parent, node->GetItem() ); | |
1248 | ||
1249 | return node->GetItem(); | |
1250 | } | |
1251 | ||
1252 | wxDataViewItem | |
1253 | wxDataViewTreeStore::AppendContainer(const wxDataViewItem& parent, | |
1254 | const wxString &text, | |
1255 | const wxIcon& icon, | |
1256 | const wxIcon& expanded, | |
1257 | wxClientData * data) | |
1258 | { | |
1259 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1260 | if (!parent_node) return wxDataViewItem(0); | |
1261 | ||
1262 | wxDataViewTreeStoreContainerNode *node = | |
1263 | new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data ); | |
1264 | parent_node->GetChildren().Append( node ); | |
1265 | ||
1266 | // notify control | |
1267 | ItemAdded( parent, node->GetItem() ); | |
1268 | ||
1269 | return node->GetItem(); | |
1270 | } | |
1271 | ||
1272 | wxDataViewItem | |
1273 | wxDataViewTreeStore::InsertContainer(const wxDataViewItem& WXUNUSED(parent), | |
1274 | const wxDataViewItem& WXUNUSED(previous), | |
1275 | const wxString& WXUNUSED(text), | |
1276 | const wxIcon& WXUNUSED(icon), | |
1277 | const wxIcon& WXUNUSED(expanded), | |
1278 | wxClientData * WXUNUSED(data)) | |
1279 | { | |
1280 | return wxDataViewItem(0); | |
1281 | } | |
1282 | ||
1283 | wxDataViewItem wxDataViewTreeStore::GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const | |
1284 | { | |
1285 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent ); | |
1286 | if (!parent_node) return wxDataViewItem(0); | |
1287 | ||
1288 | wxDataViewTreeStoreNodeList::compatibility_iterator node = parent_node->GetChildren().Item( pos ); | |
1289 | if (node) | |
1290 | return node->GetData(); | |
1291 | ||
1292 | return wxDataViewItem(0); | |
1293 | } | |
1294 | ||
1295 | int wxDataViewTreeStore::GetChildCount( const wxDataViewItem& parent ) const | |
1296 | { | |
1297 | wxDataViewTreeStoreNode *node = FindNode( parent ); | |
1298 | if (!node) return -1; | |
1299 | ||
1300 | if (!node->IsContainer()) | |
1301 | return 0; | |
1302 | ||
1303 | wxDataViewTreeStoreContainerNode *container_node = (wxDataViewTreeStoreContainerNode*) node; | |
1304 | return (int) container_node->GetChildren().GetCount(); | |
1305 | } | |
1306 | ||
1307 | void wxDataViewTreeStore::SetItemText( const wxDataViewItem& item, const wxString &text ) | |
1308 | { | |
1309 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1310 | if (!node) return; | |
1311 | ||
1312 | node->SetText( text ); | |
1313 | ||
1314 | // notify control | |
1315 | ValueChanged( item, 0 ); | |
1316 | } | |
1317 | ||
1318 | wxString wxDataViewTreeStore::GetItemText( const wxDataViewItem& item ) const | |
1319 | { | |
1320 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1321 | if (!node) return wxEmptyString; | |
1322 | ||
1323 | return node->GetText(); | |
1324 | } | |
1325 | ||
1326 | void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon ) | |
1327 | { | |
1328 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1329 | if (!node) return; | |
1330 | ||
1331 | node->SetIcon( icon ); | |
1332 | ||
1333 | // notify control | |
1334 | ValueChanged( item, 0 ); | |
1335 | } | |
1336 | ||
1337 | const wxIcon &wxDataViewTreeStore::GetItemIcon( const wxDataViewItem& item ) const | |
1338 | { | |
1339 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1340 | if (!node) return wxNullIcon; | |
1341 | ||
1342 | return node->GetIcon(); | |
1343 | } | |
1344 | ||
1345 | void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon ) | |
1346 | { | |
1347 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1348 | if (!node) return; | |
1349 | ||
1350 | node->SetExpandedIcon( icon ); | |
1351 | ||
1352 | // notify control | |
1353 | ValueChanged( item, 0 ); | |
1354 | } | |
1355 | ||
1356 | const wxIcon &wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem& item ) const | |
1357 | { | |
1358 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1359 | if (!node) return wxNullIcon; | |
1360 | ||
1361 | return node->GetExpandedIcon(); | |
1362 | } | |
1363 | ||
1364 | void wxDataViewTreeStore::SetItemData( const wxDataViewItem& item, wxClientData *data ) | |
1365 | { | |
1366 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1367 | if (!node) return; | |
1368 | ||
1369 | node->SetData( data ); | |
1370 | ||
1371 | // notify control? only sensible when sorting on client data | |
1372 | // ValueChanged( item, 0 ); | |
1373 | } | |
1374 | ||
1375 | wxClientData *wxDataViewTreeStore::GetItemData( const wxDataViewItem& item ) const | |
1376 | { | |
1377 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1378 | if (!node) return NULL; | |
1379 | ||
1380 | return node->GetData(); | |
1381 | } | |
1382 | ||
1383 | void wxDataViewTreeStore::DeleteItem( const wxDataViewItem& item ) | |
1384 | { | |
1385 | if (!item.IsOk()) return; | |
1386 | ||
1387 | wxDataViewItem parent_item = GetParent( item ); | |
1388 | ||
1389 | wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent_item ); | |
1390 | if (!parent_node) return; | |
1391 | ||
1392 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1393 | if (!node) return; | |
1394 | ||
1395 | parent_node->GetChildren().DeleteObject( node ); | |
1396 | ||
1397 | // notify control | |
1398 | ItemDeleted( parent_item, item ); | |
1399 | } | |
1400 | ||
1401 | void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem& item ) | |
1402 | { | |
1403 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1404 | if (!node) return; | |
1405 | ||
1406 | wxDataViewItemArray array; | |
1407 | wxDataViewTreeStoreNodeList::iterator iter; | |
1408 | for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++) | |
1409 | { | |
1410 | wxDataViewTreeStoreNode* child = *iter; | |
1411 | array.Add( child->GetItem() ); | |
1412 | } | |
1413 | ||
1414 | node->GetChildren().clear(); | |
1415 | ||
1416 | // notify control | |
1417 | ItemsDeleted( item, array ); | |
1418 | } | |
1419 | ||
1420 | void wxDataViewTreeStore::DeleteAllItems() | |
1421 | { | |
1422 | // TODO | |
1423 | } | |
1424 | ||
1425 | void | |
1426 | wxDataViewTreeStore::GetValue(wxVariant &variant, | |
1427 | const wxDataViewItem &item, | |
1428 | unsigned int WXUNUSED(col)) const | |
1429 | { | |
1430 | // if (col != 0) return; | |
1431 | ||
1432 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1433 | if (!node) return; | |
1434 | ||
1435 | wxIcon icon( node->GetIcon()); | |
1436 | if (node->IsContainer()) | |
1437 | { | |
1438 | wxDataViewTreeStoreContainerNode *container = (wxDataViewTreeStoreContainerNode*) node; | |
1439 | if (container->IsExpanded() && container->GetExpandedIcon().IsOk()) | |
1440 | icon = container->GetExpandedIcon(); | |
1441 | } | |
1442 | ||
1443 | wxDataViewIconText data( node->GetText(), icon ); | |
1444 | ||
1445 | variant << data; | |
1446 | } | |
1447 | ||
1448 | bool | |
1449 | wxDataViewTreeStore::SetValue(const wxVariant& variant, | |
1450 | const wxDataViewItem& item, | |
1451 | unsigned int WXUNUSED(col)) | |
1452 | { | |
1453 | // if (col != 0) return false; | |
1454 | ||
1455 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1456 | if (!node) return false; | |
1457 | ||
1458 | wxDataViewIconText data; | |
1459 | ||
1460 | data << variant; | |
1461 | ||
1462 | node->SetText( data.GetText() ); | |
1463 | node->SetIcon( data.GetIcon() ); | |
1464 | ||
1465 | return true; | |
1466 | } | |
1467 | ||
1468 | wxDataViewItem wxDataViewTreeStore::GetParent( const wxDataViewItem &item ) const | |
1469 | { | |
1470 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1471 | if (!node) return wxDataViewItem(0); | |
1472 | ||
1473 | wxDataViewTreeStoreNode *parent = node->GetParent(); | |
1474 | if (!parent) return wxDataViewItem(0); | |
1475 | ||
1476 | if (parent == m_root) | |
1477 | return wxDataViewItem(0); | |
1478 | ||
1479 | return parent->GetItem(); | |
1480 | } | |
1481 | ||
1482 | bool wxDataViewTreeStore::IsContainer( const wxDataViewItem &item ) const | |
1483 | { | |
1484 | wxDataViewTreeStoreNode *node = FindNode( item ); | |
1485 | if (!node) return false; | |
1486 | ||
1487 | return node->IsContainer(); | |
1488 | } | |
1489 | ||
1490 | unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const | |
1491 | { | |
1492 | wxDataViewTreeStoreContainerNode *node = FindContainerNode( item ); | |
1493 | if (!node) return 0; | |
1494 | ||
1495 | wxDataViewTreeStoreNodeList::iterator iter; | |
1496 | for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++) | |
1497 | { | |
1498 | wxDataViewTreeStoreNode* child = *iter; | |
1499 | children.Add( child->GetItem() ); | |
1500 | } | |
1501 | ||
1502 | return node->GetChildren().GetCount(); | |
1503 | } | |
1504 | ||
1505 | int wxDataViewTreeStore::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, | |
1506 | unsigned int WXUNUSED(column), bool WXUNUSED(ascending) ) | |
1507 | { | |
1508 | wxDataViewTreeStoreNode *node1 = FindNode( item1 ); | |
1509 | wxDataViewTreeStoreNode *node2 = FindNode( item2 ); | |
1510 | ||
1511 | if (!node1 || !node2) | |
1512 | return 0; | |
1513 | ||
1514 | wxDataViewTreeStoreContainerNode* parent1 = | |
1515 | (wxDataViewTreeStoreContainerNode*) node1->GetParent(); | |
1516 | wxDataViewTreeStoreContainerNode* parent2 = | |
1517 | (wxDataViewTreeStoreContainerNode*) node2->GetParent(); | |
1518 | ||
1519 | if (parent1 != parent2) | |
1520 | { | |
1521 | wxLogError( wxT("Comparing items with different parent.") ); | |
1522 | return 0; | |
1523 | } | |
1524 | ||
1525 | if (node1->IsContainer() && !!node2->IsContainer()) | |
1526 | return 1; | |
1527 | ||
1528 | if (node2->IsContainer() && !!node1->IsContainer()) | |
1529 | return -1; | |
1530 | ||
1531 | return parent1->GetChildren().IndexOf( node1 ) - parent1->GetChildren().IndexOf( node2 ); | |
1532 | } | |
1533 | ||
1534 | wxDataViewTreeStoreNode *wxDataViewTreeStore::FindNode( const wxDataViewItem &item ) const | |
1535 | { | |
1536 | if (!item.IsOk()) | |
1537 | return m_root; | |
1538 | ||
1539 | return (wxDataViewTreeStoreNode*) item.GetID(); | |
1540 | } | |
1541 | ||
1542 | wxDataViewTreeStoreContainerNode *wxDataViewTreeStore::FindContainerNode( const wxDataViewItem &item ) const | |
1543 | { | |
1544 | if (!item.IsOk()) | |
1545 | return (wxDataViewTreeStoreContainerNode*) m_root; | |
1546 | ||
1547 | wxDataViewTreeStoreNode* node = (wxDataViewTreeStoreNode*) item.GetID(); | |
1548 | ||
1549 | if (!node->IsContainer()) | |
1550 | return NULL; | |
1551 | ||
1552 | return (wxDataViewTreeStoreContainerNode*) node; | |
1553 | } | |
1554 | ||
1555 | //----------------------------------------------------------------------------- | |
1556 | // wxDataViewTreeCtrl | |
1557 | //----------------------------------------------------------------------------- | |
1558 | ||
1559 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl,wxDataViewCtrl) | |
1560 | ||
1561 | BEGIN_EVENT_TABLE(wxDataViewTreeCtrl,wxDataViewCtrl) | |
1562 | EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded) | |
1563 | EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed) | |
1564 | EVT_SIZE( wxDataViewTreeCtrl::OnSize ) | |
1565 | END_EVENT_TABLE() | |
1566 | ||
1567 | wxDataViewTreeCtrl::wxDataViewTreeCtrl() | |
1568 | { | |
1569 | m_imageList = NULL; | |
1570 | } | |
1571 | ||
1572 | wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow *parent, wxWindowID id, | |
1573 | const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator ) | |
1574 | { | |
1575 | m_imageList = NULL; | |
1576 | Create( parent, id, pos, size, style, validator ); | |
1577 | ||
1578 | wxDataViewTreeStore *store = new wxDataViewTreeStore; | |
1579 | AssociateModel( store ); | |
1580 | store->DecRef(); | |
1581 | ||
1582 | wxDataViewColumn *col = AppendIconTextColumn( "", 0, wxDATAVIEW_CELL_INERT, 40 ); | |
1583 | ||
1584 | #if !defined(__WXGTK20__) | |
1585 | wxSize cient_size = GetClientSize(); | |
1586 | col->SetWidth( size.x ); | |
1587 | #endif | |
1588 | } | |
1589 | ||
1590 | wxDataViewTreeCtrl::~wxDataViewTreeCtrl() | |
1591 | { | |
1592 | if (m_imageList) | |
1593 | delete m_imageList; | |
1594 | } | |
1595 | ||
1596 | bool wxDataViewTreeCtrl::Create( wxWindow *parent, wxWindowID id, | |
1597 | const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator ) | |
1598 | { | |
1599 | return wxDataViewCtrl::Create( parent, id, pos, size, style, validator ); | |
1600 | } | |
1601 | ||
1602 | void wxDataViewTreeCtrl::SetImageList( wxImageList *imagelist ) | |
1603 | { | |
1604 | if (m_imageList) | |
1605 | delete m_imageList; | |
1606 | ||
1607 | m_imageList = imagelist; | |
1608 | } | |
1609 | ||
1610 | wxDataViewItem wxDataViewTreeCtrl::AppendItem( const wxDataViewItem& parent, | |
1611 | const wxString &text, int iconIndex, wxClientData *data ) | |
1612 | { | |
1613 | wxIcon icon = wxNullIcon; | |
1614 | if (m_imageList && (iconIndex != -1)) | |
1615 | icon = m_imageList->GetIcon( iconIndex ); | |
1616 | ||
1617 | return GetStore()->AppendItem( parent, text, icon, data ); | |
1618 | } | |
1619 | ||
1620 | wxDataViewItem wxDataViewTreeCtrl::PrependItem( const wxDataViewItem& parent, | |
1621 | const wxString &text, int iconIndex, wxClientData *data ) | |
1622 | { | |
1623 | wxIcon icon = wxNullIcon; | |
1624 | if (m_imageList && (iconIndex != -1)) | |
1625 | icon = m_imageList->GetIcon( iconIndex ); | |
1626 | ||
1627 | return GetStore()->PrependItem( parent, text, icon, data ); | |
1628 | } | |
1629 | ||
1630 | wxDataViewItem wxDataViewTreeCtrl::InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous, | |
1631 | const wxString &text, int iconIndex, wxClientData *data ) | |
1632 | { | |
1633 | wxIcon icon = wxNullIcon; | |
1634 | if (m_imageList && (iconIndex != -1)) | |
1635 | icon = m_imageList->GetIcon( iconIndex ); | |
1636 | ||
1637 | return GetStore()->InsertItem( parent, previous, text, icon, data ); | |
1638 | } | |
1639 | ||
1640 | wxDataViewItem wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem& parent, | |
1641 | const wxString &text, int iconIndex, int expandedIndex, wxClientData *data ) | |
1642 | { | |
1643 | wxIcon icon = wxNullIcon; | |
1644 | if (m_imageList && (iconIndex != -1)) | |
1645 | icon = m_imageList->GetIcon( iconIndex ); | |
1646 | ||
1647 | wxIcon expanded = wxNullIcon; | |
1648 | if (m_imageList && (expandedIndex != -1)) | |
1649 | expanded = m_imageList->GetIcon( expandedIndex ); | |
1650 | ||
1651 | return GetStore()->PrependContainer( parent, text, icon, expanded, data ); | |
1652 | } | |
1653 | ||
1654 | wxDataViewItem wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem& parent, | |
1655 | const wxString &text, int iconIndex, int expandedIndex, wxClientData *data ) | |
1656 | { | |
1657 | wxIcon icon = wxNullIcon; | |
1658 | if (m_imageList && (iconIndex != -1)) | |
1659 | icon = m_imageList->GetIcon( iconIndex ); | |
1660 | ||
1661 | wxIcon expanded = wxNullIcon; | |
1662 | if (m_imageList && (expandedIndex != -1)) | |
1663 | expanded = m_imageList->GetIcon( expandedIndex ); | |
1664 | ||
1665 | return GetStore()->AppendContainer( parent, text, icon, expanded, data ); | |
1666 | } | |
1667 | ||
1668 | wxDataViewItem wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous, | |
1669 | const wxString &text, int iconIndex, int expandedIndex, wxClientData *data ) | |
1670 | { | |
1671 | wxIcon icon = wxNullIcon; | |
1672 | if (m_imageList && (iconIndex != -1)) | |
1673 | icon = m_imageList->GetIcon( iconIndex ); | |
1674 | ||
1675 | wxIcon expanded = wxNullIcon; | |
1676 | if (m_imageList && (expandedIndex != -1)) | |
1677 | expanded = m_imageList->GetIcon( expandedIndex ); | |
1678 | ||
1679 | return GetStore()->InsertContainer( parent, previous, text, icon, expanded, data ); | |
1680 | } | |
1681 | ||
1682 | void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent &event ) | |
1683 | { | |
1684 | if (m_imageList) return; | |
1685 | ||
1686 | wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() ); | |
1687 | if (!container) return; | |
1688 | ||
1689 | container->SetExpanded( true ); | |
1690 | GetStore()->ItemChanged( event.GetItem() ); | |
1691 | } | |
1692 | ||
1693 | void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent &event ) | |
1694 | { | |
1695 | if (m_imageList) return; | |
1696 | ||
1697 | wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() ); | |
1698 | if (!container) return; | |
1699 | ||
1700 | container->SetExpanded( false ); | |
1701 | GetStore()->ItemChanged( event.GetItem() ); | |
1702 | } | |
1703 | ||
1704 | void wxDataViewTreeCtrl::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
1705 | { | |
1706 | #if !defined(__WXGTK20__) | |
1707 | wxSize size = GetClientSize(); | |
1708 | wxDataViewColumn *col = GetColumn( 0 ); | |
1709 | if (col) col->SetWidth( size.x ); | |
1710 | #endif | |
1711 | } | |
1712 | ||
1713 | #endif // wxUSE_DATAVIEWCTRL | |
1714 |