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};
39 char chars
[maxLineLength
+1];
40 char styles
[maxLineLength
+1];
41 char indicators
[maxLineLength
+1];
42 int positions
[maxLineLength
+1];
45 class Editor
: public DocWatcher
{
46 // Private so Editor objects can not be copied
47 Editor(const Editor
&) : DocWatcher() {}
48 Editor
&operator=(const Editor
&) { return *this; }
49 protected: // ScintillaBase subclass needs access to much of Editor
51 // On GTK+, Scintilla is a container widget holding two scroll bars and a drawing area
52 // whereas on Windows there is just one window with both scroll bars turned on.
53 // Therefore, on GTK+ the following are separate windows but only one window on Windows.
54 Window wMain
; // The Scintilla parent window
55 Window wDraw
; // The text drawing area
57 // Style resources may be expensive to allocate so are cached between uses.
58 // When a style attribute is changed, this cache is flushed.
62 int printMagnification
;
68 // In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to
69 // the screen. This avoids flashing but is about 30% slower.
72 int xOffset
; // Horizontal scrolled amount in pixels
73 int xCaretMargin
; // Ensure this many pixels visible on both sides of caret
74 bool horizontalScrollBarVisible
;
77 Surface pixmapSelMargin
;
78 Surface pixmapSelPattern
;
79 Surface pixmapIndentGuide
;
80 Surface pixmapIndentGuideHighlight
;
81 // Intellimouse support - currently only implemented for Windows
82 unsigned int ucWheelScrollLines
;
83 int cWheelDelta
; //wheel delta from roll
91 unsigned int lastClickTime
;
92 enum { selChar
, selWord
, selLine
} selectionType
;
101 int originalAnchorPos
;
109 int bracesMatchStyle
;
110 int highlightGuideColumn
;
114 enum { notPainting
, painting
, paintAbandoned
} paintState
;
116 bool paintingAllText
;
122 bool dragIsRectangle
;
123 enum { selStream
, selRectangle
, selRectangleFixed
} selType
;
126 bool primarySelection
;
133 int displayPopupMenu
;
146 virtual void Initialise() = 0;
147 virtual void Finalise();
149 void InvalidateStyleData();
150 void InvalidateStyleRedraw();
151 virtual void RefreshColourPalette(Palette
&pal
, bool want
);
152 void RefreshStyleData();
155 PRectangle
GetClientRectangle();
156 PRectangle
GetTextRectangle();
161 Point
LocationFromPosition(unsigned int pos
);
162 int XFromPosition(unsigned int pos
);
163 int PositionFromLocation(Point pt
);
164 int PositionFromLineX(int line
, int x
);
165 int LineFromLocation(Point pt
);
166 void SetTopLine(int topLineNew
);
168 void RedrawRect(PRectangle rc
);
170 void RedrawSelMargin();
171 PRectangle
RectangleFromRange(int start
, int end
);
172 void InvalidateRange(int start
, int end
);
174 int CurrentPosition();
175 bool SelectionEmpty();
176 int SelectionStart(int line
=-1);
177 int SelectionEnd(int line
=-1);
178 void SetSelection(int currentPos_
, int anchor_
);
179 void SetSelection(int currentPos_
);
180 void SetEmptySelection(int currentPos_
);
181 int MovePositionOutsideChar(int pos
, int moveDir
, bool checkLineEnd
=true);
182 int MovePositionTo(int newPos
, bool extend
= false);
183 int MovePositionSoVisible(int pos
, int moveDir
);
184 void SetLastXChosen();
186 void ScrollTo(int line
);
187 virtual void ScrollText(int linesToMove
);
188 void HorizontalScrollTo(int xPos
);
189 void MoveCaretInsideView();
190 void EnsureCaretVisible(bool useMargin
=true);
191 void ShowCaretAtCurrentPosition();
193 void InvalidateCaret();
195 void PaintSelMargin(Surface
*surface
, PRectangle
&rc
);
196 void LayoutLine(int line
, Surface
*surface
, ViewStyle
&vstyle
, LineLayout
&ll
);
197 void DrawLine(Surface
*surface
, ViewStyle
&vsDraw
, int line
, int lineVisible
, int xStart
,
198 PRectangle rcLine
, LineLayout
&ll
);
199 void Paint(Surface
*surfaceWindow
, PRectangle rcArea
);
200 long FormatRange(bool draw
, RangeToFormat
*pfr
);
202 virtual void SetVerticalScrollPos() = 0;
203 virtual void SetHorizontalScrollPos() = 0;
204 virtual bool ModifyScrollBars(int nMax
, int nPage
) = 0;
205 virtual void ReconfigureScrollBars();
206 void SetScrollBarsTo(PRectangle rsClient
);
207 void SetScrollBars();
209 void AddChar(char ch
);
210 virtual void AddCharUTF(char *s
, unsigned int len
);
211 void ClearSelection();
213 void ClearDocumentStyle();
215 void PasteRectangular(int pos
, const char *ptr
, int len
);
216 virtual void Copy() = 0;
217 virtual void Paste() = 0;
224 virtual void ClaimSelection() = 0;
226 virtual void NotifyChange() = 0;
227 virtual void NotifyFocus(bool focus
);
228 virtual void NotifyParent(SCNotification scn
) = 0;
229 virtual void NotifyStyleToNeeded(int endStyleNeeded
);
230 void NotifyChar(char ch
);
231 void NotifyMove(int position
);
232 void NotifySavePoint(bool isSavePoint
);
233 void NotifyModifyAttempt();
234 virtual void NotifyDoubleClick(Point pt
, bool shift
);
235 void NotifyUpdateUI();
236 bool NotifyMarginClick(Point pt
, bool shift
, bool ctrl
, bool alt
);
237 void NotifyNeedShown(int pos
, int len
);
239 void NotifyModifyAttempt(Document
*document
, void *userData
);
240 void NotifySavePoint(Document
*document
, void *userData
, bool atSavePoint
);
241 void NotifyModified(Document
*document
, DocModification mh
, void *userData
);
242 void NotifyDeleted(Document
*document
, void *userData
);
243 void NotifyStyleNeeded(Document
*doc
, void *userData
, int endPos
);
247 void NotifyMacroRecord(unsigned int iMessage
, unsigned long wParam
, long lParam
);
250 void PageMove(int direction
, bool extend
=false);
251 void ChangeCaseOfSelection(bool makeUpperCase
);
252 void LineTranspose();
253 virtual void CancelModes();
254 virtual int KeyCommand(unsigned int iMessage
);
255 virtual int KeyDefault(int /* key */, int /*modifiers*/);
256 int KeyDown(int key
, bool shift
, bool ctrl
, bool alt
);
258 int GetWhitespaceVisible();
259 void SetWhitespaceVisible(int view
);
261 void Indent(bool forwards
);
263 long FindText(unsigned int iMessage
, unsigned long wParam
, long lParam
);
265 long SearchText(unsigned int iMessage
, unsigned long wParam
, long lParam
);
266 void GoToLine(int lineNo
);
268 char *CopyRange(int start
, int end
);
269 int SelectionRangeLength();
270 char *CopySelectionRange();
271 void CopySelectionIntoDrag();
272 void SetDragPosition(int newPos
);
273 virtual void StartDrag();
274 void DropAt(int position
, const char *value
, bool moving
, bool rectangular
);
275 // PositionInSelection returns 0 if position in selection, -1 if position before selection, and 1 if after.
276 // Before means either before any line of selection or before selection on its line, with a similar meaning to after
277 int PositionInSelection(int pos
);
278 bool PointInSelection(Point pt
);
279 bool PointInSelMargin(Point pt
);
280 virtual void ButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
);
281 void ButtonMove(Point pt
);
282 void ButtonUp(Point pt
, unsigned int curTime
, bool ctrl
);
285 virtual void SetTicking(bool on
) = 0;
286 virtual void SetMouseCapture(bool on
) = 0;
287 virtual bool HaveMouseCapture() = 0;
289 void CheckForChangeOutsidePaint(Range r
);
290 int BraceMatch(int position
, int maxReStyle
);
291 void SetBraceHighlight(Position pos0
, Position pos1
, int matchStyle
);
293 void SetDocPointer(Document
*document
);
295 void Expand(int &line
, bool doExpand
);
296 void ToggleContraction(int line
);
297 void EnsureLineVisible(int line
);
299 virtual long DefWndProc(unsigned int iMessage
, unsigned long wParam
, long lParam
) = 0;
302 // Public so scintilla_send_message can use it
303 virtual long WndProc(unsigned int iMessage
, unsigned long wParam
, long lParam
);
304 // Public so scintilla_set_id can use it