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 : : #include <UndoOverwrite.hxx>
30 : : #include <tools/resid.hxx>
31 : : #include <unotools/charclass.hxx>
32 : : #include <unotools/transliterationwrapper.hxx>
33 : : #include <comphelper/processfactory.hxx>
34 : : #include <doc.hxx>
35 : : #include <IDocumentUndoRedo.hxx>
36 : : #include <IShellCursorSupplier.hxx>
37 : : #include <swundo.hxx>
38 : : #include <pam.hxx>
39 : : #include <ndtxt.hxx>
40 : : #include <UndoCore.hxx>
41 : : #include <rolbck.hxx>
42 : : #include <acorrect.hxx>
43 : : #include <docary.hxx>
44 : : #include <comcore.hrc> // #111827#
45 : : #include <undo.hrc>
46 : :
47 : : using namespace ::com::sun::star;
48 : : using namespace ::com::sun::star::i18n;
49 : : using namespace ::com::sun::star::uno;
50 : :
51 : 0 : SwUndoOverwrite::SwUndoOverwrite( SwDoc* pDoc, SwPosition& rPos,
52 : : sal_Unicode cIns )
53 : : : SwUndo(UNDO_OVERWRITE),
54 [ # # ][ # # ]: 0 : pRedlSaveData( 0 ), bGroup( sal_False )
[ # # ]
55 : : {
56 [ # # ][ # # ]: 0 : if( !pDoc->IsIgnoreRedline() && !pDoc->GetRedlineTbl().empty() )
[ # # ][ # # ]
[ # # ]
57 : : {
58 : 0 : SwPaM aPam( rPos.nNode, rPos.nContent.GetIndex(),
59 [ # # ]: 0 : rPos.nNode, rPos.nContent.GetIndex()+1 );
60 [ # # ][ # # ]: 0 : pRedlSaveData = new SwRedlineSaveDatas;
61 [ # # ][ # # ]: 0 : if( !FillSaveData( aPam, *pRedlSaveData, sal_False ))
62 [ # # ][ # # ]: 0 : delete pRedlSaveData, pRedlSaveData = 0;
[ # # ]
63 : : }
64 : :
65 : 0 : nSttNode = rPos.nNode.GetIndex();
66 : 0 : nSttCntnt = rPos.nContent.GetIndex();
67 : :
68 : 0 : SwTxtNode* pTxtNd = rPos.nNode.GetNode().GetTxtNode();
69 : : OSL_ENSURE( pTxtNd, "Overwrite not in a TextNode?" );
70 : :
71 : 0 : bInsChar = sal_True;
72 : 0 : xub_StrLen nTxtNdLen = pTxtNd->GetTxt().Len();
73 [ # # ]: 0 : if( nSttCntnt < nTxtNdLen ) // no pure insert?
74 : : {
75 [ # # ]: 0 : aDelStr.Insert( pTxtNd->GetTxt().GetChar( nSttCntnt ) );
76 [ # # ]: 0 : if( !pHistory )
77 [ # # ][ # # ]: 0 : pHistory = new SwHistory;
78 [ # # ]: 0 : SwRegHistory aRHst( *pTxtNd, pHistory );
79 : : pHistory->CopyAttr( pTxtNd->GetpSwpHints(), nSttNode, 0,
80 [ # # ]: 0 : nTxtNdLen, false );
81 [ # # ]: 0 : rPos.nContent++;
82 [ # # ]: 0 : bInsChar = sal_False;
83 : : }
84 : :
85 : 0 : sal_Bool bOldExpFlg = pTxtNd->IsIgnoreDontExpand();
86 : 0 : pTxtNd->SetIgnoreDontExpand( sal_True );
87 : :
88 : : pTxtNd->InsertText( rtl::OUString(cIns), rPos.nContent,
89 [ # # ][ # # ]: 0 : IDocumentContentOperations::INS_EMPTYEXPAND );
[ # # ]
90 [ # # ]: 0 : aInsStr.Insert( cIns );
91 : :
92 [ # # ]: 0 : if( !bInsChar )
93 : : {
94 [ # # ]: 0 : const SwIndex aTmpIndex( rPos.nContent, -2 );
95 [ # # ][ # # ]: 0 : pTxtNd->EraseText( aTmpIndex, 1 );
96 : : }
97 : 0 : pTxtNd->SetIgnoreDontExpand( bOldExpFlg );
98 : :
99 : 0 : bCacheComment = false;
100 : 0 : }
101 : :
102 [ # # ][ # # ]: 0 : SwUndoOverwrite::~SwUndoOverwrite()
[ # # ]
103 : : {
104 [ # # ][ # # ]: 0 : delete pRedlSaveData;
105 [ # # ]: 0 : }
106 : :
107 : 0 : sal_Bool SwUndoOverwrite::CanGrouping( SwDoc* pDoc, SwPosition& rPos,
108 : : sal_Unicode cIns )
109 : : {
110 : : // What is with only inserted characters?
111 : :
112 : : // Only deletion of single chars can be combined.
113 [ # # ][ # # ]: 0 : if( rPos.nNode != nSttNode || !aInsStr.Len() ||
[ # # # # ]
[ # # ]
114 : 0 : ( !bGroup && aInsStr.Len() != 1 ))
115 : 0 : return sal_False;
116 : :
117 : : // Is the node a TextNode at all?
118 : 0 : SwTxtNode * pDelTxtNd = rPos.nNode.GetNode().GetTxtNode();
119 [ # # ][ # # : 0 : if( !pDelTxtNd ||
# # # # ]
120 : 0 : ( pDelTxtNd->GetTxt().Len() != rPos.nContent.GetIndex() &&
121 : 0 : rPos.nContent.GetIndex() != ( nSttCntnt + aInsStr.Len() )))
122 : 0 : return sal_False;
123 : :
124 : 0 : CharClass& rCC = GetAppCharClass();
125 : :
126 : : // ask the char that should be inserted
127 [ # # ][ # # ]: 0 : if (( CH_TXTATR_BREAKWORD == cIns || CH_TXTATR_INWORD == cIns ) ||
[ # # ][ # # ]
128 [ # # ][ # # ]: 0 : rCC.isLetterNumeric( rtl::OUString( cIns ), 0 ) !=
[ # # ][ # # ]
[ # # ]
[ # # # # ]
129 [ # # ]: 0 : rCC.isLetterNumeric( aInsStr, aInsStr.Len()-1 ) )
130 : 0 : return sal_False;
131 : :
132 : : {
133 [ # # ][ # # ]: 0 : SwRedlineSaveDatas* pTmpSav = new SwRedlineSaveDatas;
134 : 0 : SwPaM aPam( rPos.nNode, rPos.nContent.GetIndex(),
135 [ # # ]: 0 : rPos.nNode, rPos.nContent.GetIndex()+1 );
136 : :
137 [ # # ][ # # ]: 0 : if( !FillSaveData( aPam, *pTmpSav, sal_False ))
138 [ # # ][ # # ]: 0 : delete pTmpSav, pTmpSav = 0;
139 : :
140 : 0 : sal_Bool bOk = ( !pRedlSaveData && !pTmpSav ) ||
141 : : ( pRedlSaveData && pTmpSav &&
142 : : SwUndo::CanRedlineGroup( *pRedlSaveData, *pTmpSav,
143 [ # # ][ # # ]: 0 : nSttCntnt > rPos.nContent.GetIndex() ));
[ # # ][ # # ]
[ # # ][ # # ]
144 [ # # ][ # # ]: 0 : delete pTmpSav;
145 [ # # ]: 0 : if( !bOk )
146 : 0 : return sal_False;
147 : :
148 [ # # ][ # # ]: 0 : pDoc->DeleteRedline( aPam, false, USHRT_MAX );
[ # # ]
149 : : }
150 : :
151 : : // both 'overwrites' can be combined so 'move' the corresponding character
152 [ # # ]: 0 : if( !bInsChar )
153 : : {
154 [ # # ]: 0 : if( rPos.nContent.GetIndex() < pDelTxtNd->GetTxt().Len() )
155 : : {
156 : 0 : aDelStr.Insert( pDelTxtNd->GetTxt().GetChar(rPos.nContent.GetIndex()) );
157 : 0 : rPos.nContent++;
158 : : }
159 : : else
160 : 0 : bInsChar = sal_True;
161 : : }
162 : :
163 : 0 : sal_Bool bOldExpFlg = pDelTxtNd->IsIgnoreDontExpand();
164 : 0 : pDelTxtNd->SetIgnoreDontExpand( sal_True );
165 : :
166 : : pDelTxtNd->InsertText( rtl::OUString(cIns), rPos.nContent,
167 [ # # ][ # # ]: 0 : IDocumentContentOperations::INS_EMPTYEXPAND );
[ # # ]
168 : 0 : aInsStr.Insert( cIns );
169 : :
170 [ # # ]: 0 : if( !bInsChar )
171 : : {
172 [ # # ]: 0 : const SwIndex aTmpIndex( rPos.nContent, -2 );
173 [ # # ][ # # ]: 0 : pDelTxtNd->EraseText( aTmpIndex, 1 );
174 : : }
175 : 0 : pDelTxtNd->SetIgnoreDontExpand( bOldExpFlg );
176 : :
177 : 0 : bGroup = sal_True;
178 : 0 : return sal_True;
179 : : }
180 : :
181 : 0 : void SwUndoOverwrite::UndoImpl(::sw::UndoRedoContext & rContext)
182 : : {
183 : 0 : SwDoc *const pDoc = & rContext.GetDoc();
184 : 0 : SwPaM *const pAktPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
185 : :
186 : 0 : pAktPam->DeleteMark();
187 : 0 : pAktPam->GetPoint()->nNode = nSttNode;
188 : 0 : SwTxtNode* pTxtNd = pAktPam->GetNode()->GetTxtNode();
189 : : OSL_ENSURE( pTxtNd, "Overwrite not in a TextNode?" );
190 : 0 : SwIndex& rIdx = pAktPam->GetPoint()->nContent;
191 [ # # ]: 0 : rIdx.Assign( pTxtNd, nSttCntnt );
192 : :
193 : 0 : SwAutoCorrExceptWord* pACEWord = pDoc->GetAutoCorrExceptWord();
194 [ # # ]: 0 : if( pACEWord )
195 : : {
196 [ # # ][ # # ]: 0 : if( 1 == aInsStr.Len() && 1 == aDelStr.Len() )
[ # # ]
197 : 0 : pACEWord->CheckChar( *pAktPam->GetPoint(), aDelStr.GetChar( 0 ) );
198 : 0 : pDoc->SetAutoCorrExceptWord( 0 );
199 : : }
200 : :
201 : : // If there was not only a overwrite but also an insert, delete the surplus
202 [ # # ]: 0 : if( aInsStr.Len() > aDelStr.Len() )
203 : : {
204 : 0 : rIdx += aDelStr.Len();
205 : 0 : pTxtNd->EraseText( rIdx, aInsStr.Len() - aDelStr.Len() );
206 : 0 : rIdx = nSttCntnt;
207 : : }
208 : :
209 [ # # ]: 0 : if( aDelStr.Len() )
210 : : {
211 [ # # ]: 0 : String aTmpStr = rtl::OUString('1');
212 [ # # ]: 0 : sal_Unicode* pTmpStr = aTmpStr.GetBufferAccess();
213 : :
214 : 0 : sal_Bool bOldExpFlg = pTxtNd->IsIgnoreDontExpand();
215 : 0 : pTxtNd->SetIgnoreDontExpand( sal_True );
216 : :
217 [ # # ]: 0 : rIdx++;
218 [ # # ]: 0 : for( xub_StrLen n = 0; n < aDelStr.Len(); n++ )
219 : : {
220 : : // do it individually, to keep the attributes!
221 : 0 : *pTmpStr = aDelStr.GetChar( n );
222 [ # # ]: 0 : pTxtNd->InsertText( aTmpStr, rIdx /*???, SETATTR_NOTXTATRCHR*/ );
223 [ # # ]: 0 : rIdx -= 2;
224 [ # # ]: 0 : pTxtNd->EraseText( rIdx, 1 );
225 [ # # ]: 0 : rIdx += 2;
226 : : }
227 : 0 : pTxtNd->SetIgnoreDontExpand( bOldExpFlg );
228 [ # # ][ # # ]: 0 : rIdx--;
229 : : }
230 : :
231 [ # # ]: 0 : if( pHistory )
232 : : {
233 [ # # ]: 0 : if( pTxtNd->GetpSwpHints() )
234 : 0 : pTxtNd->ClearSwpHintsArr( false );
235 : 0 : pHistory->TmpRollback( pDoc, 0, false );
236 : : }
237 : :
238 [ # # ]: 0 : if( pAktPam->GetMark()->nContent.GetIndex() != nSttCntnt )
239 : : {
240 : 0 : pAktPam->SetMark();
241 : 0 : pAktPam->GetMark()->nContent = nSttCntnt;
242 : : }
243 : :
244 [ # # ]: 0 : if( pRedlSaveData )
245 : 0 : SetSaveData( *pDoc, *pRedlSaveData );
246 : 0 : }
247 : :
248 : 0 : void SwUndoOverwrite::RepeatImpl(::sw::RepeatContext & rContext)
249 : : {
250 : 0 : SwPaM *const pAktPam = & rContext.GetRepeatPaM();
251 [ # # ][ # # ]: 0 : if( !aInsStr.Len() || pAktPam->HasMark() )
[ # # ]
252 : 0 : return;
253 : :
254 : 0 : SwDoc & rDoc = rContext.GetDoc();
255 : :
256 : : {
257 [ # # ][ # # ]: 0 : ::sw::GroupUndoGuard const undoGuard(rDoc.GetIDocumentUndoRedo());
258 [ # # ][ # # ]: 0 : rDoc.Overwrite(*pAktPam, rtl::OUString(aInsStr.GetChar(0)));
[ # # ][ # # ]
259 : : }
260 [ # # ]: 0 : for( xub_StrLen n = 1; n < aInsStr.Len(); ++n )
261 [ # # ][ # # ]: 0 : rDoc.Overwrite( *pAktPam, rtl::OUString(aInsStr.GetChar(n)) );
[ # # ]
262 : : }
263 : :
264 : 0 : void SwUndoOverwrite::RedoImpl(::sw::UndoRedoContext & rContext)
265 : : {
266 : 0 : SwDoc *const pDoc = & rContext.GetDoc();
267 : 0 : SwPaM *const pAktPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
268 : :
269 : 0 : pAktPam->DeleteMark();
270 : 0 : pAktPam->GetPoint()->nNode = nSttNode;
271 : 0 : SwTxtNode* pTxtNd = pAktPam->GetNode()->GetTxtNode();
272 : : OSL_ENSURE( pTxtNd, "Overwrite not in TextNode?" );
273 : 0 : SwIndex& rIdx = pAktPam->GetPoint()->nContent;
274 : :
275 [ # # ]: 0 : if( pRedlSaveData )
276 : : {
277 [ # # ]: 0 : rIdx.Assign( pTxtNd, nSttCntnt );
278 : 0 : pAktPam->SetMark();
279 : 0 : pAktPam->GetMark()->nContent += aInsStr.Len();
280 : 0 : pDoc->DeleteRedline( *pAktPam, false, USHRT_MAX );
281 : 0 : pAktPam->DeleteMark();
282 : : }
283 [ # # ][ # # ]: 0 : rIdx.Assign( pTxtNd, aDelStr.Len() ? nSttCntnt+1 : nSttCntnt );
284 : :
285 : 0 : sal_Bool bOldExpFlg = pTxtNd->IsIgnoreDontExpand();
286 : 0 : pTxtNd->SetIgnoreDontExpand( sal_True );
287 : :
288 [ # # ]: 0 : for( xub_StrLen n = 0; n < aInsStr.Len(); n++ )
289 : : {
290 : : // do it individually, to keep the attributes!
291 : 0 : pTxtNd->InsertText( rtl::OUString(aInsStr.GetChar(n)), rIdx,
292 [ # # ][ # # ]: 0 : IDocumentContentOperations::INS_EMPTYEXPAND );
[ # # ]
293 [ # # ]: 0 : if( n < aDelStr.Len() )
294 : : {
295 : 0 : rIdx -= 2;
296 : 0 : pTxtNd->EraseText( rIdx, 1 );
297 [ # # ]: 0 : rIdx += n+1 < aDelStr.Len() ? 2 : 1;
298 : : }
299 : : }
300 : 0 : pTxtNd->SetIgnoreDontExpand( bOldExpFlg );
301 : :
302 : : // get back old start position from UndoNodes array
303 [ # # ]: 0 : if( pHistory )
304 : 0 : pHistory->SetTmpEnd( pHistory->Count() );
305 [ # # ]: 0 : if( pAktPam->GetMark()->nContent.GetIndex() != nSttCntnt )
306 : : {
307 : 0 : pAktPam->SetMark();
308 : 0 : pAktPam->GetMark()->nContent = nSttCntnt;
309 : : }
310 : 0 : }
311 : :
312 : 0 : SwRewriter SwUndoOverwrite::GetRewriter() const
313 : : {
314 [ # # ]: 0 : SwRewriter aResult;
315 : :
316 [ # # ]: 0 : String aString;
317 : :
318 [ # # ][ # # ]: 0 : aString += String(SW_RES(STR_START_QUOTE));
[ # # ]
319 : : aString += ShortenString(aInsStr, nUndoStringLength,
320 [ # # ][ # # ]: 0 : String(SW_RES(STR_LDOTS)));
[ # # ][ # # ]
[ # # ]
321 [ # # ][ # # ]: 0 : aString += String(SW_RES(STR_END_QUOTE));
[ # # ]
322 : :
323 [ # # ]: 0 : aResult.AddRule(UndoArg1, aString);
324 : :
325 [ # # ]: 0 : return aResult;
326 : : }
327 : :
328 : : struct _UndoTransliterate_Data
329 : : {
330 : : String sText;
331 : : SwHistory* pHistory;
332 : : Sequence< sal_Int32 >* pOffsets;
333 : : sal_uLong nNdIdx;
334 : : xub_StrLen nStart, nLen;
335 : :
336 : 0 : _UndoTransliterate_Data( sal_uLong nNd, xub_StrLen nStt, xub_StrLen nStrLen, const String& rTxt )
337 : : : sText( rTxt ), pHistory( 0 ), pOffsets( 0 ),
338 : 0 : nNdIdx( nNd ), nStart( nStt ), nLen( nStrLen )
339 : 0 : {}
340 [ # # ][ # # ]: 0 : ~_UndoTransliterate_Data() { delete pOffsets; delete pHistory; }
[ # # ][ # # ]
341 : :
342 : : void SetChangeAtNode( SwDoc& rDoc );
343 : : };
344 : :
345 : 0 : SwUndoTransliterate::SwUndoTransliterate(
346 : : const SwPaM& rPam,
347 : : const utl::TransliterationWrapper& rTrans )
348 [ # # ][ # # ]: 0 : : SwUndo( UNDO_TRANSLITERATE ), SwUndRng( rPam ), nType( rTrans.getType() )
349 : : {
350 : 0 : }
351 : :
352 : 0 : SwUndoTransliterate::~SwUndoTransliterate()
353 : : {
354 [ # # ]: 0 : for (size_t i = 0; i < aChanges.size(); ++i)
355 [ # # ][ # # ]: 0 : delete aChanges[i];
356 [ # # ]: 0 : }
357 : :
358 : 0 : void SwUndoTransliterate::UndoImpl(::sw::UndoRedoContext & rContext)
359 : : {
360 : 0 : SwDoc & rDoc = rContext.GetDoc();
361 : :
362 : : // since the changes were added to the vector from the end of the string/node towards
363 : : // the start, we need to revert them from the start towards the end now to keep the
364 : : // offset information of the undo data in sync with the changing text.
365 : : // Thus we need to iterate from the end of the vector to the start
366 [ # # ]: 0 : for (sal_Int32 i = aChanges.size() - 1; i >= 0; --i)
367 : 0 : aChanges[i]->SetChangeAtNode( rDoc );
368 : :
369 : 0 : AddUndoRedoPaM(rContext, true);
370 : 0 : }
371 : :
372 : 0 : void SwUndoTransliterate::RedoImpl(::sw::UndoRedoContext & rContext)
373 : : {
374 : 0 : SwPaM & rPam( AddUndoRedoPaM(rContext) );
375 : 0 : DoTransliterate(rContext.GetDoc(), rPam);
376 : 0 : }
377 : :
378 : 0 : void SwUndoTransliterate::RepeatImpl(::sw::RepeatContext & rContext)
379 : : {
380 : 0 : DoTransliterate(rContext.GetDoc(), rContext.GetRepeatPaM());
381 : 0 : }
382 : :
383 : 0 : void SwUndoTransliterate::DoTransliterate(SwDoc & rDoc, SwPaM & rPam)
384 : : {
385 [ # # ][ # # ]: 0 : utl::TransliterationWrapper aTrans( ::comphelper::getProcessServiceFactory(), nType );
386 [ # # ][ # # ]: 0 : rDoc.TransliterateText( rPam, aTrans );
387 : 0 : }
388 : :
389 : 0 : void SwUndoTransliterate::AddChanges( SwTxtNode& rTNd,
390 : : xub_StrLen nStart, xub_StrLen nLen,
391 : : uno::Sequence <sal_Int32>& rOffsets )
392 : : {
393 : 0 : long nOffsLen = rOffsets.getLength();
394 : : _UndoTransliterate_Data* pNew = new _UndoTransliterate_Data(
395 : 0 : rTNd.GetIndex(), nStart, (xub_StrLen)nOffsLen,
396 [ # # ][ # # ]: 0 : rTNd.GetTxt().Copy( nStart, nLen ));
[ # # ][ # # ]
397 : :
398 [ # # ]: 0 : aChanges.push_back( pNew );
399 : :
400 : 0 : const sal_Int32* pOffsets = rOffsets.getConstArray();
401 : : // where did we need less memory ?
402 : 0 : const sal_Int32* p = pOffsets;
403 [ # # ]: 0 : for( long n = 0; n < nOffsLen; ++n, ++p )
404 [ # # ]: 0 : if( *p != ( nStart + n ))
405 : : {
406 : : // create the Offset array
407 [ # # ]: 0 : pNew->pOffsets = new Sequence <sal_Int32> ( nLen );
408 [ # # ]: 0 : sal_Int32* pIdx = pNew->pOffsets->getArray();
409 : 0 : p = pOffsets;
410 : 0 : long nMyOff, nNewVal = nStart;
411 [ # # ]: 0 : for( n = 0, nMyOff = nStart; n < nOffsLen; ++p, ++n, ++nMyOff )
412 : : {
413 [ # # ]: 0 : if( *p < nMyOff )
414 : : {
415 : : // something is deleted
416 : 0 : nMyOff = *p;
417 : 0 : *(pIdx-1) = nNewVal++;
418 : : }
419 [ # # ]: 0 : else if( *p > nMyOff )
420 : : {
421 [ # # ]: 0 : for( ; *p > nMyOff; ++nMyOff )
422 : 0 : *pIdx++ = nNewVal;
423 : 0 : --nMyOff;
424 : 0 : --n;
425 : 0 : --p;
426 : : }
427 : : else
428 : 0 : *pIdx++ = nNewVal++;
429 : : }
430 : :
431 : : // and then we need to save the attributes/bookmarks
432 : : // but this data must moved every time to the last in the chain!
433 [ # # ]: 0 : for (size_t i = 0; i + 1 < aChanges.size(); ++i) // check all changes but not the current one
434 : : {
435 : 0 : _UndoTransliterate_Data* pD = aChanges[i];
436 [ # # ][ # # ]: 0 : if( pD->nNdIdx == pNew->nNdIdx && pD->pHistory )
437 : : {
438 : : // same node and have a history?
439 : 0 : pNew->pHistory = pD->pHistory;
440 : 0 : pD->pHistory = 0;
441 : 0 : break; // more can't exist
442 : : }
443 : : }
444 : :
445 [ # # ]: 0 : if( !pNew->pHistory )
446 : : {
447 [ # # ][ # # ]: 0 : pNew->pHistory = new SwHistory;
448 [ # # ]: 0 : SwRegHistory aRHst( rTNd, pNew->pHistory );
449 : : pNew->pHistory->CopyAttr( rTNd.GetpSwpHints(),
450 [ # # ][ # # ]: 0 : pNew->nNdIdx, 0, rTNd.GetTxt().Len(), false );
451 : : }
452 : 0 : break;
453 : : }
454 : 0 : }
455 : :
456 : 0 : void _UndoTransliterate_Data::SetChangeAtNode( SwDoc& rDoc )
457 : : {
458 : 0 : SwTxtNode* pTNd = rDoc.GetNodes()[ nNdIdx ]->GetTxtNode();
459 [ # # ]: 0 : if( pTNd )
460 : : {
461 [ # # ][ # # ]: 0 : Sequence <sal_Int32> aOffsets( pOffsets ? pOffsets->getLength() : nLen );
462 [ # # ]: 0 : if( pOffsets )
463 [ # # ]: 0 : aOffsets = *pOffsets;
464 : : else
465 : : {
466 [ # # ]: 0 : sal_Int32* p = aOffsets.getArray();
467 [ # # ]: 0 : for( xub_StrLen n = 0; n < nLen; ++n, ++p )
468 : 0 : *p = n + nStart;
469 : : }
470 [ # # ]: 0 : pTNd->ReplaceTextOnly( nStart, nLen, sText, aOffsets );
471 : :
472 [ # # ]: 0 : if( pHistory )
473 : : {
474 [ # # ]: 0 : if( pTNd->GetpSwpHints() )
475 [ # # ]: 0 : pTNd->ClearSwpHintsArr( false );
476 [ # # ]: 0 : pHistory->TmpRollback( &rDoc, 0, false );
477 [ # # ]: 0 : pHistory->SetTmpEnd( pHistory->Count() );
478 [ # # ]: 0 : }
479 : : }
480 : 0 : }
481 : :
482 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|