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 <com/sun/star/util/SearchOptions.hpp>
31 : : #include <com/sun/star/util/SearchFlags.hpp>
32 : : #include <com/sun/star/i18n/TransliterationModules.hpp>
33 : : #include <comphelper/string.hxx>
34 : : #include <svl/fstathelper.hxx>
35 : :
36 : : #include <svtools/txtcmp.hxx>
37 : :
38 : : #include <sfx2/docfile.hxx>
39 : :
40 : : #include <xmloff/odffields.hxx>
41 : :
42 : : #include <editeng/unolingu.hxx>
43 : :
44 : : #include <swtypes.hxx>
45 : : #include <editsh.hxx>
46 : : #include <doc.hxx>
47 : : #include <IDocumentUndoRedo.hxx>
48 : : #include <pam.hxx>
49 : : #include <viewopt.hxx>
50 : : #include <ndtxt.hxx>
51 : : #include <swundo.hxx>
52 : : #include <txttxmrk.hxx>
53 : : #include <edimp.hxx>
54 : : #include <tox.hxx>
55 : : #include <doctxm.hxx>
56 : : #include <docary.hxx>
57 : : #include <mdiexp.hxx>
58 : : #include <statstr.hrc>
59 : : #include <bookmrk.hxx>
60 : :
61 : : using namespace ::com::sun::star;
62 : : using namespace ::com::sun::star::i18n;
63 : : using namespace ::com::sun::star::lang;
64 : : using namespace ::com::sun::star::util;
65 : :
66 : : /*--------------------------------------------------------------------
67 : : Beschreibung: Verzeichnismarkierung ins Dokument einfuegen/loeschen
68 : : --------------------------------------------------------------------*/
69 : :
70 : :
71 : 0 : void SwEditShell::Insert(const SwTOXMark& rMark)
72 : : {
73 : 0 : sal_Bool bInsAtPos = rMark.IsAlternativeText();
74 : 0 : StartAllAction();
75 [ # # ]: 0 : FOREACHPAM_START(this)
76 : :
77 : 0 : const SwPosition *pStt = PCURCRSR->Start(),
78 : 0 : *pEnd = PCURCRSR->End();
79 [ # # ]: 0 : if( bInsAtPos )
80 : : {
81 [ # # ]: 0 : SwPaM aTmp( *pStt );
82 [ # # ][ # # ]: 0 : GetDoc()->InsertPoolItem( aTmp, rMark, 0 );
83 : : }
84 [ # # ]: 0 : else if( *pEnd != *pStt )
85 : : {
86 : 0 : GetDoc()->InsertPoolItem( *PCURCRSR, rMark,
87 : 0 : nsSetAttrMode::SETATTR_DONTEXPAND );
88 : : }
89 : :
90 : 0 : FOREACHPAM_END()
91 : 0 : EndAllAction();
92 : 0 : }
93 : :
94 : :
95 : :
96 : 0 : void SwEditShell::DeleteTOXMark( SwTOXMark* pMark )
97 : : {
98 [ # # ]: 0 : SET_CURR_SHELL( this );
99 [ # # ]: 0 : StartAllAction();
100 : :
101 [ # # ]: 0 : pDoc->DeleteTOXMark( pMark );
102 : :
103 [ # # ][ # # ]: 0 : EndAllAction();
104 : 0 : }
105 : :
106 : :
107 : : /*--------------------------------------------------------------------
108 : : Beschreibung: Alle Verzeichnismarkierungen am SPoint zusammensuchen
109 : : --------------------------------------------------------------------*/
110 : :
111 : 24 : sal_uInt16 SwEditShell::GetCurTOXMarks(SwTOXMarks& rMarks) const
112 : : {
113 : 24 : return GetDoc()->GetCurTOXMark( *GetCrsr()->Start(), rMarks );
114 : : }
115 : :
116 : 0 : sal_Bool SwEditShell::IsTOXBaseReadonly(const SwTOXBase& rTOXBase) const
117 : : {
118 : : OSL_ENSURE( rTOXBase.ISA( SwTOXBaseSection ), "no TOXBaseSection!" );
119 : 0 : const SwTOXBaseSection& rTOXSect = (const SwTOXBaseSection&)rTOXBase;
120 : 0 : return rTOXSect.IsProtect();
121 : : }
122 : :
123 : 0 : void SwEditShell::SetTOXBaseReadonly(const SwTOXBase& rTOXBase, sal_Bool bReadonly)
124 : : {
125 : : OSL_ENSURE( rTOXBase.ISA( SwTOXBaseSection ), "no TOXBaseSection!" );
126 : 0 : const SwTOXBaseSection& rTOXSect = (const SwTOXBaseSection&)rTOXBase;
127 : 0 : ((SwTOXBase&)rTOXBase).SetProtected(bReadonly);
128 : : OSL_ENSURE( rTOXSect.SwSection::GetType() == TOX_CONTENT_SECTION, "not a TOXContentSection" );
129 : :
130 [ # # ]: 0 : SwSectionData aSectionData(rTOXSect);
131 : 0 : aSectionData.SetProtectFlag(bReadonly);
132 [ # # ][ # # ]: 0 : UpdateSection( GetSectionFmtPos( *rTOXSect.GetFmt() ), aSectionData, 0 );
[ # # ]
133 : 0 : }
134 : :
135 : 0 : const SwTOXBase* SwEditShell::GetDefaultTOXBase( TOXTypes eTyp, sal_Bool bCreate )
136 : : {
137 : 0 : return GetDoc()->GetDefaultTOXBase( eTyp, bCreate );
138 : : }
139 : :
140 : 0 : void SwEditShell::SetDefaultTOXBase(const SwTOXBase& rBase)
141 : : {
142 : 0 : GetDoc()->SetDefaultTOXBase(rBase);
143 : 0 : }
144 : :
145 : : /*--------------------------------------------------------------------
146 : : Beschreibung: Verzeichnis einfuegen, und Inhalt erzeugen
147 : : --------------------------------------------------------------------*/
148 : :
149 : 0 : void SwEditShell::InsertTableOf( const SwTOXBase& rTOX, const SfxItemSet* pSet )
150 : : {
151 [ # # ]: 0 : SET_CURR_SHELL( this );
152 [ # # ]: 0 : StartAllAction();
153 : :
154 : 0 : SwDocShell* pDocSh = GetDoc()->GetDocShell();
155 [ # # ]: 0 : ::StartProgress( STR_STATSTR_TOX_INSERT, 0, 0, pDocSh );
156 [ # # ]: 0 : ::SetProgressText( STR_STATSTR_TOX_INSERT, pDocSh );
157 : :
158 : : // Einfuegen des Verzeichnisses
159 : : const SwTOXBaseSection* pTOX = pDoc->InsertTableOf(
160 [ # # ][ # # ]: 0 : *GetCrsr()->GetPoint(), rTOX, pSet, sal_True );
161 : : OSL_ENSURE(pTOX, "Kein aktuelles Verzeichnis");
162 : :
163 : : // Formatierung anstossen
164 [ # # ]: 0 : CalcLayout();
165 : :
166 : : // Seitennummern eintragen
167 [ # # ]: 0 : ((SwTOXBaseSection*)pTOX)->UpdatePageNum();
168 : :
169 [ # # ][ # # ]: 0 : pTOX->SetPosAtStartEnd( *GetCrsr()->GetPoint() );
170 : :
171 : : // Fix fuer leere Verzeichnisse
172 [ # # ]: 0 : InvalidateWindows( aVisArea );
173 [ # # ]: 0 : ::EndProgress( pDocSh );
174 [ # # ][ # # ]: 0 : EndAllAction();
175 : 0 : }
176 : :
177 : : /*--------------------------------------------------------------------
178 : : Beschreibung: Verzeichnisinhalt erneuern
179 : : --------------------------------------------------------------------*/
180 : :
181 : 0 : sal_Bool SwEditShell::UpdateTableOf( const SwTOXBase& rTOX, const SfxItemSet* pSet )
182 : : {
183 : 0 : sal_Bool bRet = sal_False;
184 : :
185 : : OSL_ENSURE( rTOX.ISA( SwTOXBaseSection ), "keine TOXBaseSection!" );
186 : 0 : SwTOXBaseSection* pTOX = (SwTOXBaseSection*)&rTOX;
187 : : OSL_ENSURE(pTOX, "Keine aktuelles Verzeichnis");
188 : : const SwSectionNode* pSectNd;
189 [ # # ][ # # ]: 0 : if( pTOX && 0 != ( pSectNd = pTOX->GetFmt()->GetSectionNode() ) )
[ # # ]
190 : : {
191 : 0 : SwDoc* pMyDoc = GetDoc();
192 : 0 : SwDocShell* pDocSh = pMyDoc->GetDocShell();
193 : :
194 [ # # ]: 0 : sal_Bool bInIndex = pTOX == GetCurTOX();
195 [ # # ]: 0 : SET_CURR_SHELL( this );
196 [ # # ]: 0 : StartAllAction();
197 : :
198 [ # # ]: 0 : ::StartProgress( STR_STATSTR_TOX_UPDATE, 0, 0, pDocSh );
199 [ # # ]: 0 : ::SetProgressText( STR_STATSTR_TOX_UPDATE, pDocSh );
200 : :
201 [ # # ][ # # ]: 0 : pMyDoc->GetIDocumentUndoRedo().StartUndo(UNDO_TOXCHANGE, NULL);
202 : :
203 : : // Verzeichnisrumpf erzeugen
204 [ # # ]: 0 : pTOX->Update(pSet);
205 : :
206 : : // Cursor korrigieren
207 [ # # ]: 0 : if( bInIndex )
208 [ # # ][ # # ]: 0 : pTOX->SetPosAtStartEnd( *GetCrsr()->GetPoint() );
209 : :
210 : : // Formatierung anstossen
211 [ # # ]: 0 : CalcLayout();
212 : :
213 : : // Seitennummern eintragen
214 [ # # ]: 0 : pTOX->UpdatePageNum();
215 : :
216 [ # # ][ # # ]: 0 : pMyDoc->GetIDocumentUndoRedo().EndUndo(UNDO_TOXCHANGE, NULL);
217 : :
218 [ # # ]: 0 : ::EndProgress( pDocSh );
219 [ # # ][ # # ]: 0 : EndAllAction();
220 : : }
221 : 0 : return bRet;
222 : : }
223 : :
224 : : /*--------------------------------------------------------------------
225 : : Beschreibung: Aktuelles Verzeichnis vor oder in dem der Cursor
226 : : steht
227 : : --------------------------------------------------------------------*/
228 : :
229 : 3683 : const SwTOXBase* SwEditShell::GetCurTOX() const
230 : : {
231 : 3683 : return GetDoc()->GetCurTOX( *GetCrsr()->GetPoint() );
232 : : }
233 : :
234 : 0 : sal_Bool SwEditShell::DeleteTOX( const SwTOXBase& rTOXBase, sal_Bool bDelNodes )
235 : : {
236 : 0 : return GetDoc()->DeleteTOX( (SwTOXBase&)rTOXBase, bDelNodes );
237 : : }
238 : :
239 : : /*--------------------------------------------------------------------
240 : : Beschreibung: Typen der Verzeichnisse verwalten
241 : : --------------------------------------------------------------------*/
242 : :
243 : 0 : const SwTOXType* SwEditShell::GetTOXType(TOXTypes eTyp, sal_uInt16 nId) const
244 : : {
245 : 0 : return pDoc->GetTOXType(eTyp, nId);
246 : : }
247 : :
248 : : /*--------------------------------------------------------------------
249 : : Beschreibung: Schluessel fuer Stichwortverzeichnisse verwalten
250 : : --------------------------------------------------------------------*/
251 : :
252 : 0 : sal_uInt16 SwEditShell::GetTOIKeys( SwTOIKeyType eTyp, std::vector<String>& rArr ) const
253 : : {
254 : 0 : return GetDoc()->GetTOIKeys( eTyp, rArr );
255 : : }
256 : :
257 : :
258 : 0 : sal_uInt16 SwEditShell::GetTOXCount() const
259 : : {
260 : 0 : const SwSectionFmts& rFmts = GetDoc()->GetSections();
261 : 0 : sal_uInt16 nRet = 0;
262 [ # # ]: 0 : for( sal_uInt16 n = rFmts.size(); n; )
263 : : {
264 : 0 : const SwSection* pSect = rFmts[ --n ]->GetSection();
265 [ # # ]: 0 : if( TOX_CONTENT_SECTION == pSect->GetType() &&
[ # # # # ]
266 : 0 : pSect->GetFmt()->GetSectionNode() )
267 : 0 : ++nRet;
268 : : }
269 : 0 : return nRet;
270 : : }
271 : :
272 : :
273 : 0 : const SwTOXBase* SwEditShell::GetTOX( sal_uInt16 nPos ) const
274 : : {
275 : 0 : const SwSectionFmts& rFmts = GetDoc()->GetSections();
276 [ # # ]: 0 : for( sal_uInt16 n = 0, nCnt = 0; n < rFmts.size(); ++n )
277 : : {
278 : 0 : const SwSection* pSect = rFmts[ n ]->GetSection();
279 [ # # ][ # # ]: 0 : if( TOX_CONTENT_SECTION == pSect->GetType() &&
[ # # # # ]
280 : 0 : pSect->GetFmt()->GetSectionNode() &&
281 : : nCnt++ == nPos )
282 : : {
283 : : OSL_ENSURE( pSect->ISA( SwTOXBaseSection ), "keine TOXBaseSection!" );
284 [ # # ]: 0 : return (SwTOXBaseSection*)pSect;
285 : : }
286 : : }
287 : 0 : return 0;
288 : : }
289 : :
290 : :
291 : : // nach einlesen einer Datei alle Verzeichnisse updaten
292 : 0 : void SwEditShell::SetUpdateTOX( sal_Bool bFlag )
293 : : {
294 : 0 : GetDoc()->SetUpdateTOX( bFlag );
295 : 0 : }
296 : :
297 : :
298 : 0 : sal_Bool SwEditShell::IsUpdateTOX() const
299 : : {
300 : 0 : return GetDoc()->IsUpdateTOX();
301 : : }
302 : :
303 : 0 : const String& SwEditShell::GetTOIAutoMarkURL() const
304 : : {
305 : 0 : return GetDoc()->GetTOIAutoMarkURL();
306 : : }
307 : :
308 : 0 : void SwEditShell::SetTOIAutoMarkURL(const String& rSet)
309 : : {
310 : 0 : GetDoc()->SetTOIAutoMarkURL(rSet);
311 : 0 : }
312 : :
313 : 0 : void SwEditShell::ApplyAutoMark()
314 : : {
315 [ # # ]: 0 : StartAllAction();
316 [ # # ]: 0 : sal_Bool bDoesUndo = DoesUndo();
317 [ # # ]: 0 : DoUndo(sal_False);
318 : : //1. remove all automatic generated index entries if AutoMarkURL has a
319 : : // length and the file exists
320 : : //2. load file
321 : : //3. select all occurrences of the searched words
322 : : //4. apply index entries
323 : :
324 [ # # ]: 0 : String sAutoMarkURL(GetDoc()->GetTOIAutoMarkURL());
325 [ # # ][ # # ]: 0 : if( sAutoMarkURL.Len() && FStatHelper::IsDocument( sAutoMarkURL ))
[ # # ][ # # ]
[ # # ]
[ # # # # ]
326 : : {
327 : : //1.
328 [ # # ]: 0 : const SwTOXType* pTOXType = GetTOXType(TOX_INDEX, 0);
329 : :
330 [ # # ]: 0 : SwTOXMarks aMarks;
331 [ # # ]: 0 : SwTOXMark::InsertTOXMarks( aMarks, *pTOXType );
332 [ # # ]: 0 : for( sal_uInt16 nMark=0; nMark<aMarks.size(); nMark++ )
333 : : {
334 : 0 : SwTOXMark* pMark = aMarks[nMark];
335 [ # # ][ # # ]: 0 : if(pMark->IsAutoGenerated() && pMark->GetTxtTOXMark())
[ # # ]
336 : : // mba: test iteration; objects are deleted in iteration
337 [ # # ]: 0 : DeleteTOXMark(pMark);
338 : : }
339 : :
340 : : //2.
341 [ # # ]: 0 : SfxMedium aMedium( sAutoMarkURL, STREAM_STD_READ );
342 [ # # ]: 0 : SvStream& rStrm = *aMedium.GetInStream();
343 : 0 : const sal_Unicode cZero('0');
344 [ # # ]: 0 : Push();
345 [ # # ]: 0 : rtl_TextEncoding eChrSet = ::osl_getThreadTextEncoding();
346 : :
347 : : //
348 : : // SearchOptions to be used in loop below
349 : : //
350 : 0 : sal_Bool bCaseSensitive = sal_True;
351 : 0 : sal_Bool bWordOnly = sal_False;
352 : 0 : sal_Bool bSrchInSel = sal_False;
353 : 0 : sal_Bool bLEV_Relaxed = sal_True;
354 : 0 : sal_Int32 nLEV_Other = 2; // -> changedChars;
355 : 0 : sal_Int32 nLEV_Longer = 3; //! -> deletedChars;
356 : 0 : sal_Int32 nLEV_Shorter = 1; //! -> insertedChars;
357 : 0 : sal_Int32 nTransliterationFlags = 0;
358 : : //
359 : 0 : sal_Int32 nSrchFlags = 0;
360 [ # # ]: 0 : if (!bCaseSensitive)
361 : : {
362 : 0 : nSrchFlags |= SearchFlags::ALL_IGNORE_CASE;
363 : 0 : nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
364 : : }
365 [ # # ]: 0 : if ( bWordOnly)
366 : 0 : nSrchFlags |= SearchFlags::NORM_WORD_ONLY;
367 [ # # ]: 0 : if ( bLEV_Relaxed)
368 : 0 : nSrchFlags |= SearchFlags::LEV_RELAXED;
369 [ # # ]: 0 : if ( bSrchInSel)
370 : : nSrchFlags |= (SearchFlags::REG_NOT_BEGINOFLINE |
371 : 0 : SearchFlags::REG_NOT_ENDOFLINE );
372 : : //
373 : 0 : rtl::OUString sEmpty;
374 : : SearchOptions aSearchOpt(
375 : : SearchAlgorithms_ABSOLUTE, nSrchFlags,
376 : : sEmpty, sEmpty,
377 : : SvxCreateLocale( LANGUAGE_SYSTEM ),
378 : : nLEV_Other, nLEV_Longer, nLEV_Shorter,
379 [ # # ]: 0 : nTransliterationFlags );
380 : :
381 [ # # ][ # # ]: 0 : while( !rStrm.GetError() && !rStrm.IsEof() )
[ # # ]
382 : : {
383 : 0 : rtl::OString aRdLine;
384 [ # # ]: 0 : rStrm.ReadLine( aRdLine );
385 : :
386 : : // # -> comment
387 : : // ; -> delimiter between entries ->
388 : : // Format: TextToSearchFor;AlternativeString;PrimaryKey;SecondaryKey;CaseSensitive;WordOnly
389 : : // Leading and trailing blanks are ignored
390 [ # # ][ # # ]: 0 : if( !aRdLine.isEmpty() && '#' != aRdLine[0] )
[ # # ]
391 : : {
392 [ # # ][ # # ]: 0 : String sLine(rtl::OStringToOUString(aRdLine, eChrSet));
393 : :
394 : 0 : xub_StrLen nTokenPos = 0;
395 [ # # ]: 0 : String sToSelect( sLine.GetToken(0, ';', nTokenPos ) );
396 [ # # ]: 0 : if( sToSelect.Len() )
397 : : {
398 [ # # ]: 0 : String sAlternative = sLine.GetToken(0, ';', nTokenPos);
399 [ # # ]: 0 : String sPrimary = sLine.GetToken(0, ';', nTokenPos);
400 [ # # ]: 0 : String sSecondary = sLine.GetToken(0, ';', nTokenPos);
401 [ # # ]: 0 : String sCase = sLine.GetToken(0, ';', nTokenPos);
402 [ # # ]: 0 : String sWordOnly = sLine.GetToken(0, ';', nTokenPos);
403 : :
404 : : //3.
405 [ # # ][ # # ]: 0 : bCaseSensitive = sCase.Len() && !comphelper::string::equals(sCase, cZero);
[ # # ][ # # ]
[ # # ]
406 [ # # ][ # # ]: 0 : bWordOnly = sWordOnly.Len() && !comphelper::string::equals(sWordOnly, cZero);
[ # # ][ # # ]
[ # # ]
407 : : //
408 [ # # ]: 0 : if (!bCaseSensitive)
409 : : {
410 : : aSearchOpt.transliterateFlags |=
411 : 0 : TransliterationModules_IGNORE_CASE;
412 : : }
413 : : else
414 : : {
415 : : aSearchOpt.transliterateFlags &=
416 : 0 : ~TransliterationModules_IGNORE_CASE;
417 : : }
418 [ # # ]: 0 : if ( bWordOnly)
419 : 0 : aSearchOpt.searchFlag |= SearchFlags::NORM_WORD_ONLY;
420 : : else
421 : 0 : aSearchOpt.searchFlag &= ~SearchFlags::NORM_WORD_ONLY;
422 : : //
423 [ # # ]: 0 : aSearchOpt.searchString = sToSelect;
424 : :
425 [ # # ]: 0 : KillPams();
426 : : sal_Bool bCancel;
427 : :
428 : : // todo/mba: assuming that notes shouldn't be searched
429 : 0 : sal_Bool bSearchInNotes = sal_False;
430 : : sal_uLong nRet = Find( aSearchOpt, bSearchInNotes, DOCPOS_START, DOCPOS_END, bCancel,
431 : : (FindRanges)(FND_IN_SELALL|FND_IN_BODYONLY|FND_IN_OTHER),
432 [ # # ]: 0 : sal_False );
433 : :
434 [ # # ]: 0 : if(nRet)
435 : : {
436 [ # # ][ # # ]: 0 : SwTOXMark* pTmpMark = new SwTOXMark(pTOXType);
437 [ # # ]: 0 : if( sPrimary.Len() )
438 : : {
439 [ # # ]: 0 : pTmpMark->SetPrimaryKey( sPrimary );
440 [ # # ]: 0 : if( sSecondary.Len() )
441 [ # # ]: 0 : pTmpMark->SetSecondaryKey( sSecondary );
442 : : }
443 [ # # ]: 0 : if(sAlternative.Len())
444 [ # # ]: 0 : pTmpMark->SetAlternativeText(sAlternative);
445 : 0 : pTmpMark->SetMainEntry(sal_False);
446 : 0 : pTmpMark->SetAutoGenerated(sal_True);
447 : : //4.
448 [ # # ]: 0 : SwEditShell::Insert(*pTmpMark);
449 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
[ # # ]
450 [ # # ][ # # ]: 0 : }
451 : : }
452 : 0 : }
453 [ # # ]: 0 : KillPams();
454 [ # # ][ # # ]: 0 : Pop(sal_False);
455 : : }
456 [ # # ]: 0 : DoUndo(bDoesUndo);
457 [ # # ][ # # ]: 0 : EndAllAction();
458 : 0 : }
459 : :
460 : :
461 : :
462 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|