+// ---------------------------------------------------------
+// wxDataViewCustomRenderer
+// ---------------------------------------------------------
+wxDataViewCustomRenderer::wxDataViewCustomRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
+ :wxDataViewCustomRendererBase(varianttype,mode,align),
+ m_editorCtrlPtr(NULL),
+ m_DCPtr(NULL)
+{
+ SetNativeData(new wxDataViewRendererNativeData(kDataBrowserCustomType));
+}
+
+bool wxDataViewCustomRenderer::MacRender()
+{
+ return true;
+}
+
+IMPLEMENT_ABSTRACT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
+
+// ---------------------------------------------------------
+// wxDataViewTextRenderer
+// ---------------------------------------------------------
+wxDataViewTextRenderer::wxDataViewTextRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
+ :wxDataViewRenderer(varianttype,mode,align)
+{
+ SetNativeData(new wxDataViewRendererNativeData(kDataBrowserTextType));
+}
+
+bool wxDataViewTextRenderer::MacRender()
+{
+ wxCHECK_MSG(GetValue().GetType() == GetVariantType(),false,wxString(_("Text renderer cannot render value; value type: ")) << GetValue().GetType());
+
+ wxCFStringRef cfString(GetValue().GetString(),(GetView()->GetFont().Ok() ? GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
+ return (::SetDataBrowserItemDataText(GetNativeData()->GetItemDataRef(),cfString) == noErr);
+}
+
+IMPLEMENT_CLASS(wxDataViewTextRenderer,wxDataViewRenderer)
+
+// ---------------------------------------------------------
+// wxDataViewBitmapRenderer
+// ---------------------------------------------------------
+wxDataViewBitmapRenderer::wxDataViewBitmapRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
+ :wxDataViewRenderer(varianttype,mode,align)
+{
+ SetNativeData(new wxDataViewRendererNativeData(kDataBrowserIconType));
+}
+
+bool wxDataViewBitmapRenderer::MacRender()
+ // This method returns 'true' if
+ // - the passed bitmap is valid and it could be assigned to the native data browser;
+ // - the passed bitmap is invalid (or is not initialized); this case simulates a non-existing bitmap.
+ // In all other cases the method returns 'false'.
+{
+ wxCHECK_MSG(GetValue().GetType() == GetVariantType(),false,wxString(_("Bitmap renderer cannot render value; value type: ")) << GetValue().GetType());
+
+ wxBitmap bitmap;
+
+ bitmap << GetValue();
+ return (!(bitmap.Ok()) || (::SetDataBrowserItemDataIcon(GetNativeData()->GetItemDataRef(),bitmap.GetIconRef()) == noErr));
+}
+
+IMPLEMENT_CLASS(wxDataViewBitmapRenderer,wxDataViewRenderer)
+
+// ---------------------------------------------------------
+// wxDataViewIconTextRenderer
+// ---------------------------------------------------------
+wxDataViewIconTextRenderer::wxDataViewIconTextRenderer(
+ const wxString& varianttype,
+ wxDataViewCellMode mode,
+ int WXUNUSED(align))
+ :wxDataViewRenderer(varianttype,mode)
+{
+ SetNativeData(new wxDataViewRendererNativeData(kDataBrowserIconAndTextType));
+}
+
+bool wxDataViewIconTextRenderer::MacRender()
+{
+ wxCHECK_MSG(GetValue().GetType() == GetVariantType(),false,wxString(_("Icon & text renderer cannot render value; value type: ")) << GetValue().GetType());
+
+ wxDataViewIconText iconText;
+
+ iconText << GetValue();
+
+ wxCFStringRef cfString(iconText.GetText(),(GetView()->GetFont().Ok() ? GetView()->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
+
+ if (iconText.GetIcon().IsOk())
+ if (::SetDataBrowserItemDataIcon(GetNativeData()->GetItemDataRef(),MAC_WXHICON(iconText.GetIcon().GetHICON())) != noErr)
+ return false;
+ return (::SetDataBrowserItemDataText(GetNativeData()->GetItemDataRef(),cfString) == noErr);
+}
+
+IMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer,wxDataViewRenderer)
+
+
+// ---------------------------------------------------------
+// wxDataViewToggleRenderer
+// ---------------------------------------------------------
+wxDataViewToggleRenderer::wxDataViewToggleRenderer(
+ const wxString& varianttype,
+ wxDataViewCellMode mode,
+ int WXUNUSED(align))
+ :wxDataViewRenderer(varianttype,mode)
+{
+ SetNativeData(new wxDataViewRendererNativeData(kDataBrowserCheckboxType));
+}
+
+bool wxDataViewToggleRenderer::MacRender()
+{
+ wxCHECK_MSG(GetValue().GetType() == GetVariantType(),false,wxString(_("Toggle renderer cannot render value; value type: ")) << GetValue().GetType());
+ return (::SetDataBrowserItemDataButtonValue(GetNativeData()->GetItemDataRef(),GetValue().GetBool()) == noErr);
+}
+
+IMPLEMENT_ABSTRACT_CLASS(wxDataViewToggleRenderer,wxDataViewRenderer)
+
+// ---------------------------------------------------------
+// wxDataViewProgressRenderer
+// ---------------------------------------------------------
+wxDataViewProgressRenderer::wxDataViewProgressRenderer(
+ const wxString& WXUNUSED(label),
+ wxString const& varianttype,
+ wxDataViewCellMode mode,
+ int align)
+ :wxDataViewRenderer(varianttype,mode,align)
+{
+ SetNativeData(new wxDataViewRendererNativeData(kDataBrowserProgressBarType));
+}
+
+bool wxDataViewProgressRenderer::MacRender()
+{
+ wxCHECK_MSG(GetValue().GetType() == GetVariantType(),false,wxString(_("Progress renderer cannot render value type; value type: ")) << GetValue().GetType());
+ return ((::SetDataBrowserItemDataMinimum(GetNativeData()->GetItemDataRef(), 0) == noErr) &&
+ (::SetDataBrowserItemDataMaximum(GetNativeData()->GetItemDataRef(),100) == noErr) &&
+ (::SetDataBrowserItemDataValue (GetNativeData()->GetItemDataRef(),GetValue().GetLong()) == noErr));
+}
+
+IMPLEMENT_ABSTRACT_CLASS(wxDataViewProgressRenderer,wxDataViewRenderer)
+
+// ---------------------------------------------------------
+// wxDataViewDateRenderer
+// ---------------------------------------------------------
+wxDataViewDateRenderer::wxDataViewDateRenderer(wxString const& varianttype, wxDataViewCellMode mode, int align)
+ :wxDataViewRenderer(varianttype,mode,align)
+{
+ SetNativeData(new wxDataViewRendererNativeData(kDataBrowserDateTimeType));
+}
+
+bool wxDataViewDateRenderer::MacRender()
+{
+ wxCHECK_MSG(GetValue().GetType() == GetVariantType(),false,wxString(_("Date renderer cannot render value; value type: ")) << GetValue().GetType());
+ return (::SetDataBrowserItemDataDateTime(GetNativeData()->GetItemDataRef(),GetValue().GetDateTime().Subtract(wxDateTime(1,wxDateTime::Jan,1904)).GetSeconds().GetLo()) == noErr);
+}
+
+IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateRenderer,wxDataViewRenderer)
+
+// ---------------------------------------------------------
+// wxDataViewColumn
+// ---------------------------------------------------------
+wxDataViewColumn::wxDataViewColumn(const wxString& title, wxDataViewRenderer* renderer, unsigned int model_column, int width, wxAlignment align, int flags)
+ :wxDataViewColumnBase(renderer, model_column), m_NativeDataPtr(new wxDataViewColumnNativeData()), m_title(title)
+{
+ InitCommon(width, align, flags);
+ if ((renderer != NULL) && (renderer->GetAlignment() == wxDVR_DEFAULT_ALIGNMENT))
+ renderer->SetAlignment(align);
+}
+
+wxDataViewColumn::wxDataViewColumn(const wxBitmap& bitmap, wxDataViewRenderer* renderer, unsigned int model_column, int width, wxAlignment align, int flags)
+ :wxDataViewColumnBase(bitmap, renderer, model_column), m_NativeDataPtr(new wxDataViewColumnNativeData())
+{
+ InitCommon(width, align, flags);
+ if ((renderer != NULL) && (renderer->GetAlignment() == wxDVR_DEFAULT_ALIGNMENT))
+ renderer->SetAlignment(align);
+}
+
+wxDataViewColumn::~wxDataViewColumn()
+{
+ delete m_NativeDataPtr;
+}
+
+int wxDataViewColumn::GetWidth() const
+{
+ // FIXME: This returns the last programatically set width and will not work if
+ // the user changes the column's width by dragging it with the mouse.
+ return m_width;
+}
+
+bool wxDataViewColumn::IsSortKey() const
+{
+ wxDataViewCtrl * const dataViewCtrlPtr(GetOwner());
+ wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(
+ dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(
+ dataViewCtrlPtr->GetPeer()));
+
+ DataBrowserPropertyID propertyID;
+ return (macDataViewListCtrlPtr->GetSortProperty(&propertyID) == noErr) &&
+ (propertyID == GetNativeData()->GetPropertyID());
+}
+
+void wxDataViewColumn::SetAlignment(wxAlignment align)
+{
+ wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
+
+
+ m_alignment = align;
+ if (dataViewCtrlPtr != NULL)
+ {
+ wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
+
+ if (macDataViewListCtrlPtr != NULL)
+ {
+ DataBrowserListViewHeaderDesc headerDescription;
+
+ wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
+ switch (align)
+ {
+ case wxALIGN_CENTER:
+ case wxALIGN_CENTER_HORIZONTAL:
+ headerDescription.btnFontStyle.just = teCenter;
+ break;
+ case wxALIGN_LEFT:
+ headerDescription.btnFontStyle.just = teFlushLeft;
+ break;
+ case wxALIGN_RIGHT:
+ headerDescription.btnFontStyle.just = teFlushRight;
+ break;
+ default:
+ headerDescription.btnFontStyle.just = teFlushDefault;
+ }
+ wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not set alignment."));
+ }
+ }
+}
+
+void wxDataViewColumn::SetBitmap(wxBitmap const& bitmap)
+{
+ wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
+
+
+ wxDataViewColumnBase::SetBitmap(bitmap);
+ if (dataViewCtrlPtr != NULL)
+ {
+ wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
+
+ if (macDataViewListCtrlPtr != NULL)
+ {
+ DataBrowserListViewHeaderDesc headerDescription;
+
+ wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
+ if (GetBitmap().Ok())
+ headerDescription.btnContentInfo.u.iconRef = GetBitmap().GetIconRef();
+ else
+ headerDescription.btnContentInfo.u.iconRef = NULL;
+ wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not set icon."));
+ }
+ }
+}
+
+void wxDataViewColumn::SetMaxWidth(int maxWidth)
+{
+ wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
+
+
+ m_maxWidth = maxWidth;
+ if (dataViewCtrlPtr != NULL)
+ {
+ wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
+
+ if (macDataViewListCtrlPtr != NULL)
+ {
+ DataBrowserListViewHeaderDesc headerDescription;
+
+ wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
+ headerDescription.maximumWidth = static_cast<UInt16>(maxWidth);
+ wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not set maximum width."));
+ }
+ }
+}
+
+void wxDataViewColumn::SetMinWidth(int minWidth)
+{
+ wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
+
+
+ m_minWidth = minWidth;
+ if (dataViewCtrlPtr != NULL)
+ {
+ wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
+
+ if (macDataViewListCtrlPtr != NULL)
+ {
+ DataBrowserListViewHeaderDesc headerDescription;
+
+ wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
+ headerDescription.minimumWidth = static_cast<UInt16>(minWidth);
+ wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not set minimum width."));
+ }
+ }
+}
+
+void wxDataViewColumn::SetReorderable(bool reorderable)
+{
+ // first set the internal flag of the column:
+ if (reorderable)
+ m_flags |= wxDATAVIEW_COL_REORDERABLE;
+ else
+ m_flags &= ~wxDATAVIEW_COL_REORDERABLE;
+ // if the column is associated with a control change also immediately the flags of the control:
+ wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
+
+ if (dataViewCtrlPtr != NULL)
+ {
+ DataBrowserPropertyFlags flags;
+ wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
+
+ wxCHECK_RET(macDataViewListCtrlPtr != NULL, _("Valid pointer to native data view control does not exist"));
+ wxCHECK_RET(macDataViewListCtrlPtr->GetPropertyFlags(GetNativeData()->GetPropertyID(),&flags) == noErr,_("Could not get property flags."));
+ if (reorderable)
+ flags |= kDataBrowserListViewMovableColumn;
+ else
+ flags &= ~kDataBrowserListViewMovableColumn;
+ wxCHECK_RET(macDataViewListCtrlPtr->SetPropertyFlags(GetNativeData()->GetPropertyID(),flags) == noErr,_("Could not set property flags."));
+ }
+}
+
+void wxDataViewColumn::SetResizeable(bool resizeable)
+{
+ // first set the internal flag of the column:
+ if (resizeable)
+ m_flags |= wxDATAVIEW_COL_RESIZABLE;
+ else
+ m_flags &= ~wxDATAVIEW_COL_RESIZABLE;
+ // if the column is associated with a control change also immediately the flags of the control:
+ wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
+
+ if (dataViewCtrlPtr != NULL)
+ {
+ wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
+
+ if (macDataViewListCtrlPtr != NULL)
+ {
+ DataBrowserListViewHeaderDesc headerDescription;
+
+ verify_noerr(macDataViewListCtrlPtr->GetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription));
+ if (resizeable)
+ {
+ if (GetMinWidth() >= GetMaxWidth())
+ {
+ m_minWidth = 0;
+ m_maxWidth = 30000;
+ }
+ headerDescription.minimumWidth = m_minWidth;
+ headerDescription.maximumWidth = m_maxWidth;
+ }
+ else
+ {
+ headerDescription.minimumWidth = m_width;
+ headerDescription.maximumWidth = m_width;
+ }
+ verify_noerr(macDataViewListCtrlPtr->SetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription));
+ macDataViewListCtrlPtr->SetSortProperty(GetNativeData()->GetPropertyID());
+ }
+ }
+}
+
+void wxDataViewColumn::SetSortable(bool sortable)
+{
+ // first set the internal flag of the column:
+ if (sortable)
+ m_flags |= wxDATAVIEW_COL_SORTABLE;
+ else
+ m_flags &= ~wxDATAVIEW_COL_SORTABLE;
+ // if the column is associated with a control change also immediately the flags of the control:
+ wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
+
+ if (dataViewCtrlPtr != NULL)
+ {
+ DataBrowserPropertyFlags flags;
+ wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
+
+ wxCHECK_RET(macDataViewListCtrlPtr != NULL, _("Valid pointer to native data view control does not exist"));
+ wxCHECK_RET(macDataViewListCtrlPtr->GetPropertyFlags(GetNativeData()->GetPropertyID(),&flags) == noErr,_("Could not get property flags."));
+ if (sortable)
+ flags |= kDataBrowserListViewSortableColumn;
+ else
+ flags &= ~kDataBrowserListViewSortableColumn;
+ wxCHECK_RET(macDataViewListCtrlPtr->SetPropertyFlags(GetNativeData()->GetPropertyID(),flags) == noErr,_("Could not set property flags."));
+ }
+}
+
+void wxDataViewColumn::SetSortOrder(bool ascending)
+{
+ wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
+
+
+ m_ascending = ascending;
+ if (dataViewCtrlPtr != NULL)
+ {
+ wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
+
+ if (macDataViewListCtrlPtr != NULL)
+ {
+ DataBrowserListViewHeaderDesc headerDescription;
+
+ verify_noerr(macDataViewListCtrlPtr->GetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription));
+ if (ascending)
+ headerDescription.initialOrder = kDataBrowserOrderIncreasing;
+ else
+ headerDescription.initialOrder = kDataBrowserOrderDecreasing;
+ verify_noerr(macDataViewListCtrlPtr->SetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription));
+ macDataViewListCtrlPtr->SetSortProperty(GetNativeData()->GetPropertyID());
+ }
+ }
+}
+
+void wxDataViewColumn::SetTitle(wxString const& title)
+{
+ wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
+
+
+ m_title = title;
+ if (dataViewCtrlPtr != NULL)
+ {
+ wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
+
+ if (macDataViewListCtrlPtr != NULL)
+ {
+ DataBrowserListViewHeaderDesc headerDescription;
+ wxCFStringRef cfTitle(title,(dataViewCtrlPtr->GetFont().Ok() ? dataViewCtrlPtr->GetFont().GetEncoding() : wxLocale::GetSystemEncoding()));
+
+ wxCHECK_RET(macDataViewListCtrlPtr->GetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not get header description."));
+ headerDescription.titleString = cfTitle;
+ wxCHECK_RET(macDataViewListCtrlPtr->SetHeaderDesc(GetNativeData()->GetPropertyID(),&headerDescription) == noErr,_("Could not set header description."));
+ }
+ }
+}
+
+void wxDataViewColumn::SetWidth(int width)
+{
+ wxDataViewCtrl* dataViewCtrlPtr(GetOwner());
+
+
+ if ((width >= m_minWidth) && (width <= m_maxWidth))
+ {
+ m_width = width;
+ if (dataViewCtrlPtr != NULL)
+ {
+ wxMacDataViewDataBrowserListViewControlPointer macDataViewListCtrlPtr(dynamic_cast<wxMacDataViewDataBrowserListViewControlPointer>(dataViewCtrlPtr->GetPeer()));
+
+ if (macDataViewListCtrlPtr != NULL)
+ wxCHECK_RET(macDataViewListCtrlPtr->SetColumnWidth(GetNativeData()->GetPropertyID(),static_cast<UInt16>(width)) == noErr,_("Could not set column width."));
+ }
+ }
+}
+
+void wxDataViewColumn::SetAsSortKey(bool WXUNUSED(sort))
+{
+ // see wxGTK native wxDataViewColumn implementation
+ wxFAIL_MSG( "not implemented" );
+}
+
+void wxDataViewColumn::SetNativeData(wxDataViewColumnNativeData* newNativeDataPtr)
+{
+ delete m_NativeDataPtr;
+ m_NativeDataPtr = newNativeDataPtr;
+}