LCOV - code coverage report
Current view: top level - sw/inc - swrect.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 97 100 97.0 %
Date: 2015-06-13 12:38:46 Functions: 34 35 97.1 %
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             : #ifndef INCLUDED_SW_INC_SWRECT_HXX
      20             : #define INCLUDED_SW_INC_SWRECT_HXX
      21             : 
      22             : #include <ostream>
      23             : 
      24             : #include <sal/log.hxx>
      25             : #include <tools/gen.hxx>
      26             : 
      27             : class SvStream;
      28             : 
      29             : class SAL_WARN_UNUSED SwRect
      30             : {
      31             :     Point m_Point;
      32             :     Size m_Size;
      33             : 
      34             : public:
      35             :     inline SwRect();
      36             :     inline SwRect( const SwRect &rRect );
      37             :     inline SwRect( const Point& rLT, const Size&  rSize );
      38             :     inline SwRect( const Point& rLT, const Point& rRB );
      39             :     inline SwRect( long X, long Y, long Width, long Height );
      40             : 
      41             :     //SV-SS e.g. SwRect( pWin->GetClipRect() );
      42             :     SwRect( const Rectangle &rRect );
      43             : 
      44             :     //Set-Methods
      45             :     inline void Chg( const Point& rNP, const Size &rNS );
      46             :     inline void Pos(  const Point& rNew );
      47             :     inline void Pos( const long nNewX, const long nNewY );
      48             :     inline void SSize( const Size&  rNew  );
      49             :     inline void SSize( const long nHeight, const long nWidth );
      50             :     inline void Width(  long nNew );
      51             :     inline void Height( long nNew );
      52             :     inline void Left( const long nLeft );
      53             :     inline void Right( const long nRight );
      54             :     inline void Top( const long nTop );
      55             :     inline void Bottom( const long nBottom );
      56             : 
      57             :     //Get-Methods
      58             :     inline const Point &Pos()  const;
      59             :     inline const Size  &SSize() const;
      60             :     inline long Width()  const;
      61             :     inline long Height() const;
      62             :     inline long Left()   const;
      63             :     inline long Right()  const;
      64             :     inline long Top()    const;
      65             :     inline long Bottom() const;
      66             : 
      67             :     // In order to be able to access the members of Pos and SSize from the layout side.
      68             :     inline Point &Pos();
      69             :     inline Size  &SSize();
      70             : 
      71             :     Point Center() const;
      72             : 
      73             :     void Justify();
      74             : 
      75             :            SwRect &Union( const SwRect& rRect );
      76             :            SwRect &Intersection( const SwRect& rRect );
      77             : 
      78             :    // Same as Intersection, only assume that Rects are overlapping!
      79             :            SwRect &_Intersection( const SwRect &rRect );
      80             :     inline SwRect  GetIntersection( const SwRect& rRect ) const;
      81             : 
      82             :            bool IsInside( const Point& rPOINT ) const;
      83             :            bool IsNear(const Point& rPoint, long nTolerance ) const;
      84             :            bool IsInside( const SwRect& rRect ) const;
      85             :            bool IsOver( const SwRect& rRect ) const;
      86             :     inline bool HasArea() const;
      87             :     inline bool IsEmpty() const;
      88             :     inline void Clear();
      89             : 
      90             :     inline SwRect &operator = ( const SwRect &rRect );
      91             : 
      92             :     inline bool operator == ( const SwRect& rRect ) const;
      93             :     inline bool operator != ( const SwRect& rRect ) const;
      94             : 
      95             :     inline SwRect &operator+=( const Point &rPt );
      96             :     inline SwRect &operator-=( const Point &rPt );
      97             : 
      98             :     inline SwRect &operator+=( const Size &rSz );
      99             :     inline SwRect &operator-=( const Size &rSz );
     100             : 
     101             :     //SV-SS e.g. pWin->DrawRect( aSwRect.SVRect() );
     102             :     inline Rectangle  SVRect() const;
     103             : 
     104             :     // Output operator for debugging.
     105             :     friend SvStream& WriteSwRect( SvStream &rStream, const SwRect &rRect );
     106             : 
     107             : 
     108             :     void _Top(      const long nTop );
     109             :     void _Bottom(   const long nBottom );
     110             :     void _Left(     const long nLeft );
     111             :     void _Right(    const long nRight );
     112             :     void _Width(    const long nNew );
     113             :     void _Height(   const long nNew );
     114             :     long _Top()     const;
     115             :     long _Bottom()  const;
     116             :     long _Left()    const;
     117             :     long _Right()   const;
     118             :     long _Width()   const;
     119             :     long _Height()  const;
     120             :     void SubTop(    const long nSub );
     121             :     void AddBottom( const long nAdd );
     122             :     void SubLeft(   const long nSub );
     123             :     void AddRight(  const long nAdd );
     124             :     void AddWidth(  const long nAdd );
     125             :     void AddHeight( const long nAdd );
     126             :     void SetPosX(   const long nNew );
     127             :     void SetPosY(   const long nNew );
     128             :     void SetLeftAndWidth( long nLeft, long nNew );
     129             :     void SetTopAndHeight( long nTop, long nNew );
     130             :     void SetRightAndWidth( long nRight, long nNew );
     131             :     void SetBottomAndHeight( long nBottom, long nNew );
     132             :     void SetUpperLeftCorner(  const Point& rNew );
     133             :     void SetUpperRightCorner(  const Point& rNew );
     134             :     void SetLowerLeftCorner(  const Point& rNew );
     135             :     const Size  _Size() const;
     136             :     const Point TopLeft()  const;
     137             :     const Point TopRight()  const;
     138             :     const Point BottomLeft()  const;
     139             :     const Point BottomRight()  const;
     140             :     const Size  SwappedSize() const;
     141             :     long GetLeftDistance( long ) const;
     142             :     long GetBottomDistance( long ) const;
     143             :     long GetRightDistance( long ) const;
     144             :     long GetTopDistance( long ) const;
     145             :     bool OverStepLeft( long ) const;
     146             :     bool OverStepBottom( long ) const;
     147             :     bool OverStepTop( long ) const;
     148             :     bool OverStepRight( long ) const;
     149             : };
     150             : 
     151             : typedef void (SwRect:: *SwRectSet)( const long nNew );
     152             : typedef long (SwRect:: *SwRectGet)() const;
     153             : typedef const Point (SwRect:: *SwRectPoint)() const;
     154             : typedef const Size (SwRect:: *SwRectSize)() const;
     155             : typedef bool (SwRect:: *SwRectMax)( long ) const;
     156             : typedef long (SwRect:: *SwRectDist)( long ) const;
     157             : typedef void (SwRect:: *SwRectSetTwice)( long, long );
     158             : typedef void (SwRect:: *SwRectSetPos)( const Point& );
     159             : 
     160             : //  Set-Methods
     161      107282 : inline void SwRect::Chg( const Point& rNP, const Size &rNS )
     162             : {
     163      107282 :     m_Point = rNP;
     164      107282 :     m_Size = rNS;
     165      107282 : }
     166      215212 : inline void SwRect::Pos(  const Point& rNew )
     167             : {
     168      215212 :     m_Point = rNew;
     169      215212 : }
     170           8 : inline void SwRect::Pos( const long nNewX, const long nNewY )
     171             : {
     172           8 :     m_Point.setX(nNewX);
     173           8 :     m_Point.setY(nNewY);
     174           8 : }
     175      119964 : inline void SwRect::SSize( const Size&  rNew  )
     176             : {
     177      119964 :     m_Size = rNew;
     178      119964 : }
     179        8707 : inline void SwRect::SSize( const long nNewHeight, const long nNewWidth )
     180             : {
     181        8707 :     m_Size.setWidth(nNewWidth);
     182        8707 :     m_Size.setHeight(nNewHeight);
     183        8707 : }
     184      366321 : inline void SwRect::Width(  long nNew )
     185             : {
     186      366321 :     m_Size.setWidth(nNew);
     187      366321 : }
     188      128512 : inline void SwRect::Height( long nNew )
     189             : {
     190      128512 :     m_Size.setHeight(nNew);
     191      128512 : }
     192      383802 : inline void SwRect::Left( const long nLeft )
     193             : {
     194      383802 :     m_Size.Width() += m_Point.getX() - nLeft;
     195      383802 :     m_Point.setX(nLeft);
     196      383802 : }
     197      390008 : inline void SwRect::Right( const long nRight )
     198             : {
     199      390008 :     m_Size.setWidth(nRight - m_Point.getX() + 1);
     200      390008 : }
     201      413822 : inline void SwRect::Top( const long nTop )
     202             : {
     203      413822 :     m_Size.Height() += m_Point.getY() - nTop;
     204      413822 :     m_Point.setY(nTop);
     205      413822 : }
     206      433016 : inline void SwRect::Bottom( const long nBottom )
     207             : {
     208      433016 :     m_Size.setHeight(nBottom - m_Point.getY() + 1);
     209      433016 : }
     210             : 
     211             : // Get-Methods
     212      610946 : inline const Point &SwRect::Pos()  const
     213             : {
     214      610946 :     return m_Point;
     215             : }
     216     1942262 : inline Point &SwRect::Pos()
     217             : {
     218     1942262 :     return m_Point;
     219             : }
     220      416642 : inline const Size  &SwRect::SSize() const
     221             : {
     222      416642 :     return m_Size;
     223             : }
     224      663715 : inline Size  &SwRect::SSize()
     225             : {
     226      663715 :     return m_Size;
     227             : }
     228     2262569 : inline long SwRect::Width()  const
     229             : {
     230     2262569 :     return m_Size.Width();
     231             : }
     232     2595333 : inline long SwRect::Height() const
     233             : {
     234     2595333 :     return m_Size.Height();
     235             : }
     236   111426577 : inline long SwRect::Left()   const
     237             : {
     238   111426577 :     return m_Point.X();
     239             : }
     240   110008991 : inline long SwRect::Right()  const
     241             : {
     242   110008991 :     return m_Size.getWidth() ? m_Point.getX() + m_Size.getWidth() - 1 : m_Point.getX();
     243             : }
     244   112843937 : inline long SwRect::Top()    const
     245             : {
     246   112843937 :     return m_Point.Y();
     247             : }
     248   110301482 : inline long SwRect::Bottom() const
     249             : {
     250   110301482 :     return m_Size.getHeight() ? m_Point.getY() + m_Size.getHeight() - 1 : m_Point.getY();
     251             : }
     252             : 
     253             : // operators
     254     1169621 : inline SwRect &SwRect::operator = ( const SwRect &rRect )
     255             : {
     256     1169621 :     m_Point = rRect.m_Point;
     257     1169621 :     m_Size = rRect.m_Size;
     258     1169621 :     return *this;
     259             : }
     260    26984283 : inline bool SwRect::operator == ( const SwRect& rRect ) const
     261             : {
     262    26984283 :     return (m_Point == rRect.m_Point && m_Size == rRect.m_Size);
     263             : }
     264    28513759 : inline bool SwRect::operator != ( const SwRect& rRect ) const
     265             : {
     266    28513759 :     return (m_Point != rRect.m_Point || m_Size != rRect.m_Size);
     267             : }
     268             : 
     269        6328 : inline SwRect &SwRect::operator+=( const Point &rPt )
     270             : {
     271        6328 :     m_Point += rPt;
     272        6328 :     return *this;
     273             : }
     274           0 : inline SwRect &SwRect::operator-=( const Point &rPt )
     275             : {
     276           0 :     m_Point -= rPt;
     277           0 :     return *this;
     278             : }
     279             : 
     280             : inline SwRect &SwRect::operator+=( const Size &rSz )
     281             : {
     282             :     m_Size.Width() += rSz.Width();
     283             :     m_Size.Height() += rSz.Height();
     284             :     return *this;
     285             : }
     286             : inline SwRect &SwRect::operator-=( const Size &rSz )
     287             : {
     288             :     m_Size.Width() -= rSz.Width();
     289             :     m_Size.Height() -= rSz.Height();
     290             :     return *this;
     291             : }
     292             : 
     293             : // other
     294      876801 : inline Rectangle SwRect::SVRect() const
     295             : {
     296             :     SAL_WARN_IF( IsEmpty(), "sw", "SVRect() without Width or Height" );
     297             :     return Rectangle( m_Point.getX(), m_Point.getY(),
     298      876801 :         m_Point.getX() + m_Size.getWidth() - 1,         //Right()
     299     1753602 :         m_Point.getY() + m_Size.getHeight() - 1 );      //Bottom()
     300             : }
     301             : 
     302             : inline SwRect SwRect::GetIntersection( const SwRect& rRect ) const
     303             : {
     304             :     return SwRect( *this ).Intersection( rRect );
     305             : }
     306             : 
     307    49228037 : inline bool SwRect::HasArea() const
     308             : {
     309    49228037 :     return !IsEmpty();
     310             : }
     311    49267008 : inline bool SwRect::IsEmpty() const
     312             : {
     313    49267008 :     return !(m_Size.getHeight() && m_Size.getWidth());
     314             : }
     315        8577 : inline void SwRect::Clear()
     316             : {
     317        8577 :     m_Point.setX(0);
     318        8577 :     m_Point.setY(0);
     319        8577 :     m_Size.setWidth(0);
     320        8577 :     m_Size.setHeight(0);
     321        8577 : }
     322             : 
     323             : // constructors
     324    50552229 : inline SwRect::SwRect() :
     325             :     m_Point( 0, 0 ),
     326    50552229 :     m_Size( 0, 0 )
     327             : {
     328    50552229 : }
     329    31080018 : inline SwRect::SwRect( const SwRect &rRect ) :
     330             :     m_Point( rRect.m_Point ),
     331    31080018 :     m_Size( rRect.m_Size )
     332             : {
     333    31080018 : }
     334      188242 : inline SwRect::SwRect( const Point& rLT, const Size&  rSize ) :
     335             :     m_Point( rLT ),
     336      188242 :     m_Size( rSize )
     337             : {
     338      188242 : }
     339       60795 : inline SwRect::SwRect( const Point& rLT, const Point& rRB ) :
     340             :     m_Point( rLT ),
     341       60795 :     m_Size( rRB.X() - rLT.X() + 1, rRB.Y() - rLT.Y() + 1 )
     342             : {
     343       60795 : }
     344      134529 : inline SwRect::SwRect( long X, long Y, long W, long H ) :
     345             :     m_Point( X, Y ),
     346      134529 :     m_Size( W, H )
     347             : {
     348      134529 : }
     349             : 
     350             : template< typename charT, typename traits >
     351             : inline std::basic_ostream<charT, traits> & operator <<(
     352             :     std::basic_ostream<charT, traits> & stream, const SwRect& rectangle )
     353             : {
     354             :     if (rectangle.IsEmpty())
     355             :         return stream << "EMPTY";
     356             :     else
     357             :         return stream << rectangle.SSize()
     358             :                       << "@(" << rectangle.Pos() << ")";
     359             : }
     360             : 
     361             : #endif // INCLUDED_SW_INC_SWRECT_HXX
     362             : 
     363             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11