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:
parent
6c6cc08975
commit
61223ab32d
@ -207,6 +207,8 @@ public:
|
||||
unsigned col);
|
||||
|
||||
private:
|
||||
void DoInitButtonCell(int buttonType);
|
||||
|
||||
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer);
|
||||
};
|
||||
|
||||
|
@ -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<NSButtonType>(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()
|
||||
|
Loading…
Reference in New Issue
Block a user