Implement macOS-specific wxDataViewCheckIconTextRenderer
This implementation suffers at least from 2 problems: 1. It doesn't support icons at all. 2. It toggles the checkbox when clicking on the text and not just on the checkbox itself, as would be expected. but it's still better than the current version which simply doesn't work at all, i.e. can't be toggled in any way (and also doesn't draw itself correctly when using dark mode under macOS 10.14+), so use it for now. A better solution would be to fix the problem with ActivateCell() not working at all (see #17746) and update the code to respect drawing in dark mode. Closes #17473. Closes https://github.com/wxWidgets/wxWidgets/pull/904
This commit is contained in:
committed by
Vadim Zeitlin
parent
fa3c0b1808
commit
235e61c311
@@ -539,6 +539,8 @@ typedef wxDataViewTextRenderer wxDataViewDateRenderer;
|
|||||||
// wxDataViewCheckIconTextRenderer: 3-state checkbox + text + optional icon
|
// wxDataViewCheckIconTextRenderer: 3-state checkbox + text + optional icon
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef __WXOSX__
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxDataViewCheckIconTextRenderer
|
class WXDLLIMPEXP_CORE wxDataViewCheckIconTextRenderer
|
||||||
: public wxDataViewCustomRenderer
|
: public wxDataViewCustomRenderer
|
||||||
{
|
{
|
||||||
@@ -589,6 +591,7 @@ private:
|
|||||||
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCheckIconTextRenderer);
|
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCheckIconTextRenderer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif // !__WXOSX__
|
||||||
|
|
||||||
// this class is obsolete, its functionality was merged in
|
// this class is obsolete, its functionality was merged in
|
||||||
// wxDataViewTextRenderer itself now, don't use it any more
|
// wxDataViewTextRenderer itself now, don't use it any more
|
||||||
|
@@ -184,6 +184,40 @@ private:
|
|||||||
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer);
|
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
// wxDataViewIconTextRenderer
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
|
class WXDLLIMPEXP_CORE wxDataViewCheckIconTextRenderer
|
||||||
|
: public wxDataViewRenderer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static wxString GetDefaultType() { return wxS("wxDataViewCheckIconText"); }
|
||||||
|
|
||||||
|
explicit wxDataViewCheckIconTextRenderer
|
||||||
|
(
|
||||||
|
wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
|
||||||
|
int align = wxDVR_DEFAULT_ALIGNMENT
|
||||||
|
);
|
||||||
|
|
||||||
|
// This renderer can always display the 3rd ("indeterminate") checkbox
|
||||||
|
// state if the model contains cells with wxCHK_UNDETERMINED value, but it
|
||||||
|
// doesn't allow the user to set it by default. Call this method to allow
|
||||||
|
// this to happen.
|
||||||
|
void Allow3rdStateForUser(bool allow = true);
|
||||||
|
|
||||||
|
virtual bool MacRender() wxOVERRIDE;
|
||||||
|
|
||||||
|
virtual void OSXOnCellChanged(NSObject *value,
|
||||||
|
const wxDataViewItem& item,
|
||||||
|
unsigned col) wxOVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_allow3rdStateForUser;
|
||||||
|
|
||||||
|
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCheckIconTextRenderer);
|
||||||
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// wxDataViewToggleRenderer
|
// wxDataViewToggleRenderer
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
@@ -1972,6 +1972,8 @@ wxSize wxDataViewDateRenderer::GetSize() const
|
|||||||
// wxDataViewCheckIconTextRenderer implementation
|
// wxDataViewCheckIconTextRenderer implementation
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef __WXOSX__
|
||||||
|
|
||||||
IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewCheckIconText, WXDLLIMPEXP_ADV)
|
IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewCheckIconText, WXDLLIMPEXP_ADV)
|
||||||
|
|
||||||
wxIMPLEMENT_CLASS(wxDataViewCheckIconText, wxDataViewIconText);
|
wxIMPLEMENT_CLASS(wxDataViewCheckIconText, wxDataViewIconText);
|
||||||
@@ -2162,6 +2164,8 @@ wxSize wxDataViewCheckIconTextRenderer::GetCheckSize() const
|
|||||||
return wxRendererNative::Get().GetCheckBoxSize(GetView());
|
return wxRendererNative::Get().GetCheckBoxSize(GetView());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // !__WXOSX__
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxDataViewListStore
|
// wxDataViewListStore
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@@ -3334,6 +3334,108 @@ void wxDataViewIconTextRenderer::OSXOnCellChanged(NSObject *value,
|
|||||||
|
|
||||||
wxIMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer,wxDataViewRenderer);
|
wxIMPLEMENT_ABSTRACT_CLASS(wxDataViewIconTextRenderer,wxDataViewRenderer);
|
||||||
|
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
// wxDataViewCheckIconTextRenderer
|
||||||
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
|
IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewCheckIconText, WXDLLIMPEXP_CORE)
|
||||||
|
|
||||||
|
wxIMPLEMENT_CLASS(wxDataViewCheckIconText, wxDataViewIconText);
|
||||||
|
|
||||||
|
wxDataViewCheckIconTextRenderer::wxDataViewCheckIconTextRenderer
|
||||||
|
(
|
||||||
|
wxDataViewCellMode mode,
|
||||||
|
int align
|
||||||
|
)
|
||||||
|
: wxDataViewRenderer(GetDefaultType(), mode,mode)
|
||||||
|
{
|
||||||
|
m_allow3rdStateForUser = false;
|
||||||
|
|
||||||
|
NSButtonCell* cell;
|
||||||
|
|
||||||
|
cell = [[NSButtonCell alloc] init];
|
||||||
|
[cell setAlignment:ConvertToNativeHorizontalTextAlignment(GetAlignment())];
|
||||||
|
[cell setButtonType: NSSwitchButton];
|
||||||
|
[cell setImagePosition:NSImageLeft];
|
||||||
|
[cell setAllowsMixedState:YES];
|
||||||
|
SetNativeData(new wxDataViewRendererNativeData(cell));
|
||||||
|
[cell release];
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewCheckIconTextRenderer::Allow3rdStateForUser(bool allow)
|
||||||
|
{
|
||||||
|
m_allow3rdStateForUser = allow;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxDataViewCheckIconTextRenderer::MacRender()
|
||||||
|
{
|
||||||
|
wxDataViewCheckIconText checkIconText;
|
||||||
|
|
||||||
|
checkIconText << GetValue();
|
||||||
|
|
||||||
|
NSButtonCell* cell = (NSButtonCell*) GetNativeData()->GetItemCell();
|
||||||
|
|
||||||
|
int nativecbvalue = 0;
|
||||||
|
switch ( checkIconText.GetCheckedState() )
|
||||||
|
{
|
||||||
|
case wxCHK_CHECKED:
|
||||||
|
nativecbvalue = 1;
|
||||||
|
break;
|
||||||
|
case wxCHK_UNDETERMINED:
|
||||||
|
nativecbvalue = -1;
|
||||||
|
break;
|
||||||
|
case wxCHK_UNCHECKED:
|
||||||
|
nativecbvalue = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
[cell setIntValue:nativecbvalue];
|
||||||
|
[cell setTitle:wxCFStringRef(checkIconText.GetText()).AsNSString()];
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewCheckIconTextRenderer::OSXOnCellChanged(NSObject *value,
|
||||||
|
const wxDataViewItem& item,
|
||||||
|
unsigned col)
|
||||||
|
{
|
||||||
|
wxDataViewModel *model = GetOwner()->GetOwner()->GetModel();
|
||||||
|
|
||||||
|
// The icon can't be edited so get its old value and reuse it.
|
||||||
|
wxVariant valueOld;
|
||||||
|
model->GetValue(valueOld, item, col);
|
||||||
|
|
||||||
|
wxDataViewCheckIconText checkIconText;
|
||||||
|
checkIconText << valueOld;
|
||||||
|
|
||||||
|
wxCheckBoxState checkedState ;
|
||||||
|
switch ( ObjectToLong(value) )
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
checkedState = wxCHK_CHECKED;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0:
|
||||||
|
checkedState = wxCHK_UNCHECKED;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case -1:
|
||||||
|
checkedState = m_allow3rdStateForUser ? wxCHK_UNDETERMINED : wxCHK_CHECKED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkIconText.SetCheckedState(checkedState);
|
||||||
|
|
||||||
|
wxVariant valueIconText;
|
||||||
|
valueIconText << checkIconText;
|
||||||
|
|
||||||
|
if ( !Validate(valueIconText) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
model->ChangeValue(valueIconText, item, col);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxIMPLEMENT_ABSTRACT_CLASS(wxDataViewCheckIconTextRenderer,wxDataViewRenderer);
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// wxDataViewToggleRenderer
|
// wxDataViewToggleRenderer
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user