xref: /AOO41X/main/sw/source/ui/index/toxmgr.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sw.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <wrtsh.hxx>
32*cdf0e10cSrcweir #include <shellres.hxx>
33*cdf0e10cSrcweir #include <swwait.hxx>
34*cdf0e10cSrcweir #include <view.hxx>
35*cdf0e10cSrcweir #include <toxmgr.hxx>
36*cdf0e10cSrcweir #include <crsskip.hxx>
37*cdf0e10cSrcweir #include <doc.hxx>
38*cdf0e10cSrcweir #include <IDocumentUndoRedo.hxx>
39*cdf0e10cSrcweir #include <swundo.hxx>
40*cdf0e10cSrcweir #include <globals.hrc>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir /*--------------------------------------------------------------------
43*cdf0e10cSrcweir 	Beschreibung: Handhabung der Verzeichnisse durch TOXMgr
44*cdf0e10cSrcweir  --------------------------------------------------------------------*/
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir SwTOXMgr::SwTOXMgr(SwWrtShell* pShell):
48*cdf0e10cSrcweir 	pSh(pShell)
49*cdf0e10cSrcweir {
50*cdf0e10cSrcweir 	GetTOXMarks();
51*cdf0e10cSrcweir 	SetCurTOXMark(0);
52*cdf0e10cSrcweir }
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir /*--------------------------------------------------------------------
55*cdf0e10cSrcweir 	Beschreibung: Aktuelle TOXMarks behandeln
56*cdf0e10cSrcweir  --------------------------------------------------------------------*/
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir sal_uInt16 SwTOXMgr::GetTOXMarks()
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir 	return pSh->GetCurTOXMarks(aCurMarks);
62*cdf0e10cSrcweir }
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir SwTOXMark* SwTOXMgr::GetTOXMark(sal_uInt16 nId)
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir 	if(aCurMarks.Count() > 0)
68*cdf0e10cSrcweir 		return aCurMarks[nId];
69*cdf0e10cSrcweir 	return 0;
70*cdf0e10cSrcweir }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir void SwTOXMgr::DeleteTOXMark()
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir 	SwTOXMark* pNext = 0;
76*cdf0e10cSrcweir 	if( pCurTOXMark )
77*cdf0e10cSrcweir 	{
78*cdf0e10cSrcweir 		pNext = (SwTOXMark*)&pSh->GotoTOXMark( *pCurTOXMark, TOX_NXT );
79*cdf0e10cSrcweir 		if( pNext == pCurTOXMark )
80*cdf0e10cSrcweir 			pNext = 0;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 		pSh->DeleteTOXMark( pCurTOXMark );
83*cdf0e10cSrcweir 		pSh->SetModified();
84*cdf0e10cSrcweir 	}
85*cdf0e10cSrcweir 	// zur naechsten wandern
86*cdf0e10cSrcweir 	pCurTOXMark = pNext;
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir /* -----------------20.08.99 10:48-------------------
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir  --------------------------------------------------*/
91*cdf0e10cSrcweir void	SwTOXMgr::InsertTOXMark(const SwTOXMarkDescription& rDesc)
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir 	SwTOXMark* pMark = 0;
94*cdf0e10cSrcweir 	switch(rDesc.GetTOXType())
95*cdf0e10cSrcweir 	{
96*cdf0e10cSrcweir 		case  TOX_CONTENT:
97*cdf0e10cSrcweir 		{
98*cdf0e10cSrcweir 			ASSERT(rDesc.GetLevel() > 0 && rDesc.GetLevel() <= MAXLEVEL,
99*cdf0e10cSrcweir 											ungueltiger Level InsertTOCMark);
100*cdf0e10cSrcweir 			pMark = new SwTOXMark(pSh->GetTOXType(TOX_CONTENT, 0));
101*cdf0e10cSrcweir             pMark->SetLevel( static_cast< sal_uInt16 >(rDesc.GetLevel()) );
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 			if(rDesc.GetAltStr())
104*cdf0e10cSrcweir 				pMark->SetAlternativeText(*rDesc.GetAltStr());
105*cdf0e10cSrcweir 		}
106*cdf0e10cSrcweir 		break;
107*cdf0e10cSrcweir 		case  TOX_INDEX:
108*cdf0e10cSrcweir 		{
109*cdf0e10cSrcweir 			pMark = new SwTOXMark(pSh->GetTOXType(TOX_INDEX, 0));
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 			if( rDesc.GetPrimKey() && rDesc.GetPrimKey()->Len() )
112*cdf0e10cSrcweir 			{
113*cdf0e10cSrcweir 				pMark->SetPrimaryKey( *rDesc.GetPrimKey() );
114*cdf0e10cSrcweir 				if(rDesc.GetPhoneticReadingOfPrimKey())
115*cdf0e10cSrcweir 					pMark->SetPrimaryKeyReading( *rDesc.GetPhoneticReadingOfPrimKey() );
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 				if( rDesc.GetSecKey() && rDesc.GetSecKey()->Len() )
118*cdf0e10cSrcweir 				{
119*cdf0e10cSrcweir 					pMark->SetSecondaryKey( *rDesc.GetSecKey() );
120*cdf0e10cSrcweir 					if(rDesc.GetPhoneticReadingOfSecKey())
121*cdf0e10cSrcweir 						pMark->SetSecondaryKeyReading( *rDesc.GetPhoneticReadingOfSecKey() );
122*cdf0e10cSrcweir 				}
123*cdf0e10cSrcweir 			}
124*cdf0e10cSrcweir 			if(rDesc.GetAltStr())
125*cdf0e10cSrcweir 				pMark->SetAlternativeText(*rDesc.GetAltStr());
126*cdf0e10cSrcweir 			if(rDesc.GetPhoneticReadingOfAltStr())
127*cdf0e10cSrcweir 				pMark->SetTextReading( *rDesc.GetPhoneticReadingOfAltStr() );
128*cdf0e10cSrcweir 			pMark->SetMainEntry(rDesc.IsMainEntry());
129*cdf0e10cSrcweir 		}
130*cdf0e10cSrcweir 		break;
131*cdf0e10cSrcweir 		case  TOX_USER:
132*cdf0e10cSrcweir 		{
133*cdf0e10cSrcweir 			ASSERT(rDesc.GetLevel() > 0 && rDesc.GetLevel() <= MAXLEVEL,
134*cdf0e10cSrcweir 											ungueltiger Level InsertTOCMark);
135*cdf0e10cSrcweir 			sal_uInt16 nId = rDesc.GetTOUName() ?
136*cdf0e10cSrcweir 				GetUserTypeID(*rDesc.GetTOUName()) : 0;
137*cdf0e10cSrcweir 			pMark = new SwTOXMark(pSh->GetTOXType(TOX_USER, nId));
138*cdf0e10cSrcweir             pMark->SetLevel( static_cast< sal_uInt16 >(rDesc.GetLevel()) );
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 			if(rDesc.GetAltStr())
141*cdf0e10cSrcweir 				pMark->SetAlternativeText(*rDesc.GetAltStr());
142*cdf0e10cSrcweir 		}
143*cdf0e10cSrcweir 		break;
144*cdf0e10cSrcweir         default:; //prevent warning
145*cdf0e10cSrcweir 	}
146*cdf0e10cSrcweir 	pSh->StartAllAction();
147*cdf0e10cSrcweir 	pSh->SwEditShell::Insert(*pMark);
148*cdf0e10cSrcweir 	pSh->EndAllAction();
149*cdf0e10cSrcweir }
150*cdf0e10cSrcweir /*--------------------------------------------------------------------
151*cdf0e10cSrcweir 	Beschreibung: Update eines TOXMarks
152*cdf0e10cSrcweir  --------------------------------------------------------------------*/
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir void SwTOXMgr::UpdateTOXMark(const SwTOXMarkDescription& rDesc)
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir 	ASSERT(pCurTOXMark, "kein aktuelles TOXMark");
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 	pSh->StartAllAction();
160*cdf0e10cSrcweir 	if(pCurTOXMark->GetTOXType()->GetType() == TOX_INDEX)
161*cdf0e10cSrcweir 	{
162*cdf0e10cSrcweir 		if(rDesc.GetPrimKey() && rDesc.GetPrimKey()->Len() )
163*cdf0e10cSrcweir 		{
164*cdf0e10cSrcweir 			pCurTOXMark->SetPrimaryKey( *rDesc.GetPrimKey() );
165*cdf0e10cSrcweir 			if(rDesc.GetPhoneticReadingOfPrimKey())
166*cdf0e10cSrcweir 				pCurTOXMark->SetPrimaryKeyReading( *rDesc.GetPhoneticReadingOfPrimKey() );
167*cdf0e10cSrcweir 			else
168*cdf0e10cSrcweir 				pCurTOXMark->SetPrimaryKeyReading( aEmptyStr );
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 			if( rDesc.GetSecKey() && rDesc.GetSecKey()->Len() )
171*cdf0e10cSrcweir 			{
172*cdf0e10cSrcweir 				pCurTOXMark->SetSecondaryKey( *rDesc.GetSecKey() );
173*cdf0e10cSrcweir 				if(rDesc.GetPhoneticReadingOfSecKey())
174*cdf0e10cSrcweir 					pCurTOXMark->SetSecondaryKeyReading( *rDesc.GetPhoneticReadingOfSecKey() );
175*cdf0e10cSrcweir 				else
176*cdf0e10cSrcweir 					pCurTOXMark->SetSecondaryKeyReading( aEmptyStr );
177*cdf0e10cSrcweir 			}
178*cdf0e10cSrcweir 			else
179*cdf0e10cSrcweir 			{
180*cdf0e10cSrcweir 				pCurTOXMark->SetSecondaryKey( aEmptyStr );
181*cdf0e10cSrcweir 				pCurTOXMark->SetSecondaryKeyReading( aEmptyStr );
182*cdf0e10cSrcweir 			}
183*cdf0e10cSrcweir 		}
184*cdf0e10cSrcweir 		else
185*cdf0e10cSrcweir 		{
186*cdf0e10cSrcweir 			pCurTOXMark->SetPrimaryKey( aEmptyStr );
187*cdf0e10cSrcweir 			pCurTOXMark->SetPrimaryKeyReading( aEmptyStr );
188*cdf0e10cSrcweir 			pCurTOXMark->SetSecondaryKey( aEmptyStr );
189*cdf0e10cSrcweir 			pCurTOXMark->SetSecondaryKeyReading( aEmptyStr );
190*cdf0e10cSrcweir 		}
191*cdf0e10cSrcweir 		if(rDesc.GetPhoneticReadingOfAltStr())
192*cdf0e10cSrcweir 			pCurTOXMark->SetTextReading( *rDesc.GetPhoneticReadingOfAltStr() );
193*cdf0e10cSrcweir 		else
194*cdf0e10cSrcweir 			pCurTOXMark->SetTextReading( aEmptyStr );
195*cdf0e10cSrcweir 		pCurTOXMark->SetMainEntry(rDesc.IsMainEntry());
196*cdf0e10cSrcweir 	}
197*cdf0e10cSrcweir 	else
198*cdf0e10cSrcweir         pCurTOXMark->SetLevel( static_cast< sal_uInt16 >(rDesc.GetLevel()) );
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 	if(rDesc.GetAltStr())
201*cdf0e10cSrcweir 	{
202*cdf0e10cSrcweir 		// JP 26.08.96: Bug 30344 - entweder der Text aus dem Doc oder
203*cdf0e10cSrcweir 		//							ein Alternativ-Text, beides gibts nicht!
204*cdf0e10cSrcweir 		sal_Bool bReplace = pCurTOXMark->IsAlternativeText();
205*cdf0e10cSrcweir 		if( bReplace )
206*cdf0e10cSrcweir 			pCurTOXMark->SetAlternativeText( *rDesc.GetAltStr() );
207*cdf0e10cSrcweir 		else
208*cdf0e10cSrcweir 		{
209*cdf0e10cSrcweir 			SwTOXMark aCpy( *pCurTOXMark );
210*cdf0e10cSrcweir 			aCurMarks.Remove(0, aCurMarks.Count());
211*cdf0e10cSrcweir 			pSh->DeleteTOXMark(pCurTOXMark);
212*cdf0e10cSrcweir 			aCpy.SetAlternativeText( *rDesc.GetAltStr() );
213*cdf0e10cSrcweir 			pSh->SwEditShell::Insert( aCpy );
214*cdf0e10cSrcweir 			pCurTOXMark = 0;
215*cdf0e10cSrcweir 		}
216*cdf0e10cSrcweir 	}
217*cdf0e10cSrcweir 	pSh->SetModified();
218*cdf0e10cSrcweir 	pSh->EndAllAction();
219*cdf0e10cSrcweir 	// Bug 36207 pCurTOXMark zeigt hier in den Wald!
220*cdf0e10cSrcweir 	if(!pCurTOXMark)
221*cdf0e10cSrcweir 	{
222*cdf0e10cSrcweir 		pSh->Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
223*cdf0e10cSrcweir 		pSh->GetCurTOXMarks(aCurMarks);
224*cdf0e10cSrcweir 		SetCurTOXMark(0);
225*cdf0e10cSrcweir 	}
226*cdf0e10cSrcweir }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir /*--------------------------------------------------------------------
230*cdf0e10cSrcweir 	Beschreibung:	UserTypeID ermitteln
231*cdf0e10cSrcweir  --------------------------------------------------------------------*/
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir sal_uInt16 SwTOXMgr::GetUserTypeID(const String& rStr)
235*cdf0e10cSrcweir {
236*cdf0e10cSrcweir 	sal_uInt16 nSize = pSh->GetTOXTypeCount(TOX_USER);
237*cdf0e10cSrcweir 	for(sal_uInt16 i=0; i < nSize; ++i)
238*cdf0e10cSrcweir 	{
239*cdf0e10cSrcweir 		const SwTOXType* pTmp = pSh->GetTOXType(TOX_USER, i);
240*cdf0e10cSrcweir 		if(pTmp && pTmp->GetTypeName() == rStr)
241*cdf0e10cSrcweir 			return i;
242*cdf0e10cSrcweir 	}
243*cdf0e10cSrcweir 	SwTOXType aUserType(TOX_USER, rStr);
244*cdf0e10cSrcweir 	pSh->InsertTOXType(aUserType);
245*cdf0e10cSrcweir 	return nSize;
246*cdf0e10cSrcweir }
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir /*--------------------------------------------------------------------
249*cdf0e10cSrcweir 	Beschreibung: Traveling zwischen den TOXMarks
250*cdf0e10cSrcweir  --------------------------------------------------------------------*/
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir void SwTOXMgr::NextTOXMark(sal_Bool bSame)
254*cdf0e10cSrcweir {
255*cdf0e10cSrcweir 	ASSERT(pCurTOXMark, "kein aktuelles TOXMark");
256*cdf0e10cSrcweir 	if( pCurTOXMark )
257*cdf0e10cSrcweir 	{
258*cdf0e10cSrcweir 		SwTOXSearch eDir = bSame ? TOX_SAME_NXT : TOX_NXT;
259*cdf0e10cSrcweir 		pCurTOXMark = (SwTOXMark*)&pSh->GotoTOXMark( *pCurTOXMark, eDir );
260*cdf0e10cSrcweir 	}
261*cdf0e10cSrcweir }
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir void SwTOXMgr::PrevTOXMark(sal_Bool bSame)
265*cdf0e10cSrcweir {
266*cdf0e10cSrcweir 	ASSERT(pCurTOXMark, "kein aktuelles TOXMark");
267*cdf0e10cSrcweir 	if( pCurTOXMark )
268*cdf0e10cSrcweir 	{
269*cdf0e10cSrcweir 		SwTOXSearch eDir = bSame ? TOX_SAME_PRV : TOX_PRV;
270*cdf0e10cSrcweir 		pCurTOXMark = (SwTOXMark*)&pSh->GotoTOXMark(*pCurTOXMark, eDir );
271*cdf0e10cSrcweir 	}
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir /*--------------------------------------------------------------------
275*cdf0e10cSrcweir 	Beschreibung: Stichwortverzeichnis einfuegen
276*cdf0e10cSrcweir  --------------------------------------------------------------------*/
277*cdf0e10cSrcweir const SwTOXBase* SwTOXMgr::GetCurTOX()
278*cdf0e10cSrcweir {
279*cdf0e10cSrcweir 	return pSh->GetCurTOX();
280*cdf0e10cSrcweir }
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir const SwTOXType* SwTOXMgr::GetTOXType(TOXTypes eTyp, sal_uInt16 nId) const
283*cdf0e10cSrcweir {
284*cdf0e10cSrcweir 	return pSh->GetTOXType(eTyp, nId);
285*cdf0e10cSrcweir }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir void SwTOXMgr::SetCurTOXMark(sal_uInt16 nId)
288*cdf0e10cSrcweir {
289*cdf0e10cSrcweir 	pCurTOXMark = (nId < aCurMarks.Count()) ? aCurMarks[nId] : 0;
290*cdf0e10cSrcweir }
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir /* -----------------01.07.99 16:23-------------------
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir  --------------------------------------------------*/
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir sal_Bool SwTOXMgr::UpdateOrInsertTOX(const SwTOXDescription& rDesc,
297*cdf0e10cSrcweir 									SwTOXBase** ppBase,
298*cdf0e10cSrcweir 									const SfxItemSet* pSet)
299*cdf0e10cSrcweir {
300*cdf0e10cSrcweir 	SwWait aWait( *pSh->GetView().GetDocShell(), sal_True );
301*cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
302*cdf0e10cSrcweir 	const SwTOXBase* pCurTOX = ppBase && *ppBase ? *ppBase : GetCurTOX();
303*cdf0e10cSrcweir 	SwTOXBase* pTOX = (SwTOXBase*)pCurTOX;
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir     SwTOXBase * pNewTOX = NULL;
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir     if (pTOX)
308*cdf0e10cSrcweir         pNewTOX = new SwTOXBase(*pTOX);
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir 	TOXTypes eCurTOXType = rDesc.GetTOXType();
311*cdf0e10cSrcweir 	if(pCurTOX && !ppBase && pSh->HasSelection())
312*cdf0e10cSrcweir         pSh->EnterStdMode();
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir 	switch(eCurTOXType)
315*cdf0e10cSrcweir 	{
316*cdf0e10cSrcweir 		case TOX_INDEX :
317*cdf0e10cSrcweir 		{
318*cdf0e10cSrcweir 			if(!pCurTOX || (ppBase && !(*ppBase)))
319*cdf0e10cSrcweir 			{
320*cdf0e10cSrcweir 				const SwTOXType* pType = pSh->GetTOXType(eCurTOXType, 0);
321*cdf0e10cSrcweir 				SwForm aForm(eCurTOXType);
322*cdf0e10cSrcweir                 pNewTOX = new SwTOXBase(pType, aForm, nsSwTOXElement::TOX_MARK, pType->GetTypeName());
323*cdf0e10cSrcweir 			}
324*cdf0e10cSrcweir 			pNewTOX->SetOptions(rDesc.GetIndexOptions());
325*cdf0e10cSrcweir 			pNewTOX->SetMainEntryCharStyle(rDesc.GetMainEntryCharStyle());
326*cdf0e10cSrcweir 			pSh->SetTOIAutoMarkURL(rDesc.GetAutoMarkURL());
327*cdf0e10cSrcweir 			pSh->ApplyAutoMark();
328*cdf0e10cSrcweir 		}
329*cdf0e10cSrcweir 		break;
330*cdf0e10cSrcweir 		case TOX_CONTENT :
331*cdf0e10cSrcweir 		{
332*cdf0e10cSrcweir 			if(!pCurTOX || (ppBase && !(*ppBase)))
333*cdf0e10cSrcweir 			{
334*cdf0e10cSrcweir 				const SwTOXType* pType = pSh->GetTOXType(eCurTOXType, 0);
335*cdf0e10cSrcweir 				SwForm aForm(eCurTOXType);
336*cdf0e10cSrcweir 				pNewTOX = new SwTOXBase(pType, aForm, rDesc.GetContentOptions(), pType->GetTypeName());
337*cdf0e10cSrcweir 			}
338*cdf0e10cSrcweir 			pNewTOX->SetCreate(rDesc.GetContentOptions());
339*cdf0e10cSrcweir 			pNewTOX->SetLevel(rDesc.GetLevel());
340*cdf0e10cSrcweir 		}
341*cdf0e10cSrcweir 		break;
342*cdf0e10cSrcweir 		case TOX_USER :
343*cdf0e10cSrcweir 		{
344*cdf0e10cSrcweir 			if(!pCurTOX || (ppBase && !(*ppBase)))
345*cdf0e10cSrcweir 			{
346*cdf0e10cSrcweir 				sal_uInt16 nPos  = 0;
347*cdf0e10cSrcweir 				sal_uInt16 nSize = pSh->GetTOXTypeCount(eCurTOXType);
348*cdf0e10cSrcweir 				for(sal_uInt16 i=0; rDesc.GetTOUName() && i < nSize; ++i)
349*cdf0e10cSrcweir 				{	const SwTOXType* pType = pSh->GetTOXType(TOX_USER, i);
350*cdf0e10cSrcweir 					if(pType->GetTypeName() == *rDesc.GetTOUName())
351*cdf0e10cSrcweir 					{	nPos = i;
352*cdf0e10cSrcweir 						break;
353*cdf0e10cSrcweir 					}
354*cdf0e10cSrcweir 				}
355*cdf0e10cSrcweir 				const SwTOXType* pType = pSh->GetTOXType(eCurTOXType, nPos);
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir 				SwForm aForm(eCurTOXType);
358*cdf0e10cSrcweir 				pNewTOX = new SwTOXBase(pType, aForm, rDesc.GetContentOptions(), pType->GetTypeName());
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 			}
361*cdf0e10cSrcweir 			else
362*cdf0e10cSrcweir 			{
363*cdf0e10cSrcweir                 const_cast<SwTOXBase*>( pCurTOX )->SetCreate(rDesc.GetContentOptions());
364*cdf0e10cSrcweir 			}
365*cdf0e10cSrcweir 			pNewTOX->SetLevelFromChapter(rDesc.IsLevelFromChapter());
366*cdf0e10cSrcweir 		}
367*cdf0e10cSrcweir 		break;
368*cdf0e10cSrcweir 		case TOX_OBJECTS:
369*cdf0e10cSrcweir 		case TOX_TABLES:
370*cdf0e10cSrcweir 		case TOX_AUTHORITIES:
371*cdf0e10cSrcweir 		case TOX_ILLUSTRATIONS:
372*cdf0e10cSrcweir 		{
373*cdf0e10cSrcweir 			//Special handling for TOX_AUTHORITY
374*cdf0e10cSrcweir 			if(TOX_AUTHORITIES == eCurTOXType)
375*cdf0e10cSrcweir 			{
376*cdf0e10cSrcweir 				SwAuthorityFieldType* pFType = (SwAuthorityFieldType*)
377*cdf0e10cSrcweir 												pSh->GetFldType(RES_AUTHORITY, aEmptyStr);
378*cdf0e10cSrcweir                 if(!pFType)
379*cdf0e10cSrcweir                     pFType = (SwAuthorityFieldType*)pSh->InsertFldType(
380*cdf0e10cSrcweir                                     SwAuthorityFieldType(pSh->GetDoc()));
381*cdf0e10cSrcweir                 pFType->SetPreSuffix(rDesc.GetAuthBrackets().GetChar(0),
382*cdf0e10cSrcweir                     rDesc.GetAuthBrackets().GetChar(1));
383*cdf0e10cSrcweir                 pFType->SetSequence(rDesc.IsAuthSequence());
384*cdf0e10cSrcweir                 SwTOXSortKey rArr[3];
385*cdf0e10cSrcweir                 rArr[0] = rDesc.GetSortKey1();
386*cdf0e10cSrcweir                 rArr[1] = rDesc.GetSortKey2();
387*cdf0e10cSrcweir                 rArr[2] = rDesc.GetSortKey3();
388*cdf0e10cSrcweir                 pFType->SetSortKeys(3, rArr);
389*cdf0e10cSrcweir                 pFType->SetSortByDocument(rDesc.IsSortByDocument());
390*cdf0e10cSrcweir                 pFType->SetLanguage(rDesc.GetLanguage());
391*cdf0e10cSrcweir                 pFType->SetSortAlgorithm(rDesc.GetSortAlgorithm());
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir                 pFType->UpdateFlds();
394*cdf0e10cSrcweir 			}
395*cdf0e10cSrcweir 			// TODO: consider properties of the current TOXType
396*cdf0e10cSrcweir 			if(!pCurTOX || (ppBase && !(*ppBase)))
397*cdf0e10cSrcweir 			{
398*cdf0e10cSrcweir 				const SwTOXType* pType = pSh->GetTOXType(eCurTOXType, 0);
399*cdf0e10cSrcweir 				SwForm aForm(eCurTOXType);
400*cdf0e10cSrcweir 				pNewTOX = new SwTOXBase(
401*cdf0e10cSrcweir 					pType, aForm,
402*cdf0e10cSrcweir                     TOX_AUTHORITIES == eCurTOXType ? nsSwTOXElement::TOX_MARK : 0, pType->GetTypeName());
403*cdf0e10cSrcweir 			}
404*cdf0e10cSrcweir 			else
405*cdf0e10cSrcweir 			{
406*cdf0e10cSrcweir 				if((!ppBase || !(*ppBase)) && pSh->HasSelection())
407*cdf0e10cSrcweir 					pSh->DelRight();
408*cdf0e10cSrcweir 				pNewTOX = (SwTOXBase*)pCurTOX;
409*cdf0e10cSrcweir 			}
410*cdf0e10cSrcweir //			pTOX->SetOptions(rDesc.GetIndexOptions());
411*cdf0e10cSrcweir 			pNewTOX->SetFromObjectNames(rDesc.IsCreateFromObjectNames());
412*cdf0e10cSrcweir 			pNewTOX->SetOLEOptions(rDesc.GetOLEOptions());
413*cdf0e10cSrcweir 		}
414*cdf0e10cSrcweir 		break;
415*cdf0e10cSrcweir 	}
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir 	DBG_ASSERT(pNewTOX, "no TOXBase created!" );
419*cdf0e10cSrcweir 	if(!pNewTOX)
420*cdf0e10cSrcweir 		return sal_False;
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir 	pNewTOX->SetFromChapter(rDesc.IsFromChapter());
423*cdf0e10cSrcweir 	pNewTOX->SetSequenceName(rDesc.GetSequenceName());
424*cdf0e10cSrcweir 	pNewTOX->SetCaptionDisplay(rDesc.GetCaptionDisplay());
425*cdf0e10cSrcweir 	pNewTOX->SetProtected(rDesc.IsReadonly());
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir 	for(sal_uInt16 nLevel = 0; nLevel < MAXLEVEL; nLevel++)
428*cdf0e10cSrcweir 		pNewTOX->SetStyleNames(rDesc.GetStyleNames(nLevel), nLevel);
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir 	if(rDesc.GetTitle())
431*cdf0e10cSrcweir 		pNewTOX->SetTitle(*rDesc.GetTitle());
432*cdf0e10cSrcweir 	if(rDesc.GetForm())
433*cdf0e10cSrcweir 		pNewTOX->SetTOXForm(*rDesc.GetForm());
434*cdf0e10cSrcweir     pNewTOX->SetLanguage(rDesc.GetLanguage());
435*cdf0e10cSrcweir     pNewTOX->SetSortAlgorithm(rDesc.GetSortAlgorithm());
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir     if(!pCurTOX || (ppBase && !(*ppBase)) )
438*cdf0e10cSrcweir 	{
439*cdf0e10cSrcweir 		// wird ppBase uebergeben, dann wird das TOXBase hier nur erzeugt
440*cdf0e10cSrcweir 		// und dann ueber den Dialog in ein Globaldokument eingefuegt
441*cdf0e10cSrcweir 		if(ppBase)
442*cdf0e10cSrcweir 			(*ppBase) = pNewTOX;
443*cdf0e10cSrcweir 		else
444*cdf0e10cSrcweir 		{
445*cdf0e10cSrcweir 			pSh->InsertTableOf(*pNewTOX, pSet);
446*cdf0e10cSrcweir 			delete pNewTOX;
447*cdf0e10cSrcweir 		}
448*cdf0e10cSrcweir 	}
449*cdf0e10cSrcweir 	else
450*cdf0e10cSrcweir     {
451*cdf0e10cSrcweir         SwDoc * pDoc = pSh->GetDoc();
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir         if (pDoc->GetIDocumentUndoRedo().DoesUndo())
454*cdf0e10cSrcweir         {
455*cdf0e10cSrcweir             if (pNewTOX != NULL)
456*cdf0e10cSrcweir             {
457*cdf0e10cSrcweir                 pDoc->GetIDocumentUndoRedo().DelAllUndoObj();
458*cdf0e10cSrcweir             }
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir             pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_TOXCHANGE, NULL);
461*cdf0e10cSrcweir         }
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir         if (pNewTOX != NULL) // => pTOX != NULL
464*cdf0e10cSrcweir             pDoc->ChgTOX(*pTOX, *pNewTOX);
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir 		bRet = pSh->UpdateTableOf(*pTOX, pSet);
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir         if (pDoc->GetIDocumentUndoRedo().DoesUndo())
469*cdf0e10cSrcweir         {
470*cdf0e10cSrcweir             pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_TOXCHANGE, NULL);
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir             if (pNewTOX == NULL)
473*cdf0e10cSrcweir             {
474*cdf0e10cSrcweir                 pDoc->GetIDocumentUndoRedo().DelAllUndoObj();
475*cdf0e10cSrcweir             }
476*cdf0e10cSrcweir         }
477*cdf0e10cSrcweir     }
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir 	return bRet;
480*cdf0e10cSrcweir }
481*cdf0e10cSrcweir /* -----------------20.10.99 14:11-------------------
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir  --------------------------------------------------*/
484*cdf0e10cSrcweir void SwTOXDescription::SetSortKeys(SwTOXSortKey eKey1,
485*cdf0e10cSrcweir 						SwTOXSortKey eKey2,
486*cdf0e10cSrcweir 							SwTOXSortKey eKey3)
487*cdf0e10cSrcweir {
488*cdf0e10cSrcweir 	SwTOXSortKey aArr[3];
489*cdf0e10cSrcweir 	sal_uInt16 nPos = 0;
490*cdf0e10cSrcweir 	if(AUTH_FIELD_END > eKey1.eField)
491*cdf0e10cSrcweir 		aArr[nPos++] = eKey1;
492*cdf0e10cSrcweir 	if(AUTH_FIELD_END > eKey2.eField)
493*cdf0e10cSrcweir 		aArr[nPos++] = eKey2;
494*cdf0e10cSrcweir 	if(AUTH_FIELD_END > eKey3.eField)
495*cdf0e10cSrcweir 		aArr[nPos++] = eKey3;
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir 	eSortKey1 = aArr[0];
498*cdf0e10cSrcweir 	eSortKey2 = aArr[1];
499*cdf0e10cSrcweir 	eSortKey3 = aArr[2];
500*cdf0e10cSrcweir }
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir /* -----------------10.09.99 10:02-------------------
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir  --------------------------------------------------*/
505*cdf0e10cSrcweir void SwTOXDescription::ApplyTo(SwTOXBase& rTOXBase)
506*cdf0e10cSrcweir {
507*cdf0e10cSrcweir 	for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
508*cdf0e10cSrcweir 		rTOXBase.SetStyleNames(GetStyleNames(i), i);
509*cdf0e10cSrcweir 	rTOXBase.SetTitle(GetTitle() ? *GetTitle() : aEmptyStr);
510*cdf0e10cSrcweir 	rTOXBase.SetCreate(GetContentOptions());
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir 	if(GetTOXType() == TOX_INDEX)
513*cdf0e10cSrcweir 		rTOXBase.SetOptions(GetIndexOptions());
514*cdf0e10cSrcweir 	if(GetTOXType() != TOX_INDEX)
515*cdf0e10cSrcweir 		rTOXBase.SetLevel(GetLevel());
516*cdf0e10cSrcweir 	rTOXBase.SetFromObjectNames(IsCreateFromObjectNames());
517*cdf0e10cSrcweir 	rTOXBase.SetSequenceName(GetSequenceName());
518*cdf0e10cSrcweir 	rTOXBase.SetCaptionDisplay(GetCaptionDisplay());
519*cdf0e10cSrcweir 	rTOXBase.SetFromChapter(IsFromChapter());
520*cdf0e10cSrcweir 	rTOXBase.SetProtected(IsReadonly());
521*cdf0e10cSrcweir 	rTOXBase.SetOLEOptions(GetOLEOptions());
522*cdf0e10cSrcweir 	rTOXBase.SetLevelFromChapter(IsLevelFromChapter());
523*cdf0e10cSrcweir     rTOXBase.SetLanguage(eLanguage);
524*cdf0e10cSrcweir     rTOXBase.SetSortAlgorithm(sSortAlgorithm);
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir }
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir 
530