]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/dataview.cpp
Document and test behaviour of wxRegion methods when it is invalid.
[wxWidgets.git] / src / osx / carbon / dataview.cpp
CommitLineData
489468fe 1/////////////////////////////////////////////////////////////////////////////
e86edab0
RR
2// Name: src/osx/carbon/dataview.cpp
3// Purpose: wxDataViewCtrl native carbon implementation
5829b303 4// Author:
e86edab0
RR
5// Id: $Id: dataview.cpp 58317 2009-01-23
6// Copyright: (c) 2009
489468fe
SC
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
e86edab0 13#if (wxUSE_DATAVIEWCTRL == 1) && !defined(wxUSE_GENERICDATAVIEWCTRL)
489468fe
SC
14
15#ifndef WX_PRECOMP
e86edab0
RR
16 #include "wx/app.h"
17 #include "wx/toplevel.h"
18 #include "wx/font.h"
489468fe 19 #include "wx/settings.h"
e86edab0 20 #include "wx/utils.h"
489468fe
SC
21#endif
22
e86edab0
RR
23#include "wx/osx/carbon/dataview.h"
24#include "wx/osx/private.h"
25#include "wx/osx/uma.h"
489468fe
SC
26#include "wx/renderer.h"
27
e86edab0 28#include <limits>
489468fe 29
e86edab0
RR
30// ============================================================================
31// Variables used locally in dataview.cpp
32// ============================================================================
33static DataBrowserGetContextualMenuUPP gDataBrowserTableViewGetContextualMenuUPP = NULL;
34static DataBrowserItemCompareUPP gDataBrowserTableViewItemCompareUPP = NULL;
35static DataBrowserItemDataUPP gDataBrowserTableViewItemDataUPP = NULL;
36static DataBrowserItemNotificationUPP gDataBrowserTableViewItemNotificationUPP = NULL;
37
38static DataBrowserAcceptDragUPP gDataBrowserTableViewAcceptDragUPP = NULL;
39static DataBrowserAddDragItemUPP gDataBrowserTableViewAddDragItemUPP = NULL;
40static DataBrowserReceiveDragUPP gDataBrowserTableViewReceiveDragUPP = NULL;
41
42static DataBrowserDrawItemUPP gDataBrowserTableViewDrawItemUPP = NULL;
43static DataBrowserEditItemUPP gDataBrowserTableViewEditItemUPP = NULL;
44static DataBrowserHitTestUPP gDataBrowserTableViewHitTestUPP = NULL;
45static DataBrowserTrackingUPP gDataBrowserTableViewTrackingUPP = NULL;
46
47// ============================================================================
48// Functions used locally in dataview.cpp
49// ============================================================================
50static DataBrowserItemID* CreateDataBrowserItemIDArray(size_t& noOfEntries, wxDataViewItemArray const& items) // returns a newly allocated pointer to valid data browser item IDs
489468fe 51{
e86edab0 52 size_t const noOfItems = items.GetCount();
489468fe 53
e86edab0
RR
54 DataBrowserItemID* itemIDs(new DataBrowserItemID[noOfItems]);
55
56
57 // convert all valid data view items to data browser items
58 noOfEntries = 0;
59 for (size_t i=0; i<noOfItems; ++i)
60 if (items[i].IsOk())
61 {
62 itemIDs[noOfEntries] = reinterpret_cast<DataBrowserItemID>(items[i].GetID());
63 ++noOfEntries;
64 }
65 // done:
66 return itemIDs;
67}
489468fe 68
8ba01d35
RR
69static const EventTypeSpec eventList[] =
70{
71 { kEventClassControl, kEventControlHit },
72 { kEventClassControl, kEventControlDraw }
73};
74
e86edab0 75static pascal OSStatus DataBrowserCtrlEventHandler(EventHandlerCallRef handler, EventRef EventReference, void* Data)
489468fe 76{
5829b303 77 wxDataViewCtrl* DataViewCtrlPtr((wxDataViewCtrl*) Data); // the 'Data' variable always contains a pointer to the data view control that installed the handler
489468fe
SC
78
79 wxMacCarbonEvent CarbonEvent(EventReference) ;
80
81
82 switch (GetEventKind(EventReference))
83 {
84 case kEventControlDraw:
85 {
86 OSStatus status;
87
88 DataViewCtrlPtr->MacSetDrawingContext(CarbonEvent.GetParameter<CGContextRef>(kEventParamCGContextRef,typeCGContextRef));
89 status = ::CallNextEventHandler(handler,EventReference);
90 DataViewCtrlPtr->MacSetDrawingContext(NULL);
91 return status;
5829b303 92 }
489468fe
SC
93 case kEventControlHit :
94 if (CarbonEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) == kControlButtonPart) // we only care about the header
95 {
96 ControlRef controlReference;
97 DataBrowserPropertyID columnPropertyID;
8ba01d35 98 DataBrowserSortOrder order;
489468fe 99 unsigned long columnIndex;
8ba01d35 100 wxDataViewColumn* column;
489468fe
SC
101 OSStatus status;
102 wxDataViewEvent DataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK,DataViewCtrlPtr->GetId());
103
104 CarbonEvent.GetParameter(kEventParamDirectObject,&controlReference);
105 // determine the column that triggered the event (this is the column that is responsible for sorting the data view):
106 status = ::GetDataBrowserSortProperty(controlReference,&columnPropertyID);
107 wxCHECK(status == noErr,status);
108 status = ::GetDataBrowserTableViewColumnPosition(controlReference,columnPropertyID,&columnIndex);
109 if (status == errDataBrowserPropertyNotFound) // user clicked into part of the header that does not have a property
110 return ::CallNextEventHandler(handler,EventReference);
111 wxCHECK(status == noErr,status);
8ba01d35
RR
112 column = DataViewCtrlPtr->GetColumn(columnIndex);
113 // set the column sort order:
114 status = ::GetDataBrowserSortOrder(controlReference,&order);
115 wxCHECK(status == noErr,status);
116 column->SetSortOrderVariable(order == kDataBrowserOrderIncreasing);
489468fe
SC
117 // initialize wxWidget event handler:
118 DataViewEvent.SetEventObject(DataViewCtrlPtr);
119 DataViewEvent.SetColumn(columnIndex);
8ba01d35 120 DataViewEvent.SetDataViewColumn(column);
489468fe 121 // finally sent the equivalent wxWidget event:
489468fe 122 DataViewCtrlPtr->HandleWindowEvent(DataViewEvent);
489468fe 123 return ::CallNextEventHandler(handler,EventReference);
5829b303 124 }
489468fe
SC
125 else
126 return eventNotHandledErr;
5829b303 127 }
489468fe 128 return eventNotHandledErr;
5829b303 129}
489468fe 130
e86edab0 131static bool InitializeColumnDescription(DataBrowserListViewColumnDesc& columnDescription, wxDataViewColumn const* columnPtr, wxCFStringRef const& title)
489468fe
SC
132{
133 // set properties for the column:
e86edab0
RR
134 columnDescription.propertyDesc.propertyID = columnPtr->GetNativeData()->GetPropertyID();
135 columnDescription.propertyDesc.propertyType = columnPtr->GetRenderer()->GetNativeData()->GetPropertyType();
489468fe
SC
136 columnDescription.propertyDesc.propertyFlags = kDataBrowserListViewSelectionColumn; // make the column selectable
137 if (columnPtr->IsReorderable())
138 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewMovableColumn;
139 if (columnPtr->IsResizeable())
140 {
141 columnDescription.headerBtnDesc.minimumWidth = 0;
142 columnDescription.headerBtnDesc.maximumWidth = 30000; // 32767 is the theoretical maximum though but 30000 looks nicer
5829b303 143 }
489468fe
SC
144 else
145 {
146 columnDescription.headerBtnDesc.minimumWidth = columnPtr->GetWidth();
147 columnDescription.headerBtnDesc.maximumWidth = columnPtr->GetWidth();
5829b303 148 }
489468fe
SC
149 if (columnPtr->IsSortable())
150 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewSortableColumn;
35d85392
RR
151 if ((columnPtr->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE) ||
152 (columnPtr->GetRenderer()->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE))
489468fe
SC
153 columnDescription.propertyDesc.propertyFlags |= kDataBrowserPropertyIsEditable;
154 if ((columnDescription.propertyDesc.propertyType == kDataBrowserCustomType) ||
155 (columnDescription.propertyDesc.propertyType == kDataBrowserDateTimeType) ||
156 (columnDescription.propertyDesc.propertyType == kDataBrowserIconAndTextType) ||
157 (columnDescription.propertyDesc.propertyType == kDataBrowserTextType))
158 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn; // enables generally the possibility to have user input for the mentioned types
159#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
160 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton;
161#endif
162 // set header's properties:
e86edab0
RR
163 columnDescription.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
164 columnDescription.headerBtnDesc.titleOffset = 0;
165 columnDescription.headerBtnDesc.titleString = ::CFStringCreateCopy(kCFAllocatorDefault,title);
489468fe
SC
166 columnDescription.headerBtnDesc.initialOrder = kDataBrowserOrderIncreasing; // choose one of the orders as "undefined" is not supported anyway (s. ControlDefs.h in the HIToolbox framework)
167 columnDescription.headerBtnDesc.btnFontStyle.flags = kControlUseFontMask | kControlUseJustMask;
168 switch (columnPtr->GetAlignment())
169 {
170 case wxALIGN_CENTER:
171 case wxALIGN_CENTER_HORIZONTAL:
172 columnDescription.headerBtnDesc.btnFontStyle.just = teCenter;
173 break;
174 case wxALIGN_LEFT:
175 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushLeft;
176 break;
177 case wxALIGN_RIGHT:
178 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushRight;
179 break;
180 default:
181 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushDefault;
5829b303 182 }
489468fe
SC
183 columnDescription.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
184 columnDescription.headerBtnDesc.btnFontStyle.style = normal;
185 if (columnPtr->GetBitmap().IsOk())
186 {
187 columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentIconRef;
489468fe 188 columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = columnPtr->GetBitmap().GetIconRef();
489468fe
SC
189 }
190 else
191 {
192 // not text only as we otherwise could not add a bitmap later
193 // columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
194 columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentIconRef;
195 columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = NULL;
196 }
5829b303 197
489468fe
SC
198 // done:
199 return true;
5829b303 200}
489468fe 201
e86edab0
RR
202// ============================================================================
203// Type definitions of locally used function pointers
204// ============================================================================
205DEFINE_ONE_SHOT_HANDLER_GETTER(DataBrowserCtrlEventHandler)
489468fe 206
e86edab0
RR
207// ============================================================================
208// Helper functions for dataview implementation on OSX
209// ============================================================================
210wxWidgetImplType* CreateDataView(wxWindowMac* wxpeer, wxWindowMac* WXUNUSED(parent), wxWindowID WXUNUSED(id), wxPoint const& pos, wxSize const& size,
211 long style, long WXUNUSED(extraStyle))
489468fe 212{
e86edab0
RR
213 return new wxMacDataViewDataBrowserListViewControl(wxpeer,pos,size,style);
214}
5829b303 215
e86edab0
RR
216// ============================================================================
217// wxMacDataBrowserTableViewControl
218// ============================================================================
219pascal Boolean wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlRef browser, DataBrowserItemID itemOneID, DataBrowserItemID itemTwoID, DataBrowserPropertyID sortProperty)
220{
221 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
5829b303 222
5829b303 223
e86edab0
RR
224 if (ControlPtr != NULL)
225 return ControlPtr->DataBrowserCompareProc(itemOneID,itemTwoID,sortProperty);
226 else
8f2a8de6 227 return FALSE;
de40d736 228}
5829b303 229
e86edab0
RR
230pascal void wxMacDataBrowserTableViewControl::DataBrowserGetContextualMenuProc(ControlRef browser, MenuRef* menu, UInt32* helpType, CFStringRef* helpItemString, AEDesc* selection)
231{
232 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
5829b303 233
489468fe 234
e86edab0
RR
235 if (ControlPtr != NULL)
236 ControlPtr->DataBrowserGetContextualMenuProc(menu,helpType,helpItemString,selection);
de40d736 237}
489468fe 238
e86edab0
RR
239pascal OSStatus wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemDataRef itemData, Boolean getValue)
240{
241 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
5829b303 242
5829b303 243
e86edab0
RR
244 if (ControlPtr != NULL)
245 return ControlPtr->DataBrowserGetSetItemDataProc(itemID,propertyID,itemData,getValue);
246 else
247 return errDataBrowserPropertyNotSupported;
de40d736 248}
489468fe 249
e86edab0
RR
250pascal void wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message, DataBrowserItemDataRef itemData)
251{
252 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
489468fe 253
5829b303 254
e86edab0
RR
255 if (ControlPtr != NULL)
256 ControlPtr->DataBrowserItemNotificationProc(itemID,message,itemData);
de40d736 257}
5829b303 258
e86edab0
RR
259pascal void wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemState state, Rect const* rectangle, SInt16 bitDepth, Boolean colorDevice)
260{
261 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
5829b303 262
5829b303 263
e86edab0
RR
264 if (ControlPtr != NULL)
265 ControlPtr->DataBrowserDrawItemProc(itemID,propertyID,state,rectangle,bitDepth,colorDevice);
de40d736 266}
5829b303 267
e86edab0
RR
268pascal Boolean wxMacDataBrowserTableViewControl::DataBrowserEditItemProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID propertyID, CFStringRef theString, Rect* maxEditTextRect, Boolean* shrinkToFit)
269{
270 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
5829b303 271
489468fe 272
e86edab0 273 return ((ControlPtr != NULL) && ControlPtr->DataBrowserEditItemProc(itemID,propertyID,theString,maxEditTextRect,shrinkToFit));
de40d736 274}
5829b303 275
e86edab0
RR
276pascal Boolean wxMacDataBrowserTableViewControl::DataBrowserHitTestProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID propertyID, Rect const* theRect, Rect const* mouseRect)
277{
278 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
5829b303 279
5829b303 280
e86edab0 281 return ((ControlPtr != NULL) && ControlPtr->DataBrowserHitTestProc(itemID,propertyID,theRect,mouseRect));
de40d736 282}
489468fe 283
e86edab0
RR
284pascal DataBrowserTrackingResult wxMacDataBrowserTableViewControl::DataBrowserTrackingProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID propertyID, Rect const* theRect, Point startPt, EventModifiers modifiers)
285{
286 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
489468fe 287
489468fe 288
e86edab0
RR
289 if (ControlPtr != NULL)
290 return ControlPtr->DataBrowserTrackingProc(itemID,propertyID,theRect,startPt,modifiers);
291 else
8f2a8de6 292 return kDataBrowserNothingHit;
de40d736 293}
5829b303 294
e86edab0
RR
295pascal Boolean wxMacDataBrowserTableViewControl::DataBrowserAcceptDragProc(ControlRef browser, DragReference dragRef, DataBrowserItemID itemID)
296{
297 wxMacDataBrowserTableViewControl* controlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
8f2a8de6
VZ
298
299
e86edab0 300 return ((controlPtr != NULL) && controlPtr->DataBrowserAcceptDragProc(dragRef,itemID));
de40d736 301}
5829b303 302
e86edab0
RR
303pascal Boolean wxMacDataBrowserTableViewControl::DataBrowserAddDragItemProc(ControlRef browser, DragReference dragRef, DataBrowserItemID itemID, ItemReference* itemRef)
304{
305 wxMacDataBrowserTableViewControl* controlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
8f2a8de6
VZ
306
307
e86edab0 308 return ((controlPtr != NULL) && controlPtr->DataBrowserAddDragItemProc(dragRef,itemID,itemRef));
de40d736 309}
489468fe 310
e86edab0
RR
311pascal Boolean wxMacDataBrowserTableViewControl::DataBrowserReceiveDragProc(ControlRef browser, DragReference dragRef, DataBrowserItemID itemID)
312{
313 wxMacDataBrowserTableViewControl* controlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
8f2a8de6
VZ
314
315
e86edab0 316 return ((controlPtr != NULL) && controlPtr->DataBrowserReceiveDragProc(dragRef,itemID));
de40d736 317}
5829b303 318
e86edab0
RR
319wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow* peer, wxPoint const& pos, wxSize const& size, long style)
320 :wxMacControl(peer)
321{
322 Rect bounds = wxMacGetBoundsForControl(peer,pos,size);
de40d736 323 OSStatus err = ::CreateDataBrowserControl(MAC_WXHWND(peer->MacGetTopLevelWindowRef()),&bounds,kDataBrowserListView,&(m_controlRef));
489468fe 324
489468fe 325
e86edab0
RR
326 SetReferenceInNativeControl();
327 verify_noerr(err);
8f2a8de6 328
de40d736 329 ::InstallControlEventHandler(m_controlRef, GetDataBrowserCtrlEventHandlerUPP(), GetEventTypeCount(eventList), eventList, peer, (EventHandlerRef *)&m_macDataViewCtrlEventHandler);
8f2a8de6 330
e86edab0
RR
331 // setup standard callbacks:
332 if (gDataBrowserTableViewGetContextualMenuUPP == NULL) gDataBrowserTableViewGetContextualMenuUPP = NewDataBrowserGetContextualMenuUPP(wxMacDataBrowserTableViewControl::DataBrowserGetContextualMenuProc);
333 if (gDataBrowserTableViewItemCompareUPP == NULL) gDataBrowserTableViewItemCompareUPP = NewDataBrowserItemCompareUPP (wxMacDataBrowserTableViewControl::DataBrowserCompareProc);
334 if (gDataBrowserTableViewItemDataUPP == NULL) gDataBrowserTableViewItemDataUPP = NewDataBrowserItemDataUPP (wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc);
335 if (gDataBrowserTableViewItemNotificationUPP == NULL)
489468fe 336 {
e86edab0
RR
337 gDataBrowserTableViewItemNotificationUPP =
338#if TARGET_API_MAC_OSX
339 (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc);
340#else
341 NewDataBrowserItemNotificationUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc);
342#endif
5829b303 343 }
e86edab0
RR
344 // setup drag and drop callbacks:
345 if (gDataBrowserTableViewAcceptDragUPP == NULL) gDataBrowserTableViewAcceptDragUPP = NewDataBrowserAcceptDragUPP (wxMacDataBrowserTableViewControl::DataBrowserAcceptDragProc);
346 if (gDataBrowserTableViewAddDragItemUPP == NULL) gDataBrowserTableViewAddDragItemUPP = NewDataBrowserAddDragItemUPP(wxMacDataBrowserTableViewControl::DataBrowserAddDragItemProc);
347 if (gDataBrowserTableViewReceiveDragUPP == NULL) gDataBrowserTableViewReceiveDragUPP = NewDataBrowserReceiveDragUPP(wxMacDataBrowserTableViewControl::DataBrowserReceiveDragProc);
348
349 DataBrowserCallbacks callbacks; // variable definition
350
351 InitializeDataBrowserCallbacks(&callbacks,kDataBrowserLatestCallbacks);
352 callbacks.u.v1.getContextualMenuCallback = gDataBrowserTableViewGetContextualMenuUPP;
353 callbacks.u.v1.itemDataCallback = gDataBrowserTableViewItemDataUPP;
354 callbacks.u.v1.itemCompareCallback = gDataBrowserTableViewItemCompareUPP;
355 callbacks.u.v1.itemNotificationCallback = gDataBrowserTableViewItemNotificationUPP;
03647350
VZ
356 callbacks.u.v1.acceptDragCallback = gDataBrowserTableViewAcceptDragUPP;
357 callbacks.u.v1.addDragItemCallback = gDataBrowserTableViewAddDragItemUPP;
358 callbacks.u.v1.receiveDragCallback = gDataBrowserTableViewReceiveDragUPP;
de40d736 359 SetCallbacks(&callbacks);
e86edab0
RR
360
361 // setup callbacks for customized items:
362 if (gDataBrowserTableViewDrawItemUPP == NULL) gDataBrowserTableViewDrawItemUPP = NewDataBrowserDrawItemUPP(wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc);
363 if (gDataBrowserTableViewEditItemUPP == NULL) gDataBrowserTableViewEditItemUPP = NewDataBrowserEditItemUPP(wxMacDataBrowserTableViewControl::DataBrowserEditItemProc);
364 if (gDataBrowserTableViewHitTestUPP == NULL) gDataBrowserTableViewHitTestUPP = NewDataBrowserHitTestUPP (wxMacDataBrowserTableViewControl::DataBrowserHitTestProc);
365 if (gDataBrowserTableViewTrackingUPP == NULL) gDataBrowserTableViewTrackingUPP = NewDataBrowserTrackingUPP(wxMacDataBrowserTableViewControl::DataBrowserTrackingProc);
366
367 DataBrowserCustomCallbacks customCallbacks; // variable definition
368
369 InitializeDataBrowserCustomCallbacks(&customCallbacks,kDataBrowserLatestCallbacks);
370 customCallbacks.u.v1.drawItemCallback = gDataBrowserTableViewDrawItemUPP;
371 customCallbacks.u.v1.editTextCallback = gDataBrowserTableViewEditItemUPP;
372 customCallbacks.u.v1.hitTestCallback = gDataBrowserTableViewHitTestUPP;
373 customCallbacks.u.v1.trackingCallback = gDataBrowserTableViewTrackingUPP;
de40d736 374 SetCustomCallbacks(&customCallbacks);
e86edab0
RR
375
376 // style setting:
de40d736 377 EnableCellSizeModification( ((style & wxDV_VARIABLE_LINE_HEIGHT) != 0), true );
e86edab0
RR
378
379 DataBrowserSelectionFlags flags; // variable definition
380
de40d736 381 if (GetSelectionFlags(&flags) == noErr) // get default settings
489468fe 382 {
e86edab0
RR
383 if ((style & wxDV_MULTIPLE) != 0)
384 flags &= ~kDataBrowserSelectOnlyOne;
385 else
386 flags |= kDataBrowserSelectOnlyOne;
de40d736 387 (void) SetSelectionFlags(flags);
5829b303 388 }
489468fe 389
e86edab0 390 OptionBits attributes; // variable definition
8f2a8de6 391
de40d736 392 if (GetAttributes(&attributes) == noErr) // get default settings
489468fe 393 {
e86edab0
RR
394 if ((style & wxDV_VERT_RULES) != 0)
395 attributes |= kDataBrowserAttributeListViewDrawColumnDividers;
489468fe 396 else
e86edab0
RR
397 attributes &= ~kDataBrowserAttributeListViewDrawColumnDividers;
398 if ((style & wxDV_ROW_LINES) != 0)
399 attributes |= kDataBrowserAttributeListViewAlternatingRowColors;
400 else
401 attributes &= ~kDataBrowserAttributeListViewAlternatingRowColors;
de40d736 402 (void) SetAttributes(attributes);
5829b303 403 }
489468fe 404
e86edab0 405 if ((style & wxDV_NO_HEADER) != 0)
de40d736
VZ
406 SetHeaderButtonHeight(0);
407}
489468fe 408
de40d736 409wxMacDataBrowserTableViewControl::~wxMacDataBrowserTableViewControl()
8ba01d35
RR
410{
411 ::RemoveEventHandler((EventHandlerRef) m_macDataViewCtrlEventHandler);
de40d736 412}
8ba01d35 413
e86edab0
RR
414//
415// callback handling
416//
417OSStatus wxMacDataBrowserTableViewControl::SetCallbacks(DataBrowserCallbacks const* callbacks)
418{
de40d736
VZ
419 return ::SetDataBrowserCallbacks(m_controlRef,callbacks);
420}
489468fe 421
e86edab0
RR
422OSStatus wxMacDataBrowserTableViewControl::SetCustomCallbacks(DataBrowserCustomCallbacks const* customCallbacks)
423{
de40d736
VZ
424 return ::SetDataBrowserCustomCallbacks(m_controlRef,customCallbacks);
425}
489468fe 426
e86edab0
RR
427//
428// DnD handling
429//
430OSStatus wxMacDataBrowserTableViewControl::EnableAutomaticDragTracking(bool enable)
489468fe 431{
de40d736 432 return ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(m_controlRef),enable);
5829b303 433}
489468fe 434
e86edab0
RR
435//
436// header handling
437//
438OSStatus wxMacDataBrowserTableViewControl::GetHeaderDesc(DataBrowserPropertyID propertyID, DataBrowserListViewHeaderDesc* desc) const
489468fe 439{
e86edab0 440 desc->version = kDataBrowserListViewLatestHeaderDesc; // if this statement is missing the next call will fail (NOT DOCUMENTED!!)
de40d736 441 return ::GetDataBrowserListViewHeaderDesc(m_controlRef,propertyID,desc);
e86edab0 442}
489468fe 443
e86edab0
RR
444OSStatus wxMacDataBrowserTableViewControl::SetHeaderDesc(DataBrowserPropertyID propertyID, DataBrowserListViewHeaderDesc* desc)
445{
de40d736 446 return ::SetDataBrowserListViewHeaderDesc(m_controlRef,propertyID,desc);
e86edab0 447}
489468fe 448
e86edab0
RR
449//
450// layout handling
451//
452OSStatus wxMacDataBrowserTableViewControl::AutoSizeColumns()
453{
de40d736 454 return AutoSizeDataBrowserListViewColumns(m_controlRef);
e86edab0 455}
5829b303 456
e86edab0
RR
457OSStatus wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool enableHeight, bool enableWidth)
458{
de40d736
VZ
459 return ::SetDataBrowserTableViewGeometry(GetControlRef(),enableWidth,enableHeight);
460}
5829b303 461
e86edab0
RR
462OSStatus wxMacDataBrowserTableViewControl::GetAttributes(OptionBits* attributes)
463{
de40d736
VZ
464 return ::DataBrowserGetAttributes(GetControlRef(),attributes);
465}
5829b303 466
e86edab0
RR
467OSStatus wxMacDataBrowserTableViewControl::GetColumnWidth(DataBrowserPropertyID propertyID, UInt16* width) const
468{
de40d736 469 return ::GetDataBrowserTableViewNamedColumnWidth(m_controlRef,propertyID,width);
5829b303 470}
489468fe 471
e86edab0 472OSStatus wxMacDataBrowserTableViewControl::GetDefaultColumnWidth( UInt16 *width ) const
489468fe 473{
de40d736 474 return GetDataBrowserTableViewColumnWidth(m_controlRef, width );
5829b303 475}
489468fe 476
e86edab0 477OSStatus wxMacDataBrowserTableViewControl::GetDefaultRowHeight(UInt16* height) const
489468fe 478{
de40d736 479 return ::GetDataBrowserTableViewRowHeight(m_controlRef,height);
5829b303 480}
489468fe 481
e86edab0 482OSStatus wxMacDataBrowserTableViewControl::GetHeaderButtonHeight(UInt16 *height)
489468fe 483{
de40d736 484 return ::GetDataBrowserListViewHeaderBtnHeight(m_controlRef,height);
489468fe
SC
485}
486
e86edab0 487OSStatus wxMacDataBrowserTableViewControl::GetPartBounds(DataBrowserItemID item, DataBrowserPropertyID propertyID, DataBrowserPropertyPart part, Rect* bounds)
489468fe 488{
de40d736
VZ
489 return ::GetDataBrowserItemPartBounds(m_controlRef,item,propertyID,part,bounds);
490}
489468fe 491
e86edab0 492OSStatus wxMacDataBrowserTableViewControl::GetRowHeight(DataBrowserItemID item, UInt16* height) const
489468fe 493{
de40d736
VZ
494 return ::GetDataBrowserTableViewItemRowHeight(m_controlRef,item,height);
495}
489468fe 496
e86edab0 497OSStatus wxMacDataBrowserTableViewControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const
489468fe 498{
de40d736 499 return GetDataBrowserScrollPosition(m_controlRef, top , left );
5829b303 500}
489468fe 501
e86edab0
RR
502OSStatus wxMacDataBrowserTableViewControl::SetAttributes(OptionBits attributes)
503{
de40d736
VZ
504 return ::DataBrowserChangeAttributes(GetControlRef(),attributes,~attributes);
505}
e86edab0
RR
506
507OSStatus wxMacDataBrowserTableViewControl::SetColumnWidth(DataBrowserPropertyID propertyID, UInt16 width)
489468fe 508{
de40d736 509 return ::SetDataBrowserTableViewNamedColumnWidth(m_controlRef,propertyID,width);
5829b303 510}
489468fe 511
e86edab0
RR
512OSStatus wxMacDataBrowserTableViewControl::SetDefaultColumnWidth(UInt16 width)
513{
de40d736 514 return ::SetDataBrowserTableViewColumnWidth(m_controlRef,width);
e86edab0 515}
489468fe 516
e86edab0 517OSStatus wxMacDataBrowserTableViewControl::SetDefaultRowHeight(UInt16 height)
489468fe 518{
de40d736 519 return ::SetDataBrowserTableViewRowHeight(m_controlRef,height);
5829b303 520}
489468fe 521
e86edab0 522OSStatus wxMacDataBrowserTableViewControl::SetHasScrollBars(bool horiz, bool vert)
489468fe 523{
de40d736
VZ
524 return ::SetDataBrowserHasScrollBars(m_controlRef,horiz,vert);
525}
489468fe 526
e86edab0
RR
527OSStatus wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16 height)
528{
de40d736
VZ
529 return ::SetDataBrowserListViewHeaderBtnHeight(m_controlRef,height);
530}
489468fe 531
e86edab0 532OSStatus wxMacDataBrowserTableViewControl::SetHiliteStyle(DataBrowserTableViewHiliteStyle hiliteStyle)
489468fe 533{
de40d736
VZ
534 return ::SetDataBrowserTableViewHiliteStyle(m_controlRef,hiliteStyle);
535}
489468fe 536
e86edab0
RR
537OSStatus wxMacDataBrowserTableViewControl::SetIndent(float Indent)
538{
de40d736
VZ
539 return ::DataBrowserSetMetric(m_controlRef,kDataBrowserMetricDisclosureColumnPerDepthGap,true,Indent);
540}
489468fe 541
e86edab0 542OSStatus wxMacDataBrowserTableViewControl::SetItemRowHeight(DataBrowserItemID item, UInt16 height)
489468fe 543{
de40d736 544 return ::SetDataBrowserTableViewItemRowHeight(m_controlRef,item,height);
5829b303
VZ
545}
546
e86edab0
RR
547OSStatus wxMacDataBrowserTableViewControl::SetScrollPosition(UInt32 top, UInt32 left)
548{
de40d736 549 return ::SetDataBrowserScrollPosition(m_controlRef,top,left);
e86edab0 550}
489468fe 551
e86edab0
RR
552//
553// column handling
554//
555OSStatus wxMacDataBrowserTableViewControl::GetColumnCount(UInt32* numColumns) const
489468fe 556{
de40d736 557 return ::GetDataBrowserTableViewColumnCount(m_controlRef,numColumns);
489468fe
SC
558}
559
e86edab0 560OSStatus wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex* index) const
489468fe 561{
de40d736
VZ
562 return ::GetDataBrowserTableViewColumnPosition(m_controlRef,propertyID,index);
563}
489468fe 564
e86edab0
RR
565OSStatus wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID* propertyID) const
566{
567 for (*propertyID=kMinPropertyID; *propertyID<std::numeric_limits<DataBrowserPropertyID>::max(); ++(*propertyID))
de40d736 568 if (IsUsedPropertyID(*propertyID) == errDataBrowserPropertyNotFound)
e86edab0
RR
569 return noErr;
570 return errDataBrowserPropertyNotSupported;
de40d736 571}
5829b303 572
e86edab0
RR
573OSStatus wxMacDataBrowserTableViewControl::GetPropertyFlags(DataBrowserPropertyID propertyID, DataBrowserPropertyFlags *flags) const
574{
de40d736 575 return ::GetDataBrowserPropertyFlags(m_controlRef,propertyID,flags);
5829b303 576}
489468fe 577
e86edab0 578OSStatus wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef itemData, DataBrowserPropertyID* propertyID) const
489468fe 579{
e86edab0 580 return ::GetDataBrowserItemDataProperty(itemData,propertyID);
de40d736 581}
489468fe 582
e86edab0
RR
583OSStatus wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex index, DataBrowserTableViewColumnID* propertyID) const
584{
de40d736
VZ
585 return ::GetDataBrowserTableViewColumnProperty(m_controlRef,index,propertyID);
586}
489468fe 587
e86edab0 588OSStatus wxMacDataBrowserTableViewControl::IsUsedPropertyID(DataBrowserPropertyID propertyID) const
489468fe 589{
e86edab0
RR
590 // 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
591 // 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
592 // the column position for the property id:
593 DataBrowserTableViewColumnIndex index;
8f2a8de6 594
de40d736
VZ
595 return ::GetDataBrowserTableViewColumnPosition(m_controlRef,propertyID,&index);
596}
489468fe 597
e86edab0 598OSStatus wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID propertyID)
489468fe 599{
de40d736
VZ
600 return ::RemoveDataBrowserTableViewColumn(m_controlRef,propertyID);
601}
489468fe 602
e86edab0
RR
603OSStatus wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex index)
604{
605 DataBrowserTableViewColumnID propertyID;
5829b303 606
489468fe 607
de40d736
VZ
608 GetPropertyID(index,&propertyID);
609 return ::RemoveDataBrowserTableViewColumn(m_controlRef,propertyID);
610}
489468fe 611
e86edab0
RR
612OSStatus wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex index)
613{
de40d736
VZ
614 return ::SetDataBrowserTableViewColumnPosition(m_controlRef,propertyID,index);
615}
489468fe 616
e86edab0 617OSStatus wxMacDataBrowserTableViewControl::SetDisclosureColumn(DataBrowserPropertyID propertyID, Boolean expandableRows)
489468fe 618{
de40d736 619 return ::SetDataBrowserListViewDisclosureColumn(m_controlRef,propertyID,expandableRows);
5829b303 620}
489468fe 621
e86edab0
RR
622OSStatus wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID propertyID, DataBrowserPropertyFlags flags)
623{
de40d736
VZ
624 return ::SetDataBrowserPropertyFlags(m_controlRef,propertyID,flags);
625}
489468fe 626
e86edab0
RR
627//
628// item handling
629//
630OSStatus wxMacDataBrowserTableViewControl::AddItems(DataBrowserItemID container, UInt32 numItems, DataBrowserItemID const* items, DataBrowserPropertyID preSortProperty)
631{
de40d736
VZ
632 return ::AddDataBrowserItems(m_controlRef,container,numItems,items,preSortProperty);
633}
489468fe 634
e86edab0 635OSStatus wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID* id) const
489468fe 636{
e86edab0 637 ItemCount noOfItems;
8f2a8de6 638
e86edab0 639 OSStatus status;
8f2a8de6
VZ
640
641
de40d736 642 status = GetItemCount(&noOfItems);
e86edab0
RR
643 wxCHECK_MSG(status == noErr,status,_("Could not retrieve number of items"));
644 if (noOfItems == 0)
645 {
646 *id = 1;
647 return noErr;
648 }
649 else
650 {
651 // 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
652 // as the number of items; therefore, start from the number of items to look for a new ID:
653 for (*id=noOfItems; *id<std::numeric_limits<DataBrowserItemID>::max(); ++(*id))
de40d736 654 if (IsUsedItemID(*id) == errDataBrowserItemNotFound)
e86edab0
RR
655 return noErr;
656 // as the first approach was not successful, try from the beginning:
657 for (*id=0; *id<noOfItems; ++(*id))
de40d736 658 if (IsUsedItemID(*id) == errDataBrowserItemNotFound)
e86edab0
RR
659 return noErr;
660 // sorry, data browser is full:
661 return errDataBrowserItemNotAdded;
662 }
de40d736 663}
489468fe 664
e86edab0 665OSStatus wxMacDataBrowserTableViewControl::GetItemCount(DataBrowserItemID container, Boolean recurse, DataBrowserItemState state, ItemCount* numItems) const
489468fe 666{
de40d736
VZ
667 return GetDataBrowserItemCount(m_controlRef,container,recurse,state,numItems);
668}
489468fe 669
e86edab0 670OSStatus wxMacDataBrowserTableViewControl::GetItemID( DataBrowserTableViewRowIndex row, DataBrowserItemID * item ) const
489468fe 671{
de40d736 672 return GetDataBrowserTableViewItemID(m_controlRef,row,item);
5829b303 673}
489468fe 674
e86edab0 675OSStatus wxMacDataBrowserTableViewControl::GetItems(DataBrowserItemID container, Boolean recurse, DataBrowserItemState state, Handle items) const
489468fe 676{
de40d736
VZ
677 return GetDataBrowserItems(m_controlRef,container,recurse,state,items);
678}
489468fe 679
e86edab0 680OSStatus wxMacDataBrowserTableViewControl::GetItemRow(DataBrowserItemID item, DataBrowserTableViewRowIndex* row) const
489468fe 681{
de40d736 682 return GetDataBrowserTableViewItemRow(m_controlRef,item,row);
5829b303 683}
489468fe 684
e86edab0 685OSStatus wxMacDataBrowserTableViewControl::GetItemState(DataBrowserItemID item, DataBrowserItemState* state) const
489468fe 686{
de40d736 687 return ::GetDataBrowserItemState(m_controlRef,item,state);
5829b303 688}
489468fe 689
e86edab0
RR
690OSStatus wxMacDataBrowserTableViewControl::IsUsedItemID(DataBrowserItemID itemID) const
691{
692 // 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
693 // 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
694 // the column position for the property id:
695 DataBrowserTableViewColumnIndex index;
8f2a8de6 696
de40d736
VZ
697 return ::GetDataBrowserTableViewItemRow(m_controlRef,itemID,&index);
698}
489468fe 699
e86edab0 700OSStatus wxMacDataBrowserTableViewControl::RemoveItems(DataBrowserItemID container, UInt32 numItems, DataBrowserItemID const* items, DataBrowserPropertyID preSortProperty)
489468fe 701{
de40d736 702 return ::RemoveDataBrowserItems(m_controlRef,container,numItems,items,preSortProperty);
489468fe
SC
703}
704
e86edab0 705OSStatus wxMacDataBrowserTableViewControl::RevealItem(DataBrowserItemID item, DataBrowserPropertyID propertyID, DataBrowserRevealOptions options) const
489468fe 706{
de40d736
VZ
707 return ::RevealDataBrowserItem(m_controlRef,item,propertyID,options);
708}
489468fe 709
e86edab0
RR
710OSStatus wxMacDataBrowserTableViewControl::UpdateItems(DataBrowserItemID container, UInt32 numItems, DataBrowserItemID const* items, DataBrowserPropertyID preSortProperty,
711 DataBrowserPropertyID propertyID) const
489468fe 712{
de40d736 713 return UpdateDataBrowserItems(m_controlRef,container,numItems,items,preSortProperty,propertyID);
5829b303 714}
489468fe 715
e86edab0
RR
716//
717// item selection
718//
719size_t wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserItemID& itemIDs) const
489468fe 720{
e86edab0
RR
721 DataBrowserItemID* itemIDPtr;
722 Handle handle(::NewHandle(0));
8f2a8de6 723
e86edab0 724 size_t noOfItems;
489468fe 725
5829b303 726
de40d736 727 wxCHECK_MSG(GetItems(kDataBrowserNoItem,true,kDataBrowserItemIsSelected,handle) == noErr,0,_("Could not get selected items."));
e86edab0
RR
728 noOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
729 itemIDs.Empty();
730 itemIDs.Alloc(noOfItems);
731 HLock(handle);
732 itemIDPtr = (DataBrowserItemID*) (*handle);
733 for (size_t i=0; i<noOfItems; ++i)
489468fe 734 {
e86edab0
RR
735 itemIDs.Add(*itemIDPtr);
736 ++itemIDPtr;
737 }
738 HUnlock(handle);
739 DisposeHandle(handle);
740 return noOfItems;
de40d736 741}
5829b303 742
e86edab0
RR
743OSStatus wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID* first, DataBrowserItemID* last) const
744{
de40d736
VZ
745 return ::GetDataBrowserSelectionAnchor(m_controlRef,first,last);
746}
489468fe 747
e86edab0
RR
748OSStatus wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags* flags) const
749{
de40d736
VZ
750 return ::GetDataBrowserSelectionFlags(m_controlRef,flags);
751}
489468fe 752
e86edab0 753bool wxMacDataBrowserTableViewControl::IsItemSelected(DataBrowserItemID item) const
489468fe 754{
de40d736
VZ
755 return ::IsDataBrowserItemSelected(m_controlRef,item);
756}
489468fe 757
e86edab0
RR
758OSStatus wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectionFlags flags)
759{
de40d736
VZ
760 return ::SetDataBrowserSelectionFlags(m_controlRef,flags);
761}
489468fe 762
e86edab0
RR
763OSStatus wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32 numItems, DataBrowserItemID const* items, DataBrowserSetOption operation)
764{
de40d736
VZ
765 return ::SetDataBrowserSelectedItems(m_controlRef, numItems, items, operation );
766}
5829b303 767
e86edab0
RR
768OSStatus wxMacDataBrowserTableViewControl::GetSortOrder(DataBrowserSortOrder* order) const
769{
de40d736 770 return ::GetDataBrowserSortOrder(m_controlRef,order);
e86edab0 771}
489468fe 772
e86edab0
RR
773OSStatus wxMacDataBrowserTableViewControl::GetSortProperty(DataBrowserPropertyID* propertyID) const
774{
de40d736 775 return ::GetDataBrowserSortProperty(m_controlRef,propertyID);
5829b303 776}
489468fe 777
e86edab0 778OSStatus wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID container, Boolean sortChildren)
489468fe 779{
de40d736
VZ
780 return ::SortDataBrowserContainer(m_controlRef,container,sortChildren);
781}
489468fe 782
e86edab0
RR
783OSStatus wxMacDataBrowserTableViewControl::SetSortOrder(DataBrowserSortOrder order)
784{
de40d736 785 return ::SetDataBrowserSortOrder(m_controlRef,order);
e86edab0 786}
5829b303 787
e86edab0
RR
788OSStatus wxMacDataBrowserTableViewControl::SetSortProperty(DataBrowserPropertyID propertyID)
789{
de40d736 790 return ::SetDataBrowserSortProperty(m_controlRef,propertyID);
e86edab0 791}
5829b303 792
e86edab0
RR
793//
794// container handling
795//
796OSStatus wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID containerID)
797{
de40d736
VZ
798 return ::CloseDataBrowserContainer(m_controlRef,containerID);
799}
5829b303 800
e86edab0
RR
801OSStatus wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID containerID)
802{
de40d736
VZ
803 return ::OpenDataBrowserContainer(m_controlRef,containerID);
804}
489468fe 805
e86edab0
RR
806IMPLEMENT_ABSTRACT_CLASS(wxMacDataBrowserTableViewControl,wxMacControl)
807
808// ============================================================================
809// wxMacDataBrowserListViewControl
810// ============================================================================
811#pragma mark -
812//
813// column handling
814//
815OSStatus wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc *columnDesc, DataBrowserTableViewColumnIndex position)
489468fe 816{
de40d736
VZ
817 return AddDataBrowserListViewColumn(m_controlRef,columnDesc,position);
818}
489468fe 819
e86edab0
RR
820// ============================================================================
821// wxMacDataViewDataBrowserListViewControl
822// ============================================================================
823#pragma mark -
824//
825// constructors / destructor
826//
827wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl(wxWindow* peer, wxPoint const& pos, wxSize const& size, long style)
828 :wxMacDataBrowserListViewControl(peer,pos,size,style)
829{
830 if ((style & wxBORDER_NONE) != 0)
de40d736
VZ
831 SetData(kControlNoPart,kControlDataBrowserIncludesFrameAndFocusTag,(Boolean) false);
832 (void) EnableAutomaticDragTracking();
833 (void) SetHiliteStyle(kDataBrowserTableViewFillHilite);
834}
5829b303 835
e86edab0
RR
836//
837// column related methods (inherited from wxDataViewWidgetImpl)
838//
de40d736 839bool wxMacDataViewDataBrowserListViewControl::ClearColumns()
e86edab0
RR
840{
841 UInt32 noOfColumns;
8f2a8de6
VZ
842
843
de40d736 844 wxCHECK_MSG(GetColumnCount(&noOfColumns) == noErr,false,_("Could not determine number of columns."));
e86edab0 845 for (UInt32 i=0; i<noOfColumns; ++i)
de40d736 846 wxCHECK_MSG(RemoveColumnByIndex(0) == noErr,false,_("Could not remove column."));
e86edab0
RR
847 return true;
848}
5829b303 849
e86edab0
RR
850bool wxMacDataViewDataBrowserListViewControl::DeleteColumn(wxDataViewColumn* columnPtr)
851{
de40d736 852 return (RemoveColumnByProperty(columnPtr->GetNativeData()->GetPropertyID()) == noErr);
e86edab0 853}
5829b303 854
e86edab0
RR
855void wxMacDataViewDataBrowserListViewControl::DoSetExpanderColumn(wxDataViewColumn const* columnPtr)
856{
4c51a665 857 SetDisclosureColumn(columnPtr->GetNativeData()->GetPropertyID(),false); // second parameter explicitly passed to ensure that arrow is centered
5829b303 858}
489468fe 859
e86edab0 860wxDataViewColumn* wxMacDataViewDataBrowserListViewControl::GetColumn(unsigned int pos) const
489468fe 861{
e86edab0
RR
862 DataBrowserPropertyID propertyID;
863
864
de40d736
VZ
865 if (GetPropertyID(pos,&propertyID) == noErr)
866 return GetColumnPtr(propertyID);
489468fe 867 else
e86edab0
RR
868 return NULL;
869}
489468fe 870
e86edab0
RR
871int wxMacDataViewDataBrowserListViewControl::GetColumnPosition(wxDataViewColumn const* columnPtr) const
872{
873 if (columnPtr != NULL)
489468fe 874 {
e86edab0 875 DataBrowserTableViewColumnIndex Position;
5829b303 876
de40d736 877 wxCHECK_MSG(GetColumnIndex(columnPtr->GetNativeData()->GetPropertyID(),&Position) == noErr,wxNOT_FOUND,_("Could not determine column's position"));
e86edab0 878 return static_cast<int>(Position);
5829b303 879 }
e86edab0
RR
880 else
881 return wxNOT_FOUND;
5829b303 882}
489468fe 883
e86edab0 884bool wxMacDataViewDataBrowserListViewControl::InsertColumn(unsigned int pos, wxDataViewColumn* columnPtr)
489468fe 885{
e86edab0 886 DataBrowserListViewColumnDesc columnDescription;
489468fe 887
e86edab0 888 DataBrowserPropertyID newPropertyID;
5829b303 889
e86edab0 890 UInt32 noOfColumns;
5829b303 891
a1b806b9 892 wxCFStringRef title(columnPtr->GetTitle(),m_font.IsOk() ? dynamic_cast<wxDataViewCtrl*>(GetWXPeer())->GetFont().GetEncoding() : wxLocale::GetSystemEncoding());
489468fe 893
489468fe 894
e86edab0 895 // try to get new ID for the column:
de40d736 896 wxCHECK_MSG(GetFreePropertyID(&newPropertyID) == noErr,false,_("Cannot create new column's ID. Probably max. number of columns reached."));
e86edab0
RR
897 // set native data:
898 columnPtr->GetNativeData()->SetPropertyID(newPropertyID);
899 // create a column description, add column to the native control and do some final layout adjustments:
900 wxCHECK_MSG(::InitializeColumnDescription(columnDescription,columnPtr,title), false,_("Column description could not be initialized."));
de40d736
VZ
901 wxCHECK_MSG(AddColumn(&columnDescription,pos) == noErr, false,_("Column could not be added."));
902 wxCHECK_MSG(SetColumnWidth(newPropertyID,columnPtr->GetWidth()) == noErr,false,_("Column width could not be set."));
903 wxCHECK_MSG(GetColumnCount(&noOfColumns) == noErr, false,_("Number of columns could not be determined."));
e86edab0 904 if (noOfColumns == 1)
489468fe 905 {
de40d736 906 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(GetWXPeer()));
8f2a8de6 907
e86edab0
RR
908 wxCHECK_MSG(dataViewCtrlPtr != NULL,false,_("wxWidget's control not initialized."));
909 dataViewCtrlPtr->AddChildren(wxDataViewItem());
910 return true;
5829b303 911 }
e86edab0 912 else
de40d736 913 return Update(columnPtr);
5829b303 914}
489468fe 915
e86edab0
RR
916//
917// item related methods (inherited from wxDataViewWidgetImpl)
918//
919bool wxMacDataViewDataBrowserListViewControl::Add(wxDataViewItem const& parent, wxDataViewItem const& item)
489468fe 920{
e86edab0 921 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
5829b303 922
5829b303 923
de40d736
VZ
924 return (( parent.IsOk() && AddItem(reinterpret_cast<DataBrowserItemID>(parent.GetID()),&itemID) == noErr) ||
925 (!(parent.IsOk()) && AddItem(kDataBrowserNoItem,&itemID) == noErr));
5829b303 926}
489468fe 927
e86edab0 928bool wxMacDataViewDataBrowserListViewControl::Add(wxDataViewItem const& parent, wxDataViewItemArray const& items)
489468fe 929{
e86edab0 930 bool noFailureFlag;
489468fe 931
e86edab0 932 DataBrowserItemID* itemIDs;
5829b303 933
e86edab0 934 size_t noOfEntries;
5829b303 935
5829b303 936
e86edab0
RR
937 // convert all valid data view items to data browser items:
938 itemIDs = ::CreateDataBrowserItemIDArray(noOfEntries,items);
939 // insert all valid items into control:
940 noFailureFlag = ((noOfEntries == 0) ||
de40d736
VZ
941 !(parent.IsOk()) && (AddItems(kDataBrowserNoItem,noOfEntries,itemIDs,kDataBrowserItemNoProperty) == noErr) ||
942 parent.IsOk() && (AddItems(reinterpret_cast<DataBrowserItemID>(parent.GetID()),noOfEntries,itemIDs,kDataBrowserItemNoProperty) == noErr));
e86edab0
RR
943 // give allocated array space free again:
944 delete[] itemIDs;
945 // done:
946 return noFailureFlag;
5829b303 947}
489468fe 948
e86edab0 949void wxMacDataViewDataBrowserListViewControl::Collapse(wxDataViewItem const& item)
489468fe 950{
de40d736 951 CloseContainer(reinterpret_cast<DataBrowserItemID>(item.GetID()));
e86edab0 952}
489468fe 953
e86edab0
RR
954void wxMacDataViewDataBrowserListViewControl::EnsureVisible(wxDataViewItem const& item, const wxDataViewColumn* columnPtr)
955{
956 DataBrowserPropertyID propertyID;
5829b303 957
5829b303 958
e86edab0
RR
959 if (columnPtr != NULL)
960 propertyID = columnPtr->GetNativeData()->GetPropertyID();
961 else
962 propertyID = kDataBrowserNoItem;
de40d736 963 RevealItem(reinterpret_cast<DataBrowserItemID>(item.GetID()),propertyID,kDataBrowserRevealOnly);
5829b303 964}
489468fe 965
e86edab0 966void wxMacDataViewDataBrowserListViewControl::Expand(wxDataViewItem const& item)
9f68fe76 967{
de40d736 968 OpenContainer(reinterpret_cast<DataBrowserItemID>(item.GetID()));
9f68fe76
VZ
969}
970
de40d736 971unsigned int wxMacDataViewDataBrowserListViewControl::GetCount() const
9f68fe76 972{
e86edab0 973 ItemCount noOfItems;
9f68fe76 974
e86edab0 975
de40d736 976 wxCHECK_MSG(GetItemCount(&noOfItems) == noErr,0,_("Could not determine number of items"));
e86edab0 977 return noOfItems;
9f68fe76
VZ
978}
979
e86edab0
RR
980wxRect wxMacDataViewDataBrowserListViewControl::GetRectangle(wxDataViewItem const& item, wxDataViewColumn const* columnPtr)
981{
982 Rect MacRectangle;
983
489468fe 984
de40d736 985 if (GetPartBounds(reinterpret_cast<DataBrowserItemID>(item.GetID()),columnPtr->GetNativeData()->GetPropertyID(),kDataBrowserPropertyContentPart,&MacRectangle) == noErr)
e86edab0
RR
986 {
987 wxRect rectangle;
489468fe 988
e86edab0
RR
989 ::wxMacNativeToRect(&MacRectangle,&rectangle);
990 return rectangle;
991 }
992 else
993 return wxRect();
489468fe
SC
994}
995
e86edab0 996bool wxMacDataViewDataBrowserListViewControl::IsExpanded(wxDataViewItem const& item) const
489468fe 997{
850e47aa 998 DataBrowserItemState state = 0;
e86edab0 999
de40d736 1000 if (GetItemState(reinterpret_cast<DataBrowserItemID>(item.GetID()),&state) != noErr)
850e47aa 1001 return false;
e86edab0 1002
850e47aa 1003 return ((state & kDataBrowserContainerIsOpen) != 0);
5829b303 1004}
489468fe 1005
de40d736 1006bool wxMacDataViewDataBrowserListViewControl::Reload()
489468fe 1007{
e86edab0 1008 bool noFailureFlag;
489468fe 1009
e86edab0 1010 wxDataViewItemArray dataViewChildren;
489468fe 1011
5829b303 1012
de40d736
VZ
1013 noFailureFlag = (RemoveItems() == noErr);
1014 SetScrollPosition(0,0); // even after having removed all items the scrollbars may remain at their old position -> reset them
1015 GetDataViewCtrl()->GetModel()->GetChildren(wxDataViewItem(),dataViewChildren);
1016 GetDataViewCtrl()->GetModel()->ItemsAdded(wxDataViewItem(),dataViewChildren);
afe44233 1017
e86edab0
RR
1018 return noFailureFlag;
1019}
489468fe 1020
e86edab0
RR
1021bool wxMacDataViewDataBrowserListViewControl::Remove(wxDataViewItem const& parent, wxDataViewItem const& item)
1022{
1023 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
5829b303 1024
489468fe 1025
de40d736 1026 return (RemoveItem(reinterpret_cast<DataBrowserItemID>(parent.GetID()),&itemID) == noErr);
5829b303 1027}
489468fe 1028
e86edab0 1029bool wxMacDataViewDataBrowserListViewControl::Remove(wxDataViewItem const& parent, wxDataViewItemArray const& items)
636c8dab 1030{
e86edab0 1031 bool noFailureFlag;
489468fe 1032
e86edab0 1033 DataBrowserItemID* itemIDs;
489468fe 1034
e86edab0 1035 size_t noOfEntries;
5829b303 1036
489468fe 1037
e86edab0
RR
1038 // convert all valid data view items to data browser items:
1039 itemIDs = ::CreateDataBrowserItemIDArray(noOfEntries,items);
1040 // insert all valid items into control:
1041 noFailureFlag = ((noOfEntries == 0) ||
de40d736
VZ
1042 !(parent.IsOk()) && (RemoveItems(kDataBrowserNoItem,noOfEntries,itemIDs,kDataBrowserItemNoProperty) == noErr) ||
1043 parent.IsOk() && (RemoveItems(reinterpret_cast<DataBrowserItemID>(parent.GetID()),noOfEntries,itemIDs,kDataBrowserItemNoProperty) == noErr));
e86edab0
RR
1044 // give allocated array space free again:
1045 delete[] itemIDs;
1046 // done:
1047 return noFailureFlag;
489468fe
SC
1048}
1049
e86edab0 1050bool wxMacDataViewDataBrowserListViewControl::Update(wxDataViewColumn const* columnPtr)
489468fe 1051{
de40d736 1052 return (UpdateItems(kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty,columnPtr->GetNativeData()->GetPropertyID()) == noErr);
5829b303 1053}
489468fe 1054
e86edab0 1055bool wxMacDataViewDataBrowserListViewControl::Update(wxDataViewItem const& parent, wxDataViewItem const& item)
489468fe 1056{
e86edab0 1057 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
489468fe 1058
489468fe 1059
e86edab0 1060 if (parent.IsOk())
de40d736 1061 return (UpdateItem(reinterpret_cast<DataBrowserItemID>(parent.GetID()),&itemID) == noErr);
e86edab0 1062 else
de40d736 1063 return (UpdateItem(kDataBrowserNoItem,&itemID) == noErr);
e86edab0 1064}
489468fe 1065
e86edab0
RR
1066bool wxMacDataViewDataBrowserListViewControl::Update(wxDataViewItem const& parent, wxDataViewItemArray const& items)
1067{
1068 bool noFailureFlag;
489468fe 1069
e86edab0 1070 DataBrowserItemID* itemIDs;
489468fe 1071
e86edab0 1072 size_t noOfEntries;
489468fe 1073
489468fe 1074
e86edab0
RR
1075 // convert all valid data view items to data browser items:
1076 itemIDs = ::CreateDataBrowserItemIDArray(noOfEntries,items);
1077 if (parent.IsOk())
de40d736 1078 noFailureFlag = (UpdateItems(reinterpret_cast<DataBrowserItemID>(parent.GetID()),noOfEntries,itemIDs,kDataBrowserItemNoProperty,kDataBrowserItemNoProperty) == noErr);
489468fe 1079 else
de40d736 1080 noFailureFlag = (UpdateItems(kDataBrowserNoItem,noOfEntries,itemIDs,kDataBrowserItemNoProperty,kDataBrowserItemNoProperty) == noErr);
e86edab0
RR
1081 // release allocated array space:
1082 delete[] itemIDs;
489468fe 1083 // done:
e86edab0 1084 return noFailureFlag;
489468fe
SC
1085}
1086
e86edab0
RR
1087//
1088// model related methods
1089//
1090bool wxMacDataViewDataBrowserListViewControl::AssociateModel(wxDataViewModel* WXUNUSED(model))
489468fe 1091{
489468fe 1092 return true;
5829b303 1093}
489468fe 1094
e86edab0
RR
1095//
1096// selection related methods (inherited from wxDataViewWidgetImpl)
1097//
80ce465c
VZ
1098wxDataViewItem wxMacDataViewDataBrowserListViewControl::GetCurrentItem() const
1099{
1100 wxFAIL_MSG( "unimplemented for Carbon" );
1101
1102 return wxDataViewItem();
1103}
1104
1105void wxMacDataViewDataBrowserListViewControl::SetCurrentItem(const wxDataViewItem& WXUNUSED(item))
1106{
1107 wxFAIL_MSG( "unimplemented for Carbon" );
1108}
1109
fa93d732
VZ
1110int wxMacDataViewDataBrowserListViewControl::GetSelectedItemsCount() const
1111{
1112 Handle handle(::NewHandle(0));
1113
1114 if ( GetItems(kDataBrowserNoItem,true,kDataBrowserItemIsSelected,handle) != noErr )
1115 {
1116 wxFAIL_MSG( "failed to get selected items" );
1117 return 0;
1118 }
1119
1120 size_t noOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
1121 HUnlock(handle);
1122 DisposeHandle(handle);
1123
1124 return noOfItems;
1125}
1126
e86edab0 1127int wxMacDataViewDataBrowserListViewControl::GetSelections(wxDataViewItemArray& sel) const
489468fe 1128{
e86edab0 1129 size_t noOfSelectedItems;
5829b303 1130
e86edab0 1131 wxArrayDataBrowserItemID itemIDs;
5829b303 1132
5829b303 1133
de40d736 1134 noOfSelectedItems = GetSelectedItemIDs(itemIDs);
e86edab0
RR
1135 sel.Empty();
1136 sel.SetCount(noOfSelectedItems);
1137 for (size_t i=0; i<noOfSelectedItems; ++i)
1138 sel[i] = wxDataViewItem(reinterpret_cast<void*>(itemIDs[i]));
1139 return static_cast<int>(noOfSelectedItems);
5829b303 1140}
489468fe 1141
e86edab0 1142bool wxMacDataViewDataBrowserListViewControl::IsSelected(wxDataViewItem const& item) const
489468fe 1143{
de40d736 1144 return IsItemSelected(reinterpret_cast<DataBrowserItemID>(item.GetID()));
5829b303 1145}
489468fe 1146
e86edab0 1147void wxMacDataViewDataBrowserListViewControl::Select(wxDataViewItem const& item)
489468fe 1148{
e86edab0 1149 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
5829b303 1150
e86edab0 1151
de40d736 1152 SetSelectedItems(1,&itemID,kDataBrowserItemsAdd);
5829b303 1153}
489468fe 1154
de40d736 1155void wxMacDataViewDataBrowserListViewControl::SelectAll()
489468fe 1156{
e86edab0
RR
1157 DataBrowserItemID* itemIDPtr;
1158
1159 Handle handle(::NewHandle(0));
489468fe 1160
e86edab0 1161 size_t noOfItems;
489468fe 1162
e86edab0 1163
de40d736 1164 wxCHECK_RET(GetItems(kDataBrowserNoItem,true,kDataBrowserItemAnyState,handle) == noErr,_("Could not get items."));
e86edab0
RR
1165 noOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
1166 ::HLock(handle);
1167 itemIDPtr = (DataBrowserItemID*) (*handle);
de40d736 1168 SetSelectedItems(noOfItems,itemIDPtr,kDataBrowserItemsAssign);
e86edab0
RR
1169 ::HUnlock(handle);
1170 ::DisposeHandle(handle);
5829b303 1171}
489468fe 1172
e86edab0 1173void wxMacDataViewDataBrowserListViewControl::Unselect(wxDataViewItem const& item)
489468fe 1174{
e86edab0 1175 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
a881f34e 1176
489468fe 1177
de40d736 1178 SetSelectedItems(1,&itemID,kDataBrowserItemsRemove);
5829b303 1179}
489468fe 1180
de40d736 1181void wxMacDataViewDataBrowserListViewControl::UnselectAll()
489468fe 1182{
e86edab0 1183 DataBrowserItemID* itemIDPtr;
5829b303 1184
e86edab0 1185 Handle handle(::NewHandle(0));
5829b303 1186
e86edab0 1187 size_t noOfItems;
489468fe 1188
e86edab0 1189
de40d736 1190 wxCHECK_RET(GetItems(kDataBrowserNoItem,true,kDataBrowserItemAnyState,handle) == noErr,_("Could not get items."));
e86edab0
RR
1191 noOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
1192 ::HLock(handle);
1193 itemIDPtr = (DataBrowserItemID*) (*handle);
de40d736 1194 SetSelectedItems(noOfItems,itemIDPtr,kDataBrowserItemsRemove);
e86edab0
RR
1195 ::HUnlock(handle);
1196 ::DisposeHandle(handle);
739a8399
RR
1197}
1198
e86edab0
RR
1199//
1200// sorting related methods
1201//
de40d736 1202wxDataViewColumn* wxMacDataViewDataBrowserListViewControl::GetSortingColumn() const
489468fe
SC
1203{
1204 DataBrowserPropertyID propertyID;
1205
5829b303 1206
de40d736
VZ
1207 if (GetSortProperty(&propertyID) == noErr)
1208 return GetColumnPtr(propertyID);
489468fe
SC
1209 else
1210 return NULL;
5829b303 1211}
489468fe 1212
de40d736 1213void wxMacDataViewDataBrowserListViewControl::Resort()
489468fe 1214{
212e8ef3 1215 (void) wxMacDataBrowserListViewControl::Resort();
5829b303 1216}
489468fe 1217
e86edab0
RR
1218//
1219// other methods (inherited from wxDataViewWidgetImpl)
1220//
8f2a8de6
VZ
1221void
1222wxMacDataViewDataBrowserListViewControl::HitTest(const wxPoint& WXUNUSED(point),
1223 wxDataViewItem& item,
1224 wxDataViewColumn*& columnPtr) const
489468fe 1225{
e86edab0
RR
1226 // not yet implemented:
1227 item = wxDataViewItem();
1228 columnPtr = NULL;
5829b303 1229}
489468fe 1230
e86edab0 1231void wxMacDataViewDataBrowserListViewControl::DoSetIndent(int indent)
489468fe 1232{
de40d736 1233 SetIndent(static_cast<float>(indent));
5829b303 1234}
489468fe 1235
e86edab0 1236void wxMacDataViewDataBrowserListViewControl::SetRowHeight(wxDataViewItem const& item, unsigned int height)
489468fe 1237{
de40d736 1238 SetItemRowHeight(reinterpret_cast<DataBrowserItemID>(item.GetID()),static_cast<UInt16>(height));
5829b303 1239}
489468fe 1240
de40d736 1241void wxMacDataViewDataBrowserListViewControl::OnSize()
489468fe 1242{
e86edab0 1243 UInt32 noOfColumns;
8f2a8de6
VZ
1244
1245
de40d736 1246 GetColumnCount(&noOfColumns);
e86edab0
RR
1247 if (noOfColumns <= 1) // no horizontal scroll bar and the only column expands to the width of the whole control
1248 {
de40d736
VZ
1249 SetHasScrollBars(false,true);
1250 AutoSizeColumns();
e86edab0
RR
1251 }
1252 else // otherwise keep the current column size and have scrollbars in both directions
de40d736 1253 SetHasScrollBars(true,true);
5829b303 1254}
489468fe 1255
eeea3b03
RD
1256void wxMacDataViewDataBrowserListViewControl::StartEditor( const wxDataViewItem & item, unsigned int column )
1257{
1258 // implement me
1259}
1260
e86edab0
RR
1261//
1262// callback functions (inherited from wxMacDataBrowserTableViewControl)
1263//
1264Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID itemOneID, DataBrowserItemID itemTwoID, DataBrowserPropertyID sortProperty)
489468fe 1265{
e86edab0 1266 DataBrowserSortOrder sortOrder;
5829b303 1267
e86edab0 1268 DataBrowserTableViewColumnIndex modelColumnIndex;
8f2a8de6 1269
de40d736 1270 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(GetWXPeer()));
8f2a8de6 1271
5829b303 1272
e86edab0
RR
1273 wxCHECK_MSG(dataViewCtrlPtr != NULL, false,_("Pointer to data view control not set correctly."));
1274 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,false,_("Pointer to model not set correctly."));
1275 if (sortProperty >= kMinPropertyID)
1276 {
1277 // variable definition and initialization:
de40d736 1278 wxDataViewColumn* ColumnPtr(GetColumnPtr(sortProperty));
8f2a8de6 1279
e86edab0
RR
1280 wxCHECK_MSG(ColumnPtr != NULL,false,_("Could not determine column index."));
1281 modelColumnIndex = ColumnPtr->GetModelColumn();
1282 }
1283 else
1284 modelColumnIndex = 0;
de40d736 1285 GetSortOrder(&sortOrder);
e86edab0
RR
1286 return static_cast<Boolean>(dataViewCtrlPtr->GetModel()->Compare(wxDataViewItem(reinterpret_cast<void*>(itemOneID)),wxDataViewItem(reinterpret_cast<void*>(itemTwoID)),
1287 modelColumnIndex,sortOrder != kDataBrowserOrderDecreasing) < 0);
de40d736 1288}
489468fe 1289
e86edab0
RR
1290void wxMacDataViewDataBrowserListViewControl::DataBrowserGetContextualMenuProc(MenuRef* menu, UInt32* helpType, CFStringRef* helpItemString, AEDesc* WXUNUSED(selection))
1291 // In this method we do not supply a contextual menu handler at all but only send a wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU.
489468fe 1292{
e86edab0 1293 wxArrayDataBrowserItemID itemIDs;
5829b303 1294
de40d736 1295 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(GetWXPeer()));
5829b303 1296
5829b303 1297
e86edab0
RR
1298 wxCHECK_RET(dataViewCtrlPtr != NULL,_("wxWidget control pointer is not a data view pointer"));
1299 // initialize parameters so that no context menu will be displayed automatically by the native data browser:
1300 *menu = NULL;
1301 *helpType = kCMHelpItemNoHelp;
1302 *helpItemString = NULL;
1303 // create information for a context menu event:
1304 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU,dataViewCtrlPtr->GetId());
5829b303 1305
e86edab0
RR
1306 dataViewEvent.SetEventObject(dataViewCtrlPtr);
1307 dataViewEvent.SetModel(dataViewCtrlPtr->GetModel());
1308 // get the item information;
1309 // theoretically more than one ID can be returned but the event can only handle one item, therefore all item related data is using the data of the first item in the array:
de40d736 1310 if (GetSelectedItemIDs(itemIDs) > 0)
e86edab0
RR
1311 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemIDs[0])));
1312 // finally send the equivalent wxWidget event:
1313 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
de40d736 1314}
489468fe 1315
e86edab0 1316OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemDataRef itemData, Boolean getValue)
489468fe 1317{
e86edab0 1318 if (getValue)
489468fe 1319 {
e86edab0
RR
1320 // variable definitions:
1321 wxDataViewCtrl* dataViewCtrlPtr;
8f2a8de6 1322
de40d736 1323 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(GetWXPeer());
e86edab0
RR
1324 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
1325 if (dataViewCtrlPtr->IsDeleting())
1326 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
1327 else
1328 {
1329 // variable definitions:
1330 OSStatus errorStatus;
1331 wxDataViewColumn* dataViewColumnPtr;
8f2a8de6 1332
e86edab0 1333 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
de40d736 1334 dataViewColumnPtr = GetColumnPtr(propertyID);
e86edab0
RR
1335 wxCHECK_MSG((dataViewColumnPtr != NULL) && (dataViewColumnPtr->GetRenderer() != NULL),errDataBrowserNotConfigured,_("There is no column or renderer for the specified column index."));
1336
1337 wxDataViewItem dvItem(reinterpret_cast<void*>(itemID));
1338 unsigned int col = dataViewColumnPtr->GetModelColumn();
8f2a8de6 1339
e86edab0
RR
1340 switch (dataViewColumnPtr->GetRenderer()->GetNativeData()->GetPropertyType())
1341 {
1342 case kDataBrowserCheckboxType:
1343 {
1344 // variable definition:
1345 ThemeButtonValue buttonValue;
5829b303 1346
e86edab0
RR
1347 errorStatus = ::GetDataBrowserItemDataButtonValue(itemData,&buttonValue);
1348 if (errorStatus == noErr)
1349 {
1350 if (buttonValue == kThemeButtonOn)
1351 {
1352 // variable definition and initialization:
1353 wxVariant modifiedData(true);
1354
795dac4c 1355 if (dataViewCtrlPtr->GetModel()->ChangeValue(modifiedData, dvItem, col))
e86edab0
RR
1356 return noErr;
1357 else
1358 return errDataBrowserInvalidPropertyData;
1359 }
1360 else if (buttonValue == kThemeButtonOff)
1361 {
1362 // variable definition and initialization:
1363 wxVariant modifiedData(false);
1364
795dac4c 1365 if (dataViewCtrlPtr->GetModel()->ChangeValue(modifiedData, dvItem, col))
e86edab0
RR
1366 return noErr;
1367 else
1368 return errDataBrowserInvalidPropertyData;
1369 }
1370 else
1371 return errDataBrowserInvalidPropertyData;
1372 }
1373 else
1374 return errorStatus;
1375 } /* block */
1376 case kDataBrowserTextType:
1377 {
1378 // variable definitions:
1379 CFStringRef stringReference;
1380
1381 errorStatus = ::GetDataBrowserItemDataText(itemData,&stringReference);
1382 if (errorStatus == noErr)
1383 {
1384 // variable definitions and initializations:
1385#if wxCHECK_VERSION(2,9,0)
1386 wxCFStringRef modifiedString(stringReference);
1387#else
1388 wxMacCFStringHolder modifiedString(stringReference);
1389#endif
1390 wxVariant modifiedData(modifiedString.AsString());
8f2a8de6 1391
795dac4c 1392 if (dataViewCtrlPtr->GetModel()->ChangeValue(modifiedData, dvItem, col))
e86edab0
RR
1393 return noErr;
1394 else
1395 return errDataBrowserInvalidPropertyData;
1396 }
1397 else
1398 return errorStatus;
1399 } /* block */
1400 default:
1401 return errDataBrowserPropertyNotSupported;
1402 }
1403 }
5829b303 1404 }
e86edab0
RR
1405 else
1406 {
1407 if (propertyID >= kMinPropertyID) // in case data columns set the data
1408 {
1409 // variable definitions:
1410 wxVariant variant;
1411 wxDataViewColumn* dataViewColumnPtr;
1412 wxDataViewCtrl* dataViewCtrlPtr;
8f2a8de6 1413
de40d736 1414 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(GetWXPeer());
e86edab0
RR
1415 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
1416 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
de40d736 1417 dataViewColumnPtr = GetColumnPtr(propertyID);
e86edab0
RR
1418 wxCHECK_MSG(dataViewColumnPtr != NULL,errDataBrowserNotConfigured,_("No column for the specified column position existing."));
1419 wxCHECK_MSG(dataViewColumnPtr->GetRenderer() != NULL,errDataBrowserNotConfigured,_("No renderer specified for column."));
1420 dataViewCtrlPtr->GetModel()->GetValue(variant,wxDataViewItem(reinterpret_cast<void*>(itemID)),dataViewColumnPtr->GetModelColumn());
1421 if (!(variant.IsNull()))
1422 {
1423 dataViewColumnPtr->GetRenderer()->GetNativeData()->SetItemDataRef(itemData);
1424 dataViewColumnPtr->GetRenderer()->SetValue(variant);
8f2a8de6 1425 wxCHECK_MSG(dataViewColumnPtr->GetRenderer()->MacRender(),errDataBrowserNotConfigured,_("Rendering failed."));
e86edab0
RR
1426 }
1427 return noErr;
1428 }
1429 else // react on special system requests
1430 {
1431 switch (propertyID)
1432 {
1433 case kDataBrowserContainerIsClosableProperty:
1434 {
1435 // variable definitions:
de40d736 1436 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(GetWXPeer()));
8f2a8de6 1437
e86edab0
RR
1438 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
1439 // initialize wxWidget event:
1440 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING,dataViewCtrlPtr->GetId()); // variable definition
8f2a8de6 1441
e86edab0
RR
1442 dataViewEvent.SetEventObject(dataViewCtrlPtr);
1443 dataViewEvent.SetItem (wxDataViewItem(reinterpret_cast<void*>(itemID)));
1444 dataViewEvent.SetModel (dataViewCtrlPtr->GetModel());
1445 // finally send the equivalent wxWidget event:
1446 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
1447 // opening the container is allowed if not vetoed:
1448 return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewEvent.IsAllowed());
1449 } /* block */
1450 case kDataBrowserContainerIsOpenableProperty:
1451 {
1452 // variable definitions:
de40d736 1453 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(GetWXPeer()));
8f2a8de6 1454
e86edab0
RR
1455 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
1456 // initialize wxWidget event:
1457 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING,dataViewCtrlPtr->GetId()); // variable definition
1458
1459 dataViewEvent.SetEventObject(dataViewCtrlPtr);
1460 dataViewEvent.SetItem (wxDataViewItem(reinterpret_cast<void*>(itemID)));
1461 dataViewEvent.SetModel (dataViewCtrlPtr->GetModel());
1462 // finally send the equivalent wxWidget event:
1463 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
1464 // opening the container is allowed if not vetoed:
1465 return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewEvent.IsAllowed());
1466 } /* block */
1467 case kDataBrowserItemIsContainerProperty:
1468 {
1469 // variable definition:
de40d736 1470 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(GetWXPeer()));
8f2a8de6 1471
e86edab0
RR
1472 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
1473 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
1474 return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewCtrlPtr->GetModel()->IsContainer(wxDataViewItem(reinterpret_cast<void*>(itemID))));
1475 } /* block */
1476 case kDataBrowserItemIsEditableProperty:
1477 return ::SetDataBrowserItemDataBooleanValue(itemData,true);
1478 }
1479 }
1480 }
1481 return errDataBrowserPropertyNotSupported;
de40d736 1482}
489468fe 1483
e86edab0 1484void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID itemID, DataBrowserItemNotification message, DataBrowserItemDataRef itemData)
489468fe 1485{
de40d736 1486 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(GetWXPeer()));
489468fe 1487
489468fe 1488
e86edab0
RR
1489 // 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:
1490 if (dataViewCtrlPtr != NULL)
1491 switch (message)
4219d8b0 1492 {
e86edab0
RR
1493 case kDataBrowserContainerClosed:
1494 dataViewCtrlPtr->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
4219d8b0 1495 {
e86edab0
RR
1496 // initialize wxWidget event:
1497 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED,dataViewCtrlPtr->GetId()); // variable definition
8f2a8de6 1498
e86edab0
RR
1499 dataViewEvent.SetEventObject(dataViewCtrlPtr);
1500 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
1501 // finally send the equivalent wxWidget event:
1502 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
1503 } /* block */
1504 break;
1505 case kDataBrowserContainerOpened:
1506 dataViewCtrlPtr->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
1507 {
1508 // initialize wxWidget event:
1509 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED,dataViewCtrlPtr->GetId()); // variable definition
8f2a8de6 1510
e86edab0
RR
1511 dataViewEvent.SetEventObject(dataViewCtrlPtr);
1512 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
1513 // finally send the equivalent wxWidget event:
1514 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
1515 // add children to the expanded container:
1516 dataViewCtrlPtr->AddChildren(wxDataViewItem(reinterpret_cast<void*>(itemID)));
1517 } /* block */
1518 break;
1519 case kDataBrowserEditStarted:
1520 dataViewCtrlPtr->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
1521 {
1522 // initialize wxWidget event:
8f2a8de6 1523 DataBrowserPropertyID propertyID;
e86edab0 1524 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED,dataViewCtrlPtr->GetId()); // variable definition
8f2a8de6 1525
e86edab0
RR
1526 dataViewEvent.SetEventObject(dataViewCtrlPtr);
1527 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
de40d736 1528 if (GetPropertyID(itemData,&propertyID) == noErr)
e86edab0
RR
1529 {
1530 // variable definition and initialization:
1531 DataBrowserTableViewColumnIndex columnIndex;
8f2a8de6 1532
de40d736 1533 wxCHECK_RET(GetColumnIndex(propertyID,&columnIndex),_("Column index not found."));
e86edab0 1534 dataViewEvent.SetColumn(columnIndex);
de40d736 1535 dataViewEvent.SetDataViewColumn(GetColumnPtr(propertyID));
e86edab0
RR
1536 }
1537 // finally send the equivalent wxWidget event:
1538 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
1539 } /* block */
1540 break;
1541 case kDataBrowserEditStopped:
1542 {
1543 // initialize wxWidget event:
8f2a8de6 1544 DataBrowserPropertyID propertyID;
e86edab0 1545 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE,dataViewCtrlPtr->GetId()); // variable definition
8f2a8de6 1546
e86edab0
RR
1547 dataViewEvent.SetEventObject(dataViewCtrlPtr);
1548 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
de40d736 1549 if (GetPropertyID(itemData,&propertyID) == noErr)
e86edab0
RR
1550 {
1551 // variable definition and initialization:
1552 DataBrowserTableViewColumnIndex columnIndex;
1553
de40d736 1554 wxCHECK_RET(GetColumnIndex(propertyID,&columnIndex),_("Column index not found."));
e86edab0 1555 dataViewEvent.SetColumn(columnIndex);
de40d736 1556 dataViewEvent.SetDataViewColumn(GetColumnPtr(propertyID));
e86edab0
RR
1557 }
1558 // finally send the equivalent wxWidget event:
1559 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
1560 } /* block */
1561 break;
1562 case kDataBrowserItemAdded:
1563 dataViewCtrlPtr->FinishCustomItemEditing();
1564 break;
1565 case kDataBrowserItemDeselected:
1566 dataViewCtrlPtr->FinishCustomItemEditing();
1567 break;
1568 case kDataBrowserItemDoubleClicked:
1569 {
1570 // initialize wxWidget event:
1571 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED,dataViewCtrlPtr->GetId()); // variable definition
1572
1573 dataViewEvent.SetEventObject(dataViewCtrlPtr);
1574 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
1575 // finally send the equivalent wxWidget event:
1576 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
1577 } /* block */
1578 break;
1579 case kDataBrowserItemRemoved:
1580 dataViewCtrlPtr->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
1581 break;
1582 case kDataBrowserItemSelected:
1583 break; // not implemented by wxWidgets; see kDataBrowserSelectionSetChanged
1584 case kDataBrowserSelectionSetChanged:
1585 {
1586 // initialize wxWidget event:
1587 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED,dataViewCtrlPtr->GetId()); // variable definition
1588
1589 dataViewEvent.SetEventObject(dataViewCtrlPtr);
1590 dataViewEvent.SetModel (dataViewCtrlPtr->GetModel());
1591 // finally send the equivalent wxWidget event:
1592 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
1593 } /* block */
1594 break;
1595 case kDataBrowserTargetChanged: // no idea if this notification is ever sent
1596 break;
1597 case kDataBrowserUserStateChanged:
1598 {
1599 // finish custom item editing if necessary:
1600 dataViewCtrlPtr->FinishCustomItemEditing();
1601 // update column widths:
1602 for (size_t i=0; i<dataViewCtrlPtr->GetColumnCount(); ++i)
1603 {
1604 // constant definition for abbreviational purposes:
1605 wxDataViewColumn* const columnPtr = dataViewCtrlPtr->GetColumnPtr(i);
1606 // variable definition:
1607 UInt16 columnWidth;
8f2a8de6 1608
de40d736 1609 wxCHECK_RET(GetColumnWidth(columnPtr->GetNativeData()->GetPropertyID(),&columnWidth) == noErr,_("Column width could not be determined"));
e86edab0
RR
1610 columnPtr->SetWidthVariable(columnWidth);
1611 }
1612 // update sorting orders:
1613 DataBrowserPropertyID propertyID; // variable definition
1614
de40d736 1615 if ((GetSortProperty(&propertyID) == noErr) && (propertyID >= kMinPropertyID))
e86edab0
RR
1616 {
1617 DataBrowserSortOrder sortOrder;
1618 DataBrowserTableViewColumnIndex columnIndex;
8f2a8de6 1619
de40d736 1620 if ((GetSortOrder(&sortOrder) == noErr) && (GetColumnIndex(propertyID,&columnIndex) == noErr))
e86edab0
RR
1621 {
1622 // variable definition and initialization:
1623 wxDataViewColumn* columnPtr;
1624 columnPtr = dataViewCtrlPtr->GetColumn(columnIndex);
1625 // check if the sort order has changed:
1626 if ( columnPtr->IsSortOrderAscending() && (sortOrder == kDataBrowserOrderDecreasing) ||
1627 !(columnPtr->IsSortOrderAscending()) && (sortOrder == kDataBrowserOrderIncreasing))
1628 {
1629 columnPtr->SetSortOrder(!(columnPtr->IsSortOrderAscending()));
1630 // initialize wxWidget event:
1631 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED,dataViewCtrlPtr->GetId()); // variable defintion
1632
1633 dataViewEvent.SetEventObject(dataViewCtrlPtr);
1634 dataViewEvent.SetColumn(columnIndex);
1635 dataViewEvent.SetDataViewColumn(columnPtr);
1636 // finally send the equivalent wxWidget event:
1637 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
1638 }
1639 }
1640 }
1641 } /* block */
1642 break;
4219d8b0 1643 }
de40d736 1644}
5829b303 1645
8f2a8de6
VZ
1646void
1647wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID itemID,
1648 DataBrowserPropertyID propertyID,
1649 DataBrowserItemState state,
1650 Rect const* rectangle,
1651 SInt16 WXUNUSED(bitDepth),
1652 Boolean WXUNUSED(colorDevice))
e86edab0
RR
1653{
1654 DataBrowserTableViewColumnIndex columnIndex;
5829b303 1655
e86edab0 1656 wxDataViewColumn* dataViewColumnPtr;
489468fe 1657
e86edab0 1658 wxDataViewCtrl* dataViewCtrlPtr;
8f2a8de6 1659
e86edab0
RR
1660 wxDataViewCustomRenderer* dataViewCustomRendererPtr;
1661
1662 wxVariant dataToRender;
1663
de40d736 1664 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(GetWXPeer());
e86edab0
RR
1665 wxCHECK_RET(dataViewCtrlPtr != NULL, _("Pointer to data view control not set correctly."));
1666 wxCHECK_RET(dataViewCtrlPtr->GetModel() != NULL, _("Pointer to model not set correctly."));
de40d736
VZ
1667 wxCHECK_RET(GetColumnIndex(propertyID,&columnIndex) == noErr,_("Could not determine column index."));
1668 dataViewColumnPtr = GetColumnPtr(propertyID);
e86edab0
RR
1669 wxCHECK_RET(dataViewColumnPtr != NULL,_("No column for the specified column existing."));
1670 dataViewCustomRendererPtr = dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer());
1671 wxCHECK_RET(dataViewCustomRendererPtr != NULL,_("No renderer or invalid renderer type specified for custom data column."));
1672 dataViewCtrlPtr->GetModel()->GetValue(dataToRender,wxDataViewItem(reinterpret_cast<void*>(itemID)),dataViewColumnPtr->GetModelColumn());
1673 dataViewCustomRendererPtr->SetValue(dataToRender);
1674
1675 wxDataViewItem dataItem( reinterpret_cast<void*>(itemID) );
1676 dataViewCtrlPtr->GetModel()->GetValue(dataToRender,dataItem,dataViewColumnPtr->GetModelColumn());
1677 dataViewCustomRendererPtr->SetValue(dataToRender);
1678
1679 // try to determine the content's size (drawable part):
1680 Rect content;
1681 RgnHandle rgn(NewRgn());
1682 UInt16 headerHeight;
1683
1684 if (GetControlRegion(m_controlRef,kControlContentMetaPart,rgn) == noErr)
1685 GetRegionBounds(rgn,&content);
1686 else
1687 GetControlBounds(m_controlRef, &content);
1688 ::DisposeRgn(rgn);
1689 // space for the header
de40d736 1690 GetHeaderButtonHeight(&headerHeight);
e86edab0
RR
1691 content.top += headerHeight;
1692 // extra space for the frame (todo: do not how to determine the space automatically from the control)
1693 content.top += 5;
1694 content.left += 5;
1695 content.right -= 3;
1696 content.bottom -= 3;
1697 // extra space for the scrollbars:
1698 content.bottom -= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
1699 content.right -= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
1700
1701 wxDC *dc = dataViewCustomRendererPtr->GetDC();
8f2a8de6 1702
35d85392
RR
1703 int active_border_fudge = 0;
1704 if (dataViewCtrlPtr->HasFocus() && !dataViewCtrlPtr->HasFlag( wxBORDER_NONE ))
1705 active_border_fudge = 1;
1706 else
1707 active_border_fudge = -2;
8f2a8de6 1708
35d85392
RR
1709 wxRect cellrect( static_cast<int>(rectangle->left + active_border_fudge),
1710 static_cast<int>(rectangle->top + active_border_fudge),
e86edab0
RR
1711 static_cast<int>(1+rectangle->right-rectangle->left),
1712 static_cast<int>(rectangle->bottom-rectangle->top) );
8f2a8de6 1713
de40d736 1714 bool is_active = IsControlActive( m_controlRef );
e86edab0 1715 if (state == kDataBrowserItemIsSelected)
489468fe 1716 {
8f2a8de6 1717 wxColour col( wxMacCreateCGColorFromHITheme( (is_active) ?
e86edab0
RR
1718 kThemeBrushAlternatePrimaryHighlightColor
1719 : kThemeBrushSecondaryHighlightColor ) );
8f2a8de6 1720
e86edab0
RR
1721 wxRect rect = cellrect;
1722 Rect itemrect;
de40d736 1723 GetDataBrowserItemPartBounds( m_controlRef, itemID, propertyID,
e86edab0 1724 kDataBrowserPropertyEnclosingPart, &itemrect );
35d85392
RR
1725 rect.x = itemrect.left-2;
1726 rect.width = itemrect.right-itemrect.left+3;
8f2a8de6 1727
0b2a23c4
VZ
1728 wxDCPenChanger setPen(*dc, *wxTRANSPARENT_PEN);
1729 wxDCBrushChanger setBrush(*dc, col);
e86edab0 1730 dc->DrawRectangle(rect);
e86edab0 1731 }
5829b303 1732
e86edab0
RR
1733 wxDataViewModel *model = dataViewCtrlPtr->GetModel();
1734 if ((columnIndex == 0) || !model->IsContainer(dataItem) || model->HasContainerColumns(dataItem))
8f2a8de6 1735 {
e86edab0
RR
1736 // make sure that 'Render' can draw only in the allowed area:
1737 dc->SetClippingRegion(content.left,content.top,content.right-content.left+1,content.bottom-content.top+1);
62265c2c 1738 (void) (dataViewCustomRendererPtr->WXCallRender( cellrect, dc,
e86edab0
RR
1739 ((state == kDataBrowserItemIsSelected) ? wxDATAVIEW_CELL_SELECTED : 0)));
1740 dc->DestroyClippingRegion(); // probably not necessary
5829b303 1741 }
8f2a8de6 1742
e86edab0 1743 dataViewCustomRendererPtr->SetDC(NULL);
de40d736 1744}
489468fe 1745
8f2a8de6
VZ
1746Boolean
1747wxMacDataViewDataBrowserListViewControl::DataBrowserEditItemProc(
1748 DataBrowserItemID WXUNUSED(itemID),
1749 DataBrowserPropertyID WXUNUSED(propertyID),
1750 CFStringRef WXUNUSED(theString),
1751 Rect* WXUNUSED(maxEditTextRect),
1752 Boolean* WXUNUSED(shrinkToFit))
489468fe 1753{
e86edab0 1754 return false;
de40d736 1755}
5829b303 1756
e86edab0
RR
1757Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserHitTestProc(DataBrowserItemID WXUNUSED(itemID), DataBrowserPropertyID WXUNUSED(property), Rect const* WXUNUSED(theRect), Rect const* WXUNUSED(mouseRect))
1758{
1759 return true;
de40d736 1760}
5829b303 1761
e86edab0
RR
1762DataBrowserTrackingResult wxMacDataViewDataBrowserListViewControl::DataBrowserTrackingProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, Rect const* theRect, Point WXUNUSED(startPt), EventModifiers WXUNUSED(modifiers))
1763{
1764 wxDataViewColumn* dataViewColumnPtr;
5829b303 1765
e86edab0 1766 wxDataViewCtrl* dataViewCtrlPtr;
8f2a8de6 1767
e86edab0 1768 wxDataViewCustomRenderer* dataViewCustomRendererPtr;
8f2a8de6 1769
e86edab0
RR
1770 wxDataViewItem dataViewCustomRendererItem;
1771
1772
de40d736 1773 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(GetWXPeer());
e86edab0
RR
1774 wxCHECK_MSG(dataViewCtrlPtr != NULL, false,_("Pointer to data view control not set correctly."));
1775 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,false,_("Pointer to model not set correctly."));
f5f302d7 1776 dataViewCustomRendererItem = wxDataViewItem(reinterpret_cast<void*>(itemID));
e86edab0 1777 wxCHECK_MSG(dataViewCustomRendererItem.IsOk(),kDataBrowserNothingHit,_("Invalid data view item"));
de40d736 1778 dataViewColumnPtr = GetColumnPtr(propertyID);
e86edab0
RR
1779 wxCHECK_MSG(dataViewColumnPtr != NULL,kDataBrowserNothingHit,_("No column existing."));
1780 dataViewCustomRendererPtr = dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer());
1781 wxCHECK_MSG(dataViewCustomRendererPtr != NULL,kDataBrowserNothingHit,_("No renderer or invalid renderer type specified for custom data column."));
1782 // if the currently edited item is identical to the to be edited nothing is done (this hit should only be handled in the control itself):
1783 if (dataViewCtrlPtr->GetCustomRendererItem() == dataViewCustomRendererItem)
1784 return kDataBrowserContentHit;
1785 // an(other) item is going to be edited and therefore the current editing - if existing - has to be finished:
1786 if (dataViewCtrlPtr->GetCustomRendererPtr() != NULL)
1787 {
1788 dataViewCtrlPtr->GetCustomRendererPtr()->FinishEditing();
1789 dataViewCtrlPtr->SetCustomRendererItem(wxDataViewItem());
1790 dataViewCtrlPtr->SetCustomRendererPtr (NULL);
1791 }
1792 // check if renderer has got a valid editor control for editing; if this is the case start editing of the new item:
1793 if (dataViewCustomRendererPtr->HasEditorCtrl())
1794 {
1795 // variable definition:
1796 wxRect wxRectangle;
8f2a8de6 1797
e86edab0
RR
1798 ::wxMacNativeToRect(theRect,&wxRectangle);
1799 dataViewCustomRendererPtr->StartEditing(dataViewCustomRendererItem,wxRectangle);
1800 dataViewCtrlPtr->SetCustomRendererItem(dataViewCustomRendererItem);
1801 dataViewCtrlPtr->SetCustomRendererPtr (dataViewCustomRendererPtr);
1802 }
1803 return kDataBrowserContentHit;
de40d736 1804}
5829b303 1805
e86edab0
RR
1806Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserAcceptDragProc(DragReference dragRef, DataBrowserItemID itemID)
1807{
1808 bool acceptDrag;
5829b303 1809
e86edab0 1810 UInt16 noOfDraggedItems;
489468fe 1811
e86edab0 1812 wxDataViewCtrl* dataViewCtrlPtr;
489468fe 1813
5829b303 1814
de40d736 1815 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(GetWXPeer());
e86edab0
RR
1816 wxCHECK_MSG(dataViewCtrlPtr != NULL, false,_("Pointer to data view control not set correctly."));
1817 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,false,_("Pointer to model not set correctly."));
5829b303 1818
e86edab0
RR
1819 // send a drag possible event for each available and item und proceed with it unless the event is vetoed:
1820 ::CountDragItems(dragRef,&noOfDraggedItems);
1821 for (UInt16 indexDraggedItem=1; indexDraggedItem<=noOfDraggedItems; ++indexDraggedItem)
1822 {
1823 // collect native information:
1824 ItemReference itemRef;
1825 wxDataObjectComposite* dataObjects;
1826 wxMemoryBuffer buffer;
8f2a8de6 1827
e86edab0 1828 ::GetDragItemReferenceNumber(dragRef,indexDraggedItem,&itemRef); // the index begins with 1!
de40d736 1829 dataObjects = GetDnDDataObjects(dragRef,itemRef);
e86edab0
RR
1830 // create wxWidget's event:
1831 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE,dataViewCtrlPtr->GetId());
1832
1833 dataViewEvent.SetEventObject(dataViewCtrlPtr);
f5f302d7
DS
1834
1835 // this is the item that receives the event (can be an invalid item ID, this is
1836 // especially useful if the dataview does not contain any items)
1837 dataViewEvent.SetItem( wxDataViewItem(reinterpret_cast<void*>(itemID)) );
1838
e86edab0
RR
1839 dataViewEvent.SetModel(dataViewCtrlPtr->GetModel());
1840 dataViewEvent.SetDataObject(dataObjects);
de40d736 1841 dataViewEvent.SetDataFormat(GetDnDDataFormat(dataObjects));
e86edab0
RR
1842 if (dataViewEvent.GetDataFormat().GetType() != wxDF_INVALID)
1843 {
1844 dataViewEvent.SetDataSize(dataObjects->GetDataSize(dataViewEvent.GetDataFormat().GetType()));
1845 dataObjects->GetDataHere(dataViewEvent.GetDataFormat().GetType(),buffer.GetWriteBuf(dataViewEvent.GetDataSize()));
1846 buffer.UngetWriteBuf(dataViewEvent.GetDataSize());
1847 dataViewEvent.SetDataBuffer(buffer.GetData());
1848 }
489468fe 1849
e86edab0
RR
1850 // send event:
1851 acceptDrag = dataViewCtrlPtr->HandleWindowEvent(dataViewEvent) && dataViewEvent.IsAllowed();
1852 delete dataObjects;
1853 if (!acceptDrag)
1854 return false;
1855 }
1856 return true;
de40d736 1857}
e86edab0
RR
1858
1859Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserAddDragItemProc(DragReference dragRef, DataBrowserItemID itemID, ItemReference* itemRef)
489468fe 1860{
e86edab0
RR
1861 Boolean addDragItem;
1862
1863 wxDataViewCtrl* dataViewCtrlPtr;
8f2a8de6 1864
e86edab0
RR
1865 wxDataViewItem dataViewItem;
1866
1867
de40d736 1868 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(GetWXPeer());
e86edab0
RR
1869 wxCHECK_MSG(dataViewCtrlPtr != NULL, false,_("Pointer to data view control not set correctly."));
1870 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,false,_("Pointer to model not set correctly."));
f5f302d7 1871 dataViewItem = wxDataViewItem(reinterpret_cast<void*>(itemID));
e86edab0
RR
1872 wxCHECK_MSG(dataViewItem.IsOk(),false,_("Invalid data view item"));
1873
1874 // send a begin drag event and proceed with dragging unless the event is vetoed:
1875 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG,dataViewCtrlPtr->GetId());
1876
1877 dataViewEvent.SetEventObject(dataViewCtrlPtr);
1878 dataViewEvent.SetItem(dataViewItem);
1879 dataViewEvent.SetModel(dataViewCtrlPtr->GetModel());
1880 // the dataview event object is also initialized with a default set of data; as it is a set of data and the user should be able to easily complete
1881 // the object a wxDataObjectComposite object is used;
1882 // currently, the composite object only contains a TAB concatenated string of all data:
1883 wxDataObjectComposite* dataObject(new wxDataObjectComposite());
8f2a8de6 1884
e86edab0
RR
1885 dataObject->Add(new wxTextDataObject(::ConcatenateDataViewItemValues(dataViewCtrlPtr,dataViewItem)));
1886 dataViewEvent.SetDataObject(dataObject);
1887 // check if event has not been vetoed:
1888 addDragItem = dataViewCtrlPtr->HandleWindowEvent(dataViewEvent) && dataViewEvent.IsAllowed();
1889 if (addDragItem)
489468fe 1890 {
e86edab0
RR
1891 // for the internal drag & drop functions create two flavors:
1892 // - the data browser's item id;
1893 // - the data contained the dataview event object (if available).
1894 // Definition: a flavor is the type dependent representation of identical data.
1895 // Example: a number can be represented by its value and by its value converted to a string. In this case the flavor
1896 // of the number's internal representation is typeSInt32 while its string representation has got the flavor 'TEXT'.
1897 // Item id is one of the flavors:
1898 wxCHECK_MSG(::AddDragItemFlavor(dragRef,*itemRef,typeUInt32,&itemID,sizeof(itemID),0) == noErr,false,_("Unable to handle native drag&drop data"));
1899 // if the dataview event object contains data it is used for additional flavors; all natively known flavors are supported:
1900 if (dataViewEvent.GetDataObject() != NULL)
1901 {
1902 // constant definition for abbreviational purposes:
1903 size_t const noOfFormats = dataViewEvent.GetDataObject()->GetFormatCount();
8f2a8de6 1904
e86edab0
RR
1905 if (noOfFormats > 0)
1906 {
1907 // variable definition:
1908 wxDataFormat* dataFormats;
8f2a8de6 1909
e86edab0
RR
1910 dataFormats = new wxDataFormat[noOfFormats];
1911 dataViewEvent.GetDataObject()->GetAllFormats(dataFormats,wxDataObject::Get);
1912 for (size_t i=0; i<noOfFormats; ++i)
1913 switch (dataFormats[i].GetType())
1914 {
1915 case wxDF_INVALID:
1916 wxFAIL_MSG(_("Data object has invalid data format"));
1917 break;
1918 case wxDF_TEXT:
1919 {
1920 // constant definition for abbreviational purposes:
1921 size_t const dataSize = dataViewEvent.GetDataObject()->GetDataSize(wxDF_TEXT);
1922 // variable definition and initialization:
1923 wxMemoryBuffer dataObject(dataSize);
8f2a8de6 1924
e86edab0
RR
1925 dataViewEvent.GetDataObject()->GetDataHere(wxDF_TEXT,dataObject.GetWriteBuf(dataSize));
1926 dataObject.UngetWriteBuf(dataSize);
1927 if (::AddDragItemFlavor(dragRef,*itemRef,'TEXT',dataObject.GetData(),dataSize,0) != noErr)
1928 wxFAIL_MSG(_("Adding flavor TEXT failed"));
1929 } /* block */
1930 break;
1931 case wxDF_UNICODETEXT:
1932 {
1933 // constant definition for abbreviational purposes:
1934 size_t const dataSize = dataViewEvent.GetDataObject()->GetDataSize(wxDF_TEXT);
1935 // as there is no direct access to the data copy it to a memory buffer:
1936 wxMemoryBuffer dataObject(dataSize);
8f2a8de6 1937
e86edab0
RR
1938 dataViewEvent.GetDataObject()->GetDataHere(wxDF_TEXT,dataObject.GetWriteBuf(dataSize));
1939 dataObject.UngetWriteBuf(dataSize);
1940 // if the data is stored in unicode format the internal representation is utf-8 (not mentioned in the documentation but in the source code);
1941 // DnD uses fixed utf-16 representation -> use the OSX functions for a conversion:
1942 CFDataRef osxData (::CFDataCreateWithBytesNoCopy(kCFAllocatorDefault,reinterpret_cast<UInt8*>(dataObject.GetData()),dataSize,kCFAllocatorNull));
1943 CFStringRef osxString(::CFStringCreateFromExternalRepresentation(kCFAllocatorDefault,osxData,kCFStringEncodingUTF8));
8f2a8de6 1944
e86edab0
RR
1945 // the osxString contains now the data and therefore the previously occupied memory can be released and re-used:
1946 ::CFRelease(osxData);
1947 osxData = ::CFStringCreateExternalRepresentation(kCFAllocatorDefault,osxString,kCFStringEncodingUTF16,32);
1948 if (::AddDragItemFlavor(dragRef,*itemRef,'utxt',::CFDataGetBytePtr(osxData),::CFDataGetLength(osxData),0) != noErr)
1949 wxFAIL_MSG(_("Adding flavor utxt failed"));
1950 // clean up:
1951 ::CFRelease(osxData);
1952 ::CFRelease(osxString);
1953 } /* block */
1954 break;
1955 case wxDF_BITMAP:
1956 case wxDF_METAFILE:
1957 case wxDF_SYLK:
1958 case wxDF_DIF:
1959 case wxDF_TIFF:
1960 case wxDF_OEMTEXT:
1961 case wxDF_DIB:
1962 case wxDF_PALETTE:
1963 case wxDF_PENDATA:
1964 case wxDF_RIFF:
1965 case wxDF_WAVE:
1966 case wxDF_ENHMETAFILE:
1967 case wxDF_FILENAME:
1968 case wxDF_LOCALE:
1969 case wxDF_PRIVATE:
1970 case wxDF_HTML:
1971 break; // not (yet) supported data formats
1972 default:
1973 wxFAIL_MSG(_("Unknown data format"));
1974 }
1975 delete[] dataFormats;
1976 }
1977 }
489468fe 1978 }
e86edab0
RR
1979 // clean-up and return result:
1980 delete dataObject;
1981 return addDragItem;
de40d736 1982}
489468fe 1983
e86edab0 1984Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserReceiveDragProc(DragReference dragRef, DataBrowserItemID itemID)
489468fe 1985{
e86edab0 1986 UInt16 noOfDraggedItems;
5829b303 1987
e86edab0 1988 wxDataViewCtrl* dataViewCtrlPtr;
489468fe 1989
e86edab0 1990
de40d736 1991 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(GetWXPeer());
e86edab0
RR
1992 wxCHECK_MSG(dataViewCtrlPtr != NULL, false,_("Pointer to data view control not set correctly."));
1993 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,false,_("Pointer to model not set correctly."));
1994
1995 // send a drag possible event for each available and item und proceed with it unless the event is vetoed:
1996 ::CountDragItems(dragRef,&noOfDraggedItems);
1997 for (UInt16 indexDraggedItem=1; indexDraggedItem<=noOfDraggedItems; ++indexDraggedItem)
489468fe 1998 {
e86edab0
RR
1999 bool receiveDrag;
2000 ItemReference itemRef;
2001 wxDataObjectComposite* dataObjects;
2002 wxMemoryBuffer buffer;
8f2a8de6 2003
e86edab0
RR
2004 // collect native information:
2005 ::GetDragItemReferenceNumber(dragRef,indexDraggedItem,&itemRef); // the index begins with 1!
de40d736 2006 dataObjects = GetDnDDataObjects(dragRef,itemRef);
e86edab0
RR
2007 // create wxWidget's event:
2008 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_DROP,dataViewCtrlPtr->GetId());
2009
2010 dataViewEvent.SetEventObject(dataViewCtrlPtr);
f5f302d7
DS
2011
2012 // this is the item that receives the event (can be an invalid item ID, this is
2013 // especially useful if the dataview does not contain any items)
2014 dataViewEvent.SetItem( wxDataViewItem(reinterpret_cast<void*>(itemID)) );
2015
e86edab0
RR
2016 dataViewEvent.SetModel(dataViewCtrlPtr->GetModel());
2017 dataViewEvent.SetDataObject(dataObjects);
de40d736 2018 dataViewEvent.SetDataFormat(GetDnDDataFormat(dataObjects));
e86edab0
RR
2019 if (dataViewEvent.GetDataFormat().GetType() != wxDF_INVALID)
2020 {
2021 dataViewEvent.SetDataSize(dataObjects->GetDataSize(dataViewEvent.GetDataFormat().GetType()));
2022 dataObjects->GetDataHere(dataViewEvent.GetDataFormat().GetType(),buffer.GetWriteBuf(dataViewEvent.GetDataSize()));
2023 buffer.UngetWriteBuf(dataViewEvent.GetDataSize());
2024 dataViewEvent.SetDataBuffer(buffer.GetData());
2025 }
489468fe 2026
e86edab0
RR
2027 // send event:
2028 receiveDrag = dataViewCtrlPtr->HandleWindowEvent(dataViewEvent) && dataViewEvent.IsAllowed();
2029 delete dataObjects;
2030 if (!receiveDrag)
2031 return false;
5829b303 2032 }
e86edab0 2033 return true;
de40d736 2034}
489468fe 2035
e86edab0
RR
2036//
2037// drag & drop helper methods
2038//
2039wxDataFormat wxMacDataViewDataBrowserListViewControl::GetDnDDataFormat(wxDataObjectComposite* dataObjects)
489468fe 2040{
e86edab0 2041 wxDataFormat resultFormat;
489468fe 2042
619df5a4 2043
e86edab0
RR
2044 if (dataObjects != NULL)
2045 {
2046 bool compatible(true);
619df5a4 2047
e86edab0
RR
2048 size_t const noOfFormats = dataObjects->GetFormatCount();
2049 size_t indexFormat;
619df5a4 2050
e86edab0 2051 wxDataFormat* formats;
8f2a8de6 2052
e86edab0
RR
2053 // get all formats and check afterwards if the formats are compatible; if they are compatible the preferred format is returned otherwise
2054 // wxDF_INVALID is returned;
2055 // currently compatible types (ordered by priority are):
2056 // - wxDF_UNICODETEXT - wxDF_TEXT
2057 formats = new wxDataFormat[noOfFormats];
2058 dataObjects->GetAllFormats(formats);
2059 indexFormat = 0;
2060 while ((indexFormat < noOfFormats) && compatible)
619df5a4 2061 {
e86edab0
RR
2062 switch (resultFormat.GetType())
2063 {
2064 case wxDF_INVALID:
2065 resultFormat.SetType(formats[indexFormat].GetType()); // first format (should only be reached if indexFormat == 0
2066 break;
2067 case wxDF_TEXT:
2068 if (formats[indexFormat].GetType() == wxDF_UNICODETEXT)
2069 resultFormat.SetType(wxDF_UNICODETEXT);
2070 else // incompatible
2071 {
2072 resultFormat.SetType(wxDF_INVALID);
2073 compatible = false;
2074 }
2075 break;
2076 case wxDF_UNICODETEXT:
2077 if (formats[indexFormat].GetType() != wxDF_TEXT)
2078 {
2079 resultFormat.SetType(wxDF_INVALID);
2080 compatible = false;
2081 }
2082 break;
2083 default:
2084 resultFormat.SetType(wxDF_INVALID); // not (yet) supported format
2085 compatible = false;
2086 }
2087 ++indexFormat;
2088 } /* while */
2089 // clean up:
2090 delete[] formats;
2091 }
2092 else
2093 resultFormat = wxDF_INVALID;
2094 return resultFormat;
de40d736 2095}
619df5a4 2096
e86edab0 2097wxDataObjectComposite* wxMacDataViewDataBrowserListViewControl::GetDnDDataObjects(DragReference dragRef, ItemReference itemRef) const
489468fe 2098{
e86edab0
RR
2099 UInt16 noOfFlavors;
2100
2101 wxDataObjectComposite* dataObject;
489468fe
SC
2102
2103
e86edab0
RR
2104 ::CountDragItemFlavors(dragRef,itemRef,&noOfFlavors);
2105 if (noOfFlavors > 0)
489468fe 2106 {
e86edab0
RR
2107 // as the native drag data can be separated into TEXT and UTXT a pointer to a wxTextDataObject is used to track the existence of 'TEXT' and 'utxt' flavors:
2108 wxTextDataObject* textDataObject(NULL);
5829b303 2109
e86edab0
RR
2110 dataObject = new wxDataObjectComposite();
2111 for (UInt16 indexFlavor=1; indexFlavor<=noOfFlavors; ++indexFlavor)
489468fe 2112 {
e86edab0
RR
2113 // variable definition:
2114 FlavorType flavorDataObject;
8f2a8de6 2115
e86edab0
RR
2116 if (::GetFlavorType(dragRef,itemRef,indexFlavor,&flavorDataObject) == noErr) // GetFlavorType uses a 1 based index!
2117 switch (flavorDataObject)
2118 {
2119 case 'TEXT':
2120 if (textDataObject == NULL) // otherwise a 'utxt' flavor has already been found that gets priority compared to the 'TEXT' flavor
2121 {
2122 // variable definitions:
2123 Size nativeDataSize;
2124 wxMemoryBuffer nativeData;
8f2a8de6 2125
e86edab0
RR
2126 if ((::GetFlavorDataSize(dragRef,itemRef,'TEXT',&nativeDataSize) == noErr) &&
2127 (::GetFlavorData(dragRef,itemRef,'TEXT',nativeData.GetWriteBuf(nativeDataSize),&nativeDataSize,0) == noErr))
2128 {
2129 nativeData.UngetWriteBuf(nativeDataSize);
2130 textDataObject = new wxTextDataObject();
2131 if (textDataObject->SetData(nativeData.GetDataLen(),nativeData.GetData()))
2132 dataObject->Add(textDataObject);
2133 else
2134 {
5276b0a5 2135 wxDELETE(textDataObject);
e86edab0
RR
2136 }
2137 }
2138 } /* block */
2139 break;
2140 case 'utxt':
2141 {
2142 // variable definition:
2143 Size nativeDataSize;
8f2a8de6 2144
e86edab0
RR
2145 if (::GetFlavorDataSize(dragRef,itemRef,'utxt',&nativeDataSize) == noErr)
2146 {
2147 CFMutableDataRef draggedData;
8f2a8de6 2148
e86edab0
RR
2149 draggedData = ::CFDataCreateMutable(kCFAllocatorDefault,nativeDataSize);
2150 ::CFDataSetLength(draggedData,nativeDataSize);
2151 if (::GetFlavorData(dragRef,itemRef,'utxt',::CFDataGetMutableBytePtr(draggedData),&nativeDataSize,0) == noErr)
2152 {
2153 // convert internally used UTF-16 representation to a UTF-8 representation:
2154 CFDataRef osxData;
2155 CFStringRef osxString;
8f2a8de6 2156
e86edab0
RR
2157 osxString = ::CFStringCreateFromExternalRepresentation(kCFAllocatorDefault,draggedData,kCFStringEncodingUTF16); // BOM character is handled by this function automatically
2158 osxData = ::CFStringCreateExternalRepresentation(kCFAllocatorDefault,osxString,kCFStringEncodingUTF8,32);
2159 if (textDataObject == NULL)
2160 {
2161 textDataObject = new wxTextDataObject();
2162 if (textDataObject->SetData(::CFDataGetLength(osxData),::CFDataGetBytePtr(osxData)))
2163 dataObject->Add(textDataObject);
2164 else
2165 {
5276b0a5 2166 wxDELETE(textDataObject);
e86edab0
RR
2167 }
2168 }
2169 else // overwrite data because the 'utxt' flavor has priority over the 'TEXT' flavor
2170 (void) textDataObject->SetData(::CFDataGetLength(osxData),::CFDataGetBytePtr(osxData));
2171 // clean up:
2172 ::CFRelease(osxData);
2173 ::CFRelease(osxString);
2174 }
2175 // clean up:
2176 ::CFRelease(draggedData);
2177 }
2178 } /* block */
2179 break;
2180 }
5829b303
VZ
2181 }
2182 }
e86edab0
RR
2183 else
2184 dataObject = NULL;
2185 return dataObject;
de40d736 2186}
5829b303 2187
e86edab0
RR
2188//
2189// other methods
2190//
2191wxDataViewColumn* wxMacDataViewDataBrowserListViewControl::GetColumnPtr(DataBrowserPropertyID propertyID) const
2192{
de40d736 2193 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(GetWXPeer()));
8f2a8de6 2194
e86edab0 2195 if (dataViewCtrlPtr != NULL)
489468fe 2196 {
e86edab0 2197 size_t const noOfColumns = dataViewCtrlPtr->GetColumnCount();
8f2a8de6 2198
e86edab0
RR
2199 for (size_t i=0; i<noOfColumns; ++i)
2200 if (dataViewCtrlPtr->GetColumnPtr(i)->GetNativeData()->GetPropertyID() == propertyID)
2201 return dataViewCtrlPtr->GetColumnPtr(i);
489468fe 2202 }
e86edab0 2203 return NULL;
5829b303 2204}
489468fe 2205
e86edab0
RR
2206// ---------------------------------------------------------
2207// wxDataViewRenderer
2208// ---------------------------------------------------------
2209wxDataViewRenderer::wxDataViewRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
2210 :wxDataViewRendererBase(varianttype,mode,align), m_alignment(align), m_mode(mode), m_NativeDataPtr(NULL)
2211{
2212}
2213
de40d736 2214wxDataViewRenderer::~wxDataViewRenderer()
e86edab0 2215{
de40d736 2216 delete m_NativeDataPtr;
e86edab0
RR
2217}
2218
2219void wxDataViewRenderer::SetAlignment(int align)
2220{
de40d736 2221 m_alignment = align;
e86edab0
RR
2222}
2223
c937bcac
VZ
2224namespace
2225{
2226
2227// get the browser control or NULL if anything went wrong (it's not supposed to
2228// so we assert if it did)
2229wxMacDataViewDataBrowserListViewControl *
2230GetBrowserFromCol(wxDataViewColumn *col)
2231{
2232 wxCHECK_MSG( col, NULL, "should have a valid column" );
2233
2234 wxDataViewCtrl * const dvc = col->GetOwner();
2235 wxCHECK_MSG( dvc, NULL, "column must be associated with the control" );
2236
2237 return static_cast<wxMacDataViewDataBrowserListViewControl *>(dvc->GetPeer());
2238}
2239
2240} // anonymous namespace
2241
e86edab0
RR
2242void wxDataViewRenderer::SetMode(wxDataViewCellMode mode)
2243{
c937bcac
VZ
2244 wxDataViewColumn * const col = GetOwner();
2245 wxMacDataViewDataBrowserListViewControl * const
2246 browser = GetBrowserFromCol(col);
2247 wxCHECK_RET( browser, "must be fully initialized" );
e86edab0 2248
c937bcac 2249 const DataBrowserPropertyID colID = col->GetNativeData()->GetPropertyID();
e86edab0 2250
c937bcac
VZ
2251 DataBrowserPropertyFlags flags;
2252 verify_noerr( browser->GetPropertyFlags(colID, &flags) );
2253
2254 if ( (mode == wxDATAVIEW_CELL_EDITABLE) ||
2255 (mode == wxDATAVIEW_CELL_ACTIVATABLE) )
2256 flags |= kDataBrowserPropertyIsEditable;
2257 else
2258 flags &= ~kDataBrowserPropertyIsEditable;
2259
2260 verify_noerr( browser->SetPropertyFlags(colID, flags) );
2261}
2262
2263void wxDataViewRenderer::EnableEllipsize(wxEllipsizeMode mode)
2264{
2265 wxDataViewColumn * const col = GetOwner();
2266
2267 wxMacDataViewDataBrowserListViewControl * const
2268 browser = GetBrowserFromCol(col);
2269 wxCHECK_RET( browser, "must be fully initialized" );
2270
2271 const DataBrowserPropertyID colID = col->GetNativeData()->GetPropertyID();
2272
2273 DataBrowserPropertyFlags flags;
2274 browser->GetPropertyFlags(colID, &flags);
2275
2276 flags &= ~(kDataBrowserDoNotTruncateText |
2277 kDataBrowserTruncateTextAtStart |
2278 kDataBrowserTruncateTextMiddle |
2279 kDataBrowserTruncateTextAtEnd);
e86edab0 2280
c937bcac
VZ
2281 int flagToSet = 0;
2282 switch ( mode )
e86edab0 2283 {
c937bcac
VZ
2284 case wxELLIPSIZE_NONE:
2285 flagToSet = kDataBrowserDoNotTruncateText;
2286 break;
e86edab0 2287
c937bcac
VZ
2288 case wxELLIPSIZE_START:
2289 flagToSet = kDataBrowserTruncateTextAtStart;
2290 break;
2291
2292 case wxELLIPSIZE_MIDDLE:
2293 flagToSet = kDataBrowserTruncateTextMiddle;
2294 break;
2295
2296 case wxELLIPSIZE_END:
2297 flagToSet = kDataBrowserTruncateTextAtEnd;
2298 break;
e86edab0 2299 }
c937bcac
VZ
2300
2301 wxCHECK_RET( flagToSet, "unknown wxEllipsizeMode value" );
2302
2303 flags |= flagToSet;
2304 verify_noerr( browser->SetPropertyFlags(colID, flags) );
2305}
2306
2307wxEllipsizeMode wxDataViewRenderer::GetEllipsizeMode() const
2308{
2309 wxDataViewColumn * const col = GetOwner();
2310
2311 wxMacDataViewDataBrowserListViewControl * const
2312 browser = GetBrowserFromCol(col);
2313 wxCHECK_MSG( browser, wxELLIPSIZE_NONE, "must be fully initialized" );
2314
2315 const DataBrowserPropertyID colID = col->GetNativeData()->GetPropertyID();
2316
2317 DataBrowserPropertyFlags flags;
2318 browser->GetPropertyFlags(colID, &flags);
2319
2320 if ( flags & kDataBrowserDoNotTruncateText )
2321 return wxELLIPSIZE_NONE;
2322 if ( flags & kDataBrowserTruncateTextAtStart )
2323 return wxELLIPSIZE_START;
c937bcac
VZ
2324 if ( flags & kDataBrowserTruncateTextAtEnd )
2325 return wxELLIPSIZE_END;
2326
c32eeacc
VZ
2327 // kDataBrowserTruncateTextMiddle == 0 so there is no need to test for it
2328 return wxELLIPSIZE_MIDDLE;
e86edab0
RR
2329}
2330
2331void wxDataViewRenderer::SetNativeData(wxDataViewRendererNativeData* newNativeDataPtr)
2332{
de40d736
VZ
2333 delete m_NativeDataPtr;
2334 m_NativeDataPtr = newNativeDataPtr;
e86edab0
RR
2335}
2336
2337IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer,wxDataViewRendererBase)
2338
2339// ---------------------------------------------------------
2340// wxDataViewCustomRenderer
2341// ---------------------------------------------------------
2342wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
6eec70b9
VZ
2343 :wxDataViewCustomRendererBase(varianttype,mode,align),
2344 m_editorCtrlPtr(NULL),
2345 m_DCPtr(NULL)
e86edab0 2346{
de40d736 2347 SetNativeData(new wxDataViewRendererNativeData(kDataBrowserCustomType));
e86edab0
RR
2348}
2349
8f2a8de6 2350bool wxDataViewCustomRenderer::MacRender()
e86edab0
RR
2351{
2352 return true;
2353}
489468fe 2354
e86edab0
RR
2355IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
2356
2357// ---------------------------------------------------------
2358// wxDataViewTextRenderer
2359// ---------------------------------------------------------
2360wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
2361 :wxDataViewRenderer(varianttype,mode,align)
2362{
de40d736 2363 SetNativeData(new wxDataViewRendererNativeData(kDataBrowserTextType));
e86edab0 2364}
489468fe 2365
8f2a8de6 2366bool wxDataViewTextRenderer::MacRender()
e86edab0 2367{
de40d736 2368 wxCHECK_MSG(GetValue().GetType() == GetVariantType(),false,wxString(_("Text renderer cannot render value; value type: ")) << GetValue().GetType());
e86edab0 2369
a1b806b9 2370 wxCFStringRef cfString(GetValue().GetString(),(GetView()->GetFont().IsOk() ? GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
de40d736 2371 return (::SetDataBrowserItemDataText(GetNativeData()->GetItemDataRef(),cfString) == noErr);
e86edab0
RR
2372}
2373
2374IMPLEMENT_CLASS(wxDataViewTextRenderer,wxDataViewRenderer)
2375
2376// ---------------------------------------------------------
2377// wxDataViewBitmapRenderer
2378// ---------------------------------------------------------
2379wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
2380 :wxDataViewRenderer(varianttype,mode,align)
2381{
de40d736 2382 SetNativeData(new wxDataViewRendererNativeData(kDataBrowserIconType));
e86edab0
RR
2383}
2384
8f2a8de6 2385bool wxDataViewBitmapRenderer::MacRender()
e86edab0
RR
2386 // This method returns 'true' if
2387 // - the passed bitmap is valid and it could be assigned to the native data browser;
2388 // - the passed bitmap is invalid (or is not initialized); this case simulates a non-existing bitmap.
2389 // In all other cases the method returns 'false'.
2390{
de40d736 2391 wxCHECK_MSG(GetValue().GetType() == GetVariantType(),false,wxString(_("Bitmap renderer cannot render value; value type: ")) << GetValue().GetType());
e86edab0
RR
2392
2393 wxBitmap bitmap;
2394
de40d736 2395 bitmap << GetValue();
a1b806b9 2396 return (!(bitmap.IsOk()) || (::SetDataBrowserItemDataIcon(GetNativeData()->GetItemDataRef(),bitmap.GetIconRef()) == noErr));
e86edab0
RR
2397}
2398
2399IMPLEMENT_CLASS(wxDataViewBitmapRenderer,wxDataViewRenderer)
2400
2401// ---------------------------------------------------------
2402// wxDataViewIconTextRenderer
2403// ---------------------------------------------------------
8f2a8de6
VZ
2404wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
2405 const wxString& varianttype,
2406 wxDataViewCellMode mode,
2407 int WXUNUSED(align))
e86edab0
RR
2408 :wxDataViewRenderer(varianttype,mode)
2409{
de40d736 2410 SetNativeData(new wxDataViewRendererNativeData(kDataBrowserIconAndTextType));
e86edab0
RR
2411}
2412
8f2a8de6 2413bool wxDataViewIconTextRenderer::MacRender()
e86edab0 2414{
de40d736 2415 wxCHECK_MSG(GetValue().GetType() == GetVariantType(),false,wxString(_("Icon & text renderer cannot render value; value type: ")) << GetValue().GetType());
e86edab0
RR
2416
2417 wxDataViewIconText iconText;
2418
de40d736 2419 iconText << GetValue();
e86edab0 2420
a1b806b9 2421 wxCFStringRef cfString(iconText.GetText(),(GetView()->GetFont().IsOk() ? GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
e86edab0
RR
2422
2423 if (iconText.GetIcon().IsOk())
de40d736 2424 if (::SetDataBrowserItemDataIcon(GetNativeData()->GetItemDataRef(),MAC_WXHICON(iconText.GetIcon().GetHICON())) != noErr)
e86edab0 2425 return false;
de40d736 2426 return (::SetDataBrowserItemDataText(GetNativeData()->GetItemDataRef(),cfString) == noErr);
e86edab0
RR
2427}
2428
2429IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer,wxDataViewRenderer)
2430
2431
2432// ---------------------------------------------------------
2433// wxDataViewToggleRenderer
2434// ---------------------------------------------------------
8f2a8de6
VZ
2435wxDataViewToggleRenderer::wxDataViewToggleRenderer(
2436 const wxString& varianttype,
2437 wxDataViewCellMode mode,
2438 int WXUNUSED(align))
e86edab0
RR
2439 :wxDataViewRenderer(varianttype,mode)
2440{
de40d736 2441 SetNativeData(new wxDataViewRendererNativeData(kDataBrowserCheckboxType));
e86edab0
RR
2442}
2443
8f2a8de6 2444bool wxDataViewToggleRenderer::MacRender()
e86edab0 2445{
de40d736
VZ
2446 wxCHECK_MSG(GetValue().GetType() == GetVariantType(),false,wxString(_("Toggle renderer cannot render value; value type: ")) << GetValue().GetType());
2447 return (::SetDataBrowserItemDataButtonValue(GetNativeData()->GetItemDataRef(),GetValue().GetBool()) == noErr);
e86edab0
RR
2448}
2449
2450IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer,wxDataViewRenderer)
2451
2452// ---------------------------------------------------------
2453// wxDataViewProgressRenderer
2454// ---------------------------------------------------------
8f2a8de6
VZ
2455wxDataViewProgressRenderer::wxDataViewProgressRenderer(
2456 const wxString& WXUNUSED(label),
2457 wxString const& varianttype,
2458 wxDataViewCellMode mode,
2459 int align)
e86edab0
RR
2460 :wxDataViewRenderer(varianttype,mode,align)
2461{
de40d736 2462 SetNativeData(new wxDataViewRendererNativeData(kDataBrowserProgressBarType));
e86edab0
RR
2463}
2464
8f2a8de6 2465bool wxDataViewProgressRenderer::MacRender()
e86edab0 2466{
de40d736
VZ
2467 wxCHECK_MSG(GetValue().GetType() == GetVariantType(),false,wxString(_("Progress renderer cannot render value type; value type: ")) << GetValue().GetType());
2468 return ((::SetDataBrowserItemDataMinimum(GetNativeData()->GetItemDataRef(), 0) == noErr) &&
2469 (::SetDataBrowserItemDataMaximum(GetNativeData()->GetItemDataRef(),100) == noErr) &&
2470 (::SetDataBrowserItemDataValue (GetNativeData()->GetItemDataRef(),GetValue().GetLong()) == noErr));
e86edab0
RR
2471}
2472
2473IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer,wxDataViewRenderer)
2474
2475// ---------------------------------------------------------
2476// wxDataViewDateRenderer
2477// ---------------------------------------------------------
2478wxDataViewDateRenderer::wxDataViewDateRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
2479 :wxDataViewRenderer(varianttype,mode,align)
2480{
de40d736 2481 SetNativeData(new wxDataViewRendererNativeData(kDataBrowserDateTimeType));
e86edab0
RR
2482}
2483
8f2a8de6 2484bool wxDataViewDateRenderer::MacRender()
e86edab0 2485{
de40d736
VZ
2486 wxCHECK_MSG(GetValue().GetType() == GetVariantType(),false,wxString(_("Date renderer cannot render value; value type: ")) << GetValue().GetType());
2487 return (::SetDataBrowserItemDataDateTime(GetNativeData()->GetItemDataRef(),GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan,1904)).GetSeconds().GetLo()) == noErr);
e86edab0
RR
2488}
2489
2490IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer,wxDataViewRenderer)
2491
2492// ---------------------------------------------------------
2493// wxDataViewColumn
2494// ---------------------------------------------------------
2495wxDataViewColumn::wxDataViewColumn(const wxString& title, wxDataViewRenderer* renderer, unsigned int model_column, int width, wxAlignment align, int flags)
2496 :wxDataViewColumnBase(renderer, model_column), m_NativeDataPtr(new wxDataViewColumnNativeData()), m_title(title)
2497{
de40d736 2498 InitCommon(width, align, flags);
f8816e49
RD
2499 if ((renderer != NULL) && !renderer->IsCustomRenderer() &&
2500 (renderer->GetAlignment() == wxDVR_DEFAULT_ALIGNMENT))
2501 renderer->SetAlignment(align);
e86edab0
RR
2502}
2503
2504wxDataViewColumn::wxDataViewColumn(const wxBitmap& bitmap, wxDataViewRenderer* renderer, unsigned int model_column, int width, wxAlignment align, int flags)
2505 :wxDataViewColumnBase(bitmap, renderer, model_column), m_NativeDataPtr(new wxDataViewColumnNativeData())
2506{
de40d736 2507 InitCommon(width, align, flags);
f8816e49
RD
2508 if ((renderer != NULL) && !renderer->IsCustomRenderer() &&
2509 (renderer->GetAlignment() == wxDVR_DEFAULT_ALIGNMENT))
2510 renderer->SetAlignment(align);
e86edab0
RR
2511}
2512
de40d736 2513wxDataViewColumn::~wxDataViewColumn()
e86edab0 2514{
de40d736 2515 delete m_NativeDataPtr;
e86edab0
RR
2516}
2517
d831e2db
VZ
2518int wxDataViewColumn::GetWidth() const
2519{
4c51a665 2520 // FIXME: This returns the last programmatically set width and will not work if
d831e2db
VZ
2521 // the user changes the column's width by dragging it with the mouse.
2522 return m_width;
2523}
2524
e86edab0
RR
2525bool wxDataViewColumn::IsSortKey() const
2526{
2527 wxDataViewCtrl * const dataViewCtrlPtr(GetOwner());
2528 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(
2529 dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(
2530 dataViewCtrlPtr->GetPeer()));
2531
2532 DataBrowserPropertyID propertyID;
2533 return (macDataViewListCtrlPtr->GetSortProperty(&propertyID) == noErr) &&
de40d736 2534 (propertyID == GetNativeData()->GetPropertyID());
e86edab0
RR
2535}
2536
2537void wxDataViewColumn::SetAlignment(wxAlignment align)
2538{
de40d736 2539 wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
e86edab0
RR
2540
2541
2542 m_alignment = align;
2543 if (dataViewCtrlPtr != NULL)
2544 {
2545 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
2546
2547 if (macDataViewListCtrlPtr != NULL)
2548 {
2549 DataBrowserListViewHeaderDesc headerDescription;
2550
de40d736 2551 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
e86edab0
RR
2552 switch (align)
2553 {
2554 case wxALIGN_CENTER:
2555 case wxALIGN_CENTER_HORIZONTAL:
2556 headerDescription.btnFontStyle.just = teCenter;
2557 break;
2558 case wxALIGN_LEFT:
2559 headerDescription.btnFontStyle.just = teFlushLeft;
2560 break;
2561 case wxALIGN_RIGHT:
2562 headerDescription.btnFontStyle.just = teFlushRight;
2563 break;
2564 default:
2565 headerDescription.btnFontStyle.just = teFlushDefault;
2566 }
de40d736 2567 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not set alignment."));
e86edab0
RR
2568 }
2569 }
2570}
2571
2572void wxDataViewColumn::SetBitmap(wxBitmap const& bitmap)
2573{
de40d736 2574 wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
e86edab0
RR
2575
2576
2577 wxDataViewColumnBase::SetBitmap(bitmap);
2578 if (dataViewCtrlPtr != NULL)
2579 {
2580 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
2581
2582 if (macDataViewListCtrlPtr != NULL)
2583 {
2584 DataBrowserListViewHeaderDesc headerDescription;
2585
de40d736 2586 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
a1b806b9 2587 if (GetBitmap().IsOk())
de40d736 2588 headerDescription.btnContentInfo.u.iconRef = GetBitmap().GetIconRef();
e86edab0
RR
2589 else
2590 headerDescription.btnContentInfo.u.iconRef = NULL;
de40d736 2591 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not set icon."));
e86edab0
RR
2592 }
2593 }
2594}
2595
2596void wxDataViewColumn::SetMaxWidth(int maxWidth)
2597{
de40d736 2598 wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
e86edab0
RR
2599
2600
2601 m_maxWidth = maxWidth;
2602 if (dataViewCtrlPtr != NULL)
2603 {
2604 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
2605
2606 if (macDataViewListCtrlPtr != NULL)
2607 {
2608 DataBrowserListViewHeaderDesc headerDescription;
2609
de40d736 2610 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
e86edab0 2611 headerDescription.maximumWidth = static_cast<UInt16>(maxWidth);
de40d736 2612 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not set maximum width."));
e86edab0
RR
2613 }
2614 }
2615}
2616
2617void wxDataViewColumn::SetMinWidth(int minWidth)
2618{
de40d736 2619 wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
e86edab0
RR
2620
2621
2622 m_minWidth = minWidth;
2623 if (dataViewCtrlPtr != NULL)
2624 {
2625 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
2626
2627 if (macDataViewListCtrlPtr != NULL)
2628 {
2629 DataBrowserListViewHeaderDesc headerDescription;
2630
de40d736 2631 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
e86edab0 2632 headerDescription.minimumWidth = static_cast<UInt16>(minWidth);
de40d736 2633 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not set minimum width."));
e86edab0
RR
2634 }
2635 }
2636}
2637
2638void wxDataViewColumn::SetReorderable(bool reorderable)
2639{
2640 // first set the internal flag of the column:
2641 if (reorderable)
2642 m_flags |= wxDATAVIEW_COL_REORDERABLE;
2643 else
2644 m_flags &= ~wxDATAVIEW_COL_REORDERABLE;
2645 // if the column is associated with a control change also immediately the flags of the control:
de40d736 2646 wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
e86edab0
RR
2647
2648 if (dataViewCtrlPtr != NULL)
2649 {
2650 DataBrowserPropertyFlags flags;
2651 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
2652
2653 wxCHECK_RET(macDataViewListCtrlPtr != NULL, _("Valid pointer to native data view control does not exist"));
de40d736 2654 wxCHECK_RET(macDataViewListCtrlPtr->GetPropertyFlags(GetNativeData()->GetPropertyID(),&flags) == noErr,_("Could not get property flags."));
e86edab0
RR
2655 if (reorderable)
2656 flags |= kDataBrowserListViewMovableColumn;
2657 else
2658 flags &= ~kDataBrowserListViewMovableColumn;
de40d736 2659 wxCHECK_RET(macDataViewListCtrlPtr->SetPropertyFlags(GetNativeData()->GetPropertyID(),flags) == noErr,_("Could not set property flags."));
e86edab0
RR
2660 }
2661}
2662
d13b34d3 2663void wxDataViewColumn::SetResizeable(bool resizable)
e86edab0
RR
2664{
2665 // first set the internal flag of the column:
d13b34d3 2666 if (resizable)
e86edab0
RR
2667 m_flags |= wxDATAVIEW_COL_RESIZABLE;
2668 else
2669 m_flags &= ~wxDATAVIEW_COL_RESIZABLE;
2670 // if the column is associated with a control change also immediately the flags of the control:
de40d736 2671 wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
e86edab0
RR
2672
2673 if (dataViewCtrlPtr != NULL)
2674 {
2675 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
2676
2677 if (macDataViewListCtrlPtr != NULL)
2678 {
2679 DataBrowserListViewHeaderDesc headerDescription;
2680
de40d736 2681 verify_noerr(macDataViewListCtrlPtr->GetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription));
d13b34d3 2682 if (resizable)
e86edab0 2683 {
de40d736 2684 if (GetMinWidth() >= GetMaxWidth())
e86edab0 2685 {
de40d736
VZ
2686 m_minWidth = 0;
2687 m_maxWidth = 30000;
e86edab0 2688 }
de40d736
VZ
2689 headerDescription.minimumWidth = m_minWidth;
2690 headerDescription.maximumWidth = m_maxWidth;
e86edab0
RR
2691 }
2692 else
2693 {
de40d736
VZ
2694 headerDescription.minimumWidth = m_width;
2695 headerDescription.maximumWidth = m_width;
e86edab0 2696 }
de40d736
VZ
2697 verify_noerr(macDataViewListCtrlPtr->SetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription));
2698 macDataViewListCtrlPtr->SetSortProperty(GetNativeData()->GetPropertyID());
e86edab0
RR
2699 }
2700 }
2701}
2702
2703void wxDataViewColumn::SetSortable(bool sortable)
2704{
2705 // first set the internal flag of the column:
2706 if (sortable)
2707 m_flags |= wxDATAVIEW_COL_SORTABLE;
2708 else
2709 m_flags &= ~wxDATAVIEW_COL_SORTABLE;
2710 // if the column is associated with a control change also immediately the flags of the control:
de40d736 2711 wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
e86edab0
RR
2712
2713 if (dataViewCtrlPtr != NULL)
2714 {
2715 DataBrowserPropertyFlags flags;
2716 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
2717
2718 wxCHECK_RET(macDataViewListCtrlPtr != NULL, _("Valid pointer to native data view control does not exist"));
de40d736 2719 wxCHECK_RET(macDataViewListCtrlPtr->GetPropertyFlags(GetNativeData()->GetPropertyID(),&flags) == noErr,_("Could not get property flags."));
e86edab0
RR
2720 if (sortable)
2721 flags |= kDataBrowserListViewSortableColumn;
2722 else
2723 flags &= ~kDataBrowserListViewSortableColumn;
de40d736 2724 wxCHECK_RET(macDataViewListCtrlPtr->SetPropertyFlags(GetNativeData()->GetPropertyID(),flags) == noErr,_("Could not set property flags."));
e86edab0
RR
2725 }
2726}
2727
2728void wxDataViewColumn::SetSortOrder(bool ascending)
2729{
de40d736 2730 wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
e86edab0
RR
2731
2732
2733 m_ascending = ascending;
2734 if (dataViewCtrlPtr != NULL)
2735 {
2736 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
2737
2738 if (macDataViewListCtrlPtr != NULL)
2739 {
2740 DataBrowserListViewHeaderDesc headerDescription;
2741
de40d736 2742 verify_noerr(macDataViewListCtrlPtr->GetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription));
e86edab0
RR
2743 if (ascending)
2744 headerDescription.initialOrder = kDataBrowserOrderIncreasing;
2745 else
2746 headerDescription.initialOrder = kDataBrowserOrderDecreasing;
de40d736
VZ
2747 verify_noerr(macDataViewListCtrlPtr->SetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription));
2748 macDataViewListCtrlPtr->SetSortProperty(GetNativeData()->GetPropertyID());
e86edab0
RR
2749 }
2750 }
2751}
2752
2753void wxDataViewColumn::SetTitle(wxString const& title)
2754{
de40d736 2755 wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
e86edab0
RR
2756
2757
2758 m_title = title;
2759 if (dataViewCtrlPtr != NULL)
2760 {
2761 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
2762
2763 if (macDataViewListCtrlPtr != NULL)
2764 {
2765 DataBrowserListViewHeaderDesc headerDescription;
a1b806b9 2766 wxCFStringRef cfTitle(title,(dataViewCtrlPtr->GetFont().IsOk() ? dataViewCtrlPtr->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
e86edab0 2767
de40d736 2768 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
e86edab0 2769 headerDescription.titleString = cfTitle;
de40d736 2770 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not set header description."));
e86edab0
RR
2771 }
2772 }
2773}
2774
2775void wxDataViewColumn::SetWidth(int width)
2776{
de40d736 2777 wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
e86edab0 2778
b06ed2f8
VS
2779 switch ( width )
2780 {
2781 case wxCOL_WIDTH_AUTOSIZE:
2782 // not implemented, fall through
2783 case wxCOL_WIDTH_DEFAULT:
2784 width = wxDVC_DEFAULT_WIDTH;
2785 break;
2786 default:
2787 break;
2788 }
e86edab0
RR
2789
2790 if ((width >= m_minWidth) && (width <= m_maxWidth))
2791 {
2792 m_width = width;
2793 if (dataViewCtrlPtr != NULL)
2794 {
2795 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
2796
2797 if (macDataViewListCtrlPtr != NULL)
de40d736 2798 wxCHECK_RET(macDataViewListCtrlPtr->SetColumnWidth(GetNativeData()->GetPropertyID(),static_cast<UInt16>(width)) == noErr,_("Could not set column width."));
e86edab0
RR
2799 }
2800 }
2801}
2802
f6cb92b8
RR
2803void wxDataViewColumn::SetHidden(bool WXUNUSED(hidden))
2804{
2805 // How to do that?
2806}
2807
2808bool wxDataViewColumn::IsHidden() const
2809{
2810 return true;
2811}
2812
2813
e86edab0
RR
2814void wxDataViewColumn::SetNativeData(wxDataViewColumnNativeData* newNativeDataPtr)
2815{
de40d736
VZ
2816 delete m_NativeDataPtr;
2817 m_NativeDataPtr = newNativeDataPtr;
e86edab0 2818}
489468fe 2819
e86edab0 2820#endif // wxUSE_DATAVIEWCTRL && !wxUSE_GENERICDATAVIEWCTRL