LibreOffice Module sw (master)  1
regionsw.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 <hintids.hxx>
21 #include <comphelper/string.hxx>
22 #include <svl/stritem.hxx>
23 #include <svl/eitem.hxx>
24 #include <sfx2/request.hxx>
25 #include <sfx2/linkmgr.hxx>
26 #include <editeng/sizeitem.hxx>
27 #include <section.hxx>
28 #include <basesh.hxx>
29 #include <view.hxx>
30 #include <wrtsh.hxx>
31 #include <fmtclds.hxx>
32 #include <fmtfsize.hxx>
33 #include <cmdid.h>
34 #include <swabstdlg.hxx>
35 
37 {
38  SwWrtShell& rSh = GetShell();
39  const SfxItemSet *pSet = rReq.GetArgs();
40 
48  SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE>
49  aSet( GetPool() );
50 
51  if (!pSet || pSet->Count()==0)
52  {
53  SwRect aRect;
54  rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
55 
56  tools::Long nWidth = aRect.Width();
57  aSet.Put(SwFormatFrameSize(SwFrameSize::Variable, nWidth));
58 
59  // height=width for more consistent preview (analog to edit region)
60  aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
63  GetView().GetFrameWeld(), aSet , rSh));
64  aTabDlg->StartExecuteAsync([aTabDlg](sal_Int32 /*nResult*/){
65  aTabDlg->disposeOnce();
66  });
67  rReq.Ignore();
68  }
69  else
70  {
71  OUString aTmpStr;
72  if ( const SfxStringItem* pItem = pSet->GetItemIfSet(FN_PARAM_REGION_NAME) )
73  {
74  const OUString sRemoveWhenUniStringIsGone = pItem->GetValue();
75  aTmpStr = rSh.GetUniqueSectionName(&sRemoveWhenUniStringIsGone);
76  }
77  else
78  aTmpStr = rSh.GetUniqueSectionName();
79 
80  SwSectionData aSection(SectionType::Content, aTmpStr);
82 
83  aSet.Put( *pSet );
84  const SfxUInt16Item *pColRegionItem = nullptr;
85  if((pColRegionItem = pSet->GetItemIfSet(SID_ATTR_COLUMNS, false)) ||
86  (pColRegionItem = pSet->GetItemIfSet(FN_INSERT_REGION, false)))
87  {
88  SwFormatCol aCol;
89  SwRect aRect;
90  rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
91  tools::Long nWidth = aRect.Width();
92 
93  sal_uInt16 nCol = pColRegionItem->GetValue();
94  if(nCol)
95  {
96  aCol.Init( nCol, 0, static_cast< sal_uInt16 >(nWidth) );
97  aSet.Put(aCol);
98  }
99  }
100  else if(const SwFormatCol* pFormatCol = pSet->GetItemIfSet(RES_COL, false))
101  {
102  aSet.Put(*pFormatCol);
103  }
104 
105  const SfxBoolItem* pBoolItem;
106  const bool bHidden = (pBoolItem = pSet->GetItemIfSet(FN_PARAM_REGION_HIDDEN)) &&
107  pBoolItem->GetValue();
108  const bool bProtect = (pBoolItem = pSet->GetItemIfSet(FN_PARAM_REGION_PROTECT)) &&
109  pBoolItem->GetValue();
110  // #114856# edit in readonly sections
111  const bool bEditInReadonly = (pBoolItem = pSet->GetItemIfSet(FN_PARAM_REGION_EDIT_IN_READONLY)) &&
112  pBoolItem->GetValue();
113 
114  aSection.SetProtectFlag(bProtect);
115  aSection.SetHidden(bHidden);
116  // #114856# edit in readonly sections
117  aSection.SetEditInReadonlyFlag(bEditInReadonly);
118 
119  if(const SfxStringItem* pConditionItem =
121  aSection.SetCondition(pConditionItem->GetValue());
122 
123  OUString aFile, aSub;
124  const SfxPoolItem* pItem;
125  if(SfxItemState::SET ==
126  pSet->GetItemState(FN_PARAM_1, true, &pItem))
127  aFile = static_cast<const SfxStringItem *>(pItem)->GetValue();
128 
129  if(SfxItemState::SET ==
130  pSet->GetItemState(FN_PARAM_3, true, &pItem))
131  aSub = static_cast<const SfxStringItem *>(pItem)->GetValue();
132 
133  if(!aFile.isEmpty() || !aSub.isEmpty())
134  {
135  OUString sLinkFileName = OUStringChar(sfx2::cTokenSeparator)
136  + OUStringChar(sfx2::cTokenSeparator);
137  sLinkFileName = comphelper::string::setToken(sLinkFileName, 0, sfx2::cTokenSeparator, aFile);
138 
139  if(SfxItemState::SET ==
140  pSet->GetItemState(FN_PARAM_2, true, &pItem))
141  {
142  sLinkFileName = comphelper::string::setToken(sLinkFileName, 1, sfx2::cTokenSeparator,
143  static_cast<const SfxStringItem *>(pItem)->GetValue());
144  }
145 
146  sLinkFileName += aSub;
147  aSection.SetType( SectionType::FileLink );
148  aSection.SetLinkFileName(sLinkFileName);
149  }
150  rSh.InsertSection(aSection, aSet.Count() ? &aSet : nullptr);
151  rReq.Done();
152  }
153 }
154 
156 {
160  RES_COL, RES_COL,
162  SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE>
163  aSet( GetView().GetPool() );
164  SwRect aRect;
165  CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
166  tools::Long nWidth = aRect.Width();
167  aSet.Put(SwFormatFrameSize(SwFrameSize::Variable, nWidth));
168  // height=width for more consistent preview (analog to edit region)
169  aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
172  GetView().GetFrameWeld(), aSet, *this));
173  aTabDlg->SetSectionData(rSectionData);
174  aTabDlg->StartExecuteAsync([aTabDlg](sal_Int32 /*nResult*/){
175  aTabDlg->disposeOnce();
176  });
177 }
178 
180 {
181  const SfxItemSet* pArgs = rReq.GetArgs();
182  sal_uInt16 nSlot = rReq.GetSlot();
183  const SfxPoolItem* pItem = nullptr;
184  if(pArgs)
185  pArgs->GetItemState(nSlot, false, &pItem);
186  SwWrtShell& rWrtShell = GetShell();
187 
188  switch ( nSlot )
189  {
190  case FN_EDIT_REGION:
192  {
193  weld::Window* pParentWin = GetView().GetFrameWeld();
194  {
196  ScopedVclPtr<AbstractEditRegionDlg> pEditRegionDlg(pFact->CreateEditRegionDlg(pParentWin, rWrtShell));
197  if(auto pStringItem = dynamic_cast< const SfxStringItem *>( pItem ))
198  {
199  pEditRegionDlg->SelectSection(pStringItem->GetValue());
200  }
201  pEditRegionDlg->Execute();
202  }
203  }
204  break;
205  }
206 }
207 
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool GetValue() const
constexpr TypedWhichId< SvxFrameDirectionItem > RES_FRAMEDIR(120)
constexpr sal_uInt16 XATTR_FILL_LAST(XATTR_FILLUSESLIDEBACKGROUND)
#define FN_PARAM_REGION_EDIT_IN_READONLY
Definition: cmdid.h:793
#define FN_EDIT_REGION
Definition: cmdid.h:115
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
void SetType(SectionType const eNew)
Definition: section.hxx:94
SwView & GetView()
Definition: basesh.hxx:59
void SetHidden(bool const bFlag)
Definition: section.hxx:97
SAL_DLLPRIVATE void SetProtectFlag(bool const bFlag)
Definition: section.hxx:104
void SetLinkFileName(OUString const &rNew)
Definition: section.hxx:116
std::string GetValue
constexpr TypedWhichId< SwFormatCol > RES_COL(109)
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
SwWrtShell & GetShell()
Definition: basesh.cxx:2820
long Long
const sal_Unicode cTokenSeparator
#define FN_INSERT_REGION
Definition: cmdid.h:294
SwSection const * InsertSection(SwSectionData &rNewData, SfxItemSet const *const =nullptr)
Definition: edsect.cxx:35
sal_uInt16 GetValue() const
virtual VclPtr< AbstractInsertSectionTabDialog > CreateInsertSectionTabDialog(weld::Window *pParent, const SfxItemSet &rSet, SwWrtShell &rSh)=0
void Done(bool bRemove=false)
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
const SfxItemSet * GetArgs() const
void StartInsertRegionDialog(const SwSectionData &)
Definition: regionsw.cxx:155
Used by the UI to modify the document model.
Definition: wrtsh.hxx:96
const SwView & GetView() const
Definition: wrtsh.hxx:437
#define FN_EDIT_CURRENT_REGION
Definition: cmdid.h:117
void Width(tools::Long nNew)
Definition: swrect.hxx:189
#define FN_PARAM_REGION_PROTECT
Definition: cmdid.h:792
SfxItemPool & GetPool() const
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:19
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
sal_uInt16 Count() const
constexpr sal_uInt16 XATTR_FILL_FIRST(XATTRSET_LINE+1)
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
void SetCondition(OUString const &rNew)
Definition: section.hxx:113
void CalcBoundRect(SwRect &_orRect, const RndStdIds _nAnchorId, const sal_Int16 _eHoriRelOrient=css::text::RelOrientation::FRAME, const sal_Int16 _eVertRelOrient=css::text::RelOrientation::FRAME, const SwPosition *_pToCharContentPos=nullptr, const bool _bFollowTextFlow=false, bool _bMirror=false, Point *_opRef=nullptr, Size *_opPercent=nullptr, const SwFormatFrameSize *pFormatFrameSize=nullptr) const
i#17567 - adjustments to allow negative vertical positions for fly frames anchored to paragraph or to...
Definition: fews.cxx:691
void SetReturnValue(const SfxPoolItem &)
sal_uInt16 GetSlot() const
#define FN_PARAM_REGION_CONDITION
Definition: cmdid.h:790
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(105)
weld::Window * GetFrameWeld() const
OUString GetUniqueSectionName(const OUString *pChkStr=nullptr) const
Definition: edsect.cxx:166
void SetEditInReadonlyFlag(bool const bFlag)
Definition: section.hxx:106
#define FN_PARAM_REGION_NAME
Definition: cmdid.h:789
OUString setToken(const OUString &rIn, sal_Int32 nToken, sal_Unicode cTok, std::u16string_view rNewToken)
void InsertRegionDialog(SfxRequest &rReq)
Definition: regionsw.cxx:36
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(91)
virtual VclPtr< AbstractEditRegionDlg > CreateEditRegionDlg(weld::Window *pParent, SwWrtShell &rWrtSh)=0
Frame is variable in Var-direction.
void Init(sal_uInt16 nNumCols, sal_uInt16 nGutterWidth, sal_uInt16 nAct)
This function allows to (repeatedly) initialize the columns.
Definition: atrfrm.cxx:970
void Ignore()
void EditRegionDialog(SfxRequest const &rReq)
Definition: regionsw.cxx:179
constexpr TypedWhichId< SwFormatFootnoteAtTextEnd > RES_FTN_AT_TXTEND(117)
#define FN_PARAM_REGION_HIDDEN
Definition: cmdid.h:791