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
This commit is contained in:
Vadim Zeitlin
2018-07-13 18:16:16 +02:00
parent 6c6cc08975
commit 61223ab32d
2 changed files with 14 additions and 3 deletions

View File

@@ -207,6 +207,8 @@ public:
unsigned col); unsigned col);
private: private:
void DoInitButtonCell(int buttonType);
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer); wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer);
}; };

View File

@@ -3324,13 +3324,18 @@ wxDataViewToggleRenderer::wxDataViewToggleRenderer(const wxString& varianttype,
wxDataViewCellMode mode, wxDataViewCellMode mode,
int align) int align)
: wxOSXDataViewDisabledInertRenderer(varianttype, mode, align) : wxOSXDataViewDisabledInertRenderer(varianttype, mode, align)
{
DoInitButtonCell(NSSwitchButton);
}
void wxDataViewToggleRenderer::DoInitButtonCell(int buttonType)
{ {
NSButtonCell* cell; NSButtonCell* cell;
cell = [[NSButtonCell alloc] init]; cell = [[NSButtonCell alloc] init];
[cell setAlignment:ConvertToNativeHorizontalTextAlignment(align)]; [cell setAlignment:ConvertToNativeHorizontalTextAlignment(GetAlignment())];
[cell setButtonType:NSSwitchButton]; [cell setButtonType: static_cast<NSButtonType>(buttonType)];
[cell setImagePosition:NSImageOnly]; [cell setImagePosition:NSImageOnly];
SetNativeData(new wxDataViewRendererNativeData(cell)); SetNativeData(new wxDataViewRendererNativeData(cell));
[cell release]; [cell release];
@@ -3338,7 +3343,11 @@ wxDataViewToggleRenderer::wxDataViewToggleRenderer(const wxString& varianttype,
void wxDataViewToggleRenderer::ShowAsRadio() 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() bool wxDataViewToggleRenderer::MacRender()