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