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 /** 46 * EditView draws the main text area. 47 */ 48 class EditView { 49 public: 50 PrintParameters printParameters; 51 PerLine *ldTabstops; 52 53 bool hideSelection; 54 bool drawOverstrikeCaret; 55 56 /** In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to 57 * the screen. This avoids flashing but is about 30% slower. */ 58 bool bufferedDraw; 59 /** In phasesTwo mode, drawing is performed in two phases, first the background 60 * and then the foreground. This avoids chopping off characters that overlap the next run. 61 * In multiPhaseDraw mode, drawing is performed in multiple phases with each phase drawing 62 * one feature over the whole drawing area, instead of within one line. This allows text to 63 * overlap from one line to the next. */ 64 enum PhasesDraw { phasesOne, phasesTwo, phasesMultiple }; 65 PhasesDraw phasesDraw; 66 67 int lineWidthMaxSeen; 68 69 bool additionalCaretsBlink; 70 bool additionalCaretsVisible; 71 72 bool imeCaretBlockOverride; 73 74 Surface *pixmapLine; 75 Surface *pixmapIndentGuide; 76 Surface *pixmapIndentGuideHighlight; 77 78 LineLayoutCache llc; 79 PositionCache posCache; 80 81 EditView(); 82 virtual ~EditView(); 83 84 bool SetTwoPhaseDraw(bool twoPhaseDraw); 85 bool SetPhasesDraw(int phases); 86 bool LinesOverlap() const; 87 88 void ClearAllTabstops(); 89 int NextTabstopPos(int line, int x, int tabWidth) const; 90 bool ClearTabstops(int line); 91 bool AddTabstop(int line, int x); 92 int GetNextTabstop(int line, int x) const; 93 void LinesAddedOrRemoved(int lineOfPos, int linesAdded); 94 95 void DropGraphics(bool freeObjects); 96 void AllocateGraphics(const ViewStyle &vsDraw); 97 void RefreshPixMaps(Surface *surfaceWindow, WindowID wid, const ViewStyle &vsDraw); 98 99 LineLayout *RetrieveLineLayout(int lineNumber, const EditModel &model); 100 void LayoutLine(const EditModel &model, int line, Surface *surface, const ViewStyle &vstyle, 101 LineLayout *ll, int width = LineLayout::wrapWidthInfinite); 102 103 Point LocationFromPosition(Surface *surface, const EditModel &model, SelectionPosition pos, int topLine, const ViewStyle &vs); 104 SelectionPosition SPositionFromLocation(Surface *surface, const EditModel &model, Point pt, bool canReturnInvalid, 105 bool charPosition, bool virtualSpace, const ViewStyle &vs); 106 SelectionPosition SPositionFromLineX(Surface *surface, const EditModel &model, int lineDoc, int x, const ViewStyle &vs); 107 int DisplayFromPosition(Surface *surface, const EditModel &model, int pos, const ViewStyle &vs); 108 int StartEndDisplayLine(Surface *surface, const EditModel &model, int pos, bool start, const ViewStyle &vs); 109 110 void DrawIndentGuide(Surface *surface, int lineVisible, int lineHeight, int start, PRectangle rcSegment, bool highlight); 111 void DrawEOL(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, PRectangle rcLine, 112 int line, int lineEnd, int xStart, int subLine, XYACCUMULATOR subLineStart, 113 ColourOptional background); 114 void DrawAnnotation(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, 115 int line, int xStart, PRectangle rcLine, int subLine, DrawPhase phase); 116 void DrawCarets(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, int line, 117 int xStart, PRectangle rcLine, int subLine) const; 118 void DrawBackground(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, PRectangle rcLine, 119 Range lineRange, int posLineStart, int xStart, 120 int subLine, ColourOptional background) const; 121 void DrawForeground(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, int lineVisible, 122 PRectangle rcLine, Range lineRange, int posLineStart, int xStart, 123 int subLine, ColourOptional background); 124 void DrawIndentGuidesOverEmpty(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, 125 int line, int lineVisible, PRectangle rcLine, int xStart, int subLine); 126 void DrawLine(Surface *surface, const EditModel &model, const ViewStyle &vsDraw, const LineLayout *ll, int line, 127 int lineVisible, int xStart, PRectangle rcLine, int subLine, DrawPhase phase); 128 void PaintText(Surface *surfaceWindow, const EditModel &model, PRectangle rcArea, PRectangle rcClient, 129 const ViewStyle &vsDraw); 130 long FormatRange(bool draw, Sci_RangeToFormat *pfr, Surface *surface, Surface *surfaceMeasure, 131 const EditModel &model, const ViewStyle &vs); 132 }; 133 134 /** 135 * Convenience class to ensure LineLayout objects are always disposed. 136 */ 137 class AutoLineLayout { 138 LineLayoutCache &llc; 139 LineLayout *ll; 140 AutoLineLayout &operator=(const AutoLineLayout &); 141 public: AutoLineLayout(LineLayoutCache & llc_,LineLayout * ll_)142 AutoLineLayout(LineLayoutCache &llc_, LineLayout *ll_) : llc(llc_), ll(ll_) {} ~AutoLineLayout()143 ~AutoLineLayout() { 144 llc.Dispose(ll); 145 ll = 0; 146 } 147 LineLayout *operator->() const { 148 return ll; 149 } 150 operator LineLayout *() const { 151 return ll; 152 } Set(LineLayout * ll_)153 void Set(LineLayout *ll_) { 154 llc.Dispose(ll); 155 ll = ll_; 156 } 157 }; 158 159 #ifdef SCI_NAMESPACE 160 } 161 #endif 162 163 #endif 164