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 318980 : void SwAttrIter::CtorInitAttrIter( SwTxtNode& rTxtNode, SwScriptInfo& rScrInf, SwTxtFrm* pFrm )
47 : {
48 : // during HTML-Import it can happen, that no layout exists
49 318980 : SwRootFrm* pRootFrm = rTxtNode.getIDocumentLayoutAccess()->GetCurrentLayout();
50 318980 : pShell = pRootFrm ? pRootFrm->GetCurrShell() : 0;
51 :
52 318980 : pScriptInfo = &rScrInf;
53 :
54 : // attributes set at the whole paragraph
55 318980 : pAttrSet = rTxtNode.GetpSwAttrSet();
56 : // attribute array
57 318980 : pHints = rTxtNode.GetpSwpHints();
58 :
59 : // Build a font matching the default paragraph style:
60 318980 : SwFontAccess aFontAccess( &rTxtNode.GetAnyFmtColl(), pShell );
61 318980 : delete pFnt;
62 318980 : pFnt = new SwFont( aFontAccess.Get()->GetFont() );
63 :
64 : // set font to vertical if frame layout is vertical
65 318980 : bool bVertLayout = false;
66 318980 : bool bRTL = false;
67 318980 : if ( pFrm )
68 : {
69 318182 : if ( pFrm->IsVertical() )
70 : {
71 4 : bVertLayout = true;
72 4 : pFnt->SetVertical( pFnt->GetOrientation(), true );
73 : }
74 318182 : 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 318980 : *rTxtNode.getIDocumentSettingAccess(), pShell, *pFnt, bVertLayout );
84 :
85 318980 : 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 318980 : if ( pScriptInfo->GetInvalidityA() != COMPLETE_STRING )
90 84347 : pScriptInfo->InitScriptInfo( rTxtNode, bRTL );
91 :
92 318980 : if ( g_pBreakIt->GetBreakIter().is() )
93 : {
94 318980 : pFnt->SetActual( SwScriptInfo::WhichFont( 0, 0, pScriptInfo ) );
95 :
96 318980 : sal_Int32 nChg = 0;
97 318980 : size_t nCnt = 0;
98 :
99 319110 : do
100 : {
101 319110 : if ( nCnt >= pScriptInfo->CountScriptChg() )
102 0 : break;
103 319110 : nChg = pScriptInfo->GetScriptChg( nCnt );
104 319110 : int nTmp = SW_SCRIPTS;
105 319110 : switch ( pScriptInfo->GetScriptType( nCnt++ ) ) {
106 : case i18n::ScriptType::ASIAN :
107 528 : if( !aMagicNo[SW_CJK] ) nTmp = SW_CJK; break;
108 : case i18n::ScriptType::COMPLEX :
109 184 : if( !aMagicNo[SW_CTL] ) nTmp = SW_CTL; break;
110 : default:
111 318398 : if( !aMagicNo[SW_LATIN ] ) nTmp = SW_LATIN;
112 : }
113 319110 : if( nTmp < SW_SCRIPTS )
114 : {
115 319074 : pFnt->ChkMagic( pShell, nTmp );
116 319074 : pFnt->GetMagic( aMagicNo[ nTmp ], aFntIdx[ nTmp ], nTmp );
117 : }
118 319110 : } while (nChg < rTxtNode.GetTxt().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 318980 : nStartIndex = nEndIndex = nPos = nChgCnt = 0;
127 318980 : nPropFont = 0;
128 318980 : SwDoc* pDoc = rTxtNode.GetDoc();
129 318980 : const IDocumentRedlineAccess* pIDRA = rTxtNode.getIDocumentRedlineAccess();
130 :
131 318980 : const SwExtTextInput* pExtInp = pDoc->GetExtTextInput( rTxtNode );
132 318980 : const bool bShow = IDocumentRedlineAccess::IsShowChanges( pIDRA->GetRedlineMode() );
133 318980 : if( pExtInp || bShow )
134 : {
135 318580 : const sal_uInt16 nRedlPos = pIDRA->GetRedlinePos( rTxtNode, USHRT_MAX );
136 318580 : if( pExtInp || USHRT_MAX != nRedlPos )
137 : {
138 4250 : const std::vector<sal_uInt16> *pArr = 0;
139 4250 : sal_Int32 nInputStt = 0;
140 4250 : 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( rTxtNode, *pFnt, aAttrHandler, nRedlPos,
148 4250 : bShow, pArr, nInputStt );
149 :
150 4250 : if( pRedln->IsOn() )
151 2768 : ++nChgCnt;
152 : }
153 318980 : }
154 318980 : }
155 :
156 : // The Redline-Iterator
157 : // The following information/states exist in RedlineIterator:
158 : //
159 : // nFirst is the first index of RedlineTbl, 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 4812 : SwRedlineItr::SwRedlineItr( const SwTxtNode& rTxtNd, SwFont& rFnt,
169 : SwAttrHandler& rAH, sal_Int32 nRed, bool bShw,
170 : const std::vector<sal_uInt16> *pArr,
171 : sal_Int32 nExtStart )
172 4812 : : rDoc( *rTxtNd.GetDoc() ), rAttrHandler( rAH ), pSet( 0 ),
173 4812 : nNdIdx( rTxtNd.GetIndex() ), nFirst( nRed ),
174 14436 : nAct( COMPLETE_STRING ), bOn( false ), bShow( bShw )
175 : {
176 4812 : if( pArr )
177 0 : pExt = new SwExtend( *pArr, nExtStart );
178 : else
179 4812 : pExt = NULL;
180 4812 : Seek (rFnt, 0, COMPLETE_STRING);
181 4812 : }
182 :
183 9624 : SwRedlineItr::~SwRedlineItr()
184 : {
185 4812 : Clear( NULL );
186 4812 : delete pSet;
187 4812 : delete pExt;
188 4812 : }
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 10853 : short SwRedlineItr::_Seek(SwFont& rFnt, sal_Int32 nNew, sal_Int32 nOld)
193 : {
194 10853 : short nRet = 0;
195 10853 : 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 10853 : if( bShow )
199 : {
200 10853 : if( bOn )
201 : {
202 3786 : if( nNew >= nEnd )
203 : {
204 620 : --nRet;
205 620 : _Clear( &rFnt ); // We go behind the current section
206 620 : ++nAct; // and check the next one
207 : }
208 3166 : 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 3166 : return nRet + EnterExtend( rFnt, nNew ); // We stayed in the same section
219 : }
220 7687 : if( COMPLETE_STRING == nAct || nOld > nNew )
221 5010 : nAct = nFirst;
222 :
223 7687 : nStart = COMPLETE_STRING;
224 7687 : nEnd = COMPLETE_STRING;
225 :
226 8339 : for( ; nAct < (sal_Int32)rDoc.getIDocumentRedlineAccess().GetRedlineTbl().size() ; ++nAct )
227 : {
228 7683 : rDoc.getIDocumentRedlineAccess().GetRedlineTbl()[ nAct ]->CalcStartEnd( nNdIdx, nStart, nEnd );
229 :
230 7683 : if( nNew < nEnd )
231 : {
232 7031 : if( nNew >= nStart ) // der einzig moegliche Kandidat
233 : {
234 5392 : bOn = true;
235 5392 : const SwRangeRedline *pRed = rDoc.getIDocumentRedlineAccess().GetRedlineTbl()[ nAct ];
236 :
237 5392 : if (pSet)
238 2040 : pSet->ClearItem();
239 : else
240 : {
241 : SwAttrPool& rPool =
242 3352 : const_cast<SwDoc&>(rDoc).GetAttrPool();
243 3352 : pSet = new SfxItemSet(rPool, RES_CHRATR_BEGIN, RES_CHRATR_END-1);
244 : }
245 :
246 5392 : if( 1 < pRed->GetStackCount() )
247 38 : FillHints( pRed->GetAuthor( 1 ), pRed->GetType( 1 ) );
248 5392 : FillHints( pRed->GetAuthor(), pRed->GetType() );
249 :
250 5392 : SfxWhichIter aIter( *pSet );
251 5392 : sal_uInt16 nWhich = aIter.FirstWhich();
252 253424 : while( nWhich )
253 : {
254 : const SfxPoolItem* pItem;
255 485280 : if( ( nWhich < RES_CHRATR_END ) &&
256 242640 : ( SfxItemState::SET == pSet->GetItemState( nWhich, true, &pItem ) ) )
257 : {
258 : SwTxtAttr* pAttr = MakeRedlineTxtAttr(
259 : const_cast<SwDoc&>(rDoc),
260 9850 : *const_cast<SfxPoolItem*>(pItem) );
261 9850 : pAttr->SetPriorityAttr( true );
262 9850 : m_Hints.push_back(pAttr);
263 9850 : rAttrHandler.PushAndChg( *pAttr, rFnt );
264 9850 : if( RES_CHRATR_COLOR == nWhich )
265 3870 : rFnt.SetNoCol( true );
266 : }
267 242640 : nWhich = aIter.NextWhich();
268 : }
269 :
270 5392 : ++nRet;
271 : }
272 7031 : break;
273 : }
274 652 : nStart = COMPLETE_STRING;
275 652 : nEnd = COMPLETE_STRING;
276 : }
277 : }
278 7687 : return nRet + EnterExtend( rFnt, nNew );
279 : }
280 :
281 5430 : void SwRedlineItr::FillHints( sal_uInt16 nAuthor, RedlineType_t eType )
282 : {
283 5430 : switch ( eType )
284 : {
285 : case nsRedlineType_t::REDLINE_INSERT:
286 722 : SW_MOD()->GetInsertAuthorAttr(nAuthor, *pSet);
287 722 : break;
288 : case nsRedlineType_t::REDLINE_DELETE:
289 2150 : SW_MOD()->GetDeletedAuthorAttr(nAuthor, *pSet);
290 2150 : break;
291 : case nsRedlineType_t::REDLINE_FORMAT:
292 : case nsRedlineType_t::REDLINE_FMTCOLL:
293 1036 : SW_MOD()->GetFormatAuthorAttr(nAuthor, *pSet);
294 1036 : break;
295 : default:
296 1522 : break;
297 : }
298 5430 : }
299 :
300 1106 : void SwRedlineItr::ChangeTxtAttr( SwFont* pFnt, SwTxtAttr &rHt, bool bChg )
301 : {
302 : OSL_ENSURE( IsOn(), "SwRedlineItr::ChangeTxtAttr: Off?" );
303 :
304 1106 : if( !bShow && !pExt )
305 1106 : return;
306 :
307 1106 : if( bChg )
308 : {
309 526 : if ( pExt && pExt->IsOn() )
310 0 : rAttrHandler.PushAndChg( rHt, *pExt->GetFont() );
311 : else
312 526 : rAttrHandler.PushAndChg( rHt, *pFnt );
313 : }
314 : else
315 : {
316 : OSL_ENSURE( ! pExt || ! pExt->IsOn(), "Pop of attribute during opened extension" );
317 580 : rAttrHandler.PopAndChg( rHt, *pFnt );
318 : }
319 : }
320 :
321 5392 : void SwRedlineItr::_Clear( SwFont* pFnt )
322 : {
323 : OSL_ENSURE( bOn, "SwRedlineItr::Clear: Off?" );
324 5392 : bOn = false;
325 20634 : while (!m_Hints.empty())
326 : {
327 9850 : SwTxtAttr *pPos = m_Hints.front();
328 9850 : m_Hints.pop_front();
329 9850 : if( pFnt )
330 3058 : rAttrHandler.PopAndChg( *pPos, *pFnt );
331 : else
332 6792 : rAttrHandler.Pop( *pPos );
333 9850 : SwTxtAttr::Destroy(pPos, const_cast<SwDoc&>(rDoc).GetAttrPool() );
334 : }
335 5392 : if( pFnt )
336 1526 : pFnt->SetNoCol( false );
337 5392 : }
338 :
339 1307 : sal_Int32 SwRedlineItr::_GetNextRedln( sal_Int32 nNext )
340 : {
341 1307 : nNext = NextExtend( nNext );
342 1307 : if( !bShow || COMPLETE_STRING == nFirst )
343 0 : return nNext;
344 1307 : if( COMPLETE_STRING == nAct )
345 : {
346 0 : nAct = nFirst;
347 0 : rDoc.getIDocumentRedlineAccess().GetRedlineTbl()[ nAct ]->CalcStartEnd( nNdIdx, nStart, nEnd );
348 : }
349 1307 : if( bOn || !nStart )
350 : {
351 2388 : if( nEnd < nNext )
352 200 : nNext = nEnd;
353 : }
354 113 : else if( nStart < nNext )
355 28 : nNext = nStart;
356 1307 : 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 981 : bool SwRedlineItr::CheckLine( sal_Int32 nChkStart, sal_Int32 nChkEnd )
375 : {
376 981 : if( nFirst == COMPLETE_STRING )
377 0 : return false;
378 981 : if( nChkEnd == nChkStart ) // empty lines look one char further
379 110 : ++nChkEnd;
380 981 : sal_Int32 nOldStart = nStart;
381 981 : sal_Int32 nOldEnd = nEnd;
382 981 : sal_Int32 nOldAct = nAct;
383 981 : bool bRet = false;
384 :
385 1159 : for( nAct = nFirst; nAct < (sal_Int32)rDoc.getIDocumentRedlineAccess().GetRedlineTbl().size() ; ++nAct )
386 : {
387 1159 : rDoc.getIDocumentRedlineAccess().GetRedlineTbl()[ nAct ]->CalcStartEnd( nNdIdx, nStart, nEnd );
388 1159 : if( nChkEnd < nStart )
389 2 : break;
390 1157 : if( nChkStart <= nEnd && ( nChkEnd > nStart || COMPLETE_STRING == nEnd ) )
391 : {
392 979 : bRet = true;
393 979 : break;
394 : }
395 : }
396 :
397 981 : nStart = nOldStart;
398 981 : nEnd = nOldEnd;
399 981 : nAct = nOldAct;
400 981 : 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 270 : }
484 :
485 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|