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