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