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