applied backgroundcolors.patch
[TortoiseGit.git] / ext / scintilla / src / Editor.h
blob26f5392026781c62ea517d115aa983e4d5ccdd23
1 // Scintilla source code edit control
2 /** @file Editor.h
3 ** Defines the main editor class.
4 **/
5 // Copyright 1998-2011 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
8 #ifndef EDITOR_H
9 #define EDITOR_H
11 #ifdef SCI_NAMESPACE
12 namespace Scintilla {
13 #endif
15 /**
17 class Caret {
18 public:
19 bool active;
20 bool on;
21 int period;
23 Caret();
26 /**
28 class Timer {
29 public:
30 bool ticking;
31 int ticksToWait;
32 enum {tickSize = 100};
33 TickerID tickerID;
35 Timer();
38 /**
40 class Idler {
41 public:
42 bool state;
43 IdlerID idlerID;
45 Idler();
48 /**
49 * When platform has a way to generate an event before painting,
50 * accumulate needed styling range in StyleNeeded to avoid unnecessary work.
52 class StyleNeeded {
53 public:
54 bool active;
55 Position upTo;
57 StyleNeeded() : active(false), upTo(0) {}
58 void Reset() {
59 active = false;
60 upTo = 0;
62 void NeedUpTo(Position pos) {
63 if (upTo < pos)
64 upTo = pos;
68 /**
69 * Hold a piece of text selected for copying or dragging.
70 * The text is expected to hold a terminating '\0' and this is counted in len.
72 class SelectionText {
73 public:
74 char *s;
75 int len;
76 bool rectangular;
77 bool lineCopy;
78 int codePage;
79 int characterSet;
80 SelectionText() : s(0), len(0), rectangular(false), lineCopy(false), codePage(0), characterSet(0) {}
81 ~SelectionText() {
82 Free();
84 void Free() {
85 Set(0, 0, 0, 0, false, false);
87 void Set(char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) {
88 delete []s;
89 s = s_;
90 if (s)
91 len = len_;
92 else
93 len = 0;
94 codePage = codePage_;
95 characterSet = characterSet_;
96 rectangular = rectangular_;
97 lineCopy = lineCopy_;
98 FixSelectionForClipboard();
100 void Copy(const char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) {
101 delete []s;
102 s = 0;
103 s = new char[len_];
104 len = len_;
105 for (int i = 0; i < len_; i++) {
106 s[i] = s_[i];
108 codePage = codePage_;
109 characterSet = characterSet_;
110 rectangular = rectangular_;
111 lineCopy = lineCopy_;
112 FixSelectionForClipboard();
114 void Copy(const SelectionText &other) {
115 Copy(other.s, other.len, other.codePage, other.characterSet, other.rectangular, other.lineCopy);
118 private:
119 void FixSelectionForClipboard() {
120 // Replace null characters by spaces.
121 // To avoid that the content of the clipboard is truncated in the paste operation
122 // when the clipboard contains null characters.
123 for (int i = 0; i < len - 1; ++i) {
124 if (s[i] == '\0')
125 s[i] = ' ';
132 class Editor : public DocWatcher {
133 // Private so Editor objects can not be copied
134 Editor(const Editor &);
135 Editor &operator=(const Editor &);
137 protected: // ScintillaBase subclass needs access to much of Editor
139 /** On GTK+, Scintilla is a container widget holding two scroll bars
140 * whereas on Windows there is just one window with both scroll bars turned on. */
141 Window wMain; ///< The Scintilla parent window
143 /** Style resources may be expensive to allocate so are cached between uses.
144 * When a style attribute is changed, this cache is flushed. */
145 bool stylesValid;
146 ViewStyle vs;
147 int technology;
148 Point sizeRGBAImage;
149 float scaleRGBAImage;
151 int printMagnification;
152 int printColourMode;
153 int printWrapState;
154 int cursorMode;
155 int controlCharSymbol;
157 // Highlight current folding block
158 HighlightDelimiter highlightDelimiter;
160 bool hasFocus;
161 bool hideSelection;
162 bool inOverstrike;
163 bool mouseDownCaptures;
165 /** In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to
166 * the screen. This avoids flashing but is about 30% slower. */
167 bool bufferedDraw;
168 /** In twoPhaseDraw mode, drawing is performed in two phases, first the background
169 * and then the foreground. This avoids chopping off characters that overlap the next run. */
170 bool twoPhaseDraw;
172 int xOffset; ///< Horizontal scrolled amount in pixels
173 int xCaretMargin; ///< Ensure this many pixels visible on both sides of caret
174 bool horizontalScrollBarVisible;
175 int scrollWidth;
176 bool trackLineWidth;
177 int lineWidthMaxSeen;
178 bool verticalScrollBarVisible;
179 bool endAtLastLine;
180 int caretSticky;
181 int marginOptions;
182 bool multipleSelection;
183 bool additionalSelectionTyping;
184 int multiPasteMode;
185 bool additionalCaretsBlink;
186 bool additionalCaretsVisible;
188 int virtualSpaceOptions;
190 Surface *pixmapLine;
191 Surface *pixmapSelMargin;
192 Surface *pixmapSelPattern;
193 Surface *pixmapIndentGuide;
194 Surface *pixmapIndentGuideHighlight;
196 LineLayoutCache llc;
197 PositionCache posCache;
199 KeyMap kmap;
201 Caret caret;
202 Timer timer;
203 Timer autoScrollTimer;
204 enum { autoScrollDelay = 200 };
206 Idler idler;
208 Point lastClick;
209 unsigned int lastClickTime;
210 int dwellDelay;
211 int ticksToDwell;
212 bool dwelling;
213 enum { selChar, selWord, selSubLine, selWholeLine } selectionType;
214 Point ptMouseLast;
215 enum { ddNone, ddInitial, ddDragging } inDragDrop;
216 bool dropWentOutside;
217 SelectionPosition posDrag;
218 SelectionPosition posDrop;
219 int hotSpotClickPos;
220 int lastXChosen;
221 int lineAnchorPos;
222 int originalAnchorPos;
223 int wordSelectAnchorStartPos;
224 int wordSelectAnchorEndPos;
225 int wordSelectInitialCaretPos;
226 int targetStart;
227 int targetEnd;
228 int searchFlags;
229 int topLine;
230 int posTopLine;
231 int lengthForEncode;
233 int needUpdateUI;
234 Position braces[2];
235 int bracesMatchStyle;
236 int highlightGuideColumn;
238 int theEdge;
240 enum { notPainting, painting, paintAbandoned } paintState;
241 PRectangle rcPaint;
242 bool paintingAllText;
243 bool willRedrawAll;
244 StyleNeeded styleNeeded;
246 int modEventMask;
248 SelectionText drag;
249 Selection sel;
250 bool primarySelection;
252 int caretXPolicy;
253 int caretXSlop; ///< Ensure this many pixels visible on both sides of caret
255 int caretYPolicy;
256 int caretYSlop; ///< Ensure this many lines visible on both sides of caret
258 int visiblePolicy;
259 int visibleSlop;
261 int searchAnchor;
263 bool recordingMacro;
265 int foldFlags;
266 ContractionState cs;
268 // Hotspot support
269 int hsStart;
270 int hsEnd;
272 // Wrapping support
273 enum { eWrapNone, eWrapWord, eWrapChar } wrapState;
274 enum { wrapLineLarge = 0x7ffffff };
275 int wrapWidth;
276 int wrapStart;
277 int wrapEnd;
278 int wrapVisualFlags;
279 int wrapVisualFlagsLocation;
280 int wrapVisualStartIndent;
281 int wrapIndentMode; // SC_WRAPINDENT_FIXED, _SAME, _INDENT
283 bool convertPastes;
285 int marginNumberPadding; // the right-side padding of the number margin
286 int ctrlCharPadding; // the padding around control character text blobs
287 int lastSegItalicsOffset; // the offset so as not to clip italic characters at EOLs
289 Document *pdoc;
291 Editor();
292 virtual ~Editor();
293 virtual void Initialise() = 0;
294 virtual void Finalise();
296 void InvalidateStyleData();
297 void InvalidateStyleRedraw();
298 void RefreshStyleData();
299 void DropGraphics(bool freeObjects);
300 void AllocateGraphics();
302 virtual PRectangle GetClientRectangle();
303 PRectangle GetTextRectangle();
305 int LinesOnScreen();
306 int LinesToScroll();
307 int MaxScrollPos();
308 SelectionPosition ClampPositionIntoDocument(SelectionPosition sp) const;
309 Point LocationFromPosition(SelectionPosition pos);
310 Point LocationFromPosition(int pos);
311 int XFromPosition(int pos);
312 int XFromPosition(SelectionPosition sp);
313 SelectionPosition SPositionFromLocation(Point pt, bool canReturnInvalid=false, bool charPosition=false, bool virtualSpace=true);
314 int PositionFromLocation(Point pt, bool canReturnInvalid=false, bool charPosition=false);
315 SelectionPosition SPositionFromLineX(int lineDoc, int x);
316 int PositionFromLineX(int line, int x);
317 int LineFromLocation(Point pt);
318 void SetTopLine(int topLineNew);
320 bool AbandonPaint();
321 void RedrawRect(PRectangle rc);
322 void Redraw();
323 void RedrawSelMargin(int line=-1, bool allAfter=false);
324 PRectangle RectangleFromRange(int start, int end);
325 void InvalidateRange(int start, int end);
327 bool UserVirtualSpace() const {
328 return ((virtualSpaceOptions & SCVS_USERACCESSIBLE) != 0);
330 int CurrentPosition();
331 bool SelectionEmpty();
332 SelectionPosition SelectionStart();
333 SelectionPosition SelectionEnd();
334 void SetRectangularRange();
335 void ThinRectangularRange();
336 void InvalidateSelection(SelectionRange newMain, bool invalidateWholeSelection=false);
337 void SetSelection(SelectionPosition currentPos_, SelectionPosition anchor_);
338 void SetSelection(int currentPos_, int anchor_);
339 void SetSelection(SelectionPosition currentPos_);
340 void SetSelection(int currentPos_);
341 void SetEmptySelection(SelectionPosition currentPos_);
342 void SetEmptySelection(int currentPos_);
343 bool RangeContainsProtected(int start, int end) const;
344 bool SelectionContainsProtected();
345 int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true) const;
346 SelectionPosition MovePositionOutsideChar(SelectionPosition pos, int moveDir, bool checkLineEnd=true) const;
347 int MovePositionTo(SelectionPosition newPos, Selection::selTypes sel=Selection::noSel, bool ensureVisible=true);
348 int MovePositionTo(int newPos, Selection::selTypes sel=Selection::noSel, bool ensureVisible=true);
349 SelectionPosition MovePositionSoVisible(SelectionPosition pos, int moveDir);
350 SelectionPosition MovePositionSoVisible(int pos, int moveDir);
351 Point PointMainCaret();
352 void SetLastXChosen();
354 void ScrollTo(int line, bool moveThumb=true);
355 virtual void ScrollText(int linesToMove);
356 void HorizontalScrollTo(int xPos);
357 void VerticalCentreCaret();
358 void MoveSelectedLines(int lineDelta);
359 void MoveSelectedLinesUp();
360 void MoveSelectedLinesDown();
361 void MoveCaretInsideView(bool ensureVisible=true);
362 int DisplayFromPosition(int pos);
364 struct XYScrollPosition {
365 int xOffset;
366 int topLine;
367 XYScrollPosition(int xOffset_, int topLine_) : xOffset(xOffset_), topLine(topLine_) {}
369 XYScrollPosition XYScrollToMakeVisible(const bool useMargin, const bool vert, const bool horiz);
370 void SetXYScroll(XYScrollPosition newXY);
371 void EnsureCaretVisible(bool useMargin=true, bool vert=true, bool horiz=true);
372 void ShowCaretAtCurrentPosition();
373 void DropCaret();
374 void InvalidateCaret();
375 virtual void UpdateSystemCaret();
377 void NeedWrapping(int docLineStart = 0, int docLineEnd = wrapLineLarge);
378 bool WrapOneLine(Surface *surface, int lineToWrap);
379 bool WrapLines(bool fullWrap, int priorityWrapLineStart);
380 void LinesJoin();
381 void LinesSplit(int pixelWidth);
383 int SubstituteMarkerIfEmpty(int markerCheck, int markerDefault);
384 void PaintSelMargin(Surface *surface, PRectangle &rc);
385 LineLayout *RetrieveLineLayout(int lineNumber);
386 void LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayout *ll,
387 int width=LineLayout::wrapWidthInfinite);
388 ColourDesired SelectionBackground(ViewStyle &vsDraw, bool main);
389 ColourDesired TextBackground(ViewStyle &vsDraw, bool overrideBackground, ColourDesired background, int inSelection, bool inHotspot, int styleMain, int i, LineLayout *ll);
390 void DrawIndentGuide(Surface *surface, int lineVisible, int lineHeight, int start, PRectangle rcSegment, bool highlight);
391 void DrawWrapMarker(Surface *surface, PRectangle rcPlace, bool isEndMarker, ColourDesired wrapColour);
392 void DrawEOL(Surface *surface, ViewStyle &vsDraw, PRectangle rcLine, LineLayout *ll,
393 int line, int lineEnd, int xStart, int subLine, XYACCUMULATOR subLineStart,
394 bool overrideBackground, ColourDesired background,
395 bool drawWrapMark, ColourDesired wrapColour);
396 void DrawIndicator(int indicNum, int startPos, int endPos, Surface *surface, ViewStyle &vsDraw,
397 int xStart, PRectangle rcLine, LineLayout *ll, int subLine);
398 void DrawIndicators(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
399 PRectangle rcLine, LineLayout *ll, int subLine, int lineEnd, bool under);
400 void DrawAnnotation(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
401 PRectangle rcLine, LineLayout *ll, int subLine);
402 void DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVisible, int xStart,
403 PRectangle rcLine, LineLayout *ll, int subLine);
404 void DrawBlockCaret(Surface *surface, ViewStyle &vsDraw, LineLayout *ll, int subLine,
405 int xStart, int offset, int posCaret, PRectangle rcCaret, ColourDesired caretColour);
406 void DrawCarets(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
407 PRectangle rcLine, LineLayout *ll, int subLine);
408 void RefreshPixMaps(Surface *surfaceWindow);
409 void Paint(Surface *surfaceWindow, PRectangle rcArea);
410 long FormatRange(bool draw, Sci_RangeToFormat *pfr);
411 int TextWidth(int style, const char *text);
413 virtual void SetVerticalScrollPos() = 0;
414 virtual void SetHorizontalScrollPos() = 0;
415 virtual bool ModifyScrollBars(int nMax, int nPage) = 0;
416 virtual void ReconfigureScrollBars();
417 void SetScrollBars();
418 void ChangeSize();
420 void FilterSelections();
421 int InsertSpace(int position, unsigned int spaces);
422 void AddChar(char ch);
423 virtual void AddCharUTF(char *s, unsigned int len, bool treatAsDBCS=false);
424 void InsertPaste(SelectionPosition selStart, const char *text, int len);
425 void ClearSelection(bool retainMultipleSelections=false);
426 void ClearAll();
427 void ClearDocumentStyle();
428 void Cut();
429 void PasteRectangular(SelectionPosition pos, const char *ptr, int len);
430 virtual void Copy() = 0;
431 virtual void CopyAllowLine();
432 virtual bool CanPaste();
433 virtual void Paste() = 0;
434 void Clear();
435 void SelectAll();
436 void Undo();
437 void Redo();
438 void DelChar();
439 void DelCharBack(bool allowLineStartDeletion);
440 virtual void ClaimSelection() = 0;
442 virtual void NotifyChange() = 0;
443 virtual void NotifyFocus(bool focus);
444 virtual void SetCtrlID(int identifier);
445 virtual int GetCtrlID() { return ctrlID; }
446 virtual void NotifyParent(SCNotification scn) = 0;
447 virtual void NotifyParent(SCNotification * scn) = 0;
448 virtual void NotifyStyleToNeeded(int endStyleNeeded);
449 void NotifyChar(int ch);
450 void NotifySavePoint(bool isSavePoint);
451 void NotifyModifyAttempt();
452 virtual void NotifyDoubleClick(Point pt, bool shift, bool ctrl, bool alt);
453 void NotifyHotSpotClicked(int position, bool shift, bool ctrl, bool alt);
454 void NotifyHotSpotDoubleClicked(int position, bool shift, bool ctrl, bool alt);
455 void NotifyHotSpotReleaseClick(int position, bool shift, bool ctrl, bool alt);
456 void NotifyUpdateUI();
457 void NotifyPainted();
458 void NotifyIndicatorClick(bool click, int position, bool shift, bool ctrl, bool alt);
459 bool NotifyMarginClick(Point pt, bool shift, bool ctrl, bool alt);
460 void NotifyNeedShown(int pos, int len);
461 void NotifyDwelling(Point pt, bool state);
462 void NotifyZoom();
464 void NotifyModifyAttempt(Document *document, void *userData);
465 void NotifySavePoint(Document *document, void *userData, bool atSavePoint);
466 void CheckModificationForWrap(DocModification mh);
467 void NotifyModified(Document *document, DocModification mh, void *userData);
468 void NotifyDeleted(Document *document, void *userData);
469 void NotifyStyleNeeded(Document *doc, void *userData, int endPos);
470 void NotifyLexerChanged(Document *doc, void *userData);
471 void NotifyErrorOccurred(Document *doc, void *userData, int status);
472 void NotifyMacroRecord(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
474 void ContainerNeedsUpdate(int flags);
475 void PageMove(int direction, Selection::selTypes sel=Selection::noSel, bool stuttered = false);
476 enum { cmSame, cmUpper, cmLower } caseMap;
477 virtual std::string CaseMapString(const std::string &s, int caseMapping);
478 void ChangeCaseOfSelection(int caseMapping);
479 void LineTranspose();
480 void Duplicate(bool forLine);
481 virtual void CancelModes();
482 void NewLine();
483 void CursorUpOrDown(int direction, Selection::selTypes sel=Selection::noSel);
484 void ParaUpOrDown(int direction, Selection::selTypes sel=Selection::noSel);
485 int StartEndDisplayLine(int pos, bool start);
486 virtual int KeyCommand(unsigned int iMessage);
487 virtual int KeyDefault(int /* key */, int /*modifiers*/);
488 int KeyDownWithModifiers(int key, int modifiers, bool *consumed);
489 int KeyDown(int key, bool shift, bool ctrl, bool alt, bool *consumed=0);
491 void Indent(bool forwards);
493 virtual CaseFolder *CaseFolderForEncoding();
494 long FindText(uptr_t wParam, sptr_t lParam);
495 void SearchAnchor();
496 long SearchText(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
497 long SearchInTarget(const char *text, int length);
498 void GoToLine(int lineNo);
500 virtual void CopyToClipboard(const SelectionText &selectedText) = 0;
501 char *CopyRange(int start, int end);
502 std::string RangeText(int start, int end) const;
503 void CopySelectionRange(SelectionText *ss, bool allowLineCopy=false);
504 void CopyRangeToClipboard(int start, int end);
505 void CopyText(int length, const char *text);
506 void SetDragPosition(SelectionPosition newPos);
507 virtual void DisplayCursor(Window::Cursor c);
508 virtual bool DragThreshold(Point ptStart, Point ptNow);
509 virtual void StartDrag();
510 void DropAt(SelectionPosition position, const char *value, bool moving, bool rectangular);
511 /** PositionInSelection returns true if position in selection. */
512 bool PositionInSelection(int pos);
513 bool PointInSelection(Point pt);
514 bool PointInSelMargin(Point pt);
515 Window::Cursor GetMarginCursor(Point pt);
516 void TrimAndSetSelection(int currentPos_, int anchor_);
517 void LineSelection(int lineCurrentPos_, int lineAnchorPos_, bool wholeLine);
518 void WordSelection(int pos);
519 void DwellEnd(bool mouseMoved);
520 void MouseLeave();
521 virtual void ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt);
522 void ButtonMove(Point pt);
523 void ButtonUp(Point pt, unsigned int curTime, bool ctrl);
525 void Tick();
526 bool Idle();
527 virtual void SetTicking(bool on) = 0;
528 virtual bool SetIdle(bool) { return false; }
529 virtual void SetMouseCapture(bool on) = 0;
530 virtual bool HaveMouseCapture() = 0;
531 void SetFocusState(bool focusState);
533 int PositionAfterArea(PRectangle rcArea);
534 void StyleToPositionInView(Position pos);
535 void IdleStyling();
536 virtual void QueueStyling(int upTo);
538 virtual bool PaintContains(PRectangle rc);
539 bool PaintContainsMargin();
540 void CheckForChangeOutsidePaint(Range r);
541 void SetBraceHighlight(Position pos0, Position pos1, int matchStyle);
543 void SetAnnotationHeights(int start, int end);
544 void SetDocPointer(Document *document);
546 void SetAnnotationVisible(int visible);
548 void Expand(int &line, bool doExpand);
549 void ToggleContraction(int line);
550 int ContractedFoldNext(int lineStart);
551 void EnsureLineVisible(int lineDoc, bool enforcePolicy);
552 int GetTag(char *tagValue, int tagNumber);
553 int ReplaceTarget(bool replacePatterns, const char *text, int length=-1);
555 bool PositionIsHotspot(int position);
556 bool PointIsHotspot(Point pt);
557 void SetHotSpotRange(Point *pt);
558 void GetHotSpotRange(int &hsStart, int &hsEnd);
560 int CodePage() const;
561 virtual bool ValidCodePage(int /* codePage */) const { return true; }
562 int WrapCount(int line);
563 void AddStyledText(char *buffer, int appendLength);
565 virtual sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) = 0;
566 void StyleSetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
567 sptr_t StyleGetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
569 static const char *StringFromEOLMode(int eolMode);
571 static sptr_t StringResult(sptr_t lParam, const char *val);
573 public:
574 // Public so the COM thunks can access it.
575 bool IsUnicodeMode() const;
576 // Public so scintilla_send_message can use it.
577 virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
578 // Public so scintilla_set_id can use it.
579 int ctrlID;
580 // Public so COM methods for drag and drop can set it.
581 int errorStatus;
582 friend class AutoSurface;
583 friend class SelectionLineIterator;
587 * A smart pointer class to ensure Surfaces are set up and deleted correctly.
589 class AutoSurface {
590 private:
591 Surface *surf;
592 public:
593 AutoSurface(Editor *ed, int technology = -1) : surf(0) {
594 if (ed->wMain.GetID()) {
595 surf = Surface::Allocate(technology != -1 ? technology : ed->technology);
596 if (surf) {
597 surf->Init(ed->wMain.GetID());
598 surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage());
599 surf->SetDBCSMode(ed->CodePage());
603 AutoSurface(SurfaceID sid, Editor *ed, int technology = -1) : surf(0) {
604 if (ed->wMain.GetID()) {
605 surf = Surface::Allocate(technology != -1 ? technology : ed->technology);
606 if (surf) {
607 surf->Init(sid, ed->wMain.GetID());
608 surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage());
609 surf->SetDBCSMode(ed->CodePage());
613 ~AutoSurface() {
614 delete surf;
616 Surface *operator->() const {
617 return surf;
619 operator Surface *() const {
620 return surf;
624 #ifdef SCI_NAMESPACE
626 #endif
628 #endif