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