]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/databrow.cpp
Return type correction
[wxWidgets.git] / src / mac / carbon / databrow.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/databrow.cpp
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 wxUSE_GENERICDATAVIEWCTRL
13
14 #include <limits>
15
16 #include "wx/wxprec.h"
17 #ifndef WX_PRECOMP
18 #include "wx/app.h"
19 #include "wx/toplevel.h"
20 #include "wx/font.h"
21 #endif
22
23 #include "wx/dataview.h"
24 #include "wx/utils.h"
25
26 #include "wx/mac/carbon/databrow.h"
27 #include "wx/mac/private.h"
28 #include "wx/mac/uma.h"
29
30 // ============================================================================
31 // Variables used globally in databrow.cpp
32 // ============================================================================
33 DataBrowserGetContextualMenuUPP gDataBrowserTableViewGetContextualMenuUPP = NULL;
34 DataBrowserItemCompareUPP gDataBrowserTableViewItemCompareUPP = NULL;
35 DataBrowserItemDataUPP gDataBrowserTableViewItemDataUPP = NULL;
36 DataBrowserItemNotificationUPP gDataBrowserTableViewItemNotificationUPP = NULL;
37
38 DataBrowserDrawItemUPP gDataBrowserTableViewDrawItemUPP = NULL;
39 DataBrowserEditItemUPP gDataBrowserTableViewEditItemUPP = NULL;
40 DataBrowserHitTestUPP gDataBrowserTableViewHitTestUPP = NULL;
41 DataBrowserTrackingUPP gDataBrowserTableViewTrackingUPP = NULL;
42
43 // ============================================================================
44 // wxMacDataBrowserTableViewControl
45 // ============================================================================
46
47 pascal Boolean wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlRef browser, DataBrowserItemID itemOneID, DataBrowserItemID itemTwoID, DataBrowserPropertyID sortProperty)
48 {
49 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
50
51
52 if (ControlPtr != NULL)
53 return ControlPtr->DataBrowserCompareProc(itemOneID,itemTwoID,sortProperty);
54 else
55 return errDataBrowserPropertyNotSupported;
56 } /* wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlRef, DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
57
58 pascal void wxMacDataBrowserTableViewControl::DataBrowserGetContextualMenuProc(ControlRef browser, MenuRef* menu, UInt32* helpType, CFStringRef* helpItemString, AEDesc* selection)
59 {
60 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
61
62
63 if (ControlPtr != NULL)
64 ControlPtr->DataBrowserGetContextualMenuProc(menu,helpType,helpItemString,selection);
65 } /* wxMacDataBrowserTableViewControl::DataBrowserGetContextualMenuProc(ControlRef, MenuRef*, UInt32*, CFStringRef*, AEDesc*) */
66
67 pascal OSStatus wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemDataRef itemData, Boolean getValue)
68 {
69 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
70
71
72 if (ControlPtr != NULL)
73 return ControlPtr->DataBrowserGetSetItemDataProc(itemID,propertyID,itemData,getValue);
74 else
75 return errDataBrowserPropertyNotSupported;
76 } /* wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */
77
78 pascal void wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message, DataBrowserItemDataRef itemData)
79 {
80 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
81
82
83 if (ControlPtr != NULL)
84 ControlPtr->DataBrowserItemNotificationProc(itemID,message,itemData);
85 } /* wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc(ControlRef, DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */
86
87 pascal void wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemState state, Rect const* rectangle, SInt16 bitDepth, Boolean colorDevice)
88 {
89 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
90
91
92 if (ControlPtr != NULL)
93 ControlPtr->DataBrowserDrawItemProc(itemID,propertyID,state,rectangle,bitDepth,colorDevice);
94 } /* wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */
95
96 pascal Boolean wxMacDataBrowserTableViewControl::DataBrowserEditItemProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID propertyID, CFStringRef theString, Rect* maxEditTextRect, Boolean* shrinkToFit)
97 {
98 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
99
100
101 return ((ControlPtr != NULL) && ControlPtr->DataBrowserEditItemProc(itemID,propertyID,theString,maxEditTextRect,shrinkToFit));
102 } /* wxMacDataBrowserTableViewControl::DataBrowserEditItemProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, CFStringRef, Rect*, Boolean*) */
103
104 pascal Boolean wxMacDataBrowserTableViewControl::DataBrowserHitTestProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID propertyID, Rect const* theRect, Rect const* mouseRect)
105 {
106 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
107
108
109 return ((ControlPtr != NULL) && ControlPtr->DataBrowserHitTestProc(itemID,propertyID,theRect,mouseRect));
110 } /* wxMacDataBrowserTableViewControl::DataBrowserHitTestProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, Rect const*, Rect const*) */
111
112 pascal DataBrowserTrackingResult wxMacDataBrowserTableViewControl::DataBrowserTrackingProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID propertyID, Rect const* theRect, Point startPt, EventModifiers modifiers)
113 {
114 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
115
116
117 if (ControlPtr != NULL)
118 return ControlPtr->DataBrowserTrackingProc(itemID,propertyID,theRect,startPt,modifiers);
119 else
120 return kDataBrowserNothingHit;
121 } /* wxMacDataBrowserTableViewControl::DataBrowserTrackingProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, Rect const*, Point, EventModifiers) */
122
123 wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow* peer, wxPoint const& pos, wxSize const& size, long style)
124 :wxMacControl(peer)
125 {
126 Rect bounds = wxMacGetBoundsForControl(peer,pos,size);
127 OSStatus err = ::CreateDataBrowserControl(MAC_WXHWND(peer->MacGetTopLevelWindowRef()),&bounds,kDataBrowserListView,&(this->m_controlRef));
128
129
130 SetReferenceInNativeControl();
131 verify_noerr(err);
132 // setup standard callbacks:
133 if (gDataBrowserTableViewGetContextualMenuUPP == NULL) gDataBrowserTableViewGetContextualMenuUPP = NewDataBrowserGetContextualMenuUPP(wxMacDataBrowserTableViewControl::DataBrowserGetContextualMenuProc);
134 if (gDataBrowserTableViewItemCompareUPP == NULL) gDataBrowserTableViewItemCompareUPP = NewDataBrowserItemCompareUPP (wxMacDataBrowserTableViewControl::DataBrowserCompareProc);
135 if (gDataBrowserTableViewItemDataUPP == NULL) gDataBrowserTableViewItemDataUPP = NewDataBrowserItemDataUPP (wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc);
136 if (gDataBrowserTableViewItemNotificationUPP == NULL)
137 {
138 gDataBrowserTableViewItemNotificationUPP =
139 #if TARGET_API_MAC_OSX
140 (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc);
141 #else
142 NewDataBrowserItemNotificationUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc);
143 #endif
144 }
145 DataBrowserCallbacks callbacks; // variable definition
146
147 InitializeDataBrowserCallbacks(&callbacks,kDataBrowserLatestCallbacks);
148 callbacks.u.v1.getContextualMenuCallback = gDataBrowserTableViewGetContextualMenuUPP;
149 callbacks.u.v1.itemDataCallback = gDataBrowserTableViewItemDataUPP;
150 callbacks.u.v1.itemCompareCallback = gDataBrowserTableViewItemCompareUPP;
151 callbacks.u.v1.itemNotificationCallback = gDataBrowserTableViewItemNotificationUPP;
152 this->SetCallbacks(&callbacks);
153
154 // setup callbacks for customized items:
155 if (gDataBrowserTableViewDrawItemUPP == NULL) gDataBrowserTableViewDrawItemUPP = NewDataBrowserDrawItemUPP(wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc);
156 if (gDataBrowserTableViewEditItemUPP == NULL) gDataBrowserTableViewEditItemUPP = NewDataBrowserEditItemUPP(wxMacDataBrowserTableViewControl::DataBrowserEditItemProc);
157 if (gDataBrowserTableViewHitTestUPP == NULL) gDataBrowserTableViewHitTestUPP = NewDataBrowserHitTestUPP (wxMacDataBrowserTableViewControl::DataBrowserHitTestProc);
158 if (gDataBrowserTableViewTrackingUPP == NULL) gDataBrowserTableViewTrackingUPP = NewDataBrowserTrackingUPP(wxMacDataBrowserTableViewControl::DataBrowserTrackingProc);
159
160 DataBrowserCustomCallbacks customCallbacks; // variable definition
161
162 InitializeDataBrowserCustomCallbacks(&customCallbacks,kDataBrowserLatestCallbacks);
163 customCallbacks.u.v1.drawItemCallback = gDataBrowserTableViewDrawItemUPP;
164 customCallbacks.u.v1.editTextCallback = gDataBrowserTableViewEditItemUPP;
165 customCallbacks.u.v1.hitTestCallback = gDataBrowserTableViewHitTestUPP;
166 customCallbacks.u.v1.trackingCallback = gDataBrowserTableViewTrackingUPP;
167 this->SetCustomCallbacks(&customCallbacks);
168
169 // style setting:
170 this->EnableCellSizeModification();
171
172 DataBrowserSelectionFlags flags; // variable definition
173
174 if (this->GetSelectionFlags(&flags) == noErr) // get default settings
175 {
176 if ((style & wxDV_MULTIPLE) != 0)
177 flags &= ~kDataBrowserSelectOnlyOne;
178 else
179 flags |= kDataBrowserSelectOnlyOne;
180 (void) this->SetSelectionFlags(flags);
181 } /* if */
182
183 OptionBits attributes; // variable definition
184
185 if (this->GetAttributes(&attributes) == noErr) // get default settings
186 {
187 if ((style & wxDV_VERT_RULES) != 0)
188 attributes |= kDataBrowserAttributeListViewDrawColumnDividers;
189 else
190 attributes &= ~kDataBrowserAttributeListViewDrawColumnDividers;
191 if ((style & wxDV_ROW_LINES) != 0)
192 attributes |= kDataBrowserAttributeListViewAlternatingRowColors;
193 else
194 attributes &= ~kDataBrowserAttributeListViewAlternatingRowColors;
195 (void) this->SetAttributes(attributes);
196 } /* if */
197
198 if ((style & wxDV_NO_HEADER) != 0)
199 this->SetHeaderButtonHeight(0);
200 } /* wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow*, wxPoint const&, wxSize const&, long) */
201
202 //
203 // callback handling
204 //
205 OSStatus wxMacDataBrowserTableViewControl::SetCallbacks(DataBrowserCallbacks const* callbacks)
206 {
207 return ::SetDataBrowserCallbacks(this->m_controlRef,callbacks);
208 } /* wxMacDataBrowserTableViewControl::SetCallbacks(DataBrowserCallbacks const*) */
209
210 OSStatus wxMacDataBrowserTableViewControl::SetCustomCallbacks(DataBrowserCustomCallbacks const* customCallbacks)
211 {
212 return ::SetDataBrowserCustomCallbacks(this->m_controlRef,customCallbacks);
213 } /* xMacDataBrowserTableViewControl::SetCustomCallbacks(DataBrowserCustomCallbacks const*) */
214
215 //
216 // header handling
217 //
218 OSStatus wxMacDataBrowserTableViewControl::GetHeaderDesc(DataBrowserPropertyID propertyID, DataBrowserListViewHeaderDesc* desc) const
219 {
220 desc->version = kDataBrowserListViewLatestHeaderDesc; // if this statement is missing the next call will fail (NOT DOCUMENTED!!)
221 return ::GetDataBrowserListViewHeaderDesc(this->m_controlRef,propertyID,desc);
222 }
223
224 OSStatus wxMacDataBrowserTableViewControl::SetHeaderDesc(DataBrowserPropertyID propertyID, DataBrowserListViewHeaderDesc* desc)
225 {
226 return ::SetDataBrowserListViewHeaderDesc(this->m_controlRef,propertyID,desc);
227 }
228
229 //
230 // layout handling
231 //
232 OSStatus wxMacDataBrowserTableViewControl::AutoSizeColumns()
233 {
234 return AutoSizeDataBrowserListViewColumns(this->m_controlRef);
235 }
236
237 OSStatus wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool enableHeight, bool enableWidth)
238 {
239 return ::SetDataBrowserTableViewGeometry(this->GetControlRef(),enableWidth,enableHeight);
240 } /* wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool, bool) */
241
242 OSStatus wxMacDataBrowserTableViewControl::GetAttributes(OptionBits* attributes)
243 {
244 return ::DataBrowserGetAttributes(this->GetControlRef(),attributes);
245 } /* wxMacDataBrowserTableViewControl::GetAttributes(OptionBits*) */
246
247 OSStatus wxMacDataBrowserTableViewControl::GetColumnWidth(DataBrowserPropertyID propertyID, UInt16* width) const
248 {
249 return ::GetDataBrowserTableViewNamedColumnWidth(this->m_controlRef,propertyID,width);
250 }
251
252 OSStatus wxMacDataBrowserTableViewControl::GetDefaultColumnWidth( UInt16 *width ) const
253 {
254 return GetDataBrowserTableViewColumnWidth(this->m_controlRef, width );
255 }
256
257 OSStatus wxMacDataBrowserTableViewControl::GetDefaultRowHeight(UInt16* height) const
258 {
259 return ::GetDataBrowserTableViewRowHeight(this->m_controlRef,height);
260 }
261
262 OSStatus wxMacDataBrowserTableViewControl::GetHeaderButtonHeight(UInt16 *height)
263 {
264 return ::GetDataBrowserListViewHeaderBtnHeight(this->m_controlRef,height);
265 }
266
267 OSStatus wxMacDataBrowserTableViewControl::GetPartBounds(DataBrowserItemID item, DataBrowserPropertyID propertyID, DataBrowserPropertyPart part, Rect* bounds)
268 {
269 return ::GetDataBrowserItemPartBounds(this->m_controlRef,item,propertyID,part,bounds);
270 } /* wxMacDataBrowserTableViewControl::GetPartBounds(DataBrowserItemID, DataBrowswerPropertyID, DataBrowserPropertyPart, Rect*) */
271
272 OSStatus wxMacDataBrowserTableViewControl::GetRowHeight(DataBrowserItemID item, UInt16* height) const
273 {
274 return ::GetDataBrowserTableViewItemRowHeight(this->m_controlRef,item,height);
275 } /* wxMacDataBrowserTableViewControl::GetRowHeight(DataBrowserItemID, UInt16*) const */
276
277 OSStatus wxMacDataBrowserTableViewControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const
278 {
279 return GetDataBrowserScrollPosition(this->m_controlRef, top , left );
280 }
281
282 OSStatus wxMacDataBrowserTableViewControl::SetAttributes(OptionBits attributes)
283 {
284 return ::DataBrowserChangeAttributes(this->GetControlRef(),attributes,~attributes);
285 } /* wxMacDataBrowserTableViewControl::SetAttributes(OptionBits) */
286
287 OSStatus wxMacDataBrowserTableViewControl::SetColumnWidth(DataBrowserPropertyID propertyID, UInt16 width)
288 {
289 return ::SetDataBrowserTableViewNamedColumnWidth(this->m_controlRef,propertyID,width);
290 }
291
292 OSStatus wxMacDataBrowserTableViewControl::SetDefaultColumnWidth(UInt16 width)
293 {
294 return ::SetDataBrowserTableViewColumnWidth(this->m_controlRef,width);
295 }
296
297 OSStatus wxMacDataBrowserTableViewControl::SetDefaultRowHeight(UInt16 height)
298 {
299 return ::SetDataBrowserTableViewRowHeight(this->m_controlRef,height);
300 }
301
302 OSStatus wxMacDataBrowserTableViewControl::SetHasScrollBars(bool horiz, bool vert)
303 {
304 return ::SetDataBrowserHasScrollBars(this->m_controlRef,horiz,vert);
305 } /* wxMacDataBrowserTableViewControl::SetHasScrollBars(bool, bool) */
306
307 OSStatus wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16 height)
308 {
309 return ::SetDataBrowserListViewHeaderBtnHeight(this->m_controlRef,height);
310 } /* wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16) */
311
312 OSStatus wxMacDataBrowserTableViewControl::SetHiliteStyle(DataBrowserTableViewHiliteStyle hiliteStyle)
313 {
314 return ::SetDataBrowserTableViewHiliteStyle(this->m_controlRef,hiliteStyle);
315 } /*wxMacDataBrowserTableViewControl::SetHiliteStyle(DataBrowserTableViewHiliteStyle) */
316
317 OSStatus wxMacDataBrowserTableViewControl::SetIndent(float Indent)
318 {
319 return ::DataBrowserSetMetric(this->m_controlRef,kDataBrowserMetricDisclosureColumnPerDepthGap,true,Indent);
320 } /* wxMacDataBrowserTableViewControl::SetIndent(float* Indent) */
321
322 OSStatus wxMacDataBrowserTableViewControl::SetRowHeight(DataBrowserItemID item, UInt16 height)
323 {
324 return ::SetDataBrowserTableViewItemRowHeight(this->m_controlRef,item,height);
325 }
326
327 OSStatus wxMacDataBrowserTableViewControl::SetScrollPosition(UInt32 top, UInt32 left)
328 {
329 return ::SetDataBrowserScrollPosition(this->m_controlRef,top,left);
330 }
331
332 //
333 // column handling
334 //
335 OSStatus wxMacDataBrowserTableViewControl::GetColumnCount(UInt32* numColumns) const
336 {
337 return ::GetDataBrowserTableViewColumnCount(this->m_controlRef,numColumns);
338 }
339
340 OSStatus wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex* index) const
341 {
342 return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,index);
343 } /* wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex*) const */
344
345 OSStatus wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID* propertyID) const
346 {
347 for (*propertyID=kMinPropertyID; *propertyID<std::numeric_limits<DataBrowserPropertyID>::max(); ++(*propertyID))
348 if (this->IsUsedPropertyID(*propertyID) == errDataBrowserPropertyNotFound)
349 return noErr;
350 return errDataBrowserPropertyNotSupported;
351 } /* wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID*) const */
352
353 OSStatus wxMacDataBrowserTableViewControl::GetPropertyFlags(DataBrowserPropertyID propertyID, DataBrowserPropertyFlags *flags) const
354 {
355 return ::GetDataBrowserPropertyFlags(this->m_controlRef,propertyID,flags);
356 }
357
358 OSStatus wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef itemData, DataBrowserPropertyID* propertyID)
359 {
360 return ::GetDataBrowserItemDataProperty(itemData,propertyID);
361 } /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef, DataBrowserPropertyID*) */
362
363 OSStatus wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex index, DataBrowserTableViewColumnID* propertyID)
364 {
365 return ::GetDataBrowserTableViewColumnProperty(this->m_controlRef,index,propertyID);
366 } /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex, DataBrowserTableViewColumnID*) */
367
368 OSStatus wxMacDataBrowserTableViewControl::IsUsedPropertyID(DataBrowserPropertyID propertyID) const
369 {
370 // as the Mac interface does not provide a function that checks if the property id is in use or not a function is chosen that should not
371 // lead to a large overhead for the call but returns an error code if the property id does not exist, here we use the function that returns
372 // the column position for the property id:
373 DataBrowserTableViewColumnIndex index;
374
375 return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,&index);
376 } /* wxMacDataBrowserTableViewControl::IsUsedPropertyId(DataBrowserPropertyID) const */
377
378 OSStatus wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID propertyID)
379 {
380 return ::RemoveDataBrowserTableViewColumn(this->m_controlRef,propertyID);
381 } /* wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID) */
382
383 OSStatus wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex index)
384 {
385 DataBrowserTableViewColumnID propertyID;
386
387
388 this->GetPropertyID(index,&propertyID);
389 return ::RemoveDataBrowserTableViewColumn(this->m_controlRef,propertyID);
390 } /* wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex) */
391
392 OSStatus wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex index)
393 {
394 return ::SetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,index);
395 } /* wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex) */
396
397 OSStatus wxMacDataBrowserTableViewControl::SetDisclosureColumn(DataBrowserPropertyID propertyID, Boolean expandableRows)
398 {
399 return ::SetDataBrowserListViewDisclosureColumn(this->m_controlRef,propertyID,expandableRows);
400 }
401
402 OSStatus wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID propertyID, DataBrowserPropertyFlags flags)
403 {
404 return ::SetDataBrowserPropertyFlags(this->m_controlRef,propertyID,flags);
405 } /* wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID, DataBrowserPropertyFlags) */
406
407 //
408 // item handling
409 //
410 OSStatus wxMacDataBrowserTableViewControl::AddItems(DataBrowserItemID container, UInt32 numItems, DataBrowserItemID const* items, DataBrowserPropertyID preSortProperty)
411 {
412 return ::AddDataBrowserItems(this->m_controlRef,container,numItems,items,preSortProperty);
413 } /* wxMacDataBrowserTableViewControl::AddItems(DataBrowserItemID, UInt32, DataBrowserItemID const*, DataBrowserPropertyID) */
414
415 OSStatus wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID* id) const
416 {
417 ItemCount NoOfItems;
418
419 OSStatus status;
420
421
422 status = this->GetItemCount(&NoOfItems);
423 wxCHECK_MSG(status == noErr,status,_("Could not retrieve number of items"));
424 if (NoOfItems == 0)
425 {
426 *id = 1;
427 return noErr;
428 } /* if */
429 else
430 {
431 // as there might be a lot of items in the data browser and mostly the data is added item by item the largest used ID number is roughly in the order of magnitude
432 // as the number of items; therefore, start from the number of items to look for a new ID:
433 for (*id=NoOfItems; *id<std::numeric_limits<DataBrowserItemID>::max(); ++(*id))
434 if (this->IsUsedItemID(*id) == errDataBrowserItemNotFound)
435 return noErr;
436 // as the first approach was not successful, try from the beginning:
437 for (*id=0; *id<NoOfItems; ++(*id))
438 if (this->IsUsedItemID(*id) == errDataBrowserItemNotFound)
439 return noErr;
440 // sorry, data browser is full:
441 return errDataBrowserItemNotAdded;
442 } /* if */
443 } /* wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID*) const */
444
445 OSStatus wxMacDataBrowserTableViewControl::GetItemCount(DataBrowserItemID container, Boolean recurse, DataBrowserItemState state, ItemCount* numItems) const
446 {
447 return GetDataBrowserItemCount(this->m_controlRef,container,recurse,state,numItems);
448 } /* wxMacDataBrowserTableViewControl::GetItemCount(DataBrowserItemID, Boolean, DataBrowserItemState, ItemCount*) const */
449
450 OSStatus wxMacDataBrowserTableViewControl::GetItemID( DataBrowserTableViewRowIndex row, DataBrowserItemID * item ) const
451 {
452 return GetDataBrowserTableViewItemID(this->m_controlRef,row,item);
453 }
454
455 OSStatus wxMacDataBrowserTableViewControl::GetItems(DataBrowserItemID container, Boolean recurse, DataBrowserItemState state, Handle items) const
456 {
457 return GetDataBrowserItems(this->m_controlRef,container,recurse,state,items);
458 } /* wxMacDataBrowserTableViewControl::GetItems(DataBrowserItemID, Boolean, DataBrowserItemState, Handle) const */
459
460 OSStatus wxMacDataBrowserTableViewControl::GetItemRow(DataBrowserItemID item, DataBrowserTableViewRowIndex* row) const
461 {
462 return GetDataBrowserTableViewItemRow(this->m_controlRef,item,row);
463 }
464
465 OSStatus wxMacDataBrowserTableViewControl::IsUsedItemID(DataBrowserItemID itemID) const
466 {
467 // as the Mac interface does not provide a function that checks if the property id is in use or not a function is chosen that should not
468 // lead to a large overhead for the call but returns an error code if the property id does not exist, here we use the function that returns
469 // the column position for the property id:
470 DataBrowserTableViewColumnIndex index;
471
472 return ::GetDataBrowserTableViewItemRow(this->m_controlRef,itemID,&index);
473 } /* wxMacDataBrowserTableViewControl::IsUsedItemID(DataBrowserItemID) const */
474
475 OSStatus wxMacDataBrowserTableViewControl::RemoveItems(DataBrowserItemID container, UInt32 numItems, DataBrowserItemID const* items, DataBrowserPropertyID preSortProperty)
476 {
477 return ::RemoveDataBrowserItems(this->m_controlRef,container,numItems,items,preSortProperty);
478 }
479
480 OSStatus wxMacDataBrowserTableViewControl::RevealItem(DataBrowserItemID item, DataBrowserPropertyID propertyID, DataBrowserRevealOptions options) const
481 {
482 return ::RevealDataBrowserItem(this->m_controlRef,item,propertyID,options);
483 } /* wxMacDataBrowserTableViewControl::RevealItem(DataBrowserItemID item, DataBrowserPropertyID propertyID, DataBrowserRevealOptions options) const */
484
485 OSStatus wxMacDataBrowserTableViewControl::UpdateItems(DataBrowserItemID container, UInt32 numItems, DataBrowserItemID const* items, DataBrowserPropertyID preSortProperty,
486 DataBrowserPropertyID propertyID) const
487 {
488 return UpdateDataBrowserItems(this->m_controlRef,container,numItems,items,preSortProperty,propertyID);
489 }
490
491 //
492 // item selection
493 //
494 size_t wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserItemID& itemIDs) const
495 {
496 DataBrowserItemID* itemIDPtr;
497 Handle handle(::NewHandle(0));
498
499 size_t NoOfItems;
500
501
502 wxCHECK_MSG(this->GetItems(kDataBrowserNoItem,true,kDataBrowserItemIsSelected,handle) == noErr,0,_("Could not get selected items."));
503 NoOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
504 itemIDs.Empty();
505 itemIDs.Alloc(NoOfItems);
506 HLock(handle);
507 itemIDPtr = (DataBrowserItemID*) (*handle);
508 for (size_t i=0; i<NoOfItems; ++i)
509 {
510 itemIDs.Add(*itemIDPtr);
511 ++itemIDPtr;
512 } /* for */
513 HUnlock(handle);
514 DisposeHandle(handle);
515 return NoOfItems;
516 } /* wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserItemID&) const*/
517
518 OSStatus wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID* first, DataBrowserItemID* last) const
519 {
520 return ::GetDataBrowserSelectionAnchor(this->m_controlRef,first,last);
521 } /* wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID*, DataBrowserItemID*) const */
522
523 OSStatus wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags* flags) const
524 {
525 return ::GetDataBrowserSelectionFlags(this->m_controlRef,flags);
526 } /* wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags*) const */
527
528 bool wxMacDataBrowserTableViewControl::IsItemSelected(DataBrowserItemID item) const
529 {
530 return ::IsDataBrowserItemSelected(this->m_controlRef,item);
531 } /* wxMacDataBrowserTableViewControl::IsItemSelected(DataBrowserItemID) const */
532
533 OSStatus wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectionFlags flags)
534 {
535 return ::SetDataBrowserSelectionFlags(this->m_controlRef,flags);
536 } /* wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectionFlags) */
537
538 OSStatus wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32 numItems, DataBrowserItemID const* items, DataBrowserSetOption operation)
539 {
540 return ::SetDataBrowserSelectedItems(this->m_controlRef, numItems, items, operation );
541 } /* wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32, DataBrowserItemID const*, DataBrowserSetOption) */
542
543 OSStatus wxMacDataBrowserTableViewControl::GetSortOrder(DataBrowserSortOrder* order) const
544 {
545 return ::GetDataBrowserSortOrder(this->m_controlRef,order);
546 }
547
548 OSStatus wxMacDataBrowserTableViewControl::GetSortProperty(DataBrowserPropertyID* propertyID) const
549 {
550 return ::GetDataBrowserSortProperty(this->m_controlRef,propertyID);
551 }
552
553 OSStatus wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID container, Boolean sortChildren)
554 {
555 return ::SortDataBrowserContainer(this->m_controlRef,container,sortChildren);
556 } /* wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID, Boolean) */
557
558 OSStatus wxMacDataBrowserTableViewControl::SetSortOrder(DataBrowserSortOrder order)
559 {
560 return ::SetDataBrowserSortOrder(this->m_controlRef,order);
561 }
562
563 OSStatus wxMacDataBrowserTableViewControl::SetSortProperty(DataBrowserPropertyID propertyID)
564 {
565 return ::SetDataBrowserSortProperty(this->m_controlRef,propertyID);
566 }
567
568 //
569 // container handling
570 //
571 OSStatus wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID containerID)
572 {
573 return ::CloseDataBrowserContainer(this->m_controlRef,containerID);
574 } /* wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID) */
575
576 OSStatus wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID containerID)
577 {
578 return ::OpenDataBrowserContainer(this->m_controlRef,containerID);
579 } /* wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID) */
580
581 IMPLEMENT_ABSTRACT_CLASS(wxMacDataBrowserTableViewControl,wxMacControl)
582
583 // ============================================================================
584 // wxMacDataBrowserListViewControl
585 // ============================================================================
586 #pragma mark -
587 //
588 // column handling
589 //
590 OSStatus wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc *columnDesc, DataBrowserTableViewColumnIndex position)
591 {
592 return AddDataBrowserListViewColumn(this->m_controlRef,columnDesc,position);
593 } /* wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc*, DataBrowserTableViewColumnIndex) */
594
595 // ============================================================================
596 // wxMacDataViewDataBrowserListViewControl
597 // ============================================================================
598 #pragma mark -
599 //
600 // constructors / destructor
601 //
602 wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl(wxWindow* peer, wxPoint const& pos, wxSize const& size, long style)
603 :wxMacDataBrowserListViewControl(peer,pos,size,style)
604 {
605 } /* wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl(wxWindow* , const wxPoint&, const wxSize&, long) */
606
607 //
608 // callback functions (inherited from wxMacDataBrowserTableViewControl)
609 //
610 Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID itemOneID, DataBrowserItemID itemTwoID, DataBrowserPropertyID sortProperty)
611 {
612 DataBrowserSortOrder sortOrder;
613
614 DataBrowserTableViewColumnIndex columnIndex;
615
616 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
617
618
619 wxCHECK_MSG(dataViewCtrlPtr != NULL, false,_("Pointer to data view control not set correctly."));
620 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,false,_("Pointer to model not set correctly."));
621 if (sortProperty >= kMinPropertyID)
622 {
623 wxCHECK_MSG(this->GetColumnIndex(sortProperty,&columnIndex) == noErr,false,_("Could not determine column index."));
624 } /* if */
625 else
626 columnIndex = 0;
627 this->GetSortOrder(&sortOrder);
628 return static_cast<Boolean>(dataViewCtrlPtr->GetModel()->Compare(wxDataViewItem(reinterpret_cast<void*>(itemOneID)),wxDataViewItem(reinterpret_cast<void*>(itemTwoID)),
629 columnIndex,sortOrder != kDataBrowserOrderDecreasing) < 0);
630 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
631
632 void wxMacDataViewDataBrowserListViewControl::DataBrowserGetContextualMenuProc(MenuRef* menu, UInt32* helpType, CFStringRef* helpItemString, AEDesc* WXUNUSED(selection))
633 // In this method we do not supply a contextual menu handler at all but only send a wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU.
634 {
635 wxArrayDataBrowserItemID itemIDs;
636
637 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
638
639
640 wxCHECK_RET(dataViewCtrlPtr != NULL,_("wxWidget control pointer is not a data view pointer"));
641 // initialize parameters so that no context menu will be displayed automatically by the native data browser:
642 *menu = NULL;
643 *helpType = kCMHelpItemNoHelp;
644 *helpItemString = NULL;
645 // create information for a context menu event:
646 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU,dataViewCtrlPtr->GetId());
647
648 dataViewEvent.SetModel(dataViewCtrlPtr->GetModel());
649 // get the item information;
650 // theoretically more than one ID can be returned but the event can only handle one item, therefore all item related data is using the data of the first item in the array:
651 if (this->GetSelectedItemIDs(itemIDs) > 0)
652 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemIDs[0])));
653 // finally send the equivalent wxWidget event:
654 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
655 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetContextualMenuProc(MenuRef*, UInt32*, CFStringRef*, AEDesc*) */
656
657 OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemDataRef itemData, Boolean getValue)
658 {
659 if (getValue)
660 {
661 // variable definitions:
662 wxDataViewCtrl* dataViewCtrlPtr;
663
664 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
665 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
666 if (dataViewCtrlPtr->IsDeleting())
667 return noErr; // if a delete process is running the data of editable fields cannot be saved because the associated model variable may already have been deleted
668 else
669 {
670 // variable definitions:
671 DataBrowserTableViewColumnIndex columnIndex;
672 OSStatus errorStatus;
673 wxDataViewColumn* dataViewColumnPtr;
674
675 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
676 errorStatus = this->GetColumnIndex(propertyID,&columnIndex);
677 wxCHECK_MSG(errorStatus == noErr,errorStatus,_("Could not determine column index"));
678 dataViewColumnPtr = dataViewCtrlPtr->GetColumn(columnIndex);
679 wxCHECK_MSG((dataViewColumnPtr != NULL) && (dataViewColumnPtr->GetRenderer() != NULL),errDataBrowserNotConfigured,_("There is no column or renderer for the specified column index."));
680 switch (dataViewColumnPtr->GetRenderer()->GetPropertyType())
681 {
682 case kDataBrowserCheckboxType:
683 {
684 // variable definition:
685 ThemeButtonValue buttonValue;
686
687 errorStatus = ::GetDataBrowserItemDataButtonValue(itemData,&buttonValue);
688 if (errorStatus == noErr)
689 {
690 if (buttonValue == kThemeButtonOn)
691 {
692 // variable definition and initialization:
693 wxVariant modifiedData(true);
694
695 return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),static_cast<unsigned int>(columnIndex)) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured));
696 } /* if */
697 else if (buttonValue == kThemeButtonOff)
698 {
699 // variable definition and initialization:
700 wxVariant modifiedData(false);
701
702 return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),static_cast<unsigned int>(columnIndex)) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured));
703 } /* if */
704 else
705 return errDataBrowserInvalidPropertyData;
706 } /* if */
707 else
708 return errorStatus;
709 } /* block */
710 case kDataBrowserTextType:
711 {
712 // variable definitions:
713 CFStringRef stringReference;
714
715 errorStatus = ::GetDataBrowserItemDataText(itemData,&stringReference);
716 if (errorStatus == noErr)
717 {
718 // variable definitions and initializations:
719 #if wxCHECK_VERSION(2,9,0)
720 wxCFStringRef modifiedString(stringReference);
721 #else
722 wxMacCFStringHolder modifiedString(stringReference);
723 #endif
724 wxVariant modifiedData(modifiedString.AsString());
725
726 if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),static_cast<unsigned int>(columnIndex)))
727 return noErr;
728 else
729 return errDataBrowserNotConfigured;
730 } /* if */
731 else
732 return errorStatus;
733 } /* block */
734 default:
735 return errDataBrowserPropertyNotSupported;
736 } /* switch */
737 } /* if */
738 } /* if */
739 else
740 {
741 if (propertyID >= kMinPropertyID) // in case data columns set the data
742 {
743 // variable definitions:
744 wxVariant variant;
745 wxDataViewColumn* dataViewColumnPtr;
746 wxDataViewCtrl* dataViewCtrlPtr;
747
748 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
749 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
750 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
751 dataViewColumnPtr = dataViewCtrlPtr->GetColumnPtr(propertyID);
752 wxCHECK_MSG(dataViewColumnPtr != NULL,errDataBrowserNotConfigured,_("No column for the specified column position existing."));
753 wxCHECK_MSG(dataViewColumnPtr->GetRenderer() != NULL,errDataBrowserNotConfigured,_("No renderer specified for column."));
754 dataViewCtrlPtr->GetModel()->GetValue(variant,wxDataViewItem(reinterpret_cast<void*>(itemID)),dataViewColumnPtr->GetModelColumn());
755 if (!(variant.IsNull()))
756 {
757 dataViewColumnPtr->GetRenderer()->SetDataReference(itemData);
758 dataViewColumnPtr->GetRenderer()->SetValue(variant);
759 wxCHECK_MSG(dataViewColumnPtr->GetRenderer()->Render(),errDataBrowserNotConfigured,_("Rendering failed."));
760 } /* if */
761 return noErr;
762 } /* if */
763 else // react on special system requests
764 {
765 switch (propertyID)
766 {
767 case kDataBrowserContainerIsClosableProperty:
768 {
769 // variable definitions:
770 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
771
772 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
773 // initialize wxWidget event:
774 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING,dataViewCtrlPtr->GetId()); // variable definition
775
776 dataViewEvent.SetEventObject(dataViewCtrlPtr);
777 dataViewEvent.SetItem (wxDataViewItem(reinterpret_cast<void*>(itemID)));
778 dataViewEvent.SetModel (dataViewCtrlPtr->GetModel());
779 // finally send the equivalent wxWidget event:
780 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
781 // opening the container is allowed if not vetoed:
782 return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewEvent.IsAllowed());
783 } /* block */
784 case kDataBrowserContainerIsOpenableProperty:
785 {
786 // variable definitions:
787 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
788
789 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
790 // initialize wxWidget event:
791 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING,dataViewCtrlPtr->GetId()); // variable definition
792
793 dataViewEvent.SetEventObject(dataViewCtrlPtr);
794 dataViewEvent.SetItem (wxDataViewItem(reinterpret_cast<void*>(itemID)));
795 dataViewEvent.SetModel (dataViewCtrlPtr->GetModel());
796 // finally send the equivalent wxWidget event:
797 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
798 // opening the container is allowed if not vetoed:
799 return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewEvent.IsAllowed());
800 } /* block */
801 case kDataBrowserItemIsContainerProperty:
802 {
803 // variable definition:
804 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
805
806 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
807 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
808 return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewCtrlPtr->GetModel()->IsContainer(wxDataViewItem(reinterpret_cast<void*>(itemID))));
809 } /* block */
810 case kDataBrowserItemIsEditableProperty:
811 return ::SetDataBrowserItemDataBooleanValue(itemData,true);
812 } /* switch */
813 } /* if */
814 } /* if */
815 return errDataBrowserPropertyNotSupported;
816 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */
817
818 void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID itemID, DataBrowserItemNotification message, DataBrowserItemDataRef itemData)
819 {
820 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
821
822
823 // check if the data view control pointer still exists because this call back function can still be called when the control has already been deleted:
824 if (dataViewCtrlPtr != NULL)
825 switch (message)
826 {
827 case kDataBrowserContainerClosed:
828 dataViewCtrlPtr->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
829 {
830 // initialize wxWidget event:
831 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED,dataViewCtrlPtr->GetId()); // variable definition
832
833 dataViewEvent.SetEventObject(dataViewCtrlPtr);
834 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
835 // finally send the equivalent wxWidget event:
836 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
837 } /* block */
838 break;
839 case kDataBrowserContainerOpened:
840 dataViewCtrlPtr->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
841 {
842 // initialize wxWidget event:
843 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED,dataViewCtrlPtr->GetId()); // variable definition
844
845 dataViewEvent.SetEventObject(dataViewCtrlPtr);
846 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
847 // finally send the equivalent wxWidget event:
848 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
849 // add children to the expanded container:
850 dataViewCtrlPtr->AddChildrenLevel(wxDataViewItem(reinterpret_cast<void*>(itemID)));
851 } /* block */
852 break;
853 case kDataBrowserEditStarted:
854 dataViewCtrlPtr->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
855 {
856 // initialize wxWidget event:
857 DataBrowserPropertyID propertyID;
858 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED,dataViewCtrlPtr->GetId()); // variable definition
859
860 dataViewEvent.SetEventObject(dataViewCtrlPtr);
861 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
862 if (this->GetPropertyID(itemData,&propertyID) == noErr)
863 {
864 // variable definition and initialization:
865 DataBrowserTableViewColumnIndex columnIndex;
866
867 wxCHECK_RET(this->GetColumnIndex(propertyID,&columnIndex),_("Column index not found."));
868 dataViewEvent.SetColumn(columnIndex);
869 dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumnPtr(propertyID));
870 } /* if */
871 // finally send the equivalent wxWidget event:
872 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
873 } /* block */
874 break;
875 case kDataBrowserEditStopped:
876 {
877 // initialize wxWidget event:
878 DataBrowserPropertyID propertyID;
879 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE,dataViewCtrlPtr->GetId()); // variable definition
880
881 dataViewEvent.SetEventObject(dataViewCtrlPtr);
882 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
883 if (this->GetPropertyID(itemData,&propertyID) == noErr)
884 {
885 // variable definition and initialization:
886 DataBrowserTableViewColumnIndex columnIndex;
887
888 wxCHECK_RET(this->GetColumnIndex(propertyID,&columnIndex),_("Column index not found."));
889 dataViewEvent.SetColumn(columnIndex);
890 dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumnPtr(propertyID));
891 } /* if */
892 // finally send the equivalent wxWidget event:
893 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
894 } /* block */
895 break;
896 case kDataBrowserItemAdded:
897 dataViewCtrlPtr->FinishCustomItemEditing();
898 break;
899 case kDataBrowserItemDeselected:
900 dataViewCtrlPtr->FinishCustomItemEditing();
901 break;
902 case kDataBrowserItemDoubleClicked:
903 {
904 // initialize wxWidget event:
905 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED,dataViewCtrlPtr->GetId()); // variable definition
906
907 dataViewEvent.SetEventObject(dataViewCtrlPtr);
908 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
909 // finally send the equivalent wxWidget event:
910 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
911 } /* block */
912 break;
913 case kDataBrowserItemRemoved:
914 dataViewCtrlPtr->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
915 break;
916 case kDataBrowserItemSelected:
917 break; // not implemented by wxWidgets; see kDataBrowserSelectionSetChanged
918 case kDataBrowserSelectionSetChanged:
919 {
920 // initialize wxWidget event:
921 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED,dataViewCtrlPtr->GetId()); // variable definition
922
923 dataViewEvent.SetEventObject(dataViewCtrlPtr);
924 dataViewEvent.SetModel (dataViewCtrlPtr->GetModel());
925 // finally send the equivalent wxWidget event:
926 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
927 } /* block */
928 break;
929 case kDataBrowserTargetChanged: // no idea if this notification is ever sent
930 break;
931 case kDataBrowserUserStateChanged:
932 {
933 // finish custom item editing if necessary:
934 dataViewCtrlPtr->FinishCustomItemEditing();
935 // update column widths:
936 for (size_t i=0; i<dataViewCtrlPtr->GetColumnCount(); ++i)
937 {
938 // constant definition for abbreviational purposes:
939 wxDataViewColumn* const columnPtr = dataViewCtrlPtr->GetColumn(i);
940 // variable definition:
941 UInt16 columnWidth;
942
943 wxCHECK_RET(this->GetColumnWidth(columnPtr->GetPropertyID(),&columnWidth) == noErr,_("Column width could not be determined"));
944 columnPtr->SetWidthVariable(columnWidth);
945 } /* for */
946 // update sorting orders:
947 DataBrowserPropertyID propertyID; // variable definition
948
949 if ((this->GetSortProperty(&propertyID) == noErr) && (propertyID >= kMinPropertyID))
950 {
951 DataBrowserSortOrder sortOrder;
952 DataBrowserTableViewColumnIndex columnIndex;
953
954 if ((this->GetSortOrder(&sortOrder) == noErr) && (this->GetColumnIndex(propertyID,&columnIndex) == noErr))
955 {
956 // variable definition and initialization:
957 wxDataViewColumn* columnPtr;
958 columnPtr = dataViewCtrlPtr->GetColumn(columnIndex);
959 // check if the sort order has changed:
960 if ( columnPtr->IsSortOrderAscending() && (sortOrder == kDataBrowserOrderDecreasing) ||
961 !(columnPtr->IsSortOrderAscending()) && (sortOrder == kDataBrowserOrderIncreasing))
962 {
963 columnPtr->SetSortOrder(!(columnPtr->IsSortOrderAscending()));
964 // initialize wxWidget event:
965 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED,dataViewCtrlPtr->GetId()); // variable defintion
966
967 dataViewEvent.SetEventObject(dataViewCtrlPtr);
968 dataViewEvent.SetColumn(columnIndex);
969 dataViewEvent.SetDataViewColumn(columnPtr);
970 // finally send the equivalent wxWidget event:
971 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
972 } /* if */
973 } /* if */
974 } /* if */
975 } /* block */
976 break;
977 } /* switch */
978 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */
979
980 void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemState state, Rect const* rectangle, SInt16 bitDepth, Boolean colorDevice)
981 {
982 wxDataViewColumn* dataViewColumnPtr;
983
984 wxDataViewCtrl* dataViewCtrlPtr;
985
986 wxDataViewCustomRenderer* dataViewCustomRendererPtr;
987
988 wxVariant dataToRender;
989
990
991 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
992 wxCHECK_RET(dataViewCtrlPtr != NULL, _("Pointer to data view control not set correctly."));
993 wxCHECK_RET(dataViewCtrlPtr->GetModel() != NULL,_("Pointer to model not set correctly."));
994 dataViewColumnPtr = dataViewCtrlPtr->GetColumnPtr(propertyID);
995 wxCHECK_RET(dataViewColumnPtr != NULL,_("No column for the specified column index existing."));
996 dataViewCustomRendererPtr = dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer());
997 wxCHECK_RET(dataViewCustomRendererPtr != NULL,_("No renderer or invalid renderer type specified for custom data column."));
998 dataViewCtrlPtr->GetModel()->GetValue(dataToRender,wxDataViewItem(reinterpret_cast<void*>(itemID)),dataViewColumnPtr->GetModelColumn());
999 dataViewCustomRendererPtr->SetValue(dataToRender);
1000
1001 // try to determine the content's size (drawable part):
1002 Rect content;
1003 RgnHandle rgn(NewRgn());
1004 UInt16 headerHeight;
1005
1006 if (this->GetRegion(kControlContentMetaPart,rgn) == noErr)
1007 GetRegionBounds(rgn,&content);
1008 else
1009 this->GetRect(&content);
1010 ::DisposeRgn(rgn);
1011 // space for the header
1012 this->GetHeaderButtonHeight(&headerHeight);
1013 content.top += headerHeight;
1014 // extra space for the frame (todo: do not how to determine the space automatically from the control)
1015 content.top += 5;
1016 content.left += 5;
1017 content.right -= 3;
1018 content.bottom -= 3;
1019 // extra space for the scrollbars:
1020 content.bottom -= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
1021 content.right -= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
1022
1023 // make sure that 'Render' can draw only in the allowed area:
1024 dataViewCustomRendererPtr->GetDC()->SetClippingRegion(content.left,content.top,content.right-content.left+1,content.bottom-content.top+1);
1025 (void) (dataViewCustomRendererPtr->Render(wxRect(static_cast<int>(rectangle->left),static_cast<int>(rectangle->top),
1026 static_cast<int>(1+rectangle->right-rectangle->left),static_cast<int>(1+rectangle->bottom-rectangle->top)),
1027 dataViewCustomRendererPtr->GetDC(),((state == kDataBrowserItemIsSelected) ? wxDATAVIEW_CELL_SELECTED : 0)));
1028 dataViewCustomRendererPtr->GetDC()->DestroyClippingRegion(); // probably not necessary
1029 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */
1030
1031 Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserEditItemProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, CFStringRef theString, Rect* maxEditTextRect, Boolean* shrinkToFit)
1032 {
1033 return false;
1034 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserEditItemProc(DataBrowserItemID, DataBrowserPropertyID, CFStringRef, Rect*, Boolean*) */
1035
1036 Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserHitTestProc(DataBrowserItemID WXUNUSED(itemID), DataBrowserPropertyID WXUNUSED(property), Rect const* WXUNUSED(theRect), Rect const* WXUNUSED(mouseRect))
1037 {
1038 return true;
1039 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserHitTestProc(DataBrowserItemID, DataBrowserPropertyID, Rect const*, Rect const*) */
1040
1041 DataBrowserTrackingResult wxMacDataViewDataBrowserListViewControl::DataBrowserTrackingProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, Rect const* theRect, Point WXUNUSED(startPt), EventModifiers WXUNUSED(modifiers))
1042 {
1043 wxDataViewColumn* dataViewColumnPtr;
1044
1045 wxDataViewCtrl* dataViewCtrlPtr;
1046
1047 wxDataViewCustomRenderer* dataViewCustomRendererPtr;
1048
1049 wxDataViewItem dataViewCustomRendererItem;
1050
1051
1052 dataViewCustomRendererItem = reinterpret_cast<void*>(itemID);
1053 wxCHECK_MSG(dataViewCustomRendererItem.IsOk(),kDataBrowserNothingHit,_("Invalid data view item"));
1054 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
1055 wxCHECK_MSG(dataViewCtrlPtr != NULL,kDataBrowserNothingHit,_("Pointer to data view control not set correctly."));
1056 dataViewColumnPtr = dataViewCtrlPtr->GetColumnPtr(propertyID);
1057 wxCHECK_MSG(dataViewColumnPtr != NULL,kDataBrowserNothingHit,_("No column existing."));
1058 dataViewCustomRendererPtr = dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer());
1059 wxCHECK_MSG(dataViewCustomRendererPtr != NULL,kDataBrowserNothingHit,_("No renderer or invalid renderer type specified for custom data column."));
1060 // if the currently edited item is identical to the to be edited nothing is done (this hit should only be handled in the control itself):
1061 if (dataViewCtrlPtr->GetCustomRendererItem() == dataViewCustomRendererItem)
1062 return kDataBrowserContentHit;
1063 // an(other) item is going to be edited and therefore the current editing - if existing - has to be finished:
1064 if (dataViewCtrlPtr->GetCustomRendererPtr() != NULL)
1065 {
1066 dataViewCtrlPtr->GetCustomRendererPtr()->FinishEditing();
1067 dataViewCtrlPtr->SetCustomRendererItem(wxDataViewItem());
1068 dataViewCtrlPtr->SetCustomRendererPtr (NULL);
1069 } /* if */
1070 // check if renderer has got a valid editor control for editing; if this is the case start editing of the new item:
1071 if (dataViewCustomRendererPtr->HasEditorCtrl())
1072 {
1073 // variable definition:
1074 wxRect wxRectangle;
1075
1076 ::wxMacNativeToRect(theRect,&wxRectangle);
1077 dataViewCustomRendererPtr->StartEditing(dataViewCustomRendererItem,wxRectangle);
1078 dataViewCtrlPtr->SetCustomRendererItem(dataViewCustomRendererItem);
1079 dataViewCtrlPtr->SetCustomRendererPtr (dataViewCustomRendererPtr);
1080 } /* if */
1081 return kDataBrowserContentHit;
1082 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserTrackingProc(DataBrowserItemID, DataBrowserPropertyID, Rect const*, Point, EventModifiers) */
1083
1084 #endif // wxUSE_GENERICDATAVIEWCTRL