diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2019-01-25 23:10:57 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2019-03-04 21:20:24 +0100 |
commit | 9671ac2dac00c21ae840cb29c2671b22ab95a7b2 (patch) | |
tree | f2a7867d2ac0918e15bb9af0aed47807f780606f | |
parent | a69ce55133b3d4dd763300ed678f30a05830c23a (diff) |
Refactor so we have only one definition map and ControlTypeAndPart
Until now we had multiple maps, each for a specific ControlType
(maPushButtonDefinitions for example) which had multiple parts
identified by the string.
To simplify matters, this changes that we have just one map for
a specific ControlType and ControlPart which are identified by
ControlTypeAndPart structure.
Change-Id: I90a2e5c8f83d697d26049054eacab250e2768c03
Reviewed-on: https://gerrit.libreoffice.org/68690
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | vcl/inc/widgetdraw/WidgetDefinition.hxx | 48 | ||||
-rw-r--r-- | vcl/inc/widgetdraw/WidgetDefinitionReader.hxx | 5 | ||||
-rw-r--r-- | vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx | 8 | ||||
-rw-r--r-- | vcl/source/gdi/FileDefinitionWidgetDraw.cxx | 6 | ||||
-rw-r--r-- | vcl/source/gdi/WidgetDefinition.cxx | 110 | ||||
-rw-r--r-- | vcl/source/gdi/WidgetDefinitionReader.cxx | 117 |
6 files changed, 158 insertions, 136 deletions
diff --git a/vcl/inc/widgetdraw/WidgetDefinition.hxx b/vcl/inc/widgetdraw/WidgetDefinition.hxx index 423ab1d970c3..486d61802654 100644 --- a/vcl/inc/widgetdraw/WidgetDefinition.hxx +++ b/vcl/inc/widgetdraw/WidgetDefinition.hxx @@ -17,6 +17,9 @@ #include <tools/color.hxx> #include <unordered_map> #include <vector> +#include <cstddef> +#include <functional> +#include <boost/functional/hash.hpp> #include <vcl/salnativewidgets.hxx> namespace vcl @@ -83,6 +86,42 @@ public: } }; +struct VCL_DLLPUBLIC ControlTypeAndPart +{ + ControlType const meType; + ControlPart const mePart; + + ControlTypeAndPart(ControlType eType, ControlPart ePart) + : meType(eType) + , mePart(ePart) + { + } + + bool operator==(ControlTypeAndPart const& aOther) const + { + return meType == aOther.meType && mePart == aOther.mePart; + } +}; + +} // end vcl namespace + +namespace std +{ +template <> struct VCL_DLLPUBLIC hash<vcl::ControlTypeAndPart> +{ + std::size_t operator()(vcl::ControlTypeAndPart const& rControlTypeAndPart) const noexcept + { + std::size_t seed = 0; + boost::hash_combine(seed, rControlTypeAndPart.meType); + boost::hash_combine(seed, rControlTypeAndPart.mePart); + return seed; + } +}; + +} // end std namespace + +namespace vcl +{ class VCL_DLLPUBLIC WidgetDefinitionState { public: @@ -171,13 +210,8 @@ public: Color maToolTextColor; Color maFontColor; - std::unordered_map<OString, std::shared_ptr<WidgetDefinitionPart>> maPushButtonDefinitions; - std::unordered_map<OString, std::shared_ptr<WidgetDefinitionPart>> maRadioButtonDefinitions; - std::unordered_map<OString, std::shared_ptr<WidgetDefinitionPart>> maEditboxDefinitions; - - std::shared_ptr<WidgetDefinitionPart> getPushButtonDefinition(ControlPart ePart); - std::shared_ptr<WidgetDefinitionPart> getRadioButtonDefinition(ControlPart ePart); - std::shared_ptr<WidgetDefinitionPart> getEditboxDefinition(ControlPart ePart); + std::unordered_map<ControlTypeAndPart, std::shared_ptr<WidgetDefinitionPart>> maDefinitions; + std::shared_ptr<WidgetDefinitionPart> getDefinition(ControlType eType, ControlPart ePart); }; } // end vcl namespace diff --git a/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx b/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx index 1cb577c08c4d..53da5e1a3bed 100644 --- a/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx +++ b/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx @@ -24,9 +24,8 @@ class VCL_DLLPUBLIC WidgetDefinitionReader private: OUString m_rFilePath; - static void - readDefinition(tools::XmlWalker& rWalker, - std::unordered_map<OString, std::shared_ptr<WidgetDefinitionPart>>& rDefinition); + static void readDefinition(tools::XmlWalker& rWalker, WidgetDefinition& rWidgetDefinition, + ControlType eType); static void readPart(tools::XmlWalker& rWalker, std::shared_ptr<WidgetDefinitionPart> rpPart); diff --git a/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx b/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx index 54ac184651ca..6f64c95ebd7a 100644 --- a/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx +++ b/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx @@ -54,9 +54,10 @@ void WidgetDefinitionReaderTest::testRead() CPPUNIT_ASSERT_EQUAL(OUString("ffffff"), aDefinition.maToolTextColor.AsRGBHexString()); CPPUNIT_ASSERT_EQUAL(OUString("ffffff"), aDefinition.maFontColor.AsRGBHexString()); + // Pushbutton { std::vector<std::shared_ptr<vcl::WidgetDefinitionState>> aStates - = aDefinition.getPushButtonDefinition(ControlPart::Entire) + = aDefinition.getDefinition(ControlType::Pushbutton, ControlPart::Entire) ->getStates(ControlState::DEFAULT | ControlState::ENABLED | ControlState::ROLLOVER, ImplControlValue()); @@ -69,9 +70,10 @@ void WidgetDefinitionReaderTest::testRead() CPPUNIT_ASSERT_EQUAL(vcl::DrawCommandType::CIRCLE, aStates[0]->mpDrawCommands[1]->maType); } + // Radiobutton { std::vector<std::shared_ptr<vcl::WidgetDefinitionState>> aStates - = aDefinition.getRadioButtonDefinition(ControlPart::Entire) + = aDefinition.getDefinition(ControlType::Radiobutton, ControlPart::Entire) ->getStates(ControlState::NONE, ImplControlValue(ButtonValue::On)); CPPUNIT_ASSERT_EQUAL(size_t(1), aStates.size()); CPPUNIT_ASSERT_EQUAL(size_t(2), aStates[0]->mpDrawCommands.size()); @@ -79,7 +81,7 @@ void WidgetDefinitionReaderTest::testRead() { std::vector<std::shared_ptr<vcl::WidgetDefinitionState>> aStates - = aDefinition.getRadioButtonDefinition(ControlPart::Entire) + = aDefinition.getDefinition(ControlType::Radiobutton, ControlPart::Entire) ->getStates(ControlState::NONE, ImplControlValue(ButtonValue::Off)); CPPUNIT_ASSERT_EQUAL(size_t(1), aStates.size()); CPPUNIT_ASSERT_EQUAL(size_t(1), aStates[0]->mpDrawCommands.size()); diff --git a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx index c28967eb9b7f..9b4aa8a8c8c9 100644 --- a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx +++ b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx @@ -197,7 +197,7 @@ bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart case ControlType::Pushbutton: { std::shared_ptr<WidgetDefinitionPart> pPart - = m_aWidgetDefinition.getPushButtonDefinition(ePart); + = m_aWidgetDefinition.getDefinition(eType, ePart); if (pPart) { auto aStates = pPart->getStates(eState, rValue); @@ -216,7 +216,7 @@ bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart case ControlType::Radiobutton: { std::shared_ptr<WidgetDefinitionPart> pPart - = m_aWidgetDefinition.getRadioButtonDefinition(ePart); + = m_aWidgetDefinition.getDefinition(eType, ePart); if (pPart) { std::shared_ptr<WidgetDefinitionState> pState @@ -236,7 +236,7 @@ bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart case ControlType::MultilineEditbox: { std::shared_ptr<WidgetDefinitionPart> pPart - = m_aWidgetDefinition.getEditboxDefinition(ePart); + = m_aWidgetDefinition.getDefinition(eType, ePart); if (pPart) { std::shared_ptr<WidgetDefinitionState> pState diff --git a/vcl/source/gdi/WidgetDefinition.cxx b/vcl/source/gdi/WidgetDefinition.cxx index e5fc5e8ae8f2..36d362479c27 100644 --- a/vcl/source/gdi/WidgetDefinition.cxx +++ b/vcl/source/gdi/WidgetDefinition.cxx @@ -16,114 +16,12 @@ namespace vcl { -namespace +std::shared_ptr<WidgetDefinitionPart> WidgetDefinition::getDefinition(ControlType eType, + ControlPart ePart) { -OString xmlControlPart(ControlPart ePart) -{ - switch (ePart) - { - case ControlPart::NONE: - return "NONE"; - case ControlPart::Entire: - return "Entire"; - case ControlPart::ListboxWindow: - return "ListboxWindow"; - case ControlPart::Button: - return "NONE"; - case ControlPart::ButtonUp: - return "NONE"; - case ControlPart::ButtonDown: - return "NONE"; - case ControlPart::ButtonLeft: - return "NONE"; - case ControlPart::ButtonRight: - return "NONE"; - case ControlPart::AllButtons: - return "NONE"; - case ControlPart::SeparatorHorz: - return "NONE"; - case ControlPart::SeparatorVert: - return "NONE"; - case ControlPart::TrackHorzLeft: - return "NONE"; - case ControlPart::TrackVertUpper: - return "NONE"; - case ControlPart::TrackHorzRight: - return "NONE"; - case ControlPart::TrackVertLower: - return "NONE"; - case ControlPart::TrackHorzArea: - return "NONE"; - case ControlPart::TrackVertArea: - return "NONE"; - case ControlPart::Arrow: - return "NONE"; - case ControlPart::ThumbHorz: - return "NONE"; - case ControlPart::ThumbVert: - return "NONE"; - case ControlPart::MenuItem: - return "NONE"; - case ControlPart::MenuItemCheckMark: - return "NONE"; - case ControlPart::MenuItemRadioMark: - return "NONE"; - case ControlPart::Separator: - return "NONE"; - case ControlPart::SubmenuArrow: - return "NONE"; - case ControlPart::SubEdit: - return "NONE"; - case ControlPart::DrawBackgroundHorz: - return "NONE"; - case ControlPart::DrawBackgroundVert: - return "NONE"; - case ControlPart::TabsDrawRtl: - return "NONE"; - case ControlPart::HasBackgroundTexture: - return "NONE"; - case ControlPart::HasThreeButtons: - return "NONE"; - case ControlPart::BackgroundWindow: - return "NONE"; - case ControlPart::BackgroundDialog: - return "NONE"; - case ControlPart::Border: - return "NONE"; - case ControlPart::Focus: - return "FOCUS"; - - default: - break; - } - return "NONE"; -} - -} // end anonymous namespace - -std::shared_ptr<WidgetDefinitionPart> WidgetDefinition::getPushButtonDefinition(ControlPart ePart) -{ - auto aIterator = maPushButtonDefinitions.find(xmlControlPart(ePart)); - - if (aIterator != maPushButtonDefinitions.end()) - return aIterator->second; - return std::shared_ptr<WidgetDefinitionPart>(); -} - -std::shared_ptr<WidgetDefinitionPart> WidgetDefinition::getRadioButtonDefinition(ControlPart ePart) -{ - auto aIterator = maRadioButtonDefinitions.find(xmlControlPart(ePart)); - - if (aIterator != maRadioButtonDefinitions.end()) - return aIterator->second; - return std::shared_ptr<WidgetDefinitionPart>(); -} - -std::shared_ptr<WidgetDefinitionPart> WidgetDefinition::getEditboxDefinition(ControlPart ePart) -{ - auto aIterator = maEditboxDefinitions.find(xmlControlPart(ePart)); + auto aIterator = maDefinitions.find(ControlTypeAndPart(eType, ePart)); - if (aIterator != maEditboxDefinitions.end()) + if (aIterator != maDefinitions.end()) return aIterator->second; return std::shared_ptr<WidgetDefinitionPart>(); } diff --git a/vcl/source/gdi/WidgetDefinitionReader.cxx b/vcl/source/gdi/WidgetDefinitionReader.cxx index e9c40d46a2fd..bc9ce749dfad 100644 --- a/vcl/source/gdi/WidgetDefinitionReader.cxx +++ b/vcl/source/gdi/WidgetDefinitionReader.cxx @@ -55,6 +55,102 @@ bool readColor(OString const& rString, Color& rColor) return true; } +ControlPart xmlStringToControlPart(OString const& sPart) +{ + if (sPart.equalsIgnoreAsciiCase("NONE")) + return ControlPart::NONE; + else if (sPart.equalsIgnoreAsciiCase("Entire")) + return ControlPart::Entire; + else if (sPart.equalsIgnoreAsciiCase("ListboxWindow")) + return ControlPart::ListboxWindow; + else if (sPart.equalsIgnoreAsciiCase("Button")) + return ControlPart::Button; + else if (sPart.equalsIgnoreAsciiCase("ButtonUp")) + return ControlPart::ButtonUp; + else if (sPart.equalsIgnoreAsciiCase("ButtonDown")) + return ControlPart::ButtonDown; + else if (sPart.equalsIgnoreAsciiCase("ButtonLeft")) + return ControlPart::ButtonLeft; + else if (sPart.equalsIgnoreAsciiCase("ButtonRight")) + return ControlPart::ButtonRight; + else if (sPart.equalsIgnoreAsciiCase("AllButtons")) + return ControlPart::AllButtons; + else if (sPart.equalsIgnoreAsciiCase("SeparatorHorz")) + return ControlPart::SeparatorHorz; + else if (sPart.equalsIgnoreAsciiCase("SeparatorVert")) + return ControlPart::SeparatorVert; + else if (sPart.equalsIgnoreAsciiCase("TrackHorzLeft")) + return ControlPart::TrackHorzLeft; + else if (sPart.equalsIgnoreAsciiCase("TrackVertUpper")) + return ControlPart::TrackVertUpper; + else if (sPart.equalsIgnoreAsciiCase("TrackHorzRight")) + return ControlPart::TrackHorzRight; + else if (sPart.equalsIgnoreAsciiCase("TrackVertLower")) + return ControlPart::TrackVertLower; + else if (sPart.equalsIgnoreAsciiCase("TrackHorzArea")) + return ControlPart::TrackHorzArea; + else if (sPart.equalsIgnoreAsciiCase("TrackVertArea")) + return ControlPart::TrackVertArea; + else if (sPart.equalsIgnoreAsciiCase("Arrow")) + return ControlPart::Arrow; + else if (sPart.equalsIgnoreAsciiCase("ThumbHorz")) + return ControlPart::ThumbHorz; + else if (sPart.equalsIgnoreAsciiCase("ThumbVert")) + return ControlPart::ThumbVert; + else if (sPart.equalsIgnoreAsciiCase("MenuItem")) + return ControlPart::MenuItem; + else if (sPart.equalsIgnoreAsciiCase("MenuItemCheckMark")) + return ControlPart::MenuItemCheckMark; + else if (sPart.equalsIgnoreAsciiCase("MenuItemRadioMark")) + return ControlPart::MenuItemRadioMark; + else if (sPart.equalsIgnoreAsciiCase("Separator")) + return ControlPart::Separator; + else if (sPart.equalsIgnoreAsciiCase("SubmenuArrow")) + return ControlPart::SubmenuArrow; + else if (sPart.equalsIgnoreAsciiCase("SubEdit")) + return ControlPart::SubEdit; + else if (sPart.equalsIgnoreAsciiCase("DrawBackgroundHorz")) + return ControlPart::DrawBackgroundHorz; + else if (sPart.equalsIgnoreAsciiCase("DrawBackgroundVert")) + return ControlPart::DrawBackgroundVert; + else if (sPart.equalsIgnoreAsciiCase("TabsDrawRtl")) + return ControlPart::TabsDrawRtl; + else if (sPart.equalsIgnoreAsciiCase("HasBackgroundTexture")) + return ControlPart::HasBackgroundTexture; + else if (sPart.equalsIgnoreAsciiCase("HasThreeButtons")) + return ControlPart::HasThreeButtons; + else if (sPart.equalsIgnoreAsciiCase("BackgroundWindow")) + return ControlPart::BackgroundWindow; + else if (sPart.equalsIgnoreAsciiCase("BackgroundDialog")) + return ControlPart::BackgroundDialog; + else if (sPart.equalsIgnoreAsciiCase("Border")) + return ControlPart::Border; + else if (sPart.equalsIgnoreAsciiCase("Focus")) + return ControlPart::Focus; + return ControlPart::NONE; +} + +bool getControlTypeForXmlString(OString const& rString, ControlType& reType) +{ + bool bReturn = false; + if (rString == "pushbutton") + { + reType = ControlType::Pushbutton; + bReturn = true; + } + else if (rString == "radiobutton") + { + reType = ControlType::Radiobutton; + bReturn = true; + } + else if (rString == "editbox") + { + reType = ControlType::Editbox; + bReturn = true; + } + return bReturn; +} + } // end anonymous namespace WidgetDefinitionReader::WidgetDefinitionReader(OUString const& rFilePath) @@ -144,9 +240,8 @@ void WidgetDefinitionReader::readDrawingDefinition(tools::XmlWalker& rWalker, rWalker.parent(); } -void WidgetDefinitionReader::readDefinition( - tools::XmlWalker& rWalker, - std::unordered_map<OString, std::shared_ptr<WidgetDefinitionPart>>& rPart) +void WidgetDefinitionReader::readDefinition(tools::XmlWalker& rWalker, + WidgetDefinition& rWidgetDefinition, ControlType eType) { rWalker.children(); while (rWalker.isValid()) @@ -154,8 +249,9 @@ void WidgetDefinitionReader::readDefinition( if (rWalker.name() == "part") { OString sPart = rWalker.attribute("value"); + ControlPart ePart = xmlStringToControlPart(sPart); std::shared_ptr<WidgetDefinitionPart> pPart = std::make_shared<WidgetDefinitionPart>(); - rPart.emplace(sPart, pPart); + rWidgetDefinition.maDefinitions.emplace(ControlTypeAndPart(eType, ePart), pPart); readPart(rWalker, pPart); } rWalker.next(); @@ -259,6 +355,7 @@ bool WidgetDefinitionReader::read(WidgetDefinition& rWidgetDefinition) aWalker.children(); while (aWalker.isValid()) { + ControlType eType; if (aWalker.name() == "style") { aWalker.children(); @@ -273,17 +370,9 @@ bool WidgetDefinitionReader::read(WidgetDefinition& rWidgetDefinition) } aWalker.parent(); } - else if (aWalker.name() == "pushbutton") - { - readDefinition(aWalker, rWidgetDefinition.maPushButtonDefinitions); - } - else if (aWalker.name() == "radiobutton") - { - readDefinition(aWalker, rWidgetDefinition.maRadioButtonDefinitions); - } - else if (aWalker.name() == "editbox") + else if (getControlTypeForXmlString(aWalker.name(), eType)) { - readDefinition(aWalker, rWidgetDefinition.maEditboxDefinitions); + readDefinition(aWalker, rWidgetDefinition, eType); } aWalker.next(); } |