1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fuconbez.cxx,v $
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>
51 #include "ViewShell.hxx"
52 #include "ViewShellBase.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
;
67 TYPEINIT1( FuConstructBezierPolygon
, FuConstruct
);
70 /*************************************************************************
74 \************************************************************************/
76 FuConstructBezierPolygon::FuConstructBezierPolygon (
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
);
96 void FuConstructBezierPolygon::DoExecute( SfxRequest
& rReq
)
98 FuConstruct::DoExecute( rReq
);
100 const SfxItemSet
* pArgs
= rReq
.GetArgs();
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
);
120 SdrHitKind eHit
= mpView
->PickAnything(rMEvt
, SDRMOUSEBUTTONDOWN
, aVEvt
);
122 if (eHit
== SDRHIT_HANDLE
|| rMEvt
.IsMod1())
124 mpView
->SetEditMode(SDREDITMODE_EDIT
);
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
);
139 mpView
->EnableExtendedMouseEventDispatcher(TRUE
);
142 if (eHit
== SDRHIT_MARKEDOBJECT
&& nEditMode
== SID_BEZIER_INSERT
)
144 /******************************************************************
145 * Klebepunkt einfuegen
146 ******************************************************************/
147 mpView
->BegInsObjPoint(aMDPos
, rMEvt
.IsMod1());
151 mpView
->MouseButtonDown(rMEvt
, mpWindow
);
153 SdrObject
* pObj
= mpView
->GetCreateObj();
157 SfxItemSet
aAttr(mpDoc
->GetPool());
158 SetStyleSheet(aAttr
, pObj
);
159 pObj
->SetMergedItemSet(aAttr
);
166 /*************************************************************************
170 \************************************************************************/
172 BOOL
FuConstructBezierPolygon::MouseMove(const MouseEvent
& rMEvt
)
174 BOOL bReturn
= FuConstruct::MouseMove(rMEvt
);
178 /*************************************************************************
180 |* MouseButtonUp-event
182 \************************************************************************/
184 BOOL
FuConstructBezierPolygon::MouseButtonUp(const MouseEvent
& rMEvt
)
186 BOOL bReturn
= FALSE
;
187 BOOL bCreated
= FALSE
;
190 mpView
->PickAnything(rMEvt
, SDRMOUSEBUTTONUP
, aVEvt
);
192 ULONG nCount
= mpView
->GetSdrPageView()->GetObjList()->GetObjCount();
194 if (mpView
->IsInsObjPoint())
196 mpView
->EndInsObjPoint(SDRCREATE_FORCEEND
);
200 mpView
->MouseButtonUp(rMEvt
, mpWindow
);
203 if (aVEvt
.eEvent
== SDREVENT_ENDCREATE
)
207 if (nCount
== (mpView
->GetSdrPageView()->GetObjList()->GetObjCount() - 1))
212 // Trick, um FuDraw::DoubleClick nicht auszuloesen
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 );
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();
235 const Any
* pTarget
= aTargets
.getConstArray();
236 double fDuration
= 0.0;
237 *pTarget
++ >>= fDuration
;
241 CustomAnimationEffectPtr
pCreated( pMainSequence
->append( *pPathObj
, *pTarget
++, fDuration
) );
245 pCreated
->setNodeType( ::com::sun::star::presentation::EffectNodeType::WITH_PREVIOUS
);
250 mpView
->DeleteMarked();
254 if ((!bPermanent
&& bCreated
) || bDeleted
)
256 mpViewShell
->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT
, SFX_CALLMODE_ASYNCHRON
);
262 /*************************************************************************
264 |* Tastaturereignisse bearbeiten
266 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert TRUE, andernfalls
269 \************************************************************************/
271 BOOL
FuConstructBezierPolygon::KeyInput(const KeyEvent
& rKEvt
)
273 BOOL bReturn
= FuConstruct::KeyInput(rKEvt
);
278 /*************************************************************************
280 |* Function aktivieren
282 \************************************************************************/
284 void FuConstructBezierPolygon::Activate()
286 mpView
->EnableExtendedMouseEventDispatcher(TRUE
);
292 case SID_DRAW_POLYGON_NOFILL
:
293 case SID_DRAW_XPOLYGON_NOFILL
:
299 case SID_DRAW_POLYGON
:
300 case SID_DRAW_XPOLYGON
:
306 case SID_DRAW_BEZIER_NOFILL
:
308 eKind
= OBJ_PATHLINE
;
312 case SID_DRAW_BEZIER_FILL
:
314 eKind
= OBJ_PATHFILL
;
318 case SID_DRAW_FREELINE_NOFILL
:
320 eKind
= OBJ_FREELINE
;
324 case SID_DRAW_FREELINE
:
326 eKind
= OBJ_FREEFILL
;
332 eKind
= OBJ_PATHLINE
;
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(
373 /*************************************************************************
375 |* Aktuellen Bezier-Editmodus setzen
377 \************************************************************************/
379 void FuConstructBezierPolygon::SetEditMode(USHORT nMode
)
384 SfxBindings
& rBindings
= mpViewShell
->GetViewFrame()->GetBindings();
385 rBindings
.Invalidate(SID_BEZIER_MOVE
);
386 rBindings
.Invalidate(SID_BEZIER_INSERT
);
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(),
407 if(pObj
->ISA(SdrPathObj
))
409 basegfx::B2DPolyPolygon aPoly
;
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
);
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(
432 basegfx::B2DPoint(rRectangle
.Center().X(), rRectangle
.Center().Y()));
434 const basegfx::B2DPoint
aCenterTop(rRectangle
.Center().X(), rRectangle
.Top());
435 aInnerPoly
.appendBezierSegment(
438 basegfx::B2DPoint(rRectangle
.Right(), rRectangle
.Top()));
440 aPoly
.append(aInnerPoly
);
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()));
466 aInnerPoly
.setClosed(true);
469 aPoly
.append(aInnerPoly
);
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()));
490 aInnerPoly
.setClosed(true);
493 aPoly
.append(aInnerPoly
);
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()));
518 aInnerPoly
.setClosed(true);
521 aPoly
.append(aInnerPoly
);
526 ((SdrPathObj
*)pObj
)->SetPathPoly(aPoly
);
530 DBG_ERROR("Object is NO path object");
533 pObj
->SetLogicRect(rRectangle
);
539 } // end of namespace sd