Update ooo320-m1
[ooovba.git] / sd / source / ui / func / fuconbez.cxx
blob52d22438665c48c02fca1c4c343f5f9638511458
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fuconbez.cxx,v $
10 * $Revision: 1.20 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include <com/sun/star/presentation/EffectNodeType.hpp>
36 #include "fuconbez.hxx"
37 #include <svtools/aeitem.hxx>
38 #include <svx/svdopath.hxx>
39 #include <svtools/intitem.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <svx/svdobj.hxx>
42 #include <sfx2/bindings.hxx>
43 #include <sfx2/request.hxx>
44 #include <sfx2/viewfrm.hxx>
47 #include <svx/svxids.hrc>
48 #include <svx/svdpagv.hxx>
50 #include "app.hrc"
51 #include "ViewShell.hxx"
52 #include "ViewShellBase.hxx"
53 #include "View.hxx"
54 #include "Window.hxx"
55 #include "ToolBarManager.hxx"
56 #include "drawdoc.hxx"
57 #include "res_bmp.hrc"
58 #include <basegfx/polygon/b2dpolygon.hxx>
59 #include <basegfx/polygon/b2dpolygontools.hxx>
61 #include "CustomAnimationEffect.hxx"
63 using namespace ::com::sun::star::uno;
65 namespace sd {
67 TYPEINIT1( FuConstructBezierPolygon, FuConstruct );
70 /*************************************************************************
72 |* Konstruktor
74 \************************************************************************/
76 FuConstructBezierPolygon::FuConstructBezierPolygon (
77 ViewShell* pViewSh,
78 ::sd::Window* pWin,
79 ::sd::View* pView,
80 SdDrawDocument* pDoc,
81 SfxRequest& rReq)
82 : FuConstruct(pViewSh, pWin, pView, pDoc, rReq),
83 nEditMode(SID_BEZIER_MOVE)
87 FunctionReference FuConstructBezierPolygon::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
89 FuConstructBezierPolygon* pFunc;
90 FunctionReference xFunc( pFunc = new FuConstructBezierPolygon( pViewSh, pWin, pView, pDoc, rReq ) );
91 xFunc->DoExecute(rReq);
92 pFunc->SetPermanent(bPermanent);
93 return xFunc;
96 void FuConstructBezierPolygon::DoExecute( SfxRequest& rReq )
98 FuConstruct::DoExecute( rReq );
100 const SfxItemSet* pArgs = rReq.GetArgs();
101 if( pArgs )
103 const SfxPoolItem* pPoolItem = NULL;
104 if( SFX_ITEM_SET == pArgs->GetItemState( SID_ADD_MOTION_PATH, TRUE, &pPoolItem ) )
105 maTargets = ( ( const SfxUnoAnyItem* ) pPoolItem )->GetValue();
109 /*************************************************************************
111 |* MouseButtonDown-event
113 \************************************************************************/
115 BOOL FuConstructBezierPolygon::MouseButtonDown(const MouseEvent& rMEvt)
117 BOOL bReturn = FuConstruct::MouseButtonDown(rMEvt);
119 SdrViewEvent aVEvt;
120 SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
122 if (eHit == SDRHIT_HANDLE || rMEvt.IsMod1())
124 mpView->SetEditMode(SDREDITMODE_EDIT);
126 else
128 mpView->SetEditMode(SDREDITMODE_CREATE);
131 if (aVEvt.eEvent == SDREVENT_BEGTEXTEDIT)
133 // Texteingabe hier nicht zulassen
134 aVEvt.eEvent = SDREVENT_BEGDRAGOBJ;
135 mpView->EnableExtendedMouseEventDispatcher(FALSE);
137 else
139 mpView->EnableExtendedMouseEventDispatcher(TRUE);
142 if (eHit == SDRHIT_MARKEDOBJECT && nEditMode == SID_BEZIER_INSERT)
144 /******************************************************************
145 * Klebepunkt einfuegen
146 ******************************************************************/
147 mpView->BegInsObjPoint(aMDPos, rMEvt.IsMod1());
149 else
151 mpView->MouseButtonDown(rMEvt, mpWindow);
153 SdrObject* pObj = mpView->GetCreateObj();
155 if (pObj)
157 SfxItemSet aAttr(mpDoc->GetPool());
158 SetStyleSheet(aAttr, pObj);
159 pObj->SetMergedItemSet(aAttr);
163 return(bReturn);
166 /*************************************************************************
168 |* MouseMove-event
170 \************************************************************************/
172 BOOL FuConstructBezierPolygon::MouseMove(const MouseEvent& rMEvt)
174 BOOL bReturn = FuConstruct::MouseMove(rMEvt);
175 return(bReturn);
178 /*************************************************************************
180 |* MouseButtonUp-event
182 \************************************************************************/
184 BOOL FuConstructBezierPolygon::MouseButtonUp(const MouseEvent& rMEvt )
186 BOOL bReturn = FALSE;
187 BOOL bCreated = FALSE;
189 SdrViewEvent aVEvt;
190 mpView->PickAnything(rMEvt, SDRMOUSEBUTTONUP, aVEvt);
192 ULONG nCount = mpView->GetSdrPageView()->GetObjList()->GetObjCount();
194 if (mpView->IsInsObjPoint())
196 mpView->EndInsObjPoint(SDRCREATE_FORCEEND);
198 else
200 mpView->MouseButtonUp(rMEvt, mpWindow);
203 if (aVEvt.eEvent == SDREVENT_ENDCREATE)
205 bReturn = TRUE;
207 if (nCount == (mpView->GetSdrPageView()->GetObjList()->GetObjCount() - 1))
209 bCreated = TRUE;
212 // Trick, um FuDraw::DoubleClick nicht auszuloesen
213 bMBDown = FALSE;
217 bReturn = FuConstruct::MouseButtonUp(rMEvt) || bReturn;
219 bool bDeleted = false;
220 if( bCreated && maTargets.hasValue() )
222 SdrPathObj* pPathObj = dynamic_cast< SdrPathObj* >( mpView->GetSdrPageView()->GetObjList()->GetObj( nCount ) );
223 SdPage* pPage = dynamic_cast< SdPage* >( pPathObj ? pPathObj->GetPage() : 0 );
224 if( pPage )
226 boost::shared_ptr< sd::MainSequence > pMainSequence( pPage->getMainSequence() );
227 if( pMainSequence.get() )
229 Sequence< Any > aTargets;
230 maTargets >>= aTargets;
232 sal_Int32 nTCount = aTargets.getLength();
233 if( nTCount > 1 )
235 const Any* pTarget = aTargets.getConstArray();
236 double fDuration = 0.0;
237 *pTarget++ >>= fDuration;
238 bool bFirst = true;
239 while( --nTCount )
241 CustomAnimationEffectPtr pCreated( pMainSequence->append( *pPathObj, *pTarget++, fDuration ) );
242 if( bFirst )
243 bFirst = false;
244 else
245 pCreated->setNodeType( ::com::sun::star::presentation::EffectNodeType::WITH_PREVIOUS );
250 mpView->DeleteMarked();
251 bDeleted = true;
254 if ((!bPermanent && bCreated) || bDeleted)
256 mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
259 return(bReturn);
262 /*************************************************************************
264 |* Tastaturereignisse bearbeiten
266 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert TRUE, andernfalls
267 |* FALSE.
269 \************************************************************************/
271 BOOL FuConstructBezierPolygon::KeyInput(const KeyEvent& rKEvt)
273 BOOL bReturn = FuConstruct::KeyInput(rKEvt);
275 return(bReturn);
278 /*************************************************************************
280 |* Function aktivieren
282 \************************************************************************/
284 void FuConstructBezierPolygon::Activate()
286 mpView->EnableExtendedMouseEventDispatcher(TRUE);
288 SdrObjKind eKind;
290 switch (nSlotId)
292 case SID_DRAW_POLYGON_NOFILL:
293 case SID_DRAW_XPOLYGON_NOFILL:
295 eKind = OBJ_PLIN;
297 break;
299 case SID_DRAW_POLYGON:
300 case SID_DRAW_XPOLYGON:
302 eKind = OBJ_POLY;
304 break;
306 case SID_DRAW_BEZIER_NOFILL:
308 eKind = OBJ_PATHLINE;
310 break;
312 case SID_DRAW_BEZIER_FILL:
314 eKind = OBJ_PATHFILL;
316 break;
318 case SID_DRAW_FREELINE_NOFILL:
320 eKind = OBJ_FREELINE;
322 break;
324 case SID_DRAW_FREELINE:
326 eKind = OBJ_FREEFILL;
328 break;
330 default:
332 eKind = OBJ_PATHLINE;
334 break;
337 mpView->SetCurrentObj((UINT16)eKind);
339 FuConstruct::Activate();
342 /*************************************************************************
344 |* Function deaktivieren
346 \************************************************************************/
348 void FuConstructBezierPolygon::Deactivate()
350 mpView->EnableExtendedMouseEventDispatcher(FALSE);
352 FuConstruct::Deactivate();
356 /*************************************************************************
358 |* Selektion hat sich geaendert
360 \************************************************************************/
362 void FuConstructBezierPolygon::SelectionHasChanged()
364 FuDraw::SelectionHasChanged();
366 mpViewShell->GetViewShellBase().GetToolBarManager()->SelectionHasChanged(
367 *mpViewShell,
368 *mpView);
373 /*************************************************************************
375 |* Aktuellen Bezier-Editmodus setzen
377 \************************************************************************/
379 void FuConstructBezierPolygon::SetEditMode(USHORT nMode)
381 nEditMode = nMode;
382 ForcePointer();
384 SfxBindings& rBindings = mpViewShell->GetViewFrame()->GetBindings();
385 rBindings.Invalidate(SID_BEZIER_MOVE);
386 rBindings.Invalidate(SID_BEZIER_INSERT);
389 // #97016#
390 SdrObject* FuConstructBezierPolygon::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
392 // case SID_DRAW_POLYGON:
393 // case SID_DRAW_POLYGON_NOFILL:
394 // case SID_DRAW_XPOLYGON:
395 // case SID_DRAW_XPOLYGON_NOFILL:
396 // case SID_DRAW_FREELINE:
397 // case SID_DRAW_FREELINE_NOFILL:
398 // case SID_DRAW_BEZIER_FILL: // BASIC
399 // case SID_DRAW_BEZIER_NOFILL: // BASIC
401 SdrObject* pObj = SdrObjFactory::MakeNewObject(
402 mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
403 0L, mpDoc);
405 if(pObj)
407 if(pObj->ISA(SdrPathObj))
409 basegfx::B2DPolyPolygon aPoly;
411 switch(nID)
413 case SID_DRAW_BEZIER_FILL:
415 const sal_Int32 nWdt(rRectangle.GetWidth() / 2);
416 const sal_Int32 nHgt(rRectangle.GetHeight() / 2);
417 const basegfx::B2DPolygon aInnerPoly(basegfx::tools::createPolygonFromEllipse(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()), nWdt, nHgt));
419 aPoly.append(aInnerPoly);
420 break;
422 case SID_DRAW_BEZIER_NOFILL:
424 basegfx::B2DPolygon aInnerPoly;
426 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
428 const basegfx::B2DPoint aCenterBottom(rRectangle.Center().X(), rRectangle.Bottom());
429 aInnerPoly.appendBezierSegment(
430 aCenterBottom,
431 aCenterBottom,
432 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
434 const basegfx::B2DPoint aCenterTop(rRectangle.Center().X(), rRectangle.Top());
435 aInnerPoly.appendBezierSegment(
436 aCenterTop,
437 aCenterTop,
438 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
440 aPoly.append(aInnerPoly);
441 break;
443 case SID_DRAW_FREELINE:
444 case SID_DRAW_FREELINE_NOFILL:
446 basegfx::B2DPolygon aInnerPoly;
448 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
450 aInnerPoly.appendBezierSegment(
451 basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()),
452 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Top()),
453 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
455 aInnerPoly.appendBezierSegment(
456 basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()),
457 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()),
458 basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
460 if(SID_DRAW_FREELINE == nID)
462 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()));
464 else
466 aInnerPoly.setClosed(true);
469 aPoly.append(aInnerPoly);
470 break;
472 case SID_DRAW_XPOLYGON:
473 case SID_DRAW_XPOLYGON_NOFILL:
475 basegfx::B2DPolygon aInnerPoly;
477 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
478 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()));
479 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Top()));
480 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
481 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Right(), rRectangle.Center().Y()));
482 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()));
484 if(SID_DRAW_XPOLYGON_NOFILL == nID)
486 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()));
488 else
490 aInnerPoly.setClosed(true);
493 aPoly.append(aInnerPoly);
494 break;
496 case SID_DRAW_POLYGON:
497 case SID_DRAW_POLYGON_NOFILL:
499 basegfx::B2DPolygon aInnerPoly;
500 const sal_Int32 nWdt(rRectangle.GetWidth());
501 const sal_Int32 nHgt(rRectangle.GetHeight());
503 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
504 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 30) / 100, rRectangle.Top() + (nHgt * 70) / 100));
505 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top() + (nHgt * 15) / 100));
506 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 65) / 100, rRectangle.Top()));
507 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + nWdt, rRectangle.Top() + (nHgt * 30) / 100));
508 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 50) / 100));
509 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 75) / 100));
510 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Bottom(), rRectangle.Right()));
512 if(SID_DRAW_POLYGON_NOFILL == nID)
514 aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()));
516 else
518 aInnerPoly.setClosed(true);
521 aPoly.append(aInnerPoly);
522 break;
526 ((SdrPathObj*)pObj)->SetPathPoly(aPoly);
528 else
530 DBG_ERROR("Object is NO path object");
533 pObj->SetLogicRect(rRectangle);
536 return pObj;
539 } // end of namespace sd
541 // eof