Add support for button-value to correctly draw the radiobutton

Change-Id: I392289f0ab284aec2ed0fb039a03fb93bf0b4aad
Reviewed-on: https://gerrit.libreoffice.org/68654
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
Tomaž Vajngerl
2019-01-23 00:58:23 +01:00
committed by Tomaž Vajngerl
parent 2e77a44ea1
commit b07a71e09a
4 changed files with 37 additions and 18 deletions

View File

@@ -78,10 +78,11 @@ public:
OString msRollover; OString msRollover;
OString msDefault; OString msDefault;
OString msSelected; OString msSelected;
OString msButtonValue;
WidgetDefinitionState(OString const& sEnabled, OString const& sFocused, OString const& sPressed, WidgetDefinitionState(OString const& sEnabled, OString const& sFocused, OString const& sPressed,
OString const& sRollover, OString const& sDefault, OString const& sRollover, OString const& sDefault,
OString const& sSelected); OString const& sSelected, OString const& sButtonValue);
std::vector<std::shared_ptr<DrawCommand>> mpDrawCommands; std::vector<std::shared_ptr<DrawCommand>> mpDrawCommands;
@@ -94,7 +95,8 @@ public:
class VCL_DLLPUBLIC WidgetDefinition class VCL_DLLPUBLIC WidgetDefinition
{ {
public: public:
std::vector<std::shared_ptr<WidgetDefinitionState>> getStates(ControlState eState); std::vector<std::shared_ptr<WidgetDefinitionState>> getStates(ControlState eState,
ImplControlValue const& rValue);
std::vector<std::shared_ptr<WidgetDefinitionState>> maStates; std::vector<std::shared_ptr<WidgetDefinitionState>> maStates;
}; };

View File

@@ -141,7 +141,7 @@ void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCom
bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart ePart, bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart ePart,
const tools::Rectangle& rControlRegion, const tools::Rectangle& rControlRegion,
ControlState eState, ControlState eState,
const ImplControlValue& /*rValue*/, const ImplControlValue& rValue,
const OUString& /*aCaptions*/) const OUString& /*aCaptions*/)
{ {
bool bOldAA = m_rGraphics.getAntiAliasB2DDraw(); bool bOldAA = m_rGraphics.getAntiAliasB2DDraw();
@@ -166,11 +166,15 @@ bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart
= m_WidgetDefinitionReader.getPushButtonDefinition(ePart); = m_WidgetDefinitionReader.getPushButtonDefinition(ePart);
if (pDefinition) if (pDefinition)
{ {
std::shared_ptr<WidgetDefinitionState> pState auto aStates = pDefinition->getStates(eState, rValue);
= pDefinition->getStates(eState).back(); if (!aStates.empty())
{ {
munchDrawCommands(pState->mpDrawCommands, m_rGraphics, nX, nY, nWidth, nHeight); std::shared_ptr<WidgetDefinitionState> pState = aStates.back();
bOK = true; {
munchDrawCommands(pState->mpDrawCommands, m_rGraphics, nX, nY, nWidth,
nHeight);
bOK = true;
}
} }
} }
} }
@@ -182,7 +186,7 @@ bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart
if (pDefinition) if (pDefinition)
{ {
std::shared_ptr<WidgetDefinitionState> pState std::shared_ptr<WidgetDefinitionState> pState
= pDefinition->getStates(eState).back(); = pDefinition->getStates(eState, rValue).back();
{ {
munchDrawCommands(pState->mpDrawCommands, m_rGraphics, nX, nY, nWidth, nHeight); munchDrawCommands(pState->mpDrawCommands, m_rGraphics, nX, nY, nWidth, nHeight);
bOK = true; bOK = true;

View File

@@ -140,10 +140,12 @@ void WidgetDefinitionReader::readPushButton(tools::XmlWalker& rWalker)
OString sRollover = rWalker.attribute("rollover"); OString sRollover = rWalker.attribute("rollover");
OString sDefault = rWalker.attribute("default"); OString sDefault = rWalker.attribute("default");
OString sSelected = rWalker.attribute("selected"); OString sSelected = rWalker.attribute("selected");
OString sButtonValue = rWalker.attribute("button-value");
std::shared_ptr<WidgetDefinitionState> pState std::shared_ptr<WidgetDefinitionState> pState
= std::make_shared<WidgetDefinitionState>(sEnabled, sFocused, sPressed, = std::make_shared<WidgetDefinitionState>(sEnabled, sFocused, sPressed,
sRollover, sDefault, sSelected); sRollover, sDefault, sSelected,
sButtonValue);
pPart->maStates.push_back(pState); pPart->maStates.push_back(pState);
readDrawingDefinition(rWalker, pState); readDrawingDefinition(rWalker, pState);
} }
@@ -177,10 +179,12 @@ void WidgetDefinitionReader::readRadioButton(tools::XmlWalker& rWalker)
OString sRollover = rWalker.attribute("rollover"); OString sRollover = rWalker.attribute("rollover");
OString sDefault = rWalker.attribute("default"); OString sDefault = rWalker.attribute("default");
OString sSelected = rWalker.attribute("selected"); OString sSelected = rWalker.attribute("selected");
OString sButtonValue = rWalker.attribute("button-value");
sButtonValue = sButtonValue.isEmpty() ? "any" : sButtonValue;
std::shared_ptr<WidgetDefinitionState> pState std::shared_ptr<WidgetDefinitionState> pState
= std::make_shared<WidgetDefinitionState>(sEnabled, sFocused, sPressed, = std::make_shared<WidgetDefinitionState>(sEnabled, sFocused, sPressed,
sRollover, sDefault, sSelected); sRollover, sDefault, sSelected,
sButtonValue);
pPart->maStates.push_back(pState); pPart->maStates.push_back(pState);
readDrawingDefinition(rWalker, pState); readDrawingDefinition(rWalker, pState);
} }
@@ -396,7 +400,8 @@ WidgetDefinitionReader::getRadioButtonDefinition(ControlPart ePart)
return std::shared_ptr<WidgetDefinition>(); return std::shared_ptr<WidgetDefinition>();
} }
std::vector<std::shared_ptr<WidgetDefinitionState>> WidgetDefinition::getStates(ControlState eState) std::vector<std::shared_ptr<WidgetDefinitionState>>
WidgetDefinition::getStates(ControlState eState, ImplControlValue const& rValue)
{ {
std::vector<std::shared_ptr<WidgetDefinitionState>> aStatesToAdd; std::vector<std::shared_ptr<WidgetDefinitionState>> aStatesToAdd;
@@ -429,6 +434,13 @@ std::vector<std::shared_ptr<WidgetDefinitionState>> WidgetDefinition::getStates(
|| (state->msSelected == "false" && !(eState & ControlState::SELECTED)))) || (state->msSelected == "false" && !(eState & ControlState::SELECTED))))
bAdd = false; bAdd = false;
ButtonValue eButtonValue = rValue.getTristateVal();
if (state->msButtonValue != "any"
&& !((state->msButtonValue == "true" && eButtonValue == ButtonValue::On)
|| (state->msButtonValue == "false" && eButtonValue != ButtonValue::On)))
bAdd = false;
if (bAdd) if (bAdd)
aStatesToAdd.push_back(state); aStatesToAdd.push_back(state);
} }
@@ -438,13 +450,15 @@ std::vector<std::shared_ptr<WidgetDefinitionState>> WidgetDefinition::getStates(
WidgetDefinitionState::WidgetDefinitionState(OString const& sEnabled, OString const& sFocused, WidgetDefinitionState::WidgetDefinitionState(OString const& sEnabled, OString const& sFocused,
OString const& sPressed, OString const& sRollover, OString const& sPressed, OString const& sRollover,
OString const& sDefault, OString const& sSelected) OString const& sDefault, OString const& sSelected,
OString const& sButtonValue)
: msEnabled(sEnabled) : msEnabled(sEnabled)
, msFocused(sFocused) , msFocused(sFocused)
, msPressed(sPressed) , msPressed(sPressed)
, msRollover(sRollover) , msRollover(sRollover)
, msDefault(sDefault) , msDefault(sDefault)
, msSelected(sSelected) , msSelected(sSelected)
, msButtonValue(sButtonValue)
{ {
} }

View File

@@ -56,11 +56,11 @@
<pushbutton> <pushbutton>
<part value="Entire"> <part value="Entire">
<state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any"> <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any">
<rect stroke="#007AFF" fill="#FFFFFF" stroke-width="1" rx="5" ry="5" margin="0"/> <rect stroke="#007AFF" fill="#FFFFFF" stroke-width="1" rx="5" ry="5" margin="0"/>
</state> </state>
<state enabled="true" focused="any" pressed="any" rollover="true" default="any" selected="any"> <state enabled="true" focused="any" pressed="any" rollover="true" default="any" selected="any" button-value="any">
<rect stroke="#007AFF" fill="#007AFF" stroke-width="1" rx="5" ry="5" margin="0"/> <rect stroke="#007AFF" fill="#007AFF" stroke-width="1" rx="5" ry="5" margin="0"/>
</state> </state>
</part> </part>
@@ -68,11 +68,10 @@
<radiobutton> <radiobutton>
<part value="Entire"> <part value="Entire">
<state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any"> <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="false">
<circ stroke="#007AFF" fill="#FFFFFF" stroke-width="1" margin="0"/> <circ stroke="#007AFF" fill="#FFFFFF" stroke-width="1" margin="0"/>
<circ stroke="#007AFF" fill="#007AFF" stroke-width="1" margin="3"/>
</state> </state>
<state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any"> <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="true">
<circ stroke="#007AFF" fill="#FFFFFF" stroke-width="1" margin="0"/> <circ stroke="#007AFF" fill="#FFFFFF" stroke-width="1" margin="0"/>
<circ stroke="#007AFF" fill="#007AFF" stroke-width="1" margin="3"/> <circ stroke="#007AFF" fill="#007AFF" stroke-width="1" margin="3"/>
</state> </state>