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 <svx/xdef.hxx>
47 #include <SwStyleNameMapper.hxx>
48 #include <SwRewriter.hxx>
49 #include <numrule.hxx>
51 #include <svx/drawitem.hxx>
58 #include <viewopt.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>
68 #include <charfmt.hxx>
69 #include <poolfmt.hxx>
70 #include <pagedesc.hxx>
71 #include <docstyle.hxx>
72 #include <uiitems.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>
90 #include <svl/ptitem.hxx>
91 #include <editeng/sizeitem.hxx>
92 #include <editeng/ulspitem.hxx>
94 using namespace ::com::sun::star
;
96 static OutlinerView
* lcl_GetPostItOutlinerView(SwWrtShell
& rShell
)
98 SwPostItMgr
* pPostItMgr
= rShell
.GetPostItMgr();
101 sw::annotation::SwAnnotationWin
* pWin
= pPostItMgr
->GetActiveSidebarWin();
104 return pWin
->GetOutlinerView();
107 void SwDocShell::StateStyleSheet(SfxItemSet
& rSet
, SwWrtShell
* pSh
)
109 SfxWhichIter
aIter(rSet
);
110 sal_uInt16 nWhich
= aIter
.FirstWhich();
111 SfxStyleFamily nActualFamily
= SfxStyleFamily(USHRT_MAX
);
113 SwWrtShell
* pShell
= pSh
? pSh
: GetWrtShell();
118 rSet
.DisableItem(nWhich
);
119 nWhich
= aIter
.NextWhich();
125 SfxViewFrame
& rFrame
= pShell
->GetView().GetViewFrame();
126 std::unique_ptr
<SfxUInt16Item
> pFamilyItem
;
127 rFrame
.GetBindings().QueryState(SID_STYLE_FAMILY
, pFamilyItem
);
130 nActualFamily
= static_cast<SfxStyleFamily
>(pFamilyItem
->GetValue());
136 // determine current template to every family
138 SwTableAutoFormat
aTableAutoFormat(u
"dummy"_ustr
); // needed to check if can take a table auto format at current cursor position
141 case SID_STYLE_APPLY
:
142 {// here the template and its family are passed to the StyleBox
143 // so that this family is being showed
144 if(pShell
->IsFrameSelected())
146 SwFrameFormat
* pFormat
= pShell
->GetSelectedFrameFormat();
148 aName
= pFormat
->GetName();
150 else if (pShell
->GetSelectionType() == SelectionType::PostIt
)
152 OutlinerView
*pOLV
= lcl_GetPostItOutlinerView(*pShell
);
153 if (SfxStyleSheetBase
* pStyle
= pOLV
? pOLV
->GetStyleSheet() : nullptr)
154 aName
= pStyle
->GetName();
158 SwTextFormatColl
* pColl
= pShell
->GetCurTextFormatColl();
160 aName
= pColl
->GetName();
162 rSet
.Put(SfxTemplateItem(nWhich
, aName
));
165 case SID_STYLE_FAMILY1
:
166 if( !pShell
->IsFrameSelected() )
168 SwCharFormat
* pFormat
= pShell
->GetCurCharFormat();
170 aName
= pFormat
->GetName();
172 aName
= SwResId(STR_POOLCHR_STANDARD
);
173 rSet
.Put(SfxTemplateItem(nWhich
, aName
));
177 case SID_STYLE_FAMILY2
:
178 if(!pShell
->IsFrameSelected())
181 if (pShell
->GetSelectionType() == SelectionType::PostIt
)
183 OutlinerView
*pOLV
= lcl_GetPostItOutlinerView(*pShell
);
184 if (SfxStyleSheetBase
* pStyle
= pOLV
? pOLV
->GetStyleSheet() : nullptr)
186 aName
= pStyle
->GetName();
187 aProgName
= SwStyleNameMapper::GetProgName(aName
, SwGetPoolIdFromName::TxtColl
);
190 else if (auto pColl
= pShell
->GetCurTextFormatColl())
192 aName
= pColl
->GetName();
193 sal_uInt16 nId
= pColl
->GetPoolFormatId();
194 SwStyleNameMapper::FillProgName(nId
, aProgName
);
197 SfxTemplateItem
aItem(nWhich
, aName
, aProgName
.toString());
199 SfxStyleSearchBits nMask
= SfxStyleSearchBits::Auto
;
200 if (m_xDoc
->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE
))
201 nMask
= SfxStyleSearchBits::SwHtml
;
204 const FrameTypeFlags nSelection
= pShell
->GetFrameType(nullptr,true);
205 if(pShell
->GetCurTOX())
206 nMask
= SfxStyleSearchBits::SwIndex
;
207 else if(nSelection
& FrameTypeFlags::HEADER
||
208 nSelection
& FrameTypeFlags::FOOTER
||
209 nSelection
& FrameTypeFlags::TABLE
||
210 nSelection
& FrameTypeFlags::FLY_ANY
||
211 nSelection
& FrameTypeFlags::FOOTNOTE
||
212 nSelection
& FrameTypeFlags::FTNPAGE
)
213 nMask
= SfxStyleSearchBits::SwExtra
;
215 nMask
= SfxStyleSearchBits::SwText
;
218 aItem
.SetValue(nMask
);
224 case SID_STYLE_FAMILY3
:
226 if (m_xDoc
->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE
))
227 rSet
.DisableItem( nWhich
);
230 SwFrameFormat
* pFormat
= pShell
->GetSelectedFrameFormat();
231 if(pFormat
&& pShell
->IsFrameSelected())
233 aName
= pFormat
->GetName();
234 rSet
.Put(SfxTemplateItem(nWhich
, aName
));
239 case SID_STYLE_FAMILY4
:
241 if (m_xDoc
->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE
) && !officecfg::Office::Common::Filter::HTML::Export::PrintLayout::get())
242 rSet
.DisableItem( nWhich
);
245 size_t n
= pShell
->GetCurPageDesc( false );
246 if( n
< pShell
->GetPageDescCnt() )
247 aName
= pShell
->GetPageDesc( n
).GetName();
249 rSet
.Put(SfxTemplateItem(nWhich
, aName
));
253 case SID_STYLE_FAMILY5
:
255 const SwNumRule
* pRule
= pShell
->GetNumRuleAtCurrCursorPos();
257 aName
= pRule
->GetName();
259 rSet
.Put(SfxTemplateItem(nWhich
, aName
));
262 case SID_STYLE_FAMILY6
:
264 const SwTableNode
*pTableNd
= pShell
->IsCursorInTable();
266 aName
= pTableNd
->GetTable().GetTableStyleName();
268 rSet
.Put(SfxTemplateItem(nWhich
, aName
));
272 case SID_STYLE_WATERCAN
:
274 SwEditWin
& rEdtWin
= pShell
->GetView().GetEditWin();
275 SwApplyTemplate
* pApply
= rEdtWin
.GetApplyTemplate();
276 rSet
.Put(SfxBoolItem(nWhich
, pApply
&& pApply
->eType
!= SfxStyleFamily(0)));
279 case SID_STYLE_UPDATE_BY_EXAMPLE
:
280 if( pShell
->IsFrameSelected()
281 ? SfxStyleFamily::Frame
!= nActualFamily
282 : ( SfxStyleFamily::Frame
== nActualFamily
||
283 SfxStyleFamily::Page
== nActualFamily
||
284 (SfxStyleFamily::Pseudo
== nActualFamily
&& !pShell
->GetNumRuleAtCurrCursorPos()) ||
285 (SfxStyleFamily::Table
== nActualFamily
&& !pShell
->GetTableAutoFormat(aTableAutoFormat
))) )
287 rSet
.DisableItem( nWhich
);
291 case SID_STYLE_NEW_BY_EXAMPLE
:
292 if( (pShell
->IsFrameSelected()
293 ? SfxStyleFamily::Frame
!= nActualFamily
294 : SfxStyleFamily::Frame
== nActualFamily
) ||
295 (SfxStyleFamily::Pseudo
== nActualFamily
&& !pShell
->GetNumRuleAtCurrCursorPos()) ||
296 (SfxStyleFamily::Table
== nActualFamily
&& !pShell
->GetTableAutoFormat(aTableAutoFormat
)) )
298 rSet
.DisableItem( nWhich
);
302 case SID_CLASSIFICATION_APPLY
:
303 // Just trigger ClassificationCategoriesController::statusChanged().
304 rSet
.InvalidateItem(nWhich
);
306 case SID_CLASSIFICATION_DIALOG
:
307 rSet
.InvalidateItem(nWhich
);
314 SfxWatermarkItem aItem
= pSh
->GetWatermark();
319 OSL_FAIL("Invalid SlotId");
321 nWhich
= aIter
.NextWhich();
325 // evaluate StyleSheet-Requests
326 void SwDocShell::ExecStyleSheet( SfxRequest
& rReq
)
328 sal_uInt16 nSlot
= rReq
.GetSlot();
330 const SfxItemSet
* pArgs
= rReq
.GetArgs();
331 const SfxPoolItem
* pItem
;
335 if( pArgs
&& SfxItemState::SET
== pArgs
->GetItemState( SID_STYLE_FAMILY
,
338 const SfxStyleFamily nFamily
= static_cast<SfxStyleFamily
>(static_cast<const SfxUInt16Item
*>(pItem
)->GetValue());
341 SfxStyleSearchBits nMask
= SfxStyleSearchBits::Auto
;
342 if( SfxItemState::SET
== pArgs
->GetItemState( SID_STYLE_NEW
,
344 sName
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
345 if( SfxItemState::SET
== pArgs
->GetItemState( SID_STYLE_MASK
,
347 nMask
= static_cast<SfxStyleSearchBits
>(static_cast<const SfxUInt16Item
*>(pItem
)->GetValue());
349 if( SfxItemState::SET
== pArgs
->GetItemState( SID_STYLE_REFERENCE
,
351 sParent
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
353 if (sName
.isEmpty() && m_xBasePool
)
354 sName
= SfxStyleDialogController::GenerateUnusedName(*m_xBasePool
, nFamily
);
356 Edit(rReq
.GetFrameWeld(), sName
, sParent
, nFamily
, nMask
, true, {}, nullptr, &rReq
, nSlot
);
360 case SID_STYLE_APPLY
:
363 GetView()->GetViewFrame().GetDispatcher()->Execute(SID_STYLE_DESIGNER
);
368 // convert internal StyleName to DisplayName (slot implementation uses the latter)
369 const SfxStringItem
* pNameItem
= rReq
.GetArg
<SfxStringItem
>(SID_APPLY_STYLE
);
370 const SfxStringItem
* pFamilyItem
= rReq
.GetArg
<SfxStringItem
>(SID_STYLE_FAMILYNAME
);
371 if ( pFamilyItem
&& pNameItem
)
373 uno::Reference
< style::XStyleFamiliesSupplier
> xModel(GetModel(), uno::UNO_QUERY
);
376 uno::Reference
< container::XNameAccess
> xStyles
;
377 uno::Reference
< container::XNameAccess
> xCont
= xModel
->getStyleFamilies();
378 xCont
->getByName(pFamilyItem
->GetValue()) >>= xStyles
;
379 uno::Reference
< beans::XPropertySet
> xInfo
;
380 xStyles
->getByName( pNameItem
->GetValue() ) >>= xInfo
;
382 xInfo
->getPropertyValue(u
"DisplayName"_ustr
) >>= aUIName
;
383 if ( !aUIName
.isEmpty() )
384 rReq
.AppendItem( SfxStringItem( SID_STYLE_APPLY
, aUIName
) );
386 catch (const uno::Exception
&)
396 case SID_STYLE_DELETE
:
399 case SID_STYLE_WATERCAN
:
400 case SID_STYLE_FAMILY
:
401 case SID_STYLE_UPDATE_BY_EXAMPLE
:
402 case SID_STYLE_NEW_BY_EXAMPLE
:
405 SfxStyleFamily nFamily
= SfxStyleFamily::Para
;
406 SfxStyleSearchBits nMask
= SfxStyleSearchBits::Auto
;
407 SwWrtShell
* pActShell
= nullptr;
413 case SID_STYLE_NEW_BY_EXAMPLE
:
415 SfxStyleSheetBasePool
& rPool
= *GetStyleSheetPool();
416 SfxNewStyleDlg
aDlg(GetView()->GetFrameWeld(), rPool
, nFamily
);
417 if (aDlg
.run() == RET_OK
)
419 aParam
= aDlg
.GetName();
420 rReq
.AppendItem(SfxStringItem(nSlot
, aParam
));
425 case SID_STYLE_UPDATE_BY_EXAMPLE
:
428 if (GetWrtShell()->GetSelectionType() == SelectionType::PostIt
)
430 OutlinerView
*pOLV
= lcl_GetPostItOutlinerView(*GetWrtShell());
431 if (SfxStyleSheetBase
* pStyle
= pOLV
? pOLV
->GetStyleSheet() : nullptr)
432 aParam
= pStyle
->GetName();
434 else if (auto pColl
= GetWrtShell()->GetCurTextFormatColl())
435 aParam
= pColl
->GetName();
437 if (!aParam
.isEmpty())
438 rReq
.AppendItem(SfxStringItem(nSlot
, aParam
));
445 SAL_WARN_IF( !pArgs
->Count(), "sw.ui", "SfxBug ItemSet is empty" );
447 SwWrtShell
* pShell
= GetWrtShell();
448 if( SfxItemState::SET
== pArgs
->GetItemState(nSlot
, false, &pItem
))
449 aParam
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
451 if( SfxItemState::SET
== pArgs
->GetItemState(SID_STYLE_FAMILY
,
453 nFamily
= static_cast<SfxStyleFamily
>(static_cast<const SfxUInt16Item
*>(pItem
)->GetValue());
455 if( SfxItemState::SET
== pArgs
->GetItemState(SID_STYLE_FAMILYNAME
, false, &pItem
))
457 OUString aFamily
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
458 if(aFamily
== "CharacterStyles")
459 nFamily
= SfxStyleFamily::Char
;
461 if(aFamily
== "ParagraphStyles")
462 nFamily
= SfxStyleFamily::Para
;
464 if(aFamily
== "PageStyles")
465 nFamily
= SfxStyleFamily::Page
;
467 if(aFamily
== "FrameStyles")
468 nFamily
= SfxStyleFamily::Frame
;
470 if(aFamily
== "NumberingStyles")
471 nFamily
= SfxStyleFamily::Pseudo
;
473 if(aFamily
== "TableStyles")
474 nFamily
= SfxStyleFamily::Table
;
477 if( SfxItemState::SET
== pArgs
->GetItemState(SID_STYLE_MASK
,
479 nMask
= static_cast<SfxStyleSearchBits
>(static_cast<const SfxUInt16Item
*>(pItem
)->GetValue());
480 if( const SwPtrItem
* pShellItem
= pArgs
->GetItemIfSet(FN_PARAM_WRTSHELL
, false ))
481 pActShell
= pShell
= static_cast<SwWrtShell
*>(pShellItem
->GetValue());
483 if( nSlot
== SID_STYLE_UPDATE_BY_EXAMPLE
&& aParam
.isEmpty() )
487 case SfxStyleFamily::Para
:
489 SwTextFormatColl
* pColl
= pShell
->GetCurTextFormatColl();
491 aParam
= pColl
->GetName();
494 case SfxStyleFamily::Frame
:
496 SwFrameFormat
* pFrame
= m_pWrtShell
->GetSelectedFrameFormat();
498 aParam
= pFrame
->GetName();
501 case SfxStyleFamily::Char
:
503 SwCharFormat
* pChar
= m_pWrtShell
->GetCurCharFormat();
505 aParam
= pChar
->GetName();
508 case SfxStyleFamily::Pseudo
:
509 if(const SfxStringItem
* pExName
= pArgs
->GetItemIfSet(SID_STYLE_UPD_BY_EX_NAME
, false))
511 aParam
= pExName
->GetValue();
514 case SfxStyleFamily::Table
:
515 if(const SfxStringItem
* pExName
= pArgs
->GetItemIfSet(SID_STYLE_UPD_BY_EX_NAME
, false))
517 aParam
= pExName
->GetValue();
522 rReq
.AppendItem(SfxStringItem(nSlot
, aParam
));
525 if (!aParam
.isEmpty() || nSlot
== SID_STYLE_WATERCAN
)
527 sal_uInt16 nRet
= 0xffff;
528 bool bReturns
= false;
534 Edit(rReq
.GetFrameWeld(), aParam
, {}, nFamily
, nMask
, false, (nSlot
== SID_STYLE_FONT
) ? u
"font"_ustr
: OUString(), pActShell
);
536 case SID_STYLE_DELETE
:
537 Delete(aParam
, nFamily
);
541 Hide(aParam
, nFamily
, nSlot
== SID_STYLE_HIDE
);
543 case SID_STYLE_APPLY
:
544 // Shell-switch in ApplyStyles
545 nRet
= static_cast<sal_uInt16
>(ApplyStyles(aParam
, nFamily
, pActShell
, rReq
.GetModifier() ));
548 case SID_STYLE_WATERCAN
:
549 nRet
= static_cast<sal_uInt16
>(DoWaterCan(aParam
, nFamily
));
552 case SID_STYLE_UPDATE_BY_EXAMPLE
:
553 UpdateStyle(aParam
, nFamily
, pActShell
);
555 case SID_STYLE_NEW_BY_EXAMPLE
:
556 MakeByExample(aParam
, nFamily
, nMask
, pActShell
);
560 OSL_FAIL("Invalid SlotId");
563 // Update formatting toolbar buttons status
564 if (GetWrtShell()->GetSelectionType() == SelectionType::PostIt
)
565 GetView()->GetViewFrame().GetBindings().InvalidateAll(false);
569 if(rReq
.IsAPI()) // Basic only gets TRUE or FALSE
570 rReq
.SetReturnValue(SfxUInt16Item(nSlot
, sal_uInt16(nRet
!=0)));
572 rReq
.SetReturnValue(SfxUInt16Item(nSlot
, nRet
));
588 ApplyStyle(SwDocShell
&rDocSh
, bool bNew
,
589 rtl::Reference
< SwDocStyleSheet
> xTmp
,
590 SfxStyleFamily nFamily
, SfxAbstractApplyTabDialog
*pDlg
,
591 rtl::Reference
< SfxStyleSheetBasePool
> xBasePool
,
596 , m_xTmp(std::move(xTmp
))
598 , m_xBasePool(std::move(xBasePool
))
599 , m_bModified(bModified
)
602 DECL_LINK( ApplyHdl
, LinkParamNone
*, void );
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
615 SwDocShell
&m_rDocSh
;
617 rtl::Reference
< SwDocStyleSheet
> m_xTmp
;
618 SfxStyleFamily m_nFamily
;
619 rtl::Reference
< SfxStyleSheetBasePool
> m_xBasePool
;
625 IMPL_LINK_NOARG(ApplyStyle
, ApplyHdl
, LinkParamNone
*, void)
627 SwWrtShell
* pWrtShell
= m_rDocSh
.GetWrtShell();
628 SwDoc
* pDoc
= m_rDocSh
.GetDoc();
629 SwView
* pView
= m_rDocSh
.GetView();
631 pWrtShell
->StartAllAction();
633 if( SfxStyleFamily::Para
== m_nFamily
)
635 SfxItemSet
aSet( *m_pDlg
->GetOutputItemSet() );
636 ::ConvertAttrGenToChar(aSet
, m_xTmp
->GetItemSet(), /*bIsPara=*/true);
637 ::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 m_xTmp
->SetItemSet( aSet
, false, true );
644 if(SfxStyleFamily::Page
== m_nFamily
|| SfxStyleFamily::Frame
== m_nFamily
)
646 static const sal_uInt16 aInval
[] = {
647 SID_IMAGE_ORIENTATION
,
649 FN_INSERT_CTRL
, FN_INSERT_OBJ_CTRL
,
650 FN_TABLE_INSERT_COL_BEFORE
,
651 FN_TABLE_INSERT_COL_AFTER
, 0};
652 pView
->GetViewFrame().GetBindings().Invalidate(aInval
);
654 SfxItemSet
aTmpSet( *m_pDlg
->GetOutputItemSet() );
655 if( SfxStyleFamily::Char
== m_nFamily
)
657 ::ConvertAttrGenToChar(aTmpSet
, m_xTmp
->GetItemSet());
660 m_xTmp
->SetItemSet( aTmpSet
, false );
662 if( SfxStyleFamily::Page
== m_nFamily
&& SvtCTLOptions::IsCTLFontEnabled() )
664 const SfxPoolItem
*pItem
= nullptr;
665 if( aTmpSet
.GetItemState( m_rDocSh
.GetPool().GetTrueWhichIDFromSlotID( SID_ATTR_FRAMEDIRECTION
, false ) , true, &pItem
) == SfxItemState::SET
)
666 SwChartHelper::DoUpdateAllCharts( pDoc
);
669 if (m_nFamily
== SfxStyleFamily::Page
)
671 if (const SfxGrabBagItem
* pGrabBagItem
= aTmpSet
.GetItemIfSet(SID_ATTR_CHAR_GRABBAG
))
674 auto it
= pGrabBagItem
->GetGrabBag().find(u
"GutterAtTop"_ustr
);
675 if (it
!= pGrabBagItem
->GetGrabBag().end())
677 it
->second
>>= bGutterAtTop
;
680 = pDoc
->getIDocumentSettingAccess().get(DocumentSettingId::GUTTER_AT_TOP
);
681 if (bOldGutterAtTop
!= bGutterAtTop
)
683 pDoc
->getIDocumentSettingAccess().set(DocumentSettingId::GUTTER_AT_TOP
,
685 pWrtShell
->InvalidateLayout(/*bSizeChanged=*/true);
690 if (m_nFamily
== SfxStyleFamily::Frame
)
692 if (const SfxBoolItem
* pBoolItem
= aTmpSet
.GetItemIfSet(FN_KEEP_ASPECT_RATIO
))
694 const SwViewOption
* pVOpt
= pWrtShell
->GetViewOptions();
695 SwViewOption
aUsrPref(*pVOpt
);
696 aUsrPref
.SetKeepRatio(pBoolItem
->GetValue());
697 if (pBoolItem
->GetValue() != pVOpt
->IsKeepRatio())
699 SwModule::get()->ApplyUsrPref(aUsrPref
, &pWrtShell
->GetView());
707 if(SfxStyleFamily::Frame
== m_nFamily
|| SfxStyleFamily::Para
== m_nFamily
)
709 // clear FillStyle so that it works as a derived attribute
710 SfxItemSet
aTmpSet(*m_pDlg
->GetOutputItemSet());
712 aTmpSet
.ClearItem(XATTR_FILLSTYLE
);
713 m_xTmp
->SetItemSet(aTmpSet
, false);
717 if(SfxStyleFamily::Page
== m_nFamily
)
718 pView
->InvalidateRulerPos();
721 m_xBasePool
->Broadcast(SfxStyleSheetHint(SfxHintId::StyleSheetModified
, *m_xTmp
));
723 pDoc
->getIDocumentState().SetModified();
726 pDoc
->GetIDocumentUndoRedo().SetUndoNoResetModified();
730 pWrtShell
->EndAllAction();
735 /// Checks if there is an Endnote page style in use, and makes sure it has the same orientation
736 /// with the Default (Standard) page style.
737 void syncEndnoteOrientation(const uno::Reference
< style::XStyleFamiliesSupplier
>& xStyleFamSupp
)
739 if (!xStyleFamSupp
.is())
741 SAL_WARN("sw.ui", "Ref to XStyleFamiliesSupplier is null.");
744 uno::Reference
<container::XNameAccess
> xStyleFamilies
= xStyleFamSupp
->getStyleFamilies();
746 if (!xStyleFamilies
.is())
749 uno::Reference
<container::XNameAccess
> xPageStyles(xStyleFamilies
->getByName(u
"PageStyles"_ustr
),
752 if (!xPageStyles
.is())
755 uno::Reference
<css::style::XStyle
> xEndnotePageStyle(xPageStyles
->getByName(u
"Endnote"_ustr
),
758 if (!xEndnotePageStyle
.is())
761 // Language-independent name of the "Default Style" is "Standard"
762 uno::Reference
<css::style::XStyle
> xDefaultPageStyle(xPageStyles
->getByName(u
"Standard"_ustr
),
764 if (!xDefaultPageStyle
.is())
767 if (xEndnotePageStyle
->isUserDefined() || !xEndnotePageStyle
->isInUse())
770 uno::Reference
<beans::XPropertySet
> xEndnotePagePropSet(xPageStyles
->getByName(u
"Endnote"_ustr
), uno::UNO_QUERY
);
771 uno::Reference
<beans::XPropertySet
> xDefaultPagePropSet(xPageStyles
->getByName(u
"Standard"_ustr
), uno::UNO_QUERY
);
773 if (!xEndnotePagePropSet
.is() || !xDefaultPagePropSet
.is())
775 SAL_WARN("sw.ui", "xEndnotePagePropSet or xDefaultPagePropSet is null.");
779 auto const bIsDefLandScape
= *o3tl::doAccess
<bool>(
780 xDefaultPagePropSet
->getPropertyValue(u
"IsLandscape"_ustr
));
781 auto const bIsEndLandScape
= *o3tl::doAccess
<bool>(
782 xEndnotePagePropSet
->getPropertyValue(u
"IsLandscape"_ustr
));
784 if (bIsDefLandScape
== bIsEndLandScape
)
787 auto const nWidth
= xEndnotePagePropSet
->getPropertyValue(u
"Width"_ustr
);
788 auto const nHeight
= xEndnotePagePropSet
->getPropertyValue(u
"Height"_ustr
);
790 xEndnotePagePropSet
->setPropertyValue(u
"IsLandscape"_ustr
, css::uno::toAny(bIsDefLandScape
));
791 xEndnotePagePropSet
->setPropertyValue(u
"Width"_ustr
, nHeight
);
792 xEndnotePagePropSet
->setPropertyValue(u
"Height"_ustr
, nWidth
);
796 void SwDocShell::Edit(
797 weld::Window
* pDialogParent
,
798 const OUString
&rName
,
799 const OUString
&rParent
,
800 const SfxStyleFamily nFamily
,
801 SfxStyleSearchBits nMask
,
803 const OUString
& sPage
,
804 SwWrtShell
* pActShell
,
808 assert( GetWrtShell() );
809 const bool bBasic
= pReq
&& pReq
->IsAPI();
810 SfxStyleSheetBase
*pStyle
= nullptr;
812 bool bModified
= m_xDoc
->getIDocumentState().IsModified();
814 SwUndoId
nNewStyleUndoId(SwUndoId::EMPTY
);
820 // start undo action in order to get only one undo action for the
821 // UI new style + change style operations
822 m_pWrtShell
->StartUndo();
825 if( SfxStyleSearchBits::All
!= nMask
&& SfxStyleSearchBits::AllVisible
!= nMask
&& SfxStyleSearchBits::Used
!= nMask
)
826 nMask
|= SfxStyleSearchBits::UserDefined
;
828 nMask
= SfxStyleSearchBits::UserDefined
;
830 if (nFamily
== SfxStyleFamily::Para
|| nFamily
== SfxStyleFamily::Char
831 || nFamily
== SfxStyleFamily::Frame
|| nFamily
== SfxStyleFamily::Pseudo
)
833 // Do Make undo append after an OK return from the style dialog below
834 ::sw::UndoGuard
const undoGuard(GetDoc()->GetIDocumentUndoRedo());
835 pStyle
= &m_xBasePool
->Make( rName
, nFamily
, nMask
);
839 pStyle
= &m_xBasePool
->Make( rName
, nFamily
, nMask
);
842 // set the current one as Parent
843 SwDocStyleSheet
* pDStyle
= static_cast<SwDocStyleSheet
*>(pStyle
);
846 case SfxStyleFamily::Para
:
848 if(!rParent
.isEmpty())
850 SwTextFormatColl
* pColl
= m_pWrtShell
->FindTextFormatCollByName( rParent
);
853 sal_uInt16 nId
= SwStyleNameMapper::GetPoolIdFromUIName(rParent
, SwGetPoolIdFromName::TxtColl
);
855 pColl
= m_pWrtShell
->GetTextCollFromPool( nId
);
857 pDStyle
->GetCollection()->SetDerivedFrom( pColl
);
858 pDStyle
->PresetParent( rParent
);
862 SwTextFormatColl
* pColl
= m_pWrtShell
->GetCurTextFormatColl();
863 pDStyle
->GetCollection()->SetDerivedFrom( pColl
);
865 pDStyle
->PresetParent( pColl
->GetName() );
869 case SfxStyleFamily::Char
:
871 if(!rParent
.isEmpty())
873 SwCharFormat
* pCFormat
= m_pWrtShell
->FindCharFormatByName(rParent
);
876 sal_uInt16 nId
= SwStyleNameMapper::GetPoolIdFromUIName(rParent
, SwGetPoolIdFromName::ChrFmt
);
878 pCFormat
= m_pWrtShell
->GetCharFormatFromPool( nId
);
881 pDStyle
->GetCharFormat()->SetDerivedFrom( pCFormat
);
882 pDStyle
->PresetParent( rParent
);
886 SwCharFormat
* pCFormat
= m_pWrtShell
->GetCurCharFormat();
887 pDStyle
->GetCharFormat()->SetDerivedFrom( pCFormat
);
889 pDStyle
->PresetParent( pCFormat
->GetName() );
893 case SfxStyleFamily::Frame
:
895 if(!rParent
.isEmpty())
897 SwFrameFormat
* pFFormat
= m_pWrtShell
->GetDoc()->FindFrameFormatByName( rParent
);
900 sal_uInt16 nId
= SwStyleNameMapper::GetPoolIdFromUIName(rParent
, SwGetPoolIdFromName::FrmFmt
);
902 pFFormat
= m_pWrtShell
->GetFrameFormatFromPool( nId
);
904 pDStyle
->GetFrameFormat()->SetDerivedFrom( pFFormat
);
905 pDStyle
->PresetParent( rParent
);
914 //Get the undo id for the type of style that was created in order to re-use that comment for the grouped
915 //create style + change style operations
916 m_pWrtShell
->GetLastUndoInfo(nullptr, &nNewStyleUndoId
);
921 pStyle
= m_xBasePool
->Find( rName
, nFamily
);
922 SAL_WARN_IF( !pStyle
, "sw.ui", "Style not found" );
928 // put dialogues together
929 rtl::Reference
< SwDocStyleSheet
> xTmp( new SwDocStyleSheet( *static_cast<SwDocStyleSheet
*>(pStyle
) ) );
930 if( SfxStyleFamily::Para
== nFamily
)
932 SfxItemSet
& rSet
= xTmp
->GetItemSet();
933 ::SwToSfxPageDescAttr( rSet
);
934 // merge list level indent attributes into the item set if needed
935 xTmp
->MergeIndentAttrsOfListStyle( rSet
);
937 ::ConvertAttrCharToGen(xTmp
->GetItemSet(), /*bIsPara=*/true);
939 else if( SfxStyleFamily::Char
== nFamily
)
941 ::ConvertAttrCharToGen(xTmp
->GetItemSet());
944 if(SfxStyleFamily::Page
== nFamily
|| SfxStyleFamily::Para
== nFamily
)
946 // create needed items for XPropertyList entries from the DrawModel so that
947 // the Area TabPage can access them
948 SfxItemSet
& rSet
= xTmp
->GetItemSet();
949 const SwDrawModel
* pDrawModel
= GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
951 rSet
.Put(SvxColorListItem(pDrawModel
->GetColorList(), SID_COLOR_TABLE
));
952 rSet
.Put(SvxGradientListItem(pDrawModel
->GetGradientList(), SID_GRADIENT_LIST
));
953 rSet
.Put(SvxHatchListItem(pDrawModel
->GetHatchList(), SID_HATCH_LIST
));
954 rSet
.Put(SvxBitmapListItem(pDrawModel
->GetBitmapList(), SID_BITMAP_LIST
));
955 rSet
.Put(SvxPatternListItem(pDrawModel
->GetPatternList(), SID_PATTERN_LIST
));
957 std::map
<OUString
, css::uno::Any
> aGrabBagMap
;
958 if (SfxGrabBagItem
const* pItem
= rSet
.GetItemIfSet(SID_ATTR_CHAR_GRABBAG
))
959 aGrabBagMap
= pItem
->GetGrabBag();
961 = GetDoc()->getIDocumentSettingAccess().get(DocumentSettingId::GUTTER_AT_TOP
);
962 aGrabBagMap
[u
"GutterAtTop"_ustr
] <<= bGutterAtTop
;
963 rSet
.Put(SfxGrabBagItem(SID_ATTR_CHAR_GRABBAG
, std::move(aGrabBagMap
)));
966 SwWrtShell
* pCurrShell
= pActShell
? pActShell
: m_pWrtShell
;
967 if (nFamily
== SfxStyleFamily::Frame
)
969 SfxItemSet
& rSet
= xTmp
->GetItemSet();
970 const SwViewOption
* pVOpt
= pCurrShell
->GetViewOptions();
971 rSet
.Put(SfxBoolItem(FN_KEEP_ASPECT_RATIO
, pVOpt
->IsKeepRatio()));
976 // prior to the dialog the HtmlMode at the DocShell is being sunk
977 sal_uInt16 nHtmlMode
= ::GetHtmlMode(this);
979 // In HTML mode, we do not always have a printer. In order to show
980 // the correct page size in the Format - Page dialog, we have to
982 if( ( HTMLMODE_ON
& nHtmlMode
) &&
983 !pCurrShell
->getIDocumentDeviceAccess().getPrinter( false ) )
984 pCurrShell
->InitPrt( pCurrShell
->getIDocumentDeviceAccess().getPrinter( true ) );
986 PutItem(SfxUInt16Item(SID_HTML_MODE
, nHtmlMode
));
987 FieldUnit eMetric
= ::GetDfltMetric(0 != (HTMLMODE_ON
&nHtmlMode
));
988 SwModule::get()->PutItem(SfxUInt16Item(SID_ATTR_METRIC
, static_cast<sal_uInt16
>(eMetric
)));
989 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
992 SAL_WARN("sw.ui", "no parent for dialog supplied, assuming document frame is good enough");
993 pDialogParent
= GetView()->GetFrameWeld();
995 VclPtr
<SfxAbstractApplyTabDialog
> pDlg(pFact
->CreateTemplateDialog(pDialogParent
,
996 *xTmp
, nFamily
, sPage
, pCurrShell
, bNew
));
997 auto pApplyStyleHelper
= std::make_shared
<ApplyStyle
>(*this, bNew
, xTmp
, nFamily
, pDlg
.get(), m_xBasePool
, bModified
);
998 pDlg
->SetApplyHdl(LINK(pApplyStyleHelper
.get(), ApplyStyle
, ApplyHdl
));
1000 std::shared_ptr
<SfxRequest
> pRequest
;
1003 pRequest
= std::make_shared
<SfxRequest
>(*pReq
);
1004 pReq
->Ignore(); // the 'old' request is not relevant any more
1007 bool bIsDefaultPage
= nFamily
== SfxStyleFamily::Page
1008 && rName
== SwResId(STR_POOLPAGE_STANDARD
)
1010 && !pStyle
->IsUserDefined();
1012 pDlg
->StartExecuteAsync([bIsDefaultPage
, bNew
, nFamily
, nSlot
, nNewStyleUndoId
,
1013 pApplyStyleHelper
=std::move(pApplyStyleHelper
),
1014 pRequest
=std::move(pRequest
), xTmp
, this](sal_Int32 nResult
){
1015 if (RET_OK
== nResult
)
1016 pApplyStyleHelper
->apply();
1022 case SfxStyleFamily::Para
:
1024 if(!xTmp
->GetParent().isEmpty())
1026 SwTextFormatColl
* pColl
= m_pWrtShell
->FindTextFormatCollByName(xTmp
->GetParent());
1027 if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1029 GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1030 std::make_unique
<SwUndoTextFormatCollCreate
>(xTmp
->GetCollection(), pColl
, *GetDoc()));
1035 case SfxStyleFamily::Char
:
1037 if(!xTmp
->GetParent().isEmpty())
1039 SwCharFormat
* pCFormat
= m_pWrtShell
->FindCharFormatByName(xTmp
->GetParent());
1040 if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1042 GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1043 std::make_unique
<SwUndoCharFormatCreate
>(xTmp
->GetCharFormat(), pCFormat
, *GetDoc()));
1048 case SfxStyleFamily::Frame
:
1050 if(!xTmp
->GetParent().isEmpty())
1052 SwFrameFormat
* pFFormat
= m_pWrtShell
->GetDoc()->FindFrameFormatByName(xTmp
->GetParent());
1053 if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1055 GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1056 std::make_unique
<SwUndoFrameFormatCreate
>(xTmp
->GetFrameFormat(), pFFormat
, *GetDoc()));
1061 case SfxStyleFamily::Pseudo
:
1063 if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1065 GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1066 std::make_unique
<SwUndoNumruleCreate
>(xTmp
->GetNumRule(),
1074 SwRewriter aRewriter
;
1075 aRewriter
.AddRule(UndoArg1
, xTmp
->GetName());
1076 //Group the create style and change style operations together under the
1077 //one "create style" comment
1078 m_pWrtShell
->EndUndo(nNewStyleUndoId
, &aRewriter
);
1081 bool bDocModified
= pApplyStyleHelper
->DocIsModified();
1083 if (RET_OK
!= nResult
)
1087 GetWrtShell()->Undo();
1088 m_xDoc
->GetIDocumentUndoRedo().ClearRedo();
1092 m_xDoc
->getIDocumentState().ResetModified();
1095 // Update Watermark if new page style was created
1096 if (nSlot
== SID_STYLE_NEW
&& nFamily
== SfxStyleFamily::Page
)
1098 SwWrtShell
* pShell
= GetWrtShell();
1099 const SfxWatermarkItem aWatermark
= pShell
->GetWatermark();
1100 pShell
->SetWatermark(aWatermark
);
1103 pApplyStyleHelper
->m_pDlg
.disposeAndClear();
1107 if (bIsDefaultPage
&& bDocModified
)
1109 uno::Reference
< style::XStyleFamiliesSupplier
> xStyleFamSupp(GetModel(), uno::UNO_QUERY
);
1111 if (!xStyleFamSupp
.is())
1113 SAL_WARN("sw.ui", "Ref to XStyleFamiliesSupplier is null.");
1117 syncEndnoteOrientation(xStyleFamSupp
);
1123 // prior to the dialog the HtmlMode at the DocShell is being sunk
1124 PutItem(SfxUInt16Item(SID_HTML_MODE
, ::GetHtmlMode(this)));
1126 GetWrtShell()->StartAllAction();
1128 if( SfxStyleFamily::Para
== nFamily
)
1130 ::SfxToSwPageDescAttr( *GetWrtShell(), xTmp
->GetItemSet() );
1131 ::ConvertAttrGenToChar(xTmp
->GetItemSet(), xTmp
->GetItemSet(), /*bIsPara=*/true);
1135 ::ConvertAttrGenToChar(xTmp
->GetItemSet(), xTmp
->GetItemSet());
1137 if(SfxStyleFamily::Page
== nFamily
)
1138 m_pView
->InvalidateRulerPos();
1140 m_xDoc
->getIDocumentState().SetModified();
1141 if( !bModified
) // Bug 57028
1143 m_xDoc
->GetIDocumentUndoRedo().SetUndoNoResetModified();
1145 GetWrtShell()->EndAllAction();
1149 void SwDocShell::Delete(const OUString
&rName
, SfxStyleFamily nFamily
)
1151 SfxStyleSheetBase
*pStyle
= m_xBasePool
->Find(rName
, nFamily
);
1155 assert( GetWrtShell() );
1157 GetWrtShell()->StartAllAction();
1158 m_xBasePool
->Remove(pStyle
);
1159 GetWrtShell()->EndAllAction();
1163 void SwDocShell::Hide(const OUString
&rName
, SfxStyleFamily nFamily
, bool bHidden
)
1165 SfxStyleSheetBase
*pStyle
= m_xBasePool
->Find(rName
, nFamily
);
1169 assert( GetWrtShell() );
1171 GetWrtShell()->StartAllAction();
1172 rtl::Reference
< SwDocStyleSheet
> xTmp( new SwDocStyleSheet( *static_cast<SwDocStyleSheet
*>(pStyle
) ) );
1173 xTmp
->SetHidden( bHidden
);
1174 GetWrtShell()->EndAllAction();
1178 #define MAX_CHAR_IN_INLINE_HEADING 120
1179 bool SwDocShell::MakeInlineHeading(SwWrtShell
*pSh
, SwTextFormatColl
* pColl
, const sal_uInt16 nMode
)
1181 // insert an inline heading frame, if only MAX_CHAR_IN_INLINE_HEADING or less
1182 // characters are selected beginning of a single paragraph, but not the full paragraph
1183 // TODO extend it for multiple selections
1184 if ( pSh
->IsSelOnePara() && !pSh
->IsSelFullPara() && pSh
->IsSelStartPara() &&
1185 GetView()->GetSelectionText().getLength() < MAX_CHAR_IN_INLINE_HEADING
&&
1186 0 < GetView()->GetSelectionText().getLength() )
1188 SwTextFormatColl
*pLocal
= pColl
? pColl
: (*GetDoc()->GetTextFormatColls())[0];
1189 // don't put inline heading in a frame (it would be enough to limit for inline heading
1190 // frames, but the recent FN_INSERT_FRAME cannot handle the insertion inside a frame
1192 // TODO: allow to insert inline headings in a (not an Inline Heading) text frame
1193 if ( pSh
->GetCursor()->GetPointNode() !=
1194 *SwOutlineNodes::GetRootNode( &pSh
->GetCursor()->GetPointNode(), /*bInlineHeading=*/false ) )
1199 // put inside a single Undo
1200 SwRewriter aRewriter
;
1201 aRewriter
.AddRule(UndoArg1
, pLocal
->GetName());
1202 GetWrtShell()->StartUndo(SwUndoId::SETFMTCOLL
, &aRewriter
);
1204 // anchor as character
1205 SfxUInt16Item
aAnchor(FN_INSERT_FRAME
, static_cast<sal_uInt16
>(1));
1206 SvxSizeItem
aSizeItem(FN_PARAM_2
, Size(1, 1));
1207 GetView()->GetViewFrame().GetDispatcher()->ExecuteList(FN_INSERT_FRAME
,
1208 SfxCallMode::SYNCHRON
|SfxCallMode::RECORD
, { &aAnchor
, &aSizeItem
});
1209 if ( pSh
->IsFrameSelected() )
1211 // use the associated borderless frame style "Inline Heading"
1212 SwDocStyleSheet
* pStyle2
= static_cast<SwDocStyleSheet
*>(
1213 m_xBasePool
->Find( "Inline Heading", SfxStyleFamily::Frame
));
1214 SAL_WARN_IF( !pStyle2
, "sw.ui", "Style not found" );
1216 pSh
->SetFrameFormat( pStyle2
->GetFrameFormat() );
1218 // select the text content of the frame, and apply the paragraph style
1219 pSh
->UnSelectFrame();
1220 pSh
->LeaveSelFrameMode();
1221 pSh
->MoveSection( GoCurrSection
, fnSectionEnd
);
1224 pSh
->SetTextFormatColl( pColl
, true, (nMode
& KEY_MOD1
) ? SetAttrMode::REMOVE_ALL_ATTR
: SetAttrMode::DEFAULT
);
1226 // zero the upper and lower margins of the paragraph (also an interoperability issue)
1227 SfxItemSetFixed
<RES_UL_SPACE
, RES_UL_SPACE
> aSet2(pSh
->GetAttrPool());
1228 pSh
->GetCurAttr( aSet2
);
1229 SvxULSpaceItem
aUL( 0, 0, RES_UL_SPACE
);
1230 pSh
->SetAttrItem( aUL
);
1232 // leave the inline heading frame
1233 GetView()->GetViewFrame().GetDispatcher()->Execute(FN_ESCAPE
, SfxCallMode::ASYNCHRON
);
1234 GetView()->GetViewFrame().GetDispatcher()->Execute(FN_ESCAPE
, SfxCallMode::ASYNCHRON
);
1235 GetView()->GetViewFrame().GetDispatcher()->Execute(FN_ESCAPE
, SfxCallMode::SYNCHRON
);
1237 GetWrtShell()->EndUndo();
1245 SfxStyleFamily
SwDocShell::ApplyStyles(const OUString
&rName
, SfxStyleFamily nFamily
,
1246 SwWrtShell
* pShell
, const sal_uInt16 nMode
)
1248 SwDocStyleSheet
* pStyle
= static_cast<SwDocStyleSheet
*>( m_xBasePool
->Find( rName
, nFamily
) );
1250 SAL_WARN_IF( !pStyle
, "sw.ui", "Style not found" );
1253 return SfxStyleFamily::None
;
1255 SwWrtShell
*pSh
= pShell
? pShell
: GetWrtShell();
1259 pSh
->StartAllAction();
1263 case SfxStyleFamily::Char
:
1265 SwFormatCharFormat
aFormat(pStyle
->GetCharFormat());
1266 SetAttrMode nFlags
= (nMode
& KEY_SHIFT
) ?
1267 SetAttrMode::DONTREPLACE
: SetAttrMode::DEFAULT
;
1268 if (nMode
& KEY_MOD1
)
1269 nFlags
|= SetAttrMode::REMOVE_ALL_ATTR
;
1270 pSh
->SetAttrItem( aFormat
, nFlags
);
1274 case SfxStyleFamily::Para
:
1276 if (OutlinerView
*pOLV
= lcl_GetPostItOutlinerView(*pSh
))
1277 pOLV
->SetStyleSheet(rName
);
1280 // When outline-folding is enabled, MakeAllOutlineContentTemporarilyVisible makes
1281 // application of a paragraph style that has an outline-level greater than the previous
1282 // outline node become folded content of the previous outline node if the previous
1283 // outline node's content is folded.
1284 MakeAllOutlineContentTemporarilyVisible
a(GetDoc());
1286 // if the first 120 or less characters are selected, but not the full paragraph,
1287 // create an inline heading from the selected text
1288 SwTextFormatColl
* pColl
= pStyle
->GetCollection();
1289 if ( MakeInlineHeading( pSh
, pColl
, nMode
) )
1293 // clear also list attributes at affected text nodes, if paragraph
1294 // style has the list style attribute set.
1295 pSh
->SetTextFormatColl( pColl
, true, (nMode
& KEY_MOD1
) ? SetAttrMode::REMOVE_ALL_ATTR
: SetAttrMode::DEFAULT
);
1299 case SfxStyleFamily::Frame
:
1301 if ( pSh
->IsFrameSelected() )
1302 pSh
->SetFrameFormat( pStyle
->GetFrameFormat() );
1305 case SfxStyleFamily::Page
:
1307 pSh
->SetPageStyle(pStyle
->GetPageDesc()->GetName());
1310 case SfxStyleFamily::Pseudo
:
1312 // reset indent attribute on applying list style
1313 // continue list of list style
1314 const SwNumRule
* pNumRule
= pStyle
->GetNumRule();
1315 if (pNumRule
->GetName() == SwResId(STR_POOLNUMRULE_NOLIST
))
1317 if (SfxViewFrame
* pViewFrm
= SfxViewFrame::Current())
1318 pViewFrm
->GetDispatcher()->Execute(FN_NUM_BULLET_OFF
);
1321 const OUString sListIdForStyle
=pNumRule
->GetDefaultListId();
1322 pSh
->SetCurNumRule( *pNumRule
, false, sListIdForStyle
, true );
1325 case SfxStyleFamily::Table
:
1327 pSh
->SetTableStyle(pStyle
->GetName());
1331 OSL_FAIL("Unknown family");
1333 pSh
->EndAllAction();
1338 // start watering-can
1339 SfxStyleFamily
SwDocShell::DoWaterCan(const OUString
&rName
, SfxStyleFamily nFamily
)
1341 assert( GetWrtShell() );
1343 SwEditWin
& rEdtWin
= m_pView
->GetEditWin();
1344 SwApplyTemplate
* pApply
= rEdtWin
.GetApplyTemplate();
1345 bool bWaterCan
= !(pApply
&& pApply
->eType
!= SfxStyleFamily(0));
1347 if( rName
.isEmpty() )
1350 SwApplyTemplate aTemplate
;
1351 aTemplate
.eType
= nFamily
;
1355 SwDocStyleSheet
* pStyle
=
1356 static_cast<SwDocStyleSheet
*>( m_xBasePool
->Find(rName
, nFamily
) );
1358 SAL_WARN_IF( !pStyle
, "sw.ui", "Where's the StyleSheet" );
1360 if(!pStyle
) return nFamily
;
1364 case SfxStyleFamily::Char
:
1365 aTemplate
.aColl
.pCharFormat
= pStyle
->GetCharFormat();
1367 case SfxStyleFamily::Para
:
1368 aTemplate
.aColl
.pTextColl
= pStyle
->GetCollection();
1370 case SfxStyleFamily::Frame
:
1371 aTemplate
.aColl
.pFrameFormat
= pStyle
->GetFrameFormat();
1373 case SfxStyleFamily::Page
:
1374 aTemplate
.aColl
.pPageDesc
= const_cast<SwPageDesc
*>(pStyle
->GetPageDesc());
1376 case SfxStyleFamily::Pseudo
:
1377 aTemplate
.aColl
.pNumRule
= const_cast<SwNumRule
*>(pStyle
->GetNumRule());
1381 OSL_FAIL("Unknown family");
1385 aTemplate
.eType
= SfxStyleFamily(0);
1387 m_pView
->GetEditWin().SetApplyTemplate(aTemplate
);
1393 void SwDocShell::UpdateStyle(const OUString
&rName
, SfxStyleFamily nFamily
, SwWrtShell
* pShell
)
1395 SwWrtShell
* pCurrWrtShell
= pShell
? pShell
: GetWrtShell();
1396 assert( pCurrWrtShell
);
1398 SwDocStyleSheet
* pStyle
=
1399 static_cast<SwDocStyleSheet
*>( m_xBasePool
->Find(rName
, nFamily
) );
1406 case SfxStyleFamily::Para
:
1408 SwTextFormatColl
* pColl
= pStyle
->GetCollection();
1409 if(pColl
&& !pColl
->IsDefault())
1411 GetWrtShell()->StartAllAction();
1413 SwRewriter aRewriter
;
1414 aRewriter
.AddRule(UndoArg1
, pColl
->GetName());
1416 GetWrtShell()->StartUndo(SwUndoId::INSFMTATTR
, &aRewriter
);
1417 GetWrtShell()->FillByEx(pColl
);
1418 // also apply template to remove hard set attributes
1419 GetWrtShell()->SetTextFormatColl( pColl
);
1420 GetWrtShell()->EndUndo();
1421 GetWrtShell()->EndAllAction();
1425 case SfxStyleFamily::Frame
:
1427 SwFrameFormat
* pFrame
= pStyle
->GetFrameFormat();
1428 if( pCurrWrtShell
->IsFrameSelected() && pFrame
&& !pFrame
->IsDefault() )
1430 SfxItemSet
aSet( GetPool(), aFrameFormatSetRange
);
1431 pCurrWrtShell
->StartAllAction();
1432 pCurrWrtShell
->GetFlyFrameAttr( aSet
);
1435 // no update of anchor attribute
1436 aSet
.ClearItem( RES_ANCHOR
);
1438 pFrame
->SetFormatAttr( aSet
);
1440 // also apply template to remove hard set attributes
1441 pCurrWrtShell
->SetFrameFormat( pFrame
, true );
1442 pCurrWrtShell
->EndAllAction();
1446 case SfxStyleFamily::Char
:
1448 SwCharFormat
* pChar
= pStyle
->GetCharFormat();
1449 if( pChar
&& !pChar
->IsDefault() )
1451 pCurrWrtShell
->StartAllAction();
1452 pCurrWrtShell
->FillByEx(pChar
);
1453 // also apply template to remove hard set attributes
1454 pCurrWrtShell
->EndAllAction();
1459 case SfxStyleFamily::Pseudo
:
1461 const SwNumRule
* pCurRule
;
1462 if( pStyle
->GetNumRule() &&
1463 nullptr != ( pCurRule
= pCurrWrtShell
->GetNumRuleAtCurrCursorPos() ))
1465 SwNumRule
aRule( *pCurRule
);
1467 aRule
.SetName( pStyle
->GetNumRule()->GetName(),
1468 pCurrWrtShell
->GetDoc()->getIDocumentListsAccess() );
1469 pCurrWrtShell
->ChgNumRuleFormats( aRule
);
1473 case SfxStyleFamily::Table
:
1475 if (SwFEShell
* pFEShell
= GetFEShell())
1477 if(pFEShell
->IsTableMode())
1479 pFEShell
->TableCursorToCursor();
1482 SwTableAutoFormat
aFormat(rName
);
1483 if (pCurrWrtShell
->GetTableAutoFormat(aFormat
))
1485 pCurrWrtShell
->StartAllAction();
1486 pCurrWrtShell
->GetDoc()->ChgTableStyle(rName
, aFormat
);
1487 pCurrWrtShell
->EndAllAction();
1495 m_xDoc
->BroadcastStyleOperation(rName
, nFamily
, SfxHintId::StyleSheetModified
);
1499 void SwDocShell::MakeByExample( const OUString
&rName
, SfxStyleFamily nFamily
,
1500 SfxStyleSearchBits nMask
, SwWrtShell
* pShell
)
1502 SwWrtShell
* pCurrWrtShell
= pShell
? pShell
: GetWrtShell();
1503 SwDocStyleSheet
* pStyle
= static_cast<SwDocStyleSheet
*>( m_xBasePool
->Find(
1507 // preserve the current mask of PI, then the new one is
1508 // immediately merged with the viewable area
1509 if( SfxStyleSearchBits::All
== nMask
|| SfxStyleSearchBits::Used
== nMask
)
1510 nMask
= SfxStyleSearchBits::UserDefined
;
1512 nMask
|= SfxStyleSearchBits::UserDefined
;
1514 if (nFamily
== SfxStyleFamily::Para
|| nFamily
== SfxStyleFamily::Char
|| nFamily
== SfxStyleFamily::Frame
)
1516 // Prevent undo append from being done during paragraph, character, and frame style Make. Do it later
1517 ::sw::UndoGuard
const undoGuard(GetDoc()->GetIDocumentUndoRedo());
1518 pStyle
= static_cast<SwDocStyleSheet
*>(&m_xBasePool
->Make(rName
, nFamily
, nMask
));
1522 pStyle
= static_cast<SwDocStyleSheet
*>(&m_xBasePool
->Make(rName
, nFamily
, nMask
));
1528 case SfxStyleFamily::Para
:
1530 SwTextFormatColl
* pColl
= pStyle
->GetCollection();
1531 if(pColl
&& !pColl
->IsDefault())
1533 pCurrWrtShell
->StartAllAction();
1534 pCurrWrtShell
->FillByEx(pColl
);
1535 // also apply template to remove hard set attributes
1536 SwTextFormatColl
* pDerivedFrom
= pCurrWrtShell
->GetCurTextFormatColl();
1537 pColl
->SetDerivedFrom(pDerivedFrom
);
1539 // set the mask at the Collection:
1540 sal_uInt16 nId
= pColl
->GetPoolFormatId() & 0x87ff;
1541 switch( nMask
& static_cast<SfxStyleSearchBits
>(0x0fff) )
1543 case SfxStyleSearchBits::SwText
:
1544 nId
|= COLL_TEXT_BITS
;
1546 case SfxStyleSearchBits::SwChapter
:
1547 nId
|= COLL_DOC_BITS
;
1549 case SfxStyleSearchBits::SwList
:
1550 nId
|= COLL_LISTS_BITS
;
1552 case SfxStyleSearchBits::SwIndex
:
1553 nId
|= COLL_REGISTER_BITS
;
1555 case SfxStyleSearchBits::SwExtra
:
1556 nId
|= COLL_EXTRA_BITS
;
1558 case SfxStyleSearchBits::SwHtml
:
1559 nId
|= COLL_HTML_BITS
;
1563 pColl
->SetPoolFormatId(nId
);
1565 if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1567 GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1568 std::make_unique
<SwUndoTextFormatCollCreate
>(pColl
, pDerivedFrom
, *GetDoc()));
1570 pCurrWrtShell
->SetTextFormatColl(pColl
);
1571 pCurrWrtShell
->EndAllAction();
1575 case SfxStyleFamily::Frame
:
1577 SwFrameFormat
* pFrame
= pStyle
->GetFrameFormat();
1578 if(pCurrWrtShell
->IsFrameSelected() && pFrame
&& !pFrame
->IsDefault())
1580 pCurrWrtShell
->StartAllAction();
1582 SfxItemSet
aSet(GetPool(), aFrameFormatSetRange
);
1583 pCurrWrtShell
->GetFlyFrameAttr( aSet
);
1584 aSet
.ClearItem(RES_ANCHOR
); // tdf#112574 no anchor in styles
1586 SwFrameFormat
* pFFormat
= pCurrWrtShell
->GetSelectedFrameFormat();
1587 pFrame
->SetDerivedFrom( pFFormat
);
1588 pFrame
->SetFormatAttr( aSet
);
1589 if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1591 GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1592 std::make_unique
<SwUndoFrameFormatCreate
>(pFrame
, pFFormat
, *GetDoc()));
1594 // also apply template to remove hard set attributes
1595 pCurrWrtShell
->SetFrameFormat(pFrame
);
1596 pCurrWrtShell
->EndAllAction();
1600 case SfxStyleFamily::Char
:
1602 SwCharFormat
* pChar
= pStyle
->GetCharFormat();
1603 if(pChar
&& !pChar
->IsDefault())
1605 pCurrWrtShell
->StartAllAction();
1606 pCurrWrtShell
->FillByEx( pChar
);
1607 SwCharFormat
* pDerivedFrom
= pCurrWrtShell
->GetCurCharFormat();
1608 pChar
->SetDerivedFrom( pDerivedFrom
);
1609 SwFormatCharFormat
aFormat( pChar
);
1611 if (GetDoc()->GetIDocumentUndoRedo().DoesUndo())
1613 // Looks like sometimes pDerivedFrom can be null and this is not supported by redo code
1614 // So use default format as a derived from in such situations
1615 GetDoc()->GetIDocumentUndoRedo().AppendUndo(
1616 std::make_unique
<SwUndoCharFormatCreate
>(
1617 pChar
, pDerivedFrom
? pDerivedFrom
: GetDoc()->GetDfltCharFormat(),
1620 pCurrWrtShell
->SetAttrItem(aFormat
);
1621 pCurrWrtShell
->EndAllAction();
1626 case SfxStyleFamily::Page
:
1628 pCurrWrtShell
->StartAllAction();
1629 size_t nPgDsc
= pCurrWrtShell
->GetCurPageDesc();
1630 SwPageDesc
& rSrc
= const_cast<SwPageDesc
&>(pCurrWrtShell
->GetPageDesc( nPgDsc
));
1631 SwPageDesc
& rDest
= *const_cast<SwPageDesc
*>(pStyle
->GetPageDesc());
1633 sal_uInt16 nPoolId
= rDest
.GetPoolFormatId();
1634 sal_uInt16 nHId
= rDest
.GetPoolHelpId();
1635 sal_uInt8 nHFId
= rDest
.GetPoolHlpFileId();
1637 pCurrWrtShell
->GetDoc()->CopyPageDesc( rSrc
, rDest
);
1639 // PoolId must NEVER be copied!
1640 rDest
.SetPoolFormatId( nPoolId
);
1641 rDest
.SetPoolHelpId( nHId
);
1642 rDest
.SetPoolHlpFileId( nHFId
);
1644 // when Headers/Footers are created, there is no Undo anymore!
1645 pCurrWrtShell
->GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj();
1647 pCurrWrtShell
->EndAllAction();
1651 case SfxStyleFamily::Pseudo
:
1653 const SwNumRule
* pCurRule
= pCurrWrtShell
->GetNumRuleAtCurrCursorPos();
1657 pCurrWrtShell
->StartAllAction();
1659 SwNumRule
aRule( *pCurRule
);
1660 OUString
sOrigRule( aRule
.GetName() );
1662 aRule
.SetName( pStyle
->GetNumRule()->GetName(),
1663 pCurrWrtShell
->GetDoc()->getIDocumentListsAccess() );
1664 pCurrWrtShell
->ChgNumRuleFormats( aRule
);
1666 pCurrWrtShell
->ReplaceNumRule( sOrigRule
, aRule
.GetName() );
1668 pCurrWrtShell
->EndAllAction();
1673 case SfxStyleFamily::Table
:
1675 SwTableAutoFormat
* pFormat
= pStyle
->GetTableFormat();
1676 if (pCurrWrtShell
->GetTableAutoFormat(*pFormat
))
1678 pCurrWrtShell
->StartAllAction();
1680 pCurrWrtShell
->SetTableStyle(rName
);
1682 pCurrWrtShell
->EndAllAction();
1691 sfx::AccessibilityIssueCollection
SwDocShell::runAccessibilityCheck()
1693 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
1694 sw::AccessibilityCheck
aCheck(m_xDoc
.get());
1696 return aCheck
.getIssueCollection();
1698 return sfx::AccessibilityIssueCollection();
1702 std::set
<Color
> SwDocShell::GetDocColors()
1704 return m_xDoc
->GetDocColors();
1707 std::shared_ptr
<model::ColorSet
> SwDocShell::GetThemeColors()
1709 SdrModel
* pModel
= m_xDoc
->getIDocumentDrawModelAccess().GetDrawModel();
1712 auto const& pTheme
= pModel
->getTheme();
1715 return pTheme
->getColorSet();
1718 void SwDocShell::LoadStyles( SfxObjectShell
& rSource
)
1720 LoadStyles_(rSource
, false);
1723 // bPreserveCurrentDocument determines whether SetFixFields() is called
1724 // This call modifies the source document. This mustn't happen when the source
1725 // is a document the user is working on.
1726 // Calls of ::LoadStyles() normally use files especially loaded for the purpose
1727 // of importing styles.
1728 void SwDocShell::LoadStyles_( SfxObjectShell
& rSource
, bool bPreserveCurrentDocument
)
1732 This method is called by SFx if Styles have to be reloaded from a
1733 document-template. Existing Styles should be overwritten by that.
1734 That's why the document has to be reformatted. Therefore applications
1735 will usually override this method and call the baseclass' implementation
1736 in their implementation.
1738 // When the source is our document, we do the checking ourselves
1739 // (much quicker and doesn't use the crutch StxStylePool).
1740 if( dynamic_cast<const SwDocShell
*>( &rSource
) != nullptr)
1742 // in order for the Headers/Footers not to get the fixed content
1743 // of the template, update all the Source's
1745 if(!bPreserveCurrentDocument
)
1746 static_cast<SwDocShell
&>(rSource
).m_xDoc
->getIDocumentFieldsAccess().SetFixFields(nullptr);
1749 // rhbz#818557, fdo#58893: EndAllAction will call SelectShell(),
1750 // which pushes a bunch of SfxShells that are not cleared
1751 // (for unknown reasons) when closing the document, causing crash;
1752 // setting g_bNoInterrupt appears to avoid the problem.
1753 ::comphelper::FlagRestorationGuard
g(g_bNoInterrupt
, true);
1754 m_pWrtShell
->StartAllAction();
1755 m_xDoc
->ReplaceStyles( *static_cast<SwDocShell
&>(rSource
).m_xDoc
);
1756 m_pWrtShell
->EndAllAction();
1760 bool bModified
= m_xDoc
->getIDocumentState().IsModified();
1761 m_xDoc
->ReplaceStyles( *static_cast<SwDocShell
&>(rSource
).m_xDoc
);
1762 if (!bModified
&& m_xDoc
->getIDocumentState().IsModified() && !m_pView
)
1764 // the View is created later, but overwrites the Modify-Flag.
1765 // Undo doesn't work anymore anyways.
1766 m_xDoc
->GetIDocumentUndoRedo().SetUndoNoResetModified();
1771 SfxObjectShell::LoadStyles( rSource
);
1774 void SwDocShell::FormatPage(
1775 weld::Window
* pDialogParent
,
1776 const OUString
& rPage
,
1777 const OUString
& rPageId
,
1778 SwWrtShell
& rActShell
,
1779 SfxRequest
* pRequest
)
1781 Edit(pDialogParent
, rPage
, OUString(), SfxStyleFamily::Page
, SfxStyleSearchBits::Auto
, false, rPageId
, &rActShell
, pRequest
);
1784 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */