1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/datavgen.cpp
3 // Purpose: wxDataViewCtrl native mac implementation
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #if wxUSE_DATAVIEWCTRL
15 #include "wx/dataview.h"
17 #if !defined(wxUSE_GENERICDATAVIEWCTRL) || (wxUSE_GENERICDATAVIEWCTRL == 0)
21 #include "wx/mac/carbon/databrow.h"
25 #include "wx/settings.h"
26 #include "wx/dcclient.h"
30 #include "wx/renderer.h"
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 // a list of all catchable events:
37 static EventTypeSpec
const eventList
[] =
39 {kEventClassControl
, kEventControlDraw
},
40 {kEventClassControl
, kEventControlHit
}
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
47 static pascal OSStatus
wxMacDataViewCtrlEventHandler(EventHandlerCallRef handler
, EventRef EventReference
, void* Data
)
49 wxDataViewCtrl
* DataViewCtrlPtr((wxDataViewCtrl
*) Data
); // the 'Data' variable always contains a pointer to the data view control that installed the handler
51 wxMacCarbonEvent
CarbonEvent(EventReference
) ;
54 switch (GetEventKind(EventReference
))
56 case kEventControlDraw
:
60 DataViewCtrlPtr
->MacSetDrawingContext(CarbonEvent
.GetParameter
<CGContextRef
>(kEventParamCGContextRef
,typeCGContextRef
));
61 status
= ::CallNextEventHandler(handler
,EventReference
);
62 DataViewCtrlPtr
->MacSetDrawingContext(NULL
);
65 case kEventControlHit
:
66 if (CarbonEvent
.GetParameter
<ControlPartCode
>(kEventParamControlPart
,typeControlPartCode
) == kControlButtonPart
) // we only care about the header
68 ControlRef controlReference
;
69 DataBrowserPropertyID columnPropertyID
;
70 unsigned long columnIndex
;
72 wxDataViewEvent
DataViewEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
,DataViewCtrlPtr
->GetId());
74 CarbonEvent
.GetParameter(kEventParamDirectObject
,&controlReference
);
75 // determine the column that triggered the event (this is the column that is responsible for sorting the data view):
76 status
= ::GetDataBrowserSortProperty(controlReference
,&columnPropertyID
);
77 wxCHECK(status
== noErr
,status
);
78 status
= ::GetDataBrowserTableViewColumnPosition(controlReference
,columnPropertyID
,&columnIndex
);
79 if (status
== errDataBrowserPropertyNotFound
) // user clicked into part of the header that does not have a property
80 return ::CallNextEventHandler(handler
,EventReference
);
81 wxCHECK(status
== noErr
,status
);
82 // initialize wxWidget event handler:
83 DataViewEvent
.SetEventObject(DataViewCtrlPtr
);
84 DataViewEvent
.SetColumn(columnIndex
);
85 DataViewEvent
.SetDataViewColumn(DataViewCtrlPtr
->GetColumn(columnIndex
));
86 // finally sent the equivalent wxWidget event:
87 DataViewCtrlPtr
->HandleWindowEvent(DataViewEvent
);
88 return ::CallNextEventHandler(handler
,EventReference
);
91 return eventNotHandledErr
;
94 return eventNotHandledErr
;
95 } /* wxMacDataViewCtrlEventHandler(EventHandlerCallRef, EventRef, void*) */
97 static DataBrowserItemID
* CreateDataBrowserItemIDArray(size_t& noOfEntries
, wxDataViewItemArray
const& items
) // returns a newly allocated pointer to valid data browser item IDs
99 size_t const noOfItems
= items
.GetCount();
101 DataBrowserItemID
* itemIDs(new DataBrowserItemID
[noOfItems
]);
104 // convert all valid data view items to data browser items
106 for (size_t i
=0; i
<noOfItems
; ++i
)
109 itemIDs
[noOfEntries
] = reinterpret_cast<DataBrowserItemID
>(items
[i
].GetID());
114 } /* CreateDataBrowserItemIDArray(size_t&, wxDataViewItemArray const&) */
116 static bool InitializeColumnDescription(DataBrowserListViewColumnDesc
& columnDescription
, wxDataViewColumn
const* columnPtr
, DataBrowserPropertyID columnPropertyID
, 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
->IsSortable())
123 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewSortableColumn
;
125 if (columnPtr
->IsMovable())
126 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewMovableColumn
;
128 if (columnPtr
->GetRenderer()->GetMode() == wxDATAVIEW_CELL_EDITABLE
)
129 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserPropertyIsEditable
;
130 if ((columnDescription
.propertyDesc
.propertyType
== kDataBrowserTextType
) ||
131 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserIconAndTextType
) ||
132 (columnDescription
.propertyDesc
.propertyType
== kDataBrowserDateTimeType
))
133 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
; // enables generally the possibility to have user input for the mentioned types
134 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
135 columnDescription
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
137 // set header's properties:
138 columnDescription
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
139 if (columnPtr
->IsResizeable())
141 columnDescription
.headerBtnDesc
.minimumWidth
= 0;
142 columnDescription
.headerBtnDesc
.maximumWidth
= 30000; // 32767 is the theoretical maximum though but 30000 looks nicer
146 columnDescription
.headerBtnDesc
.minimumWidth
= columnPtr
->GetWidth();
147 columnDescription
.headerBtnDesc
.maximumWidth
= columnPtr
->GetWidth();
149 columnDescription
.headerBtnDesc
.titleOffset
= 0;
150 columnDescription
.headerBtnDesc
.titleString
= ::CFStringCreateCopy(kCFAllocatorDefault
,title
);
151 columnDescription
.headerBtnDesc
.initialOrder
= kDataBrowserOrderIncreasing
; // choose one of the orders as "undefined" is not supported anyway (s. ControlDefs.h in the HIToolbox framework)
152 columnDescription
.headerBtnDesc
.btnFontStyle
.flags
= kControlUseFontMask
| kControlUseJustMask
;
153 switch (columnPtr
->GetAlignment())
156 case wxALIGN_CENTER_HORIZONTAL
:
157 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teCenter
;
160 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushLeft
;
163 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushRight
;
166 columnDescription
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
168 columnDescription
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
169 columnDescription
.headerBtnDesc
.btnFontStyle
.style
= normal
;
170 columnDescription
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentIconRef
;
171 if (columnPtr
->GetBitmap().Ok())
172 columnDescription
.headerBtnDesc
.btnContentInfo
.u
.iconRef
= columnPtr
->GetBitmap().GetIconRef();
175 } /* InitializeColumnDescription(DataBrowserListViewColumnDesc&, wxDataViewColumn const*, DataBrowserPropertyID, wxCFStringRef const&) */
177 //-----------------------------------------------------------------------------
178 // local function pointers
179 //-----------------------------------------------------------------------------
181 DEFINE_ONE_SHOT_HANDLER_GETTER(wxMacDataViewCtrlEventHandler
)
183 // ---------------------------------------------------------
184 // wxMacDataViewModelNotifier
185 // ---------------------------------------------------------
187 class wxMacDataViewModelNotifier
: public wxDataViewModelNotifier
190 wxMacDataViewModelNotifier(wxMacDataViewDataBrowserListViewControl
* initDataViewControlPtr
) : m_dataViewControlPtr(initDataViewControlPtr
)
194 virtual bool ItemAdded(const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
196 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
199 wxCHECK_MSG(item
.IsOk(),false,_("Added item is invalid."));
200 return (!(parent
.IsOk()) && (this->m_dataViewControlPtr
->AddItem(kDataBrowserNoItem
,&itemID
) == noErr
) ||
201 parent
.IsOk() && (this->m_dataViewControlPtr
->AddItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
) == noErr
));
202 } /* ItemAdded(wxDataViewItem const&, wxDataViewItem const&) */
204 virtual bool ItemsAdded(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
208 DataBrowserItemID
* itemIDs
;
213 // convert all valid data view items to data browser items:
214 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
215 // insert all valid items into control:
216 noFailureFlag
= ((noOfEntries
== 0) ||
217 !(parent
.IsOk()) && (this->m_dataViewControlPtr
->AddItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
) ||
218 parent
.IsOk() && (this->m_dataViewControlPtr
->AddItems(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
));
219 // give allocated array space free again:
222 return noFailureFlag
;
223 } /* ItemsAdded(wxDataViewItem const&, wxDataViewItemArray const&) */
225 virtual bool ItemChanged(wxDataViewItem
const& item
)
227 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
230 wxCHECK_MSG(item
.IsOk(),false,_("Changed item is invalid."));
231 if (this->m_dataViewControlPtr
->UpdateItems(&itemID
) == noErr
)
233 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
235 // sent the equivalent wxWidget event:
236 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId()); // variable defintion
238 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
239 dataViewEvent
.SetItem(item
);
240 // sent the equivalent wxWidget event:
241 dataViewCtrlPtr
->HandleWindowEvent(dataViewEvent
);
247 } /* ItemChanged(wxDataViewItem const&) */
249 virtual bool ItemsChanged(wxDataViewItemArray
const& items
)
253 DataBrowserItemID
* itemIDs
;
258 // convert all valid data view items to data browser items:
259 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
260 // change items (ATTENTION: ONLY ITEMS OF THE ROOT ARE CHANGED BECAUSE THE PARENT PARAMETER IS MISSING):
261 noFailureFlag
= (this->m_dataViewControlPtr
->UpdateItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
,kDataBrowserItemNoProperty
) == noErr
);
264 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
266 // send for all changed items a wxWidget event:
267 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId()); // variable defintion
269 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
270 for (size_t i
=0; i
<noOfEntries
; ++i
)
272 dataViewEvent
.SetItem(reinterpret_cast<void*>(itemIDs
[i
]));
273 dataViewCtrlPtr
->HandleWindowEvent(dataViewEvent
);
276 // release allocated array space:
279 return noFailureFlag
;
280 } /* ItemsChanged(wxDataViewItem const&) */
282 virtual bool ItemDeleted(wxDataViewItem
const& parent
, wxDataViewItem
const& item
)
286 // variable definition and initialization:
287 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
288 OSStatus errorStatus
;
289 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
291 // when this method is called and currently an item is being edited this item may have already been deleted in the model (the passed item and the being edited item have
292 // not to be identical because the being edited item might be below the passed item in the hierarchy);
293 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
294 // has been started and that variables can currently not be updated even when requested by the system:
295 dataViewCtrlPtr
->SetDeleting(true);
296 errorStatus
= this->m_dataViewControlPtr
->RemoveItem(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),&itemID
);
297 // enable automatic updating again:
298 dataViewCtrlPtr
->SetDeleting(false);
299 return (errorStatus
== noErr
);
303 } /* ItemDeleted(wxDataViewItem const&, wxDataViewItem const&) */
305 virtual bool ItemsDeleted(wxDataViewItem
const& parent
, wxDataViewItemArray
const& items
)
309 DataBrowserItemID
* itemIDs
;
311 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
316 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
,false,_("Data view control is not correctly initialized"));
317 // convert all valid data view items to data browser items:
318 itemIDs
= ::CreateDataBrowserItemIDArray(noOfEntries
,items
);
319 // when this method is called and currently an item is being edited this item may have already been deleted in the model (the passed item and the being edited item have
320 // not to be identical because the being edited item might be below the passed item in the hierarchy);
321 // to prevent the control trying to ask the model to update an already deleted item the control is informed that currently a deleting process
322 // has been started and that variables can currently not be updated even when requested by the system:
323 dataViewCtrlPtr
->SetDeleting(true);
324 // insert all valid items into control:
325 noFailureFlag
= ((noOfEntries
== 0) ||
326 !(parent
.IsOk()) && (this->m_dataViewControlPtr
->RemoveItems(kDataBrowserNoItem
,noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
) ||
327 parent
.IsOk() && (this->m_dataViewControlPtr
->RemoveItems(reinterpret_cast<DataBrowserItemID
>(parent
.GetID()),noOfEntries
,itemIDs
,kDataBrowserItemNoProperty
) == noErr
));
328 // enable automatic updating again:
329 dataViewCtrlPtr
->SetDeleting(false);
330 // give allocated array space free again:
333 return noFailureFlag
;
334 } /* ItemsDeleted(wxDataViewItem const&, wxDataViewItemArray const&) */
336 virtual bool ValueChanged(wxDataViewItem
const& item
, unsigned int col
)
338 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
339 DataBrowserItemID parentID
;
341 DataBrowserPropertyID propertyID
;
343 wxDataViewCtrl
* dataViewCtrlPtr(dynamic_cast<wxDataViewCtrl
*>(this->m_dataViewControlPtr
->GetPeer()));
346 wxCHECK_MSG(item
.IsOk(), false,_("Passed item is invalid."));
347 wxCHECK_MSG(this->GetOwner() != NULL
,false,_("Owner not initialized."));
348 wxCHECK_MSG(dataViewCtrlPtr
!= NULL
, false,_("Control is wrongly initialized."));
349 parentID
= reinterpret_cast<DataBrowserItemID
>(this->GetOwner()->GetParent(item
).GetID());
350 if ((this->m_dataViewControlPtr
->GetPropertyID(col
,&propertyID
) == noErr
) &&
351 (this->m_dataViewControlPtr
->UpdateItems(parentID
,1,&itemID
,dataViewCtrlPtr
->GetColumn(col
)->GetPropertyID(),propertyID
) == noErr
))
353 // variable definition and initialization:
354 wxDataViewEvent
dataViewEvent(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
,dataViewCtrlPtr
->GetId());
356 dataViewEvent
.SetEventObject(dataViewCtrlPtr
);
357 dataViewEvent
.SetColumn(col
);
358 dataViewEvent
.SetItem(item
);
359 // send the equivalent wxWidget event:
360 dataViewCtrlPtr
->HandleWindowEvent(dataViewEvent
);
366 } /* ValueChanged(wxDataViewItem const&, unsigned int) */
368 virtual bool Cleared(void)
370 bool noFailureFlag
= (this->m_dataViewControlPtr
->RemoveItems() == noErr
);
372 wxDataViewItemArray array
;
373 GetOwner()->GetChildren( item
, array
);
374 ItemsAdded( item
, array
);
375 return noFailureFlag
;
376 } /* Cleared(void) */
378 virtual void Resort(void)
380 this->m_dataViewControlPtr
->Resort();
388 wxMacDataViewDataBrowserListViewControl
* m_dataViewControlPtr
;
391 // ---------------------------------------------------------
392 // wxDataViewRenderer
393 // ---------------------------------------------------------
395 wxDataViewRenderer::wxDataViewRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
396 :wxDataViewRendererBase(varianttype
,mode
,align
), m_alignment(align
), m_mode(mode
)
398 } /* wxDataViewRenderer::wxDataViewRenderer(wxString const&, wxDataViewCellMode) */
400 void wxDataViewRenderer::SetMode(wxDataViewCellMode mode
)
402 wxDataViewColumn
* dataViewColumnPtr
;
406 dataViewColumnPtr
= this->GetOwner();
407 if (dataViewColumnPtr
!= NULL
)
409 // variable definition and initialization:
410 wxDataViewCtrl
* dataViewCtrlPtr(dataViewColumnPtr
->GetOwner());
412 if (dataViewCtrlPtr
!= NULL
)
414 // variable definition and initialization:
415 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
417 if (macDataViewListCtrlPtr
!= NULL
)
419 // variable definition and initialization:
420 DataBrowserPropertyFlags flags
;
422 verify_noerr(macDataViewListCtrlPtr
->GetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),&flags
));
423 if (mode
== wxDATAVIEW_CELL_EDITABLE
)
424 flags
|= kDataBrowserPropertyIsEditable
;
426 flags
&= ~kDataBrowserPropertyIsEditable
;
427 verify_noerr(macDataViewListCtrlPtr
->SetPropertyFlags(dataViewColumnPtr
->GetPropertyID(),flags
));
431 } /* wxDataViewRenderer::SetMode(wxDataViewCellMode) */
433 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer
,wxDataViewRendererBase
)
435 // ---------------------------------------------------------
436 // wxDataViewCustomRenderer
437 // ---------------------------------------------------------
439 wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
440 :wxDataViewRenderer(varianttype
,mode
,align
), m_editorCtrlPtr(NULL
), m_DCPtr(NULL
)
442 } /* wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const&, wxDataViewCellMode) */
444 wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void)
446 if (this->m_DCPtr
!= NULL
)
447 delete this->m_DCPtr
;
448 } /* wxDataViewCustomRenderer::~wxDataViewCustomRenderer(void) */
450 void wxDataViewCustomRenderer::RenderText( const wxString
&text
, int xoffset
, wxRect cell
, wxDC
*dc
, int state
)
452 wxDataViewCtrl
*view
= GetOwner()->GetOwner();
453 wxColour col
= (state
& wxDATAVIEW_CELL_SELECTED
) ? *wxWHITE
: view
->GetForegroundColour();
454 dc
->SetTextForeground(col
);
455 dc
->DrawText( text
, cell
.x
+ xoffset
, cell
.y
+ ((cell
.height
- dc
->GetCharHeight()) / 2));
458 wxDC
* wxDataViewCustomRenderer::GetDC(void)
460 if (this->m_DCPtr
== NULL
)
462 if ((GetOwner() == NULL
) || (GetOwner()->GetOwner() == NULL
))
464 this->m_DCPtr
= new wxWindowDC(this->GetOwner()->GetOwner());
466 return this->m_DCPtr
;
467 } /* wxDataViewCustomRenderer::GetDC(void) */
469 bool wxDataViewCustomRenderer::Render(void)
472 } /* wxDataViewCustomRenderer::Render(void) */
474 void wxDataViewCustomRenderer::SetDC(wxDC
* newDCPtr
)
476 delete this->m_DCPtr
;
477 this->m_DCPtr
= newDCPtr
;
478 } /* wxDataViewCustomRenderer::SetDC(wxDC*) */
480 WXDataBrowserPropertyType
wxDataViewCustomRenderer::GetPropertyType(void) const
482 return kDataBrowserCustomType
;
483 } /* wxDataViewCustomRenderer::GetPropertyType(void) const */
485 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer
, wxDataViewRenderer
)
487 // ---------------------------------------------------------
488 // wxDataViewTextRenderer
489 // ---------------------------------------------------------
491 wxDataViewTextRenderer::wxDataViewTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
492 :wxDataViewRenderer(varianttype
,mode
,align
)
494 } /* wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const&, wxDataViewCellMode, int) */
496 bool wxDataViewTextRenderer::Render(void)
498 if (this->GetValue().GetType() == this->GetVariantType())
500 // variable definition:
501 wxCFStringRef
cfString(this->GetValue().GetString(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
503 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
);
507 } /* wxDataViewTextRenderer::Render(void) */
509 WXDataBrowserPropertyType
wxDataViewTextRenderer::GetPropertyType(void) const
511 return kDataBrowserTextType
;
512 } /* wxDataViewTextRenderer::GetPropertyType(void) const */
514 IMPLEMENT_CLASS(wxDataViewTextRenderer
,wxDataViewRenderer
)
516 // ---------------------------------------------------------
517 // wxDataViewTextRendererAttr
518 // ---------------------------------------------------------
520 wxDataViewTextRendererAttr::wxDataViewTextRendererAttr(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
521 :wxDataViewTextRenderer(varianttype
,mode
,align
)
523 } /* wxDataViewTextRendererAttr::wxDataViewTextRendererAttr(wxString const&, wxDataViewCellMode, int) */
525 IMPLEMENT_CLASS(wxDataViewTextRendererAttr
,wxDataViewTextRenderer
)
527 // ---------------------------------------------------------
528 // wxDataViewBitmapRenderer
529 // ---------------------------------------------------------
531 wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
532 :wxDataViewRenderer(varianttype
,mode
,align
)
536 bool wxDataViewBitmapRenderer::Render(void)
538 if (this->GetValue().GetType() == this->GetVariantType())
542 bitmap
<< this->GetValue();
544 return (::SetDataBrowserItemDataIcon(this->GetDataReference(),bitmap
.GetIconRef()) == noErr
);
550 } /* wxDataViewBitmapRenderer::Render(void) */
552 WXDataBrowserPropertyType
wxDataViewBitmapRenderer::GetPropertyType(void) const
554 return kDataBrowserIconType
;
555 } /* wxDataViewBitmapRenderer::GetPropertyType(void) const */
557 IMPLEMENT_CLASS(wxDataViewBitmapRenderer
,wxDataViewRenderer
)
559 // ---------------------------------------------------------
560 // wxDataViewIconTextRenderer
561 // ---------------------------------------------------------
563 wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
564 :wxDataViewRenderer(varianttype
,mode
)
568 bool wxDataViewIconTextRenderer::Render(void)
570 if (this->GetValue().GetType() == this->GetVariantType())
572 // variable definition:
573 wxDataViewIconText iconText
;
575 iconText
<< this->GetValue();
577 // variable definition:
578 wxCFStringRef
cfString(iconText
.GetText(),(this->GetView()->GetFont().Ok() ? this->GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
580 if (iconText
.GetIcon().IsOk())
582 if (::SetDataBrowserItemDataIcon(this->GetDataReference(),MAC_WXHICON(iconText
.GetIcon().GetHICON())) != noErr
)
586 return (::SetDataBrowserItemDataText(this->GetDataReference(),cfString
) == noErr
);
590 } /* wxDataViewIconTextRenderer::Render(void) */
592 WXDataBrowserPropertyType
wxDataViewIconTextRenderer::GetPropertyType(void) const
594 return kDataBrowserIconAndTextType
;
595 } /* wxDataViewIconTextRenderer::GetPropertyType(void) const */
597 IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer
,wxDataViewRenderer
)
600 // ---------------------------------------------------------
601 // wxDataViewToggleRenderer
602 // ---------------------------------------------------------
604 wxDataViewToggleRenderer::wxDataViewToggleRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
605 :wxDataViewRenderer(varianttype
,mode
)
609 bool wxDataViewToggleRenderer::Render(void)
611 if (this->GetValue().GetType() == this->GetVariantType())
612 return (::SetDataBrowserItemDataButtonValue(this->GetDataReference(),this->GetValue().GetBool()) == noErr
);
615 } /* wxDataViewToggleRenderer::Render(void) */
617 WXDataBrowserPropertyType
wxDataViewToggleRenderer::GetPropertyType(void) const
619 return kDataBrowserCheckboxType
;
620 } /* wxDataViewToggleRenderer::GetPropertyType(void) const */
622 IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer
,wxDataViewRenderer
)
624 // ---------------------------------------------------------
625 // wxDataViewProgressRenderer
626 // ---------------------------------------------------------
628 wxDataViewProgressRenderer::wxDataViewProgressRenderer(wxString
const& label
, wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
629 :wxDataViewRenderer(varianttype
,mode
,align
)
633 bool wxDataViewProgressRenderer::Render(void)
635 if (this->GetValue().GetType() == this->GetVariantType())
636 return ((::SetDataBrowserItemDataMinimum(this->GetDataReference(), 0) == noErr
) &&
637 (::SetDataBrowserItemDataMaximum(this->GetDataReference(),100) == noErr
) &&
638 (::SetDataBrowserItemDataValue (this->GetDataReference(),this->GetValue().GetLong()) == noErr
));
641 } /* wxDataViewProgressRenderer::Render(void) */
643 WXDataBrowserPropertyType
wxDataViewProgressRenderer::GetPropertyType(void) const
645 return kDataBrowserProgressBarType
;
646 } /* wxDataViewProgressRenderer::GetPropertyType(void) const */
648 IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer
,wxDataViewRenderer
)
650 // ---------------------------------------------------------
651 // wxDataViewDateRenderer
652 // ---------------------------------------------------------
654 wxDataViewDateRenderer::wxDataViewDateRenderer(wxString
const& varianttype
, wxDataViewCellMode mode
, int align
)
655 :wxDataViewRenderer(varianttype
,mode
,align
)
659 bool wxDataViewDateRenderer::Render(void)
661 if (this->GetValue().GetType() == this->GetVariantType())
662 return (::SetDataBrowserItemDataDateTime(this->GetDataReference(),this->GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan
,1904)).GetSeconds().GetLo()) == noErr
);
665 } /* wxDataViewDateRenderer::Render(void) */
667 WXDataBrowserPropertyType
wxDataViewDateRenderer::GetPropertyType(void) const
669 return kDataBrowserDateTimeType
;
670 } /* wxDataViewDateRenderer::GetPropertyType(void) const */
672 IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer
,wxDataViewRenderer
)
674 // ---------------------------------------------------------
676 // ---------------------------------------------------------
678 wxDataViewColumn::wxDataViewColumn(wxString
const &title
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
679 :wxDataViewColumnBase(title
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
680 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
)), m_maxWidth(30000), m_minWidth(0), m_width(width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
),
681 m_alignment(align
), m_title(title
)
683 } /* wxDataViewColumn::wxDataViewColumn(wxString const &title, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
685 wxDataViewColumn::wxDataViewColumn(wxBitmap
const& bitmap
, wxDataViewRenderer
*cell
, unsigned int model_column
, int width
, wxAlignment align
, int flags
)
686 :wxDataViewColumnBase(bitmap
,cell
,model_column
,width
,wxALIGN_CENTER
,flags
), m_ascending(true),
687 m_flags(flags
& ~(wxDATAVIEW_COL_HIDDEN
)), m_maxWidth(30000), m_minWidth(0), m_width(width
>= 0 ? width
: wxDVC_DEFAULT_WIDTH
),
690 } /* wxDataViewColumn::wxDataViewColumn(wxBitmap const&, wxDataViewRenderer*, unsigned int, int, wxAlignment, int) */
692 void wxDataViewColumn::SetAlignment(wxAlignment align
)
694 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
697 this->m_alignment
= align
;
698 if (dataViewCtrlPtr
!= NULL
)
700 // variable definition and initialization:
701 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
703 if (macDataViewListCtrlPtr
!= NULL
)
705 // variable definition and initialization:
706 DataBrowserListViewHeaderDesc headerDescription
;
708 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
712 case wxALIGN_CENTER_HORIZONTAL
:
713 headerDescription
.btnFontStyle
.just
= teCenter
;
716 headerDescription
.btnFontStyle
.just
= teFlushLeft
;
719 headerDescription
.btnFontStyle
.just
= teFlushRight
;
722 headerDescription
.btnFontStyle
.just
= teFlushDefault
;
724 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set alignment."));
727 } /* wxDataViewColumn::SetAlignment(wxAlignment) */
729 void wxDataViewColumn::SetBitmap(wxBitmap
const& bitmap
)
731 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
734 wxDataViewColumnBase::SetBitmap(bitmap
);
735 if (dataViewCtrlPtr
!= NULL
)
737 // variable definition and initialization:
738 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
740 if (macDataViewListCtrlPtr
!= NULL
)
742 // variable definition and initialization:
743 DataBrowserListViewHeaderDesc headerDescription
;
745 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
746 if (this->GetBitmap().Ok())
747 headerDescription
.btnContentInfo
.u
.iconRef
= this->GetBitmap().GetIconRef();
749 headerDescription
.btnContentInfo
.u
.iconRef
= NULL
;
750 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set icon."));
753 } /* wxDataViewColumn::SetBitmap(wxBitmap const&) */
755 void wxDataViewColumn::SetFlags(int flags
)
757 this->SetHidden ((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
758 this->SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
759 this->SetSortable ((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
760 } /* wxDataViewColumn::SetFlags(int) */
762 void wxDataViewColumn::SetMaxWidth(int maxWidth
)
764 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
767 this->m_maxWidth
= maxWidth
;
768 if (dataViewCtrlPtr
!= NULL
)
770 // variable definition and initialization:
771 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
773 if (macDataViewListCtrlPtr
!= NULL
)
775 // variable definition and initialization:
776 DataBrowserListViewHeaderDesc headerDescription
;
778 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
779 headerDescription
.maximumWidth
= static_cast<UInt16
>(maxWidth
);
780 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set maximum width."));
783 } /* wxDataViewColumn::SetMaxWidth(int) */
785 void wxDataViewColumn::SetMinWidth(int minWidth
)
787 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
790 this->m_minWidth
= minWidth
;
791 if (dataViewCtrlPtr
!= NULL
)
793 // variable definition and initialization:
794 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
796 if (macDataViewListCtrlPtr
!= NULL
)
798 // variable definition and initialization:
799 DataBrowserListViewHeaderDesc headerDescription
;
801 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
802 headerDescription
.minimumWidth
= static_cast<UInt16
>(minWidth
);
803 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set minimum width."));
806 } /* wxDataViewColumn::SetMaxWidth(int) */
808 void wxDataViewColumn::SetResizeable(bool WXUNUSED(resizeable
))
810 } /* wxDataViewColumn::SetResizeable(bool) */
812 void wxDataViewColumn::SetSortable(bool sortable
)
814 // variable definition and initialization:
815 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
817 if (dataViewCtrlPtr
!= NULL
)
819 // variable definition and initialization:
820 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
822 if (macDataViewListCtrlPtr
!= NULL
)
824 // variable definition and initialization:
825 DataBrowserPropertyFlags flags
;
827 wxCHECK_RET(macDataViewListCtrlPtr
->GetPropertyFlags(this->GetPropertyID(),&flags
) == noErr
,_("Could not get property flags."));
830 this->m_flags
|= wxDATAVIEW_COL_SORTABLE
;
831 flags
|= kDataBrowserListViewSortableColumn
;
835 this->m_flags
&= ~wxDATAVIEW_COL_SORTABLE
;
836 flags
&= ~kDataBrowserPropertyIsEditable
;
838 wxCHECK_RET(macDataViewListCtrlPtr
->SetPropertyFlags(this->GetPropertyID(),flags
) == noErr
,_("Could not set property flags."));
841 } /* wxDataViewColumn::SetSortable(bool) */
843 void wxDataViewColumn::SetSortOrder(bool ascending
)
845 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
848 this->m_ascending
= ascending
;
849 if (dataViewCtrlPtr
!= NULL
)
851 // variable definition and initialization:
852 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
854 if (macDataViewListCtrlPtr
!= NULL
)
856 // variable definition and initialization:
857 DataBrowserListViewHeaderDesc headerDescription
;
859 verify_noerr(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
));
861 headerDescription
.initialOrder
= kDataBrowserOrderIncreasing
;
863 headerDescription
.initialOrder
= kDataBrowserOrderDecreasing
;
864 verify_noerr(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
));
865 macDataViewListCtrlPtr
->SetSortProperty(this->GetPropertyID());
868 } /* wxDataViewColumn::SetSortOrder(bool) */
870 void wxDataViewColumn::SetTitle(wxString
const& title
)
872 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
875 this->m_title
= title
;
876 if (dataViewCtrlPtr
!= NULL
)
878 // variable definition and initialization:
879 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
881 if (macDataViewListCtrlPtr
!= NULL
)
883 // variable definition and initialization:
884 DataBrowserListViewHeaderDesc headerDescription
;
885 wxCFStringRef
cfTitle(title
,(dataViewCtrlPtr
->GetFont().Ok() ? dataViewCtrlPtr
->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
887 wxCHECK_RET(macDataViewListCtrlPtr
->GetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not get header description."));
888 headerDescription
.titleString
= cfTitle
;
889 wxCHECK_RET(macDataViewListCtrlPtr
->SetHeaderDesc(this->GetPropertyID(),&headerDescription
) == noErr
,_("Could not set header description."));
892 } /* wxDataViewColumn::SetTitle(wxString const&) */
894 void wxDataViewColumn::SetWidth(int width
)
896 wxDataViewCtrl
* dataViewCtrlPtr(this->GetOwner());
899 if ((width
>= this->m_minWidth
) && (width
<= this->m_maxWidth
))
901 this->m_width
= width
;
902 if (dataViewCtrlPtr
!= NULL
)
904 // variable definition and initialization:
905 wxMacDataViewDataBrowserListViewControlPointer
macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(dataViewCtrlPtr
->GetPeer()));
907 if (macDataViewListCtrlPtr
!= NULL
)
908 wxCHECK_RET(macDataViewListCtrlPtr
->SetColumnWidth(this->GetPropertyID(),static_cast<UInt16
>(width
)) == noErr
,_("Could not set column width."));
911 } /* wxDataViewColumn::SetWidth(int) */
913 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn
,wxDataViewColumnBase
)
915 //-----------------------------------------------------------------------------
917 //-----------------------------------------------------------------------------
919 void wxDataViewCtrl::Init(void)
921 this->m_Deleting
= false;
922 this->m_macIsUserPane
= false;
923 this->m_cgContext
= NULL
;
924 } /* wxDataViewCtrl::Init(void) */
926 bool wxDataViewCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
928 if (!(this->wxControl::Create(parent
,id
,pos
,size
,(style
| wxSUNKEN_BORDER
) & ~(wxHSCROLL
| wxVSCROLL
),validator
)))
932 MacSetClipChildren(true) ;
935 this->m_peer
= new wxMacDataViewDataBrowserListViewControl(this,pos
,size
,style
);
936 this->MacPostControlCreate(pos
,size
);
937 ::SetAutomaticControlDragTrackingEnabledForWindow(::GetControlOwner(this->m_peer
->GetControlRef()),true);
939 InstallControlEventHandler(this->m_peer
->GetControlRef(),GetwxMacDataViewCtrlEventHandlerUPP(),GetEventTypeCount(eventList
),eventList
,this,NULL
);
941 ::SetDataBrowserTableViewHiliteStyle( this->m_peer
->GetControlRef(), kDataBrowserTableViewFillHilite
);
944 } /* wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator) */
946 bool wxDataViewCtrl::AssociateModel(wxDataViewModel
* model
)
948 if (!wxDataViewCtrlBase::AssociateModel(model
))
951 model
->AddNotifier(new wxMacDataViewModelNotifier(dynamic_cast<wxMacDataViewDataBrowserListViewControl
*>(this->m_peer
)));
954 } /* wxDataViewCtrl::AssociateModel(wxDataViewModel*) */
956 bool wxDataViewCtrl::AppendColumn(wxDataViewColumn
* columnPtr
)
958 DataBrowserListViewColumnDesc columnDescription
;
960 DataBrowserPropertyID NewPropertyID
;
962 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
964 wxCFStringRef
title(columnPtr
->GetTitle(),this->m_font
.Ok() ? this->m_font
.GetEncoding() : wxLocale::GetSystemEncoding());
967 // first, some error checking:
968 wxCHECK_MSG(MacDataViewListCtrlPtr
!= NULL
, false,_("m_peer is not or incorrectly initialized"));
969 wxCHECK_MSG(columnPtr
!= NULL
, false,_("Column pointer must not be NULL."));
970 wxCHECK_MSG(columnPtr
->GetRenderer() != NULL
, false,_("Column does not have a renderer."));
971 wxCHECK_MSG(this->GetModel() != NULL
, false,_("No model associated with control."));
972 wxCHECK_MSG((columnPtr
->GetModelColumn() >= 0) &&
973 (columnPtr
->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
975 // try to get new ID for the column:
976 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetFreePropertyID(&NewPropertyID
) == noErr
,false,_("Cannot create new column's ID. Probably max. number of columns reached."));
977 // full column variable initialization:
978 columnPtr
->SetPropertyID(NewPropertyID
);
979 // add column to wxWidget's internal structure:
980 wxCHECK_MSG(this->wxDataViewCtrlBase::AppendColumn(columnPtr
) &&
981 this->m_ColumnPointers
.insert(ColumnPointerHashMapType::value_type(NewPropertyID
,columnPtr
)).second
,false,_("Could not add column to internal structures."));
982 // create a column description and add column to the native control:
983 wxCHECK_MSG(::InitializeColumnDescription(columnDescription
,columnPtr
,NewPropertyID
,title
), false,_("Column description could not be initialized."));
984 wxCHECK_MSG(MacDataViewListCtrlPtr
->AddColumn(&columnDescription
,kDataBrowserListViewAppendColumn
) == noErr
,false,_("Column could not be added."));
986 // final adjustments for the layout:
987 wxCHECK_MSG(MacDataViewListCtrlPtr
->SetColumnWidth(NewPropertyID
,columnPtr
->GetWidth()) == noErr
,false,_("Column width could not be set."));
989 // make sure that the data is up-to-date...
990 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
991 // otherwise ask the control to 'update' the data in the newly appended column:
992 if (this->GetColumnCount() == 1)
994 this->SetExpanderColumn(columnPtr
);
995 this->AddChildrenLevel(wxDataViewItem());
998 MacDataViewListCtrlPtr
->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,NewPropertyID
);
1001 } /* wxDataViewCtrl::AppendColumn(wxDataViewColumn*) */
1003 bool wxDataViewCtrl::ClearColumns(void)
1005 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1008 while (this->m_ColumnPointers
.begin() != this->m_ColumnPointers
.end())
1010 wxCHECK_MSG(MacDataViewListCtrlPtr
->RemoveColumnByProperty(this->m_ColumnPointers
.begin()->first
) == noErr
,false,_("Could not remove column."));
1011 delete this->m_ColumnPointers
.begin()->second
;
1012 this->m_ColumnPointers
.erase(this->m_ColumnPointers
.begin());
1015 } /* wxDataViewCtrl::ClearColumns(void) */
1017 bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn
* columnPtr
)
1019 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1022 if ((MacDataViewListCtrlPtr
->RemoveColumnByProperty(columnPtr
->GetPropertyID()) == noErr
) && (this->m_ColumnPointers
.erase(columnPtr
->GetPropertyID()) > 0))
1029 } /* wxDataViewCtrl::DeleteColumn(wxDataViewColumn*) */
1031 wxDataViewColumn
* wxDataViewCtrl::GetColumn(unsigned int pos
) const
1033 DataBrowserPropertyID propertyID
;
1035 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1038 if (MacDataViewListCtrlPtr
->GetPropertyID(pos
,&propertyID
) == noErr
)
1040 // variable definition:
1041 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
1043 if (Result
!= this->m_ColumnPointers
.end())
1044 return Result
->second
;
1050 } /* wxDataViewCtrl::GetColumn(unsigned int pos) const */
1052 unsigned int wxDataViewCtrl::GetColumnCount(void) const
1054 return this->m_ColumnPointers
.size();
1055 } /* wxDataViewCtrl::GetColumnCount(void) const */
1057 int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn
const* columnPtr
) const
1059 if (columnPtr
!= NULL
)
1061 // variable definition and initialization:
1062 DataBrowserTableViewColumnIndex Position
;
1063 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1065 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetColumnIndex(columnPtr
->GetPropertyID(),&Position
) == noErr
,-1,_("Could not determine column's position"));
1066 return static_cast<int>(Position
);
1070 } /* wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const*) const */
1072 bool wxDataViewCtrl::PrependColumn(wxDataViewColumn
* columnPtr
)
1074 DataBrowserListViewColumnDesc columnDescription
;
1076 DataBrowserPropertyID NewPropertyID
;
1078 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1080 wxCFStringRef
title(columnPtr
->GetTitle(),this->m_font
.Ok() ? this->m_font
.GetEncoding() : wxLocale::GetSystemEncoding());
1083 // first, some error checking:
1084 wxCHECK_MSG(MacDataViewListCtrlPtr
!= NULL
, false,_("m_peer is not or incorrectly initialized"));
1085 wxCHECK_MSG(columnPtr
!= NULL
, false,_("Column pointer must not be NULL."));
1086 wxCHECK_MSG(columnPtr
->GetRenderer() != NULL
, false,_("Column does not have a renderer."));
1087 wxCHECK_MSG(this->GetModel() != NULL
, false,_("No model associated with control."));
1088 wxCHECK_MSG((columnPtr
->GetModelColumn() >= 0) &&
1089 (columnPtr
->GetModelColumn() < this->GetModel()->GetColumnCount()),false,_("Column's model column has no equivalent in the associated model."));
1091 // try to get new ID for the column:
1092 wxCHECK_MSG(MacDataViewListCtrlPtr
->GetFreePropertyID(&NewPropertyID
) == noErr
,false,_("Cannot create new column's ID. Probably max. number of columns reached."));
1093 // full column variable initialization:
1094 columnPtr
->SetPropertyID(NewPropertyID
);
1095 // add column to wxWidget's internal structure:
1096 wxCHECK_MSG(this->wxDataViewCtrlBase::AppendColumn(columnPtr
) &&
1097 this->m_ColumnPointers
.insert(ColumnPointerHashMapType::value_type(NewPropertyID
,columnPtr
)).second
,false,_("Could not add column to internal structures."));
1098 // create a column description and add column to the native control:
1099 wxCHECK_MSG(::InitializeColumnDescription(columnDescription
,columnPtr
,NewPropertyID
,title
),false,_("Column description could not be initialized."));
1100 wxCHECK_MSG(MacDataViewListCtrlPtr
->AddColumn(&columnDescription
,0) == noErr
, false,_("Column could not be added."));
1102 // final adjustments for the layout:
1103 wxCHECK_MSG(MacDataViewListCtrlPtr
->SetColumnWidth(NewPropertyID
,columnPtr
->GetWidth()) == noErr
,false,_("Column width could not be set."));
1105 // make sure that the data is up-to-date...
1106 // if the newly appended column is the first column add the initial data to the control and mark the column as an expander column,
1107 // otherwise ask the control to 'update' the data in the newly appended column:
1108 if (this->GetColumnCount() == 1)
1110 this->SetExpanderColumn(columnPtr
);
1111 this->AddChildrenLevel(wxDataViewItem());
1114 MacDataViewListCtrlPtr
->UpdateItems(kDataBrowserNoItem
,0,NULL
,kDataBrowserItemNoProperty
,NewPropertyID
);
1117 } /* wxDataViewCtrl::PrependColumn(wxDataViewColumn*) */
1119 void wxDataViewCtrl::Collapse(wxDataViewItem
const& item
)
1121 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1124 MacDataViewListCtrlPtr
->CloseContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1125 } /* wxDataViewCtrl::Collapse(wxDataViewItem const&) */
1127 void wxDataViewCtrl::EnsureVisible(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
)
1131 // variable definition and initialization:
1132 DataBrowserPropertyID propertyID
;
1133 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1135 if (columnPtr
!= NULL
)
1136 propertyID
= columnPtr
->GetPropertyID();
1138 propertyID
= kDataBrowserNoItem
;
1139 MacDataViewListCtrlPtr
->RevealItem(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),propertyID
,kDataBrowserRevealOnly
);
1141 } /* wxDataViewCtrl::EnsureVisible(wxDataViewItem const&, wxDataViewColumn const*) */
1143 void wxDataViewCtrl::Expand(wxDataViewItem
const& item
)
1145 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1148 MacDataViewListCtrlPtr
->OpenContainer(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1149 } /* wxDataViewCtrl::Expand(wxDataViewItem const&) */
1151 wxDataViewColumn
* wxDataViewCtrl::GetSortingColumn(void) const
1153 DataBrowserPropertyID propertyID
;
1155 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1158 if (MacDataViewListCtrlPtr
->GetSortProperty(&propertyID
) == noErr
)
1159 return this->GetColumnPtr(propertyID
);
1162 } /* wxDataViewCtrl::GetSortingColumn(void) const */
1164 unsigned int wxDataViewCtrl::GetCount(void) const
1166 ItemCount noOfItems
;
1169 wxCHECK_MSG(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
)->GetItemCount(&noOfItems
) == noErr
,0,_("Could not determine number of items"));
1171 } /* wxDataViewCtrl::GetCount(void) const */
1173 wxRect
wxDataViewCtrl::GetItemRect(wxDataViewItem
const& item
, wxDataViewColumn
const* columnPtr
) const
1175 if (item
.IsOk() && (columnPtr
!= NULL
))
1177 // variable definition:
1179 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1181 if (MacDataViewListCtrlPtr
->GetPartBounds(reinterpret_cast<DataBrowserItemID
>(item
.GetID()),columnPtr
->GetPropertyID(),kDataBrowserPropertyContentPart
,&MacRectangle
) == noErr
)
1183 // variable definition:
1186 ::wxMacNativeToRect(&MacRectangle
,&rectangle
);
1194 } /* wxDataViewCtrl::GetItemRect(wxDataViewItem const&, unsigned int) const */
1196 wxDataViewItem
wxDataViewCtrl::GetSelection(void) const
1198 wxArrayDataBrowserItemID itemIDs
;
1200 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1203 if (MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
) > 0)
1204 return wxDataViewItem(reinterpret_cast<void*>(itemIDs
[0]));
1206 return wxDataViewItem();
1207 } /* wxDataViewCtrl::GetSelection(void) const */
1209 int wxDataViewCtrl::GetSelections(wxDataViewItemArray
& sel
) const
1211 size_t NoOfSelectedItems
;
1213 wxArrayDataBrowserItemID itemIDs
;
1215 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1218 NoOfSelectedItems
= MacDataViewListCtrlPtr
->GetSelectedItemIDs(itemIDs
);
1220 sel
.SetCount(NoOfSelectedItems
);
1221 for (size_t i
=0; i
<NoOfSelectedItems
; ++i
)
1222 sel
[i
] = wxDataViewItem(reinterpret_cast<void*>(itemIDs
[i
]));
1223 return static_cast<int>(NoOfSelectedItems
);
1224 } /* wxDataViewCtrl::GetSelections(wxDataViewItemArray&) const */
1226 void wxDataViewCtrl::HitTest(wxPoint
const& point
, wxDataViewItem
& item
, wxDataViewColumn
*& columnPtr
) const
1228 item
= wxDataViewItem();
1230 } /* wxDataViewCtrl::HitTest(wxPoint const&, wxDataViewItem&, wxDataViewColumn*&) const */
1232 bool wxDataViewCtrl::IsSelected(wxDataViewItem
const& item
) const
1234 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1237 return MacDataViewListCtrlPtr
->IsItemSelected(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1238 } /* wxDataViewCtrl::IsSelected(wxDataViewItem const&) const */
1240 void wxDataViewCtrl::SelectAll(void)
1242 DataBrowserItemID
* itemIDPtr
;
1244 Handle
handle(::NewHandle(0));
1248 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1251 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1252 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1254 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1255 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsAssign
);
1257 DisposeHandle(handle
);
1258 } /* wxDataViewCtrl::SelectAll(void) */
1260 void wxDataViewCtrl::Select(wxDataViewItem
const& item
)
1264 // variable definition and initialization:
1265 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1266 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1268 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsAdd
);
1270 } /* wxDataViewCtrl::Select(wxDataViewItem const&) */
1272 void wxDataViewCtrl::SetSelections(wxDataViewItemArray
const& sel
)
1274 size_t const NoOfSelections
= sel
.GetCount();
1276 DataBrowserItemID
* itemIDs
;
1278 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1281 itemIDs
= new DataBrowserItemID
[NoOfSelections
];
1282 for (size_t i
=0; i
<NoOfSelections
; ++i
)
1283 itemIDs
[i
] = reinterpret_cast<DataBrowserItemID
>(sel
[i
].GetID());
1284 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfSelections
,itemIDs
,kDataBrowserItemsAssign
);
1286 } /* wxDataViewCtrl::SetSelections(wxDataViewItemArray const&) */
1288 void wxDataViewCtrl::Unselect(wxDataViewItem
const& item
)
1292 // variable definition and initialization:
1293 DataBrowserItemID
itemID(reinterpret_cast<DataBrowserItemID
>(item
.GetID()));
1294 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1296 MacDataViewListCtrlPtr
->SetSelectedItems(1,&itemID
,kDataBrowserItemsRemove
);
1298 } /* wxDataViewCtrl::Unselect(wxDataViewItem const&) */
1300 void wxDataViewCtrl::UnselectAll(void)
1302 DataBrowserItemID
* itemIDPtr
;
1304 Handle
handle(::NewHandle(0));
1308 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1311 wxCHECK_RET(MacDataViewListCtrlPtr
->GetItems(kDataBrowserNoItem
,true,kDataBrowserItemAnyState
,handle
) == noErr
,_("Could not get items."));
1312 NoOfItems
= static_cast<size_t>(::GetHandleSize(handle
)/sizeof(DataBrowserItemID
));
1314 itemIDPtr
= (DataBrowserItemID
*) (*handle
);
1315 MacDataViewListCtrlPtr
->SetSelectedItems(NoOfItems
,itemIDPtr
,kDataBrowserItemsRemove
);
1317 DisposeHandle(handle
);
1318 } /* wxDataViewCtrl::UnselectAll(void) */
1321 void wxDataViewCtrl::AddChildrenLevel(wxDataViewItem
const& parentItem
)
1325 wxDataViewItemArray items
;
1328 wxCHECK_RET(this->GetModel() != NULL
,_("Model pointer not initialized."));
1329 NoOfChildren
= this->GetModel()->GetChildren(parentItem
,items
);
1331 for (int i
=0; i
<NoOfChildren
; ++i
)
1332 (void) this->GetModel()->ItemAdded(parentItem
,items
[i
]);
1334 (void) this->GetModel()->ItemsAdded(parentItem
,items
);
1336 } /* wxDataViewCtrl::AddChildrenLevel(wxDataViewItem const&) */
1338 wxDataViewColumn
* wxDataViewCtrl::GetColumnPtr(WXDataBrowserPropertyID propertyID
) const
1340 // variable definition:
1341 ColumnPointerHashMapType::const_iterator
Result(this->m_ColumnPointers
.find(propertyID
));
1343 if (Result
!= this->m_ColumnPointers
.end())
1344 return Result
->second
;
1347 } /* wxDataViewCtrl::GetColumnPtr(DataBrowserPropertyID) const */
1349 // inherited methods from wxDataViewCtrlBase
1350 void wxDataViewCtrl::DoSetExpanderColumn(void)
1352 if (this->GetExpanderColumn() != NULL
)
1354 // variable definition and initialization:
1355 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1357 (void) MacDataViewListCtrlPtr
->SetDisclosureColumn(this->GetExpanderColumn()->GetPropertyID());
1359 } /* wxDataViewCtrl::DoSetExpanderColumn(void) */
1361 void wxDataViewCtrl::DoSetIndent(void)
1363 wxMacDataViewDataBrowserListViewControlPointer
MacDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer
>(this->m_peer
));
1366 (void) MacDataViewListCtrlPtr
->SetIndent(static_cast<float>(this->GetIndent()));
1367 } /* wxDataViewCtrl::DoSetIndent(void) */
1370 void wxDataViewCtrl::OnSize(wxSizeEvent
& event
)
1372 unsigned int const NoOfColumns
= this->GetColumnCount();
1375 for (unsigned int i
=0; i
<NoOfColumns
; ++i
)
1377 // variable definition and initialization:
1378 wxDataViewColumn
* dataViewColumnPtr(this->GetColumn(i
));
1380 if (dataViewColumnPtr
!= NULL
)
1382 // variable definition and initialization:
1383 wxDataViewCustomRenderer
* dataViewCustomRendererPtr(dynamic_cast<wxDataViewCustomRenderer
*>(dataViewColumnPtr
->GetRenderer()));
1385 if (dataViewCustomRendererPtr
!= NULL
)
1386 dataViewCustomRendererPtr
->SetDC(NULL
); // reset DC because DC has changed
1390 } /* wxDataViewCtrl::OnSize(wxSizeEvent&) */
1392 IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl
,wxDataViewCtrlBase
)
1394 BEGIN_EVENT_TABLE(wxDataViewCtrl
,wxDataViewCtrlBase
)
1395 EVT_SIZE(wxDataViewCtrl::OnSize
)
1399 // !wxUSE_GENERICDATAVIEWCTRL
1402 // wxUSE_DATAVIEWCTRL