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 columnIndex
;
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 wxCHECK_MSG(this->GetColumnIndex(sortProperty
,&columnIndex
) == noErr
,false,_("Could not determine column index."));
627 this->GetSortOrder(&sortOrder
);
628 return static_cast<Boolean
>(dataViewCtrlPtr
->GetModel()->Compare(wxDataViewItem(reinterpret_cast<void*>(itemOneID
)),wxDataViewItem(reinterpret_cast<void*>(itemTwoID
)),
629 columnIndex
,sortOrder
!= kDataBrowserOrderDecreasing
) < 0);
630 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
632 void wxMacDataViewDataBrowserListViewControl::DataBrowserGetContextualMenuProc(MenuRef
* menu
, UInt32
* helpType
, CFStringRef
* helpItemString
, AEDesc
* WXUNUSED(selection
))
633 // In this method we do not supply a contextual menu handler at all but only send a wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU.
635 wxArrayDataBrowserItemID itemIDs
;
637 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
640 wxCHECK_RET(dataViewCtrlPtr
!= NULL
,_("wxWidget control pointer is not a data view pointer"));
641 // initialize parameters so that no context menu will be displayed automatically by the native data browser:
643 *helpType
= kCMHelpItemNoHelp
;
644 *helpItemString
= NULL
;
645 // create information for a context menu event:
646 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
,dataViewCtrlPtr
->GetId());
648 dataViewEvent
.SetModel(dataViewCtrlPtr
->GetModel());
649 // get the item information;
650 // 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:
651 if (this->GetSelectedItemIDs(itemIDs
) > 0)
652 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemIDs
[0])));
653 // finally send the equivalent wxWidget event:
654 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
655 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetContextualMenuProc(MenuRef*, UInt32*, CFStringRef*, AEDesc*) */
657 OSStatus
wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemDataRef itemData
, Boolean getValue
)
661 // variable definitions:
662 wxDataViewCtrl
* dataViewCtrlPtr
;
664 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetPeer());
665 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
666 if (dataViewCtrlPtr
->IsDeleting())
667 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
670 // variable definitions:
671 DataBrowserTableViewColumnIndex columnIndex
;
672 OSStatus errorStatus
;
673 wxDataViewColumn
* dataViewColumnPtr
;
675 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,errDataBrowserNotConfigured
,_("Pointer to model not set correctly."));
676 errorStatus
= this->GetColumnIndex(propertyID
,&columnIndex
);
677 wxCHECK_MSG(errorStatus
== noErr
,errorStatus
,_("Could not determine column index"));
678 dataViewColumnPtr
= dataViewCtrlPtr
->GetColumn(columnIndex
);
679 wxCHECK_MSG((dataViewColumnPtr
!= NULL
) && (dataViewColumnPtr
->GetRenderer() != NULL
),errDataBrowserNotConfigured
,_("There is no column or renderer for the specified column index."));
680 switch (dataViewColumnPtr
->GetRenderer()->GetPropertyType())
682 case kDataBrowserCheckboxType
:
684 // variable definition:
685 ThemeButtonValue buttonValue
;
687 errorStatus
= ::GetDataBrowserItemDataButtonValue(itemData
,&buttonValue
);
688 if (errorStatus
== noErr
)
690 if (buttonValue
== kThemeButtonOn
)
692 // variable definition and initialization:
693 wxVariant
modifiedData(true);
695 return (dataViewCtrlPtr
->GetModel()->SetValue(modifiedData
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),static_cast<unsigned int>(columnIndex
)) ? OSStatus(noErr
) : OSStatus(errDataBrowserNotConfigured
));
697 else if (buttonValue
== kThemeButtonOff
)
699 // variable definition and initialization:
700 wxVariant
modifiedData(false);
702 return (dataViewCtrlPtr
->GetModel()->SetValue(modifiedData
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),static_cast<unsigned int>(columnIndex
)) ? OSStatus(noErr
) : OSStatus(errDataBrowserNotConfigured
));
705 return errDataBrowserInvalidPropertyData
;
710 case kDataBrowserTextType
:
712 // variable definitions:
713 CFStringRef stringReference
;
715 errorStatus
= ::GetDataBrowserItemDataText(itemData
,&stringReference
);
716 if (errorStatus
== noErr
)
718 // variable definitions and initializations:
719 #if wxCHECK_VERSION(2,9,0)
720 wxCFStringRef
modifiedString(stringReference
);
722 wxMacCFStringHolder
modifiedString(stringReference
);
724 wxVariant
modifiedData(modifiedString
.AsString());
726 if (dataViewCtrlPtr
->GetModel()->SetValue(modifiedData
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),static_cast<unsigned int>(columnIndex
)))
729 return errDataBrowserNotConfigured
;
735 return errDataBrowserPropertyNotSupported
;
741 if (propertyID
>= kMinPropertyID
) // in case data columns set the data
743 // variable definitions:
745 wxDataViewColumn
* dataViewColumnPtr
;
746 wxDataViewCtrl
* dataViewCtrlPtr
;
748 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetPeer());
749 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
750 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,errDataBrowserNotConfigured
,_("Pointer to model not set correctly."));
751 dataViewColumnPtr
= dataViewCtrlPtr
->GetColumnPtr(propertyID
);
752 wxCHECK_MSG(dataViewColumnPtr
!= NULL
,errDataBrowserNotConfigured
,_("No column for the specified column position existing."));
753 wxCHECK_MSG(dataViewColumnPtr
->GetRenderer() != NULL
,errDataBrowserNotConfigured
,_("No renderer specified for column."));
754 dataViewCtrlPtr
->GetModel()->GetValue(variant
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),dataViewColumnPtr
->GetModelColumn());
755 if (!(variant
.IsNull()))
757 dataViewColumnPtr
->GetRenderer()->SetDataReference(itemData
);
758 dataViewColumnPtr
->GetRenderer()->SetValue(variant
);
759 wxCHECK_MSG(dataViewColumnPtr
->GetRenderer()->Render(),errDataBrowserNotConfigured
,_("Rendering failed."));
763 else // react on special system requests
767 case kDataBrowserContainerIsClosableProperty
:
769 // variable definitions:
770 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
772 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
773 // initialize wxWidget event:
774 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,dataViewCtrlPtr
->GetId()); // variable definition
776 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
777 dataViewEvent
.SetItem (wxDataViewItem(reinterpret_cast<void*>(itemID
)));
778 dataViewEvent
.SetModel (dataViewCtrlPtr
->GetModel());
779 // finally send the equivalent wxWidget event:
780 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
781 // opening the container is allowed if not vetoed:
782 return ::SetDataBrowserItemDataBooleanValue(itemData
,dataViewEvent
.IsAllowed());
784 case kDataBrowserContainerIsOpenableProperty
:
786 // variable definitions:
787 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
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_EXPANDING
,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 kDataBrowserItemIsContainerProperty
:
803 // variable definition:
804 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
806 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
807 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,errDataBrowserNotConfigured
,_("Pointer to model not set correctly."));
808 return ::SetDataBrowserItemDataBooleanValue(itemData
,dataViewCtrlPtr
->GetModel()->IsContainer(wxDataViewItem(reinterpret_cast<void*>(itemID
))));
810 case kDataBrowserItemIsEditableProperty
:
811 return ::SetDataBrowserItemDataBooleanValue(itemData
,true);
815 return errDataBrowserPropertyNotSupported
;
816 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */
818 void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
)
820 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetPeer()));
823 // 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:
824 if (dataViewCtrlPtr
!= NULL
)
827 case kDataBrowserContainerClosed
:
828 dataViewCtrlPtr
->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
830 // initialize wxWidget event:
831 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,dataViewCtrlPtr
->GetId()); // variable definition
833 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
834 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
835 // finally send the equivalent wxWidget event:
836 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
839 case kDataBrowserContainerOpened
:
840 dataViewCtrlPtr
->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
842 // initialize wxWidget event:
843 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,dataViewCtrlPtr
->GetId()); // variable definition
845 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
846 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
847 // finally send the equivalent wxWidget event:
848 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
849 // add children to the expanded container:
850 dataViewCtrlPtr
->AddChildrenLevel(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
853 case kDataBrowserEditStarted
:
854 dataViewCtrlPtr
->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
856 // initialize wxWidget event:
857 DataBrowserPropertyID propertyID
;
858 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
,dataViewCtrlPtr
->GetId()); // variable definition
860 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
861 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
862 if (this->GetPropertyID(itemData
,&propertyID
) == noErr
)
864 // variable definition and initialization:
865 DataBrowserTableViewColumnIndex columnIndex
;
867 wxCHECK_RET(this->GetColumnIndex(propertyID
,&columnIndex
),_("Column index not found."));
868 dataViewEvent
.SetColumn(columnIndex
);
869 dataViewEvent
.SetDataViewColumn(dataViewCtrlPtr
->GetColumnPtr(propertyID
));
871 // finally send the equivalent wxWidget event:
872 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
875 case kDataBrowserEditStopped
:
877 // initialize wxWidget event:
878 DataBrowserPropertyID propertyID
;
879 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
,dataViewCtrlPtr
->GetId()); // variable definition
881 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
882 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
883 if (this->GetPropertyID(itemData
,&propertyID
) == noErr
)
885 // variable definition and initialization:
886 DataBrowserTableViewColumnIndex columnIndex
;
888 wxCHECK_RET(this->GetColumnIndex(propertyID
,&columnIndex
),_("Column index not found."));
889 dataViewEvent
.SetColumn(columnIndex
);
890 dataViewEvent
.SetDataViewColumn(dataViewCtrlPtr
->GetColumnPtr(propertyID
));
892 // finally send the equivalent wxWidget event:
893 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
896 case kDataBrowserItemAdded
:
897 dataViewCtrlPtr
->FinishCustomItemEditing();
899 case kDataBrowserItemDeselected
:
900 dataViewCtrlPtr
->FinishCustomItemEditing();
902 case kDataBrowserItemDoubleClicked
:
904 // initialize wxWidget event:
905 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
,dataViewCtrlPtr
->GetId()); // variable definition
907 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
908 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
909 // finally send the equivalent wxWidget event:
910 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
913 case kDataBrowserItemRemoved
:
914 dataViewCtrlPtr
->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
916 case kDataBrowserItemSelected
:
917 break; // not implemented by wxWidgets; see kDataBrowserSelectionSetChanged
918 case kDataBrowserSelectionSetChanged
:
920 // initialize wxWidget event:
921 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
,dataViewCtrlPtr
->GetId()); // variable definition
923 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
924 dataViewEvent
.SetModel (dataViewCtrlPtr
->GetModel());
925 // finally send the equivalent wxWidget event:
926 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
929 case kDataBrowserTargetChanged
: // no idea if this notification is ever sent
931 case kDataBrowserUserStateChanged
:
933 // finish custom item editing if necessary:
934 dataViewCtrlPtr
->FinishCustomItemEditing();
935 // update column widths:
936 for (size_t i
=0; i
<dataViewCtrlPtr
->GetColumnCount(); ++i
)
938 // constant definition for abbreviational purposes:
939 wxDataViewColumn
* const columnPtr
= dataViewCtrlPtr
->GetColumn(i
);
940 // variable definition:
943 wxCHECK_RET(this->GetColumnWidth(columnPtr
->GetPropertyID(),&columnWidth
) == noErr
,_("Column width could not be determined"));
944 columnPtr
->SetWidthVariable(columnWidth
);
946 // update sorting orders:
947 DataBrowserPropertyID propertyID
; // variable definition
949 if ((this->GetSortProperty(&propertyID
) == noErr
) && (propertyID
>= kMinPropertyID
))
951 DataBrowserSortOrder sortOrder
;
952 DataBrowserTableViewColumnIndex columnIndex
;
954 if ((this->GetSortOrder(&sortOrder
) == noErr
) && (this->GetColumnIndex(propertyID
,&columnIndex
) == noErr
))
956 // variable definition and initialization:
957 wxDataViewColumn
* columnPtr
;
958 columnPtr
= dataViewCtrlPtr
->GetColumn(columnIndex
);
959 // check if the sort order has changed:
960 if ( columnPtr
->IsSortOrderAscending() && (sortOrder
== kDataBrowserOrderDecreasing
) ||
961 !(columnPtr
->IsSortOrderAscending()) && (sortOrder
== kDataBrowserOrderIncreasing
))
963 columnPtr
->SetSortOrder(!(columnPtr
->IsSortOrderAscending()));
964 // initialize wxWidget event:
965 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
,dataViewCtrlPtr
->GetId()); // variable defintion
967 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
968 dataViewEvent
.SetColumn(columnIndex
);
969 dataViewEvent
.SetDataViewColumn(columnPtr
);
970 // finally send the equivalent wxWidget event:
971 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
978 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */
980 void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
)
982 wxDataViewColumn
* dataViewColumnPtr
;
984 wxDataViewCtrl
* dataViewCtrlPtr
;
986 wxDataViewCustomRenderer
* dataViewCustomRendererPtr
;
988 wxVariant dataToRender
;
991 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetPeer());
992 wxCHECK_RET(dataViewCtrlPtr
!= NULL
, _("Pointer to data view control not set correctly."));
993 wxCHECK_RET(dataViewCtrlPtr
->GetModel() != NULL
,_("Pointer to model not set correctly."));
994 dataViewColumnPtr
= dataViewCtrlPtr
->GetColumnPtr(propertyID
);
995 wxCHECK_RET(dataViewColumnPtr
!= NULL
,_("No column for the specified column index existing."));
996 dataViewCustomRendererPtr
= dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer());
997 wxCHECK_RET(dataViewCustomRendererPtr
!= NULL
,_("No renderer or invalid renderer type specified for custom data column."));
998 dataViewCtrlPtr
->GetModel()->GetValue(dataToRender
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),dataViewColumnPtr
->GetModelColumn());
999 dataViewCustomRendererPtr
->SetValue(dataToRender
);
1001 // try to determine the content's size (drawable part):
1003 RgnHandle
rgn(NewRgn());
1004 UInt16 headerHeight
;
1006 if (this->GetRegion(kControlContentMetaPart
,rgn
) == noErr
)
1007 GetRegionBounds(rgn
,&content
);
1009 this->GetRect(&content
);
1011 // space for the header
1012 this->GetHeaderButtonHeight(&headerHeight
);
1013 content
.top
+= headerHeight
;
1014 // extra space for the frame (todo: do not how to determine the space automatically from the control)
1018 content
.bottom
-= 3;
1019 // extra space for the scrollbars:
1020 content
.bottom
-= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
1021 content
.right
-= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1023 // make sure that 'Render' can draw only in the allowed area:
1024 dataViewCustomRendererPtr
->GetDC()->SetClippingRegion(content
.left
,content
.top
,content
.right
-content
.left
+1,content
.bottom
-content
.top
+1);
1025 (void) (dataViewCustomRendererPtr
->Render(wxRect(static_cast<int>(rectangle
->left
),static_cast<int>(rectangle
->top
),
1026 static_cast<int>(1+rectangle
->right
-rectangle
->left
),static_cast<int>(1+rectangle
->bottom
-rectangle
->top
)),
1027 dataViewCustomRendererPtr
->GetDC(),((state
== kDataBrowserItemIsSelected
) ? wxDATAVIEW_CELL_SELECTED
: 0)));
1028 dataViewCustomRendererPtr
->GetDC()->DestroyClippingRegion(); // probably not necessary
1029 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */
1031 Boolean
wxMacDataViewDataBrowserListViewControl::DataBrowserEditItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, CFStringRef theString
, Rect
* maxEditTextRect
, Boolean
* shrinkToFit
)
1034 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserEditItemProc(DataBrowserItemID, DataBrowserPropertyID, CFStringRef, Rect*, Boolean*) */
1036 Boolean
wxMacDataViewDataBrowserListViewControl::DataBrowserHitTestProc(DataBrowserItemID
WXUNUSED(itemID
), DataBrowserPropertyID
WXUNUSED(property
), Rect
const* WXUNUSED(theRect
), Rect
const* WXUNUSED(mouseRect
))
1039 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserHitTestProc(DataBrowserItemID, DataBrowserPropertyID, Rect const*, Rect const*) */
1041 DataBrowserTrackingResult
wxMacDataViewDataBrowserListViewControl::DataBrowserTrackingProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Point
WXUNUSED(startPt
), EventModifiers
WXUNUSED(modifiers
))
1043 wxDataViewColumn
* dataViewColumnPtr
;
1045 wxDataViewCtrl
* dataViewCtrlPtr
;
1047 wxDataViewCustomRenderer
* dataViewCustomRendererPtr
;
1049 wxDataViewItem dataViewCustomRendererItem
;
1052 dataViewCustomRendererItem
= reinterpret_cast<void*>(itemID
);
1053 wxCHECK_MSG(dataViewCustomRendererItem
.IsOk(),kDataBrowserNothingHit
,_("Invalid data view item"));
1054 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetPeer());
1055 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,kDataBrowserNothingHit
,_("Pointer to data view control not set correctly."));
1056 dataViewColumnPtr
= dataViewCtrlPtr
->GetColumnPtr(propertyID
);
1057 wxCHECK_MSG(dataViewColumnPtr
!= NULL
,kDataBrowserNothingHit
,_("No column existing."));
1058 dataViewCustomRendererPtr
= dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer());
1059 wxCHECK_MSG(dataViewCustomRendererPtr
!= NULL
,kDataBrowserNothingHit
,_("No renderer or invalid renderer type specified for custom data column."));
1060 // 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):
1061 if (dataViewCtrlPtr
->GetCustomRendererItem() == dataViewCustomRendererItem
)
1062 return kDataBrowserContentHit
;
1063 // an(other) item is going to be edited and therefore the current editing - if existing - has to be finished:
1064 if (dataViewCtrlPtr
->GetCustomRendererPtr() != NULL
)
1066 dataViewCtrlPtr
->GetCustomRendererPtr()->FinishEditing();
1067 dataViewCtrlPtr
->SetCustomRendererItem(wxDataViewItem());
1068 dataViewCtrlPtr
->SetCustomRendererPtr (NULL
);
1070 // check if renderer has got a valid editor control for editing; if this is the case start editing of the new item:
1071 if (dataViewCustomRendererPtr
->HasEditorCtrl())
1073 // variable definition:
1076 ::wxMacNativeToRect(theRect
,&wxRectangle
);
1077 dataViewCustomRendererPtr
->StartEditing(dataViewCustomRendererItem
,wxRectangle
);
1078 dataViewCtrlPtr
->SetCustomRendererItem(dataViewCustomRendererItem
);
1079 dataViewCtrlPtr
->SetCustomRendererPtr (dataViewCustomRendererPtr
);
1081 return kDataBrowserContentHit
;
1082 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserTrackingProc(DataBrowserItemID, DataBrowserPropertyID, Rect const*, Point, EventModifiers) */
1084 #endif // wxUSE_GENERICDATAVIEWCTRL