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_VALUE_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_ITEM_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
)
206 } /* Cleared(void) */
208 virtual void Resort(void)
210 this->m_dataViewControlPtr
->Resort();
218 wxMacDataViewDataBrowserListViewControl
* m_dataViewControlPtr
;
221 // ---------------------------------------------------------
222 // wxDataViewRenderer
223 // ---------------------------------------------------------
225 wxDataViewRenderer::wxDataViewRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
226 :wxDataViewRendererBase(varianttype
,mode
,align
), m_alignment(align
), m_mode(mode
)
228 } /* wxDataViewRenderer::wxDataViewRenderer(wxString const&, wxDataViewCellMode) */
230 void wxDataViewRenderer::SetMode(wxDataViewCellMode mode
)
232 wxDataViewColumn
* dataViewColumnPtr
;
236 dataViewColumnPtr
= this->GetOwner();
237 if (dataViewColumnPtr
!= NULL
)
239 // variable definition and initialization:
240 wxDataViewCtrl
* dataViewCtrlPtr(dataViewColumnPtr
->GetOwner());
242 if (dataViewCtrlPtr
!= NULL
)
244 // variable definition and initialization:
245 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
247 if (macDataViewListCtrlPtr
!= NULL
)
249 // variable definition and initialization:
250 DataBrowserPropertyFlags flags
;
252 verify_noerr(macDataViewListCtrlPtr
->GetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),&flags
));
253 if (mode
== wxDATAVIEW_CELL_EDITABLE
)
254 flags
|= kDataBrowserPropertyIsEditable
;
256 flags
&= ~kDataBrowserPropertyIsEditable
;
257 verify_noerr(macDataViewListCtrlPtr
->SetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),flags
));
261 } /* wxDataViewRenderer::SetMode(wxDataViewCellMode) */
263 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
,wxDataViewRendererBase
)
265 // ---------------------------------------------------------
266 // wxDataViewCustomRenderer
267 // ---------------------------------------------------------
269 wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
270 :wxDataViewRenderer(varianttype
,mode
,align
), m_editorCtrlPtr(NULL
), m_DCPtr(NULL
)
272 } /* wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const&, wxDataViewCellMode) */
274 wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void)
276 if (this->m_DCPtr
!= NULL
)
277 delete this->m_DCPtr
;
278 } /* wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) */
280 wxDC
* wxDataViewCustomRenderer::GetDC(void)
282 if (this->m_DCPtr
== NULL
)
284 if ((GetOwner() == NULL
) || (GetOwner()->GetOwner() == NULL
))
286 this->m_DCPtr
= new wxClientDC(this->GetOwner()->GetOwner());
288 return this->m_DCPtr
;
289 } /* wxDataViewCustomRenderer::GetDC(void) */
291 bool wxDataViewCustomRenderer::Render(void)
294 } /* wxDataViewCustomRenderer::Render(void) */
296 void wxDataViewCustomRenderer::SetDC(wxDC
* newDCPtr
)
298 delete this->m_DCPtr
;
299 this->m_DCPtr
= newDCPtr
;
300 } /* wxDataViewCustomRenderer::SetDC(wxDC*) */
303 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
305 // ---------------------------------------------------------
306 // wxDataViewTextRenderer
307 // ---------------------------------------------------------
309 wxDataViewTextRenderer::wxDataViewTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
310 :wxDataViewRenderer(varianttype
,mode
,align
)
312 } /* wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const&, wxDataViewCellMode, int) */
314 bool wxDataViewTextRenderer::Render(void)
316 if (this->GetValue().GetType() == this->GetVariantType())
318 // variable definition:
319 wxMacCFStringHolder
cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
321 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
);
325 } /* wxDataViewTextRenderer::Render(void) */
327 IMPLEMENT_CLASS(wxDataViewTextRenderer
,wxDataViewRenderer
)
329 // ---------------------------------------------------------
330 // wxDataViewBitmapRenderer
331 // ---------------------------------------------------------
333 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
334 :wxDataViewRenderer(varianttype
,mode
,align
)
338 bool wxDataViewBitmapRenderer::Render(void)
340 if (this->GetValue().GetType() == this->GetVariantType())
344 bitmap
<< this->GetValue();
346 return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap
.GetBitmapData()->GetIconRef()) == noErr
);
352 } /* wxDataViewBitmapRenderer::Render(void) */
354 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
,wxDataViewRenderer
)
356 // ---------------------------------------------------------
357 // wxDataViewIconTextRenderer
358 // ---------------------------------------------------------
360 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
361 :wxDataViewRenderer(varianttype
,mode
)
365 bool wxDataViewIconTextRenderer::Render(void)
367 if (this->GetValue().GetType() == this->GetVariantType())
369 // variable definition:
370 wxDataViewIconText iconText
;
372 iconText
<< this->GetValue();
374 // variable definition:
375 wxMacCFStringHolder
cfString(iconText
.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
377 return ((::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText
.GetIcon().GetHICON())) == noErr
) &&
378 (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
));
382 } /* wxDataViewIconTextRenderer::Render(void) */
384 IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer
,wxDataViewRenderer
)
387 // ---------------------------------------------------------
388 // wxDataViewToggleRenderer
389 // ---------------------------------------------------------
391 wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
392 :wxDataViewRenderer(varianttype
,mode
)
396 bool wxDataViewToggleRenderer::Render(void)
398 if (this->GetValue().GetType() == this->GetVariantType())
399 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr
);
402 } /* wxDataViewToggleRenderer::Render(void) */
404 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
,wxDataViewRenderer
)
406 // ---------------------------------------------------------
407 // wxDataViewProgressRenderer
408 // ---------------------------------------------------------
410 wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString
const& label
, wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
411 :wxDataViewRenderer(varianttype
,mode
,align
)
415 bool wxDataViewProgressRenderer::Render(void)
417 if (this->GetValue().GetType() == this->GetVariantType())
418 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr
) &&
419 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr
) &&
420 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr
));
423 } /* wxDataViewProgressRenderer::Render(void) */
425 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
,wxDataViewRenderer
)
427 // ---------------------------------------------------------
428 // wxDataViewDateRenderer
429 // ---------------------------------------------------------
431 wxDataViewDateRenderer::wxDataViewDateRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
432 :wxDataViewRenderer(varianttype
,mode
,align
)
436 bool wxDataViewDateRenderer::Render(void)
438 if (this->GetValue().GetType() == this->GetVariantType())
439 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan
,1904)).GetSeconds().GetLo()) == noErr
);
442 } /* wxDataViewDateRenderer::Render(void) */
444 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
,wxDataViewRenderer
)
446 // ---------------------------------------------------------
448 // ---------------------------------------------------------
450 wxDataViewColumn::wxDataViewColumn(wxString
const &title
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
451 :wxDataViewColumnBase(title
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
452 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
)), m_maxWidth(30000), m_minWidth(0), m_width(width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
),
453 m_alignment(align
), m_title(title
)
455 } /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
457 wxDataViewColumn::wxDataViewColumn(wxBitmap
const& bitmap
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
458 :wxDataViewColumnBase(bitmap
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
459 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
)), m_maxWidth(30000), m_minWidth(0), m_width(width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
),
462 } /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
464 void wxDataViewColumn::SetAlignment(wxAlignment align
)
466 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
469 this->m_alignment
= align
;
470 if (dataViewCtrlPtr
!= NULL
)
472 // variable definition and initialization:
473 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
475 if (macDataViewListCtrlPtr
!= NULL
)
477 // variable definition and initialization:
478 DataBrowserListViewHeaderDesc headerDescription
;
480 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
484 case wxALIGN_CENTER_HORIZONTAL
:
485 headerDescription
.btnFontStyle
.just
= teCenter
;
488 headerDescription
.btnFontStyle
.just
= teFlushLeft
;
491 headerDescription
.btnFontStyle
.just
= teFlushRight
;
494 headerDescription
.btnFontStyle
.just
= teFlushDefault
;
496 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set alignment."));
499 } /* wxDataViewColumn::SetAlignment(wxAlignment) */
501 void wxDataViewColumn::SetBitmap(wxBitmap
const& bitmap
)
503 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
506 wxDataViewColumnBase::SetBitmap(bitmap
);
507 if (dataViewCtrlPtr
!= NULL
)
509 // variable definition and initialization:
510 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
512 if (macDataViewListCtrlPtr
!= NULL
)
514 // variable definition and initialization:
515 DataBrowserListViewHeaderDesc headerDescription
;
517 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
518 if (this->GetBitmap().Ok())
519 headerDescription
.btnContentInfo
.u
.iconRef
= this->GetBitmap().GetBitmapData()->GetIconRef();
521 headerDescription
.btnContentInfo
.u
.iconRef
= NULL
;
522 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set icon."));
525 } /* wxDataViewColumn::SetBitmap(wxBitmap const&) */
527 void wxDataViewColumn::SetFlags(int flags
)
529 this->SetHidden ((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
530 this->SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
531 this->SetSortable ((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
532 } /* wxDataViewColumn::SetFlags(int) */
534 void wxDataViewColumn::SetMaxWidth(int maxWidth
)
536 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
539 this->m_maxWidth
= maxWidth
;
540 if (dataViewCtrlPtr
!= NULL
)
542 // variable definition and initialization:
543 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
545 if (macDataViewListCtrlPtr
!= NULL
)
547 // variable definition and initialization:
548 DataBrowserListViewHeaderDesc headerDescription
;
550 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
551 headerDescription
.maximumWidth
= static_cast<UInt16
>(maxWidth
);
552 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set maximum width."));
555 } /* wxDataViewColumn::SetMaxWidth(int) */
557 void wxDataViewColumn::SetMinWidth(int minWidth
)
559 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
562 this->m_minWidth
= minWidth
;
563 if (dataViewCtrlPtr
!= NULL
)
565 // variable definition and initialization:
566 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
568 if (macDataViewListCtrlPtr
!= NULL
)
570 // variable definition and initialization:
571 DataBrowserListViewHeaderDesc headerDescription
;
573 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
574 headerDescription
.minimumWidth
= static_cast<UInt16
>(minWidth
);
575 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set minimum width."));
578 } /* wxDataViewColumn::SetMaxWidth(int) */
580 void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable
))
582 } /* wxDataViewColumn::SetResizeable(bool) */
584 void wxDataViewColumn::SetSortable(bool sortable
)
586 // variable definition and initialization:
587 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
589 if (dataViewCtrlPtr
!= NULL
)
591 // variable definition and initialization:
592 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
594 if (macDataViewListCtrlPtr
!= NULL
)
596 // variable definition and initialization:
597 DataBrowserPropertyFlags flags
;
599 wxCHECK_RET(macDataViewListCtrlPtr
->GetPropertyFlags(this->GetPropertyID(),&flags
) == noErr
,_("Could not get property flags."));
602 this->m_flags
|= wxDATAVIEW_COL_SORTABLE
;
603 flags
|= kDataBrowserListViewSortableColumn
;
607 this->m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
608 flags
&= ~kDataBrowserPropertyIsEditable
;
610 wxCHECK_RET(macDataViewListCtrlPtr
->SetPropertyFlags(this->GetPropertyID(),flags
) == noErr
,_("Could not set property flags."));
613 } /* wxDataViewColumn::SetSortable(bool) */
615 void wxDataViewColumn::SetSortOrder(bool ascending
)
617 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
620 this->m_ascending
= ascending
;
621 if (dataViewCtrlPtr
!= NULL
)
623 // variable definition and initialization:
624 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
626 if (macDataViewListCtrlPtr
!= NULL
)
628 // variable definition and initialization:
629 DataBrowserListViewHeaderDesc headerDescription
;
631 verify_noerr(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
));
633 headerDescription
.initialOrder
= kDataBrowserOrderIncreasing
;
635 headerDescription
.initialOrder
= kDataBrowserOrderDecreasing
;
636 verify_noerr(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
));
637 macDataViewListCtrlPtr
->SetSortProperty(this->GetPropertyID());
640 } /* wxDataViewColumn::SetSortOrder(bool) */
642 void wxDataViewColumn::SetTitle(wxString
const& title
)
644 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
647 this->m_title
= title
;
648 if (dataViewCtrlPtr
!= NULL
)
650 // variable definition and initialization:
651 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
653 if (macDataViewListCtrlPtr
!= NULL
)
655 // variable definition and initialization:
656 DataBrowserListViewHeaderDesc headerDescription
;
657 wxMacCFStringHolder
cfTitle(title
,(dataViewCtrlPtr
->GetFont().Ok() ? dataViewCtrlPtr
->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
659 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
660 headerDescription
.titleString
= cfTitle
;
661 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set header description."));
664 } /* wxDataViewColumn::SetTitle(wxString const&) */
666 void wxDataViewColumn::SetWidth(int width
)
668 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
671 if ((width
>= this->m_minWidth
) && (width
<= this->m_maxWidth
))
673 this->m_width
= width
;
674 if (dataViewCtrlPtr
!= NULL
)
676 // variable definition and initialization:
677 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
679 if (macDataViewListCtrlPtr
!= NULL
)
680 wxCHECK_RET(macDataViewListCtrlPtr
->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16
>(width
)) == noErr
,_("Could not set column width."));
683 } /* wxDataViewColumn::SetWidth(int) */
685 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
,wxDataViewColumnBase
)
687 //-----------------------------------------------------------------------------
689 //-----------------------------------------------------------------------------
691 void wxDataViewCtrl::Init(void)
693 this->m_Deleting
= false;
694 this->m_macIsUserPane
= false;
695 this->m_cgContext
= NULL
;
696 } /* wxDataViewCtrl::Init(void) */
698 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
700 if (!(this->wxControl::Create(parent
,id
,pos
,size
,(style
| wxSUNKEN_BORDER
) & ~(wxHSCROLL
| wxVSCROLL
),validator
)))
704 MacSetClipChildren(true) ;
707 this->m_peer
= new wxMacDataViewDataBrowserListViewControl(this,pos
,size
,style
);
708 this->MacPostControlCreate(pos
,size
);
709 ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(this->m_peer
->GetControlRef()),true);
711 InstallControlEventHandler(this->m_peer
->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList
),eventList
,this,NULL
);
714 } /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
716 bool wxDataViewCtrl::AssociateModel(wxDataViewModel
* model
)
718 if (!wxDataViewCtrlBase::AssociateModel(model
))
721 model
->AddNotifier(new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl
*>(this->m_peer
)));
724 } /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
726 bool wxDataViewCtrl::AppendColumn(wxDataViewColumn
* dataViewColumnPtr
)
728 DataBrowserPropertyID NewPropertyID
;
730 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
733 // first, some error checking:
734 wxCHECK_MSG(MacDataViewListCtrlPtr
!= NULL
, false,_("m_peer is not or incorrectly initialized"));
735 wxCHECK_MSG(dataViewColumnPtr
!= NULL
, false,_("Column pointer must not be NULL."));
736 wxCHECK_MSG(dataViewColumnPtr
->GetRenderer() != NULL
, false,_("Column does not have a renderer."));
737 wxCHECK_MSG(this->GetModel() != NULL
, false,_("No model associated with control."));
738 wxCHECK_MSG((dataViewColumnPtr
->GetModelColumn() >= 0) &&
739 (dataViewColumnPtr
->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
740 if ((MacDataViewListCtrlPtr
->GetFreePropertyID(&NewPropertyID
) == noErr
) && this->wxDataViewCtrlBase::AppendColumn(dataViewColumnPtr
))
742 // insert column into hash map:
743 this->m_ColumnPointers
.insert(ColumnPointerHashMapType::value_type(NewPropertyID
,dataViewColumnPtr
));
745 // variable definitions:
746 DataBrowserListViewColumnDesc columnDescription
;
747 wxMacCFStringHolder
cfTitle(dataViewColumnPtr
->GetTitle(),(this->m_font
.Ok() ? this->m_font
.GetEncoding() : wxLocale::GetSystemEncoding()));
749 // initialize column description:
750 dataViewColumnPtr
->SetPropertyID(NewPropertyID
);
751 columnDescription
.propertyDesc
.propertyID
= NewPropertyID
;
752 columnDescription
.propertyDesc
.propertyType
= dataViewColumnPtr
->GetRenderer()->GetPropertyType();
753 columnDescription
.propertyDesc
.propertyFlags
= kDataBrowserListViewSelectionColumn
; // make the column selectable
754 if (dataViewColumnPtr
->IsSortable())
755 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewSortableColumn
;
757 if (dataViewColumnPtr
->IsMovable())
758 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewMovableColumn
;
760 if (dataViewColumnPtr
->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE
)
761 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserPropertyIsEditable
;
762 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
763 if ((columnDescription
.propertyDesc
.propertyType
== kDataBrowserTextType
) ||
764 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserIconAndTextType
) ||
765 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserDateTimeType
))
766 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
768 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
769 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
771 columnDescription
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
772 if (dataViewColumnPtr
->IsResizeable())
774 columnDescription
.headerBtnDesc
.minimumWidth
= 0;
775 columnDescription
.headerBtnDesc
.maximumWidth
= 30000;
779 columnDescription
.headerBtnDesc
.minimumWidth
= dataViewColumnPtr
->GetWidth();
780 columnDescription
.headerBtnDesc
.maximumWidth
= dataViewColumnPtr
->GetWidth();
782 columnDescription
.headerBtnDesc
.titleOffset
= 0;
783 columnDescription
.headerBtnDesc
.titleString
= cfTitle
; // we cannot directly use the wxMacCFStringHolder constructor call because then the CFStringRef is released
784 // having called 'AddColumn' where the title (CFStringRef) is going to be used
785 columnDescription
.headerBtnDesc
.initialOrder
= kDataBrowserOrderIncreasing
;
786 columnDescription
.headerBtnDesc
.btnFontStyle
.flags
= kControlUseFontMask
| kControlUseJustMask
;
787 switch (dataViewColumnPtr
->GetAlignment())
790 case wxALIGN_CENTER_HORIZONTAL
:
791 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teCenter
;
794 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushLeft
;
797 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushRight
;
800 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
802 columnDescription
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
803 columnDescription
.headerBtnDesc
.btnFontStyle
.style
= normal
;
804 columnDescription
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
805 if (dataViewColumnPtr
->GetBitmap().Ok())
806 columnDescription
.headerBtnDesc
.btnContentInfo
.u
.iconRef
= dataViewColumnPtr
->GetBitmap().GetBitmapData()->GetIconRef();
808 wxCHECK_MSG(MacDataViewListCtrlPtr
->AddColumn(&columnDescription
,kDataBrowserListViewAppendColumn
) == noErr
,false,_("Column could not be added."));
810 // final adjustments for the layout:
811 wxCHECK_MSG(MacDataViewListCtrlPtr
->SetColumnWidth(NewPropertyID
,dataViewColumnPtr
->GetWidth()) == noErr
,false,_("Column width could not be set."));
813 // make sure that the data is up-to-date...
814 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
815 // otherwise ask the control to 'update' the data in the newly appended column:
816 if (this->GetColumnCount() == 1)
818 this->SetExpanderColumn(dataViewColumnPtr
);
819 this->AddChildrenLevel(wxDataViewItem());
822 MacDataViewListCtrlPtr
->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,NewPropertyID
);
828 } /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
830 bool wxDataViewCtrl::ClearColumns(void)
832 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
835 while (this->m_ColumnPointers
.begin() != this->m_ColumnPointers
.end())
837 wxCHECK_MSG(MacDataViewListCtrlPtr
->RemoveColumnByProperty(this->m_ColumnPointers
.begin()->first
) == noErr
,false,_("Could not remove column."));
838 delete this->m_ColumnPointers
.begin()->second
;
839 this->m_ColumnPointers
.erase(this->m_ColumnPointers
.begin());
842 } /* wxDataViewCtrl::ClearColumns(void) */
844 bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn
* columnPtr
)
846 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
849 if ((MacDataViewListCtrlPtr
->RemoveColumnByProperty(columnPtr
->GetPropertyID()) == noErr
) && (this->m_ColumnPointers
.erase(columnPtr
->GetPropertyID()) > 0))
856 } /* wxDataViewCtrl::DeleteColumn(wxDataViewColumn*) */
858 wxDataViewColumn
* wxDataViewCtrl::GetColumn(unsigned int pos
) const
860 DataBrowserPropertyID propertyID
;
862 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
865 if (MacDataViewListCtrlPtr
->GetPropertyID(pos
,&propertyID
) == noErr
)
867 // variable definition:
868 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
870 if (Result
!= this->m_ColumnPointers
.end())
871 return Result
->second
;
877 } /* wxDataViewCtrl::GetColumn(unsigned int pos) const */
879 unsigned int wxDataViewCtrl::GetColumnCount(void) const
881 return this->m_ColumnPointers
.size();
882 } /* wxDataViewCtrl::GetColumnCount(void) const */
884 int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn
const* columnPtr
) const
886 if (columnPtr
!= NULL
)
888 // variable definition and initialization:
889 DataBrowserTableViewColumnIndex Position
;
890 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
892 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetColumnIndex(columnPtr
->GetPropertyID(),&Position
) == noErr
,-1,_("Could not determine column's position"));
893 return static_cast<int>(Position
);
897 } /* wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const*) const */
899 void wxDataViewCtrl::Collapse(wxDataViewItem
const& item
)
901 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
904 MacDataViewListCtrlPtr
->CloseContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
905 } /* wxDataViewCtrl::Collapse(wxDataViewItem const&) */
907 void wxDataViewCtrl::EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
)
911 // variable definition and initialization:
912 DataBrowserPropertyID propertyID
;
913 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
915 if (columnPtr
!= NULL
)
916 propertyID
= columnPtr
->GetPropertyID();
918 propertyID
= kDataBrowserNoItem
;
919 MacDataViewListCtrlPtr
->RevealItem(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),propertyID
,kDataBrowserRevealOnly
);
921 } /* wxDataViewCtrl::EnsureVisible(wxDataViewItem const&, wxDataViewColumn const*) */
923 void wxDataViewCtrl::Expand(wxDataViewItem
const& item
)
925 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
928 MacDataViewListCtrlPtr
->OpenContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
929 } /* wxDataViewCtrl::Expand(wxDataViewItem const&) */
931 wxDataViewColumn
* wxDataViewCtrl::GetSortingColumn(void) const
933 DataBrowserPropertyID propertyID
;
935 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
938 if (MacDataViewListCtrlPtr
->GetSortProperty(&propertyID
) == noErr
)
939 return this->GetColumnPtr(propertyID
);
942 } /* wxDataViewCtrl::GetSortingColumn(void) const */
944 unsigned int wxDataViewCtrl::GetCount(void) const
949 wxCHECK_MSG(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
)->GetItemCount(&noOfItems
) == noErr
,0,_("Could not determine number of items"));
951 } /* wxDataViewCtrl::GetCount(void) const */
953 wxRect
wxDataViewCtrl::GetItemRect(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
) const
955 if (item
.IsOk() && (columnPtr
!= NULL
))
957 // variable definition:
959 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
961 if (MacDataViewListCtrlPtr
->GetPartBounds(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),columnPtr
->GetPropertyID(),kDataBrowserPropertyContentPart
,&MacRectangle
) == noErr
)
963 // variable definition:
966 ::wxMacNativeToRect(&MacRectangle
,&rectangle
);
974 } /* wxDataViewCtrl::GetItemRect(wxDataViewItem const&, unsigned int) const */
976 wxDataViewItem
wxDataViewCtrl::GetSelection(void) const
978 wxArrayDataBrowserItemID itemIDs
;
980 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
983 if (MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
) > 0)
984 return wxDataViewItem(reinterpret_cast<void*>(itemIDs
[0]));
986 return wxDataViewItem();
987 } /* wxDataViewCtrl::GetSelection(void) const */
989 int wxDataViewCtrl::GetSelections(wxDataViewItemArray
& sel
) const
991 size_t NoOfSelectedItems
;
993 wxArrayDataBrowserItemID itemIDs
;
995 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
998 NoOfSelectedItems
= MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
);
1000 sel
.SetCount(NoOfSelectedItems
);
1001 for (size_t i
=0; i
<NoOfSelectedItems
; ++i
)
1002 sel
[i
] = wxDataViewItem(reinterpret_cast<void*>(itemIDs
[i
]));
1003 return static_cast<int>(NoOfSelectedItems
);
1004 } /* wxDataViewCtrl::GetSelections(wxDataViewItemArray&) const */
1006 void wxDataViewCtrl::HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const
1008 item
= wxDataViewItem();
1010 } /* wxDataViewCtrl::HitTest(wxPoint const&, wxDataViewItem&, wxDataViewColumn*&) const */
1012 bool wxDataViewCtrl::IsSelected(wxDataViewItem
const& item
) const
1014 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1017 return MacDataViewListCtrlPtr
->IsItemSelected(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1018 } /* wxDataViewCtrl::IsSelected(wxDataViewItem const&) const */
1020 void wxDataViewCtrl::SelectAll(void)
1022 DataBrowserItemID
* itemIDPtr
;
1024 Handle
handle(::NewHandle(0));
1028 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1031 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1032 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1034 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1035 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsAssign
);
1037 DisposeHandle(handle
);
1038 } /* wxDataViewCtrl::SelectAll(void) */
1040 void wxDataViewCtrl::Select(wxDataViewItem
const& item
)
1044 // variable definition and initialization:
1045 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1046 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1048 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsAdd
);
1050 } /* wxDataViewCtrl::Select(wxDataViewItem const&) */
1052 void wxDataViewCtrl::SetSelections(wxDataViewItemArray
const& sel
)
1054 size_t const NoOfSelections
= sel
.GetCount();
1056 DataBrowserItemID
* itemIDs
;
1058 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1061 itemIDs
= new DataBrowserItemID
[NoOfSelections
];
1062 for (size_t i
=0; i
<NoOfSelections
; ++i
)
1063 itemIDs
[i
] = reinterpret_cast<DataBrowserItemID
>(sel
[i
].GetID());
1064 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfSelections
,itemIDs
,kDataBrowserItemsAssign
);
1066 } /* wxDataViewCtrl::SetSelections(wxDataViewItemArray const&) */
1068 void wxDataViewCtrl::Unselect(wxDataViewItem
const& item
)
1072 // variable definition and initialization:
1073 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1074 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1076 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsRemove
);
1078 } /* wxDataViewCtrl::Unselect(wxDataViewItem const&) */
1080 void wxDataViewCtrl::UnselectAll(void)
1082 DataBrowserItemID
* itemIDPtr
;
1084 Handle
handle(::NewHandle(0));
1088 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1091 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1092 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1094 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1095 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsRemove
);
1097 DisposeHandle(handle
);
1098 } /* wxDataViewCtrl::UnselectAll(void) */
1101 void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem
const& parentItem
)
1105 wxDataViewItemArray items
;
1108 wxCHECK_RET(this->GetModel() != NULL
,_("Model pointer not initialized."));
1109 NoOfChildren
= this->GetModel()->GetChildren(parentItem
,items
);
1110 for (int i
=0; i
<NoOfChildren
; ++i
)
1111 (void) this->GetModel()->ItemAdded(parentItem
,items
[i
]);
1112 } /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
1114 wxDataViewColumn
* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID propertyID
) const
1116 // variable definition:
1117 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
1119 if (Result
!= this->m_ColumnPointers
.end())
1120 return Result
->second
;
1123 } /* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID) const */
1125 // inherited methods from wxDataViewCtrlBase
1126 void wxDataViewCtrl::DoSetExpanderColumn(void)
1128 if (this->GetExpanderColumn() != NULL
)
1130 // variable definition and initialization:
1131 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1133 (void) MacDataViewListCtrlPtr
->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID());
1135 } /* wxDataViewCtrl::DoSetExpanderColumn(void) */
1137 void wxDataViewCtrl::DoSetIndent(void)
1139 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1142 (void) MacDataViewListCtrlPtr
->SetIndent(static_cast<float>(this->GetIndent()));
1143 } /* wxDataViewCtrl::DoSetIndent(void) */
1146 void wxDataViewCtrl::OnSize(wxSizeEvent
& event
)
1148 unsigned int const NoOfColumns
= this->GetColumnCount();
1151 for (unsigned int i
=0; i
<NoOfColumns
; ++i
)
1153 // variable definition and initialization:
1154 wxDataViewColumn
* dataViewColumnPtr(this->GetColumn(i
));
1156 if (dataViewColumnPtr
!= NULL
)
1158 // variable definition and initialization:
1159 wxDataViewCustomRenderer
* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer()));
1161 if (dataViewCustomRendererPtr
!= NULL
)
1162 dataViewCustomRendererPtr
->SetDC(NULL
); // reset DC because DC has changed
1166 } /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
1168 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
,wxDataViewCtrlBase
)
1170 BEGIN_EVENT_TABLE(wxDataViewCtrl
,wxDataViewCtrlBase
)
1171 EVT_SIZE(wxDataViewCtrl::OnSize
)
1175 // !wxUSE_GENERICDATAVIEWCTRL
1178 // wxUSE_DATAVIEWCTRL