1*8af74909SZhong Yang // Scintilla source code edit control 2*8af74909SZhong Yang /** @file Editor.h 3*8af74909SZhong Yang ** Defines the main editor class. 4*8af74909SZhong Yang **/ 5*8af74909SZhong Yang // Copyright 1998-2011 by Neil Hodgson <[email protected]> 6*8af74909SZhong Yang // The License.txt file describes the conditions under which this software may be distributed. 7*8af74909SZhong Yang 8*8af74909SZhong Yang #ifndef EDITOR_H 9*8af74909SZhong Yang #define EDITOR_H 10*8af74909SZhong Yang 11*8af74909SZhong Yang namespace Scintilla { 12*8af74909SZhong Yang 13*8af74909SZhong Yang /** 14*8af74909SZhong Yang */ 15*8af74909SZhong Yang class Timer { 16*8af74909SZhong Yang public: 17*8af74909SZhong Yang bool ticking; 18*8af74909SZhong Yang int ticksToWait; 19*8af74909SZhong Yang enum {tickSize = 100}; 20*8af74909SZhong Yang TickerID tickerID; 21*8af74909SZhong Yang 22*8af74909SZhong Yang Timer() noexcept; 23*8af74909SZhong Yang }; 24*8af74909SZhong Yang 25*8af74909SZhong Yang /** 26*8af74909SZhong Yang */ 27*8af74909SZhong Yang class Idler { 28*8af74909SZhong Yang public: 29*8af74909SZhong Yang bool state; 30*8af74909SZhong Yang IdlerID idlerID; 31*8af74909SZhong Yang 32*8af74909SZhong Yang Idler() noexcept; 33*8af74909SZhong Yang }; 34*8af74909SZhong Yang 35*8af74909SZhong Yang /** 36*8af74909SZhong Yang * When platform has a way to generate an event before painting, 37*8af74909SZhong Yang * accumulate needed styling range and other work items in 38*8af74909SZhong Yang * WorkNeeded to avoid unnecessary work inside paint handler 39*8af74909SZhong Yang */ 40*8af74909SZhong Yang class WorkNeeded { 41*8af74909SZhong Yang public: 42*8af74909SZhong Yang enum workItems { 43*8af74909SZhong Yang workNone=0, 44*8af74909SZhong Yang workStyle=1, 45*8af74909SZhong Yang workUpdateUI=2 46*8af74909SZhong Yang }; 47*8af74909SZhong Yang enum workItems items; 48*8af74909SZhong Yang Sci::Position upTo; 49*8af74909SZhong Yang WorkNeeded()50*8af74909SZhong Yang WorkNeeded() noexcept : items(workNone), upTo(0) {} Reset()51*8af74909SZhong Yang void Reset() noexcept { 52*8af74909SZhong Yang items = workNone; 53*8af74909SZhong Yang upTo = 0; 54*8af74909SZhong Yang } Need(workItems items_,Sci::Position pos)55*8af74909SZhong Yang void Need(workItems items_, Sci::Position pos) noexcept { 56*8af74909SZhong Yang if ((items_ & workStyle) && (upTo < pos)) 57*8af74909SZhong Yang upTo = pos; 58*8af74909SZhong Yang items = static_cast<workItems>(items | items_); 59*8af74909SZhong Yang } 60*8af74909SZhong Yang }; 61*8af74909SZhong Yang 62*8af74909SZhong Yang /** 63*8af74909SZhong Yang * Hold a piece of text selected for copying or dragging, along with encoding and selection format information. 64*8af74909SZhong Yang */ 65*8af74909SZhong Yang class SelectionText { 66*8af74909SZhong Yang std::string s; 67*8af74909SZhong Yang public: 68*8af74909SZhong Yang bool rectangular; 69*8af74909SZhong Yang bool lineCopy; 70*8af74909SZhong Yang int codePage; 71*8af74909SZhong Yang int characterSet; SelectionText()72*8af74909SZhong Yang SelectionText() noexcept : rectangular(false), lineCopy(false), codePage(0), characterSet(0) {} Clear()73*8af74909SZhong Yang void Clear() noexcept { 74*8af74909SZhong Yang s.clear(); 75*8af74909SZhong Yang rectangular = false; 76*8af74909SZhong Yang lineCopy = false; 77*8af74909SZhong Yang codePage = 0; 78*8af74909SZhong Yang characterSet = 0; 79*8af74909SZhong Yang } Copy(const std::string & s_,int codePage_,int characterSet_,bool rectangular_,bool lineCopy_)80*8af74909SZhong Yang void Copy(const std::string &s_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) { 81*8af74909SZhong Yang s = s_; 82*8af74909SZhong Yang codePage = codePage_; 83*8af74909SZhong Yang characterSet = characterSet_; 84*8af74909SZhong Yang rectangular = rectangular_; 85*8af74909SZhong Yang lineCopy = lineCopy_; 86*8af74909SZhong Yang FixSelectionForClipboard(); 87*8af74909SZhong Yang } Copy(const SelectionText & other)88*8af74909SZhong Yang void Copy(const SelectionText &other) { 89*8af74909SZhong Yang Copy(other.s, other.codePage, other.characterSet, other.rectangular, other.lineCopy); 90*8af74909SZhong Yang } Data()91*8af74909SZhong Yang const char *Data() const noexcept { 92*8af74909SZhong Yang return s.c_str(); 93*8af74909SZhong Yang } Length()94*8af74909SZhong Yang size_t Length() const noexcept { 95*8af74909SZhong Yang return s.length(); 96*8af74909SZhong Yang } LengthWithTerminator()97*8af74909SZhong Yang size_t LengthWithTerminator() const noexcept { 98*8af74909SZhong Yang return s.length() + 1; 99*8af74909SZhong Yang } Empty()100*8af74909SZhong Yang bool Empty() const noexcept { 101*8af74909SZhong Yang return s.empty(); 102*8af74909SZhong Yang } 103*8af74909SZhong Yang private: FixSelectionForClipboard()104*8af74909SZhong Yang void FixSelectionForClipboard() { 105*8af74909SZhong Yang // To avoid truncating the contents of the clipboard when pasted where the 106*8af74909SZhong Yang // clipboard contains NUL characters, replace NUL characters by spaces. 107*8af74909SZhong Yang std::replace(s.begin(), s.end(), '\0', ' '); 108*8af74909SZhong Yang } 109*8af74909SZhong Yang }; 110*8af74909SZhong Yang 111*8af74909SZhong Yang struct WrapPending { 112*8af74909SZhong Yang // The range of lines that need to be wrapped 113*8af74909SZhong Yang enum { lineLarge = 0x7ffffff }; 114*8af74909SZhong Yang Sci::Line start; // When there are wraps pending, will be in document range 115*8af74909SZhong Yang Sci::Line end; // May be lineLarge to indicate all of document after start WrapPendingWrapPending116*8af74909SZhong Yang WrapPending() noexcept { 117*8af74909SZhong Yang start = lineLarge; 118*8af74909SZhong Yang end = lineLarge; 119*8af74909SZhong Yang } ResetWrapPending120*8af74909SZhong Yang void Reset() noexcept { 121*8af74909SZhong Yang start = lineLarge; 122*8af74909SZhong Yang end = lineLarge; 123*8af74909SZhong Yang } WrappedWrapPending124*8af74909SZhong Yang void Wrapped(Sci::Line line) noexcept { 125*8af74909SZhong Yang if (start == line) 126*8af74909SZhong Yang start++; 127*8af74909SZhong Yang } NeedsWrapWrapPending128*8af74909SZhong Yang bool NeedsWrap() const noexcept { 129*8af74909SZhong Yang return start < end; 130*8af74909SZhong Yang } AddRangeWrapPending131*8af74909SZhong Yang bool AddRange(Sci::Line lineStart, Sci::Line lineEnd) noexcept { 132*8af74909SZhong Yang const bool neededWrap = NeedsWrap(); 133*8af74909SZhong Yang bool changed = false; 134*8af74909SZhong Yang if (start > lineStart) { 135*8af74909SZhong Yang start = lineStart; 136*8af74909SZhong Yang changed = true; 137*8af74909SZhong Yang } 138*8af74909SZhong Yang if ((end < lineEnd) || !neededWrap) { 139*8af74909SZhong Yang end = lineEnd; 140*8af74909SZhong Yang changed = true; 141*8af74909SZhong Yang } 142*8af74909SZhong Yang return changed; 143*8af74909SZhong Yang } 144*8af74909SZhong Yang }; 145*8af74909SZhong Yang 146*8af74909SZhong Yang struct CaretPolicy { 147*8af74909SZhong Yang int policy; // Combination from CARET_SLOP, CARET_STRICT, CARET_JUMPS, CARET_EVEN 148*8af74909SZhong Yang int slop; // Pixels for X, lines for Y 149*8af74909SZhong Yang CaretPolicy(uptr_t policy_=0, sptr_t slop_=0) noexcept : policyCaretPolicy150*8af74909SZhong Yang policy(static_cast<int>(policy_)), slop(static_cast<int>(slop_)) {} 151*8af74909SZhong Yang }; 152*8af74909SZhong Yang 153*8af74909SZhong Yang struct CaretPolicies { 154*8af74909SZhong Yang CaretPolicy x; 155*8af74909SZhong Yang CaretPolicy y; 156*8af74909SZhong Yang }; 157*8af74909SZhong Yang 158*8af74909SZhong Yang /** 159*8af74909SZhong Yang */ 160*8af74909SZhong Yang class Editor : public EditModel, public DocWatcher { 161*8af74909SZhong Yang protected: // ScintillaBase subclass needs access to much of Editor 162*8af74909SZhong Yang 163*8af74909SZhong Yang /** On GTK+, Scintilla is a container widget holding two scroll bars 164*8af74909SZhong Yang * whereas on Windows there is just one window with both scroll bars turned on. */ 165*8af74909SZhong Yang Window wMain; ///< The Scintilla parent window 166*8af74909SZhong Yang Window wMargin; ///< May be separate when using a scroll view for wMain 167*8af74909SZhong Yang 168*8af74909SZhong Yang /** Style resources may be expensive to allocate so are cached between uses. 169*8af74909SZhong Yang * When a style attribute is changed, this cache is flushed. */ 170*8af74909SZhong Yang bool stylesValid; 171*8af74909SZhong Yang ViewStyle vs; 172*8af74909SZhong Yang int technology; 173*8af74909SZhong Yang Point sizeRGBAImage; 174*8af74909SZhong Yang float scaleRGBAImage; 175*8af74909SZhong Yang 176*8af74909SZhong Yang MarginView marginView; 177*8af74909SZhong Yang EditView view; 178*8af74909SZhong Yang 179*8af74909SZhong Yang int cursorMode; 180*8af74909SZhong Yang 181*8af74909SZhong Yang bool hasFocus; 182*8af74909SZhong Yang bool mouseDownCaptures; 183*8af74909SZhong Yang bool mouseWheelCaptures; 184*8af74909SZhong Yang 185*8af74909SZhong Yang int xCaretMargin; ///< Ensure this many pixels visible on both sides of caret 186*8af74909SZhong Yang bool horizontalScrollBarVisible; 187*8af74909SZhong Yang int scrollWidth; 188*8af74909SZhong Yang bool verticalScrollBarVisible; 189*8af74909SZhong Yang bool endAtLastLine; 190*8af74909SZhong Yang int caretSticky; 191*8af74909SZhong Yang int marginOptions; 192*8af74909SZhong Yang bool mouseSelectionRectangularSwitch; 193*8af74909SZhong Yang bool multipleSelection; 194*8af74909SZhong Yang bool additionalSelectionTyping; 195*8af74909SZhong Yang int multiPasteMode; 196*8af74909SZhong Yang 197*8af74909SZhong Yang int virtualSpaceOptions; 198*8af74909SZhong Yang 199*8af74909SZhong Yang KeyMap kmap; 200*8af74909SZhong Yang 201*8af74909SZhong Yang Timer timer; 202*8af74909SZhong Yang Timer autoScrollTimer; 203*8af74909SZhong Yang enum { autoScrollDelay = 200 }; 204*8af74909SZhong Yang 205*8af74909SZhong Yang Idler idler; 206*8af74909SZhong Yang 207*8af74909SZhong Yang Point lastClick; 208*8af74909SZhong Yang unsigned int lastClickTime; 209*8af74909SZhong Yang Point doubleClickCloseThreshold; 210*8af74909SZhong Yang int dwellDelay; 211*8af74909SZhong Yang int ticksToDwell; 212*8af74909SZhong Yang bool dwelling; 213*8af74909SZhong Yang enum class TextUnit { character, word, subLine, wholeLine } selectionUnit; 214*8af74909SZhong Yang Point ptMouseLast; 215*8af74909SZhong Yang enum { ddNone, ddInitial, ddDragging } inDragDrop; 216*8af74909SZhong Yang bool dropWentOutside; 217*8af74909SZhong Yang SelectionPosition posDrop; 218*8af74909SZhong Yang Sci::Position hotSpotClickPos; 219*8af74909SZhong Yang int lastXChosen; 220*8af74909SZhong Yang Sci::Position lineAnchorPos; 221*8af74909SZhong Yang Sci::Position originalAnchorPos; 222*8af74909SZhong Yang Sci::Position wordSelectAnchorStartPos; 223*8af74909SZhong Yang Sci::Position wordSelectAnchorEndPos; 224*8af74909SZhong Yang Sci::Position wordSelectInitialCaretPos; 225*8af74909SZhong Yang SelectionSegment targetRange; 226*8af74909SZhong Yang int searchFlags; 227*8af74909SZhong Yang Sci::Line topLine; 228*8af74909SZhong Yang Sci::Position posTopLine; 229*8af74909SZhong Yang Sci::Position lengthForEncode; 230*8af74909SZhong Yang 231*8af74909SZhong Yang int needUpdateUI; 232*8af74909SZhong Yang 233*8af74909SZhong Yang enum { notPainting, painting, paintAbandoned } paintState; 234*8af74909SZhong Yang bool paintAbandonedByStyling; 235*8af74909SZhong Yang PRectangle rcPaint; 236*8af74909SZhong Yang bool paintingAllText; 237*8af74909SZhong Yang bool willRedrawAll; 238*8af74909SZhong Yang WorkNeeded workNeeded; 239*8af74909SZhong Yang int idleStyling; 240*8af74909SZhong Yang bool needIdleStyling; 241*8af74909SZhong Yang 242*8af74909SZhong Yang int modEventMask; 243*8af74909SZhong Yang bool commandEvents; 244*8af74909SZhong Yang 245*8af74909SZhong Yang SelectionText drag; 246*8af74909SZhong Yang 247*8af74909SZhong Yang CaretPolicies caretPolicies; 248*8af74909SZhong Yang 249*8af74909SZhong Yang CaretPolicy visiblePolicy; 250*8af74909SZhong Yang 251*8af74909SZhong Yang Sci::Position searchAnchor; 252*8af74909SZhong Yang 253*8af74909SZhong Yang bool recordingMacro; 254*8af74909SZhong Yang 255*8af74909SZhong Yang int foldAutomatic; 256*8af74909SZhong Yang 257*8af74909SZhong Yang // Wrapping support 258*8af74909SZhong Yang WrapPending wrapPending; 259*8af74909SZhong Yang ActionDuration durationWrapOneLine; 260*8af74909SZhong Yang 261*8af74909SZhong Yang bool convertPastes; 262*8af74909SZhong Yang 263*8af74909SZhong Yang Editor(); 264*8af74909SZhong Yang // Deleted so Editor objects can not be copied. 265*8af74909SZhong Yang Editor(const Editor &) = delete; 266*8af74909SZhong Yang Editor(Editor &&) = delete; 267*8af74909SZhong Yang Editor &operator=(const Editor &) = delete; 268*8af74909SZhong Yang Editor &operator=(Editor &&) = delete; 269*8af74909SZhong Yang // ~Editor() in public section 270*8af74909SZhong Yang virtual void Initialise() = 0; 271*8af74909SZhong Yang virtual void Finalise(); 272*8af74909SZhong Yang 273*8af74909SZhong Yang void InvalidateStyleData(); 274*8af74909SZhong Yang void InvalidateStyleRedraw(); 275*8af74909SZhong Yang void RefreshStyleData(); 276*8af74909SZhong Yang void SetRepresentations(); 277*8af74909SZhong Yang void DropGraphics(bool freeObjects); 278*8af74909SZhong Yang void AllocateGraphics(); 279*8af74909SZhong Yang 280*8af74909SZhong Yang // The top left visible point in main window coordinates. Will be 0,0 except for 281*8af74909SZhong Yang // scroll views where it will be equivalent to the current scroll position. 282*8af74909SZhong Yang Point GetVisibleOriginInMain() const override; 283*8af74909SZhong Yang PointDocument DocumentPointFromView(Point ptView) const; // Convert a point from view space to document 284*8af74909SZhong Yang Sci::Line TopLineOfMain() const override; // Return the line at Main's y coordinate 0 285*8af74909SZhong Yang virtual PRectangle GetClientRectangle() const; 286*8af74909SZhong Yang virtual PRectangle GetClientDrawingRectangle(); 287*8af74909SZhong Yang PRectangle GetTextRectangle() const; 288*8af74909SZhong Yang 289*8af74909SZhong Yang Sci::Line LinesOnScreen() const override; 290*8af74909SZhong Yang Sci::Line LinesToScroll() const; 291*8af74909SZhong Yang Sci::Line MaxScrollPos() const; 292*8af74909SZhong Yang SelectionPosition ClampPositionIntoDocument(SelectionPosition sp) const; 293*8af74909SZhong Yang Point LocationFromPosition(SelectionPosition pos, PointEnd pe=peDefault); 294*8af74909SZhong Yang Point LocationFromPosition(Sci::Position pos, PointEnd pe=peDefault); 295*8af74909SZhong Yang int XFromPosition(SelectionPosition sp); 296*8af74909SZhong Yang SelectionPosition SPositionFromLocation(Point pt, bool canReturnInvalid=false, bool charPosition=false, bool virtualSpace=true); 297*8af74909SZhong Yang Sci::Position PositionFromLocation(Point pt, bool canReturnInvalid = false, bool charPosition = false); 298*8af74909SZhong Yang SelectionPosition SPositionFromLineX(Sci::Line lineDoc, int x); 299*8af74909SZhong Yang Sci::Position PositionFromLineX(Sci::Line lineDoc, int x); 300*8af74909SZhong Yang Sci::Line LineFromLocation(Point pt) const; 301*8af74909SZhong Yang void SetTopLine(Sci::Line topLineNew); 302*8af74909SZhong Yang 303*8af74909SZhong Yang virtual bool AbandonPaint(); 304*8af74909SZhong Yang virtual void RedrawRect(PRectangle rc); 305*8af74909SZhong Yang virtual void DiscardOverdraw(); 306*8af74909SZhong Yang virtual void Redraw(); 307*8af74909SZhong Yang void RedrawSelMargin(Sci::Line line=-1, bool allAfter=false); 308*8af74909SZhong Yang PRectangle RectangleFromRange(Range r, int overlap); 309*8af74909SZhong Yang void InvalidateRange(Sci::Position start, Sci::Position end); 310*8af74909SZhong Yang UserVirtualSpace()311*8af74909SZhong Yang bool UserVirtualSpace() const noexcept { 312*8af74909SZhong Yang return ((virtualSpaceOptions & SCVS_USERACCESSIBLE) != 0); 313*8af74909SZhong Yang } 314*8af74909SZhong Yang Sci::Position CurrentPosition() const; 315*8af74909SZhong Yang bool SelectionEmpty() const noexcept; 316*8af74909SZhong Yang SelectionPosition SelectionStart(); 317*8af74909SZhong Yang SelectionPosition SelectionEnd(); 318*8af74909SZhong Yang void SetRectangularRange(); 319*8af74909SZhong Yang void ThinRectangularRange(); 320*8af74909SZhong Yang void InvalidateSelection(SelectionRange newMain, bool invalidateWholeSelection=false); 321*8af74909SZhong Yang void InvalidateWholeSelection(); 322*8af74909SZhong Yang SelectionRange LineSelectionRange(SelectionPosition currentPos_, SelectionPosition anchor_) const; 323*8af74909SZhong Yang void SetSelection(SelectionPosition currentPos_, SelectionPosition anchor_); 324*8af74909SZhong Yang void SetSelection(Sci::Position currentPos_, Sci::Position anchor_); 325*8af74909SZhong Yang void SetSelection(SelectionPosition currentPos_); 326*8af74909SZhong Yang void SetSelection(int currentPos_); 327*8af74909SZhong Yang void SetEmptySelection(SelectionPosition currentPos_); 328*8af74909SZhong Yang void SetEmptySelection(Sci::Position currentPos_); 329*8af74909SZhong Yang enum class AddNumber { one, each }; 330*8af74909SZhong Yang void MultipleSelectAdd(AddNumber addNumber); 331*8af74909SZhong Yang bool RangeContainsProtected(Sci::Position start, Sci::Position end) const noexcept; 332*8af74909SZhong Yang bool SelectionContainsProtected() const; 333*8af74909SZhong Yang Sci::Position MovePositionOutsideChar(Sci::Position pos, Sci::Position moveDir, bool checkLineEnd=true) const; 334*8af74909SZhong Yang SelectionPosition MovePositionOutsideChar(SelectionPosition pos, Sci::Position moveDir, bool checkLineEnd=true) const; 335*8af74909SZhong Yang void MovedCaret(SelectionPosition newPos, SelectionPosition previousPos, 336*8af74909SZhong Yang bool ensureVisible, CaretPolicies policies); 337*8af74909SZhong Yang void MovePositionTo(SelectionPosition newPos, Selection::selTypes selt=Selection::noSel, bool ensureVisible=true); 338*8af74909SZhong Yang void MovePositionTo(Sci::Position newPos, Selection::selTypes selt=Selection::noSel, bool ensureVisible=true); 339*8af74909SZhong Yang SelectionPosition MovePositionSoVisible(SelectionPosition pos, int moveDir); 340*8af74909SZhong Yang SelectionPosition MovePositionSoVisible(Sci::Position pos, int moveDir); 341*8af74909SZhong Yang Point PointMainCaret(); 342*8af74909SZhong Yang void SetLastXChosen(); 343*8af74909SZhong Yang 344*8af74909SZhong Yang void ScrollTo(Sci::Line line, bool moveThumb=true); 345*8af74909SZhong Yang virtual void ScrollText(Sci::Line linesToMove); 346*8af74909SZhong Yang void HorizontalScrollTo(int xPos); 347*8af74909SZhong Yang void VerticalCentreCaret(); 348*8af74909SZhong Yang void MoveSelectedLines(int lineDelta); 349*8af74909SZhong Yang void MoveSelectedLinesUp(); 350*8af74909SZhong Yang void MoveSelectedLinesDown(); 351*8af74909SZhong Yang void MoveCaretInsideView(bool ensureVisible=true); 352*8af74909SZhong Yang Sci::Line DisplayFromPosition(Sci::Position pos); 353*8af74909SZhong Yang 354*8af74909SZhong Yang struct XYScrollPosition { 355*8af74909SZhong Yang int xOffset; 356*8af74909SZhong Yang Sci::Line topLine; XYScrollPositionXYScrollPosition357*8af74909SZhong Yang XYScrollPosition(int xOffset_, Sci::Line topLine_) noexcept : xOffset(xOffset_), topLine(topLine_) {} 358*8af74909SZhong Yang bool operator==(const XYScrollPosition &other) const noexcept { 359*8af74909SZhong Yang return (xOffset == other.xOffset) && (topLine == other.topLine); 360*8af74909SZhong Yang } 361*8af74909SZhong Yang }; 362*8af74909SZhong Yang enum XYScrollOptions { 363*8af74909SZhong Yang xysUseMargin=0x1, 364*8af74909SZhong Yang xysVertical=0x2, 365*8af74909SZhong Yang xysHorizontal=0x4, 366*8af74909SZhong Yang xysDefault=xysUseMargin|xysVertical|xysHorizontal}; 367*8af74909SZhong Yang XYScrollPosition XYScrollToMakeVisible(const SelectionRange &range, 368*8af74909SZhong Yang const XYScrollOptions options, CaretPolicies policies); 369*8af74909SZhong Yang void SetXYScroll(XYScrollPosition newXY); 370*8af74909SZhong Yang void EnsureCaretVisible(bool useMargin=true, bool vert=true, bool horiz=true); 371*8af74909SZhong Yang void ScrollRange(SelectionRange range); 372*8af74909SZhong Yang void ShowCaretAtCurrentPosition(); 373*8af74909SZhong Yang void DropCaret(); 374*8af74909SZhong Yang void CaretSetPeriod(int period); 375*8af74909SZhong Yang void InvalidateCaret(); 376*8af74909SZhong Yang virtual void NotifyCaretMove(); 377*8af74909SZhong Yang virtual void UpdateSystemCaret(); 378*8af74909SZhong Yang 379*8af74909SZhong Yang bool Wrapping() const noexcept; 380*8af74909SZhong Yang void NeedWrapping(Sci::Line docLineStart=0, Sci::Line docLineEnd=WrapPending::lineLarge); 381*8af74909SZhong Yang bool WrapOneLine(Surface *surface, Sci::Line lineToWrap); 382*8af74909SZhong Yang enum class WrapScope {wsAll, wsVisible, wsIdle}; 383*8af74909SZhong Yang bool WrapLines(WrapScope ws); 384*8af74909SZhong Yang void LinesJoin(); 385*8af74909SZhong Yang void LinesSplit(int pixelWidth); 386*8af74909SZhong Yang 387*8af74909SZhong Yang void PaintSelMargin(Surface *surfaceWindow, const PRectangle &rc); 388*8af74909SZhong Yang void RefreshPixMaps(Surface *surfaceWindow); 389*8af74909SZhong Yang void Paint(Surface *surfaceWindow, PRectangle rcArea); 390*8af74909SZhong Yang Sci::Position FormatRange(bool draw, const Sci_RangeToFormat *pfr); 391*8af74909SZhong Yang long TextWidth(uptr_t style, const char *text); 392*8af74909SZhong Yang 393*8af74909SZhong Yang virtual void SetVerticalScrollPos() = 0; 394*8af74909SZhong Yang virtual void SetHorizontalScrollPos() = 0; 395*8af74909SZhong Yang virtual bool ModifyScrollBars(Sci::Line nMax, Sci::Line nPage) = 0; 396*8af74909SZhong Yang virtual void ReconfigureScrollBars(); 397*8af74909SZhong Yang void SetScrollBars(); 398*8af74909SZhong Yang void ChangeSize(); 399*8af74909SZhong Yang 400*8af74909SZhong Yang void FilterSelections(); 401*8af74909SZhong Yang Sci::Position RealizeVirtualSpace(Sci::Position position, Sci::Position virtualSpace); 402*8af74909SZhong Yang SelectionPosition RealizeVirtualSpace(const SelectionPosition &position); 403*8af74909SZhong Yang void AddChar(char ch); 404*8af74909SZhong Yang virtual void InsertCharacter(std::string_view sv, CharacterSource charSource); 405*8af74909SZhong Yang void ClearBeforeTentativeStart(); 406*8af74909SZhong Yang void InsertPaste(const char *text, Sci::Position len); 407*8af74909SZhong Yang enum PasteShape { pasteStream=0, pasteRectangular = 1, pasteLine = 2 }; 408*8af74909SZhong Yang void InsertPasteShape(const char *text, Sci::Position len, PasteShape shape); 409*8af74909SZhong Yang void ClearSelection(bool retainMultipleSelections = false); 410*8af74909SZhong Yang void ClearAll(); 411*8af74909SZhong Yang void ClearDocumentStyle(); 412*8af74909SZhong Yang virtual void Cut(); 413*8af74909SZhong Yang void PasteRectangular(SelectionPosition pos, const char *ptr, Sci::Position len); 414*8af74909SZhong Yang virtual void Copy() = 0; 415*8af74909SZhong Yang void CopyAllowLine(); 416*8af74909SZhong Yang virtual bool CanPaste(); 417*8af74909SZhong Yang virtual void Paste() = 0; 418*8af74909SZhong Yang void Clear(); 419*8af74909SZhong Yang virtual void SelectAll(); 420*8af74909SZhong Yang virtual void Undo(); 421*8af74909SZhong Yang virtual void Redo(); 422*8af74909SZhong Yang void DelCharBack(bool allowLineStartDeletion); 423*8af74909SZhong Yang virtual void ClaimSelection() = 0; 424*8af74909SZhong Yang 425*8af74909SZhong Yang static int ModifierFlags(bool shift, bool ctrl, bool alt, bool meta=false, bool super=false) noexcept; 426*8af74909SZhong Yang virtual void NotifyChange() = 0; 427*8af74909SZhong Yang virtual void NotifyFocus(bool focus); 428*8af74909SZhong Yang virtual void SetCtrlID(int identifier); GetCtrlID()429*8af74909SZhong Yang virtual int GetCtrlID() { return ctrlID; } 430*8af74909SZhong Yang virtual void NotifyParent(SCNotification scn) = 0; 431*8af74909SZhong Yang virtual void NotifyStyleToNeeded(Sci::Position endStyleNeeded); 432*8af74909SZhong Yang void NotifyChar(int ch, CharacterSource charSource); 433*8af74909SZhong Yang void NotifySavePoint(bool isSavePoint); 434*8af74909SZhong Yang void NotifyModifyAttempt(); 435*8af74909SZhong Yang virtual void NotifyDoubleClick(Point pt, int modifiers); 436*8af74909SZhong Yang void NotifyHotSpotClicked(Sci::Position position, int modifiers); 437*8af74909SZhong Yang void NotifyHotSpotDoubleClicked(Sci::Position position, int modifiers); 438*8af74909SZhong Yang void NotifyHotSpotReleaseClick(Sci::Position position, int modifiers); 439*8af74909SZhong Yang bool NotifyUpdateUI(); 440*8af74909SZhong Yang void NotifyPainted(); 441*8af74909SZhong Yang void NotifyIndicatorClick(bool click, Sci::Position position, int modifiers); 442*8af74909SZhong Yang bool NotifyMarginClick(Point pt, int modifiers); 443*8af74909SZhong Yang bool NotifyMarginRightClick(Point pt, int modifiers); 444*8af74909SZhong Yang void NotifyNeedShown(Sci::Position pos, Sci::Position len); 445*8af74909SZhong Yang void NotifyDwelling(Point pt, bool state); 446*8af74909SZhong Yang void NotifyZoom(); 447*8af74909SZhong Yang 448*8af74909SZhong Yang void NotifyModifyAttempt(Document *document, void *userData) override; 449*8af74909SZhong Yang void NotifySavePoint(Document *document, void *userData, bool atSavePoint) override; 450*8af74909SZhong Yang void CheckModificationForWrap(DocModification mh); 451*8af74909SZhong Yang void NotifyModified(Document *document, DocModification mh, void *userData) override; 452*8af74909SZhong Yang void NotifyDeleted(Document *document, void *userData) noexcept override; 453*8af74909SZhong Yang void NotifyStyleNeeded(Document *doc, void *userData, Sci::Position endStyleNeeded) override; 454*8af74909SZhong Yang void NotifyLexerChanged(Document *doc, void *userData) override; 455*8af74909SZhong Yang void NotifyErrorOccurred(Document *doc, void *userData, int status) override; 456*8af74909SZhong Yang void NotifyMacroRecord(unsigned int iMessage, uptr_t wParam, sptr_t lParam); 457*8af74909SZhong Yang 458*8af74909SZhong Yang void ContainerNeedsUpdate(int flags) noexcept; 459*8af74909SZhong Yang void PageMove(int direction, Selection::selTypes selt=Selection::noSel, bool stuttered = false); 460*8af74909SZhong Yang enum { cmSame, cmUpper, cmLower }; 461*8af74909SZhong Yang virtual std::string CaseMapString(const std::string &s, int caseMapping); 462*8af74909SZhong Yang void ChangeCaseOfSelection(int caseMapping); 463*8af74909SZhong Yang void LineTranspose(); 464*8af74909SZhong Yang void LineReverse(); 465*8af74909SZhong Yang void Duplicate(bool forLine); 466*8af74909SZhong Yang virtual void CancelModes(); 467*8af74909SZhong Yang void NewLine(); 468*8af74909SZhong Yang SelectionPosition PositionUpOrDown(SelectionPosition spStart, int direction, int lastX); 469*8af74909SZhong Yang void CursorUpOrDown(int direction, Selection::selTypes selt); 470*8af74909SZhong Yang void ParaUpOrDown(int direction, Selection::selTypes selt); 471*8af74909SZhong Yang Range RangeDisplayLine(Sci::Line lineVisible); 472*8af74909SZhong Yang Sci::Position StartEndDisplayLine(Sci::Position pos, bool start); 473*8af74909SZhong Yang Sci::Position VCHomeDisplayPosition(Sci::Position position); 474*8af74909SZhong Yang Sci::Position VCHomeWrapPosition(Sci::Position position); 475*8af74909SZhong Yang Sci::Position LineEndWrapPosition(Sci::Position position); 476*8af74909SZhong Yang int HorizontalMove(unsigned int iMessage); 477*8af74909SZhong Yang int DelWordOrLine(unsigned int iMessage); 478*8af74909SZhong Yang virtual int KeyCommand(unsigned int iMessage); 479*8af74909SZhong Yang virtual int KeyDefault(int /* key */, int /*modifiers*/); 480*8af74909SZhong Yang int KeyDownWithModifiers(int key, int modifiers, bool *consumed); 481*8af74909SZhong Yang 482*8af74909SZhong Yang void Indent(bool forwards); 483*8af74909SZhong Yang 484*8af74909SZhong Yang virtual CaseFolder *CaseFolderForEncoding(); 485*8af74909SZhong Yang Sci::Position FindText(uptr_t wParam, sptr_t lParam); 486*8af74909SZhong Yang void SearchAnchor(); 487*8af74909SZhong Yang Sci::Position SearchText(unsigned int iMessage, uptr_t wParam, sptr_t lParam); 488*8af74909SZhong Yang Sci::Position SearchInTarget(const char *text, Sci::Position length); 489*8af74909SZhong Yang void GoToLine(Sci::Line lineNo); 490*8af74909SZhong Yang 491*8af74909SZhong Yang virtual void CopyToClipboard(const SelectionText &selectedText) = 0; 492*8af74909SZhong Yang std::string RangeText(Sci::Position start, Sci::Position end) const; 493*8af74909SZhong Yang void CopySelectionRange(SelectionText *ss, bool allowLineCopy=false); 494*8af74909SZhong Yang void CopyRangeToClipboard(Sci::Position start, Sci::Position end); 495*8af74909SZhong Yang void CopyText(size_t length, const char *text); 496*8af74909SZhong Yang void SetDragPosition(SelectionPosition newPos); 497*8af74909SZhong Yang virtual void DisplayCursor(Window::Cursor c); 498*8af74909SZhong Yang virtual bool DragThreshold(Point ptStart, Point ptNow); 499*8af74909SZhong Yang virtual void StartDrag(); 500*8af74909SZhong Yang void DropAt(SelectionPosition position, const char *value, size_t lengthValue, bool moving, bool rectangular); 501*8af74909SZhong Yang void DropAt(SelectionPosition position, const char *value, bool moving, bool rectangular); 502*8af74909SZhong Yang /** PositionInSelection returns true if position in selection. */ 503*8af74909SZhong Yang bool PositionInSelection(Sci::Position pos); 504*8af74909SZhong Yang bool PointInSelection(Point pt); 505*8af74909SZhong Yang bool PointInSelMargin(Point pt) const; 506*8af74909SZhong Yang Window::Cursor GetMarginCursor(Point pt) const noexcept; 507*8af74909SZhong Yang void TrimAndSetSelection(Sci::Position currentPos_, Sci::Position anchor_); 508*8af74909SZhong Yang void LineSelection(Sci::Position lineCurrentPos_, Sci::Position lineAnchorPos_, bool wholeLine); 509*8af74909SZhong Yang void WordSelection(Sci::Position pos); 510*8af74909SZhong Yang void DwellEnd(bool mouseMoved); 511*8af74909SZhong Yang void MouseLeave(); 512*8af74909SZhong Yang virtual void ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifiers); 513*8af74909SZhong Yang virtual void RightButtonDownWithModifiers(Point pt, unsigned int curTime, int modifiers); 514*8af74909SZhong Yang void ButtonMoveWithModifiers(Point pt, unsigned int curTime, int modifiers); 515*8af74909SZhong Yang void ButtonUpWithModifiers(Point pt, unsigned int curTime, int modifiers); 516*8af74909SZhong Yang 517*8af74909SZhong Yang bool Idle(); 518*8af74909SZhong Yang enum TickReason { tickCaret, tickScroll, tickWiden, tickDwell, tickPlatform }; 519*8af74909SZhong Yang virtual void TickFor(TickReason reason); 520*8af74909SZhong Yang virtual bool FineTickerRunning(TickReason reason); 521*8af74909SZhong Yang virtual void FineTickerStart(TickReason reason, int millis, int tolerance); 522*8af74909SZhong Yang virtual void FineTickerCancel(TickReason reason); SetIdle(bool)523*8af74909SZhong Yang virtual bool SetIdle(bool) { return false; } 524*8af74909SZhong Yang virtual void SetMouseCapture(bool on) = 0; 525*8af74909SZhong Yang virtual bool HaveMouseCapture() = 0; 526*8af74909SZhong Yang void SetFocusState(bool focusState); 527*8af74909SZhong Yang 528*8af74909SZhong Yang Sci::Position PositionAfterArea(PRectangle rcArea) const; 529*8af74909SZhong Yang void StyleToPositionInView(Sci::Position pos); 530*8af74909SZhong Yang Sci::Position PositionAfterMaxStyling(Sci::Position posMax, bool scrolling) const; 531*8af74909SZhong Yang void StartIdleStyling(bool truncatedLastStyling); 532*8af74909SZhong Yang void StyleAreaBounded(PRectangle rcArea, bool scrolling); SynchronousStylingToVisible()533*8af74909SZhong Yang constexpr bool SynchronousStylingToVisible() const noexcept { 534*8af74909SZhong Yang return (idleStyling == SC_IDLESTYLING_NONE) || (idleStyling == SC_IDLESTYLING_AFTERVISIBLE); 535*8af74909SZhong Yang } 536*8af74909SZhong Yang void IdleStyling(); 537*8af74909SZhong Yang virtual void IdleWork(); 538*8af74909SZhong Yang virtual void QueueIdleWork(WorkNeeded::workItems items, Sci::Position upTo=0); 539*8af74909SZhong Yang 540*8af74909SZhong Yang virtual bool PaintContains(PRectangle rc); 541*8af74909SZhong Yang bool PaintContainsMargin(); 542*8af74909SZhong Yang void CheckForChangeOutsidePaint(Range r); 543*8af74909SZhong Yang void SetBraceHighlight(Sci::Position pos0, Sci::Position pos1, int matchStyle); 544*8af74909SZhong Yang 545*8af74909SZhong Yang void SetAnnotationHeights(Sci::Line start, Sci::Line end); 546*8af74909SZhong Yang virtual void SetDocPointer(Document *document); 547*8af74909SZhong Yang 548*8af74909SZhong Yang void SetAnnotationVisible(int visible); 549*8af74909SZhong Yang void SetEOLAnnotationVisible(int visible); 550*8af74909SZhong Yang 551*8af74909SZhong Yang Sci::Line ExpandLine(Sci::Line line); 552*8af74909SZhong Yang void SetFoldExpanded(Sci::Line lineDoc, bool expanded); 553*8af74909SZhong Yang void FoldLine(Sci::Line line, int action); 554*8af74909SZhong Yang void FoldExpand(Sci::Line line, int action, int level); 555*8af74909SZhong Yang Sci::Line ContractedFoldNext(Sci::Line lineStart) const; 556*8af74909SZhong Yang void EnsureLineVisible(Sci::Line lineDoc, bool enforcePolicy); 557*8af74909SZhong Yang void FoldChanged(Sci::Line line, int levelNow, int levelPrev); 558*8af74909SZhong Yang void NeedShown(Sci::Position pos, Sci::Position len); 559*8af74909SZhong Yang void FoldAll(int action); 560*8af74909SZhong Yang 561*8af74909SZhong Yang Sci::Position GetTag(char *tagValue, int tagNumber); 562*8af74909SZhong Yang Sci::Position ReplaceTarget(bool replacePatterns, const char *text, Sci::Position length=-1); 563*8af74909SZhong Yang 564*8af74909SZhong Yang bool PositionIsHotspot(Sci::Position position) const; 565*8af74909SZhong Yang bool PointIsHotspot(Point pt); 566*8af74909SZhong Yang void SetHotSpotRange(const Point *pt); 567*8af74909SZhong Yang Range GetHotSpotRange() const noexcept override; 568*8af74909SZhong Yang void SetHoverIndicatorPosition(Sci::Position position); 569*8af74909SZhong Yang void SetHoverIndicatorPoint(Point pt); 570*8af74909SZhong Yang 571*8af74909SZhong Yang int CodePage() const noexcept; ValidCodePage(int)572*8af74909SZhong Yang virtual bool ValidCodePage(int /* codePage */) const { return true; } 573*8af74909SZhong Yang Sci::Line WrapCount(Sci::Line line); 574*8af74909SZhong Yang void AddStyledText(const char *buffer, Sci::Position appendLength); 575*8af74909SZhong Yang 576*8af74909SZhong Yang virtual sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) = 0; 577*8af74909SZhong Yang bool ValidMargin(uptr_t wParam) const noexcept; 578*8af74909SZhong Yang void StyleSetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam); 579*8af74909SZhong Yang sptr_t StyleGetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam); 580*8af74909SZhong Yang void SetSelectionNMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam); 581*8af74909SZhong Yang 582*8af74909SZhong Yang static const char *StringFromEOLMode(int eolMode) noexcept; 583*8af74909SZhong Yang 584*8af74909SZhong Yang // Coercion functions for transforming WndProc parameters into pointers PtrFromSPtr(sptr_t lParam)585*8af74909SZhong Yang static void *PtrFromSPtr(sptr_t lParam) noexcept { 586*8af74909SZhong Yang return reinterpret_cast<void *>(lParam); 587*8af74909SZhong Yang } ConstCharPtrFromSPtr(sptr_t lParam)588*8af74909SZhong Yang static const char *ConstCharPtrFromSPtr(sptr_t lParam) noexcept { 589*8af74909SZhong Yang return static_cast<const char *>(PtrFromSPtr(lParam)); 590*8af74909SZhong Yang } ConstUCharPtrFromSPtr(sptr_t lParam)591*8af74909SZhong Yang static const unsigned char *ConstUCharPtrFromSPtr(sptr_t lParam) noexcept { 592*8af74909SZhong Yang return static_cast<const unsigned char *>(PtrFromSPtr(lParam)); 593*8af74909SZhong Yang } CharPtrFromSPtr(sptr_t lParam)594*8af74909SZhong Yang static char *CharPtrFromSPtr(sptr_t lParam) noexcept { 595*8af74909SZhong Yang return static_cast<char *>(PtrFromSPtr(lParam)); 596*8af74909SZhong Yang } UCharPtrFromSPtr(sptr_t lParam)597*8af74909SZhong Yang static unsigned char *UCharPtrFromSPtr(sptr_t lParam) noexcept { 598*8af74909SZhong Yang return static_cast<unsigned char *>(PtrFromSPtr(lParam)); 599*8af74909SZhong Yang } PtrFromUPtr(uptr_t wParam)600*8af74909SZhong Yang static void *PtrFromUPtr(uptr_t wParam) noexcept { 601*8af74909SZhong Yang return reinterpret_cast<void *>(wParam); 602*8af74909SZhong Yang } ConstCharPtrFromUPtr(uptr_t wParam)603*8af74909SZhong Yang static const char *ConstCharPtrFromUPtr(uptr_t wParam) noexcept { 604*8af74909SZhong Yang return static_cast<const char *>(PtrFromUPtr(wParam)); 605*8af74909SZhong Yang } 606*8af74909SZhong Yang 607*8af74909SZhong Yang static sptr_t StringResult(sptr_t lParam, const char *val) noexcept; 608*8af74909SZhong Yang static sptr_t BytesResult(sptr_t lParam, const unsigned char *val, size_t len) noexcept; 609*8af74909SZhong Yang 610*8af74909SZhong Yang // Set a variable controlling appearance to a value and invalidates the display 611*8af74909SZhong Yang // if a change was made. Avoids extra text and the possibility of mistyping. 612*8af74909SZhong Yang template <typename T> SetAppearance(T & variable,T value)613*8af74909SZhong Yang bool SetAppearance(T &variable, T value) { 614*8af74909SZhong Yang // Using ! and == as more types have == defined than !=. 615*8af74909SZhong Yang const bool changed = !(variable == value); 616*8af74909SZhong Yang if (changed) { 617*8af74909SZhong Yang variable = value; 618*8af74909SZhong Yang InvalidateStyleRedraw(); 619*8af74909SZhong Yang } 620*8af74909SZhong Yang return changed; 621*8af74909SZhong Yang } 622*8af74909SZhong Yang 623*8af74909SZhong Yang public: 624*8af74909SZhong Yang ~Editor() override; 625*8af74909SZhong Yang 626*8af74909SZhong Yang // Public so the COM thunks can access it. 627*8af74909SZhong Yang bool IsUnicodeMode() const noexcept; 628*8af74909SZhong Yang // Public so scintilla_send_message can use it. 629*8af74909SZhong Yang virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam); 630*8af74909SZhong Yang // Public so scintilla_set_id can use it. 631*8af74909SZhong Yang int ctrlID; 632*8af74909SZhong Yang // Public so COM methods for drag and drop can set it. 633*8af74909SZhong Yang int errorStatus; 634*8af74909SZhong Yang friend class AutoSurface; 635*8af74909SZhong Yang }; 636*8af74909SZhong Yang 637*8af74909SZhong Yang /** 638*8af74909SZhong Yang * A smart pointer class to ensure Surfaces are set up and deleted correctly. 639*8af74909SZhong Yang */ 640*8af74909SZhong Yang class AutoSurface { 641*8af74909SZhong Yang private: 642*8af74909SZhong Yang std::unique_ptr<Surface> surf; 643*8af74909SZhong Yang public: 644*8af74909SZhong Yang AutoSurface(const Editor *ed, int technology = -1) { 645*8af74909SZhong Yang if (ed->wMain.GetID()) { 646*8af74909SZhong Yang surf.reset(Surface::Allocate(technology != -1 ? technology : ed->technology)); 647*8af74909SZhong Yang surf->Init(ed->wMain.GetID()); 648*8af74909SZhong Yang surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage()); 649*8af74909SZhong Yang surf->SetDBCSMode(ed->CodePage()); 650*8af74909SZhong Yang surf->SetBidiR2L(ed->BidirectionalR2L()); 651*8af74909SZhong Yang } 652*8af74909SZhong Yang } 653*8af74909SZhong Yang AutoSurface(SurfaceID sid, Editor *ed, int technology = -1) { 654*8af74909SZhong Yang if (ed->wMain.GetID()) { 655*8af74909SZhong Yang surf.reset(Surface::Allocate(technology != -1 ? technology : ed->technology)); 656*8af74909SZhong Yang surf->Init(sid, ed->wMain.GetID()); 657*8af74909SZhong Yang surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage()); 658*8af74909SZhong Yang surf->SetDBCSMode(ed->CodePage()); 659*8af74909SZhong Yang surf->SetBidiR2L(ed->BidirectionalR2L()); 660*8af74909SZhong Yang } 661*8af74909SZhong Yang } 662*8af74909SZhong Yang // Deleted so AutoSurface objects can not be copied. 663*8af74909SZhong Yang AutoSurface(const AutoSurface &) = delete; 664*8af74909SZhong Yang AutoSurface(AutoSurface &&) = delete; 665*8af74909SZhong Yang void operator=(const AutoSurface &) = delete; 666*8af74909SZhong Yang void operator=(AutoSurface &&) = delete; ~AutoSurface()667*8af74909SZhong Yang ~AutoSurface() { 668*8af74909SZhong Yang } 669*8af74909SZhong Yang Surface *operator->() const noexcept { 670*8af74909SZhong Yang return surf.get(); 671*8af74909SZhong Yang } 672*8af74909SZhong Yang operator Surface *() const noexcept { 673*8af74909SZhong Yang return surf.get(); 674*8af74909SZhong Yang } 675*8af74909SZhong Yang }; 676*8af74909SZhong Yang 677*8af74909SZhong Yang } 678*8af74909SZhong Yang 679*8af74909SZhong Yang #endif 680