#pragma once
#include "SynLanguage.h"
#include "XmlOutlineParser.h"
#include "KofFile.h"

static const DWORD g_dwUATComment		= 0x80000;
static const DWORD g_dwUATUncomment		= 0x100000;
static const DWORD g_dwUATFormatter		= 0x200000;

class CSynBCGPEditCtrl : public CBCGPEditCtrl
{
	DECLARE_DYNAMIC(CSynBCGPEditCtrl)
public:
	CSynBCGPEditCtrl();
	virtual ~CSynBCGPEditCtrl();

	void UseXmlParser (BOOL bXmlParser = TRUE)
	{
		((CXmlOutlineParser*)m_pOutlineParser)->EnableXmlParser (bXmlParser);
	}
	virtual CBCGPOutlineParser* CreateOutlineParser () const
	{
		return new CXmlOutlineParser;
	}

public:
	BOOL m_bCheckColorTags;	// TRUE if check for tags (<....>) in "OnGetCharColor"
	
	/**
	 * ѡ
	 * @param UINT nLanguage ID
	 * @return void 
	 */
	void SelectLanguage(UINT nLanguage);
	
	/**
	 * ݺ׺ѡ
	 * @param CString strExt ׺
	 */
	void SelectLanguageByExt(CString strExt);
	
	/**
	 * ȡַ
	 * @return LPCTSTR 
	 */
	LPCTSTR GetSelectLangString();

	/**
	* ôҳ
	* @param UINT nCodepage ҳ
	*/
	void SelectEncoding(UINT nCodepage);

	/**
	* ȡҳַ
	* @return LPCTSTR
	*/
	LPCTSTR GetSelectEncodingString();

	COLORREF m_clrSyn;		//﷨ɫ
	COLORREF m_clrType;		//ɫ
	COLORREF m_clrNumber;	//ɫ
	COLORREF m_clrString;	//ַɫ
	COLORREF m_clrChar;		//ַɫ
	COLORREF m_clrComment;	//עɫ

	
	/**
	 * ر༭ɫ
	 * @param BOOL bRedraw Ƿػ
	 * @return void 
	 */
	void LoadColor(BOOL bRedraw = FALSE);
	
	/**
	 * ļ
	 * @param const CString & strFileName ļ
	 * @return BOOL Ƿɹ
	 */
	BOOL OpenFileEx(const CString& strFileName);
	
	/**
	 * ļ
	 * @param const CString & strFileName ļ
	 * @return BOOL Ƿɹ
	 */
	BOOL SaveFileEx(const CString& strFileName);
	
	/**
	 * չHTML
	 * @param CString & strBuffer HTMLַ
	 * @return void 
	 */
	void ExportToMyHTML(CString& strBuffer);	
	
	/**
	 * 루ȡע
	 * @param BOOL bForward 뻹ȡ
	 * @return void 
	 */
	void InsertComment(BOOL bForward);
	
	/**
	 * 滻Ϊʽ
	 * @param BOOL bAllText Ƿȫıʽ
	 * @return void 
	 */
	void ReplaceTextToFormatter(BOOL bAllText = TRUE);

protected:
	CSynLanguage m_SynLanguage;
	BOOL m_bNumberColor;
	CKofFile m_File;
	void OnGetCharColor (TCHAR ch, int nOffset, COLORREF& clrText, COLORREF& clrBk);
	BOOL OnGetWordColor (const CString& strWord, COLORREF& clrText, COLORREF& clrBk, int nPos);	
	DECLARE_MESSAGE_MAP()

public:
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnSysColorChange();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
};