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