sw/inc/swtypes.hxx                         |    2 ++
 sw/qa/extras/globalfilter/globalfilter.cxx |    9 +++------
 sw/qa/extras/ooxmlexport/ooxmlexport9.cxx  |    3 +--
 sw/qa/extras/uiwriter/uiwriter5.cxx        |   14 +++++---------
 sw/source/core/text/itrform2.cxx           |    1 -
 sw/source/filter/ww8/ww8par3.cxx           |    4 +---
 sw/source/uibase/shells/basesh.cxx         |   24 ++++++++++++++++++++++++
 sw/source/uibase/shells/textfld.cxx        |    4 +---
 8 files changed, 37 insertions(+), 24 deletions(-)

New commits:
commit 7a19fa057024d8cf08551dd9005db3c8f7e2c768
Author:     Juergen Funk <juergen.funk...@cib.de>
AuthorDate: Wed Jul 17 05:23:30 2024 +0200
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Tue Jul 30 00:26:43 2024 +0200

    tdf#160163 reset placeholder in Text field when empty
    
      for all the Text field made a global define
      of the NonBreakSpaces mask
    
    Change-Id: I7107f941ee9008415325aefe5487555d91dbf1ab
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170596
    Tested-by: Gabor Kelemen <gabor.kelemen.ext...@allotropia.de>
    Tested-by: Jenkins
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>
    (cherry picked from commit e8a271dd53d605a835c493eef5c34e4fb077f16d)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170954

diff --git a/sw/inc/swtypes.hxx b/sw/inc/swtypes.hxx
index b3cdfa531074..2a528403f2a4 100644
--- a/sw/inc/swtypes.hxx
+++ b/sw/inc/swtypes.hxx
@@ -179,6 +179,8 @@ constexpr bool SW_ISPRINTABLE(sal_Unicode c) { return c >= 
' ' && 127 != c; }
 #define CHAR_WJ             u'\x2060'
 #define CHAR_NNBSP          u'\x202F' //NARROW NO-BREAK SPACE
 
+inline constexpr OUString vEnSpaces = u"\u2002\u2002\u2002\u2002\u2002"_ustr;
+
 // Returns the APP - CharClass instance - used for all ToUpper/ToLower/...
 SW_DLLPUBLIC CharClass& GetAppCharClass();
 SW_DLLPUBLIC LanguageType GetAppLanguage();
diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx 
b/sw/qa/extras/globalfilter/globalfilter.cxx
index 574f00be467d..c6217738f69f 100644
--- a/sw/qa/extras/globalfilter/globalfilter.cxx
+++ b/sw/qa/extras/globalfilter/globalfilter.cxx
@@ -1824,8 +1824,7 @@ void Test::testTextFormField()
         CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
u"TextFieldStart"_ustr, getProperty<OUString>(getRun(xPara, 1), 
u"TextPortionType"_ustr));
         CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
u"TextFieldSeparator"_ustr, getProperty<OUString>(getRun(xPara, 2), 
u"TextPortionType"_ustr));
         CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), u"Text"_ustr, 
getProperty<OUString>(getRun(xPara, 3), u"TextPortionType"_ustr));
-        sal_Unicode vEnSpaces[5] = {8194, 8194, 8194, 8194, 8194};
-        CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
OUString(vEnSpaces, 5), getRun(xPara, 3)->getString());
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), vEnSpaces, 
getRun(xPara, 3)->getString());
         CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
u"TextFieldEnd"_ustr, getProperty<OUString>(getRun(xPara, 4), 
u"TextPortionType"_ustr));
 
         // In the second paragraph we have a set text
@@ -2024,8 +2023,7 @@ void Test::testDateFormField()
 
                     CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
u"MM/DD/YY"_ustr, sDateFormat);
                     CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
u"en-US"_ustr, sLang);
-                    sal_Unicode vEnSpaces[ODF_FORMFIELD_DEFAULT_LENGTH] = 
{8194, 8194, 8194, 8194, 8194};
-                    CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
OUString(vEnSpaces, 5), sCurrentDate);
+                    CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
vEnSpaces, sCurrentDate);
 
                     CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
SwNodeOffset(9), pFieldmark->GetMarkStart().GetNodeIndex());
                     CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
sal_Int32(5), pFieldmark->GetMarkStart().GetContentIndex());
@@ -2117,8 +2115,7 @@ void Test::testDateFormField()
                 {
                     CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
u"MM/DD/YY"_ustr, sDateFormat);
                     CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
