#ifndef _COMMON_CHARFORMAT_HPP_
#define _COMMON_CHARFORMAT_HPP_
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif
#ifndef _COMMON_RICHEDIT_HPP_
#include <common/richedit.hpp>
#endif
#ifndef _COMMON_STRING_HPP_
#include <common/string.hpp>
#endif
#ifndef _COMMON_RGBCOLOR_HPP_
#include <common/rgbcolor.hpp>
#endif

class CharFormat : private CHARFORMAT
{
public:
  enum Mask{MaskBold=CFM_BOLD,MaskCharSet=CFM_CHARSET,MaskColor=CFM_COLOR,MaskFace=CFM_FACE,
	          MaskItalic=CFM_ITALIC,MaskOffset=CFM_OFFSET,MaskProtected=CFM_PROTECTED,
						MaskSize=CFM_SIZE,MaskStrikeout=CFM_STRIKEOUT,MaskUnderline=CFM_UNDERLINE};
  enum Effects{EffectAutoColor=CFE_AUTOCOLOR,EffectBold=CFE_BOLD,EffectItalic=CFE_ITALIC,
	             EffectStrikeout=CFE_STRIKEOUT,EffectUnderline=CFE_UNDERLINE,EffectProtected=CFE_PROTECTED};
  CharFormat(void);
	CharFormat(const CharFormat &someCharFormat);
	virtual ~CharFormat();
	CharFormat &operator=(const CharFormat &someCharFormat);
	BOOL operator==(const CharFormat &someCharFormat)const;
	operator CHARFORMAT &(void);
	DWORD mask(void)const;
	void mask(DWORD mask);
	DWORD effects(void)const;
	void effects(DWORD effects);
	LONG yHeight(void)const;
	void yHeight(LONG height);
	LONG yOffset(void)const;
	void yOffset(LONG offset);
	RGBColor textColor(void)const;
	void textColor(RGBColor textColor);
	BYTE charSet(void)const;
	void charSet(BYTE charSet);
	BYTE pitchAndFamily(void)const;
	void pitchAndFamily(BYTE pitchAndFamily);
	String faceName(void)const;
	void faceName(const String &faceName);
private:
  void setZero(void);
	void initLength(void);
};
#endif

inline
CharFormat::CharFormat(void)
{
  setZero();
}

inline
CharFormat::CharFormat(const CharFormat &someCharFormat)
{
 initLength();
 *this=someCharFormat;
}

inline
CharFormat::~CharFormat()
{
}

inline
CharFormat &CharFormat::operator=(const CharFormat &someCharFormat)
{
  mask(someCharFormat.mask());
	effects(someCharFormat.effects());
	yHeight(someCharFormat.yHeight());
	yOffset(someCharFormat.yOffset());
	textColor(someCharFormat.textColor());
	charSet(someCharFormat.charSet());
	pitchAndFamily(someCharFormat.pitchAndFamily());
	faceName(someCharFormat.faceName());
	return *this;
}

inline
BOOL CharFormat::operator==(const CharFormat &someCharFormat)const
{
  return (mask()==someCharFormat.mask()&&
	        effects()==someCharFormat.effects()&&
	        yHeight()==someCharFormat.yHeight()&&
	        yOffset()==someCharFormat.yOffset()&&
	        textColor()==someCharFormat.textColor()&&
	        charSet()==someCharFormat.charSet()&&
	        pitchAndFamily()&&someCharFormat.pitchAndFamily()&&
	        faceName()==someCharFormat.faceName());
}

inline
CharFormat::operator CHARFORMAT &(void)
{
  return *this;
}

inline
DWORD CharFormat::mask(void)const
{
  return CHARFORMAT::dwMask;
}

inline
void CharFormat::mask(DWORD mask)
{
  CHARFORMAT::dwMask=mask;
}

inline
DWORD CharFormat::effects(void)const
{
  return CHARFORMAT::dwEffects;
}

inline
void CharFormat::effects(DWORD effects)
{
  CHARFORMAT::dwEffects=effects;
}

inline
LONG CharFormat::yHeight(void)const
{
  return CHARFORMAT::yHeight;
}

inline
void CharFormat::yHeight(LONG height)
{
  CHARFORMAT::yHeight=height;
}

inline
LONG CharFormat::yOffset(void)const
{
  return CHARFORMAT::yOffset;
}

inline
void CharFormat::yOffset(LONG yOffset)
{
  CHARFORMAT::yOffset=yOffset;
}

inline
RGBColor CharFormat::textColor(void)const
{
  return CHARFORMAT::crTextColor;
}

inline
void CharFormat::textColor(RGBColor textColor)
{
  CHARFORMAT::crTextColor=(COLORREF)textColor;
}

inline
BYTE CharFormat::charSet(void)const
{
  return CHARFORMAT::bCharSet;
}

inline
void CharFormat::charSet(BYTE charSet)
{
  CHARFORMAT::bCharSet=charSet;
}

inline
BYTE CharFormat::pitchAndFamily(void)const
{
  return CHARFORMAT::bPitchAndFamily;
}

inline
void CharFormat::pitchAndFamily(BYTE pitchAndFamily)
{
  CHARFORMAT::bPitchAndFamily=pitchAndFamily;
}

inline
String CharFormat::faceName(void)const
{
  return CHARFORMAT::szFaceName;
}

inline
void CharFormat::faceName(const String &faceName)
{
  WORD strLength(faceName.length());
  if(faceName.isNull()||strLength>=LF_FACESIZE)return;
	::memcpy(szFaceName,(char*)(String&)faceName,strLength);
	szFaceName[strLength]=0;
}

inline
void CharFormat::setZero(void)
{
  initLength();
 	mask(0);
	effects(0);
	yHeight(0);
	yOffset(0);
	textColor(RGBColor(0,0,0));
	charSet(0);
	pitchAndFamily(0);
	faceName("Arial");
}

inline
void CharFormat::initLength(void)
{
 CHARFORMAT::cbSize=sizeof(CHARFORMAT);
}
