1 // Scintilla source code edit control
3 ** Defines the main editor class.
5 // Copyright 1998-2002 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 friend class LineLayoutCache
;
41 /// Drawing is only performed for @a maxLineLength characters on each line.
45 enum { wrapWidthInfinite
= 0x7ffffff };
48 enum validLevel
{ llInvalid
, llCheckTextAndStyle
, llPositions
, llLines
} validity
;
59 char bracePreviousStyles
[2];
61 // Wrapped line support
65 LineLayout(int maxLineLength_
);
66 virtual ~LineLayout();
67 void Resize(int maxLineLength_
);
69 void Invalidate(validLevel validity_
);
70 int LineStart(int line
) {
73 } else if ((line
>= lines
) || !lineStarts
) {
74 return numCharsInLine
;
76 return lineStarts
[line
];
79 void SetLineStart(int line
, int start
);
80 void SetBracesHighlight(Range rangeLine
, Position braces
[],
81 char bracesMatchStyle
, int xHighlight
);
82 void RestoreBracesHighlight(Range rangeLine
, Position braces
[]);
87 class LineLayoutCache
{
94 void Allocate(int length_
);
95 void AllocateForLevel(int linesOnScreen
, int linesInDoc
);
98 virtual ~LineLayoutCache();
101 llcNone
=SC_CACHE_NONE
,
102 llcCaret
=SC_CACHE_CARET
,
103 llcPage
=SC_CACHE_PAGE
,
104 llcDocument
=SC_CACHE_DOCUMENT
106 void Invalidate(LineLayout::validLevel validity_
);
107 void SetLevel(int level_
);
108 int GetLevel() { return level
; }
109 LineLayout
*Retrieve(int lineNumber
, int lineCaret
, int maxChars
, int styleClock_
,
110 int linesOnScreen
, int linesInDoc
);
111 void Dispose(LineLayout
*ll
);
114 class SelectionText
{
119 SelectionText() : s(0), len(0), rectangular(false) {}
123 void Set(char *s_
, int len_
, bool rectangular_
=false) {
130 rectangular
= rectangular_
;
135 * A smart pointer class to ensure Surfaces are set up and deleted correctly.
141 AutoSurface(bool unicodeMode
) {
142 surf
= Surface::Allocate();
145 surf
->SetUnicodeMode(unicodeMode
);
148 AutoSurface(SurfaceID sid
, bool unicodeMode
) {
149 surf
= Surface::Allocate();
152 surf
->SetUnicodeMode(unicodeMode
);
158 Surface
*operator->() const {
161 operator Surface
*() const {
168 class Editor
: public DocWatcher
{
169 // Private so Editor objects can not be copied
170 Editor(const Editor
&) : DocWatcher() {}
171 Editor
&operator=(const Editor
&) { return *this; }
173 protected: // ScintillaBase subclass needs access to much of Editor
175 /** On GTK+, Scintilla is a container widget holding two scroll bars
176 * whereas on Windows there is just one window with both scroll bars turned on. */
177 Window wMain
; ///< The Scintilla parent window
179 /** Style resources may be expensive to allocate so are cached between uses.
180 * When a style attribute is changed, this cache is flushed. */
185 int printMagnification
;
188 int controlCharSymbol
;
194 bool mouseDownCaptures
;
196 /** In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to
197 * the screen. This avoids flashing but is about 30% slower. */
200 int xOffset
; ///< Horizontal scrolled amount in pixels
201 int xCaretMargin
; ///< Ensure this many pixels visible on both sides of caret
202 bool horizontalScrollBarVisible
;
207 Surface
*pixmapSelMargin
;
208 Surface
*pixmapSelPattern
;
209 Surface
*pixmapIndentGuide
;
210 Surface
*pixmapIndentGuideHighlight
;
218 Timer autoScrollTimer
;
219 enum { autoScrollDelay
= 200 };
222 unsigned int lastClickTime
;
226 enum { selChar
, selWord
, selLine
} selectionType
;
229 bool dropWentOutside
;
234 int originalAnchorPos
;
245 int bracesMatchStyle
;
246 int highlightGuideColumn
;
250 enum { notPainting
, painting
, paintAbandoned
} paintState
;
252 bool paintingAllText
;
257 enum { selStream
, selRectangle
, selRectangleFixed
} selType
;
260 bool primarySelection
;
263 int caretXSlop
; ///< Ensure this many pixels visible on both sides of caret
266 int caretYSlop
; ///< Ensure this many lines visible on both sides of caret
279 enum { eWrapNone
, eWrapWord
} wrapState
;
281 int docLineLastWrapped
;
287 virtual void Initialise() = 0;
288 virtual void Finalise();
290 void InvalidateStyleData();
291 void InvalidateStyleRedraw();
292 virtual void RefreshColourPalette(Palette
&pal
, bool want
);
293 void RefreshStyleData();
296 virtual PRectangle
GetClientRectangle();
297 PRectangle
GetTextRectangle();
302 Point
LocationFromPosition(int pos
);
303 int XFromPosition(int pos
);
304 int PositionFromLocation(Point pt
);
305 int PositionFromLocationClose(Point pt
);
306 int PositionFromLineX(int line
, int x
);
307 int LineFromLocation(Point pt
);
308 void SetTopLine(int topLineNew
);
311 void RedrawRect(PRectangle rc
);
313 void RedrawSelMargin();
314 PRectangle
RectangleFromRange(int start
, int end
);
315 void InvalidateRange(int start
, int end
);
317 int CurrentPosition();
318 bool SelectionEmpty();
319 int SelectionStart(int line
=-1);
320 int SelectionEnd(int line
=-1);
321 void SetSelection(int currentPos_
, int anchor_
);
322 void SetSelection(int currentPos_
);
323 void SetEmptySelection(int currentPos_
);
324 int MovePositionOutsideChar(int pos
, int moveDir
, bool checkLineEnd
=true);
325 int MovePositionTo(int newPos
, bool extend
= false);
326 int MovePositionSoVisible(int pos
, int moveDir
);
327 void SetLastXChosen();
329 void ScrollTo(int line
);
330 virtual void ScrollText(int linesToMove
);
331 void HorizontalScrollTo(int xPos
);
332 void MoveCaretInsideView();
333 int DisplayFromPosition(int pos
);
334 void EnsureCaretVisible(bool useMargin
=true, bool vert
=true, bool horiz
=true);
335 void ShowCaretAtCurrentPosition();
337 void InvalidateCaret();
339 void NeedWrapping(int docLineStartWrapping
=0);
342 int SubstituteMarkerIfEmpty(int markerCheck
, int markerDefault
);
343 void PaintSelMargin(Surface
*surface
, PRectangle
&rc
);
344 LineLayout
*RetrieveLineLayout(int lineNumber
);
345 void LayoutLine(int line
, Surface
*surface
, ViewStyle
&vstyle
, LineLayout
*ll
,
346 int width
=LineLayout::wrapWidthInfinite
);
347 void DrawLine(Surface
*surface
, ViewStyle
&vsDraw
, int line
, int lineVisible
, int xStart
,
348 PRectangle rcLine
, LineLayout
*ll
, int subLine
=0);
349 void Paint(Surface
*surfaceWindow
, PRectangle rcArea
);
350 long FormatRange(bool draw
, RangeToFormat
*pfr
);
351 int TextWidth(int style
, const char *text
);
353 virtual void SetVerticalScrollPos() = 0;
354 virtual void SetHorizontalScrollPos() = 0;
355 virtual bool ModifyScrollBars(int nMax
, int nPage
) = 0;
356 virtual void ReconfigureScrollBars();
357 void SetScrollBars();
360 void AddChar(char ch
);
361 virtual void AddCharUTF(char *s
, unsigned int len
, bool treatAsDBCS
=false);
362 void ClearSelection();
364 void ClearDocumentStyle();
366 void PasteRectangular(int pos
, const char *ptr
, int len
);
367 virtual void Copy() = 0;
368 virtual bool CanPaste();
369 virtual void Paste() = 0;
375 void DelCharBack(bool allowLineStartDeletion
);
376 virtual void ClaimSelection() = 0;
378 virtual void NotifyChange() = 0;
379 virtual void NotifyFocus(bool focus
);
380 virtual int GetCtrlID() { return ctrlID
; }
381 virtual void NotifyParent(SCNotification scn
) = 0;
382 virtual void NotifyStyleToNeeded(int endStyleNeeded
);
383 void NotifyChar(int ch
);
384 void NotifyMove(int position
);
385 void NotifySavePoint(bool isSavePoint
);
386 void NotifyModifyAttempt();
387 virtual void NotifyDoubleClick(Point pt
, bool shift
);
388 void NotifyUpdateUI();
389 void NotifyPainted();
390 bool NotifyMarginClick(Point pt
, bool shift
, bool ctrl
, bool alt
);
391 void NotifyNeedShown(int pos
, int len
);
392 void NotifyDwelling(Point pt
, bool state
);
395 void NotifyModifyAttempt(Document
*document
, void *userData
);
396 void NotifySavePoint(Document
*document
, void *userData
, bool atSavePoint
);
397 void CheckModificationForWrap(DocModification mh
);
398 void NotifyModified(Document
*document
, DocModification mh
, void *userData
);
399 void NotifyDeleted(Document
*document
, void *userData
);
400 void NotifyStyleNeeded(Document
*doc
, void *userData
, int endPos
);
401 void NotifyMacroRecord(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
);
403 void PageMove(int direction
, bool extend
=false);
404 void ChangeCaseOfSelection(bool makeUpperCase
);
405 void LineTranspose();
406 virtual void CancelModes();
408 void CursorUpOrDown(int direction
, bool extend
=false);
409 virtual int KeyCommand(unsigned int iMessage
);
410 virtual int KeyDefault(int /* key */, int /*modifiers*/);
411 int KeyDown(int key
, bool shift
, bool ctrl
, bool alt
, bool *consumed
=0);
413 int GetWhitespaceVisible();
414 void SetWhitespaceVisible(int view
);
416 void Indent(bool forwards
);
418 long FindText(uptr_t wParam
, sptr_t lParam
);
420 long SearchText(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
);
421 long SearchInTarget(const char *text
, int length
);
422 void GoToLine(int lineNo
);
424 char *CopyRange(int start
, int end
);
425 void CopySelectionRange(SelectionText
*ss
);
426 void SetDragPosition(int newPos
);
427 void DisplayCursor(Window::Cursor c
);
428 virtual void StartDrag();
429 void DropAt(int position
, const char *value
, bool moving
, bool rectangular
);
430 /** PositionInSelection returns 0 if position in selection, -1 if position before selection, and 1 if after.
431 * Before means either before any line of selection or before selection on its line, with a similar meaning to after. */
432 int PositionInSelection(int pos
);
433 bool PointInSelection(Point pt
);
434 bool PointInSelMargin(Point pt
);
435 void LineSelection(int lineCurrent_
, int lineAnchor_
);
436 void DwellEnd(bool mouseMoved
);
437 virtual void ButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
);
438 void ButtonMove(Point pt
);
439 void ButtonUp(Point pt
, unsigned int curTime
, bool ctrl
);
442 virtual void SetTicking(bool on
) = 0;
443 virtual void SetMouseCapture(bool on
) = 0;
444 virtual bool HaveMouseCapture() = 0;
445 void SetFocusState(bool focusState
);
447 void CheckForChangeOutsidePaint(Range r
);
448 int BraceMatch(int position
, int maxReStyle
);
449 void SetBraceHighlight(Position pos0
, Position pos1
, int matchStyle
);
451 void SetDocPointer(Document
*document
);
453 void Expand(int &line
, bool doExpand
);
454 void ToggleContraction(int line
);
455 void EnsureLineVisible(int lineDoc
, bool enforcePolicy
);
456 int ReplaceTarget(bool replacePatterns
, const char *text
, int length
=-1);
458 virtual sptr_t
DefWndProc(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
) = 0;
461 // Public so the COM thunks can access it.
462 bool IsUnicodeMode() const;
463 // Public so scintilla_send_message can use it.
464 virtual sptr_t
WndProc(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
);
465 // Public so scintilla_set_id can use it.