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

Generated by: LCOV version 1.11