[Libreoffice-commits] core.git: 2 commits - vcl/CppunitTest_vcl_widget_definition_reader_test.mk vcl/headless vcl/inc vcl/Library_vcl.mk vcl/Module_vcl.mk vcl/qa vcl/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Mon Mar 4 11:29:13 UTC 2019
vcl/CppunitTest_vcl_widget_definition_reader_test.mk | 52 ++++
vcl/Library_vcl.mk | 2
vcl/Module_vcl.mk | 1
vcl/headless/svpgdi.cxx | 8
vcl/inc/FileDefinitionWidgetDraw.hxx | 53 +++++
vcl/inc/widgetdraw/WidgetDefinitionReader.hxx | 86 ++++++++
vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx | 61 +++++
vcl/qa/cppunit/widgetdraw/data/definition1.xml | 56 +++++
vcl/source/gdi/FileDefinitionWidgetDraw.cxx | 137 ++++++++++++
vcl/source/gdi/WidgetDefinitionReader.cxx | 159 +++++++++++++++
10 files changed, 614 insertions(+), 1 deletion(-)
New commits:
commit ffc0493902542277211d2653bf7bc81186df83fc
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu Jan 10 07:38:59 2019 +0100
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Mon Mar 4 12:29:02 2019 +0100
WidgetDrawInterface impl. to draw widgets from file definitions
This adds FileDefinitionWidgetDraw which extends the
WidgetDrawInterface and is responsible to draw the widgets from
the definition gathered from an external file. The file must be
(currently) in the user folder named definition.xml.
It instantiates the WidgetDefinitionReader to get the definitions
and sets the style colors when updateSettings is called. Later
more definitions will be implemented.
Change-Id: Id02111e8aed4648e5a306b0f5dbc9a02c9b2fcb0
Reviewed-on: https://gerrit.libreoffice.org/68645
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index ba49a711ee1e..c22cc2cdf2eb 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/FileDefinitionWidgetDraw \
vcl/source/gdi/WidgetDefinitionReader \
vcl/source/gdi/extoutdevdata \
vcl/source/gdi/gdimtf \
diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx
index fafa73fa3c56..a2b7e7933c22 100644
--- a/vcl/headless/svpgdi.cxx
+++ b/vcl/headless/svpgdi.cxx
@@ -27,6 +27,8 @@
#include <headless/CustomWidgetDraw.hxx>
#include <saldatabasic.hxx>
+#include <FileDefinitionWidgetDraw.hxx>
+
#include <sal/log.hxx>
#include <tools/helpers.hxx>
#include <o3tl/safeint.hxx>
@@ -599,7 +601,11 @@ SvpSalGraphics::SvpSalGraphics()
, m_ePaintMode(PaintMode::Over)
, m_aTextRenderImpl(*this)
{
- if (comphelper::LibreOfficeKit::isActive())
+ bool bFileDefinitionsWidgetDraw = !!getenv("VCL_DRAW_WIDGETS_FROM_FILE");
+
+ if (bFileDefinitionsWidgetDraw)
+ m_pWidgetDraw.reset(new vcl::FileDefinitionWidgetDraw(*this));
+ else if (comphelper::LibreOfficeKit::isActive())
m_pWidgetDraw.reset(new vcl::CustomWidgetDraw(*this));
}
diff --git a/vcl/inc/FileDefinitionWidgetDraw.hxx b/vcl/inc/FileDefinitionWidgetDraw.hxx
new file mode 100644
index 000000000000..97181c17bbcb
--- /dev/null
+++ b/vcl/inc/FileDefinitionWidgetDraw.hxx
@@ -0,0 +1,53 @@
+/* -*- 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_FILEDEFINITIONWIDGETDRAW_HXX
+#define INCLUDED_VCL_INC_FILEDEFINITIONWIDGETDRAW_HXX
+
+#include <vcl/dllapi.h>
+#include "widgetdraw/WidgetDefinitionReader.hxx"
+#include "salgdi.hxx"
+#include "WidgetDrawInterface.hxx"
+
+namespace vcl
+{
+class FileDefinitionWidgetDraw : public vcl::WidgetDrawInterface
+{
+private:
+ SalGraphics& m_rGraphics;
+ WidgetDefinitionReader m_WidgetDefinitionReader;
+
+public:
+ FileDefinitionWidgetDraw(SalGraphics& rGraphics);
+
+ bool isNativeControlSupported(ControlType eType, ControlPart ePart) override;
+
+ bool hitTestNativeControl(ControlType eType, ControlPart ePart,
+ const tools::Rectangle& rBoundingControlRegion, const Point& aPos,
+ bool& rIsInside) override;
+
+ bool drawNativeControl(ControlType eType, ControlPart ePart,
+ const tools::Rectangle& rBoundingControlRegion, ControlState eState,
+ const ImplControlValue& aValue, const OUString& aCaptions) override;
+
+ bool getNativeControlRegion(ControlType eType, ControlPart ePart,
+ const tools::Rectangle& rBoundingControlRegion, ControlState eState,
+ const ImplControlValue& aValue, const OUString& aCaption,
+ tools::Rectangle& rNativeBoundingRegion,
+ tools::Rectangle& rNativeContentRegion) override;
+
+ bool updateSettings(AllSettings& rSettings) override;
+};
+
+} // end vcl namespace
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
new file mode 100644
index 000000000000..9c6dbdaa206a
--- /dev/null
+++ b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
@@ -0,0 +1,137 @@
+/* -*- 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 <FileDefinitionWidgetDraw.hxx>
+
+#include <sal/config.h>
+#include <svdata.hxx>
+#include <rtl/bootstrap.hxx>
+#include <config_folders.h>
+
+namespace vcl
+{
+namespace
+{
+OUString lcl_getClassificationUserPath()
+{
+ OUString sPath("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER
+ "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/user/");
+ rtl::Bootstrap::expandMacros(sPath);
+ return sPath;
+}
+
+} // end anonymous namespace
+
+FileDefinitionWidgetDraw::FileDefinitionWidgetDraw(SalGraphics& rGraphics)
+ : m_rGraphics(rGraphics)
+ , m_WidgetDefinitionReader(lcl_getClassificationUserPath() + "definition.xml")
+{
+ m_WidgetDefinitionReader.read();
+
+ ImplSVData* pSVData = ImplGetSVData();
+ pSVData->maNWFData.mbNoFocusRects = true;
+ pSVData->maNWFData.mbNoFocusRectsForFlatButtons = true;
+}
+
+bool FileDefinitionWidgetDraw::isNativeControlSupported(ControlType /*eType*/,
+ ControlPart /*ePart*/)
+{
+ return false;
+}
+
+bool FileDefinitionWidgetDraw::hitTestNativeControl(
+ ControlType /*eType*/, ControlPart /*ePart*/,
+ const tools::Rectangle& /*rBoundingControlRegion*/, const Point& /*aPos*/, bool& /*rIsInside*/)
+{
+ return false;
+}
+
+bool FileDefinitionWidgetDraw::drawNativeControl(ControlType /*eType*/, ControlPart /*ePart*/,
+ const tools::Rectangle& /*rControlRegion*/,
+ ControlState /*eState*/,
+ const ImplControlValue& /*rValue*/,
+ const OUString& /*aCaptions*/)
+{
+ (void)m_rGraphics; // avoid unused warning
+ return false;
+}
+
+bool FileDefinitionWidgetDraw::getNativeControlRegion(
+ ControlType /*eType*/, ControlPart /*ePart*/,
+ const tools::Rectangle& /*rBoundingControlRegion*/, ControlState /*eState*/,
+ const ImplControlValue& /*aValue*/, const OUString& /*aCaption*/,
+ tools::Rectangle& /*rNativeBoundingRegion*/, tools::Rectangle& /*rNativeContentRegion*/)
+{
+ return false;
+}
+
+bool FileDefinitionWidgetDraw::updateSettings(AllSettings& rSettings)
+{
+ StyleSettings aStyleSet = rSettings.GetStyleSettings();
+
+ aStyleSet.SetFaceColor(m_WidgetDefinitionReader.maFaceColor);
+ aStyleSet.SetCheckedColor(m_WidgetDefinitionReader.maCheckedColor);
+ aStyleSet.SetLightColor(m_WidgetDefinitionReader.maLightColor);
+ aStyleSet.SetLightBorderColor(m_WidgetDefinitionReader.maLightBorderColor);
+ aStyleSet.SetShadowColor(m_WidgetDefinitionReader.maShadowColor);
+ aStyleSet.SetDarkShadowColor(m_WidgetDefinitionReader.maDarkShadowColor);
+ aStyleSet.SetButtonTextColor(m_WidgetDefinitionReader.maButtonTextColor);
+ aStyleSet.SetButtonRolloverTextColor(m_WidgetDefinitionReader.maButtonRolloverTextColor);
+ aStyleSet.SetRadioCheckTextColor(m_WidgetDefinitionReader.maRadioCheckTextColor);
+ aStyleSet.SetGroupTextColor(m_WidgetDefinitionReader.maGroupTextColor);
+ aStyleSet.SetLabelTextColor(m_WidgetDefinitionReader.maLabelTextColor);
+ aStyleSet.SetWindowColor(m_WidgetDefinitionReader.maWindowColor);
+ aStyleSet.SetWindowTextColor(m_WidgetDefinitionReader.maWindowTextColor);
+ aStyleSet.SetDialogColor(m_WidgetDefinitionReader.maDialogColor);
+ aStyleSet.SetDialogTextColor(m_WidgetDefinitionReader.maDialogTextColor);
+ aStyleSet.SetWorkspaceColor(m_WidgetDefinitionReader.maWorkspaceColor);
+ aStyleSet.SetMonoColor(m_WidgetDefinitionReader.maMonoColor);
+ aStyleSet.SetFieldColor(m_WidgetDefinitionReader.maFieldColor);
+ aStyleSet.SetFieldTextColor(m_WidgetDefinitionReader.maFieldTextColor);
+ aStyleSet.SetFieldRolloverTextColor(m_WidgetDefinitionReader.maFieldRolloverTextColor);
+ aStyleSet.SetActiveColor(m_WidgetDefinitionReader.maActiveColor);
+ aStyleSet.SetActiveTextColor(m_WidgetDefinitionReader.maActiveTextColor);
+ aStyleSet.SetActiveBorderColor(m_WidgetDefinitionReader.maActiveBorderColor);
+ aStyleSet.SetDeactiveColor(m_WidgetDefinitionReader.maDeactiveColor);
+ aStyleSet.SetDeactiveTextColor(m_WidgetDefinitionReader.maDeactiveTextColor);
+ aStyleSet.SetDeactiveBorderColor(m_WidgetDefinitionReader.maDeactiveBorderColor);
+ aStyleSet.SetMenuColor(m_WidgetDefinitionReader.maMenuColor);
+ aStyleSet.SetMenuBarColor(m_WidgetDefinitionReader.maMenuBarColor);
+ aStyleSet.SetMenuBarRolloverColor(m_WidgetDefinitionReader.maMenuBarRolloverColor);
+ aStyleSet.SetMenuBorderColor(m_WidgetDefinitionReader.maMenuBorderColor);
+ aStyleSet.SetMenuTextColor(m_WidgetDefinitionReader.maMenuTextColor);
+ aStyleSet.SetMenuBarTextColor(m_WidgetDefinitionReader.maMenuBarTextColor);
+ aStyleSet.SetMenuBarRolloverTextColor(m_WidgetDefinitionReader.maMenuBarRolloverTextColor);
+ aStyleSet.SetMenuBarHighlightTextColor(m_WidgetDefinitionReader.maMenuBarHighlightTextColor);
+ aStyleSet.SetMenuHighlightColor(m_WidgetDefinitionReader.maMenuHighlightColor);
+ aStyleSet.SetMenuHighlightTextColor(m_WidgetDefinitionReader.maMenuHighlightTextColor);
+ aStyleSet.SetHighlightColor(m_WidgetDefinitionReader.maHighlightColor);
+ aStyleSet.SetHighlightTextColor(m_WidgetDefinitionReader.maHighlightTextColor);
+ aStyleSet.SetActiveTabColor(m_WidgetDefinitionReader.maActiveTabColor);
+ aStyleSet.SetInactiveTabColor(m_WidgetDefinitionReader.maInactiveTabColor);
+ aStyleSet.SetTabTextColor(m_WidgetDefinitionReader.maTabTextColor);
+ aStyleSet.SetTabRolloverTextColor(m_WidgetDefinitionReader.maTabRolloverTextColor);
+ aStyleSet.SetTabHighlightTextColor(m_WidgetDefinitionReader.maTabHighlightTextColor);
+ aStyleSet.SetDisableColor(m_WidgetDefinitionReader.maDisableColor);
+ aStyleSet.SetHelpColor(m_WidgetDefinitionReader.maHelpColor);
+ aStyleSet.SetHelpTextColor(m_WidgetDefinitionReader.maHelpTextColor);
+ aStyleSet.SetLinkColor(m_WidgetDefinitionReader.maLinkColor);
+ aStyleSet.SetVisitedLinkColor(m_WidgetDefinitionReader.maVisitedLinkColor);
+ aStyleSet.SetToolTextColor(m_WidgetDefinitionReader.maToolTextColor);
+ aStyleSet.SetFontColor(m_WidgetDefinitionReader.maFontColor);
+
+ rSettings.SetStyleSettings(aStyleSet);
+
+ return true;
+}
+
+} // end vcl namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 3fc464ae8571f1eb4df3556149914848fd9c8e9d
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu Jan 10 07:26:18 2019 +0100
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Mon Mar 4 12:28:51 2019 +0100
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 at gmail.com>
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: */
More information about the Libreoffice-commits
mailing list