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.
11 namespace Scintilla::Internal
{
19 enum {tickSize
= 100};
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
{
52 WorkNeeded() noexcept
: items(WorkItems::none
), upTo(0) {}
53 void Reset() noexcept
{
54 items
= WorkItems::none
;
57 void Need(WorkItems items_
, Sci::Position pos
) noexcept
{
58 if (Scintilla::FlagSet(items_
, WorkItems::style
) && (upTo
< pos
))
60 items
= static_cast<WorkItems
>(static_cast<int>(items
) | static_cast<int>(items_
));
65 * Hold a piece of text selected for copying or dragging, along with encoding and selection format information.
73 Scintilla::CharacterSet characterSet
;
74 SelectionText() noexcept
: rectangular(false), lineCopy(false), codePage(0), characterSet(Scintilla::CharacterSet::Ansi
) {}
75 void Clear() noexcept
{
80 characterSet
= Scintilla::CharacterSet::Ansi
;
82 void Copy(const std::string
&s_
, int codePage_
, Scintilla::CharacterSet characterSet_
, bool rectangular_
, bool lineCopy_
) {
85 characterSet
= characterSet_
;
86 rectangular
= rectangular_
;
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
{
96 size_t Length() const noexcept
{
99 size_t LengthWithTerminator() const noexcept
{
100 return s
.length() + 1;
102 bool Empty() const noexcept
{
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', ' ');
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
{
122 void Reset() noexcept
{
126 void Wrapped(Sci::Line line
) noexcept
{
130 bool NeedsWrap() const noexcept
{
133 bool AddRange(Sci::Line lineStart
, Sci::Line lineEnd
) noexcept
{
134 const bool neededWrap
= NeedsWrap();
135 bool changed
= false;
136 if (start
> lineStart
) {
140 if ((end
< lineEnd
) || !neededWrap
) {
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
{
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
{
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 /** Style resources may be expensive to allocate so are cached between uses.
192 * When a style attribute is changed, this cache is flushed. */
195 Scintilla::Technology technology
;
197 float scaleRGBAImage
;
199 MarginView marginView
;
202 Scintilla::CursorShape cursorMode
;
204 bool mouseDownCaptures
;
205 bool mouseWheelCaptures
;
207 int xCaretMargin
; ///< Ensure this many pixels visible on both sides of caret
208 bool horizontalScrollBarVisible
;
210 bool verticalScrollBarVisible
;
212 Scintilla::CaretSticky caretSticky
;
213 Scintilla::MarginOption marginOptions
;
214 bool mouseSelectionRectangularSwitch
;
215 bool multipleSelection
;
216 bool additionalSelectionTyping
;
217 Scintilla::MultiPaste multiPasteMode
;
219 Scintilla::VirtualSpace virtualSpaceOptions
;
224 Timer autoScrollTimer
;
225 enum { autoScrollDelay
= 200 };
230 unsigned int lastClickTime
;
231 Point doubleClickCloseThreshold
;
235 enum class TextUnit
{ character
, word
, subLine
, wholeLine
} selectionUnit
;
237 enum class DragDrop
{ none
, initial
, dragging
} inDragDrop
;
238 bool dropWentOutside
;
239 SelectionPosition posDrop
;
240 Sci::Position hotSpotClickPos
;
242 Sci::Position lineAnchorPos
;
243 Sci::Position originalAnchorPos
;
244 Sci::Position wordSelectAnchorStartPos
;
245 Sci::Position wordSelectAnchorEndPos
;
246 Sci::Position wordSelectInitialCaretPos
;
247 SelectionSegment targetRange
;
248 Scintilla::FindOption searchFlags
;
250 Sci::Position posTopLine
;
251 Sci::Position lengthForEncode
;
253 Scintilla::Update needUpdateUI
;
255 enum class PaintState
{ notPainting
, painting
, abandoned
} paintState
;
256 bool paintAbandonedByStyling
;
258 bool paintingAllText
;
260 WorkNeeded workNeeded
;
261 Scintilla::IdleStyling idleStyling
;
262 bool needIdleStyling
;
264 Scintilla::ModificationFlags modEventMask
;
269 CaretPolicies caretPolicies
;
271 VisiblePolicySlop visiblePolicy
;
273 Sci::Position searchAnchor
;
277 Scintilla::AutomaticFold foldAutomatic
;
280 WrapPending wrapPending
;
281 ActionDuration durationWrapOneByte
;
286 // Deleted so Editor objects can not be copied.
287 Editor(const Editor
&) = delete;
288 Editor(Editor
&&) = delete;
289 Editor
&operator=(const Editor
&) = delete;
290 Editor
&operator=(Editor
&&) = delete;
291 // ~Editor() in public section
292 virtual void Initialise() = 0;
293 virtual void Finalise();
295 void InvalidateStyleData();
296 void InvalidateStyleRedraw();
297 void RefreshStyleData();
298 void SetRepresentations();
299 void DropGraphics() noexcept
;
301 // The top left visible point in main window coordinates. Will be 0,0 except for
302 // scroll views where it will be equivalent to the current scroll position.
303 Point
GetVisibleOriginInMain() const override
;
304 PointDocument
DocumentPointFromView(Point ptView
) const; // Convert a point from view space to document
305 Sci::Line
TopLineOfMain() const override
; // Return the line at Main's y coordinate 0
306 virtual PRectangle
GetClientRectangle() const;
307 virtual PRectangle
GetClientDrawingRectangle();
308 PRectangle
GetTextRectangle() const;
310 Sci::Line
LinesOnScreen() const override
;
311 Sci::Line
LinesToScroll() const;
312 Sci::Line
MaxScrollPos() const;
313 SelectionPosition
ClampPositionIntoDocument(SelectionPosition sp
) const;
314 Point
LocationFromPosition(SelectionPosition pos
, PointEnd pe
=PointEnd::start
);
315 Point
LocationFromPosition(Sci::Position pos
, PointEnd pe
=PointEnd::start
);
316 int XFromPosition(SelectionPosition sp
);
317 SelectionPosition
SPositionFromLocation(Point pt
, bool canReturnInvalid
=false, bool charPosition
=false, bool virtualSpace
=true);
318 Sci::Position
PositionFromLocation(Point pt
, bool canReturnInvalid
= false, bool charPosition
= false);
319 SelectionPosition
SPositionFromLineX(Sci::Line lineDoc
, int x
);
320 Sci::Position
PositionFromLineX(Sci::Line lineDoc
, int x
);
321 Sci::Line
LineFromLocation(Point pt
) const;
322 void SetTopLine(Sci::Line topLineNew
);
324 virtual bool AbandonPaint();
325 virtual void RedrawRect(PRectangle rc
);
326 virtual void DiscardOverdraw();
327 virtual void Redraw();
328 void RedrawSelMargin(Sci::Line line
=-1, bool allAfter
=false);
329 PRectangle
RectangleFromRange(Range r
, int overlap
);
330 void InvalidateRange(Sci::Position start
, Sci::Position end
);
332 bool UserVirtualSpace() const noexcept
{
333 return (FlagSet(virtualSpaceOptions
, Scintilla::VirtualSpace::UserAccessible
));
335 Sci::Position
CurrentPosition() const;
336 bool SelectionEmpty() const noexcept
;
337 SelectionPosition
SelectionStart();
338 SelectionPosition
SelectionEnd();
339 void SetRectangularRange();
340 void ThinRectangularRange();
341 void InvalidateSelection(SelectionRange newMain
, bool invalidateWholeSelection
=false);
342 void InvalidateWholeSelection();
343 SelectionRange
LineSelectionRange(SelectionPosition currentPos_
, SelectionPosition anchor_
) const;
344 void SetSelection(SelectionPosition currentPos_
, SelectionPosition anchor_
);
345 void SetSelection(Sci::Position currentPos_
, Sci::Position anchor_
);
346 void SetSelection(SelectionPosition currentPos_
);
347 void SetEmptySelection(SelectionPosition currentPos_
);
348 void SetEmptySelection(Sci::Position currentPos_
);
349 enum class AddNumber
{ one
, each
};
350 void MultipleSelectAdd(AddNumber addNumber
);
351 bool RangeContainsProtected(Sci::Position start
, Sci::Position end
) const noexcept
;
352 bool SelectionContainsProtected() const;
353 Sci::Position
MovePositionOutsideChar(Sci::Position pos
, Sci::Position moveDir
, bool checkLineEnd
=true) const;
354 SelectionPosition
MovePositionOutsideChar(SelectionPosition pos
, Sci::Position moveDir
, bool checkLineEnd
=true) const;
355 void MovedCaret(SelectionPosition newPos
, SelectionPosition previousPos
,
356 bool ensureVisible
, CaretPolicies policies
);
357 void MovePositionTo(SelectionPosition newPos
, Selection::SelTypes selt
=Selection::SelTypes::none
, bool ensureVisible
=true);
358 void MovePositionTo(Sci::Position newPos
, Selection::SelTypes selt
=Selection::SelTypes::none
, bool ensureVisible
=true);
359 SelectionPosition
MovePositionSoVisible(SelectionPosition pos
, int moveDir
);
360 SelectionPosition
MovePositionSoVisible(Sci::Position pos
, int moveDir
);
361 Point
PointMainCaret();
362 void SetLastXChosen();
364 void ScrollTo(Sci::Line line
, bool moveThumb
=true);
365 virtual void ScrollText(Sci::Line linesToMove
);
366 void HorizontalScrollTo(int xPos
);
367 void VerticalCentreCaret();
368 void MoveSelectedLines(int lineDelta
);
369 void MoveSelectedLinesUp();
370 void MoveSelectedLinesDown();
371 void MoveCaretInsideView(bool ensureVisible
=true);
372 Sci::Line
DisplayFromPosition(Sci::Position pos
);
374 struct XYScrollPosition
{
377 XYScrollPosition(int xOffset_
, Sci::Line topLine_
) noexcept
: xOffset(xOffset_
), topLine(topLine_
) {}
378 bool operator==(const XYScrollPosition
&other
) const noexcept
{
379 return (xOffset
== other
.xOffset
) && (topLine
== other
.topLine
);
382 XYScrollPosition
XYScrollToMakeVisible(const SelectionRange
&range
,
383 const XYScrollOptions options
, CaretPolicies policies
);
384 void SetXYScroll(XYScrollPosition newXY
);
385 void EnsureCaretVisible(bool useMargin
=true, bool vert
=true, bool horiz
=true);
386 void ScrollRange(SelectionRange range
);
387 void ShowCaretAtCurrentPosition();
389 void CaretSetPeriod(int period
);
390 void InvalidateCaret();
391 virtual void NotifyCaretMove();
392 virtual void UpdateSystemCaret();
394 bool Wrapping() const noexcept
;
395 void NeedWrapping(Sci::Line docLineStart
=0, Sci::Line docLineEnd
=WrapPending::lineLarge
);
396 bool WrapOneLine(Surface
*surface
, Sci::Line lineToWrap
);
397 enum class WrapScope
{wsAll
, wsVisible
, wsIdle
};
398 bool WrapLines(WrapScope ws
);
400 void LinesSplit(int pixelWidth
);
402 void PaintSelMargin(Surface
*surfaceWindow
, const PRectangle
&rc
);
403 void RefreshPixMaps(Surface
*surfaceWindow
);
404 void Paint(Surface
*surfaceWindow
, PRectangle rcArea
);
405 Sci::Position
FormatRange(bool draw
, const Scintilla::RangeToFormat
*pfr
);
406 long TextWidth(Scintilla::uptr_t style
, const char *text
);
408 virtual void SetVerticalScrollPos() = 0;
409 virtual void SetHorizontalScrollPos() = 0;
410 virtual bool ModifyScrollBars(Sci::Line nMax
, Sci::Line nPage
) = 0;
411 virtual void ReconfigureScrollBars();
412 void SetScrollBars();
415 void FilterSelections();
416 Sci::Position
RealizeVirtualSpace(Sci::Position position
, Sci::Position virtualSpace
);
417 SelectionPosition
RealizeVirtualSpace(const SelectionPosition
&position
);
418 void AddChar(char ch
);
419 virtual void InsertCharacter(std::string_view sv
, Scintilla::CharacterSource charSource
);
420 void ClearBeforeTentativeStart();
421 void InsertPaste(const char *text
, Sci::Position len
);
422 enum class PasteShape
{ stream
=0, rectangular
= 1, line
= 2 };
423 void InsertPasteShape(const char *text
, Sci::Position len
, PasteShape shape
);
424 void ClearSelection(bool retainMultipleSelections
= false);
426 void ClearDocumentStyle();
428 void PasteRectangular(SelectionPosition pos
, const char *ptr
, Sci::Position len
);
429 virtual void Copy() = 0;
430 void CopyAllowLine();
431 virtual bool CanPaste();
432 virtual void Paste() = 0;
434 virtual void SelectAll();
437 void DelCharBack(bool allowLineStartDeletion
);
438 virtual void ClaimSelection() = 0;
440 static Scintilla::KeyMod
ModifierFlags(bool shift
, bool ctrl
, bool alt
, bool meta
=false, bool super
=false) noexcept
;
441 virtual void NotifyChange() = 0;
442 virtual void NotifyFocus(bool focus
);
443 virtual void SetCtrlID(int identifier
);
444 virtual int GetCtrlID() { return ctrlID
; }
445 virtual void NotifyParent(Scintilla::NotificationData scn
) = 0;
446 virtual void NotifyStyleToNeeded(Sci::Position endStyleNeeded
);
447 void NotifyChar(int ch
, Scintilla::CharacterSource charSource
);
448 void NotifySavePoint(bool isSavePoint
);
449 void NotifyModifyAttempt();
450 virtual void NotifyDoubleClick(Point pt
, Scintilla::KeyMod modifiers
);
451 void NotifyHotSpotClicked(Sci::Position position
, Scintilla::KeyMod modifiers
);
452 void NotifyHotSpotDoubleClicked(Sci::Position position
, Scintilla::KeyMod modifiers
);
453 void NotifyHotSpotReleaseClick(Sci::Position position
, Scintilla::KeyMod modifiers
);
454 bool NotifyUpdateUI();
455 void NotifyPainted();
456 void NotifyIndicatorClick(bool click
, Sci::Position position
, Scintilla::KeyMod modifiers
);
457 bool NotifyMarginClick(Point pt
, Scintilla::KeyMod modifiers
);
458 bool NotifyMarginRightClick(Point pt
, Scintilla::KeyMod modifiers
);
459 void NotifyNeedShown(Sci::Position pos
, Sci::Position len
);
460 void NotifyDwelling(Point pt
, bool state
);
463 void NotifyModifyAttempt(Document
*document
, void *userData
) override
;
464 void NotifySavePoint(Document
*document
, void *userData
, bool atSavePoint
) override
;
465 void CheckModificationForWrap(DocModification mh
);
466 void NotifyModified(Document
*document
, DocModification mh
, void *userData
) override
;
467 void NotifyDeleted(Document
*document
, void *userData
) noexcept override
;
468 void NotifyStyleNeeded(Document
*doc
, void *userData
, Sci::Position endStyleNeeded
) override
;
469 void NotifyLexerChanged(Document
*doc
, void *userData
) override
;
470 void NotifyErrorOccurred(Document
*doc
, void *userData
, Scintilla::Status status
) override
;
471 void NotifyMacroRecord(Scintilla::Message iMessage
, Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
);
473 void ContainerNeedsUpdate(Scintilla::Update flags
) noexcept
;
474 void PageMove(int direction
, Selection::SelTypes selt
=Selection::SelTypes::none
, bool stuttered
= false);
475 enum class CaseMapping
{ same
, upper
, lower
};
476 virtual std::string
CaseMapString(const std::string
&s
, CaseMapping caseMapping
);
477 void ChangeCaseOfSelection(CaseMapping caseMapping
);
478 void LineTranspose();
480 void Duplicate(bool forLine
);
481 virtual void CancelModes();
483 SelectionPosition
PositionUpOrDown(SelectionPosition spStart
, int direction
, int lastX
);
484 void CursorUpOrDown(int direction
, Selection::SelTypes selt
);
485 void ParaUpOrDown(int direction
, Selection::SelTypes selt
);
486 Range
RangeDisplayLine(Sci::Line lineVisible
);
487 Sci::Position
StartEndDisplayLine(Sci::Position pos
, bool start
);
488 Sci::Position
VCHomeDisplayPosition(Sci::Position position
);
489 Sci::Position
VCHomeWrapPosition(Sci::Position position
);
490 Sci::Position
LineEndWrapPosition(Sci::Position position
);
491 int HorizontalMove(Scintilla::Message iMessage
);
492 int DelWordOrLine(Scintilla::Message iMessage
);
493 virtual int KeyCommand(Scintilla::Message iMessage
);
494 virtual int KeyDefault(Scintilla::Keys
/* key */, Scintilla::KeyMod
/*modifiers*/);
495 int KeyDownWithModifiers(Scintilla::Keys key
, Scintilla::KeyMod modifiers
, bool *consumed
);
497 void Indent(bool forwards
);
499 virtual std::unique_ptr
<CaseFolder
> CaseFolderForEncoding();
500 Sci::Position
FindText(Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
);
502 Sci::Position
SearchText(Scintilla::Message iMessage
, Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
);
503 Sci::Position
SearchInTarget(const char *text
, Sci::Position length
);
504 void GoToLine(Sci::Line lineNo
);
506 virtual void CopyToClipboard(const SelectionText
&selectedText
) = 0;
507 std::string
RangeText(Sci::Position start
, Sci::Position end
) const;
508 void CopySelectionRange(SelectionText
*ss
, bool allowLineCopy
=false);
509 void CopyRangeToClipboard(Sci::Position start
, Sci::Position end
);
510 void CopyText(size_t length
, const char *text
);
511 void SetDragPosition(SelectionPosition newPos
);
512 virtual void DisplayCursor(Window::Cursor c
);
513 virtual bool DragThreshold(Point ptStart
, Point ptNow
);
514 virtual void StartDrag();
515 void DropAt(SelectionPosition position
, const char *value
, size_t lengthValue
, bool moving
, bool rectangular
);
516 void DropAt(SelectionPosition position
, const char *value
, bool moving
, bool rectangular
);
517 /** PositionInSelection returns true if position in selection. */
518 bool PositionInSelection(Sci::Position pos
);
519 bool PointInSelection(Point pt
);
520 bool PointInSelMargin(Point pt
) const;
521 Window::Cursor
GetMarginCursor(Point pt
) const noexcept
;
522 void TrimAndSetSelection(Sci::Position currentPos_
, Sci::Position anchor_
);
523 void LineSelection(Sci::Position lineCurrentPos_
, Sci::Position lineAnchorPos_
, bool wholeLine
);
524 void WordSelection(Sci::Position pos
);
525 void DwellEnd(bool mouseMoved
);
527 virtual void ButtonDownWithModifiers(Point pt
, unsigned int curTime
, Scintilla::KeyMod modifiers
);
528 virtual void RightButtonDownWithModifiers(Point pt
, unsigned int curTime
, Scintilla::KeyMod modifiers
);
529 void ButtonMoveWithModifiers(Point pt
, unsigned int curTime
, Scintilla::KeyMod modifiers
);
530 void ButtonUpWithModifiers(Point pt
, unsigned int curTime
, Scintilla::KeyMod modifiers
);
533 enum class TickReason
{ caret
, scroll
, widen
, dwell
, platform
};
534 virtual void TickFor(TickReason reason
);
535 virtual bool FineTickerRunning(TickReason reason
);
536 virtual void FineTickerStart(TickReason reason
, int millis
, int tolerance
);
537 virtual void FineTickerCancel(TickReason reason
);
538 virtual bool SetIdle(bool) { return false; }
539 virtual void SetMouseCapture(bool on
) = 0;
540 virtual bool HaveMouseCapture() = 0;
541 void SetFocusState(bool focusState
);
542 virtual void UpdateBaseElements();
544 Sci::Position
PositionAfterArea(PRectangle rcArea
) const;
545 void StyleToPositionInView(Sci::Position pos
);
546 Sci::Position
PositionAfterMaxStyling(Sci::Position posMax
, bool scrolling
) const;
547 void StartIdleStyling(bool truncatedLastStyling
);
548 void StyleAreaBounded(PRectangle rcArea
, bool scrolling
);
549 constexpr bool SynchronousStylingToVisible() const noexcept
{
550 return (idleStyling
== Scintilla::IdleStyling::None
) || (idleStyling
== Scintilla::IdleStyling::AfterVisible
);
553 virtual void IdleWork();
554 virtual void QueueIdleWork(WorkItems items
, Sci::Position upTo
=0);
556 virtual int SupportsFeature(Scintilla::Supports feature
);
557 virtual bool PaintContains(PRectangle rc
);
558 bool PaintContainsMargin();
559 void CheckForChangeOutsidePaint(Range r
);
560 void SetBraceHighlight(Sci::Position pos0
, Sci::Position pos1
, int matchStyle
);
562 void SetAnnotationHeights(Sci::Line start
, Sci::Line end
);
563 virtual void SetDocPointer(Document
*document
);
565 void SetAnnotationVisible(Scintilla::AnnotationVisible visible
);
566 void SetEOLAnnotationVisible(Scintilla::EOLAnnotationVisible visible
);
568 Sci::Line
ExpandLine(Sci::Line line
);
569 void SetFoldExpanded(Sci::Line lineDoc
, bool expanded
);
570 void FoldLine(Sci::Line line
, Scintilla::FoldAction action
);
571 void FoldExpand(Sci::Line line
, Scintilla::FoldAction action
, Scintilla::FoldLevel level
);
572 Sci::Line
ContractedFoldNext(Sci::Line lineStart
) const;
573 void EnsureLineVisible(Sci::Line lineDoc
, bool enforcePolicy
);
574 void FoldChanged(Sci::Line line
, Scintilla::FoldLevel levelNow
, Scintilla::FoldLevel levelPrev
);
575 void NeedShown(Sci::Position pos
, Sci::Position len
);
576 void FoldAll(Scintilla::FoldAction action
);
578 Sci::Position
GetTag(char *tagValue
, int tagNumber
);
579 Sci::Position
ReplaceTarget(bool replacePatterns
, const char *text
, Sci::Position length
=-1);
581 bool PositionIsHotspot(Sci::Position position
) const;
582 bool PointIsHotspot(Point pt
);
583 void SetHotSpotRange(const Point
*pt
);
584 Range
GetHotSpotRange() const noexcept override
;
585 void SetHoverIndicatorPosition(Sci::Position position
);
586 void SetHoverIndicatorPoint(Point pt
);
588 int CodePage() const noexcept
;
589 virtual bool ValidCodePage(int /* codePage */) const { return true; }
590 virtual std::string
UTF8FromEncoded(std::string_view encoded
) const = 0;
591 virtual std::string
EncodedFromUTF8(std::string_view utf8
) const = 0;
593 Sci::Line
WrapCount(Sci::Line line
);
594 void AddStyledText(const char *buffer
, Sci::Position appendLength
);
596 virtual Scintilla::sptr_t
DefWndProc(Scintilla::Message iMessage
, Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
) = 0;
597 bool ValidMargin(Scintilla::uptr_t wParam
) const noexcept
;
598 void StyleSetMessage(Scintilla::Message iMessage
, Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
);
599 Scintilla::sptr_t
StyleGetMessage(Scintilla::Message iMessage
, Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
);
600 void SetSelectionNMessage(Scintilla::Message iMessage
, Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
);
602 static const char *StringFromEOLMode(Scintilla::EndOfLine eolMode
) noexcept
;
604 // Coercion functions for transforming WndProc parameters into pointers
605 static void *PtrFromSPtr(Scintilla::sptr_t lParam
) noexcept
{
606 return reinterpret_cast<void *>(lParam
);
608 static const char *ConstCharPtrFromSPtr(Scintilla::sptr_t lParam
) noexcept
{
609 return static_cast<const char *>(PtrFromSPtr(lParam
));
611 static const unsigned char *ConstUCharPtrFromSPtr(Scintilla::sptr_t lParam
) noexcept
{
612 return static_cast<const unsigned char *>(PtrFromSPtr(lParam
));
614 static char *CharPtrFromSPtr(Scintilla::sptr_t lParam
) noexcept
{
615 return static_cast<char *>(PtrFromSPtr(lParam
));
617 static unsigned char *UCharPtrFromSPtr(Scintilla::sptr_t lParam
) noexcept
{
618 return static_cast<unsigned char *>(PtrFromSPtr(lParam
));
620 static void *PtrFromUPtr(Scintilla::uptr_t wParam
) noexcept
{
621 return reinterpret_cast<void *>(wParam
);
623 static const char *ConstCharPtrFromUPtr(Scintilla::uptr_t wParam
) noexcept
{
624 return static_cast<const char *>(PtrFromUPtr(wParam
));
627 static constexpr Scintilla::sptr_t
SPtrFromUPtr(Scintilla::uptr_t wParam
) noexcept
{
628 return static_cast<Scintilla::sptr_t
>(wParam
);
630 static constexpr Sci::Position
PositionFromUPtr(Scintilla::uptr_t wParam
) noexcept
{
631 return SPtrFromUPtr(wParam
);
633 static constexpr Sci::Line
LineFromUPtr(Scintilla::uptr_t wParam
) noexcept
{
634 return SPtrFromUPtr(wParam
);
636 Point
PointFromParameters(Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
) const noexcept
{
637 return Point(static_cast<XYPOSITION
>(wParam
) - vs
.ExternalMarginWidth(), static_cast<XYPOSITION
>(lParam
));
640 constexpr std::optional
<FoldLevel
> OptionalFoldLevel(Scintilla::sptr_t lParam
) {
642 return static_cast<FoldLevel
>(lParam
);
647 static Scintilla::sptr_t
StringResult(Scintilla::sptr_t lParam
, const char *val
) noexcept
;
648 static Scintilla::sptr_t
BytesResult(Scintilla::sptr_t lParam
, const unsigned char *val
, size_t len
) noexcept
;
650 // Set a variable controlling appearance to a value and invalidates the display
651 // if a change was made. Avoids extra text and the possibility of mistyping.
652 template <typename T
>
653 bool SetAppearance(T
&variable
, T value
) {
654 // Using ! and == as more types have == defined than !=.
655 const bool changed
= !(variable
== value
);
658 InvalidateStyleRedraw();
666 // Public so the COM thunks can access it.
667 bool IsUnicodeMode() const noexcept
;
668 // Public so scintilla_send_message can use it.
669 virtual Scintilla::sptr_t
WndProc(Scintilla::Message iMessage
, Scintilla::uptr_t wParam
, Scintilla::sptr_t lParam
);
670 // Public so scintilla_set_id can use it.
672 // Public so COM methods for drag and drop can set it.
673 Scintilla::Status errorStatus
;
674 friend class AutoSurface
;
678 * A smart pointer class to ensure Surfaces are set up and deleted correctly.
682 std::unique_ptr
<Surface
> surf
;
684 AutoSurface(const Editor
*ed
) {
685 if (ed
->wMain
.GetID()) {
686 surf
= Surface::Allocate(ed
->technology
);
687 surf
->Init(ed
->wMain
.GetID());
688 surf
->SetMode(SurfaceMode(ed
->CodePage(), ed
->BidirectionalR2L()));
691 AutoSurface(SurfaceID sid
, Editor
*ed
, std::optional
<Scintilla::Technology
> technology
= {}) {
692 if (ed
->wMain
.GetID()) {
693 surf
= Surface::Allocate(technology
? *technology
: ed
->technology
);
694 surf
->Init(sid
, ed
->wMain
.GetID());
695 surf
->SetMode(SurfaceMode(ed
->CodePage(), ed
->BidirectionalR2L()));
698 // Deleted so AutoSurface objects can not be copied.
699 AutoSurface(const AutoSurface
&) = delete;
700 AutoSurface(AutoSurface
&&) = delete;
701 void operator=(const AutoSurface
&) = delete;
702 void operator=(AutoSurface
&&) = delete;
705 Surface
*operator->() const noexcept
{
708 operator Surface
*() const noexcept
{