Add undetermined state to wxCheckBoxXmlHandler

3-state checkboxes can have their initial value set to checked
or undetermined -- this adds support for the undetermined
state to the handler (only allowed if the style includes wxCHK_3STATE).

Closes #22468.
This commit is contained in:
Randalphwa
2022-05-28 08:23:47 -07:00
committed by Vadim Zeitlin
parent 070bc8bd29
commit cb8c0dfb0d
3 changed files with 37 additions and 4 deletions

View File

@@ -946,8 +946,10 @@ No additional properties.
@hdr3col{property, type, description}
@row3col{label, @ref overview_xrcformat_type_text,
Label to use for the checkbox (default: empty).}
@row3col{checked, @ref overview_xrcformat_type_bool,
Should the checkbox be checked initially (default: 0)?}
@row3col{checked, integer,
Sets the initial state of the checkbox. 0 is unchecked (default),
1 is checked, and since wxWidgets 3.1.7, 2 sets the undetermined
state of a 3-state checkbox.}
@endTable

View File

@@ -765,7 +765,7 @@ wxCheckBox =
stdObjectNodeAttributes &
stdWindowProperties &
[xrc:p="important"] element label {_, t_text }* &
[xrc:p="o"] element checked {_, t_bool }*
[xrc:p="o"] element checked {_, t_integer }*
}

View File

@@ -43,7 +43,38 @@ wxObject *wxCheckBoxXmlHandler::DoCreateResource()
wxDefaultValidator,
GetName());
control->SetValue(GetBool( wxT("checked")));
switch (GetLong("checked", wxCHK_UNCHECKED))
{
case wxCHK_UNCHECKED:
// Nothing to do here, we could call SetValue() but the default state
// is unchecked anyhow.
break;
case wxCHK_CHECKED:
control->SetValue(true);
break;
case wxCHK_UNDETERMINED:
// While just trying to set it would generate an assert if wxCHK_3STATE
// is not set, prefer to give an error here as we have more information
// about the problem.
if ( !control->HasFlag(wxCHK_3STATE) )
{
ReportParamError("checked",
"A checkbox must have wxCHK_3STATE style to use wxCHK_UNDETERMINED");
break;
}
control->Set3StateValue(wxCHK_UNDETERMINED);
break;
default:
ReportParamError("checked",
wxString::Format("Unknown checkbox state: \"%s\"",
GetParamValue("checked")));
break;
}
SetupWindow(control);
return control;