scintilla: Update scintilla with changeset 3662:1d1c06df8a2f using gtk+3
[anjuta-extras.git] / plugins / scintilla / aneditor-priv.h
blobb31da0c7bdf588d27834525dba6b53d0b83f4c2c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 aneditor-priv.h
4 Copyright (C) 2004 Naba Kumar
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef __ANEDITOR_PRIV_H__
21 #define __ANEDITOR_PRIV_H__
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 #include <stdlib.h>
28 #include <string.h>
29 #include <ctype.h>
30 #include <stdio.h>
31 #include <fcntl.h>
32 #include <stdarg.h>
33 #include <sys/stat.h>
34 #include <time.h>
35 #include <unistd.h>
36 #include <locale.h>
38 #include <gtk/gtk.h>
40 #define GTK
41 #include "Platform.h"
42 #include "PropSet.h"
43 #include "Accessor.h"
44 #include "KeyWords.h"
45 #include "Scintilla.h"
46 #include "ScintillaWidget.h"
47 #include "SciLexer.h"
48 #include "PropSetFile.h"
49 #include "lexer.h"
50 #include "properties.h"
51 #include "aneditor.h"
53 #include <libanjuta/resources.h>
55 #include <string>
56 #include <memory>
58 using namespace std;
60 // #include "debugger.h"
62 #if 0
64 #include "sv_unknown.xpm"
65 #include "sv_class.xpm"
66 #include "sv_function.xpm"
67 #include "sv_macro.xpm"
68 #include "sv_private_fun.xpm"
69 #include "sv_private_var.xpm"
70 #include "sv_protected_fun.xpm"
71 #include "sv_protected_var.xpm"
72 #include "sv_public_fun.xpm"
73 #include "sv_public_var.xpm"
74 #include "sv_struct.xpm"
75 #include "sv_variable.xpm"
77 #endif
79 // #define DEBUG
81 #define ANE_MARKER_BOOKMARK 0
82 #define MAXIMUM(x, y) ((x>y)?x:y)
83 #define MINIMUM(x,y) ((x<y)?x:y)
85 #define MAX_AUTOCOMPLETE_WORDS 50 /* Maximum number of autocomplete words to show */
87 /* Colour has mysteriously vanished from scintilla */
88 /* Using the substitute */
89 typedef class ColourDesired Colour;
91 template<int sz>
92 class EntryMemory {
93 SString entries[sz];
94 public:
95 void Insert(SString s) {
96 for (int i=0;i<sz;i++) {
97 if (entries[i] == s) {
98 for (int j=i;j>0;j--) {
99 entries[j] = entries[j-1];
101 entries[0] = s;
102 return;
105 for (int k=sz-1;k>0;k--) {
106 entries[k] = entries[k-1];
108 entries[0] = s;
110 int Length() const {
111 int len = 0;
112 for (int i=0;i<sz;i++)
113 if (entries[i].length())
114 len++;
115 return len;
117 SString At(int n)const {
118 return entries[n];
122 typedef EntryMemory<10> ComboMemory;
124 struct StyleAndWords {
125 int styleNumber;
126 SString words;
127 bool IsEmpty() { return words.length() == 0; }
128 bool IsSingleChar() { return words.length() == 1; }
131 // will contain the parameters for the recursive function completion
132 typedef struct _CallTipNode {
133 int startCalltipWord;
134 int def_index;
135 int max_def;
136 SString functionDefinition[20];
137 int rootlen;
138 int start_pos; // start position in editor
139 int call_tip_start_pos; // start position in calltip
141 } CallTipNode, *CallTipNode_ptr;
143 // Related to Utf8_16::encodingType but with additional values at end
144 enum UniMode {
145 uni8Bit=0, uni16BE=1, uni16LE=2, uniUTF8=3,
146 uniCookie=4
149 // Codes representing the effect a line has on indentation.
150 enum IndentationStatus {
151 isNone, // no effect on indentation
152 isBlockStart, // indentation block begin such as "{" or VB "function"
153 isBlockEnd, // indentation end indicator such as "}" or VB "end"
154 isKeyWordStart // Keywords that cause indentation
157 class AnEditor {
159 protected:
160 char fileName[MAX_PATH+20]; // filename kept here temporarily
162 ComboMemory memFinds;
163 ComboMemory memReplaces;
164 ComboMemory memFiles;
166 int characterSet;
167 SString language;
168 int lexLanguage;
169 SString overrideExtension; // User has chosen to use a particular language
170 enum {numWordLists=5};
171 GtkAccelGroup* accelGroup;
173 int indentSize;
175 bool indentOpening;
176 bool indentClosing;
179 bool indentMaintain;
180 bool indentAutomatic;
182 int statementLookback;
183 StyleAndWords statementIndent;
184 StyleAndWords statementEnd;
185 StyleAndWords blockStart;
186 StyleAndWords blockEnd;
187 enum { noPPC, ppcStart, ppcMiddle, ppcEnd, ppcDummy }; ///< Indicate the kind of preprocessor condition line
188 char preprocessorSymbol; ///< Preprocessor symbol (in C: #)
189 WordList preprocCondStart; ///< List of preprocessor conditional start keywords (in C: if ifdef ifndef)
190 WordList preprocCondMiddle; ///< List of preprocessor conditional middle keywords (in C: else elif)
191 WordList preprocCondEnd; ///< List of preprocessor conditional end keywords (in C: endif)
194 Window wEditor;
196 SciFnDirect fnEditor;
197 long ptrEditor;
198 SciFnDirect fnOutput;
199 long ptrOutput;
200 bool tbVisible;
201 bool tabVisible;
202 bool tabMultiLine;
203 bool sbVisible;
204 int visHeightTools;
205 int visHeightTab;
206 int visHeightStatus;
207 int visHeightEditor;
208 int heightBar;
210 int heightOutput;
211 int heightOutputStartDrag;
212 Point ptStartDrag;
213 bool capturedMouse;
214 bool firstPropertiesRead;
215 bool splitVertical;
216 bool bufferedDraw;
217 bool bracesCheck;
218 bool bracesSloppy;
219 int bracesStyle;
220 int braceCount;
221 SString sbValue;
222 bool wrapLine;
223 bool isReadOnly;
225 bool indentationWSVisible;
227 bool autoCompleteIgnoreCase;
228 bool callTipIgnoreCase;
229 bool autoCCausedByOnlyOne;
230 SString calltipWordCharacters;
231 SString calltipEndDefinition;
232 SString autoCompleteStartCharacters;
233 SString autoCompleteFillUpCharacters;
234 SString wordCharacters;
235 int startCalltipWord;
237 GQueue *call_tip_node_queue;
238 CallTipNode call_tip_node;
240 GCompletion *autocompletion;
242 // needed for calltips caret moving
243 int lastPos;
245 bool margin;
246 int marginWidth;
247 enum { marginWidthDefault = 20};
249 bool foldMargin;
250 int foldMarginWidth;
251 enum { foldMarginWidthDefault = 14};
253 bool lineNumbers;
254 int lineNumbersWidth;
255 enum { lineNumbersWidthDefault = 40};
257 bool usePalette;
258 bool clearBeforeExecute;
259 bool allowMenuActions;
260 bool isDirty;
262 bool calltipShown;
263 //bool debugTipOn;
264 static AnEditorID focusedID;
265 friend void aneditor_set_focused_ed_ID(AnEditorID id);
266 //friend void eval_output_arrived_for_aneditor(GList* lines, gpointer data);
268 PropSetFile *props;
270 int LengthDocument();
271 int GetCaretInLine();
272 void GetLine(SString & text, int line = -1);
273 int GetFullLine(SString & text, int line = -1);
274 void GetRange(Window &win, int start, int end, char *text);
276 int IsLinePreprocessorCondition(const char *line);
277 bool FindMatchingPreprocessorCondition(int &curLine, int direction,
278 int condEnd1, int condEnd2);
279 bool FindMatchingPreprocCondPosition(bool isForward, int &mppcAtCaret,
280 int &mppcMatch);
282 bool FindMatchingBracePosition(bool editor, int &braceAtCaret,
283 int &braceOpposite, bool sloppy);
284 void BraceMatch(bool editor);
286 bool GetCurrentWord(char* buffer, int maxlength);
287 bool GetWordBeforeCarat(char* buffer, int maxlength);
289 bool FindWordInRegion(char *buffer, int maxlength, SString &linebuf,
290 int current);
291 bool GetWordAtPosition(char* buffer, int maxlength, int pos);
293 void IndentationIncrease();
294 void IndentationDecrease();
296 void ClearDocument();
297 void CountLineEnds(int &linesCR, int &linesLF, int &linesCRLF);
298 CharacterRange GetSelection();
299 void SelectionWord(char *word, int len);
300 void WordSelect();
301 void LineSelect();
302 void SelectionIntoProperties();
303 long Find (long flags, char* text);
304 bool HandleXml(char ch);
305 SString FindOpenXmlTag(const char sel[], int nSize);
306 void GoMatchingBrace(bool select);
307 void GetRange(guint start, guint end, gchar *text, gboolean styled);
308 bool StartCallTip_new();
309 void ContinueCallTip_new();
310 void SaveCallTip();
311 void ResumeCallTip(bool pop_from_stack = true);
312 void ShutDownCallTip();
313 void SetCallTipDefaults( );
314 void CompleteCallTip();
316 // TMTag ** FindTypeInLocalWords(GPtrArray *CurrentFileTags, const char *root,
317 // const bool type, int *retptr, int *count);
318 //bool SendAutoCompleteRecordsFields(const GPtrArray *CurrentFileTags,
319 // const char *ScanType);
320 // bool StartAutoCompleteRecordsFields(char ch);
321 // bool StartAutoComplete();
322 // bool StartAutoCompleteWord(int autoShowCount);
323 bool StartBlockComment();
324 bool CanBeCommented(bool box_stream);
325 bool StartBoxComment();
326 bool StartStreamComment();
327 // SString GetMode(SString language);
328 // bool InsertCustomIndent();
330 // unsigned int GetLinePartsInStyle(int line, int style1, int style2,
331 // SString sv[], int len);
332 void SetLineIndentation(int line, int indent);
333 int GetLineIndentation(int line);
334 int GetLineIndentPosition(int line);
335 // IndentationStatus GetIndentState(int line);
336 // int IndentOfBlockProper(int line);
337 // int IndentOfBlock(int line);
338 void MaintainIndentation(char ch);
339 // void AutomaticIndentation(char ch);
340 void CharAdded(char ch);
341 void FoldChanged(int line, int levelNow, int levelPrev);
342 void FoldChanged(int position);
343 void Expand(int &line, bool doExpand, bool force=false,
344 int visLevels=0, int level=-1);
345 bool MarginClick(int position,int modifiers);
346 //void HandleDwellStart(int mousePos);
347 void Notify(SCNotification *notification);
348 static void NotifySignal(GtkWidget *w, gint wParam, gpointer lParam,
349 AnEditor *scitew);
351 int KeyPress (unsigned int state, unsigned int keyval);
352 static gint KeyPressEvent(GtkWidget *w, GdkEventKey *event,
353 AnEditor *editor);
355 void BookmarkToggle( int lineno = -1 );
356 void BookmarkFirst();
357 void BookmarkPrev();
358 void BookmarkNext();
359 void BookmarkLast();
360 void BookmarkClear();
362 void AssignKey(int key, int mods, int cmd);
363 StyleAndWords GetStyleAndWords(const char *base);
364 void SetOneStyle(Window &win, int style, const char *s);
365 void SetStyleFor(Window &win, const char *language);
366 SString ExtensionFileName();
367 void Command(int command, unsigned long wParam, long lparam);
368 void ForwardPropertyToEditor(const char *key);
369 SString FindLanguageProperty(const char *pattern,
370 const char *defaultValue="");
371 void ReadPropertiesInitial();
372 void ReadProperties(const char* fileForExt, char **typedef_hl);
373 long SendEditor(unsigned int msg, unsigned long wParam=0, long lParam=0);
374 long SendEditorString(unsigned int msg, unsigned long wParam,
375 const char *s);
376 void SetOverrideLanguage(int ID);
377 void ViewWhitespace(bool view);
378 bool RangeIsAllWhitespace(int start, int end);
379 void SaveToHTML(const char *saveName);
380 void SaveToRTF(const char *saveName);
381 void SetSelection(int anchor, int currentPos);
382 int GetLineLength(int line);
383 int GetCurrentLineNumber();
384 int GetCurrentScrollPosition();
385 void FoldOpenAll();
386 void FoldCloseAll();
387 void FoldCode(bool expanding);
388 void FoldToggle();
389 void SelectBlock ();
390 int GetBlockStartLine(int lineno = -1);
391 int GetBlockEndLine(int lineno = -1);
392 void GotoBlockStart();
393 void GotoBlockEnd();
394 void EnsureRangeVisible(int posStart, int posEnd);
395 void SetAccelGroup(GtkAccelGroup* acl);
396 int GetBookmarkLine( const int nLineStart );
397 void DefineMarker(int marker, int makerType, Colour fore, Colour back);
398 void SetLineWrap(bool wrap);
399 void SetReadOnly(bool readonly);
400 void SetFoldSymbols(SString fold_symbols);
401 bool iswordcharforsel(char ch);
403 public:
405 AnEditor(PropSetFile* p);
406 ~AnEditor();
407 WindowID GetID() { return wEditor.GetID(); }
408 long Command(int cmdID, long wParam, long lParam);
410 void FocusInEvent(GtkWidget* widget);
411 void FocusOutEvent(GtkWidget* widget);
413 void EvalOutputArrived(GList* lines, int textPos,
414 const string &expression);
415 void EndDebugEval();
417 void SetParent(AnEditor *parent);
420 class ExpressionEvaluationTipInfo
421 // Utility class to help displaying expression values in tips.
423 public:
424 AnEditor *editor;
425 int textPos;
426 string expression;
428 ExpressionEvaluationTipInfo(AnEditor *e, int pos, const string &expr)
429 : editor(e), textPos(pos), expression(expr) {}
432 #endif