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