]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dataview.cpp
remove the drag-and-drop compatibility hack for extracting the embedded size of the...
[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 true;
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 if (this->GetValue().GetType() == this->GetVariantType())
378 {
379 // variable definition:
380 wxDataViewIconText iconText;
381
382 iconText << this->GetValue();
383
384 // variable definition:
385 wxMacCFStringHolder cfString(iconText.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
386
387 return ((::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText.GetIcon().GetHICON())) == noErr) &&
388 (::SetDataBrowserItemDataText(this->GetDataReference(),cfString) == noErr));
389 } /* if */
390 else
391 return false;
392 } /* wxDataViewIconTextRenderer::Render(void) */
393
394 IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer,wxDataViewRenderer)
395
396
397 // ---------------------------------------------------------
398 // wxDataViewToggleRenderer
399 // ---------------------------------------------------------
400 #pragma mark -
401 wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
402 :wxDataViewRenderer(varianttype,mode)
403 {
404 }
405
406 bool wxDataViewToggleRenderer::Render(void)
407 {
408 if (this->GetValue().GetType() == this->GetVariantType())
409 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr);
410 else
411 return false;
412 } /* wxDataViewToggleRenderer::Render(void) */
413
414 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer,wxDataViewRenderer)
415
416 // ---------------------------------------------------------
417 // wxDataViewProgressRenderer
418 // ---------------------------------------------------------
419 #pragma mark -
420 wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString const& label, wxString const& varianttype, wxDataViewCellMode mode, int align)
421 :wxDataViewRenderer(varianttype,mode,align)
422 {
423 }
424
425 bool wxDataViewProgressRenderer::Render(void)
426 {
427 if (this->GetValue().GetType() == this->GetVariantType())
428 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr) &&
429 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr) &&
430 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr));
431 else
432 return false;
433 } /* wxDataViewProgressRenderer::Render(void) */
434
435 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer,wxDataViewRenderer)
436
437 // ---------------------------------------------------------
438 // wxDataViewDateRenderer
439 // ---------------------------------------------------------
440 #pragma mark -
441 wxDataViewDateRenderer::wxDataViewDateRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
442 :wxDataViewRenderer(varianttype,mode,align)
443 {
444 }
445
446 bool wxDataViewDateRenderer::Render(void)
447 {
448 if (this->GetValue().GetType() == this->GetVariantType())
449 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan,1904)).GetSeconds().GetLo()) == noErr);
450 else
451 return false;
452 } /* wxDataViewDateRenderer::Render(void) */
453
454 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer,wxDataViewRenderer)
455
456 // ---------------------------------------------------------
457 // wxDataViewColumn
458 // ---------------------------------------------------------
459 #pragma mark -
460 wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags)
461 :wxDataViewColumnBase(title,cell,model_column,width,wxALIGN_CENTER,flags), m_ascending(true),
462 m_flags(flags & ~(wxDATAVIEW_COL_HIDDEN)), m_maxWidth(30000), m_minWidth(0), m_width(width >= 0 ? width : wxDVC_DEFAULT_WIDTH),
463 m_alignment(align), m_title(title)
464 {
465 } /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
466
467 wxDataViewColumn::wxDataViewColumn(wxBitmap const& bitmap, wxDataViewRenderer *cell, unsigned int model_column, int width, wxAlignment align, int flags)
468 :wxDataViewColumnBase(bitmap,cell,model_column,width,wxALIGN_CENTER,flags), m_ascending(true),
469 m_flags(flags & ~(wxDATAVIEW_COL_HIDDEN)), m_maxWidth(30000), m_minWidth(0), m_width(width >= 0 ? width : wxDVC_DEFAULT_WIDTH),
470 m_alignment(align)
471 {
472 } /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
473
474 void wxDataViewColumn::SetAlignment(wxAlignment align)
475 {
476 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
477
478
479 this->m_alignment = align;
480 if (dataViewCtrlPtr != NULL)
481 {
482 // variable definition and initialization:
483 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
484
485 if (macDataViewListCtrlPtr != NULL)
486 {
487 // variable definition and initialization:
488 DataBrowserListViewHeaderDesc headerDescription;
489
490 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
491 switch (align)
492 {
493 case wxALIGN_CENTER:
494 case wxALIGN_CENTER_HORIZONTAL:
495 headerDescription.btnFontStyle.just = teCenter;
496 break;
497 case wxALIGN_LEFT:
498 headerDescription.btnFontStyle.just = teFlushLeft;
499 break;
500 case wxALIGN_RIGHT:
501 headerDescription.btnFontStyle.just = teFlushRight;
502 break;
503 default:
504 headerDescription.btnFontStyle.just = teFlushDefault;
505 } /* switch */
506 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set alignment."));
507 } /* if */
508 } /* if */
509 } /* wxDataViewColumn::SetAlignment(wxAlignment) */
510
511 void wxDataViewColumn::SetBitmap(wxBitmap const& bitmap)
512 {
513 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
514
515
516 wxDataViewColumnBase::SetBitmap(bitmap);
517 if (dataViewCtrlPtr != NULL)
518 {
519 // variable definition and initialization:
520 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
521
522 if (macDataViewListCtrlPtr != NULL)
523 {
524 // variable definition and initialization:
525 DataBrowserListViewHeaderDesc headerDescription;
526
527 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
528 if (this->GetBitmap().Ok())
529 headerDescription.btnContentInfo.u.iconRef = this->GetBitmap().GetBitmapData()->GetIconRef();
530 else
531 headerDescription.btnContentInfo.u.iconRef = NULL;
532 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set icon."));
533 } /* if */
534 } /* if */
535 } /* wxDataViewColumn::SetBitmap(wxBitmap const&) */
536
537 void wxDataViewColumn::SetFlags(int flags)
538 {
539 this->SetHidden ((flags & wxDATAVIEW_COL_HIDDEN) != 0);
540 this->SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0);
541 this->SetSortable ((flags & wxDATAVIEW_COL_SORTABLE) != 0);
542 } /* wxDataViewColumn::SetFlags(int) */
543
544 void wxDataViewColumn::SetMaxWidth(int maxWidth)
545 {
546 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
547
548
549 this->m_maxWidth = maxWidth;
550 if (dataViewCtrlPtr != NULL)
551 {
552 // variable definition and initialization:
553 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
554
555 if (macDataViewListCtrlPtr != NULL)
556 {
557 // variable definition and initialization:
558 DataBrowserListViewHeaderDesc headerDescription;
559
560 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
561 headerDescription.maximumWidth = static_cast<UInt16>(maxWidth);
562 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set maximum width."));
563 } /* if */
564 } /* if */
565 } /* wxDataViewColumn::SetMaxWidth(int) */
566
567 void wxDataViewColumn::SetMinWidth(int minWidth)
568 {
569 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
570
571
572 this->m_minWidth = minWidth;
573 if (dataViewCtrlPtr != NULL)
574 {
575 // variable definition and initialization:
576 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
577
578 if (macDataViewListCtrlPtr != NULL)
579 {
580 // variable definition and initialization:
581 DataBrowserListViewHeaderDesc headerDescription;
582
583 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
584 headerDescription.minimumWidth = static_cast<UInt16>(minWidth);
585 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set minimum width."));
586 } /* if */
587 } /* if */
588 } /* wxDataViewColumn::SetMaxWidth(int) */
589
590 void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable))
591 {
592 } /* wxDataViewColumn::SetResizeable(bool) */
593
594 void wxDataViewColumn::SetSortable(bool sortable)
595 {
596 // variable definition and initialization:
597 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
598
599 if (dataViewCtrlPtr != NULL)
600 {
601 // variable definition and initialization:
602 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
603
604 if (macDataViewListCtrlPtr != NULL)
605 {
606 // variable definition and initialization:
607 DataBrowserPropertyFlags flags;
608
609 wxCHECK_RET(macDataViewListCtrlPtr->GetPropertyFlags(this->GetPropertyID(),&flags) == noErr,_("Could not get property flags."));
610 if (sortable)
611 {
612 this->m_flags |= wxDATAVIEW_COL_SORTABLE;
613 flags |= kDataBrowserListViewSortableColumn;
614 } /* if */
615 else
616 {
617 this->m_flags &= ~wxDATAVIEW_COL_SORTABLE;
618 flags &= ~kDataBrowserPropertyIsEditable;
619 } /* if */
620 wxCHECK_RET(macDataViewListCtrlPtr->SetPropertyFlags(this->GetPropertyID(),flags) == noErr,_("Could not set property flags."));
621 } /* if */
622 } /* if */
623 } /* wxDataViewColumn::SetSortable(bool) */
624
625 void wxDataViewColumn::SetSortOrder(bool ascending)
626 {
627 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
628
629
630 this->m_ascending = ascending;
631 if (dataViewCtrlPtr != NULL)
632 {
633 // variable definition and initialization:
634 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
635
636 if (macDataViewListCtrlPtr != NULL)
637 {
638 // variable definition and initialization:
639 DataBrowserListViewHeaderDesc headerDescription;
640
641 verify_noerr(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription));
642 if (ascending)
643 headerDescription.initialOrder = kDataBrowserOrderIncreasing;
644 else
645 headerDescription.initialOrder = kDataBrowserOrderDecreasing;
646 verify_noerr(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription));
647 } /* if */
648 } /* if */
649 } /* wxDataViewColumn::SetSortOrder(bool) */
650
651 void wxDataViewColumn::SetTitle(wxString const& title)
652 {
653 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
654
655
656 this->m_title = title;
657 if (dataViewCtrlPtr != NULL)
658 {
659 // variable definition and initialization:
660 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
661
662 if (macDataViewListCtrlPtr != NULL)
663 {
664 // variable definition and initialization:
665 DataBrowserListViewHeaderDesc headerDescription;
666 wxMacCFStringHolder cfTitle(title,(dataViewCtrlPtr->GetFont().Ok() ? dataViewCtrlPtr->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
667
668 wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
669 headerDescription.titleString = cfTitle;
670 wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(this->GetPropertyID(),&headerDescription) == noErr,_("Could not set header description."));
671 } /* if */
672 } /* if */
673 } /* wxDataViewColumn::SetTitle(wxString const&) */
674
675 void wxDataViewColumn::SetWidth(int width)
676 {
677 wxDataViewCtrl* dataViewCtrlPtr(this->GetOwner());
678
679
680 if ((width >= this->m_minWidth) && (width <= this->m_maxWidth))
681 {
682 this->m_width = width;
683 if (dataViewCtrlPtr != NULL)
684 {
685 // variable definition and initialization:
686 wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
687
688 if (macDataViewListCtrlPtr != NULL)
689 wxCHECK_RET(macDataViewListCtrlPtr->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16>(width)) == noErr,_("Could not set column width."));
690 } /* if */
691 } /* if */
692 } /* wxDataViewColumn::SetWidth(int) */
693
694 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn,wxDataViewColumnBase)
695
696 //-----------------------------------------------------------------------------
697 // wxDataViewCtrl
698 //-----------------------------------------------------------------------------
699 #pragma mark -
700 void wxDataViewCtrl::Init(void)
701 {
702 this->m_Deleting = false;
703 this->m_macIsUserPane = false;
704 this->m_cgContext = NULL;
705 } /* wxDataViewCtrl::Init(void) */
706
707 bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
708 {
709 if (!(this->wxControl::Create(parent,id,pos,size,(style | wxSUNKEN_BORDER) & ~(wxHSCROLL | wxVSCROLL),validator)))
710 return false;
711
712 #ifdef __WXMAC__
713 MacSetClipChildren(true) ;
714 #endif
715
716 this->m_peer = new wxMacDataViewDataBrowserListViewControl(this,pos,size,style);
717 this->MacPostControlCreate(pos,size);
718 ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(this->m_peer->GetControlRef()),true);
719
720 InstallControlEventHandler(this->m_peer->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList),eventList,this,NULL);
721
722 return true;
723 } /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
724
725 bool wxDataViewCtrl::AssociateModel(wxDataViewModel* model)
726 {
727 if (!wxDataViewCtrlBase::AssociateModel(model))
728 return false;
729
730 model->AddNotifier(new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl*>(this->m_peer)));
731
732 return true;
733 } /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
734
735 bool wxDataViewCtrl::AppendColumn(wxDataViewColumn* dataViewColumnPtr)
736 {
737 DataBrowserPropertyID NewPropertyID;
738
739 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
740
741
742 // first, some error checking:
743 wxCHECK_MSG(MacDataViewListCtrlPtr != NULL, false,_("m_peer is not or incorrectly initialized"));
744 wxCHECK_MSG(dataViewColumnPtr != NULL, false,_("Column pointer must not be NULL."));
745 wxCHECK_MSG(dataViewColumnPtr->GetRenderer() != NULL, false,_("Column does not have a renderer."));
746 wxCHECK_MSG(this->GetModel() != NULL, false,_("No model associated with control."));
747 wxCHECK_MSG((dataViewColumnPtr->GetModelColumn() >= 0) &&
748 (dataViewColumnPtr->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
749 if ((MacDataViewListCtrlPtr->GetFreePropertyID(&NewPropertyID) == noErr) && this->wxDataViewCtrlBase::AppendColumn(dataViewColumnPtr))
750 {
751 // insert column into hash map:
752 this->m_ColumnPointers.insert(ColumnPointerHashMapType::value_type(NewPropertyID,dataViewColumnPtr));
753
754 // variable definitions:
755 DataBrowserListViewColumnDesc columnDescription;
756 wxMacCFStringHolder cfTitle(dataViewColumnPtr->GetTitle(),(this->m_font.Ok() ? this->m_font.GetEncoding() : wxLocale::GetSystemEncoding()));
757
758 // initialize column description:
759 dataViewColumnPtr->SetPropertyID(NewPropertyID);
760 columnDescription.propertyDesc.propertyID = NewPropertyID;
761 columnDescription.propertyDesc.propertyType = dataViewColumnPtr->GetRenderer()->GetPropertyType();
762 columnDescription.propertyDesc.propertyFlags = kDataBrowserListViewSelectionColumn; // make the column selectable
763 if (dataViewColumnPtr->IsSortable())
764 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewSortableColumn;
765 #if 0
766 if (dataViewColumnPtr->IsMovable())
767 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewMovableColumn;
768 #endif
769 if (dataViewColumnPtr->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE)
770 columnDescription.propertyDesc.propertyFlags |= kDataBrowserPropertyIsEditable;
771 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
772 if ((columnDescription.propertyDesc.propertyType == kDataBrowserTextType) ||
773 (columnDescription.propertyDesc.propertyType == kDataBrowserIconAndTextType) ||
774 (columnDescription.propertyDesc.propertyType == kDataBrowserDateTimeType))
775 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
776 #endif
777 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
778 columnDescription.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton;
779 #endif
780 columnDescription.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
781 if (dataViewColumnPtr->IsResizeable())
782 {
783 columnDescription.headerBtnDesc.minimumWidth = 0;
784 columnDescription.headerBtnDesc.maximumWidth = 30000;
785 } /* if */
786 else
787 {
788 columnDescription.headerBtnDesc.minimumWidth = dataViewColumnPtr->GetWidth();
789 columnDescription.headerBtnDesc.maximumWidth = dataViewColumnPtr->GetWidth();
790 } /* if */
791 columnDescription.headerBtnDesc.titleOffset = 0;
792 columnDescription.headerBtnDesc.titleString = cfTitle; // we cannot directly use the wxMacCFStringHolder constructor call because then the CFStringRef is released
793 // having called 'AddColumn' where the title (CFStringRef) is going to be used
794 columnDescription.headerBtnDesc.initialOrder = kDataBrowserOrderIncreasing;
795 columnDescription.headerBtnDesc.btnFontStyle.flags = kControlUseFontMask | kControlUseJustMask;
796 switch (dataViewColumnPtr->GetAlignment())
797 {
798 case wxALIGN_CENTER:
799 case wxALIGN_CENTER_HORIZONTAL:
800 columnDescription.headerBtnDesc.btnFontStyle.just = teCenter;
801 break;
802 case wxALIGN_LEFT:
803 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushLeft;
804 break;
805 case wxALIGN_RIGHT:
806 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushRight;
807 break;
808 default:
809 columnDescription.headerBtnDesc.btnFontStyle.just = teFlushDefault;
810 } /* switch */
811 columnDescription.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
812 columnDescription.headerBtnDesc.btnFontStyle.style = normal;
813 columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentIconRef;
814 if (dataViewColumnPtr->GetBitmap().Ok())
815 columnDescription.headerBtnDesc.btnContentInfo.u.iconRef = dataViewColumnPtr->GetBitmap().GetBitmapData()->GetIconRef();
816 // add column:
817 wxCHECK_MSG(MacDataViewListCtrlPtr->AddColumn(&columnDescription,kDataBrowserListViewAppendColumn) == noErr,false,_("Column could not be added."));
818
819 // final adjustments for the layout:
820 wxCHECK_MSG(MacDataViewListCtrlPtr->SetColumnWidth(NewPropertyID,dataViewColumnPtr->GetWidth()) == noErr,false,_("Column width could not be set."));
821
822 // make sure that the data is up-to-date...
823 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
824 // otherwise ask the control to 'update' the data in the newly appended column:
825 if (this->GetColumnCount() == 1)
826 {
827 this->SetExpanderColumn(dataViewColumnPtr);
828 this->AddChildrenLevel(wxDataViewItem());
829 } /* if */
830 else
831 MacDataViewListCtrlPtr->UpdateItems(kDataBrowserNoItem,0,NULL,kDataBrowserItemNoProperty,NewPropertyID);
832 // done:
833 return true;
834 } /* if */
835 else
836 return false;
837 } /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
838
839 bool wxDataViewCtrl::ClearColumns(void)
840 {
841 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
842
843
844 while (this->m_ColumnPointers.begin() != this->m_ColumnPointers.end())
845 {
846 wxCHECK_MSG(MacDataViewListCtrlPtr->RemoveColumnByProperty(this->m_ColumnPointers.begin()->first) == noErr,false,_("Could not remove column."));
847 delete this->m_ColumnPointers.begin()->second;
848 this->m_ColumnPointers.erase(this->m_ColumnPointers.begin());
849 } /* while */
850 return true;
851 } /* wxDataViewCtrl::ClearColumns(void) */
852
853 bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn* columnPtr)
854 {
855 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
856
857
858 if ((MacDataViewListCtrlPtr->RemoveColumnByProperty(columnPtr->GetPropertyID()) == noErr) && (this->m_ColumnPointers.erase(columnPtr->GetPropertyID()) > 0))
859 {
860 delete columnPtr;
861 return true;
862 } /* if */
863 else
864 return false;
865 } /* wxDataViewCtrl::DeleteColumn(wxDataViewColumn*) */
866
867 wxDataViewColumn* wxDataViewCtrl::GetColumn(unsigned int pos) const
868 {
869 DataBrowserPropertyID propertyID;
870
871 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
872
873
874 if (MacDataViewListCtrlPtr->GetPropertyID(pos,&propertyID) == noErr)
875 {
876 // variable definition:
877 ColumnPointerHashMapType::const_iterator Result(this->m_ColumnPointers.find(propertyID));
878
879 if (Result != this->m_ColumnPointers.end())
880 return Result->second;
881 else
882 return NULL;
883 } /* if */
884 else
885 return NULL;
886 } /* wxDataViewCtrl::GetColumn(unsigned int pos) const */
887
888 unsigned int wxDataViewCtrl::GetColumnCount(void) const
889 {
890 return this->m_ColumnPointers.size();
891 } /* wxDataViewCtrl::GetColumnCount(void) const */
892
893 int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const
894 {
895 return -1;
896 }
897
898 wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const
899 {
900 return NULL;
901 }
902
903 void wxDataViewCtrl::Collapse(wxDataViewItem const& item)
904 {
905 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
906
907
908 MacDataViewListCtrlPtr->CloseContainer(reinterpret_cast<DataBrowserItemID>(item.GetID()));
909 } /* wxDataViewCtrl::Collapse(wxDataViewItem const&) */
910
911 void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr)
912 {
913 if (item.IsOk())
914 {
915 // variable definition and initialization:
916 DataBrowserPropertyID propertyID;
917 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
918
919 if (columnPtr != NULL)
920 propertyID = columnPtr->GetPropertyID();
921 else
922 propertyID = kDataBrowserNoItem;
923 MacDataViewListCtrlPtr->RevealItem(reinterpret_cast<DataBrowserItemID>(item.GetID()),propertyID,kDataBrowserRevealOnly);
924 } /* if */
925 } /* wxDataViewCtrl::EnsureVisible(wxDataViewItem const&, wxDataViewColumn const*) */
926
927 void wxDataViewCtrl::Expand(wxDataViewItem const& item)
928 {
929 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
930
931
932 MacDataViewListCtrlPtr->OpenContainer(reinterpret_cast<DataBrowserItemID>(item.GetID()));
933 } /* wxDataViewCtrl::Expand(wxDataViewItem const&) */
934
935 unsigned int wxDataViewCtrl::GetCount(void) const
936 {
937 ItemCount noOfItems;
938
939
940 wxCHECK_MSG(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer)->GetItemCount(&noOfItems) == noErr,0,_("Could not determine number of items"));
941 return noOfItems;
942 } /* wxDataViewCtrl::GetCount(void) const */
943
944 wxRect wxDataViewCtrl::GetItemRect(wxDataViewItem const& item, wxDataViewColumn const* columnPtr) const
945 {
946 if (item.IsOk() && (columnPtr != NULL))
947 {
948 // variable definition:
949 Rect MacRectangle;
950 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
951
952 if (MacDataViewListCtrlPtr->GetPartBounds(reinterpret_cast<DataBrowserItemID>(item.GetID()),columnPtr->GetPropertyID(),kDataBrowserPropertyContentPart,&MacRectangle) == noErr)
953 {
954 // variable definition:
955 wxRect rectangle;
956
957 ::wxMacNativeToRect(&MacRectangle,&rectangle);
958 return rectangle;
959 } /* if */
960 else
961 return wxRect();
962 } /* if */
963 else
964 return wxRect();
965 } /* wxDataViewCtrl::GetItemRect(wxDataViewItem const&, unsigned int) const */
966
967 wxDataViewItem wxDataViewCtrl::GetSelection(void) const
968 {
969 wxArrayDataBrowserItemID itemIDs;
970
971 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
972
973
974 if (MacDataViewListCtrlPtr->GetSelectedItemIDs(itemIDs) > 0)
975 return wxDataViewItem(reinterpret_cast<void*>(itemIDs[0]));
976 else
977 return wxDataViewItem();
978 } /* wxDataViewCtrl::GetSelection(void) const */
979
980 int wxDataViewCtrl::GetSelections(wxDataViewItemArray& sel) const
981 {
982 size_t NoOfSelectedItems;
983
984 wxArrayDataBrowserItemID itemIDs;
985
986 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
987
988
989 NoOfSelectedItems = MacDataViewListCtrlPtr->GetSelectedItemIDs(itemIDs);
990 sel.Empty();
991 sel.SetCount(NoOfSelectedItems);
992 for (size_t i=0; i<NoOfSelectedItems; ++i)
993 sel[i] = wxDataViewItem(reinterpret_cast<void*>(itemIDs[i]));
994 return static_cast<int>(NoOfSelectedItems);
995 } /* wxDataViewCtrl::GetSelections(wxDataViewItemArray&) const */
996
997 void wxDataViewCtrl::HitTest(wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const
998 {
999 item = wxDataViewItem();
1000 columnPtr = NULL;
1001 } /* wxDataViewCtrl::HitTest(wxPoint const&, wxDataViewItem&, wxDataViewColumn*&) const */
1002
1003 bool wxDataViewCtrl::IsSelected(wxDataViewItem const& item) const
1004 {
1005 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1006
1007
1008 return MacDataViewListCtrlPtr->IsItemSelected(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1009 } /* wxDataViewCtrl::IsSelected(wxDataViewItem const&) const */
1010
1011 void wxDataViewCtrl::SelectAll(void)
1012 {
1013 DataBrowserItemID* itemIDPtr;
1014
1015 Handle handle(::NewHandle(0));
1016
1017 size_t NoOfItems;
1018
1019 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1020
1021
1022 wxCHECK_RET(MacDataViewListCtrlPtr->GetItems(kDataBrowserNoItem,true,kDataBrowserItemAnyState,handle) == noErr,_("Could not get items."));
1023 NoOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
1024 HLock(handle);
1025 itemIDPtr = (DataBrowserItemID*) (*handle);
1026 MacDataViewListCtrlPtr->SetSelectedItems(NoOfItems,itemIDPtr,kDataBrowserItemsAssign);
1027 HUnlock(handle);
1028 DisposeHandle(handle);
1029 } /* wxDataViewCtrl::SelectAll(void) */
1030
1031 void wxDataViewCtrl::Select(wxDataViewItem const& item)
1032 {
1033 if (item.IsOk())
1034 {
1035 // variable definition and initialization:
1036 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1037 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1038
1039 MacDataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsAdd);
1040 } /* if */
1041 } /* wxDataViewCtrl::Select(wxDataViewItem const&) */
1042
1043 void wxDataViewCtrl::SetSelections(wxDataViewItemArray const& sel)
1044 {
1045 size_t const NoOfSelections = sel.GetCount();
1046
1047 DataBrowserItemID* itemIDs;
1048
1049 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1050
1051
1052 itemIDs = new DataBrowserItemID[NoOfSelections];
1053 for (size_t i=0; i<NoOfSelections; ++i)
1054 itemIDs[i] = reinterpret_cast<DataBrowserItemID>(sel[i].GetID());
1055 MacDataViewListCtrlPtr->SetSelectedItems(NoOfSelections,itemIDs,kDataBrowserItemsAssign);
1056 delete[] itemIDs;
1057 } /* wxDataViewCtrl::SetSelections(wxDataViewItemArray const&) */
1058
1059 void wxDataViewCtrl::Unselect(wxDataViewItem const& item)
1060 {
1061 if (item.IsOk())
1062 {
1063 // variable definition and initialization:
1064 DataBrowserItemID itemID(reinterpret_cast<DataBrowserItemID>(item.GetID()));
1065 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1066
1067 MacDataViewListCtrlPtr->SetSelectedItems(1,&itemID,kDataBrowserItemsRemove);
1068 } /* if */
1069 } /* wxDataViewCtrl::Unselect(wxDataViewItem const&) */
1070
1071 void wxDataViewCtrl::UnselectAll(void)
1072 {
1073 DataBrowserItemID* itemIDPtr;
1074
1075 Handle handle(::NewHandle(0));
1076
1077 size_t NoOfItems;
1078
1079 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1080
1081
1082 wxCHECK_RET(MacDataViewListCtrlPtr->GetItems(kDataBrowserNoItem,true,kDataBrowserItemAnyState,handle) == noErr,_("Could not get items."));
1083 NoOfItems = static_cast<size_t>(::GetHandleSize(handle)/sizeof(DataBrowserItemID));
1084 HLock(handle);
1085 itemIDPtr = (DataBrowserItemID*) (*handle);
1086 MacDataViewListCtrlPtr->SetSelectedItems(NoOfItems,itemIDPtr,kDataBrowserItemsRemove);
1087 HUnlock(handle);
1088 DisposeHandle(handle);
1089 } /* wxDataViewCtrl::UnselectAll(void) */
1090
1091 // data handling:
1092 void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const& parentItem)
1093 {
1094 int NoOfChildren;
1095
1096 wxDataViewItemArray items;
1097
1098
1099 wxCHECK_RET(this->GetModel() != NULL,_("Model pointer not initialized."));
1100 NoOfChildren = this->GetModel()->GetChildren(parentItem,items);
1101 for (int i=0; i<NoOfChildren; ++i)
1102 (void) this->GetModel()->ItemAdded(parentItem,items[i]);
1103 } /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
1104
1105 wxDataViewColumn* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID propertyID) const
1106 {
1107 // variable definition:
1108 ColumnPointerHashMapType::const_iterator Result(this->m_ColumnPointers.find(propertyID));
1109
1110 if (Result != this->m_ColumnPointers.end())
1111 return Result->second;
1112 else
1113 return NULL;
1114 } /* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID) const */
1115
1116 // inherited methods from wxDataViewCtrlBase
1117 void wxDataViewCtrl::DoSetExpanderColumn(void)
1118 {
1119 if (this->GetExpanderColumn() != NULL)
1120 {
1121 // variable definition and initialization:
1122 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1123
1124 (void) MacDataViewListCtrlPtr->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID());
1125 } /* if */
1126 } /* wxDataViewCtrl::DoSetExpanderColumn(void) */
1127
1128 void wxDataViewCtrl::DoSetIndent(void)
1129 {
1130 wxMacDataViewDataBrowserListViewControlPointer MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(this->m_peer));
1131
1132
1133 (void) MacDataViewListCtrlPtr->SetIndent(static_cast<float>(this->GetIndent()));
1134 } /* wxDataViewCtrl::DoSetIndent(void) */
1135
1136 // event handling:
1137 void wxDataViewCtrl::OnSize(wxSizeEvent& event)
1138 {
1139 unsigned int const NoOfColumns = this->GetColumnCount();
1140
1141
1142 for (unsigned int i=0; i<NoOfColumns; ++i)
1143 {
1144 // variable definition and initialization:
1145 wxDataViewColumn* dataViewColumnPtr(this->GetColumn(i));
1146
1147 if (dataViewColumnPtr != NULL)
1148 {
1149 // variable definition and initialization:
1150 wxDataViewCustomRenderer* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer*>(dataViewColumnPtr->GetRenderer()));
1151
1152 if (dataViewCustomRendererPtr != NULL)
1153 dataViewCustomRendererPtr->SetDC(NULL); // reset DC because DC has changed
1154 } /* if */
1155 } /* for */
1156 event.Skip();
1157 } /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
1158
1159 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl,wxDataViewCtrlBase)
1160
1161 BEGIN_EVENT_TABLE(wxDataViewCtrl,wxDataViewCtrlBase)
1162 EVT_SIZE(wxDataViewCtrl::OnSize)
1163 END_EVENT_TABLE()
1164
1165 #endif
1166 // !wxUSE_GENERICDATAVIEWCTRL
1167
1168 #endif
1169 // wxUSE_DATAVIEWCTRL
1170