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* pDoc = pView->GetModel();
51 bool bChanged = pDoc->IsChanged();
52 pDoc->SetChanged(false);
53
54 SfxItemSet aNewAttr( pDoc->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 pDoc,
114 true,
115 false));
116
117 pDlg->StartExecuteAsync([bChanged, bHasMarked, pDoc, pDlg, pSh, pView, this](
118 sal_Int32 nResult){
119 pDoc->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 (pDoc->IsChanged())
147 GetShell().SetModified();
148 else if (bChanged)
149 pDoc->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 pDoc,
169 pObj,
170 bHasMarked));
171
172 pDlg->StartExecuteAsync([bChanged, bHasMarked, pDoc, pDlg, pSh, pView, this](
173 sal_Int32 nResult){
174 pDoc->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 (pDoc->IsChanged())
203 GetShell().SetModified();
204 else if (bChanged)
205 pDoc->SetChanged();
206
207 pDlg->disposeOnce();
208 });
209 }
210 break;
211
212 default:
213 break;
214 }
215
216 if (pDoc->IsChanged())
218 else if (bChanged)
219 pDoc->SetChanged();
220}
221
222namespace
223{
224 void lcl_convertStringArguments(sal_uInt16 nSlot, const std::unique_ptr<SfxItemSet>& pArgs)
225 {
226 Color aColor;
227 const SfxPoolItem* pItem = nullptr;
228
229 if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_COLOR_STR, false, &pItem))
230 {
231 OUString sColor = static_cast<const SfxStringItem*>(pItem)->GetValue();
232
233 if (sColor == "transparent")
234 aColor = COL_TRANSPARENT;
235 else
236 aColor = Color(ColorTransparency, sColor.toInt32(16));
237
238 switch (nSlot)
239 {
240 case SID_ATTR_LINE_COLOR:
241 {
242 XLineColorItem aLineColorItem(OUString(), aColor);
243 pArgs->Put(aLineColorItem);
244 break;
245 }
246
247 case SID_ATTR_FILL_COLOR:
248 {
249 XFillColorItem aFillColorItem(OUString(), aColor);
250 pArgs->Put(aFillColorItem);
251 break;
252 }
253 }
254 }
255 else if (const SvxDoubleItem* pWidthItem = pArgs->GetItemIfSet(SID_ATTR_LINE_WIDTH_ARG, false))
256 {
257 double fValue = pWidthItem->GetValue();
258 // FIXME: different units...
259 int nPow = 100;
260 int nValue = fValue * nPow;
261
262 XLineWidthItem aItem(nValue);
263 pArgs->Put(aItem);
264 }
265 if (const SfxStringItem* pJSON = pArgs->GetItemIfSet(SID_FILL_GRADIENT_JSON, false))
266 {
267 XGradient aGradient = XGradient::fromJSON(pJSON->GetValue());
268 XFillGradientItem aItem(aGradient);
269 pArgs->Put(aItem);
270 }
271 }
272}
273
275{
276 SwWrtShell* pSh = &GetShell();
277 SdrView* pView = pSh->GetDrawView();
278 const SfxItemSet* pArgs = rReq.GetArgs();
279 bool bChanged = pView->GetModel()->IsChanged();
280 pView->GetModel()->SetChanged(false);
281
282 GetView().NoRotate();
283
284 if (pArgs)
285 {
286 if(pView->AreObjectsMarked())
287 {
288 std::unique_ptr<SfxItemSet> pNewArgs = pArgs->Clone();
289 lcl_convertStringArguments(rReq.GetSlot(), pNewArgs);
290 pView->SetAttrToMarked(*pNewArgs, false);
291 }
292 else
293 pView->SetDefaultAttr(*rReq.GetArgs(), false);
294 }
295 else
296 {
298 switch (rReq.GetSlot())
299 {
300 case SID_ATTR_FILL_STYLE:
301 case SID_ATTR_FILL_COLOR:
302 case SID_ATTR_FILL_GRADIENT:
303 case SID_ATTR_FILL_HATCH:
304 case SID_ATTR_FILL_BITMAP:
305 case SID_ATTR_FILL_TRANSPARENCE:
306 case SID_ATTR_FILL_FLOATTRANSPARENCE:
307 pDis->Execute(SID_ATTRIBUTES_AREA);
308 break;
309 case SID_ATTR_LINE_STYLE:
310 case SID_ATTR_LINE_DASH:
311 case SID_ATTR_LINE_WIDTH:
312 case SID_ATTR_LINE_COLOR:
313 case SID_ATTR_LINE_TRANSPARENCE:
314 case SID_ATTR_LINE_JOINT:
315 case SID_ATTR_LINE_CAP:
316 pDis->Execute(SID_ATTRIBUTES_LINE);
317 break;
318 }
319 }
320 if (pView->GetModel()->IsChanged())
322 else
323 if (bChanged)
324 pView->GetModel()->SetChanged();
325}
326
328{
329 // Transparent fill options are None, Solid, Linear, Axial, Radial, Elliptical, Quadratic, Square.
330 // But this is represented across two items namely XFillTransparenceItem (for None and Solid)
331 // and XFillFloatTransparenceItem (for the rest). To simplify the representation in LOKit case let's
332 // use XFillFloatTransparenceItem to carry the information of XFillTransparenceItem when gradients
333 // are disabled. When gradient transparency is disabled, all fields of XFillFloatTransparenceItem are invalid
334 // and not used. So convert XFillTransparenceItem's constant transparency percentage as an intensity
335 // and assign this to the XFillFloatTransparenceItem's start-intensity and end-intensity fields.
336 // Now the LOK clients need only listen to statechange messages of XFillFloatTransparenceItem
337 // to get fill-transparency settings instead of listening to two separate items.
338
339 XFillFloatTransparenceItem* pFillFloatTranspItem =
340 const_cast<XFillFloatTransparenceItem*>
342 if (!pFillFloatTranspItem || pFillFloatTranspItem->IsEnabled())
343 return;
344
345 const XFillTransparenceItem* pFillTranspItem =
347
348 if (!pFillTranspItem)
349 return;
350
351 XGradient aTmpGradient = pFillFloatTranspItem->GetGradientValue();
352 sal_uInt16 nTranspPercent = pFillTranspItem->GetValue();
353 // Encode transparency percentage as intensity
354 sal_uInt16 nIntensity = 100 - std::min<sal_uInt16>
355 (std::max<sal_uInt16>(nTranspPercent, 0), 100);
356 aTmpGradient.SetStartIntens(nIntensity);
357 aTmpGradient.SetEndIntens(nIntensity);
358 pFillFloatTranspItem->SetGradientValue(aTmpGradient);
359}
360
362{
363 SdrView* pSdrView = GetShell().GetDrawView();
364
365 if (pSdrView->AreObjectsMarked())
366 {
367 bool bDisable = Disable( rSet );
368
369 if( !bDisable )
370 {
371 SfxItemSet aSet(rSet);
373 pSdrView->GetAttributes(aSet);
374 if (const SfxPoolItem* pItem = nullptr;
375 aSet.GetItemState(SDRATTR_TEXTCOLUMNS_NUMBER, false, &pItem)
376 >= SfxItemState::DEFAULT
377 && pItem)
378 {
379 aSet.Put(pItem->CloneSetWhich(SID_ATTR_TEXTCOLUMNS_NUMBER));
380 }
381 if (const SfxPoolItem* pItem = nullptr;
382 aSet.GetItemState(SDRATTR_TEXTCOLUMNS_SPACING, false, &pItem)
383 >= SfxItemState::DEFAULT
384 && pItem)
385 {
386 aSet.Put(pItem->CloneSetWhich(SID_ATTR_TEXTCOLUMNS_SPACING));
387 }
388 rSet.Put(aSet, false);
391 }
392 }
393 else
394 rSet.Put(pSdrView->GetDefaultAttr());
395}
396
397/* 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
SdrModel * GetModel() const
void SetDefaultAttr(const SfxItemSet &rAttr, bool bReplaceAll)
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)
std::unique_ptr< SfxPoolItem > CloneSetWhich(sal_uInt16 nNewWhich) const
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:2827
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:979
void GetDrawAttrState(SfxItemSet &rSet)
Definition: drawdlg.cxx:361
void ExecDrawDlg(SfxRequest &rReq)
Definition: drawdlg.cxx:46
void ExecDrawAttrArgs(SfxRequest const &rReq)
Definition: drawdlg.cxx:274
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:373
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:438
const XGradient & GetGradientValue() const
void SetGradientValue(const XGradient &rNew)
void SetEndIntens(sal_uInt16 nNewIntens)
static XGradient fromJSON(std::u16string_view rJSON)
void SetStartIntens(sal_uInt16 nNewIntens)
#define FN_DRAWTEXT_ATTR_DLG
Definition: cmdid.h:253
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
const OUStringLiteral sColor
virtual SfxBindings & GetBindings() override
static void lcl_unifyFillTransparencyItems(const SfxItemSet &rSet)
Definition: drawdlg.cxx:327
sal_Int16 nValue
const char GetValue[]
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)