Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/source/uibase/app/docstyle.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#include <memory>
21
#include <sal/config.h>
22
#include <sal/log.hxx>
23
#include <osl/diagnose.h>
24
25
#include <cstdlib>
26
27
#include <hintids.hxx>
28
#include <rtl/ustrbuf.hxx>
29
#include <svl/itemiter.hxx>
30
#include <svl/eitem.hxx>
31
#include <unotools/syslocale.hxx>
32
#include <editeng/boxitem.hxx>
33
#include <editeng/numitem.hxx>
34
#include <editeng/lrspitem.hxx>
35
#include <drawdoc.hxx>
36
#include <fmtcol.hxx>
37
#include <uitool.hxx>
38
#include <wrtsh.hxx>
39
#include <docsh.hxx>
40
#include <frmfmt.hxx>
41
#include <charfmt.hxx>
42
#include <charformats.hxx>
43
#include <tblafmt.hxx>
44
#include <poolfmt.hxx>
45
#include <pagedesc.hxx>
46
#include <docstyle.hxx>
47
#include <docary.hxx>
48
#include <ccoll.hxx>
49
#include <doc.hxx>
50
#include <IDocumentUndoRedo.hxx>
51
#include <IDocumentStylePoolAccess.hxx>
52
#include <IDocumentSettingAccess.hxx>
53
#include <IDocumentDrawModelAccess.hxx>
54
#include <IDocumentState.hxx>
55
#include <cmdid.h>
56
#include <strings.hrc>
57
#include <paratr.hxx>
58
#include <SwStyleNameMapper.hxx>
59
#include <svl/cjkoptions.hxx>
60
#include <svl/ctloptions.hxx>
61
#include <unotools/intlwrapper.hxx>
62
#include <numrule.hxx>
63
#include <svx/xdef.hxx>
64
#include <SwRewriter.hxx>
65
#include <hints.hxx>
66
#include <frameformats.hxx>
67
#include <editeng/brushitem.hxx>
68
#include <editeng/colritem.hxx>
69
#include <editeng/eeitem.hxx>
70
#include <svx/xfillit0.hxx>
71
#include <svx/xflftrit.hxx>
72
#include <svx/drawitem.hxx>
73
#include <svx/strarray.hxx>
74
#include <names.hxx>
75
76
using namespace com::sun::star;
77
78
// At the names' publication, this character is removed again and the
79
// family is newly generated.
80
81
// In addition now there is the Bit bPhysical. In case this Bit is
82
// TRUE, the Pool-Formatnames are not being submitted.
83
84
namespace {
85
86
class EEStyleSheet : public SfxStyleSheet
87
{
88
public:
89
    using SfxStyleSheet::SfxStyleSheet;
90
    bool IsUsed() const override
91
0
    {
92
0
        bool bResult = false;
93
0
        ForAllListeners(
94
0
            [&bResult] (SfxListener* pListener)
95
0
            {
96
0
                auto pUser(dynamic_cast<svl::StyleSheetUser*>(pListener));
97
0
                bResult = pUser && pUser->isUsedByModel();
98
0
                return bResult;
99
0
            });
100
0
        return bResult;
101
0
    }
102
    void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override
103
42
    {
104
42
        if (rHint.GetId() == SfxHintId::DataChanged)
105
0
            Broadcast(rHint);
106
42
        else
107
42
            SfxStyleSheet::Notify(rBC, rHint);
108
42
    }
109
    bool SetParent(const OUString& rName) override
110
63
    {
111
63
        if (SfxStyleSheet::SetParent(rName))
112
63
        {
113
63
            auto pStyle = m_pPool->Find(rName, nFamily);
114
63
            pSet->SetParent(pStyle ? &pStyle->GetItemSet() : nullptr);
115
63
            return true;
116
63
        }
117
0
        return false;
118
63
    }
119
};
120
121
class EEStyleSheetPool : public SfxStyleSheetPool, public SfxListener
122
{
123
    SfxStyleSheetBasePool* m_pOwner;
124
125
public:
126
    explicit EEStyleSheetPool(SfxStyleSheetBasePool* pOwner)
127
80.9k
        : SfxStyleSheetPool(pOwner->GetPool())
128
80.9k
        , m_pOwner(pOwner)
129
80.9k
    {
130
80.9k
        StartListening(*m_pOwner);
131
80.9k
    }
132
133
    using SfxStyleSheetPool::Create;
134
    rtl::Reference<SfxStyleSheetBase> Create(const OUString& rName, SfxStyleFamily eFamily,
135
                                             SfxStyleSearchBits nMask,
136
                                             const OUString& rParentStyleSheetName) override
137
84
    {
138
84
        return new EEStyleSheet(rName, *this, eFamily, nMask, rParentStyleSheetName);
139
84
    }
140
141
    void Notify(SfxBroadcaster&, const SfxHint& rHint) override
142
380k
    {
143
380k
        auto nId = rHint.GetId();
144
380k
        if (nId != SfxHintId::StyleSheetModified && nId != SfxHintId::StyleSheetModifiedExtended
145
0
            && nId != SfxHintId::StyleSheetErased)
146
0
            return;
147
380k
        auto pHint = static_cast<const SfxStyleSheetHint*>(&rHint);
148
149
380k
        auto pDocStyleSheet = pHint->GetStyleSheet();
150
380k
        const SfxStyleSheetModifiedHint* pExtendedHint = nullptr;
151
380k
        if (nId == SfxHintId::StyleSheetModifiedExtended)
152
0
            pExtendedHint = static_cast<const SfxStyleSheetModifiedHint*>(&rHint);
153
380k
        const OUString aName = pExtendedHint ? pExtendedHint->GetOldName() : pDocStyleSheet->GetName();
154
380k
        auto pStyleSheet = SfxStyleSheetPool::Find(aName, pDocStyleSheet->GetFamily());
155
380k
        if (!pStyleSheet)
156
380k
            return;
157
158
0
        if (nId == SfxHintId::StyleSheetModified || nId == SfxHintId::StyleSheetModifiedExtended)
159
0
        {
160
0
            pStyleSheet->SetName(pDocStyleSheet->GetName());
161
0
            UpdateStyleHierarchyFrom(pStyleSheet, pDocStyleSheet);
162
0
            static_cast<SfxStyleSheet*>(pStyleSheet)->Broadcast(SfxHint(SfxHintId::DataChanged));
163
0
        }
164
0
        else if (nId == SfxHintId::StyleSheetErased)
165
0
            Remove(pStyleSheet);
166
0
    }
167
168
    SfxStyleSheetBase* Find(const OUString& rName, SfxStyleFamily eFamily,
169
                            SfxStyleSearchBits = SfxStyleSearchBits::All) override
170
463
    {
171
463
        auto pStyleSheet = SfxStyleSheetPool::Find(rName, eFamily);
172
173
463
        if (auto pDocStyleSheet = pStyleSheet ? nullptr : m_pOwner->Find(rName, eFamily))
174
84
        {
175
84
            pStyleSheet = &Make(pDocStyleSheet->GetName(), pDocStyleSheet->GetFamily());
176
84
            UpdateStyleHierarchyFrom(pStyleSheet, pDocStyleSheet);
177
84
        }
178
179
463
        return pStyleSheet;
180
463
    }
181
182
    void UpdateStyleHierarchyFrom(SfxStyleSheetBase* pStyleSheet, SfxStyleSheetBase* pDocStyleSheet)
183
84
    {
184
84
        FillItemSet(pStyleSheet, pDocStyleSheet);
185
186
        // Remember now, as the next calls will invalidate pDocStyleSheet.
187
84
        const OUString aParent = pDocStyleSheet->GetParent();
188
84
        const OUString aFollow = pDocStyleSheet->GetFollow();
189
190
84
        if (pStyleSheet->GetParent() != aParent)
191
63
            pStyleSheet->SetParent(aParent);
192
193
84
        if (pStyleSheet->GetFollow() != aFollow)
194
42
            pStyleSheet->SetFollow(aFollow);
195
84
    }
196
197
    void FillItemSet(SfxStyleSheetBase* pDestSheet, SfxStyleSheetBase* pSourceSheet)
198
84
    {
199
84
        auto& rItemSet = pDestSheet->GetItemSet();
200
84
        rItemSet.ClearItem();
201
202
84
        auto pCol = static_cast<SwDocStyleSheet*>(pSourceSheet)->GetCollection();
203
84
        std::optional<SvxLRSpaceItem> oLRSpaceItem;
204
205
483
        for (SfxItemIter aIter(pCol->GetAttrSet()); !aIter.IsAtEnd(); aIter.Next())
206
399
        {
207
399
            const SfxPoolItem* pItem = aIter.GetCurItem();
208
399
            if (aIter.GetItemState(false) != SfxItemState::SET)
209
0
                continue;
210
211
399
            auto nWhich = pItem->Which();
212
399
            auto nSlotId = rPool.GetSlotId(nWhich);
213
399
            auto nNewWhich = rPool.GetSecondaryPool()->GetWhichIDFromSlotID(nSlotId);
214
399
            if (nNewWhich != nSlotId)
215
336
                rItemSet.Put(pItem->CloneSetWhich(nNewWhich));
216
63
            else if (nWhich == RES_MARGIN_FIRSTLINE)
217
0
            {
218
0
                if (!oLRSpaceItem)
219
0
                    oLRSpaceItem.emplace(EE_PARA_LRSPACE);
220
0
                auto pFirstLineItem = static_cast<const SvxFirstLineIndentItem*>(pItem);
221
0
                (*oLRSpaceItem).SetTextFirstLineOffset(pFirstLineItem->GetTextFirstLineOffset());
222
0
                (*oLRSpaceItem).SetAutoFirst(pFirstLineItem->IsAutoFirst());
223
0
            }
224
63
            else if (nWhich == RES_MARGIN_TEXTLEFT)
225
0
            {
226
0
                if (!oLRSpaceItem)
227
0
                    oLRSpaceItem.emplace(EE_PARA_LRSPACE);
228
0
                (*oLRSpaceItem)
229
0
                    .SetTextLeft(static_cast<const SvxTextLeftMarginItem*>(pItem)->GetTextLeft());
230
0
            }
231
63
            else if (nWhich == RES_MARGIN_RIGHT)
232
0
            {
233
0
                if (!oLRSpaceItem)
234
0
                    oLRSpaceItem.emplace(EE_PARA_LRSPACE);
235
0
                (*oLRSpaceItem).SetRight(static_cast<const SvxRightMarginItem*>(pItem)->GetRight());
236
0
            }
237
63
            else if (nWhich == RES_CHRATR_BACKGROUND)
238
0
            {
239
0
                auto pBrushItem = static_cast<const SvxBrushItem*>(pItem);
240
0
                rItemSet.Put(SvxColorItem(pBrushItem->GetColor(), EE_CHAR_BKGCOLOR));
241
0
            }
242
399
        }
243
84
        if (oLRSpaceItem)
244
0
            rItemSet.Put(*oLRSpaceItem);
245
84
    }
246
};
247
248
class SwImplShellAction
249
{
250
    SwWrtShell* m_pSh;
251
    std::unique_ptr<CurrShell> m_pCurrSh;
252
public:
253
    explicit SwImplShellAction( SwDoc& rDoc );
254
    ~SwImplShellAction() COVERITY_NOEXCEPT_FALSE;
255
    SwImplShellAction(const SwImplShellAction&) = delete;
256
    SwImplShellAction& operator=(const SwImplShellAction&) = delete;
257
};
258
259
}
260
261
SwImplShellAction::SwImplShellAction( SwDoc& rDoc )
262
590k
{
263
590k
    if( rDoc.GetDocShell() )
264
590k
        m_pSh = rDoc.GetDocShell()->GetWrtShell();
265
0
    else
266
0
        m_pSh = nullptr;
267
268
590k
    if( m_pSh )
269
0
    {
270
0
        m_pCurrSh.reset( new CurrShell( m_pSh ) );
271
0
        m_pSh->StartAllAction();
272
0
    }
273
590k
}
274
275
SwImplShellAction::~SwImplShellAction() COVERITY_NOEXCEPT_FALSE
276
590k
{
277
590k
    if( m_pCurrSh )
278
0
    {
279
0
        m_pSh->EndAllAction();
280
0
        m_pCurrSh.reset();
281
0
    }
282
590k
}
283
284
// find/create SwCharFormate
285
// possibly fill Style
286
static SwCharFormat* lcl_FindCharFormat( SwDoc& rDoc,
287
                            const UIName& rName,
288
                            SwDocStyleSheet* pStyle = nullptr,
289
                            bool bCreate = true )
290
265k
{
291
265k
    SwCharFormat*  pFormat = nullptr;
292
265k
    if (!rName.isEmpty())
293
265k
    {
294
265k
        pFormat = rDoc.FindCharFormatByName( rName );
295
265k
        if( !pFormat && rName == SwResId(STR_POOLCHR_STANDARD))
296
564
        {
297
            // Standard-Character template
298
564
            pFormat = rDoc.GetDfltCharFormat();
299
564
        }
300
301
265k
        if( !pFormat && bCreate )
302
45.6k
        {   // explore Pool
303
45.6k
            const SwPoolFormatId nId = SwStyleNameMapper::GetPoolIdFromUIName(rName, SwGetPoolIdFromName::ChrFmt);
304
45.6k
            if(nId != SwPoolFormatId::UNKNOWN)
305
4.33k
                pFormat = rDoc.getIDocumentStylePoolAccess().GetCharFormatFromPool(nId);
306
45.6k
        }
307
265k
    }
308
265k
    if(pStyle)
309
218k
    {
310
218k
        if(pFormat)
311
111k
        {
312
111k
            pStyle->SetPhysical(true);
313
111k
            SwFormat* p = pFormat->DerivedFrom();
314
111k
            if( p && !p->IsDefault() )
315
12.3k
                pStyle->PresetParent( p->GetName().toString() );
316
99.3k
            else
317
99.3k
                pStyle->PresetParent( OUString() );
318
111k
        }
319
106k
        else
320
106k
            pStyle->SetPhysical(false);
321
218k
    }
322
265k
    return pFormat;
323
265k
}
324
325
// find/create ParaFormats
326
// fill Style
327
static SwTextFormatColl* lcl_FindParaFormat(  SwDoc& rDoc,
328
                                const UIName& rName,
329
                                SwDocStyleSheet* pStyle = nullptr,
330
                                bool bCreate = true )
331
2.17M
{
332
2.17M
    SwTextFormatColl*   pColl = nullptr;
333
334
2.17M
    if (!rName.isEmpty())
335
2.14M
    {
336
2.14M
        pColl = rDoc.FindTextFormatCollByName( rName );
337
2.14M
        if( !pColl && bCreate )
338
41.9k
        {   // explore Pool
339
41.9k
            const SwPoolFormatId nId = SwStyleNameMapper::GetPoolIdFromUIName(rName, SwGetPoolIdFromName::TxtColl);
340
41.9k
            if(nId != SwPoolFormatId::UNKNOWN)
341
15.4k
                pColl = rDoc.getIDocumentStylePoolAccess().GetTextCollFromPool(nId);
342
41.9k
        }
343
2.14M
    }
344
345
2.17M
    if(pStyle)
346
2.10M
    {
347
2.10M
        if(pColl)
348
1.91M
        {
349
1.91M
            pStyle->SetPhysical(true);
350
1.91M
            if( pColl->DerivedFrom() && !pColl->DerivedFrom()->IsDefault() )
351
1.40M
                pStyle->PresetParent( pColl->DerivedFrom()->GetName().toString() );
352
511k
            else
353
511k
                pStyle->PresetParent( OUString() );
354
355
1.91M
            SwTextFormatColl& rNext = pColl->GetNextTextFormatColl();
356
1.91M
            pStyle->PresetFollow(rNext.GetName().toString());
357
1.91M
        }
358
185k
        else
359
185k
            pStyle->SetPhysical(false);
360
2.10M
    }
361
2.17M
    return pColl;
362
2.17M
}
363
364
// Border formats
365
static SwFrameFormat* lcl_FindFrameFormat(   SwDoc& rDoc,
366
                            const UIName& rName,
367
                            SwDocStyleSheet* pStyle = nullptr,
368
                            bool bCreate = true )
369
270k
{
370
270k
    SwFrameFormat* pFormat = nullptr;
371
270k
    if( !rName.isEmpty() )
372
270k
    {
373
270k
        pFormat = rDoc.FindFrameFormatByName( rName );
374
270k
        if( !pFormat && bCreate )
375
4.74k
        {   // explore Pool
376
4.74k
            const SwPoolFormatId nId = SwStyleNameMapper::GetPoolIdFromUIName(rName, SwGetPoolIdFromName::FrmFmt);
377
4.74k
            if(nId != SwPoolFormatId::UNKNOWN)
378
4.56k
                pFormat = rDoc.getIDocumentStylePoolAccess().GetFrameFormatFromPool(nId);
379
4.74k
        }
380
270k
    }
381
382
270k
    if(pStyle)
383
269k
    {
384
269k
        if(pFormat)
385
214k
        {
386
214k
            pStyle->SetPhysical(true);
387
214k
            if( pFormat->DerivedFrom() && !pFormat->DerivedFrom()->IsDefault() )
388
0
                pStyle->PresetParent( pFormat->DerivedFrom()->GetName().toString() );
389
214k
            else
390
214k
                pStyle->PresetParent( OUString() );
391
214k
        }
392
55.0k
        else
393
55.0k
            pStyle->SetPhysical(false);
394
269k
    }
395
270k
    return pFormat;
396
270k
}
397
398
// Page descriptors
399
static const SwPageDesc* lcl_FindPageDesc( SwDoc&  rDoc,
400
                                    const UIName& rName,
401
                                    SwDocStyleSheet* pStyle = nullptr,
402
                                    bool bCreate = true )
403
435k
{
404
435k
    const SwPageDesc* pDesc = nullptr;
405
406
435k
    if (!rName.isEmpty())
407
435k
    {
408
435k
        pDesc = rDoc.FindPageDesc(rName);
409
435k
        if( !pDesc && bCreate )
410
4.76k
        {
411
4.76k
            SwPoolFormatId nId = SwStyleNameMapper::GetPoolIdFromUIName(rName, SwGetPoolIdFromName::PageDesc);
412
4.76k
            if(nId != SwPoolFormatId::UNKNOWN)
413
1.63k
                pDesc = rDoc.getIDocumentStylePoolAccess().GetPageDescFromPool(nId);
414
4.76k
        }
415
435k
    }
416
417
435k
    if(pStyle)
418
432k
    {
419
432k
        if(pDesc)
420
418k
        {
421
418k
            pStyle->SetPhysical(true);
422
418k
            if(pDesc->GetFollow())
423
418k
                pStyle->PresetFollow(pDesc->GetFollow()->GetName().toString());
424
0
            else
425
0
                pStyle->PresetParent( OUString() );
426
418k
        }
427
13.6k
        else
428
13.6k
            pStyle->SetPhysical(false);
429
432k
    }
430
435k
    return pDesc;
431
435k
}
432
433
static const SwNumRule* lcl_FindNumRule(   SwDoc&  rDoc,
434
                                    const UIName& rName,
435
                                    SwDocStyleSheet* pStyle = nullptr,
436
                                    bool bCreate = true )
437
36.8k
{
438
36.8k
    const SwNumRule* pRule = nullptr;
439
440
36.8k
    if (!rName.isEmpty())
441
36.8k
    {
442
36.8k
        pRule = rDoc.FindNumRulePtr( rName );
443
36.8k
        if( !pRule && bCreate )
444
4.53k
        {
445
4.53k
            SwPoolFormatId nId = SwStyleNameMapper::GetPoolIdFromUIName(rName, SwGetPoolIdFromName::NumRule);
446
4.53k
            if(nId != SwPoolFormatId::UNKNOWN)
447
685
                pRule = rDoc.getIDocumentStylePoolAccess().GetNumRuleFromPool(nId);
448
4.53k
        }
449
36.8k
    }
450
451
36.8k
    if(pStyle)
452
33.0k
    {
453
33.0k
        if(pRule)
454
19.7k
        {
455
19.7k
            pStyle->SetPhysical(true);
456
19.7k
            pStyle->PresetParent( OUString() );
457
19.7k
        }
458
13.2k
        else
459
13.2k
            pStyle->SetPhysical(false);
460
33.0k
    }
461
36.8k
    return pRule;
462
36.8k
}
463
464
static SwTableAutoFormat* lcl_FindTableStyle(SwDoc& rDoc, const TableStyleName& rName, SwDocStyleSheet *pStyle = nullptr, bool bCreate = true)
465
0
{
466
0
    SwTableAutoFormat* pFormat = nullptr;
467
468
0
    if (!rName.isEmpty())
469
0
    {
470
0
        pFormat = rDoc.GetTableStyles().FindAutoFormat(rName);
471
0
        if (!pFormat && bCreate)
472
0
        {
473
0
            SwTableAutoFormat aNew(rName);
474
0
            rDoc.GetTableStyles().AddAutoFormat(aNew);
475
0
        }
476
0
    }
477
478
0
    if(pStyle)
479
0
    {
480
0
        if(pFormat)
481
0
        {
482
0
            pStyle->SetPhysical(true);
483
0
            pStyle->PresetParent(OUString());
484
0
        }
485
0
        else
486
0
            pStyle->SetPhysical(false);
487
0
    }
488
0
    return pFormat;
489
0
}
490
491
static const SwBoxAutoFormat* lcl_FindCellStyle(SwDoc& rDoc, const UIName& rName, SwDocStyleSheet *pStyle)
492
10.3k
{
493
10.3k
    const SwBoxAutoFormat* pFormat = rDoc.GetCellStyles().GetBoxFormat(rName);
494
495
10.3k
    if (!pFormat)
496
3.36k
    {
497
3.36k
        SwTableAutoFormatTable& rTableStyles = rDoc.GetTableStyles();
498
6.73k
        for (size_t i=0; i < rTableStyles.size() && !pFormat; ++i)
499
3.36k
        {
500
3.36k
            const SwTableAutoFormat& rTableStyle = rTableStyles[i];
501
57.2k
            for (size_t j = 0; j < ELEMENT_COUNT && !pFormat; ++j)
502
53.8k
            {
503
53.8k
                const SwBoxAutoFormat& rBoxFormat = *rTableStyle.GetField(j);
504
53.8k
                ProgName sBoxFormatName;
505
53.8k
                SwStyleNameMapper::FillProgName(UIName(rTableStyle.GetName().toString()),
506
53.8k
                                                sBoxFormatName, SwGetPoolIdFromName::TableStyle);
507
53.8k
                OUString sTmp = sBoxFormatName.toString() + "." + OUString::number(j + 1);
508
53.8k
                if (rName == sTmp)
509
0
                    pFormat = &rBoxFormat;
510
53.8k
            }
511
3.36k
        }
512
3.36k
    }
513
514
10.3k
    if(pStyle)
515
10.3k
    {
516
10.3k
        if(pFormat)
517
6.95k
        {
518
6.95k
            pStyle->SetPhysical(true);
519
6.95k
            pStyle->PresetParent(OUString());
520
6.95k
        }
521
3.36k
        else
522
3.36k
            pStyle->SetPhysical(false);
523
10.3k
    }
524
10.3k
    return pFormat;
525
10.3k
}
526
527
sal_uInt32 SwStyleSheetIterator::SwPoolFormatList::FindName(SfxStyleFamily eFam,
528
                                                         const UIName& rName)
529
0
{
530
0
    if(!maImpl.empty())
531
0
    {
532
0
        UniqueHash::const_iterator it = maUnique.find(std::pair<SfxStyleFamily,UIName>{eFam, rName});
533
0
        if (it != maUnique.end())
534
0
        {
535
0
            sal_uInt32 nIdx = it->second;
536
0
            assert (nIdx < maImpl.size());
537
0
            assert (maImpl.size() == maUnique.size());
538
0
            return nIdx;
539
0
        }
540
0
    }
541
0
    return SAL_MAX_UINT32;
542
0
}
543
544
void SwStyleSheetIterator::SwPoolFormatList::rehash()
545
0
{
546
0
    maUnique.clear();
547
0
    for (size_t i = 0; i < maImpl.size(); i++)
548
0
        maUnique[maImpl[i]] = i;
549
0
    assert (maImpl.size() == maUnique.size());
550
0
}
551
552
void SwStyleSheetIterator::SwPoolFormatList::RemoveName(SfxStyleFamily eFam,
553
                                                     const UIName& rName)
554
0
{
555
0
    sal_uInt32 nTmpPos = FindName( eFam, rName );
556
0
    if (nTmpPos != SAL_MAX_UINT32)
557
0
        maImpl.erase(maImpl.begin() + nTmpPos);
558
559
    // assumption: this seldom occurs, the iterator is built, then emptied.
560
0
    rehash();
561
0
    assert (maImpl.size() == maUnique.size());
562
0
}
563
564
// Add Strings to the list of templates
565
void SwStyleSheetIterator::SwPoolFormatList::Append( SfxStyleFamily eFam, const UIName& rStr )
566
35.6k
{
567
35.6k
    UniqueHash::const_iterator it = maUnique.find(std::pair<SfxStyleFamily,UIName>{eFam, rStr});
568
35.6k
    if (it != maUnique.end())
569
934
        return;
570
571
34.7k
    maUnique.emplace(std::pair<SfxStyleFamily,UIName>{eFam, rStr}, static_cast<sal_uInt32>(maImpl.size()));
572
34.7k
    maImpl.push_back(std::pair<SfxStyleFamily,UIName>{eFam, rStr});
573
34.7k
}
574
575
// UI-sided implementation of StyleSheets
576
// uses the Core-Engine
577
SwDocStyleSheet::SwDocStyleSheet(   SwDoc&                rDocument,
578
                                    SwDocStyleSheetPool&  rPool) :
579
580
83.8k
    SfxStyleSheetBase( OUString(), &rPool, SfxStyleFamily::Char, SfxStyleSearchBits::Auto, u""_ustr ),
581
83.8k
    m_pCharFormat(nullptr),
582
83.8k
    m_pColl(nullptr),
583
83.8k
    m_pFrameFormat(nullptr),
584
83.8k
    m_pDesc(nullptr),
585
83.8k
    m_pNumRule(nullptr),
586
83.8k
    m_pTableFormat(nullptr),
587
83.8k
    m_pBoxFormat(nullptr),
588
83.8k
    m_rDoc(rDocument),
589
83.8k
    m_aCoreSet(
590
83.8k
        rPool.GetPool(),
591
83.8k
        svl::Items<
592
83.8k
            RES_CHRATR_BEGIN, RES_CHRATR_END - 1,
593
83.8k
            RES_PARATR_BEGIN, RES_FRMATR_END - 1,
594
83.8k
            RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END - 1,
595
            // FillAttribute support:
596
83.8k
            XATTR_FILL_FIRST, XATTR_FILL_LAST,
597
83.8k
            SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
598
83.8k
            SID_ATTR_PAGE, SID_ATTR_PAGE_EXT1,
599
83.8k
            SID_ATTR_PAGE_HEADERSET, SID_ATTR_PAGE_FOOTERSET,
600
83.8k
            SID_ATTR_PARA_MODEL, SID_ATTR_PARA_MODEL,
601
            // Items to hand over XPropertyList things like XColorList,
602
            // XHatchList, XGradientList, and XBitmapList to the Area TabPage:
603
83.8k
            SID_COLOR_TABLE, SID_PATTERN_LIST,
604
83.8k
            SID_SWREGISTER_COLLECTION, SID_SWREGISTER_COLLECTION,
605
83.8k
            SID_ATTR_PARA_PAGENUM, SID_ATTR_PARA_PAGENUM,
606
83.8k
            SID_SWREGISTER_MODE, SID_SWREGISTER_MODE,
607
83.8k
            SID_ATTR_BRUSH_CHAR, SID_ATTR_BRUSH_CHAR,
608
83.8k
            SID_ATTR_NUMBERING_RULE, SID_ATTR_NUMBERING_RULE,
609
83.8k
            SID_ATTR_CHAR_GRABBAG, SID_ATTR_CHAR_GRABBAG,
610
83.8k
            SID_ATTR_AUTO_STYLE_UPDATE, SID_ATTR_AUTO_STYLE_UPDATE,
611
83.8k
            FN_PARAM_FTN_INFO, FN_PARAM_FTN_INFO,
612
83.8k
            FN_KEEP_ASPECT_RATIO, FN_KEEP_ASPECT_RATIO,
613
83.8k
            FN_COND_COLL, FN_COND_COLL>),
614
83.8k
    m_bPhysical(false)
615
83.8k
{
616
83.8k
    nHelpId = UCHAR_MAX;
617
83.8k
}
618
619
1.23M
SwDocStyleSheet::SwDocStyleSheet( const SwDocStyleSheet& ) = default;
620
621
1.32M
SwDocStyleSheet::~SwDocStyleSheet() = default;
622
623
void  SwDocStyleSheet::Reset()
624
1.45k
{
625
1.45k
    aName.clear();
626
1.45k
    aFollow.clear();
627
1.45k
    aParent.clear();
628
1.45k
    SetPhysical(false);
629
1.45k
}
630
631
void SwDocStyleSheet::SetGrabBagItem(const uno::Any& rVal)
632
15.5k
{
633
15.5k
    bool bChg = false;
634
15.5k
    if (!m_bPhysical)
635
0
        FillStyleSheet(FillPhysical);
636
637
15.5k
    SwFormat* pFormat = nullptr;
638
15.5k
    switch (nFamily)
639
15.5k
    {
640
6.86k
        case SfxStyleFamily::Char:
641
6.86k
            pFormat = m_rDoc.FindCharFormatByName(UIName(aName));
642
6.86k
            if (pFormat)
643
6.85k
            {
644
6.85k
                pFormat->SetGrabBagItem(rVal);
645
6.85k
                bChg = true;
646
6.85k
            }
647
6.86k
            break;
648
8.20k
        case SfxStyleFamily::Para:
649
8.20k
            pFormat = m_rDoc.FindTextFormatCollByName(UIName(aName));
650
8.20k
            if (pFormat)
651
8.20k
            {
652
8.20k
                pFormat->SetGrabBagItem(rVal);
653
8.20k
                bChg = true;
654
8.20k
            }
655
8.20k
            break;
656
509
        case SfxStyleFamily::Pseudo:
657
509
            {
658
509
                SwNumRule* pRule = m_rDoc.FindNumRulePtr(UIName(aName));
659
509
                if (pRule)
660
509
                {
661
509
                    pRule->SetGrabBagItem(rVal);
662
509
                    bChg = true;
663
509
                }
664
509
            }
665
509
            break;
666
0
        default:
667
0
            break;
668
15.5k
    }
669
670
15.5k
    if (bChg)
671
15.5k
    {
672
15.5k
        dynamic_cast<SwDocStyleSheetPool&>(*m_pPool).InvalidateIterator();
673
15.5k
        m_pPool->Broadcast(SfxStyleSheetHint(SfxHintId::StyleSheetModified, *this));
674
15.5k
        if (SwEditShell* pSh = m_rDoc.GetEditShell())
675
0
            pSh->CallChgLnk();
676
15.5k
    }
677
15.5k
}
678
679
void SwDocStyleSheet::GetGrabBagItem(uno::Any& rVal) const
680
0
{
681
0
    SwFormat* pFormat = nullptr;
682
0
    switch (nFamily)
683
0
    {
684
0
        case SfxStyleFamily::Char:
685
0
            pFormat = m_rDoc.FindCharFormatByName(UIName(aName));
686
0
            if (pFormat)
687
0
                pFormat->GetGrabBagItem(rVal);
688
0
            break;
689
0
        case SfxStyleFamily::Para:
690
0
            pFormat = m_rDoc.FindTextFormatCollByName(UIName(aName));
691
0
            if (pFormat)
692
0
                pFormat->GetGrabBagItem(rVal);
693
0
            break;
694
0
        case SfxStyleFamily::Pseudo:
695
0
            {
696
0
                SwNumRule* pRule = m_rDoc.FindNumRulePtr(UIName(aName));
697
0
                if (pRule)
698
0
                    pRule->GetGrabBagItem(rVal);
699
0
            }
700
0
            break;
701
0
        default:
702
0
            break;
703
0
    }
704
0
}
705
// virtual methods
706
void SwDocStyleSheet::SetHidden( bool bValue )
707
37.8k
{
708
37.8k
    bool bChg = false;
709
37.8k
    if(!m_bPhysical)
710
0
        FillStyleSheet( FillPhysical );
711
712
37.8k
    SwFormat* pFormat = nullptr;
713
37.8k
    switch(nFamily)
714
37.8k
    {
715
5.18k
        case SfxStyleFamily::Char:
716
5.18k
            pFormat = m_rDoc.FindCharFormatByName( UIName(aName) );
717
5.18k
            if ( pFormat )
718
5.13k
            {
719
5.13k
                pFormat->SetHidden( bValue );
720
5.13k
                bChg = true;
721
5.13k
            }
722
5.18k
            break;
723
724
17.9k
        case SfxStyleFamily::Para:
725
17.9k
            pFormat = m_rDoc.FindTextFormatCollByName( UIName(aName) );
726
17.9k
            if ( pFormat )
727
17.9k
            {
728
17.9k
                pFormat->SetHidden( bValue );
729
17.9k
                bChg = true;
730
17.9k
            }
731
17.9k
            break;
732
733
1.65k
        case SfxStyleFamily::Frame:
734
1.65k
            pFormat = m_rDoc.FindFrameFormatByName( UIName(aName) );
735
1.65k
            if ( pFormat )
736
1.65k
            {
737
1.65k
                pFormat->SetHidden( bValue );
738
1.65k
                bChg = true;
739
1.65k
            }
740
1.65k
            break;
741
742
12.3k
        case SfxStyleFamily::Page:
743
12.3k
            {
744
12.3k
                SwPageDesc* pPgDesc = m_rDoc.FindPageDesc(UIName(aName));
745
12.3k
                if ( pPgDesc )
746
12.3k
                {
747
12.3k
                    pPgDesc->SetHidden( bValue );
748
12.3k
                    bChg = true;
749
12.3k
                }
750
12.3k
            }
751
12.3k
            break;
752
753
802
        case SfxStyleFamily::Pseudo:
754
802
            {
755
802
                SwNumRule* pRule = m_rDoc.FindNumRulePtr( UIName(aName) );
756
802
                if ( pRule )
757
802
                {
758
802
                    pRule->SetHidden( bValue );
759
802
                    bChg = true;
760
802
                }
761
802
            }
762
802
            break;
763
764
0
        case SfxStyleFamily::Table:
765
0
            {
766
0
                SwTableAutoFormat* pTableAutoFormat = m_rDoc.GetTableStyles().FindAutoFormat( TableStyleName(aName) );
767
0
                if ( pTableAutoFormat )
768
0
                {
769
0
                    pTableAutoFormat->SetHidden( bValue );
770
0
                    bChg = true;
771
0
                }
772
0
            }
773
0
            break;
774
775
0
        default:
776
0
            break;
777
37.8k
    }
778
779
37.8k
    if( bChg )
780
37.8k
    {
781
        // calling pPool->First() here would be quite slow...
782
37.8k
        dynamic_cast<SwDocStyleSheetPool&>(*m_pPool).InvalidateIterator(); // internal list has to be updated
783
37.8k
        m_pPool->Broadcast( SfxStyleSheetHint( SfxHintId::StyleSheetModified, *this ) );
784
37.8k
        if (SwEditShell* pSh = m_rDoc.GetEditShell())
785
0
            pSh->CallChgLnk();
786
37.8k
    }
787
37.8k
}
788
789
bool SwDocStyleSheet::IsHidden( ) const
790
76
{
791
76
    bool bRet = false;
792
793
76
    SwFormat* pFormat = nullptr;
794
76
    switch(nFamily)
795
76
    {
796
0
        case SfxStyleFamily::Char:
797
0
            pFormat = m_rDoc.FindCharFormatByName( UIName(aName) );
798
0
            bRet = pFormat && pFormat->IsHidden( );
799
0
            break;
800
801
0
        case SfxStyleFamily::Para:
802
0
            pFormat = m_rDoc.FindTextFormatCollByName( UIName(aName) );
803
0
            bRet = pFormat && pFormat->IsHidden( );
804
0
            break;
805
806
0
        case SfxStyleFamily::Frame:
807
0
            pFormat = m_rDoc.FindFrameFormatByName( UIName(aName) );
808
0
            bRet = pFormat && pFormat->IsHidden( );
809
0
            break;
810
811
76
        case SfxStyleFamily::Page:
812
76
            {
813
76
                SwPageDesc* pPgDesc = m_rDoc.FindPageDesc(UIName(aName));
814
76
                bRet = pPgDesc && pPgDesc->IsHidden( );
815
76
            }
816
76
            break;
817
0
        case SfxStyleFamily::Pseudo:
818
0
            {
819
0
                SwNumRule* pRule = m_rDoc.FindNumRulePtr( UIName(aName) );
820
0
                bRet = pRule && pRule->IsHidden( );
821
0
            }
822
0
            break;
823
0
        case SfxStyleFamily::Table:
824
0
            {
825
0
                SwTableAutoFormat* pTableAutoFormat = m_rDoc.GetTableStyles().FindAutoFormat( TableStyleName(aName) );
826
0
                bRet = pTableAutoFormat && pTableAutoFormat->IsHidden( );
827
0
            }
828
0
            break;
829
0
        default:
830
0
            break;
831
76
    }
832
833
76
    return bRet;
834
76
}
835
836
const OUString&  SwDocStyleSheet::GetParent() const
837
89.8k
{
838
89.8k
    if( !m_bPhysical )
839
0
    {
840
        // check if it's already in document
841
0
        SwFormat* pFormat = nullptr;
842
0
        SwGetPoolIdFromName eGetType;
843
0
        switch(nFamily)
844
0
        {
845
0
        case SfxStyleFamily::Char:
846
0
            pFormat = m_rDoc.FindCharFormatByName( UIName(aName) );
847
0
            eGetType = SwGetPoolIdFromName::ChrFmt;
848
0
            break;
849
850
0
        case SfxStyleFamily::Para:
851
0
            pFormat = m_rDoc.FindTextFormatCollByName( UIName(aName) );
852
0
            eGetType = SwGetPoolIdFromName::TxtColl;
853
0
            break;
854
855
0
        case SfxStyleFamily::Frame:
856
0
            pFormat = m_rDoc.FindFrameFormatByName( UIName(aName) );
857
0
            eGetType = SwGetPoolIdFromName::FrmFmt;
858
0
            break;
859
860
0
        case SfxStyleFamily::Table:
861
0
            {
862
0
                SwTableAutoFormat* pTableFormat = m_rDoc.GetTableStyles().FindAutoFormat(aName);
863
0
                if (pTableFormat)
864
0
                {
865
0
                    SwDocStyleSheet* pThis = const_cast<SwDocStyleSheet*>(this);
866
0
                    pThis->aParent = pTableFormat->GetParent();
867
0
                }
868
0
                return aParent;
869
0
            }
870
871
0
        case SfxStyleFamily::Page:
872
0
        case SfxStyleFamily::Pseudo:
873
0
        default:
874
0
            {
875
0
                return EMPTY_OUSTRING; // there's no parent
876
0
            }
877
0
        }
878
879
0
        UIName sTmp;
880
0
        if( !pFormat )         // not yet there, so default Parent
881
0
        {
882
0
            SwPoolFormatId i = SwStyleNameMapper::GetPoolIdFromUIName( UIName(aName), eGetType );
883
0
            i = ::GetPoolParent( i );
884
0
            if( i != SwPoolFormatId::ZERO && i != SwPoolFormatId::UNKNOWN )
885
0
                SwStyleNameMapper::FillUIName( i, sTmp );
886
0
        }
887
0
        else
888
0
        {
889
0
            SwFormat* p = pFormat->DerivedFrom();
890
0
            if( p && !p->IsDefault() )
891
0
                sTmp = p->GetName();
892
0
        }
893
0
        SwDocStyleSheet* pThis = const_cast<SwDocStyleSheet*>(this);
894
0
        pThis->aParent = sTmp.toString();
895
0
    }
896
89.8k
    return aParent;
897
89.8k
}
898
899
// Follower
900
const OUString&  SwDocStyleSheet::GetFollow() const
901
30.3k
{
902
30.3k
    if( !m_bPhysical )
903
0
    {
904
0
        SwDocStyleSheet* pThis = const_cast<SwDocStyleSheet*>(this);
905
0
        pThis->FillStyleSheet( FillAllInfo );
906
0
    }
907
30.3k
    return aFollow;
908
30.3k
}
909
910
void SwDocStyleSheet::SetLink(const OUString& rStr)
911
3.51k
{
912
3.51k
    SwImplShellAction aTmpSh(m_rDoc);
913
3.51k
    switch (nFamily)
914
3.51k
    {
915
1.81k
        case SfxStyleFamily::Para:
916
1.81k
        {
917
1.81k
            if (m_pColl)
918
1.81k
            {
919
1.81k
                SwCharFormat* pLink = lcl_FindCharFormat(m_rDoc, UIName(rStr));
920
1.81k
                if (pLink)
921
1.81k
                {
922
1.81k
                    m_pColl->SetLinkedCharFormat(pLink);
923
1.81k
                }
924
1.81k
            }
925
1.81k
            break;
926
0
        }
927
1.69k
        case SfxStyleFamily::Char:
928
1.69k
        {
929
1.69k
            if (m_pCharFormat)
930
1.69k
            {
931
1.69k
                SwTextFormatColl* pLink = lcl_FindParaFormat(m_rDoc, UIName(rStr));
932
1.69k
                if (pLink)
933
1.69k
                {
934
1.69k
                    m_pCharFormat->SetLinkedParaFormat(pLink);
935
1.69k
                }
936
1.69k
            }
937
1.69k
            break;
938
0
        }
939
0
        default:
940
0
            break;
941
3.51k
    }
942
3.51k
}
943
944
const OUString& SwDocStyleSheet::GetLink() const
945
0
{
946
0
    if (!m_bPhysical)
947
0
    {
948
0
        SwDocStyleSheet* pThis = const_cast<SwDocStyleSheet*>(this);
949
0
        pThis->FillStyleSheet(FillAllInfo);
950
0
    }
951
952
0
    return m_aLink;
953
0
}
954
955
// What Linkage is possible
956
bool  SwDocStyleSheet::HasFollowSupport() const
957
0
{
958
0
    switch(nFamily)
959
0
    {
960
0
        case SfxStyleFamily::Para :
961
0
        case SfxStyleFamily::Page : return true;
962
0
        case SfxStyleFamily::Frame:
963
0
        case SfxStyleFamily::Char :
964
0
        case SfxStyleFamily::Pseudo: return false;
965
0
        default:
966
0
            OSL_ENSURE(false, "unknown style family");
967
0
    }
968
0
    return false;
969
0
}
970
971
// Parent ?
972
bool  SwDocStyleSheet::HasParentSupport() const
973
0
{
974
0
    bool bRet = false;
975
0
    switch(nFamily)
976
0
    {
977
0
        case SfxStyleFamily::Char :
978
0
        case SfxStyleFamily::Para :
979
0
        case SfxStyleFamily::Frame: bRet = true;
980
0
            break;
981
0
        default:; //prevent warning
982
0
    }
983
0
    return bRet;
984
0
}
985
986
bool  SwDocStyleSheet::HasClearParentSupport() const
987
0
{
988
0
    bool bRet = false;
989
0
    switch(nFamily)
990
0
    {
991
0
        case SfxStyleFamily::Para :
992
0
        case SfxStyleFamily::Char :
993
0
        case SfxStyleFamily::Frame: bRet = true;
994
0
            break;
995
0
        default:; //prevent warning
996
0
    }
997
0
    return bRet;
998
0
}
999
1000
// determine textual description
1001
OUString  SwDocStyleSheet::GetDescription(MapUnit eUnit)
1002
0
{
1003
0
    IntlWrapper aIntlWrapper(SvtSysLocale().GetUILanguageTag());
1004
1005
0
    static constexpr OUString sPlus(u" + "_ustr);
1006
0
    if ( SfxStyleFamily::Page == nFamily )
1007
0
    {
1008
0
        if( !pSet )
1009
0
            GetItemSet();
1010
1011
0
        OUStringBuffer aDesc;
1012
1013
0
        for (SfxItemIter aIter( *pSet ); !aIter.IsAtEnd(); aIter.Next())
1014
0
        {
1015
0
            const SfxPoolItem* pItem = aIter.GetCurItem();
1016
0
            if(!IsInvalidItem(pItem))
1017
0
            {
1018
0
                switch ( pItem->Which() )
1019
0
                {
1020
0
                    case RES_LR_SPACE:
1021
0
                    case SID_ATTR_PAGE_SIZE:
1022
0
                    case SID_ATTR_PAGE_MAXSIZE:
1023
0
                    case SID_ATTR_PAGE_PAPERBIN:
1024
0
                    case SID_ATTR_BORDER_INNER:
1025
0
                        break;
1026
0
                    default:
1027
0
                    {
1028
0
                        OUString aItemPresentation;
1029
0
                        if ( !IsInvalidItem( pItem ) &&
1030
0
                             m_pPool->GetPool().GetPresentation(
1031
0
                                *pItem, eUnit, aItemPresentation, aIntlWrapper ) )
1032
0
                        {
1033
0
                            if ( !aDesc.isEmpty() && !aItemPresentation.isEmpty() )
1034
0
                                aDesc.append(sPlus);
1035
0
                            aDesc.append(aItemPresentation);
1036
0
                        }
1037
0
                    }
1038
0
                }
1039
0
            }
1040
0
        }
1041
0
        return aDesc.makeStringAndClear();
1042
0
    }
1043
1044
0
    if ( SfxStyleFamily::Frame == nFamily || SfxStyleFamily::Para == nFamily || SfxStyleFamily::Char == nFamily )
1045
0
    {
1046
0
        if( !pSet )
1047
0
            GetItemSet();
1048
1049
0
        OUStringBuffer aDesc;
1050
0
        OUString sPageNum;
1051
0
        OUString sModel;
1052
0
        OUString sBreak;
1053
0
        bool bHasWesternFontPrefix = false;
1054
0
        bool bHasCJKFontPrefix = false;
1055
0
        bool bHasCTLFontPrefix = false;
1056
0
        SvtCTLOptions aCTLOptions;
1057
1058
        // Get currently used FillStyle and remember, also need the XFillFloatTransparenceItem
1059
        // to decide if gradient transparence is used
1060
0
        const drawing::FillStyle eFillStyle(pSet->Get(XATTR_FILLSTYLE).GetValue());
1061
0
        const bool bUseFloatTransparence(pSet->Get(XATTR_FILLFLOATTRANSPARENCE).IsEnabled());
1062
1063
0
        for (SfxItemIter aIter( *pSet ); !aIter.IsAtEnd(); aIter.Next())
1064
0
        {
1065
0
            const SfxPoolItem* pItem = aIter.GetCurItem();
1066
0
            if(!IsInvalidItem(pItem))
1067
0
            {
1068
0
                switch ( pItem->Which() )
1069
0
                {
1070
0
                    case SID_ATTR_AUTO_STYLE_UPDATE:
1071
0
                    case RES_PAGEDESC:
1072
0
                        break;
1073
0
                    default:
1074
0
                    {
1075
0
                        OUString aItemPresentation;
1076
0
                        if ( !IsInvalidItem( pItem ) &&
1077
0
                             m_pPool->GetPool().GetPresentation(
1078
0
                                *pItem, eUnit, aItemPresentation, aIntlWrapper ) )
1079
0
                        {
1080
0
                            bool bIsDefault = false;
1081
0
                            switch ( pItem->Which() )
1082
0
                            {
1083
0
                                case XATTR_FILLCOLOR:
1084
0
                                {
1085
                                    // only use active FillStyle information
1086
0
                                    bIsDefault = (drawing::FillStyle_SOLID == eFillStyle);
1087
0
                                    break;
1088
0
                                }
1089
0
                                case XATTR_FILLGRADIENT:
1090
0
                                {
1091
                                    // only use active FillStyle information
1092
0
                                    bIsDefault = (drawing::FillStyle_GRADIENT == eFillStyle);
1093
0
                                    break;
1094
0
                                }
1095
0
                                case XATTR_FILLHATCH:
1096
0
                                {
1097
                                    // only use active FillStyle information
1098
0
                                    bIsDefault = (drawing::FillStyle_HATCH == eFillStyle);
1099
0
                                    break;
1100
0
                                }
1101
0
                                case XATTR_FILLBITMAP:
1102
0
                                {
1103
                                    // only use active FillStyle information
1104
0
                                    bIsDefault = (drawing::FillStyle_BITMAP == eFillStyle);
1105
0
                                    break;
1106
0
                                }
1107
0
                                case XATTR_FILLTRANSPARENCE:
1108
0
                                {
1109
                                    // only active when not FloatTransparence
1110
0
                                    bIsDefault = !bUseFloatTransparence;
1111
0
                                    break;
1112
0
                                }
1113
0
                                case XATTR_FILLFLOATTRANSPARENCE:
1114
0
                                {
1115
                                    // only active when FloatTransparence
1116
0
                                    bIsDefault = bUseFloatTransparence;
1117
0
                                    break;
1118
0
                                }
1119
1120
0
                                case SID_ATTR_PARA_PAGENUM:
1121
0
                                    sPageNum = aItemPresentation;
1122
0
                                    break;
1123
0
                                case SID_ATTR_PARA_MODEL:
1124
0
                                    sModel = aItemPresentation;
1125
0
                                    break;
1126
0
                                case RES_BREAK:
1127
0
                                    sBreak = aItemPresentation;
1128
0
                                    break;
1129
0
                                case RES_CHRATR_CJK_FONT:
1130
0
                                case RES_CHRATR_CJK_FONTSIZE:
1131
0
                                case RES_CHRATR_CJK_LANGUAGE:
1132
0
                                case RES_CHRATR_CJK_POSTURE:
1133
0
                                case RES_CHRATR_CJK_WEIGHT:
1134
0
                                if(SvtCJKOptions::IsCJKFontEnabled())
1135
0
                                    bIsDefault = true;
1136
0
                                if(!bHasCJKFontPrefix)
1137
0
                                {
1138
0
                                    aItemPresentation = SwResId(STR_CJK_FONT) + aItemPresentation;
1139
0
                                    bHasCJKFontPrefix = true;
1140
0
                                }
1141
0
                                break;
1142
0
                                case RES_CHRATR_CTL_FONT:
1143
0
                                case RES_CHRATR_CTL_FONTSIZE:
1144
0
                                case RES_CHRATR_CTL_LANGUAGE:
1145
0
                                case RES_CHRATR_CTL_POSTURE:
1146
0
                                case RES_CHRATR_CTL_WEIGHT:
1147
0
                                if(SvtCTLOptions::IsCTLFontEnabled())
1148
0
                                    bIsDefault = true;
1149
0
                                if(!bHasCTLFontPrefix)
1150
0
                                {
1151
0
                                    aItemPresentation = SwResId(STR_CTL_FONT) + aItemPresentation;
1152
0
                                    bHasCTLFontPrefix = true;
1153
0
                                }
1154
0
                                break;
1155
0
                                case RES_CHRATR_FONT:
1156
0
                                case RES_CHRATR_FONTSIZE:
1157
0
                                case RES_CHRATR_LANGUAGE:
1158
0
                                case RES_CHRATR_POSTURE:
1159
0
                                case RES_CHRATR_WEIGHT:
1160
0
                                if(!bHasWesternFontPrefix)
1161
0
                                {
1162
0
                                    aItemPresentation = SwResId(STR_WESTERN_FONT) + aItemPresentation;
1163
0
                                    bHasWesternFontPrefix = true;
1164
0
                                }
1165
0
                                [[fallthrough]];
1166
0
                                default:
1167
0
                                    bIsDefault = true;
1168
0
                            }
1169
0
                            if(bIsDefault)
1170
0
                            {
1171
0
                                if ( !aDesc.isEmpty() && !aItemPresentation.isEmpty() )
1172
0
                                    aDesc.append(sPlus);
1173
0
                                aDesc.append(aItemPresentation);
1174
0
                            }
1175
0
                        }
1176
0
                    }
1177
0
                }
1178
0
            }
1179
0
        }
1180
        // Special treatment for Break, Page template and Site offset
1181
0
        if (!sModel.isEmpty())
1182
0
        {
1183
0
            if (!aDesc.isEmpty())
1184
0
                aDesc.append(sPlus);
1185
0
            aDesc.append(SwResId(STR_PAGEBREAK) + sPlus + sModel);
1186
0
            if (sPageNum != "0")
1187
0
            {
1188
0
                aDesc.append(sPlus + SwResId(STR_PAGEOFFSET) + sPageNum);
1189
0
            }
1190
0
        }
1191
0
        else if (!sBreak.isEmpty()) // Break can be valid only when NO Model
1192
0
        {
1193
0
            if (!aDesc.isEmpty())
1194
0
                aDesc.append(sPlus);
1195
0
            aDesc.append(sBreak);
1196
0
        }
1197
0
        return aDesc.makeStringAndClear();
1198
0
    }
1199
1200
0
    if( SfxStyleFamily::Pseudo == nFamily )
1201
0
    {
1202
0
        return OUString();
1203
0
    }
1204
1205
0
    return SfxStyleSheetBase::GetDescription(eUnit);
1206
0
}
1207
1208
std::vector<std::pair<sal_uInt16, OUString>> SwDocStyleSheet::GetItemPresentation(
1209
    MapUnit eMetric, const SfxItemSet* pWorkingSet)
