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

Generated by: LCOV version 1.11