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 
637  pDoc->getIDocumentState().SetModified();
638  if( !m_bModified )
639  {
641  }
642 
643  pWrtShell->EndAllAction();
644 }
645 
647  const OUString &rName,
648  const OUString &rParent,
649  const SfxStyleFamily nFamily,
650  SfxStyleSearchBits nMask,
651  const bool bNew,
652  const OString& sPage,
653  SwWrtShell* pActShell,
654  SfxRequest* pReq,
655  sal_uInt16 nSlot)
656 {
657  assert( GetWrtShell() );
658  const bool bBasic = pReq && pReq->IsAPI();
659  SfxStyleSheetBase *pStyle = nullptr;
660 
661  bool bModified = m_xDoc->getIDocumentState().IsModified();
662 
663  SwUndoId nNewStyleUndoId(SwUndoId::EMPTY);
664 
665  if( bNew )
666  {
667  if (!bBasic)
668  {
669  // start undo action in order to get only one undo action for the
670  // UI new style + change style operations
672  }
673 
674  if( SfxStyleSearchBits::All != nMask && SfxStyleSearchBits::AllVisible != nMask && SfxStyleSearchBits::Used != nMask )
675  nMask |= SfxStyleSearchBits::UserDefined;
676  else
677  nMask = SfxStyleSearchBits::UserDefined;
678 
679  pStyle = &m_xBasePool->Make( rName, nFamily, nMask );
680 
681  // set the current one as Parent
682  SwDocStyleSheet* pDStyle = static_cast<SwDocStyleSheet*>(pStyle);
683  switch( nFamily )
684  {
685  case SfxStyleFamily::Para:
686  {
687  if(!rParent.isEmpty())
688  {
690  if(!pColl)
691  {
693  if(USHRT_MAX != nId)
694  pColl = m_pWrtShell->GetTextCollFromPool( nId );
695  }
696  pDStyle->GetCollection()->SetDerivedFrom( pColl );
697  pDStyle->PresetParent( rParent );
698 
699  /*When a new paragraph style is created based on a "to outline style
700  assigned" paragraph style, the outline level attribute and the list
701  style attribute of the new paragraph style have to be set to 0
702  respectively "".*/
703  if (pColl && pColl->IsAssignedToListLevelOfOutlineStyle())
704  {
705  SwNumRuleItem aItem;
706  pDStyle->GetCollection()->SetFormatAttr( aItem );
707  pDStyle->GetCollection()->SetAttrOutlineLevel( 0 );
708  }
709  }
710  else
711  {
713  pDStyle->GetCollection()->SetDerivedFrom( pColl );
714  if( pColl )
715  pDStyle->PresetParent( pColl->GetName() );
716  }
717  }
718  break;
719  case SfxStyleFamily::Char:
720  {
721  if(!rParent.isEmpty())
722  {
723  SwCharFormat* pCFormat = m_pWrtShell->FindCharFormatByName(rParent);
724  if(!pCFormat)
725  {
727  if(USHRT_MAX != nId)
728  pCFormat = m_pWrtShell->GetCharFormatFromPool( nId );
729  }
730 
731  pDStyle->GetCharFormat()->SetDerivedFrom( pCFormat );
732  pDStyle->PresetParent( rParent );
733  }
734  else
735  {
737  pDStyle->GetCharFormat()->SetDerivedFrom( pCFormat );
738  if( pCFormat )
739  pDStyle->PresetParent( pCFormat->GetName() );
740  }
741  }
742  break;
743  case SfxStyleFamily::Frame :
744  {
745  if(!rParent.isEmpty())
746  {
747  SwFrameFormat* pFFormat = m_pWrtShell->GetDoc()->FindFrameFormatByName( rParent );
748  if(!pFFormat)
749  {
751  if(USHRT_MAX != nId)
752  pFFormat = m_pWrtShell->GetFrameFormatFromPool( nId );
753  }
754  pDStyle->GetFrameFormat()->SetDerivedFrom( pFFormat );
755  pDStyle->PresetParent( rParent );
756  }
757  }
758  break;
759  default: break;
760  }
761 
762  if (!bBasic)
763  {
764  //Get the undo id for the type of style that was created in order to re-use that comment for the grouped
765  //create style + change style operations
766  m_pWrtShell->GetLastUndoInfo(nullptr, &nNewStyleUndoId);
767  }
768  }
769  else
770  {
771  pStyle = m_xBasePool->Find( rName, nFamily );
772  SAL_WARN_IF( !pStyle, "sw.ui", "Style not found" );
773  }
774 
775  if(!pStyle)
776  return;
777 
778  // put dialogues together
779  rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pStyle) ) );
780  if( SfxStyleFamily::Para == nFamily )
781  {
782  SfxItemSet& rSet = xTmp->GetItemSet();
783  ::SwToSfxPageDescAttr( rSet );
784  // merge list level indent attributes into the item set if needed
785  xTmp->MergeIndentAttrsOfListStyle( rSet );
786  }
787  else if( SfxStyleFamily::Char == nFamily )
788  {
789  ::ConvertAttrCharToGen(xTmp->GetItemSet());
790  }
791 
792  if(SfxStyleFamily::Page == nFamily || SfxStyleFamily::Para == nFamily)
793  {
794  // create needed items for XPropertyList entries from the DrawModel so that
795  // the Area TabPage can access them
796  SfxItemSet& rSet = xTmp->GetItemSet();
797  const SwDrawModel* pDrawModel = GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
798 
799  rSet.Put(SvxColorListItem(pDrawModel->GetColorList(), SID_COLOR_TABLE));
800  rSet.Put(SvxGradientListItem(pDrawModel->GetGradientList(), SID_GRADIENT_LIST));
801  rSet.Put(SvxHatchListItem(pDrawModel->GetHatchList(), SID_HATCH_LIST));
802  rSet.Put(SvxBitmapListItem(pDrawModel->GetBitmapList(), SID_BITMAP_LIST));
803  rSet.Put(SvxPatternListItem(pDrawModel->GetPatternList(), SID_PATTERN_LIST));
804  }
805 
806  if (!bBasic)
807  {
808  // prior to the dialog the HtmlMode at the DocShell is being sunk
809  sal_uInt16 nHtmlMode = ::GetHtmlMode(this);
810 
811  // In HTML mode, we do not always have a printer. In order to show
812  // the correct page size in the Format - Page dialog, we have to
813  // get one here.
814  SwWrtShell* pCurrShell = pActShell ? pActShell : m_pWrtShell;
815  if( ( HTMLMODE_ON & nHtmlMode ) &&
816  !pCurrShell->getIDocumentDeviceAccess().getPrinter( false ) )
817  pCurrShell->InitPrt( pCurrShell->getIDocumentDeviceAccess().getPrinter( true ) );
818 
819  PutItem(SfxUInt16Item(SID_HTML_MODE, nHtmlMode));
820  FieldUnit eMetric = ::GetDfltMetric(0 != (HTMLMODE_ON&nHtmlMode));
821  SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)));
823  VclPtr<SfxAbstractApplyTabDialog> pDlg(pFact->CreateTemplateDialog(GetView()->GetViewFrame()->GetWindow().GetFrameWeld(),
824  *xTmp, nFamily, sPage, pCurrShell, bNew));
825  std::shared_ptr<ApplyStyle> pApplyStyleHelper(new ApplyStyle(*this, bNew, xTmp, nFamily, pDlg.get(), m_xBasePool, bModified));
826  pDlg->SetApplyHdl(LINK(pApplyStyleHelper.get(), ApplyStyle, ApplyHdl));
827 
828  std::shared_ptr<SfxRequest> pRequest;
829  if (pReq)
830  {
831  pRequest.reset(new SfxRequest(*pReq));
832  pReq->Ignore(); // the 'old' request is not relevant any more
833  }
834 
835  pDlg->StartExecuteAsync([bModified, bNew, nFamily, nSlot, nNewStyleUndoId, pApplyStyleHelper, pRequest, xTmp, this](sal_Int32 nResult){
836  if (RET_OK == nResult)
837  pApplyStyleHelper->apply();
838 
839  if (bNew)
840  {
841  SwRewriter aRewriter;
842  aRewriter.AddRule(UndoArg1, xTmp->GetName());
843  //Group the create style and change style operations together under the
844  //one "create style" comment
845  m_pWrtShell->EndUndo(nNewStyleUndoId, &aRewriter);
846  }
847 
848  if (RET_OK != nResult)
849  {
850  if (bNew)
851  {
852  GetWrtShell()->Undo();
853  m_xDoc->GetIDocumentUndoRedo().ClearRedo();
854  }
855 
856  if (!bModified)
857  m_xDoc->getIDocumentState().ResetModified();
858  }
859 
860  // Update Watermark if new page style was created
861  if (nSlot == SID_STYLE_NEW && nFamily == SfxStyleFamily::Page)
862  {
863  SwWrtShell* pShell = GetWrtShell();
864  const SfxWatermarkItem aWatermark = pShell->GetWatermark();
865  pShell->SetWatermark(aWatermark);
866  }
867 
868  pApplyStyleHelper->m_pDlg.disposeAndClear();
869  if (pRequest)
870  pRequest->Done();
871  });
872  }
873  else
874  {
875  // prior to the dialog the HtmlMode at the DocShell is being sunk
876  PutItem(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(this)));
877 
879 
880  if( SfxStyleFamily::Para == nFamily )
881  ::SfxToSwPageDescAttr( *GetWrtShell(), xTmp->GetItemSet() );
882  else
883  {
884  ::ConvertAttrGenToChar(xTmp->GetItemSet(), xTmp->GetItemSet());
885  }
886  if(SfxStyleFamily::Page == nFamily)
888 
889  if( bNew )
890  m_xBasePool->Broadcast(SfxStyleSheetHint(SfxHintId::StyleSheetCreated, *xTmp));
891 
892  m_xDoc->getIDocumentState().SetModified();
893  if( !bModified ) // Bug 57028
894  {
895  m_xDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
896  }
898  }
899 }
900 
901 void SwDocShell::Delete(const OUString &rName, SfxStyleFamily nFamily)
902 {
903  SfxStyleSheetBase *pStyle = m_xBasePool->Find(rName, nFamily);
904 
905  if(pStyle)
906  {
907  assert( GetWrtShell() );
908 
910  m_xBasePool->Remove(pStyle);
912  }
913 }
914 
915 void SwDocShell::Hide(const OUString &rName, SfxStyleFamily nFamily, bool bHidden)
916 {
917  SfxStyleSheetBase *pStyle = m_xBasePool->Find(rName, nFamily);
918 
919  if(pStyle)
920  {
921  assert( GetWrtShell() );
922 
924  rtl::Reference< SwDocStyleSheet > xTmp( new SwDocStyleSheet( *static_cast<SwDocStyleSheet*>(pStyle) ) );
925  xTmp->SetHidden( bHidden );
927  }
928 }
929 
930 // apply template
932  SwWrtShell* pShell, const sal_uInt16 nMode )
933 {
934  SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>( m_xBasePool->Find( rName, nFamily ) );
935 
936  SAL_WARN_IF( !pStyle, "sw.ui", "Style not found" );
937 
938  if(!pStyle)
939  return SfxStyleFamily::None;
940 
941  SwWrtShell *pSh = pShell ? pShell : GetWrtShell();
942 
943  assert( pSh );
944 
945  pSh->StartAllAction();
946 
947  switch (nFamily)
948  {
949  case SfxStyleFamily::Char:
950  {
951  SwFormatCharFormat aFormat(pStyle->GetCharFormat());
952  pSh->SetAttrItem( aFormat, (nMode & KEY_SHIFT) ?
954  break;
955  }
956  case SfxStyleFamily::Para:
957  {
958  // #i62675#
959  // clear also list attributes at affected text nodes, if paragraph
960  // style has the list style attribute set.
961  pSh->SetTextFormatColl( pStyle->GetCollection(), true );
962  break;
963  }
964  case SfxStyleFamily::Frame:
965  {
966  if ( pSh->IsFrameSelected() )
967  pSh->SetFrameFormat( pStyle->GetFrameFormat() );
968  break;
969  }
970  case SfxStyleFamily::Page:
971  {
972  pSh->SetPageStyle(pStyle->GetPageDesc()->GetName());
973  break;
974  }
975  case SfxStyleFamily::Pseudo:
976  {
977  // reset indent attribute on applying list style
978  // continue list of list style
979  const SwNumRule* pNumRule = pStyle->GetNumRule();
980  const OUString sListIdForStyle =pNumRule->GetDefaultListId();
981  pSh->SetCurNumRule( *pNumRule, false, sListIdForStyle, true );
982  break;
983  }
984  case SfxStyleFamily::Table:
985  {
986  pSh->SetTableStyle(pStyle->GetName());
987  break;
988  }
989  default:
990  OSL_FAIL("Unknown family");
991  }
992  pSh->EndAllAction();
993 
994  return nFamily;
995 }
996 
997 // start watering-can
998 SfxStyleFamily SwDocShell::DoWaterCan(const OUString &rName, SfxStyleFamily nFamily)
999 {
1000  assert( GetWrtShell() );
1001 
1002  SwEditWin& rEdtWin = m_pView->GetEditWin();
1003  SwApplyTemplate* pApply = rEdtWin.GetApplyTemplate();
1004  bool bWaterCan = !(pApply && pApply->eType != SfxStyleFamily(0));
1005 
1006  if( rName.isEmpty() )
1007  bWaterCan = false;
1008 
1009  SwApplyTemplate aTemplate;
1010  aTemplate.eType = nFamily;
1011 
1012  if(bWaterCan)
1013  {
1014  SwDocStyleSheet* pStyle =
1015  static_cast<SwDocStyleSheet*>( m_xBasePool->Find(rName, nFamily) );
1016 
1017  SAL_WARN_IF( !pStyle, "sw.ui", "Where's the StyleSheet" );
1018 
1019  if(!pStyle) return nFamily;
1020 
1021  switch(nFamily)
1022  {
1023  case SfxStyleFamily::Char:
1024  aTemplate.aColl.pCharFormat = pStyle->GetCharFormat();
1025  break;
1026  case SfxStyleFamily::Para:
1027  aTemplate.aColl.pTextColl = pStyle->GetCollection();
1028  break;
1029  case SfxStyleFamily::Frame:
1030  aTemplate.aColl.pFrameFormat = pStyle->GetFrameFormat();
1031  break;
1032  case SfxStyleFamily::Page:
1033  aTemplate.aColl.pPageDesc = const_cast<SwPageDesc*>(pStyle->GetPageDesc());
1034  break;
1035  case SfxStyleFamily::Pseudo:
1036  aTemplate.aColl.pNumRule = const_cast<SwNumRule*>(pStyle->GetNumRule());
1037  break;
1038 
1039  default:
1040  OSL_FAIL("Unknown family");
1041  }
1042  }
1043  else
1044  aTemplate.eType = SfxStyleFamily(0);
1045 
1046  m_pView->GetEditWin().SetApplyTemplate(aTemplate);
1047 
1048  return nFamily;
1049 }
1050 
1051 // update template
1052 void SwDocShell::UpdateStyle(const OUString &rName, SfxStyleFamily nFamily, SwWrtShell* pShell)
1053 {
1054  SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell();
1055  assert( pCurrWrtShell );
1056 
1057  SwDocStyleSheet* pStyle =
1058  static_cast<SwDocStyleSheet*>( m_xBasePool->Find(rName, nFamily) );
1059 
1060  if (!pStyle)
1061  return;
1062 
1063  switch(nFamily)
1064  {
1065  case SfxStyleFamily::Para:
1066  {
1067  SwTextFormatColl* pColl = pStyle->GetCollection();
1068  if(pColl && !pColl->IsDefault())
1069  {
1071 
1072  SwRewriter aRewriter;
1073  aRewriter.AddRule(UndoArg1, pColl->GetName());
1074 
1075  GetWrtShell()->StartUndo(SwUndoId::INSFMTATTR, &aRewriter);
1076  GetWrtShell()->FillByEx(pColl);
1077  // also apply template to remove hard set attributes
1078  GetWrtShell()->SetTextFormatColl( pColl );
1079  GetWrtShell()->EndUndo();
1081  }
1082  break;
1083  }
1084  case SfxStyleFamily::Frame:
1085  {
1086  SwFrameFormat* pFrame = pStyle->GetFrameFormat();
1087  if( pCurrWrtShell->IsFrameSelected() && pFrame && !pFrame->IsDefault() )
1088  {
1090  pCurrWrtShell->StartAllAction();
1091  pCurrWrtShell->GetFlyFrameAttr( aSet );
1092 
1093  // #i105535#
1094  // no update of anchor attribute
1095  aSet.ClearItem( RES_ANCHOR );
1096 
1097  pFrame->SetFormatAttr( aSet );
1098 
1099  // also apply template to remove hard set attributes
1100  pCurrWrtShell->SetFrameFormat( pFrame, true );
1101  pCurrWrtShell->EndAllAction();
1102  }
1103  }
1104  break;
1105  case SfxStyleFamily::Char:
1106  {
1107  SwCharFormat* pChar = pStyle->GetCharFormat();
1108  if( pChar && !pChar->IsDefault() )
1109  {
1110  pCurrWrtShell->StartAllAction();
1111  pCurrWrtShell->FillByEx(pChar);
1112  // also apply template to remove hard set attributes
1113  pCurrWrtShell->EndAllAction();
1114  }
1115 
1116  }
1117  break;
1118  case SfxStyleFamily::Pseudo:
1119  {
1120  const SwNumRule* pCurRule;
1121  if( pStyle->GetNumRule() &&
1122  nullptr != ( pCurRule = pCurrWrtShell->GetNumRuleAtCurrCursorPos() ))
1123  {
1124  SwNumRule aRule( *pCurRule );
1125  // #i91400#
1126  aRule.SetName( pStyle->GetNumRule()->GetName(),
1127  pCurrWrtShell->GetDoc()->getIDocumentListsAccess() );
1128  pCurrWrtShell->ChgNumRuleFormats( aRule );
1129  }
1130  }
1131  break;
1132  case SfxStyleFamily::Table:
1133  {
1134 
1135  SwTableAutoFormat aFormat(rName);
1136  if (pCurrWrtShell->GetTableAutoFormat(aFormat))
1137  {
1138  pCurrWrtShell->StartAllAction();
1139  pCurrWrtShell->GetDoc()->ChgTableStyle(rName, aFormat);
1140  pCurrWrtShell->EndAllAction();
1141  }
1142 
1143  }
1144  break;
1145  default: break;
1146  }
1147 }
1148 
1149 // NewByExample
1150 void SwDocShell::MakeByExample( const OUString &rName, SfxStyleFamily nFamily,
1151  SfxStyleSearchBits nMask, SwWrtShell* pShell )
1152 {
1153  SwWrtShell* pCurrWrtShell = pShell ? pShell : GetWrtShell();
1154  SwDocStyleSheet* pStyle = static_cast<SwDocStyleSheet*>( m_xBasePool->Find(
1155  rName, nFamily ) );
1156  if(!pStyle)
1157  {
1158  // preserve the current mask of PI, then the new one is
1159  // immediately merged with the viewable area
1160  if( SfxStyleSearchBits::All == nMask || SfxStyleSearchBits::Used == nMask )
1161  nMask = SfxStyleSearchBits::UserDefined;
1162  else
1163  nMask |= SfxStyleSearchBits::UserDefined;
1164 
1165  pStyle = static_cast<SwDocStyleSheet*>( &m_xBasePool->Make(rName,
1166  nFamily, nMask ) );
1167  }
1168 
1169  switch(nFamily)
1170  {
1171  case SfxStyleFamily::Para:
1172  {
1173  SwTextFormatColl* pColl = pStyle->GetCollection();
1174  if(pColl && !pColl->IsDefault())
1175  {
1176  pCurrWrtShell->StartAllAction();
1177  pCurrWrtShell->FillByEx(pColl);
1178  // also apply template to remove hard set attributes
1179  pColl->SetDerivedFrom(pCurrWrtShell->GetCurTextFormatColl());
1180 
1181  // set the mask at the Collection:
1182  sal_uInt16 nId = pColl->GetPoolFormatId() & 0x87ff;
1183  switch( nMask & static_cast<SfxStyleSearchBits>(0x0fff) )
1184  {
1185  case SfxStyleSearchBits::SwText:
1186  nId |= COLL_TEXT_BITS;
1187  break;
1188  case SfxStyleSearchBits::SwChapter:
1189  nId |= COLL_DOC_BITS;
1190  break;
1191  case SfxStyleSearchBits::SwList:
1192  nId |= COLL_LISTS_BITS;
1193  break;
1194  case SfxStyleSearchBits::SwIndex:
1195  nId |= COLL_REGISTER_BITS;
1196  break;
1197  case SfxStyleSearchBits::SwExtra:
1198  nId |= COLL_EXTRA_BITS;
1199  break;
1200  case SfxStyleSearchBits::SwHtml:
1201  nId |= COLL_HTML_BITS;
1202  break;
1203  default: break;
1204  }
1205  pColl->SetPoolFormatId(nId);
1206 
1207  pCurrWrtShell->SetTextFormatColl(pColl);
1208  pCurrWrtShell->EndAllAction();
1209  }
1210  }
1211  break;
1212  case SfxStyleFamily::Frame:
1213  {
1214  SwFrameFormat* pFrame = pStyle->GetFrameFormat();
1215  if(pCurrWrtShell->IsFrameSelected() && pFrame && !pFrame->IsDefault())
1216  {
1217  pCurrWrtShell->StartAllAction();
1218 
1220  pCurrWrtShell->GetFlyFrameAttr( aSet );
1221  aSet.ClearItem(RES_ANCHOR); // tdf#112574 no anchor in styles
1222 
1223  SwFrameFormat* pFFormat = pCurrWrtShell->GetSelectedFrameFormat();
1224  pFrame->SetDerivedFrom( pFFormat );
1225 
1226  pFrame->SetFormatAttr( aSet );
1227  // also apply template to remove hard set attributes
1228  pCurrWrtShell->SetFrameFormat( pFrame );
1229  pCurrWrtShell->EndAllAction();
1230  }
1231  }
1232  break;
1233  case SfxStyleFamily::Char:
1234  {
1235  SwCharFormat* pChar = pStyle->GetCharFormat();
1236  if(pChar && !pChar->IsDefault())
1237  {
1238  pCurrWrtShell->StartAllAction();
1239  pCurrWrtShell->FillByEx( pChar );
1240  pChar->SetDerivedFrom( pCurrWrtShell->GetCurCharFormat() );
1241  SwFormatCharFormat aFormat( pChar );
1242  pCurrWrtShell->SetAttrItem( aFormat );
1243  pCurrWrtShell->EndAllAction();
1244  }
1245  }
1246  break;
1247 
1248  case SfxStyleFamily::Page:
1249  {
1250  pCurrWrtShell->StartAllAction();
1251  size_t nPgDsc = pCurrWrtShell->GetCurPageDesc();
1252  SwPageDesc& rSrc = const_cast<SwPageDesc&>(pCurrWrtShell->GetPageDesc( nPgDsc ));
1253  SwPageDesc& rDest = *const_cast<SwPageDesc*>(pStyle->GetPageDesc());
1254 
1255  sal_uInt16 nPoolId = rDest.GetPoolFormatId();
1256  sal_uInt16 nHId = rDest.GetPoolHelpId();
1257  sal_uInt8 nHFId = rDest.GetPoolHlpFileId();
1258 
1259  pCurrWrtShell->GetDoc()->CopyPageDesc( rSrc, rDest );
1260 
1261  // PoolId must NEVER be copied!
1262  rDest.SetPoolFormatId( nPoolId );
1263  rDest.SetPoolHelpId( nHId );
1264  rDest.SetPoolHlpFileId( nHFId );
1265 
1266  // when Headers/Footers are created, there is no Undo anymore!
1267  pCurrWrtShell->GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj();
1268 
1269  pCurrWrtShell->EndAllAction();
1270  }
1271  break;
1272 
1273  case SfxStyleFamily::Pseudo:
1274  {
1275  const SwNumRule* pCurRule = pCurrWrtShell->GetNumRuleAtCurrCursorPos();
1276 
1277  if (pCurRule)
1278  {
1279  pCurrWrtShell->StartAllAction();
1280 
1281  SwNumRule aRule( *pCurRule );
1282  OUString sOrigRule( aRule.GetName() );
1283  // #i91400#
1284  aRule.SetName( pStyle->GetNumRule()->GetName(),
1285  pCurrWrtShell->GetDoc()->getIDocumentListsAccess() );
1286  pCurrWrtShell->ChgNumRuleFormats( aRule );
1287 
1288  pCurrWrtShell->ReplaceNumRule( sOrigRule, aRule.GetName() );
1289 
1290  pCurrWrtShell->EndAllAction();
1291  }
1292  }
1293  break;
1294 
1295  case SfxStyleFamily::Table:
1296  {
1297  SwTableAutoFormat* pFormat = pStyle->GetTableFormat();
1298  if (pCurrWrtShell->GetTableAutoFormat(*pFormat))
1299  {
1300  pCurrWrtShell->StartAllAction();
1301 
1302  pCurrWrtShell->SetTableStyle(rName);
1303 
1304  pCurrWrtShell->EndAllAction();
1305  }
1306  }
1307  break;
1308 
1309  default: break;
1310  }
1311 }
1312 
1313 std::set<Color> SwDocShell::GetDocColors()
1314 {
1315  return m_xDoc->GetDocColors();
1316 }
1317 
1319 {
1320  LoadStyles_(rSource, false);
1321 }
1322 
1323 // bPreserveCurrentDocument determines whether SetFixFields() is called
1324 // This call modifies the source document. This mustn't happen when the source
1325 // is a document the user is working on.
1326 // Calls of ::LoadStyles() normally use files especially loaded for the purpose
1327 // of importing styles.
1328 void SwDocShell::LoadStyles_( SfxObjectShell& rSource, bool bPreserveCurrentDocument )
1329 {
1330 /* [Description]
1331 
1332  This method is called by SFx if Styles have to be reloaded from a
1333  document-template. Existing Styles should be overwritten by that.
1334  That's why the document has to be reformatted. Therefore applications
1335  will usually override this method and call the baseclass' implementation
1336  in their implementation.
1337 */
1338  // When the source is our document, we do the checking ourselves
1339  // (much quicker and doesn't use the crutch StxStylePool).
1340  if( dynamic_cast<const SwDocShell*>( &rSource) != nullptr)
1341  {
1342  // in order for the Headers/Footers not to get the fixed content
1343  // of the template, update all the Source's
1344  // FixFields once.
1345  if(!bPreserveCurrentDocument)
1346  static_cast<SwDocShell&>(rSource).m_xDoc->getIDocumentFieldsAccess().SetFixFields(nullptr);
1347  if (m_pWrtShell)
1348  {
1349  // rhbz#818557, fdo#58893: EndAllAction will call SelectShell(),
1350  // which pushes a bunch of SfxShells that are not cleared
1351  // (for unknown reasons) when closing the document, causing crash;
1352  // setting g_bNoInterrupt appears to avoid the problem.
1355  m_xDoc->ReplaceStyles( *static_cast<SwDocShell&>(rSource).m_xDoc );
1357  }
1358  else
1359  {
1360  bool bModified = m_xDoc->getIDocumentState().IsModified();
1361  m_xDoc->ReplaceStyles( *static_cast<SwDocShell&>(rSource).m_xDoc );
1362  if (!bModified && m_xDoc->getIDocumentState().IsModified() && !m_pView)
1363  {
1364  // the View is created later, but overwrites the Modify-Flag.
1365  // Undo doesn't work anymore anyways.
1366  m_xDoc->GetIDocumentUndoRedo().SetUndoNoResetModified();
1367  }
1368  }
1369  }
1370  else
1371  SfxObjectShell::LoadStyles( rSource );
1372 }
1373 
1375  const OUString& rPage,
1376  const OString& rPageId,
1377  SwWrtShell& rActShell,
1378  SfxRequest* pRequest)
1379 {
1380  Edit(rPage, OUString(), SfxStyleFamily::Page, SfxStyleSearchBits::Auto, false, rPageId, &rActShell, pRequest);
1381 }
1382 
1383 /* 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:191
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:1052
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:221
SwEditWin & GetEditWin()
Definition: view.hxx:403
void Done(bool bRemove=false)
void SetPageStyle(const OUString &rCollName)
Definition: wrtsh1.cxx:1519
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:4921
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:86
void SetWatermark(const SfxWatermarkItem &rText)
Definition: edfcol.cxx:1608
SfxWatermarkItem GetWatermark()
Definition: edfcol.cxx:1383
void FillByEx(SwCharFormat *)
Definition: edfmt.cxx:55
bool IsAssignedToListLevelOfOutlineStyle() const
Definition: fmtcol.hxx:109
const SwView & GetView() const
Definition: wrtsh.hxx:424
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:646
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:1318
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:202
const IDocumentDeviceAccess & getIDocumentDeviceAccess() const
Provides access to the document device interface.
Definition: viewsh.cxx:2590
const SwTableNode * IsCursorInTable() const
Definition: crsrsh.hxx:885
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
void SetTextFormatColl(SwTextFormatColl *, const bool bResetListAttrs=false)
Add 2nd optional parameter - see also
Definition: edfcol.cxx:2188
Style of a layout element.
Definition: frmfmt.hxx:57
DECL_LINK(ApplyHdl, LinkParamNone *, void)
SwApplyTemplate * GetApplyTemplate() const
Definition: edtwin.hxx:229
#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:59
void LoadStyles_(SfxObjectShell &rSource, bool bPreserveCurrentDocument)
Definition: docst.cxx:1328
virtual std::set< Color > GetDocColors() override
Definition: docst.cxx:1313
OUString sName
SfxBindings & GetBindings()
#define FN_PARAM_WRTSHELL
Definition: cmdid.h:766
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:1160
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:223
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:229
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:1150
SAL_DLLPRIVATE void Hide(const OUString &rName, SfxStyleFamily nFamily, bool bHidden)
Definition: docst.cxx:915
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:259
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:931
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:998
bool IsAPI() const
const SwView * GetView() const
Definition: docsh.hxx:219
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:1374
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:901
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