[Libreoffice-commits] .: sw/inc sw/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Mon Jul 2 07:33:22 PDT 2012


 sw/inc/doc.hxx                 |    4 
 sw/source/core/doc/docdesc.cxx |  302 +++++++++++++++--------------------------
 2 files changed, 117 insertions(+), 189 deletions(-)

New commits:
commit fb2eac0f8f65fc1f063ebec0ed19e2ed639e0b32
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Mon Jul 2 16:32:13 2012 +0200

    SwDoc: kill copy&paste with CopyMasterHeader() and CopyMasterFooter()
    
    Change-Id: I10480cc7977e7227a6abe84e7bf27f69a980f89a

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 290a288..1529b87 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -2082,6 +2082,10 @@ public:
 private:
     /// method to set new graphics pool defaults, must only be called by SetDrawDefaults!
     void UpdateDrawDefaults();
+    /// Copies master header to left / first one, if necessary - used by ChgPageDesc().
+    void CopyMasterHeader(const SwPageDesc &rChged, const SwFmtHeader &rHead, SwPageDesc *pDesc, bool bLeft);
+    /// Copies master footer to left / first one, if necessary - used by ChgPageDesc().
+    void CopyMasterFooter(const SwPageDesc &rChged, const SwFmtFooter &rFoot, SwPageDesc *pDesc, bool bLeft);
 };
 
 // This method is called in Dtor of SwDoc and deletes cache of ContourObjects.
diff --git a/sw/source/core/doc/docdesc.cxx b/sw/source/core/doc/docdesc.cxx
index 52934cd..23fe98a 100644
--- a/sw/source/core/doc/docdesc.cxx
+++ b/sw/source/core/doc/docdesc.cxx
@@ -184,82 +184,24 @@ void lcl_DescSetAttr( const SwFrmFmt &rSource, SwFrmFmt &rDest,
     rDest.SetPoolHlpFileId( rSource.GetPoolHlpFileId() );
 }
 
-
-void SwDoc::ChgPageDesc( sal_uInt16 i, const SwPageDesc &rChged )
+void SwDoc::CopyMasterHeader(const SwPageDesc &rChged, const SwFmtHeader &rHead, SwPageDesc *pDesc, bool bLeft)
 {
-    OSL_ENSURE( i < aPageDescs.size(), "PageDescs is out of range." );
-
-    SwPageDesc *pDesc = aPageDescs[i];
-    SwRootFrm* pTmpRoot = GetCurrentLayout();
-
-    if (GetIDocumentUndoRedo().DoesUndo())
-    {
-        SwUndo *const pUndo(new SwUndoPageDesc(*pDesc, rChged, this));
-        GetIDocumentUndoRedo().AppendUndo(pUndo);
-    }
-    ::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo());
-
-    // Mirror at first if needed.
-    if ( rChged.GetUseOn() == nsUseOnPage::PD_MIRROR )
-        ((SwPageDesc&)rChged).Mirror();
-    else
-        // Or else transfer values from Master to Left.
-        ::lcl_DescSetAttr( ((SwPageDesc&)rChged).GetMaster(),
-                       ((SwPageDesc&)rChged).GetLeft() );
-
-    // Take over NumType.
-    if( rChged.GetNumType().GetNumberingType() != pDesc->GetNumType().GetNumberingType() )
-    {
-        pDesc->SetNumType( rChged.GetNumType() );
-        // Notify page number fields that NumFormat has changed
-        GetSysFldType( RES_PAGENUMBERFLD )->UpdateFlds();
-        GetSysFldType( RES_REFPAGEGETFLD )->UpdateFlds();
-
-        // If the numbering scheme has changed we could have QuoVadis/ErgoSum texts
-        // that refer to a changed page, so we invalidate foot notes.
-        SwFtnIdxs& rFtnIdxs = GetFtnIdxs();
-        for( sal_uInt16 nPos = 0; nPos < rFtnIdxs.Count(); ++nPos )
-        {
-            SwTxtFtn *pTxtFtn = rFtnIdxs[ nPos ];
-            const SwFmtFtn &rFtn = pTxtFtn->GetFtn();
-            pTxtFtn->SetNumber( rFtn.GetNumber(), &rFtn.GetNumStr());
-        }
-    }
-
-    // Take over orientation
-    pDesc->SetLandscape( rChged.GetLandscape() );
-
-    // #i46909# no undo if header or footer changed
-    bool bHeaderFooterChanged = false;
-
-    // Synch header.
-    const SwFmtHeader &rHead = rChged.GetMaster().GetHeader();
-    if (undoGuard.UndoWasEnabled())
-    {
-        // #i46909# no undo if header or footer changed
-        // Did something change in the nodes?
-        const SwFmtHeader &rOldHead = pDesc->GetMaster().GetHeader();
-        bHeaderFooterChanged |=
-            ( rHead.IsActive() != rOldHead.IsActive() ||
-              rChged.IsHeaderShared() != pDesc->IsHeaderShared() ||
-              rChged.IsHeaderSharedFirst() != pDesc->IsHeaderSharedFirst() );
-    }
-    pDesc->GetMaster().SetFmtAttr( rHead );
-    if ( rChged.IsHeaderShared() || !rHead.IsActive() )
+    SwFrmFmt& rDescFrmFmt = (bLeft ? pDesc->GetLeft() : pDesc->GetFirst());
+    if ( (bLeft ? rChged.IsHeaderShared() : rChged.IsHeaderSharedFirst() ) || !rHead.IsActive() )
     {
-        // Left shares the header with the Master.
-        pDesc->GetLeft().SetFmtAttr( pDesc->GetMaster().GetHeader() );
+        // Left or first shares the header with the Master.
+        rDescFrmFmt.SetFmtAttr( pDesc->GetMaster().GetHeader() );
     }
     else if ( rHead.IsActive() )
