1
///////////////////////////////////////////////////////////////////////////////
3
// Purpose: wxSTEditor Languages initialization
6
// Copyright: (c) John Labenski, Otto Wyss
7
// Licence: wxWidgets licence
8
///////////////////////////////////////////////////////////////////////////////
11
/// @brief wxSTEditorLangs, lexer information.
16
#include "wx/stedit/stedefs.h"
17
#include "wx/stedit/steprefs.h"
19
class WXDLLIMPEXP_FWD_BASE wxConfigBase;
21
#include "wx/stedit/pairarr.h"
23
typedef class WXDLLIMPEXP_STEDIT SortedPairArrayNumberKey<int, wxArrayInt, wxString, wxArrayString> wxSTEPairArrayIntString;
25
struct WXDLLIMPEXP_STEDIT STE_Language;
27
//----------------------------------------------------------------------------
28
/// @class wxSTEditorLangs
29
/// @brief A ref counted languages info container for the wxSTEditor.
31
/// You probably only want/need one of these and the only thing you can set
32
/// is the filepatterns.
34
/// Attach to an editor using wxSTEditor::RegisterLanguages().
36
/// This class is works a little differently than the prefs and styles. Instead
37
/// of copying the values from a set of "Init" values this merely uses the
38
/// init values in place. This is done to save memory.
40
/// The default values are stored in an array of struct STE_Language and this
41
/// class just accesses them. This means that if you do this :
43
/// const char* myCPPFilePatterns = "*.cxx"; // must exist until exit
44
/// STELangs::GetLanguage(STE_LANG_CPP)->filePattern = myCPPFilePatterns;
46
/// You've changed the filePatterns for the CPP lexer for all instances of the
49
/// In order to change the filepatterns of a specific instance of the langs use
50
/// SetUserFilePatterns().
52
/// It is assumed that there would be very few changes a user would want to make
53
/// to this data except for filepatters, added words, and style mapping.
55
/// * There is a lot of data in this class and if any of it is in error please
56
/// correct it and send me a patch.
57
//----------------------------------------------------------------------------
59
class WXDLLIMPEXP_STEDIT wxSTEditorLangs : public wxSTEditorPrefBase
62
wxSTEditorLangs(bool create = false) { if (create) Create(); }
63
wxSTEditorLangs(const wxSTEditorLangs &langs) { Create(langs); }
64
virtual ~wxSTEditorLangs() {}
65
bool IsOk() const { return m_refData != NULL; }
66
bool Create(); ///< (Re)create as new.
67
bool Create(const wxSTEditorLangs &other); ///< Make a Refed copy of other.
68
void Copy(const wxSTEditorLangs &other); ///< Make a full copy.
69
void Reset(); ///< Reset to default values.
70
void Destroy() { UnRef(); }
72
/// Do these two langs have the same values.
73
bool IsEqualTo(const wxSTEditorLangs &langs) const;
75
// ------------------------------------------------------------------------
76
/// An instance of the editor languages for many editors to share
77
/// Use this in at least one editor to not let it go to waste.
78
static wxSTEditorLangs& GetGlobalEditorLangs();
80
// ------------------------------------------------------------------------
82
/// Get the number of different languages = STE_LANG__MAX.
83
/// NB: Some may be NULL if !STE_USE_LANG_XXX is 0, check HasLanguage()
84
size_t GetCount() const;
86
/// Find what language has the extension, returns STE_LANG_NULL if unknown.
87
int FindLanguageByFilename(const wxFileName&) const;
89
/// Is this language set (else it's NULL), lang_n is enum STE_LangTypes.
90
bool HasLanguage(size_t lang_n) const { return GetLanguage(lang_n) != NULL; }
92
/// Get the name of the language.
93
wxString GetName(size_t lang_n) const;
94
/// Get the file extensions to use for this language, "*.c;*.cpp;*.h...".
95
/// If !get_default then get the set value, else return default.
96
wxString GetFilePattern(size_t lang_n, bool get_default = false) const;
97
/// Get the set filepattern, if any, else empty string.
98
wxString GetUserFilePattern(size_t lang_n) const;
99
/// Get a file filter for the language "Python (py,pyw) | *.py;*.pyw".
100
wxString GetFileFilter(size_t lang_n) const;
101
/// Get the lexer to use for Scintilla.
102
int GetLexer(size_t lang_n) const;
103
/// Get the number of styles defined for the lexer.
104
size_t GetStyleCount(size_t lang_n) const;
105
/// Get the style index the lexer uses for this language, style_n = 0 to GetStyleCount().
106
/// Typically they're in order 0,1,2 but sometimes not.
107
/// @returns A style for Scintilla's lexer or -1 if not used or error.
108
int GetSciStyle(size_t lang_n, size_t style_n) const;
109
/// Get what STE style to use for this language, style_n = 0 to GetStyleCount().
110
/// @returns A style for wxSTEditorStyles to use or -1 if not used or error.
111
int GetSTEStyle(size_t lang_n, size_t style_n, bool get_default = false) const;
112
/// Get a user set STE style to use for this language.
113
/// @returns -1 if none set.
114
int GetUserSTEStyle(size_t lang_n, size_t style_n) const;
115
/// Translate the scintilla style to the STE style using the style table.
116
/// @returns -1 on error.
117
int SciToSTEStyle(size_t lang_n, int sci_style) const;
118
/// Get a readable description of what the style is used for in Scintilla.
119
wxString GetStyleDescription(size_t lang_n, size_t style_n) const;
120
/// Get the number of keywords for the style.
121
size_t GetKeyWordsCount(size_t lang_n) const;
122
/// Get the words used for this style or NULL if none.
123
/// If !get_default then get the words + any set words, else default only.
124
wxString GetKeyWords(size_t lang_n, size_t word_n, bool get_default = false) const;
125
/// Get any set keywords added to the defaults, else empty string.
126
wxString GetUserKeyWords(size_t lang_n, size_t word_n) const;
127
/// Get the chararacters used for the start and end of blocks eg, "{}" for c.
128
bool HasBlock(size_t lang_n) const; ///< are blocks defined?
129
wxString GetBlockStart(size_t lang_n) const; ///< for cpp "{".
130
wxString GetBlockEnd(size_t lang_n) const; ///< for cpp "}".
131
int GetBlockStartSTCStyle(size_t lang_n) const; ///< Scintilla style for block start.
132
int GetBlockEndSTCStyle(size_t lang_n) const; ///< Scintilla style for block end.
133
/// Get what preprocessor symbols are used.
134
bool HasPreprocessor(size_t lang_n) const; ///< are comments defined?
135
wxString GetPreprocessorSymbol(size_t lang_n) const; ///< for cpp "#".
136
wxString GetPreprocessorStart(size_t lang_n) const; ///< for cpp "if ifdef ifndef".
137
wxString GetPreprocessorMid(size_t lang_n) const; ///< for cpp "else elif".
138
wxString GetPreprocessorEnd(size_t lang_n) const; ///< for cpp "endif".
139
/// Get what comment symbols are used.
140
bool HasComments(size_t lang_n) const; ///< are blocks defined?
141
int GetCommentBlockAtLineStart(size_t lang_n) const; ///< starts at beginning of line.
142
wxString GetCommentBlock(size_t lang_n) const; ///< for cpp "//".
143
wxString GetCommentBoxStart(size_t lang_n) const; ///< for cpp "/*".
144
wxString GetCommentBoxMiddle(size_t lang_n) const; ///< for cpp "*".
145
wxString GetCommentBoxEnd(size_t lang_n) const; ///< for cpp "*/".
146
wxString GetCommentStreamStart(size_t lang_n) const; ///< for cpp "/*".
147
wxString GetCommentStreamEnd(size_t lang_n) const; ///< for cpp "*/".
148
/// Get the Scintilla styled used for the braces.
149
int GetBracesStyle(size_t lang_n) const;
150
/// Get the folds used for this language.
151
int GetFolds(size_t lang_n) const;
152
//int GetIndent(int lang_n) const;
153
//int GetLongLine(int lang_n) const;
154
int GetFlags(size_t lang_n) const;
156
/// You can turn off the "availability" of languages by setting the
157
/// flag STE_LANG_FLAG_DONTUSE.
158
bool GetUseLanguage(size_t lang_n) const { return HasLanguage(lang_n) && ((GetFlags(lang_n) & STE_LANG_FLAG_DONTUSE) == 0); }
160
// ------------------------------------------------------------------------
162
/// Set the filepatterns to use for the language, this takes
163
/// precedence over the default file patterns. see Get(User)FilePattern().
164
void SetUserFilePattern(size_t lang_n, const wxString &filePattern);
165
/// Set the STE style to use for the Scintilla style for the language.
166
/// style_n must be in the range GetStyleCount().
167
/// ste_style is the ste_style see enum STE_StyleType (or ones you added).
168
/// This changes the default style used as well, permanently.
169
void SetSTEStyle(size_t lang_n, size_t style_n, int ste_style);
170
/// Set a user defined style to use, see SetSTEStyle for parameters.
171
void SetUserSTEStyle(size_t lang_n, size_t style_n, int ste_style);
172
/// Set additional words to use that are added to the defaults.
173
void SetUserKeyWords(size_t lang_n, size_t word_n, const wxString& words);
175
/// Set the flags for the language enum STE_LangFlagsType.
176
void SetFlags(size_t lang_n, int flags);
178
// ------------------------------------------------------------------------
179
/// Add a new language to this, the language is not deleted when done and
180
/// must exist for the life of this wxSTEditorLangs.
181
/// The function returns the position in the array where the lang is,
182
/// GetCount()-1 or STE_LANG__MAX+(num langs you've already added).
183
int AddLanguage(STE_Language* lang);
185
/// Get the language struct itself - remember that the strings in the
186
/// struct are const char* so be careful about conversion.
187
/// You should really use the above functions instead of accessing
188
/// this to avoid problems. However you may replace values.
189
STE_Language* GetLanguage(size_t lang_n) const;
191
// ------------------------------------------------------------------------
193
virtual void UpdateEditor( wxSTEditor *editor );
195
// ------------------------------------------------------------------------
196
/// @name wxConfig load & save.
197
/// See also wxSTEditorOptions for paths and internal saving config.
199
void LoadConfig(wxConfigBase &config,
200
const wxString &configRoot = wxT("/wxSTEditor/Languages/"));
201
void SaveConfig(wxConfigBase &config,
202
const wxString &configRoot = wxT("/wxSTEditor/Languages/"),
203
int flags = 0) const;
205
// ------------------------------------------------------------------------
208
wxSTEditorLangs& operator = (const wxSTEditorLangs& langs)
210
if ( (*this) != langs )
215
bool operator == (const wxSTEditorLangs& langs) const
216
{ return m_refData == langs.m_refData; }
217
bool operator != (const wxSTEditorLangs& langs) const
218
{ return m_refData != langs.m_refData; }
222
DECLARE_DYNAMIC_CLASS(wxSTEditorLangs)
226
// ---------------------------------------------------------------------------
227
// ---------------------------------------------------------------------------
230
// ---------------------------------------------------------------------------
231
/// Styles used for the language, maps enum STE_StyleType to Scintilla styles.
232
typedef struct WXDLLIMPEXP_STEDIT STE_LexerStyles
234
int ste_style; ///< STE style to use.
235
int sci_style; ///< Scintilla style to map to.
236
const char* description; ///< readable description of its use in scintilla.
239
// ---------------------------------------------------------------------------
240
/// Word list and its Scintilla style for the lexer.
241
typedef struct WXDLLIMPEXP_STEDIT STE_LexerWords
243
int sci_style; ///< Scintilla style used for the words.
244
const char* words; ///< List of words, for cpp "and and_eq asm auto...".
247
// ---------------------------------------------------------------------------
248
/// Block start and end (ie. {}) and the styles for the start/end blocks.
249
typedef struct WXDLLIMPEXP_STEDIT STE_LexerBlock
251
int sci_start_style; ///< Scintilla style to use for block start.
252
const char* start; ///< for cpp "{".
253
int sci_end_style; ///< Scintilla style to use for block end.
254
const char* end; ///< for cpp "}".
257
// ---------------------------------------------------------------------------
258
/// Comments for the lexers or NULL for none.
259
typedef struct WXDLLIMPEXP_STEDIT STE_LexerComments
261
int blockAtLineStart;
262
const char* block; ///< for cpp "//".
263
const char* boxStart; ///< for cpp "/*".
264
const char* boxMiddle; ///< for cpp "*".
265
const char* boxEnd; ///< for cpp "*/".
266
const char* streamStart; ///< for cpp "/*".
267
const char* streamEnd; ///< for cpp "*/".
270
// ---------------------------------------------------------------------------
271
/// Preprocessor symbols used for the lexers or NULL for none.
272
typedef struct WXDLLIMPEXP_STEDIT STE_LexerPreproc
274
const char* symbol; ///< for cpp "#".
275
const char* boxStart; ///< for cpp "if ifdef ifndef".
276
const char* boxMiddle; ///< for cpp "else elif".
277
const char* boxEnd; ///< for cpp "endif".
280
// ---------------------------------------------------------------------------
281
/// @struct STE_Language
282
/// @brief A struct that contains a complete language description for the lexer.
284
/// This is public so that you can create your own languages and add them.
285
/// Please try to use the accessors in wxSTEditorLangs to get values as
286
/// this struct may change at any time.
288
/// In order to create a new language, please see the cpp file for usage.
289
/// Basicly, just create permanent values and a permanent STE_Language struct
290
/// and call wxSTEditorLangs::AddLanguage() to add your new language.
291
// ---------------------------------------------------------------------------
292
typedef struct WXDLLIMPEXP_STEDIT STE_Language
294
const char* name; ///< readable name of the language.
295
int lexer; ///< Scintilla lexer number eg. wxSTC_LEX_CPP.
296
const char* filePattern; ///< file extensions, "*.c;*.cc;*.cpp...".
297
STE_LexerStyles* styles; ///< maps Scintilla styles to STE, always have 1.
298
size_t styles_count; ///< number of styles mapped.
299
const STE_LexerWords* words; ///< may be NULL for no words.
300
size_t words_count; ///< number of words.
301
const STE_LexerComments* comment; ///< may be NULL for no comments.
302
const STE_LexerBlock* block; ///< may be NULL for no blocks.
303
const STE_LexerPreproc* preproc; ///< may be NULL for no preprocessor.
304
int braces_style; ///< Scintilla style used for braces.
305
int folds; ///< what folds are available STE_FOLD_XXX (FIXME unused).
306
int flags; ///< user defined flags.
311
#endif // _STELANGS_H_