]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/modules/lseditor/sourcepainter.h
More updates.
[wxWidgets.git] / utils / wxPython / modules / lseditor / sourcepainter.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: No names yet.
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
5 // Modified by:
6 // Created: 22/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Aleskandars Gluchovas
9 // Licence: GNU General Public License
10 /////////////////////////////////////////////////////////////////////////////
11 //
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 /////////////////////////////////////////////////////////////////////////////
26
27
28
29 #ifndef __SOURCEPAINTER_G__
30 #define __SOURCEPAINTER_G__
31
32 #ifndef ASSERT
33 #define ASSERT(x) if (!(x)) throw
34 #endif
35
36 #include "wxstldefs.h"
37
38 #include "markup.h" // import MarkupTagsT definition
39
40 // "colored" codes for highlighted blocks
41
42 #define RANK_BLACK 0 // common source fragments
43 #define RANK_BLUE 1 // basic types
44 #define RANK_RED 2 // reserved words
45 #define RANK_GREEN 3 // comments
46
47 // colored block description format :
48 // int( ( rank << 16 ) | ( source_range_len ) )
49
50 inline int get_src_block_rank( int block )
51 {
52 return (block >> 16) & 0xFFFF;
53 }
54
55 inline int get_src_block_len( int block )
56 {
57 return block & 0xFFFF;
58 }
59
60 // FOR NOW:: no lagnguage-map selection
61
62 // source code syntax heighlighter (CPP+JAVA+VB+PASCAL)
63
64 class SourcePainter
65 {
66 protected:
67 string mResultStr;
68 IntListT mBlocks;
69 bool mCollectResultsOn;
70
71 // state variables
72 bool mIsInComment;
73 bool mCommentIsMultiline;
74 public:
75
76 // assembleResultString == TRUE - instructs painter
77 // to collect each chunk of srouce passed to ProcessSource(),
78 // so that results cann be futher obtained in a single string
79 // instead of vector of block descriptions
80
81 SourcePainter( bool assembleResultString = TRUE );
82 virtual ~SourcePainter() {}
83
84 // can be called multiple times (e.g. on each source line)
85 virtual void ProcessSource( char* src, int srcLen );
86
87 // method, for manually adjusting state of source painter
88 virtual void SetState( bool isInComment,
89 bool commentIsMultiline );
90
91 // reinitializes object - clears results of previouse processing
92 virtual void Init( bool assembleResultString = TRUE );
93
94 // generates string of highlighted source for the scipting
95 // language given by "tags" argument
96
97 virtual void GetResultString(string& result, MarkupTagsT tags);
98
99 // returns vector of block descriptors, see IntListT definition
100 // (block descriptors can be used for fast custom hightlighted text generation)
101
102 virtual IntListT& GetBlocks();
103
104 // NOTE:: static method
105 // returns if the given word is a reserved word or basic type identifier
106 static bool IsKeyword( char* word, int wordLen );
107 };
108
109 #endif