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 
40 using namespace com::sun::star::drawing;
41 
43 {
44  SwWrtShell* pSh = &GetShell();
45  SdrView* pView = pSh->GetDrawView();
46  SdrModel* pDoc = pView->GetModel();
47  bool bChanged = pDoc->IsChanged();
48  pDoc->SetChanged(false);
49 
50  SfxItemSet aNewAttr( pDoc->GetItemPool() );
51  pView->GetAttributes( aNewAttr );
52 
53  GetView().NoRotate();
54 
55  switch (rReq.GetSlot())
56  {
58  {
60  ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateTextTabDialog(rReq.GetFrameWeld(), &aNewAttr, pView));
61  sal_uInt16 nResult = pDlg->Execute();
62 
63  if (nResult == RET_OK)
64  {
65  if (pView->AreObjectsMarked())
66  {
67  pSh->StartAction();
68  pView->SetAttributes(*pDlg->GetOutputItemSet());
69  rReq.Done(*(pDlg->GetOutputItemSet()));
70  pSh->EndAction();
71  }
72  }
73  }
74  break;
75 
76  case SID_MEASURE_DLG:
77  {
78  bool bHasMarked = pView->AreObjectsMarked();
79 
82  aNewAttr, pView, RID_SVXPAGE_MEASURE));
83  if (pDlg->Execute() == RET_OK)
84  {
85  pSh->StartAction();
86  if (bHasMarked)
87  pView->SetAttrToMarked(*pDlg->GetOutputItemSet(), false);
88  else
89  pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
90  pSh->EndAction();
91  }
92  }
93  break;
94 
95  case SID_ATTRIBUTES_AREA:
96  {
97  bool bHasMarked = pView->AreObjectsMarked();
98 
101  &aNewAttr,
102  pDoc,
103  true));
104 
105  pDlg->StartExecuteAsync([bChanged, bHasMarked, pDoc, pDlg, pSh, pView, this](
106  sal_Int32 nResult){
107  if (nResult == RET_OK)
108  {
109  pSh->StartAction();
110  if (bHasMarked)
111  pView->SetAttributes(*pDlg->GetOutputItemSet());
112  else
113  pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
114  pSh->EndAction();
115 
116  static sal_uInt16 aInval[] =
117  {
118  SID_ATTR_FILL_STYLE,
119  SID_ATTR_FILL_COLOR,
120  SID_ATTR_FILL_TRANSPARENCE,
121  SID_ATTR_FILL_FLOATTRANSPARENCE,
122  0
123  };
124  SfxBindings &rBnd = GetView().GetViewFrame()->GetBindings();
125  rBnd.Invalidate(aInval);
126  rBnd.Update(SID_ATTR_FILL_STYLE);
127  rBnd.Update(SID_ATTR_FILL_COLOR);
128  rBnd.Update(SID_ATTR_FILL_TRANSPARENCE);
129  rBnd.Update(SID_ATTR_FILL_FLOATTRANSPARENCE);
130  }
131 
132  if (pDoc->IsChanged())
133  GetShell().SetModified();
134  else if (bChanged)
135  pDoc->SetChanged();
136 
137  pDlg->disposeOnce();
138  });
139  }
140  break;
141 
142  case SID_ATTRIBUTES_LINE:
143  {
144  bool bHasMarked = pView->AreObjectsMarked();
145 
146  const SdrObject* pObj = nullptr;
147  const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
148  if( rMarkList.GetMarkCount() == 1 )
149  pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
150 
153  &aNewAttr,
154  pDoc,
155  pObj,
156  bHasMarked));
157 
158  pDlg->StartExecuteAsync([bChanged, bHasMarked, pDoc, pDlg, pSh, pView, this](
159  sal_Int32 nResult){
160  if (nResult == RET_OK)
161  {
162  pSh->StartAction();
163  if(bHasMarked)
164  pView->SetAttrToMarked(*pDlg->GetOutputItemSet(), false);
165  else
166  pView->SetDefaultAttr(*pDlg->GetOutputItemSet(), false);
167  pSh->EndAction();
168 
169  static sal_uInt16 aInval[] =
170  {
171  SID_ATTR_LINE_STYLE, // ( SID_SVX_START + 169 )
172  SID_ATTR_LINE_DASH, // ( SID_SVX_START + 170 )
173  SID_ATTR_LINE_WIDTH, // ( SID_SVX_START + 171 )
174  SID_ATTR_LINE_COLOR, // ( SID_SVX_START + 172 )
175  SID_ATTR_LINE_START, // ( SID_SVX_START + 173 )
176  SID_ATTR_LINE_END, // ( SID_SVX_START + 174 )
177  SID_ATTR_LINE_TRANSPARENCE, // (SID_SVX_START+1107)
178  SID_ATTR_LINE_JOINT, // (SID_SVX_START+1110)
179  SID_ATTR_LINE_CAP, // (SID_SVX_START+1111)
180  0
181  };
182 
183  GetView().GetViewFrame()->GetBindings().Invalidate(aInval);
184  }
185 
186  if (pDoc->IsChanged())
187  GetShell().SetModified();
188  else if (bChanged)
189  pDoc->SetChanged();
190 
191  pDlg->disposeOnce();
192  });
193  }
194  break;
195 
196  default:
197  break;
198  }
199 
200  if (pDoc->IsChanged())
201  GetShell().SetModified();
202  else
203  if (bChanged)
204  pDoc->SetChanged();
205 }
206 
207 namespace
208 {
209  void lcl_convertStringArguments(sal_uInt16 nSlot, std::unique_ptr<SfxItemSet>& pArgs)
210  {
211  Color aColor;
212  OUString sColor;
213  const SfxPoolItem* pItem = nullptr;
214 
215  if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_COLOR_STR, false, &pItem))
216  {
217  sColor = static_cast<const SfxStringItem*>(pItem)->GetValue();
218 
219  if (sColor == "transparent")
220  aColor = COL_TRANSPARENT;
221  else
222  aColor = Color(sColor.toInt32(16));
223 
224  switch (nSlot)
225  {
226  case SID_ATTR_LINE_COLOR:
227  {
228  XLineColorItem aLineColorItem(OUString(), aColor);
229  pArgs->Put(aLineColorItem);
230  break;
231  }
232 
233  case SID_ATTR_FILL_COLOR:
234  {
235  XFillColorItem aFillColorItem(OUString(), aColor);
236  pArgs->Put(aFillColorItem);
237  break;
238  }
239  }
240  }
241  else if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_LINE_WIDTH_ARG, false, &pItem))
242  {
243  double fValue = static_cast<const SvxDoubleItem*>(pItem)->GetValue();
244  // FIXME: different units...
245  int nPow = 100;
246  int nValue = fValue * nPow;
247 
248  XLineWidthItem aItem(nValue);
249  pArgs->Put(aItem);
250  }
251  if (SfxItemState::SET == pArgs->GetItemState(SID_FILL_GRADIENT_JSON, false, &pItem))
252  {
253  const SfxStringItem* pJSON = static_cast<const SfxStringItem*>(pItem);
254  if (pJSON)
255  {
256  XGradient aGradient = XGradient::fromJSON(pJSON->GetValue());
257  XFillGradientItem aItem(aGradient);
258  pArgs->Put(aItem);
259  }
260  }
261  }
262 }
263 
265 {
266  SwWrtShell* pSh = &GetShell();
267  SdrView* pView = pSh->GetDrawView();
268  const SfxItemSet* pArgs = rReq.GetArgs();
269  bool bChanged = pView->GetModel()->IsChanged();
270  pView->GetModel()->SetChanged(false);
271 
272  GetView().NoRotate();
273 
274  if (pArgs)
275  {
276  if(pView->AreObjectsMarked())
277  {
278  std::unique_ptr<SfxItemSet> pNewArgs = pArgs->Clone();
279  lcl_convertStringArguments(rReq.GetSlot(), pNewArgs);
280  pView->SetAttrToMarked(*pNewArgs, false);
281  }
282  else
283  pView->SetDefaultAttr(*rReq.GetArgs(), false);
284  }
285  else
286  {
287  SfxDispatcher* pDis = pSh->GetView().GetViewFrame()->GetDispatcher();
288  switch (rReq.GetSlot())
289  {
290  case SID_ATTR_FILL_STYLE:
291  case SID_ATTR_FILL_COLOR:
292  case SID_ATTR_FILL_GRADIENT:
293  case SID_ATTR_FILL_HATCH:
294  case SID_ATTR_FILL_BITMAP:
295  case SID_ATTR_FILL_TRANSPARENCE:
296  case SID_ATTR_FILL_FLOATTRANSPARENCE:
297  pDis->Execute(SID_ATTRIBUTES_AREA);
298  break;
299  case SID_ATTR_LINE_STYLE:
300  case SID_ATTR_LINE_DASH:
301  case SID_ATTR_LINE_WIDTH:
302  case SID_ATTR_LINE_COLOR:
303  case SID_ATTR_LINE_TRANSPARENCE:
304  case SID_ATTR_LINE_JOINT:
305  case SID_ATTR_LINE_CAP:
306  pDis->Execute(SID_ATTRIBUTES_LINE);
307  break;
308  }
309  }
310  if (pView->GetModel()->IsChanged())
311  GetShell().SetModified();
312  else
313  if (bChanged)
314  pView->GetModel()->SetChanged();
315 }
316 
318 {
319  SdrView* pSdrView = GetShell().GetDrawView();
320 
321  if (pSdrView->AreObjectsMarked())
322  {
323  bool bDisable = Disable( rSet );
324 
325  if( !bDisable )
326  pSdrView->GetAttributes( rSet );
327  }
328  else
329  rSet.Put(pSdrView->GetDefaultAttr());
330 }
331 
332 /* 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:317
void Done(bool bRemove=false)
SdrMark * GetMark(size_t nNum) const
void ExecDrawAttrArgs(SfxRequest const &rReq)
Definition: drawdlg.cxx:264
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
sal_Int16 const nValue
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)
SdrObject * GetMarkedSdrObj() const
Shell * GetShell()
void EndAction(const bool bIdleEnd=false, const bool DoSetPosX=false)
Definition: crsrsh.cxx:232
const OUString & GetValue() const
const SdrMarkList & GetMarkedObjectList() const
bool SetAttributes(const SfxItemSet &rSet, bool bReplaceAll=false)
#define FN_DRAWTEXT_ATTR_DLG
Definition: cmdid.h:233
void SetDefaultAttr(const SfxItemSet &rAttr, bool bReplaceAll)
bool IsChanged() const
void StartAction()
Definition: crsrsh.cxx:215
virtual VclPtr< SfxAbstractTabDialog > CreateTextTabDialog(weld::Window *pParent, const SfxItemSet *pAttrSet, SdrView *pView)=0
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:42
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)
SdrModel * GetModel() const
virtual VclPtr< SfxAbstractTabDialog > CreateSvxLineTabDialog(weld::Window *pParent, const SfxItemSet *pAttr, SdrModel *pModel, const SdrObject *pObj, bool bHasObj)=0