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];
55 class Editor
: public DocWatcher
{
56 // Private so Editor objects can not be copied
57 Editor(const Editor
&) : DocWatcher() {}
58 Editor
&operator=(const Editor
&) { return *this; }
60 protected: // ScintillaBase subclass needs access to much of Editor
62 /** On GTK+, Scintilla is a container widget holding two scroll bars
63 * whereas on Windows there is just one window with both scroll bars turned on. */
64 Window wMain
; ///< The Scintilla parent window
66 /** Style resources may be expensive to allocate so are cached between uses.
67 * When a style attribute is changed, this cache is flushed. */
71 int printMagnification
;
79 bool mouseDownCaptures
;
81 /** In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to
82 * the screen. This avoids flashing but is about 30% slower. */
85 int xOffset
; ///< Horizontal scrolled amount in pixels
86 int xCaretMargin
; ///< Ensure this many pixels visible on both sides of caret
87 bool horizontalScrollBarVisible
;
90 Surface pixmapSelMargin
;
91 Surface pixmapSelPattern
;
92 Surface pixmapIndentGuide
;
93 Surface pixmapIndentGuideHighlight
;
94 // Intellimouse support - currently only implemented for Windows
95 unsigned int ucWheelScrollLines
;
96 int cWheelDelta
; ///< Wheel delta from roll
102 Timer autoScrollTimer
;
103 enum { autoScrollDelay
= 200 };
106 unsigned int lastClickTime
;
110 enum { selChar
, selWord
, selLine
} selectionType
;
114 bool dropWentOutside
;
119 int originalAnchorPos
;
130 int bracesMatchStyle
;
131 int highlightGuideColumn
;
135 enum { notPainting
, painting
, paintAbandoned
} paintState
;
137 bool paintingAllText
;
143 bool dragIsRectangle
;
144 enum { selStream
, selRectangle
, selRectangleFixed
} selType
;
147 bool primarySelection
;
157 int displayPopupMenu
;
170 virtual void Initialise() = 0;
171 virtual void Finalise();
173 void InvalidateStyleData();
174 void InvalidateStyleRedraw();
175 virtual void RefreshColourPalette(Palette
&pal
, bool want
);
176 void RefreshStyleData();
179 virtual PRectangle
GetClientRectangle();
180 PRectangle
GetTextRectangle();
185 Point
LocationFromPosition(int pos
);
186 int XFromPosition(int pos
);
187 int PositionFromLocation(Point pt
);
188 int PositionFromLocationClose(Point pt
);
189 int PositionFromLineX(int line
, int x
);
190 int LineFromLocation(Point pt
);
191 void SetTopLine(int topLineNew
);
193 void RedrawRect(PRectangle rc
);
195 void RedrawSelMargin();
196 PRectangle
RectangleFromRange(int start
, int end
);
197 void InvalidateRange(int start
, int end
);
199 int CurrentPosition();
200 bool SelectionEmpty();
201 int SelectionStart(int line
=-1);
202 int SelectionEnd(int line
=-1);
203 void SetSelection(int currentPos_
, int anchor_
);
204 void SetSelection(int currentPos_
);
205 void SetEmptySelection(int currentPos_
);
206 int MovePositionOutsideChar(int pos
, int moveDir
, bool checkLineEnd
=true);
207 int MovePositionTo(int newPos
, bool extend
= false);
208 int MovePositionSoVisible(int pos
, int moveDir
);
209 void SetLastXChosen();
211 void ScrollTo(int line
);
212 virtual void ScrollText(int linesToMove
);
213 void HorizontalScrollTo(int xPos
);
214 void MoveCaretInsideView();
215 void EnsureCaretVisible(bool useMargin
=true, bool vert
=true, bool horiz
=true);
216 void ShowCaretAtCurrentPosition();
218 void InvalidateCaret();
220 int SubstituteMarkerIfEmpty(int markerCheck
, int markerDefault
);
221 void PaintSelMargin(Surface
*surface
, PRectangle
&rc
);
222 void LayoutLine(int line
, Surface
*surface
, ViewStyle
&vstyle
, LineLayout
&ll
);
223 void DrawLine(Surface
*surface
, ViewStyle
&vsDraw
, int line
, int lineVisible
, int xStart
,
224 PRectangle rcLine
, LineLayout
&ll
);
225 void Paint(Surface
*surfaceWindow
, PRectangle rcArea
);
226 long FormatRange(bool draw
, RangeToFormat
*pfr
);
228 virtual void SetVerticalScrollPos() = 0;
229 virtual void SetHorizontalScrollPos() = 0;
230 virtual bool ModifyScrollBars(int nMax
, int nPage
) = 0;
231 virtual void ReconfigureScrollBars();
232 void SetScrollBarsTo(PRectangle rsClient
);
233 void SetScrollBars();
235 void AddChar(char ch
);
236 virtual void AddCharUTF(char *s
, unsigned int len
);
237 void ClearSelection();
239 void ClearDocumentStyle();
241 void PasteRectangular(int pos
, const char *ptr
, int len
);
242 virtual void Copy() = 0;
243 virtual bool CanPaste();
244 virtual void Paste() = 0;
251 virtual void ClaimSelection() = 0;
253 virtual void NotifyChange() = 0;
254 virtual void NotifyFocus(bool focus
);
255 virtual void NotifyParent(SCNotification scn
) = 0;
256 virtual void NotifyStyleToNeeded(int endStyleNeeded
);
257 void NotifyChar(int ch
);
258 void NotifyMove(int position
);
259 void NotifySavePoint(bool isSavePoint
);
260 void NotifyModifyAttempt();
261 virtual void NotifyDoubleClick(Point pt
, bool shift
);
262 void NotifyUpdateUI();
263 void NotifyPainted();
264 bool NotifyMarginClick(Point pt
, bool shift
, bool ctrl
, bool alt
);
265 void NotifyNeedShown(int pos
, int len
);
266 void NotifyDwelling(Point pt
, bool state
);
268 void NotifyModifyAttempt(Document
*document
, void *userData
);
269 void NotifySavePoint(Document
*document
, void *userData
, bool atSavePoint
);
270 void NotifyModified(Document
*document
, DocModification mh
, void *userData
);
271 void NotifyDeleted(Document
*document
, void *userData
);
272 void NotifyStyleNeeded(Document
*doc
, void *userData
, int endPos
);
276 void NotifyMacroRecord(unsigned int iMessage
, unsigned long wParam
, long lParam
);
279 void PageMove(int direction
, bool extend
=false);
280 void ChangeCaseOfSelection(bool makeUpperCase
);
281 void LineTranspose();
282 virtual void CancelModes();
283 virtual int KeyCommand(unsigned int iMessage
);
284 virtual int KeyDefault(int /* key */, int /*modifiers*/);
285 int KeyDown(int key
, bool shift
, bool ctrl
, bool alt
, bool *consumed
=0);
287 int GetWhitespaceVisible();
288 void SetWhitespaceVisible(int view
);
290 void Indent(bool forwards
);
292 long FindText(unsigned int iMessage
, unsigned long wParam
, long lParam
);
294 long SearchText(unsigned int iMessage
, unsigned long wParam
, long lParam
);
295 long SearchInTarget(const char *text
, int length
);
296 void GoToLine(int lineNo
);
298 char *CopyRange(int start
, int end
);
299 int SelectionRangeLength();
300 char *CopySelectionRange();
301 void CopySelectionIntoDrag();
302 void SetDragPosition(int newPos
);
303 void DisplayCursor(Window::Cursor c
);
304 virtual void StartDrag();
305 void DropAt(int position
, const char *value
, bool moving
, bool rectangular
);
306 /** PositionInSelection returns 0 if position in selection, -1 if position before selection, and 1 if after.
307 * Before means either before any line of selection or before selection on its line, with a similar meaning to after. */
308 int PositionInSelection(int pos
);
309 bool PointInSelection(Point pt
);
310 bool PointInSelMargin(Point pt
);
311 void LineSelection(int lineCurrent_
, int lineAnchor_
);
312 void DwellEnd(bool mouseMoved
);
313 virtual void ButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
);
314 void ButtonMove(Point pt
);
315 void ButtonUp(Point pt
, unsigned int curTime
, bool ctrl
);
318 virtual void SetTicking(bool on
) = 0;
319 virtual void SetMouseCapture(bool on
) = 0;
320 virtual bool HaveMouseCapture() = 0;
321 void SetFocusState(bool focusState
);
323 void CheckForChangeOutsidePaint(Range r
);
324 int BraceMatch(int position
, int maxReStyle
);
325 void SetBraceHighlight(Position pos0
, Position pos1
, int matchStyle
);
327 void SetDocPointer(Document
*document
);
329 void Expand(int &line
, bool doExpand
);
330 void ToggleContraction(int line
);
331 void EnsureLineVisible(int lineDoc
, bool enforcePolicy
);
332 int ReplaceTarget(bool replacePatterns
, const char *text
, int length
=-1);
334 virtual sptr_t
DefWndProc(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
) = 0;
337 // Public so scintilla_send_message can use it
338 virtual sptr_t
WndProc(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
);
339 // Public so scintilla_set_id can use it