]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dataview.cpp
fix wxTextCtrl::operator<<('\n') in Unicode build (should use char overload, not...
[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
c0a66d92
RR
870void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable))
871{
872} /* wxDataViewColumn::SetResizeable(bool) */
873
874void wxDataViewColumn::SetSortable(bool sortable)
875{
99c75ebc
RR
876 // first set the internal flag of the column:
877 if (sortable)
878 this->m_flags |= wxDATAVIEW_COL_SORTABLE;
879 else
880 this->m_flags &= ~wxDATAVIEW_COL_SORTABLE;
881 // if the column is associated with a control change also immediately the flags of the control:
882 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner()); // variable definition and initialization
883
c0a66d92
RR
884 if (dataViewCtrlPtr != NULL)
885 {
886 // variable definition and initialization:
99c75ebc 887 DataBrowserPropertyFlags flags;
c0a66d92
RR
888 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
889
99c75ebc
RR
890 wxCHECK_RET(macDataViewListCtrlPtr != NULL, _("Valid pointer to native data view control does not exist"));
891 wxCHECK_RET(macDataViewListCtrlPtr->GetPropertyFlags(this->GetPropertyID(),&flags) == noErr,_("Could not get property flags."));
892 if (sortable)
893 flags |= kDataBrowserListViewSortableColumn;
894 else
895 flags &= ~kDataBrowserListViewSortableColumn;
896 wxCHECK_RET(macDataViewListCtrlPtr->SetPropertyFlags(this->GetPropertyID(),flags) == noErr,_("Could not set property flags."));
c0a66d92
RR
897 } /* if */
898} /* wxDataViewColumn::SetSortable(bool) */
899
900void wxDataViewColumn::SetSortOrder(bool ascending)
901{
902 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
903
904
905 this->m_ascending = ascending;
906 if (dataViewCtrlPtr != NULL)
907 {
908 // variable definition and initialization:
909 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
910
911 if (macDataViewListCtrlPtr != NULL)
912 {
913 // variable definition and initialization:
914 DataBrowserListViewHeaderDesc headerDescription;
915
916 verify_noerr(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription));
917 if (ascending)
918 headerDescription.initialOrder = kDataBrowserOrderIncreasing;
919 else
920 headerDescription.initialOrder = kDataBrowserOrderDecreasing;
921 verify_noerr(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription));
6d9ecc87 922 macDataViewListCtrlPtr->SetSortProperty(this->GetPropertyID());
c0a66d92
RR
923 } /* if */
924 } /* if */
925} /* wxDataViewColumn::SetSortOrder(bool) */
926
927void wxDataViewColumn::SetTitle(wxString const& title)
928{
929 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
930
931
932 this->m_title = title;
933 if (dataViewCtrlPtr != NULL)
934 {
935 // variable definition and initialization:
936 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
937
938 if (macDataViewListCtrlPtr != NULL)
939 {
940 // variable definition and initialization:
941 DataBrowserListViewHeaderDesc headerDescription;
99c75ebc 942#if wxCHECK_VERSION(2,9,0)
dbe4a80c 943 wxCFStringRef cfTitle(title,(dataViewCtrlPtr->GetFont().Ok() ? dataViewCtrlPtr->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
99c75ebc
RR
944#else
945 wxMacCFStringHolder cfTitle(title,(dataViewCtrlPtr->GetFont().Ok() ? dataViewCtrlPtr->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
946#endif
c0a66d92
RR
947
948 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
949 headerDescription.titleString = cfTitle;
950 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set header description."));
951 } /* if */
952 } /* if */
953} /* wxDataViewColumn::SetTitle(wxString const&) */
954
955void wxDataViewColumn::SetWidth(int width)
956{
957 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
958
959
960 if ((width >= this->m_minWidth) && (width <= this->m_maxWidth))
961 {
962 this->m_width = width;
963 if (dataViewCtrlPtr != NULL)
964 {
965 // variable definition and initialization:
966 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
967
968 if (macDataViewListCtrlPtr != NULL)
969 wxCHECK_RET(macDataViewListCtrlPtr->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16>(width)) == noErr,_("Could not set column width."));
970 } /* if */
971 } /* if */
972} /* wxDataViewColumn::SetWidth(int) */
973
974IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn,wxDataViewColumnBase)
975
976//-----------------------------------------------------------------------------
977// wxDataViewCtrl
978//-----------------------------------------------------------------------------
979#pragma mark -
980void wxDataViewCtrl::Init(void)
981{
99c75ebc
RR
982 this->m_CustomRendererPtr = NULL;
983 this->m_Deleting = false;
984 this->m_macIsUserPane = false;
985 this->m_cgContext = NULL;
c0a66d92
RR
986} /* wxDataViewCtrl::Init(void) */
987
988bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
989{
990 if (!(this->wxControl::Create(parent,id,pos,size,(style | wxSUNKEN_BORDER) & ~(wxHSCROLL | wxVSCROLL),validator)))
991 return false;
992
993#ifdef __WXMAC__
994 MacSetClipChildren(true) ;
995#endif
996
997 this->m_peer = new wxMacDataViewDataBrowserListViewControl(this,pos,size,style);
998 this->MacPostControlCreate(pos,size);
07c51ff1 999 ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(this->m_peer->GetControlRef()),true);
c0a66d92
RR
1000
1001 InstallControlEventHandler(this->m_peer->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList),eventList,this,NULL);
1002
abcdba0a
RR
1003 ::SetDataBrowserTableViewHiliteStyle( this->m_peer->GetControlRef(), kDataBrowserTableViewFillHilite );
1004
a9c98d7d
RR
1005 ::SetDataBrowserTableViewGeometry( this->m_peer->GetControlRef(), true, false );
1006
c0a66d92
RR
1007 return true;
1008} /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
1009
4bff335a
VS
1010/*static*/
1011wxVisualAttributes wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant variant)
1012{
1013 wxVisualAttributes attr;
1014
1015 attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
1016 attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX );
1017 attr.font.MacCreateFromThemeFont(kThemeViewsFont);
1018
1019 return attr;
1020}
1021
c17b2e31
RR
1022bool wxDataViewCtrl::AssociateModel(wxDataViewModel* model)
1023{
1024 if (!wxDataViewCtrlBase::AssociateModel(model))
1025 return false;
1026
1027 model->AddNotifier(new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl*>(this->m_peer)));
1028
1029 return true;
1030} /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
1031
594d5596 1032bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* columnPtr)
c0a66d92 1033{
594d5596
RR
1034 DataBrowserListViewColumnDesc columnDescription;
1035
c17b2e31
RR
1036 DataBrowserPropertyID NewPropertyID;
1037
1038 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1039
99c75ebc 1040#if wxCHECK_VERSION(2,9,0)
34a3ed01 1041 wxCFStringRef title(columnPtr->GetTitle(),this->m_font.Ok() ? this->GetFont().GetEncoding() : wxLocale::GetSystemEncoding());
99c75ebc 1042#else
34a3ed01 1043 wxMacCFStringHolder title(columnPtr->GetTitle(),this->m_font.Ok() ? this->GetFont().GetEncoding() : wxLocale::GetSystemEncoding());
99c75ebc 1044#endif
594d5596 1045
c17b2e31 1046
194027ac 1047 // first, some error checking:
594d5596
RR
1048 wxCHECK_MSG(MacDataViewListCtrlPtr != NULL, false,_("m_peer is not or incorrectly initialized"));
1049 wxCHECK_MSG(columnPtr != NULL, false,_("Column pointer must not be NULL."));
1050 wxCHECK_MSG(columnPtr->GetRenderer() != NULL, false,_("Column does not have a renderer."));
1051 wxCHECK_MSG(this->GetModel() != NULL, false,_("No model associated with control."));
1052 wxCHECK_MSG((columnPtr->GetModelColumn() >= 0) &&
1053 (columnPtr->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
1054
1055 // try to get new ID for the column:
1056 wxCHECK_MSG(MacDataViewListCtrlPtr->GetFreePropertyID(&NewPropertyID) == noErr,false,_("Cannot create new column's ID. Probably max. number of columns reached."));
1057 // full column variable initialization:
1058 columnPtr->SetPropertyID(NewPropertyID);
1059 // add column to wxWidget's internal structure:
1060 wxCHECK_MSG(this->wxDataViewCtrlBase::AppendColumn(columnPtr) &&
1061 this->m_ColumnPointers.insert(ColumnPointerHashMapType::value_type(NewPropertyID,columnPtr)).second,false,_("Could not add column to internal structures."));
1062 // create a column description and add column to the native control:
1063 wxCHECK_MSG(::InitializeColumnDescription(columnDescription,columnPtr,NewPropertyID,title), false,_("Column description could not be initialized."));
1064 wxCHECK_MSG(MacDataViewListCtrlPtr->AddColumn(&columnDescription,kDataBrowserListViewAppendColumn) == noErr,false,_("Column could not be added."));
1065
1066 // final adjustments for the layout:
1067 wxCHECK_MSG(MacDataViewListCtrlPtr->SetColumnWidth(NewPropertyID,columnPtr->GetWidth()) == noErr,false,_("Column width could not be set."));
1068
1069 // make sure that the data is up-to-date...
1070 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
1071 // otherwise ask the control to 'update' the data in the newly appended column:
1072 if (this->GetColumnCount() == 1)
c0a66d92 1073 {
594d5596
RR
1074 this->SetExpanderColumn(columnPtr);
1075 this->AddChildrenLevel(wxDataViewItem());
c0a66d92
RR
1076 } /* if */
1077 else
594d5596
RR
1078 MacDataViewListCtrlPtr->UpdateItems(kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty,NewPropertyID);
1079 // done:
1080 return true;
c0a66d92
RR
1081} /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
1082
c17b2e31 1083bool wxDataViewCtrl::ClearColumns(void)
07c51ff1 1084{
c17b2e31
RR
1085 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1086
1087
1088 while (this->m_ColumnPointers.begin() != this->m_ColumnPointers.end())
1089 {
1090 wxCHECK_MSG(MacDataViewListCtrlPtr->RemoveColumnByProperty(this->m_ColumnPointers.begin()->first) == noErr,false,_("Could not remove column."));
1091 delete this->m_ColumnPointers.begin()->second;
1092 this->m_ColumnPointers.erase(this->m_ColumnPointers.begin());
1093 } /* while */
1094 return true;
1095} /* wxDataViewCtrl::ClearColumns(void) */
1096
1097bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn* columnPtr)
1098{
1099 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1100
1101
1102 if ((MacDataViewListCtrlPtr->RemoveColumnByProperty(columnPtr->GetPropertyID()) == noErr) && (this->m_ColumnPointers.erase(columnPtr->GetPropertyID()) > 0))
1103 {
1104 delete columnPtr;
1105 return true;
1106 } /* if */
1107 else
07c51ff1 1108 return false;
c17b2e31
RR
1109} /* wxDataViewCtrl::DeleteColumn(wxDataViewColumn*) */
1110
1111wxDataViewColumn* wxDataViewCtrl::GetColumn(unsigned int pos) const
1112{
1113 DataBrowserPropertyID propertyID;
07c51ff1 1114
c17b2e31 1115 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
07c51ff1 1116
c17b2e31
RR
1117
1118 if (MacDataViewListCtrlPtr->GetPropertyID(pos,&propertyID) == noErr)
1119 {
1120 // variable definition:
1121 ColumnPointerHashMapType::const_iterator Result(this->m_ColumnPointers.find(propertyID));
1122
1123 if (Result != this->m_ColumnPointers.end())
1124 return Result->second;
1125 else
1126 return NULL;
1127 } /* if */
1128 else
1129 return NULL;
1130} /* wxDataViewCtrl::GetColumn(unsigned int pos) const */
1131
1132unsigned int wxDataViewCtrl::GetColumnCount(void) const
1133{
1134 return this->m_ColumnPointers.size();
1135} /* wxDataViewCtrl::GetColumnCount(void) const */
1136
6d9ecc87 1137int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const* columnPtr) const
453091c2 1138{
6d9ecc87
RR
1139 if (columnPtr != NULL)
1140 {
1141 // variable definition and initialization:
1142 DataBrowserTableViewColumnIndex Position;
1143 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1144
1145 wxCHECK_MSG(MacDataViewListCtrlPtr->GetColumnIndex(columnPtr->GetPropertyID(),&Position) == noErr,-1,_("Could not determine column's position"));
1146 return static_cast<int>(Position);
1147 } /* if */
1148 else
1149 return wxNOT_FOUND;
1150} /* wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const*) const */
21f47fb9 1151
594d5596
RR
1152bool wxDataViewCtrl::PrependColumn(wxDataViewColumn* columnPtr)
1153{
1154 DataBrowserListViewColumnDesc columnDescription;
1155
1156 DataBrowserPropertyID NewPropertyID;
1157
1158 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1159
99c75ebc 1160#if wxCHECK_VERSION(2,9,0)
34a3ed01 1161 wxCFStringRef title(columnPtr->GetTitle(),this->m_font.Ok() ? this->GetFont().GetEncoding() : wxLocale::GetSystemEncoding());
99c75ebc 1162#else
34a3ed01 1163 wxMacCFStringHolder title(columnPtr->GetTitle(),this->m_font.Ok() ? this->GetFont().GetEncoding() : wxLocale::GetSystemEncoding());
99c75ebc 1164#endif
594d5596
RR
1165
1166
1167 // first, some error checking:
1168 wxCHECK_MSG(MacDataViewListCtrlPtr != NULL, false,_("m_peer is not or incorrectly initialized"));
1169 wxCHECK_MSG(columnPtr != NULL, false,_("Column pointer must not be NULL."));
1170 wxCHECK_MSG(columnPtr->GetRenderer() != NULL, false,_("Column does not have a renderer."));
1171 wxCHECK_MSG(this->GetModel() != NULL, false,_("No model associated with control."));
1172 wxCHECK_MSG((columnPtr->GetModelColumn() >= 0) &&
1173 (columnPtr->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
1174
1175 // try to get new ID for the column:
1176 wxCHECK_MSG(MacDataViewListCtrlPtr->GetFreePropertyID(&NewPropertyID) == noErr,false,_("Cannot create new column's ID. Probably max. number of columns reached."));
1177 // full column variable initialization:
1178 columnPtr->SetPropertyID(NewPropertyID);
1179 // add column to wxWidget's internal structure:
1180 wxCHECK_MSG(this->wxDataViewCtrlBase::AppendColumn(columnPtr) &&
1181 this->m_ColumnPointers.insert(ColumnPointerHashMapType::value_type(NewPropertyID,columnPtr)).second,false,_("Could not add column to internal structures."));
1182 // create a column description and add column to the native control:
1183 wxCHECK_MSG(::InitializeColumnDescription(columnDescription,columnPtr,NewPropertyID,title),false,_("Column description could not be initialized."));
1184 wxCHECK_MSG(MacDataViewListCtrlPtr->AddColumn(&columnDescription,0) == noErr, false,_("Column could not be added."));
1185
1186 // final adjustments for the layout:
1187 wxCHECK_MSG(MacDataViewListCtrlPtr->SetColumnWidth(NewPropertyID,columnPtr->GetWidth()) == noErr,false,_("Column width could not be set."));
1188
1189 // make sure that the data is up-to-date...
1190 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
1191 // otherwise ask the control to 'update' the data in the newly appended column:
1192 if (this->GetColumnCount() == 1)
1193 {
1194 this->SetExpanderColumn(columnPtr);
1195 this->AddChildrenLevel(wxDataViewItem());
1196 } /* if */
1197 else
1198 MacDataViewListCtrlPtr->UpdateItems(kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty,NewPropertyID);
1199 // done:
1200 return true;
1201} /* wxDataViewCtrl::PrependColumn(wxDataViewColumn*) */
1202
c17b2e31
RR
1203void wxDataViewCtrl::Collapse(wxDataViewItem const& item)
1204{
1205 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1206
1207
1208 MacDataViewListCtrlPtr->CloseContainer(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1209} /* wxDataViewCtrl::Collapse(wxDataViewItem const&) */
07c51ff1
RR
1210
1211void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr)
1212{
1213 if (item.IsOk())
1214 {
1215 // variable definition and initialization:
1216 DataBrowserPropertyID propertyID;
1217 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1218
1219 if (columnPtr != NULL)
1220 propertyID = columnPtr->GetPropertyID();
1221 else
1222 propertyID = kDataBrowserNoItem;
1223 MacDataViewListCtrlPtr->RevealItem(reinterpret_cast<DataBrowserItemID>(item.GetID()),propertyID,kDataBrowserRevealOnly);
1224 } /* if */
1225} /* wxDataViewCtrl::EnsureVisible(wxDataViewItem const&, wxDataViewColumn const*) */
1226
c17b2e31
RR
1227void wxDataViewCtrl::Expand(wxDataViewItem const& item)
1228{
1229 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1230
1231
1232 MacDataViewListCtrlPtr->OpenContainer(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1233} /* wxDataViewCtrl::Expand(wxDataViewItem const&) */
1234
6d9ecc87
RR
1235wxDataViewColumn* wxDataViewCtrl::GetSortingColumn(void) const
1236{
1237 DataBrowserPropertyID propertyID;
1238
1239 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1240
1241
1242 if (MacDataViewListCtrlPtr->GetSortProperty(&propertyID) == noErr)
1243 return this->GetColumnPtr(propertyID);
1244 else
1245 return NULL;
1246} /* wxDataViewCtrl::GetSortingColumn(void) const */
1247
b741dd40
RR
1248unsigned int wxDataViewCtrl::GetCount(void) const
1249{
1250 ItemCount noOfItems;
1251
1252
1253 wxCHECK_MSG(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer)->GetItemCount(&noOfItems) == noErr,0,_("Could not determine number of items"));
1254 return noOfItems;
1255} /* wxDataViewCtrl::GetCount(void) const */
1256
07c51ff1
RR
1257wxRect wxDataViewCtrl::GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const
1258{
1259 if (item.IsOk() && (columnPtr != NULL))
1260 {
1261 // variable definition:
1262 Rect MacRectangle;
1263 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1264
1265 if (MacDataViewListCtrlPtr->GetPartBounds(reinterpret_cast<DataBrowserItemID>(item.GetID()),columnPtr->GetPropertyID(),kDataBrowserPropertyContentPart,&MacRectangle) == noErr)
1266 {
1267 // variable definition:
1268 wxRect rectangle;
1269
1270 ::wxMacNativeToRect(&MacRectangle,&rectangle);
1271 return rectangle;
1272 } /* if */
1273 else
1274 return wxRect();
1275 } /* if */
1276 else
1277 return wxRect();
1278} /* wxDataViewCtrl::GetItemRect(wxDataViewItem const&, unsigned int) const */
1279
1280wxDataViewItem wxDataViewCtrl::GetSelection(void) const
c0a66d92 1281{
c0a66d92 1282 wxArrayDataBrowserItemID itemIDs;
c0a66d92 1283
194027ac 1284 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
c0a66d92
RR
1285
1286
194027ac
RR
1287 if (MacDataViewListCtrlPtr->GetSelectedItemIDs(itemIDs) > 0)
1288 return wxDataViewItem(reinterpret_cast<void*>(itemIDs[0]));
1289 else
1290 return wxDataViewItem();
07c51ff1 1291} /* wxDataViewCtrl::GetSelection(void) const */
c0a66d92 1292
07c51ff1 1293int wxDataViewCtrl::GetSelections(wxDataViewItemArray& sel) const
c0a66d92 1294{
07c51ff1
RR
1295 size_t NoOfSelectedItems;
1296
1297 wxArrayDataBrowserItemID itemIDs;
c0a66d92 1298
07c51ff1
RR
1299 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1300
1301
1302 NoOfSelectedItems = MacDataViewListCtrlPtr->GetSelectedItemIDs(itemIDs);
1303 sel.Empty();
1304 sel.SetCount(NoOfSelectedItems);
1305 for (size_t i=0; i<NoOfSelectedItems; ++i)
1306 sel[i] = wxDataViewItem(reinterpret_cast<void*>(itemIDs[i]));
1307 return static_cast<int>(NoOfSelectedItems);
1308} /* wxDataViewCtrl::GetSelections(wxDataViewItemArray&) const */
c0a66d92 1309
07c51ff1
RR
1310void wxDataViewCtrl::HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const
1311{
1312 item = wxDataViewItem();
1313 columnPtr = NULL;
1314} /* wxDataViewCtrl::HitTest(wxPoint const&, wxDataViewItem&, wxDataViewColumn*&) const */
1315
1316bool wxDataViewCtrl::IsSelected(wxDataViewItem const& item) const
1317{
1318 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1319
1320
1321 return MacDataViewListCtrlPtr->IsItemSelected(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1322} /* wxDataViewCtrl::IsSelected(wxDataViewItem const&) const */
1323
1324void wxDataViewCtrl::SelectAll(void)
1325{
1326 DataBrowserItemID* itemIDPtr;
1327
1328 Handle handle(::NewHandle(0));
1329
1330 size_t NoOfItems;
1331
1332 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1333
1334
1335 wxCHECK_RET(MacDataViewListCtrlPtr->GetItems(kDataBrowserNoItem,true,kDataBrowserItemAnyState,handle) == noErr,_("Could not get items."));
1336 NoOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
1337 HLock(handle);
1338 itemIDPtr = (DataBrowserItemID*) (*handle);
1339 MacDataViewListCtrlPtr->SetSelectedItems(NoOfItems,itemIDPtr,kDataBrowserItemsAssign);
1340 HUnlock(handle);
1341 DisposeHandle(handle);
1342} /* wxDataViewCtrl::SelectAll(void) */
1343
1344void wxDataViewCtrl::Select(wxDataViewItem const& item)
1345{
1346 if (item.IsOk())
1347 {
1348 // variable definition and initialization:
1349 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1350 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1351
1352 MacDataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsAdd);
1353 } /* if */
1354} /* wxDataViewCtrl::Select(wxDataViewItem const&) */
1355
1356void wxDataViewCtrl::SetSelections(wxDataViewItemArray const& sel)
1357{
1358 size_t const NoOfSelections = sel.GetCount();
1359
1360 DataBrowserItemID* itemIDs;
1361
1362 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1363
1364
1365 itemIDs = new DataBrowserItemID[NoOfSelections];
1366 for (size_t i=0; i<NoOfSelections; ++i)
1367 itemIDs[i] = reinterpret_cast<DataBrowserItemID>(sel[i].GetID());
1368 MacDataViewListCtrlPtr->SetSelectedItems(NoOfSelections,itemIDs,kDataBrowserItemsAssign);
1369 delete[] itemIDs;
1370} /* wxDataViewCtrl::SetSelections(wxDataViewItemArray const&) */
1371
1372void wxDataViewCtrl::Unselect(wxDataViewItem const& item)
1373{
1374 if (item.IsOk())
1375 {
1376 // variable definition and initialization:
1377 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1378 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1379
1380 MacDataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsRemove);
1381 } /* if */
1382} /* wxDataViewCtrl::Unselect(wxDataViewItem const&) */
1383
1384void wxDataViewCtrl::UnselectAll(void)
1385{
1386 DataBrowserItemID* itemIDPtr;
1387
1388 Handle handle(::NewHandle(0));
1389
1390 size_t NoOfItems;
1391
1392 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1393
1394
1395 wxCHECK_RET(MacDataViewListCtrlPtr->GetItems(kDataBrowserNoItem,true,kDataBrowserItemAnyState,handle) == noErr,_("Could not get items."));
1396 NoOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
1397 HLock(handle);
1398 itemIDPtr = (DataBrowserItemID*) (*handle);
1399 MacDataViewListCtrlPtr->SetSelectedItems(NoOfItems,itemIDPtr,kDataBrowserItemsRemove);
1400 HUnlock(handle);
1401 DisposeHandle(handle);
1402} /* wxDataViewCtrl::UnselectAll(void) */
c0a66d92 1403
194027ac
RR
1404// data handling:
1405void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const& parentItem)
c0a66d92 1406{
b741dd40
RR
1407 int NoOfChildren;
1408
1409 wxDataViewItemArray items;
c0a66d92 1410
c0a66d92 1411
194027ac 1412 wxCHECK_RET(this->GetModel() != NULL,_("Model pointer not initialized."));
b741dd40 1413 NoOfChildren = this->GetModel()->GetChildren(parentItem,items);
a5fb9253 1414#if 0
b741dd40
RR
1415 for (int i=0; i<NoOfChildren; ++i)
1416 (void) this->GetModel()->ItemAdded(parentItem,items[i]);
a5fb9253
RR
1417#else
1418 (void) this->GetModel()->ItemsAdded(parentItem,items);
1419#endif
194027ac 1420} /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
c0a66d92 1421
99c75ebc
RR
1422void wxDataViewCtrl::FinishCustomItemEditing(void)
1423{
1424 if (this->GetCustomRendererItem().IsOk())
1425 {
1426 this->GetCustomRendererPtr()->FinishEditing();
1427 this->SetCustomRendererItem(wxDataViewItem());
1428 this->SetCustomRendererPtr (NULL);
1429 } /* if */
1430} /* wxDataViewCtrl::FinishCustomItemEditing(void) */
1431
34b1fdeb 1432wxDataViewColumn* wxDataViewCtrl::GetColumnPtr(WXDataBrowserPropertyID propertyID) const
c17b2e31
RR
1433{
1434 // variable definition:
1435 ColumnPointerHashMapType::const_iterator Result(this->m_ColumnPointers.find(propertyID));
1436
1437 if (Result != this->m_ColumnPointers.end())
1438 return Result->second;
1439 else
1440 return NULL;
1441} /* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID) const */
1442
194027ac
RR
1443// inherited methods from wxDataViewCtrlBase
1444void wxDataViewCtrl::DoSetExpanderColumn(void)
c0a66d92 1445{
c17b2e31 1446 if (this->GetExpanderColumn() != NULL)
c0a66d92 1447 {
194027ac 1448 // variable definition and initialization:
194027ac
RR
1449 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1450
99c75ebc 1451 (void) MacDataViewListCtrlPtr->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID(),false); // second parameter explicitely passed to ensure that arrow is centered
c0a66d92 1452 } /* if */
194027ac 1453} /* wxDataViewCtrl::DoSetExpanderColumn(void) */
c0a66d92 1454
194027ac 1455void wxDataViewCtrl::DoSetIndent(void)
c0a66d92 1456{
c17b2e31
RR
1457 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1458
1459
1460 (void) MacDataViewListCtrlPtr->SetIndent(static_cast<float>(this->GetIndent()));
1461} /* wxDataViewCtrl::DoSetIndent(void) */
c0a66d92 1462
194027ac
RR
1463// event handling:
1464void wxDataViewCtrl::OnSize(wxSizeEvent& event)
c0a66d92 1465{
194027ac 1466 unsigned int const NoOfColumns = this->GetColumnCount();
c0a66d92 1467
194027ac
RR
1468
1469 for (unsigned int i=0; i<NoOfColumns; ++i)
c0a66d92
RR
1470 {
1471 // variable definition and initialization:
194027ac
RR
1472 wxDataViewColumn* dataViewColumnPtr(this->GetColumn(i));
1473
1474 if (dataViewColumnPtr != NULL)
c0a66d92 1475 {
194027ac
RR
1476 // variable definition and initialization:
1477 wxDataViewCustomRenderer* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer()));
1478
1479 if (dataViewCustomRendererPtr != NULL)
1480 dataViewCustomRendererPtr->SetDC(NULL); // reset DC because DC has changed
c0a66d92 1481 } /* if */
194027ac 1482 } /* for */
a9c98d7d
RR
1483
1484 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1485 ControlRef ref = MacDataViewListCtrlPtr->GetControlRef();
1486 if (NoOfColumns == 1)
1487 {
1488 ::SetDataBrowserHasScrollBars( ref, false, true );
1489 ::AutoSizeDataBrowserListViewColumns( ref );
1490 }
1491 if (NoOfColumns > 1)
1492 {
1493 ::SetDataBrowserHasScrollBars( ref, true, true );
1494 }
1495
194027ac
RR
1496 event.Skip();
1497} /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
c0a66d92
RR
1498
1499IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl,wxDataViewCtrlBase)
1500
1501BEGIN_EVENT_TABLE(wxDataViewCtrl,wxDataViewCtrlBase)
1502 EVT_SIZE(wxDataViewCtrl::OnSize)
1503END_EVENT_TABLE()
1504
1505#endif
1506 // !wxUSE_GENERICDATAVIEWCTRL
1507
1508#endif
1509 // wxUSE_DATAVIEWCTRL
1510