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__
45 #include "Scintilla.h"
46 #include "ScintillaWidget.h"
48 #include "PropSetFile.h"
50 #include "properties.h"
53 #include <libanjuta/resources.h>
60 // #include "debugger.h"
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"
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
;
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];
105 for (int k
=sz
-1;k
>0;k
--) {
106 entries
[k
] = entries
[k
-1];
112 for (int i
=0;i
<sz
;i
++)
113 if (entries
[i
].length())
117 SString
At(int n
)const {
122 typedef EntryMemory
<10> ComboMemory
;
124 struct StyleAndWords
{
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
;
136 SString functionDefinition
[20];
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
145 uni8Bit
=0, uni16BE
=1, uni16LE
=2, uniUTF8
=3,
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
160 char fileName
[MAX_PATH
+20]; // filename kept here temporarily
162 ComboMemory memFinds
;
163 ComboMemory memReplaces
;
164 ComboMemory memFiles
;
169 SString overrideExtension
; // User has chosen to use a particular language
170 enum {numWordLists
=5};
171 GtkAccelGroup
* accelGroup
;
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)
196 SciFnDirect fnEditor
;
198 SciFnDirect fnOutput
;
211 int heightOutputStartDrag
;
214 bool firstPropertiesRead
;
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
247 enum { marginWidthDefault
= 20};
251 enum { foldMarginWidthDefault
= 14};
254 int lineNumbersWidth
;
255 enum { lineNumbersWidthDefault
= 40};
258 bool clearBeforeExecute
;
259 bool allowMenuActions
;
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);
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,
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
,
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
);
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();
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
,
351 int KeyPress (unsigned int state, unsigned int keyval);
352 static gint KeyPressEvent(GtkWidget *w, GdkEventKey *event,
355 void BookmarkToggle( int lineno
= -1 );
356 void BookmarkFirst();
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
,
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();
387 void FoldCode(bool expanding
);
390 int GetBlockStartLine(int lineno
= -1);
391 int GetBlockEndLine(int lineno
= -1);
392 void GotoBlockStart();
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
);
405 AnEditor(PropSetFile
* p
);
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);
417 void SetParent(AnEditor
*parent
);
420 class ExpressionEvaluationTipInfo
421 // Utility class to help displaying expression values in tips.
428 ExpressionEvaluationTipInfo(AnEditor
*e
, int pos
, const string
&expr
)
429 : editor(e
), textPos(pos
), expression(expr
) {}