1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: toxmgr.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include <shellres.hxx>
38 #include <crsskip.hxx>
42 #include <globals.hrc>
45 /*--------------------------------------------------------------------
46 Beschreibung: Handhabung der Verzeichnisse durch TOXMgr
47 --------------------------------------------------------------------*/
50 SwTOXMgr::SwTOXMgr(SwWrtShell
* pShell
):
57 /*--------------------------------------------------------------------
58 Beschreibung: Aktuelle TOXMarks behandeln
59 --------------------------------------------------------------------*/
62 USHORT
SwTOXMgr::GetTOXMarks()
64 return pSh
->GetCurTOXMarks(aCurMarks
);
68 SwTOXMark
* SwTOXMgr::GetTOXMark(USHORT nId
)
70 if(aCurMarks
.Count() > 0)
71 return aCurMarks
[nId
];
76 void SwTOXMgr::DeleteTOXMark()
81 pNext
= (SwTOXMark
*)&pSh
->GotoTOXMark( *pCurTOXMark
, TOX_NXT
);
82 if( pNext
== pCurTOXMark
)
85 pSh
->DeleteTOXMark( pCurTOXMark
);
88 // zur naechsten wandern
91 /* -----------------20.08.99 10:48-------------------
93 --------------------------------------------------*/
94 void SwTOXMgr::InsertTOXMark(const SwTOXMarkDescription
& rDesc
)
97 switch(rDesc
.GetTOXType())
101 ASSERT(rDesc
.GetLevel() > 0 && rDesc
.GetLevel() <= MAXLEVEL
,
102 ungueltiger Level InsertTOCMark
);
103 pMark
= new SwTOXMark(pSh
->GetTOXType(TOX_CONTENT
, 0));
104 pMark
->SetLevel( static_cast< USHORT
>(rDesc
.GetLevel()) );
106 if(rDesc
.GetAltStr())
107 pMark
->SetAlternativeText(*rDesc
.GetAltStr());
112 pMark
= new SwTOXMark(pSh
->GetTOXType(TOX_INDEX
, 0));
114 if( rDesc
.GetPrimKey() && rDesc
.GetPrimKey()->Len() )
116 pMark
->SetPrimaryKey( *rDesc
.GetPrimKey() );
117 if(rDesc
.GetPhoneticReadingOfPrimKey())
118 pMark
->SetPrimaryKeyReading( *rDesc
.GetPhoneticReadingOfPrimKey() );
120 if( rDesc
.GetSecKey() && rDesc
.GetSecKey()->Len() )
122 pMark
->SetSecondaryKey( *rDesc
.GetSecKey() );
123 if(rDesc
.GetPhoneticReadingOfSecKey())
124 pMark
->SetSecondaryKeyReading( *rDesc
.GetPhoneticReadingOfSecKey() );
127 if(rDesc
.GetAltStr())
128 pMark
->SetAlternativeText(*rDesc
.GetAltStr());
129 if(rDesc
.GetPhoneticReadingOfAltStr())
130 pMark
->SetTextReading( *rDesc
.GetPhoneticReadingOfAltStr() );
131 pMark
->SetMainEntry(rDesc
.IsMainEntry());
136 ASSERT(rDesc
.GetLevel() > 0 && rDesc
.GetLevel() <= MAXLEVEL
,
137 ungueltiger Level InsertTOCMark
);
138 USHORT nId
= rDesc
.GetTOUName() ?
139 GetUserTypeID(*rDesc
.GetTOUName()) : 0;
140 pMark
= new SwTOXMark(pSh
->GetTOXType(TOX_USER
, nId
));
141 pMark
->SetLevel( static_cast< USHORT
>(rDesc
.GetLevel()) );
143 if(rDesc
.GetAltStr())
144 pMark
->SetAlternativeText(*rDesc
.GetAltStr());
147 default:; //prevent warning
149 pSh
->StartAllAction();
150 pSh
->SwEditShell::Insert(*pMark
);
153 /*--------------------------------------------------------------------
154 Beschreibung: Update eines TOXMarks
155 --------------------------------------------------------------------*/
158 void SwTOXMgr::UpdateTOXMark(const SwTOXMarkDescription
& rDesc
)
160 ASSERT(pCurTOXMark
, "kein aktuelles TOXMark");
162 pSh
->StartAllAction();
163 if(pCurTOXMark
->GetTOXType()->GetType() == TOX_INDEX
)
165 if(rDesc
.GetPrimKey() && rDesc
.GetPrimKey()->Len() )
167 pCurTOXMark
->SetPrimaryKey( *rDesc
.GetPrimKey() );
168 if(rDesc
.GetPhoneticReadingOfPrimKey())
169 pCurTOXMark
->SetPrimaryKeyReading( *rDesc
.GetPhoneticReadingOfPrimKey() );
171 pCurTOXMark
->SetPrimaryKeyReading( aEmptyStr
);
173 if( rDesc
.GetSecKey() && rDesc
.GetSecKey()->Len() )
175 pCurTOXMark
->SetSecondaryKey( *rDesc
.GetSecKey() );
176 if(rDesc
.GetPhoneticReadingOfSecKey())
177 pCurTOXMark
->SetSecondaryKeyReading( *rDesc
.GetPhoneticReadingOfSecKey() );
179 pCurTOXMark
->SetSecondaryKeyReading( aEmptyStr
);
183 pCurTOXMark
->SetSecondaryKey( aEmptyStr
);
184 pCurTOXMark
->SetSecondaryKeyReading( aEmptyStr
);
189 pCurTOXMark
->SetPrimaryKey( aEmptyStr
);
190 pCurTOXMark
->SetPrimaryKeyReading( aEmptyStr
);
191 pCurTOXMark
->SetSecondaryKey( aEmptyStr
);
192 pCurTOXMark
->SetSecondaryKeyReading( aEmptyStr
);
194 if(rDesc
.GetPhoneticReadingOfAltStr())
195 pCurTOXMark
->SetTextReading( *rDesc
.GetPhoneticReadingOfAltStr() );
197 pCurTOXMark
->SetTextReading( aEmptyStr
);
198 pCurTOXMark
->SetMainEntry(rDesc
.IsMainEntry());
201 pCurTOXMark
->SetLevel( static_cast< USHORT
>(rDesc
.GetLevel()) );
203 if(rDesc
.GetAltStr())
205 // JP 26.08.96: Bug 30344 - entweder der Text aus dem Doc oder
206 // ein Alternativ-Text, beides gibts nicht!
207 BOOL bReplace
= pCurTOXMark
->IsAlternativeText();
209 pCurTOXMark
->SetAlternativeText( *rDesc
.GetAltStr() );
212 SwTOXMark
aCpy( *pCurTOXMark
);
213 aCurMarks
.Remove(0, aCurMarks
.Count());
214 pSh
->DeleteTOXMark(pCurTOXMark
);
215 aCpy
.SetAlternativeText( *rDesc
.GetAltStr() );
216 pSh
->SwEditShell::Insert( aCpy
);
222 // Bug 36207 pCurTOXMark zeigt hier in den Wald!
225 pSh
->Left(CRSR_SKIP_CHARS
, FALSE
, 1, FALSE
);
226 pSh
->GetCurTOXMarks(aCurMarks
);
232 /*--------------------------------------------------------------------
233 Beschreibung: UserTypeID ermitteln
234 --------------------------------------------------------------------*/
237 USHORT
SwTOXMgr::GetUserTypeID(const String
& rStr
)
239 USHORT nSize
= pSh
->GetTOXTypeCount(TOX_USER
);
240 for(USHORT i
=0; i
< nSize
; ++i
)
242 const SwTOXType
* pTmp
= pSh
->GetTOXType(TOX_USER
, i
);
243 if(pTmp
&& pTmp
->GetTypeName() == rStr
)
246 SwTOXType
aUserType(TOX_USER
, rStr
);
247 pSh
->InsertTOXType(aUserType
);
251 /*--------------------------------------------------------------------
252 Beschreibung: Traveling zwischen den TOXMarks
253 --------------------------------------------------------------------*/
256 void SwTOXMgr::NextTOXMark(BOOL bSame
)
258 ASSERT(pCurTOXMark
, "kein aktuelles TOXMark");
261 SwTOXSearch eDir
= bSame
? TOX_SAME_NXT
: TOX_NXT
;
262 pCurTOXMark
= (SwTOXMark
*)&pSh
->GotoTOXMark( *pCurTOXMark
, eDir
);
267 void SwTOXMgr::PrevTOXMark(BOOL bSame
)
269 ASSERT(pCurTOXMark
, "kein aktuelles TOXMark");
272 SwTOXSearch eDir
= bSame
? TOX_SAME_PRV
: TOX_PRV
;
273 pCurTOXMark
= (SwTOXMark
*)&pSh
->GotoTOXMark(*pCurTOXMark
, eDir
);
277 /*--------------------------------------------------------------------
278 Beschreibung: Stichwortverzeichnis einfuegen
279 --------------------------------------------------------------------*/
280 const SwTOXBase
* SwTOXMgr::GetCurTOX()
282 return pSh
->GetCurTOX();
285 const SwTOXType
* SwTOXMgr::GetTOXType(TOXTypes eTyp
, USHORT nId
) const
287 return pSh
->GetTOXType(eTyp
, nId
);
290 void SwTOXMgr::SetCurTOXMark(USHORT nId
)
292 pCurTOXMark
= (nId
< aCurMarks
.Count()) ? aCurMarks
[nId
] : 0;
295 /* -----------------01.07.99 16:23-------------------
297 --------------------------------------------------*/
299 BOOL
SwTOXMgr::UpdateOrInsertTOX(const SwTOXDescription
& rDesc
,
301 const SfxItemSet
* pSet
)
303 SwWait
aWait( *pSh
->GetView().GetDocShell(), TRUE
);
305 const SwTOXBase
* pCurTOX
= ppBase
&& *ppBase
? *ppBase
: GetCurTOX();
306 SwTOXBase
* pTOX
= (SwTOXBase
*)pCurTOX
;
308 SwTOXBase
* pNewTOX
= NULL
;
311 pNewTOX
= new SwTOXBase(*pTOX
);
313 TOXTypes eCurTOXType
= rDesc
.GetTOXType();
314 if(pCurTOX
&& !ppBase
&& pSh
->HasSelection())
321 if(!pCurTOX
|| (ppBase
&& !(*ppBase
)))
323 const SwTOXType
* pType
= pSh
->GetTOXType(eCurTOXType
, 0);
324 SwForm
aForm(eCurTOXType
);
325 pNewTOX
= new SwTOXBase(pType
, aForm
, nsSwTOXElement::TOX_MARK
, pType
->GetTypeName());
327 pNewTOX
->SetOptions(rDesc
.GetIndexOptions());
328 pNewTOX
->SetMainEntryCharStyle(rDesc
.GetMainEntryCharStyle());
329 pSh
->SetTOIAutoMarkURL(rDesc
.GetAutoMarkURL());
330 pSh
->ApplyAutoMark();
335 if(!pCurTOX
|| (ppBase
&& !(*ppBase
)))
337 const SwTOXType
* pType
= pSh
->GetTOXType(eCurTOXType
, 0);
338 SwForm
aForm(eCurTOXType
);
339 pNewTOX
= new SwTOXBase(pType
, aForm
, rDesc
.GetContentOptions(), pType
->GetTypeName());
341 pNewTOX
->SetCreate(rDesc
.GetContentOptions());
342 pNewTOX
->SetLevel(rDesc
.GetLevel());
347 if(!pCurTOX
|| (ppBase
&& !(*ppBase
)))
350 USHORT nSize
= pSh
->GetTOXTypeCount(eCurTOXType
);
351 for(USHORT i
=0; rDesc
.GetTOUName() && i
< nSize
; ++i
)
352 { const SwTOXType
* pType
= pSh
->GetTOXType(TOX_USER
, i
);
353 if(pType
->GetTypeName() == *rDesc
.GetTOUName())
358 const SwTOXType
* pType
= pSh
->GetTOXType(eCurTOXType
, nPos
);
360 SwForm
aForm(eCurTOXType
);
361 pNewTOX
= new SwTOXBase(pType
, aForm
, rDesc
.GetContentOptions(), pType
->GetTypeName());
366 const_cast<SwTOXBase
*>( pCurTOX
)->SetCreate(rDesc
.GetContentOptions());
368 pNewTOX
->SetLevelFromChapter(rDesc
.IsLevelFromChapter());
373 case TOX_AUTHORITIES
:
374 case TOX_ILLUSTRATIONS
:
376 //Special handling for TOX_AUTHORITY
377 if(TOX_AUTHORITIES
== eCurTOXType
)
379 SwAuthorityFieldType
* pFType
= (SwAuthorityFieldType
*)
380 pSh
->GetFldType(RES_AUTHORITY
, aEmptyStr
);
382 pFType
= (SwAuthorityFieldType
*)pSh
->InsertFldType(
383 SwAuthorityFieldType(pSh
->GetDoc()));
384 pFType
->SetPreSuffix(rDesc
.GetAuthBrackets().GetChar(0),
385 rDesc
.GetAuthBrackets().GetChar(1));
386 pFType
->SetSequence(rDesc
.IsAuthSequence());
387 SwTOXSortKey rArr
[3];
388 rArr
[0] = rDesc
.GetSortKey1();
389 rArr
[1] = rDesc
.GetSortKey2();
390 rArr
[2] = rDesc
.GetSortKey3();
391 pFType
->SetSortKeys(3, rArr
);
392 pFType
->SetSortByDocument(rDesc
.IsSortByDocument());
393 pFType
->SetLanguage(rDesc
.GetLanguage());
394 pFType
->SetSortAlgorithm(rDesc
.GetSortAlgorithm());
396 pFType
->UpdateFlds();
398 // TODO: consider properties of the current TOXType
399 if(!pCurTOX
|| (ppBase
&& !(*ppBase
)))
401 const SwTOXType
* pType
= pSh
->GetTOXType(eCurTOXType
, 0);
402 SwForm
aForm(eCurTOXType
);
403 pNewTOX
= new SwTOXBase(
405 TOX_AUTHORITIES
== eCurTOXType
? nsSwTOXElement::TOX_MARK
: 0, pType
->GetTypeName());
409 if((!ppBase
|| !(*ppBase
)) && pSh
->HasSelection())
411 pNewTOX
= (SwTOXBase
*)pCurTOX
;
413 // pTOX->SetOptions(rDesc.GetIndexOptions());
414 pNewTOX
->SetFromObjectNames(rDesc
.IsCreateFromObjectNames());
415 pNewTOX
->SetOLEOptions(rDesc
.GetOLEOptions());
421 DBG_ASSERT(pNewTOX
, "no TOXBase created!" );
425 pNewTOX
->SetFromChapter(rDesc
.IsFromChapter());
426 pNewTOX
->SetSequenceName(rDesc
.GetSequenceName());
427 pNewTOX
->SetCaptionDisplay(rDesc
.GetCaptionDisplay());
428 pNewTOX
->SetProtected(rDesc
.IsReadonly());
430 for(USHORT nLevel
= 0; nLevel
< MAXLEVEL
; nLevel
++)
431 pNewTOX
->SetStyleNames(rDesc
.GetStyleNames(nLevel
), nLevel
);
434 pNewTOX
->SetTitle(*rDesc
.GetTitle());
436 pNewTOX
->SetTOXForm(*rDesc
.GetForm());
437 pNewTOX
->SetLanguage(rDesc
.GetLanguage());
438 pNewTOX
->SetSortAlgorithm(rDesc
.GetSortAlgorithm());
440 if(!pCurTOX
|| (ppBase
&& !(*ppBase
)) )
442 // wird ppBase uebergeben, dann wird das TOXBase hier nur erzeugt
443 // und dann ueber den Dialog in ein Globaldokument eingefuegt
448 pSh
->InsertTableOf(*pNewTOX
, pSet
);
454 SwDoc
* pDoc
= pSh
->GetDoc();
456 if (pDoc
->DoesUndo())
459 pDoc
->DelAllUndoObj();
461 pDoc
->StartUndo(UNDO_TOXCHANGE
, NULL
);
464 if (pNewTOX
!= NULL
) // => pTOX != NULL
465 pDoc
->ChgTOX(*pTOX
, *pNewTOX
);
467 bRet
= pSh
->UpdateTableOf(*pTOX
, pSet
);
469 if (pDoc
->DoesUndo())
471 pDoc
->EndUndo(UNDO_TOXCHANGE
, NULL
);
474 pDoc
->DelAllUndoObj();
480 /* -----------------20.10.99 14:11-------------------
482 --------------------------------------------------*/
483 void SwTOXDescription::SetSortKeys(SwTOXSortKey eKey1
,
487 SwTOXSortKey aArr
[3];
489 if(AUTH_FIELD_END
> eKey1
.eField
)
490 aArr
[nPos
++] = eKey1
;
491 if(AUTH_FIELD_END
> eKey2
.eField
)
492 aArr
[nPos
++] = eKey2
;
493 if(AUTH_FIELD_END
> eKey3
.eField
)
494 aArr
[nPos
++] = eKey3
;
501 /* -----------------10.09.99 10:02-------------------
503 --------------------------------------------------*/
504 void SwTOXDescription::ApplyTo(SwTOXBase
& rTOXBase
)
506 for(USHORT i
= 0; i
< MAXLEVEL
; i
++)
507 rTOXBase
.SetStyleNames(GetStyleNames(i
), i
);
508 rTOXBase
.SetTitle(GetTitle() ? *GetTitle() : aEmptyStr
);
509 rTOXBase
.SetCreate(GetContentOptions());
511 if(GetTOXType() == TOX_INDEX
)
512 rTOXBase
.SetOptions(GetIndexOptions());
513 if(GetTOXType() != TOX_INDEX
)
514 rTOXBase
.SetLevel(GetLevel());
515 rTOXBase
.SetFromObjectNames(IsCreateFromObjectNames());
516 rTOXBase
.SetSequenceName(GetSequenceName());
517 rTOXBase
.SetCaptionDisplay(GetCaptionDisplay());
518 rTOXBase
.SetFromChapter(IsFromChapter());
519 rTOXBase
.SetProtected(IsReadonly());
520 rTOXBase
.SetOLEOptions(GetOLEOptions());
521 rTOXBase
.SetLevelFromChapter(IsLevelFromChapter());
522 rTOXBase
.SetLanguage(eLanguage
);
523 rTOXBase
.SetSortAlgorithm(sSortAlgorithm
);