1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <shellres.hxx>
26 #include <crsskip.hxx>
28 #include <IDocumentUndoRedo.hxx>
30 #include <globals.hrc>
32 /*--------------------------------------------------------------------
33 Description: handle indexes with TOXMgr
34 --------------------------------------------------------------------*/
37 SwTOXMgr::SwTOXMgr(SwWrtShell
* pShell
):
44 /*--------------------------------------------------------------------
45 Description: handle current TOXMarks
46 --------------------------------------------------------------------*/
49 sal_uInt16
SwTOXMgr::GetTOXMarks()
51 return pSh
->GetCurTOXMarks(aCurMarks
);
55 SwTOXMark
* SwTOXMgr::GetTOXMark(sal_uInt16 nId
)
57 if(!aCurMarks
.empty())
58 return aCurMarks
[nId
];
63 void SwTOXMgr::DeleteTOXMark()
68 pNext
= (SwTOXMark
*)&pSh
->GotoTOXMark( *pCurTOXMark
, TOX_NXT
);
69 if( pNext
== pCurTOXMark
)
72 pSh
->DeleteTOXMark( pCurTOXMark
);
79 void SwTOXMgr::InsertTOXMark(const SwTOXMarkDescription
& rDesc
)
82 switch(rDesc
.GetTOXType())
86 OSL_ENSURE(rDesc
.GetLevel() > 0 && rDesc
.GetLevel() <= MAXLEVEL
,
87 "invalid InsertTOCMark level");
88 pMark
= new SwTOXMark(pSh
->GetTOXType(TOX_CONTENT
, 0));
89 pMark
->SetLevel( static_cast< sal_uInt16
>(rDesc
.GetLevel()) );
92 pMark
->SetAlternativeText(*rDesc
.GetAltStr());
97 pMark
= new SwTOXMark(pSh
->GetTOXType(TOX_INDEX
, 0));
99 if( rDesc
.GetPrimKey() && rDesc
.GetPrimKey()->Len() )
101 pMark
->SetPrimaryKey( *rDesc
.GetPrimKey() );
102 if(rDesc
.GetPhoneticReadingOfPrimKey())
103 pMark
->SetPrimaryKeyReading( *rDesc
.GetPhoneticReadingOfPrimKey() );
105 if( rDesc
.GetSecKey() && rDesc
.GetSecKey()->Len() )
107 pMark
->SetSecondaryKey( *rDesc
.GetSecKey() );
108 if(rDesc
.GetPhoneticReadingOfSecKey())
109 pMark
->SetSecondaryKeyReading( *rDesc
.GetPhoneticReadingOfSecKey() );
112 if(rDesc
.GetAltStr())
113 pMark
->SetAlternativeText(*rDesc
.GetAltStr());
114 if(rDesc
.GetPhoneticReadingOfAltStr())
115 pMark
->SetTextReading( *rDesc
.GetPhoneticReadingOfAltStr() );
116 pMark
->SetMainEntry(rDesc
.IsMainEntry());
121 OSL_ENSURE(rDesc
.GetLevel() > 0 && rDesc
.GetLevel() <= MAXLEVEL
,
122 "invalid InsertTOCMark level");
123 sal_uInt16 nId
= rDesc
.GetTOUName() ?
124 GetUserTypeID(*rDesc
.GetTOUName()) : 0;
125 pMark
= new SwTOXMark(pSh
->GetTOXType(TOX_USER
, nId
));
126 pMark
->SetLevel( static_cast< sal_uInt16
>(rDesc
.GetLevel()) );
128 if(rDesc
.GetAltStr())
129 pMark
->SetAlternativeText(*rDesc
.GetAltStr());
132 default:; //prevent warning
134 pSh
->StartAllAction();
135 pSh
->SwEditShell::Insert(*pMark
);
138 /*--------------------------------------------------------------------
139 Description: Update of TOXMarks
140 --------------------------------------------------------------------*/
143 void SwTOXMgr::UpdateTOXMark(const SwTOXMarkDescription
& rDesc
)
145 OSL_ENSURE(pCurTOXMark
, "no current TOXMark");
147 pSh
->StartAllAction();
148 if(pCurTOXMark
->GetTOXType()->GetType() == TOX_INDEX
)
150 if(rDesc
.GetPrimKey() && rDesc
.GetPrimKey()->Len() )
152 pCurTOXMark
->SetPrimaryKey( *rDesc
.GetPrimKey() );
153 if(rDesc
.GetPhoneticReadingOfPrimKey())
154 pCurTOXMark
->SetPrimaryKeyReading( *rDesc
.GetPhoneticReadingOfPrimKey() );
156 pCurTOXMark
->SetPrimaryKeyReading( aEmptyStr
);
158 if( rDesc
.GetSecKey() && rDesc
.GetSecKey()->Len() )
160 pCurTOXMark
->SetSecondaryKey( *rDesc
.GetSecKey() );
161 if(rDesc
.GetPhoneticReadingOfSecKey())
162 pCurTOXMark
->SetSecondaryKeyReading( *rDesc
.GetPhoneticReadingOfSecKey() );
164 pCurTOXMark
->SetSecondaryKeyReading( aEmptyStr
);
168 pCurTOXMark
->SetSecondaryKey( aEmptyStr
);
169 pCurTOXMark
->SetSecondaryKeyReading( aEmptyStr
);
174 pCurTOXMark
->SetPrimaryKey( aEmptyStr
);
175 pCurTOXMark
->SetPrimaryKeyReading( aEmptyStr
);
176 pCurTOXMark
->SetSecondaryKey( aEmptyStr
);
177 pCurTOXMark
->SetSecondaryKeyReading( aEmptyStr
);
179 if(rDesc
.GetPhoneticReadingOfAltStr())
180 pCurTOXMark
->SetTextReading( *rDesc
.GetPhoneticReadingOfAltStr() );
182 pCurTOXMark
->SetTextReading( aEmptyStr
);
183 pCurTOXMark
->SetMainEntry(rDesc
.IsMainEntry());
186 pCurTOXMark
->SetLevel( static_cast< sal_uInt16
>(rDesc
.GetLevel()) );
188 if(rDesc
.GetAltStr())
190 // JP 26.08.96: Bug 30344 - either the text of a Doc or an alternative test,
192 sal_Bool bReplace
= pCurTOXMark
->IsAlternativeText();
194 pCurTOXMark
->SetAlternativeText( *rDesc
.GetAltStr() );
197 SwTOXMark
aCpy( *pCurTOXMark
);
199 pSh
->DeleteTOXMark(pCurTOXMark
);
200 aCpy
.SetAlternativeText( *rDesc
.GetAltStr() );
201 pSh
->SwEditShell::Insert( aCpy
);
207 // Bug 36207 pCurTOXMark points nowhere here!
210 pSh
->Left(CRSR_SKIP_CHARS
, sal_False
, 1, sal_False
);
211 pSh
->GetCurTOXMarks(aCurMarks
);
217 /*--------------------------------------------------------------------
218 Description: determine UserTypeID
219 --------------------------------------------------------------------*/
222 sal_uInt16
SwTOXMgr::GetUserTypeID(const String
& rStr
)
224 sal_uInt16 nSize
= pSh
->GetTOXTypeCount(TOX_USER
);
225 for(sal_uInt16 i
=0; i
< nSize
; ++i
)
227 const SwTOXType
* pTmp
= pSh
->GetTOXType(TOX_USER
, i
);
228 if(pTmp
&& pTmp
->GetTypeName() == rStr
)
231 SwTOXType
aUserType(TOX_USER
, rStr
);
232 pSh
->InsertTOXType(aUserType
);
236 /*--------------------------------------------------------------------
237 Description: traveling between TOXMarks
238 --------------------------------------------------------------------*/
241 void SwTOXMgr::NextTOXMark(sal_Bool bSame
)
243 OSL_ENSURE(pCurTOXMark
, "no current TOXMark");
246 SwTOXSearch eDir
= bSame
? TOX_SAME_NXT
: TOX_NXT
;
247 pCurTOXMark
= (SwTOXMark
*)&pSh
->GotoTOXMark( *pCurTOXMark
, eDir
);
252 void SwTOXMgr::PrevTOXMark(sal_Bool bSame
)
254 OSL_ENSURE(pCurTOXMark
, "no current TOXMark");
257 SwTOXSearch eDir
= bSame
? TOX_SAME_PRV
: TOX_PRV
;
258 pCurTOXMark
= (SwTOXMark
*)&pSh
->GotoTOXMark(*pCurTOXMark
, eDir
);
262 /*--------------------------------------------------------------------
263 Description: insert keyword index
264 --------------------------------------------------------------------*/
265 const SwTOXBase
* SwTOXMgr::GetCurTOX()
267 return pSh
->GetCurTOX();
270 const SwTOXType
* SwTOXMgr::GetTOXType(TOXTypes eTyp
, sal_uInt16 nId
) const
272 return pSh
->GetTOXType(eTyp
, nId
);
275 void SwTOXMgr::SetCurTOXMark(sal_uInt16 nId
)
277 pCurTOXMark
= (nId
< aCurMarks
.size()) ? aCurMarks
[nId
] : 0;
280 sal_Bool
SwTOXMgr::UpdateOrInsertTOX(const SwTOXDescription
& rDesc
,
282 const SfxItemSet
* pSet
)
284 SwWait
aWait( *pSh
->GetView().GetDocShell(), sal_True
);
285 sal_Bool bRet
= sal_True
;
286 const SwTOXBase
* pCurTOX
= ppBase
&& *ppBase
? *ppBase
: GetCurTOX();
287 SwTOXBase
* pTOX
= (SwTOXBase
*)pCurTOX
;
289 SwTOXBase
* pNewTOX
= NULL
;
292 pNewTOX
= new SwTOXBase(*pTOX
);
294 TOXTypes eCurTOXType
= rDesc
.GetTOXType();
295 if(pCurTOX
&& !ppBase
&& pSh
->HasSelection())
302 if(!pCurTOX
|| (ppBase
&& !(*ppBase
)))
304 const SwTOXType
* pType
= pSh
->GetTOXType(eCurTOXType
, 0);
305 SwForm
aForm(eCurTOXType
);
306 pNewTOX
= new SwTOXBase(pType
, aForm
, nsSwTOXElement::TOX_MARK
, pType
->GetTypeName());
308 pNewTOX
->SetOptions(rDesc
.GetIndexOptions());
309 pNewTOX
->SetMainEntryCharStyle(rDesc
.GetMainEntryCharStyle());
310 pSh
->SetTOIAutoMarkURL(rDesc
.GetAutoMarkURL());
311 pSh
->ApplyAutoMark();
316 if(!pCurTOX
|| (ppBase
&& !(*ppBase
)))
318 const SwTOXType
* pType
= pSh
->GetTOXType(eCurTOXType
, 0);
319 SwForm
aForm(eCurTOXType
);
320 pNewTOX
= new SwTOXBase(pType
, aForm
, rDesc
.GetContentOptions(), pType
->GetTypeName());
322 pNewTOX
->SetCreate(rDesc
.GetContentOptions());
323 pNewTOX
->SetLevel(rDesc
.GetLevel());
328 if(!pCurTOX
|| (ppBase
&& !(*ppBase
)))
331 sal_uInt16 nSize
= pSh
->GetTOXTypeCount(eCurTOXType
);
332 for(sal_uInt16 i
=0; rDesc
.GetTOUName() && i
< nSize
; ++i
)
333 { const SwTOXType
* pType
= pSh
->GetTOXType(TOX_USER
, i
);
334 if(pType
->GetTypeName() == *rDesc
.GetTOUName())
339 const SwTOXType
* pType
= pSh
->GetTOXType(eCurTOXType
, nPos
);
341 SwForm
aForm(eCurTOXType
);
342 pNewTOX
= new SwTOXBase(pType
, aForm
, rDesc
.GetContentOptions(), pType
->GetTypeName());
347 const_cast<SwTOXBase
*>( pCurTOX
)->SetCreate(rDesc
.GetContentOptions());
349 pNewTOX
->SetLevelFromChapter(rDesc
.IsLevelFromChapter());
354 case TOX_AUTHORITIES
:
355 case TOX_ILLUSTRATIONS
:
357 //Special handling for TOX_AUTHORITY
358 if(TOX_AUTHORITIES
== eCurTOXType
)
360 SwAuthorityFieldType
* pFType
= (SwAuthorityFieldType
*)
361 pSh
->GetFldType(RES_AUTHORITY
, aEmptyStr
);
364 SwAuthorityFieldType
const type(pSh
->GetDoc());
365 pFType
= static_cast<SwAuthorityFieldType
*>(
366 pSh
->InsertFldType(type
));
368 pFType
->SetPreSuffix(rDesc
.GetAuthBrackets().GetChar(0),
369 rDesc
.GetAuthBrackets().GetChar(1));
370 pFType
->SetSequence(rDesc
.IsAuthSequence());
371 SwTOXSortKey rArr
[3];
372 rArr
[0] = rDesc
.GetSortKey1();
373 rArr
[1] = rDesc
.GetSortKey2();
374 rArr
[2] = rDesc
.GetSortKey3();
375 pFType
->SetSortKeys(3, rArr
);
376 pFType
->SetSortByDocument(rDesc
.IsSortByDocument());
377 pFType
->SetLanguage(rDesc
.GetLanguage());
378 pFType
->SetSortAlgorithm(rDesc
.GetSortAlgorithm());
380 pFType
->UpdateFlds();
382 // TODO: consider properties of the current TOXType
383 if(!pCurTOX
|| (ppBase
&& !(*ppBase
)))
385 const SwTOXType
* pType
= pSh
->GetTOXType(eCurTOXType
, 0);
386 SwForm
aForm(eCurTOXType
);
387 pNewTOX
= new SwTOXBase(
389 TOX_AUTHORITIES
== eCurTOXType
? nsSwTOXElement::TOX_MARK
: 0, pType
->GetTypeName());
393 if((!ppBase
|| !(*ppBase
)) && pSh
->HasSelection())
395 pNewTOX
= (SwTOXBase
*)pCurTOX
;
397 pNewTOX
->SetFromObjectNames(rDesc
.IsCreateFromObjectNames());
398 pNewTOX
->SetOLEOptions(rDesc
.GetOLEOptions());
404 OSL_ENSURE(pNewTOX
, "no TOXBase created!" );
408 pNewTOX
->SetFromChapter(rDesc
.IsFromChapter());
409 pNewTOX
->SetSequenceName(rDesc
.GetSequenceName());
410 pNewTOX
->SetCaptionDisplay(rDesc
.GetCaptionDisplay());
411 pNewTOX
->SetProtected(rDesc
.IsReadonly());
413 for(sal_uInt16 nLevel
= 0; nLevel
< MAXLEVEL
; nLevel
++)
414 pNewTOX
->SetStyleNames(rDesc
.GetStyleNames(nLevel
), nLevel
);
417 pNewTOX
->SetTitle(*rDesc
.GetTitle());
419 pNewTOX
->SetTOXForm(*rDesc
.GetForm());
420 pNewTOX
->SetLanguage(rDesc
.GetLanguage());
421 pNewTOX
->SetSortAlgorithm(rDesc
.GetSortAlgorithm());
423 if(!pCurTOX
|| (ppBase
&& !(*ppBase
)) )
425 // when ppBase is passed over, TOXBase is only created here
426 // and then inserted in a global document by the dialog
431 pSh
->InsertTableOf(*pNewTOX
, pSet
);
437 SwDoc
* pDoc
= pSh
->GetDoc();
439 if (pDoc
->GetIDocumentUndoRedo().DoesUndo())
443 pDoc
->GetIDocumentUndoRedo().DelAllUndoObj();
446 pDoc
->GetIDocumentUndoRedo().StartUndo(UNDO_TOXCHANGE
, NULL
);
449 if (pNewTOX
!= NULL
) // => pTOX != NULL
450 pDoc
->ChgTOX(*pTOX
, *pNewTOX
);
452 bRet
= pSh
->UpdateTableOf(*pTOX
, pSet
);
454 if (pDoc
->GetIDocumentUndoRedo().DoesUndo())
456 pDoc
->GetIDocumentUndoRedo().EndUndo(UNDO_TOXCHANGE
, NULL
);
460 pDoc
->GetIDocumentUndoRedo().DelAllUndoObj();
468 void SwTOXDescription::SetSortKeys(SwTOXSortKey eKey1
,
472 SwTOXSortKey aArr
[3];
474 if(AUTH_FIELD_END
> eKey1
.eField
)
475 aArr
[nPos
++] = eKey1
;
476 if(AUTH_FIELD_END
> eKey2
.eField
)
477 aArr
[nPos
++] = eKey2
;
478 if(AUTH_FIELD_END
> eKey3
.eField
)
479 aArr
[nPos
++] = eKey3
;
486 void SwTOXDescription::ApplyTo(SwTOXBase
& rTOXBase
)
488 for(sal_uInt16 i
= 0; i
< MAXLEVEL
; i
++)
489 rTOXBase
.SetStyleNames(GetStyleNames(i
), i
);
490 rTOXBase
.SetTitle(GetTitle() ? *GetTitle() : aEmptyStr
);
491 rTOXBase
.SetCreate(GetContentOptions());
493 if(GetTOXType() == TOX_INDEX
)
494 rTOXBase
.SetOptions(GetIndexOptions());
495 if(GetTOXType() != TOX_INDEX
)
496 rTOXBase
.SetLevel(GetLevel());
497 rTOXBase
.SetFromObjectNames(IsCreateFromObjectNames());
498 rTOXBase
.SetSequenceName(GetSequenceName());
499 rTOXBase
.SetCaptionDisplay(GetCaptionDisplay());
500 rTOXBase
.SetFromChapter(IsFromChapter());
501 rTOXBase
.SetProtected(IsReadonly());
502 rTOXBase
.SetOLEOptions(GetOLEOptions());
503 rTOXBase
.SetLevelFromChapter(IsLevelFromChapter());
504 rTOXBase
.SetLanguage(eLanguage
);
505 rTOXBase
.SetSortAlgorithm(sSortAlgorithm
);
511 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */