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>
36#include <translatehelper.hxx>
37#include <IDocumentUndoRedo.hxx>
38
40{
41 SwWrtShell& rSh = GetShell();
42 const SfxItemSet *pSet = rReq.GetArgs();
43
51 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE>
52 aSet( GetPool() );
53
54 if (!pSet || pSet->Count()==0)
55 {
56 SwRect aRect;
57 rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
58
59 tools::Long nWidth = aRect.Width();
61
62 // height=width for more consistent preview (analog to edit region)
63 aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
66 GetView().GetFrameWeld(), aSet , rSh));
67 aTabDlg->StartExecuteAsync([aTabDlg](sal_Int32 /*nResult*/){
68 aTabDlg->disposeOnce();
69 });
70 rReq.Ignore();
71 }
72 else
73 {
74 OUString aTmpStr;
75 if ( const SfxStringItem* pItem = pSet->GetItemIfSet(FN_PARAM_REGION_NAME) )
76 {
77 const OUString sRemoveWhenUniStringIsGone = 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 const SfxUInt16Item *pColRegionItem = nullptr;
88 if((pColRegionItem = pSet->GetItemIfSet(SID_ATTR_COLUMNS, false)) ||
89 (pColRegionItem = pSet->GetItemIfSet(FN_INSERT_REGION, false)))
90 {
91 SwFormatCol aCol;
92 SwRect aRect;
93 rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
94 tools::Long nWidth = aRect.Width();
95
96 sal_uInt16 nCol = pColRegionItem->GetValue();
97 if(nCol)
98 {
99 aCol.Init( nCol, 0, static_cast< sal_uInt16 >(nWidth) );
100 aSet.Put(aCol);
101 }
102 }
103 else if(const SwFormatCol* pFormatCol = pSet->GetItemIfSet(RES_COL, false))
104 {
105 aSet.Put(*pFormatCol);
106 }
107
108 const SfxBoolItem* pBoolItem;
109 const bool bHidden = (pBoolItem = pSet->GetItemIfSet(FN_PARAM_REGION_HIDDEN)) &&
110 pBoolItem->GetValue();
111 const bool bProtect = (pBoolItem = pSet->GetItemIfSet(FN_PARAM_REGION_PROTECT)) &&
112 pBoolItem->GetValue();
113 // #114856# edit in readonly sections
114 const bool bEditInReadonly = (pBoolItem = pSet->GetItemIfSet(FN_PARAM_REGION_EDIT_IN_READONLY)) &&
115 pBoolItem->GetValue();
116
117 aSection.SetProtectFlag(bProtect);
118 aSection.SetHidden(bHidden);
119 // #114856# edit in readonly sections
120 aSection.SetEditInReadonlyFlag(bEditInReadonly);
121
122 if(const SfxStringItem* pConditionItem =
124 aSection.SetCondition(pConditionItem->GetValue());
125
126 OUString aFile, aSub;
127 const SfxPoolItem* pItem;
128 if(SfxItemState::SET ==
129 pSet->GetItemState(FN_PARAM_1, true, &pItem))
130 aFile = static_cast<const SfxStringItem *>(pItem)->GetValue();
131
132 if(SfxItemState::SET ==
133 pSet->GetItemState(FN_PARAM_3, true, &pItem))
134 aSub = static_cast<const SfxStringItem *>(pItem)->GetValue();
135
136 if(!aFile.isEmpty() || !aSub.isEmpty())
137 {
138 OUString sLinkFileName = OUStringChar(sfx2::cTokenSeparator)
139 + OUStringChar(sfx2::cTokenSeparator);
140 sLinkFileName = comphelper::string::setToken(sLinkFileName, 0, sfx2::cTokenSeparator, aFile);
141
142 if(SfxItemState::SET ==
143 pSet->GetItemState(FN_PARAM_2, true, &pItem))
144 {
145 sLinkFileName = comphelper::string::setToken(sLinkFileName, 1, sfx2::cTokenSeparator,
146 static_cast<const SfxStringItem *>(pItem)->GetValue());
147 }
148
149 sLinkFileName += aSub;
150 aSection.SetType( SectionType::FileLink );
151 aSection.SetLinkFileName(sLinkFileName);
152 }
153 rSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSSECTION, nullptr);
154 rSh.StartAction();
155 rSh.InsertSection(aSection, aSet.Count() ? &aSet : nullptr);
156
157 const SfxStringItem* pSectionContent = rReq.GetArg<SfxStringItem>(FN_PARAM_4);
158 if (pSectionContent)
159 {
160 OUString aSectionContent = pSectionContent->GetValue();
161 SwPaM* pCursorPos = rSh.GetCursor();
162 pCursorPos->Move(fnMoveBackward, GoInContent);
163 // Paste HTML content.
164 SwTranslateHelper::PasteHTMLToPaM(rSh, pCursorPos, aSectionContent.toUtf8());
165 if (pCursorPos->GetPoint()->GetContentIndex() == 0)
166 {
167 // The paste created a last empty text node, remove it.
168 SwPaM aPam(*pCursorPos->GetPoint());
169 aPam.SetMark();
172 }
173 }
174 rSh.EndAction();
175 rSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSSECTION, nullptr);
176
177 rReq.Done();
178 }
179}
180
182{
188 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE>
189 aSet( GetView().GetPool() );
190 SwRect aRect;
191 CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR);
192 tools::Long nWidth = aRect.Width();
193 aSet.Put(SwFormatFrameSize(SwFrameSize::Variable, nWidth));
194 // height=width for more consistent preview (analog to edit region)
195 aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
198 GetView().GetFrameWeld(), aSet, *this));
199 aTabDlg->SetSectionData(rSectionData);
200 aTabDlg->StartExecuteAsync([aTabDlg](sal_Int32 /*nResult*/){
201 aTabDlg->disposeOnce();
202 });
203}
204
206{
207 const SfxItemSet* pArgs = rReq.GetArgs();
208 sal_uInt16 nSlot = rReq.GetSlot();
209 const SfxPoolItem* pItem = nullptr;
210 if(pArgs)
211 pArgs->GetItemState(nSlot, false, &pItem);
212 SwWrtShell& rWrtShell = GetShell();
213
214 switch ( nSlot )
215 {
216 case FN_EDIT_REGION:
218 {
219 weld::Window* pParentWin = GetView().GetFrameWeld();
220 {
222 ScopedVclPtr<AbstractEditRegionDlg> pEditRegionDlg(pFact->CreateEditRegionDlg(pParentWin, rWrtShell));
223 if(auto pStringItem = dynamic_cast< const SfxStringItem *>( pItem ))
224 {
225 pEditRegionDlg->SelectSection(pStringItem->GetValue());
226 }
227 pEditRegionDlg->Execute();
228 }
229 }
230 break;
231 }
232}
233
234/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 GetValue() const
const OUString & GetValue() const
virtual bool DeleteAndJoin(SwPaM &, SwDeleteFlags flags=SwDeleteFlags::Default)=0
complete delete of a given PaM
bool GetValue() const
sal_uInt16 Count() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
sal_uInt16 GetSlot() const
void Ignore()
const SfxItemSet * GetArgs() const
const T * GetArg(sal_uInt16 nSlotId) const
void SetReturnValue(const SfxPoolItem &)
void Done(bool bRemove=false)
SfxItemPool & GetPool() const
weld::Window * GetFrameWeld() const
virtual VclPtr< AbstractEditRegionDlg > CreateEditRegionDlg(weld::Window *pParent, SwWrtShell &rWrtSh)=0
virtual VclPtr< AbstractInsertSectionTabDialog > CreateInsertSectionTabDialog(weld::Window *pParent, const SfxItemSet &rSet, SwWrtShell &rSh)=0
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
SwWrtShell & GetShell()
Definition: basesh.cxx:3001
void EditRegionDialog(SfxRequest const &rReq)
Definition: regionsw.cxx:205
SwView & GetView()
Definition: basesh.hxx:59
void InsertRegionDialog(SfxRequest &rReq)
Definition: regionsw.cxx:39
void StartAction()
Definition: crsrsh.cxx:226
SwCursor * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:194
void EndAction(const bool bIdleEnd=false)
Definition: crsrsh.cxx:243
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:329
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:158
SwSection const * InsertSection(SwSectionData &rNewData, SfxItemSet const *const =nullptr)
Definition: edsect.cxx:35
OUString GetUniqueSectionName(const OUString *pChkStr=nullptr) const
Definition: edsect.cxx:166
void CalcBoundRect(SwRect &_orRect, const RndStdIds _nAnchorId, const sal_Int16 _eHoriRelOrient=css::text::RelOrientation::FRAME, const sal_Int16 _eVertRelOrient=css::text::RelOrientation::FRAME, const SwFormatAnchor *_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 Init(sal_uInt16 nNumCols, sal_uInt16 nGutterWidth, sal_uInt16 nAct)
This function allows to (repeatedly) initialize the columns.
Definition: atrfrm.cxx:969
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:643
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:657
const SwPosition * GetPoint() const
Definition: pam.hxx:253
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void Width(tools::Long nNew)
Definition: swrect.hxx:189
void SetHidden(bool const bFlag)
Definition: section.hxx:99
SAL_DLLPRIVATE void SetProtectFlag(bool const bFlag)
Definition: section.hxx:106
void SetEditInReadonlyFlag(bool const bFlag)
Definition: section.hxx:108
void SetType(SectionType const eNew)
Definition: section.hxx:96
void SetCondition(OUString const &rNew)
Definition: section.hxx:115
void SetLinkFileName(OUString const &rNew)
Definition: section.hxx:118
SwDoc * GetDoc() const
Definition: viewsh.hxx:308
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
void StartInsertRegionDialog(const SwSectionData &)
Definition: regionsw.cxx:181
const SwView & GetView() const
Definition: wrtsh.hxx:443
#define FN_INSERT_REGION
Definition: cmdid.h:301
#define FN_PARAM_REGION_PROTECT
Definition: cmdid.h:813
#define FN_EDIT_REGION
Definition: cmdid.h:117
#define FN_PARAM_REGION_NAME
Definition: cmdid.h:810
#define FN_EDIT_CURRENT_REGION
Definition: cmdid.h:119
#define FN_PARAM_REGION_CONDITION
Definition: cmdid.h:811
#define FN_PARAM_REGION_EDIT_IN_READONLY
Definition: cmdid.h:814
#define FN_PARAM_REGION_HIDDEN
Definition: cmdid.h:812
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:19
@ Variable
Frame is variable in Var-direction.
constexpr TypedWhichId< SvxFrameDirectionItem > RES_FRAMEDIR(126)
constexpr TypedWhichId< SwFormatFootnoteAtTextEnd > RES_FTN_AT_TXTEND(123)
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
constexpr TypedWhichId< SwFormatCol > RES_COL(115)
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(111)
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(97)
SW_DLLPUBLIC void PasteHTMLToPaM(SwWrtShell &rWrtSh, SwPaM *pCursor, const OString &rData)
OUString setToken(const OUString &rIn, sal_Int32 nToken, sal_Unicode cTok, std::u16string_view rNewToken)
const sal_Unicode cTokenSeparator
long Long
const char GetValue[]
bool GoInContent(SwPaM &rPam, SwMoveFnCollection const &fnMove)
Definition: pam.cxx:1203
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:60
sal_Int32 GetContentIndex() const
Definition: pam.hxx:85
constexpr sal_uInt16 XATTR_FILL_FIRST(XATTRSET_LINE+1)
constexpr sal_uInt16 XATTR_FILL_LAST(XATTR_FILLUSESLIDEBACKGROUND)