1210
0
{
1211
0
    std::vector<std::pair<sal_uInt16, OUString>> aResult;
1212
0
    IntlWrapper aIntlWrapper(SvtSysLocale().GetUILanguageTag());
1213
1214
0
    if (SfxStyleFamily::Page == nFamily)
1215
0
    {
1216
0
        if (!pSet)
1217
0
            GetItemSet();
1218
1219
        // tdf#172128: use the ItemSet parent instead of the shared object returned by Find(parent)
1220
0
        const SfxItemSet* pParentSet = pSet->GetParent();
1221
1222
0
        SfxItemIter aIter(*pSet);
1223
1224
0
        for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
1225
0
        {
1226
0
            if (!IsInvalidItem(pItem))
1227
0
            {
1228
                // Only show items that are explicitly SET in this style, not inherited from parent
1229
0
                if (pSet->GetItemState(pItem->Which(), false) != SfxItemState::SET)
1230
0
                    continue;
1231
1232
                // Skip items identical to parent
1233
0
                if (pParentSet)
1234
0
                {
1235
0
                    const SfxPoolItem* pParentItem = nullptr;
1236
0
                    if (pParentSet->GetItemState(pItem->Which(), true, &pParentItem) == SfxItemState::SET
1237
0
                        && pParentItem && *pParentItem == *pItem)
1238
0
                        continue;
1239
0
                }
1240
1241
                // Skip items whose value equals the pool default
1242
0
                if (*pItem == pSet->GetPool()->GetUserOrPoolDefaultItem(pItem->Which()))
1243
0
                    continue;
1244
1245
0
                switch (pItem->Which())
1246
0
                {
1247
0
                    case RES_LR_SPACE:
1248
0
                    case SID_ATTR_PAGE_SIZE:
1249
0
                    case SID_ATTR_PAGE_MAXSIZE:
1250
0
                    case SID_ATTR_PAGE_PAPERBIN:
1251
0
                    case SID_ATTR_BORDER_INNER:
1252
0
                        break;
1253
0
                    default:
1254
0
                    {
1255
0
                        OUString aItemPresentation;
1256
0
                        if (!IsInvalidItem(pItem) &&
1257
0
                            m_pPool->GetPool().GetPresentation(
1258
0
                                *pItem, eMetric, aItemPresentation, aIntlWrapper))
1259
0
                        {
1260
0
                            if (!aItemPresentation.isEmpty())
1261
0
                            {
1262
                                // If there isn't "Name: value", try adding the name
1263
0
                                if (aItemPresentation.indexOf(": ") == -1)
1264
0
                                {
1265
0
                                    sal_uInt16 nSlotId = m_pPool->GetPool().GetSlotId(pItem->Which());
1266
0
                                    sal_uInt32 nIdx = SvxAttrNameTable::FindIndex(nSlotId);
1267
0
                                    OUString aAttrName = SvxAttrNameTable::GetString(nIdx);
1268
0
                                    if (aAttrName.isEmpty())
1269
0
                                    {
1270
                                        // Fallback for Writer-specific WhichId
1271
0
                                        static const std::map<sal_uInt16, TranslateId> aSwAttrNames = {
1272
0
                                            { sal_uInt16(RES_PARATR_OUTLINELEVEL),      STR_ATTR_OUTLINE_LEVEL },
1273
0
                                            { sal_uInt16(RES_PARATR_LIST_LEVEL),        STR_ATTR_LIST_LEVEL },
1274
0
                                            { sal_uInt16(RES_PARATR_LIST_ISRESTART),    STR_ATTR_LIST_RESTART },
1275
0
                                            { sal_uInt16(RES_PARATR_LIST_RESTARTVALUE), STR_ATTR_LIST_RESTART_VALUE },
1276
0
                                            { sal_uInt16(RES_PARATR_AUTOFRAMEDIR),      STR_ATTR_TEXT_DIRECTION },
1277
0
                                            { sal_uInt16(RES_CHRATR_HIDDEN),            STR_ATTR_HIDDEN },
1278
0
                                            { sal_uInt16(XATTR_FILLSTYLE),              STR_ATTR_FILL_STYLE },
1279
0
                                            { sal_uInt16(XATTR_FILLGRADIENT),           STR_ATTR_GRADIENT },
1280
0
                                            { sal_uInt16(XATTR_GRADIENTSTEPCOUNT),      STR_ATTR_GRADIENT_STEPS },
1281
0
                                        };
1282
0
                                        auto itW = aSwAttrNames.find(pItem->Which());
1283
0
                                        if (itW != aSwAttrNames.end())
1284
0
                                            aAttrName = SwResId(itW->second);
1285
0
                                    }
1286
0
                                    if (!aAttrName.isEmpty())
1287
0
                                        aItemPresentation = aAttrName + ": " + aItemPresentation;
1288
0
                                }
1289
0
                                aResult.emplace_back(pItem->Which(), aItemPresentation);
1290
0
                            }
1291
0
                        }
1292
0
                    }
1293
0
                }
1294
0
            }
1295
0
        }
1296
0
        return aResult;
1297
0
    }
1298
1299
0
    if (SfxStyleFamily::Frame == nFamily || SfxStyleFamily::Para == nFamily || SfxStyleFamily::Char == nFamily)
1300
0
    {
1301
0
        if (!pSet)
1302
0
            GetItemSet();
1303
1304
0
        const SfxItemSet* pCheckSet = pWorkingSet ? pWorkingSet : pSet;
1305
0
        const SfxItemSet* pParentSet = pCheckSet->GetParent();
1306
1307
0
        const drawing::FillStyle eFillStyle(pCheckSet->Get(XATTR_FILLSTYLE).GetValue());
1308
0
        const bool bUseFloatTransparence(pCheckSet->Get(XATTR_FILLFLOATTRANSPARENCE).IsEnabled());
1309
1310
0
        SfxItemIter aIter(*pSet);
1311
1312
0
        for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
1313
0
        {
1314
0
            if (!IsInvalidItem(pItem))
1315
0
            {
1316
                // Only show items that are explicitly SET in this style, not inherited from parent
1317
0
                if (pCheckSet->GetItemState(pItem->Which(), false) != SfxItemState::SET)
1318
0
                    continue;
1319
1320
                // Skip items identical to parent
1321
0
                if (pParentSet)
1322
0
                {
1323
0
                    const SfxPoolItem* pParentItem = nullptr;
1324
0
                    if (pParentSet->GetItemState(pItem->Which(), true, &pParentItem) == SfxItemState::SET
1325
0
                        && pParentItem && *pParentItem == *pItem)
1326
0
                        continue;
1327
0
                }
1328
1329
0
                switch (pItem->Which())
1330
0
                {
1331
0
                    case SID_ATTR_AUTO_STYLE_UPDATE:
1332
0
                    case RES_PAGEDESC:
1333
0
                    case SID_ATTR_PARA_PAGENUM:
1334
0
                    case SID_ATTR_PARA_MODEL:
1335
0
                    case RES_BREAK:
1336
                        // Skip these - they have special handling in GetDescription
1337
0
                        break;
1338
0
                    default:
1339
0
                    {
1340
0
                        OUString aItemPresentation;
1341
0
                        if (!IsInvalidItem(pItem) &&
1342
0
                            m_pPool->GetPool().GetPresentation(
1343
0
                                *pItem, eMetric, aItemPresentation, aIntlWrapper))
1344
0
                        {
1345
0
                            bool bIsDefault = false;
1346
0
                            switch (pItem->Which())
1347
0
                            {
1348
0
                                case XATTR_FILLCOLOR:
1349
0
                                    bIsDefault = (drawing::FillStyle_SOLID == eFillStyle);
1350
0
                                    break;
1351
0
                                case XATTR_FILLGRADIENT:
1352
0
                                    bIsDefault = (drawing::FillStyle_GRADIENT == eFillStyle);
1353
0
                                    break;
1354
0
                                case XATTR_FILLHATCH:
1355
0
                                    bIsDefault = (drawing::FillStyle_HATCH == eFillStyle);
1356
0
                                    break;
1357
0
                                case XATTR_FILLBITMAP:
1358
0
                                    bIsDefault = (drawing::FillStyle_BITMAP == eFillStyle);
1359
0
                                    break;
1360
0
                                case XATTR_FILLTRANSPARENCE:
1361
0
                                    bIsDefault = !bUseFloatTransparence;
1362
0
                                    break;
1363
0
                                case XATTR_FILLFLOATTRANSPARENCE:
1364
0
                                    bIsDefault = bUseFloatTransparence;
1365
0
                                    break;
1366
0
                                case XATTR_GRADIENTSTEPCOUNT:
1367
0
                                    bIsDefault = bUseFloatTransparence;
1368
0
                                    break;
1369
0
                                case RES_CHRATR_CJK_FONT:
1370
0
                                case RES_CHRATR_CJK_FONTSIZE:
1371
0
                                case RES_CHRATR_CJK_LANGUAGE:
1372
0
                                case RES_CHRATR_CJK_POSTURE:
1373
0
                                case RES_CHRATR_CJK_WEIGHT:
1374
0
                                    if (SvtCJKOptions::IsCJKFontEnabled())
1375
0
                                        bIsDefault = true;
1376
0
                                    aItemPresentation = SwResId(STR_CJK_FONT) + aItemPresentation;
1377
0
                                        break;
1378
0
                                case RES_CHRATR_CTL_FONT:
1379
0
                                case RES_CHRATR_CTL_FONTSIZE:
1380
0
                                case RES_CHRATR_CTL_LANGUAGE:
1381
0
                                case RES_CHRATR_CTL_POSTURE:
1382
0
                                case RES_CHRATR_CTL_WEIGHT:
1383
0
                                    if (SvtCTLOptions::IsCTLFontEnabled())
1384
0
                                        bIsDefault = true;
1385
0
                                    aItemPresentation = SwResId(STR_CTL_FONT) + aItemPresentation;
1386
0
                                    break;
1387
0
                                case RES_CHRATR_FONT:
1388
0
                                case RES_CHRATR_FONTSIZE:
1389
0
                                case RES_CHRATR_LANGUAGE:
1390
0
                                case RES_CHRATR_POSTURE:
1391
0
                                case RES_CHRATR_WEIGHT:
1392
0
                                    aItemPresentation = SwResId(STR_WESTERN_FONT) + aItemPresentation;
1393
0
                                    [[fallthrough]];
1394
0
                                default:
1395
0
                                    bIsDefault = true;
1396
0
                            }
1397
0
                            if (bIsDefault && !aItemPresentation.isEmpty())
1398
0
                            {
1399
                                // If there isn't "Name: value", try adding the name
1400
0
                                if (aItemPresentation.indexOf(": ") == -1)
1401
0
                                {
1402
0
                                    sal_uInt16 nSlotId = m_pPool->GetPool().GetSlotId(pItem->Which());
1403
0
                                    sal_uInt32 nIdx = SvxAttrNameTable::FindIndex(nSlotId);
1404
0
                                    OUString aAttrName = SvxAttrNameTable::GetString(nIdx);
1405
0
                                    if (aAttrName.isEmpty())
1406
0
                                    {
1407
                                        // Fallback for Writer-specific WhichId
1408
0
                                        static const std::map<sal_uInt16, TranslateId> aSwAttrNames = {
1409
0
                                            { sal_uInt16(RES_PARATR_OUTLINELEVEL),      STR_ATTR_OUTLINE_LEVEL },
1410
0
                                            { sal_uInt16(RES_PARATR_LIST_LEVEL),        STR_ATTR_LIST_LEVEL },
1411
0
                                            { sal_uInt16(RES_PARATR_LIST_ISRESTART),    STR_ATTR_LIST_RESTART },
1412
0
                                            { sal_uInt16(RES_PARATR_LIST_RESTARTVALUE), STR_ATTR_LIST_RESTART_VALUE },
1413
0
                                            { sal_uInt16(RES_PARATR_AUTOFRAMEDIR),      STR_ATTR_TEXT_DIRECTION },
1414
0
                                            { sal_uInt16(RES_CHRATR_HIDDEN),            STR_ATTR_HIDDEN },
1415
0
                                            { sal_uInt16(XATTR_FILLSTYLE),              STR_ATTR_FILL_STYLE },
1416
0
                                            { sal_uInt16(XATTR_FILLGRADIENT),           STR_ATTR_GRADIENT },
1417
0
                                            { sal_uInt16(XATTR_GRADIENTSTEPCOUNT),      STR_ATTR_GRADIENT_STEPS },
1418
0
                                        };
1419
0
                                        auto itW = aSwAttrNames.find(pItem->Which());
1420
0
                                        if (itW != aSwAttrNames.end())
1421
0
                                            aAttrName = SwResId(itW->second);
1422
0
                                    }
1423
0
                                    if (!aAttrName.isEmpty())
1424
0
                                        aItemPresentation = aAttrName + ": " + aItemPresentation;
1425
0
                                }
1426
0
                                aResult.emplace_back(pItem->Which(), aItemPresentation);
1427
0
                            }
1428
0
                        }
1429
0
                    }
1430
0
                }
1431
0
            }
1432
0
        }
1433
0
        return aResult;
1434
0
    }
1435
1436
0
    if (SfxStyleFamily::Pseudo == nFamily)
1437
0
    {
1438
0
        return aResult;
1439
0
    }
1440
1441
0
    return SfxStyleSheetBase::GetItemPresentation(eMetric);
1442
0
}
1443
1444
void SwDocStyleSheet::ResetItems(const std::set<sal_uInt16>& rWhichIds)
1445
0
{
1446
0
    if (rWhichIds.empty())
1447
0
        return;
1448
1449
0
    std::vector<sal_uInt16> aIds(rWhichIds.begin(), rWhichIds.end());
1450
1451
0
    if (nFamily == SfxStyleFamily::Para)
1452
0
    {
1453
0
        SwTextFormatColl* pColl = m_rDoc.FindTextFormatCollByName(UIName(aName));
1454
0
        if (pColl)
1455
0
            m_rDoc.ResetAttrAtFormat(aIds, *pColl);
1456
0
    }
1457
0
    else if (nFamily == SfxStyleFamily::Char)
1458
0
    {
1459
0
        SwCharFormat* pCharFormat = m_rDoc.FindCharFormatByName(UIName(aName));
1460
0
        if (pCharFormat)
1461
0
            m_rDoc.ResetAttrAtFormat(aIds, *pCharFormat);
1462
0
    }
1463
0
    else if (nFamily == SfxStyleFamily::Frame)
1464
0
    {
1465
0
        SwFrameFormat* pFrameFormat = m_rDoc.FindFrameFormatByName(UIName(aName));
1466
0
        if (pFrameFormat)
1467
0
            m_rDoc.ResetAttrAtFormat(aIds, *pFrameFormat);
1468
0
    }
1469
0
}
1470
1471
// Set names
1472
bool  SwDocStyleSheet::SetName(const OUString& rStr, bool bReindexNow)
1473
0
{
1474
0
    if( rStr.isEmpty() )
1475
0
        return false;
1476
1477
0
    if( aName != rStr )
1478
0
    {
1479
0
        if( !SfxStyleSheetBase::SetName(rStr, bReindexNow))
1480
0
            return false;
1481
0
    }
1482
0
    else if(!m_bPhysical)
1483
0
        FillStyleSheet( FillPhysical );
1484
1485
0
    bool bChg = false;
1486
0
    switch(nFamily)
1487
0
    {
1488
0
        case SfxStyleFamily::Char :
1489
0
        {
1490
0
            OSL_ENSURE(m_pCharFormat, "SwCharFormat missing!");
1491
0
            if( m_pCharFormat && m_pCharFormat->GetName() != rStr )
1492
0
            {
1493
0
                if (!m_pCharFormat->GetName().isEmpty())
1494
0
                    m_rDoc.RenameFormat(*m_pCharFormat, UIName(rStr));
1495
0
                else
1496
0
                    m_pCharFormat->SetFormatName(UIName(rStr));
1497
1498
0
                bChg = true;
1499
0
            }
1500
0
            break;
1501
0
        }
1502
0
        case SfxStyleFamily::Para :
1503
0
        {
1504
0
            OSL_ENSURE(m_pColl, "Collection missing!");
1505
0
            if( m_pColl && m_pColl->GetName() != rStr )
1506
0
            {
1507
0
                if (!m_pColl->GetName().isEmpty())
1508
0
                    m_rDoc.RenameFormat(*m_pColl, UIName(rStr));
1509
0
                else
1510
0
                    m_pColl->SetFormatName(UIName(rStr));
1511
1512
0
                bChg = true;
1513
0
            }
1514
0
            break;
1515
0
        }
1516
0
        case SfxStyleFamily::Frame:
1517
0
        {
1518
0
            OSL_ENSURE(m_pFrameFormat, "FrameFormat missing!");
1519
0
            if( m_pFrameFormat && m_pFrameFormat->GetName() != rStr )
1520
0
            {
1521
0
                if (!m_pFrameFormat->GetName().isEmpty())
1522
0
                    m_rDoc.RenameFormat(*m_pFrameFormat, UIName(rStr));
1523
0
                else
1524
0
                    m_pFrameFormat->SetFormatName( UIName(rStr) );
1525
1526
0
                bChg = true;
1527
0
            }
1528
0
            break;
1529
0
        }
1530
0
        case SfxStyleFamily::Page :
1531
0
            OSL_ENSURE(m_pDesc, "PageDesc missing!");
1532
0
            if( m_pDesc && m_pDesc->GetName() != rStr )
1533
0
            {
1534
                // Set PageDesc - copy with earlier one - probably not
1535
                // necessary for setting the name. So here we allow a
1536
                // cast.
1537
0
                SwPageDesc aPageDesc(*const_cast<SwPageDesc*>(m_pDesc));
1538
0
                const UIName aOldName(aPageDesc.GetName());
1539
1540
0
                aPageDesc.SetName( UIName(rStr) );
1541
0
                bool const bDoesUndo = m_rDoc.GetIDocumentUndoRedo().DoesUndo();
1542
1543
0
                m_rDoc.GetIDocumentUndoRedo().DoUndo(!aOldName.isEmpty());
1544
0
                m_rDoc.ChgPageDesc(aOldName, aPageDesc);
1545
0
                m_rDoc.GetIDocumentUndoRedo().DoUndo(bDoesUndo);
1546
1547
0
                m_rDoc.getIDocumentState().SetModified();
1548
0
                bChg = true;
1549
0
            }
1550
0
            break;
1551
0
        case SfxStyleFamily::Pseudo:
1552
0
            OSL_ENSURE(m_pNumRule, "NumRule missing!");
1553
1554
0
            if (m_pNumRule)
1555
0
            {
1556
0
                UIName aOldName = m_pNumRule->GetName();
1557
1558
0
                if (!aOldName.isEmpty())
1559
0
                {
1560
0
                    if ( aOldName != rStr &&
1561
0
                         m_rDoc.RenameNumRule(aOldName, UIName(rStr)))
1562
0
                    {
1563
0
                        m_pNumRule = m_rDoc.FindNumRulePtr(UIName(rStr));
1564
0
                        m_rDoc.getIDocumentState().SetModified();
1565
1566
0
                        bChg = true;
1567
0
                    }
1568
0
                }
1569
0
                else
1570
0
                {
1571
                    // #i91400#
1572
0
                    const_cast<SwNumRule*>(m_pNumRule)->SetName( UIName(rStr), m_rDoc.getIDocumentListsAccess() );
1573
0
                    m_rDoc.getIDocumentState().SetModified();
1574
1575
0
                    bChg = true;
1576
0
                }
1577
0
            }
1578
1579
0
            break;
1580
1581
0
        default:
1582
0
            OSL_ENSURE(false, "unknown style family");
1583
0
    }
1584
1585
0
    if( bChg )
1586
0
    {
1587
0
        m_pPool->First(nFamily);  // internal list has to be updated
1588
0
        m_pPool->Broadcast( SfxStyleSheetHint( SfxHintId::StyleSheetModified, *this ) );
1589
0
        if (SwEditShell* pSh = m_rDoc.GetEditShell())
1590
0
            pSh->CallChgLnk();
1591
0
    }
1592
0
    return true;
1593
0
}
1594
1595
// hierarchy of deduction
1596
bool   SwDocStyleSheet::SetParent( const OUString& rStr)
1597
184k
{
1598
184k
    SwFormat* pFormat = nullptr, *pParent = nullptr;
1599
184k
    switch(nFamily)
1600
184k
    {
1601
83.0k
        case SfxStyleFamily::Char :
1602
83.0k
            OSL_ENSURE( m_pCharFormat, "SwCharFormat missing!" );
1603
83.0k
            if( nullptr != ( pFormat = m_pCharFormat ) && !rStr.isEmpty() )
1604
4.34k
                pParent = lcl_FindCharFormat(m_rDoc, UIName(rStr));
1605
83.0k
            break;
1606
1607
86.7k
        case SfxStyleFamily::Para :
1608
86.7k
            OSL_ENSURE( m_pColl, "Collection missing!");
1609
86.7k
            if( nullptr != ( pFormat = m_pColl ) && !rStr.isEmpty() )
1610
31.8k
                pParent = lcl_FindParaFormat( m_rDoc, UIName(rStr) );
1611
86.7k
            break;
1612
1613
372
        case SfxStyleFamily::Frame:
1614
372
            OSL_ENSURE(m_pFrameFormat, "FrameFormat missing!");
1615
372
            if( nullptr != ( pFormat = m_pFrameFormat ) && !rStr.isEmpty() )
1616
0
                pParent = lcl_FindFrameFormat( m_rDoc, UIName(rStr) );
1617
372
            break;
1618
1619
6.26k
        case SfxStyleFamily::Page:
1620
13.9k
        case SfxStyleFamily::Pseudo:
1621
13.9k
            break;
1622
0
        default:
1623
0
            OSL_ENSURE(false, "unknown style family");
1624
184k
    }
1625
1626
184k
    bool bRet = false;
1627
184k
    if( pFormat && pFormat->DerivedFrom() &&
1628
170k
        pFormat->DerivedFrom()->GetName() != rStr )
1629
170k
    {
1630
170k
        {
1631
170k
            SwImplShellAction aTmp( m_rDoc );
1632
170k
            bRet = pFormat->SetDerivedFrom( pParent );
1633
170k
        }
1634
1635
170k
        if( bRet )
1636
49.8k
        {
1637
49.8k
            aParent = rStr;
1638
49.8k
            m_pPool->Broadcast( SfxStyleSheetHint( SfxHintId::StyleSheetModified,
1639
49.8k
                            *this ) );
1640
49.8k
        }
1641
170k
    }
1642
1643
184k
    return bRet;
1644
184k
}
1645
1646
// Set Follower
1647
bool   SwDocStyleSheet::SetFollow( const OUString& rStr)
1648
16.2k
{
1649
16.2k
    if( !rStr.isEmpty() && !SfxStyleSheetBase::SetFollow( rStr ))
1650
0
        return false;
1651
1652
16.2k
    SwImplShellAction aTmpSh( m_rDoc );
1653
16.2k
    switch(nFamily)
1654
16.2k
    {
1655
15.8k
    case SfxStyleFamily::Para :
1656
15.8k
    {
1657
15.8k
        OSL_ENSURE(m_pColl, "Collection missing!");
1658
15.8k
        if( m_pColl )
1659
15.8k
        {
1660
15.8k
            SwTextFormatColl* pFollow = m_pColl;
1661
15.8k
            if( !rStr.isEmpty() && nullptr == (pFollow = lcl_FindParaFormat(m_rDoc, UIName(rStr)) ))
1662
0
                pFollow = m_pColl;
1663
1664
15.8k
            m_pColl->SetNextTextFormatColl(*pFollow);
1665
15.8k
        }
1666
15.8k
        break;
1667
0
    }
1668
449
    case SfxStyleFamily::Page :
1669
449
    {
1670
449
        OSL_ENSURE(m_pDesc, "PageDesc missing!");
1671
449
        if( m_pDesc )
1672
449
        {
1673
449
            const SwPageDesc* pFollowDesc = !rStr.isEmpty()
1674
449
                                            ? lcl_FindPageDesc(m_rDoc, UIName(rStr))
1675
449
                                            : nullptr;
1676
449
            size_t nId = 0;
1677
449
            if (pFollowDesc != m_pDesc->GetFollow() && m_rDoc.FindPageDesc(m_pDesc->GetName(), &nId))
1678
373
            {
1679
373
                SwPageDesc aDesc( *m_pDesc );
1680
373
                aDesc.SetFollow( pFollowDesc );
1681
373
                m_rDoc.ChgPageDesc( nId, aDesc );
1682
373
                m_pDesc = &m_rDoc.GetPageDesc( nId );
1683
373
            }
1684
449
        }
1685
449
        break;
1686
0
    }
1687
0
    case SfxStyleFamily::Char:
1688
0
    case SfxStyleFamily::Frame:
1689
0
    case SfxStyleFamily::Pseudo:
1690
0
        break;
1691
0
    default:
1692
0
        OSL_ENSURE(false, "unknown style family");
1693
16.2k
    }
1694
1695
16.2k
    return true;
1696
16.2k
}
1697
1698
static
1699
void lcl_SwFormatToFlatItemSet(SwFormat const *const pFormat, std::optional<SfxItemSet>& pRet)
1700
0
{
1701
    // note: we don't add the odd items that GetItemSet() would add
1702
    // because they don't seem relevant for preview
1703
0
    std::vector<SfxItemSet const*> sets;
1704
0
    sets.push_back(&pFormat->GetAttrSet());
1705
0
    while (SfxItemSet const*const pParent = sets.back()->GetParent())
1706
0
    {
1707
0
        sets.push_back(pParent);
1708
0
    }
1709
    // start by copying top-level parent set
1710
0
    pRet.emplace(*sets.back());
1711
0
    sets.pop_back();
1712
0
    for (auto iter = sets.rbegin(); iter != sets.rend(); ++iter)
1713
0
    {   // in reverse so child overrides parent
1714
0
        pRet->Put(**iter);
1715
0
    }
1716
0
}
1717
1718
std::optional<SfxItemSet> SwDocStyleSheet::GetItemSetForPreview()
1719
0
{
1720
0
    if (SfxStyleFamily::Page == nFamily || SfxStyleFamily::Pseudo == nFamily || SfxStyleFamily::Table == nFamily)
1721
0
    {
1722
0
        SAL_INFO("sw.ui", "GetItemSetForPreview not implemented for page or number or table style");
1723
0
        return std::optional<SfxItemSet>();
1724
0
    }
1725
0
    if (!m_bPhysical)
1726
0
    {
1727
        // because not only this style, but also any number of its parents
1728
        // (or follow style) may not actually exist in the document at this
1729
        // time, return one "flattened" item set that contains all items from
1730
        // all parents.
1731
0
        std::optional<SfxItemSet> pRet;
1732
1733
0
        bool bModifiedEnabled = m_rDoc.getIDocumentState().IsEnableSetModified();
1734
0
        m_rDoc.getIDocumentState().SetEnableSetModified(false);
1735
1736
0
        FillStyleSheet(FillPreview, &pRet);
1737
1738
0
        m_rDoc.getIDocumentState().SetEnableSetModified(bModifiedEnabled);
1739
1740
0
        assert(pRet);
1741
0
        return pRet;
1742
0
    }
1743
0
    else
1744
0
    {
1745
0
        std::optional<SfxItemSet> pRet;
1746
0
        switch (nFamily)
1747
0
        {
1748
0
            case SfxStyleFamily::Char:
1749
0
                lcl_SwFormatToFlatItemSet(m_pCharFormat, pRet);
1750
0
                break;
1751
0
            case SfxStyleFamily::Para:
1752
0
                lcl_SwFormatToFlatItemSet(m_pColl, pRet);
1753
0
                break;
1754
0
            case SfxStyleFamily::Frame:
1755
0
                lcl_SwFormatToFlatItemSet(m_pFrameFormat, pRet);
1756
0
                break;
1757
0
            default:
1758
0
                std::abort();
1759
0
        }
1760
0
        return pRet;
1761
0
    }
1762
0
}
1763
1764
// extract ItemSet to Name and Family, Mask
1765
1766
SfxItemSet&   SwDocStyleSheet::GetItemSet()
1767
1.06M
{
1768
1.06M
    if(!m_bPhysical)
1769
10.2k
        FillStyleSheet( FillPhysical );
1770
1771
1.06M
    switch(nFamily)
1772
1.06M
    {
1773
86.1k
        case SfxStyleFamily::Char:
1774
657k
        case SfxStyleFamily::Para:
1775
801k
        case SfxStyleFamily::Frame:
1776
801k
            {
1777
801k
                SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
1778
801k
                aBoxInfo.SetTable( false );
1779
801k
                aBoxInfo.SetDist( true );   // always show gap field
1780
801k
                aBoxInfo.SetMinDist( true );// set minimum size in tables and paragraphs
1781
801k
                aBoxInfo.SetDefDist( MIN_BORDER_DIST );// always set Default-Gap
1782
                    // Single lines can only have DontCare-Status in tables
1783
801k
                aBoxInfo.SetValid( SvxBoxInfoItemValidFlags::DISABLE );
1784
1785
801k
                if( nFamily == SfxStyleFamily::Char )
1786
86.1k
                {
1787
86.1k
                    assert(m_pCharFormat && "Where's SwCharFormat");
1788
86.1k
                    m_aCoreSet.Put(m_pCharFormat->GetAttrSet());
1789
86.1k
                    m_aCoreSet.Put( aBoxInfo );
1790
1791
86.1k
                    if(m_pCharFormat->DerivedFrom())
1792
85.9k
                        m_aCoreSet.SetParent(&m_pCharFormat->DerivedFrom()->GetAttrSet());
1793
86.1k
                }
1794
714k
                else if ( nFamily == SfxStyleFamily::Para )
1795
570k
                {
1796
570k
                    assert(m_pColl && "Where's Collection");
1797
570k
                    m_aCoreSet.Put(m_pColl->GetAttrSet());
1798
570k
                    m_aCoreSet.Put( aBoxInfo );
1799
570k
                    m_aCoreSet.Put(SfxBoolItem(SID_ATTR_AUTO_STYLE_UPDATE, m_pColl->IsAutoUpdateOnDirectFormat()));
1800
1801
570k
                    if(m_pColl->DerivedFrom())
1802
565k
                        m_aCoreSet.SetParent(&m_pColl->DerivedFrom()->GetAttrSet());
1803
570k
                }
1804
144k
                else
1805
144k
                {
1806
144k
                    assert(m_pFrameFormat && "Where's FrameFormat");
1807
144k
                    m_aCoreSet.Put(m_pFrameFormat->GetAttrSet());
1808
144k
                    m_aCoreSet.Put( aBoxInfo );
1809
144k
                    m_aCoreSet.Put(SfxBoolItem(SID_ATTR_AUTO_STYLE_UPDATE, m_pFrameFormat->IsAutoUpdateOnDirectFormat()));
1810
1811
144k
                    if(m_pFrameFormat->DerivedFrom())
1812
144k
                        m_aCoreSet.SetParent(&m_pFrameFormat->DerivedFrom()->GetAttrSet());
1813
1814
                    // create needed items for XPropertyList entries from the DrawModel so that
1815
                    // the Area TabPage can access them
1816
144k
                    const SwDrawModel* pDrawModel = m_rDoc.getIDocumentDrawModelAccess().GetDrawModel();
1817
1818
144k
                    m_aCoreSet.Put(SvxColorListItem(pDrawModel->GetColorList(), SID_COLOR_TABLE));
1819
144k
                    m_aCoreSet.Put(SvxGradientListItem(pDrawModel->GetGradientList(), SID_GRADIENT_LIST));
1820
144k
                    m_aCoreSet.Put(SvxHatchListItem(pDrawModel->GetHatchList(), SID_HATCH_LIST));
1821
144k
                    m_aCoreSet.Put(SvxBitmapListItem(pDrawModel->GetBitmapList(), SID_BITMAP_LIST));
1822
144k
                    m_aCoreSet.Put(SvxPatternListItem(pDrawModel->GetPatternList(), SID_PATTERN_LIST));
1823
144k
                }
1824
801k
            }
1825
801k
            break;
1826
1827
248k
        case SfxStyleFamily::Page :
1828
248k
            {
1829
                // set correct parent to get the drawing::FillStyle_NONE FillStyle as needed
1830
248k
                if(!m_aCoreSet.GetParent())
1831
236k
                {
1832
236k
                    m_aCoreSet.SetParent(&m_rDoc.GetDfltFrameFormat()->GetAttrSet());
1833
236k
                }
1834
1835
248k
                assert(m_pDesc && "No PageDescriptor");
1836
248k
                ::PageDescToItemSet(*const_cast<SwPageDesc*>(m_pDesc), m_aCoreSet);
1837
248k
            }
1838
248k
            break;
1839
1840
10.9k
        case SfxStyleFamily::Pseudo:
1841
10.9k
            {
1842
10.9k
                assert(m_pNumRule && "No NumRule");
1843
10.9k
                SvxNumRule aRule = m_pNumRule->MakeSvxNumRule();
1844
10.9k
                m_aCoreSet.Put(SvxNumBulletItem(std::move(aRule)));
1845
10.9k
            }
1846
10.9k
            break;
1847
1848
0
        default:
1849
0
            OSL_ENSURE(false, "unknown style family");
1850
1.06M
    }
1851
    // Member of Baseclass
1852
1.06M
    pSet = &m_aCoreSet;
1853
1854
1.06M
    return m_aCoreSet;
1855
1.06M
}
1856
1857
void SwDocStyleSheet::MergeIndentAttrsOfListStyle( SfxItemSet& rSet )
1858
0
{
1859
0
    if ( nFamily != SfxStyleFamily::Para )
1860
0
    {
1861
0
        return;
1862
0
    }
1863
1864
0
    assert(m_pColl && "<SwDocStyleSheet::MergeIndentAttrsOfListStyle(..)> - missing paragraph style");
1865
0
    ::sw::ListLevelIndents const indents(m_pColl->AreListLevelIndentsApplicable());
1866
0
    if (indents == ::sw::ListLevelIndents::No)
1867
0
        return;
1868
1869
0
    OSL_ENSURE( m_pColl->GetItemState( RES_PARATR_NUMRULE ) == SfxItemState::SET,
1870
0
            "<SwDocStyleSheet::MergeIndentAttrsOfListStyle(..)> - list level indents are applicable at paragraph style, but no list style found. Serious defect." );
1871
0
    const UIName sNumRule = m_pColl->GetNumRule().GetValue();
1872
0
    if (sNumRule.isEmpty())
1873
0
        return;
1874
1875
0
    const SwNumRule* pRule = m_rDoc.FindNumRulePtr( sNumRule );
1876
0
    if( pRule )
1877
0
    {
1878
0
        const SwNumFormat& rFormat = pRule->Get( 0 );
1879
0
        if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
1880
0
        {
1881
0
            if (indents & ::sw::ListLevelIndents::FirstLine)
1882
0
            {
1883
0
                SvxFirstLineIndentItem const firstLine(
1884
0
                    SvxIndentValue{ static_cast<double>(rFormat.GetFirstLineIndent()),
1885
0
                                    rFormat.GetFirstLineIndentUnit() },
1886
0
                    RES_MARGIN_FIRSTLINE);
1887
0
                rSet.Put(firstLine);
1888
0
            }
1889
0
            if (indents & ::sw::ListLevelIndents::LeftMargin)
1890
0
            {
1891
0
                SvxTextLeftMarginItem const leftMargin(SvxIndentValue::twips(rFormat.GetIndentAt()),
1892
0
                                                       RES_MARGIN_TEXTLEFT);
1893
0
                rSet.Put(leftMargin);
1894
0
            }
1895
0
        }
1896
0
    }
1897
0
}
1898
1899
// handling of parameter <bResetIndentAttrsAtParagraphStyle>
1900
void SwDocStyleSheet::SetItemSet(const SfxItemSet& rSet, const bool bBroadcast, const bool bParam1)
1901
400k
{
1902
    // if applicable determine format first
1903
400k
    if(!m_bPhysical)
1904
0
        FillStyleSheet( FillPhysical );
1905
1906
400k
    SwImplShellAction aTmpSh( m_rDoc );
1907
1908
400k
    OSL_ENSURE( &rSet != &m_aCoreSet, "SetItemSet with own Set is not allowed" );
1909
1910
400k
    if (m_rDoc.GetIDocumentUndoRedo().DoesUndo())
1911
0
    {
1912
0
        SwRewriter aRewriter;
1913
0
        aRewriter.AddRule( UndoArg1, GetName() );
1914
0
        m_rDoc.GetIDocumentUndoRedo().StartUndo( SwUndoId::INSFMTATTR, &aRewriter );
1915
0
    }
1916
1917
400k
    SwFormat* pFormat = nullptr;
1918
400k
    std::vector<sal_uInt16> aWhichIdsToReset;
1919
400k
    std::optional<SwPageDesc> oNewDsc;
1920
400k
    size_t nPgDscPos = 0;
1921
1922
400k
    switch(nFamily)
1923
400k
    {
1924
63.1k
        case SfxStyleFamily::Char :
1925
63.1k
            {
1926
63.1k
                OSL_ENSURE(m_pCharFormat, "Where's CharFormat");
1927
63.1k
                pFormat = m_pCharFormat;
1928
63.1k
            }
1929
63.1k
            break;
1930
1931
199k
        case SfxStyleFamily::Para :
1932
199k
        {
1933
199k
            OSL_ENSURE(m_pColl, "Where's Collection");
1934
199k
            if(const SfxBoolItem* pAutoUpdate = rSet.GetItemIfSet(SID_ATTR_AUTO_STYLE_UPDATE,false))
1935
199k
            {
1936
199k
                m_pColl->SetAutoUpdateOnDirectFormat(pAutoUpdate->GetValue());
1937
199k
            }
1938
1939
199k
            const SwCondCollItem* pCondItem = rSet.GetItemIfSet( FN_COND_COLL, false );
1940
1941
199k
            if( RES_CONDTXTFMTCOLL == m_pColl->Which() && pCondItem )
1942
0
            {
1943
0
                const CommandStruct* pCmds = SwCondCollItem::GetCmds();
1944
0
                for(sal_uInt16 i = 0; i < COND_COMMAND_COUNT; i++)
1945
0
                {
1946
0
                    SwCollCondition aCond( nullptr, pCmds[ i ].nCnd, pCmds[ i ].nSubCond );
1947
0
                    static_cast<SwConditionTextFormatColl*>(m_pColl)->RemoveCondition( aCond );
1948
0
                    const UIName sStyle = pCondItem->GetStyle( i );
1949
0
                    if (sStyle.isEmpty())
1950
0
                        continue;
1951
0
                    SwTextFormatColl* const pFindFormat = lcl_FindParaFormat( m_rDoc, sStyle );
1952
0
                    if (pFindFormat)
1953
0
                    {
1954
0
                        aCond.RegisterToFormat( *pFindFormat );
1955
0
                        static_cast<SwConditionTextFormatColl*>(m_pColl)->InsertCondition( aCond );
1956
0
                    }
1957
0
                }
1958
1959
0
                m_pColl->GetNotifier().Broadcast(sw::CondCollCondChg(*m_pColl));
1960
0
            }
1961
199k
            else if( pCondItem && !m_pColl->HasWriterListeners() )
1962
0
            {
1963
                // no conditional template, then first create and adopt
1964
                // all important values
1965
0
                SwConditionTextFormatColl* pCColl = m_rDoc.MakeCondTextFormatColl(
1966
0
                        m_pColl->GetName(), static_cast<SwTextFormatColl*>(m_pColl->DerivedFrom()) );
1967
0
                if( m_pColl != &m_pColl->GetNextTextFormatColl() )
1968
0
                    pCColl->SetNextTextFormatColl( m_pColl->GetNextTextFormatColl() );
1969
1970
0
                if( m_pColl->IsAssignedToListLevelOfOutlineStyle())
1971
0
                    pCColl->AssignToListLevelOfOutlineStyle(m_pColl->GetAssignedOutlineStyleLevel());
1972
0
                else
1973
0
                    pCColl->DeleteAssignmentToListLevelOfOutlineStyle();
1974
1975
0
                const CommandStruct* pCmds = SwCondCollItem::GetCmds();
1976
0
                for( sal_uInt16 i = 0; i < COND_COMMAND_COUNT; ++i )
1977
0
                {
1978
0
                    const UIName sStyle = pCondItem->GetStyle( i );
1979
0
                    if (sStyle.isEmpty())
1980
0
                        continue;
1981
0
                    SwTextFormatColl *const pFindFormat = lcl_FindParaFormat( m_rDoc, sStyle );
1982
0
                    if (pFindFormat)
1983
0
                    {
1984
0
                        pCColl->InsertCondition( SwCollCondition( pFindFormat,
1985
0
                                    pCmds[ i ].nCnd, pCmds[ i ].nSubCond ) );
1986
0
                    }
1987
0
                }
1988
1989
0
                m_rDoc.DelTextFormatColl( m_pColl );
1990
0
                m_pColl = pCColl;
1991
0
            }
1992
199k
            const bool bResetIndentAttrsAtParagraphStyle = bParam1;
1993
199k
            if ( bResetIndentAttrsAtParagraphStyle &&
1994
0
                 rSet.GetItemState( RES_PARATR_NUMRULE, false ) == SfxItemState::SET &&
1995
0
                 rSet.GetItemState(RES_MARGIN_FIRSTLINE, false) != SfxItemState::SET &&
1996
0
                 m_pColl->GetItemState(RES_MARGIN_FIRSTLINE, false) == SfxItemState::SET)
1997
0
            {
1998
0
                aWhichIdsToReset.emplace_back(RES_MARGIN_FIRSTLINE);
1999
0
            }
2000
199k
            if ( bResetIndentAttrsAtParagraphStyle &&
2001
0
                 rSet.GetItemState( RES_PARATR_NUMRULE, false ) == SfxItemState::SET &&
2002
0
                 rSet.GetItemState(RES_MARGIN_TEXTLEFT, false) != SfxItemState::SET &&
2003
0
                 m_pColl->GetItemState(RES_MARGIN_TEXTLEFT, false) == SfxItemState::SET)
2004
0
            {
2005
0
                aWhichIdsToReset.emplace_back(RES_MARGIN_TEXTLEFT);
2006
0
            }
2007
2008
            // #i56252: If a standard numbering style is assigned to a standard paragraph style
2009
            // we have to create a physical instance of the numbering style. If we do not and
2010
            // neither the paragraph style nor the numbering style is used in the document
2011
            // the numbering style will not be saved with the document and the assignment got lost.
2012
199k
            if( const SfxPoolItem* pNumRuleItem = rSet.GetItemIfSet( RES_PARATR_NUMRULE, false ) )
2013
1.94k
            {   // Setting a numbering rule?
2014
1.94k
                const UIName sNumRule = static_cast<const SwNumRuleItem*>(pNumRuleItem)->GetValue();
2015
1.94k
                if (!sNumRule.isEmpty())
2016
1.91k
                {
2017
1.91k
                    SwNumRule* pRule = m_rDoc.FindNumRulePtr( sNumRule );
2018
1.91k
                    if( !pRule )
2019
0
                    {   // Numbering rule not in use yet.
2020
0
                        SwPoolFormatId nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( sNumRule, SwGetPoolIdFromName::NumRule );
2021
0
                        if( SwPoolFormatId::UNKNOWN != nPoolId ) // It's a standard numbering rule
2022
0
                        {
2023
0
                            m_rDoc.getIDocumentStylePoolAccess().GetNumRuleFromPool( nPoolId ); // Create numbering rule (physical)
2024
0
                        }
2025
0
                    }
2026
1.91k
                }
2027
1.94k
            }
2028
2029
199k
            pFormat = m_pColl;
2030
2031
199k
            sal_uInt16 nId = sal_uInt16(m_pColl->GetPoolFormatId()) &
2032
199k
                            ~ ( COLL_GET_RANGE_BITS | POOLGRP_NOCOLLID );
2033
199k
            switch( GetMask() & ( static_cast<SfxStyleSearchBits>(0x0fff) & ~SfxStyleSearchBits::SwCondColl ) )
2034
199k
            {
2035
16.8k
                case SfxStyleSearchBits::SwText:
2036
16.8k
                    nId |= COLL_TEXT_BITS;
2037
16.8k
                    break;
2038
26.4k
                case SfxStyleSearchBits::SwChapter:
2039
26.4k
                    nId |= COLL_DOC_BITS;
2040
26.4k
                    break;
2041
9.28k
                case SfxStyleSearchBits::SwList:
2042
9.28k
                    nId |= COLL_LISTS_BITS;
2043
9.28k
                    break;
2044
6.60k
                case SfxStyleSearchBits::SwIndex:
2045
6.60k
                    nId |= COLL_REGISTER_BITS;
2046
6.60k
                    break;
2047
14.1k
                case SfxStyleSearchBits::SwExtra:
2048
14.1k
                    nId |= COLL_EXTRA_BITS;
2049
14.1k
                    break;
2050
4.92k
                case SfxStyleSearchBits::SwHtml:
2051
4.92k
                    nId |= COLL_HTML_BITS;
2052
4.92k
                    break;
2053
121k
                default: break;
2054
199k
            }
2055
199k
            m_pColl->SetPoolFormatId( SwPoolFormatId(nId) );
2056
199k
            break;
2057
199k
        }
2058
6.05k
        case SfxStyleFamily::Frame:
2059
6.05k
        {
2060
6.05k
            OSL_ENSURE(m_pFrameFormat, "Where's FrameFormat");
2061
2062
6.05k
            if(const SfxPoolItem* pAutoUpdate = rSet.GetItemIfSet(SID_ATTR_AUTO_STYLE_UPDATE,false))
2063
6.05k
            {
2064
6.05k
                m_pFrameFormat->SetAutoUpdateOnDirectFormat(static_cast<const SfxBoolItem*>(pAutoUpdate)->GetValue());
2065
6.05k
            }
2066
6.05k
            pFormat = m_pFrameFormat;
2067
6.05k
        }
2068
6.05k
        break;
2069
2070
122k
        case SfxStyleFamily::Page :
2071
122k
            {
2072
122k
                OSL_ENSURE(m_pDesc, "Where's PageDescriptor");
2073
2074
122k
                if (m_rDoc.FindPageDesc(m_pDesc->GetName(), &nPgDscPos))
2075
122k
                {
2076
122k
                    oNewDsc.emplace( *m_pDesc );
2077
                    // #i48949# - no undo actions for the
2078
                    // copy of the page style
2079
122k
                    ::sw::UndoGuard const ug(m_rDoc.GetIDocumentUndoRedo());
2080
122k
                    m_rDoc.CopyPageDesc(*m_pDesc, *oNewDsc); // #i7983#
2081
2082
122k
                    pFormat = &oNewDsc->GetMaster();
2083
2084
                    // tdf#134166: Changing page style can affect toolbar button state.
2085
122k
                    if (SwEditShell* pSh = m_rDoc.GetEditShell())
2086
0
                        pSh->CallChgLnk();
2087
122k
                }
2088
122k
            }
2089
122k
            break;
2090
2091
9.13k
        case SfxStyleFamily::Pseudo:
2092
9.13k
            {
2093
9.13k
                OSL_ENSURE(m_pNumRule, "Where's NumRule");
2094
2095
9.13k
                if (!m_pNumRule)
2096
0
                    break;
2097
2098
9.13k
                const SfxPoolItem* pItem;
2099
9.13k
                switch( rSet.GetItemState( SID_ATTR_NUMBERING_RULE, false, &pItem ))
2100
9.13k
                {
2101
9.13k
                case SfxItemState::SET:
2102
9.13k
                {
2103
9.13k
                    SvxNumRule& rSetRule = const_cast<SvxNumRule&>(static_cast<const SvxNumBulletItem*>(pItem)->GetNumRule());
2104
9.13k
                    rSetRule.UnLinkGraphics();
2105
9.13k
                    SwNumRule aSetRule(*m_pNumRule);
2106
9.13k
                    aSetRule.SetSvxRule(rSetRule, &m_rDoc);
2107
9.13k
                    m_rDoc.ChgNumRuleFormats( aSetRule );
2108
9.13k
                }
2109
9.13k
                break;
2110
0
                case SfxItemState::INVALID:
2111
                // set NumRule to default values
2112
                // what are the default values?
2113
0
                {
2114
0
                    SwNumRule aRule( m_pNumRule->GetName(),
2115
                                     // #i89178#
2116
0
                                     numfunc::GetDefaultPositionAndSpaceMode() );
2117
0
                    m_rDoc.ChgNumRuleFormats( aRule );
2118
0
                }
2119
0
                break;
2120
0
                default: break;
2121
9.13k
                }
2122
9.13k
            }
2123
9.13k
            break;
2124
2125
9.13k
        default:
2126
0
            OSL_ENSURE(false, "unknown style family");
2127
400k
    }
2128
2129
400k
    if( pFormat && rSet.Count())
2130
391k
    {
2131
391k
        {
2132
            // Own scope for SfxItemIter needed to have it registered at rSet as short as possible
2133
            // due to m_aCoreSet.ClearItem() below - rSet *is* equal to m_aCoreSet here sometimes.
2134
            // This should *not* be the case (see OSL_ENSURE &rSet != &m_aCoreSet at the beginning
2135
            // of this method) but happens because lcl_setLineNumbering calls GetItemSet/SetItemSet
2136
            // at the *same* xStyleSheet. You can see that SwDocStyleSheet::GetItemSet() above
2137
            // does return m_aCoreSet. I guess that lcl_setLineNumbering should not do that...
2138
4.25M
            for (SfxItemIter aIter( rSet ); !aIter.IsAtEnd(); aIter.Next())
2139
3.86M
            {
2140
3.86M
                const SfxPoolItem* pItem = aIter.GetCurItem();
2141
3.86M
                if( IsInvalidItem( pItem ) )            // Clear
2142
0
                {
2143
                    // use method <SwDoc::ResetAttrAtFormat(..)> in order to
2144
                    // create an Undo object for the attribute reset.
2145
0
                    aWhichIdsToReset.emplace_back(aIter.GetCurWhich());
2146
0
                }
2147
3.86M
            }
2148
391k
        }
2149
2150
391k
        m_rDoc.ResetAttrAtFormat(aWhichIdsToReset, *pFormat);
2151
2152
391k
        SfxItemSet aSet(rSet);
2153
391k
        aSet.ClearInvalidItems();
2154
2155
391k
        if(SfxStyleFamily::Frame == nFamily)
2156
6.05k
        {
2157
            // Need to check for unique item for DrawingLayer items of type NameOrIndex
2158
            // and evtl. correct that item to ensure unique names for that type. This call may
2159
            // modify/correct entries inside of the given SfxItemSet
2160
6.05k
            m_rDoc.CheckForUniqueItemForLineFillNameOrIndex(aSet);
2161
6.05k
        }
2162
2163
391k
        m_aCoreSet.ClearItem();
2164
2165
391k
        if( oNewDsc )
2166
122k
        {
2167
122k
            const bool bApplyToAllFormatFrames = bParam1;
2168
122k
            ::ItemSetToPageDesc(aSet, *oNewDsc, bApplyToAllFormatFrames);
2169
122k
            m_rDoc.ChgPageDesc( nPgDscPos, *oNewDsc );
2170
122k
            m_pDesc = &m_rDoc.GetPageDesc( nPgDscPos );
2171
122k
            m_rDoc.PreDelPageDesc(&*oNewDsc); // #i7983#
2172
122k
            oNewDsc.reset();
2173
122k
        }
2174
268k
        else
2175
268k
        {
2176
268k
            m_rDoc.ChgFormat(*pFormat, aSet);       // put all that is set
2177
268k
            if (bBroadcast)
2178
268k
                m_pPool->Broadcast(SfxStyleSheetHint(SfxHintId::StyleSheetModified, *this));
2179
268k
        }
2180
391k
    }
2181
9.13k
    else
2182
9.13k
    {
2183
9.13k
        m_aCoreSet.ClearItem();
2184
9.13k
        if( oNewDsc )       // we still need to delete it
2185
0
        {
2186
0
            m_rDoc.PreDelPageDesc(&*oNewDsc); // #i7983#
2187
0
            oNewDsc.reset();
2188
0
        }
2189
9.13k
    }
2190
2191
400k
    if (m_rDoc.GetIDocumentUndoRedo().DoesUndo())
2192
0
    {
2193
0
        m_rDoc.GetIDocumentUndoRedo().EndUndo(SwUndoId::END, nullptr);
2194
0
    }
2195
400k
}
2196
2197
static void lcl_SaveStyles( SfxStyleFamily nFamily, std::vector<void*>& rArr, SwDoc& rDoc )
2198
0
{
2199
0
    switch( nFamily )
2200
0
    {
2201
0
    case SfxStyleFamily::Char:
2202
0
        {
2203
0
            const SwCharFormats& rTable = *rDoc.GetCharFormats();
2204
0
            for(auto const& rChar: rTable)
2205
0
            {
2206
0
                rArr.push_back(rChar);
2207
0
            }
2208
0
        }
2209
0
        break;
2210
0
    case SfxStyleFamily::Para:
2211
0
        {
2212
0
            const SwTextFormatColls& rTable = *rDoc.GetTextFormatColls();
2213
0
            for(auto const& rPara : rTable)
2214
0
            {
2215
0
                rArr.push_back(rPara);
2216
0
            }
2217
0
        }
2218
0
        break;
2219
0
    case SfxStyleFamily::Frame:
2220
0
        {
2221
0
            for(auto const& rFrame: *rDoc.GetFrameFormats())
2222
0
            {
2223
0
                rArr.push_back(rFrame);
2224
0
            }
2225
0
        }
2226
0
        break;
2227
2228
0
    case SfxStyleFamily::Page:
2229
0
        {
2230
0
            for( size_t n = 0, nCnt = rDoc.GetPageDescCnt(); n < nCnt; ++n )
2231
0
            {
2232
0
                rArr.push_back( &rDoc.GetPageDesc( n ) );
2233
0
            }
2234
0
        }
2235
0
        break;
2236
2237
0
    case SfxStyleFamily::Pseudo:
2238
0
        {
2239
0
            const SwNumRuleTable& rTable = rDoc.GetNumRuleTable();
2240
0
            for(auto const& rPseudo: rTable)
2241
0
            {
2242
0
                rArr.push_back(rPseudo);
2243
0
            }
2244
0
        }
2245
0
        break;
2246
0
    default: break;
2247
0
    }
2248
0
}
2249
2250
static bool lcl_Contains(const std::vector<void*>& rArr, const void* p)
2251
0
{
2252
0
    return std::find( rArr.begin(), rArr.end(), p ) != rArr.end();
2253
0
}
2254
2255
static void lcl_DeleteInfoStyles( SfxStyleFamily nFamily, std::vector<void*> const & rArr, SwDoc& rDoc )
2256
0
{
2257
0
    size_t n, nCnt;
2258
0
    switch( nFamily )
2259
0
    {
2260
0
    case SfxStyleFamily::Char:
2261
0
        {
2262
0
            std::deque<sal_uInt16> aDelArr;
2263
0
            const SwCharFormats& rTable = *rDoc.GetCharFormats();
2264
0
            for( n = 0, nCnt = rTable.size(); n < nCnt; ++n )
2265
0
            {
2266
0
                if( !lcl_Contains( rArr, rTable[ n ] ))
2267
0
                    aDelArr.push_front( n );
2268
0
            }
2269
0
            for(auto const& rDelArr: aDelArr)
2270
0
                rDoc.DelCharFormat( rDelArr );
2271
0
        }
2272
0
        break;
2273
2274
0
    case SfxStyleFamily::Para :
2275
0
        {
2276
0
            std::deque<sal_uInt16> aDelArr;
2277
0
            const SwTextFormatColls& rTable = *rDoc.GetTextFormatColls();
2278
0
            for( n = 0, nCnt = rTable.size(); n < nCnt; ++n )
2279
0
            {
2280
0
                if( !lcl_Contains( rArr, rTable[ n ] ))
2281
0
                    aDelArr.push_front( n );
2282
0
            }
2283
0
            for(auto const& rDelArr: aDelArr)
2284
0
                rDoc.DelTextFormatColl( rDelArr );
2285
0
        }
2286
0
        break;
2287
2288
0
    case SfxStyleFamily::Frame:
2289
0
        {
2290
0
            std::deque<SwFrameFormat*> aDelArr;
2291
0
            for(auto const& rFrame: *rDoc.GetFrameFormats())
2292
0
            {
2293
0
                if( !lcl_Contains( rArr, rFrame ))
2294
0
                    aDelArr.push_front( rFrame );
2295
0
            }
2296
0
            for( auto const& rDelArr: aDelArr)
2297
0
                rDoc.DelFrameFormat( rDelArr );
2298
0
        }
2299
0
        break;
2300
2301
0
    case SfxStyleFamily::Page:
2302
0
        {
2303
0
            std::deque<size_t> aDelArr;
2304
0
            for( n = 0, nCnt = rDoc.GetPageDescCnt(); n < nCnt; ++n )
2305
0
            {
2306
0
                if( !lcl_Contains( rArr, &rDoc.GetPageDesc( n ) ))
2307
0
                    aDelArr.push_front( n );
2308
0
            }
2309
0
            for( auto const& rDelArr: aDelArr )
2310
0
                rDoc.DelPageDesc( rDelArr);
2311
0
        }
2312
0
        break;
2313
2314
0
    case SfxStyleFamily::Pseudo:
2315
0
        {
2316
0
            std::deque<SwNumRule*> aDelArr;
2317
0
            const SwNumRuleTable& rTable = rDoc.GetNumRuleTable();
2318
0
            for( auto const& rPseudo: rTable)
2319
0
            {
2320
0
                if( !lcl_Contains( rArr, rPseudo ))
2321
0
                    aDelArr.push_front( rPseudo );
2322
0
            }
2323
0
            for( auto const& rDelArr: aDelArr)
2324
0
                rDoc.DelNumRule( rDelArr->GetName() );
2325
0
        }
2326
0
        break;
2327
0
    default: break;
2328
0
    }
2329
0
}
2330
2331
// determine the format
2332
bool SwDocStyleSheet::FillStyleSheet(
2333
    FillStyleType const eFType, std::optional<SfxItemSet> *const o_ppFlatSet)
