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
, 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
;
205 Surface
*pixmapSelMargin
;
206 Surface
*pixmapSelPattern
;
207 Surface
*pixmapIndentGuide
;
208 Surface
*pixmapIndentGuideHighlight
;
216 Timer autoScrollTimer
;
217 enum { autoScrollDelay
= 200 };
220 unsigned int lastClickTime
;
224 enum { selChar
, selWord
, selLine
} selectionType
;
227 bool dropWentOutside
;
232 int originalAnchorPos
;
243 int bracesMatchStyle
;
244 int highlightGuideColumn
;
248 enum { notPainting
, painting
, paintAbandoned
} paintState
;
250 bool paintingAllText
;
255 enum { selStream
, selRectangle
, selRectangleFixed
} selType
;
258 bool primarySelection
;
274 enum { eWrapNone
, eWrapWord
} wrapState
;
276 int docLineLastWrapped
;
282 virtual void Initialise() = 0;
283 virtual void Finalise();
285 void InvalidateStyleData();
286 void InvalidateStyleRedraw();
287 virtual void RefreshColourPalette(Palette
&pal
, bool want
);
288 void RefreshStyleData();
291 virtual PRectangle
GetClientRectangle();
292 PRectangle
GetTextRectangle();
297 Point
LocationFromPosition(int pos
);
298 int XFromPosition(int pos
);
299 int PositionFromLocation(Point pt
);
300 int PositionFromLocationClose(Point pt
);
301 int PositionFromLineX(int line
, int x
);
302 int LineFromLocation(Point pt
);
303 void SetTopLine(int topLineNew
);
305 void RedrawRect(PRectangle rc
);
307 void RedrawSelMargin();
308 PRectangle
RectangleFromRange(int start
, int end
);
309 void InvalidateRange(int start
, int end
);
311 int CurrentPosition();
312 bool SelectionEmpty();
313 int SelectionStart(int line
=-1);
314 int SelectionEnd(int line
=-1);
315 void SetSelection(int currentPos_
, int anchor_
);
316 void SetSelection(int currentPos_
);
317 void SetEmptySelection(int currentPos_
);
318 int MovePositionOutsideChar(int pos
, int moveDir
, bool checkLineEnd
=true);
319 int MovePositionTo(int newPos
, bool extend
= false);
320 int MovePositionSoVisible(int pos
, int moveDir
);
321 void SetLastXChosen();
323 void ScrollTo(int line
);
324 virtual void ScrollText(int linesToMove
);
325 void HorizontalScrollTo(int xPos
);
326 void MoveCaretInsideView();
327 int DisplayFromPosition(int pos
);
328 void EnsureCaretVisible(bool useMargin
=true, bool vert
=true, bool horiz
=true);
329 void ShowCaretAtCurrentPosition();
331 void InvalidateCaret();
333 void NeedWrapping(int docLineStartWrapping
=0);
336 int SubstituteMarkerIfEmpty(int markerCheck
, int markerDefault
);
337 void PaintSelMargin(Surface
*surface
, PRectangle
&rc
);
338 LineLayout
*RetrieveLineLayout(int lineNumber
);
339 void LayoutLine(int line
, Surface
*surface
, ViewStyle
&vstyle
, LineLayout
*ll
,
340 int width
=LineLayout::wrapWidthInfinite
);
341 void DrawLine(Surface
*surface
, ViewStyle
&vsDraw
, int line
, int lineVisible
, int xStart
,
342 PRectangle rcLine
, LineLayout
*ll
, int subLine
=0);
343 void Paint(Surface
*surfaceWindow
, PRectangle rcArea
);
344 long FormatRange(bool draw
, RangeToFormat
*pfr
);
346 virtual void SetVerticalScrollPos() = 0;
347 virtual void SetHorizontalScrollPos() = 0;
348 virtual bool ModifyScrollBars(int nMax
, int nPage
) = 0;
349 virtual void ReconfigureScrollBars();
350 void SetScrollBars();
353 void AddChar(char ch
);
354 virtual void AddCharUTF(char *s
, unsigned int len
, bool treatAsDBCS
=false);
355 void ClearSelection();
357 void ClearDocumentStyle();
359 void PasteRectangular(int pos
, const char *ptr
, int len
);
360 virtual void Copy() = 0;
361 virtual bool CanPaste();
362 virtual void Paste() = 0;
368 void DelCharBack(bool allowLineStartDeletion
);
369 virtual void ClaimSelection() = 0;
371 virtual void NotifyChange() = 0;
372 virtual void NotifyFocus(bool focus
);
373 virtual int GetCtrlID() { return ctrlID
; }
374 virtual void NotifyParent(SCNotification scn
) = 0;
375 virtual void NotifyStyleToNeeded(int endStyleNeeded
);
376 void NotifyChar(int ch
);
377 void NotifyMove(int position
);
378 void NotifySavePoint(bool isSavePoint
);
379 void NotifyModifyAttempt();
380 virtual void NotifyDoubleClick(Point pt
, bool shift
);
381 void NotifyUpdateUI();
382 void NotifyPainted();
383 bool NotifyMarginClick(Point pt
, bool shift
, bool ctrl
, bool alt
);
384 void NotifyNeedShown(int pos
, int len
);
385 void NotifyDwelling(Point pt
, bool state
);
387 void NotifyModifyAttempt(Document
*document
, void *userData
);
388 void NotifySavePoint(Document
*document
, void *userData
, bool atSavePoint
);
389 void CheckModificationForWrap(DocModification mh
);
390 void NotifyModified(Document
*document
, DocModification mh
, void *userData
);
391 void NotifyDeleted(Document
*document
, void *userData
);
392 void NotifyStyleNeeded(Document
*doc
, void *userData
, int endPos
);
393 void NotifyMacroRecord(unsigned int iMessage
, unsigned long wParam
, long lParam
);
395 void PageMove(int direction
, bool extend
=false);
396 void ChangeCaseOfSelection(bool makeUpperCase
);
397 void LineTranspose();
398 virtual void CancelModes();
399 virtual int KeyCommand(unsigned int iMessage
);
400 virtual int KeyDefault(int /* key */, int /*modifiers*/);
401 int KeyDown(int key
, bool shift
, bool ctrl
, bool alt
, bool *consumed
=0);
403 int GetWhitespaceVisible();
404 void SetWhitespaceVisible(int view
);
406 void Indent(bool forwards
);
408 long FindText(unsigned long wParam
, long lParam
);
410 long SearchText(unsigned int iMessage
, unsigned long wParam
, long lParam
);
411 long SearchInTarget(const char *text
, int length
);
412 void GoToLine(int lineNo
);
414 char *CopyRange(int start
, int end
);
415 void CopySelectionRange(SelectionText
*ss
);
416 void SetDragPosition(int newPos
);
417 void DisplayCursor(Window::Cursor c
);
418 virtual void StartDrag();
419 void DropAt(int position
, const char *value
, bool moving
, bool rectangular
);
420 /** PositionInSelection returns 0 if position in selection, -1 if position before selection, and 1 if after.
421 * Before means either before any line of selection or before selection on its line, with a similar meaning to after. */
422 int PositionInSelection(int pos
);
423 bool PointInSelection(Point pt
);
424 bool PointInSelMargin(Point pt
);
425 void LineSelection(int lineCurrent_
, int lineAnchor_
);
426 void DwellEnd(bool mouseMoved
);
427 virtual void ButtonDown(Point pt
, unsigned int curTime
, bool shift
, bool ctrl
, bool alt
);
428 void ButtonMove(Point pt
);
429 void ButtonUp(Point pt
, unsigned int curTime
, bool ctrl
);
432 virtual void SetTicking(bool on
) = 0;
433 virtual void SetMouseCapture(bool on
) = 0;
434 virtual bool HaveMouseCapture() = 0;
435 void SetFocusState(bool focusState
);
437 void CheckForChangeOutsidePaint(Range r
);
438 int BraceMatch(int position
, int maxReStyle
);
439 void SetBraceHighlight(Position pos0
, Position pos1
, int matchStyle
);
441 void SetDocPointer(Document
*document
);
443 void Expand(int &line
, bool doExpand
);
444 void ToggleContraction(int line
);
445 void EnsureLineVisible(int lineDoc
, bool enforcePolicy
);
446 int ReplaceTarget(bool replacePatterns
, const char *text
, int length
=-1);
448 virtual sptr_t
DefWndProc(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
) = 0;
451 // Public so the COM thunks can access it.
452 bool IsUnicodeMode() const;
453 // Public so scintilla_send_message can use it.
454 virtual sptr_t
WndProc(unsigned int iMessage
, uptr_t wParam
, sptr_t lParam
);
455 // Public so scintilla_set_id can use it.