cui/source/tabpages/macroass.cxx      |   11 ++++++---
 sw/Module_sw.mk                       |    1 
 sw/UITest_sw_uibase_shells.mk         |   16 +++++++++++++
 sw/qa/uitest/data/image-rel-size.fodt |   40 ++++++++++++++++++++++++++++++++++
 sw/qa/uitest/uibase/shells/shells.py  |   32 +++++++++++++++++++++++++++
 sw/source/uibase/shells/grfsh.cxx     |   10 ++++++++
 6 files changed, 107 insertions(+), 3 deletions(-)

New commits:
commit aad0f86a30a57bebe3704c3525db7c4338a9684a
Author:     Miklos Vajna <[email protected]>
AuthorDate: Thu Mar 17 17:36:18 2022 +0100
Commit:     Miklos Vajna <[email protected]>
CommitDate: Wed Mar 23 08:12:15 2022 +0100

    sw image dialog: fix fallback width/height for images with relative sizes
    
    Make sure that we work with the up to date layout size of the image in
    the dialog, otherwise 80% shows up as 237%.
    
    Also fix SfxMacroTabPage::FillItemSet() to not put anything to the
    output item set when the macro table is empty, this way clicking OK in
    the image dialog results in an unmodified document when the user doesn't
    change anything.
    
    (cherry picked from commit 9e8712ed6f9fb5dbd971e352a5709bd45fadc74f)
    
    Change-Id: I4b987bd3e3818ee737e37ea10861f9043c25bc93
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131925
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/cui/source/tabpages/macroass.cxx b/cui/source/tabpages/macroass.cxx
index 94143e310ebd..d752a043077b 100644
--- a/cui/source/tabpages/macroass.cxx
+++ b/cui/source/tabpages/macroass.cxx
@@ -155,9 +155,14 @@ bool SfxMacroTabPage::FillItemSet( SfxItemSet* rSet )
     SvxMacroItem aItem( GetWhich( aPageRg[0] ) );
     const_cast<SvxMacroTableDtor&>(aItem.GetMacroTable()) = aTbl;
 
