1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/databrow.cpp
3 // Purpose: Classes and functions for the Carbon data browser
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef wxUSE_GENERICDATAVIEWCTRL
21 #include "wx/wxprec.h"
27 #include "wx/toplevel.h"
31 #include "wx/apptrait.h"
33 #include "wx/mac/uma.h"
37 #include <Carbon/Carbon.h>
39 #include <ATSUnicode.h>
40 #include <TextCommon.h>
41 #include <TextEncodingConverter.h>
44 #include "wx/mac/private.h"
46 #if defined(__MWERKS__) && wxUSE_UNICODE
47 #if __MWERKS__ < 0x4100 || !defined(__DARWIN__)
54 #include "wx/mac/carbon/databrow.h"
56 #include "wx/dataview.h"
58 // ============================================================================
59 // wxMacDataBrowserTableViewControl
60 // ============================================================================
62 pascal Boolean
wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlRef browser
, DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
)
64 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
67 if (ControlPtr
!= NULL
)
68 return ControlPtr
->DataBrowserCompareProc(itemOneID
,itemTwoID
,sortProperty
);
70 return errDataBrowserPropertyNotSupported
;
71 } /* wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlRef, DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
73 pascal void wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID property
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
)
75 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
78 if (ControlPtr
!= NULL
)
79 ControlPtr
->DataBrowserDrawItemProc(itemID
,property
,state
,rectangle
,bitDepth
,colorDevice
);
80 } /* wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */
82 pascal OSStatus
wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID property
, DataBrowserItemDataRef itemData
, Boolean getValue
)
84 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
87 if (ControlPtr
!= NULL
)
88 return ControlPtr
->DataBrowserGetSetItemDataProc(itemID
,property
,itemData
,getValue
);
90 return errDataBrowserPropertyNotSupported
;
91 } /* wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */
93 pascal void wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
)
95 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
98 if (ControlPtr
!= NULL
)
99 ControlPtr
->DataBrowserItemNotificationProc(itemID
,message
,itemData
);
100 } /* wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc(ControlRef, DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */
102 DataBrowserDrawItemUPP gDataBrowserTableViewDrawItemUPP
= NULL
;
103 DataBrowserItemCompareUPP gDataBrowserTableViewItemCompareUPP
= NULL
;
104 DataBrowserItemDataUPP gDataBrowserTableViewItemDataUPP
= NULL
;
105 DataBrowserItemNotificationUPP gDataBrowserTableViewItemNotificationUPP
= NULL
;
107 wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow
* peer
, wxPoint
const& pos
, wxSize
const& size
, long style
)
110 Rect bounds
= wxMacGetBoundsForControl(peer
,pos
,size
);
111 OSStatus err
= ::CreateDataBrowserControl(MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),&bounds
,kDataBrowserListView
,&(this->m_controlRef
));
114 SetReferenceInNativeControl();
116 if (gDataBrowserTableViewDrawItemUPP
== NULL
) gDataBrowserTableViewDrawItemUPP
= NewDataBrowserDrawItemUPP (DataBrowserDrawItemProc
);
117 if (gDataBrowserTableViewItemCompareUPP
== NULL
) gDataBrowserTableViewItemCompareUPP
= NewDataBrowserItemCompareUPP(wxMacDataBrowserTableViewControl::DataBrowserCompareProc
);
118 if (gDataBrowserTableViewItemDataUPP
== NULL
) gDataBrowserTableViewItemDataUPP
= NewDataBrowserItemDataUPP (wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc
);
119 if (gDataBrowserTableViewItemNotificationUPP
== NULL
)
121 gDataBrowserTableViewItemNotificationUPP
=
122 #if TARGET_API_MAC_OSX
123 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc
);
125 NewDataBrowserItemNotificationUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc
);
129 DataBrowserCallbacks callbacks
;
130 DataBrowserCustomCallbacks customCallbacks
;
132 InitializeDataBrowserCallbacks (&callbacks
, kDataBrowserLatestCallbacks
);
133 InitializeDataBrowserCustomCallbacks(&customCallbacks
,kDataBrowserLatestCallbacks
);
135 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserTableViewItemDataUPP
;
136 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserTableViewItemCompareUPP
;
137 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserTableViewItemNotificationUPP
;
138 this->SetCallbacks(&callbacks
);
140 customCallbacks
.u
.v1
.drawItemCallback
= gDataBrowserTableViewDrawItemUPP
;
141 this->SetCustomCallbacks(&customCallbacks
);
144 this->EnableCellSizeModification();
146 DataBrowserSelectionFlags flags
; // variable definition
148 if (this->GetSelectionFlags(&flags
) == noErr
) // get default settings
150 if ((style
& wxDV_MULTIPLE
) != 0)
151 flags
&= ~kDataBrowserSelectOnlyOne
;
153 flags
|= kDataBrowserSelectOnlyOne
;
154 (void) this->SetSelectionFlags(flags
);
156 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
157 OptionBits attributes
; // variable definition
159 if (this->GetAttributes(&attributes
) == noErr
) // get default settings
161 if ((style
& wxDV_VERT_RULES
) != 0)
162 attributes
|= kDataBrowserAttributeListViewDrawColumnDividers
;
164 attributes
&= ~kDataBrowserAttributeListViewDrawColumnDividers
;
165 (void) this->SetAttributes(attributes
);
168 if ((style
& wxDV_NO_HEADER
) != 0)
169 this->SetHeaderButtonHeight(0);
170 } /* wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow*, wxPoint const&, wxSize const&, long) */
175 OSStatus
wxMacDataBrowserTableViewControl::SetCallbacks(DataBrowserCallbacks
const* callbacks
)
177 return ::SetDataBrowserCallbacks(this->m_controlRef
,callbacks
);
178 } /* wxMacDataBrowserTableViewControl::SetCallbacks(DataBrowserCallbacks const*) */
180 OSStatus
wxMacDataBrowserTableViewControl::SetCustomCallbacks(DataBrowserCustomCallbacks
const* customCallbacks
)
182 return ::SetDataBrowserCustomCallbacks(this->m_controlRef
,customCallbacks
);
183 } /* xMacDataBrowserTableViewControl::SetCustomCallbacks(DataBrowserCustomCallbacks const*) */
188 OSStatus
wxMacDataBrowserTableViewControl::GetHeaderDesc(DataBrowserPropertyID property
, DataBrowserListViewHeaderDesc
* desc
) const
190 desc
->version
= kDataBrowserListViewLatestHeaderDesc
; // if this statement is missing the next call will fail (NOT DOCUMENTED!!)
191 return ::GetDataBrowserListViewHeaderDesc(this->m_controlRef
,property
,desc
);
194 OSStatus
wxMacDataBrowserTableViewControl::SetHeaderDesc(DataBrowserPropertyID property
, DataBrowserListViewHeaderDesc
* desc
)
196 return ::SetDataBrowserListViewHeaderDesc(this->m_controlRef
,property
,desc
);
202 OSStatus
wxMacDataBrowserTableViewControl::AutoSizeColumns()
204 return AutoSizeDataBrowserListViewColumns(this->m_controlRef
);
207 OSStatus
wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool enableHeight
, bool enableWidth
)
209 return ::SetDataBrowserTableViewGeometry(this->GetControlRef(),enableWidth
,enableHeight
);
210 } /* wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool, bool) */
212 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
213 OSStatus
wxMacDataBrowserTableViewControl::GetAttributes(OptionBits
* attributes
)
215 return ::DataBrowserGetAttributes(this->GetControlRef(),attributes
);
216 } /* wxMacDataBrowserTableViewControl::GetAttributes(OptionBits*) */
219 OSStatus
wxMacDataBrowserTableViewControl::GetColumnWidth(DataBrowserPropertyID propertyID
, UInt16
* width
) const
221 return ::GetDataBrowserTableViewNamedColumnWidth(this->m_controlRef
,propertyID
,width
);
224 OSStatus
wxMacDataBrowserTableViewControl::GetDefaultRowHeight(UInt16
* height
) const
226 return ::GetDataBrowserTableViewRowHeight(this->m_controlRef
,height
);
229 OSStatus
wxMacDataBrowserTableViewControl::GetHeaderButtonHeight(UInt16
*height
)
231 return ::GetDataBrowserListViewHeaderBtnHeight(this->m_controlRef
,height
);
234 OSStatus
wxMacDataBrowserTableViewControl::GetDefaultColumnWidth( UInt16
*width
) const
236 return GetDataBrowserTableViewColumnWidth(this->m_controlRef
, width
);
239 OSStatus
wxMacDataBrowserTableViewControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
241 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
244 OSStatus
wxMacDataBrowserTableViewControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
246 return GetDataBrowserScrollPosition(this->m_controlRef
, top
, left
);
249 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
250 OSStatus
wxMacDataBrowserTableViewControl::SetAttributes(OptionBits attributes
)
252 return ::DataBrowserChangeAttributes(this->GetControlRef(),attributes
,~attributes
);
253 } /* wxMacDataBrowserTableViewControl::SetAttributes(OptionBits) */
256 OSStatus
wxMacDataBrowserTableViewControl::SetColumnWidth(DataBrowserPropertyID propertyID
, UInt16 width
)
258 return ::SetDataBrowserTableViewNamedColumnWidth(this->m_controlRef
,propertyID
,width
);
261 OSStatus
wxMacDataBrowserTableViewControl::SetDefaultColumnWidth(UInt16 width
)
263 return ::SetDataBrowserTableViewColumnWidth(this->m_controlRef
,width
);
266 OSStatus
wxMacDataBrowserTableViewControl::SetDefaultRowHeight(UInt16 height
)
268 return ::SetDataBrowserTableViewRowHeight(this->m_controlRef
,height
);
271 OSStatus
wxMacDataBrowserTableViewControl::SetHasScrollBars( bool horiz
, bool vert
)
273 return SetDataBrowserHasScrollBars(this->m_controlRef
, horiz
, vert
);
276 OSStatus
wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16 height
)
278 return SetDataBrowserListViewHeaderBtnHeight(this->m_controlRef
, height
);
281 OSStatus
wxMacDataBrowserTableViewControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
283 return SetDataBrowserTableViewHiliteStyle(this->m_controlRef
, hiliteStyle
);
286 OSStatus
wxMacDataBrowserTableViewControl::SetRowHeight(DataBrowserItemID item
, UInt16 height
)
288 return ::SetDataBrowserTableViewItemRowHeight(this->m_controlRef
,item
,height
);
291 OSStatus
wxMacDataBrowserTableViewControl::SetScrollPosition(UInt32 top
, UInt32 left
)
293 return ::SetDataBrowserScrollPosition(this->m_controlRef
,top
,left
);
299 OSStatus
wxMacDataBrowserTableViewControl::GetColumnCount(UInt32
* numColumns
) const
301 return ::GetDataBrowserTableViewColumnCount(this->m_controlRef
,numColumns
);
304 OSStatus
wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID propertyID
, DataBrowserTableViewColumnIndex
* index
) const
306 return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef
,propertyID
,index
);
307 } /* wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex*) const */
309 OSStatus
wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID
* propertyID
) const
311 for (*propertyID
=kMinPropertyID
; *propertyID
<std::numeric_limits
<DataBrowserPropertyID
>::max(); ++(*propertyID
))
312 if (this->IsUsedPropertyID(*propertyID
) == errDataBrowserPropertyNotFound
)
314 return errDataBrowserPropertyNotSupported
;
315 } /* wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID*) const */
317 OSStatus
wxMacDataBrowserTableViewControl::GetPropertyFlags(DataBrowserPropertyID propertyID
, DataBrowserPropertyFlags
*flags
) const
319 return ::GetDataBrowserPropertyFlags(this->m_controlRef
,propertyID
,flags
);
322 OSStatus
wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex index
, DataBrowserTableViewColumnID
* propertyID
)
324 return ::GetDataBrowserTableViewColumnProperty(this->m_controlRef
,index
,propertyID
);
325 } /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex, DataBrowserTableViewColumnID*) */
327 OSStatus
wxMacDataBrowserTableViewControl::IsUsedPropertyID(DataBrowserPropertyID propertyID
) const
329 // as the Mac interface does not provide a function that checks if the property id is in use or not a function is chosen that should not
330 // lead to a large overhead for the call but returns an error code if the property id does not exist, here we use the function that returns
331 // the column position for the property id:
332 DataBrowserTableViewColumnIndex index
;
334 return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef
,propertyID
,&index
);
335 } /* wxMacDataBrowserTableViewControl::IsUsedPropertyId(DataBrowserPropertyID) const */
337 OSStatus
wxMacDataBrowserTableViewControl::RemoveColumn(DataBrowserTableViewColumnIndex index
)
339 DataBrowserTableViewColumnID propertyID
;
342 this->GetPropertyID(index
,&propertyID
);
343 return ::RemoveDataBrowserTableViewColumn(this->m_controlRef
,propertyID
);
344 } /* wxMacDataBrowserTableViewControl::RemoveColumn(DataBrowserTableViewColumnIndex) */
346 OSStatus
wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID propertyID
, DataBrowserTableViewColumnIndex index
)
348 return ::SetDataBrowserTableViewColumnPosition(this->m_controlRef
,propertyID
,index
);
349 } /* wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex) */
351 OSStatus
wxMacDataBrowserTableViewControl::SetDisclosureColumn(DataBrowserPropertyID propertyID
, Boolean expandableRows
)
353 return ::SetDataBrowserListViewDisclosureColumn(this->m_controlRef
,propertyID
,expandableRows
);
356 OSStatus
wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID propertyID
, DataBrowserPropertyFlags flags
)
358 return ::SetDataBrowserPropertyFlags(this->m_controlRef
,propertyID
,flags
);
359 } /* wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID, DataBrowserPropertyFlags) */
364 OSStatus
wxMacDataBrowserTableViewControl::AddItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
)
366 return ::AddDataBrowserItems(this->m_controlRef
,container
,numItems
,items
,preSortProperty
);
367 } /* wxMacDataBrowserTableViewControl::AddItems(DataBrowserItemID, UInt32, DataBrowserItemID const*, DataBrowserPropertyID) */
369 OSStatus
wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID
* id
) const
374 verify_noerr(this->GetItemCount(&NoOfItems
));
382 // as there might be a lot of items in the data browser and mostly the data is added item by item the largest used ID number is roughly in the order of magnitude
383 // as the number of items; therefore, start from the number of items to look for a new ID:
384 for (*id
=NoOfItems
; *id
<std::numeric_limits
<DataBrowserItemID
>::max(); ++(*id
))
385 if (this->IsUsedItemID(*id
) == errDataBrowserItemNotFound
)
387 // as the first approach was not successful, try from the beginning:
388 for (*id
=0; *id
<NoOfItems
; ++(*id
))
389 if (this->IsUsedItemID(*id
) == errDataBrowserItemNotFound
)
391 // sorry, data browser is full:
392 return errDataBrowserItemNotAdded
;
394 } /* wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID*) const */
396 OSStatus
wxMacDataBrowserTableViewControl::GetItemCount(DataBrowserItemID container
, Boolean recurse
, DataBrowserItemState state
, ItemCount
* numItems
) const
398 return GetDataBrowserItemCount(this->m_controlRef
,container
,recurse
,state
,numItems
);
399 } /* wxMacDataBrowserTableViewControl::GetItemCount(DataBrowserItemID, Boolean, DataBrowserItemState, ItemCount*) const */
401 OSStatus
wxMacDataBrowserTableViewControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
403 return GetDataBrowserTableViewItemID(this->m_controlRef
,row
,item
);
406 OSStatus
wxMacDataBrowserTableViewControl::GetItems(DataBrowserItemID container
, Boolean recurse
, DataBrowserItemState state
, Handle items
) const
408 return GetDataBrowserItems(this->m_controlRef
,container
,recurse
,state
,items
);
409 } /* wxMacDataBrowserTableViewControl::GetItems(DataBrowserItemID, Boolean, DataBrowserItemState, Handle) const */
411 OSStatus
wxMacDataBrowserTableViewControl::GetItemRow(DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
413 return GetDataBrowserTableViewItemRow(this->m_controlRef
,item
,row
);
416 OSStatus
wxMacDataBrowserTableViewControl::IsUsedItemID(DataBrowserItemID itemID
) const
418 // as the Mac interface does not provide a function that checks if the property id is in use or not a function is chosen that should not
419 // lead to a large overhead for the call but returns an error code if the property id does not exist, here we use the function that returns
420 // the column position for the property id:
421 DataBrowserTableViewColumnIndex index
;
423 return ::GetDataBrowserTableViewItemRow(this->m_controlRef
,itemID
,&index
);
424 } /* wxMacDataBrowserTableViewControl::IsUsedItemID(DataBrowserItemID) const */
426 OSStatus
wxMacDataBrowserTableViewControl::RemoveItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
)
428 return ::RemoveDataBrowserItems(this->m_controlRef
,container
,numItems
,items
,preSortProperty
);
431 OSStatus
wxMacDataBrowserTableViewControl::RevealItem(DataBrowserItemID item
, DataBrowserPropertyID propertyID
, DataBrowserRevealOptions options
) const
433 return ::RevealDataBrowserItem(this->m_controlRef
,item
,propertyID
,options
);
434 } /* wxMacDataBrowserTableViewControl::RevealItem(DataBrowserItemID item, DataBrowserPropertyID propertyID, DataBrowserRevealOptions options) const */
436 OSStatus
wxMacDataBrowserTableViewControl::UpdateItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
,
437 DataBrowserPropertyID propertyID
) const
439 return UpdateDataBrowserItems(this->m_controlRef
,container
,numItems
,items
,preSortProperty
,propertyID
);
445 size_t wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserItemID
& itemIDs
) const
447 DataBrowserItemID
* itemIDPtr
;
448 Handle
handle(::NewHandle(0));
453 wxCHECK_MSG(this->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemIsSelected
,handle
) == noErr
,0,_("Could not get selected items."));
454 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
456 itemIDs
.Alloc(NoOfItems
);
458 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
459 for (size_t i
=0; i
<NoOfItems
; ++i
)
461 itemIDs
.Add(*itemIDPtr
);
465 DisposeHandle(handle
);
467 } /* wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserItemID&) const*/
469 OSStatus
wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID
* first
, DataBrowserItemID
* last
) const
471 return ::GetDataBrowserSelectionAnchor(this->m_controlRef
,first
,last
);
472 } /* wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID*, DataBrowserItemID*) const */
474 OSStatus
wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags
* flags
) const
476 return ::GetDataBrowserSelectionFlags(this->m_controlRef
,flags
);
477 } /* wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags*) const */
479 bool wxMacDataBrowserTableViewControl::IsItemSelected(DataBrowserItemID item
) const
481 return ::IsDataBrowserItemSelected(this->m_controlRef
,item
);
482 } /* wxMacDataBrowserTableViewControl::IsItemSelected(DataBrowserItemID) const */
484 OSStatus
wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectionFlags flags
)
486 return ::SetDataBrowserSelectionFlags(this->m_controlRef
,flags
);
487 } /* wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectionFlags) */
489 OSStatus
wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserSetOption operation
)
491 return ::SetDataBrowserSelectedItems(this->m_controlRef
, numItems
, items
, operation
);
492 } /* wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32, DataBrowserItemID const*, DataBrowserSetOption) */
494 OSStatus
wxMacDataBrowserTableViewControl::GetSortProperty(DataBrowserPropertyID
* propertyID
) const
496 return ::GetDataBrowserSortProperty(this->m_controlRef
,propertyID
);
499 OSStatus
wxMacDataBrowserTableViewControl::SetSortProperty(DataBrowserPropertyID propertyID
)
501 return ::SetDataBrowserSortProperty(this->m_controlRef
,propertyID
);
504 OSStatus
wxMacDataBrowserTableViewControl::GetSortOrder(DataBrowserSortOrder
* order
) const
506 return ::GetDataBrowserSortOrder(this->m_controlRef
,order
);
509 OSStatus
wxMacDataBrowserTableViewControl::SetSortOrder(DataBrowserSortOrder order
)
511 return ::SetDataBrowserSortOrder(this->m_controlRef
,order
);
514 IMPLEMENT_ABSTRACT_CLASS(wxMacDataBrowserTableViewControl
,wxMacControl
)
516 // ============================================================================
517 // wxMacDataBrowserListViewControl
518 // ============================================================================
523 OSStatus
wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc
*columnDesc
, DataBrowserTableViewColumnIndex position
)
525 return AddDataBrowserListViewColumn(this->m_controlRef
,columnDesc
,position
);
526 } /* wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc*, DataBrowserTableViewColumnIndex) */
528 // ============================================================================
529 // wxMacDataViewDataBrowserListViewControl
530 // ============================================================================
533 // constructors / destructor
535 wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl(wxWindow
* peer
, wxPoint
const& pos
, wxSize
const& size
, long style
)
536 :wxMacDataBrowserListViewControl(peer
,pos
,size
,style
)
538 } /* wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl(wxWindow* , const wxPoint&, const wxSize&, long) */
541 // callback functions (inherited from wxMacDataBrowserTableViewControl)
543 Boolean
wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
)
545 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
548 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Pointer to data view control not set correctly."));
549 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,false,_("Pointer to model not set correctly."));
550 if (sortProperty
>= kMinPropertyID
)
552 // variable definition:
553 DataBrowserTableViewColumnIndex columnIndex
;
555 wxCHECK_MSG(this->GetColumnIndex(sortProperty
,&columnIndex
) == noErr
,false,_("Could not determine column index."));
556 dataViewCtrlPtr
->GetModel()->SetSortingColumn(columnIndex
);
558 return static_cast<Boolean
>(dataViewCtrlPtr
->GetModel()->Compare(wxDataViewItem(reinterpret_cast<void*>(itemOneID
)),wxDataViewItem(reinterpret_cast<void*>(itemTwoID
))) < 0);
559 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
561 void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
)
563 DataBrowserTableViewColumnIndex columnIndex
;
565 wxDataViewColumn
* dataViewColumnPtr
;
567 wxDataViewCtrl
* dataViewCtrlPtr
;
569 wxDataViewCustomRenderer
* dataViewCustomRendererPtr
;
571 wxVariant dataToRender
;
574 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetPeer());
575 wxCHECK_RET(dataViewCtrlPtr
!= NULL
, _("Pointer to data view control not set correctly."));
576 wxCHECK_RET(dataViewCtrlPtr
->GetModel() != NULL
, _("Pointer to model not set correctly."));
577 wxCHECK_RET(this->GetColumnIndex(propertyID
,&columnIndex
) == noErr
,_("Could not determine column index."));
578 dataViewColumnPtr
= dataViewCtrlPtr
->GetColumn(columnIndex
);
579 wxCHECK_RET(dataViewColumnPtr
!= NULL
,_("No column for the specified column index existing."));
580 dataViewCustomRendererPtr
= dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer());
581 wxCHECK_RET(dataViewCustomRendererPtr
!= NULL
,_("No renderer or invalid renderer type specified for custom data column."));
582 dataViewCtrlPtr
->GetModel()->GetValue(dataToRender
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),columnIndex
);
583 dataViewCustomRendererPtr
->SetValue(dataToRender
);
585 // try to determine the content's size (drawable part):
587 RgnHandle
rgn(NewRgn());
590 if (this->GetRegion(kControlContentMetaPart
,rgn
) == noErr
)
591 GetRegionBounds(rgn
,&content
);
593 this->GetRect(&content
);
595 // space for the header
596 this->GetHeaderButtonHeight(&headerHeight
);
597 content
.top
+= headerHeight
;
598 // extra space for the frame (todo: do not how to determine the space automatically from the control)
603 // extra space for the scrollbars:
604 content
.bottom
-= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
605 content
.right
-= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
607 // make sure that 'Render' can draw only in the allowed area:
608 dataViewCustomRendererPtr
->GetDC()->SetClippingRegion(content
.left
,content
.top
,content
.right
-content
.left
+1,content
.bottom
-content
.top
+1);
609 (void) (dataViewCustomRendererPtr
->Render(wxRect(static_cast<int>(rectangle
->left
),static_cast<int>(rectangle
->top
),
610 static_cast<int>(1+rectangle
->right
-rectangle
->left
),static_cast<int>(1+rectangle
->bottom
-rectangle
->top
)),
611 dataViewCustomRendererPtr
->GetDC(),((state
== kDataBrowserItemIsSelected
) ? wxDATAVIEW_CELL_SELECTED
: 0)));
612 dataViewCustomRendererPtr
->GetDC()->DestroyClippingRegion(); // probably not necessary
613 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */
615 OSStatus
wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemDataRef itemData
, Boolean getValue
)
619 // variable definitions:
620 DataBrowserTableViewColumnIndex columnIndex
;
621 OSStatus errorStatus
;
622 wxDataViewCtrl
* dataViewCtrlPtr
;
623 wxDataViewColumn
* dataViewColumnPtr
;
625 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetPeer());
626 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
627 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,errDataBrowserNotConfigured
,_("Pointer to model not set correctly."));
628 errorStatus
= this->GetColumnIndex(propertyID
,&columnIndex
);
629 wxCHECK_MSG(errorStatus
== noErr
,errorStatus
,_("Could not determine column index"));
630 dataViewColumnPtr
= dataViewCtrlPtr
->GetColumn(columnIndex
);
631 wxCHECK_MSG((dataViewColumnPtr
!= NULL
) && (dataViewColumnPtr
->GetRenderer() != NULL
),errDataBrowserNotConfigured
,_("There is no column or renderer for the specified column index."));
632 switch (dataViewColumnPtr
->GetRenderer()->GetPropertyType())
634 case kDataBrowserCheckboxType
:
636 // variable definition:
637 ThemeButtonValue buttonValue
;
639 errorStatus
= ::GetDataBrowserItemDataButtonValue(itemData
,&buttonValue
);
640 if (errorStatus
== noErr
)
642 if (buttonValue
== kThemeButtonOn
)
644 // variable definition and initialization:
645 wxVariant
modifiedData(true);
647 return (dataViewCtrlPtr
->GetModel()->SetValue(modifiedData
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),static_cast<unsigned int>(columnIndex
)) ? OSStatus(noErr
) : OSStatus(errDataBrowserNotConfigured
));
649 else if (buttonValue
== kThemeButtonOff
)
651 // variable definition and initialization:
652 wxVariant
modifiedData(false);
654 return (dataViewCtrlPtr
->GetModel()->SetValue(modifiedData
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),static_cast<unsigned int>(columnIndex
)) ? OSStatus(noErr
) : OSStatus(errDataBrowserNotConfigured
));
657 return errDataBrowserInvalidPropertyData
;
662 case kDataBrowserTextType
:
664 // variable definitions:
665 CFStringRef stringReference
;
667 errorStatus
= ::GetDataBrowserItemDataText(itemData
,&stringReference
);
668 if (errorStatus
== noErr
)
670 // variable definitions and initializations:
671 wxMacCFStringHolder
modifiedString(stringReference
);
672 wxVariant
modifiedData(modifiedString
.AsString());
674 if (dataViewCtrlPtr
->GetModel()->SetValue(modifiedData
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),static_cast<unsigned int>(columnIndex
)))
677 return errDataBrowserNotConfigured
;
683 return errDataBrowserPropertyNotSupported
;
688 if (propertyID
>= kMinPropertyID
) // in case of data columns set the data
690 // variable definitions:
691 DataBrowserTableViewColumnIndex columnIndex
;
692 OSStatus errorStatus
;
694 wxDataViewColumn
* dataViewColumnPtr
;
695 wxDataViewCtrl
* dataViewCtrlPtr
;
697 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetPeer());
698 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
699 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,errDataBrowserNotConfigured
,_("Pointer to model not set correctly."));
700 errorStatus
= this->GetColumnIndex(propertyID
,&columnIndex
);
701 wxCHECK_MSG(errorStatus
== noErr
,errorStatus
,_("Column index does not exist."));
702 dataViewColumnPtr
= dataViewCtrlPtr
->GetColumn(columnIndex
);
703 wxCHECK_MSG(dataViewColumnPtr
!= NULL
,errDataBrowserNotConfigured
,_("No column for the specified column position existing."));
704 wxCHECK_MSG(dataViewColumnPtr
->GetRenderer() != NULL
,errDataBrowserNotConfigured
,_("No renderer specified for column."));
705 dataViewCtrlPtr
->GetModel()->GetValue(variant
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),dataViewColumnPtr
->GetModelColumn());
706 dataViewColumnPtr
->GetRenderer()->SetDataReference(itemData
);
707 dataViewColumnPtr
->GetRenderer()->SetValue(variant
);
708 wxCHECK_MSG(dataViewColumnPtr
->GetRenderer()->Render(),errDataBrowserNotConfigured
,_("Rendering failed."));
710 else // react on special system requests
713 case kDataBrowserItemIsContainerProperty
:
715 // variable definition:
716 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
718 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
719 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,errDataBrowserNotConfigured
,_("Pointer to model not set correctly."));
720 return ::SetDataBrowserItemDataBooleanValue(itemData
,dataViewCtrlPtr
->GetModel()->IsContainer(wxDataViewItem(reinterpret_cast<void*>(itemID
))));
722 case kDataBrowserItemIsEditableProperty
:
723 return ::SetDataBrowserItemDataBooleanValue(itemData
,true);
726 return errDataBrowserPropertyNotSupported
;
727 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */
729 void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef
WXUNUSED(itemData
))
733 case kDataBrowserContainerOpened
:
735 // variable definitions:
736 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
738 wxCHECK_RET(dataViewCtrlPtr
!= NULL
,_("Pointer to data view control not set correctly."));
739 dataViewCtrlPtr
->AddChildrenLevel(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
742 case kDataBrowserItemDoubleClicked
:
744 // variable definitions:
745 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
747 wxCHECK_RET(dataViewCtrlPtr
!= NULL
,_("Pointer to data view control not set correctly."));
748 // initialize wxWidget event:
749 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
,dataViewCtrlPtr
->GetId()); // variable definition
751 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
752 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
753 // finally sent the equivalent wxWidget event:
754 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
757 case kDataBrowserItemSelected
:
759 // variable definitions:
760 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
762 wxCHECK_RET(dataViewCtrlPtr
!= NULL
,_("Pointer to data view control not set correctly."));
763 // initialize wxWidget event:
764 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED
,dataViewCtrlPtr
->GetId()); // variable definition
766 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
767 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
768 // finally sent the equivalent wxWidget event:
769 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
772 case kDataBrowserUserStateChanged
:
774 DataBrowserPropertyID propertyID
;
776 if ((this->GetSortProperty(&propertyID
) == noErr
) && (propertyID
>= kMinPropertyID
))
778 DataBrowserSortOrder sortOrder
;
779 DataBrowserTableViewColumnIndex columnIndex
;
781 if ((this->GetSortOrder(&sortOrder
) == noErr
) && (this->GetColumnIndex(propertyID
,&columnIndex
) == noErr
))
783 // variable definition and initialization:
784 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
786 if ( dataViewCtrlPtr
->GetColumn(columnIndex
)->IsSortOrderAscending() && (sortOrder
== kDataBrowserOrderDecreasing
) ||
787 !(dataViewCtrlPtr
->GetColumn(columnIndex
)->IsSortOrderAscending()) && (sortOrder
== kDataBrowserOrderIncreasing
))
789 // initialize wxWidget event:
790 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
,dataViewCtrlPtr
->GetId()); // variable defintion
792 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
793 dataViewEvent
.SetColumn(columnIndex
);
794 dataViewEvent
.SetDataViewColumn(dataViewCtrlPtr
->GetColumn(columnIndex
));
795 // finally sent the equivalent wxWidget event:
796 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
803 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */
807 // wxUSE_GENERICDATAVIEWCTRL