Refactor snippets_complete_constructs().
[geany-mirror.git] / scintilla / Editor.h
blob92dcfb14bf86eb768cc0a3a50f54bb5aefdd316d
1 // Scintilla source code edit control
2 /** @file Editor.h
3 ** Defines the main editor class.
4 **/
5 // Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
8 #ifndef EDITOR_H
9 #define EDITOR_H
11 #ifdef SCI_NAMESPACE
12 namespace Scintilla {
13 #endif
15 /**
17 class Caret {
18 public:
19 bool active;
20 bool on;
21 int period;
23 Caret();
26 /**
28 class Timer {
29 public:
30 bool ticking;
31 int ticksToWait;
32 enum {tickSize = 100};
33 TickerID tickerID;
35 Timer();
38 /**
40 class Idler {
41 public:
42 bool state;
43 IdlerID idlerID;
45 Idler();
48 /**
49 * Hold a piece of text selected for copying or dragging.
50 * The text is expected to hold a terminating '\0' and this is counted in len.
52 class SelectionText {
53 public:
54 char *s;
55 int len;
56 bool rectangular;
57 bool lineCopy;
58 int codePage;
59 int characterSet;
60 SelectionText() : s(0), len(0), rectangular(false), lineCopy(false), codePage(0), characterSet(0) {}
61 ~SelectionText() {
62 Free();
64 void Free() {
65 Set(0, 0, 0, 0, false, false);
67 void Set(char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) {
68 delete []s;
69 s = s_;
70 if (s)
71 len = len_;
72 else
73 len = 0;
74 codePage = codePage_;
75 characterSet = characterSet_;
76 rectangular = rectangular_;
77 lineCopy = lineCopy_;
79 void Copy(const char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) {
80 delete []s;
81 s = 0;
82 s = new char[len_];
83 len = len_;
84 for (int i = 0; i < len_; i++) {
85 s[i] = s_[i];
87 codePage = codePage_;
88 characterSet = characterSet_;
89 rectangular = rectangular_;
90 lineCopy = lineCopy_;
92 void Copy(const SelectionText &other) {
93 Copy(other.s, other.len, other.codePage, other.characterSet, other.rectangular, other.lineCopy);
97 /**
99 class Editor : public DocWatcher {
100 // Private so Editor objects can not be copied
101 Editor(const Editor &);
102 Editor &operator=(const Editor &);
104 protected: // ScintillaBase subclass needs access to much of Editor
106 /** On GTK+, Scintilla is a container widget holding two scroll bars
107 * whereas on Windows there is just one window with both scroll bars turned on. */
108 Window wMain; ///< The Scintilla parent window
110 /** Style resources may be expensive to allocate so are cached between uses.
111 * When a style attribute is changed, this cache is flushed. */
112 bool stylesValid;
113 ViewStyle vs;
114 Palette palette;
116 int printMagnification;
117 int printColourMode;
118 int printWrapState;
119 int cursorMode;
120 int controlCharSymbol;
122 bool hasFocus;
123 bool hideSelection;
124 bool inOverstrike;
125 bool mouseDownCaptures;
127 /** In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to
128 * the screen. This avoids flashing but is about 30% slower. */
129 bool bufferedDraw;
130 /** In twoPhaseDraw mode, drawing is performed in two phases, first the background
131 * and then the foreground. This avoids chopping off characters that overlap the next run. */
132 bool twoPhaseDraw;
134 int xOffset; ///< Horizontal scrolled amount in pixels
135 int xCaretMargin; ///< Ensure this many pixels visible on both sides of caret
136 bool horizontalScrollBarVisible;
137 int scrollWidth;
138 bool trackLineWidth;
139 int lineWidthMaxSeen;
140 bool verticalScrollBarVisible;
141 bool endAtLastLine;
142 bool caretSticky;
143 bool multipleSelection;
144 bool additionalSelectionTyping;
145 bool additionalCaretsBlink;
146 bool additionalCaretsVisible;
148 int virtualSpaceOptions;
150 Surface *pixmapLine;
151 Surface *pixmapSelMargin;
152 Surface *pixmapSelPattern;
153 Surface *pixmapIndentGuide;
154 Surface *pixmapIndentGuideHighlight;
156 LineLayoutCache llc;
157 PositionCache posCache;
159 KeyMap kmap;
161 Caret caret;
162 Timer timer;
163 Timer autoScrollTimer;
164 enum { autoScrollDelay = 200 };
166 Idler idler;
168 Point lastClick;
169 unsigned int lastClickTime;
170 int dwellDelay;
171 int ticksToDwell;
172 bool dwelling;
173 enum { selChar, selWord, selLine } selectionType;
174 Point ptMouseLast;
175 enum { ddNone, ddInitial, ddDragging } inDragDrop;
176 bool dropWentOutside;
177 SelectionPosition posDrag;
178 SelectionPosition posDrop;
179 int lastXChosen;
180 int lineAnchor;
181 int originalAnchorPos;
182 int targetStart;
183 int targetEnd;
184 int searchFlags;
185 int topLine;
186 int posTopLine;
187 int lengthForEncode;
189 bool needUpdateUI;
190 Position braces[2];
191 int bracesMatchStyle;
192 int highlightGuideColumn;
194 int theEdge;
196 enum { notPainting, painting, paintAbandoned } paintState;
197 PRectangle rcPaint;
198 bool paintingAllText;
200 int modEventMask;
202 SelectionText drag;
203 Selection sel;
204 bool primarySelection;
206 int caretXPolicy;
207 int caretXSlop; ///< Ensure this many pixels visible on both sides of caret
209 int caretYPolicy;
210 int caretYSlop; ///< Ensure this many lines visible on both sides of caret
212 int visiblePolicy;
213 int visibleSlop;
215 int searchAnchor;
217 bool recordingMacro;
219 int foldFlags;
220 ContractionState cs;
222 // Hotspot support
223 int hsStart;
224 int hsEnd;
226 // Wrapping support
227 enum { eWrapNone, eWrapWord, eWrapChar } wrapState;
228 enum { wrapLineLarge = 0x7ffffff };
229 int wrapWidth;
230 int wrapStart;
231 int wrapEnd;
232 int wrapVisualFlags;
233 int wrapVisualFlagsLocation;
234 int wrapVisualStartIndent;
235 int wrapAddIndent; // This will be added to initial indent of line
236 int wrapIndentMode; // SC_WRAPINDENT_FIXED, _SAME, _INDENT
238 bool convertPastes;
240 Document *pdoc;
242 Editor();
243 virtual ~Editor();
244 virtual void Initialise() = 0;
245 virtual void Finalise();
247 void InvalidateStyleData();
248 void InvalidateStyleRedraw();
249 virtual void RefreshColourPalette(Palette &pal, bool want);
250 void RefreshStyleData();
251 void DropGraphics();
253 virtual PRectangle GetClientRectangle();
254 PRectangle GetTextRectangle();
256 int LinesOnScreen();
257 int LinesToScroll();
258 int MaxScrollPos();
259 SelectionPosition ClampPositionIntoDocument(SelectionPosition sp) const;
260 Point LocationFromPosition(SelectionPosition pos);
261 Point LocationFromPosition(int pos);
262 int XFromPosition(int pos);
263 int XFromPosition(SelectionPosition sp);
264 SelectionPosition SPositionFromLocation(Point pt, bool canReturnInvalid=false, bool charPosition=false, bool virtualSpace=true);
265 int PositionFromLocation(Point pt, bool canReturnInvalid=false, bool charPosition=false);
266 SelectionPosition SPositionFromLineX(int lineDoc, int x);
267 int PositionFromLineX(int line, int x);
268 int LineFromLocation(Point pt);
269 void SetTopLine(int topLineNew);
271 bool AbandonPaint();
272 void RedrawRect(PRectangle rc);
273 void Redraw();
274 void RedrawSelMargin(int line=-1);
275 PRectangle RectangleFromRange(int start, int end);
276 void InvalidateRange(int start, int end);
278 bool UserVirtualSpace() const {
279 return ((virtualSpaceOptions & SCVS_USERACCESSIBLE) != 0);
281 int CurrentPosition();
282 bool SelectionEmpty();
283 SelectionPosition SelectionStart();
284 SelectionPosition SelectionEnd();
285 void SetRectangularRange();
286 void ThinRectangularRange();
287 void InvalidateSelection(SelectionRange newMain, bool invalidateWholeSelection=false);
288 void SetSelection(SelectionPosition currentPos_, SelectionPosition anchor_);
289 void SetSelection(int currentPos_, int anchor_);
290 void SetSelection(SelectionPosition currentPos_);
291 void SetSelection(int currentPos_);
292 void SetEmptySelection(SelectionPosition currentPos_);
293 void SetEmptySelection(int currentPos_);
294 bool RangeContainsProtected(int start, int end) const;
295 bool SelectionContainsProtected();
296 int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true) const;
297 SelectionPosition MovePositionOutsideChar(SelectionPosition pos, int moveDir, bool checkLineEnd=true) const;
298 int MovePositionTo(SelectionPosition newPos, Selection::selTypes sel=Selection::noSel, bool ensureVisible=true);
299 int MovePositionTo(int newPos, Selection::selTypes sel=Selection::noSel, bool ensureVisible=true);
300 SelectionPosition MovePositionSoVisible(SelectionPosition pos, int moveDir);
301 SelectionPosition MovePositionSoVisible(int pos, int moveDir);
302 Point PointMainCaret();
303 void SetLastXChosen();
305 void ScrollTo(int line, bool moveThumb=true);
306 virtual void ScrollText(int linesToMove);
307 void HorizontalScrollTo(int xPos);
308 void MoveCaretInsideView(bool ensureVisible=true);
309 int DisplayFromPosition(int pos);
310 void EnsureCaretVisible(bool useMargin=true, bool vert=true, bool horiz=true);
311 void ShowCaretAtCurrentPosition();
312 void DropCaret();
313 void InvalidateCaret();
314 virtual void UpdateSystemCaret();
316 void NeedWrapping(int docLineStart = 0, int docLineEnd = wrapLineLarge);
317 bool WrapOneLine(Surface *surface, int lineToWrap);
318 bool WrapLines(bool fullWrap, int priorityWrapLineStart);
319 void LinesJoin();
320 void LinesSplit(int pixelWidth);
322 int SubstituteMarkerIfEmpty(int markerCheck, int markerDefault);
323 void PaintSelMargin(Surface *surface, PRectangle &rc);
324 LineLayout *RetrieveLineLayout(int lineNumber);
325 void LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayout *ll,
326 int width=LineLayout::wrapWidthInfinite);
327 ColourAllocated SelectionBackground(ViewStyle &vsDraw, bool main);
328 ColourAllocated TextBackground(ViewStyle &vsDraw, bool overrideBackground, ColourAllocated background, int inSelection, bool inHotspot, int styleMain, int i, LineLayout *ll);
329 void DrawIndentGuide(Surface *surface, int lineVisible, int lineHeight, int start, PRectangle rcSegment, bool highlight);
330 void DrawWrapMarker(Surface *surface, PRectangle rcPlace, bool isEndMarker, ColourAllocated wrapColour);
331 void DrawEOL(Surface *surface, ViewStyle &vsDraw, PRectangle rcLine, LineLayout *ll,
332 int line, int lineEnd, int xStart, int subLine, int subLineStart,
333 bool overrideBackground, ColourAllocated background,
334 bool drawWrapMark, ColourAllocated wrapColour);
335 void DrawIndicators(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
336 PRectangle rcLine, LineLayout *ll, int subLine, int lineEnd, bool under);
337 void DrawAnnotation(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
338 PRectangle rcLine, LineLayout *ll, int subLine);
339 void DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVisible, int xStart,
340 PRectangle rcLine, LineLayout *ll, int subLine);
341 void DrawBlockCaret(Surface *surface, ViewStyle &vsDraw, LineLayout *ll, int subLine,
342 int xStart, int offset, int posCaret, PRectangle rcCaret, ColourAllocated caretColour);
343 void DrawCarets(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
344 PRectangle rcLine, LineLayout *ll, int subLine);
345 void RefreshPixMaps(Surface *surfaceWindow);
346 void Paint(Surface *surfaceWindow, PRectangle rcArea);
347 long FormatRange(bool draw, Sci_RangeToFormat *pfr);
348 int TextWidth(int style, const char *text);
350 virtual void SetVerticalScrollPos() = 0;
351 virtual void SetHorizontalScrollPos() = 0;
352 virtual bool ModifyScrollBars(int nMax, int nPage) = 0;
353 virtual void ReconfigureScrollBars();
354 void SetScrollBars();
355 void ChangeSize();
357 void FilterSelections();
358 int InsertSpace(int position, unsigned int spaces);
359 void AddChar(char ch);
360 virtual void AddCharUTF(char *s, unsigned int len, bool treatAsDBCS=false);
361 void ClearSelection();
362 void ClearAll();
363 void ClearDocumentStyle();
364 void Cut();
365 void PasteRectangular(SelectionPosition pos, const char *ptr, int len);
366 virtual void Copy() = 0;
367 virtual void CopyAllowLine();
368 virtual bool CanPaste();
369 virtual void Paste() = 0;
370 void Clear();
371 void SelectAll();
372 void Undo();
373 void Redo();
374 void DelChar();
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 NotifySavePoint(bool isSavePoint);
385 void NotifyModifyAttempt();
386 virtual void NotifyDoubleClick(Point pt, bool shift, bool ctrl, bool alt);
387 void NotifyHotSpotClicked(int position, bool shift, bool ctrl, bool alt);
388 void NotifyHotSpotDoubleClicked(int position, bool shift, bool ctrl, bool alt);
389 void NotifyUpdateUI();
390 void NotifyPainted();
391 void NotifyIndicatorClick(bool click, int position, bool shift, bool ctrl, bool alt);
392 bool NotifyMarginClick(Point pt, bool shift, bool ctrl, bool alt);
393 void NotifyNeedShown(int pos, int len);
394 void NotifyDwelling(Point pt, bool state);
395 void NotifyZoom();
397 void NotifyModifyAttempt(Document *document, void *userData);
398 void NotifySavePoint(Document *document, void *userData, bool atSavePoint);
399 void CheckModificationForWrap(DocModification mh);
400 void NotifyModified(Document *document, DocModification mh, void *userData);
401 void NotifyDeleted(Document *document, void *userData);
402 void NotifyStyleNeeded(Document *doc, void *userData, int endPos);
403 void NotifyMacroRecord(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
405 void PageMove(int direction, Selection::selTypes sel=Selection::noSel, bool stuttered = false);
406 void ChangeCaseOfSelection(bool makeUpperCase);
407 void LineTranspose();
408 void Duplicate(bool forLine);
409 virtual void CancelModes();
410 void NewLine();
411 void CursorUpOrDown(int direction, Selection::selTypes sel=Selection::noSel);
412 void ParaUpOrDown(int direction, Selection::selTypes sel=Selection::noSel);
413 int StartEndDisplayLine(int pos, bool start);
414 virtual int KeyCommand(unsigned int iMessage);
415 virtual int KeyDefault(int /* key */, int /*modifiers*/);
416 int KeyDown(int key, bool shift, bool ctrl, bool alt, bool *consumed=0);
418 int GetWhitespaceVisible();
419 void SetWhitespaceVisible(int view);
421 void Indent(bool forwards);
423 long FindText(uptr_t wParam, sptr_t lParam);
424 void SearchAnchor();
425 long SearchText(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
426 long SearchInTarget(const char *text, int length);
427 void GoToLine(int lineNo);
429 virtual void CopyToClipboard(const SelectionText &selectedText) = 0;
430 char *CopyRange(int start, int end);
431 void CopySelectionRange(SelectionText *ss, bool allowLineCopy=false);
432 void CopyRangeToClipboard(int start, int end);
433 void CopyText(int length, const char *text);
434 void SetDragPosition(SelectionPosition newPos);
435 virtual void DisplayCursor(Window::Cursor c);
436 virtual bool DragThreshold(Point ptStart, Point ptNow);
437 virtual void StartDrag();
438 void DropAt(SelectionPosition position, const char *value, bool moving, bool rectangular);
439 /** PositionInSelection returns true if position in selection. */
440 bool PositionInSelection(int pos);
441 bool PointInSelection(Point pt);
442 bool PointInSelMargin(Point pt);
443 void LineSelection(int lineCurrent_, int lineAnchor_);
444 void DwellEnd(bool mouseMoved);
445 virtual void ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt);
446 void ButtonMove(Point pt);
447 void ButtonUp(Point pt, unsigned int curTime, bool ctrl);
449 void Tick();
450 bool Idle();
451 virtual void SetTicking(bool on) = 0;
452 virtual bool SetIdle(bool) { return false; }
453 virtual void SetMouseCapture(bool on) = 0;
454 virtual bool HaveMouseCapture() = 0;
455 void SetFocusState(bool focusState);
457 virtual bool PaintContains(PRectangle rc);
458 bool PaintContainsMargin();
459 void CheckForChangeOutsidePaint(Range r);
460 void SetBraceHighlight(Position pos0, Position pos1, int matchStyle);
462 void SetAnnotationHeights(int start, int end);
463 void SetDocPointer(Document *document);
465 void SetAnnotationVisible(int visible);
467 void Expand(int &line, bool doExpand);
468 void ToggleContraction(int line);
469 void EnsureLineVisible(int lineDoc, bool enforcePolicy);
470 int ReplaceTarget(bool replacePatterns, const char *text, int length=-1);
472 bool PositionIsHotspot(int position);
473 bool PointIsHotspot(Point pt);
474 void SetHotSpotRange(Point *pt);
475 void GetHotSpotRange(int& hsStart, int& hsEnd);
477 int CodePage() const;
478 virtual bool ValidCodePage(int /* codePage */) const { return true; }
479 int WrapCount(int line);
480 void AddStyledText(char *buffer, int appendLength);
482 virtual sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) = 0;
483 void StyleSetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
484 sptr_t StyleGetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
486 static const char *StringFromEOLMode(int eolMode);
488 static sptr_t StringResult(sptr_t lParam, const char *val);
490 public:
491 // Public so the COM thunks can access it.
492 bool IsUnicodeMode() const;
493 // Public so scintilla_send_message can use it.
494 virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
495 // Public so scintilla_set_id can use it.
496 int ctrlID;
497 // Public so COM methods for drag and drop can set it.
498 int errorStatus;
499 friend class AutoSurface;
500 friend class SelectionLineIterator;
504 * A smart pointer class to ensure Surfaces are set up and deleted correctly.
506 class AutoSurface {
507 private:
508 Surface *surf;
509 public:
510 AutoSurface(Editor *ed) : surf(0) {
511 if (ed->wMain.GetID()) {
512 surf = Surface::Allocate();
513 if (surf) {
514 surf->Init(ed->wMain.GetID());
515 surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage());
516 surf->SetDBCSMode(ed->CodePage());
520 AutoSurface(SurfaceID sid, Editor *ed) : surf(0) {
521 if (ed->wMain.GetID()) {
522 surf = Surface::Allocate();
523 if (surf) {
524 surf->Init(sid, ed->wMain.GetID());
525 surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage());
526 surf->SetDBCSMode(ed->CodePage());
530 ~AutoSurface() {
531 delete surf;
533 Surface *operator->() const {
534 return surf;
536 operator Surface *() const {
537 return surf;
541 #ifdef SCI_NAMESPACE
543 #endif
545 #endif