[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-06-04 Thread Mike Kaganski (via logerrit)
 sw/qa/extras/layout/data/tdf155611_table_and_nested_section.fodt |   33 
++
 sw/qa/extras/layout/layout2.cxx  |   28 

 sw/source/core/layout/sectfrm.cxx|   16 
 3 files changed, 76 insertions(+), 1 deletion(-)

New commits:
commit 036d1d8bb324df779410b339e86d369f339cc58b
Author: Mike Kaganski 
AuthorDate: Wed May 31 18:07:14 2023 +0300
Commit: Mike Kaganski 
CommitDate: Sun Jun 4 19:11:26 2023 +0200

tdf#155611: SwFrame::FindNext sometimes returns a sub-frame of this frame

This resulted in wrong split of the section frame, when the table frame
was the last in the section, the split needed to happen after that table
(i.e., at the very end of the section), and passing the table frame as
pFrameStartAfter gave its last cell's subtable as pSav (i.e., the frame
to move after the split). The first frame of the last cell (the one prior
to pSav) got lost from the layout, and wasn't destroyed when SwRootFrame
was destroyed, and then it crashed referencing destroyed root frame and
view shell.

Change-Id: I1a539818aa890f65e961f4185ce50916ce7e4e4f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152454
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152465
Reviewed-by: Michael Stahl 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152484
Tested-by: Jenkins CollaboraOffice 

diff --git a/sw/qa/extras/layout/data/tdf155611_table_and_nested_section.fodt 
b/sw/qa/extras/layout/data/tdf155611_table_and_nested_section.fodt
new file mode 100644
index ..28c0701ea2fc
--- /dev/null
+++ b/sw/qa/extras/layout/data/tdf155611_table_and_nested_section.fodt
@@ -0,0 +1,33 @@
+
+
+
+ 
+  
+   
+
+ 
+ 
+  
+   foo
+  
+  
+   bar
+   
+
+
+ 
+  baz
+ 
+
+   
+  
+ 
+
+
+ abc
+
+   
+   
+  
+ 
+
\ No newline at end of file
diff --git a/sw/qa/extras/layout/layout2.cxx b/sw/qa/extras/layout/layout2.cxx
index 59e9d7d9f43c..70ebd9843ceb 100644
--- a/sw/qa/extras/layout/layout2.cxx
+++ b/sw/qa/extras/layout/layout2.cxx
@@ -1815,6 +1815,34 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf154113)
 "Section3. End selection here -->");
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf155611)
+{
+createSwDoc(DATA_DIRECTORY, "tdf155611_table_and_nested_section.fodt");
+Scheduler::ProcessEventsToIdle();
+
+xmlDocUniquePtr pXml = parseLayoutDump();
+CPPUNIT_ASSERT(pXml);
+
+// Check the layout: single page, two section frames (no section frames 
after the one for Inner
+// section), correct table structure and content in the first section 
frame, including nested
+// table in the last cell, and the last section text.
+assertXPath(pXml, "/root/page");
+// Without the fix in place, this would fail with
+// - Expected: 2
+// - Actual  : 3
+assertXPath(pXml, "/root/page/body/section", 2);
+assertXPath(pXml, "/root/page/body/section[1]/tab");
+assertXPath(pXml, "/root/page/body/section[1]/tab/row");
+assertXPath(pXml, "/root/page/body/section[1]/tab/row/cell", 2);
+assertXPath(pXml, 
"/root/page/body/section[1]/tab/row/cell[1]/txt/Text[@Portion='foo']");
+assertXPath(pXml, 
"/root/page/body/section[1]/tab/row/cell[2]/txt/Text[@Portion='bar']");
+assertXPath(pXml,
+
"/root/page/body/section[1]/tab/row/cell[2]/tab/row/cell/txt/Text[@Portion='baz']");
+assertXPath(pXml, 
"/root/page/body/section[2]/txt[1]/Text[@Portion='abc']");
+
+// Also must not crash on close because of a frame that accidentally fell 
off of the layout
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/sectfrm.cxx 
b/sw/source/core/layout/sectfrm.cxx
index 111c31f7d3b6..1163e048e64b 100644
--- a/sw/source/core/layout/sectfrm.cxx
+++ b/sw/source/core/layout/sectfrm.cxx
@@ -519,7 +519,21 @@ void SwSectionFrame::MergeNext( SwSectionFrame* pNxt )
 SwSectionFrame* SwSectionFrame::SplitSect( SwFrame* pFrameStartAfter, SwFrame* 
pFramePutAfter )
 {
 assert(!pFrameStartAfter || IsAnLower(pFrameStartAfter));
-SwFrame* pSav = pFrameStartAfter ? pFrameStartAfter->FindNext() : 
ContainsAny();
+SwFrame* pSav;
+if (pFrameStartAfter)
+{
+pSav = pFrameStartAfter->FindNext();
+// If pFrameStartAfter is a complex object like table, and it has no 
next,
+// its FindNext may return its own last subframe. In this case, assume 
that
+// we are at the end.
+if (pSav && pFrameStartAfter->IsLayoutFrame())
+if (static_cast(pFrameStartAfter)->IsAnLower(pSav))
+pSav = nullptr;
+}
+else
+{
+pSav = ContainsAny();
+}
 if (pSav && !IsAnLower(pSav))
 pSav = nullptr; 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-05-26 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/tiledrendering/tiledrendering.cxx |   42 +
 sw/source/core/undo/docundo.cxx|2 -
 2 files changed, 43 insertions(+), 1 deletion(-)

New commits:
commit 5f90963149509364d34fae5ecc759989620ee906
Author: Miklos Vajna 
AuthorDate: Wed May 24 15:40:35 2023 +0200
Commit: Caolán McNamara 
CommitDate: Fri May 26 13:30:16 2023 +0200

sw: fix wrong downcast in UndoManager::IsViewUndoActionIndependent()

In case a user types in one view, an other user types in an other view,
finally the first user deletes, then getting the undo state resulted in
a memory corruption.

This went wrong in commit 2875c65946e59f5dd7968155463bf00bd71d440b (sw,
out of order undo: allow a subset of a non-empty redo list, 2021-11-11),
the intention was to check if we have a redo item and it has the
expected type, but we checked the type of an earlier undo action that
belongs to the view.

Fix the problem by checking the type of the correct undo action, this
was probably a copy error of mine.

Resolves .

(cherry picked from commit f0a9d4d4eea6562e98fd92a2797d16504e1d4db5)

Change-Id: I6cb2a081067695a045d86b4ef427cc5a76c0f9c4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152269
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Caolán McNamara 

diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 3330e419dc8b..cc1dbd4947c2 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -1322,6 +1322,48 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, 
testUndoReorderingRedo)
 SfxViewShell::Current()->setLibreOfficeKitViewCallback(nullptr);
 }
 
+CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testUndoReorderingRedo2)
+{
+// Create two views.
+SwXTextDocument* pXTextDocument = createDoc();
+SwWrtShell* pWrtShell1 = pXTextDocument->GetDocShell()->GetWrtShell();
+int nView1 = SfxLokHelper::getView();
+int nView2 = SfxLokHelper::createView();
+
pXTextDocument->initializeForTiledRendering(uno::Sequence());
+SwWrtShell* pWrtShell2 = pXTextDocument->GetDocShell()->GetWrtShell();
+
+// Type in the first view.
+SfxLokHelper::setView(nView1);
+pWrtShell1->SttEndDoc(/*bStt=*/true);
+pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'f', 0);
+pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'f', 0);
+Scheduler::ProcessEventsToIdle();
+
+// Type to the same paragraph in the second view.
+SfxLokHelper::setView(nView2);
+pWrtShell2->SttEndDoc(/*bStt=*/true);
+pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 's', 0);
+pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 's', 0);
+Scheduler::ProcessEventsToIdle();
+
+// Delete in the first view and undo.
+SfxLokHelper::setView(nView1);
+pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, 
awt::Key::BACKSPACE);
+pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::BACKSPACE);
+Scheduler::ProcessEventsToIdle();
+dispatchCommand(mxComponent, ".uno:Undo", {});
+Scheduler::ProcessEventsToIdle();
+
+// Query the undo state, now that a "delete" is on the redo stack and an 
"insert" belongs to the
+// view on the undo stack, so the types are different.
+SwUndoId nUndoId(SwUndoId::EMPTY);
+// Without the accompanying fix in place, this test would have failed with:
+// runtime error: downcast which does not point to an object of type 
'const SwUndoInsert'
+// note: object is of type 'SwUndoDelete'
+// in an UBSan build.
+pWrtShell1->GetLastUndoInfo(nullptr, , >GetView());
+}
+
 CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testUndoReorderingMulti)
 {
 // Create two views and a document of 2 paragraphs.
diff --git a/sw/source/core/undo/docundo.cxx b/sw/source/core/undo/docundo.cxx
index 07998e9404ef..ccff1b663cf3 100644
--- a/sw/source/core/undo/docundo.cxx
+++ b/sw/source/core/undo/docundo.cxx
@@ -415,7 +415,7 @@ bool UndoManager::IsViewUndoActionIndependent(const SwView* 
pView, sal_uInt16& r
 for (size_t i = 0; i < GetRedoActionCount(); ++i)
 {
 auto pRedoAction = dynamic_cast(GetRedoAction(i));
-if (!pRedoAction || pViewSwAction->GetId() != SwUndoId::TYPING)
+if (!pRedoAction || pRedoAction->GetId() != SwUndoId::TYPING)
 {
 return false;
 }


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-04-27 Thread Mike Kaganski (via logerrit)
 sw/qa/extras/htmlimport/data/tdf155011.html |   31 
 sw/qa/extras/htmlimport/htmlimport.cxx  |6 +
 sw/source/core/layout/sectfrm.cxx   |4 +--
 3 files changed, 39 insertions(+), 2 deletions(-)

New commits:
commit 26d5005f4e7500beed4d6041b9e9ccc74e7dec6a
Author: Mike Kaganski 
AuthorDate: Tue Apr 25 14:08:32 2023 +0300
Commit: Mike Kaganski 
CommitDate: Thu Apr 27 17:47:57 2023 +0200

tdf#155011: Fix assert/check

pFrameStartAfter may be a section frame itself, thus its FindSctFrame
would not return this. Same for pSav.

Change-Id: Ib592965b30eb47f37ba54fe7f39af0b8689b3175
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150981
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 
(cherry picked from commit 9ca317ff313958706c63b132113d3f706813587d)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151015
Tested-by: Jenkins CollaboraOffice 

diff --git a/sw/qa/extras/htmlimport/data/tdf155011.html 
b/sw/qa/extras/htmlimport/data/tdf155011.html
new file mode 100644
index ..b3bc7845b56a
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/tdf155011.html
@@ -0,0 +1,31 @@
+
+ 
+  
+   
+
+ 
+  
+   
+
+ 
+  
+   
+
+ 
+  
+ 
+
+   
+  
+  
+  
+ 
+
+   
+  
+ 
+
+   
+  
+ 
+
\ No newline at end of file
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx 
b/sw/qa/extras/htmlimport/htmlimport.cxx
index e4547d02a008..3ed2ce922c68 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -548,6 +548,12 @@ CPPUNIT_TEST_FIXTURE(HtmlImportTest, testRGBAColor)
 CPPUNIT_ASSERT_EQUAL(nBackColor, getProperty(xRun, 
"CharBackColor"));
 }
 
+CPPUNIT_TEST_FIXTURE(HtmlImportTest, testTdf155011)
+{
+load(mpTestDocumentPath, "tdf155011.html");
+// Must not crash / fail asserts
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/sectfrm.cxx 
b/sw/source/core/layout/sectfrm.cxx
index fded9b2dc36b..111c31f7d3b6 100644
--- a/sw/source/core/layout/sectfrm.cxx
+++ b/sw/source/core/layout/sectfrm.cxx
@@ -518,9 +518,9 @@ void SwSectionFrame::MergeNext( SwSectionFrame* pNxt )
 |*/
 SwSectionFrame* SwSectionFrame::SplitSect( SwFrame* pFrameStartAfter, SwFrame* 
pFramePutAfter )
 {
-assert(!pFrameStartAfter || pFrameStartAfter->FindSctFrame() == this);
+assert(!pFrameStartAfter || IsAnLower(pFrameStartAfter));
 SwFrame* pSav = pFrameStartAfter ? pFrameStartAfter->FindNext() : 
ContainsAny();
-if (pSav && pSav->FindSctFrame() != this)
+if (pSav && !IsAnLower(pSav))
 pSav = nullptr; // we are at the very end
 
 // Put the content aside


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-04-25 Thread Mike Kaganski (via logerrit)
 sw/qa/extras/layout/data/three_sections.fodt |   18 ++
 sw/qa/extras/layout/layout2.cxx  |   42 ++
 sw/source/core/inc/sectfrm.hxx   |2 
 sw/source/core/layout/frmtool.cxx|   63 +++--
 sw/source/core/layout/layhelp.hxx|3 +
 sw/source/core/layout/sectfrm.cxx|   79 ++-
 6 files changed, 128 insertions(+), 79 deletions(-)

New commits:
commit 9c8c9499339fcf4e6f92d5bdebec0c567c815d43
Author: Mike Kaganski 
AuthorDate: Thu Apr 20 11:18:34 2023 +0300
Commit: Mike Kaganski 
CommitDate: Tue Apr 25 11:22:46 2023 +0200

tdf#154113: do not forget to split the outermost section frame

... when the inserted section node is not the first one.

The very first frame, where InsertCnt_ puts content to, may already have
some content after the insertion position. When an inner section ends,
the current section needs a new frame, and the rest of content must go
to that new frame. Previously, the new empty frame was created without
taking the content move into account.

This moves the split into the single place inside InsertCnt_, to avoid
special processing in MakeFrames.

Change-Id: I1335ebbc620af0f2b064141e8267e5bd1af0b195
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150675
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150740
Tested-by: Jenkins CollaboraOffice 

diff --git a/sw/qa/extras/layout/data/three_sections.fodt 
b/sw/qa/extras/layout/data/three_sections.fodt
new file mode 100644
index ..9233fed89085
--- /dev/null
+++ b/sw/qa/extras/layout/data/three_sections.fodt
@@ -0,0 +1,18 @@
+
+
+
+ 
+  
+   Select the text below, copy to clipboard, and paste from clipboard, 
replacing the selection.
+   
+-- Start selection here. Section1
+   
+   
+Section2
+   
+   
+Section3. End selection here --
+   
+  
+ 
+
\ No newline at end of file
diff --git a/sw/qa/extras/layout/layout2.cxx b/sw/qa/extras/layout/layout2.cxx
index 9c656a6808ba..59e9d7d9f43c 100644
--- a/sw/qa/extras/layout/layout2.cxx
+++ b/sw/qa/extras/layout/layout2.cxx
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -1773,6 +1774,47 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, 
testUserFieldTypeLanguage)
 "1,234.56");
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf154113)
+{
+createSwDoc(DATA_DIRECTORY, "three_sections.fodt");
+Scheduler::ProcessEventsToIdle();
+
+dispatchCommand(mxComponent, ".uno:GoToStartOfDoc", {});
+dispatchCommand(mxComponent, ".uno:GoToNextPara", {});
+dispatchCommand(mxComponent, ".uno:EndOfDocumentSel", {}); // to the end 
of current section!
+dispatchCommand(mxComponent, ".uno:EndOfDocumentSel", {}); // to the end 
of the document.
+
+uno::Reference xModel(mxComponent, uno::UNO_QUERY_THROW);
+uno::Reference 
xSelected(xModel->getCurrentSelection(),
+  uno::UNO_QUERY_THROW);
+CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSelected->getCount());
+uno::Reference xRange(xSelected->getByIndex(0), 
uno::UNO_QUERY_THROW);
+CPPUNIT_ASSERT_EQUAL(OUString("<-- Start selection here. Section1" 
SAL_NEWLINE_STRING
+  "Section2" SAL_NEWLINE_STRING "Section3. End 
selection here -->"),
+ xRange->getString());
+
+dispatchCommand(mxComponent, ".uno:Cut", {});
+
+xSelected.set(xModel->getCurrentSelection(), uno::UNO_QUERY_THROW);
+CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xSelected->getCount());
+xRange.set(xSelected->getByIndex(0), uno::UNO_QUERY_THROW);
+CPPUNIT_ASSERT_EQUAL(OUString(), xRange->getString());
+
+dispatchCommand(mxComponent, ".uno:Paste", {});
+
+xmlDocUniquePtr pXml = parseLayoutDump();
+
+// Without the fix in place, this would fail with
+// - Expected: 3
+// - Actual  : 2
+assertXPath(pXml, "/root/page/body/section", 3);
+assertXPath(pXml, "/root/page/body/section[1]/txt/Text", "Portion",
+"<-- Start selection here. Section1");
+assertXPath(pXml, "/root/page/body/section[2]/txt/Text", "Portion", 
"Section2");
+assertXPath(pXml, "/root/page/body/section[3]/txt/Text", "Portion",
+"Section3. End selection here -->");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/inc/sectfrm.hxx b/sw/source/core/inc/sectfrm.hxx
index 09c742f8da79..e08a9b0a7137 100644
--- a/sw/source/core/inc/sectfrm.hxx
+++ b/sw/source/core/inc/sectfrm.hxx
@@ -109,7 +109,7 @@ public:
  * Splits the SectionFrame surrounding the pFrame up in two parts:
  * pFrame and the start of the 2nd part
  */
-bool SplitSect( SwFrame* pFrame, bool bApres );
+SwSectionFrame* SplitSect( SwFrame* pFrameStartAfter, SwFrame* 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-03-31 Thread Justin Luth (via logerrit)
 sw/qa/extras/ooxmlexport/ooxmlexport10.cxx  |6 +
 sw/source/core/doc/DocumentContentOperationsManager.cxx |   18 
 sw/source/core/inc/DocumentContentOperationsManager.hxx |3 +-
 3 files changed, 22 insertions(+), 5 deletions(-)

New commits:
commit f08bd56cff961cb53f0c2b695513781bbc3e91e4
Author: Justin Luth 
AuthorDate: Fri Mar 24 20:45:29 2023 -0400
Commit: Miklos Vajna 
CommitDate: Fri Mar 31 06:02:25 2023 +

sw CopyBookmarks: ensure that Move copies can rename

The problem was that a reference to the bookmark name
was failing - since the move was adding a "Copy 1" at the end.

That rename line is very deceptive because AFAICS it fails every time.
I'm going to look at removing it in a followup commit.

Two other unit tests also found with make sw.check
-tdf149089.docx
-tdf149507.docx
but they also didn't have references to the bookmark to visually notice.

make CppunitTest_sw_ooxmlexport10 CPPUNIT_TEST_NAME=testTdf92157

Change-Id: Idd695ec4a89057b28a68bc051b73f17fd4c3de56
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149574
Tested-by: Jenkins
Reviewed-by: Justin Luth 
Reviewed-by: Miklos Vajna 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149641
Tested-by: Justin Luth 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149766
Tested-by: Jenkins CollaboraOffice 

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
index cfeafa71170b..937beb548e6d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -1177,6 +1177,12 @@ DECLARE_OOXMLEXPORT_TEST(testTdf95775, "tdf95775.docx")
 DECLARE_OOXMLEXPORT_TEST(testTdf92157, "tdf92157.docx")
 {
 // A graphic with dimensions 0,0 should not fail on load
+
+// Additionally, the bookmark names should not change (they got a "1" 
appended when copied)
+uno::Reference xBookmarksSupplier(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xBookmarksByName = 
xBookmarksSupplier->getBookmarks();
+CPPUNIT_ASSERT(xBookmarksByName->hasByName("referentiegegevens"));
+CPPUNIT_ASSERT(xBookmarksByName->hasByName("referentiegegevens_bk"));
 }
 
 DECLARE_OOXMLEXPORT_TEST(testTdf97417, "section_break_numbering.docx")
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx 
b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index c368ada50194..9e383db67190 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -230,7 +230,7 @@ namespace
 namespace sw
 {
 // TODO: use SaveBookmark (from DelBookmarks)
-void CopyBookmarks(const SwPaM& rPam, const SwPosition& rCpyPam)
+void CopyBookmarks(const SwPaM& rPam, const SwPosition& rCpyPam, 
SwCopyFlags flags)
 {
 const SwDoc& rSrcDoc = rPam.GetDoc();
 SwDoc& rDestDoc =  rCpyPam.GetDoc();
@@ -293,9 +293,19 @@ namespace sw
 lcl_SetCpyPos(pMark->GetOtherMarkPos(), rStt, *pCpyStt, 
*aTmpPam.GetMark(), nDelCount);
 }
 
+OUString sRequestedName = pMark->GetName();
+if (flags & SwCopyFlags::IsMoveToFly)
+{
+assert( == );
+// Ensure the name can be given to NewMark, since this is 
ultimately a move
+auto pSoonToBeDeletedMark = 
const_cast(pMark);
+
rDestDoc.getIDocumentMarkAccess()->renameMark(pSoonToBeDeletedMark,
+  sRequestedName + 
"COPY_IS_MOVE");
+}
+
 ::sw::mark::IMark* const pNewMark = 
rDestDoc.getIDocumentMarkAccess()->makeMark(
 aTmpPam,
-pMark->GetName(),
+sRequestedName,
 IDocumentMarkAccess::GetType(*pMark),
 ::sw::mark::InsertMode::CopyText);
 // Explicitly try to get exactly the same name as in the source
@@ -306,7 +316,7 @@ namespace sw
 || IDocumentMarkAccess::GetType(*pMark) == 
IDocumentMarkAccess::MarkType::CROSSREF_HEADING_BOOKMARK);
 continue; // can't insert duplicate cross reference mark
 }
-rDestDoc.getIDocumentMarkAccess()->renameMark(pNewMark, 
pMark->GetName());
+rDestDoc.getIDocumentMarkAccess()->renameMark(pNewMark, 
sRequestedName);
 
 // copying additional attributes for bookmarks or fieldmarks
 ::sw::mark::IBookmark* const pNewBookmark =
@@ -3683,7 +3693,7 @@ void DocumentContentOperationsManager::CopyWithFlyInFly(
 targetPos = pCopiedPaM->second;
 }
 
-sw::CopyBookmarks(pCopiedPaM ? pCopiedPaM->first : aRgTmp, targetPos);
+sw::CopyBookmarks(pCopiedPaM ? pCopiedPaM->first : aRgTmp, targetPos, 
flags);
 }
 
 if (rRg.aStart != rRg.aEnd)
diff --git 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-03-23 Thread Jaume Pujantell (via logerrit)
 sw/qa/core/layout/data/header-textbox.docx   |binary
 sw/qa/core/layout/layout.cxx |   15 +++
 sw/source/core/draw/dcontact.cxx |9 -
 sw/source/core/layout/anchoreddrawobject.cxx |8 
 4 files changed, 31 insertions(+), 1 deletion(-)

New commits:
commit 87c1d93fd2b192f341112a609c741370561879a2
Author: Jaume Pujantell 
AuthorDate: Tue Mar 21 16:03:54 2023 +0100
Commit: Andras Timar 
CommitDate: Thu Mar 23 07:10:06 2023 +

Fix wrong layout of textbox in header

In some cases the text box wasn't properly moved afeter it's position
had been calculated. Also now when the shape and text element are
brought together in the Z ordering, the one with higher Z moves down.

Change-Id: I0512db4b6466532b5af4e3c091fd65bd0a416381
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149221
Tested-by: Jenkins
Reviewed-by: Andras Timar 
(cherry picked from commit 826b20b049449c9c335ce00c781cdb52e4ee0512)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149305
Tested-by: Andras Timar 

diff --git a/sw/qa/core/layout/data/header-textbox.docx 
b/sw/qa/core/layout/data/header-textbox.docx
new file mode 100644
index ..4df72cccd3e7
Binary files /dev/null and b/sw/qa/core/layout/data/header-textbox.docx differ
diff --git a/sw/qa/core/layout/layout.cxx b/sw/qa/core/layout/layout.cxx
index abd77b3e217d..3bdeabe9b9f7 100644
--- a/sw/qa/core/layout/layout.cxx
+++ b/sw/qa/core/layout/layout.cxx
@@ -238,6 +238,21 @@ CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, 
testTextboxModification)
 CPPUNIT_ASSERT(!pDocShell->IsModified());
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testTextBoxInHeaderIsPositioned)
+{
+// Load a document with a floating text box in the header
+load(DATA_DIRECTORY, "header-textbox.docx");
+xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+CPPUNIT_ASSERT(pXmlDoc);
+
+// Without the fix in place, this test would have failed with
+// - Expected: 8051
+// - Actual  : 1418
+// Comparison with 7000 chosen due to variability between devices
+CPPUNIT_ASSERT_GREATEREQUAL(
+double(7000), getXPath(pXmlDoc, "//anchored/fly/infos/bounds", 
"left").toDouble());
+}
+
 CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testBtlrNestedCell)
 {
 // Load a document with a nested table, the inner A1 cell has a btlr text 
direction.
diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx
index 63011f0171a8..8a6871373ccf 100644
--- a/sw/source/core/draw/dcontact.cxx
+++ b/sw/source/core/draw/dcontact.cxx
@@ -1965,7 +1965,14 @@ void SwDrawContact::ConnectToLayout( const 
SwFormatAnchor* pAnch )
 if (pDrawPage)
 {
 sal_uInt32 nOrdNum = 
pAnchoredObj->GetDrawObj()->GetOrdNum();
-
pDrawPage->SetObjectOrdNum(maAnchoredDrawObj.GetDrawObj()->GetOrdNumDirect(), 
nOrdNum);
+if 
(maAnchoredDrawObj.GetDrawObj()->GetOrdNum() >= nOrdNum)
+{
+
pDrawPage->SetObjectOrdNum(maAnchoredDrawObj.GetDrawObj()->GetOrdNumDirect(), 
nOrdNum);
+}
+else
+{
+
pDrawPage->SetObjectOrdNum(nOrdNum, 
maAnchoredDrawObj.GetDrawObj()->GetOrdNumDirect() + 1);
+}
 break;
 }
 }
diff --git a/sw/source/core/layout/anchoreddrawobject.cxx 
b/sw/source/core/layout/anchoreddrawobject.cxx
index 3e37961dffd6..6cc597ef9a64 100644
--- a/sw/source/core/layout/anchoreddrawobject.cxx
+++ b/sw/source/core/layout/anchoreddrawobject.cxx
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -512,6 +513,13 @@ void SwAnchoredDrawObject::SetDrawObjAnchor()
 DrawObj()->SetAnchorPos( aNewAnchorPos );
 // correct object position, caused by setting new anchor position
 DrawObj()->Move( aMove );
+// Sync textbox if it wasn't done at move
+if ( SwTextBoxHelper::isTextBox((), RES_DRAWFRMFMT) && 
GetFrameFormat().GetDoc() &&
+
GetFrameFormat().GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell() &&
+
GetFrameFormat().GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell()->IsInConstructor())
+{
+SwTextBoxHelper::changeAnchor((), 
GetFrameFormat().FindRealSdrObject());
+}
 // --> #i70122# - missing invalidation
 InvalidateObjRectWithSpaces();
 }


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-03-14 Thread Miklos Vajna (via logerrit)
 sw/qa/core/txtnode/txtnode.cxx|   30 +
 sw/source/core/txtnode/attrcontentcontrol.cxx |   36 ++
 2 files changed, 66 insertions(+)

New commits:
commit 20d7735c21208536f98c641ca6ba8da95606
Author: Miklos Vajna 
AuthorDate: Fri Mar 10 13:36:37 2023 +0100
Commit: Miklos Vajna 
CommitDate: Tue Mar 14 12:53:04 2023 +

sw content control: fix lost properties on copy

E.g. a checkbox content control was turned into a rich text one on
copy, so toggling didn't work on the copied content control.

(cherry picked from commit c804c5354855188b5a37219cfe11dc079dc235f4)

Change-Id: Ia7262e0b88dff12a2f87acd7b0e6cc3fbde3c3a8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148836
Tested-by: Jenkins CollaboraOffice 
Tested-by: Justin Luth 
Reviewed-by: Justin Luth 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/txtnode/txtnode.cxx b/sw/qa/core/txtnode/txtnode.cxx
index bd9bcd66d6fc..5a88a2225846 100644
--- a/sw/qa/core/txtnode/txtnode.cxx
+++ b/sw/qa/core/txtnode/txtnode.cxx
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 
 constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/txtnode/data/";
 
@@ -318,6 +319,35 @@ CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, 
testDateContentControlKeyboard)
 CPPUNIT_ASSERT(bShouldOpen);
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testContentControlCopy)
+{
+// Given a document with a content control:
+SwDoc* pDoc = createSwDoc();
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+pWrtShell->InsertContentControl(SwContentControlType::CHECKBOX);
+
+// When copying that content control:
+pWrtShell->SelAll();
+rtl::Reference xTransfer = new SwTransferable(*pWrtShell);
+xTransfer->Copy();
+// Kill the selection, go to the end of the document:
+pWrtShell->EndOfSection();
+TransferableDataHelper aHelper(xTransfer);
+SwTransferable::Paste(*pWrtShell, aHelper);
+
+// Then make sure that the copy is also a checkbox:
+SwContentControlManager& rManager = pDoc->GetContentControlManager();
+CPPUNIT_ASSERT_EQUAL(static_cast(2), rManager.GetCount());
+const SwFormatContentControl& rFormat1 = 
rManager.Get(0)->GetContentControl();
+CPPUNIT_ASSERT_EQUAL(SwContentControlType::CHECKBOX, 
rFormat1.GetContentControl()->GetType());
+const SwFormatContentControl& rFormat2 = 
rManager.Get(1)->GetContentControl();
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 1 (CHECKBOX)
+// - Actual  : 0 (RICH_TEXT)
+// i.e. properties were not copied from the source to the destination 
content control.
+CPPUNIT_ASSERT_EQUAL(SwContentControlType::CHECKBOX, 
rFormat2.GetContentControl()->GetType());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/txtnode/attrcontentcontrol.cxx 
b/sw/source/core/txtnode/attrcontentcontrol.cxx
index 07e7afceb027..2b96ddda53ed 100644
--- a/sw/source/core/txtnode/attrcontentcontrol.cxx
+++ b/sw/source/core/txtnode/attrcontentcontrol.cxx
@@ -182,6 +182,42 @@ SwContentControl::SwContentControl(SwFormatContentControl* 
pFormat)
 , m_pFormat(pFormat)
 , m_pTextNode(nullptr)
 {
+if (!pFormat)
+{
+return;
+}
+
+const std::shared_ptr& pOther = 
pFormat->GetContentControl();
+if (!pOther)
+{
+return;
+}
+
+SetShowingPlaceHolder(pOther->m_bShowingPlaceHolder);
+SetCheckbox(pOther->m_bCheckbox);
+SetChecked(pOther->m_bChecked);
+SetCheckedState(pOther->m_aCheckedState);
+SetUncheckedState(pOther->m_aUncheckedState);
+SetListItems(pOther->m_aListItems);
+SetPicture(pOther->m_bPicture);
+SetDate(pOther->m_bDate);
+SetDateFormat(pOther->m_aDateFormat);
+SetDateLanguage(pOther->m_aDateLanguage);
+SetCurrentDate(pOther->m_aCurrentDate);
+SetPlainText(pOther->m_bPlainText);
+SetComboBox(pOther->m_bComboBox);
+SetDropDown(pOther->m_bDropDown);
+SetPlaceholderDocPart(pOther->m_aPlaceholderDocPart);
+SetDataBindingPrefixMappings(pOther->m_aDataBindingPrefixMappings);
+SetDataBindingXpath(pOther->m_aDataBindingXpath);
+SetDataBindingStoreItemID(pOther->m_aDataBindingStoreItemID);
+SetColor(pOther->m_aColor);
+SetAppearance(pOther->m_aAppearance);
+SetAlias(pOther->m_aAlias);
+SetTag(pOther->m_aTag);
+SetId(pOther->m_nId);
+SetTabIndex(pOther->m_nTabIndex);
+SetLock(pOther->m_aLock);
 }
 
 SwContentControl::~SwContentControl() {}


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-02-14 Thread László Németh (via logerrit)
 sw/qa/extras/ooxmlexport/data/tdf147892.fodt |   25 ++
 sw/qa/extras/ooxmlexport/ooxmlexport11.cxx   |   10 +
 sw/source/filter/ww8/docxattributeoutput.cxx |   30 ++-
 sw/source/filter/ww8/docxattributeoutput.hxx |4 +--
 4 files changed, 53 insertions(+), 16 deletions(-)

New commits:
commit f91e083e2565f07a6ebd2f2c0aa69bbacb4cfd19
Author: László Németh 
AuthorDate: Fri Feb 10 13:43:40 2023 +0100
Commit: Miklos Vajna 
CommitDate: Wed Feb 15 07:12:53 2023 +

tdf#147892 DOCX: fix corrupt export at para marker revision history

OOXML export of tracked deletion of tracked paragraph insertion
resulted invalid document.xml, because change tracking history of
paragraph markers isn't supported by OOXML. Export the tracked deletion
of the last run of paragraphs without history (tracked insertion).
This way w:p/w:pPr/w:rPr contains only w:del or w:ins, not both of them
(with broken tag order).

Note: it's possible to optimize the fix to keep the change
tracking history of the characters of the last run of the paragraph,
except the paragraph marker.

Regression from commit 19b3fcf8b0374c361c7f6c285fd5c89b5a2f
"tdf#142387 DOCX track changes: export w:del in w:ins".

Minimal unit test document was created by Miklós Vajna.

Change-Id: I425f4d63c8c6ac29ccd807c1574748c7b9b39e80
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146782
Tested-by: László Németh 
Reviewed-by: László Németh 
(cherry picked from commit 382892341a63e400f221e1a533fd5a5d6b4d9d70)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146795
Tested-by: Jenkins
Reviewed-by: Michael Stahl 
(cherry picked from commit 4eb34d281260d7c9b6f2268ca1fa439655238a55)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147022
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/ooxmlexport/data/tdf147892.fodt 
b/sw/qa/extras/ooxmlexport/data/tdf147892.fodt
new file mode 100644
index ..bb3ffc324dc1
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf147892.fodt
@@ -0,0 +1,25 @@
+
+http://purl.org/dc/elements/1.1/; 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
+  
+
+  
+
+  
+
+  Bob
+  2023-01-02T00:00:00
+
+  
+  
+
+  Alice
+  2023-01-01T00:00:00
+
+  
+
+  
+  
+  
+
+  
+
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
index 8ffd2a9e5673..f62571ff57fc 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx
@@ -1572,6 +1572,16 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf142387)
 assertXPathContent(pXmlDoc, 
"/w:document/w:body/w:p/w:ins/w:del/w:r/w:delText", "inserts ");
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf147892)
+{
+loadAndSave("tdf147892.fodt");
+xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+// w:del in w:ins is exported correctly
+// (both w:del and w:ins were exported for para marker)
+assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:rPr/w:del", 1);
+assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:pPr/w:rPr/w:ins", 0);
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf123054, "tdf123054.docx")
 {
 CPPUNIT_ASSERT_EQUAL(OUString("No Spacing"),
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 2ade8669d251..a70bee00967a 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -1507,13 +1507,13 @@ void DocxAttributeOutput::EndParagraphProperties(const 
SfxItemSet& rParagraphMar
 
 if ( pRedlineParagraphMarkerDeleted )
 {
-StartRedline( pRedlineParagraphMarkerDeleted );
-EndRedline( pRedlineParagraphMarkerDeleted );
+StartRedline( pRedlineParagraphMarkerDeleted, /*bLastRun=*/true );
+EndRedline( pRedlineParagraphMarkerDeleted, /*bLastRun=*/true );
 }
 if ( pRedlineParagraphMarkerInserted )
 {
-StartRedline( pRedlineParagraphMarkerInserted );
-EndRedline( pRedlineParagraphMarkerInserted );
+StartRedline( pRedlineParagraphMarkerInserted, /*bLastRun=*/true );
+EndRedline( pRedlineParagraphMarkerInserted, /*bLastRun=*/true );
 }
 
 // mergeTopMarks() after paragraph mark properties child elements.
@@ -1618,7 +1618,7 @@ void DocxAttributeOutput::StartRun( const SwRedlineData* 
pRedlineData, sal_Int32
 m_pSerializer->mark(Tag_StartRun_3); // let's call it "postponed text"
 }
 
-void DocxAttributeOutput::EndRun(const SwTextNode* pNode, sal_Int32 nPos, 
sal_Int32 nLen, bool /*bLastRun*/)
+void 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source writerfilter/qa

2023-01-30 Thread Justin Luth (via logerrit)
 sw/qa/extras/ooxmlexport/ooxmlexport17.cxx   |4 ++--
 sw/source/filter/ww8/docxattributeoutput.cxx |4 +++-
 writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx   |2 +-
 writerfilter/qa/cppunittests/dmapper/data/sdt-run-rich-text.docx |binary
 4 files changed, 6 insertions(+), 4 deletions(-)

New commits:
commit cb77f5a5d061bdc460f2606b861f436675443073
Author: Justin Luth 
AuthorDate: Wed Jan 25 16:29:55 2023 -0500
Commit: Miklos Vajna 
CommitDate: Mon Jan 30 08:32:56 2023 +

tdf#151548 sw content controls: preserve tabIndex val="-1"

Either we have to read sal_uInt32
(which I can't figure out how to do)
or else we have to write it out as sal_Int32.

Microsoft isn't much help here because their documentation
does not give any example of a non-tabsltop,
and one errata document indicates that MS Word
simply ignores tabIndex altogether for Sdt (and ffData).

According to the documentation,
tabIndex is a CT_UnsignedDecimalNumber
which we do not have in our model.xml
so it was defined as being a CT_DecimalNumber
which works fine for reading something human sensible like -1.

However, in our exporting we were exporting a sal_uInt32
which creates large, all positive numbers
which were not being read on import.
Nothing I tried worked to read these large numbers.
Perhaps it is even illegal to do so in MS formats?

Since it doesn't seem to matter to MS Word,
and for a human it is easier to understand -1,
and it is easier to solve in export than import,
I'm taking the easy road.

Change-Id: I6b296703c9a37149d9e11f29901e6db32bd041b7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146149
Tested-by: Jenkins
Reviewed-by: Justin Luth 
Reviewed-by: Miklos Vajna 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146296
Tested-by: Jenkins CollaboraOffice 

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index 42b7a0891877..98be0085ab6e 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -304,7 +304,7 @@ CPPUNIT_TEST_FIXTURE(Test, testDateContentControlExport)
 xContentControlProps->setPropertyValue("Alias", 
uno::Any(OUString("myalias")));
 xContentControlProps->setPropertyValue("Tag", uno::Any(OUString("mytag")));
 xContentControlProps->setPropertyValue("Id", 
uno::Any(static_cast(123)));
-xContentControlProps->setPropertyValue("TabIndex", 
uno::Any(sal_uInt32(2)));
+xContentControlProps->setPropertyValue("TabIndex", 
uno::Any(sal_uInt32(4294967295))); // -1
 xContentControlProps->setPropertyValue("Lock", 
uno::Any(OUString("sdtLocked")));
 
 xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
@@ -332,7 +332,7 @@ CPPUNIT_TEST_FIXTURE(Test, testDateContentControlExport)
 assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:alias", "val", "myalias");
 assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:tag", "val", "mytag");
 assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:id", "val", "123");
-assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:tabIndex", "val", "2");
+assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:tabIndex", "val", "-1");
 assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:lock", "val", "sdtLocked");
 }
 
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 0f65ba8cdebe..2ade8669d251 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2439,8 +2439,10 @@ void DocxAttributeOutput::WriteContentControlStart()
 
 if (m_pContentControl->GetTabIndex())
 {
+// write the unsigned value as as if it were signed since that is all 
we can import
+const sal_Int32 nTabIndex = 
static_cast(m_pContentControl->GetTabIndex());
 m_pSerializer->singleElementNS(XML_w, XML_tabIndex, FSNS(XML_w, 
XML_val),
-   
OString::number(m_pContentControl->GetTabIndex()));
+   OString::number(nTabIndex));
 }
 
 if (!m_pContentControl->GetLock().isEmpty())
diff --git a/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx 
b/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
index bde82531b327..f8fbce8dfdde 100644
--- a/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
@@ -102,7 +102,7 @@ CPPUNIT_TEST_FIXTURE(Test, testSdtRunRichText)
 sal_uInt32 nTabIndex = 0;
 xContentControlProps->getPropertyValue("TabIndex") >>= nTabIndex;
 // This was 0
-CPPUNIT_ASSERT_EQUAL(static_cast(5), nTabIndex);
+CPPUNIT_ASSERT_EQUAL(static_cast(4294967295), nTabIndex);
 OUString aLock;
 xContentControlProps->getPropertyValue("Lock") >>= aLock;
 // This was empty.
diff --git 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-01-26 Thread Miklos Vajna (via logerrit)
 sw/qa/filter/ww8/ww8.cxx |   20 
 sw/source/filter/ww8/docxattributeoutput.cxx |   11 ---
 2 files changed, 28 insertions(+), 3 deletions(-)

New commits:
commit 8af7d4822d525a4b8cea089516755de71c3eca22
Author: Miklos Vajna 
AuthorDate: Mon Nov 21 20:05:11 2022 +0100
Commit: Aron Budea 
CommitDate: Thu Jan 26 13:15:43 2023 +

tdf#152045 DOCX export: fix empty display text for content control list 
items

Regression from commit f726fbc2699b05199a8dec3055710a7131e0aad6
(tdf#151261 DOCX import: fix dropdown SDT when the item display text is
missing, 2022-10-10), the problem was that the correct way to represent
"no display value" is not an attribute with empty value but a missing
attribute.

Change-Id: I25b2bb56f43d1ca1bf95d1c59b208cb24530
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143048
Tested-by: Jenkins
Reviewed-by: Miklos Vajna 
(cherry picked from commit 017c38a9702da0566ac1ce5d758444e5ff25df9d)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146090
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Aron Budea 

diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx
index 7dcb337cd413..3848decc4f46 100644
--- a/sw/qa/filter/ww8/ww8.cxx
+++ b/sw/qa/filter/ww8/ww8.cxx
@@ -145,6 +145,26 @@ CPPUNIT_TEST_FIXTURE(Test, testDocxSymbolFontExport)
 assertXPath(pXmlDoc, "//w:p/w:r/w:sym[1]", "font", "Wingdings");
 assertXPath(pXmlDoc, "//w:p/w:r/w:sym[1]", "char", "f0e0");
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testDocxContentControlDropdownEmptyDisplayText)
+{
+// Given a document with a dropdown content control, the only list item 
has no display text
+// (only a value):
+SwDoc* pDoc = createSwDoc();
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+pWrtShell->InsertContentControl(SwContentControlType::DROP_DOWN_LIST);
+
+// When saving to DOCX:
+save("Office Open XML Text", maTempFile);
+mbExported = true;
+
+// Then make sure that no display text attribute is written:
+xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+// Without the accompanying fix in place, this test would have failed with:
+// - XPath '//w:sdt/w:sdtPr/w:dropDownList/w:listItem' unexpected 
'displayText' attribute
+// i.e. we wrote an empty attribute instead of omitting it.
+assertXPathNoAttribute(pXmlDoc, 
"//w:sdt/w:sdtPr/w:dropDownList/w:listItem", "displayText");
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index e3a7828e5961..0f65ba8cdebe 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2491,9 +2491,14 @@ void DocxAttributeOutput::WriteContentControlStart()
 }
 for (const auto& rItem : m_pContentControl->GetListItems())
 {
-m_pSerializer->singleElementNS(XML_w, XML_listItem,
-FSNS(XML_w, XML_displayText), rItem.m_aDisplayText,
-FSNS(XML_w, XML_value), rItem.m_aValue);
+rtl::Reference xAttributes = 
FastSerializerHelper::createAttrList();
+if (!rItem.m_aDisplayText.isEmpty())
+{
+// If there is no display text, need to omit the attribute, 
not write an empty one.
+xAttributes->add(FSNS(XML_w, XML_displayText), 
rItem.m_aDisplayText);
+}
+xAttributes->add(FSNS(XML_w, XML_value), rItem.m_aValue);
+m_pSerializer->singleElementNS(XML_w, XML_listItem, xAttributes);
 }
 if (m_pContentControl->GetComboBox())
 {


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-01-19 Thread Miklos Vajna (via logerrit)
 sw/qa/uibase/shells/textfld.cxx |   28 
 sw/source/uibase/shells/textfld.cxx |8 ++--
 2 files changed, 34 insertions(+), 2 deletions(-)

New commits:
commit 22f3aff3a1582f17f314e13f2685fefddccfae4a
Author: Miklos Vajna 
AuthorDate: Thu Jan 19 08:19:46 2023 +0100
Commit: Miklos Vajna 
CommitDate: Thu Jan 19 15:48:33 2023 +

sw, .uno:InsertField: handle Endnote as a value for the Wrapper parameter

This is similar to commit 43d80906c8693ca27c5b3077fbaa259df4004924 (sw:
.uno:TextFormField: handle Endnote as a value for the Wrapper parameter,
2023-01-17), but that was for fieldmarks & endnotes, this is for
refmarks & endnotes.

(cherry picked from commit 04d988d3c368fe07ae3c44c536a4513e424f104e)

Change-Id: I46512dd973508f51f7093521c40ad4100dd39ae6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145773
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Justin Luth 

diff --git a/sw/qa/uibase/shells/textfld.cxx b/sw/qa/uibase/shells/textfld.cxx
index 7799063a016c..1ef61b658c4a 100644
--- a/sw/qa/uibase/shells/textfld.cxx
+++ b/sw/qa/uibase/shells/textfld.cxx
@@ -57,4 +57,32 @@ CPPUNIT_TEST_FIXTURE(Test, testInsertRefmarkFootnote)
 CPPUNIT_ASSERT_EQUAL(OUString("content"), 
rFormatNote.GetFootnoteText(*pWrtShell->GetLayout()));
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testInsertRefmarkEndnote)
+{
+// Given an empty document:
+SwDoc* pDoc = createSwDoc();
+
+// When inserting a refmark inside an endnote:
+uno::Sequence aArgs = {
+comphelper::makePropertyValue("TypeName", 
uno::Any(OUString("SetRef"))),
+comphelper::makePropertyValue("Name", uno::Any(OUString("myref"))),
+comphelper::makePropertyValue("Content", 
uno::Any(OUString("content"))),
+comphelper::makePropertyValue("Wrapper", 
uno::Any(OUString("Endnote"))),
+};
+dispatchCommand(mxComponent, ".uno:InsertField", aArgs);
+
+// Then make sure that the note body contains the refmark:
+SwFootnoteIdxs& rNotes = pDoc->GetFootnoteIdxs();
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 1
+// - Actual  : 0
+// i.e. no endnote was inserted.
+CPPUNIT_ASSERT_EQUAL(static_cast(1), rNotes.size());
+SwTextFootnote* pNote = rNotes[0];
+const SwFormatFootnote& rNote = pNote->GetFootnote();
+CPPUNIT_ASSERT(rNote.IsEndNote());
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+CPPUNIT_ASSERT_EQUAL(OUString("content"), 
rNote.GetFootnoteText(*pWrtShell->GetLayout()));
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/shells/textfld.cxx 
b/sw/source/uibase/shells/textfld.cxx
index a68b17124d2b..a59a5616ffcf 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -292,13 +292,17 @@ void SwTextShell::ExecField(SfxRequest )
 }
 if (pArgs->GetItemState(FN_PARAM_5, false, ) == 
SfxItemState::SET)
 {
+// Wrap the field in the requested container instead of 
inserting it
+// directly at the cursor position.
 const OUString& rWrapper = static_cast(pItem)->GetValue();
 if (rWrapper == "Footnote")
 {
-// Wrap the field in the requested container instead 
of inserting it
-// directly at the cursor position.
 GetShellPtr()->InsertFootnote(OUString());
 }
+else if (rWrapper == "Endnote")
+{
+GetShellPtr()->InsertFootnote(OUString(), 
/*bEndNote=*/true);
+}
 }
 SwInsertField_Data aData(nType, nSubType, aPar1, aPar2, 
nFormat, GetShellPtr(), cSeparator );
 bRes = aFieldMgr.InsertField( aData );


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-01-18 Thread Miklos Vajna (via logerrit)
 sw/qa/uibase/shells/shells.cxx  |   40 
 sw/source/uibase/shells/textfld.cxx |   16 ++
 2 files changed, 52 insertions(+), 4 deletions(-)

New commits:
commit de0db79ed42b3df9e648b1b7cf7cae37f0601b23
Author: Miklos Vajna 
AuthorDate: Tue Jan 17 11:38:14 2023 +0100
Commit: Miklos Vajna 
CommitDate: Wed Jan 18 14:12:05 2023 +

sw: .uno:TextFormField: handle Endnote as a value for the Wrapper parameter

This is similar to the fieldmark-in-footnote case, but here we need to
make sure that the layout is calculated before the cursor attempts to
jump to the endnote, otherwise the fieldmark will be inserted before the
endnote anchor, not in the endnote body.

The move of StartAction() / EndAction() calls can be done
unconditionally, it's not a problem for the existing footnote case.

(cherry picked from commit 43d80906c8693ca27c5b3077fbaa259df4004924)

Change-Id: I772d27937456978ca6aa01148eff3163d8877208
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145672
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Justin Luth 

diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index f4fcbd8eeb7e..a41bd2299b5f 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -40,6 +40,7 @@
 #include 
 #include 
 #include 
+#include 
 
 constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/uibase/shells/data/";
 
@@ -890,6 +891,45 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testInsertTextFormFieldFootnote)
 CPPUNIT_ASSERT_EQUAL(static_cast(1), rFootnotes.size());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertTextFormFieldEndnote)
+{
+// Given an empty document:
+SwDoc* pDoc = createSwDoc();
+
+// When inserting an ODF_UNHANDLED fieldmark inside an endnote:
+uno::Sequence aArgs = {
+comphelper::makePropertyValue("FieldType", 
uno::Any(OUString(ODF_UNHANDLED))),
+comphelper::makePropertyValue("FieldCommand",
+  uno::Any(OUString("ADDIN ZOTERO_BIBL foo 
bar"))),
+comphelper::makePropertyValue("FieldResult", 
uno::Any(OUString("result"))),
+comphelper::makePropertyValue("Wrapper", 
uno::Any(OUString("Endnote"))),
+};
+dispatchCommand(mxComponent, ".uno:TextFormField", aArgs);
+
+// Then make sure that the endnote is created:
+SwFootnoteIdxs& rFootnotes = pDoc->GetFootnoteIdxs();
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 1
+// - Actual  : 0
+// i.e. no endnote was inserted.
+CPPUNIT_ASSERT_EQUAL(static_cast(1), rFootnotes.size());
+SwTextFootnote* pEndnote = rFootnotes[0];
+const SwFormatFootnote& rFormatEndnote = pEndnote->GetFootnote();
+CPPUNIT_ASSERT(rFormatEndnote.IsEndNote());
+// Also check that the endnote body contains the fieldmark:
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+pWrtShell->SttEndDoc(/*bStt=*/true);
+pWrtShell->GotoFootnoteText();
+pWrtShell->EndOfSection(/*bSelect=*/true);
+SwCursor* pCursor = pWrtShell->GetCursor();
+OUString aActual = pCursor->GetText();
+static sal_Unicode const aForbidden[]
+= { CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FIELDSEP, CH_TXT_ATR_FIELDEND, 0 
};
+aActual = comphelper::string::removeAny(aActual, aForbidden);
+// Then this was empty: the fieldmark was inserted before the note anchor, 
not in the note body.
+CPPUNIT_ASSERT_EQUAL(OUString("result"), aActual);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/shells/textfld.cxx 
b/sw/source/uibase/shells/textfld.cxx
index cd9d1f61ebf6..bce713647c62 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -722,9 +722,6 @@ FIELD_INSERT:
 }
 
 
rSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT_FORM_FIELD, 
nullptr);
-// Don't update the layout after inserting content and before 
deleting temporary
-// text nodes.
-rSh.StartAction();
 
 SwPaM* pCursorPos = rSh.GetCursor();
 if(pCursorPos)
@@ -749,8 +746,19 @@ FIELD_INSERT:
 {
 rSh.InsertFootnote(OUString());
 }
+else if (aWrapper == "Endnote")
+{
+// It's important that there is no Start/EndAction() 
around this, so the
+// inner EndAction() triggers a layout update and the 
cursor can jump to the
+// created SwFootnoteFrame.
+rSh.InsertFootnote(OUString(), /*bEndNote=*/true);
+}
 }
 
+// Don't update the layout after inserting content and before 
deleting temporary
+// text nodes.
+   

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-01-17 Thread Dennis Francis (via logerrit)
 sw/qa/extras/tiledrendering/data/savedauthorfield.odt |binary
 sw/qa/extras/tiledrendering/tiledrendering.cxx|   16 +++
 sw/source/uibase/uno/unotxdoc.cxx |   19 +-
 3 files changed, 34 insertions(+), 1 deletion(-)

New commits:
commit 5b1f5319fc065eac71267b29472111d81e0dc14e
Author: Dennis Francis 
AuthorDate: Tue Jan 17 12:23:44 2023 +0530
Commit: Miklos Vajna 
CommitDate: Tue Jan 17 14:26:29 2023 +

sw: lok: use redline author for saved author fields(2)

Without the fix author fields will expand to "Unknown author" when
loading files which have author fields in them. But only update the
fields when the first view joins and not for later view joins.

online.git does not expect document to be modified just after load, so
to avoid this situation clear the document modified flag just after
field update.

Change-Id: I19253f4c871e2c023d206d2d83b6d694ed5933d1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145654
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/tiledrendering/data/savedauthorfield.odt 
b/sw/qa/extras/tiledrendering/data/savedauthorfield.odt
new file mode 100644
index ..e4b41d28b92a
Binary files /dev/null and 
b/sw/qa/extras/tiledrendering/data/savedauthorfield.odt differ
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 88b4dcc95d7f..3330e419dc8b 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -3791,6 +3791,22 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, 
testAuthorField)
 assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/Special[1]", "rText", 
sAuthor);
 }
 
+CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testSavedAuthorField)
+{
+SwXTextDocument* pXTextDocument = createDoc("savedauthorfield.odt");
+const OUString sAuthor("XYZ ABCD");
+uno::Sequence 
aPropertyValues1(comphelper::InitPropertySequence(
+{
+{".uno:Author", uno::makeAny(sAuthor)},
+}));
+pXTextDocument->initializeForTiledRendering(aPropertyValues1);
+
+Scheduler::ProcessEventsToIdle();
+
+xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/Special[1]", "rText", 
sAuthor);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uno/unotxdoc.cxx 
b/sw/source/uibase/uno/unotxdoc.cxx
index f91fe5626f1b..78af58de3184 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3570,6 +3570,9 @@ void SwXTextDocument::initializeForTiledRendering(const 
css::uno::SequenceGetRedlineAuthor(SW_MOD()->GetRedlineAuthor());
+OUString sAuthor;
+
 for (const beans::PropertyValue& rValue : rArguments)
 {
 if (rValue.Name == ".uno:HideWhitespace" && rValue.Value.has())
@@ -3578,8 +3581,9 @@ void SwXTextDocument::initializeForTiledRendering(const 
css::uno::Sequence());
 else if (rValue.Name == ".uno:Author" && rValue.Value.has())
 {
+sAuthor = rValue.Value.get();
 // Store the author name in the view.
-pView->SetRedlineAuthor(rValue.Value.get());
+pView->SetRedlineAuthor(sAuthor);
 // Let the actual author name pick up the value from the current
 // view, which would normally happen only during the next view
 // switch.
@@ -3589,6 +3593,19 @@ void SwXTextDocument::initializeForTiledRendering(const 
css::uno::Sequence());
 }
 
+if (!sAuthor.isEmpty() && sAuthor != sOrigAuthor)
+{
+SwView* pFirstView = static_cast(SfxViewShell::GetFirst());
+if (pFirstView && SfxViewShell::GetNext(*pFirstView) == nullptr)
+{
+if (SwEditShell* pShell = >GetWrtShell())
+{
+pShell->SwViewShell::UpdateFields(true);
+pShell->ResetModified();
+}
+}
+}
+
 // Set the initial zoom value to 1; usually it is set in setClientZoom and
 // SwViewShell::PaintTile; zoom value is used for chart in place
 // editing, see postMouseEvent and setGraphicSelection methods.


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-01-17 Thread Attila Bakos (NISZ) (via logerrit)
 sw/qa/extras/ooxmlexport/data/testWPGZOrder.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport10.cxx   |4 -
 sw/qa/extras/ooxmlexport/ooxmlexport17.cxx   |   49 +++
 sw/source/core/doc/textboxhelper.cxx |   15 ---
 sw/source/core/draw/dcontact.cxx |8 +++
 5 files changed, 68 insertions(+), 8 deletions(-)

New commits:
commit 0cb370d02bebf6a9d65b5852815e2c617b33a89a
Author: Attila Bakos (NISZ) 
AuthorDate: Tue Jan 11 12:09:46 2022 +0100
Commit: Miklos Vajna 
CommitDate: Tue Jan 17 09:26:33 2023 +

Related tdf#66039 DOCX import: fix Z-order of group shapes

A missing function resulted covered textboxes which weren't
visible in group shapes.

Follow-up to 121cbc250b36290f0f8c7265fea57256dad69553
"tdf#66039 DOCX: import textboxes (with tables, images etc.)
in group shapes".

Change-Id: I08eb1c1cf4a4f4769af8812500b9cf9778b01e9c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128279
Tested-by: László Németh 
Reviewed-by: László Németh 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143372
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/ooxmlexport/data/testWPGZOrder.docx 
b/sw/qa/extras/ooxmlexport/data/testWPGZOrder.docx
new file mode 100644
index ..664f47a0b623
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/testWPGZOrder.docx 
differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
index e23a42bf4983..3dafae143432 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -116,9 +116,9 @@ protected:
 
 DECLARE_OOXMLEXPORT_TEST(testWPGtextboxes, "testWPGtextboxes.docx")
 {
-CPPUNIT_ASSERT_EQUAL(1, getShapes());
+CPPUNIT_ASSERT_EQUAL(2, getShapes());
 
-auto MyShape = getShape(1);
+auto MyShape = getShape(2);
 CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.GroupShape"), 
MyShape->getShapeType());
 
 uno::Reference xGroup(MyShape, uno::UNO_QUERY_THROW);
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index 395f0dbf03fc..42b7a0891877 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 
 
 #include 
@@ -28,6 +29,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 
@@ -390,6 +392,53 @@ DECLARE_OOXMLEXPORT_TEST(testTdf126287, "tdf126287.docx")
 CPPUNIT_ASSERT_EQUAL(2, getPages());
 }
 
+DECLARE_OOXMLEXPORT_TEST(TestWPGZOrder, "testWPGZOrder.docx")
+{
+// Check if the load failed.
+CPPUNIT_ASSERT(mxComponent);
+
+// Get the WPG
+uno::Reference xGroup(getShape(1), uno::UNO_QUERY_THROW);
+uno::Reference xGroupProperties(xGroup, 
uno::UNO_QUERY_THROW);
+
+// Initialize a queue for subgroups
+std::queue> xGroupList;
+xGroupList.push(xGroup);
+
+// Every textbox shall be visible.
+while (xGroupList.size())
+{
+// Get the first group
+xGroup = xGroupList.front();
+xGroupList.pop();
+for (sal_Int32 i = 0; i < xGroup->getCount(); ++i)
+{
+// Get the child shape
+uno::Reference 
xChildShapeProperties(xGroup->getByIndex(i),
+uno::UNO_QUERY_THROW);
+// Check for textbox
+if 
(!xChildShapeProperties->getPropertyValue("TextBox").get())
+{
+// Is this a Group Shape? Put it into the queue.
+uno::Reference 
xInnerGroup(xGroup->getByIndex(i), uno::UNO_QUERY);
+if (xInnerGroup)
+xGroupList.push(xInnerGroup);
+continue;
+}
+
+// Get the textbox properties
+uno::Reference xTextBoxFrameProperties(
+xChildShapeProperties->getPropertyValue("TextBoxContent"), 
uno::UNO_QUERY_THROW);
+
+// Assert that the textbox ZOrder greater than the groupshape
+
CPPUNIT_ASSERT_GREATER(xGroupProperties->getPropertyValue("ZOrder").get(),
+
xTextBoxFrameProperties->getPropertyValue("ZOrder").get());
+// Before the fix, this failed because that was less, and the 
textboxes were covered.
+}
+
+}
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf123642_BookmarkAtDocEnd, "tdf123642.docx")
 {
 // get bookmark interface
diff --git a/sw/source/core/doc/textboxhelper.cxx 
b/sw/source/core/doc/textboxhelper.cxx
index bcdf25002305..bb1d6f331dbc 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -1432,15 +1432,20 @@ bool 
SwTextBoxHelper::DoTextBoxZOrderCorrection(SwFrameFormat* pShape, const Sdr
 {
 // TODO: do this with group shape textboxes.
 SdrObject* pShpObj = nullptr;
-//if (pObj)
-//pShpObj = pObj;
-//else
+
 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source writerfilter/source

2023-01-13 Thread Mike Kaganski (via logerrit)
 sw/qa/extras/ooxmlexport/ooxmlexport18.cxx  |   13 -
 sw/source/filter/ww8/styles.cxx |1 
 sw/source/filter/ww8/wrtw8sty.cxx   |   13 +
 writerfilter/source/dmapper/StyleSheetTable.cxx |  232 +---
 4 files changed, 142 insertions(+), 117 deletions(-)

New commits:
commit 00943494f782295b1d186045d7307f7924eb8c1d
Author: Mike Kaganski 
AuthorDate: Wed Jan 11 17:02:04 2023 +0300
Commit: Mike Kaganski 
CommitDate: Sat Jan 14 07:17:41 2023 +

tdf#152425 Synchronize import and export style names mapping

1. Make the mapping in StyleSheetTable::ConvertStyleName match the
   opposite direction mapping happening in MSWordStyles::GetWWId and
   ww::GetEnglishNameFromSti. Add missing styles, provide comments to
   clarify the process and find respective pool format ids.
2. Instead of appending " (user)" to conflicting style names, which
   is the method used by SwStyleNameMapper to disambiguate API names,
   append " (WW)", which allows to avoid unwanted merging conflicting
   styles.

Change-Id: I47b1c7f570da6e6e21155669fdd1b77de5cc17da
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145349
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145377
Tested-by: Jenkins CollaboraOffice 

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
index 97d1d117e3ea..129e42325640 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -147,17 +147,12 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf152425)
 
 // Check that "List Number" and "List 5" styles don't get merged
 const OUString Para3Style = getProperty(getParagraph(3), 
"ParaStyleName");
-CPPUNIT_ASSERT_EQUAL(OUString("List Number"), Para3Style);
+CPPUNIT_ASSERT_EQUAL(OUString("Numbering 1"), Para3Style);
 const OUString Para4Style = getProperty(getParagraph(4), 
"ParaStyleName");
-// Eventually, we need to check this:
-// CPPUNIT_ASSERT_EQUAL(OUString("List 5"), Para4Style);
-// But for now, just make sure that the style names differ
-CPPUNIT_ASSERT(Para4Style != Para3Style);
+CPPUNIT_ASSERT_EQUAL(OUString("List 5 (WW)"), Para4Style);
+// Also check that "List 5" and "List Bullet 5" styles don't get merged
 const OUString Para5Style = getProperty(getParagraph(5), 
"ParaStyleName");
-// Eventually, we need to check this:
-// CPPUNIT_ASSERT_EQUAL(OUString("List Bullet 5"), Para5Style);
-// But for now, just make sure that the style names differ
-CPPUNIT_ASSERT(Para5Style != Para4Style);
+CPPUNIT_ASSERT_EQUAL(OUString("List 5"), Para5Style);
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/styles.cxx b/sw/source/filter/ww8/styles.cxx
index c7a28e77e60b..33d0ad3dec5f 100644
--- a/sw/source/filter/ww8/styles.cxx
+++ b/sw/source/filter/ww8/styles.cxx
@@ -23,6 +23,7 @@
 
 namespace
 {
+// Keep in sync with StyleSheetTable::ConvertStyleName
 const char **GetStiNames() noexcept
 {
 // Matches enum ww::sti in sw/source/filter/inc/wwstyles.hxx
diff --git a/sw/source/filter/ww8/wrtw8sty.cxx 
b/sw/source/filter/ww8/wrtw8sty.cxx
index b76907229f0d..5fdc76c55aac 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -198,6 +198,7 @@ static sal_uInt16 BuildGetSlot(const SwFormat& rFormat)
 }
 
 
+// Keep in sync with StyleSheetTable::ConvertStyleName
 sal_uInt16 MSWordStyles::GetWWId( const SwFormat& rFormat )
 {
 sal_uInt16 nRet = ww::stiUser;// user style as default
@@ -317,6 +318,14 @@ void MSWordStyles::BuildStylesTable()
 }
 }
 
+// StyleSheetTable::ConvertStyleName appends the suffix do disambiguate 
conflicting style names
+static OUString StripWWSuffix(const OUString& s)
+{
+OUString ret = s;
+ret.endsWith(" (WW)", );
+return ret;
+}
+
 void MSWordStyles::BuildWwNames()
 {
 std::unordered_set aUsed;
@@ -361,9 +370,9 @@ void MSWordStyles::BuildWwNames()
 if (!entry.ww_name.isEmpty())
 continue;
 if (entry.format)
-entry.ww_name = entry.format->GetName();
+entry.ww_name = StripWWSuffix(entry.format->GetName());
 else if (entry.num_rule)
-entry.ww_name = entry.num_rule->GetName();
+entry.ww_name = StripWWSuffix(entry.num_rule->GetName());
 else
 continue;
 makeUniqueName(entry.ww_name);
diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx 
b/writerfilter/source/dmapper/StyleSheetTable.cxx
index 8b3bc02b44a6..d82bc3ed61fa 100644
--- a/writerfilter/source/dmapper/StyleSheetTable.cxx
+++ b/writerfilter/source/dmapper/StyleSheetTable.cxx
@@ -1418,129 +1418,141 @@ OUString StyleSheetTable::ConvertStyleName( const 
OUString& rWWName, bool bExten
 //search for the rWWName in the IdentifierD of the existing styles 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-01-13 Thread Miklos Vajna (via logerrit)
 sw/qa/uibase/uno/uno.cxx  |   34 
 sw/source/uibase/uno/loktxdoc.cxx |   62 --
 2 files changed, 94 insertions(+), 2 deletions(-)

New commits:
commit 3c61a3642c8342568748bd9feaf58d8998ddb285
Author: Miklos Vajna 
AuthorDate: Thu Jan 12 15:13:00 2023 +0100
Commit: Pranam Lashkari 
CommitDate: Fri Jan 13 20:01:09 2023 +

sw lok: expose name of refmark under cursor

This is similar to commit 4bcb66ec7b417fbe113267f2615e78fe47eb55ca (sw
lok: expose name of bookmark under cursor, 2023-01-11), but that was for
the bookmark under the cursor and this is for refmarks.

(cherry picked from commit 81f690ec0cb2a6dc0d6ca0f6de3adcc07eb7bc12)

Change-Id: I0acf0181d0acfdc087e1ed737b3c18ab3736031a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145429
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Justin Luth 

diff --git a/sw/qa/uibase/uno/uno.cxx b/sw/qa/uibase/uno/uno.cxx
index 595987eea423..ee6ce3f1ac70 100644
--- a/sw/qa/uibase/uno/uno.cxx
+++ b/sw/qa/uibase/uno/uno.cxx
@@ -368,6 +368,40 @@ CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetBookmark)
 CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_BREF_1"), 
aBookmark.get("name"));
 }
 
+CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetField)
+{
+// Given a document with a refmark:
+SwDoc* pDoc = createSwDoc();
+uno::Sequence aArgs = {
+comphelper::makePropertyValue("TypeName", 
uno::Any(OUString("SetRef"))),
+comphelper::makePropertyValue("Name",
+  uno::Any(OUString("ZOTERO_ITEM 
CSL_CITATION {} refmark"))),
+comphelper::makePropertyValue("Content", 
uno::Any(OUString("content"))),
+};
+dispatchCommand(mxComponent, ".uno:InsertField", aArgs);
+
+// When in the refmark with the cursor and getting the command value for 
.uno:Field:
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+pWrtShell->SttEndDoc(/*bStt=*/false);
+pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
+tools::JsonWriter aJsonWriter;
+OString 
aCommand(".uno:Field?typeName=SetRef=ZOTERO_ITEM%20CSL_CITATION");
+auto pXTextDocument = dynamic_cast(mxComponent.get());
+pXTextDocument->getCommandValues(aJsonWriter, aCommand);
+
+// Then make sure we find the inserted refmark:
+std::unique_ptr 
pJSON(aJsonWriter.extractData());
+std::stringstream aStream(pJSON.get());
+boost::property_tree::ptree aTree;
+boost::property_tree::read_json(aStream, aTree);
+boost::property_tree::ptree aBookmark = aTree.get_child("setRef");
+// Without the accompanying fix in place, this test would have failed with:
+// - No such node (setRef)
+// i.e. the returned JSON was an empty object.
+CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_ITEM CSL_CITATION {} refmark"),
+ aBookmark.get("name"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uno/loktxdoc.cxx 
b/sw/source/uibase/uno/loktxdoc.cxx
index 101f0ff082c8..2780e39a1686 100644
--- a/sw/source/uibase/uno/loktxdoc.cxx
+++ b/sw/source/uibase/uno/loktxdoc.cxx
@@ -328,6 +328,58 @@ void GetFields(tools::JsonWriter& rJsonWriter, SwDocShell* 
pDocShell,
 }
 }
 
+/// Implements getCommandValues(".uno:Field").
+///
+/// Parameters:
+///
+/// - typeName: field type condition to not return all fields
+/// - namePrefix: field name prefix to not return all fields
+void GetField(tools::JsonWriter& rJsonWriter, SwDocShell* pDocShell,
+  const std::map& rArguments)
+{
+OUString aTypeName;
+{
+auto it = rArguments.find("typeName");
+if (it != rArguments.end())
+{
+aTypeName = it->second;
+}
+}
+// See SwFieldTypeFromString().
+if (aTypeName != "SetRef")
+{
+return;
+}
+
+OUString aNamePrefix;
+{
+auto it = rArguments.find("namePrefix");
+if (it != rArguments.end())
+{
+aNamePrefix = it->second;
+}
+}
+
+SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+SwPosition& rCursor = *pWrtShell->GetCursor()->GetPoint();
+SwTextNode* pTextNode = rCursor.GetNode().GetTextNode();
+std::vector aAttrs
+= pTextNode->GetTextAttrsAt(rCursor.nContent.GetIndex(), 
RES_TXTATR_REFMARK);
+tools::ScopedJsonWriterNode aRefmark = rJsonWriter.startNode("setRef");
+if (aAttrs.empty())
+{
+return;
+}
+
+const SwFormatRefMark& rRefmark = aAttrs[0]->GetRefMark();
+if (!rRefmark.GetRefName().startsWith(aNamePrefix))
+{
+return;
+}
+
+rJsonWriter.put("name", rRefmark.GetRefName());
+}
+
 /// Implements getCommandValues(".uno:Sections").
 ///
 /// Parameters:
@@ -363,8 +415,9 @@ void GetSections(tools::JsonWriter& rJsonWriter, 
SwDocShell* pDocShell,
 bool SwXTextDocument::supportsCommand(const 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-01-12 Thread Aron Budea (via logerrit)
 dev/null   |binary
 sw/qa/extras/tiledrendering/tiledrendering.cxx |   16 
 sw/source/uibase/uno/unotxdoc.cxx  |   16 +---
 3 files changed, 1 insertion(+), 31 deletions(-)

New commits:
commit ffb5c5e771f46d7bad9e39b547d40de7dca825ce
Author: Aron Budea 
AuthorDate: Fri Jan 13 01:43:29 2023 +0100
Commit: Aron Budea 
CommitDate: Fri Jan 13 03:00:17 2023 +

Revert "sw: lok: use redline author for saved author fields"

Causes unit test failures in online: unit-wopi-lock, unit-crash,
unit-wopi-fail-upload, unit-wopi-save-on-exit,
unit-wopi-documentconflict.

This reverts commit c33e60dd5d5aa8dd585afc9498f87d17ab22fb27.

Change-Id: Ib2a29ded0d3f7c2c2ba4ba4d192a3a0099b8023c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145424
Tested-by: Aron Budea 
Reviewed-by: Aron Budea 

diff --git a/sw/qa/extras/tiledrendering/data/savedauthorfield.odt 
b/sw/qa/extras/tiledrendering/data/savedauthorfield.odt
deleted file mode 100644
index a060c5892f12..
Binary files a/sw/qa/extras/tiledrendering/data/savedauthorfield.odt and 
/dev/null differ
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 3330e419dc8b..88b4dcc95d7f 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -3791,22 +3791,6 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, 
testAuthorField)
 assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/Special[1]", "rText", 
sAuthor);
 }
 
-CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testSavedAuthorField)
-{
-SwXTextDocument* pXTextDocument = createDoc("savedauthorfield.odt");
-const OUString sAuthor("XYZ ABCD");
-uno::Sequence 
aPropertyValues1(comphelper::InitPropertySequence(
-{
-{".uno:Author", uno::makeAny(sAuthor)},
-}));
-pXTextDocument->initializeForTiledRendering(aPropertyValues1);
-
-Scheduler::ProcessEventsToIdle();
-
-xmlDocUniquePtr pXmlDoc = parseLayoutDump();
-assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/Special[1]", "rText", 
sAuthor);
-}
-
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uno/unotxdoc.cxx 
b/sw/source/uibase/uno/unotxdoc.cxx
index 05bddd1f5747..f91fe5626f1b 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3570,9 +3570,6 @@ void SwXTextDocument::initializeForTiledRendering(const 
css::uno::SequenceGetRedlineAuthor(SW_MOD()->GetRedlineAuthor());
-OUString sAuthor;
-
 for (const beans::PropertyValue& rValue : rArguments)
 {
 if (rValue.Name == ".uno:HideWhitespace" && rValue.Value.has())
@@ -3581,9 +3578,8 @@ void SwXTextDocument::initializeForTiledRendering(const 
css::uno::Sequence());
 else if (rValue.Name == ".uno:Author" && rValue.Value.has())
 {
-sAuthor = rValue.Value.get();
 // Store the author name in the view.
-pView->SetRedlineAuthor(sAuthor);
+pView->SetRedlineAuthor(rValue.Value.get());
 // Let the actual author name pick up the value from the current
 // view, which would normally happen only during the next view
 // switch.
@@ -3593,16 +3589,6 @@ void SwXTextDocument::initializeForTiledRendering(const 
css::uno::Sequence());
 }
 
-if (!sAuthor.isEmpty() && sAuthor != sOrigAuthor)
-{
-SwView* pFirstView = static_cast(SfxViewShell::GetFirst());
-if (pFirstView && SfxViewShell::GetNext(*pFirstView) == nullptr)
-{
-if (SwViewShell* pShell = >GetWrtShell())
-pShell->UpdateFields(true);
-}
-}
-
 // Set the initial zoom value to 1; usually it is set in setClientZoom and
 // SwViewShell::PaintTile; zoom value is used for chart in place
 // editing, see postMouseEvent and setGraphicSelection methods.


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-01-11 Thread Dennis Francis (via logerrit)
 sw/qa/extras/tiledrendering/data/savedauthorfield.odt |binary
 sw/qa/extras/tiledrendering/tiledrendering.cxx|   16 
 sw/source/uibase/uno/unotxdoc.cxx |   16 +++-
 3 files changed, 31 insertions(+), 1 deletion(-)

New commits:
commit c33e60dd5d5aa8dd585afc9498f87d17ab22fb27
Author: Dennis Francis 
AuthorDate: Mon Jan 9 14:14:02 2023 +0530
Commit: Miklos Vajna 
CommitDate: Thu Jan 12 07:22:05 2023 +

sw: lok: use redline author for saved author fields

Without the fix author fields will expand to "Unknown author" when
loading files which have author fields in them. But only update the
fields when the first view joins and not for later view joins.

Change-Id: I4ac3b25349b8057812c45dc8148f8b3fc3b7ca1e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145192
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/tiledrendering/data/savedauthorfield.odt 
b/sw/qa/extras/tiledrendering/data/savedauthorfield.odt
new file mode 100644
index ..a060c5892f12
Binary files /dev/null and 
b/sw/qa/extras/tiledrendering/data/savedauthorfield.odt differ
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 88b4dcc95d7f..3330e419dc8b 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -3791,6 +3791,22 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, 
testAuthorField)
 assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/Special[1]", "rText", 
sAuthor);
 }
 
+CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testSavedAuthorField)
+{
+SwXTextDocument* pXTextDocument = createDoc("savedauthorfield.odt");
+const OUString sAuthor("XYZ ABCD");
+uno::Sequence 
aPropertyValues1(comphelper::InitPropertySequence(
+{
+{".uno:Author", uno::makeAny(sAuthor)},
+}));
+pXTextDocument->initializeForTiledRendering(aPropertyValues1);
+
+Scheduler::ProcessEventsToIdle();
+
+xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/Special[1]", "rText", 
sAuthor);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uno/unotxdoc.cxx 
b/sw/source/uibase/uno/unotxdoc.cxx
index f91fe5626f1b..05bddd1f5747 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3570,6 +3570,9 @@ void SwXTextDocument::initializeForTiledRendering(const 
css::uno::SequenceGetRedlineAuthor(SW_MOD()->GetRedlineAuthor());
+OUString sAuthor;
+
 for (const beans::PropertyValue& rValue : rArguments)
 {
 if (rValue.Name == ".uno:HideWhitespace" && rValue.Value.has())
@@ -3578,8 +3581,9 @@ void SwXTextDocument::initializeForTiledRendering(const 
css::uno::Sequence());
 else if (rValue.Name == ".uno:Author" && rValue.Value.has())
 {
+sAuthor = rValue.Value.get();
 // Store the author name in the view.
-pView->SetRedlineAuthor(rValue.Value.get());
+pView->SetRedlineAuthor(sAuthor);
 // Let the actual author name pick up the value from the current
 // view, which would normally happen only during the next view
 // switch.
@@ -3589,6 +3593,16 @@ void SwXTextDocument::initializeForTiledRendering(const 
css::uno::Sequence());
 }
 
+if (!sAuthor.isEmpty() && sAuthor != sOrigAuthor)
+{
+SwView* pFirstView = static_cast(SfxViewShell::GetFirst());
+if (pFirstView && SfxViewShell::GetNext(*pFirstView) == nullptr)
+{
+if (SwViewShell* pShell = >GetWrtShell())
+pShell->UpdateFields(true);
+}
+}
+
 // Set the initial zoom value to 1; usually it is set in setClientZoom and
 // SwViewShell::PaintTile; zoom value is used for chart in place
 // editing, see postMouseEvent and setGraphicSelection methods.


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-01-11 Thread Miklos Vajna (via logerrit)
 sw/qa/uibase/uno/uno.cxx  |   28 ++
 sw/source/uibase/uno/loktxdoc.cxx |   40 --
 2 files changed, 66 insertions(+), 2 deletions(-)

New commits:
commit ca4f51aad22809d94ecb9e7e8f53227171dea79f
Author: Miklos Vajna 
AuthorDate: Mon Jan 9 13:53:35 2023 +0100
Commit: Miklos Vajna 
CommitDate: Wed Jan 11 12:46:15 2023 +

sw, lok: implement a getCommandValues(Sections)

There was no LOK API to get a list of all sections where the name
matches a certain prefix.

This is useful in case the API client wants to know what previously
inserted sections were deleted by the user as part of deleting text
content.

Add a new getCommandValues(".uno:Sections") that returns the names of
matching sections. Do not return the section text, assuming that would
be updated by the API client anyway.

In practice this is needed by Zotero in case it wants to model its
bibliography items with sections.

(cherry picked from commit 2ddd41b420cea7f1b988f0b8acbca564b2811382)

Change-Id: If4f02d2a27f2328020934b319d30561aeaaf6612
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145279
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Justin Luth 

diff --git a/sw/qa/uibase/uno/uno.cxx b/sw/qa/uibase/uno/uno.cxx
index 26e912fcfb2b..300278717664 100644
--- a/sw/qa/uibase/uno/uno.cxx
+++ b/sw/qa/uibase/uno/uno.cxx
@@ -308,6 +308,34 @@ CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetTextFormField)
  field.get("command"));
 }
 
+CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetSections)
+{
+// Given a document with a section:
+createSwDoc();
+uno::Sequence aArgs = {
+comphelper::makePropertyValue(
+"RegionName", uno::Any(OUString("ZOTERO_BIBL {} CSL_BIBLIOGRAPHY 
RNDRfiit6mXBc"))),
+comphelper::makePropertyValue("Content", 
uno::Any(OUString("aaabbb"))),
+};
+dispatchCommand(mxComponent, ".uno:InsertSection", aArgs);
+
+// When asking for a list of section names:
+tools::JsonWriter aJsonWriter;
+OString aCommand(".uno:Sections?namePrefix=ZOTERO_BIBL");
+auto pXTextDocument = dynamic_cast(mxComponent.get());
+pXTextDocument->getCommandValues(aJsonWriter, aCommand);
+
+// Make sure we find our just inserted section:
+std::unique_ptr 
pJSON(aJsonWriter.extractData());
+std::stringstream aStream(pJSON.get());
+boost::property_tree::ptree aTree;
+boost::property_tree::read_json(aStream, aTree);
+// Without the accompanying fix in place, this test would have failed with:
+// - No such node (sections)
+// i.e. the returned JSON was an empty object.
+CPPUNIT_ASSERT_EQUAL(static_cast(1), 
aTree.get_child("sections").count(""));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uno/loktxdoc.cxx 
b/sw/source/uibase/uno/loktxdoc.cxx
index d1b31238dff8..30722fb6af69 100644
--- a/sw/source/uibase/uno/loktxdoc.cxx
+++ b/sw/source/uibase/uno/loktxdoc.cxx
@@ -292,13 +292,44 @@ void GetFields(tools::JsonWriter& rJsonWriter, 
SwDocShell* pDocShell,
 rJsonWriter.put("name", pRefMark->GetRefName());
 }
 }
+
+/// Implements getCommandValues(".uno:Sections").
+///
+/// Parameters:
+///
+/// - namePrefix: field name prefix to not return all sections
+void GetSections(tools::JsonWriter& rJsonWriter, SwDocShell* pDocShell,
+ const std::map& rArguments)
+{
+OUString aNamePrefix;
+{
+auto it = rArguments.find("namePrefix");
+if (it != rArguments.end())
+{
+aNamePrefix = it->second;
+}
+}
+
+SwDoc* pDoc = pDocShell->GetDoc();
+tools::ScopedJsonWriterArray aBookmarks = 
rJsonWriter.startArray("sections");
+for (const auto& pSection : pDoc->GetSections())
+{
+if (!pSection->GetName().startsWith(aNamePrefix))
+{
+continue;
+}
+
+tools::ScopedJsonWriterStruct aProperty = rJsonWriter.startStruct();
+rJsonWriter.put("name", pSection->GetName());
+}
+}
 }
 
 bool SwXTextDocument::supportsCommandValues(const OUString& rCommand)
 {
 static const std::initializer_list vForward
-= { u"TextFormFields", u"TextFormField", u"SetDocumentProperties", 
u"Bookmarks",
-u"Fields" };
+= { u"TextFormFields", u"TextFormField", u"SetDocumentProperties",
+u"Bookmarks",  u"Fields",u"Sections" };
 
 return std::find(vForward.begin(), vForward.end(), rCommand) != 
vForward.end();
 }
@@ -312,6 +343,7 @@ void SwXTextDocument::getCommandValues(tools::JsonWriter& 
rJsonWriter, const OSt
 static constexpr OStringLiteral 
aSetDocumentProperties(".uno:SetDocumentProperties");
 static constexpr OStringLiteral aBookmarks(".uno:Bookmarks");
 static constexpr OStringLiteral aFields(".uno:Fields");
+static constexpr 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-01-10 Thread Miklos Vajna (via logerrit)
 sw/qa/uibase/shells/shells.cxx  |9 +++--
 sw/source/uibase/shells/textsh1.cxx |2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

New commits:
commit 1f0d6c660c799900cfda070f7319c8e0cdde41f5
Author: Miklos Vajna 
AuthorDate: Mon Jan 9 16:27:15 2023 +0100
Commit: Pranam Lashkari 
CommitDate: Wed Jan 11 01:11:19 2023 +

sw, UpdateBookmarks: support renaming bookmarks

The problem was that the LOK API client wanted to change the name of the
bookmark, but nothing happened, because we had a sanity check that made
sure the provided vs existing bookmark names match.

The intention was that the bookmark name is just an ID (you can store
additional properties in per-doc custom properties, those can change),
so we can require that bookmarks never get renamed when using this
command.

Fix the problem by dropping this requirement and rather use renameMark()
to adjust the in-doc bookmark name if needed.

This also handles undo/redo for us.

(cherry picked from commit d2318503d559c3797965da777627e4ee45143043)

Change-Id: I7a426c865ddf24f13741c0369fb3991da2e881b2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145280
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Pranam Lashkari 

diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index 794932e8cf25..33f0d615b250 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -405,7 +405,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testUpdateBookmarks)
 {
 "Bookmark": {
 "type": "string",
-"value": "ZOTERO_BREF_GiQ7DAWQYWLy"
+"value": "ZOTERO_BREF_new1"
 },
 "BookmarkText": {
 "type": "string",
@@ -415,7 +415,7 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testUpdateBookmarks)
 {
 "Bookmark": {
 "type": "string",
-"value": "ZOTERO_BREF_PRxDGUb4SWXF"
+"value": "ZOTERO_BREF_new2"
 },
 "BookmarkText": {
 "type": "string",
@@ -437,6 +437,11 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testUpdateBookmarks)
 // - Actual  : ABCDE
 // i.e. the content was not updated.
 CPPUNIT_ASSERT_EQUAL(OUString("Anew result 1Cnew result 2E"), aActual);
+
+// Without the accompanying fix in place, this test would have failed, 
ZOTERO_BREF_GiQ7DAWQYWLy
+// was not renamed to ZOTERO_BREF_new1.
+auto it = pDoc->getIDocumentMarkAccess()->findMark("ZOTERO_BREF_new1");
+CPPUNIT_ASSERT(it != pDoc->getIDocumentMarkAccess()->getAllMarksEnd());
 }
 
 CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertFieldmarkReadonly)
diff --git a/sw/source/uibase/shells/textsh1.cxx 
b/sw/source/uibase/shells/textsh1.cxx
index 4641aede858f..2acf9b037602 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -425,7 +425,7 @@ void UpdateBookmarks(SfxRequest& rReq, SwWrtShell& rWrtSh)
 comphelper::SequenceAsHashMap aMap(aBookmarks[nBookmarkIndex++]);
 if (aMap["Bookmark"].get() != pMark->GetName())
 {
-continue;
+rIDMA.renameMark(pMark, aMap["Bookmark"].get());
 }
 
 OUString aBookmarkText = aMap["BookmarkText"].get();


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-01-10 Thread Pranam Lashkari (via logerrit)
 sw/qa/uibase/uno/uno.cxx  |5 +++--
 sw/source/uibase/uno/loktxdoc.cxx |1 +
 2 files changed, 4 insertions(+), 2 deletions(-)

New commits:
commit 10eb0e5258cf1c07878be0bf995dbf29f4d4ae06
Author: Pranam Lashkari 
AuthorDate: Tue Jan 10 11:24:56 2023 +0530
Commit: Pranam Lashkari 
CommitDate: Tue Jan 10 20:36:35 2023 +

sw: return field under cursor inside field node

Having values inside field node makes it easier to detect which commands 
value
is being returned in online. otherwise its impossible to predict the 
command from "type" and "command"
as "command" can be anything and "type" is very generic

this also makes output more consistent with "GetTextFormFields"

Signed-off-by: Pranam Lashkari 
Change-Id: I1b8b39bfd0de6d7b19c2944bd42f7031d60518af
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145248
Tested-by: Jenkins CollaboraOffice 

diff --git a/sw/qa/uibase/uno/uno.cxx b/sw/qa/uibase/uno/uno.cxx
index f24137e482a2..26e912fcfb2b 100644
--- a/sw/qa/uibase/uno/uno.cxx
+++ b/sw/qa/uibase/uno/uno.cxx
@@ -301,10 +301,11 @@ CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, 
testGetTextFormField)
 // Without the accompanying fix in place, this test would have failed with:
 // - No such node (type)
 // i.e. the returned JSON was just an empty object.
+auto field = aTree.get_child("field");
 CPPUNIT_ASSERT_EQUAL(std::string("vnd.oasis.opendocument.field.UNHANDLED"),
- aTree.get("type"));
+ field.get("type"));
 CPPUNIT_ASSERT_EQUAL(std::string("ADDIN ZOTERO_ITEM foo bar"),
- aTree.get("command"));
+ field.get("command"));
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/uibase/uno/loktxdoc.cxx 
b/sw/source/uibase/uno/loktxdoc.cxx
index c8e50206e55a..d1b31238dff8 100644
--- a/sw/source/uibase/uno/loktxdoc.cxx
+++ b/sw/source/uibase/uno/loktxdoc.cxx
@@ -126,6 +126,7 @@ void GetTextFormField(tools::JsonWriter& rJsonWriter, 
SwDocShell* pDocShell,
 SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
 SwPosition& rCursor = *pWrtShell->GetCursor()->GetPoint();
 sw::mark::IFieldmark* pFieldmark = rIDMA.getFieldmarkFor(rCursor);
+auto typeNode = rJsonWriter.startNode("field");
 if (!pFieldmark)
 {
 return;


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-01-06 Thread offtkp (via logerrit)
 sw/qa/uibase/wrtsh/wrtsh.cxx  |7 +++
 sw/source/core/txtnode/attrcontentcontrol.cxx |1 -
 sw/source/uibase/wrtsh/wrtsh1.cxx |   14 ++
 sw/source/uibase/wrtsh/wrtsh3.cxx |4 
 4 files changed, 21 insertions(+), 5 deletions(-)

New commits:
commit 06ff1602842197f045f953fd49e441f8f058d094
Author: offtkp 
AuthorDate: Mon Dec 12 13:03:43 2022 +0200
Commit: Tomaž Vajngerl 
CommitDate: Fri Jan 6 14:59:23 2023 +

docx: Do not remove showingPlcHdr until edit

When a placeholder has the showingPlcHdr attribute, the entire text is
selected upon click. This is no longer removed by selecting it once but
once the text has been edited.

Change-Id: I9a4d68289c8b95ab0098e55a5fa6edb1606c7df2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143985
Tested-by: Jenkins
Reviewed-by: Miklos Vajna 
(cherry picked from commit 618cef756b87f9816d0dcbe04af163ccd06a986e)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144307
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Tomaž Vajngerl 

diff --git a/sw/qa/uibase/wrtsh/wrtsh.cxx b/sw/qa/uibase/wrtsh/wrtsh.cxx
index cbc31237d893..43fb355fa59b 100644
--- a/sw/qa/uibase/wrtsh/wrtsh.cxx
+++ b/sw/qa/uibase/wrtsh/wrtsh.cxx
@@ -387,6 +387,13 @@ CPPUNIT_TEST_FIXTURE(Test, 
testInsertPlainTextContentControl)
 // Without the accompanying fix in place, this test would have failed, 
there was no special
 // handling for plain text content controls.
 CPPUNIT_ASSERT(pContentControl->GetPlainText());
+
+CPPUNIT_ASSERT(pContentControl->GetShowingPlaceHolder());
+pWrtShell->GotoContentControl(rFormatContentControl);
+CPPUNIT_ASSERT(pContentControl->GetShowingPlaceHolder());
+pWrtShell->Insert("Foo");
+// No longer showing placeholder text, as it has been changed
+CPPUNIT_ASSERT(!pContentControl->GetShowingPlaceHolder());
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testInsertComboBoxContentControl)
diff --git a/sw/source/core/txtnode/attrcontentcontrol.cxx 
b/sw/source/core/txtnode/attrcontentcontrol.cxx
index d324f52513a5..a54d4ef83429 100644
--- a/sw/source/core/txtnode/attrcontentcontrol.cxx
+++ b/sw/source/core/txtnode/attrcontentcontrol.cxx
@@ -754,7 +754,6 @@ void SwTextContentControl::Invalidate()
 pDocShell->GetWrtShell()->Push();
 
 // visit the control in the text (which makes any necessary visual changes)
-// NOTE: simply going to a control indicates cancelling 
ShowingPlaceHolder, unless bOnlyRefresh
 // NOTE: simply going to a checkbox causes a toggle, unless bOnlyRefresh
 auto& rFormatContentControl = 
static_cast(GetAttr());
 pDocShell->GetWrtShell()->GotoContentControl(rFormatContentControl, 
/*bOnlyRefresh=*/true);
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx 
b/sw/source/uibase/wrtsh/wrtsh1.cxx
index 4983bb3dc30f..c0112556e9d9 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -116,6 +116,7 @@
 #include 
 #include 
 #include 
+#include 
 
 using namespace sw::mark;
 using namespace com::sun::star;
@@ -261,6 +262,19 @@ void SwWrtShell::Insert( const OUString  )
 bCallIns ?
 SwEditShell::Insert2( rStr, bDeleted ) : SwEditShell::Overwrite( rStr 
);
 
+// Check whether node is content control
+SwTextContentControl* pTextContentControl = CursorInsideContentControl();
+if (pTextContentControl)
+{
+std::shared_ptr pContentControl =
+pTextContentControl->GetContentControl().GetContentControl();
+if (pContentControl)
+{
+// Set showingPlcHdr to false as node has been edited
+pContentControl->SetShowingPlaceHolder(false);
+}
+}
+
 if( bStarted )
 {
 EndUndo();
diff --git a/sw/source/uibase/wrtsh/wrtsh3.cxx 
b/sw/source/uibase/wrtsh/wrtsh3.cxx
index aa170d1374a4..4e80bfc1e3d1 100644
--- a/sw/source/uibase/wrtsh/wrtsh3.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh3.cxx
@@ -125,10 +125,6 @@ bool SwWrtShell::GotoContentControl(const 
SwFormatContentControl& rContentContro
 (this->*m_fnKillSel)(nullptr, false);
 
 bool bRet = SwCursorShell::GotoFormatContentControl(rContentControl);
-// Assume that once the placeholder is selected, the content is no longer 
the placeholder.
-if (!bOnlyRefresh && pContentControl)
-pContentControl->SetShowingPlaceHolder(false);
-
 
 if (bRet && pContentControl && pContentControl->GetCheckbox())
 {


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-01-04 Thread Andras Timar (via logerrit)
 sw/qa/extras/htmlimport/data/green-highlight.html |1 
 sw/qa/extras/htmlimport/htmlimport.cxx|   12 ++
 sw/source/filter/html/parcss1.cxx |   26 +++---
 3 files changed, 36 insertions(+), 3 deletions(-)

New commits:
commit 81c6e01e5ba9d46963ae3323804ab8379b864cc3
Author: Andras Timar 
AuthorDate: Wed Jan 4 14:34:49 2023 +0100
Commit: Andras Timar 
CommitDate: Wed Jan 4 18:17:54 2023 +

import colors with transparency from html

The support is limited, but better than before.
Before: the color was not imported.
After: the color is imported as RGB, as if the background color was white.
It is pretty much common in Writer that the background is white. On the
other hand, transparency is not supported in many use cases, such as
character background in this example green-highlight.html.

Change-Id: Ia9449e2535ddfd8cd8c2672cb3bd32987083fdbb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145041
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Andras Timar 

diff --git a/sw/qa/extras/htmlimport/data/green-highlight.html 
b/sw/qa/extras/htmlimport/data/green-highlight.html
new file mode 100644
index ..b8986e78ffd8
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/green-highlight.html
@@ -0,0 +1 @@
+Highlight green (transparency: 
0.5)
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx 
b/sw/qa/extras/htmlimport/htmlimport.cxx
index 00e2ec99191f..e4547d02a008 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -536,6 +536,18 @@ CPPUNIT_TEST_FIXTURE(HtmlImportTest, testUTF16_nonBMP)
  getParagraph(1)->getString());
 }
 
+CPPUNIT_TEST_FIXTURE(HtmlImportTest, testRGBAColor)
+{
+load(mpTestDocumentPath, "green-highlight.html");
+const uno::Reference xPara = getParagraph(1);
+const uno::Reference xRun(getRun(xPara,1), 
uno::UNO_QUERY);
+const Color nBackColor(0xaed89a);
+
+// Without the accompanying fix in place, this test would have failed, the 
backround
+// color was not imported at all, when it was in hex RGBA format in HTML.
+CPPUNIT_ASSERT_EQUAL(nBackColor, getProperty(xRun, 
"CharBackColor"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/parcss1.cxx 
b/sw/source/filter/html/parcss1.cxx
index e0b20ef4168e..518604bc1bc5 100644
--- a/sw/source/filter/html/parcss1.cxx
+++ b/sw/source/filter/html/parcss1.cxx
@@ -529,11 +529,11 @@ CSS1Token CSS1Parser::GetNextToken()
 bool bEOFSave = m_bEOF;
 
 // first try to parse a hex digit
-OUStringBuffer sTmpBuffer(6);
+OUStringBuffer sTmpBuffer(8);
 do {
 sTmpBuffer.append( m_cNextCh );
 m_cNextCh = GetNextChar();
-} while( sTmpBuffer.getLength() < 7 &&
+} while( sTmpBuffer.getLength() < 9 &&
  ( ('0'<=m_cNextCh && '9'>=m_cNextCh) ||
('A'<=m_cNextCh && 'F'>=m_cNextCh) ||
('a'<=m_cNextCh && 'f'>=m_cNextCh) ) &&
@@ -541,7 +541,7 @@ CSS1Token CSS1Parser::GetNextToken()
 
 if( sTmpBuffer.getLength()==6 || sTmpBuffer.getLength()==3 )
 {
-// we found a color in hex
+// we found a color in hex (RGB)
 m_aToken += sTmpBuffer;
 nRet = CSS1_HEXCOLOR;
 bNextCh = false;
@@ -549,6 +549,26 @@ CSS1Token CSS1Parser::GetNextToken()
 break;
 }
 
+if( sTmpBuffer.getLength()==8 )
+{
+// we found a color in hex (RGBA)
+// we convert it to RGB assuming white background
+sal_uInt32 nColor = 
sTmpBuffer.makeStringAndClear().toUInt32(16);
+sal_uInt32 nRed = (nColor & 0xff00) >> 24;
+sal_uInt32 nGreen = (nColor & 0xff) >> 16;
+sal_uInt32 nBlue = (nColor & 0xff00) >> 8;
+double nAlpha = (nColor & 0xff) / 255.0;
+nRed = (1 - nAlpha) * 255 + nAlpha * nRed;
+nGreen = (1 - nAlpha) * 255 + nAlpha * nGreen;
+nBlue = (1 - nAlpha) * 255 + nAlpha * nBlue;
+nColor = (nRed << 16) + (nGreen << 8) + nBlue;
+m_aToken += OUString::number(nColor, 16);
+nRet = CSS1_HEXCOLOR;
+bNextCh = false;
+
+break;
+}
+
 // otherwise we try a number
 m_nInPos = nInPosSave;
 m_cNextCh = cNextChSave;


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-01-03 Thread Justin Luth (via logerrit)
 sw/qa/extras/ooxmlexport/data/tdf152636_lostPageBreak2.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport18.cxx  |6 ++
 sw/source/filter/ww8/wrtw8sty.cxx   |   11 +++
 3 files changed, 13 insertions(+), 4 deletions(-)

New commits:
commit 8079fc1cc94383b3345b6dfce8346e8c1f1c60fa
Author: Justin Luth 
AuthorDate: Thu Dec 22 17:50:46 2022 -0500
Commit: Miklos Vajna 
CommitDate: Tue Jan 3 12:40:56 2023 +

tdf#152636 writerfilter: handle breakcode on table page break

We always have to handle two situations when dealing with
page breaks - paragraphs and tables.

Change-Id: Ie0347d70f9529ca2e846c4a5041e76da9bd03e30
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144778
Tested-by: Jenkins
Reviewed-by: Justin Luth 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144823
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/ooxmlexport/data/tdf152636_lostPageBreak2.docx 
b/sw/qa/extras/ooxmlexport/data/tdf152636_lostPageBreak2.docx
new file mode 100644
index ..255bf795a5e2
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf152636_lostPageBreak2.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
index a77e2ec98ca4..03d02ff7b725 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx
@@ -63,6 +63,12 @@ CPPUNIT_TEST_FIXTURE(Test, testInlineSdtHeader)
 loadAndSave("inline-sdt-header.docx");
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf152636_lostPageBreak2)
+{
+loadAndReload("tdf152636_lostPageBreak2.docx");
+CPPUNIT_ASSERT_EQUAL(2, getPages());
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testSdtDuplicatedId)
 {
 // Given a document with 2 inline , with each a :
diff --git a/sw/source/filter/ww8/wrtw8sty.cxx 
b/sw/source/filter/ww8/wrtw8sty.cxx
index cfce4172ce86..a36de19cbb2f 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -1648,12 +1648,15 @@ void MSWordExportBase::SectionProperties( const 
WW8_SepInfo& rSepInfo, WW8_PdAtt
 //  0xfff -> Section terminated
 nBreakCode = 0; // consecutive section
 
-if ( rSepInfo.pPDNd && rSepInfo.pPDNd->IsContentNode() )
+if (rSepInfo.pPDNd && (rSepInfo.pPDNd->IsContentNode() || 
rSepInfo.pPDNd->IsTableNode()))
 {
-if ( !NoPageBreakSection( 
>GetContentNode()->GetSwAttrSet() ) )
-{
+const SfxItemSet* pSet
+= rSepInfo.pPDNd->IsContentNode()
+  ? >GetContentNode()->GetSwAttrSet()
+  : 
>GetTableNode()->GetTable().GetFrameFormat()->GetAttrSet();
+
+if (!NoPageBreakSection(pSet))
 nBreakCode = 2;
-}
 }
 
 if ( reinterpret_cast(sal_IntPtr(-1)) == 
rSepInfo.pSectionFormat )


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-01-03 Thread Miklos Vajna (via logerrit)
 sw/qa/core/unocore/data/paragraph-marker.docx |binary
 sw/qa/core/unocore/unocore.cxx|   19 
 sw/qa/extras/ooxmlexport/ooxmlexport2.cxx |3 -
 sw/source/core/inc/unoport.hxx|7 ++-
 sw/source/core/unocore/unoobj.cxx |7 ++-
 sw/source/core/unocore/unoport.cxx|   57 ++
 sw/source/core/unocore/unoportenum.cxx|5 ++
 7 files changed, 86 insertions(+), 12 deletions(-)

New commits:
commit e48bf9b364c520eb68f9a3f962dc640eaa9e6661
Author: Miklos Vajna 
AuthorDate: Mon Dec 19 08:47:18 2022 +0100
Commit: Miklos Vajna 
CommitDate: Tue Jan 3 12:36:53 2023 +

sw: ODT import/export of DOCX's paragraph marker formatting

The bugdoc had a numbering, where the paragraph marker was explicitly
formatted to a custom sans font, and this font is also used for the 
numbering
portion's font. This was imported from DOCX correctly, but once you save
to ODT and reload, the font used in the numbering portion changed from
sans to serif, which is incorrect.

The reason for this seems to be that earlier
5ba30f588d6e41a13d68b1461345fca7a7ca61ac (tdf#64222 sw: better DOCX
import/export of paragraph marker formatting, 2019-09-06) introduced
support for storing this paragraph marker formatting in
RES_PARATR_LIST_AUTOFMT, but this was lost on ODT export / import.

Fix the problem by 1) adding the autostyle to the autostyle pool, so the
font gets written when writing automatic char styles 2) extending
SwXTextPortion to have a mode where it exposes the
RES_PARATR_LIST_AUTOFMT of the current text node and 3) improving
lcl_CreatePortions() to expose a trailing empty text portion that works
with these properties.

This also required adjusting CppunitTest_sw_ooxmlexport2's
testFdo64238_b, which explicitly asserted that the format of the
paragraph marker is not exposed in the UNO API text portion enumeration.
An additional improvement would be to go with a more explicit markup in
the ODT output for RES_PARATR_LIST_AUTOFMT, but we would need to decide
what name to use there, since currently we call this paragraph marker
formatting RES_PARATR_LIST_AUTOFMT / ListAutoFormat, and somewhat
confusingly this is primarily about paragraph marker formatting, not
lists / numberings (that is just a consequence).

Change-Id: I19c7eed19c6fc85c251ef87a5181c0719a0a382c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/17
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins
(cherry picked from commit 6249858a8972aef077e0249bd93cfe8f01bce4d6)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144491
Reviewed-by: Xisco Fauli 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144675
Reviewed-by: Mike Kaganski 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144960
Tested-by: Miklos Vajna 

diff --git a/sw/qa/core/unocore/data/paragraph-marker.docx 
b/sw/qa/core/unocore/data/paragraph-marker.docx
new file mode 100644
index ..8dac2d96c76d
Binary files /dev/null and b/sw/qa/core/unocore/data/paragraph-marker.docx 
differ
diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx
index e26e227b059b..58723f829439 100644
--- a/sw/qa/core/unocore/unocore.cxx
+++ b/sw/qa/core/unocore/unocore.cxx
@@ -762,6 +762,25 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, 
testContentControls)
 CPPUNIT_ASSERT_EQUAL(OUString("tag2"), aTag);
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testParagraphMarkerODFExport)
+{
+// Given a document with a red numbering portion, from the paragraph 
marker's format:
+load(DATA_DIRECTORY, "paragraph-marker.docx");
+
+// When saving that as ODT + reload:
+reload("writer8", nullptr);
+
+// Then make sure that it still has the correct color:
+xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 00ff (COL_LIGHTRED)
+// - Actual  :  (COL_AUTO)
+// i.e. the custom "red" color was lost as RES_PARATR_LIST_AUTOFMT was not 
serialized to ODT.
+CPPUNIT_ASSERT_EQUAL(
+OUString("00ff"),
+getXPath(pXmlDoc, "//Special[@nType='PortionType::Number']/SwFont", 
"color"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
index 7e4cce4ce6de..a14b0473ae08 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
@@ -854,7 +854,8 @@ DECLARE_OOXMLEXPORT_TEST(testFdo64238_b, "fdo64238_b.docx")
 xRunEnum->nextElement();
 numOfRuns++;
 }
-CPPUNIT_ASSERT_EQUAL(sal_Int32(5), numOfRuns);
+// "This is the ", "ODD", " [", "LEFT", "] header" and the colored 
paragraph marker
+

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2023-01-02 Thread Miklos Vajna (via logerrit)
 sw/qa/core/text/data/number-portion-format.odt  |binary
 sw/qa/core/text/data/number-portion-noformat.docx   |binary
 sw/qa/core/text/text.cxx|   18 ++
 sw/qa/extras/ooxmlexport/data/number-portion-format.odt |binary
 sw/qa/extras/ooxmlexport/ooxmlexport13.cxx  |6 
 sw/source/core/text/txtfld.cxx  |   10 
 sw/source/core/unocore/unoportenum.cxx  |   20 
 sw/source/filter/ww8/docxattributeoutput.cxx|2 -
 sw/source/filter/ww8/wrtw8nds.cxx   |   15 +---
 9 files changed, 51 insertions(+), 20 deletions(-)

New commits:
commit 55906cca53315c1dd0018405f64ac386da3b6c2d
Author: Miklos Vajna 
AuthorDate: Fri Dec 16 10:31:03 2022 +0100
Commit: Miklos Vajna 
CommitDate: Tue Jan 3 07:01:46 2023 +

sw, numbering portion format: ignore char formats covering the entire 
paragraph

The bugdoc has a single paragraph, where the numbering portion is bold
in Writer but not in Word.

The reason for this appears to be that Writer considers text node hints
for the formatting of the numbering portion where the hint covers the
entire paragraph, but Word doesn't do this. This behavior was added in
commits cb0e1b52d68aa6d5b505f91cb4ce577f7f3b2a8f (sw, numbering portion
format: consider full-para char formats as well, 2022-10-20) and DOCX
export was also adjusted in commit
f546f7573158e52359bbeae6194a83a1ff8ac52c (DOCX export, numbering portion
format: consider full-para char formats as well, 2022-10-28).

Fix the problem by partially reverting the above two commits and instead
only consider hints that both start and end at the paragraph end. The
revert of the first commit fixes the new bugdoc (its numbering portion
is no longer bold) and the old bugdoc keeps working if the sw UNO API's
text portion enumeration is extended to expose such empty autoformats at
paragraph end.

Related testcases:

- CppunitTest_sw_ooxmlexport13's testTdf123460 explicitly tested that we
  don't expose the paragraph marker's formatting on the UNO API.

- CppunitTest_sw_core_text's testNumberPortionFormat now uses the new
  ODT markup for these explicit paragraph marker char props (empty text
  span at para end).

- CppunitTest_sw_uiwriter2's testTdfChangeNumberingListAutoFormat failed
  when only the above first commit (layout) was reverted, so revert the
  matching DOCX export commit as well, which is also good for consistency.

- CppunitTest_sw_ooxmlexport18's testNumberPortionFormatFromODT also
  used the old ODT markup, updated.

(cherry picked from commit 99ed51bcad4008a4006dcec24aa33fd7f757a433)

Change-Id: Iee8acf72dabcd10b3f4d3d68b83ed248bf50c324
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144674
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144959
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/text/data/number-portion-format.odt 
b/sw/qa/core/text/data/number-portion-format.odt
index 3047153b63af..19b23ae84420 100644
Binary files a/sw/qa/core/text/data/number-portion-format.odt and 
b/sw/qa/core/text/data/number-portion-format.odt differ
diff --git a/sw/qa/core/text/data/number-portion-noformat.docx 
b/sw/qa/core/text/data/number-portion-noformat.docx
new file mode 100644
index ..b289b9c69ef4
Binary files /dev/null and b/sw/qa/core/text/data/number-portion-noformat.docx 
differ
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index 0bcd850073e9..38f984661ec5 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -751,6 +751,24 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, 
testNumberPortionFormat)
 assertXPath(pXmlDoc, "//Special[@nType='PortionType::Number']", "nHeight", 
"480");
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testNumberPortionNoformat)
+{
+// Given a document with a numbering and a single paragraph, the entire 
run is red:
+createSwDoc(DATA_DIRECTORY, "number-portion-noformat.docx");
+
+// When laying out that document:
+xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+
+// Then make sure that just because the entire run is red, the numbering 
portion is not red:
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected:  (COL_AUTO)
+// - Actual  : 00ff (COL_LIGHTRED)
+// i.e. the run color affected the color of the number portion in Writer, 
but not in Word.
+CPPUNIT_ASSERT_EQUAL(
+OUString(""),
+getXPath(pXmlDoc, "//Special[@nType='PortionType::Number']/SwFont", 
"color"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source writerfilter/source

2022-12-20 Thread Justin Luth (via logerrit)
 sw/qa/extras/ooxmlexport/ooxmlexport17.cxx   |6 ++
 sw/qa/extras/ooxmlexport/ooxmlexport3.cxx|4 
 sw/source/filter/ww8/docxattributeoutput.cxx |   10 ++
 sw/source/filter/ww8/docxattributeoutput.hxx |2 ++
 writerfilter/source/dmapper/DomainMapper.cxx |   20 +++-
 5 files changed, 37 insertions(+), 5 deletions(-)

New commits:
commit 529cf56d77c391ef6083808e383b171e3d70980e
Author: Justin Luth 
AuthorDate: Wed Dec 7 13:44:01 2022 -0500
Commit: Miklos Vajna 
CommitDate: Wed Dec 21 07:56:12 2022 +

tdf#149240 docx content controls: round-trip showingPlcHdr better

ShowingPlaceHolder causes all the text in the control to be
selected when the control gains the focus. Otherwise, just a
cursor is placed at the click point.

While round-tripping this attribute worked for inline SDTs,
it was lost for block SDTs. But BlockSDTs are very easy
to create. The MS templates are full of them.

Also, these are boolean, but it could have a val=0 specified,
in which case it is off, but we were importing it as on.

Change-Id: I167afa935311a63bba408ecd489ae819485a5cb7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143818
Tested-by: Jenkins
Reviewed-by: Justin Luth 
Reviewed-by: Miklos Vajna 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144621
Tested-by: Jenkins CollaboraOffice 

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index 63fda18c23f3..bb7f3d9458b6 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -496,6 +496,12 @@ DECLARE_OOXMLEXPORT_TEST(testTdf148111, "tdf148111.docx")
 
 // No more fields
 CPPUNIT_ASSERT(!xFields->hasMoreElements());
+
+if (!mbExported)
+return;
+xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+// ShowingPlaceholder should be off for 0, false and "on". (This was 21 
before the fix)
+assertXPath(pXmlDoc,"//w:p/w:sdt/w:sdtPr/w:showingPlcHdr", 12);
 }
 
 DECLARE_OOXMLEXPORT_TEST(testTdf81507, "tdf81507.docx")
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
index 2d1bc1035d5a..4e8f58f6294b 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
@@ -1013,6 +1013,10 @@ CPPUNIT_TEST_FIXTURE(Test, testGlossaryWithEmail)
 "and 
@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink'
 "
 "and @Target='mailto:emailgoesh...@example.com' "
 "and @TargetMode='External']");
+
+// preserve the ShowingPlaceholder setting on both block SDTs.
+pXmlDoc = parseExport("word/document.xml");
+
assertXPath(pXmlDoc,"/w:document/w:body/w:p/w:sdt/w:sdtPr/w:showingPlcHdr", 2);
 }
 
 DECLARE_OOXMLEXPORT_TEST(testFdo71785, "fdo71785.docx")
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index f2aaefa22440..73d01152dfb5 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -623,6 +623,7 @@ void SdtBlockHelper::DeleteAndResetTheLists()
 m_aPlaceHolderDocPart.clear();
 if (!m_aColor.isEmpty())
 m_aColor.clear();
+m_bShowingPlaceHolder = false;
 m_bHasId = false;
 }
 
@@ -715,6 +716,10 @@ void 
SdtBlockHelper::WriteExtraParams(::sax_fastparser::FSHelperPtr& pSerializer
 pSerializer->singleElementNS(XML_w, XML_docPart, FSNS(XML_w, XML_val), 
m_aPlaceHolderDocPart);
 pSerializer->endElementNS(XML_w, XML_placeholder);
 }
+
+if (m_bShowingPlaceHolder)
+pSerializer->singleElementNS(XML_w, XML_showingPlcHdr);
+
 if (!m_aColor.isEmpty())
 {
 pSerializer->singleElementNS(XML_w15, XML_color, FSNS(XML_w, XML_val), 
m_aColor);
@@ -827,6 +832,11 @@ void SdtBlockHelper::GetSdtParamsFromGrabBag(const 
uno::Sequence>= m_bShowingPlaceHolder))
+SAL_WARN("sw.ww8", "DocxAttributeOutput::GrabBag: unexpected 
sdt ShowingPlcHdr");
+}
 else if (aPropertyValue.Name == "ooxml:CT_SdtPr_alias" && 
m_aAlias.isEmpty())
 {
 if (!(aPropertyValue.Value >>= m_aAlias))
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx 
b/sw/source/filter/ww8/docxattributeoutput.hxx
index f61b4576a941..8191cfb523cf 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -130,6 +130,7 @@ public:
 SdtBlockHelper()
 : m_bHasId(false)
 , m_bStartedSdt(false)
+, m_bShowingPlaceHolder(false)
 , m_nSdtPrToken(0)
 {}
 
@@ -141,6 +142,7 @@ public:
 rtl::Reference m_pDataBindingAttrs;
 OUString m_aColor;
 OUString m_aPlaceHolderDocPart;
+bool m_bShowingPlaceHolder;
 OUString m_aAlias;
 OUString m_aTag;
 OUString m_aLock;
diff --git 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-12-05 Thread Dennis Francis (via logerrit)
 sw/qa/extras/tiledrendering/tiledrendering.cxx |   41 +
 sw/source/core/fields/docufld.cxx  |   11 ++
 2 files changed, 51 insertions(+), 1 deletion(-)

New commits:
commit 8be4a713e9f44bf05aebc0a3054654a18b4de065
Author: Dennis Francis 
AuthorDate: Thu May 19 15:27:48 2022 +0530
Commit: Miklos Vajna 
CommitDate: Mon Dec 5 11:08:52 2022 +

sw: prefer view's redline author name...

to expand SwAuthorFieldType. Redline author name is set in
SwXTextDocument::initializeForTiledRendering each time a new view is
created.

Change-Id: I316e0cae4399796682949de14b6d4b924833eb04
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134608
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143649

diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 28f67f9a8500..88b4dcc95d7f 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -19,6 +19,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 #include 
@@ -3750,6 +3752,45 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, 
testDateContentControl)
 CPPUNIT_ASSERT_EQUAL(OUString("2022-05-30"), 
pTextNode->GetExpandText(pWrtShell->GetLayout()));
 }
 
+CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testAuthorField)
+{
+SwXTextDocument* pXTextDocument = createDoc();
+const OUString sAuthor("Abcd Xyz");
+
+uno::Sequence 
aPropertyValues1(comphelper::InitPropertySequence(
+{
+{".uno:Author", uno::makeAny(sAuthor)},
+}));
+pXTextDocument->initializeForTiledRendering(aPropertyValues1);
+
+auto insertAuthorField = [this]()
+{
+uno::Reference const xMSF(mxComponent, 
uno::UNO_QUERY_THROW);
+uno::Reference const xTD(mxComponent, 
uno::UNO_QUERY_THROW);
+
+auto const xText = xTD->getText();
+auto const xTextCursor = xText->createTextCursor();
+CPPUNIT_ASSERT(xTextCursor.is());
+
+xTextCursor->gotoEnd(false);
+
+uno::Reference const xTextField(
+xMSF->createInstance("com.sun.star.text.textfield.Author"), 
uno::UNO_QUERY_THROW);
+
+uno::Reference xTextFieldProps(xTextField, 
uno::UNO_QUERY_THROW);
+xTextFieldProps->setPropertyValue("FullName", uno::Any(true));
+
+xText->insertTextContent(xTextCursor, xTextField, false);
+};
+
+insertAuthorField();
+Scheduler::ProcessEventsToIdle();
+
+xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+
+assertXPath(pXmlDoc, "/root/page[1]/body/txt[1]/Special[1]", "rText", 
sAuthor);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/fields/docufld.cxx 
b/sw/source/core/fields/docufld.cxx
index a3b5d5a5e12d..0e5777e7bf9e 100644
--- a/sw/source/core/fields/docufld.cxx
+++ b/sw/source/core/fields/docufld.cxx
@@ -314,7 +314,16 @@ OUString SwAuthorFieldType::Expand(sal_uLong nFormat)
 {
 SvtUserOptions&  rOpt = SW_MOD()->GetUserOptions();
 if((nFormat & 0xff) == AF_NAME)
-return rOpt.GetFullName();
+{
+// Prefer the view's redline author name.
+// (set in SwXTextDocument::initializeForTiledRendering)
+std::size_t nAuthor = SW_MOD()->GetRedlineAuthor();
+OUString sAuthor = SW_MOD()->GetRedlineAuthor(nAuthor);
+if (sAuthor.isEmpty())
+return rOpt.GetFullName();
+
+return sAuthor;
+}
 
 return rOpt.GetID();
 }


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-12-04 Thread Szymon Kłos (via logerrit)
 sw/qa/filter/ww8/ww8.cxx |   31 +
 sw/source/filter/ww8/attributeoutputbase.hxx |2 -
 sw/source/filter/ww8/docxattributeoutput.cxx |   33 ++-
 sw/source/filter/ww8/docxattributeoutput.hxx |2 -
 sw/source/filter/ww8/rtfattributeoutput.cxx  |3 +-
 sw/source/filter/ww8/rtfattributeoutput.hxx  |3 +-
 sw/source/filter/ww8/wrtw8nds.cxx|   31 ++---
 sw/source/filter/ww8/ww8atr.cxx  |2 -
 sw/source/filter/ww8/ww8attributeoutput.hxx  |2 -
 9 files changed, 89 insertions(+), 20 deletions(-)

New commits:
commit 59d35122eea485b56fb1f89625fffd85bac741a0
Author: Szymon Kłos 
AuthorDate: Tue Nov 29 10:09:10 2022 +0100
Commit: Mike Kaganski 
CommitDate: Sun Dec 4 09:30:19 2022 +

docx: export symbol characters correctly

Previously we had:
after save: 
original content: 

This patch checks if paragraph has symbol font used and exports
content using w:sym mark in that case

Change-Id: I74f4bb0d249cbf5dfc930e931f7d91bd0d2e9821
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143455
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Mike Kaganski 

diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx
index 44ef994bf412..7dcb337cd413 100644
--- a/sw/qa/filter/ww8/ww8.cxx
+++ b/sw/qa/filter/ww8/ww8.cxx
@@ -9,6 +9,7 @@
 
 #include 
 
+#include 
 #include 
 
 #include 
@@ -114,6 +115,36 @@ CPPUNIT_TEST_FIXTURE(Test, testDocxHyperlinkShape)
 // assertion failure for not-well-formed XML output):
 save("Office Open XML Text", maTempFile);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testDocxSymbolFontExport)
+{
+// Create document with symbol character and font Wingdings
+mxComponent = loadFromDesktop("private:factory/swriter");
+uno::Reference xMSF(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xText = xTextDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+
+xText->insertString(xCursor, u"", true);
+
+uno::Reference xRange = xCursor;
+uno::Reference xTextProps(xRange, uno::UNO_QUERY);
+xTextProps->setPropertyValue("CharFontName", 
uno::Any(OUString("Wingdings")));
+xTextProps->setPropertyValue("CharFontNameAsian", 
uno::Any(OUString("Wingdings")));
+xTextProps->setPropertyValue("CharFontNameComplex", 
uno::Any(OUString("Wingdings")));
+xTextProps->setPropertyValue("CharFontCharSet", 
uno::Any(awt::CharSet::SYMBOL));
+
+// When exporting to DOCX:
+save("Office Open XML Text", maTempFile);
+mbExported = true;
+
+// Then make sure the expected markup is used:
+xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+
+assertXPath(pXmlDoc, "//w:p/w:r/w:sym", 1);
+assertXPath(pXmlDoc, "//w:p/w:r/w:sym[1]", "font", "Wingdings");
+assertXPath(pXmlDoc, "//w:p/w:r/w:sym[1]", "char", "f0e0");
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/attributeoutputbase.hxx 
b/sw/source/filter/ww8/attributeoutputbase.hxx
index ffa81eb161fd..7e415a50a118 100644
--- a/sw/source/filter/ww8/attributeoutputbase.hxx
+++ b/sw/source/filter/ww8/attributeoutputbase.hxx
@@ -190,7 +190,7 @@ public:
 virtual void WritePostitFieldReference() {};
 
 /// Output text (inside a run).
-virtual void RunText( const OUString& rText, rtl_TextEncoding eCharSet = 
RTL_TEXTENCODING_UTF8 ) = 0;
+virtual void RunText( const OUString& rText, rtl_TextEncoding eCharSet = 
RTL_TEXTENCODING_UTF8, const OUString& rSymbolFont = OUString() ) = 0;
 
 /// Output text (without markup).
 virtual void RawText(const OUString& rText, rtl_TextEncoding eCharSet) = 0;
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 506f62328947..9c8bd63a945f 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3397,7 +3397,8 @@ bool DocxAttributeOutput::FootnoteEndnoteRefTag()
 the switch in DocxAttributeOutput::RunText() nicer ;-)
  */
 static bool impl_WriteRunText( FSHelperPtr const & pSerializer, sal_Int32 
nTextToken,
-const sal_Unicode* , const sal_Unicode* pEnd, bool bMove = true 
)
+const sal_Unicode* , const sal_Unicode* pEnd, bool bMove = true,
+const OUString& rSymbolFont = OUString() )
 {
 const sal_Unicode *pBegin = rBegin;
 
@@ -3408,22 +3409,34 @@ static bool impl_WriteRunText( FSHelperPtr const & 
pSerializer, sal_Int32 nTextT
 if ( pBegin >= pEnd )
 return false; // we want to write at least one character
 
-// we have to add 'preserve' when starting/ending with space
-if ( *pBegin == ' ' || *( pEnd - 1 ) == ' ' )
+bool bIsSymbol = !rSymbolFont.isEmpty();
+
+std::u16string_view aView( pBegin, pEnd - pBegin );
+if (bIsSymbol)
 {
-pSerializer->startElementNS(XML_w, 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-11-17 Thread Miklos Vajna (via logerrit)
 sw/qa/uibase/shells/shells.cxx  |   32 -
 sw/source/uibase/shells/textfld.cxx |   39 +---
 2 files changed, 45 insertions(+), 26 deletions(-)

New commits:
commit d576aa0a1ba17680f9cb49b23a124eacbe6bb591
Author: Miklos Vajna 
AuthorDate: Wed Nov 16 12:10:30 2022 +0100
Commit: Miklos Vajna 
CommitDate: Thu Nov 17 11:17:47 2022 +0100

sw, .uno:TextFormField command: accept HTML in the FieldResult parameter

- improve the calculation of the SwPaM that decides the start/end of the
  fieldmark: with HTML import the length of the content is not the
  length of the input string anymore

- use SwTranslateHelper::PasteHTMLToPaM() to accept formatted content
  inside a single paragraph

- avoid unwanted last empty paragraph from the HTML import

- this builds on top of commit 6870c0c3385bf5d19e9c80bf973fca255ae38c08
  (sw: add new FieldCode parameter for the .uno:TextFormField command,
  2022-11-15), which introduced plain text support for FieldResult

(cherry picked from commit 1c2ef850db29beb369dcc89a58fc73416ecd9c5c)

Conflicts:
sw/qa/uibase/shells/shells.cxx
sw/source/uibase/shells/textfld.cxx

Change-Id: I8332f6ee532ab1e844a4b94f22b1f72d2406eb3a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142824
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index 153b8fc5b479..5a7b2ca8d42c 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -241,25 +241,6 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testContentControlPageBreak)
 CPPUNIT_ASSERT_EQUAL(1, getPages());
 }
 
-namespace
-{
-// sw::mark::TextFieldmark::GetContent() on master.
-OUString TextFieldmarkGetContent(sw::mark::IFieldmark* pFieldmark)
-{
-const SwTextNode& rTextNode = 
*pFieldmark->GetMarkEnd().nNode.GetNode().GetTextNode();
-SwPosition const sepPos(sw::mark::FindFieldSep(*pFieldmark));
-const sal_Int32 nStart(sepPos.nContent.GetIndex());
-const sal_Int32 nEnd(pFieldmark->GetMarkEnd().nContent.GetIndex());
-
-OUString sContent;
-const sal_Int32 nLen = rTextNode.GetText().getLength();
-if (nStart + 1 < nLen && nEnd <= nLen && nEnd > nStart + 2)
-sContent = rTextNode.GetText().copy(nStart + 1, nEnd - nStart - 2);
-
-return sContent;
-}
-}
-
 CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertTextFormField)
 {
 // Given an empty document:
@@ -267,11 +248,10 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testInsertTextFormField)
 
 // When inserting an ODF_UNHANDLED fieldmark:
 OUString aExpectedCommand("ADDIN ZOTERO_BIBL foo bar");
-OUString aExpectedResult("(Abrikosov, n.d.)");
 uno::Sequence aArgs = {
 comphelper::makePropertyValue("FieldType", 
uno::Any(OUString(ODF_UNHANDLED))),
 comphelper::makePropertyValue("FieldCommand", 
uno::Any(aExpectedCommand)),
-comphelper::makePropertyValue("FieldResult", 
uno::Any(aExpectedResult)),
+comphelper::makePropertyValue("FieldResult", 
uno::Any(OUString("aaabbb"))),
 };
 dispatchCommand(mxComponent, ".uno:TextFormField", aArgs);
 
@@ -294,8 +274,14 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testInsertTextFormField)
 it->second >>= aActualCommand;
 CPPUNIT_ASSERT_EQUAL(aExpectedCommand, aActualCommand);
 
-OUString aActualResult = TextFieldmarkGetContent(pFieldmark);
-CPPUNIT_ASSERT_EQUAL(aExpectedResult, aActualResult);
+SwPaM aPam(pFieldmark->GetMarkStart(), pFieldmark->GetMarkEnd());
+// Ignore the leading field start + sep.
+aPam.GetMark()->nContent = aPam.GetMark()->nContent.GetIndex() + 2;
+// Ignore the trailing field end.
+aPam.GetPoint()->nContent = aPam.GetPoint()->nContent.GetIndex() - 1;
+CPPUNIT_ASSERT(aPam.HasMark());
+OUString aActualResult = aPam.GetText();
+CPPUNIT_ASSERT_EQUAL(OUString("aaa\nbbb"), aActualResult);
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/uibase/shells/textfld.cxx 
b/sw/source/uibase/shells/textfld.cxx
index 2f3c62512171..a3690619122d 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -63,6 +63,7 @@
 #include 
 #include 
 #include 
+#include 
 
 
 using namespace nsSwDocInfoSubType;
@@ -703,6 +704,9 @@ FIELD_INSERT:
 }
 
 
rSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT_FORM_FIELD, 
nullptr);
+// Don't update the layout after inserting content and before 
deleting temporary
+// text nodes.
+rSh.StartAction();
 
 SwPaM* pCursorPos = rSh.GetCursor();
 if(pCursorPos)
@@ -717,12 +721,40 @@ FIELD_INSERT:
 aFieldResult = pFieldResult->GetValue();
 }
 
-bool bSuccess = 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-10-25 Thread Miklos Vajna (via logerrit)
 sw/qa/core/text/text.cxx |   15 ++-
 sw/source/core/text/itrform2.cxx |   26 +-
 2 files changed, 31 insertions(+), 10 deletions(-)

New commits:
commit 05bdae6e949d91277978af88212a646d1bd715c3
Author: Miklos Vajna 
AuthorDate: Mon Oct 24 08:45:26 2022 +0200
Commit: Miklos Vajna 
CommitDate: Tue Oct 25 08:20:49 2022 +0200

sw content controls, alias: add PDF export

Now that content controls have aliases, map that to PDF's description
and then map the content to PDF's text when the content control is not
in placeholder mode.

This way the widget will have a description even if it's already filled
in, which helps a11y.

(cherry picked from commit 122419be4f7bf576f7db5456b8b6b1f6f700487f)

Change-Id: Ia66455eba26300c5dbb2d62b5858bac82546acf8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141726
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index 7c3077c8cdae..95b1113979b1 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -37,6 +37,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/text/data/";
 
@@ -541,7 +544,17 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testContentControlPDF)
 sal_Int32 nPlaceHolderLen = 
SwResId(STR_CONTENT_CONTROL_PLACEHOLDER).getLength();
 pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, nPlaceHolderLen,
  /*bBasicCall=*/false);
-pWrtShell->Insert("mydesc");
+pWrtShell->Insert("mycontent");
+const SwPosition* pStart = pWrtShell->GetCursor()->Start();
+SwTextNode* pTextNode = pStart->nNode.GetNode().GetTextNode();
+sal_Int32 nIndex = pStart->nContent.GetIndex();
+SwTextAttr* pAttr
+= pTextNode->GetTextAttrAt(nIndex, RES_TXTATR_CONTENTCONTROL, 
SwTextNode::PARENT);
+auto pTextContentControl = 
static_txtattr_cast(pAttr);
+const SwFormatContentControl& rFormatContentControl = 
pTextContentControl->GetContentControl();
+std::shared_ptr pContentControl = 
rFormatContentControl.GetContentControl();
+// Alias/title, to be mapped to PDF's description.
+pContentControl->SetAlias("mydesc");
 
 // When exporting to PDF:
 StoreToTempFile("writer_pdf_Export");
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 3d9ed4edebfe..fad85e12337e 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -1003,15 +1003,23 @@ bool SwContentControlPortion::DescribePDFControl(const 
SwTextPaintInfo& rInf) co
 }
 
 // Description for accessibility purposes.
-SwPosition aPoint(*pTextNode, nStart);
-SwPosition aMark(*pTextNode, nEnd);
-SwPaM aPam(aMark, aPoint);
-OUString aDescription = aPam.GetText();
-static sal_Unicode const aForbidden[] = {
-CH_TXTATR_BREAKWORD,
-0
-};
-pDescriptor->Description = comphelper::string::removeAny(aDescription, 
aForbidden);
+if (!pContentControl->GetAlias().isEmpty())
+{
+pDescriptor->Description = pContentControl->GetAlias();
+}
+
+if (!pContentControl->GetShowingPlaceHolder())
+{
+SwPosition aPoint(*pTextNode, nStart);
+SwPosition aMark(*pTextNode, nEnd);
+SwPaM aPam(aMark, aPoint);
+OUString aText = aPam.GetText();
+static sal_Unicode const aForbidden[] = {
+CH_TXTATR_BREAKWORD,
+0
+};
+pDescriptor->Text = comphelper::string::removeAny(aText, aForbidden);
+}
 
 // Calculate the bounding rectangle of this content control, which can be 
one or more layout
 // portions in one or more lines.


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source sw/uiconfig

2022-10-20 Thread Miklos Vajna (via logerrit)
 sw/qa/uitest/ui/misc/misc.py|   11 ++
 sw/source/ui/misc/contentcontroldlg.cxx |   26 ++
 sw/source/uibase/inc/contentcontroldlg.hxx  |2 +
 sw/uiconfig/swriter/ui/contentcontroldlg.ui |   51 +++-
 4 files changed, 89 insertions(+), 1 deletion(-)

New commits:
commit 8f36736f511215deff3a7d5479f23ad58266b0bc
Author: Miklos Vajna 
AuthorDate: Wed Oct 19 08:44:38 2022 +0200
Commit: Miklos Vajna 
CommitDate: Thu Oct 20 10:55:23 2022 +0200

sw content controls, alias and tag: add UI

- add 2 new weld::Entry instances to edit these strings + matching
  labels

- extend the grid to have 2 columns, as previously only a checkbox was
  there for all content controls, which only needed a single column, but
  now we want label + entry pairs in later rows

- cover this with a UITest

(cherry picked from commit add110bad816fadeb96e7af0d4689389c04c263e)

Change-Id: Ia5cfb90725d3b5b40eccf15ec7c7823e0e6d6751
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141545
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/uitest/ui/misc/misc.py b/sw/qa/uitest/ui/misc/misc.py
index cf4554ce9638..2b6307cefb61 100644
--- a/sw/qa/uitest/ui/misc/misc.py
+++ b/sw/qa/uitest/ui/misc/misc.py
@@ -10,6 +10,7 @@
 """Covers sw/source/ui/misc/ fixes."""
 
 from uitest.framework import UITestCase
+from uitest.uihelper.common import get_state_as_dict
 from uitest.uihelper.common import type_text
 
 
@@ -23,6 +24,8 @@ class TestTmpdlg(UITestCase):
 portions = paragraph.createEnumeration()
 portion = portions.nextElement()
 contentControl = portion.ContentControl
+contentControl.Alias = "my alias"
+contentControl.Tag = "my tag"
 listItems = contentControl.ListItems
 self.assertEqual(len(listItems), 1)
 self.assertEqual(listItems[0][0].Name, "DisplayText")
@@ -32,6 +35,12 @@ class TestTmpdlg(UITestCase):
 
 # Append a new list item.
 with 
self.ui_test.execute_dialog_through_command(".uno:ContentControlProperties") as 
xDialog:
+xAlias = xDialog.getChild("aliasentry")
+self.assertEqual(get_state_as_dict(xAlias)['Text'], "my alias")
+type_text(xAlias, "new alias ")
+xTag = xDialog.getChild("tagentry")
+self.assertEqual(get_state_as_dict(xTag)['Text'], "my tag")
+type_text(xTag, "new tag ")
 xAdd = xDialog.getChild("add")
 with self.ui_test.execute_blocking_action(xAdd.executeAction, 
args=('CLICK', ())) as xSubDialog:
 xDisplayName = xSubDialog.getChild("displayname")
@@ -46,6 +55,8 @@ class TestTmpdlg(UITestCase):
 self.assertEqual(listItems[1][0].Value, "Foo Bar")
 self.assertEqual(listItems[1][1].Name, "Value")
 self.assertEqual(listItems[1][1].Value, "foo-bar")
+self.assertEqual(contentControl.Alias, "new alias my alias")
+self.assertEqual(contentControl.Tag, "new tag my tag")
 
 
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/ui/misc/contentcontroldlg.cxx 
b/sw/source/ui/misc/contentcontroldlg.cxx
index 5e4347e62afb..5770bf1bd6bd 100644
--- a/sw/source/ui/misc/contentcontroldlg.cxx
+++ b/sw/source/ui/misc/contentcontroldlg.cxx
@@ -38,6 +38,8 @@ SwContentControlDlg::SwContentControlDlg(weld::Window* 
pParent, SwWrtShell& rWrt
   "ContentControlDialog")
 , m_rWrtShell(rWrtShell)
 , 
m_xShowingPlaceHolderCB(m_xBuilder->weld_check_button("showing_place_holder"))
+, m_xAlias(m_xBuilder->weld_entry("aliasentry"))
+, m_xTag(m_xBuilder->weld_entry("tagentry"))
 , m_xCheckboxFrame(m_xBuilder->weld_frame("checkboxframe"))
 , m_xCheckedState(m_xBuilder->weld_entry("checkboxcheckedentry"))
 , m_xCheckedStateBtn(m_xBuilder->weld_button("btncheckboxchecked"))
@@ -94,6 +96,18 @@ SwContentControlDlg::SwContentControlDlg(weld::Window* 
pParent, SwWrtShell& rWrt
 m_xShowingPlaceHolderCB->set_state(eShowingPlaceHolder);
 m_xShowingPlaceHolderCB->save_state();
 
+if (!m_pContentControl->GetAlias().isEmpty())
+{
+m_xAlias->set_text(m_pContentControl->GetAlias());
+m_xAlias->save_value();
+}
+
+if (!m_pContentControl->GetTag().isEmpty())
+{
+m_xTag->set_text(m_pContentControl->GetTag());
+m_xTag->save_value();
+}
+
 if (m_pContentControl->GetCheckbox())
 {
 m_xCheckedState->set_text(m_pContentControl->GetCheckedState());
@@ -176,6 +190,18 @@ IMPL_LINK_NOARG(SwContentControlDlg, OkHdl, weld::Button&, 
void)
 bChanged = true;
 }
 
+if (m_xAlias->get_value_changed_from_saved())
+{
+m_pContentControl->SetAlias(m_xAlias->get_text());
+bChanged = true;
+}
+
+if 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-10-14 Thread Justin Luth (via logerrit)
 sw/qa/extras/ww8import/ww8import.cxx |2 +-
 sw/source/ui/uno/swdetect.cxx|   25 ++---
 2 files changed, 19 insertions(+), 8 deletions(-)

New commits:
commit f657983a6ec7f79482efc3a0f70510e15b527670
Author: Justin Luth 
AuthorDate: Tue Sep 27 22:08:48 2022 -0400
Commit: Miklos Vajna 
CommitDate: Fri Oct 14 09:33:18 2022 +0200

tdf#125216 import filter: allow .doc renamed as .dot

A LO 6.2.2 regression prevented .doc-as-.dot files to load,
giving a "Read Error. This is not a valid WinWord6 file."

Well, it is not a valid .dot file (because of some bit differences),
but it is a valid .doc file.
Since it was renamed to be treated as a template
(requiring a save-as), we should treat it as that.

Change-Id: I308375797e9dae3ca6d203fab520e91ee788325e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140687
Tested-by: Jenkins
Reviewed-by: Justin Luth 
(cherry picked from commit 6cec8ba33a28de7248861b2eecfc5034cbde9d37)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140608
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/ww8import/data/tdf120761_zOrder.doc 
b/sw/qa/extras/ww8import/data/tdf120761_zOrder.dot
similarity index 100%
rename from sw/qa/extras/ww8import/data/tdf120761_zOrder.doc
rename to sw/qa/extras/ww8import/data/tdf120761_zOrder.dot
diff --git a/sw/qa/extras/ww8import/ww8import.cxx 
b/sw/qa/extras/ww8import/ww8import.cxx
index 7eb0c9f6b221..8c77217c7610 100644
--- a/sw/qa/extras/ww8import/ww8import.cxx
+++ b/sw/qa/extras/ww8import/ww8import.cxx
@@ -275,7 +275,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf110987)
 
 CPPUNIT_TEST_FIXTURE(Test, testTdf120761_zOrder)
 {
-load(mpTestDocumentPath, "tdf120761_zOrder.doc");
+load(mpTestDocumentPath, "tdf120761_zOrder.dot");
 //The blue shape was covering everything (highest zorder = 2) instead of 
the lowest(0)
 uno::Reference xShape(getShapeByName(u"Picture 2"), 
uno::UNO_QUERY);
 CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), getProperty(xShape, 
"ZOrder"));
diff --git a/sw/source/ui/uno/swdetect.cxx b/sw/source/ui/uno/swdetect.cxx
index 9e354dedaf6b..83b7162ae2a0 100644
--- a/sw/source/ui/uno/swdetect.cxx
+++ b/sw/source/ui/uno/swdetect.cxx
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 using namespace ::com::sun::star;
@@ -102,19 +103,29 @@ OUString SAL_CALL SwFilterDetect::detect( Sequence< 
PropertyValue >& lDescriptor
 // mis-detect it.
 if ( bIsDetected && aTypeName == 
"writer_MS_Word_97_Vorlage" )
 {
+// It is common practice to rename a .doc to .dot to 
make it a template.
+// Since we have detected a.doc-ish format, always 
accept .dot-named-files
+// as valid templates to avoid flagging this as an 
invalid .dot format..
+INetURLObject 
aParser(aMediaDesc.getUnpackedValueOrDefault(
+utl::MediaDescriptor::PROP_URL, OUString()));
+
 // Super ugly hack, but we don't want to use the whole 
WW8Fib thing here in
 // the swd library, apparently. We know (do we?) that 
the "aBits1" byte, as
 // the variable is called in 
WW8Fib::WW8Fib(SvStream&,sal_uInt8,sal_uInt32),
 // is at offset 10 in the WordDocument stream. The 
fDot bit is bit 0x01 of
 // that byte.
-tools::SvRef xWordDocument = 
aStorage->OpenSotStream("WordDocument", StreamMode::STD_READ);
-xWordDocument->Seek( 10 );
-if ( xWordDocument->Tell() == 10 )
+if (aParser.getExtension().toAsciiLowerCase() != "dot")
 {
-sal_uInt8 aBits1;
-xWordDocument->ReadUChar( aBits1 );
-// Check fDot bit
-bIsDetected = ((aBits1 & 0x01) == 0x01);
+tools::SvRef xWordDocument
+= aStorage->OpenSotStream("WordDocument", 
StreamMode::STD_READ);
+xWordDocument->Seek(10);
+if (xWordDocument->Tell() == 10)
+{
+sal_uInt8 aBits1;
+xWordDocument->ReadUChar(aBits1);
+// Check fDot bit
+bIsDetected = ((aBits1 & 0x01) == 0x01);
+}
 }
 }
 }


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-10-12 Thread Miklos Vajna (via logerrit)
 sw/qa/core/crsr/crsr.cxx|   23 +++
 sw/source/core/crsr/pam.cxx |7 +++
 2 files changed, 30 insertions(+)

New commits:
commit fc8b066ab832e1166da3b9dd76e11b4e266314cc
Author: Miklos Vajna 
AuthorDate: Wed Oct 12 11:44:49 2022 +0200
Commit: Andras Timar 
CommitDate: Wed Oct 12 18:17:04 2022 +0200

tdf#151190 sw content controls: make them read-write in protected sections

When the user picked a date in the date picker inside a protected
section, then we blocked the deletion of the placeholder, but allowed
insertion to the content control, which is inconsistent.

The trouble was that SwPaM::HasReadonlySel() detected that the cursor is
in a protected section, so deletion failed, leading to an ever growing
value of the content control.

Fix the problem by handling content controls similar to legacy form
fields: if the cursor is inside a content control, then that value is
editable, even if we're inside a protected section.

This is meant to fix all content control types, not just date pickers.

(cherry picked from commit b138d6c12aaeb0b87dce15ea52dd134cf1abf6ac)

Change-Id: I9eca4c4f71dcfaa61d84414f7727adcd4496735c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141255
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Andras Timar 

diff --git a/sw/qa/core/crsr/crsr.cxx b/sw/qa/core/crsr/crsr.cxx
index 5f06658b528e..7b42d4df3716 100644
--- a/sw/qa/core/crsr/crsr.cxx
+++ b/sw/qa/core/crsr/crsr.cxx
@@ -183,6 +183,29 @@ CPPUNIT_TEST_FIXTURE(SwCoreCrsrTest, 
testDropdownContentControl)
 CPPUNIT_ASSERT(pWrtShell->HasReadonlySel());
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreCrsrTest, testContentControlProtectedSection)
+{
+// Given a document with a date content control in a protected section:
+SwDoc* pDoc = createSwDoc();
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+pWrtShell->InsertContentControl(SwContentControlType::DATE);
+pWrtShell->SelAll();
+OUString aSectionName = pWrtShell->GetUniqueSectionName();
+SwSectionData aSection(SectionType::Content, aSectionName);
+aSection.SetProtectFlag(true);
+pWrtShell->InsertSection(aSection);
+
+// When entering the content control:
+pWrtShell->SttEndDoc(/*bStt=*/true);
+pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
+
+// Then make sure that the cursor is read-only:
+// Without the accompanying fix in place, this test would have failed, it 
was not possible to
+// pick a date in a protected section (the new value was inserted, but the 
placeholder was not
+// removed).
+CPPUNIT_ASSERT(!pWrtShell->HasReadonlySel());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx
index 277af8905a07..b2b51958c6cb 100644
--- a/sw/source/core/crsr/pam.cxx
+++ b/sw/source/core/crsr/pam.cxx
@@ -763,6 +763,13 @@ bool SwPaM::HasReadonlySel( bool bFormView ) const
 {
 // Allow editing when the cursor/selection is fully inside of a legacy 
form field.
 bRet = !( pA != nullptr && !bAtStartA && !bAtStartB && pA == pB );
+
+if (bRet && rDoc.GetEditShell()->CursorInsideContentControl())
+{
+// Also allow editing inside content controls in general, similar 
to form fields.
+// Specific types will be disabled below.
+bRet = false;
+}
 }
 
 if (!bRet)


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-10-10 Thread Miklos Vajna (via logerrit)
 sw/qa/core/text/text.cxx |   32 
 sw/source/core/text/itrform2.cxx |   31 ++-
 2 files changed, 58 insertions(+), 5 deletions(-)

New commits:
commit d5135d4eb2b10e6ceb78c64c298076827f1863eb
Author: Miklos Vajna 
AuthorDate: Fri Oct 7 13:51:55 2022 +0200
Commit: Miklos Vajna 
CommitDate: Mon Oct 10 09:21:36 2022 +0200

sw content controls: emit only one PDF widget for multiple text portions

If the content control's text is like "XXXYYY", then we used to
create two PDF form widgets, while only one is wanted. This is
especially annoying since the widget's width is defined by the Writer
text, so tab portions would be a natural tool to nicely increase the
width if wanted.

The problem is that in case the content is rich text, then we break up
that content into multiple portions, and each portion will be handled in
SwContentControlPortion::DescribePDFControl() separately.

Fix the problem by checking if the current text portion is the first one
for a content control, handling the entire content control there and
then silently not doing anything (no form widget, no plain text
fallback) for the rest of the content.

This also helps in case the content control has a linebreak to extend
its height. Note that this can't be perfect in case the content control
has multiple lines but the starting/ending line has text outside the
content control. This is a restriction on the PDF side, since the form
widget's area must be a rectangle.

(cherry picked from commit a70f5f141c1e6013abb4c1b3219e017b2eea40a8)

Change-Id: Ie8627faa4257d2660a733e2a28546a894548edd3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141075
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index b5b9476cd236..7c3077c8cdae 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -688,6 +689,37 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, 
testComboContentControlPDF)
 CPPUNIT_ASSERT(pAnnotation->getFormFieldFlags(pPdfDocument.get()) & 
0x0004);
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testRichContentControlPDF)
+{
+// Given a file with a rich content control, its value set to 
"xxxyyy":
+SwDoc* pDoc = createSwDoc();
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+pWrtShell->InsertContentControl(SwContentControlType::RICH_TEXT);
+pWrtShell->SttEndDoc(/*bStt=*/true);
+pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
+sal_Int32 nPlaceHolderLen = 
SwResId(STR_CONTENT_CONTROL_PLACEHOLDER).getLength();
+pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, nPlaceHolderLen,
+ /*bBasicCall=*/false);
+pWrtShell->Insert("xxxyyy");
+pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 3, 
/*bBasicCall=*/false);
+SfxItemSetFixed 
aSet(pWrtShell->GetAttrPool());
+SvxWeightItem aItem(WEIGHT_BOLD, RES_CHRATR_WEIGHT);
+aSet.Put(aItem);
+pWrtShell->SetAttrSet(aSet);
+
+// When exporting to PDF:
+StoreToTempFile("writer_pdf_Export");
+
+// Then make sure that a single fillable form widget is emitted:
+std::unique_ptr pPdfDocument = 
LoadPdfFromTempFile();
+std::unique_ptr pPage = pPdfDocument->openPage(0);
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 1
+// - Actual  : 2
+// i.e. "xxxyyy" was exported as 2 widgets, not 1.
+CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationCount());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 35548fe00217..3d9ed4edebfe 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -924,6 +924,19 @@ bool SwContentControlPortion::DescribePDFControl(const 
SwTextPaintInfo& rInf) co
 return false;
 }
 
+// Check if this is the first content control portion of this content 
control.
+SwTextNode* pTextNode = pContentControl->GetTextNode();
+sal_Int32 nStart = m_pTextContentControl->GetStart();
+sal_Int32 nEnd = *m_pTextContentControl->GetEnd();
+TextFrameIndex nViewStart = rInf.GetTextFrame()->MapModelToView(pTextNode, 
nStart);
+TextFrameIndex nViewEnd = rInf.GetTextFrame()->MapModelToView(pTextNode, 
nEnd);
+// The content control portion starts 1 char after the starting dummy 
character.
+if (rInf.GetIdx() != nViewStart + TextFrameIndex(1))
+{
+// Ignore: don't process and also don't emit plain text fallback.
+return true;
+}
+
 std::unique_ptr pDescriptor;
 switch (pContentControl->GetType())
 {
@@ -990,10 +1003,8 @@ bool 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-09-28 Thread Miklos Vajna (via logerrit)
 sw/qa/core/draw/data/sdt-textbox-header.docx |binary
 sw/qa/core/draw/draw.cxx |   11 +++
 sw/source/core/draw/dcontact.cxx |   41 +++
 sw/source/core/draw/dflyobj.cxx  |   13 
 sw/source/core/inc/dflyobj.hxx   |1 
 5 files changed, 66 insertions(+)

New commits:
commit b44e92c0d1cc36bb30100d719626873dc9e1bcdf
Author: Miklos Vajna 
AuthorDate: Wed Sep 28 08:54:06 2022 +0200
Commit: Miklos Vajna 
CommitDate: Wed Sep 28 13:23:28 2022 +0200

crashtesting: fix PDF export of fdo83057-2.docx

Loading this document and laying it out resulted in an assertion failure
since commit de90c192cb8f1f03a4028493d8bfe9a127a76b2a (sw content
controls, plain text: enable DOCX filter with data binding, 2022-09-19).

Writer has two relevant invariants: First, if a draw shape is anchored
into a header, then the "master" shape (typically on the first page) and
its "virtual" shapes (on other pages) have their indexes / ZOrders set
so that the master shape has the highest index. The second is that in
case a draw+fly format is paired into a "textbox", then the fly index is
always the draw index + 1. The assert fails because in this case the
virtual draw shape's index is not smaller than the master one.

What seems to happen here is that first SwDrawContact::ConnectToLayout()
iterates the frames of the text node in the header, and happens to first
visit page 1 and then page 2. So the master SdrObjects go to the first
page, the virtual ones go to the second page. Then later
SwDrawContact::ConnectToLayout() is called again, which removes the
master and the virtual draw SdrObject from the layout and the virtual
draw SdrObject from the model. Then it visits the text frames of the
header text node again, but this time it happens to find the second
page, and only then the first page (for reasons unclear to me, this
didn't happen before the above commit). The result is that both
invariants are failing: the master draw+fly is no longer on the same
page and the indexes are also out of order, so one of the pages don't
show shape text for the shape from the header.

Fix the problem by two tweaks:

- Improve SwDrawContact::ConnectToLayout(), so that in case it just
  appends the draw object to the layout for the master, then it adjusts
  its ZOrder so the matching fly will be the draw one + 1.

  This was working in the virtual case already, since there we call
  AddVirtObj() already, which calls SwDrawVirtObj::AddToDrawingPage(),
  which already knows how to maintain this invariant.

  This fixes master draw SdrObjects to be directly before their fly
  counterparts, even if the page order changes.

- Improve SwDrawVirtObj::AddToDrawingPage(), so that in case the virtual
  draw SdrObject finds its fly, but that fly has an incorrect index (due
  to the changed page visit order), then we first fix up the fly and
  only then set the index of the virtual draw SdrObject.

The result is a doc model like this:



  


  

I.e. each draw SdrObject is followed by its fly and the masters have the
highest indexes.

This all stems from the behavior that 1) re-connecting a draw contact to
the layout removes the draw shapes but not the flys from the layout, 2)
the order of frames in an SwIterator visiting is not something we can
depend on and 3) textboxes are implemented using a pair of draw+fly
formats.

(cherry picked from commit 914d246e0edcbdfa5969b7f3eea7c67e1a5b7522)

Change-Id: Ia03f0ec70cf67626660349accc63770fe2afef5d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140703
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/draw/data/sdt-textbox-header.docx 
b/sw/qa/core/draw/data/sdt-textbox-header.docx
new file mode 100644
index ..a8b2d9625fbe
Binary files /dev/null and b/sw/qa/core/draw/data/sdt-textbox-header.docx differ
diff --git a/sw/qa/core/draw/draw.cxx b/sw/qa/core/draw/draw.cxx
index c2514808f8e4..feb347adc8d4 100644
--- a/sw/qa/core/draw/draw.cxx
+++ b/sw/qa/core/draw/draw.cxx
@@ -141,6 +141,17 @@ CPPUNIT_TEST_FIXTURE(SwCoreDrawTest, 
testTdf107727FrameBorder)
 CPPUNIT_ASSERT_EQUAL(Color(0xff), Color(ColorTransparency, 
aBorder.Color));
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreDrawTest, testSdtTextboxHeader)
+{
+// Given a 2 page document, same header on both pages, content control in 
the header and
+// shape+fly pair (textbox) anchored in the same header:
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"sdt-textbox-header.docx";
+
+// When loading that document, then make sure that layout doesn't fail 
with an assertion because
+// the "master SdrObj should have the 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source writerfilter/qa writerfilter/source

2022-09-23 Thread Miklos Vajna (via logerrit)
 sw/qa/filter/ww8/ww8.cxx|   27 
+
 sw/source/filter/ww8/docxattributeoutput.cxx|   18 +-
 writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx  |   30 
++
 writerfilter/qa/cppunittests/dmapper/data/sdt-run-combobox.docx |binary
 writerfilter/source/dmapper/DomainMapper.cxx|   23 ++-
 writerfilter/source/dmapper/DomainMapper_Impl.cxx   |7 ++
 writerfilter/source/dmapper/SdtHelper.cxx   |3 -
 writerfilter/source/dmapper/SdtHelper.hxx   |1 
 8 files changed, 101 insertions(+), 8 deletions(-)

New commits:
commit 321aa90f483d4c458e20c96da4f8d70943184283
Author: Miklos Vajna 
AuthorDate: Thu Sep 22 10:01:26 2022 +0200
Commit: Miklos Vajna 
CommitDate: Fri Sep 23 09:35:25 2022 +0200

sw content controls, combo box: add DOCX filter

Map the ComboBox UNO property to:


  
  ...
  


and the opposite on import.

(cherry picked from commit 01b1f57a90172a76faa1489b3b72250ee76169a6)

Change-Id: I50e0b961bca99f4ecca86d6784d2e6a13f469314
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140432
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx
index d98ff7dae151..d537cee04188 100644
--- a/sw/qa/filter/ww8/ww8.cxx
+++ b/sw/qa/filter/ww8/ww8.cxx
@@ -11,6 +11,11 @@
 
 #include 
 
+#include 
+#include 
+#include 
+#include 
+
 namespace
 {
 /**
@@ -56,6 +61,28 @@ CPPUNIT_TEST_FIXTURE(Test, testPlainTextContentControlExport)
 // i.e. the plain text content control was turned into a rich text one on 
export.
 assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:text", 1);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testDocxComboBoxContentControlExport)
+{
+// Given a document with a combo box content control around a text portion:
+mxComponent = loadFromDesktop("private:factory/swriter");
+SwDocShell* pDocShell = 
dynamic_cast(mxComponent.get())->GetDocShell();
+SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+pWrtShell->InsertContentControl(SwContentControlType::COMBO_BOX);
+
+// When exporting to DOCX:
+save("Office Open XML Text", maTempFile);
+mbExported = true;
+
+// Then make sure the expected markup is used:
+xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 1
+// - Actual  : 0
+// - XPath '//w:sdt/w:sdtPr/w:comboBox' number of nodes is incorrect
+// i.e. the combo box content control was turned into a drop-down one on 
export.
+assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:comboBox", 1);
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 67e87965e5f0..42c5c0cdef15 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2395,14 +2395,28 @@ void DocxAttributeOutput::WriteContentControlStart()
 
 if (m_pContentControl->HasListItems())
 {
-m_pSerializer->startElementNS(XML_w, XML_dropDownList);
+if (m_pContentControl->GetComboBox())
+{
+m_pSerializer->startElementNS(XML_w, XML_comboBox);
+}
+else
+{
+m_pSerializer->startElementNS(XML_w, XML_dropDownList);
+}
 for (const auto& rItem : m_pContentControl->GetListItems())
 {
 m_pSerializer->singleElementNS(XML_w, XML_listItem,
 FSNS(XML_w, XML_displayText), rItem.m_aDisplayText,
 FSNS(XML_w, XML_value), rItem.m_aValue);
 }
-m_pSerializer->endElementNS(XML_w, XML_dropDownList);
+if (m_pContentControl->GetComboBox())
+{
+m_pSerializer->endElementNS(XML_w, XML_comboBox);
+}
+else
+{
+m_pSerializer->endElementNS(XML_w, XML_dropDownList);
+}
 }
 
 if (m_pContentControl->GetDate())
diff --git a/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx 
b/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
index 6b568619785e..7b842e667104 100644
--- a/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
@@ -212,6 +212,36 @@ CPPUNIT_TEST_FIXTURE(Test, testSdtRunDropdown)
 CPPUNIT_ASSERT_EQUAL(OUString("choose a color"), xContent->getString());
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testSdtRunComboBox)
+{
+// Given a document with a combo box inline/run SDT:
+OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"sdt-run-combobox.docx";
+
+// When loading the document:
+getComponent() = loadFromDesktop(aURL);
+
+// Then make sure that the doc model has a clickable combo box content 
control:
+   

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-09-20 Thread Miklos Vajna (via logerrit)
 sw/qa/core/unocore/unocore.cxx|9 ++
 sw/source/core/unocore/unoobj.cxx |  124 ++
 2 files changed, 133 insertions(+)

New commits:
commit 5eb6a716886d3d1908010d210e457069cd1e37a9
Author: Miklos Vajna 
AuthorDate: Fri Sep 16 09:12:43 2022 +0200
Commit: Miklos Vajna 
CommitDate: Tue Sep 20 09:34:15 2022 +0200

sw content controls: fix getString() and setString() on SwXContentControl

The setter was broken, it inserted the new content at the start, but
didn't delete the old content. The getter was also broken, it returned
an empty string, even if the content control had a non-empty content.

This was always a problem since c4268efef25129b162884312b15527f1e5c3bcb0
(sw content controls: add UNO API to insert this, 2022-03-31) introduced
SwXContentControl.

Fix the problem by extending SwXTextCursor, so in case m_eType is
CursorType::ContentControl, then it keeps the cursor's range inside the
boundaries of the content control.

This also allows changing the data binding code added in
b5c616d10bff3213840d4893d13b4493de71fa56 (tdf#104823: support for sdt
plain text fields, 2021-11-24) to use content controls, in a follow-up
commit.

(cherry picked from commit 08bce8eeb2e18c7cea4108dbfc2519ada56e8b61)

Change-Id: Ic3ae47a4b26af090539d61035372f1784c8ffe3f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140179
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx
index 065692fef7f3..55c04614b209 100644
--- a/sw/qa/core/unocore/unocore.cxx
+++ b/sw/qa/core/unocore/unocore.cxx
@@ -318,6 +318,15 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, 
testContentControlInsert)
 = static_cast(pTextContentControl->GetAttr());
 std::shared_ptr pContentControl = 
rFormatContentControl.GetContentControl();
 CPPUNIT_ASSERT(pContentControl->GetShowingPlaceHolder());
+
+// Also verify that setText() and getText() works:
+uno::Reference xContentControlText(xContentControl, 
uno::UNO_QUERY);
+xContentControlText->setString("new");
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: new
+// - Actual  :
+// i.e. getString() always returned an empty string.
+CPPUNIT_ASSERT_EQUAL(OUString("new"), xContentControlText->getString());
 }
 
 CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testContentControlTextPortionEnum)
diff --git a/sw/source/core/unocore/unoobj.cxx 
b/sw/source/core/unocore/unoobj.cxx
index 90072ed52b78..33dfba9e8358 100644
--- a/sw/source/core/unocore/unoobj.cxx
+++ b/sw/source/core/unocore/unoobj.cxx
@@ -748,6 +748,12 @@ namespace {
 
 enum ForceIntoMetaMode { META_CHECK_BOTH, META_INIT_START, META_INIT_END };
 
+enum ForceIntoContentControlMode
+{
+CONTENT_CONTROL_CHECK_BOTH,
+CONTENT_CONTROL_INIT_START,
+CONTENT_CONTROL_INIT_END
+};
 }
 
 static bool
@@ -794,6 +800,61 @@ lcl_ForceIntoMeta(SwPaM & rCursor,
 return bRet;
 }
 
+namespace
+{
+bool lcl_ForceIntoContentControl(SwPaM& rCursor, const 
uno::Reference& xParentText,
+ ForceIntoContentControlMode eMode)
+{
+bool bRet = true; // means not forced in CONTENT_CONTROL_CHECK_BOTH
+auto pXContentControl = 
dynamic_cast(xParentText.get());
+if (!pXContentControl)
+{
+SAL_WARN("sw.core", "lcl_ForceIntoContentControl: no parent text");
+throw uno::RuntimeException();
+}
+
+SwTextNode* pTextNode;
+sal_Int32 nStart;
+sal_Int32 nEnd;
+bool bSuccess = pXContentControl->SetContentRange(pTextNode, nStart, nEnd);
+if (!bSuccess)
+{
+SAL_WARN("sw.core", "lcl_ForceIntoContentControl: SetContentRange() 
failed");
+throw uno::RuntimeException();
+}
+
+// Force the cursor back into the content control if it has moved outside.
+SwPosition aStart(*pTextNode, nStart);
+SwPosition aEnd(*pTextNode, nEnd);
+switch (eMode)
+{
+case CONTENT_CONTROL_INIT_START:
+*rCursor.GetPoint() = aStart;
+break;
+
+case CONTENT_CONTROL_INIT_END:
+*rCursor.GetPoint() = aEnd;
+break;
+
+case CONTENT_CONTROL_CHECK_BOTH:
+if (*rCursor.Start() < aStart)
+{
+*rCursor.Start() = aStart;
+bRet = false;
+}
+
+if (*rCursor.End() > aEnd)
+{
+*rCursor.End() = aEnd;
+bRet = false;
+}
+break;
+}
+
+return bRet;
+}
+}
+
 bool SwXTextCursor::IsAtEndOfMeta() const
 {
 if (CursorType::Meta == m_eType)
@@ -958,6 +1019,11 @@ SwXTextCursor::goLeft(sal_Int16 nCount, sal_Bool Expand)
 META_CHECK_BOTH)
 && bRet;
 }
+else if (m_eType == CursorType::ContentControl)
+{
+bRet = 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-08-17 Thread Pranam Lashkari (via logerrit)
 sw/qa/extras/tiledrendering/data/testTableCommentRemoveCallback.odt |binary
 sw/qa/extras/tiledrendering/tiledrendering.cxx  |   23 
++
 sw/source/uibase/docvw/PostItMgr.cxx|1 
 3 files changed, 24 insertions(+)

New commits:
commit d365da2c47a4a40e0b33a34f559046d1162ae1fb
Author: Pranam Lashkari 
AuthorDate: Wed Aug 17 05:35:38 2022 +0530
Commit: Pranam Lashkari 
CommitDate: Wed Aug 17 20:03:50 2022 +0200

sw: online: make sure commment removal notification is sent

problem:
when comment is added inside a table in online,
and entire table is deleted, comments were not removed
due to notification not being sent.

Another failed case was when some text with comment is
copy pasted, and then pasted text is undoed,
text was removed but comment stayed.

This patch will notify comment removal before actaully distroying the 
comment/note

Signed-off-by: Pranam Lashkari 
Change-Id: I70aad7eb421b4bde52b9e54855e2360c59807852
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138398
Reviewed-by: Szymon Kłos 
Tested-by: Jenkins CollaboraOffice 

diff --git 
a/sw/qa/extras/tiledrendering/data/testTableCommentRemoveCallback.odt 
b/sw/qa/extras/tiledrendering/data/testTableCommentRemoveCallback.odt
new file mode 100644
index ..09941166a718
Binary files /dev/null and 
b/sw/qa/extras/tiledrendering/data/testTableCommentRemoveCallback.odt differ
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 5b0443884ad8..89a9acdba670 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -3266,6 +3266,29 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, 
testTablePaintInvalidate)
 CPPUNIT_ASSERT_EQUAL(0, m_nInvalidations);
 }
 
+CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testTableCommentRemoveCallback)
+{
+comphelper::LibreOfficeKit::setActive();
+comphelper::LibreOfficeKit::setTiledAnnotations(false);
+
+// Load a document with a comment in a table.
+SwXTextDocument* pXTextDocument = 
createDoc("testTableCommentRemoveCallback.odt");
+SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
+setupLibreOfficeKitViewCallback(pWrtShell->GetSfxViewShell());
+ViewCallback aView;
+
+// delete all characters
+comphelper::dispatchCommand(".uno:SelectAll", 
uno::Sequence());
+Scheduler::ProcessEventsToIdle();
+pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DELETE);
+pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DELETE);
+Scheduler::ProcessEventsToIdle();
+
+//check for comment remove callback
+OString 
sAction(aView.m_aComment.get_child("action").get_value().c_str());
+CPPUNIT_ASSERT_EQUAL(OString("Remove"), sAction);
+}
+
 CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testSpellOnlineRenderParameter)
 {
 SwXTextDocument* pXTextDocument = createDoc("dummy.fodt");
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx 
b/sw/source/uibase/docvw/PostItMgr.cxx
index 234b6c5db0c5..bab23796a94b 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -247,6 +247,7 @@ bool SwPostItMgr::CheckForRemovedPostIts()
 if (!(*it)->UseElement(*mpWrtShell->GetLayout(), rIDRA))
 {
 
EndListening(const_cast(*(*it)->GetBroadcaster()));
+lcl_CommentNotification(mpView, CommentNotificationType::Remove, 
nullptr, (*it)->mpPostIt->GetPostItField()->GetPostItId());
 std::unique_ptr p = std::move(*it);
 it = mvPostItFields.erase(it);
 if (GetActiveSidebarWin() == p->mpPostIt)


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-08-16 Thread Miklos Vajna (via logerrit)
 sw/qa/core/text/text.cxx   |   43 +
 sw/source/core/text/itrtxt.cxx |   37 ++-
 sw/source/core/text/porrst.cxx |   16 ++-
 sw/source/core/text/txtfly.cxx |   19 --
 4 files changed, 107 insertions(+), 8 deletions(-)

New commits:
commit a93556afb6c6623fba2b80850f9deec0dd069258
Author: Miklos Vajna 
AuthorDate: Mon Aug 15 15:00:47 2022 +0200
Commit: Miklos Vajna 
CommitDate: Tue Aug 16 10:57:25 2022 +0200

tdf#148289 sw clearing breaks: fix vertical layout

There were 3 problems here:

1) SwTextFly::GetMaxBottom() gets an already swapped frame, so going via
   the aRectFnSet abstraction is not correct, need to use Left() and
   similar functions directly.

2) SwTextCursor::AdjustBaseLine() centers portions in the vertical case,
   so a clearing break portion with larger height will push the other
   portions towards the left, and this is not wanted. Fix this by
   filtering out the (logic) height of the clearing break portions in
   the vertical case.

3) The fix for 2) has the side effect that the non-printable line break
   indicator character now has the wrong (logic) top position in
   SwBreakPortion::Paint(). Fix this by compensating for the offset done in
   AdjustBaseLine().

No functional changes intended for the horizontal layout.

(cherry picked from commit 251589c17c0dfa33cf5e5e5bb1ed782d2293a67c)

Change-Id: I9ea27b4247944cbab8e96c5c5e2c8f82bbbd731c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138339
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index 17234c9ec2c0..a571ced2f289 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -391,6 +391,49 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, 
testClearingLineBreakLeftRTL)
 assertXPath(pXmlDoc, "//SwParaPortion/SwLineLayout[1]", "height", "276");
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testClearingLineBreakVertical)
+{
+// Given a document with an anchored object in a vertical page and a 
clearing break (type=all):
+loadURL("private:factory/swriter", nullptr);
+uno::Reference xFactory(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xDocument(mxComponent, uno::UNO_QUERY);
+uno::Reference xText = xDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+uno::Reference 
xStandard(getStyles("PageStyles")->getByName("Standard"),
+  uno::UNO_QUERY);
+xStandard->setPropertyValue("WritingMode", 
uno::Any(text::WritingMode2::TB_RL));
+{
+uno::Reference xShape(
+xFactory->createInstance("com.sun.star.drawing.RectangleShape"), 
uno::UNO_QUERY);
+xShape->setSize(awt::Size(5000, 5000));
+uno::Reference xShapeProps(xShape, 
uno::UNO_QUERY);
+xShapeProps->setPropertyValue("AnchorType",
+  
uno::Any(text::TextContentAnchorType_AT_CHARACTER));
+uno::Reference xShapeContent(xShape, 
uno::UNO_QUERY);
+xText->insertTextContent(xCursor, xShapeContent, /*bAbsorb=*/false);
+}
+uno::Reference xLineBreak(
+xFactory->createInstance("com.sun.star.text.LineBreak"), 
uno::UNO_QUERY);
+uno::Reference xLineBreakProps(xLineBreak, 
uno::UNO_QUERY);
+auto eClear = static_cast(SwLineBreakClear::ALL);
+xLineBreakProps->setPropertyValue("Clear", uno::Any(eClear));
+xText->insertString(xCursor, "foo", /*bAbsorb=*/false);
+xText->insertTextContent(xCursor, xLineBreak, /*bAbsorb=*/false);
+xText->insertString(xCursor, "bar", /*bAbsorb=*/false);
+
+// When laying out that document:
+calcLayout();
+
+// Then make sure the "bar" does jump (logic) down the correct amount:
+xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 2837
+// - Actual  : 7135
+// i.e. the expected break height is the twips value of the 5cm rectangle 
size, it was much
+// more.
+assertXPath(pXmlDoc, "//SwParaPortion/SwLineLayout[1]", "height", "2837");
+}
+
 CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testClearingLineBreakHeader)
 {
 // Given a document with a shape in the header and a clearing break in the 
body text:
diff --git a/sw/source/core/text/itrtxt.cxx b/sw/source/core/text/itrtxt.cxx
index 8fb8334a83fa..772cf498acf9 100644
--- a/sw/source/core/text/itrtxt.cxx
+++ b/sw/source/core/text/itrtxt.cxx
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include "porfld.hxx"
+#include "porrst.hxx"
 
 #include "itrtxt.hxx"
 #include 
@@ -283,7 +284,41 @@ SwTwips SwTextCursor::AdjustBaseLine( const SwLineLayout& 
rLine,
 if (GetInfo().GetTextFrame()->IsVertLR() && 
!GetInfo().GetTextFrame()->IsVertLRBT())
   

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-08-16 Thread Miklos Vajna (via logerrit)
 sw/qa/core/text/text.cxx   |   42 +
 sw/source/core/text/porrst.cxx |8 ++-
 2 files changed, 49 insertions(+), 1 deletion(-)

New commits:
commit acfd903a583a384341c0f620a8b7a781b44586be
Author: Miklos Vajna 
AuthorDate: Wed Jul 27 16:35:13 2022 +0200
Commit: Miklos Vajna 
CommitDate: Tue Aug 16 10:56:39 2022 +0200

tdf#148291 sw clearing breaks: fix RTL layout

The bugreport has two documents that show clear=left and clear=right is
basically ignored in Word in the RTL paragraph case, while clear=none
and clear=all work as expected.

There was no special-casing for RTL in SwBreakPortion::Format()
previously, as the OOXML spec does talk about left/right even in case of
RTL, i.e. no expected mirroring is documented as the behavior. Looking
at [MS-OI29500], "2.1.528 Part 1 Section 17.18.3, ST_BrClear" does say
that the Word "behaves unpredictably" in the normal (non-web) layout.

Fix the problem by handling clear=left and clear=right as clear=none in
the RTL case, this fixes the rendering differences for both
bugdocuments.

If later we do want the mirrored layout, then such mirroring could be
done in SwTextFly::GetMaxBottom().

(cherry picked from commit 4e329f50e42c91704b84b1fc583d6815ab22adab)

Change-Id: I6265e64540fa9e5b893cfbea146152854416dce2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138338
Tested-by: Miklos Vajna 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index 68a8230a7bfc..17234c9ec2c0 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -12,6 +12,7 @@
 #include 
 
 #include 
+#include 
 
 #include 
 #include 
@@ -349,6 +350,47 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, 
testClearingLineBreakLeft)
 assertXPath(pXmlDoc, "//SwParaPortion/SwLineLayout[1]", "height", "2837");
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testClearingLineBreakLeftRTL)
+{
+// Given a document with an anchored object in an RTL para and a clearing 
break (type=left):
+loadURL("private:factory/swriter", nullptr);
+uno::Reference xFactory(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xDocument(mxComponent, uno::UNO_QUERY);
+uno::Reference xText = xDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+uno::Reference xCursorProps(xCursor, uno::UNO_QUERY);
+xCursorProps->setPropertyValue("WritingMode", 
uno::Any(text::WritingMode2::RL_TB));
+{
+uno::Reference xShape(
+xFactory->createInstance("com.sun.star.drawing.RectangleShape"), 
uno::UNO_QUERY);
+xShape->setSize(awt::Size(5000, 5000));
+uno::Reference xShapeProps(xShape, 
uno::UNO_QUERY);
+xShapeProps->setPropertyValue("AnchorType",
+  
uno::Any(text::TextContentAnchorType_AT_CHARACTER));
+uno::Reference xShapeContent(xShape, 
uno::UNO_QUERY);
+xText->insertTextContent(xCursor, xShapeContent, /*bAbsorb=*/false);
+}
+uno::Reference xLineBreak(
+xFactory->createInstance("com.sun.star.text.LineBreak"), 
uno::UNO_QUERY);
+uno::Reference xLineBreakProps(xLineBreak, 
uno::UNO_QUERY);
+auto eClear = static_cast(SwLineBreakClear::RIGHT);
+xLineBreakProps->setPropertyValue("Clear", uno::Any(eClear));
+xText->insertString(xCursor, "foo", /*bAbsorb=*/false);
+xText->insertTextContent(xCursor, xLineBreak, /*bAbsorb=*/false);
+xText->insertString(xCursor, "bar", /*bAbsorb=*/false);
+
+// When laying out that document:
+calcLayout();
+
+// Then make sure the "bar" does not jump down (due to type=left && RTL):
+xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 276
+// - Actual  : 2837
+// i.e. left/right was not ignored in the RTL case.
+assertXPath(pXmlDoc, "//SwParaPortion/SwLineLayout[1]", "height", "276");
+}
+
 CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testClearingLineBreakHeader)
 {
 // Given a document with a shape in the header and a clearing break in the 
body text:
diff --git a/sw/source/core/text/porrst.cxx b/sw/source/core/text/porrst.cxx
index f2d2b0cdd168..961c399ca5c1 100644
--- a/sw/source/core/text/porrst.cxx
+++ b/sw/source/core/text/porrst.cxx
@@ -177,7 +177,13 @@ bool SwBreakPortion::Format( SwTextFormatInfo  )
 
 // See if this is a clearing break. If so, calculate how much we need to 
"jump down" so the next
 // line can again use the full text width.
-if (m_eClear != SwLineBreakClear::NONE)
+SwLineBreakClear eClear = m_eClear;
+if (rInf.GetTextFrame()->IsRightToLeft() && eClear != 
SwLineBreakClear::ALL)
+{
+// RTL ignores left/right breaks.
+eClear = SwLineBreakClear::NONE;
+}
+if (eClear != SwLineBreakClear::NONE)
 {
 SwTextFly& rTextFly = rInf.GetTextFly();
  

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-07-27 Thread Miklos Vajna (via logerrit)
 sw/qa/core/unocore/unocore.cxx|   20 
 sw/source/core/txtnode/thints.cxx |   25 +
 2 files changed, 45 insertions(+)

New commits:
commit d3039206783ad36aaec6356512c623f93f7522e9
Author: Miklos Vajna 
AuthorDate: Thu Jul 21 08:07:27 2022 +0200
Commit: Miklos Vajna 
CommitDate: Wed Jul 27 08:32:44 2022 +0200

sw content controls, plain text: apply formatting to the entire contents

The difference between normal (rich text) content control and a plain
text one is that if you try to format a subset of the contents, that's
possible in the rich text case, but the plain text case extends the
formatted range to the entire content control.

Handle this in SwTextNode::InsertHint(), similar to how it's done for
input fields.

(cherry picked from commit 1dce9ee7e12871ee63434499db805e806b9e9d3c)

Change-Id: I9a1ad0095f0ca810da24d5c4ce4aa48d1ac59225
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137471
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx
index daf34fb89a73..065692fef7f3 100644
--- a/sw/qa/core/unocore/unocore.cxx
+++ b/sw/qa/core/unocore/unocore.cxx
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -618,6 +619,25 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, 
testContentControlPlainText)
 = static_cast(pTextContentControl->GetAttr());
 std::shared_ptr pContentControl = 
rFormatContentControl.GetContentControl();
 CPPUNIT_ASSERT(pContentControl->GetPlainText());
+
+// Now check if the char index range 2-4 is extended to 0-6 when we apply 
formatting:
+pWrtShell->SttEndDoc(/*bStt=*/true);
+// Select "es" from "test".
+pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 2, 
/*bBasicCall=*/false);
+pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 2, 
/*bBasicCall=*/false);
+SfxItemSetFixed 
aSet(pWrtShell->GetAttrPool());
+SvxWeightItem aItem(WEIGHT_BOLD, RES_CHRATR_WEIGHT);
+aSet.Put(aItem);
+pWrtShell->SetAttrSet(aSet);
+pAttr = pTextNode->GetTextAttrAt(2, RES_TXTATR_AUTOFMT);
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 0
+// - Actual  : 2
+// i.e. the plain text content control now had 3 portions 
(test), instead
+// of one (test).
+CPPUNIT_ASSERT_EQUAL(static_cast(0), pAttr->GetStart());
+CPPUNIT_ASSERT(pAttr->End());
+CPPUNIT_ASSERT_EQUAL(static_cast(6), *pAttr->End());
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/txtnode/thints.cxx 
b/sw/source/core/txtnode/thints.cxx
index e84858707ba8..63897088ab3c 100644
--- a/sw/source/core/txtnode/thints.cxx
+++ b/sw/source/core/txtnode/thints.cxx
@@ -1687,6 +1687,31 @@ bool SwTextNode::InsertHint( SwTextAttr * const pAttr, 
const SetAttrMode nMode )
 }
 }
 
+{
+// Handle the invariant that a plain text content control has the same 
character formatting
+// for all of its content.
+auto* pTextContentControl = static_txtattr_cast(
+GetTextAttrAt(pAttr->GetStart(), RES_TXTATR_CONTENTCONTROL, 
PARENT));
+if (pTextContentControl)
+{
+auto& rFormatContentControl
+= 
static_cast(pTextContentControl->GetAttr());
+std::shared_ptr pContentControl
+= rFormatContentControl.GetContentControl();
+if (pAttr->End() != nullptr && pContentControl->GetPlainText())
+{
+if (pAttr->GetStart() > pTextContentControl->GetStart())
+{
+pAttr->SetStart(pTextContentControl->GetStart());
+}
+if (*pAttr->End() < *pTextContentControl->End())
+{
+pAttr->SetEnd(*pTextContentControl->End());
+}
+}
+}
+}
+
 const bool bRet = bInsertHint
   && m_pSwpHints->TryInsertHint( pAttr, *this, nMode );
 


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-07-19 Thread Szymon Kłos (via logerrit)
 sw/qa/extras/tiledrendering/data/multiline.odt |binary
 sw/qa/extras/tiledrendering/tiledrendering.cxx |   40 +
 sw/source/filter/html/htmlatr.cxx  |   13 +---
 sw/source/filter/html/wrthtml.cxx  |4 +-
 sw/source/filter/html/wrthtml.hxx  |3 +
 sw/source/uibase/dochdl/swdtflvr.cxx   |2 -
 6 files changed, 55 insertions(+), 7 deletions(-)

New commits:
commit 9ab3be6bc0848e44f88ae157c7e8323335246897
Author: Szymon Kłos 
AuthorDate: Fri Nov 19 12:38:18 2021 +0100
Commit: Henry Castro 
CommitDate: Tue Jul 19 20:58:41 2022 +0200

lok: don't pretty print html for online

followup for "lok: don't limit line length in HTMLWriter"

Pretty printing makes html more readable for human but introduces
lots of new line marks which are later interpreted in the client
as a valid new lines in the document content.

This was causing multiplying the line breaks when inserting hyperlinks
where we read current selection's content and then we pass it back
to the core as link's content (with added new lines).

This change needs cypress change to not contain "\n" at the beginning
of some content read from the document.

This also afects copying from the online document to clipboard.

Change-Id: I2b17d62398d947fcf1d3fb1ed6005c3063d114f2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136893
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Henry Castro 

diff --git a/sw/qa/extras/tiledrendering/data/multiline.odt 
b/sw/qa/extras/tiledrendering/data/multiline.odt
new file mode 100644
index ..4c60b58decb2
Binary files /dev/null and b/sw/qa/extras/tiledrendering/data/multiline.odt 
differ
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 6db7cd57dfdd..5b0443884ad8 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -425,6 +425,46 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, 
testGetTextSelectionLineLimit)
 CPPUNIT_ASSERT(sHtmlText.match(sExpectedHtml, nStart));
 }
 
+CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testGetTextSelectionMultiLine)
+{
+// Test will check if correct number of new line marks / paragraphs is 
generated
+const char sOriginalText[] = u8"Heading\n\
+Let's have text; we need to be able to select the text inside the shape, but 
also the various individual ones too:\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+And this is all for Writer shape objects\n\
+Heading on second page";
+
+const char sExpectedHtml[] = u8"Heading\n\
+Let's have text; we need to be able to select the text inside the shape, 
but also the various individual ones too:\n\
+\n\
+\n\
+\n\
+\n\
+\n\
+And this is all for Writer shape objects\n\
+Heading on second page";
+
+SwXTextDocument* pXTextDocument = createDoc("multiline.odt");
+
+SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
+// Create a selection.
+pWrtShell->SelAll();
+
+OString sPlainText = 
apitest::helper::transferable::getTextSelection(pXTextDocument->getSelection(), 
"text/plain;charset=utf-8");
+
+CPPUNIT_ASSERT_EQUAL(OString(sOriginalText), sPlainText.trim());
+
+OString sHtmlText = 
apitest::helper::transferable::getTextSelection(pXTextDocument->getSelection(), 
"text/html");
+
+int nStart = sHtmlText.indexOf(u8"Heading");
+
+CPPUNIT_ASSERT(sHtmlText.match(sExpectedHtml, nStart));
+}
+
 CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testSetGraphicSelection)
 {
 SwXTextDocument* pXTextDocument = createDoc("shape.fodt");
diff --git a/sw/source/filter/html/htmlatr.cxx 
b/sw/source/filter/html/htmlatr.cxx
index 51f059d5a2cc..9b6c5b5d8155 100644
--- a/sw/source/filter/html/htmlatr.cxx
+++ b/sw/source/filter/html/htmlatr.cxx
@@ -770,6 +770,7 @@ static void OutHTML_SwFormat( Writer& rWrt, const SwFormat& 
rFormat,
 if( rInfo.bInNumberBulletList && bNumberedForListItem )
 {
 HtmlWriter html(rWrt.Strm(), rHWrt.maNamespace);
+html.prettyPrint(rHWrt.m_bPrettyPrint);
 html.start(OOO_STRING_SVTOOLS_HTML_li);
 if( USHRT_MAX != nNumStart )
 html.attribute(OOO_STRING_SVTOOLS_HTML_O_value, 
OString::number(nNumStart));
@@ -1000,7 +1001,7 @@ static void OutHTML_SwFormatOff( Writer& rWrt, const 
SwHTMLTextCollOutputInfo& r
 
 if( rInfo.ShouldOutputToken() )
 {
-if( rHWrt.m_bLFPossible )
+if( rHWrt.m_bPrettyPrint && rHWrt.m_bLFPossible )
 rHWrt.OutNewLine( true );
 
 // if necessary, for BLOCKQUOTE, ADDRESS and DD another paragraph token
@@ -2039,6 +2040,7 @@ Writer& OutHTML_SwTextNode( Writer& rWrt, const 
SwContentNode& rNode )
 rHTMLWrt.m_bLFPossible = true;
 
 HtmlWriter aHtml(rWrt.Strm(), rHTMLWrt.maNamespace);
+aHtml.prettyPrint(rHTMLWrt.m_bPrettyPrint);
 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-07-19 Thread Miklos Vajna (via logerrit)
 sw/qa/core/txtnode/txtnode.cxx|   23 ++-
 sw/source/core/txtnode/attrcontentcontrol.cxx |2 +-
 2 files changed, 23 insertions(+), 2 deletions(-)

New commits:
commit feae19389a2bd6ffe8cb7f2a1a34da4c6efb828b
Author: Miklos Vajna 
AuthorDate: Tue Jul 19 08:28:21 2022 +0200
Commit: Miklos Vajna 
CommitDate: Tue Jul 19 15:34:02 2022 +0200

sw content control, date: allow selecting via the keyboard

It was not possible to select the date of a date content control via
keyboard.

This meant only the mouse handling codepath needed implementing, but it
broke accessibility.

SwContentControl::ShouldOpenPopup() already knows how to handle
dropdowns via the keyboard, extend that to handle date pickers as well.

The appearing vcl Calendar / GtkCalendar appears to support keyboard
navigation already.

(cherry picked from commit 40405372fe0bbc00e67f5b0185b0d4c2d6c1e08d)

Change-Id: Ic36419f69cbcdba1a9069332184966cb4b347c49
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137229
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/txtnode/txtnode.cxx b/sw/qa/core/txtnode/txtnode.cxx
index 15d2188a8cb6..bd9bcd66d6fc 100644
--- a/sw/qa/core/txtnode/txtnode.cxx
+++ b/sw/qa/core/txtnode/txtnode.cxx
@@ -270,7 +270,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, 
testDropdownContentControlKeyboard)
 CPPUNIT_ASSERT(bShouldOpen);
 }
 
-CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testPicutreContentControlKeyboard)
+CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testPictureContentControlKeyboard)
 {
 // Given an already selected picture content control:
 SwDoc* pDoc = createSwDoc();
@@ -297,6 +297,27 @@ CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, 
testPicutreContentControlKeyboard)
 CPPUNIT_ASSERT(bIsInteracting);
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testDateContentControlKeyboard)
+{
+// Given an already selected date content control:
+SwDoc* pDoc = createSwDoc();
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+pWrtShell->InsertContentControl(SwContentControlType::DATE);
+
+// When checking if alt-down should open a popup:
+SwTextContentControl* pTextContentControl = 
pWrtShell->CursorInsideContentControl();
+auto& rFormatContentControl
+= static_cast(pTextContentControl->GetAttr());
+std::shared_ptr pContentControl = 
rFormatContentControl.GetContentControl();
+vcl::KeyCode aKeyCode(KEY_DOWN, KEY_MOD2);
+bool bShouldOpen = pContentControl->ShouldOpenPopup(aKeyCode);
+
+// Then make sure that the answer is yes for date:
+// Without the accompanying fix in place, this test would have failed, the 
date popup was
+// mouse-only.
+CPPUNIT_ASSERT(bShouldOpen);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/txtnode/attrcontentcontrol.cxx 
b/sw/source/core/txtnode/attrcontentcontrol.cxx
index c917de926296..e348432ba7b6 100644
--- a/sw/source/core/txtnode/attrcontentcontrol.cxx
+++ b/sw/source/core/txtnode/attrcontentcontrol.cxx
@@ -319,7 +319,7 @@ bool SwContentControl::IsInteractingCharacter(sal_Unicode 
cCh)
 
 bool SwContentControl::ShouldOpenPopup(const vcl::KeyCode& rKeyCode)
 {
-if (HasListItems())
+if (HasListItems() || GetDate())
 {
 // Alt-down opens the popup.
 return rKeyCode.IsMod2() && rKeyCode.GetCode() == KEY_DOWN;


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-07-18 Thread Tomaž Vajngerl (via logerrit)
 sw/qa/extras/uiwriter/data/HiddenSection.odt |binary
 sw/qa/extras/uiwriter/uiwriter2.cxx  |   50 +++
 sw/source/core/doc/docfld.cxx|   28 ++-
 sw/source/core/docnode/ndsect.cxx|1 
 4 files changed, 77 insertions(+), 2 deletions(-)

New commits:
commit 70d201c857fe86834f618f8c66df6f19b76c2556
Author: Tomaž Vajngerl 
AuthorDate: Thu Jul 14 11:07:45 2022 +0200
Commit: Andras Timar 
CommitDate: Mon Jul 18 15:38:24 2022 +0200

tdf#54703 fix unhiding at PDF export of cond. hidden sections

The conditionally hidden sections became visible when PDF export
is performed. This is due to field update where we temporary made
the conditionally hidden section visible (as the frame is needed),
but never put them back to hidden. Probably the expectation was
that the condition will be recalculated later on, but wasn't. This
change fixes this so that the changed sections will be recalculated
at the end.

Change-Id: Ic6d8a4a38f22ed961b2b37e05aaf3e720fc50ed4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137052
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137162
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Andras Timar 

diff --git a/sw/qa/extras/uiwriter/data/HiddenSection.odt 
b/sw/qa/extras/uiwriter/data/HiddenSection.odt
new file mode 100644
index ..8358cbc9951a
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/HiddenSection.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index f895b59ba402..6db1b70051fc 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -30,10 +30,12 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -6069,6 +6071,54 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf126735)
 CPPUNIT_ASSERT_EQUAL(OUString("or "), xTextRange->getString());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testConditionalHiddenSectionIssue)
+{
+// tdf#54703
+// When exporting the bug document as PDF, the conditional hidden
+// sections became visible in the PDF and in the document.
+
+std::shared_ptr pPDFium = vcl::pdf::PDFiumLibrary::get();
+if (!pPDFium)
+return;
+
+SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "HiddenSection.odt");
+
+// Check section conditional hidden status - all should be hidden 
(IsCondHidden == true)
+for (SwNodeOffset i(0); i < pDoc->GetNodes().Count(); ++i)
+{
+if (SwSectionNode const* const pNode = 
pDoc->GetNodes()[i]->GetSectionNode())
+{
+CPPUNIT_ASSERT_EQUAL(true, pNode->GetSection().IsCondHidden());
+}
+}
+
+// PDF export
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+utl::MediaDescriptor aMediaDescriptor;
+aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
+xStorable->storeToURL(maTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
+
+SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
+SvMemoryStream aMemory;
+aMemory.WriteStream(aFile);
+auto pPdfDocument = pPDFium->openDocument(aMemory.GetData(), 
aMemory.GetSize());
+CPPUNIT_ASSERT(pPdfDocument);
+auto pPdfPage = pPdfDocument->openPage(0);
+CPPUNIT_ASSERT(pPdfPage);
+
+// No PDF object should be present in the page - sections remained hidden
+CPPUNIT_ASSERT_EQUAL(0, pPdfPage->getObjectCount());
+
+// Check section conditional hidden status - all should remained hidden 
(IsCondHidden == true)
+for (SwNodeOffset i(0); i < pDoc->GetNodes().Count(); ++i)
+{
+if (SwSectionNode const* const pNode = 
pDoc->GetNodes()[i]->GetSectionNode())
+{
+CPPUNIT_ASSERT_EQUAL(true, pNode->GetSection().IsCondHidden());
+}
+}
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx
index 652af8a188b9..fb1e71f3b190 100644
--- a/sw/source/core/doc/docfld.cxx
+++ b/sw/source/core/doc/docfld.cxx
@@ -839,6 +839,9 @@ void SwDocUpdateField::MakeFieldList_( SwDoc& rDoc, int 
eGetMode )
 // new version: walk all fields of the attribute pool
 m_pFieldSortList.reset(new SetGetExpFields);
 
+// remembeer sections that were unhidden and need to be hidden again
+std::vector> aUnhiddenSections;
+
 // consider and unhide sections
 // with hide condition, only in mode GETFLD_ALL ()
 // notes by OD:
@@ -885,13 +888,27 @@ void SwDocUpdateField::MakeFieldList_( SwDoc& rDoc, int 
eGetMode )
 {
 pSectNd = rDoc.GetNodes()[ aTmpArr[ n ] ]->GetSectionNode();
 OSL_ENSURE( pSectNd, "Where is my SectionNode" );
-pSectNd->GetSection().SetCondHidden( false );
+
+  

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-07-18 Thread Miklos Vajna (via logerrit)
 sw/qa/core/txtnode/txtnode.cxx|   27 +
 sw/source/core/txtnode/attrcontentcontrol.cxx |5 
 sw/source/uibase/docvw/edtwin.cxx |   32 ++
 3 files changed, 64 insertions(+)

New commits:
commit fe072bf9e52ab4c0bd7b692940092ca296edfe59
Author: Miklos Vajna 
AuthorDate: Mon Jul 18 11:18:28 2022 +0200
Commit: Miklos Vajna 
CommitDate: Mon Jul 18 15:22:59 2022 +0200

sw content control, picture: allow replacing via the keyboard

It was not possible to replace a picture placeholder with an actual
bitmap without using the mouse, which breaks accessibility.

The mouse handling code was added in commit
b213abcb77e19fa5d22af45c7ecd17c8a63af554 (sw content controls, picture:
replace placeholder image on click, 2022-05-18), which already split the
functionality between SwEditWin::MouseButtonUp() and
SwWrtShell::GotoContentControl().

Fix the problem by reusing the shared SwWrtShell::GotoContentControl()
and extending SwEditWin::KeyInput() to allow doing the same with the
keyboard. This way the scenario when Shift-F4 selects the frame and the
user presses Enter now triggers the filepicker.

A possible future improvement would be to also handle Enter similarly
when the text cursor is inside a picture content control, but that's not
implemented here.

(cherry picked from commit aaebfb9baf53e4ed221a9bb8e1772fcbb7b921ab)

Change-Id: I756395d3811e3f4dfdce698751c4de13a0d49729
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137197
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/txtnode/txtnode.cxx b/sw/qa/core/txtnode/txtnode.cxx
index 7791cf82bbc3..15d2188a8cb6 100644
--- a/sw/qa/core/txtnode/txtnode.cxx
+++ b/sw/qa/core/txtnode/txtnode.cxx
@@ -270,6 +270,33 @@ CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, 
testDropdownContentControlKeyboard)
 CPPUNIT_ASSERT(bShouldOpen);
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testPicutreContentControlKeyboard)
+{
+// Given an already selected picture content control:
+SwDoc* pDoc = createSwDoc();
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+pWrtShell->InsertContentControl(SwContentControlType::PICTURE);
+pWrtShell->GotoObj(/*bNext=*/true, GotoObjFlags::Any);
+
+// When checking if enter should trigger the file picker:
+const SwFrameFormat* pFlyFormat = pWrtShell->GetFlyFrameFormat();
+const SwFormatAnchor& rFormatAnchor = pFlyFormat->GetAnchor();
+const SwPosition* pAnchorPos = rFormatAnchor.GetContentAnchor();
+SwTextNode* pTextNode = pAnchorPos->nNode.GetNode().GetTextNode();
+SwTextAttr* pAttr = 
pTextNode->GetTextAttrAt(pAnchorPos->nContent.GetIndex(),
+ RES_TXTATR_CONTENTCONTROL, 
SwTextNode::PARENT);
+auto pTextContentControl = 
static_txtattr_cast(pAttr);
+auto& rFormatContentControl
+= static_cast(pTextContentControl->GetAttr());
+std::shared_ptr pContentControl = 
rFormatContentControl.GetContentControl();
+bool bIsInteracting = pContentControl->IsInteractingCharacter('\r');
+
+// Then make sure that the answer is yes for pictures:
+// Without the accompanying fix in place, this test would have failed, the 
picture replacement
+// file-picker was mouse-only.
+CPPUNIT_ASSERT(bIsInteracting);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/txtnode/attrcontentcontrol.cxx 
b/sw/source/core/txtnode/attrcontentcontrol.cxx
index 2f4552f2f758..c917de926296 100644
--- a/sw/source/core/txtnode/attrcontentcontrol.cxx
+++ b/sw/source/core/txtnode/attrcontentcontrol.cxx
@@ -309,6 +309,11 @@ bool SwContentControl::IsInteractingCharacter(sal_Unicode 
cCh)
 return cCh == ' ';
 }
 
+if (GetPicture())
+{
+return cCh == '\r';
+}
+
 return false;
 }
 
diff --git a/sw/source/uibase/docvw/edtwin.cxx 
b/sw/source/uibase/docvw/edtwin.cxx
index c765e3b42d7e..bca062c9bcc6 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -1540,6 +1540,38 @@ void SwEditWin::KeyInput(const KeyEvent )
 }
 
 const SwFrameFormat* pFlyFormat = rSh.GetFlyFrameFormat();
+
+if (pFlyFormat)
+{
+// See if the fly frame's anchor is in a content control. If so,
+// try to interact with it.
+const SwFormatAnchor& rFormatAnchor = pFlyFormat->GetAnchor();
+const SwPosition* pAnchorPos = rFormatAnchor.GetContentAnchor();
+if (pAnchorPos)
+{
+SwTextNode* pTextNode = pAnchorPos->nNode.GetNode().GetTextNode();
+if (pTextNode)
+{
+SwTextAttr* pAttr = pTextNode->GetTextAttrAt(
+pAnchorPos->nContent.GetIndex(), 
RES_TXTATR_CONTENTCONTROL, SwTextNode::PARENT);
+if (pAttr)

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-06-20 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx  |   41 
 sw/source/filter/html/htmlatr.cxx   |   12 +++--
 sw/source/filter/html/htmlnumwriter.cxx |4 ++-
 sw/source/filter/html/wrthtml.hxx   |3 +-
 4 files changed, 56 insertions(+), 4 deletions(-)

New commits:
commit 846079db0cf519c396125a8dfedd86ad560c26dd
Author: Miklos Vajna 
AuthorDate: Thu Jun 16 15:55:23 2022 +0200
Commit: Miklos Vajna 
CommitDate: Mon Jun 20 09:49:33 2022 +0200

sw HTML export, XHTML mode: fix lost  with a list header + item

There is a general mismatch between XHTML and Writer lists: XHTML can
only contain list items (for ordered or unordered lists), while Writer
can contain list headers and list items. List headers have no bullet or
number at the start, list items are the normal text nodes.

Commit 8c2607ae3ce143586e623532b8ae5288277ec3ac (sw HTML export, XHTML
mode: fix lost  when last list item is not numbered, 2022-02-21)
fixed the list item end side of this problem: if all text nodes in a
list are headers, then don't write ul/ol at all, otherwise end list
headers with  as well to make sure the output XML is valid.
However, this created a mis-match, the starting  for list headers in
a list which have non-header text nodes at as was not adapted.

Fix the problem by extending OutHTML_SwFormat() so list headers in a
list with non-header text nodes always have a  and , and this
condition is the same on the start/end side.

Calculating if at least one text node is non-header in a list may not be
cheap, so reuse the already calculated info from
OutHTML_NumberBulletListStart() in OutHTML_SwFormat().

(cherry picked from commit 472a40b022ef685610faa663421a00cfe6121c24)

Change-Id: I3817a489f16166fc5b4c33ee64e2283c41a4402c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136136
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index c1e7d945dedb..21feaa0b5e73 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1535,6 +1535,47 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testPartiallyNumberedList)
 
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:p",
 2);
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testListHeaderAndItem)
+{
+// Given a document with a list, first para is not numbered, but the 
second is:
+loadURL("private:factory/swriter", nullptr);
+SwXTextDocument* pTextDoc = 
dynamic_cast(mxComponent.get());
+SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+pWrtShell->Insert("not numbered");
+SwDoc* pDoc = pWrtShell->GetDoc();
+sal_uInt16 nPos = pDoc->MakeNumRule(pDoc->GetUniqueNumRuleName());
+SwNumRule* pNumRule = pDoc->GetNumRuleTable()[nPos];
+{
+SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+SwTextNode& rTextNode = *rNode.GetTextNode();
+rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+rTextNode.SetCountedInList(false);
+}
+pWrtShell->SplitNode();
+pWrtShell->Insert2("numbered");
+{
+SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+SwTextNode& rTextNode = *rNode.GetTextNode();
+rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+}
+
+// When exporting to ReqIF:
+ExportToReqif();
+
+// Then make sure the output is well-formed xhtml:
+SvMemoryStream aStream;
+HtmlExportTest::wrapFragment(maTempFile, aStream);
+xmlDocUniquePtr pXmlDoc = parseXmlStream();
+// Without the accompanying fix in place, this test would have failed:
+// Entity: line 3: parser error : Opening and ending tag mismatch: ol line 
3 and li
+// not 
numbered
+CPPUNIT_ASSERT(pXmlDoc);
+// Make sure that in case the list has a header and an item, then both are 
wrapped in an 
+// element.
+assertXPath(pXmlDoc,
+
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:p",
 2);
+}
+
 CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testBlockQuoteNoMargin)
 {
 // Given a document with some text, para style set to Quotations, no 
bottom margin:
diff --git a/sw/source/filter/html/htmlatr.cxx 
b/sw/source/filter/html/htmlatr.cxx
index e50a5f06d6c1..51f059d5a2cc 100644
--- a/sw/source/filter/html/htmlatr.cxx
+++ b/sw/source/filter/html/htmlatr.cxx
@@ -686,11 +686,12 @@ static void OutHTML_SwFormat( Writer& rWrt, const 
SwFormat& rFormat,
 if( nNewDefListLvl != rHWrt.m_nDefListLvl )
 rHWrt.OutAndSetDefList( nNewDefListLvl );
 
+bool bAtLeastOneNumbered = false;
 // if necessary, start a bulleted or numbered list
 if( rInfo.bInNumberBulletList )
 {
 OSL_ENSURE( !rHWrt.m_nDefListLvl, "DL cannot be 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-06-15 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx |8 +++-
 sw/source/filter/html/css1atr.cxx  |   21 +++--
 2 files changed, 26 insertions(+), 3 deletions(-)

New commits:
commit 3babba2da3ba4677562b9ceeef4f1dd6e204807f
Author: Miklos Vajna 
AuthorDate: Fri Jun 10 09:12:33 2022 +0200
Commit: Miklos Vajna 
CommitDate: Wed Jun 15 10:51:36 2022 +0200

sw XHTML export: avoid writing default transparent background for ReqIF

We started writing properties of tables and rows since commit
c3c3303516c3da9372dce3f05f38f15a104e961c (sw XHTML export: output table
/ table row background format using CSS, 2022-05-10).

In case the SwTableLine has an explicit SvxBrushItem with its color set
to COL_TRANSPARENT, we turn that into a "background: transparent" CSS by
default. This is a 1:1 mapping from the doc model, but HTML defaults to
this already, so this is considered as noise.

Extend IgnorePropertyForReqIF() to filter out these unwanted defaults,
and fix SwHTMLWriter::OutCSS1_Property(), because it used to not pass
the CSS value for the filter function.

The behavior for table cells is unchanged, we continue to not export
cell properties (in the ReqIF case) at all.

Change-Id: Idbcd07809e159def694f4de017eebc7ad4104575
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135576
Tested-by: Jenkins
Reviewed-by: Miklos Vajna 
(cherry picked from commit 04cc6e079e3122c183054fde046c054ed6c7b737)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135707
Reviewed-by: Michael Stahl 
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135860
Tested-by: Jenkins CollaboraOffice 

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index dc4bc70bb56b..c1e7d945dedb 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -2177,10 +2177,14 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testTableBackground)
 pWrtShell->SetTabBackground(aBrush);
 pWrtShell->Down(/*bSelect=*/false);
 pWrtShell->SplitNode();
-pWrtShell->InsertTable(aInsertTableOptions, /*nRows=*/1, /*nCols=*/1);
+pWrtShell->InsertTable(aInsertTableOptions, /*nRows=*/2, /*nCols=*/1);
 pWrtShell->MoveTable(GotoPrevTable, fnTableStart);
 aBrush.SetColor(0x00ff00);
 pWrtShell->SetRowBackground(aBrush);
+pWrtShell->Down(/*bSelect=*/false);
+// Second row has an explicit transparent background.
+aBrush.SetColor(COL_TRANSPARENT);
+pWrtShell->SetRowBackground(aBrush);
 
 // When exporting to reqif-xhtml:
 ExportToReqif();
@@ -2197,6 +2201,8 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testTableBackground)
 assertXPath(pXmlDoc, "//reqif-xhtml:table[2]/reqif-xhtml:tr[1]", "style",
 "background: #00ff00");
 assertXPathNoAttribute(pXmlDoc, 
"//reqif-xhtml:table[2]/reqif-xhtml:tr[1]", "bgcolor");
+// Second row has no explicit style, the default is not written.
+assertXPathNoAttribute(pXmlDoc, 
"//reqif-xhtml:table[2]/reqif-xhtml:tr[2]", "style");
 }
 
 CPPUNIT_TEST_FIXTURE(HtmlExportTest, testImageKeepRatio)
diff --git a/sw/source/filter/html/css1atr.cxx 
b/sw/source/filter/html/css1atr.cxx
index 2667972a98be..f3d9a22c5140 100644
--- a/sw/source/filter/html/css1atr.cxx
+++ b/sw/source/filter/html/css1atr.cxx
@@ -185,9 +185,21 @@ OString lclConvToHex(sal_uInt16 nHex)
 bool IgnorePropertyForReqIF(bool bReqIF, std::string_view rProperty, 
std::string_view rValue,
 std::optional oMode)
 {
-if (!bReqIF || (oMode.has_value() && *oMode != 
sw::Css1Background::TableCell))
+if (!bReqIF)
 return false;
 
+if (oMode.has_value() && *oMode != sw::Css1Background::TableCell)
+{
+// Table or row.
+if (rProperty == sCSS1_P_background && rValue == "transparent")
+{
+// This is the default already.
+return true;
+}
+
+return false;
+}
+
 // Only allow these two keys, nothing else in ReqIF mode.
 if (rProperty == sCSS1_P_text_decoration)
 {
@@ -244,7 +256,12 @@ void SwHTMLWriter::OutCSS1_Property( const char *pProp,
  const OUString *pSVal,
  std::optional oMode )
 {
-if (IgnorePropertyForReqIF(mbReqIF, pProp, sVal, oMode))
+OString aPropertyValue(sVal);
+if (aPropertyValue.isEmpty() && pSVal)
+{
+aPropertyValue = pSVal->toUtf8();
+}
+if (IgnorePropertyForReqIF(mbReqIF, pProp, aPropertyValue, oMode))
 return;
 
 OStringBuffer sOut;


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-06-15 Thread Miklos Vajna (via logerrit)
 sw/qa/uibase/shells/shells.cxx  |   30 ++
 sw/source/uibase/shells/textsh1.cxx |2 +-
 2 files changed, 31 insertions(+), 1 deletion(-)

New commits:
commit 83eae71c6c43dcb6bb50743f848088320d3d97a8
Author: Miklos Vajna 
AuthorDate: Fri Jun 10 16:13:04 2022 +0200
Commit: Miklos Vajna 
CommitDate: Wed Jun 15 08:14:37 2022 +0200

tdf#149509 sw content controls: reject page break insertion

Similar to input fields, the intention is to keep the start and end of
(inline) content controls within the same text node, so just disable the
command in this context, as Word does.

(cherry picked from commit aa5824b2a6df99ef9d788a8d37bdfa77582375c8)

Change-Id: Ib797ad164a3a36b4bbde4d686cde29adf6db96bf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135822
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx
index e1f5d048c018..4bde6eab7ac6 100644
--- a/sw/qa/uibase/shells/shells.cxx
+++ b/sw/qa/uibase/shells/shells.cxx
@@ -208,6 +208,36 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, 
testBibliographyLocalCopyContextMenu)
 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eState);
 }
 
+CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testContentControlPageBreak)
+{
+// Given a document with a content control and a cursor inside the content 
control:
+SwDoc* pDoc = createSwDoc();
+uno::Reference xMSF(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xText = xTextDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+xText->insertString(xCursor, "test", /*bAbsorb=*/false);
+xCursor->gotoStart(/*bExpand=*/false);
+xCursor->gotoEnd(/*bExpand=*/true);
+uno::Reference xContentControl(
+xMSF->createInstance("com.sun.star.text.ContentControl"), 
uno::UNO_QUERY);
+xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+pWrtShell->SttEndDoc(/*bStt=*/true);
+pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
+
+// When trying to insert a page break:
+dispatchCommand(mxComponent, ".uno:InsertPagebreak", {});
+
+// Then make sure that the document still has a single page:
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 1
+// - Actual  : 2
+// i.e. inline content control had its start and end in different text 
nodes, which is not
+// allowed.
+CPPUNIT_ASSERT_EQUAL(1, getPages());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/shells/textsh1.cxx 
b/sw/source/uibase/shells/textsh1.cxx
index ceba4f56522c..8d7c07e104ca 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -1894,7 +1894,7 @@ void SwTextShell::GetState( SfxItemSet  )
 case FN_INSERT_BREAK_DLG:
 case FN_INSERT_COLUMN_BREAK:
 case FN_INSERT_PAGEBREAK:
-if( rSh.CursorInsideInputField() )
+if( rSh.CursorInsideInputField() || 
rSh.CursorInsideContentControl() )
 {
 rSet.DisableItem( nWhich );
 }


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-06-13 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx |5 +--
 sw/source/filter/html/css1atr.cxx  |   45 +
 sw/source/filter/html/wrthtml.hxx  |   24 -
 3 files changed, 43 insertions(+), 31 deletions(-)

New commits:
commit 0395daea463c28473466285c25638e870c7bb851
Author: Miklos Vajna 
AuthorDate: Fri Jun 10 08:08:52 2022 +0200
Commit: Miklos Vajna 
CommitDate: Mon Jun 13 14:24:52 2022 +0200

sw XHTML export: avoid writing background of table cells in ReqIF mode

ReqIF mostly forbids using CSS styling on elements:
IgnorePropertyForReqIF() only allows 2 CSS keys by default.

This restriction was relaxed in commit
c3c3303516c3da9372dce3f05f38f15a104e961c (sw XHTML export: output table
/ table row background format using CSS, 2022-05-10), to allow
background for tables and table rows, using CSS markup. An unwanted side
effect of this is background for table cells, which is still considered
invalid. To make this nontrivial to fix, Css1Background::Table is used
to track formatting for all of tables, rows and cells.

Fix the problem by extending Css1Background with a TableRow and
TableCell and then audit all uses of Css1Background::Table to explicitly
say if they mean table, row or cell. This keeps table and row
backgrounds, but fixes the unwanted cell background.

Also document the 3 functions doing the export of table / row / cell
background export to improve readability.

Change-Id: I03301b1fd25593cbe83489dbf140e80138d4a0de
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135570
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins
(cherry picked from commit d701eff3519287db599a2612a635bc5f610ba082)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135542
Reviewed-by: Michael Stahl 
(cherry picked from commit 2744a1d2a2ccc6ddf8c5c939af6480a5e72b9e1a)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135687
Tested-by: Jenkins CollaboraOffice 

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 997537012bb8..dc4bc70bb56b 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -803,9 +803,8 @@ DECLARE_HTMLEXPORT_TEST(testReqIfTable, "reqif-table.xhtml")
 //  was missing, so the XHTML fragment wasn't a valid
 // xhtml.BlkStruct.class type anymore.
 assertXPath(pDoc, "/html/body/div/table/tr/th", 1);
-// Make sure that row background is written using CSS.
-OUString aStyle = getXPath(pDoc, "/html/body/div/table/tr/th", "style");
-CPPUNIT_ASSERT(aStyle.startsWith("background: "));
+// Make sure that the cell background is not written using CSS.
+assertXPathNoAttribute(pDoc, "/html/body/div/table/tr/th", "style");
 // The attribute was present, which is not valid in reqif-xhtml.
 assertXPathNoAttribute(pDoc, "/html/body/div/table/tr/th", "bgcolor");
 }
diff --git a/sw/source/filter/html/css1atr.cxx 
b/sw/source/filter/html/css1atr.cxx
index 168d1cc7778a..2667972a98be 100644
--- a/sw/source/filter/html/css1atr.cxx
+++ b/sw/source/filter/html/css1atr.cxx
@@ -103,14 +103,6 @@ using editeng::SvxBorderLine;
 
 namespace {
 
-enum class Css1Background {
-Attr= 1,
-Page= 2,
-Table   = 3,
-Fly = 4,
-Section = 5
-};
-
 enum class Css1FrameSize {
 NONE   = 0x00,
 Width  = 0x01,
@@ -153,7 +145,7 @@ static Writer& OutCSS1_SvxULSpace_SvxLRSpace( Writer& rWrt,
 static Writer& OutCSS1_SvxULSpace_SvxLRSpace( Writer& rWrt,
 const SfxItemSet& rItemSet );
 static Writer& OutCSS1_SvxBrush( Writer& rWrt, const SfxPoolItem& rHt,
- Css1Background nMode,
+ sw::Css1Background nMode,
  const OUString *pGraphicName );
 static Writer& OutCSS1_SvxBrush( Writer& rWrt, const SfxPoolItem& rHt );
 static Writer& OutCSS1_SwFormatFrameSize( Writer& rWrt, const SfxPoolItem& rHt,
@@ -191,9 +183,9 @@ OString lclConvToHex(sal_uInt16 nHex)
 }
 
 bool IgnorePropertyForReqIF(bool bReqIF, std::string_view rProperty, 
std::string_view rValue,
-bool bTable)
+std::optional oMode)
 {
-if (!bReqIF || bTable)
+if (!bReqIF || (oMode.has_value() && *oMode != 
sw::Css1Background::TableCell))
 return false;
 
 // Only allow these two keys, nothing else in ReqIF mode.
@@ -250,9 +242,9 @@ public:
 void SwHTMLWriter::OutCSS1_Property( const char *pProp,
  std::string_view sVal,
  const OUString *pSVal,
- bool bTable )
+ std::optional oMode )
 {
-if (IgnorePropertyForReqIF(mbReqIF, pProp, sVal, bTable))
+if (IgnorePropertyForReqIF(mbReqIF, pProp, sVal, oMode))
 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-06-13 Thread Miklos Vajna (via logerrit)
 sw/qa/core/txtnode/txtnode.cxx|   12 
 sw/source/core/txtnode/thints.cxx |7 +--
 2 files changed, 17 insertions(+), 2 deletions(-)

New commits:
commit 00ce7545bd85193929ffec3787b7cea7932d8e1f
Author: Miklos Vajna 
AuthorDate: Thu Jun 9 14:23:11 2022 +0200
Commit: Miklos Vajna 
CommitDate: Mon Jun 13 14:24:01 2022 +0200

sw content controls: fix crash on trying to insert nested dropdown

This went wrong in commit 3dd4f3691458ea537bc1867386269694775cfbcb (sw
content controls: add document model, 2022-03-30).

(cherry picked from commit 51eb7b837996384d0155c0841bf69cf068bbe367)

Change-Id: I8040e02975d1f98cc01ef6f8a22745f27afa5276
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135571
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/txtnode/txtnode.cxx b/sw/qa/core/txtnode/txtnode.cxx
index ed8759112ae1..ad44a12f7c9b 100644
--- a/sw/qa/core/txtnode/txtnode.cxx
+++ b/sw/qa/core/txtnode/txtnode.cxx
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/txtnode/data/";
 
@@ -208,6 +209,17 @@ CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, 
testSplitNodeSuperscriptCopy)
 CPPUNIT_ASSERT(!aSet.HasItem(RES_CHRATR_ESCAPEMENT));
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testInsertDropDownContentControlTwice)
+{
+// Given an already selected dropdown content control:
+SwDoc* pDoc = createSwDoc();
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+pWrtShell->InsertContentControl(SwContentControlType::DROP_DOWN_LIST);
+
+// When trying to insert an inner one, make sure that we don't crash:
+pWrtShell->InsertContentControl(SwContentControlType::DROP_DOWN_LIST);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/txtnode/thints.cxx 
b/sw/source/core/txtnode/thints.cxx
index 71d0263850d2..f5f1a1e7b469 100644
--- a/sw/source/core/txtnode/thints.cxx
+++ b/sw/source/core/txtnode/thints.cxx
@@ -107,11 +107,14 @@ SwpHints::SwpHints(const SwTextNode& rParent)
 static void TextAttrDelete( SwDoc & rDoc, SwTextAttr * const pAttr )
 {
 if (RES_TXTATR_META == pAttr->Which() ||
-RES_TXTATR_METAFIELD == pAttr->Which() ||
-pAttr->Which() == RES_TXTATR_CONTENTCONTROL)
+RES_TXTATR_METAFIELD == pAttr->Which())
 {
 static_txtattr_cast(pAttr)->ChgTextNode(nullptr); // 
prevents ASSERT
 }
+else if (pAttr->Which() == RES_TXTATR_CONTENTCONTROL)
+{
+
static_txtattr_cast(pAttr)->ChgTextNode(nullptr);
+}
 SwTextAttr::Destroy( pAttr, rDoc.GetAttrPool() );
 }
 


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source writerfilter/source

2022-05-31 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/globalfilter/globalfilter.cxx|  276 +++---
 sw/qa/extras/ooxmlexport/ooxmlexport13.cxx|   97 ++-
 sw/qa/extras/ooxmlexport/ooxmlexport8.cxx |   54 +++-
 sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx |  136 --
 sw/qa/extras/ooxmlimport/ooxmlimport2.cxx |   42 +--
 sw/source/filter/ww8/docxattributeoutput.cxx  |2 
 writerfilter/source/dmapper/DomainMapper.cxx  |   35 ++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |   50 +++
 writerfilter/source/dmapper/SdtHelper.cxx |   11 
 writerfilter/source/dmapper/SdtHelper.hxx |   17 +
 10 files changed, 495 insertions(+), 225 deletions(-)

New commits:
commit 33d8d3bc06f07379755bfccf73e15b4cadb919d1
Author: Miklos Vajna 
AuthorDate: Mon May 30 09:00:25 2022 +0200
Commit: Miklos Vajna 
CommitDate: Tue May 31 14:41:12 2022 +0200

sw content controls, date: add DOCX import

- map
  


  
  to the Date, DateFormat and DateLanguage UNO properties of content
  controls instead of fieldmarks, which model content controls poorly

- fix CppunitTest_sw_ooxmlexport8's testN820509: date SDT is now a
  content control

- add current date DOCX import

- fix CppunitTest_sw_ooxmlexport13's testDateControl: date SDT is now a
  content control

- fix CppunitTest_sw_ooxmlexport13's testInvalidDateFormField: date SDT
  is now a content control

- fix CppunitTest_sw_ooxmlexport5's testfdo83048: minimal support for
  nested SDTs in DomainMapper::lcl_attribute()

- fix CppunitTest_sw_ooxmlfieldexport's testDateFieldAtEndOfParagraph:
  date SDT is now a content control

- fix CppunitTest_sw_ooxmlfieldexport's testDateFieldInShape: date SDT
  is now a content control

- fix CppunitTest_sw_ooxmlfieldexport's testSdtDateDuplicate: date SDT
  is now a content control

- fix CppunitTest_sw_ooxmlfieldexport's testSdtDatePicker:

  - retain placeholder

  - retain data binding

  - retain color

- fix CppunitTest_sw_ooxmlimport2's testTdf121203: date SDT is now a
  content control

- fix CppunitTest_sw_globalfilter's
  testDateFormFieldCharacterFormatting: date SDT is now a content control

- fix CppunitTest_sw_globalfilter's testDateFormField: date SDT is now a
  content control

(cherry picked from commit 5ee8670f18cb8b1913a23d04590d6a31ac9730de)

Conflicts:
sw/qa/extras/globalfilter/globalfilter.cxx

Change-Id: I5a4c34217d23ed6fa0916e4dd6290351456b7232
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135152
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx 
b/sw/qa/extras/globalfilter/globalfilter.cxx
index 04d24a825f27..ee6e9f2fbcd5 100644
--- a/sw/qa/extras/globalfilter/globalfilter.cxx
+++ b/sw/qa/extras/globalfilter/globalfilter.cxx
@@ -1651,92 +1651,170 @@ void Test::testDateFormField()
 mxComponent = loadFromDesktop(aTempFile.GetURL(), 
"com.sun.star.text.TextDocument");
 
 // Check the document after round trip
-SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get());
-CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pTextDoc);
-SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
-IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
-
-CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(5), 
pMarkAccess->getAllMarksCount());
-
-int nIndex = 0;
-for(auto aIter = pMarkAccess->getAllMarksBegin(); aIter != 
pMarkAccess->getAllMarksEnd(); ++aIter)
+if (rFilterName == "writer8")
 {
-::sw::mark::IDateFieldmark* pFieldmark = 
dynamic_cast<::sw::mark::IDateFieldmark*>(*aIter);
-CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pFieldmark);
-CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
+SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get());
+CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pTextDoc);
+SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
 
-// Check date form field's parameters.
-const sw::mark::IFieldmark::parameter_map_t* const pParameters = 
pFieldmark->GetParameters();
-OUString sDateFormat;
-auto pResult = pParameters->find(ODF_FORMDATE_DATEFORMAT);
-if (pResult != pParameters->end())
-{
-pResult->second >>= sDateFormat;
-}
+CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
sal_Int32(5), pMarkAccess->getAllMarksCount());
 
-OUString sLang;
-   

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-05-31 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/ooxmlexport/ooxmlexport17.cxx   |   34 +++
 sw/source/filter/ww8/docxattributeoutput.cxx |   18 ++
 2 files changed, 52 insertions(+)

New commits:
commit c04e1a32a1610c735ef2de6e8fde107abb1b66ae
Author: Miklos Vajna 
AuthorDate: Fri May 27 08:06:18 2022 +0200
Commit: Miklos Vajna 
CommitDate: Tue May 31 14:40:08 2022 +0200

sw content controls, date: add DOCX export

Map the Date, DateFormat and DateLanguage UNO properties to:

  


  

(cherry picked from commit 10b1a9eb8588e15ea5e98001cc4d5ab2d56604f3)

Conflicts:
sw/qa/extras/ooxmlexport/ooxmlexport17.cxx

Change-Id: I4695ac30be26968b2c2ea14b044c1e2a10638ea8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135149
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index c428d0225611..c0a0d401da35 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -274,6 +274,40 @@ CPPUNIT_TEST_FIXTURE(Test, testPictureContentControlExport)
 assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:picture", 1);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testDateContentControlExport)
+{
+// Given a document with a date content control around a text portion:
+mxComponent = loadFromDesktop("private:factory/swriter");
+uno::Reference xMSF(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xText = xTextDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+xText->insertString(xCursor, "test", /*bAbsorb=*/false);
+xCursor->gotoStart(/*bExpand=*/false);
+xCursor->gotoEnd(/*bExpand=*/true);
+uno::Reference xContentControl(
+xMSF->createInstance("com.sun.star.text.ContentControl"), 
uno::UNO_QUERY);
+uno::Reference xContentControlProps(xContentControl, 
uno::UNO_QUERY);
+xContentControlProps->setPropertyValue("Date", uno::Any(true));
+xContentControlProps->setPropertyValue("DateFormat", 
uno::Any(OUString("M/d/")));
+xContentControlProps->setPropertyValue("DateLanguage", 
uno::Any(OUString("en-US")));
+xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
+
+// When exporting to DOCX:
+save("Office Open XML Text", maTempFile);
+mbExported = true;
+
+// Then make sure the expected markup is used:
+xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+// Without the fix in place, this test would have failed with:
+// - Expected: 1
+// - Actual  : 0
+// - XPath '//w:sdt/w:sdtPr/w:date/w:dateFormat' number of nodes is 
incorrect
+// i.e. the  was lost on export.
+assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:date/w:dateFormat", "val", 
"M/d/");
+assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:date/w:lid", "val", "en-US");
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf137466, "tdf137466.docx")
 {
 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 7e30ec38e1ac..f253e77658d7 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2380,6 +2380,24 @@ void DocxAttributeOutput::WriteContentControlStart()
 m_pSerializer->endElementNS(XML_w, XML_dropDownList);
 }
 
+if (m_pContentControl->GetDate())
+{
+m_pSerializer->startElementNS(XML_w, XML_date);
+OUString aDateFormat = m_pContentControl->GetDateFormat();
+if (!aDateFormat.isEmpty())
+{
+m_pSerializer->singleElementNS(XML_w, XML_dateFormat, FSNS(XML_w, 
XML_val),
+   aDateFormat);
+}
+OUString aDateLanguage = m_pContentControl->GetDateLanguage();
+if (!aDateLanguage.isEmpty())
+{
+m_pSerializer->singleElementNS(XML_w, XML_lid, FSNS(XML_w, 
XML_val),
+   aDateLanguage);
+}
+m_pSerializer->endElementNS(XML_w, XML_date);
+}
+
 m_pSerializer->endElementNS(XML_w, XML_sdtPr);
 m_pSerializer->startElementNS(XML_w, XML_sdtContent);
 m_pContentControl = nullptr;


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-05-23 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx  |   34 +
 sw/source/filter/html/htmlflywriter.cxx |   50 
 2 files changed, 78 insertions(+), 6 deletions(-)

New commits:
commit 961c0da0503c94f5a86c962acd4932ffa8967db1
Author: Miklos Vajna 
AuthorDate: Tue May 17 16:11:25 2022 +0200
Commit: Miklos Vajna 
CommitDate: Mon May 23 10:58:13 2022 +0200

sw HTML export: avoid pixel height when height is scale and width is 
relative

Commit b17180a84cb4561b8a7bbf9e2281c91fffd56f87 (write out image size in
html export for 'keep ratio' images, 2021-06-29) changed the sw HTML
export to write the layout size of images in case one dimension is "keep
ratio" and the other is some more concrete value.

This is useful in case that other dimension is a fixed value, because
"keep ratio" on the UI only means to keep the ratio as the size changes,
it does not mean that the ratio will be the original ratio of the
bitmap. However, it's problematic to write this layout size of the "keep
ratio" dimension when the other dimension is relative, as this will mean
the image's aspect ratio will change if the user resizes the browser
window.

Fix the problem by extending the way we write the "height" and "width"
of fly frames:

1) Write a percentage in case of relative sizes

2) Write an explicit "auto" (or just omit the attribute in XHTML mode)
   in case the size is "keep ratio" and the other dimension is a
   relative size

3) Write the layout size in other cases (fixed size or "keep ratio", but
   the other dimension is a fixed size)

Note that HTML itself has no concept of relative sizes where 100% is not
the parent's size (e.g. page, not paragraph) and also has no concept of
keeping an aspect ratio which is not the aspect ratio of the bitmap, so
those cases remain unchanged.

Change-Id: Ic5c7dc4d697160eff81e960a2f7d335fb78ab7c0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134482
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins
(cherry picked from commit 9e3eee88338c45424b24040f731083f9f59cfbe2)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134450
Reviewed-by: Xisco Fauli 
(cherry picked from commit 4bced2b78b3e22730c12d9729f5633ae1a3a35c8)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134754
Tested-by: Jenkins CollaboraOffice 

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 3ee58613903a..997537012bb8 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -2200,6 +2200,40 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testTableBackground)
 assertXPathNoAttribute(pXmlDoc, 
"//reqif-xhtml:table[2]/reqif-xhtml:tr[1]", "bgcolor");
 }
 
+CPPUNIT_TEST_FIXTURE(HtmlExportTest, testImageKeepRatio)
+{
+// Given a document with an image: width is relative, height is "keep 
ratio":
+createSwDoc();
+uno::Reference xFactory(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xTextGraphic(
+xFactory->createInstance("com.sun.star.text.TextGraphicObject"), 
uno::UNO_QUERY);
+xTextGraphic->setPropertyValue("AnchorType",
+   
uno::Any(text::TextContentAnchorType_AS_CHARACTER));
+xTextGraphic->setPropertyValue("RelativeWidth", 
uno::Any(static_cast(42)));
+xTextGraphic->setPropertyValue("IsSyncHeightToWidth", uno::Any(true));
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xBodyText = xTextDocument->getText();
+uno::Reference xCursor(xBodyText->createTextCursor());
+uno::Reference xTextContent(xTextGraphic, 
uno::UNO_QUERY);
+xBodyText->insertTextContent(xCursor, xTextContent, false);
+
+// When exporting to HTML:
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+uno::Sequence aStoreProperties = {
+comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)")),
+};
+xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+
+// Then make sure that the width is not a fixed size, that would break on 
resizing the browser
+// window:
+htmlDocUniquePtr pDoc = parseHtml(maTempFile);
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: auto
+// - Actual  : 2
+// i.e. a static (CSS pixel) height was written.
+assertXPath(pDoc, "/html/body/p/img", "height", "auto");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlflywriter.cxx 
b/sw/source/filter/html/htmlflywriter.cxx
index 2aee659fc6e8..5eff1441760f 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -987,22 +987,60 @@ void SwHTMLWriter::writeFrameFormatOptions(HtmlWriter& 
aHtml, const SwFrameForma
 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-05-20 Thread Miklos Vajna (via logerrit)
 sw/qa/core/unocore/unocore.cxx|7 -
 sw/qa/uibase/wrtsh/wrtsh.cxx  |   46 ++
 sw/source/uibase/docvw/edtwin.cxx |   26 +
 sw/source/uibase/uiview/view2.cxx |2 -
 sw/source/uibase/wrtsh/wrtsh3.cxx |   18 ++
 5 files changed, 96 insertions(+), 3 deletions(-)

New commits:
commit 5a4c551a360e0c69e3f6200de45690e9ad587fb4
Author: Miklos Vajna 
AuthorDate: Wed May 18 10:51:18 2022 +0200
Commit: Miklos Vajna 
CommitDate: Fri May 20 12:19:53 2022 +0200

sw content controls, picture: replace placeholder image on click

Previous content control types (rich text, checkbox, dropdown) had the
cursor somewhere in the content control and click selected the content
control in the placeholder case.

The picture case is somewhat different: the content control has a single
as-char image, and by the time SwWrtShell::GotoContentControl() is
invoked, the picture frame is already selected.

All we have to do here is to trigger the file picker to select a
replacement and then insert that image to replace the already selected
frame's bitmap.

(cherry picked from commit b213abcb77e19fa5d22af45c7ecd17c8a63af554)

Change-Id: Id3ad94ed8f7e13b0ebc2f57327bb8c0b1e374a86
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134663
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx
index fec19e7abefe..83d2698b3353 100644
--- a/sw/qa/core/unocore/unocore.cxx
+++ b/sw/qa/core/unocore/unocore.cxx
@@ -501,7 +501,12 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, 
testContentControlPicture)
 uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
 uno::Reference xText = xTextDocument->getText();
 uno::Reference xCursor = xText->createTextCursor();
-xText->insertString(xCursor, "test", /*bAbsorb=*/false);
+uno::Reference xTextGraphic(
+xMSF->createInstance("com.sun.star.text.TextGraphicObject"), 
uno::UNO_QUERY);
+xTextGraphic->setPropertyValue("AnchorType",
+   
uno::Any(text::TextContentAnchorType_AS_CHARACTER));
+uno::Reference xTextContent(xTextGraphic, 
uno::UNO_QUERY);
+xText->insertTextContent(xCursor, xTextContent, false);
 xCursor->gotoStart(/*bExpand=*/false);
 xCursor->gotoEnd(/*bExpand=*/true);
 uno::Reference xContentControl(
diff --git a/sw/qa/uibase/wrtsh/wrtsh.cxx b/sw/qa/uibase/wrtsh/wrtsh.cxx
index 7317c0e2bbfa..9aa3efbaf214 100644
--- a/sw/qa/uibase/wrtsh/wrtsh.cxx
+++ b/sw/qa/uibase/wrtsh/wrtsh.cxx
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace
 {
@@ -239,6 +240,51 @@ CPPUNIT_TEST_FIXTURE(Test, 
testInsertDropdownContentControl)
 // i.e. the inserted content control was a default (rich text) one, not a 
dropdown.
 CPPUNIT_ASSERT_EQUAL(static_cast(1), 
pContentControl->GetListItems().size());
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testReplacePictureContentControl)
+{
+// Given a document with a picture content control:
+SwDoc* pDoc = createSwDoc();
+uno::Reference xMSF(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xText = xTextDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+uno::Reference xTextGraphic(
+xMSF->createInstance("com.sun.star.text.TextGraphicObject"), 
uno::UNO_QUERY);
+xTextGraphic->setPropertyValue("AnchorType",
+   
uno::Any(text::TextContentAnchorType_AS_CHARACTER));
+uno::Reference xTextContent(xTextGraphic, 
uno::UNO_QUERY);
+xText->insertTextContent(xCursor, xTextContent, false);
+xCursor->gotoStart(/*bExpand=*/false);
+xCursor->gotoEnd(/*bExpand=*/true);
+uno::Reference xContentControl(
+xMSF->createInstance("com.sun.star.text.ContentControl"), 
uno::UNO_QUERY);
+uno::Reference xContentControlProps(xContentControl, 
uno::UNO_QUERY);
+xContentControlProps->setPropertyValue("ShowingPlaceHolder", 
uno::Any(true));
+xContentControlProps->setPropertyValue("Picture", uno::Any(true));
+xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
+
+// When clicking on that content control:
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+pWrtShell->GotoObj(/*bNext=*/true, GotoObjFlags::Any);
+pWrtShell->EnterSelFrameMode();
+const SwFrameFormat* pFlyFormat = pWrtShell->GetFlyFrameFormat();
+const SwFormatAnchor& rFormatAnchor = pFlyFormat->GetAnchor();
+const SwPosition* pAnchorPos = rFormatAnchor.GetContentAnchor();
+SwTextNode* pTextNode = pAnchorPos->nNode.GetNode().GetTextNode();
+SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, 
RES_TXTATR_CONTENTCONTROL);
+auto pTextContentControl = 
static_txtattr_cast(pAttr);
+auto& rFormatContentControl
+= 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-05-13 Thread Miklos Vajna (via logerrit)
 sw/qa/core/unocore/unocore.cxx|   12 +++-
 sw/qa/uibase/wrtsh/wrtsh.cxx  |   10 --
 sw/source/core/crsr/crstrvl.cxx   |4 +++-
 sw/source/core/crsr/viscrs.cxx|6 +++---
 sw/source/core/txtnode/attrcontentcontrol.cxx |4 
 sw/source/core/txtnode/ndtxt.cxx  |1 +
 sw/source/core/txtnode/thints.cxx |   21 -
 sw/source/core/unocore/unocontentcontrol.cxx  |3 ++-
 sw/source/filter/ascii/ascatr.cxx |3 ++-
 sw/source/uibase/wrtsh/wrtsh3.cxx |4 
 10 files changed, 46 insertions(+), 22 deletions(-)

New commits:
commit 0577fc114efca2f9d60df702416841f6d41dd37b
Author: Miklos Vajna 
AuthorDate: Wed May 11 09:29:05 2022 +0200
Commit: Miklos Vajna 
CommitDate: Fri May 13 13:20:38 2022 +0200

sw content controls: introduce a word breaking dummy char at the end

- this way double-clicking on the last word of a content control or the
  first word after the content control selects the correct text range,
  similar to how the same at the start of content control already worked

- this allows not touching the expand flag in the SwTextContentControl
  ctor, which was overwritten by the ODT import (when the content
  control was at the end of the paragraph) anyway

- hide this dummy character when accessing the paragraph content via the
  UNO API or the text export

- still need to audit a few more places in follow-up commits to maintain
  the invariant that content controls have the same dummy char at the
  attribute start and end -- somwhat similar to how SwTextInputField
  does it with CH_TXT_ATR_INPUTFIELDSTART/END

(cherry picked from commit 1e9416fac497a58be04011cfa0ffce9c74a9e397)

Conflicts:
sw/qa/core/unocore/unocore.cxx

Change-Id: I88763d6db84afedbb865b680f040994c4d6ab7d5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134259
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx
index 40fe6c31329b..bfeaea521c6e 100644
--- a/sw/qa/core/unocore/unocore.cxx
+++ b/sw/qa/core/unocore/unocore.cxx
@@ -321,7 +321,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, 
testContentControlInsert)
 CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testContentControlTextPortionEnum)
 {
 // Given a document with a content control around one or more text 
portions:
-createSwDoc();
+SwDoc* pDoc = createSwDoc();
 uno::Reference xMSF(mxComponent, 
uno::UNO_QUERY);
 uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
 uno::Reference xText = xTextDocument->getText();
@@ -363,6 +363,16 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, 
testContentControlTextPortionEnum)
 // portion.
 assertXPath(pXmlDoc, "//SwParaPortion/SwLineLayout/SwLinePortion[2]", 
"type",
 "PortionType::ContentControl");
+
+// Also test the doc model, make sure that there is a dummy character at 
the start and end, so
+// the user can explicitly decide if they want to expand the content 
control or not:
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+OUString aText = 
pWrtShell->GetCursor()->GetNode().GetTextNode()->GetText();
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: ^Atest^A
+// - Actual  : ^Atest
+// i.e. there was no dummy character at the end.
+CPPUNIT_ASSERT_EQUAL(OUString("\x0001test\x0001"), aText);
 }
 
 CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testContentControlCheckbox)
diff --git a/sw/qa/uibase/wrtsh/wrtsh.cxx b/sw/qa/uibase/wrtsh/wrtsh.cxx
index 1e2ef1bb48bd..51a1bbb984fa 100644
--- a/sw/qa/uibase/wrtsh/wrtsh.cxx
+++ b/sw/qa/uibase/wrtsh/wrtsh.cxx
@@ -125,9 +125,8 @@ CPPUNIT_TEST_FIXTURE(Test, testTickCheckboxContentControl)
 // Without the accompanying fix in place, this test would have failed:
 // - Expected: ☐
 // - Actual  : ☒
-// i.e. the text node's text was CH_TXTATR_BREAKWORD + "Ballot Box with 
X", not just
-// CH_TXTATR_BREAKWORD + "Ballot Box".
-CPPUNIT_ASSERT_EQUAL(OUString(u"\x0001☐"), pTextNode->GetText());
+// i.e. the text node's text was "Ballot Box with X", not just "Ballot 
Box".
+CPPUNIT_ASSERT_EQUAL(OUString(u"☐"), 
pTextNode->GetExpandText(pWrtShell->GetLayout()));
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testInsertContentControl)
@@ -214,9 +213,8 @@ CPPUNIT_TEST_FIXTURE(Test, testSelectDropdownContentControl)
 // Without the accompanying fix in place, this test would have failed:
 // - Expected: red
 // - Actual  : choose an item
-// i.e. the document text was unchanged instead of CH_TXTATR_BREAKWORD + 
display text of the
-// first list item.
-CPPUNIT_ASSERT_EQUAL(OUString(u"\x0001red"), pTextNode->GetText());
+// i.e. the document text was unchanged instead of 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-05-11 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/ooxmlexport/ooxmlexport17.cxx   |   53 +++
 sw/source/filter/ww8/docxattributeoutput.cxx |   12 ++
 2 files changed, 65 insertions(+)

New commits:
commit 116338b8af38a20e21c1248cc077cfe1f0cc07c0
Author: Miklos Vajna 
AuthorDate: Tue May 10 10:41:21 2022 +0200
Commit: Miklos Vajna 
CommitDate: Wed May 11 16:43:58 2022 +0200

sw content controls, drop-down: add DOCX export

Map the list items to an XML markup like:

  

  



  

...
  

(cherry picked from commit 6de2fc2a705d3f356cac898201a98d7db6102d1a)

Conflicts:
sw/qa/extras/ooxmlexport/ooxmlexport17.cxx

Change-Id: I483009603f1138e4bd5871bfd8c760a3de739ba1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134147
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index 38a17bca714b..1c4c99597c21 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -182,6 +183,58 @@ CPPUNIT_TEST_FIXTURE(Test, 
testCheckboxContentControlExport)
 assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w14:checkbox/w14:uncheckedState", 
"val", "2610");
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testDropdownContentControlExport)
+{
+// Given a document with a checkbox content control around a text portion:
+mxComponent = loadFromDesktop("private:factory/swriter");
+uno::Reference xMSF(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xText = xTextDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+xText->insertString(xCursor, "choose an item", /*bAbsorb=*/false);
+xCursor->gotoStart(/*bExpand=*/false);
+xCursor->gotoEnd(/*bExpand=*/true);
+uno::Reference xContentControl(
+xMSF->createInstance("com.sun.star.text.ContentControl"), 
uno::UNO_QUERY);
+uno::Reference xContentControlProps(xContentControl, 
uno::UNO_QUERY);
+{
+uno::Sequence aListItems = {
+{
+comphelper::makePropertyValue("DisplayText", 
uno::Any(OUString("red"))),
+comphelper::makePropertyValue("Value", 
uno::Any(OUString("R"))),
+},
+{
+comphelper::makePropertyValue("DisplayText", 
uno::Any(OUString("green"))),
+comphelper::makePropertyValue("Value", 
uno::Any(OUString("G"))),
+},
+{
+comphelper::makePropertyValue("DisplayText", 
uno::Any(OUString("blue"))),
+comphelper::makePropertyValue("Value", 
uno::Any(OUString("B"))),
+},
+};
+xContentControlProps->setPropertyValue("ListItems", 
uno::Any(aListItems));
+}
+xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
+
+// When exporting to DOCX:
+save("Office Open XML Text", maTempFile);
+mbExported = true;
+
+// Then make sure the expected markup is used:
+xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+// Without the fix in place, this test would have failed with:
+// - Expected: 1
+// - Actual  : 0
+// - XPath '//w:sdt/w:sdtPr/w:dropDownList/w:listItem[1]' number of nodes 
is incorrect
+// i.e. the list items were lost on export.
+assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:dropDownList/w:listItem[1]", 
"displayText", "red");
+assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:dropDownList/w:listItem[1]", 
"value", "R");
+assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:dropDownList/w:listItem[2]", 
"displayText", "green");
+assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:dropDownList/w:listItem[2]", 
"value", "G");
+assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:dropDownList/w:listItem[3]", 
"displayText", "blue");
+assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w:dropDownList/w:listItem[3]", 
"value", "B");
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf137466, "tdf137466.docx")
 {
 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 2fd7a442c77d..939f3cffbbf2 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2363,6 +2363,18 @@ void DocxAttributeOutput::WriteContentControlStart()
 m_pSerializer->endElementNS(XML_w14, XML_checkbox);
 }
 
+if (m_pContentControl->HasListItems())
+{
+m_pSerializer->startElementNS(XML_w, XML_dropDownList);
+for (const auto& rItem : m_pContentControl->GetListItems())
+{
+m_pSerializer->singleElementNS(XML_w, XML_listItem,
+FSNS(XML_w, 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-05-02 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/ooxmlexport/ooxmlexport17.cxx   |   36 ++
 sw/source/filter/ww8/docxattributeoutput.cxx |   66 ++-
 sw/source/filter/ww8/docxattributeoutput.hxx |3 -
 3 files changed, 84 insertions(+), 21 deletions(-)

New commits:
commit 38ae2a54e2efc1c957868b6d8e93bd49bb3e08c7
Author: Miklos Vajna 
AuthorDate: Thu Apr 28 10:12:29 2022 +0200
Commit: Miklos Vajna 
CommitDate: Mon May 2 13:49:06 2022 +0200

sw content controls, checkbox: add DOCX export

Map the 4 UNO properties to the following XML construct:

  



  

(cherry picked from commit 8642389b954a0b8f5673c85f44d8b0ea34eb3430)

Conflicts:
sw/qa/extras/ooxmlexport/ooxmlexport17.cxx

Change-Id: I6457754e5dc9750204da7f2e5e479589380f3992
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133644
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index b72a470978cc..38a17bca714b 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -146,6 +146,42 @@ CPPUNIT_TEST_FIXTURE(Test, testContentControlExport)
 assertXPath(pXmlDoc, "//w:sdt/w:sdtContent", 1);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testCheckboxContentControlExport)
+{
+// Given a document with a checkbox content control around a text portion:
+mxComponent = loadFromDesktop("private:factory/swriter");
+uno::Reference xMSF(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xText = xTextDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+xText->insertString(xCursor, OUString(u"☐"), /*bAbsorb=*/false);
+xCursor->gotoStart(/*bExpand=*/false);
+xCursor->gotoEnd(/*bExpand=*/true);
+uno::Reference xContentControl(
+xMSF->createInstance("com.sun.star.text.ContentControl"), 
uno::UNO_QUERY);
+uno::Reference xContentControlProps(xContentControl, 
uno::UNO_QUERY);
+xContentControlProps->setPropertyValue("Checkbox", uno::makeAny(true));
+xContentControlProps->setPropertyValue("Checked", uno::makeAny(true));
+xContentControlProps->setPropertyValue("CheckedState", 
uno::makeAny(OUString(u"☒")));
+xContentControlProps->setPropertyValue("UncheckedState", 
uno::makeAny(OUString(u"☐")));
+xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
+
+// When exporting to DOCX:
+save("Office Open XML Text", maTempFile);
+mbExported = true;
+
+// Then make sure the expected markup is used:
+xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+// Without the fix in place, this test would have failed with:
+// - Expected: 1
+// - Actual  : 0
+// - XPath '//w:sdt/w:sdtPr/w14:checkbox/w14:checked' number of nodes is 
incorrect
+// i.e.  and its child elements were lost.
+assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w14:checkbox/w14:checked", "val", 
"1");
+assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w14:checkbox/w14:checkedState", 
"val", "2612");
+assertXPath(pXmlDoc, "//w:sdt/w:sdtPr/w14:checkbox/w14:uncheckedState", 
"val", "2610");
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf137466, "tdf137466.docx")
 {
 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 059c7204b01f..2fd7a442c77d 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -1635,8 +1635,7 @@ void DocxAttributeOutput::EndRun(const SwTextNode* pNode, 
sal_Int32 nPos, bool /
 for (; m_nCloseContentControlInPreviousRun > 0; 
--m_nCloseContentControlInPreviousRun)
 {
 // Not the last run of this paragraph.
-m_pSerializer->endElementNS(XML_w, XML_sdtContent);
-m_pSerializer->endElementNS(XML_w, XML_sdt);
+WriteContentControlEnd();
 }
 
 if ( m_closeHyperlinkInPreviousRun )
@@ -1736,18 +1735,7 @@ void DocxAttributeOutput::EndRun(const SwTextNode* 
pNode, sal_Int32 nPos, bool /
 m_nHyperLinkCount++;
 }
 
-if (m_pContentControl)
-{
-m_pSerializer->startElementNS(XML_w, XML_sdt);
-m_pSerializer->startElementNS(XML_w, XML_sdtPr);
-if (m_pContentControl->GetShowingPlaceHolder())
-{
-m_pSerializer->singleElementNS(XML_w, XML_showingPlcHdr);
-}
-m_pSerializer->endElementNS(XML_w, XML_sdtPr);
-m_pSerializer->startElementNS(XML_w, XML_sdtContent);
-m_pContentControl = nullptr;
-}
+WriteContentControlStart();
 
 // if there is some redlining in the document, output it
 StartRedline( m_pRedlineData );
@@ -1862,8 +1850,7 @@ void DocxAttributeOutput::EndRun(const SwTextNode* pNode, 
sal_Int32 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-05-02 Thread Miklos Vajna (via logerrit)
 sw/qa/uibase/wrtsh/wrtsh.cxx  |   38 ++
 sw/source/core/crsr/crstrvl.cxx   |2 +-
 sw/source/uibase/wrtsh/wrtsh3.cxx |   38 ++
 3 files changed, 77 insertions(+), 1 deletion(-)

New commits:
commit 4a0f65c338f32dffc9ecc47811aa199d13205a9e
Author: Miklos Vajna 
AuthorDate: Tue Apr 26 08:20:50 2022 +0200
Commit: Miklos Vajna 
CommitDate: Mon May 2 08:14:44 2022 +0200

sw content controls, checkbox: toggle the checkbox on click

Implement this by selecting the content control's text (similar to
placeholders), then replacing the selection with the content control's
relevant state.

(cherry picked from commit 6f60a89a6be85d4cbe5840f9d0146eae98dbf543)

Change-Id: I280ce45822fe3fd9615511a9a62d23dc230aa275
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133642
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/uibase/wrtsh/wrtsh.cxx b/sw/qa/uibase/wrtsh/wrtsh.cxx
index 51489553d30f..b4d4cca09df6 100644
--- a/sw/qa/uibase/wrtsh/wrtsh.cxx
+++ b/sw/qa/uibase/wrtsh/wrtsh.cxx
@@ -91,6 +91,44 @@ CPPUNIT_TEST_FIXTURE(Test, testGotoContentControl)
 CPPUNIT_ASSERT_EQUAL(static_cast(5), nEnd);
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testTickCheckboxContentControl)
+{
+// Given a document with a checkbox (checked) content control:
+SwDoc* pDoc = createSwDoc();
+uno::Reference xMSF(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xText = xTextDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+xText->insertString(xCursor, OUString(u"☒"), /*bAbsorb=*/false);
+xCursor->gotoStart(/*bExpand=*/false);
+xCursor->gotoEnd(/*bExpand=*/true);
+uno::Reference xContentControl(
+xMSF->createInstance("com.sun.star.text.ContentControl"), 
uno::UNO_QUERY);
+uno::Reference xContentControlProps(xContentControl, 
uno::UNO_QUERY);
+xContentControlProps->setPropertyValue("Checkbox", uno::makeAny(true));
+xContentControlProps->setPropertyValue("Checked", uno::makeAny(true));
+xContentControlProps->setPropertyValue("CheckedState", 
uno::makeAny(OUString(u"☒")));
+xContentControlProps->setPropertyValue("UncheckedState", 
uno::makeAny(OUString(u"☐")));
+xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
+
+// When clicking on that content control:
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+SwTextNode* pTextNode = pWrtShell->GetCursor()->GetNode().GetTextNode();
+SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, 
RES_TXTATR_CONTENTCONTROL);
+auto pTextContentControl = 
static_txtattr_cast(pAttr);
+auto& rFormatContentControl
+= static_cast(pTextContentControl->GetAttr());
+pWrtShell->GotoContentControl(rFormatContentControl);
+
+// Then make sure that the checkbox is no longer checked:
+// Without the accompanying fix in place, this test would have failed:
+// - Expected: ☐
+// - Actual  : ☒
+// i.e. the text node's text was CH_TXTATR_BREAKWORD + "Ballot Box with 
X", not just
+// CH_TXTATR_BREAKWORD + "Ballot Box".
+CPPUNIT_ASSERT_EQUAL(OUString(u"\x0001☐"), pTextNode->GetText());
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testInsertContentControl)
 {
 // Given an empty document:
diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx
index e1e9aa08913f..48c10a666c7f 100644
--- a/sw/source/core/crsr/crstrvl.cxx
+++ b/sw/source/core/crsr/crstrvl.cxx
@@ -857,7 +857,7 @@ bool SwCursorShell::GotoFormatContentControl(const 
SwFormatContentControl& rCont
 {
 bool bRet = false;
 auto pContentControl = 
const_cast(rContentControl.GetContentControl());
-if (!pContentControl->GetShowingPlaceHolder())
+if (!pContentControl->GetShowingPlaceHolder() && 
!pContentControl->GetCheckbox())
 {
 return bRet;
 }
diff --git a/sw/source/uibase/wrtsh/wrtsh3.cxx 
b/sw/source/uibase/wrtsh/wrtsh3.cxx
index 2b0b9385467e..35d1d3bd45ee 100644
--- a/sw/source/uibase/wrtsh/wrtsh3.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh3.cxx
@@ -33,6 +33,10 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
+#include 
 
 using namespace ::com::sun::star;
 
@@ -88,6 +92,40 @@ bool SwWrtShell::GotoContentControl(const 
SwFormatContentControl& rContentContro
 (this->*m_fnKillSel)(nullptr, false);
 
 bool bRet = SwCursorShell::GotoFormatContentControl(rContentControl);
+
+auto pContentControl = 
const_cast(rContentControl.GetContentControl());
+if (bRet && pContentControl && pContentControl->GetCheckbox())
+{
+// Checkbox: GotoFormatContentControl() selected the old state.
+LockView(/*bViewLocked=*/true);
+OUString aOldState;
+OUString aNewState;
+if (pContentControl->GetChecked())
+{
+aOldState = pContentControl->GetCheckedState();
+  

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source writerfilter/CppunitTest_writerfilter_dmapper.mk writerfilter/qa writerfilter/source

2022-04-25 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/ooxmlexport/ooxmlexport17.cxx   |5 
 sw/source/filter/ww8/docxattributeoutput.cxx |1 
 writerfilter/CppunitTest_writerfilter_dmapper.mk |1 
 writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx   |   89 
++
 writerfilter/qa/cppunittests/dmapper/data/sdt-run-rich-text.docx |binary
 writerfilter/source/dmapper/DomainMapper.cxx |   24 ++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx|   54 ++
 writerfilter/source/dmapper/DomainMapper_Impl.hxx|3 
 writerfilter/source/dmapper/SdtHelper.cxx|5 
 writerfilter/source/dmapper/SdtHelper.hxx|7 
 writerfilter/source/ooxml/OOXMLFastContextHandler.cxx|   16 +
 writerfilter/source/ooxml/OOXMLFastContextHandler.hxx|2 
 writerfilter/source/ooxml/model.xml  |5 
 13 files changed, 208 insertions(+), 4 deletions(-)

New commits:
commit 636ac1c46665cfe35884afb9a6663feb15f6b4c2
Author: Miklos Vajna 
AuthorDate: Wed Apr 20 08:29:35 2022 +0200
Commit: Miklos Vajna 
CommitDate: Mon Apr 25 08:26:29 2022 +0200

sw content controls: add initial DOCX import

- map inline/run SDTs with unknown type (i.e. rich text) to
  SwContentControl

- decouple block and run SDTs and leave block ones unchanged

- track start position of run SDTs similar to bookmarks, which needs
  different code to SDT at text start vs later

- fix DocxAttributeOutput::RunText() to please
  CppunitTest_sw_ooxmlexport2's testFdo67013, which had an inline SDT in
  footer, not at para end

(cherry picked from commit f2ab1375b266d7465ef31d06ec8f949c6b91d853)

Change-Id: I59b8b7f3170cf37f1547db07ae0992850e0e3aa8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/10
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index a3bd1a18094f..d0e3c151282b 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -233,8 +233,9 @@ DECLARE_OOXMLEXPORT_TEST(testTdf148361, "tdf148361.docx")
 uno::Reference xTextField1(xFields->nextElement(), 
uno::UNO_QUERY);
 CPPUNIT_ASSERT_EQUAL(OUString("itadmin"), 
xTextField1->getPresentation(false));
 
-uno::Reference xTextField2(xFields->nextElement(), 
uno::UNO_QUERY);
-CPPUNIT_ASSERT_EQUAL(OUString("[Type text]"), 
xTextField2->getPresentation(false));
+OUString aActual = getParagraph(2)->getString();
+// This was "itadmin".
+CPPUNIT_ASSERT_EQUAL(OUString("[Type text]"), aActual);
 }
 
 DECLARE_OOXMLEXPORT_TEST(testTdf142407, "tdf142407.docx")
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 038a5bd86520..059c7204b01f 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3281,6 +3281,7 @@ void DocxAttributeOutput::RunText( const OUString& rText, 
rtl_TextEncoding /*eCh
 if (m_nCloseContentControlInThisRun > 0)
 {
 ++m_nCloseContentControlInPreviousRun;
+--m_nCloseContentControlInThisRun;
 }
 m_bRunTextIsOn = true;
 // one text can be split into more blah's by line breaks etc.
diff --git a/writerfilter/CppunitTest_writerfilter_dmapper.mk 
b/writerfilter/CppunitTest_writerfilter_dmapper.mk
index 48b4ee87e087..de1a8cea9f48 100644
--- a/writerfilter/CppunitTest_writerfilter_dmapper.mk
+++ b/writerfilter/CppunitTest_writerfilter_dmapper.mk
@@ -23,6 +23,7 @@ $(eval $(call 
gb_CppunitTest_add_exception_objects,writerfilter_dmapper, \
 writerfilter/qa/cppunittests/dmapper/GraphicImport \
 writerfilter/qa/cppunittests/dmapper/TextEffectsHandler \
 writerfilter/qa/cppunittests/dmapper/PropertyMap \
+writerfilter/qa/cppunittests/dmapper/SdtHelper \
 ))
 
 $(eval $(call gb_CppunitTest_use_libraries,writerfilter_dmapper, \
diff --git a/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx 
b/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
new file mode 100644
index ..da2663b93409
--- /dev/null
+++ b/writerfilter/qa/cppunittests/dmapper/SdtHelper.cxx
@@ -0,0 +1,89 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-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/.
+ */
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+using namespace com::sun::star;
+
+namespace
+{
+/// Tests for writerfilter/source/dmapper/SdtHelper.cxx.
+class Test : public test::BootstrapFixture, public unotest::MacrosTest
+{
+private:
+

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-04-07 Thread Miklos Vajna (via logerrit)
 sw/qa/core/text/data/clearing-break-header.fodt |   31 
 sw/qa/core/text/text.cxx|   16 
 sw/source/core/text/txtfly.cxx  |7 +
 3 files changed, 54 insertions(+)

New commits:
commit 5929da2fa6fb6aa1ea32f5c0abb11b66b21f2791
Author: Miklos Vajna 
AuthorDate: Tue Apr 5 16:15:15 2022 +0200
Commit: Miklos Vajna 
CommitDate: Thu Apr 7 08:14:10 2022 +0200

tdf#148366 sw clearing breaks: fix handling of anchored objs from 
header/footer

Regression from commit f86d1482bef285f90079b5130e410646db96cf58 (sw
clearing breaks: add DOCX import, 2022-03-08), the trouble was that we
considered an anchored object from the header for text wrapping, while
this anchored object was in the background in Word.

(cherry picked from commit 61888e49d6eee55197ca1c27b4b023f9b2108d48)

Change-Id: I806cc91ce1eb390c02cbff2defa4cb47fde86853
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132620
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/text/data/clearing-break-header.fodt 
b/sw/qa/core/text/data/clearing-break-header.fodt
new file mode 100644
index ..2bdbcd3c7567
--- /dev/null
+++ b/sw/qa/core/text/data/clearing-break-header.fodt
@@ -0,0 +1,31 @@
+
+
+  
+
+  
+
+
+  
+
+
+  
+  
+  
+
+  
+
+  
+  
+
+  
+
+
+  
+
+  
+  
+
+  
+
+  
+
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index 0923758694b8..3d2c91f2b131 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -345,6 +345,22 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, 
testClearingLineBreakLeft)
 assertXPath(pXmlDoc, "//SwParaPortion/SwLineLayout[1]", "height", "2837");
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testClearingLineBreakHeader)
+{
+// Given a document with a shape in the header and a clearing break in the 
body text:
+createSwDoc(DATA_DIRECTORY, "clearing-break-header.fodt");
+
+// When laying out that document:
+xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+
+// Then make sure that the shape from the header is ignored while 
calculating the line height:
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 276
+// - Actual  : 15398
+// i.e. the shape was in the background, but we failed to ignore it for 
the break portion.
+assertXPath(pXmlDoc, "//SwParaPortion/SwLineLayout[1]", "height", "276");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/txtfly.cxx b/sw/source/core/text/txtfly.cxx
index 1b9c3b55308a..88f0687de8c1 100644
--- a/sw/source/core/text/txtfly.cxx
+++ b/sw/source/core/text/txtfly.cxx
@@ -1012,6 +1012,13 @@ SwTwips SwTextFly::GetMaxBottom(const SwBreakPortion& 
rPortion, const SwTextForm
 for (size_t i = 0; i < nCount; ++i)
 {
 const SwAnchoredObject* pAnchoredObj = (*mpAnchoredObjList)[i];
+
+if (pAnchoredObj->GetAnchorFrame()->FindFooterOrHeader())
+{
+// Anchored in the header or footer, ignore it for clearing break 
purposes.
+continue;
+}
+
 SwRect aRect(pAnchoredObj->GetObjRectWithSpaces());
 if (rPortion.GetClear() == SwLineBreakClear::LEFT)
 {


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-04-05 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/tiledrendering/tiledrendering.cxx |   39 +
 sw/source/core/doc/docredln.cxx|9 +
 2 files changed, 48 insertions(+)

New commits:
commit 167c2156b4ceda708be367ccb916c1c3a5e40597
Author: Miklos Vajna 
AuthorDate: Mon Apr 4 16:01:57 2022 +0200
Commit: Miklos Vajna 
CommitDate: Tue Apr 5 10:47:52 2022 +0200

sw lok: fix missing cache invalidation in SwRedlineTable::Insert()

The trouble is that the FillRects() call in
SwRedlineTable::LOKRedlineNotification() builds a text portion list, but
that's not yet correct, and later we don't build a text portion list as
we already have one.

Fix this similar to the frame size problem by invalidating the cache
after we got our rectangles.

(cherry picked from commit 81bcee981ee0558474467d83c0fa929e932c)

Change-Id: Ida759be418bc3706810d9774e060d06143893bb6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132557
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx 
b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 24e5876203e7..e59c8cccacf4 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -166,6 +166,7 @@ public:
 void testBulletMultiDeleteInvalidation();
 void testCondCollCopy();
 void testMoveShapeHandle();
+void testRedlinePortions();
 
 CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
 CPPUNIT_TEST(testRegisterCallback);
@@ -252,6 +253,7 @@ public:
 CPPUNIT_TEST(testBulletMultiDeleteInvalidation);
 CPPUNIT_TEST(testCondCollCopy);
 CPPUNIT_TEST(testMoveShapeHandle);
+CPPUNIT_TEST(testRedlinePortions);
 CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -3561,6 +3563,43 @@ void SwTiledRenderingTest::testCondCollCopy()
 xTransferable->getTransferData(aFlavor);
 }
 
+void SwTiledRenderingTest::testRedlinePortions()
+{
+// Given a document with 3 portions: before insert redline (foo), the 
insert redline (ins) and after insert
+// redline (bar):
+SwXTextDocument* pXTextDocument = createDoc();
+SwDocShell* pDocShell = pXTextDocument->GetDocShell();
+SwView* pView = pDocShell->GetView();
+pView->SetRedlineAuthor("first");
+pDocShell->SetView(pView);
+SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+pWrtShell->Insert("foo");
+pDocShell->SetChangeRecording(true);
+pWrtShell->Insert("ins");
+pDocShell->SetChangeRecording(false);
+pWrtShell->Insert("bar after");
+
+// When deleting "fooinsbar":
+pView->SetRedlineAuthor("second");
+pDocShell->SetView(pView);
+pWrtShell->SttEndDoc(/*bStt*/true);
+pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, /*nCount=*/9, 
/*bBasicCall=*/false);
+pDocShell->SetChangeRecording(true);
+pWrtShell->Delete();
+
+// Then make sure that the portion list is updated, so "bar" can be marked 
as deleted without
+// marking " after" as well:
+xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+assertXPath(pXmlDoc, "//Text[1]", "Portion", "foo");
+assertXPath(pXmlDoc, "//Text[2]", "Portion", "ins");
+// Without the accompanying fix in place, this test would have failed 
width:
+// - Expected: bar
+// - Actual  : bar after
+// i.e. the portion list was outdated, even " after" was marked as deleted.
+assertXPath(pXmlDoc, "//Text[3]", "Portion", "bar");
+assertXPath(pXmlDoc, "//Text[4]", "Portion", " after");
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index c6d469678fa3..35568a615581 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -57,6 +57,7 @@
 #include 
 
 #include 
+#include 
 
 using namespace com::sun::star;
 
@@ -286,6 +287,14 @@ void lcl_LOKInvalidateFrames(const sw::BroadcastingModify& 
rMod, const SwRootFra
 if (pPoint)
 {
 pTmpFrame->InvalidateSize();
+
+// Also empty the text portion cache, so it gets rebuilt, 
taking the new redlines
+// into account.
+if (pTmpFrame->IsTextFrame())
+{
+auto pTextFrame = static_cast(pTmpFrame);
+pTextFrame->ClearPara();
+}
 }
 }
 }


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-04-01 Thread Justin Luth (via logerrit)
 sw/qa/extras/ww8export/ww8export3.cxx |3 ++-
 sw/source/filter/ww8/ww8par5.cxx  |   23 ---
 2 files changed, 22 insertions(+), 4 deletions(-)

New commits:
commit 2c7e4d31662add89f0fa4c7a8e007caaacadc0b7
Author: Justin Luth 
AuthorDate: Fri Mar 11 14:55:00 2022 +0200
Commit: Miklos Vajna 
CommitDate: Fri Apr 1 17:11:45 2022 +0200

tdf#147861 ww8import: solve TODO: not fixed-field if equal

Do not mark the field as "fixed" if the displayed string
matches the internal variable. This allows changing the variable
within LO and having the field update to reflect that change,
which is the way that these fields are supposed to work
(although in MS Word they only update manually via F9
 which is why some needed to be fixed in the first place).

(cherry picked from commit f5c2085e70c40370a790868d4683133a41e6599d)

Change-Id: Id359cbf0b48e63bddab3e45871326988467d7ddb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132400
Tested-by: Miklos Vajna 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/ww8export/ww8export3.cxx 
b/sw/qa/extras/ww8export/ww8export3.cxx
index 80f0daf11f93..0ed99f7e64dc 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -104,7 +104,8 @@ DECLARE_WW8EXPORT_TEST(testTdf147861_customField, 
"tdf147861_customField.doc")
 {
 // These should each be specific values, not a shared DocProperty
 getParagraph(1, "CustomEditedTitle"); // edited
-getParagraph(2, " INSERT Custom Title here"); // matches current 
DocProperty
+// A couple of \x0\x0 at the end of the import variable thwart an equality 
comparison
+CPPUNIT_ASSERT(getParagraph(2)->getString().startsWith(" INSERT Custom 
Title here"));
 getParagraph(3, "My Title"); // edited
 
 // Verify that these are fields, and not just plain text
diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx
index 76461ab6c86a..99841fe175fe 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -1650,13 +1650,30 @@ eF_ResT SwWW8ImplReader::Read_F_DocInfo( WW8FieldDesc* 
pF, OUString& rStr )
 // In other words, Word lets the field to be out of sync with the 
controlling variable.
 // Marking as FIXEDFLD solves the automatic replacement problem, 
but of course prevents
 // Writer from making any changes, even on an F9 refresh.
-// TODO: If the field already matches the DocProperty, no need to 
mark as fixed.
 // TODO: Extend LO to allow a linked field that doesn't 
automatically update.
+IDocumentContentOperations& 
rIDCO(m_rDoc.getIDocumentContentOperations());
 const auto pType(static_cast(
 
m_rDoc.getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::DocInfo)));
 const OUString sDisplayed = GetFieldResult(pF);
-SwDocInfoField aField(pType, DI_CUSTOM | DI_SUB_FIXED | nReg, 
aDocProperty, sDisplayed);
-m_rDoc.getIDocumentContentOperations().InsertPoolItem(*m_pPaM, 
SwFormatField(aField));
+SwDocInfoField aField(pType, DI_CUSTOM | nReg, aDocProperty);
+
+// If text already matches the DocProperty var, then safe to treat 
as refreshable field.
+OUString sVariable = aField.ExpandField(/*bCache=*/false, nullptr);
+if (sDisplayed.getLength() != sVariable.getLength())
+{
+sal_Int32 nLen = sVariable.indexOf('\x0');
+if (nLen >= 0)
+sVariable = sVariable.copy(0, nLen);
+}
+if (sDisplayed == sVariable)
+rIDCO.InsertPoolItem(*m_pPaM, SwFormatField(aField));
+else
+{
+// They don't match, so use a fixed field to prevent LO from 
altering the contents.
+SwDocInfoField aFixedField(pType, DI_CUSTOM | DI_SUB_FIXED | 
nReg, aDocProperty,
+   sDisplayed);
+rIDCO.InsertPoolItem(*m_pPaM, SwFormatField(aFixedField));
+}
 
 return eF_ResT::OK;
 }


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-04-01 Thread Justin Luth (via logerrit)
 sw/qa/extras/ww8export/ww8export3.cxx |5 ++---
 sw/source/filter/ww8/ww8atr.cxx   |6 --
 2 files changed, 6 insertions(+), 5 deletions(-)

New commits:
commit daef39352b008fc1f903fd8c09288ff5e772fa42
Author: Justin Luth 
AuthorDate: Wed Mar 9 12:31:14 2022 +0200
Commit: Miklos Vajna 
CommitDate: Fri Apr 1 14:10:30 2022 +0200

tdf#147861 ww8export: DI_CUSTOM write fixed field, not plain txt

It looks like we just punt on fields, and try to avoid
round-tripping them as much as possible. And for good reason
since they are tough and poorly handled.

But since import of DI_CUSTOM has improved for DOC,
it would be nice to be able to round-trip it as well,
so that is what this allows.
It also opens the door to round-trip more field
situations as well.

This patch depends on the earlier related patch
that removes " (fixed)" from the FieldName.

RTF and DOCX also export OK, but import needs some love.

(cherry picked from commit 7974d5ef1446f106a5f7c45b76ea2728fe4b18ce)

Change-Id: I32d9aa1fea12763cc30a79bcfa6d1d1e19d2c619
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132399
Tested-by: Miklos Vajna 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/ww8export/ww8export3.cxx 
b/sw/qa/extras/ww8export/ww8export3.cxx
index e798a8cf66b6..80f0daf11f93 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -107,15 +107,14 @@ DECLARE_WW8EXPORT_TEST(testTdf147861_customField, 
"tdf147861_customField.doc")
 getParagraph(2, " INSERT Custom Title here"); // matches current 
DocProperty
 getParagraph(3, "My Title"); // edited
 
-if (mbExported)
-return;
-
 // Verify that these are fields, and not just plain text
 uno::Reference xTextFieldsSupplier(mxComponent, 
uno::UNO_QUERY);
 auto xFieldsAccess(xTextFieldsSupplier->getTextFields());
 uno::Reference 
xFields(xFieldsAccess->createEnumeration());
 uno::Reference xField(xFields->nextElement(), 
uno::UNO_QUERY);
 CPPUNIT_ASSERT_EQUAL(OUString("CustomEditedTitle"), 
xField->getPresentation(false));
+// The " (fixed)" part is unnecessary, but it must be consistent across a 
round-trip
+CPPUNIT_ASSERT_EQUAL(OUString("DocInformation:Title (fixed)"), 
xField->getPresentation(true));
 }
 
 DECLARE_WW8EXPORT_TEST(testTdf138345_paraCharHighlight, 
"tdf138345_paraCharHighlight.doc")
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 4dba4eaed63e..6a0e38eb6677 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -2916,7 +2916,7 @@ void AttributeOutputBase::TextField( const SwFormatField& 
rField )
 case SwFieldIds::DocInfo:// Last printed, last edited,...
 if( DI_SUB_FIXED & nSubType )
 bWriteExpand = true;
-else
+
 {
 OUString sStr;
 ww::eField eField(ww::eNONE);
@@ -2971,13 +2971,15 @@ void AttributeOutputBase::TextField( const 
SwFormatField& rField )
 
 if (pDocInfoField != nullptr)
 sStr = "\"" + pDocInfoField->GetName() + "\"";
+
+bWriteExpand = false;
 }
 break;
 default:
 break;
 }
 
-if (eField != ww::eNONE)
+if (!bWriteExpand && eField != ww::eNONE)
 {
 GetExport().OutputField(pField, eField, FieldString(eField) + 
sStr);
 }


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-04-01 Thread Justin Luth (via logerrit)
 sw/qa/extras/ww8export/data/tdf147861_customField.doc |binary
 sw/qa/extras/ww8export/ww8export3.cxx |   19 ++
 sw/source/filter/ww8/ww8par5.cxx  |   13 ++--
 3 files changed, 30 insertions(+), 2 deletions(-)

New commits:
commit 32de5733f41f3263f0eab894c737ebac3db65067
Author: Justin Luth 
AuthorDate: Wed Mar 9 11:38:26 2022 +0200
Commit: Miklos Vajna 
CommitDate: Fri Apr 1 14:10:08 2022 +0200

tdf#147861 ww8import: use GetFieldResult, not current DocProperty

In all the testing I could think of on DOCX and DOC examples
(and only a very few exist in the unit tests)
the actual value of the DocProperty was irrelevant to
what Word shows as the document loads.
It always takes the in-document, as-last-seen static text.

As a way to hack a fix using existing capabilities,
I marked as FIXEDFLD the unknown custom fields
that weren't handled separately.
That fixes what is displayed as the import value,
(which of course means that F9 will no longer
return a modification back to the DocProperty value).

It also means the (fixed) field is lost on export,
but a follow-up patch handles that for DOC/RTF/DOCX.

There were NO DI_CUSTOM examples in existing ww8 tests, but:
-ooxmlexport8:  fdo74745.docx, fdo81486.docx
-ooxmlexport10: tdf92157.docx
and in these cases the plain text matched the variable anyway,
but a manual manipulation showed that LO is importing DOCX wrong
as well, so a similar import fix needs to happen for RTF/DOCX.

My fear is that there are some special-magic-associations
that worked properly the old way by accident that I will
break by marking them as fixed. No backporting please
since obviously very few people report bugs about fields.

(cherry picked from commit 377e6f7e8556516b6d1698c58857a5662e6f5660)

Change-Id: I3f167eb3bd570b66ee829241bf9d31d557fc8749
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132398
Tested-by: Miklos Vajna 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/ww8export/data/tdf147861_customField.doc 
b/sw/qa/extras/ww8export/data/tdf147861_customField.doc
new file mode 100644
index ..f18d65f4059e
Binary files /dev/null and 
b/sw/qa/extras/ww8export/data/tdf147861_customField.doc differ
diff --git a/sw/qa/extras/ww8export/ww8export3.cxx 
b/sw/qa/extras/ww8export/ww8export3.cxx
index a292af9d3da6..e798a8cf66b6 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -99,6 +100,24 @@ DECLARE_WW8EXPORT_TEST(testTdf100961_fixedDateTime, 
"tdf100961_fixedDateTime.doc
 CPPUNIT_ASSERT_EQUAL(sal_uInt16(8), datetime.Seconds);
 }
 
+DECLARE_WW8EXPORT_TEST(testTdf147861_customField, "tdf147861_customField.doc")
+{
+// These should each be specific values, not a shared DocProperty
+getParagraph(1, "CustomEditedTitle"); // edited
+getParagraph(2, " INSERT Custom Title here"); // matches current 
DocProperty
+getParagraph(3, "My Title"); // edited
+
+if (mbExported)
+return;
+
+// Verify that these are fields, and not just plain text
+uno::Reference xTextFieldsSupplier(mxComponent, 
uno::UNO_QUERY);
+auto xFieldsAccess(xTextFieldsSupplier->getTextFields());
+uno::Reference 
xFields(xFieldsAccess->createEnumeration());
+uno::Reference xField(xFields->nextElement(), 
uno::UNO_QUERY);
+CPPUNIT_ASSERT_EQUAL(OUString("CustomEditedTitle"), 
xField->getPresentation(false));
+}
+
 DECLARE_WW8EXPORT_TEST(testTdf138345_paraCharHighlight, 
"tdf138345_paraCharHighlight.doc")
 {
 uno::Reference xRun(getRun(getParagraph(9), 1, "A 
side benefit is that "), uno::UNO_QUERY_THROW);
diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx
index 85af5106bfaa..76461ab6c86a 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -1645,8 +1645,17 @@ eF_ResT SwWW8ImplReader::Read_F_DocInfo( WW8FieldDesc* 
pF, OUString& rStr )
 
 if( !bFieldFound )
 {
-SwDocInfoField aField( static_cast(
-m_rDoc.getIDocumentFieldsAccess().GetSysFieldType( 
SwFieldIds::DocInfo )), DI_CUSTOM|nReg, aDocProperty, GetFieldResult( pF ) );
+// LO always automatically updates a DocInfo field from the 
File-Properties-Custom Prop
+// while MS Word requires the user to manually refresh the field 
(with F9).
+// In other words, Word lets the field to be out of sync with the 
controlling variable.
+// Marking as FIXEDFLD solves the automatic replacement problem, 
but of course prevents
+// Writer from making any changes, even on an F9 refresh.
+// TODO: If the field already matches the DocProperty, no need to 
mark as fixed.
+// TODO: 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-03-31 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/txtexport/txtexport.cxx |   39 +++
 sw/source/filter/ascii/ascatr.cxx|6 +
 2 files changed, 45 insertions(+)

New commits:
commit 6113440cfe16dadafe36d44796ff0438085d8948
Author: Miklos Vajna 
AuthorDate: Wed Mar 23 08:59:16 2022 +0100
Commit: Miklos Vajna 
CommitDate: Thu Mar 31 08:25:36 2022 +0200

sw clearing breaks: add plain text export

No need to care about the clearing, but make sure that
RES_TXTATR_LINEBREAK gets downgraded to a plain CH_TXTATR_NEWLINE.

(cherry picked from commit 59af0be9fbfcef4e157a74099a6aef0c60facb36)

Change-Id: Ia4f6b45f60a414d856db41fd09d06c902dffd908
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132295
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/txtexport/txtexport.cxx 
b/sw/qa/extras/txtexport/txtexport.cxx
index 54f623700fb0..b9b0e95e2875 100644
--- a/sw/qa/extras/txtexport/txtexport.cxx
+++ b/sw/qa/extras/txtexport/txtexport.cxx
@@ -9,7 +9,13 @@
 
 #include 
 
+#include 
+#include 
+
 #include 
+#include 
+
+#include 
 
 class TxtExportTest : public SwModelTestBase
 {
@@ -100,6 +106,39 @@ DECLARE_TXTEXPORT_TEST(testTdf142669_utf16le, 
"UTF16LECRLF.txt")
 CPPUNIT_ASSERT_EQUAL(OUString(u"フー\r\nバー\r\n"), aData);
 }
 
+CPPUNIT_TEST_FIXTURE(TxtExportTest, testClearingBreakExport)
+{
+// Given a document with a clearing break:
+mxComponent = loadFromDesktop("private:factory/swriter");
+uno::Reference xMSF(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xTextDocument(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xLineBreak(
+xMSF->createInstance("com.sun.star.text.LineBreak"), uno::UNO_QUERY);
+uno::Reference xLineBreakProps(xLineBreak, 
uno::UNO_QUERY);
+auto eClear = static_cast(SwLineBreakClear::ALL);
+xLineBreakProps->setPropertyValue("Clear", uno::makeAny(eClear));
+uno::Reference xText = xTextDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+xText->insertString(xCursor, "foo", /*bAbsorb=*/false);
+xText->insertTextContent(xCursor, xLineBreak, /*bAbsorb=*/false);
+xText->insertString(xCursor, "bar", /*bAbsorb=*/false);
+
+// When exporting to plain text:
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+uno::Sequence aStoreProps = {
+comphelper::makePropertyValue("FilterName", OUString("Text")),
+};
+xStorable->storeToURL(maTempFile.GetURL(), aStoreProps);
+
+// Then make sure that the newline is not lost:
+OString aActual = readExportedFile();
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: foo\nbar
+// - Actual  : foobar
+// i.e. the clearing break was not downgraded to a plain line break.
+CPPUNIT_ASSERT_EQUAL(OString("foo\nbar" SAL_NEWLINE_STRING), aActual);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ascii/ascatr.cxx 
b/sw/source/filter/ascii/ascatr.cxx
index 6edccce4298c..805f3ba48bc1 100644
--- a/sw/source/filter/ascii/ascatr.cxx
+++ b/sw/source/filter/ascii/ascatr.cxx
@@ -148,6 +148,12 @@ bool SwASC_AttrIter::OutAttr( sal_Int32 nSwPos )
 rFootnote.GetNumber());
 }
 break;
+case RES_TXTATR_LINEBREAK:
+{
+// Downgrade the clearing break to a simple linebreak.
+sOut = OUStringChar(GetCharOfTextAttr(*pHt));
+break;
+}
 }
 if( !sOut.isEmpty() )
 m_rWrt.Strm().WriteUnicodeOrByteText(sOut);


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-03-31 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/data/clearing-break.html |8 +
 sw/qa/extras/htmlexport/htmlexport.cxx   |   43 ++
 sw/source/filter/html/htmlatr.cxx|2 
 sw/source/filter/html/htmlftn.cxx|   27 ++
 sw/source/filter/html/swhtml.cxx |   97 +--
 sw/source/filter/html/wrthtml.hxx|1 
 6 files changed, 105 insertions(+), 73 deletions(-)

New commits:
commit c4f7c4b884ab3f47ddebc04c4e31d36e0edcda88
Author: Miklos Vajna 
AuthorDate: Tue Mar 22 09:07:09 2022 +0100
Commit: Miklos Vajna 
CommitDate: Thu Mar 31 08:25:05 2022 +0200

sw clearing breaks: add HTML filter

Map between SwLineBreakClear and .

The import-time workaround with the anchor-only wrapping is no longer
needed, the layout is now capable of doing this.

(cherry picked from commit 66d1ea5915761f3550b39466db5d48eb723f0ccc)

Conflicts:
sw/qa/extras/htmlexport/htmlexport.cxx

Change-Id: I53fa49f11e13fc3338b3cf70d8f87f3633c414c0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132294
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/htmlexport/data/clearing-break.html 
b/sw/qa/extras/htmlexport/data/clearing-break.html
new file mode 100644
index ..9586cb3af8e8
--- /dev/null
+++ b/sw/qa/extras/htmlexport/data/clearing-break.html
@@ -0,0 +1,8 @@
+
+
+
+
+
+foobar
+
+
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 7f64c835ce2d..9750555bf7f6 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -51,6 +51,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace
 {
@@ -2119,6 +2120,48 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testTrailingLineBreak)
 CPPUNIT_ASSERT_EQUAL(OUString("test\n"), aActual);
 }
 
+CPPUNIT_TEST_FIXTURE(HtmlExportTest, testClearingBreak)
+{
+auto verify = [this]() {
+uno::Reference 
xParagraph(getParagraph(1), uno::UNO_QUERY);
+uno::Reference xPortions = 
xParagraph->createEnumeration();
+uno::Reference xPortion;
+OUString aPortionType;
+while (true)
+{
+// Ignore leading comments.
+xPortion.set(xPortions->nextElement(), uno::UNO_QUERY);
+xPortion->getPropertyValue("TextPortionType") >>= aPortionType;
+if (aPortionType != "Annotation")
+{
+break;
+}
+}
+// Skip "foo".
+// Without the accompanying fix in place, this test would have failed 
with:
+// An uncaught exception of type 
com.sun.star.container.NoSuchElementException
+// i.e. the first para was just comments + text portion, the clearing 
break was lost.
+xPortion.set(xPortions->nextElement(), uno::UNO_QUERY);
+xPortion->getPropertyValue("TextPortionType") >>= aPortionType;
+CPPUNIT_ASSERT_EQUAL(OUString("LineBreak"), aPortionType);
+uno::Reference xLineBreak;
+xPortion->getPropertyValue("LineBreak") >>= xLineBreak;
+sal_Int16 eClear{};
+uno::Reference xLineBreakProps(xLineBreak, 
uno::UNO_QUERY);
+xLineBreakProps->getPropertyValue("Clear") >>= eClear;
+CPPUNIT_ASSERT_EQUAL(static_cast(SwLineBreakClear::ALL), 
eClear);
+};
+
+// Given a document with an at-para anchored image + a clearing break:
+// When loading that file:
+load(mpTestDocumentPath, "clearing-break.html");
+// Then make sure that the clear property of the break is not ignored:
+verify();
+reload(mpFilter, "clearing-break.html");
+// Make sure that that the clear property of the break is not ignored 
during export:
+verify();
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlatr.cxx 
b/sw/source/filter/html/htmlatr.cxx
index 41e5fad5c193..b34eed5bd41b 100644
--- a/sw/source/filter/html/htmlatr.cxx
+++ b/sw/source/filter/html/htmlatr.cxx
@@ -3269,7 +3269,7 @@ SwAttrFnTab aHTMLAttrFnTab = {
 /* RES_TXTATR_FLYCNT */ OutHTML_SwFlyCnt,
 /* RES_TXTATR_FTN */OutHTML_SwFormatFootnote,
 /* RES_TXTATR_ANNOTATION */ OutHTML_SwFormatField,
-/* RES_TXTATR_LINEBREAK */  nullptr,
+/* RES_TXTATR_LINEBREAK */  OutHTML_SwFormatLineBreak,
 /* RES_TXTATR_DUMMY1 */ nullptr, // Dummy:
 /* RES_TXTATR_DUMMY2 */ nullptr, // Dummy:
 
diff --git a/sw/source/filter/html/htmlftn.cxx 
b/sw/source/filter/html/htmlftn.cxx
index cfb6f59671c3..0020a4166eae 100644
--- a/sw/source/filter/html/htmlftn.cxx
+++ b/sw/source/filter/html/htmlftn.cxx
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -244,6 +245,32 @@ SwNodeIndex *SwHTMLParser::GetFootEndNoteSection( const 
OUString& rName )
 return pStartNodeIdx;
 }
 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-03-31 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/ww8export/ww8export3.cxx |   44 +++---
 sw/source/filter/ww8/ww8atr.cxx   |   10 ++-
 2 files changed, 34 insertions(+), 20 deletions(-)

New commits:
commit e2efa0f42c264ae7e6b90ad83360db425cde7d8c
Author: Miklos Vajna 
AuthorDate: Fri Mar 18 10:09:18 2022 +0100
Commit: Miklos Vajna 
CommitDate: Thu Mar 31 08:24:29 2022 +0200

sw clearing breaks: add DOC export

Map SwLineBreakClear to sprmCLbcCRJ's LBCOperand.

And most importantly, write the newline character: a clearing break was
not "downgraded" to a plain line break previously.

(cherry picked from commit 0da10420ed6e69384498de7404287e8c936fef14)

Change-Id: I3bc11a120af09d5c774df992cb17cfc5ee251e1d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132292
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/ww8export/ww8export3.cxx 
b/sw/qa/extras/ww8export/ww8export3.cxx
index 2a558c036e97..a292af9d3da6 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 
 class Test : public SwModelTestBase
 {
@@ -989,29 +990,34 @@ DECLARE_WW8EXPORT_TEST(testTdf136814, "tdf136814.odt")
 
 CPPUNIT_TEST_FIXTURE(Test, testClearingBreak)
 {
+auto verify = [this]() {
+uno::Reference 
xParagraph(getParagraph(1), uno::UNO_QUERY);
+uno::Reference xPortions = 
xParagraph->createEnumeration();
+xPortions->nextElement();
+xPortions->nextElement();
+// Without the accompanying fix in place, this test would have failed 
with:
+// An uncaught exception of type 
com.sun.star.container.NoSuchElementException
+// i.e. the first para was just a fly + text portion, the clearing 
break was lost.
+uno::Reference xPortion(xPortions->nextElement(), 
uno::UNO_QUERY);
+OUString aPortionType;
+xPortion->getPropertyValue("TextPortionType") >>= aPortionType;
+CPPUNIT_ASSERT_EQUAL(OUString("LineBreak"), aPortionType);
+uno::Reference xLineBreak;
+xPortion->getPropertyValue("LineBreak") >>= xLineBreak;
+sal_Int16 eClear{};
+uno::Reference xLineBreakProps(xLineBreak, 
uno::UNO_QUERY);
+xLineBreakProps->getPropertyValue("Clear") >>= eClear;
+CPPUNIT_ASSERT_EQUAL(static_cast(SwLineBreakClear::ALL), 
eClear);
+};
+
 // Given a document with a clearing break:
 // When loading that file:
 load(mpTestDocumentPath, "clearing-break.doc");
-
 // Then make sure that the clear property of the break is not ignored:
-uno::Reference xParagraph(getParagraph(1), 
uno::UNO_QUERY);
-uno::Reference xPortions = 
xParagraph->createEnumeration();
-xPortions->nextElement();
-xPortions->nextElement();
-// Without the accompanying fix in place, this test would have failed with:
-// An uncaught exception of type 
com.sun.star.container.NoSuchElementException
-// i.e. the first para was just a fly + text portion, the clearing break 
was lost.
-uno::Reference xPortion(xPortions->nextElement(), 
uno::UNO_QUERY);
-OUString aPortionType;
-xPortion->getPropertyValue("TextPortionType") >>= aPortionType;
-CPPUNIT_ASSERT_EQUAL(OUString("LineBreak"), aPortionType);
-uno::Reference xLineBreak;
-xPortion->getPropertyValue("LineBreak") >>= xLineBreak;
-sal_Int16 eClear{};
-uno::Reference xLineBreakProps(xLineBreak, 
uno::UNO_QUERY);
-xLineBreakProps->getPropertyValue("Clear") >>= eClear;
-// SwLineBreakClear::ALL
-CPPUNIT_ASSERT_EQUAL(static_cast(3), eClear);
+verify();
+reload(mpFilter, "clearing-break.doc");
+// Make sure that that the clear property of the break is not ignored 
during export:
+verify();
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index de00c649ba16..a7fccf6d6733 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -4190,7 +4190,15 @@ void WW8AttributeOutput::SectionRtlGutter(const 
SfxBoolItem& rRtlGutter)
 m_rWW8Export.pO->push_back(1);
 }
 
-void WW8AttributeOutput::TextLineBreak(const SwFormatLineBreak& 
/*rLineBreak*/) {}
+void WW8AttributeOutput::TextLineBreak(const SwFormatLineBreak& rLineBreak)
+{
+// Write the linebreak itself.
+m_rWW8Export.WriteChar(0x0b);
+
+// sprmCLbcCRJ
+m_rWW8Export.InsUInt16(NS_sprm::CLbcCRJ::val);
+m_rWW8Export.pO->push_back(rLineBreak.GetEnumValue());
+}
 
 void WW8AttributeOutput::FormatULSpace( const SvxULSpaceItem& rUL )
 {


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-03-30 Thread Caolán McNamara (via logerrit)
 sw/qa/extras/layout/data/forcepoint90.rtf |1 +
 sw/qa/extras/layout/layout.cxx|6 ++
 sw/source/core/layout/tabfrm.cxx  |   21 +++--
 3 files changed, 26 insertions(+), 2 deletions(-)

New commits:
commit b1e6085f51d38495f28470d8ba21a7c4f5490b64
Author: Caolán McNamara 
AuthorDate: Fri Mar 25 20:09:32 2022 +
Commit: Andras Timar 
CommitDate: Wed Mar 30 14:33:27 2022 +0200

forcepoint#90 fix crash on layout of specific rtf

Change-Id: I17c227ab278ed5a2cc60449d1d005212f00ded89
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132046
Tested-by: Jenkins
Reviewed-by: Caolán McNamara 

diff --git a/sw/qa/extras/layout/data/forcepoint90.rtf 
b/sw/qa/extras/layout/data/forcepoint90.rtf
new file mode 100644
index ..82c26224292d
--- /dev/null
+++ b/sw/qa/extras/layout/data/forcepoint90.rtf
@@ -0,0 +1 @@

... etc. - the rest is truncated


[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-03-29 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/ww8export/data/clearing-break.doc |binary
 sw/qa/extras/ww8export/ww8export3.cxx  |   26 
 sw/source/filter/ww8/ww8par.hxx|4 ++
 sw/source/filter/ww8/ww8par6.cxx   |   40 +
 4 files changed, 70 insertions(+)

New commits:
commit 51f64cf6ef8053af8c2b74b109ad4342ac9e2114
Author: Miklos Vajna 
AuthorDate: Thu Mar 17 10:15:11 2022 +0100
Commit: Miklos Vajna 
CommitDate: Tue Mar 29 16:15:56 2022 +0200

sw clearing breaks: add DOC import

Map sprmCLbcCRJ's LBCOperand to SwLineBreakClear.

(cherry picked from commit 31ac4edf2ec83c9f6ec475ad74e5fd94a0c8b1ca)

Conflicts:
sw/qa/extras/ww8export/ww8export3.cxx

Change-Id: Ie6a114bcd90a9442295815da68f6b0a9616c3210
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132261
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/ww8export/data/clearing-break.doc 
b/sw/qa/extras/ww8export/data/clearing-break.doc
new file mode 100644
index ..87b51128db3f
Binary files /dev/null and b/sw/qa/extras/ww8export/data/clearing-break.doc 
differ
diff --git a/sw/qa/extras/ww8export/ww8export3.cxx 
b/sw/qa/extras/ww8export/ww8export3.cxx
index 8e894c711457..2a558c036e97 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -987,6 +987,32 @@ DECLARE_WW8EXPORT_TEST(testTdf136814, "tdf136814.odt")
 CPPUNIT_ASSERT_EQUAL(nBorderDistance, getProperty(xStyle, 
"LeftBorderDistance"));
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testClearingBreak)
+{
+// Given a document with a clearing break:
+// When loading that file:
+load(mpTestDocumentPath, "clearing-break.doc");
+
+// Then make sure that the clear property of the break is not ignored:
+uno::Reference xParagraph(getParagraph(1), 
uno::UNO_QUERY);
+uno::Reference xPortions = 
xParagraph->createEnumeration();
+xPortions->nextElement();
+xPortions->nextElement();
+// Without the accompanying fix in place, this test would have failed with:
+// An uncaught exception of type 
com.sun.star.container.NoSuchElementException
+// i.e. the first para was just a fly + text portion, the clearing break 
was lost.
+uno::Reference xPortion(xPortions->nextElement(), 
uno::UNO_QUERY);
+OUString aPortionType;
+xPortion->getPropertyValue("TextPortionType") >>= aPortionType;
+CPPUNIT_ASSERT_EQUAL(OUString("LineBreak"), aPortionType);
+uno::Reference xLineBreak;
+xPortion->getPropertyValue("LineBreak") >>= xLineBreak;
+sal_Int16 eClear{};
+uno::Reference xLineBreakProps(xLineBreak, 
uno::UNO_QUERY);
+xLineBreakProps->getPropertyValue("Clear") >>= eClear;
+// SwLineBreakClear::ALL
+CPPUNIT_ASSERT_EQUAL(static_cast(3), eClear);
+}
 
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx
index 63d0e1baa1b1..86616b8de4b2 100644
--- a/sw/source/filter/ww8/ww8par.hxx
+++ b/sw/source/filter/ww8/ww8par.hxx
@@ -107,6 +107,7 @@ class GDIMetaFile;
 struct ESelection;
 class SfxItemSet;
 class OutlinerParaObject;
+enum class SwLineBreakClear;
 
 namespace com::sun::star{
 namespace beans{ class XPropertySet;}
@@ -1152,6 +1153,8 @@ private:
 */
 std::deque m_aFootnoteStack;
 
+std::optional m_oLineBreakClear;
+
 /*
 A queue of the ms sections in the document
 */
@@ -1753,6 +1756,7 @@ public: // really private, but can only be done public
 void Read_ParaAutoBefore(sal_uInt16 , const sal_uInt8 *pData, short nLen);
 void Read_ParaAutoAfter(sal_uInt16 , const sal_uInt8 *pData, short nLen);
 void Read_ParaContextualSpacing( sal_uInt16 nId, const sal_uInt8* pData, 
short nLen );
+void Read_LineBreakClear(sal_uInt16 nId, const sal_uInt8* pData, short 
nLen);
 void Read_LineSpace(sal_uInt16, const sal_uInt8*, short nLen );
 
 void SetRelativeJustify( bool bRel );
diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx
index 66900d1a8cc6..0679a9bcbcca 100644
--- a/sw/source/filter/ww8/ww8par6.cxx
+++ b/sw/source/filter/ww8/ww8par6.cxx
@@ -99,6 +99,7 @@
 #include "ww8graf.hxx"
 
 #include 
+#include 
 
 using namespace sw::util;
 using namespace sw::types;
@@ -4541,6 +4542,44 @@ void SwWW8ImplReader::Read_ParaContextualSpacing( 
sal_uInt16, const sal_uInt8* p
 NewAttr( aUL );
 }
 
+void SwWW8ImplReader::Read_LineBreakClear(sal_uInt16 /*nId*/, const sal_uInt8* 
pData, short nLen)
+{
+if (nLen == -1 && m_oLineBreakClear.has_value())
+{
+SwTextNode* pText = m_pPaM->GetNode().GetTextNode();
+sal_Int32 nPos = m_pPaM->GetPoint()->nContent.GetIndex();
+if (!pText || !nPos)
+{
+// There should have been a linebreak char.
+return;
+}
+
+// Replace the linebreak char with a clearing break.
+--nPos;
+m_pPaM->SetMark();
+

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-03-29 Thread Miklos Vajna (via logerrit)
 sw/qa/core/text/data/clearing-break-start.fodt |   28 +++
 sw/qa/core/text/text.cxx   |   30 +
 sw/source/core/text/porlay.cxx |   19 +++
 3 files changed, 76 insertions(+), 1 deletion(-)

New commits:
commit 0e496d1f0d3fe884f28ddfe86a1b8462bab2fb56
Author: Miklos Vajna 
AuthorDate: Thu Mar 10 08:18:55 2022 +0100
Commit: Miklos Vajna 
CommitDate: Tue Mar 29 13:34:52 2022 +0200

sw clearing breaks: fix layout when the line is empty

The break portion's height was not taken into account when the line had
no text portion ("had no content"). Fix that codepath to also take the
break portion's height into account, in case that's a clearing break.

(cherry picked from commit cee9b476d51f770fba03cb20b58370762d387e63)

Change-Id: Ib7b338911aa23fee766423897ed131ce4029223c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132258
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/text/data/clearing-break-start.fodt 
b/sw/qa/core/text/data/clearing-break-start.fodt
new file mode 100644
index ..f2df00fadd4f
--- /dev/null
+++ b/sw/qa/core/text/data/clearing-break-start.fodt
@@ -0,0 +1,28 @@
+
+
+  
+
+  
+
+  
+  
+
+  iVBORw0KGgoNSUhEUgAAAEBACAQAYLlVBGdBTUEAALGPC/xhBQFz
+   UkdCAK7OHOkgY0hSTQAAeiYAAICEAAD6gOgAAHUwAADqYAAAOpgAABdwnLpRPAAA
+   AAJiS0dEAACqjSMyCW9GRnMGAAAMc1XTCXBIWXMAAA3XAAAN1wFCKJt4
+   CXZwQWcAAABMQACdMTgbAAABzUlEQVRo3u3ZPU/CQBjA8X+Jxs3ESUDj4iK+LA5+
+   BBfjqBE1cXB2MlFAEqMgxvhNNL4sLsK3UPQL6ObkoAETz+FKW2mxCPRYnucWUu76/OC59C49
+   cGOCKqrD9kHRc6ddPv7oW2WCwMh0nF63Myz7Tm8hPTNu0pgHMER3scepTbgK6enJNND83RLn
+   /878yRaPmgBZFDuMsNLeWB9gmFQHP77MIg9gsYciR50NFKvtjIy10yk84pSZA7DYpwR8scmF
+   QQCMuoQMpzbh0iAARrlnVn90CWHTsZcAiHPPdINQAuqsc2MQAAnKDUKWEhZ10twaBEDSJWQo
+   YlFj7S9CzwEegkXWIbQsRAQASFJhpplwbRAACS+hANRJBxMiAkDcJeQ4sQkBhYgMoJ+Ozlwo
+   2YQ7AJ6CRxyiUGnVy3hVKb0Af9v7hUG2Wy9TEQCUelFTDULB2S+YKYGOMcpM6UIccOQnRA6A
+   cSp6ibfI+wkGADBGpTEd8xz1AaAfTQ7huA8AvUw5hVjuA0D/C5OaMN8XACRZ8F0zCggKAQhA
+   AAIQgAAEIAABCEAAAhCAAAQgAAH4zg3feY4w3Xs44M5+oW0qvCWoGcvaIlM3x/f/ab+O738A
+   hOCNQr34oD4ldEVYdGNyZWF0ZS1kYXRlADIwMTAtMTItMjBUMTc6MDg6MzYrMDE6MDB6
+   5RscJXRFWHRtb2RpZnktZGF0ZQAyMDEwLTEyLTIwVDE3OjA4OjM3KzAxOjAwgyNmnAAA
+   AABJRU5ErkJggg==
+  X
+
+  
+
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index f9864cbc722f..9987fac58a3f 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -263,6 +263,36 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testClearingLineBreak)
 assertXPath(pXmlDoc, "//SwParaPortion/SwLineLayout[1]", "height", "1024");
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testClearingLineBreakAtStart)
+{
+// Given a document with a fly frame and a character wrapped around it:
+createSwDoc(DATA_DIRECTORY, "clearing-break-start.fodt");
+// Insert a clearing break before "X":
+uno::Reference xDocument(mxComponent, uno::UNO_QUERY);
+uno::Reference xText = xDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+xCursor->gotoEnd(/*bSelect=*/false);
+xCursor->goLeft(/*nCount=*/1, /*bSelect=*/false);
+uno::Reference xFactory(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xLineBreak(
+xFactory->createInstance("com.sun.star.text.LineBreak"), 
uno::UNO_QUERY);
+uno::Reference xLineBreakProps(xLineBreak, 
uno::UNO_QUERY);
+auto eClear = static_cast(SwLineBreakClear::ALL);
+xLineBreakProps->setPropertyValue("Clear", uno::makeAny(eClear));
+xText->insertTextContent(xCursor, xLineBreak, /*bAbsorb=*/false);
+
+// When laying out that document:
+xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+
+// Then make sure that the second line "jumps down", below the fly frame:
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 1024
+// - Actual  : 276
+// i.e. the line height was too small, but only in case the full line was 
a fly and a break
+// portion, without any real content.
+assertXPath(pXmlDoc, "//SwParaPortion/SwLineLayout[1]", "height", "1024");
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index 05619f5591ff..575670c685eb 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -339,6 +339,10 @@ void SwLineLayout::CalcLine( SwTextFormatter , 
SwTextFormatInfo  )
 sal_uInt16 nFlyAscent = 0;
 sal_uInt16 nFlyHeight = 0;
 sal_uInt16 nFlyDescent = 0;
+
+// If this line has a clearing break, then this is the portion's height.
+sal_uInt16 nBreakHeight = 0;
+
 bool bOnlyPostIts = true;
 SetHanging( false );
 
@@ -455,6 +459,7 @@ void 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-03-29 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/ooxmlexport/data/clearing-break.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport17.cxx|   13 +++
 sw/source/filter/ww8/attributeoutputbase.hxx  |3 +
 sw/source/filter/ww8/docxattributeoutput.cxx  |   36 ++
 sw/source/filter/ww8/docxattributeoutput.hxx  |8 
 sw/source/filter/ww8/rtfattributeoutput.cxx   |2 +
 sw/source/filter/ww8/rtfattributeoutput.hxx   |2 +
 sw/source/filter/ww8/ww8atr.cxx   |5 +++
 sw/source/filter/ww8/ww8attributeoutput.hxx   |2 +
 9 files changed, 71 insertions(+)

New commits:
commit 094e4a7ee89d25bc24d90e095d65f429be947333
Author: Miklos Vajna 
AuthorDate: Wed Mar 9 08:32:24 2022 +0100
Commit: Miklos Vajna 
CommitDate: Tue Mar 29 08:52:33 2022 +0200

sw clearing breaks: add DOCX export

Need to do this in two passes, because a clearing line break is a text
attribute, but the DOCX markup is not a run property, so can only write
it once the run properties are finished.

(cherry picked from commit 280ab11ee40c95d2513e6f23ec5b08a083ecc1c5)

Change-Id: I74e94dbd02ca4e6ceee0439c5eafd3c3bbe2264b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132166
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/extras/ooxmlexport/data/clearing-break.docx 
b/sw/qa/extras/ooxmlexport/data/clearing-break.docx
new file mode 100644
index ..453a4c2b83d1
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/clearing-break.docx 
differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index 9937d86b0f88..5805fde5623e 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -67,6 +67,19 @@ CPPUNIT_TEST_FIXTURE(Test, testParaStyleNumLevel)
 assertXPath(pXmlDoc, 
"/w:styles/w:style[@w:styleId='Mystyle']/w:pPr/w:numPr/w:ilvl", "val", "1");
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testClearingBreak)
+{
+// Given a document with a clearing break, when saving to DOCX:
+loadAndSave("clearing-break.docx");
+
+// Then make sure that the clearing break is not lost:
+xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+// Without the accompanying fix in place, this test would have failed with:
+// - XPath '/w:document/w:body/w:p/w:r/w:br' number of nodes is incorrect
+// i.e. first the clearing break was turned into a plain break, then it 
was completely lost.
+assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:r/w:br", "clear", "all");
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf137466, "tdf137466.docx")
 {
 xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
diff --git a/sw/source/filter/ww8/attributeoutputbase.hxx 
b/sw/source/filter/ww8/attributeoutputbase.hxx
index 1694b9335cb5..8461f2e1510c 100644
--- a/sw/source/filter/ww8/attributeoutputbase.hxx
+++ b/sw/source/filter/ww8/attributeoutputbase.hxx
@@ -507,6 +507,9 @@ protected:
 /// Sfx item RES_TXTATR_FTN
 virtual void TextFootnote_Impl( const SwFormatFootnote& ) = 0;
 
+/// RES_TXTATR_LINEBREAK, i.e. clearing breaks.
+virtual void TextLineBreak(const SwFormatLineBreak&) = 0;
+
 /// Sfx item RES_PARATR_LINESPACING
 void ParaLineSpacing( const SvxLineSpacingItem& );
 
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 7bddf3121813..4e58196ea74e 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3112,6 +3112,8 @@ void DocxAttributeOutput::EndRunProperties( const 
SwRedlineData* pRedlineData )
 // write footnotes/endnotes if we have any
 FootnoteEndnoteReference();
 
+WriteLineBreak();
+
 // merge the properties _before_ the run text (strictly speaking, just
 // after the start of the run)
 m_pSerializer->mergeTopMarks(Tag_StartRunProperties, 
sax_fastparser::MergeMarks::PREPEND);
@@ -7224,6 +7226,40 @@ void DocxAttributeOutput::SectionRtlGutter(const 
SfxBoolItem& rRtlGutter)
 m_pSerializer->singleElementNS(XML_w, XML_rtlGutter);
 }
 
+void DocxAttributeOutput::TextLineBreak(const SwFormatLineBreak& rLineBreak)
+{
+m_oLineBreakClear = rLineBreak.GetValue();
+}
+
+void DocxAttributeOutput::WriteLineBreak()
+{
+if (!m_oLineBreakClear.has_value())
+{
+return;
+}
+
+rtl::Reference pAttr = 
FastSerializerHelper::createAttrList();
+pAttr->add(FSNS(XML_w, XML_type), "textWrapping");
+switch (*m_oLineBreakClear)
+{
+case SwLineBreakClear::NONE:
+pAttr->add(FSNS(XML_w, XML_clear), "none");
+break;
+case SwLineBreakClear::LEFT:
+pAttr->add(FSNS(XML_w, XML_clear), "left");
+break;
+case SwLineBreakClear::RIGHT:
+pAttr->add(FSNS(XML_w, XML_clear), "right");
+break;
+case SwLineBreakClear::ALL:
+   

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-03-29 Thread Miklos Vajna (via logerrit)
 sw/qa/core/text/data/clearing-break.fodt |   28 
 sw/qa/core/text/text.cxx |   31 +++
 sw/source/core/inc/txtfly.hxx|   11 +++
 sw/source/core/text/itrform2.cxx |6 +-
 sw/source/core/text/porlay.cxx   |   15 +++
 sw/source/core/text/porrst.cxx   |   27 ++-
 sw/source/core/text/porrst.hxx   |9 -
 sw/source/core/text/txtfly.cxx   |   24 
 8 files changed, 144 insertions(+), 7 deletions(-)

New commits:
commit fd7db6e5be7b36a217246517f1c4990d5879e42d
Author: Miklos Vajna 
AuthorDate: Fri Mar 4 10:36:38 2022 +0100
Commit: Miklos Vajna 
CommitDate: Tue Mar 29 08:46:23 2022 +0200

sw clearing breaks: initial layout support

- add a SwTextFly::GetMaxBottom() to know which fly frame has the
  largest bottom position from the current paragraph

- add a SwBreakPortion::m_eClear to track if the break portion is a
  clearing break

- consider height of breaking clear portions in SwLineLayout::CalcLine()

- increase the break portion height in SwBreakPortion::Format() if this
  is a clearing break and we have a fly frame that has a large enough
  bottom position, so the next line can "jump down", below the fly frame
  (so the line can be full width, which is the whole point of a clearing
  break)

(cherry picked from commit 9df80f6e41b0e69fce2afc6647adb78b0dd1df44)

Conflicts:
sw/source/core/text/xmldump.cxx

Change-Id: Ia21984b9cf9d04287cc19f98495c5b44b880020a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132163
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/sw/qa/core/text/data/clearing-break.fodt 
b/sw/qa/core/text/data/clearing-break.fodt
new file mode 100644
index ..a2f12850642c
--- /dev/null
+++ b/sw/qa/core/text/data/clearing-break.fodt
@@ -0,0 +1,28 @@
+
+
+  
+
+  
+
+  
+  
+
+  iVBORw0KGgoNSUhEUgAAAEBACAQAYLlVBGdBTUEAALGPC/xhBQFz
+   UkdCAK7OHOkgY0hSTQAAeiYAAICEAAD6gOgAAHUwAADqYAAAOpgAABdwnLpRPAAA
+   AAJiS0dEAACqjSMyCW9GRnMGAAAMc1XTCXBIWXMAAA3XAAAN1wFCKJt4
+   CXZwQWcAAABMQACdMTgbAAABzUlEQVRo3u3ZPU/CQBjA8X+Jxs3ESUDj4iK+LA5+
+   BBfjqBE1cXB2MlFAEqMgxvhNNL4sLsK3UPQL6ObkoAETz+FKW2mxCPRYnucWUu76/OC59C49
+   cGOCKqrD9kHRc6ddPv7oW2WCwMh0nF63Myz7Tm8hPTNu0pgHMER3scepTbgK6enJNND83RLn
+   /878yRaPmgBZFDuMsNLeWB9gmFQHP77MIg9gsYciR50NFKvtjIy10yk84pSZA7DYpwR8scmF
+   QQCMuoQMpzbh0iAARrlnVn90CWHTsZcAiHPPdINQAuqsc2MQAAnKDUKWEhZ10twaBEDSJWQo
+   YlFj7S9CzwEegkXWIbQsRAQASFJhpplwbRAACS+hANRJBxMiAkDcJeQ4sQkBhYgMoJ+Ozlwo
+   2YQ7AJ6CRxyiUGnVy3hVKb0Af9v7hUG2Wy9TEQCUelFTDULB2S+YKYGOMcpM6UIccOQnRA6A
+   cSp6ibfI+wkGADBGpTEd8xz1AaAfTQ7huA8AvUw5hVjuA0D/C5OaMN8XACRZ8F0zCggKAQhA
+   AAIQgAAEIAABCEAAAhCAAAQgAAH4zg3feY4w3Xs44M5+oW0qvCWoGcvaIlM3x/f/ab+O738A
+   hOCNQr34oD4ldEVYdGNyZWF0ZS1kYXRlADIwMTAtMTItMjBUMTc6MDg6MzYrMDE6MDB6
+   5RscJXRFWHRtb2RpZnktZGF0ZQAyMDEwLTEyLTIwVDE3OjA4OjM3KzAxOjAwgyNmnAAA
+   AABJRU5ErkJggg==
+  AB
+
+  
+
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index 4358fe03df75..f9864cbc722f 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -27,6 +27,7 @@
 
 #include 
 #include 
+#include 
 
 constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/text/data/";
 
@@ -232,6 +233,36 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, 
testEmptyNumberingPageSplit)
 dispatchCommand(mxComponent, ".uno:InsertGraphic", aArgs);
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testClearingLineBreak)
+{
+// Given a document with a fly frame and two characters wrapped around it:
+createSwDoc(DATA_DIRECTORY, "clearing-break.fodt");
+// Insert a clearing break between "A" and "B":
+uno::Reference xDocument(mxComponent, uno::UNO_QUERY);
+uno::Reference xText = xDocument->getText();
+uno::Reference xCursor = xText->createTextCursor();
+xCursor->gotoEnd(/*bSelect=*/false);
+xCursor->goLeft(/*nCount=*/1, /*bSelect=*/false);
+uno::Reference xFactory(mxComponent, 
uno::UNO_QUERY);
+uno::Reference xLineBreak(
+xFactory->createInstance("com.sun.star.text.LineBreak"), 
uno::UNO_QUERY);
+uno::Reference xLineBreakProps(xLineBreak, 
uno::UNO_QUERY);
+auto eClear = static_cast(SwLineBreakClear::ALL);
+xLineBreakProps->setPropertyValue("Clear", uno::makeAny(eClear));
+xText->insertTextContent(xCursor, xLineBreak, /*bAbsorb=*/false);
+
+// When laying out that document:
+xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+
+// Then make sure that the second line "jumps down", below the fly frame:
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 1024
+// - Actual  : 276
+// 

[Libreoffice-commits] core.git: Branch 'distro/collabora/co-22.05' - sw/qa sw/source

2022-02-23 Thread Miklos Vajna (via logerrit)
 sw/qa/extras/htmlexport/htmlexport.cxx  |   42 +
 sw/source/filter/html/htmlnumwriter.cxx |   46 ++--
 2 files changed, 69 insertions(+), 19 deletions(-)

New commits:
commit 2466b9fcf20ee61f6fc621298011c0efaa55e7c6
Author: Miklos Vajna 
AuthorDate: Mon Feb 21 16:38:51 2022 +0100
Commit: Miklos Vajna 
CommitDate: Wed Feb 23 11:07:45 2022 +0100

sw HTML export, XHTML mode: fix lost  when last list item is not 
numbered

This went wrong in 013a4f1f5c9ea5fb511568c53a7e76d1b365a65d (sw XHTML
export: fix handling of list labels, 2021-05-13), where we started to
assume that in case the last paragraph of a list is not numbered, then
the entire list is not numbered. This lead to loosing the  for an
 in case the list starts with a numbered paragraph, but ends with a
non-numbered one.

Fix the problem by (if necessary) looking back till the start of the
list to see if any paragraph is numbered: that ensures that the  and
 is always in sync.

This fixes the new problem and keeps the old problem fixed at the same
time.

Change-Id: I7d347b37a40dcc727c2080bf8279e33c3ad147e9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130287
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins
(cherry picked from commit 8c2607ae3ce143586e623532b8ae5288277ec3ac)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130310
Reviewed-by: Xisco Fauli 
(cherry picked from commit 81f90d4ab51ec7528fa2a9b14c0426a634971580)

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index fa40c8d7d04c..7f64c835ce2d 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1491,6 +1491,48 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testListHeading)
 assertXPathContent(pXmlDoc, 
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p", "list header");
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testPartiallyNumberedList)
+{
+// Given a document with a list, first para is numbered, second is not:
+loadURL("private:factory/swriter", nullptr);
+SwXTextDocument* pTextDoc = 
dynamic_cast(mxComponent.get());
+SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+pWrtShell->Insert("list header");
+SwDoc* pDoc = pWrtShell->GetDoc();
+sal_uInt16 nPos = pDoc->MakeNumRule(pDoc->GetUniqueNumRuleName());
+SwNumRule* pNumRule = pDoc->GetNumRuleTable()[nPos];
+{
+SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+SwTextNode& rTextNode = *rNode.GetTextNode();
+rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+}
+pWrtShell->Insert2("numbered");
+pWrtShell->SplitNode();
+pWrtShell->Insert2("not numbered");
+{
+SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+SwTextNode& rTextNode = *rNode.GetTextNode();
+rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+rTextNode.SetCountedInList(false);
+}
+
+// When exporting to ReqIF:
+ExportToReqif();
+
+// Then make sure the output is well-formed xhtml:
+SvMemoryStream aStream;
+HtmlExportTest::wrapFragment(maTempFile, aStream);
+xmlDocUniquePtr pXmlDoc = parseXmlStream();
+CPPUNIT_ASSERT(pXmlDoc);
+// Without the accompanying fix in place, this test would have failed:
+// - expected: ..
+// - actual  : ..
+// because a  without a matching  is not well-formed, and the 
 was omitted because
+// the second para was not numbered.
+assertXPath(pXmlDoc,
+
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:p",
 2);
+}
+
 CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testBlockQuoteNoMargin)
 {
 // Given a document with some text, para style set to Quotations, no 
bottom margin:
diff --git a/sw/source/filter/html/htmlnumwriter.cxx 
b/sw/source/filter/html/htmlnumwriter.cxx
index 7df3402dda35..df15619cd85e 100644
--- a/sw/source/filter/html/htmlnumwriter.cxx
+++ b/sw/source/filter/html/htmlnumwriter.cxx
@@ -321,25 +321,10 @@ Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt,
 bool bSameRule = rNextInfo.GetNumRule() == rInfo.GetNumRule();
 bool bListEnd = !bSameRule || rNextInfo.GetDepth() < rInfo.GetDepth() || 
rNextInfo.IsRestart();
 
-if (rWrt.mbXHTML)
-{
-// XHTML  for the list item content.
-if ((bListEnd && rInfo.IsNumbered()) || (!bListEnd && 
rNextInfo.IsNumbered()))
-{
-HTMLOutFuncs::Out_AsciiTag(rWrt.Strm(),
-   
OStringConcatenation(rWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_li), false);
-}
-}
-
-if (!bListEnd)
-{
-return rWrt;
-}
-
+std::optional oAtLeastOneNumbered;
 if (rWrt.mbXHTML && !rInfo.IsNumbered())
 {
-// If the list only consisted of non-numbered text