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