]>
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 PC |
20 | #include "wx/dataview.h" |
21 | ||
f554a14b | 22 | #ifndef WX_PRECOMP |
f554a14b WS |
23 | #include "wx/log.h" |
24 | #endif | |
25 | ||
4a2e5ee8 | 26 | const wxChar wxDataViewCtrlNameStr[] = wxT("dataviewCtrl"); |
239eaa41 | 27 | |
239eaa41 | 28 | |
d5025dc0 RR |
29 | bool operator == (const wxDataViewItem &left, const wxDataViewItem &right) |
30 | { | |
31 | return (left.GetID() == right.GetID() ); | |
32 | } | |
33 | ||
34 | ||
f554a14b | 35 | // --------------------------------------------------------- |
d5025dc0 | 36 | // wxDataViewModel |
f554a14b | 37 | // --------------------------------------------------------- |
239eaa41 | 38 | |
9d8fe14a RR |
39 | #include <wx/listimpl.cpp> |
40 | WX_DEFINE_LIST(wxDataViewModelNotifiers); | |
41 | ||
e0062c04 | 42 | wxDataViewModel::wxDataViewModel() |
239eaa41 | 43 | { |
8f850e28 | 44 | m_notifiers.DeleteContents( true ); |
ef427989 | 45 | m_sortingColumn = 0; |
9a45b5d5 | 46 | m_ascending = true; |
239eaa41 RR |
47 | } |
48 | ||
e0062c04 | 49 | bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) |
239eaa41 | 50 | { |
8f850e28 RR |
51 | bool ret = true; |
52 | ||
9d8fe14a RR |
53 | wxDataViewModelNotifiers::iterator iter; |
54 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
8f850e28 | 55 | { |
9d8fe14a | 56 | wxDataViewModelNotifier* notifier = *iter; |
e0062c04 | 57 | if (!notifier->ItemAdded( parent, item )) |
8f850e28 | 58 | ret = false; |
8f850e28 | 59 | } |
f554a14b | 60 | |
8f850e28 | 61 | return ret; |
239eaa41 RR |
62 | } |
63 | ||
469d3e9b | 64 | bool wxDataViewModel::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) |
239eaa41 | 65 | { |
8f850e28 RR |
66 | bool ret = true; |
67 | ||
9d8fe14a RR |
68 | wxDataViewModelNotifiers::iterator iter; |
69 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
8f850e28 | 70 | { |
9d8fe14a | 71 | wxDataViewModelNotifier* notifier = *iter; |
469d3e9b | 72 | if (!notifier->ItemDeleted( parent, item )) |
8f850e28 | 73 | ret = false; |
8f850e28 | 74 | } |
f554a14b | 75 | |
8f850e28 | 76 | return ret; |
239eaa41 RR |
77 | } |
78 | ||
e0062c04 | 79 | bool wxDataViewModel::ItemChanged( const wxDataViewItem &item ) |
239eaa41 | 80 | { |
8f850e28 RR |
81 | bool ret = true; |
82 | ||
9d8fe14a RR |
83 | wxDataViewModelNotifiers::iterator iter; |
84 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
8f850e28 | 85 | { |
9d8fe14a | 86 | wxDataViewModelNotifier* notifier = *iter; |
e0062c04 | 87 | if (!notifier->ItemChanged( item )) |
8f850e28 | 88 | ret = false; |
8f850e28 | 89 | } |
f554a14b | 90 | |
8f850e28 | 91 | return ret; |
239eaa41 RR |
92 | } |
93 | ||
e0062c04 | 94 | bool wxDataViewModel::ValueChanged( const wxDataViewItem &item, unsigned int col ) |
239eaa41 | 95 | { |
8f850e28 | 96 | bool ret = true; |
b5d777c7 | 97 | |
9d8fe14a RR |
98 | wxDataViewModelNotifiers::iterator iter; |
99 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
b5d777c7 | 100 | { |
9d8fe14a | 101 | wxDataViewModelNotifier* notifier = *iter; |
e0062c04 | 102 | if (!notifier->ValueChanged( item, col )) |
8f850e28 | 103 | ret = false; |
b5d777c7 | 104 | } |
f554a14b | 105 | |
b5d777c7 | 106 | return ret; |
239eaa41 RR |
107 | } |
108 | ||
e0062c04 | 109 | bool wxDataViewModel::Cleared() |
4eccd3a1 RR |
110 | { |
111 | bool ret = true; | |
112 | ||
9d8fe14a RR |
113 | wxDataViewModelNotifiers::iterator iter; |
114 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
4eccd3a1 | 115 | { |
9d8fe14a | 116 | wxDataViewModelNotifier* notifier = *iter; |
8f850e28 RR |
117 | if (!notifier->Cleared()) |
118 | ret = false; | |
8f850e28 | 119 | } |
f554a14b | 120 | |
8f850e28 | 121 | return ret; |
239eaa41 RR |
122 | } |
123 | ||
ef427989 RR |
124 | void wxDataViewModel::Resort() |
125 | { | |
9d8fe14a RR |
126 | wxDataViewModelNotifiers::iterator iter; |
127 | for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) | |
ef427989 | 128 | { |
9d8fe14a | 129 | wxDataViewModelNotifier* notifier = *iter; |
ef427989 | 130 | notifier->Resort(); |
ef427989 RR |
131 | } |
132 | } | |
133 | ||
e0062c04 | 134 | void wxDataViewModel::AddNotifier( wxDataViewModelNotifier *notifier ) |
239eaa41 | 135 | { |
9d8fe14a | 136 | m_notifiers.push_back( notifier ); |
8f850e28 | 137 | notifier->SetOwner( this ); |
239eaa41 RR |
138 | } |
139 | ||
e0062c04 | 140 | void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier ) |
239eaa41 | 141 | { |
8f850e28 | 142 | m_notifiers.DeleteObject( notifier ); |
239eaa41 RR |
143 | } |
144 | ||
ef427989 RR |
145 | int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 ) |
146 | { | |
cf283a47 | 147 | // sort branches before leaves |
ed903e42 RR |
148 | bool item1_is_container = IsContainer(item1); |
149 | bool item2_is_container = IsContainer(item2); | |
cf283a47 | 150 | |
ed903e42 | 151 | if (item1_is_container && !item2_is_container) |
cf283a47 | 152 | return 1; |
ed903e42 | 153 | if (item2_is_container && !item1_is_container) |
cf283a47 RR |
154 | return -1; |
155 | ||
ef427989 RR |
156 | wxVariant value1,value2; |
157 | GetValue( value1, item1, m_sortingColumn ); | |
158 | GetValue( value2, item2, m_sortingColumn ); | |
cf283a47 | 159 | |
4508fcd2 RR |
160 | if (!m_ascending) |
161 | { | |
162 | wxVariant temp = value1; | |
163 | value1 = value2; | |
164 | value2 = temp; | |
165 | } | |
166 | ||
ef427989 RR |
167 | if (value1.GetType() == wxT("string")) |
168 | { | |
169 | wxString str1 = value1.GetString(); | |
170 | wxString str2 = value2.GetString(); | |
0be79c8a | 171 | int res = str1.Cmp( str2 ); |
cf283a47 RR |
172 | if (res) return res; |
173 | } else | |
ef427989 RR |
174 | if (value1.GetType() == wxT("long")) |
175 | { | |
176 | long l1 = value1.GetLong(); | |
177 | long l2 = value2.GetLong(); | |
cf283a47 RR |
178 | long res = l1-l2; |
179 | if (res) return res; | |
180 | } else | |
ef427989 RR |
181 | if (value1.GetType() == wxT("double")) |
182 | { | |
183 | double d1 = value1.GetDouble(); | |
184 | double d2 = value2.GetDouble(); | |
ef427989 | 185 | if (d1 < d2) return 1; |
cf283a47 RR |
186 | if (d1 > d2) return -1; |
187 | } else | |
ef427989 RR |
188 | if (value1.GetType() == wxT("datetime")) |
189 | { | |
190 | wxDateTime dt1 = value1.GetDateTime(); | |
191 | wxDateTime dt2 = value2.GetDateTime(); | |
ef427989 | 192 | if (dt1.IsEarlierThan(dt2)) return 1; |
cf283a47 | 193 | if (dt2.IsEarlierThan(dt1)) return -11; |
ef427989 RR |
194 | } |
195 | ||
cf283a47 RR |
196 | // items must be different |
197 | unsigned long litem1 = (unsigned long) item1.GetID(); | |
198 | unsigned long litem2 = (unsigned long) item2.GetID(); | |
199 | ||
200 | if (!m_ascending) | |
201 | return litem2-litem1; | |
202 | return litem1-litem2; | |
ef427989 RR |
203 | } |
204 | ||
c534e696 RR |
205 | // --------------------------------------------------------- |
206 | // wxDataViewIndexListModel | |
207 | // --------------------------------------------------------- | |
208 | ||
209 | wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size ) | |
210 | { | |
211 | // build initial index | |
212 | unsigned int i; | |
213 | for (i = 1; i < initial_size+1; i++) | |
214 | m_hash.Add( (void*) i ); | |
215 | m_lastIndex = initial_size + 1; | |
216 | } | |
217 | ||
218 | wxDataViewIndexListModel::~wxDataViewIndexListModel() | |
219 | { | |
220 | } | |
221 | ||
222 | void wxDataViewIndexListModel::RowPrepended() | |
223 | { | |
224 | unsigned int id = m_lastIndex++; | |
225 | m_hash.Insert( (void*) id, 0 ); | |
226 | wxDataViewItem item( (void*) id ); | |
227 | ItemAdded( wxDataViewItem(0), item ); | |
228 | } | |
229 | ||
230 | void wxDataViewIndexListModel::RowInserted( unsigned int before ) | |
231 | { | |
232 | unsigned int id = m_lastIndex++; | |
233 | m_hash.Insert( (void*) id, before ); | |
234 | wxDataViewItem item( (void*) id ); | |
235 | ItemAdded( wxDataViewItem(0), item ); | |
236 | } | |
237 | ||
238 | void wxDataViewIndexListModel::RowAppended() | |
239 | { | |
240 | unsigned int id = m_lastIndex++; | |
241 | m_hash.Add( (void*) id ); | |
242 | wxDataViewItem item( (void*) id ); | |
243 | ItemAdded( wxDataViewItem(0), item ); | |
244 | } | |
245 | ||
246 | void wxDataViewIndexListModel::RowDeleted( unsigned int row ) | |
247 | { | |
248 | wxDataViewItem item( m_hash[row] ); | |
249 | m_hash.RemoveAt( row ); | |
469d3e9b | 250 | wxDataViewModel::ItemDeleted( wxDataViewItem(0), item ); |
c534e696 RR |
251 | } |
252 | ||
253 | void wxDataViewIndexListModel::RowChanged( unsigned int row ) | |
254 | { | |
255 | wxDataViewModel::ItemChanged( GetItem(row) ); | |
256 | } | |
257 | ||
258 | void wxDataViewIndexListModel::RowValueChanged( unsigned int row, unsigned int col ) | |
259 | { | |
260 | wxDataViewModel::ValueChanged( GetItem(row), col ); | |
261 | } | |
262 | ||
263 | unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const | |
264 | { | |
265 | // assert for not found | |
266 | return (unsigned int) m_hash.Index( item.GetID() ); | |
267 | } | |
268 | ||
269 | wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const | |
270 | { | |
271 | return wxDataViewItem( m_hash[row] ); | |
272 | } | |
273 | ||
274 | int wxDataViewIndexListModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 ) | |
275 | { | |
276 | return GetRow(item1) - GetRow(item2); | |
277 | } | |
278 | ||
279 | void wxDataViewIndexListModel::GetValue( wxVariant &variant, | |
280 | const wxDataViewItem &item, unsigned int col ) const | |
281 | { | |
282 | return GetValue( variant, GetRow(item), col ); | |
283 | } | |
284 | ||
285 | bool wxDataViewIndexListModel::SetValue( const wxVariant &variant, | |
286 | const wxDataViewItem &item, unsigned int col ) | |
287 | { | |
288 | return SetValue( variant, GetRow(item), col ); | |
289 | } | |
290 | ||
291 | wxDataViewItem wxDataViewIndexListModel::GetParent( const wxDataViewItem &item ) const | |
292 | { | |
293 | return wxDataViewItem(0); | |
294 | } | |
295 | ||
296 | bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem &item ) const | |
297 | { | |
298 | // only the invisible root item has children | |
299 | if (!item.IsOk()) | |
300 | return true; | |
301 | ||
302 | return false; | |
303 | } | |
304 | ||
305 | wxDataViewItem wxDataViewIndexListModel::GetFirstChild( const wxDataViewItem &parent ) const | |
306 | { | |
307 | if (!parent.IsOk()) | |
308 | { | |
309 | if (m_hash.GetCount() == 0) | |
310 | return wxDataViewItem(0); | |
311 | ||
312 | return wxDataViewItem( m_hash[0]); | |
313 | } | |
314 | ||
315 | return wxDataViewItem(0); | |
316 | } | |
317 | ||
318 | wxDataViewItem wxDataViewIndexListModel::GetNextSibling( const wxDataViewItem &item ) const | |
319 | { | |
320 | if (!item.IsOk()) | |
321 | return wxDataViewItem(0); | |
322 | ||
323 | int pos = m_hash.Index( item.GetID() ); | |
324 | if ((pos == wxNOT_FOUND) || (pos == m_hash.GetCount()-1)) | |
325 | return wxDataViewItem(0); | |
326 | ||
327 | return wxDataViewItem( m_hash[pos+1] ); | |
328 | } | |
329 | ||
f554a14b | 330 | // --------------------------------------------------------- |
baa9ebc4 | 331 | // wxDataViewRendererBase |
f554a14b | 332 | // --------------------------------------------------------- |
6842a71a | 333 | |
baa9ebc4 | 334 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase, wxObject) |
6842a71a | 335 | |
9861f022 RR |
336 | wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype, |
337 | wxDataViewCellMode WXUNUSED(mode), | |
338 | int WXUNUSED(align) ) | |
6842a71a RR |
339 | { |
340 | m_variantType = varianttype; | |
1e510b1e | 341 | m_editorCtrl = NULL; |
9861f022 RR |
342 | } |
343 | ||
344 | const wxDataViewCtrl* wxDataViewRendererBase::GetView() const | |
345 | { | |
346 | return wx_const_cast(wxDataViewRendererBase*, this)->GetOwner()->GetOwner(); | |
6842a71a | 347 | } |
f554a14b | 348 | |
e0062c04 | 349 | bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect ) |
1e510b1e | 350 | { |
e0062c04 | 351 | m_item = item; // remember for later |
1e510b1e RR |
352 | |
353 | unsigned int col = GetOwner()->GetModelColumn(); | |
354 | wxVariant value; | |
e0062c04 | 355 | GetOwner()->GetOwner()->GetModel()->GetValue( value, item, col ); |
1e510b1e RR |
356 | |
357 | m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value ); | |
358 | ||
30715fa1 RR |
359 | wxDataViewEditorCtrlEvtHandler *handler = |
360 | new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this ); | |
361 | ||
362 | m_editorCtrl->PushEventHandler( handler ); | |
1e510b1e | 363 | |
30715fa1 RR |
364 | #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL) |
365 | handler->SetFocusOnIdle(); | |
366 | #else | |
1e510b1e | 367 | m_editorCtrl->SetFocus(); |
30715fa1 RR |
368 | #endif |
369 | ||
1e510b1e RR |
370 | return true; |
371 | } | |
372 | ||
373 | void wxDataViewRendererBase::CancelEditing() | |
374 | { | |
2fa73716 | 375 | wxPendingDelete.Append( m_editorCtrl ); |
1e510b1e RR |
376 | |
377 | GetOwner()->GetOwner()->GetMainWindow()->SetFocus(); | |
2fa73716 RR |
378 | |
379 | // m_editorCtrl->PopEventHandler( true ); | |
1e510b1e RR |
380 | } |
381 | ||
382 | bool wxDataViewRendererBase::FinishEditing() | |
383 | { | |
1e510b1e RR |
384 | wxVariant value; |
385 | GetValueFromEditorCtrl( m_editorCtrl, value ); | |
386 | ||
2fa73716 | 387 | wxPendingDelete.Append( m_editorCtrl ); |
1e510b1e RR |
388 | |
389 | GetOwner()->GetOwner()->GetMainWindow()->SetFocus(); | |
390 | ||
391 | if (!Validate(value)) | |
392 | return false; | |
393 | ||
394 | unsigned int col = GetOwner()->GetModelColumn(); | |
e0062c04 RR |
395 | GetOwner()->GetOwner()->GetModel()->SetValue( value, m_item, col ); |
396 | GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item, col ); | |
1e510b1e | 397 | |
2fa73716 RR |
398 | // m_editorCtrl->PopEventHandler( true ); |
399 | ||
1e510b1e RR |
400 | return true; |
401 | } | |
402 | ||
403 | //----------------------------------------------------------------------------- | |
404 | // wxDataViewEditorCtrlEvtHandler | |
405 | //----------------------------------------------------------------------------- | |
406 | ||
407 | BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler) | |
408 | EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar) | |
409 | EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus) | |
30715fa1 | 410 | EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle) |
1e510b1e RR |
411 | END_EVENT_TABLE() |
412 | ||
413 | wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler( | |
414 | wxControl *editorCtrl, | |
415 | wxDataViewRenderer *owner ) | |
416 | { | |
417 | m_owner = owner; | |
418 | m_editorCtrl = editorCtrl; | |
419 | ||
420 | m_finished = false; | |
421 | } | |
422 | ||
30715fa1 RR |
423 | void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event ) |
424 | { | |
425 | if (m_focusOnIdle) | |
426 | { | |
427 | m_focusOnIdle = false; | |
428 | if (wxWindow::FindFocus() != m_editorCtrl) | |
429 | m_editorCtrl->SetFocus(); | |
430 | } | |
431 | ||
432 | event.Skip(); | |
433 | } | |
434 | ||
1e510b1e RR |
435 | void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event ) |
436 | { | |
437 | switch ( event.m_keyCode ) | |
438 | { | |
439 | case WXK_RETURN: | |
440 | m_finished = true; | |
441 | m_owner->FinishEditing(); | |
442 | break; | |
443 | ||
444 | case WXK_ESCAPE: | |
445 | m_finished = true; | |
446 | m_owner->CancelEditing(); | |
447 | break; | |
448 | ||
449 | default: | |
450 | event.Skip(); | |
451 | } | |
452 | } | |
453 | ||
454 | void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event ) | |
455 | { | |
456 | if (!m_finished) | |
457 | { | |
458 | m_finished = true; | |
459 | m_owner->FinishEditing(); | |
460 | } | |
461 | ||
1e510b1e RR |
462 | event.Skip(); |
463 | } | |
464 | ||
f554a14b | 465 | // --------------------------------------------------------- |
fa28826d | 466 | // wxDataViewColumnBase |
f554a14b | 467 | // --------------------------------------------------------- |
fa28826d RR |
468 | |
469 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject) | |
470 | ||
9861f022 | 471 | wxDataViewColumnBase::wxDataViewColumnBase(const wxString& WXUNUSED(title), |
baa9ebc4 | 472 | wxDataViewRenderer *renderer, |
0a71f9e9 | 473 | unsigned int model_column, |
008b5a66 | 474 | int WXUNUSED(width), |
87f0efe2 | 475 | wxAlignment WXUNUSED(align), |
9861f022 | 476 | int WXUNUSED(flags)) |
fa28826d | 477 | { |
baa9ebc4 | 478 | m_renderer = renderer; |
6842a71a | 479 | m_model_column = model_column; |
6842a71a | 480 | m_owner = NULL; |
baa9ebc4 | 481 | m_renderer->SetOwner( (wxDataViewColumn*) this ); |
9861f022 RR |
482 | |
483 | // NOTE: the wxDataViewColumn's ctor must store the width, align, flags | |
484 | // parameters inside the native control! | |
6842a71a RR |
485 | } |
486 | ||
07a84e7b RR |
487 | wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap& bitmap, |
488 | wxDataViewRenderer *renderer, | |
489 | unsigned int model_column, | |
490 | int WXUNUSED(width), | |
87f0efe2 | 491 | wxAlignment WXUNUSED(align), |
9861f022 | 492 | int WXUNUSED(flags) ) |
07a84e7b RR |
493 | { |
494 | m_renderer = renderer; | |
495 | m_model_column = model_column; | |
07a84e7b RR |
496 | m_bitmap = bitmap; |
497 | m_owner = NULL; | |
498 | m_renderer->SetOwner( (wxDataViewColumn*) this ); | |
499 | } | |
500 | ||
6842a71a RR |
501 | wxDataViewColumnBase::~wxDataViewColumnBase() |
502 | { | |
baa9ebc4 RR |
503 | if (m_renderer) |
504 | delete m_renderer; | |
fa28826d RR |
505 | } |
506 | ||
9861f022 | 507 | int wxDataViewColumnBase::GetFlags() const |
fa28826d | 508 | { |
9861f022 | 509 | int ret = 0; |
fa28826d | 510 | |
9861f022 RR |
511 | if (IsSortable()) |
512 | ret |= wxDATAVIEW_COL_SORTABLE; | |
513 | if (IsResizeable()) | |
514 | ret |= wxDATAVIEW_COL_RESIZABLE; | |
515 | if (IsHidden()) | |
516 | ret |= wxDATAVIEW_COL_HIDDEN; | |
fa28826d | 517 | |
9861f022 | 518 | return ret; |
07a84e7b RR |
519 | } |
520 | ||
9861f022 | 521 | void wxDataViewColumnBase::SetFlags(int flags) |
07a84e7b | 522 | { |
9861f022 RR |
523 | SetSortable((flags & wxDATAVIEW_COL_SORTABLE) != 0); |
524 | SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0); | |
525 | SetHidden((flags & wxDATAVIEW_COL_HIDDEN) != 0); | |
07a84e7b RR |
526 | } |
527 | ||
f554a14b | 528 | // --------------------------------------------------------- |
239eaa41 | 529 | // wxDataViewCtrlBase |
f554a14b | 530 | // --------------------------------------------------------- |
239eaa41 RR |
531 | |
532 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl) | |
533 | ||
534 | wxDataViewCtrlBase::wxDataViewCtrlBase() | |
535 | { | |
536 | m_model = NULL; | |
fa28826d | 537 | m_cols.DeleteContents( true ); |
3b6280be RR |
538 | m_expander_column = 0; |
539 | m_indent = 8; | |
239eaa41 RR |
540 | } |
541 | ||
542 | wxDataViewCtrlBase::~wxDataViewCtrlBase() | |
543 | { | |
87f0efe2 RR |
544 | // IMPORTANT: before calling DecRef() on our model (since it may |
545 | // result in a free() call), erase all columns (since | |
546 | // they hold a pointer to our model) | |
547 | m_cols.Clear(); | |
548 | ||
549 | if (m_model) | |
550 | { | |
551 | m_model->DecRef(); | |
552 | m_model = NULL; | |
553 | } | |
239eaa41 RR |
554 | } |
555 | ||
e0062c04 | 556 | bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model ) |
239eaa41 | 557 | { |
1821abd1 RR |
558 | if (m_model) |
559 | { | |
87f0efe2 | 560 | m_model->DecRef(); // discard old model, if any |
1821abd1 | 561 | } |
87f0efe2 RR |
562 | |
563 | // add our own reference to the new model: | |
239eaa41 | 564 | m_model = model; |
1821abd1 RR |
565 | if (m_model) |
566 | { | |
87f0efe2 | 567 | m_model->IncRef(); |
1821abd1 | 568 | } |
f554a14b | 569 | |
239eaa41 RR |
570 | return true; |
571 | } | |
572 | ||
e0062c04 | 573 | wxDataViewModel* wxDataViewCtrlBase::GetModel() |
239eaa41 RR |
574 | { |
575 | return m_model; | |
576 | } | |
577 | ||
1286b7ba | 578 | bool wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column, |
87f0efe2 | 579 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
fa28826d | 580 | { |
1286b7ba | 581 | return AppendColumn( new wxDataViewColumn( label, |
9861f022 RR |
582 | new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), |
583 | model_column, width, align, flags ) ); | |
fa28826d RR |
584 | } |
585 | ||
1286b7ba | 586 | bool wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column, |
87f0efe2 | 587 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
605c2c4a | 588 | { |
1286b7ba | 589 | return AppendColumn( new wxDataViewColumn( label, |
9861f022 RR |
590 | new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), |
591 | model_column, width, align, flags ) ); | |
605c2c4a RR |
592 | } |
593 | ||
1286b7ba | 594 | bool wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column, |
87f0efe2 | 595 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
ad63bf41 | 596 | { |
1286b7ba | 597 | return AppendColumn( new wxDataViewColumn( label, |
9861f022 RR |
598 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), |
599 | model_column, width, align, flags ) ); | |
ad63bf41 RR |
600 | } |
601 | ||
1286b7ba | 602 | bool wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column, |
87f0efe2 | 603 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
4d496ecb | 604 | { |
1286b7ba | 605 | return AppendColumn( new wxDataViewColumn( label, |
9861f022 RR |
606 | new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), |
607 | model_column, width, align, flags ) ); | |
4d496ecb RR |
608 | } |
609 | ||
1286b7ba | 610 | bool wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column, |
87f0efe2 | 611 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 612 | { |
1286b7ba | 613 | return AppendColumn( new wxDataViewColumn( label, |
9861f022 RR |
614 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), |
615 | model_column, width, align, flags ) ); | |
07a84e7b RR |
616 | } |
617 | ||
1286b7ba | 618 | bool wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column, |
87f0efe2 | 619 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 620 | { |
1286b7ba | 621 | return AppendColumn( new wxDataViewColumn( label, |
9861f022 RR |
622 | new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), |
623 | model_column, width, align, flags ) ); | |
07a84e7b RR |
624 | } |
625 | ||
1286b7ba | 626 | bool wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column, |
87f0efe2 | 627 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 628 | { |
1286b7ba | 629 | return AppendColumn( new wxDataViewColumn( label, |
9861f022 RR |
630 | new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), |
631 | model_column, width, align, flags ) ); | |
07a84e7b RR |
632 | } |
633 | ||
1286b7ba | 634 | bool wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column, |
87f0efe2 | 635 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 636 | { |
1286b7ba | 637 | return AppendColumn( new wxDataViewColumn( label, |
9861f022 RR |
638 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), |
639 | model_column, width, align, flags ) ); | |
07a84e7b RR |
640 | } |
641 | ||
1286b7ba | 642 | bool wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column, |
87f0efe2 | 643 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 644 | { |
1286b7ba | 645 | return AppendColumn( new wxDataViewColumn( label, |
9861f022 RR |
646 | new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), |
647 | model_column, width, align, flags ) ); | |
07a84e7b RR |
648 | } |
649 | ||
1286b7ba | 650 | bool wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column, |
87f0efe2 | 651 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 652 | { |
1286b7ba | 653 | return AppendColumn( new wxDataViewColumn( label, |
9861f022 RR |
654 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), |
655 | model_column, width, align, flags ) ); | |
07a84e7b RR |
656 | } |
657 | ||
fa28826d RR |
658 | bool wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col ) |
659 | { | |
660 | m_cols.Append( (wxObject*) col ); | |
6842a71a | 661 | col->SetOwner( (wxDataViewCtrl*) this ); |
fa28826d RR |
662 | return true; |
663 | } | |
664 | ||
9861f022 | 665 | unsigned int wxDataViewCtrlBase::GetColumnCount() const |
fa28826d RR |
666 | { |
667 | return m_cols.GetCount(); | |
668 | } | |
669 | ||
0a71f9e9 | 670 | bool wxDataViewCtrlBase::DeleteColumn( unsigned int WXUNUSED(pos) ) |
fa28826d RR |
671 | { |
672 | return false; | |
673 | } | |
674 | ||
675 | bool wxDataViewCtrlBase::ClearColumns() | |
676 | { | |
677 | return false; | |
678 | } | |
679 | ||
0a71f9e9 | 680 | wxDataViewColumn* wxDataViewCtrlBase::GetColumn( unsigned int pos ) |
fa28826d RR |
681 | { |
682 | return (wxDataViewColumn*) m_cols[ pos ]; | |
683 | } | |
684 | ||
eb7f97f8 RR |
685 | // --------------------------------------------------------- |
686 | // wxDataViewEvent | |
687 | // --------------------------------------------------------- | |
688 | ||
689 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent) | |
690 | ||
e0062c04 RR |
691 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED) |
692 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED) | |
31fb32e1 RR |
693 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK) |
694 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK) | |
c0a66d92 | 695 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED) |
eb7f97f8 | 696 | |
e0062c04 RR |
697 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED) |
698 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED) | |
699 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED) | |
1821abd1 | 700 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED) |
1821abd1 | 701 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED) |
eb7f97f8 | 702 | |
8045736e | 703 | #endif |