1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: beziersh.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
36 #include <svx/svdview.hxx>
37 #include <svx/srchitem.hxx>
38 #include <svtools/eitem.hxx>
39 #include <svtools/whiter.hxx>
40 #include <svx/svdopath.hxx>
41 #include <sfx2/request.hxx>
42 #include <sfx2/dispatch.hxx>
43 #include <sfx2/objface.hxx>
49 #include "globals.hrc"
50 #include "drawbase.hxx"
51 #include "beziersh.hxx"
55 #include <sfx2/msg.hxx>
56 #include "swslots.hxx"
61 SFX_IMPL_INTERFACE(SwBezierShell
, SwBaseShell
, SW_RES(STR_SHELLNAME_BEZIER
))
63 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_DRAW_POPUPMENU
));
64 SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT
, SW_RES(RID_BEZIER_TOOLBOX
));
67 TYPEINIT1(SwBezierShell
,SwBaseShell
)
69 /*--------------------------------------------------------------------
71 --------------------------------------------------------------------*/
74 SwBezierShell::SwBezierShell(SwView
&_rView
):
77 SetName(C2S("Bezier"));
78 SetHelpId(SW_BEZIERSHELL
);
80 SwWrtShell
*pSh
= &GetShell();
81 SdrView
* pSdrView
= pSh
->GetDrawView();
82 pSdrView
->SetEliminatePolyPointLimitAngle(1500L);
85 /*--------------------------------------------------------------------
87 --------------------------------------------------------------------*/
90 void SwBezierShell::Execute(SfxRequest
&rReq
)
92 SwWrtShell
*pSh
= &GetShell();
93 SdrView
* pSdrView
= pSh
->GetDrawView();
94 const SfxItemSet
*pArgs
= rReq
.GetArgs();
95 USHORT nSlotId
= rReq
.GetSlot();
96 BOOL bChanged
= pSdrView
->GetModel()->IsChanged();
97 pSdrView
->GetModel()->SetChanged(FALSE
);
98 const SfxPoolItem
* pItem
;
100 pArgs
->GetItemState(nSlotId
, FALSE
, &pItem
);
106 if (pSh
->IsObjSelected())
108 if (pSdrView
->HasMarkedPoints())
109 pSh
->GetView().GetViewFrame()->GetDispatcher()->Execute(SID_BEZIER_DELETE
, FALSE
);
112 pSh
->DelSelectedObj();
113 if (pSh
->IsSelFrmMode())
115 pSh
->LeaveSelFrmMode();
118 GetView().AttrChangedNotify(pSh
); // ggf Shellwechsel...
124 if (pSdrView
->HasMarkedPoints())
125 pSdrView
->UnmarkAllPoints();
128 if ( pSh
->IsDrawCreate() )
130 GetView().GetDrawFuncPtr()->BreakCreate();
131 GetView().AttrChangedNotify(pSh
); // ggf Shellwechsel...
133 else if ( pSh
->HasSelection() || GetView().IsDrawMode() )
135 GetView().LeaveDrawCreate();
137 GetView().AttrChangedNotify(pSh
); // ggf Shellwechsel...
142 case SID_BEZIER_MOVE
:
143 case SID_BEZIER_INSERT
:
145 GetView().GetEditWin().SetBezierMode(nSlotId
);
146 static USHORT __READONLY_DATA aInva
[] =
152 GetView().GetViewFrame()->GetBindings().Invalidate(aInva
);
156 case SID_BEZIER_DELETE
:
157 case SID_BEZIER_CUTLINE
:
158 case SID_BEZIER_CONVERT
:
159 case SID_BEZIER_EDGE
:
160 case SID_BEZIER_SMOOTH
:
161 case SID_BEZIER_SYMMTR
:
162 case SID_BEZIER_CLOSE
:
163 case SID_BEZIER_ELIMINATE_POINTS
:
165 const SdrMarkList
& rMarkList
= pSdrView
->GetMarkedObjectList();
167 if (rMarkList
.GetMark(0) && !pSdrView
->IsAction())
171 case SID_BEZIER_DELETE
:
172 pSdrView
->DeleteMarkedPoints();
175 case SID_BEZIER_CUTLINE
:
177 pSdrView
->RipUpAtMarkedPoints();
178 pSh
->CheckUnboundObjects();
182 case SID_BEZIER_CONVERT
:
184 pSdrView
->SetMarkedSegmentsKind(SDRPATHSEGMENT_TOGGLE
);
188 case SID_BEZIER_EDGE
:
189 case SID_BEZIER_SMOOTH
:
190 case SID_BEZIER_SYMMTR
:
192 SdrPathSmoothKind eKind
= SDRPATHSMOOTH_ASYMMETRIC
;
196 case SID_BEZIER_EDGE
: eKind
= SDRPATHSMOOTH_ANGULAR
; break;
197 case SID_BEZIER_SMOOTH
: eKind
= SDRPATHSMOOTH_ASYMMETRIC
; break;
198 case SID_BEZIER_SYMMTR
: eKind
= SDRPATHSMOOTH_SYMMETRIC
; break;
201 SdrPathSmoothKind eSmooth
= pSdrView
->GetMarkedPointsSmooth();
202 if (eKind
!= eSmooth
)
204 pSdrView
->SetMarkedPointsSmooth(eKind
);
206 static USHORT __READONLY_DATA aInva
[] =
213 GetView().GetViewFrame()->GetBindings().Invalidate(aInva
);
218 case SID_BEZIER_CLOSE
:
220 SdrPathObj
* pPathObj
= (SdrPathObj
*) rMarkList
.GetMark(0)->GetMarkedSdrObj();
221 pSdrView
->UnmarkAllPoints();
222 // Size aDist(GetView().GetEditWin().PixelToLogic(Size(8,8)));
223 pPathObj
->ToggleClosed(); // aDist.Width());
227 case SID_BEZIER_ELIMINATE_POINTS
:
228 pSdrView
->SetEliminatePolyPoints(!pSdrView
->IsEliminatePolyPoints());
239 if (pSdrView
->GetModel()->IsChanged())
240 GetShell().SetModified();
242 pSdrView
->GetModel()->SetChanged(TRUE
);
245 /*--------------------------------------------------------------------
247 --------------------------------------------------------------------*/
250 void SwBezierShell::GetState(SfxItemSet
&rSet
)
252 SdrView
* pSdrView
= GetShell().GetDrawView();
254 SfxWhichIter
aIter( rSet
);
255 USHORT nWhich
= aIter
.FirstWhich();
261 case SID_BEZIER_MOVE
:
262 case SID_BEZIER_INSERT
:
264 USHORT nEditMode
= GetView().GetEditWin().GetBezierMode();
266 rSet
.Put(SfxBoolItem(nWhich
, nEditMode
== nWhich
));
270 case SID_BEZIER_CUTLINE
:
271 if (!pSdrView
->IsRipUpAtMarkedPointsPossible())
273 rSet
.DisableItem(SID_BEZIER_CUTLINE
);
277 case SID_BEZIER_DELETE
:
278 if (!pSdrView
->IsDeleteMarkedPointsPossible())
280 rSet
.DisableItem(SID_BEZIER_DELETE
);
284 case SID_BEZIER_CONVERT
:
285 if (!pSdrView
->IsSetMarkedSegmentsKindPossible())
287 rSet
.DisableItem(SID_BEZIER_CONVERT
);
291 SdrPathSegmentKind eSegm
= pSdrView
->GetMarkedSegmentsKind();
294 case SDRPATHSEGMENT_DONTCARE
: rSet
.InvalidateItem(SID_BEZIER_CONVERT
); break;
295 case SDRPATHSEGMENT_LINE
: rSet
.Put(SfxBoolItem(SID_BEZIER_CONVERT
,FALSE
)); break; // Button reingedrueckt = Kurve
296 case SDRPATHSEGMENT_CURVE
: rSet
.Put(SfxBoolItem(SID_BEZIER_CONVERT
,TRUE
)); break;
297 default:; //prevent warning
302 case SID_BEZIER_EDGE
:
303 case SID_BEZIER_SMOOTH
:
304 case SID_BEZIER_SYMMTR
:
305 if (!pSdrView
->IsSetMarkedPointsSmoothPossible())
306 rSet
.DisableItem(nWhich
);
309 SdrPathSmoothKind eSmooth
= pSdrView
->GetMarkedPointsSmooth();
310 BOOL bEnable
= FALSE
;
313 case SDRPATHSMOOTH_DONTCARE
:
315 case SDRPATHSMOOTH_ANGULAR
:
316 bEnable
= nWhich
== SID_BEZIER_EDGE
;
318 case SDRPATHSMOOTH_ASYMMETRIC
:
319 bEnable
= nWhich
== SID_BEZIER_SMOOTH
;
321 case SDRPATHSMOOTH_SYMMETRIC
:
322 bEnable
= nWhich
== SID_BEZIER_SYMMTR
;
325 rSet
.Put(SfxBoolItem(nWhich
, bEnable
));
329 case SID_BEZIER_CLOSE
:
330 if (!pSdrView
->IsOpenCloseMarkedObjectsPossible())
332 rSet
.DisableItem(SID_BEZIER_CLOSE
);
336 SdrObjClosedKind eClose
= pSdrView
->GetMarkedObjectsClosedState();
339 case SDROBJCLOSED_DONTCARE
: rSet
.InvalidateItem(SID_BEZIER_CLOSE
); break;
340 case SDROBJCLOSED_OPEN
: rSet
.Put(SfxBoolItem(SID_BEZIER_CLOSE
,FALSE
)); break;
341 case SDROBJCLOSED_CLOSED
: rSet
.Put(SfxBoolItem(SID_BEZIER_CLOSE
,TRUE
)); break;
342 default:; //prevent warning
347 case SID_BEZIER_ELIMINATE_POINTS
:
348 rSet
.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS
, pSdrView
->IsEliminatePolyPoints()));
354 nWhich
= aIter
.NextWhich();