]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/osx/carbon/dataview.h
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / include / wx / osx / carbon / dataview.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/osx/carbon/dataview.h
3// Purpose: wxDataViewCtrl native implementation header for carbon
4// Author:
5// Copyright: (c) 2009
6// Licence: wxWindows licence
7/////////////////////////////////////////////////////////////////////////////
8
9#ifndef _WX_DATAVIEWCTRL_CARBON_H_
10#define _WX_DATAVIEWCTRL_CARBON_H_
11
12#include "wx/defs.h"
13
14#if wxUSE_GUI
15
16#include "wx/osx/core/dataview.h"
17#include "wx/osx/private.h"
18
19// ============================================================================
20// wxDataViewColumnNativeData
21// ============================================================================
22class wxDataViewColumnNativeData
23{
24public:
25//
26// constructors / destructor
27//
28 wxDataViewColumnNativeData()
29 {
30 }
31 wxDataViewColumnNativeData(DataBrowserPropertyID initPropertyID)
32 :m_PropertyID(initPropertyID)
33 {
34 }
35
36//
37// data access methods
38//
39 DataBrowserPropertyID GetPropertyID() const
40 {
41 return m_PropertyID;
42 }
43
44 void SetPropertyID(DataBrowserPropertyID newPropertyID)
45 {
46 m_PropertyID = newPropertyID;
47 }
48
49protected:
50private:
51//
52// variables
53//
54 DataBrowserPropertyID m_PropertyID; // each column is identified by its unique property ID (NOT by the column's index)
55};
56
57// ============================================================================
58// wxDataViewRendererNativeData
59// ============================================================================
60class wxDataViewRendererNativeData
61{
62public:
63//
64// constructors / destructor
65//
66 wxDataViewRendererNativeData()
67 {
68 }
69 wxDataViewRendererNativeData(DataBrowserPropertyType initPropertyType, DataBrowserItemDataRef initItemDataRef=NULL)
70 :m_ItemDataRef(initItemDataRef), m_PropertyType(initPropertyType)
71 {
72 }
73
74//
75// data access methods
76//
77 DataBrowserItemDataRef GetItemDataRef() const
78 {
79 return m_ItemDataRef;
80 }
81 DataBrowserPropertyType GetPropertyType() const
82 {
83 return m_PropertyType;
84 }
85
86 void SetItemDataRef(DataBrowserItemDataRef newItemDataRef)
87 {
88 m_ItemDataRef = newItemDataRef;
89 }
90 void SetPropertyType(DataBrowserPropertyType newPropertyType)
91 {
92 m_PropertyType = newPropertyType;
93 }
94
95protected:
96private:
97//
98// variables
99//
100 DataBrowserItemDataRef m_ItemDataRef;
101
102 DataBrowserPropertyType m_PropertyType;
103};
104
105// ============================================================================
106// wxMacDataBrowserTableViewControl
107// ============================================================================
108//
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
111// and column style.
112//
113
114// data browser's property IDs have a reserved ID range from 0 - 1023
115// therefore, the first usable property ID is 'kMinPropertyID'
116DataBrowserPropertyID const kMinPropertyID = 1024;
117
118// array of data browser item IDs
119WX_DEFINE_ARRAY_SIZE_T(size_t,wxArrayDataBrowserItemID);
120
121class wxMacDataBrowserTableViewControl : public wxMacControl
122{
123public:
124//
125// constructors / destructor
126//
127 wxMacDataBrowserTableViewControl(wxWindow* peer, const wxPoint& pos, const wxSize& size, long style);
128 wxMacDataBrowserTableViewControl()
129 {
130 }
131 ~wxMacDataBrowserTableViewControl();
132
133//
134// callback handling
135//
136 OSStatus SetCallbacks (DataBrowserCallbacks const* callbacks);
137 OSStatus SetCustomCallbacks(DataBrowserCustomCallbacks const* customCallbacks);
138
139//
140// DnD handling
141//
142 OSStatus EnableAutomaticDragTracking(bool enable=true);
143
144//
145// header handling
146//
147 OSStatus GetHeaderDesc(DataBrowserPropertyID property, DataBrowserListViewHeaderDesc* desc) const;
148
149 OSStatus SetHeaderDesc(DataBrowserPropertyID property, DataBrowserListViewHeaderDesc* desc);
150
151//
152// layout handling
153//
154 OSStatus AutoSizeColumns();
155
156 OSStatus EnableCellSizeModification(bool enableHeight=true, bool enableWidth=true); // enables or disables the column width and row height modification (default: false)
157
158#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
159 OSStatus GetAttributes (OptionBits* attributes);
160#endif
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;
168
169#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
170 OSStatus SetAttributes (OptionBits attributes);
171#endif
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 );
181
182//
183// column handling
184//
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
191
192 OSStatus IsUsedPropertyID(DataBrowserPropertyID propertyID) const; // checks if passed property id is used by the control; no error is returned if the id exists
193
194 OSStatus RemoveColumnByProperty(DataBrowserTableViewColumnID propertyID);
195 OSStatus RemoveColumnByIndex (DataBrowserTableViewColumnIndex index);
196
197 OSStatus SetColumnIndex (DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex index);
198 OSStatus SetDisclosureColumn(DataBrowserPropertyID propertyID, Boolean expandableRows=false);
199 OSStatus SetPropertyFlags (DataBrowserPropertyID propertyID, DataBrowserPropertyFlags flags);
200
201//
202// item handling
203//
204 OSStatus AddItem(DataBrowserItemID container, DataBrowserItemID const* itemID) // adds a single item
205 {
206 return AddItems(container,1,itemID,kDataBrowserItemNoProperty);
207 }
208 OSStatus AddItems(DataBrowserItemID container, UInt32 numItems, DataBrowserItemID const* items, DataBrowserPropertyID preSortProperty); // adds items to the data browser
209
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
212 {
213 return GetItemCount(kDataBrowserNoItem,true,kDataBrowserItemAnyState,numItems);
214 }
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;
220
221 OSStatus IsUsedItemID(DataBrowserItemID itemID) const; // checks if the passed id is in use
222
223 OSStatus RevealItem(DataBrowserItemID item, DataBrowserPropertyID propertyID, DataBrowserRevealOptions options) const;
224
225 OSStatus RemoveItem(DataBrowserItemID container, DataBrowserItemID const* itemID) // removes a single item
226 {
227 return RemoveItems(container,1,itemID,kDataBrowserItemNoProperty);
228 }
229 OSStatus RemoveItems(void) // removes all items
230 {
231 return RemoveItems(kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty);
232 }
233 OSStatus RemoveItems(DataBrowserItemID container, UInt32 numItems, DataBrowserItemID const* items, DataBrowserPropertyID preSortProperty);
234
235 OSStatus UpdateItem(DataBrowserItemID container, DataBrowserItemID const* item) // updates all columns of the passed item
236 {
237 return UpdateItems(container,1,item,kDataBrowserItemNoProperty,kDataBrowserItemNoProperty);
238 }
239 OSStatus UpdateItems(void) // updates all items
240 {
241 return UpdateItems(kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty,kDataBrowserItemNoProperty);
242 }
243 OSStatus UpdateItems(DataBrowserItemID container, UInt32 numItems, DataBrowserItemID const* items, DataBrowserPropertyID preSortProperty, DataBrowserPropertyID propertyID) const;
244
245//
246// item selection
247//
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;
251
252 bool IsItemSelected(DataBrowserItemID item) const;
253
254 OSStatus SetSelectionFlags(DataBrowserSelectionFlags flags);
255 OSStatus SetSelectedItems (UInt32 numItems, DataBrowserItemID const* itemIDs, DataBrowserSetOption operation);
256
257//
258// item sorting
259//
260 OSStatus GetSortOrder (DataBrowserSortOrder* order) const;
261 OSStatus GetSortProperty(DataBrowserPropertyID* propertyID) const;
262
263 OSStatus Resort(DataBrowserItemID container=kDataBrowserNoItem, Boolean sortChildren=true);
264
265 OSStatus SetSortOrder (DataBrowserSortOrder order);
266 OSStatus SetSortProperty(DataBrowserPropertyID propertyID);
267
268//
269// container handling
270//
271 OSStatus CloseContainer(DataBrowserItemID containerID);
272
273 OSStatus OpenContainer(DataBrowserItemID containerID);
274
275protected :
276//
277// standard callback functions
278//
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);
283
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;
288
289//
290// callback functions for customized types
291//
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);
296
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;
301
302//
303// callback functions for drag & drop
304///
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);
308
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;
312
313//
314// event handler for hit testing
315///
316 void* m_macDataViewCtrlEventHandler;
317
318private:
319//
320// wxWidget internal stuff
321//
322 DECLARE_ABSTRACT_CLASS(wxMacDataBrowserTableViewControl)
323};
324
325// ============================================================================
326// wxMacDataBrowserListViewControl
327// ============================================================================
328//
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.
333//
334class wxMacDataBrowserListViewControl : public wxMacDataBrowserTableViewControl
335{
336public:
337//
338// constructors / destructor
339//
340 wxMacDataBrowserListViewControl(wxWindow* peer, wxPoint const& pos, wxSize const& size, long style) : wxMacDataBrowserTableViewControl(peer,pos,size,style)
341 {
342 }
343
344//
345// column handling
346//
347 OSStatus AddColumn(DataBrowserListViewColumnDesc *columnDesc, DataBrowserTableViewColumnIndex position);
348
349protected:
350private:
351};
352
353
354// ============================================================================
355// wxMacDataViewDataBrowserListViewControl
356// ============================================================================
357//
358// This is the internal interface class between wxDataViewCtrl (wxWidget) and
359// the native data browser (Mac OS X carbon).
360//
361class wxMacDataViewDataBrowserListViewControl : public wxMacDataBrowserListViewControl, public wxDataViewWidgetImpl
362{
363public:
364//
365// constructors / destructor
366//
367 wxMacDataViewDataBrowserListViewControl(wxWindow* peer, wxPoint const& pos, wxSize const& size, long style);
368
369 //
370 // column related methods (inherited from wxDataViewWidgetImpl)
371 //
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*/ }
379
380 //
381 // item related methods (inherited from wxDataViewWidgetImpl)
382 //
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);
397
398 //
399 // model related methods
400 //
401 virtual bool AssociateModel(wxDataViewModel* model);
402
403 //
404 // selection related methods (inherited from wxDataViewWidgetImpl)
405 //
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 ();
416
417 //
418 // sorting related methods
419 //
420 virtual wxDataViewColumn* GetSortingColumn () const;
421 virtual void Resort ();
422
423 //
424 // other methods (inherited from wxDataViewWidgetImpl)
425 //
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 ();
430
431 virtual void StartEditor( const wxDataViewItem & item, unsigned int column );
432
433 //
434 // other methods
435 //
436 wxDataViewCtrl* GetDataViewCtrl() const
437 {
438 return dynamic_cast<wxDataViewCtrl*>(GetWXPeer());
439 }
440
441protected:
442//
443// standard callback functions (inherited from wxMacDataBrowserTableViewControl)
444//
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);
449
450//
451// callback functions for customized types (inherited from wxMacDataBrowserTableViewControl)
452//
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);
457
458//
459// callback functions for drag & drop (inherited from wxMacDataBrowserTableViewControl)
460//
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);
464
465//
466// drag & drop helper methods
467//
468 wxDataFormat GetDnDDataFormat(wxDataObjectComposite* dataObjects);
469 wxDataObjectComposite* GetDnDDataObjects(DragReference dragRef, ItemReference itemRef) const; // create the data objects from the native dragged object
470
471//
472// other methods
473//
474 wxDataViewColumn* GetColumnPtr(DataBrowserPropertyID propertyID) const; // returns for the passed property the corresponding pointer to a column; NULL is returned if not found
475
476private:
477};
478
479typedef wxMacDataViewDataBrowserListViewControl* wxMacDataViewDataBrowserListViewControlPointer;
480
481#endif // WX_GUI
482#endif // _WX_MACCARBONDATAVIEWCTRL_H_