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 // 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. */
199 Scintilla::Technology technology
;
201 float scaleRGBAImage
;
203 MarginView marginView
;
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
;
214 bool verticalScrollBarVisible
;
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
;
228 Timer autoScrollTimer
;
229 enum { autoScrollDelay
= 200 };
234 unsigned int lastClickTime
;
235 Point doubleClickCloseThreshold
;
239 enum class TextUnit
{ character
, word
, subLine
, wholeLine
} selectionUnit
;
241 enum class DragDrop
{ none
, initial
, dragging
} inDragDrop
;
242 bool dropWentOutside
;
243 SelectionPosition posDrop
;
244 Sci::Position hotSpotClickPos
;
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
;
254 Sci::Position posTopLine
;
255 Sci::Position lengthForEncode
;
257 Scintilla::Update needUpdateUI
;
259 enum class PaintState
{ notPainting
, painting
, abandoned
} paintState
;
260 bool paintAbandonedByStyling
;
262 bool paintingAllText
;
264 WorkNeeded workNeeded
;
265 Scintilla::IdleStyling idleStyling
;
266 bool needIdleStyling
;
268 Scintilla::ModificationFlags modEventMask
;
273 CaretPolicies caretPolicies
;
275 VisiblePolicySlop visiblePolicy
;
277 Sci::Position searchAnchor
;
281 Scintilla::AutomaticFold foldAutomatic
;
284 WrapPending wrapPending
;
285 ActionDuration durationWrapOneByte
;
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
{
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();
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
);
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();
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);
434 void ClearDocumentStyle();
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;
442 virtual void SelectAll();
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
);
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();
486 void Duplicate(bool forLine
);
487 virtual void CancelModes();
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
);
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
);
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
);
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
) {
664 return static_cast<FoldLevel
>(lParam
);
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
);
681 InvalidateStyleRedraw();
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.
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.
705 std::unique_ptr
<Surface
> surf
;
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;
720 Surface
*operator->() const noexcept
{
723 operator Surface
*() const noexcept
{