-    {   // Left gets its own header if the Format doesn't alrady have one.
+    {   // Left or first gets its own header if the Format doesn't alrady have one.
         // If it already has one and it points to the same Section as the
         // Right one, it needs to get an own Header.
         // The content is evidently copied.
-        const SwFmtHeader &rLeftHead = pDesc->GetLeft().GetHeader();
-        if ( !rLeftHead.IsActive() )
+        const SwFmtHeader &rFmtHead = rDescFrmFmt.GetHeader();
+        if ( !rFmtHead.IsActive() )
         {
             SwFmtHeader aHead( MakeLayoutFmt( RND_STD_HEADERL, 0 ) );
-            pDesc->GetLeft().SetFmtAttr( aHead );
+            rDescFrmFmt.SetFmtAttr( aHead );
             // take over additional attributes (margins, borders ...)
             ::lcl_DescSetAttr( *rHead.GetHeaderFmt(), *aHead.GetHeaderFmt(), sal_False);
         }
@@ -267,66 +209,20 @@ void SwDoc::ChgPageDesc( sal_uInt16 i, const SwPageDesc &rChged )
         {
             const SwFrmFmt *pRight = rHead.GetHeaderFmt();
             const SwFmtCntnt &aRCnt = pRight->GetCntnt();
-            const SwFmtCntnt &aLCnt = rLeftHead.GetHeaderFmt()->GetCntnt();
-            if( !aLCnt.GetCntntIdx() )
-                pDesc->GetLeft().SetFmtAttr( rChged.GetLeft().GetHeader() );
-            else if( (*aRCnt.GetCntntIdx()) == (*aLCnt.GetCntntIdx()) )
+            const SwFmtCntnt &aCnt = rFmtHead.GetHeaderFmt()->GetCntnt();
+            if( !aCnt.GetCntntIdx() )
             {
-                SwFrmFmt *pFmt = new SwFrmFmt( GetAttrPool(), "Header",
-                                                GetDfltFrmFmt() );
-                ::lcl_DescSetAttr( *pRight, *pFmt, sal_False );
-                // The section which the right header attribute is pointing
-                // is copied, and the Index to the StartNode is set to
-                // the left header attribute.
-                SwNodeIndex aTmp( GetNodes().GetEndOfAutotext() );
-                SwStartNode* pSttNd = GetNodes().MakeEmptySection( aTmp, SwHeaderStartNode );
-                SwNodeRange aRange( aRCnt.GetCntntIdx()->GetNode(), 0,
-                            *aRCnt.GetCntntIdx()->GetNode().EndOfSectionNode() );
-                aTmp = *pSttNd->EndOfSectionNode();
-                GetNodes()._Copy( aRange, aTmp, sal_False );
-
-                pFmt->SetFmtAttr( SwFmtCntnt( pSttNd ) );
-                pDesc->GetLeft().SetFmtAttr( SwFmtHeader( pFmt ) );
+                const SwFrmFmt& rChgedFrmFmt = (bLeft ? rChged.GetLeft() : rChged.GetFirst());
+                rDescFrmFmt.SetFmtAttr( rChgedFrmFmt.GetHeader() );
             }
-            else
-                ::lcl_DescSetAttr( *pRight,
-                               *(SwFrmFmt*)rLeftHead.GetHeaderFmt(), sal_False );
-
-        }
-    }
-    if ( rChged.IsHeaderSharedFirst() || !rHead.IsActive() )
-    {
-        // First shares the header with the Master.
-        pDesc->GetFirst().SetFmtAttr( pDesc->GetMaster().GetHeader() );
-    }
-    else if ( rHead.IsActive() )
-    {   // First gets its own header if the Format doesn't alrady have one.
-        // If it already has one and it points to the same Section as the
-        // Right one, it needs to get an own Header.
-        // The content is evidently copied.
-        const SwFmtHeader &rFirstHead = pDesc->GetFirst().GetHeader();
-        if ( !rFirstHead.IsActive() )
-        {
-            SwFmtHeader aHead( MakeLayoutFmt( RND_STD_HEADERL, 0 ) );
-            pDesc->GetFirst().SetFmtAttr( aHead );
-            // take over additional attributes (margins, borders ...)
-            ::lcl_DescSetAttr( *rHead.GetHeaderFmt(), *aHead.GetHeaderFmt(), sal_False);
-        }
-        else
-        {
-            const SwFrmFmt *pRight = rHead.GetHeaderFmt();
-            const SwFmtCntnt &aRCnt = pRight->GetCntnt();
-            const SwFmtCntnt &aLCnt = rFirstHead.GetHeaderFmt()->GetCntnt();
-            if( !aLCnt.GetCntntIdx() )
-                pDesc->GetFirst().SetFmtAttr( rChged.GetFirst().GetHeader() );
-            else if( (*aRCnt.GetCntntIdx()) == (*aLCnt.GetCntntIdx()) )
+            else if( (*aRCnt.GetCntntIdx()) == (*aCnt.GetCntntIdx()) )
             {
                 SwFrmFmt *pFmt = new SwFrmFmt( GetAttrPool(), "Header",
                                                 GetDfltFrmFmt() );
                 ::lcl_DescSetAttr( *pRight, *pFmt, sal_False );
                 // The section which the right header attribute is pointing
                 // is copied, and the Index to the StartNode is set to
-                // the left header attribute.
+                // the left or first header attribute.
                 SwNodeIndex aTmp( GetNodes().GetEndOfAutotext() );
                 SwStartNode* pSttNd = GetNodes().MakeEmptySection( aTmp, SwHeaderStartNode );
                 SwNodeRange aRange( aRCnt.GetCntntIdx()->GetNode(), 0,
@@ -335,43 +231,32 @@ void SwDoc::ChgPageDesc( sal_uInt16 i, const SwPageDesc &rChged )
                 GetNodes()._Copy( aRange, aTmp, sal_False );
 
                 pFmt->SetFmtAttr( SwFmtCntnt( pSttNd ) );
-                pDesc->GetFirst().SetFmtAttr( SwFmtHeader( pFmt ) );
+                rDescFrmFmt.SetFmtAttr( SwFmtHeader( pFmt ) );
             }
             else
                 ::lcl_DescSetAttr( *pRight,
-                               *(SwFrmFmt*)rFirstHead.GetHeaderFmt(), sal_False );
+                               *(SwFrmFmt*)rFmtHead.GetHeaderFmt(), sal_False );
 
         }
     }
-    pDesc->ChgHeaderShare( rChged.IsHeaderShared() );
-    pDesc->ChgHeaderShareFirst( rChged.IsHeaderSharedFirst() );
+}
 
