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