]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/carbon/databrow.h
made wxUSE_UNICODE=1 the default
[wxWidgets.git] / include / wx / mac / carbon / databrow.h
CommitLineData
c0a66d92
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: include/mac/carbon/databrow.h
3// Purpose: Classes and functions for the Carbon data browser
4// Author:
5// Modified by:
6// Created: 2007-05-18
7// RCS-ID: $Id$
8// Copyright: (c)
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_DATABROW_H_
13#define _WX_DATABROW_H_
14
15#include "wx/defs.h"
16
17#ifdef __DARWIN__
18# include <Carbon/Carbon.h>
19#else
20# include <Debugging.h>
21# include <Appearance.h>
22# include <Controls.h>
23# include <ControlDefinitions.h>
24# include <LowMem.h>
25# include <Gestalt.h>
26# include <CoreServices.h>
27#endif
28
29#if UNIVERSAL_INTERFACES_VERSION < 0x0342
30 #error "please update to Apple's latest universal headers from http://developer.apple.com/sdk/"
31#endif
32
33#ifndef MAC_OS_X_VERSION_10_3
34 #define MAC_OS_X_VERSION_10_3 1030
35#endif
36
37#ifndef MAC_OS_X_VERSION_10_4
38 #define MAC_OS_X_VERSION_10_4 1040
39#endif
40
41#ifndef MAC_OS_X_VERSION_10_5
42 #define MAC_OS_X_VERSION_10_5 1050
43#endif
44
45#ifdef __WXMAC_CARBON__
46# include "wx/mac/corefoundation/cfstring.h"
47#endif
48
49#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
50typedef UInt32 URefCon;
51typedef SInt32 SRefCon;
52#endif
53
54#if wxUSE_GUI
55
56#include "wx/hashmap.h"
57
58#include "wx/mac/private.h"
59
60WX_DEFINE_ARRAY_SIZE_T(size_t,wxArrayDataBrowserItemID);
61
62// ============================================================================
63// DataBrowser Wrapper
64// ============================================================================
65//
66// basing on DataBrowserItemIDs
67//
68
69// data browser's property IDs have a reserved ID range from 0 - 1023
70// therefore, the first usable property ID is 'kMinPropertyID'
71DataBrowserPropertyID const kMinPropertyID = 1024;
72
73class wxMacDataBrowserTableViewControl : public wxMacControl
74{
75public:
76//
77// constructors / destructor
78//
79 wxMacDataBrowserTableViewControl(wxWindow* peer, const wxPoint& pos, const wxSize& size, long style);
80 wxMacDataBrowserTableViewControl(void)
81 {
82 }
83
84//
85// callback handling
86//
87 OSStatus SetCallbacks (DataBrowserCallbacks const* callbacks);
88 OSStatus SetCustomCallbacks(DataBrowserCustomCallbacks const* customCallbacks);
89
90//
91// header handling
92//
93 OSStatus GetHeaderDesc(DataBrowserPropertyID property, DataBrowserListViewHeaderDesc* desc) const;
94
95 OSStatus SetHeaderDesc(DataBrowserPropertyID property, DataBrowserListViewHeaderDesc* desc);
96
97//
98// layout handling
99//
100 OSStatus AutoSizeColumns();
101
102 OSStatus EnableCellSizeModification(bool enableHeight=true, bool enableWidth=true); // enables or disables the column width and row height modification (default: false)
103
104#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
105 OSStatus GetAttributes (OptionBits* attributes);
106#endif
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;
113
114#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
115 OSStatus SetAttributes (OptionBits attributes);
116#endif
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 );
125
126//
127// column handling
128//
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;
134
135 OSStatus IsUsedPropertyID(DataBrowserPropertyID propertyID) const; // checks if passed property id is used by the control; no error is returned if the id exists
136
137 OSStatus RemoveColumn(DataBrowserTableViewColumnIndex position);
138
139 OSStatus SetColumnPosition (DataBrowserPropertyID column, DataBrowserTableViewColumnIndex position);
140 OSStatus SetDisclosureColumn(DataBrowserPropertyID property, Boolean expandableRows );
141 OSStatus SetPropertyFlags (DataBrowserPropertyID property, DataBrowserPropertyFlags flags );
142
143//
144// item handling
145//
146 OSStatus AddItem(DataBrowserItemID container, DataBrowserItemID const* itemID) // adds a single item
147 {
148 return this->AddItems(container,1,itemID,kDataBrowserItemNoProperty);
149 }
150 OSStatus AddItems(DataBrowserItemID container, UInt32 numItems, DataBrowserItemID const* items, DataBrowserPropertyID preSortProperty); // adds items to the data browser
151
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
154 {
155 return this->GetItemCount(kDataBrowserNoItem,true,kDataBrowserItemAnyState,numItems);
156 }
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;
161
162 OSStatus IsUsedItemID(DataBrowserItemID itemID) const; // checks if the passed id is in use
163
164 OSStatus RevealItem(DataBrowserItemID item, DataBrowserPropertyID propertyID, DataBrowserRevealOptions options) const;
165
166 OSStatus RemoveItem(DataBrowserItemID container, DataBrowserItemID const* itemID) // removes a single item
167 {
168 return this->RemoveItems(container,1,itemID,kDataBrowserItemNoProperty);
169 }
170 OSStatus RemoveItems(void) // removes all items
171 {
172 return this->RemoveItems(kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty);
173 }
174 OSStatus RemoveItems(DataBrowserItemID container, UInt32 numItems, DataBrowserItemID const* items, DataBrowserPropertyID preSortProperty);
175
176 OSStatus UpdateItems(void) // updates all items
177 {
178 return this->UpdateItems(kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty,kDataBrowserNoItem);
179 }
180 OSStatus UpdateItems(DataBrowserItemID const* item) // updates all columns of item
181 {
182 return this->UpdateItems(kDataBrowserNoItem,1,item,kDataBrowserItemNoProperty,kDataBrowserNoItem);
183 }
184 OSStatus UpdateItems(DataBrowserItemID container, UInt32 numItems, DataBrowserItemID const* items, DataBrowserPropertyID preSortProperty, DataBrowserPropertyID propertyID) const;
185
186//
187// item selection
188//
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;
192
193 bool IsItemSelected(DataBrowserItemID item) const;
194
195 OSStatus SetSelectionFlags(DataBrowserSelectionFlags flags);
196 OSStatus SetSelectedItems (UInt32 numItems, DataBrowserItemID const* itemIDs, DataBrowserSetOption operation);
197
198//
199// item sorting
200//
201 OSStatus GetSortOrder (DataBrowserSortOrder* order) const;
202 OSStatus GetSortProperty(DataBrowserPropertyID* column) const;
203
204 OSStatus SetSortOrder (DataBrowserSortOrder order);
205 OSStatus SetSortProperty(DataBrowserPropertyID column);
206
207protected :
208//
209// callback functions
210//
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);
215
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;
220private:
221//
222// wxWidget internal stuff
223//
224 DECLARE_ABSTRACT_CLASS(wxMacDataBrowserTableViewControl)
225};
226
227// ============================================================================
228// Databrowser class for the list view control
229// ============================================================================
230//
231class wxMacDataBrowserListViewControl : public wxMacDataBrowserTableViewControl
232{
233public:
234//
235// constructors / destructor
236//
237 wxMacDataBrowserListViewControl(wxWindow* peer, wxPoint const& pos, wxSize const& size, long style) : wxMacDataBrowserTableViewControl(peer,pos,size,style)
238 {
239 }
240
241//
242// column handling
243//
244 OSStatus AddColumn(DataBrowserListViewColumnDesc *columnDesc, DataBrowserTableViewColumnIndex position);
245
246protected:
247private:
248};
249
250
251// ============================================================================
252// Databrowser class for the data view list control model
253// ============================================================================
254//
255
256//
257// Hash maps used by the data browser for the data view model
258//
259WX_DECLARE_HASH_MAP(DataBrowserItemID,unsigned long,wxIntegerHash,wxIntegerEqual,ItemIDRowNumberHashMap); // stores for each item ID the model's row number
260
261class wxMacDataViewDataBrowserListViewControl : public wxMacDataBrowserListViewControl
262{
263public:
264//
265// constructors / destructor
266 wxMacDataViewDataBrowserListViewControl(wxWindow* peer, wxPoint const& pos, wxSize const& size, long style);
267
268//
269// item ID and model matching
270//
271 void ClearItemIDRowPairs(void); // removes all ID row pairs
272
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
274
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
276
277 bool InsertItemIDRowPair(DataBrowserItemID itemID, unsigned long rowIndex); // the pair will only be inserted if the item ID does not exist before the call
278
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'
282
283 void ReverseRowIndexNumbering(void); // reverses the order of the indices
284
285protected:
286//
287// callback functions (inherited from wxMacDataBrowserTableViewControl)
288//
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);
293
294private:
295//
296// variables
297//
298 ItemIDRowNumberHashMap m_itemIDRowNumberMap; // contains for each data browser ID the corresponding line number in the model
299};
300
301typedef wxMacDataViewDataBrowserListViewControl* wxMacDataViewDataBrowserListViewControlPointer;
302
303
304#endif // WX_GUI
305
306#endif // _WX_DATABROW_H_