1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/mac/carbon/databrow.h
3 // Purpose: Classes and functions for the Carbon data browser
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_DATABROW_H_
13 #define _WX_DATABROW_H_
18 # include <Carbon/Carbon.h>
20 # include <Debugging.h>
21 # include <Appearance.h>
22 # include <Controls.h>
23 # include <ControlDefinitions.h>
26 # include <CoreServices.h>
29 #if UNIVERSAL_INTERFACES_VERSION < 0x0342
30 #error "please update to Apple's latest universal headers from http://developer.apple.com/sdk/"
33 #ifndef MAC_OS_X_VERSION_10_3
34 #define MAC_OS_X_VERSION_10_3 1030
37 #ifndef MAC_OS_X_VERSION_10_4
38 #define MAC_OS_X_VERSION_10_4 1040
41 #ifndef MAC_OS_X_VERSION_10_5
42 #define MAC_OS_X_VERSION_10_5 1050
45 #ifdef __WXMAC_CARBON__
46 # include "wx/mac/corefoundation/cfstring.h"
49 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
50 typedef UInt32 URefCon
;
51 typedef SInt32 SRefCon
;
56 #include "wx/hashmap.h"
58 #include "wx/mac/private.h"
60 WX_DEFINE_ARRAY_SIZE_T(size_t,wxArrayDataBrowserItemID
);
62 // ============================================================================
63 // DataBrowser Wrapper
64 // ============================================================================
66 // basing on DataBrowserItemIDs
69 // data browser's property IDs have a reserved ID range from 0 - 1023
70 // therefore, the first usable property ID is 'kMinPropertyID'
71 DataBrowserPropertyID
const kMinPropertyID
= 1024;
73 class wxMacDataBrowserTableViewControl
: public wxMacControl
77 // constructors / destructor
79 wxMacDataBrowserTableViewControl(wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
80 wxMacDataBrowserTableViewControl(void)
87 OSStatus
SetCallbacks (DataBrowserCallbacks
const* callbacks
);
88 OSStatus
SetCustomCallbacks(DataBrowserCustomCallbacks
const* customCallbacks
);
93 OSStatus
GetHeaderDesc(DataBrowserPropertyID property
, DataBrowserListViewHeaderDesc
* desc
) const;
95 OSStatus
SetHeaderDesc(DataBrowserPropertyID property
, DataBrowserListViewHeaderDesc
* desc
);
100 OSStatus
AutoSizeColumns();
102 OSStatus
EnableCellSizeModification(bool enableHeight
=true, bool enableWidth
=true); // enables or disables the column width and row height modification (default: false)
104 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
105 OSStatus
GetAttributes (OptionBits
* attributes
);
107 OSStatus
GetColumnWidth (DataBrowserPropertyID column
, UInt16
*width
) const; // returns the column width in pixels
108 OSStatus
GetDefaultColumnWidth(UInt16
*width
) const; // returns the default column width in pixels
109 OSStatus
GetDefaultRowHeight (UInt16
* height
) const;
110 OSStatus
GetHeaderButtonHeight(UInt16
*height
);
111 OSStatus
GetRowHeight (DataBrowserItemID item
, UInt16
*height
) const;
112 OSStatus
GetScrollPosition (UInt32
* top
, UInt32
*left
) const;
114 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
115 OSStatus
SetAttributes (OptionBits attributes
);
117 OSStatus
SetColumnWidth(DataBrowserPropertyID column
, UInt16 width
); // sets the column width in pixels
118 OSStatus
SetDefaultColumnWidth( UInt16 width
);
119 OSStatus
SetDefaultRowHeight( UInt16 height
);
120 OSStatus
SetHasScrollBars( bool horiz
, bool vert
);
121 OSStatus
SetHeaderButtonHeight( UInt16 height
);
122 OSStatus
SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
);
123 OSStatus
SetRowHeight( DataBrowserItemID item
, UInt16 height
);
124 OSStatus
SetScrollPosition( UInt32 top
, UInt32 left
);
129 OSStatus
GetColumnCount (UInt32
* numColumns
) const;
130 OSStatus
GetColumnID (DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
);
131 OSStatus
GetFreePropertyID(DataBrowserPropertyID
* id
) const; // this method returns a property id that is valid and currently not used; if it cannot be found 'errDataBrowerPropertyNotSupported' is returned
132 OSStatus
GetPropertyColumn(DataBrowserPropertyID propertyID
, DataBrowserTableViewColumnIndex
* index
) const;
133 OSStatus
GetPropertyFlags (DataBrowserPropertyID propertyID
, DataBrowserPropertyFlags
*flags
) const;
135 OSStatus
IsUsedPropertyID(DataBrowserPropertyID propertyID
) const; // checks if passed property id is used by the control; no error is returned if the id exists
137 OSStatus
RemoveColumn(DataBrowserTableViewColumnIndex position
);
139 OSStatus
SetColumnPosition (DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
);
140 OSStatus
SetDisclosureColumn(DataBrowserPropertyID property
, Boolean expandableRows
);
141 OSStatus
SetPropertyFlags (DataBrowserPropertyID property
, DataBrowserPropertyFlags flags
);
146 OSStatus
AddItem(DataBrowserItemID container
, DataBrowserItemID
const* itemID
) // adds a single item
148 return this->AddItems(container
,1,itemID
,kDataBrowserItemNoProperty
);
150 OSStatus
AddItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
); // adds items to the data browser
152 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
153 OSStatus
GetItemCount (ItemCount
* numItems
) const
155 return this->GetItemCount(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,numItems
);
157 OSStatus
GetItemCount (DataBrowserItemID container
, Boolean recurse
, DataBrowserItemState state
, ItemCount
* numItems
) const;
158 OSStatus
GetItemID (DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const;
159 OSStatus
GetItems (DataBrowserItemID container
, Boolean recurse
, DataBrowserItemState state
, Handle items
) const;
160 OSStatus
GetItemRow (DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const;
162 OSStatus
IsUsedItemID(DataBrowserItemID itemID
) const; // checks if the passed id is in use
164 OSStatus
RevealItem(DataBrowserItemID item
, DataBrowserPropertyID propertyID
, DataBrowserRevealOptions options
) const;
166 OSStatus
RemoveItem(DataBrowserItemID container
, DataBrowserItemID
const* itemID
) // removes a single item
168 return this->RemoveItems(container
,1,itemID
,kDataBrowserItemNoProperty
);
170 OSStatus
RemoveItems(void) // removes all items
172 return this->RemoveItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
);
174 OSStatus
RemoveItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
);
176 OSStatus
UpdateItems(void) // updates all items
178 return this->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,kDataBrowserNoItem
);
180 OSStatus
UpdateItems(DataBrowserItemID
const* item
) // updates all columns of item
182 return this->UpdateItems(kDataBrowserNoItem
,1,item
,kDataBrowserItemNoProperty
,kDataBrowserNoItem
);
184 OSStatus
UpdateItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
, DataBrowserPropertyID propertyID
) const;
189 size_t GetSelectedItemIDs(wxArrayDataBrowserItemID
& itemIDs
) const; // returns the number of selected item and the item IDs in the array
190 OSStatus
GetSelectionAnchor(DataBrowserItemID
*first
, DataBrowserItemID
*last
) const;
191 OSStatus
GetSelectionFlags (DataBrowserSelectionFlags
* flags
) const;
193 bool IsItemSelected(DataBrowserItemID item
) const;
195 OSStatus
SetSelectionFlags(DataBrowserSelectionFlags flags
);
196 OSStatus
SetSelectedItems (UInt32 numItems
, DataBrowserItemID
const* itemIDs
, DataBrowserSetOption operation
);
201 OSStatus
GetSortOrder (DataBrowserSortOrder
* order
) const;
202 OSStatus
GetSortProperty(DataBrowserPropertyID
* column
) const;
204 OSStatus
SetSortOrder (DataBrowserSortOrder order
);
205 OSStatus
SetSortProperty(DataBrowserPropertyID column
);
209 // callback functions
211 static pascal Boolean
DataBrowserCompareProc (ControlRef browser
, DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
);
212 static pascal void DataBrowserDrawItemProc (ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID property
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
);
213 static pascal OSStatus
DataBrowserGetSetItemDataProc (ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID property
, DataBrowserItemDataRef itemData
, Boolean getValue
);
214 static pascal void DataBrowserItemNotificationProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
);
216 virtual Boolean
DataBrowserCompareProc (DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
) = 0;
217 virtual void DataBrowserDrawItemProc (DataBrowserItemID itemID
, DataBrowserPropertyID property
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
) = 0;
218 virtual OSStatus
DataBrowserGetSetItemDataProc (DataBrowserItemID itemID
, DataBrowserPropertyID property
, DataBrowserItemDataRef itemData
, Boolean getValue
) = 0;
219 virtual void DataBrowserItemNotificationProc(DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
) = 0;
222 // wxWidget internal stuff
224 DECLARE_ABSTRACT_CLASS(wxMacDataBrowserTableViewControl
)
227 // ============================================================================
228 // Databrowser class for the list view control
229 // ============================================================================
231 class wxMacDataBrowserListViewControl
: public wxMacDataBrowserTableViewControl
235 // constructors / destructor
237 wxMacDataBrowserListViewControl(wxWindow
* peer
, wxPoint
const& pos
, wxSize
const& size
, long style
) : wxMacDataBrowserTableViewControl(peer
,pos
,size
,style
)
244 OSStatus
AddColumn(DataBrowserListViewColumnDesc
*columnDesc
, DataBrowserTableViewColumnIndex position
);
251 // ============================================================================
252 // Databrowser class for the data view list control model
253 // ============================================================================
257 // Hash maps used by the data browser for the data view model
259 WX_DECLARE_HASH_MAP(DataBrowserItemID
,unsigned long,wxIntegerHash
,wxIntegerEqual
,ItemIDRowNumberHashMap
); // stores for each item ID the model's row number
261 class wxMacDataViewDataBrowserListViewControl
: public wxMacDataBrowserListViewControl
265 // constructors / destructor
266 wxMacDataViewDataBrowserListViewControl(wxWindow
* peer
, wxPoint
const& pos
, wxSize
const& size
, long style
);
269 // item ID and model matching
271 void ClearItemIDRowPairs(void); // removes all ID row pairs
273 bool DeleteItemIDRowPair(DataBrowserItemID itemID
); // if the id has been removed, 'true' is returned, 'false' is returned if the id did not exist or another error occurred
275 bool GetRowIndex(unsigned long& rowIndex
, DataBrowserItemID itemID
) const; // returns 'true' and the rowIndex if the id has been found in the map, otherwise 'false' is returned and rowIndex remains untouched
277 bool InsertItemIDRowPair(DataBrowserItemID itemID
, unsigned long rowIndex
); // the pair will only be inserted if the item ID does not exist before the call
279 void RenumberItemIDRowIndices (unsigned int* newIndices
); // for each item ID - row index pair the row index is changed
280 void RenumberItemIDRowIndicesDeletion (unsigned long decreaseFromIndex
); // decreases all row indices by one that are equal or larger than 'decreaseFromIndex'
281 void RenumberItemIDRowIndicesInsertion(unsigned long increaseFromIndex
); // increases all row indices by one that are equal or larger than 'increaseFromIndex'
283 void ReverseRowIndexNumbering(void); // reverses the order of the indices
287 // callback functions (inherited from wxMacDataBrowserTableViewControl)
289 virtual Boolean
DataBrowserCompareProc (DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
);
290 virtual void DataBrowserDrawItemProc (DataBrowserItemID itemID
, DataBrowserPropertyID property
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
);
291 virtual void DataBrowserItemNotificationProc(DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
);
292 virtual OSStatus
DataBrowserGetSetItemDataProc (DataBrowserItemID itemID
, DataBrowserPropertyID property
, DataBrowserItemDataRef itemData
, Boolean getValue
);
298 ItemIDRowNumberHashMap m_itemIDRowNumberMap
; // contains for each data browser ID the corresponding line number in the model
301 typedef wxMacDataViewDataBrowserListViewControl
* wxMacDataViewDataBrowserListViewControlPointer
;
306 #endif // _WX_DATABROW_H_