writerfilter/source/dmapper/DomainMapper_Impl.cxx |   80 ++++++++--------------
 writerfilter/source/dmapper/DomainMapper_Impl.hxx |    6 -
 2 files changed, 32 insertions(+), 54 deletions(-)

New commits:
commit 7bd401fa4e458c4ca16f7eb88289d50059e1d32e
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Wed Oct 11 23:09:00 2023 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Oct 12 09:31:09 2023 +0200

    writerfilter: clean-up PushPageHeaderFooter method impl.
    
    in addition change m_aHeaderFooterTextAppendStack to use enum
    PagePartType for the "second" value in pair, instead of a bool to
    denote if it is an entry for header or footer.
    
    No change in functionality.
    
    Change-Id: I2aa75494c9b3337dd51bf79e282291cdca9d8547
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157839
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index f9f6dbd52d65..1c4925b290d8 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -3415,10 +3415,10 @@ void 
DomainMapper_Impl::ConvertHeaderFooterToTextFrame(bool bDynamicHeightTop, b
 {
     while (!m_aHeaderFooterTextAppendStack.empty())
     {
-        auto aFooterHeader = m_aHeaderFooterTextAppendStack.top();
-        if ((aFooterHeader.second && !bDynamicHeightTop) || 
(!aFooterHeader.second && !bDynamicHeightBottom))
+        auto& [aTextAppendContext, ePagePartType] = 
m_aHeaderFooterTextAppendStack.top();
+        if ((ePagePartType == PagePartType::Header && !bDynamicHeightTop) || 
(ePagePartType == PagePartType::Footer && !bDynamicHeightBottom))
         {
-            uno::Reference< text::XTextAppend > xTextAppend = 
aFooterHeader.first.xTextAppend;
+            uno::Reference< text::XTextAppend > xTextAppend = 
aTextAppendContext.xTextAppend;
             uno::Reference< text::XTextCursor > xCursor = 
xTextAppend->createTextCursor();
             uno::Reference< text::XTextRange > xRangeStart, xRangeEnd;
 
@@ -3444,13 +3444,12 @@ void 
DomainMapper_Impl::ConvertHeaderFooterToTextFrame(bool bDynamicHeightTop, b
             fillEmptyFrameProperties(aFrameProperties, false);
 
             // If it is a footer, then orient the frame to the bottom
-            if (!aFooterHeader.second)
+            if (ePagePartType == PagePartType::Footer)
+            {
                 
aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_VERT_ORIENT),
 text::VertOrientation::BOTTOM));
-
-            uno::Reference<text::XTextAppendAndConvert> xBodyText(
-                xRangeStart->getText(), uno::UNO_QUERY);
-            xBodyText->convertToTextFrame(xTextAppend, xRangeEnd,
-                comphelper::containerToSequence(aFrameProperties));
+            }
+            uno::Reference<text::XTextAppendAndConvert> 
xBodyText(xRangeStart->getText(), uno::UNO_QUERY);
+            xBodyText->convertToTextFrame(xTextAppend, xRangeEnd, 
comphelper::containerToSequence(aFrameProperties));
         }
         m_aHeaderFooterTextAppendStack.pop();
     }
