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