u"en-US"_ustr, sLang);
-                    sal_Unicode vEnSpaces[ODF_FORMFIELD_DEFAULT_LENGTH] = 
{8194, 8194, 8194, 8194, 8194};
-                    CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
OUString(vEnSpaces, 5), sCurrentDate);
+                    CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
vEnSpaces, sCurrentDate);
                 }
                 else if (nIndex == 1) // The second has the default format
                 {
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
index 967e9d1aa4ed..e1b7712bfee9 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
@@ -1304,8 +1304,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf111964)
     loadAndSave("tdf111964.docx");
     xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
     // Unicode spaces that are not XML whitespace must not be trimmed
-    static constexpr OUStringLiteral sWSReference = 
u"\u2002\u2002\u2002\u2002\u2002";
-    assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[6]/w:t"_ostr, 
sWSReference);
+    assertXPathContent(pXmlDoc, "/w:document/w:body/w:p/w:r[6]/w:t"_ostr, 
vEnSpaces);
 }
 
 DECLARE_OOXMLEXPORT_TEST(testWatermark, "watermark-shapetype.docx")
diff --git a/sw/qa/extras/uiwriter/uiwriter5.cxx 
b/sw/qa/extras/uiwriter/uiwriter5.cxx
index c29d7e1bf01f..7786227dfe7e 100644
--- a/sw/qa/extras/uiwriter/uiwriter5.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter5.cxx
@@ -767,8 +767,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, 
testTextFormFieldInsertion)
 
     // The text form field has the placeholder text in it
     uno::Reference<text::XTextRange> xPara = getParagraph(1);
-    sal_Unicode vEnSpaces[5] = { 8194, 8194, 8194, 8194, 8194 };
-    CPPUNIT_ASSERT_EQUAL(OUString(vEnSpaces, 5), xPara->getString());
+    CPPUNIT_ASSERT_EQUAL(vEnSpaces, xPara->getString());
 
     // Undo insertion
     dispatchCommand(mxComponent, u".uno:Undo"_ustr, {});
@@ -780,7 +779,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, 
testTextFormFieldInsertion)
     dispatchCommand(mxComponent, u".uno:Redo"_ustr, {});
     CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
     xPara.set(getParagraph(1));
-    CPPUNIT_ASSERT_EQUAL(OUString(vEnSpaces, 5), xPara->getString());
+    CPPUNIT_ASSERT_EQUAL(vEnSpaces, xPara->getString());
 }
 
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testCheckboxFormFieldInsertion)
@@ -1522,8 +1521,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, 
testDateFormFieldInsertion)
 
     // The date form field has the placeholder text in it
     uno::Reference<text::XTextRange> xPara = getParagraph(1);
-    sal_Unicode vEnSpaces[5] = { 8194, 8194, 8194, 8194, 8194 };
-    CPPUNIT_ASSERT_EQUAL(OUString(vEnSpaces, 5), xPara->getString());
+    CPPUNIT_ASSERT_EQUAL(vEnSpaces, xPara->getString());
 
     // Undo insertion
     dispatchCommand(mxComponent, u".uno:Undo"_ustr, {});
@@ -1560,8 +1558,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, 
testDateFormFieldContentOperations)
 
     // Check the default content added by insertion
     uno::Reference<text::XTextRange> xPara = getParagraph(1);
-    sal_Unicode vEnSpaces[5] = { 8194, 8194, 8194, 8194, 8194 };
-    CPPUNIT_ASSERT_EQUAL(OUString(vEnSpaces, 5), pFieldmark->GetContent());
+    CPPUNIT_ASSERT_EQUAL(vEnSpaces, pFieldmark->GetContent());
 
     // Set content to empty string
     pFieldmark->ReplaceContent(u""_ustr);
@@ -1594,8 +1591,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, 
testDateFormFieldCurrentDateHandling)
 
     // The default content is not a valid date
     uno::Reference<text::XTextRange> xPara = getParagraph(1);
-    sal_Unicode vEnSpaces[5] = { 8194, 8194, 8194, 8194, 8194 };
-    CPPUNIT_ASSERT_EQUAL(OUString(vEnSpaces, 5), pFieldmark->GetContent());
+    CPPUNIT_ASSERT_EQUAL(vEnSpaces, pFieldmark->GetContent());
     std::pair<bool, double> aResult = pFieldmark->GetCurrentDate();
     CPPUNIT_ASSERT(!aResult.first);
 
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index b4256d85888f..f9b121210241 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -1207,7 +1207,6 @@ namespace sw::mark {
                 return vListEntries[nCurrentIdx];
         }
 
