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