sw/inc/ndtxt.hxx                  |    2 +-
 sw/sdi/swriter.sdi                |    2 +-
 sw/source/core/doc/docedt.cxx     |    9 +++++++--
 sw/source/core/txtnode/txtedt.cxx |   14 ++++++++++++--
 sw/source/uibase/uiview/view.cxx  |    3 ++-
 5 files changed, 23 insertions(+), 7 deletions(-)

New commits:
commit 6a7315a6bd53dce057be56b0c7a2358e4232ee8f
Author:     Tibor Nagy <[email protected]>
AuthorDate: Sat Feb 1 16:38:20 2025 +0100
Commit:     Nagy Tibor <[email protected]>
CommitDate: Sun Feb 2 00:05:22 2025 +0100

    tdf#163962 Enable spell checking in editable sections in read-only mode
    
    Change-Id: I1464cb229cc77748a07003e76d0d009c7a95ca66
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181000
    Reviewed-by: Nagy Tibor <[email protected]>
    Tested-by: Jenkins
    (cherry picked from commit 08e40accb3fabe676746c40797efc20eaa218801)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181003
    Tested-by: allotropia jenkins <[email protected]>

diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx
index 436349cc9653..fcb5781a381b 100644
--- a/sw/inc/ndtxt.hxx
+++ b/sw/inc/ndtxt.hxx
@@ -399,7 +399,7 @@ public:
         const sal_Int32 nIndex,
         const bool bIncludeInputFieldAtStart = false ) const;
 
-    bool Spell(SwSpellArgs*);
+    bool Spell(SwSpellArgs* , bool bIsReadOnly);
     bool Convert( SwConversionArgs & );
 
     inline SwTextFormatColl *GetTextColl() const;
diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index e2ed5432b8e3..977484c24e74 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -7349,7 +7349,7 @@ SfxBoolItem SpellingAndGrammarDialog 
FN_SPELL_GRAMMAR_DIALOG
 [
     AutoUpdate = TRUE,
     FastCall = FALSE,
-    ReadOnlyDoc = FALSE,
+    ReadOnlyDoc = TRUE,
     Toggle = FALSE,
     Container = FALSE,
     RecordAbsolute = FALSE,
diff --git a/sw/source/core/doc/docedt.cxx b/sw/source/core/doc/docedt.cxx
index 6587cb0e06a2..29f324758eae 100644
--- a/sw/source/core/doc/docedt.cxx
+++ b/sw/source/core/doc/docedt.cxx
@@ -544,6 +544,11 @@ uno::Any SwDoc::Spell( SwPaM& rPaM,
     sal_uLong nCurrNd = pSttPos->nNode.GetIndex();
     sal_uLong nEndNd = pEndPos->nNode.GetIndex();
 
+    bool bIsReadOnly = false;
+    const SfxObjectShell* pObjShell = GetDocShell();
+    if (pObjShell && pObjShell->IsReadOnly())
+        bIsReadOnly = true;
+
     uno::Any aRet;
     if( nCurrNd <= nEndNd )
     {
@@ -606,8 +611,8 @@ uno::Any SwDoc::Spell( SwPaM& rPaM,
                         }
 
                         sal_Int32 nSpellErrorPosition = 
pNd->GetTextNode()->GetText().getLength();
-                        if( (!pConvArgs && pNd->GetTextNode()->Spell( 
pSpellArgs.get() )) ||
-                            ( pConvArgs && pNd->GetTextNode()->Convert( 
*pConvArgs )))
+                        if ((!pConvArgs && 
pNd->GetTextNode()->Spell(pSpellArgs.get(), bIsReadOnly))
+                            || (pConvArgs && 
pNd->GetTextNode()->Convert(*pConvArgs)))
                         {
                             // Cancel and remember position
                             pSttPos->nNode = nCurrNd;
diff --git a/sw/source/core/txtnode/txtedt.cxx 
b/sw/source/core/txtnode/txtedt.cxx
index 00b6d9ab8d05..f93e04eb628c 100644
--- a/sw/source/core/txtnode/txtedt.cxx
+++ b/sw/source/core/txtnode/txtedt.cxx
@@ -945,7 +945,7 @@ bool SwScanner::NextWord()
 }
 
 // Note: this is a clone of SwTextFrame::AutoSpell_, so keep them in sync when 
fixing things!
-bool SwTextNode::Spell(SwSpellArgs* pArgs)
+bool SwTextNode::Spell(SwSpellArgs* pArgs, bool bIsReadOnly)
 {
     // modify string according to redline information and hidden text
     const OUString aOldText( m_Text );
@@ -967,6 +967,16 @@ bool SwTextNode::Spell(SwSpellArgs* pArgs)
 
     pArgs->xSpellAlt = nullptr;
 
+    bool bIsEditableSect = false;
+    if (bIsReadOnly)
+    {
+        // Enable spell checking in editable sections in read-only mode.
+        if (SwSectionNode* pSectNode = GetTextNode()->FindSectionNode())
+        {
+            bIsEditableSect = pSectNode->GetSection().IsEditInReadonly();
+        }
+    }
+
     // 4 cases:
 
     // 1. IsWrongDirty = 0 and GetWrong = 0
@@ -979,7 +989,7 @@ bool SwTextNode::Spell(SwSpellArgs* pArgs)
     //      Text has been checked but there is an invalid range in the wrong 
list
 
     // Nothing has to be done for case 1.
-    if ( ( IsWrongDirty() || GetWrong() ) && m_Text.getLength() )
+    if ((IsWrongDirty() || GetWrong()) && (!bIsReadOnly || bIsEditableSect) && 
m_Text.getLength())
     {
         if (nBegin > m_Text.getLength())
         {
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index 50e339fb5641..aee84c09aa3b 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -636,7 +636,8 @@ void SwView::CheckReadonlyState()
             SID_ATTR_PARA_ORPHANS,
             SID_ATTR_PARA_MODEL,        SID_PARA_DLG,
             FN_SELECT_PARA,             SID_DEC_INDENT,
-            SID_INC_INDENT
+            SID_INC_INDENT,
+            FN_SPELL_GRAMMAR_DIALOG
         };
         static bool bFirst = true;
         if ( bFirst )

Reply via email to