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