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