LCOV - code coverage report
Current view: top level - sd/source/ui/view - drbezob.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 4 130 3.1 %
Date: 2014-11-03 Functions: 5 16 31.2 %
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             : #include "BezierObjectBar.hxx"
      21             : #include <sfx2/app.hxx>
      22             : #include <sfx2/msg.hxx>
      23             : #include <sfx2/viewfrm.hxx>
      24             : #include <sfx2/objface.hxx>
      25             : 
      26             : #include <svx/svxids.hrc>
      27             : #include <svl/eitem.hxx>
      28             : #include <sfx2/request.hxx>
      29             : #include <svx/svdopath.hxx>
      30             : #include <svl/aeitem.hxx>
      31             : #include <svx/svdundo.hxx>
      32             : #include <sfx2/dispatch.hxx>
      33             : 
      34             : #include "sdresid.hxx"
      35             : 
      36             : #include "res_bmp.hrc"
      37             : #include "glob.hrc"
      38             : #include "strings.hrc"
      39             : 
      40             : #include "DrawDocShell.hxx"
      41             : #include "ViewShell.hxx"
      42             : #include "Window.hxx"
      43             : #include "drawview.hxx"
      44             : #include "drawdoc.hxx"
      45             : #include "fusel.hxx"
      46             : #include "fuconbez.hxx"
      47             : 
      48             : using namespace sd;
      49             : #define BezierObjectBar
      50             : #include "sdslots.hxx"
      51             : 
      52             : namespace sd {
      53             : 
      54             : /**
      55             :  * Declare default interface (Slotmap must not be empty)
      56             :  */
      57             : 
      58          72 : SFX_IMPL_INTERFACE(BezierObjectBar, ::SfxShell, SdResId(STR_BEZIEROBJECTBARSHELL))
      59             : 
      60          36 : void BezierObjectBar::InitInterface_Impl()
      61             : {
      62          36 : }
      63             : 
      64           0 : TYPEINIT1(BezierObjectBar, ::SfxShell);
      65             : 
      66           0 : BezierObjectBar::BezierObjectBar(
      67             :     ViewShell* pSdViewShell,
      68             :     ::sd::View* pSdView)
      69             :     : SfxShell(pSdViewShell->GetViewShell()),
      70             :       mpView(pSdView),
      71           0 :       mpViewSh(pSdViewShell)
      72             : {
      73           0 :     DrawDocShell* pDocShell = mpViewSh->GetDocSh();
      74           0 :     SetPool(&pDocShell->GetPool());
      75           0 :     SetUndoManager(pDocShell->GetUndoManager());
      76           0 :     SetRepeatTarget(mpView);
      77             : 
      78           0 :     SetHelpId( SD_IF_SDDRAWBEZIEROBJECTBAR );
      79           0 : }
      80             : 
      81           0 : BezierObjectBar::~BezierObjectBar()
      82             : {
      83           0 :     SetRepeatTarget(NULL);
      84           0 : }
      85             : 
      86             : /**
      87             :  * Status of attribute items.
      88             :  */
      89             : 
      90           0 : void BezierObjectBar::GetAttrState(SfxItemSet& rSet)
      91             : {
      92           0 :     SfxItemSet aAttrSet( mpView->GetDoc().GetPool() );
      93           0 :     mpView->GetAttributes( aAttrSet );
      94           0 :     rSet.Put(aAttrSet, false); // <- sal_False, so DontCare-Status gets aquired
      95             : 
      96           0 :     rtl::Reference<FuPoor> xFunc( mpViewSh->GetCurrentFunction() );
      97             : 
      98           0 :     if(xFunc.is())
      99             :     {
     100           0 :         if(xFunc->ISA(FuSelection))
     101             :         {
     102           0 :             sal_uInt16 nEditMode = static_cast<FuSelection*>(xFunc.get())->GetEditMode();
     103           0 :             rSet.Put(SfxBoolItem(nEditMode, true));
     104             :         }
     105           0 :         else if (xFunc->ISA(FuConstructBezierPolygon))
     106             :         {
     107           0 :             sal_uInt16 nEditMode = static_cast<FuConstructBezierPolygon*>(xFunc.get())->GetEditMode();
     108           0 :             rSet.Put(SfxBoolItem(nEditMode, true));
     109             :         }
     110             :     }
     111             : 
     112           0 :     if(!mpView->IsMoveAllowed() || !mpView->IsResizeAllowed())
     113             :     {
     114             :         // #i77187# if object is move and/or size protected, do not allow point editing at all
     115           0 :         rSet.DisableItem(SID_BEZIER_MOVE);
     116           0 :         rSet.DisableItem(SID_BEZIER_INSERT);
     117             : 
     118           0 :         rSet.DisableItem(SID_BEZIER_DELETE);
     119           0 :         rSet.DisableItem(SID_BEZIER_CUTLINE);
     120           0 :         rSet.DisableItem(SID_BEZIER_CONVERT);
     121             : 
     122           0 :         rSet.DisableItem(SID_BEZIER_EDGE);
     123           0 :         rSet.DisableItem(SID_BEZIER_SMOOTH);
     124           0 :         rSet.DisableItem(SID_BEZIER_SYMMTR);
     125             : 
     126           0 :         rSet.DisableItem(SID_BEZIER_CLOSE);
     127             : 
     128           0 :         rSet.DisableItem(SID_BEZIER_ELIMINATE_POINTS);
     129             :     }
     130             :     else
     131             :     {
     132           0 :         IPolyPolygonEditorController* pIPPEC = 0;
     133           0 :         if( mpView->GetMarkedObjectList().GetMarkCount() )
     134           0 :             pIPPEC = mpView;
     135             :         else
     136           0 :             pIPPEC = dynamic_cast< IPolyPolygonEditorController* >( mpView->getSmartTags().getSelected().get() );
     137             : 
     138           0 :         if ( !pIPPEC || !pIPPEC->IsRipUpAtMarkedPointsPossible())
     139             :         {
     140           0 :             rSet.DisableItem(SID_BEZIER_CUTLINE);
     141             :         }
     142           0 :         if (!pIPPEC || !pIPPEC->IsDeleteMarkedPointsPossible())
     143             :         {
     144           0 :             rSet.DisableItem(SID_BEZIER_DELETE);
     145             :         }
     146           0 :         if (!pIPPEC || !pIPPEC->IsSetMarkedSegmentsKindPossible())
     147             :         {
     148           0 :             rSet.DisableItem(SID_BEZIER_CONVERT);
     149             :         }
     150             :         else
     151             :         {
     152           0 :             SdrPathSegmentKind eSegm = pIPPEC->GetMarkedSegmentsKind();
     153           0 :             switch (eSegm)
     154             :             {
     155           0 :                 case SDRPATHSEGMENT_DONTCARE: rSet.InvalidateItem(SID_BEZIER_CONVERT); break;
     156           0 :                 case SDRPATHSEGMENT_LINE    : rSet.Put(SfxBoolItem(SID_BEZIER_CONVERT,false)); break; // Button down = curve
     157           0 :                 case SDRPATHSEGMENT_CURVE   : rSet.Put(SfxBoolItem(SID_BEZIER_CONVERT,true));  break;
     158           0 :                 default: break;
     159             :             }
     160             :         }
     161           0 :         if (!pIPPEC || !pIPPEC->IsSetMarkedPointsSmoothPossible())
     162             :         {
     163           0 :             rSet.DisableItem(SID_BEZIER_EDGE);
     164           0 :             rSet.DisableItem(SID_BEZIER_SMOOTH);
     165           0 :             rSet.DisableItem(SID_BEZIER_SYMMTR);
     166             :         }
     167             :         else
     168             :         {
     169           0 :             SdrPathSmoothKind eSmooth = pIPPEC->GetMarkedPointsSmooth();
     170           0 :             switch (eSmooth)
     171             :             {
     172           0 :                 case SDRPATHSMOOTH_DONTCARE  : break;
     173           0 :                 case SDRPATHSMOOTH_ANGULAR   : rSet.Put(SfxBoolItem(SID_BEZIER_EDGE,  true)); break;
     174           0 :                 case SDRPATHSMOOTH_ASYMMETRIC: rSet.Put(SfxBoolItem(SID_BEZIER_SMOOTH,true)); break;
     175           0 :                 case SDRPATHSMOOTH_SYMMETRIC : rSet.Put(SfxBoolItem(SID_BEZIER_SYMMTR,true)); break;
     176             :             }
     177             :         }
     178           0 :         if (!pIPPEC || !pIPPEC->IsOpenCloseMarkedObjectsPossible())
     179             :         {
     180           0 :             rSet.DisableItem(SID_BEZIER_CLOSE);
     181             :         }
     182             :         else
     183             :         {
     184           0 :             SdrObjClosedKind eClose = pIPPEC->GetMarkedObjectsClosedState();
     185           0 :             switch (eClose)
     186             :             {
     187           0 :                 case SDROBJCLOSED_DONTCARE: rSet.InvalidateItem(SID_BEZIER_CLOSE); break;
     188           0 :                 case SDROBJCLOSED_OPEN    : rSet.Put(SfxBoolItem(SID_BEZIER_CLOSE,false)); break;
     189           0 :                 case SDROBJCLOSED_CLOSED  : rSet.Put(SfxBoolItem(SID_BEZIER_CLOSE,true)); break;
     190           0 :                 default: break;
     191             :             }
     192             :         }
     193             : 
     194           0 :         if(pIPPEC == mpView)
     195           0 :             rSet.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS, mpView->IsEliminatePolyPoints()));
     196             :         else
     197           0 :             rSet.DisableItem( SID_BEZIER_ELIMINATE_POINTS ); // only works for views
     198           0 :     }
     199           0 : }
     200             : 
     201             : /**
     202             :  * Process SfxRequests
     203             :  */
     204             : 
     205           0 : void BezierObjectBar::Execute(SfxRequest& rReq)
     206             : {
     207           0 :     sal_uInt16 nSId = rReq.GetSlot();
     208             : 
     209           0 :     switch (nSId)
     210             :     {
     211             :         case SID_BEZIER_CUTLINE:
     212             :         case SID_BEZIER_CONVERT:
     213             :         case SID_BEZIER_DELETE:
     214             :         case SID_BEZIER_EDGE:
     215             :         case SID_BEZIER_SMOOTH:
     216             :         case SID_BEZIER_SYMMTR:
     217             :         case SID_BEZIER_CLOSE:
     218             :         {
     219           0 :             const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
     220             : 
     221           0 :             IPolyPolygonEditorController* pIPPEC = 0;
     222           0 :             if( rMarkList.GetMarkCount() )
     223           0 :                 pIPPEC = mpView;
     224             :             else
     225           0 :                 pIPPEC = dynamic_cast< IPolyPolygonEditorController* >( mpView->getSmartTags().getSelected().get() );
     226             : 
     227           0 :             if( pIPPEC && !mpView->IsAction())
     228             :             {
     229           0 :                 switch (nSId)
     230             :                 {
     231             :                     case SID_BEZIER_DELETE:
     232           0 :                         pIPPEC->DeleteMarkedPoints();
     233           0 :                         break;
     234             : 
     235             :                     case SID_BEZIER_CUTLINE:
     236           0 :                         pIPPEC->RipUpAtMarkedPoints();
     237           0 :                         break;
     238             : 
     239             :                     case SID_BEZIER_CONVERT:
     240             :                     {
     241           0 :                         pIPPEC->SetMarkedSegmentsKind(SDRPATHSEGMENT_TOGGLE);
     242           0 :                         break;
     243             :                     }
     244             : 
     245             :                     case SID_BEZIER_EDGE:
     246             :                     case SID_BEZIER_SMOOTH:
     247             :                     case SID_BEZIER_SYMMTR:
     248             :                     {
     249             :                         SdrPathSmoothKind eKind;
     250             : 
     251           0 :                         switch (nSId)
     252             :                         {
     253             :                             default:
     254           0 :                             case SID_BEZIER_EDGE:   eKind = SDRPATHSMOOTH_ANGULAR; break;
     255           0 :                             case SID_BEZIER_SMOOTH: eKind = SDRPATHSMOOTH_ASYMMETRIC; break;
     256           0 :                             case SID_BEZIER_SYMMTR: eKind = SDRPATHSMOOTH_SYMMETRIC; break;
     257             :                         }
     258             : 
     259           0 :                         pIPPEC->SetMarkedPointsSmooth(eKind);
     260           0 :                         break;
     261             :                     }
     262             : 
     263             :                     case SID_BEZIER_CLOSE:
     264             :                     {
     265           0 :                         SdrPathObj* pPathObj = (SdrPathObj*) rMarkList.GetMark(0)->GetMarkedSdrObj();
     266           0 :                         const bool bUndo = mpView->IsUndoEnabled();
     267           0 :                         if( bUndo )
     268           0 :                             mpView->BegUndo(SD_RESSTR(STR_UNDO_BEZCLOSE));
     269             : 
     270           0 :                         mpView->UnmarkAllPoints();
     271             : 
     272           0 :                         if( bUndo )
     273           0 :                             mpView->AddUndo(mpView->GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pPathObj));
     274             : 
     275           0 :                         pPathObj->ToggleClosed();
     276             : 
     277           0 :                         if( bUndo )
     278           0 :                             mpView->EndUndo();
     279           0 :                         break;
     280             :                     }
     281             :                 }
     282             :             }
     283             : 
     284           0 :             if( (pIPPEC == mpView) && !mpView->AreObjectsMarked() )
     285           0 :                 mpViewSh->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
     286             : 
     287           0 :             rReq.Ignore();
     288             :         }
     289           0 :         break;
     290             : 
     291             :         case SID_BEZIER_ELIMINATE_POINTS:
     292             :         {
     293           0 :             mpView->SetEliminatePolyPoints(!mpView->IsEliminatePolyPoints());
     294           0 :             Invalidate(SID_BEZIER_ELIMINATE_POINTS);
     295           0 :             rReq.Done();
     296             :         }
     297           0 :         break;
     298             : 
     299             :         case SID_BEZIER_MOVE:
     300             :         case SID_BEZIER_INSERT:
     301             :         {
     302           0 :             rtl::Reference<FuPoor> xFunc( mpViewSh->GetCurrentFunction() );
     303             : 
     304           0 :             if(xFunc.is())
     305             :             {
     306           0 :                 if(xFunc->ISA(FuSelection))
     307             :                 {
     308           0 :                     static_cast<FuSelection*>(xFunc.get())->SetEditMode(rReq.GetSlot());
     309             :                 }
     310           0 :                 else if(xFunc->ISA(FuConstructBezierPolygon))
     311             :                 {
     312           0 :                     static_cast<FuConstructBezierPolygon*>(xFunc.get())->SetEditMode(rReq.GetSlot());
     313             :                 }
     314             :             }
     315             : 
     316           0 :             rReq.Ignore ();
     317             :         }
     318           0 :         break;
     319             : 
     320             :         default:
     321           0 :         break;
     322             :     }
     323             : 
     324           0 :     Invalidate();
     325           0 : }
     326             : 
     327         114 : } // end of namespace sd
     328             : 
     329             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10