scintilla: Update scintilla with changeset 3662:1d1c06df8a2f using gtk+3
[anjuta-extras.git] / plugins / scintilla / scintilla / Editor.h
blob5c01ee83d477917b16b7ec9e80c25fbb640278bd
1 // Scintilla source code edit control
2 /** @file Editor.h
3 ** Defines the main editor class.
4 **/
5 // Copyright 1998-2011 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 * When platform has a way to generate an event before painting,
50 * accumulate needed styling range in StyleNeeded to avoid unnecessary work.
52 class StyleNeeded {
53 public:
54 bool active;
55 Position upTo;
57 StyleNeeded() : active(false), upTo(0) {}
58 void Reset() {
59 active = false;
60 upTo = 0;
62 void NeedUpTo(Position pos) {
63 if (upTo < pos)
64 upTo = pos;
68 /**
69 * Hold a piece of text selected for copying or dragging.
70 * The text is expected to hold a terminating '\0' and this is counted in len.
72 class SelectionText {
73 public:
74 char *s;
75 int len;
76 bool rectangular;
77 bool lineCopy;
78 int codePage;
79 int characterSet;
80 SelectionText() : s(0), len(0), rectangular(false), lineCopy(false), codePage(0), characterSet(0) {}
81 ~SelectionText() {
82 Free();
84 void Free() {
85 Set(0, 0, 0, 0, false, false);
87 void Set(char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) {
88 delete []s;
89 s = s_;
90 if (s)
91 len = len_;
92 else
93 len = 0;
94 codePage = codePage_;
95 characterSet = characterSet_;
96 rectangular = rectangular_;
97 lineCopy = lineCopy_;
99 void Copy(const char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) {
100 delete []s;
101 s = 0;
102 s = new char[len_];
103 len = len_;
104 for (int i = 0; i < len_; i++) {
105 s[i] = s_[i];
107 codePage = codePage_;
108 characterSet = characterSet_;
109 rectangular = rectangular_;
110 lineCopy = lineCopy_;
112 void Copy(const SelectionText &other) {
113 Copy(other.s, other.len, other.codePage, other.characterSet, other.rectangular, other.lineCopy);
119 class Editor : public DocWatcher {
120 // Private so Editor objects can not be copied
121 Editor(const Editor &);
122 Editor &operator=(const Editor &);
124 protected: // ScintillaBase subclass needs access to much of Editor
126 /** On GTK+, Scintilla is a container widget holding two scroll bars
127 * whereas on Windows there is just one window with both scroll bars turned on. */
128 Window wMain; ///< The Scintilla parent window
130 /** Style resources may be expensive to allocate so are cached between uses.
131 * When a style attribute is changed, this cache is flushed. */
132 bool stylesValid;
133 ViewStyle vs;
134 Palette palette;
136 int printMagnification;
137 int printColourMode;
138 int printWrapState;
139 int cursorMode;
140 int controlCharSymbol;
142 // Highlight current folding block
143 HighlightDelimiter highlightDelimiter;
145 bool hasFocus;
146 bool hideSelection;
147 bool inOverstrike;
148 bool mouseDownCaptures;
150 /** In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to
151 * the screen. This avoids flashing but is about 30% slower. */
152 bool bufferedDraw;
153 /** In twoPhaseDraw mode, drawing is performed in two phases, first the background
154 * and then the foreground. This avoids chopping off characters that overlap the next run. */
155 bool twoPhaseDraw;
157 int xOffset; ///< Horizontal scrolled amount in pixels
158 int xCaretMargin; ///< Ensure this many pixels visible on both sides of caret
159 bool horizontalScrollBarVisible;
160 int scrollWidth;
161 bool trackLineWidth;
162 int lineWidthMaxSeen;
163 bool verticalScrollBarVisible;
164 bool endAtLastLine;
165 int caretSticky;
166 bool multipleSelection;
167 bool additionalSelectionTyping;
168 int multiPasteMode;
169 bool additionalCaretsBlink;
170 bool additionalCaretsVisible;
172 int virtualSpaceOptions;
174 Surface *pixmapLine;
175 Surface *pixmapSelMargin;
176 Surface *pixmapSelPattern;
177 Surface *pixmapIndentGuide;
178 Surface *pixmapIndentGuideHighlight;
180 LineLayoutCache llc;
181 PositionCache posCache;
183 KeyMap kmap;
185 Caret caret;
186 Timer timer;
187 Timer autoScrollTimer;
188 enum { autoScrollDelay = 200 };
190 Idler idler;
192 Point lastClick;
193 unsigned int lastClickTime;
194 int dwellDelay;
195 int ticksToDwell;
196 bool dwelling;
197 enum { selChar, selWord, selLine } selectionType;
198 Point ptMouseLast;
199 enum { ddNone, ddInitial, ddDragging } inDragDrop;
200 bool dropWentOutside;
201 SelectionPosition posDrag;
202 SelectionPosition posDrop;
203 int hotSpotClickPos;
204 int lastXChosen;
205 int lineAnchor;
206 int originalAnchorPos;
207 int wordSelectAnchorStartPos;
208 int wordSelectAnchorEndPos;
209 int wordSelectInitialCaretPos;
210 int targetStart;
211 int targetEnd;
212 int searchFlags;
213 int topLine;
214 int posTopLine;
215 int lengthForEncode;
217 int needUpdateUI;
218 Position braces[2];
219 int bracesMatchStyle;
220 int highlightGuideColumn;
222 int theEdge;
224 enum { notPainting, painting, paintAbandoned } paintState;
225 PRectangle rcPaint;
226 bool paintingAllText;
227 StyleNeeded styleNeeded;
229 int modEventMask;
231 SelectionText drag;
232 Selection sel;
233 bool primarySelection;
235 int caretXPolicy;
236 int caretXSlop; ///< Ensure this many pixels visible on both sides of caret
238 int caretYPolicy;
239 int caretYSlop; ///< Ensure this many lines visible on both sides of caret
241 int visiblePolicy;
242 int visibleSlop;
244 int searchAnchor;
246 bool recordingMacro;
248 int foldFlags;
249 ContractionState cs;
251 // Hotspot support
252 int hsStart;
253 int hsEnd;
255 // Wrapping support
256 enum { eWrapNone, eWrapWord, eWrapChar } wrapState;
257 enum { wrapLineLarge = 0x7ffffff };
258 int wrapWidth;
259 int wrapStart;
260 int wrapEnd;
261 int wrapVisualFlags;
262 int wrapVisualFlagsLocation;
263 int wrapVisualStartIndent;
264 int wrapAddIndent; // This will be added to initial indent of line
265 int wrapIndentMode; // SC_WRAPINDENT_FIXED, _SAME, _INDENT
267 bool convertPastes;
269 Document *pdoc;
271 Editor();
272 virtual ~Editor();
273 virtual void Initialise() = 0;
274 virtual void Finalise();
276 void InvalidateStyleData();
277 void InvalidateStyleRedraw();
278 virtual void RefreshColourPalette(Palette &pal, bool want);
279 void RefreshStyleData();
280 void DropGraphics();
282 virtual PRectangle GetClientRectangle();
283 PRectangle GetTextRectangle();
285 int LinesOnScreen();
286 int LinesToScroll();
287 int MaxScrollPos();
288 SelectionPosition ClampPositionIntoDocument(SelectionPosition sp) const;
289 Point LocationFromPosition(SelectionPosition pos);
290 Point LocationFromPosition(int pos);
291 int XFromPosition(int pos);
292 int XFromPosition(SelectionPosition sp);
293 SelectionPosition SPositionFromLocation(Point pt, bool canReturnInvalid=false, bool charPosition=false, bool virtualSpace=true);
294 int PositionFromLocation(Point pt, bool canReturnInvalid=false, bool charPosition=false);
295 SelectionPosition SPositionFromLineX(int lineDoc, int x);
296 int PositionFromLineX(int line, int x);
297 int LineFromLocation(Point pt);
298 void SetTopLine(int topLineNew);
300 bool AbandonPaint();
301 void RedrawRect(PRectangle rc);
302 void Redraw();
303 void RedrawSelMargin(int line=-1, bool allAfter=false);
304 PRectangle RectangleFromRange(int start, int end);
305 void InvalidateRange(int start, int end);
307 bool UserVirtualSpace() const {
308 return ((virtualSpaceOptions & SCVS_USERACCESSIBLE) != 0);
310 int CurrentPosition();
311 bool SelectionEmpty();
312 SelectionPosition SelectionStart();
313 SelectionPosition SelectionEnd();
314 void SetRectangularRange();
315 void ThinRectangularRange();
316 void InvalidateSelection(SelectionRange newMain, bool invalidateWholeSelection=false);
317 void SetSelection(SelectionPosition currentPos_, SelectionPosition anchor_);
318 void SetSelection(int currentPos_, int anchor_);
319 void SetSelection(SelectionPosition currentPos_);
320 void SetSelection(int currentPos_);
321 void SetEmptySelection(SelectionPosition currentPos_);
322 void SetEmptySelection(int currentPos_);
323 bool RangeContainsProtected(int start, int end) const;
324 bool SelectionContainsProtected();
325 int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true) const;
326 SelectionPosition MovePositionOutsideChar(SelectionPosition pos, int moveDir, bool checkLineEnd=true) const;
327 int MovePositionTo(SelectionPosition newPos, Selection::selTypes sel=Selection::noSel, bool ensureVisible=true);
328 int MovePositionTo(int newPos, Selection::selTypes sel=Selection::noSel, bool ensureVisible=true);
329 SelectionPosition MovePositionSoVisible(SelectionPosition pos, int moveDir);
330 SelectionPosition MovePositionSoVisible(int pos, int moveDir);
331 Point PointMainCaret();
332 void SetLastXChosen();
334 void ScrollTo(int line, bool moveThumb=true);
335 virtual void ScrollText(int linesToMove);
336 void HorizontalScrollTo(int xPos);
337 void VerticalCentreCaret();
338 void MoveSelectedLines(int lineDelta);
339 void MoveSelectedLinesUp();
340 void MoveSelectedLinesDown();
341 void MoveCaretInsideView(bool ensureVisible=true);
342 int DisplayFromPosition(int pos);
344 struct XYScrollPosition {
345 int xOffset;
346 int topLine;
347 XYScrollPosition(int xOffset_, int topLine_) : xOffset(xOffset_), topLine(topLine_) {}
349 XYScrollPosition XYScrollToMakeVisible(const bool useMargin, const bool vert, const bool horiz);
350 void SetXYScroll(XYScrollPosition newXY);
351 void EnsureCaretVisible(bool useMargin=true, bool vert=true, bool horiz=true);
352 void ShowCaretAtCurrentPosition();
353 void DropCaret();
354 void InvalidateCaret();
355 virtual void UpdateSystemCaret();
357 void NeedWrapping(int docLineStart = 0, int docLineEnd = wrapLineLarge);
358 bool WrapOneLine(Surface *surface, int lineToWrap);
359 bool WrapLines(bool fullWrap, int priorityWrapLineStart);
360 void LinesJoin();
361 void LinesSplit(int pixelWidth);
363 int SubstituteMarkerIfEmpty(int markerCheck, int markerDefault);
364 void PaintSelMargin(Surface *surface, PRectangle &rc);
365 LineLayout *RetrieveLineLayout(int lineNumber);
366 void LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayout *ll,
367 int width=LineLayout::wrapWidthInfinite);
368 ColourAllocated SelectionBackground(ViewStyle &vsDraw, bool main);
369 ColourAllocated TextBackground(ViewStyle &vsDraw, bool overrideBackground, ColourAllocated background, int inSelection, bool inHotspot, int styleMain, int i, LineLayout *ll);
370 void DrawIndentGuide(Surface *surface, int lineVisible, int lineHeight, int start, PRectangle rcSegment, bool highlight);
371 void DrawWrapMarker(Surface *surface, PRectangle rcPlace, bool isEndMarker, ColourAllocated wrapColour);
372 void DrawEOL(Surface *surface, ViewStyle &vsDraw, PRectangle rcLine, LineLayout *ll,
373 int line, int lineEnd, int xStart, int subLine, int subLineStart,
374 bool overrideBackground, ColourAllocated background,
375 bool drawWrapMark, ColourAllocated wrapColour);
376 void DrawIndicator(int indicNum, int startPos, int endPos, Surface *surface, ViewStyle &vsDraw,
377 int xStart, PRectangle rcLine, LineLayout *ll, int subLine);
378 void DrawIndicators(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
379 PRectangle rcLine, LineLayout *ll, int subLine, int lineEnd, bool under);
380 void DrawAnnotation(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
381 PRectangle rcLine, LineLayout *ll, int subLine);
382 void DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVisible, int xStart,
383 PRectangle rcLine, LineLayout *ll, int subLine);
384 void DrawBlockCaret(Surface *surface, ViewStyle &vsDraw, LineLayout *ll, int subLine,
385 int xStart, int offset, int posCaret, PRectangle rcCaret, ColourAllocated caretColour);
386 void DrawCarets(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
387 PRectangle rcLine, LineLayout *ll, int subLine);
388 void RefreshPixMaps(Surface *surfaceWindow);
389 void Paint(Surface *surfaceWindow, PRectangle rcArea);
390 long FormatRange(bool draw, Sci_RangeToFormat *pfr);
391 int TextWidth(int style, const char *text);
393 virtual void SetVerticalScrollPos() = 0;
394 virtual void SetHorizontalScrollPos() = 0;
395 virtual bool ModifyScrollBars(int nMax, int nPage) = 0;
396 virtual void ReconfigureScrollBars();
397 void SetScrollBars();
398 void ChangeSize();
400 void FilterSelections();
401 int InsertSpace(int position, unsigned int spaces);
402 void AddChar(char ch);
403 virtual void AddCharUTF(char *s, unsigned int len, bool treatAsDBCS=false);
404 void InsertPaste(SelectionPosition selStart, const char *text, int len);
405 void ClearSelection(bool retainMultipleSelections=false);
406 void ClearAll();
407 void ClearDocumentStyle();
408 void Cut();
409 void PasteRectangular(SelectionPosition pos, const char *ptr, int len);
410 virtual void Copy() = 0;
411 virtual void CopyAllowLine();
412 virtual bool CanPaste();
413 virtual void Paste() = 0;
414 void Clear();
415 void SelectAll();
416 void Undo();
417 void Redo();
418 void DelChar();
419 void DelCharBack(bool allowLineStartDeletion);
420 virtual void ClaimSelection() = 0;
422 virtual void NotifyChange() = 0;
423 virtual void NotifyFocus(bool focus);
424 virtual int GetCtrlID() { return ctrlID; }
425 virtual void NotifyParent(SCNotification scn) = 0;
426 virtual void NotifyStyleToNeeded(int endStyleNeeded);
427 void NotifyChar(int ch);
428 void NotifySavePoint(bool isSavePoint);
429 void NotifyModifyAttempt();
430 virtual void NotifyDoubleClick(Point pt, bool shift, bool ctrl, bool alt);
431 void NotifyHotSpotClicked(int position, bool shift, bool ctrl, bool alt);
432 void NotifyHotSpotDoubleClicked(int position, bool shift, bool ctrl, bool alt);
433 void NotifyHotSpotReleaseClick(int position, bool shift, bool ctrl, bool alt);
434 void NotifyUpdateUI();
435 void NotifyPainted();
436 void NotifyIndicatorClick(bool click, int position, bool shift, bool ctrl, bool alt);
437 bool NotifyMarginClick(Point pt, bool shift, bool ctrl, bool alt);
438 void NotifyNeedShown(int pos, int len);
439 void NotifyDwelling(Point pt, bool state);
440 void NotifyZoom();
442 void NotifyModifyAttempt(Document *document, void *userData);
443 void NotifySavePoint(Document *document, void *userData, bool atSavePoint);
444 void CheckModificationForWrap(DocModification mh);
445 void NotifyModified(Document *document, DocModification mh, void *userData);
446 void NotifyDeleted(Document *document, void *userData);
447 void NotifyStyleNeeded(Document *doc, void *userData, int endPos);
448 void NotifyLexerChanged(Document *doc, void *userData);
449 void NotifyErrorOccurred(Document *doc, void *userData, int status);
450 void NotifyMacroRecord(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
452 void ContainerNeedsUpdate(int flags);
453 void PageMove(int direction, Selection::selTypes sel=Selection::noSel, bool stuttered = false);
454 enum { cmSame, cmUpper, cmLower } caseMap;
455 virtual std::string CaseMapString(const std::string &s, int caseMapping);
456 void ChangeCaseOfSelection(int caseMapping);
457 void LineTranspose();
458 void Duplicate(bool forLine);
459 virtual void CancelModes();
460 void NewLine();
461 void CursorUpOrDown(int direction, Selection::selTypes sel=Selection::noSel);
462 void ParaUpOrDown(int direction, Selection::selTypes sel=Selection::noSel);
463 int StartEndDisplayLine(int pos, bool start);
464 virtual int KeyCommand(unsigned int iMessage);
465 virtual int KeyDefault(int /* key */, int /*modifiers*/);
466 int KeyDown(int key, bool shift, bool ctrl, bool alt, bool *consumed=0);
468 int GetWhitespaceVisible();
469 void SetWhitespaceVisible(int view);
471 void Indent(bool forwards);
473 virtual CaseFolder *CaseFolderForEncoding();
474 long FindText(uptr_t wParam, sptr_t lParam);
475 void SearchAnchor();
476 long SearchText(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
477 long SearchInTarget(const char *text, int length);
478 void GoToLine(int lineNo);
480 virtual void CopyToClipboard(const SelectionText &selectedText) = 0;
481 char *CopyRange(int start, int end);
482 void CopySelectionRange(SelectionText *ss, bool allowLineCopy=false);
483 void CopyRangeToClipboard(int start, int end);
484 void CopyText(int length, const char *text);
485 void SetDragPosition(SelectionPosition newPos);
486 virtual void DisplayCursor(Window::Cursor c);
487 virtual bool DragThreshold(Point ptStart, Point ptNow);
488 virtual void StartDrag();
489 void DropAt(SelectionPosition position, const char *value, bool moving, bool rectangular);
490 /** PositionInSelection returns true if position in selection. */
491 bool PositionInSelection(int pos);
492 bool PointInSelection(Point pt);
493 bool PointInSelMargin(Point pt);
494 Window::Cursor GetMarginCursor(Point pt);
495 void LineSelection(int lineCurrent_, int lineAnchor_);
496 void WordSelection(int pos);
497 void DwellEnd(bool mouseMoved);
498 void MouseLeave();
499 virtual void ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt);
500 void ButtonMove(Point pt);
501 void ButtonUp(Point pt, unsigned int curTime, bool ctrl);
503 void Tick();
504 bool Idle();
505 virtual void SetTicking(bool on) = 0;
506 virtual bool SetIdle(bool) { return false; }
507 virtual void SetMouseCapture(bool on) = 0;
508 virtual bool HaveMouseCapture() = 0;
509 void SetFocusState(bool focusState);
511 int PositionAfterArea(PRectangle rcArea);
512 void StyleToPositionInView(Position pos);
513 void IdleStyling();
514 virtual void QueueStyling(int upTo);
516 virtual bool PaintContains(PRectangle rc);
517 bool PaintContainsMargin();
518 void CheckForChangeOutsidePaint(Range r);
519 void SetBraceHighlight(Position pos0, Position pos1, int matchStyle);
521 void SetAnnotationHeights(int start, int end);
522 void SetDocPointer(Document *document);
524 void SetAnnotationVisible(int visible);
526 void Expand(int &line, bool doExpand);
527 void ToggleContraction(int line);
528 int ContractedFoldNext(int lineStart);
529 void EnsureLineVisible(int lineDoc, bool enforcePolicy);
530 int GetTag(char *tagValue, int tagNumber);
531 int ReplaceTarget(bool replacePatterns, const char *text, int length=-1);
533 bool PositionIsHotspot(int position);
534 bool PointIsHotspot(Point pt);
535 void SetHotSpotRange(Point *pt);
536 void GetHotSpotRange(int &hsStart, int &hsEnd);
538 int CodePage() const;
539 virtual bool ValidCodePage(int /* codePage */) const { return true; }
540 int WrapCount(int line);
541 void AddStyledText(char *buffer, int appendLength);
543 virtual sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) = 0;
544 void StyleSetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
545 sptr_t StyleGetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
547 static const char *StringFromEOLMode(int eolMode);
549 static sptr_t StringResult(sptr_t lParam, const char *val);
551 public:
552 // Public so the COM thunks can access it.
553 bool IsUnicodeMode() const;
554 // Public so scintilla_send_message can use it.
555 virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
556 // Public so scintilla_set_id can use it.
557 int ctrlID;
558 // Public so COM methods for drag and drop can set it.
559 int errorStatus;
560 friend class AutoSurface;
561 friend class SelectionLineIterator;
565 * A smart pointer class to ensure Surfaces are set up and deleted correctly.
567 class AutoSurface {
568 private:
569 Surface *surf;
570 public:
571 AutoSurface(Editor *ed) : surf(0) {
572 if (ed->wMain.GetID()) {
573 surf = Surface::Allocate();
574 if (surf) {
575 surf->Init(ed->wMain.GetID());
576 surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage());
577 surf->SetDBCSMode(ed->CodePage());
581 AutoSurface(SurfaceID sid, Editor *ed) : surf(0) {
582 if (ed->wMain.GetID()) {
583 surf = Surface::Allocate();
584 if (surf) {
585 surf->Init(sid, ed->wMain.GetID());
586 surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage());
587 surf->SetDBCSMode(ed->CodePage());
591 ~AutoSurface() {
592 delete surf;
594 Surface *operator->() const {
595 return surf;
597 operator Surface *() const {
598 return surf;
602 #ifdef SCI_NAMESPACE
604 #endif
606 #endif