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 <sfx2/request.hxx>
21 #include <sfx2/dispatch.hxx>
22 #include <sfx2/viewfrm.hxx>
23 #include <svx/svdview.hxx>
30 #include <svx/svxdlg.hxx>
31 #include <svx/dialogs.hrc>
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
);
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())
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()));
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
)
98 pView
->SetAttrToMarked(*pDlg
->GetOutputItemSet(), false);
100 pView
->SetDefaultAttr(*pDlg
->GetOutputItemSet(), false);
106 case SID_ATTRIBUTES_AREA
:
108 bool bHasMarked
= pView
->AreObjectsMarked();
110 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
111 VclPtr
<AbstractSvxAreaTabDialog
> pDlg(pFact
->CreateSvxAreaTabDialog(rReq
.GetFrameWeld(),
117 pDlg
->StartExecuteAsync([bChanged
, bHasMarked
, &rModel
, pDlg
, pSh
, pView
, this](
119 rModel
.SetChanged(false);
121 if (nResult
== RET_OK
)
125 pView
->SetAttributes(*pDlg
->GetOutputItemSet());
127 pView
->SetDefaultAttr(*pDlg
->GetOutputItemSet(), false);
130 static sal_uInt16 aInval
[] =
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();
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(),
172 pDlg
->StartExecuteAsync([bChanged
, bHasMarked
, &rModel
, pDlg
, pSh
, pView
, this](
174 rModel
.SetChanged(false);
176 if (nResult
== RET_OK
)
180 pView
->SetAttrToMarked(*pDlg
->GetOutputItemSet(), false);
182 pView
->SetDefaultAttr(*pDlg
->GetOutputItemSet(), false);
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();
216 if (rModel
.IsChanged())
217 GetShell().SetModified();
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...
231 int nValue
= fValue
* nPow
;
233 XLineWidthItem
aItem(nValue
);
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
);
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();
257 if(pView
->AreObjectsMarked())
259 std::unique_ptr
<SfxItemSet
> pNewArgs
= pArgs
->Clone();
260 lcl_convertStringArguments(pNewArgs
);
261 pView
->SetAttrToMarked(*pNewArgs
, false);
264 pView
->SetDefaultAttr(*rReq
.GetArgs(), false);
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
);
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
);
291 if (pView
->GetModel().IsChanged())
292 GetShell().SetModified();
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())
316 const XFillTransparenceItem
* pFillTranspItem
=
317 rSet
.GetItem
<XFillTransparenceItem
>(XATTR_FILLTRANSPARENCE
);
319 if (!pFillTranspItem
)
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
);
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
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
357 aSet
.Put(pItem
->CloneSetWhich(SID_ATTR_TEXTCOLUMNS_SPACING
));
359 rSet
.Put(aSet
, false);
360 if (comphelper::LibreOfficeKit::isActive())
361 lcl_unifyFillTransparencyItems(rSet
);
365 rSet
.Put(pSdrView
->GetDefaultAttr());
368 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */