1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
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__
44 #include "WindowAccessor.h"
46 #include "Scintilla.h"
47 #include "ScintillaWidget.h"
50 #include "properties_cxx.h"
51 #include "properties.h"
54 #include <libanjuta/resources.h>
56 #include "tm_tagmanager.h"
63 // #include "debugger.h"
67 #include "sv_unknown.xpm"
68 #include "sv_class.xpm"
69 #include "sv_function.xpm"
70 #include "sv_macro.xpm"
71 #include "sv_private_fun.xpm"
72 #include "sv_private_var.xpm"
73 #include "sv_protected_fun.xpm"
74 #include "sv_protected_var.xpm"
75 #include "sv_public_fun.xpm"
76 #include "sv_public_var.xpm"
77 #include "sv_struct.xpm"
78 #include "sv_variable.xpm"
84 #define ANE_MARKER_BOOKMARK 0
86 #define MAXIMUM(x, y) ((x>y)?x:y)
87 #define MINIMUM(x,y) ((x<y)?x:y)
89 #define MAX_AUTOCOMPLETE_WORDS 50 /* Maximum number of autocomplete words to show */
91 /* Colour has mysteriously vanished from scintilla */
92 /* Using the substitute */
93 typedef class ColourDesired Colour
;
99 void Insert(SString s
) {
100 for (int i
=0;i
<sz
;i
++) {
101 if (entries
[i
] == s
) {
102 for (int j
=i
;j
>0;j
--) {
103 entries
[j
] = entries
[j
-1];
109 for (int k
=sz
-1;k
>0;k
--) {
110 entries
[k
] = entries
[k
-1];
116 for (int i
=0;i
<sz
;i
++)
117 if (entries
[i
].length())
121 SString
At(int n
)const {
126 typedef EntryMemory
<10> ComboMemory
;
128 struct StyleAndWords
{
131 bool IsEmpty() { return words
.length() == 0; }
132 bool IsSingleChar() { return words
.length() == 1; }
135 // will contain the parameters for the recursive function completion
136 typedef struct _CallTipNode
{
137 int startCalltipWord
;
140 SString functionDefinition
[20];
142 int start_pos
; // start position in editor
143 int call_tip_start_pos
; // start position in calltip
145 } CallTipNode
, *CallTipNode_ptr
;
147 // Related to Utf8_16::encodingType but with additional values at end
149 uni8Bit
=0, uni16BE
=1, uni16LE
=2, uniUTF8
=3,
153 // Codes representing the effect a line has on indentation.
154 enum IndentationStatus
{
155 isNone
, // no effect on indentation
156 isBlockStart
, // indentation block begin such as "{" or VB "function"
157 isBlockEnd
, // indentation end indicator such as "}" or VB "end"
158 isKeyWordStart
// Keywords that cause indentation
164 char fileName
[MAX_PATH
+20]; // filename kept here temporarily
166 ComboMemory memFinds
;
167 ComboMemory memReplaces
;
168 ComboMemory memFiles
;
173 SString overrideExtension
; // User has chosen to use a particular language
174 enum {numWordLists
=5};
175 GtkAccelGroup
* accelGroup
;
185 int statementLookback;
186 StyleAndWords statementIndent;
187 StyleAndWords statementEnd;
188 StyleAndWords blockStart;
189 StyleAndWords blockEnd;
190 enum { noPPC, ppcStart, ppcMiddle, ppcEnd, ppcDummy }; ///< Indicate the kind of preprocessor condition line
191 char preprocessorSymbol; ///< Preprocessor symbol (in C: #)
192 WordList preprocCondStart; ///< List of preprocessor conditional start keywords (in C: if ifdef ifndef)
193 WordList preprocCondMiddle; ///< List of preprocessor conditional middle keywords (in C: else elif)
194 WordList preprocCondEnd; ///< List of preprocessor conditional end keywords (in C: endif)
199 SciFnDirect fnEditor
;
201 SciFnDirect fnOutput
;
214 int heightOutputStartDrag
;
217 bool firstPropertiesRead
;
228 bool indentationWSVisible
;
230 bool autoCompleteIgnoreCase
;
231 bool callTipIgnoreCase
;
232 bool autoCCausedByOnlyOne
;
233 SString calltipWordCharacters
;
234 SString calltipEndDefinition
;
235 SString autoCompleteStartCharacters
;
236 SString autoCompleteFillUpCharacters
;
237 SString wordCharacters
;
238 int startCalltipWord
;
240 GQueue
*call_tip_node_queue
;
241 CallTipNode call_tip_node
;
243 GCompletion
*autocompletion
;
245 // needed for calltips caret moving
250 enum { marginWidthDefault
= 20};
254 enum { foldMarginWidthDefault
= 14};
257 int lineNumbersWidth
;
258 enum { lineNumbersWidthDefault
= 40};
261 bool clearBeforeExecute
;
262 bool allowMenuActions
;
267 static AnEditorID focusedID
;
268 friend void aneditor_set_focused_ed_ID(AnEditorID id
);
269 //friend void eval_output_arrived_for_aneditor(GList* lines, gpointer data);
273 int LengthDocument();
274 int GetCaretInLine();
275 void GetLine(SString
& text
, int line
= -1);
276 int GetFullLine(SString
& text
, int line
= -1);
277 void GetRange(Window
&win
, int start
, int end
, char *text
);
279 int IsLinePreprocessorCondition(const char *line);
280 bool FindMatchingPreprocessorCondition(int &curLine, int direction,
281 int condEnd1, int condEnd2);
282 bool FindMatchingPreprocCondPosition(bool isForward, int &mppcAtCaret,
285 bool FindMatchingBracePosition(bool editor
, int &braceAtCaret
,
286 int &braceOpposite
, bool sloppy
);
287 void BraceMatch(bool editor
);
289 bool GetCurrentWord(char* buffer
, int maxlength
);
290 bool GetWordBeforeCarat(char* buffer
, int maxlength
);
292 bool FindWordInRegion(char *buffer
, int maxlength
, SString
&linebuf
,
294 bool GetWordAtPosition(char* buffer
, int maxlength
, int pos
);
296 void IndentationIncrease();
297 void IndentationDecrease();
299 void ClearDocument();
300 void CountLineEnds(int &linesCR
, int &linesLF
, int &linesCRLF
);
301 CharacterRange
GetSelection();
302 void SelectionWord(char *word
, int len
);
305 void SelectionIntoProperties();
306 long Find (long flags
, char* text
);
307 bool HandleXml(char ch
);
308 SString
FindOpenXmlTag(const char sel
[], int nSize
);
309 void GoMatchingBrace(bool select
);
310 void GetRange(guint start
, guint end
, gchar
*text
, gboolean styled
);
311 bool StartCallTip_new();
312 void ContinueCallTip_new();
314 void ResumeCallTip(bool pop_from_stack
= true);
315 void ShutDownCallTip();
316 void SetCallTipDefaults( );
317 void CompleteCallTip();
319 // TMTag ** FindTypeInLocalWords(GPtrArray *CurrentFileTags, const char *root,
320 // const bool type, int *retptr, int *count);
321 //bool SendAutoCompleteRecordsFields(const GPtrArray *CurrentFileTags,
322 // const char *ScanType);
323 // bool StartAutoCompleteRecordsFields(char ch);
324 // bool StartAutoComplete();
325 // bool StartAutoCompleteWord(int autoShowCount);
326 bool StartBlockComment();
327 bool CanBeCommented(bool box_stream
);
328 bool StartBoxComment();
329 bool StartStreamComment();
330 // SString GetMode(SString language);
331 // bool InsertCustomIndent();
333 // unsigned int GetLinePartsInStyle(int line, int style1, int style2,
334 // SString sv[], int len);
335 void SetLineIndentation(int line
, int indent
);
336 int GetLineIndentation(int line
);
337 int GetLineIndentPosition(int line
);
338 // IndentationStatus GetIndentState(int line);
339 // int IndentOfBlockProper(int line);
340 // int IndentOfBlock(int line);
341 void MaintainIndentation(char ch
);
342 // void AutomaticIndentation(char ch);
343 void CharAdded(char ch
);
344 void FoldChanged(int line
, int levelNow
, int levelPrev
);
345 void FoldChanged(int position
);
346 void Expand(int &line
, bool doExpand
, bool force
=false,
347 int visLevels
=0, int level
=-1);
348 bool MarginClick(int position
,int modifiers
);
349 //void HandleDwellStart(int mousePos);
350 void Notify(SCNotification
*notification
);
351 static void NotifySignal(GtkWidget
*w
, gint wParam
, gpointer lParam
,
354 int KeyPress (unsigned int state, unsigned int keyval);
355 static gint KeyPressEvent(GtkWidget *w, GdkEventKey *event,
358 void BookmarkToggle( int lineno
= -1 );
359 void BookmarkFirst();
363 void BookmarkClear();
365 void AssignKey(int key
, int mods
, int cmd
);
366 StyleAndWords
GetStyleAndWords(const char *base
);
367 void SetOneStyle(Window
&win
, int style
, const char *s
);
368 void SetStyleFor(Window
&win
, const char *language
);
369 SString
ExtensionFileName();
370 void Command(int command
, unsigned long wParam
, long lparam
);
371 void ForwardPropertyToEditor(const char *key
);
372 SString
FindLanguageProperty(const char *pattern
,
373 const char *defaultValue
="");
374 void ReadPropertiesInitial();
375 void ReadProperties(const char* fileForExt
);
376 long SendEditor(unsigned int msg
, unsigned long wParam
=0, long lParam
=0);
377 long SendEditorString(unsigned int msg
, unsigned long wParam
,
379 void SetOverrideLanguage(int ID
);
380 void ViewWhitespace(bool view
);
381 bool RangeIsAllWhitespace(int start
, int end
);
382 void SaveToHTML(const char *saveName
);
383 void SaveToRTF(const char *saveName
);
384 void SetSelection(int anchor
, int currentPos
);
385 int GetLineLength(int line
);
386 int GetCurrentLineNumber();
387 int GetCurrentScrollPosition();
390 void FoldCode(bool expanding
);
393 int GetBlockStartLine(int lineno
= -1);
394 int GetBlockEndLine(int lineno
= -1);
395 void GotoBlockStart();
397 void EnsureRangeVisible(int posStart
, int posEnd
);
398 void SetAccelGroup(GtkAccelGroup
* acl
);
399 int GetBookmarkLine( const int nLineStart
);
400 void DefineMarker(int marker
, int makerType
, Colour fore
, Colour back
);
401 void SetLineWrap(bool wrap
);
402 void SetReadOnly(bool readonly
);
403 void SetFoldSymbols(SString fold_symbols
);
404 bool iswordcharforsel(char ch
);
408 AnEditor(PropSetFile
* p
);
410 WindowID
GetID() { return wEditor
.GetID(); }
411 long Command(int cmdID
, long wParam
, long lParam
);
413 void FocusInEvent(GtkWidget
* widget
);
414 void FocusOutEvent(GtkWidget
* widget
);
416 void EvalOutputArrived(GList* lines, int textPos,
417 const string &expression);
420 void SetParent(AnEditor
*parent
);
423 class ExpressionEvaluationTipInfo
424 // Utility class to help displaying expression values in tips.
431 ExpressionEvaluationTipInfo(AnEditor
*e
, int pos
, const string
&expr
)
432 : editor(e
), textPos(pos
), expression(expr
) {}