LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/inc - swrect.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 97 100 97.0 %
Date: 2013-07-09 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 _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       25626 : inline void SwRect::Chg( const Point& rNP, const Size &rNS )
     164             : {
     165       25626 :     m_Point = rNP;
     166       25626 :     m_Size = rNS;
     167       25626 : }
     168       45886 : inline void SwRect::Pos(  const Point& rNew )
     169             : {
     170       45886 :     m_Point = rNew;
     171       45886 : }
     172           6 : inline void SwRect::Pos( const long nNewX, const long nNewY )
     173             : {
     174           6 :     m_Point.setX(nNewX);
     175           6 :     m_Point.setY(nNewY);
     176           6 : }
     177       42665 : inline void SwRect::SSize( const Size&  rNew  )
     178             : {
     179       42665 :     m_Size = rNew;
     180       42665 : }
     181        7888 : inline void SwRect::SSize( const long nNewHeight, const long nNewWidth )
     182             : {
     183        7888 :     m_Size.setWidth(nNewWidth);
     184        7888 :     m_Size.setHeight(nNewHeight);
     185        7888 : }
     186      115061 : inline void SwRect::Width(  long nNew )
     187             : {
     188      115061 :     m_Size.setWidth(nNew);
     189      115061 : }
     190       41103 : inline void SwRect::Height( long nNew )
     191             : {
     192       41103 :     m_Size.setHeight(nNew);
     193       41103 : }
     194      122462 : inline void SwRect::Left( const long nLeft )
     195             : {
     196      122462 :     m_Size.Width() += m_Point.getX() - nLeft;
     197      122462 :     m_Point.setX(nLeft);
     198      122462 : }
     199      130094 : inline void SwRect::Right( const long nRight )
     200             : {
     201      130094 :     m_Size.setWidth(nRight - m_Point.getX() + 1);
     202      130094 : }
     203      157582 : inline void SwRect::Top( const long nTop )
     204             : {
     205      157582 :     m_Size.Height() += m_Point.getY() - nTop;
     206      157582 :     m_Point.setY(nTop);
     207      157582 : }
     208      152079 : inline void SwRect::Bottom( const long nBottom )
     209             : {
     210      152079 :     m_Size.setHeight(nBottom - m_Point.getY() + 1);
     211      152079 : }
     212             : 
     213             : // Get-Methods
     214      116260 : inline const Point &SwRect::Pos()  const
     215             : {
     216      116260 :     return m_Point;
     217             : }
     218      392297 : inline Point &SwRect::Pos()
     219             : {
     220      392297 :     return m_Point;
     221             : }
     222       86379 : inline const Size  &SwRect::SSize() const
     223             : {
     224       86379 :     return m_Size;
     225             : }
     226       97809 : inline Size  &SwRect::SSize()
     227             : {
     228       97809 :     return m_Size;
     229             : }
     230      628747 : inline long SwRect::Width()  const
     231             : {
     232      628747 :     return m_Size.Width();
     233             : }
     234      793051 : inline long SwRect::Height() const
     235             : {
     236      793051 :     return m_Size.Height();
     237             : }
     238     1784715 : inline long SwRect::Left()   const
     239             : {
     240     1784715 :     return m_Point.X();
     241             : }
     242     1237372 : inline long SwRect::Right()  const
     243             : {
     244     1237372 :     return m_Size.getWidth() ? m_Point.getX() + m_Size.getWidth() - 1 : m_Point.getX();
     245             : }
     246     2018355 : inline long SwRect::Top()    const
     247             : {
     248     2018355 :     return m_Point.Y();
     249             : }
     250     1236540 : inline long SwRect::Bottom() const
     251             : {
     252     1236540 :     return m_Size.getHeight() ? m_Point.getY() + m_Size.getHeight() - 1 : m_Point.getY();
     253             : }
     254             : 
     255             : // operators
     256      381148 : inline SwRect &SwRect::operator = ( const SwRect &rRect )
     257             : {
     258      381148 :     m_Point = rRect.m_Point;
     259      381148 :     m_Size = rRect.m_Size;
     260      381148 :     return *this;
     261             : }
     262       46483 : inline sal_Bool SwRect::operator == ( const SwRect& rRect ) const
     263             : {
     264       46483 :     return (m_Point == rRect.m_Point && m_Size == rRect.m_Size);
     265             : }
     266       23456 : inline sal_Bool SwRect::operator != ( const SwRect& rRect ) const
     267             : {
     268       23456 :     return (m_Point != rRect.m_Point || m_Size != rRect.m_Size);
     269             : }
     270             : 
     271        2278 : inline SwRect &SwRect::operator+=( const Point &rPt )
     272             : {
     273        2278 :     m_Point += rPt;
     274        2278 :     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      288940 : 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      288940 :         m_Point.getX() + m_Size.getWidth() - 1,         //Right()
     302      577880 :         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      231826 : inline sal_Bool SwRect::HasArea() const
     311             : {
     312      231826 :     return !IsEmpty();
     313             : }
     314      238729 : inline sal_Bool SwRect::IsEmpty() const
     315             : {
     316      238729 :     return !(m_Size.getHeight() && m_Size.getWidth());
     317             : }
     318        5104 : inline void SwRect::Clear()
     319             : {
     320        5104 :     m_Point.setX(0);
     321        5104 :     m_Point.setY(0);
     322        5104 :     m_Size.setWidth(0);
     323        5104 :     m_Size.setHeight(0);
     324        5104 : }
     325             : 
     326             : // constructors
     327      478029 : inline SwRect::SwRect() :
     328             :     m_Point( 0, 0 ),
     329      478029 :     m_Size( 0, 0 )
     330             : {
     331      478029 : }
     332      629253 : inline SwRect::SwRect( const SwRect &rRect ) :
     333             :     m_Point( rRect.m_Point ),
     334      629253 :     m_Size( rRect.m_Size )
     335             : {
     336      629253 : }
     337       35226 : inline SwRect::SwRect( const Point& rLT, const Size&  rSize ) :
     338             :     m_Point( rLT ),
     339       35226 :     m_Size( rSize )
     340             : {
     341       35226 : }
     342       33794 : inline SwRect::SwRect( const Point& rLT, const Point& rRB ) :
     343             :     m_Point( rLT ),
     344       33794 :     m_Size( rRB.X() - rLT.X() + 1, rRB.Y() - rLT.Y() + 1 )
     345             : {
     346       33794 : }
     347        5492 : inline SwRect::SwRect( long X, long Y, long W, long H ) :
     348             :     m_Point( X, Y ),
     349        5492 :     m_Size( W, H )
     350             : {
     351        5492 : }
     352             : 
     353             : 
     354             : #endif  //_SWRECT_HXX
     355             : 
     356             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10