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

Generated by: LCOV version 1.10