]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dataview.cpp
use WX_ASSERT_STR/SIZET_EQUAL instead of CPPUNIT_ASSERT_EQUAL with casts
[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 #endif
26
27 #include "wx/icon.h"
28 #include "wx/renderer.h"
29
30 //-----------------------------------------------------------------------------
31 // local constants
32 //-----------------------------------------------------------------------------
33
34 // a list of all catchable events:
35 static EventTypeSpec const eventList[] =
36 {
37 {kEventClassControl, kEventControlDraw},
38 {kEventClassControl, kEventControlHit}
39 };
40
41 //-----------------------------------------------------------------------------
42 // local functions
43 //-----------------------------------------------------------------------------
44
45 static pascal OSStatus wxMacDataViewCtrlEventHandler(EventHandlerCallRef handler, EventRef EventReference, void* Data)
46 {
47 wxDataViewCtrl* DataViewCtrlPtr((wxDataViewCtrl*) Data); // the 'Data' variable always contains a pointer to the data view control that installed the handler
48
49 wxMacCarbonEvent CarbonEvent(EventReference) ;
50
51
52 switch (GetEventKind(EventReference))
53 {
54 case kEventControlDraw:
55 {
56 OSStatus status;
57
58 DataViewCtrlPtr->MacSetDrawingContext(CarbonEvent.GetParameter<CGContextRef>(kEventParamCGContextRef,typeCGContextRef));
59 status = ::CallNextEventHandler(handler,EventReference);
60 DataViewCtrlPtr->MacSetDrawingContext(NULL);
61 return status;
62 } /* block */
63 case kEventControlHit :
64 if (CarbonEvent.GetParameter<ControlPartCode>(kEventParamControlPart,typeControlPartCode) == kControlButtonPart) // we only care about the header
65 {
66 ControlRef controlReference;
67 DataBrowserPropertyID columnPropertyID;
68 unsigned long columnIndex;
69 OSStatus status;
70 wxDataViewEvent DataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK,DataViewCtrlPtr->GetId());
71
72 CarbonEvent.GetParameter(kEventParamDirectObject,&controlReference);
73 // determine the column that triggered the event (this is the column that is responsible for sorting the data view):
74 status = ::GetDataBrowserSortProperty(controlReference,&columnPropertyID);
75 wxCHECK(status == noErr,status);
76 status = ::GetDataBrowserTableViewColumnPosition(controlReference,columnPropertyID,&columnIndex);
77 if (status == errDataBrowserPropertyNotFound) // user clicked into part of the header that does not have a property
78 return ::CallNextEventHandler(handler,EventReference);
79 wxCHECK(status == noErr,status);
80 // initialize wxWidget event handler:
81 DataViewEvent.SetEventObject(DataViewCtrlPtr);
82 DataViewEvent.SetColumn(columnIndex);
83 DataViewEvent.SetDataViewColumn(DataViewCtrlPtr->GetColumn(columnIndex));
84 // finally sent the equivalent wxWidget event:
85 DataViewCtrlPtr->GetEventHandler()->ProcessEvent(DataViewEvent);
86 return ::CallNextEventHandler(handler,EventReference);
87 } /* if */
88 else
89 return eventNotHandledErr;
90 } /* switch */
91
92 return eventNotHandledErr;
93 } /* wxMacDataViewCtrlEventHandler(EventHandlerCallRef, EventRef, void*) */
94
95 //-----------------------------------------------------------------------------
96 // local function pointers
97 //-----------------------------------------------------------------------------
98
99 DEFINE_ONE_SHOT_HANDLER_GETTER(wxMacDataViewCtrlEventHandler)
100
101 // ---------------------------------------------------------
102 // wxMacDataViewModelNotifier
103 // ---------------------------------------------------------
104 #pragma mark -
105 class wxMacDataViewModelNotifier : public wxDataViewModelNotifier
106 {
107 public:
108 wxMacDataViewModelNotifier(wxMacDataViewDataBrowserListViewControl* initDataViewControlPtr) : m_dataViewControlPtr(initDataViewControlPtr)
109 {
110 }
111
112 virtual bool ItemAdded(const wxDataViewItem &parent, const wxDataViewItem &item)
113 {
114 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
115
116
117 wxCHECK_MSG(item.IsOk(),false,_("Added item is invalid."));
118 return (!(parent.IsOk()) && (this->m_dataViewControlPtr->AddItem(kDataBrowserNoItem,&itemID) == noErr) ||
119 parent.IsOk() && (this->m_dataViewControlPtr->AddItem(reinterpret_cast<DataBrowserItemID>(parent.GetID()),&itemID) == noErr));
120 } /* ItemAdded(wxDataViewItem const&, wxDataViewItem const&) */
121
122 virtual bool ItemChanged(wxDataViewItem const& item)
123 {
124 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
125
126
127 wxCHECK_MSG(item.IsOk(), false,_("Changed item is invalid."));
128 wxCHECK_MSG(this->GetOwner() != NULL,false,_("Owner not initialized."));
129 if (this->m_dataViewControlPtr->UpdateItems(&itemID) == noErr)
130 {
131 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
132
133 // sent the equivalent wxWidget event:
134 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED,dataViewCtrlPtr->GetId()); // variable defintion
135
136 dataViewEvent.SetEventObject(dataViewCtrlPtr);
137 dataViewEvent.SetItem(item);
138 // sent the equivalent wxWidget event:
139 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
140 // done
141 return true;
142 } /* if */
143 else
144 return false;
145 } /* ItemChanged(wxDataViewItem const&) */
146
147 virtual bool ItemDeleted(wxDataViewItem const& parent, wxDataViewItem const& item)
148 {
149 if (item.IsOk())
150 {
151 // variable definition and initialization:
152 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
153 OSStatus errorStatus;
154 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
155
156 // 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
157 // not to be identical because the being edited item might be below the passed item in the hierarchy); therefore, the control is informed that currently a deleting process
158 // is started and that variables can currently not be updated even when requested by the system:
159 dataViewCtrlPtr->SetDeleting(true);
160 errorStatus = this->m_dataViewControlPtr->RemoveItem(reinterpret_cast<DataBrowserItemID>(parent.GetID()),&itemID);
161 dataViewCtrlPtr->SetDeleting(false);
162 return (errorStatus == noErr);
163 } /* if */
164 else
165 return false;
166 } /* ItemDeleted(wxDataViewItem const&, wxDataViewItem const&) */
167
168 virtual bool ValueChanged(wxDataViewItem const& item, unsigned int col)
169 {
170 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
171 DataBrowserItemID parentID;
172
173 DataBrowserPropertyID propertyID;
174
175 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
176
177
178 wxCHECK_MSG(item.IsOk(), false,_("Passed item is invalid."));
179 wxCHECK_MSG(this->GetOwner() != NULL,false,_("Owner not initialized."));
180 wxCHECK_MSG(dataViewCtrlPtr != NULL, false,_("Control is wrongly initialized."));
181 parentID = reinterpret_cast<DataBrowserItemID>(this->GetOwner()->GetParent(item).GetID());
182 if ((this->m_dataViewControlPtr->GetPropertyID(col,&propertyID) == noErr) &&
183 (this->m_dataViewControlPtr->UpdateItems(parentID,1,&itemID,dataViewCtrlPtr->GetColumn(col)->GetPropertyID(),propertyID) == noErr))
184 {
185 // variable definition and initialization:
186 wxDataViewEvent dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED,dataViewCtrlPtr->GetId());
187
188 dataViewEvent.SetEventObject(dataViewCtrlPtr);
189 dataViewEvent.SetColumn(col);
190 dataViewEvent.SetItem(item);
191 // send the equivalent wxWidget event:
192 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
193 // done
194 return true;
195 } /* if */
196 else
197 return false;
198 } /* ValueChanged(wxDataViewItem const&, unsigned int) */
199
200 virtual bool Cleared(void)
201 {
202 if (this->m_dataViewControlPtr->RemoveItems() == noErr)
203 {
204 // variable definitions and initializations:
205 wxDataViewCtrl* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl*>(this->m_dataViewControlPtr->GetPeer()));
206 wxDataViewEvent dataViewEvent (wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED,dataViewCtrlPtr->GetId());
207
208 dataViewEvent.SetEventObject(dataViewCtrlPtr);
209 // send the equivalent wxWidget event:
210 dataViewCtrlPtr->GetEventHandler()->ProcessEvent(dataViewEvent);
211 // done
212 return true;
213 } /* if */
214 else
215 return false;
216 } /* Cleared(void) */
217
218 virtual void Resort(void)
219 {
220 this->m_dataViewControlPtr->Resort();
221 }
222
223 protected:
224 private:
225 //
226 // variables
227 //
228 wxMacDataViewDataBrowserListViewControl* m_dataViewControlPtr;
229 };
230
231 // ---------------------------------------------------------
232 // wxDataViewRenderer
233 // ---------------------------------------------------------
234 #pragma mark -
235 wxDataViewRenderer::wxDataViewRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
236 :wxDataViewRendererBase(varianttype,mode,align), m_alignment(align), m_mode(mode)
237 {
238 } /* wxDataViewRenderer::wxDataViewRenderer(wxString const&, wxDataViewCellMode) */
239
240 void wxDataViewRenderer::SetMode(wxDataViewCellMode mode)
241 {
242 wxDataViewColumn* dataViewColumnPtr;
243
244
245 this->m_mode = mode;
246 dataViewColumnPtr = this->GetOwner();
247 if (dataViewColumnPtr != NULL)
248 {
249 // variable definition and initialization:
250 wxDataViewCtrl* dataViewCtrlPtr(dataViewColumnPtr->GetOwner());
251
252 if (dataViewCtrlPtr != NULL)
253 {
254 // variable definition and initialization:
255 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
256
257 if (macDataViewListCtrlPtr != NULL)
258 {
259 // variable definition and initialization:
260 DataBrowserPropertyFlags flags;
261
262 verify_noerr(macDataViewListCtrlPtr->GetPropertyFlags(dataViewColumnPtr->GetPropertyID(),&flags));
263 if (mode == wxDATAVIEW_CELL_EDITABLE)
264 flags |= kDataBrowserPropertyIsEditable;
265 else
266 flags &= ~kDataBrowserPropertyIsEditable;
267 verify_noerr(macDataViewListCtrlPtr->SetPropertyFlags(dataViewColumnPtr->GetPropertyID(),flags));
268 } /* if */
269 } /* if */
270 } /* if */
271 } /* wxDataViewRenderer::SetMode(wxDataViewCellMode) */
272
273 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer,wxDataViewRendererBase)
274
275 // ---------------------------------------------------------
276 // wxDataViewCustomRenderer
277 // ---------------------------------------------------------
278 #pragma mark -
279 wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
280 :wxDataViewRenderer(varianttype,mode,align), m_editorCtrlPtr(NULL), m_DCPtr(NULL)
281 {
282 } /* wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const&, wxDataViewCellMode) */
283
284 wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void)
285 {
286 if (this->m_DCPtr != NULL)
287 delete this->m_DCPtr;
288 } /* wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) */
289
290 wxDC* wxDataViewCustomRenderer::GetDC(void)
291 {
292 if (this->m_DCPtr == NULL)
293 {
294 if ((GetOwner() == NULL) || (GetOwner()->GetOwner() == NULL))
295 return NULL;
296 this->m_DCPtr = new wxClientDC(this->GetOwner()->GetOwner());
297 } /* if */
298 return this->m_DCPtr;
299 } /* wxDataViewCustomRenderer::GetDC(void) */
300
301 bool wxDataViewCustomRenderer::Render(void)
302 {
303 return true;
304 } /* wxDataViewCustomRenderer::Render(void) */
305
306 void wxDataViewCustomRenderer::SetDC(wxDC* newDCPtr)
307 {
308 delete this->m_DCPtr;
309 this->m_DCPtr = newDCPtr;
310 } /* wxDataViewCustomRenderer::SetDC(wxDC*) */
311
312
313 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
314
315 // ---------------------------------------------------------
316 // wxDataViewTextRenderer
317 // ---------------------------------------------------------
318 #pragma mark -
319 wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
320 :wxDataViewRenderer(varianttype,mode,align)
321 {
322 } /* wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const&, wxDataViewCellMode, int) */
323
324 bool wxDataViewTextRenderer::Render(void)
325 {
326 if (this->GetValue().GetType() == this->GetVariantType())
327 {
328 // variable definition:
329 wxMacCFStringHolder cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
330
331 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString) == noErr);
332 } /* if */
333 else
334 return false;
335 } /* wxDataViewTextRenderer::Render(void) */
336
337 IMPLEMENT_CLASS(wxDataViewTextRenderer,wxDataViewRenderer)
338
339 // ---------------------------------------------------------
340 // wxDataViewBitmapRenderer
341 // ---------------------------------------------------------
342 #pragma mark -
343 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
344 :wxDataViewRenderer(varianttype,mode,align)
345 {
346 }
347
348 bool wxDataViewBitmapRenderer::Render(void)
349 {
350 if (this->GetValue().GetType() == this->GetVariantType())
351 {
352 wxBitmap bitmap;
353
354 bitmap << this->GetValue();
355 if (bitmap.Ok())
356 return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap.GetBitmapData()->GetIconRef()) == noErr);
357 else
358 return false;
359 } /* if */
360 else
361 return false;
362 } /* wxDataViewBitmapRenderer::Render(void) */
363
364 IMPLEMENT_CLASS(wxDataViewBitmapRenderer,wxDataViewRenderer)
365
366 // ---------------------------------------------------------
367 // wxDataViewIconTextRenderer
368 // ---------------------------------------------------------
369 #pragma mark -
370 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
371 :wxDataViewRenderer(varianttype,mode)
372 {
373 }
374
375 bool wxDataViewIconTextRenderer::Render(void)
376 {
377 wxLogMessage(wxString(_("Types: ")) << this->GetValue().GetType() << wxT(' ') << this->GetVariantType());
378 if (this->GetValue().GetType() == this->GetVariantType())
379 {
380 // variable definition:
381 wxDataViewIconText iconText;
382
383 iconText << this->GetValue();
384
385 // variable definition:
386 wxMacCFStringHolder cfString(iconText.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
387
388 return ((::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText.GetIcon().GetHICON())) == noErr) &&
389 (::SetDataBrowserItemDataText(this->GetDataReference(),cfString) == noErr));
390 } /* if */
391 else
392 return false;
393 } /* wxDataViewIconTextRenderer::Render(void) */
394
395 IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer,wxDataViewRenderer)
396
397
398 // ---------------------------------------------------------
399 // wxDataViewToggleRenderer
400 // ---------------------------------------------------------
401 #pragma mark -
402 wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
403 :wxDataViewRenderer(varianttype,mode)
404 {
405 }
406
407 bool wxDataViewToggleRenderer::Render(void)
408 {
409 if (this->GetValue().GetType() == this->GetVariantType())
410 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr);
411 else
412 return false;
413 } /* wxDataViewToggleRenderer::Render(void) */
414
415 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer,wxDataViewRenderer)
416
417 // ---------------------------------------------------------
418 // wxDataViewProgressRenderer
419 // ---------------------------------------------------------
420 #pragma mark -
421 wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString const& label, wxString const& varianttype, wxDataViewCellMode mode, int align)
422 :wxDataViewRenderer(varianttype,mode,align)
423 {
424 }
425
426 bool wxDataViewProgressRenderer::Render(void)
427 {
428 if (this->GetValue().GetType() == this->GetVariantType())
429 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr) &&
430 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr) &&
431 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr));
432 else
433 return false;
434 } /* wxDataViewProgressRenderer::Render(void) */
435
436 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer,wxDataViewRenderer)
437
438 // ---------------------------------------------------------
439 // wxDataViewDateRenderer
440 // ---------------------------------------------------------
441 #pragma mark -
442 wxDataViewDateRenderer::wxDataViewDateRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
443 :wxDataViewRenderer(varianttype,mode,align)
444 {
445 }
446
447 bool wxDataViewDateRenderer::Render(void)
448 {
449 if (this->GetValue().GetType() == this->GetVariantType())
450 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan,1904)).GetSeconds().GetLo()) == noErr);
451 else
452 return false;
453 } /* wxDataViewDateRenderer::Render(void) */
454
455 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer,wxDataViewRenderer)
456
457 // ---------------------------------------------------------
458 // wxDataViewColumn
459 // ---------------------------------------------------------
460 #pragma mark -
461 wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags)
462 :wxDataViewColumnBase(title,cell,model_column,width,wxALIGN_CENTER,flags), m_ascending(true),
463 m_flags(flags & ~(wxDATAVIEW_COL_HIDDEN | wxDATAVIEW_COL_RESIZABLE)), m_maxWidth(std::numeric_limits<int>::max()), m_minWidth(0), m_width(width),
464 m_alignment(align), m_title(title)
465 {
466 } /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
467
468 wxDataViewColumn::wxDataViewColumn(wxBitmap const& bitmap, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags)
469 :wxDataViewColumnBase(bitmap,cell,model_column,width,wxALIGN_CENTER,flags), m_ascending(true),
470 m_flags(flags & (wxDATAVIEW_COL_HIDDEN | wxDATAVIEW_COL_RESIZABLE)), m_maxWidth(std::numeric_limits<int>::max()), m_minWidth(0), m_width(width),
471 m_alignment(align)
472 {
473 } /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
474
475 void wxDataViewColumn::SetAlignment(wxAlignment align)
476 {
477 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
478
479
480 this->m_alignment = align;
481 if (dataViewCtrlPtr != NULL)
482 {
483 // variable definition and initialization:
484 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
485
486 if (macDataViewListCtrlPtr != NULL)
487 {
488 // variable definition and initialization:
489 DataBrowserListViewHeaderDesc headerDescription;
490
491 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
492 switch (align)
493 {
494 case wxALIGN_CENTER:
495 case wxALIGN_CENTER_HORIZONTAL:
496 headerDescription.btnFontStyle.just = teCenter;
497 break;
498 case wxALIGN_LEFT:
499 headerDescription.btnFontStyle.just = teFlushLeft;
500 break;
501 case wxALIGN_RIGHT:
502 headerDescription.btnFontStyle.just = teFlushRight;
503 break;
504 default:
505 headerDescription.btnFontStyle.just = teFlushDefault;
506 } /* switch */
507 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set alignment."));
508 } /* if */
509 } /* if */
510 } /* wxDataViewColumn::SetAlignment(wxAlignment) */
511
512 void wxDataViewColumn::SetBitmap(wxBitmap const& bitmap)
513 {
514 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
515
516
517 wxDataViewColumnBase::SetBitmap(bitmap);
518 if (dataViewCtrlPtr != NULL)
519 {
520 // variable definition and initialization:
521 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
522
523 if (macDataViewListCtrlPtr != NULL)
524 {
525 // variable definition and initialization:
526 DataBrowserListViewHeaderDesc headerDescription;
527
528 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
529 if (this->GetBitmap().Ok())
530 headerDescription.btnContentInfo.u.iconRef = this->GetBitmap().GetBitmapData()->GetIconRef();
531 else
532 headerDescription.btnContentInfo.u.iconRef = NULL;
533 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set icon."));
534 } /* if */
535 } /* if */
536 } /* wxDataViewColumn::SetBitmap(wxBitmap const&) */
537
538 void wxDataViewColumn::SetFlags(int flags)
539 {
540 this->SetHidden ((flags & wxDATAVIEW_COL_HIDDEN) != 0);
541 this->SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0);
542 this->SetSortable ((flags & wxDATAVIEW_COL_SORTABLE) != 0);
543 } /* wxDataViewColumn::SetFlags(int) */
544
545 void wxDataViewColumn::SetMaxWidth(int maxWidth)
546 {
547 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
548
549
550 this->m_maxWidth = maxWidth;
551 if (dataViewCtrlPtr != NULL)
552 {
553 // variable definition and initialization:
554 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
555
556 if (macDataViewListCtrlPtr != NULL)
557 {
558 // variable definition and initialization:
559 DataBrowserListViewHeaderDesc headerDescription;
560
561 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
562 headerDescription.maximumWidth = static_cast<UInt16>(maxWidth);
563 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set maximum width."));
564 } /* if */
565 } /* if */
566 } /* wxDataViewColumn::SetMaxWidth(int) */
567
568 void wxDataViewColumn::SetMinWidth(int minWidth)
569 {
570 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
571
572
573 this->m_minWidth = minWidth;
574 if (dataViewCtrlPtr != NULL)
575 {
576 // variable definition and initialization:
577 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
578
579 if (macDataViewListCtrlPtr != NULL)
580 {
581 // variable definition and initialization:
582 DataBrowserListViewHeaderDesc headerDescription;
583
584 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
585 headerDescription.minimumWidth = static_cast<UInt16>(minWidth);
586 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set minimum width."));
587 } /* if */
588 } /* if */
589 } /* wxDataViewColumn::SetMaxWidth(int) */
590
591 void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable))
592 {
593 } /* wxDataViewColumn::SetResizeable(bool) */
594
595 void wxDataViewColumn::SetSortable(bool sortable)
596 {
597 // variable definition and initialization:
598 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
599
600 if (dataViewCtrlPtr != NULL)
601 {
602 // variable definition and initialization:
603 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
604
605 if (macDataViewListCtrlPtr != NULL)
606 {
607 // variable definition and initialization:
608 DataBrowserPropertyFlags flags;
609
610 wxCHECK_RET(macDataViewListCtrlPtr->GetPropertyFlags(this->GetPropertyID(),&flags) == noErr,_("Could not get property flags."));
611 if (sortable)
612 {
613 this->m_flags |= wxDATAVIEW_COL_SORTABLE;
614 flags |= kDataBrowserListViewSortableColumn;
615 } /* if */
616 else
617 {
618 this->m_flags &= ~wxDATAVIEW_COL_SORTABLE;
619 flags &= ~kDataBrowserPropertyIsEditable;
620 } /* if */
621 wxCHECK_RET(macDataViewListCtrlPtr->SetPropertyFlags(this->GetPropertyID(),flags) == noErr,_("Could not set property flags."));
622 } /* if */
623 } /* if */
624 } /* wxDataViewColumn::SetSortable(bool) */
625
626 void wxDataViewColumn::SetSortOrder(bool ascending)
627 {
628 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
629
630
631 this->m_ascending = ascending;
632 if (dataViewCtrlPtr != NULL)
633 {
634 // variable definition and initialization:
635 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
636
637 if (macDataViewListCtrlPtr != NULL)
638 {
639 // variable definition and initialization:
640 DataBrowserListViewHeaderDesc headerDescription;
641
642 verify_noerr(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription));
643 if (ascending)
644 headerDescription.initialOrder = kDataBrowserOrderIncreasing;
645 else
646 headerDescription.initialOrder = kDataBrowserOrderDecreasing;
647 verify_noerr(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription));
648 } /* if */
649 } /* if */
650 } /* wxDataViewColumn::SetSortOrder(bool) */
651
652 void wxDataViewColumn::SetTitle(wxString const& title)
653 {
654 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
655
656
657 this->m_title = title;
658 if (dataViewCtrlPtr != NULL)
659 {
660 // variable definition and initialization:
661 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
662
663 if (macDataViewListCtrlPtr != NULL)
664 {
665 // variable definition and initialization:
666 DataBrowserListViewHeaderDesc headerDescription;
667 wxMacCFStringHolder cfTitle(title,(dataViewCtrlPtr->GetFont().Ok() ? dataViewCtrlPtr->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
668
669 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
670 headerDescription.titleString = cfTitle;
671 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set header description."));
672 } /* if */
673 } /* if */
674 } /* wxDataViewColumn::SetTitle(wxString const&) */
675
676 void wxDataViewColumn::SetWidth(int width)
677 {
678 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
679
680
681 if ((width >= this->m_minWidth) && (width <= this->m_maxWidth))
682 {
683 this->m_width = width;
684 if (dataViewCtrlPtr != NULL)
685 {
686 // variable definition and initialization:
687 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
688
689 if (macDataViewListCtrlPtr != NULL)
690 wxCHECK_RET(macDataViewListCtrlPtr->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16>(width)) == noErr,_("Could not set column width."));
691 } /* if */
692 } /* if */
693 } /* wxDataViewColumn::SetWidth(int) */
694
695 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn,wxDataViewColumnBase)
696
697 //-----------------------------------------------------------------------------
698 // wxDataViewCtrl
699 //-----------------------------------------------------------------------------
700 #pragma mark -
701 void wxDataViewCtrl::Init(void)
702 {
703 this->m_Deleting = false;
704 this->m_macIsUserPane = false;
705 this->m_cgContext = NULL;
706 } /* wxDataViewCtrl::Init(void) */
707
708 bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
709 {
710 if (!(this->wxControl::Create(parent,id,pos,size,(style | wxSUNKEN_BORDER) & ~(wxHSCROLL | wxVSCROLL),validator)))
711 return false;
712
713 #ifdef __WXMAC__
714 MacSetClipChildren(true) ;
715 #endif
716
717 this->m_peer = new wxMacDataViewDataBrowserListViewControl(this,pos,size,style);
718 this->MacPostControlCreate(pos,size);
719 ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(this->m_peer->GetControlRef()),true);
720
721 InstallControlEventHandler(this->m_peer->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList),eventList,this,NULL);
722
723 return true;
724 } /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
725
726 bool wxDataViewCtrl::AssociateModel(wxDataViewModel* model)
727 {
728 if (!wxDataViewCtrlBase::AssociateModel(model))
729 return false;
730
731 model->AddNotifier(new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl*>(this->m_peer)));
732
733 return true;
734 } /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
735
736 bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* dataViewColumnPtr)
737 {
738 DataBrowserPropertyID NewPropertyID;
739
740 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
741
742
743 // first, some error checking:
744 wxCHECK_MSG(MacDataViewListCtrlPtr != NULL, false,_("m_peer is not or incorrectly initialized"));
745 wxCHECK_MSG(dataViewColumnPtr != NULL, false,_("Column pointer must not be NULL."));
746 wxCHECK_MSG(dataViewColumnPtr->GetRenderer() != NULL, false,_("Column does not have a renderer."));
747 wxCHECK_MSG(this->GetModel() != NULL, false,_("No model associated with control."));
748 wxCHECK_MSG((dataViewColumnPtr->GetModelColumn() >= 0) &&
749 (dataViewColumnPtr->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
750 if ((MacDataViewListCtrlPtr->GetFreePropertyID(&NewPropertyID) == noErr) && this->wxDataViewCtrlBase::AppendColumn(dataViewColumnPtr))
751 {
752 // insert column into hash map:
753 this->m_ColumnPointers.insert(ColumnPointerHashMapType::value_type(NewPropertyID,dataViewColumnPtr));
754
755 // variable definitions:
756 DataBrowserListViewColumnDesc columnDescription;
757 wxMacCFStringHolder cfTitle(dataViewColumnPtr->GetTitle(),(this->m_font.Ok() ? this->m_font.GetEncoding() : wxLocale::GetSystemEncoding()));
758
759 // initialize column description:
760 dataViewColumnPtr->SetPropertyID(NewPropertyID);
761 if (dataViewColumnPtr->GetWidth() <= 0)
762 dataViewColumnPtr->SetWidth(wxDVC_DEFAULT_WIDTH);
763 columnDescription.propertyDesc.propertyID = NewPropertyID;
764 columnDescription.propertyDesc.propertyType = dataViewColumnPtr->GetRenderer()->GetPropertyType();
765 columnDescription.propertyDesc.propertyFlags = kDataBrowserListViewSelectionColumn; // make the column selectable
766 if (dataViewColumnPtr->IsSortable())
767 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewSortableColumn;
768 #if 0
769 if (dataViewColumnPtr->IsMovable())
770 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewMovableColumn;
771 #endif
772 if (dataViewColumnPtr->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE)
773 columnDescription.propertyDesc.propertyFlags |= kDataBrowserPropertyIsEditable;
774 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
775 if ((columnDescription.propertyDesc.propertyType == kDataBrowserTextType) ||
776 (columnDescription.propertyDesc.propertyType == kDataBrowserIconAndTextType) ||
777 (columnDescription.propertyDesc.propertyType == kDataBrowserDateTimeType))
778 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
779 #endif
780 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
781 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton;
782 #endif
783 columnDescription.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
784 if (dataViewColumnPtr->IsResizeable())
785 {
786 columnDescription.headerBtnDesc.minimumWidth = 0;
787 columnDescription.headerBtnDesc.maximumWidth = 30000;
788 } /* if */
789 else
790 {
791 columnDescription.headerBtnDesc.minimumWidth = dataViewColumnPtr->GetWidth();
792 columnDescription.headerBtnDesc.maximumWidth = dataViewColumnPtr->GetWidth();
793 } /* if */
794 columnDescription.headerBtnDesc.titleOffset = 0;
795 columnDescription.headerBtnDesc.titleString = cfTitle; // we cannot directly use the wxMacCFStringHolder constructor call because then the CFStringRef is released
796 // having called 'AddColumn' where the title (CFStringRef) is going to be used
797 columnDescription.headerBtnDesc.initialOrder = kDataBrowserOrderIncreasing;
798 columnDescription.headerBtnDesc.btnFontStyle.flags = kControlUseFontMask | kControlUseJustMask;
799 switch (dataViewColumnPtr->GetAlignment())
800 {
801 case wxALIGN_CENTER:
802 case wxALIGN_CENTER_HORIZONTAL:
803 columnDescription.headerBtnDesc.btnFontStyle.just = teCenter;
804 break;
805 case wxALIGN_LEFT:
806 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushLeft;
807 break;
808 case wxALIGN_RIGHT:
809 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushRight;
810 break;
811 default:
812 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushDefault;
813 } /* switch */
814 columnDescription.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
815 columnDescription.headerBtnDesc.btnFontStyle.style = normal;
816 columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentIconRef;
817 if (dataViewColumnPtr->GetBitmap().Ok())
818 columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = dataViewColumnPtr->GetBitmap().GetBitmapData()->GetIconRef();
819 // add column:
820 wxCHECK_MSG(MacDataViewListCtrlPtr->AddColumn(&columnDescription,kDataBrowserListViewAppendColumn) == noErr,false,_("Column could not be added."));
821
822 // final adjustments for the layout:
823 wxCHECK_MSG(MacDataViewListCtrlPtr->SetColumnWidth(NewPropertyID,dataViewColumnPtr->GetWidth()) == noErr,false,_("Column width could not be set."));
824 if (dataViewColumnPtr == this->GetExpanderColumn()) // if the current column is marked expandable this column will become the active expandable column
825 MacDataViewListCtrlPtr->SetDisclosureColumn(NewPropertyID,true);
826
827 // make sure that the data is up-to-date...
828 // if the newly appended column is the first column add the initial data to the control otherwise ask the control to 'update' the data in the newly appended column:
829 if (this->GetColumnCount() == 1)
830 this->AddChildrenLevel(wxDataViewItem());
831 else
832 MacDataViewListCtrlPtr->UpdateItems(kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty,NewPropertyID);
833 // done:
834 return true;
835 } /* if */
836 else
837 return false;
838 } /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
839
840 bool wxDataViewCtrl::ClearColumns(void)
841 {
842 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
843
844
845 while (this->m_ColumnPointers.begin() != this->m_ColumnPointers.end())
846 {
847 wxCHECK_MSG(MacDataViewListCtrlPtr->RemoveColumnByProperty(this->m_ColumnPointers.begin()->first) == noErr,false,_("Could not remove column."));
848 delete this->m_ColumnPointers.begin()->second;
849 this->m_ColumnPointers.erase(this->m_ColumnPointers.begin());
850 } /* while */
851 return true;
852 } /* wxDataViewCtrl::ClearColumns(void) */
853
854 bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn* columnPtr)
855 {
856 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
857
858
859 if ((MacDataViewListCtrlPtr->RemoveColumnByProperty(columnPtr->GetPropertyID()) == noErr) && (this->m_ColumnPointers.erase(columnPtr->GetPropertyID()) > 0))
860 {
861 delete columnPtr;
862 return true;
863 } /* if */
864 else
865 return false;
866 } /* wxDataViewCtrl::DeleteColumn(wxDataViewColumn*) */
867
868 wxDataViewColumn* wxDataViewCtrl::GetColumn(unsigned int pos) const
869 {
870 DataBrowserPropertyID propertyID;
871
872 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
873
874
875 if (MacDataViewListCtrlPtr->GetPropertyID(pos,&propertyID) == noErr)
876 {
877 // variable definition:
878 ColumnPointerHashMapType::const_iterator Result(this->m_ColumnPointers.find(propertyID));
879
880 if (Result != this->m_ColumnPointers.end())
881 return Result->second;
882 else
883 return NULL;
884 } /* if */
885 else
886 return NULL;
887 } /* wxDataViewCtrl::GetColumn(unsigned int pos) const */
888
889 unsigned int wxDataViewCtrl::GetColumnCount(void) const
890 {
891 return this->m_ColumnPointers.size();
892 } /* wxDataViewCtrl::GetColumnCount(void) const */
893
894 void wxDataViewCtrl::Collapse(wxDataViewItem const& item)
895 {
896 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
897
898
899 MacDataViewListCtrlPtr->CloseContainer(reinterpret_cast<DataBrowserItemID>(item.GetID()));
900 } /* wxDataViewCtrl::Collapse(wxDataViewItem const&) */
901
902 void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr)
903 {
904 if (item.IsOk())
905 {
906 // variable definition and initialization:
907 DataBrowserPropertyID propertyID;
908 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
909
910 if (columnPtr != NULL)
911 propertyID = columnPtr->GetPropertyID();
912 else
913 propertyID = kDataBrowserNoItem;
914 MacDataViewListCtrlPtr->RevealItem(reinterpret_cast<DataBrowserItemID>(item.GetID()),propertyID,kDataBrowserRevealOnly);
915 } /* if */
916 } /* wxDataViewCtrl::EnsureVisible(wxDataViewItem const&, wxDataViewColumn const*) */
917
918 void wxDataViewCtrl::Expand(wxDataViewItem const& item)
919 {
920 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
921
922
923 MacDataViewListCtrlPtr->OpenContainer(reinterpret_cast<DataBrowserItemID>(item.GetID()));
924 } /* wxDataViewCtrl::Expand(wxDataViewItem const&) */
925
926 wxRect wxDataViewCtrl::GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const
927 {
928 if (item.IsOk() && (columnPtr != NULL))
929 {
930 // variable definition:
931 Rect MacRectangle;
932 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
933
934 if (MacDataViewListCtrlPtr->GetPartBounds(reinterpret_cast<DataBrowserItemID>(item.GetID()),columnPtr->GetPropertyID(),kDataBrowserPropertyContentPart,&MacRectangle) == noErr)
935 {
936 // variable definition:
937 wxRect rectangle;
938
939 ::wxMacNativeToRect(&MacRectangle,&rectangle);
940 return rectangle;
941 } /* if */
942 else
943 return wxRect();
944 } /* if */
945 else
946 return wxRect();
947 } /* wxDataViewCtrl::GetItemRect(wxDataViewItem const&, unsigned int) const */
948
949 wxDataViewItem wxDataViewCtrl::GetSelection(void) const
950 {
951 wxArrayDataBrowserItemID itemIDs;
952
953 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
954
955
956 if (MacDataViewListCtrlPtr->GetSelectedItemIDs(itemIDs) > 0)
957 return wxDataViewItem(reinterpret_cast<void*>(itemIDs[0]));
958 else
959 return wxDataViewItem();
960 } /* wxDataViewCtrl::GetSelection(void) const */
961
962 int wxDataViewCtrl::GetSelections(wxDataViewItemArray& sel) const
963 {
964 size_t NoOfSelectedItems;
965
966 wxArrayDataBrowserItemID itemIDs;
967
968 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
969
970
971 NoOfSelectedItems = MacDataViewListCtrlPtr->GetSelectedItemIDs(itemIDs);
972 sel.Empty();
973 sel.SetCount(NoOfSelectedItems);
974 for (size_t i=0; i<NoOfSelectedItems; ++i)
975 sel[i] = wxDataViewItem(reinterpret_cast<void*>(itemIDs[i]));
976 return static_cast<int>(NoOfSelectedItems);
977 } /* wxDataViewCtrl::GetSelections(wxDataViewItemArray&) const */
978
979 void wxDataViewCtrl::HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const
980 {
981 item = wxDataViewItem();
982 columnPtr = NULL;
983 } /* wxDataViewCtrl::HitTest(wxPoint const&, wxDataViewItem&, wxDataViewColumn*&) const */
984
985 bool wxDataViewCtrl::IsSelected(wxDataViewItem const& item) const
986 {
987 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
988
989
990 return MacDataViewListCtrlPtr->IsItemSelected(reinterpret_cast<DataBrowserItemID>(item.GetID()));
991 } /* wxDataViewCtrl::IsSelected(wxDataViewItem const&) const */
992
993 void wxDataViewCtrl::SelectAll(void)
994 {
995 DataBrowserItemID* itemIDPtr;
996
997 Handle handle(::NewHandle(0));
998
999 size_t NoOfItems;
1000
1001 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1002
1003
1004 wxCHECK_RET(MacDataViewListCtrlPtr->GetItems(kDataBrowserNoItem,true,kDataBrowserItemAnyState,handle) == noErr,_("Could not get items."));
1005 NoOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
1006 HLock(handle);
1007 itemIDPtr = (DataBrowserItemID*) (*handle);
1008 MacDataViewListCtrlPtr->SetSelectedItems(NoOfItems,itemIDPtr,kDataBrowserItemsAssign);
1009 HUnlock(handle);
1010 DisposeHandle(handle);
1011 } /* wxDataViewCtrl::SelectAll(void) */
1012
1013 void wxDataViewCtrl::Select(wxDataViewItem const& item)
1014 {
1015 if (item.IsOk())
1016 {
1017 // variable definition and initialization:
1018 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1019 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1020
1021 MacDataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsAdd);
1022 } /* if */
1023 } /* wxDataViewCtrl::Select(wxDataViewItem const&) */
1024
1025 void wxDataViewCtrl::SetSelections(wxDataViewItemArray const& sel)
1026 {
1027 size_t const NoOfSelections = sel.GetCount();
1028
1029 DataBrowserItemID* itemIDs;
1030
1031 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1032
1033
1034 itemIDs = new DataBrowserItemID[NoOfSelections];
1035 for (size_t i=0; i<NoOfSelections; ++i)
1036 itemIDs[i] = reinterpret_cast<DataBrowserItemID>(sel[i].GetID());
1037 MacDataViewListCtrlPtr->SetSelectedItems(NoOfSelections,itemIDs,kDataBrowserItemsAssign);
1038 delete[] itemIDs;
1039 } /* wxDataViewCtrl::SetSelections(wxDataViewItemArray const&) */
1040
1041 void wxDataViewCtrl::Unselect(wxDataViewItem const& item)
1042 {
1043 if (item.IsOk())
1044 {
1045 // variable definition and initialization:
1046 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1047 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1048
1049 MacDataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsRemove);
1050 } /* if */
1051 } /* wxDataViewCtrl::Unselect(wxDataViewItem const&) */
1052
1053 void wxDataViewCtrl::UnselectAll(void)
1054 {
1055 DataBrowserItemID* itemIDPtr;
1056
1057 Handle handle(::NewHandle(0));
1058
1059 size_t NoOfItems;
1060
1061 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1062
1063
1064 wxCHECK_RET(MacDataViewListCtrlPtr->GetItems(kDataBrowserNoItem,true,kDataBrowserItemAnyState,handle) == noErr,_("Could not get items."));
1065 NoOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
1066 HLock(handle);
1067 itemIDPtr = (DataBrowserItemID*) (*handle);
1068 MacDataViewListCtrlPtr->SetSelectedItems(NoOfItems,itemIDPtr,kDataBrowserItemsRemove);
1069 HUnlock(handle);
1070 DisposeHandle(handle);
1071 } /* wxDataViewCtrl::UnselectAll(void) */
1072
1073 // data handling:
1074 void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const& parentItem)
1075 {
1076 wxDataViewItem item;
1077
1078
1079 wxCHECK_RET(this->GetModel() != NULL,_("Model pointer not initialized."));
1080 item = this->GetModel()->GetFirstChild(parentItem);
1081 while (item.IsOk())
1082 {
1083 (void) this->GetModel()->ItemAdded(parentItem,item);
1084 item = this->GetModel()->GetNextSibling(item);
1085 } /* while */
1086 } /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
1087
1088 wxDataViewColumn* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID propertyID) const
1089 {
1090 // variable definition:
1091 ColumnPointerHashMapType::const_iterator Result(this->m_ColumnPointers.find(propertyID));
1092
1093 if (Result != this->m_ColumnPointers.end())
1094 return Result->second;
1095 else
1096 return NULL;
1097 } /* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID) const */
1098
1099 // inherited methods from wxDataViewCtrlBase
1100 void wxDataViewCtrl::DoSetExpanderColumn(void)
1101 {
1102 if (this->GetExpanderColumn() != NULL)
1103 {
1104 // variable definition and initialization:
1105 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1106
1107 (void) MacDataViewListCtrlPtr->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID());
1108 } /* if */
1109 } /* wxDataViewCtrl::DoSetExpanderColumn(void) */
1110
1111 void wxDataViewCtrl::DoSetIndent(void)
1112 {
1113 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1114
1115
1116 (void) MacDataViewListCtrlPtr->SetIndent(static_cast<float>(this->GetIndent()));
1117 } /* wxDataViewCtrl::DoSetIndent(void) */
1118
1119 // event handling:
1120 void wxDataViewCtrl::OnSize(wxSizeEvent& event)
1121 {
1122 unsigned int const NoOfColumns = this->GetColumnCount();
1123
1124
1125 for (unsigned int i=0; i<NoOfColumns; ++i)
1126 {
1127 // variable definition and initialization:
1128 wxDataViewColumn* dataViewColumnPtr(this->GetColumn(i));
1129
1130 if (dataViewColumnPtr != NULL)
1131 {
1132 // variable definition and initialization:
1133 wxDataViewCustomRenderer* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer()));
1134
1135 if (dataViewCustomRendererPtr != NULL)
1136 dataViewCustomRendererPtr->SetDC(NULL); // reset DC because DC has changed
1137 } /* if */
1138 } /* for */
1139 event.Skip();
1140 } /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
1141
1142 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl,wxDataViewCtrlBase)
1143
1144 BEGIN_EVENT_TABLE(wxDataViewCtrl,wxDataViewCtrlBase)
1145 EVT_SIZE(wxDataViewCtrl::OnSize)
1146 END_EVENT_TABLE()
1147
1148 #endif
1149 // !wxUSE_GENERICDATAVIEWCTRL
1150
1151 #endif
1152 // wxUSE_DATAVIEWCTRL
1153