xref: /aoo41x/main/sw/source/core/text/redlnitr.cxx (revision efeef26f)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*efeef26fSAndrew Rist  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19*efeef26fSAndrew Rist  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "hintids.hxx"
29cdf0e10cSrcweir #include <svl/whiter.hxx>
30cdf0e10cSrcweir #include <tools/shl.hxx>
31cdf0e10cSrcweir #ifndef _COM_SUN_STAR_I18N_SCRIPTTYPE_HDL_
32cdf0e10cSrcweir #include <com/sun/star/i18n/ScriptType.hdl>
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir #include <swmodule.hxx>
35cdf0e10cSrcweir #include <redline.hxx>		// SwRedline
36cdf0e10cSrcweir #include <txtatr.hxx>		// SwTxt ...
37cdf0e10cSrcweir #include <docary.hxx>		// SwRedlineTbl
38cdf0e10cSrcweir #include <itratr.hxx>		// SwAttrIter
39cdf0e10cSrcweir #include <ndtxt.hxx>		// SwTxtNode
40cdf0e10cSrcweir #include <doc.hxx>			// SwDoc
41cdf0e10cSrcweir #include <rootfrm.hxx>
42cdf0e10cSrcweir #include <breakit.hxx>
43cdf0e10cSrcweir #include <vcl/keycodes.hxx>
44cdf0e10cSrcweir #include <vcl/cmdevt.hxx>
45cdf0e10cSrcweir #include <vcl/settings.hxx>
46cdf0e10cSrcweir #include <txtfrm.hxx>		// SwTxtFrm
47cdf0e10cSrcweir #ifndef _APP_HXX //autogen
48cdf0e10cSrcweir #include <vcl/svapp.hxx>
49cdf0e10cSrcweir #endif
50cdf0e10cSrcweir #include <redlnitr.hxx>
51cdf0e10cSrcweir #include <extinput.hxx>
52cdf0e10cSrcweir #include <sfx2/printer.hxx>
53cdf0e10cSrcweir #include <vcl/window.hxx>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir using namespace ::com::sun::star;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir /*************************************************************************
58cdf0e10cSrcweir  *						SwAttrIter::CtorInitAttrIter()
59cdf0e10cSrcweir  *************************************************************************/
CtorInitAttrIter(SwTxtNode & rTxtNode,SwScriptInfo & rScrInf,SwTxtFrm * pFrm)60cdf0e10cSrcweir void SwAttrIter::CtorInitAttrIter( SwTxtNode& rTxtNode, SwScriptInfo& rScrInf, SwTxtFrm* pFrm )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	// Beim HTML-Import kann es vorkommen, dass kein Layout existiert.
63cdf0e10cSrcweir     SwRootFrm* pRootFrm = rTxtNode.getIDocumentLayoutAccess()->GetCurrentLayout();
64cdf0e10cSrcweir     pShell = pRootFrm ? pRootFrm->GetCurrShell() : 0;	//swmod 080218
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     pScriptInfo = &rScrInf;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     // attributes set at the whole paragraph
69cdf0e10cSrcweir 	pAttrSet = rTxtNode.GetpSwAttrSet();
70cdf0e10cSrcweir     // attribute array
71cdf0e10cSrcweir     pHints = rTxtNode.GetpSwpHints();
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     // Build a font matching the default paragraph style:
74cdf0e10cSrcweir     SwFontAccess aFontAccess( &rTxtNode.GetAnyFmtColl(), pShell );
75cdf0e10cSrcweir     delete pFnt;
76cdf0e10cSrcweir     pFnt = new SwFont( *aFontAccess.Get()->GetFont() );
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     // set font to vertical if frame layout is vertical
79cdf0e10cSrcweir     sal_Bool bVertLayout = sal_False;
80cdf0e10cSrcweir     sal_Bool bRTL = sal_False;
81cdf0e10cSrcweir     if ( pFrm )
82cdf0e10cSrcweir     {
83cdf0e10cSrcweir         if ( pFrm->IsVertical() )
84cdf0e10cSrcweir         {
85cdf0e10cSrcweir             bVertLayout = sal_True;
86cdf0e10cSrcweir             pFnt->SetVertical( pFnt->GetOrientation(), sal_True );
87cdf0e10cSrcweir         }
88cdf0e10cSrcweir         bRTL = pFrm->IsRightToLeft();
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     // Initialize the default attribute of the attribute handler
92cdf0e10cSrcweir     // based on the attribute array cached together with the font.
93cdf0e10cSrcweir     // If any further attributes for the paragraph are given in pAttrSet
94cdf0e10cSrcweir     // consider them during construction of the default array, and apply
95cdf0e10cSrcweir     // them to the font
96cdf0e10cSrcweir     aAttrHandler.Init( aFontAccess.Get()->GetDefault(), pAttrSet,
97cdf0e10cSrcweir                        *rTxtNode.getIDocumentSettingAccess(), pShell, *pFnt, bVertLayout );
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	aMagicNo[SW_LATIN] = aMagicNo[SW_CJK] = aMagicNo[SW_CTL] = NULL;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	// determine script changes if not already done for current paragraph
102cdf0e10cSrcweir 	ASSERT( pScriptInfo, "No script info available");
103cdf0e10cSrcweir     if ( pScriptInfo->GetInvalidity() != STRING_LEN )
104cdf0e10cSrcweir          pScriptInfo->InitScriptInfo( rTxtNode, bRTL );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	if ( pBreakIt->GetBreakIter().is() )
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir         pFnt->SetActual( SwScriptInfo::WhichFont( 0, 0, pScriptInfo ) );
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         xub_StrLen nChg = 0;
111cdf0e10cSrcweir 		sal_uInt16 nCnt = 0;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir         do
114cdf0e10cSrcweir 		{
115cdf0e10cSrcweir 			nChg = pScriptInfo->GetScriptChg( nCnt );
116cdf0e10cSrcweir             sal_uInt16 nScript = pScriptInfo->GetScriptType( nCnt++ );
117cdf0e10cSrcweir 			sal_uInt8 nTmp = 4;
118cdf0e10cSrcweir 			switch ( nScript ) {
119cdf0e10cSrcweir 				case i18n::ScriptType::ASIAN :
120cdf0e10cSrcweir 					if( !aMagicNo[SW_CJK] ) nTmp = SW_CJK; break;
121cdf0e10cSrcweir 				case i18n::ScriptType::COMPLEX :
122cdf0e10cSrcweir 					if( !aMagicNo[SW_CTL] ) nTmp = SW_CTL; break;
123cdf0e10cSrcweir 				default:
124cdf0e10cSrcweir 					if( !aMagicNo[SW_LATIN ] ) nTmp = SW_LATIN;
125cdf0e10cSrcweir 			}
126cdf0e10cSrcweir 			if( nTmp < 4 )
127cdf0e10cSrcweir 			{
128cdf0e10cSrcweir 				pFnt->ChkMagic( pShell, nTmp );
129cdf0e10cSrcweir 				pFnt->GetMagic( aMagicNo[ nTmp ], aFntIdx[ nTmp ], nTmp );
130cdf0e10cSrcweir 			}
131cdf0e10cSrcweir 		} while( nChg < rTxtNode.GetTxt().Len() );
132cdf0e10cSrcweir 	}
133cdf0e10cSrcweir 	else
134cdf0e10cSrcweir 	{
135cdf0e10cSrcweir 		pFnt->ChkMagic( pShell, SW_LATIN );
136cdf0e10cSrcweir 		pFnt->GetMagic( aMagicNo[ SW_LATIN ], aFntIdx[ SW_LATIN ], SW_LATIN );
137cdf0e10cSrcweir 	}
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     nStartIndex = nEndIndex = nPos = nChgCnt = 0;
140cdf0e10cSrcweir 	nPropFont = 0;
141cdf0e10cSrcweir 	SwDoc* pDoc = rTxtNode.GetDoc();
142cdf0e10cSrcweir     const IDocumentRedlineAccess* pIDRA = rTxtNode.getIDocumentRedlineAccess();
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	const SwExtTextInput* pExtInp = pDoc->GetExtTextInput( rTxtNode );
145cdf0e10cSrcweir     const bool bShow = IDocumentRedlineAccess::IsShowChanges( pIDRA->GetRedlineMode() );
146cdf0e10cSrcweir     if( pExtInp || bShow )
147cdf0e10cSrcweir 	{
148cdf0e10cSrcweir         MSHORT nRedlPos = pIDRA->GetRedlinePos( rTxtNode, USHRT_MAX );
149cdf0e10cSrcweir 		if( pExtInp || MSHRT_MAX != nRedlPos )
150cdf0e10cSrcweir 		{
151cdf0e10cSrcweir 			const SvUShorts* pArr = 0;
152cdf0e10cSrcweir 			xub_StrLen nInputStt = 0;
153cdf0e10cSrcweir 			if( pExtInp )
154cdf0e10cSrcweir 			{
155cdf0e10cSrcweir 				pArr = &pExtInp->GetAttrs();
156cdf0e10cSrcweir 				nInputStt = pExtInp->Start()->nContent.GetIndex();
157cdf0e10cSrcweir                 Seek( 0 );
158cdf0e10cSrcweir 			}
159cdf0e10cSrcweir 
160cdf0e10cSrcweir             pRedln = new SwRedlineItr( rTxtNode, *pFnt, aAttrHandler, nRedlPos,
161cdf0e10cSrcweir                                         bShow, pArr, nInputStt );
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 			if( pRedln->IsOn() )
164cdf0e10cSrcweir 				++nChgCnt;
165cdf0e10cSrcweir 		}
166cdf0e10cSrcweir 	}
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir /*************************************************************************
170cdf0e10cSrcweir  * SwRedlineItr - Der Redline-Iterator
171cdf0e10cSrcweir  *
172cdf0e10cSrcweir  * Folgende Informationen/Zustaende gibt es im RedlineIterator:
173cdf0e10cSrcweir  *
174cdf0e10cSrcweir  * nFirst ist der erste Index der RedlineTbl, der mit dem Absatz ueberlappt.
175cdf0e10cSrcweir  *
176cdf0e10cSrcweir  * nAct ist der zur Zeit aktive ( wenn bOn gesetzt ist ) oder der naechste
177cdf0e10cSrcweir  * in Frage kommende Index.
178cdf0e10cSrcweir  * nStart und nEnd geben die Grenzen des Objekts innerhalb des Absatzes an.
179cdf0e10cSrcweir  *
180cdf0e10cSrcweir  * Wenn bOn gesetzt ist, ist der Font entsprechend manipuliert worden.
181cdf0e10cSrcweir  *
182cdf0e10cSrcweir  * Wenn nAct auf MSHRT_MAX gesetzt wurde ( durch Reset() ), so ist zur Zeit
183cdf0e10cSrcweir  * kein Redline aktiv, nStart und nEnd sind invalid.
184cdf0e10cSrcweir  *************************************************************************/
185cdf0e10cSrcweir 
SwRedlineItr(const SwTxtNode & rTxtNd,SwFont & rFnt,SwAttrHandler & rAH,MSHORT nRed,sal_Bool bShw,const SvUShorts * pArr,xub_StrLen nExtStart)186cdf0e10cSrcweir SwRedlineItr::SwRedlineItr( const SwTxtNode& rTxtNd, SwFont& rFnt,
187cdf0e10cSrcweir     SwAttrHandler& rAH, MSHORT nRed, sal_Bool bShw, const SvUShorts *pArr,
188cdf0e10cSrcweir     xub_StrLen nExtStart )
189cdf0e10cSrcweir     : rDoc( *rTxtNd.GetDoc() ), rNd( rTxtNd ), rAttrHandler( rAH ), pSet( 0 ),
190cdf0e10cSrcweir 	  nNdIdx( rTxtNd.GetIndex() ), nFirst( nRed ),
191cdf0e10cSrcweir       nAct( MSHRT_MAX ), bOn( sal_False ), bShow( bShw )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir     if( pArr )
194cdf0e10cSrcweir         pExt = new SwExtend( *pArr, nExtStart );
195cdf0e10cSrcweir     else
196cdf0e10cSrcweir         pExt = NULL;
197cdf0e10cSrcweir 	Seek( rFnt, 0, STRING_LEN );
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
~SwRedlineItr()200cdf0e10cSrcweir SwRedlineItr::~SwRedlineItr()
201cdf0e10cSrcweir {
202cdf0e10cSrcweir 	Clear( NULL );
203cdf0e10cSrcweir 	delete pSet;
204cdf0e10cSrcweir 	delete pExt;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir // Der Return-Wert von SwRedlineItr::Seek gibt an, ob der aktuelle Font
208cdf0e10cSrcweir // veraendert wurde durch Verlassen (-1) oder Betreten eines Bereichs (+1)
209cdf0e10cSrcweir 
_Seek(SwFont & rFnt,xub_StrLen nNew,xub_StrLen nOld)210cdf0e10cSrcweir short SwRedlineItr::_Seek( SwFont& rFnt, xub_StrLen nNew, xub_StrLen nOld )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir 	short nRet = 0;
213cdf0e10cSrcweir 	if( ExtOn() )
214cdf0e10cSrcweir         return 0; // Abkuerzung: wenn wir innerhalb eines ExtendTextInputs sind
215cdf0e10cSrcweir 			// kann es keine anderen Attributwechsel (auch nicht durch Redlining) geben
216cdf0e10cSrcweir 	if( bShow )
217cdf0e10cSrcweir 	{
218cdf0e10cSrcweir 		if( bOn )
219cdf0e10cSrcweir 		{
220cdf0e10cSrcweir 			if( nNew >= nEnd )
221cdf0e10cSrcweir 			{
222cdf0e10cSrcweir 				--nRet;
223cdf0e10cSrcweir 				_Clear( &rFnt );	// Wir gehen hinter den aktuellen Bereich
224cdf0e10cSrcweir 				++nAct;		   		// und pruefen gleich den naechsten
225cdf0e10cSrcweir 			}
226cdf0e10cSrcweir 			else if( nNew < nStart )
227cdf0e10cSrcweir 			{
228cdf0e10cSrcweir 				--nRet;
229cdf0e10cSrcweir 				_Clear( &rFnt );	// Wir gehen vor den aktuellen Bereich
230cdf0e10cSrcweir 				if( nAct > nFirst )
231cdf0e10cSrcweir 					nAct = nFirst;	// Die Pruefung muss von vorne beginnen
232cdf0e10cSrcweir 				else
233cdf0e10cSrcweir 					return nRet + EnterExtend( rFnt, nNew ); // Es gibt keinen vor uns.
234cdf0e10cSrcweir 			}
235cdf0e10cSrcweir 			else
236cdf0e10cSrcweir 				return nRet + EnterExtend( rFnt, nNew ); // Wir sind im gleichen Bereich geblieben.
237cdf0e10cSrcweir 		}
238cdf0e10cSrcweir 		if( MSHRT_MAX == nAct || nOld > nNew )
239cdf0e10cSrcweir 			nAct = nFirst;
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 		nStart = STRING_LEN;
242cdf0e10cSrcweir 		nEnd = STRING_LEN;
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 		for( ; nAct < rDoc.GetRedlineTbl().Count() ; ++nAct )
245cdf0e10cSrcweir 		{
246cdf0e10cSrcweir             rDoc.GetRedlineTbl()[ nAct ]->CalcStartEnd( nNdIdx, nStart, nEnd );
247cdf0e10cSrcweir 
248cdf0e10cSrcweir             if( nNew < nEnd )
249cdf0e10cSrcweir 			{
250cdf0e10cSrcweir 				if( nNew >= nStart ) // der einzig moegliche Kandidat
251cdf0e10cSrcweir 				{
252cdf0e10cSrcweir 					bOn = sal_True;
253cdf0e10cSrcweir 					const SwRedline *pRed = rDoc.GetRedlineTbl()[ nAct ];
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 					if (pSet)
256cdf0e10cSrcweir 						pSet->ClearItem();
257cdf0e10cSrcweir 					else
258cdf0e10cSrcweir 					{
259cdf0e10cSrcweir                         SwAttrPool& rPool =
260cdf0e10cSrcweir                             const_cast<SwDoc&>(rDoc).GetAttrPool();
261cdf0e10cSrcweir 						pSet = new SfxItemSet(rPool, RES_CHRATR_BEGIN, RES_CHRATR_END-1);
262cdf0e10cSrcweir 					}
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 					if( 1 < pRed->GetStackCount() )
265cdf0e10cSrcweir 						FillHints( pRed->GetAuthor( 1 ), pRed->GetType( 1 ) );
266cdf0e10cSrcweir 					FillHints( pRed->GetAuthor(), pRed->GetType() );
267cdf0e10cSrcweir 
268cdf0e10cSrcweir 					SfxWhichIter aIter( *pSet );
269cdf0e10cSrcweir 					MSHORT nWhich = aIter.FirstWhich();
270cdf0e10cSrcweir 					while( nWhich )
271cdf0e10cSrcweir 					{
272cdf0e10cSrcweir 						const SfxPoolItem* pItem;
273cdf0e10cSrcweir 						if( ( nWhich < RES_CHRATR_END ) &&
274cdf0e10cSrcweir 							( SFX_ITEM_SET == pSet->GetItemState( nWhich, sal_True,	&pItem ) ) )
275cdf0e10cSrcweir                         {
276cdf0e10cSrcweir                             SwTxtAttr* pAttr = MakeRedlineTxtAttr(
277cdf0e10cSrcweir                                 const_cast<SwDoc&>(rDoc),
278cdf0e10cSrcweir                                 *const_cast<SfxPoolItem*>(pItem) );
279cdf0e10cSrcweir                             pAttr->SetPriorityAttr( sal_True );
280cdf0e10cSrcweir 							aHints.C40_INSERT( SwTxtAttr, pAttr, aHints.Count());
281cdf0e10cSrcweir                             rAttrHandler.PushAndChg( *pAttr, rFnt );
282cdf0e10cSrcweir 							if( RES_CHRATR_COLOR == nWhich )
283cdf0e10cSrcweir 								rFnt.SetNoCol( sal_True );
284cdf0e10cSrcweir 						}
285cdf0e10cSrcweir 						nWhich = aIter.NextWhich();
286cdf0e10cSrcweir 					}
287cdf0e10cSrcweir 
288cdf0e10cSrcweir 					++nRet;
289cdf0e10cSrcweir 				}
290cdf0e10cSrcweir 				break;
291cdf0e10cSrcweir 			}
292cdf0e10cSrcweir 			nStart = STRING_LEN;
293cdf0e10cSrcweir 			nEnd = STRING_LEN;
294cdf0e10cSrcweir 		}
295cdf0e10cSrcweir 	}
296cdf0e10cSrcweir 	return nRet + EnterExtend( rFnt, nNew );
297cdf0e10cSrcweir }
298cdf0e10cSrcweir 
FillHints(MSHORT nAuthor,RedlineType_t eType)299cdf0e10cSrcweir void SwRedlineItr::FillHints( MSHORT nAuthor, RedlineType_t eType )
300cdf0e10cSrcweir {
301cdf0e10cSrcweir 	switch ( eType )
302cdf0e10cSrcweir 	{
303cdf0e10cSrcweir 		case nsRedlineType_t::REDLINE_INSERT:
304cdf0e10cSrcweir 			SW_MOD()->GetInsertAuthorAttr(nAuthor, *pSet);
305cdf0e10cSrcweir 			break;
306cdf0e10cSrcweir 		case nsRedlineType_t::REDLINE_DELETE:
307cdf0e10cSrcweir 			SW_MOD()->GetDeletedAuthorAttr(nAuthor, *pSet);
308cdf0e10cSrcweir 			break;
309cdf0e10cSrcweir 		case nsRedlineType_t::REDLINE_FORMAT:
310cdf0e10cSrcweir 		case nsRedlineType_t::REDLINE_FMTCOLL:
311cdf0e10cSrcweir 			SW_MOD()->GetFormatAuthorAttr(nAuthor, *pSet);
312cdf0e10cSrcweir 			break;
313cdf0e10cSrcweir         default:
314cdf0e10cSrcweir             break;
315cdf0e10cSrcweir 	}
316cdf0e10cSrcweir }
317cdf0e10cSrcweir 
ChangeTxtAttr(SwFont * pFnt,SwTxtAttr & rHt,sal_Bool bChg)318cdf0e10cSrcweir void SwRedlineItr::ChangeTxtAttr( SwFont* pFnt, SwTxtAttr &rHt, sal_Bool bChg )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir 	ASSERT( IsOn(), "SwRedlineItr::ChangeTxtAttr: Off?" );
321cdf0e10cSrcweir 
322cdf0e10cSrcweir     if( !bShow && !pExt )
323cdf0e10cSrcweir         return;
324cdf0e10cSrcweir 
325cdf0e10cSrcweir     if( bChg )
326cdf0e10cSrcweir     {
327cdf0e10cSrcweir         if ( pExt && pExt->IsOn() )
328cdf0e10cSrcweir             rAttrHandler.PushAndChg( rHt, *pExt->GetFont() );
329cdf0e10cSrcweir         else
330cdf0e10cSrcweir             rAttrHandler.PushAndChg( rHt, *pFnt );
331cdf0e10cSrcweir     }
332cdf0e10cSrcweir     else
333cdf0e10cSrcweir     {
334cdf0e10cSrcweir         ASSERT( ! pExt || ! pExt->IsOn(), "Pop of attribute during opened extension" )
335cdf0e10cSrcweir         rAttrHandler.PopAndChg( rHt, *pFnt );
336cdf0e10cSrcweir     }
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
_Clear(SwFont * pFnt)339cdf0e10cSrcweir void SwRedlineItr::_Clear( SwFont* pFnt )
340cdf0e10cSrcweir {
341cdf0e10cSrcweir 	ASSERT( bOn, "SwRedlineItr::Clear: Off?" );
342cdf0e10cSrcweir 	bOn = sal_False;
343cdf0e10cSrcweir 	while( aHints.Count() )
344cdf0e10cSrcweir 	{
345cdf0e10cSrcweir 		SwTxtAttr *pPos = aHints[ 0 ];
346cdf0e10cSrcweir 		aHints.Remove(0);
347cdf0e10cSrcweir         if( pFnt )
348cdf0e10cSrcweir             rAttrHandler.PopAndChg( *pPos, *pFnt );
349cdf0e10cSrcweir         else
350cdf0e10cSrcweir             rAttrHandler.Pop( *pPos );
351cdf0e10cSrcweir         SwTxtAttr::Destroy(pPos, const_cast<SwDoc&>(rDoc).GetAttrPool() );
352cdf0e10cSrcweir 	}
353cdf0e10cSrcweir 	if( pFnt )
354cdf0e10cSrcweir 		pFnt->SetNoCol( sal_False );
355cdf0e10cSrcweir }
356cdf0e10cSrcweir 
_GetNextRedln(xub_StrLen nNext)357cdf0e10cSrcweir xub_StrLen SwRedlineItr::_GetNextRedln( xub_StrLen nNext )
358cdf0e10cSrcweir {
359cdf0e10cSrcweir 	nNext = NextExtend( nNext );
360cdf0e10cSrcweir 	if( !bShow || MSHRT_MAX == nFirst )
361cdf0e10cSrcweir 		return nNext;
362cdf0e10cSrcweir 	if( MSHRT_MAX == nAct )
363cdf0e10cSrcweir 	{
364cdf0e10cSrcweir 		nAct = nFirst;
365cdf0e10cSrcweir         rDoc.GetRedlineTbl()[ nAct ]->CalcStartEnd( nNdIdx, nStart, nEnd );
366cdf0e10cSrcweir 	}
367cdf0e10cSrcweir 	if( bOn || !nStart )
368cdf0e10cSrcweir 	{
369cdf0e10cSrcweir 		if( nEnd < nNext )
370cdf0e10cSrcweir 			nNext = nEnd;
371cdf0e10cSrcweir 	}
372cdf0e10cSrcweir 	else if( nStart < nNext )
373cdf0e10cSrcweir 		nNext = nStart;
374cdf0e10cSrcweir 	return nNext;
375cdf0e10cSrcweir }
376cdf0e10cSrcweir 
_ChkSpecialUnderline() const377cdf0e10cSrcweir sal_Bool SwRedlineItr::_ChkSpecialUnderline() const
378cdf0e10cSrcweir {
379cdf0e10cSrcweir 	// Wenn die Unterstreichung oder das Escapement vom Redling kommt,
380cdf0e10cSrcweir 	// wenden wir immer das SpecialUnderlining, d.h. die Unterstreichung
381cdf0e10cSrcweir 	// unter der Grundlinie an.
382cdf0e10cSrcweir 	for( MSHORT i = 0; i < aHints.Count(); ++i )
383cdf0e10cSrcweir 	{
384cdf0e10cSrcweir         MSHORT nWhich = aHints[i]->Which();
385cdf0e10cSrcweir 		if( RES_CHRATR_UNDERLINE == nWhich ||
386cdf0e10cSrcweir 			RES_CHRATR_ESCAPEMENT == nWhich )
387cdf0e10cSrcweir 			return sal_True;
388cdf0e10cSrcweir 	}
389cdf0e10cSrcweir 	return sal_False;
390cdf0e10cSrcweir }
391cdf0e10cSrcweir 
CheckLine(xub_StrLen nChkStart,xub_StrLen nChkEnd)392cdf0e10cSrcweir sal_Bool SwRedlineItr::CheckLine( xub_StrLen nChkStart, xub_StrLen nChkEnd )
393cdf0e10cSrcweir {
394cdf0e10cSrcweir 	if( nFirst == MSHRT_MAX )
395cdf0e10cSrcweir 		return sal_False;
396cdf0e10cSrcweir 	if( nChkEnd == nChkStart ) // Leerzeilen gucken ein Zeichen weiter.
397cdf0e10cSrcweir 		++nChkEnd;
398cdf0e10cSrcweir 	xub_StrLen nOldStart = nStart;
399cdf0e10cSrcweir 	xub_StrLen nOldEnd = nEnd;
400cdf0e10cSrcweir 	xub_StrLen nOldAct = nAct;
401cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
402cdf0e10cSrcweir 
403cdf0e10cSrcweir 	for( nAct = nFirst; nAct < rDoc.GetRedlineTbl().Count() ; ++nAct )
404cdf0e10cSrcweir 	{
405cdf0e10cSrcweir         rDoc.GetRedlineTbl()[ nAct ]->CalcStartEnd( nNdIdx, nStart, nEnd );
406cdf0e10cSrcweir 		if( nChkEnd < nStart )
407cdf0e10cSrcweir 			break;
408cdf0e10cSrcweir 		if( nChkStart <= nEnd && ( nChkEnd > nStart || STRING_LEN == nEnd ) )
409cdf0e10cSrcweir 		{
410cdf0e10cSrcweir 			bRet = sal_True;
411cdf0e10cSrcweir 			break;
412cdf0e10cSrcweir 		}
413cdf0e10cSrcweir 	}
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 	nStart = nOldStart;
416cdf0e10cSrcweir 	nEnd = nOldEnd;
417cdf0e10cSrcweir 	nAct = nOldAct;
418cdf0e10cSrcweir 	return bRet;
419cdf0e10cSrcweir }
420cdf0e10cSrcweir 
ActualizeFont(SwFont & rFnt,MSHORT nAttr)421cdf0e10cSrcweir void SwExtend::ActualizeFont( SwFont &rFnt, MSHORT nAttr )
422cdf0e10cSrcweir {
423cdf0e10cSrcweir 	if ( nAttr & EXTTEXTINPUT_ATTR_UNDERLINE )
424cdf0e10cSrcweir 		rFnt.SetUnderline( UNDERLINE_SINGLE );
425cdf0e10cSrcweir 	else if ( nAttr & EXTTEXTINPUT_ATTR_BOLDUNDERLINE )
426cdf0e10cSrcweir 		rFnt.SetUnderline( UNDERLINE_BOLD );
427cdf0e10cSrcweir 	else if ( nAttr & EXTTEXTINPUT_ATTR_DOTTEDUNDERLINE )
428cdf0e10cSrcweir 		rFnt.SetUnderline( UNDERLINE_DOTTED );
429cdf0e10cSrcweir 	else if ( nAttr & EXTTEXTINPUT_ATTR_DASHDOTUNDERLINE )
430cdf0e10cSrcweir 		rFnt.SetUnderline( UNDERLINE_DOTTED );
431cdf0e10cSrcweir 
432cdf0e10cSrcweir 	if ( nAttr & EXTTEXTINPUT_ATTR_REDTEXT )
433cdf0e10cSrcweir 		rFnt.SetColor( Color( COL_RED ) );
434cdf0e10cSrcweir 
435cdf0e10cSrcweir 	if ( nAttr & EXTTEXTINPUT_ATTR_HIGHLIGHT )
436cdf0e10cSrcweir 	{
437cdf0e10cSrcweir 		const StyleSettings& rStyleSettings = GetpApp()->GetSettings().GetStyleSettings();
438cdf0e10cSrcweir 		rFnt.SetColor( rStyleSettings.GetHighlightTextColor() );
439cdf0e10cSrcweir         rFnt.SetBackColor( new Color( rStyleSettings.GetHighlightColor() ) );
440cdf0e10cSrcweir 	}
441cdf0e10cSrcweir 	if ( nAttr & EXTTEXTINPUT_ATTR_GRAYWAVELINE )
442cdf0e10cSrcweir 		rFnt.SetGreyWave( sal_True );
443cdf0e10cSrcweir }
444cdf0e10cSrcweir 
Enter(SwFont & rFnt,xub_StrLen nNew)445cdf0e10cSrcweir short SwExtend::Enter( SwFont& rFnt, xub_StrLen nNew )
446cdf0e10cSrcweir {
447cdf0e10cSrcweir 	ASSERT( !Inside(), "SwExtend: Enter without Leave" );
448cdf0e10cSrcweir 	ASSERT( !pFnt, "SwExtend: Enter with Font" );
449cdf0e10cSrcweir 	nPos = nNew;
450cdf0e10cSrcweir 	if( Inside() )
451cdf0e10cSrcweir 	{
452cdf0e10cSrcweir 		pFnt = new SwFont( rFnt );
453cdf0e10cSrcweir         ActualizeFont( rFnt, rArr[ nPos - nStart ] );
454cdf0e10cSrcweir 		return 1;
455cdf0e10cSrcweir 	}
456cdf0e10cSrcweir 	return 0;
457cdf0e10cSrcweir }
458cdf0e10cSrcweir 
_Leave(SwFont & rFnt,xub_StrLen nNew)459cdf0e10cSrcweir sal_Bool SwExtend::_Leave( SwFont& rFnt, xub_StrLen nNew )
460cdf0e10cSrcweir {
461cdf0e10cSrcweir 	ASSERT( Inside(), "SwExtend: Leave without Enter" );
462cdf0e10cSrcweir 	MSHORT nOldAttr = rArr[ nPos - nStart ];
463cdf0e10cSrcweir 	nPos = nNew;
464cdf0e10cSrcweir 	if( Inside() )
465cdf0e10cSrcweir 	{	// Wir sind innerhalb des ExtendText-Bereichs geblieben
466cdf0e10cSrcweir 		MSHORT nAttr = rArr[ nPos - nStart ];
467cdf0e10cSrcweir 		if( nOldAttr != nAttr ) // Gibt es einen (inneren) Attributwechsel?
468cdf0e10cSrcweir 		{
469cdf0e10cSrcweir             rFnt = *pFnt;
470cdf0e10cSrcweir             ActualizeFont( rFnt, nAttr );
471cdf0e10cSrcweir 		}
472cdf0e10cSrcweir 	}
473cdf0e10cSrcweir 	else
474cdf0e10cSrcweir 	{
475cdf0e10cSrcweir         rFnt = *pFnt;
476cdf0e10cSrcweir 		delete pFnt;
477cdf0e10cSrcweir 		pFnt = NULL;
478cdf0e10cSrcweir 		return sal_True;
479cdf0e10cSrcweir 	}
480cdf0e10cSrcweir 	return sal_False;
481cdf0e10cSrcweir }
482cdf0e10cSrcweir 
Next(xub_StrLen nNext)483cdf0e10cSrcweir xub_StrLen SwExtend::Next( xub_StrLen nNext )
484cdf0e10cSrcweir {
485cdf0e10cSrcweir 	if( nPos < nStart )
486cdf0e10cSrcweir 	{
487cdf0e10cSrcweir 		if( nNext > nStart )
488cdf0e10cSrcweir 			nNext = nStart;
489cdf0e10cSrcweir 	}
490cdf0e10cSrcweir 	else if( nPos < nEnd )
491cdf0e10cSrcweir 	{
492cdf0e10cSrcweir 		MSHORT nIdx = nPos - nStart;
493cdf0e10cSrcweir 		MSHORT nAttr = rArr[ nIdx ];
494cdf0e10cSrcweir 		while( ++nIdx < rArr.Count() && nAttr == rArr[ nIdx ] )
495cdf0e10cSrcweir 			; //nothing
496cdf0e10cSrcweir 		nIdx = nIdx + nStart;
497cdf0e10cSrcweir 		if( nNext > nIdx )
498cdf0e10cSrcweir 			nNext = nIdx;
499cdf0e10cSrcweir 	}
500cdf0e10cSrcweir 	return nNext;
501cdf0e10cSrcweir }
502