sfx2/source/doc/objembed.cxx                    |    9 +++++-
 sfx2/source/doc/objmisc.cxx                     |    7 ++++
 sfx2/source/doc/objxtor.cxx                     |    8 ++++-
 starmath/qa/cppunit/test_cursor.cxx             |    1 
 starmath/qa/cppunit/test_node.cxx               |    1 
 starmath/qa/cppunit/test_nodetotextvisitors.cxx |    1 
 starmath/qa/extras/mmlexport-test.cxx           |    3 ++
 sw/qa/extras/uiwriter/uiwriter.cxx              |   34 ++++++++++++------------
 sw/qa/python/check_xmodifiable2.py              |    9 ++----
 9 files changed, 48 insertions(+), 25 deletions(-)

New commits:
commit 67232f226438a9e73beab9dec90f1a3739088b57
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Fri Jun 16 14:51:13 2023 +0200
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
CommitDate: Mon Jun 19 10:51:58 2023 +0200

    tdf#146547 sfx2: allow read-only documents to be modified
    
    This is particularly useful for a Writer document that contains a
    section that is set to be editable in a read-only document, so that the
    user is warned when closing such a document without saving it.
    
    Originally this check was added in commit
    27db57efc51487b3976fbf73df1868b8fb78d201 "CWS fwkbugfix05"
    "#i39869#: readonly docs should never become modified"
    but the actual problem there was that the read-only document was
    displayed in a wizard dialog, not in a document view, so let's instead
    check that the document is some kind of "internal" document.
    
    Also the dialog's Save button should do something, and since the
    document is read-only, a Save As dialog appears appropriate.
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153180
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit aca32a55456aa4e907b216fb490b3c15d26c3d55)
    
    Change-Id: I339cbe92a2c9eb74a1f5061246f921037a47f79c

diff --git a/sfx2/source/doc/objembed.cxx b/sfx2/source/doc/objembed.cxx
index 7d5cdb5cb21c..2d4b6ef5229e 100644
--- a/sfx2/source/doc/objembed.cxx
+++ b/sfx2/source/doc/objembed.cxx
@@ -28,6 +28,7 @@
 #include <sfx2/app.hxx>
 #include <objshimp.hxx>
 #include <sfx2/event.hxx>
+#include <sfx2/sfxbasemodel.hxx>
 
 #include <comphelper/fileformat.h>
 #include <svtools/embedtransfer.hxx>
@@ -118,8 +119,14 @@ void SfxObjectShell::SetVisArea( const tools::Rectangle & 
rVisArea )
         pImpl->m_aVisArea = rVisArea;
         if ( GetCreateMode() == SfxObjectCreateMode::EMBEDDED )
         {
-            if ( IsEnableSetModified() )
+            if (IsEnableSetModified()
+                // Base forms use EMBEDDED but they actually live in their own
+                // frame - resizing that shouldn't set it to modified.
+                && pImpl->pBaseModel
+                && pImpl->pBaseModel->getIdentifier() != 
"com.sun.star.sdb.FormDesign")
+            {
                 SetModified();
+            }
 
             SfxGetpApp()->NotifyEvent(SfxEventHint( 
SfxEventHintId::VisAreaChanged, 
GlobalEventConfig::GetEventName(GlobalEventId::VISAREACHANGED), this));
         }
diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx
index ff31ce956bbc..2b6b361b1231 100644
--- a/sfx2/source/doc/objmisc.cxx
+++ b/sfx2/source/doc/objmisc.cxx
@@ -262,7 +262,12 @@ void SfxObjectShell::EnableSetModified( bool bEnable )
 
 bool SfxObjectShell::IsEnableSetModified() const
 {
-    return pImpl->m_bEnableSetModified && !IsReadOnly();
+    // tdf#146547 read-only does not prevent modified, instead try to prevent
+    // setting "internal" documents that may be displayed in some dialog but
+    // which the user didn't load or activate to modified.
+    return pImpl->m_bEnableSetModified && !IsPreview()
+        && eCreateMode != SfxObjectCreateMode::ORGANIZER
+        && eCreateMode != SfxObjectCreateMode::INTERNAL;
 }
 
 
diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx
index 510c35daf59f..29171a3e4e9a 100644
--- a/sfx2/source/doc/objxtor.cxx
+++ b/sfx2/source/doc/objxtor.cxx
@@ -589,7 +589,13 @@ bool SfxObjectShell::PrepareClose
         {
             // Save by each Dispatcher
             const SfxPoolItem *pPoolItem;
-            if ( IsSaveVersionOnClose() )
+            if (IsReadOnly())
+            {
+                SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI );
+                const SfxPoolItem* ppArgs[] = { &aWarnItem, nullptr };
+                pPoolItem = 
pFrame->GetBindings().ExecuteSynchron(SID_SAVEASDOC, ppArgs);
+            }
+            else if (IsSaveVersionOnClose())
             {
                 SfxStringItem aItem( SID_DOCINFO_COMMENTS, 
SfxResId(STR_AUTOMATICVERSION) );
                 SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI );
diff --git a/starmath/qa/cppunit/test_cursor.cxx 
b/starmath/qa/cppunit/test_cursor.cxx
index 080e7a274c4d..b85b5ceef37a 100644
--- a/starmath/qa/cppunit/test_cursor.cxx
+++ b/starmath/qa/cppunit/test_cursor.cxx
@@ -57,6 +57,7 @@ void Test::setUp()
     SmGlobals::ensure();
 
     xDocShRef = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT);
+    xDocShRef->DoInitNew();
 }
 
 void Test::tearDown()
diff --git a/starmath/qa/cppunit/test_node.cxx 
b/starmath/qa/cppunit/test_node.cxx
index dba0b9ff3c40..570cab00d062 100644
--- a/starmath/qa/cppunit/test_node.cxx
+++ b/starmath/qa/cppunit/test_node.cxx
@@ -53,6 +53,7 @@ void NodeTest::setUp()
     mxDocShell = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT |
                                 SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
                                 SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
+    mxDocShell->DoInitNew();
 }
 
 void NodeTest::tearDown()
diff --git a/starmath/qa/cppunit/test_nodetotextvisitors.cxx 
b/starmath/qa/cppunit/test_nodetotextvisitors.cxx
index c3172ab60126..e738351a8d23 100644
--- a/starmath/qa/cppunit/test_nodetotextvisitors.cxx
+++ b/starmath/qa/cppunit/test_nodetotextvisitors.cxx
@@ -90,6 +90,7 @@ void Test::setUp()
     SmGlobals::ensure();
 
     xDocShRef = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT);
+    xDocShRef->DoInitNew();
 }
 
 void Test::tearDown()
