diff options
author | Maxime de Roucy <mderoucy@linagora.com> | 2012-03-14 12:22:30 +0100 |
---|---|---|
committer | Cédric Bosdonnat <cedric.bosdonnat.ooo@free.fr> | 2012-03-28 12:07:51 +0200 |
commit | 16094573256e4c4ece92f86f63559658a25e8d61 (patch) | |
tree | c32fd8a6fe8fd34dd4a405d3a44e954cf6c69e7b | |
parent | 5aa523a61f812a44d6cab926df501d6672e4aeda (diff) |
add GetCurParAttr and GetPaMParAttr in SwEditShell
GetCurParAttr : Get the paragraph format attribute(s) of the current selection.
GetPaMParAttr : Get the paragraph format attribute(s) of the selection(s) described by a SwPaM.
The advantage of these methods is that the take the named and automatic
format attributes.
-rw-r--r-- | sw/inc/editsh.hxx | 28 | ||||
-rw-r--r-- | sw/source/core/edit/edattr.cxx | 57 |
2 files changed, 85 insertions, 0 deletions
diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx index a160b6ef909c..fac6e05972ff 100644 --- a/sw/inc/editsh.hxx +++ b/sw/inc/editsh.hxx @@ -253,6 +253,34 @@ public: void SetAttr( const SfxPoolItem&, sal_uInt16 nFlags = 0 ); void SetAttr( const SfxItemSet&, sal_uInt16 nFlags = 0, SwPaM* pCrsr = NULL ); + /** + * Get the paragraph format attribute(s) of the current selection. + * + * @see GetPaMParAttr() + * + * @param rSet + * output parameter - the SfxItemSet where the automatic paragraph format attribut(s) will be store. + * The attributes aren't invalidated or cleared if the function reach the getMaxLookup limite. + * + * @return true if the function inspect all the nodes point by the pPaM parameter, + * false if the function reach the limit of getMaxLookup number of nodes inspected. + */ + sal_Bool GetCurParAttr( SfxItemSet& rSet ) const; + /** + * Get the paragraph format attribute(s) of the selection(s) described by a SwPaM. + * + * @param pPaM + * input parameter - the selection where to look for the paragraph format. + * + * @param rSet + * output parameter - the SfxItemSet where the automatic paragraph format attribute(s) will be store. + * The attributes aren't invalidated or cleared if the function reaches the getMaxLookup limit. + * + * @return true if the function inspects all the nodes point by the pPaM parameter, + * false if the function reaches the limit of getMaxLookup number of nodes inspected. + */ + sal_Bool GetPaMParAttr( SwPaM* pPaM, SfxItemSet& rSet ) const; + // Set attribute as new default attribute in document. void SetDefault( const SfxPoolItem& ); diff --git a/sw/source/core/edit/edattr.cxx b/sw/source/core/edit/edattr.cxx index b189c992e879..f42e3abe182c 100644 --- a/sw/source/core/edit/edattr.cxx +++ b/sw/source/core/edit/edattr.cxx @@ -176,6 +176,63 @@ sal_Bool SwEditShell::GetCurAttr( SfxItemSet& rSet, return GetPaMAttr( GetCrsr(), rSet, bMergeIndentValuesOfNumRule ); } +sal_Bool SwEditShell::GetCurParAttr( SfxItemSet& rSet) const +{ + return GetPaMParAttr( GetCrsr(), rSet ); +} + +sal_Bool SwEditShell::GetPaMParAttr( SwPaM* pPaM, SfxItemSet& rSet ) const +{ + // number of nodes the function has explored so far + sal_uInt16 numberOfLookup = 0; + + SfxItemSet aSet( *rSet.GetPool(), rSet.GetRanges() ); + SfxItemSet* pSet = &rSet; + + SwPaM* pStartPaM = pPaM; + do { // for all the point and mark (selections) + + // get the start and the end node of the current selection + sal_uLong nSttNd = pPaM->GetMark()->nNode.GetIndex(), + nEndNd = pPaM->GetPoint()->nNode.GetIndex(); + + // reverse start and end if there number aren't sorted correctly + if( nSttNd > nEndNd ) + std::swap(nSttNd, nEndNd); + + // for all the nodes in the current selection + // get the node (paragraph) attributes + // and merge them in rSet + for( sal_uLong n = nSttNd; n <= nEndNd; ++n ) + { + // get the node + SwNode* pNd = GetDoc()->GetNodes()[ n ]; + + if( pNd->IsTxtNode() ) + { + // get the node (paragraph) attributes + static_cast<SwCntntNode*>(pNd)->GetAttr(*pSet); + + if( pSet != &rSet && aSet.Count() ) + { + rSet.MergeValues( aSet ); + aSet.ClearItem(); + } + + pSet = &aSet; + } + + ++numberOfLookup; + + // if the maximum number of node that can be inspected has been reached + if (numberOfLookup >= getMaxLookup()) + return sal_False; + } + } while ( ( pPaM = static_cast<SwPaM*>(pPaM->GetNext()) ) != pStartPaM ); + + return sal_True; +} + SwTxtFmtColl* SwEditShell::GetCurTxtFmtColl( ) const { return GetPaMTxtFmtColl( GetCrsr() ); |