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