/src/libreoffice/sw/source/uibase/dialog/regionsw.cxx
Line | Count | Source (jump to first uncovered line) |
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 | | #include <IDocumentContentOperations.hxx> |
36 | | #include <translatehelper.hxx> |
37 | | #include <IDocumentUndoRedo.hxx> |
38 | | |
39 | | void SwBaseShell::InsertRegionDialog(SfxRequest& rReq) |
40 | 0 | { |
41 | 0 | SwWrtShell& rSh = GetShell(); |
42 | 0 | const SfxItemSet *pSet = rReq.GetArgs(); |
43 | |
|
44 | 0 | SfxItemSetFixed< |
45 | 0 | RES_FRM_SIZE, RES_FRM_SIZE, |
46 | 0 | RES_LR_SPACE, RES_LR_SPACE, |
47 | 0 | RES_BACKGROUND, RES_BACKGROUND, |
48 | 0 | RES_COL, RES_COL, |
49 | 0 | RES_FTN_AT_TXTEND, RES_FRAMEDIR, |
50 | 0 | XATTR_FILL_FIRST, XATTR_FILL_LAST, |
51 | 0 | SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE> |
52 | 0 | aSet( GetPool() ); |
53 | |
|
54 | 0 | if (!pSet || pSet->Count()==0) |
55 | 0 | { |
56 | 0 | SwRect aRect; |
57 | 0 | rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR); |
58 | |
|
59 | 0 | tools::Long nWidth = aRect.Width(); |
60 | 0 | aSet.Put(SwFormatFrameSize(SwFrameSize::Variable, nWidth)); |
61 | | |
62 | | // height=width for more consistent preview (analog to edit region) |
63 | 0 | aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth))); |
64 | 0 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); |
65 | 0 | VclPtr<AbstractInsertSectionTabDialog> aTabDlg(pFact->CreateInsertSectionTabDialog( |
66 | 0 | GetView().GetFrameWeld(), aSet , rSh)); |
67 | 0 | aTabDlg->StartExecuteAsync([aTabDlg](sal_Int32 /*nResult*/){ |
68 | 0 | aTabDlg->disposeOnce(); |
69 | 0 | }); |
70 | 0 | rReq.Ignore(); |
71 | 0 | } |
72 | 0 | else |
73 | 0 | { |
74 | 0 | OUString aTmpStr; |
75 | 0 | if ( const SfxStringItem* pItem = pSet->GetItemIfSet(FN_PARAM_REGION_NAME) ) |
76 | 0 | { |
77 | 0 | const OUString sRemoveWhenUniStringIsGone = pItem->GetValue(); |
78 | 0 | aTmpStr = rSh.GetUniqueSectionName(&sRemoveWhenUniStringIsGone); |
79 | 0 | } |
80 | 0 | else |
81 | 0 | aTmpStr = rSh.GetUniqueSectionName(); |
82 | |
|
83 | 0 | SwSectionData aSection(SectionType::Content, UIName(aTmpStr)); |
84 | 0 | rReq.SetReturnValue(SfxStringItem(FN_INSERT_REGION, aTmpStr)); |
85 | |
|
86 | 0 | aSet.Put( *pSet ); |
87 | 0 | const SfxUInt16Item *pColRegionItem = nullptr; |
88 | 0 | if((pColRegionItem = pSet->GetItemIfSet(SID_ATTR_COLUMNS, false)) || |
89 | 0 | (pColRegionItem = pSet->GetItemIfSet(FN_INSERT_REGION, false))) |
90 | 0 | { |
91 | 0 | SwFormatCol aCol; |
92 | 0 | SwRect aRect; |
93 | 0 | rSh.CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR); |
94 | 0 | tools::Long nWidth = aRect.Width(); |
95 | |
|
96 | 0 | sal_uInt16 nCol = pColRegionItem->GetValue(); |
97 | 0 | if(nCol) |
98 | 0 | { |
99 | 0 | aCol.Init( nCol, 0, static_cast< sal_uInt16 >(nWidth) ); |
100 | 0 | aSet.Put(aCol); |
101 | 0 | } |
102 | 0 | } |
103 | 0 | else if(const SwFormatCol* pFormatCol = pSet->GetItemIfSet(RES_COL, false)) |
104 | 0 | { |
105 | 0 | aSet.Put(*pFormatCol); |
106 | 0 | } |
107 | |
|
108 | 0 | const SfxBoolItem* pBoolItem; |
109 | 0 | const bool bHidden = (pBoolItem = pSet->GetItemIfSet(FN_PARAM_REGION_HIDDEN)) && |
110 | 0 | pBoolItem->GetValue(); |
111 | 0 | const bool bProtect = (pBoolItem = pSet->GetItemIfSet(FN_PARAM_REGION_PROTECT)) && |
112 | 0 | pBoolItem->GetValue(); |
113 | | // #114856# edit in readonly sections |
114 | 0 | const bool bEditInReadonly = (pBoolItem = pSet->GetItemIfSet(FN_PARAM_REGION_EDIT_IN_READONLY)) && |
115 | 0 | pBoolItem->GetValue(); |
116 | |
|
117 | 0 | aSection.SetProtectFlag(bProtect); |
118 | 0 | aSection.SetHidden(bHidden); |
119 | | // #114856# edit in readonly sections |
120 | 0 | aSection.SetEditInReadonlyFlag(bEditInReadonly); |
121 | |
|
122 | 0 | if(const SfxStringItem* pConditionItem = |
123 | 0 | pSet->GetItemIfSet(FN_PARAM_REGION_CONDITION)) |
124 | 0 | aSection.SetCondition(pConditionItem->GetValue()); |
125 | |
|
126 | 0 | OUString aFile, aSub; |
127 | 0 | const SfxPoolItem* pItem; |
128 | 0 | if(SfxItemState::SET == |
129 | 0 | pSet->GetItemState(FN_PARAM_1, true, &pItem)) |
130 | 0 | aFile = static_cast<const SfxStringItem *>(pItem)->GetValue(); |
131 | |
|
132 | 0 | if(SfxItemState::SET == |
133 | 0 | pSet->GetItemState(FN_PARAM_3, true, &pItem)) |
134 | 0 | aSub = static_cast<const SfxStringItem *>(pItem)->GetValue(); |
135 | |
|
136 | 0 | if(!aFile.isEmpty() || !aSub.isEmpty()) |
137 | 0 | { |
138 | 0 | OUString sLinkFileName = OUStringChar(sfx2::cTokenSeparator) |
139 | 0 | + OUStringChar(sfx2::cTokenSeparator); |
140 | 0 | sLinkFileName = comphelper::string::setToken(sLinkFileName, 0, sfx2::cTokenSeparator, aFile); |
141 | |
|
142 | 0 | if(SfxItemState::SET == |
143 | 0 | pSet->GetItemState(FN_PARAM_2, true, &pItem)) |
144 | 0 | { |
145 | 0 | sLinkFileName = comphelper::string::setToken(sLinkFileName, 1, sfx2::cTokenSeparator, |
146 | 0 | static_cast<const SfxStringItem *>(pItem)->GetValue()); |
147 | 0 | } |
148 | |
|
149 | 0 | sLinkFileName += aSub; |
150 | 0 | aSection.SetType( SectionType::FileLink ); |
151 | 0 | aSection.SetLinkFileName(sLinkFileName); |
152 | 0 | } |
153 | 0 | rSh.GetDoc()->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSSECTION, nullptr); |
154 | 0 | rSh.StartAction(); |
155 | 0 | rSh.InsertSection(aSection, aSet.Count() ? &aSet : nullptr); |
156 | |
|
157 | 0 | const SfxStringItem* pSectionContent = rReq.GetArg<SfxStringItem>(FN_PARAM_4); |
158 | 0 | if (pSectionContent) |
159 | 0 | { |
160 | 0 | OUString aSectionContent = pSectionContent->GetValue(); |
161 | 0 | SwPaM* pCursorPos = rSh.GetCursor(); |
162 | 0 | pCursorPos->Move(fnMoveBackward, GoInContent); |
163 | | // Paste HTML content. |
164 | 0 | SwTranslateHelper::PasteHTMLToPaM(rSh, pCursorPos, aSectionContent.toUtf8()); |
165 | 0 | if (pCursorPos->GetPoint()->GetContentIndex() == 0) |
166 | 0 | { |
167 | | // The paste created a last empty text node, remove it. |
168 | 0 | SwPaM aPam(*pCursorPos->GetPoint()); |
169 | 0 | aPam.SetMark(); |
170 | 0 | aPam.Move(fnMoveBackward, GoInContent); |
171 | 0 | rSh.GetDoc()->getIDocumentContentOperations().DeleteAndJoin(aPam); |
172 | 0 | } |
173 | 0 | } |
174 | 0 | rSh.EndAction(); |
175 | 0 | rSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSSECTION, nullptr); |
176 | |
|
177 | 0 | rReq.Done(); |
178 | 0 | } |
179 | 0 | } |
180 | | |
181 | | void SwWrtShell::StartInsertRegionDialog(const SwSectionData& rSectionData) |
182 | 0 | { |
183 | 0 | SfxItemSetFixed< |
184 | 0 | RES_FRM_SIZE, RES_FRM_SIZE, |
185 | 0 | RES_BACKGROUND, RES_BACKGROUND, |
186 | 0 | RES_COL, RES_COL, |
187 | 0 | XATTR_FILL_FIRST, XATTR_FILL_LAST, |
188 | 0 | SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE> |
189 | 0 | aSet( GetView().GetPool() ); |
190 | 0 | SwRect aRect; |
191 | 0 | CalcBoundRect(aRect, RndStdIds::FLY_AS_CHAR); |
192 | 0 | tools::Long nWidth = aRect.Width(); |
193 | 0 | aSet.Put(SwFormatFrameSize(SwFrameSize::Variable, nWidth)); |
194 | | // height=width for more consistent preview (analog to edit region) |
195 | 0 | aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth))); |
196 | 0 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); |
197 | 0 | VclPtr<AbstractInsertSectionTabDialog> aTabDlg(pFact->CreateInsertSectionTabDialog( |
198 | 0 | GetView().GetFrameWeld(), aSet, *this)); |
199 | 0 | aTabDlg->SetSectionData(rSectionData); |
200 | 0 | aTabDlg->StartExecuteAsync([aTabDlg](sal_Int32 /*nResult*/){ |
201 | 0 | aTabDlg->disposeOnce(); |
202 | 0 | }); |
203 | 0 | } |
204 | | |
205 | | void SwBaseShell::EditRegionDialog(SfxRequest const & rReq) |
206 | 0 | { |
207 | 0 | const SfxItemSet* pArgs = rReq.GetArgs(); |
208 | 0 | sal_uInt16 nSlot = rReq.GetSlot(); |
209 | 0 | const SfxPoolItem* pItem = nullptr; |
210 | 0 | if(pArgs) |
211 | 0 | pArgs->GetItemState(nSlot, false, &pItem); |
212 | 0 | SwWrtShell& rWrtShell = GetShell(); |
213 | |
|
214 | 0 | switch ( nSlot ) |
215 | 0 | { |
216 | 0 | case FN_EDIT_REGION: |
217 | 0 | case FN_EDIT_CURRENT_REGION: |
218 | 0 | { |
219 | 0 | weld::Window* pParentWin = GetView().GetFrameWeld(); |
220 | |
|
221 | 0 | SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); |
222 | 0 | VclPtr<AbstractEditRegionDlg> pEditRegionDlg(pFact->CreateEditRegionDlg(pParentWin, rWrtShell)); |
223 | |
|
224 | 0 | if(auto pStringItem = dynamic_cast< const SfxStringItem *>( pItem )) |
225 | 0 | { |
226 | 0 | pEditRegionDlg->SelectSection(pStringItem->GetValue()); |
227 | 0 | } |
228 | 0 | pEditRegionDlg->StartExecuteAsync([pEditRegionDlg](sal_Int32 /*nResult */){ |
229 | 0 | pEditRegionDlg->disposeOnce(); |
230 | 0 | }); |
231 | 0 | } |
232 | 0 | break; |
233 | 0 | } |
234 | 0 | } |
235 | | |
236 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |