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 #ifdef SCI_NAMESPACE 12 namespace Scintilla { 13 #endif 14 15 struct PrintParameters { 16 int magnification; 17 int colourMode; 18 WrapMode wrapState; 19 PrintParameters(); 20 }; 21 22 /** 23 * The view may be drawn in separate phases. 24 */ 25 enum DrawPhase { 26 drawBack = 0x1, 27 drawIndicatorsBack = 0x2, 28 drawText = 0x4, 29 drawIndentationGuides = 0x8, 30 drawIndicatorsFore = 0x10, 31 drawSelectionTranslucent = 0x20, 32 drawLineTranslucent = 0x40, 33 drawFoldLines = 0x80, 34 drawCarets = 0x100, 35 drawAll = 0x1FF 36 }; 37 38 bool ValidStyledText(const ViewStyle &vs, size_t styleOffset, const StyledText &st); 39 int WidestLineWidth(Surface *surface, const ViewStyle &vs, int styleOffset, const StyledText &st); 40 void DrawTextNoClipPhase(Surface *surface, PRectangle rc, const Style &style, XYPOSITION ybase, 41 const char *s, int len, DrawPhase phase); 42 void DrawStyledText(Surface *surface, const ViewStyle &vs, int styleOffset, PRectangle rcText, 43 const StyledText &st, size_t start, size_t length, DrawPhase phase); 44 45 typedef void (*DrawTabArrowFn)(Surface *surface, PRectangle rcTab, int ymid); 46 47 /** 48 * EditView draws the main text area. 49 */ 50 class EditView { 51 public: 52 PrintParameters printParameters; 53 PerLine *ldTabstops; 54 int tabWidthMinimumPixels; 55 56 bool hideSelection; 57 bool drawOverstrikeCaret; 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 Surface *pixmapLine; 78 Surface *pixmapIndentGuide; 79 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 virtual ~EditView(); 94 95 bool SetTwoPhaseDraw(bool twoPhaseDraw); 96 bool SetPhasesDraw(int phases); 97 bool LinesOverlap() const; 98 99 void ClearAllTabstops(); 100 XYPOSITION NextTabstopPos(int line, XYPOSITION x, XYPOSITION tabWidth) const; 101 bool ClearTabstops(int line); 102 bool AddTabstop(int line, int x); 103 int GetNextTabstop(int line, int x) const; 104 void LinesAddedOrRemoved(int lineOfPos, int linesAdded); 105 106 void DropGraphics(bool freeObjects); 107 void AllocateGraphics(const ViewStyle &vsDraw); 108 void RefreshPixMaps(Surface *surfaceWindow, WindowID wid, const ViewStyle &vsDraw); 109 110 LineLayout *RetrieveLineLayout(int lineNumber, const EditModel &model); 111 void LayoutLine(const EditModel &model, int line, Surface *surface, const ViewStyle &vstyle, 112 LineLayout *ll, int width = LineLayout::wrapWidthInfinite); 113 114 Point LocationFromPosition(Surface *surface, const EditModel &model, SelectionPosition pos, int topLine, 115 const ViewStyle &vs, PointEnd pe); 116 Range RangeDisplayLine(Surface *surface, const EditModel &model, int lineVisible, const ViewStyle &vs); 117 SelectionPosition SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid, 118 bool charPosition, bool virtualSpace, const ViewStyle &vs); 119 SelectionPosition SPositionFromLineX(Surface *surface, const EditModel &model, int lineDoc, int x, const ViewStyle &vs); 120 int DisplayFromPosition(Surface *surface, const EditModel &model, int pos, const ViewStyle &vs); 121 int StartEndDisplayLine(Surface *surface, const EditModel &model, int pos, bool start, const ViewStyle &vs); 122 123 void DrawIndentGuide(Surface *surface, int lineVisible, int lineHeight, int start, PRectangle rcSegment, bool highlight); 124 void DrawEOL(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, PRectangle rcLine, 125 int line, int lineEnd, int xStart, int subLine, XYACCUMULATOR subLineStart, 126 ColourOptional background); 127 void DrawFoldDisplayText(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, 128 int line, int xStart, PRectangle rcLine, int subLine, XYACCUMULATOR subLineStart, DrawPhase phase); 129 void DrawAnnotation(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, 130 int line, int xStart, PRectangle rcLine, int subLine, DrawPhase phase); 131 void DrawCarets(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, int line, 132 int xStart, PRectangle rcLine, int subLine) const; 133 void DrawBackground(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, PRectangle rcLine, 134 Range lineRange, int posLineStart, int xStart, 135 int subLine, ColourOptional background) const; 136 void DrawForeground(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, int lineVisible, 137 PRectangle rcLine, Range lineRange, int posLineStart, int xStart, 138 int subLine, ColourOptional background); 139 void DrawIndentGuidesOverEmpty(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, 140 int line, int lineVisible, PRectangle rcLine, int xStart, int subLine); 141 void DrawLine(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, int line, 142 int lineVisible, int xStart, PRectangle rcLine, int subLine, DrawPhase phase); 143 void PaintText(Surface *surfaceWindow, const EditModel &model, PRectangle rcArea, PRectangle rcClient, 144 const ViewStyle &vsDraw); 145 void FillLineRemainder(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, 146 int line, PRectangle rcArea, int subLine); 147 long FormatRange(bool draw, Sci_RangeToFormat *pfr, Surface *surface, Surface *surfaceMeasure, 148 const EditModel &model, const ViewStyle &vs); 149 }; 150 151 /** 152 * Convenience class to ensure LineLayout objects are always disposed. 153 */ 154 class AutoLineLayout { 155 LineLayoutCache &llc; 156 LineLayout *ll; 157 AutoLineLayout &operator=(const AutoLineLayout &); 158 public: AutoLineLayout(LineLayoutCache & llc_,LineLayout * ll_)159 AutoLineLayout(LineLayoutCache &llc_, LineLayout *ll_) : llc(llc_), ll(ll_) {} ~AutoLineLayout()160 ~AutoLineLayout() { 161 llc.Dispose(ll); 162 ll = 0; 163 } 164 LineLayout *operator->() const { 165 return ll; 166 } 167 operator LineLayout *() const { 168 return ll; 169 } Set(LineLayout * ll_)170 void Set(LineLayout *ll_) { 171 llc.Dispose(ll); 172 ll = ll_; 173 } 174 }; 175 176 #ifdef SCI_NAMESPACE 177 } 178 #endif 179 180 #endif 181