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

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Mon Jun 7 16:49:50 UTC 2021


 sw/qa/uibase/uiview/data/keep-ratio.fodt |   21 +++++++++++++++++
 sw/qa/uibase/uiview/uiview.cxx           |   38 +++++++++++++++++++++++++++++++
 sw/source/uibase/uiview/view.cxx         |   18 ++++++++++++++
 3 files changed, 77 insertions(+)

New commits:
commit 02c435082058ecf7f9d4d73cb47d31d0218dc10d
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Jun 7 18:03:33 2021 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Jun 7 18:49:07 2021 +0200

    sw keep aspect ratio: add filter for this setting
    
    SwViewOption::IsKeepRatio() was only in-memory, so ticking that checkbox
    and restarting soffice disabled it again.
    
    Handle this similar to e.g. the zoom factor which is mapped to a
    view-specific settings.xml key.
    
    Change-Id: I8d2de7d2c7ae0dbf34230e2011f6b07f63e02fbb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116791
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/uibase/uiview/data/keep-ratio.fodt b/sw/qa/uibase/uiview/data/keep-ratio.fodt
new file mode 100644
index 000000000000..7cfffbec567a
--- /dev/null
+++ b/sw/qa/uibase/uiview/data/keep-ratio.fodt
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" office:mimetype="application/vnd.oasis.opendocument.text">
+  <office:settings>
+    <config:config-item-set config:name="ooo:view-settings">
+      <config:config-item-map-indexed config:name="Views">
+        <config:config-item-map-entry>
+          <config:config-item config:name="VisibleLeft" config:type="long">0</config:config-item>
+          <config:config-item config:name="VisibleTop" config:type="long">0</config:config-item>
+          <config:config-item config:name="VisibleRight" config:type="long">40190</config:config-item>
+          <config:config-item config:name="VisibleBottom" config:type="long">22728</config:config-item>
+          <config:config-item config:name="KeepRatio" config:type="boolean">true</config:config-item>
+        </config:config-item-map-entry>
+      </config:config-item-map-indexed>
+    </config:config-item-set>
+  </office:settings>
+  <office:body>
+    <office:text>
+      <text:p/>
+    </office:text>
+  </office:body>
+</office:document>
diff --git a/sw/qa/uibase/uiview/uiview.cxx b/sw/qa/uibase/uiview/uiview.cxx
index 0c12fd6dd81d..6711aa15b115 100644
--- a/sw/qa/uibase/uiview/uiview.cxx
+++ b/sw/qa/uibase/uiview/uiview.cxx
@@ -12,6 +12,7 @@
 #include <comphelper/processfactory.hxx>
 #include <osl/file.hxx>
 #include <comphelper/propertyvalue.hxx>
+#include <comphelper/scopeguard.hxx>
 
 #include <com/sun/star/frame/XDispatchHelper.hpp>
 #include <com/sun/star/frame/XDispatchProvider.hpp>
@@ -20,6 +21,11 @@
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <com/sun/star/packages/zip/ZipFileAccess.hpp>
 
+#include <unotxdoc.hxx>
+#include <docsh.hxx>
+#include <wrtsh.hxx>
+#include <swmodule.hxx>
+
 constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/uibase/uiview/data/";
 
 /// Covers sw/source/uibase/uiview/ fixes.
@@ -108,6 +114,38 @@ CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testUpdateReplacementNosetting)
     CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Components"));
 }
 
+CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testKeepRatio)
+{
+    // Given a document with a custom KeepRatio:
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "keep-ratio.fodt";
+
+    // When loading that document:
+    mxComponent = loadFromDesktop(aURL);
+
+    // Then make sure we read the custom value:
+    auto pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
+    const SwViewOption* pViewOption = pWrtShell->GetViewOptions();
+    comphelper::ScopeGuard g([pWrtShell, pViewOption] {
+        SwViewOption aViewOption(*pViewOption);
+        aViewOption.SetKeepRatio(false);
+        SW_MOD()->ApplyUsrPref(aViewOption, &pWrtShell->GetView());
+    });
+    // Without the accompanying fix in place, this test would have failed, because KeepRatio was not
+    // mapped to settings.xml
+    CPPUNIT_ASSERT(pViewOption->IsKeepRatio());
+
+    // Then export as well:
+    uno::Reference<frame::XStorable2> xStorable(mxComponent, uno::UNO_QUERY);
+    uno::Sequence<beans::PropertyValue> aStoreArgs = {
+        comphelper::makePropertyValue("FilterName", OUString("writer8")),
+    };
+    xStorable->storeToURL(maTempFile.GetURL(), aStoreArgs);
+    mbExported = true;
+    xmlDocUniquePtr pXmlDoc = parseExport("settings.xml");
+    assertXPathContent(pXmlDoc, "//config:config-item[@config:name='KeepRatio']", "true");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index 5612191cc77a..7880e4fcacd8 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -1316,6 +1316,8 @@ void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >
              bGotZoomFactor = false, bGotIsSelectedFrame = false,
              bGotViewLayoutColumns = false, bGotViewLayoutBookMode = false,
              bBrowseMode = false, bGotBrowseMode = false;
+    bool bKeepRatio = pVOpt->IsKeepRatio();
+    bool bGotKeepRatio = false;
 
     for (const beans::PropertyValue& rValue : rSequence)
     {
@@ -1383,6 +1385,11 @@ void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >
            rValue.Value >>= bBrowseMode;
            bGotBrowseMode = true;
         }
+        else if (rValue.Name == "KeepRatio")
+        {
+            rValue.Value >>= bKeepRatio;
+            bGotKeepRatio = true;
+        }
         // Fallback to common SdrModel processing
         else
            GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->ReadUserDataSequenceValue(&rValue);
@@ -1459,6 +1466,14 @@ void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >
         m_pWrtShell->SetMacroExecAllowed( bSavedFlagValue );
     }
 
+    if (bGotKeepRatio && bKeepRatio != pVOpt->IsKeepRatio())
+    {
+        // Got a custom value, then it makes sense to trigger notifications.
+        SwViewOption aUsrPref(*pVOpt);
+        aUsrPref.SetKeepRatio(bKeepRatio);
+        SW_MOD()->ApplyUsrPref(aUsrPref, this);
+    }
+
     // Set ViewLayoutSettings
     const bool bSetViewLayoutSettings = bGotViewLayoutColumns && bGotViewLayoutBookMode &&
                                         ( pVOpt->GetViewLayoutColumns() != nViewLayoutColumns || pVOpt->IsViewLayoutBookMode() != bViewLayoutBookMode );
@@ -1557,6 +1572,9 @@ void SwView::WriteUserDataSequence ( uno::Sequence < beans::PropertyValue >& rSe
 
     aVector.push_back(comphelper::makePropertyValue("IsSelectedFrame", FrameTypeFlags::NONE != m_pWrtShell->GetSelFrameType()));
 
+    aVector.push_back(
+        comphelper::makePropertyValue("KeepRatio", m_pWrtShell->GetViewOptions()->IsKeepRatio()));
+
     rSequence = comphelper::containerToSequence(aVector);
 
     // Common SdrModel processing


More information about the Libreoffice-commits mailing list