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
) ? *wxWHITE
: 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 wxWindowDC(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 if (iconText
.GetIcon().IsOk())
577 if (::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText
.GetIcon().GetHICON())) != noErr
)
581 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
);
585 } /* wxDataViewIconTextRenderer::Render(void) */
587 WXDataBrowserPropertyType
wxDataViewIconTextRenderer::GetPropertyType(void) const
589 return kDataBrowserIconAndTextType
;
590 } /* wxDataViewIconTextRenderer::GetPropertyType(void) const */
592 IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer
,wxDataViewRenderer
)
595 // ---------------------------------------------------------
596 // wxDataViewToggleRenderer
597 // ---------------------------------------------------------
599 wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
600 :wxDataViewRenderer(varianttype
,mode
)
604 bool wxDataViewToggleRenderer::Render(void)
606 if (this->GetValue().GetType() == this->GetVariantType())
607 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr
);
610 } /* wxDataViewToggleRenderer::Render(void) */
612 WXDataBrowserPropertyType
wxDataViewToggleRenderer::GetPropertyType(void) const
614 return kDataBrowserCheckboxType
;
615 } /* wxDataViewToggleRenderer::GetPropertyType(void) const */
617 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
,wxDataViewRenderer
)
619 // ---------------------------------------------------------
620 // wxDataViewProgressRenderer
621 // ---------------------------------------------------------
623 wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString
const& label
, wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
624 :wxDataViewRenderer(varianttype
,mode
,align
)
628 bool wxDataViewProgressRenderer::Render(void)
630 if (this->GetValue().GetType() == this->GetVariantType())
631 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr
) &&
632 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr
) &&
633 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr
));
636 } /* wxDataViewProgressRenderer::Render(void) */
638 WXDataBrowserPropertyType
wxDataViewProgressRenderer::GetPropertyType(void) const
640 return kDataBrowserProgressBarType
;
641 } /* wxDataViewProgressRenderer::GetPropertyType(void) const */
643 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
,wxDataViewRenderer
)
645 // ---------------------------------------------------------
646 // wxDataViewDateRenderer
647 // ---------------------------------------------------------
649 wxDataViewDateRenderer::wxDataViewDateRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
650 :wxDataViewRenderer(varianttype
,mode
,align
)
654 bool wxDataViewDateRenderer::Render(void)
656 if (this->GetValue().GetType() == this->GetVariantType())
657 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan
,1904)).GetSeconds().GetLo()) == noErr
);
660 } /* wxDataViewDateRenderer::Render(void) */
662 WXDataBrowserPropertyType
wxDataViewDateRenderer::GetPropertyType(void) const
664 return kDataBrowserDateTimeType
;
665 } /* wxDataViewDateRenderer::GetPropertyType(void) const */
667 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
,wxDataViewRenderer
)
669 // ---------------------------------------------------------
671 // ---------------------------------------------------------
673 wxDataViewColumn::wxDataViewColumn(wxString
const &title
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
674 :wxDataViewColumnBase(title
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
675 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
)), m_maxWidth(30000), m_minWidth(0), m_width(width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
),
676 m_alignment(align
), m_title(title
)
678 } /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
680 wxDataViewColumn::wxDataViewColumn(wxBitmap
const& bitmap
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
681 :wxDataViewColumnBase(bitmap
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
682 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
)), m_maxWidth(30000), m_minWidth(0), m_width(width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
),
685 } /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
687 void wxDataViewColumn::SetAlignment(wxAlignment align
)
689 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
692 this->m_alignment
= align
;
693 if (dataViewCtrlPtr
!= NULL
)
695 // variable definition and initialization:
696 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
698 if (macDataViewListCtrlPtr
!= NULL
)
700 // variable definition and initialization:
701 DataBrowserListViewHeaderDesc headerDescription
;
703 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
707 case wxALIGN_CENTER_HORIZONTAL
:
708 headerDescription
.btnFontStyle
.just
= teCenter
;
711 headerDescription
.btnFontStyle
.just
= teFlushLeft
;
714 headerDescription
.btnFontStyle
.just
= teFlushRight
;
717 headerDescription
.btnFontStyle
.just
= teFlushDefault
;
719 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set alignment."));
722 } /* wxDataViewColumn::SetAlignment(wxAlignment) */
724 void wxDataViewColumn::SetBitmap(wxBitmap
const& bitmap
)
726 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
729 wxDataViewColumnBase::SetBitmap(bitmap
);
730 if (dataViewCtrlPtr
!= NULL
)
732 // variable definition and initialization:
733 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
735 if (macDataViewListCtrlPtr
!= NULL
)
737 // variable definition and initialization:
738 DataBrowserListViewHeaderDesc headerDescription
;
740 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
741 if (this->GetBitmap().Ok())
742 headerDescription
.btnContentInfo
.u
.iconRef
= this->GetBitmap().GetIconRef();
744 headerDescription
.btnContentInfo
.u
.iconRef
= NULL
;
745 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set icon."));
748 } /* wxDataViewColumn::SetBitmap(wxBitmap const&) */
750 void wxDataViewColumn::SetFlags(int flags
)
752 this->SetHidden ((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
753 this->SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
754 this->SetSortable ((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
755 } /* wxDataViewColumn::SetFlags(int) */
757 void wxDataViewColumn::SetMaxWidth(int maxWidth
)
759 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
762 this->m_maxWidth
= maxWidth
;
763 if (dataViewCtrlPtr
!= NULL
)
765 // variable definition and initialization:
766 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
768 if (macDataViewListCtrlPtr
!= NULL
)
770 // variable definition and initialization:
771 DataBrowserListViewHeaderDesc headerDescription
;
773 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
774 headerDescription
.maximumWidth
= static_cast<UInt16
>(maxWidth
);
775 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set maximum width."));
778 } /* wxDataViewColumn::SetMaxWidth(int) */
780 void wxDataViewColumn::SetMinWidth(int minWidth
)
782 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
785 this->m_minWidth
= minWidth
;
786 if (dataViewCtrlPtr
!= NULL
)
788 // variable definition and initialization:
789 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
791 if (macDataViewListCtrlPtr
!= NULL
)
793 // variable definition and initialization:
794 DataBrowserListViewHeaderDesc headerDescription
;
796 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
797 headerDescription
.minimumWidth
= static_cast<UInt16
>(minWidth
);
798 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set minimum width."));
801 } /* wxDataViewColumn::SetMaxWidth(int) */
803 void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable
))
805 } /* wxDataViewColumn::SetResizeable(bool) */
807 void wxDataViewColumn::SetSortable(bool sortable
)
809 // variable definition and initialization:
810 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
812 if (dataViewCtrlPtr
!= NULL
)
814 // variable definition and initialization:
815 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
817 if (macDataViewListCtrlPtr
!= NULL
)
819 // variable definition and initialization:
820 DataBrowserPropertyFlags flags
;
822 wxCHECK_RET(macDataViewListCtrlPtr
->GetPropertyFlags(this->GetPropertyID(),&flags
) == noErr
,_("Could not get property flags."));
825 this->m_flags
|= wxDATAVIEW_COL_SORTABLE
;
826 flags
|= kDataBrowserListViewSortableColumn
;
830 this->m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
831 flags
&= ~kDataBrowserPropertyIsEditable
;
833 wxCHECK_RET(macDataViewListCtrlPtr
->SetPropertyFlags(this->GetPropertyID(),flags
) == noErr
,_("Could not set property flags."));
836 } /* wxDataViewColumn::SetSortable(bool) */
838 void wxDataViewColumn::SetSortOrder(bool ascending
)
840 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
843 this->m_ascending
= ascending
;
844 if (dataViewCtrlPtr
!= NULL
)
846 // variable definition and initialization:
847 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
849 if (macDataViewListCtrlPtr
!= NULL
)
851 // variable definition and initialization:
852 DataBrowserListViewHeaderDesc headerDescription
;
854 verify_noerr(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
));
856 headerDescription
.initialOrder
= kDataBrowserOrderIncreasing
;
858 headerDescription
.initialOrder
= kDataBrowserOrderDecreasing
;
859 verify_noerr(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
));
860 macDataViewListCtrlPtr
->SetSortProperty(this->GetPropertyID());
863 } /* wxDataViewColumn::SetSortOrder(bool) */
865 void wxDataViewColumn::SetTitle(wxString
const& title
)
867 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
870 this->m_title
= title
;
871 if (dataViewCtrlPtr
!= NULL
)
873 // variable definition and initialization:
874 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
876 if (macDataViewListCtrlPtr
!= NULL
)
878 // variable definition and initialization:
879 DataBrowserListViewHeaderDesc headerDescription
;
880 wxMacCFStringHolder
cfTitle(title
,(dataViewCtrlPtr
->GetFont().Ok() ? dataViewCtrlPtr
->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
882 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
883 headerDescription
.titleString
= cfTitle
;
884 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set header description."));
887 } /* wxDataViewColumn::SetTitle(wxString const&) */
889 void wxDataViewColumn::SetWidth(int width
)
891 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
894 if ((width
>= this->m_minWidth
) && (width
<= this->m_maxWidth
))
896 this->m_width
= width
;
897 if (dataViewCtrlPtr
!= NULL
)
899 // variable definition and initialization:
900 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
902 if (macDataViewListCtrlPtr
!= NULL
)
903 wxCHECK_RET(macDataViewListCtrlPtr
->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16
>(width
)) == noErr
,_("Could not set column width."));
906 } /* wxDataViewColumn::SetWidth(int) */
908 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
,wxDataViewColumnBase
)
910 //-----------------------------------------------------------------------------
912 //-----------------------------------------------------------------------------
914 void wxDataViewCtrl::Init(void)
916 this->m_Deleting
= false;
917 this->m_macIsUserPane
= false;
918 this->m_cgContext
= NULL
;
919 } /* wxDataViewCtrl::Init(void) */
921 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
923 if (!(this->wxControl::Create(parent
,id
,pos
,size
,(style
| wxSUNKEN_BORDER
) & ~(wxHSCROLL
| wxVSCROLL
),validator
)))
927 MacSetClipChildren(true) ;
930 this->m_peer
= new wxMacDataViewDataBrowserListViewControl(this,pos
,size
,style
);
931 this->MacPostControlCreate(pos
,size
);
932 ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(this->m_peer
->GetControlRef()),true);
934 InstallControlEventHandler(this->m_peer
->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList
),eventList
,this,NULL
);
936 ::SetDataBrowserTableViewHiliteStyle( this->m_peer
->GetControlRef(), kDataBrowserTableViewFillHilite
);
939 } /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
941 bool wxDataViewCtrl::AssociateModel(wxDataViewModel
* model
)
943 if (!wxDataViewCtrlBase::AssociateModel(model
))
946 model
->AddNotifier(new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl
*>(this->m_peer
)));
949 } /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
951 bool wxDataViewCtrl::AppendColumn(wxDataViewColumn
* columnPtr
)
953 DataBrowserListViewColumnDesc columnDescription
;
955 DataBrowserPropertyID NewPropertyID
;
957 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
959 wxMacCFStringHolder
title(columnPtr
->GetTitle(),this->m_font
.Ok() ? this->m_font
.GetEncoding() : wxLocale::GetSystemEncoding());
962 // first, some error checking:
963 wxCHECK_MSG(MacDataViewListCtrlPtr
!= NULL
, false,_("m_peer is not or incorrectly initialized"));
964 wxCHECK_MSG(columnPtr
!= NULL
, false,_("Column pointer must not be NULL."));
965 wxCHECK_MSG(columnPtr
->GetRenderer() != NULL
, false,_("Column does not have a renderer."));
966 wxCHECK_MSG(this->GetModel() != NULL
, false,_("No model associated with control."));
967 wxCHECK_MSG((columnPtr
->GetModelColumn() >= 0) &&
968 (columnPtr
->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
970 // try to get new ID for the column:
971 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetFreePropertyID(&NewPropertyID
) == noErr
,false,_("Cannot create new column's ID. Probably max. number of columns reached."));
972 // full column variable initialization:
973 columnPtr
->SetPropertyID(NewPropertyID
);
974 // add column to wxWidget's internal structure:
975 wxCHECK_MSG(this->wxDataViewCtrlBase::AppendColumn(columnPtr
) &&
976 this->m_ColumnPointers
.insert(ColumnPointerHashMapType::value_type(NewPropertyID
,columnPtr
)).second
,false,_("Could not add column to internal structures."));
977 // create a column description and add column to the native control:
978 wxCHECK_MSG(::InitializeColumnDescription(columnDescription
,columnPtr
,NewPropertyID
,title
), false,_("Column description could not be initialized."));
979 wxCHECK_MSG(MacDataViewListCtrlPtr
->AddColumn(&columnDescription
,kDataBrowserListViewAppendColumn
) == noErr
,false,_("Column could not be added."));
981 // final adjustments for the layout:
982 wxCHECK_MSG(MacDataViewListCtrlPtr
->SetColumnWidth(NewPropertyID
,columnPtr
->GetWidth()) == noErr
,false,_("Column width could not be set."));
984 // make sure that the data is up-to-date...
985 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
986 // otherwise ask the control to 'update' the data in the newly appended column:
987 if (this->GetColumnCount() == 1)
989 this->SetExpanderColumn(columnPtr
);
990 this->AddChildrenLevel(wxDataViewItem());
993 MacDataViewListCtrlPtr
->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,NewPropertyID
);
996 } /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
998 bool wxDataViewCtrl::ClearColumns(void)
1000 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1003 while (this->m_ColumnPointers
.begin() != this->m_ColumnPointers
.end())
1005 wxCHECK_MSG(MacDataViewListCtrlPtr
->RemoveColumnByProperty(this->m_ColumnPointers
.begin()->first
) == noErr
,false,_("Could not remove column."));
1006 delete this->m_ColumnPointers
.begin()->second
;
1007 this->m_ColumnPointers
.erase(this->m_ColumnPointers
.begin());
1010 } /* wxDataViewCtrl::ClearColumns(void) */
1012 bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn
* columnPtr
)
1014 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1017 if ((MacDataViewListCtrlPtr
->RemoveColumnByProperty(columnPtr
->GetPropertyID()) == noErr
) && (this->m_ColumnPointers
.erase(columnPtr
->GetPropertyID()) > 0))
1024 } /* wxDataViewCtrl::DeleteColumn(wxDataViewColumn*) */
1026 wxDataViewColumn
* wxDataViewCtrl::GetColumn(unsigned int pos
) const
1028 DataBrowserPropertyID propertyID
;
1030 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1033 if (MacDataViewListCtrlPtr
->GetPropertyID(pos
,&propertyID
) == noErr
)
1035 // variable definition:
1036 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
1038 if (Result
!= this->m_ColumnPointers
.end())
1039 return Result
->second
;
1045 } /* wxDataViewCtrl::GetColumn(unsigned int pos) const */
1047 unsigned int wxDataViewCtrl::GetColumnCount(void) const
1049 return this->m_ColumnPointers
.size();
1050 } /* wxDataViewCtrl::GetColumnCount(void) const */
1052 int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn
const* columnPtr
) const
1054 if (columnPtr
!= NULL
)
1056 // variable definition and initialization:
1057 DataBrowserTableViewColumnIndex Position
;
1058 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1060 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetColumnIndex(columnPtr
->GetPropertyID(),&Position
) == noErr
,-1,_("Could not determine column's position"));
1061 return static_cast<int>(Position
);
1065 } /* wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const*) const */
1067 bool wxDataViewCtrl::PrependColumn(wxDataViewColumn
* columnPtr
)
1069 DataBrowserListViewColumnDesc columnDescription
;
1071 DataBrowserPropertyID NewPropertyID
;
1073 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1075 wxMacCFStringHolder
title(columnPtr
->GetTitle(),this->m_font
.Ok() ? this->m_font
.GetEncoding() : wxLocale::GetSystemEncoding());
1078 // first, some error checking:
1079 wxCHECK_MSG(MacDataViewListCtrlPtr
!= NULL
, false,_("m_peer is not or incorrectly initialized"));
1080 wxCHECK_MSG(columnPtr
!= NULL
, false,_("Column pointer must not be NULL."));
1081 wxCHECK_MSG(columnPtr
->GetRenderer() != NULL
, false,_("Column does not have a renderer."));
1082 wxCHECK_MSG(this->GetModel() != NULL
, false,_("No model associated with control."));
1083 wxCHECK_MSG((columnPtr
->GetModelColumn() >= 0) &&
1084 (columnPtr
->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
1086 // try to get new ID for the column:
1087 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetFreePropertyID(&NewPropertyID
) == noErr
,false,_("Cannot create new column's ID. Probably max. number of columns reached."));
1088 // full column variable initialization:
1089 columnPtr
->SetPropertyID(NewPropertyID
);
1090 // add column to wxWidget's internal structure:
1091 wxCHECK_MSG(this->wxDataViewCtrlBase::AppendColumn(columnPtr
) &&
1092 this->m_ColumnPointers
.insert(ColumnPointerHashMapType::value_type(NewPropertyID
,columnPtr
)).second
,false,_("Could not add column to internal structures."));
1093 // create a column description and add column to the native control:
1094 wxCHECK_MSG(::InitializeColumnDescription(columnDescription
,columnPtr
,NewPropertyID
,title
),false,_("Column description could not be initialized."));
1095 wxCHECK_MSG(MacDataViewListCtrlPtr
->AddColumn(&columnDescription
,0) == noErr
, false,_("Column could not be added."));
1097 // final adjustments for the layout:
1098 wxCHECK_MSG(MacDataViewListCtrlPtr
->SetColumnWidth(NewPropertyID
,columnPtr
->GetWidth()) == noErr
,false,_("Column width could not be set."));
1100 // make sure that the data is up-to-date...
1101 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
1102 // otherwise ask the control to 'update' the data in the newly appended column:
1103 if (this->GetColumnCount() == 1)
1105 this->SetExpanderColumn(columnPtr
);
1106 this->AddChildrenLevel(wxDataViewItem());
1109 MacDataViewListCtrlPtr
->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,NewPropertyID
);
1112 } /* wxDataViewCtrl::PrependColumn(wxDataViewColumn*) */
1114 void wxDataViewCtrl::Collapse(wxDataViewItem
const& item
)
1116 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1119 MacDataViewListCtrlPtr
->CloseContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1120 } /* wxDataViewCtrl::Collapse(wxDataViewItem const&) */
1122 void wxDataViewCtrl::EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
)
1126 // variable definition and initialization:
1127 DataBrowserPropertyID propertyID
;
1128 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1130 if (columnPtr
!= NULL
)
1131 propertyID
= columnPtr
->GetPropertyID();
1133 propertyID
= kDataBrowserNoItem
;
1134 MacDataViewListCtrlPtr
->RevealItem(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),propertyID
,kDataBrowserRevealOnly
);
1136 } /* wxDataViewCtrl::EnsureVisible(wxDataViewItem const&, wxDataViewColumn const*) */
1138 void wxDataViewCtrl::Expand(wxDataViewItem
const& item
)
1140 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1143 MacDataViewListCtrlPtr
->OpenContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1144 } /* wxDataViewCtrl::Expand(wxDataViewItem const&) */
1146 wxDataViewColumn
* wxDataViewCtrl::GetSortingColumn(void) const
1148 DataBrowserPropertyID propertyID
;
1150 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1153 if (MacDataViewListCtrlPtr
->GetSortProperty(&propertyID
) == noErr
)
1154 return this->GetColumnPtr(propertyID
);
1157 } /* wxDataViewCtrl::GetSortingColumn(void) const */
1159 unsigned int wxDataViewCtrl::GetCount(void) const
1161 ItemCount noOfItems
;
1164 wxCHECK_MSG(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
)->GetItemCount(&noOfItems
) == noErr
,0,_("Could not determine number of items"));
1166 } /* wxDataViewCtrl::GetCount(void) const */
1168 wxRect
wxDataViewCtrl::GetItemRect(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
) const
1170 if (item
.IsOk() && (columnPtr
!= NULL
))
1172 // variable definition:
1174 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1176 if (MacDataViewListCtrlPtr
->GetPartBounds(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),columnPtr
->GetPropertyID(),kDataBrowserPropertyContentPart
,&MacRectangle
) == noErr
)
1178 // variable definition:
1181 ::wxMacNativeToRect(&MacRectangle
,&rectangle
);
1189 } /* wxDataViewCtrl::GetItemRect(wxDataViewItem const&, unsigned int) const */
1191 wxDataViewItem
wxDataViewCtrl::GetSelection(void) const
1193 wxArrayDataBrowserItemID itemIDs
;
1195 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1198 if (MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
) > 0)
1199 return wxDataViewItem(reinterpret_cast<void*>(itemIDs
[0]));
1201 return wxDataViewItem();
1202 } /* wxDataViewCtrl::GetSelection(void) const */
1204 int wxDataViewCtrl::GetSelections(wxDataViewItemArray
& sel
) const
1206 size_t NoOfSelectedItems
;
1208 wxArrayDataBrowserItemID itemIDs
;
1210 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1213 NoOfSelectedItems
= MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
);
1215 sel
.SetCount(NoOfSelectedItems
);
1216 for (size_t i
=0; i
<NoOfSelectedItems
; ++i
)
1217 sel
[i
] = wxDataViewItem(reinterpret_cast<void*>(itemIDs
[i
]));
1218 return static_cast<int>(NoOfSelectedItems
);
1219 } /* wxDataViewCtrl::GetSelections(wxDataViewItemArray&) const */
1221 void wxDataViewCtrl::HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const
1223 item
= wxDataViewItem();
1225 } /* wxDataViewCtrl::HitTest(wxPoint const&, wxDataViewItem&, wxDataViewColumn*&) const */
1227 bool wxDataViewCtrl::IsSelected(wxDataViewItem
const& item
) const
1229 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1232 return MacDataViewListCtrlPtr
->IsItemSelected(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1233 } /* wxDataViewCtrl::IsSelected(wxDataViewItem const&) const */
1235 void wxDataViewCtrl::SelectAll(void)
1237 DataBrowserItemID
* itemIDPtr
;
1239 Handle
handle(::NewHandle(0));
1243 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1246 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1247 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1249 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1250 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsAssign
);
1252 DisposeHandle(handle
);
1253 } /* wxDataViewCtrl::SelectAll(void) */
1255 void wxDataViewCtrl::Select(wxDataViewItem
const& item
)
1259 // variable definition and initialization:
1260 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1261 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1263 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsAdd
);
1265 } /* wxDataViewCtrl::Select(wxDataViewItem const&) */
1267 void wxDataViewCtrl::SetSelections(wxDataViewItemArray
const& sel
)
1269 size_t const NoOfSelections
= sel
.GetCount();
1271 DataBrowserItemID
* itemIDs
;
1273 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1276 itemIDs
= new DataBrowserItemID
[NoOfSelections
];
1277 for (size_t i
=0; i
<NoOfSelections
; ++i
)
1278 itemIDs
[i
] = reinterpret_cast<DataBrowserItemID
>(sel
[i
].GetID());
1279 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfSelections
,itemIDs
,kDataBrowserItemsAssign
);
1281 } /* wxDataViewCtrl::SetSelections(wxDataViewItemArray const&) */
1283 void wxDataViewCtrl::Unselect(wxDataViewItem
const& item
)
1287 // variable definition and initialization:
1288 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1289 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1291 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsRemove
);
1293 } /* wxDataViewCtrl::Unselect(wxDataViewItem const&) */
1295 void wxDataViewCtrl::UnselectAll(void)
1297 DataBrowserItemID
* itemIDPtr
;
1299 Handle
handle(::NewHandle(0));
1303 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1306 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1307 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1309 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1310 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsRemove
);
1312 DisposeHandle(handle
);
1313 } /* wxDataViewCtrl::UnselectAll(void) */
1316 void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem
const& parentItem
)
1320 wxDataViewItemArray items
;
1323 wxCHECK_RET(this->GetModel() != NULL
,_("Model pointer not initialized."));
1324 NoOfChildren
= this->GetModel()->GetChildren(parentItem
,items
);
1326 for (int i
=0; i
<NoOfChildren
; ++i
)
1327 (void) this->GetModel()->ItemAdded(parentItem
,items
[i
]);
1329 (void) this->GetModel()->ItemsAdded(parentItem
,items
);
1331 } /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
1333 wxDataViewColumn
* wxDataViewCtrl::GetColumnPtr(WXDataBrowserPropertyID propertyID
) const
1335 // variable definition:
1336 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
1338 if (Result
!= this->m_ColumnPointers
.end())
1339 return Result
->second
;
1342 } /* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID) const */
1344 // inherited methods from wxDataViewCtrlBase
1345 void wxDataViewCtrl::DoSetExpanderColumn(void)
1347 if (this->GetExpanderColumn() != NULL
)
1349 // variable definition and initialization:
1350 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1352 (void) MacDataViewListCtrlPtr
->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID());
1354 } /* wxDataViewCtrl::DoSetExpanderColumn(void) */
1356 void wxDataViewCtrl::DoSetIndent(void)
1358 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1361 (void) MacDataViewListCtrlPtr
->SetIndent(static_cast<float>(this->GetIndent()));
1362 } /* wxDataViewCtrl::DoSetIndent(void) */
1365 void wxDataViewCtrl::OnSize(wxSizeEvent
& event
)
1367 unsigned int const NoOfColumns
= this->GetColumnCount();
1370 for (unsigned int i
=0; i
<NoOfColumns
; ++i
)
1372 // variable definition and initialization:
1373 wxDataViewColumn
* dataViewColumnPtr(this->GetColumn(i
));
1375 if (dataViewColumnPtr
!= NULL
)
1377 // variable definition and initialization:
1378 wxDataViewCustomRenderer
* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer()));
1380 if (dataViewCustomRendererPtr
!= NULL
)
1381 dataViewCustomRendererPtr
->SetDC(NULL
); // reset DC because DC has changed
1385 } /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
1387 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
,wxDataViewCtrlBase
)
1389 BEGIN_EVENT_TABLE(wxDataViewCtrl
,wxDataViewCtrlBase
)
1390 EVT_SIZE(wxDataViewCtrl::OnSize
)
1394 // !wxUSE_GENERICDATAVIEWCTRL
1397 // wxUSE_DATAVIEWCTRL