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
->HandleWindowEvent(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 static bool InitializeColumnDescription(DataBrowserListViewColumnDesc
& columnDescription
, wxDataViewColumn
const* columnPtr
, DataBrowserPropertyID columnPropertyID
, wxMacCFStringHolder
const& title
)
118 // set properties for the column:
119 columnDescription
.propertyDesc
.propertyID
= columnPropertyID
;
120 columnDescription
.propertyDesc
.propertyType
= columnPtr
->GetRenderer()->GetPropertyType();
121 columnDescription
.propertyDesc
.propertyFlags
= kDataBrowserListViewSelectionColumn
; // make the column selectable
122 if (columnPtr
->IsSortable())
123 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewSortableColumn
;
125 if (columnPtr
->IsMovable())
126 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewMovableColumn
;
128 if (columnPtr
->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE
)
129 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserPropertyIsEditable
;
130 if ((columnDescription
.propertyDesc
.propertyType
== kDataBrowserTextType
) ||
131 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserIconAndTextType
) ||
132 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserDateTimeType
))
133 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
; // enables generally the possibility to have user input for the mentioned types
134 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
135 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
137 // set header's properties:
138 columnDescription
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
139 if (columnPtr
->IsResizeable())
141 columnDescription
.headerBtnDesc
.minimumWidth
= 0;
142 columnDescription
.headerBtnDesc
.maximumWidth
= 30000; // 32767 is the theoretical maximum though but 30000 looks nicer
146 columnDescription
.headerBtnDesc
.minimumWidth
= columnPtr
->GetWidth();
147 columnDescription
.headerBtnDesc
.maximumWidth
= columnPtr
->GetWidth();
149 columnDescription
.headerBtnDesc
.titleOffset
= 0;
150 columnDescription
.headerBtnDesc
.titleString
= ::CFStringCreateCopy(kCFAllocatorDefault
,title
);
151 columnDescription
.headerBtnDesc
.initialOrder
= kDataBrowserOrderIncreasing
; // choose one of the orders as "undefined" is not supported anyway (s. ControlDefs.h in the HIToolbox framework)
152 columnDescription
.headerBtnDesc
.btnFontStyle
.flags
= kControlUseFontMask
| kControlUseJustMask
;
153 switch (columnPtr
->GetAlignment())
156 case wxALIGN_CENTER_HORIZONTAL
:
157 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teCenter
;
160 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushLeft
;
163 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushRight
;
166 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
168 columnDescription
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
169 columnDescription
.headerBtnDesc
.btnFontStyle
.style
= normal
;
170 columnDescription
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
171 if (columnPtr
->GetBitmap().Ok())
172 columnDescription
.headerBtnDesc
.btnContentInfo
.u
.iconRef
= columnPtr
->GetBitmap().GetIconRef();
175 } /* InitializeColumnDescription(DataBrowserListViewColumnDesc&, wxDataViewColumn const*, DataBrowserPropertyID, wxMacCFStringHolder const&) */
177 //-----------------------------------------------------------------------------
178 // local function pointers
179 //-----------------------------------------------------------------------------
181 DEFINE_ONE_SHOT_HANDLER_GETTER(wxMacDataViewCtrlEventHandler
)
183 // ---------------------------------------------------------
184 // wxMacDataViewModelNotifier
185 // ---------------------------------------------------------
187 class wxMacDataViewModelNotifier
: public wxDataViewModelNotifier
190 wxMacDataViewModelNotifier(wxMacDataViewDataBrowserListViewControl
* initDataViewControlPtr
) : m_dataViewControlPtr(initDataViewControlPtr
)
194 virtual bool ItemAdded(const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
196 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
199 wxCHECK_MSG(item
.IsOk(),false,_("Added item is invalid."));
200 return (!(parent
.IsOk()) && (this->m_dataViewControlPtr
->AddItem(kDataBrowserNoItem
,&itemID
) == noErr
) ||
201 parent
.IsOk() && (this->m_dataViewControlPtr
->AddItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
) == noErr
));
202 } /* ItemAdded(wxDataViewItem const&, wxDataViewItem const&) */
204 virtual bool ItemsAdded(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
208 DataBrowserItemID
* itemIDs
;
213 // convert all valid data view items to data browser items:
214 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
215 // insert all valid items into control:
216 noFailureFlag
= ((noOfEntries
== 0) ||
217 !(parent
.IsOk()) && (this->m_dataViewControlPtr
->AddItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
) ||
218 parent
.IsOk() && (this->m_dataViewControlPtr
->AddItems(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
));
219 // give allocated array space free again:
222 return noFailureFlag
;
223 } /* ItemsAdded(wxDataViewItem const&, wxDataViewItemArray const&) */
225 virtual bool ItemChanged(wxDataViewItem
const& item
)
227 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
230 wxCHECK_MSG(item
.IsOk(),false,_("Changed item is invalid."));
231 if (this->m_dataViewControlPtr
->UpdateItems(&itemID
) == noErr
)
233 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
235 // sent the equivalent wxWidget event:
236 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId()); // variable defintion
238 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
239 dataViewEvent
.SetItem(item
);
240 // sent the equivalent wxWidget event:
241 dataViewCtrlPtr
->HandleWindowEvent(dataViewEvent
);
247 } /* ItemChanged(wxDataViewItem const&) */
249 virtual bool ItemsChanged(wxDataViewItemArray
const& items
)
253 DataBrowserItemID
* itemIDs
;
258 // convert all valid data view items to data browser items:
259 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
260 // change items (ATTENTION: ONLY ITEMS OF THE ROOT ARE CHANGED BECAUSE THE PARENT PARAMETER IS MISSING):
261 noFailureFlag
= (this->m_dataViewControlPtr
->UpdateItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
,kDataBrowserItemNoProperty
) == noErr
);
264 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
266 // send for all changed items a wxWidget event:
267 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId()); // variable defintion
269 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
270 for (size_t i
=0; i
<noOfEntries
; ++i
)
272 dataViewEvent
.SetItem(reinterpret_cast<void*>(itemIDs
[i
]));
273 dataViewCtrlPtr
->HandleWindowEvent(dataViewEvent
);
276 // release allocated array space:
279 return noFailureFlag
;
280 } /* ItemsChanged(wxDataViewItem const&) */
282 virtual bool ItemDeleted(wxDataViewItem
const& parent
, wxDataViewItem
const& item
)
286 // variable definition and initialization:
287 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
288 OSStatus errorStatus
;
289 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
291 // 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
292 // not to be identical because the being edited item might be below the passed item in the hierarchy);
293 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
294 // has been started and that variables can currently not be updated even when requested by the system:
295 dataViewCtrlPtr
->SetDeleting(true);
296 errorStatus
= this->m_dataViewControlPtr
->RemoveItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
);
297 // enable automatic updating again:
298 dataViewCtrlPtr
->SetDeleting(false);
299 return (errorStatus
== noErr
);
303 } /* ItemDeleted(wxDataViewItem const&, wxDataViewItem const&) */
305 virtual bool ItemsDeleted(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
309 DataBrowserItemID
* itemIDs
;
311 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
316 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,false,_("Data view control is not correctly initialized"));
317 // convert all valid data view items to data browser items:
318 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
319 // 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
320 // not to be identical because the being edited item might be below the passed item in the hierarchy);
321 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
322 // has been started and that variables can currently not be updated even when requested by the system:
323 dataViewCtrlPtr
->SetDeleting(true);
324 // insert all valid items into control:
325 noFailureFlag
= ((noOfEntries
== 0) ||
326 !(parent
.IsOk()) && (this->m_dataViewControlPtr
->RemoveItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
) ||
327 parent
.IsOk() && (this->m_dataViewControlPtr
->RemoveItems(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
));
328 // enable automatic updating again:
329 dataViewCtrlPtr
->SetDeleting(false);
330 // give allocated array space free again:
333 return noFailureFlag
;
334 } /* ItemsDeleted(wxDataViewItem const&, wxDataViewItemArray const&) */
336 virtual bool ValueChanged(wxDataViewItem
const& item
, unsigned int col
)
338 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
339 DataBrowserItemID parentID
;
341 DataBrowserPropertyID propertyID
;
343 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
346 wxCHECK_MSG(item
.IsOk(), false,_("Passed item is invalid."));
347 wxCHECK_MSG(this->GetOwner() != NULL
,false,_("Owner not initialized."));
348 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Control is wrongly initialized."));
349 parentID
= reinterpret_cast<DataBrowserItemID
>(this->GetOwner()->GetParent(item
).GetID());
350 if ((this->m_dataViewControlPtr
->GetPropertyID(col
,&propertyID
) == noErr
) &&
351 (this->m_dataViewControlPtr
->UpdateItems(parentID
,1,&itemID
,dataViewCtrlPtr
->GetColumn(col
)->GetPropertyID(),propertyID
) == noErr
))
353 // variable definition and initialization:
354 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId());
356 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
357 dataViewEvent
.SetColumn(col
);
358 dataViewEvent
.SetItem(item
);
359 // send the equivalent wxWidget event:
360 dataViewCtrlPtr
->HandleWindowEvent(dataViewEvent
);
366 } /* ValueChanged(wxDataViewItem const&, unsigned int) */
368 virtual bool Cleared(void)
370 return (this->m_dataViewControlPtr
->RemoveItems() == noErr
);
371 } /* Cleared(void) */
373 virtual void Resort(void)
375 this->m_dataViewControlPtr
->Resort();
383 wxMacDataViewDataBrowserListViewControl
* m_dataViewControlPtr
;
386 // ---------------------------------------------------------
387 // wxDataViewRenderer
388 // ---------------------------------------------------------
390 wxDataViewRenderer::wxDataViewRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
391 :wxDataViewRendererBase(varianttype
,mode
,align
), m_alignment(align
), m_mode(mode
)
393 } /* wxDataViewRenderer::wxDataViewRenderer(wxString const&, wxDataViewCellMode) */
395 void wxDataViewRenderer::SetMode(wxDataViewCellMode mode
)
397 wxDataViewColumn
* dataViewColumnPtr
;
401 dataViewColumnPtr
= this->GetOwner();
402 if (dataViewColumnPtr
!= NULL
)
404 // variable definition and initialization:
405 wxDataViewCtrl
* dataViewCtrlPtr(dataViewColumnPtr
->GetOwner());
407 if (dataViewCtrlPtr
!= NULL
)
409 // variable definition and initialization:
410 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
412 if (macDataViewListCtrlPtr
!= NULL
)
414 // variable definition and initialization:
415 DataBrowserPropertyFlags flags
;
417 verify_noerr(macDataViewListCtrlPtr
->GetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),&flags
));
418 if (mode
== wxDATAVIEW_CELL_EDITABLE
)
419 flags
|= kDataBrowserPropertyIsEditable
;
421 flags
&= ~kDataBrowserPropertyIsEditable
;
422 verify_noerr(macDataViewListCtrlPtr
->SetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),flags
));
426 } /* wxDataViewRenderer::SetMode(wxDataViewCellMode) */
428 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
,wxDataViewRendererBase
)
430 // ---------------------------------------------------------
431 // wxDataViewCustomRenderer
432 // ---------------------------------------------------------
434 wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
435 :wxDataViewRenderer(varianttype
,mode
,align
), m_editorCtrlPtr(NULL
), m_DCPtr(NULL
)
437 } /* wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const&, wxDataViewCellMode) */
439 wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void)
441 if (this->m_DCPtr
!= NULL
)
442 delete this->m_DCPtr
;
443 } /* wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) */
445 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
)
447 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
448 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) : view
->GetForegroundColour();
449 dc
->SetTextForeground(col
);
450 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
453 wxDC
* wxDataViewCustomRenderer::GetDC(void)
455 if (this->m_DCPtr
== NULL
)
457 if ((GetOwner() == NULL
) || (GetOwner()->GetOwner() == NULL
))
459 this->m_DCPtr
= new wxClientDC(this->GetOwner()->GetOwner());
461 return this->m_DCPtr
;
462 } /* wxDataViewCustomRenderer::GetDC(void) */
464 bool wxDataViewCustomRenderer::Render(void)
467 } /* wxDataViewCustomRenderer::Render(void) */
469 void wxDataViewCustomRenderer::SetDC(wxDC
* newDCPtr
)
471 delete this->m_DCPtr
;
472 this->m_DCPtr
= newDCPtr
;
473 } /* wxDataViewCustomRenderer::SetDC(wxDC*) */
475 WXDataBrowserPropertyType
wxDataViewCustomRenderer::GetPropertyType(void) const
477 return kDataBrowserCustomType
;
478 } /* wxDataViewCustomRenderer::GetPropertyType(void) const */
480 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
482 // ---------------------------------------------------------
483 // wxDataViewTextRenderer
484 // ---------------------------------------------------------
486 wxDataViewTextRenderer::wxDataViewTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
487 :wxDataViewRenderer(varianttype
,mode
,align
)
489 } /* wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const&, wxDataViewCellMode, int) */
491 bool wxDataViewTextRenderer::Render(void)
493 if (this->GetValue().GetType() == this->GetVariantType())
495 // variable definition:
496 wxMacCFStringHolder
cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
498 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
);
502 } /* wxDataViewTextRenderer::Render(void) */
504 WXDataBrowserPropertyType
wxDataViewTextRenderer::GetPropertyType(void) const
506 return kDataBrowserTextType
;
507 } /* wxDataViewTextRenderer::GetPropertyType(void) const */
509 IMPLEMENT_CLASS(wxDataViewTextRenderer
,wxDataViewRenderer
)
511 // ---------------------------------------------------------
512 // wxDataViewTextRendererAttr
513 // ---------------------------------------------------------
515 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
516 :wxDataViewTextRenderer(varianttype
,mode
,align
)
518 } /* wxDataViewTextRendererAttr::wxDataViewTextRendererAttr(wxString const&, wxDataViewCellMode, int) */
520 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
,wxDataViewTextRenderer
)
522 // ---------------------------------------------------------
523 // wxDataViewBitmapRenderer
524 // ---------------------------------------------------------
526 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
527 :wxDataViewRenderer(varianttype
,mode
,align
)
531 bool wxDataViewBitmapRenderer::Render(void)
533 if (this->GetValue().GetType() == this->GetVariantType())
537 bitmap
<< this->GetValue();
539 return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap
.GetIconRef()) == noErr
);
545 } /* wxDataViewBitmapRenderer::Render(void) */
547 WXDataBrowserPropertyType
wxDataViewBitmapRenderer::GetPropertyType(void) const
549 return kDataBrowserIconType
;
550 } /* wxDataViewBitmapRenderer::GetPropertyType(void) const */
552 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
,wxDataViewRenderer
)
554 // ---------------------------------------------------------
555 // wxDataViewIconTextRenderer
556 // ---------------------------------------------------------
558 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
559 :wxDataViewRenderer(varianttype
,mode
)
563 bool wxDataViewIconTextRenderer::Render(void)
565 if (this->GetValue().GetType() == this->GetVariantType())
567 // variable definition:
568 wxDataViewIconText iconText
;
570 iconText
<< this->GetValue();
572 // variable definition:
573 wxMacCFStringHolder
cfString(iconText
.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
575 return ((::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText
.GetIcon().GetHICON())) == noErr
) &&
576 (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
));
580 } /* wxDataViewIconTextRenderer::Render(void) */
582 WXDataBrowserPropertyType
wxDataViewIconTextRenderer::GetPropertyType(void) const
584 return kDataBrowserIconAndTextType
;
585 } /* wxDataViewIconTextRenderer::GetPropertyType(void) const */
587 IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer
,wxDataViewRenderer
)
590 // ---------------------------------------------------------
591 // wxDataViewToggleRenderer
592 // ---------------------------------------------------------
594 wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
595 :wxDataViewRenderer(varianttype
,mode
)
599 bool wxDataViewToggleRenderer::Render(void)
601 if (this->GetValue().GetType() == this->GetVariantType())
602 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr
);
605 } /* wxDataViewToggleRenderer::Render(void) */
607 WXDataBrowserPropertyType
wxDataViewToggleRenderer::GetPropertyType(void) const
609 return kDataBrowserCheckboxType
;
610 } /* wxDataViewToggleRenderer::GetPropertyType(void) const */
612 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
,wxDataViewRenderer
)
614 // ---------------------------------------------------------
615 // wxDataViewProgressRenderer
616 // ---------------------------------------------------------
618 wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString
const& label
, wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
619 :wxDataViewRenderer(varianttype
,mode
,align
)
623 bool wxDataViewProgressRenderer::Render(void)
625 if (this->GetValue().GetType() == this->GetVariantType())
626 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr
) &&
627 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr
) &&
628 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr
));
631 } /* wxDataViewProgressRenderer::Render(void) */
633 WXDataBrowserPropertyType
wxDataViewProgressRenderer::GetPropertyType(void) const
635 return kDataBrowserProgressBarType
;
636 } /* wxDataViewProgressRenderer::GetPropertyType(void) const */
638 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
,wxDataViewRenderer
)
640 // ---------------------------------------------------------
641 // wxDataViewDateRenderer
642 // ---------------------------------------------------------
644 wxDataViewDateRenderer::wxDataViewDateRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
645 :wxDataViewRenderer(varianttype
,mode
,align
)
649 bool wxDataViewDateRenderer::Render(void)
651 if (this->GetValue().GetType() == this->GetVariantType())
652 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan
,1904)).GetSeconds().GetLo()) == noErr
);
655 } /* wxDataViewDateRenderer::Render(void) */
657 WXDataBrowserPropertyType
wxDataViewDateRenderer::GetPropertyType(void) const
659 return kDataBrowserDateTimeType
;
660 } /* wxDataViewDateRenderer::GetPropertyType(void) const */
662 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
,wxDataViewRenderer
)
664 // ---------------------------------------------------------
666 // ---------------------------------------------------------
668 wxDataViewColumn::wxDataViewColumn(wxString
const &title
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
669 :wxDataViewColumnBase(title
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
670 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
)), m_maxWidth(30000), m_minWidth(0), m_width(width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
),
671 m_alignment(align
), m_title(title
)
673 } /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
675 wxDataViewColumn::wxDataViewColumn(wxBitmap
const& bitmap
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
676 :wxDataViewColumnBase(bitmap
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
677 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
)), m_maxWidth(30000), m_minWidth(0), m_width(width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
),
680 } /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
682 void wxDataViewColumn::SetAlignment(wxAlignment align
)
684 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
687 this->m_alignment
= align
;
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."));
702 case wxALIGN_CENTER_HORIZONTAL
:
703 headerDescription
.btnFontStyle
.just
= teCenter
;
706 headerDescription
.btnFontStyle
.just
= teFlushLeft
;
709 headerDescription
.btnFontStyle
.just
= teFlushRight
;
712 headerDescription
.btnFontStyle
.just
= teFlushDefault
;
714 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set alignment."));
717 } /* wxDataViewColumn::SetAlignment(wxAlignment) */
719 void wxDataViewColumn::SetBitmap(wxBitmap
const& bitmap
)
721 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
724 wxDataViewColumnBase::SetBitmap(bitmap
);
725 if (dataViewCtrlPtr
!= NULL
)
727 // variable definition and initialization:
728 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
730 if (macDataViewListCtrlPtr
!= NULL
)
732 // variable definition and initialization:
733 DataBrowserListViewHeaderDesc headerDescription
;
735 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
736 if (this->GetBitmap().Ok())
737 headerDescription
.btnContentInfo
.u
.iconRef
= this->GetBitmap().GetIconRef();
739 headerDescription
.btnContentInfo
.u
.iconRef
= NULL
;
740 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set icon."));
743 } /* wxDataViewColumn::SetBitmap(wxBitmap const&) */
745 void wxDataViewColumn::SetFlags(int flags
)
747 this->SetHidden ((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
748 this->SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
749 this->SetSortable ((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
750 } /* wxDataViewColumn::SetFlags(int) */
752 void wxDataViewColumn::SetMaxWidth(int maxWidth
)
754 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
757 this->m_maxWidth
= maxWidth
;
758 if (dataViewCtrlPtr
!= NULL
)
760 // variable definition and initialization:
761 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
763 if (macDataViewListCtrlPtr
!= NULL
)
765 // variable definition and initialization:
766 DataBrowserListViewHeaderDesc headerDescription
;
768 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
769 headerDescription
.maximumWidth
= static_cast<UInt16
>(maxWidth
);
770 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set maximum width."));
773 } /* wxDataViewColumn::SetMaxWidth(int) */
775 void wxDataViewColumn::SetMinWidth(int minWidth
)
777 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
780 this->m_minWidth
= minWidth
;
781 if (dataViewCtrlPtr
!= NULL
)
783 // variable definition and initialization:
784 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
786 if (macDataViewListCtrlPtr
!= NULL
)
788 // variable definition and initialization:
789 DataBrowserListViewHeaderDesc headerDescription
;
791 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
792 headerDescription
.minimumWidth
= static_cast<UInt16
>(minWidth
);
793 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set minimum width."));
796 } /* wxDataViewColumn::SetMaxWidth(int) */
798 void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable
))
800 } /* wxDataViewColumn::SetResizeable(bool) */
802 void wxDataViewColumn::SetSortable(bool sortable
)
804 // variable definition and initialization:
805 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
807 if (dataViewCtrlPtr
!= NULL
)
809 // variable definition and initialization:
810 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
812 if (macDataViewListCtrlPtr
!= NULL
)
814 // variable definition and initialization:
815 DataBrowserPropertyFlags flags
;
817 wxCHECK_RET(macDataViewListCtrlPtr
->GetPropertyFlags(this->GetPropertyID(),&flags
) == noErr
,_("Could not get property flags."));
820 this->m_flags
|= wxDATAVIEW_COL_SORTABLE
;
821 flags
|= kDataBrowserListViewSortableColumn
;
825 this->m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
826 flags
&= ~kDataBrowserPropertyIsEditable
;
828 wxCHECK_RET(macDataViewListCtrlPtr
->SetPropertyFlags(this->GetPropertyID(),flags
) == noErr
,_("Could not set property flags."));
831 } /* wxDataViewColumn::SetSortable(bool) */
833 void wxDataViewColumn::SetSortOrder(bool ascending
)
835 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
838 this->m_ascending
= ascending
;
839 if (dataViewCtrlPtr
!= NULL
)
841 // variable definition and initialization:
842 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
844 if (macDataViewListCtrlPtr
!= NULL
)
846 // variable definition and initialization:
847 DataBrowserListViewHeaderDesc headerDescription
;
849 verify_noerr(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
));
851 headerDescription
.initialOrder
= kDataBrowserOrderIncreasing
;
853 headerDescription
.initialOrder
= kDataBrowserOrderDecreasing
;
854 verify_noerr(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
));
855 macDataViewListCtrlPtr
->SetSortProperty(this->GetPropertyID());
858 } /* wxDataViewColumn::SetSortOrder(bool) */
860 void wxDataViewColumn::SetTitle(wxString
const& title
)
862 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
865 this->m_title
= title
;
866 if (dataViewCtrlPtr
!= NULL
)
868 // variable definition and initialization:
869 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
871 if (macDataViewListCtrlPtr
!= NULL
)
873 // variable definition and initialization:
874 DataBrowserListViewHeaderDesc headerDescription
;
875 wxMacCFStringHolder
cfTitle(title
,(dataViewCtrlPtr
->GetFont().Ok() ? dataViewCtrlPtr
->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
877 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
878 headerDescription
.titleString
= cfTitle
;
879 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set header description."));
882 } /* wxDataViewColumn::SetTitle(wxString const&) */
884 void wxDataViewColumn::SetWidth(int width
)
886 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
889 if ((width
>= this->m_minWidth
) && (width
<= this->m_maxWidth
))
891 this->m_width
= width
;
892 if (dataViewCtrlPtr
!= NULL
)
894 // variable definition and initialization:
895 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
897 if (macDataViewListCtrlPtr
!= NULL
)
898 wxCHECK_RET(macDataViewListCtrlPtr
->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16
>(width
)) == noErr
,_("Could not set column width."));
901 } /* wxDataViewColumn::SetWidth(int) */
903 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
,wxDataViewColumnBase
)
905 //-----------------------------------------------------------------------------
907 //-----------------------------------------------------------------------------
909 void wxDataViewCtrl::Init(void)
911 this->m_Deleting
= false;
912 this->m_macIsUserPane
= false;
913 this->m_cgContext
= NULL
;
914 } /* wxDataViewCtrl::Init(void) */
916 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
918 if (!(this->wxControl::Create(parent
,id
,pos
,size
,(style
| wxSUNKEN_BORDER
) & ~(wxHSCROLL
| wxVSCROLL
),validator
)))
922 MacSetClipChildren(true) ;
925 this->m_peer
= new wxMacDataViewDataBrowserListViewControl(this,pos
,size
,style
);
926 this->MacPostControlCreate(pos
,size
);
927 ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(this->m_peer
->GetControlRef()),true);
929 InstallControlEventHandler(this->m_peer
->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList
),eventList
,this,NULL
);
932 } /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
934 bool wxDataViewCtrl::AssociateModel(wxDataViewModel
* model
)
936 if (!wxDataViewCtrlBase::AssociateModel(model
))
939 model
->AddNotifier(new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl
*>(this->m_peer
)));
942 } /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
944 bool wxDataViewCtrl::AppendColumn(wxDataViewColumn
* columnPtr
)
946 DataBrowserListViewColumnDesc columnDescription
;
948 DataBrowserPropertyID NewPropertyID
;
950 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
952 wxMacCFStringHolder
title(columnPtr
->GetTitle(),this->m_font
.Ok() ? this->m_font
.GetEncoding() : wxLocale::GetSystemEncoding());
955 // first, some error checking:
956 wxCHECK_MSG(MacDataViewListCtrlPtr
!= NULL
, false,_("m_peer is not or incorrectly initialized"));
957 wxCHECK_MSG(columnPtr
!= NULL
, false,_("Column pointer must not be NULL."));
958 wxCHECK_MSG(columnPtr
->GetRenderer() != NULL
, false,_("Column does not have a renderer."));
959 wxCHECK_MSG(this->GetModel() != NULL
, false,_("No model associated with control."));
960 wxCHECK_MSG((columnPtr
->GetModelColumn() >= 0) &&
961 (columnPtr
->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
963 // try to get new ID for the column:
964 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetFreePropertyID(&NewPropertyID
) == noErr
,false,_("Cannot create new column's ID. Probably max. number of columns reached."));
965 // full column variable initialization:
966 columnPtr
->SetPropertyID(NewPropertyID
);
967 // add column to wxWidget's internal structure:
968 wxCHECK_MSG(this->wxDataViewCtrlBase::AppendColumn(columnPtr
) &&
969 this->m_ColumnPointers
.insert(ColumnPointerHashMapType::value_type(NewPropertyID
,columnPtr
)).second
,false,_("Could not add column to internal structures."));
970 // create a column description and add column to the native control:
971 wxCHECK_MSG(::InitializeColumnDescription(columnDescription
,columnPtr
,NewPropertyID
,title
), false,_("Column description could not be initialized."));
972 wxCHECK_MSG(MacDataViewListCtrlPtr
->AddColumn(&columnDescription
,kDataBrowserListViewAppendColumn
) == noErr
,false,_("Column could not be added."));
974 // final adjustments for the layout:
975 wxCHECK_MSG(MacDataViewListCtrlPtr
->SetColumnWidth(NewPropertyID
,columnPtr
->GetWidth()) == noErr
,false,_("Column width could not be set."));
977 // make sure that the data is up-to-date...
978 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
979 // otherwise ask the control to 'update' the data in the newly appended column:
980 if (this->GetColumnCount() == 1)
982 this->SetExpanderColumn(columnPtr
);
983 this->AddChildrenLevel(wxDataViewItem());
986 MacDataViewListCtrlPtr
->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,NewPropertyID
);
989 } /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
991 bool wxDataViewCtrl::ClearColumns(void)
993 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
996 while (this->m_ColumnPointers
.begin() != this->m_ColumnPointers
.end())
998 wxCHECK_MSG(MacDataViewListCtrlPtr
->RemoveColumnByProperty(this->m_ColumnPointers
.begin()->first
) == noErr
,false,_("Could not remove column."));
999 delete this->m_ColumnPointers
.begin()->second
;
1000 this->m_ColumnPointers
.erase(this->m_ColumnPointers
.begin());
1003 } /* wxDataViewCtrl::ClearColumns(void) */
1005 bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn
* columnPtr
)
1007 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1010 if ((MacDataViewListCtrlPtr
->RemoveColumnByProperty(columnPtr
->GetPropertyID()) == noErr
) && (this->m_ColumnPointers
.erase(columnPtr
->GetPropertyID()) > 0))
1017 } /* wxDataViewCtrl::DeleteColumn(wxDataViewColumn*) */
1019 wxDataViewColumn
* wxDataViewCtrl::GetColumn(unsigned int pos
) const
1021 DataBrowserPropertyID propertyID
;
1023 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1026 if (MacDataViewListCtrlPtr
->GetPropertyID(pos
,&propertyID
) == noErr
)
1028 // variable definition:
1029 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
1031 if (Result
!= this->m_ColumnPointers
.end())
1032 return Result
->second
;
1038 } /* wxDataViewCtrl::GetColumn(unsigned int pos) const */
1040 unsigned int wxDataViewCtrl::GetColumnCount(void) const
1042 return this->m_ColumnPointers
.size();
1043 } /* wxDataViewCtrl::GetColumnCount(void) const */
1045 int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn
const* columnPtr
) const
1047 if (columnPtr
!= NULL
)
1049 // variable definition and initialization:
1050 DataBrowserTableViewColumnIndex Position
;
1051 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1053 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetColumnIndex(columnPtr
->GetPropertyID(),&Position
) == noErr
,-1,_("Could not determine column's position"));
1054 return static_cast<int>(Position
);
1058 } /* wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const*) const */
1060 bool wxDataViewCtrl::PrependColumn(wxDataViewColumn
* columnPtr
)
1062 DataBrowserListViewColumnDesc columnDescription
;
1064 DataBrowserPropertyID NewPropertyID
;
1066 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1068 wxMacCFStringHolder
title(columnPtr
->GetTitle(),this->m_font
.Ok() ? this->m_font
.GetEncoding() : wxLocale::GetSystemEncoding());
1071 // first, some error checking:
1072 wxCHECK_MSG(MacDataViewListCtrlPtr
!= NULL
, false,_("m_peer is not or incorrectly initialized"));
1073 wxCHECK_MSG(columnPtr
!= NULL
, false,_("Column pointer must not be NULL."));
1074 wxCHECK_MSG(columnPtr
->GetRenderer() != NULL
, false,_("Column does not have a renderer."));
1075 wxCHECK_MSG(this->GetModel() != NULL
, false,_("No model associated with control."));
1076 wxCHECK_MSG((columnPtr
->GetModelColumn() >= 0) &&
1077 (columnPtr
->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
1079 // try to get new ID for the column:
1080 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetFreePropertyID(&NewPropertyID
) == noErr
,false,_("Cannot create new column's ID. Probably max. number of columns reached."));
1081 // full column variable initialization:
1082 columnPtr
->SetPropertyID(NewPropertyID
);
1083 // add column to wxWidget's internal structure:
1084 wxCHECK_MSG(this->wxDataViewCtrlBase::AppendColumn(columnPtr
) &&
1085 this->m_ColumnPointers
.insert(ColumnPointerHashMapType::value_type(NewPropertyID
,columnPtr
)).second
,false,_("Could not add column to internal structures."));
1086 // create a column description and add column to the native control:
1087 wxCHECK_MSG(::InitializeColumnDescription(columnDescription
,columnPtr
,NewPropertyID
,title
),false,_("Column description could not be initialized."));
1088 wxCHECK_MSG(MacDataViewListCtrlPtr
->AddColumn(&columnDescription
,0) == noErr
, false,_("Column could not be added."));
1090 // final adjustments for the layout:
1091 wxCHECK_MSG(MacDataViewListCtrlPtr
->SetColumnWidth(NewPropertyID
,columnPtr
->GetWidth()) == noErr
,false,_("Column width could not be set."));
1093 // make sure that the data is up-to-date...
1094 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
1095 // otherwise ask the control to 'update' the data in the newly appended column:
1096 if (this->GetColumnCount() == 1)
1098 this->SetExpanderColumn(columnPtr
);
1099 this->AddChildrenLevel(wxDataViewItem());
1102 MacDataViewListCtrlPtr
->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,NewPropertyID
);
1105 } /* wxDataViewCtrl::PrependColumn(wxDataViewColumn*) */
1107 void wxDataViewCtrl::Collapse(wxDataViewItem
const& item
)
1109 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1112 MacDataViewListCtrlPtr
->CloseContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1113 } /* wxDataViewCtrl::Collapse(wxDataViewItem const&) */
1115 void wxDataViewCtrl::EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
)
1119 // variable definition and initialization:
1120 DataBrowserPropertyID propertyID
;
1121 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1123 if (columnPtr
!= NULL
)
1124 propertyID
= columnPtr
->GetPropertyID();
1126 propertyID
= kDataBrowserNoItem
;
1127 MacDataViewListCtrlPtr
->RevealItem(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),propertyID
,kDataBrowserRevealOnly
);
1129 } /* wxDataViewCtrl::EnsureVisible(wxDataViewItem const&, wxDataViewColumn const*) */
1131 void wxDataViewCtrl::Expand(wxDataViewItem
const& item
)
1133 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1136 MacDataViewListCtrlPtr
->OpenContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1137 } /* wxDataViewCtrl::Expand(wxDataViewItem const&) */
1139 wxDataViewColumn
* wxDataViewCtrl::GetSortingColumn(void) const
1141 DataBrowserPropertyID propertyID
;
1143 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1146 if (MacDataViewListCtrlPtr
->GetSortProperty(&propertyID
) == noErr
)
1147 return this->GetColumnPtr(propertyID
);
1150 } /* wxDataViewCtrl::GetSortingColumn(void) const */
1152 unsigned int wxDataViewCtrl::GetCount(void) const
1154 ItemCount noOfItems
;
1157 wxCHECK_MSG(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
)->GetItemCount(&noOfItems
) == noErr
,0,_("Could not determine number of items"));
1159 } /* wxDataViewCtrl::GetCount(void) const */
1161 wxRect
wxDataViewCtrl::GetItemRect(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
) const
1163 if (item
.IsOk() && (columnPtr
!= NULL
))
1165 // variable definition:
1167 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1169 if (MacDataViewListCtrlPtr
->GetPartBounds(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),columnPtr
->GetPropertyID(),kDataBrowserPropertyContentPart
,&MacRectangle
) == noErr
)
1171 // variable definition:
1174 ::wxMacNativeToRect(&MacRectangle
,&rectangle
);
1182 } /* wxDataViewCtrl::GetItemRect(wxDataViewItem const&, unsigned int) const */
1184 wxDataViewItem
wxDataViewCtrl::GetSelection(void) const
1186 wxArrayDataBrowserItemID itemIDs
;
1188 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1191 if (MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
) > 0)
1192 return wxDataViewItem(reinterpret_cast<void*>(itemIDs
[0]));
1194 return wxDataViewItem();
1195 } /* wxDataViewCtrl::GetSelection(void) const */
1197 int wxDataViewCtrl::GetSelections(wxDataViewItemArray
& sel
) const
1199 size_t NoOfSelectedItems
;
1201 wxArrayDataBrowserItemID itemIDs
;
1203 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1206 NoOfSelectedItems
= MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
);
1208 sel
.SetCount(NoOfSelectedItems
);
1209 for (size_t i
=0; i
<NoOfSelectedItems
; ++i
)
1210 sel
[i
] = wxDataViewItem(reinterpret_cast<void*>(itemIDs
[i
]));
1211 return static_cast<int>(NoOfSelectedItems
);
1212 } /* wxDataViewCtrl::GetSelections(wxDataViewItemArray&) const */
1214 void wxDataViewCtrl::HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const
1216 item
= wxDataViewItem();
1218 } /* wxDataViewCtrl::HitTest(wxPoint const&, wxDataViewItem&, wxDataViewColumn*&) const */
1220 bool wxDataViewCtrl::IsSelected(wxDataViewItem
const& item
) const
1222 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1225 return MacDataViewListCtrlPtr
->IsItemSelected(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1226 } /* wxDataViewCtrl::IsSelected(wxDataViewItem const&) const */
1228 void wxDataViewCtrl::SelectAll(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
,kDataBrowserItemsAssign
);
1245 DisposeHandle(handle
);
1246 } /* wxDataViewCtrl::SelectAll(void) */
1248 void wxDataViewCtrl::Select(wxDataViewItem
const& item
)
1252 // variable definition and initialization:
1253 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1254 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1256 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsAdd
);
1258 } /* wxDataViewCtrl::Select(wxDataViewItem const&) */
1260 void wxDataViewCtrl::SetSelections(wxDataViewItemArray
const& sel
)
1262 size_t const NoOfSelections
= sel
.GetCount();
1264 DataBrowserItemID
* itemIDs
;
1266 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1269 itemIDs
= new DataBrowserItemID
[NoOfSelections
];
1270 for (size_t i
=0; i
<NoOfSelections
; ++i
)
1271 itemIDs
[i
] = reinterpret_cast<DataBrowserItemID
>(sel
[i
].GetID());
1272 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfSelections
,itemIDs
,kDataBrowserItemsAssign
);
1274 } /* wxDataViewCtrl::SetSelections(wxDataViewItemArray const&) */
1276 void wxDataViewCtrl::Unselect(wxDataViewItem
const& item
)
1280 // variable definition and initialization:
1281 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1282 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1284 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsRemove
);
1286 } /* wxDataViewCtrl::Unselect(wxDataViewItem const&) */
1288 void wxDataViewCtrl::UnselectAll(void)
1290 DataBrowserItemID
* itemIDPtr
;
1292 Handle
handle(::NewHandle(0));
1296 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1299 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1300 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1302 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1303 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsRemove
);
1305 DisposeHandle(handle
);
1306 } /* wxDataViewCtrl::UnselectAll(void) */
1309 void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem
const& parentItem
)
1313 wxDataViewItemArray items
;
1316 wxCHECK_RET(this->GetModel() != NULL
,_("Model pointer not initialized."));
1317 NoOfChildren
= this->GetModel()->GetChildren(parentItem
,items
);
1319 for (int i
=0; i
<NoOfChildren
; ++i
)
1320 (void) this->GetModel()->ItemAdded(parentItem
,items
[i
]);
1322 (void) this->GetModel()->ItemsAdded(parentItem
,items
);
1324 } /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
1326 wxDataViewColumn
* wxDataViewCtrl::GetColumnPtr(WXDataBrowserPropertyID propertyID
) const
1328 // variable definition:
1329 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
1331 if (Result
!= this->m_ColumnPointers
.end())
1332 return Result
->second
;
1335 } /* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID) const */
1337 // inherited methods from wxDataViewCtrlBase
1338 void wxDataViewCtrl::DoSetExpanderColumn(void)
1340 if (this->GetExpanderColumn() != NULL
)
1342 // variable definition and initialization:
1343 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1345 (void) MacDataViewListCtrlPtr
->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID());
1347 } /* wxDataViewCtrl::DoSetExpanderColumn(void) */
1349 void wxDataViewCtrl::DoSetIndent(void)
1351 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1354 (void) MacDataViewListCtrlPtr
->SetIndent(static_cast<float>(this->GetIndent()));
1355 } /* wxDataViewCtrl::DoSetIndent(void) */
1358 void wxDataViewCtrl::OnSize(wxSizeEvent
& event
)
1360 unsigned int const NoOfColumns
= this->GetColumnCount();
1363 for (unsigned int i
=0; i
<NoOfColumns
; ++i
)
1365 // variable definition and initialization:
1366 wxDataViewColumn
* dataViewColumnPtr(this->GetColumn(i
));
1368 if (dataViewColumnPtr
!= NULL
)
1370 // variable definition and initialization:
1371 wxDataViewCustomRenderer
* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer()));
1373 if (dataViewCustomRendererPtr
!= NULL
)
1374 dataViewCustomRendererPtr
->SetDC(NULL
); // reset DC because DC has changed
1378 } /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
1380 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
,wxDataViewCtrlBase
)
1382 BEGIN_EVENT_TABLE(wxDataViewCtrl
,wxDataViewCtrlBase
)
1383 EVT_SIZE(wxDataViewCtrl::OnSize
)
1387 // !wxUSE_GENERICDATAVIEWCTRL
1390 // wxUSE_DATAVIEWCTRL