xref: /AOO41X/main/sw/source/ui/shells/beziersh.cxx (revision efeef26f81c84063fb0a91bde3856d4a51172d90)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "cmdid.h"
29cdf0e10cSrcweir #include <svx/svdview.hxx>
30cdf0e10cSrcweir #include <svl/srchitem.hxx>
31cdf0e10cSrcweir #include <svl/eitem.hxx>
32cdf0e10cSrcweir #include <svl/whiter.hxx>
33cdf0e10cSrcweir #include <svx/svdopath.hxx>
34cdf0e10cSrcweir #include <sfx2/request.hxx>
35cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
36cdf0e10cSrcweir #include <sfx2/objface.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include "wrtsh.hxx"
39cdf0e10cSrcweir #include "view.hxx"
40cdf0e10cSrcweir #include "edtwin.hxx"
41cdf0e10cSrcweir #include "helpid.h"
42cdf0e10cSrcweir #include "globals.hrc"
43cdf0e10cSrcweir #include "drawbase.hxx"
44cdf0e10cSrcweir #include "beziersh.hxx"
45cdf0e10cSrcweir #include "popup.hrc"
46cdf0e10cSrcweir #include "shells.hrc"
47cdf0e10cSrcweir #define SwBezierShell
48cdf0e10cSrcweir #include <sfx2/msg.hxx>
49cdf0e10cSrcweir #include "swslots.hxx"
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #include <unomid.h>
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 
54cdf0e10cSrcweir SFX_IMPL_INTERFACE(SwBezierShell, SwBaseShell, SW_RES(STR_SHELLNAME_BEZIER))
55cdf0e10cSrcweir {
56cdf0e10cSrcweir 	SFX_POPUPMENU_REGISTRATION(SW_RES(MN_DRAW_POPUPMENU));
57cdf0e10cSrcweir 	SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_BEZIER_TOOLBOX));
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir TYPEINIT1(SwBezierShell,SwBaseShell)
61cdf0e10cSrcweir 
62cdf0e10cSrcweir /*--------------------------------------------------------------------
63cdf0e10cSrcweir 	Beschreibung:
64cdf0e10cSrcweir  --------------------------------------------------------------------*/
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 
67cdf0e10cSrcweir SwBezierShell::SwBezierShell(SwView &_rView):
68cdf0e10cSrcweir     SwBaseShell( _rView )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir 	SetName(C2S("Bezier"));
71cdf0e10cSrcweir 	SetHelpId(SW_BEZIERSHELL);
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	SwWrtShell *pSh = &GetShell();
74cdf0e10cSrcweir 	SdrView*	pSdrView = pSh->GetDrawView();
75cdf0e10cSrcweir 	pSdrView->SetEliminatePolyPointLimitAngle(1500L);
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir /*--------------------------------------------------------------------
79cdf0e10cSrcweir 	Beschreibung:
80cdf0e10cSrcweir  --------------------------------------------------------------------*/
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 
83cdf0e10cSrcweir void SwBezierShell::Execute(SfxRequest &rReq)
84cdf0e10cSrcweir {
85cdf0e10cSrcweir 	SwWrtShell *pSh = &GetShell();
86cdf0e10cSrcweir 	SdrView*	pSdrView = pSh->GetDrawView();
87cdf0e10cSrcweir 	const SfxItemSet *pArgs = rReq.GetArgs();
88cdf0e10cSrcweir 	sal_uInt16		nSlotId = rReq.GetSlot();
89cdf0e10cSrcweir 	sal_Bool		bChanged = pSdrView->GetModel()->IsChanged();
90cdf0e10cSrcweir 	pSdrView->GetModel()->SetChanged(sal_False);
91cdf0e10cSrcweir 	const SfxPoolItem* pItem;
92cdf0e10cSrcweir 	if(pArgs)
93cdf0e10cSrcweir 		pArgs->GetItemState(nSlotId, sal_False, &pItem);
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	switch (nSlotId)
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir 		case SID_DELETE:
98cdf0e10cSrcweir 		case FN_BACKSPACE:
99cdf0e10cSrcweir 			if (pSh->IsObjSelected())
100cdf0e10cSrcweir 			{
101cdf0e10cSrcweir 				if (pSdrView->HasMarkedPoints())
102cdf0e10cSrcweir 					pSh->GetView().GetViewFrame()->GetDispatcher()->Execute(SID_BEZIER_DELETE, sal_False);
103cdf0e10cSrcweir 				else
104cdf0e10cSrcweir 				{
105cdf0e10cSrcweir 					pSh->DelSelectedObj();
106cdf0e10cSrcweir 					if (pSh->IsSelFrmMode())
107cdf0e10cSrcweir 					{
108cdf0e10cSrcweir 						pSh->LeaveSelFrmMode();
109cdf0e10cSrcweir 						pSh->NoEdit();
110cdf0e10cSrcweir 					}
111cdf0e10cSrcweir 					GetView().AttrChangedNotify(pSh); // ggf Shellwechsel...
112cdf0e10cSrcweir 				}
113cdf0e10cSrcweir 			}
114cdf0e10cSrcweir 			break;
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 		case FN_ESCAPE:
117cdf0e10cSrcweir 			if (pSdrView->HasMarkedPoints())
118cdf0e10cSrcweir 				pSdrView->UnmarkAllPoints();
119cdf0e10cSrcweir 			else
120cdf0e10cSrcweir 			{
121cdf0e10cSrcweir 				if ( pSh->IsDrawCreate() )
122cdf0e10cSrcweir 				{
123cdf0e10cSrcweir 					GetView().GetDrawFuncPtr()->BreakCreate();
124cdf0e10cSrcweir 					GetView().AttrChangedNotify(pSh); // ggf Shellwechsel...
125cdf0e10cSrcweir 				}
126cdf0e10cSrcweir 				else if ( pSh->HasSelection() || GetView().IsDrawMode() )
127cdf0e10cSrcweir 				{
128cdf0e10cSrcweir 					GetView().LeaveDrawCreate();
129cdf0e10cSrcweir 					pSh->EnterStdMode();
130cdf0e10cSrcweir 					GetView().AttrChangedNotify(pSh); // ggf Shellwechsel...
131cdf0e10cSrcweir 				}
132cdf0e10cSrcweir 			}
133cdf0e10cSrcweir 			break;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 		case SID_BEZIER_MOVE:
136cdf0e10cSrcweir 		case SID_BEZIER_INSERT:
137cdf0e10cSrcweir 			{
138cdf0e10cSrcweir 				GetView().GetEditWin().SetBezierMode(nSlotId);
139cdf0e10cSrcweir 				static sal_uInt16 __READONLY_DATA aInva[] =
140cdf0e10cSrcweir 								{
141cdf0e10cSrcweir 									SID_BEZIER_INSERT,
142cdf0e10cSrcweir 									SID_BEZIER_MOVE,
143cdf0e10cSrcweir 									0
144cdf0e10cSrcweir 								};
145cdf0e10cSrcweir 				GetView().GetViewFrame()->GetBindings().Invalidate(aInva);
146cdf0e10cSrcweir 			}
147cdf0e10cSrcweir 			break;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 		case SID_BEZIER_DELETE:
150cdf0e10cSrcweir 		case SID_BEZIER_CUTLINE:
151cdf0e10cSrcweir 		case SID_BEZIER_CONVERT:
152cdf0e10cSrcweir 		case SID_BEZIER_EDGE:
153cdf0e10cSrcweir 		case SID_BEZIER_SMOOTH:
154cdf0e10cSrcweir 		case SID_BEZIER_SYMMTR:
155cdf0e10cSrcweir 		case SID_BEZIER_CLOSE:
156cdf0e10cSrcweir 		case SID_BEZIER_ELIMINATE_POINTS:
157cdf0e10cSrcweir 		{
158cdf0e10cSrcweir 			const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 			if (rMarkList.GetMark(0) && !pSdrView->IsAction())
161cdf0e10cSrcweir 			{
162cdf0e10cSrcweir 				switch (nSlotId)
163cdf0e10cSrcweir 				{
164cdf0e10cSrcweir 					case SID_BEZIER_DELETE:
165cdf0e10cSrcweir 						pSdrView->DeleteMarkedPoints();
166cdf0e10cSrcweir 						break;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 					case SID_BEZIER_CUTLINE:
169cdf0e10cSrcweir 						{
170cdf0e10cSrcweir 							pSdrView->RipUpAtMarkedPoints();
171cdf0e10cSrcweir 							pSh->CheckUnboundObjects();
172cdf0e10cSrcweir 						}
173cdf0e10cSrcweir 						break;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 					case SID_BEZIER_CONVERT:
176cdf0e10cSrcweir 					{
177cdf0e10cSrcweir 						pSdrView->SetMarkedSegmentsKind(SDRPATHSEGMENT_TOGGLE);
178cdf0e10cSrcweir 						break;
179cdf0e10cSrcweir 					}
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 					case SID_BEZIER_EDGE:
182cdf0e10cSrcweir 					case SID_BEZIER_SMOOTH:
183cdf0e10cSrcweir 					case SID_BEZIER_SYMMTR:
184cdf0e10cSrcweir 					{
185cdf0e10cSrcweir                         SdrPathSmoothKind eKind = SDRPATHSMOOTH_ASYMMETRIC;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 						switch (nSlotId)
188cdf0e10cSrcweir 						{
189cdf0e10cSrcweir 							case SID_BEZIER_EDGE:   eKind = SDRPATHSMOOTH_ANGULAR; break;
190cdf0e10cSrcweir 							case SID_BEZIER_SMOOTH: eKind = SDRPATHSMOOTH_ASYMMETRIC; break;
191cdf0e10cSrcweir 							case SID_BEZIER_SYMMTR: eKind = SDRPATHSMOOTH_SYMMETRIC; break;
192cdf0e10cSrcweir 						}
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 						SdrPathSmoothKind eSmooth = pSdrView->GetMarkedPointsSmooth();
195cdf0e10cSrcweir 						if (eKind != eSmooth)
196cdf0e10cSrcweir 						{
197cdf0e10cSrcweir 							pSdrView->SetMarkedPointsSmooth(eKind);
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 							static sal_uInt16 __READONLY_DATA aInva[] =
200cdf0e10cSrcweir 											{
201cdf0e10cSrcweir 												SID_BEZIER_SMOOTH,
202cdf0e10cSrcweir 												SID_BEZIER_EDGE,
203cdf0e10cSrcweir 												SID_BEZIER_SYMMTR,
204cdf0e10cSrcweir 												0
205cdf0e10cSrcweir 											};
206cdf0e10cSrcweir 							GetView().GetViewFrame()->GetBindings().Invalidate(aInva);
207cdf0e10cSrcweir 						}
208cdf0e10cSrcweir 						break;
209cdf0e10cSrcweir 					}
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 					case SID_BEZIER_CLOSE:
212cdf0e10cSrcweir 					{
213cdf0e10cSrcweir 						SdrPathObj* pPathObj = (SdrPathObj*) rMarkList.GetMark(0)->GetMarkedSdrObj();
214cdf0e10cSrcweir 						pSdrView->UnmarkAllPoints();
215cdf0e10cSrcweir 						// Size aDist(GetView().GetEditWin().PixelToLogic(Size(8,8)));
216cdf0e10cSrcweir 						pPathObj->ToggleClosed(); // aDist.Width());
217cdf0e10cSrcweir 						break;
218cdf0e10cSrcweir 					}
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 					case SID_BEZIER_ELIMINATE_POINTS:
221cdf0e10cSrcweir 						pSdrView->SetEliminatePolyPoints(!pSdrView->IsEliminatePolyPoints());
222cdf0e10cSrcweir 						break;
223cdf0e10cSrcweir 				}
224cdf0e10cSrcweir 			}
225cdf0e10cSrcweir 		}
226cdf0e10cSrcweir 		break;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 		default:
229cdf0e10cSrcweir 			break;
230cdf0e10cSrcweir 	}
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 	if (pSdrView->GetModel()->IsChanged())
233cdf0e10cSrcweir 		GetShell().SetModified();
234cdf0e10cSrcweir 	else if (bChanged)
235cdf0e10cSrcweir 		pSdrView->GetModel()->SetChanged(sal_True);
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir /*--------------------------------------------------------------------
239cdf0e10cSrcweir 	Beschreibung:
240cdf0e10cSrcweir  --------------------------------------------------------------------*/
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 
243cdf0e10cSrcweir void SwBezierShell::GetState(SfxItemSet &rSet)
244cdf0e10cSrcweir {
245cdf0e10cSrcweir 	SdrView* pSdrView = GetShell().GetDrawView();
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 	SfxWhichIter aIter( rSet );
248cdf0e10cSrcweir 	sal_uInt16 nWhich = aIter.FirstWhich();
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 	while( nWhich )
251cdf0e10cSrcweir 	{
252cdf0e10cSrcweir 		switch( nWhich )
253cdf0e10cSrcweir 		{
254cdf0e10cSrcweir 			case SID_BEZIER_MOVE:
255cdf0e10cSrcweir 			case SID_BEZIER_INSERT:
256cdf0e10cSrcweir 			{
257cdf0e10cSrcweir 				sal_uInt16 nEditMode = GetView().GetEditWin().GetBezierMode();
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 				rSet.Put(SfxBoolItem(nWhich, nEditMode == nWhich));
260cdf0e10cSrcweir 			}
261cdf0e10cSrcweir 			break;
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 			case SID_BEZIER_CUTLINE:
264cdf0e10cSrcweir 				if (!pSdrView->IsRipUpAtMarkedPointsPossible())
265cdf0e10cSrcweir 				{
266cdf0e10cSrcweir 					rSet.DisableItem(SID_BEZIER_CUTLINE);
267cdf0e10cSrcweir 				}
268cdf0e10cSrcweir 				break;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 			case SID_BEZIER_DELETE:
271cdf0e10cSrcweir 				if (!pSdrView->IsDeleteMarkedPointsPossible())
272cdf0e10cSrcweir 				{
273cdf0e10cSrcweir 					rSet.DisableItem(SID_BEZIER_DELETE);
274cdf0e10cSrcweir 				}
275cdf0e10cSrcweir 				break;
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 			case SID_BEZIER_CONVERT:
278cdf0e10cSrcweir 				if (!pSdrView->IsSetMarkedSegmentsKindPossible())
279cdf0e10cSrcweir 				{
280cdf0e10cSrcweir 					rSet.DisableItem(SID_BEZIER_CONVERT);
281cdf0e10cSrcweir 				}
282cdf0e10cSrcweir 				else
283cdf0e10cSrcweir 				{
284cdf0e10cSrcweir 					SdrPathSegmentKind eSegm = pSdrView->GetMarkedSegmentsKind();
285cdf0e10cSrcweir 					switch (eSegm)
286cdf0e10cSrcweir 					{
287cdf0e10cSrcweir 						case SDRPATHSEGMENT_DONTCARE: rSet.InvalidateItem(SID_BEZIER_CONVERT); break;
288cdf0e10cSrcweir 						case SDRPATHSEGMENT_LINE    : rSet.Put(SfxBoolItem(SID_BEZIER_CONVERT,sal_False)); break; // Button reingedrueckt = Kurve
289cdf0e10cSrcweir 						case SDRPATHSEGMENT_CURVE   : rSet.Put(SfxBoolItem(SID_BEZIER_CONVERT,sal_True));  break;
290cdf0e10cSrcweir                         default:; //prevent warning
291cdf0e10cSrcweir 					}
292cdf0e10cSrcweir 				}
293cdf0e10cSrcweir 				break;
294cdf0e10cSrcweir 
295cdf0e10cSrcweir 			case SID_BEZIER_EDGE:
296cdf0e10cSrcweir 			case SID_BEZIER_SMOOTH:
297cdf0e10cSrcweir 			case SID_BEZIER_SYMMTR:
298cdf0e10cSrcweir 				if (!pSdrView->IsSetMarkedPointsSmoothPossible())
299cdf0e10cSrcweir 					rSet.DisableItem(nWhich);
300cdf0e10cSrcweir 				else
301cdf0e10cSrcweir 				{
302cdf0e10cSrcweir 					SdrPathSmoothKind eSmooth = pSdrView->GetMarkedPointsSmooth();
303cdf0e10cSrcweir 					sal_Bool bEnable = sal_False;
304cdf0e10cSrcweir 					switch (eSmooth)
305cdf0e10cSrcweir 					{
306cdf0e10cSrcweir 						case SDRPATHSMOOTH_DONTCARE  :
307cdf0e10cSrcweir 							break;
308cdf0e10cSrcweir 						case SDRPATHSMOOTH_ANGULAR   :
309cdf0e10cSrcweir 							bEnable = nWhich == SID_BEZIER_EDGE;
310cdf0e10cSrcweir 							break;
311cdf0e10cSrcweir 						case SDRPATHSMOOTH_ASYMMETRIC:
312cdf0e10cSrcweir 							bEnable = nWhich == SID_BEZIER_SMOOTH;
313cdf0e10cSrcweir 							break;
314cdf0e10cSrcweir 						case SDRPATHSMOOTH_SYMMETRIC :
315cdf0e10cSrcweir 							bEnable = nWhich == SID_BEZIER_SYMMTR;
316cdf0e10cSrcweir 							break;
317cdf0e10cSrcweir 					}
318cdf0e10cSrcweir 					rSet.Put(SfxBoolItem(nWhich, bEnable));
319cdf0e10cSrcweir 				}
320cdf0e10cSrcweir 				break;
321cdf0e10cSrcweir 
322cdf0e10cSrcweir 			case SID_BEZIER_CLOSE:
323cdf0e10cSrcweir 				if (!pSdrView->IsOpenCloseMarkedObjectsPossible())
324cdf0e10cSrcweir 				{
325cdf0e10cSrcweir 					rSet.DisableItem(SID_BEZIER_CLOSE);
326cdf0e10cSrcweir 				}
327cdf0e10cSrcweir 				else
328cdf0e10cSrcweir 				{
329cdf0e10cSrcweir 					SdrObjClosedKind eClose = pSdrView->GetMarkedObjectsClosedState();
330cdf0e10cSrcweir 					switch (eClose)
331cdf0e10cSrcweir 					{
332cdf0e10cSrcweir 						case SDROBJCLOSED_DONTCARE: rSet.InvalidateItem(SID_BEZIER_CLOSE); break;
333cdf0e10cSrcweir 						case SDROBJCLOSED_OPEN    : rSet.Put(SfxBoolItem(SID_BEZIER_CLOSE,sal_False)); break;
334cdf0e10cSrcweir 						case SDROBJCLOSED_CLOSED  : rSet.Put(SfxBoolItem(SID_BEZIER_CLOSE,sal_True)); break;
335cdf0e10cSrcweir                         default:; //prevent warning
336cdf0e10cSrcweir 					}
337cdf0e10cSrcweir 				}
338cdf0e10cSrcweir 				break;
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 			case SID_BEZIER_ELIMINATE_POINTS:
341cdf0e10cSrcweir 				rSet.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS, pSdrView->IsEliminatePolyPoints()));
342cdf0e10cSrcweir 				break;
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 			default:
345cdf0e10cSrcweir 				break;
346cdf0e10cSrcweir 		}
347cdf0e10cSrcweir 		nWhich = aIter.NextWhich();
348cdf0e10cSrcweir 	}
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir 
352cdf0e10cSrcweir 
353