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 static DataBrowserItemID
* CreateDataBrowserItemIDArray(size_t& noOfEntries
, wxDataViewItemArray
const& items
) // returns a newly allocated pointer to valid data browser item IDs
97 size_t const noOfItems
= items
.GetCount();
99 DataBrowserItemID
* itemIDs(new DataBrowserItemID
[noOfItems
]);
102 // convert all valid data view items to data browser items
104 for (size_t i
=0; i
<noOfItems
; ++i
)
107 itemIDs
[noOfEntries
] = reinterpret_cast<DataBrowserItemID
>(items
[i
].GetID());
112 } /* CreateDataBrowserItemIDArray(size_t&, wxDataViewItemArray const&) */
114 //-----------------------------------------------------------------------------
115 // local function pointers
116 //-----------------------------------------------------------------------------
118 DEFINE_ONE_SHOT_HANDLER_GETTER(wxMacDataViewCtrlEventHandler
)
120 // ---------------------------------------------------------
121 // wxMacDataViewModelNotifier
122 // ---------------------------------------------------------
124 class wxMacDataViewModelNotifier
: public wxDataViewModelNotifier
127 wxMacDataViewModelNotifier(wxMacDataViewDataBrowserListViewControl
* initDataViewControlPtr
) : m_dataViewControlPtr(initDataViewControlPtr
)
131 virtual bool ItemAdded(const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
133 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
136 wxCHECK_MSG(item
.IsOk(),false,_("Added item is invalid."));
137 return (!(parent
.IsOk()) && (this->m_dataViewControlPtr
->AddItem(kDataBrowserNoItem
,&itemID
) == noErr
) ||
138 parent
.IsOk() && (this->m_dataViewControlPtr
->AddItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
) == noErr
));
139 } /* ItemAdded(wxDataViewItem const&, wxDataViewItem const&) */
141 virtual bool ItemsAdded(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
145 DataBrowserItemID
* itemIDs
;
150 // convert all valid data view items to data browser items:
151 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
152 // insert all valid items into control:
153 noFailureFlag
= ((noOfEntries
== 0) ||
154 !(parent
.IsOk()) && (this->m_dataViewControlPtr
->AddItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
) ||
155 parent
.IsOk() && (this->m_dataViewControlPtr
->AddItems(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
));
156 // give allocated array space free again:
159 return noFailureFlag
;
160 } /* ItemsAdded(wxDataViewItem const&, wxDataViewItemArray const&) */
162 virtual bool ItemChanged(wxDataViewItem
const& item
)
164 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
167 wxCHECK_MSG(item
.IsOk(),false,_("Changed item is invalid."));
168 if (this->m_dataViewControlPtr
->UpdateItems(&itemID
) == noErr
)
170 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
172 // sent the equivalent wxWidget event:
173 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId()); // variable defintion
175 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
176 dataViewEvent
.SetItem(item
);
177 // sent the equivalent wxWidget event:
178 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
184 } /* ItemChanged(wxDataViewItem const&) */
186 virtual bool ItemsChanged(wxDataViewItemArray
const& items
)
190 DataBrowserItemID
* itemIDs
;
195 // convert all valid data view items to data browser items:
196 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
197 // change items (ATTENTION: ONLY ITEMS OF THE ROOT ARE CHANGED BECAUSE THE PARENT PARAMETER IS MISSING):
198 noFailureFlag
= (this->m_dataViewControlPtr
->UpdateItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
,kDataBrowserItemNoProperty
) == noErr
);
201 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
203 // send for all changed items a wxWidget event:
204 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId()); // variable defintion
206 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
207 for (size_t i
=0; i
<noOfEntries
; ++i
)
209 dataViewEvent
.SetItem(reinterpret_cast<void*>(itemIDs
[i
]));
210 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
213 // release allocated array space:
216 return noFailureFlag
;
217 } /* ItemsChanged(wxDataViewItem const&) */
219 virtual bool ItemDeleted(wxDataViewItem
const& parent
, wxDataViewItem
const& item
)
223 // variable definition and initialization:
224 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
225 OSStatus errorStatus
;
226 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
228 // 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
229 // not to be identical because the being edited item might be below the passed item in the hierarchy);
230 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
231 // has been started and that variables can currently not be updated even when requested by the system:
232 dataViewCtrlPtr
->SetDeleting(true);
233 errorStatus
= this->m_dataViewControlPtr
->RemoveItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
);
234 // enable automatic updating again:
235 dataViewCtrlPtr
->SetDeleting(false);
236 return (errorStatus
== noErr
);
240 } /* ItemDeleted(wxDataViewItem const&, wxDataViewItem const&) */
242 virtual bool ItemsDeleted(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
246 DataBrowserItemID
* itemIDs
;
248 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
253 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,false,_("Data view control is not correctly initialized"));
254 // convert all valid data view items to data browser items:
255 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
256 // 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
257 // not to be identical because the being edited item might be below the passed item in the hierarchy);
258 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
259 // has been started and that variables can currently not be updated even when requested by the system:
260 dataViewCtrlPtr
->SetDeleting(true);
261 // insert all valid items into control:
262 noFailureFlag
= ((noOfEntries
== 0) ||
263 !(parent
.IsOk()) && (this->m_dataViewControlPtr
->RemoveItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
) ||
264 parent
.IsOk() && (this->m_dataViewControlPtr
->RemoveItems(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
));
265 // enable automatic updating again:
266 dataViewCtrlPtr
->SetDeleting(false);
267 // give allocated array space free again:
270 return noFailureFlag
;
271 } /* ItemsDeleted(wxDataViewItem const&, wxDataViewItemArray const&) */
273 virtual bool ValueChanged(wxDataViewItem
const& item
, unsigned int col
)
275 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
276 DataBrowserItemID parentID
;
278 DataBrowserPropertyID propertyID
;
280 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
283 wxCHECK_MSG(item
.IsOk(), false,_("Passed item is invalid."));
284 wxCHECK_MSG(this->GetOwner() != NULL
,false,_("Owner not initialized."));
285 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Control is wrongly initialized."));
286 parentID
= reinterpret_cast<DataBrowserItemID
>(this->GetOwner()->GetParent(item
).GetID());
287 if ((this->m_dataViewControlPtr
->GetPropertyID(col
,&propertyID
) == noErr
) &&
288 (this->m_dataViewControlPtr
->UpdateItems(parentID
,1,&itemID
,dataViewCtrlPtr
->GetColumn(col
)->GetPropertyID(),propertyID
) == noErr
))
290 // variable definition and initialization:
291 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId());
293 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
294 dataViewEvent
.SetColumn(col
);
295 dataViewEvent
.SetItem(item
);
296 // send the equivalent wxWidget event:
297 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
303 } /* ValueChanged(wxDataViewItem const&, unsigned int) */
305 virtual bool Cleared(void)
307 return (this->m_dataViewControlPtr
->RemoveItems() == noErr
);
308 } /* Cleared(void) */
310 virtual void Resort(void)
312 this->m_dataViewControlPtr
->Resort();
320 wxMacDataViewDataBrowserListViewControl
* m_dataViewControlPtr
;
323 // ---------------------------------------------------------
324 // wxDataViewRenderer
325 // ---------------------------------------------------------
327 wxDataViewRenderer::wxDataViewRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
328 :wxDataViewRendererBase(varianttype
,mode
,align
), m_alignment(align
), m_mode(mode
)
330 } /* wxDataViewRenderer::wxDataViewRenderer(wxString const&, wxDataViewCellMode) */
332 void wxDataViewRenderer::SetMode(wxDataViewCellMode mode
)
334 wxDataViewColumn
* dataViewColumnPtr
;
338 dataViewColumnPtr
= this->GetOwner();
339 if (dataViewColumnPtr
!= NULL
)
341 // variable definition and initialization:
342 wxDataViewCtrl
* dataViewCtrlPtr(dataViewColumnPtr
->GetOwner());
344 if (dataViewCtrlPtr
!= NULL
)
346 // variable definition and initialization:
347 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
349 if (macDataViewListCtrlPtr
!= NULL
)
351 // variable definition and initialization:
352 DataBrowserPropertyFlags flags
;
354 verify_noerr(macDataViewListCtrlPtr
->GetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),&flags
));
355 if (mode
== wxDATAVIEW_CELL_EDITABLE
)
356 flags
|= kDataBrowserPropertyIsEditable
;
358 flags
&= ~kDataBrowserPropertyIsEditable
;
359 verify_noerr(macDataViewListCtrlPtr
->SetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),flags
));
363 } /* wxDataViewRenderer::SetMode(wxDataViewCellMode) */
365 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
,wxDataViewRendererBase
)
367 // ---------------------------------------------------------
368 // wxDataViewCustomRenderer
369 // ---------------------------------------------------------
371 wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
372 :wxDataViewRenderer(varianttype
,mode
,align
), m_editorCtrlPtr(NULL
), m_DCPtr(NULL
)
374 } /* wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const&, wxDataViewCellMode) */
376 wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void)
378 if (this->m_DCPtr
!= NULL
)
379 delete this->m_DCPtr
;
380 } /* wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) */
382 wxDC
* wxDataViewCustomRenderer::GetDC(void)
384 if (this->m_DCPtr
== NULL
)
386 if ((GetOwner() == NULL
) || (GetOwner()->GetOwner() == NULL
))
388 this->m_DCPtr
= new wxClientDC(this->GetOwner()->GetOwner());
390 return this->m_DCPtr
;
391 } /* wxDataViewCustomRenderer::GetDC(void) */
393 bool wxDataViewCustomRenderer::Render(void)
396 } /* wxDataViewCustomRenderer::Render(void) */
398 void wxDataViewCustomRenderer::SetDC(wxDC
* newDCPtr
)
400 delete this->m_DCPtr
;
401 this->m_DCPtr
= newDCPtr
;
402 } /* wxDataViewCustomRenderer::SetDC(wxDC*) */
405 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
407 // ---------------------------------------------------------
408 // wxDataViewTextRenderer
409 // ---------------------------------------------------------
411 wxDataViewTextRenderer::wxDataViewTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
412 :wxDataViewRenderer(varianttype
,mode
,align
)
414 } /* wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const&, wxDataViewCellMode, int) */
416 bool wxDataViewTextRenderer::Render(void)
418 if (this->GetValue().GetType() == this->GetVariantType())
420 // variable definition:
421 wxMacCFStringHolder
cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
423 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
);
427 } /* wxDataViewTextRenderer::Render(void) */
429 IMPLEMENT_CLASS(wxDataViewTextRenderer
,wxDataViewRenderer
)
431 // ---------------------------------------------------------
432 // wxDataViewBitmapRenderer
433 // ---------------------------------------------------------
435 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
436 :wxDataViewRenderer(varianttype
,mode
,align
)
440 bool wxDataViewBitmapRenderer::Render(void)
442 if (this->GetValue().GetType() == this->GetVariantType())
446 bitmap
<< this->GetValue();
448 return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap
.GetBitmapData()->GetIconRef()) == noErr
);
454 } /* wxDataViewBitmapRenderer::Render(void) */
456 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
,wxDataViewRenderer
)
458 // ---------------------------------------------------------
459 // wxDataViewIconTextRenderer
460 // ---------------------------------------------------------
462 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
463 :wxDataViewRenderer(varianttype
,mode
)
467 bool wxDataViewIconTextRenderer::Render(void)
469 if (this->GetValue().GetType() == this->GetVariantType())
471 // variable definition:
472 wxDataViewIconText iconText
;
474 iconText
<< this->GetValue();
476 // variable definition:
477 wxMacCFStringHolder
cfString(iconText
.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
479 return ((::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText
.GetIcon().GetHICON())) == noErr
) &&
480 (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
));
484 } /* wxDataViewIconTextRenderer::Render(void) */
486 IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer
,wxDataViewRenderer
)
489 // ---------------------------------------------------------
490 // wxDataViewToggleRenderer
491 // ---------------------------------------------------------
493 wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
494 :wxDataViewRenderer(varianttype
,mode
)
498 bool wxDataViewToggleRenderer::Render(void)
500 if (this->GetValue().GetType() == this->GetVariantType())
501 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr
);
504 } /* wxDataViewToggleRenderer::Render(void) */
506 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
,wxDataViewRenderer
)
508 // ---------------------------------------------------------
509 // wxDataViewProgressRenderer
510 // ---------------------------------------------------------
512 wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString
const& label
, wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
513 :wxDataViewRenderer(varianttype
,mode
,align
)
517 bool wxDataViewProgressRenderer::Render(void)
519 if (this->GetValue().GetType() == this->GetVariantType())
520 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr
) &&
521 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr
) &&
522 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr
));
525 } /* wxDataViewProgressRenderer::Render(void) */
527 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
,wxDataViewRenderer
)
529 // ---------------------------------------------------------
530 // wxDataViewDateRenderer
531 // ---------------------------------------------------------
533 wxDataViewDateRenderer::wxDataViewDateRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
534 :wxDataViewRenderer(varianttype
,mode
,align
)
538 bool wxDataViewDateRenderer::Render(void)
540 if (this->GetValue().GetType() == this->GetVariantType())
541 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan
,1904)).GetSeconds().GetLo()) == noErr
);
544 } /* wxDataViewDateRenderer::Render(void) */
546 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
,wxDataViewRenderer
)
548 // ---------------------------------------------------------
550 // ---------------------------------------------------------
552 wxDataViewColumn::wxDataViewColumn(wxString
const &title
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
553 :wxDataViewColumnBase(title
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
554 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
)), m_maxWidth(30000), m_minWidth(0), m_width(width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
),
555 m_alignment(align
), m_title(title
)
557 } /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
559 wxDataViewColumn::wxDataViewColumn(wxBitmap
const& bitmap
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
560 :wxDataViewColumnBase(bitmap
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
561 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
)), m_maxWidth(30000), m_minWidth(0), m_width(width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
),
564 } /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
566 void wxDataViewColumn::SetAlignment(wxAlignment align
)
568 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
571 this->m_alignment
= align
;
572 if (dataViewCtrlPtr
!= NULL
)
574 // variable definition and initialization:
575 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
577 if (macDataViewListCtrlPtr
!= NULL
)
579 // variable definition and initialization:
580 DataBrowserListViewHeaderDesc headerDescription
;
582 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
586 case wxALIGN_CENTER_HORIZONTAL
:
587 headerDescription
.btnFontStyle
.just
= teCenter
;
590 headerDescription
.btnFontStyle
.just
= teFlushLeft
;
593 headerDescription
.btnFontStyle
.just
= teFlushRight
;
596 headerDescription
.btnFontStyle
.just
= teFlushDefault
;
598 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set alignment."));
601 } /* wxDataViewColumn::SetAlignment(wxAlignment) */
603 void wxDataViewColumn::SetBitmap(wxBitmap
const& bitmap
)
605 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
608 wxDataViewColumnBase::SetBitmap(bitmap
);
609 if (dataViewCtrlPtr
!= NULL
)
611 // variable definition and initialization:
612 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
614 if (macDataViewListCtrlPtr
!= NULL
)
616 // variable definition and initialization:
617 DataBrowserListViewHeaderDesc headerDescription
;
619 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
620 if (this->GetBitmap().Ok())
621 headerDescription
.btnContentInfo
.u
.iconRef
= this->GetBitmap().GetBitmapData()->GetIconRef();
623 headerDescription
.btnContentInfo
.u
.iconRef
= NULL
;
624 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set icon."));
627 } /* wxDataViewColumn::SetBitmap(wxBitmap const&) */
629 void wxDataViewColumn::SetFlags(int flags
)
631 this->SetHidden ((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
632 this->SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
633 this->SetSortable ((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
634 } /* wxDataViewColumn::SetFlags(int) */
636 void wxDataViewColumn::SetMaxWidth(int maxWidth
)
638 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
641 this->m_maxWidth
= maxWidth
;
642 if (dataViewCtrlPtr
!= NULL
)
644 // variable definition and initialization:
645 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
647 if (macDataViewListCtrlPtr
!= NULL
)
649 // variable definition and initialization:
650 DataBrowserListViewHeaderDesc headerDescription
;
652 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
653 headerDescription
.maximumWidth
= static_cast<UInt16
>(maxWidth
);
654 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set maximum width."));
657 } /* wxDataViewColumn::SetMaxWidth(int) */
659 void wxDataViewColumn::SetMinWidth(int minWidth
)
661 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
664 this->m_minWidth
= minWidth
;
665 if (dataViewCtrlPtr
!= NULL
)
667 // variable definition and initialization:
668 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
670 if (macDataViewListCtrlPtr
!= NULL
)
672 // variable definition and initialization:
673 DataBrowserListViewHeaderDesc headerDescription
;
675 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
676 headerDescription
.minimumWidth
= static_cast<UInt16
>(minWidth
);
677 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set minimum width."));
680 } /* wxDataViewColumn::SetMaxWidth(int) */
682 void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable
))
684 } /* wxDataViewColumn::SetResizeable(bool) */
686 void wxDataViewColumn::SetSortable(bool sortable
)
688 // variable definition and initialization:
689 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
691 if (dataViewCtrlPtr
!= NULL
)
693 // variable definition and initialization:
694 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
696 if (macDataViewListCtrlPtr
!= NULL
)
698 // variable definition and initialization:
699 DataBrowserPropertyFlags flags
;
701 wxCHECK_RET(macDataViewListCtrlPtr
->GetPropertyFlags(this->GetPropertyID(),&flags
) == noErr
,_("Could not get property flags."));
704 this->m_flags
|= wxDATAVIEW_COL_SORTABLE
;
705 flags
|= kDataBrowserListViewSortableColumn
;
709 this->m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
710 flags
&= ~kDataBrowserPropertyIsEditable
;
712 wxCHECK_RET(macDataViewListCtrlPtr
->SetPropertyFlags(this->GetPropertyID(),flags
) == noErr
,_("Could not set property flags."));
715 } /* wxDataViewColumn::SetSortable(bool) */
717 void wxDataViewColumn::SetSortOrder(bool ascending
)
719 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
722 this->m_ascending
= ascending
;
723 if (dataViewCtrlPtr
!= NULL
)
725 // variable definition and initialization:
726 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
728 if (macDataViewListCtrlPtr
!= NULL
)
730 // variable definition and initialization:
731 DataBrowserListViewHeaderDesc headerDescription
;
733 verify_noerr(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
));
735 headerDescription
.initialOrder
= kDataBrowserOrderIncreasing
;
737 headerDescription
.initialOrder
= kDataBrowserOrderDecreasing
;
738 verify_noerr(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
));
739 macDataViewListCtrlPtr
->SetSortProperty(this->GetPropertyID());
742 } /* wxDataViewColumn::SetSortOrder(bool) */
744 void wxDataViewColumn::SetTitle(wxString
const& title
)
746 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
749 this->m_title
= title
;
750 if (dataViewCtrlPtr
!= NULL
)
752 // variable definition and initialization:
753 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
755 if (macDataViewListCtrlPtr
!= NULL
)
757 // variable definition and initialization:
758 DataBrowserListViewHeaderDesc headerDescription
;
759 wxMacCFStringHolder
cfTitle(title
,(dataViewCtrlPtr
->GetFont().Ok() ? dataViewCtrlPtr
->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
761 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
762 headerDescription
.titleString
= cfTitle
;
763 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set header description."));
766 } /* wxDataViewColumn::SetTitle(wxString const&) */
768 void wxDataViewColumn::SetWidth(int width
)
770 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
773 if ((width
>= this->m_minWidth
) && (width
<= this->m_maxWidth
))
775 this->m_width
= width
;
776 if (dataViewCtrlPtr
!= NULL
)
778 // variable definition and initialization:
779 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
781 if (macDataViewListCtrlPtr
!= NULL
)
782 wxCHECK_RET(macDataViewListCtrlPtr
->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16
>(width
)) == noErr
,_("Could not set column width."));
785 } /* wxDataViewColumn::SetWidth(int) */
787 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
,wxDataViewColumnBase
)
789 //-----------------------------------------------------------------------------
791 //-----------------------------------------------------------------------------
793 void wxDataViewCtrl::Init(void)
795 this->m_Deleting
= false;
796 this->m_macIsUserPane
= false;
797 this->m_cgContext
= NULL
;
798 } /* wxDataViewCtrl::Init(void) */
800 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
802 if (!(this->wxControl::Create(parent
,id
,pos
,size
,(style
| wxSUNKEN_BORDER
) & ~(wxHSCROLL
| wxVSCROLL
),validator
)))
806 MacSetClipChildren(true) ;
809 this->m_peer
= new wxMacDataViewDataBrowserListViewControl(this,pos
,size
,style
);
810 this->MacPostControlCreate(pos
,size
);
811 ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(this->m_peer
->GetControlRef()),true);
813 InstallControlEventHandler(this->m_peer
->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList
),eventList
,this,NULL
);
816 } /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
818 bool wxDataViewCtrl::AssociateModel(wxDataViewModel
* model
)
820 if (!wxDataViewCtrlBase::AssociateModel(model
))
823 model
->AddNotifier(new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl
*>(this->m_peer
)));
826 } /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
828 bool wxDataViewCtrl::AppendColumn(wxDataViewColumn
* dataViewColumnPtr
)
830 DataBrowserPropertyID NewPropertyID
;
832 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
835 // first, some error checking:
836 wxCHECK_MSG(MacDataViewListCtrlPtr
!= NULL
, false,_("m_peer is not or incorrectly initialized"));
837 wxCHECK_MSG(dataViewColumnPtr
!= NULL
, false,_("Column pointer must not be NULL."));
838 wxCHECK_MSG(dataViewColumnPtr
->GetRenderer() != NULL
, false,_("Column does not have a renderer."));
839 wxCHECK_MSG(this->GetModel() != NULL
, false,_("No model associated with control."));
840 wxCHECK_MSG((dataViewColumnPtr
->GetModelColumn() >= 0) &&
841 (dataViewColumnPtr
->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
842 if ((MacDataViewListCtrlPtr
->GetFreePropertyID(&NewPropertyID
) == noErr
) && this->wxDataViewCtrlBase::AppendColumn(dataViewColumnPtr
))
844 // insert column into hash map:
845 this->m_ColumnPointers
.insert(ColumnPointerHashMapType::value_type(NewPropertyID
,dataViewColumnPtr
));
847 // variable definitions:
848 DataBrowserListViewColumnDesc columnDescription
;
849 wxMacCFStringHolder
cfTitle(dataViewColumnPtr
->GetTitle(),(this->m_font
.Ok() ? this->m_font
.GetEncoding() : wxLocale::GetSystemEncoding()));
851 // initialize column description:
852 dataViewColumnPtr
->SetPropertyID(NewPropertyID
);
853 columnDescription
.propertyDesc
.propertyID
= NewPropertyID
;
854 columnDescription
.propertyDesc
.propertyType
= dataViewColumnPtr
->GetRenderer()->GetPropertyType();
855 columnDescription
.propertyDesc
.propertyFlags
= kDataBrowserListViewSelectionColumn
; // make the column selectable
856 if (dataViewColumnPtr
->IsSortable())
857 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewSortableColumn
;
859 if (dataViewColumnPtr
->IsMovable())
860 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewMovableColumn
;
862 if (dataViewColumnPtr
->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE
)
863 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserPropertyIsEditable
;
864 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
865 if ((columnDescription
.propertyDesc
.propertyType
== kDataBrowserTextType
) ||
866 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserIconAndTextType
) ||
867 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserDateTimeType
))
868 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
870 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
871 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
873 columnDescription
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
874 if (dataViewColumnPtr
->IsResizeable())
876 columnDescription
.headerBtnDesc
.minimumWidth
= 0;
877 columnDescription
.headerBtnDesc
.maximumWidth
= 30000;
881 columnDescription
.headerBtnDesc
.minimumWidth
= dataViewColumnPtr
->GetWidth();
882 columnDescription
.headerBtnDesc
.maximumWidth
= dataViewColumnPtr
->GetWidth();
884 columnDescription
.headerBtnDesc
.titleOffset
= 0;
885 columnDescription
.headerBtnDesc
.titleString
= cfTitle
; // we cannot directly use the wxMacCFStringHolder constructor call because then the CFStringRef is released
886 // having called 'AddColumn' where the title (CFStringRef) is going to be used
887 columnDescription
.headerBtnDesc
.initialOrder
= kDataBrowserOrderIncreasing
;
888 columnDescription
.headerBtnDesc
.btnFontStyle
.flags
= kControlUseFontMask
| kControlUseJustMask
;
889 switch (dataViewColumnPtr
->GetAlignment())
892 case wxALIGN_CENTER_HORIZONTAL
:
893 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teCenter
;
896 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushLeft
;
899 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushRight
;
902 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
904 columnDescription
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
905 columnDescription
.headerBtnDesc
.btnFontStyle
.style
= normal
;
906 columnDescription
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
907 if (dataViewColumnPtr
->GetBitmap().Ok())
908 columnDescription
.headerBtnDesc
.btnContentInfo
.u
.iconRef
= dataViewColumnPtr
->GetBitmap().GetBitmapData()->GetIconRef();
910 wxCHECK_MSG(MacDataViewListCtrlPtr
->AddColumn(&columnDescription
,kDataBrowserListViewAppendColumn
) == noErr
,false,_("Column could not be added."));
912 // final adjustments for the layout:
913 wxCHECK_MSG(MacDataViewListCtrlPtr
->SetColumnWidth(NewPropertyID
,dataViewColumnPtr
->GetWidth()) == noErr
,false,_("Column width could not be set."));
915 // make sure that the data is up-to-date...
916 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
917 // otherwise ask the control to 'update' the data in the newly appended column:
918 if (this->GetColumnCount() == 1)
920 this->SetExpanderColumn(dataViewColumnPtr
);
921 this->AddChildrenLevel(wxDataViewItem());
924 MacDataViewListCtrlPtr
->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,NewPropertyID
);
930 } /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
932 bool wxDataViewCtrl::ClearColumns(void)
934 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
937 while (this->m_ColumnPointers
.begin() != this->m_ColumnPointers
.end())
939 wxCHECK_MSG(MacDataViewListCtrlPtr
->RemoveColumnByProperty(this->m_ColumnPointers
.begin()->first
) == noErr
,false,_("Could not remove column."));
940 delete this->m_ColumnPointers
.begin()->second
;
941 this->m_ColumnPointers
.erase(this->m_ColumnPointers
.begin());
944 } /* wxDataViewCtrl::ClearColumns(void) */
946 bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn
* columnPtr
)
948 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
951 if ((MacDataViewListCtrlPtr
->RemoveColumnByProperty(columnPtr
->GetPropertyID()) == noErr
) && (this->m_ColumnPointers
.erase(columnPtr
->GetPropertyID()) > 0))
958 } /* wxDataViewCtrl::DeleteColumn(wxDataViewColumn*) */
960 wxDataViewColumn
* wxDataViewCtrl::GetColumn(unsigned int pos
) const
962 DataBrowserPropertyID propertyID
;
964 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
967 if (MacDataViewListCtrlPtr
->GetPropertyID(pos
,&propertyID
) == noErr
)
969 // variable definition:
970 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
972 if (Result
!= this->m_ColumnPointers
.end())
973 return Result
->second
;
979 } /* wxDataViewCtrl::GetColumn(unsigned int pos) const */
981 unsigned int wxDataViewCtrl::GetColumnCount(void) const
983 return this->m_ColumnPointers
.size();
984 } /* wxDataViewCtrl::GetColumnCount(void) const */
986 int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn
const* columnPtr
) const
988 if (columnPtr
!= NULL
)
990 // variable definition and initialization:
991 DataBrowserTableViewColumnIndex Position
;
992 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
994 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetColumnIndex(columnPtr
->GetPropertyID(),&Position
) == noErr
,-1,_("Could not determine column's position"));
995 return static_cast<int>(Position
);
999 } /* wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const*) const */
1001 void wxDataViewCtrl::Collapse(wxDataViewItem
const& item
)
1003 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1006 MacDataViewListCtrlPtr
->CloseContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1007 } /* wxDataViewCtrl::Collapse(wxDataViewItem const&) */
1009 void wxDataViewCtrl::EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
)
1013 // variable definition and initialization:
1014 DataBrowserPropertyID propertyID
;
1015 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1017 if (columnPtr
!= NULL
)
1018 propertyID
= columnPtr
->GetPropertyID();
1020 propertyID
= kDataBrowserNoItem
;
1021 MacDataViewListCtrlPtr
->RevealItem(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),propertyID
,kDataBrowserRevealOnly
);
1023 } /* wxDataViewCtrl::EnsureVisible(wxDataViewItem const&, wxDataViewColumn const*) */
1025 void wxDataViewCtrl::Expand(wxDataViewItem
const& item
)
1027 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1030 MacDataViewListCtrlPtr
->OpenContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1031 } /* wxDataViewCtrl::Expand(wxDataViewItem const&) */
1033 wxDataViewColumn
* wxDataViewCtrl::GetSortingColumn(void) const
1035 DataBrowserPropertyID propertyID
;
1037 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1040 if (MacDataViewListCtrlPtr
->GetSortProperty(&propertyID
) == noErr
)
1041 return this->GetColumnPtr(propertyID
);
1044 } /* wxDataViewCtrl::GetSortingColumn(void) const */
1046 unsigned int wxDataViewCtrl::GetCount(void) const
1048 ItemCount noOfItems
;
1051 wxCHECK_MSG(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
)->GetItemCount(&noOfItems
) == noErr
,0,_("Could not determine number of items"));
1053 } /* wxDataViewCtrl::GetCount(void) const */
1055 wxRect
wxDataViewCtrl::GetItemRect(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
) const
1057 if (item
.IsOk() && (columnPtr
!= NULL
))
1059 // variable definition:
1061 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1063 if (MacDataViewListCtrlPtr
->GetPartBounds(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),columnPtr
->GetPropertyID(),kDataBrowserPropertyContentPart
,&MacRectangle
) == noErr
)
1065 // variable definition:
1068 ::wxMacNativeToRect(&MacRectangle
,&rectangle
);
1076 } /* wxDataViewCtrl::GetItemRect(wxDataViewItem const&, unsigned int) const */
1078 wxDataViewItem
wxDataViewCtrl::GetSelection(void) const
1080 wxArrayDataBrowserItemID itemIDs
;
1082 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1085 if (MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
) > 0)
1086 return wxDataViewItem(reinterpret_cast<void*>(itemIDs
[0]));
1088 return wxDataViewItem();
1089 } /* wxDataViewCtrl::GetSelection(void) const */
1091 int wxDataViewCtrl::GetSelections(wxDataViewItemArray
& sel
) const
1093 size_t NoOfSelectedItems
;
1095 wxArrayDataBrowserItemID itemIDs
;
1097 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1100 NoOfSelectedItems
= MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
);
1102 sel
.SetCount(NoOfSelectedItems
);
1103 for (size_t i
=0; i
<NoOfSelectedItems
; ++i
)
1104 sel
[i
] = wxDataViewItem(reinterpret_cast<void*>(itemIDs
[i
]));
1105 return static_cast<int>(NoOfSelectedItems
);
1106 } /* wxDataViewCtrl::GetSelections(wxDataViewItemArray&) const */
1108 void wxDataViewCtrl::HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const
1110 item
= wxDataViewItem();
1112 } /* wxDataViewCtrl::HitTest(wxPoint const&, wxDataViewItem&, wxDataViewColumn*&) const */
1114 bool wxDataViewCtrl::IsSelected(wxDataViewItem
const& item
) const
1116 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1119 return MacDataViewListCtrlPtr
->IsItemSelected(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1120 } /* wxDataViewCtrl::IsSelected(wxDataViewItem const&) const */
1122 void wxDataViewCtrl::SelectAll(void)
1124 DataBrowserItemID
* itemIDPtr
;
1126 Handle
handle(::NewHandle(0));
1130 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1133 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1134 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1136 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1137 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsAssign
);
1139 DisposeHandle(handle
);
1140 } /* wxDataViewCtrl::SelectAll(void) */
1142 void wxDataViewCtrl::Select(wxDataViewItem
const& item
)
1146 // variable definition and initialization:
1147 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1148 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1150 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsAdd
);
1152 } /* wxDataViewCtrl::Select(wxDataViewItem const&) */
1154 void wxDataViewCtrl::SetSelections(wxDataViewItemArray
const& sel
)
1156 size_t const NoOfSelections
= sel
.GetCount();
1158 DataBrowserItemID
* itemIDs
;
1160 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1163 itemIDs
= new DataBrowserItemID
[NoOfSelections
];
1164 for (size_t i
=0; i
<NoOfSelections
; ++i
)
1165 itemIDs
[i
] = reinterpret_cast<DataBrowserItemID
>(sel
[i
].GetID());
1166 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfSelections
,itemIDs
,kDataBrowserItemsAssign
);
1168 } /* wxDataViewCtrl::SetSelections(wxDataViewItemArray const&) */
1170 void wxDataViewCtrl::Unselect(wxDataViewItem
const& item
)
1174 // variable definition and initialization:
1175 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1176 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1178 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsRemove
);
1180 } /* wxDataViewCtrl::Unselect(wxDataViewItem const&) */
1182 void wxDataViewCtrl::UnselectAll(void)
1184 DataBrowserItemID
* itemIDPtr
;
1186 Handle
handle(::NewHandle(0));
1190 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1193 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1194 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1196 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1197 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsRemove
);
1199 DisposeHandle(handle
);
1200 } /* wxDataViewCtrl::UnselectAll(void) */
1203 void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem
const& parentItem
)
1207 wxDataViewItemArray items
;
1210 wxCHECK_RET(this->GetModel() != NULL
,_("Model pointer not initialized."));
1211 NoOfChildren
= this->GetModel()->GetChildren(parentItem
,items
);
1213 for (int i
=0; i
<NoOfChildren
; ++i
)
1214 (void) this->GetModel()->ItemAdded(parentItem
,items
[i
]);
1216 (void) this->GetModel()->ItemsAdded(parentItem
,items
);
1218 } /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
1220 wxDataViewColumn
* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID propertyID
) const
1222 // variable definition:
1223 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
1225 if (Result
!= this->m_ColumnPointers
.end())
1226 return Result
->second
;
1229 } /* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID) const */
1231 // inherited methods from wxDataViewCtrlBase
1232 void wxDataViewCtrl::DoSetExpanderColumn(void)
1234 if (this->GetExpanderColumn() != NULL
)
1236 // variable definition and initialization:
1237 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1239 (void) MacDataViewListCtrlPtr
->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID());
1241 } /* wxDataViewCtrl::DoSetExpanderColumn(void) */
1243 void wxDataViewCtrl::DoSetIndent(void)
1245 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1248 (void) MacDataViewListCtrlPtr
->SetIndent(static_cast<float>(this->GetIndent()));
1249 } /* wxDataViewCtrl::DoSetIndent(void) */
1252 void wxDataViewCtrl::OnSize(wxSizeEvent
& event
)
1254 unsigned int const NoOfColumns
= this->GetColumnCount();
1257 for (unsigned int i
=0; i
<NoOfColumns
; ++i
)
1259 // variable definition and initialization:
1260 wxDataViewColumn
* dataViewColumnPtr(this->GetColumn(i
));
1262 if (dataViewColumnPtr
!= NULL
)
1264 // variable definition and initialization:
1265 wxDataViewCustomRenderer
* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer()));
1267 if (dataViewCustomRendererPtr
!= NULL
)
1268 dataViewCustomRendererPtr
->SetDC(NULL
); // reset DC because DC has changed
1272 } /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
1274 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
,wxDataViewCtrlBase
)
1276 BEGIN_EVENT_TABLE(wxDataViewCtrl
,wxDataViewCtrlBase
)
1277 EVT_SIZE(wxDataViewCtrl::OnSize
)
1281 // !wxUSE_GENERICDATAVIEWCTRL
1284 // wxUSE_DATAVIEWCTRL