update credits
[LibreOffice.git] / sw / source / ui / shells / beziersh.cxx
blobfe87a0a8b93aab16c91815530b44815394167d1d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "cmdid.h"
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>
31 #include "wrtsh.hxx"
32 #include "view.hxx"
33 #include "edtwin.hxx"
34 #include "helpid.h"
35 #include "globals.hrc"
36 #include "drawbase.hxx"
37 #include "beziersh.hxx"
38 #include "popup.hrc"
39 #include "shells.hrc"
40 #define SwBezierShell
41 #include <sfx2/msg.hxx>
42 #include "swslots.hxx"
44 #include <unomid.h>
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):
55 SwBaseShell( _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;
76 if(pArgs)
77 pArgs->GetItemState(nSlotId, sal_False, &pItem);
79 switch (nSlotId)
81 case SID_DELETE:
82 case FN_BACKSPACE:
83 if (pSh->IsObjSelected())
85 if (pSdrView->HasMarkedPoints())
86 pSh->GetView().GetViewFrame()->GetDispatcher()->Execute(SID_BEZIER_DELETE, sal_False);
87 else
89 pSh->DelSelectedObj();
90 if (pSh->IsSelFrmMode())
92 pSh->LeaveSelFrmMode();
93 pSh->NoEdit();
95 GetView().AttrChangedNotify(pSh); // Shell change if applicable...
98 break;
100 case FN_ESCAPE:
101 if (pSdrView->HasMarkedPoints())
102 pSdrView->UnmarkAllPoints();
103 else
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();
113 pSh->EnterStdMode();
114 GetView().AttrChangedNotify(pSh); // Shell change if applicable...
117 break;
119 case SID_BEZIER_MOVE:
120 case SID_BEZIER_INSERT:
122 GetView().GetEditWin().SetBezierMode(nSlotId);
123 static sal_uInt16 aInva[] =
125 SID_BEZIER_INSERT,
126 SID_BEZIER_MOVE,
129 GetView().GetViewFrame()->GetBindings().Invalidate(aInva);
131 break;
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())
146 switch (nSlotId)
148 case SID_BEZIER_DELETE:
149 pSdrView->DeleteMarkedPoints();
150 break;
152 case SID_BEZIER_CUTLINE:
154 pSdrView->RipUpAtMarkedPoints();
155 pSh->CheckUnboundObjects();
157 break;
159 case SID_BEZIER_CONVERT:
161 pSdrView->SetMarkedSegmentsKind(SDRPATHSEGMENT_TOGGLE);
162 break;
165 case SID_BEZIER_EDGE:
166 case SID_BEZIER_SMOOTH:
167 case SID_BEZIER_SYMMTR:
169 SdrPathSmoothKind eKind = SDRPATHSMOOTH_ASYMMETRIC;
171 switch (nSlotId)
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[] =
185 SID_BEZIER_SMOOTH,
186 SID_BEZIER_EDGE,
187 SID_BEZIER_SYMMTR,
190 GetView().GetViewFrame()->GetBindings().Invalidate(aInva);
192 break;
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());
201 break;
204 case SID_BEZIER_ELIMINATE_POINTS:
205 pSdrView->SetEliminatePolyPoints(!pSdrView->IsEliminatePolyPoints());
206 break;
210 break;
212 default:
213 break;
216 if (pSdrView->GetModel()->IsChanged())
217 GetShell().SetModified();
218 else if (bChanged)
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();
229 while( nWhich )
231 switch( nWhich )
233 case SID_BEZIER_MOVE:
234 case SID_BEZIER_INSERT:
236 sal_uInt16 nEditMode = GetView().GetEditWin().GetBezierMode();
238 rSet.Put(SfxBoolItem(nWhich, nEditMode == nWhich));
240 break;
242 case SID_BEZIER_CUTLINE:
243 if (!pSdrView->IsRipUpAtMarkedPointsPossible())
245 rSet.DisableItem(SID_BEZIER_CUTLINE);
247 break;
249 case SID_BEZIER_DELETE:
250 if (!pSdrView->IsDeleteMarkedPointsPossible())
252 rSet.DisableItem(SID_BEZIER_DELETE);
254 break;
256 case SID_BEZIER_CONVERT:
257 if (!pSdrView->IsSetMarkedSegmentsKindPossible())
259 rSet.DisableItem(SID_BEZIER_CONVERT);
261 else
263 SdrPathSegmentKind eSegm = pSdrView->GetMarkedSegmentsKind();
264 switch (eSegm)
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
272 break;
274 case SID_BEZIER_EDGE:
275 case SID_BEZIER_SMOOTH:
276 case SID_BEZIER_SYMMTR:
277 if (!pSdrView->IsSetMarkedPointsSmoothPossible())
278 rSet.DisableItem(nWhich);
279 else
281 SdrPathSmoothKind eSmooth = pSdrView->GetMarkedPointsSmooth();
282 sal_Bool bEnable = sal_False;
283 switch (eSmooth)
285 case SDRPATHSMOOTH_DONTCARE :
286 break;
287 case SDRPATHSMOOTH_ANGULAR :
288 bEnable = nWhich == SID_BEZIER_EDGE;
289 break;
290 case SDRPATHSMOOTH_ASYMMETRIC:
291 bEnable = nWhich == SID_BEZIER_SMOOTH;
292 break;
293 case SDRPATHSMOOTH_SYMMETRIC :
294 bEnable = nWhich == SID_BEZIER_SYMMTR;
295 break;
297 rSet.Put(SfxBoolItem(nWhich, bEnable));
299 break;
301 case SID_BEZIER_CLOSE:
302 if (!pSdrView->IsOpenCloseMarkedObjectsPossible())
304 rSet.DisableItem(SID_BEZIER_CLOSE);
306 else
308 SdrObjClosedKind eClose = pSdrView->GetMarkedObjectsClosedState();
309 switch (eClose)
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
317 break;
319 case SID_BEZIER_ELIMINATE_POINTS:
320 rSet.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS, pSdrView->IsEliminatePolyPoints()));
321 break;
323 default:
324 break;
326 nWhich = aIter.NextWhich();
330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */