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