]> git.saurik.com Git - wxWidgets.git/blame - src/osx/dataview_osx.cpp
Create an autorelease pool to catch objects created during several special situations...
[wxWidgets.git] / src / osx / dataview_osx.cpp
CommitLineData
e86edab0
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/dataview_osx.cpp
3// Purpose: wxDataViewCtrl native mac implementation
4// Author:
5// Id: $Id: dataview_osx.cpp 58317 2009-01-27
6// Copyright: (c) 2009
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#if (wxUSE_DATAVIEWCTRL != 0) && (!defined(wxUSE_GENERICDATAVIEWCTRL) || (wxUSE_GENERICDATAVIEWCTRL == 0))
14
e86edab0
RR
15#include <limits>
16
17#ifndef WX_PRECOMP
18 #include "wx/timer.h"
19 #include "wx/settings.h"
20 #include "wx/dcclient.h"
21 #include "wx/icon.h"
22#endif
23
24#include "wx/osx/core/dataview.h"
25#include "wx/osx/private.h"
26#include "wx/renderer.h"
27
28// ============================================================================
29// Helper functions for dataviewe implementation on OSX
30// ============================================================================
31wxString ConcatenateDataViewItemValues(wxDataViewCtrl const* dataViewCtrlPtr, wxDataViewItem const& dataViewItem)
32{
33 wxString dataString; // contains the TAB concatenated data
34
35
36 for (size_t i=0; i<dataViewCtrlPtr->GetColumnCount(); i++)
37 {
38 // variable definition:
39 wxVariant dataValue;
608129e5 40
e86edab0
RR
41 dataViewCtrlPtr->GetModel()->GetValue(dataValue,dataViewItem,dataViewCtrlPtr->GetColumn(i)->GetModelColumn());
42 if (i > 0)
43 dataString << wxT('\t');
44 dataString << dataValue.MakeString();
45 }
46 return dataString;
47}
48
49// ============================================================================
50// wxOSXDataViewModelNotifier
51// ============================================================================
52class wxOSXDataViewModelNotifier : public wxDataViewModelNotifier
53{
54public:
55 //
56 // constructors / destructor
57 //
58 wxOSXDataViewModelNotifier(wxDataViewCtrl* initDataViewCtrlPtr);
59
60 //
61 // inherited methods from wxDataViewModelNotifier
62 //
63 virtual bool ItemAdded (wxDataViewItem const &parent, wxDataViewItem const &item);
64 virtual bool ItemsAdded (wxDataViewItem const& parent, wxDataViewItemArray const& items);
65 virtual bool ItemChanged (wxDataViewItem const& item);
66 virtual bool ItemsChanged(wxDataViewItemArray const& items);
67 virtual bool ItemDeleted (wxDataViewItem const& parent, wxDataViewItem const& item);
68 virtual bool ItemsDeleted(wxDataViewItem const& parent, wxDataViewItemArray const& items);
69 virtual bool ValueChanged(wxDataViewItem const& item, unsigned int col);
70 virtual bool Cleared();
71 virtual void Resort();
72
73protected:
74 // if the dataview control can have a variable row height this method sets the dataview's control row height of
75 // the passed item to the maximum value occupied by the item in all columns
76 void AdjustRowHeight(wxDataViewItem const& item);
77 // ... and the same method for a couple of items:
78 void AdjustRowHeights(wxDataViewItemArray const& items);
79
80private:
81 wxDataViewCtrl* m_DataViewCtrlPtr;
82};
83
84//
85// constructors / destructor
86//
87wxOSXDataViewModelNotifier::wxOSXDataViewModelNotifier(wxDataViewCtrl* initDataViewCtrlPtr)
88 :m_DataViewCtrlPtr(initDataViewCtrlPtr)
89{
90 if (initDataViewCtrlPtr == NULL)
91 wxFAIL_MSG(_("Pointer to dataview control must not be NULL"));
92}
93
94bool wxOSXDataViewModelNotifier::ItemAdded(wxDataViewItem const& parent, wxDataViewItem const& item)
95{
96 bool noFailureFlag;
97
98
99 wxCHECK_MSG(item.IsOk(),false,_("Added item is invalid."));
de40d736
VZ
100 noFailureFlag = m_DataViewCtrlPtr->GetDataViewPeer()->Add(parent,item);
101 AdjustRowHeight(item);
e86edab0
RR
102 return noFailureFlag;
103}
104
105bool wxOSXDataViewModelNotifier::ItemsAdded(wxDataViewItem const& parent, wxDataViewItemArray const& items)
106{
107 bool noFailureFlag;
108
109
110 // insert all valid items into control:
de40d736 111 noFailureFlag = m_DataViewCtrlPtr->GetDataViewPeer()->Add(parent,items);
e86edab0 112 // adjust row heights:
de40d736 113 AdjustRowHeights(items);
e86edab0
RR
114 // done:
115 return noFailureFlag;
116}
117
118bool wxOSXDataViewModelNotifier::ItemChanged(wxDataViewItem const& item)
119{
120 wxCHECK_MSG(item.IsOk(), false,_("Changed item is invalid."));
de40d736
VZ
121 wxCHECK_MSG(GetOwner() != NULL,false,_("Owner not initialized."));
122 if (m_DataViewCtrlPtr->GetDataViewPeer()->Update(GetOwner()->GetParent(item),item))
e86edab0
RR
123 {
124 // sent the equivalent wxWidget event:
de40d736 125 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId());
e86edab0 126
de40d736 127 dataViewEvent.SetEventObject(m_DataViewCtrlPtr);
e86edab0
RR
128 dataViewEvent.SetItem(item);
129 // sent the equivalent wxWidget event:
de40d736 130 m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
e86edab0 131 // row height may have to be adjusted:
de40d736 132 AdjustRowHeight(item);
e86edab0
RR
133 // done
134 return true;
135 }
136 else
137 return false;
138}
139
140bool wxOSXDataViewModelNotifier::ItemsChanged(wxDataViewItemArray const& items)
141{
142 size_t const noOfItems = items.GetCount();
143
de40d736 144 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId());
e86edab0
RR
145
146
de40d736 147 dataViewEvent.SetEventObject(m_DataViewCtrlPtr);
e86edab0 148 for (size_t indexItem=0; indexItem<noOfItems; ++indexItem)
de40d736 149 if (m_DataViewCtrlPtr->GetDataViewPeer()->Update(GetOwner()->GetParent(items[indexItem]),items[indexItem]))
e86edab0
RR
150 {
151 // send for all changed items a wxWidget event:
152 dataViewEvent.SetItem(items[indexItem]);
de40d736 153 m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
e86edab0
RR
154 }
155 else
156 return false;
157 // if this location is reached all items have been updated:
de40d736 158 AdjustRowHeights(items);
e86edab0
RR
159 // done:
160 return true;
161}
162
163bool wxOSXDataViewModelNotifier::ItemDeleted(wxDataViewItem const& parent, wxDataViewItem const& item)
164{
165 bool noFailureFlag;
166
167
168 wxCHECK_MSG(item.IsOk(),false,_("To be deleted item is invalid."));
169 // when this method is called and currently an item is being edited this item may have already been deleted in the model (the passed item and the being edited item have
170 // not to be identical because the being edited item might be below the passed item in the hierarchy);
171 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
172 // has been started and that variables can currently not be updated even when requested by the system:
de40d736
VZ
173 m_DataViewCtrlPtr->SetDeleting(true);
174 noFailureFlag = m_DataViewCtrlPtr->GetDataViewPeer()->Remove(parent,item);
e86edab0 175 // enable automatic updating again:
de40d736 176 m_DataViewCtrlPtr->SetDeleting(false);
e86edab0
RR
177 // done:
178 return noFailureFlag;
179}
180
181bool wxOSXDataViewModelNotifier::ItemsDeleted(wxDataViewItem const& parent, wxDataViewItemArray const& items)
182{
183 bool noFailureFlag;
184
185
186 // when this method is called and currently an item is being edited this item may have already been deleted in the model (the passed item and the being edited item have
187 // not to be identical because the being edited item might be below the passed item in the hierarchy);
188 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
189 // has been started and that variables can currently not be updated even when requested by the system:
de40d736 190 m_DataViewCtrlPtr->SetDeleting(true);
e86edab0 191 // delete all specified items:
de40d736 192 noFailureFlag = m_DataViewCtrlPtr->GetDataViewPeer()->Remove(parent,items);
e86edab0 193 // enable automatic updating again:
de40d736 194 m_DataViewCtrlPtr->SetDeleting(false);
e86edab0
RR
195 // done:
196 return noFailureFlag;
197}
198
199bool wxOSXDataViewModelNotifier::ValueChanged(wxDataViewItem const& item, unsigned int col)
200{
201 wxCHECK_MSG(item.IsOk(), false,_("Passed item is invalid."));
de40d736
VZ
202 wxCHECK_MSG(GetOwner() != NULL,false,_("Owner not initialized."));
203 if (m_DataViewCtrlPtr->GetDataViewPeer()->Update(GetOwner()->GetParent(item),item))
e86edab0 204 {
de40d736 205 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,m_DataViewCtrlPtr->GetId());
e86edab0 206
de40d736 207 dataViewEvent.SetEventObject(m_DataViewCtrlPtr);
e86edab0
RR
208 dataViewEvent.SetColumn(col);
209 dataViewEvent.SetItem(item);
210 // send the equivalent wxWidget event:
de40d736 211 m_DataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
e86edab0
RR
212 // done
213 return true;
214 }
215 else
216 return false;
217}
218
219bool wxOSXDataViewModelNotifier::Cleared()
220{
de40d736 221 return m_DataViewCtrlPtr->GetDataViewPeer()->Reload();
e86edab0
RR
222}
223
224void wxOSXDataViewModelNotifier::Resort()
225{
de40d736 226 m_DataViewCtrlPtr->GetDataViewPeer()->Resort();
e86edab0
RR
227}
228
229void wxOSXDataViewModelNotifier::AdjustRowHeight(wxDataViewItem const& item)
230{
de40d736 231 if ((m_DataViewCtrlPtr->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) != 0)
e86edab0 232 {
de40d736 233 wxDataViewModel *model = GetOwner();
e86edab0
RR
234
235 int height = 20; // TODO find out standard height
de40d736 236 unsigned int num = m_DataViewCtrlPtr->GetColumnCount();
e86edab0
RR
237 unsigned int col;
238 for (col = 0; col < num; col++)
239 {
de40d736 240 wxDataViewColumn* column(m_DataViewCtrlPtr->GetColumnPtr(col));
608129e5 241
e86edab0
RR
242 if (!(column->IsHidden()))
243 {
244 wxDataViewCustomRenderer *renderer = dynamic_cast<wxDataViewCustomRenderer*>(column->GetRenderer());
245 if (renderer)
246 {
247 wxVariant value;
248 model->GetValue( value, item, column->GetModelColumn() );
249 renderer->SetValue( value );
250 height = wxMax( height, renderer->GetSize().y );
251 }
252 }
253 }
254 if (height > 20)
de40d736 255 m_DataViewCtrlPtr->GetDataViewPeer()->SetRowHeight(item,height);
e86edab0
RR
256 }
257}
258
259void wxOSXDataViewModelNotifier::AdjustRowHeights(wxDataViewItemArray const& items)
260{
de40d736 261 if ((m_DataViewCtrlPtr->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) != 0)
e86edab0
RR
262 {
263 size_t const noOfItems = items.GetCount();
264
de40d736 265 wxDataViewModel *model = GetOwner();
e86edab0
RR
266
267 for (size_t itemIndex=0; itemIndex<noOfItems; ++itemIndex)
268 {
269 int height = 20; // TODO find out standard height
de40d736 270 unsigned int num = m_DataViewCtrlPtr->GetColumnCount();
e86edab0
RR
271 unsigned int col;
272
273 for (col = 0; col < num; col++)
274 {
de40d736 275 wxDataViewColumn* column(m_DataViewCtrlPtr->GetColumnPtr(col));
608129e5 276
e86edab0
RR
277 if (!(column->IsHidden()))
278 {
279 wxDataViewCustomRenderer *renderer = dynamic_cast<wxDataViewCustomRenderer*>(column->GetRenderer());
280 if (renderer)
281 {
282 wxVariant value;
283 model->GetValue( value, items[itemIndex], column->GetModelColumn() );
284 renderer->SetValue( value );
285 height = wxMax( height, renderer->GetSize().y );
286 }
287 }
288 }
289 if (height > 20)
de40d736 290 m_DataViewCtrlPtr->GetDataViewPeer()->SetRowHeight(items[itemIndex],height);
e86edab0
RR
291 }
292 }
293}
294
295// ---------------------------------------------------------
296// wxDataViewCustomRenderer
297// The constructor, the implementation macro and environment
298// dependent methods can be found in the environment's
299// source file.
300// ---------------------------------------------------------
de40d736 301wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
e86edab0 302{
de40d736 303 delete m_DCPtr;
e86edab0
RR
304}
305
306void wxDataViewCustomRenderer::RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state )
307{
308 wxDataViewCtrl *view = GetOwner()->GetOwner();
309
310 wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ? *wxWHITE : view->GetForegroundColour();
311 dc->SetTextForeground(col);
312 dc->DrawText( text, cell.x + xoffset, cell.y + ((cell.height - dc->GetCharHeight()) / 2));
313}
314
315wxDC* wxDataViewCustomRenderer::GetDC()
316{
de40d736
VZ
317 if ((m_DCPtr == NULL) && (GetOwner() != NULL) && (GetOwner()->GetOwner() != NULL))
318 m_DCPtr = new wxClientDC(GetOwner()->GetOwner());
319 return m_DCPtr;
e86edab0
RR
320}
321
322void wxDataViewCustomRenderer::SetDC(wxDC* newDCPtr)
323{
324 delete m_DCPtr;
325 m_DCPtr = newDCPtr;
326}
327
e86edab0
RR
328//-----------------------------------------------------------------------------
329// wxDataViewCtrl
330//-----------------------------------------------------------------------------
331
332wxDataViewCtrl::~wxDataViewCtrl()
333{
de40d736 334 ClearColumns();
e86edab0
RR
335}
336
337void wxDataViewCtrl::Init()
338{
339 m_CustomRendererPtr = NULL;
340 m_Deleting = false;
341 m_macIsUserPane = false;
342 m_cgContext = NULL;
343}
344
345bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
346{
de40d736 347 if (!(wxControl::Create(parent,id,pos,size,style & ~(wxHSCROLL | wxVSCROLL),validator)))
e86edab0 348 return false;
de40d736 349 m_peer = ::CreateDataView(this,parent,id,pos,size,style,GetExtraStyle());
e86edab0 350
de40d736 351 MacPostControlCreate(pos,size);
e86edab0
RR
352
353 return true;
354}
355
356bool wxDataViewCtrl::AssociateModel(wxDataViewModel* model)
357{
de40d736 358 wxDataViewWidgetImpl* dataViewWidgetPtr(GetDataViewPeer());
e86edab0
RR
359
360
361 wxCHECK_MSG(dataViewWidgetPtr != NULL,false,_("Pointer to native control must not be NULL."));
362 if (wxDataViewCtrlBase::AssociateModel(model) && dataViewWidgetPtr->AssociateModel(model))
363 {
364 if (model != NULL)
365 model->AddNotifier(new wxOSXDataViewModelNotifier(this));
366 return true;
367 }
368 else
369 return false;
370}
371
372bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* columnPtr)
373{
374 return wxDataViewCtrl::InsertColumn( GetColumnCount(), columnPtr );
375}
376
377bool wxDataViewCtrl::PrependColumn(wxDataViewColumn* columnPtr)
378{
379 return wxDataViewCtrl::InsertColumn( 0, columnPtr );
380}
381
382bool wxDataViewCtrl::InsertColumn(unsigned int pos, wxDataViewColumn* columnPtr)
383{
de40d736 384 wxDataViewWidgetImpl* dataViewWidgetPtr(GetDataViewPeer());
e86edab0
RR
385
386 // first, some error checking:
387 wxCHECK_MSG(dataViewWidgetPtr != NULL, false,_("Pointer to native control must not be NULL."));
388 wxCHECK_MSG(columnPtr != NULL, false,_("Column pointer must not be NULL."));
389 wxCHECK_MSG(columnPtr->GetRenderer() != NULL, false,_("Column does not have a renderer."));
de40d736 390 wxCHECK_MSG(GetModel() != NULL, false,_("No model associated with control."));
e86edab0 391 wxCHECK_MSG((columnPtr->GetModelColumn() >= 0) &&
de40d736 392 (columnPtr->GetModelColumn() < GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
e86edab0
RR
393
394 // add column to wxWidget's internal structure:
de40d736 395 if (wxDataViewCtrlBase::InsertColumn(pos,columnPtr))
e86edab0 396 {
de40d736 397 m_ColumnPtrs.Add(columnPtr);
e86edab0
RR
398 // if the insertion in the native control is successful the rest can also be initialized:
399 if (dataViewWidgetPtr->InsertColumn(pos,columnPtr))
400 {
401 // make sure that the data is up-to-date...
402 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
403 // otherwise ask the control to 'update' the data in the newly appended column:
de40d736
VZ
404 if (GetColumnCount() == 1)
405 SetExpanderColumn(columnPtr);
e86edab0
RR
406 // done:
407 return true;
408 }
409 else
410 {
411 // clean-up:
de40d736 412 m_ColumnPtrs.Remove(columnPtr);
e86edab0
RR
413 delete columnPtr;
414 // and send a message in debug mode:
415 wxFAIL_MSG(_("Column could not be added to native control."));
416 // failed:
417 return false;
418 }
419 }
420 else
421 {
422 // clean-up:
423 delete columnPtr;
424 wxFAIL_MSG(_("Could not add column to internal structures."));
425 // failed:
426 return false;
427 }
428}
429
430bool wxDataViewCtrl::ClearColumns()
431{
de40d736 432 if (GetDataViewPeer()->ClearColumns())
e86edab0 433 {
de40d736 434 WX_CLEAR_ARRAY(m_ColumnPtrs);
e86edab0
RR
435 return true;
436 }
437 else
438 return false;
439}
440
441bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn* columnPtr)
442{
de40d736 443 if (GetDataViewPeer()->DeleteColumn(columnPtr))
e86edab0 444 {
de40d736 445 m_ColumnPtrs.Remove(columnPtr);
e86edab0
RR
446 delete columnPtr;
447 return true;
448 }
449 else
450 return false;
451}
452
453wxDataViewColumn* wxDataViewCtrl::GetColumn(unsigned int pos) const
454{
de40d736 455 return GetDataViewPeer()->GetColumn(pos);
e86edab0
RR
456}
457
458unsigned int wxDataViewCtrl::GetColumnCount() const
459{
de40d736 460 return m_ColumnPtrs.GetCount();
e86edab0
RR
461}
462
463int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const* columnPtr) const
464{
de40d736 465 return GetDataViewPeer()->GetColumnPosition(columnPtr);
e86edab0
RR
466}
467
468void wxDataViewCtrl::Collapse(wxDataViewItem const& item)
469{
de40d736 470 GetDataViewPeer()->Collapse(item);
e86edab0
RR
471}
472
473void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr)
474{
475 if (item.IsOk())
476 {
de40d736
VZ
477 ExpandAncestors(item); // make sure that the item exists in the control
478 GetDataViewPeer()->EnsureVisible(item,columnPtr);
e86edab0
RR
479 }
480}
481
482void wxDataViewCtrl::Expand(wxDataViewItem const& item)
483{
de40d736 484 return GetDataViewPeer()->Expand(item);
e86edab0
RR
485}
486
487bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const
488{
de40d736 489 return (item.IsOk() && GetDataViewPeer()->IsExpanded(item));
e86edab0
RR
490}
491
492wxDataViewColumn* wxDataViewCtrl::GetSortingColumn() const
493{
de40d736 494 return GetDataViewPeer()->GetSortingColumn();
e86edab0
RR
495}
496
497unsigned int wxDataViewCtrl::GetCount() const
498{
de40d736 499 return GetDataViewPeer()->GetCount();
e86edab0
RR
500}
501
502wxRect wxDataViewCtrl::GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const
503{
504 if (item.IsOk() && (columnPtr != NULL))
de40d736 505 return GetDataViewPeer()->GetRectangle(item,columnPtr);
e86edab0
RR
506 else
507 return wxRect();
508}
509
510wxDataViewItem wxDataViewCtrl::GetSelection() const
511{
512 wxDataViewItemArray itemIDs;
513
514
de40d736 515 if (GetDataViewPeer()->GetSelections(itemIDs) > 0)
e86edab0
RR
516 return itemIDs[0];
517 else
518 return wxDataViewItem();
519}
520
521int wxDataViewCtrl::GetSelections(wxDataViewItemArray& sel) const
522{
de40d736 523 return GetDataViewPeer()->GetSelections(sel);
e86edab0
RR
524}
525
526void wxDataViewCtrl::HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const
527{
de40d736 528 return GetDataViewPeer()->HitTest(point,item,columnPtr);
e86edab0
RR
529}
530
531bool wxDataViewCtrl::IsSelected(wxDataViewItem const& item) const
532{
de40d736 533 return GetDataViewPeer()->IsSelected(item);
e86edab0
RR
534}
535
536void wxDataViewCtrl::Select(wxDataViewItem const& item)
537{
538 if (item.IsOk())
539 {
de40d736
VZ
540 ExpandAncestors(item); // make sure that the item exists in the control
541 GetDataViewPeer()->Select(item);
e86edab0
RR
542 }
543}
544
de40d736 545void wxDataViewCtrl::SelectAll()
e86edab0 546{
de40d736 547 GetDataViewPeer()->SelectAll();
e86edab0
RR
548}
549
550void wxDataViewCtrl::SetSelections(wxDataViewItemArray const& sel)
551{
552 size_t const noOfSelections = sel.GetCount();
553
554 size_t i;
555
556 wxDataViewItem last_parent;
557
558
559 // make sure that all to be selected items are visible in the control:
560 for (i = 0; i < noOfSelections; i++)
561 {
562 wxDataViewItem item = sel[i];
de40d736 563 wxDataViewItem parent = GetModel()->GetParent( item );
e86edab0
RR
564
565 if (parent.IsOk() && (parent != last_parent))
de40d736 566 ExpandAncestors(item);
e86edab0
RR
567 last_parent = parent;
568 }
569
570 // finally select the items:
de40d736 571 wxDataViewWidgetImpl* dataViewWidgetPtr(GetDataViewPeer()); // variable definition for abbreviational purposes
e86edab0
RR
572
573 for (i=0; i<noOfSelections; ++i)
574 dataViewWidgetPtr->Select(sel[i]);
575}
576
577void wxDataViewCtrl::Unselect(wxDataViewItem const& item)
578{
579 if (item.IsOk())
de40d736 580 GetDataViewPeer()->Unselect(item);
e86edab0
RR
581}
582
de40d736 583void wxDataViewCtrl::UnselectAll()
e86edab0 584{
de40d736 585 GetDataViewPeer()->UnselectAll();
e86edab0
RR
586}
587
588//
589// implementation
590//
de40d736 591wxDataViewWidgetImpl* wxDataViewCtrl::GetDataViewPeer() const
e86edab0 592{
de40d736 593 return dynamic_cast<wxDataViewWidgetImpl*>(GetPeer());
e86edab0
RR
594}
595
596void wxDataViewCtrl::AddChildren(wxDataViewItem const& parentItem)
597{
598 int noOfChildren;
599
600 wxDataViewItemArray items;
601
602
de40d736
VZ
603 wxCHECK_RET(GetModel() != NULL,_("Model pointer not initialized."));
604 noOfChildren = GetModel()->GetChildren(parentItem,items);
605 (void) GetModel()->ItemsAdded(parentItem,items);
e86edab0
RR
606}
607
de40d736 608void wxDataViewCtrl::FinishCustomItemEditing()
e86edab0 609{
de40d736 610 if (GetCustomRendererItem().IsOk())
e86edab0 611 {
de40d736
VZ
612 GetCustomRendererPtr()->FinishEditing();
613 SetCustomRendererItem(wxDataViewItem());
614 SetCustomRendererPtr (NULL);
e86edab0
RR
615 }
616}
617
618/*static*/
8f2a8de6
VZ
619wxVisualAttributes
620wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
e86edab0
RR
621{
622 wxVisualAttributes attr;
623
624 attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
625 attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX );
465eba14 626 attr.font.CreateSystemFont(wxOSX_SYSTEM_FONT_VIEWS);
e86edab0
RR
627
628 return attr;
629}
630
631// inherited methods from wxDataViewCtrlBase
632void wxDataViewCtrl::DoSetExpanderColumn()
633{
de40d736
VZ
634 if (GetExpanderColumn() != NULL)
635 GetDataViewPeer()->DoSetExpanderColumn(GetExpanderColumn());
e86edab0
RR
636}
637
638void wxDataViewCtrl::DoSetIndent()
639{
de40d736 640 GetDataViewPeer()->DoSetIndent(GetIndent());
e86edab0
RR
641}
642
643// event handling:
644void wxDataViewCtrl::OnSize(wxSizeEvent& event)
645{
de40d736 646 unsigned int const noOfColumns = GetColumnCount();
e86edab0
RR
647
648
649 // reset DC of all custom renderers because DC has changed:
650 for (unsigned int i=0; i<noOfColumns; ++i)
651 {
de40d736 652 wxDataViewColumn* dataViewColumnPtr(GetColumn(i));
e86edab0
RR
653
654 if (dataViewColumnPtr != NULL)
655 {
656 wxDataViewCustomRenderer* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer()));
657
658 if (dataViewCustomRendererPtr != NULL)
659 dataViewCustomRendererPtr->SetDC(NULL);
660 }
661 }
662
663 // update the layout of the native control after a size event:
de40d736 664 GetDataViewPeer()->OnSize();
e86edab0
RR
665
666 event.Skip();
667}
668
35d85392
RR
669wxSize wxDataViewCtrl::DoGetBestSize() const
670{
671 wxSize best = wxControl::DoGetBestSize();
672 best.y = 80;
608129e5 673
35d85392
RR
674 return best;
675}
676
677void wxDataViewCtrl::OnMouse(wxMouseEvent& event)
678{
679 event.Skip();
608129e5 680
35d85392
RR
681 if (GetModel() == NULL)
682 return;
683
684#if 0
685 // Doesn't compile anymore
686 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(m_peer));
687
688 int NoOfChildren;
689 wxDataViewItemArray items;
690 NoOfChildren = GetModel()->GetChildren( wxDataViewItem(), items);
691 if (NoOfChildren == 0)
692 return;
693 wxDataViewItem firstChild = items[0];
694
695 UInt16 headerHeight = 0;
696 MacDataViewListCtrlPtr->GetHeaderButtonHeight(&headerHeight);
608129e5
VZ
697
698
35d85392
RR
699 if (event.GetY() < headerHeight)
700 {
701 unsigned int col_count = GetColumnCount();
702 unsigned int col;
703 for (col = 0; col < col_count; col++)
704 {
705 wxDataViewColumn *column = GetColumn( col );
706 if (column->IsHidden())
707 continue;
608129e5 708
35d85392 709 Rect itemrect;
608129e5 710 ::GetDataBrowserItemPartBounds( MacDataViewListCtrlPtr->GetControlRef(),
35d85392
RR
711 reinterpret_cast<DataBrowserItemID>(firstChild.GetID()), column->GetPropertyID(),
712 kDataBrowserPropertyEnclosingPart, &itemrect );
608129e5 713
35d85392
RR
714 if (abs( event.GetX() - itemrect.right) < 3)
715 {
716 if (column->GetFlags() & wxDATAVIEW_COL_RESIZABLE)
717 SetCursor( wxCursor( wxCURSOR_SIZEWE ) );
718 else
719 SetCursor( *wxSTANDARD_CURSOR );
720 return;
721 }
722 }
608129e5 723
35d85392 724 }
608129e5 725
35d85392
RR
726 SetCursor( *wxSTANDARD_CURSOR );
727#endif
728}
729
e86edab0
RR
730IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl,wxDataViewCtrlBase)
731
732BEGIN_EVENT_TABLE(wxDataViewCtrl,wxDataViewCtrlBase)
733 EVT_SIZE(wxDataViewCtrl::OnSize)
35d85392 734 EVT_MOTION(wxDataViewCtrl::OnMouse)
e86edab0
RR
735END_EVENT_TABLE()
736
737#endif // (wxUSE_DATAVIEWCTRL != 0) && (!defined(wxUSE_GENERICDATAVIEWCTRL) || (wxUSE_GENERICDATAVIEWCTRL == 0))
738