[Libreoffice-commits] core.git: vcl/inc vcl/qa vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Tue Nov 19 07:18:09 UTC 2019


 vcl/inc/widgetdraw/WidgetDefinition.hxx                  |    7 +++
 vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx |   28 +++++++++++++-
 vcl/qa/cppunit/widgetdraw/data/definitionSettings1.xml   |    5 ++
 vcl/qa/cppunit/widgetdraw/data/definitionSettings2.xml   |    6 +++
 vcl/qa/cppunit/widgetdraw/data/definitionSettings3.xml   |    6 +++
 vcl/source/gdi/FileDefinitionWidgetDraw.cxx              |   12 +++++-
 vcl/source/gdi/WidgetDefinition.cxx                      |    2 -
 vcl/source/gdi/WidgetDefinitionReader.cxx                |   30 +++++++++++++++
 8 files changed, 93 insertions(+), 3 deletions(-)

New commits:
commit b234743dd26e0be4be272d2d2c82f90c67e192b7
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon Nov 18 22:50:46 2019 +0100
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Tue Nov 19 08:17:29 2019 +0100

    widget theme: add centeredTabs setting to theme definition file
    
    Change-Id: I714a44d40a99e0bb5ff48e3d36ded73db60af5a0
    Reviewed-on: https://gerrit.libreoffice.org/83133
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/vcl/inc/widgetdraw/WidgetDefinition.hxx b/vcl/inc/widgetdraw/WidgetDefinition.hxx
index 7c0259468328..50a853a6c1a6 100644
--- a/vcl/inc/widgetdraw/WidgetDefinition.hxx
+++ b/vcl/inc/widgetdraw/WidgetDefinition.hxx
@@ -201,6 +201,12 @@ public:
     std::vector<std::shared_ptr<WidgetDefinitionState>> maStates;
 };
 
+class VCL_DLLPUBLIC WidgetDefinitionSettings
+{
+public:
+    OString msCenteredTabs;
+};
+
 class VCL_DLLPUBLIC WidgetDefinitionStyle
 {
 public:
@@ -263,6 +269,7 @@ class VCL_DLLPUBLIC WidgetDefinition
 {
 public:
     std::shared_ptr<WidgetDefinitionStyle> mpStyle;
+    std::shared_ptr<WidgetDefinitionSettings> mpSettings;
     std::unordered_map<ControlTypeAndPart, std::shared_ptr<WidgetDefinitionPart>> maDefinitions;
     std::shared_ptr<WidgetDefinitionPart> getDefinition(ControlType eType, ControlPart ePart);
 };
diff --git a/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx b/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx
index 9cf818932c38..cd7945fba82c 100644
--- a/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx
+++ b/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx
@@ -28,18 +28,44 @@ private:
 
 public:
     void testRead();
+    void testReadSettings();
 
     CPPUNIT_TEST_SUITE(WidgetDefinitionReaderTest);
     CPPUNIT_TEST(testRead);
+    CPPUNIT_TEST(testReadSettings);
     CPPUNIT_TEST_SUITE_END();
 };
 
+void WidgetDefinitionReaderTest::testReadSettings()
+{
+    {
+        vcl::WidgetDefinition aDefinition;
+        vcl::WidgetDefinitionReader aReader(getFullUrl("definitionSettings1.xml"), getFullUrl(""));
+        CPPUNIT_ASSERT(aReader.read(aDefinition));
+        CPPUNIT_ASSERT_EQUAL(OString(""), aDefinition.mpSettings->msCenteredTabs);
+    }
+
+    {
+        vcl::WidgetDefinition aDefinition;
+        vcl::WidgetDefinitionReader aReader(getFullUrl("definitionSettings2.xml"), getFullUrl(""));
+        CPPUNIT_ASSERT(aReader.read(aDefinition));
+        CPPUNIT_ASSERT_EQUAL(OString("true"), aDefinition.mpSettings->msCenteredTabs);
+    }
+
+    {
+        vcl::WidgetDefinition aDefinition;
+        vcl::WidgetDefinitionReader aReader(getFullUrl("definitionSettings3.xml"), getFullUrl(""));
+        CPPUNIT_ASSERT(aReader.read(aDefinition));
+        CPPUNIT_ASSERT_EQUAL(OString("false"), aDefinition.mpSettings->msCenteredTabs);
+    }
+}
+
 void WidgetDefinitionReaderTest::testRead()
 {
     vcl::WidgetDefinition aDefinition;
 
     vcl::WidgetDefinitionReader aReader(getFullUrl("definition1.xml"), getFullUrl(""));
-    aReader.read(aDefinition);
+    CPPUNIT_ASSERT(aReader.read(aDefinition));
 
     CPPUNIT_ASSERT_EQUAL(OUString("123456"), aDefinition.mpStyle->maFaceColor.AsRGBHexString());
     CPPUNIT_ASSERT_EQUAL(OUString("234567"), aDefinition.mpStyle->maCheckedColor.AsRGBHexString());
diff --git a/vcl/qa/cppunit/widgetdraw/data/definitionSettings1.xml b/vcl/qa/cppunit/widgetdraw/data/definitionSettings1.xml
new file mode 100644
index 000000000000..9ca7f894f29d
--- /dev/null
+++ b/vcl/qa/cppunit/widgetdraw/data/definitionSettings1.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<widgets>
+    <settings>
+    </settings>
+</widgets>
diff --git a/vcl/qa/cppunit/widgetdraw/data/definitionSettings2.xml b/vcl/qa/cppunit/widgetdraw/data/definitionSettings2.xml
new file mode 100644
index 000000000000..0d6d6e11151a
--- /dev/null
+++ b/vcl/qa/cppunit/widgetdraw/data/definitionSettings2.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<widgets>
+    <settings>
+        <centeredTabs value="true"/>
+    </settings>
+</widgets>
diff --git a/vcl/qa/cppunit/widgetdraw/data/definitionSettings3.xml b/vcl/qa/cppunit/widgetdraw/data/definitionSettings3.xml
new file mode 100644
index 000000000000..20541b2a219e
--- /dev/null
+++ b/vcl/qa/cppunit/widgetdraw/data/definitionSettings3.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<widgets>
+    <settings>
+        <centeredTabs value="false"/>
+    </settings>
+</widgets>
diff --git a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
index d6f827de3938..580f3783143b 100644
--- a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
+++ b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
@@ -85,6 +85,15 @@ std::shared_ptr<WidgetDefinition> const& getWidgetDefinitionForTheme(OUString co
     return spDefinition;
 }
 
+bool getSettingValueBool(OString const& rValue, bool bDefault)
+{
+    if (rValue.isEmpty())
+        return bDefault;
+    if (rValue == "true" || rValue == "false")
+        return rValue == "true";
+    return bDefault;
+}
+
 } // end anonymous namespace
 
 FileDefinitionWidgetDraw::FileDefinitionWidgetDraw(SalGraphics& rGraphics)
