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