1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/carbon/dataview.h
3 // Purpose: wxDataViewCtrl native implementation header for carbon
5 // Id: $Id: dataview.h 57374 2009-01-27
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_DATAVIEWCTRL_CARBON_H_
11 #define _WX_DATAVIEWCTRL_CARBON_H_
17 #include "wx/osx/core/dataview.h"
18 #include "wx/osx/private.h"
20 // ============================================================================
21 // wxDataViewColumnNativeData
22 // ============================================================================
23 class wxDataViewColumnNativeData
27 // constructors / destructor
29 wxDataViewColumnNativeData(void)
32 wxDataViewColumnNativeData(DataBrowserPropertyID initPropertyID
)
33 :m_PropertyID(initPropertyID
)
38 // data access methods
40 DataBrowserPropertyID
GetPropertyID(void) const
42 return this->m_PropertyID
;
45 void SetPropertyID(DataBrowserPropertyID newPropertyID
)
47 this->m_PropertyID
= newPropertyID
;
55 DataBrowserPropertyID m_PropertyID
; // each column is identified by its unique property ID (NOT by the column's index)
58 // ============================================================================
59 // wxDataViewRendererNativeData
60 // ============================================================================
61 class wxDataViewRendererNativeData
65 // constructors / destructor
67 wxDataViewRendererNativeData(void)
70 wxDataViewRendererNativeData(DataBrowserPropertyType initPropertyType
, DataBrowserItemDataRef initItemDataRef
=NULL
)
71 :m_ItemDataRef(initItemDataRef
), m_PropertyType(initPropertyType
)
76 // data access methods
78 DataBrowserItemDataRef
GetItemDataRef(void) const
80 return this->m_ItemDataRef
;
82 DataBrowserPropertyType
GetPropertyType(void) const
84 return this->m_PropertyType
;
87 void SetItemDataRef(DataBrowserItemDataRef newItemDataRef
)
89 this->m_ItemDataRef
= newItemDataRef
;
91 void SetPropertyType(DataBrowserPropertyType newPropertyType
)
93 this->m_PropertyType
= newPropertyType
;
101 DataBrowserItemDataRef m_ItemDataRef
;
103 DataBrowserPropertyType m_PropertyType
;
106 // ============================================================================
107 // wxMacDataBrowserTableViewControl
108 // ============================================================================
110 // This is a wrapper class for the Mac OS X data browser environment.
111 // It covers all data brower functionality for the native browser's list
115 // data browser's property IDs have a reserved ID range from 0 - 1023
116 // therefore, the first usable property ID is 'kMinPropertyID'
117 DataBrowserPropertyID
const kMinPropertyID
= 1024;
119 // array of data browser item IDs
120 WX_DEFINE_ARRAY_SIZE_T(size_t,wxArrayDataBrowserItemID
);
122 class wxMacDataBrowserTableViewControl
: public wxMacControl
126 // constructors / destructor
128 wxMacDataBrowserTableViewControl(wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
129 wxMacDataBrowserTableViewControl(void)
132 ~wxMacDataBrowserTableViewControl(void);
137 OSStatus
SetCallbacks (DataBrowserCallbacks
const* callbacks
);
138 OSStatus
SetCustomCallbacks(DataBrowserCustomCallbacks
const* customCallbacks
);
143 OSStatus
EnableAutomaticDragTracking(bool enable
=true);
148 OSStatus
GetHeaderDesc(DataBrowserPropertyID property
, DataBrowserListViewHeaderDesc
* desc
) const;
150 OSStatus
SetHeaderDesc(DataBrowserPropertyID property
, DataBrowserListViewHeaderDesc
* desc
);
155 OSStatus
AutoSizeColumns();
157 OSStatus
EnableCellSizeModification(bool enableHeight
=true, bool enableWidth
=true); // enables or disables the column width and row height modification (default: false)
159 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
160 OSStatus
GetAttributes (OptionBits
* attributes
);
162 OSStatus
GetColumnWidth (DataBrowserPropertyID column
, UInt16
*width
) const; // returns the column width in pixels
163 OSStatus
GetDefaultColumnWidth(UInt16
*width
) const; // returns the default column width in pixels
164 OSStatus
GetDefaultRowHeight (UInt16
* height
) const;
165 OSStatus
GetHeaderButtonHeight(UInt16
*height
);
166 OSStatus
GetPartBounds (DataBrowserItemID item
, DataBrowserPropertyID property
, DataBrowserPropertyPart part
, Rect
* bounds
);
167 OSStatus
GetRowHeight (DataBrowserItemID item
, UInt16
*height
) const;
168 OSStatus
GetScrollPosition (UInt32
* top
, UInt32
*left
) const;
170 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
171 OSStatus
SetAttributes (OptionBits attributes
);
173 OSStatus
SetColumnWidth(DataBrowserPropertyID column
, UInt16 width
); // sets the column width in pixels
174 OSStatus
SetDefaultColumnWidth( UInt16 width
);
175 OSStatus
SetDefaultRowHeight( UInt16 height
);
176 OSStatus
SetHasScrollBars( bool horiz
, bool vert
);
177 OSStatus
SetHeaderButtonHeight( UInt16 height
);
178 OSStatus
SetHiliteStyle(DataBrowserTableViewHiliteStyle hiliteStyle
);
179 OSStatus
SetIndent(float Indent
);
180 OSStatus
SetItemRowHeight( DataBrowserItemID item
, UInt16 height
);
181 OSStatus
SetScrollPosition( UInt32 top
, UInt32 left
);
186 OSStatus
GetColumnCount (UInt32
* numColumns
) const;
187 OSStatus
GetColumnIndex (DataBrowserPropertyID propertyID
, DataBrowserTableViewColumnIndex
* index
) const; // returns for the passed property the corresponding column index
188 OSStatus
GetFreePropertyID(DataBrowserPropertyID
* propertyID
) const; // this method returns a property id that is valid and currently not used; if it cannot be found 'errDataBrowerPropertyNotSupported' is returned
189 OSStatus
GetPropertyFlags (DataBrowserPropertyID propertyID
, DataBrowserPropertyFlags
*flags
) const;
190 OSStatus
GetPropertyID (DataBrowserItemDataRef itemData
, DataBrowserPropertyID
* propertyID
) const; // returns for the passed item data reference the corresponding property ID
191 OSStatus
GetPropertyID (DataBrowserTableViewColumnIndex index
, DataBrowserPropertyID
* propertyID
) const; // returns for the passed column index the corresponding property ID
193 OSStatus
IsUsedPropertyID(DataBrowserPropertyID propertyID
) const; // checks if passed property id is used by the control; no error is returned if the id exists
195 OSStatus
RemoveColumnByProperty(DataBrowserTableViewColumnID propertyID
);
196 OSStatus
RemoveColumnByIndex (DataBrowserTableViewColumnIndex index
);
198 OSStatus
SetColumnIndex (DataBrowserPropertyID propertyID
, DataBrowserTableViewColumnIndex index
);
199 OSStatus
SetDisclosureColumn(DataBrowserPropertyID propertyID
, Boolean expandableRows
=false);
200 OSStatus
SetPropertyFlags (DataBrowserPropertyID propertyID
, DataBrowserPropertyFlags flags
);
205 OSStatus
AddItem(DataBrowserItemID container
, DataBrowserItemID
const* itemID
) // adds a single item
207 return this->AddItems(container
,1,itemID
,kDataBrowserItemNoProperty
);
209 OSStatus
AddItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
); // adds items to the data browser
211 OSStatus
GetFreeItemID(DataBrowserItemID
* id
) const; // this method returns an item id that is valid and currently not used; if it cannot be found 'errDataBrowserItemNotAdded' is returned
212 OSStatus
GetItemCount (ItemCount
* numItems
) const
214 return this->GetItemCount(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,numItems
);
216 OSStatus
GetItemCount (DataBrowserItemID container
, Boolean recurse
, DataBrowserItemState state
, ItemCount
* numItems
) const;
217 OSStatus
GetItemID (DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const;
218 OSStatus
GetItems (DataBrowserItemID container
, Boolean recurse
, DataBrowserItemState state
, Handle items
) const;
219 OSStatus
GetItemRow (DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const;
220 OSStatus
GetItemState (DataBrowserItemID item
, DataBrowserItemState
* state
) const;
222 OSStatus
IsUsedItemID(DataBrowserItemID itemID
) const; // checks if the passed id is in use
224 OSStatus
RevealItem(DataBrowserItemID item
, DataBrowserPropertyID propertyID
, DataBrowserRevealOptions options
) const;
226 OSStatus
RemoveItem(DataBrowserItemID container
, DataBrowserItemID
const* itemID
) // removes a single item
228 return this->RemoveItems(container
,1,itemID
,kDataBrowserItemNoProperty
);
230 OSStatus
RemoveItems(void) // removes all items
232 return this->RemoveItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
);
234 OSStatus
RemoveItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
);
236 OSStatus
UpdateItem(DataBrowserItemID container
, DataBrowserItemID
const* item
) // updates all columns of the passed item
238 return this->UpdateItems(container
,1,item
,kDataBrowserItemNoProperty
,kDataBrowserItemNoProperty
);
240 OSStatus
UpdateItems(void) // updates all items
242 return this->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,kDataBrowserItemNoProperty
);
244 OSStatus
UpdateItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
, DataBrowserPropertyID propertyID
) const;
249 size_t GetSelectedItemIDs(wxArrayDataBrowserItemID
& itemIDs
) const; // returns the number of selected item and the item IDs in the array
250 OSStatus
GetSelectionAnchor(DataBrowserItemID
*first
, DataBrowserItemID
*last
) const;
251 OSStatus
GetSelectionFlags (DataBrowserSelectionFlags
* flags
) const;
253 bool IsItemSelected(DataBrowserItemID item
) const;
255 OSStatus
SetSelectionFlags(DataBrowserSelectionFlags flags
);
256 OSStatus
SetSelectedItems (UInt32 numItems
, DataBrowserItemID
const* itemIDs
, DataBrowserSetOption operation
);
261 OSStatus
GetSortOrder (DataBrowserSortOrder
* order
) const;
262 OSStatus
GetSortProperty(DataBrowserPropertyID
* propertyID
) const;
264 OSStatus
Resort(DataBrowserItemID container
=kDataBrowserNoItem
, Boolean sortChildren
=true);
266 OSStatus
SetSortOrder (DataBrowserSortOrder order
);
267 OSStatus
SetSortProperty(DataBrowserPropertyID propertyID
);
270 // container handling
272 OSStatus
CloseContainer(DataBrowserItemID containerID
);
274 OSStatus
OpenContainer(DataBrowserItemID containerID
);
278 // standard callback functions
280 static pascal Boolean
DataBrowserCompareProc (ControlRef browser
, DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
);
281 static pascal void DataBrowserGetContextualMenuProc(ControlRef browser
, MenuRef
* menu
, UInt32
* helpType
, CFStringRef
* helpItemString
, AEDesc
* selection
);
282 static pascal OSStatus
DataBrowserGetSetItemDataProc (ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID property
, DataBrowserItemDataRef itemData
, Boolean getValue
);
283 static pascal void DataBrowserItemNotificationProc (ControlRef browser
, DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
);
285 virtual Boolean
DataBrowserCompareProc (DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
) = 0;
286 virtual void DataBrowserGetContextualMenuProc(MenuRef
* menu
, UInt32
* helpType
, CFStringRef
* helpItemString
, AEDesc
* selection
) = 0;
287 virtual OSStatus
DataBrowserGetSetItemDataProc (DataBrowserItemID itemID
, DataBrowserPropertyID property
, DataBrowserItemDataRef itemData
, Boolean getValue
) = 0;
288 virtual void DataBrowserItemNotificationProc (DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
) = 0;
291 // callback functions for customized types
293 static pascal void DataBrowserDrawItemProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
);
294 static pascal Boolean
DataBrowserEditItemProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, CFStringRef theString
, Rect
* maxEditTextRect
, Boolean
* shrinkToFit
);
295 static pascal Boolean
DataBrowserHitTestProc (ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Rect
const* mouseRect
);
296 static pascal DataBrowserTrackingResult
DataBrowserTrackingProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Point startPt
, EventModifiers modifiers
);
298 virtual void DataBrowserDrawItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
) = 0;
299 virtual Boolean
DataBrowserEditItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, CFStringRef theString
, Rect
* maxEditTextRect
, Boolean
* shrinkToFit
) = 0;
300 virtual Boolean
DataBrowserHitTestProc (DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Rect
const* mouseRect
) = 0;
301 virtual DataBrowserTrackingResult
DataBrowserTrackingProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Point startPt
, EventModifiers modifiers
) = 0;
304 // callback functions for drag & drop
306 static pascal Boolean
DataBrowserAcceptDragProc (ControlRef browser
, DragReference dragRef
, DataBrowserItemID itemID
);
307 static pascal Boolean
DataBrowserAddDragItemProc(ControlRef browser
, DragReference dragRef
, DataBrowserItemID itemID
, ItemReference
* itemRef
);
308 static pascal Boolean
DataBrowserReceiveDragProc(ControlRef browser
, DragReference dragRef
, DataBrowserItemID itemID
);
310 virtual Boolean
DataBrowserAcceptDragProc (DragReference dragRef
, DataBrowserItemID itemID
) = 0;
311 virtual Boolean
DataBrowserAddDragItemProc(DragReference dragRef
, DataBrowserItemID itemID
, ItemReference
* itemRef
) = 0;
312 virtual Boolean
DataBrowserReceiveDragProc(DragReference dragRef
, DataBrowserItemID itemID
) = 0;
315 // event handler for hit testing
317 void* m_macDataViewCtrlEventHandler
;
321 // wxWidget internal stuff
323 DECLARE_ABSTRACT_CLASS(wxMacDataBrowserTableViewControl
)
326 // ============================================================================
327 // wxMacDataBrowserListViewControl
328 // ============================================================================
330 // This class is a wrapper for the native browser's list view style. It expands
331 // the inherited functionality of the table view control class.
332 // The term list view is in this case Mac OS X specific and is not related
333 // to any wxWidget naming conventions.
335 class wxMacDataBrowserListViewControl
: public wxMacDataBrowserTableViewControl
339 // constructors / destructor
341 wxMacDataBrowserListViewControl(wxWindow
* peer
, wxPoint
const& pos
, wxSize
const& size
, long style
) : wxMacDataBrowserTableViewControl(peer
,pos
,size
,style
)
348 OSStatus
AddColumn(DataBrowserListViewColumnDesc
*columnDesc
, DataBrowserTableViewColumnIndex position
);
355 // ============================================================================
356 // wxMacDataViewDataBrowserListViewControl
357 // ============================================================================
359 // This is the internal interface class between wxDataViewCtrl (wxWidget) and
360 // the native data browser (Mac OS X carbon).
362 class wxMacDataViewDataBrowserListViewControl
: public wxMacDataBrowserListViewControl
, public wxDataViewWidgetImpl
366 // constructors / destructor
368 wxMacDataViewDataBrowserListViewControl(wxWindow
* peer
, wxPoint
const& pos
, wxSize
const& size
, long style
);
371 // column related methods (inherited from wxDataViewWidgetImpl)
373 virtual bool ClearColumns (void);
374 virtual bool DeleteColumn (wxDataViewColumn
* columnPtr
);
375 virtual void DoSetExpanderColumn(wxDataViewColumn
const* columnPtr
);
376 virtual wxDataViewColumn
* GetColumn (unsigned int pos
) const;
377 virtual int GetColumnPosition (wxDataViewColumn
const* columnPtr
) const;
378 virtual bool InsertColumn (unsigned int pos
, wxDataViewColumn
* columnPtr
);
381 // item related methods (inherited from wxDataViewWidgetImpl)
383 virtual bool Add (wxDataViewItem
const& parent
, wxDataViewItem
const& item
);
384 virtual bool Add (wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
);
385 virtual void Collapse (wxDataViewItem
const& item
);
386 virtual void EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
);
387 virtual void Expand (wxDataViewItem
const& item
);
388 virtual unsigned int GetCount (void) const;
389 virtual wxRect
GetRectangle (wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
);
390 virtual bool IsExpanded (wxDataViewItem
const& item
) const;
391 virtual bool Reload (void);
392 virtual bool Remove (wxDataViewItem
const& parent
, wxDataViewItem
const& item
);
393 virtual bool Remove (wxDataViewItem
const& parent
, wxDataViewItemArray
const& item
);
394 virtual bool Update (wxDataViewColumn
const* columnPtr
);
395 virtual bool Update (wxDataViewItem
const& parent
, wxDataViewItem
const& item
);
396 virtual bool Update (wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
);
399 // model related methods
401 virtual bool AssociateModel(wxDataViewModel
* model
);
404 // selection related methods (inherited from wxDataViewWidgetImpl)
406 virtual int GetSelections(wxDataViewItemArray
& sel
) const;
407 virtual bool IsSelected (wxDataViewItem
const& item
) const;
408 virtual void Select (wxDataViewItem
const& item
);
409 virtual void SelectAll (void);
410 virtual void Unselect (wxDataViewItem
const& item
);
411 virtual void UnselectAll (void);
414 // sorting related methods
416 virtual wxDataViewColumn
* GetSortingColumn (void) const;
417 virtual void Resort (void);
420 // other methods (inherited from wxDataViewWidgetImpl)
422 virtual void DoSetIndent (int indent
);
423 virtual void HitTest (wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const;
424 virtual void SetRowHeight(wxDataViewItem
const& item
, unsigned int height
);
425 virtual void OnSize (void);
430 wxDataViewCtrl
* GetDataViewCtrl(void) const
432 return dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer());
437 // standard callback functions (inherited from wxMacDataBrowserTableViewControl)
439 virtual Boolean
DataBrowserCompareProc (DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
);
440 virtual void DataBrowserItemNotificationProc (DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
);
441 virtual void DataBrowserGetContextualMenuProc(MenuRef
* menu
, UInt32
* helpType
, CFStringRef
* helpItemString
, AEDesc
* selection
);
442 virtual OSStatus
DataBrowserGetSetItemDataProc (DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemDataRef itemData
, Boolean getValue
);
445 // callback functions for customized types (inherited from wxMacDataBrowserTableViewControl)
447 virtual void DataBrowserDrawItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
);
448 virtual Boolean
DataBrowserEditItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, CFStringRef theString
, Rect
* maxEditTextRect
, Boolean
* shrinkToFit
);
449 virtual Boolean
DataBrowserHitTestProc (DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Rect
const* mouseRect
);
450 virtual DataBrowserTrackingResult
DataBrowserTrackingProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Point startPt
, EventModifiers modifiers
);
453 // callback functions for drag & drop (inherited from wxMacDataBrowserTableViewControl)
455 virtual Boolean
DataBrowserAcceptDragProc (DragReference dragRef
, DataBrowserItemID itemID
);
456 virtual Boolean
DataBrowserAddDragItemProc(DragReference dragRef
, DataBrowserItemID itemID
, ItemReference
* itemRef
);
457 virtual Boolean
DataBrowserReceiveDragProc(DragReference dragRef
, DataBrowserItemID itemID
);
460 // drag & drop helper methods
462 wxDataFormat
GetDnDDataFormat(wxDataObjectComposite
* dataObjects
);
463 wxDataObjectComposite
* GetDnDDataObjects(DragReference dragRef
, ItemReference itemRef
) const; // create the data objects from the native dragged object
468 wxDataViewColumn
* GetColumnPtr(DataBrowserPropertyID propertyID
) const; // returns for the passed property the corresponding pointer to a column; NULL is returned if not found
473 typedef wxMacDataViewDataBrowserListViewControl
* wxMacDataViewDataBrowserListViewControlPointer
;
476 #endif // _WX_MACCARBONDATAVIEWCTRL_H_