diff --git a/starmath/qa/extras/mmlexport-test.cxx 
b/starmath/qa/extras/mmlexport-test.cxx
index 737885d5f73e..c3a2fc5afca0 100644
--- a/starmath/qa/extras/mmlexport-test.cxx
+++ b/starmath/qa/extras/mmlexport-test.cxx
@@ -91,6 +91,7 @@ xmlDocPtr MathMLExportTest::exportAndParse()
 
 void MathMLExportTest::testBlank()
 {
+    mxDocShell->DoInitNew();
     mxDocShell->SetText("x`y~~z");
     xmlDocPtr pDoc = exportAndParse();
     assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mspace[1]", "width", 
"0.5em");
@@ -99,6 +100,7 @@ void MathMLExportTest::testBlank()
 
 void MathMLExportTest::testTdf97049()
 {
+    mxDocShell->DoInitNew();
     mxDocShell->SetText("intd {{1 over x} dx}");
     xmlDocPtr pDoc = exportAndParse();
     assertXPath(pDoc, "/m:math/m:semantics/m:mrow/m:mo[1]", "stretchy", 
"true");
@@ -111,6 +113,7 @@ void MathMLExportTest::testTdf101022()
 {
 #define CHECK_MATHVARIANT(capital, small) do                            \
     {                                                                   \
+        mxDocShell->DoInitNew();                                        \
         mxDocShell->SetText("%GAMMA %iGAMMA {ital %GAMMA} {nitalic %iGAMMA} " \
                             "%gamma %igamma {ital %gamma} {nitalic %igamma}"); 
\
         xmlDocPtr pDoc = exportAndParse();                              \
diff --git a/sw/qa/python/check_xmodifiable2.py 
b/sw/qa/python/check_xmodifiable2.py
index 53082fc2865e..b860e1f31d0f 100644
--- a/sw/qa/python/check_xmodifiable2.py
+++ b/sw/qa/python/check_xmodifiable2.py
@@ -173,17 +173,16 @@ class XModifiable2(unittest.TestCase):
         xDoc = self._uno.openTemplateFromTDOC('WriteProtected.odt')
 
         # perform unit test:
-        #       it is unable to set modified flag using text editing
-        #       when modification of the flag was disabled as
+        #       it is able to set modified flag using text editing despite
         #       ODT file was marked to be opened as read-only
-        self.assertFalse(xDoc.isSetModifiedEnabled())
+        self.assertTrue(xDoc.isSetModifiedEnabled())
         self.assertFalse(xDoc.isModified())
 
         cursor = xDoc.Text.createTextCursor()
         xDoc.Text.insertString(cursor, "The first paragraph", 0)
 
-        self.assertFalse(xDoc.isSetModifiedEnabled())
-        self.assertFalse(xDoc.isModified())
+        self.assertTrue(xDoc.isSetModifiedEnabled())
+        self.assertTrue(xDoc.isModified())
 
         # clean up
         xDoc.close(True)
commit 71c48fa7be6a526430e81067a1e439207a4a1b39
Author:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
AuthorDate: Mon Jun 19 10:19:04 2023 +0200
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
CommitDate: Mon Jun 19 10:19:04 2023 +0200

    Fix unit test
    
    After 2a682fd1ad43e966d47c863bb1144165662d66f4
    
    Change-Id: I199ce473a038b944e4ce4f15e3126351acca8ad6

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx 
b/sw/qa/extras/uiwriter/uiwriter.cxx
index 120b065482d7..6a08e69a3d06 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -155,6 +155,21 @@ int CountFilesInDirectory(const OUString &rURL)
 
     return nRet;
 }
+
+static void lcl_dispatchCommand(const uno::Reference<lang::XComponent>& 
xComponent, const OUString& rCommand, const 
uno::Sequence<beans::PropertyValue>& rPropertyValues)
+{
+    uno::Reference<frame::XController> xController = 
uno::Reference<frame::XModel>(xComponent, 
uno::UNO_QUERY_THROW)->getCurrentController();
+    CPPUNIT_ASSERT(xController.is());
+    uno::Reference<frame::XDispatchProvider> xFrame(xController->getFrame(), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xFrame.is());
+
+    uno::Reference<uno::XComponentContext> xContext = 
::comphelper::getProcessComponentContext();
+    uno::Reference<frame::XDispatchHelper> 
xDispatchHelper(frame::DispatchHelper::create(xContext));
+    CPPUNIT_ASSERT(xDispatchHelper.is());
+
+    xDispatchHelper->executeDispatch(xFrame, rCommand, OUString(), 0, 
rPropertyValues);
+}
+
 }
 
 class SwUiWriterTest : public SwModelTestBase, public HtmlTestTools
@@ -790,9 +805,8 @@ void SwUiWriterTest::testBookmarkCopy()
 
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testFormulaNumberWithGroupSeparator)
 {
-    createSwDoc("tdf125154.odt");
-    dispatchCommand(mxComponent, ".uno:UpdateAll", {});
-    SwDoc* pDoc = getSwDoc();
+    SwDoc* pDoc = createDoc("tdf125154.odt");
+    lcl_dispatchCommand(mxComponent, ".uno:UpdateAll", {});
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     pWrtShell->SttEndDoc(true);
     SwField const* pField;
@@ -4193,20 +4207,6 @@ void SwUiWriterTest::testShapeAnchorUndo()
     CPPUNIT_ASSERT_EQUAL(pObject->GetLogicRect(), aOrigLogicRect);
 }
 
-static void lcl_dispatchCommand(const uno::Reference<lang::XComponent>& 
xComponent, const OUString& rCommand, const 
uno::Sequence<beans::PropertyValue>& rPropertyValues)
-{
-    uno::Reference<frame::XController> xController = 
uno::Reference<frame::XModel>(xComponent, 
uno::UNO_QUERY_THROW)->getCurrentController();
-    CPPUNIT_ASSERT(xController.is());
-    uno::Reference<frame::XDispatchProvider> xFrame(xController->getFrame(), 
uno::UNO_QUERY);
-    CPPUNIT_ASSERT(xFrame.is());
-
-    uno::Reference<uno::XComponentContext> xContext = 
::comphelper::getProcessComponentContext();
-    uno::Reference<frame::XDispatchHelper> 
xDispatchHelper(frame::DispatchHelper::create(xContext));
-    CPPUNIT_ASSERT(xDispatchHelper.is());
-
-    xDispatchHelper->executeDispatch(xFrame, rCommand, OUString(), 0, 
rPropertyValues);
-}
-
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf149595)
 {
     SwDoc* pDoc = createDoc("demo91.fodt");

Reply via email to