xref: /trunk/main/sd/source/ui/func/fuconbez.cxx (revision 79aad27f)
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_sd.hxx"
26 
27 #include <com/sun/star/presentation/EffectNodeType.hpp>
28 
29 #include "fuconbez.hxx"
30 #include <svl/aeitem.hxx>
31 #include <svx/svdopath.hxx>
32 #include <svl/intitem.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <svx/svdobj.hxx>
35 #include <sfx2/bindings.hxx>
36 #include <sfx2/request.hxx>
37 #include <sfx2/viewfrm.hxx>
38 
39 
40 #include <svx/svxids.hrc>
41 #include <svx/svdpagv.hxx>
42 
43 #include "app.hrc"
44 #include "ViewShell.hxx"
45 #include "ViewShellBase.hxx"
46 #include "View.hxx"
47 #include "Window.hxx"
48 #include "ToolBarManager.hxx"
49 #include "drawdoc.hxx"
50 #include "res_bmp.hrc"
51 #include <basegfx/polygon/b2dpolygon.hxx>
52 #include <basegfx/polygon/b2dpolygontools.hxx>
53 
54 #include "CustomAnimationEffect.hxx"
55 
56 using namespace ::com::sun::star::uno;
57 
58 namespace sd {
59 
60 TYPEINIT1( FuConstructBezierPolygon, FuConstruct );
61 
62 
63 /*************************************************************************
64 |*
65 |* Konstruktor
66 |*
67 \************************************************************************/
68 
FuConstructBezierPolygon(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)69 FuConstructBezierPolygon::FuConstructBezierPolygon (
70     ViewShell* pViewSh,
71     ::sd::Window* pWin,
72     ::sd::View* pView,
73     SdDrawDocument* pDoc,
74     SfxRequest& rReq)
75 	: FuConstruct(pViewSh, pWin, pView, pDoc, rReq),
76       nEditMode(SID_BEZIER_MOVE)
77 {
78 }
79 
Create(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq,bool bPermanent)80 FunctionReference FuConstructBezierPolygon::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
81 {
82 	FuConstructBezierPolygon* pFunc;
83 	FunctionReference xFunc( pFunc = new FuConstructBezierPolygon( pViewSh, pWin, pView, pDoc, rReq ) );
84 	xFunc->DoExecute(rReq);
85 	pFunc->SetPermanent(bPermanent);
86 	return xFunc;
87 }
88 
DoExecute(SfxRequest & rReq)89 void FuConstructBezierPolygon::DoExecute( SfxRequest& rReq )
90 {
91 	FuConstruct::DoExecute( rReq );
92 
93 	const SfxItemSet* pArgs = rReq.GetArgs();
94 	if( pArgs )
95 	{
96 		const SfxPoolItem*  pPoolItem = NULL;
97 		if( SFX_ITEM_SET == pArgs->GetItemState( SID_ADD_MOTION_PATH, sal_True, &pPoolItem ) )
98 			maTargets = ( ( const SfxUnoAnyItem* ) pPoolItem )->GetValue();
99 	}
100 }
101 
102 /*************************************************************************
103 |*
104 |* MouseButtonDown-event
105 |*
106 \************************************************************************/
107 
MouseButtonDown(const MouseEvent & rMEvt)108 sal_Bool FuConstructBezierPolygon::MouseButtonDown(const MouseEvent& rMEvt)
109 {
110 	sal_Bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
111 
112 	SdrViewEvent aVEvt;
113 	SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
114 
115 	if (eHit == SDRHIT_HANDLE || rMEvt.IsMod1())
116 	{
117 		mpView->SetEditMode(SDREDITMODE_EDIT);
118 	}
119 	else
120 	{
121 		mpView->SetEditMode(SDREDITMODE_CREATE);
122 	}
123 
124 	if (aVEvt.eEvent == SDREVENT_BEGTEXTEDIT)
125 	{
126 		// Texteingabe hier nicht zulassen
127 		aVEvt.eEvent = SDREVENT_BEGDRAGOBJ;
128 		mpView->EnableExtendedMouseEventDispatcher(sal_False);
129 	}
130 	else
131 	{
132 		mpView->EnableExtendedMouseEventDispatcher(sal_True);
133 	}
134 
135 	if (eHit == SDRHIT_MARKEDOBJECT && nEditMode == SID_BEZIER_INSERT)
136 	{
137 		/******************************************************************
138 		* Klebepunkt einfuegen
139 		******************************************************************/
140 		mpView->BegInsObjPoint(aMDPos, rMEvt.IsMod1());
141 	}
142 	else
143 	{
144 		mpView->MouseButtonDown(rMEvt, mpWindow);
145 
146 		SdrObject* pObj = mpView->GetCreateObj();
147 
148 		if (pObj)
149 		{
150 			SfxItemSet aAttr(mpDoc->GetPool());
151 			SetStyleSheet(aAttr, pObj);
152 			pObj->SetMergedItemSet(aAttr);
153 		}
154 	}
155 
156 	return(bReturn);
157 }
158 
159 /*************************************************************************
160 |*
161 |* MouseMove-event
162 |*
163 \************************************************************************/
164 
MouseMove(const MouseEvent & rMEvt)165 sal_Bool FuConstructBezierPolygon::MouseMove(const MouseEvent& rMEvt)
166 {
167 	sal_Bool bReturn = FuConstruct::MouseMove(rMEvt);
168 	return(bReturn);
169 }
170 
171 /*************************************************************************
172 |*
173 |* MouseButtonUp-event
174 |*
175 \************************************************************************/
176 
MouseButtonUp(const MouseEvent & rMEvt)177 sal_Bool FuConstructBezierPolygon::MouseButtonUp(const MouseEvent& rMEvt )
178 {
179 	sal_Bool bReturn = sal_False;
180 	sal_Bool bCreated = sal_False;
181 
182 	SdrViewEvent aVEvt;
183 	mpView->PickAnything(rMEvt, SDRMOUSEBUTTONUP, aVEvt);
184 
185 	sal_uLong nCount = mpView->GetSdrPageView()->GetObjList()->GetObjCount();
186 
187 	if (mpView->IsInsObjPoint())
188 	{
189 		mpView->EndInsObjPoint(SDRCREATE_FORCEEND);
190 	}
191 	else
192 	{
193 		mpView->MouseButtonUp(rMEvt, mpWindow);
194 	}
195 
196 	if (aVEvt.eEvent == SDREVENT_ENDCREATE)
197 	{
198 		bReturn = sal_True;
199 
200 		if (nCount == (mpView->GetSdrPageView()->GetObjList()->GetObjCount() - 1))
201 		{
202 			bCreated = sal_True;
203 		}
204 
205 		// Trick, um FuDraw::DoubleClick nicht auszuloesen
206 		bMBDown = sal_False;
207 
208 	}
209 
210 	bReturn = FuConstruct::MouseButtonUp(rMEvt) || bReturn;
211 
212 	bool bDeleted = false;
213 	if( bCreated && maTargets.hasValue() )
214 	{
215 		SdrPathObj* pPathObj = dynamic_cast< SdrPathObj* >( mpView->GetSdrPageView()->GetObjList()->GetObj( nCount ) );
216 		SdPage* pPage = dynamic_cast< SdPage* >( pPathObj ? pPathObj->GetPage() : 0 );
217 		if( pPage )
218 		{
219 			boost::shared_ptr< sd::MainSequence > pMainSequence( pPage->getMainSequence() );
220 			if( pMainSequence.get() )
221 			{
222 				Sequence< Any > aTargets;
223 				maTargets >>= aTargets;
224 
225 				sal_Int32 nTCount = aTargets.getLength();
226 				if( nTCount > 1 )
227 				{
228 					const Any* pTarget = aTargets.getConstArray();
229 					double fDuration = 0.0;
230 					*pTarget++ >>= fDuration;
231 					bool bFirst = true;
232 					while( --nTCount )
233 					{
234 						CustomAnimationEffectPtr pCreated( pMainSequence->append( *pPathObj, *pTarget++, fDuration ) );
235 						if( bFirst )
236 							bFirst = false;
237 						else
238 							pCreated->setNodeType( ::com::sun::star::presentation::EffectNodeType::WITH_PREVIOUS );
239 					}
240 				}
241 			}
242 		}
243 		mpView->DeleteMarked();
244 		bDeleted = true;
245 	}
246 
247 	if ((!bPermanent && bCreated) || bDeleted)
248 	{
249 		mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
250 	}
251 
252 	return(bReturn);
253 }
254 
255 /*************************************************************************
256 |*
257 |* Tastaturereignisse bearbeiten
258 |*
259 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
260 |* sal_False.
261 |*
262 \************************************************************************/
263 
KeyInput(const KeyEvent & rKEvt)264 sal_Bool FuConstructBezierPolygon::KeyInput(const KeyEvent& rKEvt)
265 {
266 	sal_Bool bReturn = FuConstruct::KeyInput(rKEvt);
267 
268 	return(bReturn);
269 }
270 
271 /*************************************************************************
272 |*
273 |* Function aktivieren
274 |*
275 \************************************************************************/
276 
Activate()277 void FuConstructBezierPolygon::Activate()
278 {
279 	mpView->EnableExtendedMouseEventDispatcher(sal_True);
280 
281 	SdrObjKind eKind;
282 
283 	switch (nSlotId)
284 	{
285 		case SID_DRAW_POLYGON_NOFILL:
286 		case SID_DRAW_XPOLYGON_NOFILL:
287 		{
288 			eKind = OBJ_PLIN;
289 		}
290 		break;
291 
292 		case SID_DRAW_POLYGON:
293 		case SID_DRAW_XPOLYGON:
294 		{
295 			eKind = OBJ_POLY;
296 		}
297 		break;
298 
299 		case SID_DRAW_BEZIER_NOFILL:
300 		{
301 			eKind = OBJ_PATHLINE;
302 		}
303 		break;
304 
305 		case SID_DRAW_BEZIER_FILL:
306 		{
307 			eKind = OBJ_PATHFILL;
308 		}
309 		break;
310 
311 		case SID_DRAW_FREELINE_NOFILL:
312 		{
313 			eKind = OBJ_FREELINE;
314 		}
315 		break;
316 
317 		case SID_DRAW_FREELINE:
318 		{
319 			eKind = OBJ_FREEFILL;
320 		}
321 		break;
322 
323 		default:
324 		{
325 			eKind = OBJ_PATHLINE;
326 		}
327 		break;
328 	}
329 
330 	mpView->SetCurrentObj((sal_uInt16)eKind);
331 
332 	FuConstruct::Activate();
333 }
334 
335 /*************************************************************************
336 |*
337 |* Function deaktivieren
338 |*
339 \************************************************************************/
340 
Deactivate()341 void FuConstructBezierPolygon::Deactivate()
342 {
343 	mpView->EnableExtendedMouseEventDispatcher(sal_False);
344 
345 	FuConstruct::Deactivate();
346 }
347 
348 
349 /*************************************************************************
350 |*
351 |* Selektion hat sich geaendert
352 |*
353 \************************************************************************/
354 
SelectionHasChanged()355 void FuConstructBezierPolygon::SelectionHasChanged()
356 {
357 	FuDraw::SelectionHasChanged();
358 
359 	mpViewShell->GetViewShellBase().GetToolBarManager()->SelectionHasChanged(
360         *mpViewShell,
361         *mpView);
362 }
363 
364 
365 
366 /*************************************************************************
367 |*
368 |* Aktuellen Bezier-Editmodus setzen
369 |*
370 \************************************************************************/
371 
SetEditMode(sal_uInt16 nMode)372 void FuConstructBezierPolygon::SetEditMode(sal_uInt16 nMode)
373 {
374 	nEditMode = nMode;
375 	ForcePointer();
376 
377 	SfxBindings& rBindings = mpViewShell->GetViewFrame()->GetBindings();
378 	rBindings.Invalidate(SID_BEZIER_MOVE);
379 	rBindings.Invalidate(SID_BEZIER_INSERT);
380 }
381 
382 // #97016#
CreateDefaultObject(const sal_uInt16 nID,const Rectangle & rRectangle)383 SdrObject* FuConstructBezierPolygon::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
384 {
385 	// case SID_DRAW_POLYGON:
386 	// case SID_DRAW_POLYGON_NOFILL:
387 	// case SID_DRAW_XPOLYGON:
388 	// case SID_DRAW_XPOLYGON_NOFILL:
389 	// case SID_DRAW_FREELINE:
390 	// case SID_DRAW_FREELINE_NOFILL:
391 	// case SID_DRAW_BEZIER_FILL:          // BASIC
392 	// case SID_DRAW_BEZIER_NOFILL:        // BASIC
393 
394 	SdrObject* pObj = SdrObjFactory::MakeNewObject(
395 		mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
396 		0L, mpDoc);
397 
398 	if(pObj)
399 	{
400 		if(pObj->ISA(SdrPathObj))
401 		{
402 			basegfx::B2DPolyPolygon aPoly;
403 
404 			switch(nID)
405 			{
406 				case SID_DRAW_BEZIER_FILL:
407 				{
408 					const sal_Int32 nWdt(rRectangle.GetWidth() / 2);
409 					const sal_Int32 nHgt(rRectangle.GetHeight() / 2);
410 					const basegfx::B2DPolygon aInnerPoly(basegfx::tools::createPolygonFromEllipse(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()), nWdt, nHgt));
411 
412 					aPoly.append(aInnerPoly);
413 					break;
414 				}
415 				case SID_DRAW_BEZIER_NOFILL:
416 				{
417 					basegfx::B2DPolygon aInnerPoly;
418 
419 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
420 
421 					const basegfx::B2DPoint aCenterBottom(rRectangle.Center().X(), rRectangle.Bottom());
422 					aInnerPoly.appendBezierSegment(
423 						aCenterBottom,
424 						aCenterBottom,
425 						basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
426 
427 					const basegfx::B2DPoint aCenterTop(rRectangle.Center().X(), rRectangle.Top());
428 					aInnerPoly.appendBezierSegment(
429 						aCenterTop,
430 						aCenterTop,
431 						basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
432 
433 					aPoly.append(aInnerPoly);
434 					break;
435 				}
436 				case SID_DRAW_FREELINE:
437 				case SID_DRAW_FREELINE_NOFILL:
438 				{
439 					basegfx::B2DPolygon aInnerPoly;
440 
441 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
442 
443 					aInnerPoly.appendBezierSegment(
444 						basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()),
445 						basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Top()),
446 						basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
447 
448 					aInnerPoly.appendBezierSegment(
449 						basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()),
450 						basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()),
451 						basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
452 
453 					if(SID_DRAW_FREELINE == nID)
454 					{
455 						aInnerPoly.append(basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()));
456 					}
457 					else
458 					{
459 						aInnerPoly.setClosed(true);
460 					}
461 
462 					aPoly.append(aInnerPoly);
463 					break;
464 				}
465 				case SID_DRAW_XPOLYGON:
466 				case SID_DRAW_XPOLYGON_NOFILL:
467 				{
468 					basegfx::B2DPolygon aInnerPoly;
469 
470 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
471 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()));
472 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Top()));
473 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
474 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Right(), rRectangle.Center().Y()));
475 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()));
476 
477 					if(SID_DRAW_XPOLYGON_NOFILL == nID)
478 					{
479 						aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()));
480 					}
481 					else
482 					{
483 						aInnerPoly.setClosed(true);
484 					}
485 
486 					aPoly.append(aInnerPoly);
487 					break;
488 				}
489 				case SID_DRAW_POLYGON:
490 				case SID_DRAW_POLYGON_NOFILL:
491 				{
492 					basegfx::B2DPolygon aInnerPoly;
493 					const sal_Int32 nWdt(rRectangle.GetWidth());
494 					const sal_Int32 nHgt(rRectangle.GetHeight());
495 
496 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
497 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 30) / 100, rRectangle.Top() + (nHgt * 70) / 100));
498 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top() + (nHgt * 15) / 100));
499 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 65) / 100, rRectangle.Top()));
500 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + nWdt, rRectangle.Top() + (nHgt * 30) / 100));
501 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 50) / 100));
502 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 75) / 100));
503 					aInnerPoly.append(basegfx::B2DPoint(rRectangle.Bottom(), rRectangle.Right()));
504 
505 					if(SID_DRAW_POLYGON_NOFILL == nID)
506 					{
507 						aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()));
508 					}
509 					else
510 					{
511 						aInnerPoly.setClosed(true);
512 					}
513 
514 					aPoly.append(aInnerPoly);
515 					break;
516 				}
517 			}
518 
519 			((SdrPathObj*)pObj)->SetPathPoly(aPoly);
520 		}
521 		else
522 		{
523 			DBG_ERROR("Object is NO path object");
524 		}
525 
526 		pObj->SetLogicRect(rRectangle);
527 	}
528 
529 	return pObj;
530 }
531 
532 } // end of namespace sd
533 
534 // eof
535