LibreOffice Module sw (master) 1
drawdlg.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 <sfx2/request.hxx>
21#include <sfx2/dispatch.hxx>
22#include <sfx2/viewfrm.hxx>
23#include <svx/svdview.hxx>
24
25#include <view.hxx>
26#include <wrtsh.hxx>
27#include <cmdid.h>
28
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>
43
44using namespace com::sun::star::drawing;
45
47{
48 SwWrtShell* pSh = &GetShell();
49 SdrView* pView = pSh->GetDrawView();
50 SdrModel& rModel = pView->GetModel();
51 bool bChanged = rModel.IsChanged();
52 rModel.SetChanged(false);
53
54 SfxItemSet aNewAttr(rModel.GetItemPool());
55 pView->GetAttributes( aNewAttr );
56
57 GetView().NoRotate();
58
59 switch (rReq.GetSlot())
60 {
62 {
64 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateTextTabDialog(rReq.GetFrameWeld(), &aNewAttr, pView));
65 sal_uInt16 nResult = pDlg->Execute();
66
67 if (nResult == RET_OK)
68 {
69 if (pView->AreObjectsMarked())
70 {
71 pSh->StartAction();
72 pView->SetAttributes(*pDlg->GetOutputItemSet());
73 auto vMarkedObjs = pView->GetMarkedObjects();
74 for (auto pObj : vMarkedObjs)
75 {
76 // If the shape has textframe, set its params as well.
79 }
80 rReq.Done(*(pDlg->GetOutputItemSet()));
81 pSh->EndAction();
82 }
83 }
84 }
85 break;
86
87 case SID_MEASURE_DLG:
88 {
89 bool bHasMarked = pView->AreObjectsMarked();
90
93 aNewAttr, pView, RID_SVXPAGE_MEASURE));
94 if (pDlg->Execute() == RET_OK)
95 {
96 pSh->StartAction();
97 if (bHasMarked)
98 pView->SetAttrToMarked(*pDlg->GetOutputItemSet(), false);
99 else
100 pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
101 pSh->EndAction();
102 }
103 }
104 break;
105
106 case SID_ATTRIBUTES_AREA:
107 {
108 bool bHasMarked = pView->AreObjectsMarked();
109
112 &aNewAttr,
113 &rModel,
114 true,
115 false));
116
117 pDlg->StartExecuteAsync([bChanged, bHasMarked, &rModel, pDlg, pSh, pView, this](
118 sal_Int32 nResult){
119 rModel.SetChanged(false);
120
121 if (nResult == RET_OK)
122 {
123 pSh->StartAction();
124 if (bHasMarked)
125 pView->SetAttributes(*pDlg->GetOutputItemSet());
126 else
127 pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
128 pSh->EndAction();
129
130 static sal_uInt16 aInval[] =
131 {
132 SID_ATTR_FILL_STYLE,
133 SID_ATTR_FILL_COLOR,
134 SID_ATTR_FILL_TRANSPARENCE,
135 SID_ATTR_FILL_FLOATTRANSPARENCE,
136 0
137 };
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);
144 }
145
146 if (rModel.IsChanged())
147 GetShell().SetModified();
148 else if (bChanged)
149 rModel.SetChanged();
150
151 pDlg->disposeOnce();
152 });
153 }
154 break;
155
156 case SID_ATTRIBUTES_LINE:
157 {
158 bool bHasMarked = pView->AreObjectsMarked();
159
160 const SdrObject* pObj = nullptr;
161 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
162 if( rMarkList.GetMarkCount() == 1 )
163 pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
164
167 &aNewAttr,
168 &rModel,
169 pObj,
170 bHasMarked));
171
172 pDlg->StartExecuteAsync([bChanged, bHasMarked, &rModel, pDlg, pSh, pView, this](
173 sal_Int32 nResult){
174 rModel.SetChanged(false);
175
176 if (nResult == RET_OK)
177 {
178 pSh->StartAction();
179 if(bHasMarked)
180 pView->SetAttrToMarked(*pDlg->GetOutputItemSet(), false);
181 else
182 pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
183 pSh->EndAction();
184
185 static sal_uInt16 aInval[] =
186 {
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)
196 0
197 };
198
199 GetView().GetViewFrame().GetBindings().Invalidate(aInval);
200 }
201
202 if (rModel.IsChanged())
203 GetShell().SetModified();
204 else if (bChanged)
205 rModel.SetChanged();
206
207 pDlg->disposeOnce();
208 });
209 }
210 break;
211
212 default:
213 break;
214 }
215
216 if (rModel.IsChanged())
218 else if (bChanged)
219 rModel.SetChanged();
220}
221
222namespace
223{
224 void lcl_convertStringArguments(const std::unique_ptr<SfxItemSet>& pArgs)
225 {
226 if (const SvxDoubleItem* pWidthItem = pArgs->GetItemIfSet(SID_ATTR_LINE_WIDTH_ARG, false))
227 {
228 double fValue = pWidthItem->GetValue();
229 // FIXME: different units...
230 int nPow = 100;
231 int nValue = fValue * nPow;
232
233 XLineWidthItem aItem(nValue);
234 pArgs->Put(aItem);
235 }
236 if (const SfxStringItem* pJSON = pArgs->GetItemIfSet(SID_FILL_GRADIENT_JSON, false))
237 {
238 basegfx::BGradient aGradient = basegfx::BGradient::fromJSON(pJSON->GetValue());
239 XFillGradientItem aItem(aGradient);
240 pArgs->Put(aItem);
241 }
242 }
243}
244
246{
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);
252
253 GetView().NoRotate();
254
255 if (pArgs)
256 {
257 if(pView->AreObjectsMarked())
258 {
259 std::unique_ptr<SfxItemSet> pNewArgs = pArgs->Clone();
260 lcl_convertStringArguments(pNewArgs);
261 pView->SetAttrToMarked(*pNewArgs, false);
262 }
263 else
264 pView->SetDefaultAttr(*rReq.GetArgs(), false);
265 }
266 else
267 {
269 switch (rReq.GetSlot())
270 {
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;
289 }
290 }
291 if (pView->GetModel().IsChanged())
293 else
294 if (bChanged)
295 pView->GetModel().SetChanged();
296}
297
299{
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.
309
310 XFillFloatTransparenceItem* pFillFloatTranspItem =
311 const_cast<XFillFloatTransparenceItem*>
313 if (!pFillFloatTranspItem || pFillFloatTranspItem->IsEnabled())
314 return;
315
316 const XFillTransparenceItem* pFillTranspItem =
318
319 if (!pFillTranspItem)
320 return;
321
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);
330}
331
333{
334 SdrView* pSdrView = GetShell().GetDrawView();
335
336 if (pSdrView->AreObjectsMarked())
337 {
338 bool bDisable = Disable( rSet );
339
340 if( !bDisable )
341 {
342 SfxItemSet aSet(rSet);
344 pSdrView->GetAttributes(aSet);
345 if (const SfxPoolItem* pItem = nullptr;
346 aSet.GetItemState(SDRATTR_TEXTCOLUMNS_NUMBER, false, &pItem)
347 >= SfxItemState::DEFAULT
348 && pItem)
349 {
350 aSet.Put(pItem->CloneSetWhich(SID_ATTR_TEXTCOLUMNS_NUMBER));
351 }
352 if (const SfxPoolItem* pItem = nullptr;
353 aSet.GetItemState(SDRATTR_TEXTCOLUMNS_SPACING, false, &pItem)
354 >= SfxItemState::DEFAULT
355 && pItem)
356 {
357 aSet.Put(pItem->CloneSetWhich(SID_ATTR_TEXTCOLUMNS_SPACING));
358 }
359 rSet.Put(aSet, false);
362 }
363 }
364 else
365 rSet.Put(pSdrView->GetDefaultAttr());
366}
367
368/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetAttrToMarked(const SfxItemSet &rAttr, bool bReplaceAll)
::std::vector< SdrObject * > GetMarkedObjects() const
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
bool AreObjectsMarked() const
SdrObject * GetMarkedSdrObj() const
virtual void SetChanged(bool bFlg=true)
bool IsChanged() const
const SfxItemPool & GetItemPool() const
const SfxItemSet & GetDefaultAttr() const
void SetDefaultAttr(const SfxItemSet &rAttr, bool bReplaceAll)
SdrModel & GetModel() const
bool SetAttributes(const SfxItemSet &rSet, bool bReplaceAll=false)
void GetAttributes(SfxItemSet &rTargetSet, bool bOnlyHardAttr=false) const
void Invalidate(sal_uInt16 nId)
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
virtual std::unique_ptr< SfxItemSet > Clone(bool bItems=true, SfxItemPool *pToPool=nullptr) const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void MergeRange(sal_uInt16 nFrom, sal_uInt16 nTo)
sal_uInt16 GetSlot() const
const SfxItemSet * GetArgs() const
weld::Window * GetFrameWeld() const
void Done(bool bRemove=false)
virtual void Invalidate(sal_uInt16 nId=0)
SfxDispatcher * GetDispatcher()
SfxViewFrame & GetViewFrame() const
virtual VclPtr< AbstractSvxAreaTabDialog > CreateSvxAreaTabDialog(weld::Window *pParent, const SfxItemSet *pAttr, SdrModel *pModel, bool bShadow, bool bSlideBackground)=0
virtual VclPtr< SfxAbstractTabDialog > CreateTextTabDialog(weld::Window *pParent, const SfxItemSet *pAttrSet, SdrView *pView)=0
virtual VclPtr< SfxAbstractDialog > CreateSfxDialog(weld::Window *pParent, const SfxItemSet &rAttr, const SdrView *pView, sal_uInt32 nResId)=0
virtual VclPtr< SfxAbstractTabDialog > CreateSvxLineTabDialog(weld::Window *pParent, const SfxItemSet *pAttr, SdrModel *pModel, const SdrObject *pObj, bool bHasObj)=0
static SvxAbstractDialogFactory * Create()
SwWrtShell & GetShell()
Definition: basesh.cxx:3001
SwView & GetView()
Definition: basesh.hxx:59
void StartAction()
Definition: crsrsh.cxx:226
void EndAction(const bool bIdleEnd=false)
Definition: crsrsh.cxx:243
bool Disable(SfxItemSet &rSet, sal_uInt16 nWhich=0)
Definition: drwbassh.cxx:982
void GetDrawAttrState(SfxItemSet &rSet)
Definition: drawdlg.cxx:332
void ExecDrawDlg(SfxRequest &rReq)
Definition: drawdlg.cxx:46
void ExecDrawAttrArgs(SfxRequest const &rReq)
Definition: drawdlg.cxx:245
void SetModified()
Definition: edws.cxx:70
static bool hasTextFrame(const SdrObject *pObj)
Returns true if the SdrObject has a SwTextFrame otherwise false.
static void updateTextBoxMargin(SdrObject *pObj)
Copy shape attributes to the text frame.
SdrView * GetDrawView()
Definition: vnew.cxx:386
void NoRotate()
Definition: viewdraw.cxx:439
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
const SwView & GetView() const
Definition: wrtsh.hxx:443
void SetGradientValue(const basegfx::BGradient &rNew)
const basegfx::BGradient & GetGradientValue() const
void SetEndIntens(sal_uInt16 nNewIntens)
static BGradient fromJSON(std::u16string_view rJSON)
void SetStartIntens(sal_uInt16 nNewIntens)
#define FN_DRAWTEXT_ATTR_DLG
Definition: cmdid.h:260
virtual SfxBindings & GetBindings() override
static void lcl_unifyFillTransparencyItems(const SfxItemSet &rSet)
Definition: drawdlg.cxx:298
sal_Int16 nValue
static SfxItemSet & rSet
constexpr TypedWhichId< SfxInt16Item > SDRATTR_TEXTCOLUMNS_NUMBER(SDRATTR_TEXTCOLUMNS_FIRST+0)
constexpr TypedWhichId< SdrMetricItem > SDRATTR_TEXTCOLUMNS_SPACING(SDRATTR_TEXTCOLUMNS_FIRST+1)
RET_OK
constexpr TypedWhichId< XFillTransparenceItem > XATTR_FILLTRANSPARENCE(XATTR_FILL_FIRST+5)
constexpr TypedWhichId< XFillFloatTransparenceItem > XATTR_FILLFLOATTRANSPARENCE(XATTR_FILL_FIRST+11)