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 <uitool.hxx>
22 #include <comphelper/string.hxx>
23 #include <svl/urihelper.hxx>
24 #include <svl/PasswordHelper.hxx>
25 #include <svl/stritem.hxx>
26 #include <svl/eitem.hxx>
27 #include <sot/formats.hxx>
28 #include <sfx2/passwd.hxx>
29 #include <sfx2/docfilt.hxx>
30 #include <sfx2/request.hxx>
31 #include <sfx2/docfile.hxx>
32 #include <sfx2/linkmgr.hxx>
33 #include <svx/svxids.hrc>
34 #include <editeng/sizeitem.hxx>
35 #include <svtools/htmlcfg.hxx>
36 #include <section.hxx>
37 #include <docary.hxx>
38 #include <regionsw.hxx>
39 #include <basesh.hxx>
40 #include <wdocsh.hxx>
41 #include <view.hxx>
42 #include <swmodule.hxx>
43 #include <wrtsh.hxx>
44 #include <swundo.hxx>
45 #include <column.hxx>
46 #include <fmtfsize.hxx>
47 #include <shellio.hxx>
48 #include <cmdid.h>
49 #include <globals.hrc>
50 #include <sfx2/bindings.hxx>
51 #include <sfx2/htmlmode.hxx>
52 #include <sfx2/viewfrm.hxx>
53 #include <svx/dlgutil.hxx>
54 #include <swabstdlg.hxx>
55 #include <memory>
56 
58 {
59  SwWrtShell& rSh = GetShell();
60  const SfxItemSet *pSet = rReq.GetArgs();
61 
62  SfxItemSet aSet(
63  GetPool(),
64  svl::Items<
71  SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE>{});
72 
73  if (!pSet || pSet->Count()==0)
74  {
75  SwRect aRect;
76  rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
77 
78  long nWidth = aRect.Width();
79  aSet.Put(SwFormatFrameSize(ATT_VAR_SIZE, nWidth));
80 
81  // height=width for more consistent preview (analog to edit region)
82  aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
85  GetView().GetViewFrame()->GetWindow().GetFrameWeld(), aSet , rSh));
86  aTabDlg->StartExecuteAsync([aTabDlg](sal_Int32 /*nResult*/){
87  aTabDlg->disposeOnce();
88  });
89  rReq.Ignore();
90  }
91  else
92  {
93  const SfxPoolItem *pItem = nullptr;
94  OUString aTmpStr;
95  if ( SfxItemState::SET ==
96  pSet->GetItemState(FN_PARAM_REGION_NAME, true, &pItem) )
97  {
98  const OUString sRemoveWhenUniStringIsGone = static_cast<const SfxStringItem *>(pItem)->GetValue();
99  aTmpStr = rSh.GetUniqueSectionName(&sRemoveWhenUniStringIsGone);
100  }
101  else
102  aTmpStr = rSh.GetUniqueSectionName();
103 
104  SwSectionData aSection(CONTENT_SECTION, aTmpStr);
106 
107  aSet.Put( *pSet );
108  if(SfxItemState::SET == pSet->GetItemState(SID_ATTR_COLUMNS, false, &pItem)||
109  SfxItemState::SET == pSet->GetItemState(FN_INSERT_REGION, false, &pItem))
110  {
111  SwFormatCol aCol;
112  SwRect aRect;
113  rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
114  long nWidth = aRect.Width();
115 
116  sal_uInt16 nCol = static_cast<const SfxUInt16Item *>(pItem)->GetValue();
117  if(nCol)
118  {
119  aCol.Init( nCol, 0, static_cast< sal_uInt16 >(nWidth) );
120  aSet.Put(aCol);
121  }
122  }
123  else if(SfxItemState::SET == pSet->GetItemState(RES_COL, false, &pItem))
124  {
125  aSet.Put(*pItem);
126  }
127 
128  const bool bHidden = SfxItemState::SET == pSet->GetItemState(FN_PARAM_REGION_HIDDEN, true, &pItem) &&
129  static_cast<const SfxBoolItem *>(pItem)->GetValue();
130  const bool bProtect = SfxItemState::SET == pSet->GetItemState(FN_PARAM_REGION_PROTECT, true, &pItem) &&
131  static_cast<const SfxBoolItem *>(pItem)->GetValue();
132  // #114856# edit in readonly sections
133  const bool bEditInReadonly = SfxItemState::SET == pSet->GetItemState(FN_PARAM_REGION_EDIT_IN_READONLY, true, &pItem) &&
134  static_cast<const SfxBoolItem *>(pItem)->GetValue();
135 
136  aSection.SetProtectFlag(bProtect);
137  aSection.SetHidden(bHidden);
138  // #114856# edit in readonly sections
139  aSection.SetEditInReadonlyFlag(bEditInReadonly);
140 
141  if(SfxItemState::SET ==
142  pSet->GetItemState(FN_PARAM_REGION_CONDITION, true, &pItem))
143  aSection.SetCondition(static_cast<const SfxStringItem *>(pItem)->GetValue());
144 
145  OUString aFile, aSub;
146  if(SfxItemState::SET ==
147  pSet->GetItemState(FN_PARAM_1, true, &pItem))
148  aFile = static_cast<const SfxStringItem *>(pItem)->GetValue();
149 
150  if(SfxItemState::SET ==
151  pSet->GetItemState(FN_PARAM_3, true, &pItem))
152  aSub = static_cast<const SfxStringItem *>(pItem)->GetValue();
153 
154  if(!aFile.isEmpty() || !aSub.isEmpty())
155  {
156  OUString sLinkFileName = OUStringLiteral1(sfx2::cTokenSeparator)
157  + OUStringLiteral1(sfx2::cTokenSeparator);
158  sLinkFileName = comphelper::string::setToken(sLinkFileName, 0, sfx2::cTokenSeparator, aFile);
159 
160  if(SfxItemState::SET ==
161  pSet->GetItemState(FN_PARAM_2, true, &pItem))
162  {
163  sLinkFileName = comphelper::string::setToken(sLinkFileName, 1, sfx2::cTokenSeparator,
164  static_cast<const SfxStringItem *>(pItem)->GetValue());
165  }
166 
167  sLinkFileName += aSub;
168  aSection.SetType( FILE_LINK_SECTION );
169  aSection.SetLinkFileName(sLinkFileName);
170  }
171  rSh.InsertSection(aSection, aSet.Count() ? &aSet : nullptr);
172  rReq.Done();
173  }
174 }
175 
177 {
178  SfxItemSet aSet(
179  GetView().GetPool(),
180  svl::Items<
183  RES_COL, RES_COL,
185  SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE>{});
186  SwRect aRect;
187  CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
188  long nWidth = aRect.Width();
189  aSet.Put(SwFormatFrameSize(ATT_VAR_SIZE, nWidth));
190  // height=width for more consistent preview (analog to edit region)
191  aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
194  GetView().GetViewFrame()->GetWindow().GetFrameWeld(), aSet, *this));
195  aTabDlg->SetSectionData(rSectionData);
196  aTabDlg->StartExecuteAsync([aTabDlg](sal_Int32 /*nResult*/){
197  aTabDlg->disposeOnce();
198  });
199 }
200 
202 {
203  const SfxItemSet* pArgs = rReq.GetArgs();
204  sal_uInt16 nSlot = rReq.GetSlot();
205  const SfxPoolItem* pItem = nullptr;
206  if(pArgs)
207  pArgs->GetItemState(nSlot, false, &pItem);
208  SwWrtShell& rWrtShell = GetShell();
209 
210  switch ( nSlot )
211  {
212  case FN_EDIT_REGION:
214  {
215  weld::Window* pParentWin = GetView().GetViewFrame()->GetWindow().GetFrameWeld();
216  {
218  ScopedVclPtr<AbstractEditRegionDlg> pEditRegionDlg(pFact->CreateEditRegionDlg(pParentWin, rWrtShell));
219  if(auto pStringItem = dynamic_cast< const SfxStringItem *>( pItem ))
220  {
221  pEditRegionDlg->SelectSection(pStringItem->GetValue());
222  }
223  pEditRegionDlg->Execute();
224  }
225  }
226  break;
227  }
228 }
229 
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
#define RES_FTN_AT_TXTEND
Definition: hintids.hxx:222
#define RES_FRM_SIZE
Definition: hintids.hxx:194
#define FN_PARAM_REGION_EDIT_IN_READONLY
Definition: cmdid.h:748
#define RES_COL
Definition: hintids.hxx:214
#define FN_EDIT_REGION
Definition: cmdid.h:107
void SetType(SectionType const eNew)
Definition: section.hxx:96
SwView & GetView()
Definition: basesh.hxx:57
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
SwWrtShell & GetShell()
Definition: basesh.cxx:2623
#define RES_FRAMEDIR
Definition: hintids.hxx:225
const sal_Unicode cTokenSeparator
#define FN_INSERT_REGION
Definition: cmdid.h:269
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:176
Used by the UI to modify the document model.
Definition: wrtsh.hxx:88
weld::Window * GetFrameWeld() const
vcl::Window & GetWindow() const
const SwView & GetView() const
Definition: wrtsh.hxx:426
#define XATTR_FILL_LAST
#define FN_EDIT_CURRENT_REGION
Definition: cmdid.h:109
#define XATTR_FILL_FIRST
#define FN_PARAM_REGION_PROTECT
Definition: cmdid.h:747
SfxItemPool & GetPool() const
#define RES_BACKGROUND
Definition: hintids.hxx:210
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
sal_uInt16 Count() const
weld::Window * GetFrameWeld(SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
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:730
#define RES_LR_SPACE
Definition: hintids.hxx:196
void SetReturnValue(const SfxPoolItem &)
sal_uInt16 GetSlot() const
#define FN_PARAM_REGION_CONDITION
Definition: cmdid.h:745
OUString GetUniqueSectionName(const OUString *pChkStr=nullptr) const
Definition: edsect.cxx:166
void Width(long nNew)
Definition: swrect.hxx:185
void SetEditInReadonlyFlag(bool const bFlag)
Definition: section.hxx:108
#define FN_PARAM_REGION_NAME
Definition: cmdid.h:744
void InsertRegionDialog(SfxRequest &rReq)
Definition: regionsw.cxx:57
virtual VclPtr< AbstractEditRegionDlg > CreateEditRegionDlg(weld::Window *pParent, SwWrtShell &rWrtSh)=0
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:947
void Ignore()
Frame is variable in Var-direction.
Definition: fmtfsize.hxx:37
void EditRegionDialog(SfxRequest const &rReq)
Definition: regionsw.cxx:201
#define FN_PARAM_REGION_HIDDEN
Definition: cmdid.h:746