@@ -3468,7 +3467,7 @@ void DomainMapper_Impl::PushPageHeaderFooter(PagePartType 
ePagePartType, PageTyp
     const PropertyIds ePropIsOn = bHeader ? PROP_HEADER_IS_ON: 
PROP_FOOTER_IS_ON;
     const PropertyIds ePropShared = bHeader ? PROP_HEADER_IS_SHARED: 
PROP_FOOTER_IS_SHARED;
     const PropertyIds ePropTextLeft = bHeader ? PROP_HEADER_TEXT_LEFT: 
PROP_FOOTER_TEXT_LEFT;
-    const PropertyIds ePropText = bHeader ? PROP_HEADER_TEXT: PROP_FOOTER_TEXT;
+    const PropertyIds ePropTextRight = bHeader ? PROP_HEADER_TEXT: 
PROP_FOOTER_TEXT;
 
     m_bDiscardHeaderFooter = true;
     m_eInHeaderFooterImport = bHeader ? HeaderFooterImportState::header : 
HeaderFooterImportState::footer;
@@ -3476,8 +3475,8 @@ void DomainMapper_Impl::PushPageHeaderFooter(PagePartType 
ePagePartType, PageTyp
     //get the section context
     PropertyMapPtr pContext = 
DomainMapper_Impl::GetTopContextOfType(CONTEXT_SECTION);
     //ask for the header/footer name of the given type
-    SectionPropertyMap* pSectionContext = dynamic_cast< SectionPropertyMap* >( 
pContext.get() );
-    if(!pSectionContext)
+    SectionPropertyMap* pSectionContext = 
dynamic_cast<SectionPropertyMap*>(pContext.get());
+    if (!pSectionContext)
         return;
 
     // clear the "Link To Previous" flag so that the header/footer
@@ -3494,31 +3493,24 @@ void 
DomainMapper_Impl::PushPageHeaderFooter(PagePartType ePagePartType, PageTyp
         return;
     try
     {
-        bool bLeft = eType == PageType::LEFT;
-        bool bFirst = eType == PageType::FIRST;
-        if (!bLeft || GetSettingsTable()->GetEvenAndOddHeaders())
+        const PropertyIds ePropText = eType == PageType::LEFT ? ePropTextLeft 
: ePropTextRight;
+        if (eType != PageType::LEFT || 
GetSettingsTable()->GetEvenAndOddHeaders())
         {
             //switch on header/footer use
             xPageStyle->setPropertyValue(getPropertyName(ePropIsOn), 
uno::Any(true));
 
             // If the 'Different Even & Odd Pages' flag is turned on - do not 
ignore it
             // Even if the 'Even' header/footer is blank - the flag should be 
imported (so it would look in LO like in Word)
-            if (!bFirst && GetSettingsTable()->GetEvenAndOddHeaders())
+            if (eType != PageType::FIRST && 
GetSettingsTable()->GetEvenAndOddHeaders())
                 xPageStyle->setPropertyValue(getPropertyName(ePropShared), 
uno::Any(false));
 
             //set the interface
-            uno::Reference< text::XText > xText;
-            xPageStyle->getPropertyValue(getPropertyName(bLeft? ePropTextLeft: 
ePropText)) >>= xText;
-
-            m_aTextAppendStack.push(TextAppendContext(uno::Reference< 
text::XTextAppend >(xText, uno::UNO_QUERY_THROW),
-                m_bIsNewDoc
-                    ? uno::Reference<text::XTextCursor>()
-                    : xText->createTextCursorByRange(xText->getStart())));
-            
m_aHeaderFooterTextAppendStack.push(std::make_pair(TextAppendContext(uno::Reference<
 text::XTextAppend >(xText, uno::UNO_QUERY_THROW),
-                m_bIsNewDoc
-                    ? uno::Reference<text::XTextCursor>()
-                    : xText->createTextCursorByRange(xText->getStart())),
-                bHeader));
+            uno::Reference<text::XText> xText;
+            xPageStyle->getPropertyValue(getPropertyName(ePropText)) >>= xText;
+            auto xTextCursor = m_bIsNewDoc ? 
uno::Reference<text::XTextCursor>() : 
xText->createTextCursorByRange(xText->getStart());
+            uno::Reference<text::XTextAppend> xTextAppend(xText, 
uno::UNO_QUERY_THROW);
+            m_aTextAppendStack.push(TextAppendContext(xTextAppend, 
xTextCursor));
+            
m_aHeaderFooterTextAppendStack.push(std::make_pair(TextAppendContext(xTextAppend,
 xTextCursor), ePagePartType));
         }
         // If we have *hidden* header footer
         else
@@ -3532,13 +3524,11 @@ void 
DomainMapper_Impl::PushPageHeaderFooter(PagePartType ePagePartType, PageTyp
             xPageStyle->setPropertyValue(getPropertyName(ePropShared), 
uno::Any(false));
             // Add the content of the headers footers to the doc
             uno::Reference<text::XText> xText;
-            xPageStyle->getPropertyValue(getPropertyName(bLeft ? ePropTextLeft 
: ePropText))
-                >>= xText;
+            xPageStyle->getPropertyValue(getPropertyName(ePropText)) >>= xText;
+            auto xTextCursor = m_bIsNewDoc ? 
uno::Reference<text::XTextCursor>() : 
xText->createTextCursorByRange(xText->getStart());
+            uno::Reference<text::XTextAppend> xTextAppend(xText, 
uno::UNO_QUERY_THROW);
+            m_aTextAppendStack.push(TextAppendContext(xTextAppend, 
xTextCursor));
 
-            m_aTextAppendStack.push(
-                TextAppendContext(uno::Reference<text::XTextAppend>(xText, 
uno::UNO_QUERY_THROW),
-                                  m_bIsNewDoc ? 
uno::Reference<text::XTextCursor>()
-                                              : 
xText->createTextCursorByRange(xText->getStart())));
             // Restore the original state of the shared prop after we stored 
the necessary values.
             xPageStyle->setPropertyValue(getPropertyName(ePropShared), 
uno::Any(bIsShared));
         }
@@ -3550,16 +3540,6 @@ void 
DomainMapper_Impl::PushPageHeaderFooter(PagePartType ePagePartType, PageTyp
     }
 }
 
-void DomainMapper_Impl::PushPageHeader(PageType eType)
-{
-    PushPageHeaderFooter(PagePartType::Header, eType);
-}
-
-void DomainMapper_Impl::PushPageFooter(PageType eType)
-{
-    PushPageHeaderFooter(PagePartType::Footer, eType);
-}
-
 void DomainMapper_Impl::PopPageHeaderFooter()
 {
     //header and footer always have an empty paragraph at the end
@@ -9286,22 +9266,22 @@ void DomainMapper_Impl::substream(Id rName,
     switch( rName )
     {
     case NS_ooxml::LN_headerl:
-            PushPageHeader(PageType::LEFT);
+            PushPageHeaderFooter(PagePartType::Header, PageType::LEFT);
         break;
     case NS_ooxml::LN_headerr:
-            PushPageHeader(PageType::RIGHT);
+            PushPageHeaderFooter(PagePartType::Header, PageType::RIGHT);
         break;
     case NS_ooxml::LN_headerf:
-            PushPageHeader(PageType::FIRST);
+            PushPageHeaderFooter(PagePartType::Header, PageType::FIRST);
         break;
     case NS_ooxml::LN_footerl:
-            PushPageFooter(PageType::LEFT);
+            PushPageHeaderFooter(PagePartType::Footer, PageType::LEFT);
         break;
     case NS_ooxml::LN_footerr:
-            PushPageFooter(PageType::RIGHT);
+            PushPageHeaderFooter(PagePartType::Footer, PageType::RIGHT);
         break;
     case NS_ooxml::LN_footerf:
-            PushPageFooter(PageType::FIRST);
+            PushPageHeaderFooter(PagePartType::Footer, PageType::FIRST);
         break;
     case NS_ooxml::LN_footnote:
     case NS_ooxml::LN_endnote:
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 83a804cf618d..95382009766e 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -460,7 +460,8 @@ private:
     std::stack<TextAppendContext>                                              
     m_aTextAppendStack;
     std::stack<AnchoredContext>                                                
     m_aAnchoredStack;
     std::stack<HeaderFooterContext>                                            
     m_aHeaderFooterStack;
-    std::stack<std::pair<TextAppendContext, bool>>                             
     m_aHeaderFooterTextAppendStack;
+    std::stack<std::pair<TextAppendContext, PagePartType>> 
m_aHeaderFooterTextAppendStack;
+
     std::deque<FieldContextPtr> m_aFieldStack;
     bool m_bForceGenericFields;
     /// Type of decimal symbol associated to the document language in Writer 
locale definition
@@ -853,9 +854,6 @@ public:
     /// Get the first pending shape, if there are any.
     css::uno::Reference<css::drawing::XShape> PopPendingShape();
 
-    void PushPageHeader(PageType eType);
-    void PushPageFooter(PageType eType);
-
     void PopPageHeaderFooter();
     bool IsInHeaderFooter() const { return m_eInHeaderFooterImport != 
HeaderFooterImportState::none; }
     void ConvertHeaderFooterToTextFrame(bool, bool);

Reply via email to