2334
3.06M
{
2335
3.06M
    bool bRet = false;
2336
3.06M
    SwPoolFormatId nPoolId = SwPoolFormatId::UNKNOWN;
2337
3.06M
    SwFormat* pFormat = nullptr;
2338
2339
3.06M
    bool bCreate = FillPhysical == eFType;
2340
3.06M
    bool bDeleteInfo = false;
2341
3.06M
    bool bFillOnlyInfo = FillAllInfo == eFType || FillPreview == eFType;
2342
3.06M
    std::vector<void*> aDelArr;
2343
3.06M
    bool const isModified(m_rDoc.getIDocumentState().IsModified());
2344
2345
3.06M
    switch(nFamily)
2346
3.06M
    {
2347
218k
    case SfxStyleFamily::Char:
2348
218k
        m_pCharFormat = lcl_FindCharFormat(m_rDoc, UIName(aName), this, bCreate );
2349
218k
        m_bPhysical = nullptr != m_pCharFormat;
2350
218k
        if( bFillOnlyInfo && !m_bPhysical )
2351
0
        {
2352
            // create style (plus all needed parents) and clean it up
2353
            // later - without affecting the undo/redo stack
2354
0
            ::sw::UndoGuard const ug(m_rDoc.GetIDocumentUndoRedo());
2355
0
            bDeleteInfo = true;
2356
0
            ::lcl_SaveStyles( nFamily, aDelArr, m_rDoc );
2357
0
            m_pCharFormat = lcl_FindCharFormat(m_rDoc, UIName(aName), this );
2358
0
        }
2359
2360
218k
        pFormat = m_pCharFormat;
2361
218k
        m_aLink.clear();
2362
218k
        if( !bCreate && !pFormat )
2363
106k
        {
2364
106k
            if( aName == SwResId(STR_POOLCHR_STANDARD))
2365
0
                nPoolId = SwPoolFormatId::ZERO;
2366
106k
            else
2367
106k
                nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( UIName(aName), SwGetPoolIdFromName::ChrFmt );
2368
106k
        }
2369
2370
218k
        if (m_pCharFormat)
2371
111k
        {
2372
111k
            const SwTextFormatColl* pParaFormat = m_pCharFormat->GetLinkedParaFormat();
2373
111k
            if (pParaFormat)
2374
0
            {
2375
0
                m_aLink = pParaFormat->GetName().toString();
2376
0
            }
2377
111k
        }
2378
2379
218k
        bRet = nullptr != m_pCharFormat || SwPoolFormatId::UNKNOWN != nPoolId;
2380
2381
218k
        if( bDeleteInfo )
2382
0
            m_pCharFormat = nullptr;
2383
218k
        break;
2384
2385
2.10M
    case SfxStyleFamily::Para:
2386
2.10M
        {
2387
2.10M
            m_pColl = lcl_FindParaFormat(m_rDoc, UIName(aName), this, bCreate);
2388
2.10M
            m_bPhysical = nullptr != m_pColl;
2389
2.10M
            if( bFillOnlyInfo && !m_bPhysical )
2390
0
            {
2391
0
                ::sw::UndoGuard const ug(m_rDoc.GetIDocumentUndoRedo());
2392
0
                bDeleteInfo = true;
2393
0
                ::lcl_SaveStyles( nFamily, aDelArr, m_rDoc );
2394
0
                m_pColl = lcl_FindParaFormat(m_rDoc, UIName(aName), this );
2395
0
            }
2396
2397
2.10M
            pFormat = m_pColl;
2398
2.10M
            m_aLink.clear();
2399
2.10M
            if( m_pColl )
2400
1.91M
            {
2401
1.91M
                PresetFollow( m_pColl->GetNextTextFormatColl().GetName().toString() );
2402
1.91M
                const SwCharFormat* pCharFormat = m_pColl->GetLinkedCharFormat();
2403
1.91M
                if (pCharFormat)
2404
1.61k
                {
2405
1.61k
                    m_aLink = pCharFormat->GetName().toString();
2406
1.61k
                }
2407
1.91M
            }
2408
185k
            else if( !bCreate )
2409
185k
                nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( UIName(aName), SwGetPoolIdFromName::TxtColl );
2410
2411
2.10M
            bRet = nullptr != m_pColl || SwPoolFormatId::UNKNOWN != nPoolId;
2412
2413
2.10M
            if( bDeleteInfo )
2414
0
                m_pColl = nullptr;
2415
2.10M
        }
2416
2.10M
        break;
2417
2418
269k
    case SfxStyleFamily::Frame:
2419
269k
        m_pFrameFormat = lcl_FindFrameFormat(m_rDoc, UIName(aName), this, bCreate);
2420
269k
        m_bPhysical = nullptr != m_pFrameFormat;
2421
269k
        if (bFillOnlyInfo && !m_bPhysical)
2422
0
        {
2423
0
            ::sw::UndoGuard const ug(m_rDoc.GetIDocumentUndoRedo());
2424
0
            bDeleteInfo = true;
2425
0
            ::lcl_SaveStyles( nFamily, aDelArr, m_rDoc );
2426
0
            m_pFrameFormat = lcl_FindFrameFormat(m_rDoc, UIName(aName), this );
2427
0
        }
2428
269k
        pFormat = m_pFrameFormat;
2429
269k
        if( !bCreate && !pFormat )
2430
55.0k
            nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( UIName(aName), SwGetPoolIdFromName::FrmFmt );
2431
2432
269k
        bRet = nullptr != m_pFrameFormat || SwPoolFormatId::UNKNOWN != nPoolId;
2433
2434
269k
        if( bDeleteInfo )
2435
0
            m_pFrameFormat = nullptr;
2436
269k
        break;
2437
2438
432k
    case SfxStyleFamily::Page:
2439
432k
        m_pDesc = lcl_FindPageDesc(m_rDoc, UIName(aName), this, bCreate);
2440
432k
        m_bPhysical = nullptr != m_pDesc;
2441
432k
        if( bFillOnlyInfo && !m_pDesc )
2442
0
        {
2443
0
            ::sw::UndoGuard const ug(m_rDoc.GetIDocumentUndoRedo());
2444
0
            bDeleteInfo = true;
2445
0
            ::lcl_SaveStyles( nFamily, aDelArr, m_rDoc );
2446
0
            m_pDesc = lcl_FindPageDesc( m_rDoc, UIName(aName), this );
2447
0
        }
2448
2449
432k
        if( m_pDesc )
2450
418k
        {
2451
418k
            nPoolId = m_pDesc->GetPoolFormatId();
2452
418k
            nHelpId = m_pDesc->GetPoolHelpId();
2453
418k
            if (const OUString* pattern = m_pDesc->GetPoolHlpFileId() != UCHAR_MAX
2454
418k
                                              ? m_rDoc.GetDocPattern(m_pDesc->GetPoolHlpFileId())
2455
418k
                                              : nullptr)
2456
0
                aHelpFile = *pattern;
2457
418k
            else
2458
418k
                aHelpFile.clear();
2459
418k
        }
2460
13.6k
        else if( !bCreate )
2461
13.6k
            nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( UIName(aName), SwGetPoolIdFromName::PageDesc );
2462
432k
        SetMask( (USER_FMT & sal_uInt16(nPoolId)) ? SfxStyleSearchBits::UserDefined : SfxStyleSearchBits::Auto );
2463
2464
432k
        bRet = nullptr != m_pDesc || SwPoolFormatId::UNKNOWN != nPoolId;
2465
432k
        if( bDeleteInfo )
2466
0
            m_pDesc = nullptr;
2467
432k
        break;
2468
2469
33.0k
    case SfxStyleFamily::Pseudo:
2470
33.0k
        m_pNumRule = lcl_FindNumRule(m_rDoc, UIName(aName), this, bCreate);
2471
33.0k
        m_bPhysical = nullptr != m_pNumRule;
2472
33.0k
        if( bFillOnlyInfo && !m_pNumRule )
2473
0
        {
2474
0
            ::sw::UndoGuard const ug(m_rDoc.GetIDocumentUndoRedo());
2475
0
            bDeleteInfo = true;
2476
0
            ::lcl_SaveStyles( nFamily, aDelArr, m_rDoc );
2477
0
            m_pNumRule = lcl_FindNumRule( m_rDoc, UIName(aName), this );
2478
0
        }
2479
2480
33.0k
        if( m_pNumRule )
2481
19.7k
        {
2482
19.7k
            nPoolId = m_pNumRule->GetPoolFormatId();
2483
19.7k
            nHelpId = m_pNumRule->GetPoolHelpId();
2484
19.7k
            if (const OUString* pattern = m_pNumRule->GetPoolHlpFileId() != UCHAR_MAX
2485
19.7k
                                              ? m_rDoc.GetDocPattern(m_pNumRule->GetPoolHlpFileId())
2486
19.7k
                                              : nullptr)
2487
0
                aHelpFile = *pattern;
2488
19.7k
            else
2489
19.7k
                aHelpFile.clear();
2490
19.7k
        }
2491
13.2k
        else if( !bCreate )
2492
13.2k
            nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( UIName(aName), SwGetPoolIdFromName::NumRule );
2493
33.0k
        SetMask( (USER_FMT & sal_uInt16(nPoolId)) ? SfxStyleSearchBits::UserDefined : SfxStyleSearchBits::Auto );
2494
2495
33.0k
        bRet = nullptr != m_pNumRule || SwPoolFormatId::UNKNOWN != nPoolId;
2496
2497
33.0k
        if( bDeleteInfo )
2498
0
            m_pNumRule = nullptr;
2499
33.0k
        break;
2500
2501
0
    case SfxStyleFamily::Table:
2502
0
        m_pTableFormat = lcl_FindTableStyle(m_rDoc, TableStyleName(aName), this, bCreate);
2503
0
        SetMask((m_pTableFormat && m_pTableFormat->IsUserDefined()) ? SfxStyleSearchBits::UserDefined : SfxStyleSearchBits::Auto);
2504
0
        bRet = m_bPhysical = (nullptr != m_pTableFormat);
2505
0
        break;
2506
2507
10.3k
    case SfxStyleFamily::Cell:
2508
10.3k
        m_pBoxFormat = lcl_FindCellStyle(m_rDoc, UIName(aName), this);
2509
10.3k
        bRet = m_bPhysical = (nullptr != m_pBoxFormat);
2510
10.3k
        break;
2511
0
        default:; //prevent warning
2512
3.06M
    }
2513
2514
3.06M
    if( SfxStyleFamily::Char == nFamily ||
2515
2.84M
        SfxStyleFamily::Para == nFamily ||
2516
745k
        SfxStyleFamily::Frame == nFamily )
2517
2.58M
    {
2518
2.58M
        if( pFormat )
2519
2.24M
            nPoolId = pFormat->GetPoolFormatId();
2520
2521
2.58M
        SfxStyleSearchBits _nMask = SfxStyleSearchBits::Auto;
2522
2.58M
        if( pFormat == m_rDoc.GetDfltCharFormat() )
2523
550
            _nMask |= SfxStyleSearchBits::ReadOnly;
2524
2.58M
        else if( USER_FMT & sal_uInt16(nPoolId) )
2525
583k
            _nMask |= SfxStyleSearchBits::UserDefined;
2526
2527
2.58M
        switch ( COLL_GET_RANGE_BITS & sal_uInt16(nPoolId) )
2528
2.58M
        {
2529
522k
        case COLL_TEXT_BITS:     _nMask |= SfxStyleSearchBits::SwText;    break;
2530
1.24M
        case COLL_DOC_BITS :     _nMask |= SfxStyleSearchBits::SwChapter; break;
2531
48.3k
        case COLL_LISTS_BITS:    _nMask |= SfxStyleSearchBits::SwList;    break;
2532
36.5k
        case COLL_REGISTER_BITS: _nMask |= SfxStyleSearchBits::SwIndex;   break;
2533
108k
        case COLL_EXTRA_BITS:    _nMask |= SfxStyleSearchBits::SwExtra;   break;
2534
24.0k
        case COLL_HTML_BITS:     _nMask |= SfxStyleSearchBits::SwHtml;    break;
2535
2.58M
        }
2536
2537
2.58M
        if( pFormat )
2538
2.24M
        {
2539
2.24M
            OSL_ENSURE( m_bPhysical, "Format not found" );
2540
2541
2.24M
            nHelpId = pFormat->GetPoolHelpId();
2542
2.24M
            if (const OUString* pattern = pFormat->GetPoolHlpFileId() != UCHAR_MAX
2543
2.24M
                                              ? m_rDoc.GetDocPattern(pFormat->GetPoolHlpFileId())
2544
2.24M
                                              : nullptr)
2545
0
                aHelpFile = *pattern;
2546
2.24M
            else
2547
2.24M
                aHelpFile.clear();
2548
2549
2.24M
            if( RES_CONDTXTFMTCOLL == pFormat->Which() )
2550
22.2k
                _nMask |= SfxStyleSearchBits::SwCondColl;
2551
2552
2.24M
            if (FillPreview == eFType)
2553
0
            {
2554
0
                assert(o_ppFlatSet);
2555
0
                lcl_SwFormatToFlatItemSet(pFormat, *o_ppFlatSet);
2556
0
            }
2557
2.24M
        }
2558
2559
2.58M
        SetMask( _nMask );
2560
2.58M
    }
2561
3.06M
    if( bDeleteInfo && bFillOnlyInfo )
2562
0
    {
2563
0
        ::sw::UndoGuard const ug(m_rDoc.GetIDocumentUndoRedo());
2564
0
        ::lcl_DeleteInfoStyles( nFamily, aDelArr, m_rDoc );
2565
0
        if (!isModified)
2566
0
        {
2567
0
            m_rDoc.getIDocumentState().ResetModified();
2568
0
        }
2569
0
    }
2570
3.06M
    return bRet;
2571
3.06M
}
2572
2573
// Create new format in Core
2574
void SwDocStyleSheet::Create()
2575
74.9k
{
2576
74.9k
    switch(nFamily)
2577
74.9k
    {
2578
41.3k
        case SfxStyleFamily::Char :
2579
41.3k
            m_pCharFormat = lcl_FindCharFormat( m_rDoc, UIName(aName) );
2580
41.3k
            if( !m_pCharFormat )
2581
41.3k
                m_pCharFormat = m_rDoc.MakeCharFormat(UIName(aName),
2582
41.3k
                                            m_rDoc.GetDfltCharFormat());
2583
41.3k
            m_pCharFormat->SetAuto(false);
2584
41.3k
            break;
2585
2586
26.4k
        case SfxStyleFamily::Para :
2587
26.4k
            m_pColl = lcl_FindParaFormat( m_rDoc, UIName(aName) );
2588
26.4k
            if( !m_pColl )
2589
26.4k
            {
2590
26.4k
                SwTextFormatColl *pPar = (*m_rDoc.GetTextFormatColls())[0];
2591
26.4k
                if( nMask & SfxStyleSearchBits::SwCondColl )
2592
0
                    m_pColl = m_rDoc.MakeCondTextFormatColl( UIName(aName), pPar );
2593
26.4k
                else
2594
26.4k
                    m_pColl = m_rDoc.MakeTextFormatColl( UIName(aName), pPar );
2595
26.4k
            }
2596
26.4k
            break;
2597
2598
186
        case SfxStyleFamily::Frame:
2599
186
            m_pFrameFormat = lcl_FindFrameFormat( m_rDoc, UIName(aName) );
2600
186
            if( !m_pFrameFormat )
2601
186
                m_pFrameFormat = m_rDoc.MakeFrameFormat(UIName(aName), m_rDoc.GetDfltFrameFormat(), false);
2602
2603
186
            break;
2604
2605
3.13k
        case SfxStyleFamily::Page :
2606
3.13k
            m_pDesc = lcl_FindPageDesc( m_rDoc, UIName(aName) );
2607
3.13k
            if( !m_pDesc )
2608
3.13k
            {
2609
3.13k
                m_pDesc = m_rDoc.MakePageDesc(UIName(aName));
2610
3.13k
            }
2611
3.13k
            break;
2612
2613
3.84k
        case SfxStyleFamily::Pseudo:
2614
3.84k
            m_pNumRule = lcl_FindNumRule( m_rDoc, UIName(aName) );
2615
3.84k
            if( !m_pNumRule )
2616
3.84k
            {
2617
3.84k
                const OUString sTmpNm( aName.isEmpty() ? m_rDoc.GetUniqueNumRuleName().toString() : aName );
2618
3.84k
                SwNumRule* pRule = m_rDoc.GetNumRuleTable()[
2619
3.84k
                    m_rDoc.MakeNumRule( UIName(sTmpNm), nullptr,
2620
                                      // #i89178#
2621
3.84k
                                      numfunc::GetDefaultPositionAndSpaceMode() ) ];
2622
3.84k
                pRule->SetAutoRule( false );
2623
3.84k
                if( aName.isEmpty() )
2624
0
                {
2625
                    // #i91400#
2626
0
                    pRule->SetName( UIName(aName), m_rDoc.getIDocumentListsAccess() );
2627
0
                }
2628
3.84k
                m_pNumRule = pRule;
2629
3.84k
            }
2630
3.84k
            break;
2631
2632
0
        case SfxStyleFamily::Table:
2633
0
            if (aName.isEmpty())
2634
0
                return;
2635
0
            m_pTableFormat = lcl_FindTableStyle(m_rDoc, TableStyleName(aName));
2636
0
            if (!m_pTableFormat)
2637
0
            {
2638
0
                m_rDoc.MakeTableStyle(TableStyleName(aName));
2639
0
                m_pTableFormat = m_rDoc.GetTableStyles().FindAutoFormat(TableStyleName(aName));
2640
0
                SAL_WARN_IF(!m_pTableFormat, "sw.ui", "Recently added auto format not found");
2641
0
            }
2642
0
            break;
2643
0
        default:; //prevent warning
2644
74.9k
    }
2645
74.9k
    m_bPhysical = true;
2646
74.9k
    m_aCoreSet.ClearItem();
2647
74.9k
}
2648
2649
SwCharFormat* SwDocStyleSheet::GetCharFormat()
2650
121k
{
2651
121k
    if(!m_bPhysical)
2652
3.22k
        FillStyleSheet( FillPhysical );
2653
121k
    return m_pCharFormat;
2654
121k
}
2655
2656
SwTextFormatColl* SwDocStyleSheet::GetCollection()
2657
2.38M
{
2658
2.38M
    if(!m_bPhysical)
2659
9.62k
        FillStyleSheet( FillPhysical );
2660
2.38M
    return m_pColl;
2661
2.38M
}
2662
2663
const SwPageDesc* SwDocStyleSheet::GetPageDesc()
2664
435k
{
2665
435k
    if(!m_bPhysical)
2666
1.63k
        FillStyleSheet( FillPhysical );
2667
435k
    return m_pDesc;
2668
435k
}
2669
2670
const SwNumRule * SwDocStyleSheet::GetNumRule()
2671
23.4k
{
2672
23.4k
    if(!m_bPhysical)
2673
0
        FillStyleSheet( FillPhysical );
2674
23.4k
    return m_pNumRule;
2675
23.4k
}
2676
2677
2678
void SwDocStyleSheet::SetNumRule(const SwNumRule& rRule)
2679
3.97k
{
2680
3.97k
    OSL_ENSURE(m_pNumRule, "Where is the NumRule");
2681
3.97k
    m_rDoc.ChgNumRuleFormats( rRule );
2682
3.97k
}
2683
2684
SwTableAutoFormat* SwDocStyleSheet::GetTableFormat()
2685
0
{
2686
0
    if(!m_bPhysical)
2687
0
        FillStyleSheet( FillPhysical );
2688
0
    assert(m_pTableFormat && "SwDocStyleSheet table style, SwTableAutoFormat not found");
2689
0
    return m_pTableFormat;
2690
0
}
2691
2692
// re-generate Name AND Family from String
2693
// First() and Next() (see below) insert an identification letter at Pos.1
2694
2695
void SwDocStyleSheet::PresetNameAndFamily(SfxStyleFamily eFamily, const OUString& rName)
2696
34.7k
{
2697
34.7k
    this->nFamily = eFamily;
2698
34.7k
    this->aName = rName;
2699
34.7k
}
2700
2701
// Is the format physically present yet
2702
void SwDocStyleSheet::SetPhysical(bool bPhys)
2703
6.21M
{
2704
6.21M
    m_bPhysical = bPhys;
2705
2706
6.21M
    if(!bPhys)
2707
3.45M
    {
2708
3.45M
        m_pCharFormat = nullptr;
2709
3.45M
        m_pColl    = nullptr;
2710
3.45M
        m_pFrameFormat  = nullptr;
2711
3.45M
        m_pDesc    = nullptr;
2712
        // tdf#172128: SwDocStyleSheetPool::Find() reuses one sheet object. Clear the
2713
        // cached ItemSet so attributes from the previously represented style cannot
2714
        // leak into the next style (and then be exported as direct overrides).
2715
3.45M
        m_aCoreSet.ClearItem();
2716
3.45M
        m_aCoreSet.SetParent(nullptr);
2717
3.45M
        pSet = nullptr;
2718
3.45M
    }
2719
6.21M
}
2720
2721
SwFrameFormat* SwDocStyleSheet::GetFrameFormat()
2722
215k
{
2723
215k
    if(!m_bPhysical)
2724
1.91k
        FillStyleSheet( FillPhysical );
2725
215k
    return m_pFrameFormat;
2726
215k
}
2727
2728
bool SwDocStyleSheet::IsUsed() const
2729
0
{
2730
0
    if( !m_bPhysical )
2731
0
    {
2732
0
        SwDocStyleSheet* pThis = const_cast<SwDocStyleSheet*>(this);
2733
0
        pThis->FillStyleSheet( FillOnlyName );
2734
0
    }
2735
2736
0
    if( !m_bPhysical )
2737
0
        return false;
2738
2739
0
    const sw::BroadcastingModify* pMod;
2740
0
    switch( nFamily )
2741
0
    {
2742
0
    case SfxStyleFamily::Para : pMod = m_pColl;      break;
2743
0
    case SfxStyleFamily::Frame: pMod = m_pFrameFormat;    break;
2744
0
    case SfxStyleFamily::Char:
2745
0
            return m_pCharFormat->IsUsed();
2746
0
    case SfxStyleFamily::Page:
2747
0
            return m_pDesc->IsUsed();
2748
2749
0
    case SfxStyleFamily::Pseudo:
2750
0
            return m_pNumRule && m_rDoc.IsUsed(*m_pNumRule);
2751
2752
0
    case SfxStyleFamily::Table:
2753
0
            return m_pTableFormat && m_rDoc.IsUsed( *m_pTableFormat );
2754
2755
0
    default:
2756
0
        OSL_ENSURE(false, "unknown style family");
2757
0
        return false;
2758
0
    }
2759
2760
0
    if (m_rDoc.IsUsed(*pMod))
2761
0
        return true;
2762
2763
0
    SfxStyleSheetIterator aIter(static_cast<SwDocStyleSheetPool*>(m_pPool)->GetEEStyleSheetPool(), nFamily,
2764
0
                                SfxStyleSearchBits::Used);
2765
0
    return aIter.Find(GetName()) != nullptr;
2766
0
}
2767
2768
OUString SwDocStyleSheet::GetUsedBy()
2769
0
{
2770
0
    return m_pNumRule ? m_pNumRule->MakeParagraphStyleListString() : OUString();
2771
0
}
2772
2773
sal_uInt32  SwDocStyleSheet::GetHelpId( OUString& rFile )
2774
0
{
2775
0
    sal_uInt32 nId = 0;
2776
0
    SwPoolFormatId nPoolId = SwPoolFormatId::ZERO;
2777
0
    unsigned char nFileId = UCHAR_MAX;
2778
2779
0
    rFile = "swrhlppi.hlp";
2780
2781
0
    const SwFormat* pTmpFormat = nullptr;
2782
0
    switch( nFamily )
2783
0
    {
2784
0
    case SfxStyleFamily::Char :
2785
0
        if( !m_pCharFormat &&
2786
0
            nullptr == (m_pCharFormat = lcl_FindCharFormat( m_rDoc, UIName(aName), nullptr, false )) )
2787
0
        {
2788
0
            SwPoolFormatId nTmpId = SwStyleNameMapper::GetPoolIdFromUIName( UIName(aName), SwGetPoolIdFromName::ChrFmt );
2789
0
            return SwPoolFormatId::UNKNOWN == nTmpId ? 0 : sal_uInt16(nTmpId);
2790
0
        }
2791
0
        pTmpFormat = m_pCharFormat;
2792
0
        break;
2793
2794
0
    case SfxStyleFamily::Para:
2795
0
        if( !m_pColl &&
2796
0
            nullptr == ( m_pColl = lcl_FindParaFormat( m_rDoc, UIName(aName), nullptr, false )) )
2797
0
        {
2798
0
            SwPoolFormatId nTmpId = SwStyleNameMapper::GetPoolIdFromUIName( UIName(aName), SwGetPoolIdFromName::TxtColl );
2799
0
            return SwPoolFormatId::UNKNOWN == nTmpId ? 0 : sal_uInt16(nTmpId);
2800
0
        }
2801
0
        pTmpFormat = m_pColl;
2802
0
        break;
2803
2804
0
    case SfxStyleFamily::Frame:
2805
0
        if( !m_pFrameFormat &&
2806
0
            nullptr == ( m_pFrameFormat = lcl_FindFrameFormat( m_rDoc, UIName(aName), nullptr, false ) ) )
2807
0
        {
2808
0
            SwPoolFormatId nTmpId = SwStyleNameMapper::GetPoolIdFromUIName( UIName(aName), SwGetPoolIdFromName::FrmFmt );
2809
0
            return SwPoolFormatId::UNKNOWN == nTmpId ? 0 : sal_uInt16(nTmpId);
2810
0
        }
2811
0
        pTmpFormat = m_pFrameFormat;
2812
0
        break;
2813
2814
0
    case SfxStyleFamily::Page:
2815
0
        if( !m_pDesc &&
2816
0
            nullptr == ( m_pDesc = lcl_FindPageDesc( m_rDoc, UIName(aName), nullptr, false ) ) )
2817
0
        {
2818
0
            SwPoolFormatId nTmpId = SwStyleNameMapper::GetPoolIdFromUIName( UIName(aName), SwGetPoolIdFromName::PageDesc );
2819
0
            return SwPoolFormatId::UNKNOWN == nTmpId ? 0 : sal_uInt16(nTmpId);
2820
0
        }
2821
2822
0
        nId = m_pDesc->GetPoolHelpId();
2823
0
        nFileId = m_pDesc->GetPoolHlpFileId();
2824
0
        nPoolId = m_pDesc->GetPoolFormatId();
2825
0
        break;
2826
2827
0
    case SfxStyleFamily::Pseudo:
2828
0
        if( !m_pNumRule &&
2829
0
            nullptr == ( m_pNumRule = lcl_FindNumRule( m_rDoc, UIName(aName), nullptr, false ) ) )
2830
0
        {
2831
0
            SwPoolFormatId nTmpId = SwStyleNameMapper::GetPoolIdFromUIName( UIName(aName), SwGetPoolIdFromName::NumRule );
2832
0
            return SwPoolFormatId::UNKNOWN == nTmpId ? 0 : sal_uInt16(nTmpId);
2833
0
        }
2834
2835
0
        nId = m_pNumRule->GetPoolHelpId();
2836
0
        nFileId = m_pNumRule->GetPoolHlpFileId();
2837
0
        nPoolId = m_pNumRule->GetPoolFormatId();
2838
0
        break;
2839
2840
0
    default:
2841
0
        OSL_ENSURE(false, "unknown style family");
2842
0
        return 0;
2843
0
    }
2844
2845
0
    if( pTmpFormat )
2846
0
    {
2847
0
        nId = pTmpFormat->GetPoolHelpId();
2848
0
        nFileId = pTmpFormat->GetPoolHlpFileId();
2849
0
        nPoolId = pTmpFormat->GetPoolFormatId();
2850
0
    }
2851
2852
0
    if( UCHAR_MAX != nFileId )
2853
0
    {
2854
0
        const OUString *pTemplate = m_rDoc.GetDocPattern( nFileId );
2855
0
        if( pTemplate )
2856
0
        {
2857
0
            rFile = *pTemplate;
2858
0
        }
2859
0
    }
2860
0
    else if( !IsPoolUserFormat( nPoolId ) )
2861
0
    {
2862
0
        nId = sal_uInt16(nPoolId);
2863
0
    }
2864
2865
    // because SFX acts like that, with HelpId:
2866
0
    if( USHRT_MAX == nId )
2867
0
        nId = 0;        // don't show Help accordingly
2868
2869
0
    return nId;
2870
0
}
2871
2872
void  SwDocStyleSheet::SetHelpId( const OUString& r, sal_uInt32 nId )
2873
0
{
2874
0
    sal_uInt8 nFileId = static_cast< sal_uInt8 >(m_rDoc.SetDocPattern( r ));
2875
2876
0
    SwFormat* pTmpFormat = nullptr;
2877
0
    switch( nFamily )
2878
0
    {
2879
0
    case SfxStyleFamily::Char : pTmpFormat = m_pCharFormat;    break;
2880
0
    case SfxStyleFamily::Para : pTmpFormat = m_pColl;       break;
2881
0
    case SfxStyleFamily::Frame: pTmpFormat = m_pFrameFormat;     break;
2882
0
    case SfxStyleFamily::Page :
2883
0
        const_cast<SwPageDesc*>(m_pDesc)->SetPoolHelpId( nId );
2884
0
        const_cast<SwPageDesc*>(m_pDesc)->SetPoolHlpFileId( nFileId );
2885
0
        break;
2886
2887
0
    case SfxStyleFamily::Pseudo:
2888
0
        const_cast<SwNumRule*>(m_pNumRule)->SetPoolHelpId( nId );
2889
0
        const_cast<SwNumRule*>(m_pNumRule)->SetPoolHlpFileId( nFileId );
2890
0
        break;
2891
2892
0
    default:
2893
0
        OSL_ENSURE(false, "unknown style family");
2894
0
        return ;
2895
0
    }
2896
0
    if( pTmpFormat )
2897
0
    {
2898
0
        pTmpFormat->SetPoolHelpId( nId );
2899
0
        pTmpFormat->SetPoolHlpFileId( nFileId );
2900
0
    }
2901
0
}
2902
2903
sal_Int32 SwDocStyleSheet::GetSpotlightId()
2904
0
{
2905
0
    if (nFamily == SfxStyleFamily::Para)
2906
0
    {
2907
0
        SwTextFormatColl* pColl = m_pColl ?
2908
0
            m_pColl : m_rDoc.FindTextFormatCollByName(UIName(aName));
2909
0
        return pColl ?  m_rDoc.GetTextFormatColls()->GetPos(pColl) : -1;
2910
0
    }
2911
2912
0
    if (nFamily == SfxStyleFamily::Char)
2913
0
    {
2914
0
        SwCharFormat* pCharFormat = m_pCharFormat
2915
0
            ? m_pCharFormat : m_rDoc.FindCharFormatByName(UIName(aName));
2916
0
        return pCharFormat ?  m_rDoc.GetCharFormats()->GetPos(pCharFormat) : -1;
2917
0
    }
2918
2919
0
    return SfxStyleSheetBase::GetSpotlightId();
2920
0
}
2921
2922
// methods for DocStyleSheetPool
2923
SwDocStyleSheetPool::SwDocStyleSheetPool( SwDoc& rDocument, bool bOrg )
2924
80.9k
    : SfxStyleSheetBasePool(rDocument.GetAttrPool())
