1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/databrow.cpp
3 // Purpose: Classes and functions for the Carbon data browser
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #if wxUSE_DATAVIEWCTRL
15 #ifndef wxUSE_GENERICDATAVIEWCTRL
19 #include "wx/toplevel.h"
21 #include "wx/settings.h"
25 #include "wx/dataview.h"
26 #include "wx/osx/carbon/databrow.h"
27 #include "wx/osx/private.h"
28 #include "wx/osx/uma.h"
32 // ============================================================================
33 // Variables used globally in databrow.cpp
34 // ============================================================================
35 DataBrowserGetContextualMenuUPP gDataBrowserTableViewGetContextualMenuUPP
= NULL
;
36 DataBrowserItemCompareUPP gDataBrowserTableViewItemCompareUPP
= NULL
;
37 DataBrowserItemDataUPP gDataBrowserTableViewItemDataUPP
= NULL
;
38 DataBrowserItemNotificationUPP gDataBrowserTableViewItemNotificationUPP
= NULL
;
40 DataBrowserDrawItemUPP gDataBrowserTableViewDrawItemUPP
= NULL
;
41 DataBrowserEditItemUPP gDataBrowserTableViewEditItemUPP
= NULL
;
42 DataBrowserHitTestUPP gDataBrowserTableViewHitTestUPP
= NULL
;
43 DataBrowserTrackingUPP gDataBrowserTableViewTrackingUPP
= NULL
;
45 // ============================================================================
46 // wxMacDataBrowserTableViewControl
47 // ============================================================================
49 pascal Boolean
wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlRef browser
, DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
)
51 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
54 if (ControlPtr
!= NULL
)
55 return ControlPtr
->DataBrowserCompareProc(itemOneID
,itemTwoID
,sortProperty
);
57 return errDataBrowserPropertyNotSupported
;
58 } /* wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlRef, DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
60 pascal void wxMacDataBrowserTableViewControl::DataBrowserGetContextualMenuProc(ControlRef browser
, MenuRef
* menu
, UInt32
* helpType
, CFStringRef
* helpItemString
, AEDesc
* selection
)
62 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
65 if (ControlPtr
!= NULL
)
66 ControlPtr
->DataBrowserGetContextualMenuProc(menu
,helpType
,helpItemString
,selection
);
67 } /* wxMacDataBrowserTableViewControl::DataBrowserGetContextualMenuProc(ControlRef, MenuRef*, UInt32*, CFStringRef*, AEDesc*) */
69 pascal OSStatus
wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemDataRef itemData
, Boolean getValue
)
71 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
74 if (ControlPtr
!= NULL
)
75 return ControlPtr
->DataBrowserGetSetItemDataProc(itemID
,propertyID
,itemData
,getValue
);
77 return errDataBrowserPropertyNotSupported
;
78 } /* wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */
80 pascal void wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
)
82 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
85 if (ControlPtr
!= NULL
)
86 ControlPtr
->DataBrowserItemNotificationProc(itemID
,message
,itemData
);
87 } /* wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc(ControlRef, DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */
89 pascal void wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
)
91 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
94 if (ControlPtr
!= NULL
)
95 ControlPtr
->DataBrowserDrawItemProc(itemID
,propertyID
,state
,rectangle
,bitDepth
,colorDevice
);
96 } /* wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */
98 pascal Boolean
wxMacDataBrowserTableViewControl::DataBrowserEditItemProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, CFStringRef theString
, Rect
* maxEditTextRect
, Boolean
* shrinkToFit
)
100 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
103 return ((ControlPtr
!= NULL
) && ControlPtr
->DataBrowserEditItemProc(itemID
,propertyID
,theString
,maxEditTextRect
,shrinkToFit
));
104 } /* wxMacDataBrowserTableViewControl::DataBrowserEditItemProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, CFStringRef, Rect*, Boolean*) */
106 pascal Boolean
wxMacDataBrowserTableViewControl::DataBrowserHitTestProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Rect
const* mouseRect
)
108 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
111 return ((ControlPtr
!= NULL
) && ControlPtr
->DataBrowserHitTestProc(itemID
,propertyID
,theRect
,mouseRect
));
112 } /* wxMacDataBrowserTableViewControl::DataBrowserHitTestProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, Rect const*, Rect const*) */
114 pascal DataBrowserTrackingResult
wxMacDataBrowserTableViewControl::DataBrowserTrackingProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Point startPt
, EventModifiers modifiers
)
116 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
119 if (ControlPtr
!= NULL
)
120 return ControlPtr
->DataBrowserTrackingProc(itemID
,propertyID
,theRect
,startPt
,modifiers
);
122 return kDataBrowserNothingHit
;
123 } /* wxMacDataBrowserTableViewControl::DataBrowserTrackingProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, Rect const*, Point, EventModifiers) */
125 wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow
* peer
, wxPoint
const& pos
, wxSize
const& size
, long style
)
128 Rect bounds
= wxMacGetBoundsForControl(peer
,pos
,size
);
129 OSStatus err
= ::CreateDataBrowserControl(MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),&bounds
,kDataBrowserListView
,&(this->m_controlRef
));
132 SetReferenceInNativeControl();
134 // setup standard callbacks:
135 if (gDataBrowserTableViewGetContextualMenuUPP
== NULL
) gDataBrowserTableViewGetContextualMenuUPP
= NewDataBrowserGetContextualMenuUPP(wxMacDataBrowserTableViewControl::DataBrowserGetContextualMenuProc
);
136 if (gDataBrowserTableViewItemCompareUPP
== NULL
) gDataBrowserTableViewItemCompareUPP
= NewDataBrowserItemCompareUPP (wxMacDataBrowserTableViewControl::DataBrowserCompareProc
);
137 if (gDataBrowserTableViewItemDataUPP
== NULL
) gDataBrowserTableViewItemDataUPP
= NewDataBrowserItemDataUPP (wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc
);
138 if (gDataBrowserTableViewItemNotificationUPP
== NULL
)
140 gDataBrowserTableViewItemNotificationUPP
=
141 #if TARGET_API_MAC_OSX
142 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc
);
144 NewDataBrowserItemNotificationUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc
);
147 DataBrowserCallbacks callbacks
; // variable definition
149 InitializeDataBrowserCallbacks(&callbacks
,kDataBrowserLatestCallbacks
);
150 callbacks
.u
.v1
.getContextualMenuCallback
= gDataBrowserTableViewGetContextualMenuUPP
;
151 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserTableViewItemDataUPP
;
152 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserTableViewItemCompareUPP
;
153 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserTableViewItemNotificationUPP
;
154 this->SetCallbacks(&callbacks
);
156 // setup callbacks for customized items:
157 if (gDataBrowserTableViewDrawItemUPP
== NULL
) gDataBrowserTableViewDrawItemUPP
= NewDataBrowserDrawItemUPP(wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc
);
158 if (gDataBrowserTableViewEditItemUPP
== NULL
) gDataBrowserTableViewEditItemUPP
= NewDataBrowserEditItemUPP(wxMacDataBrowserTableViewControl::DataBrowserEditItemProc
);
159 if (gDataBrowserTableViewHitTestUPP
== NULL
) gDataBrowserTableViewHitTestUPP
= NewDataBrowserHitTestUPP (wxMacDataBrowserTableViewControl::DataBrowserHitTestProc
);
160 if (gDataBrowserTableViewTrackingUPP
== NULL
) gDataBrowserTableViewTrackingUPP
= NewDataBrowserTrackingUPP(wxMacDataBrowserTableViewControl::DataBrowserTrackingProc
);
162 DataBrowserCustomCallbacks customCallbacks
; // variable definition
164 InitializeDataBrowserCustomCallbacks(&customCallbacks
,kDataBrowserLatestCallbacks
);
165 customCallbacks
.u
.v1
.drawItemCallback
= gDataBrowserTableViewDrawItemUPP
;
166 customCallbacks
.u
.v1
.editTextCallback
= gDataBrowserTableViewEditItemUPP
;
167 customCallbacks
.u
.v1
.hitTestCallback
= gDataBrowserTableViewHitTestUPP
;
168 customCallbacks
.u
.v1
.trackingCallback
= gDataBrowserTableViewTrackingUPP
;
169 this->SetCustomCallbacks(&customCallbacks
);
172 this->EnableCellSizeModification( ((style
& wxDV_VARIABLE_LINE_HEIGHT
) != 0), true );
174 DataBrowserSelectionFlags flags
; // variable definition
176 if (this->GetSelectionFlags(&flags
) == noErr
) // get default settings
178 if ((style
& wxDV_MULTIPLE
) != 0)
179 flags
&= ~kDataBrowserSelectOnlyOne
;
181 flags
|= kDataBrowserSelectOnlyOne
;
182 (void) this->SetSelectionFlags(flags
);
185 OptionBits attributes
; // variable definition
187 if (this->GetAttributes(&attributes
) == noErr
) // get default settings
189 if ((style
& wxDV_VERT_RULES
) != 0)
190 attributes
|= kDataBrowserAttributeListViewDrawColumnDividers
;
192 attributes
&= ~kDataBrowserAttributeListViewDrawColumnDividers
;
193 if ((style
& wxDV_ROW_LINES
) != 0)
194 attributes
|= kDataBrowserAttributeListViewAlternatingRowColors
;
196 attributes
&= ~kDataBrowserAttributeListViewAlternatingRowColors
;
197 (void) this->SetAttributes(attributes
);
200 if ((style
& wxDV_NO_HEADER
) != 0)
201 this->SetHeaderButtonHeight(0);
202 } /* wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow*, wxPoint const&, wxSize const&, long) */
207 OSStatus
wxMacDataBrowserTableViewControl::SetCallbacks(DataBrowserCallbacks
const* callbacks
)
209 return ::SetDataBrowserCallbacks(this->m_controlRef
,callbacks
);
210 } /* wxMacDataBrowserTableViewControl::SetCallbacks(DataBrowserCallbacks const*) */
212 OSStatus
wxMacDataBrowserTableViewControl::SetCustomCallbacks(DataBrowserCustomCallbacks
const* customCallbacks
)
214 return ::SetDataBrowserCustomCallbacks(this->m_controlRef
,customCallbacks
);
215 } /* xMacDataBrowserTableViewControl::SetCustomCallbacks(DataBrowserCustomCallbacks const*) */
220 OSStatus
wxMacDataBrowserTableViewControl::GetHeaderDesc(DataBrowserPropertyID propertyID
, DataBrowserListViewHeaderDesc
* desc
) const
222 desc
->version
= kDataBrowserListViewLatestHeaderDesc
; // if this statement is missing the next call will fail (NOT DOCUMENTED!!)
223 return ::GetDataBrowserListViewHeaderDesc(this->m_controlRef
,propertyID
,desc
);
226 OSStatus
wxMacDataBrowserTableViewControl::SetHeaderDesc(DataBrowserPropertyID propertyID
, DataBrowserListViewHeaderDesc
* desc
)
228 return ::SetDataBrowserListViewHeaderDesc(this->m_controlRef
,propertyID
,desc
);
234 OSStatus
wxMacDataBrowserTableViewControl::AutoSizeColumns()
236 return AutoSizeDataBrowserListViewColumns(this->m_controlRef
);
239 OSStatus
wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool enableHeight
, bool enableWidth
)
241 return ::SetDataBrowserTableViewGeometry(this->GetControlRef(),enableWidth
,enableHeight
);
242 } /* wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool, bool) */
244 OSStatus
wxMacDataBrowserTableViewControl::GetAttributes(OptionBits
* attributes
)
246 return ::DataBrowserGetAttributes(this->GetControlRef(),attributes
);
247 } /* wxMacDataBrowserTableViewControl::GetAttributes(OptionBits*) */
249 OSStatus
wxMacDataBrowserTableViewControl::GetColumnWidth(DataBrowserPropertyID propertyID
, UInt16
* width
) const
251 return ::GetDataBrowserTableViewNamedColumnWidth(this->m_controlRef
,propertyID
,width
);
254 OSStatus
wxMacDataBrowserTableViewControl::GetDefaultColumnWidth( UInt16
*width
) const
256 return GetDataBrowserTableViewColumnWidth(this->m_controlRef
, width
);
259 OSStatus
wxMacDataBrowserTableViewControl::GetDefaultRowHeight(UInt16
* height
) const
261 return ::GetDataBrowserTableViewRowHeight(this->m_controlRef
,height
);
264 OSStatus
wxMacDataBrowserTableViewControl::GetHeaderButtonHeight(UInt16
*height
)
266 return ::GetDataBrowserListViewHeaderBtnHeight(this->m_controlRef
,height
);
269 OSStatus
wxMacDataBrowserTableViewControl::GetPartBounds(DataBrowserItemID item
, DataBrowserPropertyID propertyID
, DataBrowserPropertyPart part
, Rect
* bounds
)
271 return ::GetDataBrowserItemPartBounds(this->m_controlRef
,item
,propertyID
,part
,bounds
);
272 } /* wxMacDataBrowserTableViewControl::GetPartBounds(DataBrowserItemID, DataBrowswerPropertyID, DataBrowserPropertyPart, Rect*) */
274 OSStatus
wxMacDataBrowserTableViewControl::GetRowHeight(DataBrowserItemID item
, UInt16
* height
) const
276 return ::GetDataBrowserTableViewItemRowHeight(this->m_controlRef
,item
,height
);
277 } /* wxMacDataBrowserTableViewControl::GetRowHeight(DataBrowserItemID, UInt16*) const */
279 OSStatus
wxMacDataBrowserTableViewControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
281 return GetDataBrowserScrollPosition(this->m_controlRef
, top
, left
);
284 OSStatus
wxMacDataBrowserTableViewControl::SetAttributes(OptionBits attributes
)
286 return ::DataBrowserChangeAttributes(this->GetControlRef(),attributes
,~attributes
);
287 } /* wxMacDataBrowserTableViewControl::SetAttributes(OptionBits) */
289 OSStatus
wxMacDataBrowserTableViewControl::SetColumnWidth(DataBrowserPropertyID propertyID
, UInt16 width
)
291 return ::SetDataBrowserTableViewNamedColumnWidth(this->m_controlRef
,propertyID
,width
);
294 OSStatus
wxMacDataBrowserTableViewControl::SetDefaultColumnWidth(UInt16 width
)
296 return ::SetDataBrowserTableViewColumnWidth(this->m_controlRef
,width
);
299 OSStatus
wxMacDataBrowserTableViewControl::SetDefaultRowHeight(UInt16 height
)
301 return ::SetDataBrowserTableViewRowHeight(this->m_controlRef
,height
);
304 OSStatus
wxMacDataBrowserTableViewControl::SetHasScrollBars(bool horiz
, bool vert
)
306 return ::SetDataBrowserHasScrollBars(this->m_controlRef
,horiz
,vert
);
307 } /* wxMacDataBrowserTableViewControl::SetHasScrollBars(bool, bool) */
309 OSStatus
wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16 height
)
311 return ::SetDataBrowserListViewHeaderBtnHeight(this->m_controlRef
,height
);
312 } /* wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16) */
314 OSStatus
wxMacDataBrowserTableViewControl::SetHiliteStyle(DataBrowserTableViewHiliteStyle hiliteStyle
)
316 return ::SetDataBrowserTableViewHiliteStyle(this->m_controlRef
,hiliteStyle
);
317 } /*wxMacDataBrowserTableViewControl::SetHiliteStyle(DataBrowserTableViewHiliteStyle) */
319 OSStatus
wxMacDataBrowserTableViewControl::SetIndent(float Indent
)
321 return ::DataBrowserSetMetric(this->m_controlRef
,kDataBrowserMetricDisclosureColumnPerDepthGap
,true,Indent
);
322 } /* wxMacDataBrowserTableViewControl::SetIndent(float* Indent) */
324 OSStatus
wxMacDataBrowserTableViewControl::SetRowHeight(DataBrowserItemID item
, UInt16 height
)
326 return ::SetDataBrowserTableViewItemRowHeight(this->m_controlRef
,item
,height
);
329 OSStatus
wxMacDataBrowserTableViewControl::SetScrollPosition(UInt32 top
, UInt32 left
)
331 return ::SetDataBrowserScrollPosition(this->m_controlRef
,top
,left
);
337 OSStatus
wxMacDataBrowserTableViewControl::GetColumnCount(UInt32
* numColumns
) const
339 return ::GetDataBrowserTableViewColumnCount(this->m_controlRef
,numColumns
);
342 OSStatus
wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID propertyID
, DataBrowserTableViewColumnIndex
* index
) const
344 return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef
,propertyID
,index
);
345 } /* wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex*) const */
347 OSStatus
wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID
* propertyID
) const
349 for (*propertyID
=kMinPropertyID
; *propertyID
<std::numeric_limits
<DataBrowserPropertyID
>::max(); ++(*propertyID
))
350 if (this->IsUsedPropertyID(*propertyID
) == errDataBrowserPropertyNotFound
)
352 return errDataBrowserPropertyNotSupported
;
353 } /* wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID*) const */
355 OSStatus
wxMacDataBrowserTableViewControl::GetPropertyFlags(DataBrowserPropertyID propertyID
, DataBrowserPropertyFlags
*flags
) const
357 return ::GetDataBrowserPropertyFlags(this->m_controlRef
,propertyID
,flags
);
360 OSStatus
wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef itemData
, DataBrowserPropertyID
* propertyID
)
362 return ::GetDataBrowserItemDataProperty(itemData
,propertyID
);
363 } /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef, DataBrowserPropertyID*) */
365 OSStatus
wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex index
, DataBrowserTableViewColumnID
* propertyID
)
367 return ::GetDataBrowserTableViewColumnProperty(this->m_controlRef
,index
,propertyID
);
368 } /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex, DataBrowserTableViewColumnID*) */
370 OSStatus
wxMacDataBrowserTableViewControl::IsUsedPropertyID(DataBrowserPropertyID propertyID
) const
372 // 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
373 // 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
374 // the column position for the property id:
375 DataBrowserTableViewColumnIndex index
;
377 return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef
,propertyID
,&index
);
378 } /* wxMacDataBrowserTableViewControl::IsUsedPropertyId(DataBrowserPropertyID) const */
380 OSStatus
wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID propertyID
)
382 return ::RemoveDataBrowserTableViewColumn(this->m_controlRef
,propertyID
);
383 } /* wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID) */
385 OSStatus
wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex index
)
387 DataBrowserTableViewColumnID propertyID
;
390 this->GetPropertyID(index
,&propertyID
);
391 return ::RemoveDataBrowserTableViewColumn(this->m_controlRef
,propertyID
);
392 } /* wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex) */
394 OSStatus
wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID propertyID
, DataBrowserTableViewColumnIndex index
)
396 return ::SetDataBrowserTableViewColumnPosition(this->m_controlRef
,propertyID
,index
);
397 } /* wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex) */
399 OSStatus
wxMacDataBrowserTableViewControl::SetDisclosureColumn(DataBrowserPropertyID propertyID
, Boolean expandableRows
)
401 return ::SetDataBrowserListViewDisclosureColumn(this->m_controlRef
,propertyID
,expandableRows
);
404 OSStatus
wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID propertyID
, DataBrowserPropertyFlags flags
)
406 return ::SetDataBrowserPropertyFlags(this->m_controlRef
,propertyID
,flags
);
407 } /* wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID, DataBrowserPropertyFlags) */
412 OSStatus
wxMacDataBrowserTableViewControl::AddItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
)
414 return ::AddDataBrowserItems(this->m_controlRef
,container
,numItems
,items
,preSortProperty
);
415 } /* wxMacDataBrowserTableViewControl::AddItems(DataBrowserItemID, UInt32, DataBrowserItemID const*, DataBrowserPropertyID) */
417 OSStatus
wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID
* id
) const
424 status
= this->GetItemCount(&NoOfItems
);
425 wxCHECK_MSG(status
== noErr
,status
,_("Could not retrieve number of items"));
433 // 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
434 // as the number of items; therefore, start from the number of items to look for a new ID:
435 for (*id
=NoOfItems
; *id
<std::numeric_limits
<DataBrowserItemID
>::max(); ++(*id
))
436 if (this->IsUsedItemID(*id
) == errDataBrowserItemNotFound
)
438 // as the first approach was not successful, try from the beginning:
439 for (*id
=0; *id
<NoOfItems
; ++(*id
))
440 if (this->IsUsedItemID(*id
) == errDataBrowserItemNotFound
)
442 // sorry, data browser is full:
443 return errDataBrowserItemNotAdded
;
445 } /* wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID*) const */
447 OSStatus
wxMacDataBrowserTableViewControl::GetItemCount(DataBrowserItemID container
, Boolean recurse
, DataBrowserItemState state
, ItemCount
* numItems
) const
449 return GetDataBrowserItemCount(this->m_controlRef
,container
,recurse
,state
,numItems
);
450 } /* wxMacDataBrowserTableViewControl::GetItemCount(DataBrowserItemID, Boolean, DataBrowserItemState, ItemCount*) const */
452 OSStatus
wxMacDataBrowserTableViewControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
454 return GetDataBrowserTableViewItemID(this->m_controlRef
,row
,item
);
457 OSStatus
wxMacDataBrowserTableViewControl::GetItems(DataBrowserItemID container
, Boolean recurse
, DataBrowserItemState state
, Handle items
) const
459 return GetDataBrowserItems(this->m_controlRef
,container
,recurse
,state
,items
);
460 } /* wxMacDataBrowserTableViewControl::GetItems(DataBrowserItemID, Boolean, DataBrowserItemState, Handle) const */
462 OSStatus
wxMacDataBrowserTableViewControl::GetItemRow(DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
464 return GetDataBrowserTableViewItemRow(this->m_controlRef
,item
,row
);
467 OSStatus
wxMacDataBrowserTableViewControl::IsUsedItemID(DataBrowserItemID itemID
) const
469 // 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
470 // 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
471 // the column position for the property id:
472 DataBrowserTableViewColumnIndex index
;
474 return ::GetDataBrowserTableViewItemRow(this->m_controlRef
,itemID
,&index
);
475 } /* wxMacDataBrowserTableViewControl::IsUsedItemID(DataBrowserItemID) const */
477 OSStatus
wxMacDataBrowserTableViewControl::RemoveItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
)
479 return ::RemoveDataBrowserItems(this->m_controlRef
,container
,numItems
,items
,preSortProperty
);
482 OSStatus
wxMacDataBrowserTableViewControl::RevealItem(DataBrowserItemID item
, DataBrowserPropertyID propertyID
, DataBrowserRevealOptions options
) const
484 return ::RevealDataBrowserItem(this->m_controlRef
,item
,propertyID
,options
);
485 } /* wxMacDataBrowserTableViewControl::RevealItem(DataBrowserItemID item, DataBrowserPropertyID propertyID, DataBrowserRevealOptions options) const */
487 OSStatus
wxMacDataBrowserTableViewControl::UpdateItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
,
488 DataBrowserPropertyID propertyID
) const
490 return UpdateDataBrowserItems(this->m_controlRef
,container
,numItems
,items
,preSortProperty
,propertyID
);
496 size_t wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserItemID
& itemIDs
) const
498 DataBrowserItemID
* itemIDPtr
;
499 Handle
handle(::NewHandle(0));
504 wxCHECK_MSG(this->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemIsSelected
,handle
) == noErr
,0,_("Could not get selected items."));
505 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
507 itemIDs
.Alloc(NoOfItems
);
509 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
510 for (size_t i
=0; i
<NoOfItems
; ++i
)
512 itemIDs
.Add(*itemIDPtr
);
516 DisposeHandle(handle
);
518 } /* wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserItemID&) const*/
520 OSStatus
wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID
* first
, DataBrowserItemID
* last
) const
522 return ::GetDataBrowserSelectionAnchor(this->m_controlRef
,first
,last
);
523 } /* wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID*, DataBrowserItemID*) const */
525 OSStatus
wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags
* flags
) const
527 return ::GetDataBrowserSelectionFlags(this->m_controlRef
,flags
);
528 } /* wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags*) const */
530 bool wxMacDataBrowserTableViewControl::IsItemSelected(DataBrowserItemID item
) const
532 return ::IsDataBrowserItemSelected(this->m_controlRef
,item
);
533 } /* wxMacDataBrowserTableViewControl::IsItemSelected(DataBrowserItemID) const */
535 OSStatus
wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectionFlags flags
)
537 return ::SetDataBrowserSelectionFlags(this->m_controlRef
,flags
);
538 } /* wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectionFlags) */
540 OSStatus
wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserSetOption operation
)
542 return ::SetDataBrowserSelectedItems(this->m_controlRef
, numItems
, items
, operation
);
543 } /* wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32, DataBrowserItemID const*, DataBrowserSetOption) */
545 OSStatus
wxMacDataBrowserTableViewControl::GetSortOrder(DataBrowserSortOrder
* order
) const
547 return ::GetDataBrowserSortOrder(this->m_controlRef
,order
);
550 OSStatus
wxMacDataBrowserTableViewControl::GetSortProperty(DataBrowserPropertyID
* propertyID
) const
552 return ::GetDataBrowserSortProperty(this->m_controlRef
,propertyID
);
555 OSStatus
wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID container
, Boolean sortChildren
)
557 return ::SortDataBrowserContainer(this->m_controlRef
,container
,sortChildren
);
558 } /* wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID, Boolean) */
560 OSStatus
wxMacDataBrowserTableViewControl::SetSortOrder(DataBrowserSortOrder order
)
562 return ::SetDataBrowserSortOrder(this->m_controlRef
,order
);
565 OSStatus
wxMacDataBrowserTableViewControl::SetSortProperty(DataBrowserPropertyID propertyID
)
567 return ::SetDataBrowserSortProperty(this->m_controlRef
,propertyID
);
571 // container handling
573 OSStatus
wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID containerID
)
575 return ::CloseDataBrowserContainer(this->m_controlRef
,containerID
);
576 } /* wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID) */
578 OSStatus
wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID containerID
)
580 return ::OpenDataBrowserContainer(this->m_controlRef
,containerID
);
581 } /* wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID) */
583 IMPLEMENT_ABSTRACT_CLASS(wxMacDataBrowserTableViewControl
,wxMacControl
)
585 // ============================================================================
586 // wxMacDataBrowserListViewControl
587 // ============================================================================
592 OSStatus
wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc
*columnDesc
, DataBrowserTableViewColumnIndex position
)
594 return AddDataBrowserListViewColumn(this->m_controlRef
,columnDesc
,position
);
595 } /* wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc*, DataBrowserTableViewColumnIndex) */
597 // ============================================================================
598 // wxMacDataViewDataBrowserListViewControl
599 // ============================================================================
602 // constructors / destructor
604 wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl(wxWindow
* peer
, wxPoint
const& pos
, wxSize
const& size
, long style
)
605 :wxMacDataBrowserListViewControl(peer
,pos
,size
,style
)
607 } /* wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl(wxWindow* , const wxPoint&, const wxSize&, long) */
610 // callback functions (inherited from wxMacDataBrowserTableViewControl)
612 Boolean
wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
)
614 DataBrowserSortOrder sortOrder
;
616 DataBrowserTableViewColumnIndex modelColumnIndex
;
618 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer()));
621 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Pointer to data view control not set correctly."));
622 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,false,_("Pointer to model not set correctly."));
623 if (sortProperty
>= kMinPropertyID
)
625 // variable definition and initialization:
626 wxDataViewColumn
* ColumnPtr(dataViewCtrlPtr
->GetColumnPtr(sortProperty
));
628 wxCHECK_MSG(ColumnPtr
!= NULL
,false,_("Could not determine column index."));
629 modelColumnIndex
= ColumnPtr
->GetModelColumn();
632 modelColumnIndex
= 0;
633 this->GetSortOrder(&sortOrder
);
634 return static_cast<Boolean
>(dataViewCtrlPtr
->GetModel()->Compare(wxDataViewItem(reinterpret_cast<void*>(itemOneID
)),wxDataViewItem(reinterpret_cast<void*>(itemTwoID
)),
635 modelColumnIndex
,sortOrder
!= kDataBrowserOrderDecreasing
) < 0);
636 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
638 void wxMacDataViewDataBrowserListViewControl::DataBrowserGetContextualMenuProc(MenuRef
* menu
, UInt32
* helpType
, CFStringRef
* helpItemString
, AEDesc
* WXUNUSED(selection
))
639 // In this method we do not supply a contextual menu handler at all but only send a wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU.
641 wxArrayDataBrowserItemID itemIDs
;
643 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer()));
646 wxCHECK_RET(dataViewCtrlPtr
!= NULL
,_("wxWidget control pointer is not a data view pointer"));
647 // initialize parameters so that no context menu will be displayed automatically by the native data browser:
649 *helpType
= kCMHelpItemNoHelp
;
650 *helpItemString
= NULL
;
651 // create information for a context menu event:
652 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
,dataViewCtrlPtr
->GetId());
654 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
655 dataViewEvent
.SetModel(dataViewCtrlPtr
->GetModel());
656 // get the item information;
657 // theoretically more than one ID can be returned but the event can only handle one item, therefore all item related data is using the data of the first item in the array:
658 if (this->GetSelectedItemIDs(itemIDs
) > 0)
659 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemIDs
[0])));
660 // finally send the equivalent wxWidget event:
661 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
662 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetContextualMenuProc(MenuRef*, UInt32*, CFStringRef*, AEDesc*) */
664 OSStatus
wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemDataRef itemData
, Boolean getValue
)
668 // variable definitions:
669 wxDataViewCtrl
* dataViewCtrlPtr
;
671 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer());
672 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
673 if (dataViewCtrlPtr
->IsDeleting())
674 return noErr
; // if a delete process is running the data of editable fields cannot be saved because the associated model variable may already have been deleted
677 // variable definitions:
678 OSStatus errorStatus
;
679 wxDataViewColumn
* dataViewColumnPtr
;
681 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,errDataBrowserNotConfigured
,_("Pointer to model not set correctly."));
682 dataViewColumnPtr
= dataViewCtrlPtr
->GetColumnPtr(propertyID
);
683 wxCHECK_MSG((dataViewColumnPtr
!= NULL
) && (dataViewColumnPtr
->GetRenderer() != NULL
),errDataBrowserNotConfigured
,_("There is no column or renderer for the specified column index."));
685 wxDataViewItem
dvItem(reinterpret_cast<void*>(itemID
));
686 unsigned int col
= dataViewColumnPtr
->GetModelColumn();
688 switch (dataViewColumnPtr
->GetRenderer()->GetPropertyType())
690 case kDataBrowserCheckboxType
:
692 // variable definition:
693 ThemeButtonValue buttonValue
;
695 errorStatus
= ::GetDataBrowserItemDataButtonValue(itemData
,&buttonValue
);
696 if (errorStatus
== noErr
)
698 if (buttonValue
== kThemeButtonOn
)
700 // variable definition and initialization:
701 wxVariant
modifiedData(true);
703 if (dataViewCtrlPtr
->GetModel()->SetValue(modifiedData
, dvItem
, col
) &&
704 dataViewCtrlPtr
->GetModel()->ValueChanged(dvItem
, col
))
707 return errDataBrowserInvalidPropertyData
;
709 else if (buttonValue
== kThemeButtonOff
)
711 // variable definition and initialization:
712 wxVariant
modifiedData(false);
714 if (dataViewCtrlPtr
->GetModel()->SetValue(modifiedData
, dvItem
, col
) &&
715 dataViewCtrlPtr
->GetModel()->ValueChanged(dvItem
, col
))
718 return errDataBrowserInvalidPropertyData
;
721 return errDataBrowserInvalidPropertyData
;
726 case kDataBrowserTextType
:
728 // variable definitions:
729 CFStringRef stringReference
;
731 errorStatus
= ::GetDataBrowserItemDataText(itemData
,&stringReference
);
732 if (errorStatus
== noErr
)
734 // variable definitions and initializations:
735 #if wxCHECK_VERSION(2,9,0)
736 wxCFStringRef
modifiedString(stringReference
);
738 wxMacCFStringHolder
modifiedString(stringReference
);
740 wxVariant
modifiedData(modifiedString
.AsString());
742 if (dataViewCtrlPtr
->GetModel()->SetValue(modifiedData
, dvItem
, col
) &&
743 dataViewCtrlPtr
->GetModel()->ValueChanged(dvItem
, col
))
746 return errDataBrowserInvalidPropertyData
;
752 return errDataBrowserPropertyNotSupported
;
758 if (propertyID
>= kMinPropertyID
) // in case data columns set the data
760 // variable definitions:
762 wxDataViewColumn
* dataViewColumnPtr
;
763 wxDataViewCtrl
* dataViewCtrlPtr
;
765 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer());
766 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
767 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,errDataBrowserNotConfigured
,_("Pointer to model not set correctly."));
768 dataViewColumnPtr
= dataViewCtrlPtr
->GetColumnPtr(propertyID
);
769 wxCHECK_MSG(dataViewColumnPtr
!= NULL
,errDataBrowserNotConfigured
,_("No column for the specified column position existing."));
770 wxCHECK_MSG(dataViewColumnPtr
->GetRenderer() != NULL
,errDataBrowserNotConfigured
,_("No renderer specified for column."));
771 dataViewCtrlPtr
->GetModel()->GetValue(variant
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),dataViewColumnPtr
->GetModelColumn());
772 if (!(variant
.IsNull()))
774 dataViewColumnPtr
->GetRenderer()->SetDataReference(itemData
);
775 dataViewColumnPtr
->GetRenderer()->SetValue(variant
);
776 wxCHECK_MSG(dataViewColumnPtr
->GetRenderer()->Render(),errDataBrowserNotConfigured
,_("Rendering failed."));
780 else // react on special system requests
784 case kDataBrowserContainerIsClosableProperty
:
786 // variable definitions:
787 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer()));
789 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
790 // initialize wxWidget event:
791 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,dataViewCtrlPtr
->GetId()); // variable definition
793 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
794 dataViewEvent
.SetItem (wxDataViewItem(reinterpret_cast<void*>(itemID
)));
795 dataViewEvent
.SetModel (dataViewCtrlPtr
->GetModel());
796 // finally send the equivalent wxWidget event:
797 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
798 // opening the container is allowed if not vetoed:
799 return ::SetDataBrowserItemDataBooleanValue(itemData
,dataViewEvent
.IsAllowed());
801 case kDataBrowserContainerIsOpenableProperty
:
803 // variable definitions:
804 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer()));
806 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
807 // initialize wxWidget event:
808 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
,dataViewCtrlPtr
->GetId()); // variable definition
810 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
811 dataViewEvent
.SetItem (wxDataViewItem(reinterpret_cast<void*>(itemID
)));
812 dataViewEvent
.SetModel (dataViewCtrlPtr
->GetModel());
813 // finally send the equivalent wxWidget event:
814 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
815 // opening the container is allowed if not vetoed:
816 return ::SetDataBrowserItemDataBooleanValue(itemData
,dataViewEvent
.IsAllowed());
818 case kDataBrowserItemIsContainerProperty
:
820 // variable definition:
821 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer()));
823 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
824 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,errDataBrowserNotConfigured
,_("Pointer to model not set correctly."));
825 return ::SetDataBrowserItemDataBooleanValue(itemData
,dataViewCtrlPtr
->GetModel()->IsContainer(wxDataViewItem(reinterpret_cast<void*>(itemID
))));
827 case kDataBrowserItemIsEditableProperty
:
828 return ::SetDataBrowserItemDataBooleanValue(itemData
,true);
832 return errDataBrowserPropertyNotSupported
;
833 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */
835 void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
)
837 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer()));
840 // check if the data view control pointer still exists because this call back function can still be called when the control has already been deleted:
841 if (dataViewCtrlPtr
!= NULL
)
844 case kDataBrowserContainerClosed
:
845 dataViewCtrlPtr
->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
847 // initialize wxWidget event:
848 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,dataViewCtrlPtr
->GetId()); // variable definition
850 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
851 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
852 // finally send the equivalent wxWidget event:
853 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
856 case kDataBrowserContainerOpened
:
857 dataViewCtrlPtr
->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
859 // initialize wxWidget event:
860 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,dataViewCtrlPtr
->GetId()); // variable definition
862 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
863 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
864 // finally send the equivalent wxWidget event:
865 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
866 // add children to the expanded container:
867 dataViewCtrlPtr
->AddChildrenLevel(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
870 case kDataBrowserEditStarted
:
871 dataViewCtrlPtr
->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
873 // initialize wxWidget event:
874 DataBrowserPropertyID propertyID
;
875 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
,dataViewCtrlPtr
->GetId()); // variable definition
877 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
878 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
879 if (this->GetPropertyID(itemData
,&propertyID
) == noErr
)
881 // variable definition and initialization:
882 DataBrowserTableViewColumnIndex columnIndex
;
884 wxCHECK_RET(this->GetColumnIndex(propertyID
,&columnIndex
),_("Column index not found."));
885 dataViewEvent
.SetColumn(columnIndex
);
886 dataViewEvent
.SetDataViewColumn(dataViewCtrlPtr
->GetColumnPtr(propertyID
));
888 // finally send the equivalent wxWidget event:
889 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
892 case kDataBrowserEditStopped
:
894 // initialize wxWidget event:
895 DataBrowserPropertyID propertyID
;
896 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
,dataViewCtrlPtr
->GetId()); // variable definition
898 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
899 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
900 if (this->GetPropertyID(itemData
,&propertyID
) == noErr
)
902 // variable definition and initialization:
903 DataBrowserTableViewColumnIndex columnIndex
;
905 wxCHECK_RET(this->GetColumnIndex(propertyID
,&columnIndex
),_("Column index not found."));
906 dataViewEvent
.SetColumn(columnIndex
);
907 dataViewEvent
.SetDataViewColumn(dataViewCtrlPtr
->GetColumnPtr(propertyID
));
909 // finally send the equivalent wxWidget event:
910 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
913 case kDataBrowserItemAdded
:
914 dataViewCtrlPtr
->FinishCustomItemEditing();
916 case kDataBrowserItemDeselected
:
917 dataViewCtrlPtr
->FinishCustomItemEditing();
919 case kDataBrowserItemDoubleClicked
:
921 // initialize wxWidget event:
922 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
,dataViewCtrlPtr
->GetId()); // variable definition
924 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
925 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
926 // finally send the equivalent wxWidget event:
927 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
930 case kDataBrowserItemRemoved
:
931 dataViewCtrlPtr
->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
933 case kDataBrowserItemSelected
:
934 break; // not implemented by wxWidgets; see kDataBrowserSelectionSetChanged
935 case kDataBrowserSelectionSetChanged
:
937 // initialize wxWidget event:
938 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
,dataViewCtrlPtr
->GetId()); // variable definition
940 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
941 dataViewEvent
.SetModel (dataViewCtrlPtr
->GetModel());
942 // finally send the equivalent wxWidget event:
943 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
946 case kDataBrowserTargetChanged
: // no idea if this notification is ever sent
948 case kDataBrowserUserStateChanged
:
950 // finish custom item editing if necessary:
951 dataViewCtrlPtr
->FinishCustomItemEditing();
952 // update column widths:
953 for (size_t i
=0; i
<dataViewCtrlPtr
->GetColumnCount(); ++i
)
955 // constant definition for abbreviational purposes:
956 wxDataViewColumn
* const columnPtr
= dataViewCtrlPtr
->GetColumn(i
);
957 // variable definition:
960 wxCHECK_RET(this->GetColumnWidth(columnPtr
->GetPropertyID(),&columnWidth
) == noErr
,_("Column width could not be determined"));
961 columnPtr
->SetWidthVariable(columnWidth
);
963 // update sorting orders:
964 DataBrowserPropertyID propertyID
; // variable definition
966 if ((this->GetSortProperty(&propertyID
) == noErr
) && (propertyID
>= kMinPropertyID
))
968 DataBrowserSortOrder sortOrder
;
969 DataBrowserTableViewColumnIndex columnIndex
;
971 if ((this->GetSortOrder(&sortOrder
) == noErr
) && (this->GetColumnIndex(propertyID
,&columnIndex
) == noErr
))
973 // variable definition and initialization:
974 wxDataViewColumn
* columnPtr
;
975 columnPtr
= dataViewCtrlPtr
->GetColumn(columnIndex
);
976 // check if the sort order has changed:
977 if ( columnPtr
->IsSortOrderAscending() && (sortOrder
== kDataBrowserOrderDecreasing
) ||
978 !(columnPtr
->IsSortOrderAscending()) && (sortOrder
== kDataBrowserOrderIncreasing
))
980 columnPtr
->SetSortOrder(!(columnPtr
->IsSortOrderAscending()));
981 // initialize wxWidget event:
982 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
,dataViewCtrlPtr
->GetId()); // variable defintion
984 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
985 dataViewEvent
.SetColumn(columnIndex
);
986 dataViewEvent
.SetDataViewColumn(columnPtr
);
987 // finally send the equivalent wxWidget event:
988 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
995 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */
997 void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
)
999 DataBrowserTableViewColumnIndex columnIndex
;
1001 wxDataViewColumn
* dataViewColumnPtr
;
1003 wxDataViewCtrl
* dataViewCtrlPtr
;
1005 wxDataViewCustomRenderer
* dataViewCustomRendererPtr
;
1007 wxVariant dataToRender
;
1009 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer());
1010 wxCHECK_RET(dataViewCtrlPtr
!= NULL
, _("Pointer to data view control not set correctly."));
1011 wxCHECK_RET(dataViewCtrlPtr
->GetModel() != NULL
,_("Pointer to model not set correctly."));
1012 wxCHECK_RET(this->GetColumnIndex(propertyID
,&columnIndex
) == noErr
,_("Could not determine column index."));
1013 dataViewColumnPtr
= dataViewCtrlPtr
->GetColumnPtr(propertyID
);
1014 wxCHECK_RET(dataViewColumnPtr
!= NULL
,_("No column for the specified column index existing."));
1015 dataViewCustomRendererPtr
= dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer());
1016 wxCHECK_RET(dataViewCustomRendererPtr
!= NULL
,_("No renderer or invalid renderer type specified for custom data column."));
1017 dataViewCtrlPtr
->GetModel()->GetValue(dataToRender
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),dataViewColumnPtr
->GetModelColumn());
1018 dataViewCustomRendererPtr
->SetValue(dataToRender
);
1020 wxDataViewItem
dataitem( reinterpret_cast<void*>(itemID
) );
1021 dataViewCtrlPtr
->GetModel()->GetValue(dataToRender
,dataitem
,dataViewColumnPtr
->GetModelColumn());
1022 dataViewCustomRendererPtr
->SetValue(dataToRender
);
1024 // try to determine the content's size (drawable part):
1026 RgnHandle
rgn(NewRgn());
1027 UInt16 headerHeight
;
1029 if (this->GetRegion(kControlContentMetaPart
,rgn
) == noErr
)
1030 GetRegionBounds(rgn
,&content
);
1032 GetControlBounds(m_controlRef
, &content
);
1034 // space for the header
1035 this->GetHeaderButtonHeight(&headerHeight
);
1036 content
.top
+= headerHeight
;
1037 // extra space for the frame (todo: do not how to determine the space automatically from the control)
1041 content
.bottom
-= 3;
1042 // extra space for the scrollbars:
1043 content
.bottom
-= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
1044 content
.right
-= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1046 wxDC
*dc
= dataViewCustomRendererPtr
->GetDC();
1048 wxRect
cellrect( static_cast<int>(rectangle
->left
),
1049 static_cast<int>(rectangle
->top
),
1050 static_cast<int>(1+rectangle
->right
-rectangle
->left
),
1051 static_cast<int>(rectangle
->bottom
-rectangle
->top
) );
1053 bool is_active
= IsControlActive( this->m_controlRef
);
1054 if (state
== kDataBrowserItemIsSelected
)
1057 wxColour
col( wxMacCreateCGColorFromHITheme( (is_active
) ?
1058 kThemeBrushAlternatePrimaryHighlightColor
1059 : kThemeBrushSecondaryHighlightColor
) );
1061 wxRect rect
= cellrect
;
1063 GetDataBrowserItemPartBounds( this->m_controlRef
, itemID
, propertyID
,
1064 kDataBrowserPropertyEnclosingPart
, &itemrect
);
1065 rect
.x
= itemrect
.left
;
1066 rect
.width
= itemrect
.right
-itemrect
.left
+1;
1068 wxBrush
selBrush( col
);
1069 wxPen
oldpen( dc
->GetPen() );
1070 wxBrush
oldbrush( dc
->GetBrush() );
1071 dc
->SetPen( *wxTRANSPARENT_PEN
);
1072 dc
->SetBrush( selBrush
);
1073 dc
->DrawRectangle(rect
);
1074 dc
->SetBrush( oldbrush
);
1075 dc
->SetPen( oldpen
);
1078 wxDataViewModel
*model
= dataViewCtrlPtr
->GetModel();
1079 if ((columnIndex
== 0) || !model
->IsContainer(dataitem
) || model
->HasContainerColumns(dataitem
))
1081 // make sure that 'Render' can draw only in the allowed area:
1082 dc
->SetClippingRegion(content
.left
,content
.top
,content
.right
-content
.left
+1,content
.bottom
-content
.top
+1);
1083 (void) (dataViewCustomRendererPtr
->Render( cellrect
, dc
,
1084 ((state
== kDataBrowserItemIsSelected
) ? wxDATAVIEW_CELL_SELECTED
: 0)));
1085 dc
->DestroyClippingRegion(); // probably not necessary
1088 dataViewCustomRendererPtr
->SetDC(NULL
);
1089 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */
1091 Boolean
wxMacDataViewDataBrowserListViewControl::DataBrowserEditItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, CFStringRef theString
, Rect
* maxEditTextRect
, Boolean
* shrinkToFit
)
1094 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserEditItemProc(DataBrowserItemID, DataBrowserPropertyID, CFStringRef, Rect*, Boolean*) */
1096 Boolean
wxMacDataViewDataBrowserListViewControl::DataBrowserHitTestProc(DataBrowserItemID
WXUNUSED(itemID
), DataBrowserPropertyID
WXUNUSED(property
), Rect
const* WXUNUSED(theRect
), Rect
const* WXUNUSED(mouseRect
))
1099 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserHitTestProc(DataBrowserItemID, DataBrowserPropertyID, Rect const*, Rect const*) */
1101 DataBrowserTrackingResult
wxMacDataViewDataBrowserListViewControl::DataBrowserTrackingProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Point
WXUNUSED(startPt
), EventModifiers
WXUNUSED(modifiers
))
1103 wxDataViewColumn
* dataViewColumnPtr
;
1105 wxDataViewCtrl
* dataViewCtrlPtr
;
1107 wxDataViewCustomRenderer
* dataViewCustomRendererPtr
;
1109 wxDataViewItem dataViewCustomRendererItem
;
1112 dataViewCustomRendererItem
= reinterpret_cast<void*>(itemID
);
1113 wxCHECK_MSG(dataViewCustomRendererItem
.IsOk(),kDataBrowserNothingHit
,_("Invalid data view item"));
1114 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer());
1115 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,kDataBrowserNothingHit
,_("Pointer to data view control not set correctly."));
1116 dataViewColumnPtr
= dataViewCtrlPtr
->GetColumnPtr(propertyID
);
1117 wxCHECK_MSG(dataViewColumnPtr
!= NULL
,kDataBrowserNothingHit
,_("No column existing."));
1118 dataViewCustomRendererPtr
= dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer());
1119 wxCHECK_MSG(dataViewCustomRendererPtr
!= NULL
,kDataBrowserNothingHit
,_("No renderer or invalid renderer type specified for custom data column."));
1120 // if the currently edited item is identical to the to be edited nothing is done (this hit should only be handled in the control itself):
1121 if (dataViewCtrlPtr
->GetCustomRendererItem() == dataViewCustomRendererItem
)
1122 return kDataBrowserContentHit
;
1123 // an(other) item is going to be edited and therefore the current editing - if existing - has to be finished:
1124 if (dataViewCtrlPtr
->GetCustomRendererPtr() != NULL
)
1126 dataViewCtrlPtr
->GetCustomRendererPtr()->FinishEditing();
1127 dataViewCtrlPtr
->SetCustomRendererItem(wxDataViewItem());
1128 dataViewCtrlPtr
->SetCustomRendererPtr (NULL
);
1130 // check if renderer has got a valid editor control for editing; if this is the case start editing of the new item:
1131 if (dataViewCustomRendererPtr
->HasEditorCtrl())
1133 // variable definition:
1136 ::wxMacNativeToRect(theRect
,&wxRectangle
);
1137 dataViewCustomRendererPtr
->StartEditing(dataViewCustomRendererItem
,wxRectangle
);
1138 dataViewCtrlPtr
->SetCustomRendererItem(dataViewCustomRendererItem
);
1139 dataViewCtrlPtr
->SetCustomRendererPtr (dataViewCustomRendererPtr
);
1141 return kDataBrowserContentHit
;
1142 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserTrackingProc(DataBrowserItemID, DataBrowserPropertyID, Rect const*, Point, EventModifiers) */
1144 #endif // wxUSE_GENERICDATAVIEWCTRL
1145 #endif // wxUSE_DATAVIEWCTRL