[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - vcl/inc vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Tue May 14 08:25:37 UTC 2019


 vcl/inc/FileDefinitionWidgetDraw.hxx        |    4 +
 vcl/source/gdi/FileDefinitionWidgetDraw.cxx |   67 ++++++++++++++++++++--------
 vcl/source/gdi/salgdilayout.cxx             |    6 ++
 3 files changed, 58 insertions(+), 19 deletions(-)

New commits:
commit 078ced35814f4c953ac26fe01f1254a6718a6354
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Tue May 14 16:51:59 2019 +0900
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Tue May 14 10:24:41 2019 +0200

    Gaceful fallback if the widget theme files can't be found
    
    Change-Id: Ied3831c83ed385f5f28b82eb1ee67a2a4448cd05
    Reviewed-on: https://gerrit.libreoffice.org/72270
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/vcl/inc/FileDefinitionWidgetDraw.hxx b/vcl/inc/FileDefinitionWidgetDraw.hxx
index 24b9e0ab8a26..a5b95c8fad6a 100644
--- a/vcl/inc/FileDefinitionWidgetDraw.hxx
+++ b/vcl/inc/FileDefinitionWidgetDraw.hxx
@@ -22,6 +22,8 @@ class FileDefinitionWidgetDraw : public vcl::WidgetDrawInterface
 {
 private:
     SalGraphics& m_rGraphics;
+    bool m_bIsActive;
+
     std::shared_ptr<WidgetDefinition> m_pWidgetDefinition;
 
     bool resolveDefinition(ControlType eType, ControlPart ePart, ControlState eState,
@@ -31,6 +33,8 @@ private:
 public:
     FileDefinitionWidgetDraw(SalGraphics& rGraphics);
 
+    bool isActive() { return m_bIsActive; }
+
     bool isNativeControlSupported(ControlType eType, ControlPart ePart) override;
 
     bool hitTestNativeControl(ControlType eType, ControlPart ePart,
diff --git a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
index 43f8e1487943..7c86d04b084b 100644
--- a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
+++ b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx
@@ -14,6 +14,7 @@
 #include <svdata.hxx>
 #include <rtl/bootstrap.hxx>
 #include <config_folders.h>
+#include <osl/file.hxx>
 
 #include <basegfx/range/b2drectangle.hxx>
 #include <basegfx/polygon/b2dpolygontools.hxx>
@@ -48,15 +49,40 @@ OUString lcl_getThemeDefinitionPath()
     return sPath;
 }
 
-std::shared_ptr<WidgetDefinition> setWidgetDefinition(OUString const& rDefinitionFile,
+bool lcl_directoryExists(OUString const& sDirectory)
+{
+    osl::DirectoryItem aDirectoryItem;
+    osl::FileBase::RC eRes = osl::DirectoryItem::get(sDirectory, aDirectoryItem);
+    return eRes == osl::FileBase::E_None;
+}
+
+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;
+}
+
+std::shared_ptr<WidgetDefinition> getWidgetDefinition(OUString const& rDefinitionFile,
                                                       OUString const& rDefinitionResourcesPath)
 {
+    auto pWidgetDefinition = std::make_shared<WidgetDefinition>();
+    WidgetDefinitionReader aReader(rDefinitionFile, rDefinitionResourcesPath);
+    if (aReader.read(*pWidgetDefinition))
+        return pWidgetDefinition;
+    return std::shared_ptr<WidgetDefinition>();
+}
+
+std::shared_ptr<WidgetDefinition> getWidgetDefinitionForTheme(OUString const& rThemenName)
+{
     static std::shared_ptr<WidgetDefinition> spDefinition;
     if (!spDefinition)
     {
-        spDefinition = std::make_shared<WidgetDefinition>();
-        WidgetDefinitionReader aReader(rDefinitionFile, rDefinitionResourcesPath);
-        aReader.read(*spDefinition);
+        OUString sSharedDefinitionBasePath = lcl_getThemeDefinitionPath();
+        OUString sThemeFolder = sSharedDefinitionBasePath + rThemenName + "/";
+        OUString sThemeDefinitionFile = sThemeFolder + "definition.xml";
+        if (lcl_directoryExists(sThemeFolder) && lcl_fileExists(sThemeDefinitionFile))
+            spDefinition = getWidgetDefinition(sThemeDefinitionFile, sThemeFolder);
     }
     return spDefinition;
 }
@@ -65,22 +91,25 @@ std::shared_ptr<WidgetDefinition> setWidgetDefinition(OUString const& rDefinitio
 
 FileDefinitionWidgetDraw::FileDefinitionWidgetDraw(SalGraphics& rGraphics)
     : m_rGraphics(rGraphics)
+    , m_bIsActive(false)
 {
-    OUString sDefinitionBasePath = lcl_getThemeDefinitionPath();
-    OUString sThemeName = "ios";
-    OUString sThemeFolder = sDefinitionBasePath + sThemeName + "/";
-
-    m_pWidgetDefinition = setWidgetDefinition(sThemeFolder + "definition.xml", sThemeFolder);
-
-    ImplSVData* pSVData = ImplGetSVData();
-    pSVData->maNWFData.mbNoFocusRects = true;
-    pSVData->maNWFData.mbNoFocusRectsForFlatButtons = true;
-    pSVData->maNWFData.mbNoActiveTabTextRaise = true;
-    pSVData->maNWFData.mbCenteredTabs = true;
-    pSVData->maNWFData.mbProgressNeedsErase = true;
-    pSVData->maNWFData.mnStatusBarLowerRightOffset = 10;
-    pSVData->maNWFData.mbCanDrawWidgetAnySize = true;
-    pSVData->maNWFData.mnListBoxEntryMargin = 20;
+    if (!m_pWidgetDefinition)
+        m_pWidgetDefinition = getWidgetDefinitionForTheme("ios");
+
+    if (m_pWidgetDefinition)
+    {
+        ImplSVData* pSVData = ImplGetSVData();
+        pSVData->maNWFData.mbNoFocusRects = true;
+        pSVData->maNWFData.mbNoFocusRectsForFlatButtons = true;
+        pSVData->maNWFData.mbNoActiveTabTextRaise = true;
+        pSVData->maNWFData.mbCenteredTabs = true;
+        pSVData->maNWFData.mbProgressNeedsErase = true;
+        pSVData->maNWFData.mnStatusBarLowerRightOffset = 10;
+        pSVData->maNWFData.mbCanDrawWidgetAnySize = true;
+        pSVData->maNWFData.mnListBoxEntryMargin = 20;
+
+        m_bIsActive = true;
+    }
 }
 
 bool FileDefinitionWidgetDraw::isNativeControlSupported(ControlType eType, ControlPart ePart)
diff --git a/vcl/source/gdi/salgdilayout.cxx b/vcl/source/gdi/salgdilayout.cxx
index 8b87e9872072..558e5164f075 100644
--- a/vcl/source/gdi/salgdilayout.cxx
+++ b/vcl/source/gdi/salgdilayout.cxx
@@ -65,6 +65,12 @@ bool SalGraphics::initWidgetDrawBackends(bool bForce)
     if (bFileDefinitionsWidgetDraw || bForce)
     {
         m_pWidgetDraw.reset(new vcl::FileDefinitionWidgetDraw(*this));
+        auto pFileDefinitionWidgetDraw = static_cast<vcl::FileDefinitionWidgetDraw*>(m_pWidgetDraw.get());
+        if (!pFileDefinitionWidgetDraw->isActive())
+        {
+            m_pWidgetDraw.reset();
+            return false;
+        }
         return true;
     }
     return false;


More information about the Libreoffice-commits mailing list