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

Generated by: LCOV version 1.10