@@ -104,7 +113,8 @@ FileDefinitionWidgetDraw::FileDefinitionWidgetDraw(SalGraphics& rGraphics)
         pSVData->maNWFData.mbNoFocusRects = true;
         pSVData->maNWFData.mbNoFocusRectsForFlatButtons = true;
         pSVData->maNWFData.mbNoActiveTabTextRaise = true;
-        pSVData->maNWFData.mbCenteredTabs = true;
+        pSVData->maNWFData.mbCenteredTabs
+            = getSettingValueBool(m_pWidgetDefinition->mpSettings->msCenteredTabs, true);
         pSVData->maNWFData.mbProgressNeedsErase = true;
         pSVData->maNWFData.mnStatusBarLowerRightOffset = 10;
         pSVData->maNWFData.mbCanDrawWidgetAnySize = true;
diff --git a/vcl/source/gdi/WidgetDefinition.cxx b/vcl/source/gdi/WidgetDefinition.cxx
index cabb0d0817ba..3db9214c45ce 100644
--- a/vcl/source/gdi/WidgetDefinition.cxx
+++ b/vcl/source/gdi/WidgetDefinition.cxx
@@ -64,7 +64,7 @@ WidgetDefinitionPart::getStates(ControlType eType, ControlPart ePart, ControlSta
 
         if (state->msButtonValue != "any"
             && !((state->msButtonValue == "true" && eButtonValue == ButtonValue::On)
-                 || (state->msButtonValue == "false" && eButtonValue != ButtonValue::On)))
+                 || (state->msButtonValue == "false" && eButtonValue == ButtonValue::Off)))
         {
             bAdd = false;
         }
diff --git a/vcl/source/gdi/WidgetDefinitionReader.cxx b/vcl/source/gdi/WidgetDefinitionReader.cxx
index cdd14802f137..b78a269b147b 100644
--- a/vcl/source/gdi/WidgetDefinitionReader.cxx
+++ b/vcl/source/gdi/WidgetDefinitionReader.cxx
@@ -55,6 +55,13 @@ bool readColor(OString const& rString, Color& rColor)
     return true;
 }
 
+bool readSetting(OString const& rInputString, OString& rOutputString)
+{
+    if (!rInputString.isEmpty())
+        rOutputString = rInputString;
+    return true;
+}
+
 OString getValueOrAny(OString const& rInputString)
 {
     if (rInputString.isEmpty())
@@ -412,8 +419,17 @@ bool WidgetDefinitionReader::read(WidgetDefinition& rWidgetDefinition)
         { "toolTextColor", &pStyle->maToolTextColor },
         { "fontColor", &pStyle->maFontColor },
     };
+
     rWidgetDefinition.mpStyle = pStyle;
 
+    auto pSettings = std::make_shared<WidgetDefinitionSettings>();
+
+    std::unordered_map<OString, OString*> aSettingMap = {
+        { "centeredTabs", &pSettings->msCenteredTabs },
+    };
+
+    rWidgetDefinition.mpSettings = pSettings;
+
     SvFileStream aFileStream(m_rDefinitionFile, StreamMode::READ);
 
     tools::XmlWalker aWalker;
@@ -441,6 +457,20 @@ bool WidgetDefinitionReader::read(WidgetDefinition& rWidgetDefinition)
             }
             aWalker.parent();
         }
+        if (aWalker.name() == "settings")
+        {
+            aWalker.children();
+            while (aWalker.isValid())
+            {
+                auto pair = aSettingMap.find(aWalker.name());
+                if (pair != aSettingMap.end())
+                {
+                    readSetting(aWalker.attribute("value"), *pair->second);
+                }
+                aWalker.next();
+            }
+            aWalker.parent();
+        }
         else if (getControlTypeForXmlString(aWalker.name(), eType))
         {
             readDefinition(aWalker, rWidgetDefinition, eType);


More information about the Libreoffice-commits mailing list