]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/databrow.cpp
DC headers don't need to be in gtk/private.h
[wxWidgets.git] / src / mac / carbon / databrow.cpp
CommitLineData
c0a66d92
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/mac/carbon/databrow.cpp
3// Purpose: Classes and functions for the Carbon data browser
6e1609b1 4// Author:
c0a66d92
RR
5// Modified by:
6// Created: 2007-05-18
7// RCS-ID: $Id$
8// Copyright: (c)
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
6e1609b1
VZ
12#include "wx/wxprec.h"
13
14#if wxUSE_DATAVIEWCTRL && !defined(wxUSE_GENERICDATAVIEWCTRL)
a3fd36e7 15
594d5596 16#include <limits>
c0a66d92 17
a5fb9253
RR
18#ifndef WX_PRECOMP
19 #include "wx/app.h"
20 #include "wx/toplevel.h"
21 #include "wx/font.h"
915bd4e4 22 #include "wx/settings.h"
a5fb9253
RR
23#endif
24
25#include "wx/dataview.h"
26#include "wx/utils.h"
27
f53c8638 28#include "wx/mac/carbon/databrow.h"
594d5596 29#include "wx/mac/private.h"
a5fb9253 30#include "wx/mac/uma.h"
c0a66d92 31
c0a66d92 32// ============================================================================
194027ac 33// wxMacDataBrowserTableViewControl
c0a66d92 34// ============================================================================
c0a66d92
RR
35
36pascal Boolean wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlRef browser, DataBrowserItemID itemOneID, DataBrowserItemID itemTwoID, DataBrowserPropertyID sortProperty)
37{
38 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
39
40
41 if (ControlPtr != NULL)
42 return ControlPtr->DataBrowserCompareProc(itemOneID,itemTwoID,sortProperty);
43 else
44 return errDataBrowserPropertyNotSupported;
45} /* wxMacDataBrowserTableViewControl::DataBrowserCompareProc(ControlRef, DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
46
47pascal void wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemState state, Rect const* rectangle, SInt16 bitDepth, Boolean colorDevice)
48{
49 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
50
51
52 if (ControlPtr != NULL)
53 ControlPtr->DataBrowserDrawItemProc(itemID,property,state,rectangle,bitDepth,colorDevice);
54} /* wxMacDataBrowserTableViewControl::DataBrowserDrawItemProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */
55
56pascal OSStatus wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserPropertyID property, DataBrowserItemDataRef itemData, Boolean getValue)
57{
58 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
59
60
61 if (ControlPtr != NULL)
62 return ControlPtr->DataBrowserGetSetItemDataProc(itemID,property,itemData,getValue);
63 else
64 return errDataBrowserPropertyNotSupported;
65} /* wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc(ControlRef, DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */
66
67pascal void wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc(ControlRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message, DataBrowserItemDataRef itemData)
68{
69 wxMacDataBrowserTableViewControl* ControlPtr(dynamic_cast<wxMacDataBrowserTableViewControl*>(wxMacControl::GetReferenceFromNativeControl(browser)));
70
71
72 if (ControlPtr != NULL)
73 ControlPtr->DataBrowserItemNotificationProc(itemID,message,itemData);
74} /* wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc(ControlRef, DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */
75
76DataBrowserDrawItemUPP gDataBrowserTableViewDrawItemUPP = NULL;
77DataBrowserItemCompareUPP gDataBrowserTableViewItemCompareUPP = NULL;
78DataBrowserItemDataUPP gDataBrowserTableViewItemDataUPP = NULL;
79DataBrowserItemNotificationUPP gDataBrowserTableViewItemNotificationUPP = NULL;
80
81wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow* peer, wxPoint const& pos, wxSize const& size, long style)
82 :wxMacControl(peer)
83{
84 Rect bounds = wxMacGetBoundsForControl(peer,pos,size);
85 OSStatus err = ::CreateDataBrowserControl(MAC_WXHWND(peer->MacGetTopLevelWindowRef()),&bounds,kDataBrowserListView,&(this->m_controlRef));
86
87
88 SetReferenceInNativeControl();
89 verify_noerr(err);
90 if (gDataBrowserTableViewDrawItemUPP == NULL) gDataBrowserTableViewDrawItemUPP = NewDataBrowserDrawItemUPP (DataBrowserDrawItemProc);
91 if (gDataBrowserTableViewItemCompareUPP == NULL) gDataBrowserTableViewItemCompareUPP = NewDataBrowserItemCompareUPP(wxMacDataBrowserTableViewControl::DataBrowserCompareProc);
92 if (gDataBrowserTableViewItemDataUPP == NULL) gDataBrowserTableViewItemDataUPP = NewDataBrowserItemDataUPP (wxMacDataBrowserTableViewControl::DataBrowserGetSetItemDataProc);
93 if (gDataBrowserTableViewItemNotificationUPP == NULL)
94 {
95 gDataBrowserTableViewItemNotificationUPP =
c0a66d92 96 (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(wxMacDataBrowserTableViewControl::DataBrowserItemNotificationProc);
c0a66d92
RR
97 }
98
99 DataBrowserCallbacks callbacks;
100 DataBrowserCustomCallbacks customCallbacks;
101
102 InitializeDataBrowserCallbacks (&callbacks, kDataBrowserLatestCallbacks);
103 InitializeDataBrowserCustomCallbacks(&customCallbacks,kDataBrowserLatestCallbacks);
104
105 callbacks.u.v1.itemDataCallback = gDataBrowserTableViewItemDataUPP;
106 callbacks.u.v1.itemCompareCallback = gDataBrowserTableViewItemCompareUPP;
107 callbacks.u.v1.itemNotificationCallback = gDataBrowserTableViewItemNotificationUPP;
108 this->SetCallbacks(&callbacks);
109
110 customCallbacks.u.v1.drawItemCallback = gDataBrowserTableViewDrawItemUPP;
111 this->SetCustomCallbacks(&customCallbacks);
112
113 // style setting:
114 this->EnableCellSizeModification();
115
116 DataBrowserSelectionFlags flags; // variable definition
117
118 if (this->GetSelectionFlags(&flags) == noErr) // get default settings
119 {
120 if ((style & wxDV_MULTIPLE) != 0)
121 flags &= ~kDataBrowserSelectOnlyOne;
122 else
123 flags |= kDataBrowserSelectOnlyOne;
124 (void) this->SetSelectionFlags(flags);
125 } /* if */
594d5596 126
c0a66d92 127 OptionBits attributes; // variable definition
6e1609b1 128
c0a66d92
RR
129 if (this->GetAttributes(&attributes) == noErr) // get default settings
130 {
131 if ((style & wxDV_VERT_RULES) != 0)
132 attributes |= kDataBrowserAttributeListViewDrawColumnDividers;
133 else
134 attributes &= ~kDataBrowserAttributeListViewDrawColumnDividers;
6ab2382a
RR
135
136 if ((style & wxDV_ROW_LINES) != 0)
137 attributes |= kDataBrowserAttributeListViewAlternatingRowColors;
138
c0a66d92
RR
139 (void) this->SetAttributes(attributes);
140 } /* if */
594d5596 141
c0a66d92
RR
142 if ((style & wxDV_NO_HEADER) != 0)
143 this->SetHeaderButtonHeight(0);
144} /* wxMacDataBrowserTableViewControl::wxMacDataBrowserTableViewControl(wxWindow*, wxPoint const&, wxSize const&, long) */
145
146//
147// callback handling
148//
149OSStatus wxMacDataBrowserTableViewControl::SetCallbacks(DataBrowserCallbacks const* callbacks)
150{
151 return ::SetDataBrowserCallbacks(this->m_controlRef,callbacks);
152} /* wxMacDataBrowserTableViewControl::SetCallbacks(DataBrowserCallbacks const*) */
153
154OSStatus wxMacDataBrowserTableViewControl::SetCustomCallbacks(DataBrowserCustomCallbacks const* customCallbacks)
155{
156 return ::SetDataBrowserCustomCallbacks(this->m_controlRef,customCallbacks);
157} /* xMacDataBrowserTableViewControl::SetCustomCallbacks(DataBrowserCustomCallbacks const*) */
158
159//
160// header handling
161//
162OSStatus wxMacDataBrowserTableViewControl::GetHeaderDesc(DataBrowserPropertyID property, DataBrowserListViewHeaderDesc* desc) const
163{
164 desc->version = kDataBrowserListViewLatestHeaderDesc; // if this statement is missing the next call will fail (NOT DOCUMENTED!!)
165 return ::GetDataBrowserListViewHeaderDesc(this->m_controlRef,property,desc);
166}
167
168OSStatus wxMacDataBrowserTableViewControl::SetHeaderDesc(DataBrowserPropertyID property, DataBrowserListViewHeaderDesc* desc)
169{
170 return ::SetDataBrowserListViewHeaderDesc(this->m_controlRef,property,desc);
171}
172
173//
174// layout handling
175//
176OSStatus wxMacDataBrowserTableViewControl::AutoSizeColumns()
177{
178 return AutoSizeDataBrowserListViewColumns(this->m_controlRef);
179}
180
181OSStatus wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool enableHeight, bool enableWidth)
182{
183 return ::SetDataBrowserTableViewGeometry(this->GetControlRef(),enableWidth,enableHeight);
184} /* wxMacDataBrowserTableViewControl::EnableCellSizeModification(bool, bool) */
185
c0a66d92
RR
186OSStatus wxMacDataBrowserTableViewControl::GetAttributes(OptionBits* attributes)
187{
188 return ::DataBrowserGetAttributes(this->GetControlRef(),attributes);
189} /* wxMacDataBrowserTableViewControl::GetAttributes(OptionBits*) */
c0a66d92 190
194027ac 191OSStatus wxMacDataBrowserTableViewControl::GetColumnWidth(DataBrowserPropertyID propertyID, UInt16* width) const
c0a66d92 192{
194027ac 193 return ::GetDataBrowserTableViewNamedColumnWidth(this->m_controlRef,propertyID,width);
c0a66d92
RR
194}
195
07c51ff1
RR
196OSStatus wxMacDataBrowserTableViewControl::GetDefaultColumnWidth( UInt16 *width ) const
197{
198 return GetDataBrowserTableViewColumnWidth(this->m_controlRef, width );
199}
200
194027ac 201OSStatus wxMacDataBrowserTableViewControl::GetDefaultRowHeight(UInt16* height) const
c0a66d92 202{
194027ac 203 return ::GetDataBrowserTableViewRowHeight(this->m_controlRef,height);
c0a66d92
RR
204}
205
206OSStatus wxMacDataBrowserTableViewControl::GetHeaderButtonHeight(UInt16 *height)
207{
194027ac 208 return ::GetDataBrowserListViewHeaderBtnHeight(this->m_controlRef,height);
c0a66d92
RR
209}
210
07c51ff1 211OSStatus wxMacDataBrowserTableViewControl::GetPartBounds(DataBrowserItemID item, DataBrowserPropertyID property, DataBrowserPropertyPart part, Rect* bounds)
c0a66d92 212{
07c51ff1
RR
213 return ::GetDataBrowserItemPartBounds(this->m_controlRef,item,property,part,bounds);
214} /* wxMacDataBrowserTableViewControl::GetPartBounds(DataBrowserItemID, DataBrowswerPropertyID, DataBrowserPropertyPart, Rect*) */
c0a66d92 215
07c51ff1 216OSStatus wxMacDataBrowserTableViewControl::GetRowHeight(DataBrowserItemID item, UInt16* height) const
c0a66d92 217{
07c51ff1
RR
218 return ::GetDataBrowserTableViewItemRowHeight(this->m_controlRef,item,height);
219} /* wxMacDataBrowserTableViewControl::GetRowHeight(DataBrowserItemID, UInt16*) const */
c0a66d92
RR
220
221OSStatus wxMacDataBrowserTableViewControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const
222{
194027ac 223 return GetDataBrowserScrollPosition(this->m_controlRef, top , left );
c0a66d92
RR
224}
225
c0a66d92
RR
226OSStatus wxMacDataBrowserTableViewControl::SetAttributes(OptionBits attributes)
227{
228 return ::DataBrowserChangeAttributes(this->GetControlRef(),attributes,~attributes);
229} /* wxMacDataBrowserTableViewControl::SetAttributes(OptionBits) */
c0a66d92 230
194027ac 231OSStatus wxMacDataBrowserTableViewControl::SetColumnWidth(DataBrowserPropertyID propertyID, UInt16 width)
c0a66d92 232{
194027ac 233 return ::SetDataBrowserTableViewNamedColumnWidth(this->m_controlRef,propertyID,width);
c0a66d92
RR
234}
235
194027ac 236OSStatus wxMacDataBrowserTableViewControl::SetDefaultColumnWidth(UInt16 width)
c0a66d92 237{
194027ac 238 return ::SetDataBrowserTableViewColumnWidth(this->m_controlRef,width);
c0a66d92
RR
239}
240
194027ac 241OSStatus wxMacDataBrowserTableViewControl::SetDefaultRowHeight(UInt16 height)
c0a66d92 242{
194027ac 243 return ::SetDataBrowserTableViewRowHeight(this->m_controlRef,height);
c0a66d92
RR
244}
245
c17b2e31 246OSStatus wxMacDataBrowserTableViewControl::SetHasScrollBars(bool horiz, bool vert)
c0a66d92 247{
c17b2e31
RR
248 return ::SetDataBrowserHasScrollBars(this->m_controlRef,horiz,vert);
249} /* wxMacDataBrowserTableViewControl::SetHasScrollBars(bool, bool) */
c0a66d92
RR
250
251OSStatus wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16 height)
252{
c17b2e31
RR
253 return ::SetDataBrowserListViewHeaderBtnHeight(this->m_controlRef,height);
254} /* wxMacDataBrowserTableViewControl::SetHeaderButtonHeight(UInt16) */
c0a66d92 255
c17b2e31 256OSStatus wxMacDataBrowserTableViewControl::SetHiliteStyle(DataBrowserTableViewHiliteStyle hiliteStyle)
c0a66d92 257{
c17b2e31
RR
258 return ::SetDataBrowserTableViewHiliteStyle(this->m_controlRef,hiliteStyle);
259} /*wxMacDataBrowserTableViewControl::SetHiliteStyle(DataBrowserTableViewHiliteStyle) */
260
261OSStatus wxMacDataBrowserTableViewControl::SetIndent(float Indent)
262{
263 return ::DataBrowserSetMetric(this->m_controlRef,kDataBrowserMetricDisclosureColumnPerDepthGap,true,Indent);
264} /* wxMacDataBrowserTableViewControl::SetIndent(float* Indent) */
c0a66d92
RR
265
266OSStatus wxMacDataBrowserTableViewControl::SetRowHeight(DataBrowserItemID item, UInt16 height)
267{
268 return ::SetDataBrowserTableViewItemRowHeight(this->m_controlRef,item,height);
269}
270
271OSStatus wxMacDataBrowserTableViewControl::SetScrollPosition(UInt32 top, UInt32 left)
272{
273 return ::SetDataBrowserScrollPosition(this->m_controlRef,top,left);
274}
275
276//
277// column handling
278//
279OSStatus wxMacDataBrowserTableViewControl::GetColumnCount(UInt32* numColumns) const
280{
194027ac 281 return ::GetDataBrowserTableViewColumnCount(this->m_controlRef,numColumns);
c0a66d92
RR
282}
283
194027ac 284OSStatus wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex* index) const
c0a66d92 285{
194027ac
RR
286 return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,index);
287} /* wxMacDataBrowserTableViewControl::GetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex*) const */
c0a66d92 288
194027ac 289OSStatus wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID* propertyID) const
c0a66d92 290{
194027ac
RR
291 for (*propertyID=kMinPropertyID; *propertyID<std::numeric_limits<DataBrowserPropertyID>::max(); ++(*propertyID))
292 if (this->IsUsedPropertyID(*propertyID) == errDataBrowserPropertyNotFound)
c0a66d92
RR
293 return noErr;
294 return errDataBrowserPropertyNotSupported;
295} /* wxMacDataBrowserTableViewControl::GetFreePropertyID(DataBrowserPropertyID*) const */
296
194027ac 297OSStatus wxMacDataBrowserTableViewControl::GetPropertyFlags(DataBrowserPropertyID propertyID, DataBrowserPropertyFlags *flags) const
c0a66d92 298{
194027ac
RR
299 return ::GetDataBrowserPropertyFlags(this->m_controlRef,propertyID,flags);
300}
c0a66d92 301
07c51ff1
RR
302OSStatus wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef itemData, DataBrowserPropertyID* propertyID)
303{
304 return ::GetDataBrowserItemDataProperty(itemData,propertyID);
305} /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserItemDataRef, DataBrowserPropertyID*) */
306
194027ac 307OSStatus wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex index, DataBrowserTableViewColumnID* propertyID)
c0a66d92 308{
194027ac
RR
309 return ::GetDataBrowserTableViewColumnProperty(this->m_controlRef,index,propertyID);
310} /* wxMacDataBrowserTableViewControl::GetPropertyID(DataBrowserTableViewColumnIndex, DataBrowserTableViewColumnID*) */
c0a66d92
RR
311
312OSStatus wxMacDataBrowserTableViewControl::IsUsedPropertyID(DataBrowserPropertyID propertyID) const
313{
314 // 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
315 // 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
316 // the column position for the property id:
317 DataBrowserTableViewColumnIndex index;
6e1609b1 318
c0a66d92
RR
319 return ::GetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,&index);
320} /* wxMacDataBrowserTableViewControl::IsUsedPropertyId(DataBrowserPropertyID) const */
321
c17b2e31
RR
322OSStatus wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID propertyID)
323{
324 return ::RemoveDataBrowserTableViewColumn(this->m_controlRef,propertyID);
325} /* wxMacDataBrowserTableViewControl::RemoveColumnByProperty(DataBrowserTableViewColumnID) */
326
327OSStatus wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex index)
c0a66d92 328{
194027ac 329 DataBrowserTableViewColumnID propertyID;
c0a66d92 330
c0a66d92 331
194027ac
RR
332 this->GetPropertyID(index,&propertyID);
333 return ::RemoveDataBrowserTableViewColumn(this->m_controlRef,propertyID);
c17b2e31 334} /* wxMacDataBrowserTableViewControl::RemoveColumnByIndex(DataBrowserTableViewColumnIndex) */
194027ac
RR
335
336OSStatus wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID propertyID, DataBrowserTableViewColumnIndex index)
c0a66d92 337{
194027ac
RR
338 return ::SetDataBrowserTableViewColumnPosition(this->m_controlRef,propertyID,index);
339} /* wxMacDataBrowserTableViewControl::SetColumnIndex(DataBrowserPropertyID, DataBrowserTableViewColumnIndex) */
c0a66d92 340
194027ac 341OSStatus wxMacDataBrowserTableViewControl::SetDisclosureColumn(DataBrowserPropertyID propertyID, Boolean expandableRows)
c0a66d92 342{
194027ac 343 return ::SetDataBrowserListViewDisclosureColumn(this->m_controlRef,propertyID,expandableRows);
c0a66d92
RR
344}
345
194027ac
RR
346OSStatus wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID propertyID, DataBrowserPropertyFlags flags)
347{
348 return ::SetDataBrowserPropertyFlags(this->m_controlRef,propertyID,flags);
349} /* wxMacDataBrowserTableViewControl::SetPropertyFlags(DataBrowserPropertyID, DataBrowserPropertyFlags) */
350
c0a66d92
RR
351//
352// item handling
353//
354OSStatus wxMacDataBrowserTableViewControl::AddItems(DataBrowserItemID container, UInt32 numItems, DataBrowserItemID const* items, DataBrowserPropertyID preSortProperty)
355{
356 return ::AddDataBrowserItems(this->m_controlRef,container,numItems,items,preSortProperty);
357} /* wxMacDataBrowserTableViewControl::AddItems(DataBrowserItemID, UInt32, DataBrowserItemID const*, DataBrowserPropertyID) */
358
359OSStatus wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID* id) const
360{
361 ItemCount NoOfItems;
6e1609b1
VZ
362
363
c0a66d92
RR
364 verify_noerr(this->GetItemCount(&NoOfItems));
365 if (NoOfItems == 0)
366 {
367 *id = 1;
368 return noErr;
369 } /* if */
370 else
371 {
372 // 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
373 // as the number of items; therefore, start from the number of items to look for a new ID:
374 for (*id=NoOfItems; *id<std::numeric_limits<DataBrowserItemID>::max(); ++(*id))
375 if (this->IsUsedItemID(*id) == errDataBrowserItemNotFound)
376 return noErr;
377 // as the first approach was not successful, try from the beginning:
378 for (*id=0; *id<NoOfItems; ++(*id))
379 if (this->IsUsedItemID(*id) == errDataBrowserItemNotFound)
380 return noErr;
381 // sorry, data browser is full:
382 return errDataBrowserItemNotAdded;
383 } /* if */
384} /* wxMacDataBrowserTableViewControl::GetFreeItemID(DataBrowserItemID*) const */
385
386OSStatus wxMacDataBrowserTableViewControl::GetItemCount(DataBrowserItemID container, Boolean recurse, DataBrowserItemState state, ItemCount* numItems) const
387{
388 return GetDataBrowserItemCount(this->m_controlRef,container,recurse,state,numItems);
389} /* wxMacDataBrowserTableViewControl::GetItemCount(DataBrowserItemID, Boolean, DataBrowserItemState, ItemCount*) const */
390
391OSStatus wxMacDataBrowserTableViewControl::GetItemID( DataBrowserTableViewRowIndex row, DataBrowserItemID * item ) const
392{
393 return GetDataBrowserTableViewItemID(this->m_controlRef,row,item);
394}
395
396OSStatus wxMacDataBrowserTableViewControl::GetItems(DataBrowserItemID container, Boolean recurse, DataBrowserItemState state, Handle items) const
397{
398 return GetDataBrowserItems(this->m_controlRef,container,recurse,state,items);
399} /* wxMacDataBrowserTableViewControl::GetItems(DataBrowserItemID, Boolean, DataBrowserItemState, Handle) const */
400
401OSStatus wxMacDataBrowserTableViewControl::GetItemRow(DataBrowserItemID item, DataBrowserTableViewRowIndex* row) const
402{
403 return GetDataBrowserTableViewItemRow(this->m_controlRef,item,row);
404}
405
406OSStatus wxMacDataBrowserTableViewControl::IsUsedItemID(DataBrowserItemID itemID) const
407{
408 // 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
409 // 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
410 // the column position for the property id:
411 DataBrowserTableViewColumnIndex index;
6e1609b1 412
c0a66d92
RR
413 return ::GetDataBrowserTableViewItemRow(this->m_controlRef,itemID,&index);
414} /* wxMacDataBrowserTableViewControl::IsUsedItemID(DataBrowserItemID) const */
415
416OSStatus wxMacDataBrowserTableViewControl::RemoveItems(DataBrowserItemID container, UInt32 numItems, DataBrowserItemID const* items, DataBrowserPropertyID preSortProperty)
417{
418 return ::RemoveDataBrowserItems(this->m_controlRef,container,numItems,items,preSortProperty);
419}
420
421OSStatus wxMacDataBrowserTableViewControl::RevealItem(DataBrowserItemID item, DataBrowserPropertyID propertyID, DataBrowserRevealOptions options) const
422{
423 return ::RevealDataBrowserItem(this->m_controlRef,item,propertyID,options);
424} /* wxMacDataBrowserTableViewControl::RevealItem(DataBrowserItemID item, DataBrowserPropertyID propertyID, DataBrowserRevealOptions options) const */
425
426OSStatus wxMacDataBrowserTableViewControl::UpdateItems(DataBrowserItemID container, UInt32 numItems, DataBrowserItemID const* items, DataBrowserPropertyID preSortProperty,
427 DataBrowserPropertyID propertyID) const
428{
429 return UpdateDataBrowserItems(this->m_controlRef,container,numItems,items,preSortProperty,propertyID);
430}
431
432//
433// item selection
434//
435size_t wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserItemID& itemIDs) const
436{
437 DataBrowserItemID* itemIDPtr;
438 Handle handle(::NewHandle(0));
6e1609b1 439
c0a66d92
RR
440 size_t NoOfItems;
441
442
443 wxCHECK_MSG(this->GetItems(kDataBrowserNoItem,true,kDataBrowserItemIsSelected,handle) == noErr,0,_("Could not get selected items."));
444 NoOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
445 itemIDs.Empty();
446 itemIDs.Alloc(NoOfItems);
447 HLock(handle);
448 itemIDPtr = (DataBrowserItemID*) (*handle);
449 for (size_t i=0; i<NoOfItems; ++i)
450 {
451 itemIDs.Add(*itemIDPtr);
452 ++itemIDPtr;
453 } /* for */
454 HUnlock(handle);
455 DisposeHandle(handle);
456 return NoOfItems;
457} /* wxMacDataBrowserTableViewControl::GetSelectedItemIDs(wxArrayDataBrowserItemID&) const*/
458
194027ac 459OSStatus wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID* first, DataBrowserItemID* last) const
c0a66d92 460{
194027ac
RR
461 return ::GetDataBrowserSelectionAnchor(this->m_controlRef,first,last);
462} /* wxMacDataBrowserTableViewControl::GetSelectionAnchor(DataBrowserItemID*, DataBrowserItemID*) const */
c0a66d92
RR
463
464OSStatus wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags* flags) const
465{
466 return ::GetDataBrowserSelectionFlags(this->m_controlRef,flags);
467} /* wxMacDataBrowserTableViewControl::GetSelectionFlags(DataBrowserSelectionFlags*) const */
468
469bool wxMacDataBrowserTableViewControl::IsItemSelected(DataBrowserItemID item) const
470{
471 return ::IsDataBrowserItemSelected(this->m_controlRef,item);
472} /* wxMacDataBrowserTableViewControl::IsItemSelected(DataBrowserItemID) const */
473
474OSStatus wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectionFlags flags)
475{
476 return ::SetDataBrowserSelectionFlags(this->m_controlRef,flags);
477} /* wxMacDataBrowserTableViewControl::SetSelectionFlags(DataBrowserSelectionFlags) */
478
479OSStatus wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32 numItems, DataBrowserItemID const* items, DataBrowserSetOption operation)
480{
194027ac 481 return ::SetDataBrowserSelectedItems(this->m_controlRef, numItems, items, operation );
c0a66d92
RR
482} /* wxMacDataBrowserTableViewControl::SetSelectedItems(UInt32, DataBrowserItemID const*, DataBrowserSetOption) */
483
07c51ff1 484OSStatus wxMacDataBrowserTableViewControl::GetSortOrder(DataBrowserSortOrder* order) const
c0a66d92 485{
07c51ff1 486 return ::GetDataBrowserSortOrder(this->m_controlRef,order);
c0a66d92
RR
487}
488
07c51ff1 489OSStatus wxMacDataBrowserTableViewControl::GetSortProperty(DataBrowserPropertyID* propertyID) const
c0a66d92 490{
07c51ff1 491 return ::GetDataBrowserSortProperty(this->m_controlRef,propertyID);
c0a66d92
RR
492}
493
07c51ff1 494OSStatus wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID container, Boolean sortChildren)
c0a66d92 495{
07c51ff1
RR
496 return ::SortDataBrowserContainer(this->m_controlRef,container,sortChildren);
497} /* wxMacDataBrowserTableViewControl::Resort(DataBrowserItemID, Boolean) */
c0a66d92 498
194027ac 499OSStatus wxMacDataBrowserTableViewControl::SetSortOrder(DataBrowserSortOrder order)
c0a66d92 500{
194027ac 501 return ::SetDataBrowserSortOrder(this->m_controlRef,order);
c0a66d92
RR
502}
503
07c51ff1
RR
504OSStatus wxMacDataBrowserTableViewControl::SetSortProperty(DataBrowserPropertyID propertyID)
505{
506 return ::SetDataBrowserSortProperty(this->m_controlRef,propertyID);
507}
508
c17b2e31
RR
509//
510// container handling
511//
512OSStatus wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID containerID)
513{
514 return ::CloseDataBrowserContainer(this->m_controlRef,containerID);
515} /* wxMacDataBrowserTableViewControl::CloseContainer(DataBrowserItemID) */
516
517OSStatus wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID containerID)
518{
519 return ::OpenDataBrowserContainer(this->m_controlRef,containerID);
520} /* wxMacDataBrowserTableViewControl::OpenContainer(DataBrowserItemID) */
521
c0a66d92
RR
522IMPLEMENT_ABSTRACT_CLASS(wxMacDataBrowserTableViewControl,wxMacControl)
523
524// ============================================================================
194027ac 525// wxMacDataBrowserListViewControl
c0a66d92 526// ============================================================================
c0a66d92
RR
527#pragma mark -
528//
529// column handling
530//
531OSStatus wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc *columnDesc, DataBrowserTableViewColumnIndex position)
532{
533 return AddDataBrowserListViewColumn(this->m_controlRef,columnDesc,position);
534} /* wxMacDataBrowserListViewControl::AddColumn(DataBrowserListViewColumnDesc*, DataBrowserTableViewColumnIndex) */
535
536// ============================================================================
194027ac 537// wxMacDataViewDataBrowserListViewControl
c0a66d92 538// ============================================================================
c0a66d92
RR
539#pragma mark -
540//
541// constructors / destructor
542//
543wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl(wxWindow* peer, wxPoint const& pos, wxSize const& size, long style)
544 :wxMacDataBrowserListViewControl(peer,pos,size,style)
545{
546} /* wxMacDataViewDataBrowserListViewControl::wxMacDataViewDataBrowserListViewControl(wxWindow* , const wxPoint&, const wxSize&, long) */
547
548//
194027ac 549// callback functions (inherited from wxMacDataBrowserTableViewControl)
c0a66d92 550//
194027ac 551Boolean wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID itemOneID, DataBrowserItemID itemTwoID, DataBrowserPropertyID sortProperty)
c0a66d92 552{
07c51ff1
RR
553 DataBrowserSortOrder sortOrder;
554
555 DataBrowserTableViewColumnIndex columnIndex;
6e1609b1 556
194027ac 557 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
6e1609b1 558
c0a66d92 559
194027ac
RR
560 wxCHECK_MSG(dataViewCtrlPtr != NULL, false,_("Pointer to data view control not set correctly."));
561 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,false,_("Pointer to model not set correctly."));
562 if (sortProperty >= kMinPropertyID)
c0a66d92 563 {
194027ac 564 wxCHECK_MSG(this->GetColumnIndex(sortProperty,&columnIndex) == noErr,false,_("Could not determine column index."));
c0a66d92 565 } /* if */
07c51ff1
RR
566 else
567 columnIndex = 0;
568 this->GetSortOrder(&sortOrder);
569 return static_cast<Boolean>(dataViewCtrlPtr->GetModel()->Compare(wxDataViewItem(reinterpret_cast<void*>(itemOneID)),wxDataViewItem(reinterpret_cast<void*>(itemTwoID)),
570 columnIndex,sortOrder != kDataBrowserOrderDecreasing) < 0);
c0a66d92
RR
571} /* wxMacDataViewDataBrowserListViewControl::DataBrowserCompareProc(DataBrowserItemID, DataBrowserItemID, DataBrowserPropertyID) */
572
6ab2382a 573void wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemState state, Rect const* rectangle, SInt16 WXUNUSED(bitDepth), Boolean WXUNUSED(colorDevice))
c0a66d92 574{
194027ac 575 DataBrowserTableViewColumnIndex columnIndex;
c0a66d92
RR
576
577 wxDataViewColumn* dataViewColumnPtr;
578
579 wxDataViewCtrl* dataViewCtrlPtr;
6e1609b1 580
c0a66d92
RR
581 wxDataViewCustomRenderer* dataViewCustomRendererPtr;
582
583 wxVariant dataToRender;
584
c0a66d92 585 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
194027ac
RR
586 wxCHECK_RET(dataViewCtrlPtr != NULL, _("Pointer to data view control not set correctly."));
587 wxCHECK_RET(dataViewCtrlPtr->GetModel() != NULL, _("Pointer to model not set correctly."));
588 wxCHECK_RET(this->GetColumnIndex(propertyID,&columnIndex) == noErr,_("Could not determine column index."));
589 dataViewColumnPtr = dataViewCtrlPtr->GetColumn(columnIndex);
c0a66d92
RR
590 wxCHECK_RET(dataViewColumnPtr != NULL,_("No column for the specified column index existing."));
591 dataViewCustomRendererPtr = dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer());
592 wxCHECK_RET(dataViewCustomRendererPtr != NULL,_("No renderer or invalid renderer type specified for custom data column."));
350df6ae
RR
593
594 wxDataViewItem dataitem( reinterpret_cast<void*>(itemID) );
595 dataViewCtrlPtr->GetModel()->GetValue(dataToRender,dataitem,columnIndex);
c0a66d92
RR
596 dataViewCustomRendererPtr->SetValue(dataToRender);
597
598 // try to determine the content's size (drawable part):
599 Rect content;
600 RgnHandle rgn(NewRgn());
601 UInt16 headerHeight;
602
603 if (this->GetRegion(kControlContentMetaPart,rgn) == noErr)
604 GetRegionBounds(rgn,&content);
605 else
606 this->GetRect(&content);
607 ::DisposeRgn(rgn);
608 // space for the header
609 this->GetHeaderButtonHeight(&headerHeight);
610 content.top += headerHeight;
611 // extra space for the frame (todo: do not how to determine the space automatically from the control)
612 content.top += 5;
613 content.left += 5;
614 content.right -= 3;
615 content.bottom -= 3;
6e1609b1 616 // extra space for the scrollbars:
c0a66d92
RR
617 content.bottom -= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y);
618 content.right -= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
619
350df6ae
RR
620 wxDC *dc = dataViewCustomRendererPtr->GetDC();
621
622 wxRect cellrect( static_cast<int>(rectangle->left),
623 static_cast<int>(rectangle->top+2),
624 static_cast<int>(1+rectangle->right-rectangle->left),
625 static_cast<int>(rectangle->bottom-rectangle->top) );
626
627 bool is_active = IsControlActive( this->m_controlRef );
628 if (state == kDataBrowserItemIsSelected)
629 {
630
631 wxColour col( wxMacCreateCGColorFromHITheme( (is_active) ?
632 kThemeBrushAlternatePrimaryHighlightColor
633 : kThemeBrushSecondaryHighlightColor ) );
634
635 wxRect rect = cellrect;
636 Rect itemrect;
637 GetDataBrowserItemPartBounds( this->m_controlRef, itemID, propertyID,
638 kDataBrowserPropertyEnclosingPart, &itemrect );
639 rect.x = itemrect.left;
640 rect.width = itemrect.right-itemrect.left+1;
641
642 wxBrush selBrush( col );
643 wxPen oldpen( dc->GetPen() );
644 wxBrush oldbrush( dc->GetBrush() );
645 dc->SetPen( *wxTRANSPARENT_PEN );
646 dc->SetBrush( selBrush );
647 dc->DrawRectangle(rect);
648 dc->SetBrush( oldbrush );
649 dc->SetPen( oldpen );
650 }
651
652 wxDataViewModel *model = dataViewCtrlPtr->GetModel();
653 if ((columnIndex == 0) || !model->IsContainer(dataitem) || model->HasContainerColumns(dataitem))
654 {
655 // make sure that 'Render' can draw only in the allowed area:
656 dc->SetClippingRegion(content.left,content.top,content.right-content.left+1,content.bottom-content.top+1);
657 (void) (dataViewCustomRendererPtr->Render( cellrect, dc,
658 ((state == kDataBrowserItemIsSelected) ? wxDATAVIEW_CELL_SELECTED : 0)));
659 dc->DestroyClippingRegion(); // probably not necessary
660 }
661
a5388f80 662 dataViewCustomRendererPtr->SetDC(NULL);
c0a66d92
RR
663} /* wxMacDataViewDataBrowserListViewControl::DataBrowserDrawItemProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemState, Rect const*, SInt16, Boolean) */
664
194027ac 665OSStatus wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID itemID, DataBrowserPropertyID propertyID, DataBrowserItemDataRef itemData, Boolean getValue)
c0a66d92
RR
666{
667 if (getValue)
668 {
194027ac 669 // variable definitions:
07c51ff1 670 wxDataViewCtrl* dataViewCtrlPtr;
6e1609b1 671
c0a66d92 672 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
07c51ff1
RR
673 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
674 if (dataViewCtrlPtr->IsDeleting())
675 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
676 else
c0a66d92 677 {
07c51ff1
RR
678 // variable definitions:
679 DataBrowserTableViewColumnIndex columnIndex;
680 OSStatus errorStatus;
681 wxDataViewColumn* dataViewColumnPtr;
6e1609b1 682
07c51ff1
RR
683 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
684 errorStatus = this->GetColumnIndex(propertyID,&columnIndex);
685 wxCHECK_MSG(errorStatus == noErr,errorStatus,_("Could not determine column index"));
686 dataViewColumnPtr = dataViewCtrlPtr->GetColumn(columnIndex);
687 wxCHECK_MSG((dataViewColumnPtr != NULL) && (dataViewColumnPtr->GetRenderer() != NULL),errDataBrowserNotConfigured,_("There is no column or renderer for the specified column index."));
688 switch (dataViewColumnPtr->GetRenderer()->GetPropertyType())
689 {
690 case kDataBrowserCheckboxType:
c0a66d92 691 {
07c51ff1
RR
692 // variable definition:
693 ThemeButtonValue buttonValue;
c0a66d92 694
07c51ff1
RR
695 errorStatus = ::GetDataBrowserItemDataButtonValue(itemData,&buttonValue);
696 if (errorStatus == noErr)
c0a66d92 697 {
07c51ff1
RR
698 if (buttonValue == kThemeButtonOn)
699 {
700 // variable definition and initialization:
701 wxVariant modifiedData(true);
702
703 return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),static_cast<unsigned int>(columnIndex)) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured));
704 } /* if */
705 else if (buttonValue == kThemeButtonOff)
706 {
707 // variable definition and initialization:
708 wxVariant modifiedData(false);
709
710 return (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),static_cast<unsigned int>(columnIndex)) ? OSStatus(noErr) : OSStatus(errDataBrowserNotConfigured));
711 } /* if */
712 else
713 return errDataBrowserInvalidPropertyData;
c0a66d92
RR
714 } /* if */
715 else
07c51ff1
RR
716 return errorStatus;
717 } /* block */
718 case kDataBrowserTextType:
c0a66d92 719 {
07c51ff1
RR
720 // variable definitions:
721 CFStringRef stringReference;
c0a66d92 722
07c51ff1
RR
723 errorStatus = ::GetDataBrowserItemDataText(itemData,&stringReference);
724 if (errorStatus == noErr)
725 {
726 // variable definitions and initializations:
dbe4a80c 727 wxCFStringRef modifiedString(stringReference);
07c51ff1
RR
728 wxVariant modifiedData(modifiedString.AsString());
729
730 if (dataViewCtrlPtr->GetModel()->SetValue(modifiedData,wxDataViewItem(reinterpret_cast<void*>(itemID)),static_cast<unsigned int>(columnIndex)))
731 return noErr;
732 else
733 return errDataBrowserNotConfigured;
734 } /* if */
c0a66d92 735 else
07c51ff1
RR
736 return errorStatus;
737 } /* block */
738 default:
739 return errDataBrowserPropertyNotSupported;
740 } /* switch */
741 } /* if */
c0a66d92
RR
742 } /* if */
743 else
744 {
07c51ff1 745 if (propertyID >= kMinPropertyID) // in case data columns set the data
c0a66d92
RR
746 {
747 // variable definitions:
c17b2e31
RR
748 wxVariant variant;
749 wxDataViewColumn* dataViewColumnPtr;
750 wxDataViewCtrl* dataViewCtrlPtr;
6e1609b1 751
194027ac
RR
752 dataViewCtrlPtr = dynamic_cast<wxDataViewCtrl*>(this->GetPeer());
753 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
754 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
c17b2e31 755 dataViewColumnPtr = dataViewCtrlPtr->GetColumnPtr(propertyID);
194027ac 756 wxCHECK_MSG(dataViewColumnPtr != NULL,errDataBrowserNotConfigured,_("No column for the specified column position existing."));
c0a66d92 757 wxCHECK_MSG(dataViewColumnPtr->GetRenderer() != NULL,errDataBrowserNotConfigured,_("No renderer specified for column."));
194027ac 758 dataViewCtrlPtr->GetModel()->GetValue(variant,wxDataViewItem(reinterpret_cast<void*>(itemID)),dataViewColumnPtr->GetModelColumn());
c17b2e31
RR
759 if (!(variant.IsNull()))
760 {
761 dataViewColumnPtr->GetRenderer()->SetDataReference(itemData);
762 dataViewColumnPtr->GetRenderer()->SetValue(variant);
763 wxCHECK_MSG(dataViewColumnPtr->GetRenderer()->Render(),errDataBrowserNotConfigured,_("Rendering failed."));
764 } /* if */
07c51ff1 765 return noErr;
c0a66d92
RR
766 } /* if */
767 else // react on special system requests
c17b2e31 768 {
194027ac 769 switch (propertyID)
c0a66d92 770 {
07c51ff1
RR
771 case kDataBrowserContainerIsClosableProperty:
772 {
773 // variable definitions:
774 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
6e1609b1 775
07c51ff1
RR
776 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
777 // initialize wxWidget event:
778 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING,dataViewCtrlPtr->GetId()); // variable definition
6e1609b1 779
07c51ff1
RR
780 dataViewEvent.SetEventObject(dataViewCtrlPtr);
781 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
782 // finally send the equivalent wxWidget event:
937013e0 783 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
07c51ff1
RR
784 // opening the container is allowed if not vetoed:
785 return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewEvent.IsAllowed());
786 } /* block */
07c51ff1
RR
787 case kDataBrowserContainerIsOpenableProperty:
788 {
789 // variable definitions:
790 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
6e1609b1 791
07c51ff1
RR
792 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
793 // initialize wxWidget event:
794 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING,dataViewCtrlPtr->GetId()); // variable definition
6e1609b1 795
07c51ff1
RR
796 dataViewEvent.SetEventObject(dataViewCtrlPtr);
797 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
798 // finally send the equivalent wxWidget event:
937013e0 799 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
07c51ff1
RR
800 // opening the container is allowed if not vetoed:
801 return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewEvent.IsAllowed());
802 } /* block */
c0a66d92 803 case kDataBrowserItemIsContainerProperty:
194027ac
RR
804 {
805 // variable definition:
806 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
6e1609b1 807
194027ac
RR
808 wxCHECK_MSG(dataViewCtrlPtr != NULL,errDataBrowserNotConfigured,_("Pointer to data view control not set correctly."));
809 wxCHECK_MSG(dataViewCtrlPtr->GetModel() != NULL,errDataBrowserNotConfigured,_("Pointer to model not set correctly."));
810 return ::SetDataBrowserItemDataBooleanValue(itemData,dataViewCtrlPtr->GetModel()->IsContainer(wxDataViewItem(reinterpret_cast<void*>(itemID))));
811 } /* block */
c0a66d92
RR
812 case kDataBrowserItemIsEditableProperty:
813 return ::SetDataBrowserItemDataBooleanValue(itemData,true);
814 } /* switch */
c17b2e31 815 } /* if */
c0a66d92
RR
816 } /* if */
817 return errDataBrowserPropertyNotSupported;
818} /* wxMacDataViewDataBrowserListViewControl::DataBrowserGetSetItemDataProc(DataBrowserItemID, DataBrowserPropertyID, DataBrowserItemDataRef, Boolean) */
819
c17b2e31 820void wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID itemID, DataBrowserItemNotification message, DataBrowserItemDataRef itemData)
c0a66d92 821{
a5fb9253
RR
822 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->GetPeer()));
823
824
825 // 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:
826 if (dataViewCtrlPtr != NULL)
827 switch (message)
828 {
829 case kDataBrowserContainerClosed:
07c51ff1
RR
830 {
831 // initialize wxWidget event:
832 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED,dataViewCtrlPtr->GetId()); // variable definition
6e1609b1 833
07c51ff1
RR
834 dataViewEvent.SetEventObject(dataViewCtrlPtr);
835 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
836 // finally send the equivalent wxWidget event:
937013e0 837 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
a5fb9253
RR
838 } /* block */
839 break;
840 case kDataBrowserContainerOpened:
841 {
842 // initialize wxWidget event:
843 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED,dataViewCtrlPtr->GetId()); // variable definition
6e1609b1 844
a5fb9253
RR
845 dataViewEvent.SetEventObject(dataViewCtrlPtr);
846 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
847 // finally send the equivalent wxWidget event:
937013e0 848 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
a5fb9253
RR
849 // add children to the expanded container:
850 dataViewCtrlPtr->AddChildrenLevel(wxDataViewItem(reinterpret_cast<void*>(itemID)));
851 } /* block */
852 break;
853 case kDataBrowserEditStarted:
c17b2e31
RR
854 {
855 // initialize wxWidget event:
6e1609b1 856 DataBrowserPropertyID propertyID;
c17b2e31 857 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED,dataViewCtrlPtr->GetId()); // variable definition
6e1609b1 858
c17b2e31
RR
859 dataViewEvent.SetEventObject(dataViewCtrlPtr);
860 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
861 if (this->GetPropertyID(itemData,&propertyID) == noErr)
862 {
863 // variable definition and initialization:
864 DataBrowserTableViewColumnIndex columnIndex;
6e1609b1 865
c17b2e31
RR
866 wxCHECK_RET(this->GetColumnIndex(propertyID,&columnIndex),_("Column index not found."));
867 dataViewEvent.SetColumn(columnIndex);
6e1609b1 868 dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumnPtr(propertyID));
c17b2e31
RR
869 } /* if */
870 // finally send the equivalent wxWidget event:
937013e0 871 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
a5fb9253
RR
872 } /* block */
873 break;
874 case kDataBrowserEditStopped:
07c51ff1
RR
875 {
876 // initialize wxWidget event:
6e1609b1 877 DataBrowserPropertyID propertyID;
a5fb9253 878 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE,dataViewCtrlPtr->GetId()); // variable definition
6e1609b1 879
07c51ff1
RR
880 dataViewEvent.SetEventObject(dataViewCtrlPtr);
881 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
a5fb9253
RR
882 if (this->GetPropertyID(itemData,&propertyID) == noErr)
883 {
884 // variable definition and initialization:
885 DataBrowserTableViewColumnIndex columnIndex;
886
887 wxCHECK_RET(this->GetColumnIndex(propertyID,&columnIndex),_("Column index not found."));
888 dataViewEvent.SetColumn(columnIndex);
6e1609b1 889 dataViewEvent.SetDataViewColumn(dataViewCtrlPtr->GetColumnPtr(propertyID));
a5fb9253 890 } /* if */
07c51ff1 891 // finally send the equivalent wxWidget event:
937013e0 892 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
a5fb9253
RR
893 } /* block */
894 break;
895 case kDataBrowserItemAdded:
896 break; // not used anymore
897 case kDataBrowserItemDeselected:
898 break; // not implemented by wxWidgets; see kDataBrowserSelectionSetChanged
899 case kDataBrowserItemDoubleClicked:
900 {
901 // initialize wxWidget event:
902 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED,dataViewCtrlPtr->GetId()); // variable definition
6d9ecc87 903
a5fb9253
RR
904 dataViewEvent.SetEventObject(dataViewCtrlPtr);
905 dataViewEvent.SetItem(wxDataViewItem(reinterpret_cast<void*>(itemID)));
906 // finally send the equivalent wxWidget event:
937013e0 907 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
a5fb9253
RR
908 } /* block */
909 break;
910 case kDataBrowserItemRemoved:
911 break; // not used anymore
912 case kDataBrowserItemSelected:
913 break; // not implemented by wxWidgets; see kDataBrowserSelectionSetChanged
914 case kDataBrowserSelectionSetChanged:
6d9ecc87 915 {
a5fb9253
RR
916 // initialize wxWidget event:
917 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED,dataViewCtrlPtr->GetId()); // variable definition
918
919 dataViewEvent.SetEventObject(dataViewCtrlPtr);
920 dataViewEvent.SetModel (dataViewCtrlPtr->GetModel());
921 // finally send the equivalent wxWidget event:
937013e0 922 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
a5fb9253
RR
923 } /* block */
924 break;
925 case kDataBrowserUserStateChanged:
c0a66d92 926 {
a5fb9253
RR
927 // update column widths:
928 for (size_t i=0; i<dataViewCtrlPtr->GetColumnCount(); ++i)
c0a66d92 929 {
a5fb9253
RR
930 // constant definition for abbreviational purposes:
931 wxDataViewColumn* const columnPtr = dataViewCtrlPtr->GetColumn(i);
932 // variable definition:
933 UInt16 columnWidth;
6e1609b1 934
a5fb9253
RR
935 wxCHECK_RET(this->GetColumnWidth(columnPtr->GetPropertyID(),&columnWidth) == noErr,_("Column width could not be determined"));
936 columnPtr->SetWidthVariable(columnWidth);
937 } /* for */
938 // update order status:
939 DataBrowserPropertyID propertyID; // variable definition
940
941 if ((this->GetSortProperty(&propertyID) == noErr) && (propertyID >= kMinPropertyID))
942 {
943 DataBrowserSortOrder sortOrder;
944 DataBrowserTableViewColumnIndex columnIndex;
6e1609b1 945
a5fb9253 946 if ((this->GetSortOrder(&sortOrder) == noErr) && (this->GetColumnIndex(propertyID,&columnIndex) == noErr))
c0a66d92 947 {
a5fb9253
RR
948 // variable definition and initialization:
949 wxDataViewColumn* columnPtr;
950 columnPtr = dataViewCtrlPtr->GetColumn(columnIndex);
951 // check if the sort order has changed:
952 if ( columnPtr->IsSortOrderAscending() && (sortOrder == kDataBrowserOrderDecreasing) ||
953 !(columnPtr->IsSortOrderAscending()) && (sortOrder == kDataBrowserOrderIncreasing))
954 {
955 columnPtr->SetSortOrder(!(columnPtr->IsSortOrderAscending()));
956 // initialize wxWidget event:
957 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED,dataViewCtrlPtr->GetId()); // variable defintion
958
959 dataViewEvent.SetEventObject(dataViewCtrlPtr);
960 dataViewEvent.SetColumn(columnIndex);
961 dataViewEvent.SetDataViewColumn(columnPtr);
962 // finally send the equivalent wxWidget event:
937013e0 963 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
a5fb9253 964 } /* if */
c0a66d92
RR
965 } /* if */
966 } /* if */
a5fb9253
RR
967 } /* block */
968 break;
969 } /* switch */
c0a66d92
RR
970} /* wxMacDataViewDataBrowserListViewControl::DataBrowserItemNotificationProc(DataBrowserItemID, DataBrowserItemNotification, DataBrowserItemDataRef) */
971
972
6e1609b1 973#endif // wxUSE_DATAVIEWCTRL && !wxUSE_GENERICDATAVIEWCTRL