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 {
12 
13 struct PrintParameters {
14 	int magnification;
15 	int colourMode;
16 	WrapMode wrapState;
17 	PrintParameters() noexcept;
18 };
19 
20 /**
21 * The view may be drawn in separate phases.
22 */
23 enum DrawPhase {
24 	drawBack = 0x1,
25 	drawIndicatorsBack = 0x2,
26 	drawText = 0x4,
27 	drawIndentationGuides = 0x8,
28 	drawIndicatorsFore = 0x10,
29 	drawSelectionTranslucent = 0x20,
30 	drawLineTranslucent = 0x40,
31 	drawFoldLines = 0x80,
32 	drawCarets = 0x100,
33 	drawAll = 0x1FF
34 };
35 
36 bool ValidStyledText(const ViewStyle &vs, size_t styleOffset, const StyledText &st) noexcept;
37 int WidestLineWidth(Surface *surface, const ViewStyle &vs, int styleOffset, const StyledText &st);
38 void DrawTextNoClipPhase(Surface *surface, PRectangle rc, const Style &style, XYPOSITION ybase,
39 	std::string_view text, DrawPhase phase);
40 void DrawStyledText(Surface *surface, const ViewStyle &vs, int styleOffset, PRectangle rcText,
41 	const StyledText &st, size_t start, size_t length, DrawPhase phase);
42 
43 typedef void (*DrawTabArrowFn)(Surface *surface, PRectangle rcTab, int ymid);
44 
45 class LineTabstops;
46 
47 /**
48 * EditView draws the main text area.
49 */
50 class EditView {
51 public:
52 	PrintParameters printParameters;
53 	std::unique_ptr<LineTabstops> ldTabstops;
54 	int tabWidthMinimumPixels;
55 
56 	bool hideSelection;
57 	bool drawOverstrikeCaret; // used by the curses platform
58 
59 	/** In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to
60 	* the screen. This avoids flashing but is about 30% slower. */
61 	bool bufferedDraw;
62 	/** In phasesTwo mode, drawing is performed in two phases, first the background
63 	* and then the foreground. This avoids chopping off characters that overlap the next run.
64 	* In multiPhaseDraw mode, drawing is performed in multiple phases with each phase drawing
65 	* one feature over the whole drawing area, instead of within one line. This allows text to
66 	* overlap from one line to the next. */
67 	enum PhasesDraw { phasesOne, phasesTwo, phasesMultiple };
68 	PhasesDraw phasesDraw;
69 
70 	int lineWidthMaxSeen;
71 
72 	bool additionalCaretsBlink;
73 	bool additionalCaretsVisible;
74 
75 	bool imeCaretBlockOverride;
76 
77 	std::unique_ptr<Surface> pixmapLine;
78 	std::unique_ptr<Surface> pixmapIndentGuide;
79 	std::unique_ptr<Surface> pixmapIndentGuideHighlight;
80 
81 	LineLayoutCache llc;
82 	PositionCache posCache;
83 
84 	int tabArrowHeight; // draw arrow heads this many pixels above/below line midpoint
85 	/** Some platforms, notably PLAT_CURSES, do not support Scintilla's native
86 	 * DrawTabArrow function for drawing tab characters. Allow those platforms to
87 	 * override it instead of creating a new method in the Surface class that
88 	 * existing platforms must implement as empty. */
89 	DrawTabArrowFn customDrawTabArrow;
90 	DrawWrapMarkerFn customDrawWrapMarker;
91 
92 	EditView();
93 	// Deleted so EditView objects can not be copied.
94 	EditView(const EditView &) = delete;
95 	EditView(EditView &&) = delete;
96 	void operator=(const EditView &) = delete;
97 	void operator=(EditView &&) = delete;
98 	virtual ~EditView();
99 
100 	bool SetTwoPhaseDraw(bool twoPhaseDraw) noexcept;
101 	bool SetPhasesDraw(int phases) noexcept;
102 	bool LinesOverlap() const noexcept;
103 
104 	void ClearAllTabstops() noexcept;
105 	XYPOSITION NextTabstopPos(Sci::Line line, XYPOSITION x, XYPOSITION tabWidth) const noexcept;
106 	bool ClearTabstops(Sci::Line line) noexcept;
107 	bool AddTabstop(Sci::Line line, int x);
108 	int GetNextTabstop(Sci::Line line, int x) const noexcept;
109 	void LinesAddedOrRemoved(Sci::Line lineOfPos, Sci::Line linesAdded);
110 
111 	void DropGraphics(bool freeObjects);
112 	void AllocateGraphics(const ViewStyle &vsDraw);
113 	void RefreshPixMaps(Surface *surfaceWindow, WindowID wid, const ViewStyle &vsDraw);
114 
115 	LineLayout *RetrieveLineLayout(Sci::Line lineNumber, const EditModel &model);
116 	void LayoutLine(const EditModel &model, Sci::Line line, Surface *surface, const ViewStyle &vstyle,
117 		LineLayout *ll, int width = LineLayout::wrapWidthInfinite);
118 
119 	static void UpdateBidiData(const EditModel &model, const ViewStyle &vstyle, LineLayout *ll);
120 
121 	Point LocationFromPosition(Surface *surface, const EditModel &model, SelectionPosition pos, Sci::Line topLine,
122 		const ViewStyle &vs, PointEnd pe, const PRectangle rcClient);
123 	Range RangeDisplayLine(Surface *surface, const EditModel &model, Sci::Line lineVisible, const ViewStyle &vs);
124 	SelectionPosition SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid,
125 		bool charPosition, bool virtualSpace, const ViewStyle &vs, const PRectangle rcClient);
126 	SelectionPosition SPositionFromLineX(Surface *surface, const EditModel &model, Sci::Line lineDoc, int x, const ViewStyle &vs);
127 	Sci::Line DisplayFromPosition(Surface *surface, const EditModel &model, Sci::Position pos, const ViewStyle &vs);
128 	Sci::Position StartEndDisplayLine(Surface *surface, const EditModel &model, Sci::Position pos, bool start, const ViewStyle &vs);
129 
130 	void DrawIndentGuide(Surface *surface, Sci::Line lineVisible, int lineHeight, XYPOSITION start, PRectangle rcSegment, bool highlight);
131 	void DrawEOL(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, PRectangle rcLine,
132 		Sci::Line line, Sci::Position lineEnd, int xStart, int subLine, XYACCUMULATOR subLineStart,
133 		ColourOptional background);
134 	void DrawFoldDisplayText(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll,
135 		Sci::Line line, int xStart, PRectangle rcLine, int subLine, XYACCUMULATOR subLineStart, DrawPhase phase);
136 	void DrawEOLAnnotationText(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll,
137 		Sci::Line line, int xStart, PRectangle rcLine, int subLine, XYACCUMULATOR subLineStart, DrawPhase phase);
138 	void DrawAnnotation(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll,
139 		Sci::Line line, int xStart, PRectangle rcLine, int subLine, DrawPhase phase);
140 	void DrawCarets(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, Sci::Line lineDoc,
141 		int xStart, PRectangle rcLine, int subLine) const;
142 	void DrawBackground(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, PRectangle rcLine,
143 		Range lineRange, Sci::Position posLineStart, int xStart,
144 		int subLine, ColourOptional background) const;
145 	void DrawForeground(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, Sci::Line lineVisible,
146 		PRectangle rcLine, Range lineRange, Sci::Position posLineStart, int xStart,
147 		int subLine, ColourOptional background);
148 	void DrawIndentGuidesOverEmpty(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll,
149 		Sci::Line line, Sci::Line lineVisible, PRectangle rcLine, int xStart, int subLine);
150 	void DrawLine(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, Sci::Line line,
151 		Sci::Line lineVisible, int xStart, PRectangle rcLine, int subLine, DrawPhase phase);
152 	void PaintText(Surface *surfaceWindow, const EditModel &model, PRectangle rcArea, PRectangle rcClient,
153 		const ViewStyle &vsDraw);
154 	void FillLineRemainder(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll,
155 		Sci::Line line, PRectangle rcArea, int subLine) const;
156 	Sci::Position FormatRange(bool draw, const Sci_RangeToFormat *pfr, Surface *surface, Surface *surfaceMeasure,
157 		const EditModel &model, const ViewStyle &vs);
158 };
159 
160 /**
161 * Convenience class to ensure LineLayout objects are always disposed.
162 */
163 class AutoLineLayout {
164 	LineLayoutCache &llc;
165 	LineLayout *ll;
166 public:
AutoLineLayout(LineLayoutCache & llc_,LineLayout * ll_)167 	AutoLineLayout(LineLayoutCache &llc_, LineLayout *ll_) noexcept : llc(llc_), ll(ll_) {}
168 	AutoLineLayout(const AutoLineLayout &) = delete;
169 	AutoLineLayout(AutoLineLayout &&) = delete;
170 	AutoLineLayout &operator=(const AutoLineLayout &) = delete;
171 	AutoLineLayout &operator=(AutoLineLayout &&) = delete;
~AutoLineLayout()172 	~AutoLineLayout() noexcept {
173 		llc.Dispose(ll);
174 		ll = nullptr;
175 	}
176 	LineLayout *operator->() const noexcept {
177 		return ll;
178 	}
179 	operator LineLayout *() const noexcept {
180 		return ll;
181 	}
Set(LineLayout * ll_)182 	void Set(LineLayout *ll_) noexcept {
183 		llc.Dispose(ll);
184 		ll = ll_;
185 	}
186 };
187 
188 }
189 
190 #endif
191