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 <hintids.hxx>
30 : :
31 : : #include <svx/svxids.hrc>
32 : : #include <editeng/langitem.hxx>
33 : : #include <fmtinfmt.hxx>
34 : : #include <txtatr.hxx>
35 : : #include <txtinet.hxx>
36 : : #include <editsh.hxx>
37 : : #include <doc.hxx>
38 : : #include <pam.hxx>
39 : : #include <ndtxt.hxx>
40 : : #include <acorrect.hxx>
41 : : #include <shellio.hxx>
42 : : #include <swundo.hxx>
43 : : #include <viscrs.hxx>
44 : :
45 : : #include <editeng/acorrcfg.hxx>
46 : :
47 : : using namespace ::com::sun::star;
48 : :
49 : :
50 : : class _PaMIntoCrsrShellRing
51 : : {
52 : : SwCrsrShell& rSh;
53 : : SwPaM &rDelPam, &rCrsr;
54 : : Ring *pPrevDelPam, *pPrevCrsr;
55 : :
56 : : void RemoveFromRing( SwPaM& rPam, Ring* pPrev );
57 : : public:
58 : : _PaMIntoCrsrShellRing( SwCrsrShell& rSh, SwPaM& rCrsr, SwPaM& rPam );
59 : : ~_PaMIntoCrsrShellRing();
60 : : };
61 : :
62 : 0 : _PaMIntoCrsrShellRing::_PaMIntoCrsrShellRing( SwCrsrShell& rCSh,
63 : : SwPaM& rShCrsr, SwPaM& rPam )
64 : 0 : : rSh( rCSh ), rDelPam( rPam ), rCrsr( rShCrsr )
65 : : {
66 [ # # ]: 0 : SwPaM* pShCrsr = rSh._GetCrsr();
67 : :
68 : 0 : pPrevDelPam = rDelPam.GetPrev();
69 : 0 : pPrevCrsr = rCrsr.GetPrev();
70 : :
71 : 0 : rDelPam.MoveRingTo( pShCrsr );
72 : 0 : rCrsr.MoveRingTo( pShCrsr );
73 : 0 : }
74 : 0 : _PaMIntoCrsrShellRing::~_PaMIntoCrsrShellRing()
75 : : {
76 : : // und den Pam wieder herausnehmen:
77 : 0 : RemoveFromRing( rDelPam, pPrevDelPam );
78 : 0 : RemoveFromRing( rCrsr, pPrevCrsr );
79 : 0 : }
80 : 0 : void _PaMIntoCrsrShellRing::RemoveFromRing( SwPaM& rPam, Ring* pPrev )
81 : : {
82 : 0 : Ring *p, *pNext = (Ring*)&rPam;
83 [ # # ]: 0 : do {
84 : 0 : p = pNext;
85 : 0 : pNext = p->GetNext();
86 : 0 : p->MoveTo( &rPam );
87 : : } while( p != pPrev );
88 : 0 : }
89 : :
90 : :
91 : 0 : SwAutoCorrDoc::SwAutoCorrDoc( SwEditShell& rEditShell, SwPaM& rPam,
92 : : sal_Unicode cIns )
93 : : : rEditSh( rEditShell ), rCrsr( rPam ), pIdx( 0 )
94 : : , m_nEndUndoCounter(0)
95 : 0 : , bUndoIdInitialized( cIns ? false : true )
96 : : {
97 : 0 : }
98 : :
99 : :
100 : 0 : SwAutoCorrDoc::~SwAutoCorrDoc()
101 : : {
102 [ # # ]: 0 : for (int i = 0; i < m_nEndUndoCounter; ++i)
103 : : {
104 [ # # ]: 0 : rEditSh.EndUndo();
105 : : }
106 [ # # ][ # # ]: 0 : delete pIdx;
107 [ # # ]: 0 : }
108 : :
109 : 0 : void SwAutoCorrDoc::DeleteSel( SwPaM& rDelPam )
110 : : {
111 : 0 : SwDoc* pDoc = rEditSh.GetDoc();
112 [ # # ]: 0 : if( pDoc->IsAutoFmtRedline() )
113 : : {
114 : : // damit der DelPam auch verschoben wird, in den Shell-Cursr-Ring
115 : : // mit aufnehmen !!
116 [ # # ]: 0 : _PaMIntoCrsrShellRing aTmp( rEditSh, rCrsr, rDelPam );
117 [ # # ][ # # ]: 0 : pDoc->DeleteAndJoin( rDelPam );
118 : : }
119 : : else
120 : : {
121 : 0 : pDoc->DeleteRange( rDelPam );
122 : : }
123 : 0 : }
124 : :
125 : 0 : sal_Bool SwAutoCorrDoc::Delete( xub_StrLen nStt, xub_StrLen nEnd )
126 : : {
127 : 0 : const SwNodeIndex& rNd = rCrsr.GetPoint()->nNode;
128 [ # # ]: 0 : SwPaM aSel( rNd, nStt, rNd, nEnd );
129 [ # # ]: 0 : DeleteSel( aSel );
130 : :
131 [ # # ]: 0 : if( bUndoIdInitialized )
132 : 0 : bUndoIdInitialized = true;
133 [ # # ]: 0 : return sal_True;
134 : : }
135 : :
136 : :
137 : 0 : sal_Bool SwAutoCorrDoc::Insert( xub_StrLen nPos, const String& rTxt )
138 : : {
139 [ # # ]: 0 : SwPaM aPam( rCrsr.GetPoint()->nNode.GetNode(), nPos );
140 [ # # ]: 0 : rEditSh.GetDoc()->InsertString( aPam, rTxt );
141 [ # # ]: 0 : if( !bUndoIdInitialized )
142 : : {
143 : 0 : bUndoIdInitialized = true;
144 [ # # ]: 0 : if( 1 == rTxt.Len() )
145 : : {
146 [ # # ]: 0 : rEditSh.StartUndo( UNDO_AUTOCORRECT );
147 : 0 : ++m_nEndUndoCounter;
148 : : }
149 : : }
150 [ # # ]: 0 : return sal_True;
151 : : }
152 : :
153 : :
154 : 0 : sal_Bool SwAutoCorrDoc::Replace( xub_StrLen nPos, const String& rTxt )
155 : : {
156 : 0 : return ReplaceRange( nPos, rTxt.Len(), rTxt );
157 : : }
158 : 0 : sal_Bool SwAutoCorrDoc::ReplaceRange( xub_StrLen nPos, xub_StrLen nSourceLength, const String& rTxt )
159 : : {
160 : 0 : SwPaM* pPam = &rCrsr;
161 [ # # ]: 0 : if( pPam->GetPoint()->nContent.GetIndex() != nPos )
162 : : {
163 [ # # ]: 0 : pPam = new SwPaM( *rCrsr.GetPoint() );
164 : 0 : pPam->GetPoint()->nContent = nPos;
165 : : }
166 : :
167 : 0 : SwTxtNode * const pNd = pPam->GetNode()->GetTxtNode();
168 [ # # ]: 0 : if ( !pNd )
169 : : {
170 : 0 : return sal_False;
171 : : }
172 : :
173 : : // text attributes with dummy characters must not be replaced!
174 : 0 : bool bDoReplace = true;
175 : 0 : xub_StrLen const nLen = rTxt.Len();
176 [ # # ]: 0 : for ( xub_StrLen n = 0; n < nLen; ++n )
177 : : {
178 : 0 : sal_Unicode const Char = pNd->GetTxt().GetChar( n + nPos );
179 [ # # # # ]: 0 : if ( ( CH_TXTATR_BREAKWORD == Char || CH_TXTATR_INWORD == Char )
[ # # ][ # # ]
180 : 0 : && pNd->GetTxtAttrForCharAt( n + nPos ) )
181 : : {
182 : 0 : bDoReplace = false;
183 : 0 : break;
184 : : }
185 : : }
186 : :
187 [ # # ]: 0 : if ( bDoReplace )
188 : : {
189 : 0 : SwDoc* pDoc = rEditSh.GetDoc();
190 : :
191 [ # # ]: 0 : if( pDoc->IsAutoFmtRedline() )
192 : : {
193 [ # # ]: 0 : if( nPos == pNd->GetTxt().Len() ) // am Ende erfolgt ein Insert
194 : : {
195 : 0 : pDoc->InsertString( *pPam, rTxt );
196 : : }
197 : : else
198 : : {
199 [ # # ]: 0 : _PaMIntoCrsrShellRing aTmp( rEditSh, rCrsr, *pPam );
200 : :
201 [ # # ]: 0 : pPam->SetMark();
202 : 0 : pPam->GetPoint()->nContent = Min( pNd->GetTxt().Len(),
203 [ # # ]: 0 : xub_StrLen( nPos + nSourceLength ));
204 [ # # ]: 0 : pDoc->ReplaceRange( *pPam, rTxt, false );
205 : 0 : pPam->Exchange();
206 [ # # ][ # # ]: 0 : pPam->DeleteMark();
207 : : }
208 : : }
209 : : else
210 : : {
211 [ # # ]: 0 : if( nSourceLength != rTxt.Len() )
212 : : {
213 : 0 : pPam->SetMark();
214 : 0 : pPam->GetPoint()->nContent = Min( pNd->GetTxt().Len(),
215 : 0 : xub_StrLen( nPos + nSourceLength ));
216 : 0 : pDoc->ReplaceRange( *pPam, rTxt, false );
217 : 0 : pPam->Exchange();
218 : 0 : pPam->DeleteMark();
219 : : }
220 : : else
221 : 0 : pDoc->Overwrite( *pPam, rTxt );
222 : : }
223 : :
224 : : // pDoc->SetRedlineMode_intern( eOld );
225 [ # # ]: 0 : if( bUndoIdInitialized )
226 : : {
227 : 0 : bUndoIdInitialized = true;
228 [ # # ]: 0 : if( 1 == rTxt.Len() )
229 : : {
230 : 0 : rEditSh.StartUndo( UNDO_AUTOCORRECT );
231 : 0 : ++m_nEndUndoCounter;
232 : : }
233 : : }
234 : : }
235 : :
236 [ # # ]: 0 : if( pPam != &rCrsr )
237 [ # # ]: 0 : delete pPam;
238 : :
239 : 0 : return sal_True;
240 : : }
241 : :
242 : :
243 : :
244 : 0 : sal_Bool SwAutoCorrDoc::SetAttr( xub_StrLen nStt, xub_StrLen nEnd, sal_uInt16 nSlotId,
245 : : SfxPoolItem& rItem )
246 : : {
247 : 0 : const SwNodeIndex& rNd = rCrsr.GetPoint()->nNode;
248 [ # # ]: 0 : SwPaM aPam( rNd, nStt, rNd, nEnd );
249 : :
250 : 0 : SfxItemPool& rPool = rEditSh.GetDoc()->GetAttrPool();
251 [ # # ]: 0 : sal_uInt16 nWhich = rPool.GetWhich( nSlotId, sal_False );
252 [ # # ]: 0 : if( nWhich )
253 : : {
254 : 0 : rItem.SetWhich( nWhich );
255 : :
256 [ # # ]: 0 : SfxItemSet aSet( rPool, aCharFmtSetRange );
257 [ # # ]: 0 : SetAllScriptItem( aSet, rItem );
258 : :
259 [ # # ]: 0 : rEditSh.GetDoc()->SetFmtItemByAutoFmt( aPam, aSet );
260 : :
261 [ # # ]: 0 : if( bUndoIdInitialized )
262 [ # # ]: 0 : bUndoIdInitialized = true;
263 : : }
264 [ # # ]: 0 : return 0 != nWhich;
265 : : }
266 : :
267 : :
268 : :
269 : 0 : sal_Bool SwAutoCorrDoc::SetINetAttr( xub_StrLen nStt, xub_StrLen nEnd, const String& rURL )
270 : : {
271 : 0 : const SwNodeIndex& rNd = rCrsr.GetPoint()->nNode;
272 [ # # ]: 0 : SwPaM aPam( rNd, nStt, rNd, nEnd );
273 : :
274 : 0 : SfxItemSet aSet( rEditSh.GetDoc()->GetAttrPool(),
275 [ # # ]: 0 : RES_TXTATR_INETFMT, RES_TXTATR_INETFMT );
276 [ # # ][ # # ]: 0 : aSet.Put( SwFmtINetFmt( rURL, aEmptyStr ));
[ # # ]
277 [ # # ]: 0 : rEditSh.GetDoc()->SetFmtItemByAutoFmt( aPam, aSet );
278 [ # # ]: 0 : if( bUndoIdInitialized )
279 : 0 : bUndoIdInitialized = true;
280 [ # # ][ # # ]: 0 : return sal_True;
281 : : }
282 : :
283 : : // returne den Text eines vorherigen Absatzes.
284 : : // Dieser darf nicht leer sein!
285 : : // Gibt es diesen nicht oder gibt es davor nur Leere, dann returne 0
286 : : // Das Flag gibt an:
287 : : // sal_True: den, vor der normalen Einfuegeposition (sal_True)
288 : : // sal_False: den, in den das korrigierte Wort eingfuegt wurde.
289 : : // (Muss nicht der gleiche Absatz sein!!!!)
290 : 0 : const String* SwAutoCorrDoc::GetPrevPara( sal_Bool bAtNormalPos )
291 : : {
292 : 0 : const String* pStr = 0;
293 : :
294 [ # # ][ # # ]: 0 : if( bAtNormalPos || !pIdx )
295 [ # # ]: 0 : pIdx = new SwNodeIndex( rCrsr.GetPoint()->nNode, -1 );
296 : : else
297 : 0 : (*pIdx)--;
298 : :
299 : 0 : SwTxtNode* pTNd = pIdx->GetNode().GetTxtNode();
300 [ # # ][ # # ]: 0 : while( pTNd && !pTNd->GetTxt().Len() )
[ # # ]
301 : : {
302 : 0 : (*pIdx)--;
303 : 0 : pTNd = pIdx->GetNode().GetTxtNode();
304 : : }
305 [ # # ][ # # ]: 0 : if( pTNd && 0 == pTNd->GetAttrOutlineLevel() )//#outline level,zhaojianwei
[ # # ]
306 : 0 : pStr = &pTNd->GetTxt();
307 : :
308 [ # # ]: 0 : if( bUndoIdInitialized )
309 : 0 : bUndoIdInitialized = true;
310 : 0 : return pStr;
311 : : }
312 : :
313 : :
314 : 0 : sal_Bool SwAutoCorrDoc::ChgAutoCorrWord( xub_StrLen & rSttPos, xub_StrLen nEndPos,
315 : : SvxAutoCorrect& rACorrect,
316 : : const String** ppPara )
317 : : {
318 [ # # ]: 0 : if( bUndoIdInitialized )
319 : 0 : bUndoIdInitialized = true;
320 : :
321 : : // Absatz-Anfang oder ein Blank gefunden, suche nach dem Wort
322 : : // Kuerzel im Auto
323 : 0 : SwTxtNode* pTxtNd = rCrsr.GetNode()->GetTxtNode();
324 : : OSL_ENSURE( pTxtNd, "wo ist denn der TextNode?" );
325 : :
326 : 0 : sal_Bool bRet = sal_False;
327 [ # # ]: 0 : if( nEndPos == rSttPos )
328 : 0 : return bRet;
329 : :
330 [ # # ]: 0 : LanguageType eLang = GetLanguage(nEndPos, sal_False);
331 [ # # ]: 0 : if(LANGUAGE_SYSTEM == eLang)
332 [ # # ]: 0 : eLang = (LanguageType)GetAppLanguage();
333 : :
334 : : //JP 22.04.99: Bug 63883 - Sonderbehandlung fuer Punkte.
335 : 0 : sal_Bool bLastCharIsPoint = nEndPos < pTxtNd->GetTxt().Len() &&
336 [ # # ][ # # ]: 0 : '.' == pTxtNd->GetTxt().GetChar( nEndPos );
337 : :
338 : : const SvxAutocorrWord* pFnd = rACorrect.SearchWordsInList(
339 [ # # ]: 0 : pTxtNd->GetTxt(), rSttPos, nEndPos, *this, eLang );
340 : 0 : SwDoc* pDoc = rEditSh.GetDoc();
341 [ # # ]: 0 : if( pFnd )
342 : : {
343 : 0 : const SwNodeIndex& rNd = rCrsr.GetPoint()->nNode;
344 [ # # ]: 0 : SwPaM aPam( rNd, rSttPos, rNd, nEndPos );
345 : :
346 [ # # ]: 0 : if( pFnd->IsTextOnly() )
347 : : {
348 : : //JP 22.04.99: Bug 63883 - Sonderbehandlung fuer Punkte.
349 [ # # ]: 0 : if( !bLastCharIsPoint || !pFnd->GetLong().Len() ||
[ # # # # ]
[ # # ]
350 : 0 : '.' != pFnd->GetLong().GetChar( pFnd->GetLong().Len() - 1 ) )
351 : : {
352 : : // replace the selection
353 [ # # ]: 0 : pDoc->ReplaceRange( aPam, pFnd->GetLong(), false);
354 : 0 : bRet = sal_True;
355 : : }
356 : : }
357 : : else
358 : : {
359 [ # # ][ # # ]: 0 : SwTextBlocks aTBlks( rACorrect.GetAutoCorrFileName( eLang, sal_False, sal_True ));
[ # # ]
360 [ # # ]: 0 : sal_uInt16 nPos = aTBlks.GetIndex( pFnd->GetShort() );
361 [ # # ][ # # ]: 0 : if( USHRT_MAX != nPos && aTBlks.BeginGetDoc( nPos ) )
[ # # ][ # # ]
362 : : {
363 [ # # ]: 0 : DeleteSel( aPam );
364 [ # # ]: 0 : pDoc->DontExpandFmt( *aPam.GetPoint() );
365 : :
366 [ # # ]: 0 : if( ppPara )
367 : : {
368 : : OSL_ENSURE( !pIdx, "wer hat seinen Index nicht geloescht?" );
369 [ # # ][ # # ]: 0 : pIdx = new SwNodeIndex( rCrsr.GetPoint()->nNode, -1 );
370 : : }
371 : :
372 : : //
373 [ # # ]: 0 : SwDoc* pAutoDoc = aTBlks.GetDoc();
374 [ # # ][ # # ]: 0 : SwNodeIndex aSttIdx( pAutoDoc->GetNodes().GetEndOfExtras(), 1 );
375 [ # # ][ # # ]: 0 : SwCntntNode* pCntntNd = pAutoDoc->GetNodes().GoNext( &aSttIdx );
376 [ # # ]: 0 : SwPaM aCpyPam( aSttIdx );
377 : :
378 [ # # ]: 0 : const SwTableNode* pTblNd = pCntntNd->FindTableNode();
379 [ # # ]: 0 : if( pTblNd )
380 : : {
381 [ # # ]: 0 : aCpyPam.GetPoint()->nContent.Assign( 0, 0 );
382 [ # # ]: 0 : aCpyPam.GetPoint()->nNode = *pTblNd;
383 : : }
384 [ # # ]: 0 : aCpyPam.SetMark();
385 : :
386 : : // dann bis zum Ende vom Nodes Array
387 [ # # ][ # # ]: 0 : aCpyPam.GetPoint()->nNode.Assign( pAutoDoc->GetNodes().GetEndOfContent(), -1 );
388 : 0 : pCntntNd = aCpyPam.GetCntntNode();
389 [ # # ][ # # ]: 0 : aCpyPam.GetPoint()->nContent.Assign( pCntntNd, pCntntNd->Len() );
[ # # ]
390 : :
391 : 0 : SwDontExpandItem aExpItem;
392 [ # # ]: 0 : aExpItem.SaveDontExpandItems( *aPam.GetPoint() );
393 : :
394 [ # # ]: 0 : pAutoDoc->CopyRange( aCpyPam, *aPam.GetPoint(), false );
395 : :
396 [ # # ]: 0 : aExpItem.RestoreDontExpandItems( *aPam.GetPoint() );
397 : :
398 [ # # ]: 0 : if( ppPara )
399 : : {
400 [ # # ]: 0 : (*pIdx)++;
401 : 0 : pTxtNd = pIdx->GetNode().GetTxtNode();
402 : : }
403 [ # # ][ # # ]: 0 : bRet = sal_True;
[ # # ]
404 : : }
405 [ # # ][ # # ]: 0 : aTBlks.EndGetDoc();
406 [ # # ]: 0 : }
407 : : }
408 : :
409 [ # # ][ # # ]: 0 : if( bRet && ppPara && pTxtNd )
[ # # ]
410 : 0 : *ppPara = &pTxtNd->GetTxt();
411 : :
412 : 0 : return bRet;
413 : : }
414 : :
415 : :
416 : : // wird nach dem austauschen der Zeichen von den Funktionen
417 : : // - FnCptlSttWrd
418 : : // - FnCptlSttSntnc
419 : : // gerufen. Dann koennen die Worte ggfs. in die Ausnahmelisten
420 : : // aufgenommen werden.
421 : 0 : void SwAutoCorrDoc::SaveCpltSttWord( sal_uLong nFlag, xub_StrLen nPos,
422 : : const String& rExceptWord,
423 : : sal_Unicode cChar )
424 : : {
425 [ # # ]: 0 : sal_uLong nNode = pIdx ? pIdx->GetIndex() : rCrsr.GetPoint()->nNode.GetIndex();
426 : 0 : LanguageType eLang = GetLanguage(nPos, sal_False);
427 : : rEditSh.GetDoc()->SetAutoCorrExceptWord( new SwAutoCorrExceptWord( nFlag,
428 [ # # ]: 0 : nNode, nPos, rExceptWord, cChar, eLang ));
429 : 0 : }
430 : :
431 : 0 : LanguageType SwAutoCorrDoc::GetLanguage( xub_StrLen nPos, sal_Bool bPrevPara ) const
432 : : {
433 : 0 : LanguageType eRet = LANGUAGE_SYSTEM;
434 : :
435 : : SwTxtNode* pNd = (( bPrevPara && pIdx )
436 : : ? *pIdx
437 [ # # ][ # # ]: 0 : : rCrsr.GetPoint()->nNode ).GetNode().GetTxtNode();
438 : :
439 [ # # ]: 0 : if( pNd )
440 : 0 : eRet = pNd->GetLang( nPos, 0 );
441 [ # # ]: 0 : if(LANGUAGE_SYSTEM == eRet)
442 : 0 : eRet = (LanguageType)GetAppLanguage();
443 : 0 : return eRet;
444 : : }
445 : :
446 : 0 : void SwAutoCorrExceptWord::CheckChar( const SwPosition& rPos, sal_Unicode cChr )
447 : : {
448 : : // nur testen ob es eine Verbesserung ist. Wenn ja, dann das Wort
449 : : // in die Ausnahmeliste aufnehmen.
450 [ # # ]: 0 : if( cChar == cChr && rPos.nNode.GetIndex() == nNode &&
[ # # # # ]
[ # # ]
451 : 0 : rPos.nContent.GetIndex() == nCntnt )
452 : : {
453 : : // die akt. Autokorrektur besorgen:
454 : 0 : SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get().GetAutoCorrect();
455 : :
456 : : // dann in die Liste aufnehmen:
457 [ # # ]: 0 : if( CptlSttWrd & nFlags )
458 : 0 : pACorr->AddWrtSttException( sWord, eLanguage );
459 [ # # ]: 0 : else if( CptlSttSntnc & nFlags )
460 : 0 : pACorr->AddCplSttException( sWord, eLanguage );
461 : : }
462 : 0 : }
463 : :
464 : :
465 : 0 : sal_Bool SwAutoCorrExceptWord::CheckDelChar( const SwPosition& rPos )
466 : : {
467 : 0 : sal_Bool bRet = sal_False;
468 [ # # ]: 0 : if( !bDeleted && rPos.nNode.GetIndex() == nNode &&
[ # # # # ]
[ # # ]
469 : 0 : rPos.nContent.GetIndex() == nCntnt )
470 : 0 : bDeleted = bRet = sal_True;
471 : 0 : return bRet;
472 : : }
473 : :
474 : 8 : SwDontExpandItem::~SwDontExpandItem()
475 : : {
476 [ - + ]: 8 : delete pDontExpItems;
477 : 8 : }
478 : :
479 : 8 : void SwDontExpandItem::SaveDontExpandItems( const SwPosition& rPos )
480 : : {
481 : 8 : const SwTxtNode* pTxtNd = rPos.nNode.GetNode().GetTxtNode();
482 [ + - ]: 8 : if( pTxtNd )
483 : : {
484 : 8 : pDontExpItems = new SfxItemSet( ((SwDoc*)pTxtNd->GetDoc())->GetAttrPool(),
485 [ + - ]: 8 : aCharFmtSetRange );
486 : 8 : xub_StrLen n = rPos.nContent.GetIndex();
487 [ + - ]: 8 : if( !pTxtNd->GetAttr( *pDontExpItems, n, n,
488 : 8 : n != pTxtNd->GetTxt().Len() ))
489 [ + - ]: 8 : delete pDontExpItems, pDontExpItems = 0;
490 : : }
491 : 8 : }
492 : :
493 : 8 : void SwDontExpandItem::RestoreDontExpandItems( const SwPosition& rPos )
494 : : {
495 : 8 : SwTxtNode* pTxtNd = rPos.nNode.GetNode().GetTxtNode();
496 [ + - ]: 8 : if( pTxtNd )
497 : : {
498 : 8 : xub_StrLen nStart = rPos.nContent.GetIndex();
499 [ + + ]: 8 : if( nStart == pTxtNd->GetTxt().Len() )
500 : 2 : pTxtNd->FmtToTxtAttr( pTxtNd );
501 : :
502 [ - + ][ # # ]: 8 : if( pTxtNd->GetpSwpHints() && pTxtNd->GetpSwpHints()->Count() )
[ - + ]
503 : : {
504 : 0 : const sal_uInt16 nSize = pTxtNd->GetpSwpHints()->Count();
505 : : sal_uInt16 n;
506 : : xub_StrLen nAttrStart;
507 : : const xub_StrLen* pAttrEnd;
508 : :
509 [ # # ]: 0 : for( n = 0; n < nSize; ++n )
510 : : {
511 : 0 : SwTxtAttr* pHt = pTxtNd->GetpSwpHints()->GetTextHint( n );
512 : 0 : nAttrStart = *pHt->GetStart();
513 [ # # ]: 0 : if( nAttrStart > nStart ) // ueber den Bereich hinaus
514 : 0 : break;
515 : :
516 [ # # ]: 0 : if( 0 != ( pAttrEnd = pHt->GetEnd() ) &&
[ # # # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
517 : : ( ( nAttrStart < nStart &&
518 : 0 : ( pHt->DontExpand() ? nStart < *pAttrEnd
519 : : : nStart <= *pAttrEnd )) ||
520 : : ( nStart == nAttrStart &&
521 : : ( nAttrStart == *pAttrEnd || !nStart ))) )
522 : : {
523 : : const SfxPoolItem* pItem;
524 [ # # ][ # # ]: 0 : if( !pDontExpItems || SFX_ITEM_SET != pDontExpItems->
[ # # ][ # # ]
525 [ # # ][ # # ]: 0 : GetItemState( pHt->Which(), sal_False, &pItem ) ||
526 [ # # ]: 0 : *pItem != pHt->GetAttr() )
527 : : {
528 : : // das Attribut war vorher nicht in dieser Form im Absatz
529 : : // gesetzt, also kann es nur durchs einfuegen/kopieren erzeugt
530 : : // worden sein. Damit ist es ein Kandiadat fuers DontExpand
531 : 0 : pHt->SetDontExpand( sal_True );
532 : : }
533 : : }
534 : : }
535 : : }
536 : : }
537 : 8 : }
538 : :
539 : :
540 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|