]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/Editor.h
d1281be5a8c98ed794fe5eaddee5362d719b4d6b
[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 int displayPopupMenu;
120
121 #ifdef MACRO_SUPPORT
122 int recordingMacro;
123 #endif
124
125 int foldFlags;
126 ContractionState cs;
127
128 Document *pdoc;
129
130 Editor();
131 virtual ~Editor();
132 virtual void Initialise() = 0;
133 virtual void Finalise();
134
135 void InvalidateStyleData();
136 void InvalidateStyleRedraw();
137 virtual void RefreshColourPalette(Palette &pal, bool want);
138 void RefreshStyleData();
139 void DropGraphics();
140
141 PRectangle GetClientRectangle();
142 PRectangle GetTextRectangle();
143
144 int LinesOnScreen();
145 int LinesToScroll();
146 int MaxScrollPos();
147 Point LocationFromPosition(unsigned int pos);
148 int XFromPosition(unsigned int pos);
149 int PositionFromLocation(Point pt);
150 int PositionFromLineX(int line, int x);
151 int LineFromLocation(Point pt);
152 void SetTopLine(int topLineNew);
153
154 void RedrawRect(PRectangle rc);
155 void Redraw();
156 void RedrawSelMargin();
157 PRectangle RectangleFromRange(int start, int end);
158 void InvalidateRange(int start, int end);
159
160 int CurrentPosition();
161 bool SelectionEmpty();
162 int SelectionStart(int line=-1);
163 int SelectionEnd(int line=-1);
164 void SetSelection(int currentPos_, int anchor_);
165 void SetSelection(int currentPos_);
166 void SetEmptySelection(int currentPos_);
167 int MovePositionTo(int newPos, bool extend = false);
168 int MovePositionSoVisible(int pos, int moveDir);
169 void SetLastXChosen();
170
171 void ScrollTo(int line);
172 virtual void ScrollText(int linesToMove);
173 void HorizontalScrollTo(int xPos);
174 void EnsureCaretVisible(bool useMargin=true);
175 void ShowCaretAtCurrentPosition();
176 void DropCaret();
177 void InvalidateCaret();
178
179 void PaintSelMargin(Surface *surface, PRectangle &rc);
180 void LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayout &ll);
181 void DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
182 PRectangle rcLine, LineLayout &ll);
183 void Paint(Surface *surfaceWindow, PRectangle rcArea);
184 long FormatRange(bool draw, FORMATRANGE *pfr);
185
186 virtual void SetVerticalScrollPos() = 0;
187 virtual void SetHorizontalScrollPos() = 0;
188 virtual bool ModifyScrollBars(int nMax, int nPage) = 0;
189 void SetScrollBarsTo(PRectangle rsClient);
190 void SetScrollBars();
191
192 virtual void AddChar(char ch);
193 void ClearSelection();
194 void ClearAll();
195 void Cut();
196 void PasteRectangular(int pos, const char *ptr, int len);
197 virtual void Copy() = 0;
198 virtual void Paste() = 0;
199 void Clear();
200 void SelectAll();
201 void Undo();
202 void Redo();
203 void DelChar();
204 void DelCharBack();
205 virtual void ClaimSelection() = 0;
206
207 virtual void NotifyChange() = 0;
208 virtual void NotifyFocus(bool focus);
209 virtual void NotifyParent(SCNotification scn) = 0;
210 virtual void NotifyStyleNeeded(int endStyleNeeded);
211 void NotifyChar(char ch);
212 void NotifySavePoint(bool isSavePoint);
213 void NotifyModifyAttempt();
214 virtual void NotifyDoubleClick(Point pt, bool shift);
215 void NotifyUpdateUI();
216 bool NotifyMarginClick(Point pt, bool shift, bool ctrl, bool alt);
217 void NotifyNeedShown(int pos, int len);
218
219 void NotifyModifyAttempt(Document *document, void *userData);
220 void NotifySavePoint(Document *document, void *userData, bool atSavePoint);
221 void NotifyModified(Document *document, DocModification mh, void *userData);
222 void NotifyDeleted(Document *document, void *userData);
223 void NotifyStyleNeeded(Document *doc, void *userData, int endPos);
224
225
226 #ifdef MACRO_SUPPORT
227 void NotifyMacroRecord(UINT iMessage, WPARAM wParam, LPARAM lParam);
228 #endif
229
230 void PageMove(int direction, bool extend=false);
231 void ChangeCaseOfSelection(bool makeUpperCase);
232 void LineTranspose();
233 virtual int KeyCommand(UINT iMessage);
234 virtual int KeyDefault(int /* key */, int /*modifiers*/);
235 int KeyDown(int key, bool shift, bool ctrl, bool alt);
236
237 bool GetWhitespaceVisible();
238 void SetWhitespaceVisible(bool view);
239
240 void Indent(bool forwards);
241
242 long FindText(UINT iMessage,WPARAM wParam,LPARAM lParam);
243 void SearchAnchor();
244 long SearchText(UINT iMessage,WPARAM wParam,LPARAM lParam);
245 void GoToLine(int lineNo);
246
247 char *CopyRange(int start, int end);
248 int SelectionRangeLength();
249 char *CopySelectionRange();
250 void CopySelectionIntoDrag();
251 void SetDragPosition(int newPos);
252 virtual void StartDrag();
253 void DropAt(int position, const char *value, bool moving, bool rectangular);
254 // PositionInSelection returns 0 if position in selection, -1 if position before selection, and 1 if after.
255 // Before means either before any line of selection or before selection on its line, with a similar meaning to after
256 int PositionInSelection(int pos);
257 bool PointInSelection(Point pt);
258 bool PointInSelMargin(Point pt);
259 virtual void ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt);
260 void ButtonMove(Point pt);
261 void ButtonUp(Point pt, unsigned int curTime, bool ctrl);
262
263 void Tick();
264 virtual void SetTicking(bool on) = 0;
265 virtual void SetMouseCapture(bool on) = 0;
266 virtual bool HaveMouseCapture() = 0;
267
268 void CheckForChangeOutsidePaint(Range r);
269 int BraceMatch(int position, int maxReStyle);
270 void SetBraceHighlight(Position pos0, Position pos1, int matchStyle);
271
272 void SetDocPointer(Document *document);
273
274 void Expand(int &line, bool doExpand);
275 void ToggleContraction(int line);
276 void EnsureLineVisible(int line);
277
278 virtual LRESULT DefWndProc(UINT iMessage, WPARAM wParam, LPARAM lParam) = 0;
279
280 public:
281 // Public so scintilla_send_message can use it
282 virtual LRESULT WndProc(UINT iMessage, WPARAM wParam, LPARAM lParam);
283 // Public so scintilla_set_id can use it
284 int ctrlID;
285 };
286
287 #endif