1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/dataview.cpp
3 // Purpose: wxDataViewCtrl native carbon implementation
5 // Id: $Id: dataview.cpp 58317 2009-01-23
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if (wxUSE_DATAVIEWCTRL == 1) && !defined(wxUSE_GENERICDATAVIEWCTRL)
17 #include "wx/toplevel.h"
19 #include "wx/settings.h"
23 #include "wx/osx/carbon/dataview.h"
24 #include "wx/osx/private.h"
25 #include "wx/osx/uma.h"
26 #include "wx/renderer.h"
30 // ============================================================================
31 // Variables used locally in dataview.cpp
32 // ============================================================================
33 static DataBrowserGetContextualMenuUPP gDataBrowserTableViewGetContextualMenuUPP
= NULL
;
34 static DataBrowserItemCompareUPP gDataBrowserTableViewItemCompareUPP
= NULL
;
35 static DataBrowserItemDataUPP gDataBrowserTableViewItemDataUPP
= NULL
;
36 static DataBrowserItemNotificationUPP gDataBrowserTableViewItemNotificationUPP
= NULL
;
38 static DataBrowserAcceptDragUPP gDataBrowserTableViewAcceptDragUPP
= NULL
;
39 static DataBrowserAddDragItemUPP gDataBrowserTableViewAddDragItemUPP
= NULL
;
40 static DataBrowserReceiveDragUPP gDataBrowserTableViewReceiveDragUPP
= NULL
;
42 static DataBrowserDrawItemUPP gDataBrowserTableViewDrawItemUPP
= NULL
;
43 static DataBrowserEditItemUPP gDataBrowserTableViewEditItemUPP
= NULL
;
44 static DataBrowserHitTestUPP gDataBrowserTableViewHitTestUPP
= NULL
;
45 static DataBrowserTrackingUPP gDataBrowserTableViewTrackingUPP
= NULL
;
47 // ============================================================================
48 // Functions used locally in dataview.cpp
49 // ============================================================================
50 static DataBrowserItemID
* CreateDataBrowserItemIDArray(size_t& noOfEntries
, wxDataViewItemArray
const& items
) // returns a newly allocated pointer to valid data browser item IDs
52 size_t const noOfItems
= items
.GetCount();
54 DataBrowserItemID
* itemIDs(new DataBrowserItemID
[noOfItems
]);
57 // convert all valid data view items to data browser items
59 for (size_t i
=0; i
<noOfItems
; ++i
)
62 itemIDs
[noOfEntries
] = reinterpret_cast<DataBrowserItemID
>(items
[i
].GetID());
69 static const EventTypeSpec eventList
[] =
71 { kEventClassControl
, kEventControlHit
},
72 { kEventClassControl
, kEventControlDraw
}
75 static pascal OSStatus
DataBrowserCtrlEventHandler(EventHandlerCallRef handler
, EventRef EventReference
, void* Data
)
77 wxDataViewCtrl
* DataViewCtrlPtr((wxDataViewCtrl
*) Data
); // the 'Data' variable always contains a pointer to the data view control that installed the handler
79 wxMacCarbonEvent
CarbonEvent(EventReference
) ;
82 switch (GetEventKind(EventReference
))
84 case kEventControlDraw
:
88 DataViewCtrlPtr
->MacSetDrawingContext(CarbonEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
,typeCGContextRef
));
89 status
= ::CallNextEventHandler(handler
,EventReference
);
90 DataViewCtrlPtr
->MacSetDrawingContext(NULL
);
93 case kEventControlHit
:
94 if (CarbonEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
,typeControlPartCode
) == kControlButtonPart
) // we only care about the header
96 ControlRef controlReference
;
97 DataBrowserPropertyID columnPropertyID
;
98 DataBrowserSortOrder order
;
99 unsigned long columnIndex
;
100 wxDataViewColumn
* column
;
102 wxDataViewEvent
DataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
,DataViewCtrlPtr
->GetId());
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
);
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
);
117 // initialize wxWidget event handler:
118 DataViewEvent
.SetEventObject(DataViewCtrlPtr
);
119 DataViewEvent
.SetColumn(columnIndex
);
120 DataViewEvent
.SetDataViewColumn(column
);
121 // finally sent the equivalent wxWidget event:
122 DataViewCtrlPtr
->HandleWindowEvent(DataViewEvent
);
123 return ::CallNextEventHandler(handler
,EventReference
);
126 return eventNotHandledErr
;
128 return eventNotHandledErr
;
131 static bool InitializeColumnDescription(DataBrowserListViewColumnDesc
& columnDescription
, wxDataViewColumn
const* columnPtr
, wxCFStringRef
const& title
)
133 // set properties for the column:
134 columnDescription
.propertyDesc
.propertyID
= columnPtr
->GetNativeData()->GetPropertyID();
135 columnDescription
.propertyDesc
.propertyType
= columnPtr
->GetRenderer()->GetNativeData()->GetPropertyType();
136 columnDescription
.propertyDesc
.propertyFlags
= kDataBrowserListViewSelectionColumn
; // make the column selectable
137 if (columnPtr
->IsReorderable())
138 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewMovableColumn
;
139 if (columnPtr
->IsResizeable())
141 columnDescription
.headerBtnDesc
.minimumWidth
= 0;
142 columnDescription
.headerBtnDesc
.maximumWidth
= 30000; // 32767 is the theoretical maximum though but 30000 looks nicer
146 columnDescription
.headerBtnDesc
.minimumWidth
= columnPtr
->GetWidth();
147 columnDescription
.headerBtnDesc
.maximumWidth
= columnPtr
->GetWidth();
149 if (columnPtr
->IsSortable())
150 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewSortableColumn
;
151 if ((columnPtr
->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE
) ||
152 (columnPtr
->GetRenderer()->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
))
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
;
162 // set header's properties:
163 columnDescription
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
164 columnDescription
.headerBtnDesc
.titleOffset
= 0;
165 columnDescription
.headerBtnDesc
.titleString
= ::CFStringCreateCopy(kCFAllocatorDefault
,title
);
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())
171 case wxALIGN_CENTER_HORIZONTAL
:
172 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teCenter
;
175 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushLeft
;
178 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushRight
;
181 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
183 columnDescription
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
184 columnDescription
.headerBtnDesc
.btnFontStyle
.style
= normal
;
185 if (columnPtr
->GetBitmap().IsOk())
187 columnDescription
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
188 columnDescription
.headerBtnDesc
.btnContentInfo
.u
.iconRef
= columnPtr
->GetBitmap().GetIconRef();
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
;
202 // ============================================================================
203 // Type definitions of locally used function pointers
204 // ============================================================================
205 DEFINE_ONE_SHOT_HANDLER_GETTER(DataBrowserCtrlEventHandler
)
207 // ============================================================================
208 // Helper functions for dataview implementation on OSX
209 // ============================================================================
210 wxWidgetImplType
* CreateDataView(wxWindowMac
* wxpeer
, wxWindowMac
* WXUNUSED(parent
), wxWindowID
WXUNUSED(id
), wxPoint
const& pos
, wxSize
const& size
,
211 long style
, long WXUNUSED(extraStyle
))
213 return new wxMacDataViewDataBrowserListViewControl(wxpeer
,pos
,size
,style
);
216 // ============================================================================
217 // wxMacDataBrowserTableViewControl
218 // ============================================================================
219 pascal Boolean
wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlRef browser
, DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
)
221 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
224 if (ControlPtr
!= NULL
)
225 return ControlPtr
->DataBrowserCompareProc(itemOneID
,itemTwoID
,sortProperty
);
227 return errDataBrowserPropertyNotSupported
;
228 } /* wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlRef, DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
230 pascal void wxMacDataBrowserTableViewControl::DataBrowserGetContextualMenuProc(ControlRef browser
, MenuRef
* menu
, UInt32
* helpType
, CFStringRef
* helpItemString
, AEDesc
* selection
)
232 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
235 if (ControlPtr
!= NULL
)
236 ControlPtr
->DataBrowserGetContextualMenuProc(menu
,helpType
,helpItemString
,selection
);
237 } /* wxMacDataBrowserTableViewControl::DataBrowserGetContextualMenuProc(ControlRef, MenuRef*, UInt32*, CFStringRef*, AEDesc*) */
239 pascal OSStatus
wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemDataRef itemData
, Boolean getValue
)
241 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
244 if (ControlPtr
!= NULL
)
245 return ControlPtr
->DataBrowserGetSetItemDataProc(itemID
,propertyID
,itemData
,getValue
);
247 return errDataBrowserPropertyNotSupported
;
248 } /* wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */
250 pascal void wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
)
252 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
255 if (ControlPtr
!= NULL
)
256 ControlPtr
->DataBrowserItemNotificationProc(itemID
,message
,itemData
);
257 } /* wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc(ControlRef, DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */
259 pascal void wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
)
261 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
264 if (ControlPtr
!= NULL
)
265 ControlPtr
->DataBrowserDrawItemProc(itemID
,propertyID
,state
,rectangle
,bitDepth
,colorDevice
);
266 } /* wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */
268 pascal Boolean
wxMacDataBrowserTableViewControl::DataBrowserEditItemProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, CFStringRef theString
, Rect
* maxEditTextRect
, Boolean
* shrinkToFit
)
270 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
273 return ((ControlPtr
!= NULL
) && ControlPtr
->DataBrowserEditItemProc(itemID
,propertyID
,theString
,maxEditTextRect
,shrinkToFit
));
274 } /* wxMacDataBrowserTableViewControl::DataBrowserEditItemProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, CFStringRef, Rect*, Boolean*) */
276 pascal Boolean
wxMacDataBrowserTableViewControl::DataBrowserHitTestProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Rect
const* mouseRect
)
278 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
281 return ((ControlPtr
!= NULL
) && ControlPtr
->DataBrowserHitTestProc(itemID
,propertyID
,theRect
,mouseRect
));
282 } /* wxMacDataBrowserTableViewControl::DataBrowserHitTestProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, Rect const*, Rect const*) */
284 pascal DataBrowserTrackingResult
wxMacDataBrowserTableViewControl::DataBrowserTrackingProc(ControlRef browser
, DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Point startPt
, EventModifiers modifiers
)
286 wxMacDataBrowserTableViewControl
* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
289 if (ControlPtr
!= NULL
)
290 return ControlPtr
->DataBrowserTrackingProc(itemID
,propertyID
,theRect
,startPt
,modifiers
);
292 return kDataBrowserNothingHit
;
293 } /* wxMacDataBrowserTableViewControl::DataBrowserTrackingProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, Rect const*, Point, EventModifiers) */
295 pascal Boolean
wxMacDataBrowserTableViewControl::DataBrowserAcceptDragProc(ControlRef browser
, DragReference dragRef
, DataBrowserItemID itemID
)
297 wxMacDataBrowserTableViewControl
* controlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
300 return ((controlPtr
!= NULL
) && controlPtr
->DataBrowserAcceptDragProc(dragRef
,itemID
));
301 } /* wxMacDataBrowserTableViewControl::DataBrowserAcceptDragProc(ControlRef, DragReference, DataBrowserItemID) */
303 pascal Boolean
wxMacDataBrowserTableViewControl::DataBrowserAddDragItemProc(ControlRef browser
, DragReference dragRef
, DataBrowserItemID itemID
, ItemReference
* itemRef
)
305 wxMacDataBrowserTableViewControl
* controlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
308 return ((controlPtr
!= NULL
) && controlPtr
->DataBrowserAddDragItemProc(dragRef
,itemID
,itemRef
));
309 } /* wxMacDataBrowserTableViewControl::DataBrowserAddDragItemProc(ControlRef, DragReference, DataBrowserItemID, ItemReference*) */
311 pascal Boolean
wxMacDataBrowserTableViewControl::DataBrowserReceiveDragProc(ControlRef browser
, DragReference dragRef
, DataBrowserItemID itemID
)
313 wxMacDataBrowserTableViewControl
* controlPtr(dynamic_cast<wxMacDataBrowserTableViewControl
*>(wxMacControl::GetReferenceFromNativeControl(browser
)));
316 return ((controlPtr
!= NULL
) && controlPtr
->DataBrowserReceiveDragProc(dragRef
,itemID
));
317 } /* wxMacDataBrowserTableViewControl::DataBrowserReceiveDragProc(ControlRef, DragReference, DataBrowserItemID) */
319 wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow
* peer
, wxPoint
const& pos
, wxSize
const& size
, long style
)
322 Rect bounds
= wxMacGetBoundsForControl(peer
,pos
,size
);
323 OSStatus err
= ::CreateDataBrowserControl(MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),&bounds
,kDataBrowserListView
,&(this->m_controlRef
));
326 SetReferenceInNativeControl();
329 ::InstallControlEventHandler(this->m_controlRef
, GetDataBrowserCtrlEventHandlerUPP(), GetEventTypeCount(eventList
), eventList
, peer
, (EventHandlerRef
*)&m_macDataViewCtrlEventHandler
);
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
)
337 gDataBrowserTableViewItemNotificationUPP
=
338 #if TARGET_API_MAC_OSX
339 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc
);
341 NewDataBrowserItemNotificationUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc
);
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
);
349 DataBrowserCallbacks callbacks
; // variable definition
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
);
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
);
367 DataBrowserCustomCallbacks customCallbacks
; // variable definition
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
);
377 this->EnableCellSizeModification( ((style
& wxDV_VARIABLE_LINE_HEIGHT
) != 0), true );
379 DataBrowserSelectionFlags flags
; // variable definition
381 if (this->GetSelectionFlags(&flags
) == noErr
) // get default settings
383 if ((style
& wxDV_MULTIPLE
) != 0)
384 flags
&= ~kDataBrowserSelectOnlyOne
;
386 flags
|= kDataBrowserSelectOnlyOne
;
387 (void) this->SetSelectionFlags(flags
);
390 OptionBits attributes
; // variable definition
392 if (this->GetAttributes(&attributes
) == noErr
) // get default settings
394 if ((style
& wxDV_VERT_RULES
) != 0)
395 attributes
|= kDataBrowserAttributeListViewDrawColumnDividers
;
397 attributes
&= ~kDataBrowserAttributeListViewDrawColumnDividers
;
398 if ((style
& wxDV_ROW_LINES
) != 0)
399 attributes
|= kDataBrowserAttributeListViewAlternatingRowColors
;
401 attributes
&= ~kDataBrowserAttributeListViewAlternatingRowColors
;
402 (void) this->SetAttributes(attributes
);
405 if ((style
& wxDV_NO_HEADER
) != 0)
406 this->SetHeaderButtonHeight(0);
407 } /* wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow*, wxPoint const&, wxSize const&, long) */
409 wxMacDataBrowserTableViewControl::~wxMacDataBrowserTableViewControl(void)
411 ::RemoveEventHandler((EventHandlerRef
) m_macDataViewCtrlEventHandler
);
412 } /* wxMacDataBrowserTableViewControl::~wxMacDataBrowserTableViewControl(void) */
417 OSStatus
wxMacDataBrowserTableViewControl::SetCallbacks(DataBrowserCallbacks
const* callbacks
)
419 return ::SetDataBrowserCallbacks(this->m_controlRef
,callbacks
);
420 } /* wxMacDataBrowserTableViewControl::SetCallbacks(DataBrowserCallbacks const*) */
422 OSStatus
wxMacDataBrowserTableViewControl::SetCustomCallbacks(DataBrowserCustomCallbacks
const* customCallbacks
)
424 return ::SetDataBrowserCustomCallbacks(this->m_controlRef
,customCallbacks
);
425 } /* xMacDataBrowserTableViewControl::SetCustomCallbacks(DataBrowserCustomCallbacks const*) */
430 OSStatus
wxMacDataBrowserTableViewControl::EnableAutomaticDragTracking(bool enable
)
432 return ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(this->m_controlRef
),enable
);
438 OSStatus
wxMacDataBrowserTableViewControl::GetHeaderDesc(DataBrowserPropertyID propertyID
, DataBrowserListViewHeaderDesc
* desc
) const
440 desc
->version
= kDataBrowserListViewLatestHeaderDesc
; // if this statement is missing the next call will fail (NOT DOCUMENTED!!)
441 return ::GetDataBrowserListViewHeaderDesc(this->m_controlRef
,propertyID
,desc
);
444 OSStatus
wxMacDataBrowserTableViewControl::SetHeaderDesc(DataBrowserPropertyID propertyID
, DataBrowserListViewHeaderDesc
* desc
)
446 return ::SetDataBrowserListViewHeaderDesc(this->m_controlRef
,propertyID
,desc
);
452 OSStatus
wxMacDataBrowserTableViewControl::AutoSizeColumns()
454 return AutoSizeDataBrowserListViewColumns(this->m_controlRef
);
457 OSStatus
wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool enableHeight
, bool enableWidth
)
459 return ::SetDataBrowserTableViewGeometry(this->GetControlRef(),enableWidth
,enableHeight
);
460 } /* wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool, bool) */
462 OSStatus
wxMacDataBrowserTableViewControl::GetAttributes(OptionBits
* attributes
)
464 return ::DataBrowserGetAttributes(this->GetControlRef(),attributes
);
465 } /* wxMacDataBrowserTableViewControl::GetAttributes(OptionBits*) */
467 OSStatus
wxMacDataBrowserTableViewControl::GetColumnWidth(DataBrowserPropertyID propertyID
, UInt16
* width
) const
469 return ::GetDataBrowserTableViewNamedColumnWidth(this->m_controlRef
,propertyID
,width
);
472 OSStatus
wxMacDataBrowserTableViewControl::GetDefaultColumnWidth( UInt16
*width
) const
474 return GetDataBrowserTableViewColumnWidth(this->m_controlRef
, width
);
477 OSStatus
wxMacDataBrowserTableViewControl::GetDefaultRowHeight(UInt16
* height
) const
479 return ::GetDataBrowserTableViewRowHeight(this->m_controlRef
,height
);
482 OSStatus
wxMacDataBrowserTableViewControl::GetHeaderButtonHeight(UInt16
*height
)
484 return ::GetDataBrowserListViewHeaderBtnHeight(this->m_controlRef
,height
);
487 OSStatus
wxMacDataBrowserTableViewControl::GetPartBounds(DataBrowserItemID item
, DataBrowserPropertyID propertyID
, DataBrowserPropertyPart part
, Rect
* bounds
)
489 return ::GetDataBrowserItemPartBounds(this->m_controlRef
,item
,propertyID
,part
,bounds
);
490 } /* wxMacDataBrowserTableViewControl::GetPartBounds(DataBrowserItemID, DataBrowswerPropertyID, DataBrowserPropertyPart, Rect*) */
492 OSStatus
wxMacDataBrowserTableViewControl::GetRowHeight(DataBrowserItemID item
, UInt16
* height
) const
494 return ::GetDataBrowserTableViewItemRowHeight(this->m_controlRef
,item
,height
);
495 } /* wxMacDataBrowserTableViewControl::GetRowHeight(DataBrowserItemID, UInt16*) const */
497 OSStatus
wxMacDataBrowserTableViewControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
499 return GetDataBrowserScrollPosition(this->m_controlRef
, top
, left
);
502 OSStatus
wxMacDataBrowserTableViewControl::SetAttributes(OptionBits attributes
)
504 return ::DataBrowserChangeAttributes(this->GetControlRef(),attributes
,~attributes
);
505 } /* wxMacDataBrowserTableViewControl::SetAttributes(OptionBits) */
507 OSStatus
wxMacDataBrowserTableViewControl::SetColumnWidth(DataBrowserPropertyID propertyID
, UInt16 width
)
509 return ::SetDataBrowserTableViewNamedColumnWidth(this->m_controlRef
,propertyID
,width
);
512 OSStatus
wxMacDataBrowserTableViewControl::SetDefaultColumnWidth(UInt16 width
)
514 return ::SetDataBrowserTableViewColumnWidth(this->m_controlRef
,width
);
517 OSStatus
wxMacDataBrowserTableViewControl::SetDefaultRowHeight(UInt16 height
)
519 return ::SetDataBrowserTableViewRowHeight(this->m_controlRef
,height
);
522 OSStatus
wxMacDataBrowserTableViewControl::SetHasScrollBars(bool horiz
, bool vert
)
524 return ::SetDataBrowserHasScrollBars(this->m_controlRef
,horiz
,vert
);
525 } /* wxMacDataBrowserTableViewControl::SetHasScrollBars(bool, bool) */
527 OSStatus
wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16 height
)
529 return ::SetDataBrowserListViewHeaderBtnHeight(this->m_controlRef
,height
);
530 } /* wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16) */
532 OSStatus
wxMacDataBrowserTableViewControl::SetHiliteStyle(DataBrowserTableViewHiliteStyle hiliteStyle
)
534 return ::SetDataBrowserTableViewHiliteStyle(this->m_controlRef
,hiliteStyle
);
535 } /*wxMacDataBrowserTableViewControl::SetHiliteStyle(DataBrowserTableViewHiliteStyle) */
537 OSStatus
wxMacDataBrowserTableViewControl::SetIndent(float Indent
)
539 return ::DataBrowserSetMetric(this->m_controlRef
,kDataBrowserMetricDisclosureColumnPerDepthGap
,true,Indent
);
540 } /* wxMacDataBrowserTableViewControl::SetIndent(float* Indent) */
542 OSStatus
wxMacDataBrowserTableViewControl::SetItemRowHeight(DataBrowserItemID item
, UInt16 height
)
544 return ::SetDataBrowserTableViewItemRowHeight(this->m_controlRef
,item
,height
);
547 OSStatus
wxMacDataBrowserTableViewControl::SetScrollPosition(UInt32 top
, UInt32 left
)
549 return ::SetDataBrowserScrollPosition(this->m_controlRef
,top
,left
);
555 OSStatus
wxMacDataBrowserTableViewControl::GetColumnCount(UInt32
* numColumns
) const
557 return ::GetDataBrowserTableViewColumnCount(this->m_controlRef
,numColumns
);
560 OSStatus
wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID propertyID
, DataBrowserTableViewColumnIndex
* index
) const
562 return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef
,propertyID
,index
);
563 } /* wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex*) const */
565 OSStatus
wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID
* propertyID
) const
567 for (*propertyID
=kMinPropertyID
; *propertyID
<std::numeric_limits
<DataBrowserPropertyID
>::max(); ++(*propertyID
))
568 if (this->IsUsedPropertyID(*propertyID
) == errDataBrowserPropertyNotFound
)
570 return errDataBrowserPropertyNotSupported
;
571 } /* wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID*) const */
573 OSStatus
wxMacDataBrowserTableViewControl::GetPropertyFlags(DataBrowserPropertyID propertyID
, DataBrowserPropertyFlags
*flags
) const
575 return ::GetDataBrowserPropertyFlags(this->m_controlRef
,propertyID
,flags
);
578 OSStatus
wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef itemData
, DataBrowserPropertyID
* propertyID
) const
580 return ::GetDataBrowserItemDataProperty(itemData
,propertyID
);
581 } /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef, DataBrowserPropertyID*) */
583 OSStatus
wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex index
, DataBrowserTableViewColumnID
* propertyID
) const
585 return ::GetDataBrowserTableViewColumnProperty(this->m_controlRef
,index
,propertyID
);
586 } /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex, DataBrowserTableViewColumnID*) */
588 OSStatus
wxMacDataBrowserTableViewControl::IsUsedPropertyID(DataBrowserPropertyID propertyID
) const
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
;
595 return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef
,propertyID
,&index
);
596 } /* wxMacDataBrowserTableViewControl::IsUsedPropertyId(DataBrowserPropertyID) const */
598 OSStatus
wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID propertyID
)
600 return ::RemoveDataBrowserTableViewColumn(this->m_controlRef
,propertyID
);
601 } /* wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID) */
603 OSStatus
wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex index
)
605 DataBrowserTableViewColumnID propertyID
;
608 this->GetPropertyID(index
,&propertyID
);
609 return ::RemoveDataBrowserTableViewColumn(this->m_controlRef
,propertyID
);
610 } /* wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex) */
612 OSStatus
wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID propertyID
, DataBrowserTableViewColumnIndex index
)
614 return ::SetDataBrowserTableViewColumnPosition(this->m_controlRef
,propertyID
,index
);
615 } /* wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex) */
617 OSStatus
wxMacDataBrowserTableViewControl::SetDisclosureColumn(DataBrowserPropertyID propertyID
, Boolean expandableRows
)
619 return ::SetDataBrowserListViewDisclosureColumn(this->m_controlRef
,propertyID
,expandableRows
);
622 OSStatus
wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID propertyID
, DataBrowserPropertyFlags flags
)
624 return ::SetDataBrowserPropertyFlags(this->m_controlRef
,propertyID
,flags
);
625 } /* wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID, DataBrowserPropertyFlags) */
630 OSStatus
wxMacDataBrowserTableViewControl::AddItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
)
632 return ::AddDataBrowserItems(this->m_controlRef
,container
,numItems
,items
,preSortProperty
);
633 } /* wxMacDataBrowserTableViewControl::AddItems(DataBrowserItemID, UInt32, DataBrowserItemID const*, DataBrowserPropertyID) */
635 OSStatus
wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID
* id
) const
642 status
= this->GetItemCount(&noOfItems
);
643 wxCHECK_MSG(status
== noErr
,status
,_("Could not retrieve number of items"));
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
)
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
)
660 // sorry, data browser is full:
661 return errDataBrowserItemNotAdded
;
663 } /* wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID*) const */
665 OSStatus
wxMacDataBrowserTableViewControl::GetItemCount(DataBrowserItemID container
, Boolean recurse
, DataBrowserItemState state
, ItemCount
* numItems
) const
667 return GetDataBrowserItemCount(this->m_controlRef
,container
,recurse
,state
,numItems
);
668 } /* wxMacDataBrowserTableViewControl::GetItemCount(DataBrowserItemID, Boolean, DataBrowserItemState, ItemCount*) const */
670 OSStatus
wxMacDataBrowserTableViewControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
672 return GetDataBrowserTableViewItemID(this->m_controlRef
,row
,item
);
675 OSStatus
wxMacDataBrowserTableViewControl::GetItems(DataBrowserItemID container
, Boolean recurse
, DataBrowserItemState state
, Handle items
) const
677 return GetDataBrowserItems(this->m_controlRef
,container
,recurse
,state
,items
);
678 } /* wxMacDataBrowserTableViewControl::GetItems(DataBrowserItemID, Boolean, DataBrowserItemState, Handle) const */
680 OSStatus
wxMacDataBrowserTableViewControl::GetItemRow(DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
682 return GetDataBrowserTableViewItemRow(this->m_controlRef
,item
,row
);
685 OSStatus
wxMacDataBrowserTableViewControl::GetItemState(DataBrowserItemID item
, DataBrowserItemState
* state
) const
687 return ::GetDataBrowserItemState(this->m_controlRef
,item
,state
);
690 OSStatus
wxMacDataBrowserTableViewControl::IsUsedItemID(DataBrowserItemID itemID
) const
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
;
697 return ::GetDataBrowserTableViewItemRow(this->m_controlRef
,itemID
,&index
);
698 } /* wxMacDataBrowserTableViewControl::IsUsedItemID(DataBrowserItemID) const */
700 OSStatus
wxMacDataBrowserTableViewControl::RemoveItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
)
702 return ::RemoveDataBrowserItems(this->m_controlRef
,container
,numItems
,items
,preSortProperty
);
705 OSStatus
wxMacDataBrowserTableViewControl::RevealItem(DataBrowserItemID item
, DataBrowserPropertyID propertyID
, DataBrowserRevealOptions options
) const
707 return ::RevealDataBrowserItem(this->m_controlRef
,item
,propertyID
,options
);
708 } /* wxMacDataBrowserTableViewControl::RevealItem(DataBrowserItemID item, DataBrowserPropertyID propertyID, DataBrowserRevealOptions options) const */
710 OSStatus
wxMacDataBrowserTableViewControl::UpdateItems(DataBrowserItemID container
, UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserPropertyID preSortProperty
,
711 DataBrowserPropertyID propertyID
) const
713 return UpdateDataBrowserItems(this->m_controlRef
,container
,numItems
,items
,preSortProperty
,propertyID
);
719 size_t wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserItemID
& itemIDs
) const
721 DataBrowserItemID
* itemIDPtr
;
722 Handle
handle(::NewHandle(0));
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
));
730 itemIDs
.Alloc(noOfItems
);
732 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
733 for (size_t i
=0; i
<noOfItems
; ++i
)
735 itemIDs
.Add(*itemIDPtr
);
739 DisposeHandle(handle
);
741 } /* wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserItemID&) const*/
743 OSStatus
wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID
* first
, DataBrowserItemID
* last
) const
745 return ::GetDataBrowserSelectionAnchor(this->m_controlRef
,first
,last
);
746 } /* wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID*, DataBrowserItemID*) const */
748 OSStatus
wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags
* flags
) const
750 return ::GetDataBrowserSelectionFlags(this->m_controlRef
,flags
);
751 } /* wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags*) const */
753 bool wxMacDataBrowserTableViewControl::IsItemSelected(DataBrowserItemID item
) const
755 return ::IsDataBrowserItemSelected(this->m_controlRef
,item
);
756 } /* wxMacDataBrowserTableViewControl::IsItemSelected(DataBrowserItemID) const */
758 OSStatus
wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectionFlags flags
)
760 return ::SetDataBrowserSelectionFlags(this->m_controlRef
,flags
);
761 } /* wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectionFlags) */
763 OSStatus
wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32 numItems
, DataBrowserItemID
const* items
, DataBrowserSetOption operation
)
765 return ::SetDataBrowserSelectedItems(this->m_controlRef
, numItems
, items
, operation
);
766 } /* wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32, DataBrowserItemID const*, DataBrowserSetOption) */
768 OSStatus
wxMacDataBrowserTableViewControl::GetSortOrder(DataBrowserSortOrder
* order
) const
770 return ::GetDataBrowserSortOrder(this->m_controlRef
,order
);
773 OSStatus
wxMacDataBrowserTableViewControl::GetSortProperty(DataBrowserPropertyID
* propertyID
) const
775 return ::GetDataBrowserSortProperty(this->m_controlRef
,propertyID
);
778 OSStatus
wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID container
, Boolean sortChildren
)
780 return ::SortDataBrowserContainer(this->m_controlRef
,container
,sortChildren
);
781 } /* wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID, Boolean) */
783 OSStatus
wxMacDataBrowserTableViewControl::SetSortOrder(DataBrowserSortOrder order
)
785 return ::SetDataBrowserSortOrder(this->m_controlRef
,order
);
788 OSStatus
wxMacDataBrowserTableViewControl::SetSortProperty(DataBrowserPropertyID propertyID
)
790 return ::SetDataBrowserSortProperty(this->m_controlRef
,propertyID
);
794 // container handling
796 OSStatus
wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID containerID
)
798 return ::CloseDataBrowserContainer(this->m_controlRef
,containerID
);
799 } /* wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID) */
801 OSStatus
wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID containerID
)
803 return ::OpenDataBrowserContainer(this->m_controlRef
,containerID
);
804 } /* wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID) */
806 IMPLEMENT_ABSTRACT_CLASS(wxMacDataBrowserTableViewControl
,wxMacControl
)
808 // ============================================================================
809 // wxMacDataBrowserListViewControl
810 // ============================================================================
815 OSStatus
wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc
*columnDesc
, DataBrowserTableViewColumnIndex position
)
817 return AddDataBrowserListViewColumn(this->m_controlRef
,columnDesc
,position
);
818 } /* wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc*, DataBrowserTableViewColumnIndex) */
820 // ============================================================================
821 // wxMacDataViewDataBrowserListViewControl
822 // ============================================================================
825 // constructors / destructor
827 wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl(wxWindow
* peer
, wxPoint
const& pos
, wxSize
const& size
, long style
)
828 :wxMacDataBrowserListViewControl(peer
,pos
,size
,style
)
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) */
837 // column related methods (inherited from wxDataViewWidgetImpl)
839 bool wxMacDataViewDataBrowserListViewControl::ClearColumns(void)
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."));
850 bool wxMacDataViewDataBrowserListViewControl::DeleteColumn(wxDataViewColumn
* columnPtr
)
852 return (this->RemoveColumnByProperty(columnPtr
->GetNativeData()->GetPropertyID()) == noErr
);
855 void wxMacDataViewDataBrowserListViewControl::DoSetExpanderColumn(wxDataViewColumn
const* columnPtr
)
857 this->SetDisclosureColumn(columnPtr
->GetNativeData()->GetPropertyID(),false); // second parameter explicitely passed to ensure that arrow is centered
860 wxDataViewColumn
* wxMacDataViewDataBrowserListViewControl::GetColumn(unsigned int pos
) const
862 DataBrowserPropertyID propertyID
;
865 if (this->GetPropertyID(pos
,&propertyID
) == noErr
)
866 return this->GetColumnPtr(propertyID
);
871 int wxMacDataViewDataBrowserListViewControl::GetColumnPosition(wxDataViewColumn
const* columnPtr
) const
873 if (columnPtr
!= NULL
)
875 DataBrowserTableViewColumnIndex Position
;
877 wxCHECK_MSG(this->GetColumnIndex(columnPtr
->GetNativeData()->GetPropertyID(),&Position
) == noErr
,wxNOT_FOUND
,_("Could not determine column's position"));
878 return static_cast<int>(Position
);
884 bool wxMacDataViewDataBrowserListViewControl::InsertColumn(unsigned int pos
, wxDataViewColumn
* columnPtr
)
886 DataBrowserListViewColumnDesc columnDescription
;
888 DataBrowserPropertyID newPropertyID
;
892 wxCFStringRef
title(columnPtr
->GetTitle(),m_font
.Ok() ? dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer())->GetFont().GetEncoding() : wxLocale::GetSystemEncoding());
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."));
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)
906 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer()));
908 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,false,_("wxWidget's control not initialized."));
909 dataViewCtrlPtr
->AddChildren(wxDataViewItem());
913 return this->Update(columnPtr
);
917 // item related methods (inherited from wxDataViewWidgetImpl)
919 bool wxMacDataViewDataBrowserListViewControl::Add(wxDataViewItem
const& parent
, wxDataViewItem
const& item
)
921 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
924 return (( parent
.IsOk() && this->AddItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
) == noErr
) ||
925 (!(parent
.IsOk()) && this->AddItem(kDataBrowserNoItem
,&itemID
) == noErr
));
928 bool wxMacDataViewDataBrowserListViewControl::Add(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
932 DataBrowserItemID
* itemIDs
;
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:
946 return noFailureFlag
;
949 void wxMacDataViewDataBrowserListViewControl::Collapse(wxDataViewItem
const& item
)
951 this->CloseContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
954 void wxMacDataViewDataBrowserListViewControl::EnsureVisible(wxDataViewItem
const& item
, const wxDataViewColumn
* columnPtr
)
956 DataBrowserPropertyID propertyID
;
959 if (columnPtr
!= NULL
)
960 propertyID
= columnPtr
->GetNativeData()->GetPropertyID();
962 propertyID
= kDataBrowserNoItem
;
963 this->RevealItem(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),propertyID
,kDataBrowserRevealOnly
);
966 void wxMacDataViewDataBrowserListViewControl::Expand(wxDataViewItem
const& item
)
968 this->OpenContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
971 unsigned int wxMacDataViewDataBrowserListViewControl::GetCount(void) const
976 wxCHECK_MSG(this->GetItemCount(&noOfItems
) == noErr
,0,_("Could not determine number of items"));
980 wxRect
wxMacDataViewDataBrowserListViewControl::GetRectangle(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
)
985 if (this->GetPartBounds(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),columnPtr
->GetNativeData()->GetPropertyID(),kDataBrowserPropertyContentPart
,&MacRectangle
) == noErr
)
989 ::wxMacNativeToRect(&MacRectangle
,&rectangle
);
996 bool wxMacDataViewDataBrowserListViewControl::IsExpanded(wxDataViewItem
const& item
) const
998 DataBrowserItemState state
;
1001 return ((this->GetItemState(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),&state
) == noErr
) &&
1002 (state
& kDataBrowserContainerIsOpen
!= 0));
1005 bool wxMacDataViewDataBrowserListViewControl::Reload(void)
1009 wxDataViewItemArray dataViewChildren
;
1012 noFailureFlag
= (this->RemoveItems() == noErr
);
1013 this->SetScrollPosition(0,0); // even after having removed all items the scrollbars may remain at their old position -> reset them
1014 this->GetDataViewCtrl()->GetModel()->GetChildren(wxDataViewItem(),dataViewChildren
);
1015 this->GetDataViewCtrl()->GetModel()->ItemsAdded(wxDataViewItem(),dataViewChildren
);
1017 return noFailureFlag
;
1020 bool wxMacDataViewDataBrowserListViewControl::Remove(wxDataViewItem
const& parent
, wxDataViewItem
const& item
)
1022 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1025 return (this->RemoveItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
) == noErr
);
1028 bool wxMacDataViewDataBrowserListViewControl::Remove(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
1032 DataBrowserItemID
* itemIDs
;
1037 // convert all valid data view items to data browser items:
1038 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
1039 // insert all valid items into control:
1040 noFailureFlag
= ((noOfEntries
== 0) ||
1041 !(parent
.IsOk()) && (this->RemoveItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
) ||
1042 parent
.IsOk() && (this->RemoveItems(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
));
1043 // give allocated array space free again:
1046 return noFailureFlag
;
1049 bool wxMacDataViewDataBrowserListViewControl::Update(wxDataViewColumn
const* columnPtr
)
1051 return (this->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,columnPtr
->GetNativeData()->GetPropertyID()) == noErr
);
1054 bool wxMacDataViewDataBrowserListViewControl::Update(wxDataViewItem
const& parent
, wxDataViewItem
const& item
)
1056 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1060 return (this->UpdateItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
) == noErr
);
1062 return (this->UpdateItem(kDataBrowserNoItem
,&itemID
) == noErr
);
1065 bool wxMacDataViewDataBrowserListViewControl::Update(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
1069 DataBrowserItemID
* itemIDs
;
1074 // convert all valid data view items to data browser items:
1075 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
1077 noFailureFlag
= (this->UpdateItems(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
,kDataBrowserItemNoProperty
) == noErr
);
1079 noFailureFlag
= (this->UpdateItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
,kDataBrowserItemNoProperty
) == noErr
);
1080 // release allocated array space:
1083 return noFailureFlag
;
1087 // model related methods
1089 bool wxMacDataViewDataBrowserListViewControl::AssociateModel(wxDataViewModel
* WXUNUSED(model
))
1095 // selection related methods (inherited from wxDataViewWidgetImpl)
1097 int wxMacDataViewDataBrowserListViewControl::GetSelections(wxDataViewItemArray
& sel
) const
1099 size_t noOfSelectedItems
;
1101 wxArrayDataBrowserItemID itemIDs
;
1104 noOfSelectedItems
= this->GetSelectedItemIDs(itemIDs
);
1106 sel
.SetCount(noOfSelectedItems
);
1107 for (size_t i
=0; i
<noOfSelectedItems
; ++i
)
1108 sel
[i
] = wxDataViewItem(reinterpret_cast<void*>(itemIDs
[i
]));
1109 return static_cast<int>(noOfSelectedItems
);
1112 bool wxMacDataViewDataBrowserListViewControl::IsSelected(wxDataViewItem
const& item
) const
1114 return this->IsItemSelected(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1117 void wxMacDataViewDataBrowserListViewControl::Select(wxDataViewItem
const& item
)
1119 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1122 this->SetSelectedItems(1,&itemID
,kDataBrowserItemsAdd
);
1125 void wxMacDataViewDataBrowserListViewControl::SelectAll(void)
1127 DataBrowserItemID
* itemIDPtr
;
1129 Handle
handle(::NewHandle(0));
1134 wxCHECK_RET(this->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1135 noOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1137 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1138 this->SetSelectedItems(noOfItems
,itemIDPtr
,kDataBrowserItemsAssign
);
1140 ::DisposeHandle(handle
);
1143 void wxMacDataViewDataBrowserListViewControl::Unselect(wxDataViewItem
const& item
)
1145 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1148 this->SetSelectedItems(1,&itemID
,kDataBrowserItemsRemove
);
1151 void wxMacDataViewDataBrowserListViewControl::UnselectAll(void)
1153 DataBrowserItemID
* itemIDPtr
;
1155 Handle
handle(::NewHandle(0));
1160 wxCHECK_RET(this->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1161 noOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1163 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1164 this->SetSelectedItems(noOfItems
,itemIDPtr
,kDataBrowserItemsRemove
);
1166 ::DisposeHandle(handle
);
1170 // sorting related methods
1172 wxDataViewColumn
* wxMacDataViewDataBrowserListViewControl::GetSortingColumn(void) const
1174 DataBrowserPropertyID propertyID
;
1177 if (this->GetSortProperty(&propertyID
) == noErr
)
1178 return this->GetColumnPtr(propertyID
);
1183 void wxMacDataViewDataBrowserListViewControl::Resort(void)
1185 (void) this->Resort();
1189 // other methods (inherited from wxDataViewWidgetImpl)
1191 void wxMacDataViewDataBrowserListViewControl::HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const
1193 // not yet implemented:
1194 item
= wxDataViewItem();
1198 void wxMacDataViewDataBrowserListViewControl::DoSetIndent(int indent
)
1200 this->SetIndent(static_cast<float>(indent
));
1203 void wxMacDataViewDataBrowserListViewControl::SetRowHeight(wxDataViewItem
const& item
, unsigned int height
)
1205 this->SetItemRowHeight(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),static_cast<UInt16
>(height
));
1208 void wxMacDataViewDataBrowserListViewControl::OnSize(void)
1213 this->GetColumnCount(&noOfColumns
);
1214 if (noOfColumns
<= 1) // no horizontal scroll bar and the only column expands to the width of the whole control
1216 this->SetHasScrollBars(false,true);
1217 this->AutoSizeColumns();
1219 else // otherwise keep the current column size and have scrollbars in both directions
1220 this->SetHasScrollBars(true,true);
1224 // callback functions (inherited from wxMacDataBrowserTableViewControl)
1226 Boolean
wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID itemOneID
, DataBrowserItemID itemTwoID
, DataBrowserPropertyID sortProperty
)
1228 DataBrowserSortOrder sortOrder
;
1230 DataBrowserTableViewColumnIndex modelColumnIndex
;
1232 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer()));
1235 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Pointer to data view control not set correctly."));
1236 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,false,_("Pointer to model not set correctly."));
1237 if (sortProperty
>= kMinPropertyID
)
1239 // variable definition and initialization:
1240 wxDataViewColumn
* ColumnPtr(this->GetColumnPtr(sortProperty
));
1242 wxCHECK_MSG(ColumnPtr
!= NULL
,false,_("Could not determine column index."));
1243 modelColumnIndex
= ColumnPtr
->GetModelColumn();
1246 modelColumnIndex
= 0;
1247 this->GetSortOrder(&sortOrder
);
1248 return static_cast<Boolean
>(dataViewCtrlPtr
->GetModel()->Compare(wxDataViewItem(reinterpret_cast<void*>(itemOneID
)),wxDataViewItem(reinterpret_cast<void*>(itemTwoID
)),
1249 modelColumnIndex
,sortOrder
!= kDataBrowserOrderDecreasing
) < 0);
1250 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
1252 void wxMacDataViewDataBrowserListViewControl::DataBrowserGetContextualMenuProc(MenuRef
* menu
, UInt32
* helpType
, CFStringRef
* helpItemString
, AEDesc
* WXUNUSED(selection
))
1253 // In this method we do not supply a contextual menu handler at all but only send a wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU.
1255 wxArrayDataBrowserItemID itemIDs
;
1257 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer()));
1260 wxCHECK_RET(dataViewCtrlPtr
!= NULL
,_("wxWidget control pointer is not a data view pointer"));
1261 // initialize parameters so that no context menu will be displayed automatically by the native data browser:
1263 *helpType
= kCMHelpItemNoHelp
;
1264 *helpItemString
= NULL
;
1265 // create information for a context menu event:
1266 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
,dataViewCtrlPtr
->GetId());
1268 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
1269 dataViewEvent
.SetModel(dataViewCtrlPtr
->GetModel());
1270 // get the item information;
1271 // 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:
1272 if (this->GetSelectedItemIDs(itemIDs
) > 0)
1273 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemIDs
[0])));
1274 // finally send the equivalent wxWidget event:
1275 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
1276 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetContextualMenuProc(MenuRef*, UInt32*, CFStringRef*, AEDesc*) */
1278 OSStatus
wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemDataRef itemData
, Boolean getValue
)
1282 // variable definitions:
1283 wxDataViewCtrl
* dataViewCtrlPtr
;
1285 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer());
1286 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
1287 if (dataViewCtrlPtr
->IsDeleting())
1288 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
1291 // variable definitions:
1292 OSStatus errorStatus
;
1293 wxDataViewColumn
* dataViewColumnPtr
;
1295 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,errDataBrowserNotConfigured
,_("Pointer to model not set correctly."));
1296 dataViewColumnPtr
= this->GetColumnPtr(propertyID
);
1297 wxCHECK_MSG((dataViewColumnPtr
!= NULL
) && (dataViewColumnPtr
->GetRenderer() != NULL
),errDataBrowserNotConfigured
,_("There is no column or renderer for the specified column index."));
1299 wxDataViewItem
dvItem(reinterpret_cast<void*>(itemID
));
1300 unsigned int col
= dataViewColumnPtr
->GetModelColumn();
1302 switch (dataViewColumnPtr
->GetRenderer()->GetNativeData()->GetPropertyType())
1304 case kDataBrowserCheckboxType
:
1306 // variable definition:
1307 ThemeButtonValue buttonValue
;
1309 errorStatus
= ::GetDataBrowserItemDataButtonValue(itemData
,&buttonValue
);
1310 if (errorStatus
== noErr
)
1312 if (buttonValue
== kThemeButtonOn
)
1314 // variable definition and initialization:
1315 wxVariant
modifiedData(true);
1317 if (dataViewCtrlPtr
->GetModel()->SetValue(modifiedData
, dvItem
, col
) &&
1318 dataViewCtrlPtr
->GetModel()->ValueChanged(dvItem
, col
))
1321 return errDataBrowserInvalidPropertyData
;
1323 else if (buttonValue
== kThemeButtonOff
)
1325 // variable definition and initialization:
1326 wxVariant
modifiedData(false);
1328 if (dataViewCtrlPtr
->GetModel()->SetValue(modifiedData
, dvItem
, col
) &&
1329 dataViewCtrlPtr
->GetModel()->ValueChanged(dvItem
, col
))
1332 return errDataBrowserInvalidPropertyData
;
1335 return errDataBrowserInvalidPropertyData
;
1340 case kDataBrowserTextType
:
1342 // variable definitions:
1343 CFStringRef stringReference
;
1345 errorStatus
= ::GetDataBrowserItemDataText(itemData
,&stringReference
);
1346 if (errorStatus
== noErr
)
1348 // variable definitions and initializations:
1349 #if wxCHECK_VERSION(2,9,0)
1350 wxCFStringRef
modifiedString(stringReference
);
1352 wxMacCFStringHolder
modifiedString(stringReference
);
1354 wxVariant
modifiedData(modifiedString
.AsString());
1356 if (dataViewCtrlPtr
->GetModel()->SetValue(modifiedData
, dvItem
, col
) &&
1357 dataViewCtrlPtr
->GetModel()->ValueChanged(dvItem
, col
))
1360 return errDataBrowserInvalidPropertyData
;
1366 return errDataBrowserPropertyNotSupported
;
1372 if (propertyID
>= kMinPropertyID
) // in case data columns set the data
1374 // variable definitions:
1376 wxDataViewColumn
* dataViewColumnPtr
;
1377 wxDataViewCtrl
* dataViewCtrlPtr
;
1379 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer());
1380 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
1381 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,errDataBrowserNotConfigured
,_("Pointer to model not set correctly."));
1382 dataViewColumnPtr
= this->GetColumnPtr(propertyID
);
1383 wxCHECK_MSG(dataViewColumnPtr
!= NULL
,errDataBrowserNotConfigured
,_("No column for the specified column position existing."));
1384 wxCHECK_MSG(dataViewColumnPtr
->GetRenderer() != NULL
,errDataBrowserNotConfigured
,_("No renderer specified for column."));
1385 dataViewCtrlPtr
->GetModel()->GetValue(variant
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),dataViewColumnPtr
->GetModelColumn());
1386 if (!(variant
.IsNull()))
1388 dataViewColumnPtr
->GetRenderer()->GetNativeData()->SetItemDataRef(itemData
);
1389 dataViewColumnPtr
->GetRenderer()->SetValue(variant
);
1390 wxCHECK_MSG(dataViewColumnPtr
->GetRenderer()->Render(),errDataBrowserNotConfigured
,_("Rendering failed."));
1394 else // react on special system requests
1398 case kDataBrowserContainerIsClosableProperty
:
1400 // variable definitions:
1401 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer()));
1403 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
1404 // initialize wxWidget event:
1405 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
,dataViewCtrlPtr
->GetId()); // variable definition
1407 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
1408 dataViewEvent
.SetItem (wxDataViewItem(reinterpret_cast<void*>(itemID
)));
1409 dataViewEvent
.SetModel (dataViewCtrlPtr
->GetModel());
1410 // finally send the equivalent wxWidget event:
1411 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
1412 // opening the container is allowed if not vetoed:
1413 return ::SetDataBrowserItemDataBooleanValue(itemData
,dataViewEvent
.IsAllowed());
1415 case kDataBrowserContainerIsOpenableProperty
:
1417 // variable definitions:
1418 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer()));
1420 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
1421 // initialize wxWidget event:
1422 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
,dataViewCtrlPtr
->GetId()); // variable definition
1424 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
1425 dataViewEvent
.SetItem (wxDataViewItem(reinterpret_cast<void*>(itemID
)));
1426 dataViewEvent
.SetModel (dataViewCtrlPtr
->GetModel());
1427 // finally send the equivalent wxWidget event:
1428 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
1429 // opening the container is allowed if not vetoed:
1430 return ::SetDataBrowserItemDataBooleanValue(itemData
,dataViewEvent
.IsAllowed());
1432 case kDataBrowserItemIsContainerProperty
:
1434 // variable definition:
1435 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer()));
1437 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,errDataBrowserNotConfigured
,_("Pointer to data view control not set correctly."));
1438 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,errDataBrowserNotConfigured
,_("Pointer to model not set correctly."));
1439 return ::SetDataBrowserItemDataBooleanValue(itemData
,dataViewCtrlPtr
->GetModel()->IsContainer(wxDataViewItem(reinterpret_cast<void*>(itemID
))));
1441 case kDataBrowserItemIsEditableProperty
:
1442 return ::SetDataBrowserItemDataBooleanValue(itemData
,true);
1446 return errDataBrowserPropertyNotSupported
;
1447 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */
1449 void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID itemID
, DataBrowserItemNotification message
, DataBrowserItemDataRef itemData
)
1451 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer()));
1454 // 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:
1455 if (dataViewCtrlPtr
!= NULL
)
1458 case kDataBrowserContainerClosed
:
1459 dataViewCtrlPtr
->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
1461 // initialize wxWidget event:
1462 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
,dataViewCtrlPtr
->GetId()); // variable definition
1464 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
1465 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
1466 // finally send the equivalent wxWidget event:
1467 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
1470 case kDataBrowserContainerOpened
:
1471 dataViewCtrlPtr
->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
1473 // initialize wxWidget event:
1474 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
,dataViewCtrlPtr
->GetId()); // variable definition
1476 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
1477 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
1478 // finally send the equivalent wxWidget event:
1479 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
1480 // add children to the expanded container:
1481 dataViewCtrlPtr
->AddChildren(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
1484 case kDataBrowserEditStarted
:
1485 dataViewCtrlPtr
->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
1487 // initialize wxWidget event:
1488 DataBrowserPropertyID propertyID
;
1489 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
,dataViewCtrlPtr
->GetId()); // variable definition
1491 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
1492 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
1493 if (this->GetPropertyID(itemData
,&propertyID
) == noErr
)
1495 // variable definition and initialization:
1496 DataBrowserTableViewColumnIndex columnIndex
;
1498 wxCHECK_RET(this->GetColumnIndex(propertyID
,&columnIndex
),_("Column index not found."));
1499 dataViewEvent
.SetColumn(columnIndex
);
1500 dataViewEvent
.SetDataViewColumn(this->GetColumnPtr(propertyID
));
1502 // finally send the equivalent wxWidget event:
1503 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
1506 case kDataBrowserEditStopped
:
1508 // initialize wxWidget event:
1509 DataBrowserPropertyID propertyID
;
1510 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
,dataViewCtrlPtr
->GetId()); // variable definition
1512 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
1513 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
1514 if (this->GetPropertyID(itemData
,&propertyID
) == noErr
)
1516 // variable definition and initialization:
1517 DataBrowserTableViewColumnIndex columnIndex
;
1519 wxCHECK_RET(this->GetColumnIndex(propertyID
,&columnIndex
),_("Column index not found."));
1520 dataViewEvent
.SetColumn(columnIndex
);
1521 dataViewEvent
.SetDataViewColumn(this->GetColumnPtr(propertyID
));
1523 // finally send the equivalent wxWidget event:
1524 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
1527 case kDataBrowserItemAdded
:
1528 dataViewCtrlPtr
->FinishCustomItemEditing();
1530 case kDataBrowserItemDeselected
:
1531 dataViewCtrlPtr
->FinishCustomItemEditing();
1533 case kDataBrowserItemDoubleClicked
:
1535 // initialize wxWidget event:
1536 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
,dataViewCtrlPtr
->GetId()); // variable definition
1538 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
1539 dataViewEvent
.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID
)));
1540 // finally send the equivalent wxWidget event:
1541 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
1544 case kDataBrowserItemRemoved
:
1545 dataViewCtrlPtr
->FinishCustomItemEditing(); // stop editing of a custom item first (if necessary)
1547 case kDataBrowserItemSelected
:
1548 break; // not implemented by wxWidgets; see kDataBrowserSelectionSetChanged
1549 case kDataBrowserSelectionSetChanged
:
1551 // initialize wxWidget event:
1552 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
,dataViewCtrlPtr
->GetId()); // variable definition
1554 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
1555 dataViewEvent
.SetModel (dataViewCtrlPtr
->GetModel());
1556 // finally send the equivalent wxWidget event:
1557 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
1560 case kDataBrowserTargetChanged
: // no idea if this notification is ever sent
1562 case kDataBrowserUserStateChanged
:
1564 // finish custom item editing if necessary:
1565 dataViewCtrlPtr
->FinishCustomItemEditing();
1566 // update column widths:
1567 for (size_t i
=0; i
<dataViewCtrlPtr
->GetColumnCount(); ++i
)
1569 // constant definition for abbreviational purposes:
1570 wxDataViewColumn
* const columnPtr
= dataViewCtrlPtr
->GetColumnPtr(i
);
1571 // variable definition:
1574 wxCHECK_RET(this->GetColumnWidth(columnPtr
->GetNativeData()->GetPropertyID(),&columnWidth
) == noErr
,_("Column width could not be determined"));
1575 columnPtr
->SetWidthVariable(columnWidth
);
1577 // update sorting orders:
1578 DataBrowserPropertyID propertyID
; // variable definition
1580 if ((this->GetSortProperty(&propertyID
) == noErr
) && (propertyID
>= kMinPropertyID
))
1582 DataBrowserSortOrder sortOrder
;
1583 DataBrowserTableViewColumnIndex columnIndex
;
1585 if ((this->GetSortOrder(&sortOrder
) == noErr
) && (this->GetColumnIndex(propertyID
,&columnIndex
) == noErr
))
1587 // variable definition and initialization:
1588 wxDataViewColumn
* columnPtr
;
1589 columnPtr
= dataViewCtrlPtr
->GetColumn(columnIndex
);
1590 // check if the sort order has changed:
1591 if ( columnPtr
->IsSortOrderAscending() && (sortOrder
== kDataBrowserOrderDecreasing
) ||
1592 !(columnPtr
->IsSortOrderAscending()) && (sortOrder
== kDataBrowserOrderIncreasing
))
1594 columnPtr
->SetSortOrder(!(columnPtr
->IsSortOrderAscending()));
1595 // initialize wxWidget event:
1596 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
,dataViewCtrlPtr
->GetId()); // variable defintion
1598 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
1599 dataViewEvent
.SetColumn(columnIndex
);
1600 dataViewEvent
.SetDataViewColumn(columnPtr
);
1601 // finally send the equivalent wxWidget event:
1602 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
1609 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */
1611 void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, DataBrowserItemState state
, Rect
const* rectangle
, SInt16 bitDepth
, Boolean colorDevice
)
1613 DataBrowserTableViewColumnIndex columnIndex
;
1615 wxDataViewColumn
* dataViewColumnPtr
;
1617 wxDataViewCtrl
* dataViewCtrlPtr
;
1619 wxDataViewCustomRenderer
* dataViewCustomRendererPtr
;
1621 wxVariant dataToRender
;
1623 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer());
1624 wxCHECK_RET(dataViewCtrlPtr
!= NULL
, _("Pointer to data view control not set correctly."));
1625 wxCHECK_RET(dataViewCtrlPtr
->GetModel() != NULL
, _("Pointer to model not set correctly."));
1626 wxCHECK_RET(this->GetColumnIndex(propertyID
,&columnIndex
) == noErr
,_("Could not determine column index."));
1627 dataViewColumnPtr
= this->GetColumnPtr(propertyID
);
1628 wxCHECK_RET(dataViewColumnPtr
!= NULL
,_("No column for the specified column existing."));
1629 dataViewCustomRendererPtr
= dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer());
1630 wxCHECK_RET(dataViewCustomRendererPtr
!= NULL
,_("No renderer or invalid renderer type specified for custom data column."));
1631 dataViewCtrlPtr
->GetModel()->GetValue(dataToRender
,wxDataViewItem(reinterpret_cast<void*>(itemID
)),dataViewColumnPtr
->GetModelColumn());
1632 dataViewCustomRendererPtr
->SetValue(dataToRender
);
1634 wxDataViewItem
dataItem( reinterpret_cast<void*>(itemID
) );
1635 dataViewCtrlPtr
->GetModel()->GetValue(dataToRender
,dataItem
,dataViewColumnPtr
->GetModelColumn());
1636 dataViewCustomRendererPtr
->SetValue(dataToRender
);
1638 // try to determine the content's size (drawable part):
1640 RgnHandle
rgn(NewRgn());
1641 UInt16 headerHeight
;
1643 if (GetControlRegion(m_controlRef
,kControlContentMetaPart
,rgn
) == noErr
)
1644 GetRegionBounds(rgn
,&content
);
1646 GetControlBounds(m_controlRef
, &content
);
1648 // space for the header
1649 this->GetHeaderButtonHeight(&headerHeight
);
1650 content
.top
+= headerHeight
;
1651 // extra space for the frame (todo: do not how to determine the space automatically from the control)
1655 content
.bottom
-= 3;
1656 // extra space for the scrollbars:
1657 content
.bottom
-= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
1658 content
.right
-= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1660 wxDC
*dc
= dataViewCustomRendererPtr
->GetDC();
1662 int active_border_fudge
= 0;
1663 if (dataViewCtrlPtr
->HasFocus() && !dataViewCtrlPtr
->HasFlag( wxBORDER_NONE
))
1664 active_border_fudge
= 1;
1666 active_border_fudge
= -2;
1668 wxRect
cellrect( static_cast<int>(rectangle
->left
+ active_border_fudge
),
1669 static_cast<int>(rectangle
->top
+ active_border_fudge
),
1670 static_cast<int>(1+rectangle
->right
-rectangle
->left
),
1671 static_cast<int>(rectangle
->bottom
-rectangle
->top
) );
1673 bool is_active
= IsControlActive( this->m_controlRef
);
1674 if (state
== kDataBrowserItemIsSelected
)
1677 wxColour
col( wxMacCreateCGColorFromHITheme( (is_active
) ?
1678 kThemeBrushAlternatePrimaryHighlightColor
1679 : kThemeBrushSecondaryHighlightColor
) );
1681 wxRect rect
= cellrect
;
1683 GetDataBrowserItemPartBounds( this->m_controlRef
, itemID
, propertyID
,
1684 kDataBrowserPropertyEnclosingPart
, &itemrect
);
1685 rect
.x
= itemrect
.left
-2;
1686 rect
.width
= itemrect
.right
-itemrect
.left
+3;
1688 wxBrush
selBrush( col
);
1689 wxPen
oldpen( dc
->GetPen() );
1690 wxBrush
oldbrush( dc
->GetBrush() );
1691 dc
->SetPen( *wxTRANSPARENT_PEN
);
1692 dc
->SetBrush( selBrush
);
1693 dc
->DrawRectangle(rect
);
1694 dc
->SetBrush( oldbrush
);
1695 dc
->SetPen( oldpen
);
1698 wxDataViewModel
*model
= dataViewCtrlPtr
->GetModel();
1699 if ((columnIndex
== 0) || !model
->IsContainer(dataItem
) || model
->HasContainerColumns(dataItem
))
1701 // make sure that 'Render' can draw only in the allowed area:
1702 dc
->SetClippingRegion(content
.left
,content
.top
,content
.right
-content
.left
+1,content
.bottom
-content
.top
+1);
1703 (void) (dataViewCustomRendererPtr
->Render( cellrect
, dc
,
1704 ((state
== kDataBrowserItemIsSelected
) ? wxDATAVIEW_CELL_SELECTED
: 0)));
1705 dc
->DestroyClippingRegion(); // probably not necessary
1708 dataViewCustomRendererPtr
->SetDC(NULL
);
1709 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */
1711 Boolean
wxMacDataViewDataBrowserListViewControl::DataBrowserEditItemProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, CFStringRef theString
, Rect
* maxEditTextRect
, Boolean
* shrinkToFit
)
1714 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserEditItemProc(DataBrowserItemID, DataBrowserPropertyID, CFStringRef, Rect*, Boolean*) */
1716 Boolean
wxMacDataViewDataBrowserListViewControl::DataBrowserHitTestProc(DataBrowserItemID
WXUNUSED(itemID
), DataBrowserPropertyID
WXUNUSED(property
), Rect
const* WXUNUSED(theRect
), Rect
const* WXUNUSED(mouseRect
))
1719 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserHitTestProc(DataBrowserItemID, DataBrowserPropertyID, Rect const*, Rect const*) */
1721 DataBrowserTrackingResult
wxMacDataViewDataBrowserListViewControl::DataBrowserTrackingProc(DataBrowserItemID itemID
, DataBrowserPropertyID propertyID
, Rect
const* theRect
, Point
WXUNUSED(startPt
), EventModifiers
WXUNUSED(modifiers
))
1723 wxDataViewColumn
* dataViewColumnPtr
;
1725 wxDataViewCtrl
* dataViewCtrlPtr
;
1727 wxDataViewCustomRenderer
* dataViewCustomRendererPtr
;
1729 wxDataViewItem dataViewCustomRendererItem
;
1732 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer());
1733 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Pointer to data view control not set correctly."));
1734 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,false,_("Pointer to model not set correctly."));
1735 dataViewCustomRendererItem
= reinterpret_cast<void*>(itemID
);
1736 wxCHECK_MSG(dataViewCustomRendererItem
.IsOk(),kDataBrowserNothingHit
,_("Invalid data view item"));
1737 dataViewColumnPtr
= this->GetColumnPtr(propertyID
);
1738 wxCHECK_MSG(dataViewColumnPtr
!= NULL
,kDataBrowserNothingHit
,_("No column existing."));
1739 dataViewCustomRendererPtr
= dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer());
1740 wxCHECK_MSG(dataViewCustomRendererPtr
!= NULL
,kDataBrowserNothingHit
,_("No renderer or invalid renderer type specified for custom data column."));
1741 // 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):
1742 if (dataViewCtrlPtr
->GetCustomRendererItem() == dataViewCustomRendererItem
)
1743 return kDataBrowserContentHit
;
1744 // an(other) item is going to be edited and therefore the current editing - if existing - has to be finished:
1745 if (dataViewCtrlPtr
->GetCustomRendererPtr() != NULL
)
1747 dataViewCtrlPtr
->GetCustomRendererPtr()->FinishEditing();
1748 dataViewCtrlPtr
->SetCustomRendererItem(wxDataViewItem());
1749 dataViewCtrlPtr
->SetCustomRendererPtr (NULL
);
1751 // check if renderer has got a valid editor control for editing; if this is the case start editing of the new item:
1752 if (dataViewCustomRendererPtr
->HasEditorCtrl())
1754 // variable definition:
1757 ::wxMacNativeToRect(theRect
,&wxRectangle
);
1758 dataViewCustomRendererPtr
->StartEditing(dataViewCustomRendererItem
,wxRectangle
);
1759 dataViewCtrlPtr
->SetCustomRendererItem(dataViewCustomRendererItem
);
1760 dataViewCtrlPtr
->SetCustomRendererPtr (dataViewCustomRendererPtr
);
1762 return kDataBrowserContentHit
;
1763 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserTrackingProc(DataBrowserItemID, DataBrowserPropertyID, Rect const*, Point, EventModifiers) */
1765 Boolean
wxMacDataViewDataBrowserListViewControl::DataBrowserAcceptDragProc(DragReference dragRef
, DataBrowserItemID itemID
)
1769 UInt16 noOfDraggedItems
;
1771 wxDataViewCtrl
* dataViewCtrlPtr
;
1774 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer());
1775 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Pointer to data view control not set correctly."));
1776 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,false,_("Pointer to model not set correctly."));
1778 // send a drag possible event for each available and item und proceed with it unless the event is vetoed:
1779 ::CountDragItems(dragRef
,&noOfDraggedItems
);
1780 for (UInt16 indexDraggedItem
=1; indexDraggedItem
<=noOfDraggedItems
; ++indexDraggedItem
)
1782 // collect native information:
1783 ItemReference itemRef
;
1784 wxDataObjectComposite
* dataObjects
;
1785 wxMemoryBuffer buffer
;
1787 ::GetDragItemReferenceNumber(dragRef
,indexDraggedItem
,&itemRef
); // the index begins with 1!
1788 dataObjects
= this->GetDnDDataObjects(dragRef
,itemRef
);
1789 // create wxWidget's event:
1790 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
,dataViewCtrlPtr
->GetId());
1792 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
1793 dataViewEvent
.SetItem(reinterpret_cast<void*>(itemID
)); // this is the item that receives the event
1794 // (can be an invalid item ID, this is especially useful if the dataview does not contain any items)
1795 dataViewEvent
.SetModel(dataViewCtrlPtr
->GetModel());
1796 dataViewEvent
.SetDataObject(dataObjects
);
1797 dataViewEvent
.SetDataFormat(this->GetDnDDataFormat(dataObjects
));
1798 if (dataViewEvent
.GetDataFormat().GetType() != wxDF_INVALID
)
1800 dataViewEvent
.SetDataSize(dataObjects
->GetDataSize(dataViewEvent
.GetDataFormat().GetType()));
1801 dataObjects
->GetDataHere(dataViewEvent
.GetDataFormat().GetType(),buffer
.GetWriteBuf(dataViewEvent
.GetDataSize()));
1802 buffer
.UngetWriteBuf(dataViewEvent
.GetDataSize());
1803 dataViewEvent
.SetDataBuffer(buffer
.GetData());
1807 acceptDrag
= dataViewCtrlPtr
->HandleWindowEvent(dataViewEvent
) && dataViewEvent
.IsAllowed();
1813 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserAcceptDragProc(DragReference, DataBrowserItemID) */
1815 Boolean
wxMacDataViewDataBrowserListViewControl::DataBrowserAddDragItemProc(DragReference dragRef
, DataBrowserItemID itemID
, ItemReference
* itemRef
)
1817 Boolean addDragItem
;
1819 wxDataViewCtrl
* dataViewCtrlPtr
;
1821 wxDataViewItem dataViewItem
;
1824 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer());
1825 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Pointer to data view control not set correctly."));
1826 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,false,_("Pointer to model not set correctly."));
1827 dataViewItem
= reinterpret_cast<void*>(itemID
);
1828 wxCHECK_MSG(dataViewItem
.IsOk(),false,_("Invalid data view item"));
1830 // send a begin drag event and proceed with dragging unless the event is vetoed:
1831 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
,dataViewCtrlPtr
->GetId());
1833 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
1834 dataViewEvent
.SetItem(dataViewItem
);
1835 dataViewEvent
.SetModel(dataViewCtrlPtr
->GetModel());
1836 // 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
1837 // the object a wxDataObjectComposite object is used;
1838 // currently, the composite object only contains a TAB concatenated string of all data:
1839 wxDataObjectComposite
* dataObject(new wxDataObjectComposite());
1841 dataObject
->Add(new wxTextDataObject(::ConcatenateDataViewItemValues(dataViewCtrlPtr
,dataViewItem
)));
1842 dataViewEvent
.SetDataObject(dataObject
);
1843 // check if event has not been vetoed:
1844 addDragItem
= dataViewCtrlPtr
->HandleWindowEvent(dataViewEvent
) && dataViewEvent
.IsAllowed();
1847 // for the internal drag & drop functions create two flavors:
1848 // - the data browser's item id;
1849 // - the data contained the dataview event object (if available).
1850 // Definition: a flavor is the type dependent representation of identical data.
1851 // Example: a number can be represented by its value and by its value converted to a string. In this case the flavor
1852 // of the number's internal representation is typeSInt32 while its string representation has got the flavor 'TEXT'.
1853 // Item id is one of the flavors:
1854 wxCHECK_MSG(::AddDragItemFlavor(dragRef
,*itemRef
,typeUInt32
,&itemID
,sizeof(itemID
),0) == noErr
,false,_("Unable to handle native drag&drop data"));
1855 // if the dataview event object contains data it is used for additional flavors; all natively known flavors are supported:
1856 if (dataViewEvent
.GetDataObject() != NULL
)
1858 // constant definition for abbreviational purposes:
1859 size_t const noOfFormats
= dataViewEvent
.GetDataObject()->GetFormatCount();
1861 if (noOfFormats
> 0)
1863 // variable definition:
1864 wxDataFormat
* dataFormats
;
1866 dataFormats
= new wxDataFormat
[noOfFormats
];
1867 dataViewEvent
.GetDataObject()->GetAllFormats(dataFormats
,wxDataObject::Get
);
1868 for (size_t i
=0; i
<noOfFormats
; ++i
)
1869 switch (dataFormats
[i
].GetType())
1872 wxFAIL_MSG(_("Data object has invalid data format"));
1876 // constant definition for abbreviational purposes:
1877 size_t const dataSize
= dataViewEvent
.GetDataObject()->GetDataSize(wxDF_TEXT
);
1878 // variable definition and initialization:
1879 wxMemoryBuffer
dataObject(dataSize
);
1881 dataViewEvent
.GetDataObject()->GetDataHere(wxDF_TEXT
,dataObject
.GetWriteBuf(dataSize
));
1882 dataObject
.UngetWriteBuf(dataSize
);
1883 if (::AddDragItemFlavor(dragRef
,*itemRef
,'TEXT',dataObject
.GetData(),dataSize
,0) != noErr
)
1884 wxFAIL_MSG(_("Adding flavor TEXT failed"));
1887 case wxDF_UNICODETEXT
:
1889 // constant definition for abbreviational purposes:
1890 size_t const dataSize
= dataViewEvent
.GetDataObject()->GetDataSize(wxDF_TEXT
);
1891 // as there is no direct access to the data copy it to a memory buffer:
1892 wxMemoryBuffer
dataObject(dataSize
);
1894 dataViewEvent
.GetDataObject()->GetDataHere(wxDF_TEXT
,dataObject
.GetWriteBuf(dataSize
));
1895 dataObject
.UngetWriteBuf(dataSize
);
1896 // if the data is stored in unicode format the internal representation is utf-8 (not mentioned in the documentation but in the source code);
1897 // DnD uses fixed utf-16 representation -> use the OSX functions for a conversion:
1898 CFDataRef
osxData (::CFDataCreateWithBytesNoCopy(kCFAllocatorDefault
,reinterpret_cast<UInt8
*>(dataObject
.GetData()),dataSize
,kCFAllocatorNull
));
1899 CFStringRef
osxString(::CFStringCreateFromExternalRepresentation(kCFAllocatorDefault
,osxData
,kCFStringEncodingUTF8
));
1901 // the osxString contains now the data and therefore the previously occupied memory can be released and re-used:
1902 ::CFRelease(osxData
);
1903 osxData
= ::CFStringCreateExternalRepresentation(kCFAllocatorDefault
,osxString
,kCFStringEncodingUTF16
,32);
1904 if (::AddDragItemFlavor(dragRef
,*itemRef
,'utxt',::CFDataGetBytePtr(osxData
),::CFDataGetLength(osxData
),0) != noErr
)
1905 wxFAIL_MSG(_("Adding flavor utxt failed"));
1907 ::CFRelease(osxData
);
1908 ::CFRelease(osxString
);
1922 case wxDF_ENHMETAFILE
:
1927 break; // not (yet) supported data formats
1929 wxFAIL_MSG(_("Unknown data format"));
1931 delete[] dataFormats
;
1935 // clean-up and return result:
1938 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserAddDragItemProc(DragReference, DataBrowserItemID, ItemReference*) */
1940 Boolean
wxMacDataViewDataBrowserListViewControl::DataBrowserReceiveDragProc(DragReference dragRef
, DataBrowserItemID itemID
)
1942 UInt16 noOfDraggedItems
;
1944 wxDataViewCtrl
* dataViewCtrlPtr
;
1947 dataViewCtrlPtr
= dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer());
1948 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Pointer to data view control not set correctly."));
1949 wxCHECK_MSG(dataViewCtrlPtr
->GetModel() != NULL
,false,_("Pointer to model not set correctly."));
1951 // send a drag possible event for each available and item und proceed with it unless the event is vetoed:
1952 ::CountDragItems(dragRef
,&noOfDraggedItems
);
1953 for (UInt16 indexDraggedItem
=1; indexDraggedItem
<=noOfDraggedItems
; ++indexDraggedItem
)
1956 ItemReference itemRef
;
1957 wxDataObjectComposite
* dataObjects
;
1958 wxMemoryBuffer buffer
;
1960 // collect native information:
1961 ::GetDragItemReferenceNumber(dragRef
,indexDraggedItem
,&itemRef
); // the index begins with 1!
1962 dataObjects
= this->GetDnDDataObjects(dragRef
,itemRef
);
1963 // create wxWidget's event:
1964 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_DROP
,dataViewCtrlPtr
->GetId());
1966 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
1967 dataViewEvent
.SetItem(reinterpret_cast<void*>(itemID
)); // this is the item that receives the event
1968 // (can be an invalid item ID, this is especially useful if the dataview does not contain any items)
1969 dataViewEvent
.SetModel(dataViewCtrlPtr
->GetModel());
1970 dataViewEvent
.SetDataObject(dataObjects
);
1971 dataViewEvent
.SetDataFormat(this->GetDnDDataFormat(dataObjects
));
1972 if (dataViewEvent
.GetDataFormat().GetType() != wxDF_INVALID
)
1974 dataViewEvent
.SetDataSize(dataObjects
->GetDataSize(dataViewEvent
.GetDataFormat().GetType()));
1975 dataObjects
->GetDataHere(dataViewEvent
.GetDataFormat().GetType(),buffer
.GetWriteBuf(dataViewEvent
.GetDataSize()));
1976 buffer
.UngetWriteBuf(dataViewEvent
.GetDataSize());
1977 dataViewEvent
.SetDataBuffer(buffer
.GetData());
1981 receiveDrag
= dataViewCtrlPtr
->HandleWindowEvent(dataViewEvent
) && dataViewEvent
.IsAllowed();
1987 } /* wxMacDataViewDataBrowserListViewControl::DataBrowserReceiveDragProc(DragReference, DataBrowserItemID) */
1990 // drag & drop helper methods
1992 wxDataFormat
wxMacDataViewDataBrowserListViewControl::GetDnDDataFormat(wxDataObjectComposite
* dataObjects
)
1994 wxDataFormat resultFormat
;
1997 if (dataObjects
!= NULL
)
1999 bool compatible(true);
2001 size_t const noOfFormats
= dataObjects
->GetFormatCount();
2004 wxDataFormat
* formats
;
2006 // get all formats and check afterwards if the formats are compatible; if they are compatible the preferred format is returned otherwise
2007 // wxDF_INVALID is returned;
2008 // currently compatible types (ordered by priority are):
2009 // - wxDF_UNICODETEXT - wxDF_TEXT
2010 formats
= new wxDataFormat
[noOfFormats
];
2011 dataObjects
->GetAllFormats(formats
);
2013 while ((indexFormat
< noOfFormats
) && compatible
)
2015 switch (resultFormat
.GetType())
2018 resultFormat
.SetType(formats
[indexFormat
].GetType()); // first format (should only be reached if indexFormat == 0
2021 if (formats
[indexFormat
].GetType() == wxDF_UNICODETEXT
)
2022 resultFormat
.SetType(wxDF_UNICODETEXT
);
2023 else // incompatible
2025 resultFormat
.SetType(wxDF_INVALID
);
2029 case wxDF_UNICODETEXT
:
2030 if (formats
[indexFormat
].GetType() != wxDF_TEXT
)
2032 resultFormat
.SetType(wxDF_INVALID
);
2037 resultFormat
.SetType(wxDF_INVALID
); // not (yet) supported format
2046 resultFormat
= wxDF_INVALID
;
2047 return resultFormat
;
2048 } /* wxMacDataViewDataBrowserListViewControl::GetDnDDataFormat(wxDataObjectComposite*) */
2050 wxDataObjectComposite
* wxMacDataViewDataBrowserListViewControl::GetDnDDataObjects(DragReference dragRef
, ItemReference itemRef
) const
2054 wxDataObjectComposite
* dataObject
;
2057 ::CountDragItemFlavors(dragRef
,itemRef
,&noOfFlavors
);
2058 if (noOfFlavors
> 0)
2060 // 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:
2061 wxTextDataObject
* textDataObject(NULL
);
2063 dataObject
= new wxDataObjectComposite();
2064 for (UInt16 indexFlavor
=1; indexFlavor
<=noOfFlavors
; ++indexFlavor
)
2066 // variable definition:
2067 FlavorType flavorDataObject
;
2069 if (::GetFlavorType(dragRef
,itemRef
,indexFlavor
,&flavorDataObject
) == noErr
) // GetFlavorType uses a 1 based index!
2070 switch (flavorDataObject
)
2073 if (textDataObject
== NULL
) // otherwise a 'utxt' flavor has already been found that gets priority compared to the 'TEXT' flavor
2075 // variable definitions:
2076 Size nativeDataSize
;
2077 wxMemoryBuffer nativeData
;
2079 if ((::GetFlavorDataSize(dragRef
,itemRef
,'TEXT',&nativeDataSize
) == noErr
) &&
2080 (::GetFlavorData(dragRef
,itemRef
,'TEXT',nativeData
.GetWriteBuf(nativeDataSize
),&nativeDataSize
,0) == noErr
))
2082 nativeData
.UngetWriteBuf(nativeDataSize
);
2083 textDataObject
= new wxTextDataObject();
2084 if (textDataObject
->SetData(nativeData
.GetDataLen(),nativeData
.GetData()))
2085 dataObject
->Add(textDataObject
);
2088 delete textDataObject
;
2089 textDataObject
= NULL
;
2096 // variable definition:
2097 Size nativeDataSize
;
2099 if (::GetFlavorDataSize(dragRef
,itemRef
,'utxt',&nativeDataSize
) == noErr
)
2101 CFMutableDataRef draggedData
;
2103 draggedData
= ::CFDataCreateMutable(kCFAllocatorDefault
,nativeDataSize
);
2104 ::CFDataSetLength(draggedData
,nativeDataSize
);
2105 if (::GetFlavorData(dragRef
,itemRef
,'utxt',::CFDataGetMutableBytePtr(draggedData
),&nativeDataSize
,0) == noErr
)
2107 // convert internally used UTF-16 representation to a UTF-8 representation:
2109 CFStringRef osxString
;
2111 osxString
= ::CFStringCreateFromExternalRepresentation(kCFAllocatorDefault
,draggedData
,kCFStringEncodingUTF16
); // BOM character is handled by this function automatically
2112 osxData
= ::CFStringCreateExternalRepresentation(kCFAllocatorDefault
,osxString
,kCFStringEncodingUTF8
,32);
2113 if (textDataObject
== NULL
)
2115 textDataObject
= new wxTextDataObject();
2116 if (textDataObject
->SetData(::CFDataGetLength(osxData
),::CFDataGetBytePtr(osxData
)))
2117 dataObject
->Add(textDataObject
);
2120 delete textDataObject
;
2121 textDataObject
= NULL
;
2124 else // overwrite data because the 'utxt' flavor has priority over the 'TEXT' flavor
2125 (void) textDataObject
->SetData(::CFDataGetLength(osxData
),::CFDataGetBytePtr(osxData
));
2127 ::CFRelease(osxData
);
2128 ::CFRelease(osxString
);
2131 ::CFRelease(draggedData
);
2141 } /* wxMacDataViewDataBrowserListViewControl::GetDnDDataObjects(DragReference, ItemReference) const */
2146 wxDataViewColumn
* wxMacDataViewDataBrowserListViewControl::GetColumnPtr(DataBrowserPropertyID propertyID
) const
2148 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->GetWXPeer()));
2150 if (dataViewCtrlPtr
!= NULL
)
2152 size_t const noOfColumns
= dataViewCtrlPtr
->GetColumnCount();
2154 for (size_t i
=0; i
<noOfColumns
; ++i
)
2155 if (dataViewCtrlPtr
->GetColumnPtr(i
)->GetNativeData()->GetPropertyID() == propertyID
)
2156 return dataViewCtrlPtr
->GetColumnPtr(i
);
2161 // ---------------------------------------------------------
2162 // wxDataViewRenderer
2163 // ---------------------------------------------------------
2164 wxDataViewRenderer::wxDataViewRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
2165 :wxDataViewRendererBase(varianttype
,mode
,align
), m_alignment(align
), m_mode(mode
), m_NativeDataPtr(NULL
)
2169 wxDataViewRenderer::~wxDataViewRenderer(void)
2171 delete this->m_NativeDataPtr
;
2174 void wxDataViewRenderer::SetAlignment(int align
)
2176 this->m_alignment
= align
;
2179 void wxDataViewRenderer::SetMode(wxDataViewCellMode mode
)
2181 wxDataViewColumn
* dataViewColumnPtr
;
2185 dataViewColumnPtr
= this->GetOwner();
2186 if (dataViewColumnPtr
!= NULL
)
2188 wxDataViewCtrl
* dataViewCtrlPtr(dataViewColumnPtr
->GetOwner());
2190 if (dataViewCtrlPtr
!= NULL
)
2192 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
2194 if (macDataViewListCtrlPtr
!= NULL
)
2196 DataBrowserPropertyFlags flags
;
2198 verify_noerr(macDataViewListCtrlPtr
->GetPropertyFlags(dataViewColumnPtr
->GetNativeData()->GetPropertyID(),&flags
));
2199 if ((mode
== wxDATAVIEW_CELL_EDITABLE
) ||
2200 (mode
== wxDATAVIEW_CELL_ACTIVATABLE
))
2201 flags
|= kDataBrowserPropertyIsEditable
;
2203 flags
&= ~kDataBrowserPropertyIsEditable
;
2204 verify_noerr(macDataViewListCtrlPtr
->SetPropertyFlags(dataViewColumnPtr
->GetNativeData()->GetPropertyID(),flags
));
2210 void wxDataViewRenderer::SetNativeData(wxDataViewRendererNativeData
* newNativeDataPtr
)
2212 delete this->m_NativeDataPtr
;
2213 this->m_NativeDataPtr
= newNativeDataPtr
;
2216 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
,wxDataViewRendererBase
)
2218 // ---------------------------------------------------------
2219 // wxDataViewCustomRenderer
2220 // ---------------------------------------------------------
2221 wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
2222 :wxDataViewRenderer(varianttype
,mode
,align
), m_editorCtrlPtr(NULL
), m_DCPtr(NULL
)
2224 this->SetNativeData(new wxDataViewRendererNativeData(kDataBrowserCustomType
));
2227 bool wxDataViewCustomRenderer::Render()
2232 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
2234 // ---------------------------------------------------------
2235 // wxDataViewTextRenderer
2236 // ---------------------------------------------------------
2237 wxDataViewTextRenderer::wxDataViewTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
2238 :wxDataViewRenderer(varianttype
,mode
,align
)
2240 this->SetNativeData(new wxDataViewRendererNativeData(kDataBrowserTextType
));
2243 bool wxDataViewTextRenderer::Render()
2245 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Text renderer cannot render value; value type: ")) << this->GetValue().GetType());
2247 wxCFStringRef
cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
2248 return (::SetDataBrowserItemDataText(this->GetNativeData()->GetItemDataRef(),cfString
) == noErr
);
2251 IMPLEMENT_CLASS(wxDataViewTextRenderer
,wxDataViewRenderer
)
2253 // ---------------------------------------------------------
2254 // wxDataViewBitmapRenderer
2255 // ---------------------------------------------------------
2256 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
2257 :wxDataViewRenderer(varianttype
,mode
,align
)
2259 this->SetNativeData(new wxDataViewRendererNativeData(kDataBrowserIconType
));
2262 bool wxDataViewBitmapRenderer::Render()
2263 // This method returns 'true' if
2264 // - the passed bitmap is valid and it could be assigned to the native data browser;
2265 // - the passed bitmap is invalid (or is not initialized); this case simulates a non-existing bitmap.
2266 // In all other cases the method returns 'false'.
2268 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Bitmap renderer cannot render value; value type: ")) << this->GetValue().GetType());
2272 bitmap
<< this->GetValue();
2273 return (!(bitmap
.Ok()) || (::SetDataBrowserItemDataIcon(this->GetNativeData()->GetItemDataRef(),bitmap
.GetIconRef()) == noErr
));
2276 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
,wxDataViewRenderer
)
2278 // ---------------------------------------------------------
2279 // wxDataViewIconTextRenderer
2280 // ---------------------------------------------------------
2281 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
2282 :wxDataViewRenderer(varianttype
,mode
)
2284 this->SetNativeData(new wxDataViewRendererNativeData(kDataBrowserIconAndTextType
));
2287 bool wxDataViewIconTextRenderer::Render()
2289 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Icon & text renderer cannot render value; value type: ")) << this->GetValue().GetType());
2291 wxDataViewIconText iconText
;
2293 iconText
<< this->GetValue();
2295 wxCFStringRef
cfString(iconText
.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
2297 if (iconText
.GetIcon().IsOk())
2298 if (::SetDataBrowserItemDataIcon(this->GetNativeData()->GetItemDataRef(),MAC_WXHICON(iconText
.GetIcon().GetHICON())) != noErr
)
2300 return (::SetDataBrowserItemDataText(this->GetNativeData()->GetItemDataRef(),cfString
) == noErr
);
2303 IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer
,wxDataViewRenderer
)
2306 // ---------------------------------------------------------
2307 // wxDataViewToggleRenderer
2308 // ---------------------------------------------------------
2309 wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
2310 :wxDataViewRenderer(varianttype
,mode
)
2312 this->SetNativeData(new wxDataViewRendererNativeData(kDataBrowserCheckboxType
));
2315 bool wxDataViewToggleRenderer::Render()
2317 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Toggle renderer cannot render value; value type: ")) << this->GetValue().GetType());
2318 return (::SetDataBrowserItemDataButtonValue(this->GetNativeData()->GetItemDataRef(),this->GetValue().GetBool()) == noErr
);
2321 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
,wxDataViewRenderer
)
2323 // ---------------------------------------------------------
2324 // wxDataViewProgressRenderer
2325 // ---------------------------------------------------------
2326 wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString
const& label
, wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
2327 :wxDataViewRenderer(varianttype
,mode
,align
)
2329 this->SetNativeData(new wxDataViewRendererNativeData(kDataBrowserProgressBarType
));
2332 bool wxDataViewProgressRenderer::Render()
2334 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Progress renderer cannot render value type; value type: ")) << this->GetValue().GetType());
2335 return ((::SetDataBrowserItemDataMinimum(this->GetNativeData()->GetItemDataRef(), 0) == noErr
) &&
2336 (::SetDataBrowserItemDataMaximum(this->GetNativeData()->GetItemDataRef(),100) == noErr
) &&
2337 (::SetDataBrowserItemDataValue (this->GetNativeData()->GetItemDataRef(),this->GetValue().GetLong()) == noErr
));
2340 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
,wxDataViewRenderer
)
2342 // ---------------------------------------------------------
2343 // wxDataViewDateRenderer
2344 // ---------------------------------------------------------
2345 wxDataViewDateRenderer::wxDataViewDateRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
2346 :wxDataViewRenderer(varianttype
,mode
,align
)
2348 this->SetNativeData(new wxDataViewRendererNativeData(kDataBrowserDateTimeType
));
2351 bool wxDataViewDateRenderer::Render()
2353 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Date renderer cannot render value; value type: ")) << this->GetValue().GetType());
2354 return (::SetDataBrowserItemDataDateTime(this->GetNativeData()->GetItemDataRef(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan
,1904)).GetSeconds().GetLo()) == noErr
);
2357 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
,wxDataViewRenderer
)
2359 // ---------------------------------------------------------
2361 // ---------------------------------------------------------
2362 wxDataViewColumn::wxDataViewColumn(const wxString
& title
, wxDataViewRenderer
* renderer
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
2363 :wxDataViewColumnBase(renderer
, model_column
), m_NativeDataPtr(new wxDataViewColumnNativeData()), m_title(title
)
2365 this->InitCommon(width
, align
, flags
);
2366 if ((renderer
!= NULL
) && (renderer
->GetAlignment() == wxDVR_DEFAULT_ALIGNMENT
))
2367 renderer
->SetAlignment(align
);
2370 wxDataViewColumn::wxDataViewColumn(const wxBitmap
& bitmap
, wxDataViewRenderer
* renderer
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
2371 :wxDataViewColumnBase(bitmap
, renderer
, model_column
), m_NativeDataPtr(new wxDataViewColumnNativeData())
2373 this->InitCommon(width
, align
, flags
);
2374 if ((renderer
!= NULL
) && (renderer
->GetAlignment() == wxDVR_DEFAULT_ALIGNMENT
))
2375 renderer
->SetAlignment(align
);
2378 wxDataViewColumn::~wxDataViewColumn(void)
2380 delete this->m_NativeDataPtr
;
2383 bool wxDataViewColumn::IsSortKey() const
2385 wxDataViewCtrl
* const dataViewCtrlPtr(GetOwner());
2386 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(
2387 dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(
2388 dataViewCtrlPtr
->GetPeer()));
2390 DataBrowserPropertyID propertyID
;
2391 return (macDataViewListCtrlPtr
->GetSortProperty(&propertyID
) == noErr
) &&
2392 (propertyID
== this->GetNativeData()->GetPropertyID());
2395 void wxDataViewColumn::SetAlignment(wxAlignment align
)
2397 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
2400 m_alignment
= align
;
2401 if (dataViewCtrlPtr
!= NULL
)
2403 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
2405 if (macDataViewListCtrlPtr
!= NULL
)
2407 DataBrowserListViewHeaderDesc headerDescription
;
2409 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetNativeData()->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
2412 case wxALIGN_CENTER
:
2413 case wxALIGN_CENTER_HORIZONTAL
:
2414 headerDescription
.btnFontStyle
.just
= teCenter
;
2417 headerDescription
.btnFontStyle
.just
= teFlushLeft
;
2420 headerDescription
.btnFontStyle
.just
= teFlushRight
;
2423 headerDescription
.btnFontStyle
.just
= teFlushDefault
;
2425 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetNativeData()->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set alignment."));
2430 void wxDataViewColumn::SetBitmap(wxBitmap
const& bitmap
)
2432 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
2435 wxDataViewColumnBase::SetBitmap(bitmap
);
2436 if (dataViewCtrlPtr
!= NULL
)
2438 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
2440 if (macDataViewListCtrlPtr
!= NULL
)
2442 DataBrowserListViewHeaderDesc headerDescription
;
2444 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetNativeData()->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
2445 if (this->GetBitmap().Ok())
2446 headerDescription
.btnContentInfo
.u
.iconRef
= this->GetBitmap().GetIconRef();
2448 headerDescription
.btnContentInfo
.u
.iconRef
= NULL
;
2449 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetNativeData()->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set icon."));
2454 void wxDataViewColumn::SetMaxWidth(int maxWidth
)
2456 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
2459 m_maxWidth
= maxWidth
;
2460 if (dataViewCtrlPtr
!= NULL
)
2462 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
2464 if (macDataViewListCtrlPtr
!= NULL
)
2466 DataBrowserListViewHeaderDesc headerDescription
;
2468 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetNativeData()->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
2469 headerDescription
.maximumWidth
= static_cast<UInt16
>(maxWidth
);
2470 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetNativeData()->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set maximum width."));
2475 void wxDataViewColumn::SetMinWidth(int minWidth
)
2477 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
2480 m_minWidth
= minWidth
;
2481 if (dataViewCtrlPtr
!= NULL
)
2483 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
2485 if (macDataViewListCtrlPtr
!= NULL
)
2487 DataBrowserListViewHeaderDesc headerDescription
;
2489 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetNativeData()->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
2490 headerDescription
.minimumWidth
= static_cast<UInt16
>(minWidth
);
2491 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetNativeData()->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set minimum width."));
2496 void wxDataViewColumn::SetReorderable(bool reorderable
)
2498 // first set the internal flag of the column:
2500 m_flags
|= wxDATAVIEW_COL_REORDERABLE
;
2502 m_flags
&= ~wxDATAVIEW_COL_REORDERABLE
;
2503 // if the column is associated with a control change also immediately the flags of the control:
2504 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
2506 if (dataViewCtrlPtr
!= NULL
)
2508 DataBrowserPropertyFlags flags
;
2509 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
2511 wxCHECK_RET(macDataViewListCtrlPtr
!= NULL
, _("Valid pointer to native data view control does not exist"));
2512 wxCHECK_RET(macDataViewListCtrlPtr
->GetPropertyFlags(this->GetNativeData()->GetPropertyID(),&flags
) == noErr
,_("Could not get property flags."));
2514 flags
|= kDataBrowserListViewMovableColumn
;
2516 flags
&= ~kDataBrowserListViewMovableColumn
;
2517 wxCHECK_RET(macDataViewListCtrlPtr
->SetPropertyFlags(this->GetNativeData()->GetPropertyID(),flags
) == noErr
,_("Could not set property flags."));
2521 void wxDataViewColumn::SetResizeable(bool resizeable
)
2523 // first set the internal flag of the column:
2525 m_flags
|= wxDATAVIEW_COL_RESIZABLE
;
2527 m_flags
&= ~wxDATAVIEW_COL_RESIZABLE
;
2528 // if the column is associated with a control change also immediately the flags of the control:
2529 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
2531 if (dataViewCtrlPtr
!= NULL
)
2533 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
2535 if (macDataViewListCtrlPtr
!= NULL
)
2537 DataBrowserListViewHeaderDesc headerDescription
;
2539 verify_noerr(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetNativeData()->GetPropertyID(),&headerDescription
));
2542 if (this->GetMinWidth() >= this->GetMaxWidth())
2544 this->m_minWidth
= 0;
2545 this->m_maxWidth
= 30000;
2547 headerDescription
.minimumWidth
= this->m_minWidth
;
2548 headerDescription
.maximumWidth
= this->m_maxWidth
;
2552 headerDescription
.minimumWidth
= this->m_width
;
2553 headerDescription
.maximumWidth
= this->m_width
;
2555 verify_noerr(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetNativeData()->GetPropertyID(),&headerDescription
));
2556 macDataViewListCtrlPtr
->SetSortProperty(this->GetNativeData()->GetPropertyID());
2561 void wxDataViewColumn::SetSortable(bool sortable
)
2563 // first set the internal flag of the column:
2565 m_flags
|= wxDATAVIEW_COL_SORTABLE
;
2567 m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
2568 // if the column is associated with a control change also immediately the flags of the control:
2569 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
2571 if (dataViewCtrlPtr
!= NULL
)
2573 DataBrowserPropertyFlags flags
;
2574 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
2576 wxCHECK_RET(macDataViewListCtrlPtr
!= NULL
, _("Valid pointer to native data view control does not exist"));
2577 wxCHECK_RET(macDataViewListCtrlPtr
->GetPropertyFlags(this->GetNativeData()->GetPropertyID(),&flags
) == noErr
,_("Could not get property flags."));
2579 flags
|= kDataBrowserListViewSortableColumn
;
2581 flags
&= ~kDataBrowserListViewSortableColumn
;
2582 wxCHECK_RET(macDataViewListCtrlPtr
->SetPropertyFlags(this->GetNativeData()->GetPropertyID(),flags
) == noErr
,_("Could not set property flags."));
2586 void wxDataViewColumn::SetSortOrder(bool ascending
)
2588 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
2591 m_ascending
= ascending
;
2592 if (dataViewCtrlPtr
!= NULL
)
2594 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
2596 if (macDataViewListCtrlPtr
!= NULL
)
2598 DataBrowserListViewHeaderDesc headerDescription
;
2600 verify_noerr(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetNativeData()->GetPropertyID(),&headerDescription
));
2602 headerDescription
.initialOrder
= kDataBrowserOrderIncreasing
;
2604 headerDescription
.initialOrder
= kDataBrowserOrderDecreasing
;
2605 verify_noerr(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetNativeData()->GetPropertyID(),&headerDescription
));
2606 macDataViewListCtrlPtr
->SetSortProperty(this->GetNativeData()->GetPropertyID());
2611 void wxDataViewColumn::SetTitle(wxString
const& title
)
2613 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
2617 if (dataViewCtrlPtr
!= NULL
)
2619 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
2621 if (macDataViewListCtrlPtr
!= NULL
)
2623 DataBrowserListViewHeaderDesc headerDescription
;
2624 wxCFStringRef
cfTitle(title
,(dataViewCtrlPtr
->GetFont().Ok() ? dataViewCtrlPtr
->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
2626 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetNativeData()->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
2627 headerDescription
.titleString
= cfTitle
;
2628 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetNativeData()->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set header description."));
2633 void wxDataViewColumn::SetWidth(int width
)
2635 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
2638 if ((width
>= m_minWidth
) && (width
<= m_maxWidth
))
2641 if (dataViewCtrlPtr
!= NULL
)
2643 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
2645 if (macDataViewListCtrlPtr
!= NULL
)
2646 wxCHECK_RET(macDataViewListCtrlPtr
->SetColumnWidth(this->GetNativeData()->GetPropertyID(),static_cast<UInt16
>(width
)) == noErr
,_("Could not set column width."));
2651 void wxDataViewColumn::SetAsSortKey(bool WXUNUSED(sort
))
2653 // see wxGTK native wxDataViewColumn implementation
2654 wxFAIL_MSG( "not implemented" );
2657 void wxDataViewColumn::SetNativeData(wxDataViewColumnNativeData
* newNativeDataPtr
)
2659 delete this->m_NativeDataPtr
;
2660 this->m_NativeDataPtr
= newNativeDataPtr
;
2663 #endif // wxUSE_DATAVIEWCTRL && !wxUSE_GENERICDATAVIEWCTRL