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"
25 #include "wx/settings.h"
26 #include "wx/dcclient.h"
30 #include "wx/renderer.h"
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 // a list of all catchable events:
37 static EventTypeSpec
const eventList
[] =
39 {kEventClassControl
, kEventControlDraw
},
40 {kEventClassControl
, kEventControlHit
}
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
47 static pascal OSStatus
wxMacDataViewCtrlEventHandler(EventHandlerCallRef handler
, EventRef EventReference
, void* Data
)
49 wxDataViewCtrl
* DataViewCtrlPtr((wxDataViewCtrl
*) Data
); // the 'Data' variable always contains a pointer to the data view control that installed the handler
51 wxMacCarbonEvent
CarbonEvent(EventReference
) ;
54 switch (GetEventKind(EventReference
))
56 case kEventControlDraw
:
60 DataViewCtrlPtr
->MacSetDrawingContext(CarbonEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
,typeCGContextRef
));
61 status
= ::CallNextEventHandler(handler
,EventReference
);
62 DataViewCtrlPtr
->MacSetDrawingContext(NULL
);
65 case kEventControlHit
:
66 if (CarbonEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
,typeControlPartCode
) == kControlButtonPart
) // we only care about the header
68 ControlRef controlReference
;
69 DataBrowserPropertyID columnPropertyID
;
70 unsigned long columnIndex
;
72 wxDataViewEvent
DataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
,DataViewCtrlPtr
->GetId());
74 CarbonEvent
.GetParameter(kEventParamDirectObject
,&controlReference
);
75 // determine the column that triggered the event (this is the column that is responsible for sorting the data view):
76 status
= ::GetDataBrowserSortProperty(controlReference
,&columnPropertyID
);
77 wxCHECK(status
== noErr
,status
);
78 status
= ::GetDataBrowserTableViewColumnPosition(controlReference
,columnPropertyID
,&columnIndex
);
79 if (status
== errDataBrowserPropertyNotFound
) // user clicked into part of the header that does not have a property
80 return ::CallNextEventHandler(handler
,EventReference
);
81 wxCHECK(status
== noErr
,status
);
82 // initialize wxWidget event handler:
83 DataViewEvent
.SetEventObject(DataViewCtrlPtr
);
84 DataViewEvent
.SetColumn(columnIndex
);
85 DataViewEvent
.SetDataViewColumn(DataViewCtrlPtr
->GetColumn(columnIndex
));
86 // finally sent the equivalent wxWidget event:
87 DataViewCtrlPtr
->GetEventHandler()->ProcessEvent(DataViewEvent
);
88 return ::CallNextEventHandler(handler
,EventReference
);
91 return eventNotHandledErr
;
94 return eventNotHandledErr
;
95 } /* wxMacDataViewCtrlEventHandler(EventHandlerCallRef, EventRef, void*) */
97 static DataBrowserItemID
* CreateDataBrowserItemIDArray(size_t& noOfEntries
, wxDataViewItemArray
const& items
) // returns a newly allocated pointer to valid data browser item IDs
99 size_t const noOfItems
= items
.GetCount();
101 DataBrowserItemID
* itemIDs(new DataBrowserItemID
[noOfItems
]);
104 // convert all valid data view items to data browser items
106 for (size_t i
=0; i
<noOfItems
; ++i
)
109 itemIDs
[noOfEntries
] = reinterpret_cast<DataBrowserItemID
>(items
[i
].GetID());
114 } /* CreateDataBrowserItemIDArray(size_t&, wxDataViewItemArray const&) */
116 //-----------------------------------------------------------------------------
117 // local function pointers
118 //-----------------------------------------------------------------------------
120 DEFINE_ONE_SHOT_HANDLER_GETTER(wxMacDataViewCtrlEventHandler
)
122 // ---------------------------------------------------------
123 // wxMacDataViewModelNotifier
124 // ---------------------------------------------------------
126 class wxMacDataViewModelNotifier
: public wxDataViewModelNotifier
129 wxMacDataViewModelNotifier(wxMacDataViewDataBrowserListViewControl
* initDataViewControlPtr
) : m_dataViewControlPtr(initDataViewControlPtr
)
133 virtual bool ItemAdded(const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
135 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
138 wxCHECK_MSG(item
.IsOk(),false,_("Added item is invalid."));
139 return (!(parent
.IsOk()) && (this->m_dataViewControlPtr
->AddItem(kDataBrowserNoItem
,&itemID
) == noErr
) ||
140 parent
.IsOk() && (this->m_dataViewControlPtr
->AddItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
) == noErr
));
141 } /* ItemAdded(wxDataViewItem const&, wxDataViewItem const&) */
143 virtual bool ItemsAdded(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
147 DataBrowserItemID
* itemIDs
;
152 // convert all valid data view items to data browser items:
153 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
154 // insert all valid items into control:
155 noFailureFlag
= ((noOfEntries
== 0) ||
156 !(parent
.IsOk()) && (this->m_dataViewControlPtr
->AddItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
) ||
157 parent
.IsOk() && (this->m_dataViewControlPtr
->AddItems(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
));
158 // give allocated array space free again:
161 return noFailureFlag
;
162 } /* ItemsAdded(wxDataViewItem const&, wxDataViewItemArray const&) */
164 virtual bool ItemChanged(wxDataViewItem
const& item
)
166 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
169 wxCHECK_MSG(item
.IsOk(),false,_("Changed item is invalid."));
170 if (this->m_dataViewControlPtr
->UpdateItems(&itemID
) == noErr
)
172 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
174 // sent the equivalent wxWidget event:
175 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId()); // variable defintion
177 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
178 dataViewEvent
.SetItem(item
);
179 // sent the equivalent wxWidget event:
180 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
186 } /* ItemChanged(wxDataViewItem const&) */
188 virtual bool ItemsChanged(wxDataViewItemArray
const& items
)
192 DataBrowserItemID
* itemIDs
;
197 // convert all valid data view items to data browser items:
198 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
199 // change items (ATTENTION: ONLY ITEMS OF THE ROOT ARE CHANGED BECAUSE THE PARENT PARAMETER IS MISSING):
200 noFailureFlag
= (this->m_dataViewControlPtr
->UpdateItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
,kDataBrowserItemNoProperty
) == noErr
);
203 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
205 // send for all changed items a wxWidget event:
206 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId()); // variable defintion
208 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
209 for (size_t i
=0; i
<noOfEntries
; ++i
)
211 dataViewEvent
.SetItem(reinterpret_cast<void*>(itemIDs
[i
]));
212 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
215 // release allocated array space:
218 return noFailureFlag
;
219 } /* ItemsChanged(wxDataViewItem const&) */
221 virtual bool ItemDeleted(wxDataViewItem
const& parent
, wxDataViewItem
const& item
)
225 // variable definition and initialization:
226 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
227 OSStatus errorStatus
;
228 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
230 // 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
231 // not to be identical because the being edited item might be below the passed item in the hierarchy);
232 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
233 // has been started and that variables can currently not be updated even when requested by the system:
234 dataViewCtrlPtr
->SetDeleting(true);
235 errorStatus
= this->m_dataViewControlPtr
->RemoveItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
);
236 // enable automatic updating again:
237 dataViewCtrlPtr
->SetDeleting(false);
238 return (errorStatus
== noErr
);
242 } /* ItemDeleted(wxDataViewItem const&, wxDataViewItem const&) */
244 virtual bool ItemsDeleted(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
248 DataBrowserItemID
* itemIDs
;
250 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
255 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,false,_("Data view control is not correctly initialized"));
256 // convert all valid data view items to data browser items:
257 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
258 // 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
259 // not to be identical because the being edited item might be below the passed item in the hierarchy);
260 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
261 // has been started and that variables can currently not be updated even when requested by the system:
262 dataViewCtrlPtr
->SetDeleting(true);
263 // insert all valid items into control:
264 noFailureFlag
= ((noOfEntries
== 0) ||
265 !(parent
.IsOk()) && (this->m_dataViewControlPtr
->RemoveItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
) ||
266 parent
.IsOk() && (this->m_dataViewControlPtr
->RemoveItems(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
));
267 // enable automatic updating again:
268 dataViewCtrlPtr
->SetDeleting(false);
269 // give allocated array space free again:
272 return noFailureFlag
;
273 } /* ItemsDeleted(wxDataViewItem const&, wxDataViewItemArray const&) */
275 virtual bool ValueChanged(wxDataViewItem
const& item
, unsigned int col
)
277 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
278 DataBrowserItemID parentID
;
280 DataBrowserPropertyID propertyID
;
282 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
285 wxCHECK_MSG(item
.IsOk(), false,_("Passed item is invalid."));
286 wxCHECK_MSG(this->GetOwner() != NULL
,false,_("Owner not initialized."));
287 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Control is wrongly initialized."));
288 parentID
= reinterpret_cast<DataBrowserItemID
>(this->GetOwner()->GetParent(item
).GetID());
289 if ((this->m_dataViewControlPtr
->GetPropertyID(col
,&propertyID
) == noErr
) &&
290 (this->m_dataViewControlPtr
->UpdateItems(parentID
,1,&itemID
,dataViewCtrlPtr
->GetColumn(col
)->GetPropertyID(),propertyID
) == noErr
))
292 // variable definition and initialization:
293 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId());
295 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
296 dataViewEvent
.SetColumn(col
);
297 dataViewEvent
.SetItem(item
);
298 // send the equivalent wxWidget event:
299 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
305 } /* ValueChanged(wxDataViewItem const&, unsigned int) */
307 virtual bool Cleared(void)
309 return (this->m_dataViewControlPtr
->RemoveItems() == noErr
);
310 } /* Cleared(void) */
312 virtual void Resort(void)
314 this->m_dataViewControlPtr
->Resort();
322 wxMacDataViewDataBrowserListViewControl
* m_dataViewControlPtr
;
325 // ---------------------------------------------------------
326 // wxDataViewRenderer
327 // ---------------------------------------------------------
329 wxDataViewRenderer::wxDataViewRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
330 :wxDataViewRendererBase(varianttype
,mode
,align
), m_alignment(align
), m_mode(mode
)
332 } /* wxDataViewRenderer::wxDataViewRenderer(wxString const&, wxDataViewCellMode) */
334 void wxDataViewRenderer::SetMode(wxDataViewCellMode mode
)
336 wxDataViewColumn
* dataViewColumnPtr
;
340 dataViewColumnPtr
= this->GetOwner();
341 if (dataViewColumnPtr
!= NULL
)
343 // variable definition and initialization:
344 wxDataViewCtrl
* dataViewCtrlPtr(dataViewColumnPtr
->GetOwner());
346 if (dataViewCtrlPtr
!= NULL
)
348 // variable definition and initialization:
349 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
351 if (macDataViewListCtrlPtr
!= NULL
)
353 // variable definition and initialization:
354 DataBrowserPropertyFlags flags
;
356 verify_noerr(macDataViewListCtrlPtr
->GetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),&flags
));
357 if (mode
== wxDATAVIEW_CELL_EDITABLE
)
358 flags
|= kDataBrowserPropertyIsEditable
;
360 flags
&= ~kDataBrowserPropertyIsEditable
;
361 verify_noerr(macDataViewListCtrlPtr
->SetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),flags
));
365 } /* wxDataViewRenderer::SetMode(wxDataViewCellMode) */
367 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
,wxDataViewRendererBase
)
369 // ---------------------------------------------------------
370 // wxDataViewCustomRenderer
371 // ---------------------------------------------------------
373 wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
374 :wxDataViewRenderer(varianttype
,mode
,align
), m_editorCtrlPtr(NULL
), m_DCPtr(NULL
)
376 } /* wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const&, wxDataViewCellMode) */
378 wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void)
380 if (this->m_DCPtr
!= NULL
)
381 delete this->m_DCPtr
;
382 } /* wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) */
384 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
)
386 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
387 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ?
388 wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) :
389 view
->GetForegroundColour();
390 dc
->SetTextForeground(col
);
391 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
394 wxDC
* wxDataViewCustomRenderer::GetDC(void)
396 if (this->m_DCPtr
== NULL
)
398 if ((GetOwner() == NULL
) || (GetOwner()->GetOwner() == NULL
))
400 this->m_DCPtr
= new wxClientDC(this->GetOwner()->GetOwner());
402 return this->m_DCPtr
;
403 } /* wxDataViewCustomRenderer::GetDC(void) */
405 bool wxDataViewCustomRenderer::Render(void)
408 } /* wxDataViewCustomRenderer::Render(void) */
410 void wxDataViewCustomRenderer::SetDC(wxDC
* newDCPtr
)
412 delete this->m_DCPtr
;
413 this->m_DCPtr
= newDCPtr
;
414 } /* wxDataViewCustomRenderer::SetDC(wxDC*) */
416 WXDataBrowserPropertyType
wxDataViewCustomRenderer::GetPropertyType() const
418 return kDataBrowserCustomType
;
421 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
423 // ---------------------------------------------------------
424 // wxDataViewTextRenderer
425 // ---------------------------------------------------------
427 wxDataViewTextRenderer::wxDataViewTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
428 :wxDataViewRenderer(varianttype
,mode
,align
)
430 } /* wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const&, wxDataViewCellMode, int) */
432 bool wxDataViewTextRenderer::Render(void)
434 if (this->GetValue().GetType() == this->GetVariantType())
436 // variable definition:
437 wxMacCFStringHolder
cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
439 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
);
443 } /* wxDataViewTextRenderer::Render(void) */
445 WXDataBrowserPropertyType
wxDataViewTextRenderer::GetPropertyType() const
447 return kDataBrowserTextType
;
450 IMPLEMENT_CLASS(wxDataViewTextRenderer
,wxDataViewRenderer
)
452 // ---------------------------------------------------------
453 // wxDataViewBitmapRenderer
454 // ---------------------------------------------------------
456 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
457 :wxDataViewRenderer(varianttype
,mode
,align
)
461 bool wxDataViewBitmapRenderer::Render(void)
463 if (this->GetValue().GetType() == this->GetVariantType())
467 bitmap
<< this->GetValue();
469 return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap
.GetBitmapData()->GetIconRef()) == noErr
);
475 } /* wxDataViewBitmapRenderer::Render(void) */
477 WXDataBrowserPropertyType
wxDataViewBitmapRenderer::GetPropertyType() const
479 return kDataBrowserIconType
;
482 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
,wxDataViewRenderer
)
484 // ---------------------------------------------------------
485 // wxDataViewIconTextRenderer
486 // ---------------------------------------------------------
488 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
489 :wxDataViewRenderer(varianttype
,mode
)
493 bool wxDataViewIconTextRenderer::Render(void)
495 if (this->GetValue().GetType() == this->GetVariantType())
497 // variable definition:
498 wxDataViewIconText iconText
;
500 iconText
<< this->GetValue();
502 // variable definition:
503 wxMacCFStringHolder
cfString(iconText
.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
505 return ((::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText
.GetIcon().GetHICON())) == noErr
) &&
506 (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
));
510 } /* wxDataViewIconTextRenderer::Render(void) */
512 WXDataBrowserPropertyType
wxDataViewIconTextRenderer::GetPropertyType() const
514 return kDataBrowserIconAndTextType
;
517 IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer
,wxDataViewRenderer
)
520 // ---------------------------------------------------------
521 // wxDataViewToggleRenderer
522 // ---------------------------------------------------------
524 wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
525 :wxDataViewRenderer(varianttype
,mode
)
529 bool wxDataViewToggleRenderer::Render(void)
531 if (this->GetValue().GetType() == this->GetVariantType())
532 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr
);
535 } /* wxDataViewToggleRenderer::Render(void) */
537 WXDataBrowserPropertyType
wxDataViewToggleRenderer::GetPropertyType() const
539 return kDataBrowserCheckboxType
;
542 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
,wxDataViewRenderer
)
544 // ---------------------------------------------------------
545 // wxDataViewProgressRenderer
546 // ---------------------------------------------------------
548 wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString
const& label
, wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
549 :wxDataViewRenderer(varianttype
,mode
,align
)
553 bool wxDataViewProgressRenderer::Render(void)
555 if (this->GetValue().GetType() == this->GetVariantType())
556 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr
) &&
557 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr
) &&
558 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr
));
561 } /* wxDataViewProgressRenderer::Render(void) */
563 WXDataBrowserPropertyType
wxDataViewProgressRenderer::GetPropertyType() const
565 return kDataBrowserProgressBarType
;
568 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
,wxDataViewRenderer
)
570 // ---------------------------------------------------------
571 // wxDataViewDateRenderer
572 // ---------------------------------------------------------
574 wxDataViewDateRenderer::wxDataViewDateRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
575 :wxDataViewRenderer(varianttype
,mode
,align
)
579 bool wxDataViewDateRenderer::Render(void)
581 if (this->GetValue().GetType() == this->GetVariantType())
582 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan
,1904)).GetSeconds().GetLo()) == noErr
);
585 } /* wxDataViewDateRenderer::Render(void) */
587 WXDataBrowserPropertyType
wxDataViewDateRenderer::GetPropertyType() const
589 return kDataBrowserDateTimeType
;
592 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
,wxDataViewRenderer
)
594 // ---------------------------------------------------------
596 // ---------------------------------------------------------
598 wxDataViewColumn::wxDataViewColumn(wxString
const &title
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
599 :wxDataViewColumnBase(title
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
600 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
)), m_maxWidth(30000), m_minWidth(0), m_width(width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
),
601 m_alignment(align
), m_title(title
)
603 } /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
605 wxDataViewColumn::wxDataViewColumn(wxBitmap
const& bitmap
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
606 :wxDataViewColumnBase(bitmap
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
607 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
)), m_maxWidth(30000), m_minWidth(0), m_width(width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
),
610 } /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
612 void wxDataViewColumn::SetAlignment(wxAlignment align
)
614 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
617 this->m_alignment
= align
;
618 if (dataViewCtrlPtr
!= NULL
)
620 // variable definition and initialization:
621 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
623 if (macDataViewListCtrlPtr
!= NULL
)
625 // variable definition and initialization:
626 DataBrowserListViewHeaderDesc headerDescription
;
628 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
632 case wxALIGN_CENTER_HORIZONTAL
:
633 headerDescription
.btnFontStyle
.just
= teCenter
;
636 headerDescription
.btnFontStyle
.just
= teFlushLeft
;
639 headerDescription
.btnFontStyle
.just
= teFlushRight
;
642 headerDescription
.btnFontStyle
.just
= teFlushDefault
;
644 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set alignment."));
647 } /* wxDataViewColumn::SetAlignment(wxAlignment) */
649 void wxDataViewColumn::SetBitmap(wxBitmap
const& bitmap
)
651 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
654 wxDataViewColumnBase::SetBitmap(bitmap
);
655 if (dataViewCtrlPtr
!= NULL
)
657 // variable definition and initialization:
658 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
660 if (macDataViewListCtrlPtr
!= NULL
)
662 // variable definition and initialization:
663 DataBrowserListViewHeaderDesc headerDescription
;
665 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
666 if (this->GetBitmap().Ok())
667 headerDescription
.btnContentInfo
.u
.iconRef
= this->GetBitmap().GetBitmapData()->GetIconRef();
669 headerDescription
.btnContentInfo
.u
.iconRef
= NULL
;
670 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set icon."));
673 } /* wxDataViewColumn::SetBitmap(wxBitmap const&) */
675 void wxDataViewColumn::SetFlags(int flags
)
677 this->SetHidden ((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
678 this->SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
679 this->SetSortable ((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
680 } /* wxDataViewColumn::SetFlags(int) */
682 void wxDataViewColumn::SetMaxWidth(int maxWidth
)
684 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
687 this->m_maxWidth
= maxWidth
;
688 if (dataViewCtrlPtr
!= NULL
)
690 // variable definition and initialization:
691 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
693 if (macDataViewListCtrlPtr
!= NULL
)
695 // variable definition and initialization:
696 DataBrowserListViewHeaderDesc headerDescription
;
698 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
699 headerDescription
.maximumWidth
= static_cast<UInt16
>(maxWidth
);
700 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set maximum width."));
703 } /* wxDataViewColumn::SetMaxWidth(int) */
705 void wxDataViewColumn::SetMinWidth(int minWidth
)
707 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
710 this->m_minWidth
= minWidth
;
711 if (dataViewCtrlPtr
!= NULL
)
713 // variable definition and initialization:
714 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
716 if (macDataViewListCtrlPtr
!= NULL
)
718 // variable definition and initialization:
719 DataBrowserListViewHeaderDesc headerDescription
;
721 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
722 headerDescription
.minimumWidth
= static_cast<UInt16
>(minWidth
);
723 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set minimum width."));
726 } /* wxDataViewColumn::SetMaxWidth(int) */
728 void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable
))
730 } /* wxDataViewColumn::SetResizeable(bool) */
732 void wxDataViewColumn::SetSortable(bool sortable
)
734 // variable definition and initialization:
735 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
737 if (dataViewCtrlPtr
!= NULL
)
739 // variable definition and initialization:
740 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
742 if (macDataViewListCtrlPtr
!= NULL
)
744 // variable definition and initialization:
745 DataBrowserPropertyFlags flags
;
747 wxCHECK_RET(macDataViewListCtrlPtr
->GetPropertyFlags(this->GetPropertyID(),&flags
) == noErr
,_("Could not get property flags."));
750 this->m_flags
|= wxDATAVIEW_COL_SORTABLE
;
751 flags
|= kDataBrowserListViewSortableColumn
;
755 this->m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
756 flags
&= ~kDataBrowserPropertyIsEditable
;
758 wxCHECK_RET(macDataViewListCtrlPtr
->SetPropertyFlags(this->GetPropertyID(),flags
) == noErr
,_("Could not set property flags."));
761 } /* wxDataViewColumn::SetSortable(bool) */
763 void wxDataViewColumn::SetSortOrder(bool ascending
)
765 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
768 this->m_ascending
= ascending
;
769 if (dataViewCtrlPtr
!= NULL
)
771 // variable definition and initialization:
772 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
774 if (macDataViewListCtrlPtr
!= NULL
)
776 // variable definition and initialization:
777 DataBrowserListViewHeaderDesc headerDescription
;
779 verify_noerr(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
));
781 headerDescription
.initialOrder
= kDataBrowserOrderIncreasing
;
783 headerDescription
.initialOrder
= kDataBrowserOrderDecreasing
;
784 verify_noerr(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
));
785 macDataViewListCtrlPtr
->SetSortProperty(this->GetPropertyID());
788 } /* wxDataViewColumn::SetSortOrder(bool) */
790 void wxDataViewColumn::SetTitle(wxString
const& title
)
792 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
795 this->m_title
= title
;
796 if (dataViewCtrlPtr
!= NULL
)
798 // variable definition and initialization:
799 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
801 if (macDataViewListCtrlPtr
!= NULL
)
803 // variable definition and initialization:
804 DataBrowserListViewHeaderDesc headerDescription
;
805 wxMacCFStringHolder
cfTitle(title
,(dataViewCtrlPtr
->GetFont().Ok() ? dataViewCtrlPtr
->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
807 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
808 headerDescription
.titleString
= cfTitle
;
809 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set header description."));
812 } /* wxDataViewColumn::SetTitle(wxString const&) */
814 void wxDataViewColumn::SetWidth(int width
)
816 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
819 if ((width
>= this->m_minWidth
) && (width
<= this->m_maxWidth
))
821 this->m_width
= width
;
822 if (dataViewCtrlPtr
!= NULL
)
824 // variable definition and initialization:
825 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
827 if (macDataViewListCtrlPtr
!= NULL
)
828 wxCHECK_RET(macDataViewListCtrlPtr
->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16
>(width
)) == noErr
,_("Could not set column width."));
831 } /* wxDataViewColumn::SetWidth(int) */
833 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
,wxDataViewColumnBase
)
835 //-----------------------------------------------------------------------------
837 //-----------------------------------------------------------------------------
839 void wxDataViewCtrl::Init(void)
841 this->m_Deleting
= false;
842 this->m_macIsUserPane
= false;
843 this->m_cgContext
= NULL
;
844 } /* wxDataViewCtrl::Init(void) */
846 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
848 if (!(this->wxControl::Create(parent
,id
,pos
,size
,(style
| wxSUNKEN_BORDER
) & ~(wxHSCROLL
| wxVSCROLL
),validator
)))
852 MacSetClipChildren(true) ;
855 this->m_peer
= new wxMacDataViewDataBrowserListViewControl(this,pos
,size
,style
);
856 this->MacPostControlCreate(pos
,size
);
857 ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(this->m_peer
->GetControlRef()),true);
859 InstallControlEventHandler(this->m_peer
->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList
),eventList
,this,NULL
);
862 } /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
864 bool wxDataViewCtrl::AssociateModel(wxDataViewModel
* model
)
866 if (!wxDataViewCtrlBase::AssociateModel(model
))
869 model
->AddNotifier(new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl
*>(this->m_peer
)));
872 } /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
874 bool wxDataViewCtrl::AppendColumn(wxDataViewColumn
* dataViewColumnPtr
)
876 DataBrowserPropertyID NewPropertyID
;
878 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
881 // first, some error checking:
882 wxCHECK_MSG(MacDataViewListCtrlPtr
!= NULL
, false,_("m_peer is not or incorrectly initialized"));
883 wxCHECK_MSG(dataViewColumnPtr
!= NULL
, false,_("Column pointer must not be NULL."));
884 wxCHECK_MSG(dataViewColumnPtr
->GetRenderer() != NULL
, false,_("Column does not have a renderer."));
885 wxCHECK_MSG(this->GetModel() != NULL
, false,_("No model associated with control."));
886 wxCHECK_MSG((dataViewColumnPtr
->GetModelColumn() >= 0) &&
887 (dataViewColumnPtr
->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
888 if ((MacDataViewListCtrlPtr
->GetFreePropertyID(&NewPropertyID
) == noErr
) && this->wxDataViewCtrlBase::AppendColumn(dataViewColumnPtr
))
890 // insert column into hash map:
891 this->m_ColumnPointers
.insert(ColumnPointerHashMapType::value_type(NewPropertyID
,dataViewColumnPtr
));
893 // variable definitions:
894 DataBrowserListViewColumnDesc columnDescription
;
895 wxMacCFStringHolder
cfTitle(dataViewColumnPtr
->GetTitle(),(this->m_font
.Ok() ? this->m_font
.GetEncoding() : wxLocale::GetSystemEncoding()));
897 // initialize column description:
898 dataViewColumnPtr
->SetPropertyID(NewPropertyID
);
899 columnDescription
.propertyDesc
.propertyID
= NewPropertyID
;
900 columnDescription
.propertyDesc
.propertyType
= DataBrowserPropertyType(dataViewColumnPtr
->GetRenderer()->GetPropertyType());
901 columnDescription
.propertyDesc
.propertyFlags
= kDataBrowserListViewSelectionColumn
; // make the column selectable
902 if (dataViewColumnPtr
->IsSortable())
903 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewSortableColumn
;
905 if (dataViewColumnPtr
->IsMovable())
906 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewMovableColumn
;
908 if (dataViewColumnPtr
->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE
)
909 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserPropertyIsEditable
;
910 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
911 if ((columnDescription
.propertyDesc
.propertyType
== kDataBrowserTextType
) ||
912 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserIconAndTextType
) ||
913 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserDateTimeType
))
914 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
916 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
917 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
919 columnDescription
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
920 if (dataViewColumnPtr
->IsResizeable())
922 columnDescription
.headerBtnDesc
.minimumWidth
= 0;
923 columnDescription
.headerBtnDesc
.maximumWidth
= 30000;
927 columnDescription
.headerBtnDesc
.minimumWidth
= dataViewColumnPtr
->GetWidth();
928 columnDescription
.headerBtnDesc
.maximumWidth
= dataViewColumnPtr
->GetWidth();
930 columnDescription
.headerBtnDesc
.titleOffset
= 0;
931 columnDescription
.headerBtnDesc
.titleString
= cfTitle
; // we cannot directly use the wxMacCFStringHolder constructor call because then the CFStringRef is released
932 // having called 'AddColumn' where the title (CFStringRef) is going to be used
933 columnDescription
.headerBtnDesc
.initialOrder
= kDataBrowserOrderIncreasing
;
934 columnDescription
.headerBtnDesc
.btnFontStyle
.flags
= kControlUseFontMask
| kControlUseJustMask
;
935 switch (dataViewColumnPtr
->GetAlignment())
938 case wxALIGN_CENTER_HORIZONTAL
:
939 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teCenter
;
942 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushLeft
;
945 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushRight
;
948 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
950 columnDescription
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
951 columnDescription
.headerBtnDesc
.btnFontStyle
.style
= normal
;
952 columnDescription
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
953 if (dataViewColumnPtr
->GetBitmap().Ok())
954 columnDescription
.headerBtnDesc
.btnContentInfo
.u
.iconRef
= dataViewColumnPtr
->GetBitmap().GetBitmapData()->GetIconRef();
956 wxCHECK_MSG(MacDataViewListCtrlPtr
->AddColumn(&columnDescription
,kDataBrowserListViewAppendColumn
) == noErr
,false,_("Column could not be added."));
958 // final adjustments for the layout:
959 wxCHECK_MSG(MacDataViewListCtrlPtr
->SetColumnWidth(NewPropertyID
,dataViewColumnPtr
->GetWidth()) == noErr
,false,_("Column width could not be set."));
961 // make sure that the data is up-to-date...
962 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
963 // otherwise ask the control to 'update' the data in the newly appended column:
964 if (this->GetColumnCount() == 1)
966 this->SetExpanderColumn(dataViewColumnPtr
);
967 this->AddChildrenLevel(wxDataViewItem());
970 MacDataViewListCtrlPtr
->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,NewPropertyID
);
976 } /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
978 bool wxDataViewCtrl::ClearColumns(void)
980 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
983 while (this->m_ColumnPointers
.begin() != this->m_ColumnPointers
.end())
985 wxCHECK_MSG(MacDataViewListCtrlPtr
->RemoveColumnByProperty(this->m_ColumnPointers
.begin()->first
) == noErr
,false,_("Could not remove column."));
986 delete this->m_ColumnPointers
.begin()->second
;
987 this->m_ColumnPointers
.erase(this->m_ColumnPointers
.begin());
990 } /* wxDataViewCtrl::ClearColumns(void) */
992 bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn
* columnPtr
)
994 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
997 if ((MacDataViewListCtrlPtr
->RemoveColumnByProperty(columnPtr
->GetPropertyID()) == noErr
) && (this->m_ColumnPointers
.erase(columnPtr
->GetPropertyID()) > 0))
1004 } /* wxDataViewCtrl::DeleteColumn(wxDataViewColumn*) */
1006 wxDataViewColumn
* wxDataViewCtrl::GetColumn(unsigned int pos
) const
1008 DataBrowserPropertyID propertyID
;
1010 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1013 if (MacDataViewListCtrlPtr
->GetPropertyID(pos
,&propertyID
) == noErr
)
1015 // variable definition:
1016 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
1018 if (Result
!= this->m_ColumnPointers
.end())
1019 return Result
->second
;
1025 } /* wxDataViewCtrl::GetColumn(unsigned int pos) const */
1027 unsigned int wxDataViewCtrl::GetColumnCount(void) const
1029 return this->m_ColumnPointers
.size();
1030 } /* wxDataViewCtrl::GetColumnCount(void) const */
1032 int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn
const* columnPtr
) const
1034 if (columnPtr
!= NULL
)
1036 // variable definition and initialization:
1037 DataBrowserTableViewColumnIndex Position
;
1038 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1040 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetColumnIndex(columnPtr
->GetPropertyID(),&Position
) == noErr
,-1,_("Could not determine column's position"));
1041 return static_cast<int>(Position
);
1045 } /* wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const*) const */
1047 void wxDataViewCtrl::Collapse(wxDataViewItem
const& item
)
1049 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1052 MacDataViewListCtrlPtr
->CloseContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1053 } /* wxDataViewCtrl::Collapse(wxDataViewItem const&) */
1055 void wxDataViewCtrl::EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
)
1059 // variable definition and initialization:
1060 DataBrowserPropertyID propertyID
;
1061 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1063 if (columnPtr
!= NULL
)
1064 propertyID
= columnPtr
->GetPropertyID();
1066 propertyID
= kDataBrowserNoItem
;
1067 MacDataViewListCtrlPtr
->RevealItem(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),propertyID
,kDataBrowserRevealOnly
);
1069 } /* wxDataViewCtrl::EnsureVisible(wxDataViewItem const&, wxDataViewColumn const*) */
1071 void wxDataViewCtrl::Expand(wxDataViewItem
const& item
)
1073 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1076 MacDataViewListCtrlPtr
->OpenContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1077 } /* wxDataViewCtrl::Expand(wxDataViewItem const&) */
1079 wxDataViewColumn
* wxDataViewCtrl::GetSortingColumn(void) const
1081 DataBrowserPropertyID propertyID
;
1083 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1086 if (MacDataViewListCtrlPtr
->GetSortProperty(&propertyID
) == noErr
)
1087 return this->GetColumnPtr(propertyID
);
1090 } /* wxDataViewCtrl::GetSortingColumn(void) const */
1092 unsigned int wxDataViewCtrl::GetCount(void) const
1094 ItemCount noOfItems
;
1097 wxCHECK_MSG(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
)->GetItemCount(&noOfItems
) == noErr
,0,_("Could not determine number of items"));
1099 } /* wxDataViewCtrl::GetCount(void) const */
1101 wxRect
wxDataViewCtrl::GetItemRect(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
) const
1103 if (item
.IsOk() && (columnPtr
!= NULL
))
1105 // variable definition:
1107 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1109 if (MacDataViewListCtrlPtr
->GetPartBounds(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),columnPtr
->GetPropertyID(),kDataBrowserPropertyContentPart
,&MacRectangle
) == noErr
)
1111 // variable definition:
1114 ::wxMacNativeToRect(&MacRectangle
,&rectangle
);
1122 } /* wxDataViewCtrl::GetItemRect(wxDataViewItem const&, unsigned int) const */
1124 wxDataViewItem
wxDataViewCtrl::GetSelection(void) const
1126 wxArrayDataBrowserItemID itemIDs
;
1128 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1131 if (MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
) > 0)
1132 return wxDataViewItem(reinterpret_cast<void*>(itemIDs
[0]));
1134 return wxDataViewItem();
1135 } /* wxDataViewCtrl::GetSelection(void) const */
1137 int wxDataViewCtrl::GetSelections(wxDataViewItemArray
& sel
) const
1139 size_t NoOfSelectedItems
;
1141 wxArrayDataBrowserItemID itemIDs
;
1143 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1146 NoOfSelectedItems
= MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
);
1148 sel
.SetCount(NoOfSelectedItems
);
1149 for (size_t i
=0; i
<NoOfSelectedItems
; ++i
)
1150 sel
[i
] = wxDataViewItem(reinterpret_cast<void*>(itemIDs
[i
]));
1151 return static_cast<int>(NoOfSelectedItems
);
1152 } /* wxDataViewCtrl::GetSelections(wxDataViewItemArray&) const */
1154 void wxDataViewCtrl::HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const
1156 item
= wxDataViewItem();
1158 } /* wxDataViewCtrl::HitTest(wxPoint const&, wxDataViewItem&, wxDataViewColumn*&) const */
1160 bool wxDataViewCtrl::IsSelected(wxDataViewItem
const& item
) const
1162 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1165 return MacDataViewListCtrlPtr
->IsItemSelected(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1166 } /* wxDataViewCtrl::IsSelected(wxDataViewItem const&) const */
1168 void wxDataViewCtrl::SelectAll(void)
1170 DataBrowserItemID
* itemIDPtr
;
1172 Handle
handle(::NewHandle(0));
1176 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1179 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1180 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1182 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1183 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsAssign
);
1185 DisposeHandle(handle
);
1186 } /* wxDataViewCtrl::SelectAll(void) */
1188 void wxDataViewCtrl::Select(wxDataViewItem
const& item
)
1192 // variable definition and initialization:
1193 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1194 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1196 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsAdd
);
1198 } /* wxDataViewCtrl::Select(wxDataViewItem const&) */
1200 void wxDataViewCtrl::SetSelections(wxDataViewItemArray
const& sel
)
1202 size_t const NoOfSelections
= sel
.GetCount();
1204 DataBrowserItemID
* itemIDs
;
1206 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1209 itemIDs
= new DataBrowserItemID
[NoOfSelections
];
1210 for (size_t i
=0; i
<NoOfSelections
; ++i
)
1211 itemIDs
[i
] = reinterpret_cast<DataBrowserItemID
>(sel
[i
].GetID());
1212 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfSelections
,itemIDs
,kDataBrowserItemsAssign
);
1214 } /* wxDataViewCtrl::SetSelections(wxDataViewItemArray const&) */
1216 void wxDataViewCtrl::Unselect(wxDataViewItem
const& item
)
1220 // variable definition and initialization:
1221 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1222 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1224 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsRemove
);
1226 } /* wxDataViewCtrl::Unselect(wxDataViewItem const&) */
1228 void wxDataViewCtrl::UnselectAll(void)
1230 DataBrowserItemID
* itemIDPtr
;
1232 Handle
handle(::NewHandle(0));
1236 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1239 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1240 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1242 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1243 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsRemove
);
1245 DisposeHandle(handle
);
1246 } /* wxDataViewCtrl::UnselectAll(void) */
1249 void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem
const& parentItem
)
1253 wxDataViewItemArray items
;
1256 wxCHECK_RET(this->GetModel() != NULL
,_("Model pointer not initialized."));
1257 NoOfChildren
= this->GetModel()->GetChildren(parentItem
,items
);
1259 for (int i
=0; i
<NoOfChildren
; ++i
)
1260 (void) this->GetModel()->ItemAdded(parentItem
,items
[i
]);
1262 (void) this->GetModel()->ItemsAdded(parentItem
,items
);
1264 } /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
1266 wxDataViewColumn
* wxDataViewCtrl::GetColumnPtr(WXDataBrowserPropertyID propertyID
) const
1268 // variable definition:
1269 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
1271 if (Result
!= this->m_ColumnPointers
.end())
1272 return Result
->second
;
1275 } /* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID) const */
1277 // inherited methods from wxDataViewCtrlBase
1278 void wxDataViewCtrl::DoSetExpanderColumn(void)
1280 if (this->GetExpanderColumn() != NULL
)
1282 // variable definition and initialization:
1283 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1285 (void) MacDataViewListCtrlPtr
->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID());
1287 } /* wxDataViewCtrl::DoSetExpanderColumn(void) */
1289 void wxDataViewCtrl::DoSetIndent(void)
1291 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1294 (void) MacDataViewListCtrlPtr
->SetIndent(static_cast<float>(this->GetIndent()));
1295 } /* wxDataViewCtrl::DoSetIndent(void) */
1298 void wxDataViewCtrl::OnSize(wxSizeEvent
& event
)
1300 unsigned int const NoOfColumns
= this->GetColumnCount();
1303 for (unsigned int i
=0; i
<NoOfColumns
; ++i
)
1305 // variable definition and initialization:
1306 wxDataViewColumn
* dataViewColumnPtr(this->GetColumn(i
));
1308 if (dataViewColumnPtr
!= NULL
)
1310 // variable definition and initialization:
1311 wxDataViewCustomRenderer
* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer()));
1313 if (dataViewCustomRendererPtr
!= NULL
)
1314 dataViewCustomRendererPtr
->SetDC(NULL
); // reset DC because DC has changed
1318 } /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
1320 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
,wxDataViewCtrlBase
)
1322 BEGIN_EVENT_TABLE(wxDataViewCtrl
,wxDataViewCtrlBase
)
1323 EVT_SIZE(wxDataViewCtrl::OnSize
)
1327 // !wxUSE_GENERICDATAVIEWCTRL
1330 // wxUSE_DATAVIEWCTRL