Update ooo320-m1
[ooovba.git] / sw / source / ui / shells / beziersh.cxx
blob613f3b732759fbb3a268f616c1892b912fbdf411
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: beziersh.cxx,v $
10 * $Revision: 1.13 $
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"
35 #include "cmdid.h"
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>
45 #include "wrtsh.hxx"
46 #include "view.hxx"
47 #include "edtwin.hxx"
48 #include "helpid.h"
49 #include "globals.hrc"
50 #include "drawbase.hxx"
51 #include "beziersh.hxx"
52 #include "popup.hrc"
53 #include "shells.hrc"
54 #define SwBezierShell
55 #include <sfx2/msg.hxx>
56 #include "swslots.hxx"
58 #include <unomid.h>
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 /*--------------------------------------------------------------------
70 Beschreibung:
71 --------------------------------------------------------------------*/
74 SwBezierShell::SwBezierShell(SwView &_rView):
75 SwBaseShell( _rView )
77 SetName(C2S("Bezier"));
78 SetHelpId(SW_BEZIERSHELL);
80 SwWrtShell *pSh = &GetShell();
81 SdrView* pSdrView = pSh->GetDrawView();
82 pSdrView->SetEliminatePolyPointLimitAngle(1500L);
85 /*--------------------------------------------------------------------
86 Beschreibung:
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;
99 if(pArgs)
100 pArgs->GetItemState(nSlotId, FALSE, &pItem);
102 switch (nSlotId)
104 case SID_DELETE:
105 case FN_BACKSPACE:
106 if (pSh->IsObjSelected())
108 if (pSdrView->HasMarkedPoints())
109 pSh->GetView().GetViewFrame()->GetDispatcher()->Execute(SID_BEZIER_DELETE, FALSE);
110 else
112 pSh->DelSelectedObj();
113 if (pSh->IsSelFrmMode())
115 pSh->LeaveSelFrmMode();
116 pSh->NoEdit();
118 GetView().AttrChangedNotify(pSh); // ggf Shellwechsel...
121 break;
123 case FN_ESCAPE:
124 if (pSdrView->HasMarkedPoints())
125 pSdrView->UnmarkAllPoints();
126 else
128 if ( pSh->IsDrawCreate() )
130 GetView().GetDrawFuncPtr()->BreakCreate();
131 GetView().AttrChangedNotify(pSh); // ggf Shellwechsel...
133 else if ( pSh->HasSelection() || GetView().IsDrawMode() )
135 GetView().LeaveDrawCreate();
136 pSh->EnterStdMode();
137 GetView().AttrChangedNotify(pSh); // ggf Shellwechsel...
140 break;
142 case SID_BEZIER_MOVE:
143 case SID_BEZIER_INSERT:
145 GetView().GetEditWin().SetBezierMode(nSlotId);
146 static USHORT __READONLY_DATA aInva[] =
148 SID_BEZIER_INSERT,
149 SID_BEZIER_MOVE,
152 GetView().GetViewFrame()->GetBindings().Invalidate(aInva);
154 break;
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())
169 switch (nSlotId)
171 case SID_BEZIER_DELETE:
172 pSdrView->DeleteMarkedPoints();
173 break;
175 case SID_BEZIER_CUTLINE:
177 pSdrView->RipUpAtMarkedPoints();
178 pSh->CheckUnboundObjects();
180 break;
182 case SID_BEZIER_CONVERT:
184 pSdrView->SetMarkedSegmentsKind(SDRPATHSEGMENT_TOGGLE);
185 break;
188 case SID_BEZIER_EDGE:
189 case SID_BEZIER_SMOOTH:
190 case SID_BEZIER_SYMMTR:
192 SdrPathSmoothKind eKind = SDRPATHSMOOTH_ASYMMETRIC;
194 switch (nSlotId)
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[] =
208 SID_BEZIER_SMOOTH,
209 SID_BEZIER_EDGE,
210 SID_BEZIER_SYMMTR,
213 GetView().GetViewFrame()->GetBindings().Invalidate(aInva);
215 break;
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());
224 break;
227 case SID_BEZIER_ELIMINATE_POINTS:
228 pSdrView->SetEliminatePolyPoints(!pSdrView->IsEliminatePolyPoints());
229 break;
233 break;
235 default:
236 break;
239 if (pSdrView->GetModel()->IsChanged())
240 GetShell().SetModified();
241 else if (bChanged)
242 pSdrView->GetModel()->SetChanged(TRUE);
245 /*--------------------------------------------------------------------
246 Beschreibung:
247 --------------------------------------------------------------------*/
250 void SwBezierShell::GetState(SfxItemSet &rSet)
252 SdrView* pSdrView = GetShell().GetDrawView();
254 SfxWhichIter aIter( rSet );
255 USHORT nWhich = aIter.FirstWhich();
257 while( nWhich )
259 switch( nWhich )
261 case SID_BEZIER_MOVE:
262 case SID_BEZIER_INSERT:
264 USHORT nEditMode = GetView().GetEditWin().GetBezierMode();
266 rSet.Put(SfxBoolItem(nWhich, nEditMode == nWhich));
268 break;
270 case SID_BEZIER_CUTLINE:
271 if (!pSdrView->IsRipUpAtMarkedPointsPossible())
273 rSet.DisableItem(SID_BEZIER_CUTLINE);
275 break;
277 case SID_BEZIER_DELETE:
278 if (!pSdrView->IsDeleteMarkedPointsPossible())
280 rSet.DisableItem(SID_BEZIER_DELETE);
282 break;
284 case SID_BEZIER_CONVERT:
285 if (!pSdrView->IsSetMarkedSegmentsKindPossible())
287 rSet.DisableItem(SID_BEZIER_CONVERT);
289 else
291 SdrPathSegmentKind eSegm = pSdrView->GetMarkedSegmentsKind();
292 switch (eSegm)
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
300 break;
302 case SID_BEZIER_EDGE:
303 case SID_BEZIER_SMOOTH:
304 case SID_BEZIER_SYMMTR:
305 if (!pSdrView->IsSetMarkedPointsSmoothPossible())
306 rSet.DisableItem(nWhich);
307 else
309 SdrPathSmoothKind eSmooth = pSdrView->GetMarkedPointsSmooth();
310 BOOL bEnable = FALSE;
311 switch (eSmooth)
313 case SDRPATHSMOOTH_DONTCARE :
314 break;
315 case SDRPATHSMOOTH_ANGULAR :
316 bEnable = nWhich == SID_BEZIER_EDGE;
317 break;
318 case SDRPATHSMOOTH_ASYMMETRIC:
319 bEnable = nWhich == SID_BEZIER_SMOOTH;
320 break;
321 case SDRPATHSMOOTH_SYMMETRIC :
322 bEnable = nWhich == SID_BEZIER_SYMMTR;
323 break;
325 rSet.Put(SfxBoolItem(nWhich, bEnable));
327 break;
329 case SID_BEZIER_CLOSE:
330 if (!pSdrView->IsOpenCloseMarkedObjectsPossible())
332 rSet.DisableItem(SID_BEZIER_CLOSE);
334 else
336 SdrObjClosedKind eClose = pSdrView->GetMarkedObjectsClosedState();
337 switch (eClose)
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
345 break;
347 case SID_BEZIER_ELIMINATE_POINTS:
348 rSet.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS, pSdrView->IsEliminatePolyPoints()));
349 break;
351 default:
352 break;
354 nWhich = aIter.NextWhich();