Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/source/uibase/app/docst.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 <config_wasm_strip.h>
21
22
#include <memory>
23
24
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
25
#include <com/sun/star/beans/XPropertySet.hpp>
26
#include <com/sun/star/container/XNameAccess.hpp>
27
#include <com/sun/star/frame/XModel.hpp>
28
#include <comphelper/flagguard.hxx>
29
#include <o3tl/any.hxx>
30
#include <sal/log.hxx>
31
#include <osl/diagnose.h>
32
#include <hintids.hxx>
33
#include <sfx2/styledlg.hxx>
34
#include <svl/whiter.hxx>
35
#include <sfx2/tplpitem.hxx>
36
#include <sfx2/request.hxx>
37
#include <sfx2/dispatch.hxx>
38
#include <sfx2/newstyle.hxx>
39
#include <sfx2/printer.hxx>
40
#include <sfx2/viewfrm.hxx>
41
#include <svl/stritem.hxx>
42
#include <svl/ctloptions.hxx>
43
#include <sfx2/htmlmode.hxx>
44
#include <swmodule.hxx>
45
#include <fchrfmt.hxx>
46
#include <svx/xdef.hxx>
47
#include <SwStyleNameMapper.hxx>
48
#include <SwRewriter.hxx>
49
#include <numrule.hxx>
50
#include <swundo.hxx>
51
#include <svx/drawitem.hxx>
52
#include <utility>
53
#include <view.hxx>
54
#include <wrtsh.hxx>
55
#include <docsh.hxx>
56
#include <uitool.hxx>
57
#include <cmdid.h>
58
#include <viewopt.hxx>
59
#include <doc.hxx>
60
#include <drawdoc.hxx>
61
#include <IDocumentDrawModelAccess.hxx>
62
#include <IDocumentUndoRedo.hxx>
63
#include <IDocumentSettingAccess.hxx>
64
#include <IDocumentDeviceAccess.hxx>
65
#include <IDocumentFieldsAccess.hxx>
66
#include <IDocumentState.hxx>
67
#include <frmfmt.hxx>
68
#include <charfmt.hxx>
69
#include <poolfmt.hxx>
70
#include <pagedesc.hxx>
71
#include <docstyle.hxx>
72
#include <uiitems.hxx>
73
#include <fmtcol.hxx>
74
#include <edtwin.hxx>
75
#include <unochart.hxx>
76
#include <swabstdlg.hxx>
77
#include <tblafmt.hxx>
78
#include <sfx2/watermarkitem.hxx>
79
#include <svl/grabbagitem.hxx>
80
#include <PostItMgr.hxx>
81
#include <AnnotationWin.hxx>
82
#include <SwUndoFmt.hxx>
83
#include <strings.hrc>
84
#include <AccessibilityCheck.hxx>
85
#include <docmodel/theme/Theme.hxx>
86
#include <svx/svdpage.hxx>
87
#include <officecfg/Office/Common.hxx>
88
#include <fmtfsize.hxx>
89
#include <names.hxx>
90
#include <svl/ptitem.hxx>
91
#include <editeng/sizeitem.hxx>
92
#include <editeng/ulspitem.hxx>
93
94
using namespace ::com::sun::star;
95
96
static OutlinerView* lcl_GetPostItOutlinerView(SwWrtShell& rShell)
97
0
{
98
0
    SwPostItMgr* pPostItMgr = rShell.GetPostItMgr();
99
0
    if (!pPostItMgr)
100
0
        return nullptr;
101
0
    sw::annotation::SwAnnotationWin* pWin = pPostItMgr->GetActiveSidebarWin();
102
0
    if (!pWin)
103
0
        return nullptr;
104
0
    return pWin->GetOutlinerView();
105
0
}
106
107
void  SwDocShell::StateStyleSheet(SfxItemSet& rSet, SwWrtShell* pSh)
108
0
{
109
0
    SfxWhichIter aIter(rSet);
110
0
    sal_uInt16  nWhich  = aIter.FirstWhich();
111
0
    SfxStyleFamily nActualFamily = SfxStyleFamily(USHRT_MAX);
112
113
0
    SwWrtShell* pShell = pSh ? pSh : GetWrtShell();
114
0
    if(!pShell)
115
0
    {
116
0
        while (nWhich)
117
0
        {
118
0
            rSet.DisableItem(nWhich);
119
0
            nWhich = aIter.NextWhich();
120
0
        }
121
0
        return;
122
0
    }
123
0
    else
124
0
    {
125
0
        SfxViewFrame& rFrame = pShell->GetView().GetViewFrame();
126
0
        std::unique_ptr<SfxUInt16Item> pFamilyItem;
127
0
        rFrame.GetBindings().QueryState(SID_STYLE_FAMILY, pFamilyItem);
128
0
        if (pFamilyItem)
129
0
        {
130
0
            nActualFamily = static_cast<SfxStyleFamily>(pFamilyItem->GetValue());
131
0
        }
132
0
    }
133
134
0
    while (nWhich)
135
0
    {
136
        // determine current template to every family
137
0
        UIName aName;
138
0
        SwTableAutoFormat aTableAutoFormat(TableStyleName(u"dummy"_ustr)); // needed to check if can take a table auto format at current cursor position
139
0
        switch (nWhich)
140
0
        {
141
0
            case SID_STYLE_APPLY:
142
0
            {// here the template and its family are passed to the StyleBox
143
             // so that this family is being showed
144
0
                if(pShell->IsFrameSelected())
145
0
                {
146
0
                    SwFrameFormat* pFormat = pShell->GetSelectedFrameFormat();
147
0
                    if( pFormat )
148
0
                        aName = pFormat->GetName();
149
0
                }
150
0
                else if (pShell->GetSelectionType() == SelectionType::PostIt)
151
0
                {
152
0
                    OutlinerView *pOLV = lcl_GetPostItOutlinerView(*pShell);
153
0
                    if (SfxStyleSheetBase* pStyle = pOLV ? pOLV->GetStyleSheet() : nullptr)
154
0
                        aName = UIName(pStyle->GetName());
155
0
                }
156
0
                else
157
0
                {
158
0
                    SwTextFormatColl* pColl = pShell->GetCurTextFormatColl();
159
0
                    if(pColl)
160
0
                        aName = pColl->GetName();
161
0
                }
162
0
                rSet.Put(SfxTemplateItem(nWhich, aName.toString()));
163
0
            }
164
0
            break;
165
0
            case SID_STYLE_FAMILY1:
166
0
                if( !pShell->IsFrameSelected() )
167
0
                {
168
0
                    SwCharFormat* pFormat = pShell->GetCurCharFormat();
169
0
                    if(pFormat)
170
0
                        aName = pFormat->GetName();
171
0
                    else
172
0
                        aName = UIName(SwResId(STR_POOLCHR_STANDARD));
173
0
                    rSet.Put(SfxTemplateItem(nWhich, aName.toString()));
174
0
                }
175
0
                break;
176
177
0
            case SID_STYLE_FAMILY2:
178
0
                if(!pShell->IsFrameSelected())
179
0
                {
180
0
                    ProgName aProgName;
181
0
                    if (pShell->GetSelectionType() == SelectionType::PostIt)
182
0
                    {
183
0
                        OutlinerView *pOLV = lcl_GetPostItOutlinerView(*pShell);
184
0
                        if (SfxStyleSheetBase* pStyle = pOLV ? pOLV->GetStyleSheet() : nullptr)
185
0
                        {
186
0
                            aName = UIName(pStyle->GetName());
187
0
                            aProgName = SwStyleNameMapper::GetProgName(aName, SwGetPoolIdFromName::TxtColl);
188
0
                        }
189
0
                    }
190
0
                    else if (auto pColl = pShell->GetCurTextFormatColl())
191
0
                    {
192
0
                        aName = pColl->GetName();
193
0
                        sal_uInt16 nId = pColl->GetPoolFormatId();
194
0
                        SwStyleNameMapper::FillProgName(nId, aProgName);
195
0
                    }
196
197
0
                    SfxTemplateItem aItem(nWhich, aName.toString(), aProgName.toString());
198
199
0
                    SfxStyleSearchBits nMask = SfxStyleSearchBits::Auto;
200
0
                    if (m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE))
201
0
                        nMask = SfxStyleSearchBits::SwHtml;
202
0
                    else
203
0
                    {
204
0
                        const FrameTypeFlags nSelection = pShell->GetFrameType(nullptr,true);
205
0
                        if(pShell->GetCurTOX())
206
0
                            nMask = SfxStyleSearchBits::SwIndex  ;
207
0
                        else if(nSelection & FrameTypeFlags::HEADER     ||
208
0
                                nSelection & FrameTypeFlags::FOOTER     ||
209
0
                                nSelection & FrameTypeFlags::TABLE      ||
210
0
                                nSelection & FrameTypeFlags::FLY_ANY    ||
211
0
                                nSelection & FrameTypeFlags::FOOTNOTE   ||
212
0
                                nSelection & FrameTypeFlags::FTNPAGE)
213
0
                            nMask = SfxStyleSearchBits::SwExtra;
214
0
                        else
215
0
                            nMask = SfxStyleSearchBits::SwText;
216
0
                    }
217
218
0
                    aItem.SetValue(nMask);
219
0
                    rSet.Put(aItem);
220
0
                }
221
222
0
                break;
223
224
0
            case SID_STYLE_FAMILY3:
225
226
0
                if (m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE))
227
0
                    rSet.DisableItem( nWhich );
228
0
                else
229
0
                {
230
0
                    SwFrameFormat* pFormat = pShell->GetSelectedFrameFormat();
231
0
                    if(pFormat && pShell->IsFrameSelected())
232
0
                    {
233
0
                        aName = pFormat->GetName();
234
0
                        rSet.Put(SfxTemplateItem(nWhich, aName.toString()));
235
0
                    }
236
0
                }
237
0
                break;
238
239
0
            case SID_STYLE_FAMILY4:
240
0
            {
241
0
                if (m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE) && !officecfg::Office::Common::Filter::HTML::Export::PrintLayout::get())
242
0
                    rSet.DisableItem( nWhich );
243
0
                else
244
0
                {
245
0
                    size_t n = pShell->GetCurPageDesc( false );
246
0
                    if( n < pShell->GetPageDescCnt() )
247
0
                        aName = pShell->GetPageDesc( n ).GetName();
248
249
0
                    rSet.Put(SfxTemplateItem(nWhich, aName.toString()));
250
0
                }
251
0
            }
252
0
            break;
253
0
            case SID_STYLE_FAMILY5:
254
0
                {
255
0
                    const SwNumRule* pRule = pShell->GetNumRuleAtCurrCursorPos();
256
0
                    if( pRule )
257
0
                        aName = pRule->GetName();
258
259
0
                    rSet.Put(SfxTemplateItem(nWhich, aName.toString()));
260
0
                }
261
0
                break;
262
0
            case SID_STYLE_FAMILY6:
263
0
                {
264
0
                    const SwTableNode *pTableNd = pShell->IsCursorInTable();
265
0
                    if( pTableNd )
266
0
                        aName = UIName(pTableNd->GetTable().GetTableStyleName().toString());
267
268
0
                    rSet.Put(SfxTemplateItem(nWhich, aName.toString()));
269
0
                }
270
0
                break;
271
272
0
            case SID_STYLE_WATERCAN:
273
0
            {
274
0
                SwEditWin& rEdtWin = pShell->GetView().GetEditWin();
275
0
                SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
276
0
                rSet.Put(SfxBoolItem(nWhich, pApply && pApply->eType != SfxStyleFamily(0)));
277
0
            }
278
0
            break;
279
0
            case SID_STYLE_UPDATE_BY_EXAMPLE:
280
0
                if( pShell->IsFrameSelected()
281
0
                        ? SfxStyleFamily::Frame != nActualFamily
282
0
                        : ( SfxStyleFamily::Frame == nActualFamily ||
283
0
                            SfxStyleFamily::Page == nActualFamily ||
284
0
                            (SfxStyleFamily::Pseudo == nActualFamily && !pShell->GetNumRuleAtCurrCursorPos()) ||
285
0
                            (SfxStyleFamily::Table == nActualFamily && !pShell->GetTableAutoFormat(aTableAutoFormat))) )
286
0
                {
287
0
                    rSet.DisableItem( nWhich );
288
0
                }
289
0
                break;
290
291
0
            case SID_STYLE_NEW_BY_EXAMPLE:
292
0
                if( (pShell->IsFrameSelected()
293
0
                        ? SfxStyleFamily::Frame != nActualFamily
294
0
                        : SfxStyleFamily::Frame == nActualFamily) ||
295
0
                    (SfxStyleFamily::Pseudo == nActualFamily && !pShell->GetNumRuleAtCurrCursorPos()) ||
296
0
                    (SfxStyleFamily::Table == nActualFamily && !pShell->GetTableAutoFormat(aTableAutoFormat)) )
297
0
                {
298
0
                    rSet.DisableItem( nWhich );
299
0
                }
300
0
                break;
301
302
0
            case SID_CLASSIFICATION_APPLY:
303
                // Just trigger ClassificationCategoriesController::statusChanged().
304
0
                rSet.InvalidateItem(nWhich);
305
0
                break;
306
0
            case SID_CLASSIFICATION_DIALOG:
307
0
                rSet.InvalidateItem(nWhich);
308
0
                break;
309
0
            case SID_STYLE_EDIT:
310
0
                break;
311
0
            case SID_WATERMARK:
312
0
                if (pSh)
313
0
                {
314
0
                    SfxWatermarkItem aItem = pSh->GetWatermark();
315
0
                    rSet.Put(aItem);
316
0
                }
317
0
                break;
318
0
            default:
319
0
                OSL_FAIL("Invalid SlotId");
320
0
        }
321
0
        nWhich = aIter.NextWhich();
322
0
    }
323
0
}
324
325
// evaluate StyleSheet-Requests
326
void SwDocShell::ExecStyleSheet( SfxRequest& rReq )
327
0
{
328
0
    sal_uInt16  nSlot   = rReq.GetSlot();
329
330
0
    const SfxItemSet* pArgs = rReq.GetArgs();
331
0
    const SfxPoolItem* pItem;
332
0
    switch (nSlot)
333
0
    {
334
0
    case SID_STYLE_NEW:
335
0
        if( pArgs && SfxItemState::SET == pArgs->GetItemState( SID_STYLE_FAMILY,
336
0
            false, &pItem ))
337
0
        {
338
0
            const SfxStyleFamily nFamily = static_cast<SfxStyleFamily>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
339
340
0
            OUString sName;
341
0
            SfxStyleSearchBits nMask = SfxStyleSearchBits::Auto;
342
0
            if( SfxItemState::SET == pArgs->GetItemState( SID_STYLE_NEW,
343
0
                false, &pItem ))
344
0
                sName = static_cast<const SfxStringItem*>(pItem)->GetValue();
345
0
            if( SfxItemState::SET == pArgs->GetItemState( SID_STYLE_MASK,
346
0
                false, &pItem ))
347
0
                nMask = static_cast<SfxStyleSearchBits>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
348
0
            OUString sParent;
349
0
            if( SfxItemState::SET == pArgs->GetItemState( SID_STYLE_REFERENCE,
350
0
                false, &pItem ))
351
0
                sParent = static_cast<const SfxStringItem*>(pItem)->GetValue();
352
353
0
            if (sName.isEmpty() && m_xBasePool)
354
0
                sName = SfxStyleDialogController::GenerateUnusedName(*m_xBasePool, nFamily);
355
356
0
            Edit(rReq.GetFrameWeld(), UIName(sName), UIName(sParent), nFamily, nMask, true, {}, nullptr, &rReq, nSlot);
357
0
        }
358
0
        break;
359
360
0
        case SID_STYLE_APPLY:
361
0
            if( !pArgs )
362
0
            {
363
0
                GetView()->GetViewFrame().GetDispatcher()->Execute(SID_STYLE_DESIGNER);
364
0
                break;
365
0
            }
366
0
            else
367
0
            {
368
                // convert internal StyleName to DisplayName (slot implementation uses the latter)
369
0
                const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(SID_APPLY_STYLE);
370
0
                const SfxStringItem* pFamilyItem = rReq.GetArg<SfxStringItem>(SID_STYLE_FAMILYNAME);
371
0
                if ( pFamilyItem && pNameItem )
372
0
                {
373
0
                    uno::Reference< style::XStyleFamiliesSupplier > xModel(GetModel(), uno::UNO_QUERY);
374
0
                    try
375
0
                    {
376
0
                        uno::Reference< container::XNameAccess > xStyles;
377
0
                        uno::Reference< container::XNameAccess > xCont = xModel->getStyleFamilies();
378
0
                        xCont->getByName(pFamilyItem->GetValue()) >>= xStyles;
379
0
                        uno::Reference< beans::XPropertySet > xInfo;
380
0
                        xStyles->getByName( pNameItem->GetValue() ) >>= xInfo;
381
0
                        OUString aUIName;
382
0
                        xInfo->getPropertyValue(u"DisplayName"_ustr) >>= aUIName;
383
0
                        if ( !aUIName.isEmpty() )
384
0
                            rReq.AppendItem( SfxStringItem( SID_STYLE_APPLY, aUIName ) );
385
0
                    }
386
0
                    catch (const uno::Exception&)
387
0
                    {
388
0
                    }
389
0
                }
390
0
            }
391
392
0
            [[fallthrough]];
393
394
0
        case SID_STYLE_EDIT:
395
0
        case SID_STYLE_FONT:
396
0
        case SID_STYLE_DELETE:
397
0
        case SID_STYLE_HIDE:
398
0
        case SID_STYLE_SHOW:
399
0
        case SID_STYLE_WATERCAN:
400
0
        case SID_STYLE_FAMILY:
401
0
        case SID_STYLE_UPDATE_BY_EXAMPLE:
402
0
        case SID_STYLE_NEW_BY_EXAMPLE:
403
0
        {
404
0
            OUString aParam;
405
0
            SfxStyleFamily nFamily = SfxStyleFamily::Para;
406
0
            SfxStyleSearchBits nMask = SfxStyleSearchBits::Auto;
407
0
            SwWrtShell* pActShell = nullptr;
408
409
0
            if( !pArgs )
410
0
            {
411
0
                switch (nSlot)
412
0
                {
413
0
                    case SID_STYLE_NEW_BY_EXAMPLE:
414
0
                    {
415
0
                        SfxStyleSheetBasePool& rPool = *GetStyleSheetPool();
416
0
                        SfxNewStyleDlg aDlg(GetView()->GetFrameWeld(), rPool, nFamily);
417
0
                        if (aDlg.run() == RET_OK)
418
0
                        {
419
0
                            aParam = aDlg.GetName();
420
0
                            rReq.AppendItem(SfxStringItem(nSlot, aParam));
421
0
                        }
422
0
                    }
423
0
                    break;
424
425
0
                    case SID_STYLE_UPDATE_BY_EXAMPLE:
426
0
                    case SID_STYLE_EDIT:
427
0
                    {
428
0
                        if (GetWrtShell()->GetSelectionType() == SelectionType::PostIt)
429
0
                        {
430
0
                            OutlinerView *pOLV = lcl_GetPostItOutlinerView(*GetWrtShell());
431
0
                            if (SfxStyleSheetBase* pStyle = pOLV ? pOLV->GetStyleSheet() : nullptr)
432
0
                                aParam = pStyle->GetName();
433
0
                        }
434
0
                        else if (auto pColl = GetWrtShell()->GetCurTextFormatColl())
435
0
                            aParam = pColl->GetName().toString();
436
437
0
                        if (!aParam.isEmpty())
438
0
                            rReq.AppendItem(SfxStringItem(nSlot, aParam));
439
0
                    }
440
0
                    break;
441
0
                }
442
0
            }
443
0
            else
444
0
            {
445
0
                SAL_WARN_IF( !pArgs->Count(), "sw.ui", "SfxBug ItemSet is empty" );
446
447
0
                SwWrtShell* pShell = GetWrtShell();
448
0
                if( SfxItemState::SET == pArgs->GetItemState(nSlot, false, &pItem ))
449
0
                    aParam = static_cast<const SfxStringItem*>(pItem)->GetValue();
450
451
0
                if( SfxItemState::SET == pArgs->GetItemState(SID_STYLE_FAMILY,
452
0
                    false, &pItem ))
453
0
                    nFamily = static_cast<SfxStyleFamily>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
454
455
0
                if( SfxItemState::SET == pArgs->GetItemState(SID_STYLE_FAMILYNAME, false, &pItem ))
456
0
                {
457
0
                    OUString aFamily = static_cast<const SfxStringItem*>(pItem)->GetValue();
458
0
                    if(aFamily == "CharacterStyles")
459
0
                        nFamily = SfxStyleFamily::Char;
460
0
                    else
461
0
                    if(aFamily == "ParagraphStyles")
462
0
                        nFamily = SfxStyleFamily::Para;
463
0
                    else
464
0
                    if(aFamily == "PageStyles")
465
0
                        nFamily = SfxStyleFamily::Page;
466
0
                    else
467
0
                    if(aFamily == "FrameStyles")
468
0
                        nFamily = SfxStyleFamily::Frame;
469
0
                    else
470
0
                    if(aFamily == "NumberingStyles")
471
0
                        nFamily = SfxStyleFamily::Pseudo;
472
0
                    else
473
0
                    if(aFamily == "TableStyles")
474
0
                        nFamily = SfxStyleFamily::Table;
475
0
                }
476
477
0
                if( SfxItemState::SET == pArgs->GetItemState(SID_STYLE_MASK,
478
0
                    false, &pItem ))
479
0
                    nMask = static_cast<SfxStyleSearchBits>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
480
0
                if( const SwPtrItem* pShellItem = pArgs->GetItemIfSet(FN_PARAM_WRTSHELL, false ))
481
0
                    pActShell = pShell = static_cast<SwWrtShell*>(pShellItem->GetValue());
482
483
0
                if( nSlot == SID_STYLE_UPDATE_BY_EXAMPLE && aParam.isEmpty() )
484
0
                {
485
0
                    switch( nFamily )
486
0
                    {
487
0
                        case SfxStyleFamily::Para:
488
0
                        {
489
0
                            SwTextFormatColl* pColl = pShell->GetCurTextFormatColl();
490
0
                            if(pColl)
491
0
                                aParam = pColl->GetName().toString();
492
0
                        }
493
0
                        break;
494
0
                        case SfxStyleFamily::Frame:
495
0
                        {
496
0
                            SwFrameFormat* pFrame = m_pWrtShell->GetSelectedFrameFormat();
497
0
                            if( pFrame )
498
0
                                aParam = pFrame->GetName().toString();
499
0
                        }
500
0
                        break;
501
0
                        case SfxStyleFamily::Char:
502
0
                        {
503
0
                            SwCharFormat* pChar = m_pWrtShell->GetCurCharFormat();
504
0
                            if( pChar )
505
0
                                aParam = pChar->GetName().toString();
506
0
                        }
507
0
                        break;
508
0
                        case SfxStyleFamily::Pseudo:
509
0
                        if(const SfxStringItem* pExName = pArgs->GetItemIfSet(SID_STYLE_UPD_BY_EX_NAME, false))
510
0
                        {
511
0
                            aParam = pExName->GetValue();
512
0
                        }
513
0
                        break;
514
0
                        case SfxStyleFamily::Table:
515
0
                        if(const SfxStringItem* pExName = pArgs->GetItemIfSet(SID_STYLE_UPD_BY_EX_NAME, false))
516
0
                        {
517
0
                            aParam = pExName->GetValue();
518
0
                        }
519
0
                        break;
520
0
                        default: break;
521
0
                    }
522
0
                    rReq.AppendItem(SfxStringItem(nSlot, aParam));
523
0
                }
524
0
            }
525
0
            if (!aParam.isEmpty() || nSlot == SID_STYLE_WATERCAN )
526
0
            {
527
0
                sal_uInt16 nRet = 0xffff;
528
0
                bool bReturns = false;
529
530
0
                switch(nSlot)
531
0
                {
532
0
                    case SID_STYLE_EDIT:
533
0
                    case SID_STYLE_FONT:
534
0
                        Edit(rReq.GetFrameWeld(), UIName(aParam), {}, nFamily, nMask, false, (nSlot == SID_STYLE_FONT) ? u"font"_ustr : OUString(), pActShell);
535
0
                        break;
536
0
                    case SID_STYLE_DELETE:
537
0
                        Delete(aParam, nFamily);
538
0
                        break;
539
0
                    case SID_STYLE_HIDE:
540
0
                    case SID_STYLE_SHOW:
541
0
                        Hide(aParam, nFamily, nSlot == SID_STYLE_HIDE);
542
0
                        break;
543
0
                    case SID_STYLE_APPLY:
544
                        // Shell-switch in ApplyStyles
545
0
                        nRet = static_cast<sal_uInt16>(ApplyStyles(aParam, nFamily, pActShell, rReq.GetModifier() ));
546
0
                        bReturns = true;
547
0
                        break;
548
0
                    case SID_STYLE_WATERCAN:
549
0
                        nRet = static_cast<sal_uInt16>(DoWaterCan(aParam, nFamily));
550
0
                        bReturns = true;
551
0
                        break;
552
0
                    case SID_STYLE_UPDATE_BY_EXAMPLE:
553
0
                        UpdateStyle(UIName(aParam), nFamily, pActShell);
554
0
                        break;
555
0
                    case SID_STYLE_NEW_BY_EXAMPLE:
556
0
                        MakeByExample(UIName(aParam), nFamily, nMask, pActShell);
557
0
                        break;
558
559
0
                    default:
560
0
                        OSL_FAIL("Invalid SlotId");
561
0
                }
562
563
                // Update formatting toolbar buttons status
564
0
                if (GetWrtShell()->GetSelectionType() == SelectionType::PostIt)
565
0
                    GetView()->GetViewFrame().GetBindings().InvalidateAll(false);
566
567
0
                if (bReturns)
568
0
                {
569
0
                    if(rReq.IsAPI()) // Basic only gets TRUE or FALSE
570
0
                        rReq.SetReturnValue(SfxUInt16Item(nSlot, sal_uInt16(nRet !=0)));
571
0
                    else
572
0
                        rReq.SetReturnValue(SfxUInt16Item(nSlot, nRet));
573
0
                }
574
575
0
                rReq.Done();
576
0
            }
577
578
0
            break;
579
0
        }
580
0
    }
581
0
}
582
583
namespace {
584
585
class ApplyStyle
586
{
587
public:
588
    ApplyStyle(SwDocShell &rDocSh, bool bNew,
589
        rtl::Reference< SwDocStyleSheet > xTmp,
590
        SfxStyleFamily nFamily, SfxAbstractApplyTabDialog *pDlg,
591
        rtl::Reference< SfxStyleSheetBasePool > xBasePool,
592
        bool bModified)
593
0
        : m_pDlg(pDlg)
594
0
        , m_rDocSh(rDocSh)
595
0
        , m_bNew(bNew)
596
0
        , m_xTmp(std::move(xTmp))
597
0
        , m_nFamily(nFamily)
598
0
        , m_xBasePool(std::move(xBasePool))
599
0
        , m_bModified(bModified)
600
0
    {
601
0
    }
602
    DECL_LINK( ApplyHdl, LinkParamNone*, void );
603
    void apply()
604
0
    {
605
0
        ApplyHdl(nullptr);
606
0
    }
607
    VclPtr<SfxAbstractApplyTabDialog> m_pDlg;
608
    // true if the document was initially modified before ApplyStyle was created
609
    // or if ApplyStyle:::apply was called
610
    bool DocIsModified() const
611
0
    {
612
0
        return m_bModified;
613
0
    }
614
private:
615
    SwDocShell &m_rDocSh;
616
    bool m_bNew;
617
    rtl::Reference< SwDocStyleSheet > m_xTmp;
618
    SfxStyleFamily m_nFamily;
619
    rtl::Reference< SfxStyleSheetBasePool > m_xBasePool;
620
    bool m_bModified;
621
};
622
623
}
624
625
IMPL_LINK_NOARG(ApplyStyle, ApplyHdl, LinkParamNone*, void)
626
0
{
627
0
    SwWrtShell* pWrtShell = m_rDocSh.GetWrtShell();
628
0
    SwDoc* pDoc = m_rDocSh.GetDoc();
629
0
    SwView* pView = m_rDocSh.GetView();
630
631
0
    pWrtShell->StartAllAction();
632
633
0
    if( SfxStyleFamily::Para == m_nFamily )
634
0
    {
635
0
        SfxItemSet aSet( *m_pDlg->GetOutputItemSet() );
636
0
        ::ConvertAttrGenToChar(aSet, m_xTmp->GetItemSet(), /*bIsPara=*/true);
637
0
        ::SfxToSwPageDescAttr( *pWrtShell, aSet  );
638
        // reset indent attributes at paragraph style, if a list style
639
        // will be applied and no indent attributes will be applied.
640
0
        m_xTmp->SetItemSet( aSet, false, true );
641
0
    }
642
0
    else
643
0
    {
644
0
        if(SfxStyleFamily::Page == m_nFamily || SfxStyleFamily::Frame == m_nFamily)
645
0
        {
646
0
            static const sal_uInt16 aInval[] = {
647
0
                SID_IMAGE_ORIENTATION,
648
0
                SID_ATTR_CHAR_FONT,
649
0
                FN_INSERT_CTRL, FN_INSERT_OBJ_CTRL,
650
0
                FN_TABLE_INSERT_COL_BEFORE,
651
0
                FN_TABLE_INSERT_COL_AFTER, 0};
652
0
            pView->GetViewFrame().GetBindings().Invalidate(aInval);
653
0
        }
654
0
        SfxItemSet aTmpSet( *m_pDlg->GetOutputItemSet() );
655
0
        if( SfxStyleFamily::Char == m_nFamily )
656
0
        {
657
0
            ::ConvertAttrGenToChar(aTmpSet, m_xTmp->GetItemSet());
658
0
        }
659
660
0
        bool bParam1 = SfxStyleFamily::Page == m_nFamily; // bApplyToAllFormatFrames
661
0
        m_xTmp->SetItemSet(aTmpSet, /*bBroadcast=*/ false, bParam1);
662
663
0
        if( SfxStyleFamily::Page == m_nFamily && SvtCTLOptions::IsCTLFontEnabled() )
664
0
        {
665
0
            const SfxPoolItem *pItem = nullptr;
666
0
            if( aTmpSet.GetItemState( m_rDocSh.GetPool().GetTrueWhichIDFromSlotID( SID_ATTR_FRAMEDIRECTION, false ) , true, &pItem ) == SfxItemState::SET )
667
0
                SwChartHelper::DoUpdateAllCharts( pDoc );
668
0
        }
669
670
0
        if (m_nFamily == SfxStyleFamily::Page)
671
0
        {
672
0
            if (const SfxGrabBagItem* pGrabBagItem = aTmpSet.GetItemIfSet(SID_ATTR_CHAR_GRABBAG))
673
0
            {
674
0
                bool bGutterAtTop{};
675
0
                auto it = pGrabBagItem->GetGrabBag().find(u"GutterAtTop"_ustr);
676
0
                if (it != pGrabBagItem->GetGrabBag().end())
677
0
                {
678
0
                    it->second >>= bGutterAtTop;
679
0
                }
680
0
                bool bOldGutterAtTop
681
0
                    = pDoc->getIDocumentSettingAccess().get(DocumentSettingId::GUTTER_AT_TOP);
682
0
                if (bOldGutterAtTop != bGutterAtTop)
683
0
                {
684
0
                    pDoc->getIDocumentSettingAccess().set(DocumentSettingId::GUTTER_AT_TOP,
685
0
                                                          bGutterAtTop);
686
0
                    pWrtShell->InvalidateLayout(/*bSizeChanged=*/true);
687
0
                }
688
0
            }
689
0
        }
690
691
0
        if (m_nFamily == SfxStyleFamily::Frame)
692
0
        {
693
0
            if (const SfxBoolItem* pBoolItem = aTmpSet.GetItemIfSet(FN_KEEP_ASPECT_RATIO))
694
0
            {
695
0
                const SwViewOption* pVOpt = pWrtShell->GetViewOptions();
696
0
                SwViewOption aUsrPref(*pVOpt);
697
0
                aUsrPref.SetKeepRatio(pBoolItem->GetValue());
698
0
                if (pBoolItem->GetValue() != pVOpt->IsKeepRatio())
699
0
                {
700
0
                    SwModule::get()->ApplyUsrPref(aUsrPref, &pWrtShell->GetView());
701
0
                }
702
0
            }
703
0
        }
704
0
    }
705
706
0
    if(m_bNew)
707
0
    {
708
0
        if(SfxStyleFamily::Frame == m_nFamily || SfxStyleFamily::Para == m_nFamily)
709
0
        {
710
            // clear FillStyle so that it works as a derived attribute
711
0
            SfxItemSet aTmpSet(*m_pDlg->GetOutputItemSet());
712
713
0
            aTmpSet.ClearItem(XATTR_FILLSTYLE);
714
0
            m_xTmp->SetItemSet(aTmpSet, false);
715
0
        }
716
0
    }
717
718
0
    if(SfxStyleFamily::Page == m_nFamily)
719
0
        pView->InvalidateRulerPos();
720
721
0
    if( !m_bNew )
722
0
        m_xBasePool->Broadcast(SfxStyleSheetHint(SfxHintId::StyleSheetModified, *m_xTmp));
723
724
0
    pDoc->getIDocumentState().SetModified();
725
0
    if( !m_bModified )
726
0
    {
727
0
        pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
728
0
        m_bModified = true;
729
0
    }
730
731
0
    pWrtShell->EndAllAction();
732
0
}
733
734
namespace
735
{
736
/// Checks if there is an Endnote page style in use, and makes sure it has the same orientation
737
/// with the Default (Standard) page style.
738
void syncEndnoteOrientation(const uno::Reference< style::XStyleFamiliesSupplier >& xStyleFamSupp)
739
0
{
740
0
    if (!xStyleFamSupp.is())
741
0
    {
742
0
        SAL_WARN("sw.ui", "Ref to XStyleFamiliesSupplier is null.");
743
0
        return;
744
0
    }
745
0
    uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamSupp->getStyleFamilies();
746
747
0
    if (!xStyleFamilies.is())
748
0
        return;
749
750
0
    uno::Reference<container::XNameAccess> xPageStyles(xStyleFamilies->getByName(u"PageStyles"_ustr),
751
0
                                                       uno::UNO_QUERY);
752
753
0
    if (!xPageStyles.is())
754
0
        return;
755
756
0
    uno::Reference<css::style::XStyle> xEndnotePageStyle(xPageStyles->getByName(u"Endnote"_ustr),
757
0
                                                  uno::UNO_QUERY);
758
759
0
    if (!xEndnotePageStyle.is())
760
0
        return;
761
762
    // Language-independent name of the "Default Style" is "Standard"
763
0
    uno::Reference<css::style::XStyle> xDefaultPageStyle(xPageStyles->getByName(u"Standard"_ustr),
764
0
                                                  uno::UNO_QUERY);
765
0
    if (!xDefaultPageStyle.is())
766
0
        return;
767
768
0
    if (xEndnotePageStyle->isUserDefined() || !xEndnotePageStyle->isInUse())
769
0
        return;
770
771
0
    uno::Reference<beans::XPropertySet> xEndnotePagePropSet(xPageStyles->getByName(u"Endnote"_ustr), uno::UNO_QUERY);
772
0
    uno::Reference<beans::XPropertySet> xDefaultPagePropSet(xPageStyles->getByName(u"Standard"_ustr), uno::UNO_QUERY);
773
774
0
    if (!xEndnotePagePropSet.is() || !xDefaultPagePropSet.is())
775
0
    {
776
0
        SAL_WARN("sw.ui", "xEndnotePagePropSet or xDefaultPagePropSet is null.");
777
0
        return;
778
0
    }
779
780
0
    auto const bIsDefLandScape = *o3tl::doAccess<bool>(
781
0
        xDefaultPagePropSet->getPropertyValue(u"IsLandscape"_ustr));
782
0
    auto const bIsEndLandScape = *o3tl::doAccess<bool>(
783
0
        xEndnotePagePropSet->getPropertyValue(u"IsLandscape"_ustr));
784
785
0
    if (bIsDefLandScape == bIsEndLandScape)
786
0
        return;
787
788
0
    auto const nWidth = xEndnotePagePropSet->getPropertyValue(u"Width"_ustr);
789
0
    auto const nHeight = xEndnotePagePropSet->getPropertyValue(u"Height"_ustr);
790
791
0
    xEndnotePagePropSet->setPropertyValue(u"IsLandscape"_ustr, css::uno::toAny(bIsDefLandScape));
792
0
    xEndnotePagePropSet->setPropertyValue(u"Width"_ustr, nHeight);
793
0
    xEndnotePagePropSet->setPropertyValue(u"Height"_ustr, nWidth);
794
0
}
795
}
796
797
void SwDocShell::Edit(
798
    weld::Window* pDialogParent,
799
    const UIName &rName,
800
    const UIName &rParent,
801
    const SfxStyleFamily nFamily,
802
    SfxStyleSearchBits nMask,
803
    const bool bNew,
804
    const OUString& sPage,
805
    SwWrtShell* pActShell,
806
    SfxRequest* pReq,
807
    sal_uInt16 nSlot)
808
0
{
809
0
    assert( GetWrtShell() );
810
0
    const bool bBasic = pReq && pReq->IsAPI();
811
0
    SfxStyleSheetBase *pStyle = nullptr;
812
813
0
    bool bModified = m_xDoc->getIDocumentState().IsModified();
814
815
0
    SwUndoId nNewStyleUndoId(SwUndoId::EMPTY);
816
817
0
    if( bNew )
818
0
    {
819
0
        if (!bBasic)
820
0
        {
821
            // start undo action in order to get only one undo action for the
822
            // UI new style + change style operations
823
0
            m_pWrtShell->StartUndo();
824
0
        }
825
826
0
        if( SfxStyleSearchBits::All != nMask && SfxStyleSearchBits::AllVisible != nMask && SfxStyleSearchBits::Used != nMask )
827
0
            nMask |= SfxStyleSearchBits::UserDefined;
828
0
        else
829
0
            nMask = SfxStyleSearchBits::UserDefined;
830
831
0
        if (nFamily == SfxStyleFamily::Para || nFamily == SfxStyleFamily::Char
832
0
            || nFamily == SfxStyleFamily::Frame || nFamily == SfxStyleFamily::Pseudo)
833
0
        {
834
            // Do Make undo append after an OK return from the style dialog below
835
0
            ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
836
0
            pStyle = &m_xBasePool->Make( rName.toString(), nFamily, nMask );
837
0
        }
838
0
        else
839
0
        {
840
0
            pStyle = &m_xBasePool->Make( rName.toString(), nFamily, nMask );
841
0
        }
842
843
        // set the current one as Parent
844
0
        SwDocStyleSheet* pDStyle = static_cast<SwDocStyleSheet*>(pStyle);
845
0
        switch( nFamily )
846
0
        {
847
0
            case SfxStyleFamily::Para:
848
0
            {
849
0
                if(!rParent.isEmpty())
850
0
                {
851
0
                    SwTextFormatColl* pColl = m_pWrtShell->FindTextFormatCollByName( rParent );
852
0
                    if(!pColl)
853
0
                    {
854
0
                        sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, SwGetPoolIdFromName::TxtColl);
855
0
                        if(USHRT_MAX != nId)
856
0
                            pColl = m_pWrtShell->GetTextCollFromPool( nId );
857
0
                    }
858
0
                    pDStyle->GetCollection()->SetDerivedFrom( pColl );
859
0
                    pDStyle->PresetParent( rParent.toString() );
860
0
                }
861
0
                else
862
0
                {
863
0
                    SwTextFormatColl* pColl = m_pWrtShell->GetCurTextFormatColl();
864
0
                    pDStyle->GetCollection()->SetDerivedFrom( pColl );
865
0
                    if( pColl )
866
0
                        pDStyle->PresetParent( pColl->GetName().toString() );
867
0
                }
868
0
            }
869
0
            break;
870
0
            case SfxStyleFamily::Char:
871
0
            {
872
0
                if(!rParent.isEmpty())
873
0
                {
874
0
                    SwCharFormat* pCFormat = m_pWrtShell->FindCharFormatByName(rParent);
875
0
                    if(!pCFormat)
876
0
                    {
877
0
                        sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, SwGetPoolIdFromName::ChrFmt);
878
0
                        if(USHRT_MAX != nId)
879
0
                            pCFormat = m_pWrtShell->GetCharFormatFromPool( nId );
880
0
                    }
881
882
0
                    pDStyle->GetCharFormat()->SetDerivedFrom( pCFormat );
883
0
                    pDStyle->PresetParent( rParent.toString() );
884
0
                }
885
0
                else
886
0
                {
887
0
                    SwCharFormat* pCFormat = m_pWrtShell->GetCurCharFormat();
888
0
                    pDStyle->GetCharFormat()->SetDerivedFrom( pCFormat );
889
0
                    if( pCFormat )
890
0
                        pDStyle->PresetParent( pCFormat->GetName().toString() );
891
0
                }
892
0
            }
893
0
            break;
894
0
            case SfxStyleFamily::Frame :
895
0
            {
896
0
                if(!rParent.isEmpty())
897
0
                {
898
0
                    SwFrameFormat* pFFormat = m_pWrtShell->GetDoc()->FindFrameFormatByName( rParent );
899
0
                    if(!pFFormat)
900
0
                    {
901
0
                        sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(rParent, SwGetPoolIdFromName::FrmFmt);
902
0
                        if(USHRT_MAX != nId)
903
0
                            pFFormat = m_pWrtShell->GetFrameFormatFromPool( nId );
904
0
                    }
905
0
                    pDStyle->GetFrameFormat()->SetDerivedFrom( pFFormat );
906
0
                    pDStyle->PresetParent( rParent.toString() );
907
0
                }
908
0
            }
909
0
            break;
910
0
            default: break;
911
0
        }
912
913
0
        if (!bBasic)
914
0
        {
915
            //Get the undo id for the type of style that was created in order to re-use that comment for the grouped
916
            //create style + change style operations
917
0
            m_pWrtShell->GetLastUndoInfo(nullptr, &nNewStyleUndoId);
918
0
        }
919
0
    }
920
0
    else
921
0
    {
922
0
        pStyle = m_xBasePool->Find( rName.toString(), nFamily );
923
0
        SAL_WARN_IF( !pStyle, "sw.ui", "Style not found" );
924
0
    }
925
926
0
    if(!pStyle)
927
0
        return;
928
929
    // put dialogues together
930
0
    rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pStyle) ) );
931
0
    if( SfxStyleFamily::Para == nFamily )
932
0
    {
933
0
        SfxItemSet& rSet = xTmp->GetItemSet();
934
0
        ::SwToSfxPageDescAttr( rSet );
935
        // merge list level indent attributes into the item set if needed
936
0
        xTmp->MergeIndentAttrsOfListStyle( rSet );
937
938
0
        ::ConvertAttrCharToGen(xTmp->GetItemSet(), /*bIsPara=*/true);
939
0
    }
940
0
    else if( SfxStyleFamily::Char == nFamily )
941
0
    {
942
0
        ::ConvertAttrCharToGen(xTmp->GetItemSet());
943
0
    }
944
945
0
    if(SfxStyleFamily::Page == nFamily || SfxStyleFamily::Para == nFamily)
946
0
    {
947
        // create needed items for XPropertyList entries from the DrawModel so that
948
        // the Area TabPage can access them
949
0
        SfxItemSet& rSet = xTmp->GetItemSet();
950
0
        const SwDrawModel* pDrawModel = GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
951
952
0
        rSet.Put(SvxColorListItem(pDrawModel->GetColorList(), SID_COLOR_TABLE));
953
0
        rSet.Put(SvxGradientListItem(pDrawModel->GetGradientList(), SID_GRADIENT_LIST));
954
0
        rSet.Put(SvxHatchListItem(pDrawModel->GetHatchList(), SID_HATCH_LIST));
955
0
        rSet.Put(SvxBitmapListItem(pDrawModel->GetBitmapList(), SID_BITMAP_LIST));
956
0
        rSet.Put(SvxPatternListItem(pDrawModel->GetPatternList(), SID_PATTERN_LIST));
957
958
0
        std::map<OUString, css::uno::Any> aGrabBagMap;
959
0
        if (SfxGrabBagItem const* pItem = rSet.GetItemIfSet(SID_ATTR_CHAR_GRABBAG))
960
0
            aGrabBagMap = pItem->GetGrabBag();
961
0
        bool bGutterAtTop
962
0
            = GetDoc()->getIDocumentSettingAccess().get(DocumentSettingId::GUTTER_AT_TOP);
963
0
        aGrabBagMap[u"GutterAtTop"_ustr] <<= bGutterAtTop;
964
0
        rSet.Put(SfxGrabBagItem(SID_ATTR_CHAR_GRABBAG, std::move(aGrabBagMap)));
965
0
    }
966
967
0
    SwWrtShell* pCurrShell = pActShell ? pActShell : m_pWrtShell;
968
0
    if (nFamily == SfxStyleFamily::Frame)
969
0
    {
970
0
        SfxItemSet& rSet = xTmp->GetItemSet();
971
0
        const SwViewOption* pVOpt = pCurrShell->GetViewOptions();
972
0
        rSet.Put(SfxBoolItem(FN_KEEP_ASPECT_RATIO, pVOpt->IsKeepRatio()));
973
0
    }
974
975
0
    if (!bBasic)
976
0
    {
977
        // prior to the dialog the HtmlMode at the DocShell is being sunk
978
0
        sal_uInt16 nHtmlMode = ::GetHtmlMode(this);
979
980
        // In HTML mode, we do not always have a printer. In order to show
981
        // the correct page size in the Format - Page dialog, we have to
982
        // get one here.
983
0
        if( ( HTMLMODE_ON & nHtmlMode ) &&
984
0
            !pCurrShell->getIDocumentDeviceAccess().getPrinter( false ) )
985
0
            pCurrShell->InitPrt( pCurrShell->getIDocumentDeviceAccess().getPrinter( true ) );
986
987
0
        PutItem(SfxUInt16Item(SID_HTML_MODE, nHtmlMode));
988
0
        FieldUnit eMetric = ::GetDfltMetric(0 != (HTMLMODE_ON&nHtmlMode));
989
0
        SwModule::get()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast<sal_uInt16>(eMetric)));
990
0
        SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
991
0
        if (!pDialogParent)
992
0
        {
993
0
            SAL_WARN("sw.ui", "no parent for dialog supplied, assuming document frame is good enough");
994
0
            pDialogParent = GetView()->GetFrameWeld();
995
0
        }
996
0
        VclPtr<SfxAbstractApplyTabDialog> pDlg(pFact->CreateTemplateDialog(pDialogParent,
997
0
                                                    *xTmp, nFamily, sPage, pCurrShell, bNew));
998
0
        auto pApplyStyleHelper = std::make_shared<ApplyStyle>(*this, bNew, xTmp, nFamily, pDlg.get(), m_xBasePool, bModified);
999
0
        pDlg->SetApplyHdl(LINK(pApplyStyleHelper.get(), ApplyStyle, ApplyHdl));
1000
1001
0
        std::shared_ptr<SfxRequest> pRequest;
1002
0
        if (pReq)
1003
0
        {
1004
0
            pRequest = std::make_shared<SfxRequest>(*pReq);
1005
0
            pReq->Ignore(); // the 'old' request is not relevant any more
1006
0
        }
1007
1008
0
        bool bIsDefaultPage = nFamily == SfxStyleFamily::Page
1009
0
                                    && rName == SwResId(STR_POOLPAGE_STANDARD)
1010
0
                                    && pStyle->IsUsed()
1011
0
                                    && !pStyle->IsUserDefined();
1012
1013
0
        pDlg->StartExecuteAsync([bIsDefaultPage, bNew, nFamily, nSlot, nNewStyleUndoId,
1014
0
                                 pApplyStyleHelper=std::move(pApplyStyleHelper),
1015
0
                                 pRequest=std::move(pRequest), xTmp, this](sal_Int32 nResult){
1016
0
            if (RET_OK == nResult)
1017
0
                pApplyStyleHelper->apply();
1018
1019
0
            if (bNew)
1020
0
            {
1021
0
                switch( nFamily )
1022
0
                {
1023
0
                    case SfxStyleFamily::Para:
1024
0
                    {
1025
0
                        if(!xTmp->GetParent().isEmpty())
1026
0
                        {
1027
0
                            SwTextFormatColl* pColl = m_pWrtShell->FindTextFormatCollByName(UIName(xTmp->GetParent()));
1028
0
                            if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1029
0
                            {
1030
0
                                GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1031
0
                                    std::make_unique<SwUndoTextFormatCollCreate>(xTmp->GetCollection(), pColl, *GetDoc()));
1032
0
                            }
1033
0
                        }
1034
0
                    }
1035
0
                    break;
1036
0
                    case SfxStyleFamily::Char:
1037
0
                    {
1038
0
                        if(!xTmp->GetParent().isEmpty())
1039
0
                        {
1040
0
                            SwCharFormat* pCFormat = m_pWrtShell->FindCharFormatByName(UIName(xTmp->GetParent()));
1041
0
                            if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1042
0
                            {
1043
0
                                GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1044
0
                                    std::make_unique<SwUndoCharFormatCreate>(xTmp->GetCharFormat(), pCFormat, *GetDoc()));
1045
0
                            }
1046
0
                        }
1047
0
                    }
1048
0
                    break;
1049
0
                    case SfxStyleFamily::Frame:
1050
0
                    {
1051
0
                        if(!xTmp->GetParent().isEmpty())
1052
0
                        {
1053
0
                            SwFrameFormat* pFFormat = m_pWrtShell->GetDoc()->FindFrameFormatByName(UIName(xTmp->GetParent()));
1054
0
                            if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1055
0
                            {
1056
0
                                GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1057
0
                                    std::make_unique<SwUndoFrameFormatCreate>(xTmp->GetFrameFormat(), pFFormat, *GetDoc()));
1058
0
                            }
1059
0
                        }
1060
0
                    }
1061
0
                    break;
1062
0
                    case SfxStyleFamily::Pseudo:
1063
0
                    {
1064
0
                        if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1065
0
                        {
1066
0
                            GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1067
0
                                std::make_unique<SwUndoNumruleCreate>(xTmp->GetNumRule(),
1068
0
                                                                      *GetDoc()));
1069
0
                        }
1070
0
                    }
1071
0
                    break;
1072
0
                    default: break;
1073
0
                }
1074
1075
0
                SwRewriter aRewriter;
1076
0
                aRewriter.AddRule(UndoArg1, xTmp->GetName());
1077
                //Group the create style and change style operations together under the
1078
                //one "create style" comment
1079
0
                m_pWrtShell->EndUndo(nNewStyleUndoId, &aRewriter);
1080
0
            }
1081
1082
0
            bool bDocModified = pApplyStyleHelper->DocIsModified();
1083
1084
0
            if (RET_OK != nResult)
1085
0
            {
1086
0
                if (bNew)
1087
0
                {
1088
0
                    GetWrtShell()->Undo();
1089
0
                    m_xDoc->GetIDocumentUndoRedo().ClearRedo();
1090
0
                }
1091
1092
0
                if (!bDocModified)
1093
0
                    m_xDoc->getIDocumentState().ResetModified();
1094
0
            }
1095
1096
            // Update Watermark if new page style was created
1097
0
            if (nSlot == SID_STYLE_NEW && nFamily == SfxStyleFamily::Page)
1098
0
            {
1099
0
                SwWrtShell* pShell = GetWrtShell();
1100
0
                const SfxWatermarkItem aWatermark = pShell->GetWatermark();
1101
0
                pShell->SetWatermark(aWatermark);
1102
0
            }
1103
1104
0
            pApplyStyleHelper->m_pDlg.disposeAndClear();
1105
0
            if (pRequest)
1106
0
                pRequest->Done();
1107
1108
0
            if (bIsDefaultPage && bDocModified)
1109
0
            {
1110
0
                uno::Reference< style::XStyleFamiliesSupplier > xStyleFamSupp(GetModel(), uno::UNO_QUERY);
1111
1112
0
                if (!xStyleFamSupp.is())
1113
0
                {
1114
0
                    SAL_WARN("sw.ui", "Ref to XStyleFamiliesSupplier is null.");
1115
0
                    return;
1116
0
                }
1117
1118
0
                syncEndnoteOrientation(xStyleFamSupp);
1119
0
            }
1120
0
        });
1121
0
    }
1122
0
    else
1123
0
    {
1124
        // prior to the dialog the HtmlMode at the DocShell is being sunk
1125
0
        PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(this)));
1126
1127
0
        GetWrtShell()->StartAllAction();
1128
1129
0
        if( SfxStyleFamily::Para == nFamily )
1130
0
        {
1131
0
            ::SfxToSwPageDescAttr( *GetWrtShell(), xTmp->GetItemSet() );
1132
0
            ::ConvertAttrGenToChar(xTmp->GetItemSet(), xTmp->GetItemSet(), /*bIsPara=*/true);
1133
0
        }
1134
0
        else
1135
0
        {
1136
0
            ::ConvertAttrGenToChar(xTmp->GetItemSet(), xTmp->GetItemSet());
1137
0
        }
1138
0
        if(SfxStyleFamily::Page == nFamily)
1139
0
            m_pView->InvalidateRulerPos();
1140
1141
0
        m_xDoc->getIDocumentState().SetModified();
1142
0
        if( !bModified )        // Bug 57028
1143
0
        {
1144
0
            m_xDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
1145
0
        }
1146
0
        GetWrtShell()->EndAllAction();
1147
0
    }
1148
0
}
1149
1150
void SwDocShell::Delete(const OUString &rName, SfxStyleFamily nFamily)
1151
0
{
1152
0
    SfxStyleSheetBase *pStyle = m_xBasePool->Find(rName, nFamily);
1153
1154
0
    if(pStyle)
1155
0
    {
1156
0
        assert( GetWrtShell() );
1157
1158
0
        GetWrtShell()->StartAllAction();
1159
0
        m_xBasePool->Remove(pStyle);
1160
0
        GetWrtShell()->EndAllAction();
1161
0
    }
1162
0
}
1163
1164
void SwDocShell::Hide(const OUString &rName, SfxStyleFamily nFamily, bool bHidden)
1165
0
{
1166
0
    SfxStyleSheetBase *pStyle = m_xBasePool->Find(rName, nFamily);
1167
1168
0
    if(pStyle)
1169
0
    {
1170
0
        assert( GetWrtShell() );
1171
1172
0
        GetWrtShell()->StartAllAction();
1173
0
        rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pStyle) ) );
1174
0
        xTmp->SetHidden( bHidden );
1175
0
        GetWrtShell()->EndAllAction();
1176
0
    }
1177
0
}
1178
1179
0
#define MAX_CHAR_IN_INLINE_HEADING 120
1180
bool SwDocShell::MakeInlineHeading(SwWrtShell *pSh, SwTextFormatColl* pColl, const sal_uInt16 nMode)
1181
0
{
1182
    // insert an inline heading frame, if only MAX_CHAR_IN_INLINE_HEADING or less
1183
    // characters are selected beginning of a single paragraph, but not the full paragraph
1184
    // TODO extend it for multiple selections
1185
0
    if ( pSh->IsSelOnePara() && !pSh->IsSelFullPara() && pSh->IsSelStartPara() &&
1186
0
            GetView()->GetSelectionText().getLength() < MAX_CHAR_IN_INLINE_HEADING &&
1187
0
            0 < GetView()->GetSelectionText().getLength() )
1188
0
    {
1189
0
        SwTextFormatColl *pLocal = pColl? pColl: (*GetDoc()->GetTextFormatColls())[0];
1190
        // don't put inline heading in a frame (it would be enough to limit for inline heading
1191
        // frames, but the recent FN_INSERT_FRAME cannot handle the insertion inside a frame
1192
        // correctly)
1193
        // TODO: allow to insert inline headings in a (not an Inline Heading) text frame
1194
0
        if ( pSh->GetCursor()->GetPointNode() !=
1195
0
                *SwOutlineNodes::GetRootNode( &pSh->GetCursor()->GetPointNode(), /*bInlineHeading=*/false ) )
1196
0
        {
1197
0
            return false;
1198
0
        }
1199
1200
        // put inside a single Undo
1201
0
        SwRewriter aRewriter;
1202
0
        aRewriter.AddRule(UndoArg1, pLocal->GetName());
1203
0
        GetWrtShell()->StartUndo(SwUndoId::SETFMTCOLL, &aRewriter);
1204
1205
        // anchor as character
1206
0
        SfxUInt16Item aAnchor(FN_INSERT_FRAME, static_cast<sal_uInt16>(1));
1207
0
        SvxSizeItem aSizeItem(FN_PARAM_2, Size(1, 1));
1208
0
        GetView()->GetViewFrame().GetDispatcher()->ExecuteList(FN_INSERT_FRAME,
1209
0
                SfxCallMode::SYNCHRON|SfxCallMode::RECORD, { &aAnchor, &aSizeItem });
1210
0
        if ( pSh->IsFrameSelected() )
1211
0
        {
1212
            // use the associated borderless frame style "Inline Heading"
1213
0
            SwDocStyleSheet* pStyle2 = static_cast<SwDocStyleSheet*>(
1214
0
                            m_xBasePool->Find( "Inline Heading", SfxStyleFamily::Frame));
1215
0
            SAL_WARN_IF( !pStyle2, "sw.ui", "Style not found" );
1216
0
            if(pStyle2)
1217
0
                pSh->SetFrameFormat( pStyle2->GetFrameFormat() );
1218
1219
            // select the text content of the frame, and apply the paragraph style
1220
0
            pSh->UnSelectFrame();
1221
0
            pSh->LeaveSelFrameMode();
1222
0
            pSh->MoveSection( GoCurrSection, fnSectionEnd );
1223
0
            pSh->SelAll();
1224
1225
0
            const bool bResetAllCharAttrs(nMode & KEY_MOD1);
1226
0
            pSh->SetTextFormatColl(pColl, true, bResetAllCharAttrs);
1227
1228
            // zero the upper and lower margins of the paragraph (also an interoperability issue)
1229
0
            SfxItemSetFixed<RES_UL_SPACE, RES_UL_SPACE> aSet2(pSh->GetAttrPool());
1230
0
            pSh->GetCurAttr( aSet2 );
1231
0
            SvxULSpaceItem aUL( 0, 0, RES_UL_SPACE );
1232
0
            pSh->SetAttrItem( aUL );
1233
1234
            // leave the inline heading frame
1235
0
            GetView()->GetViewFrame().GetDispatcher()->Execute(FN_ESCAPE, SfxCallMode::ASYNCHRON);
1236
0
            GetView()->GetViewFrame().GetDispatcher()->Execute(FN_ESCAPE, SfxCallMode::ASYNCHRON);
1237
0
            GetView()->GetViewFrame().GetDispatcher()->Execute(FN_ESCAPE, SfxCallMode::SYNCHRON);
1238
1239
0
            GetWrtShell()->EndUndo();
1240
0
            return true;
1241
0
        }
1242
0
    }
1243
0
    return false;
1244
0
}
1245
1246
// apply template
1247
SfxStyleFamily SwDocShell::ApplyStyles(const OUString &rName, SfxStyleFamily nFamily,
1248
                               SwWrtShell* pShell, const sal_uInt16 nMode )
1249
0
{
1250
0
    SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>( m_xBasePool->Find( rName, nFamily ) );
1251
1252
0
    SAL_WARN_IF( !pStyle, "sw.ui", "Style not found" );
1253
1254
0
    if(!pStyle)
1255
0
        return SfxStyleFamily::None;
1256
1257
0
    SwWrtShell *pSh = pShell ? pShell : GetWrtShell();
1258
1259
0
    assert( pSh );
1260
1261
0
    pSh->StartAllAction();
1262
1263
0
    switch (nFamily)
1264
0
    {
1265
0
        case SfxStyleFamily::Char:
1266
0
        {
1267
0
            SwFormatCharFormat aFormat(pStyle->GetCharFormat());
1268
0
            SetAttrMode nFlags = (nMode & KEY_SHIFT) ?
1269
0
                SetAttrMode::DONTREPLACE : SetAttrMode::DEFAULT;
1270
0
            if (nMode & KEY_MOD1)
1271
0
                nFlags |= SetAttrMode::REMOVE_ALL_ATTR;
1272
0
            pSh->SetAttrItem( aFormat, nFlags );
1273
1274
0
            break;
1275
0
        }
1276
0
        case SfxStyleFamily::Para:
1277
0
        {
1278
0
            if (OutlinerView *pOLV = lcl_GetPostItOutlinerView(*pSh))
1279
0
                pOLV->SetStyleSheet(rName);
1280
0
            else
1281
0
            {
1282
                // When outline-folding is enabled, MakeAllOutlineContentTemporarilyVisible makes
1283
                // application of a paragraph style that has an outline-level greater than the previous
1284
                // outline node become folded content of the previous outline node if the previous
1285
                // outline node's content is folded.
1286
0
                MakeAllOutlineContentTemporarilyVisible a(GetDoc());
1287
1288
                // if the first 120 or less characters are selected, but not the full paragraph,
1289
                // create an inline heading from the selected text
1290
0
                SwTextFormatColl* pColl = pStyle->GetCollection();
1291
0
                if ( MakeInlineHeading( pSh, pColl, nMode ) )
1292
0
                    break;
1293
1294
                // #i62675#
1295
                // clear also list attributes at affected text nodes, if paragraph
1296
                // style has the list style attribute set.
1297
0
                const bool bResetAllCharAttrs(nMode & KEY_MOD1);
1298
0
                const bool bResetListAttrs
1299
0
                    = bResetAllCharAttrs
1300
0
                      || (pColl && pColl->GetItemState(RES_PARATR_NUMRULE) == SfxItemState::SET);
1301
0
                pSh->SetTextFormatColl(pColl, bResetListAttrs, bResetAllCharAttrs);
1302
0
            }
1303
0
            break;
1304
0
        }
1305
0
        case SfxStyleFamily::Frame:
1306
0
        {
1307
0
            if ( pSh->IsFrameSelected() )
1308
0
                pSh->SetFrameFormat( pStyle->GetFrameFormat() );
1309
0
            break;
1310
0
        }
1311
0
        case SfxStyleFamily::Page:
1312
0
        {
1313
0
            pSh->SetPageStyle(pStyle->GetPageDesc()->GetName());
1314
0
            break;
1315
0
        }
1316
0
        case SfxStyleFamily::Pseudo:
1317
0
        {
1318
            // reset indent attribute on applying list style
1319
            // continue list of list style
1320
0
            const SwNumRule* pNumRule = pStyle->GetNumRule();
1321
0
            if (pNumRule->GetName() == SwResId(STR_POOLNUMRULE_NOLIST))
1322
0
            {
1323
0
                if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
1324
0
                    pViewFrm->GetDispatcher()->Execute(FN_NUM_BULLET_OFF);
1325
0
                break;
1326
0
            }
1327
0
            const OUString sListIdForStyle =pNumRule->GetDefaultListId();
1328
0
            pSh->SetCurNumRule( *pNumRule, false, sListIdForStyle, true );
1329
0
            break;
1330
0
        }
1331
0
        case SfxStyleFamily::Table:
1332
0
        {
1333
0
            pSh->SetTableStyle(TableStyleName(pStyle->GetName()));
1334
0
            break;
1335
0
        }
1336
0
        default:
1337
0
            OSL_FAIL("Unknown family");
1338
0
    }
1339
0
    pSh->EndAllAction();
1340
1341
0
    return nFamily;
1342
0
}
1343
1344
// start watering-can
1345
SfxStyleFamily SwDocShell::DoWaterCan(const OUString &rName, SfxStyleFamily nFamily)
1346
0
{
1347
0
    assert( GetWrtShell() );
1348
1349
0
    SwEditWin& rEdtWin = m_pView->GetEditWin();
1350
0
    SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
1351
0
    bool bWaterCan = !(pApply && pApply->eType != SfxStyleFamily(0));
1352
1353
0
    if( rName.isEmpty() )
1354
0
        bWaterCan = false;
1355
1356
0
    SwApplyTemplate aTemplate;
1357
0
    aTemplate.eType = nFamily;
1358
1359
0
    if(bWaterCan)
1360
0
    {
1361
0
        SwDocStyleSheet* pStyle =
1362
0
            static_cast<SwDocStyleSheet*>( m_xBasePool->Find(rName, nFamily) );
1363
1364
0
        SAL_WARN_IF( !pStyle, "sw.ui", "Where's the StyleSheet" );
1365
1366
0
        if(!pStyle) return nFamily;
1367
1368
0
        switch(nFamily)
1369
0
        {
1370
0
            case SfxStyleFamily::Char:
1371
0
                aTemplate.aColl.pCharFormat = pStyle->GetCharFormat();
1372
0
                break;
1373
0
            case SfxStyleFamily::Para:
1374
0
                aTemplate.aColl.pTextColl = pStyle->GetCollection();
1375
0
                break;
1376
0
            case SfxStyleFamily::Frame:
1377
0
                aTemplate.aColl.pFrameFormat = pStyle->GetFrameFormat();
1378
0
                break;
1379
0
            case SfxStyleFamily::Page:
1380
0
                aTemplate.aColl.pPageDesc = const_cast<SwPageDesc*>(pStyle->GetPageDesc());
1381
0
                break;
1382
0
            case SfxStyleFamily::Pseudo:
1383
0
                aTemplate.aColl.pNumRule = const_cast<SwNumRule*>(pStyle->GetNumRule());
1384
0
                break;
1385
1386
0
            default:
1387
0
                OSL_FAIL("Unknown family");
1388
0
        }
1389
0
    }
1390
0
    else
1391
0
        aTemplate.eType = SfxStyleFamily(0);
1392
1393
0
    m_pView->GetEditWin().SetApplyTemplate(aTemplate);
1394
1395
0
    return nFamily;
1396
0
}
1397
1398
// update template
1399
void SwDocShell::UpdateStyle(const UIName &rName, SfxStyleFamily nFamily, SwWrtShell* pShell)
1400
0
{
1401
0
    SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell();
1402
0
    assert( pCurrWrtShell );
1403
1404
0
    SwDocStyleSheet* pStyle =
1405
0
        static_cast<SwDocStyleSheet*>( m_xBasePool->Find(rName.toString(), nFamily) );
1406
1407
0
    if (!pStyle)
1408
0
        return;
1409
1410
0
    switch(nFamily)
1411
0
    {
1412
0
        case SfxStyleFamily::Para:
1413
0
        {
1414
0
            SwTextFormatColl* pColl = pStyle->GetCollection();
1415
0
            if(pColl && !pColl->IsDefault())
1416
0
            {
1417
0
                GetWrtShell()->StartAllAction();
1418
1419
0
                SwRewriter aRewriter;
1420
0
                aRewriter.AddRule(UndoArg1, pColl->GetName());
1421
1422
0
                GetWrtShell()->StartUndo(SwUndoId::INSFMTATTR, &aRewriter);
1423
0
                GetWrtShell()->FillByEx(pColl);
1424
                    // also apply template to remove hard set attributes
1425
0
                GetWrtShell()->SetTextFormatColl( pColl );
1426
0
                GetWrtShell()->EndUndo();
1427
0
                GetWrtShell()->EndAllAction();
1428
0
            }
1429
0
            break;
1430
0
        }
1431
0
        case SfxStyleFamily::Frame:
1432
0
        {
1433
0
            SwFrameFormat* pFrame = pStyle->GetFrameFormat();
1434
0
            if( pCurrWrtShell->IsFrameSelected() && pFrame && !pFrame->IsDefault() )
1435
0
            {
1436
0
                SfxItemSet aSet( GetPool(), aFrameFormatSetRange );
1437
0
                pCurrWrtShell->StartAllAction();
1438
0
                pCurrWrtShell->GetFlyFrameAttr( aSet );
1439
1440
                // #i105535#
1441
                // no update of anchor attribute
1442
0
                aSet.ClearItem( RES_ANCHOR );
1443
1444
0
                pFrame->SetFormatAttr( aSet );
1445
1446
                    // also apply template to remove hard set attributes
1447
0
                pCurrWrtShell->SetFrameFormat( pFrame, true );
1448
0
                pCurrWrtShell->EndAllAction();
1449
0
            }
1450
0
        }
1451
0
        break;
1452
0
        case SfxStyleFamily::Char:
1453
0
        {
1454
0
            SwCharFormat* pChar = pStyle->GetCharFormat();
1455
0
            if( pChar && !pChar->IsDefault() )
1456
0
            {
1457
0
                pCurrWrtShell->StartAllAction();
1458
0
                pCurrWrtShell->FillByEx(pChar);
1459
                // also apply template to remove hard set attributes
1460
0
                pCurrWrtShell->EndAllAction();
1461
0
            }
1462
1463
0
        }
1464
0
        break;
1465
0
        case SfxStyleFamily::Pseudo:
1466
0
        {
1467
0
            const SwNumRule* pCurRule;
1468
0
            if( pStyle->GetNumRule() &&
1469
0
                nullptr != ( pCurRule = pCurrWrtShell->GetNumRuleAtCurrCursorPos() ))
1470
0
            {
1471
0
                SwNumRule aRule( *pCurRule );
1472
                // #i91400#
1473
0
                aRule.SetName( pStyle->GetNumRule()->GetName(),
1474
0
                               pCurrWrtShell->GetDoc()->getIDocumentListsAccess() );
1475
0
                pCurrWrtShell->ChgNumRuleFormats( aRule );
1476
0
            }
1477
0
        }
1478
0
        break;
1479
0
        case SfxStyleFamily::Table:
1480
0
        {
1481
0
            if (SwFEShell* pFEShell = GetFEShell())
1482
0
            {
1483
0
                if(pFEShell->IsTableMode())
1484
0
                {
1485
0
                    pFEShell->TableCursorToCursor();
1486
0
                }
1487
0
            }
1488
0
            SwTableAutoFormat aFormat(TableStyleName(rName.toString()));
1489
0
            if (pCurrWrtShell->GetTableAutoFormat(aFormat))
1490
0
            {
1491
0
                pCurrWrtShell->StartAllAction();
1492
0
                pCurrWrtShell->GetDoc()->ChgTableStyle(TableStyleName(rName.toString()), aFormat);
1493
0
                pCurrWrtShell->EndAllAction();
1494
0
            }
1495
1496
0
        }
1497
0
        break;
1498
0
        default: break;
1499
0
    }
1500
1501
0
    m_xDoc->BroadcastStyleOperation(rName, nFamily, SfxHintId::StyleSheetModified);
1502
0
}
1503
1504
// NewByExample
1505
void SwDocShell::MakeByExample( const UIName &rName, SfxStyleFamily nFamily,
1506
                                    SfxStyleSearchBits nMask, SwWrtShell* pShell )
1507
0
{
1508
0
    SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell();
1509
0
    SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>( m_xBasePool->Find(
1510
0
                                            rName.toString(), nFamily ) );
1511
0
    if(!pStyle)
1512
0
    {
1513
        // preserve the current mask of PI, then the new one is
1514
        // immediately merged with the viewable area
1515
0
        if( SfxStyleSearchBits::All == nMask || SfxStyleSearchBits::Used == nMask )
1516
0
            nMask = SfxStyleSearchBits::UserDefined;
1517
0
        else
1518
0
            nMask |= SfxStyleSearchBits::UserDefined;
1519
1520
0
        if (nFamily == SfxStyleFamily::Para || nFamily == SfxStyleFamily::Char || nFamily == SfxStyleFamily::Frame)
1521
0
        {
1522
            // Prevent undo append from being done during paragraph, character, and frame style Make. Do it later
1523
0
            ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
1524
0
            pStyle = static_cast<SwDocStyleSheet*>(&m_xBasePool->Make(rName.toString(), nFamily, nMask));
1525
0
        }
1526
0
        else
1527
0
        {
1528
0
            pStyle = static_cast<SwDocStyleSheet*>(&m_xBasePool->Make(rName.toString(), nFamily, nMask));
1529
0
        }
1530
0
    }
1531
1532
0
    switch(nFamily)
1533
0
    {
1534
0
        case  SfxStyleFamily::Para:
1535
0
        {
1536
0
            SwTextFormatColl* pColl = pStyle->GetCollection();
1537
0
            if(pColl && !pColl->IsDefault())
1538
0
            {
1539
0
                pCurrWrtShell->StartAllAction();
1540
0
                pCurrWrtShell->FillByEx(pColl);
1541
                    // also apply template to remove hard set attributes
1542
0
                SwTextFormatColl * pDerivedFrom = pCurrWrtShell->GetCurTextFormatColl();
1543
0
                pColl->SetDerivedFrom(pDerivedFrom);
1544
1545
                    // set the mask at the Collection:
1546
0
                sal_uInt16 nId = pColl->GetPoolFormatId() & 0x87ff;
1547
0
                switch( nMask & static_cast<SfxStyleSearchBits>(0x0fff) )
1548
0
                {
1549
0
                    case SfxStyleSearchBits::SwText:
1550
0
                        nId |= COLL_TEXT_BITS;
1551
0
                        break;
1552
0
                    case SfxStyleSearchBits::SwChapter:
1553
0
                        nId |= COLL_DOC_BITS;
1554
0
                        break;
1555
0
                    case SfxStyleSearchBits::SwList:
1556
0
                        nId |= COLL_LISTS_BITS;
1557
0
                        break;
1558
0
                    case SfxStyleSearchBits::SwIndex:
1559
0
                        nId |= COLL_REGISTER_BITS;
1560
0
                        break;
1561
0
                    case SfxStyleSearchBits::SwExtra:
1562
0
                        nId |= COLL_EXTRA_BITS;
1563
0
                        break;
1564
0
                    case SfxStyleSearchBits::SwHtml:
1565
0
                        nId |= COLL_HTML_BITS;
1566
0
                        break;
1567
0
                    default: break;
1568
0
                }
1569
0
                pColl->SetPoolFormatId(nId);
1570
1571
0
                if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1572
0
                {
1573
0
                    GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1574
0
                        std::make_unique<SwUndoTextFormatCollCreate>(pColl, pDerivedFrom, *GetDoc()));
1575
0
                }
1576
0
                pCurrWrtShell->SetTextFormatColl(pColl);
1577
0
                pCurrWrtShell->EndAllAction();
1578
0
            }
1579
0
        }
1580
0
        break;
1581
0
        case SfxStyleFamily::Frame:
1582
0
        {
1583
0
            SwFrameFormat* pFrame = pStyle->GetFrameFormat();
1584
0
            if(pCurrWrtShell->IsFrameSelected() && pFrame && !pFrame->IsDefault())
1585
0
            {
1586
0
                pCurrWrtShell->StartAllAction();
1587
1588
0
                SfxItemSet aSet(GetPool(), aFrameFormatSetRange );
1589
0
                pCurrWrtShell->GetFlyFrameAttr( aSet );
1590
0
                aSet.ClearItem(RES_ANCHOR); // tdf#112574 no anchor in styles
1591
1592
0
                SwFrameFormat* pFFormat = pCurrWrtShell->GetSelectedFrameFormat();
1593
0
                pFrame->SetDerivedFrom( pFFormat );
1594
0
                pFrame->SetFormatAttr( aSet );
1595
0
                if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1596
0
                {
1597
0
                    GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1598
0
                        std::make_unique<SwUndoFrameFormatCreate>(pFrame, pFFormat, *GetDoc()));
1599
0
                }
1600
                // also apply template to remove hard set attributes
1601
0
                pCurrWrtShell->SetFrameFormat(pFrame);
1602
0
                pCurrWrtShell->EndAllAction();
1603
0
            }
1604
0
        }
