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

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: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst a69ce551
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
#include <tools/color.hxx> #include <tools/color.hxx>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <cstddef>
#include <functional>
#include <boost/functional/hash.hpp>
#include <vcl/salnativewidgets.hxx> #include <vcl/salnativewidgets.hxx>
namespace vcl namespace vcl
...@@ -83,6 +86,42 @@ public: ...@@ -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 class VCL_DLLPUBLIC WidgetDefinitionState
{ {
public: public:
...@@ -171,13 +210,8 @@ public: ...@@ -171,13 +210,8 @@ public:
Color maToolTextColor; Color maToolTextColor;
Color maFontColor; Color maFontColor;
std::unordered_map<OString, std::shared_ptr<WidgetDefinitionPart>> maPushButtonDefinitions; std::unordered_map<ControlTypeAndPart, std::shared_ptr<WidgetDefinitionPart>> maDefinitions;
std::unordered_map<OString, std::shared_ptr<WidgetDefinitionPart>> maRadioButtonDefinitions; std::shared_ptr<WidgetDefinitionPart> getDefinition(ControlType eType, ControlPart ePart);
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);
}; };
} // end vcl namespace } // end vcl namespace
......
...@@ -24,9 +24,8 @@ class VCL_DLLPUBLIC WidgetDefinitionReader ...@@ -24,9 +24,8 @@ class VCL_DLLPUBLIC WidgetDefinitionReader
private: private:
OUString m_rFilePath; OUString m_rFilePath;
static void static void readDefinition(tools::XmlWalker& rWalker, WidgetDefinition& rWidgetDefinition,
readDefinition(tools::XmlWalker& rWalker, ControlType eType);
std::unordered_map<OString, std::shared_ptr<WidgetDefinitionPart>>& rDefinition);
static void readPart(tools::XmlWalker& rWalker, std::shared_ptr<WidgetDefinitionPart> rpPart); static void readPart(tools::XmlWalker& rWalker, std::shared_ptr<WidgetDefinitionPart> rpPart);
......
...@@ -54,9 +54,10 @@ void WidgetDefinitionReaderTest::testRead() ...@@ -54,9 +54,10 @@ void WidgetDefinitionReaderTest::testRead()
CPPUNIT_ASSERT_EQUAL(OUString("ffffff"), aDefinition.maToolTextColor.AsRGBHexString()); CPPUNIT_ASSERT_EQUAL(OUString("ffffff"), aDefinition.maToolTextColor.AsRGBHexString());
CPPUNIT_ASSERT_EQUAL(OUString("ffffff"), aDefinition.maFontColor.AsRGBHexString()); CPPUNIT_ASSERT_EQUAL(OUString("ffffff"), aDefinition.maFontColor.AsRGBHexString());
// Pushbutton
{ {
std::vector<std::shared_ptr<vcl::WidgetDefinitionState>> aStates std::vector<std::shared_ptr<vcl::WidgetDefinitionState>> aStates
= aDefinition.getPushButtonDefinition(ControlPart::Entire) = aDefinition.getDefinition(ControlType::Pushbutton, ControlPart::Entire)
->getStates(ControlState::DEFAULT | ControlState::ENABLED ->getStates(ControlState::DEFAULT | ControlState::ENABLED
| ControlState::ROLLOVER, | ControlState::ROLLOVER,
ImplControlValue()); ImplControlValue());
...@@ -69,9 +70,10 @@ void WidgetDefinitionReaderTest::testRead() ...@@ -69,9 +70,10 @@ void WidgetDefinitionReaderTest::testRead()
CPPUNIT_ASSERT_EQUAL(vcl::DrawCommandType::CIRCLE, aStates[0]->mpDrawCommands[1]->maType); CPPUNIT_ASSERT_EQUAL(vcl::DrawCommandType::CIRCLE, aStates[0]->mpDrawCommands[1]->maType);
} }
// Radiobutton
{ {
std::vector<std::shared_ptr<vcl::WidgetDefinitionState>> aStates std::vector<std::shared_ptr<vcl::WidgetDefinitionState>> aStates
= aDefinition.getRadioButtonDefinition(ControlPart::Entire) = aDefinition.getDefinition(ControlType::Radiobutton, ControlPart::Entire)
->getStates(ControlState::NONE, ImplControlValue(ButtonValue::On)); ->getStates(ControlState::NONE, ImplControlValue(ButtonValue::On));
CPPUNIT_ASSERT_EQUAL(size_t(1), aStates.size()); CPPUNIT_ASSERT_EQUAL(size_t(1), aStates.size());
CPPUNIT_ASSERT_EQUAL(size_t(2), aStates[0]->mpDrawCommands.size()); CPPUNIT_ASSERT_EQUAL(size_t(2), aStates[0]->mpDrawCommands.size());
...@@ -79,7 +81,7 @@ void WidgetDefinitionReaderTest::testRead() ...@@ -79,7 +81,7 @@ void WidgetDefinitionReaderTest::testRead()
{ {
std::vector<std::shared_ptr<vcl::WidgetDefinitionState>> aStates std::vector<std::shared_ptr<vcl::WidgetDefinitionState>> aStates
= aDefinition.getRadioButtonDefinition(ControlPart::Entire) = aDefinition.getDefinition(ControlType::Radiobutton, ControlPart::Entire)
->getStates(ControlState::NONE, ImplControlValue(ButtonValue::Off)); ->getStates(ControlState::NONE, ImplControlValue(ButtonValue::Off));
CPPUNIT_ASSERT_EQUAL(size_t(1), aStates.size()); CPPUNIT_ASSERT_EQUAL(size_t(1), aStates.size());
CPPUNIT_ASSERT_EQUAL(size_t(1), aStates[0]->mpDrawCommands.size()); CPPUNIT_ASSERT_EQUAL(size_t(1), aStates[0]->mpDrawCommands.size());
......
...@@ -197,7 +197,7 @@ bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart ...@@ -197,7 +197,7 @@ bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart
case ControlType::Pushbutton: case ControlType::Pushbutton:
{ {
std::shared_ptr<WidgetDefinitionPart> pPart std::shared_ptr<WidgetDefinitionPart> pPart
= m_aWidgetDefinition.getPushButtonDefinition(ePart); = m_aWidgetDefinition.getDefinition(eType, ePart);
if (pPart) if (pPart)
{ {
auto aStates = pPart->getStates(eState, rValue); auto aStates = pPart->getStates(eState, rValue);
...@@ -216,7 +216,7 @@ bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart ...@@ -216,7 +216,7 @@ bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart
case ControlType::Radiobutton: case ControlType::Radiobutton:
{ {
std::shared_ptr<WidgetDefinitionPart> pPart std::shared_ptr<WidgetDefinitionPart> pPart
= m_aWidgetDefinition.getRadioButtonDefinition(ePart); = m_aWidgetDefinition.getDefinition(eType, ePart);
if (pPart) if (pPart)
{ {
std::shared_ptr<WidgetDefinitionState> pState std::shared_ptr<WidgetDefinitionState> pState
...@@ -236,7 +236,7 @@ bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart ...@@ -236,7 +236,7 @@ bool FileDefinitionWidgetDraw::drawNativeControl(ControlType eType, ControlPart
case ControlType::MultilineEditbox: case ControlType::MultilineEditbox:
{ {
std::shared_ptr<WidgetDefinitionPart> pPart std::shared_ptr<WidgetDefinitionPart> pPart
= m_aWidgetDefinition.getEditboxDefinition(ePart); = m_aWidgetDefinition.getDefinition(eType, ePart);
if (pPart) if (pPart)
{ {
std::shared_ptr<WidgetDefinitionState> pState std::shared_ptr<WidgetDefinitionState> pState
......
...@@ -16,114 +16,12 @@ ...@@ -16,114 +16,12 @@
namespace vcl namespace vcl
{ {
namespace std::shared_ptr<WidgetDefinitionPart> WidgetDefinition::getDefinition(ControlType eType,
ControlPart ePart)
{ {
OString xmlControlPart(ControlPart ePart) auto aIterator = maDefinitions.find(ControlTypeAndPart(eType, 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));
if (aIterator != maEditboxDefinitions.end()) if (aIterator != maDefinitions.end())
return aIterator->second; return aIterator->second;
return std::shared_ptr<WidgetDefinitionPart>(); return std::shared_ptr<WidgetDefinitionPart>();
} }
......
...@@ -55,6 +55,102 @@ bool readColor(OString const& rString, Color& rColor) ...@@ -55,6 +55,102 @@ bool readColor(OString const& rString, Color& rColor)
return true; 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 } // end anonymous namespace
WidgetDefinitionReader::WidgetDefinitionReader(OUString const& rFilePath) WidgetDefinitionReader::WidgetDefinitionReader(OUString const& rFilePath)
...@@ -144,9 +240,8 @@ void WidgetDefinitionReader::readDrawingDefinition(tools::XmlWalker& rWalker, ...@@ -144,9 +240,8 @@ void WidgetDefinitionReader::readDrawingDefinition(tools::XmlWalker& rWalker,
rWalker.parent(); rWalker.parent();
} }
void WidgetDefinitionReader::readDefinition( void WidgetDefinitionReader::readDefinition(tools::XmlWalker& rWalker,
tools::XmlWalker& rWalker, WidgetDefinition& rWidgetDefinition, ControlType eType)
std::unordered_map<OString, std::shared_ptr<WidgetDefinitionPart>>& rPart)
{ {
rWalker.children(); rWalker.children();
while (rWalker.isValid()) while (rWalker.isValid())
...@@ -154,8 +249,9 @@ void WidgetDefinitionReader::readDefinition( ...@@ -154,8 +249,9 @@ void WidgetDefinitionReader::readDefinition(
if (rWalker.name() == "part") if (rWalker.name() == "part")
{ {
OString sPart = rWalker.attribute("value"); OString sPart = rWalker.attribute("value");
ControlPart ePart = xmlStringToControlPart(sPart);
std::shared_ptr<WidgetDefinitionPart> pPart = std::make_shared<WidgetDefinitionPart>(); std::shared_ptr<WidgetDefinitionPart> pPart = std::make_shared<WidgetDefinitionPart>();
rPart.emplace(sPart, pPart); rWidgetDefinition.maDefinitions.emplace(ControlTypeAndPart(eType, ePart), pPart);
readPart(rWalker, pPart); readPart(rWalker, pPart);
} }
rWalker.next(); rWalker.next();
...@@ -259,6 +355,7 @@ bool WidgetDefinitionReader::read(WidgetDefinition& rWidgetDefinition) ...@@ -259,6 +355,7 @@ bool WidgetDefinitionReader::read(WidgetDefinition& rWidgetDefinition)
aWalker.children(); aWalker.children();
while (aWalker.isValid()) while (aWalker.isValid())
{ {
ControlType eType;
if (aWalker.name() == "style") if (aWalker.name() == "style")
{ {
aWalker.children(); aWalker.children();
...@@ -273,17 +370,9 @@ bool WidgetDefinitionReader::read(WidgetDefinition& rWidgetDefinition) ...@@ -273,17 +370,9 @@ bool WidgetDefinitionReader::read(WidgetDefinition& rWidgetDefinition)
} }
aWalker.parent(); aWalker.parent();
} }
else if (aWalker.name() == "pushbutton") else if (getControlTypeForXmlString(aWalker.name(), eType))
{
readDefinition(aWalker, rWidgetDefinition.maPushButtonDefinitions);
}
else if (aWalker.name() == "radiobutton")
{
readDefinition(aWalker, rWidgetDefinition.maRadioButtonDefinitions);
}
else if (aWalker.name() == "editbox")
{ {
readDefinition(aWalker, rWidgetDefinition.maEditboxDefinitions); readDefinition(aWalker, rWidgetDefinition, eType);
} }
aWalker.next(); aWalker.next();
} }
......
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