/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- *//* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */#include <swrect.hxx>#ifdef DBG_UTIL#include <tools/stream.hxx>#endifSwRect::SwRect(consttools::Rectangle&rRect):m_Point(rRect.Left(),rRect.Top()){m_Size.setWidth(rRect.IsWidthEmpty()?0:rRect.Right()-rRect.Left()+1);m_Size.setHeight(rRect.IsHeightEmpty()?0:rRect.Bottom()-rRect.Top()+1);}PointSwRect::Center()const{returnPoint(Left()+Width()/2,Top()+Height()/2);}SwRect&SwRect::Union(constSwRect&rRect){if(Top()>rRect.Top())Top(rRect.Top());if(Left()>rRect.Left())Left(rRect.Left());longn=rRect.Right();if(Right()<n)Right(n);n=rRect.Bottom();if(Bottom()<n)Bottom(n);return*this;}SwRect&SwRect::Intersection(constSwRect&rRect){// any similarity between me and given element?if(IsOver(rRect)){// get smaller right and lower, and greater left and upper edgeif(Left()<rRect.Left())Left(rRect.Left());if(Top()<rRect.Top())Top(rRect.Top());longn=rRect.Right();if(Right()>n)Right(n);n=rRect.Bottom();if(Bottom()>n)Bottom(n);}else// Def.: if intersection is empty, set only SSize to 0SSize(0,0);return*this;}SwRect&SwRect::Intersection_(constSwRect&rRect){// get smaller right and lower, and greater left and upper edgeif(Left()<rRect.Left())Left(rRect.Left());if(Top()<rRect.Top())Top(rRect.Top());longn=rRect.Right();if(Right()>n)Right(n);n=rRect.Bottom();if(Bottom()>n)Bottom(n);return*this;}boolSwRect::IsInside(constSwRect&rRect)const{constlongnRight=Right();constlongnBottom=Bottom();constlongnrRight=rRect.Right();constlongnrBottom=rRect.Bottom();return(Left()<=rRect.Left())&&(rRect.Left()<=nRight)&&(Left()<=nrRight)&&(nrRight<=nRight)&&(Top()<=rRect.Top())&&(rRect.Top()<=nBottom)&&(Top()<=nrBottom)&&(nrBottom<=nBottom);}boolSwRect::IsInside(constPoint&rPoint)const{return(Left()<=rPoint.X())&&(Top()<=rPoint.Y())&&(Right()>=rPoint.X())&&(Bottom()>=rPoint.Y());}// mouse moving of table bordersboolSwRect::IsNear(constPoint&rPoint,longnTolerance)const{boolbIsNearby=(((Left()-nTolerance)<=rPoint.X())&&((Top()-nTolerance)<=rPoint.Y())&&((Right()+nTolerance)>=rPoint.X())&&((Bottom()+nTolerance)>=rPoint.Y()));returnIsInside(rPoint)||bIsNearby;}boolSwRect::IsOver(constSwRect&rRect)const{return(Top()<=rRect.Bottom())&&(Left()<=rRect.Right())&&(Right()>=rRect.Left())&&(Bottom()>=rRect.Top());}voidSwRect::Justify(){if(m_Size.getHeight()<0){m_Point.setY(m_Point.getY()+m_Size.getHeight()+1);m_Size.setHeight(-m_Size.getHeight());}if(m_Size.getWidth()<0){m_Point.setX(m_Point.getX()+m_Size.getWidth()+1);m_Size.setWidth(-m_Size.getWidth());}}// Similar to the inline methods, but we need the function pointersvoidSwRect::Width_(constlongnNew){m_Size.setWidth(nNew);}voidSwRect::Height_(constlongnNew){m_Size.setHeight(nNew);}voidSwRect::Left_(constlongnLeft){m_Size.AdjustWidth(m_Point.getX()-nLeft);m_Point.setX(nLeft);}voidSwRect::Right_(constlongnRight){m_Size.setWidth(nRight-m_Point.getX());}voidSwRect::Top_(constlongnTop){m_Size.AdjustHeight(m_Point.getY()-nTop);m_Point.setY(nTop);}voidSwRect::Bottom_(constlongnBottom){m_Size.setHeight(nBottom-m_Point.getY());}longSwRect::Width_()const{returnm_Size.getWidth();}longSwRect::Height_()const{returnm_Size.getHeight();}longSwRect::Left_()const{returnm_Point.getX();}longSwRect::Right_()const{returnm_Point.getX()+m_Size.getWidth();}longSwRect::Top_()const{returnm_Point.getY();}longSwRect::Bottom_()const{returnm_Point.getY()+m_Size.getHeight();}voidSwRect::AddWidth(constlongnAdd){m_Size.AdjustWidth(nAdd);}voidSwRect::AddHeight(constlongnAdd){m_Size.AdjustHeight(nAdd);}voidSwRect::SubLeft(constlongnSub){m_Size.AdjustWidth(nSub);m_Point.setX(m_Point.getX()-nSub);}voidSwRect::AddRight(constlongnAdd){m_Size.AdjustWidth(nAdd);}voidSwRect::SubTop(constlongnSub){m_Size.AdjustHeight(nSub);m_Point.setY(m_Point.getY()-nSub);}voidSwRect::AddBottom(constlongnAdd){m_Size.AdjustHeight(nAdd);}voidSwRect::SetPosX(constlongnNew){m_Point.setX(nNew);}voidSwRect::SetPosY(constlongnNew){m_Point.setY(nNew);}SizeSwRect::Size_()const{returnSSize();}SizeSwRect::SwappedSize()const{returnSize(m_Size.getHeight(),m_Size.getWidth());}PointSwRect::TopLeft()const{returnPos();}PointSwRect::TopRight()const{returnPoint(m_Point.getX()+m_Size.getWidth(),m_Point.getY());}PointSwRect::BottomLeft()const{returnPoint(m_Point.getX(),m_Point.getY()+m_Size.getHeight());}PointSwRect::BottomRight()const{returnPoint(m_Point.getX()+m_Size.getWidth(),m_Point.getY()+m_Size.getHeight());}longSwRect::GetLeftDistance(longnLimit)const{returnm_Point.getX()-nLimit;}longSwRect::GetBottomDistance(longnLim)const{returnnLim-m_Point.getY()-m_Size.getHeight();}longSwRect::GetTopDistance(longnLimit)const{returnm_Point.getY()-nLimit;}longSwRect::GetRightDistance(longnLim)const{returnnLim-m_Point.getX()-m_Size.getWidth();}boolSwRect::OverStepLeft(longnLimit)const{returnnLimit>m_Point.getX()&&m_Point.getX()+m_Size.getWidth()>nLimit;}boolSwRect::OverStepBottom(longnLimit)const{returnnLimit>m_Point.getY()&&m_Point.getY()+m_Size.getHeight()>nLimit;}boolSwRect::OverStepTop(longnLimit)const{returnnLimit>m_Point.getY()&&m_Point.getY()+m_Size.getHeight()>nLimit;}boolSwRect::OverStepRight(longnLimit)const{returnnLimit>m_Point.getX()&&m_Point.getX()+m_Size.getWidth()>nLimit;}voidSwRect::SetLeftAndWidth(longnLeft,longnNew){m_Point.setX(nLeft);m_Size.setWidth(nNew);}voidSwRect::SetTopAndHeight(longnTop,longnNew){m_Point.setY(nTop);m_Size.setHeight(nNew);}voidSwRect::SetRightAndWidth(longnRight,longnNew){m_Point.setX(nRight-nNew);m_Size.setWidth(nNew);}voidSwRect::SetBottomAndHeight(longnBottom,longnNew){m_Point.setY(nBottom-nNew);m_Size.setHeight(nNew);}voidSwRect::SetUpperLeftCorner(constPoint&rNew){m_Point=rNew;}voidSwRect::SetUpperRightCorner(constPoint&rNew){m_Point=Point(rNew.X()-m_Size.getWidth(),rNew.Y());}voidSwRect::SetLowerLeftCorner(constPoint&rNew){m_Point=Point(rNew.X(),rNew.Y()-m_Size.getHeight());}#ifdef DBG_UTILSvStream&WriteSwRect(SvStream&rStream,constSwRect&rRect)<--- The function 'WriteSwRect' is never used.{rStream.WriteChar('[').WriteInt32(rRect.Top()).WriteChar('/').WriteInt32(rRect.Left()).WriteChar(',').WriteInt32(rRect.Width()).WriteChar('x').WriteInt32(rRect.Height()).WriteCharPtr("] ");returnrStream;}#endif/* vim:set shiftwidth=4 softtabstop=4 expandtab: */