]> git.saurik.com Git - wxWidgets.git/blob - utils/HelpGen/src/sourcepainter.h
wxCocoa build fix. Use XPM everywhere.
[wxWidgets.git] / utils / HelpGen / src / 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: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __SOURCEPAINTER_G__
13 #define __SOURCEPAINTER_G__
14
15 #ifndef ASSERT
16 #define ASSERT(x) if (!(x)) throw
17 #endif
18
19 #if defined( wxUSE_TEMPLATE_STL )
20
21 #include <vector.h>
22 typedef vector<int> SPBlockListT;
23
24 #ifdef WIN32
25 #include <bstring.h>
26 #else
27 #include <strclass.h>
28 #include <string.h>
29 #endif
30 #else
31
32 #include "wxstlvec.h"
33 #include "wx/string.h"
34
35 #if wxUSE_STD_STRING
36 using std::string;
37 #else
38 // FIXME:: dirty!
39 #define string wxString
40 #endif
41
42 typedef WXSTL_VECTOR_SHALLOW_COPY(int) SPBlockListT;
43
44 #endif
45
46 #include "markup.h" // import MarkupTagsT definition
47
48 // "colored" codes for highlighted blocks
49
50 #define RANK_BLACK 0 // common source fragments
51 #define RANK_BLUE 1 // basic types
52 #define RANK_RED 2 // reserved words
53 #define RANK_GREEN 3 // comments
54
55 // colored block description format :
56 // int( ( rank << 16 ) | ( source_range_len ) )
57
58
59 // FOR NOW:: no lagnguage-map selection
60
61 // source code syntax heighlighter (CPP+JAVA+VB+PASCAL)
62
63 class SourcePainter
64 {
65 protected:
66 string mResultStr;
67 SPBlockListT mBlocks;
68 bool mCollectResultsOn;
69
70 // state variables
71 bool mIsInComment;
72 bool mCommentIsMultiline;
73 public:
74
75 // assembleResultString == true - instructs painter
76 // to collect each chunk of srouce passed to ProcessSource(),
77 // so that results cann be futher obtained in a single string
78 // instead of vector of block descriptions
79
80 SourcePainter( bool assembleResultString = true );
81 virtual ~SourcePainter() {}
82
83 // can be called multiple times (e.g. on each source line)
84 void ProcessSource( char* src, int srcLen );
85
86 // method, for manually adjusting state of source painter
87 void SetState( bool isInComment,
88 bool commentIsMultiline );
89
90 // reinitializes object - clears results of previouse processing
91 void Init( bool assembleResultString = true );
92
93 // generates string of highlighted source for the scipting
94 // language given by "tags" argument
95
96 virtual void GetResultString(string& result, MarkupTagsT tags);
97
98 // returns vector of block descriptors, see SPBlockListT definition
99 // (block descriptors can be used for fast custom hightlighted text generation)
100
101 SPBlockListT& GetBlocks();
102
103 // NOTE:: static method
104 // returns if the given word is a reserved word or basic type identifier
105 static bool IsKeyword( char* word, int wordLen );
106 };
107
108 #endif