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