]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/databrow.cpp
non-pch build fix
[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 modelColumnIndex;
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 // variable definition and initialization:
624 wxDataViewColumn* ColumnPtr(dataViewCtrlPtr->GetColumnPtr(sortProperty));
625
626 wxCHECK_MSG(ColumnPtr != NULL,false,_("Could not determine column index."));
627 modelColumnIndex = ColumnPtr->GetModelColumn();
628 } /* if */
629 else
630 modelColumnIndex = 0;
631 this->GetSortOrder(&sortOrder);
632 return static_cast<Boolean>(dataViewCtrlPtr->GetModel()->Compare(wxDataViewItem(reinterpret_cast<void*>(itemOneID)),wxDataViewItem(reinterpret_cast<void*>(itemTwoID)),
633 modelColumnIndex,sortOrder != kDataBrowserOrderDecreasing) < 0);
634 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
635
636 void wxMacDataViewDataBrowserListViewControl::DataBrowserGetContextualMenuProc(MenuRef* menu, UInt32* helpType, CFStringRef* helpItemString, AEDesc* WXUNUSED(selection))
637 // In this method we do not supply a contextual menu handler at all but only send a wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU.
638 {
639 wxArrayDataBrowserItemID itemIDs;
640
641 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
642
643
644 wxCHECK_RET(dataViewCtrlPtr != NULL,_("wxWidget control pointer is not a data view pointer"));
645 // initialize parameters so that no context menu will be displayed automatically by the native data browser:
646 *menu = NULL;
647 *helpType = kCMHelpItemNoHelp;
648 *helpItemString = NULL;
649 // create information for a context menu event:
650 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU,dataViewCtrlPtr->GetId());
651
652 dataViewEvent.SetModel(dataViewCtrlPtr->GetModel());
653 // get the item information;
654 // 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:
655 if (this->GetSelectedItemIDs(itemIDs) > 0)
656 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemIDs[0])));
657 // finally send the equivalent wxWidget event:
658 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
659 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetContextualMenuProc(MenuRef*, UInt32*, CFStringRef*, AEDesc*) */
660
661 OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemDataRef itemData, Boolean getValue)
662 {
663 if (getValue)
664 {
665 // variable definitions:
666 wxDataViewCtrl* dataViewCtrlPtr;
667
668 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
669 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
670 if (dataViewCtrlPtr->IsDeleting())
671 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
672 else
673 {
674 // variable definitions:
675 OSStatus errorStatus;
676 wxDataViewColumn* dataViewColumnPtr;
677
678 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
679 dataViewColumnPtr = dataViewCtrlPtr->GetColumnPtr(propertyID);
680 wxCHECK_MSG((dataViewColumnPtr != NULL) && (dataViewColumnPtr->GetRenderer() != NULL),errDataBrowserNotConfigured,_("There is no column or renderer for the specified column index."));
681 switch (dataViewColumnPtr->GetRenderer()->GetPropertyType())
682 {
683 case kDataBrowserCheckboxType:
684 {
685 // variable definition:
686 ThemeButtonValue buttonValue;
687
688 errorStatus = ::GetDataBrowserItemDataButtonValue(itemData,&buttonValue);
689 if (errorStatus == noErr)
690 {
691 if (buttonValue == kThemeButtonOn)
692 {
693 // variable definition and initialization:
694 wxVariant modifiedData(true);
695
696 return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),dataViewColumnPtr->GetModelColumn()) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured));
697 } /* if */
698 else if (buttonValue == kThemeButtonOff)
699 {
700 // variable definition and initialization:
701 wxVariant modifiedData(false);
702
703 return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),dataViewColumnPtr->GetModelColumn()) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured));
704 } /* if */
705 else
706 return errDataBrowserInvalidPropertyData;
707 } /* if */
708 else
709 return errorStatus;
710 } /* block */
711 case kDataBrowserTextType:
712 {
713 // variable definitions:
714 CFStringRef stringReference;
715
716 errorStatus = ::GetDataBrowserItemDataText(itemData,&stringReference);
717 if (errorStatus == noErr)
718 {
719 // variable definitions and initializations:
720 #if wxCHECK_VERSION(2,9,0)
721 wxCFStringRef modifiedString(stringReference);
722 #else
723 wxMacCFStringHolder modifiedString(stringReference);
724 #endif
725 wxVariant modifiedData(modifiedString.AsString());
726
727 if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),dataViewColumnPtr->GetModelColumn()))
728 return noErr;
729 else
730 return errDataBrowserNotConfigured;
731 } /* if */
732 else
733 return errorStatus;
734 } /* block */
735 default:
736 return errDataBrowserPropertyNotSupported;
737 } /* switch */
738 } /* if */
739 } /* if */
740 else
741 {
742 if (propertyID >= kMinPropertyID) // in case data columns set the data
743 {
744 // variable definitions:
745 wxVariant variant;
746 wxDataViewColumn* dataViewColumnPtr;
747 wxDataViewCtrl* dataViewCtrlPtr;
748
749 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
750 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
751 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
752 dataViewColumnPtr = dataViewCtrlPtr->GetColumnPtr(propertyID);
753 wxCHECK_MSG(dataViewColumnPtr != NULL,errDataBrowserNotConfigured,_("No column for the specified column position existing."));
754 wxCHECK_MSG(dataViewColumnPtr->GetRenderer() != NULL,errDataBrowserNotConfigured,_("No renderer specified for column."));
755 dataViewCtrlPtr->GetModel()->GetValue(variant,wxDataViewItem(reinterpret_cast<void*>(itemID)),dataViewColumnPtr->GetModelColumn());
756 if (!(variant.IsNull()))
757 {
758 dataViewColumnPtr->GetRenderer()->SetDataReference(itemData);
759 dataViewColumnPtr->GetRenderer()->SetValue(variant);
760 wxCHECK_MSG(dataViewColumnPtr->GetRenderer()->Render(),errDataBrowserNotConfigured,_("Rendering failed."));
761 } /* if */
762 return noErr;
763 } /* if */
764 else // react on special system requests
765 {
766 switch (propertyID)
767 {
768 case kDataBrowserContainerIsClosableProperty:
769 {
770 // variable definitions:
771 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
772
773 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
774 // initialize wxWidget event:
775 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING,dataViewCtrlPtr->GetId()); // variable definition
776
777 dataViewEvent.SetEventObject(dataViewCtrlPtr);
778 dataViewEvent.SetItem (wxDataViewItem(reinterpret_cast<void*>(itemID)));
779 dataViewEvent.SetModel (dataViewCtrlPtr->GetModel());
780 // finally send the equivalent wxWidget event:
781 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
782 // opening the container is allowed if not vetoed:
783 return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewEvent.IsAllowed());
784 } /* block */
785 case kDataBrowserContainerIsOpenableProperty:
786 {
787 // variable definitions:
788 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
789
790 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
791 // initialize wxWidget event:
792 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING,dataViewCtrlPtr->GetId()); // variable definition
793
794 dataViewEvent.SetEventObject(dataViewCtrlPtr);
795 dataViewEvent.SetItem (wxDataViewItem(reinterpret_cast<void*>(itemID)));
796 dataViewEvent.SetModel (dataViewCtrlPtr->GetModel());
797 // finally send the equivalent wxWidget event:
798 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
799 // opening the container is allowed if not vetoed:
800 return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewEvent.IsAllowed());
801 } /* block */
802 case kDataBrowserItemIsContainerProperty:
803 {
804 // variable definition:
805 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
806
807 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
808 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
809 return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewCtrlPtr->GetModel()->IsContainer(wxDataViewItem(reinterpret_cast<void*>(itemID))));
810 } /* block */
811 case kDataBrowserItemIsEditableProperty:
812 return ::SetDataBrowserItemDataBooleanValue(itemData,true);
813 } /* switch */
814 } /* if */
815 } /* if */
816 return errDataBrowserPropertyNotSupported;
817 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */
818
819 void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID itemID, DataBrowserItemNotification message, DataBrowserItemDataRef itemData)
820 {
821 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
822
823
824 // 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:
825 if (dataViewCtrlPtr != NULL)
826 switch (message)
827 {
828 case kDataBrowserContainerClosed:
829 dataViewCtrlPtr->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
830 {
831 // initialize wxWidget event:
832 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED,dataViewCtrlPtr->GetId()); // variable definition
833
834 dataViewEvent.SetEventObject(dataViewCtrlPtr);
835 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
836 // finally send the equivalent wxWidget event:
837 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
838 } /* block */
839 break;
840 case kDataBrowserContainerOpened:
841 dataViewCtrlPtr->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
842 {
843 // initialize wxWidget event:
844 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED,dataViewCtrlPtr->GetId()); // variable definition
845
846 dataViewEvent.SetEventObject(dataViewCtrlPtr);
847 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
848 // finally send the equivalent wxWidget event:
849 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
850 // add children to the expanded container:
851 dataViewCtrlPtr->AddChildrenLevel(wxDataViewItem(reinterpret_cast<void*>(itemID)));
852 } /* block */
853 break;
854 case kDataBrowserEditStarted:
855 dataViewCtrlPtr->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
856 {
857 // initialize wxWidget event:
858 DataBrowserPropertyID propertyID;
859 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED,dataViewCtrlPtr->GetId()); // variable definition
860
861 dataViewEvent.SetEventObject(dataViewCtrlPtr);
862 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
863 if (this->GetPropertyID(itemData,&propertyID) == noErr)
864 {
865 // variable definition and initialization:
866 DataBrowserTableViewColumnIndex columnIndex;
867
868 wxCHECK_RET(this->GetColumnIndex(propertyID,&columnIndex),_("Column index not found."));
869 dataViewEvent.SetColumn(columnIndex);
870 dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumnPtr(propertyID));
871 } /* if */
872 // finally send the equivalent wxWidget event:
873 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
874 } /* block */
875 break;
876 case kDataBrowserEditStopped:
877 {
878 // initialize wxWidget event:
879 DataBrowserPropertyID propertyID;
880 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE,dataViewCtrlPtr->GetId()); // variable definition
881
882 dataViewEvent.SetEventObject(dataViewCtrlPtr);
883 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
884 if (this->GetPropertyID(itemData,&propertyID) == noErr)
885 {
886 // variable definition and initialization:
887 DataBrowserTableViewColumnIndex columnIndex;
888
889 wxCHECK_RET(this->GetColumnIndex(propertyID,&columnIndex),_("Column index not found."));
890 dataViewEvent.SetColumn(columnIndex);
891 dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumnPtr(propertyID));
892 } /* if */
893 // finally send the equivalent wxWidget event:
894 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
895 } /* block */
896 break;
897 case kDataBrowserItemAdded:
898 dataViewCtrlPtr->FinishCustomItemEditing();
899 break;
900 case kDataBrowserItemDeselected:
901 dataViewCtrlPtr->FinishCustomItemEditing();
902 break;
903 case kDataBrowserItemDoubleClicked:
904 {
905 // initialize wxWidget event:
906 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED,dataViewCtrlPtr->GetId()); // variable definition
907
908 dataViewEvent.SetEventObject(dataViewCtrlPtr);
909 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
910 // finally send the equivalent wxWidget event:
911 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
912 } /* block */
913 break;
914 case kDataBrowserItemRemoved:
915 dataViewCtrlPtr->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
916 break;
917 case kDataBrowserItemSelected:
918 break; // not implemented by wxWidgets; see kDataBrowserSelectionSetChanged
919 case kDataBrowserSelectionSetChanged:
920 {
921 // initialize wxWidget event:
922 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED,dataViewCtrlPtr->GetId()); // variable definition
923
924 dataViewEvent.SetEventObject(dataViewCtrlPtr);
925 dataViewEvent.SetModel (dataViewCtrlPtr->GetModel());
926 // finally send the equivalent wxWidget event:
927 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
928 } /* block */
929 break;
930 case kDataBrowserTargetChanged: // no idea if this notification is ever sent
931 break;
932 case kDataBrowserUserStateChanged:
933 {
934 // finish custom item editing if necessary:
935 dataViewCtrlPtr->FinishCustomItemEditing();
936 // update column widths:
937 for (size_t i=0; i<dataViewCtrlPtr->GetColumnCount(); ++i)
938 {
939 // constant definition for abbreviational purposes:
940 wxDataViewColumn* const columnPtr = dataViewCtrlPtr->GetColumn(i);
941 // variable definition:
942 UInt16 columnWidth;
943
944 wxCHECK_RET(this->GetColumnWidth(columnPtr->GetPropertyID(),&columnWidth) == noErr,_("Column width could not be determined"));
945 columnPtr->SetWidthVariable(columnWidth);
946 } /* for */
947 // update sorting orders:
948 DataBrowserPropertyID propertyID; // variable definition
949
950 if ((this->GetSortProperty(&propertyID) == noErr) && (propertyID >= kMinPropertyID))
951 {
952 DataBrowserSortOrder sortOrder;
953 DataBrowserTableViewColumnIndex columnIndex;
954
955 if ((this->GetSortOrder(&sortOrder) == noErr) && (this->GetColumnIndex(propertyID,&columnIndex) == noErr))
956 {
957 // variable definition and initialization:
958 wxDataViewColumn* columnPtr;
959 columnPtr = dataViewCtrlPtr->GetColumn(columnIndex);
960 // check if the sort order has changed:
961 if ( columnPtr->IsSortOrderAscending() && (sortOrder == kDataBrowserOrderDecreasing) ||
962 !(columnPtr->IsSortOrderAscending()) && (sortOrder == kDataBrowserOrderIncreasing))
963 {
964 columnPtr->SetSortOrder(!(columnPtr->IsSortOrderAscending()));
965 // initialize wxWidget event:
966 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED,dataViewCtrlPtr->GetId()); // variable defintion
967
968 dataViewEvent.SetEventObject(dataViewCtrlPtr);
969 dataViewEvent.SetColumn(columnIndex);
970 dataViewEvent.SetDataViewColumn(columnPtr);
971 // finally send the equivalent wxWidget event:
972 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
973 } /* if */
974 } /* if */
975 } /* if */
976 } /* block */
977 break;
978 } /* switch */
979 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */
980
981 void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemState state, Rect const* rectangle, SInt16 bitDepth, Boolean colorDevice)
982 {
983 wxDataViewColumn* dataViewColumnPtr;
984
985 wxDataViewCtrl* dataViewCtrlPtr;
986
987 wxDataViewCustomRenderer* dataViewCustomRendererPtr;
988
989 wxVariant dataToRender;
990
991
992 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
993 wxCHECK_RET(dataViewCtrlPtr != NULL, _("Pointer to data view control not set correctly."));
994 wxCHECK_RET(dataViewCtrlPtr->GetModel() != NULL,_("Pointer to model not set correctly."));
995 dataViewColumnPtr = dataViewCtrlPtr->GetColumnPtr(propertyID);
996 wxCHECK_RET(dataViewColumnPtr != NULL,_("No column for the specified column index existing."));
997 dataViewCustomRendererPtr = dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer());
998 wxCHECK_RET(dataViewCustomRendererPtr != NULL,_("No renderer or invalid renderer type specified for custom data column."));
999 dataViewCtrlPtr->GetModel()->GetValue(dataToRender,wxDataViewItem(reinterpret_cast<void*>(itemID)),dataViewColumnPtr->GetModelColumn());
1000 dataViewCustomRendererPtr->SetValue(dataToRender);
1001
1002 // try to determine the content's size (drawable part):
1003 Rect content;
1004 RgnHandle rgn(NewRgn());
1005 UInt16 headerHeight;
1006
1007 if (this->GetRegion(kControlContentMetaPart,rgn) == noErr)
1008 GetRegionBounds(rgn,&content);
1009 else
1010 this->GetRect(&content);
1011 ::DisposeRgn(rgn);
1012 // space for the header
1013 this->GetHeaderButtonHeight(&headerHeight);
1014 content.top += headerHeight;
1015 // extra space for the frame (todo: do not how to determine the space automatically from the control)
1016 content.top += 5;
1017 content.left += 5;
1018 content.right -= 3;
1019 content.bottom -= 3;
1020 // extra space for the scrollbars:
1021 content.bottom -= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
1022 content.right -= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
1023
1024 // make sure that 'Render' can draw only in the allowed area:
1025 dataViewCustomRendererPtr->GetDC()->SetClippingRegion(content.left,content.top,content.right-content.left+1,content.bottom-content.top+1);
1026 (void) (dataViewCustomRendererPtr->Render(wxRect(static_cast<int>(rectangle->left),static_cast<int>(rectangle->top),
1027 static_cast<int>(1+rectangle->right-rectangle->left),static_cast<int>(1+rectangle->bottom-rectangle->top)),
1028 dataViewCustomRendererPtr->GetDC(),((state == kDataBrowserItemIsSelected) ? wxDATAVIEW_CELL_SELECTED : 0)));
1029 dataViewCustomRendererPtr->GetDC()->DestroyClippingRegion(); // probably not necessary
1030 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */
1031
1032 Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserEditItemProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, CFStringRef theString, Rect* maxEditTextRect, Boolean* shrinkToFit)
1033 {
1034 return false;
1035 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserEditItemProc(DataBrowserItemID, DataBrowserPropertyID, CFStringRef, Rect*, Boolean*) */
1036
1037 Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserHitTestProc(DataBrowserItemID WXUNUSED(itemID), DataBrowserPropertyID WXUNUSED(property), Rect const* WXUNUSED(theRect), Rect const* WXUNUSED(mouseRect))
1038 {
1039 return true;
1040 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserHitTestProc(DataBrowserItemID, DataBrowserPropertyID, Rect const*, Rect const*) */
1041
1042 DataBrowserTrackingResult wxMacDataViewDataBrowserListViewControl::DataBrowserTrackingProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, Rect const* theRect, Point WXUNUSED(startPt), EventModifiers WXUNUSED(modifiers))
1043 {
1044 wxDataViewColumn* dataViewColumnPtr;
1045
1046 wxDataViewCtrl* dataViewCtrlPtr;
1047
1048 wxDataViewCustomRenderer* dataViewCustomRendererPtr;
1049
1050 wxDataViewItem dataViewCustomRendererItem;
1051
1052
1053 dataViewCustomRendererItem = reinterpret_cast<void*>(itemID);
1054 wxCHECK_MSG(dataViewCustomRendererItem.IsOk(),kDataBrowserNothingHit,_("Invalid data view item"));
1055 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
1056 wxCHECK_MSG(dataViewCtrlPtr != NULL,kDataBrowserNothingHit,_("Pointer to data view control not set correctly."));
1057 dataViewColumnPtr = dataViewCtrlPtr->GetColumnPtr(propertyID);
1058 wxCHECK_MSG(dataViewColumnPtr != NULL,kDataBrowserNothingHit,_("No column existing."));
1059 dataViewCustomRendererPtr = dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer());
1060 wxCHECK_MSG(dataViewCustomRendererPtr != NULL,kDataBrowserNothingHit,_("No renderer or invalid renderer type specified for custom data column."));
1061 // 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):
1062 if (dataViewCtrlPtr->GetCustomRendererItem() == dataViewCustomRendererItem)
1063 return kDataBrowserContentHit;
1064 // an(other) item is going to be edited and therefore the current editing - if existing - has to be finished:
1065 if (dataViewCtrlPtr->GetCustomRendererPtr() != NULL)
1066 {
1067 dataViewCtrlPtr->GetCustomRendererPtr()->FinishEditing();
1068 dataViewCtrlPtr->SetCustomRendererItem(wxDataViewItem());
1069 dataViewCtrlPtr->SetCustomRendererPtr (NULL);
1070 } /* if */
1071 // check if renderer has got a valid editor control for editing; if this is the case start editing of the new item:
1072 if (dataViewCustomRendererPtr->HasEditorCtrl())
1073 {
1074 // variable definition:
1075 wxRect wxRectangle;
1076
1077 ::wxMacNativeToRect(theRect,&wxRectangle);
1078 dataViewCustomRendererPtr->StartEditing(dataViewCustomRendererItem,wxRectangle);
1079 dataViewCtrlPtr->SetCustomRendererItem(dataViewCustomRendererItem);
1080 dataViewCtrlPtr->SetCustomRendererPtr (dataViewCustomRendererPtr);
1081 } /* if */
1082 return kDataBrowserContentHit;
1083 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserTrackingProc(DataBrowserItemID, DataBrowserPropertyID, Rect const*, Point, EventModifiers) */
1084
1085 #endif // wxUSE_GENERICDATAVIEWCTRL