summaryrefslogtreecommitdiff
path: root/svx/source/editeng
diff options
context:
space:
mode:
authorMalte Timmermann <mt@openoffice.org>2001-11-12 12:06:40 +0000
committerMalte Timmermann <mt@openoffice.org>2001-11-12 12:06:40 +0000
commit57ccf3dbed3874f61a3e407ed8f6445484d8eefa (patch)
treefa6216e61790a6d521bc8f73795683898447c48e /svx/source/editeng
parentf9bcd321f0144a71010cab24dab8b11580ee1126 (diff)
#94002# Optimized GetAttribs()
Diffstat (limited to 'svx/source/editeng')
-rw-r--r--svx/source/editeng/editdoc.cxx32
-rw-r--r--svx/source/editeng/editdoc.hxx5
-rw-r--r--svx/source/editeng/editeng.cxx11
-rw-r--r--svx/source/editeng/impedit5.cxx103
4 files changed, 143 insertions, 8 deletions
diff --git a/svx/source/editeng/editdoc.cxx b/svx/source/editeng/editdoc.cxx
index bb8f131cf940..ac191274c211 100644
--- a/svx/source/editeng/editdoc.cxx
+++ b/svx/source/editeng/editdoc.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: editdoc.cxx,v $
*
- * $Revision: 1.20 $
+ * $Revision: 1.21 $
*
- * last change: $Author: mt $ $Date: 2001-10-11 11:46:59 $
+ * last change: $Author: mt $ $Date: 2001-11-12 13:06:40 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -1894,6 +1894,7 @@ void EditDoc::FindAttribs( ContentNode* pNode, USHORT nStartPos, USHORT nEndPos,
}
}
+
// -------------------------------------------------------------------------
// class EditCharAttribList
// -------------------------------------------------------------------------
@@ -1961,6 +1962,33 @@ void CharAttribList::ResortAttribs()
}
}
+void CharAttribList::OptimizeRanges( SfxItemPool& rItemPool )
+{
+ for ( USHORT n = 0; n < aAttribs.Count(); n++ )
+ {
+ EditCharAttrib* pAttr = aAttribs.GetObject( n );
+ for ( USHORT nNext = n+1; nNext < aAttribs.Count(); nNext++ )
+ {
+ EditCharAttrib* p = aAttribs.GetObject( nNext );
+ if ( ( p->GetStart() == pAttr->GetEnd() ) && ( p->Which() == pAttr->Which() ) )
+ {
+ if ( *p->GetItem() == *pAttr->GetItem() )
+ {
+ pAttr->GetEnd() = p->GetEnd();
+ aAttribs.Remove( nNext );
+ rItemPool.Remove( *p->GetItem() );
+ delete p;
+ }
+ break; // only 1 attr with same which can start here.
+ }
+ else if ( p->GetStart() > pAttr->GetEnd() )
+ {
+ break;
+ }
+ }
+ }
+}
+
EditCharAttrib* CharAttribList::FindAttrib( USHORT nWhich, USHORT nPos )
{
// Rueckwaerts, falls eins dort endet, das naechste startet.
diff --git a/svx/source/editeng/editdoc.hxx b/svx/source/editeng/editdoc.hxx
index 68a7a6b4073d..2819c6be28d6 100644
--- a/svx/source/editeng/editdoc.hxx
+++ b/svx/source/editeng/editdoc.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: editdoc.hxx,v $
*
- * $Revision: 1.12 $
+ * $Revision: 1.13 $
*
- * last change: $Author: mt $ $Date: 2001-10-17 15:31:38 $
+ * last change: $Author: mt $ $Date: 2001-11-12 13:06:40 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -247,6 +247,7 @@ public:
void ResortAttribs();
+ void OptimizeRanges( SfxItemPool& rItemPool );
USHORT Count() { return aAttribs.Count(); }
void Clear() { aAttribs.Remove( 0, aAttribs.Count()); }
diff --git a/svx/source/editeng/editeng.cxx b/svx/source/editeng/editeng.cxx
index db1d118fefc2..3ce3894732ef 100644
--- a/svx/source/editeng/editeng.cxx
+++ b/svx/source/editeng/editeng.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: editeng.cxx,v $
*
- * $Revision: 1.47 $
+ * $Revision: 1.48 $
*
- * last change: $Author: hr $ $Date: 2001-10-16 18:57:58 $
+ * last change: $Author: mt $ $Date: 2001-11-12 13:06:40 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -1364,6 +1364,13 @@ SfxItemSet EditEngine::GetAttribs( const ESelection& rSel, BOOL bOnlyHardAttrib
return pImpEditEngine->GetAttribs( aSel, bOnlyHardAttrib );
}
+SfxItemSet EditEngine::GetAttribs( USHORT nPara, USHORT nStart, USHORT nEnd, sal_uInt8 nFlags ) const
+{
+ DBG_CHKTHIS( EditEngine, 0 );
+ return pImpEditEngine->GetAttribs( nPara, nStart, nEnd, nFlags );
+}
+
+
Font EditEngine::GetStandardFont( sal_uInt16 nPara )
{
DBG_CHKTHIS( EditEngine, 0 );
diff --git a/svx/source/editeng/impedit5.cxx b/svx/source/editeng/impedit5.cxx
index 3e976205af9c..7de704d93805 100644
--- a/svx/source/editeng/impedit5.cxx
+++ b/svx/source/editeng/impedit5.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: impedit5.cxx,v $
*
- * $Revision: 1.16 $
+ * $Revision: 1.17 $
*
- * last change: $Author: cl $ $Date: 2001-08-28 13:06:33 $
+ * last change: $Author: mt $ $Date: 2001-11-12 13:06:40 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -400,6 +400,12 @@ SfxItemSet ImpEditEngine::GetAttribs( EditSelection aSel, BOOL bOnlyHardAttrib )
aSel.Adjust( aEditDoc );
+#ifdef DEBUG
+// if ( ( aSel.Min().GetNode() == aSel.Max().GetNode() ) && ( bOnlyHardAttrib == EditEngineAttribs_All ) )
+// return GetAttribs( aEditDoc.GetPos( aSel.Min().GetNode() ), aSel.Min().GetIndex(), aSel.Max().GetIndex(), GETATTRIBS_ALL );
+#endif
+
+
SfxItemSet aCurSet( GetEmptyItemSet() );
USHORT nStartNode = aEditDoc.GetPos( aSel.Min().GetNode() );
@@ -507,6 +513,99 @@ SfxItemSet ImpEditEngine::GetAttribs( EditSelection aSel, BOOL bOnlyHardAttrib )
return aCurSet;
}
+
+SfxItemSet ImpEditEngine::GetAttribs( USHORT nPara, USHORT nStart, USHORT nEnd, sal_uInt8 nFlags ) const
+{
+ // MT: #94002# Optimized function with less Puts(), which cause unnecessary cloning from default items.
+ // If this works, change GetAttribs( EditSelection ) to use this for each paragraph and merge the results!
+
+ DBG_CHKOBJ( GetEditEnginePtr(), EditEngine, 0 );
+
+ ContentNode* pNode = aEditDoc.SaveGetObject( nPara );
+ DBG_ASSERT( pNode, "GetAttribs - unknown paragraph!" );
+
+ SfxItemSet aAttribs( ((ImpEditEngine*)this)->GetEmptyItemSet() );
+
+ if ( pNode )
+ {
+ if ( nEnd > pNode->Len() )
+ nEnd = pNode->Len();
+
+ DBG_ASSERT( nStart <= nEnd, "getAttribs: Start > End not supported!" );
+
+ if ( nStart > nEnd )
+ nStart = nEnd;
+
+ // StyleSheet / Parattribs...
+
+ if ( pNode->GetStyleSheet() && ( nFlags & GETATTRIBS_STYLESHEET ) )
+ aAttribs.Set( pNode->GetStyleSheet()->GetItemSet(), TRUE );
+
+ if ( nFlags & GETATTRIBS_PARAATTRIBS )
+ aAttribs.Put( pNode->GetContentAttribs().GetItems() );
+
+ // CharAttribs...
+
+ if ( nFlags & GETATTRIBS_PARAATTRIBS )
+ {
+ // Make testing easier...
+ pNode->GetCharAttribs().OptimizeRanges( ((ImpEditEngine*)this)->GetEditDoc().GetItemPool() );
+
+ const CharAttribArray& rAttrs = pNode->GetCharAttribs().GetAttribs();
+ for ( USHORT nAttr = 0; nAttr < rAttrs.Count(); nAttr++ )
+ {
+ EditCharAttrib* pAttr = rAttrs.GetObject( nAttr );
+
+ if ( nStart == nEnd )
+ {
+ USHORT nCursorPos = nStart;
+ if ( ( pAttr->GetStart() <= nCursorPos ) && ( pAttr->GetEnd() >= nCursorPos ) )
+ {
+ // To be used the attribute has to start BEFORE the position, or it must be a
+ // new empty attr AT the position, or we are on position 0.
+ if ( ( pAttr->GetStart() < nCursorPos ) || pAttr->IsEmpty() || !nCursorPos )
+ {
+ // maybe this attrib ends here and a new attrib with 0 Len may follow and be valid here,
+ // but that s no problem, the empty item will come later and win.
+ aAttribs.Put( *pAttr->GetItem() );
+ }
+ }
+ }
+ else
+ {
+ // Check every attribute covering the area, partial or full.
+ if ( ( pAttr->GetStart() < nEnd ) && ( pAttr->GetEnd() > nStart ) )
+ {
+ if ( ( pAttr->GetStart() <= nStart ) && ( pAttr->GetEnd() >= nEnd ) )
+ {
+ // full coverage
+ aAttribs.Put( *pAttr->GetItem() );
+ }
+ else
+ {
+ // OptimizeRagnge() assures that not the same attr can follow for full coverage
+ // only partial, check with current, when using para/styhe, otherwise invalid.
+ if ( !( nFlags & (GETATTRIBS_PARAATTRIBS|GETATTRIBS_STYLESHEET) ) ||
+ ( *pAttr->GetItem() != aAttribs.Get( pAttr->Which() ) ) )
+ {
+ aAttribs.InvalidateItem( pAttr->Which() );
+ }
+ }
+ }
+ }
+
+ if ( pAttr->GetStart() > nEnd )
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ return aAttribs;
+}
+
+
void ImpEditEngine::SetAttribs( EditSelection aSel, const SfxItemSet& rSet, BYTE nSpecial )
{
aSel.Adjust( aEditDoc );