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 <vcl/wrkwin.hxx>
21 : #include <vcl/dialog.hxx>
22 : #include <vcl/msgbox.hxx>
23 : #include <vcl/svapp.hxx>
24 : #include <impedit.hxx>
25 : #include <editeng/editeng.hxx>
26 : #include <editdbg.hxx>
27 : #include <svl/smplhint.hxx>
28 : #include <editeng/lrspitem.hxx>
29 :
30 20115 : void ImpEditEngine::SetStyleSheetPool( SfxStyleSheetPool* pSPool )
31 : {
32 20115 : if ( pStylePool != pSPool )
33 : {
34 2622 : pStylePool = pSPool;
35 : }
36 20115 : }
37 :
38 0 : const SfxStyleSheet* ImpEditEngine::GetStyleSheet( sal_Int32 nPara ) const
39 : {
40 0 : const ContentNode* pNode = aEditDoc.GetObject( nPara );
41 0 : return pNode ? pNode->GetContentAttribs().GetStyleSheet() : NULL;
42 : }
43 :
44 9300 : SfxStyleSheet* ImpEditEngine::GetStyleSheet( sal_Int32 nPara )
45 : {
46 9300 : ContentNode* pNode = aEditDoc.GetObject( nPara );
47 9300 : return pNode ? pNode->GetContentAttribs().GetStyleSheet() : NULL;
48 : }
49 :
50 0 : void ImpEditEngine::SetStyleSheet( EditSelection aSel, SfxStyleSheet* pStyle )
51 : {
52 0 : aSel.Adjust( aEditDoc );
53 :
54 0 : sal_Int32 nStartPara = aEditDoc.GetPos( aSel.Min().GetNode() );
55 0 : sal_Int32 nEndPara = aEditDoc.GetPos( aSel.Max().GetNode() );
56 :
57 0 : sal_Bool _bUpdate = GetUpdateMode();
58 0 : SetUpdateMode( false );
59 :
60 0 : for ( sal_Int32 n = nStartPara; n <= nEndPara; n++ )
61 0 : SetStyleSheet( n, pStyle );
62 :
63 0 : SetUpdateMode( _bUpdate, 0 );
64 0 : }
65 :
66 35424 : void ImpEditEngine::SetStyleSheet( sal_Int32 nPara, SfxStyleSheet* pStyle )
67 : {
68 : DBG_ASSERT( GetStyleSheetPool() || !pStyle, "SetStyleSheet: No StyleSheetPool registered!" );
69 35424 : ContentNode* pNode = aEditDoc.GetObject( nPara );
70 35424 : SfxStyleSheet* pCurStyle = pNode->GetStyleSheet();
71 35424 : if ( pStyle != pCurStyle )
72 : {
73 28569 : if ( IsUndoEnabled() && !IsInUndo() && aStatus.DoUndoAttribs() )
74 : {
75 3056 : OUString aPrevStyleName;
76 3056 : if ( pCurStyle )
77 1976 : aPrevStyleName = pCurStyle->GetName();
78 :
79 6112 : OUString aNewStyleName;
80 3056 : if ( pStyle )
81 3056 : aNewStyleName = pStyle->GetName();
82 :
83 : InsertUndo(
84 3056 : new EditUndoSetStyleSheet(pEditEngine, aEditDoc.GetPos( pNode ),
85 1976 : aPrevStyleName, pCurStyle ? pCurStyle->GetFamily() : SFX_STYLE_FAMILY_PARA,
86 3056 : aNewStyleName, pStyle ? pStyle->GetFamily() : SFX_STYLE_FAMILY_PARA,
87 11144 : pNode->GetContentAttribs().GetItems() ) );
88 : }
89 28569 : if ( pCurStyle )
90 2100 : EndListening( *pCurStyle, false );
91 28569 : pNode->SetStyleSheet( pStyle, aStatus.UseCharAttribs() );
92 28569 : if ( pStyle )
93 28569 : StartListening( *pStyle, false );
94 28569 : ParaAttribsChanged( pNode );
95 : }
96 35424 : FormatAndUpdate();
97 35424 : }
98 :
99 0 : void ImpEditEngine::UpdateParagraphsWithStyleSheet( SfxStyleSheet* pStyle )
100 : {
101 0 : SvxFont aFontFromStyle;
102 0 : CreateFont( aFontFromStyle, pStyle->GetItemSet() );
103 :
104 0 : sal_Bool bUsed = sal_False;
105 0 : for ( sal_Int32 nNode = 0; nNode < aEditDoc.Count(); nNode++ )
106 : {
107 0 : ContentNode* pNode = aEditDoc.GetObject( nNode );
108 0 : if ( pNode->GetStyleSheet() == pStyle )
109 : {
110 0 : bUsed = sal_True;
111 0 : if ( aStatus.UseCharAttribs() )
112 0 : pNode->SetStyleSheet( pStyle, aFontFromStyle );
113 : else
114 0 : pNode->SetStyleSheet( pStyle, sal_False );
115 :
116 0 : ParaAttribsChanged( pNode );
117 : }
118 : }
119 0 : if ( bUsed )
120 : {
121 0 : GetEditEnginePtr()->StyleSheetChanged( pStyle );
122 0 : FormatAndUpdate();
123 0 : }
124 0 : }
125 :
126 0 : void ImpEditEngine::RemoveStyleFromParagraphs( SfxStyleSheet* pStyle )
127 : {
128 0 : for ( sal_Int32 nNode = 0; nNode < aEditDoc.Count(); nNode++ )
129 : {
130 0 : ContentNode* pNode = aEditDoc.GetObject(nNode);
131 0 : if ( pNode->GetStyleSheet() == pStyle )
132 : {
133 0 : pNode->SetStyleSheet( NULL );
134 0 : ParaAttribsChanged( pNode );
135 : }
136 : }
137 0 : FormatAndUpdate();
138 0 : }
139 :
140 0 : void ImpEditEngine::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
141 : {
142 : // So that not a lot of unnecessary formatting is done when destructing:
143 0 : if ( !bDowning )
144 : {
145 :
146 0 : SfxStyleSheet* pStyle = NULL;
147 0 : sal_uLong nId = 0;
148 :
149 0 : if ( rHint.ISA( SfxStyleSheetHint ) )
150 : {
151 0 : const SfxStyleSheetHint& rH = (const SfxStyleSheetHint&) rHint;
152 : DBG_ASSERT( rH.GetStyleSheet()->ISA( SfxStyleSheet ), "No SfxStyleSheet!" );
153 0 : pStyle = (SfxStyleSheet*) rH.GetStyleSheet();
154 0 : nId = rH.GetHint();
155 : }
156 0 : else if ( ( rHint.Type() == TYPE(SfxSimpleHint ) ) && ( rBC.ISA( SfxStyleSheet ) ) )
157 : {
158 0 : pStyle = (SfxStyleSheet*)&rBC;
159 0 : nId = ((SfxSimpleHint&)rHint).GetId();
160 : }
161 :
162 0 : if ( pStyle )
163 : {
164 0 : if ( ( nId == SFX_HINT_DYING ) ||
165 0 : ( nId == SFX_STYLESHEET_INDESTRUCTION ) ||
166 : ( nId == SFX_STYLESHEET_ERASED ) )
167 : {
168 0 : RemoveStyleFromParagraphs( pStyle );
169 : }
170 0 : else if ( ( nId == SFX_HINT_DATACHANGED ) ||
171 : ( nId == SFX_STYLESHEET_MODIFIED ) )
172 : {
173 0 : UpdateParagraphsWithStyleSheet( pStyle );
174 : }
175 : }
176 : }
177 0 : }
178 :
179 4449 : EditUndoSetAttribs* ImpEditEngine::CreateAttribUndo( EditSelection aSel, const SfxItemSet& rSet )
180 : {
181 : DBG_ASSERT( !aSel.DbgIsBuggy( aEditDoc ), "CreateAttribUndo: Incorrect selection ");
182 4449 : aSel.Adjust( aEditDoc );
183 :
184 4449 : ESelection aESel( CreateESel( aSel ) );
185 :
186 4449 : sal_Int32 nStartNode = aEditDoc.GetPos( aSel.Min().GetNode() );
187 4449 : sal_Int32 nEndNode = aEditDoc.GetPos( aSel.Max().GetNode() );
188 :
189 : DBG_ASSERT( nStartNode <= nEndNode, "CreateAttribUndo: Start > End ?!" );
190 :
191 4449 : EditUndoSetAttribs* pUndo = NULL;
192 4449 : if ( rSet.GetPool() != &aEditDoc.GetItemPool() )
193 : {
194 0 : SfxItemSet aTmpSet( GetEmptyItemSet() );
195 0 : aTmpSet.Put( rSet );
196 0 : pUndo = new EditUndoSetAttribs(pEditEngine, aESel, aTmpSet);
197 : }
198 : else
199 : {
200 4449 : pUndo = new EditUndoSetAttribs(pEditEngine, aESel, rSet);
201 : }
202 :
203 4449 : SfxItemPool* pPool = pUndo->GetNewAttribs().GetPool();
204 :
205 9267 : for ( sal_Int32 nPara = nStartNode; nPara <= nEndNode; nPara++ )
206 : {
207 4818 : ContentNode* pNode = aEditDoc.GetObject( nPara );
208 : DBG_ASSERT( aEditDoc.GetObject( nPara ), "Node not found: CreateAttribUndo" );
209 4818 : ContentAttribsInfo* pInf = new ContentAttribsInfo( pNode->GetContentAttribs().GetItems() );
210 4818 : pUndo->AppendContentInfo(pInf);
211 :
212 40081 : for ( sal_uInt16 nAttr = 0; nAttr < pNode->GetCharAttribs().Count(); nAttr++ )
213 : {
214 35263 : const EditCharAttrib& rAttr = pNode->GetCharAttribs().GetAttribs()[nAttr];
215 35263 : if (rAttr.GetLen())
216 : {
217 27844 : EditCharAttrib* pNew = MakeCharAttrib(*pPool, *rAttr.GetItem(), rAttr.GetStart(), rAttr.GetEnd());
218 27844 : pInf->AppendCharAttrib(pNew);
219 : }
220 : }
221 : }
222 4449 : return pUndo;
223 : }
224 :
225 0 : void ImpEditEngine::UndoActionStart( sal_uInt16 nId, const ESelection& aSel )
226 : {
227 0 : if ( IsUndoEnabled() && !IsInUndo() )
228 : {
229 0 : GetUndoManager().EnterListAction( GetEditEnginePtr()->GetUndoComment( nId ), OUString(), nId );
230 : DBG_ASSERT( !pUndoMarkSelection, "UndoAction SelectionMarker?" );
231 0 : pUndoMarkSelection = new ESelection( aSel );
232 : }
233 0 : }
234 :
235 121259 : void ImpEditEngine::UndoActionStart( sal_uInt16 nId )
236 : {
237 121259 : if ( IsUndoEnabled() && !IsInUndo() )
238 : {
239 110389 : GetUndoManager().EnterListAction( GetEditEnginePtr()->GetUndoComment( nId ), OUString(), nId );
240 : DBG_ASSERT( !pUndoMarkSelection, "UndoAction SelectionMarker?" );
241 : }
242 121259 : }
243 :
244 121259 : void ImpEditEngine::UndoActionEnd( sal_uInt16 )
245 : {
246 121259 : if ( IsUndoEnabled() && !IsInUndo() )
247 : {
248 110389 : GetUndoManager().LeaveListAction();
249 110389 : delete pUndoMarkSelection;
250 110389 : pUndoMarkSelection = NULL;
251 : }
252 121259 : }
253 :
254 49281 : void ImpEditEngine::InsertUndo( EditUndo* pUndo, bool bTryMerge )
255 : {
256 : DBG_ASSERT( !IsInUndo(), "InsertUndo in Undomodus!" );
257 49281 : if ( pUndoMarkSelection )
258 : {
259 0 : EditUndoMarkSelection* pU = new EditUndoMarkSelection(pEditEngine, *pUndoMarkSelection);
260 0 : GetUndoManager().AddUndoAction( pU, false );
261 0 : delete pUndoMarkSelection;
262 0 : pUndoMarkSelection = NULL;
263 : }
264 49281 : GetUndoManager().AddUndoAction( pUndo, bTryMerge );
265 :
266 49281 : mbLastTryMerge = bTryMerge;
267 49281 : }
268 :
269 1550305 : void ImpEditEngine::ResetUndoManager()
270 : {
271 1550305 : if ( HasUndoManager() )
272 1486528 : GetUndoManager().Clear();
273 1550305 : }
274 :
275 2033688 : void ImpEditEngine::EnableUndo( bool bEnable )
276 : {
277 : // When switching the mode Delete list:
278 2033688 : if ( bEnable != IsUndoEnabled() )
279 1050879 : ResetUndoManager();
280 :
281 2033688 : bUndoEnabled = bEnable;
282 2033688 : }
283 :
284 0 : sal_Bool ImpEditEngine::Undo( EditView* pView )
285 : {
286 0 : if ( HasUndoManager() && GetUndoManager().GetUndoActionCount() )
287 : {
288 0 : SetActiveView( pView );
289 0 : GetUndoManager().Undo();
290 0 : return sal_True;
291 : }
292 0 : return sal_False;
293 : }
294 :
295 0 : sal_Bool ImpEditEngine::Redo( EditView* pView )
296 : {
297 0 : if ( HasUndoManager() && GetUndoManager().GetRedoActionCount() )
298 : {
299 0 : SetActiveView( pView );
300 0 : GetUndoManager().Redo();
301 0 : return sal_True;
302 : }
303 0 : return sal_False;
304 : }
305 :
306 2079 : SfxItemSet ImpEditEngine::GetAttribs( EditSelection aSel, EditEngineAttribs nOnlyHardAttrib )
307 : {
308 :
309 2079 : aSel.Adjust( aEditDoc );
310 :
311 2079 : SfxItemSet aCurSet( GetEmptyItemSet() );
312 :
313 2079 : sal_Int32 nStartNode = aEditDoc.GetPos( aSel.Min().GetNode() );
314 2079 : sal_Int32 nEndNode = aEditDoc.GetPos( aSel.Max().GetNode() );
315 :
316 : // iterate over the paragraphs ...
317 4653 : for ( sal_Int32 nNode = nStartNode; nNode <= nEndNode; nNode++ )
318 : {
319 2574 : ContentNode* pNode = aEditDoc.GetObject( nNode );
320 : DBG_ASSERT( aEditDoc.GetObject( nNode ), "Node not found: GetAttrib" );
321 :
322 2574 : const sal_Int32 nStartPos = nNode==nStartNode ? aSel.Min().GetIndex() : 0;
323 2574 : const sal_Int32 nEndPos = nNode==nEndNode ? aSel.Max().GetIndex() : pNode->Len(); // Can also be == nStart!
324 :
325 : // Problem: Templates ....
326 : // => Other way:
327 : // 1) Hard character attributes, as usual ...
328 : // 2) Examine Style and paragraph attributes only when OFF ...
329 :
330 : // First the very hard formatting ...
331 2574 : aEditDoc.FindAttribs( pNode, nStartPos, nEndPos, aCurSet );
332 :
333 2574 : if( nOnlyHardAttrib != EditEngineAttribs_OnlyHard )
334 : {
335 : // and then paragraph formatting and template...
336 120513 : for ( sal_uInt16 nWhich = EE_ITEMS_START; nWhich <= EE_CHAR_END; nWhich++)
337 : {
338 118150 : if ( aCurSet.GetItemState( nWhich ) == SFX_ITEM_OFF )
339 : {
340 86905 : if ( nOnlyHardAttrib == EditEngineAttribs_All )
341 : {
342 86905 : const SfxPoolItem& rItem = pNode->GetContentAttribs().GetItem( nWhich );
343 86905 : aCurSet.Put( rItem );
344 : }
345 0 : else if ( pNode->GetContentAttribs().GetItems().GetItemState( nWhich ) == SFX_ITEM_ON )
346 : {
347 0 : const SfxPoolItem& rItem = pNode->GetContentAttribs().GetItems().Get( nWhich );
348 0 : aCurSet.Put( rItem );
349 : }
350 : }
351 31245 : else if ( aCurSet.GetItemState( nWhich ) == SFX_ITEM_ON )
352 : {
353 30720 : const SfxPoolItem* pItem = NULL;
354 30720 : if ( nOnlyHardAttrib == EditEngineAttribs_All )
355 : {
356 30720 : pItem = &pNode->GetContentAttribs().GetItem( nWhich );
357 : }
358 0 : else if ( pNode->GetContentAttribs().GetItems().GetItemState( nWhich ) == SFX_ITEM_ON )
359 : {
360 0 : pItem = &pNode->GetContentAttribs().GetItems().Get( nWhich );
361 : }
362 : // pItem can only be NULL when nOnlyHardAttrib...
363 30720 : if ( !pItem || ( *pItem != aCurSet.Get( nWhich ) ) )
364 : {
365 : // Problem: When Paragraph style with for example font,
366 : // but the Font is hard and completely different,
367 : // wrong in selection if invalidated....
368 : // => better not invalidate, instead CHANGE!
369 : // It would be better to fill each paragraph with
370 : // a itemset and compare this in large.
371 13772 : if ( nWhich <= EE_PARA_END )
372 6 : aCurSet.InvalidateItem( nWhich );
373 : }
374 : }
375 : }
376 : }
377 : }
378 :
379 : // fill empty slots with defaults ...
380 2079 : if ( nOnlyHardAttrib == EditEngineAttribs_All )
381 : {
382 95268 : for ( sal_uInt16 nWhich = EE_ITEMS_START; nWhich <= EE_CHAR_END; nWhich++ )
383 : {
384 93400 : if ( aCurSet.GetItemState( nWhich ) == SFX_ITEM_OFF )
385 : {
386 0 : aCurSet.Put( aEditDoc.GetItemPool().GetDefaultItem( nWhich ) );
387 : }
388 : }
389 : }
390 2079 : return aCurSet;
391 : }
392 :
393 :
394 14363 : SfxItemSet ImpEditEngine::GetAttribs( sal_Int32 nPara, sal_Int32 nStart, sal_Int32 nEnd, sal_uInt8 nFlags ) const
395 : {
396 : // Optimized function with less Puts(), which cause unnecessary cloning from default items.
397 : // If this works, change GetAttribs( EditSelection ) to use this for each paragraph and merge the results!
398 :
399 :
400 14363 : ContentNode* pNode = const_cast<ContentNode*>(aEditDoc.GetObject(nPara));
401 : DBG_ASSERT( pNode, "GetAttribs - unknown paragraph!" );
402 : DBG_ASSERT( nStart <= nEnd, "getAttribs: Start > End not supported!" );
403 :
404 14363 : SfxItemSet aAttribs( ((ImpEditEngine*)this)->GetEmptyItemSet() );
405 :
406 14363 : if ( pNode )
407 : {
408 14363 : if ( nEnd > pNode->Len() )
409 0 : nEnd = pNode->Len();
410 :
411 14363 : if ( nStart > nEnd )
412 0 : nStart = nEnd;
413 :
414 : // StyleSheet / Parattribs...
415 :
416 14363 : if ( pNode->GetStyleSheet() && ( nFlags & GETATTRIBS_STYLESHEET ) )
417 2033 : aAttribs.Set(pNode->GetStyleSheet()->GetItemSet(), true);
418 :
419 14363 : if ( nFlags & GETATTRIBS_PARAATTRIBS )
420 13421 : aAttribs.Put( pNode->GetContentAttribs().GetItems() );
421 :
422 : // CharAttribs...
423 :
424 14363 : if ( nFlags & GETATTRIBS_CHARATTRIBS )
425 : {
426 : // Make testing easier...
427 14363 : const SfxItemPool& rPool = GetEditDoc().GetItemPool();
428 14363 : pNode->GetCharAttribs().OptimizeRanges(const_cast<SfxItemPool&>(rPool));
429 :
430 14363 : const CharAttribList::AttribsType& rAttrs = pNode->GetCharAttribs().GetAttribs();
431 104511 : for (size_t nAttr = 0; nAttr < rAttrs.size(); ++nAttr)
432 : {
433 90548 : const EditCharAttrib& rAttr = rAttrs[nAttr];
434 :
435 90548 : if ( nStart == nEnd )
436 : {
437 52585 : sal_Int32 nCursorPos = nStart;
438 52585 : if ( ( rAttr.GetStart() <= nCursorPos ) && ( rAttr.GetEnd() >= nCursorPos ) )
439 : {
440 : // To be used the attribute has to start BEFORE the position, or it must be a
441 : // new empty attr AT the position, or we are on position 0.
442 52439 : if ( ( rAttr.GetStart() < nCursorPos ) || rAttr.IsEmpty() || !nCursorPos )
443 : {
444 : // maybe this attrib ends here and a new attrib with 0 Len may follow and be valid here,
445 : // but that s no problem, the empty item will come later and win.
446 52439 : aAttribs.Put( *rAttr.GetItem() );
447 : }
448 : }
449 : }
450 : else
451 : {
452 : // Check every attribute covering the area, partial or full.
453 37963 : if ( ( rAttr.GetStart() < nEnd ) && ( rAttr.GetEnd() > nStart ) )
454 : {
455 35992 : if ( ( rAttr.GetStart() <= nStart ) && ( rAttr.GetEnd() >= nEnd ) )
456 : {
457 : // full coverage
458 35189 : aAttribs.Put( *rAttr.GetItem() );
459 : }
460 : else
461 : {
462 : // OptimizeRagnge() assures that not the same attr can follow for full coverage
463 : // only partial, check with current, when using para/styhe, otherwise invalid.
464 1606 : if ( !( nFlags & (GETATTRIBS_PARAATTRIBS|GETATTRIBS_STYLESHEET) ) ||
465 803 : ( *rAttr.GetItem() != aAttribs.Get( rAttr.Which() ) ) )
466 : {
467 797 : aAttribs.InvalidateItem( rAttr.Which() );
468 : }
469 : }
470 : }
471 : }
472 :
473 90548 : if ( rAttr.GetStart() > nEnd )
474 : {
475 400 : break;
476 : }
477 : }
478 : }
479 : }
480 :
481 14363 : return aAttribs;
482 : }
483 :
484 :
485 5990 : void ImpEditEngine::SetAttribs( EditSelection aSel, const SfxItemSet& rSet, sal_uInt8 nSpecial )
486 : {
487 5990 : aSel.Adjust( aEditDoc );
488 :
489 : // When no selection => use the Attribute on the word.
490 : // ( the RTF-parser should actually never call the Method without a Range )
491 5990 : if ( ( nSpecial == ATTRSPECIAL_WHOLEWORD ) && !aSel.HasRange() )
492 97 : aSel = SelectWord( aSel, ::com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES, sal_False );
493 :
494 5990 : sal_Int32 nStartNode = aEditDoc.GetPos( aSel.Min().GetNode() );
495 5990 : sal_Int32 nEndNode = aEditDoc.GetPos( aSel.Max().GetNode() );
496 :
497 5990 : if ( IsUndoEnabled() && !IsInUndo() && aStatus.DoUndoAttribs() )
498 : {
499 3692 : EditUndoSetAttribs* pUndo = CreateAttribUndo( aSel, rSet );
500 3692 : pUndo->SetSpecial( nSpecial );
501 3692 : InsertUndo( pUndo );
502 : }
503 :
504 5990 : sal_Bool bCheckLanguage = sal_False;
505 5990 : if ( GetStatus().DoOnlineSpelling() )
506 : {
507 3005 : bCheckLanguage = ( rSet.GetItemState( EE_CHAR_LANGUAGE ) == SFX_ITEM_ON ) ||
508 3005 : ( rSet.GetItemState( EE_CHAR_LANGUAGE_CJK ) == SFX_ITEM_ON ) ||
509 3005 : ( rSet.GetItemState( EE_CHAR_LANGUAGE_CTL ) == SFX_ITEM_ON );
510 : }
511 :
512 : // iterate over the paragraphs ...
513 12388 : for ( sal_Int32 nNode = nStartNode; nNode <= nEndNode; nNode++ )
514 : {
515 6398 : sal_Bool bParaAttribFound = sal_False;
516 6398 : sal_Bool bCharAttribFound = sal_False;
517 :
518 : DBG_ASSERT( aEditDoc.GetObject( nNode ), "Node not founden: SetAttribs" );
519 : DBG_ASSERT( GetParaPortions().SafeGetObject( nNode ), "Portion not found: SetAttribs" );
520 :
521 6398 : ContentNode* pNode = aEditDoc.GetObject( nNode );
522 6398 : ParaPortion* pPortion = GetParaPortions()[nNode];
523 :
524 6398 : const sal_Int32 nStartPos = nNode==nStartNode ? aSel.Min().GetIndex() : 0;
525 6398 : const sal_Int32 nEndPos = nNode==nEndNode ? aSel.Max().GetIndex() : pNode->Len(); // can also be == nStart!
526 :
527 : // Iterate over the Items...
528 326298 : for ( sal_uInt16 nWhich = EE_ITEMS_START; nWhich <= EE_CHAR_END; nWhich++)
529 : {
530 319900 : if ( rSet.GetItemState( nWhich ) == SFX_ITEM_ON )
531 : {
532 41731 : const SfxPoolItem& rItem = rSet.Get( nWhich );
533 41731 : if ( nWhich <= EE_PARA_END )
534 : {
535 5649 : pNode->GetContentAttribs().GetItems().Put( rItem );
536 5649 : bParaAttribFound = sal_True;
537 : }
538 : else
539 : {
540 36082 : aEditDoc.InsertAttrib( pNode, nStartPos, nEndPos, rItem );
541 36082 : bCharAttribFound = sal_True;
542 36082 : if ( nSpecial == ATTRSPECIAL_EDGE )
543 : {
544 0 : CharAttribList::AttribsType& rAttribs = pNode->GetCharAttribs().GetAttribs();
545 0 : for (size_t i = 0, n = rAttribs.size(); i < n; ++i)
546 : {
547 0 : EditCharAttrib& rAttr = rAttribs[i];
548 0 : if (rAttr.GetStart() > nEndPos)
549 0 : break;
550 :
551 0 : if (rAttr.GetEnd() == nEndPos && rAttr.Which() == nWhich)
552 : {
553 0 : rAttr.SetEdge(true);
554 0 : break;
555 : }
556 : }
557 : }
558 : }
559 : }
560 : }
561 :
562 6398 : if ( bParaAttribFound )
563 : {
564 1259 : ParaAttribsChanged( pPortion->GetNode() );
565 : }
566 5139 : else if ( bCharAttribFound )
567 : {
568 4213 : bFormatted = false;
569 4213 : if ( !pNode->Len() || ( nStartPos != nEndPos ) )
570 : {
571 4064 : pPortion->MarkSelectionInvalid( nStartPos, nEndPos-nStartPos );
572 4064 : if ( bCheckLanguage )
573 1261 : pNode->GetWrongList()->SetInvalidRange(nStartPos, nEndPos);
574 : }
575 : }
576 : }
577 5990 : }
578 :
579 561 : void ImpEditEngine::RemoveCharAttribs( EditSelection aSel, sal_Bool bRemoveParaAttribs, sal_uInt16 nWhich )
580 : {
581 561 : aSel.Adjust( aEditDoc );
582 :
583 561 : sal_Int32 nStartNode = aEditDoc.GetPos( aSel.Min().GetNode() );
584 561 : sal_Int32 nEndNode = aEditDoc.GetPos( aSel.Max().GetNode() );
585 :
586 561 : const SfxItemSet* _pEmptyItemSet = bRemoveParaAttribs ? &GetEmptyItemSet() : 0;
587 :
588 561 : if ( IsUndoEnabled() && !IsInUndo() && aStatus.DoUndoAttribs() )
589 : {
590 : // Possibly a special Undo, or itemset*
591 561 : EditUndoSetAttribs* pUndo = CreateAttribUndo( aSel, GetEmptyItemSet() );
592 561 : pUndo->SetRemoveAttribs( sal_True );
593 561 : pUndo->SetRemoveParaAttribs( bRemoveParaAttribs );
594 561 : pUndo->SetRemoveWhich( nWhich );
595 561 : InsertUndo( pUndo );
596 : }
597 :
598 : // iterate over the paragraphs ...
599 1122 : for ( sal_Int32 nNode = nStartNode; nNode <= nEndNode; nNode++ )
600 : {
601 561 : ContentNode* pNode = aEditDoc.GetObject( nNode );
602 561 : ParaPortion* pPortion = GetParaPortions()[nNode];
603 :
604 : DBG_ASSERT( aEditDoc.GetObject( nNode ), "Node not found: SetAttribs" );
605 : DBG_ASSERT( GetParaPortions().SafeGetObject( nNode ), "Portion not found: SetAttribs" );
606 :
607 561 : const sal_Int32 nStartPos = nNode==nStartNode ? aSel.Min().GetIndex() : 0;
608 561 : const sal_Int32 nEndPos = nNode==nEndNode ? aSel.Max().GetIndex() : pNode->Len(); // can also be == nStart!
609 :
610 : // Optimize: If whole paragraph, then RemoveCharAttribs (nPara)?
611 561 : sal_Bool bChanged = aEditDoc.RemoveAttribs( pNode, nStartPos, nEndPos, nWhich );
612 561 : if ( bRemoveParaAttribs )
613 : {
614 141 : SetParaAttribs( nNode, *_pEmptyItemSet ); // Invalidated
615 : }
616 : else
617 : {
618 : // For 'Format-Standard' also the character attributes should
619 : // disappear, which were set as paragraph attributes by the
620 : // DrawingEngine. These could not have been set by the user anyway.
621 :
622 : // #106871# Not when nWhich
623 : // Would have been better to offer a separate method for format/standard...
624 420 : if ( !nWhich )
625 : {
626 420 : SfxItemSet aAttribs( GetParaAttribs( nNode ) );
627 13860 : for ( sal_uInt16 nW = EE_CHAR_START; nW <= EE_CHAR_END; nW++ )
628 13440 : aAttribs.ClearItem( nW );
629 420 : SetParaAttribs( nNode, aAttribs );
630 : }
631 : }
632 :
633 561 : if ( bChanged && !bRemoveParaAttribs )
634 : {
635 214 : bFormatted = false;
636 214 : pPortion->MarkSelectionInvalid( nStartPos, nEndPos-nStartPos );
637 : }
638 : }
639 561 : }
640 :
641 40443 : void ImpEditEngine::RemoveCharAttribs( sal_Int32 nPara, sal_uInt16 nWhich, sal_Bool bRemoveFeatures )
642 : {
643 40443 : ContentNode* pNode = aEditDoc.GetObject( nPara );
644 40443 : ParaPortion* pPortion = GetParaPortions().SafeGetObject( nPara );
645 :
646 : DBG_ASSERT( pNode, "Node not found: RemoveCharAttribs" );
647 : DBG_ASSERT( pPortion, "Portion not found: RemoveCharAttribs" );
648 :
649 40443 : if ( !pNode )
650 40443 : return;
651 :
652 40443 : size_t nAttr = 0;
653 40443 : CharAttribList::AttribsType& rAttrs = pNode->GetCharAttribs().GetAttribs();
654 40443 : EditCharAttrib* pAttr = GetAttrib(rAttrs, nAttr);
655 87445 : while ( pAttr )
656 : {
657 8165 : if ( ( !pAttr->IsFeature() || bRemoveFeatures ) &&
658 3846 : ( !nWhich || ( pAttr->GetItem()->Which() == nWhich ) ) )
659 : {
660 1606 : pNode->GetCharAttribs().Remove(nAttr);
661 1606 : nAttr--;
662 : }
663 6559 : nAttr++;
664 6559 : pAttr = GetAttrib(rAttrs, nAttr);
665 : }
666 :
667 40443 : pPortion->MarkSelectionInvalid( 0, pNode->Len() );
668 : }
669 :
670 770459 : void ImpEditEngine::SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet )
671 : {
672 770459 : ContentNode* pNode = aEditDoc.GetObject( nPara );
673 :
674 770459 : if ( !pNode )
675 770459 : return;
676 :
677 770459 : if ( !( pNode->GetContentAttribs().GetItems() == rSet ) )
678 : {
679 389942 : if ( IsUndoEnabled() && !IsInUndo() && aStatus.DoUndoAttribs() )
680 : {
681 22003 : if ( rSet.GetPool() != &aEditDoc.GetItemPool() )
682 : {
683 0 : SfxItemSet aTmpSet( GetEmptyItemSet() );
684 0 : aTmpSet.Put( rSet );
685 0 : InsertUndo(new EditUndoSetParaAttribs(pEditEngine, nPara, pNode->GetContentAttribs().GetItems(), aTmpSet));
686 : }
687 : else
688 : {
689 22003 : InsertUndo(new EditUndoSetParaAttribs(pEditEngine, nPara, pNode->GetContentAttribs().GetItems(), rSet));
690 : }
691 : }
692 389942 : pNode->GetContentAttribs().GetItems().Set( rSet );
693 389942 : if ( aStatus.UseCharAttribs() )
694 389942 : pNode->CreateDefFont();
695 :
696 389942 : ParaAttribsChanged( pNode );
697 : }
698 : }
699 :
700 630762 : const SfxItemSet& ImpEditEngine::GetParaAttribs( sal_Int32 nPara ) const
701 : {
702 630762 : const ContentNode* pNode = aEditDoc.GetObject( nPara );
703 : DBG_ASSERT( pNode, "Node not found: GetParaAttribs" );
704 630762 : return pNode->GetContentAttribs().GetItems();
705 : }
706 :
707 9731 : bool ImpEditEngine::HasParaAttrib( sal_Int32 nPara, sal_uInt16 nWhich ) const
708 : {
709 9731 : const ContentNode* pNode = aEditDoc.GetObject( nPara );
710 : DBG_ASSERT( pNode, "Node not found: HasParaAttrib" );
711 :
712 9731 : return pNode->GetContentAttribs().HasItem( nWhich );
713 : }
714 :
715 1543943 : const SfxPoolItem& ImpEditEngine::GetParaAttrib( sal_Int32 nPara, sal_uInt16 nWhich ) const
716 : {
717 1543943 : const ContentNode* pNode = aEditDoc.GetObject( nPara );
718 : DBG_ASSERT( pNode, "Node not found: GetParaAttrib" );
719 :
720 1543943 : return pNode->GetContentAttribs().GetItem( nWhich );
721 : }
722 :
723 237 : void ImpEditEngine::GetCharAttribs( sal_Int32 nPara, std::vector<EECharAttrib>& rLst ) const
724 : {
725 237 : rLst.clear();
726 237 : const ContentNode* pNode = aEditDoc.GetObject( nPara );
727 237 : if ( pNode )
728 : {
729 237 : rLst.reserve(pNode->GetCharAttribs().Count());
730 237 : const CharAttribList::AttribsType& rAttrs = pNode->GetCharAttribs().GetAttribs();
731 1088 : for (size_t i = 0; i < rAttrs.size(); ++i)
732 : {
733 851 : const EditCharAttrib& rAttr = rAttrs[i];
734 : EECharAttrib aEEAttr;
735 851 : aEEAttr.pAttr = rAttr.GetItem();
736 851 : aEEAttr.nPara = nPara;
737 851 : aEEAttr.nStart = rAttr.GetStart();
738 851 : aEEAttr.nEnd = rAttr.GetEnd();
739 851 : rLst.push_back(aEEAttr);
740 : }
741 : }
742 237 : }
743 :
744 0 : void ImpEditEngine::ParaAttribsToCharAttribs( ContentNode* pNode )
745 : {
746 0 : pNode->GetCharAttribs().DeleteEmptyAttribs( GetEditDoc().GetItemPool() );
747 0 : sal_Int32 nEndPos = pNode->Len();
748 0 : for ( sal_uInt16 nWhich = EE_CHAR_START; nWhich <= EE_CHAR_END; nWhich++ )
749 : {
750 0 : if ( pNode->GetContentAttribs().HasItem( nWhich ) )
751 : {
752 0 : const SfxPoolItem& rItem = pNode->GetContentAttribs().GetItem( nWhich );
753 : // Fill the gap:
754 0 : sal_Int32 nLastEnd = 0;
755 0 : const EditCharAttrib* pAttr = pNode->GetCharAttribs().FindNextAttrib( nWhich, nLastEnd );
756 0 : while ( pAttr )
757 : {
758 0 : nLastEnd = pAttr->GetEnd();
759 0 : if ( pAttr->GetStart() > nLastEnd )
760 0 : aEditDoc.InsertAttrib( pNode, nLastEnd, pAttr->GetStart(), rItem );
761 : // #112831# Last Attr might go from 0xffff to 0x0000
762 0 : pAttr = nLastEnd ? pNode->GetCharAttribs().FindNextAttrib( nWhich, nLastEnd ) : NULL;
763 : }
764 :
765 : // And the Rest:
766 0 : if ( nLastEnd < nEndPos )
767 0 : aEditDoc.InsertAttrib( pNode, nLastEnd, nEndPos, rItem );
768 : }
769 : }
770 0 : bFormatted = false;
771 : // Portion does not need to be invalidated here, happens elsewhere.
772 0 : }
773 :
774 25815 : IdleFormattter::IdleFormattter()
775 : {
776 25815 : pView = 0;
777 25815 : nRestarts = 0;
778 25815 : }
779 :
780 48200 : IdleFormattter::~IdleFormattter()
781 : {
782 24100 : pView = 0;
783 24100 : }
784 :
785 0 : void IdleFormattter::DoIdleFormat( EditView* pV )
786 : {
787 0 : pView = pV;
788 :
789 0 : if ( IsActive() )
790 0 : nRestarts++;
791 :
792 0 : if ( nRestarts > 4 )
793 0 : ForceTimeout();
794 : else
795 0 : Start();
796 0 : }
797 :
798 1912 : void IdleFormattter::ForceTimeout()
799 : {
800 1912 : if ( IsActive() )
801 : {
802 0 : Stop();
803 0 : ((Link&)GetTimeoutHdl()).Call( this );
804 : }
805 1912 : }
806 :
807 0 : ImplIMEInfos::ImplIMEInfos( const EditPaM& rPos, const OUString& rOldTextAfterStartPos )
808 0 : : aOldTextAfterStartPos( rOldTextAfterStartPos )
809 : {
810 0 : aPos = rPos;
811 0 : nLen = 0;
812 0 : bCursor = sal_True;
813 0 : pAttribs = NULL;
814 0 : bWasCursorOverwrite = sal_False;
815 0 : }
816 :
817 0 : ImplIMEInfos::~ImplIMEInfos()
818 : {
819 0 : delete[] pAttribs;
820 0 : }
821 :
822 0 : void ImplIMEInfos::CopyAttribs( const sal_uInt16* pA, sal_uInt16 nL )
823 : {
824 0 : nLen = nL;
825 0 : delete[] pAttribs;
826 0 : pAttribs = new sal_uInt16[ nL ];
827 0 : memcpy( pAttribs, pA, nL*sizeof(sal_uInt16) );
828 0 : }
829 :
830 0 : void ImplIMEInfos::DestroyAttribs()
831 : {
832 0 : delete[] pAttribs;
833 0 : pAttribs = NULL;
834 0 : nLen = 0;
835 0 : }
836 :
837 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|