LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/shells - beziersh.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 5 130 3.8 %
Date: 2013-07-09 Functions: 5 14 35.7 %
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 "cmdid.h"
      21             : #include <svx/svdview.hxx>
      22             : #include <svl/srchitem.hxx>
      23             : #include <svl/eitem.hxx>
      24             : #include <svl/whiter.hxx>
      25             : #include <svx/svdopath.hxx>
      26             : #include <sfx2/sidebar/EnumContext.hxx>
      27             : #include <sfx2/request.hxx>
      28             : #include <sfx2/dispatch.hxx>
      29             : #include <sfx2/objface.hxx>
      30             : 
      31             : #include "wrtsh.hxx"
      32             : #include "view.hxx"
      33             : #include "edtwin.hxx"
      34             : #include "helpid.h"
      35             : #include "globals.hrc"
      36             : #include "drawbase.hxx"
      37             : #include "beziersh.hxx"
      38             : #include "popup.hrc"
      39             : #include "shells.hrc"
      40             : #define SwBezierShell
      41             : #include <sfx2/msg.hxx>
      42             : #include "swslots.hxx"
      43             : 
      44             : #include <unomid.h>
      45             : 
      46         165 : SFX_IMPL_INTERFACE(SwBezierShell, SwBaseShell, SW_RES(STR_SHELLNAME_BEZIER))
      47             : {
      48          33 :     SFX_POPUPMENU_REGISTRATION(SW_RES(MN_DRAW_POPUPMENU));
      49          33 :     SFX_OBJECTBAR_REGISTRATION(SFX_OBJECTBAR_OBJECT, SW_RES(RID_BEZIER_TOOLBOX));
      50          33 : }
      51             : 
      52           0 : TYPEINIT1(SwBezierShell,SwBaseShell)
      53             : 
      54           0 : SwBezierShell::SwBezierShell(SwView &_rView):
      55           0 :     SwBaseShell( _rView )
      56             : {
      57           0 :     SetName(OUString("Bezier"));
      58           0 :     SetHelpId(SW_BEZIERSHELL);
      59             : 
      60           0 :     SwWrtShell *pSh = &GetShell();
      61           0 :     SdrView*    pSdrView = pSh->GetDrawView();
      62           0 :     pSdrView->SetEliminatePolyPointLimitAngle(1500L);
      63             : 
      64           0 :     SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Draw));
      65           0 : }
      66             : 
      67           0 : void SwBezierShell::Execute(SfxRequest &rReq)
      68             : {
      69           0 :     SwWrtShell *pSh = &GetShell();
      70           0 :     SdrView*    pSdrView = pSh->GetDrawView();
      71           0 :     const SfxItemSet *pArgs = rReq.GetArgs();
      72           0 :     sal_uInt16      nSlotId = rReq.GetSlot();
      73           0 :     sal_Bool        bChanged = pSdrView->GetModel()->IsChanged();
      74           0 :     pSdrView->GetModel()->SetChanged(sal_False);
      75             :     const SfxPoolItem* pItem;
      76           0 :     if(pArgs)
      77           0 :         pArgs->GetItemState(nSlotId, sal_False, &pItem);
      78             : 
      79           0 :     switch (nSlotId)
      80             :     {
      81             :         case SID_DELETE:
      82             :         case FN_BACKSPACE:
      83           0 :             if (pSh->IsObjSelected())
      84             :             {
      85           0 :                 if (pSdrView->HasMarkedPoints())
      86           0 :                     pSh->GetView().GetViewFrame()->GetDispatcher()->Execute(SID_BEZIER_DELETE, sal_False);
      87             :                 else
      88             :                 {
      89           0 :                     pSh->DelSelectedObj();
      90           0 :                     if (pSh->IsSelFrmMode())
      91             :                     {
      92           0 :                         pSh->LeaveSelFrmMode();
      93           0 :                         pSh->NoEdit();
      94             :                     }
      95           0 :                     GetView().AttrChangedNotify(pSh); // Shell change if applicable...
      96             :                 }
      97             :             }
      98           0 :             break;
      99             : 
     100             :         case FN_ESCAPE:
     101           0 :             if (pSdrView->HasMarkedPoints())
     102           0 :                 pSdrView->UnmarkAllPoints();
     103             :             else
     104             :             {
     105           0 :                 if ( pSh->IsDrawCreate() )
     106             :                 {
     107           0 :                     GetView().GetDrawFuncPtr()->BreakCreate();
     108           0 :                     GetView().AttrChangedNotify(pSh); // Shell change if applicable...
     109             :                 }
     110           0 :                 else if ( pSh->HasSelection() || GetView().IsDrawMode() )
     111             :                 {
     112           0 :                     GetView().LeaveDrawCreate();
     113           0 :                     pSh->EnterStdMode();
     114           0 :                     GetView().AttrChangedNotify(pSh); // Shell change if applicable...
     115             :                 }
     116             :             }
     117           0 :             break;
     118             : 
     119             :         case SID_BEZIER_MOVE:
     120             :         case SID_BEZIER_INSERT:
     121             :             {
     122           0 :                 GetView().GetEditWin().SetBezierMode(nSlotId);
     123             :                 static sal_uInt16 aInva[] =
     124             :                                 {
     125             :                                     SID_BEZIER_INSERT,
     126             :                                     SID_BEZIER_MOVE,
     127             :                                     0
     128             :                                 };
     129           0 :                 GetView().GetViewFrame()->GetBindings().Invalidate(aInva);
     130             :             }
     131           0 :             break;
     132             : 
     133             :         case SID_BEZIER_DELETE:
     134             :         case SID_BEZIER_CUTLINE:
     135             :         case SID_BEZIER_CONVERT:
     136             :         case SID_BEZIER_EDGE:
     137             :         case SID_BEZIER_SMOOTH:
     138             :         case SID_BEZIER_SYMMTR:
     139             :         case SID_BEZIER_CLOSE:
     140             :         case SID_BEZIER_ELIMINATE_POINTS:
     141             :         {
     142           0 :             const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
     143             : 
     144           0 :             if (rMarkList.GetMark(0) && !pSdrView->IsAction())
     145             :             {
     146           0 :                 switch (nSlotId)
     147             :                 {
     148             :                     case SID_BEZIER_DELETE:
     149           0 :                         pSdrView->DeleteMarkedPoints();
     150           0 :                         break;
     151             : 
     152             :                     case SID_BEZIER_CUTLINE:
     153             :                         {
     154           0 :                             pSdrView->RipUpAtMarkedPoints();
     155           0 :                             pSh->CheckUnboundObjects();
     156             :                         }
     157           0 :                         break;
     158             : 
     159             :                     case SID_BEZIER_CONVERT:
     160             :                     {
     161           0 :                         pSdrView->SetMarkedSegmentsKind(SDRPATHSEGMENT_TOGGLE);
     162           0 :                         break;
     163             :                     }
     164             : 
     165             :                     case SID_BEZIER_EDGE:
     166             :                     case SID_BEZIER_SMOOTH:
     167             :                     case SID_BEZIER_SYMMTR:
     168             :                     {
     169           0 :                         SdrPathSmoothKind eKind = SDRPATHSMOOTH_ASYMMETRIC;
     170             : 
     171           0 :                         switch (nSlotId)
     172             :                         {
     173           0 :                             case SID_BEZIER_EDGE:   eKind = SDRPATHSMOOTH_ANGULAR; break;
     174           0 :                             case SID_BEZIER_SMOOTH: eKind = SDRPATHSMOOTH_ASYMMETRIC; break;
     175           0 :                             case SID_BEZIER_SYMMTR: eKind = SDRPATHSMOOTH_SYMMETRIC; break;
     176             :                         }
     177             : 
     178           0 :                         SdrPathSmoothKind eSmooth = pSdrView->GetMarkedPointsSmooth();
     179           0 :                         if (eKind != eSmooth)
     180             :                         {
     181           0 :                             pSdrView->SetMarkedPointsSmooth(eKind);
     182             : 
     183             :                             static sal_uInt16 aInva[] =
     184             :                                             {
     185             :                                                 SID_BEZIER_SMOOTH,
     186             :                                                 SID_BEZIER_EDGE,
     187             :                                                 SID_BEZIER_SYMMTR,
     188             :                                                 0
     189             :                                             };
     190           0 :                             GetView().GetViewFrame()->GetBindings().Invalidate(aInva);
     191             :                         }
     192           0 :                         break;
     193             :                     }
     194             : 
     195             :                     case SID_BEZIER_CLOSE:
     196             :                     {
     197           0 :                         SdrPathObj* pPathObj = (SdrPathObj*) rMarkList.GetMark(0)->GetMarkedSdrObj();
     198           0 :                         pSdrView->UnmarkAllPoints();
     199             :                         // Size aDist(GetView().GetEditWin().PixelToLogic(Size(8,8)));
     200           0 :                         pPathObj->ToggleClosed(); // aDist.Width());
     201           0 :                         break;
     202             :                     }
     203             : 
     204             :                     case SID_BEZIER_ELIMINATE_POINTS:
     205           0 :                         pSdrView->SetEliminatePolyPoints(!pSdrView->IsEliminatePolyPoints());
     206           0 :                         break;
     207             :                 }
     208             :             }
     209             :         }
     210           0 :         break;
     211             : 
     212             :         default:
     213           0 :             break;
     214             :     }
     215             : 
     216           0 :     if (pSdrView->GetModel()->IsChanged())
     217           0 :         GetShell().SetModified();
     218           0 :     else if (bChanged)
     219           0 :         pSdrView->GetModel()->SetChanged(sal_True);
     220           0 : }
     221             : 
     222           0 : void SwBezierShell::GetState(SfxItemSet &rSet)
     223             : {
     224           0 :     SdrView* pSdrView = GetShell().GetDrawView();
     225             : 
     226           0 :     SfxWhichIter aIter( rSet );
     227           0 :     sal_uInt16 nWhich = aIter.FirstWhich();
     228             : 
     229           0 :     while( nWhich )
     230             :     {
     231           0 :         switch( nWhich )
     232             :         {
     233             :             case SID_BEZIER_MOVE:
     234             :             case SID_BEZIER_INSERT:
     235             :             {
     236           0 :                 sal_uInt16 nEditMode = GetView().GetEditWin().GetBezierMode();
     237             : 
     238           0 :                 rSet.Put(SfxBoolItem(nWhich, nEditMode == nWhich));
     239             :             }
     240           0 :             break;
     241             : 
     242             :             case SID_BEZIER_CUTLINE:
     243           0 :                 if (!pSdrView->IsRipUpAtMarkedPointsPossible())
     244             :                 {
     245           0 :                     rSet.DisableItem(SID_BEZIER_CUTLINE);
     246             :                 }
     247           0 :                 break;
     248             : 
     249             :             case SID_BEZIER_DELETE:
     250           0 :                 if (!pSdrView->IsDeleteMarkedPointsPossible())
     251             :                 {
     252           0 :                     rSet.DisableItem(SID_BEZIER_DELETE);
     253             :                 }
     254           0 :                 break;
     255             : 
     256             :             case SID_BEZIER_CONVERT:
     257           0 :                 if (!pSdrView->IsSetMarkedSegmentsKindPossible())
     258             :                 {
     259           0 :                     rSet.DisableItem(SID_BEZIER_CONVERT);
     260             :                 }
     261             :                 else
     262             :                 {
     263           0 :                     SdrPathSegmentKind eSegm = pSdrView->GetMarkedSegmentsKind();
     264           0 :                     switch (eSegm)
     265             :                     {
     266           0 :                         case SDRPATHSEGMENT_DONTCARE: rSet.InvalidateItem(SID_BEZIER_CONVERT); break;
     267           0 :                         case SDRPATHSEGMENT_LINE    : rSet.Put(SfxBoolItem(SID_BEZIER_CONVERT,sal_False)); break; // Button pressed = curve
     268           0 :                         case SDRPATHSEGMENT_CURVE   : rSet.Put(SfxBoolItem(SID_BEZIER_CONVERT,sal_True));  break;
     269             :                         default:; //prevent warning
     270             :                     }
     271             :                 }
     272           0 :                 break;
     273             : 
     274             :             case SID_BEZIER_EDGE:
     275             :             case SID_BEZIER_SMOOTH:
     276             :             case SID_BEZIER_SYMMTR:
     277           0 :                 if (!pSdrView->IsSetMarkedPointsSmoothPossible())
     278           0 :                     rSet.DisableItem(nWhich);
     279             :                 else
     280             :                 {
     281           0 :                     SdrPathSmoothKind eSmooth = pSdrView->GetMarkedPointsSmooth();
     282           0 :                     sal_Bool bEnable = sal_False;
     283           0 :                     switch (eSmooth)
     284             :                     {
     285             :                         case SDRPATHSMOOTH_DONTCARE  :
     286           0 :                             break;
     287             :                         case SDRPATHSMOOTH_ANGULAR   :
     288           0 :                             bEnable = nWhich == SID_BEZIER_EDGE;
     289           0 :                             break;
     290             :                         case SDRPATHSMOOTH_ASYMMETRIC:
     291           0 :                             bEnable = nWhich == SID_BEZIER_SMOOTH;
     292           0 :                             break;
     293             :                         case SDRPATHSMOOTH_SYMMETRIC :
     294           0 :                             bEnable = nWhich == SID_BEZIER_SYMMTR;
     295           0 :                             break;
     296             :                     }
     297           0 :                     rSet.Put(SfxBoolItem(nWhich, bEnable));
     298             :                 }
     299           0 :                 break;
     300             : 
     301             :             case SID_BEZIER_CLOSE:
     302           0 :                 if (!pSdrView->IsOpenCloseMarkedObjectsPossible())
     303             :                 {
     304           0 :                     rSet.DisableItem(SID_BEZIER_CLOSE);
     305             :                 }
     306             :                 else
     307             :                 {
     308           0 :                     SdrObjClosedKind eClose = pSdrView->GetMarkedObjectsClosedState();
     309           0 :                     switch (eClose)
     310             :                     {
     311           0 :                         case SDROBJCLOSED_DONTCARE: rSet.InvalidateItem(SID_BEZIER_CLOSE); break;
     312           0 :                         case SDROBJCLOSED_OPEN    : rSet.Put(SfxBoolItem(SID_BEZIER_CLOSE,sal_False)); break;
     313           0 :                         case SDROBJCLOSED_CLOSED  : rSet.Put(SfxBoolItem(SID_BEZIER_CLOSE,sal_True)); break;
     314             :                         default:; //prevent warning
     315             :                     }
     316             :                 }
     317           0 :                 break;
     318             : 
     319             :             case SID_BEZIER_ELIMINATE_POINTS:
     320           0 :                 rSet.Put(SfxBoolItem(SID_BEZIER_ELIMINATE_POINTS, pSdrView->IsEliminatePolyPoints()));
     321           0 :                 break;
     322             : 
     323             :             default:
     324           0 :                 break;
     325             :         }
     326           0 :         nWhich = aIter.NextWhich();
     327           0 :     }
     328          99 : }
     329             : 
     330             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10