]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/Editor.h
allow customizing wxStandardPaths logic for the program directory determination
[wxWidgets.git] / 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-2003 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 #ifdef SCI_NAMESPACE
12 namespace Scintilla {
13 #endif
14
15 /**
16 */
17 class Caret {
18 public:
19 bool active;
20 bool on;
21 int period;
22
23 Caret();
24 };
25
26 /**
27 */
28 class Timer {
29 public:
30 bool ticking;
31 int ticksToWait;
32 enum {tickSize = 100};
33 TickerID tickerID;
34
35 Timer();
36 };
37
38 /**
39 */
40 class Idler {
41 public:
42 bool state;
43 IdlerID idlerID;
44
45 Idler();
46 };
47
48 /**
49 * Hold a piece of text selected for copying or dragging.
50 * The text is expected to hold a terminating '\0' and this is counted in len.
51 */
52 class SelectionText {
53 public:
54 char *s;
55 int len;
56 bool rectangular;
57 int codePage;
58 int characterSet;
59 SelectionText() : s(0), len(0), rectangular(false), codePage(0), characterSet(0) {}
60 ~SelectionText() {
61 Free();
62 }
63 void Free() {
64 Set(0, 0, 0, 0, false);
65 }
66 void Set(char *s_, int len_, int codePage_, int characterSet_, bool rectangular_) {
67 delete []s;
68 s = s_;
69 if (s)
70 len = len_;
71 else
72 len = 0;
73 codePage = codePage_;
74 characterSet = characterSet_;
75 rectangular = rectangular_;
76 }
77 void Copy(const char *s_, int len_, int codePage_, int characterSet_, bool rectangular_) {
78 delete []s;
79 s = new char[len_];
80 if (s) {
81 len = len_;
82 for (int i = 0; i < len_; i++) {
83 s[i] = s_[i];
84 }
85 } else {
86 len = 0;
87 }
88 codePage = codePage_;
89 characterSet = characterSet_;
90 rectangular = rectangular_;
91 }
92 void Copy(const SelectionText &other) {
93 Copy(other.s, other.len, other.codePage, other.characterSet, other.rectangular);
94 }
95 };
96
97 /**
98 */
99 class Editor : public DocWatcher {
100 // Private so Editor objects can not be copied
101 Editor(const Editor &) : DocWatcher() {}
102 Editor &operator=(const Editor &) { return *this; }
103
104 protected: // ScintillaBase subclass needs access to much of Editor
105
106 /** On GTK+, Scintilla is a container widget holding two scroll bars
107 * whereas on Windows there is just one window with both scroll bars turned on. */
108 Window wMain; ///< The Scintilla parent window
109
110 /** Style resources may be expensive to allocate so are cached between uses.
111 * When a style attribute is changed, this cache is flushed. */
112 bool stylesValid;
113 ViewStyle vs;
114 Palette palette;
115
116 int printMagnification;
117 int printColourMode;
118 int printWrapState;
119 int cursorMode;
120 int controlCharSymbol;
121
122 bool hasFocus;
123 bool hideSelection;
124 bool inOverstrike;
125 int errorStatus;
126 bool mouseDownCaptures;
127
128 /** In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to
129 * the screen. This avoids flashing but is about 30% slower. */
130 bool bufferedDraw;
131 /** In twoPhaseDraw mode, drawing is performed in two phases, first the background
132 * and then the foreground. This avoids chopping off characters that overlap the next run. */
133 bool twoPhaseDraw;
134
135 int xOffset; ///< Horizontal scrolled amount in pixels
136 int xCaretMargin; ///< Ensure this many pixels visible on both sides of caret
137 bool horizontalScrollBarVisible;
138 int scrollWidth;
139 bool trackLineWidth;
140 int lineWidthMaxSeen;
141 bool verticalScrollBarVisible;
142 bool endAtLastLine;
143 bool caretSticky;
144
145 Surface *pixmapLine;
146 Surface *pixmapSelMargin;
147 Surface *pixmapSelPattern;
148 Surface *pixmapIndentGuide;
149 Surface *pixmapIndentGuideHighlight;
150
151 LineLayoutCache llc;
152 PositionCache posCache;
153
154 KeyMap kmap;
155
156 Caret caret;
157 Timer timer;
158 Timer autoScrollTimer;
159 enum { autoScrollDelay = 200 };
160
161 Idler idler;
162
163 Point lastClick;
164 unsigned int lastClickTime;
165 int dwellDelay;
166 int ticksToDwell;
167 bool dwelling;
168 enum { selChar, selWord, selLine } selectionType;
169 Point ptMouseLast;
170 enum { ddNone, ddInitial, ddDragging } inDragDrop;
171 bool dropWentOutside;
172 int posDrag;
173 int posDrop;
174 int lastXChosen;
175 int lineAnchor;
176 int originalAnchorPos;
177 int currentPos;
178 int anchor;
179 int targetStart;
180 int targetEnd;
181 int searchFlags;
182 int topLine;
183 int posTopLine;
184 int lengthForEncode;
185
186 bool needUpdateUI;
187 Position braces[2];
188 int bracesMatchStyle;
189 int highlightGuideColumn;
190
191 int theEdge;
192
193 enum { notPainting, painting, paintAbandoned } paintState;
194 PRectangle rcPaint;
195 bool paintingAllText;
196
197 int modEventMask;
198
199 SelectionText drag;
200 enum selTypes { noSel, selStream, selRectangle, selLines };
201 selTypes selType;
202 bool moveExtendsSelection;
203 int xStartSelect; ///< x position of start of rectangular selection
204 int xEndSelect; ///< x position of end of rectangular selection
205 bool primarySelection;
206
207 int caretXPolicy;
208 int caretXSlop; ///< Ensure this many pixels visible on both sides of caret
209
210 int caretYPolicy;
211 int caretYSlop; ///< Ensure this many lines visible on both sides of caret
212
213 int visiblePolicy;
214 int visibleSlop;
215
216 int searchAnchor;
217
218 bool recordingMacro;
219
220 int foldFlags;
221 ContractionState cs;
222
223 // Hotspot support
224 int hsStart;
225 int hsEnd;
226
227 // Wrapping support
228 enum { eWrapNone, eWrapWord, eWrapChar } wrapState;
229 enum { wrapLineLarge = 0x7ffffff };
230 int wrapWidth;
231 int wrapStart;
232 int wrapEnd;
233 int wrapVisualFlags;
234 int wrapVisualFlagsLocation;
235 int wrapVisualStartIndent;
236 int actualWrapVisualStartIndent;
237
238 bool convertPastes;
239
240 Document *pdoc;
241
242 Editor();
243 virtual ~Editor();
244 virtual void Initialise() = 0;
245 virtual void Finalise();
246
247 void InvalidateStyleData();
248 void InvalidateStyleRedraw();
249 virtual void RefreshColourPalette(Palette &pal, bool want);
250 void RefreshStyleData();
251 void DropGraphics();
252
253 virtual PRectangle GetClientRectangle();
254 PRectangle GetTextRectangle();
255
256 int LinesOnScreen();
257 int LinesToScroll();
258 int MaxScrollPos();
259 Point LocationFromPosition(int pos);
260 int XFromPosition(int pos);
261 int PositionFromLocation(Point pt);
262 int PositionFromLocationClose(Point pt);
263 int PositionFromLineX(int line, int x);
264 int LineFromLocation(Point pt);
265 void SetTopLine(int topLineNew);
266
267 bool AbandonPaint();
268 void RedrawRect(PRectangle rc);
269 void Redraw();
270 void RedrawSelMargin(int line=-1);
271 PRectangle RectangleFromRange(int start, int end);
272 void InvalidateRange(int start, int end);
273
274 int CurrentPosition();
275 bool SelectionEmpty();
276 int SelectionStart();
277 int SelectionEnd();
278 void SetRectangularRange();
279 void InvalidateSelection(int currentPos_, int anchor_);
280 void SetSelection(int currentPos_, int anchor_);
281 void SetSelection(int currentPos_);
282 void SetEmptySelection(int currentPos_);
283 bool RangeContainsProtected(int start, int end) const;
284 bool SelectionContainsProtected();
285 int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true);
286 int MovePositionTo(int newPos, selTypes sel=noSel, bool ensureVisible=true);
287 int MovePositionSoVisible(int pos, int moveDir);
288 void SetLastXChosen();
289
290 void ScrollTo(int line, bool moveThumb=true);
291 virtual void ScrollText(int linesToMove);
292 void HorizontalScrollTo(int xPos);
293 void MoveCaretInsideView(bool ensureVisible=true);
294 int DisplayFromPosition(int pos);
295 void EnsureCaretVisible(bool useMargin=true, bool vert=true, bool horiz=true);
296 void ShowCaretAtCurrentPosition();
297 void DropCaret();
298 void InvalidateCaret();
299 virtual void UpdateSystemCaret();
300
301 void NeedWrapping(int docLineStart = 0, int docLineEnd = wrapLineLarge);
302 bool WrapOneLine(Surface *surface, int lineToWrap);
303 bool WrapLines(bool fullWrap, int priorityWrapLineStart);
304 void LinesJoin();
305 void LinesSplit(int pixelWidth);
306
307 int SubstituteMarkerIfEmpty(int markerCheck, int markerDefault);
308 void PaintSelMargin(Surface *surface, PRectangle &rc);
309 LineLayout *RetrieveLineLayout(int lineNumber);
310 void LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayout *ll,
311 int width=LineLayout::wrapWidthInfinite);
312 ColourAllocated SelectionBackground(ViewStyle &vsDraw);
313 ColourAllocated TextBackground(ViewStyle &vsDraw, bool overrideBackground, ColourAllocated background, bool inSelection, bool inHotspot, int styleMain, int i, LineLayout *ll);
314 void DrawIndentGuide(Surface *surface, int lineVisible, int lineHeight, int start, PRectangle rcSegment, bool highlight);
315 void DrawWrapMarker(Surface *surface, PRectangle rcPlace, bool isEndMarker, ColourAllocated wrapColour);
316 void DrawEOL(Surface *surface, ViewStyle &vsDraw, PRectangle rcLine, LineLayout *ll,
317 int line, int lineEnd, int xStart, int subLine, int subLineStart,
318 bool overrideBackground, ColourAllocated background,
319 bool drawWrapMark, ColourAllocated wrapColour);
320 void DrawIndicators(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
321 PRectangle rcLine, LineLayout *ll, int subLine, int lineEnd, bool under);
322 void DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVisible, int xStart,
323 PRectangle rcLine, LineLayout *ll, int subLine=0);
324 void DrawBlockCaret(Surface *surface, ViewStyle &vsDraw, LineLayout *ll, int subLine, int xStart, int offset, int posCaret, PRectangle rcCaret);
325 void RefreshPixMaps(Surface *surfaceWindow);
326 void Paint(Surface *surfaceWindow, PRectangle rcArea);
327 long FormatRange(bool draw, RangeToFormat *pfr);
328 int TextWidth(int style, const char *text);
329
330 virtual void SetVerticalScrollPos() = 0;
331 virtual void SetHorizontalScrollPos() = 0;
332 virtual bool ModifyScrollBars(int nMax, int nPage) = 0;
333 virtual void ReconfigureScrollBars();
334 void SetScrollBars();
335 void ChangeSize();
336
337 void AddChar(char ch);
338 virtual void AddCharUTF(char *s, unsigned int len, bool treatAsDBCS=false);
339 void ClearSelection();
340 void ClearAll();
341 void ClearDocumentStyle();
342 void Cut();
343 void PasteRectangular(int pos, const char *ptr, int len);
344 virtual void Copy() = 0;
345 virtual bool CanPaste();
346 virtual void Paste() = 0;
347 void Clear();
348 void SelectAll();
349 void Undo();
350 void Redo();
351 void DelChar();
352 void DelCharBack(bool allowLineStartDeletion);
353 virtual void ClaimSelection() = 0;
354
355 virtual void NotifyChange() = 0;
356 virtual void NotifyFocus(bool focus);
357 virtual int GetCtrlID() { return ctrlID; }
358 virtual void NotifyParent(SCNotification scn) = 0;
359 virtual void NotifyStyleToNeeded(int endStyleNeeded);
360 void NotifyChar(int ch);
361 void NotifyMove(int position);
362 void NotifySavePoint(bool isSavePoint);
363 void NotifyModifyAttempt();
364 virtual void NotifyDoubleClick(Point pt, bool shift, bool ctrl, bool alt);
365 void NotifyHotSpotClicked(int position, bool shift, bool ctrl, bool alt);
366 void NotifyHotSpotDoubleClicked(int position, bool shift, bool ctrl, bool alt);
367 void NotifyUpdateUI();
368 void NotifyPainted();
369 void NotifyIndicatorClick(bool click, int position, bool shift, bool ctrl, bool alt);
370 bool NotifyMarginClick(Point pt, bool shift, bool ctrl, bool alt);
371 void NotifyNeedShown(int pos, int len);
372 void NotifyDwelling(Point pt, bool state);
373 void NotifyZoom();
374
375 void NotifyModifyAttempt(Document *document, void *userData);
376 void NotifySavePoint(Document *document, void *userData, bool atSavePoint);
377 void CheckModificationForWrap(DocModification mh);
378 void NotifyModified(Document *document, DocModification mh, void *userData);
379 void NotifyDeleted(Document *document, void *userData);
380 void NotifyStyleNeeded(Document *doc, void *userData, int endPos);
381 void NotifyMacroRecord(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
382
383 void PageMove(int direction, selTypes sel=noSel, bool stuttered = false);
384 void ChangeCaseOfSelection(bool makeUpperCase);
385 void LineTranspose();
386 void Duplicate(bool forLine);
387 virtual void CancelModes();
388 void NewLine();
389 void CursorUpOrDown(int direction, selTypes sel=noSel);
390 void ParaUpOrDown(int direction, selTypes sel=noSel);
391 int StartEndDisplayLine(int pos, bool start);
392 virtual int KeyCommand(unsigned int iMessage);
393 virtual int KeyDefault(int /* key */, int /*modifiers*/);
394 int KeyDown(int key, bool shift, bool ctrl, bool alt, bool *consumed=0);
395
396 int GetWhitespaceVisible();
397 void SetWhitespaceVisible(int view);
398
399 void Indent(bool forwards);
400
401 long FindText(uptr_t wParam, sptr_t lParam);
402 void SearchAnchor();
403 long SearchText(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
404 long SearchInTarget(const char *text, int length);
405 void GoToLine(int lineNo);
406
407 virtual void CopyToClipboard(const SelectionText &selectedText) = 0;
408 char *CopyRange(int start, int end);
409 void CopySelectionFromRange(SelectionText *ss, int start, int end);
410 void CopySelectionRange(SelectionText *ss);
411 void CopyRangeToClipboard(int start, int end);
412 void CopyText(int length, const char *text);
413 void SetDragPosition(int newPos);
414 virtual void DisplayCursor(Window::Cursor c);
415 virtual bool DragThreshold(Point ptStart, Point ptNow);
416 virtual void StartDrag();
417 void DropAt(int position, const char *value, bool moving, bool rectangular);
418 /** PositionInSelection returns 0 if position in selection, -1 if position before selection, and 1 if after.
419 * Before means either before any line of selection or before selection on its line, with a similar meaning to after. */
420 int PositionInSelection(int pos);
421 bool PointInSelection(Point pt);
422 bool PointInSelMargin(Point pt);
423 void LineSelection(int lineCurrent_, int lineAnchor_);
424 void DwellEnd(bool mouseMoved);
425 virtual void ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt);
426 void ButtonMove(Point pt);
427 void ButtonUp(Point pt, unsigned int curTime, bool ctrl);
428
429 void Tick();
430 bool Idle();
431 virtual void SetTicking(bool on) = 0;
432 virtual bool SetIdle(bool) { return false; }
433 virtual void SetMouseCapture(bool on) = 0;
434 virtual bool HaveMouseCapture() = 0;
435 void SetFocusState(bool focusState);
436
437 virtual bool PaintContains(PRectangle rc);
438 bool PaintContainsMargin();
439 void CheckForChangeOutsidePaint(Range r);
440 void SetBraceHighlight(Position pos0, Position pos1, int matchStyle);
441
442 void SetDocPointer(Document *document);
443
444 void Expand(int &line, bool doExpand);
445 void ToggleContraction(int line);
446 void EnsureLineVisible(int lineDoc, bool enforcePolicy);
447 int ReplaceTarget(bool replacePatterns, const char *text, int length=-1);
448
449 bool PositionIsHotspot(int position);
450 bool PointIsHotspot(Point pt);
451 void SetHotSpotRange(Point *pt);
452 void GetHotSpotRange(int& hsStart, int& hsEnd);
453
454 int CodePage() const;
455 virtual bool ValidCodePage(int /* codePage */) const { return true; }
456 int WrapCount(int line);
457 void AddStyledText(char *buffer, int appendLength);
458
459 virtual sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) = 0;
460 void StyleSetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
461 sptr_t StyleGetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
462
463 public:
464 // Public so the COM thunks can access it.
465 bool IsUnicodeMode() const;
466 // Public so scintilla_send_message can use it.
467 virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
468 // Public so scintilla_set_id can use it.
469 int ctrlID;
470 friend class AutoSurface;
471 friend class SelectionLineIterator;
472 };
473
474 /**
475 * A smart pointer class to ensure Surfaces are set up and deleted correctly.
476 */
477 class AutoSurface {
478 private:
479 Surface *surf;
480 public:
481 AutoSurface(Editor *ed) : surf(0) {
482 if (ed->wMain.GetID()) {
483 surf = Surface::Allocate();
484 if (surf) {
485 surf->Init(ed->wMain.GetID());
486 surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage());
487 surf->SetDBCSMode(ed->CodePage());
488 }
489 }
490 }
491 AutoSurface(SurfaceID sid, Editor *ed) : surf(0) {
492 if (ed->wMain.GetID()) {
493 surf = Surface::Allocate();
494 if (surf) {
495 surf->Init(sid, ed->wMain.GetID());
496 surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage());
497 surf->SetDBCSMode(ed->CodePage());
498 }
499 }
500 }
501 ~AutoSurface() {
502 delete surf;
503 }
504 Surface *operator->() const {
505 return surf;
506 }
507 operator Surface *() const {
508 return surf;
509 }
510 };
511
512 #ifdef SCI_NAMESPACE
513 }
514 #endif
515
516 #endif