1 // Scintilla source code edit control
2 // Editor.h - defines the main editor class
3 // Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
4 // The License.txt file describes the conditions under which this software may be distributed.
23 enum {tickSize
= 100};
31 // Drawing is only performed for maxLineLength characters on each line.
32 enum {maxLineLength
= 4000};
34 char chars
[maxLineLength
];
35 char styles
[maxLineLength
];
36 char indicators
[maxLineLength
];
37 int positions
[maxLineLength
];
40 class Editor
: public DocWatcher
{
41 // Private so Editor objects can not be copied
42 Editor(const Editor
&) : DocWatcher() {}
43 Editor
&operator=(const Editor
&) { return *this; }
44 protected: // ScintillaBase subclass needs access to much of Editor
46 // On GTK+, Scintilla is a container widget holding two scroll bars and a drawing area
47 // whereas on Windows there is just one window with both scroll bars turned on.
48 // Therefore, on GTK+ the following are separate windows but only one window on Windows.
49 Window wMain
; // The Scintilla parent window
50 Window wDraw
; // The text drawing area
52 // Style resources may be expensive to allocate so are cached between uses.
53 // When a style attribute is changed, this cache is flushed.
61 // In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to
62 // the screen. This avoids flashing but is about 30% slower.
65 int xOffset
; // Horizontal scrolled amount in pixels
66 int xCaretMargin
; // Ensure this many pixels visible on both sides of caret
67 bool horizontalScrollBarVisible
;
70 Surface pixmapSelMargin
;
71 Surface pixmapSelPattern
;
72 // Intellimouse support - currently only implemented for Windows
73 unsigned int ucWheelScrollLines
;
74 int cWheelDelta
; //wheel delta from roll
82 unsigned int lastClickTime
;
83 enum { selChar
, selWord
, selLine
} selectionType
;
92 int originalAnchorPos
;
100 int bracesMatchStyle
;
105 enum { notPainting
, painting
, paintAbandoned
} paintState
;
107 bool paintingAllText
;
113 bool dragIsRectangle
;
114 enum { selStream
, selRectangle
, selRectangleFixed
} selType
;
123 int displayPopupMenu
;
136 virtual void Initialise() = 0;
137 virtual void Finalise();
139 void InvalidateStyleData();
140 void InvalidateStyleRedraw();
141 virtual void RefreshColourPalette(Palette
&pal
, bool want
);
142 void RefreshStyleData();
145 PRectangle
GetClientRectangle();
146 PRectangle
GetTextRectangle();
151 Point
LocationFromPosition(unsigned int pos
);
152 int XFromPosition(unsigned int pos
);
153 int PositionFromLocation(Point pt
);
154 int PositionFromLineX(int line
, int x
);
155 int LineFromLocation(Point pt
);
156 void SetTopLine(int topLineNew
);
158 void RedrawRect(PRectangle rc
);
160 void RedrawSelMargin();
161 PRectangle
RectangleFromRange(int start
, int end
);
162 void InvalidateRange(int start
, int end
);
164 int CurrentPosition();
165 bool SelectionEmpty();
166 int SelectionStart(int line
=-1);
167 int SelectionEnd(int line
=-1);
168 void SetSelection(int currentPos_
, int anchor_
);
169 void SetSelection(int currentPos_
);
170 void SetEmptySelection(int currentPos_
);
171 int MovePositionTo(int newPos
, bool extend
= false);
172 int MovePositionSoVisible(int pos
, int moveDir
);
173 void SetLastXChosen();
175 void ScrollTo(int line
);
176 virtual void ScrollText(int linesToMove
);
177 void HorizontalScrollTo(int xPos
);
178 void MoveCaretInsideView();
179 void EnsureCaretVisible(bool useMargin
=true);
180 void ShowCaretAtCurrentPosition();
182 void InvalidateCaret();
184 void PaintSelMargin(Surface
*surface
, PRectangle
&rc
);
185 void LayoutLine(int line
, Surface
*surface
, ViewStyle
&vstyle
, LineLayout
&ll
);
186 void DrawLine(Surface
*surface
, ViewStyle
&vsDraw
, int line
, int xStart
,
187 PRectangle rcLine
, LineLayout
&ll
);
188 void Paint(Surface
*surfaceWindow
, PRectangle rcArea
);
189 long FormatRange(bool draw
, FORMATRANGE
*pfr
);
191 virtual void SetVerticalScrollPos() = 0;
192 virtual void SetHorizontalScrollPos() = 0;
193 virtual bool ModifyScrollBars(int nMax
, int nPage
) = 0;
194 virtual void ReconfigureScrollBars();
195 void SetScrollBarsTo(PRectangle rsClient
);
196 void SetScrollBars();
198 void AddChar(char ch
);
199 virtual void AddCharUTF(char *s
, unsigned int len
);
200 void ClearSelection();
203 void PasteRectangular(int pos
, const char *ptr
, int len
);
204 virtual void Copy() = 0;
205 virtual void Paste() = 0;
212 virtual void ClaimSelection() = 0;
214 virtual void NotifyChange() = 0;
215 virtual void NotifyFocus(bool focus
);
216 virtual void NotifyParent(SCNotification scn
) = 0;
217 virtual void NotifyStyleToNeeded(int endStyleNeeded
);
218 void NotifyChar(char ch
);
219 void NotifySavePoint(bool isSavePoint
);
220 void NotifyModifyAttempt();
221 virtual void NotifyDoubleClick(Point pt
, bool shift
);
222 void NotifyUpdateUI();
223 bool NotifyMarginClick(Point pt
, bool shift
, bool ctrl
, bool alt
);
224 void NotifyNeedShown(int pos
, int len
);
226 void NotifyModifyAttempt(Document
*document
, void *userData
);
227 void NotifySavePoint(Document
*document
, void *userData
, bool atSavePoint
);
228 void NotifyModified(Document
*document
, DocModification mh
, void *userData
);
229 void NotifyDeleted(Document
*document
, void *userData
);
230 void NotifyStyleNeeded(Document
*doc
, void *userData
, int endPos
);
234 void NotifyMacroRecord(UINT iMessage
, WPARAM wParam
, LPARAM lParam
);
237 void PageMove(int direction
, bool extend
=false);
238 void ChangeCaseOfSelection(bool makeUpperCase
);
239 void LineTranspose();
240 virtual int KeyCommand(UINT iMessage
);
241 virtual int KeyDefault(int /* key */, int /*modifiers*/);
242 int KeyDown(int key
, bool shift
, bool ctrl
, bool alt
);
244 bool GetWhitespaceVisible();
245 void SetWhitespaceVisible(bool view
);
247 void Indent(bool forwards
);
249 long FindText(UINT iMessage
,WPARAM wParam
,LPARAM lParam
);
251 long SearchText(UINT iMessage
,WPARAM wParam
,LPARAM lParam
);
252 void GoToLine(int lineNo
);
254 char *CopyRange(int start
, int end
);
255 int SelectionRangeLength();
256 char *CopySelectionRange();
257 void CopySelectionIntoDrag();
258 void SetDragPosition(int newPos
);
259 virtual void StartDrag();
260 void DropAt(int position
, const char *value
, bool moving
, bool rectangular
);
261 // PositionInSelection returns 0 if position in selection, -1 if position before selection, and 1 if after.
262 // Before means either before any line of selection or before selection on its line, with a similar meaning to after
263 int PositionInSelection(int pos
);
264 bool PointInSelection(Point pt
);
265 bool PointInSelMargin(Point pt
);
266 virtual void ButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
);
267 void ButtonMove(Point pt
);
268 void ButtonUp(Point pt
, unsigned int curTime
, bool ctrl
);
271 virtual void SetTicking(bool on
) = 0;
272 virtual void SetMouseCapture(bool on
) = 0;
273 virtual bool HaveMouseCapture() = 0;
275 void CheckForChangeOutsidePaint(Range r
);
276 int BraceMatch(int position
, int maxReStyle
);
277 void SetBraceHighlight(Position pos0
, Position pos1
, int matchStyle
);
279 void SetDocPointer(Document
*document
);
281 void Expand(int &line
, bool doExpand
);
282 void ToggleContraction(int line
);
283 void EnsureLineVisible(int line
);
285 virtual LRESULT
DefWndProc(UINT iMessage
, WPARAM wParam
, LPARAM lParam
) = 0;
288 // Public so scintilla_send_message can use it
289 virtual LRESULT
WndProc(UINT iMessage
, WPARAM wParam
, LPARAM lParam
);
290 // Public so scintilla_set_id can use it