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
16 #include "wx/wxprec.h"
19 #include "wx/toplevel.h"
23 #include "wx/dataview.h"
26 #include "wx/mac/carbon/databrow.h"
27 #include "wx/mac/private.h"
28 #include "wx/mac/uma.h"
30 // ============================================================================
31 // Variables used globally in databrow.cpp
32 // ============================================================================
33 DataBrowserGetContextualMenuUPP gDataBrowserTableViewGetContextualMenuUPP
= NULL
;
34 DataBrowserItemCompareUPP gDataBrowserTableViewItemCompareUPP
= NULL
;
35 DataBrowserItemDataUPP gDataBrowserTableViewItemDataUPP
= NULL
;
36 DataBrowserItemNotificationUPP gDataBrowserTableViewItemNotificationUPP
= NULL
;
38 DataBrowserDrawItemUPP gDataBrowserTableViewDrawItemUPP
= NULL
;
39 DataBrowserEditItemUPP gDataBrowserTableViewEditItemUPP
= NULL
;
40 DataBrowserHitTestUPP gDataBrowserTableViewHitTestUPP
= NULL
;
41 DataBrowserTrackingUPP gDataBrowserTableViewTrackingUPP
= NULL
;
43 // ============================================================================
44 // wxMacDataBrowserTableViewControl
45 // ============================================================================
47 pascal Boolean
wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlRef browser
, DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
)
49 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
52 if (ControlPtr
!= NULL
)
53 return ControlPtr
->DataBrowserCompareProc(itemOneID
,itemTwoID
,sortProperty
);
55 return errDataBrowserPropertyNotSupported
;
56 } /* wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlRef, DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
58 pascal void wxMacDataBrowserTableViewControl::DataBrowserGetContextualMenuProc(ControlRef browser
, MenuRef
* menu
, UInt32
* helpType
, CFStringRef
* helpItemString
, AEDesc
* selection
)
60 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
63 if (ControlPtr
!= NULL
)
64 ControlPtr
->DataBrowserGetContextualMenuProc(menu
,helpType
,helpItemString
,selection
);
65 } /* wxMacDataBrowserTableViewControl::DataBrowserGetContextualMenuProc(ControlRef, MenuRef*, UInt32*, CFStringRef*, AEDesc*) */
67 pascal OSStatus
wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemDataRef itemData
, Boolean getValue
)
69 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
72 if (ControlPtr
!= NULL
)
73 return ControlPtr
->DataBrowserGetSetItemDataProc(itemID
,propertyID
,itemData
,getValue
);
75 return errDataBrowserPropertyNotSupported
;
76 } /* wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */
78 pascal void wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
)
80 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
83 if (ControlPtr
!= NULL
)
84 ControlPtr
->DataBrowserItemNotificationProc(itemID
,message
,itemData
);
85 } /* wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc(ControlRef, DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */
87 pascal void wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
)
89 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
92 if (ControlPtr
!= NULL
)
93 ControlPtr
->DataBrowserDrawItemProc(itemID
,propertyID
,state
,rectangle
,bitDepth
,colorDevice
);
94 } /* wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */
96 pascal Boolean
wxMacDataBrowserTableViewControl::DataBrowserEditItemProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, CFStringRef theString
, Rect
* maxEditTextRect
, Boolean
* shrinkToFit
)
98 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
101 return ((ControlPtr
!= NULL
) && ControlPtr
->DataBrowserEditItemProc(itemID
,propertyID
,theString
,maxEditTextRect
,shrinkToFit
));
102 } /* wxMacDataBrowserTableViewControl::DataBrowserEditItemProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, CFStringRef, Rect*, Boolean*) */
104 pascal Boolean
wxMacDataBrowserTableViewControl::DataBrowserHitTestProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Rect
const* mouseRect
)
106 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
109 return ((ControlPtr
!= NULL
) && ControlPtr
->DataBrowserHitTestProc(itemID
,propertyID
,theRect
,mouseRect
));
110 } /* wxMacDataBrowserTableViewControl::DataBrowserHitTestProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, Rect const*, Rect const*) */
112 pascal DataBrowserTrackingResult
wxMacDataBrowserTableViewControl::DataBrowserTrackingProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Point startPt
, EventModifiers modifiers
)
114 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
117 if (ControlPtr
!= NULL
)
118 return ControlPtr
->DataBrowserTrackingProc(itemID
,propertyID
,theRect
,startPt
,modifiers
);
120 return kDataBrowserNothingHit
;
121 } /* wxMacDataBrowserTableViewControl::DataBrowserTrackingProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, Rect const*, Point, EventModifiers) */
123 wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow
* peer
, wxPoint
const& pos
, wxSize
const& size
, long style
)
126 Rect bounds
= wxMacGetBoundsForControl(peer
,pos
,size
);
127 OSStatus err
= ::CreateDataBrowserControl(MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),&bounds
,kDataBrowserListView
,&(this->m_controlRef
));
130 SetReferenceInNativeControl();
132 // setup standard callbacks:
133 if (gDataBrowserTableViewGetContextualMenuUPP
== NULL
) gDataBrowserTableViewGetContextualMenuUPP
= NewDataBrowserGetContextualMenuUPP(wxMacDataBrowserTableViewControl::DataBrowserGetContextualMenuProc
);
134 if (gDataBrowserTableViewItemCompareUPP
== NULL
) gDataBrowserTableViewItemCompareUPP
= NewDataBrowserItemCompareUPP (wxMacDataBrowserTableViewControl::DataBrowserCompareProc
);
135 if (gDataBrowserTableViewItemDataUPP
== NULL
) gDataBrowserTableViewItemDataUPP
= NewDataBrowserItemDataUPP (wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc
);
136 if (gDataBrowserTableViewItemNotificationUPP
== NULL
)
138 gDataBrowserTableViewItemNotificationUPP
=
139 #if TARGET_API_MAC_OSX
140 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc
);
142 NewDataBrowserItemNotificationUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc
);
145 DataBrowserCallbacks callbacks
; // variable definition
147 InitializeDataBrowserCallbacks(&callbacks
,kDataBrowserLatestCallbacks
);
148 callbacks
.u
.v1
.getContextualMenuCallback
= gDataBrowserTableViewGetContextualMenuUPP
;
149 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserTableViewItemDataUPP
;
150 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserTableViewItemCompareUPP
;
151 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserTableViewItemNotificationUPP
;
152 this->SetCallbacks(&callbacks
);
154 // setup callbacks for customized items:
155 if (gDataBrowserTableViewDrawItemUPP
== NULL
) gDataBrowserTableViewDrawItemUPP
= NewDataBrowserDrawItemUPP(wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc
);
156 if (gDataBrowserTableViewEditItemUPP
== NULL
) gDataBrowserTableViewEditItemUPP
= NewDataBrowserEditItemUPP(wxMacDataBrowserTableViewControl::DataBrowserEditItemProc
);
157 if (gDataBrowserTableViewHitTestUPP
== NULL
) gDataBrowserTableViewHitTestUPP
= NewDataBrowserHitTestUPP (wxMacDataBrowserTableViewControl::DataBrowserHitTestProc
);
158 if (gDataBrowserTableViewTrackingUPP
== NULL
) gDataBrowserTableViewTrackingUPP
= NewDataBrowserTrackingUPP(wxMacDataBrowserTableViewControl::DataBrowserTrackingProc
);
160 DataBrowserCustomCallbacks customCallbacks
; // variable definition
162 InitializeDataBrowserCustomCallbacks(&customCallbacks
,kDataBrowserLatestCallbacks
);
163 customCallbacks
.u
.v1
.drawItemCallback
= gDataBrowserTableViewDrawItemUPP
;
164 customCallbacks
.u
.v1
.editTextCallback
= gDataBrowserTableViewEditItemUPP
;
165 customCallbacks
.u
.v1
.hitTestCallback
= gDataBrowserTableViewHitTestUPP
;
166 customCallbacks
.u
.v1
.trackingCallback
= gDataBrowserTableViewTrackingUPP
;
167 this->SetCustomCallbacks(&customCallbacks
);
170 this->EnableCellSizeModification();
172 DataBrowserSelectionFlags flags
; // variable definition
174 if (this->GetSelectionFlags(&flags
) == noErr
) // get default settings
176 if ((style
& wxDV_MULTIPLE
) != 0)
177 flags
&= ~kDataBrowserSelectOnlyOne
;
179 flags
|= kDataBrowserSelectOnlyOne
;
180 (void) this->SetSelectionFlags(flags
);
183 OptionBits attributes
; // variable definition
185 if (this->GetAttributes(&attributes
) == noErr
) // get default settings
187 if ((style
& wxDV_VERT_RULES
) != 0)
188 attributes
|= kDataBrowserAttributeListViewDrawColumnDividers
;
190 attributes
&= ~kDataBrowserAttributeListViewDrawColumnDividers
;
191 if ((style
& wxDV_ROW_LINES
) != 0)
192 attributes
|= kDataBrowserAttributeListViewAlternatingRowColors
;
194 attributes
&= ~kDataBrowserAttributeListViewAlternatingRowColors
;
195 (void) this->SetAttributes(attributes
);
198 if ((style
& wxDV_NO_HEADER
) != 0)
199 this->SetHeaderButtonHeight(0);
200 } /* wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow*, wxPoint const&, wxSize const&, long) */
205 OSStatus
wxMacDataBrowserTableViewControl::SetCallbacks(DataBrowserCallbacks
const* callbacks
)
207 return ::SetDataBrowserCallbacks(this->m_controlRef
,callbacks
);
208 } /* wxMacDataBrowserTableViewControl::SetCallbacks(DataBrowserCallbacks const*) */
210 OSStatus
wxMacDataBrowserTableViewControl::SetCustomCallbacks(DataBrowserCustomCallbacks
const* customCallbacks
)
212 return ::SetDataBrowserCustomCallbacks(this->m_controlRef
,customCallbacks
);
213 } /* xMacDataBrowserTableViewControl::SetCustomCallbacks(DataBrowserCustomCallbacks const*) */
218 OSStatus
wxMacDataBrowserTableViewControl::GetHeaderDesc(DataBrowserPropertyID propertyID
, DataBrowserListViewHeaderDesc
* desc
) const
220 desc
->version
= kDataBrowserListViewLatestHeaderDesc
; // if this statement is missing the next call will fail (NOT DOCUMENTED!!)
221 return ::GetDataBrowserListViewHeaderDesc(this->m_controlRef
,propertyID
,desc
);
224 OSStatus
wxMacDataBrowserTableViewControl::SetHeaderDesc(DataBrowserPropertyID propertyID
, DataBrowserListViewHeaderDesc
* desc
)
226 return ::SetDataBrowserListViewHeaderDesc(this->m_controlRef
,propertyID
,desc
);
232 OSStatus
wxMacDataBrowserTableViewControl::AutoSizeColumns()
234 return AutoSizeDataBrowserListViewColumns(this->m_controlRef
);
237 OSStatus
wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool enableHeight
, bool enableWidth
)
239 return ::SetDataBrowserTableViewGeometry(this->GetControlRef(),enableWidth
,enableHeight
);
240 } /* wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool, bool) */
242 OSStatus
wxMacDataBrowserTableViewControl::GetAttributes(OptionBits
* attributes
)
244 return ::DataBrowserGetAttributes(this->GetControlRef(),attributes
);
245 } /* wxMacDataBrowserTableViewControl::GetAttributes(OptionBits*) */
247 OSStatus
wxMacDataBrowserTableViewControl::GetColumnWidth(DataBrowserPropertyID propertyID
, UInt16
* width
) const
249 return ::GetDataBrowserTableViewNamedColumnWidth(this->m_controlRef
,propertyID
,width
);
252 OSStatus
wxMacDataBrowserTableViewControl::GetDefaultColumnWidth( UInt16
*width
) const
254 return GetDataBrowserTableViewColumnWidth(this->m_controlRef
, width
);
257 OSStatus
wxMacDataBrowserTableViewControl::GetDefaultRowHeight(UInt16
* height
) const
259 return ::GetDataBrowserTableViewRowHeight(this->m_controlRef
,height
);
262 OSStatus
wxMacDataBrowserTableViewControl::GetHeaderButtonHeight(UInt16
*height
)
264 return ::GetDataBrowserListViewHeaderBtnHeight(this->m_controlRef
,height
);
267 OSStatus
wxMacDataBrowserTableViewControl::GetPartBounds(DataBrowserItemID item
, DataBrowserPropertyID propertyID
, DataBrowserPropertyPart part
, Rect
* bounds
)
269 return ::GetDataBrowserItemPartBounds(this->m_controlRef
,item
,propertyID
,part
,bounds
);
270 } /* wxMacDataBrowserTableViewControl::GetPartBounds(DataBrowserItemID, DataBrowswerPropertyID, DataBrowserPropertyPart, Rect*) */
272 OSStatus
wxMacDataBrowserTableViewControl::GetRowHeight(DataBrowserItemID item
, UInt16
* height
) const
274 return ::GetDataBrowserTableViewItemRowHeight(this->m_controlRef
,item
,height
);
275 } /* wxMacDataBrowserTableViewControl::GetRowHeight(DataBrowserItemID, UInt16*) const */
277 OSStatus
wxMacDataBrowserTableViewControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
279 return GetDataBrowserScrollPosition(this->m_controlRef
, top
, left
);
282 OSStatus
wxMacDataBrowserTableViewControl::SetAttributes(OptionBits attributes
)
284 return ::DataBrowserChangeAttributes(this->GetControlRef(),attributes
,~attributes
);
285 } /* wxMacDataBrowserTableViewControl::SetAttributes(OptionBits) */
287 OSStatus
wxMacDataBrowserTableViewControl::SetColumnWidth(DataBrowserPropertyID propertyID
, UInt16 width
)
289 return ::SetDataBrowserTableViewNamedColumnWidth(this->m_controlRef
,propertyID
,width
);
292 OSStatus
wxMacDataBrowserTableViewControl::SetDefaultColumnWidth(UInt16 width
)
294 return ::SetDataBrowserTableViewColumnWidth(this->m_controlRef
,width
);
297 OSStatus
wxMacDataBrowserTableViewControl::SetDefaultRowHeight(UInt16 height
)
299 return ::SetDataBrowserTableViewRowHeight(this->m_controlRef
,height
);
302 OSStatus
wxMacDataBrowserTableViewControl::SetHasScrollBars(bool horiz
, bool vert
)
304 return ::SetDataBrowserHasScrollBars(this->m_controlRef
,horiz
,vert
);
305 } /* wxMacDataBrowserTableViewControl::SetHasScrollBars(bool, bool) */
307 OSStatus
wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16 height
)
309 return ::SetDataBrowserListViewHeaderBtnHeight(this->m_controlRef
,height
);
310 } /* wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16) */
312 OSStatus
wxMacDataBrowserTableViewControl::SetHiliteStyle(DataBrowserTableViewHiliteStyle hiliteStyle
)
314 return ::SetDataBrowserTableViewHiliteStyle(this->m_controlRef
,hiliteStyle
);
315 } /*wxMacDataBrowserTableViewControl::SetHiliteStyle(DataBrowserTableViewHiliteStyle) */
317 OSStatus
wxMacDataBrowserTableViewControl::SetIndent(float Indent
)
319 return ::DataBrowserSetMetric(this->m_controlRef
,kDataBrowserMetricDisclosureColumnPerDepthGap
,true,Indent
);
320 } /* wxMacDataBrowserTableViewControl::SetIndent(float* Indent) */
322 OSStatus
wxMacDataBrowserTableViewControl::SetRowHeight(DataBrowserItemID item
, UInt16 height
)
324 return ::SetDataBrowserTableViewItemRowHeight(this->m_controlRef
,item
,height
);
327 OSStatus
wxMacDataBrowserTableViewControl::SetScrollPosition(UInt32 top
, UInt32 left
)
329 return ::SetDataBrowserScrollPosition(this->m_controlRef
,top
,left
);
335 OSStatus
wxMacDataBrowserTableViewControl::GetColumnCount(UInt32
* numColumns
) const
337 return ::GetDataBrowserTableViewColumnCount(this->m_controlRef
,numColumns
);
340 OSStatus
wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID propertyID
, DataBrowserTableViewColumnIndex
* index
) const
342 return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef
,propertyID
,index
);
343 } /* wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex*) const */
345 OSStatus
wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID
* propertyID
) const
347 for (*propertyID
=kMinPropertyID
; *propertyID
<std::numeric_limits
<DataBrowserPropertyID
>::max(); ++(*propertyID
))
348 if (this->IsUsedPropertyID(*propertyID
) == errDataBrowserPropertyNotFound
)
350 return errDataBrowserPropertyNotSupported
;
351 } /* wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID*) const */
353 OSStatus
wxMacDataBrowserTableViewControl::GetPropertyFlags(DataBrowserPropertyID propertyID
, DataBrowserPropertyFlags
*flags
) const
355 return ::GetDataBrowserPropertyFlags(this->m_controlRef
,propertyID
,flags
);
358 OSStatus
wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef itemData
, DataBrowserPropertyID
* propertyID
)
360 return ::GetDataBrowserItemDataProperty(itemData
,propertyID
);
361 } /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef, DataBrowserPropertyID*) */
363 OSStatus
wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex index
, DataBrowserTableViewColumnID
* propertyID
)
365 return ::GetDataBrowserTableViewColumnProperty(this->m_controlRef
,index
,propertyID
);
366 } /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex, DataBrowserTableViewColumnID*) */
368 OSStatus
wxMacDataBrowserTableViewControl::IsUsedPropertyID(DataBrowserPropertyID propertyID
) const
370 // 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
371 // 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
372 // the column position for the property id:
373 DataBrowserTableViewColumnIndex index
;
375 return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef
,propertyID
,&index
);
376 } /* wxMacDataBrowserTableViewControl::IsUsedPropertyId(DataBrowserPropertyID) const */
378 OSStatus
wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID propertyID
)
380 return ::RemoveDataBrowserTableViewColumn(this->m_controlRef
,propertyID
);
381 } /* wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID) */
383 OSStatus
wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex index
)
385 DataBrowserTableViewColumnID propertyID
;
388 this->GetPropertyID(index
,&propertyID
);
389 return ::RemoveDataBrowserTableViewColumn(this->m_controlRef
,propertyID
);
390 } /* wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex) */
392 OSStatus
wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID propertyID
, DataBrowserTableViewColumnIndex index
)
394 return ::SetDataBrowserTableViewColumnPosition(this->m_controlRef
,propertyID
,index
);
395 } /* wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex) */
397 OSStatus
wxMacDataBrowserTableViewControl::SetDisclosureColumn(DataBrowserPropertyID propertyID
, Boolean expandableRows
)
399 return ::SetDataBrowserListViewDisclosureColumn(this->m_controlRef
,propertyID
,expandableRows
);
402 OSStatus
wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID propertyID
, DataBrowserPropertyFlags flags
)
404 return ::SetDataBrowserPropertyFlags(this->m_controlRef
,propertyID
,flags
);
405 } /* wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID, DataBrowserPropertyFlags) */
410 OSStatus
wxMacDataBrowserTableViewControl::AddItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
)
412 return ::AddDataBrowserItems(this->m_controlRef
,container
,numItems
,items
,preSortProperty
);
413 } /* wxMacDataBrowserTableViewControl::AddItems(DataBrowserItemID, UInt32, DataBrowserItemID const*, DataBrowserPropertyID) */
415 OSStatus
wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID
* id
) const
422 status
= this->GetItemCount(&NoOfItems
);
423 wxCHECK_MSG(status
== noErr
,status
,_("Could not retrieve number of items"));
431 // 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
432 // as the number of items; therefore, start from the number of items to look for a new ID:
433 for (*id
=NoOfItems
; *id
<std::numeric_limits
<DataBrowserItemID
>::max(); ++(*id
))
434 if (this->IsUsedItemID(*id
) == errDataBrowserItemNotFound
)
436 // as the first approach was not successful, try from the beginning:
437 for (*id
=0; *id
<NoOfItems
; ++(*id
))
438 if (this->IsUsedItemID(*id
) == errDataBrowserItemNotFound
)
440 // sorry, data browser is full:
441 return errDataBrowserItemNotAdded
;
443 } /* wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID*) const */
445 OSStatus
wxMacDataBrowserTableViewControl::GetItemCount(DataBrowserItemID container
, Boolean recurse
, DataBrowserItemState state
, ItemCount
* numItems
) const
447 return GetDataBrowserItemCount(this->m_controlRef
,container
,recurse
,state
,numItems
);
448 } /* wxMacDataBrowserTableViewControl::GetItemCount(DataBrowserItemID, Boolean, DataBrowserItemState, ItemCount*) const */
450 OSStatus
wxMacDataBrowserTableViewControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
452 return GetDataBrowserTableViewItemID(this->m_controlRef
,row
,item
);
455 OSStatus
wxMacDataBrowserTableViewControl::GetItems(DataBrowserItemID container
, Boolean recurse
, DataBrowserItemState state
, Handle items
) const
457 return GetDataBrowserItems(this->m_controlRef
,container
,recurse
,state
,items
);
458 } /* wxMacDataBrowserTableViewControl::GetItems(DataBrowserItemID, Boolean, DataBrowserItemState, Handle) const */
460 OSStatus
wxMacDataBrowserTableViewControl::GetItemRow(DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
462 return GetDataBrowserTableViewItemRow(this->m_controlRef
,item
,row
);
465 OSStatus
wxMacDataBrowserTableViewControl::IsUsedItemID(DataBrowserItemID itemID
) const
467 // 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
468 // 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
469 // the column position for the property id:
470 DataBrowserTableViewColumnIndex index
;
472 return ::GetDataBrowserTableViewItemRow(this->m_controlRef
,itemID
,&index
);
473 } /* wxMacDataBrowserTableViewControl::IsUsedItemID(DataBrowserItemID) const */
475 OSStatus
wxMacDataBrowserTableViewControl::RemoveItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
)
477 return ::RemoveDataBrowserItems(this->m_controlRef
,container
,numItems
,items
,preSortProperty
);
480 OSStatus
wxMacDataBrowserTableViewControl::RevealItem(DataBrowserItemID item
, DataBrowserPropertyID propertyID
, DataBrowserRevealOptions options
) const
482 return ::RevealDataBrowserItem(this->m_controlRef
,item
,propertyID
,options
);
483 } /* wxMacDataBrowserTableViewControl::RevealItem(DataBrowserItemID item, DataBrowserPropertyID propertyID, DataBrowserRevealOptions options) const */
485 OSStatus
wxMacDataBrowserTableViewControl::UpdateItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
,
486 DataBrowserPropertyID propertyID
) const
488 return UpdateDataBrowserItems(this->m_controlRef
,container
,numItems
,items
,preSortProperty
,propertyID
);
494 size_t wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserItemID
& itemIDs
) const
496 DataBrowserItemID
* itemIDPtr
;
497 Handle
handle(::NewHandle(0));
502 wxCHECK_MSG(this->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemIsSelected
,handle
) == noErr
,0,_("Could not get selected items."));
503 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
505 itemIDs
.Alloc(NoOfItems
);
507 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
508 for (size_t i
=0; i
<NoOfItems
; ++i
)
510 itemIDs
.Add(*itemIDPtr
);
514 DisposeHandle(handle
);
516 } /* wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserItemID&) const*/
518 OSStatus
wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID
* first
, DataBrowserItemID
* last
) const
520 return ::GetDataBrowserSelectionAnchor(this->m_controlRef
,first
,last
);
521 } /* wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID*, DataBrowserItemID*) const */
523 OSStatus
wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags
* flags
) const
525 return ::GetDataBrowserSelectionFlags(this->m_controlRef
,flags
);
526 } /* wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags*) const */
528 bool wxMacDataBrowserTableViewControl::IsItemSelected(DataBrowserItemID item
) const
530 return ::IsDataBrowserItemSelected(this->m_controlRef
,item
);
531 } /* wxMacDataBrowserTableViewControl::IsItemSelected(DataBrowserItemID) const */
533 OSStatus
wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectionFlags flags
)
535 return ::SetDataBrowserSelectionFlags(this->m_controlRef
,flags
);
536 } /* wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectionFlags) */
538 OSStatus
wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserSetOption operation
)
540 return ::SetDataBrowserSelectedItems(this->m_controlRef
, numItems
, items
, operation
);
541 } /* wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32, DataBrowserItemID const*, DataBrowserSetOption) */
543 OSStatus
wxMacDataBrowserTableViewControl::GetSortOrder(DataBrowserSortOrder
* order
) const
545 return ::GetDataBrowserSortOrder(this->m_controlRef
,order
);
548 OSStatus
wxMacDataBrowserTableViewControl::GetSortProperty(DataBrowserPropertyID
* propertyID
) const
550 return ::GetDataBrowserSortProperty(this->m_controlRef
,propertyID
);
553 OSStatus
wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID container
, Boolean sortChildren
)
555 return ::SortDataBrowserContainer(this->m_controlRef
,container
,sortChildren
);
556 } /* wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID, Boolean) */
558 OSStatus
wxMacDataBrowserTableViewControl::SetSortOrder(DataBrowserSortOrder order
)
560 return ::SetDataBrowserSortOrder(this->m_controlRef
,order
);
563 OSStatus
wxMacDataBrowserTableViewControl::SetSortProperty(DataBrowserPropertyID propertyID
)
565 return ::SetDataBrowserSortProperty(this->m_controlRef
,propertyID
);
569 // container handling
571 OSStatus
wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID containerID
)
573 return ::CloseDataBrowserContainer(this->m_controlRef
,containerID
);
574 } /* wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID) */
576 OSStatus
wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID containerID
)
578 return ::OpenDataBrowserContainer(this->m_controlRef
,containerID
);
579 } /* wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID) */
581 IMPLEMENT_ABSTRACT_CLASS(wxMacDataBrowserTableViewControl
,wxMacControl
)
583 // ============================================================================
584 // wxMacDataBrowserListViewControl
585 // ============================================================================
590 OSStatus
wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc
*columnDesc
, DataBrowserTableViewColumnIndex position
)
592 return AddDataBrowserListViewColumn(this->m_controlRef
,columnDesc
,position
);
593 } /* wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc*, DataBrowserTableViewColumnIndex) */
595 // ============================================================================
596 // wxMacDataViewDataBrowserListViewControl
597 // ============================================================================
600 // constructors / destructor
602 wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl(wxWindow
* peer
, wxPoint
const& pos
, wxSize
const& size
, long style
)
603 :wxMacDataBrowserListViewControl(peer
,pos
,size
,style
)
605 } /* wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl(wxWindow* , const wxPoint&, const wxSize&, long) */
608 // callback functions (inherited from wxMacDataBrowserTableViewControl)
610 Boolean
wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
)
612 DataBrowserSortOrder sortOrder
;
614 DataBrowserTableViewColumnIndex modelColumnIndex
;
616 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
619 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Pointer to data view control not set correctly."));
620 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,false,_("Pointer to model not set correctly."));
621 if (sortProperty
>= kMinPropertyID
)
623 // variable definition and initialization:
624 wxDataViewColumn
* ColumnPtr(dataViewCtrlPtr
->GetColumnPtr(sortProperty
));
626 wxCHECK_MSG(ColumnPtr
!= NULL
,false,_("Could not determine column index."));
627 modelColumnIndex
= ColumnPtr
->GetModelColumn();
630 modelColumnIndex
= 0;
631 this->GetSortOrder(&sortOrder
);
632 return static_cast<Boolean
>(dataViewCtrlPtr
->GetModel()->Compare(wxDataViewItem(reinterpret_cast<void*>(itemOneID
)),wxDataViewItem(reinterpret_cast<void*>(itemTwoID
)),
633 modelColumnIndex
,sortOrder
!= kDataBrowserOrderDecreasing
) < 0);
634 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
636 void wxMacDataViewDataBrowserListViewControl::DataBrowserGetContextualMenuProc(MenuRef
* menu
, UInt32
* helpType
, CFStringRef
* helpItemString
, AEDesc
* WXUNUSED(selection
))
637 // In this method we do not supply a contextual menu handler at all but only send a wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU.
639 wxArrayDataBrowserItemID itemIDs
;
641 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
644 wxCHECK_RET(dataViewCtrlPtr
!= NULL
,_("wxWidget control pointer is not a data view pointer"));
645 // initialize parameters so that no context menu will be displayed automatically by the native data browser:
647 *helpType
= kCMHelpItemNoHelp
;
648 *helpItemString
= NULL
;
649 // create information for a context menu event:
650 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
,dataViewCtrlPtr
->GetId());
652 dataViewEvent
.SetModel(dataViewCtrlPtr
->GetModel());
653 // get the item information;
654 // 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:
655 if (this->GetSelectedItemIDs(itemIDs
) > 0)
656 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemIDs
[0])));
657 // finally send the equivalent wxWidget event:
658 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
659 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetContextualMenuProc(MenuRef*, UInt32*, CFStringRef*, AEDesc*) */
661 OSStatus
wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemDataRef itemData
, Boolean getValue
)
665 // variable definitions:
666 wxDataViewCtrl
* dataViewCtrlPtr
;
668 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetPeer());
669 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
670 if (dataViewCtrlPtr
->IsDeleting())
671 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
674 // variable definitions:
675 OSStatus errorStatus
;
676 wxDataViewColumn
* dataViewColumnPtr
;
678 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,errDataBrowserNotConfigured
,_("Pointer to model not set correctly."));
679 dataViewColumnPtr
= dataViewCtrlPtr
->GetColumnPtr(propertyID
);
680 wxCHECK_MSG((dataViewColumnPtr
!= NULL
) && (dataViewColumnPtr
->GetRenderer() != NULL
),errDataBrowserNotConfigured
,_("There is no column or renderer for the specified column index."));
681 switch (dataViewColumnPtr
->GetRenderer()->GetPropertyType())
683 case kDataBrowserCheckboxType
:
685 // variable definition:
686 ThemeButtonValue buttonValue
;
688 errorStatus
= ::GetDataBrowserItemDataButtonValue(itemData
,&buttonValue
);
689 if (errorStatus
== noErr
)
691 if (buttonValue
== kThemeButtonOn
)
693 // variable definition and initialization:
694 wxVariant
modifiedData(true);
696 return (dataViewCtrlPtr
->GetModel()->SetValue(modifiedData
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),dataViewColumnPtr
->GetModelColumn()) ? OSStatus(noErr
) : OSStatus(errDataBrowserNotConfigured
));
698 else if (buttonValue
== kThemeButtonOff
)
700 // variable definition and initialization:
701 wxVariant
modifiedData(false);
703 return (dataViewCtrlPtr
->GetModel()->SetValue(modifiedData
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),dataViewColumnPtr
->GetModelColumn()) ? OSStatus(noErr
) : OSStatus(errDataBrowserNotConfigured
));
706 return errDataBrowserInvalidPropertyData
;
711 case kDataBrowserTextType
:
713 // variable definitions:
714 CFStringRef stringReference
;
716 errorStatus
= ::GetDataBrowserItemDataText(itemData
,&stringReference
);
717 if (errorStatus
== noErr
)
719 // variable definitions and initializations:
720 #if wxCHECK_VERSION(2,9,0)
721 wxCFStringRef
modifiedString(stringReference
);
723 wxMacCFStringHolder
modifiedString(stringReference
);
725 wxVariant
modifiedData(modifiedString
.AsString());
727 if (dataViewCtrlPtr
->GetModel()->SetValue(modifiedData
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),dataViewColumnPtr
->GetModelColumn()))
730 return errDataBrowserNotConfigured
;
736 return errDataBrowserPropertyNotSupported
;
742 if (propertyID
>= kMinPropertyID
) // in case data columns set the data
744 // variable definitions:
746 wxDataViewColumn
* dataViewColumnPtr
;
747 wxDataViewCtrl
* dataViewCtrlPtr
;
749 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetPeer());
750 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
751 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,errDataBrowserNotConfigured
,_("Pointer to model not set correctly."));
752 dataViewColumnPtr
= dataViewCtrlPtr
->GetColumnPtr(propertyID
);
753 wxCHECK_MSG(dataViewColumnPtr
!= NULL
,errDataBrowserNotConfigured
,_("No column for the specified column position existing."));
754 wxCHECK_MSG(dataViewColumnPtr
->GetRenderer() != NULL
,errDataBrowserNotConfigured
,_("No renderer specified for column."));
755 dataViewCtrlPtr
->GetModel()->GetValue(variant
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),dataViewColumnPtr
->GetModelColumn());
756 if (!(variant
.IsNull()))
758 dataViewColumnPtr
->GetRenderer()->SetDataReference(itemData
);
759 dataViewColumnPtr
->GetRenderer()->SetValue(variant
);
760 wxCHECK_MSG(dataViewColumnPtr
->GetRenderer()->Render(),errDataBrowserNotConfigured
,_("Rendering failed."));
764 else // react on special system requests
768 case kDataBrowserContainerIsClosableProperty
:
770 // variable definitions:
771 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
773 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
774 // initialize wxWidget event:
775 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,dataViewCtrlPtr
->GetId()); // variable definition
777 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
778 dataViewEvent
.SetItem (wxDataViewItem(reinterpret_cast<void*>(itemID
)));
779 dataViewEvent
.SetModel (dataViewCtrlPtr
->GetModel());
780 // finally send the equivalent wxWidget event:
781 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
782 // opening the container is allowed if not vetoed:
783 return ::SetDataBrowserItemDataBooleanValue(itemData
,dataViewEvent
.IsAllowed());
785 case kDataBrowserContainerIsOpenableProperty
:
787 // variable definitions:
788 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
790 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
791 // initialize wxWidget event:
792 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
,dataViewCtrlPtr
->GetId()); // variable definition
794 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
795 dataViewEvent
.SetItem (wxDataViewItem(reinterpret_cast<void*>(itemID
)));
796 dataViewEvent
.SetModel (dataViewCtrlPtr
->GetModel());
797 // finally send the equivalent wxWidget event:
798 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
799 // opening the container is allowed if not vetoed:
800 return ::SetDataBrowserItemDataBooleanValue(itemData
,dataViewEvent
.IsAllowed());
802 case kDataBrowserItemIsContainerProperty
:
804 // variable definition:
805 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
807 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
808 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,errDataBrowserNotConfigured
,_("Pointer to model not set correctly."));
809 return ::SetDataBrowserItemDataBooleanValue(itemData
,dataViewCtrlPtr
->GetModel()->IsContainer(wxDataViewItem(reinterpret_cast<void*>(itemID
))));
811 case kDataBrowserItemIsEditableProperty
:
812 return ::SetDataBrowserItemDataBooleanValue(itemData
,true);
816 return errDataBrowserPropertyNotSupported
;
817 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */
819 void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
)
821 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
824 // 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:
825 if (dataViewCtrlPtr
!= NULL
)
828 case kDataBrowserContainerClosed
:
829 dataViewCtrlPtr
->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
831 // initialize wxWidget event:
832 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,dataViewCtrlPtr
->GetId()); // variable definition
834 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
835 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
836 // finally send the equivalent wxWidget event:
837 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
840 case kDataBrowserContainerOpened
:
841 dataViewCtrlPtr
->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
843 // initialize wxWidget event:
844 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,dataViewCtrlPtr
->GetId()); // variable definition
846 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
847 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
848 // finally send the equivalent wxWidget event:
849 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
850 // add children to the expanded container:
851 dataViewCtrlPtr
->AddChildrenLevel(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
854 case kDataBrowserEditStarted
:
855 dataViewCtrlPtr
->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
857 // initialize wxWidget event:
858 DataBrowserPropertyID propertyID
;
859 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
,dataViewCtrlPtr
->GetId()); // variable definition
861 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
862 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
863 if (this->GetPropertyID(itemData
,&propertyID
) == noErr
)
865 // variable definition and initialization:
866 DataBrowserTableViewColumnIndex columnIndex
;
868 wxCHECK_RET(this->GetColumnIndex(propertyID
,&columnIndex
),_("Column index not found."));
869 dataViewEvent
.SetColumn(columnIndex
);
870 dataViewEvent
.SetDataViewColumn(dataViewCtrlPtr
->GetColumnPtr(propertyID
));
872 // finally send the equivalent wxWidget event:
873 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
876 case kDataBrowserEditStopped
:
878 // initialize wxWidget event:
879 DataBrowserPropertyID propertyID
;
880 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
,dataViewCtrlPtr
->GetId()); // variable definition
882 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
883 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
884 if (this->GetPropertyID(itemData
,&propertyID
) == noErr
)
886 // variable definition and initialization:
887 DataBrowserTableViewColumnIndex columnIndex
;
889 wxCHECK_RET(this->GetColumnIndex(propertyID
,&columnIndex
),_("Column index not found."));
890 dataViewEvent
.SetColumn(columnIndex
);
891 dataViewEvent
.SetDataViewColumn(dataViewCtrlPtr
->GetColumnPtr(propertyID
));
893 // finally send the equivalent wxWidget event:
894 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
897 case kDataBrowserItemAdded
:
898 dataViewCtrlPtr
->FinishCustomItemEditing();
900 case kDataBrowserItemDeselected
:
901 dataViewCtrlPtr
->FinishCustomItemEditing();
903 case kDataBrowserItemDoubleClicked
:
905 // initialize wxWidget event:
906 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
,dataViewCtrlPtr
->GetId()); // variable definition
908 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
909 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
910 // finally send the equivalent wxWidget event:
911 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
914 case kDataBrowserItemRemoved
:
915 dataViewCtrlPtr
->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
917 case kDataBrowserItemSelected
:
918 break; // not implemented by wxWidgets; see kDataBrowserSelectionSetChanged
919 case kDataBrowserSelectionSetChanged
:
921 // initialize wxWidget event:
922 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
,dataViewCtrlPtr
->GetId()); // variable definition
924 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
925 dataViewEvent
.SetModel (dataViewCtrlPtr
->GetModel());
926 // finally send the equivalent wxWidget event:
927 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
930 case kDataBrowserTargetChanged
: // no idea if this notification is ever sent
932 case kDataBrowserUserStateChanged
:
934 // finish custom item editing if necessary:
935 dataViewCtrlPtr
->FinishCustomItemEditing();
936 // update column widths:
937 for (size_t i
=0; i
<dataViewCtrlPtr
->GetColumnCount(); ++i
)
939 // constant definition for abbreviational purposes:
940 wxDataViewColumn
* const columnPtr
= dataViewCtrlPtr
->GetColumn(i
);
941 // variable definition:
944 wxCHECK_RET(this->GetColumnWidth(columnPtr
->GetPropertyID(),&columnWidth
) == noErr
,_("Column width could not be determined"));
945 columnPtr
->SetWidthVariable(columnWidth
);
947 // update sorting orders:
948 DataBrowserPropertyID propertyID
; // variable definition
950 if ((this->GetSortProperty(&propertyID
) == noErr
) && (propertyID
>= kMinPropertyID
))
952 DataBrowserSortOrder sortOrder
;
953 DataBrowserTableViewColumnIndex columnIndex
;
955 if ((this->GetSortOrder(&sortOrder
) == noErr
) && (this->GetColumnIndex(propertyID
,&columnIndex
) == noErr
))
957 // variable definition and initialization:
958 wxDataViewColumn
* columnPtr
;
959 columnPtr
= dataViewCtrlPtr
->GetColumn(columnIndex
);
960 // check if the sort order has changed:
961 if ( columnPtr
->IsSortOrderAscending() && (sortOrder
== kDataBrowserOrderDecreasing
) ||
962 !(columnPtr
->IsSortOrderAscending()) && (sortOrder
== kDataBrowserOrderIncreasing
))
964 columnPtr
->SetSortOrder(!(columnPtr
->IsSortOrderAscending()));
965 // initialize wxWidget event:
966 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
,dataViewCtrlPtr
->GetId()); // variable defintion
968 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
969 dataViewEvent
.SetColumn(columnIndex
);
970 dataViewEvent
.SetDataViewColumn(columnPtr
);
971 // finally send the equivalent wxWidget event:
972 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
979 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */
981 void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
)
983 wxDataViewColumn
* dataViewColumnPtr
;
985 wxDataViewCtrl
* dataViewCtrlPtr
;
987 wxDataViewCustomRenderer
* dataViewCustomRendererPtr
;
989 wxVariant dataToRender
;
992 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetPeer());
993 wxCHECK_RET(dataViewCtrlPtr
!= NULL
, _("Pointer to data view control not set correctly."));
994 wxCHECK_RET(dataViewCtrlPtr
->GetModel() != NULL
,_("Pointer to model not set correctly."));
995 dataViewColumnPtr
= dataViewCtrlPtr
->GetColumnPtr(propertyID
);
996 wxCHECK_RET(dataViewColumnPtr
!= NULL
,_("No column for the specified column index existing."));
997 dataViewCustomRendererPtr
= dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer());
998 wxCHECK_RET(dataViewCustomRendererPtr
!= NULL
,_("No renderer or invalid renderer type specified for custom data column."));
999 dataViewCtrlPtr
->GetModel()->GetValue(dataToRender
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),dataViewColumnPtr
->GetModelColumn());
1000 dataViewCustomRendererPtr
->SetValue(dataToRender
);
1002 // try to determine the content's size (drawable part):
1004 RgnHandle
rgn(NewRgn());
1005 UInt16 headerHeight
;
1007 if (this->GetRegion(kControlContentMetaPart
,rgn
) == noErr
)
1008 GetRegionBounds(rgn
,&content
);
1010 this->GetRect(&content
);
1012 // space for the header
1013 this->GetHeaderButtonHeight(&headerHeight
);
1014 content
.top
+= headerHeight
;
1015 // extra space for the frame (todo: do not how to determine the space automatically from the control)
1019 content
.bottom
-= 3;
1020 // extra space for the scrollbars:
1021 content
.bottom
-= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
1022 content
.right
-= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1024 // make sure that 'Render' can draw only in the allowed area:
1025 dataViewCustomRendererPtr
->GetDC()->SetClippingRegion(content
.left
,content
.top
,content
.right
-content
.left
+1,content
.bottom
-content
.top
+1);
1026 (void) (dataViewCustomRendererPtr
->Render(wxRect(static_cast<int>(rectangle
->left
),static_cast<int>(rectangle
->top
),
1027 static_cast<int>(1+rectangle
->right
-rectangle
->left
),static_cast<int>(1+rectangle
->bottom
-rectangle
->top
)),
1028 dataViewCustomRendererPtr
->GetDC(),((state
== kDataBrowserItemIsSelected
) ? wxDATAVIEW_CELL_SELECTED
: 0)));
1029 dataViewCustomRendererPtr
->GetDC()->DestroyClippingRegion(); // probably not necessary
1030 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */
1032 Boolean
wxMacDataViewDataBrowserListViewControl::DataBrowserEditItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, CFStringRef theString
, Rect
* maxEditTextRect
, Boolean
* shrinkToFit
)
1035 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserEditItemProc(DataBrowserItemID, DataBrowserPropertyID, CFStringRef, Rect*, Boolean*) */
1037 Boolean
wxMacDataViewDataBrowserListViewControl::DataBrowserHitTestProc(DataBrowserItemID
WXUNUSED(itemID
), DataBrowserPropertyID
WXUNUSED(property
), Rect
const* WXUNUSED(theRect
), Rect
const* WXUNUSED(mouseRect
))
1040 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserHitTestProc(DataBrowserItemID, DataBrowserPropertyID, Rect const*, Rect const*) */
1042 DataBrowserTrackingResult
wxMacDataViewDataBrowserListViewControl::DataBrowserTrackingProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Point
WXUNUSED(startPt
), EventModifiers
WXUNUSED(modifiers
))
1044 wxDataViewColumn
* dataViewColumnPtr
;
1046 wxDataViewCtrl
* dataViewCtrlPtr
;
1048 wxDataViewCustomRenderer
* dataViewCustomRendererPtr
;
1050 wxDataViewItem dataViewCustomRendererItem
;
1053 dataViewCustomRendererItem
= reinterpret_cast<void*>(itemID
);
1054 wxCHECK_MSG(dataViewCustomRendererItem
.IsOk(),kDataBrowserNothingHit
,_("Invalid data view item"));
1055 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetPeer());
1056 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,kDataBrowserNothingHit
,_("Pointer to data view control not set correctly."));
1057 dataViewColumnPtr
= dataViewCtrlPtr
->GetColumnPtr(propertyID
);
1058 wxCHECK_MSG(dataViewColumnPtr
!= NULL
,kDataBrowserNothingHit
,_("No column existing."));
1059 dataViewCustomRendererPtr
= dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer());
1060 wxCHECK_MSG(dataViewCustomRendererPtr
!= NULL
,kDataBrowserNothingHit
,_("No renderer or invalid renderer type specified for custom data column."));
1061 // 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):
1062 if (dataViewCtrlPtr
->GetCustomRendererItem() == dataViewCustomRendererItem
)
1063 return kDataBrowserContentHit
;
1064 // an(other) item is going to be edited and therefore the current editing - if existing - has to be finished:
1065 if (dataViewCtrlPtr
->GetCustomRendererPtr() != NULL
)
1067 dataViewCtrlPtr
->GetCustomRendererPtr()->FinishEditing();
1068 dataViewCtrlPtr
->SetCustomRendererItem(wxDataViewItem());
1069 dataViewCtrlPtr
->SetCustomRendererPtr (NULL
);
1071 // check if renderer has got a valid editor control for editing; if this is the case start editing of the new item:
1072 if (dataViewCustomRendererPtr
->HasEditorCtrl())
1074 // variable definition:
1077 ::wxMacNativeToRect(theRect
,&wxRectangle
);
1078 dataViewCustomRendererPtr
->StartEditing(dataViewCustomRendererItem
,wxRectangle
);
1079 dataViewCtrlPtr
->SetCustomRendererItem(dataViewCustomRendererItem
);
1080 dataViewCtrlPtr
->SetCustomRendererPtr (dataViewCustomRendererPtr
);
1082 return kDataBrowserContentHit
;
1083 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserTrackingProc(DataBrowserItemID, DataBrowserPropertyID, Rect const*, Point, EventModifiers) */
1085 #endif // wxUSE_GENERICDATAVIEWCTRL