vcl/inc/widgetdraw/WidgetDefinitionReader.hxx | 17 +++++ vcl/source/gdi/FileDefinitionWidgetDraw.cxx | 35 +++++++++++ vcl/source/gdi/WidgetDefinitionReader.cxx | 80 ++++++++++++++++++++++++++ vcl/uiconfig/theme_definitions/definition.xml | 13 ++++ 4 files changed, 144 insertions(+), 1 deletion(-)
New commits: commit f08c5964f6c2143a28969f10dcc1269cfcb7e64a Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Jan 22 21:30:00 2019 +0100 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon Mar 4 12:29:43 2019 +0100 Draw basic RadioButton from the theme definition Change-Id: I5bc4aa44174a89fd3003ee032f65d9d02a87a969 Reviewed-on: https://gerrit.libreoffice.org/68653 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx b/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx index a5d8661304ea..e88ebac924be 100644 --- a/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx +++ b/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx @@ -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(); diff --git a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx index 7b493c507b26..55f556349a78 100644 --- a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx +++ b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx @@ -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: diff --git a/vcl/source/gdi/WidgetDefinitionReader.cxx b/vcl/source/gdi/WidgetDefinitionReader.cxx index 0d78522abfd2..85276e3a35e8 100644 --- a/vcl/source/gdi/WidgetDefinitionReader.cxx +++ b/vcl/source/gdi/WidgetDefinitionReader.cxx @@ -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: */ diff --git a/vcl/uiconfig/theme_definitions/definition.xml b/vcl/uiconfig/theme_definitions/definition.xml index dbf87fddd6ba..9ee8838fa705 100644 --- a/vcl/uiconfig/theme_definitions/definition.xml +++ b/vcl/uiconfig/theme_definitions/definition.xml @@ -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> _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits