LibreOffice Module sw (master)  1
beziersh.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 <cmdid.h>
21 #include <svx/svdview.hxx>
22 #include <svl/srchitem.hxx>
23 #include <svl/eitem.hxx>
24 #include <svl/whiter.hxx>
25 #include <svx/svdopath.hxx>
26 #include <svx/svxids.hrc>
27 #include <vcl/EnumContext.hxx>
28 #include <sfx2/request.hxx>
29 #include <sfx2/dispatch.hxx>
30 #include <sfx2/objface.hxx>
31 #include <sfx2/viewfrm.hxx>
32 
33 #include <wrtsh.hxx>
34 #include <view.hxx>
35 #include <edtwin.hxx>
36 #include <globals.hrc>
37 #include <drawbase.hxx>
38 #include <beziersh.hxx>
39 #define ShellClass_SwBezierShell
40 #include <sfx2/msg.hxx>
41 #include <swslots.hxx>
42 
43 #include <unomid.h>
44 
46 
47 void SwBezierShell::InitInterface_Impl()
48 {
49  GetStaticInterface()->RegisterPopupMenu("draw");
50 
51  GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT, SfxVisibilityFlags::Invisible, ToolbarId::Bezier_Toolbox_Sw);
52 }
53 
54 
56  SwBaseShell( _rView )
57 {
58  SetName("Bezier");
59 
60  SwWrtShell *pSh = &GetShell();
61  SdrView* pSdrView = pSh->GetDrawView();
62  pSdrView->SetEliminatePolyPointLimitAngle(1500);
63 
65 }
66 
68 {
69  SwWrtShell *pSh = &GetShell();
70  SdrView* pSdrView = pSh->GetDrawView();
71  const SfxItemSet *pArgs = rReq.GetArgs();
72  sal_uInt16 nSlotId = rReq.GetSlot();
73  bool bChanged = pSdrView->GetModel()->IsChanged();
74  pSdrView->GetModel()->SetChanged(false);
75  const SfxPoolItem* pItem;
76  if(pArgs)
77  pArgs->GetItemState(nSlotId, false, &pItem);
78 
79  switch (nSlotId)
80  {
81  case SID_DELETE:
82  case FN_BACKSPACE:
83  if (pSh->IsObjSelected())
84  {
85  if (pSdrView->HasMarkedPoints())
86  pSh->GetView().GetViewFrame()->GetDispatcher()->Execute(SID_BEZIER_DELETE);
87  else
88  {
89  pSh->DelSelectedObj();
90  if (pSh->IsSelFrameMode())
91  {
92  pSh->LeaveSelFrameMode();
93  pSh->NoEdit();
94  }
95  GetView().AttrChangedNotify(nullptr); // Shell change if applicable...
96  }
97  }
98  break;
99 
100  case FN_ESCAPE:
101  if (pSdrView->HasMarkedPoints())
102  pSdrView->UnmarkAllPoints();
103  else
104  {
105  if ( pSh->IsDrawCreate() )
106  {
108  GetView().AttrChangedNotify(nullptr); // Shell change if applicable...
109  }
110  else if ( pSh->HasSelection() || GetView().IsDrawMode() )
111  {
113  pSh->EnterStdMode();
114  GetView().AttrChangedNotify(nullptr); // Shell change if applicable...
115  }
116  }
117  break;
118 
119  case SID_BEZIER_MOVE:
120  case SID_BEZIER_INSERT:
121  {
122  GetView().GetEditWin().SetBezierMode(nSlotId);
123  static sal_uInt16 aInva[] =
124  {
125  SID_BEZIER_INSERT,
126  SID_BEZIER_MOVE,
127  0
128  };
130  }
131  break;
132 
133  case SID_BEZIER_DELETE:
134  case SID_BEZIER_CUTLINE:
135  case SID_BEZIER_CONVERT:
136  case SID_BEZIER_EDGE:
137  case SID_BEZIER_SMOOTH:
138  case SID_BEZIER_SYMMTR:
139  case SID_BEZIER_CLOSE:
140  case SID_BEZIER_ELIMINATE_POINTS:
141  {
142  const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
143 
144  if (rMarkList.GetMark(0) && !pSdrView->IsAction())
145  {
146  switch (nSlotId)
147  {
148  case SID_BEZIER_DELETE:
149  pSdrView->DeleteMarkedPoints();
150  break;
151 
152  case SID_BEZIER_CUTLINE:
153  {
154  pSdrView->RipUpAtMarkedPoints();
155  pSh->CheckUnboundObjects();
156  }
157  break;
158 
159  case SID_BEZIER_CONVERT:
160  {
161  pSdrView->SetMarkedSegmentsKind(SdrPathSegmentKind::Toggle);
162  break;
163  }
164 
165  case SID_BEZIER_EDGE:
166  case SID_BEZIER_SMOOTH:
167  case SID_BEZIER_SYMMTR:
168  {
169  SdrPathSmoothKind eKind = SdrPathSmoothKind::Asymmetric;
170 
171  switch (nSlotId)
172  {
173  case SID_BEZIER_EDGE: eKind = SdrPathSmoothKind::Angular; break;
174  case SID_BEZIER_SMOOTH: eKind = SdrPathSmoothKind::Asymmetric; break;
175  case SID_BEZIER_SYMMTR: eKind = SdrPathSmoothKind::Symmetric; break;
176  }
177 
178  SdrPathSmoothKind eSmooth = pSdrView->GetMarkedPointsSmooth();
179  if (eKind != eSmooth)
180  {
181  pSdrView->SetMarkedPointsSmooth(eKind);
182 
183  static sal_uInt16 aInva[] =
184  {
185  SID_BEZIER_SMOOTH,
186  SID_BEZIER_EDGE,
187  SID_BEZIER_SYMMTR,
188  0
189  };
191  }
192  break;
193  }
194 
195  case SID_BEZIER_CLOSE:
196  {
197  SdrPathObj* pPathObj = static_cast<SdrPathObj*>( rMarkList.GetMark(0)->GetMarkedSdrObj() );
198  pSdrView->UnmarkAllPoints();
199  // Size aDist(GetView().GetEditWin().PixelToLogic(Size(8,8)));
200  pPathObj->ToggleClosed(); // aDist.Width());
201  break;
202  }
203 
204  case SID_BEZIER_ELIMINATE_POINTS:
205  pSdrView->SetEliminatePolyPoints(!pSdrView->IsEliminatePolyPoints());
206  break;
207  }
208  }
209  }
210  break;
211 
212  default:
213  break;
214  }
215 
216  if (pSdrView->GetModel()->IsChanged())
217  GetShell().SetModified();
218  else if (bChanged)
219  pSdrView->GetModel()->SetChanged();
220 }
221 
223 {
224  SdrView* pSdrView = GetShell().GetDrawView();
225 
226  SfxWhichIter aIter( rSet );
227  sal_uInt16 nWhich = aIter.FirstWhich();
228 
229  while( nWhich )
230  {
231  switch( nWhich )
232  {
233  case SID_BEZIER_MOVE:
234  case SID_BEZIER_INSERT:
235  {
236  sal_uInt16 nEditMode = GetView().GetEditWin().GetBezierMode();
237 
238  rSet.Put(SfxBoolItem(nWhich, nEditMode == nWhich));
239  }
240  break;
241 
242  case SID_BEZIER_CUTLINE:
243  if (!pSdrView->IsRipUpAtMarkedPointsPossible())
244  {
245  rSet.DisableItem(SID_BEZIER_CUTLINE);
246  }
247  break;
248 
249  case SID_BEZIER_DELETE:
250  if (!pSdrView->IsDeleteMarkedPointsPossible())
251  {
252  rSet.DisableItem(SID_BEZIER_DELETE);
253  }
254  break;
255 
256  case SID_BEZIER_CONVERT:
257  if (!pSdrView->IsSetMarkedSegmentsKindPossible())
258  {
259  rSet.DisableItem(SID_BEZIER_CONVERT);
260  }
261  else
262  {
263  SdrPathSegmentKind eSegm = pSdrView->GetMarkedSegmentsKind();
264  switch (eSegm)
265  {
266  case SdrPathSegmentKind::DontCare: rSet.InvalidateItem(SID_BEZIER_CONVERT); break;
267  case SdrPathSegmentKind::Line : rSet.Put(SfxBoolItem(SID_BEZIER_CONVERT,false)); break; // Button pressed = curve
268  case SdrPathSegmentKind::Curve : rSet.Put(SfxBoolItem(SID_BEZIER_CONVERT,true)); break;
269  default:; //prevent warning
270  }
271  }
272  break;
273 
274  case SID_BEZIER_EDGE:
275  case SID_BEZIER_SMOOTH:
276  case SID_BEZIER_SYMMTR:
277  if (!pSdrView->IsSetMarkedPointsSmoothPossible())
278  rSet.DisableItem(nWhich);
279  else
280  {
281  SdrPathSmoothKind eSmooth = pSdrView->GetMarkedPointsSmooth();
282  bool bEnable = false;
283  switch (eSmooth)
284  {
285  case SdrPathSmoothKind::DontCare :
286  break;
287  case SdrPathSmoothKind::Angular :
288  bEnable = nWhich == SID_BEZIER_EDGE;
289  break;
290  case SdrPathSmoothKind::Asymmetric:
291  bEnable = nWhich == SID_BEZIER_SMOOTH;
292  break;
293  case SdrPathSmoothKind::Symmetric :
294  bEnable = nWhich == SID_BEZIER_SYMMTR;
295  break;
296  }
297  rSet.Put(SfxBoolItem(nWhich, bEnable));
298  }
299  break;
300 
301  case SID_BEZIER_CLOSE:
302  if (!pSdrView->IsOpenCloseMarkedObjectsPossible())
303  {
304  rSet.DisableItem(SID_BEZIER_CLOSE);
305  }
306  else
307  {
308  SdrObjClosedKind eClose = pSdrView->GetMarkedObjectsClosedState();
309  switch (eClose)
310  {
311  case SdrObjClosedKind::DontCare: rSet.InvalidateItem(SID_BEZIER_CLOSE); break;
312  case SdrObjClosedKind::Open : rSet.Put(SfxBoolItem(SID_BEZIER_CLOSE,false)); break;
313  case SdrObjClosedKind::Closed : rSet.Put(SfxBoolItem(SID_BEZIER_CLOSE,true)); break;
314  default:; //prevent warning
315  }
316  }
317  break;
318 
319  case SID_BEZIER_ELIMINATE_POINTS:
320  rSet.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS, pSdrView->IsEliminatePolyPoints()));
321  break;
322 
323  default:
324  break;
325  }
326  nWhich = aIter.NextWhich();
327  }
328 }
329 
330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
bool IsEliminatePolyPoints() const
SwView & GetView()
Definition: basesh.hxx:57
bool IsDrawMode() const
Definition: view.hxx:526
#define SFX_IMPL_INTERFACE(Class, SuperClass)
SdrView * GetDrawView()
Definition: vnew.cxx:375
void DeleteMarkedPoints() override
SfxDispatcher * GetDispatcher()
SwWrtShell & GetShell()
Definition: basesh.cxx:2622
void CheckUnboundObjects()
Temporary work around for bug.
Definition: feshview.cxx:2730
void SetEliminatePolyPointLimitAngle(long nAngle)
SdrPathSegmentKind GetMarkedSegmentsKind() const override
void RipUpAtMarkedPoints() override
void InvalidateItem(sal_uInt16 nWhich)
sal_uInt16 FirstWhich()
void EnterStdMode()
Definition: select.cxx:552
SwEditWin & GetEditWin()
Definition: view.hxx:403
SdrMark * GetMark(size_t nNum) const
void SetMarkedSegmentsKind(SdrPathSegmentKind eKind) override
void SetModified()
Definition: edws.cxx:69
const SfxItemSet * GetArgs() const
void Invalidate(sal_uInt16 nId)
void GetState(SfxItemSet &)
Definition: beziersh.cxx:222
sal_uInt16 GetBezierMode() const
Definition: edtwin.hxx:217
void NoEdit(bool bHideCursor=true)
Definition: wrtsh1.cxx:160
sal_uInt16 NextWhich()
Used by the UI to modify the document model.
Definition: wrtsh.hxx:88
SdrPathSmoothKind GetMarkedPointsSmooth() const override
void BreakCreate()
Definition: drawbase.cxx:466
const SwView & GetView() const
Definition: wrtsh.hxx:426
virtual void SetChanged(bool bFlg=true)
bool IsDeleteMarkedPointsPossible() const override
SdrObjClosedKind GetMarkedObjectsClosedState() const override
void SetEliminatePolyPoints(bool bOn)
virtual bool HasMarkedPoints() const
SdrObject * GetMarkedSdrObj() const
bool HasSelection() const
Definition: wrtsh.hxx:139
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
SdrObjClosedKind
SfxBindings & GetBindings()
const SdrMarkList & GetMarkedObjectList() const
void SetMarkedPointsSmooth(SdrPathSmoothKind eKind) override
void SetName(const OUString &rName)
void LeaveDrawCreate()
Definition: view.hxx:525
SwDrawBase * GetDrawFuncPtr() const
Definition: view.hxx:513
#define SFX_OBJECTBAR_OBJECT
bool IsChanged() const
virtual bool IsAction() const override
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
static const OUString & GetContextName(const Context eContext)
bool UnmarkAllPoints()
void DisableItem(sal_uInt16 nWhich)
bool IsOpenCloseMarkedObjectsPossible() const override
bool IsSetMarkedSegmentsKindPossible() const override
bool IsRipUpAtMarkedPointsPossible() const override
SdrPathSmoothKind
void Execute(SfxRequest const &)
Definition: beziersh.cxx:67
#define FN_BACKSPACE
Definition: cmdid.h:642
size_t IsObjSelected() const
Definition: feshview.cxx:1167
void DelSelectedObj()
Definition: feshview.cxx:2297
void LeaveSelFrameMode()
Definition: select.cxx:721
SdrPathSegmentKind
void SetBezierMode(sal_uInt16 eBezMode)
Definition: edtwin.hxx:218
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
bool IsSetMarkedPointsSmoothPossible() const override
#define FN_ESCAPE
Definition: cmdid.h:656
bool IsDrawCreate() const
Definition: feshview.cxx:2148
void ToggleClosed()
SdrModel * GetModel() const
void SetContextName(const OUString &rsContextName)
Definition: view.hxx:146
bool IsSelFrameMode() const
Definition: wrtsh.hxx:168
SwBezierShell(SwView &rView)
Definition: beziersh.cxx:55