From 61223ab32d969da233d388883069749d2b936551 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 13 Jul 2018 18:16:16 +0200 Subject: [PATCH] Fix using radio buttons in wxDataViewToggleRenderer under macOS Changing item cell in ShowAsRadio() was wrong as the item cell doesn't exist when it is called and changing the column cell didn't seem to work well, so just recreate the entire cell in it instead. See https://github.com/wxWidgets/wxWidgets/pull/853 --- include/wx/osx/dvrenderers.h | 2 ++ src/osx/cocoa/dataview.mm | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/wx/osx/dvrenderers.h b/include/wx/osx/dvrenderers.h index e9ad8edd79..1c6b5b5687 100644 --- a/include/wx/osx/dvrenderers.h +++ b/include/wx/osx/dvrenderers.h @@ -207,6 +207,8 @@ public: unsigned col); private: + void DoInitButtonCell(int buttonType); + wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer); }; diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index a95d29190e..de561b8b4e 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -3324,13 +3324,18 @@ wxDataViewToggleRenderer::wxDataViewToggleRenderer(const wxString& varianttype, wxDataViewCellMode mode, int align) : wxOSXDataViewDisabledInertRenderer(varianttype, mode, align) +{ + DoInitButtonCell(NSSwitchButton); +} + +void wxDataViewToggleRenderer::DoInitButtonCell(int buttonType) { NSButtonCell* cell; cell = [[NSButtonCell alloc] init]; - [cell setAlignment:ConvertToNativeHorizontalTextAlignment(align)]; - [cell setButtonType:NSSwitchButton]; + [cell setAlignment:ConvertToNativeHorizontalTextAlignment(GetAlignment())]; + [cell setButtonType: static_cast(buttonType)]; [cell setImagePosition:NSImageOnly]; SetNativeData(new wxDataViewRendererNativeData(cell)); [cell release]; @@ -3338,7 +3343,11 @@ wxDataViewToggleRenderer::wxDataViewToggleRenderer(const wxString& varianttype, void wxDataViewToggleRenderer::ShowAsRadio() { - [GetNativeData()->GetItemCell() setButtonType:NSRadioButton]; + // This is a bit wasteful, as we always create the cell using + // NSSwitchButton in the ctor and recreate it here, but modifying the + // existing cell doesn't seem to work well and delaying the creation of the + // cell until it's used doesn't seem to be worth it, so just recreate it. + DoInitButtonCell(NSRadioButton); } bool wxDataViewToggleRenderer::MacRender()