-    // Synch Footer.
-    const SwFmtFooter &rFoot = rChged.GetMaster().GetFooter();
-    if (undoGuard.UndoWasEnabled())
-    {
-        // #i46909# no undo if header or footer changed
-        // Did something change in the Nodes?
-        const SwFmtFooter &rOldFoot = pDesc->GetMaster().GetFooter();
-        bHeaderFooterChanged |=
-            ( rFoot.IsActive() != rOldFoot.IsActive() ||
-              rChged.IsFooterShared() != pDesc->IsFooterShared() ||
-              rChged.IsFooterSharedFirst() != pDesc->IsFooterSharedFirst() );
-    }
-    pDesc->GetMaster().SetFmtAttr( rFoot );
-    if ( rChged.IsFooterShared() || !rFoot.IsActive() )
-        // Left shares the Header with the Master.
-        pDesc->GetLeft().SetFmtAttr( pDesc->GetMaster().GetFooter() );
+void SwDoc::CopyMasterFooter(const SwPageDesc &rChged, const SwFmtFooter &rFoot, SwPageDesc *pDesc, bool bLeft)
+{
+    SwFrmFmt& rDescFrmFmt = (bLeft ? pDesc->GetLeft() : pDesc->GetFirst());
+    if ( (bLeft ? rChged.IsFooterShared() : rChged.IsFooterSharedFirst() ) || !rFoot.IsActive() )
+        // Left or first shares the Header with the Master.
+        rDescFrmFmt.SetFmtAttr( pDesc->GetMaster().GetFooter() );
     else if ( rFoot.IsActive() )
-    {   // Left gets its own Footer if the Format does not already have one.
+    {   // Left or first gets its own Footer if the Format does not already have one.
         // If the Format already has a Footer and it points to the same section as the Right one,
         // it needs to get an own one.
         // The content is evidently copied.
-        const SwFmtFooter &rLeftFoot = pDesc->GetLeft().GetFooter();
-        if ( !rLeftFoot.IsActive() )
+        const SwFmtFooter &rFmtFoot = rDescFrmFmt.GetFooter();
+        if ( !rFmtFoot.IsActive() )
         {
             SwFmtFooter aFoot( MakeLayoutFmt( RND_STD_FOOTER, 0 ) );
-            pDesc->GetLeft().SetFmtAttr( aFoot );
+            rDescFrmFmt.SetFmtAttr( aFoot );
             // Take over additional attributes (margins, borders ...).
             ::lcl_DescSetAttr( *rFoot.GetFooterFmt(), *aFoot.GetFooterFmt(), sal_False);
         }
@@ -379,9 +264,12 @@ void SwDoc::ChgPageDesc( sal_uInt16 i, const SwPageDesc &rChged )
         {
             const SwFrmFmt *pRight = rFoot.GetFooterFmt();
             const SwFmtCntnt &aRCnt = pRight->GetCntnt();
-            const SwFmtCntnt &aLCnt = rLeftFoot.GetFooterFmt()->GetCntnt();
+            const SwFmtCntnt &aLCnt = rFmtFoot.GetFooterFmt()->GetCntnt();
             if( !aLCnt.GetCntntIdx() )
-                pDesc->GetLeft().SetFmtAttr( rChged.GetLeft().GetFooter() );
+            {
+                const SwFrmFmt& rChgedFrmFmt = (bLeft ? rChged.GetLeft() : rChged.GetFirst());
+                rDescFrmFmt.SetFmtAttr( rChgedFrmFmt.GetFooter() );
+            }
             else if( (*aRCnt.GetCntntIdx()) == (*aLCnt.GetCntntIdx()) )
             {
                 SwFrmFmt *pFmt = new SwFrmFmt( GetAttrPool(), "Footer",
@@ -398,59 +286,95 @@ void SwDoc::ChgPageDesc( sal_uInt16 i, const SwPageDesc &rChged )
                 GetNodes()._Copy( aRange, aTmp, sal_False );
 
                 pFmt->SetFmtAttr( SwFmtCntnt( pSttNd ) );
-                pDesc->GetLeft().SetFmtAttr( SwFmtFooter( pFmt ) );
+                rDescFrmFmt.SetFmtAttr( SwFmtFooter( pFmt ) );
             }
             else
                 ::lcl_DescSetAttr( *pRight,
-                               *(SwFrmFmt*)rLeftFoot.GetFooterFmt(), sal_False );
+                               *(SwFrmFmt*)rFmtFoot.GetFooterFmt(), sal_False );
         }
     }
-    if ( rChged.IsFooterSharedFirst() || !rFoot.IsActive() )
-        // First shares the Header with the Master.
-        pDesc->GetFirst().SetFmtAttr( pDesc->GetMaster().GetFooter() );
-    else if ( rFoot.IsActive() )
-    {   // First gets its own Footer if the Format does not already have one.
-        // If the Format already has a Footer and it points to the same section as the Right one,
-        // it needs to get an own one.
-        // The content is evidently copied.
-        const SwFmtFooter &rFirstFoot = pDesc->GetFirst().GetFooter();
-        if ( !rFirstFoot.IsActive() )
+}
+
+void SwDoc::ChgPageDesc( sal_uInt16 i, const SwPageDesc &rChged )
+{
+    OSL_ENSURE( i < aPageDescs.size(), "PageDescs is out of range." );
+
+    SwPageDesc *pDesc = aPageDescs[i];
+    SwRootFrm* pTmpRoot = GetCurrentLayout();
+
+    if (GetIDocumentUndoRedo().DoesUndo())
+    {
+        SwUndo *const pUndo(new SwUndoPageDesc(*pDesc, rChged, this));
+        GetIDocumentUndoRedo().AppendUndo(pUndo);
+    }
+    ::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo());
+
+    // Mirror at first if needed.
+    if ( rChged.GetUseOn() == nsUseOnPage::PD_MIRROR )
+        ((SwPageDesc&)rChged).Mirror();
+    else
+        // Or else transfer values from Master to Left.
+        ::lcl_DescSetAttr( ((SwPageDesc&)rChged).GetMaster(),
+                       ((SwPageDesc&)rChged).GetLeft() );
+
+    // Take over NumType.
+    if( rChged.GetNumType().GetNumberingType() != pDesc->GetNumType().GetNumberingType() )
+    {
+        pDesc->SetNumType( rChged.GetNumType() );
+        // Notify page number fields that NumFormat has changed
+        GetSysFldType( RES_PAGENUMBERFLD )->UpdateFlds();
+        GetSysFldType( RES_REFPAGEGETFLD )->UpdateFlds();
+
+        // If the numbering scheme has changed we could have QuoVadis/ErgoSum texts
+        // that refer to a changed page, so we invalidate foot notes.
+        SwFtnIdxs& rFtnIdxs = GetFtnIdxs();
+        for( sal_uInt16 nPos = 0; nPos < rFtnIdxs.Count(); ++nPos )
         {
-            SwFmtFooter aFoot( MakeLayoutFmt( RND_STD_FOOTER, 0 ) );
-            pDesc->GetFirst().SetFmtAttr( aFoot );
-            // Take over additional attributes (margins, borders ...).
-            ::lcl_DescSetAttr( *rFoot.GetFooterFmt(), *aFoot.GetFooterFmt(), sal_False);
+            SwTxtFtn *pTxtFtn = rFtnIdxs[ nPos ];
+            const SwFmtFtn &rFtn = pTxtFtn->GetFtn();
+            pTxtFtn->SetNumber( rFtn.GetNumber(), &rFtn.GetNumStr());
         }
-        else
-        {
-            const SwFrmFmt *pRight = rFoot.GetFooterFmt();
-            const SwFmtCntnt &aRCnt = pRight->GetCntnt();
-            const SwFmtCntnt &aLCnt = rFirstFoot.GetFooterFmt()->GetCntnt();
-            if( !aLCnt.GetCntntIdx() )
-                pDesc->GetFirst().SetFmtAttr( rChged.GetFirst().GetFooter() );
-            else if( (*aRCnt.GetCntntIdx()) == (*aLCnt.GetCntntIdx()) )
-            {
-                SwFrmFmt *pFmt = new SwFrmFmt( GetAttrPool(), "Footer",
-                                                GetDfltFrmFmt() );
-                ::lcl_DescSetAttr( *pRight, *pFmt, sal_False );
-                // The section to which the right footer attribute is pointing
-                // is copied, and the Index to the StartNode is set to
-                // the first footer attribute.
-                SwNodeIndex aTmp( GetNodes().GetEndOfAutotext() );
-                SwStartNode* pSttNd = GetNodes().MakeEmptySection( aTmp, SwFooterStartNode );
-                SwNodeRange aRange( aRCnt.GetCntntIdx()->GetNode(), 0,
-                            *aRCnt.GetCntntIdx()->GetNode().EndOfSectionNode() );
-                aTmp = *pSttNd->EndOfSectionNode();
-                GetNodes()._Copy( aRange, aTmp, sal_False );
+    }
 
-                pFmt->SetFmtAttr( SwFmtCntnt( pSttNd ) );
-                pDesc->GetFirst().SetFmtAttr( SwFmtFooter( pFmt ) );
-            }
-            else
-                ::lcl_DescSetAttr( *pRight,
-                               *(SwFrmFmt*)rFirstFoot.GetFooterFmt(), sal_False );
-        }
+    // Take over orientation
+    pDesc->SetLandscape( rChged.GetLandscape() );
+
+    // #i46909# no undo if header or footer changed
+    bool bHeaderFooterChanged = false;
+
+    // Synch header.
+    const SwFmtHeader &rHead = rChged.GetMaster().GetHeader();
+    if (undoGuard.UndoWasEnabled())
+    {
+        // #i46909# no undo if header or footer changed
+        // Did something change in the nodes?
+        const SwFmtHeader &rOldHead = pDesc->GetMaster().GetHeader();
+        bHeaderFooterChanged |=
+            ( rHead.IsActive() != rOldHead.IsActive() ||
+              rChged.IsHeaderShared() != pDesc->IsHeaderShared() ||
+              rChged.IsHeaderSharedFirst() != pDesc->IsHeaderSharedFirst() );
     }
+    pDesc->GetMaster().SetFmtAttr( rHead );
+    CopyMasterHeader(rChged, rHead, pDesc, true); // Copy left header
+    CopyMasterHeader(rChged, rHead, pDesc, false); // Copy first header
+    pDesc->ChgHeaderShare( rChged.IsHeaderShared() );
+    pDesc->ChgHeaderShareFirst( rChged.IsHeaderSharedFirst() );
+
+    // Synch Footer.
+    const SwFmtFooter &rFoot = rChged.GetMaster().GetFooter();
+    if (undoGuard.UndoWasEnabled())
+    {
+        // #i46909# no undo if header or footer changed
+        // Did something change in the Nodes?
+        const SwFmtFooter &rOldFoot = pDesc->GetMaster().GetFooter();
+        bHeaderFooterChanged |=
+            ( rFoot.IsActive() != rOldFoot.IsActive() ||
+              rChged.IsFooterShared() != pDesc->IsFooterShared() ||
+              rChged.IsFooterSharedFirst() != pDesc->IsFooterSharedFirst() );
+    }
+    pDesc->GetMaster().SetFmtAttr( rFoot );
+    CopyMasterFooter(rChged, rFoot, pDesc, true); // Copy left footer
+    CopyMasterFooter(rChged, rFoot, pDesc, false); // Copy first footer
     pDesc->ChgFooterShare( rChged.IsFooterShared() );
     pDesc->ChgFooterShareFirst( rChged.IsFooterSharedFirst() );
 


More information about the Libreoffice-commits mailing list