-        static constexpr OUStringLiteral vEnSpaces = 
u"\u2002\u2002\u2002\u2002\u2002";
         return vEnSpaces;
     }
 }
diff --git a/sw/source/filter/ww8/ww8par3.cxx b/sw/source/filter/ww8/ww8par3.cxx
index 02e67fc4d026..0976737d7230 100644
--- a/sw/source/filter/ww8/ww8par3.cxx
+++ b/sw/source/filter/ww8/ww8par3.cxx
@@ -2456,9 +2456,7 @@ bool WW8FormulaListBox::Import(const uno::Reference <
     }
     else
     {
-        static constexpr OUStringLiteral aBlank =
-            u"\u2002\u2002\u2002\u2002\u2002";
-        rSz = mrRdr.MiserableDropDownFormHack(aBlank, xPropSet);
+        rSz = mrRdr.MiserableDropDownFormHack(vEnSpaces, xPropSet);
     }
 
     return true;
diff --git a/sw/source/uibase/shells/basesh.cxx 
b/sw/source/uibase/shells/basesh.cxx
index 3b7e66f6c465..30a6883bf307 100644
--- a/sw/source/uibase/shells/basesh.cxx
+++ b/sw/source/uibase/shells/basesh.cxx
@@ -290,6 +290,30 @@ void SwBaseShell::ExecDelete(SfxRequest &rReq)
 
     //#i42732# - notify the edit window that from now on we do not use the 
input language
     rTmpEditWin.SetUseInputLanguage( false );
+
+    std::function<void(SwPosition* sp, const IDocumentMarkAccess* 
pMarksAccess)>
+        NoEmptyTextField = [](SwPosition* sp, const IDocumentMarkAccess* 
pMarksAccess)
+    {
+        // Legacy text/combo/checkbox: never return read-only when inside 
these form fields.
+        sw::mark::IFieldmark* pA = pMarksAccess->getInnerFieldmarkFor(*sp);
+        if (pA != nullptr)
+        {
+            bool fm = IDocumentMarkAccess::GetType(*pA) == 
IDocumentMarkAccess::MarkType::TEXT_FIELDMARK;
+            if ((pA->GetContent().getLength() == 0) && fm)
+            {
+                pA->ReplaceContent(vEnSpaces);
+            };
+        }
+    };
+
+    const IDocumentMarkAccess* pMarksAccess = 
rSh.GetDoc()->getIDocumentMarkAccess();
+    for (SwPaM& rPaM : rSh.GetCursor()->GetRingContainer())
+    {
+        auto [pStt, pEnd] = rPaM.StartEnd(); // SwPosition*
+        NoEmptyTextField(pStt, pMarksAccess);
+        NoEmptyTextField(pEnd, pMarksAccess);
+    }
+
 }
 
 void SwBaseShell::ExecClpbrd(SfxRequest &rReq)
diff --git a/sw/source/uibase/shells/textfld.cxx 
b/sw/source/uibase/shells/textfld.cxx
index bd0861ace3f0..b9e12c45a384 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -806,7 +806,6 @@ FIELD_INSERT:
             if(pCursorPos)
             {
                 // Insert five En Space into the text field so the field has 
extent
-                static constexpr OUStringLiteral vEnSpaces = 
u"\u2002\u2002\u2002\u2002\u2002";
                 OUString aFieldResult(vEnSpaces);
                 const SfxStringItem* pFieldResult = 
rReq.GetArg<SfxStringItem>(FN_PARAM_3);
                 if (pFieldResult)
@@ -924,8 +923,7 @@ FIELD_INSERT:
         if(pCursorPos)
         {
             // Insert five enspaces into the text field so the field has extent
-            sal_Unicode vEnSpaces[ODF_FORMFIELD_DEFAULT_LENGTH] = {8194, 8194, 
8194, 8194, 8194};
-            bool bSuccess = 
rSh.GetDoc()->getIDocumentContentOperations().InsertString(*pCursorPos, 
OUString(vEnSpaces, ODF_FORMFIELD_DEFAULT_LENGTH));
+            bool bSuccess = 
rSh.GetDoc()->getIDocumentContentOperations().InsertString(*pCursorPos, 
vEnSpaces);
             if(bSuccess)
             {
                 IDocumentMarkAccess* pMarksAccess = 
rSh.GetDoc()->getIDocumentMarkAccess();

Reply via email to