1605
0
        break;
1606
0
        case SfxStyleFamily::Char:
1607
0
        {
1608
0
            SwCharFormat* pChar = pStyle->GetCharFormat();
1609
0
            if(pChar && !pChar->IsDefault())
1610
0
            {
1611
0
                pCurrWrtShell->StartAllAction();
1612
0
                pCurrWrtShell->FillByEx( pChar );
1613
0
                SwCharFormat * pDerivedFrom = pCurrWrtShell->GetCurCharFormat();
1614
0
                pChar->SetDerivedFrom( pDerivedFrom );
1615
0
                SwFormatCharFormat aFormat( pChar );
1616
1617
0
                if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1618
0
                {
1619
                    // Looks like sometimes pDerivedFrom can be null and this is not supported by redo code
1620
                    // So use default format as a derived from in such situations
1621
0
                    GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1622
0
                        std::make_unique<SwUndoCharFormatCreate>(
1623
0
                            pChar, pDerivedFrom ? pDerivedFrom : GetDoc()->GetDfltCharFormat(),
1624
0
                            *GetDoc()));
1625
0
                }
1626
0
                pCurrWrtShell->SetAttrItem(aFormat);
1627
0
                pCurrWrtShell->EndAllAction();
1628
0
            }
1629
0
        }
1630
0
        break;
1631
1632
0
        case SfxStyleFamily::Page:
1633
0
        {
1634
0
            pCurrWrtShell->StartAllAction();
1635
0
            size_t nPgDsc = pCurrWrtShell->GetCurPageDesc();
1636
0
            SwPageDesc& rSrc = const_cast<SwPageDesc&>(pCurrWrtShell->GetPageDesc( nPgDsc ));
1637
0
            SwPageDesc& rDest = *const_cast<SwPageDesc*>(pStyle->GetPageDesc());
1638
1639
0
            sal_uInt16 nPoolId = rDest.GetPoolFormatId();
1640
0
            sal_uInt16 nHId = rDest.GetPoolHelpId();
1641
0
            sal_uInt8 nHFId = rDest.GetPoolHlpFileId();
1642
1643
0
            pCurrWrtShell->GetDoc()->CopyPageDesc( rSrc, rDest );
1644
1645
            // PoolId must NEVER be copied!
1646
0
            rDest.SetPoolFormatId( nPoolId );
1647
0
            rDest.SetPoolHelpId( nHId );
1648
0
            rDest.SetPoolHlpFileId( nHFId );
1649
1650
            // when Headers/Footers are created, there is no Undo anymore!
1651
0
            pCurrWrtShell->GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj();
1652
1653
0
            pCurrWrtShell->EndAllAction();
1654
0
        }
1655
0
        break;
1656
1657
0
        case SfxStyleFamily::Pseudo:
1658
0
        {
1659
0
            const SwNumRule* pCurRule = pCurrWrtShell->GetNumRuleAtCurrCursorPos();
1660
1661
0
            if (pCurRule)
1662
0
            {
1663
0
                pCurrWrtShell->StartAllAction();
1664
1665
0
                SwNumRule aRule( *pCurRule );
1666
0
                UIName sOrigRule( aRule.GetName() );
1667
                // #i91400#
1668
0
                aRule.SetName( pStyle->GetNumRule()->GetName(),
1669
0
                               pCurrWrtShell->GetDoc()->getIDocumentListsAccess() );
1670
0
                pCurrWrtShell->ChgNumRuleFormats( aRule );
1671
1672
0
                pCurrWrtShell->ReplaceNumRule( sOrigRule, aRule.GetName() );
1673
1674
0
                pCurrWrtShell->EndAllAction();
1675
0
            }
1676
0
        }
1677
0
        break;
1678
1679
0
        case SfxStyleFamily::Table:
1680
0
        {
1681
0
            SwTableAutoFormat* pFormat = pStyle->GetTableFormat();
1682
0
            if (pCurrWrtShell->GetTableAutoFormat(*pFormat))
1683
0
            {
1684
0
                pCurrWrtShell->StartAllAction();
1685
1686
0
                pCurrWrtShell->SetTableStyle(TableStyleName(rName.toString()));
1687
1688
0
                pCurrWrtShell->EndAllAction();
1689
0
            }
1690
0
        }
1691
0
        break;
1692
1693
0
        default: break;
1694
0
    }
1695
0
}
1696
1697
sfx::AccessibilityIssueCollection SwDocShell::runAccessibilityCheck()
1698
0
{
1699
0
#if !ENABLE_WASM_STRIP_ACCESSIBILITY
1700
0
    sw::AccessibilityCheck aCheck(m_xDoc.get());
1701
0
    aCheck.check();
1702
0
    return aCheck.getIssueCollection();
1703
#else
1704
    return sfx::AccessibilityIssueCollection();
1705
#endif
1706
0
}
1707
1708
std::set<Color> SwDocShell::GetDocColors()
1709
0
{
1710
0
    return m_xDoc->GetDocColors();
1711
0
}
1712
1713
std::shared_ptr<model::ColorSet> SwDocShell::GetThemeColors()
1714
0
{
1715
0
    SdrModel* pModel = m_xDoc->getIDocumentDrawModelAccess().GetDrawModel();
1716
0
    if (!pModel)
1717
0
        return {};
1718
0
    auto const& pTheme = pModel->getTheme();
1719
0
    if (!pTheme)
1720
0
        return {};
1721
0
    return pTheme->getColorSet();
1722
0
}
1723
1724
void  SwDocShell::LoadStyles( SfxObjectShell& rSource )
1725
0
{
1726
0
    LoadStyles_(rSource, false);
1727
0
}
1728
1729
// bPreserveCurrentDocument determines whether SetFixFields() is called
1730
// This call modifies the source document. This mustn't happen when the source
1731
// is a document the user is working on.
1732
// Calls of ::LoadStyles() normally use files especially loaded for the purpose
1733
// of importing styles.
1734
void SwDocShell::LoadStyles_( SfxObjectShell& rSource, bool bPreserveCurrentDocument )
1735
0
{
1736
/*  [Description]
1737
1738
    This method is called by SFx if Styles have to be reloaded from a
1739
    document-template. Existing Styles should be overwritten by that.
1740
    That's why the document has to be reformatted. Therefore applications
1741
    will usually override this method and call the baseclass' implementation
1742
    in their implementation.
1743
*/
1744
    // When the source is our document, we do the checking ourselves
1745
    // (much quicker and doesn't use the crutch StxStylePool).
1746
0
    if( dynamic_cast<const SwDocShell*>( &rSource) !=  nullptr)
1747
0
    {
1748
        // in order for the Headers/Footers not to get the fixed content
1749
        // of the template, update all the Source's
1750
        // FixFields once.
1751
0
        if(!bPreserveCurrentDocument)
1752
0
            static_cast<SwDocShell&>(rSource).m_xDoc->getIDocumentFieldsAccess().SetFixFields(nullptr);
1753
0
        if (m_pWrtShell)
1754
0
        {
1755
            // rhbz#818557, fdo#58893: EndAllAction will call SelectShell(),
1756
            // which pushes a bunch of SfxShells that are not cleared
1757
            // (for unknown reasons) when closing the document, causing crash;
1758
            // setting g_bNoInterrupt appears to avoid the problem.
1759
0
            ::comphelper::FlagRestorationGuard g(g_bNoInterrupt, true);
1760
0
            m_pWrtShell->StartAllAction();
1761
0
            m_xDoc->ReplaceStyles( *static_cast<SwDocShell&>(rSource).m_xDoc );
1762
0
            m_pWrtShell->EndAllAction();
1763
0
        }
1764
0
        else
1765
0
        {
1766
0
            bool bModified = m_xDoc->getIDocumentState().IsModified();
1767
0
            m_xDoc->ReplaceStyles( *static_cast<SwDocShell&>(rSource).m_xDoc );
1768
0
            if (!bModified && m_xDoc->getIDocumentState().IsModified() && !m_pView)
1769
0
            {
1770
                // the View is created later, but overwrites the Modify-Flag.
1771
                // Undo doesn't work anymore anyways.
1772
0
                m_xDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
1773
0
            }
1774
0
        }
1775
0
    }
1776
0
    else
1777
0
        SfxObjectShell::LoadStyles( rSource );
1778
0
}
1779
1780
void SwDocShell::FormatPage(
1781
    weld::Window* pDialogParent,
1782
    const UIName& rPage,
1783
    const OUString& rPageId,
1784
    SwWrtShell& rActShell,
1785
    SfxRequest* pRequest)
1786
0
{
1787
0
    Edit(pDialogParent, rPage, UIName(), SfxStyleFamily::Page, SfxStyleSearchBits::Auto, false, rPageId, &rActShell, pRequest);
1788
0
}
1789
1790
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */