1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
31 #include <fmtclds.hxx>
32 #include <fmtfsize.hxx>
34 #include <swabstdlg.hxx>
35 #include <IDocumentContentOperations.hxx>
36 #include <translatehelper.hxx>
37 #include <IDocumentUndoRedo.hxx>
39 void SwBaseShell::InsertRegionDialog(SfxRequest
& rReq
)
41 SwWrtShell
& rSh
= GetShell();
42 const SfxItemSet
*pSet
= rReq
.GetArgs();
45 RES_FRM_SIZE
, RES_FRM_SIZE
,
46 RES_LR_SPACE
, RES_LR_SPACE
,
47 RES_BACKGROUND
, RES_BACKGROUND
,
49 RES_FTN_AT_TXTEND
, RES_FRAMEDIR
,
50 XATTR_FILL_FIRST
, XATTR_FILL_LAST
,
51 SID_ATTR_PAGE_SIZE
, SID_ATTR_PAGE_SIZE
>
54 if (!pSet
|| pSet
->Count()==0)
57 rSh
.CalcBoundRect(aRect
, RndStdIds::FLY_AS_CHAR
);
59 tools::Long nWidth
= aRect
.Width();
60 aSet
.Put(SwFormatFrameSize(SwFrameSize::Variable
, nWidth
));
62 // height=width for more consistent preview (analog to edit region)
63 aSet
.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE
, Size(nWidth
, nWidth
)));
64 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
65 VclPtr
<AbstractInsertSectionTabDialog
> aTabDlg(pFact
->CreateInsertSectionTabDialog(
66 GetView().GetFrameWeld(), aSet
, rSh
));
67 aTabDlg
->StartExecuteAsync([aTabDlg
](sal_Int32
/*nResult*/){
68 aTabDlg
->disposeOnce();
75 if ( const SfxStringItem
* pItem
= pSet
->GetItemIfSet(FN_PARAM_REGION_NAME
) )
77 const OUString sRemoveWhenUniStringIsGone
= pItem
->GetValue();
78 aTmpStr
= rSh
.GetUniqueSectionName(&sRemoveWhenUniStringIsGone
);
81 aTmpStr
= rSh
.GetUniqueSectionName();
83 SwSectionData
aSection(SectionType::Content
, aTmpStr
);
84 rReq
.SetReturnValue(SfxStringItem(FN_INSERT_REGION
, aTmpStr
));
87 const SfxUInt16Item
*pColRegionItem
= nullptr;
88 if((pColRegionItem
= pSet
->GetItemIfSet(SID_ATTR_COLUMNS
, false)) ||
89 (pColRegionItem
= pSet
->GetItemIfSet(FN_INSERT_REGION
, false)))
93 rSh
.CalcBoundRect(aRect
, RndStdIds::FLY_AS_CHAR
);
94 tools::Long nWidth
= aRect
.Width();
96 sal_uInt16 nCol
= pColRegionItem
->GetValue();
99 aCol
.Init( nCol
, 0, static_cast< sal_uInt16
>(nWidth
) );
103 else if(const SwFormatCol
* pFormatCol
= pSet
->GetItemIfSet(RES_COL
, false))
105 aSet
.Put(*pFormatCol
);
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();
117 aSection
.SetProtectFlag(bProtect
);
118 aSection
.SetHidden(bHidden
);
119 // #114856# edit in readonly sections
120 aSection
.SetEditInReadonlyFlag(bEditInReadonly
);
122 if(const SfxStringItem
* pConditionItem
=
123 pSet
->GetItemIfSet(FN_PARAM_REGION_CONDITION
))
124 aSection
.SetCondition(pConditionItem
->GetValue());
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();
132 if(SfxItemState::SET
==
133 pSet
->GetItemState(FN_PARAM_3
, true, &pItem
))
134 aSub
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
136 if(!aFile
.isEmpty() || !aSub
.isEmpty())
138 OUString sLinkFileName
= OUStringChar(sfx2::cTokenSeparator
)
139 + OUStringChar(sfx2::cTokenSeparator
);
140 sLinkFileName
= comphelper::string::setToken(sLinkFileName
, 0, sfx2::cTokenSeparator
, aFile
);
142 if(SfxItemState::SET
==
143 pSet
->GetItemState(FN_PARAM_2
, true, &pItem
))
145 sLinkFileName
= comphelper::string::setToken(sLinkFileName
, 1, sfx2::cTokenSeparator
,
146 static_cast<const SfxStringItem
*>(pItem
)->GetValue());
149 sLinkFileName
+= aSub
;
150 aSection
.SetType( SectionType::FileLink
);
151 aSection
.SetLinkFileName(sLinkFileName
);
153 rSh
.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSSECTION
, nullptr);
155 rSh
.InsertSection(aSection
, aSet
.Count() ? &aSet
: nullptr);
157 const SfxStringItem
* pSectionContent
= rReq
.GetArg
<SfxStringItem
>(FN_PARAM_4
);
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 /*bSetSelection=*/true);
166 if (pCursorPos
->GetPoint()->GetContentIndex() == 0)
168 // The paste created a last empty text node, remove it.
169 SwPaM
aPam(*pCursorPos
->GetPoint());
171 aPam
.Move(fnMoveBackward
, GoInContent
);
172 rSh
.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(aPam
);
176 rSh
.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSSECTION
, nullptr);
182 void SwWrtShell::StartInsertRegionDialog(const SwSectionData
& rSectionData
)
185 RES_FRM_SIZE
, RES_FRM_SIZE
,
186 RES_BACKGROUND
, RES_BACKGROUND
,
188 XATTR_FILL_FIRST
, XATTR_FILL_LAST
,
189 SID_ATTR_PAGE_SIZE
, SID_ATTR_PAGE_SIZE
>
190 aSet( GetView().GetPool() );
192 CalcBoundRect(aRect
, RndStdIds::FLY_AS_CHAR
);
193 tools::Long nWidth
= aRect
.Width();
194 aSet
.Put(SwFormatFrameSize(SwFrameSize::Variable
, nWidth
));
195 // height=width for more consistent preview (analog to edit region)
196 aSet
.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE
, Size(nWidth
, nWidth
)));
197 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
198 VclPtr
<AbstractInsertSectionTabDialog
> aTabDlg(pFact
->CreateInsertSectionTabDialog(
199 GetView().GetFrameWeld(), aSet
, *this));
200 aTabDlg
->SetSectionData(rSectionData
);
201 aTabDlg
->StartExecuteAsync([aTabDlg
](sal_Int32
/*nResult*/){
202 aTabDlg
->disposeOnce();
206 void SwBaseShell::EditRegionDialog(SfxRequest
const & rReq
)
208 const SfxItemSet
* pArgs
= rReq
.GetArgs();
209 sal_uInt16 nSlot
= rReq
.GetSlot();
210 const SfxPoolItem
* pItem
= nullptr;
212 pArgs
->GetItemState(nSlot
, false, &pItem
);
213 SwWrtShell
& rWrtShell
= GetShell();
218 case FN_EDIT_CURRENT_REGION
:
220 weld::Window
* pParentWin
= GetView().GetFrameWeld();
222 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
223 ScopedVclPtr
<AbstractEditRegionDlg
> pEditRegionDlg(pFact
->CreateEditRegionDlg(pParentWin
, rWrtShell
));
224 if(auto pStringItem
= dynamic_cast< const SfxStringItem
*>( pItem
))
226 pEditRegionDlg
->SelectSection(pStringItem
->GetValue());
228 pEditRegionDlg
->Execute();
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */