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