aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Editor.h
blob: 4ff334767a19b67c454d80f2de85e4f0364b7819 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
// Scintilla source code edit control
// Editor.h - defines the main editor class
// Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.

#ifndef EDITOR_H
#define EDITOR_H

class Caret {
public:
	bool active;
	bool on;
	int period;
		
	Caret();
};

class Timer {

public:
	bool ticking;
	int ticksToWait;
	enum {tickSize = 100};
	int tickerID;
		
	Timer();
};

class LineLayout {
public:
	// Drawing is only performed for maxLineLength characters on each line.
	enum {maxLineLength = 4000};
	int numCharsInLine;
	char chars[maxLineLength];
	char styles[maxLineLength];
	char indicators[maxLineLength];
	int positions[maxLineLength];
};

class Editor : public DocWatcher {
protected:	// ScintillaBase subclass needs access to much of Editor

	// On GTK+, Scintilla is a container widget holding two scroll bars and a drawing area
	// whereas on Windows there is just one window with both scroll bars turned on.
	// Therefore, on GTK+ the following are separate windows but only one window on Windows.
	Window wMain;	// The Scintilla parent window
	Window wDraw;	// The text drawing area

	// Style resources may be expensive to allocate so are cached between uses.
	// When a style attribute is changed, this cache is flushed.
	bool stylesValid;	
	ViewStyle vs;
	Palette palette;
	
	bool hideSelection;
	bool inOverstrike;

	// In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to 
	// the screen. This avoids flashing but is about 30% slower.
	bool bufferedDraw;

	int xOffset;				// Horizontal scrolled amount in pixels
	int xCaretMargin;	// Ensure this many pixels visible on both sides of caret
	
	Surface pixmapLine;
	Surface pixmapSelMargin;
	Surface pixmapSelPattern;
	// Intellimouse support - currently only implemented for Windows
	unsigned int ucWheelScrollLines;
	short cWheelDelta; //wheel delta from roll

	KeyMap kmap;

	Caret caret;
	Timer timer;

	Point lastClick;
	unsigned int lastClickTime;
	enum { selChar, selWord, selLine } selectionType;
	Point ptMouseLast;
	bool firstExpose;
	bool inDragDrop;
	bool dropWentOutside;
	int posDrag;
	int posDrop;
	int lastXChosen;
	int lineAnchor;
	int originalAnchorPos;
	int currentPos;
	int anchor;
	int topLine;
	int posTopLine;
	
	bool needUpdateUI;
	Position braces[2];
	int bracesMatchStyle;
	
	int edgeState;
	int theEdge;

	enum { notPainting, painting, paintAbandoned } paintState;
	PRectangle rcPaint;
	bool paintingAllText;
	
	int modEventMask;
	
	char *dragChars;
	int lenDrag;
	bool dragIsRectangle;
	enum { selStream, selRectangle, selRectangleFixed } selType;
	int xStartSelect;
	int xEndSelect;
	
	int caretPolicy;
	int caretSlop;

	int searchAnchor;

#ifdef MACRO_SUPPORT
	int recordingMacro;
#endif

	int foldFlags;
	ContractionState cs;

	Document *pdoc;

	Editor();
	virtual ~Editor();
	virtual void Initialise() = 0;
	virtual void Finalise();

	void InvalidateStyleData();
	void InvalidateStyleRedraw();
	virtual void RefreshColourPalette(Palette &pal, bool want);
	void RefreshStyleData();
	void DropGraphics();

	PRectangle GetClientRectangle();
	PRectangle GetTextRectangle();
	
	int LinesOnScreen();
	int LinesToScroll();
	int MaxScrollPos();
	Point LocationFromPosition(unsigned int pos);
	int XFromPosition(unsigned int pos);
	int PositionFromLocation(Point pt);
	int PositionFromLineX(int line, int x);
	int LineFromLocation(Point pt);
	void SetTopLine(int topLineNew);
	
	void RedrawRect(PRectangle rc);
	void Redraw();
	void RedrawSelMargin();
	PRectangle RectangleFromRange(int start, int end);
	void InvalidateRange(int start, int end);
	
	int CurrentPosition();
	bool SelectionEmpty();
	int SelectionStart(int line=-1);
	int SelectionEnd(int line=-1);
	void SetSelection(int currentPos_, int anchor_);
	void SetSelection(int currentPos_);
	void SetEmptySelection(int currentPos_);
	int MovePositionTo(int newPos, bool extend = false);
	int MovePositionSoVisible(int pos, int moveDir);
	void SetLastXChosen();

