]> git.saurik.com Git - wxWidgets.git/blame - src/stc/scintilla/src/Editor.h
improved error messages
[wxWidgets.git] / src / stc / scintilla / src / Editor.h
CommitLineData
9ce192d4 1// Scintilla source code edit control
65ec6247
RD
2/** @file Editor.h
3 ** Defines the main editor class.
4 **/
1a2fb4cd 5// Copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org>
9ce192d4
RD
6// The License.txt file describes the conditions under which this software may be distributed.
7
8#ifndef EDITOR_H
9#define EDITOR_H
10
65ec6247
RD
11/**
12 */
9ce192d4
RD
13class Caret {
14public:
15 bool active;
16 bool on;
17 int period;
1a2fb4cd 18
9ce192d4
RD
19 Caret();
20};
21
65ec6247
RD
22/**
23 */
9ce192d4 24class Timer {
9ce192d4
RD
25public:
26 bool ticking;
27 int ticksToWait;
28 enum {tickSize = 100};
1a2fb4cd
RD
29 TickerID tickerID;
30
9ce192d4
RD
31 Timer();
32};
33
65ec6247
RD
34/**
35 */
9ce192d4 36class LineLayout {
1a2fb4cd
RD
37private:
38 friend class LineLayoutCache;
39 int *lineStarts;
40 int lenLineStarts;
65ec6247 41 /// Drawing is only performed for @a maxLineLength characters on each line.
1a2fb4cd
RD
42 int lineNumber;
43 bool inCache;
44public:
45 enum { wrapWidthInfinite = 0x7ffffff };
46 int maxLineLength;
9ce192d4 47 int numCharsInLine;
1a2fb4cd 48 enum validLevel { llInvalid, llPositions, llLines } validity;
d134f170
RD
49 int xHighlightGuide;
50 bool highlightColumn;
51 int selStart;
52 int selEnd;
65ec6247 53 bool containsCaret;
d134f170 54 int edgeColumn;
1a2fb4cd
RD
55 char *chars;
56 char *styles;
57 char *indicators;
58 int *positions;
59 char bracePreviousStyles[2];
60
61 // Wrapped line support
62 int widthLine;
63 int lines;
64
65 LineLayout(int maxLineLength_);
66 virtual ~LineLayout();
67 void Resize(int maxLineLength_);
68 void Free();
69 void Invalidate(validLevel validity_);
70 int LineStart(int line) {
71 if (line <= 0) {
72 return 0;
73 } else if ((line >= lines) || !lineStarts) {
74 return numCharsInLine;
75 } else {
76 return lineStarts[line];
77 }
78 }
79 void SetLineStart(int line, int start);
80 void SetBracesHighlight(Range rangeLine, Position braces[],
81 char bracesMatchStyle, int xHighlight);
82 void RestoreBracesHighlight(Range rangeLine, Position braces[]);
83};
84
85/**
86 */
87class LineLayoutCache {
88 int level;
89 int length;
90 int size;
91 LineLayout **cache;
92 bool allInvalidated;
93 int styleClock;
94 void Allocate(int length_);
95 void AllocateForLevel(int linesOnScreen, int linesInDoc);
96public:
97 LineLayoutCache();
98 virtual ~LineLayoutCache();
99 void Deallocate();
100 enum {
101 llcNone=SC_CACHE_NONE,
102 llcCaret=SC_CACHE_CARET,
103 llcPage=SC_CACHE_PAGE,
104 llcDocument=SC_CACHE_DOCUMENT
105 };
106 void Invalidate(LineLayout::validLevel validity_);
107 void SetLevel(int level_);
108 int GetLevel() { return level; }
109 LineLayout *Retrieve(int lineNumber, int lineCaret, int maxChars, int styleClock_,
110 int linesOnScreen, int linesInDoc);
111 void Dispose(LineLayout *ll);
9ce192d4
RD
112};
113
b8b0e402
RD
114class SelectionText {
115public:
116 char *s;
117 int len;
118 bool rectangular;
119 SelectionText() : s(0), len(0), rectangular(false) {}
120 ~SelectionText() {
121 Set(0, 0);
122 }
123 void Set(char *s_, int len_, bool rectangular_=false) {
124 delete []s;
125 s = s_;
126 if (s)
127 len = len_;
128 else
129 len = 0;
130 rectangular = rectangular_;
131 }
132};
133
1a2fb4cd
RD
134/**
135 * A smart pointer class to ensure Surfaces are set up and deleted correctly.
136 */
137class AutoSurface {
138private:
139 Surface *surf;
140public:
141 AutoSurface(bool unicodeMode) {
142 surf = Surface::Allocate();
143 if (surf) {
144 surf->Init();
145 surf->SetUnicodeMode(unicodeMode);
146 }
147 }
148 AutoSurface(SurfaceID sid, bool unicodeMode) {
149 surf = Surface::Allocate();
150 if (surf) {
151 surf->Init(sid);
152 surf->SetUnicodeMode(unicodeMode);
153 }
154 }
155 ~AutoSurface() {
156 delete surf;
157 }
158 Surface *operator->() const {
159 return surf;
160 }
161 operator Surface *() const {
162 return surf;
163 }
164};
165
65ec6247
RD
166/**
167 */
9ce192d4 168class Editor : public DocWatcher {
f6bcfd97
BP
169 // Private so Editor objects can not be copied
170 Editor(const Editor &) : DocWatcher() {}
171 Editor &operator=(const Editor &) { return *this; }
65ec6247 172
9ce192d4
RD
173protected: // ScintillaBase subclass needs access to much of Editor
174
65ec6247
RD
175 /** On GTK+, Scintilla is a container widget holding two scroll bars
176 * whereas on Windows there is just one window with both scroll bars turned on. */
177 Window wMain; ///< The Scintilla parent window
9ce192d4 178
65ec6247
RD
179 /** Style resources may be expensive to allocate so are cached between uses.
180 * When a style attribute is changed, this cache is flushed. */
1a2fb4cd 181 bool stylesValid;
9ce192d4
RD
182 ViewStyle vs;
183 Palette palette;
b8b0e402 184
d134f170
RD
185 int printMagnification;
186 int printColourMode;
65ec6247 187 int cursorMode;
1a2fb4cd 188 int controlCharSymbol;
65ec6247
RD
189
190 bool hasFocus;
9ce192d4
RD
191 bool hideSelection;
192 bool inOverstrike;
65ec6247
RD
193 int errorStatus;
194 bool mouseDownCaptures;
1a2fb4cd 195
65ec6247
RD
196 /** In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to
197 * the screen. This avoids flashing but is about 30% slower. */
9ce192d4
RD
198 bool bufferedDraw;
199
65ec6247
RD
200 int xOffset; ///< Horizontal scrolled amount in pixels
201 int xCaretMargin; ///< Ensure this many pixels visible on both sides of caret
f6bcfd97 202 bool horizontalScrollBarVisible;
1a2fb4cd
RD
203
204 Surface *pixmapLine;
205 Surface *pixmapSelMargin;
206 Surface *pixmapSelPattern;
207 Surface *pixmapIndentGuide;
208 Surface *pixmapIndentGuideHighlight;
209
210 LineLayoutCache llc;
9ce192d4
RD
211
212 KeyMap kmap;
213
214 Caret caret;
215 Timer timer;
65ec6247
RD
216 Timer autoScrollTimer;
217 enum { autoScrollDelay = 200 };
9ce192d4
RD
218
219 Point lastClick;
220 unsigned int lastClickTime;
65ec6247
RD
221 int dwellDelay;
222 int ticksToDwell;
223 bool dwelling;
9ce192d4
RD
224 enum { selChar, selWord, selLine } selectionType;
225 Point ptMouseLast;
9ce192d4
RD
226 bool inDragDrop;
227 bool dropWentOutside;
228 int posDrag;
229 int posDrop;
230 int lastXChosen;
231 int lineAnchor;
232 int originalAnchorPos;
233 int currentPos;
234 int anchor;
65ec6247
RD
235 int targetStart;
236 int targetEnd;
237 int searchFlags;
9ce192d4
RD
238 int topLine;
239 int posTopLine;
1a2fb4cd 240
9ce192d4
RD
241 bool needUpdateUI;
242 Position braces[2];
243 int bracesMatchStyle;
d134f170 244 int highlightGuideColumn;
1a2fb4cd 245
9ce192d4
RD
246 int theEdge;
247
248 enum { notPainting, painting, paintAbandoned } paintState;
249 PRectangle rcPaint;
250 bool paintingAllText;
1a2fb4cd 251
9ce192d4 252 int modEventMask;
1a2fb4cd 253
b8b0e402 254 SelectionText drag;
9ce192d4
RD
255 enum { selStream, selRectangle, selRectangleFixed } selType;
256 int xStartSelect;
257 int xEndSelect;
d134f170 258 bool primarySelection;
1a2fb4cd 259
9ce192d4
RD
260 int caretPolicy;
261 int caretSlop;
262
65ec6247
RD
263 int visiblePolicy;
264 int visibleSlop;
1a2fb4cd 265
9ce192d4
RD
266 int searchAnchor;
267
b8b0e402 268 bool recordingMacro;
9ce192d4
RD
269
270 int foldFlags;
271 ContractionState cs;
272
1a2fb4cd
RD
273 // Wrapping support
274 enum { eWrapNone, eWrapWord } wrapState;
275 int wrapWidth;
276 int docLineLastWrapped;
277
9ce192d4
RD
278 Document *pdoc;
279
280 Editor();
281 virtual ~Editor();
282 virtual void Initialise() = 0;
283 virtual void Finalise();
284
285 void InvalidateStyleData();
286 void InvalidateStyleRedraw();
287 virtual void RefreshColourPalette(Palette &pal, bool want);
288 void RefreshStyleData();
289 void DropGraphics();
290
65ec6247 291 virtual PRectangle GetClientRectangle();
9ce192d4 292 PRectangle GetTextRectangle();
1a2fb4cd 293
9ce192d4
RD
294 int LinesOnScreen();
295 int LinesToScroll();
296 int MaxScrollPos();
65ec6247
RD
297 Point LocationFromPosition(int pos);
298 int XFromPosition(int pos);
9ce192d4 299 int PositionFromLocation(Point pt);
65ec6247 300 int PositionFromLocationClose(Point pt);
9ce192d4
RD
301 int PositionFromLineX(int line, int x);
302 int LineFromLocation(Point pt);
303 void SetTopLine(int topLineNew);
1a2fb4cd 304
9ce192d4
RD
305 void RedrawRect(PRectangle rc);
306 void Redraw();
307 void RedrawSelMargin();
308 PRectangle RectangleFromRange(int start, int end);
309 void InvalidateRange(int start, int end);
1a2fb4cd 310
9ce192d4
RD
311 int CurrentPosition();
312 bool SelectionEmpty();
313 int SelectionStart(int line=-1);
314 int SelectionEnd(int line=-1);
315 void SetSelection(int currentPos_, int anchor_);
316 void SetSelection(int currentPos_);
317 void SetEmptySelection(int currentPos_);
d134f170 318 int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true);
9ce192d4
RD
319 int MovePositionTo(int newPos, bool extend = false);
320 int MovePositionSoVisible(int pos, int moveDir);
321 void SetLastXChosen();
322
323 void ScrollTo(int line);
324 virtual void ScrollText(int linesToMove);
325 void HorizontalScrollTo(int xPos);
f6bcfd97 326 void MoveCaretInsideView();
1a2fb4cd 327 int DisplayFromPosition(int pos);
65ec6247 328 void EnsureCaretVisible(bool useMargin=true, bool vert=true, bool horiz=true);
9ce192d4
RD
329 void ShowCaretAtCurrentPosition();
330 void DropCaret();
331 void InvalidateCaret();
332
1a2fb4cd
RD
333 void NeedWrapping(int docLineStartWrapping=0);
334 bool WrapLines();
335
65ec6247 336 int SubstituteMarkerIfEmpty(int markerCheck, int markerDefault);
9ce192d4 337 void PaintSelMargin(Surface *surface, PRectangle &rc);
1a2fb4cd
RD
338 LineLayout *RetrieveLineLayout(int lineNumber);
339 void LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayout *ll,
340 int width=LineLayout::wrapWidthInfinite);
341 void DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVisible, int xStart,
342 PRectangle rcLine, LineLayout *ll, int subLine=0);
9ce192d4 343 void Paint(Surface *surfaceWindow, PRectangle rcArea);
d134f170 344 long FormatRange(bool draw, RangeToFormat *pfr);
9ce192d4
RD
345
346 virtual void SetVerticalScrollPos() = 0;
347 virtual void SetHorizontalScrollPos() = 0;
348 virtual bool ModifyScrollBars(int nMax, int nPage) = 0;
f6bcfd97 349 virtual void ReconfigureScrollBars();
9ce192d4 350 void SetScrollBars();
1a2fb4cd 351 void ChangeSize();
9ce192d4 352
f6bcfd97 353 void AddChar(char ch);
1a2fb4cd 354 virtual void AddCharUTF(char *s, unsigned int len, bool treatAsDBCS=false);
9ce192d4
RD
355 void ClearSelection();
356 void ClearAll();
d134f170 357 void ClearDocumentStyle();
9ce192d4
RD
358 void Cut();
359 void PasteRectangular(int pos, const char *ptr, int len);
360 virtual void Copy() = 0;
65ec6247 361 virtual bool CanPaste();
9ce192d4
RD
362 virtual void Paste() = 0;
363 void Clear();
364 void SelectAll();
365 void Undo();
366 void Redo();
367 void DelChar();
1a2fb4cd 368 void DelCharBack(bool allowLineStartDeletion);
9ce192d4
RD
369 virtual void ClaimSelection() = 0;
370
371 virtual void NotifyChange() = 0;
372 virtual void NotifyFocus(bool focus);
1a2fb4cd 373 virtual int GetCtrlID() { return ctrlID; }
9ce192d4 374 virtual void NotifyParent(SCNotification scn) = 0;
f6bcfd97 375 virtual void NotifyStyleToNeeded(int endStyleNeeded);
65ec6247 376 void NotifyChar(int ch);
d134f170 377 void NotifyMove(int position);
9ce192d4
RD
378 void NotifySavePoint(bool isSavePoint);
379 void NotifyModifyAttempt();
380 virtual void NotifyDoubleClick(Point pt, bool shift);
381 void NotifyUpdateUI();
65ec6247 382 void NotifyPainted();
9ce192d4
RD
383 bool NotifyMarginClick(Point pt, bool shift, bool ctrl, bool alt);
384 void NotifyNeedShown(int pos, int len);
65ec6247 385 void NotifyDwelling(Point pt, bool state);
1a2fb4cd 386
9ce192d4
RD
387 void NotifyModifyAttempt(Document *document, void *userData);
388 void NotifySavePoint(Document *document, void *userData, bool atSavePoint);
1a2fb4cd 389 void CheckModificationForWrap(DocModification mh);
9ce192d4
RD
390 void NotifyModified(Document *document, DocModification mh, void *userData);
391 void NotifyDeleted(Document *document, void *userData);
f6bcfd97 392 void NotifyStyleNeeded(Document *doc, void *userData, int endPos);
d134f170 393 void NotifyMacroRecord(unsigned int iMessage, unsigned long wParam, long lParam);
9ce192d4
RD
394
395 void PageMove(int direction, bool extend=false);
f6bcfd97
BP
396 void ChangeCaseOfSelection(bool makeUpperCase);
397 void LineTranspose();
d134f170
RD
398 virtual void CancelModes();
399 virtual int KeyCommand(unsigned int iMessage);
9ce192d4 400 virtual int KeyDefault(int /* key */, int /*modifiers*/);
65ec6247 401 int KeyDown(int key, bool shift, bool ctrl, bool alt, bool *consumed=0);
9ce192d4 402
d134f170
RD
403 int GetWhitespaceVisible();
404 void SetWhitespaceVisible(int view);
9ce192d4
RD
405
406 void Indent(bool forwards);
407
b8b0e402 408 long FindText(unsigned long wParam, long lParam);
9ce192d4 409 void SearchAnchor();
d134f170 410 long SearchText(unsigned int iMessage, unsigned long wParam, long lParam);
65ec6247 411 long SearchInTarget(const char *text, int length);
9ce192d4
RD
412 void GoToLine(int lineNo);
413
414 char *CopyRange(int start, int end);
b8b0e402 415 void CopySelectionRange(SelectionText *ss);
9ce192d4 416 void SetDragPosition(int newPos);
65ec6247 417 void DisplayCursor(Window::Cursor c);
9ce192d4
RD
418 virtual void StartDrag();
419 void DropAt(int position, const char *value, bool moving, bool rectangular);
65ec6247
RD
420 /** PositionInSelection returns 0 if position in selection, -1 if position before selection, and 1 if after.
421 * Before means either before any line of selection or before selection on its line, with a similar meaning to after. */
9ce192d4
RD
422 int PositionInSelection(int pos);
423 bool PointInSelection(Point pt);
424 bool PointInSelMargin(Point pt);
65ec6247
RD
425 void LineSelection(int lineCurrent_, int lineAnchor_);
426 void DwellEnd(bool mouseMoved);
9ce192d4
RD
427 virtual void ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt);
428 void ButtonMove(Point pt);
429 void ButtonUp(Point pt, unsigned int curTime, bool ctrl);
430
431 void Tick();
432 virtual void SetTicking(bool on) = 0;
433 virtual void SetMouseCapture(bool on) = 0;
434 virtual bool HaveMouseCapture() = 0;
65ec6247 435 void SetFocusState(bool focusState);
9ce192d4
RD
436
437 void CheckForChangeOutsidePaint(Range r);
438 int BraceMatch(int position, int maxReStyle);
439 void SetBraceHighlight(Position pos0, Position pos1, int matchStyle);
1a2fb4cd 440
9ce192d4 441 void SetDocPointer(Document *document);
1a2fb4cd 442
9ce192d4
RD
443 void Expand(int &line, bool doExpand);
444 void ToggleContraction(int line);
65ec6247
RD
445 void EnsureLineVisible(int lineDoc, bool enforcePolicy);
446 int ReplaceTarget(bool replacePatterns, const char *text, int length=-1);
9ce192d4 447
65ec6247 448 virtual sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) = 0;
1a2fb4cd 449
9ce192d4 450public:
1a2fb4cd
RD
451 // Public so the COM thunks can access it.
452 bool IsUnicodeMode() const;
453 // Public so scintilla_send_message can use it.
65ec6247 454 virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
1a2fb4cd
RD
455 // Public so scintilla_set_id can use it.
456 int ctrlID;
9ce192d4
RD
457};
458
459#endif