#ifndef _COMMON_RICHEDIT_HPP_
#define _COMMON_RICHEDIT_HPP_
#ifndef _COMMON_CONTROL_HPP_
#include <common/control.hpp>
#endif
#ifndef _COMMON_RICHED_HPP_
#include <common/riched.hpp>
#endif

#ifndef _COMMON_FINDTEXTEX_HPP_
#include <common/fndtextx.hpp>
#endif

class Font;
class RGBColor;

class RichEditControl : public Control
{
public:
  enum ScrollAction{ScrollLineDown=SB_LINEDOWN,ScrollLineUp=SB_LINEUP,ScrollPageDown=SB_PAGEDOWN,ScrollPageUp=SB_PAGEUP};
  RichEditControl(void);
	RichEditControl(HWND hControlWnd,BOOL destroyWindow=TRUE);
	virtual ~RichEditControl();
	BOOL createControl(GUIWindow &parentWnd,const Rect &initRect,UINT controlID,UINT styles=0);
  BOOL setTextColor(const RGBColor &textColor)const;
	BOOL setBkGndColor(const RGBColor &bkGndColor)const;
	BOOL wantReturn(BOOL wantReturn)const;
	BOOL setFont(const Font &someFont)const;
  BOOL setCharFormat(const String faceName,int charHeight)const;
	BOOL limitText(DWORD cchMax)const;
	BOOL setReadOnly(BOOL isReadOnly)const;
	BOOL getLines(Block<String> &strLines);
  BOOL getSelectedText(String &strText)const;
  BOOL selectLine(int line)const;
	BOOL setLine(int line,const String &strLine)const;
	BOOL findText(FindTextEx &findTextEx,BOOL matchCase=TRUE,BOOL wholeWord=TRUE);
	BOOL scrollCaret(void)const;
	BOOL scrollLine(int cyScroll=1)const;
	BOOL scroll(ScrollAction scrollAction)const;
	BOOL isDirty(void)const;
	BOOL replaceSelection(const String &strReplacementText,BOOL canUndo=TRUE)const;
	BOOL cutSelection(BOOL canUndo=TRUE)const;
	BOOL pasteSpecial(UINT cbFormat)const;
	String getLine(int line)const;
	String getCurrentLine(void)const;
	int lineCount(void)const;
  int lineFromCharPos(int charPos);
	int currentLine(void)const;
	int firstVisibleLine(void)const;
	int charFromPos(const GDIPoint &cursorPoint);
  int getCaretPosition(void)const;
	void isDirty(BOOL isDirty)const;
	void setLimitRect(const Rect &limitRect)const;
	void getLimitRect(Rect &limitRect)const;
	void copyClipboard(void);
  void setCaption(Block<String> &codeLines)const;
	void setCaption(const String &strCaption)const;
protected:
	int lineIndex(int lineIndex=-1)const;
private:
  enum {MaxLine=4096,MaxText=128000};
  void loadLibrary(void);
	void freeLibrary(void);
	void getLogPixelsy(void);

	int mLogPixelsy;
  HINSTANCE mhLibInst;
};
#endif