	void ScrollTo(int line);
	virtual void ScrollText(int linesToMove);
	void HorizontalScrollTo(int xPos);
	void EnsureCaretVisible(bool useMargin=true);
	void ShowCaretAtCurrentPosition();
	void DropCaret();
	void InvalidateCaret();

	void PaintSelMargin(Surface *surface, PRectangle &rc);
        void LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayout &ll);
	void DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int xStart, 
		PRectangle rcLine, LineLayout &ll);
	void Paint(Surface *surfaceWindow, PRectangle rcArea);
	long FormatRange(bool draw, FORMATRANGE *pfr);

	virtual void SetVerticalScrollPos() = 0;
	virtual void SetHorizontalScrollPos() = 0;
	virtual bool ModifyScrollBars(int nMax, int nPage) = 0;
	void SetScrollBarsTo(PRectangle rsClient);
	void SetScrollBars();

	virtual void AddChar(char ch);
	void ClearSelection();
	void ClearAll();
	void Cut();
	void PasteRectangular(int pos, const char *ptr, int len);
	virtual void Copy() = 0;
	virtual void Paste() = 0;
	void Clear();
	void SelectAll();
	void Undo();
	void Redo();
	void DelChar();
	void DelCharBack();
	virtual void ClaimSelection() = 0;

	virtual void NotifyChange() = 0;
	virtual void NotifyFocus(bool focus);
	virtual void NotifyParent(SCNotification scn) = 0;
	virtual void NotifyStyleNeeded(int endStyleNeeded);
	void NotifyChar(char ch);
	void NotifySavePoint(bool isSavePoint);
	void NotifyModifyAttempt();
	virtual void NotifyDoubleClick(Point pt, bool shift);
	void NotifyUpdateUI();
	bool NotifyMarginClick(Point pt, bool shift, bool ctrl, bool alt);
	void NotifyNeedShown(int pos, int len);
	
	void NotifyModifyAttempt(Document *document, void *userData);
	void NotifySavePoint(Document *document, void *userData, bool atSavePoint);
	void NotifyModified(Document *document, DocModification mh, void *userData);
	void NotifyDeleted(Document *document, void *userData);
	
#ifdef MACRO_SUPPORT
	void NotifyMacroRecord(UINT iMessage, WPARAM wParam, LPARAM lParam);
#endif

	void PageMove(int direction, bool extend=false);
	virtual int KeyCommand(UINT iMessage);
	virtual int KeyDefault(int /* key */, int /*modifiers*/);
	int KeyDown(int key, bool shift, bool ctrl, bool alt);

	bool GetWhitespaceVisible();
	void SetWhitespaceVisible(bool view);

	void Indent(bool forwards);

	long FindText(UINT iMessage,WPARAM wParam,LPARAM lParam);
	void SearchAnchor();
	long SearchText(UINT iMessage,WPARAM wParam,LPARAM lParam);
	void GoToLine(int lineNo);

	char *CopyRange(int start, int end);
	int SelectionRangeLength();
	char *CopySelectionRange();
	void CopySelectionIntoDrag();
	void SetDragPosition(int newPos);
	virtual void StartDrag();
	void DropAt(int position, const char *value, bool moving, bool rectangular);
	// PositionInSelection returns 0 if position in selection, -1 if position before selection, and 1 if after.
	// Before means either before any line of selection or before selection on its line, with a similar meaning to after
	int PositionInSelection(int pos);
	bool PointInSelection(Point pt);
	bool PointInSelMargin(Point pt);
	virtual void ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt);
	void ButtonMove(Point pt);
	void ButtonUp(Point pt, unsigned int curTime, bool ctrl);

	void Tick();
	virtual void SetTicking(bool on) = 0;
	virtual void SetMouseCapture(bool on) = 0;
	virtual bool HaveMouseCapture() = 0;

	void CheckForChangeOutsidePaint(Range r);
	int BraceMatch(int position, int maxReStyle);
	void SetBraceHighlight(Position pos0, Position pos1, int matchStyle);
	
	void SetDocPointer(Document *document);
	
	void Expand(int &line, bool doExpand);
	void ToggleContraction(int line);
	void EnsureLineVisible(int line);

	virtual LRESULT DefWndProc(UINT iMessage, WPARAM wParam, LPARAM lParam) = 0;
	
public:
	// Public so scintilla_send_message can use it
	virtual LRESULT WndProc(UINT iMessage, WPARAM wParam, LPARAM lParam);
	// Public so scintilla_set_id can use it
	int ctrlID;	
};

#endif