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