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