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