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