]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/Editor.h
d9719dc534e7fb1ebafb12a75ceeb0dd33d84608
[wxWidgets.git] / contrib / src / stc / scintilla / src / Editor.h
1 // Scintilla source code edit control
2 /** @file Editor.h
3 ** Defines the main editor class.
4 **/
5 // Copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org>
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
11 /**
12 */
13 class Caret {
14 public:
15 bool active;
16 bool on;
17 int period;
18
19 Caret();
20 };
21
22 /**
23 */
24 class Timer {
25 public:
26 bool ticking;
27 int ticksToWait;
28 enum {tickSize = 100};
29 TickerID tickerID;
30
31 Timer();
32 };
33
34 /**
35 */
36 class LineLayout {
37 private:
38 friend class LineLayoutCache;
39 int *lineStarts;
40 int lenLineStarts;
41 /// Drawing is only performed for @a maxLineLength characters on each line.
42 int lineNumber;
43 bool inCache;
44 public:
45 enum { wrapWidthInfinite = 0x7ffffff };
46 int maxLineLength;
47 int numCharsInLine;
48 enum validLevel { llInvalid, llPositions, llLines } validity;
49 int xHighlightGuide;
50 bool highlightColumn;
51 int selStart;
52 int selEnd;
53 bool containsCaret;
54 int edgeColumn;
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 */
87 class 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);
96 public:
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);
112 };
113
114 class SelectionText {
115 public:
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
134 /**
135 * A smart pointer class to ensure Surfaces are set up and deleted correctly.
136 */
137 class AutoSurface {
138 private:
139 Surface *surf;
140 public:
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
166 /**
167 */
168 class Editor : public DocWatcher {
169 // Private so Editor objects can not be copied
170 Editor(const Editor &) : DocWatcher() {}
171 Editor &operator=(const Editor &) { return *this; }
172
173 protected: // ScintillaBase subclass needs access to much of Editor
174
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
178
179 /** Style resources may be expensive to allocate so are cached between uses.
180 * When a style attribute is changed, this cache is flushed. */
181 bool stylesValid;
182 ViewStyle vs;
183 Palette palette;
184
185 int printMagnification;
186 int printColourMode;
187 int cursorMode;
188 int controlCharSymbol;
189
190 bool hasFocus;
191 bool hideSelection;
192 bool inOverstrike;
193 int errorStatus;
194 bool mouseDownCaptures;
195
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. */
198 bool bufferedDraw;
199
200 int xOffset; ///< Horizontal scrolled amount in pixels
201 int xCaretMargin; ///< Ensure this many pixels visible on both sides of caret
202 bool horizontalScrollBarVisible;
203
204 Surface *pixmapLine;
205 Surface *pixmapSelMargin;
206 Surface *pixmapSelPattern;
207 Surface *pixmapIndentGuide;
208 Surface *pixmapIndentGuideHighlight;
209
210 LineLayoutCache llc;
211
212 KeyMap kmap;
213
214 Caret caret;
215 Timer timer;
216 Timer autoScrollTimer;
217 enum { autoScrollDelay = 200 };
218
219 Point lastClick;
220 unsigned int lastClickTime;
221 int dwellDelay;
222 int ticksToDwell;
223 bool dwelling;
224 enum { selChar, selWord, selLine } selectionType;
225 Point ptMouseLast;
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;
235 int targetStart;
236 int targetEnd;
237 int searchFlags;
238 int topLine;
239 int posTopLine;
240
241 bool needUpdateUI;
242 Position braces[2];
243 int bracesMatchStyle;
244 int highlightGuideColumn;
245
246 int theEdge;
247
248 enum { notPainting, painting, paintAbandoned } paintState;
249 PRectangle rcPaint;
250 bool paintingAllText;
251
252 int modEventMask;
253
254 SelectionText drag;
255 enum { selStream, selRectangle, selRectangleFixed } selType;
256 int xStartSelect;
257 int xEndSelect;
258 bool primarySelection;
259
260 int caretPolicy;
261 int caretSlop;
262
263 int visiblePolicy;
264 int visibleSlop;
265
266 int searchAnchor;
267
268 bool recordingMacro;
269
270 int foldFlags;
271 ContractionState cs;
272
273 // Wrapping support
274 enum { eWrapNone, eWrapWord } wrapState;
275 int wrapWidth;
276 int docLineLastWrapped;
277
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
291 virtual PRectangle GetClientRectangle();
292 PRectangle GetTextRectangle();
293
294 int LinesOnScreen();
295 int LinesToScroll();
296 int MaxScrollPos();
297 Point LocationFromPosition(int pos);
298 int XFromPosition(int pos);
299 int PositionFromLocation(Point pt);
300 int PositionFromLocationClose(Point pt);
301 int PositionFromLineX(int line, int x);
302 int LineFromLocation(Point pt);
303 void SetTopLine(int topLineNew);
304
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);
310
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_);
318 int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true);
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);
326 void MoveCaretInsideView();
327 int DisplayFromPosition(int pos);
328 void EnsureCaretVisible(bool useMargin=true, bool vert=true, bool horiz=true);
329 void ShowCaretAtCurrentPosition();
330 void DropCaret();
331 void InvalidateCaret();
332
333 void NeedWrapping(int docLineStartWrapping=0);
334 bool WrapLines();
335
336 int SubstituteMarkerIfEmpty(int markerCheck, int markerDefault);
337 void PaintSelMargin(Surface *surface, PRectangle &rc);
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);
343 void Paint(Surface *surfaceWindow, PRectangle rcArea);
344 long FormatRange(bool draw, RangeToFormat *pfr);
345
346 virtual void SetVerticalScrollPos() = 0;
347 virtual void SetHorizontalScrollPos() = 0;
348 virtual bool ModifyScrollBars(int nMax, int nPage) = 0;
349 virtual void ReconfigureScrollBars();
350 void SetScrollBars();
351 void ChangeSize();
352
353 void AddChar(char ch);
354 virtual void AddCharUTF(char *s, unsigned int len, bool treatAsDBCS=false);
355 void ClearSelection();
356 void ClearAll();
357 void ClearDocumentStyle();
358 void Cut();
359 void PasteRectangular(int pos, const char *ptr, int len);
360 virtual void Copy() = 0;
361 virtual bool CanPaste();
362 virtual void Paste() = 0;
363 void Clear();
364 void SelectAll();
365 void Undo();
366 void Redo();
367 void DelChar();
368 void DelCharBack(bool allowLineStartDeletion);
369 virtual void ClaimSelection() = 0;
370
371 virtual void NotifyChange() = 0;
372 virtual void NotifyFocus(bool focus);
373 virtual int GetCtrlID() { return ctrlID; }
374 virtual void NotifyParent(SCNotification scn) = 0;
375 virtual void NotifyStyleToNeeded(int endStyleNeeded);
376 void NotifyChar(int ch);
377 void NotifyMove(int position);
378 void NotifySavePoint(bool isSavePoint);
379 void NotifyModifyAttempt();
380 virtual void NotifyDoubleClick(Point pt, bool shift);
381 void NotifyUpdateUI();
382 void NotifyPainted();
383 bool NotifyMarginClick(Point pt, bool shift, bool ctrl, bool alt);
384 void NotifyNeedShown(int pos, int len);
385 void NotifyDwelling(Point pt, bool state);
386
387 void NotifyModifyAttempt(Document *document, void *userData);
388 void NotifySavePoint(Document *document, void *userData, bool atSavePoint);
389 void CheckModificationForWrap(DocModification mh);
390 void NotifyModified(Document *document, DocModification mh, void *userData);
391 void NotifyDeleted(Document *document, void *userData);
392 void NotifyStyleNeeded(Document *doc, void *userData, int endPos);
393 void NotifyMacroRecord(unsigned int iMessage, unsigned long wParam, long lParam);
394
395 void PageMove(int direction, bool extend=false);
396 void ChangeCaseOfSelection(bool makeUpperCase);
397 void LineTranspose();
398 virtual void CancelModes();
399 virtual int KeyCommand(unsigned int iMessage);
400 virtual int KeyDefault(int /* key */, int /*modifiers*/);
401 int KeyDown(int key, bool shift, bool ctrl, bool alt, bool *consumed=0);
402
403 int GetWhitespaceVisible();
404 void SetWhitespaceVisible(int view);
405
406 void Indent(bool forwards);
407
408 long FindText(unsigned long wParam, long lParam);
409 void SearchAnchor();
410 long SearchText(unsigned int iMessage, unsigned long wParam, long lParam);
411 long SearchInTarget(const char *text, int length);
412 void GoToLine(int lineNo);
413
414 char *CopyRange(int start, int end);
415 void CopySelectionRange(SelectionText *ss);
416 void SetDragPosition(int newPos);
417 void DisplayCursor(Window::Cursor c);
418 virtual void StartDrag();
419 void DropAt(int position, const char *value, bool moving, bool rectangular);
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. */
422 int PositionInSelection(int pos);
423 bool PointInSelection(Point pt);
424 bool PointInSelMargin(Point pt);
425 void LineSelection(int lineCurrent_, int lineAnchor_);
426 void DwellEnd(bool mouseMoved);
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;
435 void SetFocusState(bool focusState);
436
437 void CheckForChangeOutsidePaint(Range r);
438 int BraceMatch(int position, int maxReStyle);
439 void SetBraceHighlight(Position pos0, Position pos1, int matchStyle);
440
441 void SetDocPointer(Document *document);
442
443 void Expand(int &line, bool doExpand);
444 void ToggleContraction(int line);
445 void EnsureLineVisible(int lineDoc, bool enforcePolicy);
446 int ReplaceTarget(bool replacePatterns, const char *text, int length=-1);
447
448 virtual sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) = 0;
449
450 public:
451 // Public so the COM thunks can access it.
452 bool IsUnicodeMode() const;
453 // Public so scintilla_send_message can use it.
454 virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
455 // Public so scintilla_set_id can use it.
456 int ctrlID;
457 };
458
459 #endif