1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/datavgen.cpp
3 // Purpose: wxDataViewCtrl native mac implementation
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_DATAVIEWCTRL
15 #include "wx/dataview.h"
17 #if !defined(wxUSE_GENERICDATAVIEWCTRL) || (wxUSE_GENERICDATAVIEWCTRL == 0)
21 #include "wx/mac/carbon/databrow.h"
28 #include "wx/renderer.h"
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 // a list of all catchable events:
35 static EventTypeSpec
const eventList
[] =
37 {kEventClassControl
, kEventControlDraw
},
38 {kEventClassControl
, kEventControlHit
}
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 static pascal OSStatus
wxMacDataViewCtrlEventHandler(EventHandlerCallRef handler
, EventRef EventReference
, void* Data
)
47 wxDataViewCtrl
* DataViewCtrlPtr((wxDataViewCtrl
*) Data
); // the 'Data' variable always contains a pointer to the data view control that installed the handler
49 wxMacCarbonEvent
CarbonEvent(EventReference
) ;
52 switch (GetEventKind(EventReference
))
54 case kEventControlDraw
:
58 DataViewCtrlPtr
->MacSetDrawingContext(CarbonEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
,typeCGContextRef
));
59 status
= ::CallNextEventHandler(handler
,EventReference
);
60 DataViewCtrlPtr
->MacSetDrawingContext(NULL
);
63 case kEventControlHit
:
64 if (CarbonEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
,typeControlPartCode
) == kControlButtonPart
) // we only care about the header
66 ControlRef controlReference
;
67 DataBrowserPropertyID columnPropertyID
;
68 unsigned long columnIndex
;
70 wxDataViewEvent
DataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
,DataViewCtrlPtr
->GetId());
72 CarbonEvent
.GetParameter(kEventParamDirectObject
,&controlReference
);
73 // determine the column that triggered the event (this is the column that is responsible for sorting the data view):
74 status
= ::GetDataBrowserSortProperty(controlReference
,&columnPropertyID
);
75 wxCHECK(status
== noErr
,status
);
76 status
= ::GetDataBrowserTableViewColumnPosition(controlReference
,columnPropertyID
,&columnIndex
);
77 if (status
== errDataBrowserPropertyNotFound
) // user clicked into part of the header that does not have a property
78 return ::CallNextEventHandler(handler
,EventReference
);
79 wxCHECK(status
== noErr
,status
);
80 // initialize wxWidget event handler:
81 DataViewEvent
.SetEventObject(DataViewCtrlPtr
);
82 DataViewEvent
.SetColumn(columnIndex
);
83 DataViewEvent
.SetDataViewColumn(DataViewCtrlPtr
->GetColumn(columnIndex
));
84 // finally sent the equivalent wxWidget event:
85 DataViewCtrlPtr
->GetEventHandler()->ProcessEvent(DataViewEvent
);
86 return ::CallNextEventHandler(handler
,EventReference
);
89 return eventNotHandledErr
;
92 return eventNotHandledErr
;
93 } /* wxMacDataViewCtrlEventHandler(EventHandlerCallRef, EventRef, void*) */
95 //-----------------------------------------------------------------------------
96 // local function pointers
97 //-----------------------------------------------------------------------------
99 DEFINE_ONE_SHOT_HANDLER_GETTER(wxMacDataViewCtrlEventHandler
)
101 // ---------------------------------------------------------
102 // wxMacDataViewModelNotifier
103 // ---------------------------------------------------------
105 class wxMacDataViewModelNotifier
: public wxDataViewModelNotifier
108 wxMacDataViewModelNotifier(wxMacDataViewDataBrowserListViewControl
* initDataViewControlPtr
) : m_dataViewControlPtr(initDataViewControlPtr
)
112 virtual bool ItemAdded(const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
114 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
117 wxCHECK_MSG(item
.IsOk(),false,_("Added item is invalid."));
118 return (!(parent
.IsOk()) && (this->m_dataViewControlPtr
->AddItem(kDataBrowserNoItem
,&itemID
) == noErr
) ||
119 parent
.IsOk() && (this->m_dataViewControlPtr
->AddItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
) == noErr
));
120 } /* ItemAdded(wxDataViewItem const&, wxDataViewItem const&) */
122 virtual bool ItemChanged(wxDataViewItem
const& item
)
124 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
127 wxCHECK_MSG(item
.IsOk(), false,_("Changed item is invalid."));
128 wxCHECK_MSG(this->GetOwner() != NULL
,false,_("Owner not initialized."));
129 if (this->m_dataViewControlPtr
->UpdateItems(&itemID
) == noErr
)
131 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
133 // sent the equivalent wxWidget event:
134 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED
,dataViewCtrlPtr
->GetId()); // variable defintion
136 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
137 dataViewEvent
.SetItem(item
);
138 // sent the equivalent wxWidget event:
139 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
145 } /* ItemChanged(wxDataViewItem const&) */
147 virtual bool ItemDeleted(wxDataViewItem
const& parent
, wxDataViewItem
const& item
)
151 // variable definition and initialization:
152 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
153 OSStatus errorStatus
;
154 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
156 // 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
157 // not to be identical because the being edited item might be below the passed item in the hierarchy); therefore, the control is informed that currently a deleting process
158 // is started and that variables can currently not be updated even when requested by the system:
159 dataViewCtrlPtr
->SetDeleting(true);
160 errorStatus
= this->m_dataViewControlPtr
->RemoveItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
);
161 dataViewCtrlPtr
->SetDeleting(false);
162 return (errorStatus
== noErr
);
166 } /* ItemDeleted(wxDataViewItem const&, wxDataViewItem const&) */
168 virtual bool ValueChanged(wxDataViewItem
const& item
, unsigned int col
)
170 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
171 DataBrowserItemID parentID
;
173 DataBrowserPropertyID propertyID
;
175 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
178 wxCHECK_MSG(item
.IsOk(), false,_("Passed item is invalid."));
179 wxCHECK_MSG(this->GetOwner() != NULL
,false,_("Owner not initialized."));
180 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Control is wrongly initialized."));
181 parentID
= reinterpret_cast<DataBrowserItemID
>(this->GetOwner()->GetParent(item
).GetID());
182 if ((this->m_dataViewControlPtr
->GetPropertyID(col
,&propertyID
) == noErr
) &&
183 (this->m_dataViewControlPtr
->UpdateItems(parentID
,1,&itemID
,dataViewCtrlPtr
->GetColumn(col
)->GetPropertyID(),propertyID
) == noErr
))
185 // variable definition and initialization:
186 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED
,dataViewCtrlPtr
->GetId());
188 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
189 dataViewEvent
.SetColumn(col
);
190 dataViewEvent
.SetItem(item
);
191 // send the equivalent wxWidget event:
192 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
198 } /* ValueChanged(wxDataViewItem const&, unsigned int) */
200 virtual bool Cleared(void)
202 if (this->m_dataViewControlPtr
->RemoveItems() == noErr
)
204 // variable definitions and initializations:
205 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
206 wxDataViewEvent
dataViewEvent (wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED
,dataViewCtrlPtr
->GetId());
208 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
209 // send the equivalent wxWidget event:
210 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
216 } /* Cleared(void) */
218 virtual void Resort(void)
220 this->m_dataViewControlPtr
->Resort();
228 wxMacDataViewDataBrowserListViewControl
* m_dataViewControlPtr
;
231 // ---------------------------------------------------------
232 // wxDataViewRenderer
233 // ---------------------------------------------------------
235 wxDataViewRenderer::wxDataViewRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
236 :wxDataViewRendererBase(varianttype
,mode
,align
), m_alignment(align
), m_mode(mode
)
238 } /* wxDataViewRenderer::wxDataViewRenderer(wxString const&, wxDataViewCellMode) */
240 void wxDataViewRenderer::SetMode(wxDataViewCellMode mode
)
242 wxDataViewColumn
* dataViewColumnPtr
;
246 dataViewColumnPtr
= this->GetOwner();
247 if (dataViewColumnPtr
!= NULL
)
249 // variable definition and initialization:
250 wxDataViewCtrl
* dataViewCtrlPtr(dataViewColumnPtr
->GetOwner());
252 if (dataViewCtrlPtr
!= NULL
)
254 // variable definition and initialization:
255 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
257 if (macDataViewListCtrlPtr
!= NULL
)
259 // variable definition and initialization:
260 DataBrowserPropertyFlags flags
;
262 verify_noerr(macDataViewListCtrlPtr
->GetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),&flags
));
263 if (mode
== wxDATAVIEW_CELL_EDITABLE
)
264 flags
|= kDataBrowserPropertyIsEditable
;
266 flags
&= ~kDataBrowserPropertyIsEditable
;
267 verify_noerr(macDataViewListCtrlPtr
->SetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),flags
));
271 } /* wxDataViewRenderer::SetMode(wxDataViewCellMode) */
273 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
,wxDataViewRendererBase
)
275 // ---------------------------------------------------------
276 // wxDataViewCustomRenderer
277 // ---------------------------------------------------------
279 wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
280 :wxDataViewRenderer(varianttype
,mode
,align
), m_editorCtrlPtr(NULL
), m_DCPtr(NULL
)
282 } /* wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const&, wxDataViewCellMode) */
284 wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void)
286 if (this->m_DCPtr
!= NULL
)
287 delete this->m_DCPtr
;
288 } /* wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) */
290 wxDC
* wxDataViewCustomRenderer::GetDC(void)
292 if (this->m_DCPtr
== NULL
)
294 if ((GetOwner() == NULL
) || (GetOwner()->GetOwner() == NULL
))
296 this->m_DCPtr
= new wxClientDC(this->GetOwner()->GetOwner());
298 return this->m_DCPtr
;
299 } /* wxDataViewCustomRenderer::GetDC(void) */
301 bool wxDataViewCustomRenderer::Render(void)
304 } /* wxDataViewCustomRenderer::Render(void) */
306 void wxDataViewCustomRenderer::SetDC(wxDC
* newDCPtr
)
308 delete this->m_DCPtr
;
309 this->m_DCPtr
= newDCPtr
;
310 } /* wxDataViewCustomRenderer::SetDC(wxDC*) */
313 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
315 // ---------------------------------------------------------
316 // wxDataViewTextRenderer
317 // ---------------------------------------------------------
319 wxDataViewTextRenderer::wxDataViewTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
320 :wxDataViewRenderer(varianttype
,mode
,align
)
322 } /* wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const&, wxDataViewCellMode, int) */
324 bool wxDataViewTextRenderer::Render(void)
326 if (this->GetValue().GetType() == this->GetVariantType())
328 // variable definition:
329 wxMacCFStringHolder
cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
331 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
);
335 } /* wxDataViewTextRenderer::Render(void) */
337 IMPLEMENT_CLASS(wxDataViewTextRenderer
,wxDataViewRenderer
)
339 // ---------------------------------------------------------
340 // wxDataViewBitmapRenderer
341 // ---------------------------------------------------------
343 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
344 :wxDataViewRenderer(varianttype
,mode
,align
)
348 bool wxDataViewBitmapRenderer::Render(void)
350 if (this->GetValue().GetType() == this->GetVariantType())
354 bitmap
<< this->GetValue();
356 return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap
.GetBitmapData()->GetIconRef()) == noErr
);
362 } /* wxDataViewBitmapRenderer::Render(void) */
364 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
,wxDataViewRenderer
)
366 // ---------------------------------------------------------
367 // wxDataViewIconTextRenderer
368 // ---------------------------------------------------------
370 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
371 :wxDataViewRenderer(varianttype
,mode
)
375 bool wxDataViewIconTextRenderer::Render(void)
377 wxLogMessage(wxString(_("Types: ")) << this->GetValue().GetType() << wxT(' ') << this->GetVariantType());
378 if (this->GetValue().GetType() == this->GetVariantType())
380 // variable definition:
381 wxDataViewIconText iconText
;
383 iconText
<< this->GetValue();
385 // variable definition:
386 wxMacCFStringHolder
cfString(iconText
.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
388 return ((::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText
.GetIcon().GetHICON())) == noErr
) &&
389 (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
));
393 } /* wxDataViewIconTextRenderer::Render(void) */
395 IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer
,wxDataViewRenderer
)
398 // ---------------------------------------------------------
399 // wxDataViewToggleRenderer
400 // ---------------------------------------------------------
402 wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
403 :wxDataViewRenderer(varianttype
,mode
)
407 bool wxDataViewToggleRenderer::Render(void)
409 if (this->GetValue().GetType() == this->GetVariantType())
410 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr
);
413 } /* wxDataViewToggleRenderer::Render(void) */
415 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
,wxDataViewRenderer
)
417 // ---------------------------------------------------------
418 // wxDataViewProgressRenderer
419 // ---------------------------------------------------------
421 wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString
const& label
, wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
422 :wxDataViewRenderer(varianttype
,mode
,align
)
426 bool wxDataViewProgressRenderer::Render(void)
428 if (this->GetValue().GetType() == this->GetVariantType())
429 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr
) &&
430 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr
) &&
431 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr
));
434 } /* wxDataViewProgressRenderer::Render(void) */
436 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
,wxDataViewRenderer
)
438 // ---------------------------------------------------------
439 // wxDataViewDateRenderer
440 // ---------------------------------------------------------
442 wxDataViewDateRenderer::wxDataViewDateRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
443 :wxDataViewRenderer(varianttype
,mode
,align
)
447 bool wxDataViewDateRenderer::Render(void)
449 if (this->GetValue().GetType() == this->GetVariantType())
450 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan
,1904)).GetSeconds().GetLo()) == noErr
);
453 } /* wxDataViewDateRenderer::Render(void) */
455 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
,wxDataViewRenderer
)
457 // ---------------------------------------------------------
459 // ---------------------------------------------------------
461 wxDataViewColumn::wxDataViewColumn(wxString
const &title
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
462 :wxDataViewColumnBase(title
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
463 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
| wxDATAVIEW_COL_RESIZABLE
)), m_maxWidth(std::numeric_limits
<int>::max()), m_minWidth(0), m_width(width
),
464 m_alignment(align
), m_title(title
)
466 } /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
468 wxDataViewColumn::wxDataViewColumn(wxBitmap
const& bitmap
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
469 :wxDataViewColumnBase(bitmap
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
470 m_flags(flags
& (wxDATAVIEW_COL_HIDDEN
| wxDATAVIEW_COL_RESIZABLE
)), m_maxWidth(std::numeric_limits
<int>::max()), m_minWidth(0), m_width(width
),
473 } /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
475 void wxDataViewColumn::SetAlignment(wxAlignment align
)
477 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
480 this->m_alignment
= align
;
481 if (dataViewCtrlPtr
!= NULL
)
483 // variable definition and initialization:
484 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
486 if (macDataViewListCtrlPtr
!= NULL
)
488 // variable definition and initialization:
489 DataBrowserListViewHeaderDesc headerDescription
;
491 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
495 case wxALIGN_CENTER_HORIZONTAL
:
496 headerDescription
.btnFontStyle
.just
= teCenter
;
499 headerDescription
.btnFontStyle
.just
= teFlushLeft
;
502 headerDescription
.btnFontStyle
.just
= teFlushRight
;
505 headerDescription
.btnFontStyle
.just
= teFlushDefault
;
507 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set alignment."));
510 } /* wxDataViewColumn::SetAlignment(wxAlignment) */
512 void wxDataViewColumn::SetBitmap(wxBitmap
const& bitmap
)
514 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
517 wxDataViewColumnBase::SetBitmap(bitmap
);
518 if (dataViewCtrlPtr
!= NULL
)
520 // variable definition and initialization:
521 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
523 if (macDataViewListCtrlPtr
!= NULL
)
525 // variable definition and initialization:
526 DataBrowserListViewHeaderDesc headerDescription
;
528 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
529 if (this->GetBitmap().Ok())
530 headerDescription
.btnContentInfo
.u
.iconRef
= this->GetBitmap().GetBitmapData()->GetIconRef();
532 headerDescription
.btnContentInfo
.u
.iconRef
= NULL
;
533 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set icon."));
536 } /* wxDataViewColumn::SetBitmap(wxBitmap const&) */
538 void wxDataViewColumn::SetFlags(int flags
)
540 this->SetHidden ((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
541 this->SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
542 this->SetSortable ((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
543 } /* wxDataViewColumn::SetFlags(int) */
545 void wxDataViewColumn::SetMaxWidth(int maxWidth
)
547 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
550 this->m_maxWidth
= maxWidth
;
551 if (dataViewCtrlPtr
!= NULL
)
553 // variable definition and initialization:
554 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
556 if (macDataViewListCtrlPtr
!= NULL
)
558 // variable definition and initialization:
559 DataBrowserListViewHeaderDesc headerDescription
;
561 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
562 headerDescription
.maximumWidth
= static_cast<UInt16
>(maxWidth
);
563 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set maximum width."));
566 } /* wxDataViewColumn::SetMaxWidth(int) */
568 void wxDataViewColumn::SetMinWidth(int minWidth
)
570 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
573 this->m_minWidth
= minWidth
;
574 if (dataViewCtrlPtr
!= NULL
)
576 // variable definition and initialization:
577 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
579 if (macDataViewListCtrlPtr
!= NULL
)
581 // variable definition and initialization:
582 DataBrowserListViewHeaderDesc headerDescription
;
584 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
585 headerDescription
.minimumWidth
= static_cast<UInt16
>(minWidth
);
586 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set minimum width."));
589 } /* wxDataViewColumn::SetMaxWidth(int) */
591 void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable
))
593 } /* wxDataViewColumn::SetResizeable(bool) */
595 void wxDataViewColumn::SetSortable(bool sortable
)
597 // variable definition and initialization:
598 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
600 if (dataViewCtrlPtr
!= NULL
)
602 // variable definition and initialization:
603 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
605 if (macDataViewListCtrlPtr
!= NULL
)
607 // variable definition and initialization:
608 DataBrowserPropertyFlags flags
;
610 wxCHECK_RET(macDataViewListCtrlPtr
->GetPropertyFlags(this->GetPropertyID(),&flags
) == noErr
,_("Could not get property flags."));
613 this->m_flags
|= wxDATAVIEW_COL_SORTABLE
;
614 flags
|= kDataBrowserListViewSortableColumn
;
618 this->m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
619 flags
&= ~kDataBrowserPropertyIsEditable
;
621 wxCHECK_RET(macDataViewListCtrlPtr
->SetPropertyFlags(this->GetPropertyID(),flags
) == noErr
,_("Could not set property flags."));
624 } /* wxDataViewColumn::SetSortable(bool) */
626 void wxDataViewColumn::SetSortOrder(bool ascending
)
628 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
631 this->m_ascending
= ascending
;
632 if (dataViewCtrlPtr
!= NULL
)
634 // variable definition and initialization:
635 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
637 if (macDataViewListCtrlPtr
!= NULL
)
639 // variable definition and initialization:
640 DataBrowserListViewHeaderDesc headerDescription
;
642 verify_noerr(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
));
644 headerDescription
.initialOrder
= kDataBrowserOrderIncreasing
;
646 headerDescription
.initialOrder
= kDataBrowserOrderDecreasing
;
647 verify_noerr(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
));
650 } /* wxDataViewColumn::SetSortOrder(bool) */
652 void wxDataViewColumn::SetTitle(wxString
const& title
)
654 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
657 this->m_title
= title
;
658 if (dataViewCtrlPtr
!= NULL
)
660 // variable definition and initialization:
661 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
663 if (macDataViewListCtrlPtr
!= NULL
)
665 // variable definition and initialization:
666 DataBrowserListViewHeaderDesc headerDescription
;
667 wxMacCFStringHolder
cfTitle(title
,(dataViewCtrlPtr
->GetFont().Ok() ? dataViewCtrlPtr
->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
669 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
670 headerDescription
.titleString
= cfTitle
;
671 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set header description."));
674 } /* wxDataViewColumn::SetTitle(wxString const&) */
676 void wxDataViewColumn::SetWidth(int width
)
678 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
681 if ((width
>= this->m_minWidth
) && (width
<= this->m_maxWidth
))
683 this->m_width
= width
;
684 if (dataViewCtrlPtr
!= NULL
)
686 // variable definition and initialization:
687 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
689 if (macDataViewListCtrlPtr
!= NULL
)
690 wxCHECK_RET(macDataViewListCtrlPtr
->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16
>(width
)) == noErr
,_("Could not set column width."));
693 } /* wxDataViewColumn::SetWidth(int) */
695 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
,wxDataViewColumnBase
)
697 //-----------------------------------------------------------------------------
699 //-----------------------------------------------------------------------------
701 void wxDataViewCtrl::Init(void)
703 this->m_Deleting
= false;
704 this->m_macIsUserPane
= false;
705 this->m_cgContext
= NULL
;
706 } /* wxDataViewCtrl::Init(void) */
708 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
710 if (!(this->wxControl::Create(parent
,id
,pos
,size
,(style
| wxSUNKEN_BORDER
) & ~(wxHSCROLL
| wxVSCROLL
),validator
)))
714 MacSetClipChildren(true) ;
717 this->m_peer
= new wxMacDataViewDataBrowserListViewControl(this,pos
,size
,style
);
718 this->MacPostControlCreate(pos
,size
);
719 ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(this->m_peer
->GetControlRef()),true);
721 InstallControlEventHandler(this->m_peer
->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList
),eventList
,this,NULL
);
724 } /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
726 bool wxDataViewCtrl::AssociateModel(wxDataViewModel
* model
)
728 if (!wxDataViewCtrlBase::AssociateModel(model
))
731 model
->AddNotifier(new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl
*>(this->m_peer
)));
734 } /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
736 bool wxDataViewCtrl::AppendColumn(wxDataViewColumn
* dataViewColumnPtr
)
738 DataBrowserPropertyID NewPropertyID
;
740 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
743 // first, some error checking:
744 wxCHECK_MSG(MacDataViewListCtrlPtr
!= NULL
, false,_("m_peer is not or incorrectly initialized"));
745 wxCHECK_MSG(dataViewColumnPtr
!= NULL
, false,_("Column pointer must not be NULL."));
746 wxCHECK_MSG(dataViewColumnPtr
->GetRenderer() != NULL
, false,_("Column does not have a renderer."));
747 wxCHECK_MSG(this->GetModel() != NULL
, false,_("No model associated with control."));
748 wxCHECK_MSG((dataViewColumnPtr
->GetModelColumn() >= 0) &&
749 (dataViewColumnPtr
->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
750 if ((MacDataViewListCtrlPtr
->GetFreePropertyID(&NewPropertyID
) == noErr
) && this->wxDataViewCtrlBase::AppendColumn(dataViewColumnPtr
))
752 // insert column into hash map:
753 this->m_ColumnPointers
.insert(ColumnPointerHashMapType::value_type(NewPropertyID
,dataViewColumnPtr
));
755 // variable definitions:
756 DataBrowserListViewColumnDesc columnDescription
;
757 wxMacCFStringHolder
cfTitle(dataViewColumnPtr
->GetTitle(),(this->m_font
.Ok() ? this->m_font
.GetEncoding() : wxLocale::GetSystemEncoding()));
759 // initialize column description:
760 dataViewColumnPtr
->SetPropertyID(NewPropertyID
);
761 if (dataViewColumnPtr
->GetWidth() <= 0)
762 dataViewColumnPtr
->SetWidth(wxDVC_DEFAULT_WIDTH
);
763 columnDescription
.propertyDesc
.propertyID
= NewPropertyID
;
764 columnDescription
.propertyDesc
.propertyType
= dataViewColumnPtr
->GetRenderer()->GetPropertyType();
765 columnDescription
.propertyDesc
.propertyFlags
= kDataBrowserListViewSelectionColumn
; // make the column selectable
766 if (dataViewColumnPtr
->IsSortable())
767 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewSortableColumn
;
769 if (dataViewColumnPtr
->IsMovable())
770 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewMovableColumn
;
772 if (dataViewColumnPtr
->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE
)
773 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserPropertyIsEditable
;
774 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
775 if ((columnDescription
.propertyDesc
.propertyType
== kDataBrowserTextType
) ||
776 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserIconAndTextType
) ||
777 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserDateTimeType
))
778 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
780 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
781 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
783 columnDescription
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
784 if (dataViewColumnPtr
->IsResizeable())
786 columnDescription
.headerBtnDesc
.minimumWidth
= 0;
787 columnDescription
.headerBtnDesc
.maximumWidth
= 30000;
791 columnDescription
.headerBtnDesc
.minimumWidth
= dataViewColumnPtr
->GetWidth();
792 columnDescription
.headerBtnDesc
.maximumWidth
= dataViewColumnPtr
->GetWidth();
794 columnDescription
.headerBtnDesc
.titleOffset
= 0;
795 columnDescription
.headerBtnDesc
.titleString
= cfTitle
; // we cannot directly use the wxMacCFStringHolder constructor call because then the CFStringRef is released
796 // having called 'AddColumn' where the title (CFStringRef) is going to be used
797 columnDescription
.headerBtnDesc
.initialOrder
= kDataBrowserOrderIncreasing
;
798 columnDescription
.headerBtnDesc
.btnFontStyle
.flags
= kControlUseFontMask
| kControlUseJustMask
;
799 switch (dataViewColumnPtr
->GetAlignment())
802 case wxALIGN_CENTER_HORIZONTAL
:
803 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teCenter
;
806 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushLeft
;
809 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushRight
;
812 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
814 columnDescription
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
815 columnDescription
.headerBtnDesc
.btnFontStyle
.style
= normal
;
816 columnDescription
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
817 if (dataViewColumnPtr
->GetBitmap().Ok())
818 columnDescription
.headerBtnDesc
.btnContentInfo
.u
.iconRef
= dataViewColumnPtr
->GetBitmap().GetBitmapData()->GetIconRef();
820 wxCHECK_MSG(MacDataViewListCtrlPtr
->AddColumn(&columnDescription
,kDataBrowserListViewAppendColumn
) == noErr
,false,_("Column could not be added."));
822 // final adjustments for the layout:
823 wxCHECK_MSG(MacDataViewListCtrlPtr
->SetColumnWidth(NewPropertyID
,dataViewColumnPtr
->GetWidth()) == noErr
,false,_("Column width could not be set."));
824 if (dataViewColumnPtr
== this->GetExpanderColumn()) // if the current column is marked expandable this column will become the active expandable column
825 MacDataViewListCtrlPtr
->SetDisclosureColumn(NewPropertyID
,true);
827 // make sure that the data is up-to-date...
828 // if the newly appended column is the first column add the initial data to the control otherwise ask the control to 'update' the data in the newly appended column:
829 if (this->GetColumnCount() == 1)
830 this->AddChildrenLevel(wxDataViewItem());
832 MacDataViewListCtrlPtr
->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,NewPropertyID
);
838 } /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
840 bool wxDataViewCtrl::ClearColumns(void)
842 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
845 while (this->m_ColumnPointers
.begin() != this->m_ColumnPointers
.end())
847 wxCHECK_MSG(MacDataViewListCtrlPtr
->RemoveColumnByProperty(this->m_ColumnPointers
.begin()->first
) == noErr
,false,_("Could not remove column."));
848 delete this->m_ColumnPointers
.begin()->second
;
849 this->m_ColumnPointers
.erase(this->m_ColumnPointers
.begin());
852 } /* wxDataViewCtrl::ClearColumns(void) */
854 bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn
* columnPtr
)
856 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
859 if ((MacDataViewListCtrlPtr
->RemoveColumnByProperty(columnPtr
->GetPropertyID()) == noErr
) && (this->m_ColumnPointers
.erase(columnPtr
->GetPropertyID()) > 0))
866 } /* wxDataViewCtrl::DeleteColumn(wxDataViewColumn*) */
868 wxDataViewColumn
* wxDataViewCtrl::GetColumn(unsigned int pos
) const
870 DataBrowserPropertyID propertyID
;
872 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
875 if (MacDataViewListCtrlPtr
->GetPropertyID(pos
,&propertyID
) == noErr
)
877 // variable definition:
878 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
880 if (Result
!= this->m_ColumnPointers
.end())
881 return Result
->second
;
887 } /* wxDataViewCtrl::GetColumn(unsigned int pos) const */
889 unsigned int wxDataViewCtrl::GetColumnCount(void) const
891 return this->m_ColumnPointers
.size();
892 } /* wxDataViewCtrl::GetColumnCount(void) const */
894 void wxDataViewCtrl::Collapse(wxDataViewItem
const& item
)
896 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
899 MacDataViewListCtrlPtr
->CloseContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
900 } /* wxDataViewCtrl::Collapse(wxDataViewItem const&) */
902 void wxDataViewCtrl::EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
)
906 // variable definition and initialization:
907 DataBrowserPropertyID propertyID
;
908 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
910 if (columnPtr
!= NULL
)
911 propertyID
= columnPtr
->GetPropertyID();
913 propertyID
= kDataBrowserNoItem
;
914 MacDataViewListCtrlPtr
->RevealItem(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),propertyID
,kDataBrowserRevealOnly
);
916 } /* wxDataViewCtrl::EnsureVisible(wxDataViewItem const&, wxDataViewColumn const*) */
918 void wxDataViewCtrl::Expand(wxDataViewItem
const& item
)
920 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
923 MacDataViewListCtrlPtr
->OpenContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
924 } /* wxDataViewCtrl::Expand(wxDataViewItem const&) */
926 wxRect
wxDataViewCtrl::GetItemRect(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
) const
928 if (item
.IsOk() && (columnPtr
!= NULL
))
930 // variable definition:
932 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
934 if (MacDataViewListCtrlPtr
->GetPartBounds(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),columnPtr
->GetPropertyID(),kDataBrowserPropertyContentPart
,&MacRectangle
) == noErr
)
936 // variable definition:
939 ::wxMacNativeToRect(&MacRectangle
,&rectangle
);
947 } /* wxDataViewCtrl::GetItemRect(wxDataViewItem const&, unsigned int) const */
949 wxDataViewItem
wxDataViewCtrl::GetSelection(void) const
951 wxArrayDataBrowserItemID itemIDs
;
953 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
956 if (MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
) > 0)
957 return wxDataViewItem(reinterpret_cast<void*>(itemIDs
[0]));
959 return wxDataViewItem();
960 } /* wxDataViewCtrl::GetSelection(void) const */
962 int wxDataViewCtrl::GetSelections(wxDataViewItemArray
& sel
) const
964 size_t NoOfSelectedItems
;
966 wxArrayDataBrowserItemID itemIDs
;
968 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
971 NoOfSelectedItems
= MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
);
973 sel
.SetCount(NoOfSelectedItems
);
974 for (size_t i
=0; i
<NoOfSelectedItems
; ++i
)
975 sel
[i
] = wxDataViewItem(reinterpret_cast<void*>(itemIDs
[i
]));
976 return static_cast<int>(NoOfSelectedItems
);
977 } /* wxDataViewCtrl::GetSelections(wxDataViewItemArray&) const */
979 void wxDataViewCtrl::HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const
981 item
= wxDataViewItem();
983 } /* wxDataViewCtrl::HitTest(wxPoint const&, wxDataViewItem&, wxDataViewColumn*&) const */
985 bool wxDataViewCtrl::IsSelected(wxDataViewItem
const& item
) const
987 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
990 return MacDataViewListCtrlPtr
->IsItemSelected(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
991 } /* wxDataViewCtrl::IsSelected(wxDataViewItem const&) const */
993 void wxDataViewCtrl::SelectAll(void)
995 DataBrowserItemID
* itemIDPtr
;
997 Handle
handle(::NewHandle(0));
1001 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1004 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1005 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1007 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1008 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsAssign
);
1010 DisposeHandle(handle
);
1011 } /* wxDataViewCtrl::SelectAll(void) */
1013 void wxDataViewCtrl::Select(wxDataViewItem
const& item
)
1017 // variable definition and initialization:
1018 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1019 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1021 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsAdd
);
1023 } /* wxDataViewCtrl::Select(wxDataViewItem const&) */
1025 void wxDataViewCtrl::SetSelections(wxDataViewItemArray
const& sel
)
1027 size_t const NoOfSelections
= sel
.GetCount();
1029 DataBrowserItemID
* itemIDs
;
1031 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1034 itemIDs
= new DataBrowserItemID
[NoOfSelections
];
1035 for (size_t i
=0; i
<NoOfSelections
; ++i
)
1036 itemIDs
[i
] = reinterpret_cast<DataBrowserItemID
>(sel
[i
].GetID());
1037 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfSelections
,itemIDs
,kDataBrowserItemsAssign
);
1039 } /* wxDataViewCtrl::SetSelections(wxDataViewItemArray const&) */
1041 void wxDataViewCtrl::Unselect(wxDataViewItem
const& item
)
1045 // variable definition and initialization:
1046 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1047 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1049 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsRemove
);
1051 } /* wxDataViewCtrl::Unselect(wxDataViewItem const&) */
1053 void wxDataViewCtrl::UnselectAll(void)
1055 DataBrowserItemID
* itemIDPtr
;
1057 Handle
handle(::NewHandle(0));
1061 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1064 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1065 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1067 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1068 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsRemove
);
1070 DisposeHandle(handle
);
1071 } /* wxDataViewCtrl::UnselectAll(void) */
1074 void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem
const& parentItem
)
1076 wxDataViewItem item
;
1079 wxCHECK_RET(this->GetModel() != NULL
,_("Model pointer not initialized."));
1080 item
= this->GetModel()->GetFirstChild(parentItem
);
1083 (void) this->GetModel()->ItemAdded(parentItem
,item
);
1084 item
= this->GetModel()->GetNextSibling(item
);
1086 } /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
1088 wxDataViewColumn
* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID propertyID
) const
1090 // variable definition:
1091 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
1093 if (Result
!= this->m_ColumnPointers
.end())
1094 return Result
->second
;
1097 } /* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID) const */
1099 // inherited methods from wxDataViewCtrlBase
1100 void wxDataViewCtrl::DoSetExpanderColumn(void)
1102 if (this->GetExpanderColumn() != NULL
)
1104 // variable definition and initialization:
1105 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1107 (void) MacDataViewListCtrlPtr
->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID());
1109 } /* wxDataViewCtrl::DoSetExpanderColumn(void) */
1111 void wxDataViewCtrl::DoSetIndent(void)
1113 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1116 (void) MacDataViewListCtrlPtr
->SetIndent(static_cast<float>(this->GetIndent()));
1117 } /* wxDataViewCtrl::DoSetIndent(void) */
1120 void wxDataViewCtrl::OnSize(wxSizeEvent
& event
)
1122 unsigned int const NoOfColumns
= this->GetColumnCount();
1125 for (unsigned int i
=0; i
<NoOfColumns
; ++i
)
1127 // variable definition and initialization:
1128 wxDataViewColumn
* dataViewColumnPtr(this->GetColumn(i
));
1130 if (dataViewColumnPtr
!= NULL
)
1132 // variable definition and initialization:
1133 wxDataViewCustomRenderer
* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer()));
1135 if (dataViewCustomRendererPtr
!= NULL
)
1136 dataViewCustomRendererPtr
->SetDC(NULL
); // reset DC because DC has changed
1140 } /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
1142 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
,wxDataViewCtrlBase
)
1144 BEGIN_EVENT_TABLE(wxDataViewCtrl
,wxDataViewCtrlBase
)
1145 EVT_SIZE(wxDataViewCtrl::OnSize
)
1149 // !wxUSE_GENERICDATAVIEWCTRL
1152 // wxUSE_DATAVIEWCTRL