1 // Scintilla source code edit control
3 ** Defines the main editor class.
5 // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
28 enum {tickSize
= 100};
38 /// Drawing is only performed for @a maxLineLength characters on each line.
39 enum {maxLineLength
= 4000};
47 char chars
[maxLineLength
+1];
48 char styles
[maxLineLength
+1];
49 char indicators
[maxLineLength
+1];
50 int positions
[maxLineLength
+1];
58 SelectionText() : s(0), len(0), rectangular(false) {}
62 void Set(char *s_
, int len_
, bool rectangular_
=false) {
69 rectangular
= rectangular_
;
75 class Editor
: public DocWatcher
{
76 // Private so Editor objects can not be copied
77 Editor(const Editor
&) : DocWatcher() {}
78 Editor
&operator=(const Editor
&) { return *this; }
80 protected: // ScintillaBase subclass needs access to much of Editor
82 /** On GTK+, Scintilla is a container widget holding two scroll bars
83 * whereas on Windows there is just one window with both scroll bars turned on. */
84 Window wMain
; ///< The Scintilla parent window
86 /** Style resources may be expensive to allocate so are cached between uses.
87 * When a style attribute is changed, this cache is flushed. */
92 int printMagnification
;
100 bool mouseDownCaptures
;
102 /** In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to
103 * the screen. This avoids flashing but is about 30% slower. */
106 int xOffset
; ///< Horizontal scrolled amount in pixels
107 int xCaretMargin
; ///< Ensure this many pixels visible on both sides of caret
108 bool horizontalScrollBarVisible
;
111 Surface pixmapSelMargin
;
112 Surface pixmapSelPattern
;
113 Surface pixmapIndentGuide
;
114 Surface pixmapIndentGuideHighlight
;
120 Timer autoScrollTimer
;
121 enum { autoScrollDelay
= 200 };
124 unsigned int lastClickTime
;
128 enum { selChar
, selWord
, selLine
} selectionType
;
131 bool dropWentOutside
;
136 int originalAnchorPos
;
147 int bracesMatchStyle
;
148 int highlightGuideColumn
;
152 enum { notPainting
, painting
, paintAbandoned
} paintState
;
154 bool paintingAllText
;
159 enum { selStream
, selRectangle
, selRectangleFixed
} selType
;
162 bool primarySelection
;
181 virtual void Initialise() = 0;
182 virtual void Finalise();
184 void InvalidateStyleData();
185 void InvalidateStyleRedraw();
186 virtual void RefreshColourPalette(Palette
&pal
, bool want
);
187 void RefreshStyleData();
190 virtual PRectangle
GetClientRectangle();
191 PRectangle
GetTextRectangle();
196 Point
LocationFromPosition(int pos
);
197 int XFromPosition(int pos
);
198 int PositionFromLocation(Point pt
);
199 int PositionFromLocationClose(Point pt
);
200 int PositionFromLineX(int line
, int x
);
201 int LineFromLocation(Point pt
);
202 void SetTopLine(int topLineNew
);
204 void RedrawRect(PRectangle rc
);
206 void RedrawSelMargin();
207 PRectangle
RectangleFromRange(int start
, int end
);
208 void InvalidateRange(int start
, int end
);
210 int CurrentPosition();
211 bool SelectionEmpty();
212 int SelectionStart(int line
=-1);
213 int SelectionEnd(int line
=-1);
214 void SetSelection(int currentPos_
, int anchor_
);
215 void SetSelection(int currentPos_
);
216 void SetEmptySelection(int currentPos_
);
217 int MovePositionOutsideChar(int pos
, int moveDir
, bool checkLineEnd
=true);
218 int MovePositionTo(int newPos
, bool extend
= false);
219 int MovePositionSoVisible(int pos
, int moveDir
);
220 void SetLastXChosen();
222 void ScrollTo(int line
);
223 virtual void ScrollText(int linesToMove
);
224 void HorizontalScrollTo(int xPos
);
225 void MoveCaretInsideView();
226 void EnsureCaretVisible(bool useMargin
=true, bool vert
=true, bool horiz
=true);
227 void ShowCaretAtCurrentPosition();
229 void InvalidateCaret();
231 int SubstituteMarkerIfEmpty(int markerCheck
, int markerDefault
);
232 void PaintSelMargin(Surface
*surface
, PRectangle
&rc
);
233 void LayoutLine(int line
, Surface
*surface
, ViewStyle
&vstyle
, LineLayout
&ll
);
234 void DrawLine(Surface
*surface
, ViewStyle
&vsDraw
, int line
, int lineVisible
, int xStart
,
235 PRectangle rcLine
, LineLayout
&ll
);
236 void Paint(Surface
*surfaceWindow
, PRectangle rcArea
);
237 long FormatRange(bool draw
, RangeToFormat
*pfr
);
239 virtual void SetVerticalScrollPos() = 0;
240 virtual void SetHorizontalScrollPos() = 0;
241 virtual bool ModifyScrollBars(int nMax
, int nPage
) = 0;
242 virtual void ReconfigureScrollBars();
243 void SetScrollBarsTo(PRectangle rsClient
);
244 void SetScrollBars();
246 void AddChar(char ch
);
247 virtual void AddCharUTF(char *s
, unsigned int len
);
248 void ClearSelection();
250 void ClearDocumentStyle();
252 void PasteRectangular(int pos
, const char *ptr
, int len
);
253 virtual void Copy() = 0;
254 virtual bool CanPaste();
255 virtual void Paste() = 0;
262 virtual void ClaimSelection() = 0;
264 virtual void NotifyChange() = 0;
265 virtual void NotifyFocus(bool focus
);
266 virtual void NotifyParent(SCNotification scn
) = 0;
267 virtual void NotifyStyleToNeeded(int endStyleNeeded
);
268 void NotifyChar(int ch
);
269 void NotifyMove(int position
);
270 void NotifySavePoint(bool isSavePoint
);
271 void NotifyModifyAttempt();
272 virtual void NotifyDoubleClick(Point pt
, bool shift
);
273 void NotifyUpdateUI();
274 void NotifyPainted();
275 bool NotifyMarginClick(Point pt
, bool shift
, bool ctrl
, bool alt
);
276 void NotifyNeedShown(int pos
, int len
);
277 void NotifyDwelling(Point pt
, bool state
);
279 void NotifyModifyAttempt(Document
*document
, void *userData
);
280 void NotifySavePoint(Document
*document
, void *userData
, bool atSavePoint
);
281 void NotifyModified(Document
*document
, DocModification mh
, void *userData
);
282 void NotifyDeleted(Document
*document
, void *userData
);
283 void NotifyStyleNeeded(Document
*doc
, void *userData
, int endPos
);
284 void NotifyMacroRecord(unsigned int iMessage
, unsigned long wParam
, long lParam
);
286 void PageMove(int direction
, bool extend
=false);
287 void ChangeCaseOfSelection(bool makeUpperCase
);
288 void LineTranspose();
289 virtual void CancelModes();
290 virtual int KeyCommand(unsigned int iMessage
);
291 virtual int KeyDefault(int /* key */, int /*modifiers*/);
292 int KeyDown(int key
, bool shift
, bool ctrl
, bool alt
, bool *consumed
=0);
294 int GetWhitespaceVisible();
295 void SetWhitespaceVisible(int view
);
297 void Indent(bool forwards
);
299 long FindText(unsigned long wParam
, long lParam
);
301 long SearchText(unsigned int iMessage
, unsigned long wParam
, long lParam
);
302 long SearchInTarget(const char *text
, int length
);
303 void GoToLine(int lineNo
);
305 char *CopyRange(int start
, int end
);
306 void CopySelectionRange(SelectionText
*ss
);
307 void SetDragPosition(int newPos
);
308 void DisplayCursor(Window::Cursor c
);
309 virtual void StartDrag();
310 void DropAt(int position
, const char *value
, bool moving
, bool rectangular
);
311 /** PositionInSelection returns 0 if position in selection, -1 if position before selection, and 1 if after.
312 * Before means either before any line of selection or before selection on its line, with a similar meaning to after. */
313 int PositionInSelection(int pos
);
314 bool PointInSelection(Point pt
);
315 bool PointInSelMargin(Point pt
);
316 void LineSelection(int lineCurrent_
, int lineAnchor_
);
317 void DwellEnd(bool mouseMoved
);
318 virtual void ButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
);
319 void ButtonMove(Point pt
);
320 void ButtonUp(Point pt
, unsigned int curTime
, bool ctrl
);
323 virtual void SetTicking(bool on
) = 0;
324 virtual void SetMouseCapture(bool on
) = 0;
325 virtual bool HaveMouseCapture() = 0;
326 void SetFocusState(bool focusState
);
328 void CheckForChangeOutsidePaint(Range r
);
329 int BraceMatch(int position
, int maxReStyle
);
330 void SetBraceHighlight(Position pos0
, Position pos1
, int matchStyle
);
332 void SetDocPointer(Document
*document
);
334 void Expand(int &line
, bool doExpand
);
335 void ToggleContraction(int line
);
336 void EnsureLineVisible(int lineDoc
, bool enforcePolicy
);
337 int ReplaceTarget(bool replacePatterns
, const char *text
, int length
=-1);
339 virtual sptr_t
DefWndProc(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
) = 0;
342 // Public so scintilla_send_message can use it
343 virtual sptr_t
WndProc(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
);
344 // Public so scintilla_set_id can use it