2925
80.9k
    , mxStyleSheet(new SwDocStyleSheet(rDocument, *this))
2926
80.9k
    , mxEEStyleSheetPool(new EEStyleSheetPool(this))
2927
80.9k
    , m_rDoc(rDocument)
2928
80.9k
{
2929
80.9k
    m_bOrganizer = bOrg;
2930
80.9k
}
2931
2932
SwDocStyleSheetPool::~SwDocStyleSheetPool()
2933
80.9k
{
2934
80.9k
}
2935
2936
SfxStyleSheetBase&   SwDocStyleSheetPool::Make( const OUString&   rName,
2937
                                                SfxStyleFamily  eFam,
2938
                                                SfxStyleSearchBits _nMask,
2939
                                                const OUString& rParentStyleSheetName)
2940
74.9k
{
2941
74.9k
    mxStyleSheet->PresetName(rName);
2942
74.9k
    mxStyleSheet->PresetParent(OUString());
2943
74.9k
    mxStyleSheet->PresetFollow(OUString());
2944
74.9k
    mxStyleSheet->SetMask(_nMask) ;
2945
74.9k
    mxStyleSheet->SetFamily(eFam);
2946
74.9k
    mxStyleSheet->SetPhysical(true);
2947
74.9k
    mxStyleSheet->Create();
2948
74.9k
    mxStyleSheet->SetParent(rParentStyleSheetName);
2949
2950
74.9k
    return *mxStyleSheet;
2951
74.9k
}
2952
2953
rtl::Reference<SfxStyleSheetBase> SwDocStyleSheetPool::Create( const SfxStyleSheetBase& /*rOrg*/)
2954
0
{
2955
0
    OSL_ENSURE(false , "Create in SW-Stylesheet-Pool not possible" );
2956
0
    return nullptr;
2957
0
}
2958
2959
rtl::Reference<SfxStyleSheetBase> SwDocStyleSheetPool::Create( const OUString &,
2960
                                                  SfxStyleFamily, SfxStyleSearchBits, const OUString& )
