LibreOffice Module sw (master)  1
docst.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <memory>
21 
22 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/container/XNameAccess.hpp>
25 
26 #include <comphelper/flagguard.hxx>
27 
28 #include <sal/log.hxx>
29 #include <hintids.hxx>
30 #include <sfx2/app.hxx>
31 #include <sfx2/styledlg.hxx>
32 #include <svl/whiter.hxx>
33 #include <sfx2/templdlg.hxx>
34 #include <sfx2/tplpitem.hxx>
35 #include <sfx2/request.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <sfx2/newstyle.hxx>
38 #include <sfx2/printer.hxx>
39 #include <sfx2/viewfrm.hxx>
40 #include <svl/macitem.hxx>
41 #include <svl/stritem.hxx>
42 #include <svl/languageoptions.hxx>
43 #include <editeng/eeitem.hxx>
44 #include <sfx2/htmlmode.hxx>
45 #include <swmodule.hxx>
46 #include <wdocsh.hxx>
47 #include <fmtfsize.hxx>
48 #include <fchrfmt.hxx>
49 #include <svtools/htmlcfg.hxx>
50 #include <svx/xdef.hxx>
51 #include <SwStyleNameMapper.hxx>
52 #include <SwRewriter.hxx>
53 #include <numrule.hxx>
54 #include <swundo.hxx>
55 #include <svx/svdmodel.hxx>
56 #include <svx/drawitem.hxx>
57 #include <svx/svxids.hrc>
58 #include <view.hxx>
59 #include <wrtsh.hxx>
60 #include <docsh.hxx>
61 #include <uitool.hxx>
62 #include <cmdid.h>
63 #include <globals.hrc>
64 #include <viewopt.hxx>
65 #include <doc.hxx>
66 #include <drawdoc.hxx>
68 #include <IDocumentUndoRedo.hxx>
72 #include <IDocumentListsAccess.hxx>
73 #include <IDocumentState.hxx>
74 #include <frmfmt.hxx>
75 #include <charfmt.hxx>
76 #include <poolfmt.hxx>
77 #include <pagedesc.hxx>
78 #include <docstyle.hxx>
79 #include <uiitems.hxx>
80 #include <fmtcol.hxx>
81 #include <frmmgr.hxx>
82 #include <swevent.hxx>
83 #include <edtwin.hxx>
84 #include <unochart.hxx>
85 #include <app.hrc>
86 #include <swabstdlg.hxx>
87 #include <list.hxx>
88 #include <paratr.hxx>
89 #include <tblafmt.hxx>
90 #include <sfx2/watermarkitem.hxx>
91 
92 using namespace ::com::sun::star;
93 
95 {
96  SfxWhichIter aIter(rSet);
97  sal_uInt16 nWhich = aIter.FirstWhich();
98  SfxStyleFamily nActualFamily = SfxStyleFamily(USHRT_MAX);
99 
100  SwWrtShell* pShell = pSh ? pSh : GetWrtShell();
101  if(!pShell)
102  {
103  while (nWhich)
104  {
105  rSet.DisableItem(nWhich);
106  nWhich = aIter.NextWhich();
107  }
108  return;
109  }
110  else
111  {
112  SfxViewFrame* pFrame = pShell->GetView().GetViewFrame();
113  std::unique_ptr<SfxPoolItem> pItem;
114  pFrame->GetBindings().QueryState(SID_STYLE_FAMILY, pItem);
115  SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem.get());
116  if (pFamilyItem)
117  {
118  nActualFamily = static_cast<SfxStyleFamily>(pFamilyItem->GetValue());
119  }
120  }
121 
122  while (nWhich)
123  {
124  // determine current template to every family
125  OUString aName;
126  SwTableAutoFormat aTableAutoFormat("dummy"); // needed to check if can take a table auto format at current cursor position
127  switch (nWhich)
128  {
129  case SID_STYLE_APPLY:
130  {// here the template and its family are passed to the StyleBox
131  // so that this family is being showed
132  if(pShell->IsFrameSelected())
133  {
134  SwFrameFormat* pFormat = pShell->GetSelectedFrameFormat();
135  if( pFormat )
136  aName = pFormat->GetName();
137  }
138  else
139  {
140  SwTextFormatColl* pColl = pShell->GetCurTextFormatColl();
141  if(pColl)
142  aName = pColl->GetName();
143  }
144  rSet.Put(SfxTemplateItem(nWhich, aName));
145  }
146  break;
147  case SID_STYLE_FAMILY1:
148  if( !pShell->IsFrameSelected() )
149  {
150  SwCharFormat* pFormat = pShell->GetCurCharFormat();
151  if(pFormat)
152  aName = pFormat->GetName();
153  else
156  rSet.Put(SfxTemplateItem(nWhich, aName));
157  }
158  break;
159 
160  case SID_STYLE_FAMILY2:
161  if(!pShell->IsFrameSelected())
162  {
163  SwTextFormatColl* pColl = pShell->GetCurTextFormatColl();
164  if(pColl)
165  aName = pColl->GetName();
166 
167  SfxTemplateItem aItem(nWhich, aName);
168 
169  SfxStyleSearchBits nMask = SfxStyleSearchBits::Auto;
170  if (m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE))
171  nMask = SfxStyleSearchBits::SwHtml;
172  else
173  {
174  const FrameTypeFlags nSelection = pShell->GetFrameType(nullptr,true);
175  if(pShell->GetCurTOX())
176  nMask = SfxStyleSearchBits::SwIndex ;
177  else if(nSelection & FrameTypeFlags::HEADER ||
178  nSelection & FrameTypeFlags::FOOTER ||
179  nSelection & FrameTypeFlags::TABLE ||
180  nSelection & FrameTypeFlags::FLY_ANY ||
181  nSelection & FrameTypeFlags::FOOTNOTE ||
182  nSelection & FrameTypeFlags::FTNPAGE)
183  nMask = SfxStyleSearchBits::SwExtra;
184  else
185  nMask = SfxStyleSearchBits::SwText;
186  }
187 
188  aItem.SetValue(nMask);
189  rSet.Put(aItem);
190  }
191 
192  break;
193 
194  case SID_STYLE_FAMILY3:
195 
196  if (m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE))
197  rSet.DisableItem( nWhich );
198  else
199  {
200  SwFrameFormat* pFormat = pShell->GetSelectedFrameFormat();
201  if(pFormat && pShell->IsFrameSelected())
202  {
203  aName = pFormat->GetName();
204  rSet.Put(SfxTemplateItem(nWhich, aName));
205  }
206  }
207  break;
208 
209  case SID_STYLE_FAMILY4:
210  {
211  SvxHtmlOptions& rHtmlOpt = SvxHtmlOptions::Get();
212  if (m_xDoc->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE) && !rHtmlOpt.IsPrintLayoutExtension())
213  rSet.DisableItem( nWhich );
214  else
215  {
216  size_t n = pShell->GetCurPageDesc( false );
217  if( n < pShell->GetPageDescCnt() )
218  aName = pShell->GetPageDesc( n ).GetName();
219 
220  rSet.Put(SfxTemplateItem(nWhich, aName));
221  }
222  }
223  break;
224  case SID_STYLE_FAMILY5:
225  {
226  const SwNumRule* pRule = pShell->GetNumRuleAtCurrCursorPos();
227  if( pRule )
228  aName = pRule->GetName();
229 
230  rSet.Put(SfxTemplateItem(nWhich, aName));
231  }
232  break;
233  case SID_STYLE_FAMILY6:
234  {
235  const SwTableNode *pTableNd = pShell->IsCursorInTable();
236  if( pTableNd )
237  aName = pTableNd->GetTable().GetTableStyleName();
238 
239  rSet.Put(SfxTemplateItem(nWhich, aName));
240  }
241  break;
242 
243  case SID_STYLE_WATERCAN:
244  {
245  SwEditWin& rEdtWin = pShell->GetView().GetEditWin();
246  SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
247  rSet.Put(SfxBoolItem(nWhich, pApply && pApply->eType != SfxStyleFamily(0)));
248  }
249  break;
250  case SID_STYLE_UPDATE_BY_EXAMPLE:
251  if( pShell->IsFrameSelected()
252  ? SfxStyleFamily::Frame != nActualFamily
253  : ( SfxStyleFamily::Frame == nActualFamily ||
254  SfxStyleFamily::Page == nActualFamily ||
255  (SfxStyleFamily::Pseudo == nActualFamily && !pShell->GetNumRuleAtCurrCursorPos()) ||
256  (SfxStyleFamily::Table == nActualFamily && !pShell->GetTableAutoFormat(aTableAutoFormat))) )
257  {
258  rSet.DisableItem( nWhich );
259  }
260  break;
261 
262  case SID_STYLE_NEW_BY_EXAMPLE:
263  if( (pShell->IsFrameSelected()
264  ? SfxStyleFamily::Frame != nActualFamily
265  : SfxStyleFamily::Frame == nActualFamily) ||
266  (SfxStyleFamily::Pseudo == nActualFamily && !pShell->GetNumRuleAtCurrCursorPos()) ||
267  (SfxStyleFamily::Table == nActualFamily && !pShell->GetTableAutoFormat(aTableAutoFormat)) )
268  {
269  rSet.DisableItem( nWhich );
270  }
271  break;
272 
273  case SID_CLASSIFICATION_APPLY:
274  // Just trigger ClassificationCategoriesController::statusChanged().
275  rSet.InvalidateItem(nWhich);
276  break;
277  case SID_CLASSIFICATION_DIALOG:
278  rSet.InvalidateItem(nWhich);
279  break;
280  case SID_STYLE_EDIT:
281  break;
282  case SID_WATERMARK:
283  if (pSh)
284  {
285  SfxWatermarkItem aItem = pSh->GetWatermark();
286  rSet.Put(aItem);
287  }
288  break;
289  default:
290  OSL_FAIL("Invalid SlotId");
291  }
292  nWhich = aIter.NextWhich();
293  }
294 }
295 
296 // evaluate StyleSheet-Requests
298 {
299  sal_uInt16 nSlot = rReq.GetSlot();
300 
301  const SfxItemSet* pArgs = rReq.GetArgs();
302  const SfxPoolItem* pItem;
303  switch (nSlot)
304  {
305  case SID_STYLE_NEW:
306  if( pArgs && SfxItemState::SET == pArgs->GetItemState( SID_STYLE_FAMILY,
307  false, &pItem ))
308  {
309  const SfxStyleFamily nFamily = static_cast<SfxStyleFamily>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
310 
311  OUString sName;
312  SfxStyleSearchBits nMask = SfxStyleSearchBits::Auto;
313  if( SfxItemState::SET == pArgs->GetItemState( SID_STYLE_NEW,
314  false, &pItem ))
315  sName = static_cast<const SfxStringItem*>(pItem)->GetValue();
316  if( SfxItemState::SET == pArgs->GetItemState( SID_STYLE_MASK,
317  false, &pItem ))
318  nMask = static_cast<SfxStyleSearchBits>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
319  OUString sParent;
320  if( SfxItemState::SET == pArgs->GetItemState( SID_STYLE_REFERENCE,
321  false, &pItem ))
322  sParent = static_cast<const SfxStringItem*>(pItem)->GetValue();
323 
324  if (sName.isEmpty() && m_xBasePool.get())
326 
327  Edit(sName, sParent, nFamily, nMask, true, OString(), nullptr, &rReq, nSlot);
328  }
329  break;
330 
331  case SID_STYLE_APPLY:
332  if( !pArgs )
333  {
334  GetView()->GetViewFrame()->GetDispatcher()->Execute(SID_STYLE_DESIGNER);
335  break;
336  }
337  else
338  {
339  // convert internal StyleName to DisplayName (slot implementation uses the latter)
340  const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(SID_APPLY_STYLE);
341  const SfxStringItem* pFamilyItem = rReq.GetArg<SfxStringItem>(SID_STYLE_FAMILYNAME);
342  if ( pFamilyItem && pNameItem )
343  {
344  uno::Reference< style::XStyleFamiliesSupplier > xModel(GetModel(), uno::UNO_QUERY);
345  try
346  {
347  uno::Reference< container::XNameAccess > xStyles;
348  uno::Reference< container::XNameAccess > xCont = xModel->getStyleFamilies();
349  xCont->getByName(pFamilyItem->GetValue()) >>= xStyles;
350  uno::Reference< beans::XPropertySet > xInfo;
351  xStyles->getByName( pNameItem->GetValue() ) >>= xInfo;
352  OUString aUIName;
353  xInfo->getPropertyValue("DisplayName") >>= aUIName;
354  if ( !aUIName.isEmpty() )
355  rReq.AppendItem( SfxStringItem( SID_STYLE_APPLY, aUIName ) );
356  }
357  catch (const uno::Exception&)
358  {
359  }
360  }
361  }
362 
363  [[fallthrough]];
364 
365  case SID_STYLE_EDIT:
366  case SID_STYLE_DELETE:
367  case SID_STYLE_HIDE:
368  case SID_STYLE_SHOW:
369  case SID_STYLE_WATERCAN:
370  case SID_STYLE_FAMILY:
371  case SID_STYLE_UPDATE_BY_EXAMPLE:
372  case SID_STYLE_NEW_BY_EXAMPLE:
373  {
374  OUString aParam;
375  SfxStyleFamily nFamily = SfxStyleFamily::Para;
376  SfxStyleSearchBits nMask = SfxStyleSearchBits::Auto;
377  SwWrtShell* pActShell = nullptr;
378 
379  if( !pArgs )
380  {
381  nFamily = SfxStyleFamily::Para;
382 
383  switch (nSlot)
384  {
385  case SID_STYLE_NEW_BY_EXAMPLE:
386  {
387  SfxNewStyleDlg aDlg(GetView()->GetViewFrame()->GetWindow().GetFrameWeld(), *GetStyleSheetPool());
388  if (aDlg.run() == RET_OK)
389  {
390  aParam = aDlg.GetName();
391  rReq.AppendItem(SfxStringItem(nSlot, aParam));
392  }
393  }
394  break;
395 
396  case SID_STYLE_UPDATE_BY_EXAMPLE:
397  case SID_STYLE_EDIT:
398  {
400  if(pColl)
401  {
402  aParam = pColl->GetName();
403  rReq.AppendItem(SfxStringItem(nSlot, aParam));
404  }
405  }
406  break;
407  }
408  }
409  else
410  {
411  SAL_WARN_IF( !pArgs->Count(), "sw.ui", "SfxBug ItemSet is empty" );
412 
413  SwWrtShell* pShell = GetWrtShell();
414  if( SfxItemState::SET == pArgs->GetItemState(nSlot, false, &pItem ))
415  aParam = static_cast<const SfxStringItem*>(pItem)->GetValue();
416 
417  if( SfxItemState::SET == pArgs->GetItemState(SID_STYLE_FAMILY,
418  false, &pItem ))
419  nFamily = static_cast<SfxStyleFamily>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
420 
421  if( SfxItemState::SET == pArgs->GetItemState(SID_STYLE_FAMILYNAME, false, &pItem ))
422  {
423  OUString aFamily = static_cast<const SfxStringItem*>(pItem)->GetValue();
424  if(aFamily == "CharacterStyles")
425  nFamily = SfxStyleFamily::Char;
426  else
427  if(aFamily == "ParagraphStyles")
428  nFamily = SfxStyleFamily::Para;
429  else
430  if(aFamily == "PageStyles")
431  nFamily = SfxStyleFamily::Page;
432  else
433  if(aFamily == "FrameStyles")
434  nFamily = SfxStyleFamily::Frame;
435  else
436  if(aFamily == "NumberingStyles")
437  nFamily = SfxStyleFamily::Pseudo;
438  else
439  if(aFamily == "TableStyles")
440  nFamily = SfxStyleFamily::Table;
441  }
442 
443  if( SfxItemState::SET == pArgs->GetItemState(SID_STYLE_MASK,
444  false, &pItem ))
445  nMask = static_cast<SfxStyleSearchBits>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
446  if( SfxItemState::SET == pArgs->GetItemState(FN_PARAM_WRTSHELL,
447  false, &pItem ))
448  pActShell = pShell = static_cast<SwWrtShell*>(static_cast<const SwPtrItem*>(pItem)->GetValue());
449 
450  if( nSlot == SID_STYLE_UPDATE_BY_EXAMPLE && aParam.isEmpty() )
451  {
452  switch( nFamily )
453  {
454  case SfxStyleFamily::Para:
455  {
456  SwTextFormatColl* pColl = pShell->GetCurTextFormatColl();
457  if(pColl)
458  aParam = pColl->GetName();
459  }
460  break;
461  case SfxStyleFamily::Frame:
462  {
464  if( pFrame )
465  aParam = pFrame->GetName();
466  }
467  break;
468  case SfxStyleFamily::Char:
469  {
471  if( pChar )
472  aParam = pChar->GetName();
473  }
474  break;
475  case SfxStyleFamily::Pseudo:
476  if(SfxItemState::SET == pArgs->GetItemState(SID_STYLE_UPD_BY_EX_NAME, false, &pItem))
477  {
478  aParam = static_cast<const SfxStringItem*>(pItem)->GetValue();
479  }
480  break;
481  case SfxStyleFamily::Table:
482  if(SfxItemState::SET == pArgs->GetItemState(SID_STYLE_UPD_BY_EX_NAME, false, &pItem))
483  {
484  aParam = static_cast<const SfxStringItem*>(pItem)->GetValue();
485  }
486  break;
487  default: break;
488  }
489  rReq.AppendItem(SfxStringItem(nSlot, aParam));
490  }
491  }
492  if (!aParam.isEmpty() || nSlot == SID_STYLE_WATERCAN )
493  {
494  sal_uInt16 nRet = 0xffff;
495  bool bReturns = false;
496 
497  switch(nSlot)
498  {
499  case SID_STYLE_EDIT:
500  Edit(aParam, OUString(), nFamily, nMask, false, OString(), pActShell);
501  break;
502  case SID_STYLE_DELETE:
503  Delete(aParam, nFamily);
504  break;
505  case SID_STYLE_HIDE:
506  case SID_STYLE_SHOW:
507  Hide(aParam, nFamily, nSlot == SID_STYLE_HIDE);
508  break;
509  case SID_STYLE_APPLY:
510  // Shell-switch in ApplyStyles
511  nRet = static_cast<sal_uInt16>(ApplyStyles(aParam, nFamily, pActShell, rReq.GetModifier() ));
512  bReturns = true;
513  break;
514  case SID_STYLE_WATERCAN:
515  nRet = static_cast<sal_uInt16>(DoWaterCan(aParam, nFamily));
516  bReturns = true;
517  break;
518  case SID_STYLE_UPDATE_BY_EXAMPLE:
519  UpdateStyle(aParam, nFamily, pActShell);
520  break;
521  case SID_STYLE_NEW_BY_EXAMPLE:
522  MakeByExample(aParam, nFamily, nMask, pActShell);
523  break;
524 
525  default:
526  OSL_FAIL("Invalid SlotId");
527  }
528 
529  if (bReturns)
530  {
531  if(rReq.IsAPI()) // Basic only gets TRUE or FALSE
532  rReq.SetReturnValue(SfxUInt16Item(nSlot, sal_uInt16(nRet !=0)));
533  else
534  rReq.SetReturnValue(SfxUInt16Item(nSlot, nRet));
535  }
536 
537  rReq.Done();
538  }
539 
540  break;
541  }
542  }
543 }
544 
546 {
547 public:
548  ApplyStyle(SwDocShell &rDocSh, bool bNew,
551  rtl::Reference< SfxStyleSheetBasePool > const & xBasePool,
552  bool bModified)
553  : m_pDlg(pDlg)
554  , m_rDocSh(rDocSh)
555  , m_bNew(bNew)
556  , m_xTmp(xTmp)
557  , m_nFamily(nFamily)
558  , m_xBasePool(xBasePool)
559  , m_bModified(bModified)
560  {
561  }
562  DECL_LINK( ApplyHdl, LinkParamNone*, void );
563  void apply()
564  {
565  ApplyHdl(nullptr);
566  }
568 private:
570  bool const m_bNew;
574  bool const m_bModified;
575 };
576 
578 {
579  SwWrtShell* pWrtShell = m_rDocSh.GetWrtShell();
580  SwDoc* pDoc = m_rDocSh.GetDoc();
581  SwView* pView = m_rDocSh.GetView();
582 
583  pWrtShell->StartAllAction();
584 
585  if( SfxStyleFamily::Para == m_nFamily )
586  {
587  SfxItemSet aSet( *m_pDlg->GetOutputItemSet() );
588  ::SfxToSwPageDescAttr( *pWrtShell, aSet );
589  // reset indent attributes at paragraph style, if a list style
590  // will be applied and no indent attributes will be applied.
591  m_xTmp->SetItemSet( aSet, true );
592  }
593  else
594  {
595  if(SfxStyleFamily::Page == m_nFamily)
596  {
597  static const sal_uInt16 aInval[] = {
598  SID_IMAGE_ORIENTATION,
599  SID_ATTR_CHAR_FONT,
601  pView->GetViewFrame()->GetBindings().Invalidate(aInval);
602  }
603  SfxItemSet aTmpSet( *m_pDlg->GetOutputItemSet() );
604  if( SfxStyleFamily::Char == m_nFamily )
605  {
606  ::ConvertAttrGenToChar(aTmpSet, m_xTmp->GetItemSet());
607  }
608 
609  m_xTmp->SetItemSet( aTmpSet );
610 
611  if( SfxStyleFamily::Page == m_nFamily && SvtLanguageOptions().IsCTLFontEnabled() )
612  {
613  const SfxPoolItem *pItem = nullptr;
614  if( aTmpSet.GetItemState( m_rDocSh.GetPool().GetTrueWhich( SID_ATTR_FRAMEDIRECTION, false ) , true, &pItem ) == SfxItemState::SET )
616  }
617  }
618 
619  if(m_bNew)
620  {
621  if(SfxStyleFamily::Frame == m_nFamily || SfxStyleFamily::Para == m_nFamily)
622  {
623  // clear FillStyle so that it works as a derived attribute
624  SfxItemSet aTmpSet(*m_pDlg->GetOutputItemSet());
625 
626  aTmpSet.ClearItem(XATTR_FILLSTYLE);
627  m_xTmp->SetItemSet(aTmpSet);
628  }
629  }
630 
631  if(SfxStyleFamily::Page == m_nFamily)
632  pView->InvalidateRulerPos();
633 
634  if( m_bNew )
635  m_xBasePool->Broadcast(SfxStyleSheetHint(SfxHintId::StyleSheetCreated, *m_xTmp));
636  else
637  m_xBasePool->Broadcast(SfxStyleSheetHint(SfxHintId::StyleSheetModified, *m_xTmp));
638 
639  pDoc->getIDocumentState().SetModified();
640  if( !m_bModified )
641  {
643  }
644 
645  pWrtShell->EndAllAction();
646 }
647 
649  const OUString &rName,
650  const OUString &rParent,
651  const SfxStyleFamily nFamily,
652  SfxStyleSearchBits nMask,
653  const bool bNew,
654  const OString& sPage,
655  SwWrtShell* pActShell,
656  SfxRequest* pReq,
657  sal_uInt16 nSlot)
658 {
659  assert( GetWrtShell() );
660  const bool bBasic = pReq && pReq->IsAPI();
661  SfxStyleSheetBase *pStyle = nullptr;
662 
663  bool bModified = m_xDoc->getIDocumentState().IsModified();
664 
665  SwUndoId nNewStyleUndoId(SwUndoId::EMPTY);
666 
667  if( bNew )
668  {
669  if (!bBasic)
670  {
671  // start undo action in order to get only one undo action for the
672  // UI new style + change style operations
674  }
675 
676  if( SfxStyleSearchBits::All != nMask && SfxStyleSearchBits::AllVisible != nMask && SfxStyleSearchBits::Used != nMask )
677  nMask |= SfxStyleSearchBits::UserDefined;
678  else
679  nMask = SfxStyleSearchBits::UserDefined;
680 
681  pStyle = &m_xBasePool->Make( rName, nFamily, nMask );
682 
683  // set the current one as Parent
684  SwDocStyleSheet* pDStyle = static_cast<SwDocStyleSheet*>(pStyle);
685  switch( nFamily )
686  {
687  case SfxStyleFamily::Para:
688  {
689  if(!rParent.isEmpty())
690  {
692  if(!pColl)
693  {
695  if(USHRT_MAX != nId)
696  pColl = m_pWrtShell->GetTextCollFromPool( nId );
697  }
698  pDStyle->GetCollection()->SetDerivedFrom( pColl );
699  pDStyle->PresetParent( rParent );
700 
701  /*When a new paragraph style is created based on a "to outline style
702  assigned" paragraph style, the outline level attribute and the list
703  style attribute of the new paragraph style have to be set to 0
704  respectively "".*/
705  if (pColl && pColl->IsAssignedToListLevelOfOutlineStyle())
706  {
707  SwNumRuleItem aItem;
708  pDStyle->GetCollection()->SetFormatAttr( aItem );
709  pDStyle->GetCollection()->SetAttrOutlineLevel( 0 );
710  }
711  }
712  else
713  {
715  pDStyle->GetCollection()->SetDerivedFrom( pColl );
716  if( pColl )
717  pDStyle->PresetParent( pColl->GetName() );
718  }
719  }
720  break;
721  case SfxStyleFamily::Char:
722  {
723  if(!rParent.isEmpty())
724  {
725  SwCharFormat* pCFormat = m_pWrtShell->FindCharFormatByName(rParent);
726  if(!pCFormat)
727  {
729  if(USHRT_MAX != nId)
730  pCFormat = m_pWrtShell->GetCharFormatFromPool( nId );
731  }
732 
733  pDStyle->GetCharFormat()->SetDerivedFrom( pCFormat );
734  pDStyle->PresetParent( rParent );
735  }
736  else
737  {
739  pDStyle->GetCharFormat()->SetDerivedFrom( pCFormat );
740  if( pCFormat )
741  pDStyle->PresetParent( pCFormat->GetName() );
742  }
743  }
744  break;
745  case SfxStyleFamily::Frame :
746  {
747  if(!rParent.isEmpty())
748  {
749  SwFrameFormat* pFFormat = m_pWrtShell->GetDoc()->FindFrameFormatByName( rParent );
750  if(!pFFormat)
751  {
753  if(USHRT_MAX != nId)
754  pFFormat = m_pWrtShell->GetFrameFormatFromPool( nId );
755  }
756  pDStyle->GetFrameFormat()->SetDerivedFrom( pFFormat );
757  pDStyle->PresetParent( rParent );
758  }
759  }
760  break;
761  default: break;
762  }
763 
764  if (!bBasic)
765  {
766  //Get the undo id for the type of style that was created in order to re-use that comment for the grouped
767  //create style + change style operations
768  m_pWrtShell->GetLastUndoInfo(nullptr, &nNewStyleUndoId);
769  }
770  }
771  else
772  {
773  pStyle = m_xBasePool->Find( rName, nFamily );
774  SAL_WARN_IF( !pStyle, "sw.ui", "Style not found" );
775  }
776 
777  if(!pStyle)
778  return;
779 
780  // put dialogues together
781  rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pStyle) ) );
782  if( SfxStyleFamily::Para == nFamily )
783  {
784  SfxItemSet& rSet = xTmp->GetItemSet();
785  ::SwToSfxPageDescAttr( rSet );
786  // merge list level indent attributes into the item set if needed
787  xTmp->MergeIndentAttrsOfListStyle( rSet );
788  }
789  else if( SfxStyleFamily::Char == nFamily )
790  {
791  ::ConvertAttrCharToGen(xTmp->GetItemSet());
792  }
793 
794  if(SfxStyleFamily::Page == nFamily || SfxStyleFamily::Para == nFamily)
795  {
796  // create needed items for XPropertyList entries from the DrawModel so that
797  // the Area TabPage can access them
798  SfxItemSet& rSet = xTmp->GetItemSet();
799  const SwDrawModel* pDrawModel = GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
800 
801  rSet.Put(SvxColorListItem(pDrawModel->GetColorList(), SID_COLOR_TABLE));
802  rSet.Put(SvxGradientListItem(pDrawModel->GetGradientList(), SID_GRADIENT_LIST));
803  rSet.Put(SvxHatchListItem(pDrawModel->GetHatchList(), SID_HATCH_LIST));
804  rSet.Put(SvxBitmapListItem(pDrawModel->GetBitmapList(), SID_BITMAP_LIST));
805  rSet.Put(SvxPatternListItem(pDrawModel->GetPatternList(), SID_PATTERN_LIST));
806  }
807 
808  if (!bBasic)
809  {
810  // prior to the dialog the HtmlMode at the DocShell is being sunk
811  sal_uInt16 nHtmlMode = ::GetHtmlMode(this);
812 
813  // In HTML mode, we do not always have a printer. In order to show
814  // the correct page size in the Format - Page dialog, we have to
815  // get one here.
816  SwWrtShell* pCurrShell = pActShell ? pActShell : m_pWrtShell;
817  if( ( HTMLMODE_ON & nHtmlMode ) &&
818  !pCurrShell->getIDocumentDeviceAccess().getPrinter( false ) )
819  pCurrShell->InitPrt( pCurrShell->getIDocumentDeviceAccess().getPrinter( true ) );
820 
821  PutItem(SfxUInt16Item(SID_HTML_MODE, nHtmlMode));
822  FieldUnit eMetric = ::GetDfltMetric(0 != (HTMLMODE_ON&nHtmlMode));
823  SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)));
825  VclPtr<SfxAbstractApplyTabDialog> pDlg(pFact->CreateTemplateDialog(GetView()->GetViewFrame()->GetWindow().GetFrameWeld(),
826  *xTmp, nFamily, sPage, pCurrShell, bNew));
827  std::shared_ptr<ApplyStyle> pApplyStyleHelper(new ApplyStyle(*this, bNew, xTmp, nFamily, pDlg.get(), m_xBasePool, bModified));
828  pDlg->SetApplyHdl(LINK(pApplyStyleHelper.get(), ApplyStyle, ApplyHdl));
829 
830  std::shared_ptr<SfxRequest> pRequest;
831  if (pReq)
832  {
833  pRequest.reset(new SfxRequest(*pReq));
834  pReq->Ignore(); // the 'old' request is not relevant any more
835  }
836 
837  pDlg->StartExecuteAsync([bModified, bNew, nFamily, nSlot, nNewStyleUndoId, pApplyStyleHelper, pRequest, xTmp, this](sal_Int32 nResult){
838  if (RET_OK == nResult)
839  pApplyStyleHelper->apply();
840 
841  if (bNew)
842  {
843  SwRewriter aRewriter;
844  aRewriter.AddRule(UndoArg1, xTmp->GetName());
845  //Group the create style and change style operations together under the
846  //one "create style" comment
847  m_pWrtShell->EndUndo(nNewStyleUndoId, &aRewriter);
848  }
849 
850  if (RET_OK != nResult)
851  {
852  if (bNew)
853  {
854  GetWrtShell()->Undo();
855  m_xDoc->GetIDocumentUndoRedo().ClearRedo();
856  }
857 
858  if (!bModified)
859  m_xDoc->getIDocumentState().ResetModified();
860  }
861 
862  // Update Watermark if new page style was created
863  if (nSlot == SID_STYLE_NEW && nFamily == SfxStyleFamily::Page)
864  {
865  SwWrtShell* pShell = GetWrtShell();
866  const SfxWatermarkItem aWatermark = pShell->GetWatermark();
867  pShell->SetWatermark(aWatermark);
868  }
869 
870  pApplyStyleHelper->m_pDlg.disposeAndClear();
871  if (pRequest)
872  pRequest->Done();
873  });
874  }
875  else
876  {
877  // prior to the dialog the HtmlMode at the DocShell is being sunk
878  PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(this)));
879 
881 
882  if( SfxStyleFamily::Para == nFamily )
883  ::SfxToSwPageDescAttr( *GetWrtShell(), xTmp->GetItemSet() );
884  else
885  {
886  ::ConvertAttrGenToChar(xTmp->GetItemSet(), xTmp->GetItemSet());
887  }
888  if(SfxStyleFamily::Page == nFamily)
890 
891  if( bNew )
892  m_xBasePool->Broadcast(SfxStyleSheetHint(SfxHintId::StyleSheetCreated, *xTmp));
893 
894  m_xDoc->getIDocumentState().SetModified();
895  if( !bModified ) // Bug 57028
896  {
897  m_xDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
898  }
900  }
901 }
902 
903 void SwDocShell::Delete(const OUString &rName, SfxStyleFamily nFamily)
904 {
905  SfxStyleSheetBase *pStyle = m_xBasePool->Find(rName, nFamily);
906 
907  if(pStyle)
908  {
909  assert( GetWrtShell() );
910 
912  m_xBasePool->Remove(pStyle);
914  }
915 }
916 
917 void SwDocShell::Hide(const OUString &rName, SfxStyleFamily nFamily, bool bHidden)
918 {
919  SfxStyleSheetBase *pStyle = m_xBasePool->Find(rName, nFamily);
920 
921  if(pStyle)
922  {
923  assert( GetWrtShell() );
924 
926  rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pStyle) ) );
927  xTmp->SetHidden( bHidden );
929  }
930 }
931 
932 // apply template
934  SwWrtShell* pShell, const sal_uInt16 nMode )
935 {
936  SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>( m_xBasePool->Find( rName, nFamily ) );
937 
938  SAL_WARN_IF( !pStyle, "sw.ui", "Style not found" );
939 
940  if(!pStyle)
941  return SfxStyleFamily::None;
942 
943  SwWrtShell *pSh = pShell ? pShell : GetWrtShell();
944 
945  assert( pSh );
946 
947  pSh->StartAllAction();
948 
949  switch (nFamily)
950  {
951  case SfxStyleFamily::Char:
952  {
953  SwFormatCharFormat aFormat(pStyle->GetCharFormat());
954  pSh->SetAttrItem( aFormat, (nMode & KEY_SHIFT) ?
956  break;
957  }
958  case SfxStyleFamily::Para:
959  {
960  // #i62675#
961  // clear also list attributes at affected text nodes, if paragraph
962  // style has the list style attribute set.
963  pSh->SetTextFormatColl( pStyle->GetCollection(), true );
964  break;
965  }
966  case SfxStyleFamily::Frame:
967  {
968  if ( pSh->IsFrameSelected() )
969  pSh->SetFrameFormat( pStyle->GetFrameFormat() );
970  break;
971  }
972  case SfxStyleFamily::Page:
973  {
974  pSh->SetPageStyle(pStyle->GetPageDesc()->GetName());
975  break;
976  }
977  case SfxStyleFamily::Pseudo:
978  {
979  // reset indent attribute on applying list style
980  // continue list of list style
981  const SwNumRule* pNumRule = pStyle->GetNumRule();
982  const OUString sListIdForStyle =pNumRule->GetDefaultListId();
983  pSh->SetCurNumRule( *pNumRule, false, sListIdForStyle, true );
984  break;
985  }
986  case SfxStyleFamily::Table:
987  {
988  pSh->SetTableStyle(pStyle->GetName());
989  break;
990  }
991  default:
992  OSL_FAIL("Unknown family");
993  }
994  pSh->EndAllAction();
995 
996  return nFamily;
997 }
998 
999 // start watering-can
1001 {
1002  assert( GetWrtShell() );
1003 
1004  SwEditWin& rEdtWin = m_pView->GetEditWin();
1005  SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
1006  bool bWaterCan = !(pApply && pApply->eType != SfxStyleFamily(0));
1007 
1008  if( rName.isEmpty() )
1009  bWaterCan = false;
1010 
1011  SwApplyTemplate aTemplate;
1012  aTemplate.eType = nFamily;
1013 
1014  if(bWaterCan)
1015  {
1016  SwDocStyleSheet* pStyle =
1017  static_cast<SwDocStyleSheet*>( m_xBasePool->Find(rName, nFamily) );
1018 
1019  SAL_WARN_IF( !pStyle, "sw.ui", "Where's the StyleSheet" );
1020 
1021  if(!pStyle) return nFamily;
1022 
1023  switch(nFamily)
1024  {
1025  case SfxStyleFamily::Char:
1026  aTemplate.aColl.pCharFormat = pStyle->GetCharFormat();
1027  break;
1028  case SfxStyleFamily::Para:
1029  aTemplate.aColl.pTextColl = pStyle->GetCollection();
1030  break;
1031  case SfxStyleFamily::Frame:
1032  aTemplate.aColl.pFrameFormat = pStyle->GetFrameFormat();
1033  break;
1034  case SfxStyleFamily::Page:
1035  aTemplate.aColl.pPageDesc = const_cast<SwPageDesc*>(pStyle->GetPageDesc());
1036  break;
1037  case SfxStyleFamily::Pseudo:
1038  aTemplate.aColl.pNumRule = const_cast<SwNumRule*>(pStyle->GetNumRule());
1039  break;
1040 
1041  default:
1042  OSL_FAIL("Unknown family");
1043  }
1044  }
1045  else
1046  aTemplate.eType = SfxStyleFamily(0);
1047 
1048  m_pView->GetEditWin().SetApplyTemplate(aTemplate);
1049 
1050  return nFamily;
1051 }
1052 
1053 // update template
1054 void SwDocShell::UpdateStyle(const OUString &rName, SfxStyleFamily nFamily, SwWrtShell* pShell)
1055 {
1056  SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell();
1057  assert( pCurrWrtShell );
1058 
1059  SwDocStyleSheet* pStyle =
1060  static_cast<SwDocStyleSheet*>( m_xBasePool->Find(rName, nFamily) );
1061 
1062  if (!pStyle)
1063  return;
1064 
1065  switch(nFamily)
1066  {
1067  case SfxStyleFamily::Para:
1068  {
1069  SwTextFormatColl* pColl = pStyle->GetCollection();
1070  if(pColl && !pColl->IsDefault())
1071  {
1073 
1074  SwRewriter aRewriter;
1075  aRewriter.AddRule(UndoArg1, pColl->GetName());
1076 
1077  GetWrtShell()->StartUndo(SwUndoId::INSFMTATTR, &aRewriter);
1078  GetWrtShell()->FillByEx(pColl);
1079  // also apply template to remove hard set attributes
1080  GetWrtShell()->SetTextFormatColl( pColl );
1081  GetWrtShell()->EndUndo();
1083  }
1084  break;
1085  }
1086  case SfxStyleFamily::Frame:
1087  {
1088  SwFrameFormat* pFrame = pStyle->GetFrameFormat();
1089  if( pCurrWrtShell->IsFrameSelected() && pFrame && !pFrame->IsDefault() )
1090  {
1092  pCurrWrtShell->StartAllAction();
1093  pCurrWrtShell->GetFlyFrameAttr( aSet );
1094 
1095  // #i105535#
1096  // no update of anchor attribute
1097  aSet.ClearItem( RES_ANCHOR );
1098 
1099  pFrame->SetFormatAttr( aSet );
1100 
1101  // also apply template to remove hard set attributes
1102  pCurrWrtShell->SetFrameFormat( pFrame, true );
1103  pCurrWrtShell->EndAllAction();
1104  }
1105  }
1106  break;
1107  case SfxStyleFamily::Char:
1108  {
1109  SwCharFormat* pChar = pStyle->GetCharFormat();
1110  if( pChar && !pChar->IsDefault() )
1111  {
1112  pCurrWrtShell->StartAllAction();
1113  pCurrWrtShell->FillByEx(pChar);
1114  // also apply template to remove hard set attributes
1115  pCurrWrtShell->EndAllAction();
1116  }
1117 
1118  }
1119  break;
1120  case SfxStyleFamily::Pseudo:
1121  {
1122  const SwNumRule* pCurRule;
1123  if( pStyle->GetNumRule() &&
1124  nullptr != ( pCurRule = pCurrWrtShell->GetNumRuleAtCurrCursorPos() ))
1125  {
1126  SwNumRule aRule( *pCurRule );
1127  // #i91400#
1128  aRule.SetName( pStyle->GetNumRule()->GetName(),
1129  pCurrWrtShell->GetDoc()->getIDocumentListsAccess() );
1130  pCurrWrtShell->ChgNumRuleFormats( aRule );
1131  }
1132  }
1133  break;
1134  case SfxStyleFamily::Table:
1135  {
1136 
1137  SwTableAutoFormat aFormat(rName);
1138  if (pCurrWrtShell->GetTableAutoFormat(aFormat))
1139  {
1140  pCurrWrtShell->StartAllAction();
1141  pCurrWrtShell->GetDoc()->ChgTableStyle(rName, aFormat);
1142  pCurrWrtShell->EndAllAction();
1143  }
1144 
1145  }
1146  break;
1147  default: break;
1148  }
1149 }
1150 
1151 // NewByExample
1152 void SwDocShell::MakeByExample( const OUString &rName, SfxStyleFamily nFamily,
1153  SfxStyleSearchBits nMask, SwWrtShell* pShell )
1154 {
1155  SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell();
1156  SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>( m_xBasePool->Find(
1157  rName, nFamily ) );
1158  if(!pStyle)
1159  {
1160  // preserve the current mask of PI, then the new one is
1161  // immediately merged with the viewable area
1162  if( SfxStyleSearchBits::All == nMask || SfxStyleSearchBits::Used == nMask )
1163  nMask = SfxStyleSearchBits::UserDefined;
1164  else
1165  nMask |= SfxStyleSearchBits::UserDefined;
1166 
1167  pStyle = static_cast<SwDocStyleSheet*>( &m_xBasePool->Make(rName,
1168  nFamily, nMask ) );
1169  }
1170 
1171  switch(nFamily)
1172  {
1173  case SfxStyleFamily::Para:
1174  {
1175  SwTextFormatColl* pColl = pStyle->GetCollection();
1176  if(pColl && !pColl->IsDefault())
1177  {
1178  pCurrWrtShell->StartAllAction();
1179  pCurrWrtShell->FillByEx(pColl);
1180  // also apply template to remove hard set attributes
1181  pColl->SetDerivedFrom(pCurrWrtShell->GetCurTextFormatColl());
1182 
1183  // set the mask at the Collection:
1184  sal_uInt16 nId = pColl->GetPoolFormatId() & 0x87ff;
1185  switch( nMask & static_cast<SfxStyleSearchBits>(0x0fff) )
1186  {
1187  case SfxStyleSearchBits::SwText:
1188  nId |= COLL_TEXT_BITS;
1189  break;
1190  case SfxStyleSearchBits::SwChapter:
1191  nId |= COLL_DOC_BITS;
1192  break;
1193  case SfxStyleSearchBits::SwList:
1194  nId |= COLL_LISTS_BITS;
1195  break;
1196  case SfxStyleSearchBits::SwIndex:
1197  nId |= COLL_REGISTER_BITS;
1198  break;
1199  case SfxStyleSearchBits::SwExtra:
1200  nId |= COLL_EXTRA_BITS;
1201  break;
1202  case SfxStyleSearchBits::SwHtml:
1203  nId |= COLL_HTML_BITS;
1204  break;
1205  default: break;
1206  }
1207  pColl->SetPoolFormatId(nId);
1208 
1209  pCurrWrtShell->SetTextFormatColl(pColl);
1210  pCurrWrtShell->EndAllAction();
1211  }
1212  }
1213  break;
1214  case SfxStyleFamily::Frame:
1215  {
1216  SwFrameFormat* pFrame = pStyle->GetFrameFormat();
1217  if(pCurrWrtShell->IsFrameSelected() && pFrame && !pFrame->IsDefault())
1218  {
1219  pCurrWrtShell->StartAllAction();
1220 
1222  pCurrWrtShell->GetFlyFrameAttr( aSet );
1223  aSet.ClearItem(RES_ANCHOR); // tdf#112574 no anchor in styles
1224 
1225  SwFrameFormat* pFFormat = pCurrWrtShell->GetSelectedFrameFormat();
1226  pFrame->SetDerivedFrom( pFFormat );
1227 
1228  pFrame->SetFormatAttr( aSet );
1229  // also apply template to remove hard set attributes
1230  pCurrWrtShell->SetFrameFormat( pFrame );
1231  pCurrWrtShell->EndAllAction();
1232  }
1233  }
1234  break;
1235  case SfxStyleFamily::Char:
1236  {
1237  SwCharFormat* pChar = pStyle->GetCharFormat();
1238  if(pChar && !pChar->IsDefault())
1239  {
1240  pCurrWrtShell->StartAllAction();
1241  pCurrWrtShell->FillByEx( pChar );
1242  pChar->SetDerivedFrom( pCurrWrtShell->GetCurCharFormat() );
1243  SwFormatCharFormat aFormat( pChar );
1244  pCurrWrtShell->SetAttrItem( aFormat );
1245  pCurrWrtShell->EndAllAction();
1246  }
1247  }
1248  break;
1249 
1250  case SfxStyleFamily::Page:
1251  {
1252  pCurrWrtShell->StartAllAction();
1253  size_t nPgDsc = pCurrWrtShell->GetCurPageDesc();
1254  SwPageDesc& rSrc = const_cast<SwPageDesc&>(pCurrWrtShell->GetPageDesc( nPgDsc ));
1255  SwPageDesc& rDest = *const_cast<SwPageDesc*>(pStyle->GetPageDesc());
1256 
1257  sal_uInt16 nPoolId = rDest.GetPoolFormatId();
1258  sal_uInt16 nHId = rDest.GetPoolHelpId();
1259  sal_uInt8 nHFId = rDest.GetPoolHlpFileId();
1260 
1261  pCurrWrtShell->GetDoc()->CopyPageDesc( rSrc, rDest );
1262 
1263  // PoolId must NEVER be copied!
1264  rDest.SetPoolFormatId( nPoolId );
1265  rDest.SetPoolHelpId( nHId );
1266  rDest.SetPoolHlpFileId( nHFId );
1267 
1268  // when Headers/Footers are created, there is no Undo anymore!
1269  pCurrWrtShell->GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj();
1270 
1271  pCurrWrtShell->EndAllAction();
1272  }
1273  break;
1274 
1275  case SfxStyleFamily::Pseudo:
1276  {
1277  const SwNumRule* pCurRule = pCurrWrtShell->GetNumRuleAtCurrCursorPos();
1278 
1279  if (pCurRule)
1280  {
1281  pCurrWrtShell->StartAllAction();
1282 
1283  SwNumRule aRule( *pCurRule );
1284  OUString sOrigRule( aRule.GetName() );
1285  // #i91400#
1286  aRule.SetName( pStyle->GetNumRule()->GetName(),
1287  pCurrWrtShell->GetDoc()->getIDocumentListsAccess() );
1288  pCurrWrtShell->ChgNumRuleFormats( aRule );
1289 
1290  pCurrWrtShell->ReplaceNumRule( sOrigRule, aRule.GetName() );
1291 
1292  pCurrWrtShell->EndAllAction();
1293  }
1294  }
1295  break;
1296 
1297  case SfxStyleFamily::Table:
1298  {
1299  SwTableAutoFormat* pFormat = pStyle->GetTableFormat();
1300  if (pCurrWrtShell->GetTableAutoFormat(*pFormat))
1301  {
1302  pCurrWrtShell->StartAllAction();
1303 
1304  pCurrWrtShell->SetTableStyle(rName);
1305 
1306  pCurrWrtShell->EndAllAction();
1307  }
1308  }
1309  break;
1310 
1311  default: break;
1312  }
1313 }
1314 
1315 std::set<Color> SwDocShell::GetDocColors()
1316 {
1317  return m_xDoc->GetDocColors();
1318 }
1319 
1321 {
1322  LoadStyles_(rSource, false);
1323 }
1324 
1325 // bPreserveCurrentDocument determines whether SetFixFields() is called
1326 // This call modifies the source document. This mustn't happen when the source
1327 // is a document the user is working on.
1328 // Calls of ::LoadStyles() normally use files especially loaded for the purpose
1329 // of importing styles.
1330 void SwDocShell::LoadStyles_( SfxObjectShell& rSource, bool bPreserveCurrentDocument )
1331 {
1332 /* [Description]
1333 
1334  This method is called by SFx if Styles have to be reloaded from a
1335  document-template. Existing Styles should be overwritten by that.
1336  That's why the document has to be reformatted. Therefore applications
1337  will usually override this method and call the baseclass' implementation
1338  in their implementation.
1339 */
1340  // When the source is our document, we do the checking ourselves
1341  // (much quicker and doesn't use the crutch StxStylePool).
1342  if( dynamic_cast<const SwDocShell*>( &rSource) != nullptr)
1343  {
1344  // in order for the Headers/Footers not to get the fixed content
1345  // of the template, update all the Source's
1346  // FixFields once.
1347  if(!bPreserveCurrentDocument)
1348  static_cast<SwDocShell&>(rSource).m_xDoc->getIDocumentFieldsAccess().SetFixFields(nullptr);
1349  if (m_pWrtShell)
1350  {
1351  // rhbz#818557, fdo#58893: EndAllAction will call SelectShell(),
1352  // which pushes a bunch of SfxShells that are not cleared
1353  // (for unknown reasons) when closing the document, causing crash;
1354  // setting g_bNoInterrupt appears to avoid the problem.
1357  m_xDoc->ReplaceStyles( *static_cast<SwDocShell&>(rSource).m_xDoc );
1359  }
1360  else
1361  {
1362  bool bModified = m_xDoc->getIDocumentState().IsModified();
1363  m_xDoc->ReplaceStyles( *static_cast<SwDocShell&>(rSource).m_xDoc );
1364  if (!bModified && m_xDoc->getIDocumentState().IsModified() && !m_pView)
1365  {
1366  // the View is created later, but overwrites the Modify-Flag.
1367  // Undo doesn't work anymore anyways.
1368  m_xDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
1369  }
1370  }
1371  }
1372  else
1373  SfxObjectShell::LoadStyles( rSource );
1374 }
1375 
1377  const OUString& rPage,
1378  const OString& rPageId,
1379  SwWrtShell& rActShell,
1380  SfxRequest* pRequest)
1381 {
1382  Edit(rPage, OUString(), SfxStyleFamily::Page, SfxStyleSearchBits::Auto, false, rPageId, &rActShell, pRequest);
1383 }
1384 
1385 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
const sal_Char * pChar
bool IsPrintLayoutExtension() const
FieldUnit
SwTextFormatColl * GetCurTextFormatColl() const
Get the named paragraph format of the current selection.
Definition: edattr.cxx:250
const sal_uInt16 COLL_LISTS_BITS
Definition: poolfmt.hxx:67
const sal_uInt16 COLL_DOC_BITS
Definition: poolfmt.hxx:70
static OUString GenerateUnusedName(SfxStyleSheetBasePool &rPool)
IMPL_LINK_NOARG(ApplyStyle, ApplyHdl, LinkParamNone *, void)
Definition: docst.cxx:577
Represents the style of a paragraph.
Definition: fmtcol.hxx:55
SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId)
Definition: edfmt.cxx:125
void SwToSfxPageDescAttr(SfxItemSet &rSet)
Definition: uitool.cxx:652
bool IsDefault() const
Definition: format.hxx:109
SwTableAutoFormat * GetTableFormat()
Definition: docstyle.cxx:2186
SfxStyleFamily eType
Definition: view.hxx:118
SW_DLLPUBLIC void ConvertAttrCharToGen(SfxItemSet &rSet)
Convert character specific attributes to general ones used by tab pages.
Definition: uitool.cxx:128
SwUndoId
Definition: swundo.hxx:29
void SetPoolHelpId(sal_uInt16 const nId)
Definition: pagedesc.hxx:256
std::string GetValue
const SwNumRule * GetNumRuleAtCurrCursorPos() const
Definition: ednumber.cxx:727
SwCharFormat * GetCharFormatFromPool(sal_uInt16 nId)
Definition: editsh.hxx:358
SfxDispatcher * GetDispatcher()
virtual void SetModified()=0
Must be called manually at changes of format.
bool GetLastUndoInfo(OUString *const o_pStr, SwUndoId *const o_pId, const SwView *pView=nullptr) const
Definition: edws.cxx:236
#define KEY_SHIFT
const OUString & GetDefaultListId() const
Definition: numrule.hxx:192
const sal_uInt16 COLL_HTML_BITS
Definition: poolfmt.hxx:71
Definition: doc.hxx:185
SAL_DLLPRIVATE void UpdateStyle(const OUString &rName, SfxStyleFamily nFamily, SwWrtShell *pShell)
Definition: docst.cxx:1054
sal_uInt16 GetValue() const
void InvalidateItem(sal_uInt16 nWhich)
sal_Int16 nId
sal_uInt16 FirstWhich()
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:233
rtl::Reference< SfxStyleSheetBasePool > m_xBasePool
Definition: docst.cxx:573
const OUString & GetName() const
Definition: numrule.hxx:222
SwEditWin & GetEditWin()
Definition: view.hxx:403
void Done(bool bRemove=false)
void SetPageStyle(const OUString &rCollName)
Definition: wrtsh1.cxx:1526
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:176
css::uno::Reference< css::frame::XModel > GetModel() const
const SfxItemSet * GetArgs() const
void Invalidate(sal_uInt16 nId)
void SfxToSwPageDescAttr(const SwWrtShell &rShell, SfxItemSet &rSet)
Definition: uitool.cxx:592
virtual bool SetFormatAttr(const SfxPoolItem &rAttr) override
Override to recognize changes on the and register/unregister the paragragh style at t...
Definition: fmtcol.cxx:330
SwFrameFormat * GetFrameFormatFromPool(sal_uInt16 nId)
Definition: editsh.hxx:356
void PutItem(const SfxPoolItem &rItem)
void SetValue(SfxStyleSearchBits n)
void EndAllAction()
Definition: edws.cxx:96
void SetApplyTemplate(const SwApplyTemplate &)
Apply template.
Definition: edtwin.cxx:4926
SwPageDesc * pPageDesc
Definition: view.hxx:112
sal_uInt16 NextWhich()
XPatternListRef GetPatternList() const
const OUString & GetName() const
Definition: pagedesc.hxx:186
IDocumentDrawModelAccess const & getIDocumentDrawModelAccess() const
Definition: doc.cxx:187
void SetCurNumRule(const SwNumRule &, const bool bCreateNewList, const OUString &sContinuedListId=OUString(), const bool bResetIndentAttrs=false)
Optional parameter (default value false).
Definition: ednumber.cxx:771
Used by the UI to modify the document model.
Definition: wrtsh.hxx:88
void SetWatermark(const SfxWatermarkItem &rText)
Definition: edfcol.cxx:1610
SfxWatermarkItem GetWatermark()
Definition: edfcol.cxx:1385
void FillByEx(SwCharFormat *)
Definition: edfmt.cxx:55
bool IsAssignedToListLevelOfOutlineStyle() const
Definition: fmtcol.hxx:109
const SwView & GetView() const
Definition: wrtsh.hxx:426
const OUString & GetName() const
ApplyStyle(SwDocShell &rDocSh, bool bNew, rtl::Reference< SwDocStyleSheet > const &xTmp, SfxStyleFamily nFamily, SfxAbstractApplyTabDialog *pDlg, rtl::Reference< SfxStyleSheetBasePool > const &xBasePool, bool bModified)
Definition: docst.cxx:548
void SetPoolFormatId(sal_uInt16 nId)
Definition: format.hxx:144
sal_uInt16 GetPoolFormatId() const
Query and set PoolFormat-Id.
Definition: pagedesc.hxx:253
void ExecStyleSheet(SfxRequest &)
Definition: docst.cxx:297
SAL_DLLPRIVATE void Edit(const OUString &rName, const OUString &rParent, const SfxStyleFamily nFamily, SfxStyleSearchBits nMask, const bool bNew, const OString &sPageId, SwWrtShell *pActShell, SfxRequest *pRequest=nullptr, sal_uInt16 nSlot=0)
Methods for StyleSheets.
Definition: docst.cxx:648
bool SetTableStyle(const OUString &rStyleName)
Set table style of the current table.
Definition: fetab.cxx:1180
const OUString & GetName() const
Definition: format.hxx:111
virtual void DelAllUndoObj()=0
Delete all Undo actions.
void InitPrt(OutputDevice *pOutDev)
Definition: vprint.cxx:196
SwFrameFormat * GetFrameFormat()
Definition: docstyle.cxx:2225
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
OUString GetName() const
const SwTable & GetTable() const
Definition: node.hxx:497
void SetPoolHlpFileId(sal_uInt8 const nId)
Definition: pagedesc.hxx:258
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
const SwPageDesc * GetPageDesc()
Definition: docstyle.cxx:2165
const OUString & GetTableStyleName() const
Return the table style name of this table.
Definition: swtable.hxx:188
SfxStyleFamily
const SwTOXBase * GetCurTOX() const
Get current listing before or at the Cursor.
Definition: edtox.cxx:195
virtual void LoadStyles(SfxObjectShell &rSource) override
Definition: docst.cxx:1320
const sal_uInt16 COLL_REGISTER_BITS
Definition: poolfmt.hxx:69
SwCharFormat * GetCharFormat()
Definition: docstyle.cxx:2151
bool SetDerivedFrom(SwFormat *pDerivedFrom=nullptr)
0 is Default.
Definition: format.cxx:328
void PresetParent(const OUString &rName)
Definition: docstyle.hxx:119
sal_uInt16 GetPoolFormatId() const
Get and set Pool style IDs.
Definition: format.hxx:143
SfxItemPool & GetPool() const
bool const m_bModified
Definition: docst.cxx:574
SwFrameFormat * FindFrameFormatByName(const OUString &rName) const
Definition: doc.hxx:759
static SvxHtmlOptions & Get()
void ChgNumRuleFormats(const SwNumRule &rRule)
Definition: ednumber.cxx:821
bool GetFlyFrameAttr(SfxItemSet &rSet) const
Definition: fefly1.cxx:1023
SwDocShell & m_rDocSh
Definition: docst.cxx:569
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:203
const IDocumentDeviceAccess & getIDocumentDeviceAccess() const
Provides access to the document device interface.
Definition: viewsh.cxx:2590
const SwTableNode * IsCursorInTable() const
Definition: crsrsh.hxx:887
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
void SetTextFormatColl(SwTextFormatColl *, const bool bResetListAttrs=false)
Add 2nd optional parameter - see also
Definition: edfcol.cxx:2190
Style of a layout element.
Definition: frmfmt.hxx:57
DECL_LINK(ApplyHdl, LinkParamNone *, void)
SwApplyTemplate * GetApplyTemplate() const
Definition: edtwin.hxx:228
#define SW_MOD()
Definition: swmodule.hxx:255
SwCharFormat * FindCharFormatByName(const OUString &rName) const
Definition: edfmt.cxx:151
#define RES_ANCHOR
Definition: hintids.hxx:209
#define FN_INSERT_CTRL
Definition: cmdid.h:244
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:691
SwTextFormatColl * pTextColl
Definition: view.hxx:111
SwNumRule * pNumRule
Definition: view.hxx:115
virtual void SetUndoNoResetModified()=0
Disable (re)setting the document modified flag on Undo/Redo.
sal_uInt16 GetModifier() const
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:58
void LoadStyles_(SfxObjectShell &rSource, bool bPreserveCurrentDocument)
Definition: docst.cxx:1330
virtual std::set< Color > GetDocColors() override
Definition: docst.cxx:1315
OUString sName
SfxBindings & GetBindings()
#define FN_PARAM_WRTSHELL
Definition: cmdid.h:769
bool const m_bNew
Definition: docst.cxx:570
void SetAttrItem(const SfxPoolItem &, SetAttrMode nFlags=SetAttrMode::DEFAULT, const bool bParagraphSetting=false)
Definition: edatmisc.cxx:113
const OUString & GetValue() const
sal_uInt16 Count() const
const SwPageDesc & GetPageDesc(size_t i) const
Definition: fedesc.cxx:127
HTMLMODE_ON
FrameTypeFlags
values can be combined via logical or
Definition: fesh.hxx:62
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:339
const T * GetArg(sal_uInt16 nSlotId) const
void ChgTableStyle(const OUString &rName, const SwTableAutoFormat &rNewFormat)
Definition: ndtbl.cxx:4587
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
Definition: edws.cxx:222
virtual SfxStyleSheetBasePool * GetStyleSheetPool() override
For Style PI.
Definition: docsh.cxx:1159
XGradientListRef GetGradientList() const
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:29
weld::Window * GetFrameWeld(SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:426
SwWrtShell * GetWrtShell()
Access to the SwWrtShell belonging to SwView.
Definition: docsh.hxx:224
SwFrameFormat * pFrameFormat
Definition: view.hxx:113
const SwNumRule * GetNumRule()
Definition: docstyle.cxx:2172
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
SfxItemState QueryState(sal_uInt16 nSID, std::unique_ptr< SfxPoolItem > &rpState)
rtl::Reference< SwDoc > m_xDoc
Document.
Definition: docsh.hxx:71
void SetPoolFormatId(sal_uInt16 const nId)
Definition: pagedesc.hxx:254
#define XATTR_FILLSTYLE
virtual SfxPrinter * getPrinter(bool bCreate) const =0
Return the printer set at the document.
rtl::Reference< SwDocStyleSheet > m_xTmp
Definition: docst.cxx:571
virtual void LoadStyles(SfxObjectShell &rSource)
SwFrameFormat * GetSelectedFrameFormat() const
If frame then frame style, else 0.
Definition: fefly1.cxx:1178
rtl::Reference< SfxStyleSheetBasePool > m_xBasePool
Passing through for formats.
Definition: docsh.hxx:72
sal_uInt16 const aFrameFormatSetRange[]
Definition: init.cxx:240
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:460
void SetReturnValue(const SfxPoolItem &)
SwCharFormat * pCharFormat
Definition: view.hxx:114
SAL_DLLPRIVATE void MakeByExample(const OUString &rName, SfxStyleFamily nFamily, SfxStyleSearchBits nMask, SwWrtShell *pShell)
Definition: docst.cxx:1152
SAL_DLLPRIVATE void Hide(const OUString &rName, SfxStyleFamily nFamily, bool bHidden)
Definition: docst.cxx:917
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
void CopyPageDesc(const SwPageDesc &rSrcDesc, SwPageDesc &rDstDesc, bool bCopyPoolIds=true)
Copy the complete PageDesc - beyond document and "deep"! Optionally copying of PoolFormatId, -HlpId can be prevented.
Definition: docfmt.cxx:1427
XHatchListRef GetHatchList() const
SwTextFormatColl * GetCollection()
Definition: docstyle.cxx:2158
void DisableItem(sal_uInt16 nWhich)
SwView * m_pView
For "historical reasons" nothing can be done without the WrtShell.
Definition: docsh.hxx:83
void ReplaceNumRule(const OUString &rOldRule, const OUString &rNewRule)
Definition: ednumber.cxx:828
#define SAL_WARN_IF(condition, area, stream)
unsigned char sal_uInt8
union SwApplyTemplate::@33 aColl
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:261
SwTextFormatColl * FindTextFormatCollByName(const OUString &rName) const
Definition: edfmt.cxx:156
RET_OK
SwWrtShell * m_pWrtShell
Definition: docsh.hxx:84
sal_uInt16 GetPoolHelpId() const
Definition: pagedesc.hxx:255
void SetAttrOutlineLevel(int)
Definition: fmtcol.cxx:576
void InvalidateRulerPos()
Definition: viewport.cxx:118
void SetFrameFormat(SwFrameFormat *pFormat, bool bKeepOrient=false, Point const *pDocPos=nullptr)
If frame then set frame style.
Definition: fefly1.cxx:1188
XBitmapListRef GetBitmapList() const
OString const aName
sal_uInt8 GetPoolHlpFileId() const
Definition: pagedesc.hxx:257
reference_type * get() const
SAL_DLLPRIVATE SfxStyleFamily ApplyStyles(const OUString &rName, const SfxStyleFamily nFamily, SwWrtShell *pShell, sal_uInt16 nMode)
Definition: docst.cxx:933
SwCharFormat * GetCurCharFormat() const
Definition: edfmt.cxx:42
bool g_bNoInterrupt
Definition: swmodule.cxx:138
void AppendItem(const SfxPoolItem &)
Reference< XModel > xModel
SAL_DLLPRIVATE SfxStyleFamily DoWaterCan(const OUString &rName, SfxStyleFamily nFamily)
Definition: docst.cxx:1000
bool IsAPI() const
const SwView * GetView() const
Definition: docsh.hxx:220
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
#define FN_INSERT_OBJ_CTRL
Definition: cmdid.h:245
const sal_uInt16 COLL_TEXT_BITS
Definition: poolfmt.hxx:66
XColorListRef GetColorList() const
void FormatPage(const OUString &rPage, const OString &rPageId, SwWrtShell &rActShell, SfxRequest *pRequest=nullptr)
Show page style format dialog.
Definition: docst.cxx:1376
void SetName(const OUString &rNm, IDocumentListsAccess &rDocListAccess)
Definition: number.cxx:107
void apply()
Definition: docst.cxx:563
void StartAllAction()
For all views of this document.
Definition: edws.cxx:85
SAL_DLLPRIVATE void Delete(const OUString &rName, SfxStyleFamily nFamily)
Definition: docst.cxx:903
IDocumentListsAccess const & getIDocumentListsAccess() const
Definition: doc.cxx:325
void Ignore()
size_t GetCurPageDesc(const bool bCalcFrame=true) const
Definition: fedesc.cxx:168
static const std::vector< OUString > & GetTextUINameArray()
void StateStyleSheet(SfxItemSet &, SwWrtShell *pSh=nullptr)
Definition: docst.cxx:94
SW_DLLPUBLIC void ConvertAttrGenToChar(SfxItemSet &rSet, const SfxItemSet &rOrigSet)
Convert general attributes to the corresponding character attributes.
Definition: uitool.cxx:156
void Undo(sal_uInt16 const nCount=1)
Definition: edundo.cxx:101
FrameTypeFlags GetFrameType(const Point *pPt, bool bStopAtFly) const
For return values see above FrameType.
Definition: fews.cxx:238
bool IsFrameSelected() const
Definition: feshview.cxx:1175
SfxStyleSearchBits
Definition: view.hxx:146
const sal_uInt16 COLL_EXTRA_BITS
Definition: poolfmt.hxx:68
VclPtr< SfxAbstractApplyTabDialog > m_pDlg
Definition: docst.cxx:567
SfxStyleFamily const m_nFamily
Definition: docst.cxx:572
static void DoUpdateAllCharts(SwDoc *pDoc)
Definition: unochart.cxx:54
bool GetTableAutoFormat(SwTableAutoFormat &rGet)
Definition: fetab.cxx:1256
virtual VclPtr< SfxAbstractApplyTabDialog > CreateTemplateDialog(weld::Window *pParent, SfxStyleSheetBase &rBase, SfxStyleFamily nRegion, const OString &sPage, SwWrtShell *pActShell, bool bNew)=0