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