sw/qa/extras/mailmerge/data/bookmarkcondition.fodt |   91 +++++++++++++++++++++
 sw/qa/extras/mailmerge/data/bookmarkcondition.ods  |binary
 sw/qa/extras/mailmerge/mailmerge.cxx               |   27 ++++++
 sw/source/core/crsr/bookmrk.cxx                    |    3 
 sw/source/core/doc/DocumentFieldsManager.cxx       |   11 ++
 sw/source/core/doc/docfld.cxx                      |   58 +++++++++++--
 sw/source/core/inc/docfld.hxx                      |   12 ++
 sw/source/core/text/porlay.cxx                     |   22 -----
 sw/source/ui/misc/bookmark.cxx                     |    4 
 9 files changed, 194 insertions(+), 34 deletions(-)

New commits:
commit 43fc5f3aee4c06fb5983b625175d6991433945d4
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Fri Aug 20 17:09:28 2021 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Mon Aug 23 15:42:43 2021 +0200

    sw: evaluate bookmark conditions differently
    
    Conditions may refer to database rows in mail merge, which requires a
    SwDBManager to evaluate.
    
    So do it in DocumentFieldsManager::UpdateExpFieldsImpl() where the
    similar conditions on sections and fields are evaluated.
    
    Change the meaning of the m_bHidden flag to store the result of
    evaluating the condition, instead of being always true when there is
    a condition.
    
    Change-Id: Ib8f5483e7f68fc37c650b790b70d10af3c1e6f28
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120793
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/qa/extras/mailmerge/data/bookmarkcondition.fodt 
b/sw/qa/extras/mailmerge/data/bookmarkcondition.fodt
new file mode 100644
index 000000000000..0f9d5a90b1dc
--- /dev/null
+++ b/sw/qa/extras/mailmerge/data/bookmarkcondition.fodt
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document xmlns:officeooo="http://openoffice.org/2009/office"; 
xmlns:css3t="http://www.w3.org/TR/css3-text/"; 
xmlns:grddl="http://www.w3.org/2003/g/data-view#"; 
xmlns:xhtml="http://www.w3.org/1999/xhtml"; 
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" 
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" 
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" 
xmlns:oooc="http://openoffice.org/2004/calc"; 
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" 
xmlns:ooow="http://openoffice.org/2004/writer"; 
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" 
xmlns:dc="http://purl.org/dc/elements/1.1/"; 
xmlns:rpt="http://openoffice.org/2005/report"; 
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" 
xmlns:config="urn:oasis:names:tc:opendocument:xmlns
 :config:1.0" xmlns:xlink="http://www.w3.org/1999/xlink"; 
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" 
xmlns:ooo="http://openoffice.org/2004/office"; 
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" 
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" 
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" 
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" 
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" 
xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
 xmlns:tableooo="http://openoffice.org/2009/table"; 
xmlns:drawooo="http://openoffice.org/2010/draw"; 
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
 xmlns:dom="http://www.w3.org/2001/xml-events"; 
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" 
xmlns:math="http://www.w3.org/1998/Math/MathML"; 
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="ur
 n:oasis:names:tc:opendocument:xmlns:script:1.0" 
xmlns:xforms="http://www.w3.org/2002/xforms"; office:version="1.2" 
office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:font-face-decls>
+  <style:font-face style:name="Liberation Serif" 
svg:font-family="&apos;Liberation Serif&apos;" 
style:font-family-generic="roman" style:font-pitch="variable"/>
+  <style:font-face style:name="Lohit Devanagari" svg:font-family="&apos;Lohit 
Devanagari&apos;" style:font-family-generic="system" 
style:font-pitch="variable"/>
+  <style:font-face style:name="Source Han Serif CN" 
svg:font-family="&apos;Source Han Serif CN&apos;" 
style:font-family-generic="system" style:font-pitch="variable"/>
+ </office:font-face-decls>
+ <office:styles>
+  <style:default-style style:family="graphic">
+   <style:graphic-properties svg:stroke-color="#3465a4" 
draw:fill-color="#729fcf" fo:wrap-option="no-wrap" draw:shadow-offset-x="0.3cm" 
draw:shadow-offset-y="0.3cm" draw:start-line-spacing-horizontal="0.283cm" 
draw:start-line-spacing-vertical="0.283cm" 
draw:end-line-spacing-horizontal="0.283cm" 
draw:end-line-spacing-vertical="0.283cm" style:flow-with-text="false"/>
+   <style:paragraph-properties style:text-autospace="ideograph-alpha" 
style:line-break="strict" style:writing-mode="lr-tb" 
style:font-independent-line-spacing="false">
+    <style:tab-stops/>
+   </style:paragraph-properties>
+   <style:text-properties style:use-window-font-color="true" 
loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" 
fo:language="de" fo:country="DE" style:letter-kerning="true" 
style:font-name-asian="Source Han Serif CN" style:font-size-asian="10.5pt" 
style:language-asian="zh" style:country-asian="CN" 
style:font-name-complex="Lohit Devanagari" style:font-size-complex="12pt" 
style:language-complex="hi" style:country-complex="IN"/>
+  </style:default-style>
+  <style:default-style style:family="paragraph">
+   <style:paragraph-properties fo:orphans="2" fo:widows="2" 
fo:hyphenation-ladder-count="no-limit" style:text-autospace="ideograph-alpha" 
style:punctuation-wrap="hanging" style:line-break="strict" 
style:tab-stop-distance="1.251cm" style:writing-mode="page"/>
+   <style:text-properties style:use-window-font-color="true" 
loext:opacity="0%" style:font-name="Liberation Serif" fo:font-size="12pt" 
fo:language="de" fo:country="DE" style:letter-kerning="true" 
style:font-name-asian="Source Han Serif CN" style:font-size-asian="10.5pt" 
style:language-asian="zh" style:country-asian="CN" 
style:font-name-complex="Lohit Devanagari" style:font-size-complex="12pt" 
style:language-complex="hi" style:country-complex="IN" fo:hyphenate="false" 
fo:hyphenation-remain-char-count="2" fo:hyphenation-push-char-count="2" 
loext:hyphenation-no-caps="false"/>
+  </style:default-style>
+  <style:default-style style:family="table">
+   <style:table-properties table:border-model="collapsing"/>
+  </style:default-style>
+  <style:default-style style:family="table-row">
+   <style:table-row-properties fo:keep-together="auto"/>
+  </style:default-style>
+  <style:style style:name="Standard" style:family="paragraph" 
style:class="text"/>
+  <style:style style:name="Table_20_Contents" style:display-name="Table 
Contents" style:family="paragraph" style:parent-style-name="Standard" 
style:class="extra">
+   <style:paragraph-properties fo:orphans="0" fo:widows="0" 
text:number-lines="false" text:line-number="0"/>
+  </style:style>
+
+  <text:notes-configuration text:note-class="footnote" style:num-format="1" 
text:start-value="0" text:footnotes-position="page" 
text:start-numbering-at="document"/>
+  <text:notes-configuration text:note-class="endnote" style:num-format="i" 
text:start-value="0"/>
+  <text:linenumbering-configuration text:number-lines="false" 
text:offset="0.499cm" style:num-format="1" text:number-position="left" 
text:increment="5"/>
+ </office:styles>
+ <office:automatic-styles>
+  <style:style style:name="P1" style:family="paragraph" 
style:parent-style-name="Standard">
+   <style:text-properties officeooo:rsid="001fe5a9" 
officeooo:paragraph-rsid="001fe5a9"/>
+  </style:style>
+  <style:style style:name="T1" style:family="text">
+   <style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" 
style:font-weight-complex="bold"/>
+  </style:style>
+  <style:style style:name="Sect1" style:family="section">
+   <style:section-properties style:editable="false">
+    <style:columns fo:column-count="1" fo:column-gap="0cm"/>
+   </style:section-properties>
+  </style:style>
+  <style:page-layout style:name="pm1">
+   <style:page-layout-properties fo:page-width="21.001cm" 
fo:page-height="29.7cm" style:num-format="1" style:print-orientation="portrait" 
fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" 
fo:margin-right="2cm" style:writing-mode="lr-tb" 
style:footnote-max-height="0cm">
+    <style:footnote-sep style:width="0.018cm" 
style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" 
style:line-style="solid" style:adjustment="left" style:rel-width="25%" 
style:color="#000000"/>
+   </style:page-layout-properties>
+   <style:header-style/>
+   <style:footer-style/>
+  </style:page-layout>
+ </office:automatic-styles>
+ <office:master-styles>
+  <style:master-page style:name="Standard" style:page-layout-name="pm1"/>
+ </office:master-styles>
+ <office:body>
+  <office:text>
+      <text:p text:style-name="P1"/>
+      <text:section text:style-name="Sect1" text:name="a" 
text:condition="ooow:([WM:SE_S_Berge] != &quot;true&quot;)" 
text:is-hidden="true" text:display="condition">
+        <text:p text:style-name="P1">In den Bergen war es anstrengend.</text:p>
+      </text:section>
+      <text:p text:style-name="P1"/>
+      <text:section text:style-name="Sect1" text:name="b" 
text:condition="ooow:([WM:SE_S_Barcelona] != &quot;true&quot;)" 
text:is-hidden="true" text:display="condition">
+        <text:p text:style-name="P1">In Barcelona war es schön.</text:p>
+      </text:section>
+      <text:p text:style-name="P1"/>
+      <text:section text:style-name="Sect1" text:name="c" 
text:condition="ooow:([WM:SE_S_Paris] != &quot;true&quot;)" 
text:is-hidden="true" text:display="condition">
+        <text:p text:style-name="P1">In Paris war es erlebnisreich.</text:p>
+      </text:section>
+      <text:p text:style-name="P1"/>
+      <text:p text:style-name="P1">
+        <text:span text:style-name="T1">Mein Urlaub war </text:span>
+        <text:bookmark-start text:name="S_Berge" loext:hidden="true" 
loext:condition="([WM:SE_S_Berge] != &quot;true&quot;)"/>
+        <text:span text:style-name="T1">anstrengend</text:span>
+        <text:bookmark-start text:name="S_Barcelona" loext:hidden="true" 
loext:condition="([WM:SE_S_Barcelona] != &quot;true&quot;)"/>
+        <text:bookmark-end text:name="S_Berge"/>
+        <text:span text:style-name="T1">schön</text:span>
+        <text:bookmark-start text:name="S_Paris" loext:hidden="true" 
loext:condition="([WM:SE_S_Paris] != &quot;true&quot;)"/>
+        <text:bookmark-end text:name="S_Barcelona"/>
+        <text:span text:style-name="T1">erlebnisreich</text:span>
+        <text:bookmark-end text:name="S_Paris"/>
+        <text:span text:style-name="T1">.</text:span>
+      </text:p>
+      <text:p text:style-name="P1"/>
+
+  </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/extras/mailmerge/data/bookmarkcondition.ods 
b/sw/qa/extras/mailmerge/data/bookmarkcondition.ods
new file mode 100644
index 000000000000..463781ed5f6e
Binary files /dev/null and b/sw/qa/extras/mailmerge/data/bookmarkcondition.ods 
differ
diff --git a/sw/qa/extras/mailmerge/mailmerge.cxx 
b/sw/qa/extras/mailmerge/mailmerge.cxx
index 67fb47fe6996..98c626d07f0c 100644
--- a/sw/qa/extras/mailmerge/mailmerge.cxx
+++ b/sw/qa/extras/mailmerge/mailmerge.cxx
@@ -589,6 +589,33 @@ DECLARE_SHELL_MAILMERGE_TEST(testTdf92623, "tdf92623.odt", 
"10-testing-addresses
     CPPUNIT_ASSERT_EQUAL(sal_Int32(10), countFieldMarks);
 }
 
+DECLARE_SHELL_MAILMERGE_TEST(testBookmarkCondition, "bookmarkcondition.fodt", 
"bookmarkcondition.ods", "data")
+{
+    executeMailMerge();
+
+    dumpMMLayout();
+    xmlDocUniquePtr pLayout(
+        xmlParseMemory(reinterpret_cast<const 
char*>(xmlBufferContent(mpXmlBuffer)),
+                       xmlBufferLength(mpXmlBuffer)));
+
+    // check that conditions on sections and bookmarks are evaluated the same
+    assertXPath(pLayout, "/root/page", 7);
+    assertXPath(pLayout, "/root/page[1]/body/section", 1);
+    assertXPath(pLayout, "/root/page[1]/body/section[1]/txt[1]/LineBreak", 
"Line", u"In den Bergen war es anstrengend.");
+    assertXPath(pLayout, "/root/page[1]/body/txt[5]/LineBreak", "Line", u"Mein 
Urlaub war anstrengend . ");
+    assertXPath(pLayout, "/root/page[3]/body/section", 1);
+    assertXPath(pLayout, "/root/page[3]/body/section[1]/txt[1]/LineBreak", 
"Line", u"In Barcelona war es schön.");
+    assertXPath(pLayout, "/root/page[3]/body/txt[5]/LineBreak", "Line", u"Mein 
Urlaub war schön . ");
+    assertXPath(pLayout, "/root/page[5]/body/section", 1);
+    assertXPath(pLayout, "/root/page[5]/body/section[1]/txt[1]/LineBreak", 
"Line", "In Paris war es erlebnisreich.");
+    assertXPath(pLayout, "/root/page[5]/body/txt[5]/LineBreak", "Line", u"Mein 
Urlaub war erlebnisreich . ");
+    assertXPath(pLayout, "/root/page[7]/body/section", 3);
+    assertXPath(pLayout, "/root/page[7]/body/section[1]/txt[1]/LineBreak", 
"Line", u"In den Bergen war es anstrengend.");
+    assertXPath(pLayout, "/root/page[7]/body/section[2]/txt[1]/LineBreak", 
"Line", u"In Barcelona war es schön.");
+    assertXPath(pLayout, "/root/page[7]/body/section[3]/txt[1]/LineBreak", 
"Line", u"In Paris war es erlebnisreich.");
+    assertXPath(pLayout, "/root/page[7]/body/txt[5]/LineBreak", "Line", u"Mein 
Urlaub war anstrengend schön erlebnisreich . ");
+}
+
 DECLARE_SHELL_MAILMERGE_TEST_SELECTION(testTdf95292, "linked-labels.odt", 
"10-testing-addresses.ods", "testing-addresses", 5)
 {
     // A document with two labels merged with 5 datasets should result in 
three pages
diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx
index 5f39798b767a..dc45eb7e22d4 100644
--- a/sw/source/core/crsr/bookmrk.cxx
+++ b/sw/source/core/crsr/bookmrk.cxx
@@ -452,7 +452,8 @@ namespace sw::mark
         if (m_sHideCondition != rHideCondition)
         {
             m_sHideCondition = rHideCondition;
-            InvalidateFrames();
+            // don't eval condition here yet - probably only needed for
+            // UI editing condition and that doesn't exist yet
         }
     }
 
diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx 
b/sw/source/core/doc/DocumentFieldsManager.cxx
index 85f4761fb13d..adf7e26e4e05 100644
--- a/sw/source/core/doc/DocumentFieldsManager.cxx
+++ b/sw/source/core/doc/DocumentFieldsManager.cxx
@@ -1039,6 +1039,17 @@ void DocumentFieldsManager::UpdateExpFieldsImpl(
             }
             continue;
         }
+        ::sw::mark::IBookmark *const pBookmark(
+                const_cast<::sw::mark::IBookmark *>(it->GetBookmark()));
+        if (pBookmark)
+        {
+            SwSbxValue const 
aValue(aCalc.Calculate(pBookmark->GetHideCondition()));
+            if (!aValue.IsVoidValue())
+            {
+                pBookmark->Hide(aValue.GetBool());
+            }
+            continue;
+        }
 
         SwTextField* pTextField = const_cast<SwTextField*>(it->GetTextField());
         if( !pTextField )
diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx
index 74483926e90e..fa8d0d2e2484 100644
--- a/sw/source/core/doc/docfld.cxx
+++ b/sw/source/core/doc/docfld.cxx
@@ -29,6 +29,7 @@
 #endif
 #include <doc.hxx>
 #include <IDocumentFieldsAccess.hxx>
+#include <IDocumentMarkAccess.hxx>
 #include <IDocumentState.hxx>
 #include <IDocumentLayoutAccess.hxx>
 #include <cntfrm.hxx>
@@ -104,6 +105,24 @@ SetGetExpField::SetGetExpField( const SwSectionNode& 
rSectNd,
     }
 }
 
+SetGetExpField::SetGetExpField(::sw::mark::IBookmark const& rBookmark,
+                               SwPosition const*const pPos)
+{
+    m_eSetGetExpFieldType = BOOKMARK;
+    m_CNTNT.pBookmark = &rBookmark;
+
+    if (pPos)
+    {
+        m_nNode = pPos->nNode.GetIndex();
+        m_nContent = pPos->nContent.GetIndex();
+    }
+    else
+    {
+        m_nNode = rBookmark.GetMarkStart().nNode.GetIndex();
+        m_nContent = rBookmark.GetMarkStart().nContent.GetIndex();;
+    }
+}
+
 SetGetExpField::SetGetExpField( const SwTableBox& rTBox )
 {
     m_eSetGetExpFieldType = TABLEBOX;
@@ -274,6 +293,10 @@ const SwNode* SetGetExpField::GetNodeFromContent() const
             pRet = m_CNTNT.pSection->GetFormat()->GetSectionNode();
             break;
 
+        case BOOKMARK:
+            pRet = &m_CNTNT.pBookmark->GetMarkStart().nNode.GetNode();
+            break;
+
         case CRSRPOS:
             pRet = &m_CNTNT.pPos->nNode.GetNode();
             break;
@@ -315,6 +338,9 @@ sal_Int32 SetGetExpField::GetCntPosFromContent() const
         case TEXTTOXMARK:
             nRet = m_CNTNT.pTextTOX->GetStart();
             break;
+        case BOOKMARK:
+            nRet = m_CNTNT.pBookmark->GetMarkStart().nContent.GetIndex();
+            break;
         case CRSRPOS:
             nRet =  m_CNTNT.pPos->nContent.GetIndex();
             break;
@@ -858,7 +884,20 @@ void SwDocUpdateField::MakeFieldList_( SwDoc& rDoc, int 
eGetMode )
         // add all to the list so that they are sorted
         for (const auto &nId : aTmpArr)
         {
-            GetBodyNode( *rDoc.GetNodes()[ nId ]->GetSectionNode() );
+            SwSectionNode const& rSectionNode(*rDoc.GetNodes()[ nId 
]->GetSectionNode());
+            GetBodyNodeGeneric(rSectionNode, rSectionNode);
+        }
+
+        // bookmarks with hide conditions, handle similar to sections
+        auto const& rIDMA(*rDoc.getIDocumentMarkAccess());
+        for (auto it = rIDMA.getBookmarksBegin(); it != 
rIDMA.getBookmarksEnd(); ++it)
+        {
+            auto const pBookmark(dynamic_cast<::sw::mark::IBookmark 
const*>(*it));
+            assert(pBookmark);
+            if (!pBookmark->GetHideCondition().isEmpty())
+            {
+                GetBodyNodeGeneric((*it)->GetMarkStart().nNode.GetNode(), 
*pBookmark);
+            }
         }
     }
 
@@ -1035,19 +1074,22 @@ void SwDocUpdateField::GetBodyNode( const SwTextField& 
rTField, SwFieldIds nFiel
         m_pFieldSortList->insert( std::move(pNew) );
 }
 
-void SwDocUpdateField::GetBodyNode( const SwSectionNode& rSectNd )
+template<typename T>
+void SwDocUpdateField::GetBodyNodeGeneric(SwNode const& rNode, T const& rCond)
 {
-    const SwDoc& rDoc = rSectNd.GetDoc();
+    const SwDoc& rDoc = rNode.GetDoc();
     std::unique_ptr<SetGetExpField> pNew;
 
-    if( rSectNd.GetIndex() < rDoc.GetNodes().GetEndOfExtras().GetIndex() )
+    if (rNode.GetIndex() < rDoc.GetNodes().GetEndOfExtras().GetIndex())
     {
         do {            // middle check loop
 
             // we need to get the anchor first
             // create index to determine the TextNode
-            SwPosition aPos( rSectNd );
-            SwContentNode* pCNd = rDoc.GetNodes().GoNext( &aPos.nNode ); // to 
the next ContentNode
+            SwPosition aPos(rNode);
+            SwContentNode const*const pCNd = rNode.IsSectionNode()
+                ? rDoc.GetNodes().GoNext(&aPos.nNode) // to the next 
ContentNode
+                : rNode.GetContentNode();
 
             if( !pCNd || !pCNd->IsTextNode() )
                 break;
@@ -1063,13 +1105,13 @@ void SwDocUpdateField::GetBodyNode( const 
SwSectionNode& rSectNd )
 
             bool const bResult = GetBodyTextNode( rDoc, aPos, *pFrame );
             OSL_ENSURE(bResult, "where is the Field");
-            pNew.reset(new SetGetExpField( rSectNd, &aPos ));
+            pNew.reset(new SetGetExpField(rCond, &aPos));
 
         } while( false );
     }
 
     if( !pNew )
-        pNew.reset(new SetGetExpField( rSectNd ));
+        pNew.reset(new SetGetExpField(rCond));
 
     m_pFieldSortList->insert( std::move(pNew) );
 }
diff --git a/sw/source/core/inc/docfld.hxx b/sw/source/core/inc/docfld.hxx
index a1d6e816c267..f17d5451c140 100644
--- a/sw/source/core/inc/docfld.hxx
+++ b/sw/source/core/inc/docfld.hxx
@@ -23,6 +23,7 @@
 #include <calc.hxx>
 #include <doc.hxx>
 #include <IDocumentTimerAccess.hxx>
+#include <IMark.hxx>
 #include <o3tl/sorted_vector.hxx>
 #include <memory>
 
@@ -52,11 +53,12 @@ class SetGetExpField
         const SwTableBox* pTBox;
         const SwTextINetFormat* pTextINet;
         const SwFlyFrameFormat* pFlyFormat;
+        ::sw::mark::IBookmark const* pBookmark;
     } m_CNTNT;
     sal_Int32 m_nContent;
     enum SetGetExpFieldType
         {
-            TEXTFIELD, TEXTTOXMARK, SECTIONNODE, CRSRPOS, TABLEBOX,
+            TEXTFIELD, TEXTTOXMARK, SECTIONNODE, BOOKMARK, CRSRPOS, TABLEBOX,
             TEXTINET, FLYFRAME
         } m_eSetGetExpFieldType;
 
@@ -69,6 +71,9 @@ public:
     SetGetExpField( const SwSectionNode& rSectNode,
                     const SwPosition* pPos = nullptr  );
 
+    SetGetExpField( ::sw::mark::IBookmark const& rBookmark,
+                    SwPosition const* pPos = nullptr );
+
     SetGetExpField( const SwTableBox& rTableBox  );
 
     SetGetExpField( const SwNodeIndex& rNdIdx, const SwTextTOXMark& rTOX );
@@ -84,6 +89,8 @@ public:
         { return TEXTFIELD == m_eSetGetExpFieldType ? m_CNTNT.pTextField : 
nullptr; }
     const SwSection* GetSection() const
         { return SECTIONNODE == m_eSetGetExpFieldType ? m_CNTNT.pSection : 
nullptr; }
+    ::sw::mark::IBookmark const* GetBookmark() const
+        { return BOOKMARK == m_eSetGetExpFieldType ? m_CNTNT.pBookmark : 
nullptr; }
     const SwTextINetFormat* GetINetFormat() const
         { return TEXTINET == m_eSetGetExpFieldType ? m_CNTNT.pTextINet : 
nullptr; }
     const SwFlyFrameFormat* GetFlyFormat() const
@@ -142,7 +149,8 @@ class SwDocUpdateField
 
     void MakeFieldList_( SwDoc& pDoc, int eGetMode );
     void GetBodyNode( const SwTextField& , SwFieldIds nFieldWhich );
-    void GetBodyNode( const SwSectionNode&);
+    template<typename T>
+    void GetBodyNodeGeneric(SwNode const& rNode, T const&);
 
 public:
     SwDocUpdateField(SwDoc& rDocument);
diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index a66e69d88f59..052b95fec597 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -2619,28 +2619,8 @@ void SwScriptInfo::selectHiddenTextProperty(const 
SwTextNode& rNode,
             }
         }
 
-        bool bHide = false;
+        // condition is evaluated in DocumentFieldsManager::UpdateExpFields()
         if (pBookmark && pBookmark->IsHidden())
-        {
-            // bookmark is marked as hidden
-            bHide = true;
-
-            // bookmark is marked as hidden with conditions
-            if (!pBookmark->GetHideCondition().isEmpty())
-            {
-                SwDoc& rDoc = const_cast<SwDoc&>(rNode.GetDoc());
-                SwCalc aCalc(rDoc);
-                rDoc.getIDocumentFieldsAccess().FieldsToCalc(aCalc, 
rNode.GetIndex(), SAL_MAX_INT32);
-
-                SwSbxValue aValue = 
aCalc.Calculate(pBookmark->GetHideCondition());
-                if(!aValue.IsVoidValue())
-                {
-                    bHide = aValue.GetBool();
-                }
-            }
-        }
-
-        if (bHide)
         {
             // intersect bookmark range with textnode range and add the 
intersection to rHiddenMulti
 
diff --git a/sw/source/ui/misc/bookmark.cxx b/sw/source/ui/misc/bookmark.cxx
index 1eeca19769c5..54538bd502ff 100644
--- a/sw/source/ui/misc/bookmark.cxx
+++ b/sw/source/ui/misc/bookmark.cxx
@@ -440,10 +440,10 @@ void BookmarkTable::InsertBookmark(sw::mark::IMark* pMark)
     else if (bPulling && !bPulledAll)
         sBookmarkNodeText = "..." + sBookmarkNodeText;
 
+    const OUString& sHideCondition = pBookmark->GetHideCondition();
     OUString sHidden = SwResId(STR_BOOKMARK_NO);
-    if (pBookmark->IsHidden())
+    if (pBookmark->IsHidden() || !sHideCondition.isEmpty())
         sHidden = SwResId(STR_BOOKMARK_YES);
-    const OUString& sHideCondition = pBookmark->GetHideCondition();
     OUString sPageNum = 
OUString::number(SwPaM(pMark->GetMarkStart()).GetPageNum());
     int nRow = m_xControl->n_children();
     m_xControl->append(OUString::number(reinterpret_cast<sal_Int64>(pMark)), 
sPageNum);

Reply via email to