1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
34 #include <drawbase.hxx>
35 #include <beziersh.hxx>
36 #define ShellClass_SwBezierShell
37 #include <sfx2/msg.hxx>
38 #include <swslots.hxx>
40 SFX_IMPL_INTERFACE(SwBezierShell
, SwBaseShell
)
42 void SwBezierShell::InitInterface_Impl()
44 GetStaticInterface()->RegisterPopupMenu(u
"draw"_ustr
);
46 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT
, SfxVisibilityFlags::Invisible
, ToolbarId::Bezier_Toolbox_Sw
);
50 SwBezierShell::SwBezierShell(SwView
&_rView
):
53 SetName(u
"Bezier"_ustr
);
55 SwWrtShell
*pSh
= &GetShell();
56 SdrView
* pSdrView
= pSh
->GetDrawView();
57 pSdrView
->SetEliminatePolyPointLimitAngle(1500_deg100
);
59 SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Draw
));
62 void SwBezierShell::Execute(SfxRequest
const &rReq
)
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
;
72 pArgs
->GetItemState(nSlotId
, false, &pItem
);
78 if (pSh
->GetSelectedObjCount())
80 if (pSdrView
->HasMarkedPoints())
81 pSh
->GetView().GetViewFrame().GetDispatcher()->Execute(SID_BEZIER_DELETE
);
84 pSh
->DelSelectedObj();
85 if (pSh
->IsSelFrameMode())
87 pSh
->LeaveSelFrameMode();
90 GetView().AttrChangedNotify(nullptr); // Shell change if applicable...
96 if (pSdrView
->HasMarkedPoints())
97 pSdrView
->UnmarkAllPoints();
100 if ( pSh
->IsDrawCreate() )
102 GetView().GetDrawFuncPtr()->BreakCreate();
103 GetView().AttrChangedNotify(nullptr); // Shell change if applicable...
105 else if ( pSh
->HasSelection() || GetView().IsDrawMode() )
107 GetView().LeaveDrawCreate();
109 GetView().AttrChangedNotify(nullptr); // Shell change if applicable...
114 case SID_BEZIER_MOVE
:
115 case SID_BEZIER_INSERT
:
117 GetView().GetEditWin().SetBezierMode(nSlotId
);
118 static sal_uInt16 aInva
[] =
124 GetView().GetViewFrame().GetBindings().Invalidate(aInva
);
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
:
137 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
139 if (rMarkList
.GetMark(0) && !pSdrView
->IsAction())
143 case SID_BEZIER_DELETE
:
144 pSdrView
->DeleteMarkedPoints();
147 case SID_BEZIER_CUTLINE
:
149 pSdrView
->RipUpAtMarkedPoints();
150 pSh
->CheckUnboundObjects();
154 case SID_BEZIER_CONVERT
:
156 pSdrView
->SetMarkedSegmentsKind(SdrPathSegmentKind::Toggle
);
160 case SID_BEZIER_EDGE
:
161 case SID_BEZIER_SMOOTH
:
162 case SID_BEZIER_SYMMTR
:
164 SdrPathSmoothKind eKind
= SdrPathSmoothKind::Asymmetric
;
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;
173 SdrPathSmoothKind eSmooth
= pSdrView
->GetMarkedPointsSmooth();
174 if (eKind
!= eSmooth
)
176 pSdrView
->SetMarkedPointsSmooth(eKind
);
178 static sal_uInt16 aInva
[] =
185 GetView().GetViewFrame().GetBindings().Invalidate(aInva
);
190 case SID_BEZIER_CLOSE
:
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());
199 case SID_BEZIER_ELIMINATE_POINTS
:
200 pSdrView
->SetEliminatePolyPoints(!pSdrView
->IsEliminatePolyPoints());
211 if (pSdrView
->GetModel().IsChanged())
212 GetShell().SetModified();
214 pSdrView
->GetModel().SetChanged();
217 void SwBezierShell::GetState(SfxItemSet
&rSet
)
219 SdrView
* pSdrView
= GetShell().GetDrawView();
221 SfxWhichIter
aIter( rSet
);
222 sal_uInt16 nWhich
= aIter
.FirstWhich();
228 case SID_BEZIER_MOVE
:
229 case SID_BEZIER_INSERT
:
231 sal_uInt16 nEditMode
= GetView().GetEditWin().GetBezierMode();
233 rSet
.Put(SfxBoolItem(nWhich
, nEditMode
== nWhich
));
237 case SID_BEZIER_CUTLINE
:
238 if (!pSdrView
->IsRipUpAtMarkedPointsPossible())
240 rSet
.DisableItem(SID_BEZIER_CUTLINE
);
244 case SID_BEZIER_DELETE
:
245 if (!pSdrView
->IsDeleteMarkedPointsPossible())
247 rSet
.DisableItem(SID_BEZIER_DELETE
);
251 case SID_BEZIER_CONVERT
:
252 if (!pSdrView
->IsSetMarkedSegmentsKindPossible())
254 rSet
.DisableItem(SID_BEZIER_CONVERT
);
258 SdrPathSegmentKind eSegm
= pSdrView
->GetMarkedSegmentsKind();
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
269 case SID_BEZIER_EDGE
:
270 case SID_BEZIER_SMOOTH
:
271 case SID_BEZIER_SYMMTR
:
272 if (!pSdrView
->IsSetMarkedPointsSmoothPossible())
273 rSet
.DisableItem(nWhich
);
276 SdrPathSmoothKind eSmooth
= pSdrView
->GetMarkedPointsSmooth();
277 bool bEnable
= false;
280 case SdrPathSmoothKind::DontCare
:
282 case SdrPathSmoothKind::Angular
:
283 bEnable
= nWhich
== SID_BEZIER_EDGE
;
285 case SdrPathSmoothKind::Asymmetric
:
286 bEnable
= nWhich
== SID_BEZIER_SMOOTH
;
288 case SdrPathSmoothKind::Symmetric
:
289 bEnable
= nWhich
== SID_BEZIER_SYMMTR
;
292 rSet
.Put(SfxBoolItem(nWhich
, bEnable
));
296 case SID_BEZIER_CLOSE
:
297 if (!pSdrView
->IsOpenCloseMarkedObjectsPossible())
299 rSet
.DisableItem(SID_BEZIER_CLOSE
);
303 SdrObjClosedKind eClose
= pSdrView
->GetMarkedObjectsClosedState();
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
314 case SID_BEZIER_ELIMINATE_POINTS
:
315 rSet
.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS
, pSdrView
->IsEliminatePolyPoints()));
321 nWhich
= aIter
.NextWhich();
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */