Update Scintilla to 5.4.3
[TortoiseGit.git] / ext / scintilla / src / Editor.h
blobe5ce0792ff163a54096e2ee2532a2394edb45cce
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 namespace Scintilla::Internal {
13 /**
15 class Timer {
16 public:
17 bool ticking;
18 int ticksToWait;
19 enum {tickSize = 100};
20 TickerID tickerID;
22 Timer() noexcept;
25 /**
27 class Idler {
28 public:
29 bool state;
30 IdlerID idlerID;
32 Idler() noexcept;
35 /**
36 * When platform has a way to generate an event before painting,
37 * accumulate needed styling range and other work items in
38 * WorkNeeded to avoid unnecessary work inside paint handler
41 enum class WorkItems {
42 none = 0,
43 style = 1,
44 updateUI = 2
47 class WorkNeeded {
48 public:
49 enum WorkItems items;
50 Sci::Position upTo;
52 WorkNeeded() noexcept : items(WorkItems::none), upTo(0) {}
53 void Reset() noexcept {
54 items = WorkItems::none;
55 upTo = 0;
57 void Need(WorkItems items_, Sci::Position pos) noexcept {
58 if (Scintilla::FlagSet(items_, WorkItems::style) && (upTo < pos))
59 upTo = pos;
60 items = static_cast<WorkItems>(static_cast<int>(items) | static_cast<int>(items_));
64 /**
65 * Hold a piece of text selected for copying or dragging, along with encoding and selection format information.
67 class SelectionText {
68 std::string s;
69 public:
70 bool rectangular;
71 bool lineCopy;
72 int codePage;
73 Scintilla::CharacterSet characterSet;
74 SelectionText() noexcept : rectangular(false), lineCopy(false), codePage(0), characterSet(Scintilla::CharacterSet::Ansi) {}
75 void Clear() noexcept {
76 s.clear();
77 rectangular = false;
78 lineCopy = false;
79 codePage = 0;
80 characterSet = Scintilla::CharacterSet::Ansi;
82 void Copy(const std::string &s_, int codePage_, Scintilla::CharacterSet characterSet_, bool rectangular_, bool lineCopy_) {
83 s = s_;
84 codePage = codePage_;
85 characterSet = characterSet_;
86 rectangular = rectangular_;
87 lineCopy = lineCopy_;
88 FixSelectionForClipboard();
90 void Copy(const SelectionText &other) {
91 Copy(other.s, other.codePage, other.characterSet, other.rectangular, other.lineCopy);
93 const char *Data() const noexcept {
94 return s.c_str();
96 size_t Length() const noexcept {
97 return s.length();
99 size_t LengthWithTerminator() const noexcept {
100 return s.length() + 1;
102 bool Empty() const noexcept {
103 return s.empty();
105 private:
106 void FixSelectionForClipboard() {
107 // To avoid truncating the contents of the clipboard when pasted where the
108 // clipboard contains NUL characters, replace NUL characters by spaces.
109 std::replace(s.begin(), s.end(), '\0', ' ');
113 struct WrapPending {
114 // The range of lines that need to be wrapped
115 enum { lineLarge = 0x7ffffff };
116 Sci::Line start; // When there are wraps pending, will be in document range
117 Sci::Line end; // May be lineLarge to indicate all of document after start
118 WrapPending() noexcept {
119 start = lineLarge;
120 end = lineLarge;
122 void Reset() noexcept {
123 start = lineLarge;
124 end = lineLarge;
126 void Wrapped(Sci::Line line) noexcept {
127 if (start == line)
128 start++;
130 bool NeedsWrap() const noexcept {
131 return start < end;
133 bool AddRange(Sci::Line lineStart, Sci::Line lineEnd) noexcept {
134 const bool neededWrap = NeedsWrap();
135 bool changed = false;
136 if (start > lineStart) {
137 start = lineStart;
138 changed = true;
140 if ((end < lineEnd) || !neededWrap) {
141 end = lineEnd;
142 changed = true;
144 return changed;
148 struct CaretPolicySlop {
149 Scintilla::CaretPolicy policy; // Combination from CaretPolicy::Slop, CaretPolicy::Strict, CaretPolicy::Jumps, CaretPolicy::Even
150 int slop; // Pixels for X, lines for Y
151 CaretPolicySlop(Scintilla::CaretPolicy policy_, intptr_t slop_) noexcept :
152 policy(policy_), slop(static_cast<int>(slop_)) {}
153 CaretPolicySlop(uintptr_t policy_=0, intptr_t slop_=0) noexcept :
154 policy(static_cast<Scintilla::CaretPolicy>(policy_)), slop(static_cast<int>(slop_)) {}
157 struct CaretPolicies {
158 CaretPolicySlop x;
159 CaretPolicySlop y;
162 struct VisiblePolicySlop {
163 Scintilla::VisiblePolicy policy; // Combination from VisiblePolicy::Slop, VisiblePolicy::Strict
164 int slop; // Pixels for X, lines for Y
165 VisiblePolicySlop(uintptr_t policy_ = 0, intptr_t slop_ = 0) noexcept :
166 policy(static_cast<Scintilla::VisiblePolicy>(policy_)), slop(static_cast<int>(slop_)) {}
169 enum class XYScrollOptions {
170 none = 0x0,
171 useMargin = 0x1,
172 vertical = 0x2,
173 horizontal = 0x4,
174 all = useMargin | vertical | horizontal
177 constexpr XYScrollOptions operator|(XYScrollOptions a, XYScrollOptions b) noexcept {
178 return static_cast<XYScrollOptions>(static_cast<int>(a) | static_cast<int>(b));
183 class Editor : public EditModel, public DocWatcher {
184 protected: // ScintillaBase subclass needs access to much of Editor
186 /** On GTK+, Scintilla is a container widget holding two scroll bars
187 * whereas on Windows there is just one window with both scroll bars turned on. */
188 Window wMain; ///< The Scintilla parent window
189 Window wMargin; ///< May be separate when using a scroll view for wMain
191 // Optimization that avoids superfluous invalidations
192 bool redrawPendingText = false;
193 bool redrawPendingMargin = false;
195 /** Style resources may be expensive to allocate so are cached between uses.
196 * When a style attribute is changed, this cache is flushed. */
197 bool stylesValid;
198 ViewStyle vs;
199 Scintilla::Technology technology;
200 Point sizeRGBAImage;
201 float scaleRGBAImage;
203 MarginView marginView;
204 EditView view;
206 Scintilla::CursorShape cursorMode;
208 bool mouseDownCaptures;
209 bool mouseWheelCaptures;
211 int xCaretMargin; ///< Ensure this many pixels visible on both sides of caret
212 bool horizontalScrollBarVisible;
213 int scrollWidth;
214 bool verticalScrollBarVisible;
215 bool endAtLastLine;
216 Scintilla::CaretSticky caretSticky;
217 Scintilla::MarginOption marginOptions;
218 bool mouseSelectionRectangularSwitch;
219 bool multipleSelection;
220 bool additionalSelectionTyping;
221 Scintilla::MultiPaste multiPasteMode;
223 Scintilla::VirtualSpace virtualSpaceOptions;
225 KeyMap kmap;
227 Timer timer;
228 Timer autoScrollTimer;
229 enum { autoScrollDelay = 200 };
231 Idler idler;
233 Point lastClick;
234 unsigned int lastClickTime;
235 Point doubleClickCloseThreshold;
236 int dwellDelay;
237 int ticksToDwell;
238 bool dwelling;
239 enum class TextUnit { character, word, subLine, wholeLine } selectionUnit;
240 Point ptMouseLast;
241 enum class DragDrop { none, initial, dragging } inDragDrop;
242 bool dropWentOutside;
243 SelectionPosition posDrop;
244 Sci::Position hotSpotClickPos;
245 int lastXChosen;
246 Sci::Position lineAnchorPos;
247 Sci::Position originalAnchorPos;
248 Sci::Position wordSelectAnchorStartPos;
249 Sci::Position wordSelectAnchorEndPos;
250 Sci::Position wordSelectInitialCaretPos;
251 SelectionSegment targetRange;
252 Scintilla::FindOption searchFlags;
253 Sci::Line topLine;
254 Sci::Position posTopLine;
255 Sci::Position lengthForEncode;
257 Scintilla::Update needUpdateUI;
259 enum class PaintState { notPainting, painting, abandoned } paintState;
260 bool paintAbandonedByStyling;
261 PRectangle rcPaint;
262 bool paintingAllText;
263 bool willRedrawAll;
264 WorkNeeded workNeeded;
265 Scintilla::IdleStyling idleStyling;
266 bool needIdleStyling;
268 Scintilla::ModificationFlags modEventMask;
269 bool commandEvents;
271 SelectionText drag;
273 CaretPolicies caretPolicies;
275 VisiblePolicySlop visiblePolicy;
277 Sci::Position searchAnchor;
279 bool recordingMacro;
281 Scintilla::AutomaticFold foldAutomatic;
283 // Wrapping support
284 WrapPending wrapPending;
285 ActionDuration durationWrapOneByte;
287 bool convertPastes;
289 Editor();
290 // Deleted so Editor objects can not be copied.
291 Editor(const Editor &) = delete;
292 Editor(Editor &&) = delete;
293 Editor &operator=(const Editor &) = delete;
294 Editor &operator=(Editor &&) = delete;
295 // ~Editor() in public section
296 virtual void Initialise() = 0;
297 virtual void Finalise();
299 void InvalidateStyleData() noexcept;
300 void InvalidateStyleRedraw();
301 void RefreshStyleData();
302 void SetRepresentations();
303 void DropGraphics() noexcept;
305 bool HasMarginWindow() const noexcept;
306 // The top left visible point in main window coordinates. Will be 0,0 except for
307 // scroll views where it will be equivalent to the current scroll position.
308 Point GetVisibleOriginInMain() const override;
309 PointDocument DocumentPointFromView(Point ptView) const; // Convert a point from view space to document
310 Sci::Line TopLineOfMain() const noexcept final; // Return the line at Main's y coordinate 0
311 virtual Point ClientSize() const;
312 virtual PRectangle GetClientRectangle() const;
313 virtual PRectangle GetClientDrawingRectangle();
314 PRectangle GetTextRectangle() const;
316 Sci::Line LinesOnScreen() const override;
317 Sci::Line LinesToScroll() const;
318 Sci::Line MaxScrollPos() const;
319 SelectionPosition ClampPositionIntoDocument(SelectionPosition sp) const;
320 Point LocationFromPosition(SelectionPosition pos, PointEnd pe=PointEnd::start);
321 Point LocationFromPosition(Sci::Position pos, PointEnd pe=PointEnd::start);
322 int XFromPosition(SelectionPosition sp);
323 SelectionPosition SPositionFromLocation(Point pt, bool canReturnInvalid=false, bool charPosition=false, bool virtualSpace=true);
324 Sci::Position PositionFromLocation(Point pt, bool canReturnInvalid = false, bool charPosition = false);
325 SelectionPosition SPositionFromLineX(Sci::Line lineDoc, int x);
326 Sci::Position PositionFromLineX(Sci::Line lineDoc, int x);
327 Sci::Line LineFromLocation(Point pt) const noexcept;
328 void SetTopLine(Sci::Line topLineNew);
330 virtual bool AbandonPaint();
331 virtual void RedrawRect(PRectangle rc);
332 virtual void DiscardOverdraw();
333 virtual void Redraw();
334 void RedrawSelMargin(Sci::Line line=-1, bool allAfter=false);
335 PRectangle RectangleFromRange(Range r, int overlap);
336 void InvalidateRange(Sci::Position start, Sci::Position end);
338 bool UserVirtualSpace() const noexcept {
339 return (FlagSet(virtualSpaceOptions, Scintilla::VirtualSpace::UserAccessible));
341 Sci::Position CurrentPosition() const noexcept;
342 bool SelectionEmpty() const noexcept;
343 SelectionPosition SelectionStart() noexcept;
344 SelectionPosition SelectionEnd() noexcept;
345 void SetRectangularRange();
346 void ThinRectangularRange();
347 void InvalidateSelection(SelectionRange newMain, bool invalidateWholeSelection=false);
348 void InvalidateWholeSelection();
349 SelectionRange LineSelectionRange(SelectionPosition currentPos_, SelectionPosition anchor_) const;
350 void SetSelection(SelectionPosition currentPos_, SelectionPosition anchor_);
351 void SetSelection(Sci::Position currentPos_, Sci::Position anchor_);
352 void SetSelection(SelectionPosition currentPos_);
353 void SetEmptySelection(SelectionPosition currentPos_);
354 void SetEmptySelection(Sci::Position currentPos_);
355 enum class AddNumber { one, each };
356 void MultipleSelectAdd(AddNumber addNumber);
357 bool RangeContainsProtected(Sci::Position start, Sci::Position end) const noexcept;
358 bool SelectionContainsProtected() const noexcept;
359 Sci::Position MovePositionOutsideChar(Sci::Position pos, Sci::Position moveDir, bool checkLineEnd=true) const;
360 SelectionPosition MovePositionOutsideChar(SelectionPosition pos, Sci::Position moveDir, bool checkLineEnd=true) const;
361 void MovedCaret(SelectionPosition newPos, SelectionPosition previousPos,
362 bool ensureVisible, CaretPolicies policies);
363 void MovePositionTo(SelectionPosition newPos, Selection::SelTypes selt=Selection::SelTypes::none, bool ensureVisible=true);
364 void MovePositionTo(Sci::Position newPos, Selection::SelTypes selt=Selection::SelTypes::none, bool ensureVisible=true);
365 SelectionPosition MovePositionSoVisible(SelectionPosition pos, int moveDir);
366 SelectionPosition MovePositionSoVisible(Sci::Position pos, int moveDir);
367 Point PointMainCaret();
368 void SetLastXChosen();
370 void ScrollTo(Sci::Line line, bool moveThumb=true);
371 virtual void ScrollText(Sci::Line linesToMove);
372 void HorizontalScrollTo(int xPos);
373 void VerticalCentreCaret();
374 void MoveSelectedLines(int lineDelta);
375 void MoveSelectedLinesUp();
376 void MoveSelectedLinesDown();
377 void MoveCaretInsideView(bool ensureVisible=true);
378 Sci::Line DisplayFromPosition(Sci::Position pos);
380 struct XYScrollPosition {
381 int xOffset;
382 Sci::Line topLine;
383 XYScrollPosition(int xOffset_, Sci::Line topLine_) noexcept : xOffset(xOffset_), topLine(topLine_) {}
384 bool operator==(const XYScrollPosition &other) const noexcept {
385 return (xOffset == other.xOffset) && (topLine == other.topLine);
388 XYScrollPosition XYScrollToMakeVisible(const SelectionRange &range,
389 const XYScrollOptions options, CaretPolicies policies);
390 void SetXYScroll(XYScrollPosition newXY);
391 void EnsureCaretVisible(bool useMargin=true, bool vert=true, bool horiz=true);
392 void ScrollRange(SelectionRange range);
393 void ShowCaretAtCurrentPosition();
394 void DropCaret();
395 void CaretSetPeriod(int period);
396 void InvalidateCaret();
397 virtual void NotifyCaretMove();
398 virtual void UpdateSystemCaret();
400 bool Wrapping() const noexcept;
401 void NeedWrapping(Sci::Line docLineStart=0, Sci::Line docLineEnd=WrapPending::lineLarge);
402 bool WrapOneLine(Surface *surface, Sci::Line lineToWrap);
403 bool WrapBlock(Surface *surface, Sci::Line lineToWrap, Sci::Line lineToWrapEnd);
404 enum class WrapScope {wsAll, wsVisible, wsIdle};
405 bool WrapLines(WrapScope ws);
406 void LinesJoin();
407 void LinesSplit(int pixelWidth);
409 void PaintSelMargin(Surface *surfaceWindow, const PRectangle &rc);
410 void RefreshPixMaps(Surface *surfaceWindow);
411 void Paint(Surface *surfaceWindow, PRectangle rcArea);
412 Sci::Position FormatRange(Scintilla::Message iMessage, Scintilla::uptr_t wParam, Scintilla::sptr_t lParam);
413 long TextWidth(Scintilla::uptr_t style, const char *text);
415 virtual void SetVerticalScrollPos() = 0;
416 virtual void SetHorizontalScrollPos() = 0;
417 virtual bool ModifyScrollBars(Sci::Line nMax, Sci::Line nPage) = 0;
418 virtual void ReconfigureScrollBars();
419 void ChangeScrollBars();
420 virtual void SetScrollBars();
421 void ChangeSize();
423 void FilterSelections();
424 Sci::Position RealizeVirtualSpace(Sci::Position position, Sci::Position virtualSpace);
425 SelectionPosition RealizeVirtualSpace(const SelectionPosition &position);
426 void AddChar(char ch);
427 virtual void InsertCharacter(std::string_view sv, Scintilla::CharacterSource charSource);
428 void ClearBeforeTentativeStart();
429 void InsertPaste(const char *text, Sci::Position len);
430 enum class PasteShape { stream=0, rectangular = 1, line = 2 };
431 void InsertPasteShape(const char *text, Sci::Position len, PasteShape shape);
432 void ClearSelection(bool retainMultipleSelections = false);
433 void ClearAll();
434 void ClearDocumentStyle();
435 virtual void Cut();
436 void PasteRectangular(SelectionPosition pos, const char *ptr, Sci::Position len);
437 virtual void Copy() = 0;
438 void CopyAllowLine();
439 virtual bool CanPaste();
440 virtual void Paste() = 0;
441 void Clear();
442 virtual void SelectAll();
443 virtual void Undo();
444 virtual void Redo();
445 void DelCharBack(bool allowLineStartDeletion);
446 virtual void ClaimSelection() = 0;
448 virtual void NotifyChange() = 0;
449 virtual void NotifyFocus(bool focus);
450 virtual void SetCtrlID(int identifier);
451 virtual int GetCtrlID() { return ctrlID; }
452 virtual void NotifyParent(Scintilla::NotificationData scn) = 0;
453 virtual void NotifyStyleToNeeded(Sci::Position endStyleNeeded);
454 void NotifyChar(int ch, Scintilla::CharacterSource charSource);
455 void NotifySavePoint(bool isSavePoint);
456 void NotifyModifyAttempt();
457 virtual void NotifyDoubleClick(Point pt, Scintilla::KeyMod modifiers);
458 void NotifyHotSpotClicked(Sci::Position position, Scintilla::KeyMod modifiers);
459 void NotifyHotSpotDoubleClicked(Sci::Position position, Scintilla::KeyMod modifiers);
460 void NotifyHotSpotReleaseClick(Sci::Position position, Scintilla::KeyMod modifiers);
461 bool NotifyUpdateUI();
462 void NotifyPainted();
463 void NotifyIndicatorClick(bool click, Sci::Position position, Scintilla::KeyMod modifiers);
464 bool NotifyMarginClick(Point pt, Scintilla::KeyMod modifiers);
465 bool NotifyMarginRightClick(Point pt, Scintilla::KeyMod modifiers);
466 void NotifyNeedShown(Sci::Position pos, Sci::Position len);
467 void NotifyDwelling(Point pt, bool state);
468 void NotifyZoom();
470 void NotifyModifyAttempt(Document *document, void *userData) override;
471 void NotifySavePoint(Document *document, void *userData, bool atSavePoint) override;
472 void CheckModificationForWrap(DocModification mh);
473 void NotifyModified(Document *document, DocModification mh, void *userData) override;
474 void NotifyDeleted(Document *document, void *userData) noexcept override;
475 void NotifyStyleNeeded(Document *doc, void *userData, Sci::Position endStyleNeeded) override;
476 void NotifyErrorOccurred(Document *doc, void *userData, Scintilla::Status status) override;
477 void NotifyMacroRecord(Scintilla::Message iMessage, Scintilla::uptr_t wParam, Scintilla::sptr_t lParam);
479 void ContainerNeedsUpdate(Scintilla::Update flags) noexcept;
480 void PageMove(int direction, Selection::SelTypes selt=Selection::SelTypes::none, bool stuttered = false);
481 enum class CaseMapping { same, upper, lower };
482 virtual std::string CaseMapString(const std::string &s, CaseMapping caseMapping);
483 void ChangeCaseOfSelection(CaseMapping caseMapping);
484 void LineTranspose();
485 void LineReverse();
486 void Duplicate(bool forLine);
487 virtual void CancelModes();
488 void NewLine();
489 SelectionPosition PositionUpOrDown(SelectionPosition spStart, int direction, int lastX);
490 void CursorUpOrDown(int direction, Selection::SelTypes selt);
491 void ParaUpOrDown(int direction, Selection::SelTypes selt);
492 Range RangeDisplayLine(Sci::Line lineVisible);
493 Sci::Position StartEndDisplayLine(Sci::Position pos, bool start);
494 Sci::Position HomeWrapPosition(Sci::Position position);
495 Sci::Position VCHomeDisplayPosition(Sci::Position position);
496 Sci::Position VCHomeWrapPosition(Sci::Position position);
497 Sci::Position LineEndWrapPosition(Sci::Position position);
498 SelectionPosition PositionMove(Scintilla::Message iMessage, SelectionPosition spCaretNow);
499 SelectionRange SelectionMove(Scintilla::Message iMessage, size_t r);
500 int HorizontalMove(Scintilla::Message iMessage);
501 int DelWordOrLine(Scintilla::Message iMessage);
502 virtual int KeyCommand(Scintilla::Message iMessage);
503 virtual int KeyDefault(Scintilla::Keys /* key */, Scintilla::KeyMod /*modifiers*/);
504 int KeyDownWithModifiers(Scintilla::Keys key, Scintilla::KeyMod modifiers, bool *consumed);
506 void Indent(bool forwards);
508 virtual std::unique_ptr<CaseFolder> CaseFolderForEncoding();
509 Sci::Position FindText(Scintilla::uptr_t wParam, Scintilla::sptr_t lParam);
510 Sci::Position FindTextFull(Scintilla::uptr_t wParam, Scintilla::sptr_t lParam);
511 void SearchAnchor() noexcept;
512 Sci::Position SearchText(Scintilla::Message iMessage, Scintilla::uptr_t wParam, Scintilla::sptr_t lParam);
513 Sci::Position SearchInTarget(const char *text, Sci::Position length);
514 void GoToLine(Sci::Line lineNo);
516 virtual void CopyToClipboard(const SelectionText &selectedText) = 0;
517 std::string RangeText(Sci::Position start, Sci::Position end) const;
518 void CopySelectionRange(SelectionText *ss, bool allowLineCopy=false);
519 void CopyRangeToClipboard(Sci::Position start, Sci::Position end);
520 void CopyText(size_t length, const char *text);
521 void SetDragPosition(SelectionPosition newPos);
522 virtual void DisplayCursor(Window::Cursor c);
523 virtual bool DragThreshold(Point ptStart, Point ptNow);
524 virtual void StartDrag();
525 void DropAt(SelectionPosition position, const char *value, size_t lengthValue, bool moving, bool rectangular);
526 void DropAt(SelectionPosition position, const char *value, bool moving, bool rectangular);
527 /** PositionInSelection returns true if position in selection. */
528 bool PositionInSelection(Sci::Position pos);
529 bool PointInSelection(Point pt);
530 ptrdiff_t SelectionFromPoint(Point pt);
531 bool PointInSelMargin(Point pt) const;
532 Window::Cursor GetMarginCursor(Point pt) const noexcept;
533 void DropSelection(size_t part);
534 void TrimAndSetSelection(Sci::Position currentPos_, Sci::Position anchor_);
535 void LineSelection(Sci::Position lineCurrentPos_, Sci::Position lineAnchorPos_, bool wholeLine);
536 void WordSelection(Sci::Position pos);
537 void DwellEnd(bool mouseMoved);
538 void MouseLeave();
539 virtual void ButtonDownWithModifiers(Point pt, unsigned int curTime, Scintilla::KeyMod modifiers);
540 virtual void RightButtonDownWithModifiers(Point pt, unsigned int curTime, Scintilla::KeyMod modifiers);
541 void ButtonMoveWithModifiers(Point pt, unsigned int curTime, Scintilla::KeyMod modifiers);
542 void ButtonUpWithModifiers(Point pt, unsigned int curTime, Scintilla::KeyMod modifiers);
544 bool Idle();
545 enum class TickReason { caret, scroll, widen, dwell, platform };
546 virtual void TickFor(TickReason reason);
547 virtual bool FineTickerRunning(TickReason reason);
548 virtual void FineTickerStart(TickReason reason, int millis, int tolerance);
549 virtual void FineTickerCancel(TickReason reason);
550 virtual bool SetIdle(bool) { return false; }
551 void ChangeMouseCapture(bool on);
552 virtual void SetMouseCapture(bool on) = 0;
553 virtual bool HaveMouseCapture() = 0;
554 void SetFocusState(bool focusState);
555 virtual void UpdateBaseElements();
557 Sci::Position PositionAfterArea(PRectangle rcArea) const;
558 void StyleToPositionInView(Sci::Position pos);
559 Sci::Position PositionAfterMaxStyling(Sci::Position posMax, bool scrolling) const;
560 void StartIdleStyling(bool truncatedLastStyling);
561 void StyleAreaBounded(PRectangle rcArea, bool scrolling);
562 constexpr bool SynchronousStylingToVisible() const noexcept {
563 return (idleStyling == Scintilla::IdleStyling::None) || (idleStyling == Scintilla::IdleStyling::AfterVisible);
565 void IdleStyle();
566 virtual void IdleWork();
567 virtual void QueueIdleWork(WorkItems items, Sci::Position upTo=0);
569 virtual int SupportsFeature(Scintilla::Supports feature);
570 virtual bool PaintContains(PRectangle rc);
571 bool PaintContainsMargin();
572 void CheckForChangeOutsidePaint(Range r);
573 void SetBraceHighlight(Sci::Position pos0, Sci::Position pos1, int matchStyle);
575 void SetAnnotationHeights(Sci::Line start, Sci::Line end);
576 virtual void SetDocPointer(Document *document);
578 void SetAnnotationVisible(Scintilla::AnnotationVisible visible);
579 void SetEOLAnnotationVisible(Scintilla::EOLAnnotationVisible visible);
581 Sci::Line ExpandLine(Sci::Line line);
582 void SetFoldExpanded(Sci::Line lineDoc, bool expanded);
583 void FoldLine(Sci::Line line, Scintilla::FoldAction action);
584 void FoldExpand(Sci::Line line, Scintilla::FoldAction action, Scintilla::FoldLevel level);
585 Sci::Line ContractedFoldNext(Sci::Line lineStart) const;
586 void EnsureLineVisible(Sci::Line lineDoc, bool enforcePolicy);
587 void FoldChanged(Sci::Line line, Scintilla::FoldLevel levelNow, Scintilla::FoldLevel levelPrev);
588 void NeedShown(Sci::Position pos, Sci::Position len);
589 void FoldAll(Scintilla::FoldAction action);
591 Sci::Position GetTag(char *tagValue, int tagNumber);
592 enum class ReplaceType {basic, patterns, minimal};
593 Sci::Position ReplaceTarget(ReplaceType replaceType, std::string_view text);
595 bool PositionIsHotspot(Sci::Position position) const noexcept;
596 bool PointIsHotspot(Point pt);
597 void SetHotSpotRange(const Point *pt);
598 void SetHoverIndicatorPosition(Sci::Position position);
599 void SetHoverIndicatorPoint(Point pt);
601 int CodePage() const noexcept;
602 virtual bool ValidCodePage(int /* codePage */) const { return true; }
603 virtual std::string UTF8FromEncoded(std::string_view encoded) const = 0;
604 virtual std::string EncodedFromUTF8(std::string_view utf8) const = 0;
605 virtual std::unique_ptr<Surface> CreateMeasurementSurface() const;
606 virtual std::unique_ptr<Surface> CreateDrawingSurface(SurfaceID sid, std::optional<Scintilla::Technology> technologyOpt = {}) const;
608 Sci::Line WrapCount(Sci::Line line);
609 void AddStyledText(const char *buffer, Sci::Position appendLength);
610 Sci::Position GetStyledText(char *buffer, Sci::Position cpMin, Sci::Position cpMax) const noexcept;
611 Sci::Position GetTextRange(char *buffer, Sci::Position cpMin, Sci::Position cpMax) const;
613 virtual Scintilla::sptr_t DefWndProc(Scintilla::Message iMessage, Scintilla::uptr_t wParam, Scintilla::sptr_t lParam) = 0;
614 bool ValidMargin(Scintilla::uptr_t wParam) const noexcept;
615 void StyleSetMessage(Scintilla::Message iMessage, Scintilla::uptr_t wParam, Scintilla::sptr_t lParam);
616 Scintilla::sptr_t StyleGetMessage(Scintilla::Message iMessage, Scintilla::uptr_t wParam, Scintilla::sptr_t lParam);
617 void SetSelectionNMessage(Scintilla::Message iMessage, Scintilla::uptr_t wParam, Scintilla::sptr_t lParam);
618 void SetSelectionMode(uptr_t wParam, bool setMoveExtends);
620 // Coercion functions for transforming WndProc parameters into pointers
621 static void *PtrFromSPtr(Scintilla::sptr_t lParam) noexcept {
622 return reinterpret_cast<void *>(lParam);
624 static const char *ConstCharPtrFromSPtr(Scintilla::sptr_t lParam) noexcept {
625 return static_cast<const char *>(PtrFromSPtr(lParam));
627 static const unsigned char *ConstUCharPtrFromSPtr(Scintilla::sptr_t lParam) noexcept {
628 return static_cast<const unsigned char *>(PtrFromSPtr(lParam));
630 static char *CharPtrFromSPtr(Scintilla::sptr_t lParam) noexcept {
631 return static_cast<char *>(PtrFromSPtr(lParam));
633 static unsigned char *UCharPtrFromSPtr(Scintilla::sptr_t lParam) noexcept {
634 return static_cast<unsigned char *>(PtrFromSPtr(lParam));
636 static std::string_view ViewFromParams(Scintilla::sptr_t lParam, Scintilla::uptr_t wParam) noexcept {
637 if (SPtrFromUPtr(wParam) == -1) {
638 return std::string_view(CharPtrFromSPtr(lParam));
640 return std::string_view(CharPtrFromSPtr(lParam), wParam);
642 static void *PtrFromUPtr(Scintilla::uptr_t wParam) noexcept {
643 return reinterpret_cast<void *>(wParam);
645 static const char *ConstCharPtrFromUPtr(Scintilla::uptr_t wParam) noexcept {
646 return static_cast<const char *>(PtrFromUPtr(wParam));
649 static constexpr Scintilla::sptr_t SPtrFromUPtr(Scintilla::uptr_t wParam) noexcept {
650 return static_cast<Scintilla::sptr_t>(wParam);
652 static constexpr Sci::Position PositionFromUPtr(Scintilla::uptr_t wParam) noexcept {
653 return SPtrFromUPtr(wParam);
655 static constexpr Sci::Line LineFromUPtr(Scintilla::uptr_t wParam) noexcept {
656 return SPtrFromUPtr(wParam);
658 Point PointFromParameters(Scintilla::uptr_t wParam, Scintilla::sptr_t lParam) const noexcept {
659 return Point(static_cast<XYPOSITION>(wParam) - vs.ExternalMarginWidth(), static_cast<XYPOSITION>(lParam));
662 static constexpr std::optional<FoldLevel> OptionalFoldLevel(Scintilla::sptr_t lParam) {
663 if (lParam >= 0) {
664 return static_cast<FoldLevel>(lParam);
666 return std::nullopt;
669 static Scintilla::sptr_t StringResult(Scintilla::sptr_t lParam, const char *val) noexcept;
670 static Scintilla::sptr_t BytesResult(Scintilla::sptr_t lParam, const unsigned char *val, size_t len) noexcept;
671 static Scintilla::sptr_t BytesResult(Scintilla::sptr_t lParam, std::string_view sv) noexcept;
673 // Set a variable controlling appearance to a value and invalidates the display
674 // if a change was made. Avoids extra text and the possibility of mistyping.
675 template <typename T>
676 bool SetAppearance(T &variable, T value) {
677 // Using ! and == as more types have == defined than !=.
678 const bool changed = !(variable == value);
679 if (changed) {
680 variable = value;
681 InvalidateStyleRedraw();
683 return changed;
686 public:
687 ~Editor() override;
689 // Public so the COM thunks can access it.
690 bool IsUnicodeMode() const noexcept;
691 // Public so scintilla_send_message can use it.
692 virtual Scintilla::sptr_t WndProc(Scintilla::Message iMessage, Scintilla::uptr_t wParam, Scintilla::sptr_t lParam);
693 // Public so scintilla_set_id can use it.
694 int ctrlID;
695 // Public so COM methods for drag and drop can set it.
696 Scintilla::Status errorStatus;
697 friend class AutoSurface;
701 * A smart pointer class to ensure Surfaces are set up and deleted correctly.
703 class AutoSurface {
704 private:
705 std::unique_ptr<Surface> surf;
706 public:
707 AutoSurface(const Editor *ed) :
708 surf(ed->CreateMeasurementSurface()) {
710 AutoSurface(SurfaceID sid, const Editor *ed, std::optional<Scintilla::Technology> technology = {}) :
711 surf(ed->CreateDrawingSurface(sid, technology)) {
713 // Deleted so AutoSurface objects can not be copied.
714 AutoSurface(const AutoSurface &) = delete;
715 AutoSurface(AutoSurface &&) = delete;
716 void operator=(const AutoSurface &) = delete;
717 void operator=(AutoSurface &&) = delete;
718 ~AutoSurface() {
720 Surface *operator->() const noexcept {
721 return surf.get();
723 operator Surface *() const noexcept {
724 return surf.get();
730 #endif