LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/ui/func - fuconbez.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 187 0.5 %
Date: 2013-07-09 Functions: 2 19 10.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <com/sun/star/presentation/EffectNodeType.hpp>
      22             : 
      23             : #include "fuconbez.hxx"
      24             : #include <svl/aeitem.hxx>
      25             : #include <svx/svdopath.hxx>
      26             : #include <svl/intitem.hxx>
      27             : #include <sfx2/dispatch.hxx>
      28             : #include <svx/svdobj.hxx>
      29             : #include <sfx2/bindings.hxx>
      30             : #include <sfx2/request.hxx>
      31             : #include <sfx2/viewfrm.hxx>
      32             : 
      33             : 
      34             : #include <svx/svxids.hrc>
      35             : #include <svx/svdpagv.hxx>
      36             : 
      37             : #include "app.hrc"
      38             : #include "ViewShell.hxx"
      39             : #include "ViewShellBase.hxx"
      40             : #include "View.hxx"
      41             : #include "Window.hxx"
      42             : #include "ToolBarManager.hxx"
      43             : #include "drawdoc.hxx"
      44             : #include "res_bmp.hrc"
      45             : #include <basegfx/polygon/b2dpolygon.hxx>
      46             : #include <basegfx/polygon/b2dpolygontools.hxx>
      47             : 
      48             : #include "CustomAnimationEffect.hxx"
      49             : 
      50             : using namespace ::com::sun::star::uno;
      51             : 
      52             : namespace sd {
      53             : 
      54           0 : TYPEINIT1( FuConstructBezierPolygon, FuConstruct );
      55             : 
      56             : 
      57             : 
      58           0 : FuConstructBezierPolygon::FuConstructBezierPolygon (
      59             :     ViewShell* pViewSh,
      60             :     ::sd::Window* pWin,
      61             :     ::sd::View* pView,
      62             :     SdDrawDocument* pDoc,
      63             :     SfxRequest& rReq)
      64             :     : FuConstruct(pViewSh, pWin, pView, pDoc, rReq),
      65           0 :       nEditMode(SID_BEZIER_MOVE)
      66             : {
      67           0 : }
      68             : 
      69           0 : FunctionReference FuConstructBezierPolygon::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent )
      70             : {
      71             :     FuConstructBezierPolygon* pFunc;
      72           0 :     FunctionReference xFunc( pFunc = new FuConstructBezierPolygon( pViewSh, pWin, pView, pDoc, rReq ) );
      73           0 :     xFunc->DoExecute(rReq);
      74           0 :     pFunc->SetPermanent(bPermanent);
      75           0 :     return xFunc;
      76             : }
      77             : 
      78           0 : void FuConstructBezierPolygon::DoExecute( SfxRequest& rReq )
      79             : {
      80           0 :     FuConstruct::DoExecute( rReq );
      81             : 
      82           0 :     const SfxItemSet* pArgs = rReq.GetArgs();
      83           0 :     if( pArgs )
      84             :     {
      85           0 :         const SfxPoolItem*  pPoolItem = NULL;
      86           0 :         if( SFX_ITEM_SET == pArgs->GetItemState( SID_ADD_MOTION_PATH, sal_True, &pPoolItem ) )
      87           0 :             maTargets = ( ( const SfxUnoAnyItem* ) pPoolItem )->GetValue();
      88             :     }
      89           0 : }
      90             : 
      91             : 
      92           0 : sal_Bool FuConstructBezierPolygon::MouseButtonDown(const MouseEvent& rMEvt)
      93             : {
      94           0 :     sal_Bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
      95             : 
      96           0 :     SdrViewEvent aVEvt;
      97           0 :     SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
      98             : 
      99           0 :     if (eHit == SDRHIT_HANDLE || rMEvt.IsMod1())
     100             :     {
     101           0 :         mpView->SetEditMode(SDREDITMODE_EDIT);
     102             :     }
     103             :     else
     104             :     {
     105           0 :         mpView->SetEditMode(SDREDITMODE_CREATE);
     106             :     }
     107             : 
     108           0 :     if (aVEvt.eEvent == SDREVENT_BEGTEXTEDIT)
     109             :     {
     110             :         // here, we do not allow text input
     111           0 :         aVEvt.eEvent = SDREVENT_BEGDRAGOBJ;
     112           0 :         mpView->EnableExtendedMouseEventDispatcher(sal_False);
     113             :     }
     114             :     else
     115             :     {
     116           0 :         mpView->EnableExtendedMouseEventDispatcher(sal_True);
     117             :     }
     118             : 
     119           0 :     if (eHit == SDRHIT_MARKEDOBJECT && nEditMode == SID_BEZIER_INSERT)
     120             :     {
     121             :         // insert glue point
     122           0 :         mpView->BegInsObjPoint(aMDPos, rMEvt.IsMod1());
     123             :     }
     124             :     else
     125             :     {
     126           0 :         mpView->MouseButtonDown(rMEvt, mpWindow);
     127             : 
     128           0 :         SdrObject* pObj = mpView->GetCreateObj();
     129             : 
     130           0 :         if (pObj)
     131             :         {
     132           0 :             SfxItemSet aAttr(mpDoc->GetPool());
     133           0 :             SetStyleSheet(aAttr, pObj);
     134           0 :             pObj->SetMergedItemSet(aAttr);
     135             :         }
     136             :     }
     137             : 
     138           0 :     return(bReturn);
     139             : }
     140             : 
     141             : 
     142           0 : sal_Bool FuConstructBezierPolygon::MouseMove(const MouseEvent& rMEvt)
     143             : {
     144           0 :     sal_Bool bReturn = FuConstruct::MouseMove(rMEvt);
     145           0 :     return(bReturn);
     146             : }
     147             : 
     148             : 
     149           0 : sal_Bool FuConstructBezierPolygon::MouseButtonUp(const MouseEvent& rMEvt )
     150             : {
     151           0 :     sal_Bool bReturn = sal_False;
     152           0 :     sal_Bool bCreated = sal_False;
     153             : 
     154           0 :     SdrViewEvent aVEvt;
     155           0 :     mpView->PickAnything(rMEvt, SDRMOUSEBUTTONUP, aVEvt);
     156             : 
     157           0 :     sal_uLong nCount = mpView->GetSdrPageView()->GetObjList()->GetObjCount();
     158             : 
     159           0 :     if (mpView->IsInsObjPoint())
     160             :     {
     161           0 :         mpView->EndInsObjPoint(SDRCREATE_FORCEEND);
     162             :     }
     163             :     else
     164             :     {
     165           0 :         mpView->MouseButtonUp(rMEvt, mpWindow);
     166             :     }
     167             : 
     168           0 :     if (aVEvt.eEvent == SDREVENT_ENDCREATE)
     169             :     {
     170           0 :         bReturn = sal_True;
     171             : 
     172           0 :         if (nCount == (mpView->GetSdrPageView()->GetObjList()->GetObjCount() - 1))
     173             :         {
     174           0 :             bCreated = sal_True;
     175             :         }
     176             : 
     177             :         // trick to suppress FuDraw::DoubleClick
     178           0 :         bMBDown = sal_False;
     179             : 
     180             :     }
     181             : 
     182           0 :     bReturn = FuConstruct::MouseButtonUp(rMEvt) || bReturn;
     183             : 
     184           0 :     bool bDeleted = false;
     185           0 :     if( bCreated && maTargets.hasValue() )
     186             :     {
     187           0 :         SdrPathObj* pPathObj = dynamic_cast< SdrPathObj* >( mpView->GetSdrPageView()->GetObjList()->GetObj( nCount ) );
     188           0 :         SdPage* pPage = dynamic_cast< SdPage* >( pPathObj ? pPathObj->GetPage() : 0 );
     189           0 :         if( pPage )
     190             :         {
     191           0 :             boost::shared_ptr< sd::MainSequence > pMainSequence( pPage->getMainSequence() );
     192           0 :             if( pMainSequence.get() )
     193             :             {
     194           0 :                 Sequence< Any > aTargets;
     195           0 :                 maTargets >>= aTargets;
     196             : 
     197           0 :                 sal_Int32 nTCount = aTargets.getLength();
     198           0 :                 if( nTCount > 1 )
     199             :                 {
     200           0 :                     const Any* pTarget = aTargets.getConstArray();
     201           0 :                     double fDuration = 0.0;
     202           0 :                     *pTarget++ >>= fDuration;
     203           0 :                     bool bFirst = true;
     204           0 :                     while( --nTCount )
     205             :                     {
     206           0 :                         CustomAnimationEffectPtr pCreated( pMainSequence->append( *pPathObj, *pTarget++, fDuration ) );
     207           0 :                         if( bFirst )
     208           0 :                             bFirst = false;
     209             :                         else
     210           0 :                             pCreated->setNodeType( ::com::sun::star::presentation::EffectNodeType::WITH_PREVIOUS );
     211           0 :                     }
     212           0 :                 }
     213           0 :             }
     214             :         }
     215           0 :         mpView->DeleteMarked();
     216           0 :         bDeleted = true;
     217             :     }
     218             : 
     219           0 :     if ((!bPermanent && bCreated) || bDeleted)
     220             :     {
     221           0 :         mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
     222             :     }
     223             : 
     224           0 :     return(bReturn);
     225             : }
     226             : 
     227             : /**
     228             :  * Process keyboard input
     229             :  * @returns sal_True if a KeyEvent is being processed, sal_False otherwise
     230             :  */
     231           0 : sal_Bool FuConstructBezierPolygon::KeyInput(const KeyEvent& rKEvt)
     232             : {
     233           0 :     sal_Bool bReturn = FuConstruct::KeyInput(rKEvt);
     234             : 
     235           0 :     return(bReturn);
     236             : }
     237             : 
     238             : 
     239           0 : void FuConstructBezierPolygon::Activate()
     240             : {
     241           0 :     mpView->EnableExtendedMouseEventDispatcher(sal_True);
     242             : 
     243             :     SdrObjKind eKind;
     244             : 
     245           0 :     switch (nSlotId)
     246             :     {
     247             :         case SID_DRAW_POLYGON_NOFILL:
     248             :         case SID_DRAW_XPOLYGON_NOFILL:
     249             :         {
     250           0 :             eKind = OBJ_PLIN;
     251             :         }
     252           0 :         break;
     253             : 
     254             :         case SID_DRAW_POLYGON:
     255             :         case SID_DRAW_XPOLYGON:
     256             :         {
     257           0 :             eKind = OBJ_POLY;
     258             :         }
     259           0 :         break;
     260             : 
     261             :         case SID_DRAW_BEZIER_NOFILL:
     262             :         {
     263           0 :             eKind = OBJ_PATHLINE;
     264             :         }
     265           0 :         break;
     266             : 
     267             :         case SID_DRAW_BEZIER_FILL:
     268             :         {
     269           0 :             eKind = OBJ_PATHFILL;
     270             :         }
     271           0 :         break;
     272             : 
     273             :         case SID_DRAW_FREELINE_NOFILL:
     274             :         {
     275           0 :             eKind = OBJ_FREELINE;
     276             :         }
     277           0 :         break;
     278             : 
     279             :         case SID_DRAW_FREELINE:
     280             :         {
     281           0 :             eKind = OBJ_FREEFILL;
     282             :         }
     283           0 :         break;
     284             : 
     285             :         default:
     286             :         {
     287           0 :             eKind = OBJ_PATHLINE;
     288             :         }
     289           0 :         break;
     290             :     }
     291             : 
     292           0 :     mpView->SetCurrentObj((sal_uInt16)eKind);
     293             : 
     294           0 :     FuConstruct::Activate();
     295           0 : }
     296             : 
     297             : 
     298           0 : void FuConstructBezierPolygon::Deactivate()
     299             : {
     300           0 :     mpView->EnableExtendedMouseEventDispatcher(sal_False);
     301             : 
     302           0 :     FuConstruct::Deactivate();
     303           0 : }
     304             : 
     305             : 
     306             : 
     307           0 : void FuConstructBezierPolygon::SelectionHasChanged()
     308             : {
     309           0 :     FuDraw::SelectionHasChanged();
     310             : 
     311           0 :     mpViewShell->GetViewShellBase().GetToolBarManager()->SelectionHasChanged(
     312             :         *mpViewShell,
     313           0 :         *mpView);
     314           0 : }
     315             : 
     316             : 
     317             : /**
     318             :  * Set current bezier edit mode
     319             :  */
     320           0 : void FuConstructBezierPolygon::SetEditMode(sal_uInt16 nMode)
     321             : {
     322           0 :     nEditMode = nMode;
     323           0 :     ForcePointer();
     324             : 
     325           0 :     SfxBindings& rBindings = mpViewShell->GetViewFrame()->GetBindings();
     326           0 :     rBindings.Invalidate(SID_BEZIER_MOVE);
     327           0 :     rBindings.Invalidate(SID_BEZIER_INSERT);
     328           0 : }
     329             : 
     330           0 : SdrObject* FuConstructBezierPolygon::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
     331             : {
     332             :     // case SID_DRAW_POLYGON:
     333             :     // case SID_DRAW_POLYGON_NOFILL:
     334             :     // case SID_DRAW_XPOLYGON:
     335             :     // case SID_DRAW_XPOLYGON_NOFILL:
     336             :     // case SID_DRAW_FREELINE:
     337             :     // case SID_DRAW_FREELINE_NOFILL:
     338             :     // case SID_DRAW_BEZIER_FILL:          // BASIC
     339             :     // case SID_DRAW_BEZIER_NOFILL:        // BASIC
     340             : 
     341             :     SdrObject* pObj = SdrObjFactory::MakeNewObject(
     342           0 :         mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
     343           0 :         0L, mpDoc);
     344             : 
     345           0 :     if(pObj)
     346             :     {
     347           0 :         if(pObj->ISA(SdrPathObj))
     348             :         {
     349           0 :             basegfx::B2DPolyPolygon aPoly;
     350             : 
     351           0 :             switch(nID)
     352             :             {
     353             :                 case SID_DRAW_BEZIER_FILL:
     354             :                 {
     355           0 :                     const sal_Int32 nWdt(rRectangle.GetWidth() / 2);
     356           0 :                     const sal_Int32 nHgt(rRectangle.GetHeight() / 2);
     357           0 :                     const basegfx::B2DPolygon aInnerPoly(basegfx::tools::createPolygonFromEllipse(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()), nWdt, nHgt));
     358             : 
     359           0 :                     aPoly.append(aInnerPoly);
     360           0 :                     break;
     361             :                 }
     362             :                 case SID_DRAW_BEZIER_NOFILL:
     363             :                 {
     364           0 :                     basegfx::B2DPolygon aInnerPoly;
     365             : 
     366           0 :                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
     367             : 
     368           0 :                     const basegfx::B2DPoint aCenterBottom(rRectangle.Center().X(), rRectangle.Bottom());
     369             :                     aInnerPoly.appendBezierSegment(
     370             :                         aCenterBottom,
     371             :                         aCenterBottom,
     372           0 :                         basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
     373             : 
     374           0 :                     const basegfx::B2DPoint aCenterTop(rRectangle.Center().X(), rRectangle.Top());
     375             :                     aInnerPoly.appendBezierSegment(
     376             :                         aCenterTop,
     377             :                         aCenterTop,
     378           0 :                         basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
     379             : 
     380           0 :                     aPoly.append(aInnerPoly);
     381           0 :                     break;
     382             :                 }
     383             :                 case SID_DRAW_FREELINE:
     384             :                 case SID_DRAW_FREELINE_NOFILL:
     385             :                 {
     386           0 :                     basegfx::B2DPolygon aInnerPoly;
     387             : 
     388           0 :                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
     389             : 
     390             :                     aInnerPoly.appendBezierSegment(
     391           0 :                         basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()),
     392           0 :                         basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Top()),
     393           0 :                         basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
     394             : 
     395             :                     aInnerPoly.appendBezierSegment(
     396           0 :                         basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()),
     397           0 :                         basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()),
     398           0 :                         basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
     399             : 
     400           0 :                     if(SID_DRAW_FREELINE == nID)
     401             :                     {
     402           0 :                         aInnerPoly.append(basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()));
     403             :                     }
     404             :                     else
     405             :                     {
     406           0 :                         aInnerPoly.setClosed(true);
     407             :                     }
     408             : 
     409           0 :                     aPoly.append(aInnerPoly);
     410           0 :                     break;
     411             :                 }
     412             :                 case SID_DRAW_XPOLYGON:
     413             :                 case SID_DRAW_XPOLYGON_NOFILL:
     414             :                 {
     415           0 :                     basegfx::B2DPolygon aInnerPoly;
     416             : 
     417           0 :                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
     418           0 :                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()));
     419           0 :                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Top()));
     420           0 :                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
     421           0 :                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Right(), rRectangle.Center().Y()));
     422           0 :                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()));
     423             : 
     424           0 :                     if(SID_DRAW_XPOLYGON_NOFILL == nID)
     425             :                     {
     426           0 :                         aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()));
     427             :                     }
     428             :                     else
     429             :                     {
     430           0 :                         aInnerPoly.setClosed(true);
     431             :                     }
     432             : 
     433           0 :                     aPoly.append(aInnerPoly);
     434           0 :                     break;
     435             :                 }
     436             :                 case SID_DRAW_POLYGON:
     437             :                 case SID_DRAW_POLYGON_NOFILL:
     438             :                 {
     439           0 :                     basegfx::B2DPolygon aInnerPoly;
     440           0 :                     const sal_Int32 nWdt(rRectangle.GetWidth());
     441           0 :                     const sal_Int32 nHgt(rRectangle.GetHeight());
     442             : 
     443           0 :                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
     444           0 :                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 30) / 100, rRectangle.Top() + (nHgt * 70) / 100));
     445           0 :                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top() + (nHgt * 15) / 100));
     446           0 :                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 65) / 100, rRectangle.Top()));
     447           0 :                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + nWdt, rRectangle.Top() + (nHgt * 30) / 100));
     448           0 :                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 50) / 100));
     449           0 :                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 75) / 100));
     450           0 :                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Bottom(), rRectangle.Right()));
     451             : 
     452           0 :                     if(SID_DRAW_POLYGON_NOFILL == nID)
     453             :                     {
     454           0 :                         aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()));
     455             :                     }
     456             :                     else
     457             :                     {
     458           0 :                         aInnerPoly.setClosed(true);
     459             :                     }
     460             : 
     461           0 :                     aPoly.append(aInnerPoly);
     462           0 :                     break;
     463             :                 }
     464             :             }
     465             : 
     466           0 :             ((SdrPathObj*)pObj)->SetPathPoly(aPoly);
     467             :         }
     468             :         else
     469             :         {
     470             :             OSL_FAIL("Object is NO path object");
     471             :         }
     472             : 
     473           0 :         pObj->SetLogicRect(rRectangle);
     474             :     }
     475             : 
     476           0 :     return pObj;
     477             : }
     478             : 
     479          33 : } // end of namespace sd
     480             : 
     481             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10