2961
0
{
2962
0
    OSL_ENSURE( false, "Create in SW-Stylesheet-Pool not possible" );
2963
0
    return nullptr;
2964
0
}
2965
2966
std::unique_ptr<SfxStyleSheetIterator> SwDocStyleSheetPool::CreateIterator( SfxStyleFamily eFam, SfxStyleSearchBits _nMask )
2967
1.45k
{
2968
1.45k
    return std::make_unique<SwStyleSheetIterator>(*this, eFam, _nMask);
2969
1.45k
}
2970
2971
void SwDocStyleSheetPool::dispose()
2972
80.9k
{
2973
80.9k
    mxStyleSheet.clear();
2974
80.9k
    mxEEStyleSheetPool.clear();
2975
80.9k
}
2976
2977
void SwDocStyleSheetPool::Remove( SfxStyleSheetBase* pStyle)
2978
0
{
2979
0
    if( !pStyle )
2980
0
        return;
2981
2982
0
    bool bBroadcast = true;
2983
0
    SwImplShellAction aTmpSh( m_rDoc );
2984
0
    const UIName sName(pStyle->GetName());
2985
0
    switch( pStyle->GetFamily() )
2986
0
    {
2987
0
    case SfxStyleFamily::Char:
2988
0
        {
2989
0
            SwCharFormat* pFormat = lcl_FindCharFormat(m_rDoc, sName, nullptr, false );
2990
0
            if(pFormat)
2991
0
                m_rDoc.DelCharFormat(pFormat);
2992
0
        }
2993
0
        break;
2994
0
    case SfxStyleFamily::Para:
2995
0
        {
2996
0
            SwTextFormatColl* pColl = lcl_FindParaFormat(m_rDoc, sName, nullptr, false );
2997
0
            if(pColl)
2998
0
                m_rDoc.DelTextFormatColl(pColl);
2999
0
        }
3000
0
        break;
3001
0
    case SfxStyleFamily::Frame:
3002
0
        {
3003
0
            SwFrameFormat* pFormat = lcl_FindFrameFormat(m_rDoc, sName, nullptr, false );
3004
0
            if(pFormat)
3005
0
                m_rDoc.DelFrameFormat(pFormat);
3006
0
        }
3007
0
        break;
3008
0
    case SfxStyleFamily::Page :
3009
0
        {
3010
0
            m_rDoc.DelPageDesc(sName);
3011
0
        }
3012
0
        break;
3013
3014
0
    case SfxStyleFamily::Pseudo:
3015
0
        {
3016
0
            if( !m_rDoc.DelNumRule( sName ) )
3017
                // Only send Broadcast, when something was deleted
3018
0
                bBroadcast = false;
3019
0
        }
3020
0
        break;
3021
3022
0
    case SfxStyleFamily::Table:
3023
0
        {
3024
0
            m_rDoc.DelTableStyle(TableStyleName(sName.toString()));
3025
0
        }
3026
0
        break;
3027
3028
0
    default:
3029
0
        OSL_ENSURE(false, "unknown style family");
3030
0
        bBroadcast = false;
3031
0
    }
3032
3033
0
    if( bBroadcast )
3034
0
        Broadcast( SfxStyleSheetHint( SfxHintId::StyleSheetErased, *pStyle ) );
3035
0
}
3036
3037
SfxStyleSheetBase* SwDocStyleSheetPool::Find(const OUString& rName,
3038
                                             SfxStyleFamily eFam, SfxStyleSearchBits n)
