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 (columnPtr
->GetRenderer()->GetMode() == wxDATAVIEW_CELL_ACTIVATABLE
))
138 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserPropertyIsEditable
;
139 if ((columnDescription
.propertyDesc
.propertyType
== kDataBrowserCustomType
) ||
140 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserDateTimeType
) ||
141 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserIconAndTextType
) ||
142 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserTextType
))
143 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
; // enables generally the possibility to have user input for the mentioned types
144 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
145 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
147 // set header's properties:
148 columnDescription
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
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 if (columnPtr
->GetBitmap().IsOk())
172 columnDescription
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
173 columnDescription
.headerBtnDesc
.btnContentInfo
.u
.iconRef
= columnPtr
->GetBitmap().GetIconRef();
177 // not text only as we otherwise could not add a bitmap later
178 // columnDescription.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
179 columnDescription
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
180 columnDescription
.headerBtnDesc
.btnContentInfo
.u
.iconRef
= NULL
;
187 //-----------------------------------------------------------------------------
188 // local function pointers
189 //-----------------------------------------------------------------------------
191 DEFINE_ONE_SHOT_HANDLER_GETTER(wxMacDataViewCtrlEventHandler
)
193 // ---------------------------------------------------------
194 // wxMacDataViewModelNotifier
195 // ---------------------------------------------------------
196 class wxMacDataViewModelNotifier
: public wxDataViewModelNotifier
199 wxMacDataViewModelNotifier(wxMacDataViewDataBrowserListViewControl
* initDataViewControlPtr
) : m_dataViewControlPtr(initDataViewControlPtr
)
203 virtual bool ItemAdded(const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
205 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
207 wxCHECK_MSG(item
.IsOk(),false,_("Added item is invalid."));
208 bool noFailureFlag
= (!(parent
.IsOk()) && (m_dataViewControlPtr
->AddItem(kDataBrowserNoItem
,&itemID
) == noErr
) ||
209 parent
.IsOk() && (m_dataViewControlPtr
->AddItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
) == noErr
));
211 wxDataViewCtrl
*dvc
= (wxDataViewCtrl
*) m_dataViewControlPtr
->GetWXPeer();
212 if (dvc
->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
214 wxDataViewModel
*model
= GetOwner();
216 int height
= 20; // TODO find out standard height
217 unsigned int num
= dvc
->GetColumnCount();
219 for (col
= 0; col
< num
; col
++)
221 wxDataViewColumn
*column
= dvc
->GetColumn( col
);
222 if (column
->IsHidden())
225 wxDataViewCustomRenderer
*renderer
= wxDynamicCast( column
->GetRenderer(), wxDataViewCustomRenderer
);
229 model
->GetValue( value
, item
, column
->GetModelColumn() );
230 renderer
->SetValue( value
);
231 height
= wxMax( height
, renderer
->GetSize().y
);
237 m_dataViewControlPtr
->SetRowHeight( itemID
, height
);
240 return noFailureFlag
;
243 virtual bool ItemsAdded(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
247 DataBrowserItemID
* itemIDs
;
252 // convert all valid data view items to data browser items:
253 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
254 // insert all valid items into control:
255 noFailureFlag
= ((noOfEntries
== 0) ||
256 !(parent
.IsOk()) && (m_dataViewControlPtr
->AddItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
) ||
257 parent
.IsOk() && (m_dataViewControlPtr
->AddItems(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
));
258 // give allocated array space free again:
261 wxDataViewCtrl
*dvc
= (wxDataViewCtrl
*) m_dataViewControlPtr
->GetWXPeer();
262 if (dvc
->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT
)
264 wxDataViewModel
*model
= GetOwner();
265 unsigned int colnum
= dvc
->GetColumnCount();
268 size_t count
= items
.GetCount();
269 for (i
= 0; i
< count
; i
++)
271 wxDataViewItem item
= items
[i
];
272 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
274 int height
= 20; // TODO find out standard height
276 for (col
= 0; col
< colnum
; col
++)
278 wxDataViewColumn
*column
= dvc
->GetColumn( col
);
279 if (column
->IsHidden())
280 continue; // skip it!
282 if ((col
!= 0) && model
->IsContainer(item
) && !model
->HasContainerColumns(item
))
283 continue; // skip it!
285 wxDataViewCustomRenderer
*renderer
= wxDynamicCast( column
->GetRenderer(), wxDataViewCustomRenderer
);
289 model
->GetValue( value
, item
, column
->GetModelColumn() );
290 renderer
->SetValue( value
);
291 height
= wxMax( height
, renderer
->GetSize().y
);
296 m_dataViewControlPtr
->SetRowHeight( itemID
, height
);
301 return noFailureFlag
;
304 virtual bool ItemChanged(wxDataViewItem
const& item
)
306 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
309 wxCHECK_MSG(item
.IsOk(),false,_("Changed item is invalid."));
310 if (m_dataViewControlPtr
->UpdateItems(&itemID
) == noErr
)
312 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(m_dataViewControlPtr
->GetWXPeer()));
314 // sent the equivalent wxWidget event:
315 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId());
317 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
318 dataViewEvent
.SetItem(item
);
319 // sent the equivalent wxWidget event:
320 dataViewCtrlPtr
->HandleWindowEvent(dataViewEvent
);
328 virtual bool ItemsChanged(wxDataViewItemArray
const& items
)
332 DataBrowserItemID
* itemIDs
;
337 // convert all valid data view items to data browser items:
338 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
339 // change items (ATTENTION: ONLY ITEMS OF THE ROOT ARE CHANGED BECAUSE THE PARENT PARAMETER IS MISSING):
340 noFailureFlag
= (m_dataViewControlPtr
->UpdateItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
,kDataBrowserItemNoProperty
) == noErr
);
343 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(m_dataViewControlPtr
->GetWXPeer()));
345 // send for all changed items a wxWidget event:
346 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId());
348 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
349 for (size_t i
=0; i
<noOfEntries
; ++i
)
351 dataViewEvent
.SetItem(reinterpret_cast<void*>(itemIDs
[i
]));
352 dataViewCtrlPtr
->HandleWindowEvent(dataViewEvent
);
355 // release allocated array space:
358 return noFailureFlag
;
361 virtual bool ItemDeleted(wxDataViewItem
const& parent
, wxDataViewItem
const& item
)
365 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
366 OSStatus errorStatus
;
367 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(m_dataViewControlPtr
->GetWXPeer()));
369 // 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
370 // not to be identical because the being edited item might be below the passed item in the hierarchy);
371 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
372 // has been started and that variables can currently not be updated even when requested by the system:
373 dataViewCtrlPtr
->SetDeleting(true);
374 errorStatus
= m_dataViewControlPtr
->RemoveItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
);
375 // enable automatic updating again:
376 dataViewCtrlPtr
->SetDeleting(false);
377 return (errorStatus
== noErr
);
383 virtual bool ItemsDeleted(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
387 DataBrowserItemID
* itemIDs
;
389 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(m_dataViewControlPtr
->GetWXPeer()));
394 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,false,_("Data view control is not correctly initialized"));
395 // convert all valid data view items to data browser items:
396 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
397 // 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
398 // not to be identical because the being edited item might be below the passed item in the hierarchy);
399 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
400 // has been started and that variables can currently not be updated even when requested by the system:
401 dataViewCtrlPtr
->SetDeleting(true);
402 // insert all valid items into control:
403 noFailureFlag
= ((noOfEntries
== 0) ||
404 !(parent
.IsOk()) && (m_dataViewControlPtr
->RemoveItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
) ||
405 parent
.IsOk() && (m_dataViewControlPtr
->RemoveItems(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
));
406 // enable automatic updating again:
407 dataViewCtrlPtr
->SetDeleting(false);
408 // give allocated array space free again:
411 return noFailureFlag
;
414 virtual bool ValueChanged(wxDataViewItem
const& item
, unsigned int col
)
416 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
417 DataBrowserItemID parentID
;
419 DataBrowserPropertyID propertyID
;
421 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(m_dataViewControlPtr
->GetWXPeer()));
424 wxCHECK_MSG(item
.IsOk(), false,_("Passed item is invalid."));
425 wxCHECK_MSG(this->GetOwner() != NULL
,false,_("Owner not initialized."));
426 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Control is wrongly initialized."));
427 parentID
= reinterpret_cast<DataBrowserItemID
>(this->GetOwner()->GetParent(item
).GetID());
428 if ((m_dataViewControlPtr
->GetPropertyID(col
,&propertyID
) == noErr
) &&
429 (m_dataViewControlPtr
->UpdateItems(parentID
,1,&itemID
,dataViewCtrlPtr
->GetColumn(col
)->GetPropertyID(),propertyID
) == noErr
))
431 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId());
433 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
434 dataViewEvent
.SetColumn(col
);
435 dataViewEvent
.SetItem(item
);
436 // send the equivalent wxWidget event:
437 dataViewCtrlPtr
->HandleWindowEvent(dataViewEvent
);
445 virtual bool Cleared()
447 bool noFailureFlag
= (m_dataViewControlPtr
->RemoveItems() == noErr
);
449 wxDataViewItemArray array
;
450 GetOwner()->GetChildren( item
, array
);
451 ItemsAdded( item
, array
);
452 m_dataViewControlPtr
->SetScrollPosition(0, 0);
453 return noFailureFlag
;
456 virtual void Resort()
458 m_dataViewControlPtr
->Resort();
462 wxMacDataViewDataBrowserListViewControl
* m_dataViewControlPtr
;
465 // ---------------------------------------------------------
466 // wxDataViewRenderer
467 // ---------------------------------------------------------
468 wxDataViewRenderer::wxDataViewRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
469 :wxDataViewRendererBase(varianttype
,mode
,align
), m_alignment(align
), m_mode(mode
)
473 void wxDataViewRenderer::SetMode(wxDataViewCellMode mode
)
475 wxDataViewColumn
* dataViewColumnPtr
;
479 dataViewColumnPtr
= this->GetOwner();
480 if (dataViewColumnPtr
!= NULL
)
482 wxDataViewCtrl
* dataViewCtrlPtr(dataViewColumnPtr
->GetOwner());
484 if (dataViewCtrlPtr
!= NULL
)
486 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
488 if (macDataViewListCtrlPtr
!= NULL
)
490 DataBrowserPropertyFlags flags
;
492 verify_noerr(macDataViewListCtrlPtr
->GetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),&flags
));
493 if ((mode
== wxDATAVIEW_CELL_EDITABLE
) || (mode
== wxDATAVIEW_CELL_ACTIVATABLE
))
494 flags
|= kDataBrowserPropertyIsEditable
;
496 flags
&= ~kDataBrowserPropertyIsEditable
;
497 verify_noerr(macDataViewListCtrlPtr
->SetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),flags
));
503 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
,wxDataViewRendererBase
)
505 // ---------------------------------------------------------
506 // wxDataViewCustomRenderer
507 // ---------------------------------------------------------
508 wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
509 :wxDataViewRenderer(varianttype
,mode
,align
), m_editorCtrlPtr(NULL
), m_DCPtr(NULL
)
513 wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
518 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
)
520 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
521 // wxColour col = (state & wxDATAVIEW_CELL_SELECTED) ? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) : view->GetForegroundColour();
522 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ? *wxWHITE
: view
->GetForegroundColour();
523 dc
->SetTextForeground(col
);
524 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
527 wxDC
* wxDataViewCustomRenderer::GetDC()
531 if ((GetOwner() == NULL
) || (GetOwner()->GetOwner() == NULL
))
533 m_DCPtr
= new wxWindowDC(this->GetOwner()->GetOwner());
538 bool wxDataViewCustomRenderer::Render()
543 void wxDataViewCustomRenderer::SetDC(wxDC
* newDCPtr
)
549 WXDataBrowserPropertyType
wxDataViewCustomRenderer::GetPropertyType() const
551 return kDataBrowserCustomType
;
554 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
556 // ---------------------------------------------------------
557 // wxDataViewTextRenderer
558 // ---------------------------------------------------------
559 wxDataViewTextRenderer::wxDataViewTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
560 :wxDataViewRenderer(varianttype
,mode
,align
)
564 bool wxDataViewTextRenderer::Render()
566 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Text renderer cannot render value; value type: ")) << this->GetValue().GetType());
568 wxCFStringRef
cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
569 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
);
572 WXDataBrowserPropertyType
wxDataViewTextRenderer::GetPropertyType() const
574 return kDataBrowserTextType
;
577 IMPLEMENT_CLASS(wxDataViewTextRenderer
,wxDataViewRenderer
)
579 // ---------------------------------------------------------
580 // wxDataViewTextRendererAttr
581 // ---------------------------------------------------------
582 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
583 :wxDataViewTextRenderer(varianttype
,mode
,align
)
587 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
,wxDataViewTextRenderer
)
589 // ---------------------------------------------------------
590 // wxDataViewBitmapRenderer
591 // ---------------------------------------------------------
592 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
593 :wxDataViewRenderer(varianttype
,mode
,align
)
597 bool wxDataViewBitmapRenderer::Render()
598 // This method returns 'true' if
599 // - the passed bitmap is valid and it could be assigned to the native data browser;
600 // - the passed bitmap is invalid (or is not initialized); this case simulates a non-existing bitmap.
601 // In all other cases the method returns 'false'.
603 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Bitmap renderer cannot render value; value type: ")) << this->GetValue().GetType());
607 bitmap
<< this->GetValue();
609 return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap
.GetIconRef()) == noErr
);
614 WXDataBrowserPropertyType
wxDataViewBitmapRenderer::GetPropertyType() const
616 return kDataBrowserIconType
;
619 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
,wxDataViewRenderer
)
621 // ---------------------------------------------------------
622 // wxDataViewIconTextRenderer
623 // ---------------------------------------------------------
624 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
625 :wxDataViewRenderer(varianttype
,mode
)
629 bool wxDataViewIconTextRenderer::Render()
631 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Icon & text renderer cannot render value; value type: ")) << this->GetValue().GetType());
633 wxDataViewIconText iconText
;
635 iconText
<< this->GetValue();
637 wxCFStringRef
cfString(iconText
.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
639 if (iconText
.GetIcon().IsOk())
640 if (::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText
.GetIcon().GetHICON())) != noErr
)
642 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
);
645 WXDataBrowserPropertyType
wxDataViewIconTextRenderer::GetPropertyType() const
647 return kDataBrowserIconAndTextType
;
650 IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer
,wxDataViewRenderer
)
653 // ---------------------------------------------------------
654 // wxDataViewToggleRenderer
655 // ---------------------------------------------------------
656 wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
657 :wxDataViewRenderer(varianttype
,mode
)
661 bool wxDataViewToggleRenderer::Render()
663 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Toggle renderer cannot render value; value type: ")) << this->GetValue().GetType());
664 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr
);
667 WXDataBrowserPropertyType
wxDataViewToggleRenderer::GetPropertyType() const
669 return kDataBrowserCheckboxType
;
672 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
,wxDataViewRenderer
)
674 // ---------------------------------------------------------
675 // wxDataViewProgressRenderer
676 // ---------------------------------------------------------
677 wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString
const& label
, wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
678 :wxDataViewRenderer(varianttype
,mode
,align
)
682 bool wxDataViewProgressRenderer::Render()
684 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Progress renderer cannot render value type; value type: ")) << this->GetValue().GetType());
685 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr
) &&
686 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr
) &&
687 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr
));
690 WXDataBrowserPropertyType
wxDataViewProgressRenderer::GetPropertyType() const
692 return kDataBrowserProgressBarType
;
695 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
,wxDataViewRenderer
)
697 // ---------------------------------------------------------
698 // wxDataViewDateRenderer
699 // ---------------------------------------------------------
700 wxDataViewDateRenderer::wxDataViewDateRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
701 :wxDataViewRenderer(varianttype
,mode
,align
)
705 bool wxDataViewDateRenderer::Render()
707 wxCHECK_MSG(this->GetValue().GetType() == this->GetVariantType(),false,wxString(_("Date renderer cannot render value; value type: ")) << this->GetValue().GetType());
708 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan
,1904)).GetSeconds().GetLo()) == noErr
);
711 WXDataBrowserPropertyType
wxDataViewDateRenderer::GetPropertyType() const
713 return kDataBrowserDateTimeType
;
716 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
,wxDataViewRenderer
)
718 // ---------------------------------------------------------
720 // ---------------------------------------------------------
722 void wxDataViewColumn::SetAlignment(wxAlignment align
)
724 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
728 if (dataViewCtrlPtr
!= NULL
)
730 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
732 if (macDataViewListCtrlPtr
!= NULL
)
734 DataBrowserListViewHeaderDesc headerDescription
;
736 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
740 case wxALIGN_CENTER_HORIZONTAL
:
741 headerDescription
.btnFontStyle
.just
= teCenter
;
744 headerDescription
.btnFontStyle
.just
= teFlushLeft
;
747 headerDescription
.btnFontStyle
.just
= teFlushRight
;
750 headerDescription
.btnFontStyle
.just
= teFlushDefault
;
752 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set alignment."));
757 void wxDataViewColumn::SetBitmap(wxBitmap
const& bitmap
)
759 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
762 wxDataViewColumnBase::SetBitmap(bitmap
);
763 if (dataViewCtrlPtr
!= NULL
)
765 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
767 if (macDataViewListCtrlPtr
!= NULL
)
769 DataBrowserListViewHeaderDesc headerDescription
;
771 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
772 if (this->GetBitmap().Ok())
773 headerDescription
.btnContentInfo
.u
.iconRef
= this->GetBitmap().GetIconRef();
775 headerDescription
.btnContentInfo
.u
.iconRef
= NULL
;
776 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set icon."));
781 void wxDataViewColumn::SetMaxWidth(int maxWidth
)
783 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
786 m_maxWidth
= maxWidth
;
787 if (dataViewCtrlPtr
!= NULL
)
789 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
791 if (macDataViewListCtrlPtr
!= NULL
)
793 DataBrowserListViewHeaderDesc headerDescription
;
795 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
796 headerDescription
.maximumWidth
= static_cast<UInt16
>(maxWidth
);
797 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set maximum width."));
802 void wxDataViewColumn::SetMinWidth(int minWidth
)
804 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
807 m_minWidth
= minWidth
;
808 if (dataViewCtrlPtr
!= NULL
)
810 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
812 if (macDataViewListCtrlPtr
!= NULL
)
814 DataBrowserListViewHeaderDesc headerDescription
;
816 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
817 headerDescription
.minimumWidth
= static_cast<UInt16
>(minWidth
);
818 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set minimum width."));
823 void wxDataViewColumn::SetReorderable(bool reorderable
)
825 // first set the internal flag of the column:
827 m_flags
|= wxDATAVIEW_COL_REORDERABLE
;
829 m_flags
&= ~wxDATAVIEW_COL_REORDERABLE
;
830 // if the column is associated with a control change also immediately the flags of the control:
831 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
833 if (dataViewCtrlPtr
!= NULL
)
835 DataBrowserPropertyFlags flags
;
836 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
838 wxCHECK_RET(macDataViewListCtrlPtr
!= NULL
, _("Valid pointer to native data view control does not exist"));
839 wxCHECK_RET(macDataViewListCtrlPtr
->GetPropertyFlags(this->GetPropertyID(),&flags
) == noErr
,_("Could not get property flags."));
841 flags
|= kDataBrowserListViewMovableColumn
;
843 flags
&= ~kDataBrowserListViewMovableColumn
;
844 wxCHECK_RET(macDataViewListCtrlPtr
->SetPropertyFlags(this->GetPropertyID(),flags
) == noErr
,_("Could not set property flags."));
848 void wxDataViewColumn::SetResizeable(bool resizeable
)
850 // first set the internal flag of the column:
852 m_flags
|= wxDATAVIEW_COL_RESIZABLE
;
854 m_flags
&= ~wxDATAVIEW_COL_RESIZABLE
;
855 // if the column is associated with a control change also immediately the flags of the control:
856 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
858 if (dataViewCtrlPtr
!= NULL
)
860 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
862 if (macDataViewListCtrlPtr
!= NULL
)
864 DataBrowserListViewHeaderDesc headerDescription
;
866 verify_noerr(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
));
868 headerDescription
.minimumWidth
= 0;
869 headerDescription
.maximumWidth
= 30000;
872 headerDescription
.minimumWidth
= m_width
;
873 headerDescription
.maximumWidth
= m_width
;
875 verify_noerr(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
));
876 macDataViewListCtrlPtr
->SetSortProperty(this->GetPropertyID());
881 void wxDataViewColumn::SetSortable(bool sortable
)
883 // first set the internal flag of the column:
885 m_flags
|= wxDATAVIEW_COL_SORTABLE
;
887 m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
888 // if the column is associated with a control change also immediately the flags of the control:
889 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
891 if (dataViewCtrlPtr
!= NULL
)
893 DataBrowserPropertyFlags flags
;
894 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
896 wxCHECK_RET(macDataViewListCtrlPtr
!= NULL
, _("Valid pointer to native data view control does not exist"));
897 wxCHECK_RET(macDataViewListCtrlPtr
->GetPropertyFlags(this->GetPropertyID(),&flags
) == noErr
,_("Could not get property flags."));
899 flags
|= kDataBrowserListViewSortableColumn
;
901 flags
&= ~kDataBrowserListViewSortableColumn
;
902 wxCHECK_RET(macDataViewListCtrlPtr
->SetPropertyFlags(this->GetPropertyID(),flags
) == noErr
,_("Could not set property flags."));
906 void wxDataViewColumn::SetSortOrder(bool ascending
)
908 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
911 m_ascending
= ascending
;
912 if (dataViewCtrlPtr
!= NULL
)
914 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
916 if (macDataViewListCtrlPtr
!= NULL
)
918 DataBrowserListViewHeaderDesc headerDescription
;
920 verify_noerr(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
));
922 headerDescription
.initialOrder
= kDataBrowserOrderIncreasing
;
924 headerDescription
.initialOrder
= kDataBrowserOrderDecreasing
;
925 verify_noerr(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
));
926 macDataViewListCtrlPtr
->SetSortProperty(this->GetPropertyID());
931 void wxDataViewColumn::SetTitle(wxString
const& title
)
933 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
937 if (dataViewCtrlPtr
!= NULL
)
939 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
941 if (macDataViewListCtrlPtr
!= NULL
)
943 DataBrowserListViewHeaderDesc headerDescription
;
944 wxCFStringRef
cfTitle(title
,(dataViewCtrlPtr
->GetFont().Ok() ? dataViewCtrlPtr
->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
946 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
947 headerDescription
.titleString
= cfTitle
;
948 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set header description."));
953 void wxDataViewColumn::SetWidth(int width
)
955 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
958 if ((width
>= m_minWidth
) && (width
<= m_maxWidth
))
961 if (dataViewCtrlPtr
!= NULL
)
963 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
965 if (macDataViewListCtrlPtr
!= NULL
)
966 wxCHECK_RET(macDataViewListCtrlPtr
->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16
>(width
)) == noErr
,_("Could not set column width."));
971 void wxDataViewColumn::SetAsSortKey(bool WXUNUSED(sort
))
973 // see wxGTK native wxDataViewColumn implementation
974 wxFAIL_MSG( "not implemented" );
977 bool wxDataViewColumn::IsSortKey() const
979 wxDataViewCtrl
* const dataViewCtrlPtr(GetOwner());
980 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(
981 dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(
982 dataViewCtrlPtr
->GetPeer()));
984 DataBrowserPropertyID propertyID
;
985 return macDataViewListCtrlPtr
->GetSortProperty(&propertyID
) == noErr
&&
986 propertyID
== m_propertyID
;
989 //-----------------------------------------------------------------------------
991 //-----------------------------------------------------------------------------
994 wxDataViewCtrl::~wxDataViewCtrl()
999 void wxDataViewCtrl::Init()
1001 m_CustomRendererPtr
= NULL
;
1003 m_macIsUserPane
= false;
1007 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1009 if (!(this->wxControl::Create(parent
,id
,pos
,size
,style
& ~(wxHSCROLL
| wxVSCROLL
),validator
)))
1013 MacSetClipChildren(true) ;
1016 m_peer
= new wxMacDataViewDataBrowserListViewControl(this,pos
,size
,style
);
1018 if ( style
& wxBORDER_NONE
)
1019 m_peer
->SetData( kControlNoPart
, kControlDataBrowserIncludesFrameAndFocusTag
, (Boolean
) false ) ;
1021 this->MacPostControlCreate(pos
,size
);
1022 ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(m_peer
->GetControlRef()),true);
1024 InstallControlEventHandler(m_peer
->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList
),eventList
,this,NULL
);
1026 ::SetDataBrowserTableViewHiliteStyle( m_peer
->GetControlRef(), kDataBrowserTableViewFillHilite
);
1031 wxSize
wxDataViewCtrl::DoGetBestSize() const
1033 wxSize best
= wxControl::DoGetBestSize();
1040 wxVisualAttributes
wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant variant
)
1042 wxVisualAttributes attr
;
1044 attr
.colFg
= wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT
);
1045 attr
.colBg
= wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX
);
1046 //attr.font.CreateSystemFont(wxOSX_SYSTEM_FONT_VIEWS);
1051 bool wxDataViewCtrl::AssociateModel(wxDataViewModel
* model
)
1053 if (!wxDataViewCtrlBase::AssociateModel(model
))
1056 model
->AddNotifier(new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl
*>(m_peer
)));
1061 bool wxDataViewCtrl::AppendColumn(wxDataViewColumn
* columnPtr
)
1063 return wxDataViewCtrl::InsertColumn( GetColumnCount(), columnPtr
);
1066 bool wxDataViewCtrl::PrependColumn(wxDataViewColumn
* columnPtr
)
1068 return wxDataViewCtrl::InsertColumn( 0, columnPtr
);
1071 bool wxDataViewCtrl::InsertColumn(unsigned int pos
, wxDataViewColumn
* columnPtr
)
1073 DataBrowserListViewColumnDesc columnDescription
;
1075 DataBrowserPropertyID NewPropertyID
;
1077 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1079 wxCFStringRef
title(columnPtr
->GetTitle(),m_font
.Ok() ? this->GetFont().GetEncoding() : wxLocale::GetSystemEncoding());
1082 // first, some error checking:
1083 wxCHECK_MSG(MacDataViewListCtrlPtr
!= NULL
, false,_("m_peer is not or incorrectly initialized"));
1084 wxCHECK_MSG(columnPtr
!= NULL
, false,_("Column pointer must not be NULL."));
1085 wxCHECK_MSG(columnPtr
->GetRenderer() != NULL
, false,_("Column does not have a renderer."));
1086 wxCHECK_MSG(this->GetModel() != NULL
, false,_("No model associated with control."));
1087 wxCHECK_MSG((columnPtr
->GetModelColumn() >= 0) &&
1088 (columnPtr
->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
1090 // try to get new ID for the column:
1091 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetFreePropertyID(&NewPropertyID
) == noErr
,false,_("Cannot create new column's ID. Probably max. number of columns reached."));
1092 // full column variable initialization:
1093 columnPtr
->SetPropertyID(NewPropertyID
);
1094 // add column to wxWidget's internal structure:
1095 wxCHECK_MSG(this->wxDataViewCtrlBase::InsertColumn(pos
,columnPtr
) &&
1096 m_ColumnPointers
.insert(ColumnPointerHashMapType::value_type(NewPropertyID
,columnPtr
)).second
,false,_("Could not add column to internal structures."));
1097 // create a column description and add column to the native control:
1098 wxCHECK_MSG(::InitializeColumnDescription(columnDescription
,columnPtr
,NewPropertyID
,title
), false,_("Column description could not be initialized."));
1099 wxCHECK_MSG(MacDataViewListCtrlPtr
->AddColumn(&columnDescription
,pos
) == noErr
,false,_("Column could not be added."));
1101 // final adjustments for the layout:
1102 wxCHECK_MSG(MacDataViewListCtrlPtr
->SetColumnWidth(NewPropertyID
,columnPtr
->GetWidth()) == noErr
,false,_("Column width could not be set."));
1104 // make sure that the data is up-to-date...
1105 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
1106 // otherwise ask the control to 'update' the data in the newly appended column:
1107 if (this->GetColumnCount() == 1)
1109 this->SetExpanderColumn(columnPtr
);
1110 this->AddChildrenLevel(wxDataViewItem());
1113 MacDataViewListCtrlPtr
->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,NewPropertyID
);
1118 bool wxDataViewCtrl::ClearColumns()
1120 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1123 while (m_ColumnPointers
.begin() != m_ColumnPointers
.end())
1125 wxCHECK_MSG(MacDataViewListCtrlPtr
->RemoveColumnByProperty(m_ColumnPointers
.begin()->first
) == noErr
,false,_("Could not remove column."));
1126 delete m_ColumnPointers
.begin()->second
;
1127 m_ColumnPointers
.erase(m_ColumnPointers
.begin());
1132 bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn
* columnPtr
)
1134 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1137 if ((MacDataViewListCtrlPtr
->RemoveColumnByProperty(columnPtr
->GetPropertyID()) == noErr
) && (m_ColumnPointers
.erase(columnPtr
->GetPropertyID()) > 0))
1146 wxDataViewColumn
* wxDataViewCtrl::GetColumn(unsigned int pos
) const
1148 DataBrowserPropertyID propertyID
;
1150 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1153 if (MacDataViewListCtrlPtr
->GetPropertyID(pos
,&propertyID
) == noErr
)
1155 ColumnPointerHashMapType::const_iterator
Result(m_ColumnPointers
.find(propertyID
));
1157 if (Result
!= m_ColumnPointers
.end())
1158 return Result
->second
;
1166 unsigned int wxDataViewCtrl::GetColumnCount() const
1168 return m_ColumnPointers
.size();
1171 int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn
const* columnPtr
) const
1173 if (columnPtr
!= NULL
)
1175 DataBrowserTableViewColumnIndex Position
;
1176 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1178 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetColumnIndex(columnPtr
->GetPropertyID(),&Position
) == noErr
,-1,_("Could not determine column's position"));
1179 return static_cast<int>(Position
);
1185 void wxDataViewCtrl::Collapse(wxDataViewItem
const& item
)
1187 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1190 MacDataViewListCtrlPtr
->CloseContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1193 void wxDataViewCtrl::EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
)
1195 ExpandAncestors(item
);
1199 DataBrowserPropertyID propertyID
;
1200 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1202 if (columnPtr
!= NULL
)
1203 propertyID
= columnPtr
->GetPropertyID();
1205 propertyID
= kDataBrowserNoItem
;
1206 MacDataViewListCtrlPtr
->RevealItem(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),propertyID
,kDataBrowserRevealOnly
);
1210 void wxDataViewCtrl::Expand(wxDataViewItem
const& item
)
1212 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1215 MacDataViewListCtrlPtr
->OpenContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1218 bool wxDataViewCtrl::IsExpanded( const wxDataViewItem
& item
) const
1222 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1224 DataBrowserItemState state
= 0;
1225 OSStatus err
= ::GetDataBrowserItemState(
1226 MacDataViewListCtrlPtr
->GetControlRef(),
1227 reinterpret_cast<DataBrowserItemID
>(item
.GetID()),
1229 if ((err
== 0) && (state
& kDataBrowserContainerIsOpen
))
1235 wxDataViewColumn
* wxDataViewCtrl::GetSortingColumn() const
1237 DataBrowserPropertyID propertyID
;
1239 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1242 if (MacDataViewListCtrlPtr
->GetSortProperty(&propertyID
) == noErr
)
1243 return this->GetColumnPtr(propertyID
);
1248 unsigned int wxDataViewCtrl::GetCount() const
1250 ItemCount noOfItems
;
1253 wxCHECK_MSG(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
)->GetItemCount(&noOfItems
) == noErr
,0,_("Could not determine number of items"));
1257 wxRect
wxDataViewCtrl::GetItemRect(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
) const
1259 if (item
.IsOk() && (columnPtr
!= NULL
))
1262 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1264 if (MacDataViewListCtrlPtr
->GetPartBounds(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),columnPtr
->GetPropertyID(),kDataBrowserPropertyContentPart
,&MacRectangle
) == noErr
)
1268 ::wxMacNativeToRect(&MacRectangle
,&rectangle
);
1278 wxDataViewItem
wxDataViewCtrl::GetSelection() const
1280 wxArrayDataBrowserItemID itemIDs
;
1282 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1285 if (MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
) > 0)
1286 return wxDataViewItem(reinterpret_cast<void*>(itemIDs
[0]));
1288 return wxDataViewItem();
1291 int wxDataViewCtrl::GetSelections(wxDataViewItemArray
& sel
) const
1293 size_t NoOfSelectedItems
;
1295 wxArrayDataBrowserItemID itemIDs
;
1297 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1300 NoOfSelectedItems
= MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
);
1302 sel
.SetCount(NoOfSelectedItems
);
1303 for (size_t i
=0; i
<NoOfSelectedItems
; ++i
)
1304 sel
[i
] = wxDataViewItem(reinterpret_cast<void*>(itemIDs
[i
]));
1305 return static_cast<int>(NoOfSelectedItems
);
1308 void wxDataViewCtrl::HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const
1310 item
= wxDataViewItem();
1314 bool wxDataViewCtrl::IsSelected(wxDataViewItem
const& item
) const
1316 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1319 return MacDataViewListCtrlPtr
->IsItemSelected(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1322 void wxDataViewCtrl::SelectAll()
1324 DataBrowserItemID
* itemIDPtr
;
1326 Handle
handle(::NewHandle(0));
1330 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1333 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1334 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1336 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1337 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsAssign
);
1339 DisposeHandle(handle
);
1342 void wxDataViewCtrl::Select(wxDataViewItem
const& item
)
1346 ExpandAncestors(item
);
1348 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1349 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1351 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsAdd
);
1355 void wxDataViewCtrl::SetSelections(wxDataViewItemArray
const& sel
)
1357 size_t const NoOfSelections
= sel
.GetCount();
1359 wxDataViewItem last_parent
;
1362 for (i
= 0; i
< NoOfSelections
; i
++)
1364 wxDataViewItem item
= sel
[i
];
1365 wxDataViewItem parent
= GetModel()->GetParent( item
);
1368 if (parent
!= last_parent
)
1369 ExpandAncestors(item
);
1371 last_parent
= parent
;
1374 DataBrowserItemID
* itemIDs
;
1375 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1377 itemIDs
= new DataBrowserItemID
[NoOfSelections
];
1378 for (i
=0; i
<NoOfSelections
; ++i
)
1379 itemIDs
[i
] = reinterpret_cast<DataBrowserItemID
>(sel
[i
].GetID());
1380 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfSelections
,itemIDs
,kDataBrowserItemsAssign
);
1384 void wxDataViewCtrl::Unselect(wxDataViewItem
const& item
)
1388 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1389 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1391 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsRemove
);
1395 void wxDataViewCtrl::UnselectAll()
1397 DataBrowserItemID
* itemIDPtr
;
1399 Handle
handle(::NewHandle(0));
1403 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1406 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1407 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1409 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1410 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsRemove
);
1412 DisposeHandle(handle
);
1416 void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem
const& parentItem
)
1420 wxDataViewItemArray items
;
1423 wxCHECK_RET(this->GetModel() != NULL
,_("Model pointer not initialized."));
1424 NoOfChildren
= this->GetModel()->GetChildren(parentItem
,items
);
1426 for (int i
=0; i
<NoOfChildren
; ++i
)
1427 (void) this->GetModel()->ItemAdded(parentItem
,items
[i
]);
1429 (void) this->GetModel()->ItemsAdded(parentItem
,items
);
1433 void wxDataViewCtrl::FinishCustomItemEditing()
1435 if (this->GetCustomRendererItem().IsOk())
1437 this->GetCustomRendererPtr()->FinishEditing();
1438 this->SetCustomRendererItem(wxDataViewItem());
1439 this->SetCustomRendererPtr (NULL
);
1443 wxDataViewColumn
* wxDataViewCtrl::GetColumnPtr(WXDataBrowserPropertyID propertyID
) const
1445 ColumnPointerHashMapType::const_iterator
Result(m_ColumnPointers
.find(propertyID
));
1447 if (Result
!= m_ColumnPointers
.end())
1448 return Result
->second
;
1453 // inherited methods from wxDataViewCtrlBase
1454 void wxDataViewCtrl::DoSetExpanderColumn()
1456 if (this->GetExpanderColumn() != NULL
)
1458 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1460 (void) MacDataViewListCtrlPtr
->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID(),false); // second parameter explicitely passed to ensure that arrow is centered
1464 void wxDataViewCtrl::DoSetIndent()
1466 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1468 (void) MacDataViewListCtrlPtr
->SetIndent(static_cast<float>(this->GetIndent()));
1472 void wxDataViewCtrl::OnMouse(wxMouseEvent
& event
)
1476 if (GetModel() == NULL
)
1479 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1482 wxDataViewItemArray items
;
1483 NoOfChildren
= GetModel()->GetChildren( wxDataViewItem(), items
);
1484 if (NoOfChildren
== 0)
1486 wxDataViewItem firstChild
= items
[0];
1488 UInt16 headerHeight
= 0;
1489 MacDataViewListCtrlPtr
->GetHeaderButtonHeight(&headerHeight
);
1492 if (event
.GetY() < headerHeight
)
1494 unsigned int col_count
= GetColumnCount();
1496 for (col
= 0; col
< col_count
; col
++)
1498 wxDataViewColumn
*column
= GetColumn( col
);
1499 if (column
->IsHidden())
1503 ::GetDataBrowserItemPartBounds( MacDataViewListCtrlPtr
->GetControlRef(),
1504 reinterpret_cast<DataBrowserItemID
>(firstChild
.GetID()), column
->GetPropertyID(),
1505 kDataBrowserPropertyEnclosingPart
, &itemrect
);
1507 if (abs( event
.GetX() - itemrect
.right
) < 3)
1509 if (column
->GetFlags() & wxDATAVIEW_COL_RESIZABLE
)
1510 SetCursor( wxCursor( wxCURSOR_SIZEWE
) );
1512 SetCursor( *wxSTANDARD_CURSOR
);
1519 SetCursor( *wxSTANDARD_CURSOR
);
1522 void wxDataViewCtrl::OnSize(wxSizeEvent
& event
)
1524 unsigned int const NoOfColumns
= this->GetColumnCount();
1527 for (unsigned int i
=0; i
<NoOfColumns
; ++i
)
1529 wxDataViewColumn
* dataViewColumnPtr(this->GetColumn(i
));
1531 if (dataViewColumnPtr
!= NULL
)
1533 wxDataViewCustomRenderer
* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer()));
1535 if (dataViewCustomRendererPtr
!= NULL
)
1536 dataViewCustomRendererPtr
->SetDC(NULL
); // reset DC because DC has changed
1540 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(m_peer
));
1541 ControlRef ref
= MacDataViewListCtrlPtr
->GetControlRef();
1542 if (NoOfColumns
== 1)
1544 ::SetDataBrowserHasScrollBars( ref
, false, true );
1545 ::AutoSizeDataBrowserListViewColumns( ref
);
1547 if (NoOfColumns
> 1)
1549 ::SetDataBrowserHasScrollBars( ref
, true, true );
1555 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
,wxDataViewCtrlBase
)
1557 BEGIN_EVENT_TABLE(wxDataViewCtrl
,wxDataViewCtrlBase
)
1558 EVT_SIZE(wxDataViewCtrl::OnSize
)
1559 EVT_MOTION(wxDataViewCtrl::OnMouse
)
1562 #endif // !wxUSE_GENERICDATAVIEWCTRL
1564 #endif // wxUSE_DATAVIEWCTRL