#ifndef _COMMON_OWNERDRAWBUTTON_HPP_
#define _COMMON_OWNERDRAWBUTTON_HPP_
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif
#ifndef _COMMON_CONTROL_HPP_
#include <common/control.hpp>
#endif
#ifndef _COMMON_STRING_HPP_
#include <common/string.hpp>
#endif
#ifndef _COMMON_RESBITMAP_HPP_
#include <common/resbmp.hpp>
#endif
#ifndef _COMMON_SMARTPOINTER_HPP_
#include <common/pointer.hpp>
#endif
#ifndef _COMMON_FONT_HPP_
#include <common/font.hpp>
#endif

class DrawItem;
class MeasureItem;
class PureDevice;
class DIBitmap;

class OwnerDrawButton : public Control
{
public:
  OwnerDrawButton(GUIWindow &parentWnd,HWND hControlWnd,UINT controlID,const String &strBmFocusUp,const String &strBmFocusDown,const String &strBmNoFocusUp,const String &strBmDisabled,BOOL hasButtonLines=TRUE,Font textFont=Font("MS Sans Serif",8,Font::FamilySwiss|Font::PitchVariable,Font::WeightBold));
	OwnerDrawButton(GUIWindow &parentWnd,const Point &initPoint,UINT controlID,const String &strBmFocusUp,const String &strBmFocusDown,const String &strBmNoFocusUp,const String &strBmDisabled,BOOL hasButtonLines=TRUE,const String &strLabel=String(),Font textFont=Font("MS Sans Serif",8,Font::FamilySwiss|Font::PitchVariable,Font::WeightBold),DWORD style=BS_OWNERDRAW|WS_CLIPCHILDREN|WS_CLIPSIBLINGS);
	OwnerDrawButton(GUIWindow &parentWnd,const Rect &initRect,UINT controlID,const String &strBmFocusUp,const String &strBmFocusDown,const String &strBmNoFocusUp,const String &strBmDisabled,BOOL hasButtonLines=TRUE,const String &strLabel=String(),Font textFont=Font("MS Sans Serif",8,Font::FamilySwiss|Font::PitchVariable,Font::WeightBold),DWORD style=BS_OWNERDRAW|WS_CLIPCHILDREN|WS_CLIPSIBLINGS);
	virtual ~OwnerDrawButton();
	OwnerDrawButton &operator=(const OwnerDrawButton &someOwnerDrawButton);
	const Point &initPoint(void)const;
	BOOL hasButtonLines(void)const;
	void hasButtonLines(BOOL hasButtonLines);
	void textColor(const RGBColor &rgbColor);
	RGBColor textColor(void)const;
protected:
  virtual WORD handleDraw(const DrawItem &drawItem);
	virtual WORD handleMeasureItem(MeasureItem &measureItem);
	virtual LPARAM handleControlColor(PureDevice &pureDevice,Control &wndButton);
	virtual void drawEntire(const DrawItem &drawItem);
	virtual WORD drawSelect(const DrawItem &drawItem);
	virtual void drawFocus(const DrawItem &drawItem);
	virtual void drawButtonText(const DrawItem &drawItem);
	virtual void drawButtonLines(const DrawItem &drawItem);
private:
  void drawBitmap(const DrawItem &drawItem,ResBitmap &resBitmap);
  CallbackData::ReturnType drawItemHandler(CallbackData &someCallbackData);
	CallbackData::ReturnType controlColorHandler(CallbackData &someCallbackData);

	Callback<OwnerDrawButton> mDrawItemHandler;
	Callback<OwnerDrawButton> mMeasureItemHandler;
	Callback<OwnerDrawButton> mControlColorHandler;
	SmartPointer<DIBitmap> mDIBitmap;
	ResBitmap mBmFocusDown;
	ResBitmap mBmNoFocusUp;
  ResBitmap mBmDisabled;
	ResBitmap mBmFocusUp;
	GUIWindow &mParentWnd;
	Point mInitPoint;
	HBRUSH mhBkGndBrush;
	RGBColor mTextColor;
	BOOL mHasButtonLines;
	Font mTextFont;
};

inline
const Point &OwnerDrawButton::initPoint(void)const
{
  return mInitPoint;
}

inline
void OwnerDrawButton::textColor(const RGBColor &rgbColor)
{
  mTextColor=rgbColor;
}

inline
RGBColor OwnerDrawButton::textColor(void)const
{
  return mTextColor;
}

inline
BOOL OwnerDrawButton::hasButtonLines(void)const
{
  return mHasButtonLines;
}

inline
void OwnerDrawButton::hasButtonLines(BOOL hasButtonLines)
{
  mHasButtonLines=hasButtonLines;
}
#endif
