]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/databrow.cpp
test for valid icon
[wxWidgets.git] / src / mac / carbon / databrow.cpp
CommitLineData
c0a66d92
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/mac/carbon/databrow.cpp
3// Purpose: Classes and functions for the Carbon data browser
6e1609b1 4// Author:
c0a66d92
RR
5// Modified by:
6// Created: 2007-05-18
7// RCS-ID: $Id$
8// Copyright: (c)
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
6e1609b1
VZ
12#include "wx/wxprec.h"
13
14#if wxUSE_DATAVIEWCTRL && !defined(wxUSE_GENERICDATAVIEWCTRL)
a3fd36e7 15
594d5596 16#include <limits>
c0a66d92 17
a5fb9253
RR
18#ifndef WX_PRECOMP
19 #include "wx/app.h"
20 #include "wx/toplevel.h"
21 #include "wx/font.h"
915bd4e4 22 #include "wx/settings.h"
a5fb9253
RR
23#endif
24
25#include "wx/dataview.h"
26#include "wx/utils.h"
27
f53c8638 28#include "wx/mac/carbon/databrow.h"
594d5596 29#include "wx/mac/private.h"
a5fb9253 30#include "wx/mac/uma.h"
c0a66d92 31
c0a66d92 32// ============================================================================
194027ac 33// wxMacDataBrowserTableViewControl
c0a66d92 34// ============================================================================
c0a66d92
RR
35
36pascal 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
47pascal 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
56pascal 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
67pascal 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
76DataBrowserDrawItemUPP gDataBrowserTableViewDrawItemUPP = NULL;
77DataBrowserItemCompareUPP gDataBrowserTableViewItemCompareUPP = NULL;
78DataBrowserItemDataUPP gDataBrowserTableViewItemDataUPP = NULL;
79DataBrowserItemNotificationUPP gDataBrowserTableViewItemNotificationUPP = NULL;
80
81wxMacDataBrowserTableViewControl::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 =
c0a66d92 96 (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc);
c0a66d92
RR
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 */
594d5596 126
c0a66d92 127 OptionBits attributes; // variable definition
6e1609b1 128
c0a66d92
RR
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 */
594d5596 137
c0a66d92
RR
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//
145OSStatus wxMacDataBrowserTableViewControl::SetCallbacks(DataBrowserCallbacks const* callbacks)
146{
147 return ::SetDataBrowserCallbacks(this->m_controlRef,callbacks);
148} /* wxMacDataBrowserTableViewControl::SetCallbacks(DataBrowserCallbacks const*) */
149
150OSStatus wxMacDataBrowserTableViewControl::SetCustomCallbacks(DataBrowserCustomCallbacks const* customCallbacks)
151{
152 return ::SetDataBrowserCustomCallbacks(this->m_controlRef,customCallbacks);
153} /* xMacDataBrowserTableViewControl::SetCustomCallbacks(DataBrowserCustomCallbacks const*) */
154
155//
156// header handling
157//
158OSStatus 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
164OSStatus wxMacDataBrowserTableViewControl::SetHeaderDesc(DataBrowserPropertyID property, DataBrowserListViewHeaderDesc* desc)
165{
166 return ::SetDataBrowserListViewHeaderDesc(this->m_controlRef,property,desc);
167}
168
169//
170// layout handling
171//
172OSStatus wxMacDataBrowserTableViewControl::AutoSizeColumns()
173{
174 return AutoSizeDataBrowserListViewColumns(this->m_controlRef);
175}
176
177OSStatus wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool enableHeight, bool enableWidth)
178{
179 return ::SetDataBrowserTableViewGeometry(this->GetControlRef(),enableWidth,enableHeight);
180} /* wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool, bool) */
181
c0a66d92
RR
182OSStatus wxMacDataBrowserTableViewControl::GetAttributes(OptionBits* attributes)
183{
184 return ::DataBrowserGetAttributes(this->GetControlRef(),attributes);
185} /* wxMacDataBrowserTableViewControl::GetAttributes(OptionBits*) */
c0a66d92 186
194027ac 187OSStatus wxMacDataBrowserTableViewControl::GetColumnWidth(DataBrowserPropertyID propertyID, UInt16* width) const
c0a66d92 188{
194027ac 189 return ::GetDataBrowserTableViewNamedColumnWidth(this->m_controlRef,propertyID,width);
c0a66d92
RR
190}
191
07c51ff1
RR
192OSStatus wxMacDataBrowserTableViewControl::GetDefaultColumnWidth( UInt16 *width ) const
193{
194 return GetDataBrowserTableViewColumnWidth(this->m_controlRef, width );
195}
196
194027ac 197OSStatus wxMacDataBrowserTableViewControl::GetDefaultRowHeight(UInt16* height) const
c0a66d92 198{
194027ac 199 return ::GetDataBrowserTableViewRowHeight(this->m_controlRef,height);
c0a66d92
RR
200}
201
202OSStatus wxMacDataBrowserTableViewControl::GetHeaderButtonHeight(UInt16 *height)
203{
194027ac 204 return ::GetDataBrowserListViewHeaderBtnHeight(this->m_controlRef,height);
c0a66d92
RR
205}
206
07c51ff1 207OSStatus wxMacDataBrowserTableViewControl::GetPartBounds(DataBrowserItemID item, DataBrowserPropertyID property, DataBrowserPropertyPart part, Rect* bounds)
c0a66d92 208{
07c51ff1
RR
209 return ::GetDataBrowserItemPartBounds(this->m_controlRef,item,property,part,bounds);
210} /* wxMacDataBrowserTableViewControl::GetPartBounds(DataBrowserItemID, DataBrowswerPropertyID, DataBrowserPropertyPart, Rect*) */
c0a66d92 211
07c51ff1 212OSStatus wxMacDataBrowserTableViewControl::GetRowHeight(DataBrowserItemID item, UInt16* height) const
c0a66d92 213{
07c51ff1
RR
214 return ::GetDataBrowserTableViewItemRowHeight(this->m_controlRef,item,height);
215} /* wxMacDataBrowserTableViewControl::GetRowHeight(DataBrowserItemID, UInt16*) const */
c0a66d92
RR
216
217OSStatus wxMacDataBrowserTableViewControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const
218{
194027ac 219 return GetDataBrowserScrollPosition(this->m_controlRef, top , left );
c0a66d92
RR
220}
221
c0a66d92
RR
222OSStatus wxMacDataBrowserTableViewControl::SetAttributes(OptionBits attributes)
223{
224 return ::DataBrowserChangeAttributes(this->GetControlRef(),attributes,~attributes);
225} /* wxMacDataBrowserTableViewControl::SetAttributes(OptionBits) */
c0a66d92 226
194027ac 227OSStatus wxMacDataBrowserTableViewControl::SetColumnWidth(DataBrowserPropertyID propertyID, UInt16 width)
c0a66d92 228{
194027ac 229 return ::SetDataBrowserTableViewNamedColumnWidth(this->m_controlRef,propertyID,width);
c0a66d92
RR
230}
231
194027ac 232OSStatus wxMacDataBrowserTableViewControl::SetDefaultColumnWidth(UInt16 width)
c0a66d92 233{
194027ac 234 return ::SetDataBrowserTableViewColumnWidth(this->m_controlRef,width);
c0a66d92
RR
235}
236
194027ac 237OSStatus wxMacDataBrowserTableViewControl::SetDefaultRowHeight(UInt16 height)
c0a66d92 238{
194027ac 239 return ::SetDataBrowserTableViewRowHeight(this->m_controlRef,height);
c0a66d92
RR
240}
241
c17b2e31 242OSStatus wxMacDataBrowserTableViewControl::SetHasScrollBars(bool horiz, bool vert)
c0a66d92 243{
c17b2e31
RR
244 return ::SetDataBrowserHasScrollBars(this->m_controlRef,horiz,vert);
245} /* wxMacDataBrowserTableViewControl::SetHasScrollBars(bool, bool) */
c0a66d92
RR
246
247OSStatus wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16 height)
248{
c17b2e31
RR
249 return ::SetDataBrowserListViewHeaderBtnHeight(this->m_controlRef,height);
250} /* wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16) */
c0a66d92 251
c17b2e31 252OSStatus wxMacDataBrowserTableViewControl::SetHiliteStyle(DataBrowserTableViewHiliteStyle hiliteStyle)
c0a66d92 253{
c17b2e31
RR
254 return ::SetDataBrowserTableViewHiliteStyle(this->m_controlRef,hiliteStyle);
255} /*wxMacDataBrowserTableViewControl::SetHiliteStyle(DataBrowserTableViewHiliteStyle) */
256
257OSStatus wxMacDataBrowserTableViewControl::SetIndent(float Indent)
258{
259 return ::DataBrowserSetMetric(this->m_controlRef,kDataBrowserMetricDisclosureColumnPerDepthGap,true,Indent);
260} /* wxMacDataBrowserTableViewControl::SetIndent(float* Indent) */
c0a66d92
RR
261
262OSStatus wxMacDataBrowserTableViewControl::SetRowHeight(DataBrowserItemID item, UInt16 height)
263{
264 return ::SetDataBrowserTableViewItemRowHeight(this->m_controlRef,item,height);
265}
266
267OSStatus wxMacDataBrowserTableViewControl::SetScrollPosition(UInt32 top, UInt32 left)
268{
269 return ::SetDataBrowserScrollPosition(this->m_controlRef,top,left);
270}
271
272//
273// column handling
274//
275OSStatus wxMacDataBrowserTableViewControl::GetColumnCount(UInt32* numColumns) const
276{
194027ac 277 return ::GetDataBrowserTableViewColumnCount(this->m_controlRef,numColumns);
c0a66d92
RR
278}
279
194027ac 280OSStatus wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex* index) const
c0a66d92 281{
194027ac
RR
282 return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,index);
283} /* wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex*) const */
c0a66d92 284
194027ac 285OSStatus wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID* propertyID) const
c0a66d92 286{
194027ac
RR
287 for (*propertyID=kMinPropertyID; *propertyID<std::numeric_limits<DataBrowserPropertyID>::max(); ++(*propertyID))
288 if (this->IsUsedPropertyID(*propertyID) == errDataBrowserPropertyNotFound)
c0a66d92
RR
289 return noErr;
290 return errDataBrowserPropertyNotSupported;
291} /* wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID*) const */
292
194027ac 293OSStatus wxMacDataBrowserTableViewControl::GetPropertyFlags(DataBrowserPropertyID propertyID, DataBrowserPropertyFlags *flags) const
c0a66d92 294{
194027ac
RR
295 return ::GetDataBrowserPropertyFlags(this->m_controlRef,propertyID,flags);
296}
c0a66d92 297
07c51ff1
RR
298OSStatus wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef itemData, DataBrowserPropertyID* propertyID)
299{
300 return ::GetDataBrowserItemDataProperty(itemData,propertyID);
301} /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef, DataBrowserPropertyID*) */
302
194027ac 303OSStatus wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex index, DataBrowserTableViewColumnID* propertyID)
c0a66d92 304{
194027ac
RR
305 return ::GetDataBrowserTableViewColumnProperty(this->m_controlRef,index,propertyID);
306} /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex, DataBrowserTableViewColumnID*) */
c0a66d92
RR
307
308OSStatus 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;
6e1609b1 314
c0a66d92
RR
315 return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,&index);
316} /* wxMacDataBrowserTableViewControl::IsUsedPropertyId(DataBrowserPropertyID) const */
317
c17b2e31
RR
318OSStatus wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID propertyID)
319{
320 return ::RemoveDataBrowserTableViewColumn(this->m_controlRef,propertyID);
321} /* wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID) */
322
323OSStatus wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex index)
c0a66d92 324{
194027ac 325 DataBrowserTableViewColumnID propertyID;
c0a66d92 326
c0a66d92 327
194027ac
RR
328 this->GetPropertyID(index,&propertyID);
329 return ::RemoveDataBrowserTableViewColumn(this->m_controlRef,propertyID);
c17b2e31 330} /* wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex) */
194027ac
RR
331
332OSStatus wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex index)
c0a66d92 333{
194027ac
RR
334 return ::SetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,index);
335} /* wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex) */
c0a66d92 336
194027ac 337OSStatus wxMacDataBrowserTableViewControl::SetDisclosureColumn(DataBrowserPropertyID propertyID, Boolean expandableRows)
c0a66d92 338{
194027ac 339 return ::SetDataBrowserListViewDisclosureColumn(this->m_controlRef,propertyID,expandableRows);
c0a66d92
RR
340}
341
194027ac
RR
342OSStatus wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID propertyID, DataBrowserPropertyFlags flags)
343{
344 return ::SetDataBrowserPropertyFlags(this->m_controlRef,propertyID,flags);
345} /* wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID, DataBrowserPropertyFlags) */
346
c0a66d92
RR
347//
348// item handling
349//
350OSStatus 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
355OSStatus wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID* id) const
356{
357 ItemCount NoOfItems;
6e1609b1
VZ
358
359
c0a66d92
RR
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
382OSStatus 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
387OSStatus wxMacDataBrowserTableViewControl::GetItemID( DataBrowserTableViewRowIndex row, DataBrowserItemID * item ) const
388{
389 return GetDataBrowserTableViewItemID(this->m_controlRef,row,item);
390}
391
392OSStatus 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
397OSStatus wxMacDataBrowserTableViewControl::GetItemRow(DataBrowserItemID item, DataBrowserTableViewRowIndex* row) const
398{
399 return GetDataBrowserTableViewItemRow(this->m_controlRef,item,row);
400}
401
402OSStatus 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;
6e1609b1 408
c0a66d92
RR
409 return ::GetDataBrowserTableViewItemRow(this->m_controlRef,itemID,&index);
410} /* wxMacDataBrowserTableViewControl::IsUsedItemID(DataBrowserItemID) const */
411
412OSStatus wxMacDataBrowserTableViewControl::RemoveItems(DataBrowserItemID container, UInt32 numItems, DataBrowserItemID const* items, DataBrowserPropertyID preSortProperty)
413{
414 return ::RemoveDataBrowserItems(this->m_controlRef,container,numItems,items,preSortProperty);
415}
416
417OSStatus 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
422OSStatus 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//
431size_t wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserItemID& itemIDs) const
432{
433 DataBrowserItemID* itemIDPtr;
434 Handle handle(::NewHandle(0));
6e1609b1 435
c0a66d92
RR
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
194027ac 455OSStatus wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID* first, DataBrowserItemID* last) const
c0a66d92 456{
194027ac
RR
457 return ::GetDataBrowserSelectionAnchor(this->m_controlRef,first,last);
458} /* wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID*, DataBrowserItemID*) const */
c0a66d92
RR
459
460OSStatus wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags* flags) const
461{
462 return ::GetDataBrowserSelectionFlags(this->m_controlRef,flags);
463} /* wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags*) const */
464
465bool wxMacDataBrowserTableViewControl::IsItemSelected(DataBrowserItemID item) const
466{
467 return ::IsDataBrowserItemSelected(this->m_controlRef,item);
468} /* wxMacDataBrowserTableViewControl::IsItemSelected(DataBrowserItemID) const */
469
470OSStatus wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectionFlags flags)
471{
472 return ::SetDataBrowserSelectionFlags(this->m_controlRef,flags);
473} /* wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectionFlags) */
474
475OSStatus wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32 numItems, DataBrowserItemID const* items, DataBrowserSetOption operation)
476{
194027ac 477 return ::SetDataBrowserSelectedItems(this->m_controlRef, numItems, items, operation );
c0a66d92
RR
478} /* wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32, DataBrowserItemID const*, DataBrowserSetOption) */
479
07c51ff1 480OSStatus wxMacDataBrowserTableViewControl::GetSortOrder(DataBrowserSortOrder* order) const
c0a66d92 481{
07c51ff1 482 return ::GetDataBrowserSortOrder(this->m_controlRef,order);
c0a66d92
RR
483}
484
07c51ff1 485OSStatus wxMacDataBrowserTableViewControl::GetSortProperty(DataBrowserPropertyID* propertyID) const
c0a66d92 486{
07c51ff1 487 return ::GetDataBrowserSortProperty(this->m_controlRef,propertyID);
c0a66d92
RR
488}
489
07c51ff1 490OSStatus wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID container, Boolean sortChildren)
c0a66d92 491{
07c51ff1
RR
492 return ::SortDataBrowserContainer(this->m_controlRef,container,sortChildren);
493} /* wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID, Boolean) */
c0a66d92 494
194027ac 495OSStatus wxMacDataBrowserTableViewControl::SetSortOrder(DataBrowserSortOrder order)
c0a66d92 496{
194027ac 497 return ::SetDataBrowserSortOrder(this->m_controlRef,order);
c0a66d92
RR
498}
499
07c51ff1
RR
500OSStatus wxMacDataBrowserTableViewControl::SetSortProperty(DataBrowserPropertyID propertyID)
501{
502 return ::SetDataBrowserSortProperty(this->m_controlRef,propertyID);
503}
504
c17b2e31
RR
505//
506// container handling
507//
508OSStatus wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID containerID)
509{
510 return ::CloseDataBrowserContainer(this->m_controlRef,containerID);
511} /* wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID) */
512
513OSStatus wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID containerID)
514{
515 return ::OpenDataBrowserContainer(this->m_controlRef,containerID);
516} /* wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID) */
517
c0a66d92
RR
518IMPLEMENT_ABSTRACT_CLASS(wxMacDataBrowserTableViewControl,wxMacControl)
519
520// ============================================================================
194027ac 521// wxMacDataBrowserListViewControl
c0a66d92 522// ============================================================================
c0a66d92
RR
523#pragma mark -
524//
525// column handling
526//
527OSStatus wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc *columnDesc, DataBrowserTableViewColumnIndex position)
528{
529 return AddDataBrowserListViewColumn(this->m_controlRef,columnDesc,position);
530} /* wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc*, DataBrowserTableViewColumnIndex) */
531
532// ============================================================================
194027ac 533// wxMacDataViewDataBrowserListViewControl
c0a66d92 534// ============================================================================
c0a66d92
RR
535#pragma mark -
536//
537// constructors / destructor
538//
539wxMacDataViewDataBrowserListViewControl::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//
194027ac 545// callback functions (inherited from wxMacDataBrowserTableViewControl)
c0a66d92 546//
194027ac 547Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID itemOneID, DataBrowserItemID itemTwoID, DataBrowserPropertyID sortProperty)
c0a66d92 548{
07c51ff1
RR
549 DataBrowserSortOrder sortOrder;
550
551 DataBrowserTableViewColumnIndex columnIndex;
6e1609b1 552
194027ac 553 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
6e1609b1 554
c0a66d92 555
194027ac
RR
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)
c0a66d92 559 {
194027ac 560 wxCHECK_MSG(this->GetColumnIndex(sortProperty,&columnIndex) == noErr,false,_("Could not determine column index."));
c0a66d92 561 } /* if */
07c51ff1
RR
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);
c0a66d92
RR
567} /* wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
568
194027ac 569void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemState state, Rect const* rectangle, SInt16 bitDepth, Boolean colorDevice)
c0a66d92 570{
194027ac 571 DataBrowserTableViewColumnIndex columnIndex;
c0a66d92
RR
572
573 wxDataViewColumn* dataViewColumnPtr;
574
575 wxDataViewCtrl* dataViewCtrlPtr;
6e1609b1 576
c0a66d92
RR
577 wxDataViewCustomRenderer* dataViewCustomRendererPtr;
578
579 wxVariant dataToRender;
580
581
c0a66d92 582 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
194027ac
RR
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);
c0a66d92
RR
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."));
194027ac 590 dataViewCtrlPtr->GetModel()->GetValue(dataToRender,wxDataViewItem(reinterpret_cast<void*>(itemID)),columnIndex);
c0a66d92
RR
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;
6e1609b1 611 // extra space for the scrollbars:
c0a66d92
RR
612 content.bottom -= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
613 content.right -= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
614
6e1609b1 615 // make sure that 'Render' can draw only in the allowed area:
c0a66d92
RR
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
a5388f80 621 dataViewCustomRendererPtr->SetDC(NULL);
c0a66d92
RR
622} /* wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */
623
194027ac 624OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemDataRef itemData, Boolean getValue)
c0a66d92
RR
625{
626 if (getValue)
627 {
194027ac 628 // variable definitions:
07c51ff1 629 wxDataViewCtrl* dataViewCtrlPtr;
6e1609b1 630
c0a66d92 631 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
07c51ff1
RR
632 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
633 if (dataViewCtrlPtr->IsDeleting())
634 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
635 else
c0a66d92 636 {
07c51ff1
RR
637 // variable definitions:
638 DataBrowserTableViewColumnIndex columnIndex;
639 OSStatus errorStatus;
640 wxDataViewColumn* dataViewColumnPtr;
6e1609b1 641
07c51ff1
RR
642 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
643 errorStatus = this->GetColumnIndex(propertyID,&columnIndex);
644 wxCHECK_MSG(errorStatus == noErr,errorStatus,_("Could not determine column index"));
645 dataViewColumnPtr = dataViewCtrlPtr->GetColumn(columnIndex);
646 wxCHECK_MSG((dataViewColumnPtr != NULL) && (dataViewColumnPtr->GetRenderer() != NULL),errDataBrowserNotConfigured,_("There is no column or renderer for the specified column index."));
647 switch (dataViewColumnPtr->GetRenderer()->GetPropertyType())
648 {
649 case kDataBrowserCheckboxType:
c0a66d92 650 {
07c51ff1
RR
651 // variable definition:
652 ThemeButtonValue buttonValue;
c0a66d92 653
07c51ff1
RR
654 errorStatus = ::GetDataBrowserItemDataButtonValue(itemData,&buttonValue);
655 if (errorStatus == noErr)
c0a66d92 656 {
07c51ff1
RR
657 if (buttonValue == kThemeButtonOn)
658 {
659 // variable definition and initialization:
660 wxVariant modifiedData(true);
661
662 return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),static_cast<unsigned int>(columnIndex)) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured));
663 } /* if */
664 else if (buttonValue == kThemeButtonOff)
665 {
666 // variable definition and initialization:
667 wxVariant modifiedData(false);
668
669 return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),static_cast<unsigned int>(columnIndex)) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured));
670 } /* if */
671 else
672 return errDataBrowserInvalidPropertyData;
c0a66d92
RR
673 } /* if */
674 else
07c51ff1
RR
675 return errorStatus;
676 } /* block */
677 case kDataBrowserTextType:
c0a66d92 678 {
07c51ff1
RR
679 // variable definitions:
680 CFStringRef stringReference;
c0a66d92 681
07c51ff1
RR
682 errorStatus = ::GetDataBrowserItemDataText(itemData,&stringReference);
683 if (errorStatus == noErr)
684 {
685 // variable definitions and initializations:
686 wxMacCFStringHolder modifiedString(stringReference);
687 wxVariant modifiedData(modifiedString.AsString());
688
689 if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),static_cast<unsigned int>(columnIndex)))
690 return noErr;
691 else
692 return errDataBrowserNotConfigured;
693 } /* if */
c0a66d92 694 else
07c51ff1
RR
695 return errorStatus;
696 } /* block */
697 default:
698 return errDataBrowserPropertyNotSupported;
699 } /* switch */
700 } /* if */
c0a66d92
RR
701 } /* if */
702 else
703 {
07c51ff1 704 if (propertyID >= kMinPropertyID) // in case data columns set the data
c0a66d92
RR
705 {
706 // variable definitions:
c17b2e31
RR
707 wxVariant variant;
708 wxDataViewColumn* dataViewColumnPtr;
709 wxDataViewCtrl* dataViewCtrlPtr;
6e1609b1 710
194027ac
RR
711 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
712 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
713 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
c17b2e31 714 dataViewColumnPtr = dataViewCtrlPtr->GetColumnPtr(propertyID);
194027ac 715 wxCHECK_MSG(dataViewColumnPtr != NULL,errDataBrowserNotConfigured,_("No column for the specified column position existing."));
c0a66d92 716 wxCHECK_MSG(dataViewColumnPtr->GetRenderer() != NULL,errDataBrowserNotConfigured,_("No renderer specified for column."));
194027ac 717 dataViewCtrlPtr->GetModel()->GetValue(variant,wxDataViewItem(reinterpret_cast<void*>(itemID)),dataViewColumnPtr->GetModelColumn());
c17b2e31
RR
718 if (!(variant.IsNull()))
719 {
720 dataViewColumnPtr->GetRenderer()->SetDataReference(itemData);
721 dataViewColumnPtr->GetRenderer()->SetValue(variant);
722 wxCHECK_MSG(dataViewColumnPtr->GetRenderer()->Render(),errDataBrowserNotConfigured,_("Rendering failed."));
723 } /* if */
07c51ff1 724 return noErr;
c0a66d92
RR
725 } /* if */
726 else // react on special system requests
c17b2e31 727 {
194027ac 728 switch (propertyID)
c0a66d92 729 {
07c51ff1
RR
730 case kDataBrowserContainerIsClosableProperty:
731 {
732 // variable definitions:
733 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
6e1609b1 734
07c51ff1
RR
735 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
736 // initialize wxWidget event:
737 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING,dataViewCtrlPtr->GetId()); // variable definition
6e1609b1 738
07c51ff1
RR
739 dataViewEvent.SetEventObject(dataViewCtrlPtr);
740 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
741 // finally send the equivalent wxWidget event:
937013e0 742 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
07c51ff1
RR
743 // opening the container is allowed if not vetoed:
744 return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewEvent.IsAllowed());
745 } /* block */
07c51ff1
RR
746 case kDataBrowserContainerIsOpenableProperty:
747 {
748 // variable definitions:
749 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
6e1609b1 750
07c51ff1
RR
751 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
752 // initialize wxWidget event:
753 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING,dataViewCtrlPtr->GetId()); // variable definition
6e1609b1 754
07c51ff1
RR
755 dataViewEvent.SetEventObject(dataViewCtrlPtr);
756 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
757 // finally send the equivalent wxWidget event:
937013e0 758 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
07c51ff1
RR
759 // opening the container is allowed if not vetoed:
760 return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewEvent.IsAllowed());
761 } /* block */
c0a66d92 762 case kDataBrowserItemIsContainerProperty:
194027ac
RR
763 {
764 // variable definition:
765 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
6e1609b1 766
194027ac
RR
767 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
768 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
769 return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewCtrlPtr->GetModel()->IsContainer(wxDataViewItem(reinterpret_cast<void*>(itemID))));
770 } /* block */
c0a66d92
RR
771 case kDataBrowserItemIsEditableProperty:
772 return ::SetDataBrowserItemDataBooleanValue(itemData,true);
773 } /* switch */
c17b2e31 774 } /* if */
c0a66d92
RR
775 } /* if */
776 return errDataBrowserPropertyNotSupported;
777} /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */
778
c17b2e31 779void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID itemID, DataBrowserItemNotification message, DataBrowserItemDataRef itemData)
c0a66d92 780{
a5fb9253
RR
781 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
782
783
784 // 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:
785 if (dataViewCtrlPtr != NULL)
786 switch (message)
787 {
788 case kDataBrowserContainerClosed:
07c51ff1
RR
789 {
790 // initialize wxWidget event:
791 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED,dataViewCtrlPtr->GetId()); // variable definition
6e1609b1 792
07c51ff1
RR
793 dataViewEvent.SetEventObject(dataViewCtrlPtr);
794 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
795 // finally send the equivalent wxWidget event:
937013e0 796 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
a5fb9253
RR
797 } /* block */
798 break;
799 case kDataBrowserContainerOpened:
800 {
801 // initialize wxWidget event:
802 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED,dataViewCtrlPtr->GetId()); // variable definition
6e1609b1 803
a5fb9253
RR
804 dataViewEvent.SetEventObject(dataViewCtrlPtr);
805 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
806 // finally send the equivalent wxWidget event:
937013e0 807 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
a5fb9253
RR
808 // add children to the expanded container:
809 dataViewCtrlPtr->AddChildrenLevel(wxDataViewItem(reinterpret_cast<void*>(itemID)));
810 } /* block */
811 break;
812 case kDataBrowserEditStarted:
c17b2e31
RR
813 {
814 // initialize wxWidget event:
6e1609b1 815 DataBrowserPropertyID propertyID;
c17b2e31 816 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED,dataViewCtrlPtr->GetId()); // variable definition
6e1609b1 817
c17b2e31
RR
818 dataViewEvent.SetEventObject(dataViewCtrlPtr);
819 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
820 if (this->GetPropertyID(itemData,&propertyID) == noErr)
821 {
822 // variable definition and initialization:
823 DataBrowserTableViewColumnIndex columnIndex;
6e1609b1 824
c17b2e31
RR
825 wxCHECK_RET(this->GetColumnIndex(propertyID,&columnIndex),_("Column index not found."));
826 dataViewEvent.SetColumn(columnIndex);
6e1609b1 827 dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumnPtr(propertyID));
c17b2e31
RR
828 } /* if */
829 // finally send the equivalent wxWidget event:
937013e0 830 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
a5fb9253
RR
831 } /* block */
832 break;
833 case kDataBrowserEditStopped:
07c51ff1
RR
834 {
835 // initialize wxWidget event:
6e1609b1 836 DataBrowserPropertyID propertyID;
a5fb9253 837 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE,dataViewCtrlPtr->GetId()); // variable definition
6e1609b1 838
07c51ff1
RR
839 dataViewEvent.SetEventObject(dataViewCtrlPtr);
840 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
a5fb9253
RR
841 if (this->GetPropertyID(itemData,&propertyID) == noErr)
842 {
843 // variable definition and initialization:
844 DataBrowserTableViewColumnIndex columnIndex;
845
846 wxCHECK_RET(this->GetColumnIndex(propertyID,&columnIndex),_("Column index not found."));
847 dataViewEvent.SetColumn(columnIndex);
6e1609b1 848 dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumnPtr(propertyID));
a5fb9253 849 } /* if */
07c51ff1 850 // finally send the equivalent wxWidget event:
937013e0 851 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
a5fb9253
RR
852 } /* block */
853 break;
854 case kDataBrowserItemAdded:
855 break; // not used anymore
856 case kDataBrowserItemDeselected:
857 break; // not implemented by wxWidgets; see kDataBrowserSelectionSetChanged
858 case kDataBrowserItemDoubleClicked:
859 {
860 // initialize wxWidget event:
861 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED,dataViewCtrlPtr->GetId()); // variable definition
6d9ecc87 862
a5fb9253
RR
863 dataViewEvent.SetEventObject(dataViewCtrlPtr);
864 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
865 // finally send the equivalent wxWidget event:
937013e0 866 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
a5fb9253
RR
867 } /* block */
868 break;
869 case kDataBrowserItemRemoved:
870 break; // not used anymore
871 case kDataBrowserItemSelected:
872 break; // not implemented by wxWidgets; see kDataBrowserSelectionSetChanged
873 case kDataBrowserSelectionSetChanged:
6d9ecc87 874 {
a5fb9253
RR
875 // initialize wxWidget event:
876 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED,dataViewCtrlPtr->GetId()); // variable definition
877
878 dataViewEvent.SetEventObject(dataViewCtrlPtr);
879 dataViewEvent.SetModel (dataViewCtrlPtr->GetModel());
880 // finally send the equivalent wxWidget event:
937013e0 881 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
a5fb9253
RR
882 } /* block */
883 break;
884 case kDataBrowserUserStateChanged:
c0a66d92 885 {
a5fb9253
RR
886 // update column widths:
887 for (size_t i=0; i<dataViewCtrlPtr->GetColumnCount(); ++i)
c0a66d92 888 {
a5fb9253
RR
889 // constant definition for abbreviational purposes:
890 wxDataViewColumn* const columnPtr = dataViewCtrlPtr->GetColumn(i);
891 // variable definition:
892 UInt16 columnWidth;
6e1609b1 893
a5fb9253
RR
894 wxCHECK_RET(this->GetColumnWidth(columnPtr->GetPropertyID(),&columnWidth) == noErr,_("Column width could not be determined"));
895 columnPtr->SetWidthVariable(columnWidth);
896 } /* for */
897 // update order status:
898 DataBrowserPropertyID propertyID; // variable definition
899
900 if ((this->GetSortProperty(&propertyID) == noErr) && (propertyID >= kMinPropertyID))
901 {
902 DataBrowserSortOrder sortOrder;
903 DataBrowserTableViewColumnIndex columnIndex;
6e1609b1 904
a5fb9253 905 if ((this->GetSortOrder(&sortOrder) == noErr) && (this->GetColumnIndex(propertyID,&columnIndex) == noErr))
c0a66d92 906 {
a5fb9253
RR
907 // variable definition and initialization:
908 wxDataViewColumn* columnPtr;
909 columnPtr = dataViewCtrlPtr->GetColumn(columnIndex);
910 // check if the sort order has changed:
911 if ( columnPtr->IsSortOrderAscending() && (sortOrder == kDataBrowserOrderDecreasing) ||
912 !(columnPtr->IsSortOrderAscending()) && (sortOrder == kDataBrowserOrderIncreasing))
913 {
914 columnPtr->SetSortOrder(!(columnPtr->IsSortOrderAscending()));
915 // initialize wxWidget event:
916 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED,dataViewCtrlPtr->GetId()); // variable defintion
917
918 dataViewEvent.SetEventObject(dataViewCtrlPtr);
919 dataViewEvent.SetColumn(columnIndex);
920 dataViewEvent.SetDataViewColumn(columnPtr);
921 // finally send the equivalent wxWidget event:
937013e0 922 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
a5fb9253 923 } /* if */
c0a66d92
RR
924 } /* if */
925 } /* if */
a5fb9253
RR
926 } /* block */
927 break;
928 } /* switch */
c0a66d92
RR
929} /* wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */
930
931
6e1609b1 932#endif // wxUSE_DATAVIEWCTRL && !wxUSE_GENERICDATAVIEWCTRL