1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <wrtsh.hxx>
#include <swwait.hxx>
#include <view.hxx>
#include <toxmgr.hxx>
#include <doc.hxx>
#include <IDocumentUndoRedo.hxx>
#include <swundo.hxx>
// handle indexes with TOXMgr
SwTOXMgr::SwTOXMgr(SwWrtShell* pShell):
pSh(pShell)
{
pSh->GetCurTOXMarks(aCurMarks);
SetCurTOXMark(0);
}
SwTOXMark* SwTOXMgr::GetTOXMark(sal_uInt16 nId)
{
if(!aCurMarks.empty())
return aCurMarks[nId];
return nullptr;
}
void SwTOXMgr::DeleteTOXMark()
{
SwTOXMark* pNext = nullptr;
if( pCurTOXMark )
{
pNext = const_cast<SwTOXMark*>(&pSh->GotoTOXMark( *pCurTOXMark, TOX_NXT ));
if( pNext == pCurTOXMark )
pNext = nullptr;
pSh->DeleteTOXMark( pCurTOXMark );
pSh->SetModified();
}
// go to next one
pCurTOXMark = pNext;
}
void SwTOXMgr::InsertTOXMark(const SwTOXMarkDescription& rDesc)
{
SwTOXMark* pMark = nullptr;
switch(rDesc.GetTOXType())
{
case TOX_CONTENT:
{
OSL_ENSURE(rDesc.GetLevel() > 0 && rDesc.GetLevel() <= MAXLEVEL,
"invalid InsertTOCMark level");
pMark = new SwTOXMark(pSh->GetTOXType(TOX_CONTENT, 0));
pMark->SetLevel( static_cast< sal_uInt16 >(rDesc.GetLevel()) );
if(rDesc.GetAltStr())
pMark->SetAlternativeText(*rDesc.GetAltStr());
}
break;
case TOX_INDEX:
{
pMark = new SwTOXMark(pSh->GetTOXType(TOX_INDEX, 0));
if( rDesc.GetPrimKey() && !rDesc.GetPrimKey()->isEmpty() )
{
pMark->SetPrimaryKey( *rDesc.GetPrimKey() );
if(rDesc.GetPhoneticReadingOfPrimKey())
pMark->SetPrimaryKeyReading( *rDesc.GetPhoneticReadingOfPrimKey() );
if( rDesc.GetSecKey() && !rDesc.GetSecKey()->isEmpty() )
{
pMark->SetSecondaryKey( *rDesc.GetSecKey() );
if(rDesc.GetPhoneticReadingOfSecKey())
pMark->SetSecondaryKeyReading( *rDesc.GetPhoneticReadingOfSecKey() );
}
}
if(rDesc.GetAltStr())
pMark->SetAlternativeText(*rDesc.GetAltStr());
if(rDesc.GetPhoneticReadingOfAltStr())
pMark->SetTextReading( *rDesc.GetPhoneticReadingOfAltStr() );
pMark->SetMainEntry(rDesc.IsMainEntry());
}
break;
case TOX_USER:
{
OSL_ENSURE(rDesc.GetLevel() > 0 && rDesc.GetLevel() <= MAXLEVEL,
"invalid InsertTOCMark level");
sal_uInt16 nId = rDesc.GetTOUName() ?
GetUserTypeID(*rDesc.GetTOUName()) : 0;
pMark = new SwTOXMark(pSh->GetTOXType(TOX_USER, nId));
pMark->SetLevel( static_cast< sal_uInt16 >(rDesc.GetLevel()) );
if(rDesc.GetAltStr())
pMark->SetAlternativeText(*rDesc.GetAltStr());
}
break;
case TOX_BIBLIOGRAPHY:
{
pMark = new SwTOXMark(pSh->GetTOXType(TOX_BIBLIOGRAPHY, 0));
if( rDesc.GetPrimKey() && !rDesc.GetPrimKey()->isEmpty() )
{
pMark->SetPrimaryKey( *rDesc.GetPrimKey() );
if(rDesc.GetPhoneticReadingOfPrimKey())
pMark->SetPrimaryKeyReading( *rDesc.GetPhoneticReadingOfPrimKey() );
if( rDesc.GetSecKey() && !rDesc.GetSecKey()->isEmpty() )
{
pMark->SetSecondaryKey( *rDesc.GetSecKey() );
if(rDesc.GetPhoneticReadingOfSecKey())
pMark->SetSecondaryKeyReading( *rDesc.GetPhoneticReadingOfSecKey() );
}
}
if(rDesc.GetAltStr())
pMark->SetAlternativeText(*rDesc.GetAltStr());
if(rDesc.GetPhoneticReadingOfAltStr())
pMark->SetTextReading( *rDesc.GetPhoneticReadingOfAltStr() );
pMark->SetMainEntry(rDesc.IsMainEntry());
}
break;
default:; //prevent warning
}
if (!pMark)
return;
pSh->StartAllAction();
pSh->SwEditShell::Insert(*pMark);
pSh->EndAllAction();
}
// Update of TOXMarks
void SwTOXMgr::UpdateTOXMark(const SwTOXMarkDescription& rDesc)
{
assert(pCurTOXMark && "no current TOXMark");
pSh->StartAllAction();
if(pCurTOXMark->GetTOXType()->GetType() == TOX_INDEX)
{
if(rDesc.GetPrimKey() && !rDesc.GetPrimKey()->isEmpty() )
{
pCurTOXMark->SetPrimaryKey( *rDesc.GetPrimKey() );
if(rDesc.GetPhoneticReadingOfPrimKey())
pCurTOXMark->SetPrimaryKeyReading( *rDesc.GetPhoneticReadingOfPrimKey() );
else
pCurTOXMark->SetPrimaryKeyReading(OUString());
if( rDesc.GetSecKey() && !rDesc.GetSecKey()->isEmpty() )
{
pCurTOXMark->SetSecondaryKey( *rDesc.GetSecKey() );
if(rDesc.GetPhoneticReadingOfSecKey())
pCurTOXMark->SetSecondaryKeyReading( *rDesc.GetPhoneticReadingOfSecKey() );
else
pCurTOXMark->SetSecondaryKeyReading(OUString());
}
else
{
pCurTOXMark->SetSecondaryKey(OUString());
pCurTOXMark->SetSecondaryKeyReading(OUString());
}
}
else
{
pCurTOXMark->SetPrimaryKey(OUString());
pCurTOXMark->SetPrimaryKeyReading(OUString());
pCurTOXMark->SetSecondaryKey(OUString());
pCurTOXMark->SetSecondaryKeyReading(OUString());
}
if(rDesc.GetPhoneticReadingOfAltStr())
pCurTOXMark->SetTextReading( *rDesc.GetPhoneticReadingOfAltStr() );
else
pCurTOXMark->SetTextReading(OUString());
pCurTOXMark->SetMainEntry(rDesc.IsMainEntry());
}
else
pCurTOXMark->SetLevel( static_cast< sal_uInt16 >(rDesc.GetLevel()) );
if(rDesc.GetAltStr())
{
// JP 26.08.96: Bug 30344 - either the text of a Doc or an alternative test,
// not both!
bool bReplace = pCurTOXMark->IsAlternativeText();
if( bReplace )
pCurTOXMark->SetAlternativeText( *rDesc.GetAltStr() );
else
{
SwTOXMark aCpy( *pCurTOXMark );
aCurMarks.clear();
pSh->DeleteTOXMark(pCurTOXMark);
aCpy.SetAlternativeText( *rDesc.GetAltStr() );
pSh->SwEditShell::Insert( aCpy );
pCurTOXMark = nullptr;
}
}
pSh->SetModified();
pSh->EndAllAction();
// Bug 36207 pCurTOXMark points nowhere here!
if(!pCurTOXMark)
{
pSh->Left(CRSR_SKIP_CHARS, false, 1, false );
pSh->GetCurTOXMarks(aCurMarks);
SetCurTOXMark(0);
}
}
// determine UserTypeID
sal_uInt16 SwTOXMgr::GetUserTypeID(const OUString& rStr)
{
sal_uInt16 nSize = pSh->GetTOXTypeCount(TOX_USER);
for(sal_uInt16 i=0; i < nSize; ++i)
{
const SwTOXType* pTmp = pSh->GetTOXType(TOX_USER, i);
if(pTmp && pTmp->GetTypeName() == rStr)
return i;
}
SwTOXType aUserType(*pSh->GetDoc(), TOX_USER, rStr);
pSh->InsertTOXType(aUserType);
return nSize;
}
// traveling between TOXMarks
void SwTOXMgr::NextTOXMark(bool bSame)
{
OSL_ENSURE(pCurTOXMark, "no current TOXMark");
if( pCurTOXMark )
{
SwTOXSearch eDir = bSame ? TOX_SAME_NXT : TOX_NXT;
pCurTOXMark = const_cast<SwTOXMark*>(&pSh->GotoTOXMark( *pCurTOXMark, eDir ));
}
}
void SwTOXMgr::PrevTOXMark(bool bSame)
{
OSL_ENSURE(pCurTOXMark, "no current TOXMark");
if( pCurTOXMark )
{
SwTOXSearch eDir = bSame ? TOX_SAME_PRV : TOX_PRV;
pCurTOXMark = const_cast<SwTOXMark*>(&pSh->GotoTOXMark(*pCurTOXMark, eDir ));
}
}
const SwTOXType* SwTOXMgr::GetTOXType(TOXTypes eTyp) const
{
return pSh->GetTOXType(eTyp, 0);
}
void SwTOXMgr::SetCurTOXMark(sal_uInt16 nId)
{
pCurTOXMark = (nId < aCurMarks.size()) ? aCurMarks[nId] : nullptr;
}
bool SwTOXMgr::UpdateOrInsertTOX(const SwTOXDescription& rDesc,
SwTOXBase** ppBase,
const SfxItemSet* pSet)
{
SwWait aWait( *pSh->GetView().GetDocShell(), true );
bool bRet = true;
const SwTOXBase* pCurTOX = ppBase && *ppBase ? *ppBase : pSh->GetCurTOX();
SwTOXBase* pTOX = const_cast<SwTOXBase*>(pCurTOX);
SwTOXBase * pNewTOX = nullptr;
if (pTOX)
pNewTOX = new SwTOXBase(*pTOX);
TOXTypes eCurTOXType = rDesc.GetTOXType();
if(pCurTOX && !ppBase && pSh->HasSelection())
pSh->EnterStdMode();
switch(eCurTOXType)
{
case TOX_INDEX :
{
if(!pCurTOX || (ppBase && !(*ppBase)))
{
const SwTOXType* pType = pSh->GetTOXType(eCurTOXType, 0);
SwForm aForm(eCurTOXType);
pNewTOX = new SwTOXBase(pType, aForm, SwTOXElement::Mark, pType->GetTypeName());
}
pNewTOX->SetOptions(rDesc.GetIndexOptions());
pNewTOX->SetMainEntryCharStyle(rDesc.GetMainEntryCharStyle());
pSh->SetTOIAutoMarkURL(rDesc.GetAutoMarkURL());
pSh->ApplyAutoMark();
}
break;
case TOX_CONTENT :
{
if(!pCurTOX || (ppBase && !(*ppBase)))
{
const SwTOXType* pType = pSh->GetTOXType(eCurTOXType, 0);
SwForm aForm(eCurTOXType);
pNewTOX = new SwTOXBase(pType, aForm, rDesc.GetContentOptions(), pType->GetTypeName());
}
pNewTOX->SetCreate(rDesc.GetContentOptions());
pNewTOX->SetLevel(rDesc.GetLevel());
}
break;
case TOX_USER :
{
if(!pCurTOX || (ppBase && !(*ppBase)))
{
sal_uInt16 nPos = 0;
sal_uInt16 nSize = pSh->GetTOXTypeCount(eCurTOXType);
for(sal_uInt16 i=0; rDesc.GetTOUName() && i < nSize; ++i)
{ const SwTOXType* pType = pSh->GetTOXType(TOX_USER, i);
if(pType->GetTypeName() == *rDesc.GetTOUName())
{ nPos = i;
break;
}
}
const SwTOXType* pType = pSh->GetTOXType(eCurTOXType, nPos);
SwForm aForm(eCurTOXType);
pNewTOX = new SwTOXBase(pType, aForm, rDesc.GetContentOptions(), pType->GetTypeName());
}
else
{
const_cast<SwTOXBase*>( pCurTOX )->SetCreate(rDesc.GetContentOptions());
}
pNewTOX->SetLevelFromChapter(rDesc.IsLevelFromChapter());
}
break;
case TOX_CITATION: /** TODO */break;
case TOX_OBJECTS:
case TOX_TABLES:
case TOX_AUTHORITIES:
case TOX_BIBLIOGRAPHY:
case TOX_ILLUSTRATIONS:
{
//Special handling for TOX_AUTHORITY
if(TOX_AUTHORITIES == eCurTOXType)
{
SwAuthorityFieldType* pFType = static_cast<SwAuthorityFieldType*>(
pSh->GetFieldType(SwFieldIds::TableOfAuthorities, OUString()));
if (!pFType)
{
SwAuthorityFieldType const type(pSh->GetDoc());
pFType = static_cast<SwAuthorityFieldType*>(
pSh->InsertFieldType(type));
}
OUString const& rBrackets(rDesc.GetAuthBrackets());
if (rBrackets.isEmpty())
{
pFType->SetPreSuffix('\0', '\0');
}
else
{
assert(rBrackets.getLength() == 2);
pFType->SetPreSuffix(rBrackets[0], rBrackets[1]);
}
pFType->SetSequence(rDesc.IsAuthSequence());
SwTOXSortKey rArr[3];
rArr[0] = rDesc.GetSortKey1();
rArr[1] = rDesc.GetSortKey2();
rArr[2] = rDesc.GetSortKey3();
pFType->SetSortKeys(3, rArr);
pFType->SetSortByDocument(rDesc.IsSortByDocument());
pFType->SetLanguage(rDesc.GetLanguage());
pFType->SetSortAlgorithm(rDesc.GetSortAlgorithm());
pFType->UpdateFields();
}
// TODO: consider properties of the current TOXType
if(!pCurTOX || (ppBase && !(*ppBase)))
{
const SwTOXType* pType = pSh->GetTOXType(eCurTOXType, 0);
SwForm aForm(eCurTOXType);
pNewTOX = new SwTOXBase(
pType, aForm,
TOX_AUTHORITIES == eCurTOXType ? SwTOXElement::Mark : SwTOXElement::NONE,
pType->GetTypeName());
}
else
{
if((!ppBase || !(*ppBase)) && pSh->HasSelection())
pSh->DelRight();
pNewTOX = const_cast<SwTOXBase*>(pCurTOX);
}
pNewTOX->SetFromObjectNames(rDesc.IsCreateFromObjectNames());
pNewTOX->SetOLEOptions(rDesc.GetOLEOptions());
}
break;
}
OSL_ENSURE(pNewTOX, "no TOXBase created!" );
if(!pNewTOX)
return false;
pNewTOX->SetFromChapter(rDesc.IsFromChapter());
pNewTOX->SetSequenceName(rDesc.GetSequenceName());
pNewTOX->SetCaptionDisplay(rDesc.GetCaptionDisplay());
pNewTOX->SetProtected(rDesc.IsReadonly());
for(sal_uInt16 nLevel = 0; nLevel < MAXLEVEL; nLevel++)
pNewTOX->SetStyleNames(rDesc.GetStyleNames(nLevel), nLevel);
if(rDesc.GetTitle())
pNewTOX->SetTitle(*rDesc.GetTitle());
if(rDesc.GetForm())
pNewTOX->SetTOXForm(*rDesc.GetForm());
pNewTOX->SetLanguage(rDesc.GetLanguage());
pNewTOX->SetSortAlgorithm(rDesc.GetSortAlgorithm());
if(!pCurTOX || (ppBase && !(*ppBase)) )
{
// when ppBase is passed over, TOXBase is only created here
// and then inserted in a global document by the dialog
if(ppBase)
(*ppBase) = pNewTOX;
else
{
pSh->InsertTableOf(*pNewTOX, pSet);
delete pNewTOX;
}
}
else
{
SwDoc * pDoc = pSh->GetDoc();
if (pDoc->GetIDocumentUndoRedo().DoesUndo())
{
pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::TOXCHANGE, nullptr);
}
pDoc->ChangeTOX(*pTOX, *pNewTOX);
pTOX->DisableKeepExpression();
pSh->UpdateTableOf(*pTOX, pSet);
bRet = false;
pTOX->EnableKeepExpression();
if (pDoc->GetIDocumentUndoRedo().DoesUndo())
{
pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::TOXCHANGE, nullptr);
}
}
return bRet;
}
void SwTOXDescription::SetSortKeys(SwTOXSortKey eKey1,
SwTOXSortKey eKey2,
SwTOXSortKey eKey3)
{
SwTOXSortKey aArr[3];
sal_uInt16 nPos = 0;
if(AUTH_FIELD_END > eKey1.eField)
aArr[nPos++] = eKey1;
if(AUTH_FIELD_END > eKey2.eField)
aArr[nPos++] = eKey2;
if(AUTH_FIELD_END > eKey3.eField)
aArr[nPos++] = eKey3;
m_eSortKey1 = aArr[0];
m_eSortKey2 = aArr[1];
m_eSortKey3 = aArr[2];
}
void SwTOXDescription::ApplyTo(SwTOXBase& rTOXBase)
{
for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
rTOXBase.SetStyleNames(GetStyleNames(i), i);
rTOXBase.SetTitle(GetTitle() ? *GetTitle() : OUString());
rTOXBase.SetCreate(GetContentOptions());
if(GetTOXType() == TOX_INDEX)
rTOXBase.SetOptions(GetIndexOptions());
if(GetTOXType() != TOX_INDEX)
rTOXBase.SetLevel(GetLevel());
rTOXBase.SetFromObjectNames(IsCreateFromObjectNames());
rTOXBase.SetSequenceName(GetSequenceName());
rTOXBase.SetCaptionDisplay(GetCaptionDisplay());
rTOXBase.SetFromChapter(IsFromChapter());
rTOXBase.SetProtected(IsReadonly());
rTOXBase.SetOLEOptions(GetOLEOptions());
rTOXBase.SetLevelFromChapter(IsLevelFromChapter());
rTOXBase.SetLanguage(m_eLanguage);
rTOXBase.SetSortAlgorithm(m_sSortAlgorithm);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|