1 // Scintilla source code edit control
3 ** Defines the main editor class.
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.
10 #include "Scintilla.h"
12 namespace Scintilla::Internal
{
20 enum {tickSize
= 100};
37 * When platform has a way to generate an event before painting,
38 * accumulate needed styling range and other work items in
39 * WorkNeeded to avoid unnecessary work inside paint handler
42 enum class WorkItems
{
53 WorkNeeded() noexcept
: items(WorkItems::none
), upTo(0) {}
54 void Reset() noexcept
{
55 items
= WorkItems::none
;
58 void Need(WorkItems items_
, Sci::Position pos
) noexcept
{
59 if (Scintilla::FlagSet(items_
, WorkItems::style
) && (upTo
< pos
))
61 items
= static_cast<WorkItems
>(static_cast<int>(items
) | static_cast<int>(items_
));
66 * Hold a piece of text selected for copying or dragging, along with encoding and selection format information.
74 Scintilla::CharacterSet characterSet
;
75 SelectionText() noexcept
: rectangular(false), lineCopy(false), codePage(0), characterSet(Scintilla::CharacterSet::Ansi
) {}
76 void Clear() noexcept
{
81 characterSet
= Scintilla::CharacterSet::Ansi
;
83 void Copy(const std::string
&s_
, int codePage_
, Scintilla::CharacterSet characterSet_
, bool rectangular_
, bool lineCopy_
) {
86 characterSet
= characterSet_
;
87 rectangular
= rectangular_
;
89 FixSelectionForClipboard();
91 void Copy(const SelectionText
&other
) {
92 Copy(other
.s
, other
.codePage
, other
.characterSet
, other
.rectangular
, other
.lineCopy
);
94 const char *Data() const noexcept
{
97 size_t Length() const noexcept
{
100 size_t LengthWithTerminator() const noexcept
{
101 return s
.length() + 1;
103 bool Empty() const noexcept
{
107 void FixSelectionForClipboard() {
108 // To avoid truncating the contents of the clipboard when pasted where the
109 // clipboard contains NUL characters, replace NUL characters by spaces.
110 std::replace(s
.begin(), s
.end(), '\0', ' ');
115 // The range of lines that need to be wrapped
116 enum { lineLarge
= 0x7ffffff };
117 Sci::Line start
; // When there are wraps pending, will be in document range
118 Sci::Line end
; // May be lineLarge to indicate all of document after start
119 WrapPending() noexcept
{
123 void Reset() noexcept
{
127 void Wrapped(Sci::Line line
) noexcept
{
131 bool NeedsWrap() const noexcept
{
134 bool AddRange(Sci::Line lineStart
, Sci::Line lineEnd
) noexcept
{
135 const bool neededWrap
= NeedsWrap();
136 bool changed
= false;
137 if (start
> lineStart
) {
141 if ((end
< lineEnd
) || !neededWrap
) {
149 struct CaretPolicySlop
{
150 Scintilla::CaretPolicy policy
; // Combination from CaretPolicy::Slop, CaretPolicy::Strict, CaretPolicy::Jumps, CaretPolicy::Even
151 int slop
; // Pixels for X, lines for Y
152 CaretPolicySlop(Scintilla::CaretPolicy policy_
, intptr_t slop_
) noexcept
:
153 policy(policy_
), slop(static_cast<int>(slop_
)) {}
154 CaretPolicySlop(uintptr_t policy_
=0, intptr_t slop_
=0) noexcept
:
155 policy(static_cast<Scintilla::CaretPolicy
>(policy_
)), slop(static_cast<int>(slop_
)) {}
158 struct CaretPolicies
{
163 struct VisiblePolicySlop
{
164 Scintilla::VisiblePolicy policy
; // Combination from VisiblePolicy::Slop, VisiblePolicy::Strict
165 int slop
; // Pixels for X, lines for Y
166 VisiblePolicySlop(uintptr_t policy_
= 0, intptr_t slop_
= 0) noexcept
:
167 policy(static_cast<Scintilla::VisiblePolicy
>(policy_
)), slop(static_cast<int>(slop_
)) {}
170 enum class XYScrollOptions
{
175 all
= useMargin
| vertical
| horizontal
178 constexpr XYScrollOptions
operator|(XYScrollOptions a
, XYScrollOptions b
) noexcept
{
179 return static_cast<XYScrollOptions
>(static_cast<int>(a
) | static_cast<int>(b
));
184 class Editor
: public EditModel
, public DocWatcher
{
185 protected: // ScintillaBase subclass needs access to much of Editor
187 /** On GTK+, Scintilla is a container widget holding two scroll bars
188 * whereas on Windows there is just one window with both scroll bars turned on. */
189 Window wMain
; ///< The Scintilla parent window
190 Window wMargin
; ///< May be separate when using a scroll view for wMain
192 // Optimization that avoids superfluous invalidations
193 bool redrawPendingText
= false;
194 bool redrawPendingMargin
= false;
196 /** Style resources may be expensive to allocate so are cached between uses.
197 * When a style attribute is changed, this cache is flushed. */
200 Scintilla::Technology technology
;
202 float scaleRGBAImage
;
204 MarginView marginView
;
207 Scintilla::CursorShape cursorMode
;
209 bool mouseDownCaptures
;
210 bool mouseWheelCaptures
;
212 int xCaretMargin
; ///< Ensure this many pixels visible on both sides of caret
213 bool horizontalScrollBarVisible
;
215 bool verticalScrollBarVisible
;
217 Scintilla::CaretSticky caretSticky
;
218 Scintilla::MarginOption marginOptions
;
219 bool mouseSelectionRectangularSwitch
;
220 bool multipleSelection
;
221 bool additionalSelectionTyping
;
222 Scintilla::MultiPaste multiPasteMode
;
224 Scintilla::VirtualSpace virtualSpaceOptions
;
229 Timer autoScrollTimer
;
230 enum { autoScrollDelay
= 200 };
235 unsigned int lastClickTime
;
236 Point doubleClickCloseThreshold
;
240 enum class TextUnit
{ character
, word
, subLine
, wholeLine
} selectionUnit
;
242 enum class DragDrop
{ none
, initial
, dragging
} inDragDrop
;
243 bool dropWentOutside
;
244 SelectionPosition posDrop
;
245 Sci::Position hotSpotClickPos
;
247 Sci::Position lineAnchorPos
;
248 Sci::Position originalAnchorPos
;
249 Sci::Position wordSelectAnchorStartPos
;
250 Sci::Position wordSelectAnchorEndPos
;
251 Sci::Position wordSelectInitialCaretPos
;
252 SelectionSegment targetRange
;
253 Scintilla::FindOption searchFlags
;
255 Sci::Position posTopLine
;
256 Sci::Position lengthForEncode
;
258 Scintilla::Update needUpdateUI
;
260 enum class PaintState
{ notPainting
, painting
, abandoned
} paintState
;
261 bool paintAbandonedByStyling
;
263 bool paintingAllText
;
265 WorkNeeded workNeeded
;
266 Scintilla::IdleStyling idleStyling
;
267 bool needIdleStyling
;
269 Scintilla::ModificationFlags modEventMask
;
274 CaretPolicies caretPolicies
;
276 VisiblePolicySlop visiblePolicy
;
278 Sci::Position searchAnchor
;
282 Scintilla::AutomaticFold foldAutomatic
;
285 WrapPending wrapPending
;
286 ActionDuration durationWrapOneByte
;
291 // Deleted so Editor objects can not be copied.
292 Editor(const Editor
&) = delete;
293 Editor(Editor
&&) = delete;
294 Editor
&operator=(const Editor
&) = delete;
295 Editor
&operator=(Editor
&&) = delete;
296 // ~Editor() in public section
297 virtual void Initialise() = 0;
298 virtual void Finalise();
300 void InvalidateStyleData() noexcept
;
301 void InvalidateStyleRedraw();
302 void RefreshStyleData();
303 void SetRepresentations();
304 void DropGraphics() noexcept
;
306 bool HasMarginWindow() const noexcept
;
307 // The top left visible point in main window coordinates. Will be 0,0 except for
308 // scroll views where it will be equivalent to the current scroll position.
309 Point
GetVisibleOriginInMain() const override
;
310 PointDocument
DocumentPointFromView(Point ptView
) const; // Convert a point from view space to document
311 Sci::Line
TopLineOfMain() const noexcept final
; // Return the line at Main's y coordinate 0
312 virtual Point
ClientSize() const;
313 virtual PRectangle
GetClientRectangle() const;
314 virtual PRectangle
GetClientDrawingRectangle();
315 PRectangle
GetTextRectangle() const;
317 Sci::Line
LinesOnScreen() const override
;
318 Sci::Line
LinesToScroll() const;
319 Sci::Line
MaxScrollPos() const;
320 SelectionPosition
ClampPositionIntoDocument(SelectionPosition sp
) const;
321 Point
LocationFromPosition(SelectionPosition pos
, PointEnd pe
=PointEnd::start
);
322 Point
LocationFromPosition(Sci::Position pos
, PointEnd pe
=PointEnd::start
);
323 int XFromPosition(SelectionPosition sp
);
324 SelectionPosition
SPositionFromLocation(Point pt
, bool canReturnInvalid
=false, bool charPosition
=false, bool virtualSpace
=true);
325 Sci::Position
PositionFromLocation(Point pt
, bool canReturnInvalid
= false, bool charPosition
= false);
326 SelectionPosition
SPositionFromLineX(Sci::Line lineDoc
, int x
);
327 Sci::Position
PositionFromLineX(Sci::Line lineDoc
, int x
);
328 Sci::Line
LineFromLocation(Point pt
) const noexcept
;
329 void SetTopLine(Sci::Line topLineNew
);
331 virtual bool AbandonPaint();
332 virtual void RedrawRect(PRectangle rc
);
333 virtual void DiscardOverdraw();
334 virtual void Redraw();
335 void RedrawSelMargin(Sci::Line line
=-1, bool allAfter
=false);
336 PRectangle
RectangleFromRange(Range r
, int overlap
);
337 void InvalidateRange(Sci::Position start
, Sci::Position end
);
339 bool UserVirtualSpace() const noexcept
{
340 return (FlagSet(virtualSpaceOptions
, Scintilla::VirtualSpace::UserAccessible
));
342 Sci::Position
CurrentPosition() const noexcept
;
343 bool SelectionEmpty() const noexcept
;
344 SelectionPosition
SelectionStart() noexcept
;
345 SelectionPosition
SelectionEnd() noexcept
;
346 void SetRectangularRange();
347 void ThinRectangularRange();
348 void InvalidateSelection(SelectionRange newMain
, bool invalidateWholeSelection
=false);
349 void InvalidateWholeSelection();
350 SelectionRange
LineSelectionRange(SelectionPosition currentPos_
, SelectionPosition anchor_
) const;
351 void SetSelection(SelectionPosition currentPos_
, SelectionPosition anchor_
);
352 void SetSelection(Sci::Position currentPos_
, Sci::Position anchor_
);
353 void SetSelection(SelectionPosition currentPos_
);
354 void SetEmptySelection(SelectionPosition currentPos_
);
355 void SetEmptySelection(Sci::Position currentPos_
);
356 enum class AddNumber
{ one
, each
};
357 void MultipleSelectAdd(AddNumber addNumber
);
358 bool RangeContainsProtected(Sci::Position start
, Sci::Position end
) const noexcept
;
359 bool SelectionContainsProtected() const noexcept
;
360 Sci::Position
MovePositionOutsideChar(Sci::Position pos
, Sci::Position moveDir
, bool checkLineEnd
=true) const;
361 SelectionPosition
MovePositionOutsideChar(SelectionPosition pos
, Sci::Position moveDir
, bool checkLineEnd
=true) const;
362 void MovedCaret(SelectionPosition newPos
, SelectionPosition previousPos
,
363 bool ensureVisible
, CaretPolicies policies
);
364 void MovePositionTo(SelectionPosition newPos
, Selection::SelTypes selt
=Selection::SelTypes::none
, bool ensureVisible
=true);
365 void MovePositionTo(Sci::Position newPos
, Selection::SelTypes selt
=Selection::SelTypes::none
, bool ensureVisible
=true);
366 SelectionPosition
MovePositionSoVisible(SelectionPosition pos
, int moveDir
);
367 SelectionPosition
MovePositionSoVisible(Sci::Position pos
, int moveDir
);
368 Point
PointMainCaret();
369 void SetLastXChosen();
371 void ScrollTo(Sci::Line line
, bool moveThumb
=true);
372 virtual void ScrollText(Sci::Line linesToMove
);
373 void HorizontalScrollTo(int xPos
);
374 void VerticalCentreCaret();
375 void MoveSelectedLines(int lineDelta
);
376 void MoveSelectedLinesUp();
377 void MoveSelectedLinesDown();
378 void MoveCaretInsideView(bool ensureVisible
=true);
379 Sci::Line
DisplayFromPosition(Sci::Position pos
);
381 struct XYScrollPosition
{
384 XYScrollPosition(int xOffset_
, Sci::Line topLine_
) noexcept
: xOffset(xOffset_
), topLine(topLine_
) {}
385 bool operator==(const XYScrollPosition
&other
) const noexcept
{
386 return (xOffset
== other
.xOffset
) && (topLine
== other
.topLine
);
389 XYScrollPosition
XYScrollToMakeVisible(const SelectionRange
&range
,
390 const XYScrollOptions options
, CaretPolicies policies
);
391 void SetXYScroll(XYScrollPosition newXY
);
392 void EnsureCaretVisible(bool useMargin
=true, bool vert
=true, bool horiz
=true);
393 void ScrollRange(SelectionRange range
);
394 void ShowCaretAtCurrentPosition();
396 void CaretSetPeriod(int period
);
397 void InvalidateCaret();
398 virtual void NotifyCaretMove();
399 virtual void UpdateSystemCaret();
401 bool Wrapping() const noexcept
;
402 void NeedWrapping(Sci::Line docLineStart
=0, Sci::Line docLineEnd
=WrapPending::lineLarge
);
403 bool WrapOneLine(Surface
*surface
, Sci::Line lineToWrap
);
404 bool WrapBlock(Surface
*surface
, Sci::Line lineToWrap
, Sci::Line lineToWrapEnd
);
405 enum class WrapScope
{wsAll
, wsVisible
, wsIdle
};
406 bool WrapLines(WrapScope ws
);
408 void LinesSplit(int pixelWidth
);
410 void PaintSelMargin(Surface
*surfaceWindow
, const PRectangle
&rc
);
411 void RefreshPixMaps(Surface
*surfaceWindow
);
412 void Paint(Surface
*surfaceWindow
, PRectangle rcArea
);
413 Sci::Position
FormatRange(Scintilla::Message iMessage
, Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
);
414 long TextWidth(Scintilla::uptr_t style
, const char *text
);
416 virtual void SetVerticalScrollPos() = 0;
417 virtual void SetHorizontalScrollPos() = 0;
418 virtual bool ModifyScrollBars(Sci::Line nMax
, Sci::Line nPage
) = 0;
419 virtual void ReconfigureScrollBars();
420 void ChangeScrollBars();
421 virtual void SetScrollBars();
424 void FilterSelections();
425 Sci::Position
RealizeVirtualSpace(Sci::Position position
, Sci::Position virtualSpace
);
426 SelectionPosition
RealizeVirtualSpace(const SelectionPosition
&position
);
427 void AddChar(char ch
);
428 virtual void InsertCharacter(std::string_view sv
, Scintilla::CharacterSource charSource
);
429 void ClearBeforeTentativeStart();
430 void InsertPaste(const char *text
, Sci::Position len
);
431 enum class PasteShape
{ stream
=0, rectangular
= 1, line
= 2 };
432 void InsertPasteShape(const char *text
, Sci::Position len
, PasteShape shape
);
433 void ClearSelection(bool retainMultipleSelections
= false);
435 void ClearDocumentStyle();
437 void PasteRectangular(SelectionPosition pos
, const char *ptr
, Sci::Position len
);
438 virtual void Copy() = 0;
439 void CopyAllowLine();
440 virtual bool CanPaste();
441 virtual void Paste() = 0;
443 virtual void SelectAll();
446 void DelCharBack(bool allowLineStartDeletion
);
447 virtual void ClaimSelection() = 0;
449 virtual void NotifyChange() = 0;
450 virtual void NotifyFocus(bool focus
);
451 virtual void SetCtrlID(int identifier
);
452 virtual int GetCtrlID() { return ctrlID
; }
453 virtual void NotifyParent(Scintilla::NotificationData scn
) = 0;
454 virtual void NotifyStyleToNeeded(Sci::Position endStyleNeeded
);
455 void NotifyChar(int ch
, Scintilla::CharacterSource charSource
);
456 void NotifySavePoint(bool isSavePoint
);
457 void NotifyModifyAttempt();
458 virtual void NotifyDoubleClick(Point pt
, Scintilla::KeyMod modifiers
);
459 void NotifyHotSpotClicked(Sci::Position position
, Scintilla::KeyMod modifiers
);
460 void NotifyHotSpotDoubleClicked(Sci::Position position
, Scintilla::KeyMod modifiers
);
461 void NotifyHotSpotReleaseClick(Sci::Position position
, Scintilla::KeyMod modifiers
);
462 bool NotifyUpdateUI();
463 void NotifyPainted();
464 void NotifyIndicatorClick(bool click
, Sci::Position position
, Scintilla::KeyMod modifiers
);
465 bool NotifyMarginClick(Point pt
, Scintilla::KeyMod modifiers
);
466 bool NotifyMarginRightClick(Point pt
, Scintilla::KeyMod modifiers
);
467 void NotifyNeedShown(Sci::Position pos
, Sci::Position len
);
468 void NotifyDwelling(Point pt
, bool state
);
471 void NotifyModifyAttempt(Document
*document
, void *userData
) override
;
472 void NotifySavePoint(Document
*document
, void *userData
, bool atSavePoint
) override
;
473 void CheckModificationForWrap(DocModification mh
);
474 void NotifyModified(Document
*document
, DocModification mh
, void *userData
) override
;
475 void NotifyDeleted(Document
*document
, void *userData
) noexcept override
;
476 void NotifyStyleNeeded(Document
*doc
, void *userData
, Sci::Position endStyleNeeded
) override
;
477 void NotifyErrorOccurred(Document
*doc
, void *userData
, Scintilla::Status status
) override
;
478 void NotifyMacroRecord(Scintilla::Message iMessage
, Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
);
480 void ContainerNeedsUpdate(Scintilla::Update flags
) noexcept
;
481 void PageMove(int direction
, Selection::SelTypes selt
=Selection::SelTypes::none
, bool stuttered
= false);
482 enum class CaseMapping
{ same
, upper
, lower
};
483 virtual std::string
CaseMapString(const std::string
&s
, CaseMapping caseMapping
);
484 void ChangeCaseOfSelection(CaseMapping caseMapping
);
485 void LineTranspose();
487 void Duplicate(bool forLine
);
488 virtual void CancelModes();
490 SelectionPosition
PositionUpOrDown(SelectionPosition spStart
, int direction
, int lastX
);
491 void CursorUpOrDown(int direction
, Selection::SelTypes selt
);
492 void ParaUpOrDown(int direction
, Selection::SelTypes selt
);
493 Range
RangeDisplayLine(Sci::Line lineVisible
);
494 Sci::Position
StartEndDisplayLine(Sci::Position pos
, bool start
);
495 Sci::Position
HomeWrapPosition(Sci::Position position
);
496 Sci::Position
VCHomeDisplayPosition(Sci::Position position
);
497 Sci::Position
VCHomeWrapPosition(Sci::Position position
);
498 Sci::Position
LineEndWrapPosition(Sci::Position position
);
499 SelectionPosition
PositionMove(Scintilla::Message iMessage
, SelectionPosition spCaretNow
);
500 SelectionRange
SelectionMove(Scintilla::Message iMessage
, size_t r
);
501 int HorizontalMove(Scintilla::Message iMessage
);
502 int DelWordOrLine(Scintilla::Message iMessage
);
503 virtual int KeyCommand(Scintilla::Message iMessage
);
504 virtual int KeyDefault(Scintilla::Keys
/* key */, Scintilla::KeyMod
/*modifiers*/);
505 int KeyDownWithModifiers(Scintilla::Keys key
, Scintilla::KeyMod modifiers
, bool *consumed
);
507 void Indent(bool forwards
);
509 virtual std::unique_ptr
<CaseFolder
> CaseFolderForEncoding();
510 Sci::Position
FindText(Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
);
511 Sci::Position
FindTextFull(Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
);
512 void SearchAnchor() noexcept
;
513 Sci::Position
SearchText(Scintilla::Message iMessage
, Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
);
514 Sci::Position
SearchInTarget(const char *text
, Sci::Position length
);
515 void GoToLine(Sci::Line lineNo
);
517 virtual void CopyToClipboard(const SelectionText
&selectedText
) = 0;
518 std::string
RangeText(Sci::Position start
, Sci::Position end
) const;
519 void CopySelectionRange(SelectionText
*ss
, bool allowLineCopy
=false);
520 void CopyRangeToClipboard(Sci::Position start
, Sci::Position end
);
521 void CopyText(size_t length
, const char *text
);
522 void SetDragPosition(SelectionPosition newPos
);
523 virtual void DisplayCursor(Window::Cursor c
);
524 virtual bool DragThreshold(Point ptStart
, Point ptNow
);
525 virtual void StartDrag();
526 void DropAt(SelectionPosition position
, const char *value
, size_t lengthValue
, bool moving
, bool rectangular
);
527 void DropAt(SelectionPosition position
, const char *value
, bool moving
, bool rectangular
);
528 /** PositionInSelection returns true if position in selection. */
529 bool PositionInSelection(Sci::Position pos
);
530 bool PointInSelection(Point pt
);
531 ptrdiff_t SelectionFromPoint(Point pt
);
532 bool PointInSelMargin(Point pt
) const;
533 Window::Cursor
GetMarginCursor(Point pt
) const noexcept
;
534 void DropSelection(size_t part
);
535 void TrimAndSetSelection(Sci::Position currentPos_
, Sci::Position anchor_
);
536 void LineSelection(Sci::Position lineCurrentPos_
, Sci::Position lineAnchorPos_
, bool wholeLine
);
537 void WordSelection(Sci::Position pos
);
538 void DwellEnd(bool mouseMoved
);
540 virtual void ButtonDownWithModifiers(Point pt
, unsigned int curTime
, Scintilla::KeyMod modifiers
);
541 virtual void RightButtonDownWithModifiers(Point pt
, unsigned int curTime
, Scintilla::KeyMod modifiers
);
542 void ButtonMoveWithModifiers(Point pt
, unsigned int curTime
, Scintilla::KeyMod modifiers
);
543 void ButtonUpWithModifiers(Point pt
, unsigned int curTime
, Scintilla::KeyMod modifiers
);
546 enum class TickReason
{ caret
, scroll
, widen
, dwell
, platform
};
547 virtual void TickFor(TickReason reason
);
548 virtual bool FineTickerRunning(TickReason reason
);
549 virtual void FineTickerStart(TickReason reason
, int millis
, int tolerance
);
550 virtual void FineTickerCancel(TickReason reason
);
551 virtual bool SetIdle(bool) { return false; }
552 void ChangeMouseCapture(bool on
);
553 virtual void SetMouseCapture(bool on
) = 0;
554 virtual bool HaveMouseCapture() = 0;
555 void SetFocusState(bool focusState
);
556 virtual void UpdateBaseElements();
558 Sci::Position
PositionAfterArea(PRectangle rcArea
) const;
559 void StyleToPositionInView(Sci::Position pos
);
560 Sci::Position
PositionAfterMaxStyling(Sci::Position posMax
, bool scrolling
) const;
561 void StartIdleStyling(bool truncatedLastStyling
);
562 void StyleAreaBounded(PRectangle rcArea
, bool scrolling
);
563 constexpr bool SynchronousStylingToVisible() const noexcept
{
564 return (idleStyling
== Scintilla::IdleStyling::None
) || (idleStyling
== Scintilla::IdleStyling::AfterVisible
);
567 virtual void IdleWork();
568 virtual void QueueIdleWork(WorkItems items
, Sci::Position upTo
=0);
570 virtual int SupportsFeature(Scintilla::Supports feature
);
571 virtual bool PaintContains(PRectangle rc
);
572 bool PaintContainsMargin();
573 void CheckForChangeOutsidePaint(Range r
);
574 void SetBraceHighlight(Sci::Position pos0
, Sci::Position pos1
, int matchStyle
);
576 void SetAnnotationHeights(Sci::Line start
, Sci::Line end
);
577 virtual void SetDocPointer(Document
*document
);
579 void SetAnnotationVisible(Scintilla::AnnotationVisible visible
);
580 void SetEOLAnnotationVisible(Scintilla::EOLAnnotationVisible visible
);
582 Sci::Line
ExpandLine(Sci::Line line
);
583 void SetFoldExpanded(Sci::Line lineDoc
, bool expanded
);
584 void FoldLine(Sci::Line line
, Scintilla::FoldAction action
);
585 void FoldExpand(Sci::Line line
, Scintilla::FoldAction action
, Scintilla::FoldLevel level
);
586 Sci::Line
ContractedFoldNext(Sci::Line lineStart
) const;
587 void EnsureLineVisible(Sci::Line lineDoc
, bool enforcePolicy
);
588 void FoldChanged(Sci::Line line
, Scintilla::FoldLevel levelNow
, Scintilla::FoldLevel levelPrev
);
589 void NeedShown(Sci::Position pos
, Sci::Position len
);
590 void FoldAll(Scintilla::FoldAction action
);
592 Sci::Position
GetTag(char *tagValue
, int tagNumber
);
593 enum class ReplaceType
{basic
, patterns
, minimal
};
594 Sci::Position
ReplaceTarget(ReplaceType replaceType
, std::string_view text
);
596 bool PositionIsHotspot(Sci::Position position
) const noexcept
;
597 bool PointIsHotspot(Point pt
);
598 void SetHotSpotRange(const Point
*pt
);
599 void SetHoverIndicatorPosition(Sci::Position position
);
600 void SetHoverIndicatorPoint(Point pt
);
602 int CodePage() const noexcept
;
603 virtual bool ValidCodePage(int /* codePage */) const { return true; }
604 virtual std::string
UTF8FromEncoded(std::string_view encoded
) const = 0;
605 virtual std::string
EncodedFromUTF8(std::string_view utf8
) const = 0;
606 virtual std::unique_ptr
<Surface
> CreateMeasurementSurface() const;
607 virtual std::unique_ptr
<Surface
> CreateDrawingSurface(SurfaceID sid
, std::optional
<Scintilla::Technology
> technologyOpt
= {}) const;
609 Sci::Line
WrapCount(Sci::Line line
);
610 void AddStyledText(const char *buffer
, Sci::Position appendLength
);
611 Sci::Position
GetStyledText(char *buffer
, Sci::Position cpMin
, Sci::Position cpMax
) const noexcept
;
612 Sci::Position
GetTextRange(char *buffer
, Sci::Position cpMin
, Sci::Position cpMax
) const;
614 virtual Scintilla::sptr_t
DefWndProc(Scintilla::Message iMessage
, Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
) = 0;
615 bool ValidMargin(Scintilla::uptr_t wParam
) const noexcept
;
616 void StyleSetMessage(Scintilla::Message iMessage
, Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
);
617 Scintilla::sptr_t
StyleGetMessage(Scintilla::Message iMessage
, Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
);
618 void SetSelectionNMessage(Scintilla::Message iMessage
, Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
);
619 void SetSelectionMode(uptr_t wParam
, bool setMoveExtends
);
621 // Coercion functions for transforming WndProc parameters into pointers
622 static void *PtrFromSPtr(Scintilla::sptr_t lParam
) noexcept
{
623 return reinterpret_cast<void *>(lParam
);
625 static const char *ConstCharPtrFromSPtr(Scintilla::sptr_t lParam
) noexcept
{
626 return static_cast<const char *>(PtrFromSPtr(lParam
));
628 static const unsigned char *ConstUCharPtrFromSPtr(Scintilla::sptr_t lParam
) noexcept
{
629 return static_cast<const unsigned char *>(PtrFromSPtr(lParam
));
631 static char *CharPtrFromSPtr(Scintilla::sptr_t lParam
) noexcept
{
632 return static_cast<char *>(PtrFromSPtr(lParam
));
634 static unsigned char *UCharPtrFromSPtr(Scintilla::sptr_t lParam
) noexcept
{
635 return static_cast<unsigned char *>(PtrFromSPtr(lParam
));
637 static std::string_view
ViewFromParams(Scintilla::sptr_t lParam
, Scintilla::uptr_t wParam
) noexcept
{
638 if (SPtrFromUPtr(wParam
) == -1) {
639 return std::string_view(CharPtrFromSPtr(lParam
));
641 return std::string_view(CharPtrFromSPtr(lParam
), wParam
);
643 static void *PtrFromUPtr(Scintilla::uptr_t wParam
) noexcept
{
644 return reinterpret_cast<void *>(wParam
);
646 static const char *ConstCharPtrFromUPtr(Scintilla::uptr_t wParam
) noexcept
{
647 return static_cast<const char *>(PtrFromUPtr(wParam
));
650 static constexpr Scintilla::sptr_t
SPtrFromUPtr(Scintilla::uptr_t wParam
) noexcept
{
651 return static_cast<Scintilla::sptr_t
>(wParam
);
653 static constexpr Sci::Position
PositionFromUPtr(Scintilla::uptr_t wParam
) noexcept
{
654 return SPtrFromUPtr(wParam
);
656 static constexpr Sci::Line
LineFromUPtr(Scintilla::uptr_t wParam
) noexcept
{
657 return SPtrFromUPtr(wParam
);
659 Point
PointFromParameters(Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
) const noexcept
{
660 return Point(static_cast<XYPOSITION
>(wParam
) - vs
.ExternalMarginWidth(), static_cast<XYPOSITION
>(lParam
));
663 static constexpr std::optional
<FoldLevel
> OptionalFoldLevel(Scintilla::sptr_t lParam
) {
665 return static_cast<FoldLevel
>(lParam
);
670 static Scintilla::sptr_t
StringResult(Scintilla::sptr_t lParam
, const char *val
) noexcept
;
671 static Scintilla::sptr_t
BytesResult(Scintilla::sptr_t lParam
, const unsigned char *val
, size_t len
) noexcept
;
672 static Scintilla::sptr_t
BytesResult(Scintilla::sptr_t lParam
, std::string_view sv
) noexcept
;
674 // Set a variable controlling appearance to a value and invalidates the display
675 // if a change was made. Avoids extra text and the possibility of mistyping.
676 template <typename T
>
677 bool SetAppearance(T
&variable
, T value
) {
678 // Using ! and == as more types have == defined than !=.
679 const bool changed
= !(variable
== value
);
682 InvalidateStyleRedraw();
690 virtual void NotifyParent(SCNotification
*scn
) = 0;
691 // Public so the COM thunks can access it.
692 bool IsUnicodeMode() const noexcept
;
693 // Public so scintilla_send_message can use it.
694 virtual Scintilla::sptr_t
WndProc(Scintilla::Message iMessage
, Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
);
695 // Public so scintilla_set_id can use it.
697 // Public so COM methods for drag and drop can set it.
698 Scintilla::Status errorStatus
;
699 friend class AutoSurface
;
703 * A smart pointer class to ensure Surfaces are set up and deleted correctly.
707 std::unique_ptr
<Surface
> surf
;
709 AutoSurface(const Editor
*ed
) :
710 surf(ed
->CreateMeasurementSurface()) {
712 AutoSurface(SurfaceID sid
, const Editor
*ed
, std::optional
<Scintilla::Technology
> technology
= {}) :
713 surf(ed
->CreateDrawingSurface(sid
, technology
)) {
715 // Deleted so AutoSurface objects can not be copied.
716 AutoSurface(const AutoSurface
&) = delete;
717 AutoSurface(AutoSurface
&&) = delete;
718 void operator=(const AutoSurface
&) = delete;
719 void operator=(AutoSurface
&&) = delete;
722 Surface
*operator->() const noexcept
{
725 operator Surface
*() const noexcept
{