Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / shells / drawdlg.cxx
blobec93f35029b04592aa2ee6cd1bf5c6d9b3b9a499
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <sfx2/request.hxx>
21 #include <sfx2/dispatch.hxx>
22 #include <sfx2/viewfrm.hxx>
23 #include <svx/svdview.hxx>
25 #include <view.hxx>
26 #include <wrtsh.hxx>
27 #include <cmdid.h>
29 #include <drawsh.hxx>
30 #include <svx/svxdlg.hxx>
31 #include <svx/dialogs.hrc>
32 #include <memory>
33 #include <svl/stritem.hxx>
34 #include <svx/xlnclit.hxx>
35 #include <svx/xflclit.hxx>
36 #include <svx/chrtitem.hxx>
37 #include <svx/xlnwtit.hxx>
38 #include <svx/xflgrit.hxx>
39 #include <svx/xflftrit.hxx>
40 #include <svx/xfltrit.hxx>
41 #include <comphelper/lok.hxx>
42 #include <textboxhelper.hxx>
44 using namespace com::sun::star::drawing;
46 void SwDrawShell::ExecDrawDlg(SfxRequest& rReq)
48 SwWrtShell* pSh = &GetShell();
49 SdrView* pView = pSh->GetDrawView();
50 SdrModel& rModel = pView->GetModel();
51 bool bChanged = rModel.IsChanged();
52 rModel.SetChanged(false);
54 SfxItemSet aNewAttr(rModel.GetItemPool());
55 pView->GetAttributes( aNewAttr );
57 GetView().NoRotate();
59 switch (rReq.GetSlot())
61 case FN_DRAWTEXT_ATTR_DLG:
63 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
64 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateTextTabDialog(rReq.GetFrameWeld(), &aNewAttr, pView));
65 sal_uInt16 nResult = pDlg->Execute();
67 if (nResult == RET_OK)
69 if (pView->AreObjectsMarked())
71 pSh->StartAction();
72 pView->SetAttributes(*pDlg->GetOutputItemSet());
73 auto vMarkedObjs = pView->GetMarkedObjects();
74 for (auto pObj : vMarkedObjs)
76 // If the shape has textframe, set its params as well.
77 if (SwTextBoxHelper::hasTextFrame(pObj))
78 SwTextBoxHelper::updateTextBoxMargin(pObj);
80 rReq.Done(*(pDlg->GetOutputItemSet()));
81 pSh->EndAction();
85 break;
87 case SID_MEASURE_DLG:
89 bool bHasMarked = pView->AreObjectsMarked();
91 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
92 ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog(rReq.GetFrameWeld(),
93 aNewAttr, pView, RID_SVXPAGE_MEASURE));
94 if (pDlg->Execute() == RET_OK)
96 pSh->StartAction();
97 if (bHasMarked)
98 pView->SetAttrToMarked(*pDlg->GetOutputItemSet(), false);
99 else
100 pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
101 pSh->EndAction();
104 break;
106 case SID_ATTRIBUTES_AREA:
108 bool bHasMarked = pView->AreObjectsMarked();
110 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
111 VclPtr<AbstractSvxAreaTabDialog> pDlg(pFact->CreateSvxAreaTabDialog(rReq.GetFrameWeld(),
112 &aNewAttr,
113 &rModel,
114 true,
115 false));
117 pDlg->StartExecuteAsync([bChanged, bHasMarked, &rModel, pDlg, pSh, pView, this](
118 sal_Int32 nResult){
119 rModel.SetChanged(false);
121 if (nResult == RET_OK)
123 pSh->StartAction();
124 if (bHasMarked)
125 pView->SetAttributes(*pDlg->GetOutputItemSet());
126 else
127 pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
128 pSh->EndAction();
130 static sal_uInt16 aInval[] =
132 SID_ATTR_FILL_STYLE,
133 SID_ATTR_FILL_COLOR,
134 SID_ATTR_FILL_TRANSPARENCE,
135 SID_ATTR_FILL_FLOATTRANSPARENCE,
138 SfxBindings &rBnd = GetView().GetViewFrame().GetBindings();
139 rBnd.Invalidate(aInval);
140 rBnd.Update(SID_ATTR_FILL_STYLE);
141 rBnd.Update(SID_ATTR_FILL_COLOR);
142 rBnd.Update(SID_ATTR_FILL_TRANSPARENCE);
143 rBnd.Update(SID_ATTR_FILL_FLOATTRANSPARENCE);
146 if (rModel.IsChanged())
147 GetShell().SetModified();
148 else if (bChanged)
149 rModel.SetChanged();
151 pDlg->disposeOnce();
154 break;
156 case SID_ATTRIBUTES_LINE:
158 bool bHasMarked = pView->AreObjectsMarked();
160 const SdrObject* pObj = nullptr;
161 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
162 if( rMarkList.GetMarkCount() == 1 )
163 pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
165 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
166 VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSvxLineTabDialog(rReq.GetFrameWeld(),
167 &aNewAttr,
168 &rModel,
169 pObj,
170 bHasMarked));
172 pDlg->StartExecuteAsync([bChanged, bHasMarked, &rModel, pDlg, pSh, pView, this](
173 sal_Int32 nResult){
174 rModel.SetChanged(false);
176 if (nResult == RET_OK)
178 pSh->StartAction();
179 if(bHasMarked)
180 pView->SetAttrToMarked(*pDlg->GetOutputItemSet(), false);
181 else
182 pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
183 pSh->EndAction();
185 static sal_uInt16 aInval[] =
187 SID_ATTR_LINE_STYLE, // ( SID_SVX_START + 169 )
188 SID_ATTR_LINE_DASH, // ( SID_SVX_START + 170 )
189 SID_ATTR_LINE_WIDTH, // ( SID_SVX_START + 171 )
190 SID_ATTR_LINE_COLOR, // ( SID_SVX_START + 172 )
191 SID_ATTR_LINE_START, // ( SID_SVX_START + 173 )
192 SID_ATTR_LINE_END, // ( SID_SVX_START + 174 )
193 SID_ATTR_LINE_TRANSPARENCE, // (SID_SVX_START+1107)
194 SID_ATTR_LINE_JOINT, // (SID_SVX_START+1110)
195 SID_ATTR_LINE_CAP, // (SID_SVX_START+1111)
199 GetView().GetViewFrame().GetBindings().Invalidate(aInval);
202 if (rModel.IsChanged())
203 GetShell().SetModified();
204 else if (bChanged)
205 rModel.SetChanged();
207 pDlg->disposeOnce();
210 break;
212 default:
213 break;
216 if (rModel.IsChanged())
217 GetShell().SetModified();
218 else if (bChanged)
219 rModel.SetChanged();
222 namespace
224 void lcl_convertStringArguments(const std::unique_ptr<SfxItemSet>& pArgs)
226 if (const SvxDoubleItem* pWidthItem = pArgs->GetItemIfSet(SID_ATTR_LINE_WIDTH_ARG, false))
228 double fValue = pWidthItem->GetValue();
229 // FIXME: different units...
230 int nPow = 100;
231 int nValue = fValue * nPow;
233 XLineWidthItem aItem(nValue);
234 pArgs->Put(aItem);
236 if (const SfxStringItem* pJSON = pArgs->GetItemIfSet(SID_FILL_GRADIENT_JSON, false))
238 basegfx::BGradient aGradient = basegfx::BGradient::fromJSON(pJSON->GetValue());
239 XFillGradientItem aItem(aGradient);
240 pArgs->Put(aItem);
245 void SwDrawShell::ExecDrawAttrArgs(SfxRequest const & rReq)
247 SwWrtShell* pSh = &GetShell();
248 SdrView* pView = pSh->GetDrawView();
249 const SfxItemSet* pArgs = rReq.GetArgs();
250 bool bChanged = pView->GetModel().IsChanged();
251 pView->GetModel().SetChanged(false);
253 GetView().NoRotate();
255 if (pArgs)
257 if(pView->AreObjectsMarked())
259 std::unique_ptr<SfxItemSet> pNewArgs = pArgs->Clone();
260 lcl_convertStringArguments(pNewArgs);
261 pView->SetAttrToMarked(*pNewArgs, false);
263 else
264 pView->SetDefaultAttr(*rReq.GetArgs(), false);
266 else
268 SfxDispatcher* pDis = pSh->GetView().GetViewFrame().GetDispatcher();
269 switch (rReq.GetSlot())
271 case SID_ATTR_FILL_STYLE:
272 case SID_ATTR_FILL_COLOR:
273 case SID_ATTR_FILL_GRADIENT:
274 case SID_ATTR_FILL_HATCH:
275 case SID_ATTR_FILL_BITMAP:
276 case SID_ATTR_FILL_TRANSPARENCE:
277 case SID_ATTR_FILL_FLOATTRANSPARENCE:
278 pDis->Execute(SID_ATTRIBUTES_AREA);
279 break;
280 case SID_ATTR_LINE_STYLE:
281 case SID_ATTR_LINE_DASH:
282 case SID_ATTR_LINE_WIDTH:
283 case SID_ATTR_LINE_COLOR:
284 case SID_ATTR_LINE_TRANSPARENCE:
285 case SID_ATTR_LINE_JOINT:
286 case SID_ATTR_LINE_CAP:
287 pDis->Execute(SID_ATTRIBUTES_LINE);
288 break;
291 if (pView->GetModel().IsChanged())
292 GetShell().SetModified();
293 else
294 if (bChanged)
295 pView->GetModel().SetChanged();
298 static void lcl_unifyFillTransparencyItems(const SfxItemSet& rSet)
300 // Transparent fill options are None, Solid, Linear, Axial, Radial, Elliptical, Square, Rectangular.
301 // But this is represented across two items namely XFillTransparenceItem (for None and Solid)
302 // and XFillFloatTransparenceItem (for the rest). To simplify the representation in LOKit case let's
303 // use XFillFloatTransparenceItem to carry the information of XFillTransparenceItem when gradients
304 // are disabled. When gradient transparency is disabled, all fields of XFillFloatTransparenceItem are invalid
305 // and not used. So convert XFillTransparenceItem's constant transparency percentage as an intensity
306 // and assign this to the XFillFloatTransparenceItem's start-intensity and end-intensity fields.
307 // Now the LOK clients need only listen to statechange messages of XFillFloatTransparenceItem
308 // to get fill-transparency settings instead of listening to two separate items.
310 XFillFloatTransparenceItem* pFillFloatTranspItem =
311 const_cast<XFillFloatTransparenceItem*>
312 (rSet.GetItem<XFillFloatTransparenceItem>(XATTR_FILLFLOATTRANSPARENCE));
313 if (!pFillFloatTranspItem || pFillFloatTranspItem->IsEnabled())
314 return;
316 const XFillTransparenceItem* pFillTranspItem =
317 rSet.GetItem<XFillTransparenceItem>(XATTR_FILLTRANSPARENCE);
319 if (!pFillTranspItem)
320 return;
322 basegfx::BGradient aTmpGradient = pFillFloatTranspItem->GetGradientValue();
323 sal_uInt16 nTranspPercent = pFillTranspItem->GetValue();
324 // Encode transparency percentage as intensity
325 sal_uInt16 nIntensity = 100 - std::min<sal_uInt16>
326 (std::max<sal_uInt16>(nTranspPercent, 0), 100);
327 aTmpGradient.SetStartIntens(nIntensity);
328 aTmpGradient.SetEndIntens(nIntensity);
329 pFillFloatTranspItem->SetGradientValue(aTmpGradient);
332 void SwDrawShell::GetDrawAttrState(SfxItemSet& rSet)
334 SdrView* pSdrView = GetShell().GetDrawView();
336 if (pSdrView->AreObjectsMarked())
338 bool bDisable = Disable( rSet );
340 if( !bDisable )
342 SfxItemSet aSet(rSet);
343 aSet.MergeRange(SDRATTR_TEXTCOLUMNS_NUMBER, SDRATTR_TEXTCOLUMNS_SPACING);
344 pSdrView->GetAttributes(aSet);
345 if (const SfxPoolItem* pItem = nullptr;
346 aSet.GetItemState(SDRATTR_TEXTCOLUMNS_NUMBER, false, &pItem)
347 >= SfxItemState::DEFAULT
348 && pItem)
350 aSet.Put(pItem->CloneSetWhich(SID_ATTR_TEXTCOLUMNS_NUMBER));
352 if (const SfxPoolItem* pItem = nullptr;
353 aSet.GetItemState(SDRATTR_TEXTCOLUMNS_SPACING, false, &pItem)
354 >= SfxItemState::DEFAULT
355 && pItem)
357 aSet.Put(pItem->CloneSetWhich(SID_ATTR_TEXTCOLUMNS_SPACING));
359 rSet.Put(aSet, false);
360 if (comphelper::LibreOfficeKit::isActive())
361 lcl_unifyFillTransparencyItems(rSet);
364 else
365 rSet.Put(pSdrView->GetDefaultAttr());
368 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */