Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "hintids.hxx"
21 : #include <svl/whiter.hxx>
22 : #include <com/sun/star/i18n/ScriptType.hpp>
23 : #include <swmodule.hxx>
24 : #include <redline.hxx>
25 : #include <txtatr.hxx>
26 : #include <docary.hxx>
27 : #include <itratr.hxx>
28 : #include <ndtxt.hxx>
29 : #include <doc.hxx>
30 : #include <IDocumentRedlineAccess.hxx>
31 : #include <IDocumentLayoutAccess.hxx>
32 : #include <rootfrm.hxx>
33 : #include <breakit.hxx>
34 : #include <vcl/keycodes.hxx>
35 : #include <vcl/cmdevt.hxx>
36 : #include <vcl/settings.hxx>
37 : #include <txtfrm.hxx>
38 : #include <vcl/svapp.hxx>
39 : #include <redlnitr.hxx>
40 : #include <extinput.hxx>
41 : #include <sfx2/printer.hxx>
42 : #include <vcl/window.hxx>
43 :
44 : using namespace ::com::sun::star;
45 :
46 185270 : void SwAttrIter::CtorInitAttrIter( SwTextNode& rTextNode, SwScriptInfo& rScrInf, SwTextFrm* pFrm )
47 : {
48 : // during HTML-Import it can happen, that no layout exists
49 185270 : SwRootFrm* pRootFrm = rTextNode.getIDocumentLayoutAccess()->GetCurrentLayout();
50 185270 : pShell = pRootFrm ? pRootFrm->GetCurrShell() : 0;
51 :
52 185270 : pScriptInfo = &rScrInf;
53 :
54 : // attributes set at the whole paragraph
55 185270 : pAttrSet = rTextNode.GetpSwAttrSet();
56 : // attribute array
57 185270 : pHints = rTextNode.GetpSwpHints();
58 :
59 : // Build a font matching the default paragraph style:
60 185270 : SwFontAccess aFontAccess( &rTextNode.GetAnyFormatColl(), pShell );
61 185270 : delete pFnt;
62 185270 : pFnt = new SwFont( aFontAccess.Get()->GetFont() );
63 :
64 : // set font to vertical if frame layout is vertical
65 185270 : bool bVertLayout = false;
66 185270 : bool bRTL = false;
67 185270 : if ( pFrm )
68 : {
69 184833 : if ( pFrm->IsVertical() )
70 : {
71 5 : bVertLayout = true;
72 5 : pFnt->SetVertical( pFnt->GetOrientation(), true );
73 : }
74 184833 : bRTL = pFrm->IsRightToLeft();
75 : }
76 :
77 : // Initialize the default attribute of the attribute handler
78 : // based on the attribute array cached together with the font.
79 : // If any further attributes for the paragraph are given in pAttrSet
80 : // consider them during construction of the default array, and apply
81 : // them to the font
82 : aAttrHandler.Init( aFontAccess.Get()->GetDefault(), pAttrSet,
83 185270 : *rTextNode.getIDocumentSettingAccess(), pShell, *pFnt, bVertLayout );
84 :
85 185270 : aMagicNo[SW_LATIN] = aMagicNo[SW_CJK] = aMagicNo[SW_CTL] = NULL;
86 :
87 : // determine script changes if not already done for current paragraph
88 : OSL_ENSURE( pScriptInfo, "No script info available");
89 185270 : if ( pScriptInfo->GetInvalidityA() != COMPLETE_STRING )
90 47489 : pScriptInfo->InitScriptInfo( rTextNode, bRTL );
91 :
92 185270 : if ( g_pBreakIt->GetBreakIter().is() )
93 : {
94 185270 : pFnt->SetActual( SwScriptInfo::WhichFont( 0, 0, pScriptInfo ) );
95 :
96 185270 : sal_Int32 nChg = 0;
97 185270 : size_t nCnt = 0;
98 :
99 185563 : do
100 : {
101 185563 : if ( nCnt >= pScriptInfo->CountScriptChg() )
102 0 : break;
103 185563 : nChg = pScriptInfo->GetScriptChg( nCnt );
104 185563 : int nTmp = SW_SCRIPTS;
105 185563 : switch ( pScriptInfo->GetScriptType( nCnt++ ) ) {
106 : case i18n::ScriptType::ASIAN :
107 351 : if( !aMagicNo[SW_CJK] ) nTmp = SW_CJK; break;
108 : case i18n::ScriptType::COMPLEX :
109 152 : if( !aMagicNo[SW_CTL] ) nTmp = SW_CTL; break;
110 : default:
111 185060 : if( !aMagicNo[SW_LATIN ] ) nTmp = SW_LATIN;
112 : }
113 185563 : if( nTmp < SW_SCRIPTS )
114 : {
115 185389 : pFnt->ChkMagic( pShell, nTmp );
116 185389 : pFnt->GetMagic( aMagicNo[ nTmp ], aFntIdx[ nTmp ], nTmp );
117 : }
118 185563 : } while (nChg < rTextNode.GetText().getLength());
119 : }
120 : else
121 : {
122 0 : pFnt->ChkMagic( pShell, SW_LATIN );
123 0 : pFnt->GetMagic( aMagicNo[ SW_LATIN ], aFntIdx[ SW_LATIN ], SW_LATIN );
124 : }
125 :
126 185270 : nStartIndex = nEndIndex = nPos = nChgCnt = 0;
127 185270 : nPropFont = 0;
128 185270 : SwDoc* pDoc = rTextNode.GetDoc();
129 185270 : const IDocumentRedlineAccess* pIDRA = rTextNode.getIDocumentRedlineAccess();
130 :
131 185270 : const SwExtTextInput* pExtInp = pDoc->GetExtTextInput( rTextNode );
132 185270 : const bool bShow = IDocumentRedlineAccess::IsShowChanges( pIDRA->GetRedlineMode() );
133 185270 : if( pExtInp || bShow )
134 : {
135 183970 : const sal_uInt16 nRedlPos = pIDRA->GetRedlinePos( rTextNode, USHRT_MAX );
136 183970 : if( pExtInp || USHRT_MAX != nRedlPos )
137 : {
138 2387 : const std::vector<sal_uInt16> *pArr = 0;
139 2387 : sal_Int32 nInputStt = 0;
140 2387 : if( pExtInp )
141 : {
142 0 : pArr = &pExtInp->GetAttrs();
143 0 : nInputStt = pExtInp->Start()->nContent.GetIndex();
144 0 : Seek( 0 );
145 : }
146 :
147 : pRedln = new SwRedlineItr( rTextNode, *pFnt, aAttrHandler, nRedlPos,
148 2387 : bShow, pArr, nInputStt );
149 :
150 2387 : if( pRedln->IsOn() )
151 1478 : ++nChgCnt;
152 : }
153 185270 : }
154 185270 : }
155 :
156 : // The Redline-Iterator
157 : // The following information/states exist in RedlineIterator:
158 : //
159 : // nFirst is the first index of RedlineTable, which overlaps with the paragraph.
160 : //
161 : // nAct is the currently active (if bOn is set) or the next possible index.
162 : // nStart and nEnd give you the borders of the object within the paragraph.
163 : //
164 : // If bOn is set, the font has been manipulated according to it.
165 : //
166 : // If nAct is set to COMPLETE_STRING (via Reset()), then currently no
167 : // Redline is active, nStart and nEnd are invalid.
168 2668 : SwRedlineItr::SwRedlineItr( const SwTextNode& rTextNd, SwFont& rFnt,
169 : SwAttrHandler& rAH, sal_Int32 nRed, bool bShw,
170 : const std::vector<sal_uInt16> *pArr,
171 : sal_Int32 nExtStart )
172 2668 : : rDoc( *rTextNd.GetDoc() ), rAttrHandler( rAH ), pSet( 0 ),
173 2668 : nNdIdx( rTextNd.GetIndex() ), nFirst( nRed ),
174 8004 : nAct( COMPLETE_STRING ), bOn( false ), bShow( bShw )
175 : {
176 2668 : if( pArr )
177 0 : pExt = new SwExtend( *pArr, nExtStart );
178 : else
179 2668 : pExt = NULL;
180 2668 : Seek (rFnt, 0, COMPLETE_STRING);
181 2668 : }
182 :
183 5336 : SwRedlineItr::~SwRedlineItr()
184 : {
185 2668 : Clear( NULL );
186 2668 : delete pSet;
187 2668 : delete pExt;
188 2668 : }
189 :
190 : // The return value of SwRedlineItr::Seek tells you if the current font
191 : // has been manipulated by leaving (-1) or accessing (+1) of a section
192 6495 : short SwRedlineItr::_Seek(SwFont& rFnt, sal_Int32 nNew, sal_Int32 nOld)
193 : {
194 6495 : short nRet = 0;
195 6495 : if( ExtOn() )
196 0 : return 0; // Abbreviation: if we're within an ExtendTextInputs
197 : // there can't be other changes of attributes (not even by redlining)
198 6495 : if( bShow )
199 : {
200 6495 : if( bOn )
201 : {
202 2386 : if( nNew >= nEnd )
203 : {
204 366 : --nRet;
205 366 : _Clear( &rFnt ); // We go behind the current section
206 366 : ++nAct; // and check the next one
207 : }
208 2020 : else if( nNew < nStart )
209 : {
210 0 : --nRet;
211 0 : _Clear( &rFnt ); // We go in front of the current section
212 0 : if( nAct > nFirst )
213 0 : nAct = nFirst; // the test has to run from the beginning
214 : else
215 0 : return nRet + EnterExtend( rFnt, nNew ); // There's none prior to us
216 : }
217 : else
218 2020 : return nRet + EnterExtend( rFnt, nNew ); // We stayed in the same section
219 : }
220 4475 : if( COMPLETE_STRING == nAct || nOld > nNew )
221 2775 : nAct = nFirst;
222 :
223 4475 : nStart = COMPLETE_STRING;
224 4475 : nEnd = COMPLETE_STRING;
225 :
226 4769 : for( ; nAct < (sal_Int32)rDoc.getIDocumentRedlineAccess().GetRedlineTable().size() ; ++nAct )
227 : {
228 4509 : rDoc.getIDocumentRedlineAccess().GetRedlineTable()[ nAct ]->CalcStartEnd( nNdIdx, nStart, nEnd );
229 :
230 4509 : if( nNew < nEnd )
231 : {
232 4215 : if( nNew >= nStart ) // der einzig moegliche Kandidat
233 : {
234 2956 : bOn = true;
235 2956 : const SwRangeRedline *pRed = rDoc.getIDocumentRedlineAccess().GetRedlineTable()[ nAct ];
236 :
237 2956 : if (pSet)
238 1107 : pSet->ClearItem();
239 : else
240 : {
241 : SwAttrPool& rPool =
242 1849 : const_cast<SwDoc&>(rDoc).GetAttrPool();
243 1849 : pSet = new SfxItemSet(rPool, RES_CHRATR_BEGIN, RES_CHRATR_END-1);
244 : }
245 :
246 2956 : if( 1 < pRed->GetStackCount() )
247 19 : FillHints( pRed->GetAuthor( 1 ), pRed->GetType( 1 ) );
248 2956 : FillHints( pRed->GetAuthor(), pRed->GetType() );
249 :
250 2956 : SfxWhichIter aIter( *pSet );
251 2956 : sal_uInt16 nWhich = aIter.FirstWhich();
252 138932 : while( nWhich )
253 : {
254 : const SfxPoolItem* pItem;
255 266040 : if( ( nWhich < RES_CHRATR_END ) &&
256 133020 : ( SfxItemState::SET == pSet->GetItemState( nWhich, true, &pItem ) ) )
257 : {
258 : SwTextAttr* pAttr = MakeRedlineTextAttr(
259 : const_cast<SwDoc&>(rDoc),
260 5301 : *const_cast<SfxPoolItem*>(pItem) );
261 5301 : pAttr->SetPriorityAttr( true );
262 5301 : m_Hints.push_back(pAttr);
263 5301 : rAttrHandler.PushAndChg( *pAttr, rFnt );
264 5301 : if( RES_CHRATR_COLOR == nWhich )
265 2123 : rFnt.SetNoCol( true );
266 : }
267 133020 : nWhich = aIter.NextWhich();
268 : }
269 :
270 2956 : ++nRet;
271 : }
272 4215 : break;
273 : }
274 294 : nStart = COMPLETE_STRING;
275 294 : nEnd = COMPLETE_STRING;
276 : }
277 : }
278 4475 : return nRet + EnterExtend( rFnt, nNew );
279 : }
280 :
281 2975 : void SwRedlineItr::FillHints( sal_uInt16 nAuthor, RedlineType_t eType )
282 : {
283 2975 : switch ( eType )
284 : {
285 : case nsRedlineType_t::REDLINE_INSERT:
286 496 : SW_MOD()->GetInsertAuthorAttr(nAuthor, *pSet);
287 496 : break;
288 : case nsRedlineType_t::REDLINE_DELETE:
289 1128 : SW_MOD()->GetDeletedAuthorAttr(nAuthor, *pSet);
290 1128 : break;
291 : case nsRedlineType_t::REDLINE_FORMAT:
292 : case nsRedlineType_t::REDLINE_FMTCOLL:
293 518 : SW_MOD()->GetFormatAuthorAttr(nAuthor, *pSet);
294 518 : break;
295 : default:
296 833 : break;
297 : }
298 2975 : }
299 :
300 606 : void SwRedlineItr::ChangeTextAttr( SwFont* pFnt, SwTextAttr &rHt, bool bChg )
301 : {
302 : OSL_ENSURE( IsOn(), "SwRedlineItr::ChangeTextAttr: Off?" );
303 :
304 606 : if( !bShow && !pExt )
305 606 : return;
306 :
307 606 : if( bChg )
308 : {
309 290 : if ( pExt && pExt->IsOn() )
310 0 : rAttrHandler.PushAndChg( rHt, *pExt->GetFont() );
311 : else
312 290 : rAttrHandler.PushAndChg( rHt, *pFnt );
313 : }
314 : else
315 : {
316 : OSL_ENSURE( ! pExt || ! pExt->IsOn(), "Pop of attribute during opened extension" );
317 316 : rAttrHandler.PopAndChg( rHt, *pFnt );
318 : }
319 : }
320 :
321 2956 : void SwRedlineItr::_Clear( SwFont* pFnt )
322 : {
323 : OSL_ENSURE( bOn, "SwRedlineItr::Clear: Off?" );
324 2956 : bOn = false;
325 11213 : while (!m_Hints.empty())
326 : {
327 5301 : SwTextAttr *pPos = m_Hints.front();
328 5301 : m_Hints.pop_front();
329 5301 : if( pFnt )
330 1695 : rAttrHandler.PopAndChg( *pPos, *pFnt );
331 : else
332 3606 : rAttrHandler.Pop( *pPos );
333 5301 : SwTextAttr::Destroy(pPos, const_cast<SwDoc&>(rDoc).GetAttrPool() );
334 : }
335 2956 : if( pFnt )
336 850 : pFnt->SetNoCol( false );
337 2956 : }
338 :
339 769 : sal_Int32 SwRedlineItr::_GetNextRedln( sal_Int32 nNext )
340 : {
341 769 : nNext = NextExtend( nNext );
342 769 : if( !bShow || COMPLETE_STRING == nFirst )
343 0 : return nNext;
344 769 : if( COMPLETE_STRING == nAct )
345 : {
346 0 : nAct = nFirst;
347 0 : rDoc.getIDocumentRedlineAccess().GetRedlineTable()[ nAct ]->CalcStartEnd( nNdIdx, nStart, nEnd );
348 : }
349 769 : if( bOn || !nStart )
350 : {
351 1346 : if( nEnd < nNext )
352 163 : nNext = nEnd;
353 : }
354 96 : else if( nStart < nNext )
355 47 : nNext = nStart;
356 769 : return nNext;
357 : }
358 :
359 0 : bool SwRedlineItr::_ChkSpecialUnderline() const
360 : {
361 : // If the underlining or the escapement is caused by redlining,
362 : // we always apply the SpecialUnderlining, i.e. the underlining
363 : // below the base line
364 0 : for (size_t i = 0; i < m_Hints.size(); ++i)
365 : {
366 0 : const sal_uInt16 nWhich = m_Hints[i]->Which();
367 0 : if( RES_CHRATR_UNDERLINE == nWhich ||
368 : RES_CHRATR_ESCAPEMENT == nWhich )
369 0 : return true;
370 : }
371 0 : return false;
372 : }
373 :
374 554 : bool SwRedlineItr::CheckLine( sal_Int32 nChkStart, sal_Int32 nChkEnd )
375 : {
376 554 : if( nFirst == COMPLETE_STRING )
377 0 : return false;
378 554 : if( nChkEnd == nChkStart ) // empty lines look one char further
379 55 : ++nChkEnd;
380 554 : sal_Int32 nOldStart = nStart;
381 554 : sal_Int32 nOldEnd = nEnd;
382 554 : sal_Int32 nOldAct = nAct;
383 554 : bool bRet = false;
384 :
385 649 : for( nAct = nFirst; nAct < (sal_Int32)rDoc.getIDocumentRedlineAccess().GetRedlineTable().size() ; ++nAct )
386 : {
387 649 : rDoc.getIDocumentRedlineAccess().GetRedlineTable()[ nAct ]->CalcStartEnd( nNdIdx, nStart, nEnd );
388 649 : if( nChkEnd < nStart )
389 9 : break;
390 640 : if( nChkStart <= nEnd && ( nChkEnd > nStart || COMPLETE_STRING == nEnd ) )
391 : {
392 545 : bRet = true;
393 545 : break;
394 : }
395 : }
396 :
397 554 : nStart = nOldStart;
398 554 : nEnd = nOldEnd;
399 554 : nAct = nOldAct;
400 554 : return bRet;
401 : }
402 :
403 0 : void SwExtend::ActualizeFont( SwFont &rFnt, sal_uInt16 nAttr )
404 : {
405 0 : if ( nAttr & EXTTEXTINPUT_ATTR_UNDERLINE )
406 0 : rFnt.SetUnderline( UNDERLINE_SINGLE );
407 0 : else if ( nAttr & EXTTEXTINPUT_ATTR_BOLDUNDERLINE )
408 0 : rFnt.SetUnderline( UNDERLINE_BOLD );
409 0 : else if ( nAttr & EXTTEXTINPUT_ATTR_DOTTEDUNDERLINE )
410 0 : rFnt.SetUnderline( UNDERLINE_DOTTED );
411 0 : else if ( nAttr & EXTTEXTINPUT_ATTR_DASHDOTUNDERLINE )
412 0 : rFnt.SetUnderline( UNDERLINE_DOTTED );
413 :
414 0 : if ( nAttr & EXTTEXTINPUT_ATTR_REDTEXT )
415 0 : rFnt.SetColor( Color( COL_RED ) );
416 :
417 0 : if ( nAttr & EXTTEXTINPUT_ATTR_HIGHLIGHT )
418 : {
419 0 : const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
420 0 : rFnt.SetColor( rStyleSettings.GetHighlightTextColor() );
421 0 : rFnt.SetBackColor( new Color( rStyleSettings.GetHighlightColor() ) );
422 : }
423 0 : if ( nAttr & EXTTEXTINPUT_ATTR_GRAYWAVELINE )
424 0 : rFnt.SetGreyWave( true );
425 0 : }
426 :
427 0 : short SwExtend::Enter(SwFont& rFnt, sal_Int32 nNew)
428 : {
429 : OSL_ENSURE( !Inside(), "SwExtend: Enter without Leave" );
430 : OSL_ENSURE( !pFnt, "SwExtend: Enter with Font" );
431 0 : nPos = nNew;
432 0 : if( Inside() )
433 : {
434 0 : pFnt = new SwFont( rFnt );
435 0 : ActualizeFont( rFnt, rArr[ nPos - nStart ] );
436 0 : return 1;
437 : }
438 0 : return 0;
439 : }
440 :
441 0 : bool SwExtend::_Leave(SwFont& rFnt, sal_Int32 nNew)
442 : {
443 : OSL_ENSURE( Inside(), "SwExtend: Leave without Enter" );
444 0 : const sal_uInt16 nOldAttr = rArr[ nPos - nStart ];
445 0 : nPos = nNew;
446 0 : if( Inside() )
447 : { // We stayed within the ExtendText-section
448 0 : const sal_uInt16 nAttr = rArr[ nPos - nStart ];
449 0 : if( nOldAttr != nAttr ) // Is there an (inner) change of attributes?
450 : {
451 0 : rFnt = *pFnt;
452 0 : ActualizeFont( rFnt, nAttr );
453 : }
454 : }
455 : else
456 : {
457 0 : rFnt = *pFnt;
458 0 : delete pFnt;
459 0 : pFnt = NULL;
460 0 : return true;
461 : }
462 0 : return false;
463 : }
464 :
465 0 : sal_Int32 SwExtend::Next( sal_Int32 nNext )
466 : {
467 0 : if( nPos < nStart )
468 : {
469 0 : if( nNext > nStart )
470 0 : nNext = nStart;
471 : }
472 0 : else if( nPos < nEnd )
473 : {
474 0 : sal_Int32 nIdx = nPos - nStart;
475 0 : const sal_uInt16 nAttr = rArr[ nIdx ];
476 0 : while( static_cast<size_t>(++nIdx) < rArr.size() && nAttr == rArr[ nIdx ] )
477 : ; //nothing
478 0 : nIdx = nIdx + nStart;
479 0 : if( nNext > nIdx )
480 0 : nNext = nIdx;
481 : }
482 0 : return nNext;
483 177 : }
484 :
485 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|