Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <UndoInsert.hxx>
31 : :
32 : : #include <hintids.hxx>
33 : : #include <unotools/charclass.hxx>
34 : : #include <sot/storage.hxx>
35 : : #include <editeng/keepitem.hxx>
36 : : #include <svx/svdobj.hxx>
37 : :
38 : : #include <docsh.hxx>
39 : : #include <fmtcntnt.hxx>
40 : : #include <fmtanchr.hxx>
41 : : #include <frmfmt.hxx>
42 : : #include <doc.hxx>
43 : : #include <IDocumentUndoRedo.hxx>
44 : : #include <swundo.hxx>
45 : : #include <pam.hxx>
46 : : #include <ndtxt.hxx>
47 : : #include <UndoCore.hxx>
48 : : #include <UndoDelete.hxx>
49 : : #include <UndoAttribute.hxx>
50 : : #include <rolbck.hxx>
51 : : #include <ndgrf.hxx>
52 : : #include <ndole.hxx>
53 : : #include <grfatr.hxx>
54 : : #include <cntfrm.hxx>
55 : : #include <flyfrm.hxx>
56 : : #include <fesh.hxx>
57 : : #include <swtable.hxx>
58 : : #include <redline.hxx>
59 : : #include <docary.hxx>
60 : : #include <acorrect.hxx>
61 : : #include <dcontact.hxx>
62 : :
63 : : #include <comcore.hrc> // #111827#
64 : : #include <undo.hrc>
65 : :
66 : : using namespace ::com::sun::star;
67 : :
68 : :
69 : : //------------------------------------------------------------
70 : :
71 : : // INSERT
72 : :
73 : 7218 : String * SwUndoInsert::GetTxtFromDoc() const
74 : : {
75 : 7218 : String * pResult = NULL;
76 : :
77 [ + - ][ + - ]: 7218 : SwNodeIndex aNd( pDoc->GetNodes(), nNode);
78 : 7218 : SwCntntNode* pCNd = aNd.GetNode().GetCntntNode();
79 [ + - ]: 7218 : SwPaM aPaM( *pCNd, nCntnt );
80 : :
81 [ + - ]: 7218 : aPaM.SetMark();
82 : :
83 [ + - ]: 7218 : if( pCNd->IsTxtNode() )
84 : : {
85 : : pResult = new String( ((SwTxtNode*)pCNd)->GetTxt().Copy(nCntnt-nLen,
86 [ + - ][ + - ]: 7218 : nLen ) );
87 : :
88 : : }
89 : :
90 [ + - ][ + - ]: 7218 : return pResult;
91 : : }
92 : :
93 : 7216 : void SwUndoInsert::Init(const SwNodeIndex & rNd)
94 : : {
95 : : // consider Redline
96 : 7216 : pDoc = rNd.GetNode().GetDoc();
97 [ - + ]: 7216 : if( pDoc->IsRedlineOn() )
98 : : {
99 : : pRedlData = new SwRedlineData( nsRedlineType_t::REDLINE_INSERT,
100 [ # # ]: 0 : pDoc->GetRedlineAuthor() );
101 : 0 : SetRedlineMode( pDoc->GetRedlineMode() );
102 : : }
103 : :
104 : 7216 : pUndoTxt = GetTxtFromDoc();
105 : :
106 : 7216 : bCacheComment = false;
107 : 7216 : }
108 : :
109 : : // #111827#
110 : 7194 : SwUndoInsert::SwUndoInsert( const SwNodeIndex& rNd, xub_StrLen nCnt,
111 : : xub_StrLen nL,
112 : : const IDocumentContentOperations::InsertFlags nInsertFlags,
113 : : sal_Bool bWDelim )
114 : : : SwUndo(UNDO_TYPING), pPos( 0 ), pTxt( 0 ), pRedlData( 0 ),
115 : 7194 : nNode( rNd.GetIndex() ), nCntnt(nCnt), nLen(nL),
116 : : bIsWordDelim( bWDelim ), bIsAppend( sal_False )
117 [ + - ]: 7194 : , m_nInsertFlags(nInsertFlags)
118 : : {
119 [ + - ]: 7194 : Init(rNd);
120 : 7194 : }
121 : :
122 : : // #111827#
123 : 22 : SwUndoInsert::SwUndoInsert( const SwNodeIndex& rNd )
124 : : : SwUndo(UNDO_SPLITNODE), pPos( 0 ), pTxt( 0 ),
125 : 22 : pRedlData( 0 ), nNode( rNd.GetIndex() ), nCntnt(0), nLen(1),
126 : : bIsWordDelim( sal_False ), bIsAppend( sal_True )
127 [ + - ]: 22 : , m_nInsertFlags(IDocumentContentOperations::INS_EMPTYEXPAND)
128 : : {
129 [ + - ]: 22 : Init(rNd);
130 : 22 : }
131 : :
132 : : // Check if the next Insert can be combined with the current one. If so
133 : : // change the length and InsPos. As a result, SwDoc::Inser will not add a
134 : : // new object into the Undo list.
135 : :
136 : 266 : sal_Bool SwUndoInsert::CanGrouping( sal_Unicode cIns )
137 : : {
138 [ + - ][ + + ]: 798 : if( !bIsAppend && bIsWordDelim ==
[ + + ]
139 [ + - ][ + - ]: 532 : !GetAppCharClass().isLetterNumeric( rtl::OUString( cIns )) )
[ + - ][ + - ]
[ + - ][ + - ]
[ # # # # ]
140 : : {
141 : 260 : nLen++;
142 : 260 : nCntnt++;
143 : :
144 [ + - ]: 260 : if (pUndoTxt)
145 : 260 : pUndoTxt->Insert(cIns);
146 : :
147 : 260 : return sal_True;
148 : : }
149 : 266 : return sal_False;
150 : : }
151 : :
152 : 94 : sal_Bool SwUndoInsert::CanGrouping( const SwPosition& rPos )
153 : : {
154 : 94 : sal_Bool bRet = sal_False;
155 [ + - + + ]: 188 : if( nNode == rPos.nNode.GetIndex() &&
[ + + ]
156 : 94 : nCntnt == rPos.nContent.GetIndex() )
157 : : {
158 : : // consider Redline
159 : 92 : SwDoc& rDoc = *rPos.nNode.GetNode().GetDoc();
160 [ + - ]: 184 : if( ( ~nsRedlineMode_t::REDLINE_SHOW_MASK & rDoc.GetRedlineMode() ) ==
161 : 92 : ( ~nsRedlineMode_t::REDLINE_SHOW_MASK & GetRedlineMode() ) )
162 : : {
163 : 92 : bRet = sal_True;
164 : :
165 : : // than there is or was still an active Redline:
166 : : // Check if there is another Redline at the InsPosition. If the
167 : : // same exists only once, it can be combined.
168 : 92 : const SwRedlineTbl& rTbl = rDoc.GetRedlineTbl();
169 [ - + ]: 92 : if( !rTbl.empty() )
170 : : {
171 [ # # ][ # # ]: 0 : SwRedlineData aRData( nsRedlineType_t::REDLINE_INSERT, rDoc.GetRedlineAuthor() );
172 : 0 : const SwIndexReg* pIReg = rPos.nContent.GetIdxReg();
173 : : SwIndex* pIdx;
174 [ # # ]: 0 : for( sal_uInt16 i = 0; i < rTbl.size(); ++i )
175 : : {
176 [ # # ]: 0 : SwRedline* pRedl = rTbl[ i ];
177 [ # # ]: 0 : if( pIReg == (pIdx = &pRedl->End()->nContent)->GetIdxReg() &&
[ # # # # ]
[ # # ]
178 : 0 : nCntnt == pIdx->GetIndex() )
179 : : {
180 [ # # ][ # # ]: 0 : if( !pRedl->HasMark() || !pRedlData ||
[ # # ][ # # ]
[ # # ]
181 [ # # ][ # # ]: 0 : *pRedl != *pRedlData || *pRedl != aRData )
182 : : {
183 : 0 : bRet = sal_False;
184 : 0 : break;
185 : : }
186 : : }
187 [ # # ]: 0 : }
188 : : }
189 : : }
190 : : }
191 : 94 : return bRet;
192 : : }
193 : :
194 [ + - ]: 7198 : SwUndoInsert::~SwUndoInsert()
195 : : {
196 [ - + ]: 7198 : if( pPos ) // delete the section from UndoNodes array
197 : : {
198 : : // Insert saves the content in IconSection
199 : 0 : SwNodes& rUNds = pPos->nNode.GetNode().GetNodes();
200 [ # # ]: 0 : if( pPos->nContent.GetIndex() ) // do not delete the whole node
201 : : {
202 : 0 : SwTxtNode* pTxtNd = pPos->nNode.GetNode().GetTxtNode();
203 : : OSL_ENSURE( pTxtNd, "no TextNode to delete from" );
204 [ # # ]: 0 : pTxtNd->EraseText( pPos->nContent );
205 [ # # ]: 0 : pPos->nNode++;
206 : : }
207 [ # # ]: 0 : pPos->nContent.Assign( 0, 0 );
208 : 0 : rUNds.Delete( pPos->nNode, rUNds.GetEndOfExtras().GetIndex() -
209 [ # # ]: 0 : pPos->nNode.GetIndex() );
210 [ # # ][ # # ]: 0 : delete pPos;
211 : : }
212 [ + + ]: 7198 : else if( pTxt ) // the inserted text
213 [ + - ][ + - ]: 4 : delete pTxt;
214 [ - + ][ # # ]: 7198 : delete pRedlData;
215 [ + + ][ + - ]: 7198 : delete pUndoTxt;
216 [ - + ]: 14396 : }
217 : :
218 : :
219 : :
220 : 6 : void SwUndoInsert::UndoImpl(::sw::UndoRedoContext & rContext)
221 : : {
222 : 6 : SwDoc *const pTmpDoc = & rContext.GetDoc();
223 : 6 : SwPaM *const pPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
224 : :
225 [ - + ]: 6 : if( bIsAppend )
226 : : {
227 : 0 : pPam->GetPoint()->nNode = nNode;
228 : :
229 [ # # ]: 0 : if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
230 : : {
231 [ # # ]: 0 : pPam->GetPoint()->nContent.Assign( pPam->GetCntntNode(), 0 );
232 : 0 : pPam->SetMark();
233 : 0 : pPam->Move( fnMoveBackward );
234 : 0 : pPam->Exchange();
235 : 0 : pTmpDoc->DeleteRedline( *pPam, true, USHRT_MAX );
236 : : }
237 : 0 : pPam->DeleteMark();
238 : 0 : pTmpDoc->DelFullPara( *pPam );
239 [ # # ]: 0 : pPam->GetPoint()->nContent.Assign( pPam->GetCntntNode(), 0 );
240 : : }
241 : : else
242 : : {
243 : 6 : sal_uLong nNd = nNode;
244 : 6 : xub_StrLen nCnt = nCntnt;
245 [ + - ]: 6 : if( nLen )
246 : : {
247 [ + - ][ + - ]: 6 : SwNodeIndex aNd( pTmpDoc->GetNodes(), nNode);
248 : 6 : SwCntntNode* pCNd = aNd.GetNode().GetCntntNode();
249 [ + - ]: 6 : SwPaM aPaM( *pCNd, nCntnt );
250 : :
251 [ + - ]: 6 : aPaM.SetMark();
252 : :
253 : 6 : SwTxtNode * const pTxtNode( pCNd->GetTxtNode() );
254 [ + - ]: 6 : if ( pTxtNode )
255 : : {
256 [ + - ]: 6 : aPaM.GetPoint()->nContent -= nLen;
257 [ - + ]: 6 : if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
258 [ # # ]: 0 : pTmpDoc->DeleteRedline( aPaM, true, USHRT_MAX );
259 [ + - ]: 6 : RemoveIdxFromRange( aPaM, sal_False );
260 [ + - ][ + - ]: 6 : pTxt = new String( pTxtNode->GetTxt().Copy(nCntnt-nLen, nLen) );
261 [ + - ]: 6 : pTxtNode->EraseText( aPaM.GetPoint()->nContent, nLen );
262 : : }
263 : : else // otherwise Graphics/OLE/Text/...
264 : : {
265 [ # # ]: 0 : aPaM.Move(fnMoveBackward);
266 [ # # ]: 0 : if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
267 [ # # ]: 0 : pTmpDoc->DeleteRedline( aPaM, true, USHRT_MAX );
268 [ # # ]: 0 : RemoveIdxFromRange( aPaM, sal_False );
269 : : }
270 : :
271 : 6 : nNd = aPaM.GetPoint()->nNode.GetIndex();
272 : 6 : nCnt = aPaM.GetPoint()->nContent.GetIndex();
273 : :
274 [ - + ]: 6 : if( !pTxt )
275 : : {
276 [ # # ][ # # ]: 0 : pPos = new SwPosition( *aPaM.GetPoint() );
277 [ # # ]: 0 : MoveToUndoNds( aPaM, &pPos->nNode, &pPos->nContent );
278 : : }
279 : 6 : nNode = aPaM.GetPoint()->nNode.GetIndex();
280 [ + - ][ + - ]: 6 : nCntnt = aPaM.GetPoint()->nContent.GetIndex();
281 : : }
282 : :
283 : : // set cursor to Undo range
284 : 6 : pPam->DeleteMark();
285 : :
286 : 6 : pPam->GetPoint()->nNode = nNd;
287 : 6 : pPam->GetPoint()->nContent.Assign(
288 [ + - ]: 12 : pPam->GetPoint()->nNode.GetNode().GetCntntNode(), nCnt );
289 : : }
290 : :
291 [ + - ]: 6 : DELETEZ(pUndoTxt);
292 : 6 : }
293 : :
294 : :
295 : 2 : void SwUndoInsert::RedoImpl(::sw::UndoRedoContext & rContext)
296 : : {
297 : 2 : SwDoc *const pTmpDoc = & rContext.GetDoc();
298 : 2 : SwPaM *const pPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
299 : 2 : pPam->DeleteMark();
300 : :
301 [ - + ]: 2 : if( bIsAppend )
302 : : {
303 : 0 : pPam->GetPoint()->nNode = nNode - 1;
304 : 0 : pTmpDoc->AppendTxtNode( *pPam->GetPoint() );
305 : :
306 : 0 : pPam->SetMark();
307 : 0 : pPam->Move( fnMoveBackward );
308 : 0 : pPam->Exchange();
309 : :
310 [ # # ][ # # ]: 0 : if( pRedlData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
[ # # ]
311 : : {
312 : 0 : RedlineMode_t eOld = pTmpDoc->GetRedlineMode();
313 : 0 : pTmpDoc->SetRedlineMode_intern((RedlineMode_t)(eOld & ~nsRedlineMode_t::REDLINE_IGNORE));
314 [ # # ]: 0 : pTmpDoc->AppendRedline( new SwRedline( *pRedlData, *pPam ), true);
315 : 0 : pTmpDoc->SetRedlineMode_intern( eOld );
316 : : }
317 [ # # # # ]: 0 : else if( !( nsRedlineMode_t::REDLINE_IGNORE & GetRedlineMode() ) &&
[ # # ]
318 : 0 : !pTmpDoc->GetRedlineTbl().empty() )
319 : 0 : pTmpDoc->SplitRedline( *pPam );
320 : :
321 : 0 : pPam->DeleteMark();
322 : : }
323 : : else
324 : : {
325 : 2 : pPam->GetPoint()->nNode = nNode;
326 : : SwCntntNode *const pCNd =
327 : 2 : pPam->GetPoint()->nNode.GetNode().GetCntntNode();
328 [ + - ]: 2 : pPam->GetPoint()->nContent.Assign( pCNd, nCntnt );
329 : :
330 [ + - ]: 2 : if( nLen )
331 : : {
332 : 2 : sal_Bool bMvBkwrd = MovePtBackward( *pPam );
333 : :
334 [ + - ]: 2 : if( pTxt )
335 : : {
336 : 2 : SwTxtNode *const pTxtNode = pCNd->GetTxtNode();
337 : : OSL_ENSURE( pTxtNode, "where is my textnode ?" );
338 : 2 : pTxtNode->InsertText( *pTxt, pPam->GetMark()->nContent,
339 : 2 : m_nInsertFlags );
340 [ + - ]: 2 : DELETEZ( pTxt );
341 : : }
342 : : else
343 : : {
344 : : // re-insert content (log out pPos before!)
345 : 0 : sal_uLong nMvNd = pPos->nNode.GetIndex();
346 : 0 : xub_StrLen nMvCnt = pPos->nContent.GetIndex();
347 [ # # ]: 0 : DELETEZ( pPos );
348 : 0 : MoveFromUndoNds( *pTmpDoc, nMvNd, nMvCnt, *pPam->GetMark() );
349 : : }
350 : 2 : nNode = pPam->GetMark()->nNode.GetIndex();
351 : 2 : nCntnt = pPam->GetMark()->nContent.GetIndex();
352 : :
353 : 2 : MovePtForward( *pPam, bMvBkwrd );
354 : 2 : pPam->Exchange();
355 [ # # ][ - + ]: 2 : if( pRedlData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
[ - + ]
356 : : {
357 : 0 : RedlineMode_t eOld = pTmpDoc->GetRedlineMode();
358 : 0 : pTmpDoc->SetRedlineMode_intern((RedlineMode_t)(eOld & ~nsRedlineMode_t::REDLINE_IGNORE));
359 : : pTmpDoc->AppendRedline( new SwRedline( *pRedlData,
360 [ # # ]: 0 : *pPam ), true);
361 : 0 : pTmpDoc->SetRedlineMode_intern( eOld );
362 : : }
363 [ + - - + ]: 4 : else if( !( nsRedlineMode_t::REDLINE_IGNORE & GetRedlineMode() ) &&
[ - + ]
364 : 2 : !pTmpDoc->GetRedlineTbl().empty() )
365 : 0 : pTmpDoc->SplitRedline(*pPam);
366 : : }
367 : : }
368 : :
369 : 2 : pUndoTxt = GetTxtFromDoc();
370 : 2 : }
371 : :
372 : :
373 : 0 : void SwUndoInsert::RepeatImpl(::sw::RepeatContext & rContext)
374 : : {
375 [ # # ]: 0 : if( !nLen )
376 : 0 : return;
377 : :
378 : 0 : SwDoc & rDoc = rContext.GetDoc();
379 [ # # ][ # # ]: 0 : SwNodeIndex aNd( rDoc.GetNodes(), nNode );
380 : 0 : SwCntntNode* pCNd = aNd.GetNode().GetCntntNode();
381 : :
382 [ # # ][ # # ]: 0 : if( !bIsAppend && 1 == nLen ) // >1 than always Text, otherwise Graphics/OLE/Text/...
383 : : {
384 [ # # ]: 0 : SwPaM aPaM( *pCNd, nCntnt );
385 [ # # ]: 0 : aPaM.SetMark();
386 [ # # ]: 0 : aPaM.Move(fnMoveBackward);
387 [ # # ]: 0 : pCNd = aPaM.GetCntntNode();
388 : : }
389 : :
390 : : // What happens with the possible selected range ???
391 : :
392 [ # # # # ]: 0 : switch( pCNd->GetNodeType() )
393 : : {
394 : : case ND_TEXTNODE:
395 [ # # ]: 0 : if( bIsAppend )
396 : : {
397 [ # # ]: 0 : rDoc.AppendTxtNode( *rContext.GetRepeatPaM().GetPoint() );
398 : : }
399 : : else
400 : : {
401 [ # # ]: 0 : String aTxt( ((SwTxtNode*)pCNd)->GetTxt() );
402 [ # # ][ # # ]: 0 : ::sw::GroupUndoGuard const undoGuard(rDoc.GetIDocumentUndoRedo());
403 : 0 : rDoc.InsertString( rContext.GetRepeatPaM(),
404 [ # # # # ]: 0 : aTxt.Copy( nCntnt - nLen, nLen ) );
[ # # ][ # # ]
[ # # ]
405 : : }
406 : 0 : break;
407 : : case ND_GRFNODE:
408 : : {
409 : 0 : SwGrfNode* pGrfNd = (SwGrfNode*)pCNd;
410 [ # # ][ # # ]: 0 : String sFile, sFilter;
411 [ # # ]: 0 : if( pGrfNd->IsGrfLink() )
412 [ # # ]: 0 : pGrfNd->GetFileFilterNms( &sFile, &sFilter );
413 : :
414 : 0 : rDoc.Insert( rContext.GetRepeatPaM(), sFile, sFilter,
415 [ # # ]: 0 : &pGrfNd->GetGrf(),
416 [ # # ][ # # ]: 0 : 0/* Graphics collection*/, NULL, NULL );
[ # # ]
417 : : }
418 : 0 : break;
419 : :
420 : : case ND_OLENODE:
421 : : {
422 : : // StarView does not yet provide an option to copy a StarOBJ
423 [ # # ][ # # ]: 0 : SvStorageRef aRef = new SvStorage( aEmptyStr );
424 : 0 : SwOLEObj& rSwOLE = (SwOLEObj&)((SwOLENode*)pCNd)->GetOLEObj();
425 : :
426 : : // temporary storage until object is inserted
427 : : // TODO/MBA: seems that here a physical copy is done - not as in drawing layer! Testing!
428 : : // TODO/LATER: Copying through the container would copy the replacement image as well
429 [ # # ]: 0 : comphelper::EmbeddedObjectContainer aCnt;
430 [ # # ]: 0 : ::rtl::OUString aName = aCnt.CreateUniqueObjectName();
431 [ # # ][ # # ]: 0 : if ( aCnt.StoreEmbeddedObject( rSwOLE.GetOleRef(), aName, sal_True ) )
[ # # ]
432 : : {
433 [ # # ]: 0 : uno::Reference < embed::XEmbeddedObject > aNew = aCnt.GetEmbeddedObject( aName );
434 : 0 : rDoc.Insert( rContext.GetRepeatPaM(),
435 : : svt::EmbeddedObjectRef( aNew,
436 : : static_cast<SwOLENode*>(pCNd)->GetAspect() ),
437 [ # # ]: 0 : NULL, NULL, NULL );
[ # # # # ]
[ # # ]
438 : : }
439 : :
440 [ # # ][ # # ]: 0 : break;
441 : : }
442 [ # # ]: 0 : }
443 : : }
444 : :
445 : : // #111827#
446 : 7237 : SwRewriter SwUndoInsert::GetRewriter() const
447 : : {
448 : 7237 : SwRewriter aResult;
449 : 7237 : String * pStr = NULL;
450 : 7237 : bool bDone = false;
451 : :
452 [ - + ]: 7237 : if (pTxt)
453 : 0 : pStr = pTxt;
454 [ + - ]: 7237 : else if (pUndoTxt)
455 : 7237 : pStr = pUndoTxt;
456 : :
457 [ + - ]: 7237 : if (pStr)
458 : : {
459 : : String aString = ShortenString(DenoteSpecialCharacters(*pStr),
460 : : nUndoStringLength,
461 [ + - ][ + - ]: 7237 : String(SW_RES(STR_LDOTS)));
[ + - ][ + - ]
[ + - ]
462 : :
463 [ + - ]: 7237 : aResult.AddRule(UndoArg1, aString);
464 : :
465 [ + - ]: 7237 : bDone = true;
466 : : }
467 : :
468 [ - + ]: 7237 : if ( ! bDone )
469 : : {
470 [ # # ][ # # ]: 0 : aResult.AddRule(UndoArg1, String("??", RTL_TEXTENCODING_ASCII_US));
[ # # ]
471 : : }
472 : :
473 : 7237 : return aResult;
474 : : }
475 : :
476 : :
477 : : // SwUndoReplace /////////////////////////////////////////////////////////
478 : :
479 : :
480 : : class SwUndoReplace::Impl
481 : : : private SwUndoSaveCntnt
482 : : {
483 : : ::rtl::OUString m_sOld;
484 : : ::rtl::OUString m_sIns;
485 : : sal_uLong m_nSttNd, m_nEndNd, m_nOffset;
486 : : xub_StrLen m_nSttCnt, m_nEndCnt, m_nSetPos, m_nSelEnd;
487 : : bool m_bSplitNext : 1;
488 : : bool m_bRegExp : 1;
489 : : // metadata references for paragraph and following para (if m_bSplitNext)
490 : : ::boost::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndoStart;
491 : : ::boost::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndoEnd;
492 : :
493 : : public:
494 : : Impl(SwPaM const& rPam, ::rtl::OUString const& rIns, bool const bRegExp);
495 : 176 : virtual ~Impl()
496 [ + - ][ + - ]: 88 : {
497 [ - + ]: 176 : }
498 : :
499 : : virtual void UndoImpl( ::sw::UndoRedoContext & );
500 : : virtual void RedoImpl( ::sw::UndoRedoContext & );
501 : :
502 : : void SetEnd(SwPaM const& rPam);
503 : :
504 : 88 : ::rtl::OUString const& GetOld() const { return m_sOld; }
505 : 88 : ::rtl::OUString const& GetIns() const { return m_sIns; }
506 : : };
507 : :
508 : :
509 : 88 : SwUndoReplace::SwUndoReplace(SwPaM const& rPam,
510 : : ::rtl::OUString const& rIns, bool const bRegExp)
511 : : : SwUndo( UNDO_REPLACE )
512 [ + - ][ + - ]: 88 : , m_pImpl(new Impl(rPam, rIns, bRegExp))
513 : : {
514 : 88 : }
515 : :
516 [ + - ]: 88 : SwUndoReplace::~SwUndoReplace()
517 : : {
518 [ - + ]: 176 : }
519 : :
520 : 0 : void SwUndoReplace::UndoImpl(::sw::UndoRedoContext & rContext)
521 : : {
522 : 0 : m_pImpl->UndoImpl(rContext);
523 : 0 : }
524 : :
525 : 0 : void SwUndoReplace::RedoImpl(::sw::UndoRedoContext & rContext)
526 : : {
527 : 0 : m_pImpl->RedoImpl(rContext);
528 : 0 : }
529 : :
530 : : SwRewriter
531 : 92 : MakeUndoReplaceRewriter(sal_uLong const occurrences,
532 : : ::rtl::OUString const& sOld, ::rtl::OUString const& sNew)
533 : : {
534 : 92 : SwRewriter aResult;
535 : :
536 [ + + ]: 92 : if (1 < occurrences)
537 : : {
538 [ + - ][ + - ]: 4 : aResult.AddRule(UndoArg1, String::CreateFromInt32(occurrences));
[ + - ]
539 [ + - ][ + - ]: 4 : aResult.AddRule(UndoArg2, String(SW_RES(STR_OCCURRENCES_OF)));
[ + - ]
540 : :
541 [ + - ]: 4 : String aTmpStr;
542 [ + - ][ + - ]: 4 : aTmpStr += String(SW_RES(STR_START_QUOTE));
[ + - ]
543 : : aTmpStr += ShortenString(sOld, nUndoStringLength,
544 [ + - ][ + - ]: 4 : SW_RES(STR_LDOTS));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
545 [ + - ][ + - ]: 4 : aTmpStr += String(SW_RES(STR_END_QUOTE));
[ + - ]
546 [ + - ][ + - ]: 4 : aResult.AddRule(UndoArg3, aTmpStr);
547 : : }
548 [ + - ]: 88 : else if (1 == occurrences)
549 : : {
550 : : {
551 [ + - ]: 88 : String aTmpStr;
552 : :
553 [ + - ][ + - ]: 88 : aTmpStr += String(SW_RES(STR_START_QUOTE));
[ + - ]
554 : : // #i33488 #
555 : : aTmpStr += ShortenString(sOld, nUndoStringLength,
556 [ + - ][ + - ]: 88 : SW_RES(STR_LDOTS));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
557 [ + - ][ + - ]: 88 : aTmpStr += String(SW_RES(STR_END_QUOTE));
[ + - ]
558 [ + - ][ + - ]: 88 : aResult.AddRule(UndoArg1, aTmpStr);
559 : : }
560 : :
561 [ + - ][ + - ]: 88 : aResult.AddRule(UndoArg2, String(SW_RES(STR_YIELDS)));
[ + - ]
562 : :
563 : : {
564 [ + - ]: 88 : String aTmpStr;
565 : :
566 [ + - ][ + - ]: 88 : aTmpStr += String(SW_RES(STR_START_QUOTE));
[ + - ]
567 : : // #i33488 #
568 : : aTmpStr += ShortenString(sNew, nUndoStringLength,
569 [ + - ][ + - ]: 88 : SW_RES(STR_LDOTS));
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
570 [ + - ][ + - ]: 88 : aTmpStr += String(SW_RES(STR_END_QUOTE));
[ + - ]
571 [ + - ][ + - ]: 88 : aResult.AddRule(UndoArg3, aTmpStr);
572 : : }
573 : : }
574 : :
575 : 92 : return aResult;
576 : : }
577 : :
578 : : // #111827#
579 : 88 : SwRewriter SwUndoReplace::GetRewriter() const
580 : : {
581 : 88 : return MakeUndoReplaceRewriter(1, m_pImpl->GetOld(), m_pImpl->GetIns());
582 : : }
583 : :
584 : 88 : void SwUndoReplace::SetEnd(SwPaM const& rPam)
585 : : {
586 : 88 : m_pImpl->SetEnd(rPam);
587 : 88 : }
588 : :
589 : 88 : SwUndoReplace::Impl::Impl(
590 : : SwPaM const& rPam, ::rtl::OUString const& rIns, bool const bRegExp)
591 : : : m_sIns( rIns )
592 : : , m_nOffset( 0 )
593 [ + - ][ + - ]: 88 : , m_bRegExp(bRegExp)
594 : : {
595 : :
596 [ + - ]: 88 : const SwPosition * pStt( rPam.Start() );
597 [ + - ]: 88 : const SwPosition * pEnd( rPam.End() );
598 : :
599 : 88 : m_nSttNd = m_nEndNd = pStt->nNode.GetIndex();
600 : 88 : m_nSttCnt = pStt->nContent.GetIndex();
601 : 88 : m_nSelEnd = m_nEndCnt = pEnd->nContent.GetIndex();
602 : :
603 : 88 : m_bSplitNext = m_nSttNd != pEnd->nNode.GetIndex();
604 : :
605 : 88 : SwTxtNode* pNd = pStt->nNode.GetNode().GetTxtNode();
606 : : OSL_ENSURE( pNd, "Dude, where's my TextNode?" );
607 : :
608 [ + - ][ + - ]: 88 : pHistory = new SwHistory;
609 [ + - ]: 88 : DelCntntIndex( *rPam.GetMark(), *rPam.GetPoint() );
610 : :
611 : 88 : m_nSetPos = pHistory->Count();
612 : :
613 : 88 : sal_uLong nNewPos = pStt->nNode.GetIndex();
614 : 88 : m_nOffset = m_nSttNd - nNewPos;
615 : :
616 [ - + ]: 88 : if ( pNd->GetpSwpHints() )
617 : : {
618 : : pHistory->CopyAttr( pNd->GetpSwpHints(), nNewPos, 0,
619 [ # # ]: 0 : pNd->GetTxt().Len(), true );
620 : : }
621 : :
622 [ - + ]: 88 : if ( m_bSplitNext )
623 : : {
624 [ # # ][ # # ]: 0 : if( pNd->HasSwAttrSet() )
625 [ # # ][ # # ]: 0 : pHistory->CopyFmtAttr( *pNd->GetpSwAttrSet(), nNewPos );
626 [ # # ]: 0 : pHistory->Add( pNd->GetTxtColl(), nNewPos, ND_TEXTNODE );
627 : :
628 : 0 : SwTxtNode* pNext = pEnd->nNode.GetNode().GetTxtNode();
629 : 0 : sal_uLong nTmp = pNext->GetIndex();
630 : : pHistory->CopyAttr( pNext->GetpSwpHints(), nTmp, 0,
631 [ # # ]: 0 : pNext->GetTxt().Len(), true );
632 [ # # ][ # # ]: 0 : if( pNext->HasSwAttrSet() )
633 [ # # ][ # # ]: 0 : pHistory->CopyFmtAttr( *pNext->GetpSwAttrSet(), nTmp );
634 [ # # ]: 0 : pHistory->Add( pNext->GetTxtColl(),nTmp, ND_TEXTNODE );
635 : : // METADATA: store
636 [ # # ][ # # ]: 0 : m_pMetadataUndoStart = pNd ->CreateUndo();
[ # # ]
637 [ # # ][ # # ]: 0 : m_pMetadataUndoEnd = pNext->CreateUndo();
[ # # ]
638 : : }
639 : :
640 [ + + ]: 88 : if( !pHistory->Count() )
641 [ + - ][ + - ]: 44 : delete pHistory, pHistory = 0;
642 : :
643 : 0 : xub_StrLen nECnt = m_bSplitNext ? pNd->GetTxt().Len()
644 [ - + ]: 88 : : pEnd->nContent.GetIndex();
645 [ + - ][ + - ]: 88 : m_sOld = pNd->GetTxt().Copy( m_nSttCnt, nECnt - m_nSttCnt );
[ + - ]
646 : 88 : }
647 : :
648 : 0 : void SwUndoReplace::Impl::UndoImpl(::sw::UndoRedoContext & rContext)
649 : : {
650 : 0 : SwDoc *const pDoc = & rContext.GetDoc();
651 [ # # ]: 0 : SwPaM & rPam(rContext.GetCursorSupplier().CreateNewShellCursor());
652 [ # # ]: 0 : rPam.DeleteMark();
653 : :
654 [ # # ][ # # ]: 0 : SwTxtNode* pNd = pDoc->GetNodes()[ m_nSttNd - m_nOffset ]->GetTxtNode();
655 : : OSL_ENSURE( pNd, "Dude, where's my TextNode?" );
656 : :
657 : 0 : SwAutoCorrExceptWord* pACEWord = pDoc->GetAutoCorrExceptWord();
658 [ # # ]: 0 : if( pACEWord )
659 : : {
660 [ # # ][ # # ]: 0 : if ((1 == m_sIns.getLength()) && (1 == m_sOld.getLength()))
[ # # ]
661 : : {
662 [ # # ][ # # ]: 0 : SwPosition aPos( *pNd ); aPos.nContent.Assign( pNd, m_nSttCnt );
[ # # ]
663 [ # # ][ # # ]: 0 : pACEWord->CheckChar( aPos, m_sOld[ 0 ] );
664 : : }
665 [ # # ]: 0 : pDoc->SetAutoCorrExceptWord( 0 );
666 : : }
667 : :
668 [ # # ][ # # ]: 0 : SwIndex aIdx( pNd, m_nSttCnt );
669 [ # # ]: 0 : if( m_nSttNd == m_nEndNd )
670 : : {
671 [ # # ]: 0 : pNd->EraseText( aIdx, sal_uInt16( m_sIns.getLength() ) );
672 : : }
673 : : else
674 : : {
675 [ # # ]: 0 : rPam.GetPoint()->nNode = *pNd;
676 [ # # ][ # # ]: 0 : rPam.GetPoint()->nContent.Assign( pNd, m_nSttCnt );
677 [ # # ]: 0 : rPam.SetMark();
678 [ # # ]: 0 : rPam.GetPoint()->nNode = m_nEndNd - m_nOffset;
679 [ # # ][ # # ]: 0 : rPam.GetPoint()->nContent.Assign( rPam.GetCntntNode(), m_nEndCnt );
680 : : // move it out of the way so it is not registered at deleted node
681 [ # # ]: 0 : aIdx.Assign(0, 0);
682 : :
683 [ # # ]: 0 : pDoc->DeleteAndJoin( rPam );
684 [ # # ]: 0 : rPam.DeleteMark();
685 : 0 : pNd = rPam.GetNode()->GetTxtNode();
686 : : OSL_ENSURE( pNd, "Dude, where's my TextNode?" );
687 [ # # ][ # # ]: 0 : aIdx.Assign( pNd, m_nSttCnt );
688 : : }
689 : :
690 [ # # ]: 0 : if( m_bSplitNext )
691 : : {
692 [ # # ][ # # ]: 0 : SwPosition aPos( *pNd, aIdx );
[ # # ]
693 [ # # ]: 0 : pDoc->SplitNode( aPos, false );
694 [ # # ]: 0 : pNd->RestoreMetadata(m_pMetadataUndoEnd);
695 [ # # ][ # # ]: 0 : pNd = pDoc->GetNodes()[ m_nSttNd - m_nOffset ]->GetTxtNode();
696 [ # # ][ # # ]: 0 : aIdx.Assign( pNd, m_nSttCnt );
697 : : // METADATA: restore
698 [ # # ][ # # ]: 0 : pNd->RestoreMetadata(m_pMetadataUndoStart);
699 : : }
700 : :
701 [ # # ]: 0 : if (!m_sOld.isEmpty())
702 : : {
703 [ # # ][ # # ]: 0 : pNd->InsertText( m_sOld, aIdx );
[ # # ]
704 : : }
705 : :
706 [ # # ]: 0 : if( pHistory )
707 : : {
708 [ # # ]: 0 : if( pNd->GetpSwpHints() )
709 [ # # ]: 0 : pNd->ClearSwpHintsArr( true );
710 : :
711 [ # # ]: 0 : pHistory->TmpRollback( pDoc, m_nSetPos, false );
712 [ # # ]: 0 : if ( m_nSetPos ) // there were footnotes/FlyFrames
713 : : {
714 : : // are there others than these?
715 [ # # ]: 0 : if( m_nSetPos < pHistory->Count() )
716 : : {
717 : : // than save those attributes as well
718 [ # # ]: 0 : SwHistory aHstr;
719 [ # # ]: 0 : aHstr.Move( 0, pHistory, m_nSetPos );
720 [ # # ]: 0 : pHistory->Rollback( pDoc );
721 [ # # ][ # # ]: 0 : pHistory->Move( 0, &aHstr );
722 : : }
723 : : else
724 : : {
725 [ # # ]: 0 : pHistory->Rollback( pDoc );
726 [ # # ][ # # ]: 0 : DELETEZ( pHistory );
727 : : }
728 : : }
729 : : }
730 : :
731 [ # # ]: 0 : rPam.GetPoint()->nNode = m_nSttNd;
732 [ # # ][ # # ]: 0 : rPam.GetPoint()->nContent = aIdx;
733 : 0 : }
734 : :
735 : 0 : void SwUndoReplace::Impl::RedoImpl(::sw::UndoRedoContext & rContext)
736 : : {
737 : 0 : SwDoc & rDoc = rContext.GetDoc();
738 : 0 : SwPaM & rPam(rContext.GetCursorSupplier().CreateNewShellCursor());
739 : 0 : rPam.DeleteMark();
740 : 0 : rPam.GetPoint()->nNode = m_nSttNd;
741 : :
742 : 0 : SwTxtNode* pNd = rPam.GetPoint()->nNode.GetNode().GetTxtNode();
743 : : OSL_ENSURE( pNd, "Dude, where's my TextNode?" );
744 [ # # ]: 0 : rPam.GetPoint()->nContent.Assign( pNd, m_nSttCnt );
745 : 0 : rPam.SetMark();
746 [ # # ]: 0 : if( m_bSplitNext )
747 : : {
748 : 0 : rPam.GetPoint()->nNode = m_nSttNd + 1;
749 : 0 : pNd = rPam.GetPoint()->nNode.GetNode().GetTxtNode();
750 : : }
751 [ # # ]: 0 : rPam.GetPoint()->nContent.Assign( pNd, m_nSelEnd );
752 : :
753 [ # # ]: 0 : if( pHistory )
754 : : {
755 : 0 : SwHistory* pSave = pHistory;
756 [ # # ]: 0 : SwHistory aHst;
757 : 0 : pHistory = &aHst;
758 [ # # ]: 0 : DelCntntIndex( *rPam.GetMark(), *rPam.GetPoint() );
759 : 0 : m_nSetPos = pHistory->Count();
760 : :
761 : 0 : pHistory = pSave;
762 [ # # ][ # # ]: 0 : pHistory->Move( 0, &aHst );
763 : : }
764 : : else
765 : : {
766 [ # # ]: 0 : pHistory = new SwHistory;
767 : 0 : DelCntntIndex( *rPam.GetMark(), *rPam.GetPoint() );
768 : 0 : m_nSetPos = pHistory->Count();
769 [ # # ]: 0 : if( !m_nSetPos )
770 [ # # ]: 0 : delete pHistory, pHistory = 0;
771 : : }
772 : :
773 [ # # ]: 0 : rDoc.ReplaceRange( rPam, m_sIns, m_bRegExp );
774 : 0 : rPam.DeleteMark();
775 : 0 : }
776 : :
777 : 88 : void SwUndoReplace::Impl::SetEnd(SwPaM const& rPam)
778 : : {
779 [ - + ]: 88 : if( rPam.GetPoint()->nNode != rPam.GetMark()->nNode )
780 : : {
781 : : // multiple paragraphs were inserted
782 : 0 : const SwPosition* pEnd = rPam.End();
783 : 0 : m_nEndNd = m_nOffset + pEnd->nNode.GetIndex();
784 : 0 : m_nEndCnt = pEnd->nContent.GetIndex();
785 : : }
786 : 88 : }
787 : :
788 : :
789 : : // SwUndoReRead //////////////////////////////////////////////////////////
790 : :
791 : :
792 : 12 : SwUndoReRead::SwUndoReRead( const SwPaM& rPam, const SwGrfNode& rGrfNd )
793 : 12 : : SwUndo( UNDO_REREAD ), nPos( rPam.GetPoint()->nNode.GetIndex() )
794 : : {
795 [ + - ]: 12 : SaveGraphicData( rGrfNd );
796 : 12 : }
797 : :
798 : :
799 : 12 : SwUndoReRead::~SwUndoReRead()
800 : : {
801 [ + + ][ + - ]: 12 : delete pGrf;
802 [ + + ][ + - ]: 12 : delete pNm;
803 [ + + ][ + - ]: 12 : delete pFltr;
804 [ - + ]: 24 : }
805 : :
806 : :
807 : 0 : void SwUndoReRead::SetAndSave(::sw::UndoRedoContext & rContext)
808 : : {
809 : 0 : SwDoc & rDoc = rContext.GetDoc();
810 : 0 : SwGrfNode* pGrfNd = rDoc.GetNodes()[ nPos ]->GetGrfNode();
811 : :
812 [ # # ]: 0 : if( !pGrfNd )
813 : 0 : return ;
814 : :
815 : : // cache the old values
816 : 0 : Graphic* pOldGrf = pGrf;
817 : 0 : String* pOldNm = pNm;
818 : 0 : String* pOldFltr = pFltr;
819 : 0 : sal_uInt16 nOldMirr = nMirr;
820 : :
821 : 0 : SaveGraphicData( *pGrfNd );
822 [ # # ]: 0 : if( pOldNm )
823 : : {
824 [ # # ]: 0 : pGrfNd->ReRead( *pOldNm, pFltr ? *pFltr : aEmptyStr, 0, 0, sal_True );
825 [ # # ]: 0 : delete pOldNm;
826 [ # # ]: 0 : delete pOldFltr;
827 : : }
828 : : else
829 : : {
830 : 0 : pGrfNd->ReRead( aEmptyStr, aEmptyStr, pOldGrf, 0, sal_True );
831 [ # # ]: 0 : delete pOldGrf;
832 : : }
833 : :
834 [ # # ]: 0 : if( RES_MIRROR_GRAPH_DONT != nOldMirr )
835 [ # # ]: 0 : pGrfNd->SetAttr( SwMirrorGrf() );
836 : :
837 : 0 : rContext.SetSelections(pGrfNd->GetFlyFmt(), 0);
838 : : }
839 : :
840 : :
841 : 0 : void SwUndoReRead::UndoImpl(::sw::UndoRedoContext & rContext)
842 : : {
843 : 0 : SetAndSave(rContext);
844 : 0 : }
845 : :
846 : :
847 : 0 : void SwUndoReRead::RedoImpl(::sw::UndoRedoContext & rContext)
848 : : {
849 : 0 : SetAndSave(rContext);
850 : 0 : }
851 : :
852 : :
853 : 12 : void SwUndoReRead::SaveGraphicData( const SwGrfNode& rGrfNd )
854 : : {
855 [ + + ]: 12 : if( rGrfNd.IsGrfLink() )
856 : : {
857 [ + - ]: 4 : pNm = new String;
858 [ + - ]: 4 : pFltr = new String;
859 : 4 : rGrfNd.GetFileFilterNms( pNm, pFltr );
860 : 4 : pGrf = 0;
861 : : }
862 : : else
863 : : {
864 : 8 : ((SwGrfNode&)rGrfNd).SwapIn( sal_True );
865 [ + - ]: 8 : pGrf = new Graphic( rGrfNd.GetGrf() );
866 : 8 : pNm = pFltr = 0;
867 : : }
868 : 12 : nMirr = rGrfNd.GetSwAttrSet().GetMirrorGrf().GetValue();
869 : 12 : }
870 : :
871 : :
872 : 0 : SwUndoInsertLabel::SwUndoInsertLabel( const SwLabelType eTyp,
873 : : const String &rTxt,
874 : : const String& rSeparator,
875 : : const String& rNumberSeparator,
876 : : const sal_Bool bBef,
877 : : const sal_uInt16 nInitId,
878 : : const String& rCharacterStyle,
879 : : const sal_Bool bCpyBorder )
880 : : : SwUndo( UNDO_INSERTLABEL ),
881 : : sText( rTxt ),
882 : : sSeparator( rSeparator ),
883 : : sNumberSeparator( rNumberSeparator ),//#i61007# order of captions
884 : : sCharacterStyle( rCharacterStyle ),
885 : : nFldId( nInitId ),
886 : : eType( eTyp ),
887 : : nLayerId( 0 ),
888 : : bBefore( bBef ),
889 [ # # ][ # # ]: 0 : bCpyBrd( bCpyBorder )
[ # # ][ # # ]
890 : : {
891 : 0 : bUndoKeep = sal_False;
892 : 0 : OBJECT.pUndoFly = 0;
893 : 0 : OBJECT.pUndoAttr = 0;
894 : 0 : }
895 : :
896 [ # # ][ # # ]: 0 : SwUndoInsertLabel::~SwUndoInsertLabel()
[ # # ][ # # ]
897 : : {
898 [ # # ][ # # ]: 0 : if( LTYPE_OBJECT == eType || LTYPE_DRAW == eType )
899 : : {
900 [ # # ][ # # ]: 0 : delete OBJECT.pUndoFly;
901 [ # # ][ # # ]: 0 : delete OBJECT.pUndoAttr;
902 : : }
903 : : else
904 [ # # ][ # # ]: 0 : delete NODE.pUndoInsNd;
905 [ # # ]: 0 : }
906 : :
907 : 0 : void SwUndoInsertLabel::UndoImpl(::sw::UndoRedoContext & rContext)
908 : : {
909 : 0 : SwDoc & rDoc = rContext.GetDoc();
910 : :
911 [ # # ][ # # ]: 0 : if( LTYPE_OBJECT == eType || LTYPE_DRAW == eType )
912 : : {
913 : : OSL_ENSURE( OBJECT.pUndoAttr && OBJECT.pUndoFly, "Pointer not initialized" );
914 : : SwFrmFmt* pFmt;
915 : 0 : SdrObject *pSdrObj = 0;
916 [ # # ][ # # ]: 0 : if( OBJECT.pUndoAttr &&
[ # # ][ # # ]
[ # # ]
917 : 0 : 0 != (pFmt = (SwFrmFmt*)OBJECT.pUndoAttr->GetFmt( rDoc )) &&
918 : : ( LTYPE_DRAW != eType ||
919 : : 0 != (pSdrObj = pFmt->FindSdrObject()) ) )
920 : : {
921 : 0 : OBJECT.pUndoAttr->UndoImpl(rContext);
922 : 0 : OBJECT.pUndoFly->UndoImpl(rContext);
923 [ # # ]: 0 : if( LTYPE_DRAW == eType )
924 : : {
925 : 0 : pSdrObj->SetLayer( nLayerId );
926 : : }
927 : 0 : }
928 : : }
929 [ # # ]: 0 : else if( NODE.nNode )
930 : : {
931 [ # # ][ # # ]: 0 : if ( eType == LTYPE_TABLE && bUndoKeep )
932 : : {
933 [ # # ]: 0 : SwTableNode *pNd = rDoc.GetNodes()[
934 [ # # ][ # # ]: 0 : rDoc.GetNodes()[NODE.nNode-1]->StartOfSectionIndex()]->GetTableNode();
[ # # ]
935 [ # # ]: 0 : if ( pNd )
936 [ # # ]: 0 : pNd->GetTable().GetFrmFmt()->ResetFmtAttr( RES_KEEP );
937 : : }
938 [ # # ][ # # ]: 0 : SwPaM aPam( rDoc.GetNodes().GetEndOfContent() );
939 [ # # ]: 0 : aPam.GetPoint()->nNode = NODE.nNode;
940 [ # # ]: 0 : aPam.SetMark();
941 [ # # ]: 0 : aPam.GetPoint()->nNode = NODE.nNode + 1;
942 [ # # ][ # # ]: 0 : NODE.pUndoInsNd = new SwUndoDelete( aPam, sal_True );
[ # # ]
943 : : }
944 : 0 : }
945 : :
946 : :
947 : 0 : void SwUndoInsertLabel::RedoImpl(::sw::UndoRedoContext & rContext)
948 : : {
949 : 0 : SwDoc & rDoc = rContext.GetDoc();
950 : :
951 [ # # ][ # # ]: 0 : if( LTYPE_OBJECT == eType || LTYPE_DRAW == eType )
952 : : {
953 : : OSL_ENSURE( OBJECT.pUndoAttr && OBJECT.pUndoFly, "Pointer not initialized" );
954 : : SwFrmFmt* pFmt;
955 : 0 : SdrObject *pSdrObj = 0;
956 [ # # ][ # # ]: 0 : if( OBJECT.pUndoAttr &&
[ # # ][ # # ]
[ # # ]
957 : 0 : 0 != (pFmt = (SwFrmFmt*)OBJECT.pUndoAttr->GetFmt( rDoc )) &&
958 : : ( LTYPE_DRAW != eType ||
959 : : 0 != (pSdrObj = pFmt->FindSdrObject()) ) )
960 : : {
961 : 0 : OBJECT.pUndoFly->RedoImpl(rContext);
962 : 0 : OBJECT.pUndoAttr->RedoImpl(rContext);
963 [ # # ]: 0 : if( LTYPE_DRAW == eType )
964 : : {
965 : 0 : pSdrObj->SetLayer( nLayerId );
966 [ # # ]: 0 : if( pSdrObj->GetLayer() == rDoc.GetHellId() )
967 : 0 : pSdrObj->SetLayer( rDoc.GetHeavenId() );
968 : : // OD 02.07.2003 #108784#
969 [ # # ]: 0 : else if( pSdrObj->GetLayer() == rDoc.GetInvisibleHellId() )
970 : 0 : pSdrObj->SetLayer( rDoc.GetInvisibleHeavenId() );
971 : : }
972 : 0 : }
973 : : }
974 [ # # ]: 0 : else if( NODE.pUndoInsNd )
975 : : {
976 [ # # ][ # # ]: 0 : if ( eType == LTYPE_TABLE && bUndoKeep )
977 : : {
978 : 0 : SwTableNode *pNd = rDoc.GetNodes()[
979 : 0 : rDoc.GetNodes()[NODE.nNode-1]->StartOfSectionIndex()]->GetTableNode();
980 [ # # ]: 0 : if ( pNd )
981 [ # # ]: 0 : pNd->GetTable().GetFrmFmt()->SetFmtAttr( SvxFmtKeepItem(sal_True, RES_KEEP) );
982 : : }
983 : 0 : NODE.pUndoInsNd->UndoImpl(rContext);
984 [ # # ]: 0 : delete NODE.pUndoInsNd, NODE.pUndoInsNd = 0;
985 : : }
986 : 0 : }
987 : :
988 : 0 : void SwUndoInsertLabel::RepeatImpl(::sw::RepeatContext & rContext)
989 : : {
990 : 0 : SwDoc & rDoc = rContext.GetDoc();
991 : 0 : const SwPosition& rPos = *rContext.GetRepeatPaM().GetPoint();
992 : :
993 : 0 : sal_uLong nIdx = 0;
994 : :
995 : 0 : SwCntntNode* pCNd = rPos.nNode.GetNode().GetCntntNode();
996 [ # # ]: 0 : if( pCNd )
997 [ # # # # ]: 0 : switch( eType )
998 : : {
999 : : case LTYPE_TABLE:
1000 : : {
1001 : 0 : const SwTableNode* pTNd = pCNd->FindTableNode();
1002 [ # # ]: 0 : if( pTNd )
1003 : 0 : nIdx = pTNd->GetIndex();
1004 : : }
1005 : 0 : break;
1006 : :
1007 : : case LTYPE_FLY:
1008 : : case LTYPE_OBJECT:
1009 : : {
1010 : : SwFlyFrm* pFly;
1011 : 0 : SwCntntFrm *pCnt = pCNd->getLayoutFrm( rDoc.GetCurrentLayout() );
1012 [ # # ][ # # ]: 0 : if( pCnt && 0 != ( pFly = pCnt->FindFlyFrm() ) )
[ # # ]
1013 : 0 : nIdx = pFly->GetFmt()->GetCntnt().GetCntntIdx()->GetIndex();
1014 : : }
1015 : 0 : break;
1016 : : case LTYPE_DRAW:
1017 : 0 : break;
1018 : : }
1019 : :
1020 [ # # ]: 0 : if( nIdx )
1021 : : {
1022 : : rDoc.InsertLabel( eType, sText, sSeparator, sNumberSeparator, bBefore,
1023 : 0 : nFldId, nIdx, sCharacterStyle, bCpyBrd );
1024 : : }
1025 : 0 : }
1026 : :
1027 : : // #111827#
1028 : 0 : SwRewriter SwUndoInsertLabel::GetRewriter() const
1029 : : {
1030 [ # # ]: 0 : SwRewriter aRewriter;
1031 : :
1032 [ # # ]: 0 : String aTmpStr;
1033 : :
1034 [ # # ][ # # ]: 0 : aTmpStr += String(SW_RES(STR_START_QUOTE));
[ # # ]
1035 : : aTmpStr += ShortenString(sText, nUndoStringLength,
1036 [ # # ][ # # ]: 0 : String(SW_RES(STR_LDOTS)));
[ # # ][ # # ]
[ # # ]
1037 [ # # ][ # # ]: 0 : aTmpStr += String(SW_RES(STR_END_QUOTE));
[ # # ]
1038 : :
1039 [ # # ]: 0 : aRewriter.AddRule(UndoArg1, aTmpStr);
1040 : :
1041 [ # # ]: 0 : return aRewriter;
1042 : : }
1043 : :
1044 : 0 : void SwUndoInsertLabel::SetFlys( SwFrmFmt& rOldFly, SfxItemSet& rChgSet,
1045 : : SwFrmFmt& rNewFly )
1046 : : {
1047 [ # # ][ # # ]: 0 : if( LTYPE_OBJECT == eType || LTYPE_DRAW == eType )
1048 : : {
1049 [ # # ]: 0 : SwUndoFmtAttrHelper aTmp( rOldFly, false );
1050 [ # # ]: 0 : rOldFly.SetFmtAttr( rChgSet );
1051 [ # # ]: 0 : if ( aTmp.GetUndo() )
1052 : : {
1053 : 0 : OBJECT.pUndoAttr = aTmp.ReleaseUndo();
1054 : : }
1055 [ # # ][ # # ]: 0 : OBJECT.pUndoFly = new SwUndoInsLayFmt( &rNewFly,0,0 );
[ # # ]
1056 : : }
1057 : 0 : }
1058 : :
1059 : 0 : void SwUndoInsertLabel::SetDrawObj( sal_uInt8 nLId )
1060 : : {
1061 [ # # ]: 0 : if( LTYPE_DRAW == eType )
1062 : : {
1063 : 0 : nLayerId = nLId;
1064 : : }
1065 : 0 : }
1066 : :
1067 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|