1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_wasm_strip.h>
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 <svtools/htmlcfg.hxx>
47 #include <svx/xdef.hxx>
48 #include <SwStyleNameMapper.hxx>
49 #include <SwRewriter.hxx>
50 #include <numrule.hxx>
52 #include <svx/drawitem.hxx>
59 #include <viewopt.hxx>
61 #include <drawdoc.hxx>
62 #include <IDocumentDrawModelAccess.hxx>
63 #include <IDocumentUndoRedo.hxx>
64 #include <IDocumentSettingAccess.hxx>
65 #include <IDocumentDeviceAccess.hxx>
66 #include <IDocumentFieldsAccess.hxx>
67 #include <IDocumentState.hxx>
69 #include <charfmt.hxx>
70 #include <poolfmt.hxx>
71 #include <pagedesc.hxx>
72 #include <docstyle.hxx>
73 #include <uiitems.hxx>
76 #include <unochart.hxx>
77 #include <swabstdlg.hxx>
78 #include <tblafmt.hxx>
79 #include <sfx2/watermarkitem.hxx>
80 #include <svl/grabbagitem.hxx>
81 #include <SwUndoFmt.hxx>
82 #include <strings.hrc>
83 #include <AccessibilityCheck.hxx>
84 #include <docmodel/theme/Theme.hxx>
85 #include <svx/svdpage.hxx>
87 using namespace ::com::sun::star
;
89 void SwDocShell::StateStyleSheet(SfxItemSet
& rSet
, SwWrtShell
* pSh
)
91 SfxWhichIter
aIter(rSet
);
92 sal_uInt16 nWhich
= aIter
.FirstWhich();
93 SfxStyleFamily nActualFamily
= SfxStyleFamily(USHRT_MAX
);
95 SwWrtShell
* pShell
= pSh
? pSh
: GetWrtShell();
100 rSet
.DisableItem(nWhich
);
101 nWhich
= aIter
.NextWhich();
107 SfxViewFrame
& rFrame
= pShell
->GetView().GetViewFrame();
108 std::unique_ptr
<SfxUInt16Item
> pFamilyItem
;
109 rFrame
.GetBindings().QueryState(SID_STYLE_FAMILY
, pFamilyItem
);
112 nActualFamily
= static_cast<SfxStyleFamily
>(pFamilyItem
->GetValue());
118 // determine current template to every family
120 SwTableAutoFormat
aTableAutoFormat("dummy"); // needed to check if can take a table auto format at current cursor position
123 case SID_STYLE_APPLY
:
124 {// here the template and its family are passed to the StyleBox
125 // so that this family is being showed
126 if(pShell
->IsFrameSelected())
128 SwFrameFormat
* pFormat
= pShell
->GetSelectedFrameFormat();
130 aName
= pFormat
->GetName();
134 SwTextFormatColl
* pColl
= pShell
->GetCurTextFormatColl();
136 aName
= pColl
->GetName();
138 rSet
.Put(SfxTemplateItem(nWhich
, aName
));
141 case SID_STYLE_FAMILY1
:
142 if( !pShell
->IsFrameSelected() )
144 SwCharFormat
* pFormat
= pShell
->GetCurCharFormat();
146 aName
= pFormat
->GetName();
148 aName
= SwResId(STR_POOLCHR_STANDARD
);
149 rSet
.Put(SfxTemplateItem(nWhich
, aName
));
153 case SID_STYLE_FAMILY2
:
154 if(!pShell
->IsFrameSelected())
157 SwTextFormatColl
* pColl
= pShell
->GetCurTextFormatColl();
160 aName
= pColl
->GetName();
161 sal_uInt16 nId
= pColl
->GetPoolFormatId();
162 SwStyleNameMapper::FillProgName(nId
, aProgName
);
165 SfxTemplateItem
aItem(nWhich
, aName
, aProgName
);
167 SfxStyleSearchBits nMask
= SfxStyleSearchBits::Auto
;
168 if (m_xDoc
->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE
))
169 nMask
= SfxStyleSearchBits::SwHtml
;
172 const FrameTypeFlags nSelection
= pShell
->GetFrameType(nullptr,true);
173 if(pShell
->GetCurTOX())
174 nMask
= SfxStyleSearchBits::SwIndex
;
175 else if(nSelection
& FrameTypeFlags::HEADER
||
176 nSelection
& FrameTypeFlags::FOOTER
||
177 nSelection
& FrameTypeFlags::TABLE
||
178 nSelection
& FrameTypeFlags::FLY_ANY
||
179 nSelection
& FrameTypeFlags::FOOTNOTE
||
180 nSelection
& FrameTypeFlags::FTNPAGE
)
181 nMask
= SfxStyleSearchBits::SwExtra
;
183 nMask
= SfxStyleSearchBits::SwText
;
186 aItem
.SetValue(nMask
);
192 case SID_STYLE_FAMILY3
:
194 if (m_xDoc
->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE
))
195 rSet
.DisableItem( nWhich
);
198 SwFrameFormat
* pFormat
= pShell
->GetSelectedFrameFormat();
199 if(pFormat
&& pShell
->IsFrameSelected())
201 aName
= pFormat
->GetName();
202 rSet
.Put(SfxTemplateItem(nWhich
, aName
));
207 case SID_STYLE_FAMILY4
:
209 if (m_xDoc
->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE
) && !SvxHtmlOptions::IsPrintLayoutExtension())
210 rSet
.DisableItem( nWhich
);
213 size_t n
= pShell
->GetCurPageDesc( false );
214 if( n
< pShell
->GetPageDescCnt() )
215 aName
= pShell
->GetPageDesc( n
).GetName();
217 rSet
.Put(SfxTemplateItem(nWhich
, aName
));
221 case SID_STYLE_FAMILY5
:
223 const SwNumRule
* pRule
= pShell
->GetNumRuleAtCurrCursorPos();
225 aName
= pRule
->GetName();
227 rSet
.Put(SfxTemplateItem(nWhich
, aName
));
230 case SID_STYLE_FAMILY6
:
232 const SwTableNode
*pTableNd
= pShell
->IsCursorInTable();
234 aName
= pTableNd
->GetTable().GetTableStyleName();
236 rSet
.Put(SfxTemplateItem(nWhich
, aName
));
240 case SID_STYLE_WATERCAN
:
242 SwEditWin
& rEdtWin
= pShell
->GetView().GetEditWin();
243 SwApplyTemplate
* pApply
= rEdtWin
.GetApplyTemplate();
244 rSet
.Put(SfxBoolItem(nWhich
, pApply
&& pApply
->eType
!= SfxStyleFamily(0)));
247 case SID_STYLE_UPDATE_BY_EXAMPLE
:
248 if( pShell
->IsFrameSelected()
249 ? SfxStyleFamily::Frame
!= nActualFamily
250 : ( SfxStyleFamily::Frame
== nActualFamily
||
251 SfxStyleFamily::Page
== nActualFamily
||
252 (SfxStyleFamily::Pseudo
== nActualFamily
&& !pShell
->GetNumRuleAtCurrCursorPos()) ||
253 (SfxStyleFamily::Table
== nActualFamily
&& !pShell
->GetTableAutoFormat(aTableAutoFormat
))) )
255 rSet
.DisableItem( nWhich
);
259 case SID_STYLE_NEW_BY_EXAMPLE
:
260 if( (pShell
->IsFrameSelected()
261 ? SfxStyleFamily::Frame
!= nActualFamily
262 : SfxStyleFamily::Frame
== nActualFamily
) ||
263 (SfxStyleFamily::Pseudo
== nActualFamily
&& !pShell
->GetNumRuleAtCurrCursorPos()) ||
264 (SfxStyleFamily::Table
== nActualFamily
&& !pShell
->GetTableAutoFormat(aTableAutoFormat
)) )
266 rSet
.DisableItem( nWhich
);
270 case SID_CLASSIFICATION_APPLY
:
271 // Just trigger ClassificationCategoriesController::statusChanged().
272 rSet
.InvalidateItem(nWhich
);
274 case SID_CLASSIFICATION_DIALOG
:
275 rSet
.InvalidateItem(nWhich
);
282 SfxWatermarkItem aItem
= pSh
->GetWatermark();
287 OSL_FAIL("Invalid SlotId");
289 nWhich
= aIter
.NextWhich();
293 // evaluate StyleSheet-Requests
294 void SwDocShell::ExecStyleSheet( SfxRequest
& rReq
)
296 sal_uInt16 nSlot
= rReq
.GetSlot();
298 const SfxItemSet
* pArgs
= rReq
.GetArgs();
299 const SfxPoolItem
* pItem
;
303 if( pArgs
&& SfxItemState::SET
== pArgs
->GetItemState( SID_STYLE_FAMILY
,
306 const SfxStyleFamily nFamily
= static_cast<SfxStyleFamily
>(static_cast<const SfxUInt16Item
*>(pItem
)->GetValue());
309 SfxStyleSearchBits nMask
= SfxStyleSearchBits::Auto
;
310 if( SfxItemState::SET
== pArgs
->GetItemState( SID_STYLE_NEW
,
312 sName
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
313 if( SfxItemState::SET
== pArgs
->GetItemState( SID_STYLE_MASK
,
315 nMask
= static_cast<SfxStyleSearchBits
>(static_cast<const SfxUInt16Item
*>(pItem
)->GetValue());
317 if( SfxItemState::SET
== pArgs
->GetItemState( SID_STYLE_REFERENCE
,
319 sParent
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
321 if (sName
.isEmpty() && m_xBasePool
)
322 sName
= SfxStyleDialogController::GenerateUnusedName(*m_xBasePool
, nFamily
);
324 Edit(rReq
.GetFrameWeld(), sName
, sParent
, nFamily
, nMask
, true, {}, nullptr, &rReq
, nSlot
);
328 case SID_STYLE_APPLY
:
331 GetView()->GetViewFrame().GetDispatcher()->Execute(SID_STYLE_DESIGNER
);
336 // convert internal StyleName to DisplayName (slot implementation uses the latter)
337 const SfxStringItem
* pNameItem
= rReq
.GetArg
<SfxStringItem
>(SID_APPLY_STYLE
);
338 const SfxStringItem
* pFamilyItem
= rReq
.GetArg
<SfxStringItem
>(SID_STYLE_FAMILYNAME
);
339 if ( pFamilyItem
&& pNameItem
)
341 uno::Reference
< style::XStyleFamiliesSupplier
> xModel(GetModel(), uno::UNO_QUERY
);
344 uno::Reference
< container::XNameAccess
> xStyles
;
345 uno::Reference
< container::XNameAccess
> xCont
= xModel
->getStyleFamilies();
346 xCont
->getByName(pFamilyItem
->GetValue()) >>= xStyles
;
347 uno::Reference
< beans::XPropertySet
> xInfo
;
348 xStyles
->getByName( pNameItem
->GetValue() ) >>= xInfo
;
350 xInfo
->getPropertyValue("DisplayName") >>= aUIName
;
351 if ( !aUIName
.isEmpty() )
352 rReq
.AppendItem( SfxStringItem( SID_STYLE_APPLY
, aUIName
) );
354 catch (const uno::Exception
&)
364 case SID_STYLE_DELETE
:
367 case SID_STYLE_WATERCAN
:
368 case SID_STYLE_FAMILY
:
369 case SID_STYLE_UPDATE_BY_EXAMPLE
:
370 case SID_STYLE_NEW_BY_EXAMPLE
:
373 SfxStyleFamily nFamily
= SfxStyleFamily::Para
;
374 SfxStyleSearchBits nMask
= SfxStyleSearchBits::Auto
;
375 SwWrtShell
* pActShell
= nullptr;
381 case SID_STYLE_NEW_BY_EXAMPLE
:
383 SfxStyleSheetBasePool
& rPool
= *GetStyleSheetPool();
384 SfxNewStyleDlg
aDlg(GetView()->GetFrameWeld(), rPool
, nFamily
);
385 if (aDlg
.run() == RET_OK
)
387 aParam
= aDlg
.GetName();
388 rReq
.AppendItem(SfxStringItem(nSlot
, aParam
));
393 case SID_STYLE_UPDATE_BY_EXAMPLE
:
396 SwTextFormatColl
* pColl
= GetWrtShell()->GetCurTextFormatColl();
399 aParam
= pColl
->GetName();
400 rReq
.AppendItem(SfxStringItem(nSlot
, aParam
));
408 SAL_WARN_IF( !pArgs
->Count(), "sw.ui", "SfxBug ItemSet is empty" );
410 SwWrtShell
* pShell
= GetWrtShell();
411 if( SfxItemState::SET
== pArgs
->GetItemState(nSlot
, false, &pItem
))
412 aParam
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
414 if( SfxItemState::SET
== pArgs
->GetItemState(SID_STYLE_FAMILY
,
416 nFamily
= static_cast<SfxStyleFamily
>(static_cast<const SfxUInt16Item
*>(pItem
)->GetValue());
418 if( SfxItemState::SET
== pArgs
->GetItemState(SID_STYLE_FAMILYNAME
, false, &pItem
))
420 OUString aFamily
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
421 if(aFamily
== "CharacterStyles")
422 nFamily
= SfxStyleFamily::Char
;
424 if(aFamily
== "ParagraphStyles")
425 nFamily
= SfxStyleFamily::Para
;
427 if(aFamily
== "PageStyles")
428 nFamily
= SfxStyleFamily::Page
;
430 if(aFamily
== "FrameStyles")
431 nFamily
= SfxStyleFamily::Frame
;
433 if(aFamily
== "NumberingStyles")
434 nFamily
= SfxStyleFamily::Pseudo
;
436 if(aFamily
== "TableStyles")
437 nFamily
= SfxStyleFamily::Table
;
440 if( SfxItemState::SET
== pArgs
->GetItemState(SID_STYLE_MASK
,
442 nMask
= static_cast<SfxStyleSearchBits
>(static_cast<const SfxUInt16Item
*>(pItem
)->GetValue());
443 if( const SwPtrItem
* pShellItem
= pArgs
->GetItemIfSet(FN_PARAM_WRTSHELL
, false ))
444 pActShell
= pShell
= static_cast<SwWrtShell
*>(pShellItem
->GetValue());
446 if( nSlot
== SID_STYLE_UPDATE_BY_EXAMPLE
&& aParam
.isEmpty() )
450 case SfxStyleFamily::Para
:
452 SwTextFormatColl
* pColl
= pShell
->GetCurTextFormatColl();
454 aParam
= pColl
->GetName();
457 case SfxStyleFamily::Frame
:
459 SwFrameFormat
* pFrame
= m_pWrtShell
->GetSelectedFrameFormat();
461 aParam
= pFrame
->GetName();
464 case SfxStyleFamily::Char
:
466 SwCharFormat
* pChar
= m_pWrtShell
->GetCurCharFormat();
468 aParam
= pChar
->GetName();
471 case SfxStyleFamily::Pseudo
:
472 if(const SfxStringItem
* pExName
= pArgs
->GetItemIfSet(SID_STYLE_UPD_BY_EX_NAME
, false))
474 aParam
= pExName
->GetValue();
477 case SfxStyleFamily::Table
:
478 if(const SfxStringItem
* pExName
= pArgs
->GetItemIfSet(SID_STYLE_UPD_BY_EX_NAME
, false))
480 aParam
= pExName
->GetValue();
485 rReq
.AppendItem(SfxStringItem(nSlot
, aParam
));
488 if (!aParam
.isEmpty() || nSlot
== SID_STYLE_WATERCAN
)
490 sal_uInt16 nRet
= 0xffff;
491 bool bReturns
= false;
497 Edit(rReq
.GetFrameWeld(), aParam
, {}, nFamily
, nMask
, false, (nSlot
== SID_STYLE_FONT
) ? "font" : OUString(), pActShell
);
499 case SID_STYLE_DELETE
:
500 Delete(aParam
, nFamily
);
504 Hide(aParam
, nFamily
, nSlot
== SID_STYLE_HIDE
);
506 case SID_STYLE_APPLY
:
507 // Shell-switch in ApplyStyles
508 nRet
= static_cast<sal_uInt16
>(ApplyStyles(aParam
, nFamily
, pActShell
, rReq
.GetModifier() ));
511 case SID_STYLE_WATERCAN
:
512 nRet
= static_cast<sal_uInt16
>(DoWaterCan(aParam
, nFamily
));
515 case SID_STYLE_UPDATE_BY_EXAMPLE
:
516 UpdateStyle(aParam
, nFamily
, pActShell
);
518 case SID_STYLE_NEW_BY_EXAMPLE
:
519 MakeByExample(aParam
, nFamily
, nMask
, pActShell
);
523 OSL_FAIL("Invalid SlotId");
528 if(rReq
.IsAPI()) // Basic only gets TRUE or FALSE
529 rReq
.SetReturnValue(SfxUInt16Item(nSlot
, sal_uInt16(nRet
!=0)));
531 rReq
.SetReturnValue(SfxUInt16Item(nSlot
, nRet
));
547 ApplyStyle(SwDocShell
&rDocSh
, bool bNew
,
548 rtl::Reference
< SwDocStyleSheet
> xTmp
,
549 SfxStyleFamily nFamily
, SfxAbstractApplyTabDialog
*pDlg
,
550 rtl::Reference
< SfxStyleSheetBasePool
> xBasePool
,
555 , m_xTmp(std::move(xTmp
))
557 , m_xBasePool(std::move(xBasePool
))
558 , m_bModified(bModified
)
561 DECL_LINK( ApplyHdl
, LinkParamNone
*, void );
566 VclPtr
<SfxAbstractApplyTabDialog
> m_pDlg
;
567 // true if the document was initially modified before ApplyStyle was created
568 // or if ApplyStyle:::apply was called
569 bool DocIsModified() const
574 SwDocShell
&m_rDocSh
;
576 rtl::Reference
< SwDocStyleSheet
> m_xTmp
;
577 SfxStyleFamily m_nFamily
;
578 rtl::Reference
< SfxStyleSheetBasePool
> m_xBasePool
;
584 IMPL_LINK_NOARG(ApplyStyle
, ApplyHdl
, LinkParamNone
*, void)
586 SwWrtShell
* pWrtShell
= m_rDocSh
.GetWrtShell();
587 SwDoc
* pDoc
= m_rDocSh
.GetDoc();
588 SwView
* pView
= m_rDocSh
.GetView();
590 pWrtShell
->StartAllAction();
592 if( SfxStyleFamily::Para
== m_nFamily
)
594 SfxItemSet
aSet( *m_pDlg
->GetOutputItemSet() );
595 ::ConvertAttrGenToChar(aSet
, m_xTmp
->GetItemSet(), /*bIsPara=*/true);
596 ::SfxToSwPageDescAttr( *pWrtShell
, aSet
);
597 // reset indent attributes at paragraph style, if a list style
598 // will be applied and no indent attributes will be applied.
599 m_xTmp
->SetItemSet( aSet
, true );
603 if(SfxStyleFamily::Page
== m_nFamily
|| SfxStyleFamily::Frame
== m_nFamily
)
605 static const sal_uInt16 aInval
[] = {
606 SID_IMAGE_ORIENTATION
,
608 FN_INSERT_CTRL
, FN_INSERT_OBJ_CTRL
,
609 FN_TABLE_INSERT_COL_BEFORE
,
610 FN_TABLE_INSERT_COL_AFTER
, 0};
611 pView
->GetViewFrame().GetBindings().Invalidate(aInval
);
613 SfxItemSet
aTmpSet( *m_pDlg
->GetOutputItemSet() );
614 if( SfxStyleFamily::Char
== m_nFamily
)
616 ::ConvertAttrGenToChar(aTmpSet
, m_xTmp
->GetItemSet());
619 m_xTmp
->SetItemSet( aTmpSet
);
621 if( SfxStyleFamily::Page
== m_nFamily
&& SvtCTLOptions::IsCTLFontEnabled() )
623 const SfxPoolItem
*pItem
= nullptr;
624 if( aTmpSet
.GetItemState( m_rDocSh
.GetPool().GetTrueWhich( SID_ATTR_FRAMEDIRECTION
, false ) , true, &pItem
) == SfxItemState::SET
)
625 SwChartHelper::DoUpdateAllCharts( pDoc
);
628 if (m_nFamily
== SfxStyleFamily::Page
)
630 if (const SfxGrabBagItem
* pGrabBagItem
= aTmpSet
.GetItemIfSet(SID_ATTR_CHAR_GRABBAG
))
633 auto it
= pGrabBagItem
->GetGrabBag().find("GutterAtTop");
634 if (it
!= pGrabBagItem
->GetGrabBag().end())
636 it
->second
>>= bGutterAtTop
;
639 = pDoc
->getIDocumentSettingAccess().get(DocumentSettingId::GUTTER_AT_TOP
);
640 if (bOldGutterAtTop
!= bGutterAtTop
)
642 pDoc
->getIDocumentSettingAccess().set(DocumentSettingId::GUTTER_AT_TOP
,
644 pWrtShell
->InvalidateLayout(/*bSizeChanged=*/true);
649 if (m_nFamily
== SfxStyleFamily::Frame
)
651 if (const SfxBoolItem
* pBoolItem
= aTmpSet
.GetItemIfSet(FN_KEEP_ASPECT_RATIO
))
653 const SwViewOption
* pVOpt
= pWrtShell
->GetViewOptions();
654 SwViewOption
aUsrPref(*pVOpt
);
655 aUsrPref
.SetKeepRatio(pBoolItem
->GetValue());
656 if (pBoolItem
->GetValue() != pVOpt
->IsKeepRatio())
658 SW_MOD()->ApplyUsrPref(aUsrPref
, &pWrtShell
->GetView());
666 if(SfxStyleFamily::Frame
== m_nFamily
|| SfxStyleFamily::Para
== m_nFamily
)
668 // clear FillStyle so that it works as a derived attribute
669 SfxItemSet
aTmpSet(*m_pDlg
->GetOutputItemSet());
671 aTmpSet
.ClearItem(XATTR_FILLSTYLE
);
672 m_xTmp
->SetItemSet(aTmpSet
);
676 if(SfxStyleFamily::Page
== m_nFamily
)
677 pView
->InvalidateRulerPos();
680 m_xBasePool
->Broadcast(SfxStyleSheetHint(SfxHintId::StyleSheetCreated
, *m_xTmp
));
682 m_xBasePool
->Broadcast(SfxStyleSheetHint(SfxHintId::StyleSheetModified
, *m_xTmp
));
684 pDoc
->getIDocumentState().SetModified();
687 pDoc
->GetIDocumentUndoRedo().SetUndoNoResetModified();
691 pWrtShell
->EndAllAction();
696 /// Checks if there is an Endnote page style in use, and makes sure it has the same orientation
697 /// with the Default (Standard) page style.
698 void syncEndnoteOrientation(const uno::Reference
< style::XStyleFamiliesSupplier
>& xStyleFamSupp
)
700 if (!xStyleFamSupp
.is())
702 SAL_WARN("sw.ui", "Ref to XStyleFamiliesSupplier is null.");
705 uno::Reference
<container::XNameAccess
> xStyleFamilies
= xStyleFamSupp
->getStyleFamilies();
707 if (!xStyleFamilies
.is())
710 uno::Reference
<container::XNameAccess
> xPageStyles(xStyleFamilies
->getByName("PageStyles"),
713 if (!xPageStyles
.is())
716 uno::Reference
<css::style::XStyle
> xEndnotePageStyle(xPageStyles
->getByName("Endnote"),
719 if (!xEndnotePageStyle
.is())
722 // Language-independent name of the "Default Style" is "Standard"
723 uno::Reference
<css::style::XStyle
> xDefaultPageStyle(xPageStyles
->getByName("Standard"),
725 if (!xDefaultPageStyle
.is())
728 if (xEndnotePageStyle
->isUserDefined() || !xEndnotePageStyle
->isInUse())
731 uno::Reference
<beans::XPropertySet
> xEndnotePagePropSet(xPageStyles
->getByName("Endnote"), uno::UNO_QUERY
);
732 uno::Reference
<beans::XPropertySet
> xDefaultPagePropSet(xPageStyles
->getByName("Standard"), uno::UNO_QUERY
);
734 if (!xEndnotePagePropSet
.is() || !xDefaultPagePropSet
.is())
736 SAL_WARN("sw.ui", "xEndnotePagePropSet or xDefaultPagePropSet is null.");
740 auto const bIsDefLandScape
= *o3tl::doAccess
<bool>(
741 xDefaultPagePropSet
->getPropertyValue("IsLandscape"));
742 auto const bIsEndLandScape
= *o3tl::doAccess
<bool>(
743 xEndnotePagePropSet
->getPropertyValue("IsLandscape"));
745 if (bIsDefLandScape
== bIsEndLandScape
)
748 auto const nWidth
= xEndnotePagePropSet
->getPropertyValue("Width");
749 auto const nHeight
= xEndnotePagePropSet
->getPropertyValue("Height");
751 xEndnotePagePropSet
->setPropertyValue("IsLandscape", css::uno::toAny(bIsDefLandScape
));
752 xEndnotePagePropSet
->setPropertyValue("Width", nHeight
);
753 xEndnotePagePropSet
->setPropertyValue("Height", nWidth
);
757 void SwDocShell::Edit(
758 weld::Window
* pDialogParent
,
759 const OUString
&rName
,
760 const OUString
&rParent
,
761 const SfxStyleFamily nFamily
,
762 SfxStyleSearchBits nMask
,
764 const OUString
& sPage
,
765 SwWrtShell
* pActShell
,
769 assert( GetWrtShell() );
770 const bool bBasic
= pReq
&& pReq
->IsAPI();
771 SfxStyleSheetBase
*pStyle
= nullptr;
773 bool bModified
= m_xDoc
->getIDocumentState().IsModified();
775 SwUndoId
nNewStyleUndoId(SwUndoId::EMPTY
);
781 // start undo action in order to get only one undo action for the
782 // UI new style + change style operations
783 m_pWrtShell
->StartUndo();
786 if( SfxStyleSearchBits::All
!= nMask
&& SfxStyleSearchBits::AllVisible
!= nMask
&& SfxStyleSearchBits::Used
!= nMask
)
787 nMask
|= SfxStyleSearchBits::UserDefined
;
789 nMask
= SfxStyleSearchBits::UserDefined
;
791 if ( nFamily
== SfxStyleFamily::Para
|| nFamily
== SfxStyleFamily::Char
|| nFamily
== SfxStyleFamily::Frame
)
793 // Prevent undo append from being done during paragraph, character, and frame style Make
794 // Do it after ok return from style dialog when derived from style is known
795 ::sw::UndoGuard
const undoGuard(GetDoc()->GetIDocumentUndoRedo());
796 pStyle
= &m_xBasePool
->Make( rName
, nFamily
, nMask
);
800 pStyle
= &m_xBasePool
->Make( rName
, nFamily
, nMask
);
803 // set the current one as Parent
804 SwDocStyleSheet
* pDStyle
= static_cast<SwDocStyleSheet
*>(pStyle
);
807 case SfxStyleFamily::Para
:
809 if(!rParent
.isEmpty())
811 SwTextFormatColl
* pColl
= m_pWrtShell
->FindTextFormatCollByName( rParent
);
814 sal_uInt16 nId
= SwStyleNameMapper::GetPoolIdFromUIName(rParent
, SwGetPoolIdFromName::TxtColl
);
816 pColl
= m_pWrtShell
->GetTextCollFromPool( nId
);
818 pDStyle
->GetCollection()->SetDerivedFrom( pColl
);
819 pDStyle
->PresetParent( rParent
);
823 SwTextFormatColl
* pColl
= m_pWrtShell
->GetCurTextFormatColl();
824 pDStyle
->GetCollection()->SetDerivedFrom( pColl
);
826 pDStyle
->PresetParent( pColl
->GetName() );
830 case SfxStyleFamily::Char
:
832 if(!rParent
.isEmpty())
834 SwCharFormat
* pCFormat
= m_pWrtShell
->FindCharFormatByName(rParent
);
837 sal_uInt16 nId
= SwStyleNameMapper::GetPoolIdFromUIName(rParent
, SwGetPoolIdFromName::ChrFmt
);
839 pCFormat
= m_pWrtShell
->GetCharFormatFromPool( nId
);
842 pDStyle
->GetCharFormat()->SetDerivedFrom( pCFormat
);
843 pDStyle
->PresetParent( rParent
);
847 SwCharFormat
* pCFormat
= m_pWrtShell
->GetCurCharFormat();
848 pDStyle
->GetCharFormat()->SetDerivedFrom( pCFormat
);
850 pDStyle
->PresetParent( pCFormat
->GetName() );
854 case SfxStyleFamily::Frame
:
856 if(!rParent
.isEmpty())
858 SwFrameFormat
* pFFormat
= m_pWrtShell
->GetDoc()->FindFrameFormatByName( rParent
);
861 sal_uInt16 nId
= SwStyleNameMapper::GetPoolIdFromUIName(rParent
, SwGetPoolIdFromName::FrmFmt
);
863 pFFormat
= m_pWrtShell
->GetFrameFormatFromPool( nId
);
865 pDStyle
->GetFrameFormat()->SetDerivedFrom( pFFormat
);
866 pDStyle
->PresetParent( rParent
);
875 //Get the undo id for the type of style that was created in order to re-use that comment for the grouped
876 //create style + change style operations
877 m_pWrtShell
->GetLastUndoInfo(nullptr, &nNewStyleUndoId
);
882 pStyle
= m_xBasePool
->Find( rName
, nFamily
);
883 SAL_WARN_IF( !pStyle
, "sw.ui", "Style not found" );
889 // put dialogues together
890 rtl::Reference
< SwDocStyleSheet
> xTmp( new SwDocStyleSheet( *static_cast<SwDocStyleSheet
*>(pStyle
) ) );
891 if( SfxStyleFamily::Para
== nFamily
)
893 SfxItemSet
& rSet
= xTmp
->GetItemSet();
894 ::SwToSfxPageDescAttr( rSet
);
895 // merge list level indent attributes into the item set if needed
896 xTmp
->MergeIndentAttrsOfListStyle( rSet
);
898 ::ConvertAttrCharToGen(xTmp
->GetItemSet(), /*bIsPara=*/true);
900 else if( SfxStyleFamily::Char
== nFamily
)
902 ::ConvertAttrCharToGen(xTmp
->GetItemSet());
905 if(SfxStyleFamily::Page
== nFamily
|| SfxStyleFamily::Para
== nFamily
)
907 // create needed items for XPropertyList entries from the DrawModel so that
908 // the Area TabPage can access them
909 SfxItemSet
& rSet
= xTmp
->GetItemSet();
910 const SwDrawModel
* pDrawModel
= GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
912 rSet
.Put(SvxColorListItem(pDrawModel
->GetColorList(), SID_COLOR_TABLE
));
913 rSet
.Put(SvxGradientListItem(pDrawModel
->GetGradientList(), SID_GRADIENT_LIST
));
914 rSet
.Put(SvxHatchListItem(pDrawModel
->GetHatchList(), SID_HATCH_LIST
));
915 rSet
.Put(SvxBitmapListItem(pDrawModel
->GetBitmapList(), SID_BITMAP_LIST
));
916 rSet
.Put(SvxPatternListItem(pDrawModel
->GetPatternList(), SID_PATTERN_LIST
));
918 std::optional
<SfxGrabBagItem
> oGrabBag
;
919 if (SfxGrabBagItem
const* pItem
= rSet
.GetItemIfSet(SID_ATTR_CHAR_GRABBAG
))
921 oGrabBag
.emplace(*pItem
);
925 oGrabBag
.emplace(SID_ATTR_CHAR_GRABBAG
);
928 = GetDoc()->getIDocumentSettingAccess().get(DocumentSettingId::GUTTER_AT_TOP
);
929 oGrabBag
->GetGrabBag()["GutterAtTop"] <<= bGutterAtTop
;
933 SwWrtShell
* pCurrShell
= pActShell
? pActShell
: m_pWrtShell
;
934 if (nFamily
== SfxStyleFamily::Frame
)
936 SfxItemSet
& rSet
= xTmp
->GetItemSet();
937 const SwViewOption
* pVOpt
= pCurrShell
->GetViewOptions();
938 rSet
.Put(SfxBoolItem(FN_KEEP_ASPECT_RATIO
, pVOpt
->IsKeepRatio()));
943 // prior to the dialog the HtmlMode at the DocShell is being sunk
944 sal_uInt16 nHtmlMode
= ::GetHtmlMode(this);
946 // In HTML mode, we do not always have a printer. In order to show
947 // the correct page size in the Format - Page dialog, we have to
949 if( ( HTMLMODE_ON
& nHtmlMode
) &&
950 !pCurrShell
->getIDocumentDeviceAccess().getPrinter( false ) )
951 pCurrShell
->InitPrt( pCurrShell
->getIDocumentDeviceAccess().getPrinter( true ) );
953 PutItem(SfxUInt16Item(SID_HTML_MODE
, nHtmlMode
));
954 FieldUnit eMetric
= ::GetDfltMetric(0 != (HTMLMODE_ON
&nHtmlMode
));
955 SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC
, static_cast< sal_uInt16
>(eMetric
)));
956 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
959 SAL_WARN("sw.ui", "no parent for dialog supplied, assuming document frame is good enough");
960 pDialogParent
= GetView()->GetFrameWeld();
962 VclPtr
<SfxAbstractApplyTabDialog
> pDlg(pFact
->CreateTemplateDialog(pDialogParent
,
963 *xTmp
, nFamily
, sPage
, pCurrShell
, bNew
));
964 auto pApplyStyleHelper
= std::make_shared
<ApplyStyle
>(*this, bNew
, xTmp
, nFamily
, pDlg
.get(), m_xBasePool
, bModified
);
965 pDlg
->SetApplyHdl(LINK(pApplyStyleHelper
.get(), ApplyStyle
, ApplyHdl
));
967 std::shared_ptr
<SfxRequest
> pRequest
;
970 pRequest
= std::make_shared
<SfxRequest
>(*pReq
);
971 pReq
->Ignore(); // the 'old' request is not relevant any more
974 bool bIsDefaultPage
= nFamily
== SfxStyleFamily::Page
975 && rName
== SwResId(STR_POOLPAGE_STANDARD
)
977 && !pStyle
->IsUserDefined();
979 pDlg
->StartExecuteAsync([bIsDefaultPage
, bNew
, nFamily
, nSlot
, nNewStyleUndoId
, pApplyStyleHelper
, pRequest
, xTmp
, this](sal_Int32 nResult
){
980 if (RET_OK
== nResult
)
981 pApplyStyleHelper
->apply();
987 case SfxStyleFamily::Para
:
989 if(!xTmp
->GetParent().isEmpty())
991 SwTextFormatColl
* pColl
= m_pWrtShell
->FindTextFormatCollByName(xTmp
->GetParent());
992 if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
994 GetDoc()->GetIDocumentUndoRedo().AppendUndo(
995 std::make_unique
<SwUndoTextFormatCollCreate
>(xTmp
->GetCollection(), pColl
, *GetDoc()));
1000 case SfxStyleFamily::Char
:
1002 if(!xTmp
->GetParent().isEmpty())
1004 SwCharFormat
* pCFormat
= m_pWrtShell
->FindCharFormatByName(xTmp
->GetParent());
1005 if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1007 GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1008 std::make_unique
<SwUndoCharFormatCreate
>(xTmp
->GetCharFormat(), pCFormat
, *GetDoc()));
1013 case SfxStyleFamily::Frame
:
1015 if(!xTmp
->GetParent().isEmpty())
1017 SwFrameFormat
* pFFormat
= m_pWrtShell
->GetDoc()->FindFrameFormatByName(xTmp
->GetParent());
1018 if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1020 GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1021 std::make_unique
<SwUndoFrameFormatCreate
>(xTmp
->GetFrameFormat(), pFFormat
, *GetDoc()));
1029 SwRewriter aRewriter
;
1030 aRewriter
.AddRule(UndoArg1
, xTmp
->GetName());
1031 //Group the create style and change style operations together under the
1032 //one "create style" comment
1033 m_pWrtShell
->EndUndo(nNewStyleUndoId
, &aRewriter
);
1036 bool bDocModified
= pApplyStyleHelper
->DocIsModified();
1038 if (RET_OK
!= nResult
)
1042 GetWrtShell()->Undo();
1043 m_xDoc
->GetIDocumentUndoRedo().ClearRedo();
1047 m_xDoc
->getIDocumentState().ResetModified();
1050 // Update Watermark if new page style was created
1051 if (nSlot
== SID_STYLE_NEW
&& nFamily
== SfxStyleFamily::Page
)
1053 SwWrtShell
* pShell
= GetWrtShell();
1054 const SfxWatermarkItem aWatermark
= pShell
->GetWatermark();
1055 pShell
->SetWatermark(aWatermark
);
1058 pApplyStyleHelper
->m_pDlg
.disposeAndClear();
1062 if (bIsDefaultPage
&& bDocModified
)
1064 uno::Reference
< style::XStyleFamiliesSupplier
> xStyleFamSupp(GetModel(), uno::UNO_QUERY
);
1066 if (!xStyleFamSupp
.is())
1068 SAL_WARN("sw.ui", "Ref to XStyleFamiliesSupplier is null.");
1072 syncEndnoteOrientation(xStyleFamSupp
);
1078 // prior to the dialog the HtmlMode at the DocShell is being sunk
1079 PutItem(SfxUInt16Item(SID_HTML_MODE
, ::GetHtmlMode(this)));
1081 GetWrtShell()->StartAllAction();
1083 if( SfxStyleFamily::Para
== nFamily
)
1085 ::SfxToSwPageDescAttr( *GetWrtShell(), xTmp
->GetItemSet() );
1086 ::ConvertAttrGenToChar(xTmp
->GetItemSet(), xTmp
->GetItemSet(), /*bIsPara=*/true);
1090 ::ConvertAttrGenToChar(xTmp
->GetItemSet(), xTmp
->GetItemSet());
1092 if(SfxStyleFamily::Page
== nFamily
)
1093 m_pView
->InvalidateRulerPos();
1096 m_xBasePool
->Broadcast(SfxStyleSheetHint(SfxHintId::StyleSheetCreated
, *xTmp
));
1098 m_xDoc
->getIDocumentState().SetModified();
1099 if( !bModified
) // Bug 57028
1101 m_xDoc
->GetIDocumentUndoRedo().SetUndoNoResetModified();
1103 GetWrtShell()->EndAllAction();
1107 void SwDocShell::Delete(const OUString
&rName
, SfxStyleFamily nFamily
)
1109 SfxStyleSheetBase
*pStyle
= m_xBasePool
->Find(rName
, nFamily
);
1113 assert( GetWrtShell() );
1115 GetWrtShell()->StartAllAction();
1116 m_xBasePool
->Remove(pStyle
);
1117 GetWrtShell()->EndAllAction();
1121 void SwDocShell::Hide(const OUString
&rName
, SfxStyleFamily nFamily
, bool bHidden
)
1123 SfxStyleSheetBase
*pStyle
= m_xBasePool
->Find(rName
, nFamily
);
1127 assert( GetWrtShell() );
1129 GetWrtShell()->StartAllAction();
1130 rtl::Reference
< SwDocStyleSheet
> xTmp( new SwDocStyleSheet( *static_cast<SwDocStyleSheet
*>(pStyle
) ) );
1131 xTmp
->SetHidden( bHidden
);
1132 GetWrtShell()->EndAllAction();
1137 SfxStyleFamily
SwDocShell::ApplyStyles(const OUString
&rName
, SfxStyleFamily nFamily
,
1138 SwWrtShell
* pShell
, const sal_uInt16 nMode
)
1140 SwDocStyleSheet
* pStyle
= static_cast<SwDocStyleSheet
*>( m_xBasePool
->Find( rName
, nFamily
) );
1142 SAL_WARN_IF( !pStyle
, "sw.ui", "Style not found" );
1145 return SfxStyleFamily::None
;
1147 SwWrtShell
*pSh
= pShell
? pShell
: GetWrtShell();
1151 pSh
->StartAllAction();
1155 case SfxStyleFamily::Char
:
1157 SwFormatCharFormat
aFormat(pStyle
->GetCharFormat());
1158 pSh
->SetAttrItem( aFormat
, (nMode
& KEY_SHIFT
) ?
1159 SetAttrMode::DONTREPLACE
: SetAttrMode::DEFAULT
);
1162 case SfxStyleFamily::Para
:
1164 // When outline-folding is enabled, MakeAllOutlineContentTemporarilyVisible makes
1165 // application of a paragraph style that has an outline-level greater than the previous
1166 // outline node become folded content of the previous outline node if the previous
1167 // outline node's content is folded.
1168 MakeAllOutlineContentTemporarilyVisible
a(GetDoc());
1170 // clear also list attributes at affected text nodes, if paragraph
1171 // style has the list style attribute set.
1172 pSh
->SetTextFormatColl( pStyle
->GetCollection(), true );
1175 case SfxStyleFamily::Frame
:
1177 if ( pSh
->IsFrameSelected() )
1178 pSh
->SetFrameFormat( pStyle
->GetFrameFormat() );
1181 case SfxStyleFamily::Page
:
1183 pSh
->SetPageStyle(pStyle
->GetPageDesc()->GetName());
1186 case SfxStyleFamily::Pseudo
:
1188 // reset indent attribute on applying list style
1189 // continue list of list style
1190 const SwNumRule
* pNumRule
= pStyle
->GetNumRule();
1191 if (pNumRule
->GetName() == SwResId(STR_POOLNUMRULE_NOLIST
))
1193 if (SfxViewFrame
* pViewFrm
= SfxViewFrame::Current())
1194 pViewFrm
->GetDispatcher()->Execute(FN_NUM_BULLET_OFF
);
1197 const OUString sListIdForStyle
=pNumRule
->GetDefaultListId();
1198 pSh
->SetCurNumRule( *pNumRule
, false, sListIdForStyle
, true );
1201 case SfxStyleFamily::Table
:
1203 pSh
->SetTableStyle(pStyle
->GetName());
1207 OSL_FAIL("Unknown family");
1209 pSh
->EndAllAction();
1214 // start watering-can
1215 SfxStyleFamily
SwDocShell::DoWaterCan(const OUString
&rName
, SfxStyleFamily nFamily
)
1217 assert( GetWrtShell() );
1219 SwEditWin
& rEdtWin
= m_pView
->GetEditWin();
1220 SwApplyTemplate
* pApply
= rEdtWin
.GetApplyTemplate();
1221 bool bWaterCan
= !(pApply
&& pApply
->eType
!= SfxStyleFamily(0));
1223 if( rName
.isEmpty() )
1226 SwApplyTemplate aTemplate
;
1227 aTemplate
.eType
= nFamily
;
1231 SwDocStyleSheet
* pStyle
=
1232 static_cast<SwDocStyleSheet
*>( m_xBasePool
->Find(rName
, nFamily
) );
1234 SAL_WARN_IF( !pStyle
, "sw.ui", "Where's the StyleSheet" );
1236 if(!pStyle
) return nFamily
;
1240 case SfxStyleFamily::Char
:
1241 aTemplate
.aColl
.pCharFormat
= pStyle
->GetCharFormat();
1243 case SfxStyleFamily::Para
:
1244 aTemplate
.aColl
.pTextColl
= pStyle
->GetCollection();
1246 case SfxStyleFamily::Frame
:
1247 aTemplate
.aColl
.pFrameFormat
= pStyle
->GetFrameFormat();
1249 case SfxStyleFamily::Page
:
1250 aTemplate
.aColl
.pPageDesc
= const_cast<SwPageDesc
*>(pStyle
->GetPageDesc());
1252 case SfxStyleFamily::Pseudo
:
1253 aTemplate
.aColl
.pNumRule
= const_cast<SwNumRule
*>(pStyle
->GetNumRule());
1257 OSL_FAIL("Unknown family");
1261 aTemplate
.eType
= SfxStyleFamily(0);
1263 m_pView
->GetEditWin().SetApplyTemplate(aTemplate
);
1269 void SwDocShell::UpdateStyle(const OUString
&rName
, SfxStyleFamily nFamily
, SwWrtShell
* pShell
)
1271 SwWrtShell
* pCurrWrtShell
= pShell
? pShell
: GetWrtShell();
1272 assert( pCurrWrtShell
);
1274 SwDocStyleSheet
* pStyle
=
1275 static_cast<SwDocStyleSheet
*>( m_xBasePool
->Find(rName
, nFamily
) );
1282 case SfxStyleFamily::Para
:
1284 SwTextFormatColl
* pColl
= pStyle
->GetCollection();
1285 if(pColl
&& !pColl
->IsDefault())
1287 GetWrtShell()->StartAllAction();
1289 SwRewriter aRewriter
;
1290 aRewriter
.AddRule(UndoArg1
, pColl
->GetName());
1292 GetWrtShell()->StartUndo(SwUndoId::INSFMTATTR
, &aRewriter
);
1293 GetWrtShell()->FillByEx(pColl
);
1294 // also apply template to remove hard set attributes
1295 GetWrtShell()->SetTextFormatColl( pColl
);
1296 GetWrtShell()->EndUndo();
1297 GetWrtShell()->EndAllAction();
1301 case SfxStyleFamily::Frame
:
1303 SwFrameFormat
* pFrame
= pStyle
->GetFrameFormat();
1304 if( pCurrWrtShell
->IsFrameSelected() && pFrame
&& !pFrame
->IsDefault() )
1306 SfxItemSet
aSet( GetPool(), aFrameFormatSetRange
);
1307 pCurrWrtShell
->StartAllAction();
1308 pCurrWrtShell
->GetFlyFrameAttr( aSet
);
1311 // no update of anchor attribute
1312 aSet
.ClearItem( RES_ANCHOR
);
1314 pFrame
->SetFormatAttr( aSet
);
1316 // also apply template to remove hard set attributes
1317 pCurrWrtShell
->SetFrameFormat( pFrame
, true );
1318 pCurrWrtShell
->EndAllAction();
1322 case SfxStyleFamily::Char
:
1324 SwCharFormat
* pChar
= pStyle
->GetCharFormat();
1325 if( pChar
&& !pChar
->IsDefault() )
1327 pCurrWrtShell
->StartAllAction();
1328 pCurrWrtShell
->FillByEx(pChar
);
1329 // also apply template to remove hard set attributes
1330 pCurrWrtShell
->EndAllAction();
1335 case SfxStyleFamily::Pseudo
:
1337 const SwNumRule
* pCurRule
;
1338 if( pStyle
->GetNumRule() &&
1339 nullptr != ( pCurRule
= pCurrWrtShell
->GetNumRuleAtCurrCursorPos() ))
1341 SwNumRule
aRule( *pCurRule
);
1343 aRule
.SetName( pStyle
->GetNumRule()->GetName(),
1344 pCurrWrtShell
->GetDoc()->getIDocumentListsAccess() );
1345 pCurrWrtShell
->ChgNumRuleFormats( aRule
);
1349 case SfxStyleFamily::Table
:
1351 if (SwFEShell
* pFEShell
= GetFEShell())
1353 if(pFEShell
->IsTableMode())
1355 pFEShell
->TableCursorToCursor();
1358 SwTableAutoFormat
aFormat(rName
);
1359 if (pCurrWrtShell
->GetTableAutoFormat(aFormat
))
1361 pCurrWrtShell
->StartAllAction();
1362 pCurrWrtShell
->GetDoc()->ChgTableStyle(rName
, aFormat
);
1363 pCurrWrtShell
->EndAllAction();
1371 m_xDoc
->BroadcastStyleOperation(rName
, nFamily
, SfxHintId::StyleSheetModified
);
1375 void SwDocShell::MakeByExample( const OUString
&rName
, SfxStyleFamily nFamily
,
1376 SfxStyleSearchBits nMask
, SwWrtShell
* pShell
)
1378 SwWrtShell
* pCurrWrtShell
= pShell
? pShell
: GetWrtShell();
1379 SwDocStyleSheet
* pStyle
= static_cast<SwDocStyleSheet
*>( m_xBasePool
->Find(
1383 // preserve the current mask of PI, then the new one is
1384 // immediately merged with the viewable area
1385 if( SfxStyleSearchBits::All
== nMask
|| SfxStyleSearchBits::Used
== nMask
)
1386 nMask
= SfxStyleSearchBits::UserDefined
;
1388 nMask
|= SfxStyleSearchBits::UserDefined
;
1390 if (nFamily
== SfxStyleFamily::Para
|| nFamily
== SfxStyleFamily::Char
|| nFamily
== SfxStyleFamily::Frame
)
1392 // Prevent undo append from being done during paragraph, character, and frame style Make. Do it later
1393 ::sw::UndoGuard
const undoGuard(GetDoc()->GetIDocumentUndoRedo());
1394 pStyle
= static_cast<SwDocStyleSheet
*>(&m_xBasePool
->Make(rName
, nFamily
, nMask
));
1398 pStyle
= static_cast<SwDocStyleSheet
*>(&m_xBasePool
->Make(rName
, nFamily
, nMask
));
1404 case SfxStyleFamily::Para
:
1406 SwTextFormatColl
* pColl
= pStyle
->GetCollection();
1407 if(pColl
&& !pColl
->IsDefault())
1409 pCurrWrtShell
->StartAllAction();
1410 pCurrWrtShell
->FillByEx(pColl
);
1411 // also apply template to remove hard set attributes
1412 SwTextFormatColl
* pDerivedFrom
= pCurrWrtShell
->GetCurTextFormatColl();
1413 pColl
->SetDerivedFrom(pDerivedFrom
);
1415 // set the mask at the Collection:
1416 sal_uInt16 nId
= pColl
->GetPoolFormatId() & 0x87ff;
1417 switch( nMask
& static_cast<SfxStyleSearchBits
>(0x0fff) )
1419 case SfxStyleSearchBits::SwText
:
1420 nId
|= COLL_TEXT_BITS
;
1422 case SfxStyleSearchBits::SwChapter
:
1423 nId
|= COLL_DOC_BITS
;
1425 case SfxStyleSearchBits::SwList
:
1426 nId
|= COLL_LISTS_BITS
;
1428 case SfxStyleSearchBits::SwIndex
:
1429 nId
|= COLL_REGISTER_BITS
;
1431 case SfxStyleSearchBits::SwExtra
:
1432 nId
|= COLL_EXTRA_BITS
;
1434 case SfxStyleSearchBits::SwHtml
:
1435 nId
|= COLL_HTML_BITS
;
1439 pColl
->SetPoolFormatId(nId
);
1441 if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1443 GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1444 std::make_unique
<SwUndoTextFormatCollCreate
>(pColl
, pDerivedFrom
, *GetDoc()));
1446 pCurrWrtShell
->SetTextFormatColl(pColl
);
1447 pCurrWrtShell
->EndAllAction();
1451 case SfxStyleFamily::Frame
:
1453 SwFrameFormat
* pFrame
= pStyle
->GetFrameFormat();
1454 if(pCurrWrtShell
->IsFrameSelected() && pFrame
&& !pFrame
->IsDefault())
1456 pCurrWrtShell
->StartAllAction();
1458 SfxItemSet
aSet(GetPool(), aFrameFormatSetRange
);
1459 pCurrWrtShell
->GetFlyFrameAttr( aSet
);
1460 aSet
.ClearItem(RES_ANCHOR
); // tdf#112574 no anchor in styles
1462 SwFrameFormat
* pFFormat
= pCurrWrtShell
->GetSelectedFrameFormat();
1463 pFrame
->SetDerivedFrom( pFFormat
);
1464 pFrame
->SetFormatAttr( aSet
);
1465 if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1467 GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1468 std::make_unique
<SwUndoFrameFormatCreate
>(pFrame
, pFFormat
, *GetDoc()));
1470 // also apply template to remove hard set attributes
1471 pCurrWrtShell
->SetFrameFormat(pFrame
);
1472 pCurrWrtShell
->EndAllAction();
1476 case SfxStyleFamily::Char
:
1478 SwCharFormat
* pChar
= pStyle
->GetCharFormat();
1479 if(pChar
&& !pChar
->IsDefault())
1481 pCurrWrtShell
->StartAllAction();
1482 pCurrWrtShell
->FillByEx( pChar
);
1483 SwCharFormat
* pDerivedFrom
= pCurrWrtShell
->GetCurCharFormat();
1484 pChar
->SetDerivedFrom( pDerivedFrom
);
1485 SwFormatCharFormat
aFormat( pChar
);
1487 if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1489 // Looks like sometimes pDerivedFrom can be null and this is not supported by redo code
1490 // So use default format as a derived from in such situations
1491 GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1492 std::make_unique
<SwUndoCharFormatCreate
>(
1493 pChar
, pDerivedFrom
? pDerivedFrom
: GetDoc()->GetDfltCharFormat(),
1496 pCurrWrtShell
->SetAttrItem(aFormat
);
1497 pCurrWrtShell
->EndAllAction();
1502 case SfxStyleFamily::Page
:
1504 pCurrWrtShell
->StartAllAction();
1505 size_t nPgDsc
= pCurrWrtShell
->GetCurPageDesc();
1506 SwPageDesc
& rSrc
= const_cast<SwPageDesc
&>(pCurrWrtShell
->GetPageDesc( nPgDsc
));
1507 SwPageDesc
& rDest
= *const_cast<SwPageDesc
*>(pStyle
->GetPageDesc());
1509 sal_uInt16 nPoolId
= rDest
.GetPoolFormatId();
1510 sal_uInt16 nHId
= rDest
.GetPoolHelpId();
1511 sal_uInt8 nHFId
= rDest
.GetPoolHlpFileId();
1513 pCurrWrtShell
->GetDoc()->CopyPageDesc( rSrc
, rDest
);
1515 // PoolId must NEVER be copied!
1516 rDest
.SetPoolFormatId( nPoolId
);
1517 rDest
.SetPoolHelpId( nHId
);
1518 rDest
.SetPoolHlpFileId( nHFId
);
1520 // when Headers/Footers are created, there is no Undo anymore!
1521 pCurrWrtShell
->GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj();
1523 pCurrWrtShell
->EndAllAction();
1527 case SfxStyleFamily::Pseudo
:
1529 const SwNumRule
* pCurRule
= pCurrWrtShell
->GetNumRuleAtCurrCursorPos();
1533 pCurrWrtShell
->StartAllAction();
1535 SwNumRule
aRule( *pCurRule
);
1536 OUString
sOrigRule( aRule
.GetName() );
1538 aRule
.SetName( pStyle
->GetNumRule()->GetName(),
1539 pCurrWrtShell
->GetDoc()->getIDocumentListsAccess() );
1540 pCurrWrtShell
->ChgNumRuleFormats( aRule
);
1542 pCurrWrtShell
->ReplaceNumRule( sOrigRule
, aRule
.GetName() );
1544 pCurrWrtShell
->EndAllAction();
1549 case SfxStyleFamily::Table
:
1551 SwTableAutoFormat
* pFormat
= pStyle
->GetTableFormat();
1552 if (pCurrWrtShell
->GetTableAutoFormat(*pFormat
))
1554 pCurrWrtShell
->StartAllAction();
1556 pCurrWrtShell
->SetTableStyle(rName
);
1558 pCurrWrtShell
->EndAllAction();
1566 m_xDoc
->BroadcastStyleOperation(rName
, nFamily
, SfxHintId::StyleSheetCreated
);
1569 sfx::AccessibilityIssueCollection
SwDocShell::runAccessibilityCheck()
1571 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
1572 sw::AccessibilityCheck
aCheck(m_xDoc
.get());
1574 return aCheck
.getIssueCollection();
1576 return sfx::AccessibilityIssueCollection();
1580 std::set
<Color
> SwDocShell::GetDocColors()
1582 return m_xDoc
->GetDocColors();
1585 std::shared_ptr
<model::ColorSet
> SwDocShell::GetThemeColors()
1587 SdrPage
* pPage
= m_xDoc
->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
1590 auto const& pTheme
= pPage
->getSdrPageProperties().GetTheme();
1593 return pTheme
->getColorSet();
1596 void SwDocShell::LoadStyles( SfxObjectShell
& rSource
)
1598 LoadStyles_(rSource
, false);
1601 // bPreserveCurrentDocument determines whether SetFixFields() is called
1602 // This call modifies the source document. This mustn't happen when the source
1603 // is a document the user is working on.
1604 // Calls of ::LoadStyles() normally use files especially loaded for the purpose
1605 // of importing styles.
1606 void SwDocShell::LoadStyles_( SfxObjectShell
& rSource
, bool bPreserveCurrentDocument
)
1610 This method is called by SFx if Styles have to be reloaded from a
1611 document-template. Existing Styles should be overwritten by that.
1612 That's why the document has to be reformatted. Therefore applications
1613 will usually override this method and call the baseclass' implementation
1614 in their implementation.
1616 // When the source is our document, we do the checking ourselves
1617 // (much quicker and doesn't use the crutch StxStylePool).
1618 if( dynamic_cast<const SwDocShell
*>( &rSource
) != nullptr)
1620 // in order for the Headers/Footers not to get the fixed content
1621 // of the template, update all the Source's
1623 if(!bPreserveCurrentDocument
)
1624 static_cast<SwDocShell
&>(rSource
).m_xDoc
->getIDocumentFieldsAccess().SetFixFields(nullptr);
1627 // rhbz#818557, fdo#58893: EndAllAction will call SelectShell(),
1628 // which pushes a bunch of SfxShells that are not cleared
1629 // (for unknown reasons) when closing the document, causing crash;
1630 // setting g_bNoInterrupt appears to avoid the problem.
1631 ::comphelper::FlagRestorationGuard
g(g_bNoInterrupt
, true);
1632 m_pWrtShell
->StartAllAction();
1633 m_xDoc
->ReplaceStyles( *static_cast<SwDocShell
&>(rSource
).m_xDoc
);
1634 m_pWrtShell
->EndAllAction();
1638 bool bModified
= m_xDoc
->getIDocumentState().IsModified();
1639 m_xDoc
->ReplaceStyles( *static_cast<SwDocShell
&>(rSource
).m_xDoc
);
1640 if (!bModified
&& m_xDoc
->getIDocumentState().IsModified() && !m_pView
)
1642 // the View is created later, but overwrites the Modify-Flag.
1643 // Undo doesn't work anymore anyways.
1644 m_xDoc
->GetIDocumentUndoRedo().SetUndoNoResetModified();
1649 SfxObjectShell::LoadStyles( rSource
);
1652 void SwDocShell::FormatPage(
1653 weld::Window
* pDialogParent
,
1654 const OUString
& rPage
,
1655 const OUString
& rPageId
,
1656 SwWrtShell
& rActShell
,
1657 SfxRequest
* pRequest
)
1659 Edit(pDialogParent
, rPage
, OUString(), SfxStyleFamily::Page
, SfxStyleSearchBits::Auto
, false, rPageId
, &rActShell
, pRequest
);
1662 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */