1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"
#include <com/sun/star/util/SearchOptions.hpp>
#include <com/sun/star/util/SearchFlags.hpp>
#include <com/sun/star/i18n/TransliterationModules.hpp>
#include <tools/urlobj.hxx>
#include <svtools/txtcmp.hxx>
#ifndef SVTOOLS_FSTATHELPER_HXX
#include <svl/fstathelper.hxx>
#endif
#include <sfx2/docfile.hxx>
#include "editeng/unolingu.hxx"
#include <swtypes.hxx>
#include <editsh.hxx>
#include <doc.hxx>
#include <pam.hxx>
#include <viewopt.hxx>
#include <ndtxt.hxx>
#include <errhdl.hxx>
#include <swundo.hxx>
#include <undobj.hxx>
#include <txttxmrk.hxx>
#include <edimp.hxx>
#include <tox.hxx>
#include <doctxm.hxx>
#include <docary.hxx>
#include <mdiexp.hxx>
#ifndef _STATSTR_HRC
#include <statstr.hrc>
#endif
#include <bookmrk.hxx>
#include <xmloff/odffields.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::i18n;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::util;
/*--------------------------------------------------------------------
Beschreibung: Verzeichnismarkierung ins Dokument einfuegen/loeschen
--------------------------------------------------------------------*/
void SwEditShell::Insert(const SwTOXMark& rMark)
{
BOOL bInsAtPos = rMark.IsAlternativeText();
StartAllAction();
FOREACHPAM_START(this)
const SwPosition *pStt = PCURCRSR->Start(),
*pEnd = PCURCRSR->End();
if( bInsAtPos )
{
SwPaM aTmp( *pStt );
GetDoc()->InsertPoolItem( aTmp, rMark, 0 );
}
else if( *pEnd != *pStt )
{
GetDoc()->InsertPoolItem( *PCURCRSR, rMark,
nsSetAttrMode::SETATTR_DONTEXPAND );
}
FOREACHPAM_END()
EndAllAction();
}
void SwEditShell::DeleteTOXMark( SwTOXMark* pMark )
{
SET_CURR_SHELL( this );
StartAllAction();
pDoc->DeleteTOXMark( pMark );
EndAllAction();
}
/*--------------------------------------------------------------------
Beschreibung: Alle Verzeichnismarkierungen am SPoint zusammensuchen
--------------------------------------------------------------------*/
USHORT SwEditShell::GetCurTOXMarks(SwTOXMarks& rMarks) const
{
return GetDoc()->GetCurTOXMark( *GetCrsr()->Start(), rMarks );
}
/* -----------------01.09.99 16:05-------------------
--------------------------------------------------*/
BOOL SwEditShell::IsTOXBaseReadonly(const SwTOXBase& rTOXBase) const
{
ASSERT( rTOXBase.ISA( SwTOXBaseSection ), "no TOXBaseSection!" );
const SwTOXBaseSection& rTOXSect = (const SwTOXBaseSection&)rTOXBase;
return rTOXSect.IsProtect();
}
/* -----------------18.10.99 15:53-------------------
--------------------------------------------------*/
void SwEditShell::SetTOXBaseReadonly(const SwTOXBase& rTOXBase, BOOL bReadonly)
{
ASSERT( rTOXBase.ISA( SwTOXBaseSection ), "no TOXBaseSection!" );
const SwTOXBaseSection& rTOXSect = (const SwTOXBaseSection&)rTOXBase;
((SwTOXBase&)rTOXBase).SetProtected(bReadonly);
ASSERT( rTOXSect.SwSection::GetType() == TOX_CONTENT_SECTION, "not a TOXContentSection" );
SwSectionData aSectionData(rTOXSect);
aSectionData.SetProtectFlag(bReadonly);
UpdateSection( GetSectionFmtPos( *rTOXSect.GetFmt() ), aSectionData, 0 );
}
/* -----------------02.09.99 07:47-------------------
--------------------------------------------------*/
const SwTOXBase* SwEditShell::GetDefaultTOXBase( TOXTypes eTyp, BOOL bCreate )
{
return GetDoc()->GetDefaultTOXBase( eTyp, bCreate );
}
/* -----------------02.09.99 08:05-------------------
--------------------------------------------------*/
void SwEditShell::SetDefaultTOXBase(const SwTOXBase& rBase)
{
GetDoc()->SetDefaultTOXBase(rBase);
}
/*--------------------------------------------------------------------
Beschreibung: Verzeichnis einfuegen, und Inhalt erzeugen
--------------------------------------------------------------------*/
void SwEditShell::InsertTableOf( const SwTOXBase& rTOX, const SfxItemSet* pSet )
{
SET_CURR_SHELL( this );
StartAllAction();
SwDocShell* pDocSh = GetDoc()->GetDocShell();
::StartProgress( STR_STATSTR_TOX_INSERT, 0, 0, pDocSh );
::SetProgressText( STR_STATSTR_TOX_INSERT, pDocSh );
// Einfuegen des Verzeichnisses
const SwTOXBaseSection* pTOX = pDoc->InsertTableOf(
*GetCrsr()->GetPoint(), rTOX, pSet, TRUE );
ASSERT(pTOX, "Kein aktuelles Verzeichnis");
// Formatierung anstossen
CalcLayout();
// Seitennummern eintragen
((SwTOXBaseSection*)pTOX)->UpdatePageNum();
pTOX->SetPosAtStartEnd( *GetCrsr()->GetPoint() );
// Fix fuer leere Verzeichnisse
InvalidateWindows( aVisArea );
::EndProgress( pDocSh );
EndAllAction();
}
/*--------------------------------------------------------------------
Beschreibung: Verzeichnisinhalt erneuern
--------------------------------------------------------------------*/
BOOL SwEditShell::UpdateTableOf( const SwTOXBase& rTOX, const SfxItemSet* pSet )
{
BOOL bRet = FALSE;
ASSERT( rTOX.ISA( SwTOXBaseSection ), "keine TOXBaseSection!" );
SwTOXBaseSection* pTOX = (SwTOXBaseSection*)&rTOX;
ASSERT(pTOX, "Keine aktuelles Verzeichnis");
const SwSectionNode* pSectNd;
if( pTOX && 0 != ( pSectNd = pTOX->GetFmt()->GetSectionNode() ) )
{
SwDoc* pMyDoc = GetDoc();
SwDocShell* pDocSh = pMyDoc->GetDocShell();
BOOL bInIndex = pTOX == GetCurTOX();
SET_CURR_SHELL( this );
StartAllAction();
::StartProgress( STR_STATSTR_TOX_UPDATE, 0, 0, pDocSh );
::SetProgressText( STR_STATSTR_TOX_UPDATE, pDocSh );
pMyDoc->StartUndo(UNDO_TOXCHANGE, NULL);
// Verzeichnisrumpf erzeugen
pTOX->Update(pSet);
// Cursor korrigieren
if( bInIndex )
pTOX->SetPosAtStartEnd( *GetCrsr()->GetPoint() );
// Formatierung anstossen
CalcLayout();
// Seitennummern eintragen
pTOX->UpdatePageNum();
pMyDoc->EndUndo(UNDO_TOXCHANGE, NULL);
::EndProgress( pDocSh );
EndAllAction();
}
return bRet;
}
BOOL SwEditShell::UpdateField( sw::mark::IFieldmark &fieldBM)
{
// SwDocShell* pDocSh = pDoc->GetDocShell();
//@TODO implement me...; add undo etc...
if ( pDoc && fieldBM.IsExpanded( ) ) {
SwPosition aSttPos = fieldBM.GetMarkStart( );
aSttPos.nContent++;
SwPosition aEndPos = fieldBM.GetMarkEnd( );
aEndPos.nContent--;
SwPaM aPaM( aSttPos, aEndPos );
pDoc->DeleteRange(aPaM);
pDoc->InsertString(aPaM, String::CreateFromAscii("Implement me ;-)") );
}
return TRUE;
}
/*--------------------------------------------------------------------
Beschreibung: Aktuelles Verzeichnis vor oder in dem der Cursor
steht
--------------------------------------------------------------------*/
const SwTOXBase* SwEditShell::GetCurTOX() const
{
return GetDoc()->GetCurTOX( *GetCrsr()->GetPoint() );
}
BOOL SwEditShell::DeleteTOX( const SwTOXBase& rTOXBase, BOOL bDelNodes )
{
return GetDoc()->DeleteTOX( (SwTOXBase&)rTOXBase, bDelNodes );
}
/*--------------------------------------------------------------------
Beschreibung: Typen der Verzeichnisse verwalten
--------------------------------------------------------------------*/
const SwTOXType* SwEditShell::GetTOXType(TOXTypes eTyp, USHORT nId) const
{
return pDoc->GetTOXType(eTyp, nId);
}
/*--------------------------------------------------------------------
Beschreibung: Schluessel fuer Stichwortverzeichnisse verwalten
--------------------------------------------------------------------*/
USHORT SwEditShell::GetTOIKeys( SwTOIKeyType eTyp, SvStringsSort& rArr ) const
{
return GetDoc()->GetTOIKeys( eTyp, rArr );
}
USHORT SwEditShell::GetTOXCount() const
{
const SwSectionFmts& rFmts = GetDoc()->GetSections();
USHORT nRet = 0;
for( USHORT n = rFmts.Count(); n; )
{
const SwSection* pSect = rFmts[ --n ]->GetSection();
if( TOX_CONTENT_SECTION == pSect->GetType() &&
pSect->GetFmt()->GetSectionNode() )
++nRet;
}
return nRet;
}
const SwTOXBase* SwEditShell::GetTOX( USHORT nPos ) const
{
const SwSectionFmts& rFmts = GetDoc()->GetSections();
for( USHORT n = 0, nCnt = 0; n < rFmts.Count(); ++n )
{
const SwSection* pSect = rFmts[ n ]->GetSection();
if( TOX_CONTENT_SECTION == pSect->GetType() &&
pSect->GetFmt()->GetSectionNode() &&
nCnt++ == nPos )
{
ASSERT( pSect->ISA( SwTOXBaseSection ), "keine TOXBaseSection!" );
return (SwTOXBaseSection*)pSect;
}
}
return 0;
}
// nach einlesen einer Datei alle Verzeichnisse updaten
void SwEditShell::SetUpdateTOX( BOOL bFlag )
{
GetDoc()->SetUpdateTOX( bFlag );
}
BOOL SwEditShell::IsUpdateTOX() const
{
return GetDoc()->IsUpdateTOX();
}
/* -----------------26.08.99 13:49-------------------
--------------------------------------------------*/
const String& SwEditShell::GetTOIAutoMarkURL() const
{
return GetDoc()->GetTOIAutoMarkURL();
}
/* -----------------26.08.99 13:49-------------------
--------------------------------------------------*/
void SwEditShell::SetTOIAutoMarkURL(const String& rSet)
{
GetDoc()->SetTOIAutoMarkURL(rSet);
}
/* -----------------26.08.99 09:29-------------------
--------------------------------------------------*/
void SwEditShell::ApplyAutoMark()
{
StartAllAction();
BOOL bDoesUndo = DoesUndo();
DoUndo(FALSE);
//1. remove all automatic generated index entries if AutoMarkURL has a
// length and the file exists
//2. load file
//3. select all occurrences of the searched words
//4. apply index entries
String sAutoMarkURL(GetDoc()->GetTOIAutoMarkURL());
if( sAutoMarkURL.Len() && FStatHelper::IsDocument( sAutoMarkURL ))
{
//1.
const SwTOXType* pTOXType = GetTOXType(TOX_INDEX, 0);
SwClientIter aIter(*(SwTOXType*)pTOXType);
SwTOXMark* pMark = (SwTOXMark*)aIter.First(TYPE(SwTOXMark));
while( pMark )
{
if(pMark->IsAutoGenerated() && pMark->GetTxtTOXMark())
DeleteTOXMark(pMark);
pMark = (SwTOXMark*)aIter.Next();
}
//2.
SfxMedium aMedium( sAutoMarkURL, STREAM_STD_READ, TRUE );
SvStream& rStrm = *aMedium.GetInStream();
const String sZero('0');
Push();
rtl_TextEncoding eChrSet = ::gsl_getSystemTextEncoding();
//
// SearchOptions to be used in loop below
//
//SearchAlgorithms eSrchType = SearchAlgorithms_ABSOLUTE;
//OUString aSrchStr = rText;
BOOL bCaseSensitive = TRUE;
BOOL bWordOnly = FALSE;
BOOL bSrchInSel = FALSE;
BOOL bLEV_Relaxed = TRUE;
INT32 nLEV_Other = 2; // -> changedChars;
INT32 nLEV_Longer = 3; //! -> deletedChars;
INT32 nLEV_Shorter = 1; //! -> insertedChars;
INT32 nTransliterationFlags = 0;
//
INT32 nSrchFlags = 0;
if (!bCaseSensitive)
{
nSrchFlags |= SearchFlags::ALL_IGNORE_CASE;
nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
}
if ( bWordOnly)
nSrchFlags |= SearchFlags::NORM_WORD_ONLY;
if ( bLEV_Relaxed)
nSrchFlags |= SearchFlags::LEV_RELAXED;
if ( bSrchInSel)
nSrchFlags |= (SearchFlags::REG_NOT_BEGINOFLINE |
SearchFlags::REG_NOT_ENDOFLINE );
//
rtl::OUString sEmpty;
SearchOptions aSearchOpt(
SearchAlgorithms_ABSOLUTE, nSrchFlags,
sEmpty, sEmpty,
SvxCreateLocale( LANGUAGE_SYSTEM ),
nLEV_Other, nLEV_Longer, nLEV_Shorter,
nTransliterationFlags );
while( !rStrm.GetError() && !rStrm.IsEof() )
{
ByteString aRdLine;
rStrm.ReadLine( aRdLine );
// # -> comment
// ; -> delimiter between entries ->
// Format: TextToSearchFor;AlternativeString;PrimaryKey;SecondaryKey;CaseSensitive;WordOnly
// Leading and trailing blanks are ignored
if( aRdLine.Len() && '#' != aRdLine.GetChar(0) )
{
String sLine( aRdLine, eChrSet );
xub_StrLen nTokenPos = 0;
String sToSelect( sLine.GetToken(0, ';', nTokenPos ) );
if( sToSelect.Len() )
{
String sAlternative = sLine.GetToken(0, ';', nTokenPos);
String sPrimary = sLine.GetToken(0, ';', nTokenPos);
String sSecondary = sLine.GetToken(0, ';', nTokenPos);
String sCase = sLine.GetToken(0, ';', nTokenPos);
String sWordOnly = sLine.GetToken(0, ';', nTokenPos);
//3.
bCaseSensitive = sCase.Len() && sCase != sZero;
bWordOnly = sWordOnly.Len() && sWordOnly != sZero;
//
if (!bCaseSensitive)
{
//nSrchFlags |= SearchFlags::ALL_IGNORE_CASE;
aSearchOpt.transliterateFlags |=
TransliterationModules_IGNORE_CASE;
}
else
{
//aSearchOpt.searchFlag &= ~SearchFlags::ALL_IGNORE_CASE;
aSearchOpt.transliterateFlags &=
~TransliterationModules_IGNORE_CASE;
}
if ( bWordOnly)
aSearchOpt.searchFlag |= SearchFlags::NORM_WORD_ONLY;
else
aSearchOpt.searchFlag &= ~SearchFlags::NORM_WORD_ONLY;
//
aSearchOpt.searchString = sToSelect;
KillPams();
BOOL bCancel;
// todo/mba: assuming that notes shouldn't be searched
BOOL bSearchInNotes = FALSE;
ULONG nRet = Find( aSearchOpt, bSearchInNotes, DOCPOS_START, DOCPOS_END, bCancel,
(FindRanges)(FND_IN_SELALL|FND_IN_BODYONLY),
FALSE );
if(nRet)
{
SwTOXMark* pTmpMark = new SwTOXMark(pTOXType);
if( sPrimary.Len() )
{
pTmpMark->SetPrimaryKey( sPrimary );
if( sSecondary.Len() )
pTmpMark->SetSecondaryKey( sSecondary );
}
if(sAlternative.Len())
pTmpMark->SetAlternativeText(sAlternative);
pTmpMark->SetMainEntry(FALSE);
pTmpMark->SetAutoGenerated(TRUE);
//4.
SwEditShell::Insert(*pTmpMark);
}
}
}
}
KillPams();
Pop(FALSE);
}
DoUndo(bDoesUndo);
EndAllAction();
}
|