1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/datavgen.cpp
3 // Purpose: wxDataViewCtrl native mac implementation
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_DATAVIEWCTRL
15 #include "wx/dataview.h"
17 #if !defined(wxUSE_GENERICDATAVIEWCTRL) || (wxUSE_GENERICDATAVIEWCTRL == 0)
21 #include "wx/mac/carbon/databrow.h"
28 #include "wx/renderer.h"
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 // a list of all catchable events:
35 static EventTypeSpec
const eventList
[] =
37 {kEventClassControl
, kEventControlDraw
},
38 {kEventClassControl
, kEventControlHit
}
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 static pascal OSStatus
wxMacDataViewCtrlEventHandler(EventHandlerCallRef handler
, EventRef EventReference
, void* Data
)
47 wxDataViewCtrl
* DataViewCtrlPtr((wxDataViewCtrl
*) Data
); // the 'Data' variable always contains a pointer to the data view control that installed the handler
49 wxMacCarbonEvent
CarbonEvent(EventReference
) ;
52 switch (GetEventKind(EventReference
))
54 case kEventControlDraw
:
58 DataViewCtrlPtr
->MacSetDrawingContext(CarbonEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
,typeCGContextRef
));
59 status
= ::CallNextEventHandler(handler
,EventReference
);
60 DataViewCtrlPtr
->MacSetDrawingContext(NULL
);
63 case kEventControlHit
:
64 if (CarbonEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
,typeControlPartCode
) == kControlButtonPart
) // we only care about the header
66 ControlRef controlReference
;
67 DataBrowserPropertyID columnPropertyID
;
68 unsigned long columnIndex
;
70 wxDataViewEvent
DataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
,DataViewCtrlPtr
->GetId());
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
);
89 return eventNotHandledErr
;
92 return eventNotHandledErr
;
93 } /* wxMacDataViewCtrlEventHandler(EventHandlerCallRef, EventRef, void*) */
95 //-----------------------------------------------------------------------------
96 // local function pointers
97 //-----------------------------------------------------------------------------
99 DEFINE_ONE_SHOT_HANDLER_GETTER(wxMacDataViewCtrlEventHandler
)
101 // ---------------------------------------------------------
102 // wxMacDataViewModelNotifier
103 // ---------------------------------------------------------
105 class wxMacDataViewModelNotifier
: public wxDataViewModelNotifier
108 wxMacDataViewModelNotifier(wxMacDataViewDataBrowserListViewControl
* initDataViewControlPtr
) : m_dataViewControlPtr(initDataViewControlPtr
)
112 virtual bool ItemAdded(const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
114 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
117 wxCHECK_MSG(item
.IsOk(),false,_("Added item is invalid."));
118 if (!(parent
.IsOk()) && (this->m_dataViewControlPtr
->AddItem(kDataBrowserNoItem
, &itemID
) == noErr
) ||
119 parent
.IsOk() && (this->m_dataViewControlPtr
->AddItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
) == noErr
))
121 // variable definitions and initializations:
122 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
123 wxDataViewEvent
dataViewEvent (wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED
,dataViewCtrlPtr
->GetId());
125 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
126 dataViewEvent
.SetItem(item
);
127 // sent the equivalent wxWidget event:
128 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
134 } /* ItemAdded(wxDataViewItem const&, wxDataViewItem const&) */
136 virtual bool ItemChanged(wxDataViewItem
const& item
)
138 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
141 wxCHECK_MSG(item
.IsOk(), false,_("Changed item is invalid."));
142 wxCHECK_MSG(this->GetOwner() != NULL
,false,_("Owner not initialized."));
143 if (this->m_dataViewControlPtr
->UpdateItems(&itemID
) == noErr
)
145 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
147 // sent the equivalent wxWidget event:
148 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED
,dataViewCtrlPtr
->GetId()); // variable defintion
150 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
151 dataViewEvent
.SetItem(item
);
152 // sent the equivalent wxWidget event:
153 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
159 } /* ItemChanged(wxDataViewItem const&) */
161 virtual bool ItemDeleted(wxDataViewItem
const& parent
, wxDataViewItem
const& item
)
163 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
166 wxCHECK_MSG(item
.IsOk(),false,_("Deleted item is invalid."));
167 if (this->m_dataViewControlPtr
->RemoveItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
) == noErr
)
169 // variable definitions and initializations:
170 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
171 wxDataViewEvent
dataViewEvent (wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED
,dataViewCtrlPtr
->GetId());
173 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
174 dataViewEvent
.SetItem(item
);
175 // sent the equivalent wxWidget event:
176 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
182 } /* ItemDeleted(wxDataViewItem const&) */
184 virtual bool ValueChanged(wxDataViewItem
const& item
, unsigned int col
)
186 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
187 DataBrowserItemID parentID
;
189 DataBrowserPropertyID propertyID
;
191 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
194 wxCHECK_MSG(item
.IsOk(), false,_("Passed item is invalid."));
195 wxCHECK_MSG(this->GetOwner() != NULL
,false,_("Owner not initialized."));
196 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Control is wrongly initialized."));
197 parentID
= reinterpret_cast<DataBrowserItemID
>(this->GetOwner()->GetParent(item
).GetID());
198 if ((this->m_dataViewControlPtr
->GetPropertyID(col
,&propertyID
) == noErr
) &&
199 (this->m_dataViewControlPtr
->UpdateItems(parentID
,1,&itemID
,dataViewCtrlPtr
->GetColumn(col
)->GetPropertyID(),propertyID
) == noErr
))
201 // variable definition and initialization:
202 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED
,dataViewCtrlPtr
->GetId());
204 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
205 dataViewEvent
.SetColumn(col
);
206 dataViewEvent
.SetItem(item
);
207 // send the equivalent wxWidget event:
208 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
214 } /* ValueChanged(wxDataViewItem const&, unsigned int) */
216 virtual bool Cleared(void)
218 if (this->m_dataViewControlPtr
->RemoveItems() == noErr
)
220 // variable definitions and initializations:
221 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
222 wxDataViewEvent
dataViewEvent (wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED
,dataViewCtrlPtr
->GetId());
224 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
225 // send the equivalent wxWidget event:
226 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
232 } /* Cleared(void) */
239 wxMacDataViewDataBrowserListViewControl
* m_dataViewControlPtr
;
242 // ---------------------------------------------------------
243 // wxDataViewRenderer
244 // ---------------------------------------------------------
246 wxDataViewRenderer::wxDataViewRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
247 :wxDataViewRendererBase(varianttype
,mode
,align
), m_alignment(align
), m_mode(mode
)
249 } /* wxDataViewRenderer::wxDataViewRenderer(wxString const&, wxDataViewCellMode) */
251 void wxDataViewRenderer::SetMode(wxDataViewCellMode mode
)
253 wxDataViewColumn
* dataViewColumnPtr
;
257 dataViewColumnPtr
= this->GetOwner();
258 if (dataViewColumnPtr
!= NULL
)
260 // variable definition and initialization:
261 wxDataViewCtrl
* dataViewCtrlPtr(dataViewColumnPtr
->GetOwner());
263 if (dataViewCtrlPtr
!= NULL
)
265 // variable definition and initialization:
266 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
268 if (macDataViewListCtrlPtr
!= NULL
)
270 // variable definition and initialization:
271 DataBrowserPropertyFlags flags
;
273 verify_noerr(macDataViewListCtrlPtr
->GetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),&flags
));
274 if (mode
== wxDATAVIEW_CELL_EDITABLE
)
275 flags
|= kDataBrowserPropertyIsEditable
;
277 flags
&= ~kDataBrowserPropertyIsEditable
;
278 verify_noerr(macDataViewListCtrlPtr
->SetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),flags
));
282 } /* wxDataViewRenderer::SetMode(wxDataViewCellMode) */
284 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
,wxDataViewRendererBase
)
286 // ---------------------------------------------------------
287 // wxDataViewCustomRenderer
288 // ---------------------------------------------------------
290 wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
291 :wxDataViewRenderer(varianttype
,mode
,align
), m_editorCtrlPtr(NULL
)
293 } /* wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const&, wxDataViewCellMode) */
295 wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void)
297 if (this->m_DCPtr
!= NULL
)
298 delete this->m_DCPtr
;
299 } /* wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) */
301 wxDC
* wxDataViewCustomRenderer::GetDC(void)
303 if (this->m_DCPtr
== NULL
)
305 if ((GetOwner() == NULL
) || (GetOwner()->GetOwner() == NULL
))
307 this->m_DCPtr
= new wxClientDC(this->GetOwner()->GetOwner());
309 return this->m_DCPtr
;
310 } /* wxDataViewCustomRenderer::GetDC(void) */
312 bool wxDataViewCustomRenderer::Render(void)
315 } /* wxDataViewCustomRenderer::Render(void) */
317 void wxDataViewCustomRenderer::SetDC(wxDC
* newDCPtr
)
319 delete this->m_DCPtr
;
320 this->m_DCPtr
= newDCPtr
;
321 } /* wxDataViewCustomRenderer::SetDC(wxDC*) */
324 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
326 // ---------------------------------------------------------
327 // wxDataViewTextRenderer
328 // ---------------------------------------------------------
330 wxDataViewTextRenderer::wxDataViewTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
331 :wxDataViewRenderer(varianttype
,mode
,align
)
333 } /* wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const&, wxDataViewCellMode, int) */
335 bool wxDataViewTextRenderer::Render(void)
337 if (this->GetValue().GetType() == this->GetVariantType())
339 // variable definition:
340 wxMacCFStringHolder
cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
342 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
);
346 } /* wxDataViewTextRenderer::Render(void) */
348 IMPLEMENT_CLASS(wxDataViewTextRenderer
,wxDataViewRenderer
)
350 // ---------------------------------------------------------
351 // wxDataViewBitmapRenderer
352 // ---------------------------------------------------------
354 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
355 :wxDataViewRenderer(varianttype
,mode
,align
)
359 bool wxDataViewBitmapRenderer::Render(void)
361 if (this->GetValue().GetType() == this->GetVariantType())
365 bitmap
<< this->GetValue();
367 return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap
.GetBitmapData()->GetIconRef()) == noErr
);
373 } /* wxDataViewBitmapRenderer::Render(void) */
375 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
,wxDataViewRenderer
)
377 // ---------------------------------------------------------
378 // wxDataViewToggleRenderer
379 // ---------------------------------------------------------
381 wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
382 :wxDataViewRenderer(varianttype
,mode
)
386 bool wxDataViewToggleRenderer::Render(void)
388 if (this->GetValue().GetType() == this->GetVariantType())
389 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr
);
392 } /* wxDataViewToggleRenderer::Render(void) */
394 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
,wxDataViewRenderer
)
396 // ---------------------------------------------------------
397 // wxDataViewProgressRenderer
398 // ---------------------------------------------------------
400 wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString
const& label
, wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
401 :wxDataViewRenderer(varianttype
,mode
,align
)
405 bool wxDataViewProgressRenderer::Render(void)
407 if (this->GetValue().GetType() == this->GetVariantType())
408 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr
) &&
409 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr
) &&
410 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr
));
413 } /* wxDataViewProgressRenderer::Render(void) */
415 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
,wxDataViewRenderer
)
417 // ---------------------------------------------------------
418 // wxDataViewDateRenderer
419 // ---------------------------------------------------------
421 wxDataViewDateRenderer::wxDataViewDateRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
422 :wxDataViewRenderer(varianttype
,mode
,align
)
426 bool wxDataViewDateRenderer::Render(void)
428 if (this->GetValue().GetType() == this->GetVariantType())
429 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan
,1904)).GetSeconds().GetLo()) == noErr
);
432 } /* wxDataViewDateRenderer::Render(void) */
434 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
,wxDataViewRenderer
)
436 // ---------------------------------------------------------
438 // ---------------------------------------------------------
440 wxDataViewColumn::wxDataViewColumn(wxString
const &title
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
441 :wxDataViewColumnBase(title
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
442 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
| wxDATAVIEW_COL_RESIZABLE
)), m_maxWidth(std::numeric_limits
<int>::max()), m_minWidth(0), m_width(width
),
443 m_alignment(align
), m_title(title
)
445 } /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
447 wxDataViewColumn::wxDataViewColumn(wxBitmap
const& bitmap
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
448 :wxDataViewColumnBase(bitmap
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
449 m_flags(flags
& (wxDATAVIEW_COL_HIDDEN
| wxDATAVIEW_COL_RESIZABLE
)), m_maxWidth(std::numeric_limits
<int>::max()), m_minWidth(0), m_width(width
),
452 } /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
454 void wxDataViewColumn::SetAlignment(wxAlignment align
)
456 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
459 this->m_alignment
= align
;
460 if (dataViewCtrlPtr
!= NULL
)
462 // variable definition and initialization:
463 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
465 if (macDataViewListCtrlPtr
!= NULL
)
467 // variable definition and initialization:
468 DataBrowserListViewHeaderDesc headerDescription
;
470 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
474 case wxALIGN_CENTER_HORIZONTAL
:
475 headerDescription
.btnFontStyle
.just
= teCenter
;
478 headerDescription
.btnFontStyle
.just
= teFlushLeft
;
481 headerDescription
.btnFontStyle
.just
= teFlushRight
;
484 headerDescription
.btnFontStyle
.just
= teFlushDefault
;
486 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set alignment."));
489 } /* wxDataViewColumn::SetAlignment(wxAlignment) */
491 void wxDataViewColumn::SetBitmap(wxBitmap
const& bitmap
)
493 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
496 wxDataViewColumnBase::SetBitmap(bitmap
);
497 if (dataViewCtrlPtr
!= NULL
)
499 // variable definition and initialization:
500 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
502 if (macDataViewListCtrlPtr
!= NULL
)
504 // variable definition and initialization:
505 DataBrowserListViewHeaderDesc headerDescription
;
507 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
508 if (this->GetBitmap().Ok())
509 headerDescription
.btnContentInfo
.u
.iconRef
= this->GetBitmap().GetBitmapData()->GetIconRef();
511 headerDescription
.btnContentInfo
.u
.iconRef
= NULL
;
512 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set icon."));
515 } /* wxDataViewColumn::SetBitmap(wxBitmap const&) */
517 void wxDataViewColumn::SetFlags(int flags
)
519 this->SetHidden ((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
520 this->SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
521 this->SetSortable ((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
522 } /* wxDataViewColumn::SetFlags(int) */
524 void wxDataViewColumn::SetMaxWidth(int maxWidth
)
526 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
529 this->m_maxWidth
= maxWidth
;
530 if (dataViewCtrlPtr
!= NULL
)
532 // variable definition and initialization:
533 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
535 if (macDataViewListCtrlPtr
!= NULL
)
537 // variable definition and initialization:
538 DataBrowserListViewHeaderDesc headerDescription
;
540 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
541 headerDescription
.maximumWidth
= static_cast<UInt16
>(maxWidth
);
542 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set maximum width."));
545 } /* wxDataViewColumn::SetMaxWidth(int) */
547 void wxDataViewColumn::SetMinWidth(int minWidth
)
549 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
552 this->m_minWidth
= minWidth
;
553 if (dataViewCtrlPtr
!= NULL
)
555 // variable definition and initialization:
556 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
558 if (macDataViewListCtrlPtr
!= NULL
)
560 // variable definition and initialization:
561 DataBrowserListViewHeaderDesc headerDescription
;
563 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
564 headerDescription
.minimumWidth
= static_cast<UInt16
>(minWidth
);
565 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set minimum width."));
568 } /* wxDataViewColumn::SetMaxWidth(int) */
570 void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable
))
572 } /* wxDataViewColumn::SetResizeable(bool) */
574 void wxDataViewColumn::SetSortable(bool sortable
)
576 // variable definition and initialization:
577 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
579 if (dataViewCtrlPtr
!= NULL
)
581 // variable definition and initialization:
582 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
584 if (macDataViewListCtrlPtr
!= NULL
)
586 // variable definition and initialization:
587 DataBrowserPropertyFlags flags
;
589 wxCHECK_RET(macDataViewListCtrlPtr
->GetPropertyFlags(this->GetPropertyID(),&flags
) == noErr
,_("Could not get property flags."));
592 this->m_flags
|= wxDATAVIEW_COL_SORTABLE
;
593 flags
|= kDataBrowserListViewSortableColumn
;
597 this->m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
598 flags
&= ~kDataBrowserPropertyIsEditable
;
600 wxCHECK_RET(macDataViewListCtrlPtr
->SetPropertyFlags(this->GetPropertyID(),flags
) == noErr
,_("Could not set property flags."));
603 } /* wxDataViewColumn::SetSortable(bool) */
605 void wxDataViewColumn::SetSortOrder(bool ascending
)
607 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
610 this->m_ascending
= ascending
;
611 if (dataViewCtrlPtr
!= NULL
)
613 // variable definition and initialization:
614 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
616 if (macDataViewListCtrlPtr
!= NULL
)
618 // variable definition and initialization:
619 DataBrowserListViewHeaderDesc headerDescription
;
621 verify_noerr(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
));
623 headerDescription
.initialOrder
= kDataBrowserOrderIncreasing
;
625 headerDescription
.initialOrder
= kDataBrowserOrderDecreasing
;
626 verify_noerr(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
));
629 } /* wxDataViewColumn::SetSortOrder(bool) */
631 void wxDataViewColumn::SetTitle(wxString
const& title
)
633 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
636 this->m_title
= title
;
637 if (dataViewCtrlPtr
!= NULL
)
639 // variable definition and initialization:
640 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
642 if (macDataViewListCtrlPtr
!= NULL
)
644 // variable definition and initialization:
645 DataBrowserListViewHeaderDesc headerDescription
;
646 wxMacCFStringHolder
cfTitle(title
,(dataViewCtrlPtr
->GetFont().Ok() ? dataViewCtrlPtr
->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
648 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
649 headerDescription
.titleString
= cfTitle
;
650 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set header description."));
653 } /* wxDataViewColumn::SetTitle(wxString const&) */
655 void wxDataViewColumn::SetWidth(int width
)
657 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
660 if ((width
>= this->m_minWidth
) && (width
<= this->m_maxWidth
))
662 this->m_width
= width
;
663 if (dataViewCtrlPtr
!= NULL
)
665 // variable definition and initialization:
666 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
668 if (macDataViewListCtrlPtr
!= NULL
)
669 wxCHECK_RET(macDataViewListCtrlPtr
->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16
>(width
)) == noErr
,_("Could not set column width."));
672 } /* wxDataViewColumn::SetWidth(int) */
674 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
,wxDataViewColumnBase
)
676 //-----------------------------------------------------------------------------
678 //-----------------------------------------------------------------------------
680 void wxDataViewCtrl::Init(void)
682 this->m_macIsUserPane
= false;
683 this->m_NotifierPtr
= NULL
;
684 this->m_cgContext
= NULL
;
685 } /* wxDataViewCtrl::Init(void) */
687 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
689 if (!(this->wxControl::Create(parent
,id
,pos
,size
,(style
| wxSUNKEN_BORDER
) & ~(wxHSCROLL
| wxVSCROLL
),validator
)))
693 MacSetClipChildren(true) ;
696 this->m_peer
= new wxMacDataViewDataBrowserListViewControl(this,pos
,size
,style
);
697 this->MacPostControlCreate(pos
,size
);
699 InstallControlEventHandler(this->m_peer
->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList
),eventList
,this,NULL
);
702 } /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
704 bool wxDataViewCtrl::AppendColumn(wxDataViewColumn
* dataViewColumnPtr
)
706 // first, some error checking:
707 wxCHECK_MSG(dataViewColumnPtr
!= NULL
, false,_("Column pointer must not be NULL."));
708 wxCHECK_MSG(dataViewColumnPtr
->GetRenderer() != NULL
, false,_("Column does not have a renderer."));
709 wxCHECK_MSG(this->GetModel() != NULL
, false,_("No model associated with control."));
710 wxCHECK_MSG((dataViewColumnPtr
->GetModelColumn() >= 0) &&
711 (dataViewColumnPtr
->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
712 if (this->wxDataViewCtrlBase::AppendColumn(dataViewColumnPtr
))
714 // variable definition:
715 DataBrowserPropertyID NewPropertyID
;
716 DataBrowserListViewColumnDesc columnDescription
;
717 wxMacCFStringHolder
cfTitle(dataViewColumnPtr
->GetTitle(),(this->m_font
.Ok() ? this->m_font
.GetEncoding() : wxLocale::GetSystemEncoding()));
718 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
720 // initialize column description:
721 wxCHECK_MSG(MacDataViewListCtrlPtr
!= NULL
, false,_("m_peer is not or incorrectly initialized"));
722 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetFreePropertyID(&NewPropertyID
) == noErr
,false,_("Maximum number of columns reached."));
723 dataViewColumnPtr
->SetPropertyID(NewPropertyID
);
724 columnDescription
.propertyDesc
.propertyID
= NewPropertyID
;
725 columnDescription
.propertyDesc
.propertyType
= dataViewColumnPtr
->GetRenderer()->GetPropertyType();
726 columnDescription
.propertyDesc
.propertyFlags
= kDataBrowserListViewSelectionColumn
;
727 if (dataViewColumnPtr
->IsSortable())
728 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewSortableColumn
;
729 if (dataViewColumnPtr
->IsResizeable())
730 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewMovableColumn
;
731 if (dataViewColumnPtr
->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE
)
732 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserPropertyIsEditable
;
733 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
734 if ((columnDescription
.propertyDesc
.propertyType
== kDataBrowserTextType
) ||
735 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserIconAndTextType
) ||
736 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserDateTimeType
))
737 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
739 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
740 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
742 columnDescription
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
743 columnDescription
.headerBtnDesc
.minimumWidth
= 0;
744 columnDescription
.headerBtnDesc
.maximumWidth
= 30000;
745 columnDescription
.headerBtnDesc
.titleOffset
= 0;
746 columnDescription
.headerBtnDesc
.titleString
= cfTitle
; // we cannot directly use the wxMacCFStringHolder constructor call because then the CFStringRef is released
747 // having called 'AddColumn' where the title (CFStringRef) is going to be used
748 columnDescription
.headerBtnDesc
.initialOrder
= kDataBrowserOrderIncreasing
;
749 columnDescription
.headerBtnDesc
.btnFontStyle
.flags
= kControlUseFontMask
| kControlUseJustMask
;
750 switch (dataViewColumnPtr
->GetAlignment())
753 case wxALIGN_CENTER_HORIZONTAL
:
754 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teCenter
;
757 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushLeft
;
760 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushRight
;
763 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
765 columnDescription
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
766 columnDescription
.headerBtnDesc
.btnFontStyle
.style
= normal
;
767 columnDescription
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
768 if (dataViewColumnPtr
->GetBitmap().Ok())
769 columnDescription
.headerBtnDesc
.btnContentInfo
.u
.iconRef
= dataViewColumnPtr
->GetBitmap().GetBitmapData()->GetIconRef();
771 wxCHECK_MSG(MacDataViewListCtrlPtr
->AddColumn(&columnDescription
,kDataBrowserListViewAppendColumn
) == noErr
,false,_("Column could not be added."));
773 // final adjustments for the layout:
774 if (dataViewColumnPtr
->GetWidth() <= 0)
775 dataViewColumnPtr
->SetWidth(wxDVC_DEFAULT_WIDTH
);
776 wxCHECK_MSG(MacDataViewListCtrlPtr
->SetColumnWidth(NewPropertyID
,dataViewColumnPtr
->GetWidth()) == noErr
,false,_("Column width could not be set."));
777 if (dataViewColumnPtr
->IsSortable()) // if the current column is marked sortable this column will become the active sortable column, otherwise don't do anything
778 MacDataViewListCtrlPtr
->SetSortProperty(NewPropertyID
);
779 if (this->GetColumnCount()-1 == this->GetExpanderColumn()) // if the current column is marked expandable this column will become the active expandable column
780 MacDataViewListCtrlPtr
->SetDisclosureColumn(NewPropertyID
,true);
782 // make sure that the data is up-to-date...
783 // 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:
784 if (this->GetColumnCount() == 1)
785 this->AddChildrenLevel(wxDataViewItem());
787 MacDataViewListCtrlPtr
->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,NewPropertyID
);
793 } /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
795 wxDataViewItem
wxDataViewCtrl::GetSelection(void)
797 wxArrayDataBrowserItemID itemIDs
;
799 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
802 if (MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
) > 0)
803 return wxDataViewItem(reinterpret_cast<void*>(itemIDs
[0]));
805 return wxDataViewItem();
806 } /* wxDataViewCtrl::GetSelection(void) */
808 bool wxDataViewCtrl::AssociateModel(wxDataViewModel
* model
)
810 if (!wxDataViewCtrlBase::AssociateModel(model
))
813 this->m_NotifierPtr
= new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl
*>(this->m_peer
));
814 model
->AddNotifier(this->m_NotifierPtr
);
817 } /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
820 void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem
const& parentItem
)
825 wxCHECK_RET(this->GetModel() != NULL
,_("Model pointer not initialized."));
826 item
= this->GetModel()->GetFirstChild(parentItem
);
829 (void) this->GetModel()->ItemAdded(parentItem
,item
);
830 item
= this->GetModel()->GetNextSibling(item
);
832 } /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
834 // inherited methods from wxDataViewCtrlBase
835 void wxDataViewCtrl::DoSetExpanderColumn(void)
837 if (this->GetExpanderColumn() < this->GetColumnCount())
839 // variable definition and initialization:
840 DataBrowserPropertyID propertyID
;
841 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
843 if (MacDataViewListCtrlPtr
->GetPropertyID(this->GetExpanderColumn(),&propertyID
) == noErr
)
844 (void) MacDataViewListCtrlPtr
->SetDisclosureColumn(propertyID
);
846 } /* wxDataViewCtrl::DoSetExpanderColumn(void) */
848 void wxDataViewCtrl::DoSetIndent(void)
850 } /* wxDataViewCtrl::DoSetExpanderColumn(void) */
853 void wxDataViewCtrl::OnSize(wxSizeEvent
& event
)
855 unsigned int const NoOfColumns
= this->GetColumnCount();
858 for (unsigned int i
=0; i
<NoOfColumns
; ++i
)
860 // variable definition and initialization:
861 wxDataViewColumn
* dataViewColumnPtr(this->GetColumn(i
));
863 if (dataViewColumnPtr
!= NULL
)
865 // variable definition and initialization:
866 wxDataViewCustomRenderer
* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer()));
868 if (dataViewCustomRendererPtr
!= NULL
)
869 dataViewCustomRendererPtr
->SetDC(NULL
); // reset DC because DC has changed
873 } /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
875 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
,wxDataViewCtrlBase
)
877 BEGIN_EVENT_TABLE(wxDataViewCtrl
,wxDataViewCtrlBase
)
878 EVT_SIZE(wxDataViewCtrl::OnSize
)
882 // !wxUSE_GENERICDATAVIEWCTRL
885 // wxUSE_DATAVIEWCTRL