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