// Scintilla source code edit control /** @file Editor.h ** Defines the main editor class. **/ // Copyright 1998-2003 by Neil Hodgson // The License.txt file describes the conditions under which this software may be distributed. #ifndef EDITOR_H #define EDITOR_H #ifdef SCI_NAMESPACE namespace Scintilla { #endif /** */ class Caret { public: bool active; bool on; int period; Caret(); }; /** */ class Timer { public: bool ticking; int ticksToWait; enum {tickSize = 100}; TickerID tickerID; Timer(); }; /** */ class Idler { public: bool state; IdlerID idlerID; Idler(); }; /** * When platform has a way to generate an event before painting, * accumulate needed styling range in StyleNeeded to avoid unnecessary work. */ class StyleNeeded { public: bool active; Position upTo; StyleNeeded() : active(false), upTo(0) {} void Reset() { active = false; upTo = 0; } void NeedUpTo(Position pos) { if (upTo < pos) upTo = pos; } }; /** * Hold a piece of text selected for copying or dragging. * The text is expected to hold a terminating '\0' and this is counted in len. */ class SelectionText { public: char *s; int len; bool rectangular; bool lineCopy; int codePage; int characterSet; SelectionText() : s(0), len(0), rectangular(false), lineCopy(false), codePage(0), characterSet(0) {} ~SelectionText() { Free(); } void Free() { Set(0, 0, 0, 0, false, false); } void Set(char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) { delete []s; s = s_; if (s) len = len_; else len = 0; codePage = codePage_; characterSet = characterSet_; rectangular = rectangular_; lineCopy = lineCopy_; } void Copy(const char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) { delete []s; s = 0; s = new char[len_]; len = len_; for (int i = 0; i < len_; i++) { s[i] = s_[i]; } codePage = codePage_; characterSet = characterSet_; rectangular = rectangular_; lineCopy = lineCopy_; } void Copy(const SelectionText &other) { Copy(other.s, other.len, other.codePage, other.characterSet, other.rectangular, other.lineCopy); } }; /** */ class Editor : public DocWatcher { // Private so Editor objects can not be copied Editor(const Editor &); Editor &operator=(const Editor &); protected: // ScintillaBase subclass needs access to much of Editor /** On GTK+, Scintilla is a container widget holding two scroll bars * whereas on Windows there is just one window with both scroll bars turned on. */ Window wMain; ///< The Scintilla parent window /** Style resources may be expensive to allocate so are cached between uses. * When a style attribute is changed, this cache is flushed. */ bool stylesValid; ViewStyle vs; Palette palette; int printMagnification; int printColourMode; int printWrapState; int cursorMode; int controlCharSymbol; bool hasFocus; bool hideSelection; bool inOverstrike; bool mouseDownCaptures; /** In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to * the screen. This avoids flashing but is about 30% slower. */ bool bufferedDraw; /** In twoPhaseDraw mode, drawing is performed in two phases, first the background * and then the foreground. This avoids chopping off characters that overlap the next run. */ bool twoPhaseDraw; int xOffset; ///< Horizontal scrolled amount in pixels int xCaretMargin; ///< Ensure this many pixels visible on both sides of caret bool horizontalScrollBarVisible; int scrollWidth; bool trackLineWidth; int lineWidthMaxSeen; bool verticalScrollBarVisible; bool endAtLastLine; int caretSticky; bool multipleSelection; bool additionalSelectionTyping; int multiPasteMode; bool additionalCaretsBlink; bool additionalCaretsVisible; int virtualSpaceOptions; Surface *pixmapLine; Surface *pixmapSelMargin; Surface *pixmapSelPattern; Surface *pixmapIndentGuide; Surface *pixmapIndentGuideHighlight; LineLayoutCache llc; PositionCache posCache; KeyMap kmap; Caret caret; Timer timer; Timer autoScrollTimer; enum { autoScrollDelay = 200 }; Idler idler; Point lastClick; unsigned int lastClickTime; int dwellDelay; int ticksToDwell; bool dwelling; enum { selChar, selWord, selLine } selectionType; Point ptMouseLast; enum { ddNone, ddInitial, ddDragging } inDragDrop; bool dropWentOutside; SelectionPosition posDrag; SelectionPosition posDrop; int lastXChosen; int lineAnchor; int originalAnchorPos; int targetStart; int targetEnd; int searchFlags; int topLine; int posTopLine; int lengthForEncode; bool needUpdateUI; Position braces[2]; int bracesMatchStyle; int highlightGuideColumn; int theEdge; enum { notPainting, painting, paintAbandoned } paintState; PRectangle rcPaint; bool paintingAllText; StyleNeeded styleNeeded; int modEventMask; SelectionText drag; Selection sel; bool primarySelection; int caretXPolicy; int caretXSlop; ///< Ensure this many pixels visible on both sides of caret int caretYPolicy; int caretYSlop; ///< Ensure this many lines visible on both sides of caret int visiblePolicy; int visibleSlop; int searchAnchor; bool recordingMacro; int foldFlags; ContractionState cs; // Hotspot support int hsStart; int hsEnd; // Wrapping support enum { eWrapNone, eWrapWord, eWrapChar } wrapState; enum { wrapLineLarge = 0x7ffffff }; int wrapWidth; int wrapStart; int wrapEnd; int wrapVisualFlags; int wrapVisualFlagsLocation; int wrapVisualStartIndent; int wrapAddIndent; // This will be added to initial indent of line int wrapIndentMode; // SC_WRAPINDENT_FIXED, _SAME, _INDENT bool convertPastes; Document *pdoc; Editor(); virtual ~Editor(); virtual void Initialise() = 0; virtual void Finalise(); void InvalidateStyleData(); void InvalidateStyleRedraw(); virtual void RefreshColourPalette(Palette &pal, bool want); void RefreshStyleData(); void DropGraphics(); virtual PRectangle GetClientRectangle(); PRectangle GetTextRectangle(); int LinesOnScreen(); int LinesToScroll(); int MaxScrollPos(); SelectionPosition ClampPositionIntoDocument(SelectionPosition sp) const; Point LocationFromPosition(SelectionPosition pos); Point LocationFromPosition(int pos); int XFromPosition(int pos); int XFromPosition(SelectionPosition sp); SelectionPosition SPositionFromLocation(Point pt, bool canReturnInvalid=false, bool charPosition=false, bool virtualSpace=true); int PositionFromLocation(Point pt, bool canReturnInvalid=false, bool charPosition=false); SelectionPosition SPositionFromLineX(int lineDoc, int x); int PositionFromLineX(int line, int x); int LineFromLocation(Point pt); void SetTopLine(int topLineNew); bool AbandonPaint(); void RedrawRect(PRectangle rc); void Redraw(); void RedrawSelMargin(int line=-1, bool allAfter=false); PRectangle RectangleFromRange(int start, int end); void InvalidateRange(int start, int end); bool UserVirtualSpace() const { return ((virtualSpaceOptions & SCVS_USERACCESSIBLE) != 0); } int CurrentPosition(); bool SelectionEmpty(); SelectionPosition SelectionStart(); SelectionPosition SelectionEnd(); void SetRectangularRange(); void ThinRectangularRange(); void InvalidateSelection(SelectionRange newMain, bool invalidateWholeSelection=false); void SetSelection(SelectionPosition currentPos_, SelectionPosition anchor_); void SetSelection(int currentPos_, int anchor_); void SetSelection(SelectionPosition currentPos_); void SetSelection(int currentPos_); void SetEmptySelection(SelectionPosition currentPos_); void SetEmptySelection(int currentPos_); bool RangeContainsProtected(int start, int end) const; bool SelectionContainsProtected(); int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true) const; SelectionPosition MovePositionOutsideChar(SelectionPosition pos, int moveDir, bool checkLineEnd=true) const; int MovePositionTo(SelectionPosition newPos, Selection::selTypes sel=Selection::noSel, bool ensureVisible=true); int MovePositionTo(int newPos, Selection::selTypes sel=Selection::noSel, bool ensureVisible=true); SelectionPosition MovePositionSoVisible(SHTTP/1.1 200 OK Connection: keep-alive Connection: keep-alive Content-Disposition: inline; filename="Editor.h" Content-Disposition: inline; filename="Editor.h" Content-Length: 18618 Content-Length: 18618 Content-Security-Policy: default-src 'none' Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Type: text/plain; charset=UTF-8 Date: Wed, 31 Dec 2025 20:34:24 UTC ETag: "aa4fc923657eab6458be7ec9041c8a65aa528483" ETag: "aa4fc923657eab6458be7ec9041c8a65aa528483" Expires: Sat, 29 Dec 2035 20:34:24 GMT Expires: Sat, 29 Dec 2035 20:34:25 GMT Last-Modified: Wed, 31 Dec 2025 20:34:24 GMT Last-Modified: Wed, 31 Dec 2025 20:34:25 GMT Server: OpenBSD httpd Server: OpenBSD httpd X-Content-Type-Options: nosniff X-Content-Type-Options: nosniff // Scintilla source code edit control /** @file Editor.h ** Defines the main editor class. **/ // Copyright 1998-2003 by Neil Hodgson // The License.txt file describes the conditions under which this software may be distributed. #ifndef EDITOR_H #define EDITOR_H #ifdef SCI_NAMESPACE namespace Scintilla { #endif /** */ class Caret { public: bool active; bool on; int period; Caret(); }; /** */ class Timer { public: bool ticking; int ticksToWait; enum {tickSize = 100}; TickerID tickerID; Timer(); }; /** */ class Idler { public: bool state; IdlerID idlerID; Idler(); }; /** * When platform has a way to generate an event before painting, * accumulate needed styling range in StyleNeeded to avoid unnecessary work. */ class StyleNeeded { public: bool active; Position upTo; StyleNeeded() : active(false), upTo(0) {} void Reset() { active = false; upTo = 0; } void NeedUpTo(Position pos) { if (upTo < pos) upTo = pos; } }; /** * Hold a piece of text selected for copying or dragging. * The text is expected to hold a terminating '\0' and this is counted in len. */ class SelectionText { public: char *s; int len; bool rectangular; bool lineCopy; int codePage; int characterSet; SelectionText() : s(0), len(0), rectangular(false), lineCopy(false), codePage(0), characterSet(0) {} ~SelectionText() { Free(); } void Free() { Set(0, 0, 0, 0, false, false); } void Set(char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) { delete []s; s = s_; if (s) len = len_; else len = 0; codePage = codePage_; characterSet = characterSet_; rectangular = rectangular_; lineCopy = lineCopy_; } void Copy(const char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) { delete []s; s = 0; s = new char[len_]; len = len_; for (int i = 0; i < len_; i++) { s[i] = s_[i]; } codePage = codePage_; characterSet = characterSet_; rectangular = rectangular_; lineCopy = lineCopy_; } void Copy(const SelectionText &other) { Copy(other.s, other.len, other.codePage, other.characterSet, other.rectangular, other.lineCopy); } }; /** */ class Editor : public DocWatcher { // Private so Editor objects can not be copied Editor(const Editor &); Editor &operator=(const Editor &); protected: // ScintillaBase subclass needs access to much of Editor /** On GTK+, Scintilla is a container widget holding two scroll bars * whereas on Windows there is just one window with both scroll bars turned on. */ Window wMain; ///< The Scintilla parent window /** Style resources may be expensive to allocate so are cached between uses. * When a style attribute is changed, this cache is flushed. */ bool stylesValid; ViewStyle vs; Palette palette; int printMagnification; int printColourMode; int printWrapState; int cursorMode; int controlCharSymbol; bool hasFocus; bool hideSelection; bool inOverstrike; bool mouseDownCaptures; /** In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to * the screen. This avoids flashing but is about 30% slower. */ bool bufferedDraw; /** In twoPhaseDraw mode, drawing is performed in two phases, first the background * and then the foreground. This avoids chopping off characters that overlap the next run. */ bool twoPhaseDraw; int xOffset; ///< Horizontal scrolled amount in pixels int xCaretMargin; ///< Ensure this many pixels visible on both sides of caret bool horizontalScrollBarVisible; int scrollWidth; bool trackLineWidth; int lineWidthMaxSeen; bool verticalScrollBarVisible; bool endAtLastLine; int caretSticky; bool multipleSelection; bool additionalSelectionTyping; int multiPasteMode; bool additionalCaretsBlink; bool additionalCaretsVisible; int virtualSpaceOptions; Surface *pixmapLine; Surface *pixmapSelMargin; Surface *pixmapSelPattern; Surface *pixmapIndentGuide; Surface *pixmapIndentGuideHighlight; LineLayoutCache llc; PositionCache posCache; KeyMap kmap; Caret caret; Timer timer; Timer autoScrollTimer; enum { autoScrollDelay = 200 }; Idler idler; Point lastClick; unsigned int lastClickTime; int dwellDelay; int ticksToDwell; bool dwelling; enum { selChar, selWord, selLine } selectionType; Point ptMouseLast; enum { ddNone, ddInitial, ddDragging } inDragDrop; bool dropWentOutside; SelectionPosition posDrag; SelectionPosition posDrop; int lastXChosen; int lineAnchor; int originalAnchorPos; int targetStart; int targetEnd; int searchFlags; int topLine; int posTopLine; int lengthForEncode; bool needUpdateUI; Position braces[2]; int bracesMatchStyle; int highlightGuideColumn; int theEdge; enum { notPainting, painting, paintAbandoned } paintState; PRectangle rcPaint; bool paintingAllText; StyleNeeded styleNeeded; int modEventMask; SelectionText drag; Selection sel; bool primarySelection; int caretXPolicy; int caretXSlop; ///< Ensure this many pixels visible on both sides of caret int caretYPolicy; int caretYSlop; ///< Ensure this many lines visible on both sides of caret int visiblePolicy; int visibleSlop; int searchAnchor; bool recordingMacro; int foldFlags; ContractionState cs; // Hotspot support int hsStart; int hsEnd; // Wrapping support enum { eWrapNone, eWrapWord, eWrapChar } wrapState; enum { wrapLineLarge = 0x7ffffff }; int wrapWidth; int wrapStart; int wrapEnd; int wrapVisualFlags; int wrapVisualFlagsLocation; int wrapVisualStartIndent; int wrapAddIndent; // This will be added to initial indent of line int wrapIndentMode; // SC_WRAPINDENT_FIXED, _SAME, _INDENT bool convertPastes; Document *pdoc; Editor(); virtual ~Editor(); virtual void Initialise() = 0; virtual void Finalise(); void InvalidateStyleData(); void InvalidateStyleRedraw(); virtual void RefreshColourPalette(Palette &pal, bool want); void RefreshStyleData(); void DropGraphics(); virtual PRectangle GetClientRectangle(); PRectangle GetTextRectangle(); int LinesOnScreen(); int LinesToScroll(); int MaxScrollPos(); SelectionPosition ClampPositionIntoDocument(SelectionPosition sp) const; Point LocationFromPosition(SelectionPosition pos); Point LocationFromPosition(int pos); int XFromPosition(int pos); int XFromPosition(SelectionPosition sp); SelectionPosition SPositionFromLocation(Point pt, bool canReturnInvalid=false, bool charPosition=false, bool virtualSpace=true); int PositionFromLocation(Point pt, bool canReturnInvalid=false, bool charPosition=false); SelectionPosition SPositionFromLineX(int lineDoc, int x); int PositionFromLineX(int line, int x); int LineFromLocation(Point pt); void SetTopLine(int topLineNew); bool AbandonPaint(); void RedrawRect(PRectangle rc); void Redraw(); void RedrawSelMargin(int line=-1, bool allAfter=false); PRectangle RectangleFromRange(int start, int end); void InvalidateRange(int start, int end); bool UserVirtualSpace() const { return ((virtualSpaceOptions & SCVS_USERACCESSIBLE) != 0); } int CurrentPosition(); bool SelectionEmpty(); SelectionPosition SelectionStart(); SelectionPosition SelectionEnd(); void SetRectangularRange(); void ThinRectangularRange(); void InvalidateSelection(SelectionRange newMain, bool invalidateWholeSelection=false); void SetSelection(SelectionPosition currentPos_, SelectionPosition anchor_); void SetSelection(int currentPos_, int anchor_); void SetSelection(SelectionPosition currentPos_); void SetSelection(int currentPos_); void SetEmptySelection(SelectionPosition currentPos_); void SetEmptySelection(int currentPos_); bool RangeContainsProtected(int start, int end) const; bool SelectionContainsProtected(); int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true) const; SelectionPosition MovePositionOutsideChar(SelectionPosition pos, int moveDir, bool checkLineEnd=true) const; int MovePositionTo(SelectionPosition newPos, Selection::selTypes sel=Selection::noSel, bool ensureVisible=true); int MovePositionTo(int newPos, Selection::selTypes sel=Selection::noSel, bool ensureVisible=true); SelectionPosition MovePositionSoVisible(SelectionPosition pos, int moveDir); SelectionPosition MovePositionSoVisible(int pos, int moveDir); Point PointMainCaret(); void SetLastXChosen(); void ScrollTo(int line, bool moveThumb=true); virtual void ScrollText(int linesToMove); void HorizontalScrollTo(int xPos); void MoveCaretInsideView(bool ensureVisible=true); int DisplayFromPosition(int pos); struct XYScrollPosition { int xOffset; int topLine; XYScrollPosition(int xOffset_, int topLine_) : xOffset(xOffset_), topLine(topLine_) {} }; XYScrollPosition XYScrollToMakeVisible(const bool useMargin, const bool vert, const bool horiz); void SetXYScroll(XYScrollPosition newXY); void EnsureCaretVisible(bool useMargin=true, bool vert=true, bool horiz=true); void ShowCaretAtCurrentPosition(); void DropCaret(); void InvalidateCaret(); virtual void UpdateSystemCaret(); void NeedWrapping(int docLineStart = 0, int docLineEnd = wrapLineLarge); bool WrapOneLine(Surface *surface, int lineToWrap); bool WrapLines(bool fullWrap, int priorityWrapLineStart); void LinesJoin(); void LinesSplit(int pixelWidth); int SubstituteMarkerIfEmpty(int markerCheck, int markerDefault); void PaintSelMargin(Surface *surface, PRectangle &rc); LineLayout *RetrieveLineLayout(int lineNumber); void LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayout *ll, int width=LineLayout::wrapWidthInfinite); ColourAllocated SelectionBackground(ViewS