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 
41  SfxItemSet aSet(
42  GetPool(),
43  svl::Items<
50  SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE>{});
51 
52  if (!pSet || pSet->Count()==0)
53  {
54  SwRect aRect;
55  rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
56 
57  long nWidth = aRect.Width();
58  aSet.Put(SwFormatFrameSize(SwFrameSize::Variable, nWidth));
59 
60  // height=width for more consistent preview (analog to edit region)
61  aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
64  GetView().GetFrameWeld(), aSet , rSh));
65  aTabDlg->StartExecuteAsync([aTabDlg](sal_Int32 /*nResult*/){
66  aTabDlg->disposeOnce();
67  });
68  rReq.Ignore();
69  }
70  else
71  {
72  const SfxPoolItem *pItem = nullptr;
73  OUString aTmpStr;
74  if ( SfxItemState::SET ==
75  pSet->GetItemState(FN_PARAM_REGION_NAME, true, &pItem) )
76  {
77  const OUString sRemoveWhenUniStringIsGone = static_cast<const SfxStringItem *>(pItem)->GetValue();
78  aTmpStr = rSh.GetUniqueSectionName(&sRemoveWhenUniStringIsGone);
79  }
80  else
81  aTmpStr = rSh.GetUniqueSectionName();
82 
83  SwSectionData aSection(SectionType::Content, aTmpStr);
85 
86  aSet.Put( *pSet );
87  if(SfxItemState::SET == pSet->GetItemState(SID_ATTR_COLUMNS, false, &pItem)||
88  SfxItemState::SET == pSet->GetItemState(FN_INSERT_REGION, false, &pItem))
89  {
90  SwFormatCol aCol;
91  SwRect aRect;
92  rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
93  long nWidth = aRect.Width();
94 
95  sal_uInt16 nCol = static_cast<const SfxUInt16Item *>(pItem)->GetValue();
96  if(nCol)
97  {
98  aCol.Init( nCol, 0, static_cast< sal_uInt16 >(nWidth) );
99  aSet.Put(aCol);
100  }
101  }
102  else if(SfxItemState::SET == pSet->GetItemState(RES_COL, false, &pItem))
103  {
104  aSet.Put(*pItem);
105  }
106 
107  const bool bHidden = SfxItemState::SET == pSet->GetItemState(FN_PARAM_REGION_HIDDEN, true, &pItem) &&
108  static_cast<const SfxBoolItem *>(pItem)->GetValue();
109  const bool bProtect = SfxItemState::SET == pSet->GetItemState(FN_PARAM_REGION_PROTECT, true, &pItem) &&
110  static_cast<const SfxBoolItem *>(pItem)->GetValue();
111  // #114856# edit in readonly sections
112  const bool bEditInReadonly = SfxItemState::SET == pSet->GetItemState(FN_PARAM_REGION_EDIT_IN_READONLY, true, &pItem) &&
113  static_cast<const SfxBoolItem *>(pItem)->GetValue();
114 
115  aSection.SetProtectFlag(bProtect);
116  aSection.SetHidden(bHidden);
117  // #114856# edit in readonly sections
118  aSection.SetEditInReadonlyFlag(bEditInReadonly);
119 
120  if(SfxItemState::SET ==
121  pSet->GetItemState(FN_PARAM_REGION_CONDITION, true, &pItem))
122  aSection.SetCondition(static_cast<const SfxStringItem *>(pItem)->GetValue());
123 
124  OUString aFile, aSub;
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 {
157  SfxItemSet aSet(
158  GetView().GetPool(),
159  svl::Items<
162  RES_COL, RES_COL,
164  SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE>{});
165  SwRect aRect;
166  CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
167  long nWidth = aRect.Width();
168  aSet.Put(SwFormatFrameSize(SwFrameSize::Variable, nWidth));
169  // height=width for more consistent preview (analog to edit region)
170  aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
173  GetView().GetFrameWeld(), aSet, *this));
174  aTabDlg->SetSectionData(rSectionData);
175  aTabDlg->StartExecuteAsync([aTabDlg](sal_Int32 /*nResult*/){
176  aTabDlg->disposeOnce();
177  });
178 }
179 
181 {
182  const SfxItemSet* pArgs = rReq.GetArgs();
183  sal_uInt16 nSlot = rReq.GetSlot();
184  const SfxPoolItem* pItem = nullptr;
185  if(pArgs)
186  pArgs->GetItemState(nSlot, false, &pItem);
187  SwWrtShell& rWrtShell = GetShell();
188 
189  switch ( nSlot )
190  {
191  case FN_EDIT_REGION:
193  {
194  weld::Window* pParentWin = GetView().GetFrameWeld();
195  {
197  ScopedVclPtr<AbstractEditRegionDlg> pEditRegionDlg(pFact->CreateEditRegionDlg(pParentWin, rWrtShell));
198  if(auto pStringItem = dynamic_cast< const SfxStringItem *>( pItem ))
199  {
200  pEditRegionDlg->SelectSection(pStringItem->GetValue());
201  }
202  pEditRegionDlg->Execute();
203  }
204  }
205  break;
206  }
207 }
208 
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr TypedWhichId< SvxFrameDirectionItem > RES_FRAMEDIR(120)
#define FN_PARAM_REGION_EDIT_IN_READONLY
Definition: cmdid.h:771
#define FN_EDIT_REGION
Definition: cmdid.h:108
void SetType(SectionType const eNew)
Definition: section.hxx:95
SwView & GetView()
Definition: basesh.hxx:57
void SetHidden(bool const bFlag)
Definition: section.hxx:98
SAL_DLLPRIVATE void SetProtectFlag(bool const bFlag)
Definition: section.hxx:105
void SetLinkFileName(OUString const &rNew)
Definition: section.hxx:117
std::string GetValue
constexpr TypedWhichId< SwFormatCol > RES_COL(109)
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
SwWrtShell & GetShell()
Definition: basesh.cxx:2680
const sal_Unicode cTokenSeparator
#define FN_INSERT_REGION
Definition: cmdid.h:278
SwSection const * InsertSection(SwSectionData &rNewData, SfxItemSet const *const =nullptr)
Definition: edsect.cxx:34
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:35
const SfxItemSet * GetArgs() const
void StartInsertRegionDialog(const SwSectionData &)
Definition: regionsw.cxx:155
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
const SwView & GetView() const
Definition: wrtsh.hxx:428
#define FN_EDIT_CURRENT_REGION
Definition: cmdid.h:110
#define FN_PARAM_REGION_PROTECT
Definition: cmdid.h:770
SfxItemPool & GetPool() const
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
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:114
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:690
void SetReturnValue(const SfxPoolItem &)
sal_uInt16 GetSlot() const
#define FN_PARAM_REGION_CONDITION
Definition: cmdid.h:768
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(105)
weld::Window * GetFrameWeld() const
OUString GetUniqueSectionName(const OUString *pChkStr=nullptr) const
Definition: edsect.cxx:165
void Width(long nNew)
Definition: swrect.hxx:187
void SetEditInReadonlyFlag(bool const bFlag)
Definition: section.hxx:107
#define FN_PARAM_REGION_NAME
Definition: cmdid.h:767
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.
OUString setToken(const OUString &rIn, sal_Int32 nToken, sal_Unicode cTok, const OUString &rNewToken)
void Init(sal_uInt16 nNumCols, sal_uInt16 nGutterWidth, sal_uInt16 nAct)
This function allows to (repeatedly) initialize the columns.
Definition: atrfrm.cxx:984
void Ignore()
void EditRegionDialog(SfxRequest const &rReq)
Definition: regionsw.cxx:180
constexpr TypedWhichId< SwFormatFootnoteAtTextEnd > RES_FTN_AT_TXTEND(117)
#define FN_PARAM_REGION_HIDDEN
Definition: cmdid.h:769