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