1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/carbon/dataview.h
3 // Purpose: wxDataViewCtrl native implementation header for carbon
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 #ifndef _WX_DATAVIEWCTRL_CARBON_H_
10 #define _WX_DATAVIEWCTRL_CARBON_H_
16 #include "wx/osx/core/dataview.h"
17 #include "wx/osx/private.h"
19 // ============================================================================
20 // wxDataViewColumnNativeData
21 // ============================================================================
22 class wxDataViewColumnNativeData
26 // constructors / destructor
28 wxDataViewColumnNativeData()
31 wxDataViewColumnNativeData(DataBrowserPropertyID initPropertyID
)
32 :m_PropertyID(initPropertyID
)
37 // data access methods
39 DataBrowserPropertyID
GetPropertyID() const
44 void SetPropertyID(DataBrowserPropertyID newPropertyID
)
46 m_PropertyID
= newPropertyID
;
54 DataBrowserPropertyID m_PropertyID
; // each column is identified by its unique property ID (NOT by the column's index)
57 // ============================================================================
58 // wxDataViewRendererNativeData
59 // ============================================================================
60 class wxDataViewRendererNativeData
64 // constructors / destructor
66 wxDataViewRendererNativeData()
69 wxDataViewRendererNativeData(DataBrowserPropertyType initPropertyType
, DataBrowserItemDataRef initItemDataRef
=NULL
)
70 :m_ItemDataRef(initItemDataRef
), m_PropertyType(initPropertyType
)
75 // data access methods
77 DataBrowserItemDataRef
GetItemDataRef() const
81 DataBrowserPropertyType
GetPropertyType() const
83 return m_PropertyType
;
86 void SetItemDataRef(DataBrowserItemDataRef newItemDataRef
)
88 m_ItemDataRef
= newItemDataRef
;
90 void SetPropertyType(DataBrowserPropertyType newPropertyType
)
92 m_PropertyType
= newPropertyType
;
100 DataBrowserItemDataRef m_ItemDataRef
;
102 DataBrowserPropertyType m_PropertyType
;
105 // ============================================================================
106 // wxMacDataBrowserTableViewControl
107 // ============================================================================
109 // This is a wrapper class for the Mac OS X data browser environment.
110 // It covers all data brower functionality for the native browser's list
114 // data browser's property IDs have a reserved ID range from 0 - 1023
115 // therefore, the first usable property ID is 'kMinPropertyID'
116 DataBrowserPropertyID
const kMinPropertyID
= 1024;
118 // array of data browser item IDs
119 WX_DEFINE_ARRAY_SIZE_T(size_t,wxArrayDataBrowserItemID
);
121 class wxMacDataBrowserTableViewControl
: public wxMacControl
125 // constructors / destructor
127 wxMacDataBrowserTableViewControl(wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
128 wxMacDataBrowserTableViewControl()
131 ~wxMacDataBrowserTableViewControl();
136 OSStatus
SetCallbacks (DataBrowserCallbacks
const* callbacks
);
137 OSStatus
SetCustomCallbacks(DataBrowserCustomCallbacks
const* customCallbacks
);
142 OSStatus
EnableAutomaticDragTracking(bool enable
=true);
147 OSStatus
GetHeaderDesc(DataBrowserPropertyID property
, DataBrowserListViewHeaderDesc
* desc
) const;
149 OSStatus
SetHeaderDesc(DataBrowserPropertyID property
, DataBrowserListViewHeaderDesc
* desc
);
154 OSStatus
AutoSizeColumns();
156 OSStatus
EnableCellSizeModification(bool enableHeight
=true, bool enableWidth
=true); // enables or disables the column width and row height modification (default: false)
158 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
159 OSStatus
GetAttributes (OptionBits
* attributes
);
161 OSStatus
GetColumnWidth (DataBrowserPropertyID column
, UInt16
*width
) const; // returns the column width in pixels
162 OSStatus
GetDefaultColumnWidth(UInt16
*width
) const; // returns the default column width in pixels
163 OSStatus
GetDefaultRowHeight (UInt16
* height
) const;
164 OSStatus
GetHeaderButtonHeight(UInt16
*height
);
165 OSStatus
GetPartBounds (DataBrowserItemID item
, DataBrowserPropertyID property
, DataBrowserPropertyPart part
, Rect
* bounds
);
166 OSStatus
GetRowHeight (DataBrowserItemID item
, UInt16
*height
) const;
167 OSStatus
GetScrollPosition (UInt32
* top
, UInt32
*left
) const;
169 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
170 OSStatus
SetAttributes (OptionBits attributes
);
172 OSStatus
SetColumnWidth(DataBrowserPropertyID column
, UInt16 width
); // sets the column width in pixels
173 OSStatus
SetDefaultColumnWidth( UInt16 width
);
174 OSStatus
SetDefaultRowHeight( UInt16 height
);
175 OSStatus
SetHasScrollBars( bool horiz
, bool vert
);
176 OSStatus
SetHeaderButtonHeight( UInt16 height
);
177 OSStatus
SetHiliteStyle(DataBrowserTableViewHiliteStyle hiliteStyle
);
178 OSStatus
SetIndent(float Indent
);
179 OSStatus
SetItemRowHeight( DataBrowserItemID item
, UInt16 height
);
180 OSStatus
SetScrollPosition( UInt32 top
, UInt32 left
);
185 OSStatus
GetColumnCount (UInt32
* numColumns
) const;
186 OSStatus
GetColumnIndex (DataBrowserPropertyID propertyID
, DataBrowserTableViewColumnIndex
* index
) const; // returns for the passed property the corresponding column index
187 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
188 OSStatus
GetPropertyFlags (DataBrowserPropertyID propertyID
, DataBrowserPropertyFlags
*flags
) const;
189 OSStatus
GetPropertyID (DataBrowserItemDataRef itemData
, DataBrowserPropertyID
* propertyID
) const; // returns for the passed item data reference the corresponding property ID
190 OSStatus
GetPropertyID (DataBrowserTableViewColumnIndex index
, DataBrowserPropertyID
* propertyID
) const; // returns for the passed column index the corresponding property ID
192 OSStatus
IsUsedPropertyID(DataBrowserPropertyID propertyID
) const; // checks if passed property id is used by the control; no error is returned if the id exists
194 OSStatus
RemoveColumnByProperty(DataBrowserTableViewColumnID propertyID
);
195 OSStatus
RemoveColumnByIndex (DataBrowserTableViewColumnIndex index
);
197 OSStatus
SetColumnIndex (DataBrowserPropertyID propertyID
, DataBrowserTableViewColumnIndex index
);
198 OSStatus
SetDisclosureColumn(DataBrowserPropertyID propertyID
, Boolean expandableRows
=false);
199 OSStatus
SetPropertyFlags (DataBrowserPropertyID propertyID
, DataBrowserPropertyFlags flags
);
204 OSStatus
AddItem(DataBrowserItemID container
, DataBrowserItemID
const* itemID
) // adds a single item
206 return AddItems(container
,1,itemID
,kDataBrowserItemNoProperty
);
208 OSStatus
AddItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
); // adds items to the data browser
210 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
211 OSStatus
GetItemCount (ItemCount
* numItems
) const
213 return GetItemCount(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,numItems
);
215 OSStatus
GetItemCount (DataBrowserItemID container
, Boolean recurse
, DataBrowserItemState state
, ItemCount
* numItems
) const;
216 OSStatus
GetItemID (DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const;
217 OSStatus
GetItems (DataBrowserItemID container
, Boolean recurse
, DataBrowserItemState state
, Handle items
) const;
218 OSStatus
GetItemRow (DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const;
219 OSStatus
GetItemState (DataBrowserItemID item
, DataBrowserItemState
* state
) const;
221 OSStatus
IsUsedItemID(DataBrowserItemID itemID
) const; // checks if the passed id is in use
223 OSStatus
RevealItem(DataBrowserItemID item
, DataBrowserPropertyID propertyID
, DataBrowserRevealOptions options
) const;
225 OSStatus
RemoveItem(DataBrowserItemID container
, DataBrowserItemID
const* itemID
) // removes a single item
227 return RemoveItems(container
,1,itemID
,kDataBrowserItemNoProperty
);
229 OSStatus
RemoveItems(void) // removes all items
231 return RemoveItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
);
233 OSStatus
RemoveItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
);
235 OSStatus
UpdateItem(DataBrowserItemID container
, DataBrowserItemID
const* item
) // updates all columns of the passed item
237 return UpdateItems(container
,1,item
,kDataBrowserItemNoProperty
,kDataBrowserItemNoProperty
);
239 OSStatus
UpdateItems(void) // updates all items
241 return UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,kDataBrowserItemNoProperty
);
243 OSStatus
UpdateItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
, DataBrowserPropertyID propertyID
) const;
248 size_t GetSelectedItemIDs(wxArrayDataBrowserItemID
& itemIDs
) const; // returns the number of selected item and the item IDs in the array
249 OSStatus
GetSelectionAnchor(DataBrowserItemID
*first
, DataBrowserItemID
*last
) const;
250 OSStatus
GetSelectionFlags (DataBrowserSelectionFlags
* flags
) const;
252 bool IsItemSelected(DataBrowserItemID item
) const;
254 OSStatus
SetSelectionFlags(DataBrowserSelectionFlags flags
);
255 OSStatus
SetSelectedItems (UInt32 numItems
, DataBrowserItemID
const* itemIDs
, DataBrowserSetOption operation
);
260 OSStatus
GetSortOrder (DataBrowserSortOrder
* order
) const;
261 OSStatus
GetSortProperty(DataBrowserPropertyID
* propertyID
) const;
263 OSStatus
Resort(DataBrowserItemID container
=kDataBrowserNoItem
, Boolean sortChildren
=true);
265 OSStatus
SetSortOrder (DataBrowserSortOrder order
);
266 OSStatus
SetSortProperty(DataBrowserPropertyID propertyID
);
269 // container handling
271 OSStatus
CloseContainer(DataBrowserItemID containerID
);
273 OSStatus
OpenContainer(DataBrowserItemID containerID
);
277 // standard callback functions
279 static pascal Boolean
DataBrowserCompareProc (ControlRef browser
, DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
);
280 static pascal void DataBrowserGetContextualMenuProc(ControlRef browser
, MenuRef
* menu
, UInt32
* helpType
, CFStringRef
* helpItemString
, AEDesc
* selection
);
281 static pascal OSStatus
DataBrowserGetSetItemDataProc (ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID property
, DataBrowserItemDataRef itemData
, Boolean getValue
);
282 static pascal void DataBrowserItemNotificationProc (ControlRef browser
, DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
);
284 virtual Boolean
DataBrowserCompareProc (DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
) = 0;
285 virtual void DataBrowserGetContextualMenuProc(MenuRef
* menu
, UInt32
* helpType
, CFStringRef
* helpItemString
, AEDesc
* selection
) = 0;
286 virtual OSStatus
DataBrowserGetSetItemDataProc (DataBrowserItemID itemID
, DataBrowserPropertyID property
, DataBrowserItemDataRef itemData
, Boolean getValue
) = 0;
287 virtual void DataBrowserItemNotificationProc (DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
) = 0;
290 // callback functions for customized types
292 static pascal void DataBrowserDrawItemProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
);
293 static pascal Boolean
DataBrowserEditItemProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, CFStringRef theString
, Rect
* maxEditTextRect
, Boolean
* shrinkToFit
);
294 static pascal Boolean
DataBrowserHitTestProc (ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Rect
const* mouseRect
);
295 static pascal DataBrowserTrackingResult
DataBrowserTrackingProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Point startPt
, EventModifiers modifiers
);
297 virtual void DataBrowserDrawItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
) = 0;
298 virtual Boolean
DataBrowserEditItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, CFStringRef theString
, Rect
* maxEditTextRect
, Boolean
* shrinkToFit
) = 0;
299 virtual Boolean
DataBrowserHitTestProc (DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Rect
const* mouseRect
) = 0;
300 virtual DataBrowserTrackingResult
DataBrowserTrackingProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Point startPt
, EventModifiers modifiers
) = 0;
303 // callback functions for drag & drop
305 static pascal Boolean
DataBrowserAcceptDragProc (ControlRef browser
, DragReference dragRef
, DataBrowserItemID itemID
);
306 static pascal Boolean
DataBrowserAddDragItemProc(ControlRef browser
, DragReference dragRef
, DataBrowserItemID itemID
, ItemReference
* itemRef
);
307 static pascal Boolean
DataBrowserReceiveDragProc(ControlRef browser
, DragReference dragRef
, DataBrowserItemID itemID
);
309 virtual Boolean
DataBrowserAcceptDragProc (DragReference dragRef
, DataBrowserItemID itemID
) = 0;
310 virtual Boolean
DataBrowserAddDragItemProc(DragReference dragRef
, DataBrowserItemID itemID
, ItemReference
* itemRef
) = 0;
311 virtual Boolean
DataBrowserReceiveDragProc(DragReference dragRef
, DataBrowserItemID itemID
) = 0;
314 // event handler for hit testing
316 void* m_macDataViewCtrlEventHandler
;
320 // wxWidget internal stuff
322 DECLARE_ABSTRACT_CLASS(wxMacDataBrowserTableViewControl
)
325 // ============================================================================
326 // wxMacDataBrowserListViewControl
327 // ============================================================================
329 // This class is a wrapper for the native browser's list view style. It expands
330 // the inherited functionality of the table view control class.
331 // The term list view is in this case Mac OS X specific and is not related
332 // to any wxWidget naming conventions.
334 class wxMacDataBrowserListViewControl
: public wxMacDataBrowserTableViewControl
338 // constructors / destructor
340 wxMacDataBrowserListViewControl(wxWindow
* peer
, wxPoint
const& pos
, wxSize
const& size
, long style
) : wxMacDataBrowserTableViewControl(peer
,pos
,size
,style
)
347 OSStatus
AddColumn(DataBrowserListViewColumnDesc
*columnDesc
, DataBrowserTableViewColumnIndex position
);
354 // ============================================================================
355 // wxMacDataViewDataBrowserListViewControl
356 // ============================================================================
358 // This is the internal interface class between wxDataViewCtrl (wxWidget) and
359 // the native data browser (Mac OS X carbon).
361 class wxMacDataViewDataBrowserListViewControl
: public wxMacDataBrowserListViewControl
, public wxDataViewWidgetImpl
365 // constructors / destructor
367 wxMacDataViewDataBrowserListViewControl(wxWindow
* peer
, wxPoint
const& pos
, wxSize
const& size
, long style
);
370 // column related methods (inherited from wxDataViewWidgetImpl)
372 virtual bool ClearColumns ();
373 virtual bool DeleteColumn (wxDataViewColumn
* columnPtr
);
374 virtual void DoSetExpanderColumn(wxDataViewColumn
const* columnPtr
);
375 virtual wxDataViewColumn
* GetColumn (unsigned int pos
) const;
376 virtual int GetColumnPosition (wxDataViewColumn
const* columnPtr
) const;
377 virtual bool InsertColumn (unsigned int pos
, wxDataViewColumn
* columnPtr
);
378 virtual void FitColumnWidthToContent(unsigned int WXUNUSED(pos
)) { /*not implemented*/ }
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 () const;
389 virtual wxRect
GetRectangle (wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
);
390 virtual bool IsExpanded (wxDataViewItem
const& item
) const;
391 virtual bool Reload ();
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 wxDataViewItem
GetCurrentItem() const;
407 virtual void SetCurrentItem(const wxDataViewItem
& item
);
408 virtual wxDataViewColumn
*GetCurrentColumn() const;
409 virtual int GetSelectedItemsCount() const;
410 virtual int GetSelections(wxDataViewItemArray
& sel
) const;
411 virtual bool IsSelected (wxDataViewItem
const& item
) const;
412 virtual void Select (wxDataViewItem
const& item
);
413 virtual void SelectAll ();
414 virtual void Unselect (wxDataViewItem
const& item
);
415 virtual void UnselectAll ();
418 // sorting related methods
420 virtual wxDataViewColumn
* GetSortingColumn () const;
421 virtual void Resort ();
424 // other methods (inherited from wxDataViewWidgetImpl)
426 virtual void DoSetIndent (int indent
);
427 virtual void HitTest (wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const;
428 virtual void SetRowHeight(wxDataViewItem
const& item
, unsigned int height
);
429 virtual void OnSize ();
431 virtual void StartEditor( const wxDataViewItem
& item
, unsigned int column
);
436 wxDataViewCtrl
* GetDataViewCtrl() const
438 return dynamic_cast<wxDataViewCtrl
*>(GetWXPeer());
443 // standard callback functions (inherited from wxMacDataBrowserTableViewControl)
445 virtual Boolean
DataBrowserCompareProc (DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
);
446 virtual void DataBrowserItemNotificationProc (DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
);
447 virtual void DataBrowserGetContextualMenuProc(MenuRef
* menu
, UInt32
* helpType
, CFStringRef
* helpItemString
, AEDesc
* selection
);
448 virtual OSStatus
DataBrowserGetSetItemDataProc (DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemDataRef itemData
, Boolean getValue
);
451 // callback functions for customized types (inherited from wxMacDataBrowserTableViewControl)
453 virtual void DataBrowserDrawItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
);
454 virtual Boolean
DataBrowserEditItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, CFStringRef theString
, Rect
* maxEditTextRect
, Boolean
* shrinkToFit
);
455 virtual Boolean
DataBrowserHitTestProc (DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Rect
const* mouseRect
);
456 virtual DataBrowserTrackingResult
DataBrowserTrackingProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Point startPt
, EventModifiers modifiers
);
459 // callback functions for drag & drop (inherited from wxMacDataBrowserTableViewControl)
461 virtual Boolean
DataBrowserAcceptDragProc (DragReference dragRef
, DataBrowserItemID itemID
);
462 virtual Boolean
DataBrowserAddDragItemProc(DragReference dragRef
, DataBrowserItemID itemID
, ItemReference
* itemRef
);
463 virtual Boolean
DataBrowserReceiveDragProc(DragReference dragRef
, DataBrowserItemID itemID
);
466 // drag & drop helper methods
468 wxDataFormat
GetDnDDataFormat(wxDataObjectComposite
* dataObjects
);
469 wxDataObjectComposite
* GetDnDDataObjects(DragReference dragRef
, ItemReference itemRef
) const; // create the data objects from the native dragged object
474 wxDataViewColumn
* GetColumnPtr(DataBrowserPropertyID propertyID
) const; // returns for the passed property the corresponding pointer to a column; NULL is returned if not found
479 typedef wxMacDataViewDataBrowserListViewControl
* wxMacDataViewDataBrowserListViewControlPointer
;
482 #endif // _WX_MACCARBONDATAVIEWCTRL_H_