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/srchitem.hxx>
23 #include <svl/eitem.hxx>
24 #include <svl/whiter.hxx>
25 #include <svx/svdopath.hxx>
26 #include <sfx2/sidebar/EnumContext.hxx>
27 #include <sfx2/request.hxx>
28 #include <sfx2/dispatch.hxx>
29 #include <sfx2/objface.hxx>
35 #include "globals.hrc"
36 #include "drawbase.hxx"
37 #include "beziersh.hxx"
41 #include <sfx2/msg.hxx>
42 #include "swslots.hxx"
46 SFX_IMPL_INTERFACE(SwBezierShell
, SwBaseShell
, SW_RES(STR_SHELLNAME_BEZIER
))
48 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_DRAW_POPUPMENU
));
49 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT
, SW_RES(RID_BEZIER_TOOLBOX
));
52 TYPEINIT1(SwBezierShell
,SwBaseShell
)
54 SwBezierShell::SwBezierShell(SwView
&_rView
):
57 SetName(OUString("Bezier"));
58 SetHelpId(SW_BEZIERSHELL
);
60 SwWrtShell
*pSh
= &GetShell();
61 SdrView
* pSdrView
= pSh
->GetDrawView();
62 pSdrView
->SetEliminatePolyPointLimitAngle(1500L);
64 SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Draw
));
67 void SwBezierShell::Execute(SfxRequest
&rReq
)
69 SwWrtShell
*pSh
= &GetShell();
70 SdrView
* pSdrView
= pSh
->GetDrawView();
71 const SfxItemSet
*pArgs
= rReq
.GetArgs();
72 sal_uInt16 nSlotId
= rReq
.GetSlot();
73 sal_Bool bChanged
= pSdrView
->GetModel()->IsChanged();
74 pSdrView
->GetModel()->SetChanged(sal_False
);
75 const SfxPoolItem
* pItem
;
77 pArgs
->GetItemState(nSlotId
, sal_False
, &pItem
);
83 if (pSh
->IsObjSelected())
85 if (pSdrView
->HasMarkedPoints())
86 pSh
->GetView().GetViewFrame()->GetDispatcher()->Execute(SID_BEZIER_DELETE
, sal_False
);
89 pSh
->DelSelectedObj();
90 if (pSh
->IsSelFrmMode())
92 pSh
->LeaveSelFrmMode();
95 GetView().AttrChangedNotify(pSh
); // Shell change if applicable...
101 if (pSdrView
->HasMarkedPoints())
102 pSdrView
->UnmarkAllPoints();
105 if ( pSh
->IsDrawCreate() )
107 GetView().GetDrawFuncPtr()->BreakCreate();
108 GetView().AttrChangedNotify(pSh
); // Shell change if applicable...
110 else if ( pSh
->HasSelection() || GetView().IsDrawMode() )
112 GetView().LeaveDrawCreate();
114 GetView().AttrChangedNotify(pSh
); // Shell change if applicable...
119 case SID_BEZIER_MOVE
:
120 case SID_BEZIER_INSERT
:
122 GetView().GetEditWin().SetBezierMode(nSlotId
);
123 static sal_uInt16 aInva
[] =
129 GetView().GetViewFrame()->GetBindings().Invalidate(aInva
);
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
:
142 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
144 if (rMarkList
.GetMark(0) && !pSdrView
->IsAction())
148 case SID_BEZIER_DELETE
:
149 pSdrView
->DeleteMarkedPoints();
152 case SID_BEZIER_CUTLINE
:
154 pSdrView
->RipUpAtMarkedPoints();
155 pSh
->CheckUnboundObjects();
159 case SID_BEZIER_CONVERT
:
161 pSdrView
->SetMarkedSegmentsKind(SDRPATHSEGMENT_TOGGLE
);
165 case SID_BEZIER_EDGE
:
166 case SID_BEZIER_SMOOTH
:
167 case SID_BEZIER_SYMMTR
:
169 SdrPathSmoothKind eKind
= SDRPATHSMOOTH_ASYMMETRIC
;
173 case SID_BEZIER_EDGE
: eKind
= SDRPATHSMOOTH_ANGULAR
; break;
174 case SID_BEZIER_SMOOTH
: eKind
= SDRPATHSMOOTH_ASYMMETRIC
; break;
175 case SID_BEZIER_SYMMTR
: eKind
= SDRPATHSMOOTH_SYMMETRIC
; break;
178 SdrPathSmoothKind eSmooth
= pSdrView
->GetMarkedPointsSmooth();
179 if (eKind
!= eSmooth
)
181 pSdrView
->SetMarkedPointsSmooth(eKind
);
183 static sal_uInt16 aInva
[] =
190 GetView().GetViewFrame()->GetBindings().Invalidate(aInva
);
195 case SID_BEZIER_CLOSE
:
197 SdrPathObj
* pPathObj
= (SdrPathObj
*) rMarkList
.GetMark(0)->GetMarkedSdrObj();
198 pSdrView
->UnmarkAllPoints();
199 // Size aDist(GetView().GetEditWin().PixelToLogic(Size(8,8)));
200 pPathObj
->ToggleClosed(); // aDist.Width());
204 case SID_BEZIER_ELIMINATE_POINTS
:
205 pSdrView
->SetEliminatePolyPoints(!pSdrView
->IsEliminatePolyPoints());
216 if (pSdrView
->GetModel()->IsChanged())
217 GetShell().SetModified();
219 pSdrView
->GetModel()->SetChanged(sal_True
);
222 void SwBezierShell::GetState(SfxItemSet
&rSet
)
224 SdrView
* pSdrView
= GetShell().GetDrawView();
226 SfxWhichIter
aIter( rSet
);
227 sal_uInt16 nWhich
= aIter
.FirstWhich();
233 case SID_BEZIER_MOVE
:
234 case SID_BEZIER_INSERT
:
236 sal_uInt16 nEditMode
= GetView().GetEditWin().GetBezierMode();
238 rSet
.Put(SfxBoolItem(nWhich
, nEditMode
== nWhich
));
242 case SID_BEZIER_CUTLINE
:
243 if (!pSdrView
->IsRipUpAtMarkedPointsPossible())
245 rSet
.DisableItem(SID_BEZIER_CUTLINE
);
249 case SID_BEZIER_DELETE
:
250 if (!pSdrView
->IsDeleteMarkedPointsPossible())
252 rSet
.DisableItem(SID_BEZIER_DELETE
);
256 case SID_BEZIER_CONVERT
:
257 if (!pSdrView
->IsSetMarkedSegmentsKindPossible())
259 rSet
.DisableItem(SID_BEZIER_CONVERT
);
263 SdrPathSegmentKind eSegm
= pSdrView
->GetMarkedSegmentsKind();
266 case SDRPATHSEGMENT_DONTCARE
: rSet
.InvalidateItem(SID_BEZIER_CONVERT
); break;
267 case SDRPATHSEGMENT_LINE
: rSet
.Put(SfxBoolItem(SID_BEZIER_CONVERT
,sal_False
)); break; // Button pressed = curve
268 case SDRPATHSEGMENT_CURVE
: rSet
.Put(SfxBoolItem(SID_BEZIER_CONVERT
,sal_True
)); break;
269 default:; //prevent warning
274 case SID_BEZIER_EDGE
:
275 case SID_BEZIER_SMOOTH
:
276 case SID_BEZIER_SYMMTR
:
277 if (!pSdrView
->IsSetMarkedPointsSmoothPossible())
278 rSet
.DisableItem(nWhich
);
281 SdrPathSmoothKind eSmooth
= pSdrView
->GetMarkedPointsSmooth();
282 sal_Bool bEnable
= sal_False
;
285 case SDRPATHSMOOTH_DONTCARE
:
287 case SDRPATHSMOOTH_ANGULAR
:
288 bEnable
= nWhich
== SID_BEZIER_EDGE
;
290 case SDRPATHSMOOTH_ASYMMETRIC
:
291 bEnable
= nWhich
== SID_BEZIER_SMOOTH
;
293 case SDRPATHSMOOTH_SYMMETRIC
:
294 bEnable
= nWhich
== SID_BEZIER_SYMMTR
;
297 rSet
.Put(SfxBoolItem(nWhich
, bEnable
));
301 case SID_BEZIER_CLOSE
:
302 if (!pSdrView
->IsOpenCloseMarkedObjectsPossible())
304 rSet
.DisableItem(SID_BEZIER_CLOSE
);
308 SdrObjClosedKind eClose
= pSdrView
->GetMarkedObjectsClosedState();
311 case SDROBJCLOSED_DONTCARE
: rSet
.InvalidateItem(SID_BEZIER_CLOSE
); break;
312 case SDROBJCLOSED_OPEN
: rSet
.Put(SfxBoolItem(SID_BEZIER_CLOSE
,sal_False
)); break;
313 case SDROBJCLOSED_CLOSED
: rSet
.Put(SfxBoolItem(SID_BEZIER_CLOSE
,sal_True
)); break;
314 default:; //prevent warning
319 case SID_BEZIER_ELIMINATE_POINTS
:
320 rSet
.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS
, pSdrView
->IsEliminatePolyPoints()));
326 nWhich
= aIter
.NextWhich();
330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */