]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/Editor.h
4ff334767a19b67c454d80f2de85e4f0364b7819
[wxWidgets.git] / src / stc / scintilla / src / Editor.h
1 // Scintilla source code edit control
2 // Editor.h - defines the main editor class
3 // Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
4 // The License.txt file describes the conditions under which this software may be distributed.
5
6 #ifndef EDITOR_H
7 #define EDITOR_H
8
9 class Caret {
10 public:
11 bool active;
12 bool on;
13 int period;
14
15 Caret();
16 };
17
18 class Timer {
19
20 public:
21 bool ticking;
22 int ticksToWait;
23 enum {tickSize = 100};
24 int tickerID;
25
26 Timer();
27 };
28
29 class LineLayout {
30 public:
31 // Drawing is only performed for maxLineLength characters on each line.
32 enum {maxLineLength = 4000};
33 int numCharsInLine;
34 char chars[maxLineLength];
35 char styles[maxLineLength];
36 char indicators[maxLineLength];
37 int positions[maxLineLength];
38 };
39
40 class Editor : public DocWatcher {
41 protected: // ScintillaBase subclass needs access to much of Editor
42
43 // On GTK+, Scintilla is a container widget holding two scroll bars and a drawing area
44 // whereas on Windows there is just one window with both scroll bars turned on.
45 // Therefore, on GTK+ the following are separate windows but only one window on Windows.
46 Window wMain; // The Scintilla parent window
47 Window wDraw; // The text drawing area
48
49 // Style resources may be expensive to allocate so are cached between uses.
50 // When a style attribute is changed, this cache is flushed.
51 bool stylesValid;
52 ViewStyle vs;
53 Palette palette;
54
55 bool hideSelection;
56 bool inOverstrike;
57
58 // In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to
59 // the screen. This avoids flashing but is about 30% slower.
60 bool bufferedDraw;
61
62 int xOffset; // Horizontal scrolled amount in pixels
63 int xCaretMargin; // Ensure this many pixels visible on both sides of caret
64
65 Surface pixmapLine;
66 Surface pixmapSelMargin;
67 Surface pixmapSelPattern;
68 // Intellimouse support - currently only implemented for Windows
69 unsigned int ucWheelScrollLines;
70 short cWheelDelta; //wheel delta from roll
71
72 KeyMap kmap;
73
74 Caret caret;
75 Timer timer;
76
77 Point lastClick;
78 unsigned int lastClickTime;
79 enum { selChar, selWord, selLine } selectionType;
80 Point ptMouseLast;
81 bool firstExpose;
82 bool inDragDrop;
83 bool dropWentOutside;
84 int posDrag;
85 int posDrop;
86 int lastXChosen;
87 int lineAnchor;
88 int originalAnchorPos;
89 int currentPos;
90 int anchor;
91 int topLine;
92 int posTopLine;
93
94 bool needUpdateUI;
95 Position braces[2];
96 int bracesMatchStyle;
97
98 int edgeState;
99 int theEdge;
100
101 enum { notPainting, painting, paintAbandoned } paintState;
102 PRectangle rcPaint;
103 bool paintingAllText;
104
105 int modEventMask;
106
107 char *dragChars;
108 int lenDrag;
109 bool dragIsRectangle;
110 enum { selStream, selRectangle, selRectangleFixed } selType;
111 int xStartSelect;
112 int xEndSelect;
113
114 int caretPolicy;
115 int caretSlop;
116
117 int searchAnchor;
118
119 #ifdef MACRO_SUPPORT
120 int recordingMacro;
121 #endif
122
123 int foldFlags;
124 ContractionState cs;
125
126 Document *pdoc;
127
128 Editor();
129 virtual ~Editor();
130 virtual void Initialise() = 0;
131 virtual void Finalise();
132
133 void InvalidateStyleData();
134 void InvalidateStyleRedraw();
135 virtual void RefreshColourPalette(Palette &pal, bool want);
136 void RefreshStyleData();
137 void DropGraphics();
138
139 PRectangle GetClientRectangle();
140 PRectangle GetTextRectangle();
141
142 int LinesOnScreen();
143 int LinesToScroll();
144 int MaxScrollPos();
145 Point LocationFromPosition(unsigned int pos);
146 int XFromPosition(unsigned int pos);
147 int PositionFromLocation(Point pt);
148 int PositionFromLineX(int line, int x);
149 int LineFromLocation(Point pt);
150 void SetTopLine(int topLineNew);
151
152 void RedrawRect(PRectangle rc);
153 void Redraw();
154 void RedrawSelMargin();
155 PRectangle RectangleFromRange(int start, int end);
156 void InvalidateRange(int start, int end);
157
158 int CurrentPosition();
159 bool SelectionEmpty();
160 int SelectionStart(int line=-1);
161 int SelectionEnd(int line=-1);
162 void SetSelection(int currentPos_, int anchor_);
163 void SetSelection(int currentPos_);
164 void SetEmptySelection(int currentPos_);
165 int MovePositionTo(int newPos, bool extend = false);
166 int MovePositionSoVisible(int pos, int moveDir);
167 void SetLastXChosen();
168
169 void ScrollTo(int line);
170 virtual void ScrollText(int linesToMove);
171 void HorizontalScrollTo(int xPos);
172 void EnsureCaretVisible(bool useMargin=true);
173 void ShowCaretAtCurrentPosition();
174 void DropCaret();
175 void InvalidateCaret();
176
177 void PaintSelMargin(Surface *surface, PRectangle &rc);
178 void LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayout &ll);
179 void DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
180 PRectangle rcLine, LineLayout &ll);
181 void Paint(Surface *surfaceWindow, PRectangle rcArea);
182 long FormatRange(bool draw, FORMATRANGE *pfr);
183
184 virtual void SetVerticalScrollPos() = 0;
185 virtual void SetHorizontalScrollPos() = 0;
186 virtual bool ModifyScrollBars(int nMax, int nPage) = 0;
187 void SetScrollBarsTo(PRectangle rsClient);
188 void SetScrollBars();
189
190 virtual void AddChar(char ch);
191 void ClearSelection();
192 void ClearAll();
193 void Cut();
194 void PasteRectangular(int pos, const char *ptr, int len);
195 virtual void Copy() = 0;
196 virtual void Paste() = 0;
197 void Clear();
198 void SelectAll();
199 void Undo();
200 void Redo();
201 void DelChar();
202 void DelCharBack();
203 virtual void ClaimSelection() = 0;
204
205 virtual void NotifyChange() = 0;
206 virtual void NotifyFocus(bool focus);
207 virtual void NotifyParent(SCNotification scn) = 0;
208 virtual void NotifyStyleNeeded(int endStyleNeeded);
209 void NotifyChar(char ch);
210 void NotifySavePoint(bool isSavePoint);
211 void NotifyModifyAttempt();
212 virtual void NotifyDoubleClick(Point pt, bool shift);
213 void NotifyUpdateUI();
214 bool NotifyMarginClick(Point pt, bool shift, bool ctrl, bool alt);
215 void NotifyNeedShown(int pos, int len);
216
217 void NotifyModifyAttempt(Document *document, void *userData);
218 void NotifySavePoint(Document *document, void *userData, bool atSavePoint);
219 void NotifyModified(Document *document, DocModification mh, void *userData);
220 void NotifyDeleted(Document *document, void *userData);
221
222 #ifdef MACRO_SUPPORT
223 void NotifyMacroRecord(UINT iMessage, WPARAM wParam, LPARAM lParam);
224 #endif
225
226 void PageMove(int direction, bool extend=false);
227 virtual int KeyCommand(UINT iMessage);
228 virtual int KeyDefault(int /* key */, int /*modifiers*/);
229 int KeyDown(int key, bool shift, bool ctrl, bool alt);
230
231 bool GetWhitespaceVisible();
232 void SetWhitespaceVisible(bool view);
233
234 void Indent(bool forwards);
235
236 long FindText(UINT iMessage,WPARAM wParam,LPARAM lParam);
237 void SearchAnchor();
238 long SearchText(UINT iMessage,WPARAM wParam,LPARAM lParam);
239 void GoToLine(int lineNo);
240
241 char *CopyRange(int start, int end);
242 int SelectionRangeLength();
243 char *CopySelectionRange();
244 void CopySelectionIntoDrag();
245 void SetDragPosition(int newPos);
246 virtual void StartDrag();
247 void DropAt(int position, const char *value, bool moving, bool rectangular);
248 // PositionInSelection returns 0 if position in selection, -1 if position before selection, and 1 if after.
249 // Before means either before any line of selection or before selection on its line, with a similar meaning to after
250 int PositionInSelection(int pos);
251 bool PointInSelection(Point pt);
252 bool PointInSelMargin(Point pt);
253 virtual void ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt);
254 void ButtonMove(Point pt);
255 void ButtonUp(Point pt, unsigned int curTime, bool ctrl);
256
257 void Tick();
258 virtual void SetTicking(bool on) = 0;
259 virtual void SetMouseCapture(bool on) = 0;
260 virtual bool HaveMouseCapture() = 0;
261
262 void CheckForChangeOutsidePaint(Range r);
263 int BraceMatch(int position, int maxReStyle);
264 void SetBraceHighlight(Position pos0, Position pos1, int matchStyle);
265
266 void SetDocPointer(Document *document);
267
268 void Expand(int &line, bool doExpand);
269 void ToggleContraction(int line);
270 void EnsureLineVisible(int line);
271
272 virtual LRESULT DefWndProc(UINT iMessage, WPARAM wParam, LPARAM lParam) = 0;
273
274 public:
275 // Public so scintilla_send_message can use it
276 virtual LRESULT WndProc(UINT iMessage, WPARAM wParam, LPARAM lParam);
277 // Public so scintilla_set_id can use it
278 int ctrlID;
279 };
280
281 #endif