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  const SfxPoolItem *pItem = nullptr;
72  OUString aTmpStr;
73  if ( SfxItemState::SET ==
74  pSet->GetItemState(FN_PARAM_REGION_NAME, true, &pItem) )
75  {
76  const OUString sRemoveWhenUniStringIsGone = static_cast<const SfxStringItem *>(pItem)->GetValue();
77  aTmpStr = rSh.GetUniqueSectionName(&sRemoveWhenUniStringIsGone);
78  }
79  else
80  aTmpStr = rSh.GetUniqueSectionName();
81 
82  SwSectionData aSection(SectionType::Content, aTmpStr);
84 
85  aSet.Put( *pSet );
86  if(SfxItemState::SET == pSet->GetItemState(SID_ATTR_COLUMNS, false, &pItem)||
87  SfxItemState::SET == pSet->GetItemState(FN_INSERT_REGION, false, &pItem))
88  {
89  SwFormatCol aCol;
90  SwRect aRect;
91  rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
92  tools::Long nWidth = aRect.Width();
93 
94  sal_uInt16 nCol = static_cast<const SfxUInt16Item *>(pItem)->GetValue();
95  if(nCol)
96  {
97  aCol.Init( nCol, 0, static_cast< sal_uInt16 >(nWidth) );
98  aSet.Put(aCol);
99  }
100  }
101  else if(SfxItemState::SET == pSet->GetItemState(RES_COL, false, &pItem))
102  {
103  aSet.Put(*pItem);
104  }
105 
106  const bool bHidden = SfxItemState::SET == pSet->GetItemState(FN_PARAM_REGION_HIDDEN, true, &pItem) &&
107  static_cast<const SfxBoolItem *>(pItem)->GetValue();
108  const bool bProtect = SfxItemState::SET == pSet->GetItemState(FN_PARAM_REGION_PROTECT, true, &pItem) &&
109  static_cast<const SfxBoolItem *>(pItem)->GetValue();
110  // #114856# edit in readonly sections
111  const bool bEditInReadonly = SfxItemState::SET == pSet->GetItemState(FN_PARAM_REGION_EDIT_IN_READONLY, true, &pItem) &&
112  static_cast<const SfxBoolItem *>(pItem)->GetValue();
113 
114  aSection.SetProtectFlag(bProtect);
115  aSection.SetHidden(bHidden);
116  // #114856# edit in readonly sections
117  aSection.SetEditInReadonlyFlag(bEditInReadonly);
118 
119  if(SfxItemState::SET ==
120  pSet->GetItemState(FN_PARAM_REGION_CONDITION, true, &pItem))
121  aSection.SetCondition(static_cast<const SfxStringItem *>(pItem)->GetValue());
122 
123  OUString aFile, aSub;
124  if(SfxItemState::SET ==
125  pSet->GetItemState(FN_PARAM_1, true, &pItem))
126  aFile = static_cast<const SfxStringItem *>(pItem)->GetValue();
127 
128  if(SfxItemState::SET ==
129  pSet->GetItemState(FN_PARAM_3, true, &pItem))
130  aSub = static_cast<const SfxStringItem *>(pItem)->GetValue();
131 
132  if(!aFile.isEmpty() || !aSub.isEmpty())
133  {
134  OUString sLinkFileName = OUStringChar(sfx2::cTokenSeparator)
135  + OUStringChar(sfx2::cTokenSeparator);
136  sLinkFileName = comphelper::string::setToken(sLinkFileName, 0, sfx2::cTokenSeparator, aFile);
137 
138  if(SfxItemState::SET ==
139  pSet->GetItemState(FN_PARAM_2, true, &pItem))
140  {
141  sLinkFileName = comphelper::string::setToken(sLinkFileName, 1, sfx2::cTokenSeparator,
142  static_cast<const SfxStringItem *>(pItem)->GetValue());
143  }
144 
145  sLinkFileName += aSub;
146  aSection.SetType( SectionType::FileLink );
147  aSection.SetLinkFileName(sLinkFileName);
148  }
149  rSh.InsertSection(aSection, aSet.Count() ? &aSet : nullptr);
150  rReq.Done();
151  }
152 }
153 
155 {
159  RES_COL, RES_COL,
161  SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE>
162  aSet( GetView().GetPool() );
163  SwRect aRect;
164  CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
165  tools::Long nWidth = aRect.Width();
166  aSet.Put(SwFormatFrameSize(SwFrameSize::Variable, nWidth));
167  // height=width for more consistent preview (analog to edit region)
168  aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
171  GetView().GetFrameWeld(), aSet, *this));
172  aTabDlg->SetSectionData(rSectionData);
173  aTabDlg->StartExecuteAsync([aTabDlg](sal_Int32 /*nResult*/){
174  aTabDlg->disposeOnce();
175  });
176 }
177 
179 {
180  const SfxItemSet* pArgs = rReq.GetArgs();
181  sal_uInt16 nSlot = rReq.GetSlot();
182  const SfxPoolItem* pItem = nullptr;
183  if(pArgs)
184  pArgs->GetItemState(nSlot, false, &pItem);
185  SwWrtShell& rWrtShell = GetShell();
186 
187  switch ( nSlot )
188  {
189  case FN_EDIT_REGION:
191  {
192  weld::Window* pParentWin = GetView().GetFrameWeld();
193  {
195  ScopedVclPtr<AbstractEditRegionDlg> pEditRegionDlg(pFact->CreateEditRegionDlg(pParentWin, rWrtShell));
196  if(auto pStringItem = dynamic_cast< const SfxStringItem *>( pItem ))
197  {
198  pEditRegionDlg->SelectSection(pStringItem->GetValue());
199  }
200  pEditRegionDlg->Execute();
201  }
202  }
203  break;
204  }
205 }
206 
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr TypedWhichId< SvxFrameDirectionItem > RES_FRAMEDIR(120)
#define FN_PARAM_REGION_EDIT_IN_READONLY
Definition: cmdid.h:777
#define FN_EDIT_REGION
Definition: cmdid.h:108
void SetType(SectionType const eNew)
Definition: section.hxx:96
SwView & GetView()
Definition: basesh.hxx:59
void SetHidden(bool const bFlag)
Definition: section.hxx:99
SAL_DLLPRIVATE void SetProtectFlag(bool const bFlag)
Definition: section.hxx:106
void SetLinkFileName(OUString const &rNew)
Definition: section.hxx:118
std::string GetValue
constexpr TypedWhichId< SwFormatCol > RES_COL(109)
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
SwWrtShell & GetShell()
Definition: basesh.cxx:2811
long Long
const sal_Unicode cTokenSeparator
#define FN_INSERT_REGION
Definition: cmdid.h:281
SwSection const * InsertSection(SwSectionData &rNewData, SfxItemSet const *const =nullptr)
Definition: edsect.cxx:35
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:154
Used by the UI to modify the document model.
Definition: wrtsh.hxx:93
const SwView & GetView() const
Definition: wrtsh.hxx:431
#define FN_EDIT_CURRENT_REGION
Definition: cmdid.h:110
void Width(tools::Long nNew)
Definition: swrect.hxx:189
#define FN_PARAM_REGION_PROTECT
Definition: cmdid.h:776
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:115
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:774
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:108
#define FN_PARAM_REGION_NAME
Definition: cmdid.h:773
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)
constexpr sal_uInt16 XATTR_FILL_LAST(XATTR_FILLBACKGROUND)
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:969
void Ignore()
void EditRegionDialog(SfxRequest const &rReq)
Definition: regionsw.cxx:178
constexpr TypedWhichId< SwFormatFootnoteAtTextEnd > RES_FTN_AT_TXTEND(117)
#define FN_PARAM_REGION_HIDDEN
Definition: cmdid.h:775