#ifndef _COMMON_RECTANGLE_HPP_
#define _COMMON_RECTANGLE_HPP_
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif
#ifndef _COMMON_POINT_HPP_
#include <common/point.hpp>
#endif
#ifndef _COMMON_GDIPOINT_HPP_
#include <common/gdipoint.hpp>
#endif
#ifndef _COMMON_STRING_HPP_
#include <common/string.hpp>
#endif
#ifndef _COMMON_STDIO_HPP_
#include <common/stdio.hpp>
#endif

class Rect : private tagRECT
{
public:
	Rect(void);
	Rect(const RECT &someRECT);
	Rect(const Rect &someRect);
  Rect(LONG left,LONG top,LONG right,LONG bottom);
	~Rect();
	operator RECT &(void);
	operator RECT *(void);
	Rect &operator=(const Rect &someRect);
  WORD operator==(const Rect &someRect)const;
	BOOL ptInRect(const Point &point)const;
	BOOL ptInRect(const GDIPoint &point)const;
	BOOL ptOnRect(const Point &point)const;
  BOOL ptOnRect(const GDIPoint &point)const;
	LONG left(void)const;
	void left(LONG newLeft);
	LONG top(void)const;
	void top(LONG newTop);
	LONG right(void)const;
	void right(LONG newRight);
	LONG bottom(void)const;
	void bottom(LONG newBottom);
	LONG width(void)const;
	void width(LONG newWidth);
	LONG height(void)const;
  void height(LONG newHeight);
	tagRECT &getRect(void);
  String Rect::toString(void)const;
private:
};

inline
Rect::Rect(void)
{
	tagRECT::left=0;
	tagRECT::top=0;
	tagRECT::right=0;
  tagRECT::bottom=0;
}

inline
Rect::Rect(const Rect &someRect)
{
	tagRECT::left=someRect.left();
	tagRECT::top=someRect.top();
	tagRECT::right=someRect.right();
	tagRECT::bottom=someRect.bottom();
}

inline
Rect::Rect(const RECT &someRECT)
{
	tagRECT::left=someRECT.left;
	tagRECT::top=someRECT.top;
	tagRECT::right=someRECT.right;
	tagRECT::bottom=someRECT.bottom;
}

inline
Rect::Rect(LONG left,LONG top,LONG right,LONG bottom)
{
	tagRECT::left=left;
	tagRECT::top=top;
	tagRECT::right=right;
  tagRECT::bottom=bottom;
}

inline
Rect::~Rect()
{
}

inline
Rect::operator RECT &(void)
{
	return *this;
}

inline
Rect::operator RECT *(void)
{
	return this;
}

inline
BOOL Rect::ptInRect(const Point &point)const
{
  return ptInRect(GDIPoint(point.x(),point.y()));
}

inline
BOOL Rect::ptInRect(const GDIPoint &point)const
{
  RECT cRect=*this;
  return ::PtInRect(&cRect,((GDIPoint&)point).getPOINT());
}

inline
BOOL Rect::ptOnRect(const Point &point)const
{
  return ptOnRect(GDIPoint(point.x(),point.y()));
}

inline
BOOL Rect::ptOnRect(const GDIPoint &point)const
{
  if(point.x()==left()||point.x()==right())return TRUE;
	if(point.y()==top()||point.y()==bottom())return TRUE;
	return FALSE;
}

inline
LONG Rect::left(void)const
{
	return tagRECT::left;
}

inline
void Rect::left(LONG newLeft)
{
	tagRECT::left=newLeft;
}

inline
LONG Rect::top(void)const
{
	return tagRECT::top;
}

inline
void Rect::top(LONG newTop)
{
	tagRECT::top=newTop;
}

inline
LONG Rect::right(void)const
{
  return tagRECT::right;
}

inline
void Rect::right(LONG newRight)
{
  tagRECT::right=newRight;
}

inline
LONG Rect::bottom(void)const
{
  return tagRECT::bottom;
}

inline
void Rect::bottom(LONG newBottom)
{
  tagRECT::bottom=newBottom;
}

inline
LONG Rect::width(void)const
{
  return (tagRECT::right-tagRECT::left)+1;  
}

inline
void Rect::width(LONG newWidth)
{
  tagRECT::right=tagRECT::left+newWidth;
}

inline
LONG Rect::height(void)const
{
  return (tagRECT::bottom-tagRECT::top)+1;
}

inline
void Rect::height(LONG newHeight)
{
  tagRECT::bottom=tagRECT::top+newHeight;
}

inline
Rect &Rect::operator=(const Rect &someRect)
{
	tagRECT::left=someRect.left();
	tagRECT::top=someRect.top();
	tagRECT::right=someRect.right();
	tagRECT::bottom=someRect.bottom();
  return *this;
}

inline
WORD Rect::operator==(const Rect &someRect)const
{
	return(tagRECT::left==someRect.left()&&
				 tagRECT::top==someRect.top()&&
				 tagRECT::right==someRect.right()&&
	       tagRECT::bottom==someRect.bottom());
}

inline
tagRECT &Rect::getRect(void)
{
  return *this;
}

inline
String Rect::toString(void)const
{
  String strRect;
	::sprintf(strRect.str(),"(%d,%d,%d,%d)(%d,%d)",left(),top(),right(),bottom(),width(),height());
	return strRect;
}
#endif
