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 +
 sw/qa/python/check_xmodifiable2.py              |    9 ++++-----
 vcl/qa/cppunit/filter/ipdf/ipdf.cxx             |    4 ++++
 xmlsecurity/qa/unit/signing/signing.cxx         |    4 ++++
 9 files changed, 36 insertions(+), 8 deletions(-)

New commits:
commit aca32a55456aa4e907b216fb490b3c15d26c3d55
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Fri Jun 16 14:51:13 2023 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Fri Jun 16 16:52:43 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.
    
    Change-Id: I339cbe92a2c9eb74a1f5061246f921037a47f79c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153180
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sfx2/source/doc/objembed.cxx b/sfx2/source/doc/objembed.cxx
index f2e91cef821e..1be515a6e704 100644
--- a/sfx2/source/doc/objembed.cxx
+++ b/sfx2/source/doc/objembed.cxx
@@ -21,6 +21,7 @@
 #include <sfx2/app.hxx>
 #include <objshimp.hxx>
 #include <sfx2/event.hxx>
+#include <sfx2/sfxbasemodel.hxx>
 
 #include <comphelper/fileformat.h>
 #include <tools/fract.hxx>
@@ -84,8 +85,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 6b86e2163ccb..d0f49831db0c 100644
--- a/sfx2/source/doc/objmisc.cxx
+++ b/sfx2/source/doc/objmisc.cxx
@@ -247,7 +247,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 c7f34aeadc31..397a9372089e 100644
--- a/sfx2/source/doc/objxtor.cxx
+++ b/sfx2/source/doc/objxtor.cxx
@@ -565,7 +565,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 56c673c1bd22..5f4c551675a1 100644
--- a/starmath/qa/cppunit/test_cursor.cxx
+++ b/starmath/qa/cppunit/test_cursor.cxx
@@ -58,6 +58,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 f16f195aa8bc..af9ff177f38f 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 6f714321de82..11ef5affcc4c 100644
--- a/starmath/qa/cppunit/test_nodetotextvisitors.cxx
+++ b/starmath/qa/cppunit/test_nodetotextvisitors.cxx
@@ -91,6 +91,7 @@ void Test::setUp()
     SmGlobals::ensure();
 
     xDocShRef = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT);
+    xDocShRef->DoInitNew();
 }
 
 void Test::tearDown()
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)
diff --git a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx 
b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
index f33bd7a27244..7097c89970d3 100644
--- a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
+++ b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx
@@ -110,6 +110,10 @@ CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, 
testPDFAddVisibleSignatureLastPage)
     SdrView* pView = SfxViewShell::Current()->GetDrawView();
     svx::SignatureLineHelper::setShapeCertificate(pView, xCert);
 
+    // the document is modified now, but Sign function can't show SaveAs dialog
+    // in unit test, so just clear the modified
+    pObjectShell->SetModified(false);
+
     // When: do the actual signing.
     pObjectShell->SignDocumentContentUsingCertificate(xCert);
 
diff --git a/xmlsecurity/qa/unit/signing/signing.cxx 
b/xmlsecurity/qa/unit/signing/signing.cxx
index d59a0e84a666..bb7e050a3886 100644
--- a/xmlsecurity/qa/unit/signing/signing.cxx
+++ b/xmlsecurity/qa/unit/signing/signing.cxx
@@ -756,6 +756,10 @@ CPPUNIT_TEST_FIXTURE(SigningTest, 
testPDFAddVisibleSignature)
     SdrView* pView = SfxViewShell::Current()->GetDrawView();
     svx::SignatureLineHelper::setShapeCertificate(pView, aCertificates[0]);
 
+    // the document is modified now, but Sign function can't show SaveAs dialog
+    // in unit test, so just clear the modified
+    pObjectShell->SetModified(false);
+
     // When: do the actual signing.
     pObjectShell->SignDocumentContentUsingCertificate(aCertificates[0]);
 

Reply via email to