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