]>
Commit | Line | Data |
---|---|---|
cecfc5e7 VZ |
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 | |
8bc17f14 | 9 | // Licence: wxWindows licence |
cecfc5e7 VZ |
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 | ||
8bc17f14 WS |
21 | #include <vector.h> |
22 | typedef vector<int> SPBlockListT; | |
cecfc5e7 | 23 | |
8bc17f14 WS |
24 | #ifdef WIN32 |
25 | #include <bstring.h> | |
26 | #else | |
27 | #include <strclass.h> | |
28 | #include <string.h> | |
29 | #endif | |
cecfc5e7 VZ |
30 | #else |
31 | ||
8bc17f14 WS |
32 | #include "wxstlvec.h" |
33 | #include "wx/string.h" | |
cecfc5e7 | 34 | |
8bc17f14 WS |
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; | |
cecfc5e7 VZ |
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: | |
8bc17f14 WS |
66 | string mResultStr; |
67 | SPBlockListT mBlocks; | |
68 | bool mCollectResultsOn; | |
cecfc5e7 | 69 | |
8bc17f14 WS |
70 | // state variables |
71 | bool mIsInComment; | |
72 | bool mCommentIsMultiline; | |
cecfc5e7 VZ |
73 | public: |
74 | ||
8bc17f14 WS |
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() {} | |
cecfc5e7 | 82 | |
8bc17f14 WS |
83 | // can be called multiple times (e.g. on each source line) |
84 | void ProcessSource( char* src, int srcLen ); | |
cecfc5e7 | 85 | |
8bc17f14 WS |
86 | // method, for manually adjusting state of source painter |
87 | void SetState( bool isInComment, | |
88 | bool commentIsMultiline ); | |
cecfc5e7 | 89 | |
8bc17f14 WS |
90 | // reinitializes object - clears results of previouse processing |
91 | void Init( bool assembleResultString = true ); | |
cecfc5e7 | 92 | |
8bc17f14 WS |
93 | // generates string of highlighted source for the scipting |
94 | // language given by "tags" argument | |
cecfc5e7 | 95 | |
b6317810 | 96 | virtual void GetResultString(wxString& result, MarkupTagsT tags); |
cecfc5e7 | 97 | |
8bc17f14 | 98 | // returns vector of block descriptors, see SPBlockListT definition |
d6922577 | 99 | // (block descriptors can be used for fast custom highlighted text generation) |
cecfc5e7 | 100 | |
8bc17f14 | 101 | SPBlockListT& GetBlocks(); |
cecfc5e7 | 102 | |
8bc17f14 WS |
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 ); | |
cecfc5e7 VZ |
106 | }; |
107 | ||
108 | #endif |