1 | // Scintilla source code edit control |
2 | /** @file EditView.h |
3 | ** Defines the appearance of the main text area of the editor window. |
4 | **/ |
5 | // Copyright 1998-2014 by Neil Hodgson <neilh@scintilla.org> |
6 | // The License.txt file describes the conditions under which this software may be distributed. |
7 | |
8 | #ifndef EDITVIEW_H |
9 | #define EDITVIEW_H |
10 | |
11 | namespace Scintilla::Internal { |
12 | |
13 | struct PrintParameters { |
14 | int magnification; |
15 | Scintilla::PrintOption colourMode; |
16 | Scintilla::Wrap wrapState; |
17 | PrintParameters() noexcept; |
18 | }; |
19 | |
20 | /** |
21 | * The view may be drawn in separate phases. |
22 | */ |
23 | enum class DrawPhase { |
24 | none = 0x0, |
25 | back = 0x1, |
26 | indicatorsBack = 0x2, |
27 | text = 0x4, |
28 | indentationGuides = 0x8, |
29 | indicatorsFore = 0x10, |
30 | selectionTranslucent = 0x20, |
31 | lineTranslucent = 0x40, |
32 | foldLines = 0x80, |
33 | carets = 0x100, |
34 | all = 0x1FF |
35 | }; |
36 | |
37 | bool ValidStyledText(const ViewStyle &vs, size_t styleOffset, const StyledText &st) noexcept; |
38 | int WidestLineWidth(Surface *surface, const ViewStyle &vs, int styleOffset, const StyledText &st); |
39 | void DrawTextNoClipPhase(Surface *surface, PRectangle rc, const Style &style, XYPOSITION ybase, |
40 | std::string_view text, DrawPhase phase); |
41 | void DrawStyledText(Surface *surface, const ViewStyle &vs, int styleOffset, PRectangle rcText, |
42 | const StyledText &st, size_t start, size_t length, DrawPhase phase); |
43 | void Hexits(char *hexits, int ch) noexcept; |
44 | |
45 | typedef void (*DrawTabArrowFn)(Surface *surface, PRectangle rcTab, int ymid, |
46 | const ViewStyle &vsDraw, Stroke stroke); |
47 | |
48 | class LineTabstops; |
49 | |
50 | /** |
51 | * EditView draws the main text area. |
52 | */ |
53 | class EditView { |
54 | public: |
55 | PrintParameters printParameters; |
56 | std::unique_ptr<LineTabstops> ldTabstops; |
57 | int tabWidthMinimumPixels; |
58 | |
59 | bool hideSelection; |
60 | bool drawOverstrikeCaret; // used by the curses platform |
61 | |
62 | /** In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to |
63 | * the screen. This avoids flashing but is about 30% slower. */ |
64 | bool bufferedDraw; |
65 | /** In phasesTwo mode, drawing is performed in two phases, first the background |
66 | * and then the foreground. This avoids chopping off characters that overlap the next run. |
67 | * In multiPhaseDraw mode, drawing is performed in multiple phases with each phase drawing |
68 | * one feature over the whole drawing area, instead of within one line. This allows text to |
69 | * overlap from one line to the next. */ |
70 | Scintilla::PhasesDraw phasesDraw; |
71 | |
72 | int lineWidthMaxSeen; |
73 | |
74 | bool additionalCaretsBlink; |
75 | bool additionalCaretsVisible; |
76 | |
77 | bool imeCaretBlockOverride; |
78 | |
79 | std::unique_ptr<Surface> pixmapLine; |
80 | std::unique_ptr<Surface> pixmapIndentGuide; |
81 | std::unique_ptr<Surface> pixmapIndentGuideHighlight; |
82 | |
83 | LineLayoutCache llc; |
84 | PositionCache posCache; |
85 | |
86 | int tabArrowHeight; // draw arrow heads this many pixels above/below line midpoint |
87 | /** Some platforms, notably PLAT_CURSES, do not support Scintilla's native |
88 | * DrawTabArrow function for drawing tab characters. Allow those platforms to |
89 | * override it instead of creating a new method in the Surface class that |
90 | * existing platforms must implement as empty. */ |
91 | DrawTabArrowFn customDrawTabArrow; |
92 | DrawWrapMarkerFn customDrawWrapMarker; |
93 | |
94 | EditView(); |
95 | // Deleted so EditView objects can not be copied. |
96 | EditView(const EditView &) = delete; |
97 | EditView(EditView &&) = delete; |
98 | void operator=(const EditView &) = delete; |
99 | void operator=(EditView &&) = delete; |
100 | virtual ~EditView(); |
101 | |
102 | bool SetTwoPhaseDraw(bool twoPhaseDraw) noexcept; |
103 | bool SetPhasesDraw(int phases) noexcept; |
104 | bool LinesOverlap() const noexcept; |
105 | |
106 | void ClearAllTabstops() noexcept; |
107 | XYPOSITION NextTabstopPos(Sci::Line line, XYPOSITION x, XYPOSITION tabWidth) const noexcept; |
108 | bool ClearTabstops(Sci::Line line) noexcept; |
109 | bool AddTabstop(Sci::Line line, int x); |
110 | int GetNextTabstop(Sci::Line line, int x) const noexcept; |
111 | void LinesAddedOrRemoved(Sci::Line lineOfPos, Sci::Line linesAdded); |
112 | |
113 | void DropGraphics() noexcept; |
114 | void RefreshPixMaps(Surface *surfaceWindow, const ViewStyle &vsDraw); |
115 | |
116 | std::shared_ptr<LineLayout> RetrieveLineLayout(Sci::Line lineNumber, const EditModel &model); |
117 | void LayoutLine(const EditModel &model, Surface *surface, const ViewStyle &vstyle, |
118 | LineLayout *ll, int width = LineLayout::wrapWidthInfinite); |
119 | |
120 | static void UpdateBidiData(const EditModel &model, const ViewStyle &vstyle, LineLayout *ll); |
121 | |
122 | Point LocationFromPosition(Surface *surface, const EditModel &model, SelectionPosition pos, Sci::Line topLine, |
123 | const ViewStyle &vs, PointEnd pe, const PRectangle rcClient); |
124 | Range RangeDisplayLine(Surface *surface, const EditModel &model, Sci::Line lineVisible, const ViewStyle &vs); |
125 | SelectionPosition SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid, |
126 | bool charPosition, bool virtualSpace, const ViewStyle &vs, const PRectangle rcClient); |
127 | SelectionPosition SPositionFromLineX(Surface *surface, const EditModel &model, Sci::Line lineDoc, int x, const ViewStyle &vs); |
128 | Sci::Line DisplayFromPosition(Surface *surface, const EditModel &model, Sci::Position pos, const ViewStyle &vs); |
129 | Sci::Position StartEndDisplayLine(Surface *surface, const EditModel &model, Sci::Position pos, bool start, const ViewStyle &vs); |
130 | |
131 | void DrawIndentGuide(Surface *surface, Sci::Line lineVisible, int lineHeight, XYPOSITION start, PRectangle rcSegment, bool highlight); |
132 | void DrawEOL(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, PRectangle rcLine, |
133 | Sci::Line line, Sci::Position lineEnd, int xStart, int subLine, XYACCUMULATOR subLineStart, |
134 | std::optional<ColourRGBA> background); |
135 | void DrawFoldDisplayText(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, |
136 | Sci::Line line, int xStart, PRectangle rcLine, int subLine, XYACCUMULATOR subLineStart, DrawPhase phase); |
137 | void DrawEOLAnnotationText(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, |
138 | Sci::Line line, int xStart, PRectangle rcLine, int subLine, XYACCUMULATOR subLineStart, DrawPhase phase); |
139 | void DrawAnnotation(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, |
140 | Sci::Line line, int xStart, PRectangle rcLine, int subLine, DrawPhase phase); |
141 | void DrawCarets(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, Sci::Line lineDoc, |
142 | int xStart, PRectangle rcLine, int subLine) const; |
143 | void DrawBackground(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, PRectangle rcLine, |
144 | Range lineRange, Sci::Position posLineStart, int xStart, |
145 | int subLine, std::optional<ColourRGBA> background) const; |
146 | void DrawForeground(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, Sci::Line lineVisible, |
147 | PRectangle rcLine, Range lineRange, Sci::Position posLineStart, int xStart, |
148 | int subLine, std::optional<ColourRGBA> background); |
149 | void DrawIndentGuidesOverEmpty(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, |
150 | Sci::Line line, Sci::Line lineVisible, PRectangle rcLine, int xStart, int subLine); |
151 | void DrawLine(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, Sci::Line line, |
152 | Sci::Line lineVisible, int xStart, PRectangle rcLine, int subLine, DrawPhase phase); |
153 | void PaintText(Surface *surfaceWindow, const EditModel &model, PRectangle rcArea, PRectangle rcClient, |
154 | const ViewStyle &vsDraw); |
155 | void FillLineRemainder(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, |
156 | Sci::Line line, PRectangle rcArea, int subLine) const; |
157 | Sci::Position FormatRange(bool draw, const Scintilla::RangeToFormat *pfr, Surface *surface, Surface *surfaceMeasure, |
158 | const EditModel &model, const ViewStyle &vs); |
159 | }; |
160 | |
161 | } |
162 | |
163 | #endif |
164 | |