SyntaxColorizer.h
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 3k
Category:

Graph program

Development Platform:

Visual C++

  1. // SyntaxColorizer.h: interface for the CSyntaxColorizer class.
  2. //
  3. // Version: 1.0.0
  4. // Author: Jeff Schering jeffschering@hotmail.com
  5. // Date: Jan 2001
  6. // Copyright 2001 by Jeff Schering
  7. //
  8. //////////////////////////////////////////////////////////////////////
  9. #if !defined(AFX_SYNTAXCOLORIZER_H__5C50E421_E4AC_11D4_A61E_60A459C10100__INCLUDED_)
  10. #define AFX_SYNTAXCOLORIZER_H__5C50E421_E4AC_11D4_A61E_60A459C10100__INCLUDED_
  11. #if _MSC_VER > 1000
  12. #pragma once
  13. #endif // _MSC_VER > 1000
  14. #define CLR_STRING RGB(55,0,200)
  15. #define CLR_PLAIN RGB(0,0,0)
  16. #define CLR_COMMENT RGB(0,170,0)
  17. #define CLR_KEYWORD RGB(0,0,255)
  18. #define GRP_KEYWORD 0
  19. class CSyntaxColorizer  
  20. {
  21. public:
  22. CSyntaxColorizer();
  23. virtual ~CSyntaxColorizer();
  24. //protected vars
  25. protected:
  26. unsigned char *m_pTableZero, *m_pTableOne;
  27. unsigned char *m_pTableTwo,  *m_pTableThree;
  28. unsigned char *m_pTableFour, *m_pAllowable;
  29. enum Types
  30. {
  31. SKIP,
  32. DQSTART, //Double Quotes start
  33. DQEND, //Double Quotes end
  34. SQSTART, //Single Quotes start
  35. SQEND, //Single Quotes end
  36. CMSTART, //Comment start (both single and multi line)
  37. SLEND, //Single line comment end
  38. MLEND, //Multi line comment end
  39. KEYWORD //Keyword start
  40. } m_type;
  41. struct SKeyword 
  42. {
  43. char* keyword;
  44. int  keylen;
  45. CHARFORMAT cf;
  46. int group;
  47. SKeyword* pNext;
  48. SKeyword() { pNext = NULL; }
  49. };
  50. SKeyword* m_pskKeyword;
  51. CHARFORMAT m_cfComment;
  52. CHARFORMAT m_cfString;
  53. CHARFORMAT m_cfDefault;
  54. //protected member functions
  55. protected:
  56. void addKey(LPCTSTR Keyword, CHARFORMAT cf, int grp);
  57. void createTables();
  58. void deleteTables();
  59. void createDefaultKeywordList();
  60. void createDefaultCharFormat();
  61. void colorize(LPTSTR lpszBuf, CRichEditCtrl *pCtrl, long iOffset = 0);
  62. //public member functions
  63. public:
  64. void Colorize(long StartChar, long nEndChar, CRichEditCtrl *pCtrl);
  65. void Colorize(CHARRANGE cr, CRichEditCtrl *pCtrl);
  66. void GetCommentStyle(CHARFORMAT &cf) { cf = m_cfComment; };
  67. void GetStringStyle(CHARFORMAT &cf) { cf = m_cfString; };
  68. void GetGroupStyle(int grp, CHARFORMAT &cf);
  69. void GetDefaultStyle(CHARFORMAT &cf) { cf = m_cfDefault; };
  70. void SetCommentStyle(CHARFORMAT cf) { m_cfComment = cf; };
  71. void SetCommentColor(COLORREF cr);
  72. void SetStringStyle(CHARFORMAT cf) { m_cfString = cf; };
  73. void SetStringColor(COLORREF cr);
  74. void SetGroupStyle(int grp, CHARFORMAT cf);
  75. void SetGroupColor(int grp, COLORREF cr);
  76. void SetDefaultStyle(CHARFORMAT cf) { m_cfDefault = cf; };
  77. void AddKeyword(LPCTSTR Keyword, CHARFORMAT cf, int grp = 0); 
  78. void AddKeyword(LPCTSTR Keyword, COLORREF cr, int grp = 0);
  79. void ClearKeywordList();
  80. CString GetKeywordList();
  81. CString GetKeywordList(int grp);
  82. };
  83. #endif // !defined(AFX_SYNTAXCOLORIZER_H__5C50E421_E4AC_11D4_A61E_60A459C10100__INCLUDED_)