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