xref: /aoo42x/main/sd/source/ui/view/drbezob.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "BezierObjectBar.hxx"
32 #include <sfx2/app.hxx>
33 #include <sfx2/msg.hxx>
34 
35 #include <sfx2/viewfrm.hxx>
36 #include <sfx2/objface.hxx>
37 
38 #include <svx/svxids.hrc>
39 #include <svl/eitem.hxx>
40 #include <sfx2/request.hxx>
41 #include <svx/svdopath.hxx>
42 #include <svl/aeitem.hxx>
43 #include <svx/svdundo.hxx>
44 #include <sfx2/dispatch.hxx>
45 
46 
47 #include "sdresid.hxx"
48 
49 
50 
51 #include "res_bmp.hrc"
52 #include "glob.hrc"
53 #include "strings.hrc"
54 
55 #include "DrawDocShell.hxx"
56 #include "ViewShell.hxx"
57 #include "Window.hxx"
58 #include "drawview.hxx"
59 #include "drawdoc.hxx"
60 #include "sdresid.hxx"
61 #include "fusel.hxx"
62 #include "fuconbez.hxx"
63 
64 
65 using namespace sd;
66 #define BezierObjectBar
67 #include "sdslots.hxx"
68 
69 namespace sd {
70 
71 /*************************************************************************
72 |*
73 |* Standardinterface deklarieren (Die Slotmap darf nicht leer sein)
74 |*
75 \************************************************************************/
76 
77 
78 
79 SFX_IMPL_INTERFACE(BezierObjectBar, ::SfxShell, SdResId(STR_BEZIEROBJECTBARSHELL))
80 {
81 }
82 
83 TYPEINIT1(BezierObjectBar, ::SfxShell);
84 
85 /*************************************************************************
86 |*
87 |* Standard-Konstruktor
88 |*
89 \************************************************************************/
90 
91 BezierObjectBar::BezierObjectBar(
92     ViewShell* pSdViewShell,
93     ::sd::View* pSdView)
94     : SfxShell(pSdViewShell->GetViewShell()),
95       mpView(pSdView),
96       mpViewSh(pSdViewShell)
97 {
98 	DrawDocShell* pDocShell = mpViewSh->GetDocSh();
99 	SetPool(&pDocShell->GetPool());
100 	SetUndoManager(pDocShell->GetUndoManager());
101 	SetRepeatTarget(mpView);
102 
103 	SetHelpId( SD_IF_SDDRAWBEZIEROBJECTBAR );
104 }
105 
106 /*************************************************************************
107 |*
108 |* Destruktor
109 |*
110 \************************************************************************/
111 
112 BezierObjectBar::~BezierObjectBar()
113 {
114 	SetRepeatTarget(NULL);
115 }
116 
117 
118 /*************************************************************************
119 |*
120 |* Status der Attribut-Items
121 |*
122 \************************************************************************/
123 
124 void BezierObjectBar::GetAttrState(SfxItemSet& rSet)
125 {
126 	SfxItemSet aAttrSet( mpView->GetDoc()->GetPool() );
127 	mpView->GetAttributes( aAttrSet );
128 	rSet.Put(aAttrSet, sal_False); // <- sal_False, damit DontCare-Status uebernommen wird
129 
130 	FunctionReference xFunc( mpViewSh->GetCurrentFunction() );
131 
132 	if(xFunc.is())
133 	{
134 		if(xFunc->ISA(FuSelection))
135 		{
136 			sal_uInt16 nEditMode = static_cast<FuSelection*>(xFunc.get())->GetEditMode();
137 			rSet.Put(SfxBoolItem(nEditMode, sal_True));
138 		}
139 		else if (xFunc->ISA(FuConstructBezierPolygon))
140 		{
141 			sal_uInt16 nEditMode = static_cast<FuConstructBezierPolygon*>(xFunc.get())->GetEditMode();
142 			rSet.Put(SfxBoolItem(nEditMode, sal_True));
143 		}
144 	}
145 
146 	if(!mpView->IsMoveAllowed() || !mpView->IsResizeAllowed())
147 	{
148 		// #i77187# if object is move and/or size protected, do not allow point editing at all
149 		rSet.DisableItem(SID_BEZIER_MOVE);
150 		rSet.DisableItem(SID_BEZIER_INSERT);
151 
152 		rSet.DisableItem(SID_BEZIER_DELETE);
153 		rSet.DisableItem(SID_BEZIER_CUTLINE);
154 		rSet.DisableItem(SID_BEZIER_CONVERT);
155 
156 		rSet.DisableItem(SID_BEZIER_EDGE);
157 		rSet.DisableItem(SID_BEZIER_SMOOTH);
158 		rSet.DisableItem(SID_BEZIER_SYMMTR);
159 
160 		rSet.DisableItem(SID_BEZIER_CLOSE);
161 
162 		rSet.DisableItem(SID_BEZIER_ELIMINATE_POINTS);
163 	}
164 	else
165 	{
166 		IPolyPolygonEditorController* pIPPEC = 0;
167 		if( mpView->GetMarkedObjectList().GetMarkCount() )
168 			pIPPEC = mpView;
169 		else
170 			pIPPEC = dynamic_cast< IPolyPolygonEditorController* >( mpView->getSmartTags().getSelected().get() );
171 
172 		if ( !pIPPEC || !pIPPEC->IsRipUpAtMarkedPointsPossible())
173 		{
174 			rSet.DisableItem(SID_BEZIER_CUTLINE);
175 		}
176 		if (!pIPPEC || !pIPPEC->IsDeleteMarkedPointsPossible())
177 		{
178 			rSet.DisableItem(SID_BEZIER_DELETE);
179 		}
180 		if (!pIPPEC || !pIPPEC->IsSetMarkedSegmentsKindPossible())
181 		{
182 			rSet.DisableItem(SID_BEZIER_CONVERT);
183 		}
184 		else
185 		{
186 			SdrPathSegmentKind eSegm = pIPPEC->GetMarkedSegmentsKind();
187 			switch (eSegm)
188 			{
189 				case SDRPATHSEGMENT_DONTCARE: rSet.InvalidateItem(SID_BEZIER_CONVERT); break;
190 				case SDRPATHSEGMENT_LINE    : rSet.Put(SfxBoolItem(SID_BEZIER_CONVERT,sal_False)); break; // Button reingedrueckt = Kurve
191 				case SDRPATHSEGMENT_CURVE   : rSet.Put(SfxBoolItem(SID_BEZIER_CONVERT,sal_True));  break;
192 				default: break;
193 			}
194 		}
195 		if (!pIPPEC || !pIPPEC->IsSetMarkedPointsSmoothPossible())
196 		{
197 			rSet.DisableItem(SID_BEZIER_EDGE);
198 			rSet.DisableItem(SID_BEZIER_SMOOTH);
199 			rSet.DisableItem(SID_BEZIER_SYMMTR);
200 		}
201 		else
202 		{
203 			SdrPathSmoothKind eSmooth = pIPPEC->GetMarkedPointsSmooth();
204 			switch (eSmooth)
205 			{
206 				case SDRPATHSMOOTH_DONTCARE  : break;
207 				case SDRPATHSMOOTH_ANGULAR   : rSet.Put(SfxBoolItem(SID_BEZIER_EDGE,  sal_True)); break;
208 				case SDRPATHSMOOTH_ASYMMETRIC: rSet.Put(SfxBoolItem(SID_BEZIER_SMOOTH,sal_True)); break;
209 				case SDRPATHSMOOTH_SYMMETRIC : rSet.Put(SfxBoolItem(SID_BEZIER_SYMMTR,sal_True)); break;
210 			}
211 		}
212 		if (!pIPPEC || !pIPPEC->IsOpenCloseMarkedObjectsPossible())
213 		{
214 			rSet.DisableItem(SID_BEZIER_CLOSE);
215 		}
216 		else
217 		{
218 			SdrObjClosedKind eClose = pIPPEC->GetMarkedObjectsClosedState();
219 			switch (eClose)
220 			{
221 				case SDROBJCLOSED_DONTCARE: rSet.InvalidateItem(SID_BEZIER_CLOSE); break;
222 				case SDROBJCLOSED_OPEN    : rSet.Put(SfxBoolItem(SID_BEZIER_CLOSE,sal_False)); break;
223 				case SDROBJCLOSED_CLOSED  : rSet.Put(SfxBoolItem(SID_BEZIER_CLOSE,sal_True)); break;
224 				default: break;
225 			}
226 		}
227 
228 		if(pIPPEC == mpView)
229 			rSet.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS, mpView->IsEliminatePolyPoints()));
230 		else
231 			rSet.DisableItem( SID_BEZIER_ELIMINATE_POINTS ); // only works for views
232 	}
233 }
234 
235 
236 /*************************************************************************
237 |*
238 |* Bearbeitung der SfxRequests
239 |*
240 \************************************************************************/
241 
242 void BezierObjectBar::Execute(SfxRequest& rReq)
243 {
244 	sal_uInt16 nSId = rReq.GetSlot();
245 
246 	switch (nSId)
247 	{
248 		case SID_BEZIER_CUTLINE:
249 		case SID_BEZIER_CONVERT:
250 		case SID_BEZIER_DELETE:
251 		case SID_BEZIER_EDGE:
252 		case SID_BEZIER_SMOOTH:
253 		case SID_BEZIER_SYMMTR:
254 		case SID_BEZIER_CLOSE:
255 		{
256 			const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
257 
258 			IPolyPolygonEditorController* pIPPEC = 0;
259 			if( rMarkList.GetMarkCount() )
260 				pIPPEC = mpView;
261 			else
262 				pIPPEC = dynamic_cast< IPolyPolygonEditorController* >( mpView->getSmartTags().getSelected().get() );
263 
264 			if( pIPPEC && !mpView->IsAction())
265 			{
266 				switch (nSId)
267 				{
268 					case SID_BEZIER_DELETE:
269 						pIPPEC->DeleteMarkedPoints();
270 						break;
271 
272 					case SID_BEZIER_CUTLINE:
273 						pIPPEC->RipUpAtMarkedPoints();
274 						break;
275 
276 					case SID_BEZIER_CONVERT:
277 					{
278 						pIPPEC->SetMarkedSegmentsKind(SDRPATHSEGMENT_TOGGLE);
279 						break;
280 					}
281 
282 					case SID_BEZIER_EDGE:
283 					case SID_BEZIER_SMOOTH:
284 					case SID_BEZIER_SYMMTR:
285 					{
286 						SdrPathSmoothKind eKind;
287 
288 						switch (nSId)
289 						{
290 							default:
291 							case SID_BEZIER_EDGE:   eKind = SDRPATHSMOOTH_ANGULAR; break;
292 							case SID_BEZIER_SMOOTH: eKind = SDRPATHSMOOTH_ASYMMETRIC; break;
293 							case SID_BEZIER_SYMMTR: eKind = SDRPATHSMOOTH_SYMMETRIC; break;
294 						}
295 
296 						pIPPEC->SetMarkedPointsSmooth(eKind);
297 						break;
298 					}
299 
300 					case SID_BEZIER_CLOSE:
301 					{
302 						SdrPathObj* pPathObj = (SdrPathObj*) rMarkList.GetMark(0)->GetMarkedSdrObj();
303 						const bool bUndo = mpView->IsUndoEnabled();
304 						if( bUndo )
305 							mpView->BegUndo(String(SdResId(STR_UNDO_BEZCLOSE)));
306 
307 						mpView->UnmarkAllPoints();
308 
309 						if( bUndo )
310 							mpView->AddUndo(mpView->GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pPathObj));
311 
312 						pPathObj->ToggleClosed();
313 
314 						if( bUndo )
315 							mpView->EndUndo();
316 						break;
317 					}
318 				}
319 			}
320 
321 			if( (pIPPEC == mpView) && !mpView->AreObjectsMarked() )
322 				mpViewSh->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
323 
324 			rReq.Ignore();
325 		}
326 		break;
327 
328 		case SID_BEZIER_ELIMINATE_POINTS:
329 		{
330 			mpView->SetEliminatePolyPoints(!mpView->IsEliminatePolyPoints());
331 			Invalidate(SID_BEZIER_ELIMINATE_POINTS);
332 			rReq.Done();
333 		}
334 		break;
335 
336 		case SID_BEZIER_MOVE:
337 		case SID_BEZIER_INSERT:
338 		{
339 			FunctionReference xFunc( mpViewSh->GetCurrentFunction() );
340 
341 			if(xFunc.is())
342 			{
343 				if(xFunc->ISA(FuSelection))
344 				{
345 					static_cast<FuSelection*>(xFunc.get())->SetEditMode(rReq.GetSlot());
346 				}
347 				else if(xFunc->ISA(FuConstructBezierPolygon))
348 				{
349 					static_cast<FuConstructBezierPolygon*>(xFunc.get())->SetEditMode(rReq.GetSlot());
350 				}
351 			}
352 
353 			rReq.Ignore ();
354 		}
355 		break;
356 
357 		default:
358 		break;
359 	}
360 
361 	Invalidate();
362 }
363 
364 
365 } // end of namespace sd
366