Kaydet (Commit) f08c5964 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

Draw basic RadioButton from the theme definition

Change-Id: I5bc4aa44174a89fd3003ee032f65d9d02a87a969
Reviewed-on: https://gerrit.libreoffice.org/68653
Tested-by: Jenkins
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst fd23d1ed
......@@ -24,7 +24,8 @@ namespace vcl
{
enum class DrawCommandType
{
RECTANGLE
RECTANGLE,
CIRCLE
};
class VCL_DLLPUBLIC DrawCommand
......@@ -59,6 +60,15 @@ public:
}
};
class VCL_DLLPUBLIC CircleDrawCommand : public DrawCommand
{
public:
CircleDrawCommand()
: DrawCommand(DrawCommandType::CIRCLE)
{
}
};
class VCL_DLLPUBLIC WidgetDefinitionState
{
public:
......@@ -77,6 +87,8 @@ public:
void addDrawRectangle(Color aStrokeColor, sal_Int32 nStrokeWidth, Color aFillColor,
sal_Int32 nRx, sal_Int32 nRy, sal_Int32 nMargin);
void addDrawCircle(Color aStrokeColor, sal_Int32 nStrokeWidth, Color aFillColor,
sal_Int32 nMargin);
};
class VCL_DLLPUBLIC WidgetDefinition
......@@ -93,6 +105,7 @@ private:
OUString m_rFilePath;
void readPushButton(tools::XmlWalker& rWalker);
void readRadioButton(tools::XmlWalker& rWalker);
static void readDrawingDefinition(tools::XmlWalker& rWalker,
std::shared_ptr<WidgetDefinitionState>& rStates);
......@@ -149,8 +162,10 @@ public:
Color maFontColor;
std::unordered_map<OString, std::shared_ptr<WidgetDefinition>> maPushButtonDefinitions;
std::unordered_map<OString, std::shared_ptr<WidgetDefinition>> maRadioButtonDefinitions;
std::shared_ptr<WidgetDefinition> getPushButtonDefinition(ControlPart ePart);
std::shared_ptr<WidgetDefinition> getRadioButtonDefinition(ControlPart ePart);
WidgetDefinitionReader(OUString const& rFilePath);
bool read();
......
......@@ -47,6 +47,7 @@ bool FileDefinitionWidgetDraw::isNativeControlSupported(ControlType eType, Contr
case ControlType::Pushbutton:
return true;
case ControlType::Radiobutton:
return true;
case ControlType::Checkbox:
case ControlType::Combobox:
case ControlType::Editbox:
......@@ -111,6 +112,26 @@ void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCom
basegfx::B2DPolyPolygon(aB2DPolygon), 0.0f, nullptr);
}
break;
case DrawCommandType::CIRCLE:
{
auto const& rCircleDrawCommand
= static_cast<CircleDrawCommand const&>(*pDrawCommand);
Point aRectPoint(nX + 1 + rCircleDrawCommand.mnMargin,
nY + 1 + rCircleDrawCommand.mnMargin);
Size aRectSize(nWidth - 1 - 2 * rCircleDrawCommand.mnMargin,
nHeight - 1 - 2 * rCircleDrawCommand.mnMargin);
tools::Rectangle aRectangle(aRectPoint, aRectSize);
tools::Polygon aPolygon(aRectangle.Center(), aRectangle.GetWidth() >> 1,
aRectangle.GetHeight() >> 1);
basegfx::B2DPolygon aB2DPolygon(aPolygon.getB2DPolygon());
rGraphics.SetLineColor(rCircleDrawCommand.maStrokeColor);
rGraphics.SetFillColor(rCircleDrawCommand.maFillColor);
rGraphics.DrawPolyPolygon(basegfx::B2DHomMatrix(),
basegfx::B2DPolyPolygon(aB2DPolygon), 0.0f, nullptr);
}
break;
}
}
}
......@@ -155,6 +176,20 @@ bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart
}
break;
case ControlType::Radiobutton:
{
std::shared_ptr<WidgetDefinition> pDefinition
= m_WidgetDefinitionReader.getRadioButtonDefinition(ePart);
if (pDefinition)
{
std::shared_ptr<WidgetDefinitionState> pState
= pDefinition->getStates(eState).back();
{
munchDrawCommands(pState->mpDrawCommands, m_rGraphics, nX, nY, nWidth, nHeight);
bOK = true;
}
}
}
break;
case ControlType::Checkbox:
case ControlType::Combobox:
case ControlType::Editbox:
......
......@@ -96,6 +96,24 @@ void WidgetDefinitionReader::readDrawingDefinition(tools::XmlWalker& rWalker,
rpState->addDrawRectangle(aStrokeColor, nStrokeWidth, aFillColor, nRx, nRy, nMargin);
}
else if (rWalker.name() == "circ")
{
Color aStrokeColor;
readColor(rWalker.attribute("stroke"), aStrokeColor);
Color aFillColor;
readColor(rWalker.attribute("fill"), aFillColor);
OString sStrokeWidth = rWalker.attribute("stroke-width");
sal_Int32 nStrokeWidth = -1;
if (!sStrokeWidth.isEmpty())
nStrokeWidth = sStrokeWidth.toInt32();
sal_Int32 nMargin = 0;
OString sMargin = rWalker.attribute("margin");
if (!sMargin.isEmpty())
nMargin = sMargin.toInt32();
rpState->addDrawCircle(aStrokeColor, nStrokeWidth, aFillColor, nMargin);
}
rWalker.next();
}
rWalker.parent();
......@@ -138,6 +156,43 @@ void WidgetDefinitionReader::readPushButton(tools::XmlWalker& rWalker)
rWalker.parent();
}
void WidgetDefinitionReader::readRadioButton(tools::XmlWalker& rWalker)
{
rWalker.children();
while (rWalker.isValid())
{
if (rWalker.name() == "part")
{
OString sPart = rWalker.attribute("value");
std::shared_ptr<WidgetDefinition> pPart = std::make_shared<WidgetDefinition>();
maRadioButtonDefinitions.emplace(sPart, pPart);
rWalker.children();
while (rWalker.isValid())
{
if (rWalker.name() == "state")
{
OString sEnabled = rWalker.attribute("enabled");
OString sFocused = rWalker.attribute("focused");
OString sPressed = rWalker.attribute("pressed");
OString sRollover = rWalker.attribute("rollover");
OString sDefault = rWalker.attribute("default");
OString sSelected = rWalker.attribute("selected");
std::shared_ptr<WidgetDefinitionState> pState
= std::make_shared<WidgetDefinitionState>(sEnabled, sFocused, sPressed,
sRollover, sDefault, sSelected);
pPart->maStates.push_back(pState);
readDrawingDefinition(rWalker, pState);
}
rWalker.next();
}
rWalker.parent();
}
rWalker.next();
}
rWalker.parent();
}
bool WidgetDefinitionReader::read()
{
if (!lcl_fileExists(m_rFilePath))
......@@ -226,6 +281,10 @@ bool WidgetDefinitionReader::read()
{
readPushButton(aWalker);
}
else if (aWalker.name() == "radiobutton")
{
readRadioButton(aWalker);
}
aWalker.next();
}
aWalker.parent();
......@@ -327,6 +386,16 @@ std::shared_ptr<WidgetDefinition> WidgetDefinitionReader::getPushButtonDefinitio
return std::shared_ptr<WidgetDefinition>();
}
std::shared_ptr<WidgetDefinition>
WidgetDefinitionReader::getRadioButtonDefinition(ControlPart ePart)
{
auto aIterator = maRadioButtonDefinitions.find(xmlControlPart(ePart));
if (aIterator != maRadioButtonDefinitions.end())
return aIterator->second;
return std::shared_ptr<WidgetDefinition>();
}
std::vector<std::shared_ptr<WidgetDefinitionState>> WidgetDefinition::getStates(ControlState eState)
{
std::vector<std::shared_ptr<WidgetDefinitionState>> aStatesToAdd;
......@@ -394,6 +463,17 @@ void WidgetDefinitionState::addDrawRectangle(Color aStrokeColor, sal_Int32 nStro
mpDrawCommands.push_back(pCommand);
}
void WidgetDefinitionState::addDrawCircle(Color aStrokeColor, sal_Int32 nStrokeWidth,
Color aFillColor, sal_Int32 nMargin)
{
std::unique_ptr<DrawCommand> pCommand(std::make_unique<CircleDrawCommand>());
pCommand->maStrokeColor = aStrokeColor;
pCommand->maFillColor = aFillColor;
pCommand->mnStrokeWidth = nStrokeWidth;
pCommand->mnMargin = nMargin;
mpDrawCommands.push_back(std::move(pCommand));
}
} // end vcl namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -66,4 +66,17 @@
</part>
</pushbutton>
<radiobutton>
<part value="Entire">
<state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any">
<circ stroke="#007AFF" fill="#FFFFFF" stroke-width="1" margin="0"/>
<circ stroke="#007AFF" fill="#007AFF" stroke-width="1" margin="3"/>
</state>
<state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any">
<circ stroke="#007AFF" fill="#FFFFFF" stroke-width="1" margin="0"/>
<circ stroke="#007AFF" fill="#007AFF" stroke-width="1" margin="3"/>
</state>
</part>
</radiobutton>
</widgets>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment