LCOV - code coverage report
Current view: top level - svx/source/svdraw - svdsnpv.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 50 344 14.5 %
Date: 2012-08-25 Functions: 7 33 21.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 373 2.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <svx/svdsnpv.hxx>
      31                 :            : #include <math.h>
      32                 :            : 
      33                 :            : #include <svx/svdetc.hxx>
      34                 :            : #include <svx/svdobj.hxx>
      35                 :            : #include <svx/svdpagv.hxx>
      36                 :            : #include <svx/svdpage.hxx>
      37                 :            : #include "svx/svditer.hxx"
      38                 :            : #include <svx/sdr/overlay/overlayobjectlist.hxx>
      39                 :            : #include <svx/sdr/overlay/overlaycrosshair.hxx>
      40                 :            : #include <svx/sdr/overlay/overlayhelpline.hxx>
      41                 :            : #include <svx/sdr/overlay/overlaymanager.hxx>
      42                 :            : #include <basegfx/matrix/b2dhommatrix.hxx>
      43                 :            : #include <svx/sdrpaintwindow.hxx>
      44                 :            : 
      45                 :            : ////////////////////////////////////////////////////////////////////////////////////////////////////
      46                 :            : class ImplPageOriginOverlay
      47                 :            : {
      48                 :            :     // The OverlayObjects
      49                 :            :     ::sdr::overlay::OverlayObjectList               maObjects;
      50                 :            : 
      51                 :            :     // The current position in logical coodinates
      52                 :            :     basegfx::B2DPoint                               maPosition;
      53                 :            : 
      54                 :            : public:
      55                 :            :     ImplPageOriginOverlay(const SdrPaintView& rView, const basegfx::B2DPoint& rStartPos);
      56                 :            :     ~ImplPageOriginOverlay();
      57                 :            : 
      58                 :            :     void SetPosition(const basegfx::B2DPoint& rNewPosition);
      59                 :            : };
      60                 :            : 
      61                 :          0 : ImplPageOriginOverlay::ImplPageOriginOverlay(const SdrPaintView& rView, const basegfx::B2DPoint& rStartPos)
      62                 :          0 : :   maPosition(rStartPos)
      63                 :            : {
      64         [ #  # ]:          0 :     for(sal_uInt32 a(0L); a < rView.PaintWindowCount(); a++)
      65                 :            :     {
      66         [ #  # ]:          0 :         SdrPaintWindow* pCandidate = rView.GetPaintWindow(a);
      67         [ #  # ]:          0 :         rtl::Reference< ::sdr::overlay::OverlayManager > xTargetOverlay = pCandidate->GetOverlayManager();
      68                 :            : 
      69         [ #  # ]:          0 :         if (xTargetOverlay.is())
      70                 :            :         {
      71                 :            :             ::sdr::overlay::OverlayCrosshairStriped* aNew = new ::sdr::overlay::OverlayCrosshairStriped(
      72 [ #  # ][ #  # ]:          0 :                 maPosition);
      73         [ #  # ]:          0 :             xTargetOverlay->add(*aNew);
      74         [ #  # ]:          0 :             maObjects.append(*aNew);
      75                 :            :         }
      76         [ #  # ]:          0 :     }
      77                 :          0 : }
      78                 :            : 
      79                 :          0 : ImplPageOriginOverlay::~ImplPageOriginOverlay()
      80                 :            : {
      81                 :            :     // The OverlayObjects are cleared using the destructor of OverlayObjectList.
      82                 :            :     // That destructor calls clear() at the list which removes all objects from the
      83                 :            :     // OverlayManager and deletes them.
      84                 :          0 : }
      85                 :            : 
      86                 :          0 : void ImplPageOriginOverlay::SetPosition(const basegfx::B2DPoint& rNewPosition)
      87                 :            : {
      88         [ #  # ]:          0 :     if(rNewPosition != maPosition)
      89                 :            :     {
      90                 :            :         // apply to OverlayObjects
      91         [ #  # ]:          0 :         for(sal_uInt32 a(0); a < maObjects.count(); a++)
      92                 :            :         {
      93                 :            :             sdr::overlay::OverlayCrosshairStriped* pCandidate =
      94                 :          0 :                 static_cast< sdr::overlay::OverlayCrosshairStriped* >(&maObjects.getOverlayObject(a));
      95                 :            : 
      96         [ #  # ]:          0 :             if(pCandidate)
      97                 :            :             {
      98                 :          0 :                 pCandidate->setBasePosition(rNewPosition);
      99                 :            :             }
     100                 :            :         }
     101                 :            : 
     102                 :            :         // remember new position
     103                 :          0 :         maPosition = rNewPosition;
     104                 :            :     }
     105                 :          0 : }
     106                 :            : 
     107                 :            : ////////////////////////////////////////////////////////////////////////////////////////////////////
     108                 :            : class ImplHelpLineOverlay
     109                 :            : {
     110                 :            :     // The OverlayObjects
     111                 :            :     ::sdr::overlay::OverlayObjectList               maObjects;
     112                 :            : 
     113                 :            :     // The current position in logical coodinates
     114                 :            :     basegfx::B2DPoint                               maPosition;
     115                 :            : 
     116                 :            :     // HelpLine specific stuff
     117                 :            :     SdrPageView*                                    mpPageView;
     118                 :            :     sal_uInt16                                      mnHelpLineNumber;
     119                 :            :     SdrHelpLineKind                                 meHelpLineKind;
     120                 :            : 
     121                 :            : public:
     122                 :            :     ImplHelpLineOverlay(const SdrPaintView& rView, const basegfx::B2DPoint& rStartPos,
     123                 :            :         SdrPageView* pPageView, sal_uInt16 nHelpLineNumber, SdrHelpLineKind eKind);
     124                 :            :     ~ImplHelpLineOverlay();
     125                 :            : 
     126                 :            :     void SetPosition(const basegfx::B2DPoint& rNewPosition);
     127                 :            : 
     128                 :            :     // access to HelpLine specific stuff
     129                 :          0 :     SdrPageView* GetPageView() const { return mpPageView; }
     130                 :          0 :     sal_uInt16 GetHelpLineNumber() const { return mnHelpLineNumber; }
     131                 :          0 :     SdrHelpLineKind GetHelpLineKind() const { return meHelpLineKind; }
     132                 :            : };
     133                 :            : 
     134                 :          0 : ImplHelpLineOverlay::ImplHelpLineOverlay(
     135                 :            :     const SdrPaintView& rView, const basegfx::B2DPoint& rStartPos,
     136                 :            :     SdrPageView* pPageView, sal_uInt16 nHelpLineNumber, SdrHelpLineKind eKind)
     137                 :            : :   maPosition(rStartPos),
     138                 :            :     mpPageView(pPageView),
     139                 :            :     mnHelpLineNumber(nHelpLineNumber),
     140                 :          0 :     meHelpLineKind(eKind)
     141                 :            : {
     142         [ #  # ]:          0 :     for(sal_uInt32 a(0L); a < rView.PaintWindowCount(); a++)
     143                 :            :     {
     144         [ #  # ]:          0 :         SdrPaintWindow* pCandidate = rView.GetPaintWindow(a);
     145         [ #  # ]:          0 :         rtl::Reference< ::sdr::overlay::OverlayManager > xTargetOverlay = pCandidate->GetOverlayManager();
     146                 :            : 
     147         [ #  # ]:          0 :         if (xTargetOverlay.is())
     148                 :            :         {
     149                 :            :             ::sdr::overlay::OverlayHelplineStriped* aNew = new ::sdr::overlay::OverlayHelplineStriped(
     150 [ #  # ][ #  # ]:          0 :                 maPosition, meHelpLineKind);
     151         [ #  # ]:          0 :             xTargetOverlay->add(*aNew);
     152         [ #  # ]:          0 :             maObjects.append(*aNew);
     153                 :            :         }
     154         [ #  # ]:          0 :     }
     155                 :          0 : }
     156                 :            : 
     157                 :          0 : ImplHelpLineOverlay::~ImplHelpLineOverlay()
     158                 :            : {
     159                 :            :     // The OverlayObjects are cleared using the destructor of OverlayObjectList.
     160                 :            :     // That destructor calls clear() at the list which removes all objects from the
     161                 :            :     // OverlayManager and deletes them.
     162                 :          0 : }
     163                 :            : 
     164                 :          0 : void ImplHelpLineOverlay::SetPosition(const basegfx::B2DPoint& rNewPosition)
     165                 :            : {
     166         [ #  # ]:          0 :     if(rNewPosition != maPosition)
     167                 :            :     {
     168                 :            :         // apply to OverlayObjects
     169         [ #  # ]:          0 :         for(sal_uInt32 a(0); a < maObjects.count(); a++)
     170                 :            :         {
     171                 :            :             sdr::overlay::OverlayHelplineStriped* pCandidate =
     172                 :          0 :                 static_cast< sdr::overlay::OverlayHelplineStriped* >(&maObjects.getOverlayObject(a));
     173                 :            : 
     174         [ #  # ]:          0 :             if(pCandidate)
     175                 :            :             {
     176                 :          0 :                 pCandidate->setBasePosition(rNewPosition);
     177                 :            :             }
     178                 :            :         }
     179                 :            : 
     180                 :            :         // remember new position
     181                 :          0 :         maPosition = rNewPosition;
     182                 :            :     }
     183                 :          0 : }
     184                 :            : 
     185                 :            : 
     186                 :       4699 : void SdrSnapView::ClearVars()
     187                 :            : {
     188                 :       4699 :     nMagnSizPix=4;
     189                 :       4699 :     bSnapEnab=sal_True;
     190                 :       4699 :     bGridSnap=sal_True;
     191                 :       4699 :     bSnapTo1Pix=sal_True;
     192                 :       4699 :     bBordSnap=sal_True;
     193                 :       4699 :     bHlplSnap=sal_True;
     194                 :       4699 :     bOFrmSnap=sal_True;
     195                 :       4699 :     bOPntSnap=sal_False;
     196                 :       4699 :     bOConSnap=sal_True;
     197                 :       4699 :     bMoveMFrmSnap=sal_True;
     198                 :       4699 :     bMoveOFrmSnap=sal_True;
     199                 :       4699 :     bMoveOPntSnap=sal_True;
     200                 :       4699 :     bMoveOConSnap=sal_True;
     201                 :       4699 :     bMoveSnapOnlyTopLeft=sal_False;
     202                 :       4699 :     bOrtho=sal_False;
     203                 :       4699 :     bBigOrtho=sal_True;
     204                 :       4699 :     nSnapAngle=1500;
     205                 :       4699 :     bAngleSnapEnab=sal_False;
     206                 :       4699 :     bMoveOnlyDragging=sal_False;
     207                 :       4699 :     bSlantButShear=sal_False;
     208                 :       4699 :     bCrookNoContortion=sal_False;
     209                 :       4699 :     eCrookMode=SDRCROOK_ROTATE;
     210                 :       4699 :     bHlplFixed=sal_False;
     211                 :       4699 :     bEliminatePolyPoints=sal_False;
     212                 :       4699 :     nEliminatePolyPointLimitAngle=0;
     213                 :            : 
     214                 :       4699 :     BrkSetPageOrg();
     215                 :       4699 :     BrkDragHelpLine();
     216                 :       4699 : }
     217                 :            : 
     218                 :       4699 : SdrSnapView::SdrSnapView(SdrModel* pModel1, OutputDevice* pOut):
     219                 :            :     SdrPaintView(pModel1,pOut),
     220                 :            :     mpPageOriginOverlay(0L),
     221                 :       4699 :     mpHelpLineOverlay(0L)
     222                 :            : {
     223         [ +  - ]:       4699 :     ClearVars();
     224                 :       4699 : }
     225                 :            : 
     226                 :       4508 : SdrSnapView::~SdrSnapView()
     227                 :            : {
     228         [ +  - ]:       4508 :     BrkSetPageOrg();
     229         [ +  - ]:       4508 :     BrkDragHelpLine();
     230         [ -  + ]:       4508 : }
     231                 :            : 
     232                 :            : ////////////////////////////////////////////////////////////////////////////////////////////////////
     233                 :            : 
     234                 :       2168 : sal_Bool SdrSnapView::IsAction() const
     235                 :            : {
     236 [ +  - ][ +  - ]:       2168 :     return IsSetPageOrg() || IsDragHelpLine() || SdrPaintView::IsAction();
                 [ -  + ]
     237                 :            : }
     238                 :            : 
     239                 :          0 : void SdrSnapView::MovAction(const Point& rPnt)
     240                 :            : {
     241                 :          0 :     SdrPaintView::MovAction(rPnt);
     242         [ #  # ]:          0 :     if (IsSetPageOrg()) {
     243                 :          0 :         MovSetPageOrg(rPnt);
     244                 :            :     }
     245         [ #  # ]:          0 :     if (IsDragHelpLine()) {
     246                 :          0 :         MovDragHelpLine(rPnt);
     247                 :            :     }
     248                 :          0 : }
     249                 :            : 
     250                 :          0 : void SdrSnapView::EndAction()
     251                 :            : {
     252         [ #  # ]:          0 :     if (IsSetPageOrg()) {
     253                 :          0 :         EndSetPageOrg();
     254                 :            :     }
     255         [ #  # ]:          0 :     if (IsDragHelpLine()) {
     256                 :          0 :         EndDragHelpLine();
     257                 :            :     }
     258                 :          0 :     SdrPaintView::EndAction();
     259                 :          0 : }
     260                 :            : 
     261                 :          0 : void SdrSnapView::BckAction()
     262                 :            : {
     263                 :          0 :     BrkSetPageOrg();
     264                 :          0 :     BrkDragHelpLine();
     265                 :          0 :     SdrPaintView::BckAction();
     266                 :          0 : }
     267                 :            : 
     268                 :       4877 : void SdrSnapView::BrkAction()
     269                 :            : {
     270                 :       4877 :     BrkSetPageOrg();
     271                 :       4877 :     BrkDragHelpLine();
     272                 :       4877 :     SdrPaintView::BrkAction();
     273                 :       4877 : }
     274                 :            : 
     275                 :          0 : void SdrSnapView::TakeActionRect(Rectangle& rRect) const
     276                 :            : {
     277 [ #  # ][ #  # ]:          0 :     if (IsSetPageOrg() || IsDragHelpLine()) {
                 [ #  # ]
     278                 :          0 :         rRect=Rectangle(aDragStat.GetNow(),aDragStat.GetNow());
     279                 :            :     } else {
     280                 :          0 :         SdrPaintView::TakeActionRect(rRect);
     281                 :            :     }
     282                 :          0 : }
     283                 :            : 
     284                 :            : ////////////////////////////////////////////////////////////////////////////////////////////////////
     285                 :            : 
     286                 :          0 : Point SdrSnapView::GetSnapPos(const Point& rPnt, const SdrPageView* pPV) const
     287                 :            : {
     288                 :          0 :     Point aPt(rPnt);
     289                 :          0 :     SnapPos(aPt,pPV);
     290                 :          0 :     return aPt;
     291                 :            : }
     292                 :            : 
     293                 :            : #define NOT_SNAPPED 0x7FFFFFFF
     294                 :          0 : sal_uInt16 SdrSnapView::SnapPos(Point& rPnt, const SdrPageView* pPV) const
     295                 :            : {
     296         [ #  # ]:          0 :     if (!bSnapEnab) return SDRSNAP_NOTSNAPPED;
     297                 :          0 :     long x=rPnt.X();
     298                 :          0 :     long y=rPnt.Y();
     299         [ #  # ]:          0 :     if (pPV==NULL) {
     300                 :          0 :         pPV=GetSdrPageView();
     301         [ #  # ]:          0 :         if (pPV==NULL) return SDRSNAP_NOTSNAPPED;
     302                 :            :     }
     303                 :            : 
     304                 :          0 :     long dx=NOT_SNAPPED;
     305                 :          0 :     long dy=NOT_SNAPPED;
     306                 :            :     long dx1,dy1;
     307                 :          0 :     long mx=aMagnSiz.Width();
     308                 :          0 :     long my=aMagnSiz.Height();
     309 [ #  # ][ #  # ]:          0 :     if (bHlplVisible && bHlplSnap && !IsDragHelpLine())
         [ #  # ][ #  # ]
     310                 :            :     {
     311                 :          0 :         const SdrHelpLineList& rHLL=pPV->GetHelpLines();
     312                 :          0 :         sal_uInt16 nAnz=rHLL.GetCount();
     313         [ #  # ]:          0 :         for (sal_uInt16 i=nAnz; i>0;) {
     314                 :          0 :             i--;
     315                 :          0 :             const SdrHelpLine& rHL=rHLL[i];
     316                 :          0 :             const Point& rPos=rHL.GetPos();
     317   [ #  #  #  # ]:          0 :             switch (rHL.GetKind()) {
     318                 :            :                 case SDRHELPLINE_VERTICAL: {
     319                 :          0 :                     long a=x-rPos.X();
     320 [ #  # ][ #  # ]:          0 :                     if (Abs(a)<=mx) { dx1=-a; if (Abs(dx1)<Abs(dx)) dx=dx1; }
     321                 :          0 :                 } break;
     322                 :            :                 case SDRHELPLINE_HORIZONTAL: {
     323                 :          0 :                     long b=y-rPos.Y();
     324 [ #  # ][ #  # ]:          0 :                     if (Abs(b)<=my) { dy1=-b; if (Abs(dy1)<Abs(dy)) dy=dy1; }
     325                 :          0 :                 } break;
     326                 :            :                 case SDRHELPLINE_POINT: {
     327                 :          0 :                     long a=x-rPos.X();
     328                 :          0 :                     long b=y-rPos.Y();
     329 [ #  # ][ #  # ]:          0 :                     if (Abs(a)<=mx && Abs(b)<=my) {
                 [ #  # ]
     330                 :          0 :                         dx1=-a; dy1=-b;
     331 [ #  # ][ #  # ]:          0 :                         if (Abs(dx1)<Abs(dx) && Abs(dy1)<Abs(dy)) { dx=dx1; dy=dy1; }
                 [ #  # ]
     332                 :            :                     }
     333                 :          0 :                 } break;
     334                 :            :             } // switch
     335                 :            :         }
     336                 :            :     }
     337 [ #  # ][ #  # ]:          0 :     if (bBordVisible && bBordSnap) {
     338                 :          0 :         SdrPage* pPage=pPV->GetPage();
     339                 :          0 :         long xs=pPage->GetWdt();
     340                 :          0 :         long ys=pPage->GetHgt();
     341                 :          0 :         long lft=pPage->GetLftBorder();
     342                 :          0 :         long rgt=pPage->GetRgtBorder();
     343                 :          0 :         long upp=pPage->GetUppBorder();
     344                 :          0 :         long lwr=pPage->GetLwrBorder();
     345                 :            :         long a;
     346 [ #  # ][ #  # ]:          0 :         a=x- lft    ; if (Abs(a)<=mx) { dx1=-a; if (Abs(dx1)<Abs(dx)) dx=dx1; } // left margin
     347 [ #  # ][ #  # ]:          0 :         a=x-(xs-rgt); if (Abs(a)<=mx) { dx1=-a; if (Abs(dx1)<Abs(dx)) dx=dx1; } // right margin
     348 [ #  # ][ #  # ]:          0 :         a=x         ; if (Abs(a)<=mx) { dx1=-a; if (Abs(dx1)<Abs(dx)) dx=dx1; } // left edge of paper
     349 [ #  # ][ #  # ]:          0 :         a=x- xs     ; if (Abs(a)<=mx) { dx1=-a; if (Abs(dx1)<Abs(dx)) dx=dx1; } // right edge of paper
     350 [ #  # ][ #  # ]:          0 :         a=y- upp    ; if (Abs(a)<=my) { dy1=-a; if (Abs(dy1)<Abs(dy)) dy=dy1; } // left margin
     351 [ #  # ][ #  # ]:          0 :         a=y-(ys-lwr); if (Abs(a)<=my) { dy1=-a; if (Abs(dy1)<Abs(dy)) dy=dy1; } // right margin
     352 [ #  # ][ #  # ]:          0 :         a=y         ; if (Abs(a)<=my) { dy1=-a; if (Abs(dy1)<Abs(dy)) dy=dy1; } // left edge of paper
     353 [ #  # ][ #  # ]:          0 :         a=y- ys     ; if (Abs(a)<=my) { dy1=-a; if (Abs(dy1)<Abs(dy)) dy=dy1; } // right edge of paper
     354                 :            :     }
     355 [ #  # ][ #  # ]:          0 :     if (bOFrmSnap || bOPntSnap) {
     356                 :          0 :         sal_uIntPtr nMaxPointSnapCount=200;
     357                 :          0 :         sal_uIntPtr nMaxFrameSnapCount=200;
     358                 :            : 
     359                 :            :         // go back to IM_DEEPNOGROUPS runthrough for snap to object comparisons
     360         [ #  # ]:          0 :         SdrObjListIter aIter(*pPV->GetPage(),IM_DEEPNOGROUPS,sal_True);
     361                 :            : 
     362 [ #  # ][ #  # ]:          0 :         while (aIter.IsMore() && (nMaxPointSnapCount>0 || nMaxFrameSnapCount>0)) {
         [ #  # ][ #  # ]
     363         [ #  # ]:          0 :             SdrObject* pO=aIter.Next();
     364         [ #  # ]:          0 :             Rectangle aRect(pO->GetCurrentBoundRect());
     365                 :          0 :             aRect.Left  ()-=mx;
     366                 :          0 :             aRect.Right ()+=mx;
     367                 :          0 :             aRect.Top   ()-=my;
     368                 :          0 :             aRect.Bottom()+=my;
     369 [ #  # ][ #  # ]:          0 :             if (aRect.IsInside(rPnt)) {
     370 [ #  # ][ #  # ]:          0 :                 if (bOPntSnap && nMaxPointSnapCount>0)
     371                 :            :                 {
     372         [ #  # ]:          0 :                     sal_uInt32 nAnz(pO->GetSnapPointCount());
     373 [ #  # ][ #  # ]:          0 :                     for (sal_uInt32 i(0L); i < nAnz && nMaxPointSnapCount > 0L; i++)
                 [ #  # ]
     374                 :            :                     {
     375         [ #  # ]:          0 :                         Point aP(pO->GetSnapPoint(i));
     376                 :          0 :                         dx1=x-aP.X();
     377                 :          0 :                         dy1=y-aP.Y();
     378 [ #  # ][ #  # ]:          0 :                         if (Abs(dx1)<=mx && Abs(dy1)<=my && Abs(dx1)<Abs(dx) && Abs(dy1)<Abs(dy)) {
         [ #  # ][ #  # ]
                 [ #  # ]
     379                 :          0 :                             dx=-dx1;
     380                 :          0 :                             dy=-dy1;
     381                 :            :                         }
     382                 :          0 :                         nMaxPointSnapCount--;
     383                 :            :                     }
     384                 :            :                 }
     385 [ #  # ][ #  # ]:          0 :                 if (bOFrmSnap && nMaxFrameSnapCount>0) {
     386         [ #  # ]:          0 :                     Rectangle aLog(pO->GetSnapRect());
     387                 :          0 :                     Rectangle aR1(aLog);
     388                 :          0 :                     aR1.Left  ()-=mx;
     389                 :          0 :                     aR1.Right ()+=mx;
     390                 :          0 :                     aR1.Top   ()-=my;
     391                 :          0 :                     aR1.Bottom()+=my;
     392 [ #  # ][ #  # ]:          0 :                     if (aR1.IsInside(rPnt)) {
     393 [ #  # ][ #  # ]:          0 :                         if (Abs(x-aLog.Left  ())<=mx) { dx1=-(x-aLog.Left  ()); if (Abs(dx1)<Abs(dx)) dx=dx1; }
     394 [ #  # ][ #  # ]:          0 :                         if (Abs(x-aLog.Right ())<=mx) { dx1=-(x-aLog.Right ()); if (Abs(dx1)<Abs(dx)) dx=dx1; }
     395 [ #  # ][ #  # ]:          0 :                         if (Abs(y-aLog.Top   ())<=my) { dy1=-(y-aLog.Top   ()); if (Abs(dy1)<Abs(dy)) dy=dy1; }
     396 [ #  # ][ #  # ]:          0 :                         if (Abs(y-aLog.Bottom())<=my) { dy1=-(y-aLog.Bottom()); if (Abs(dy1)<Abs(dy)) dy=dy1; }
     397                 :            :                     }
     398                 :          0 :                     nMaxFrameSnapCount--;
     399                 :            :                 }
     400                 :            :             }
     401                 :          0 :         }
     402                 :            :     }
     403         [ #  # ]:          0 :     if(bGridSnap)
     404                 :            :     {
     405                 :          0 :         double fSnapWidth = aSnapWdtX;
     406 [ #  # ][ #  # ]:          0 :         if(dx == NOT_SNAPPED && fSnapWidth != 0.0)
     407                 :            :         {
     408                 :          0 :             double fx = (double)x;
     409                 :            : 
     410                 :            :             // round instead of trunc
     411         [ #  # ]:          0 :             if(fx - (double)pPV->GetPageOrigin().X() >= 0.0)
     412                 :          0 :                 fx += fSnapWidth / 2.0;
     413                 :            :             else
     414                 :          0 :                 fx -= fSnapWidth / 2.0;
     415                 :            : 
     416                 :          0 :             x = (long)((fx - (double)pPV->GetPageOrigin().X()) / fSnapWidth);
     417                 :          0 :             x = (long)((double)x * fSnapWidth + (double)pPV->GetPageOrigin().X());
     418                 :          0 :             dx = 0;
     419                 :            :         }
     420                 :          0 :         fSnapWidth = aSnapWdtY;
     421 [ #  # ][ #  # ]:          0 :         if(dy == NOT_SNAPPED && fSnapWidth)
     422                 :            :         {
     423                 :          0 :             double fy = (double)y;
     424                 :            : 
     425                 :            :             // round instead of trunc
     426         [ #  # ]:          0 :             if(fy - (double)pPV->GetPageOrigin().Y() >= 0.0)
     427                 :          0 :                 fy += fSnapWidth / 2.0;
     428                 :            :             else
     429                 :          0 :                 fy -= fSnapWidth / 2.0;
     430                 :            : 
     431                 :          0 :             y = (long)((fy - (double)pPV->GetPageOrigin().Y()) / fSnapWidth);
     432                 :          0 :             y = (long)((double)y * fSnapWidth + (double)pPV->GetPageOrigin().Y());
     433                 :          0 :             dy = 0;
     434                 :            :         }
     435                 :            :     }
     436                 :          0 :     sal_Bool bRet=SDRSNAP_NOTSNAPPED;
     437         [ #  # ]:          0 :     if (dx==NOT_SNAPPED) dx=0; else bRet|=SDRSNAP_XSNAPPED;
     438         [ #  # ]:          0 :     if (dy==NOT_SNAPPED) dy=0; else bRet|=SDRSNAP_YSNAPPED;
     439                 :          0 :     rPnt.X()=x+dx;
     440                 :          0 :     rPnt.Y()=y+dy;
     441                 :          0 :     return bRet;
     442                 :            : }
     443                 :            : 
     444                 :          0 : void SdrSnapView::CheckSnap(const Point& rPt, const SdrPageView* pPV, long& nBestXSnap, long& nBestYSnap, bool& bXSnapped, bool& bYSnapped) const
     445                 :            : {
     446                 :          0 :     Point aPt(rPt);
     447         [ #  # ]:          0 :     sal_uInt16 nRet=SnapPos(aPt,pPV);
     448                 :          0 :     aPt-=rPt;
     449         [ #  # ]:          0 :     if ((nRet & SDRSNAP_XSNAPPED) !=0) {
     450         [ #  # ]:          0 :         if (bXSnapped) {
     451         [ #  # ]:          0 :             if (Abs(aPt.X())<Abs(nBestXSnap)) {
     452                 :          0 :                 nBestXSnap=aPt.X();
     453                 :            :             }
     454                 :            :         } else {
     455                 :          0 :             nBestXSnap=aPt.X();
     456                 :          0 :             bXSnapped=sal_True;
     457                 :            :         }
     458                 :            :     }
     459         [ #  # ]:          0 :     if ((nRet & SDRSNAP_YSNAPPED) !=0) {
     460         [ #  # ]:          0 :         if (bYSnapped) {
     461         [ #  # ]:          0 :             if (Abs(aPt.Y())<Abs(nBestYSnap)) {
     462                 :          0 :                 nBestYSnap=aPt.Y();
     463                 :            :             }
     464                 :            :         } else {
     465                 :          0 :             nBestYSnap=aPt.Y();
     466                 :          0 :             bYSnapped=sal_True;
     467                 :            :         }
     468                 :            :     }
     469                 :          0 : }
     470                 :            : 
     471                 :            : ////////////////////////////////////////////////////////////////////////////////////////////////////
     472                 :            : 
     473                 :          0 : sal_Bool SdrSnapView::BegSetPageOrg(const Point& rPnt)
     474                 :            : {
     475         [ #  # ]:          0 :     BrkAction();
     476                 :            : 
     477                 :            :     DBG_ASSERT(0L == mpPageOriginOverlay, "SdrSnapView::BegSetPageOrg: There exists a ImplPageOriginOverlay (!)");
     478                 :          0 :     basegfx::B2DPoint aStartPos(rPnt.X(), rPnt.Y());
     479 [ #  # ][ #  # ]:          0 :     mpPageOriginOverlay = new ImplPageOriginOverlay(*this, aStartPos);
     480 [ #  # ][ #  # ]:          0 :     aDragStat.Reset(GetSnapPos(rPnt,NULL));
     481                 :            : 
     482                 :          0 :     return sal_True;
     483                 :            : }
     484                 :            : 
     485                 :          0 : void SdrSnapView::MovSetPageOrg(const Point& rPnt)
     486                 :            : {
     487         [ #  # ]:          0 :     if(IsSetPageOrg())
     488                 :            :     {
     489 [ #  # ][ #  # ]:          0 :         aDragStat.NextMove(GetSnapPos(rPnt,NULL));
     490                 :            :         DBG_ASSERT(mpPageOriginOverlay, "SdrSnapView::MovSetPageOrg: no ImplPageOriginOverlay (!)");
     491 [ #  # ][ #  # ]:          0 :         basegfx::B2DPoint aNewPos(aDragStat.GetNow().X(), aDragStat.GetNow().Y());
     492         [ #  # ]:          0 :         mpPageOriginOverlay->SetPosition(aNewPos);
     493                 :            :     }
     494                 :          0 : }
     495                 :            : 
     496                 :          0 : sal_Bool SdrSnapView::EndSetPageOrg()
     497                 :            : {
     498                 :          0 :     sal_Bool bRet(sal_False);
     499                 :            : 
     500         [ #  # ]:          0 :     if(IsSetPageOrg())
     501                 :            :     {
     502                 :          0 :         SdrPageView* pPV = GetSdrPageView();
     503                 :            : 
     504         [ #  # ]:          0 :         if(pPV)
     505                 :            :         {
     506         [ #  # ]:          0 :             Point aPnt(aDragStat.GetNow());
     507         [ #  # ]:          0 :             pPV->SetPageOrigin(aPnt);
     508                 :          0 :             bRet = sal_True;
     509                 :            :         }
     510                 :            : 
     511                 :            :         // cleanup
     512                 :          0 :         BrkSetPageOrg();
     513                 :            :     }
     514                 :            : 
     515                 :          0 :     return bRet;
     516                 :            : }
     517                 :            : 
     518                 :      14084 : void SdrSnapView::BrkSetPageOrg()
     519                 :            : {
     520         [ -  + ]:      14084 :     if(IsSetPageOrg())
     521                 :            :     {
     522                 :            :         DBG_ASSERT(mpPageOriginOverlay, "SdrSnapView::MovSetPageOrg: no ImplPageOriginOverlay (!)");
     523         [ #  # ]:          0 :         delete mpPageOriginOverlay;
     524                 :          0 :         mpPageOriginOverlay = 0L;
     525                 :            :     }
     526                 :      14084 : }
     527                 :            : 
     528                 :            : ////////////////////////////////////////////////////////////////////////////////////////////////////
     529                 :            : 
     530                 :          0 : sal_Bool SdrSnapView::PickHelpLine(const Point& rPnt, short nTol, const OutputDevice& rOut, sal_uInt16& rnHelpLineNum, SdrPageView*& rpPV) const
     531                 :            : {
     532                 :          0 :     rpPV=NULL;
     533                 :          0 :     nTol=ImpGetHitTolLogic(nTol,&rOut);
     534                 :          0 :     SdrPageView* pPV = GetSdrPageView();
     535                 :            : 
     536         [ #  # ]:          0 :     if(pPV)
     537                 :            :     {
     538                 :          0 :         Point aPnt(rPnt);
     539         [ #  # ]:          0 :         sal_uInt16 nIndex=pPV->GetHelpLines().HitTest(aPnt,sal_uInt16(nTol),rOut);
     540         [ #  # ]:          0 :         if (nIndex!=SDRHELPLINE_NOTFOUND) {
     541                 :          0 :             rpPV=pPV;
     542                 :          0 :             rnHelpLineNum=nIndex;
     543                 :          0 :             return sal_True;
     544                 :            :         }
     545                 :            :     }
     546                 :          0 :     return sal_False;
     547                 :            : }
     548                 :            : 
     549                 :            : // start HelpLine drag for new HelpLine
     550                 :          0 : sal_Bool SdrSnapView::BegDragHelpLine(sal_uInt16 nHelpLineNum, SdrPageView* pPV)
     551                 :            : {
     552                 :          0 :     sal_Bool bRet(sal_False);
     553                 :            : 
     554         [ #  # ]:          0 :     if(!bHlplFixed)
     555                 :            :     {
     556                 :          0 :         BrkAction();
     557                 :            : 
     558 [ #  # ][ #  # ]:          0 :         if(pPV && nHelpLineNum < pPV->GetHelpLines().GetCount())
                 [ #  # ]
     559                 :            :         {
     560                 :          0 :             const SdrHelpLineList& rHelpLines = pPV->GetHelpLines();
     561         [ #  # ]:          0 :             const SdrHelpLine& rHelpLine = rHelpLines[nHelpLineNum];
     562                 :          0 :             Point aHelpLinePos = rHelpLine.GetPos();
     563                 :          0 :             basegfx::B2DPoint aStartPos(aHelpLinePos.X(), aHelpLinePos.Y());
     564                 :            : 
     565                 :            :             DBG_ASSERT(0L == mpHelpLineOverlay, "SdrSnapView::BegDragHelpLine: There exists a ImplHelpLineOverlay (!)");
     566 [ #  # ][ #  # ]:          0 :             mpHelpLineOverlay = new ImplHelpLineOverlay(*this, aStartPos, pPV, nHelpLineNum, rHelpLine.GetKind());
     567                 :            : 
     568 [ #  # ][ #  # ]:          0 :             aDragStat.Reset(GetSnapPos(aHelpLinePos, pPV));
     569         [ #  # ]:          0 :             aDragStat.SetMinMove(ImpGetMinMovLogic(-3, 0L));
     570                 :            : 
     571                 :          0 :             bRet = sal_True;
     572                 :            :         }
     573                 :            :     }
     574                 :            : 
     575                 :          0 :     return bRet;
     576                 :            : }
     577                 :            : 
     578                 :            : // start HelpLine drag with existing HelpLine
     579                 :          0 : sal_Bool SdrSnapView::BegDragHelpLine(const Point& rPnt, SdrHelpLineKind eNewKind)
     580                 :            : {
     581                 :          0 :     sal_Bool bRet(sal_False);
     582                 :            : 
     583                 :          0 :     BrkAction();
     584                 :            : 
     585         [ #  # ]:          0 :     if(GetSdrPageView())
     586                 :            :     {
     587                 :            :         DBG_ASSERT(0L == mpHelpLineOverlay, "SdrSnapView::BegDragHelpLine: There exists a ImplHelpLineOverlay (!)");
     588                 :          0 :         basegfx::B2DPoint aStartPos(rPnt.X(), rPnt.Y());
     589 [ #  # ][ #  # ]:          0 :         mpHelpLineOverlay = new ImplHelpLineOverlay(*this, aStartPos, 0L, 0, eNewKind);
     590 [ #  # ][ #  # ]:          0 :         aDragStat.Reset(GetSnapPos(rPnt, 0L));
     591                 :          0 :         bRet = sal_True;
     592                 :            :     }
     593                 :            : 
     594                 :          0 :     return bRet;
     595                 :            : }
     596                 :            : 
     597                 :          0 : Pointer SdrSnapView::GetDraggedHelpLinePointer() const
     598                 :            : {
     599         [ #  # ]:          0 :     if(IsDragHelpLine())
     600                 :            :     {
     601      [ #  #  # ]:          0 :         switch(mpHelpLineOverlay->GetHelpLineKind())
     602                 :            :         {
     603                 :          0 :             case SDRHELPLINE_VERTICAL  : return Pointer(POINTER_ESIZE);
     604                 :          0 :             case SDRHELPLINE_HORIZONTAL: return Pointer(POINTER_SSIZE);
     605                 :          0 :             default                    : return Pointer(POINTER_MOVE);
     606                 :            :         }
     607                 :            :     }
     608                 :            : 
     609                 :          0 :     return Pointer(POINTER_MOVE);
     610                 :            : }
     611                 :            : 
     612                 :          0 : void SdrSnapView::MovDragHelpLine(const Point& rPnt)
     613                 :            : {
     614 [ #  # ][ #  # ]:          0 :     if(IsDragHelpLine() && aDragStat.CheckMinMoved(rPnt))
                 [ #  # ]
     615                 :            :     {
     616         [ #  # ]:          0 :         Point aPnt(GetSnapPos(rPnt, 0L));
     617                 :            : 
     618 [ #  # ][ #  # ]:          0 :         if(aPnt != aDragStat.GetNow())
     619                 :            :         {
     620         [ #  # ]:          0 :             aDragStat.NextMove(aPnt);
     621                 :            :             DBG_ASSERT(mpHelpLineOverlay, "SdrSnapView::MovDragHelpLine: no ImplHelpLineOverlay (!)");
     622 [ #  # ][ #  # ]:          0 :             basegfx::B2DPoint aNewPos(aDragStat.GetNow().X(), aDragStat.GetNow().Y());
     623         [ #  # ]:          0 :             mpHelpLineOverlay->SetPosition(aNewPos);
     624                 :            :         }
     625                 :            :     }
     626                 :          0 : }
     627                 :            : 
     628                 :          0 : sal_Bool SdrSnapView::EndDragHelpLine()
     629                 :            : {
     630                 :          0 :     sal_Bool bRet(sal_False);
     631                 :            : 
     632         [ #  # ]:          0 :     if(IsDragHelpLine())
     633                 :            :     {
     634         [ #  # ]:          0 :         if(aDragStat.IsMinMoved())
     635                 :            :         {
     636                 :          0 :             SdrPageView* pPageView = mpHelpLineOverlay->GetPageView();
     637                 :            : 
     638         [ #  # ]:          0 :             if(pPageView)
     639                 :            :             {
     640                 :            :                 // moved existing one
     641         [ #  # ]:          0 :                 Point aPnt(aDragStat.GetNow());
     642                 :          0 :                 const SdrHelpLineList& rHelpLines = pPageView->GetHelpLines();
     643         [ #  # ]:          0 :                 SdrHelpLine aChangedHelpLine = rHelpLines[mpHelpLineOverlay->GetHelpLineNumber()];
     644                 :          0 :                 aChangedHelpLine.SetPos(aPnt);
     645         [ #  # ]:          0 :                 pPageView->SetHelpLine(mpHelpLineOverlay->GetHelpLineNumber(), aChangedHelpLine);
     646                 :            : 
     647                 :          0 :                 bRet = sal_True;
     648                 :            :             }
     649                 :            :             else
     650                 :            :             {
     651                 :            :                 // create new one
     652                 :          0 :                 pPageView = GetSdrPageView();
     653                 :            : 
     654         [ #  # ]:          0 :                 if(pPageView)
     655                 :            :                 {
     656         [ #  # ]:          0 :                     Point aPnt(aDragStat.GetNow());
     657                 :          0 :                     SdrHelpLine aNewHelpLine(mpHelpLineOverlay->GetHelpLineKind(), aPnt);
     658         [ #  # ]:          0 :                     pPageView->InsertHelpLine(aNewHelpLine);
     659                 :            : 
     660                 :          0 :                     bRet = sal_True;
     661                 :            :                 }
     662                 :            :             }
     663                 :            :         }
     664                 :            : 
     665                 :            :         // cleanup
     666                 :          0 :         BrkDragHelpLine();
     667                 :            :     }
     668                 :            : 
     669                 :          0 :     return bRet;
     670                 :            : }
     671                 :            : 
     672                 :      14084 : void SdrSnapView::BrkDragHelpLine()
     673                 :            : {
     674         [ -  + ]:      14084 :     if(IsDragHelpLine())
     675                 :            :     {
     676                 :            :         DBG_ASSERT(mpHelpLineOverlay, "SdrSnapView::EndDragHelpLine: no ImplHelpLineOverlay (!)");
     677         [ #  # ]:          0 :         delete mpHelpLineOverlay;
     678                 :          0 :         mpHelpLineOverlay = 0L;
     679                 :            :     }
     680                 :      14084 : }
     681                 :            : 
     682                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10