LCOV - code coverage report
Current view: top level - sw/inc - swrect.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 97 100 97.0 %
Date: 2014-04-11 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             :            sal_Bool IsInside( const Point& rPOINT ) const;
      83             :            sal_Bool IsNear(const Point& rPoint, long nTolerance ) const;
      84             :            sal_Bool IsInside( const SwRect& rRect ) const;
      85             :            sal_Bool IsOver( const SwRect& rRect ) const;
      86             :     inline sal_Bool HasArea() const;
      87             :     inline sal_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             :     void _Top(      const long nTop );
     105             :     void _Bottom(   const long nBottom );
     106             :     void _Left(     const long nLeft );
     107             :     void _Right(    const long nRight );
     108             :     void _Width(    const long nNew );
     109             :     void _Height(   const long nNew );
     110             :     long _Top()     const;
     111             :     long _Bottom()  const;
     112             :     long _Left()    const;
     113             :     long _Right()   const;
     114             :     long _Width()   const;
     115             :     long _Height()  const;
     116             :     void SubTop(    const long nSub );
     117             :     void AddBottom( const long nAdd );
     118             :     void SubLeft(   const long nSub );
     119             :     void AddRight(  const long nAdd );
     120             :     void AddWidth(  const long nAdd );
     121             :     void AddHeight( const long nAdd );
     122             :     void SetPosX(   const long nNew );
     123             :     void SetPosY(   const long nNew );
     124             :     void SetLeftAndWidth( long nLeft, long nNew );
     125             :     void SetTopAndHeight( long nTop, long nNew );
     126             :     void SetRightAndWidth( long nRight, long nNew );
     127             :     void SetBottomAndHeight( long nBottom, long nNew );
     128             :     void SetUpperLeftCorner(  const Point& rNew );
     129             :     void SetUpperRightCorner(  const Point& rNew );
     130             :     void SetLowerLeftCorner(  const Point& rNew );
     131             :     const Size  _Size() const;
     132             :     const Point TopLeft()  const;
     133             :     const Point TopRight()  const;
     134             :     const Point BottomLeft()  const;
     135             :     const Point BottomRight()  const;
     136             :     const Size  SwappedSize() const;
     137             :     long GetLeftDistance( long ) const;
     138             :     long GetBottomDistance( long ) const;
     139             :     long GetRightDistance( long ) const;
     140             :     long GetTopDistance( long ) const;
     141             :     sal_Bool OverStepLeft( long ) const;
     142             :     sal_Bool OverStepBottom( long ) const;
     143             :     sal_Bool OverStepTop( long ) const;
     144             :     sal_Bool OverStepRight( long ) const;
     145             : };
     146             : 
     147             : typedef void (SwRect:: *SwRectSet)( const long nNew );
     148             : typedef long (SwRect:: *SwRectGet)() const;
     149             : typedef const Point (SwRect:: *SwRectPoint)() const;
     150             : typedef const Size (SwRect:: *SwRectSize)() const;
     151             : typedef sal_Bool (SwRect:: *SwRectMax)( long ) const;
     152             : typedef long (SwRect:: *SwRectDist)( long ) const;
     153             : typedef void (SwRect:: *SwRectSetTwice)( long, long );
     154             : typedef void (SwRect:: *SwRectSetPos)( const Point& );
     155             : 
     156             : //  Set-Methods
     157       60860 : inline void SwRect::Chg( const Point& rNP, const Size &rNS )
     158             : {
     159       60860 :     m_Point = rNP;
     160       60860 :     m_Size = rNS;
     161       60860 : }
     162      150144 : inline void SwRect::Pos(  const Point& rNew )
     163             : {
     164      150144 :     m_Point = rNew;
     165      150144 : }
     166          10 : inline void SwRect::Pos( const long nNewX, const long nNewY )
     167             : {
     168          10 :     m_Point.setX(nNewX);
     169          10 :     m_Point.setY(nNewY);
     170          10 : }
     171       69589 : inline void SwRect::SSize( const Size&  rNew  )
     172             : {
     173       69589 :     m_Size = rNew;
     174       69589 : }
     175        8617 : inline void SwRect::SSize( const long nNewHeight, const long nNewWidth )
     176             : {
     177        8617 :     m_Size.setWidth(nNewWidth);
     178        8617 :     m_Size.setHeight(nNewHeight);
     179        8617 : }
     180      257880 : inline void SwRect::Width(  long nNew )
     181             : {
     182      257880 :     m_Size.setWidth(nNew);
     183      257880 : }
     184      100492 : inline void SwRect::Height( long nNew )
     185             : {
     186      100492 :     m_Size.setHeight(nNew);
     187      100492 : }
     188      285439 : inline void SwRect::Left( const long nLeft )
     189             : {
     190      285439 :     m_Size.Width() += m_Point.getX() - nLeft;
     191      285439 :     m_Point.setX(nLeft);
     192      285439 : }
     193      235363 : inline void SwRect::Right( const long nRight )
     194             : {
     195      235363 :     m_Size.setWidth(nRight - m_Point.getX() + 1);
     196      235363 : }
     197      307951 : inline void SwRect::Top( const long nTop )
     198             : {
     199      307951 :     m_Size.Height() += m_Point.getY() - nTop;
     200      307951 :     m_Point.setY(nTop);
     201      307951 : }
     202      286776 : inline void SwRect::Bottom( const long nBottom )
     203             : {
     204      286776 :     m_Size.setHeight(nBottom - m_Point.getY() + 1);
     205      286776 : }
     206             : 
     207             : // Get-Methods
     208      405275 : inline const Point &SwRect::Pos()  const
     209             : {
     210      405275 :     return m_Point;
     211             : }
     212     1202445 : inline Point &SwRect::Pos()
     213             : {
     214     1202445 :     return m_Point;
     215             : }
     216      267706 : inline const Size  &SwRect::SSize() const
     217             : {
     218      267706 :     return m_Size;
     219             : }
     220      467942 : inline Size  &SwRect::SSize()
     221             : {
     222      467942 :     return m_Size;
     223             : }
     224     1433410 : inline long SwRect::Width()  const
     225             : {
     226     1433410 :     return m_Size.Width();
     227             : }
     228     1671461 : inline long SwRect::Height() const
     229             : {
     230     1671461 :     return m_Size.Height();
     231             : }
     232     3083777 : inline long SwRect::Left()   const
     233             : {
     234     3083777 :     return m_Point.X();
     235             : }
     236     2051295 : inline long SwRect::Right()  const
     237             : {
     238     2051295 :     return m_Size.getWidth() ? m_Point.getX() + m_Size.getWidth() - 1 : m_Point.getX();
     239             : }
     240     3755911 : inline long SwRect::Top()    const
     241             : {
     242     3755911 :     return m_Point.Y();
     243             : }
     244     2092541 : inline long SwRect::Bottom() const
     245             : {
     246     2092541 :     return m_Size.getHeight() ? m_Point.getY() + m_Size.getHeight() - 1 : m_Point.getY();
     247             : }
     248             : 
     249             : // operators
     250      706472 : inline SwRect &SwRect::operator = ( const SwRect &rRect )
     251             : {
     252      706472 :     m_Point = rRect.m_Point;
     253      706472 :     m_Size = rRect.m_Size;
     254      706472 :     return *this;
     255             : }
     256      138165 : inline bool SwRect::operator == ( const SwRect& rRect ) const
     257             : {
     258      138165 :     return (m_Point == rRect.m_Point && m_Size == rRect.m_Size);
     259             : }
     260      443308 : inline bool SwRect::operator != ( const SwRect& rRect ) const
     261             : {
     262      443308 :     return (m_Point != rRect.m_Point || m_Size != rRect.m_Size);
     263             : }
     264             : 
     265        3726 : inline SwRect &SwRect::operator+=( const Point &rPt )
     266             : {
     267        3726 :     m_Point += rPt;
     268        3726 :     return *this;
     269             : }
     270           0 : inline SwRect &SwRect::operator-=( const Point &rPt )
     271             : {
     272           0 :     m_Point -= rPt;
     273           0 :     return *this;
     274             : }
     275             : 
     276             : inline SwRect &SwRect::operator+=( const Size &rSz )
     277             : {
     278             :     m_Size.Width() += rSz.Width();
     279             :     m_Size.Height() += rSz.Height();
     280             :     return *this;
     281             : }
     282             : inline SwRect &SwRect::operator-=( const Size &rSz )
     283             : {
     284             :     m_Size.Width() -= rSz.Width();
     285             :     m_Size.Height() -= rSz.Height();
     286             :     return *this;
     287             : }
     288             : 
     289             : // other
     290      536355 : inline Rectangle SwRect::SVRect() const
     291             : {
     292             :     SAL_WARN_IF( IsEmpty(), "sw", "SVRect() without Width or Height" );
     293             :     return Rectangle( m_Point.getX(), m_Point.getY(),
     294      536355 :         m_Point.getX() + m_Size.getWidth() - 1,         //Right()
     295     1072710 :         m_Point.getY() + m_Size.getHeight() - 1 );      //Bottom()
     296             : }
     297             : 
     298             : inline SwRect SwRect::GetIntersection( const SwRect& rRect ) const
     299             : {
     300             :     return SwRect( *this ).Intersection( rRect );
     301             : }
     302             : 
     303      469549 : inline sal_Bool SwRect::HasArea() const
     304             : {
     305      469549 :     return !IsEmpty();
     306             : }
     307      483862 : inline sal_Bool SwRect::IsEmpty() const
     308             : {
     309      483862 :     return !(m_Size.getHeight() && m_Size.getWidth());
     310             : }
     311        6636 : inline void SwRect::Clear()
     312             : {
     313        6636 :     m_Point.setX(0);
     314        6636 :     m_Point.setY(0);
     315        6636 :     m_Size.setWidth(0);
     316        6636 :     m_Size.setHeight(0);
     317        6636 : }
     318             : 
     319             : // constructors
     320     1184672 : inline SwRect::SwRect() :
     321             :     m_Point( 0, 0 ),
     322     1184672 :     m_Size( 0, 0 )
     323             : {
     324     1184672 : }
     325     1998530 : inline SwRect::SwRect( const SwRect &rRect ) :
     326             :     m_Point( rRect.m_Point ),
     327     1998530 :     m_Size( rRect.m_Size )
     328             : {
     329     1998530 : }
     330      117347 : inline SwRect::SwRect( const Point& rLT, const Size&  rSize ) :
     331             :     m_Point( rLT ),
     332      117347 :     m_Size( rSize )
     333             : {
     334      117347 : }
     335       42818 : inline SwRect::SwRect( const Point& rLT, const Point& rRB ) :
     336             :     m_Point( rLT ),
     337       42818 :     m_Size( rRB.X() - rLT.X() + 1, rRB.Y() - rLT.Y() + 1 )
     338             : {
     339       42818 : }
     340       47404 : inline SwRect::SwRect( long X, long Y, long W, long H ) :
     341             :     m_Point( X, Y ),
     342       47404 :     m_Size( W, H )
     343             : {
     344       47404 : }
     345             : 
     346             : template< typename charT, typename traits >
     347             : inline std::basic_ostream<charT, traits> & operator <<(
     348             :     std::basic_ostream<charT, traits> & stream, const SwRect& rectangle )
     349             : {
     350             :     if (rectangle.IsEmpty())
     351             :         return stream << "EMPTY";
     352             :     else
     353             :         return stream << rectangle.SSize()
     354             :                       << "@(" << rectangle.Pos() << ")";
     355             : }
     356             : 
     357             : #endif // INCLUDED_SW_INC_SWRECT_HXX
     358             : 
     359             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10