#ifndef _COMMON_PEN_HPP_
#define _COMMON_PEN_HPP_
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif
#ifndef _COMMON_RGBCOLOR_HPP_
#include <common/rgbcolor.hpp>
#endif

class Pen
{
public:
	enum{DefaultWidth=1};
	enum PenStyle{PSolid=PS_SOLID,PDash=PS_DASH,PDot=PS_DOT,PDashDot=PS_DASHDOT,PDashDotDot=PS_DASHDOTDOT,PNull=PS_NULL,PInsideFrame=PS_INSIDEFRAME};
	Pen(void);
	Pen(HPEN somePen);
	Pen(const Pen &somePen);
	Pen(const RGBColor &someRGBColor,PenStyle penStyle=PSolid,short penWidth=DefaultWidth);
	Pen(const RGBColor &someRGBColor,short penWidth);
	~Pen();
	void color(const RGBColor &someRGBColor);
	const RGBColor &color(void)const;
	operator HPEN(void)const;
private:
	enum Disposition{DeletePen,AssumePen,InvalidPen};
	Pen &operator=(const Pen &somePen);
  WORD operator==(const Pen &somePen);
	HPEN  mhPen;
	RGBColor mColor;
	Disposition mDisposition;
};

inline
Pen::Pen(void)
: mhPen(::CreatePen(PS_SOLID,DefaultWidth,RGBColor(0,0,0))), mDisposition(DeletePen)
{
}

inline
Pen::Pen(HPEN somePen)
: mhPen(somePen), mDisposition(AssumePen)
{
}

inline
Pen::Pen(const Pen &somePen)
: mhPen(::CreatePen(PS_SOLID,DefaultWidth,somePen.mColor)), mColor(somePen.mColor),
	mDisposition(DeletePen)
{
}

inline
Pen::Pen(const RGBColor &someRGBColor,PenStyle penStyle,short penWidth)
: mhPen(::CreatePen(penStyle,penWidth,(COLORREF)someRGBColor)), mColor(someRGBColor),
	mDisposition(DeletePen)
{
}

inline
Pen::Pen(const RGBColor &someRGBColor,short penWidth)
: mhPen(::CreatePen(PSolid,penWidth,(COLORREF)someRGBColor)), mColor(someRGBColor),
  mDisposition(DeletePen)
{
}

inline
Pen::~Pen()
{
	if(mhPen&&DeletePen==mDisposition)::DeleteObject(mhPen);
}

inline
void Pen::color(const RGBColor &someRGBColor)
{
	if(mhPen)::DeleteObject(mhPen);
	mhPen=::CreatePen(PS_SOLID,DefaultWidth,(COLORREF)someRGBColor);
	mDisposition=DeletePen;
	mColor=someRGBColor;
}

inline
const RGBColor &Pen::color(void)const
{
	return mColor;
}

inline
Pen::operator HPEN(void)const
{
	return mhPen;
}

inline
Pen &Pen::operator=(const Pen &/*somePen*/)
{
  return *this;
}

inline
WORD Pen::operator==(const Pen &/*somePen*/)
{
	return FALSE;
}
#endif
