diff options
-rw-r--r-- | sw/inc/doc.hxx | 4 | ||||
-rw-r--r-- | sw/source/core/crsr/crstrvl.cxx | 22 | ||||
-rw-r--r-- | sw/source/core/doc/docdesc.cxx | 70 | ||||
-rw-r--r-- | sw/source/core/doc/docfmt.cxx | 7 | ||||
-rw-r--r-- | sw/source/core/frmedt/fedesc.cxx | 17 | ||||
-rw-r--r-- | sw/source/core/layout/pagedesc.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/unocore/unosett.cxx | 12 | ||||
-rw-r--r-- | sw/source/core/unocore/unostyle.cxx | 14 | ||||
-rw-r--r-- | sw/source/filter/html/htmlcss1.cxx | 15 |
9 files changed, 84 insertions, 79 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index b9b55515ccd5..d0b3fbc5ac2e 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -948,6 +948,9 @@ public: const SwPageDesc& GetPageDesc( const sal_uInt16 i ) const { return maPageDescs[i]; } SwPageDesc& GetPageDesc( sal_uInt16 i ) { return maPageDescs[i]; } SwPageDesc* FindPageDesc(const OUString& rName, sal_uInt16* pPos = NULL); + SwPageDesc* FindPageDesc(const OUString& rName, sal_uInt16* pPos = NULL) const; + // Just searches the pointer in the maPageDescs vector! + bool ContainsPageDesc(const SwPageDesc *pDesc, sal_uInt16* pPos = NULL); /** Copy the complete PageDesc - beyond document and "deep"! Optionally copying of PoolFmtId, -HlpId can be prevented. */ @@ -965,7 +968,6 @@ public: { CopyPageDescHeaderFooterImpl( false, rSrcFmt, rDestFmt ); } // For Reader - SwPageDesc * GetPageDesc( const OUString & rName ); void ChgPageDesc( const OUString & rName, const SwPageDesc& ); void ChgPageDesc( sal_uInt16 i, const SwPageDesc& ); void DelPageDesc( const OUString & rName, bool bBroadcast = false); diff --git a/sw/source/core/crsr/crstrvl.cxx b/sw/source/core/crsr/crstrvl.cxx index 9993b5037d37..e11fdd2e9e6b 100644 --- a/sw/source/core/crsr/crstrvl.cxx +++ b/sw/source/core/crsr/crstrvl.cxx @@ -190,6 +190,7 @@ bool SwCrsrShell::SetCrsrInHdFt( sal_uInt16 nDescNo, bool bInHeader ) { bool bRet = false; SwDoc *pMyDoc = GetDoc(); + const SwPageDesc* pDesc = NULL; SET_CURR_SHELL( this ); @@ -197,31 +198,28 @@ bool SwCrsrShell::SetCrsrInHdFt( sal_uInt16 nDescNo, bool bInHeader ) { // take the current one const SwPageFrm* pPage = GetCurrFrm()->FindPageFrm(); - if( pPage ) - for( sal_uInt16 i = 0; i < pMyDoc->GetPageDescCnt(); ++i ) - if( pPage->GetPageDesc() == &pMyDoc->GetPageDesc( i ) ) - { - nDescNo = i; - break; - } + if( pPage && pMyDoc->ContainsPageDesc( + pPage->GetPageDesc(), &nDescNo) ) + pDesc = pPage->GetPageDesc(); } + else + if (nDescNo < pMyDoc->GetPageDescCnt()) + pDesc = &pMyDoc->GetPageDesc( nDescNo ); - if( USHRT_MAX != nDescNo && nDescNo < pMyDoc->GetPageDescCnt() ) + if( pDesc ) { // check if the attribute exists - const SwPageDesc& rDesc = const_cast<const SwDoc *>(pMyDoc) - ->GetPageDesc( nDescNo ); const SwFmtCntnt* pCnt = 0; if( bInHeader ) { // mirrored pages? ignore for now - const SwFmtHeader& rHd = rDesc.GetMaster().GetHeader(); + const SwFmtHeader& rHd = pDesc->GetMaster().GetHeader(); if( rHd.GetHeaderFmt() ) pCnt = &rHd.GetHeaderFmt()->GetCntnt(); } else { - const SwFmtFooter& rFt = rDesc.GetMaster().GetFooter(); + const SwFmtFooter& rFt = pDesc->GetMaster().GetFooter(); if( rFt.GetFooterFmt() ) pCnt = &rFt.GetFooterFmt()->GetCntnt(); } diff --git a/sw/source/core/doc/docdesc.cxx b/sw/source/core/doc/docdesc.cxx index c489c627869e..0c29eb4f9071 100644 --- a/sw/source/core/doc/docdesc.cxx +++ b/sw/source/core/doc/docdesc.cxx @@ -684,24 +684,6 @@ SwPageDesc* SwDoc::MakePageDesc(const OUString &rName, const SwPageDesc *pCpy, return pNew; } -SwPageDesc* SwDoc::FindPageDesc(const OUString& rName, sal_uInt16* pPos) -{ - SwPageDesc* pRet = NULL; - if( pPos ) *pPos = USHRT_MAX; - - for( SwPageDescs::size_type n = 0, nEnd = maPageDescs.size(); n < nEnd; ++n ) - { - if( maPageDescs[ n ].HasName( rName ) ) - { - pRet = &maPageDescs[ n ]; - if( pPos ) - *pPos = n; - break; - } - } - return pRet; -} - // We collect the GlobalNames of the servers at runtime, who don't want to be notified // about printer changes. Thereby saving loading a lot of objects (luckily all foreign // objects are mapped to one ID). @@ -830,9 +812,57 @@ IMPL_LINK( SwDoc, DoUpdateModifiedOLE, Timer *, ) return 0; } -SwPageDesc * SwDoc::GetPageDesc( const OUString & rName ) +struct CompareSwPageDescName { + CompareSwPageDescName(const OUString &rName) : mName(rName) {} + bool operator () (const SwPageDesc& other) const { return other.GetName() == mName; } + const OUString &mName; +}; + +template <class UnaryPredicate> +static SwPageDesc* lcl_FindPageDesc( SwPageDescs *pPageDescs, + sal_uInt16 *pPos, UnaryPredicate pred ) +{ + SwPageDescs::iterator it = std::find_if( + pPageDescs->begin(), pPageDescs->end(), pred); + SwPageDesc* res = NULL; + if( it != pPageDescs->end() ) + { + res = const_cast <SwPageDesc *>( &( *it ) );; + if( pPos ) + *pPos = std::distance( pPageDescs->begin(), it ); + } + else if( pPos ) + *pPos = USHRT_MAX; + return res; +} + +SwPageDesc* SwDoc::FindPageDesc( const OUString & rName, sal_uInt16* pPos ) +{ + return lcl_FindPageDesc<CompareSwPageDescName>( + &maPageDescs, pPos, CompareSwPageDescName(rName) ); +} + +SwPageDesc* SwDoc::FindPageDesc( const OUString & rName, sal_uInt16* pPos ) const +{ + return lcl_FindPageDesc<CompareSwPageDescName>( + const_cast <SwPageDescs *>( &maPageDescs ), pPos, + CompareSwPageDescName(rName) ); +} + +struct CompareSwPageDescToPtr { + CompareSwPageDescToPtr(const SwPageDesc* ptr) : mPtr(ptr) {} + bool operator () (const SwPageDesc& other) const { return &other == mPtr; } + const SwPageDesc *mPtr; +}; + +bool SwDoc::ContainsPageDesc( const SwPageDesc *pDesc, sal_uInt16* pPos ) { - return FindPageDesc(rName); + if (pDesc == NULL) + return false; + SwPageDesc *res = lcl_FindPageDesc<CompareSwPageDescToPtr>( + const_cast <SwPageDescs *>( &maPageDescs ), pPos, + CompareSwPageDescToPtr(pDesc) ); + return res != NULL; } void SwDoc::DelPageDesc( const OUString & rName, bool bBroadcast ) diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx index 0d319011a49b..cfa65b85ed9f 100644 --- a/sw/source/core/doc/docfmt.cxx +++ b/sw/source/core/doc/docfmt.cxx @@ -1419,12 +1419,13 @@ void SwDoc::CopyPageDesc( const SwPageDesc& rSrcDesc, SwPageDesc& rDstDesc, if( rSrcDesc.GetFollow() != &rSrcDesc ) { - SwPageDesc* pFollow = FindPageDesc( rSrcDesc.GetFollow()->GetName() ); + const SwPageDesc* pSrcFollow = rSrcDesc.GetFollow(); + SwPageDesc* pFollow = FindPageDesc( pSrcFollow->GetName() ); if( !pFollow ) { // copy - pFollow = MakePageDesc(rSrcDesc.GetFollow()->GetName()); - CopyPageDesc( *rSrcDesc.GetFollow(), *pFollow ); + pFollow = MakePageDesc( pSrcFollow->GetName() ); + CopyPageDesc( *pSrcFollow, *pFollow ); } rDstDesc.SetFollow( pFollow ); bNotifyLayout = true; diff --git a/sw/source/core/frmedt/fedesc.cxx b/sw/source/core/frmedt/fedesc.cxx index 9db4fee77545..67f786d461cd 100644 --- a/sw/source/core/frmedt/fedesc.cxx +++ b/sw/source/core/frmedt/fedesc.cxx @@ -150,11 +150,9 @@ sal_uInt16 SwFEShell::GetMousePageDesc( const Point &rPt ) const while( pPage->GetNext() && rPt.Y() > pPage->Frm().Bottom() ) pPage = static_cast<const SwPageFrm*>( pPage->GetNext() ); SwDoc *pMyDoc = GetDoc(); - for ( sal_uInt16 i = 0; i < GetDoc()->GetPageDescCnt(); ++i ) - { - if ( pPage->GetPageDesc() == &pMyDoc->GetPageDesc(i) ) - return i; - } + sal_uInt16 nPos; + if (pMyDoc->ContainsPageDesc( pPage->GetPageDesc(), &nPos ) ) + return nPos; } } return 0; @@ -168,12 +166,9 @@ sal_uInt16 SwFEShell::GetCurPageDesc( const bool bCalcFrm ) const const SwPageFrm *pPage = pFrm->FindPageFrm(); if ( pPage ) { - SwDoc *pMyDoc = GetDoc(); - for ( sal_uInt16 i = 0; i < GetDoc()->GetPageDescCnt(); ++i ) - { - if ( pPage->GetPageDesc() == &pMyDoc->GetPageDesc(i) ) - return i; - } + sal_uInt16 nPos; + if (GetDoc()->ContainsPageDesc( pPage->GetPageDesc(), &nPos )) + return nPos; } } return 0; diff --git a/sw/source/core/layout/pagedesc.cxx b/sw/source/core/layout/pagedesc.cxx index 6b79713df44e..0d05037df14c 100644 --- a/sw/source/core/layout/pagedesc.cxx +++ b/sw/source/core/layout/pagedesc.cxx @@ -452,7 +452,7 @@ SwPageDescExt::operator SwPageDesc() const { SwPageDesc aResult(aPageDesc); - SwPageDesc * pPageDesc = pDoc->GetPageDesc(sFollow); + SwPageDesc * pPageDesc = pDoc->FindPageDesc(sFollow); if ( 0 != pPageDesc ) aResult.SetFollow(pPageDesc); diff --git a/sw/source/core/unocore/unosett.cxx b/sw/source/core/unocore/unosett.cxx index 1a17f3d579b7..a565dceb9266 100644 --- a/sw/source/core/unocore/unosett.cxx +++ b/sw/source/core/unocore/unosett.cxx @@ -227,21 +227,11 @@ static SwTxtFmtColl* lcl_GetParaStyle(SwDoc* pDoc, const uno::Any& aValue) static SwPageDesc* lcl_GetPageDesc(SwDoc* pDoc, const uno::Any& aValue) { - SwPageDesc* pRet = 0; - const sal_uInt16 nCount = pDoc->GetPageDescCnt(); OUString uTmp; aValue >>= uTmp; OUString sPageDesc; SwStyleNameMapper::FillUIName(uTmp, sPageDesc, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, true ); - for( sal_uInt16 i = 0; i < nCount; i++) - { - const SwPageDesc& rDesc = pDoc->GetPageDesc( i ); - if(rDesc.GetName() == sPageDesc) - { - pRet = (SwPageDesc*)&rDesc; - break; - } - } + SwPageDesc* pRet = pDoc->FindPageDesc( sPageDesc ); if(!pRet) { const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(sPageDesc, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC); diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index e101eb953f42..886c37158277 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1626,16 +1626,10 @@ const SwPageDesc& SwStyleBase_Impl::GetOldPageDesc() { if(!mpOldPageDesc) { - const sal_uInt16 nPDescCount = mrDoc.GetPageDescCnt(); - for(sal_uInt16 i = 0; i < nPDescCount; ++i) - { - const SwPageDesc& rDesc = mrDoc.GetPageDesc( i ); - if(rDesc.GetName() == mrStyleName) - { - mpOldPageDesc = & rDesc; - break; - } - } + SwPageDesc *pd = mrDoc.FindPageDesc( mrStyleName ); + if( pd ) + mpOldPageDesc = pd; + if(!mpOldPageDesc) { for(sal_uInt16 i = RC_POOLPAGEDESC_BEGIN; i <= STR_POOLPAGE_LANDSCAPE; ++i) diff --git a/sw/source/filter/html/htmlcss1.cxx b/sw/source/filter/html/htmlcss1.cxx index 12544015625f..f026033d4fe9 100644 --- a/sw/source/filter/html/htmlcss1.cxx +++ b/sw/source/filter/html/htmlcss1.cxx @@ -89,16 +89,11 @@ static struct SwCSS1ItemIds void SwCSS1Parser::ChgPageDesc( const SwPageDesc *pPageDesc, const SwPageDesc& rNewPageDesc ) { - sal_uInt16 nPageDescs = pDoc->GetPageDescCnt(); - sal_uInt16 i; - for( i=0; i<nPageDescs; i++ ) - if( pPageDesc == &pDoc->GetPageDesc(i) ) - { - pDoc->ChgPageDesc( i, rNewPageDesc ); - return; - } - - OSL_ENSURE( i<nPageDescs, "Seitenvorlage nicht gefunden" ); + sal_uInt16 pos; + bool found = pDoc->ContainsPageDesc( pPageDesc, &pos ); + OSL_ENSURE( found, "Seitenvorlage nicht gefunden" ); + if (found) + pDoc->ChgPageDesc( pos, rNewPageDesc ); } SwCSS1Parser::SwCSS1Parser( SwDoc *pD, sal_uInt32 aFHeights[7], const OUString& rBaseURL, bool bNewDoc ) : |