doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CSyntaxRichEditCtrl.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __CSYNTAXRICHEDITCTR_H__
30 #define __CSYNTAXRICHEDITCTR_H__
31 
32 /*
33 ===============================================================================
34 
35  Rich Edit Control with:
36 
37  - syntax highlighting
38  - braced section highlighting
39  - braced section auto-indentation
40  - multi-line tabs
41  - keyword auto-completion
42  - object member auto-completion
43  - keyword tool tip
44  - function parameter tool tip
45 
46 ===============================================================================
47 */
48 
49 // use #import on Vista to generate .tlh header to copy from intermediate compile directory to local directory for subsequent builds
50 // rename: avoids warning C4278: 'FindText': identifier in type library 'riched20.dll' is already a macro; use the 'rename' qualifier
51 // no_auto_exclude: avoids warnings
52 // no_namespace: no longer using this option, which avoids variable redifinition compile errors on Vista
53 //#define GENERATE_TLH
54 #ifdef GENERATE_TLH
55 # import "riched20.dll" raw_interfaces_only, raw_native_types, named_guids, no_auto_exclude, no_implementation, rename( "FindText", "FindShit" )
56 #else
57 # include "riched20.tlh"
58 #endif
59 
60 static const char * FONT_NAME = "Courier";
61 static const int FONT_HEIGHT = 10;
62 static const int FONT_WIDTH = 8;
63 static const int TAB_SIZE = 4;
64 
65 static const COLORREF SRE_COLOR_BLACK = RGB( 0, 0, 0 );
66 static const COLORREF SRE_COLOR_WHITE = RGB( 255, 255, 255 );
67 static const COLORREF SRE_COLOR_RED = RGB( 255, 0, 0 );
68 static const COLORREF SRE_COLOR_GREEN = RGB( 0, 255, 0 );
69 static const COLORREF SRE_COLOR_BLUE = RGB( 0, 0, 255 );
70 static const COLORREF SRE_COLOR_YELLOW = RGB( 255, 255, 0 );
71 static const COLORREF SRE_COLOR_MAGENTA = RGB( 255, 0, 255 );
72 static const COLORREF SRE_COLOR_CYAN = RGB( 0, 255, 255 );
73 static const COLORREF SRE_COLOR_ORANGE = RGB( 255, 128, 0 );
74 static const COLORREF SRE_COLOR_PURPLE = RGB( 150, 0, 150 );
75 static const COLORREF SRE_COLOR_PINK = RGB( 186, 102, 123 );
76 static const COLORREF SRE_COLOR_GREY = RGB( 85, 85, 85 );
77 static const COLORREF SRE_COLOR_BROWN = RGB( 100, 90, 20 );
78 static const COLORREF SRE_COLOR_LIGHT_GREY = RGB( 170, 170, 170 );
79 static const COLORREF SRE_COLOR_LIGHT_BROWN = RGB( 170, 150, 20 );
80 static const COLORREF SRE_COLOR_DARK_GREEN = RGB( 0, 128, 0 );
81 static const COLORREF SRE_COLOR_DARK_CYAN = RGB( 0, 150, 150 );
82 static const COLORREF SRE_COLOR_DARK_YELLOW = RGB( 220, 200, 20 );
83 
84 typedef struct {
85  const char * keyWord;
86  COLORREF color;
87  const char * description;
88 } keyWord_t;
89 
90 typedef bool (*objectMemberCallback_t)( const char *objectName, CListBox &listBox );
91 typedef bool (*toolTipCallback_t)( const char *name, CString &string );
92 
93 
94 class CSyntaxRichEditCtrl : public CRichEditCtrl {
95 public:
96  CSyntaxRichEditCtrl( void );
97  ~CSyntaxRichEditCtrl( void );
98 
99  void Init( void );
100 
101  void SetCaseSensitive( bool caseSensitive );
102  void AllowPathNames( bool allow );
103  void EnableKeyWordAutoCompletion( bool enable );
104  void SetKeyWords( const keyWord_t kws[] );
105  bool LoadKeyWordsFromFile( const char *fileName );
108  void SetToolTipCallback( toolTipCallback_t callback );
109 
110  void SetDefaultColor( const COLORREF color );
111  void SetCommentColor( const COLORREF color );
112  void SetStringColor( const COLORREF color, const COLORREF altColor = -1 );
113  void SetLiteralColor( const COLORREF color );
114 
115  COLORREF GetForeColor( int charIndex ) const;
116  COLORREF GetBackColor( int charIndex ) const;
117 
118  void GetCursorPos( int &line, int &column, int &character ) const;
119  CHARRANGE GetVisibleRange( void ) const;
120 
121  void GetText( idStr &text ) const;
122  void GetText( idStr &text, int startCharIndex, int endCharIndex ) const;
123  void SetText( const char *text );
124 
125  void GoToLine( int line );
126  bool FindNext( const char *find, bool matchCase, bool matchWholeWords, bool searchForward );
127  int ReplaceAll( const char *find, const char *replace, bool matchCase, bool matchWholeWords );
128  void ReplaceText( int startCharIndex, int endCharIndex, const char *replace );
129 
130 protected:
131  virtual int OnToolHitTest( CPoint point, TOOLINFO* pTI ) const;
132  afx_msg BOOL OnToolTipNotify( UINT id, NMHDR *pNMHDR, LRESULT *pResult );
133  afx_msg UINT OnGetDlgCode();
134  afx_msg void OnChar( UINT nChar, UINT nRepCnt, UINT nFlags );
135  afx_msg void OnKeyDown( UINT nKey, UINT nRepCnt, UINT nFlags );
136  afx_msg void OnLButtonDown( UINT nFlags, CPoint point );
137  afx_msg BOOL OnMouseWheel( UINT nFlags, short zDelta, CPoint pt );
138  afx_msg void OnMouseMove( UINT nFlags, CPoint point );
139  afx_msg void OnVScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar );
140  afx_msg void OnSize( UINT nType, int cx, int cy );
141  afx_msg void OnProtected( NMHDR *pNMHDR, LRESULT *pResult );
142  afx_msg void OnChange();
143  afx_msg void OnAutoCompleteListBoxChange();
144  afx_msg void OnAutoCompleteListBoxDblClk();
145 
146  DECLARE_MESSAGE_MAP()
147 
148  // settings
149  CHARFORMAT2 defaultCharFormat;
150  COLORREF defaultColor;
153  COLORREF stringColor[2];
154  COLORREF literalColor;
156 
157  typedef enum {
165  } charType_t;
166 
167  int charType[256];
168 
172  COLORREF * keyWordColors;
174 
178 
182 
183  // run-time variables
184  tom::ITextDocument * m_TextDoc;
185  tom::ITextFont * m_DefaultFont;
186 
187  CHARRANGE updateRange;
191 
194 
197 
199 
200  CPoint mousePoint;
201  CToolTipCtrl * keyWordToolTip;
202  TCHAR * m_pchTip;
203  WCHAR * m_pwchTip;
204 
205 protected:
206  void InitFont( void );
207  void InitSyntaxHighlighting( void );
208  void SetCharType( int first, int last, int type );
209  void SetDefaultFont( int startCharIndex, int endCharIndex );
210  void SetColor( int startCharIndex, int endCharIndex, COLORREF foreColor, COLORREF backColor, bool bold );
211 
212  void FreeKeyWordsFromFile( void );
213  int FindKeyWord( const char *keyWord, int length ) const;
214 
215  void HighlightSyntax( int startCharIndex, int endCharIndex );
216  void UpdateVisibleRange( void );
217 
218  bool GetNameBeforeCurrentSelection( CString &name, int &charIndex ) const;
219  bool GetNameForMousePosition( idStr &name ) const;
220 
221  void AutoCompleteInsertText( void );
222  void AutoCompleteUpdate( void );
223  void AutoCompleteShow( int charIndex );
224  void AutoCompleteHide( void );
225 
226  void ToolTipShow( int charIndex, const char *string );
227  void ToolTipHide( void );
228 
229  bool BracedSectionStart( char braceStartChar, char braceEndChar );
230  bool BracedSectionEnd( char braceStartChar, char braceEndChar );
231  void BracedSectionAdjustEndTabs( void );
232  void BracedSectionShow( void );
233  void BracedSectionHide( void );
234 };
235 
236 #endif /* !__CSYNTAXRICHEDITCTR_H__ */
objectMemberCallback_t GetObjectMembers
byte color[4]
Definition: MegaTexture.cpp:54
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
afx_msg void OnAutoCompleteListBoxChange()
bool GetNameForMousePosition(idStr &name) const
const char * description
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
void GetText(idStr &text) const
void SetFunctionParmCallback(toolTipCallback_t callback)
void SetStringColor(const COLORREF color, const COLORREF altColor=-1)
bool FindNext(const char *find, bool matchCase, bool matchWholeWords, bool searchForward)
prefInfo callback
COLORREF GetForeColor(int charIndex) const
GLenum GLsizei const GLvoid * string
Definition: glext.h:3472
void ReplaceText(int startCharIndex, int endCharIndex, const char *replace)
afx_msg void OnProtected(NMHDR *pNMHDR, LRESULT *pResult)
GLuint GLuint GLsizei GLenum type
Definition: glext.h:2845
#define BOOL
Definition: mprintf.c:71
void SetObjectMemberCallback(objectMemberCallback_t callback)
void SetLiteralColor(const COLORREF color)
void SetToolTipCallback(toolTipCallback_t callback)
void SetText(const char *text)
void AllowPathNames(bool allow)
CHARRANGE GetVisibleRange(void) const
void HighlightSyntax(int startCharIndex, int endCharIndex)
afx_msg void OnSize(UINT nType, int cx, int cy)
bool BracedSectionStart(char braceStartChar, char braceEndChar)
void GetCursorPos(int &line, int &column, int &character) const
afx_msg void OnMouseMove(UINT nFlags, CPoint point)
void SetKeyWords(const keyWord_t kws[])
toolTipCallback_t GetFunctionParms
void SetCharType(int first, int last, int type)
int FindKeyWord(const char *keyWord, int length) const
CToolTipCtrl * keyWordToolTip
COLORREF GetBackColor(int charIndex) const
virtual int OnToolHitTest(CPoint point, TOOLINFO *pTI) const
bool GetNameBeforeCurrentSelection(CString &name, int &charIndex) const
bool(* objectMemberCallback_t)(const char *objectName, CListBox &listBox)
void SetColor(int startCharIndex, int endCharIndex, COLORREF foreColor, COLORREF backColor, bool bold)
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar)
const keyWord_t * keyWords
void SetDefaultFont(int startCharIndex, int endCharIndex)
tom::ITextFont * m_DefaultFont
void SetCommentColor(const COLORREF color)
const GLcharARB * name
Definition: glext.h:3629
afx_msg BOOL OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult)
Definition: Str.h:116
bool BracedSectionEnd(char braceStartChar, char braceEndChar)
afx_msg void OnAutoCompleteListBoxDblClk()
GLsizei const GLcharARB const GLint * length
Definition: glext.h:3599
idList< keyWord_t > keyWordsFromFile
unsigned char bool
Definition: setup.h:74
void SetDefaultColor(const COLORREF color)
afx_msg void OnKeyDown(UINT nKey, UINT nRepCnt, UINT nFlags)
GLint * first
Definition: glext.h:3036
tom::ITextDocument * m_TextDoc
void SetCaseSensitive(bool caseSensitive)
void EnableKeyWordAutoCompletion(bool enable)
void AutoCompleteShow(int charIndex)
GLenum GLenum GLvoid GLvoid * column
Definition: glext.h:2866
void ToolTipShow(int charIndex, const char *string)
toolTipCallback_t GetToolTip
bool LoadKeyWordsFromFile(const char *fileName)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point)
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
const char * keyWord
bool(* toolTipCallback_t)(const char *name, CString &string)
int ReplaceAll(const char *find, const char *replace, bool matchCase, bool matchWholeWords)