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 
44 using 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 
116  pDlg->StartExecuteAsync([bChanged, bHasMarked, pDoc, pDlg, pSh, pView, this](
117  sal_Int32 nResult){
118  if (nResult == RET_OK)
119  {
120  pSh->StartAction();
121  if (bHasMarked)
122  pView->SetAttributes(*pDlg->GetOutputItemSet());
123  else
124  pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
125  pSh->EndAction();
126 
127  static sal_uInt16 aInval[] =
128  {
129  SID_ATTR_FILL_STYLE,
130  SID_ATTR_FILL_COLOR,
131  SID_ATTR_FILL_TRANSPARENCE,
132  SID_ATTR_FILL_FLOATTRANSPARENCE,
133  0
134  };
135  SfxBindings &rBnd = GetView().GetViewFrame()->GetBindings();
136  rBnd.Invalidate(aInval);
137  rBnd.Update(SID_ATTR_FILL_STYLE);
138  rBnd.Update(SID_ATTR_FILL_COLOR);
139  rBnd.Update(SID_ATTR_FILL_TRANSPARENCE);
140  rBnd.Update(SID_ATTR_FILL_FLOATTRANSPARENCE);
141  }
142 
143  if (pDoc->IsChanged())
144  GetShell().SetModified();
145  else if (bChanged)
146  pDoc->SetChanged();
147 
148  pDlg->disposeOnce();
149  });
150  }
151  break;
152 
153  case SID_ATTRIBUTES_LINE:
154  {
155  bool bHasMarked = pView->AreObjectsMarked();
156 
157  const SdrObject* pObj = nullptr;
158  const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
159  if( rMarkList.GetMarkCount() == 1 )
160  pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
161 
164  &aNewAttr,
165  pDoc,
166  pObj,
167  bHasMarked));
168 
169  pDlg->StartExecuteAsync([bChanged, bHasMarked, pDoc, pDlg, pSh, pView, this](
170  sal_Int32 nResult){
171  if (nResult == RET_OK)
172  {
173  pSh->StartAction();
174  if(bHasMarked)
175  pView->SetAttrToMarked(*pDlg->GetOutputItemSet(), false);
176  else
177  pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
178  pSh->EndAction();
179 
180  static sal_uInt16 aInval[] =
181  {
182  SID_ATTR_LINE_STYLE, // ( SID_SVX_START + 169 )
183  SID_ATTR_LINE_DASH, // ( SID_SVX_START + 170 )
184  SID_ATTR_LINE_WIDTH, // ( SID_SVX_START + 171 )
185  SID_ATTR_LINE_COLOR, // ( SID_SVX_START + 172 )
186  SID_ATTR_LINE_START, // ( SID_SVX_START + 173 )
187  SID_ATTR_LINE_END, // ( SID_SVX_START + 174 )
188  SID_ATTR_LINE_TRANSPARENCE, // (SID_SVX_START+1107)
189  SID_ATTR_LINE_JOINT, // (SID_SVX_START+1110)
190  SID_ATTR_LINE_CAP, // (SID_SVX_START+1111)
191  0
192  };
193 
194  GetView().GetViewFrame()->GetBindings().Invalidate(aInval);
195  }
196 
197  if (pDoc->IsChanged())
198  GetShell().SetModified();
199  else if (bChanged)
200  pDoc->SetChanged();
201 
202  pDlg->disposeOnce();
203  });
204  }
205  break;
206 
207  default:
208  break;
209  }
210 
211  if (pDoc->IsChanged())
212  GetShell().SetModified();
213  else
214  if (bChanged)
215  pDoc->SetChanged();
216 }
217 
218 namespace
219 {
220  void lcl_convertStringArguments(sal_uInt16 nSlot, const std::unique_ptr<SfxItemSet>& pArgs)
221  {
222  Color aColor;
223  const SfxPoolItem* pItem = nullptr;
224 
225  if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_COLOR_STR, false, &pItem))
226  {
227  OUString sColor = static_cast<const SfxStringItem*>(pItem)->GetValue();
228 
229  if (sColor == "transparent")
230  aColor = COL_TRANSPARENT;
231  else
232  aColor = Color(sColor.toInt32(16));
233 
234  switch (nSlot)
235  {
236  case SID_ATTR_LINE_COLOR:
237  {
238  XLineColorItem aLineColorItem(OUString(), aColor);
239  pArgs->Put(aLineColorItem);
240  break;
241  }
242 
243  case SID_ATTR_FILL_COLOR:
244  {
245  XFillColorItem aFillColorItem(OUString(), aColor);
246  pArgs->Put(aFillColorItem);
247  break;
248  }
249  }
250  }
251  else if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_LINE_WIDTH_ARG, false, &pItem))
252  {
253  double fValue = static_cast<const SvxDoubleItem*>(pItem)->GetValue();
254  // FIXME: different units...
255  int nPow = 100;
256  int nValue = fValue * nPow;
257 
258  XLineWidthItem aItem(nValue);
259  pArgs->Put(aItem);
260  }
261  if (SfxItemState::SET == pArgs->GetItemState(SID_FILL_GRADIENT_JSON, false, &pItem))
262  {
263  const SfxStringItem* pJSON = static_cast<const SfxStringItem*>(pItem);
264  if (pJSON)
265  {
266  XGradient aGradient = XGradient::fromJSON(pJSON->GetValue());
267  XFillGradientItem aItem(aGradient);
268  pArgs->Put(aItem);
269  }
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  {
297  SfxDispatcher* pDis = pSh->GetView().GetViewFrame()->GetDispatcher();
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())
321  GetShell().SetModified();
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  pSdrView->GetAttributes( rSet );
374  }
375  }
376  else
377  rSet.Put(pSdrView->GetDefaultAttr());
378 }
379 
380 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
size_t GetMarkCount() const
SdrView * GetDrawView()
Definition: vnew.cxx:375
virtual const SfxItemSet * GetOutputItemSet() const =0
std::string GetValue
static XGradient fromJSON(const OUString &rJSON)
static bool hasTextFrame(const SdrObject *pObj)
Returns true if the SdrObject has a SwTextFrame otherwise false.
SfxDispatcher * GetDispatcher()
bool AreObjectsMarked() const
static SvxAbstractDialogFactory * Create()
void GetDrawAttrState(SfxItemSet &rSet)
Definition: drawdlg.cxx:361
void Done(bool bRemove=false)
SdrMark * GetMark(size_t nNum) const
void ExecDrawAttrArgs(SfxRequest const &rReq)
Definition: drawdlg.cxx:274
const SfxItemSet * GetArgs() const
void Invalidate(sal_uInt16 nId)
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
void SetAttrToMarked(const SfxItemSet &rAttr, bool bReplaceAll)
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
const SwView & GetView() const
Definition: wrtsh.hxx:428
virtual VclPtr< SfxAbstractDialog > CreateSfxDialog(weld::Window *pParent, const SfxItemSet &rAttr, const SdrView *pView, sal_uInt32 nResId)=0
const SfxItemSet & GetDefaultAttr() const
virtual void SetChanged(bool bFlg=true)
void SetEndIntens(sal_uInt16 nNewIntens)
SdrObject * GetMarkedSdrObj() const
static void updateTextBoxMargin(SdrObject *pObj)
Copy shape attributes to the text frame.
constexpr TypedWhichId< XFillTransparenceItem > XATTR_FILLTRANSPARENCE(XATTR_FILL_FIRST+5)
Shell * GetShell()
const XGradient & GetGradientValue() const
void EndAction(const bool bIdleEnd=false, const bool DoSetPosX=false)
Definition: crsrsh.cxx:239
void SetGradientValue(const XGradient &rNew)
const OUString & GetValue() const
const SdrMarkList & GetMarkedObjectList() const
bool SetAttributes(const SfxItemSet &rSet, bool bReplaceAll=false)
#define FN_DRAWTEXT_ATTR_DLG
Definition: cmdid.h:238
void SetDefaultAttr(const SfxItemSet &rAttr, bool bReplaceAll)
bool IsChanged() const
void StartAction()
Definition: crsrsh.cxx:222
virtual VclPtr< SfxAbstractTabDialog > CreateTextTabDialog(weld::Window *pParent, const SfxItemSet *pAttrSet, SdrView *pView)=0
void SetStartIntens(sal_uInt16 nNewIntens)
weld::Window * GetFrameWeld() const
void Update(sal_uInt16 nId)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
void ExecDrawDlg(SfxRequest &rReq)
Definition: drawdlg.cxx:46
constexpr TypedWhichId< XFillFloatTransparenceItem > XATTR_FILLFLOATTRANSPARENCE(XATTR_FILL_FIRST+11)
virtual std::unique_ptr< SfxItemSet > Clone(bool bItems=true, SfxItemPool *pToPool=nullptr) const
virtual VclPtr< AbstractSvxAreaTabDialog > CreateSvxAreaTabDialog(weld::Window *pParent, const SfxItemSet *pAttr, SdrModel *pModel, bool bShadow)=0
void GetAttributes(SfxItemSet &rTargetSet, bool bOnlyHardAttr=false) const
RET_OK
const SfxItemPool & GetItemPool() const
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
::std::vector< SdrObject * > GetMarkedObjects() const
static void lcl_unifyFillTransparencyItems(const SfxItemSet &rSet)
Definition: drawdlg.cxx:327
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
SdrModel * GetModel() const
virtual VclPtr< SfxAbstractTabDialog > CreateSvxLineTabDialog(weld::Window *pParent, const SfxItemSet *pAttr, SdrModel *pModel, const SdrObject *pObj, bool bHasObj)=0
sal_Int16 nValue