1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/datavgen.cpp
3 // Purpose: wxDataViewCtrl native mac implementation
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_DATAVIEWCTRL
15 #include "wx/dataview.h"
17 #if !defined(wxUSE_GENERICDATAVIEWCTRL) || (wxUSE_GENERICDATAVIEWCTRL == 0)
21 #include "wx/mac/carbon/databrow.h"
28 #include "wx/renderer.h"
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 // a list of all catchable events:
35 static EventTypeSpec
const eventList
[] =
37 {kEventClassControl
, kEventControlDraw
},
38 {kEventClassControl
, kEventControlHit
}
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 static pascal OSStatus
wxMacDataViewCtrlEventHandler(EventHandlerCallRef handler
, EventRef EventReference
, void* Data
)
47 wxDataViewCtrl
* DataViewCtrlPtr((wxDataViewCtrl
*) Data
); // the 'Data' variable always contains a pointer to the data view control that installed the handler
49 wxMacCarbonEvent
CarbonEvent(EventReference
) ;
52 switch (GetEventKind(EventReference
))
54 case kEventControlDraw
:
58 DataViewCtrlPtr
->MacSetDrawingContext(CarbonEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
,typeCGContextRef
));
59 status
= ::CallNextEventHandler(handler
,EventReference
);
60 DataViewCtrlPtr
->MacSetDrawingContext(NULL
);
63 case kEventControlHit
:
64 if (CarbonEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
,typeControlPartCode
) == kControlButtonPart
) // we only care about the header
66 ControlRef controlReference
;
67 DataBrowserPropertyID columnPropertyID
;
68 unsigned long columnIndex
;
70 wxDataViewEvent
DataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
,DataViewCtrlPtr
->GetId());
72 CarbonEvent
.GetParameter(kEventParamDirectObject
,&controlReference
);
73 // determine the column that triggered the event (this is the column that is responsible for sorting the data view):
74 status
= ::GetDataBrowserSortProperty(controlReference
,&columnPropertyID
);
75 wxCHECK(status
== noErr
,status
);
76 status
= ::GetDataBrowserTableViewColumnPosition(controlReference
,columnPropertyID
,&columnIndex
);
77 if (status
== errDataBrowserPropertyNotFound
) // user clicked into part of the header that does not have a property
78 return ::CallNextEventHandler(handler
,EventReference
);
79 wxCHECK(status
== noErr
,status
);
80 // initialize wxWidget event handler:
81 DataViewEvent
.SetEventObject(DataViewCtrlPtr
);
82 DataViewEvent
.SetColumn(columnIndex
);
83 DataViewEvent
.SetDataViewColumn(DataViewCtrlPtr
->GetColumn(columnIndex
));
84 // finally sent the equivalent wxWidget event:
85 DataViewCtrlPtr
->GetEventHandler()->ProcessEvent(DataViewEvent
);
86 return ::CallNextEventHandler(handler
,EventReference
);
89 return eventNotHandledErr
;
92 return eventNotHandledErr
;
93 } /* wxMacDataViewCtrlEventHandler(EventHandlerCallRef, EventRef, void*) */
95 static DataBrowserItemID
* CreateDataBrowserItemIDArray(size_t& noOfEntries
, wxDataViewItemArray
const& items
) // returns a newly allocated pointer to valid data browser item IDs
97 size_t const noOfItems
= items
.GetCount();
99 DataBrowserItemID
* itemIDs(new DataBrowserItemID
[noOfItems
]);
102 // convert all valid data view items to data browser items
104 for (size_t i
=0; i
<noOfItems
; ++i
)
107 itemIDs
[noOfEntries
] = reinterpret_cast<DataBrowserItemID
>(items
[i
].GetID());
112 } /* CreateDataBrowserItemIDArray(size_t&, wxDataViewItemArray const&) */
114 static bool InitializeColumnDescription(DataBrowserListViewColumnDesc
& columnDescription
, wxDataViewColumn
const* columnPtr
, DataBrowserPropertyID columnPropertyID
, wxMacCFStringHolder
const& title
)
116 // set properties for the column:
117 columnDescription
.propertyDesc
.propertyID
= columnPropertyID
;
118 columnDescription
.propertyDesc
.propertyType
= columnPtr
->GetRenderer()->GetPropertyType();
119 columnDescription
.propertyDesc
.propertyFlags
= kDataBrowserListViewSelectionColumn
; // make the column selectable
120 if (columnPtr
->IsSortable())
121 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewSortableColumn
;
123 if (columnPtr
->IsMovable())
124 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewMovableColumn
;
126 if (columnPtr
->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE
)
127 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserPropertyIsEditable
;
128 if ((columnDescription
.propertyDesc
.propertyType
== kDataBrowserTextType
) ||
129 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserIconAndTextType
) ||
130 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserDateTimeType
))
131 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
; // enables generally the possibility to have user input for the mentioned types
132 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
133 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
135 // set header's properties:
136 columnDescription
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
137 if (columnPtr
->IsResizeable())
139 columnDescription
.headerBtnDesc
.minimumWidth
= 0;
140 columnDescription
.headerBtnDesc
.maximumWidth
= 30000; // 32767 is the theoretical maximum though but 30000 looks nicer
144 columnDescription
.headerBtnDesc
.minimumWidth
= columnPtr
->GetWidth();
145 columnDescription
.headerBtnDesc
.maximumWidth
= columnPtr
->GetWidth();
147 columnDescription
.headerBtnDesc
.titleOffset
= 0;
148 columnDescription
.headerBtnDesc
.titleString
= ::CFStringCreateCopy(kCFAllocatorDefault
,title
);
149 columnDescription
.headerBtnDesc
.initialOrder
= kDataBrowserOrderIncreasing
; // choose one of the orders as "undefined" is not supported anyway (s. ControlDefs.h in the HIToolbox framework)
150 columnDescription
.headerBtnDesc
.btnFontStyle
.flags
= kControlUseFontMask
| kControlUseJustMask
;
151 switch (columnPtr
->GetAlignment())
154 case wxALIGN_CENTER_HORIZONTAL
:
155 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teCenter
;
158 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushLeft
;
161 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushRight
;
164 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
166 columnDescription
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
167 columnDescription
.headerBtnDesc
.btnFontStyle
.style
= normal
;
168 columnDescription
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
169 if (columnPtr
->GetBitmap().Ok())
170 columnDescription
.headerBtnDesc
.btnContentInfo
.u
.iconRef
= columnPtr
->GetBitmap().GetBitmapData()->GetIconRef();
173 } /* InitializeColumnDescription(DataBrowserListViewColumnDesc&, wxDataViewColumn const*, DataBrowserPropertyID, wxMacCFStringHolder const&) */
175 //-----------------------------------------------------------------------------
176 // local function pointers
177 //-----------------------------------------------------------------------------
179 DEFINE_ONE_SHOT_HANDLER_GETTER(wxMacDataViewCtrlEventHandler
)
181 // ---------------------------------------------------------
182 // wxMacDataViewModelNotifier
183 // ---------------------------------------------------------
185 class wxMacDataViewModelNotifier
: public wxDataViewModelNotifier
188 wxMacDataViewModelNotifier(wxMacDataViewDataBrowserListViewControl
* initDataViewControlPtr
) : m_dataViewControlPtr(initDataViewControlPtr
)
192 virtual bool ItemAdded(const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
194 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
197 wxCHECK_MSG(item
.IsOk(),false,_("Added item is invalid."));
198 return (!(parent
.IsOk()) && (this->m_dataViewControlPtr
->AddItem(kDataBrowserNoItem
,&itemID
) == noErr
) ||
199 parent
.IsOk() && (this->m_dataViewControlPtr
->AddItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
) == noErr
));
200 } /* ItemAdded(wxDataViewItem const&, wxDataViewItem const&) */
202 virtual bool ItemsAdded(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
206 DataBrowserItemID
* itemIDs
;
211 // convert all valid data view items to data browser items:
212 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
213 // insert all valid items into control:
214 noFailureFlag
= ((noOfEntries
== 0) ||
215 !(parent
.IsOk()) && (this->m_dataViewControlPtr
->AddItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
) ||
216 parent
.IsOk() && (this->m_dataViewControlPtr
->AddItems(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
));
217 // give allocated array space free again:
220 return noFailureFlag
;
221 } /* ItemsAdded(wxDataViewItem const&, wxDataViewItemArray const&) */
223 virtual bool ItemChanged(wxDataViewItem
const& item
)
225 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
228 wxCHECK_MSG(item
.IsOk(),false,_("Changed item is invalid."));
229 if (this->m_dataViewControlPtr
->UpdateItems(&itemID
) == noErr
)
231 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
233 // sent the equivalent wxWidget event:
234 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId()); // variable defintion
236 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
237 dataViewEvent
.SetItem(item
);
238 // sent the equivalent wxWidget event:
239 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
245 } /* ItemChanged(wxDataViewItem const&) */
247 virtual bool ItemsChanged(wxDataViewItemArray
const& items
)
251 DataBrowserItemID
* itemIDs
;
256 // convert all valid data view items to data browser items:
257 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
258 // change items (ATTENTION: ONLY ITEMS OF THE ROOT ARE CHANGED BECAUSE THE PARENT PARAMETER IS MISSING):
259 noFailureFlag
= (this->m_dataViewControlPtr
->UpdateItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
,kDataBrowserItemNoProperty
) == noErr
);
262 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
264 // send for all changed items a wxWidget event:
265 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId()); // variable defintion
267 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
268 for (size_t i
=0; i
<noOfEntries
; ++i
)
270 dataViewEvent
.SetItem(reinterpret_cast<void*>(itemIDs
[i
]));
271 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
274 // release allocated array space:
277 return noFailureFlag
;
278 } /* ItemsChanged(wxDataViewItem const&) */
280 virtual bool ItemDeleted(wxDataViewItem
const& parent
, wxDataViewItem
const& item
)
284 // variable definition and initialization:
285 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
286 OSStatus errorStatus
;
287 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
289 // 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
290 // not to be identical because the being edited item might be below the passed item in the hierarchy);
291 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
292 // has been started and that variables can currently not be updated even when requested by the system:
293 dataViewCtrlPtr
->SetDeleting(true);
294 errorStatus
= this->m_dataViewControlPtr
->RemoveItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
);
295 // enable automatic updating again:
296 dataViewCtrlPtr
->SetDeleting(false);
297 return (errorStatus
== noErr
);
301 } /* ItemDeleted(wxDataViewItem const&, wxDataViewItem const&) */
303 virtual bool ItemsDeleted(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
307 DataBrowserItemID
* itemIDs
;
309 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
314 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,false,_("Data view control is not correctly initialized"));
315 // convert all valid data view items to data browser items:
316 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
317 // 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
318 // not to be identical because the being edited item might be below the passed item in the hierarchy);
319 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
320 // has been started and that variables can currently not be updated even when requested by the system:
321 dataViewCtrlPtr
->SetDeleting(true);
322 // insert all valid items into control:
323 noFailureFlag
= ((noOfEntries
== 0) ||
324 !(parent
.IsOk()) && (this->m_dataViewControlPtr
->RemoveItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
) ||
325 parent
.IsOk() && (this->m_dataViewControlPtr
->RemoveItems(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
));
326 // enable automatic updating again:
327 dataViewCtrlPtr
->SetDeleting(false);
328 // give allocated array space free again:
331 return noFailureFlag
;
332 } /* ItemsDeleted(wxDataViewItem const&, wxDataViewItemArray const&) */
334 virtual bool ValueChanged(wxDataViewItem
const& item
, unsigned int col
)
336 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
337 DataBrowserItemID parentID
;
339 DataBrowserPropertyID propertyID
;
341 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
344 wxCHECK_MSG(item
.IsOk(), false,_("Passed item is invalid."));
345 wxCHECK_MSG(this->GetOwner() != NULL
,false,_("Owner not initialized."));
346 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Control is wrongly initialized."));
347 parentID
= reinterpret_cast<DataBrowserItemID
>(this->GetOwner()->GetParent(item
).GetID());
348 if ((this->m_dataViewControlPtr
->GetPropertyID(col
,&propertyID
) == noErr
) &&
349 (this->m_dataViewControlPtr
->UpdateItems(parentID
,1,&itemID
,dataViewCtrlPtr
->GetColumn(col
)->GetPropertyID(),propertyID
) == noErr
))
351 // variable definition and initialization:
352 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId());
354 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
355 dataViewEvent
.SetColumn(col
);
356 dataViewEvent
.SetItem(item
);
357 // send the equivalent wxWidget event:
358 dataViewCtrlPtr
->GetEventHandler()->ProcessEvent(dataViewEvent
);
364 } /* ValueChanged(wxDataViewItem const&, unsigned int) */
366 virtual bool Cleared(void)
368 return (this->m_dataViewControlPtr
->RemoveItems() == noErr
);
369 } /* Cleared(void) */
371 virtual void Resort(void)
373 this->m_dataViewControlPtr
->Resort();
381 wxMacDataViewDataBrowserListViewControl
* m_dataViewControlPtr
;
384 // ---------------------------------------------------------
385 // wxDataViewRenderer
386 // ---------------------------------------------------------
388 wxDataViewRenderer::wxDataViewRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
389 :wxDataViewRendererBase(varianttype
,mode
,align
), m_alignment(align
), m_mode(mode
)
391 } /* wxDataViewRenderer::wxDataViewRenderer(wxString const&, wxDataViewCellMode) */
393 void wxDataViewRenderer::SetMode(wxDataViewCellMode mode
)
395 wxDataViewColumn
* dataViewColumnPtr
;
399 dataViewColumnPtr
= this->GetOwner();
400 if (dataViewColumnPtr
!= NULL
)
402 // variable definition and initialization:
403 wxDataViewCtrl
* dataViewCtrlPtr(dataViewColumnPtr
->GetOwner());
405 if (dataViewCtrlPtr
!= NULL
)
407 // variable definition and initialization:
408 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
410 if (macDataViewListCtrlPtr
!= NULL
)
412 // variable definition and initialization:
413 DataBrowserPropertyFlags flags
;
415 verify_noerr(macDataViewListCtrlPtr
->GetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),&flags
));
416 if (mode
== wxDATAVIEW_CELL_EDITABLE
)
417 flags
|= kDataBrowserPropertyIsEditable
;
419 flags
&= ~kDataBrowserPropertyIsEditable
;
420 verify_noerr(macDataViewListCtrlPtr
->SetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),flags
));
424 } /* wxDataViewRenderer::SetMode(wxDataViewCellMode) */
426 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
,wxDataViewRendererBase
)
428 // ---------------------------------------------------------
429 // wxDataViewCustomRenderer
430 // ---------------------------------------------------------
432 wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
433 :wxDataViewRenderer(varianttype
,mode
,align
), m_editorCtrlPtr(NULL
), m_DCPtr(NULL
)
435 } /* wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const&, wxDataViewCellMode) */
437 wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void)
439 if (this->m_DCPtr
!= NULL
)
440 delete this->m_DCPtr
;
441 } /* wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) */
443 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
)
445 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
446 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) : view
->GetForegroundColour();
447 dc
->SetTextForeground(col
);
448 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
451 wxDC
* wxDataViewCustomRenderer::GetDC(void)
453 if (this->m_DCPtr
== NULL
)
455 if ((GetOwner() == NULL
) || (GetOwner()->GetOwner() == NULL
))
457 this->m_DCPtr
= new wxClientDC(this->GetOwner()->GetOwner());
459 return this->m_DCPtr
;
460 } /* wxDataViewCustomRenderer::GetDC(void) */
462 bool wxDataViewCustomRenderer::Render(void)
465 } /* wxDataViewCustomRenderer::Render(void) */
467 void wxDataViewCustomRenderer::SetDC(wxDC
* newDCPtr
)
469 delete this->m_DCPtr
;
470 this->m_DCPtr
= newDCPtr
;
471 } /* wxDataViewCustomRenderer::SetDC(wxDC*) */
473 WXDataBrowserPropertyType
wxDataViewCustomRenderer::GetPropertyType(void) const
475 return kDataBrowserCustomType
;
476 } /* wxDataViewCustomRenderer::GetPropertyType(void) const */
478 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
480 // ---------------------------------------------------------
481 // wxDataViewTextRenderer
482 // ---------------------------------------------------------
484 wxDataViewTextRenderer::wxDataViewTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
485 :wxDataViewRenderer(varianttype
,mode
,align
)
487 } /* wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const&, wxDataViewCellMode, int) */
489 bool wxDataViewTextRenderer::Render(void)
491 if (this->GetValue().GetType() == this->GetVariantType())
493 // variable definition:
494 wxMacCFStringHolder
cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
496 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
);
500 } /* wxDataViewTextRenderer::Render(void) */
502 WXDataBrowserPropertyType
wxDataViewTextRenderer::GetPropertyType(void) const
504 return kDataBrowserTextType
;
505 } /* wxDataViewTextRenderer::GetPropertyType(void) const */
507 IMPLEMENT_CLASS(wxDataViewTextRenderer
,wxDataViewRenderer
)
509 // ---------------------------------------------------------
510 // wxDataViewTextRendererAttr
511 // ---------------------------------------------------------
513 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
514 :wxDataViewTextRenderer(varianttype
,mode
,align
)
516 } /* wxDataViewTextRendererAttr::wxDataViewTextRendererAttr(wxString const&, wxDataViewCellMode, int) */
518 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
,wxDataViewTextRenderer
)
520 // ---------------------------------------------------------
521 // wxDataViewTextRendererAttr
522 // ---------------------------------------------------------
524 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
525 :wxDataViewTextRenderer(varianttype
,mode
,align
)
529 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
,wxDataViewTextRenderer
)
531 // ---------------------------------------------------------
532 // wxDataViewBitmapRenderer
533 // ---------------------------------------------------------
535 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
536 :wxDataViewRenderer(varianttype
,mode
,align
)
540 bool wxDataViewBitmapRenderer::Render(void)
542 if (this->GetValue().GetType() == this->GetVariantType())
546 bitmap
<< this->GetValue();
548 return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap
.GetBitmapData()->GetIconRef()) == noErr
);
554 } /* wxDataViewBitmapRenderer::Render(void) */
556 WXDataBrowserPropertyType
wxDataViewBitmapRenderer::GetPropertyType(void) const
558 return kDataBrowserIconType
;
559 } /* wxDataViewBitmapRenderer::GetPropertyType(void) const */
561 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
,wxDataViewRenderer
)
563 // ---------------------------------------------------------
564 // wxDataViewIconTextRenderer
565 // ---------------------------------------------------------
567 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
568 :wxDataViewRenderer(varianttype
,mode
)
572 bool wxDataViewIconTextRenderer::Render(void)
574 if (this->GetValue().GetType() == this->GetVariantType())
576 // variable definition:
577 wxDataViewIconText iconText
;
579 iconText
<< this->GetValue();
581 // variable definition:
582 wxMacCFStringHolder
cfString(iconText
.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
584 return ((::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText
.GetIcon().GetHICON())) == noErr
) &&
585 (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
));
589 } /* wxDataViewIconTextRenderer::Render(void) */
591 WXDataBrowserPropertyType
wxDataViewIconTextRenderer::GetPropertyType(void) const
593 return kDataBrowserIconAndTextType
;
594 } /* wxDataViewIconTextRenderer::GetPropertyType(void) const */
596 IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer
,wxDataViewRenderer
)
599 // ---------------------------------------------------------
600 // wxDataViewToggleRenderer
601 // ---------------------------------------------------------
603 wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
604 :wxDataViewRenderer(varianttype
,mode
)
608 bool wxDataViewToggleRenderer::Render(void)
610 if (this->GetValue().GetType() == this->GetVariantType())
611 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr
);
614 } /* wxDataViewToggleRenderer::Render(void) */
616 WXDataBrowserPropertyType
wxDataViewToggleRenderer::GetPropertyType(void) const
618 return kDataBrowserCheckboxType
;
619 } /* wxDataViewToggleRenderer::GetPropertyType(void) const */
621 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
,wxDataViewRenderer
)
623 // ---------------------------------------------------------
624 // wxDataViewProgressRenderer
625 // ---------------------------------------------------------
627 wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString
const& label
, wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
628 :wxDataViewRenderer(varianttype
,mode
,align
)
632 bool wxDataViewProgressRenderer::Render(void)
634 if (this->GetValue().GetType() == this->GetVariantType())
635 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr
) &&
636 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr
) &&
637 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr
));
640 } /* wxDataViewProgressRenderer::Render(void) */
642 WXDataBrowserPropertyType
wxDataViewProgressRenderer::GetPropertyType(void) const
644 return kDataBrowserProgressBarType
;
645 } /* wxDataViewProgressRenderer::GetPropertyType(void) const */
647 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
,wxDataViewRenderer
)
649 // ---------------------------------------------------------
650 // wxDataViewDateRenderer
651 // ---------------------------------------------------------
653 wxDataViewDateRenderer::wxDataViewDateRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
654 :wxDataViewRenderer(varianttype
,mode
,align
)
658 bool wxDataViewDateRenderer::Render(void)
660 if (this->GetValue().GetType() == this->GetVariantType())
661 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan
,1904)).GetSeconds().GetLo()) == noErr
);
664 } /* wxDataViewDateRenderer::Render(void) */
666 WXDataBrowserPropertyType
wxDataViewDateRenderer::GetPropertyType(void) const
668 return kDataBrowserDateTimeType
;
669 } /* wxDataViewDateRenderer::GetPropertyType(void) const */
671 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
,wxDataViewRenderer
)
673 // ---------------------------------------------------------
675 // ---------------------------------------------------------
677 wxDataViewColumn::wxDataViewColumn(wxString
const &title
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
678 :wxDataViewColumnBase(title
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
679 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
)), m_maxWidth(30000), m_minWidth(0), m_width(width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
),
680 m_alignment(align
), m_title(title
)
682 } /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
684 wxDataViewColumn::wxDataViewColumn(wxBitmap
const& bitmap
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
685 :wxDataViewColumnBase(bitmap
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
686 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
)), m_maxWidth(30000), m_minWidth(0), m_width(width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
),
689 } /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
691 void wxDataViewColumn::SetAlignment(wxAlignment align
)
693 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
696 this->m_alignment
= align
;
697 if (dataViewCtrlPtr
!= NULL
)
699 // variable definition and initialization:
700 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
702 if (macDataViewListCtrlPtr
!= NULL
)
704 // variable definition and initialization:
705 DataBrowserListViewHeaderDesc headerDescription
;
707 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
711 case wxALIGN_CENTER_HORIZONTAL
:
712 headerDescription
.btnFontStyle
.just
= teCenter
;
715 headerDescription
.btnFontStyle
.just
= teFlushLeft
;
718 headerDescription
.btnFontStyle
.just
= teFlushRight
;
721 headerDescription
.btnFontStyle
.just
= teFlushDefault
;
723 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set alignment."));
726 } /* wxDataViewColumn::SetAlignment(wxAlignment) */
728 void wxDataViewColumn::SetBitmap(wxBitmap
const& bitmap
)
730 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
733 wxDataViewColumnBase::SetBitmap(bitmap
);
734 if (dataViewCtrlPtr
!= NULL
)
736 // variable definition and initialization:
737 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
739 if (macDataViewListCtrlPtr
!= NULL
)
741 // variable definition and initialization:
742 DataBrowserListViewHeaderDesc headerDescription
;
744 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
745 if (this->GetBitmap().Ok())
746 headerDescription
.btnContentInfo
.u
.iconRef
= this->GetBitmap().GetBitmapData()->GetIconRef();
748 headerDescription
.btnContentInfo
.u
.iconRef
= NULL
;
749 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set icon."));
752 } /* wxDataViewColumn::SetBitmap(wxBitmap const&) */
754 void wxDataViewColumn::SetFlags(int flags
)
756 this->SetHidden ((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
757 this->SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
758 this->SetSortable ((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
759 } /* wxDataViewColumn::SetFlags(int) */
761 void wxDataViewColumn::SetMaxWidth(int maxWidth
)
763 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
766 this->m_maxWidth
= maxWidth
;
767 if (dataViewCtrlPtr
!= NULL
)
769 // variable definition and initialization:
770 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
772 if (macDataViewListCtrlPtr
!= NULL
)
774 // variable definition and initialization:
775 DataBrowserListViewHeaderDesc headerDescription
;
777 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
778 headerDescription
.maximumWidth
= static_cast<UInt16
>(maxWidth
);
779 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set maximum width."));
782 } /* wxDataViewColumn::SetMaxWidth(int) */
784 void wxDataViewColumn::SetMinWidth(int minWidth
)
786 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
789 this->m_minWidth
= minWidth
;
790 if (dataViewCtrlPtr
!= NULL
)
792 // variable definition and initialization:
793 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
795 if (macDataViewListCtrlPtr
!= NULL
)
797 // variable definition and initialization:
798 DataBrowserListViewHeaderDesc headerDescription
;
800 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
801 headerDescription
.minimumWidth
= static_cast<UInt16
>(minWidth
);
802 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set minimum width."));
805 } /* wxDataViewColumn::SetMaxWidth(int) */
807 void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable
))
809 } /* wxDataViewColumn::SetResizeable(bool) */
811 void wxDataViewColumn::SetSortable(bool sortable
)
813 // variable definition and initialization:
814 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
816 if (dataViewCtrlPtr
!= NULL
)
818 // variable definition and initialization:
819 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
821 if (macDataViewListCtrlPtr
!= NULL
)
823 // variable definition and initialization:
824 DataBrowserPropertyFlags flags
;
826 wxCHECK_RET(macDataViewListCtrlPtr
->GetPropertyFlags(this->GetPropertyID(),&flags
) == noErr
,_("Could not get property flags."));
829 this->m_flags
|= wxDATAVIEW_COL_SORTABLE
;
830 flags
|= kDataBrowserListViewSortableColumn
;
834 this->m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
835 flags
&= ~kDataBrowserPropertyIsEditable
;
837 wxCHECK_RET(macDataViewListCtrlPtr
->SetPropertyFlags(this->GetPropertyID(),flags
) == noErr
,_("Could not set property flags."));
840 } /* wxDataViewColumn::SetSortable(bool) */
842 void wxDataViewColumn::SetSortOrder(bool ascending
)
844 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
847 this->m_ascending
= ascending
;
848 if (dataViewCtrlPtr
!= NULL
)
850 // variable definition and initialization:
851 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
853 if (macDataViewListCtrlPtr
!= NULL
)
855 // variable definition and initialization:
856 DataBrowserListViewHeaderDesc headerDescription
;
858 verify_noerr(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
));
860 headerDescription
.initialOrder
= kDataBrowserOrderIncreasing
;
862 headerDescription
.initialOrder
= kDataBrowserOrderDecreasing
;
863 verify_noerr(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
));
864 macDataViewListCtrlPtr
->SetSortProperty(this->GetPropertyID());
867 } /* wxDataViewColumn::SetSortOrder(bool) */
869 void wxDataViewColumn::SetTitle(wxString
const& title
)
871 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
874 this->m_title
= title
;
875 if (dataViewCtrlPtr
!= NULL
)
877 // variable definition and initialization:
878 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
880 if (macDataViewListCtrlPtr
!= NULL
)
882 // variable definition and initialization:
883 DataBrowserListViewHeaderDesc headerDescription
;
884 wxMacCFStringHolder
cfTitle(title
,(dataViewCtrlPtr
->GetFont().Ok() ? dataViewCtrlPtr
->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
886 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
887 headerDescription
.titleString
= cfTitle
;
888 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set header description."));
891 } /* wxDataViewColumn::SetTitle(wxString const&) */
893 void wxDataViewColumn::SetWidth(int width
)
895 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
898 if ((width
>= this->m_minWidth
) && (width
<= this->m_maxWidth
))
900 this->m_width
= width
;
901 if (dataViewCtrlPtr
!= NULL
)
903 // variable definition and initialization:
904 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
906 if (macDataViewListCtrlPtr
!= NULL
)
907 wxCHECK_RET(macDataViewListCtrlPtr
->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16
>(width
)) == noErr
,_("Could not set column width."));
910 } /* wxDataViewColumn::SetWidth(int) */
912 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
,wxDataViewColumnBase
)
914 //-----------------------------------------------------------------------------
916 //-----------------------------------------------------------------------------
918 void wxDataViewCtrl::Init(void)
920 this->m_Deleting
= false;
921 this->m_macIsUserPane
= false;
922 this->m_cgContext
= NULL
;
923 } /* wxDataViewCtrl::Init(void) */
925 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
927 if (!(this->wxControl::Create(parent
,id
,pos
,size
,(style
| wxSUNKEN_BORDER
) & ~(wxHSCROLL
| wxVSCROLL
),validator
)))
931 MacSetClipChildren(true) ;
934 this->m_peer
= new wxMacDataViewDataBrowserListViewControl(this,pos
,size
,style
);
935 this->MacPostControlCreate(pos
,size
);
936 ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(this->m_peer
->GetControlRef()),true);
938 InstallControlEventHandler(this->m_peer
->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList
),eventList
,this,NULL
);
941 } /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
943 bool wxDataViewCtrl::AssociateModel(wxDataViewModel
* model
)
945 if (!wxDataViewCtrlBase::AssociateModel(model
))
948 model
->AddNotifier(new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl
*>(this->m_peer
)));
951 } /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
953 bool wxDataViewCtrl::AppendColumn(wxDataViewColumn
* columnPtr
)
955 DataBrowserListViewColumnDesc columnDescription
;
957 DataBrowserPropertyID NewPropertyID
;
959 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
961 wxMacCFStringHolder
title(columnPtr
->GetTitle(),this->m_font
.Ok() ? this->m_font
.GetEncoding() : wxLocale::GetSystemEncoding());
964 // first, some error checking:
965 wxCHECK_MSG(MacDataViewListCtrlPtr
!= NULL
, false,_("m_peer is not or incorrectly initialized"));
966 wxCHECK_MSG(columnPtr
!= NULL
, false,_("Column pointer must not be NULL."));
967 wxCHECK_MSG(columnPtr
->GetRenderer() != NULL
, false,_("Column does not have a renderer."));
968 wxCHECK_MSG(this->GetModel() != NULL
, false,_("No model associated with control."));
969 wxCHECK_MSG((columnPtr
->GetModelColumn() >= 0) &&
970 (columnPtr
->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
972 // try to get new ID for the column:
973 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetFreePropertyID(&NewPropertyID
) == noErr
,false,_("Cannot create new column's ID. Probably max. number of columns reached."));
974 // full column variable initialization:
975 columnPtr
->SetPropertyID(NewPropertyID
);
976 // add column to wxWidget's internal structure:
977 wxCHECK_MSG(this->wxDataViewCtrlBase::AppendColumn(columnPtr
) &&
978 this->m_ColumnPointers
.insert(ColumnPointerHashMapType::value_type(NewPropertyID
,columnPtr
)).second
,false,_("Could not add column to internal structures."));
979 // create a column description and add column to the native control:
980 wxCHECK_MSG(::InitializeColumnDescription(columnDescription
,columnPtr
,NewPropertyID
,title
), false,_("Column description could not be initialized."));
981 wxCHECK_MSG(MacDataViewListCtrlPtr
->AddColumn(&columnDescription
,kDataBrowserListViewAppendColumn
) == noErr
,false,_("Column could not be added."));
983 // final adjustments for the layout:
984 wxCHECK_MSG(MacDataViewListCtrlPtr
->SetColumnWidth(NewPropertyID
,columnPtr
->GetWidth()) == noErr
,false,_("Column width could not be set."));
986 // make sure that the data is up-to-date...
987 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
988 // otherwise ask the control to 'update' the data in the newly appended column:
989 if (this->GetColumnCount() == 1)
991 this->SetExpanderColumn(columnPtr
);
992 this->AddChildrenLevel(wxDataViewItem());
995 MacDataViewListCtrlPtr
->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,NewPropertyID
);
998 } /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
1000 bool wxDataViewCtrl::ClearColumns(void)
1002 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1005 while (this->m_ColumnPointers
.begin() != this->m_ColumnPointers
.end())
1007 wxCHECK_MSG(MacDataViewListCtrlPtr
->RemoveColumnByProperty(this->m_ColumnPointers
.begin()->first
) == noErr
,false,_("Could not remove column."));
1008 delete this->m_ColumnPointers
.begin()->second
;
1009 this->m_ColumnPointers
.erase(this->m_ColumnPointers
.begin());
1012 } /* wxDataViewCtrl::ClearColumns(void) */
1014 bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn
* columnPtr
)
1016 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1019 if ((MacDataViewListCtrlPtr
->RemoveColumnByProperty(columnPtr
->GetPropertyID()) == noErr
) && (this->m_ColumnPointers
.erase(columnPtr
->GetPropertyID()) > 0))
1026 } /* wxDataViewCtrl::DeleteColumn(wxDataViewColumn*) */
1028 wxDataViewColumn
* wxDataViewCtrl::GetColumn(unsigned int pos
) const
1030 DataBrowserPropertyID propertyID
;
1032 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1035 if (MacDataViewListCtrlPtr
->GetPropertyID(pos
,&propertyID
) == noErr
)
1037 // variable definition:
1038 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
1040 if (Result
!= this->m_ColumnPointers
.end())
1041 return Result
->second
;
1047 } /* wxDataViewCtrl::GetColumn(unsigned int pos) const */
1049 unsigned int wxDataViewCtrl::GetColumnCount(void) const
1051 return this->m_ColumnPointers
.size();
1052 } /* wxDataViewCtrl::GetColumnCount(void) const */
1054 int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn
const* columnPtr
) const
1056 if (columnPtr
!= NULL
)
1058 // variable definition and initialization:
1059 DataBrowserTableViewColumnIndex Position
;
1060 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1062 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetColumnIndex(columnPtr
->GetPropertyID(),&Position
) == noErr
,-1,_("Could not determine column's position"));
1063 return static_cast<int>(Position
);
1067 } /* wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const*) const */
1069 bool wxDataViewCtrl::PrependColumn(wxDataViewColumn
* columnPtr
)
1071 DataBrowserListViewColumnDesc columnDescription
;
1073 DataBrowserPropertyID NewPropertyID
;
1075 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1077 wxMacCFStringHolder
title(columnPtr
->GetTitle(),this->m_font
.Ok() ? this->m_font
.GetEncoding() : wxLocale::GetSystemEncoding());
1080 // first, some error checking:
1081 wxCHECK_MSG(MacDataViewListCtrlPtr
!= NULL
, false,_("m_peer is not or incorrectly initialized"));
1082 wxCHECK_MSG(columnPtr
!= NULL
, false,_("Column pointer must not be NULL."));
1083 wxCHECK_MSG(columnPtr
->GetRenderer() != NULL
, false,_("Column does not have a renderer."));
1084 wxCHECK_MSG(this->GetModel() != NULL
, false,_("No model associated with control."));
1085 wxCHECK_MSG((columnPtr
->GetModelColumn() >= 0) &&
1086 (columnPtr
->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
1088 // try to get new ID for the column:
1089 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetFreePropertyID(&NewPropertyID
) == noErr
,false,_("Cannot create new column's ID. Probably max. number of columns reached."));
1090 // full column variable initialization:
1091 columnPtr
->SetPropertyID(NewPropertyID
);
1092 // add column to wxWidget's internal structure:
1093 wxCHECK_MSG(this->wxDataViewCtrlBase::AppendColumn(columnPtr
) &&
1094 this->m_ColumnPointers
.insert(ColumnPointerHashMapType::value_type(NewPropertyID
,columnPtr
)).second
,false,_("Could not add column to internal structures."));
1095 // create a column description and add column to the native control:
1096 wxCHECK_MSG(::InitializeColumnDescription(columnDescription
,columnPtr
,NewPropertyID
,title
),false,_("Column description could not be initialized."));
1097 wxCHECK_MSG(MacDataViewListCtrlPtr
->AddColumn(&columnDescription
,0) == noErr
, false,_("Column could not be added."));
1099 // final adjustments for the layout:
1100 wxCHECK_MSG(MacDataViewListCtrlPtr
->SetColumnWidth(NewPropertyID
,columnPtr
->GetWidth()) == noErr
,false,_("Column width could not be set."));
1102 // make sure that the data is up-to-date...
1103 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
1104 // otherwise ask the control to 'update' the data in the newly appended column:
1105 if (this->GetColumnCount() == 1)
1107 this->SetExpanderColumn(columnPtr
);
1108 this->AddChildrenLevel(wxDataViewItem());
1111 MacDataViewListCtrlPtr
->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,NewPropertyID
);
1114 } /* wxDataViewCtrl::PrependColumn(wxDataViewColumn*) */
1116 void wxDataViewCtrl::Collapse(wxDataViewItem
const& item
)
1118 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1121 MacDataViewListCtrlPtr
->CloseContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1122 } /* wxDataViewCtrl::Collapse(wxDataViewItem const&) */
1124 void wxDataViewCtrl::EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
)
1128 // variable definition and initialization:
1129 DataBrowserPropertyID propertyID
;
1130 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1132 if (columnPtr
!= NULL
)
1133 propertyID
= columnPtr
->GetPropertyID();
1135 propertyID
= kDataBrowserNoItem
;
1136 MacDataViewListCtrlPtr
->RevealItem(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),propertyID
,kDataBrowserRevealOnly
);
1138 } /* wxDataViewCtrl::EnsureVisible(wxDataViewItem const&, wxDataViewColumn const*) */
1140 void wxDataViewCtrl::Expand(wxDataViewItem
const& item
)
1142 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1145 MacDataViewListCtrlPtr
->OpenContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1146 } /* wxDataViewCtrl::Expand(wxDataViewItem const&) */
1148 wxDataViewColumn
* wxDataViewCtrl::GetSortingColumn(void) const
1150 DataBrowserPropertyID propertyID
;
1152 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1155 if (MacDataViewListCtrlPtr
->GetSortProperty(&propertyID
) == noErr
)
1156 return this->GetColumnPtr(propertyID
);
1159 } /* wxDataViewCtrl::GetSortingColumn(void) const */
1161 unsigned int wxDataViewCtrl::GetCount(void) const
1163 ItemCount noOfItems
;
1166 wxCHECK_MSG(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
)->GetItemCount(&noOfItems
) == noErr
,0,_("Could not determine number of items"));
1168 } /* wxDataViewCtrl::GetCount(void) const */
1170 wxRect
wxDataViewCtrl::GetItemRect(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
) const
1172 if (item
.IsOk() && (columnPtr
!= NULL
))
1174 // variable definition:
1176 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1178 if (MacDataViewListCtrlPtr
->GetPartBounds(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),columnPtr
->GetPropertyID(),kDataBrowserPropertyContentPart
,&MacRectangle
) == noErr
)
1180 // variable definition:
1183 ::wxMacNativeToRect(&MacRectangle
,&rectangle
);
1191 } /* wxDataViewCtrl::GetItemRect(wxDataViewItem const&, unsigned int) const */
1193 wxDataViewItem
wxDataViewCtrl::GetSelection(void) const
1195 wxArrayDataBrowserItemID itemIDs
;
1197 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1200 if (MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
) > 0)
1201 return wxDataViewItem(reinterpret_cast<void*>(itemIDs
[0]));
1203 return wxDataViewItem();
1204 } /* wxDataViewCtrl::GetSelection(void) const */
1206 int wxDataViewCtrl::GetSelections(wxDataViewItemArray
& sel
) const
1208 size_t NoOfSelectedItems
;
1210 wxArrayDataBrowserItemID itemIDs
;
1212 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1215 NoOfSelectedItems
= MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
);
1217 sel
.SetCount(NoOfSelectedItems
);
1218 for (size_t i
=0; i
<NoOfSelectedItems
; ++i
)
1219 sel
[i
] = wxDataViewItem(reinterpret_cast<void*>(itemIDs
[i
]));
1220 return static_cast<int>(NoOfSelectedItems
);
1221 } /* wxDataViewCtrl::GetSelections(wxDataViewItemArray&) const */
1223 void wxDataViewCtrl::HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const
1225 item
= wxDataViewItem();
1227 } /* wxDataViewCtrl::HitTest(wxPoint const&, wxDataViewItem&, wxDataViewColumn*&) const */
1229 bool wxDataViewCtrl::IsSelected(wxDataViewItem
const& item
) const
1231 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1234 return MacDataViewListCtrlPtr
->IsItemSelected(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1235 } /* wxDataViewCtrl::IsSelected(wxDataViewItem const&) const */
1237 void wxDataViewCtrl::SelectAll(void)
1239 DataBrowserItemID
* itemIDPtr
;
1241 Handle
handle(::NewHandle(0));
1245 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1248 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1249 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1251 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1252 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsAssign
);
1254 DisposeHandle(handle
);
1255 } /* wxDataViewCtrl::SelectAll(void) */
1257 void wxDataViewCtrl::Select(wxDataViewItem
const& item
)
1261 // variable definition and initialization:
1262 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1263 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1265 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsAdd
);
1267 } /* wxDataViewCtrl::Select(wxDataViewItem const&) */
1269 void wxDataViewCtrl::SetSelections(wxDataViewItemArray
const& sel
)
1271 size_t const NoOfSelections
= sel
.GetCount();
1273 DataBrowserItemID
* itemIDs
;
1275 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1278 itemIDs
= new DataBrowserItemID
[NoOfSelections
];
1279 for (size_t i
=0; i
<NoOfSelections
; ++i
)
1280 itemIDs
[i
] = reinterpret_cast<DataBrowserItemID
>(sel
[i
].GetID());
1281 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfSelections
,itemIDs
,kDataBrowserItemsAssign
);
1283 } /* wxDataViewCtrl::SetSelections(wxDataViewItemArray const&) */
1285 void wxDataViewCtrl::Unselect(wxDataViewItem
const& item
)
1289 // variable definition and initialization:
1290 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1291 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1293 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsRemove
);
1295 } /* wxDataViewCtrl::Unselect(wxDataViewItem const&) */
1297 void wxDataViewCtrl::UnselectAll(void)
1299 DataBrowserItemID
* itemIDPtr
;
1301 Handle
handle(::NewHandle(0));
1305 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1308 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1309 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1311 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1312 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsRemove
);
1314 DisposeHandle(handle
);
1315 } /* wxDataViewCtrl::UnselectAll(void) */
1318 void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem
const& parentItem
)
1322 wxDataViewItemArray items
;
1325 wxCHECK_RET(this->GetModel() != NULL
,_("Model pointer not initialized."));
1326 NoOfChildren
= this->GetModel()->GetChildren(parentItem
,items
);
1328 for (int i
=0; i
<NoOfChildren
; ++i
)
1329 (void) this->GetModel()->ItemAdded(parentItem
,items
[i
]);
1331 (void) this->GetModel()->ItemsAdded(parentItem
,items
);
1333 } /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
1335 wxDataViewColumn
* wxDataViewCtrl::GetColumnPtr(WXDataBrowserPropertyID propertyID
) const
1337 // variable definition:
1338 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
1340 if (Result
!= this->m_ColumnPointers
.end())
1341 return Result
->second
;
1344 } /* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID) const */
1346 // inherited methods from wxDataViewCtrlBase
1347 void wxDataViewCtrl::DoSetExpanderColumn(void)
1349 if (this->GetExpanderColumn() != NULL
)
1351 // variable definition and initialization:
1352 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1354 (void) MacDataViewListCtrlPtr
->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID());
1356 } /* wxDataViewCtrl::DoSetExpanderColumn(void) */
1358 void wxDataViewCtrl::DoSetIndent(void)
1360 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1363 (void) MacDataViewListCtrlPtr
->SetIndent(static_cast<float>(this->GetIndent()));
1364 } /* wxDataViewCtrl::DoSetIndent(void) */
1367 void wxDataViewCtrl::OnSize(wxSizeEvent
& event
)
1369 unsigned int const NoOfColumns
= this->GetColumnCount();
1372 for (unsigned int i
=0; i
<NoOfColumns
; ++i
)
1374 // variable definition and initialization:
1375 wxDataViewColumn
* dataViewColumnPtr(this->GetColumn(i
));
1377 if (dataViewColumnPtr
!= NULL
)
1379 // variable definition and initialization:
1380 wxDataViewCustomRenderer
* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer()));
1382 if (dataViewCustomRendererPtr
!= NULL
)
1383 dataViewCustomRendererPtr
->SetDC(NULL
); // reset DC because DC has changed
1387 } /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
1389 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
,wxDataViewCtrlBase
)
1391 BEGIN_EVENT_TABLE(wxDataViewCtrl
,wxDataViewCtrlBase
)
1392 EVT_SIZE(wxDataViewCtrl::OnSize
)
1396 // !wxUSE_GENERICDATAVIEWCTRL
1399 // wxUSE_DATAVIEWCTRL