diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2019-01-10 07:26:18 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2019-03-04 12:28:51 +0100 |
commit | 3fc464ae8571f1eb4df3556149914848fd9c8e9d (patch) | |
tree | f76b6ff445a1b6a576d836242ffb25683c26713e | |
parent | b47bca7fd71abb7fb65269f377446a26cd41cb91 (diff) |
Read style colors from a xml widget definition file
WidgetDefinitionReader is responsible to read the definitions from
an xml file. The first implemented definitions are style colors.
They are read from the file and stored into class fields.
This also adds the unit test which tests that the reader is
functioning as expected for a small certain subset of colors.
Change-Id: Icd44cb465b084c32db8323e2f2f7dfa57823d559
Reviewed-on: https://gerrit.libreoffice.org/68642
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | vcl/CppunitTest_vcl_widget_definition_reader_test.mk | 52 | ||||
-rw-r--r-- | vcl/Library_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/Module_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/inc/widgetdraw/WidgetDefinitionReader.hxx | 86 | ||||
-rw-r--r-- | vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx | 61 | ||||
-rw-r--r-- | vcl/qa/cppunit/widgetdraw/data/definition1.xml | 56 | ||||
-rw-r--r-- | vcl/source/gdi/WidgetDefinitionReader.cxx | 159 |
7 files changed, 416 insertions, 0 deletions
diff --git a/vcl/CppunitTest_vcl_widget_definition_reader_test.mk b/vcl/CppunitTest_vcl_widget_definition_reader_test.mk new file mode 100644 index 000000000000..a7d77312cd1c --- /dev/null +++ b/vcl/CppunitTest_vcl_widget_definition_reader_test.mk @@ -0,0 +1,52 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_CppunitTest_CppunitTest,vcl_widget_definition_reader_test)) + +$(eval $(call gb_CppunitTest_add_exception_objects,vcl_widget_definition_reader_test, \ + vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest \ +)) + +$(eval $(call gb_CppunitTest_use_externals,vcl_widget_definition_reader_test,\ + boost_headers \ +)) + +$(eval $(call gb_CppunitTest_set_include,vcl_widget_definition_reader_test,\ + $$(INCLUDE) \ + -I$(SRCDIR)/vcl/inc \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,vcl_widget_definition_reader_test, \ + comphelper \ + cppu \ + cppuhelper \ + sal \ + svt \ + test \ + tl \ + unotest \ + vcl \ + utl \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,vcl_widget_definition_reader_test)) + +$(eval $(call gb_CppunitTest_use_ure,vcl_widget_definition_reader_test)) +$(eval $(call gb_CppunitTest_use_vcl,vcl_widget_definition_reader_test)) + +$(eval $(call gb_CppunitTest_use_components,vcl_widget_definition_reader_test,\ + configmgr/source/configmgr \ + i18npool/util/i18npool \ + ucb/source/core/ucb1 \ + unotools/util/utl \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,vcl_widget_definition_reader_test)) + +# vim: set noet sw=4 ts=4: diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 45b427c389de..ba49a711ee1e 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -260,6 +260,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/gdi/svmconverter \ vcl/source/gdi/dibtools \ vcl/source/gdi/embeddedfontshelper \ + vcl/source/gdi/WidgetDefinitionReader \ vcl/source/gdi/extoutdevdata \ vcl/source/gdi/gdimtf \ vcl/source/gdi/mtfxmldump \ diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk index 14e3eacf1bf5..71db1571c20e 100644 --- a/vcl/Module_vcl.mk +++ b/vcl/Module_vcl.mk @@ -206,6 +206,7 @@ $(eval $(call gb_Module_add_check_targets,vcl,\ CppunitTest_vcl_bitmap_render_test \ CppunitTest_vcl_apitests \ CppunitTest_vcl_png_test \ + CppunitTest_vcl_widget_definition_reader_test \ )) ifneq (,$(filter PDFIUM,$(BUILD_TYPE))) diff --git a/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx b/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx new file mode 100644 index 000000000000..350696a87dae --- /dev/null +++ b/vcl/inc/widgetdraw/WidgetDefinitionReader.hxx @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#ifndef INCLUDED_VCL_INC_WIDGETDEFINITIONREADER_HXX +#define INCLUDED_VCL_INC_WIDGETDEFINITIONREADER_HXX + +#include <vcl/dllapi.h> +#include <memory> +#include <rtl/ustring.hxx> +#include <tools/color.hxx> + +namespace vcl +{ +class VCL_DLLPUBLIC WidgetDefinitionReader +{ +private: + OUString m_rFilePath; + +public: + Color maFaceColor; + Color maCheckedColor; + Color maLightColor; + Color maLightBorderColor; + Color maShadowColor; + Color maDarkShadowColor; + Color maButtonTextColor; + Color maButtonRolloverTextColor; + Color maRadioCheckTextColor; + Color maGroupTextColor; + Color maLabelTextColor; + Color maWindowColor; + Color maWindowTextColor; + Color maDialogColor; + Color maDialogTextColor; + Color maWorkspaceColor; + Color maMonoColor; + Color maFieldColor; + Color maFieldTextColor; + Color maFieldRolloverTextColor; + Color maActiveColor; + Color maActiveTextColor; + Color maActiveBorderColor; + Color maDeactiveColor; + Color maDeactiveTextColor; + Color maDeactiveBorderColor; + Color maMenuColor; + Color maMenuBarColor; + Color maMenuBarRolloverColor; + Color maMenuBorderColor; + Color maMenuTextColor; + Color maMenuBarTextColor; + Color maMenuBarRolloverTextColor; + Color maMenuBarHighlightTextColor; + Color maMenuHighlightColor; + Color maMenuHighlightTextColor; + Color maHighlightColor; + Color maHighlightTextColor; + Color maActiveTabColor; + Color maInactiveTabColor; + Color maTabTextColor; + Color maTabRolloverTextColor; + Color maTabHighlightTextColor; + Color maDisableColor; + Color maHelpColor; + Color maHelpTextColor; + Color maLinkColor; + Color maVisitedLinkColor; + Color maToolTextColor; + Color maFontColor; + + WidgetDefinitionReader(OUString const& rFilePath); + bool read(); +}; + +} // end vcl namespace + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx b/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx new file mode 100644 index 000000000000..e58770706535 --- /dev/null +++ b/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> +#include <unotest/bootstrapfixturebase.hxx> + +#include <widgetdraw/WidgetDefinitionReader.hxx> + +namespace +{ +static OUString const gaDataUrl("/vcl/qa/cppunit/widgetdraw/data/"); + +class WidgetDefinitionReaderTest : public test::BootstrapFixtureBase +{ +private: + OUString getFullUrl(const OUString& sFileName) + { + return m_directories.getURLFromSrc(gaDataUrl) + sFileName; + } + +public: + void testRead(); + + CPPUNIT_TEST_SUITE(WidgetDefinitionReaderTest); + CPPUNIT_TEST(testRead); + CPPUNIT_TEST_SUITE_END(); +}; + +void WidgetDefinitionReaderTest::testRead() +{ + vcl::WidgetDefinitionReader aWidgetDefinitionReader(getFullUrl("definition1.xml")); + + CPPUNIT_ASSERT_EQUAL(OUString("000000"), aWidgetDefinitionReader.maFaceColor.AsRGBHexString()); + CPPUNIT_ASSERT_EQUAL(OUString("000000"), + aWidgetDefinitionReader.maCheckedColor.AsRGBHexString()); + CPPUNIT_ASSERT_EQUAL(OUString("000000"), aWidgetDefinitionReader.maLightColor.AsRGBHexString()); + + aWidgetDefinitionReader.read(); + + CPPUNIT_ASSERT_EQUAL(OUString("f7f7f7"), aWidgetDefinitionReader.maFaceColor.AsRGBHexString()); + CPPUNIT_ASSERT_EQUAL(OUString("c0c0c0"), + aWidgetDefinitionReader.maCheckedColor.AsRGBHexString()); + CPPUNIT_ASSERT_EQUAL(OUString("ffffff"), aWidgetDefinitionReader.maLightColor.AsRGBHexString()); +} + +} // namespace + +CPPUNIT_TEST_SUITE_REGISTRATION(WidgetDefinitionReaderTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qa/cppunit/widgetdraw/data/definition1.xml b/vcl/qa/cppunit/widgetdraw/data/definition1.xml new file mode 100644 index 000000000000..0dd3a94f38b7 --- /dev/null +++ b/vcl/qa/cppunit/widgetdraw/data/definition1.xml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<widgets> + <style> + <faceColor value="#F7F7F7"/> + <checkedColor value="#C0C0C0"/> + <lightColor value="#FFFFFF"/> + <lightBorderColor value="#F7F7F7"/> + <shadowColor value="#808080"/> + <darkShadowColor value="#000000"/> + <buttonTextColor value="#000000"/> + <buttonRolloverTextColor value="#000000"/> + <radioCheckTextColor value="#000000"/> + <groupTextColor value="#000000"/> + <labelTextColor value="#000000"/> + <windowColor value="#FFFFFF"/> + <windowTextColor value="#000000"/> + <dialogColor value="#FFFFFF"/> + <dialogTextColor value="#000000"/> + <workspaceColor value="#F7F7F7"/> + <monoColor value="#000000"/> + <fieldColor value="#FFFFFF"/> + <fieldTextColor value="#000000"/> + <fieldRolloverTextColor value="#000000"/> + <activeColor value="#0B87E7"/> + <activeTextColor value="#FFFFFF"/> + <activeBorderColor value="#C0C0C0"/> + <deactiveColor value="#808080"/> + <deactiveTextColor value="#C0C0C0"/> + <deactiveBorderColor value="#C0C0C0"/> + <menuColor value="#FFFFFF"/> + <menuBarColor value="#FFFFFF"/> + <menuBarRolloverColor value="#0B87E7"/> + <menuBorderColor value="#C0C0C0"/> + <menuTextColor value="#000000"/> + <menuBarTextColor value="#000000"/> + <menuBarRolloverTextColor value="#000000"/> + <menuBarHighlightTextColor value="#000000"/> + <menuHighlightColor value="#0B87E7"/> + <menuHighlightTextColor value="#FFFFFF"/> + <highlightColor value="#0B87E7"/> + <highlightTextColor value="#FFFFFF"/> + <activeTabColor value="#FFFFFF"/> + <inactiveTabColor value="#C0C0C0"/> + <tabTextColor value="#000000"/> + <tabRolloverTextColor value="#000000"/> + <tabHighlightTextColor value="#000000"/> + <disableColor value="#808080"/> + <helpColor value="#FFFFE0"/> + <helpTextColor value="#000000"/> + <linkColor value="#0B87E7"/> + <visitedLinkColor value="#0464AA"/> + <toolTextColor value="#000000"/> + <fontColor value="#000000"/> + </style> +</widgets> diff --git a/vcl/source/gdi/WidgetDefinitionReader.cxx b/vcl/source/gdi/WidgetDefinitionReader.cxx new file mode 100644 index 000000000000..1bb7acb37eeb --- /dev/null +++ b/vcl/source/gdi/WidgetDefinitionReader.cxx @@ -0,0 +1,159 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <widgetdraw/WidgetDefinitionReader.hxx> + +#include <sal/config.h> +#include <osl/file.hxx> +#include <tools/stream.hxx> +#include <tools/XmlWalker.hxx> +#include <unordered_map> + +namespace vcl +{ +namespace +{ +bool lcl_fileExists(OUString const& sFilename) +{ + osl::File aFile(sFilename); + osl::FileBase::RC eRC = aFile.open(osl_File_OpenFlag_Read); + return osl::FileBase::E_None == eRC; +} + +int lcl_gethex(sal_Char aChar) +{ + if (aChar >= '0' && aChar <= '9') + return aChar - '0'; + else if (aChar >= 'a' && aChar <= 'f') + return aChar - 'a' + 10; + else if (aChar >= 'A' && aChar <= 'F') + return aChar - 'A' + 10; + else + return 0; +} + +bool readColor(OString const& rString, Color& rColor) +{ + if (rString.getLength() != 7) + return false; + + const sal_Char aChar(rString[0]); + + if (aChar != '#') + return false; + + rColor.SetRed((lcl_gethex(rString[1]) << 4) | lcl_gethex(rString[2])); + rColor.SetGreen((lcl_gethex(rString[3]) << 4) | lcl_gethex(rString[4])); + rColor.SetBlue((lcl_gethex(rString[5]) << 4) | lcl_gethex(rString[6])); + + return true; +} + +} // end anonymous namespace + +WidgetDefinitionReader::WidgetDefinitionReader(OUString const& rFilePath) + : m_rFilePath(rFilePath) +{ +} + +bool WidgetDefinitionReader::read() +{ + if (!lcl_fileExists(m_rFilePath)) + return false; + + SvFileStream aFileStream(m_rFilePath, StreamMode::READ); + + std::unordered_map<OString, Color*> aStyleColorMap = { + { "faceColor", &maFaceColor }, + { "checkedColor", &maCheckedColor }, + { "lightColor", &maLightColor }, + { "lightBorderColor", &maLightBorderColor }, + { "shadowColor", &maShadowColor }, + { "darkShadowColor", &maDarkShadowColor }, + { "buttonTextColor", &maButtonTextColor }, + { "buttonRolloverTextColor", &maButtonRolloverTextColor }, + { "radioCheckTextColor", &maRadioCheckTextColor }, + { "groupTextColor", &maGroupTextColor }, + { "labelTextColor", &maLabelTextColor }, + { "windowColor", &maWindowColor }, + { "windowTextColor", &maWindowTextColor }, + { "dialogColor", &maDialogColor }, + { "dialogTextColor", &maDialogTextColor }, + { "workspaceColor", &maWorkspaceColor }, + { "monoColor", &maMonoColor }, + { "fieldColor", &maFieldColor }, + { "fieldTextColor", &maFieldTextColor }, + { "fieldRolloverTextColor", &maFieldRolloverTextColor }, + { "activeColor", &maActiveColor }, + { "activeTextColor", &maActiveTextColor }, + { "activeBorderColor", &maActiveBorderColor }, + { "deactiveColor", &maDeactiveColor }, + { "deactiveTextColor", &maDeactiveTextColor }, + { "deactiveBorderColor", &maDeactiveBorderColor }, + { "menuColor", &maMenuColor }, + { "menuBarColor", &maMenuBarColor }, + { "menuBarRolloverColor", &maMenuBarRolloverColor }, + { "menuBorderColor", &maMenuBorderColor }, + { "menuTextColor", &maMenuTextColor }, + { "menuBarTextColor", &maMenuBarTextColor }, + { "menuBarRolloverTextColor", &maMenuBarRolloverTextColor }, + { "menuBarHighlightTextColor", &maMenuBarHighlightTextColor }, + { "menuHighlightColor", &maMenuHighlightColor }, + { "menuHighlightTextColor", &maMenuHighlightTextColor }, + { "highlightColor", &maHighlightColor }, + { "highlightTextColor", &maHighlightTextColor }, + { "activeTabColor", &maActiveTabColor }, + { "inactiveTabColor", &maInactiveTabColor }, + { "tabTextColor", &maTabTextColor }, + { "tabRolloverTextColor", &maTabRolloverTextColor }, + { "tabHighlightTextColor", &maTabHighlightTextColor }, + { "disableColor", &maDisableColor }, + { "helpColor", &maHelpColor }, + { "helpTextColor", &maHelpTextColor }, + { "linkColor", &maLinkColor }, + { "visitedLinkColor", &maVisitedLinkColor }, + { "toolTextColor", &maToolTextColor }, + { "fontColor", &maFontColor }, + }; + + tools::XmlWalker aWalker; + if (!aWalker.open(&aFileStream)) + return false; + + if (aWalker.name() != "widgets") + return false; + + aWalker.children(); + while (aWalker.isValid()) + { + if (aWalker.name() == "style") + { + aWalker.children(); + while (aWalker.isValid()) + { + auto pair = aStyleColorMap.find(aWalker.name()); + if (pair != aStyleColorMap.end()) + { + readColor(aWalker.attribute("value"), *pair->second); + } + aWalker.next(); + } + aWalker.parent(); + } + aWalker.next(); + } + aWalker.parent(); + + return true; +} + +} // end vcl namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |