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 
43 using namespace com::sun::star::drawing;
44 
46 {
47  SwWrtShell* pSh = &GetShell();
48  SdrView* pView = pSh->GetDrawView();
49  SdrModel* pDoc = pView->GetModel();
50  bool bChanged = pDoc->IsChanged();
51  pDoc->SetChanged(false);
52 
53  SfxItemSet aNewAttr( pDoc->GetItemPool() );
54  pView->GetAttributes( aNewAttr );
55 
56  GetView().NoRotate();
57 
58  switch (rReq.GetSlot())
59  {
61  {
63  ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateTextTabDialog(rReq.GetFrameWeld(), &aNewAttr, pView));
64  sal_uInt16 nResult = pDlg->Execute();
65 
66  if (nResult == RET_OK)
67  {
68  if (pView->AreObjectsMarked())
69  {
70  pSh->StartAction();
71  pView->SetAttributes(*pDlg->GetOutputItemSet());
72  rReq.Done(*(pDlg->GetOutputItemSet()));
73  pSh->EndAction();
74  }
75  }
76  }
77  break;
78 
79  case SID_MEASURE_DLG:
80  {
81  bool bHasMarked = pView->AreObjectsMarked();
82 
85  aNewAttr, pView, RID_SVXPAGE_MEASURE));
86  if (pDlg->Execute() == RET_OK)
87  {
88  pSh->StartAction();
89  if (bHasMarked)
90  pView->SetAttrToMarked(*pDlg->GetOutputItemSet(), false);
91  else
92  pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
93  pSh->EndAction();
94  }
95  }
96  break;
97 
98  case SID_ATTRIBUTES_AREA:
99  {
100  bool bHasMarked = pView->AreObjectsMarked();
101 
104  &aNewAttr,
105  pDoc,
106  true));
107 
108  pDlg->StartExecuteAsync([bChanged, bHasMarked, pDoc, pDlg, pSh, pView, this](
109  sal_Int32 nResult){
110  if (nResult == RET_OK)
111  {
112  pSh->StartAction();
113  if (bHasMarked)
114  pView->SetAttributes(*pDlg->GetOutputItemSet());
115  else
116  pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
117  pSh->EndAction();
118 
119  static sal_uInt16 aInval[] =
120  {
121  SID_ATTR_FILL_STYLE,
122  SID_ATTR_FILL_COLOR,
123  SID_ATTR_FILL_TRANSPARENCE,
124  SID_ATTR_FILL_FLOATTRANSPARENCE,
125  0
126  };
127  SfxBindings &rBnd = GetView().GetViewFrame()->GetBindings();
128  rBnd.Invalidate(aInval);
129  rBnd.Update(SID_ATTR_FILL_STYLE);
130  rBnd.Update(SID_ATTR_FILL_COLOR);
131  rBnd.Update(SID_ATTR_FILL_TRANSPARENCE);
132  rBnd.Update(SID_ATTR_FILL_FLOATTRANSPARENCE);
133  }
134 
135  if (pDoc->IsChanged())
136  GetShell().SetModified();
137  else if (bChanged)
138  pDoc->SetChanged();
139 
140  pDlg->disposeOnce();
141  });
142  }
143  break;
144 
145  case SID_ATTRIBUTES_LINE:
146  {
147  bool bHasMarked = pView->AreObjectsMarked();
148 
149  const SdrObject* pObj = nullptr;
150  const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
151  if( rMarkList.GetMarkCount() == 1 )
152  pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
153 
156  &aNewAttr,
157  pDoc,
158  pObj,
159  bHasMarked));
160 
161  pDlg->StartExecuteAsync([bChanged, bHasMarked, pDoc, pDlg, pSh, pView, this](
162  sal_Int32 nResult){
163  if (nResult == RET_OK)
164  {
165  pSh->StartAction();
166  if(bHasMarked)
167  pView->SetAttrToMarked(*pDlg->GetOutputItemSet(), false);
168  else
169  pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
170  pSh->EndAction();
171 
172  static sal_uInt16 aInval[] =
173  {
174  SID_ATTR_LINE_STYLE, // ( SID_SVX_START + 169 )
175  SID_ATTR_LINE_DASH, // ( SID_SVX_START + 170 )
176  SID_ATTR_LINE_WIDTH, // ( SID_SVX_START + 171 )
177  SID_ATTR_LINE_COLOR, // ( SID_SVX_START + 172 )
178  SID_ATTR_LINE_START, // ( SID_SVX_START + 173 )
179  SID_ATTR_LINE_END, // ( SID_SVX_START + 174 )
180  SID_ATTR_LINE_TRANSPARENCE, // (SID_SVX_START+1107)
181  SID_ATTR_LINE_JOINT, // (SID_SVX_START+1110)
182  SID_ATTR_LINE_CAP, // (SID_SVX_START+1111)
183  0
184  };
185 
186  GetView().GetViewFrame()->GetBindings().Invalidate(aInval);
187  }
188 
189  if (pDoc->IsChanged())
190  GetShell().SetModified();
191  else if (bChanged)
192  pDoc->SetChanged();
193 
194  pDlg->disposeOnce();
195  });
196  }
197  break;
198 
199  default:
200  break;
201  }
202 
203  if (pDoc->IsChanged())
204  GetShell().SetModified();
205  else
206  if (bChanged)
207  pDoc->SetChanged();
208 }
209 
210 namespace
211 {
212  void lcl_convertStringArguments(sal_uInt16 nSlot, std::unique_ptr<SfxItemSet>& pArgs)
213  {
214  Color aColor;
215  OUString sColor;
216  const SfxPoolItem* pItem = nullptr;
217 
218  if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_COLOR_STR, false, &pItem))
219  {
220  sColor = static_cast<const SfxStringItem*>(pItem)->GetValue();
221 
222  if (sColor == "transparent")
223  aColor = COL_TRANSPARENT;
224  else
225  aColor = Color(sColor.toInt32(16));
226 
227  switch (nSlot)
228  {
229  case SID_ATTR_LINE_COLOR:
230  {
231  XLineColorItem aLineColorItem(OUString(), aColor);
232  pArgs->Put(aLineColorItem);
233  break;
234  }
235 
236  case SID_ATTR_FILL_COLOR:
237  {
238  XFillColorItem aFillColorItem(OUString(), aColor);
239  pArgs->Put(aFillColorItem);
240  break;
241  }
242  }
243  }
244  else if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_LINE_WIDTH_ARG, false, &pItem))
245  {
246  double fValue = static_cast<const SvxDoubleItem*>(pItem)->GetValue();
247  // FIXME: different units...
248  int nPow = 100;
249  int nValue = fValue * nPow;
250 
251  XLineWidthItem aItem(nValue);
252  pArgs->Put(aItem);
253  }
254  if (SfxItemState::SET == pArgs->GetItemState(SID_FILL_GRADIENT_JSON, false, &pItem))
255  {
256  const SfxStringItem* pJSON = static_cast<const SfxStringItem*>(pItem);
257  if (pJSON)
258  {
259  XGradient aGradient = XGradient::fromJSON(pJSON->GetValue());
260  XFillGradientItem aItem(aGradient);
261  pArgs->Put(aItem);
262  }
263  }
264  }
265 }
266 
268 {
269  SwWrtShell* pSh = &GetShell();
270  SdrView* pView = pSh->GetDrawView();
271  const SfxItemSet* pArgs = rReq.GetArgs();
272  bool bChanged = pView->GetModel()->IsChanged();
273  pView->GetModel()->SetChanged(false);
274 
275  GetView().NoRotate();
276 
277  if (pArgs)
278  {
279  if(pView->AreObjectsMarked())
280  {
281  std::unique_ptr<SfxItemSet> pNewArgs = pArgs->Clone();
282  lcl_convertStringArguments(rReq.GetSlot(), pNewArgs);
283  pView->SetAttrToMarked(*pNewArgs, false);
284  }
285  else
286  pView->SetDefaultAttr(*rReq.GetArgs(), false);
287  }
288  else
289  {
290  SfxDispatcher* pDis = pSh->GetView().GetViewFrame()->GetDispatcher();
291  switch (rReq.GetSlot())
292  {
293  case SID_ATTR_FILL_STYLE:
294  case SID_ATTR_FILL_COLOR:
295  case SID_ATTR_FILL_GRADIENT:
296  case SID_ATTR_FILL_HATCH:
297  case SID_ATTR_FILL_BITMAP:
298  case SID_ATTR_FILL_TRANSPARENCE:
299  case SID_ATTR_FILL_FLOATTRANSPARENCE:
300  pDis->Execute(SID_ATTRIBUTES_AREA);
301  break;
302  case SID_ATTR_LINE_STYLE:
303  case SID_ATTR_LINE_DASH:
304  case SID_ATTR_LINE_WIDTH:
305  case SID_ATTR_LINE_COLOR:
306  case SID_ATTR_LINE_TRANSPARENCE:
307  case SID_ATTR_LINE_JOINT:
308  case SID_ATTR_LINE_CAP:
309  pDis->Execute(SID_ATTRIBUTES_LINE);
310  break;
311  }
312  }
313  if (pView->GetModel()->IsChanged())
314  GetShell().SetModified();
315  else
316  if (bChanged)
317  pView->GetModel()->SetChanged();
318 }
319 
321 {
322  // Transparent fill options are None, Solid, Linear, Axial, Radial, Elliptical, Quadratic, Square.
323  // But this is represented across two items namely XFillTransparenceItem (for None and Solid)
324  // and XFillFloatTransparenceItem (for the rest). To simplify the representation in LOKit case let's
325  // use XFillFloatTransparenceItem to carry the information of XFillTransparenceItem when gradients
326  // are disabled. When gradient transparency is disabled, all fields of XFillFloatTransparenceItem are invalid
327  // and not used. So convert XFillTransparenceItem's constant transparency percentage as an intensity
328  // and assign this to the XFillFloatTransparenceItem's start-intensity and end-intensity fields.
329  // Now the LOK clients need only listen to statechange messages of XFillFloatTransparenceItem
330  // to get fill-transparency settings instead of listening to two separate items.
331 
332  XFillFloatTransparenceItem* pFillFloatTranspItem =
333  const_cast<XFillFloatTransparenceItem*>
335  if (!pFillFloatTranspItem || pFillFloatTranspItem->IsEnabled())
336  return;
337 
338  const XFillTransparenceItem* pFillTranspItem =
340 
341  if (!pFillTranspItem)
342  return;
343 
344  XGradient aTmpGradient = pFillFloatTranspItem->GetGradientValue();
345  sal_uInt16 nTranspPercent = pFillTranspItem->GetValue();
346  // Encode transparency percentage as intensity
347  sal_uInt16 nIntensity = 100 - std::min<sal_uInt16>
348  (std::max<sal_uInt16>(nTranspPercent, 0), 100);
349  aTmpGradient.SetStartIntens(nIntensity);
350  aTmpGradient.SetEndIntens(nIntensity);
351  pFillFloatTranspItem->SetGradientValue(aTmpGradient);
352 }
353 
355 {
356  SdrView* pSdrView = GetShell().GetDrawView();
357 
358  if (pSdrView->AreObjectsMarked())
359  {
360  bool bDisable = Disable( rSet );
361 
362  if( !bDisable )
363  {
364  pSdrView->GetAttributes( rSet );
367  }
368  }
369  else
370  rSet.Put(pSdrView->GetDefaultAttr());
371 }
372 
373 /* 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)
SfxDispatcher * GetDispatcher()
bool AreObjectsMarked() const
static SvxAbstractDialogFactory * Create()
void GetDrawAttrState(SfxItemSet &rSet)
Definition: drawdlg.cxx:354
void Done(bool bRemove=false)
SdrMark * GetMark(size_t nNum) const
void ExecDrawAttrArgs(SfxRequest const &rReq)
Definition: drawdlg.cxx:267
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
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:238
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:235
void SetDefaultAttr(const SfxItemSet &rAttr, bool bReplaceAll)
bool IsChanged() const
void StartAction()
Definition: crsrsh.cxx:221
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:45
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)
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
static void lcl_unifyFillTransparencyItems(SfxItemSet &rSet)
Definition: drawdlg.cxx:320