LCOV - code coverage report
Current view: top level - include/svx - svdsnpv.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 42 46 91.3 %
Date: 2015-06-13 12:38:46 Functions: 42 46 91.3 %
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             : #ifndef INCLUDED_SVX_SVDSNPV_HXX
      21             : #define INCLUDED_SVX_SVDSNPV_HXX
      22             : 
      23             : #include <svx/svdpntv.hxx>
      24             : #include <svx/svdhlpln.hxx>
      25             : #include <svx/svxdllapi.h>
      26             : #include <o3tl/typed_flags_set.hxx>
      27             : 
      28             : 
      29             : /** return value for SnapPos() method */
      30             : enum class SdrSnap
      31             : {
      32             :     NOTSNAPPED = 0x00,
      33             :     XSNAPPED   = 0x01,
      34             :     YSNAPPED   = 0x02,
      35             :     XYSNAPPED  = XSNAPPED | YSNAPPED,
      36             : };
      37             : namespace o3tl
      38             : {
      39             :     template<> struct typed_flags<SdrSnap> : is_typed_flags<SdrSnap, 3> {};
      40             : }
      41             : 
      42             : // SDRCROOK_STRETCH is not implemented yet!
      43             : enum SdrCrookMode {
      44             :     SDRCROOK_ROTATE,
      45             :     SDRCROOK_SLANT,
      46             :     SDRCROOK_STRETCH
      47             : };
      48             : 
      49             : 
      50             : // #114409#-1 Migrate PageOrigin
      51             : class ImplPageOriginOverlay;
      52             : 
      53             : class SVX_DLLPUBLIC SdrSnapView: public SdrPaintView
      54             : {
      55             : protected:
      56             :     // #114409#-1 Migrate PageOrigin
      57             :     class ImplPageOriginOverlay*            mpPageOriginOverlay;
      58             : 
      59             :     // #114409#-2 Migrate HelpLine
      60             :     class ImplHelpLineOverlay*              mpHelpLineOverlay;
      61             : 
      62             :     Size                        aMagnSiz;
      63             :     Fraction                    aSnapWdtX;
      64             :     Fraction                    aSnapWdtY;
      65             : 
      66             :     sal_uInt16                      nMagnSizPix;
      67             :     long                        nSnapAngle;
      68             :     long                        nEliminatePolyPointLimitAngle;
      69             : 
      70             :     SdrCrookMode                eCrookMode;
      71             : 
      72             :     bool                        bSnapEnab : 1;
      73             :     bool                        bGridSnap : 1;
      74             :     bool                        bSnapTo1Pix : 1;             // If GridSnap off, snap to one Pixel to avoid values like 10.01
      75             :     bool                        bBordSnap : 1;
      76             :     bool                        bHlplSnap : 1;
      77             :     bool                        bOFrmSnap : 1;
      78             :     bool                        bOPntSnap : 1;
      79             :     bool                        bOConSnap : 1;
      80             :     bool                        bMoveMFrmSnap : 1;
      81             :     bool                        bMoveOFrmSnap : 1;
      82             :     bool                        bMoveOPntSnap : 1;
      83             :     bool                        bMoveOConSnap : 1;
      84             :     bool                        bMoveSnapOnlyTopLeft : 1;    //  Special for dialogeditor
      85             :     bool                        bOrtho : 1;
      86             :     bool                        bBigOrtho : 1;
      87             :     bool                        bAngleSnapEnab : 1;
      88             :     bool                        bMoveOnlyDragging : 1;       // only move objects while Resize/Rotate/...
      89             :     bool                        bSlantButShear : 1;          // use slant instead of shear
      90             :     bool                        bCrookNoContortion : 1;      // no contorsion while Crook
      91             :     bool                        bHlplFixed : 1;              // sal_True= fixed auxiliary lines, so it isn't movable
      92             :     bool                        bEliminatePolyPoints : 1;
      93             : 
      94             : protected:
      95             :     // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
      96             :     SdrSnapView(SdrModel* pModel1, OutputDevice* pOut = 0L);
      97             :     virtual ~SdrSnapView();
      98             : 
      99             : public:
     100             :     virtual bool IsAction() const SAL_OVERRIDE;
     101             :     virtual void MovAction(const Point& rPnt) SAL_OVERRIDE;
     102             :     virtual void EndAction() SAL_OVERRIDE;
     103             :     virtual void BckAction() SAL_OVERRIDE;
     104             :     virtual void BrkAction() SAL_OVERRIDE; // break actions for derived classes e.g. interrupt dragging.
     105             :     virtual void TakeActionRect(Rectangle& rRect) const SAL_OVERRIDE;
     106             : 
     107        6306 :     void SetSnapGridWidth(const Fraction& rX, const Fraction& rY) { aSnapWdtX=rX; aSnapWdtY=rY; }
     108        2383 :     const Fraction& GetSnapGridWidthX() const { return aSnapWdtX; }
     109        2115 :     const Fraction& GetSnapGridWidthY() const { return aSnapWdtY; }
     110             : 
     111       15006 :     void SetSnapMagnetic(const Size& rSiz) { if (rSiz!=aMagnSiz) { aMagnSiz=rSiz; } }
     112             :     const Size& GetSnapMagnetic() const { return aMagnSiz; }
     113         367 :     void SetSnapMagneticPixel(sal_uInt16 nPix) { nMagnSizPix=nPix; }
     114        1056 :     sal_uInt16 GetSnapMagneticPixel() const { return nMagnSizPix; }
     115             : 
     116             :     // RecalcLogicSnapMagnetic has to be called for every change of OutputDevices and every change of the MapMode!
     117       15006 :     void RecalcLogicSnapMagnetic(const OutputDevice& rOut) { SetSnapMagnetic(rOut.PixelToLogic(Size(nMagnSizPix,nMagnSizPix))); }
     118       14149 :     void SetActualWin(const OutputDevice* pWin) { SdrPaintView::SetActualWin(pWin); if (pWin!=NULL) RecalcLogicSnapMagnetic(*pWin); }
     119             : 
     120             :     // Coordinates referred to the view!
     121             :     // Returnvalues are SdrSnap::NOTSNAPPED,SdrSnap::XSNAPPED,
     122             :     // SdrSnap::YSNAPPED or SdrSnap::XYSNAPPED
     123             :     SdrSnap SnapPos(Point& rPnt, const SdrPageView* pPV) const;
     124             :     Point GetSnapPos(const Point& rPnt, const SdrPageView* pPV) const;
     125             :     void CheckSnap(const Point& rPt, const SdrPageView* pPV, long& nBestXSnap, long& nBestYSnap, bool& bXSnapped, bool& bYSnapped) const;
     126             : 
     127             :     // All attitudes to snap are persistent.
     128           2 :     bool IsSnapEnabled() const { return bSnapEnab; }
     129        3157 :     bool IsGridSnap() const { return bGridSnap; } // Snap to grid
     130        1991 :     bool IsBordSnap() const { return bBordSnap; } // Snap to border
     131        2077 :     bool IsHlplSnap() const { return bHlplSnap; } // Snap to auxiliary line
     132        2077 :     bool IsOFrmSnap() const { return bOFrmSnap; } // Snap to LogFram from surrounding drawing objects
     133        1991 :     bool IsOPntSnap() const { return bOPntSnap; } // Snap to distinct points from surrounding drawing objects
     134        1839 :     bool IsOConSnap() const { return bOConSnap; } // Snap to connectors of the drawing objects
     135         500 :     void SetSnapEnabled(bool bOn) { bSnapEnab=bOn; }
     136        4776 :     void SetGridSnap(bool bOn) { bGridSnap=bOn; }
     137        1166 :     void SetBordSnap(bool bOn) { bBordSnap=bOn; }
     138        1252 :     void SetHlplSnap(bool bOn) { bHlplSnap=bOn; }
     139        1252 :     void SetOFrmSnap(bool bOn) { bOFrmSnap=bOn; }
     140        1166 :     void SetOPntSnap(bool bOn) { bOPntSnap=bOn; }
     141        1143 :     void SetOConSnap(bool bOn) { bOConSnap=bOn; }
     142             : 
     143             :     // Usually every 4 corners of Object-SnapRects are snapped for Move-Dragging.
     144             :     // The following attitudes e.g. if you only want to snap the left corner on the top (e.g. DialogEditor)
     145             :     // persistent, Default=FALSE.
     146           0 :     void SetMoveSnapOnlyTopLeft(bool bOn) { bMoveSnapOnlyTopLeft=bOn; }
     147           0 :     bool IsMoveSnapOnlyTopLeft() const { return bMoveSnapOnlyTopLeft; }
     148             : 
     149             :     // auxiliary lines fixed (not moveable)
     150             :     // persistent, Default=FALSE.
     151             :     bool IsHlplFixed() const { return bHlplFixed; }
     152             :     void SetHlplFixed(bool bOn) { bHlplFixed=bOn; }
     153             : 
     154             :     bool IsMoveMFrmSnap() const { return bMoveMFrmSnap; } // Fang des LogFram aller markierten Objekte
     155             :     bool IsMoveOFrmSnap() const { return bMoveOFrmSnap; } // Fang aller LogFram der markierten Objekte
     156             :     bool IsMoveOPntSnap() const { return bMoveOPntSnap; } // Fang ausgepraegter Punkte der markierten Objekte
     157             :     bool IsMoveOConSnap() const { return bMoveOConSnap; } // Fang der Konnektoren der markierten Objekte
     158             : 
     159             :     void SetMoveMFrmSnap(bool bOn) { bMoveMFrmSnap=bOn; }
     160             :     void SetMoveOFrmSnap(bool bOn) { bMoveOFrmSnap=bOn; }
     161             :     void SetMoveOPntSnap(bool bOn) { bMoveOPntSnap=bOn; }
     162             :     void SetMoveOConSnap(bool bOn) { bMoveOConSnap=bOn; }
     163             : 
     164             :     // #114409#-1 Migrate PageOrigin
     165             :     bool BegSetPageOrg(const Point& rPnt);
     166             :     void MovSetPageOrg(const Point& rPnt);
     167             :     bool EndSetPageOrg();
     168             :     void BrkSetPageOrg();
     169       17650 :     bool IsSetPageOrg() const { return (0L != mpPageOriginOverlay); }
     170             : 
     171             :     // HitTest. If sal_True, in rnHelpLineNum is the number of the auxiliary line and in rpPv
     172             :     // the appendent PageView.
     173             :     bool PickHelpLine(const Point& rPnt, short nTol, const OutputDevice& rOut, sal_uInt16& rnHelpLineNum, SdrPageView*& rpPV) const;
     174             : 
     175             :     // Move of an available auxiliary line. Use nHelpLineNum and pPV from PickHelpLine.
     176             :     bool BegDragHelpLine(sal_uInt16 nHelpLineNum, SdrPageView* pPV);
     177             :     // interactive insertionof a new auxiliary line
     178             :     bool BegDragHelpLine(const Point& rPnt, SdrHelpLineKind eNewKind);
     179             :     Pointer GetDraggedHelpLinePointer() const;
     180             : 
     181             :     // change the type of auxiliary line while dragging
     182             :     // void SetDraggedHelpLineKind(SdrHelpLineKind eNewKind);
     183             :     void MovDragHelpLine(const Point& rPnt);
     184             :     bool EndDragHelpLine();
     185             :     void BrkDragHelpLine();
     186       17651 :     bool IsDragHelpLine() const { return (0L != mpHelpLineOverlay); }
     187             : 
     188             :     // SnapAngle is for angles in circle, RotateDragging, ...
     189             :     // The snapping of an angle is beared down, if it is swiched off
     190             :     // with SetAngleSnapEnabled(sal_False)
     191             :     // The snapping angles is independent of snapping coordinates
     192             :     // and so independent of the attitude IsSnapEnabled()
     193             :     // Only values should be specified for them is applied:
     194             :     //     36000 modulu nAngle = 0
     195             :     // Implemented for:
     196             :     // - Rotate (Dragging)
     197             :     // - Shear (Dragging)
     198             :     // - circular arc/-sector/-section angle (Create and Dragging)
     199             :     // persistent.
     200         394 :     void SetAngleSnapEnabled(bool bOn) { bAngleSnapEnab=bOn; }
     201        1051 :     bool IsAngleSnapEnabled() const { return bAngleSnapEnab; }
     202        1165 :     void SetSnapAngle(long nAngle) { nSnapAngle=nAngle; }
     203        1816 :     long GetSnapAngle() const { return nSnapAngle; }
     204             : 
     205             :     // different effects from Ortho (depending on the context):
     206             :     // - Create
     207             :     //   - only lines in 45deg grid
     208             :     //   - instead of rectangles squares are created
     209             :     //   - instead of ellipse circles are created
     210             :     // - Dragging
     211             :     //   - general Dragging
     212             :     //     - Move only horizontal, vertical or 45deg
     213             :     //     - Resize proportional
     214             :     //     - Mirror: nothing
     215             :     //     - Shear without Resize
     216             :     //     - Crook without Resize
     217             :     //   - move handles
     218             :     //     - mirror axis only 45deg grid
     219             :     //   - object-specific Dragging
     220             :     //     - rectangle corner radius: nothing
     221             :     //     - circle object angle: nothing
     222             :     //     - line keeps while Dragging the angle and is only stretched/ contracted
     223             :     // Default value for Ortho is off. persistent.
     224         239 :     void SetOrtho(bool bOn) { bOrtho=bOn; } // unvollstaendig
     225         943 :     bool IsOrtho() const { return bOrtho; }
     226             : 
     227             :     // BigOrtho is only relevant if Ortho is switched on.
     228             :     // Example: rectangle is created and ortho is switched on (--> square)
     229             :     //   and the Mouse was dragged from zero to the coordinates
     230             :     //   (80,30). Now there are 2 alternatives to determine the edge length
     231             :     //   of the square: 30 and 80.
     232             :     //   The standard Ortho-Function took 30 (every time the smaller length)
     233             :     //   If BigOrtho is switched on, you get a square with edge length of 80.
     234             :     // The same also applies to Resize.
     235             :     // Default value for BigOrtho is on. persistent.
     236        1008 :     void SetBigOrtho(bool bOn) { bBigOrtho=bOn; }
     237        1697 :     bool IsBigOrtho() const { return bBigOrtho; }
     238             : 
     239             :     // If MoveOnlyDragging=sal_True only the center of the marked objects is
     240             :     // transformed when Resize/Rotate/Shear/Mirror/Crook is executed.
     241             :     // Size, form and rotation angle of the objects are conserved only their positions
     242             :     // are changed. persistent. Default=FALSE. (ni)
     243        1008 :     void SetMoveOnlyDragging(bool bOn) { bMoveOnlyDragging=bOn; }
     244        1697 :     bool IsMoveOnlyDragging() const { return bMoveOnlyDragging; }
     245             : 
     246             :     // Use Slant instead of Shear. persistent. Default=FALSE.
     247         234 :     void SetSlantButShear(bool bOn) { bSlantButShear=bOn; }
     248           1 :     bool IsSlantButShear() const { return bSlantButShear; }
     249             : 
     250             :     // Don't contort objecte while Crook. persistent. Default=FALSE. (ni)
     251        1008 :     void SetCrookNoContortion(bool bOn) { bCrookNoContortion=bOn; }
     252        5864 :     bool IsCrookNoContortion() const { return bCrookNoContortion; }
     253             : 
     254             :     // Crook-Mode. persistent. Default=SDRCROOK_ROTATE. (ni)
     255           0 :     void SetCrookMode(SdrCrookMode eMode) { eCrookMode=eMode; }
     256           0 :     SdrCrookMode GetCrookMode() const { return eCrookMode; }
     257             : 
     258             :     // Special for IBM: While Dragging of a traverse station, it is deleted
     259             :     // if its adjacent lines are almost a solid line.
     260        1165 :     void SetEliminatePolyPoints(bool bOn) { bEliminatePolyPoints=bOn; }
     261        1816 :     bool IsEliminatePolyPoints() const { return bEliminatePolyPoints; }
     262        1298 :     void SetEliminatePolyPointLimitAngle(long nAngle) { nEliminatePolyPointLimitAngle=nAngle; }
     263        1949 :     long GetEliminatePolyPointLimitAngle() const { return nEliminatePolyPointLimitAngle; }
     264             : };
     265             : 
     266             : // definition:
     267             : //   - snap something= e.g. the mouse pointer or some marked objects in drag can be snapped
     268             : //   - snap on sth.= you can e.g. snap on the grid or on auxiliary lines.
     269             : //
     270             : //
     271             : // Grundsaetzlich wird nur gefangen auf sichtbare Elemente (-> Border,
     272             : // Hilfslinien, Konnektoren; Ausnahme: Grid). Ebenso koennen nur sichtbare
     273             : // Elemente gefangen werden (->Konnektoren).
     274             : //
     275             : // Auf's Grid wird immer erst dann gefangen, wenn nix Anderes in der Naehe
     276             : // (->Magnetic) ist.
     277             : //
     278             : // Der "Cursor" (also der Mauszeiger) beim Erzeugen von Objekten, beim Draggen
     279             : // von Polygonpunkten, ... wird immer auf allen eingeschalteten Fangalternativen
     280             : // gefangen (max 6).
     281             : //
     282             : // Beim Verschieben markierter Objekte ist das etwas anders. Statt des einen
     283             : // Mauscursors gibt es hier 4 Alternativen an den markierten Objekten, die
     284             : // gefangen werden koennen:
     285             : //   1. die logisch-umschliessenden Rahmen der einzelnen Objekte
     286             : //   2. der logisch-umschliessende Rahmen aller markierten Objekte
     287             : //   3. ausgezeichnete Punkte der markierten Objekte (Polygonpunkte, ...)
     288             : //   4. die Konnektoren der markierten Objekte
     289             : // Da 1. und 2. einander ausschliessen (2. ist eine Verfeinerung von 1.)
     290             : // bleiben 3 voneinander unabhaengige Alternativen. Bei 6. Moeglichkeiten auf
     291             : // die gefangen werden kann kaeme man auf max. 18 Kombinationsmoeglichkeiten!
     292             : // Deshalb werden folgende Vereinfachungen festgelegt:
     293             : //   1. Konnektoren fangen sich nur auf Konnektoren.
     294             : // Verbleiben also nun noch max. 2x5+1=11 Fangkombinationen beim MoveDrag:
     295             : //   1-3.  umschliessende(r) Rahmen auf Grid/Border/Hilfslinien
     296             : //   4.    umschliessende(r) Rahmen auf ausgezeichnete Objektpunkte
     297             : //   5.    umschliessende(r) Rahmen auf umschliessenden Rahmen
     298             : //   6-8.  ausgezeichnete Punkte auf Grid/Border/Hilfslinien
     299             : //   7.    ausgezeichnete Punkte auf ausgezeichnete Objektpunkte
     300             : //   8-10. ausgezeichnete Punkte auf umschliessenden Rahmen
     301             : //   11.   Konnektoren auf Konnektoren
     302             : // Beim MouseMove-Event im DragMove werden also diese bis zu max. 11 moeglichen
     303             : // Alternativen durchgetestet und die mit dem gerigsten Korrekturaufwand
     304             : // vollzogen.
     305             : //
     306             : // Beim Resize, ... wird immer nur der logisch-umschliessende Rahmen der
     307             : // markierten Objekte gefangen.
     308             : 
     309             : #endif // INCLUDED_SVX_SVDSNPV_HXX
     310             : 
     311             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11