3039
3.03M
{
3040
3.03M
    SfxStyleSearchBits nSMask = n;
3041
3.03M
    if( SfxStyleFamily::Para == eFam &&  m_rDoc.getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE) )
3042
0
    {
3043
        // then only HTML-Templates are of interest
3044
0
        if( SfxStyleSearchBits::All == nSMask )
3045
0
            nSMask = SfxStyleSearchBits::SwHtml | SfxStyleSearchBits::UserDefined | SfxStyleSearchBits::Used;
3046
0
        else
3047
0
            nSMask &= SfxStyleSearchBits::Used | SfxStyleSearchBits::UserDefined |
3048
0
                                SfxStyleSearchBits::SwCondColl | SfxStyleSearchBits::SwHtml;
3049
0
        if( nSMask == SfxStyleSearchBits::Auto )
3050
0
            nSMask = SfxStyleSearchBits::SwHtml;
3051
0
    }
3052
3053
3.03M
    const bool bSearchUsed = ( n != SfxStyleSearchBits::All && n & SfxStyleSearchBits::Used );
3054
3.03M
    const sw::BroadcastingModify* pMod = nullptr;
3055
3056
3.03M
    mxStyleSheet->SetPhysical( false );
3057
3.03M
    mxStyleSheet->PresetName( rName );
3058
3.03M
    mxStyleSheet->SetFamily( eFam );
3059
3.03M
    bool bFnd = mxStyleSheet->FillStyleSheet( SwDocStyleSheet::FillOnlyName );
3060
3061
3.03M
    if( mxStyleSheet->IsPhysical() )
3062
2.66M
    {
3063
2.66M
        switch( eFam )
3064
2.66M
        {
3065
107k
        case SfxStyleFamily::Char:
3066
107k
            pMod = mxStyleSheet->GetCharFormat();
3067
107k
            break;
3068
3069
1.90M
        case SfxStyleFamily::Para:
3070
1.90M
            pMod = mxStyleSheet->GetCollection();
3071
1.90M
            break;
3072
3073
210k
        case SfxStyleFamily::Frame:
3074
210k
            pMod = mxStyleSheet->GetFrameFormat();
3075
210k
            break;
3076
3077
417k
        case SfxStyleFamily::Page:
3078
417k
            pMod = mxStyleSheet->GetPageDesc();
3079
417k
            break;
3080
3081
19.1k
        case SfxStyleFamily::Pseudo:
3082
19.1k
            {
3083
19.1k
                const SwNumRule* pRule = mxStyleSheet->GetNumRule();
3084
19.1k
                if( pRule &&
3085
19.1k
                    !bSearchUsed &&
3086
19.1k
                    (( nSMask & ~SfxStyleSearchBits::Used) == SfxStyleSearchBits::UserDefined
3087
19.1k
                            ? !(sal_uInt16(pRule->GetPoolFormatId()) & USER_FMT)
3088
                                // searched for used and found none
3089
19.1k
                            : bSearchUsed ))
3090
0
                    bFnd = false;
3091
19.1k
            }
3092
19.1k
            break;
3093
3094
0
        case SfxStyleFamily::Table:
3095
6.95k
        case SfxStyleFamily::Cell:
3096
6.95k
            break;
3097
0
        default:
3098
0
            OSL_ENSURE(false, "unknown style family");
3099
2.66M
        }
3100
2.66M
    }
3101
3102
    // then evaluate the mask:
3103
3.03M
    if( pMod && !bSearchUsed )
3104
2.63M
    {
3105
2.63M
        const SwPoolFormatId nId = SfxStyleFamily::Page == eFam
3106
2.63M
                        ? static_cast<const SwPageDesc*>(pMod)->GetPoolFormatId()
3107
2.63M
                        : static_cast<const SwFormat*>(pMod)->GetPoolFormatId();
3108
3109
2.63M
        if( ( nSMask & ~SfxStyleSearchBits::Used) == SfxStyleSearchBits::UserDefined
3110
0
            && !(sal_uInt16(nId) & USER_FMT) )
3111
                // searched for used and found none
3112
0
                bFnd = false;
3113
2.63M
    }
3114
3.03M
    return bFnd ? mxStyleSheet.get() : nullptr;
3115
3.03M
}
3116
3117
SwStyleSheetIterator::SwStyleSheetIterator(SwDocStyleSheetPool& rBase,
3118
                                SfxStyleFamily eFam, SfxStyleSearchBits n )
3119
1.45k
    : SfxStyleSheetIterator(&rBase, eFam, n)
3120
1.45k
    , mxIterSheet(new SwDocStyleSheet(rBase.GetDoc(), rBase))
3121
1.45k
    , mxStyleSheet(new SwDocStyleSheet(rBase.GetDoc(), rBase))
3122
1.45k
{
3123
1.45k
    m_bFirstCalled = false;
3124
1.45k
    m_nLastPos = 0;
3125
1.45k
    StartListening(rBase);
3126
1.45k
}
3127
3128
SwStyleSheetIterator::~SwStyleSheetIterator()
3129
1.45k
{
3130
1.45k
    EndListening( *mxIterSheet->GetPool() );
3131
1.45k
}
3132
3133
sal_Int32  SwStyleSheetIterator::Count()
3134
0
{
3135
    // let the list fill correctly!!
3136
0
    if( !m_bFirstCalled )
3137
0
        First();
3138
0
    return m_aLst.size();
3139
0
}
3140
3141
SfxStyleSheetBase* SwStyleSheetIterator::operator[]( sal_Int32 nIdx )
3142
0
{
3143
    // found
3144
0
    if( !m_bFirstCalled )
3145
0
        First();
3146
0
    auto const & rEntry = m_aLst[ nIdx ];
3147
0
    mxStyleSheet->PresetNameAndFamily( rEntry.first, rEntry.second.toString() );
3148
0
    mxStyleSheet->SetPhysical( false );
3149
0
    mxStyleSheet->FillStyleSheet( SwDocStyleSheet::FillOnlyName );
3150
3151
0
    return mxStyleSheet.get();
3152
0
}
3153
3154
SfxStyleSheetBase*  SwStyleSheetIterator::First()
3155
1.45k
{
3156
    // Delete old list
3157
1.45k
    m_bFirstCalled = true;
3158
1.45k
    m_nLastPos = 0;
3159
1.45k
    m_aLst.clear();
3160
3161
    // Delete current
3162
1.45k
    mxIterSheet->Reset();
3163
3164
1.45k
    const SwDoc& rDoc = static_cast<const SwDocStyleSheetPool*>(pBasePool)->GetDoc();
3165
1.45k
    SfxStyleSearchBits nSrchMask = nMask;
3166
1.45k
    const bool bIsSearchUsed = SearchUsed();
3167
3168
1.45k
    bool bSearchHidden( nMask & SfxStyleSearchBits::Hidden );
3169
1.45k
    bool bOnlyHidden = nMask == SfxStyleSearchBits::Hidden;
3170
1.45k
    if (!bOnlyHidden)
3171
1.45k
        nSrchMask = nSrchMask & ~SfxStyleSearchBits::Hidden;
3172
1.45k
    bool bFavourite = nMask == SfxStyleSearchBits::Favourite;
3173
3174
1.45k
    const bool bOrganizer = static_cast<const SwDocStyleSheetPool*>(pBasePool)->IsOrganizerMode();
3175
1.45k
    bool bAll = ( nSrchMask & SfxStyleSearchBits::AllVisible ) == SfxStyleSearchBits::AllVisible;
3176
3177
1.45k
    if( nSearchFamily == SfxStyleFamily::Char
3178
511
     || nSearchFamily == SfxStyleFamily::All )
3179
942
    {
3180
942
        const size_t nArrLen = rDoc.GetCharFormats()->size();
3181
6.47k
        for( size_t i = 0; i < nArrLen; i++ )
3182
5.53k
        {
3183
5.53k
            SwCharFormat* pFormat = (*rDoc.GetCharFormats())[ i ];
3184
3185
            // tdf#159168: default char format should be considered 'applied'/used, even if it apparently is not
3186
5.53k
            const bool bUsed = bIsSearchUsed && (bOrganizer || pFormat->IsUsed() || pFormat == rDoc.GetDfltCharFormat());
3187
5.53k
            if( ( !bSearchHidden && pFormat->IsHidden() && !bUsed ) || ( pFormat->IsDefault() && pFormat != rDoc.GetDfltCharFormat() ) )
3188
0
                continue;
3189
3190
5.53k
            if ( nSrchMask == SfxStyleSearchBits::Hidden && !pFormat->IsHidden( ) )
3191
0
                continue;
3192
3193
5.53k
            if( !bUsed )
3194
5.53k
            {
3195
                // Standard is no User template
3196
5.53k
                const SwPoolFormatId nId =
3197
5.53k
                        rDoc.GetDfltCharFormat() == pFormat
3198
5.53k
                        ? SwPoolFormatId::CHR_INET_NORMAL
3199
5.53k
                        : pFormat->GetPoolFormatId();
3200
5.53k
                if( (nSrchMask & ~SfxStyleSearchBits::Used) == SfxStyleSearchBits::UserDefined
3201
5.53k
                    ? !(sal_uInt16(nId) & USER_FMT)
3202
                        // searched for used and found none
3203
5.53k
                    : bIsSearchUsed )
3204
0
                {
3205
0
                    continue;
3206
0
                }
3207
3208
5.53k
                if(  rDoc.getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE) && !(sal_uInt16(nId) & USER_FMT) &&
3209
0
                    ( SwPoolFormatId::CHR_HTML_BEGIN > nId || nId >= SwPoolFormatId::CHR_HTML_END ) &&
3210
0
                    SwPoolFormatId::CHR_INET_NORMAL != nId &&
3211
0
                    SwPoolFormatId::CHR_INET_VISIT != nId &&
3212
0
                    SwPoolFormatId::CHR_FOOTNOTE  != nId &&
3213
0
                    SwPoolFormatId::CHR_ENDNOTE != nId )
3214
0
                    continue;
3215
5.53k
            }
3216
3217
5.53k
            m_aLst.Append( SfxStyleFamily::Char, pFormat == rDoc.GetDfltCharFormat()
3218
5.53k
                        ? UIName(SwResId(STR_POOLCHR_STANDARD))
3219
5.53k
                        : pFormat->GetName() );
3220
5.53k
        }
3221
3222
        // PoolFormat
3223
942
        if( bAll )
3224
942
        {
3225
942
            if( ! rDoc.getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE) )
3226
942
                AppendStyleList(SwStyleNameMapper::GetChrFormatUINameArray(),
3227
942
                                bIsSearchUsed, bSearchHidden, bOnlyHidden,
3228
942
                                SwGetPoolIdFromName::ChrFmt, SfxStyleFamily::Char);
3229
0
            else
3230
0
            {
3231
0
                m_aLst.Append( SfxStyleFamily::Char, UIName(SwStyleNameMapper::GetChrFormatUINameArray()[
3232
0
                        sal_uInt16(SwPoolFormatId::CHR_INET_NORMAL - SwPoolFormatId::CHR_BEGIN) ]) );
3233
0
                m_aLst.Append( SfxStyleFamily::Char, UIName(SwStyleNameMapper::GetChrFormatUINameArray()[
3234
0
                        sal_uInt16(SwPoolFormatId::CHR_INET_VISIT - SwPoolFormatId::CHR_BEGIN) ]) );
3235
0
                m_aLst.Append( SfxStyleFamily::Char, UIName(SwStyleNameMapper::GetChrFormatUINameArray()[
3236
0
                        sal_uInt16(SwPoolFormatId::CHR_ENDNOTE - SwPoolFormatId::CHR_BEGIN) ]) );
3237
0
                m_aLst.Append( SfxStyleFamily::Char, UIName(SwStyleNameMapper::GetChrFormatUINameArray()[
3238
0
                        sal_uInt16(SwPoolFormatId::CHR_FOOTNOTE - SwPoolFormatId::CHR_BEGIN) ]) );
3239
0
            }
3240
942
            AppendStyleList(SwStyleNameMapper::GetHTMLChrFormatUINameArray(),
3241
942
                                bIsSearchUsed, bSearchHidden, bOnlyHidden,
3242
942
                                SwGetPoolIdFromName::ChrFmt, SfxStyleFamily::Char);
3243
942
        }
3244
942
    }
3245
3246
1.45k
    if( nSearchFamily == SfxStyleFamily::Para ||
3247
1.45k
        nSearchFamily == SfxStyleFamily::All )
3248
0
    {
3249
0
        SfxStyleSearchBits nSMask = nSrchMask;
3250
0
        if(  rDoc.getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE) )
3251
0
        {
3252
            // then only HTML-Template are of interest
3253
0
            if( SfxStyleSearchBits::AllVisible == ( nSMask & SfxStyleSearchBits::AllVisible ) )
3254
0
                nSMask = SfxStyleSearchBits::SwHtml | SfxStyleSearchBits::UserDefined |
3255
0
                            SfxStyleSearchBits::Used;
3256
0
            else
3257
0
                nSMask &= SfxStyleSearchBits::Used | SfxStyleSearchBits::UserDefined |
3258
0
                                SfxStyleSearchBits::SwCondColl | SfxStyleSearchBits::SwHtml;
3259
0
            if( nSMask == SfxStyleSearchBits::Auto )
3260
0
                nSMask = SfxStyleSearchBits::SwHtml;
3261
0
        }
3262
3263
0
        const size_t nArrLen = rDoc.GetTextFormatColls()->size();
3264
0
        for( size_t i = 0; i < nArrLen; i++ )
3265
0
        {
3266
0
            SwTextFormatColl* pColl = (*rDoc.GetTextFormatColls())[ i ];
3267
3268
0
            const bool bUsed = bOrganizer || rDoc.IsUsed(*pColl) || IsUsedInComments(pColl->GetName());
3269
0
            if ( ( !bSearchHidden && pColl->IsHidden( ) && !bUsed && !bFavourite ) || pColl->IsDefault() )
3270
0
                continue;
3271
3272
0
            if ( nSMask == SfxStyleSearchBits::Hidden && !pColl->IsHidden( ) )
3273
0
                continue;
3274
3275
0
            if( !(bIsSearchUsed && bUsed ))
3276
0
            {
3277
0
                const SwPoolFormatId nId = pColl->GetPoolFormatId();
3278
0
                auto tmpMask = nSMask & ~SfxStyleSearchBits::Used;
3279
0
                if (tmpMask == SfxStyleSearchBits::UserDefined)
3280
0
                {
3281
0
                    if(!IsPoolUserFormat(nId)) continue;
3282
0
                }
3283
0
                else if (tmpMask == SfxStyleSearchBits::SwText)
3284
0
                {
3285
0
                    if((sal_uInt16(nId) & COLL_GET_RANGE_BITS) != COLL_TEXT_BITS) continue;
3286
0
                }
3287
0
                else if (tmpMask == SfxStyleSearchBits::SwChapter)
3288
0
                {
3289
0
                    if((sal_uInt16(nId) & COLL_GET_RANGE_BITS) != COLL_DOC_BITS) continue;
3290
0
                }
3291
0
                else if (tmpMask == SfxStyleSearchBits::SwList)
3292
0
                {
3293
0
                    if((sal_uInt16(nId) & COLL_GET_RANGE_BITS) != COLL_LISTS_BITS) continue;
3294
0
                }
3295
0
                else if (tmpMask == SfxStyleSearchBits::SwIndex)
3296
0
                {
3297
0
                    if((sal_uInt16(nId) & COLL_GET_RANGE_BITS) != COLL_REGISTER_BITS) continue;
3298
0
                }
3299
0
                else if (tmpMask == SfxStyleSearchBits::SwExtra)
3300
0
                {
3301
0
                    if((sal_uInt16(nId) & COLL_GET_RANGE_BITS) != COLL_EXTRA_BITS) continue;
3302
0
                }
3303
0
                else if (tmpMask == (SfxStyleSearchBits::SwHtml | SfxStyleSearchBits::UserDefined)
3304
0
                         || tmpMask == SfxStyleSearchBits::SwHtml)
3305
0
                {
3306
0
                    if((tmpMask & SfxStyleSearchBits::UserDefined) && IsPoolUserFormat(nId))
3307
0
                        ; // do nothing
3308
0
                    else if( (sal_uInt16(nId) & COLL_GET_RANGE_BITS) != COLL_HTML_BITS)
3309
0
                    {
3310
                        // but some we also want to see in this section
3311
0
                        bool bContinue = true;
3312
0
                        switch( nId )
3313
0
                        {
3314
0
                        case SwPoolFormatId::COLL_SEND_ADDRESS: //  --> ADDRESS
3315
0
                        case SwPoolFormatId::COLL_TABLE_HDLN:   //  --> TH
3316
0
                        case SwPoolFormatId::COLL_TABLE:        //  --> TD
3317
0
                        case SwPoolFormatId::COLL_TEXT:         //  --> P
3318
0
                        case SwPoolFormatId::COLL_HEADLINE_BASE://  --> H
3319
0
                        case SwPoolFormatId::COLL_HEADLINE1:    //  --> H1
3320
0
                        case SwPoolFormatId::COLL_HEADLINE2:    //  --> H2
3321
0
                        case SwPoolFormatId::COLL_HEADLINE3:    //  --> H3
3322
0
                        case SwPoolFormatId::COLL_HEADLINE4:    //  --> H4
3323
0
                        case SwPoolFormatId::COLL_HEADLINE5:    //  --> H5
3324
0
                        case SwPoolFormatId::COLL_HEADLINE6:    //  --> H6
3325
0
                        case SwPoolFormatId::COLL_STANDARD:     //  --> P
3326
0
                        case SwPoolFormatId::COLL_FOOTNOTE:
3327
0
                        case SwPoolFormatId::COLL_ENDNOTE:
3328
0
                            bContinue = false;
3329
0
                            break;
3330
0
                        default: break;
3331
0
                        }
3332
0
                        if( bContinue )
3333
0
                            continue;
3334
0
                    }
3335
0
                }
3336
0
                else if (tmpMask == SfxStyleSearchBits::SwCondColl)
3337
0
                {
3338
0
                    if( RES_CONDTXTFMTCOLL != pColl->Which() ) continue;
3339
0
                }
3340
0
                else
3341
0
                {
3342
0
                    if ( tmpMask & SfxStyleSearchBits::Favourite )
3343
0
                    {
3344
0
                        SwFormat* pFormat = rDoc.FindTextFormatCollByName( pColl->GetName() );
3345
0
                        if (!(pFormat && pFormat->IsFavourite().value_or(false))) continue;
3346
0
                    }
3347
3348
                    // searched for used and found none
3349
0
                    if( bIsSearchUsed )
3350
0
                        continue;
3351
0
                }
3352
0
            }
3353
0
            m_aLst.Append( SfxStyleFamily::Para, pColl->GetName() );
3354
0
        }
