1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/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/osx/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
;
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());
116 static bool InitializeColumnDescription(DataBrowserListViewColumnDesc
& columnDescription
, wxDataViewColumn
const* columnPtr
, DataBrowserPropertyID columnPropertyID
, wxCFStringRef
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
->IsReorderable())
123 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewMovableColumn
;
124 if (columnPtr
->IsResizeable())
126 columnDescription
.headerBtnDesc
.minimumWidth
= 0;
127 columnDescription
.headerBtnDesc
.maximumWidth
= 30000; // 32767 is the theoretical maximum though but 30000 looks nicer
131 columnDescription
.headerBtnDesc
.minimumWidth
= columnPtr
->GetWidth();
132 columnDescription
.headerBtnDesc
.maximumWidth
= columnPtr
->GetWidth();
134 if (columnPtr
->IsSortable())
135 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewSortableColumn
;
136 if (columnPtr
->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE
)
137 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserPropertyIsEditable
;
138 if ((columnDescription
.propertyDesc
.propertyType
== kDataBrowserCustomType
) ||
139 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserDateTimeType
) ||
140 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserIconAndTextType
) ||
141 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserTextType
))
142 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
; // enables generally the possibility to have user input for the mentioned types
143 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
144 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
146 // set header's properties:
147 columnDescription
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
148 columnDescription
.headerBtnDesc
.titleOffset
= 0;
149 columnDescription
.headerBtnDesc
.titleString
= ::CFStringCreateCopy(kCFAllocatorDefault
,title
);
150 columnDescription
.headerBtnDesc
.initialOrder
= kDataBrowserOrderIncreasing
; // choose one of the orders as "undefined" is not supported anyway (s. ControlDefs.h in the HIToolbox framework)
151 columnDescription
.headerBtnDesc
.btnFontStyle
.flags
= kControlUseFontMask
| kControlUseJustMask
;
152 switch (columnPtr
->GetAlignment())
155 case wxALIGN_CENTER_HORIZONTAL
:
156 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teCenter
;
159 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushLeft
;
162 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushRight
;
165 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
167 columnDescription
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
168 columnDescription
.headerBtnDesc
.btnFontStyle
.style
= normal
;
169 if (columnPtr
->GetBitmap().IsOk())
171 columnDescription
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
172 columnDescription
.headerBtnDesc
.btnContentInfo
.u
.iconRef
= columnPtr
->GetBitmap().GetIconRef();
176 // not text only as we otherwise could not add a bitmap later
177 // columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
178 columnDescription
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
179 columnDescription
.headerBtnDesc
.btnContentInfo
.u
.iconRef
= NULL
;
186 //-----------------------------------------------------------------------------
187 // local function pointers
188 //-----------------------------------------------------------------------------
190 DEFINE_ONE_SHOT_HANDLER_GETTER(wxMacDataViewCtrlEventHandler
)
192 // ---------------------------------------------------------
193 // wxMacDataViewModelNotifier
194 // ---------------------------------------------------------
195 class wxMacDataViewModelNotifier
: public wxDataViewModelNotifier
198 wxMacDataViewModelNotifier(wxMacDataViewDataBrowserListViewControl
* initDataViewControlPtr
) : m_dataViewControlPtr(initDataViewControlPtr
)
202 virtual bool ItemAdded(const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
204 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
206 wxCHECK_MSG(item
.IsOk(),false,_("Added item is invalid."));
207 bool noFailureFlag
= (!(parent
.IsOk()) && (m_dataViewControlPtr
->AddItem(kDataBrowserNoItem
,&itemID
) == noErr
) ||
208 parent
.IsOk() && (m_dataViewControlPtr
->AddItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
) == noErr
));
210 wxDataViewCtrl
*dvc
= (wxDataViewCtrl
*) m_dataViewControlPtr
->GetWXPeer();
211 if (dvc
->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
213 wxDataViewModel
*model
= GetOwner();
215 int height
= 20; // TODO find out standard height
216 unsigned int num
= dvc
->GetColumnCount();
218 for (col
= 0; col
< num
; col
++)
220 wxDataViewColumn
*column
= dvc
->GetColumn( col
);
221 if (column
->IsHidden())
224 wxDataViewCustomRenderer
*renderer
= wxDynamicCast( column
->GetRenderer(), wxDataViewCustomRenderer
);
228 model
->GetValue( value
, item
, column
->GetModelColumn() );
229 renderer
->SetValue( value
);
230 height
= wxMax( height
, renderer
->GetSize().y
);
236 m_dataViewControlPtr
->SetRowHeight( itemID
, height
);
239 return noFailureFlag
;
242 virtual bool ItemsAdded(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
246 DataBrowserItemID
* itemIDs
;
251 // convert all valid data view items to data browser items:
252 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
253 // insert all valid items into control:
254 noFailureFlag
= ((noOfEntries
== 0) ||
255 !(parent
.IsOk()) && (m_dataViewControlPtr
->AddItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
) ||
256 parent
.IsOk() && (m_dataViewControlPtr
->AddItems(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
));
257 // give allocated array space free again:
260 wxDataViewCtrl
*dvc
= (wxDataViewCtrl
*) m_dataViewControlPtr
->GetWXPeer();
261 if (dvc
->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
263 wxDataViewModel
*model
= GetOwner();
264 unsigned int colnum
= dvc
->GetColumnCount();
267 size_t count
= items
.GetCount();
268 for (i
= 0; i
< count
; i
++)
270 wxDataViewItem item
= items
[i
];
271 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
273 int height
= 20; // TODO find out standard height
275 for (col
= 0; col
< colnum
; col
++)
277 wxDataViewColumn
*column
= dvc
->GetColumn( col
);
278 if (column
->IsHidden())
279 continue; // skip it!
281 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
282 continue; // skip it!
284 wxDataViewCustomRenderer
*renderer
= wxDynamicCast( column
->GetRenderer(), wxDataViewCustomRenderer
);
288 model
->GetValue( value
, item
, column
->GetModelColumn() );
289 renderer
->SetValue( value
);
290 height
= wxMax( height
, renderer
->GetSize().y
);
295 m_dataViewControlPtr
->SetRowHeight( itemID
, height
);
300 return noFailureFlag
;
303 virtual bool ItemChanged(wxDataViewItem
const& item
)
305 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
308 wxCHECK_MSG(item
.IsOk(),false,_("Changed item is invalid."));
309 if (m_dataViewControlPtr
->UpdateItems(&itemID
) == noErr
)
311 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(m_dataViewControlPtr
->GetWXPeer()));
313 // sent the equivalent wxWidget event:
314 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId());
316 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
317 dataViewEvent
.SetItem(item
);
318 // sent the equivalent wxWidget event:
319 dataViewCtrlPtr
->HandleWindowEvent(dataViewEvent
);
327 virtual bool ItemsChanged(wxDataViewItemArray
const& items
)
331 DataBrowserItemID
* itemIDs
;
336 // convert all valid data view items to data browser items:
337 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
338 // change items (ATTENTION: ONLY ITEMS OF THE ROOT ARE CHANGED BECAUSE THE PARENT PARAMETER IS MISSING):
339 noFailureFlag
= (m_dataViewControlPtr
->UpdateItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
,kDataBrowserItemNoProperty
) == noErr
);
342 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(m_dataViewControlPtr
->GetWXPeer()));
344 // send for all changed items a wxWidget event:
345 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId());
347 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
348 for (size_t i
=0; i
<noOfEntries
; ++i
)
350 dataViewEvent
.SetItem(reinterpret_cast<void*>(itemIDs
[i
]));
351 dataViewCtrlPtr
->HandleWindowEvent(dataViewEvent
);
354 // release allocated array space:
357 return noFailureFlag
;
360 virtual bool ItemDeleted(wxDataViewItem
const& parent
, wxDataViewItem
const& item
)
364 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
365 OSStatus errorStatus
;
366 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(m_dataViewControlPtr
->GetWXPeer()));
368 // 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
369 // not to be identical because the being edited item might be below the passed item in the hierarchy);
370 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
371 // has been started and that variables can currently not be updated even when requested by the system:
372 dataViewCtrlPtr
->SetDeleting(true);
373 errorStatus
= m_dataViewControlPtr
->RemoveItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
);
374 // enable automatic updating again:
375 dataViewCtrlPtr
->SetDeleting(false);
376 return (errorStatus
== noErr
);
382 virtual bool ItemsDeleted(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
386 DataBrowserItemID
* itemIDs
;
388 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(m_dataViewControlPtr
->GetWXPeer()));
393 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,false,_("Data view control is not correctly initialized"));
394 // convert all valid data view items to data browser items:
395 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
396 // 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
397 // not to be identical because the being edited item might be below the passed item in the hierarchy);
398 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
399 // has been started and that variables can currently not be updated even when requested by the system:
400 dataViewCtrlPtr
->SetDeleting(true);
401 // insert all valid items into control:
402 noFailureFlag
= ((noOfEntries
== 0) ||
403 !(parent
.IsOk()) && (m_dataViewControlPtr
->RemoveItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
) ||
404 parent
.IsOk() && (m_dataViewControlPtr
->RemoveItems(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
));
405 // enable automatic updating again:
406 dataViewCtrlPtr
->SetDeleting(false);
407 // give allocated array space free again:
410 return noFailureFlag
;
413 virtual bool ValueChanged(wxDataViewItem
const& item
, unsigned int col
)
415 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
416 DataBrowserItemID parentID
;
418 DataBrowserPropertyID propertyID
;
420 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(m_dataViewControlPtr
->GetWXPeer()));
423 wxCHECK_MSG(item
.IsOk(), false,_("Passed item is invalid."));
424 wxCHECK_MSG(this->GetOwner() != NULL
,false,_("Owner not initialized."));
425 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Control is wrongly initialized."));
426 parentID
= reinterpret_cast<DataBrowserItemID
>(this->GetOwner()->GetParent(item
).GetID());
427 if ((m_dataViewControlPtr
->GetPropertyID(col
,&propertyID
) == noErr
) &&
428 (m_dataViewControlPtr
->UpdateItems(parentID
,1,&itemID
,dataViewCtrlPtr
->GetColumn(col
)->GetPropertyID(),propertyID
) == noErr
))
430 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId());
432 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
433 dataViewEvent
.SetColumn(col
);
434 dataViewEvent
.SetItem(item
);
435 // send the equivalent wxWidget event:
436 dataViewCtrlPtr
->HandleWindowEvent(dataViewEvent
);
444 virtual bool Cleared()
446 bool noFailureFlag
= (m_dataViewControlPtr
->RemoveItems() == noErr
);
448 wxDataViewItemArray array
;
449 GetOwner()->GetChildren( item
, array
);
450 ItemsAdded( item
, array
);
451 m_dataViewControlPtr
->SetScrollPosition(0, 0);
452 return noFailureFlag
;
455 virtual void Resort()
457 m_dataViewControlPtr
->Resort();
461 wxMacDataViewDataBrowserListViewControl
* m_dataViewControlPtr
;
464 // ---------------------------------------------------------
465 // wxDataViewRenderer
466 // ---------------------------------------------------------
467 wxDataViewRenderer::wxDataViewRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
468 :wxDataViewRendererBase(varianttype
,mode
,align
), m_alignment(align
), m_mode(mode
)
472 void wxDataViewRenderer::SetMode(wxDataViewCellMode mode
)
474 wxDataViewColumn
* dataViewColumnPtr
;
478 dataViewColumnPtr
= this->GetOwner();
479 if (dataViewColumnPtr
!= NULL
)
481 wxDataViewCtrl
* dataViewCtrlPtr(dataViewColumnPtr
->GetOwner());
483 if (dataViewCtrlPtr
!= NULL
)
485 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
487 if (macDataViewListCtrlPtr
!= NULL
)
489 DataBrowserPropertyFlags flags
;
491 verify_noerr(macDataViewListCtrlPtr
->GetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),&flags
));
492 if (mode
== wxDATAVIEW_CELL_EDITABLE
)
493 flags
|= kDataBrowserPropertyIsEditable
;
495 flags
&= ~kDataBrowserPropertyIsEditable
;
496 verify_noerr(macDataViewListCtrlPtr
->SetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),flags
));
502 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
,wxDataViewRendererBase
)
504 // ---------------------------------------------------------
505 // wxDataViewCustomRenderer
506 // ---------------------------------------------------------
507 wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
508 :wxDataViewRenderer(varianttype
,mode
,align
), m_editorCtrlPtr(NULL
), m_DCPtr(NULL
)
512 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
517 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
)
519 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
520 // wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) : view->GetForegroundColour();
521 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ? *wxWHITE
: view
->GetForegroundColour();
522 dc
->SetTextForeground(col
);
523 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
526 wxDC
* wxDataViewCustomRenderer::GetDC()
530 if ((GetOwner() == NULL
) || (GetOwner()->GetOwner() == NULL
))
532 m_DCPtr
= new wxWindowDC(this->GetOwner()->GetOwner());
537 bool wxDataViewCustomRenderer::Render()
542 void wxDataViewCustomRenderer::SetDC(wxDC
* newDCPtr
)
548 WXDataBrowserPropertyType
wxDataViewCustomRenderer::GetPropertyType() const
550 return kDataBrowserCustomType
;
553 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
555 // ---------------------------------------------------------
556 // wxDataViewTextRenderer
557 // ---------------------------------------------------------
558 wxDataViewTextRenderer::wxDataViewTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
559 :wxDataViewRenderer(varianttype
,mode
,align
)
563 bool wxDataViewTextRenderer::Render()
565 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Text renderer cannot render value; value type: ")) << this->GetValue().GetType());
567 wxCFStringRef
cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
568 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
);
571 WXDataBrowserPropertyType
wxDataViewTextRenderer::GetPropertyType() const
573 return kDataBrowserTextType
;
576 IMPLEMENT_CLASS(wxDataViewTextRenderer
,wxDataViewRenderer
)
578 // ---------------------------------------------------------
579 // wxDataViewTextRendererAttr
580 // ---------------------------------------------------------
581 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
582 :wxDataViewTextRenderer(varianttype
,mode
,align
)
586 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
,wxDataViewTextRenderer
)
588 // ---------------------------------------------------------
589 // wxDataViewBitmapRenderer
590 // ---------------------------------------------------------
591 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
592 :wxDataViewRenderer(varianttype
,mode
,align
)
596 bool wxDataViewBitmapRenderer::Render()
597 // This method returns 'true' if
598 // - the passed bitmap is valid and it could be assigned to the native data browser;
599 // - the passed bitmap is invalid (or is not initialized); this case simulates a non-existing bitmap.
600 // In all other cases the method returns 'false'.
602 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Bitmap renderer cannot render value; value type: ")) << this->GetValue().GetType());
606 bitmap
<< this->GetValue();
608 return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap
.GetIconRef()) == noErr
);
613 WXDataBrowserPropertyType
wxDataViewBitmapRenderer::GetPropertyType() const
615 return kDataBrowserIconType
;
618 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
,wxDataViewRenderer
)
620 // ---------------------------------------------------------
621 // wxDataViewIconTextRenderer
622 // ---------------------------------------------------------
623 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
624 :wxDataViewRenderer(varianttype
,mode
)
628 bool wxDataViewIconTextRenderer::Render()
630 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Icon & text renderer cannot render value; value type: ")) << this->GetValue().GetType());
632 wxDataViewIconText iconText
;
634 iconText
<< this->GetValue();
636 wxCFStringRef
cfString(iconText
.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
638 if (iconText
.GetIcon().IsOk())
639 if (::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText
.GetIcon().GetHICON())) != noErr
)
641 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
);
644 WXDataBrowserPropertyType
wxDataViewIconTextRenderer::GetPropertyType() const
646 return kDataBrowserIconAndTextType
;
649 IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer
,wxDataViewRenderer
)
652 // ---------------------------------------------------------
653 // wxDataViewToggleRenderer
654 // ---------------------------------------------------------
655 wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
656 :wxDataViewRenderer(varianttype
,mode
)
660 bool wxDataViewToggleRenderer::Render()
662 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Toggle renderer cannot render value; value type: ")) << this->GetValue().GetType());
663 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr
);
666 WXDataBrowserPropertyType
wxDataViewToggleRenderer::GetPropertyType() const
668 return kDataBrowserCheckboxType
;
671 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
,wxDataViewRenderer
)
673 // ---------------------------------------------------------
674 // wxDataViewProgressRenderer
675 // ---------------------------------------------------------
676 wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString
const& label
, wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
677 :wxDataViewRenderer(varianttype
,mode
,align
)
681 bool wxDataViewProgressRenderer::Render()
683 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Progress renderer cannot render value type; value type: ")) << this->GetValue().GetType());
684 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr
) &&
685 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr
) &&
686 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr
));
689 WXDataBrowserPropertyType
wxDataViewProgressRenderer::GetPropertyType() const
691 return kDataBrowserProgressBarType
;
694 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
,wxDataViewRenderer
)
696 // ---------------------------------------------------------
697 // wxDataViewDateRenderer
698 // ---------------------------------------------------------
699 wxDataViewDateRenderer::wxDataViewDateRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
700 :wxDataViewRenderer(varianttype
,mode
,align
)
704 bool wxDataViewDateRenderer::Render()
706 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Date renderer cannot render value; value type: ")) << this->GetValue().GetType());
707 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan
,1904)).GetSeconds().GetLo()) == noErr
);
710 WXDataBrowserPropertyType
wxDataViewDateRenderer::GetPropertyType() const
712 return kDataBrowserDateTimeType
;
715 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
,wxDataViewRenderer
)
717 // ---------------------------------------------------------
719 // ---------------------------------------------------------
721 void wxDataViewColumn::SetAlignment(wxAlignment align
)
723 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
727 if (dataViewCtrlPtr
!= NULL
)
729 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
731 if (macDataViewListCtrlPtr
!= NULL
)
733 DataBrowserListViewHeaderDesc headerDescription
;
735 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
739 case wxALIGN_CENTER_HORIZONTAL
:
740 headerDescription
.btnFontStyle
.just
= teCenter
;
743 headerDescription
.btnFontStyle
.just
= teFlushLeft
;
746 headerDescription
.btnFontStyle
.just
= teFlushRight
;
749 headerDescription
.btnFontStyle
.just
= teFlushDefault
;
751 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set alignment."));
756 void wxDataViewColumn::SetBitmap(wxBitmap
const& bitmap
)
758 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
761 wxDataViewColumnBase::SetBitmap(bitmap
);
762 if (dataViewCtrlPtr
!= NULL
)
764 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
766 if (macDataViewListCtrlPtr
!= NULL
)
768 DataBrowserListViewHeaderDesc headerDescription
;
770 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
771 if (this->GetBitmap().Ok())
772 headerDescription
.btnContentInfo
.u
.iconRef
= this->GetBitmap().GetIconRef();
774 headerDescription
.btnContentInfo
.u
.iconRef
= NULL
;
775 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set icon."));
780 void wxDataViewColumn::SetMaxWidth(int maxWidth
)
782 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
785 m_maxWidth
= maxWidth
;
786 if (dataViewCtrlPtr
!= NULL
)
788 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
790 if (macDataViewListCtrlPtr
!= NULL
)
792 DataBrowserListViewHeaderDesc headerDescription
;
794 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
795 headerDescription
.maximumWidth
= static_cast<UInt16
>(maxWidth
);
796 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set maximum width."));
801 void wxDataViewColumn::SetMinWidth(int minWidth
)
803 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
806 m_minWidth
= minWidth
;
807 if (dataViewCtrlPtr
!= NULL
)
809 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
811 if (macDataViewListCtrlPtr
!= NULL
)
813 DataBrowserListViewHeaderDesc headerDescription
;
815 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
816 headerDescription
.minimumWidth
= static_cast<UInt16
>(minWidth
);
817 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set minimum width."));
822 void wxDataViewColumn::SetReorderable(bool reorderable
)
824 // first set the internal flag of the column:
826 m_flags
|= wxDATAVIEW_COL_REORDERABLE
;
828 m_flags
&= ~wxDATAVIEW_COL_REORDERABLE
;
829 // if the column is associated with a control change also immediately the flags of the control:
830 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
832 if (dataViewCtrlPtr
!= NULL
)
834 DataBrowserPropertyFlags flags
;
835 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
837 wxCHECK_RET(macDataViewListCtrlPtr
!= NULL
, _("Valid pointer to native data view control does not exist"));
838 wxCHECK_RET(macDataViewListCtrlPtr
->GetPropertyFlags(this->GetPropertyID(),&flags
) == noErr
,_("Could not get property flags."));
840 flags
|= kDataBrowserListViewMovableColumn
;
842 flags
&= ~kDataBrowserListViewMovableColumn
;
843 wxCHECK_RET(macDataViewListCtrlPtr
->SetPropertyFlags(this->GetPropertyID(),flags
) == noErr
,_("Could not set property flags."));
847 void wxDataViewColumn::SetResizeable(bool resizeable
)
849 // first set the internal flag of the column:
851 m_flags
|= wxDATAVIEW_COL_RESIZABLE
;
853 m_flags
&= ~wxDATAVIEW_COL_RESIZABLE
;
854 // if the column is associated with a control change also immediately the flags of the control:
855 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
857 if (dataViewCtrlPtr
!= NULL
)
859 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
861 if (macDataViewListCtrlPtr
!= NULL
)
863 DataBrowserListViewHeaderDesc headerDescription
;
865 verify_noerr(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
));
867 headerDescription
.minimumWidth
= 0;
868 headerDescription
.maximumWidth
= 30000;
871 headerDescription
.minimumWidth
= m_width
;
872 headerDescription
.maximumWidth
= m_width
;
874 verify_noerr(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
));
875 macDataViewListCtrlPtr
->SetSortProperty(this->GetPropertyID());
880 void wxDataViewColumn::SetSortable(bool sortable
)
882 // first set the internal flag of the column:
884 m_flags
|= wxDATAVIEW_COL_SORTABLE
;
886 m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
887 // if the column is associated with a control change also immediately the flags of the control:
888 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
890 if (dataViewCtrlPtr
!= NULL
)
892 DataBrowserPropertyFlags flags
;
893 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
895 wxCHECK_RET(macDataViewListCtrlPtr
!= NULL
, _("Valid pointer to native data view control does not exist"));
896 wxCHECK_RET(macDataViewListCtrlPtr
->GetPropertyFlags(this->GetPropertyID(),&flags
) == noErr
,_("Could not get property flags."));
898 flags
|= kDataBrowserListViewSortableColumn
;
900 flags
&= ~kDataBrowserListViewSortableColumn
;
901 wxCHECK_RET(macDataViewListCtrlPtr
->SetPropertyFlags(this->GetPropertyID(),flags
) == noErr
,_("Could not set property flags."));
905 void wxDataViewColumn::SetSortOrder(bool ascending
)
907 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
910 m_ascending
= ascending
;
911 if (dataViewCtrlPtr
!= NULL
)
913 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
915 if (macDataViewListCtrlPtr
!= NULL
)
917 DataBrowserListViewHeaderDesc headerDescription
;
919 verify_noerr(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
));
921 headerDescription
.initialOrder
= kDataBrowserOrderIncreasing
;
923 headerDescription
.initialOrder
= kDataBrowserOrderDecreasing
;
924 verify_noerr(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
));
925 macDataViewListCtrlPtr
->SetSortProperty(this->GetPropertyID());
930 void wxDataViewColumn::SetTitle(wxString
const& title
)
932 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
936 if (dataViewCtrlPtr
!= NULL
)
938 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
940 if (macDataViewListCtrlPtr
!= NULL
)
942 DataBrowserListViewHeaderDesc headerDescription
;
943 wxCFStringRef
cfTitle(title
,(dataViewCtrlPtr
->GetFont().Ok() ? dataViewCtrlPtr
->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
945 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
946 headerDescription
.titleString
= cfTitle
;
947 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set header description."));
952 void wxDataViewColumn::SetWidth(int width
)
954 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
957 if ((width
>= m_minWidth
) && (width
<= m_maxWidth
))
960 if (dataViewCtrlPtr
!= NULL
)
962 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
964 if (macDataViewListCtrlPtr
!= NULL
)
965 wxCHECK_RET(macDataViewListCtrlPtr
->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16
>(width
)) == noErr
,_("Could not set column width."));
970 void wxDataViewColumn::SetAsSortKey(bool WXUNUSED(sort
))
972 // see wxGTK native wxDataViewColumn implementation
973 wxFAIL_MSG( "not implemented" );
976 bool wxDataViewColumn::IsSortKey() const
978 wxDataViewCtrl
* const dataViewCtrlPtr(GetOwner());
979 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(
980 dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(
981 dataViewCtrlPtr
->GetPeer()));
983 DataBrowserPropertyID propertyID
;
984 return macDataViewListCtrlPtr
->GetSortProperty(&propertyID
) == noErr
&&
985 propertyID
== m_propertyID
;
988 //-----------------------------------------------------------------------------
990 //-----------------------------------------------------------------------------
993 wxDataViewCtrl::~wxDataViewCtrl()
998 void wxDataViewCtrl::Init()
1000 m_CustomRendererPtr
= NULL
;
1002 m_macIsUserPane
= false;
1006 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1008 if (!(this->wxControl::Create(parent
,id
,pos
,size
,style
& ~(wxHSCROLL
| wxVSCROLL
),validator
)))
1012 MacSetClipChildren(true) ;
1015 m_peer
= new wxMacDataViewDataBrowserListViewControl(this,pos
,size
,style
);
1017 if ( style
& wxBORDER_NONE
)
1018 m_peer
->SetData( kControlNoPart
, kControlDataBrowserIncludesFrameAndFocusTag
, (Boolean
) false ) ;
1020 this->MacPostControlCreate(pos
,size
);
1021 ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(m_peer
->GetControlRef()),true);
1023 InstallControlEventHandler(m_peer
->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList
),eventList
,this,NULL
);
1025 ::SetDataBrowserTableViewHiliteStyle( m_peer
->GetControlRef(), kDataBrowserTableViewFillHilite
);
1031 wxVisualAttributes
wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
1033 wxVisualAttributes attr
;
1035 attr
.colFg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1036 attr
.colBg
= wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
);
1037 attr
.font
.MacCreateFromThemeFont(kThemeViewsFont
);
1042 bool wxDataViewCtrl::AssociateModel(wxDataViewModel
* model
)
1044 if (!wxDataViewCtrlBase::AssociateModel(model
))
1047 model
->AddNotifier(new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl
*>(m_peer
)));
1052 bool wxDataViewCtrl::AppendColumn(wxDataViewColumn
* columnPtr
)
1054 return InsertColumn( kDataBrowserListViewAppendColumn
, columnPtr
);
1057 bool wxDataViewCtrl::PrependColumn(wxDataViewColumn
* columnPtr
)
1059 return InsertColumn( 0, columnPtr
);
1062 bool wxDataViewCtrl::InsertColumn(unsigned int pos
, wxDataViewColumn
* columnPtr
)
1064 DataBrowserListViewColumnDesc columnDescription
;
1066 DataBrowserPropertyID NewPropertyID
;
1068 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1070 wxCFStringRef
title(columnPtr
->GetTitle(),m_font
.Ok() ? this->GetFont().GetEncoding() : wxLocale::GetSystemEncoding());
1073 // first, some error checking:
1074 wxCHECK_MSG(MacDataViewListCtrlPtr
!= NULL
, false,_("m_peer is not or incorrectly initialized"));
1075 wxCHECK_MSG(columnPtr
!= NULL
, false,_("Column pointer must not be NULL."));
1076 wxCHECK_MSG(columnPtr
->GetRenderer() != NULL
, false,_("Column does not have a renderer."));
1077 wxCHECK_MSG(this->GetModel() != NULL
, false,_("No model associated with control."));
1078 wxCHECK_MSG((columnPtr
->GetModelColumn() >= 0) &&
1079 (columnPtr
->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
1081 // try to get new ID for the column:
1082 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetFreePropertyID(&NewPropertyID
) == noErr
,false,_("Cannot create new column's ID. Probably max. number of columns reached."));
1083 // full column variable initialization:
1084 columnPtr
->SetPropertyID(NewPropertyID
);
1085 // add column to wxWidget's internal structure:
1086 wxCHECK_MSG(this->wxDataViewCtrlBase::AppendColumn(columnPtr
) &&
1087 m_ColumnPointers
.insert(ColumnPointerHashMapType::value_type(NewPropertyID
,columnPtr
)).second
,false,_("Could not add column to internal structures."));
1088 // create a column description and add column to the native control:
1089 wxCHECK_MSG(::InitializeColumnDescription(columnDescription
,columnPtr
,NewPropertyID
,title
), false,_("Column description could not be initialized."));
1090 wxCHECK_MSG(MacDataViewListCtrlPtr
->AddColumn(&columnDescription
,pos
) == noErr
,false,_("Column could not be added."));
1092 // final adjustments for the layout:
1093 wxCHECK_MSG(MacDataViewListCtrlPtr
->SetColumnWidth(NewPropertyID
,columnPtr
->GetWidth()) == noErr
,false,_("Column width could not be set."));
1095 // make sure that the data is up-to-date...
1096 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
1097 // otherwise ask the control to 'update' the data in the newly appended column:
1098 if (this->GetColumnCount() == 1)
1100 this->SetExpanderColumn(columnPtr
);
1101 this->AddChildrenLevel(wxDataViewItem());
1104 MacDataViewListCtrlPtr
->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,NewPropertyID
);
1109 bool wxDataViewCtrl::ClearColumns()
1111 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1114 while (m_ColumnPointers
.begin() != m_ColumnPointers
.end())
1116 wxCHECK_MSG(MacDataViewListCtrlPtr
->RemoveColumnByProperty(m_ColumnPointers
.begin()->first
) == noErr
,false,_("Could not remove column."));
1117 delete m_ColumnPointers
.begin()->second
;
1118 m_ColumnPointers
.erase(m_ColumnPointers
.begin());
1123 bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn
* columnPtr
)
1125 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1128 if ((MacDataViewListCtrlPtr
->RemoveColumnByProperty(columnPtr
->GetPropertyID()) == noErr
) && (m_ColumnPointers
.erase(columnPtr
->GetPropertyID()) > 0))
1137 wxDataViewColumn
* wxDataViewCtrl::GetColumn(unsigned int pos
) const
1139 DataBrowserPropertyID propertyID
;
1141 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1144 if (MacDataViewListCtrlPtr
->GetPropertyID(pos
,&propertyID
) == noErr
)
1146 ColumnPointerHashMapType::const_iterator
Result(m_ColumnPointers
.find(propertyID
));
1148 if (Result
!= m_ColumnPointers
.end())
1149 return Result
->second
;
1157 unsigned int wxDataViewCtrl::GetColumnCount() const
1159 return m_ColumnPointers
.size();
1162 int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn
const* columnPtr
) const
1164 if (columnPtr
!= NULL
)
1166 DataBrowserTableViewColumnIndex Position
;
1167 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1169 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetColumnIndex(columnPtr
->GetPropertyID(),&Position
) == noErr
,-1,_("Could not determine column's position"));
1170 return static_cast<int>(Position
);
1176 void wxDataViewCtrl::Collapse(wxDataViewItem
const& item
)
1178 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1181 MacDataViewListCtrlPtr
->CloseContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1184 void wxDataViewCtrl::EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
)
1186 ExpandAncestors(item
);
1190 DataBrowserPropertyID propertyID
;
1191 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1193 if (columnPtr
!= NULL
)
1194 propertyID
= columnPtr
->GetPropertyID();
1196 propertyID
= kDataBrowserNoItem
;
1197 MacDataViewListCtrlPtr
->RevealItem(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),propertyID
,kDataBrowserRevealOnly
);
1201 void wxDataViewCtrl::Expand(wxDataViewItem
const& item
)
1203 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1206 MacDataViewListCtrlPtr
->OpenContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1209 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
1213 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1215 DataBrowserItemState state
= 0;
1216 OSStatus err
= ::GetDataBrowserItemState(
1217 MacDataViewListCtrlPtr
->GetControlRef(),
1218 reinterpret_cast<DataBrowserItemID
>(item
.GetID()),
1220 if ((err
== 0) && (state
& kDataBrowserContainerIsOpen
))
1226 wxDataViewColumn
* wxDataViewCtrl::GetSortingColumn() const
1228 DataBrowserPropertyID propertyID
;
1230 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1233 if (MacDataViewListCtrlPtr
->GetSortProperty(&propertyID
) == noErr
)
1234 return this->GetColumnPtr(propertyID
);
1239 unsigned int wxDataViewCtrl::GetCount() const
1241 ItemCount noOfItems
;
1244 wxCHECK_MSG(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
)->GetItemCount(&noOfItems
) == noErr
,0,_("Could not determine number of items"));
1248 wxRect
wxDataViewCtrl::GetItemRect(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
) const
1250 if (item
.IsOk() && (columnPtr
!= NULL
))
1253 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1255 if (MacDataViewListCtrlPtr
->GetPartBounds(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),columnPtr
->GetPropertyID(),kDataBrowserPropertyContentPart
,&MacRectangle
) == noErr
)
1259 ::wxMacNativeToRect(&MacRectangle
,&rectangle
);
1269 wxDataViewItem
wxDataViewCtrl::GetSelection() const
1271 wxArrayDataBrowserItemID itemIDs
;
1273 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1276 if (MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
) > 0)
1277 return wxDataViewItem(reinterpret_cast<void*>(itemIDs
[0]));
1279 return wxDataViewItem();
1282 int wxDataViewCtrl::GetSelections(wxDataViewItemArray
& sel
) const
1284 size_t NoOfSelectedItems
;
1286 wxArrayDataBrowserItemID itemIDs
;
1288 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1291 NoOfSelectedItems
= MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
);
1293 sel
.SetCount(NoOfSelectedItems
);
1294 for (size_t i
=0; i
<NoOfSelectedItems
; ++i
)
1295 sel
[i
] = wxDataViewItem(reinterpret_cast<void*>(itemIDs
[i
]));
1296 return static_cast<int>(NoOfSelectedItems
);
1299 void wxDataViewCtrl::HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const
1301 item
= wxDataViewItem();
1305 bool wxDataViewCtrl::IsSelected(wxDataViewItem
const& item
) const
1307 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1310 return MacDataViewListCtrlPtr
->IsItemSelected(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1313 void wxDataViewCtrl::SelectAll()
1315 DataBrowserItemID
* itemIDPtr
;
1317 Handle
handle(::NewHandle(0));
1321 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1324 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1325 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1327 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1328 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsAssign
);
1330 DisposeHandle(handle
);
1333 void wxDataViewCtrl::Select(wxDataViewItem
const& item
)
1337 ExpandAncestors(item
);
1339 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1340 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1342 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsAdd
);
1346 void wxDataViewCtrl::SetSelections(wxDataViewItemArray
const& sel
)
1348 size_t const NoOfSelections
= sel
.GetCount();
1350 wxDataViewItem last_parent
;
1353 for (i
= 0; i
< NoOfSelections
; i
++)
1355 wxDataViewItem item
= sel
[i
];
1356 wxDataViewItem parent
= GetModel()->GetParent( item
);
1359 if (parent
!= last_parent
)
1360 ExpandAncestors(item
);
1362 last_parent
= parent
;
1365 DataBrowserItemID
* itemIDs
;
1366 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1368 itemIDs
= new DataBrowserItemID
[NoOfSelections
];
1369 for (i
=0; i
<NoOfSelections
; ++i
)
1370 itemIDs
[i
] = reinterpret_cast<DataBrowserItemID
>(sel
[i
].GetID());
1371 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfSelections
,itemIDs
,kDataBrowserItemsAssign
);
1375 void wxDataViewCtrl::Unselect(wxDataViewItem
const& item
)
1379 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1380 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1382 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsRemove
);
1386 void wxDataViewCtrl::UnselectAll()
1388 DataBrowserItemID
* itemIDPtr
;
1390 Handle
handle(::NewHandle(0));
1394 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1397 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1398 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1400 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1401 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsRemove
);
1403 DisposeHandle(handle
);
1407 void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem
const& parentItem
)
1411 wxDataViewItemArray items
;
1414 wxCHECK_RET(this->GetModel() != NULL
,_("Model pointer not initialized."));
1415 NoOfChildren
= this->GetModel()->GetChildren(parentItem
,items
);
1417 for (int i
=0; i
<NoOfChildren
; ++i
)
1418 (void) this->GetModel()->ItemAdded(parentItem
,items
[i
]);
1420 (void) this->GetModel()->ItemsAdded(parentItem
,items
);
1424 void wxDataViewCtrl::FinishCustomItemEditing()
1426 if (this->GetCustomRendererItem().IsOk())
1428 this->GetCustomRendererPtr()->FinishEditing();
1429 this->SetCustomRendererItem(wxDataViewItem());
1430 this->SetCustomRendererPtr (NULL
);
1434 wxDataViewColumn
* wxDataViewCtrl::GetColumnPtr(WXDataBrowserPropertyID propertyID
) const
1436 ColumnPointerHashMapType::const_iterator
Result(m_ColumnPointers
.find(propertyID
));
1438 if (Result
!= m_ColumnPointers
.end())
1439 return Result
->second
;
1444 // inherited methods from wxDataViewCtrlBase
1445 void wxDataViewCtrl::DoSetExpanderColumn()
1447 if (this->GetExpanderColumn() != NULL
)
1449 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1451 (void) MacDataViewListCtrlPtr
->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID(),false); // second parameter explicitely passed to ensure that arrow is centered
1455 void wxDataViewCtrl::DoSetIndent()
1457 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1459 (void) MacDataViewListCtrlPtr
->SetIndent(static_cast<float>(this->GetIndent()));
1463 void wxDataViewCtrl::OnSize(wxSizeEvent
& event
)
1465 unsigned int const NoOfColumns
= this->GetColumnCount();
1468 for (unsigned int i
=0; i
<NoOfColumns
; ++i
)
1470 wxDataViewColumn
* dataViewColumnPtr(this->GetColumn(i
));
1472 if (dataViewColumnPtr
!= NULL
)
1474 wxDataViewCustomRenderer
* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer()));
1476 if (dataViewCustomRendererPtr
!= NULL
)
1477 dataViewCustomRendererPtr
->SetDC(NULL
); // reset DC because DC has changed
1481 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1482 ControlRef ref
= MacDataViewListCtrlPtr
->GetControlRef();
1483 if (NoOfColumns
== 1)
1485 ::SetDataBrowserHasScrollBars( ref
, false, true );
1486 ::AutoSizeDataBrowserListViewColumns( ref
);
1488 if (NoOfColumns
> 1)
1490 ::SetDataBrowserHasScrollBars( ref
, true, true );
1496 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
,wxDataViewCtrlBase
)
1498 BEGIN_EVENT_TABLE(wxDataViewCtrl
,wxDataViewCtrlBase
)
1499 EVT_SIZE(wxDataViewCtrl::OnSize
)
1502 #endif // !wxUSE_GENERICDATAVIEWCTRL
1504 #endif // wxUSE_DATAVIEWCTRL