--- /dev/null
+// Scintilla source code edit control\r
+/** @file Editor.h\r
+ ** Defines the main editor class.\r
+ **/\r
+// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>\r
+// The License.txt file describes the conditions under which this software may be distributed.\r
+\r
+#ifndef EDITOR_H\r
+#define EDITOR_H\r
+\r
+#ifdef SCI_NAMESPACE\r
+namespace Scintilla {\r
+#endif\r
+\r
+/**\r
+ */\r
+class Caret {\r
+public:\r
+ bool active;\r
+ bool on;\r
+ int period;\r
+\r
+ Caret();\r
+};\r
+\r
+/**\r
+ */\r
+class Timer {\r
+public:\r
+ bool ticking;\r
+ int ticksToWait;\r
+ enum {tickSize = 100};\r
+ TickerID tickerID;\r
+\r
+ Timer();\r
+};\r
+\r
+/**\r
+ */\r
+class Idler {\r
+public:\r
+ bool state;\r
+ IdlerID idlerID;\r
+\r
+ Idler();\r
+};\r
+\r
+/**\r
+ * Hold a piece of text selected for copying or dragging.\r
+ * The text is expected to hold a terminating '\0' and this is counted in len.\r
+ */\r
+class SelectionText {\r
+public:\r
+ char *s;\r
+ int len;\r
+ bool rectangular;\r
+ bool lineCopy;\r
+ int codePage;\r
+ int characterSet;\r
+ SelectionText() : s(0), len(0), rectangular(false), lineCopy(false), codePage(0), characterSet(0) {}\r
+ ~SelectionText() {\r
+ Free();\r
+ }\r
+ void Free() {\r
+ Set(0, 0, 0, 0, false, false);\r
+ }\r
+ void Set(char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) {\r
+ delete []s;\r
+ s = s_;\r
+ if (s)\r
+ len = len_;\r
+ else\r
+ len = 0;\r
+ codePage = codePage_;\r
+ characterSet = characterSet_;\r
+ rectangular = rectangular_;\r
+ lineCopy = lineCopy_;\r
+ }\r
+ void Copy(const char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) {\r
+ delete []s;\r
+ s = new char[len_];\r
+ if (s) {\r
+ len = len_;\r
+ for (int i = 0; i < len_; i++) {\r
+ s[i] = s_[i];\r
+ }\r
+ } else {\r
+ len = 0;\r
+ }\r
+ codePage = codePage_;\r
+ characterSet = characterSet_;\r
+ rectangular = rectangular_;\r
+ lineCopy = lineCopy_;\r
+ }\r
+ void Copy(const SelectionText &other) {\r
+ Copy(other.s, other.len, other.codePage, other.characterSet, other.rectangular, other.lineCopy);\r
+ }\r
+};\r
+\r
+/**\r
+ */\r
+class Editor : public DocWatcher {\r
+ // Private so Editor objects can not be copied\r
+ Editor(const Editor &) : DocWatcher() {}\r
+ Editor &operator=(const Editor &) { return *this; }\r
+\r
+protected: // ScintillaBase subclass needs access to much of Editor\r
+\r
+ /** On GTK+, Scintilla is a container widget holding two scroll bars\r
+ * whereas on Windows there is just one window with both scroll bars turned on. */\r
+ Window wMain; ///< The Scintilla parent window\r
+\r
+ /** Style resources may be expensive to allocate so are cached between uses.\r
+ * When a style attribute is changed, this cache is flushed. */\r
+ bool stylesValid;\r
+ ViewStyle vs;\r
+ Palette palette;\r
+\r
+ int printMagnification;\r
+ int printColourMode;\r
+ int printWrapState;\r
+ int cursorMode;\r
+ int controlCharSymbol;\r
+\r
+ bool hasFocus;\r
+ bool hideSelection;\r
+ bool inOverstrike;\r
+ int errorStatus;\r
+ bool mouseDownCaptures;\r
+\r
+ /** In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to\r
+ * the screen. This avoids flashing but is about 30% slower. */\r
+ bool bufferedDraw;\r
+ /** In twoPhaseDraw mode, drawing is performed in two phases, first the background\r
+ * and then the foreground. This avoids chopping off characters that overlap the next run. */\r
+ bool twoPhaseDraw;\r
+\r
+ int xOffset; ///< Horizontal scrolled amount in pixels\r
+ int xCaretMargin; ///< Ensure this many pixels visible on both sides of caret\r
+ bool horizontalScrollBarVisible;\r
+ int scrollWidth;\r
+ bool trackLineWidth;\r
+ int lineWidthMaxSeen;\r
+ bool verticalScrollBarVisible;\r
+ bool endAtLastLine;\r
+ bool caretSticky;\r
+\r
+ Surface *pixmapLine;\r
+ Surface *pixmapSelMargin;\r
+ Surface *pixmapSelPattern;\r
+ Surface *pixmapIndentGuide;\r
+ Surface *pixmapIndentGuideHighlight;\r
+\r
+ LineLayoutCache llc;\r
+ PositionCache posCache;\r
+\r
+ KeyMap kmap;\r
+\r
+ Caret caret;\r
+ Timer timer;\r
+ Timer autoScrollTimer;\r
+ enum { autoScrollDelay = 200 };\r
+\r
+ Idler idler;\r
+\r
+ Point lastClick;\r
+ unsigned int lastClickTime;\r
+ int dwellDelay;\r
+ int ticksToDwell;\r
+ bool dwelling;\r
+ enum { selChar, selWord, selLine } selectionType;\r
+ Point ptMouseLast;\r
+ enum { ddNone, ddInitial, ddDragging } inDragDrop;\r
+ bool dropWentOutside;\r
+ int posDrag;\r
+ int posDrop;\r
+ int lastXChosen;\r
+ int lineAnchor;\r
+ int originalAnchorPos;\r
+ int currentPos;\r
+ int anchor;\r
+ int targetStart;\r
+ int targetEnd;\r
+ int searchFlags;\r
+ int topLine;\r
+ int posTopLine;\r
+ int lengthForEncode;\r
+\r
+ bool needUpdateUI;\r
+ Position braces[2];\r
+ int bracesMatchStyle;\r
+ int highlightGuideColumn;\r
+\r
+ int theEdge;\r
+\r
+ enum { notPainting, painting, paintAbandoned } paintState;\r
+ PRectangle rcPaint;\r
+ bool paintingAllText;\r
+\r
+ int modEventMask;\r
+\r
+ SelectionText drag;\r
+ enum selTypes { noSel, selStream, selRectangle, selLines };\r
+ selTypes selType;\r
+ bool moveExtendsSelection;\r
+ int xStartSelect; ///< x position of start of rectangular selection\r
+ int xEndSelect; ///< x position of end of rectangular selection\r
+ bool primarySelection;\r
+\r
+ int caretXPolicy;\r
+ int caretXSlop; ///< Ensure this many pixels visible on both sides of caret\r
+\r
+ int caretYPolicy;\r
+ int caretYSlop; ///< Ensure this many lines visible on both sides of caret\r
+\r
+ int visiblePolicy;\r
+ int visibleSlop;\r
+\r
+ int searchAnchor;\r
+\r
+ bool recordingMacro;\r
+\r
+ int foldFlags;\r
+ ContractionState cs;\r
+\r
+ // Hotspot support\r
+ int hsStart;\r
+ int hsEnd;\r
+\r
+ // Wrapping support\r
+ enum { eWrapNone, eWrapWord, eWrapChar } wrapState;\r
+ enum { wrapLineLarge = 0x7ffffff };\r
+ int wrapWidth;\r
+ int wrapStart;\r
+ int wrapEnd;\r
+ int wrapVisualFlags;\r
+ int wrapVisualFlagsLocation;\r
+ int wrapVisualStartIndent;\r
+ int actualWrapVisualStartIndent;\r
+\r
+ bool convertPastes;\r
+\r
+ Document *pdoc;\r
+\r
+ Editor();\r
+ virtual ~Editor();\r
+ virtual void Initialise() = 0;\r
+ virtual void Finalise();\r
+\r
+ void InvalidateStyleData();\r
+ void InvalidateStyleRedraw();\r
+ virtual void RefreshColourPalette(Palette &pal, bool want);\r
+ void RefreshStyleData();\r
+ void DropGraphics();\r
+\r
+ virtual PRectangle GetClientRectangle();\r
+ PRectangle GetTextRectangle();\r
+\r
+ int LinesOnScreen();\r
+ int LinesToScroll();\r
+ int MaxScrollPos();\r
+ Point LocationFromPosition(int pos);\r
+ int XFromPosition(int pos);\r
+ int PositionFromLocation(Point pt);\r
+ int PositionFromLocationClose(Point pt);\r
+ int PositionFromLineX(int line, int x);\r
+ int LineFromLocation(Point pt);\r
+ void SetTopLine(int topLineNew);\r
+\r
+ bool AbandonPaint();\r
+ void RedrawRect(PRectangle rc);\r
+ void Redraw();\r
+ void RedrawSelMargin(int line=-1);\r
+ PRectangle RectangleFromRange(int start, int end);\r
+ void InvalidateRange(int start, int end);\r
+\r
+ int CurrentPosition();\r
+ bool SelectionEmpty();\r
+ int SelectionStart();\r
+ int SelectionEnd();\r
+ void SetRectangularRange();\r
+ void InvalidateSelection(int currentPos_, int anchor_, bool invalidateWholeSelection);\r
+ void SetSelection(int currentPos_, int anchor_);\r
+ void SetSelection(int currentPos_);\r
+ void SetEmptySelection(int currentPos_);\r
+ bool RangeContainsProtected(int start, int end) const;\r
+ bool SelectionContainsProtected();\r
+ int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true);\r
+ int MovePositionTo(int newPos, selTypes sel=noSel, bool ensureVisible=true);\r
+ int MovePositionSoVisible(int pos, int moveDir);\r
+ void SetLastXChosen();\r
+\r
+ void ScrollTo(int line, bool moveThumb=true);\r
+ virtual void ScrollText(int linesToMove);\r
+ void HorizontalScrollTo(int xPos);\r
+ void MoveCaretInsideView(bool ensureVisible=true);\r
+ int DisplayFromPosition(int pos);\r
+ void EnsureCaretVisible(bool useMargin=true, bool vert=true, bool horiz=true);\r
+ void ShowCaretAtCurrentPosition();\r
+ void DropCaret();\r
+ void InvalidateCaret();\r
+ virtual void UpdateSystemCaret();\r
+\r
+ void NeedWrapping(int docLineStart = 0, int docLineEnd = wrapLineLarge);\r
+ bool WrapOneLine(Surface *surface, int lineToWrap);\r
+ bool WrapLines(bool fullWrap, int priorityWrapLineStart);\r
+ void LinesJoin();\r
+ void LinesSplit(int pixelWidth);\r
+\r
+ int SubstituteMarkerIfEmpty(int markerCheck, int markerDefault);\r
+ void PaintSelMargin(Surface *surface, PRectangle &rc);\r
+ LineLayout *RetrieveLineLayout(int lineNumber);\r
+ void LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayout *ll,\r
+ int width=LineLayout::wrapWidthInfinite);\r
+ ColourAllocated SelectionBackground(ViewStyle &vsDraw);\r
+ ColourAllocated TextBackground(ViewStyle &vsDraw, bool overrideBackground, ColourAllocated background, bool inSelection, bool inHotspot, int styleMain, int i, LineLayout *ll);\r
+ void DrawIndentGuide(Surface *surface, int lineVisible, int lineHeight, int start, PRectangle rcSegment, bool highlight);\r
+ void DrawWrapMarker(Surface *surface, PRectangle rcPlace, bool isEndMarker, ColourAllocated wrapColour);\r
+ void DrawEOL(Surface *surface, ViewStyle &vsDraw, PRectangle rcLine, LineLayout *ll,\r
+ int line, int lineEnd, int xStart, int subLine, int subLineStart,\r
+ bool overrideBackground, ColourAllocated background,\r
+ bool drawWrapMark, ColourAllocated wrapColour);\r
+ void DrawIndicators(Surface *surface, ViewStyle &vsDraw, int line, int xStart,\r
+ PRectangle rcLine, LineLayout *ll, int subLine, int lineEnd, bool under);\r
+ void DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVisible, int xStart,\r
+ PRectangle rcLine, LineLayout *ll, int subLine=0);\r
+ void DrawBlockCaret(Surface *surface, ViewStyle &vsDraw, LineLayout *ll, int subLine, int xStart, int offset, int posCaret, PRectangle rcCaret);\r
+ void RefreshPixMaps(Surface *surfaceWindow);\r
+ void Paint(Surface *surfaceWindow, PRectangle rcArea);\r
+ long FormatRange(bool draw, RangeToFormat *pfr);\r
+ int TextWidth(int style, const char *text);\r
+\r
+ virtual void SetVerticalScrollPos() = 0;\r
+ virtual void SetHorizontalScrollPos() = 0;\r
+ virtual bool ModifyScrollBars(int nMax, int nPage) = 0;\r
+ virtual void ReconfigureScrollBars();\r
+ void SetScrollBars();\r
+ void ChangeSize();\r
+\r
+ void AddChar(char ch);\r
+ virtual void AddCharUTF(char *s, unsigned int len, bool treatAsDBCS=false);\r
+ void ClearSelection();\r
+ void ClearAll();\r
+ void ClearDocumentStyle();\r
+ void Cut();\r
+ void PasteRectangular(int pos, const char *ptr, int len);\r
+ virtual void Copy() = 0;\r
+ virtual void CopyAllowLine();\r
+ virtual bool CanPaste();\r
+ virtual void Paste() = 0;\r
+ void Clear();\r
+ void SelectAll();\r
+ void Undo();\r
+ void Redo();\r
+ void DelChar();\r
+ void DelCharBack(bool allowLineStartDeletion);\r
+ virtual void ClaimSelection() = 0;\r
+\r
+ virtual void NotifyChange() = 0;\r
+ virtual void NotifyFocus(bool focus);\r
+ virtual int GetCtrlID() { return ctrlID; }\r
+ virtual void NotifyParent(SCNotification scn) = 0;\r
+ virtual void NotifyParent(SCNotification * scn) = 0;\r
+ virtual void NotifyStyleToNeeded(int endStyleNeeded);\r
+ void NotifyChar(int ch);\r
+ void NotifyMove(int position);\r
+ void NotifySavePoint(bool isSavePoint);\r
+ void NotifyModifyAttempt();\r
+ virtual void NotifyDoubleClick(Point pt, bool shift, bool ctrl, bool alt);\r
+ void NotifyHotSpotClicked(int position, bool shift, bool ctrl, bool alt);\r
+ void NotifyHotSpotDoubleClicked(int position, bool shift, bool ctrl, bool alt);\r
+ void NotifyUpdateUI();\r
+ void NotifyPainted();\r
+ void NotifyIndicatorClick(bool click, int position, bool shift, bool ctrl, bool alt);\r
+ bool NotifyMarginClick(Point pt, bool shift, bool ctrl, bool alt);\r
+ void NotifyNeedShown(int pos, int len);\r
+ void NotifyDwelling(Point pt, bool state);\r
+ void NotifyZoom();\r
+\r
+ void NotifyModifyAttempt(Document *document, void *userData);\r
+ void NotifySavePoint(Document *document, void *userData, bool atSavePoint);\r
+ void CheckModificationForWrap(DocModification mh);\r
+ void NotifyModified(Document *document, DocModification mh, void *userData);\r
+ void NotifyDeleted(Document *document, void *userData);\r
+ void NotifyStyleNeeded(Document *doc, void *userData, int endPos);\r
+ void NotifyMacroRecord(unsigned int iMessage, uptr_t wParam, sptr_t lParam);\r
+\r
+ void PageMove(int direction, selTypes sel=noSel, bool stuttered = false);\r
+ void ChangeCaseOfSelection(bool makeUpperCase);\r
+ void LineTranspose();\r
+ void Duplicate(bool forLine);\r
+ virtual void CancelModes();\r
+ void NewLine();\r
+ void CursorUpOrDown(int direction, selTypes sel=noSel);\r
+ void ParaUpOrDown(int direction, selTypes sel=noSel);\r
+ int StartEndDisplayLine(int pos, bool start);\r
+ virtual int KeyCommand(unsigned int iMessage);\r
+ virtual int KeyDefault(int /* key */, int /*modifiers*/);\r
+ int KeyDown(int key, bool shift, bool ctrl, bool alt, bool *consumed=0);\r
+\r
+ int GetWhitespaceVisible();\r
+ void SetWhitespaceVisible(int view);\r
+\r
+ void Indent(bool forwards);\r
+\r
+ long FindText(uptr_t wParam, sptr_t lParam);\r
+ void SearchAnchor();\r
+ long SearchText(unsigned int iMessage, uptr_t wParam, sptr_t lParam);\r
+ long SearchInTarget(const char *text, int length);\r
+ void GoToLine(int lineNo);\r
+\r
+ virtual void CopyToClipboard(const SelectionText &selectedText) = 0;\r
+ char *CopyRange(int start, int end);\r
+ void CopySelectionFromRange(SelectionText *ss, bool allowLineCopy, int start, int end);\r
+ void CopySelectionRange(SelectionText *ss, bool allowLineCopy=false);\r
+ void CopyRangeToClipboard(int start, int end);\r
+ void CopyText(int length, const char *text);\r
+ void SetDragPosition(int newPos);\r
+ virtual void DisplayCursor(Window::Cursor c);\r
+ virtual bool DragThreshold(Point ptStart, Point ptNow);\r
+ virtual void StartDrag();\r
+ void DropAt(int position, const char *value, bool moving, bool rectangular);\r
+ /** PositionInSelection returns 0 if position in selection, -1 if position before selection, and 1 if after.\r
+ * Before means either before any line of selection or before selection on its line, with a similar meaning to after. */\r
+ int PositionInSelection(int pos);\r
+ bool PointInSelection(Point pt);\r
+ bool PointInSelMargin(Point pt);\r
+ void LineSelection(int lineCurrent_, int lineAnchor_);\r
+ void DwellEnd(bool mouseMoved);\r
+ virtual void ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt);\r
+ void ButtonMove(Point pt);\r
+ void ButtonUp(Point pt, unsigned int curTime, bool ctrl);\r
+\r
+ void Tick();\r
+ bool Idle();\r
+ virtual void SetTicking(bool on) = 0;\r
+ virtual bool SetIdle(bool) { return false; }\r
+ virtual void SetMouseCapture(bool on) = 0;\r
+ virtual bool HaveMouseCapture() = 0;\r
+ void SetFocusState(bool focusState);\r
+\r
+ virtual bool PaintContains(PRectangle rc);\r
+ bool PaintContainsMargin();\r
+ void CheckForChangeOutsidePaint(Range r);\r
+ void SetBraceHighlight(Position pos0, Position pos1, int matchStyle);\r
+\r
+ void SetDocPointer(Document *document);\r
+\r
+ void Expand(int &line, bool doExpand);\r
+ void ToggleContraction(int line);\r
+ void EnsureLineVisible(int lineDoc, bool enforcePolicy);\r
+ int ReplaceTarget(bool replacePatterns, const char *text, int length=-1);\r
+\r
+ bool PositionIsHotspot(int position);\r
+ bool PointIsHotspot(Point pt);\r
+ void SetHotSpotRange(Point *pt);\r
+ void GetHotSpotRange(int& hsStart, int& hsEnd);\r
+\r
+ int CodePage() const;\r
+ virtual bool ValidCodePage(int /* codePage */) const { return true; }\r
+ int WrapCount(int line);\r
+ void AddStyledText(char *buffer, int appendLength);\r
+\r
+ virtual sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) = 0;\r
+ void StyleSetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam);\r
+ sptr_t StyleGetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam);\r
+\r
+ static const char *StringFromEOLMode(int eolMode);\r
+\r
+public:\r
+ // Public so the COM thunks can access it.\r
+ bool IsUnicodeMode() const;\r
+ // Public so scintilla_send_message can use it.\r
+ virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);\r
+ // Public so scintilla_set_id can use it.\r
+ int ctrlID;\r
+ friend class AutoSurface;\r
+ friend class SelectionLineIterator;\r
+};\r
+\r
+/**\r
+ * A smart pointer class to ensure Surfaces are set up and deleted correctly.\r
+ */\r
+class AutoSurface {\r
+private:\r
+ Surface *surf;\r
+public:\r
+ AutoSurface(Editor *ed) : surf(0) {\r
+ if (ed->wMain.GetID()) {\r
+ surf = Surface::Allocate();\r
+ if (surf) {\r
+ surf->Init(ed->wMain.GetID());\r
+ surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage());\r
+ surf->SetDBCSMode(ed->CodePage());\r
+ }\r
+ }\r
+ }\r
+ AutoSurface(SurfaceID sid, Editor *ed) : surf(0) {\r
+ if (ed->wMain.GetID()) {\r
+ surf = Surface::Allocate();\r
+ if (surf) {\r
+ surf->Init(sid, ed->wMain.GetID());\r
+ surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage());\r
+ surf->SetDBCSMode(ed->CodePage());\r
+ }\r
+ }\r
+ }\r
+ ~AutoSurface() {\r
+ delete surf;\r
+ }\r
+ Surface *operator->() const {\r
+ return surf;\r
+ }\r
+ operator Surface *() const {\r
+ return surf;\r
+ }\r
+};\r
+\r
+#ifdef SCI_NAMESPACE\r
+}\r
+#endif\r
+\r
+#endif\r