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