]>
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 | |
fbda518c | 39 | #include <wx/listimpl.cpp> |
9d8fe14a RR |
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 | { | |
fbda518c | 271 | wxASSERT( row < m_hash.GetCount() ); |
c534e696 RR |
272 | return wxDataViewItem( m_hash[row] ); |
273 | } | |
274 | ||
7ee7191c RR |
275 | int wxDataViewIndexListModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, |
276 | unsigned int column, bool ascending ) | |
c534e696 | 277 | { |
7ee7191c RR |
278 | if (ascending) |
279 | return GetRow(item1) - GetRow(item2); | |
280 | ||
281 | return GetRow(item2) - GetRow(item1); | |
c534e696 RR |
282 | } |
283 | ||
900af470 | 284 | void wxDataViewIndexListModel::GetValue( wxVariant &variant, |
c534e696 RR |
285 | const wxDataViewItem &item, unsigned int col ) const |
286 | { | |
900af470 | 287 | GetValue( variant, GetRow(item), col ); |
c534e696 RR |
288 | } |
289 | ||
900af470 | 290 | bool wxDataViewIndexListModel::SetValue( const wxVariant &variant, |
c534e696 RR |
291 | const wxDataViewItem &item, unsigned int col ) |
292 | { | |
293 | return SetValue( variant, GetRow(item), col ); | |
294 | } | |
295 | ||
900af470 | 296 | wxDataViewItem wxDataViewIndexListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const |
c534e696 RR |
297 | { |
298 | return wxDataViewItem(0); | |
299 | } | |
300 | ||
301 | bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem &item ) const | |
302 | { | |
303 | // only the invisible root item has children | |
304 | if (!item.IsOk()) | |
305 | return true; | |
900af470 | 306 | |
c534e696 RR |
307 | return false; |
308 | } | |
309 | ||
310 | wxDataViewItem wxDataViewIndexListModel::GetFirstChild( const wxDataViewItem &parent ) const | |
311 | { | |
312 | if (!parent.IsOk()) | |
313 | { | |
314 | if (m_hash.GetCount() == 0) | |
315 | return wxDataViewItem(0); | |
900af470 | 316 | |
c534e696 RR |
317 | return wxDataViewItem( m_hash[0]); |
318 | } | |
900af470 | 319 | |
c534e696 RR |
320 | return wxDataViewItem(0); |
321 | } | |
322 | ||
323 | wxDataViewItem wxDataViewIndexListModel::GetNextSibling( const wxDataViewItem &item ) const | |
324 | { | |
325 | if (!item.IsOk()) | |
326 | return wxDataViewItem(0); | |
900af470 | 327 | |
c534e696 | 328 | int pos = m_hash.Index( item.GetID() ); |
900af470 | 329 | if ((pos == wxNOT_FOUND) || (pos == (int) (m_hash.GetCount()-1))) |
c534e696 | 330 | return wxDataViewItem(0); |
900af470 | 331 | |
c534e696 RR |
332 | return wxDataViewItem( m_hash[pos+1] ); |
333 | } | |
334 | ||
89352653 RR |
335 | //----------------------------------------------------------------------------- |
336 | // wxDataViewIconText | |
337 | //----------------------------------------------------------------------------- | |
338 | ||
339 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText,wxObject) | |
340 | ||
341 | IMPLEMENT_VARIANT_OBJECT(wxDataViewIconText) | |
342 | ||
343 | bool operator == (const wxDataViewIconText &one, const wxDataViewIconText &two) | |
344 | { | |
345 | if (one.GetText() != two.GetText()) return false; | |
346 | if (one.IsSameAs(two)) return false; | |
347 | return true; | |
348 | } | |
349 | ||
f554a14b | 350 | // --------------------------------------------------------- |
baa9ebc4 | 351 | // wxDataViewRendererBase |
f554a14b | 352 | // --------------------------------------------------------- |
6842a71a | 353 | |
baa9ebc4 | 354 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase, wxObject) |
6842a71a | 355 | |
900af470 | 356 | wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype, |
9861f022 RR |
357 | wxDataViewCellMode WXUNUSED(mode), |
358 | int WXUNUSED(align) ) | |
6842a71a RR |
359 | { |
360 | m_variantType = varianttype; | |
1e510b1e | 361 | m_editorCtrl = NULL; |
9861f022 RR |
362 | } |
363 | ||
364 | const wxDataViewCtrl* wxDataViewRendererBase::GetView() const | |
365 | { | |
366 | return wx_const_cast(wxDataViewRendererBase*, this)->GetOwner()->GetOwner(); | |
6842a71a | 367 | } |
f554a14b | 368 | |
e0062c04 | 369 | bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect ) |
1e510b1e | 370 | { |
e0062c04 | 371 | m_item = item; // remember for later |
900af470 | 372 | |
1e510b1e RR |
373 | unsigned int col = GetOwner()->GetModelColumn(); |
374 | wxVariant value; | |
e0062c04 | 375 | GetOwner()->GetOwner()->GetModel()->GetValue( value, item, col ); |
900af470 | 376 | |
1e510b1e | 377 | m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value ); |
900af470 JS |
378 | |
379 | wxDataViewEditorCtrlEvtHandler *handler = | |
30715fa1 | 380 | new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this ); |
900af470 | 381 | |
30715fa1 | 382 | m_editorCtrl->PushEventHandler( handler ); |
900af470 | 383 | |
30715fa1 RR |
384 | #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL) |
385 | handler->SetFocusOnIdle(); | |
386 | #else | |
1e510b1e | 387 | m_editorCtrl->SetFocus(); |
30715fa1 RR |
388 | #endif |
389 | ||
afebb87b RR |
390 | // Now we should send Editing Started event |
391 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, GetOwner()->GetOwner()->GetId() ); | |
392 | event.SetDataViewColumn( GetOwner() ); | |
393 | event.SetModel( GetOwner()->GetOwner()->GetModel() ); | |
394 | event.SetItem( item ); | |
afebb87b RR |
395 | GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event ); |
396 | ||
1e510b1e RR |
397 | return true; |
398 | } | |
399 | ||
400 | void wxDataViewRendererBase::CancelEditing() | |
401 | { | |
2fa73716 | 402 | wxPendingDelete.Append( m_editorCtrl ); |
900af470 | 403 | |
1e510b1e | 404 | GetOwner()->GetOwner()->GetMainWindow()->SetFocus(); |
900af470 | 405 | |
2fa73716 | 406 | // m_editorCtrl->PopEventHandler( true ); |
1e510b1e RR |
407 | } |
408 | ||
409 | bool wxDataViewRendererBase::FinishEditing() | |
410 | { | |
1e510b1e RR |
411 | wxVariant value; |
412 | GetValueFromEditorCtrl( m_editorCtrl, value ); | |
413 | ||
2fa73716 | 414 | wxPendingDelete.Append( m_editorCtrl ); |
900af470 | 415 | |
1e510b1e | 416 | GetOwner()->GetOwner()->GetMainWindow()->SetFocus(); |
900af470 | 417 | |
1e510b1e RR |
418 | if (!Validate(value)) |
419 | return false; | |
900af470 | 420 | |
1e510b1e | 421 | unsigned int col = GetOwner()->GetModelColumn(); |
e0062c04 RR |
422 | GetOwner()->GetOwner()->GetModel()->SetValue( value, m_item, col ); |
423 | GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item, col ); | |
900af470 | 424 | |
2fa73716 | 425 | // m_editorCtrl->PopEventHandler( true ); |
afebb87b RR |
426 | |
427 | // Now we should send Editing Done event | |
428 | wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, GetOwner()->GetOwner()->GetId() ); | |
429 | event.SetDataViewColumn( GetOwner() ); | |
430 | event.SetModel( GetOwner()->GetOwner()->GetModel() ); | |
8fdaf7de | 431 | event.SetItem( m_item ); |
afebb87b | 432 | GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event ); |
900af470 | 433 | |
1e510b1e RR |
434 | return true; |
435 | } | |
436 | ||
437 | //----------------------------------------------------------------------------- | |
438 | // wxDataViewEditorCtrlEvtHandler | |
439 | //----------------------------------------------------------------------------- | |
440 | ||
441 | BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler) | |
442 | EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar) | |
443 | EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus) | |
30715fa1 | 444 | EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle) |
1e510b1e RR |
445 | END_EVENT_TABLE() |
446 | ||
447 | wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler( | |
448 | wxControl *editorCtrl, | |
449 | wxDataViewRenderer *owner ) | |
450 | { | |
451 | m_owner = owner; | |
452 | m_editorCtrl = editorCtrl; | |
453 | ||
454 | m_finished = false; | |
455 | } | |
456 | ||
30715fa1 RR |
457 | void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event ) |
458 | { | |
459 | if (m_focusOnIdle) | |
460 | { | |
461 | m_focusOnIdle = false; | |
462 | if (wxWindow::FindFocus() != m_editorCtrl) | |
463 | m_editorCtrl->SetFocus(); | |
464 | } | |
900af470 | 465 | |
30715fa1 RR |
466 | event.Skip(); |
467 | } | |
468 | ||
1e510b1e RR |
469 | void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event ) |
470 | { | |
471 | switch ( event.m_keyCode ) | |
472 | { | |
473 | case WXK_RETURN: | |
474 | m_finished = true; | |
475 | m_owner->FinishEditing(); | |
476 | break; | |
477 | ||
478 | case WXK_ESCAPE: | |
479 | m_finished = true; | |
480 | m_owner->CancelEditing(); | |
481 | break; | |
482 | ||
483 | default: | |
484 | event.Skip(); | |
485 | } | |
486 | } | |
487 | ||
488 | void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event ) | |
489 | { | |
490 | if (!m_finished) | |
491 | { | |
492 | m_finished = true; | |
493 | m_owner->FinishEditing(); | |
494 | } | |
495 | ||
1e510b1e RR |
496 | event.Skip(); |
497 | } | |
498 | ||
f554a14b | 499 | // --------------------------------------------------------- |
fa28826d | 500 | // wxDataViewColumnBase |
f554a14b | 501 | // --------------------------------------------------------- |
fa28826d RR |
502 | |
503 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject) | |
504 | ||
9861f022 | 505 | wxDataViewColumnBase::wxDataViewColumnBase(const wxString& WXUNUSED(title), |
baa9ebc4 | 506 | wxDataViewRenderer *renderer, |
0a71f9e9 | 507 | unsigned int model_column, |
008b5a66 | 508 | int WXUNUSED(width), |
87f0efe2 | 509 | wxAlignment WXUNUSED(align), |
900af470 | 510 | int WXUNUSED(flags)) |
fa28826d | 511 | { |
baa9ebc4 | 512 | m_renderer = renderer; |
6842a71a | 513 | m_model_column = model_column; |
6842a71a | 514 | m_owner = NULL; |
baa9ebc4 | 515 | m_renderer->SetOwner( (wxDataViewColumn*) this ); |
9861f022 RR |
516 | |
517 | // NOTE: the wxDataViewColumn's ctor must store the width, align, flags | |
518 | // parameters inside the native control! | |
6842a71a RR |
519 | } |
520 | ||
07a84e7b RR |
521 | wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap& bitmap, |
522 | wxDataViewRenderer *renderer, | |
523 | unsigned int model_column, | |
524 | int WXUNUSED(width), | |
87f0efe2 | 525 | wxAlignment WXUNUSED(align), |
900af470 | 526 | int WXUNUSED(flags) ) |
07a84e7b RR |
527 | { |
528 | m_renderer = renderer; | |
529 | m_model_column = model_column; | |
07a84e7b RR |
530 | m_bitmap = bitmap; |
531 | m_owner = NULL; | |
532 | m_renderer->SetOwner( (wxDataViewColumn*) this ); | |
533 | } | |
534 | ||
6842a71a RR |
535 | wxDataViewColumnBase::~wxDataViewColumnBase() |
536 | { | |
baa9ebc4 RR |
537 | if (m_renderer) |
538 | delete m_renderer; | |
fa28826d RR |
539 | } |
540 | ||
9861f022 | 541 | int wxDataViewColumnBase::GetFlags() const |
fa28826d | 542 | { |
9861f022 | 543 | int ret = 0; |
fa28826d | 544 | |
9861f022 RR |
545 | if (IsSortable()) |
546 | ret |= wxDATAVIEW_COL_SORTABLE; | |
547 | if (IsResizeable()) | |
548 | ret |= wxDATAVIEW_COL_RESIZABLE; | |
549 | if (IsHidden()) | |
550 | ret |= wxDATAVIEW_COL_HIDDEN; | |
fa28826d | 551 | |
9861f022 | 552 | return ret; |
07a84e7b RR |
553 | } |
554 | ||
9861f022 | 555 | void wxDataViewColumnBase::SetFlags(int flags) |
07a84e7b | 556 | { |
9861f022 RR |
557 | SetSortable((flags & wxDATAVIEW_COL_SORTABLE) != 0); |
558 | SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0); | |
559 | SetHidden((flags & wxDATAVIEW_COL_HIDDEN) != 0); | |
07a84e7b RR |
560 | } |
561 | ||
f554a14b | 562 | // --------------------------------------------------------- |
239eaa41 | 563 | // wxDataViewCtrlBase |
f554a14b | 564 | // --------------------------------------------------------- |
239eaa41 RR |
565 | |
566 | IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl) | |
567 | ||
568 | wxDataViewCtrlBase::wxDataViewCtrlBase() | |
569 | { | |
570 | m_model = NULL; | |
3b6280be RR |
571 | m_expander_column = 0; |
572 | m_indent = 8; | |
239eaa41 RR |
573 | } |
574 | ||
575 | wxDataViewCtrlBase::~wxDataViewCtrlBase() | |
576 | { | |
87f0efe2 RR |
577 | if (m_model) |
578 | { | |
579 | m_model->DecRef(); | |
580 | m_model = NULL; | |
581 | } | |
239eaa41 RR |
582 | } |
583 | ||
e0062c04 | 584 | bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model ) |
239eaa41 | 585 | { |
1821abd1 RR |
586 | if (m_model) |
587 | { | |
87f0efe2 | 588 | m_model->DecRef(); // discard old model, if any |
1821abd1 | 589 | } |
87f0efe2 RR |
590 | |
591 | // add our own reference to the new model: | |
239eaa41 | 592 | m_model = model; |
1821abd1 RR |
593 | if (m_model) |
594 | { | |
900af470 | 595 | m_model->IncRef(); |
1821abd1 | 596 | } |
f554a14b | 597 | |
239eaa41 RR |
598 | return true; |
599 | } | |
600 | ||
e0062c04 | 601 | wxDataViewModel* wxDataViewCtrlBase::GetModel() |
239eaa41 RR |
602 | { |
603 | return m_model; | |
604 | } | |
605 | ||
c7074d44 RR |
606 | wxDataViewColumn * |
607 | wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 608 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
fa28826d | 609 | { |
c7074d44 | 610 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 611 | new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), |
c7074d44 RR |
612 | model_column, width, align, flags ); |
613 | AppendColumn( ret ); | |
614 | return ret; | |
fa28826d RR |
615 | } |
616 | ||
c7074d44 RR |
617 | wxDataViewColumn * |
618 | wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 619 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
605c2c4a | 620 | { |
c7074d44 RR |
621 | |
622 | wxDataViewColumn *ret = new wxDataViewColumn( label, | |
900af470 | 623 | new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), |
c7074d44 RR |
624 | model_column, width, align, flags ); |
625 | AppendColumn( ret ); | |
626 | return ret; | |
605c2c4a RR |
627 | } |
628 | ||
c7074d44 RR |
629 | wxDataViewColumn * |
630 | wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 631 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
ad63bf41 | 632 | { |
c7074d44 | 633 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 634 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), |
c7074d44 RR |
635 | model_column, width, align, flags ); |
636 | AppendColumn( ret ); | |
637 | return ret; | |
ad63bf41 RR |
638 | } |
639 | ||
c7074d44 RR |
640 | wxDataViewColumn * |
641 | wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 642 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
4d496ecb | 643 | { |
c7074d44 | 644 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 645 | new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), |
c7074d44 RR |
646 | model_column, width, align, flags ); |
647 | AppendColumn( ret ); | |
648 | return ret; | |
4d496ecb RR |
649 | } |
650 | ||
c7074d44 RR |
651 | wxDataViewColumn * |
652 | wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column, | |
87f0efe2 | 653 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 654 | { |
c7074d44 | 655 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 656 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), |
c7074d44 RR |
657 | model_column, width, align, flags ); |
658 | AppendColumn( ret ); | |
659 | return ret; | |
07a84e7b RR |
660 | } |
661 | ||
c7074d44 RR |
662 | wxDataViewColumn * |
663 | wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 664 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 665 | { |
c7074d44 | 666 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 667 | new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), |
c7074d44 RR |
668 | model_column, width, align, flags ); |
669 | AppendColumn( ret ); | |
670 | return ret; | |
07a84e7b RR |
671 | } |
672 | ||
c7074d44 RR |
673 | wxDataViewColumn * |
674 | wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 675 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 676 | { |
c7074d44 | 677 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 678 | new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), |
c7074d44 RR |
679 | model_column, width, align, flags ); |
680 | AppendColumn( ret ); | |
681 | return ret; | |
07a84e7b RR |
682 | } |
683 | ||
c7074d44 RR |
684 | wxDataViewColumn * |
685 | wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 686 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 687 | { |
c7074d44 | 688 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 689 | new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), |
c7074d44 RR |
690 | model_column, width, align, flags ); |
691 | AppendColumn( ret ); | |
692 | return ret; | |
07a84e7b RR |
693 | } |
694 | ||
c7074d44 RR |
695 | wxDataViewColumn * |
696 | wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 697 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 698 | { |
c7074d44 | 699 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 700 | new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), |
c7074d44 RR |
701 | model_column, width, align, flags ); |
702 | AppendColumn( ret ); | |
703 | return ret; | |
07a84e7b RR |
704 | } |
705 | ||
c7074d44 RR |
706 | wxDataViewColumn * |
707 | wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column, | |
87f0efe2 | 708 | wxDataViewCellMode mode, int width, wxAlignment align, int flags ) |
07a84e7b | 709 | { |
c7074d44 | 710 | wxDataViewColumn *ret = new wxDataViewColumn( label, |
900af470 | 711 | new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), |
c7074d44 RR |
712 | model_column, width, align, flags ); |
713 | AppendColumn( ret ); | |
714 | return ret; | |
07a84e7b RR |
715 | } |
716 | ||
c7074d44 RR |
717 | bool |
718 | wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col ) | |
fa28826d | 719 | { |
6842a71a | 720 | col->SetOwner( (wxDataViewCtrl*) this ); |
fa28826d RR |
721 | return true; |
722 | } | |
723 | ||
eb7f97f8 RR |
724 | // --------------------------------------------------------- |
725 | // wxDataViewEvent | |
726 | // --------------------------------------------------------- | |
727 | ||
728 | IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent) | |
729 | ||
e0062c04 | 730 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED) |
e98351ec | 731 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_DESELECTED) |
e0062c04 | 732 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED) |
6977c3bf | 733 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING) |
3ecb8a53 | 734 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED) |
6977c3bf | 735 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING) |
3ecb8a53 | 736 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED) |
e0000f94 RR |
737 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED) |
738 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE) | |
739 | ||
31fb32e1 RR |
740 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK) |
741 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK) | |
c0a66d92 | 742 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED) |
eb7f97f8 | 743 | |
e0062c04 RR |
744 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED) |
745 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED) | |
746 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED) | |
1821abd1 | 747 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED) |
1821abd1 | 748 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED) |
eb7f97f8 | 749 | |
8045736e | 750 | #endif |
e0000f94 | 751 |