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