]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dataview.cpp
Correct vert alignment
[wxWidgets.git] / src / mac / carbon / dataview.cpp
CommitLineData
c0a66d92
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/mac/carbon/datavgen.cpp
3// Purpose: wxDataViewCtrl native mac implementation
4// Author:
5// Id: $Id$
6// Copyright: (c) 2007
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#if wxUSE_DATAVIEWCTRL
14
15#include "wx/dataview.h"
16
17#if !defined(wxUSE_GENERICDATAVIEWCTRL) || (wxUSE_GENERICDATAVIEWCTRL == 0)
18
19#include <limits>
20
21#include "wx/mac/carbon/databrow.h"
22
23#ifndef WX_PRECOMP
910c0f44
PC
24 #include "wx/timer.h"
25 #include "wx/settings.h"
26 #include "wx/dcclient.h"
27 #include "wx/icon.h"
c0a66d92
RR
28#endif
29
c0a66d92
RR
30#include "wx/renderer.h"
31
32//-----------------------------------------------------------------------------
33// local constants
34//-----------------------------------------------------------------------------
35
36// a list of all catchable events:
37static EventTypeSpec const eventList[] =
38{
39 {kEventClassControl, kEventControlDraw},
40 {kEventClassControl, kEventControlHit}
41};
42
43//-----------------------------------------------------------------------------
44// local functions
45//-----------------------------------------------------------------------------
46
47static pascal OSStatus wxMacDataViewCtrlEventHandler(EventHandlerCallRef handler, EventRef EventReference, void* Data)
48{
49 wxDataViewCtrl* DataViewCtrlPtr((wxDataViewCtrl*) Data); // the 'Data' variable always contains a pointer to the data view control that installed the handler
50
51 wxMacCarbonEvent CarbonEvent(EventReference) ;
52
53
54 switch (GetEventKind(EventReference))
55 {
56 case kEventControlDraw:
57 {
58 OSStatus status;
59
60 DataViewCtrlPtr->MacSetDrawingContext(CarbonEvent.GetParameter<CGContextRef>(kEventParamCGContextRef,typeCGContextRef));
61 status = ::CallNextEventHandler(handler,EventReference);
62 DataViewCtrlPtr->MacSetDrawingContext(NULL);
63 return status;
64 } /* block */
65 case kEventControlHit :
66 if (CarbonEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) == kControlButtonPart) // we only care about the header
67 {
68 ControlRef controlReference;
69 DataBrowserPropertyID columnPropertyID;
70 unsigned long columnIndex;
71 OSStatus status;
72 wxDataViewEvent DataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK,DataViewCtrlPtr->GetId());
73
74 CarbonEvent.GetParameter(kEventParamDirectObject,&controlReference);
75 // determine the column that triggered the event (this is the column that is responsible for sorting the data view):
76 status = ::GetDataBrowserSortProperty(controlReference,&columnPropertyID);
77 wxCHECK(status == noErr,status);
78 status = ::GetDataBrowserTableViewColumnPosition(controlReference,columnPropertyID,&columnIndex);
79 if (status == errDataBrowserPropertyNotFound) // user clicked into part of the header that does not have a property
80 return ::CallNextEventHandler(handler,EventReference);
81 wxCHECK(status == noErr,status);
82 // initialize wxWidget event handler:
83 DataViewEvent.SetEventObject(DataViewCtrlPtr);
84 DataViewEvent.SetColumn(columnIndex);
85 DataViewEvent.SetDataViewColumn(DataViewCtrlPtr->GetColumn(columnIndex));
86 // finally sent the equivalent wxWidget event:
99c75ebc 87#if wxCHECK_VERSION(2,9,0)
937013e0 88 DataViewCtrlPtr->HandleWindowEvent(DataViewEvent);
99c75ebc
RR
89#else
90 DataViewCtrlPtr->GetEventHandler()->ProcessEvent(DataViewEvent);
91#endif
c0a66d92
RR
92 return ::CallNextEventHandler(handler,EventReference);
93 } /* if */
94 else
95 return eventNotHandledErr;
96 } /* switch */
97
98 return eventNotHandledErr;
99} /* wxMacDataViewCtrlEventHandler(EventHandlerCallRef, EventRef, void*) */
100
a5fb9253
RR
101static DataBrowserItemID* CreateDataBrowserItemIDArray(size_t& noOfEntries, wxDataViewItemArray const& items) // returns a newly allocated pointer to valid data browser item IDs
102{
103 size_t const noOfItems = items.GetCount();
104
105 DataBrowserItemID* itemIDs(new DataBrowserItemID[noOfItems]);
106
107
108 // convert all valid data view items to data browser items
109 noOfEntries = 0;
110 for (size_t i=0; i<noOfItems; ++i)
111 if (items[i].IsOk())
112 {
113 itemIDs[noOfEntries] = reinterpret_cast<DataBrowserItemID>(items[i].GetID());
114 ++noOfEntries;
115 } /* if */
116 // done:
117 return itemIDs;
118} /* CreateDataBrowserItemIDArray(size_t&, wxDataViewItemArray const&) */
119
99c75ebc 120#if wxCHECK_VERSION(2,9,0)
dbe4a80c 121static bool InitializeColumnDescription(DataBrowserListViewColumnDesc& columnDescription, wxDataViewColumn const* columnPtr, DataBrowserPropertyID columnPropertyID, wxCFStringRef const& title)
99c75ebc
RR
122#else
123static bool InitializeColumnDescription(DataBrowserListViewColumnDesc& columnDescription, wxDataViewColumn const* columnPtr, DataBrowserPropertyID columnPropertyID, wxMacCFStringHolder const& title)
124#endif
594d5596
RR
125{
126 // set properties for the column:
127 columnDescription.propertyDesc.propertyID = columnPropertyID;
128 columnDescription.propertyDesc.propertyType = columnPtr->GetRenderer()->GetPropertyType();
129 columnDescription.propertyDesc.propertyFlags = kDataBrowserListViewSelectionColumn; // make the column selectable
99c75ebc 130 if (columnPtr->IsReorderable())
594d5596 131 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewMovableColumn;
594d5596
RR
132 if (columnPtr->IsResizeable())
133 {
134 columnDescription.headerBtnDesc.minimumWidth = 0;
135 columnDescription.headerBtnDesc.maximumWidth = 30000; // 32767 is the theoretical maximum though but 30000 looks nicer
136 } /* if */
137 else
138 {
139 columnDescription.headerBtnDesc.minimumWidth = columnPtr->GetWidth();
140 columnDescription.headerBtnDesc.maximumWidth = columnPtr->GetWidth();
141 } /* if */
99c75ebc
RR
142 if (columnPtr->IsSortable())
143 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewSortableColumn;
144 if (columnPtr->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE)
145 columnDescription.propertyDesc.propertyFlags |= kDataBrowserPropertyIsEditable;
146 if ((columnDescription.propertyDesc.propertyType == kDataBrowserCustomType) ||
147 (columnDescription.propertyDesc.propertyType == kDataBrowserDateTimeType) ||
148 (columnDescription.propertyDesc.propertyType == kDataBrowserIconAndTextType) ||
149 (columnDescription.propertyDesc.propertyType == kDataBrowserTextType))
150 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn; // enables generally the possibility to have user input for the mentioned types
151#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
152 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton;
153#endif
154 // set header's properties:
155 columnDescription.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
594d5596
RR
156 columnDescription.headerBtnDesc.titleOffset = 0;
157 columnDescription.headerBtnDesc.titleString = ::CFStringCreateCopy(kCFAllocatorDefault,title);
158 columnDescription.headerBtnDesc.initialOrder = kDataBrowserOrderIncreasing; // choose one of the orders as "undefined" is not supported anyway (s. ControlDefs.h in the HIToolbox framework)
159 columnDescription.headerBtnDesc.btnFontStyle.flags = kControlUseFontMask | kControlUseJustMask;
160 switch (columnPtr->GetAlignment())
161 {
162 case wxALIGN_CENTER:
163 case wxALIGN_CENTER_HORIZONTAL:
164 columnDescription.headerBtnDesc.btnFontStyle.just = teCenter;
165 break;
166 case wxALIGN_LEFT:
167 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushLeft;
168 break;
169 case wxALIGN_RIGHT:
170 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushRight;
171 break;
172 default:
173 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushDefault;
174 } /* switch */
175 columnDescription.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
176 columnDescription.headerBtnDesc.btnFontStyle.style = normal;
419a3607
RR
177 if (columnPtr->GetBitmap().IsOk())
178 {
179 columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentIconRef;
99c75ebc 180#if wxCHECK_VERSION(2,9,0)
968c951f 181 columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = columnPtr->GetBitmap().GetIconRef();
99c75ebc
RR
182#else
183 columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = columnPtr->GetBitmap().GetBitmapData()->GetIconRef();
184#endif
419a3607
RR
185 }
186 else
187 {
188 // not text only as we otherwise could not add a bitmap later
189 // columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
190 columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentIconRef;
191 columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = NULL;
192 }
193
594d5596
RR
194 // done:
195 return true;
99c75ebc 196} /* InitializeColumnDescription(DataBrowserListViewColumnDesc&, wxDataViewColumn const*, DataBrowserPropertyID, wxMacCFStringHolder const&) */
594d5596 197
c0a66d92
RR
198//-----------------------------------------------------------------------------
199// local function pointers
200//-----------------------------------------------------------------------------
201
202DEFINE_ONE_SHOT_HANDLER_GETTER(wxMacDataViewCtrlEventHandler)
203
204// ---------------------------------------------------------
194027ac 205// wxMacDataViewModelNotifier
c0a66d92
RR
206// ---------------------------------------------------------
207#pragma mark -
194027ac 208class wxMacDataViewModelNotifier : public wxDataViewModelNotifier
c0a66d92
RR
209{
210public:
194027ac 211 wxMacDataViewModelNotifier(wxMacDataViewDataBrowserListViewControl* initDataViewControlPtr) : m_dataViewControlPtr(initDataViewControlPtr)
c0a66d92
RR
212 {
213 }
214
194027ac 215 virtual bool ItemAdded(const wxDataViewItem &parent, const wxDataViewItem &item)
c0a66d92 216 {
194027ac
RR
217 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
218
219
220 wxCHECK_MSG(item.IsOk(),false,_("Added item is invalid."));
07c51ff1
RR
221 return (!(parent.IsOk()) && (this->m_dataViewControlPtr->AddItem(kDataBrowserNoItem,&itemID) == noErr) ||
222 parent.IsOk() && (this->m_dataViewControlPtr->AddItem(reinterpret_cast<DataBrowserItemID>(parent.GetID()),&itemID) == noErr));
194027ac
RR
223 } /* ItemAdded(wxDataViewItem const&, wxDataViewItem const&) */
224
a5fb9253
RR
225 virtual bool ItemsAdded(wxDataViewItem const& parent, wxDataViewItemArray const& items)
226 {
227 bool noFailureFlag;
228
229 DataBrowserItemID* itemIDs;
230
231 size_t noOfEntries;
232
233
234 // convert all valid data view items to data browser items:
235 itemIDs = ::CreateDataBrowserItemIDArray(noOfEntries,items);
236 // insert all valid items into control:
237 noFailureFlag = ((noOfEntries == 0) ||
238 !(parent.IsOk()) && (this->m_dataViewControlPtr->AddItems(kDataBrowserNoItem,noOfEntries,itemIDs,kDataBrowserItemNoProperty) == noErr) ||
239 parent.IsOk() && (this->m_dataViewControlPtr->AddItems(reinterpret_cast<DataBrowserItemID>(parent.GetID()),noOfEntries,itemIDs,kDataBrowserItemNoProperty) == noErr));
240 // give allocated array space free again:
241 delete[] itemIDs;
242 // done:
243 return noFailureFlag;
244 } /* ItemsAdded(wxDataViewItem const&, wxDataViewItemArray const&) */
245
194027ac 246 virtual bool ItemChanged(wxDataViewItem const& item)
c0a66d92 247 {
194027ac 248 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
c0a66d92
RR
249
250
a5fb9253 251 wxCHECK_MSG(item.IsOk(),false,_("Changed item is invalid."));
194027ac 252 if (this->m_dataViewControlPtr->UpdateItems(&itemID) == noErr)
c0a66d92
RR
253 {
254 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
255
256 // sent the equivalent wxWidget event:
a5fb9253 257 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,dataViewCtrlPtr->GetId()); // variable defintion
c0a66d92
RR
258
259 dataViewEvent.SetEventObject(dataViewCtrlPtr);
194027ac 260 dataViewEvent.SetItem(item);
c0a66d92 261 // sent the equivalent wxWidget event:
99c75ebc 262#if wxCHECK_VERSION(2,9,0)
937013e0 263 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
99c75ebc
RR
264#else
265 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
266#endif
c0a66d92
RR
267 // done
268 return true;
269 } /* if */
270 else
271 return false;
194027ac 272 } /* ItemChanged(wxDataViewItem const&) */
c0a66d92 273
a5fb9253
RR
274 virtual bool ItemsChanged(wxDataViewItemArray const& items)
275 {
276 bool noFailureFlag;
277
278 DataBrowserItemID* itemIDs;
279
280 size_t noOfEntries;
281
282
283 // convert all valid data view items to data browser items:
284 itemIDs = ::CreateDataBrowserItemIDArray(noOfEntries,items);
285 // change items (ATTENTION: ONLY ITEMS OF THE ROOT ARE CHANGED BECAUSE THE PARENT PARAMETER IS MISSING):
286 noFailureFlag = (this->m_dataViewControlPtr->UpdateItems(kDataBrowserNoItem,noOfEntries,itemIDs,kDataBrowserItemNoProperty,kDataBrowserItemNoProperty) == noErr);
287 if (noFailureFlag)
288 {
289 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
290
291 // send for all changed items a wxWidget event:
292 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,dataViewCtrlPtr->GetId()); // variable defintion
293
294 dataViewEvent.SetEventObject(dataViewCtrlPtr);
295 for (size_t i=0; i<noOfEntries; ++i)
296 {
297 dataViewEvent.SetItem(reinterpret_cast<void*>(itemIDs[i]));
99c75ebc 298#if wxCHECK_VERSION(2,9,0)
937013e0 299 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
99c75ebc
RR
300#else
301 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
302#endif
a5fb9253
RR
303 } /* for */
304 } /* if */
305 // release allocated array space:
306 delete[] itemIDs;
307 // done:
308 return noFailureFlag;
309 } /* ItemsChanged(wxDataViewItem const&) */
310
194027ac 311 virtual bool ItemDeleted(wxDataViewItem const& parent, wxDataViewItem const& item)
c0a66d92 312 {
07c51ff1 313 if (item.IsOk())
c0a66d92 314 {
07c51ff1
RR
315 // variable definition and initialization:
316 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
317 OSStatus errorStatus;
318 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
319
320 // when this method is called and currently an item is being edited this item may have already been deleted in the model (the passed item and the being edited item have
a5fb9253
RR
321 // not to be identical because the being edited item might be below the passed item in the hierarchy);
322 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
323 // has been started and that variables can currently not be updated even when requested by the system:
07c51ff1
RR
324 dataViewCtrlPtr->SetDeleting(true);
325 errorStatus = this->m_dataViewControlPtr->RemoveItem(reinterpret_cast<DataBrowserItemID>(parent.GetID()),&itemID);
a5fb9253 326 // enable automatic updating again:
07c51ff1
RR
327 dataViewCtrlPtr->SetDeleting(false);
328 return (errorStatus == noErr);
c0a66d92
RR
329 } /* if */
330 else
331 return false;
07c51ff1 332 } /* ItemDeleted(wxDataViewItem const&, wxDataViewItem const&) */
194027ac 333
a5fb9253
RR
334 virtual bool ItemsDeleted(wxDataViewItem const& parent, wxDataViewItemArray const& items)
335 {
336 bool noFailureFlag;
337
338 DataBrowserItemID* itemIDs;
339
340 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
341
342 size_t noOfEntries;
343
344
345 wxCHECK_MSG(dataViewCtrlPtr != NULL,false,_("Data view control is not correctly initialized"));
346 // convert all valid data view items to data browser items:
347 itemIDs = ::CreateDataBrowserItemIDArray(noOfEntries,items);
348 // when this method is called and currently an item is being edited this item may have already been deleted in the model (the passed item and the being edited item have
349 // not to be identical because the being edited item might be below the passed item in the hierarchy);
350 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
351 // has been started and that variables can currently not be updated even when requested by the system:
352 dataViewCtrlPtr->SetDeleting(true);
353 // insert all valid items into control:
354 noFailureFlag = ((noOfEntries == 0) ||
355 !(parent.IsOk()) && (this->m_dataViewControlPtr->RemoveItems(kDataBrowserNoItem,noOfEntries,itemIDs,kDataBrowserItemNoProperty) == noErr) ||
356 parent.IsOk() && (this->m_dataViewControlPtr->RemoveItems(reinterpret_cast<DataBrowserItemID>(parent.GetID()),noOfEntries,itemIDs,kDataBrowserItemNoProperty) == noErr));
357 // enable automatic updating again:
358 dataViewCtrlPtr->SetDeleting(false);
359 // give allocated array space free again:
360 delete[] itemIDs;
361 // done:
362 return noFailureFlag;
363 } /* ItemsDeleted(wxDataViewItem const&, wxDataViewItemArray const&) */
364
194027ac 365 virtual bool ValueChanged(wxDataViewItem const& item, unsigned int col)
c0a66d92 366 {
194027ac
RR
367 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
368 DataBrowserItemID parentID;
c0a66d92
RR
369
370 DataBrowserPropertyID propertyID;
371
194027ac
RR
372 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
373
374
375 wxCHECK_MSG(item.IsOk(), false,_("Passed item is invalid."));
376 wxCHECK_MSG(this->GetOwner() != NULL,false,_("Owner not initialized."));
377 wxCHECK_MSG(dataViewCtrlPtr != NULL, false,_("Control is wrongly initialized."));
378 parentID = reinterpret_cast<DataBrowserItemID>(this->GetOwner()->GetParent(item).GetID());
379 if ((this->m_dataViewControlPtr->GetPropertyID(col,&propertyID) == noErr) &&
380 (this->m_dataViewControlPtr->UpdateItems(parentID,1,&itemID,dataViewCtrlPtr->GetColumn(col)->GetPropertyID(),propertyID) == noErr))
c0a66d92 381 {
194027ac 382 // variable definition and initialization:
6608fdab 383 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED,dataViewCtrlPtr->GetId());
c0a66d92
RR
384
385 dataViewEvent.SetEventObject(dataViewCtrlPtr);
386 dataViewEvent.SetColumn(col);
194027ac
RR
387 dataViewEvent.SetItem(item);
388 // send the equivalent wxWidget event:
99c75ebc 389#if wxCHECK_VERSION(2,9,0)
937013e0 390 dataViewCtrlPtr->HandleWindowEvent(dataViewEvent);
99c75ebc
RR
391#else
392 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
393#endif
c0a66d92
RR
394 // done
395 return true;
396 } /* if */
397 else
398 return false;
194027ac 399 } /* ValueChanged(wxDataViewItem const&, unsigned int) */
c0a66d92 400
c0a66d92
RR
401 virtual bool Cleared(void)
402 {
33ba5a05
RR
403 bool noFailureFlag = (this->m_dataViewControlPtr->RemoveItems() == noErr);
404 wxDataViewItem item;
405 wxDataViewItemArray array;
406 GetOwner()->GetChildren( item, array );
407 ItemsAdded( item, array );
408 return noFailureFlag;
194027ac 409 } /* Cleared(void) */
c0a66d92 410
07c51ff1
RR
411 virtual void Resort(void)
412 {
413 this->m_dataViewControlPtr->Resort();
414 }
415
c0a66d92
RR
416protected:
417private:
418//
419// variables
420//
421 wxMacDataViewDataBrowserListViewControl* m_dataViewControlPtr;
422};
423
424// ---------------------------------------------------------
425// wxDataViewRenderer
426// ---------------------------------------------------------
427#pragma mark -
428wxDataViewRenderer::wxDataViewRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
429 :wxDataViewRendererBase(varianttype,mode,align), m_alignment(align), m_mode(mode)
430{
431} /* wxDataViewRenderer::wxDataViewRenderer(wxString const&, wxDataViewCellMode) */
432
433void wxDataViewRenderer::SetMode(wxDataViewCellMode mode)
434{
435 wxDataViewColumn* dataViewColumnPtr;
436
437
438 this->m_mode = mode;
439 dataViewColumnPtr = this->GetOwner();
440 if (dataViewColumnPtr != NULL)
441 {
442 // variable definition and initialization:
443 wxDataViewCtrl* dataViewCtrlPtr(dataViewColumnPtr->GetOwner());
444
445 if (dataViewCtrlPtr != NULL)
446 {
447 // variable definition and initialization:
448 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
449
450 if (macDataViewListCtrlPtr != NULL)
451 {
452 // variable definition and initialization:
453 DataBrowserPropertyFlags flags;
454
455 verify_noerr(macDataViewListCtrlPtr->GetPropertyFlags(dataViewColumnPtr->GetPropertyID(),&flags));
456 if (mode == wxDATAVIEW_CELL_EDITABLE)
457 flags |= kDataBrowserPropertyIsEditable;
458 else
459 flags &= ~kDataBrowserPropertyIsEditable;
460 verify_noerr(macDataViewListCtrlPtr->SetPropertyFlags(dataViewColumnPtr->GetPropertyID(),flags));
461 } /* if */
462 } /* if */
463 } /* if */
464} /* wxDataViewRenderer::SetMode(wxDataViewCellMode) */
465
466IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer,wxDataViewRendererBase)
467
468// ---------------------------------------------------------
469// wxDataViewCustomRenderer
470// ---------------------------------------------------------
471#pragma mark -
472wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
c17b2e31 473 :wxDataViewRenderer(varianttype,mode,align), m_editorCtrlPtr(NULL), m_DCPtr(NULL)
c0a66d92
RR
474{
475} /* wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const&, wxDataViewCellMode) */
476
477wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void)
478{
479 if (this->m_DCPtr != NULL)
480 delete this->m_DCPtr;
481} /* wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) */
482
52e750fc
RR
483void wxDataViewCustomRenderer::RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state )
484{
485 wxDataViewCtrl *view = GetOwner()->GetOwner();
99c75ebc 486 wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) : view->GetForegroundColour();
52e750fc
RR
487 dc->SetTextForeground(col);
488 dc->DrawText( text, cell.x + xoffset, cell.y + ((cell.height - dc->GetCharHeight()) / 2));
489}
490
c0a66d92
RR
491wxDC* wxDataViewCustomRenderer::GetDC(void)
492{
493 if (this->m_DCPtr == NULL)
494 {
495 if ((GetOwner() == NULL) || (GetOwner()->GetOwner() == NULL))
496 return NULL;
350df6ae 497 this->m_DCPtr = new wxWindowDC(this->GetOwner()->GetOwner());
c0a66d92
RR
498 } /* if */
499 return this->m_DCPtr;
500} /* wxDataViewCustomRenderer::GetDC(void) */
501
502bool wxDataViewCustomRenderer::Render(void)
503{
c17b2e31 504 return true;
c0a66d92
RR
505} /* wxDataViewCustomRenderer::Render(void) */
506
507void wxDataViewCustomRenderer::SetDC(wxDC* newDCPtr)
508{
509 delete this->m_DCPtr;
510 this->m_DCPtr = newDCPtr;
511} /* wxDataViewCustomRenderer::SetDC(wxDC*) */
512
594d5596 513WXDataBrowserPropertyType wxDataViewCustomRenderer::GetPropertyType(void) const
34b1fdeb 514{
594d5596
RR
515 return kDataBrowserCustomType;
516} /* wxDataViewCustomRenderer::GetPropertyType(void) const */
c0a66d92
RR
517
518IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
519
520// ---------------------------------------------------------
521// wxDataViewTextRenderer
522// ---------------------------------------------------------
523#pragma mark -
524wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
525 :wxDataViewRenderer(varianttype,mode,align)
526{
527} /* wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const&, wxDataViewCellMode, int) */
528
529bool wxDataViewTextRenderer::Render(void)
530{
99c75ebc 531 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Text renderer cannot render value; value type: ")) << this->GetValue().GetType());
c0a66d92 532
99c75ebc
RR
533 // variable definition:
534#if wxCHECK_VERSION(2,9,0)
535 wxCFStringRef cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
536#else
537 wxMacCFStringHolder cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
538#endif
539 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString) == noErr);
c0a66d92
RR
540} /* wxDataViewTextRenderer::Render(void) */
541
594d5596 542WXDataBrowserPropertyType wxDataViewTextRenderer::GetPropertyType(void) const
34b1fdeb 543{
594d5596
RR
544 return kDataBrowserTextType;
545} /* wxDataViewTextRenderer::GetPropertyType(void) const */
34b1fdeb 546
c0a66d92
RR
547IMPLEMENT_CLASS(wxDataViewTextRenderer,wxDataViewRenderer)
548
594d5596
RR
549// ---------------------------------------------------------
550// wxDataViewTextRendererAttr
551// ---------------------------------------------------------
552#pragma mark -
553wxDataViewTextRendererAttr::wxDataViewTextRendererAttr(wxString const& varianttype, wxDataViewCellMode mode, int align)
554 :wxDataViewTextRenderer(varianttype,mode,align)
555{
556} /* wxDataViewTextRendererAttr::wxDataViewTextRendererAttr(wxString const&, wxDataViewCellMode, int) */
557
558IMPLEMENT_CLASS(wxDataViewTextRendererAttr,wxDataViewTextRenderer)
559
c0a66d92
RR
560// ---------------------------------------------------------
561// wxDataViewBitmapRenderer
562// ---------------------------------------------------------
563#pragma mark -
564wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
565 :wxDataViewRenderer(varianttype,mode,align)
566{
567}
568
569bool wxDataViewBitmapRenderer::Render(void)
99c75ebc
RR
570 // This method returns 'true' if
571 // - the passed bitmap is valid and it could be assigned to the native data browser;
572 // - the passed bitmap is invalid (or is not initialized); this case simulates a non-existing bitmap.
573 // In all other cases the method returns 'false'.
c0a66d92 574{
99c75ebc
RR
575 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Bitmap renderer cannot render value; value type: ")) << this->GetValue().GetType());
576
577 // variable definition:
578 wxBitmap bitmap;
579
580 bitmap << this->GetValue();
581 if (bitmap.Ok())
582#if wxCHECK_VERSION(2,9,0)
583 return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap.GetIconRef()) == noErr);
584#else
585 return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap.GetBitmapData()->GetIconRef()) == noErr);
586#endif
c0a66d92 587 else
99c75ebc 588 return true;
c0a66d92
RR
589} /* wxDataViewBitmapRenderer::Render(void) */
590
594d5596 591WXDataBrowserPropertyType wxDataViewBitmapRenderer::GetPropertyType(void) const
34b1fdeb 592{
594d5596
RR
593 return kDataBrowserIconType;
594} /* wxDataViewBitmapRenderer::GetPropertyType(void) const */
34b1fdeb 595
c0a66d92
RR
596IMPLEMENT_CLASS(wxDataViewBitmapRenderer,wxDataViewRenderer)
597
c17b2e31
RR
598// ---------------------------------------------------------
599// wxDataViewIconTextRenderer
600// ---------------------------------------------------------
601#pragma mark -
602wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
603 :wxDataViewRenderer(varianttype,mode)
604{
605}
606
607bool wxDataViewIconTextRenderer::Render(void)
608{
99c75ebc 609 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Icon & text renderer cannot render value; value type: ")) << this->GetValue().GetType());
c17b2e31 610
99c75ebc
RR
611 // variable definition:
612 wxDataViewIconText iconText;
613
614 iconText << this->GetValue();
c576a25a 615
99c75ebc
RR
616 // variable definition:
617#if wxCHECK_VERSION(2,9,0)
618 wxCFStringRef cfString(iconText.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
619#else
620 wxMacCFStringHolder cfString(iconText.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
621#endif
622
623 if (iconText.GetIcon().IsOk())
624 if (::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText.GetIcon().GetHICON())) != noErr)
625 return false;
626 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString) == noErr);
c17b2e31
RR
627} /* wxDataViewIconTextRenderer::Render(void) */
628
594d5596 629WXDataBrowserPropertyType wxDataViewIconTextRenderer::GetPropertyType(void) const
34b1fdeb 630{
594d5596
RR
631 return kDataBrowserIconAndTextType;
632} /* wxDataViewIconTextRenderer::GetPropertyType(void) const */
34b1fdeb 633
c17b2e31
RR
634IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer,wxDataViewRenderer)
635
636
c0a66d92
RR
637// ---------------------------------------------------------
638// wxDataViewToggleRenderer
639// ---------------------------------------------------------
640#pragma mark -
641wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
642 :wxDataViewRenderer(varianttype,mode)
643{
644}
645
646bool wxDataViewToggleRenderer::Render(void)
647{
99c75ebc
RR
648 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Toggle renderer cannot render value; value type: ")) << this->GetValue().GetType());
649 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr);
c0a66d92
RR
650} /* wxDataViewToggleRenderer::Render(void) */
651
594d5596 652WXDataBrowserPropertyType wxDataViewToggleRenderer::GetPropertyType(void) const
34b1fdeb 653{
594d5596
RR
654 return kDataBrowserCheckboxType;
655} /* wxDataViewToggleRenderer::GetPropertyType(void) const */
34b1fdeb 656
c0a66d92
RR
657IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer,wxDataViewRenderer)
658
659// ---------------------------------------------------------
660// wxDataViewProgressRenderer
661// ---------------------------------------------------------
662#pragma mark -
663wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString const& label, wxString const& varianttype, wxDataViewCellMode mode, int align)
664 :wxDataViewRenderer(varianttype,mode,align)
665{
666}
667
668bool wxDataViewProgressRenderer::Render(void)
669{
99c75ebc
RR
670 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Progress renderer cannot render value type; value type: ")) << this->GetValue().GetType());
671 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr) &&
672 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr) &&
673 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr));
c0a66d92
RR
674} /* wxDataViewProgressRenderer::Render(void) */
675
594d5596 676WXDataBrowserPropertyType wxDataViewProgressRenderer::GetPropertyType(void) const
34b1fdeb 677{
594d5596
RR
678 return kDataBrowserProgressBarType;
679} /* wxDataViewProgressRenderer::GetPropertyType(void) const */
34b1fdeb 680
c0a66d92
RR
681IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer,wxDataViewRenderer)
682
683// ---------------------------------------------------------
684// wxDataViewDateRenderer
685// ---------------------------------------------------------
686#pragma mark -
687wxDataViewDateRenderer::wxDataViewDateRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
688 :wxDataViewRenderer(varianttype,mode,align)
689{
690}
691
692bool wxDataViewDateRenderer::Render(void)
693{
99c75ebc
RR
694 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Date renderer cannot render value; value type: ")) << this->GetValue().GetType());
695 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan,1904)).GetSeconds().GetLo()) == noErr);
c0a66d92
RR
696} /* wxDataViewDateRenderer::Render(void) */
697
594d5596 698WXDataBrowserPropertyType wxDataViewDateRenderer::GetPropertyType(void) const
34b1fdeb 699{
594d5596
RR
700 return kDataBrowserDateTimeType;
701} /* wxDataViewDateRenderer::GetPropertyType(void) const */
34b1fdeb 702
c0a66d92
RR
703IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer,wxDataViewRenderer)
704
705// ---------------------------------------------------------
706// wxDataViewColumn
707// ---------------------------------------------------------
708#pragma mark -
709wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags)
99c75ebc 710 :wxDataViewColumnBase(title,cell,model_column,width,align,flags), m_ascending(true),
b741dd40 711 m_flags(flags & ~(wxDATAVIEW_COL_HIDDEN)), m_maxWidth(30000), m_minWidth(0), m_width(width >= 0 ? width : wxDVC_DEFAULT_WIDTH),
194027ac 712 m_alignment(align), m_title(title)
c0a66d92
RR
713{
714} /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
715
716wxDataViewColumn::wxDataViewColumn(wxBitmap const& bitmap, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags)
99c75ebc 717 :wxDataViewColumnBase(bitmap,cell,model_column,width,align,flags), m_ascending(true),
b741dd40 718 m_flags(flags & ~(wxDATAVIEW_COL_HIDDEN)), m_maxWidth(30000), m_minWidth(0), m_width(width >= 0 ? width : wxDVC_DEFAULT_WIDTH),
194027ac 719 m_alignment(align)
c0a66d92
RR
720{
721} /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
722
723void wxDataViewColumn::SetAlignment(wxAlignment align)
724{
725 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
726
727
728 this->m_alignment = align;
729 if (dataViewCtrlPtr != NULL)
730 {
731 // variable definition and initialization:
732 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
733
734 if (macDataViewListCtrlPtr != NULL)
735 {
736 // variable definition and initialization:
737 DataBrowserListViewHeaderDesc headerDescription;
738
739 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
740 switch (align)
741 {
742 case wxALIGN_CENTER:
743 case wxALIGN_CENTER_HORIZONTAL:
744 headerDescription.btnFontStyle.just = teCenter;
745 break;
746 case wxALIGN_LEFT:
747 headerDescription.btnFontStyle.just = teFlushLeft;
748 break;
749 case wxALIGN_RIGHT:
750 headerDescription.btnFontStyle.just = teFlushRight;
751 break;
752 default:
753 headerDescription.btnFontStyle.just = teFlushDefault;
754 } /* switch */
755 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set alignment."));
756 } /* if */
757 } /* if */
758} /* wxDataViewColumn::SetAlignment(wxAlignment) */
759
760void wxDataViewColumn::SetBitmap(wxBitmap const& bitmap)
761{
762 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
763
764
765 wxDataViewColumnBase::SetBitmap(bitmap);
766 if (dataViewCtrlPtr != NULL)
767 {
768 // variable definition and initialization:
769 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
770
771 if (macDataViewListCtrlPtr != NULL)
772 {
773 // variable definition and initialization:
774 DataBrowserListViewHeaderDesc headerDescription;
775
776 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
777 if (this->GetBitmap().Ok())
99c75ebc 778#if wxCHECK_VERSION(2,9,0)
968c951f 779 headerDescription.btnContentInfo.u.iconRef = this->GetBitmap().GetIconRef();
99c75ebc
RR
780#else
781 headerDescription.btnContentInfo.u.iconRef = this->GetBitmap().GetBitmapData()->GetIconRef();
782#endif
c0a66d92
RR
783 else
784 headerDescription.btnContentInfo.u.iconRef = NULL;
785 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set icon."));
786 } /* if */
787 } /* if */
788} /* wxDataViewColumn::SetBitmap(wxBitmap const&) */
789
790void wxDataViewColumn::SetFlags(int flags)
791{
99c75ebc
RR
792 this->SetHidden ((flags & wxDATAVIEW_COL_HIDDEN) != 0);
793 this->SetReorderable((flags & wxDATAVIEW_COL_REORDERABLE) != 0);
794 this->SetResizeable ((flags & wxDATAVIEW_COL_RESIZABLE) != 0);
795 this->SetSortable ((flags & wxDATAVIEW_COL_SORTABLE) != 0);
c0a66d92
RR
796} /* wxDataViewColumn::SetFlags(int) */
797
798void wxDataViewColumn::SetMaxWidth(int maxWidth)
799{
800 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
801
802
803 this->m_maxWidth = maxWidth;
804 if (dataViewCtrlPtr != NULL)
805 {
806 // variable definition and initialization:
807 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
808
809 if (macDataViewListCtrlPtr != NULL)
810 {
811 // variable definition and initialization:
812 DataBrowserListViewHeaderDesc headerDescription;
813
814 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
815 headerDescription.maximumWidth = static_cast<UInt16>(maxWidth);
816 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set maximum width."));
817 } /* if */
818 } /* if */
819} /* wxDataViewColumn::SetMaxWidth(int) */
820
821void wxDataViewColumn::SetMinWidth(int minWidth)
822{
823 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
824
825
826 this->m_minWidth = minWidth;
827 if (dataViewCtrlPtr != NULL)
828 {
829 // variable definition and initialization:
830 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
831
832 if (macDataViewListCtrlPtr != NULL)
833 {
834 // variable definition and initialization:
835 DataBrowserListViewHeaderDesc headerDescription;
836
837 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
838 headerDescription.minimumWidth = static_cast<UInt16>(minWidth);
839 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set minimum width."));
840 } /* if */
841 } /* if */
842} /* wxDataViewColumn::SetMaxWidth(int) */
843
99c75ebc
RR
844void wxDataViewColumn::SetReorderable(bool reorderable)
845{
846 // first set the internal flag of the column:
847 if (reorderable)
848 this->m_flags |= wxDATAVIEW_COL_REORDERABLE;
849 else
850 this->m_flags &= ~wxDATAVIEW_COL_REORDERABLE;
851 // if the column is associated with a control change also immediately the flags of the control:
852 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner()); // variable definition and initialization
853
854 if (dataViewCtrlPtr != NULL)
855 {
856 // variable definition and initialization:
857 DataBrowserPropertyFlags flags;
858 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
859
860 wxCHECK_RET(macDataViewListCtrlPtr != NULL, _("Valid pointer to native data view control does not exist"));
861 wxCHECK_RET(macDataViewListCtrlPtr->GetPropertyFlags(this->GetPropertyID(),&flags) == noErr,_("Could not get property flags."));
862 if (reorderable)
863 flags |= kDataBrowserListViewMovableColumn;
864 else
865 flags &= ~kDataBrowserListViewMovableColumn;
866 wxCHECK_RET(macDataViewListCtrlPtr->SetPropertyFlags(this->GetPropertyID(),flags) == noErr,_("Could not set property flags."));
867 } /* if */
868} /* wxDataViewColumn::SetReorderable(bool) */
869
9534c003 870void wxDataViewColumn::SetResizeable(bool resizeable)
c0a66d92 871{
9534c003
RR
872 // first set the internal flag of the column:
873 if (resizeable)
874 this->m_flags |= wxDATAVIEW_COL_RESIZABLE;
875 else
876 this->m_flags &= ~wxDATAVIEW_COL_RESIZABLE;
877 // if the column is associated with a control change also immediately the flags of the control:
878 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner()); // variable definition and initialization
879
880 if (dataViewCtrlPtr != NULL)
881 {
882 // variable definition and initialization:
883 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
884
885 if (macDataViewListCtrlPtr != NULL)
886 {
887 // variable definition and initialization:
888 DataBrowserListViewHeaderDesc headerDescription;
889
890 verify_noerr(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription));
891 if (resizeable) {
892 headerDescription.minimumWidth = 0;
893 headerDescription.maximumWidth = 30000;
894 }
895 else {
896 headerDescription.minimumWidth = this->m_width;
897 headerDescription.maximumWidth = this->m_width;
898 }
899 verify_noerr(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription));
900 macDataViewListCtrlPtr->SetSortProperty(this->GetPropertyID());
901 } /* if */
902 } /* if */
c0a66d92
RR
903} /* wxDataViewColumn::SetResizeable(bool) */
904
905void wxDataViewColumn::SetSortable(bool sortable)
906{
99c75ebc
RR
907 // first set the internal flag of the column:
908 if (sortable)
909 this->m_flags |= wxDATAVIEW_COL_SORTABLE;
910 else
911 this->m_flags &= ~wxDATAVIEW_COL_SORTABLE;
912 // if the column is associated with a control change also immediately the flags of the control:
913 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner()); // variable definition and initialization
914
c0a66d92
RR
915 if (dataViewCtrlPtr != NULL)
916 {
917 // variable definition and initialization:
99c75ebc 918 DataBrowserPropertyFlags flags;
c0a66d92
RR
919 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
920
99c75ebc
RR
921 wxCHECK_RET(macDataViewListCtrlPtr != NULL, _("Valid pointer to native data view control does not exist"));
922 wxCHECK_RET(macDataViewListCtrlPtr->GetPropertyFlags(this->GetPropertyID(),&flags) == noErr,_("Could not get property flags."));
923 if (sortable)
924 flags |= kDataBrowserListViewSortableColumn;
925 else
926 flags &= ~kDataBrowserListViewSortableColumn;
927 wxCHECK_RET(macDataViewListCtrlPtr->SetPropertyFlags(this->GetPropertyID(),flags) == noErr,_("Could not set property flags."));
c0a66d92
RR
928 } /* if */
929} /* wxDataViewColumn::SetSortable(bool) */
930
931void wxDataViewColumn::SetSortOrder(bool ascending)
932{
933 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
934
935
936 this->m_ascending = ascending;
937 if (dataViewCtrlPtr != NULL)
938 {
939 // variable definition and initialization:
940 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
941
942 if (macDataViewListCtrlPtr != NULL)
943 {
944 // variable definition and initialization:
945 DataBrowserListViewHeaderDesc headerDescription;
946
947 verify_noerr(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription));
948 if (ascending)
949 headerDescription.initialOrder = kDataBrowserOrderIncreasing;
950 else
951 headerDescription.initialOrder = kDataBrowserOrderDecreasing;
952 verify_noerr(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription));
6d9ecc87 953 macDataViewListCtrlPtr->SetSortProperty(this->GetPropertyID());
c0a66d92
RR
954 } /* if */
955 } /* if */
956} /* wxDataViewColumn::SetSortOrder(bool) */
957
958void wxDataViewColumn::SetTitle(wxString const& title)
959{
960 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
961
962
963 this->m_title = title;
964 if (dataViewCtrlPtr != NULL)
965 {
966 // variable definition and initialization:
967 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
968
969 if (macDataViewListCtrlPtr != NULL)
970 {
971 // variable definition and initialization:
972 DataBrowserListViewHeaderDesc headerDescription;
99c75ebc 973#if wxCHECK_VERSION(2,9,0)
dbe4a80c 974 wxCFStringRef cfTitle(title,(dataViewCtrlPtr->GetFont().Ok() ? dataViewCtrlPtr->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
99c75ebc
RR
975#else
976 wxMacCFStringHolder cfTitle(title,(dataViewCtrlPtr->GetFont().Ok() ? dataViewCtrlPtr->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
977#endif
c0a66d92
RR
978
979 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
980 headerDescription.titleString = cfTitle;
981 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set header description."));
982 } /* if */
983 } /* if */
984} /* wxDataViewColumn::SetTitle(wxString const&) */
985
986void wxDataViewColumn::SetWidth(int width)
987{
988 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
989
990
991 if ((width >= this->m_minWidth) && (width <= this->m_maxWidth))
992 {
993 this->m_width = width;
994 if (dataViewCtrlPtr != NULL)
995 {
996 // variable definition and initialization:
997 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
998
999 if (macDataViewListCtrlPtr != NULL)
1000 wxCHECK_RET(macDataViewListCtrlPtr->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16>(width)) == noErr,_("Could not set column width."));
1001 } /* if */
1002 } /* if */
1003} /* wxDataViewColumn::SetWidth(int) */
1004
1005IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn,wxDataViewColumnBase)
1006
1007//-----------------------------------------------------------------------------
1008// wxDataViewCtrl
1009//-----------------------------------------------------------------------------
1010#pragma mark -
1011void wxDataViewCtrl::Init(void)
1012{
99c75ebc
RR
1013 this->m_CustomRendererPtr = NULL;
1014 this->m_Deleting = false;
1015 this->m_macIsUserPane = false;
1016 this->m_cgContext = NULL;
c0a66d92
RR
1017} /* wxDataViewCtrl::Init(void) */
1018
1019bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
1020{
1021 if (!(this->wxControl::Create(parent,id,pos,size,(style | wxSUNKEN_BORDER) & ~(wxHSCROLL | wxVSCROLL),validator)))
1022 return false;
1023
1024#ifdef __WXMAC__
1025 MacSetClipChildren(true) ;
1026#endif
1027
1028 this->m_peer = new wxMacDataViewDataBrowserListViewControl(this,pos,size,style);
1029 this->MacPostControlCreate(pos,size);
07c51ff1 1030 ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(this->m_peer->GetControlRef()),true);
c0a66d92
RR
1031
1032 InstallControlEventHandler(this->m_peer->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList),eventList,this,NULL);
1033
abcdba0a
RR
1034 ::SetDataBrowserTableViewHiliteStyle( this->m_peer->GetControlRef(), kDataBrowserTableViewFillHilite );
1035
a9c98d7d
RR
1036 ::SetDataBrowserTableViewGeometry( this->m_peer->GetControlRef(), true, false );
1037
c0a66d92
RR
1038 return true;
1039} /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
1040
4bff335a
VS
1041/*static*/
1042wxVisualAttributes wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant variant)
1043{
1044 wxVisualAttributes attr;
1045
1046 attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
1047 attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX );
1048 attr.font.MacCreateFromThemeFont(kThemeViewsFont);
1049
1050 return attr;
1051}
1052
c17b2e31
RR
1053bool wxDataViewCtrl::AssociateModel(wxDataViewModel* model)
1054{
1055 if (!wxDataViewCtrlBase::AssociateModel(model))
1056 return false;
1057
1058 model->AddNotifier(new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl*>(this->m_peer)));
1059
1060 return true;
1061} /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
1062
594d5596 1063bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* columnPtr)
c0a66d92 1064{
594d5596
RR
1065 DataBrowserListViewColumnDesc columnDescription;
1066
c17b2e31
RR
1067 DataBrowserPropertyID NewPropertyID;
1068
1069 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1070
99c75ebc 1071#if wxCHECK_VERSION(2,9,0)
34a3ed01 1072 wxCFStringRef title(columnPtr->GetTitle(),this->m_font.Ok() ? this->GetFont().GetEncoding() : wxLocale::GetSystemEncoding());
99c75ebc 1073#else
34a3ed01 1074 wxMacCFStringHolder title(columnPtr->GetTitle(),this->m_font.Ok() ? this->GetFont().GetEncoding() : wxLocale::GetSystemEncoding());
99c75ebc 1075#endif
594d5596 1076
c17b2e31 1077
194027ac 1078 // first, some error checking:
594d5596
RR
1079 wxCHECK_MSG(MacDataViewListCtrlPtr != NULL, false,_("m_peer is not or incorrectly initialized"));
1080 wxCHECK_MSG(columnPtr != NULL, false,_("Column pointer must not be NULL."));
1081 wxCHECK_MSG(columnPtr->GetRenderer() != NULL, false,_("Column does not have a renderer."));
1082 wxCHECK_MSG(this->GetModel() != NULL, false,_("No model associated with control."));
1083 wxCHECK_MSG((columnPtr->GetModelColumn() >= 0) &&
1084 (columnPtr->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
1085
1086 // try to get new ID for the column:
1087 wxCHECK_MSG(MacDataViewListCtrlPtr->GetFreePropertyID(&NewPropertyID) == noErr,false,_("Cannot create new column's ID. Probably max. number of columns reached."));
1088 // full column variable initialization:
1089 columnPtr->SetPropertyID(NewPropertyID);
1090 // add column to wxWidget's internal structure:
1091 wxCHECK_MSG(this->wxDataViewCtrlBase::AppendColumn(columnPtr) &&
1092 this->m_ColumnPointers.insert(ColumnPointerHashMapType::value_type(NewPropertyID,columnPtr)).second,false,_("Could not add column to internal structures."));
1093 // create a column description and add column to the native control:
1094 wxCHECK_MSG(::InitializeColumnDescription(columnDescription,columnPtr,NewPropertyID,title), false,_("Column description could not be initialized."));
1095 wxCHECK_MSG(MacDataViewListCtrlPtr->AddColumn(&columnDescription,kDataBrowserListViewAppendColumn) == noErr,false,_("Column could not be added."));
1096
1097 // final adjustments for the layout:
1098 wxCHECK_MSG(MacDataViewListCtrlPtr->SetColumnWidth(NewPropertyID,columnPtr->GetWidth()) == noErr,false,_("Column width could not be set."));
1099
1100 // make sure that the data is up-to-date...
1101 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
1102 // otherwise ask the control to 'update' the data in the newly appended column:
1103 if (this->GetColumnCount() == 1)
c0a66d92 1104 {
594d5596
RR
1105 this->SetExpanderColumn(columnPtr);
1106 this->AddChildrenLevel(wxDataViewItem());
c0a66d92
RR
1107 } /* if */
1108 else
594d5596
RR
1109 MacDataViewListCtrlPtr->UpdateItems(kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty,NewPropertyID);
1110 // done:
1111 return true;
c0a66d92
RR
1112} /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
1113
c17b2e31 1114bool wxDataViewCtrl::ClearColumns(void)
07c51ff1 1115{
c17b2e31
RR
1116 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1117
1118
1119 while (this->m_ColumnPointers.begin() != this->m_ColumnPointers.end())
1120 {
1121 wxCHECK_MSG(MacDataViewListCtrlPtr->RemoveColumnByProperty(this->m_ColumnPointers.begin()->first) == noErr,false,_("Could not remove column."));
1122 delete this->m_ColumnPointers.begin()->second;
1123 this->m_ColumnPointers.erase(this->m_ColumnPointers.begin());
1124 } /* while */
1125 return true;
1126} /* wxDataViewCtrl::ClearColumns(void) */
1127
1128bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn* columnPtr)
1129{
1130 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1131
1132
1133 if ((MacDataViewListCtrlPtr->RemoveColumnByProperty(columnPtr->GetPropertyID()) == noErr) && (this->m_ColumnPointers.erase(columnPtr->GetPropertyID()) > 0))
1134 {
1135 delete columnPtr;
1136 return true;
1137 } /* if */
1138 else
07c51ff1 1139 return false;
c17b2e31
RR
1140} /* wxDataViewCtrl::DeleteColumn(wxDataViewColumn*) */
1141
1142wxDataViewColumn* wxDataViewCtrl::GetColumn(unsigned int pos) const
1143{
1144 DataBrowserPropertyID propertyID;
07c51ff1 1145
c17b2e31 1146 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
07c51ff1 1147
c17b2e31
RR
1148
1149 if (MacDataViewListCtrlPtr->GetPropertyID(pos,&propertyID) == noErr)
1150 {
1151 // variable definition:
1152 ColumnPointerHashMapType::const_iterator Result(this->m_ColumnPointers.find(propertyID));
1153
1154 if (Result != this->m_ColumnPointers.end())
1155 return Result->second;
1156 else
1157 return NULL;
1158 } /* if */
1159 else
1160 return NULL;
1161} /* wxDataViewCtrl::GetColumn(unsigned int pos) const */
1162
1163unsigned int wxDataViewCtrl::GetColumnCount(void) const
1164{
1165 return this->m_ColumnPointers.size();
1166} /* wxDataViewCtrl::GetColumnCount(void) const */
1167
6d9ecc87 1168int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const* columnPtr) const
453091c2 1169{
6d9ecc87
RR
1170 if (columnPtr != NULL)
1171 {
1172 // variable definition and initialization:
1173 DataBrowserTableViewColumnIndex Position;
1174 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1175
1176 wxCHECK_MSG(MacDataViewListCtrlPtr->GetColumnIndex(columnPtr->GetPropertyID(),&Position) == noErr,-1,_("Could not determine column's position"));
1177 return static_cast<int>(Position);
1178 } /* if */
1179 else
1180 return wxNOT_FOUND;
1181} /* wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const*) const */
21f47fb9 1182
594d5596
RR
1183bool wxDataViewCtrl::PrependColumn(wxDataViewColumn* columnPtr)
1184{
1185 DataBrowserListViewColumnDesc columnDescription;
1186
1187 DataBrowserPropertyID NewPropertyID;
1188
1189 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1190
99c75ebc 1191#if wxCHECK_VERSION(2,9,0)
34a3ed01 1192 wxCFStringRef title(columnPtr->GetTitle(),this->m_font.Ok() ? this->GetFont().GetEncoding() : wxLocale::GetSystemEncoding());
99c75ebc 1193#else
34a3ed01 1194 wxMacCFStringHolder title(columnPtr->GetTitle(),this->m_font.Ok() ? this->GetFont().GetEncoding() : wxLocale::GetSystemEncoding());
99c75ebc 1195#endif
594d5596
RR
1196
1197
1198 // first, some error checking:
1199 wxCHECK_MSG(MacDataViewListCtrlPtr != NULL, false,_("m_peer is not or incorrectly initialized"));
1200 wxCHECK_MSG(columnPtr != NULL, false,_("Column pointer must not be NULL."));
1201 wxCHECK_MSG(columnPtr->GetRenderer() != NULL, false,_("Column does not have a renderer."));
1202 wxCHECK_MSG(this->GetModel() != NULL, false,_("No model associated with control."));
1203 wxCHECK_MSG((columnPtr->GetModelColumn() >= 0) &&
1204 (columnPtr->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
1205
1206 // try to get new ID for the column:
1207 wxCHECK_MSG(MacDataViewListCtrlPtr->GetFreePropertyID(&NewPropertyID) == noErr,false,_("Cannot create new column's ID. Probably max. number of columns reached."));
1208 // full column variable initialization:
1209 columnPtr->SetPropertyID(NewPropertyID);
1210 // add column to wxWidget's internal structure:
1211 wxCHECK_MSG(this->wxDataViewCtrlBase::AppendColumn(columnPtr) &&
1212 this->m_ColumnPointers.insert(ColumnPointerHashMapType::value_type(NewPropertyID,columnPtr)).second,false,_("Could not add column to internal structures."));
1213 // create a column description and add column to the native control:
1214 wxCHECK_MSG(::InitializeColumnDescription(columnDescription,columnPtr,NewPropertyID,title),false,_("Column description could not be initialized."));
1215 wxCHECK_MSG(MacDataViewListCtrlPtr->AddColumn(&columnDescription,0) == noErr, false,_("Column could not be added."));
1216
1217 // final adjustments for the layout:
1218 wxCHECK_MSG(MacDataViewListCtrlPtr->SetColumnWidth(NewPropertyID,columnPtr->GetWidth()) == noErr,false,_("Column width could not be set."));
1219
1220 // make sure that the data is up-to-date...
1221 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
1222 // otherwise ask the control to 'update' the data in the newly appended column:
1223 if (this->GetColumnCount() == 1)
1224 {
1225 this->SetExpanderColumn(columnPtr);
1226 this->AddChildrenLevel(wxDataViewItem());
1227 } /* if */
1228 else
1229 MacDataViewListCtrlPtr->UpdateItems(kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty,NewPropertyID);
1230 // done:
1231 return true;
1232} /* wxDataViewCtrl::PrependColumn(wxDataViewColumn*) */
1233
c17b2e31
RR
1234void wxDataViewCtrl::Collapse(wxDataViewItem const& item)
1235{
1236 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1237
1238
1239 MacDataViewListCtrlPtr->CloseContainer(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1240} /* wxDataViewCtrl::Collapse(wxDataViewItem const&) */
07c51ff1
RR
1241
1242void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr)
1243{
1244 if (item.IsOk())
1245 {
1246 // variable definition and initialization:
1247 DataBrowserPropertyID propertyID;
1248 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1249
1250 if (columnPtr != NULL)
1251 propertyID = columnPtr->GetPropertyID();
1252 else
1253 propertyID = kDataBrowserNoItem;
1254 MacDataViewListCtrlPtr->RevealItem(reinterpret_cast<DataBrowserItemID>(item.GetID()),propertyID,kDataBrowserRevealOnly);
1255 } /* if */
1256} /* wxDataViewCtrl::EnsureVisible(wxDataViewItem const&, wxDataViewColumn const*) */
1257
c17b2e31
RR
1258void wxDataViewCtrl::Expand(wxDataViewItem const& item)
1259{
1260 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1261
1262
1263 MacDataViewListCtrlPtr->OpenContainer(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1264} /* wxDataViewCtrl::Expand(wxDataViewItem const&) */
1265
6d9ecc87
RR
1266wxDataViewColumn* wxDataViewCtrl::GetSortingColumn(void) const
1267{
1268 DataBrowserPropertyID propertyID;
1269
1270 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1271
1272
1273 if (MacDataViewListCtrlPtr->GetSortProperty(&propertyID) == noErr)
1274 return this->GetColumnPtr(propertyID);
1275 else
1276 return NULL;
1277} /* wxDataViewCtrl::GetSortingColumn(void) const */
1278
b741dd40
RR
1279unsigned int wxDataViewCtrl::GetCount(void) const
1280{
1281 ItemCount noOfItems;
1282
1283
1284 wxCHECK_MSG(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer)->GetItemCount(&noOfItems) == noErr,0,_("Could not determine number of items"));
1285 return noOfItems;
1286} /* wxDataViewCtrl::GetCount(void) const */
1287
07c51ff1
RR
1288wxRect wxDataViewCtrl::GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const
1289{
1290 if (item.IsOk() && (columnPtr != NULL))
1291 {
1292 // variable definition:
1293 Rect MacRectangle;
1294 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1295
1296 if (MacDataViewListCtrlPtr->GetPartBounds(reinterpret_cast<DataBrowserItemID>(item.GetID()),columnPtr->GetPropertyID(),kDataBrowserPropertyContentPart,&MacRectangle) == noErr)
1297 {
1298 // variable definition:
1299 wxRect rectangle;
1300
1301 ::wxMacNativeToRect(&MacRectangle,&rectangle);
1302 return rectangle;
1303 } /* if */
1304 else
1305 return wxRect();
1306 } /* if */
1307 else
1308 return wxRect();
1309} /* wxDataViewCtrl::GetItemRect(wxDataViewItem const&, unsigned int) const */
1310
1311wxDataViewItem wxDataViewCtrl::GetSelection(void) const
c0a66d92 1312{
c0a66d92 1313 wxArrayDataBrowserItemID itemIDs;
c0a66d92 1314
194027ac 1315 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
c0a66d92
RR
1316
1317
194027ac
RR
1318 if (MacDataViewListCtrlPtr->GetSelectedItemIDs(itemIDs) > 0)
1319 return wxDataViewItem(reinterpret_cast<void*>(itemIDs[0]));
1320 else
1321 return wxDataViewItem();
07c51ff1 1322} /* wxDataViewCtrl::GetSelection(void) const */
c0a66d92 1323
07c51ff1 1324int wxDataViewCtrl::GetSelections(wxDataViewItemArray& sel) const
c0a66d92 1325{
07c51ff1
RR
1326 size_t NoOfSelectedItems;
1327
1328 wxArrayDataBrowserItemID itemIDs;
c0a66d92 1329
07c51ff1
RR
1330 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1331
1332
1333 NoOfSelectedItems = MacDataViewListCtrlPtr->GetSelectedItemIDs(itemIDs);
1334 sel.Empty();
1335 sel.SetCount(NoOfSelectedItems);
1336 for (size_t i=0; i<NoOfSelectedItems; ++i)
1337 sel[i] = wxDataViewItem(reinterpret_cast<void*>(itemIDs[i]));
1338 return static_cast<int>(NoOfSelectedItems);
1339} /* wxDataViewCtrl::GetSelections(wxDataViewItemArray&) const */
c0a66d92 1340
07c51ff1
RR
1341void wxDataViewCtrl::HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const
1342{
1343 item = wxDataViewItem();
1344 columnPtr = NULL;
1345} /* wxDataViewCtrl::HitTest(wxPoint const&, wxDataViewItem&, wxDataViewColumn*&) const */
1346
1347bool wxDataViewCtrl::IsSelected(wxDataViewItem const& item) const
1348{
1349 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1350
1351
1352 return MacDataViewListCtrlPtr->IsItemSelected(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1353} /* wxDataViewCtrl::IsSelected(wxDataViewItem const&) const */
1354
1355void wxDataViewCtrl::SelectAll(void)
1356{
1357 DataBrowserItemID* itemIDPtr;
1358
1359 Handle handle(::NewHandle(0));
1360
1361 size_t NoOfItems;
1362
1363 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1364
1365
1366 wxCHECK_RET(MacDataViewListCtrlPtr->GetItems(kDataBrowserNoItem,true,kDataBrowserItemAnyState,handle) == noErr,_("Could not get items."));
1367 NoOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
1368 HLock(handle);
1369 itemIDPtr = (DataBrowserItemID*) (*handle);
1370 MacDataViewListCtrlPtr->SetSelectedItems(NoOfItems,itemIDPtr,kDataBrowserItemsAssign);
1371 HUnlock(handle);
1372 DisposeHandle(handle);
1373} /* wxDataViewCtrl::SelectAll(void) */
1374
1375void wxDataViewCtrl::Select(wxDataViewItem const& item)
1376{
1377 if (item.IsOk())
1378 {
1379 // variable definition and initialization:
1380 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1381 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1382
1383 MacDataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsAdd);
1384 } /* if */
1385} /* wxDataViewCtrl::Select(wxDataViewItem const&) */
1386
1387void wxDataViewCtrl::SetSelections(wxDataViewItemArray const& sel)
1388{
1389 size_t const NoOfSelections = sel.GetCount();
1390
1391 DataBrowserItemID* itemIDs;
1392
1393 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1394
1395
1396 itemIDs = new DataBrowserItemID[NoOfSelections];
1397 for (size_t i=0; i<NoOfSelections; ++i)
1398 itemIDs[i] = reinterpret_cast<DataBrowserItemID>(sel[i].GetID());
1399 MacDataViewListCtrlPtr->SetSelectedItems(NoOfSelections,itemIDs,kDataBrowserItemsAssign);
1400 delete[] itemIDs;
1401} /* wxDataViewCtrl::SetSelections(wxDataViewItemArray const&) */
1402
1403void wxDataViewCtrl::Unselect(wxDataViewItem const& item)
1404{
1405 if (item.IsOk())
1406 {
1407 // variable definition and initialization:
1408 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1409 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1410
1411 MacDataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsRemove);
1412 } /* if */
1413} /* wxDataViewCtrl::Unselect(wxDataViewItem const&) */
1414
1415void wxDataViewCtrl::UnselectAll(void)
1416{
1417 DataBrowserItemID* itemIDPtr;
1418
1419 Handle handle(::NewHandle(0));
1420
1421 size_t NoOfItems;
1422
1423 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1424
1425
1426 wxCHECK_RET(MacDataViewListCtrlPtr->GetItems(kDataBrowserNoItem,true,kDataBrowserItemAnyState,handle) == noErr,_("Could not get items."));
1427 NoOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
1428 HLock(handle);
1429 itemIDPtr = (DataBrowserItemID*) (*handle);
1430 MacDataViewListCtrlPtr->SetSelectedItems(NoOfItems,itemIDPtr,kDataBrowserItemsRemove);
1431 HUnlock(handle);
1432 DisposeHandle(handle);
1433} /* wxDataViewCtrl::UnselectAll(void) */
c0a66d92 1434
194027ac
RR
1435// data handling:
1436void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const& parentItem)
c0a66d92 1437{
b741dd40
RR
1438 int NoOfChildren;
1439
1440 wxDataViewItemArray items;
c0a66d92 1441
c0a66d92 1442
194027ac 1443 wxCHECK_RET(this->GetModel() != NULL,_("Model pointer not initialized."));
b741dd40 1444 NoOfChildren = this->GetModel()->GetChildren(parentItem,items);
a5fb9253 1445#if 0
b741dd40
RR
1446 for (int i=0; i<NoOfChildren; ++i)
1447 (void) this->GetModel()->ItemAdded(parentItem,items[i]);
a5fb9253
RR
1448#else
1449 (void) this->GetModel()->ItemsAdded(parentItem,items);
1450#endif
194027ac 1451} /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
c0a66d92 1452
99c75ebc
RR
1453void wxDataViewCtrl::FinishCustomItemEditing(void)
1454{
1455 if (this->GetCustomRendererItem().IsOk())
1456 {
1457 this->GetCustomRendererPtr()->FinishEditing();
1458 this->SetCustomRendererItem(wxDataViewItem());
1459 this->SetCustomRendererPtr (NULL);
1460 } /* if */
1461} /* wxDataViewCtrl::FinishCustomItemEditing(void) */
1462
34b1fdeb 1463wxDataViewColumn* wxDataViewCtrl::GetColumnPtr(WXDataBrowserPropertyID propertyID) const
c17b2e31
RR
1464{
1465 // variable definition:
1466 ColumnPointerHashMapType::const_iterator Result(this->m_ColumnPointers.find(propertyID));
1467
1468 if (Result != this->m_ColumnPointers.end())
1469 return Result->second;
1470 else
1471 return NULL;
1472} /* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID) const */
1473
194027ac
RR
1474// inherited methods from wxDataViewCtrlBase
1475void wxDataViewCtrl::DoSetExpanderColumn(void)
c0a66d92 1476{
c17b2e31 1477 if (this->GetExpanderColumn() != NULL)
c0a66d92 1478 {
194027ac 1479 // variable definition and initialization:
194027ac
RR
1480 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1481
99c75ebc 1482 (void) MacDataViewListCtrlPtr->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID(),false); // second parameter explicitely passed to ensure that arrow is centered
c0a66d92 1483 } /* if */
194027ac 1484} /* wxDataViewCtrl::DoSetExpanderColumn(void) */
c0a66d92 1485
194027ac 1486void wxDataViewCtrl::DoSetIndent(void)
c0a66d92 1487{
c17b2e31
RR
1488 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1489
1490
1491 (void) MacDataViewListCtrlPtr->SetIndent(static_cast<float>(this->GetIndent()));
1492} /* wxDataViewCtrl::DoSetIndent(void) */
c0a66d92 1493
194027ac
RR
1494// event handling:
1495void wxDataViewCtrl::OnSize(wxSizeEvent& event)
c0a66d92 1496{
194027ac 1497 unsigned int const NoOfColumns = this->GetColumnCount();
c0a66d92 1498
194027ac
RR
1499
1500 for (unsigned int i=0; i<NoOfColumns; ++i)
c0a66d92
RR
1501 {
1502 // variable definition and initialization:
194027ac
RR
1503 wxDataViewColumn* dataViewColumnPtr(this->GetColumn(i));
1504
1505 if (dataViewColumnPtr != NULL)
c0a66d92 1506 {
194027ac
RR
1507 // variable definition and initialization:
1508 wxDataViewCustomRenderer* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer()));
1509
1510 if (dataViewCustomRendererPtr != NULL)
1511 dataViewCustomRendererPtr->SetDC(NULL); // reset DC because DC has changed
c0a66d92 1512 } /* if */
194027ac 1513 } /* for */
a9c98d7d
RR
1514
1515 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1516 ControlRef ref = MacDataViewListCtrlPtr->GetControlRef();
1517 if (NoOfColumns == 1)
1518 {
1519 ::SetDataBrowserHasScrollBars( ref, false, true );
1520 ::AutoSizeDataBrowserListViewColumns( ref );
1521 }
1522 if (NoOfColumns > 1)
1523 {
1524 ::SetDataBrowserHasScrollBars( ref, true, true );
1525 }
1526
194027ac
RR
1527 event.Skip();
1528} /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
c0a66d92
RR
1529
1530IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl,wxDataViewCtrlBase)
1531
1532BEGIN_EVENT_TABLE(wxDataViewCtrl,wxDataViewCtrlBase)
1533 EVT_SIZE(wxDataViewCtrl::OnSize)
1534END_EVENT_TABLE()
1535
1536#endif
1537 // !wxUSE_GENERICDATAVIEWCTRL
1538
1539#endif
1540 // wxUSE_DATAVIEWCTRL
1541