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