Click here to Skip to main content
15,893,381 members
Articles / Desktop Programming / MFC

SolidGraph CAD System

Rate me:
Please Sign up or sign in to vote.
4.97/5 (78 votes)
12 Sep 20062 min read 375.7K   29.8K   209  
A SolidGraph CAD system source code.
// SyntaxColorizer.h: interface for the CSyntaxColorizer class.
//
// Version:	1.0.0
// Author:	Jeff Schering jeffschering@hotmail.com
// Date:	Jan 2001
// Copyright 2001 by Jeff Schering
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_SYNTAXCOLORIZER_H__5C50E421_E4AC_11D4_A61E_60A459C10100__INCLUDED_)
#define AFX_SYNTAXCOLORIZER_H__5C50E421_E4AC_11D4_A61E_60A459C10100__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define CLR_STRING	RGB(55,0,200)
#define CLR_PLAIN	RGB(0,0,0)
#define CLR_COMMENT RGB(0,170,0)
#define CLR_KEYWORD RGB(0,0,255)
#define GRP_KEYWORD		0

class CSyntaxColorizer  
{
public:
	CSyntaxColorizer();
	virtual ~CSyntaxColorizer();

//protected vars
protected:
	unsigned char *m_pTableZero, *m_pTableOne;
	unsigned char *m_pTableTwo,  *m_pTableThree;
	unsigned char *m_pTableFour, *m_pAllowable;

	enum Types
	{
		SKIP,
		DQSTART,	//Double Quotes start
		DQEND,		//Double Quotes end
		SQSTART,	//Single Quotes start
		SQEND,		//Single Quotes end
		CMSTART,	//Comment start (both single and multi line)
		SLEND,		//Single line comment end
		MLEND,		//Multi line comment end
		KEYWORD		//Keyword start
	} m_type;

	struct SKeyword 
	{
		char* keyword;
		int  keylen;
		CHARFORMAT cf;
		int group;
		SKeyword* pNext;
		SKeyword() { pNext = NULL; }
	};

	SKeyword*	m_pskKeyword;
	CHARFORMAT	m_cfComment;
	CHARFORMAT	m_cfString;
	CHARFORMAT	m_cfDefault;

//protected member functions
protected:
	void addKey(LPCTSTR Keyword, CHARFORMAT cf, int grp);
	void createTables();
	void deleteTables();
	void createDefaultKeywordList();
	void createDefaultCharFormat();
	void colorize(LPTSTR lpszBuf, CRichEditCtrl *pCtrl, long iOffset = 0);

//public member functions
public:
	void Colorize(long StartChar, long nEndChar, CRichEditCtrl *pCtrl);
	void Colorize(CHARRANGE cr, CRichEditCtrl *pCtrl);

	void GetCommentStyle(CHARFORMAT &cf) { cf = m_cfComment; };
	void GetStringStyle(CHARFORMAT &cf) { cf = m_cfString; };
	void GetGroupStyle(int grp, CHARFORMAT &cf);
	void GetDefaultStyle(CHARFORMAT &cf) { cf = m_cfDefault; };

	void SetCommentStyle(CHARFORMAT cf) { m_cfComment = cf; };
	void SetCommentColor(COLORREF cr);
	void SetStringStyle(CHARFORMAT cf) { m_cfString = cf; };
	void SetStringColor(COLORREF cr);
	void SetGroupStyle(int grp, CHARFORMAT cf);
	void SetGroupColor(int grp, COLORREF cr);
	void SetDefaultStyle(CHARFORMAT cf) { m_cfDefault = cf; };

	void AddKeyword(LPCTSTR Keyword, CHARFORMAT cf, int grp = 0); 
	void AddKeyword(LPCTSTR Keyword, COLORREF cr, int grp = 0);
	void ClearKeywordList();
	CString GetKeywordList();
	CString GetKeywordList(int grp);
};

#endif // !defined(AFX_SYNTAXCOLORIZER_H__5C50E421_E4AC_11D4_A61E_60A459C10100__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions