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