#ifndef _gdiPEN_
#define _gdiPEN_
/*<<<***************************************************************************
The MIT License (MIT)

Copyright(C) 2013 - 2015 Marc Mirti Mancinelli, Christophe Lardau and Philippe Pamart (xdcube.org)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
////////////////////////////////////////////////////////////////////////////////
#Title: gdiPen
#Project: xdcGdi
////////////////////////////////////////////////////////////////////////////////
#Author: Marc MIRTI MANCINELLI
#History:
<10/09/2013: creation.
12/02/2014: this notice inserted.
***************************************************************************>>>*/

#ifndef _gdiBASE_
#	include "gdiBase.h"
#endif

enum gdiPenStyleMode
{
	gdiPenStyle_Solid = PS_SOLID, //The pen is solid.
	gdiPenStyle_Dash = PS_DASH, //The pen is dashed. This style is valid only when the pen width is one or less in device units.
	gdiPenStyle_Dot = PS_DOT, //The pen is dotted. This style is valid only when the pen width is one or less in device units.
	gdiPenStyle_DashDot = PS_DASHDOT, //The pen has alternating dashes and dots. This style is valid only when the pen width is one or less in device units.
	gdiPenStyle_DashDotDot = PS_DASHDOTDOT, //The pen has alternating dashes and double dots. This style is valid only when the pen width is one or less in device units.
	gdiPenStyle_Null = PS_NULL, //The pen is invisible.
	gdiPenStyle_InsideFrame = PS_INSIDEFRAME //The pen is solid. When this pen is used in any GDI drawing function that takes a bounding rectangle, the dimensions of the figure are shrunk so that it fits entirely in the bounding rectangle, taking into account the width of the pen. This applies only to geometric pens.
};

class gdiEXPORT gdiPen
{
public:
	gdiPen(const gdiColor &clr,int width = 1,gdiPenStyleMode style = gdiPenStyle_Solid)
		:m_clr(clr),m_width(width),m_style(style)
	{
	}
	gdiPen()
		:m_width(1),m_style(gdiPenStyle_Solid)
	{
	}
	void Init(const gdiColor &clr,int width = 1,gdiPenStyleMode style = gdiPenStyle_Solid)
	{
		penDestroy();
		m_clr = clr;
		m_width = width;
		m_style = style;
	}
	HPEN GetHandle() const {if (m_hPen==NULL) penCreate();return m_hPen;}

	~gdiPen()
	{
		penDestroy();
		
	}
protected:
	void penCreate() const
	{
		if (m_hPen != NULL)
			return;
		HPEN hPen = ::CreatePen((int)m_style,m_width,m_clr.GetRGB());
		if (hPen == NULL)
			gdiEsys::Throw(xbHR_LAST,"gdiPen::penCreate() failure");
		m_hPen = hPen;
	}
	void penDestroy()
	{
		if (m_hPen == NULL)
			return;
		::DeleteObject(m_hPen);
		m_hPen = NULL;
	}
	gdiPenStyleMode m_style;
	int				m_width;
	gdiColor		m_clr;
	mutable HPEN	m_hPen;
private:
	xbDclNoNewForObject(gdiPen);
	xbDclNoCopyForObject(gdiPen);
};


#endif
