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); 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 const char *s, int len, 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; 106 bool ClearTabstops(Sci::Line line); 107 bool AddTabstop(Sci::Line line, int x); 108 int GetNextTabstop(Sci::Line line, int x) const; 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 Point LocationFromPosition(Surface *surface, const EditModel &model, SelectionPosition pos, Sci::Line topLine, 120 const ViewStyle &vs, PointEnd pe); 121 Range RangeDisplayLine(Surface *surface, const EditModel &model, Sci::Line lineVisible, const ViewStyle &vs); 122 SelectionPosition SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid, 123 bool charPosition, bool virtualSpace, const ViewStyle &vs); 124 SelectionPosition SPositionFromLineX(Surface *surface, const EditModel &model, Sci::Line lineDoc, int x, const ViewStyle &vs); 125 Sci::Line DisplayFromPosition(Surface *surface, const EditModel &model, Sci::Position pos, const ViewStyle &vs); 126 Sci::Position StartEndDisplayLine(Surface *surface, const EditModel &model, Sci::Position pos, bool start, const ViewStyle &vs); 127 128 void DrawIndentGuide(Surface *surface, Sci::Line lineVisible, int lineHeight, XYPOSITION start, PRectangle rcSegment, bool highlight); 129 void DrawEOL(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, PRectangle rcLine, 130 Sci::Line line, Sci::Position lineEnd, int xStart, int subLine, XYACCUMULATOR subLineStart, 131 ColourOptional background); 132 void DrawFoldDisplayText(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, 133 Sci::Line line, int xStart, PRectangle rcLine, int subLine, XYACCUMULATOR subLineStart, DrawPhase phase); 134 void DrawAnnotation(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, 135 Sci::Line line, int xStart, PRectangle rcLine, int subLine, DrawPhase phase); 136 void DrawCarets(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, Sci::Line lineDoc, 137 int xStart, PRectangle rcLine, int subLine) const; 138 void DrawBackground(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, PRectangle rcLine, 139 Range lineRange, Sci::Position posLineStart, int xStart, 140 int subLine, ColourOptional background) const; 141 void DrawForeground(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, Sci::Line lineVisible, 142 PRectangle rcLine, Range lineRange, Sci::Position posLineStart, int xStart, 143 int subLine, ColourOptional background); 144 void DrawIndentGuidesOverEmpty(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, 145 Sci::Line line, Sci::Line lineVisible, PRectangle rcLine, int xStart, int subLine); 146 void DrawLine(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, Sci::Line line, 147 Sci::Line lineVisible, int xStart, PRectangle rcLine, int subLine, DrawPhase phase); 148 void PaintText(Surface *surfaceWindow, const EditModel &model, PRectangle rcArea, PRectangle rcClient, 149 const ViewStyle &vsDraw); 150 void FillLineRemainder(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, 151 Sci::Line line, PRectangle rcArea, int subLine) const; 152 Sci::Position FormatRange(bool draw, const Sci_RangeToFormat *pfr, Surface *surface, Surface *surfaceMeasure, 153 const EditModel &model, const ViewStyle &vs); 154 }; 155 156 /** 157 * Convenience class to ensure LineLayout objects are always disposed. 158 */ 159 class AutoLineLayout { 160 LineLayoutCache &llc; 161 LineLayout *ll; 162 public: AutoLineLayout(LineLayoutCache & llc_,LineLayout * ll_)163 AutoLineLayout(LineLayoutCache &llc_, LineLayout *ll_) noexcept : llc(llc_), ll(ll_) {} 164 AutoLineLayout(const AutoLineLayout &) = delete; 165 AutoLineLayout(AutoLineLayout &&) = delete; 166 AutoLineLayout &operator=(const AutoLineLayout &) = delete; 167 AutoLineLayout &operator=(AutoLineLayout &&) = delete; ~AutoLineLayout()168 ~AutoLineLayout() noexcept { 169 llc.Dispose(ll); 170 ll = nullptr; 171 } 172 LineLayout *operator->() const noexcept { 173 return ll; 174 } 175 operator LineLayout *() const noexcept { 176 return ll; 177 } Set(LineLayout * ll_)178 void Set(LineLayout *ll_) noexcept { 179 llc.Dispose(ll); 180 ll = ll_; 181 } 182 }; 183 184 } 185 186 #endif 187