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 if (this->GetValue().GetType() == this->GetVariantType())
379 // variable definition:
380 wxDataViewIconText iconText
;
382 iconText
<< this->GetValue();
384 // variable definition:
385 wxMacCFStringHolder
cfString(iconText
.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
387 return ((::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText
.GetIcon().GetHICON())) == noErr
) &&
388 (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
));
392 } /* wxDataViewIconTextRenderer::Render(void) */
394 IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer
,wxDataViewRenderer
)
397 // ---------------------------------------------------------
398 // wxDataViewToggleRenderer
399 // ---------------------------------------------------------
401 wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
402 :wxDataViewRenderer(varianttype
,mode
)
406 bool wxDataViewToggleRenderer::Render(void)
408 if (this->GetValue().GetType() == this->GetVariantType())
409 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr
);
412 } /* wxDataViewToggleRenderer::Render(void) */
414 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
,wxDataViewRenderer
)
416 // ---------------------------------------------------------
417 // wxDataViewProgressRenderer
418 // ---------------------------------------------------------
420 wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString
const& label
, wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
421 :wxDataViewRenderer(varianttype
,mode
,align
)
425 bool wxDataViewProgressRenderer::Render(void)
427 if (this->GetValue().GetType() == this->GetVariantType())
428 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr
) &&
429 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr
) &&
430 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr
));
433 } /* wxDataViewProgressRenderer::Render(void) */
435 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
,wxDataViewRenderer
)
437 // ---------------------------------------------------------
438 // wxDataViewDateRenderer
439 // ---------------------------------------------------------
441 wxDataViewDateRenderer::wxDataViewDateRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
442 :wxDataViewRenderer(varianttype
,mode
,align
)
446 bool wxDataViewDateRenderer::Render(void)
448 if (this->GetValue().GetType() == this->GetVariantType())
449 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan
,1904)).GetSeconds().GetLo()) == noErr
);
452 } /* wxDataViewDateRenderer::Render(void) */
454 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
,wxDataViewRenderer
)
456 // ---------------------------------------------------------
458 // ---------------------------------------------------------
460 wxDataViewColumn::wxDataViewColumn(wxString
const &title
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
461 :wxDataViewColumnBase(title
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
462 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
)), m_maxWidth(30000), m_minWidth(0), m_width(width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
),
463 m_alignment(align
), m_title(title
)
465 } /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
467 wxDataViewColumn::wxDataViewColumn(wxBitmap
const& bitmap
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
468 :wxDataViewColumnBase(bitmap
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
469 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
)), m_maxWidth(30000), m_minWidth(0), m_width(width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
),
472 } /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
474 void wxDataViewColumn::SetAlignment(wxAlignment align
)
476 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
479 this->m_alignment
= align
;
480 if (dataViewCtrlPtr
!= NULL
)
482 // variable definition and initialization:
483 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
485 if (macDataViewListCtrlPtr
!= NULL
)
487 // variable definition and initialization:
488 DataBrowserListViewHeaderDesc headerDescription
;
490 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
494 case wxALIGN_CENTER_HORIZONTAL
:
495 headerDescription
.btnFontStyle
.just
= teCenter
;
498 headerDescription
.btnFontStyle
.just
= teFlushLeft
;
501 headerDescription
.btnFontStyle
.just
= teFlushRight
;
504 headerDescription
.btnFontStyle
.just
= teFlushDefault
;
506 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set alignment."));
509 } /* wxDataViewColumn::SetAlignment(wxAlignment) */
511 void wxDataViewColumn::SetBitmap(wxBitmap
const& bitmap
)
513 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
516 wxDataViewColumnBase::SetBitmap(bitmap
);
517 if (dataViewCtrlPtr
!= NULL
)
519 // variable definition and initialization:
520 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
522 if (macDataViewListCtrlPtr
!= NULL
)
524 // variable definition and initialization:
525 DataBrowserListViewHeaderDesc headerDescription
;
527 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
528 if (this->GetBitmap().Ok())
529 headerDescription
.btnContentInfo
.u
.iconRef
= this->GetBitmap().GetBitmapData()->GetIconRef();
531 headerDescription
.btnContentInfo
.u
.iconRef
= NULL
;
532 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set icon."));
535 } /* wxDataViewColumn::SetBitmap(wxBitmap const&) */
537 void wxDataViewColumn::SetFlags(int flags
)
539 this->SetHidden ((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
540 this->SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
541 this->SetSortable ((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
542 } /* wxDataViewColumn::SetFlags(int) */
544 void wxDataViewColumn::SetMaxWidth(int maxWidth
)
546 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
549 this->m_maxWidth
= maxWidth
;
550 if (dataViewCtrlPtr
!= NULL
)
552 // variable definition and initialization:
553 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
555 if (macDataViewListCtrlPtr
!= NULL
)
557 // variable definition and initialization:
558 DataBrowserListViewHeaderDesc headerDescription
;
560 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
561 headerDescription
.maximumWidth
= static_cast<UInt16
>(maxWidth
);
562 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set maximum width."));
565 } /* wxDataViewColumn::SetMaxWidth(int) */
567 void wxDataViewColumn::SetMinWidth(int minWidth
)
569 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
572 this->m_minWidth
= minWidth
;
573 if (dataViewCtrlPtr
!= NULL
)
575 // variable definition and initialization:
576 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
578 if (macDataViewListCtrlPtr
!= NULL
)
580 // variable definition and initialization:
581 DataBrowserListViewHeaderDesc headerDescription
;
583 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
584 headerDescription
.minimumWidth
= static_cast<UInt16
>(minWidth
);
585 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set minimum width."));
588 } /* wxDataViewColumn::SetMaxWidth(int) */
590 void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable
))
592 } /* wxDataViewColumn::SetResizeable(bool) */
594 void wxDataViewColumn::SetSortable(bool sortable
)
596 // variable definition and initialization:
597 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
599 if (dataViewCtrlPtr
!= NULL
)
601 // variable definition and initialization:
602 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
604 if (macDataViewListCtrlPtr
!= NULL
)
606 // variable definition and initialization:
607 DataBrowserPropertyFlags flags
;
609 wxCHECK_RET(macDataViewListCtrlPtr
->GetPropertyFlags(this->GetPropertyID(),&flags
) == noErr
,_("Could not get property flags."));
612 this->m_flags
|= wxDATAVIEW_COL_SORTABLE
;
613 flags
|= kDataBrowserListViewSortableColumn
;
617 this->m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
618 flags
&= ~kDataBrowserPropertyIsEditable
;
620 wxCHECK_RET(macDataViewListCtrlPtr
->SetPropertyFlags(this->GetPropertyID(),flags
) == noErr
,_("Could not set property flags."));
623 } /* wxDataViewColumn::SetSortable(bool) */
625 void wxDataViewColumn::SetSortOrder(bool ascending
)
627 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
630 this->m_ascending
= ascending
;
631 if (dataViewCtrlPtr
!= NULL
)
633 // variable definition and initialization:
634 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
636 if (macDataViewListCtrlPtr
!= NULL
)
638 // variable definition and initialization:
639 DataBrowserListViewHeaderDesc headerDescription
;
641 verify_noerr(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
));
643 headerDescription
.initialOrder
= kDataBrowserOrderIncreasing
;
645 headerDescription
.initialOrder
= kDataBrowserOrderDecreasing
;
646 verify_noerr(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
));
647 macDataViewListCtrlPtr
->SetSortProperty(this->GetPropertyID());
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 columnDescription
.propertyDesc
.propertyID
= NewPropertyID
;
762 columnDescription
.propertyDesc
.propertyType
= dataViewColumnPtr
->GetRenderer()->GetPropertyType();
763 columnDescription
.propertyDesc
.propertyFlags
= kDataBrowserListViewSelectionColumn
; // make the column selectable
764 if (dataViewColumnPtr
->IsSortable())
765 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewSortableColumn
;
767 if (dataViewColumnPtr
->IsMovable())
768 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewMovableColumn
;
770 if (dataViewColumnPtr
->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE
)
771 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserPropertyIsEditable
;
772 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
773 if ((columnDescription
.propertyDesc
.propertyType
== kDataBrowserTextType
) ||
774 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserIconAndTextType
) ||
775 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserDateTimeType
))
776 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
778 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
779 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
781 columnDescription
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
782 if (dataViewColumnPtr
->IsResizeable())
784 columnDescription
.headerBtnDesc
.minimumWidth
= 0;
785 columnDescription
.headerBtnDesc
.maximumWidth
= 30000;
789 columnDescription
.headerBtnDesc
.minimumWidth
= dataViewColumnPtr
->GetWidth();
790 columnDescription
.headerBtnDesc
.maximumWidth
= dataViewColumnPtr
->GetWidth();
792 columnDescription
.headerBtnDesc
.titleOffset
= 0;
793 columnDescription
.headerBtnDesc
.titleString
= cfTitle
; // we cannot directly use the wxMacCFStringHolder constructor call because then the CFStringRef is released
794 // having called 'AddColumn' where the title (CFStringRef) is going to be used
795 columnDescription
.headerBtnDesc
.initialOrder
= kDataBrowserOrderIncreasing
;
796 columnDescription
.headerBtnDesc
.btnFontStyle
.flags
= kControlUseFontMask
| kControlUseJustMask
;
797 switch (dataViewColumnPtr
->GetAlignment())
800 case wxALIGN_CENTER_HORIZONTAL
:
801 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teCenter
;
804 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushLeft
;
807 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushRight
;
810 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
812 columnDescription
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
813 columnDescription
.headerBtnDesc
.btnFontStyle
.style
= normal
;
814 columnDescription
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
815 if (dataViewColumnPtr
->GetBitmap().Ok())
816 columnDescription
.headerBtnDesc
.btnContentInfo
.u
.iconRef
= dataViewColumnPtr
->GetBitmap().GetBitmapData()->GetIconRef();
818 wxCHECK_MSG(MacDataViewListCtrlPtr
->AddColumn(&columnDescription
,kDataBrowserListViewAppendColumn
) == noErr
,false,_("Column could not be added."));
820 // final adjustments for the layout:
821 wxCHECK_MSG(MacDataViewListCtrlPtr
->SetColumnWidth(NewPropertyID
,dataViewColumnPtr
->GetWidth()) == noErr
,false,_("Column width could not be set."));
823 // make sure that the data is up-to-date...
824 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
825 // otherwise ask the control to 'update' the data in the newly appended column:
826 if (this->GetColumnCount() == 1)
828 this->SetExpanderColumn(dataViewColumnPtr
);
829 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 int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn
const* columnPtr
) const
896 if (columnPtr
!= NULL
)
898 // variable definition and initialization:
899 DataBrowserTableViewColumnIndex Position
;
900 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
902 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetColumnIndex(columnPtr
->GetPropertyID(),&Position
) == noErr
,-1,_("Could not determine column's position"));
903 return static_cast<int>(Position
);
907 } /* wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const*) const */
909 void wxDataViewCtrl::Collapse(wxDataViewItem
const& item
)
911 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
914 MacDataViewListCtrlPtr
->CloseContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
915 } /* wxDataViewCtrl::Collapse(wxDataViewItem const&) */
917 void wxDataViewCtrl::EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
)
921 // variable definition and initialization:
922 DataBrowserPropertyID propertyID
;
923 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
925 if (columnPtr
!= NULL
)
926 propertyID
= columnPtr
->GetPropertyID();
928 propertyID
= kDataBrowserNoItem
;
929 MacDataViewListCtrlPtr
->RevealItem(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),propertyID
,kDataBrowserRevealOnly
);
931 } /* wxDataViewCtrl::EnsureVisible(wxDataViewItem const&, wxDataViewColumn const*) */
933 void wxDataViewCtrl::Expand(wxDataViewItem
const& item
)
935 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
938 MacDataViewListCtrlPtr
->OpenContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
939 } /* wxDataViewCtrl::Expand(wxDataViewItem const&) */
941 wxDataViewColumn
* wxDataViewCtrl::GetSortingColumn(void) const
943 DataBrowserPropertyID propertyID
;
945 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
948 if (MacDataViewListCtrlPtr
->GetSortProperty(&propertyID
) == noErr
)
949 return this->GetColumnPtr(propertyID
);
952 } /* wxDataViewCtrl::GetSortingColumn(void) const */
954 unsigned int wxDataViewCtrl::GetCount(void) const
959 wxCHECK_MSG(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
)->GetItemCount(&noOfItems
) == noErr
,0,_("Could not determine number of items"));
961 } /* wxDataViewCtrl::GetCount(void) const */
963 wxRect
wxDataViewCtrl::GetItemRect(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
) const
965 if (item
.IsOk() && (columnPtr
!= NULL
))
967 // variable definition:
969 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
971 if (MacDataViewListCtrlPtr
->GetPartBounds(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),columnPtr
->GetPropertyID(),kDataBrowserPropertyContentPart
,&MacRectangle
) == noErr
)
973 // variable definition:
976 ::wxMacNativeToRect(&MacRectangle
,&rectangle
);
984 } /* wxDataViewCtrl::GetItemRect(wxDataViewItem const&, unsigned int) const */
986 wxDataViewItem
wxDataViewCtrl::GetSelection(void) const
988 wxArrayDataBrowserItemID itemIDs
;
990 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
993 if (MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
) > 0)
994 return wxDataViewItem(reinterpret_cast<void*>(itemIDs
[0]));
996 return wxDataViewItem();
997 } /* wxDataViewCtrl::GetSelection(void) const */
999 int wxDataViewCtrl::GetSelections(wxDataViewItemArray
& sel
) const
1001 size_t NoOfSelectedItems
;
1003 wxArrayDataBrowserItemID itemIDs
;
1005 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1008 NoOfSelectedItems
= MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
);
1010 sel
.SetCount(NoOfSelectedItems
);
1011 for (size_t i
=0; i
<NoOfSelectedItems
; ++i
)
1012 sel
[i
] = wxDataViewItem(reinterpret_cast<void*>(itemIDs
[i
]));
1013 return static_cast<int>(NoOfSelectedItems
);
1014 } /* wxDataViewCtrl::GetSelections(wxDataViewItemArray&) const */
1016 void wxDataViewCtrl::HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const
1018 item
= wxDataViewItem();
1020 } /* wxDataViewCtrl::HitTest(wxPoint const&, wxDataViewItem&, wxDataViewColumn*&) const */
1022 bool wxDataViewCtrl::IsSelected(wxDataViewItem
const& item
) const
1024 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1027 return MacDataViewListCtrlPtr
->IsItemSelected(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1028 } /* wxDataViewCtrl::IsSelected(wxDataViewItem const&) const */
1030 void wxDataViewCtrl::SelectAll(void)
1032 DataBrowserItemID
* itemIDPtr
;
1034 Handle
handle(::NewHandle(0));
1038 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1041 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1042 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1044 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1045 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsAssign
);
1047 DisposeHandle(handle
);
1048 } /* wxDataViewCtrl::SelectAll(void) */
1050 void wxDataViewCtrl::Select(wxDataViewItem
const& item
)
1054 // variable definition and initialization:
1055 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1056 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1058 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsAdd
);
1060 } /* wxDataViewCtrl::Select(wxDataViewItem const&) */
1062 void wxDataViewCtrl::SetSelections(wxDataViewItemArray
const& sel
)
1064 size_t const NoOfSelections
= sel
.GetCount();
1066 DataBrowserItemID
* itemIDs
;
1068 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1071 itemIDs
= new DataBrowserItemID
[NoOfSelections
];
1072 for (size_t i
=0; i
<NoOfSelections
; ++i
)
1073 itemIDs
[i
] = reinterpret_cast<DataBrowserItemID
>(sel
[i
].GetID());
1074 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfSelections
,itemIDs
,kDataBrowserItemsAssign
);
1076 } /* wxDataViewCtrl::SetSelections(wxDataViewItemArray const&) */
1078 void wxDataViewCtrl::Unselect(wxDataViewItem
const& item
)
1082 // variable definition and initialization:
1083 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1084 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1086 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsRemove
);
1088 } /* wxDataViewCtrl::Unselect(wxDataViewItem const&) */
1090 void wxDataViewCtrl::UnselectAll(void)
1092 DataBrowserItemID
* itemIDPtr
;
1094 Handle
handle(::NewHandle(0));
1098 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1101 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1102 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1104 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1105 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsRemove
);
1107 DisposeHandle(handle
);
1108 } /* wxDataViewCtrl::UnselectAll(void) */
1111 void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem
const& parentItem
)
1115 wxDataViewItemArray items
;
1118 wxCHECK_RET(this->GetModel() != NULL
,_("Model pointer not initialized."));
1119 NoOfChildren
= this->GetModel()->GetChildren(parentItem
,items
);
1120 for (int i
=0; i
<NoOfChildren
; ++i
)
1121 (void) this->GetModel()->ItemAdded(parentItem
,items
[i
]);
1122 } /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
1124 wxDataViewColumn
* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID propertyID
) const
1126 // variable definition:
1127 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
1129 if (Result
!= this->m_ColumnPointers
.end())
1130 return Result
->second
;
1133 } /* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID) const */
1135 // inherited methods from wxDataViewCtrlBase
1136 void wxDataViewCtrl::DoSetExpanderColumn(void)
1138 if (this->GetExpanderColumn() != NULL
)
1140 // variable definition and initialization:
1141 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1143 (void) MacDataViewListCtrlPtr
->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID());
1145 } /* wxDataViewCtrl::DoSetExpanderColumn(void) */
1147 void wxDataViewCtrl::DoSetIndent(void)
1149 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1152 (void) MacDataViewListCtrlPtr
->SetIndent(static_cast<float>(this->GetIndent()));
1153 } /* wxDataViewCtrl::DoSetIndent(void) */
1156 void wxDataViewCtrl::OnSize(wxSizeEvent
& event
)
1158 unsigned int const NoOfColumns
= this->GetColumnCount();
1161 for (unsigned int i
=0; i
<NoOfColumns
; ++i
)
1163 // variable definition and initialization:
1164 wxDataViewColumn
* dataViewColumnPtr(this->GetColumn(i
));
1166 if (dataViewColumnPtr
!= NULL
)
1168 // variable definition and initialization:
1169 wxDataViewCustomRenderer
* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer()));
1171 if (dataViewCustomRendererPtr
!= NULL
)
1172 dataViewCustomRendererPtr
->SetDC(NULL
); // reset DC because DC has changed
1176 } /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
1178 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
,wxDataViewCtrlBase
)
1180 BEGIN_EVENT_TABLE(wxDataViewCtrl
,wxDataViewCtrlBase
)
1181 EVT_SIZE(wxDataViewCtrl::OnSize
)
1185 // !wxUSE_GENERICDATAVIEWCTRL
1188 // wxUSE_DATAVIEWCTRL