]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/Editor.h
451f123411e6d44138924706398e2cbe17123441
[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, llCheckTextAndStyle, 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 int scrollWidth;
204 bool endAtLastLine;
205
206 Surface *pixmapLine;
207 Surface *pixmapSelMargin;
208 Surface *pixmapSelPattern;
209 Surface *pixmapIndentGuide;
210 Surface *pixmapIndentGuideHighlight;
211
212 LineLayoutCache llc;
213
214 KeyMap kmap;
215
216 Caret caret;
217 Timer timer;
218 Timer autoScrollTimer;
219 enum { autoScrollDelay = 200 };
220
221 Point lastClick;
222 unsigned int lastClickTime;
223 int dwellDelay;
224 int ticksToDwell;
225 bool dwelling;
226 enum { selChar, selWord, selLine } selectionType;
227 Point ptMouseLast;
228 bool inDragDrop;
229 bool dropWentOutside;
230 int posDrag;
231 int posDrop;
232 int lastXChosen;
233 int lineAnchor;
234 int originalAnchorPos;
235 int currentPos;
236 int anchor;
237 int targetStart;
238 int targetEnd;
239 int searchFlags;
240 int topLine;
241 int posTopLine;
242
243 bool needUpdateUI;
244 Position braces[2];
245 int bracesMatchStyle;
246 int highlightGuideColumn;
247
248 int theEdge;
249
250 enum { notPainting, painting, paintAbandoned } paintState;
251 PRectangle rcPaint;
252 bool paintingAllText;
253
254 int modEventMask;
255
256 SelectionText drag;
257 enum { selStream, selRectangle, selRectangleFixed } selType;
258 int xStartSelect;
259 int xEndSelect;
260 bool primarySelection;
261
262 int caretXPolicy;
263 int caretXSlop; ///< Ensure this many pixels visible on both sides of caret
264
265 int caretYPolicy;
266 int caretYSlop; ///< Ensure this many lines visible on both sides of caret
267
268 int visiblePolicy;
269 int visibleSlop;
270
271 int searchAnchor;
272
273 bool recordingMacro;
274
275 int foldFlags;
276 ContractionState cs;
277
278 // Wrapping support
279 enum { eWrapNone, eWrapWord } wrapState;
280 int wrapWidth;
281 int docLineLastWrapped;
282
283 Document *pdoc;
284
285 Editor();
286 virtual ~Editor();
287 virtual void Initialise() = 0;
288 virtual void Finalise();
289
290 void InvalidateStyleData();
291 void InvalidateStyleRedraw();
292 virtual void RefreshColourPalette(Palette &pal, bool want);
293 void RefreshStyleData();
294 void DropGraphics();
295
296 virtual PRectangle GetClientRectangle();
297 PRectangle GetTextRectangle();
298
299 int LinesOnScreen();
300 int LinesToScroll();
301 int MaxScrollPos();
302 Point LocationFromPosition(int pos);
303 int XFromPosition(int pos);
304 int PositionFromLocation(Point pt);
305 int PositionFromLocationClose(Point pt);
306 int PositionFromLineX(int line, int x);
307 int LineFromLocation(Point pt);
308 void SetTopLine(int topLineNew);
309
310 bool AbandonPaint();
311 void RedrawRect(PRectangle rc);
312 void Redraw();
313 void RedrawSelMargin();
314 PRectangle RectangleFromRange(int start, int end);
315 void InvalidateRange(int start, int end);
316
317 int CurrentPosition();
318 bool SelectionEmpty();
319 int SelectionStart(int line=-1);
320 int SelectionEnd(int line=-1);
321 void SetSelection(int currentPos_, int anchor_);
322 void SetSelection(int currentPos_);
323 void SetEmptySelection(int currentPos_);
324 int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true);
325 int MovePositionTo(int newPos, bool extend = false);
326 int MovePositionSoVisible(int pos, int moveDir);
327 void SetLastXChosen();
328
329 void ScrollTo(int line);
330 virtual void ScrollText(int linesToMove);
331 void HorizontalScrollTo(int xPos);
332 void MoveCaretInsideView();
333 int DisplayFromPosition(int pos);
334 void EnsureCaretVisible(bool useMargin=true, bool vert=true, bool horiz=true);
335 void ShowCaretAtCurrentPosition();
336 void DropCaret();
337 void InvalidateCaret();
338
339 void NeedWrapping(int docLineStartWrapping=0);
340 bool WrapLines();
341
342 int SubstituteMarkerIfEmpty(int markerCheck, int markerDefault);
343 void PaintSelMargin(Surface *surface, PRectangle &rc);
344 LineLayout *RetrieveLineLayout(int lineNumber);
345 void LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayout *ll,
346 int width=LineLayout::wrapWidthInfinite);
347 void DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVisible, int xStart,
348 PRectangle rcLine, LineLayout *ll, int subLine=0);
349 void Paint(Surface *surfaceWindow, PRectangle rcArea);
350 long FormatRange(bool draw, RangeToFormat *pfr);
351 int TextWidth(int style, const char *text);
352
353 virtual void SetVerticalScrollPos() = 0;
354 virtual void SetHorizontalScrollPos() = 0;
355 virtual bool ModifyScrollBars(int nMax, int nPage) = 0;
356 virtual void ReconfigureScrollBars();
357 void SetScrollBars();
358 void ChangeSize();
359
360 void AddChar(char ch);
361 virtual void AddCharUTF(char *s, unsigned int len, bool treatAsDBCS=false);
362 void ClearSelection();
363 void ClearAll();
364 void ClearDocumentStyle();
365 void Cut();
366 void PasteRectangular(int pos, const char *ptr, int len);
367 virtual void Copy() = 0;
368 virtual bool CanPaste();
369 virtual void Paste() = 0;
370 void Clear();
371 void SelectAll();
372 void Undo();
373 void Redo();
374 void DelChar();
375 void DelCharBack(bool allowLineStartDeletion);
376 virtual void ClaimSelection() = 0;
377
378 virtual void NotifyChange() = 0;
379 virtual void NotifyFocus(bool focus);
380 virtual int GetCtrlID() { return ctrlID; }
381 virtual void NotifyParent(SCNotification scn) = 0;
382 virtual void NotifyStyleToNeeded(int endStyleNeeded);
383 void NotifyChar(int ch);
384 void NotifyMove(int position);
385 void NotifySavePoint(bool isSavePoint);
386 void NotifyModifyAttempt();
387 virtual void NotifyDoubleClick(Point pt, bool shift);
388 void NotifyUpdateUI();
389 void NotifyPainted();
390 bool NotifyMarginClick(Point pt, bool shift, bool ctrl, bool alt);
391 void NotifyNeedShown(int pos, int len);
392 void NotifyDwelling(Point pt, bool state);
393 void NotifyZoom();
394
395 void NotifyModifyAttempt(Document *document, void *userData);
396 void NotifySavePoint(Document *document, void *userData, bool atSavePoint);
397 void CheckModificationForWrap(DocModification mh);
398 void NotifyModified(Document *document, DocModification mh, void *userData);
399 void NotifyDeleted(Document *document, void *userData);
400 void NotifyStyleNeeded(Document *doc, void *userData, int endPos);
401 void NotifyMacroRecord(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
402
403 void PageMove(int direction, bool extend=false);
404 void ChangeCaseOfSelection(bool makeUpperCase);
405 void LineTranspose();
406 virtual void CancelModes();
407 void NewLine();
408 void CursorUpOrDown(int direction, bool extend=false);
409 virtual int KeyCommand(unsigned int iMessage);
410 virtual int KeyDefault(int /* key */, int /*modifiers*/);
411 int KeyDown(int key, bool shift, bool ctrl, bool alt, bool *consumed=0);
412
413 int GetWhitespaceVisible();
414 void SetWhitespaceVisible(int view);
415
416 void Indent(bool forwards);
417
418 long FindText(uptr_t wParam, sptr_t lParam);
419 void SearchAnchor();
420 long SearchText(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
421 long SearchInTarget(const char *text, int length);
422 void GoToLine(int lineNo);
423
424 char *CopyRange(int start, int end);
425 void CopySelectionRange(SelectionText *ss);
426 void SetDragPosition(int newPos);
427 void DisplayCursor(Window::Cursor c);
428 virtual void StartDrag();
429 void DropAt(int position, const char *value, bool moving, bool rectangular);
430 /** PositionInSelection returns 0 if position in selection, -1 if position before selection, and 1 if after.
431 * Before means either before any line of selection or before selection on its line, with a similar meaning to after. */
432 int PositionInSelection(int pos);
433 bool PointInSelection(Point pt);
434 bool PointInSelMargin(Point pt);
435 void LineSelection(int lineCurrent_, int lineAnchor_);
436 void DwellEnd(bool mouseMoved);
437 virtual void ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt);
438 void ButtonMove(Point pt);
439 void ButtonUp(Point pt, unsigned int curTime, bool ctrl);
440
441 void Tick();
442 virtual void SetTicking(bool on) = 0;
443 virtual void SetMouseCapture(bool on) = 0;
444 virtual bool HaveMouseCapture() = 0;
445 void SetFocusState(bool focusState);
446
447 void CheckForChangeOutsidePaint(Range r);
448 int BraceMatch(int position, int maxReStyle);
449 void SetBraceHighlight(Position pos0, Position pos1, int matchStyle);
450
451 void SetDocPointer(Document *document);
452
453 void Expand(int &line, bool doExpand);
454 void ToggleContraction(int line);
455 void EnsureLineVisible(int lineDoc, bool enforcePolicy);
456 int ReplaceTarget(bool replacePatterns, const char *text, int length=-1);
457
458 virtual sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) = 0;
459
460 public:
461 // Public so the COM thunks can access it.
462 bool IsUnicodeMode() const;
463 // Public so scintilla_send_message can use it.
464 virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
465 // Public so scintilla_set_id can use it.
466 int ctrlID;
467 };
468
469 #endif