-    const SfxPoolItem* pItem;
-    if( SfxItemState::SET != GetItemSet().GetItemState( aItem.Which(), true, 
&pItem )
-        || aItem != *static_cast<const SvxMacroItem*>(pItem) )
+    const SfxPoolItem* pItem = nullptr;
+    SfxItemState eState = GetItemSet().GetItemState(aItem.Which(), true, 
&pItem);
+    if (eState == SfxItemState::DEFAULT && aTbl.empty())
+    {
+        // Don't touch the item set if there was no input and our table is 
empty.
+        return false;
+    }
+    if (SfxItemState::SET != eState || aItem != *static_cast<const 
SvxMacroItem*>(pItem))
     {
         rSet->Put( aItem );
         return true;
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index da25613e7ace..05a07c427841 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -195,6 +195,7 @@ $(eval $(call gb_Module_add_uicheck_targets,sw,\
        UITest_sw_styleInspector \
        UITest_sw_ui_fmtui \
        UITest_sw_ui_index \
+       UITest_sw_uibase_shells \
        UITest_classification \
        UITest_writer_macro_tests \
        UITest_writer_dialogs \
diff --git a/sw/UITest_sw_uibase_shells.mk b/sw/UITest_sw_uibase_shells.mk
new file mode 100644
index 000000000000..de9cb7c8a9d9
--- /dev/null
+++ b/sw/UITest_sw_uibase_shells.mk
@@ -0,0 +1,16 @@
+# 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_UITest_UITest,sw_uibase_shells))
+
+$(eval $(call gb_UITest_add_modules,sw_uibase_shells,$(SRCDIR)/sw/qa/uitest,\
+       uibase/shells/ \
+))
+
+$(eval $(call gb_UITest_set_defs,sw_uibase_shells, \
+    TDOC="$(SRCDIR)/sw/qa/uitest/data" \
+))
diff --git a/sw/qa/uitest/data/image-rel-size.fodt 
b/sw/qa/uitest/data/image-rel-size.fodt
new file mode 100644
index 000000000000..9df285861616
--- /dev/null
+++ b/sw/qa/uitest/data/image-rel-size.fodt
@@ -0,0 +1,40 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<office:document 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+  <office:automatic-styles>
+    <style:style style:name="fr1" style:family="graphic" 
style:parent-style-name="Graphics">
+      <style:graphic-properties style:vertical-pos="top" 
style:vertical-rel="baseline"/>
+    </style:style>
+    <style:page-layout style:name="pm1">
+      <style:page-layout-properties fo:page-width="21.001cm" 
fo:page-height="29.7cm" fo:margin-top="2cm" fo:margin-bottom="2cm" 
fo:margin-left="2cm" fo:margin-right="2cm">
+      </style:page-layout-properties>
+      <style:header-style/>
+      <style:footer-style/>
+    </style:page-layout>
+    <style:style style:name="dp1" style:family="drawing-page">
+      <style:drawing-page-properties draw:background-size="full"/>
+    </style:style>
+  </office:automatic-styles>
+  <office:master-styles>
+    <style:master-page style:name="Standard" style:page-layout-name="pm1" 
draw:style-name="dp1"/>
+  </office:master-styles>
+  <office:body>
+    <office:text>
+      <text:p text:style-name="Standard"><draw:frame draw:style-name="fr1" 
draw:name="Bild1" text:anchor-type="as-char" svg:width="40.282cm" 
style:rel-width="80%" svg:height="15.88cm" style:rel-height="scale" 
draw:z-index="0"><draw:image 
draw:mime-type="image/png"><office:binary-data>iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAQAAAAAYLlVAAAABGdBTUEAALGPC/xhBQAAAAFz
+       UkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAA
+       AAJiS0dEAACqjSMyAAAACW9GRnMAAAAGAAAAAAAMc1XTAAAACXBIWXMAAA3XAAAN1wFCKJt4
+       AAAACXZwQWcAAABMAAAAQACdMTgbAAABzUlEQVRo3u3ZPU/CQBjA8X+Jxs3ESUDj4iK+LA5+
+       BBfjqBE1cXB2MlFAEqMgxvhNNL4sLsK3UPQL6ObkoAETz+FKW2mxCPRYnucWUu76/OC59C49
+       cGOCKqrD9kHRc6ddPv7oW2WCwMh0nF63Myz7Tm8hPTNu0pgHMER3scepTbgK6enJNND83RLn
+       /878yRaPmgBZFDuMsNLeWB9gmFQHP77MIg9gsYciR50NFKvtjIy10yk84pSZA7DYpwR8scmF
+       QQCMuoQMpzbh0iAARrlnVn90CWHTsZcAiHPPdINQAuqsc2MQAAnKDUKWEhZ10twaBEDSJWQo
+       YlFj7S9CzwEegkXWIbQsRAQASFJhpplwbRAACS+hANRJBxMiAkDcJeQ4sQkBhYgMoJ+Ozlwo
+       2YQ7AJ6CRxyiUGnVy3hVKb0Af9v7hUG2Wy9TEQCUelFTDULB2S+YKYGOMcpM6UIccOQnRA6A
+       cSp6ibfI+wkGADBGpTEd8xz1AaAfTQ7huA8AvUw5hVjuA0D/C5OaMN8XACRZ8F0zCggKAQhA
+       AAIQgAAEIAABCEAAAhCAAAQgAAH4zg3feY4w3Xs44M5+oW0qvCWoGcvaIlM3x/f/ab+O738A
+       hOCNQr34oD4AAAAldEVYdGNyZWF0ZS1kYXRlADIwMTAtMTItMjBUMTc6MDg6MzYrMDE6MDB6
+       5RscAAAAJXRFWHRtb2RpZnktZGF0ZQAyMDEwLTEyLTIwVDE3OjA4OjM3KzAxOjAwgyNmnAAA
+       AABJRU5ErkJggg==
+      </office:binary-data></draw:image></draw:frame></text:p>
+    </office:text>
+  </office:body>
+</office:document>
diff --git a/sw/qa/uitest/uibase/shells/shells.py 
b/sw/qa/uitest/uibase/shells/shells.py
new file mode 100644
index 000000000000..e422c012a322
--- /dev/null
+++ b/sw/qa/uitest/uibase/shells/shells.py
@@ -0,0 +1,32 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/.
+#
+
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_state_as_dict
+from uitest.uihelper.common import get_url_for_data_file
+import time
+
+
+class TestSwGrfShell(UITestCase):
+    def testFormatGraphicDlg(self):
+        # Given a document with an image with a relative size:
+        with 
self.ui_test.load_file(get_url_for_data_file("image-rel-size.fodt")) as 
component:
+            self.xUITest.executeCommand(".uno:JumpToNextFrame")
+            # 120 ms in the SwView ctor
+            time.sleep(0.2)
+            # When opening the properties dialog for the image:
+            with 
self.ui_test.execute_dialog_through_command(".uno:GraphicDialog") as dialog:
+                # Then make sure the width is 80% as in the file:
+                widthField = dialog.getChild('width')
+                # Without the accompanying fix in place, this test would have 
failed with:
+                # AssertionError: '237%' != '80%'
+                # i.e. the percent width of the image was wrong.
+                self.assertEqual(get_state_as_dict(widthField)["Text"], "80%")
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/uibase/shells/grfsh.cxx 
b/sw/source/uibase/shells/grfsh.cxx
index fa293272d0b9..827dc667439c 100644
--- a/sw/source/uibase/shells/grfsh.cxx
+++ b/sw/source/uibase/shells/grfsh.cxx
@@ -63,6 +63,7 @@
 #include <swslots.hxx>
 #include <swabstdlg.hxx>
 #include <unocrsr.hxx>
+#include <flyfrm.hxx>
 #include <memory>
 
 constexpr OUStringLiteral TOOLBOX_NAME = u"colorbar";
@@ -318,6 +319,15 @@ void SwGrfShell::Execute(SfxRequest &rReq)
             aSet.Put( aFrameSize );
 
             aSet.Put( aMgr.GetAttrSet() );
+            SwFlyFrame* pFly = rSh.GetSelectedFlyFrame();
+            if (pFly)
+            {
+                // Work with the up to date layout size if possible.
+                SwFormatFrameSize aSize = aSet.Get(RES_FRM_SIZE);
+                aSize.SetWidth(pFly->getFrameArea().Width());
+                aSize.SetHeight(pFly->getFrameArea().Height());
+                aSet.Put(aSize);
+            }
             aSet.SetParent( aMgr.GetAttrSet().GetParent() );
 
             // At percentage values initialize size

Reply via email to