3355
3356
0
        bAll = ( nSMask & SfxStyleSearchBits::AllVisible ) == SfxStyleSearchBits::AllVisible;
3357
0
        if ( bAll || (nSMask & ~SfxStyleSearchBits::Used) == SfxStyleSearchBits::SwText )
3358
0
            AppendStyleList(SwStyleNameMapper::GetTextUINameArray(),
3359
0
                            bIsSearchUsed, bSearchHidden, bOnlyHidden, SwGetPoolIdFromName::TxtColl, SfxStyleFamily::Para );
3360
0
        if ( bAll || (nSMask & ~SfxStyleSearchBits::Used) == SfxStyleSearchBits::SwChapter )
3361
0
            AppendStyleList(SwStyleNameMapper::GetDocUINameArray(),
3362
0
                            bIsSearchUsed, bSearchHidden, bOnlyHidden, SwGetPoolIdFromName::TxtColl, SfxStyleFamily::Para ) ;
3363
0
        if ( bAll || (nSMask & ~SfxStyleSearchBits::Used) == SfxStyleSearchBits::SwList )
3364
0
            AppendStyleList(SwStyleNameMapper::GetListsUINameArray(),
3365
0
                            bIsSearchUsed, bSearchHidden, bOnlyHidden, SwGetPoolIdFromName::TxtColl, SfxStyleFamily::Para ) ;
3366
0
        if ( bAll || (nSMask & ~SfxStyleSearchBits::Used) == SfxStyleSearchBits::SwIndex )
3367
0
            AppendStyleList(SwStyleNameMapper::GetRegisterUINameArray(),
3368
0
                            bIsSearchUsed, bSearchHidden, bOnlyHidden, SwGetPoolIdFromName::TxtColl, SfxStyleFamily::Para ) ;
3369
0
        if ( bAll || (nSMask & ~SfxStyleSearchBits::Used) == SfxStyleSearchBits::SwExtra )
3370
0
            AppendStyleList(SwStyleNameMapper::GetExtraUINameArray(),
3371
0
                            bIsSearchUsed, bSearchHidden, bOnlyHidden, SwGetPoolIdFromName::TxtColl, SfxStyleFamily::Para ) ;
3372
0
        if ( bAll || (nSMask & ~SfxStyleSearchBits::Used) == SfxStyleSearchBits::SwCondColl )
3373
0
        {
3374
0
            if( !bIsSearchUsed ||
3375
0
                rDoc.getIDocumentStylePoolAccess().IsPoolTextCollUsed( SwPoolFormatId::COLL_TEXT ))
3376
0
                m_aLst.Append( SfxStyleFamily::Para, UIName(SwStyleNameMapper::GetTextUINameArray()[
3377
0
                        sal_uInt16(SwPoolFormatId::COLL_TEXT - SwPoolFormatId::COLL_TEXT_BEGIN) ]) );
3378
0
        }
3379
0
        if ( bAll ||
3380
0
            (nSMask & ~SfxStyleSearchBits::Used) == SfxStyleSearchBits::SwHtml ||
3381
0
            (nSMask & ~SfxStyleSearchBits::Used) ==
3382
0
                        (SfxStyleSearchBits::SwHtml | SfxStyleSearchBits::UserDefined) )
3383
0
        {
3384
0
            AppendStyleList(SwStyleNameMapper::GetHTMLUINameArray(),
3385
0
                            bIsSearchUsed, bSearchHidden, bOnlyHidden, SwGetPoolIdFromName::TxtColl, SfxStyleFamily::Para ) ;
3386
0
            if( !bAll )
3387
0
            {
3388
                // then also the ones, that we are mapping:
3389
0
                static constexpr SwPoolFormatId aPoolIds[] = {
3390
0
                    SwPoolFormatId::COLL_SEND_ADDRESS, //  --> ADDRESS
3391
0
                    SwPoolFormatId::COLL_TABLE_HDLN,    //  --> TH
3392
0
                    SwPoolFormatId::COLL_TABLE,     //  --> TD
3393
0
                    SwPoolFormatId::COLL_STANDARD,      //  --> P
3394
0
                    SwPoolFormatId::COLL_TEXT,          //  --> P
3395
0
                    SwPoolFormatId::COLL_HEADLINE_BASE, //  --> H
3396
0
                    SwPoolFormatId::COLL_HEADLINE1, //  --> H1
3397
0
                    SwPoolFormatId::COLL_HEADLINE2, //  --> H2
3398
0
                    SwPoolFormatId::COLL_HEADLINE3, //  --> H3
3399
0
                    SwPoolFormatId::COLL_HEADLINE4, //  --> H4
3400
0
                    SwPoolFormatId::COLL_HEADLINE5, //  --> H5
3401
0
                    SwPoolFormatId::COLL_HEADLINE6, //  --> H6
3402
0
                    SwPoolFormatId::COLL_FOOTNOTE,
3403
0
                    SwPoolFormatId::COLL_ENDNOTE
3404
0
                    };
3405
3406
0
                for( const SwPoolFormatId nPoolId : aPoolIds )
3407
0
                {
3408
0
                    if( !bIsSearchUsed || rDoc.getIDocumentStylePoolAccess().IsPoolTextCollUsed( nPoolId ) )
3409
0
                    {
3410
0
                        UIName s = SwStyleNameMapper::GetUIName( nPoolId, ProgName() );
3411
0
                        m_aLst.Append( SfxStyleFamily::Para, s);
3412
0
                    }
3413
0
                }
3414
0
            }
3415
0
        }
3416
0
    }
3417
3418
1.45k
    if( nSearchFamily == SfxStyleFamily::Frame ||
3419
1.45k
        nSearchFamily == SfxStyleFamily::All )
3420
0
    {
3421
0
        const size_t nArrLen = rDoc.GetFrameFormats()->size();
3422
0
        for( size_t i = 0; i < nArrLen; i++ )
3423
0
        {
3424
0
            const SwFrameFormat* pFormat = (*rDoc.GetFrameFormats())[ i ];
3425
3426
0
            bool bUsed = bIsSearchUsed && ( bOrganizer || rDoc.IsUsed(*pFormat));
3427
0
            if( ( !bSearchHidden && pFormat->IsHidden( ) && !bUsed ) || pFormat->IsDefault() || pFormat->IsAuto() )
3428
0
                continue;
3429
3430
0
            if ( nSrchMask == SfxStyleSearchBits::Hidden && !pFormat->IsHidden( ) )
3431
0
                continue;
3432
3433
0
            const SwPoolFormatId nId = pFormat->GetPoolFormatId();
3434
0
            if( !bUsed )
3435
0
            {
3436
0
                if( (nSrchMask & ~SfxStyleSearchBits::Used) == SfxStyleSearchBits::UserDefined
3437
0
                    ? !(sal_uInt16(nId) & USER_FMT)
3438
                    // searched for used and found none
3439
0
                    : bIsSearchUsed )
3440
0
                {
3441
0
                    continue;
3442
0
                }
3443
0
            }
3444
3445
0
            m_aLst.Append( SfxStyleFamily::Frame, pFormat->GetName() );
3446
0
        }
3447
3448
        // PoolFormat
3449
0
        if ( bAll )
3450
0
            AppendStyleList(SwStyleNameMapper::GetFrameFormatUINameArray(),
3451
0
                                    bIsSearchUsed, bSearchHidden, bOnlyHidden, SwGetPoolIdFromName::FrmFmt, SfxStyleFamily::Frame);
3452
0
    }
3453
3454
1.45k
    if( nSearchFamily == SfxStyleFamily::Page ||
3455
942
        nSearchFamily == SfxStyleFamily::All )
3456
511
    {
3457
511
        const size_t nCount = rDoc.GetPageDescCnt();
3458
1.02k
        for(size_t i = 0; i < nCount; ++i)
3459
516
        {
3460
516
            const SwPageDesc& rDesc = rDoc.GetPageDesc(i);
3461
516
            const SwPoolFormatId nId = rDesc.GetPoolFormatId();
3462
516
            bool bUsed = bIsSearchUsed && ( bOrganizer || rDesc.IsUsed() );
3463
516
            if( !bUsed )
3464
516
            {
3465
516
                if ( ( !bSearchHidden && rDesc.IsHidden() ) ||
3466
516
                       ( (nSrchMask & ~SfxStyleSearchBits::Used) == SfxStyleSearchBits::UserDefined
3467
516
                    ? !(sal_uInt16(nId) & USER_FMT)
3468
                    // searched for used and found none
3469
516
                    : bIsSearchUsed ) )
3470
0
                    continue;
3471
516
            }
3472
3473
516
            if ( nSrchMask == SfxStyleSearchBits::Hidden && !rDesc.IsHidden( ) )
3474
0
                continue;
3475
3476
516
            m_aLst.Append( SfxStyleFamily::Page, rDesc.GetName() );
3477
516
        }
3478
511
        if ( bAll )
3479
511
            AppendStyleList(SwStyleNameMapper::GetPageDescUINameArray(),
3480
511
                            bIsSearchUsed, bSearchHidden, bOnlyHidden, SwGetPoolIdFromName::PageDesc, SfxStyleFamily::Page);
3481
511
    }
3482
3483
1.45k
    if( nSearchFamily == SfxStyleFamily::Pseudo ||
3484
1.45k
        nSearchFamily == SfxStyleFamily::All )
3485
0
    {
3486
0
        const SwNumRuleTable& rNumTable = rDoc.GetNumRuleTable();
3487
0
        for(auto const& rNum: rNumTable)
3488
0
        {
3489
0
            const SwNumRule& rRule = *rNum;
3490
0
            if( !rRule.IsAutoRule() )
3491
0
            {
3492
0
                if ( nSrchMask == SfxStyleSearchBits::Hidden && !rRule.IsHidden( ) )
3493
0
                    continue;
3494
3495
0
                bool bUsed = bIsSearchUsed && (bOrganizer || rDoc.IsUsed(rRule));
3496
0
                if( !bUsed )
3497
0
                {
3498
0
                    if( ( !bSearchHidden && rRule.IsHidden() ) ||
3499
0
                           ( (nSrchMask & ~SfxStyleSearchBits::Used) == SfxStyleSearchBits::UserDefined
3500
0
                        ? !(sal_uInt16(rRule.GetPoolFormatId()) & USER_FMT)
3501
                        // searched for used and found none
3502
0
                        : bIsSearchUsed ) )
3503
0
                        continue;
3504
0
                }
3505
3506
0
                m_aLst.Append( SfxStyleFamily::Pseudo, rRule.GetName() );
3507
0
            }
3508
0
        }
3509
0
        if ( bAll )
3510
0
            AppendStyleList(SwStyleNameMapper::GetNumRuleUINameArray(),
3511
0
                            bIsSearchUsed, bSearchHidden, bOnlyHidden, SwGetPoolIdFromName::NumRule, SfxStyleFamily::Pseudo);
3512
0
    }
3513
3514
1.45k
    if( nSearchFamily == SfxStyleFamily::Table ||
3515
1.45k
        nSearchFamily == SfxStyleFamily::All )
3516
0
    {
3517
0
        const SwTableAutoFormatTable& rTableStyles = rDoc.GetTableStyles();
3518
0
        for(size_t i = 0; i < rTableStyles.size(); ++i)
3519
0
        {
3520
0
            const SwTableAutoFormat& rTableStyle = rTableStyles[i];
3521
3522
0
            bool bUsed = bIsSearchUsed && (bOrganizer || rDoc.IsUsed(rTableStyle));
3523
0
            if(!bUsed)
3524
0
            {
3525
0
                if(nSrchMask == SfxStyleSearchBits::Hidden && !rTableStyle.IsHidden())
3526
0
                    continue;
3527
3528
0
                if( (!bSearchHidden && rTableStyle.IsHidden() ) ||
3529
0
                        ( (nSrchMask & ~SfxStyleSearchBits::Used) == SfxStyleSearchBits::UserDefined
3530
0
                    ? !rTableStyle.IsUserDefined()
3531
                    // searched for used and found none
3532
0
                    : bIsSearchUsed ) )
3533
0
                    continue;
3534
0
            }
3535
3536
0
            m_aLst.Append( SfxStyleFamily::Table, UIName(rTableStyle.GetName().toString()) );
3537
0
        }
3538
0
    }
3539
3540
1.45k
    if( nSearchFamily == SfxStyleFamily::Cell ||
3541
1.45k
        nSearchFamily == SfxStyleFamily::All )
3542
0
    {
3543
0
        if (rDoc.HasTableStyles())
3544
0
        {
3545
0
            const SwTableAutoFormatTable& rTableStyles = rDoc.GetTableStyles();
3546
0
            for(size_t i = 0; i < rTableStyles.size(); ++i)
3547
0
            {
3548
0
                const SwTableAutoFormat& rTableStyle = rTableStyles[i];
3549
0
                for (size_t j = 0; j < ELEMENT_COUNT; ++j)
3550
0
                {
3551
0
                    ProgName sBoxFormatName;
3552
0
                    SwStyleNameMapper::FillProgName(UIName(rTableStyle.GetName().toString()), sBoxFormatName, SwGetPoolIdFromName::TableStyle);
3553
0
                    m_aLst.Append(SfxStyleFamily::Cell, UIName(sBoxFormatName.toString() + "."
3554
0
                                                               + OUString::number(j + 1)));
3555
0
                }
3556
0
            }
3557
0
        }
3558
0
        const SwCellStyleTable& rCellStyles = rDoc.GetCellStyles();
3559
0
        for(size_t i = 0; i < rCellStyles.size(); ++i)
3560
0
            m_aLst.Append( SfxStyleFamily::Cell, rCellStyles[i].GetName() );
3561
0
    }
3562
3563
1.45k
    if(!m_aLst.empty())
3564
1.45k
    {
3565
1.45k
        m_nLastPos = SAL_MAX_UINT32;
3566
1.45k
        return Next();
3567
1.45k
    }
3568
0
    return nullptr;
3569
1.45k
}
3570
3571
SfxStyleSheetBase* SwStyleSheetIterator::Next()
3572
36.1k
{
3573
36.1k
    assert(m_bFirstCalled);
3574
36.1k
    ++m_nLastPos;
3575
36.1k
    if(m_nLastPos < m_aLst.size())
3576
34.7k
    {
3577
34.7k
        auto const & rEntry = m_aLst[m_nLastPos];
3578
34.7k
        mxIterSheet->PresetNameAndFamily(rEntry.first, rEntry.second.toString());
3579
34.7k
        mxIterSheet->SetPhysical( false );
3580
34.7k
        mxIterSheet->SetMask( nMask );
3581
34.7k
        if(mxIterSheet->pSet)
3582
0
        {
3583
0
            mxIterSheet->pSet->ClearItem();
3584
0
            mxIterSheet->pSet= nullptr;
3585
0
        }
3586
34.7k
        return mxIterSheet.get();
3587
34.7k
    }
3588
1.45k
    return nullptr;
3589
36.1k
}
3590
3591
SfxStyleSheetBase* SwStyleSheetIterator::Find(const OUString& rName)
3592
0
{
3593
    // searching
3594
0
    if( !m_bFirstCalled )
3595
0
        First();
3596
3597
0
    m_nLastPos = m_aLst.FindName( nSearchFamily, UIName(rName) );
3598
0
    if( SAL_MAX_UINT32 != m_nLastPos )
3599
0
    {
3600
        // found
3601
0
        auto const & rEntry = m_aLst[m_nLastPos];
3602
0
        mxStyleSheet->PresetNameAndFamily(rEntry.first, rEntry.second.toString());
3603
        // new name is set, so determine its Data
3604
0
        mxStyleSheet->FillStyleSheet( SwDocStyleSheet::FillOnlyName );
3605
0
        if( !mxStyleSheet->IsPhysical() )
3606
0
            mxStyleSheet->SetPhysical( false );
3607
3608
0
        return mxStyleSheet.get();
3609
0
    }
3610
0
    return nullptr;
3611
0
}
3612
3613
static std::map<UIName, const SwFormat*> MakeNameToFormatMap(const SwFormatsBase& rFormats)
3614
1.88k
{
3615
1.88k
    std::map<UIName, const SwFormat*> ret;
3616
12.9k
    for( size_t n = 0; n < rFormats.GetFormatCount(); ++n )
3617
11.0k
    {
3618
11.0k
        auto pFormat = rFormats.GetFormat(n);
3619
11.0k
        ret.insert( { pFormat->GetName(), pFormat } );
3620
11.0k
    }
3621
1.88k
    return ret;
3622
1.88k
}
3623
3624
void SwStyleSheetIterator::AppendStyleList(const std::vector<OUString>& rList,
3625
                                            bool bTestUsed, bool bTestHidden, bool bOnlyHidden,
3626
                                            SwGetPoolIdFromName nSection, SfxStyleFamily eFamily )
3627
2.39k
{
3628
2.39k
    const SwDoc& rDoc = static_cast<const SwDocStyleSheetPool*>(pBasePool)->GetDoc();
3629
2.39k
    bool bUsed = false;
3630
3631
    // Most of the searching for formats uses a linear search, so to avoid an O(n^2) loop, build
3632
    // a map of name->SwFormat.
3633
2.39k
    std::map<UIName, const SwFormat*> aNameToFormatMap;
3634
2.39k
    switch ( nSection )
3635
2.39k
    {
3636
0
        case SwGetPoolIdFromName::TxtColl:
3637
0
            aNameToFormatMap = MakeNameToFormatMap(*rDoc.GetTextFormatColls());
3638
0
            break;
3639
1.88k
        case SwGetPoolIdFromName::ChrFmt:
3640
1.88k
            aNameToFormatMap = MakeNameToFormatMap(*rDoc.GetCharFormats());
3641
1.88k
            break;
3642
0
        case SwGetPoolIdFromName::FrmFmt:
3643
0
            aNameToFormatMap = MakeNameToFormatMap(*rDoc.GetFrameFormats());
3644
0
            break;
3645
511
        case SwGetPoolIdFromName::PageDesc:
3646
            // do nothing
3647
511
            break;
3648
0
        case SwGetPoolIdFromName::NumRule:
3649
            // do nothing
3650
0
            break;
3651
0
        default:
3652
0
            OSL_ENSURE( false, "unknown PoolFormat-Id" );
3653
2.39k
    }
3654
3655
2.39k
    auto findByName = [&aNameToFormatMap] (const UIName& rName) -> const SwFormat*
3656
24.4k
        {
3657
24.4k
            auto it = aNameToFormatMap.find(rName);
3658
24.4k
            if (it == aNameToFormatMap.end())
3659
24.0k
                return nullptr;
3660
418
            return it->second;
3661
24.4k
        };
3662
2.39k
    for (const auto & rEntry : rList)
3663
29.6k
    {
3664
29.6k
        UIName i(rEntry);
3665
29.6k
        bool bHidden = false;
3666
29.6k
        bool bFavourite = false;
3667
29.6k
        SwPoolFormatId nId = SwStyleNameMapper::GetPoolIdFromUIName(i, nSection);
3668
29.6k
        switch ( nSection )
3669
29.6k
        {
3670
0
            case SwGetPoolIdFromName::TxtColl:
3671
0
                {
3672
0
                    const SwFormat* pFormat = findByName(i);
3673
0
                    bUsed = pFormat != nullptr && rDoc.getIDocumentStylePoolAccess().IsPoolTextCollUsed( static_cast<const SwTextFormatColl&>(*pFormat) );
3674
0
                    bHidden = pFormat && pFormat->IsHidden( );
3675
0
                    bFavourite = pFormat && pFormat->IsFavourite().value_or(false);
3676
0
                }
3677
0
                break;
3678
24.4k
            case SwGetPoolIdFromName::ChrFmt:
3679
24.4k
                {
3680
24.4k
                    const SwFormat* pFormat = findByName(i);
3681
24.4k
                    bUsed = pFormat != nullptr && rDoc.getIDocumentStylePoolAccess().IsPoolFormatUsed( *pFormat );
3682
24.4k
                    bHidden = pFormat && pFormat->IsHidden( );
3683
24.4k
                    bFavourite = pFormat && pFormat->IsFavourite().value_or(false);
3684
24.4k
                }
3685
24.4k
                break;
3686
0
            case SwGetPoolIdFromName::FrmFmt:
3687
0
                {
3688
0
                    const SwFormat* pFormat = findByName(i);
3689
0
                    bUsed = pFormat != nullptr && rDoc.getIDocumentStylePoolAccess().IsPoolFormatUsed( *pFormat );
3690
0
                    bHidden = pFormat && pFormat->IsHidden( );
3691
0
                }
3692
0
                break;
3693
5.11k
            case SwGetPoolIdFromName::PageDesc:
3694
5.11k
                {
3695
5.11k
                    bUsed = rDoc.getIDocumentStylePoolAccess().IsPoolPageDescUsed( nId );
3696
5.11k
                    SwPageDesc* pPgDesc = rDoc.FindPageDesc(i);
3697
5.11k
                    bHidden = pPgDesc && pPgDesc->IsHidden( );
3698
5.11k
                }
3699
5.11k
                break;
3700
0
            case SwGetPoolIdFromName::NumRule:
3701
0
                {
3702
0
                    SwNumRule* pRule = rDoc.FindNumRulePtr( i );
3703
0
                    bUsed = pRule && rDoc.IsUsed(*pRule);
3704
0
                    bHidden = pRule && pRule->IsHidden( );
3705
0
                }
3706
0
                break;
3707
0
            default:
3708
0
                OSL_ENSURE( false, "unknown PoolFormat-Id" );
3709
29.6k
        }
3710
3711
29.6k
        bool bMatchHidden = ( bTestHidden && ( bHidden || !bOnlyHidden ) ) || ( !bTestHidden && ( !bHidden || bUsed ) );
3712
29.6k
        if ( ( !bTestUsed && bMatchHidden ) || ( bTestUsed && bUsed ) || bFavourite )
3713
29.6k
            m_aLst.Append( eFamily, i );
3714
29.6k
    }
3715
2.39k
}
3716
3717
bool SwStyleSheetIterator::IsUsedInComments(const UIName& rName) const
3718
0
{
3719
0
    auto pPool = static_cast<const SwDocStyleSheetPool*>(pBasePool)->GetEEStyleSheetPool();
3720
0
    SfxStyleSheetIterator aIter(pPool, GetSearchFamily(), SfxStyleSearchBits::Used);
3721
0
    return aIter.Find(rName.toString()) != nullptr;
3722
0
}
3723
3724
void SwDocStyleSheetPool::InvalidateIterator()
3725
53.4k
{
3726
53.4k
    if (SfxStyleSheetIterator* pIter = GetCachedIterator())
3727
0
        dynamic_cast<SwStyleSheetIterator&>(*pIter).InvalidateIterator();
3728
53.4k
}
3729
3730
void SwStyleSheetIterator::InvalidateIterator()
3731
0
{
3732
    // potentially we could send an SfxHint to Notify but currently it's
3733
    // iterating over the vector anyway so would still be slow - why does
3734
    // this iterator not use a map?
3735
0
    m_bFirstCalled = false;
3736
0
    m_nLastPos = 0;
3737
0
    m_aLst.clear();
3738
0
}
3739
3740
void SwStyleSheetIterator::Notify( SfxBroadcaster&, const SfxHint& rHint )
3741
0
{
3742
    // search and remove from View-List!!
3743
0
    if( SfxHintId::StyleSheetErased == rHint.GetId() )
3744
0
    {
3745
0
        const SfxStyleSheetHint* pStyleSheetHint = static_cast<const SfxStyleSheetHint*>(&rHint);
3746
0
        SfxStyleSheetBase* pStyle = pStyleSheetHint->GetStyleSheet();
3747
3748
0
        if (pStyle)
3749
0
            m_aLst.RemoveName(pStyle->GetFamily(), UIName(pStyle->GetName()));
3750
0
    }
3751
0
}
3752
3753
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */