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 38376 : void ImpEditEngine::SetStyleSheetPool( SfxStyleSheetPool* pSPool )
31 : {
32 38376 : if ( pStylePool != pSPool )
33 : {
34 7656 : pStylePool = pSPool;
35 : }
36 38376 : }
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 41654 : SfxStyleSheet* ImpEditEngine::GetStyleSheet( sal_Int32 nPara )
45 : {
46 41654 : ContentNode* pNode = aEditDoc.GetObject( nPara );
47 41654 : 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 : 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 97036 : void ImpEditEngine::SetStyleSheet( sal_Int32 nPara, SfxStyleSheet* pStyle )
67 : {
68 : DBG_ASSERT( GetStyleSheetPool() || !pStyle, "SetStyleSheet: No StyleSheetPool registered!" );
69 97036 : ContentNode* pNode = aEditDoc.GetObject( nPara );
70 97036 : SfxStyleSheet* pCurStyle = pNode->GetStyleSheet();
71 97036 : if ( pStyle != pCurStyle )
72 : {
73 75670 : if ( IsUndoEnabled() && !IsInUndo() && aStatus.DoUndoAttribs() )
74 : {
75 9546 : OUString aPrevStyleName;
76 9546 : if ( pCurStyle )
77 6828 : aPrevStyleName = pCurStyle->GetName();
78 :
79 19092 : OUString aNewStyleName;
80 9546 : if ( pStyle )
81 9546 : aNewStyleName = pStyle->GetName();
82 :
83 : InsertUndo(
84 9546 : new EditUndoSetStyleSheet(pEditEngine, aEditDoc.GetPos( pNode ),
85 6828 : aPrevStyleName, pCurStyle ? pCurStyle->GetFamily() : SFX_STYLE_FAMILY_PARA,
86 9546 : aNewStyleName, pStyle ? pStyle->GetFamily() : SFX_STYLE_FAMILY_PARA,
87 35466 : pNode->GetContentAttribs().GetItems() ) );
88 : }
89 75670 : if ( pCurStyle )
90 7254 : EndListening( *pCurStyle, false );
91 75670 : pNode->SetStyleSheet( pStyle, aStatus.UseCharAttribs() );
92 75670 : if ( pStyle )
93 75670 : StartListening( *pStyle, false );
94 75670 : ParaAttribsChanged( pNode );
95 : }
96 97036 : FormatAndUpdate();
97 97036 : }
98 :
99 0 : void ImpEditEngine::UpdateParagraphsWithStyleSheet( SfxStyleSheet* pStyle )
100 : {
101 0 : SvxFont aFontFromStyle;
102 0 : CreateFont( aFontFromStyle, pStyle->GetItemSet() );
103 :
104 0 : bool bUsed = 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 = true;
111 0 : if ( aStatus.UseCharAttribs() )
112 0 : pNode->SetStyleSheet( pStyle, aFontFromStyle );
113 : else
114 0 : pNode->SetStyleSheet( pStyle, 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 : const SfxStyleSheetHint* pStyleSheetHint = dynamic_cast<const SfxStyleSheetHint*>(&rHint);
150 0 : if ( pStyleSheetHint )
151 : {
152 : DBG_ASSERT( pStyleSheetHint->GetStyleSheet()->ISA( SfxStyleSheet ), "No SfxStyleSheet!" );
153 0 : pStyle = static_cast<SfxStyleSheet*>( pStyleSheetHint->GetStyleSheet() );
154 0 : nId = pStyleSheetHint->GetHint();
155 : }
156 0 : else if ( dynamic_cast<const SfxSimpleHint*>(&rHint) && rBC.ISA( SfxStyleSheet ) )
157 : {
158 0 : pStyle = static_cast<SfxStyleSheet*>(&rBC);
159 0 : nId = dynamic_cast<const 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 9887 : EditUndoSetAttribs* ImpEditEngine::CreateAttribUndo( EditSelection aSel, const SfxItemSet& rSet )
180 : {
181 : DBG_ASSERT( !aSel.DbgIsBuggy( aEditDoc ), "CreateAttribUndo: Incorrect selection ");
182 9887 : aSel.Adjust( aEditDoc );
183 :
184 9887 : ESelection aESel( CreateESel( aSel ) );
185 :
186 9887 : sal_Int32 nStartNode = aEditDoc.GetPos( aSel.Min().GetNode() );
187 9887 : sal_Int32 nEndNode = aEditDoc.GetPos( aSel.Max().GetNode() );
188 :
189 : DBG_ASSERT( nStartNode <= nEndNode, "CreateAttribUndo: Start > End ?!" );
190 :
191 9887 : EditUndoSetAttribs* pUndo = NULL;
192 9887 : 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 9887 : pUndo = new EditUndoSetAttribs(pEditEngine, aESel, rSet);
201 : }
202 :
203 9887 : SfxItemPool* pPool = pUndo->GetNewAttribs().GetPool();
204 :
205 20530 : for ( sal_Int32 nPara = nStartNode; nPara <= nEndNode; nPara++ )
206 : {
207 10643 : ContentNode* pNode = aEditDoc.GetObject( nPara );
208 : DBG_ASSERT( aEditDoc.GetObject( nPara ), "Node not found: CreateAttribUndo" );
209 10643 : ContentAttribsInfo* pInf = new ContentAttribsInfo( pNode->GetContentAttribs().GetItems() );
210 10643 : pUndo->AppendContentInfo(pInf);
211 :
212 92095 : for ( sal_uInt16 nAttr = 0; nAttr < pNode->GetCharAttribs().Count(); nAttr++ )
213 : {
214 81452 : const EditCharAttrib& rAttr = pNode->GetCharAttribs().GetAttribs()[nAttr];
215 81452 : if (rAttr.GetLen())
216 : {
217 62994 : EditCharAttrib* pNew = MakeCharAttrib(*pPool, *rAttr.GetItem(), rAttr.GetStart(), rAttr.GetEnd());
218 62994 : pInf->AppendCharAttrib(pNew);
219 : }
220 : }
221 : }
222 9887 : 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 181813 : void ImpEditEngine::UndoActionStart( sal_uInt16 nId )
236 : {
237 181813 : if ( IsUndoEnabled() && !IsInUndo() )
238 : {
239 143366 : GetUndoManager().EnterListAction( GetEditEnginePtr()->GetUndoComment( nId ), OUString(), nId );
240 : DBG_ASSERT( !pUndoMarkSelection, "UndoAction SelectionMarker?" );
241 : }
242 181813 : }
243 :
244 181813 : void ImpEditEngine::UndoActionEnd( sal_uInt16 )
245 : {
246 181813 : if ( IsUndoEnabled() && !IsInUndo() )
247 : {
248 143366 : GetUndoManager().LeaveListAction();
249 143366 : delete pUndoMarkSelection;
250 143366 : pUndoMarkSelection = NULL;
251 : }
252 181813 : }
253 :
254 77488 : void ImpEditEngine::InsertUndo( EditUndo* pUndo, bool bTryMerge )
255 : {
256 : DBG_ASSERT( !IsInUndo(), "InsertUndo in Undomodus!" );
257 77488 : 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 77488 : GetUndoManager().AddUndoAction( pUndo, bTryMerge );
265 :
266 77488 : mbLastTryMerge = bTryMerge;
267 77488 : }
268 :
269 1671138 : void ImpEditEngine::ResetUndoManager()
270 : {
271 1671138 : if ( HasUndoManager() )
272 1526176 : GetUndoManager().Clear();
273 1671138 : }
274 :
275 2207240 : void ImpEditEngine::EnableUndo( bool bEnable )
276 : {
277 : // When switching the mode Delete list:
278 2207240 : if ( bEnable != IsUndoEnabled() )
279 1112048 : ResetUndoManager();
280 :
281 2207240 : bUndoEnabled = bEnable;
282 2207240 : }
283 :
284 0 : bool ImpEditEngine::Undo( EditView* pView )
285 : {
286 0 : if ( HasUndoManager() && GetUndoManager().GetUndoActionCount() )
287 : {
288 0 : SetActiveView( pView );
289 0 : GetUndoManager().Undo();
290 0 : return true;
291 : }
292 0 : return false;
293 : }
294 :
295 0 : bool ImpEditEngine::Redo( EditView* pView )
296 : {
297 0 : if ( HasUndoManager() && GetUndoManager().GetRedoActionCount() )
298 : {
299 0 : SetActiveView( pView );
300 0 : GetUndoManager().Redo();
301 0 : return true;
302 : }
303 0 : return false;
304 : }
305 :
306 5087 : SfxItemSet ImpEditEngine::GetAttribs( EditSelection aSel, EditEngineAttribs nOnlyHardAttrib )
307 : {
308 :
309 5087 : aSel.Adjust( aEditDoc );
310 :
311 5087 : SfxItemSet aCurSet( GetEmptyItemSet() );
312 :
313 5087 : sal_Int32 nStartNode = aEditDoc.GetPos( aSel.Min().GetNode() );
314 5087 : sal_Int32 nEndNode = aEditDoc.GetPos( aSel.Max().GetNode() );
315 :
316 : // iterate over the paragraphs ...
317 11218 : for ( sal_Int32 nNode = nStartNode; nNode <= nEndNode; nNode++ )
318 : {
319 6131 : ContentNode* pNode = aEditDoc.GetObject( nNode );
320 : DBG_ASSERT( aEditDoc.GetObject( nNode ), "Node not found: GetAttrib" );
321 :
322 6131 : const sal_Int32 nStartPos = nNode==nStartNode ? aSel.Min().GetIndex() : 0;
323 6131 : 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 6131 : aEditDoc.FindAttribs( pNode, nStartPos, nEndPos, aCurSet );
332 :
333 6131 : if( nOnlyHardAttrib != EditEngineAttribs_OnlyHard )
334 : {
335 : // and then paragraph formatting and template...
336 296556 : for ( sal_uInt16 nWhich = EE_ITEMS_START; nWhich <= EE_CHAR_END; nWhich++)
337 : {
338 290853 : if ( aCurSet.GetItemState( nWhich ) == SfxItemState::DEFAULT )
339 : {
340 221135 : if ( nOnlyHardAttrib == EditEngineAttribs_All )
341 : {
342 221135 : const SfxPoolItem& rItem = pNode->GetContentAttribs().GetItem( nWhich );
343 221135 : aCurSet.Put( rItem );
344 : }
345 0 : else if ( pNode->GetContentAttribs().GetItems().GetItemState( nWhich ) == SfxItemState::SET )
346 : {
347 0 : const SfxPoolItem& rItem = pNode->GetContentAttribs().GetItems().Get( nWhich );
348 0 : aCurSet.Put( rItem );
349 : }
350 : }
351 69718 : else if ( aCurSet.GetItemState( nWhich ) == SfxItemState::SET )
352 : {
353 68584 : const SfxPoolItem* pItem = NULL;
354 68584 : if ( nOnlyHardAttrib == EditEngineAttribs_All )
355 : {
356 68584 : pItem = &pNode->GetContentAttribs().GetItem( nWhich );
357 : }
358 0 : else if ( pNode->GetContentAttribs().GetItems().GetItemState( nWhich ) == SfxItemState::SET )
359 : {
360 0 : pItem = &pNode->GetContentAttribs().GetItems().Get( nWhich );
361 : }
362 : // pItem can only be NULL when nOnlyHardAttrib...
363 68584 : 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 30516 : if ( nWhich <= EE_PARA_END )
372 18 : aCurSet.InvalidateItem( nWhich );
373 : }
374 : }
375 : }
376 : }
377 : }
378 :
379 : // fill empty slots with defaults ...
380 5087 : if ( nOnlyHardAttrib == EditEngineAttribs_All )
381 : {
382 242268 : for ( sal_uInt16 nWhich = EE_ITEMS_START; nWhich <= EE_CHAR_END; nWhich++ )
383 : {
384 237609 : if ( aCurSet.GetItemState( nWhich ) == SfxItemState::DEFAULT )
385 : {
386 0 : aCurSet.Put( aEditDoc.GetItemPool().GetDefaultItem( nWhich ) );
387 : }
388 : }
389 : }
390 5087 : return aCurSet;
391 : }
392 :
393 :
394 42490 : 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 42490 : 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 42490 : SfxItemSet aAttribs( ((ImpEditEngine*)this)->GetEmptyItemSet() );
405 :
406 42490 : if ( pNode )
407 : {
408 42490 : if ( nEnd > pNode->Len() )
409 0 : nEnd = pNode->Len();
410 :
411 42490 : if ( nStart > nEnd )
412 0 : nStart = nEnd;
413 :
414 : // StyleSheet / Parattribs...
415 :
416 42490 : if ( pNode->GetStyleSheet() && ( nFlags & GETATTRIBS_STYLESHEET ) )
417 13222 : aAttribs.Set(pNode->GetStyleSheet()->GetItemSet(), true);
418 :
419 42490 : if ( nFlags & GETATTRIBS_PARAATTRIBS )
420 39524 : aAttribs.Put( pNode->GetContentAttribs().GetItems() );
421 :
422 : // CharAttribs...
423 :
424 42490 : if ( nFlags & GETATTRIBS_CHARATTRIBS )
425 : {
426 : // Make testing easier...
427 42490 : const SfxItemPool& rPool = GetEditDoc().GetItemPool();
428 42490 : pNode->GetCharAttribs().OptimizeRanges(const_cast<SfxItemPool&>(rPool));
429 :
430 42490 : const CharAttribList::AttribsType& rAttrs = pNode->GetCharAttribs().GetAttribs();
431 318730 : for (size_t nAttr = 0; nAttr < rAttrs.size(); ++nAttr)
432 : {
433 277304 : const EditCharAttrib& rAttr = rAttrs[nAttr];
434 :
435 277304 : if ( nStart == nEnd )
436 : {
437 180132 : sal_Int32 nCursorPos = nStart;
438 180132 : 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 179452 : 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 179452 : aAttribs.Put( *rAttr.GetItem() );
447 : }
448 : }
449 : }
450 : else
451 : {
452 : // Check every attribute covering the area, partial or full.
453 97172 : if ( ( rAttr.GetStart() < nEnd ) && ( rAttr.GetEnd() > nStart ) )
454 : {
455 81396 : if ( ( rAttr.GetStart() <= nStart ) && ( rAttr.GetEnd() >= nEnd ) )
456 : {
457 : // full coverage
458 79348 : 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 4096 : if ( !( nFlags & (GETATTRIBS_PARAATTRIBS|GETATTRIBS_STYLESHEET) ) ||
465 2048 : ( *rAttr.GetItem() != aAttribs.Get( rAttr.Which() ) ) )
466 : {
467 1968 : aAttribs.InvalidateItem( rAttr.Which() );
468 : }
469 : }
470 : }
471 : }
472 :
473 277304 : if ( rAttr.GetStart() > nEnd )
474 : {
475 1064 : break;
476 : }
477 : }
478 : }
479 : }
480 :
481 42490 : return aAttribs;
482 : }
483 :
484 :
485 19267 : void ImpEditEngine::SetAttribs( EditSelection aSel, const SfxItemSet& rSet, sal_uInt8 nSpecial )
486 : {
487 19267 : 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 19267 : if ( ( nSpecial == ATTRSPECIAL_WHOLEWORD ) && !aSel.HasRange() )
492 282 : aSel = SelectWord( aSel, ::com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES, false );
493 :
494 19267 : sal_Int32 nStartNode = aEditDoc.GetPos( aSel.Min().GetNode() );
495 19267 : sal_Int32 nEndNode = aEditDoc.GetPos( aSel.Max().GetNode() );
496 :
497 19267 : if ( IsUndoEnabled() && !IsInUndo() && aStatus.DoUndoAttribs() )
498 : {
499 8175 : EditUndoSetAttribs* pUndo = CreateAttribUndo( aSel, rSet );
500 8175 : pUndo->SetSpecial( nSpecial );
501 8175 : InsertUndo( pUndo );
502 : }
503 :
504 19267 : bool bCheckLanguage = false;
505 19267 : if ( GetStatus().DoOnlineSpelling() )
506 : {
507 6096 : bCheckLanguage = ( rSet.GetItemState( EE_CHAR_LANGUAGE ) == SfxItemState::SET ) ||
508 6096 : ( rSet.GetItemState( EE_CHAR_LANGUAGE_CJK ) == SfxItemState::SET ) ||
509 6096 : ( rSet.GetItemState( EE_CHAR_LANGUAGE_CTL ) == SfxItemState::SET );
510 : }
511 :
512 : // iterate over the paragraphs ...
513 39404 : for ( sal_Int32 nNode = nStartNode; nNode <= nEndNode; nNode++ )
514 : {
515 20137 : bool bParaAttribFound = false;
516 20137 : bool bCharAttribFound = false;
517 :
518 : DBG_ASSERT( aEditDoc.GetObject( nNode ), "Node not founden: SetAttribs" );
519 : DBG_ASSERT( GetParaPortions().SafeGetObject( nNode ), "Portion not found: SetAttribs" );
520 :
521 20137 : ContentNode* pNode = aEditDoc.GetObject( nNode );
522 20137 : ParaPortion* pPortion = GetParaPortions()[nNode];
523 :
524 20137 : const sal_Int32 nStartPos = nNode==nStartNode ? aSel.Min().GetIndex() : 0;
525 20137 : const sal_Int32 nEndPos = nNode==nEndNode ? aSel.Max().GetIndex() : pNode->Len(); // can also be == nStart!
526 :
527 : // Iterate over the Items...
528 1047124 : for ( sal_uInt16 nWhich = EE_ITEMS_START; nWhich <= EE_CHAR_END; nWhich++)
529 : {
530 1026987 : if ( rSet.GetItemState( nWhich ) == SfxItemState::SET )
531 : {
532 140597 : const SfxPoolItem& rItem = rSet.Get( nWhich );
533 140597 : if ( nWhich <= EE_PARA_END )
534 : {
535 12126 : pNode->GetContentAttribs().GetItems().Put( rItem );
536 12126 : bParaAttribFound = true;
537 : }
538 : else
539 : {
540 128471 : aEditDoc.InsertAttrib( pNode, nStartPos, nEndPos, rItem );
541 128471 : bCharAttribFound = true;
542 128471 : 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 20137 : if ( bParaAttribFound )
563 : {
564 2564 : ParaAttribsChanged( pPortion->GetNode() );
565 : }
566 17573 : else if ( bCharAttribFound )
567 : {
568 14357 : bFormatted = false;
569 14357 : if ( !pNode->Len() || ( nStartPos != nEndPos ) )
570 : {
571 13474 : pPortion->MarkSelectionInvalid( nStartPos, nEndPos-nStartPos );
572 13474 : if ( bCheckLanguage )
573 2522 : pNode->GetWrongList()->SetInvalidRange(nStartPos, nEndPos);
574 : }
575 : }
576 : }
577 19267 : }
578 :
579 1316 : void ImpEditEngine::RemoveCharAttribs( EditSelection aSel, bool bRemoveParaAttribs, sal_uInt16 nWhich )
580 : {
581 1316 : aSel.Adjust( aEditDoc );
582 :
583 1316 : sal_Int32 nStartNode = aEditDoc.GetPos( aSel.Min().GetNode() );
584 1316 : sal_Int32 nEndNode = aEditDoc.GetPos( aSel.Max().GetNode() );
585 :
586 1316 : const SfxItemSet* _pEmptyItemSet = bRemoveParaAttribs ? &GetEmptyItemSet() : 0;
587 :
588 1316 : if ( IsUndoEnabled() && !IsInUndo() && aStatus.DoUndoAttribs() )
589 : {
590 : // Possibly a special Undo, or itemset*
591 1316 : EditUndoSetAttribs* pUndo = CreateAttribUndo( aSel, GetEmptyItemSet() );
592 1316 : pUndo->SetRemoveAttribs( true );
593 1316 : pUndo->SetRemoveParaAttribs( bRemoveParaAttribs );
594 1316 : pUndo->SetRemoveWhich( nWhich );
595 1316 : InsertUndo( pUndo );
596 : }
597 :
598 : // iterate over the paragraphs ...
599 2632 : for ( sal_Int32 nNode = nStartNode; nNode <= nEndNode; nNode++ )
600 : {
601 1316 : ContentNode* pNode = aEditDoc.GetObject( nNode );
602 1316 : 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 1316 : const sal_Int32 nStartPos = nNode==nStartNode ? aSel.Min().GetIndex() : 0;
608 1316 : 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 1316 : bool bChanged = aEditDoc.RemoveAttribs( pNode, nStartPos, nEndPos, nWhich );
612 1316 : if ( bRemoveParaAttribs )
613 : {
614 406 : 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 910 : if ( !nWhich )
625 : {
626 910 : SfxItemSet aAttribs( GetParaAttribs( nNode ) );
627 30940 : for ( sal_uInt16 nW = EE_CHAR_START; nW <= EE_CHAR_END; nW++ )
628 30030 : aAttribs.ClearItem( nW );
629 910 : SetParaAttribs( nNode, aAttribs );
630 : }
631 : }
632 :
633 1316 : if ( bChanged && !bRemoveParaAttribs )
634 : {
635 470 : bFormatted = false;
636 470 : pPortion->MarkSelectionInvalid( nStartPos, nEndPos-nStartPos );
637 : }
638 : }
639 1316 : }
640 :
641 153058 : void ImpEditEngine::RemoveCharAttribs( sal_Int32 nPara, sal_uInt16 nWhich, bool bRemoveFeatures )
642 : {
643 153058 : ContentNode* pNode = aEditDoc.GetObject( nPara );
644 153058 : ParaPortion* pPortion = GetParaPortions().SafeGetObject( nPara );
645 :
646 : DBG_ASSERT( pNode, "Node not found: RemoveCharAttribs" );
647 : DBG_ASSERT( pPortion, "Portion not found: RemoveCharAttribs" );
648 :
649 153058 : if ( !pNode )
650 153058 : return;
651 :
652 153058 : size_t nAttr = 0;
653 153058 : CharAttribList::AttribsType& rAttrs = pNode->GetCharAttribs().GetAttribs();
654 153058 : EditCharAttrib* pAttr = GetAttrib(rAttrs, nAttr);
655 320174 : while ( pAttr )
656 : {
657 17324 : if ( ( !pAttr->IsFeature() || bRemoveFeatures ) &&
658 7692 : ( !nWhich || ( pAttr->GetItem()->Which() == nWhich ) ) )
659 : {
660 3266 : pNode->GetCharAttribs().Remove(nAttr);
661 3266 : nAttr--;
662 : }
663 14058 : nAttr++;
664 14058 : pAttr = GetAttrib(rAttrs, nAttr);
665 : }
666 :
667 153058 : pPortion->MarkSelectionInvalid( 0, pNode->Len() );
668 : }
669 :
670 883416 : void ImpEditEngine::SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet )
671 : {
672 883416 : ContentNode* pNode = aEditDoc.GetObject( nPara );
673 :
674 883416 : if ( !pNode )
675 883416 : return;
676 :
677 883416 : if ( !( pNode->GetContentAttribs().GetItems() == rSet ) )
678 : {
679 485611 : if ( IsUndoEnabled() && !IsInUndo() && aStatus.DoUndoAttribs() )
680 : {
681 29242 : 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 29242 : InsertUndo(new EditUndoSetParaAttribs(pEditEngine, nPara, pNode->GetContentAttribs().GetItems(), rSet));
690 : }
691 : }
692 485611 : pNode->GetContentAttribs().GetItems().Set( rSet );
693 485611 : if ( aStatus.UseCharAttribs() )
694 485611 : pNode->CreateDefFont();
695 :
696 485611 : ParaAttribsChanged( pNode );
697 : }
698 : }
699 :
700 714336 : const SfxItemSet& ImpEditEngine::GetParaAttribs( sal_Int32 nPara ) const
701 : {
702 714336 : const ContentNode* pNode = aEditDoc.GetObject( nPara );
703 : assert(pNode && "Node not found: GetParaAttribs");
704 714336 : return pNode->GetContentAttribs().GetItems();
705 : }
706 :
707 23971 : bool ImpEditEngine::HasParaAttrib( sal_Int32 nPara, sal_uInt16 nWhich ) const
708 : {
709 23971 : const ContentNode* pNode = aEditDoc.GetObject( nPara );
710 : assert(pNode && "Node not found: HasParaAttrib");
711 23971 : return pNode->GetContentAttribs().HasItem( nWhich );
712 : }
713 :
714 1559159 : const SfxPoolItem& ImpEditEngine::GetParaAttrib( sal_Int32 nPara, sal_uInt16 nWhich ) const
715 : {
716 1559159 : const ContentNode* pNode = aEditDoc.GetObject(nPara);
717 : assert(pNode && "Node not found: GetParaAttrib");
718 1559159 : return pNode->GetContentAttribs().GetItem(nWhich);
719 : }
720 :
721 1220 : void ImpEditEngine::GetCharAttribs( sal_Int32 nPara, std::vector<EECharAttrib>& rLst ) const
722 : {
723 1220 : rLst.clear();
724 1220 : const ContentNode* pNode = aEditDoc.GetObject( nPara );
725 1220 : if ( pNode )
726 : {
727 1220 : rLst.reserve(pNode->GetCharAttribs().Count());
728 1220 : const CharAttribList::AttribsType& rAttrs = pNode->GetCharAttribs().GetAttribs();
729 10398 : for (size_t i = 0; i < rAttrs.size(); ++i)
730 : {
731 9178 : const EditCharAttrib& rAttr = rAttrs[i];
732 : EECharAttrib aEEAttr;
733 9178 : aEEAttr.pAttr = rAttr.GetItem();
734 9178 : aEEAttr.nPara = nPara;
735 9178 : aEEAttr.nStart = rAttr.GetStart();
736 9178 : aEEAttr.nEnd = rAttr.GetEnd();
737 9178 : rLst.push_back(aEEAttr);
738 : }
739 : }
740 1220 : }
741 :
742 0 : void ImpEditEngine::ParaAttribsToCharAttribs( ContentNode* pNode )
743 : {
744 0 : pNode->GetCharAttribs().DeleteEmptyAttribs( GetEditDoc().GetItemPool() );
745 0 : sal_Int32 nEndPos = pNode->Len();
746 0 : for ( sal_uInt16 nWhich = EE_CHAR_START; nWhich <= EE_CHAR_END; nWhich++ )
747 : {
748 0 : if ( pNode->GetContentAttribs().HasItem( nWhich ) )
749 : {
750 0 : const SfxPoolItem& rItem = pNode->GetContentAttribs().GetItem( nWhich );
751 : // Fill the gap:
752 0 : sal_Int32 nLastEnd = 0;
753 0 : const EditCharAttrib* pAttr = pNode->GetCharAttribs().FindNextAttrib( nWhich, nLastEnd );
754 0 : while ( pAttr )
755 : {
756 0 : nLastEnd = pAttr->GetEnd();
757 0 : if ( pAttr->GetStart() > nLastEnd )
758 0 : aEditDoc.InsertAttrib( pNode, nLastEnd, pAttr->GetStart(), rItem );
759 : // #112831# Last Attr might go from 0xffff to 0x0000
760 0 : pAttr = nLastEnd ? pNode->GetCharAttribs().FindNextAttrib( nWhich, nLastEnd ) : NULL;
761 : }
762 :
763 : // And the Rest:
764 0 : if ( nLastEnd < nEndPos )
765 0 : aEditDoc.InsertAttrib( pNode, nLastEnd, nEndPos, rItem );
766 : }
767 : }
768 0 : bFormatted = false;
769 : // Portion does not need to be invalidated here, happens elsewhere.
770 0 : }
771 :
772 51673 : IdleFormattter::IdleFormattter()
773 : {
774 51673 : pView = 0;
775 51673 : nRestarts = 0;
776 51673 : }
777 :
778 102558 : IdleFormattter::~IdleFormattter()
779 : {
780 51279 : pView = 0;
781 51279 : }
782 :
783 0 : void IdleFormattter::DoIdleFormat( EditView* pV )
784 : {
785 0 : pView = pV;
786 :
787 0 : if ( IsActive() )
788 0 : nRestarts++;
789 :
790 0 : if ( nRestarts > 4 )
791 0 : ForceTimeout();
792 : else
793 0 : Start();
794 0 : }
795 :
796 4118 : void IdleFormattter::ForceTimeout()
797 : {
798 4118 : if ( IsActive() )
799 : {
800 0 : Stop();
801 0 : ((Link&)GetTimeoutHdl()).Call( this );
802 : }
803 4118 : }
804 :
805 0 : ImplIMEInfos::ImplIMEInfos( const EditPaM& rPos, const OUString& rOldTextAfterStartPos )
806 0 : : aOldTextAfterStartPos( rOldTextAfterStartPos )
807 : {
808 0 : aPos = rPos;
809 0 : nLen = 0;
810 0 : bCursor = true;
811 0 : pAttribs = NULL;
812 0 : bWasCursorOverwrite = false;
813 0 : }
814 :
815 0 : ImplIMEInfos::~ImplIMEInfos()
816 : {
817 0 : delete[] pAttribs;
818 0 : }
819 :
820 0 : void ImplIMEInfos::CopyAttribs( const sal_uInt16* pA, sal_uInt16 nL )
821 : {
822 0 : nLen = nL;
823 0 : delete[] pAttribs;
824 0 : pAttribs = new sal_uInt16[ nL ];
825 0 : memcpy( pAttribs, pA, nL*sizeof(sal_uInt16) );
826 0 : }
827 :
828 0 : void ImplIMEInfos::DestroyAttribs()
829 : {
830 0 : delete[] pAttribs;
831 0 : pAttribs = NULL;
832 0 : nLen = 0;
833 669 : }
834 :
835 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|