1 // Scintilla source code edit control
2 /** @file Editor.h
3  ** Defines the main editor class.
4  **/
5 // Copyright 1998-2011 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 #ifdef SCI_NAMESPACE
12 namespace Scintilla {
13 #endif
14 
15 /**
16  */
17 class Caret {
18 public:
19 	bool active;
20 	bool on;
21 	int period;
22 
23 	Caret();
24 };
25 
26 /**
27  */
28 class Timer {
29 public:
30 	bool ticking;
31 	int ticksToWait;
32 	enum {tickSize = 100};
33 	TickerID tickerID;
34 
35 	Timer();
36 };
37 
38 /**
39  */
40 class Idler {
41 public:
42 	bool state;
43 	IdlerID idlerID;
44 
45 	Idler();
46 };
47 
48 /**
49  * When platform has a way to generate an event before painting,
50  * accumulate needed styling range and other work items in
51  * WorkNeeded to avoid unnecessary work inside paint handler
52  */
53 class WorkNeeded {
54 public:
55 	enum workItems {
56 		workNone=0,
57 		workStyle=1,
58 		workUpdateUI=2
59 	};
60 	bool active;
61 	enum workItems items;
62 	Position upTo;
63 
WorkNeeded()64 	WorkNeeded() : active(false), items(workNone), upTo(0) {}
Reset()65 	void Reset() {
66 		active = false;
67 		items = workNone;
68 		upTo = 0;
69 	}
Need(workItems items_,Position pos)70 	void Need(workItems items_, Position pos) {
71 		if ((items_ & workStyle) && (upTo < pos))
72 			upTo = pos;
73 		items = static_cast<workItems>(items | items_);
74 	}
75 };
76 
77 /**
78  * Hold a piece of text selected for copying or dragging, along with encoding and selection format information.
79  */
80 class SelectionText {
81 	std::string s;
82 public:
83 	bool rectangular;
84 	bool lineCopy;
85 	int codePage;
86 	int characterSet;
SelectionText()87 	SelectionText() : rectangular(false), lineCopy(false), codePage(0), characterSet(0) {}
~SelectionText()88 	~SelectionText() {
89 	}
Clear()90 	void Clear() {
91 		s.clear();
92 		rectangular = false;
93 		lineCopy = false;
94 		codePage = 0;
95 		characterSet = 0;
96 	}
Copy(const std::string & s_,int codePage_,int characterSet_,bool rectangular_,bool lineCopy_)97 	void Copy(const std::string &s_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) {
98 		s = s_;
99 		codePage = codePage_;
100 		characterSet = characterSet_;
101 		rectangular = rectangular_;
102 		lineCopy = lineCopy_;
103 		FixSelectionForClipboard();
104 	}
Copy(const SelectionText & other)105 	void Copy(const SelectionText &other) {
106 		Copy(other.s, other.codePage, other.characterSet, other.rectangular, other.lineCopy);
107 	}
Data()108 	const char *Data() const {
109 		return s.c_str();
110 	}
Length()111 	size_t Length() const {
112 		return s.length();
113 	}
LengthWithTerminator()114 	size_t LengthWithTerminator() const {
115 		return s.length() + 1;
116 	}
Empty()117 	bool Empty() const {
118 		return s.empty();
119 	}
120 private:
FixSelectionForClipboard()121 	void FixSelectionForClipboard() {
122 		// To avoid truncating the contents of the clipboard when pasted where the
123 		// clipboard contains NUL characters, replace NUL characters by spaces.
124 		std::replace(s.begin(), s.end(), '\0', ' ');
125 	}
126 };
127 
128 struct WrapPending {
129 	// The range of lines that need to be wrapped
130 	enum { lineLarge = 0x7ffffff };
131 	int start;	// When there are wraps pending, will be in document range
132 	int end;	// May be lineLarge to indicate all of document after start
WrapPendingWrapPending133 	WrapPending() {
134 		start = lineLarge;
135 		end = lineLarge;
136 	}
ResetWrapPending137 	void Reset() {
138 		start = lineLarge;
139 		end = lineLarge;
140 	}
WrappedWrapPending141 	void Wrapped(int line) {
142 		if (start == line)
143 			start++;
144 	}
NeedsWrapWrapPending145 	bool NeedsWrap() const {
146 		return start < end;
147 	}
AddRangeWrapPending148 	bool AddRange(int lineStart, int lineEnd) {
149 		const bool neededWrap = NeedsWrap();
150 		bool changed = false;
151 		if (start > lineStart) {
152 			start = lineStart;
153 			changed = true;
154 		}
155 		if ((end < lineEnd) || !neededWrap) {
156 			end = lineEnd;
157 			changed = true;
158 		}
159 		return changed;
160 	}
161 };
162 
163 struct PrintParameters {
164 	int magnification;
165 	int colourMode;
166 	WrapMode wrapState;
167 	PrintParameters();
168 };
169 
170 /**
171  */
172 class Editor : public DocWatcher {
173 	// Private so Editor objects can not be copied
174 	Editor(const Editor &);
175 	Editor &operator=(const Editor &);
176 
177 protected:	// ScintillaBase subclass needs access to much of Editor
178 
179 	/** On GTK+, Scintilla is a container widget holding two scroll bars
180 	 * whereas on Windows there is just one window with both scroll bars turned on. */
181 	Window wMain;	///< The Scintilla parent window
182 	Window wMargin;	///< May be separate when using a scroll view for wMain
183 
184 	/** Style resources may be expensive to allocate so are cached between uses.
185 	 * When a style attribute is changed, this cache is flushed. */
186 	bool stylesValid;
187 	ViewStyle vs;
188 	int technology;
189 	Point sizeRGBAImage;
190 	float scaleRGBAImage;
191 
192 	PrintParameters printParameters;
193 
194 	int cursorMode;
195 
196 	// Highlight current folding block
197 	HighlightDelimiter highlightDelimiter;
198 
199 	bool hasFocus;
200 	bool hideSelection;
201 	bool inOverstrike;
202 	bool drawOverstrikeCaret;
203 	bool mouseDownCaptures;
204 
205 	/** In bufferedDraw mode, graphics operations are drawn to a pixmap and then copied to
206 	 * the screen. This avoids flashing but is about 30% slower. */
207 	bool bufferedDraw;
208 	/** In twoPhaseDraw mode, drawing is performed in two phases, first the background
209 	* and then the foreground. This avoids chopping off characters that overlap the next run. */
210 	bool twoPhaseDraw;
211 
212 	int xOffset;		///< Horizontal scrolled amount in pixels
213 	int xCaretMargin;	///< Ensure this many pixels visible on both sides of caret
214 	bool horizontalScrollBarVisible;
215 	int scrollWidth;
216 	bool trackLineWidth;
217 	int lineWidthMaxSeen;
218 	bool verticalScrollBarVisible;
219 	bool endAtLastLine;
220 	int caretSticky;
221 	int marginOptions;
222 	bool mouseSelectionRectangularSwitch;
223 	bool multipleSelection;
224 	bool additionalSelectionTyping;
225 	int multiPasteMode;
226 	bool additionalCaretsBlink;
227 	bool additionalCaretsVisible;
228 
229 	int virtualSpaceOptions;
230 
231 	Surface *pixmapLine;
232 	Surface *pixmapSelMargin;
233 	Surface *pixmapSelPattern;
234 	Surface *pixmapSelPatternOffset1;
235 	Surface *pixmapIndentGuide;
236 	Surface *pixmapIndentGuideHighlight;
237 
238 	LineLayoutCache llc;
239 	PositionCache posCache;
240 	SpecialRepresentations reprs;
241 
242 	KeyMap kmap;
243 
244 	Caret caret;
245 	Timer timer;
246 	Timer autoScrollTimer;
247 	enum { autoScrollDelay = 200 };
248 
249 	Idler idler;
250 
251 	Point lastClick;
252 	unsigned int lastClickTime;
253 	int dwellDelay;
254 	int ticksToDwell;
255 	bool dwelling;
256 	enum { selChar, selWord, selSubLine, selWholeLine } selectionType;
257 	Point ptMouseLast;
258 	enum { ddNone, ddInitial, ddDragging } inDragDrop;
259 	bool dropWentOutside;
260 	SelectionPosition posDrag;
261 	SelectionPosition posDrop;
262 	int hotSpotClickPos;
263 	int lastXChosen;
264 	int lineAnchorPos;
265 	int originalAnchorPos;
266 	int wordSelectAnchorStartPos;
267 	int wordSelectAnchorEndPos;
268 	int wordSelectInitialCaretPos;
269 	int targetStart;
270 	int targetEnd;
271 	int searchFlags;
272 	int topLine;
273 	int posTopLine;
274 	int lengthForEncode;
275 
276 	int needUpdateUI;
277 	Position braces[2];
278 	int bracesMatchStyle;
279 	int highlightGuideColumn;
280 
281 	enum { notPainting, painting, paintAbandoned } paintState;
282 	bool paintAbandonedByStyling;
283 	PRectangle rcPaint;
284 	bool paintingAllText;
285 	bool willRedrawAll;
286 	WorkNeeded workNeeded;
287 
288 	int modEventMask;
289 
290 	SelectionText drag;
291 	Selection sel;
292 	bool primarySelection;
293 
294 	int caretXPolicy;
295 	int caretXSlop;	///< Ensure this many pixels visible on both sides of caret
296 
297 	int caretYPolicy;
298 	int caretYSlop;	///< Ensure this many lines visible on both sides of caret
299 
300 	int visiblePolicy;
301 	int visibleSlop;
302 
303 	int searchAnchor;
304 
305 	bool recordingMacro;
306 
307 	int foldFlags;
308 	int foldAutomatic;
309 	ContractionState cs;
310 
311 	// Hotspot support
312 	int hsStart;
313 	int hsEnd;
314 
315 	// Wrapping support
316 	int wrapWidth;
317 	WrapPending wrapPending;
318 
319 	bool convertPastes;
320 
321 	Document *pdoc;
322 
323 	Editor();
324 	virtual ~Editor();
325 	virtual void Initialise() = 0;
326 	virtual void Finalise();
327 
328 	void InvalidateStyleData();
329 	void InvalidateStyleRedraw();
330 	void RefreshStyleData();
331 	void SetRepresentations();
332 	void DropGraphics(bool freeObjects);
333 	void AllocateGraphics();
334 
335 	// The top left visible point in main window coordinates. Will be 0,0 except for
336 	// scroll views where it will be equivalent to the current scroll position.
337 	virtual Point GetVisibleOriginInMain();
338 	Point DocumentPointFromView(Point ptView);  // Convert a point from view space to document
339 	int TopLineOfMain() const;   // Return the line at Main's y coordinate 0
340 	virtual PRectangle GetClientRectangle();
341 	PRectangle GetTextRectangle();
342 
343 	int LinesOnScreen();
344 	int LinesToScroll();
345 	int MaxScrollPos();
346 	SelectionPosition ClampPositionIntoDocument(SelectionPosition sp) const;
347 	Point LocationFromPosition(SelectionPosition pos);
348 	Point LocationFromPosition(int pos);
349 	int XFromPosition(int pos);
350 	int XFromPosition(SelectionPosition sp);
351 	SelectionPosition SPositionFromLocation(Point pt, bool canReturnInvalid=false, bool charPosition=false, bool virtualSpace=true);
352 	int PositionFromLocation(Point pt, bool canReturnInvalid=false, bool charPosition=false);
353 	SelectionPosition SPositionFromLineX(int lineDoc, int x);
354 	int PositionFromLineX(int line, int x);
355 	int LineFromLocation(Point pt) const;
356 	void SetTopLine(int topLineNew);
357 
358 	bool AbandonPaint();
359 	void RedrawRect(PRectangle rc);
360 	void Redraw();
361 	void RedrawSelMargin(int line=-1, bool allAfter=false);
362 	PRectangle RectangleFromRange(int start, int end);
363 	void InvalidateRange(int start, int end);
364 
UserVirtualSpace()365 	bool UserVirtualSpace() const {
366 		return ((virtualSpaceOptions & SCVS_USERACCESSIBLE) != 0);
367 	}
368 	int CurrentPosition() const;
369 	bool SelectionEmpty() const;
370 	SelectionPosition SelectionStart();
371 	SelectionPosition SelectionEnd();
372 	void SetRectangularRange();
373 	void ThinRectangularRange();
374 	void InvalidateSelection(SelectionRange newMain, bool invalidateWholeSelection=false);
375 	void SetSelection(SelectionPosition currentPos_, SelectionPosition anchor_);
376 	void SetSelection(int currentPos_, int anchor_);
377 	void SetSelection(SelectionPosition currentPos_);
378 	void SetSelection(int currentPos_);
379 	void SetEmptySelection(SelectionPosition currentPos_);
380 	void SetEmptySelection(int currentPos_);
381 	bool RangeContainsProtected(int start, int end) const;
382 	bool SelectionContainsProtected();
383 	int MovePositionOutsideChar(int pos, int moveDir, bool checkLineEnd=true) const;
384 	SelectionPosition MovePositionOutsideChar(SelectionPosition pos, int moveDir, bool checkLineEnd=true) const;
385 	int MovePositionTo(SelectionPosition newPos, Selection::selTypes sel=Selection::noSel, bool ensureVisible=true);
386 	int MovePositionTo(int newPos, Selection::selTypes sel=Selection::noSel, bool ensureVisible=true);
387 	SelectionPosition MovePositionSoVisible(SelectionPosition pos, int moveDir);
388 	SelectionPosition MovePositionSoVisible(int pos, int moveDir);
389 	Point PointMainCaret();
390 	void SetLastXChosen();
391 
392 	void ScrollTo(int line, bool moveThumb=true);
393 	virtual void ScrollText(int linesToMove);
394 	void HorizontalScrollTo(int xPos);
395 	void VerticalCentreCaret();
396 	void MoveSelectedLines(int lineDelta);
397 	void MoveSelectedLinesUp();
398 	void MoveSelectedLinesDown();
399 	void MoveCaretInsideView(bool ensureVisible=true);
400 	int DisplayFromPosition(int pos);
401 
402 	struct XYScrollPosition {
403 		int xOffset;
404 		int topLine;
XYScrollPositionXYScrollPosition405 		XYScrollPosition(int xOffset_, int topLine_) : xOffset(xOffset_), topLine(topLine_) {}
406 		bool operator==(const XYScrollPosition &other) const {
407 			return (xOffset == other.xOffset) && (topLine == other.topLine);
408 		}
409 	};
410 	enum XYScrollOptions {
411 		xysUseMargin=0x1,
412 		xysVertical=0x2,
413 		xysHorizontal=0x4,
414 		xysDefault=xysUseMargin|xysVertical|xysHorizontal};
415 	XYScrollPosition XYScrollToMakeVisible(const SelectionRange range, const XYScrollOptions options);
416 	void SetXYScroll(XYScrollPosition newXY);
417 	void EnsureCaretVisible(bool useMargin=true, bool vert=true, bool horiz=true);
418 	void ScrollRange(SelectionRange range);
419 	void ShowCaretAtCurrentPosition();
420 	void DropCaret();
421 	void InvalidateCaret();
422 	virtual void UpdateSystemCaret();
423 
424 	bool Wrapping() const;
425 	void NeedWrapping(int docLineStart=0, int docLineEnd=WrapPending::lineLarge);
426 	bool WrapOneLine(Surface *surface, int lineToWrap);
427 	enum wrapScope {wsAll, wsVisible, wsIdle};
428 	bool WrapLines(enum wrapScope ws);
429 	void LinesJoin();
430 	void LinesSplit(int pixelWidth);
431 
432 	int SubstituteMarkerIfEmpty(int markerCheck, int markerDefault) const;
433 	void PaintSelMargin(Surface *surface, PRectangle &rc);
434 	LineLayout *RetrieveLineLayout(int lineNumber);
435 	void LayoutLine(int line, Surface *surface, ViewStyle &vstyle, LineLayout *ll,
436 		int width=LineLayout::wrapWidthInfinite);
437 	ColourDesired SelectionBackground(ViewStyle &vsDraw, bool main) const;
438 	ColourDesired TextBackground(ViewStyle &vsDraw, bool overrideBackground, ColourDesired background, int inSelection, bool inHotspot, int styleMain, int i, LineLayout *ll) const;
439 	void DrawIndentGuide(Surface *surface, int lineVisible, int lineHeight, int start, PRectangle rcSegment, bool highlight);
440 	void DrawWrapMarker(Surface *surface, PRectangle rcPlace, bool isEndMarker, ColourDesired wrapColour);
441 	void DrawEOL(Surface *surface, ViewStyle &vsDraw, PRectangle rcLine, LineLayout *ll,
442 		int line, int lineEnd, int xStart, int subLine, XYACCUMULATOR subLineStart,
443 		bool overrideBackground, ColourDesired background,
444 		bool drawWrapMark, ColourDesired wrapColour);
445 	void DrawIndicator(int indicNum, int startPos, int endPos, Surface *surface, ViewStyle &vsDraw,
446 		int xStart, PRectangle rcLine, LineLayout *ll, int subLine);
447 	void DrawIndicators(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
448 		PRectangle rcLine, LineLayout *ll, int subLine, int lineEnd, bool under);
449 	void DrawAnnotation(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
450         PRectangle rcLine, LineLayout *ll, int subLine);
451 	void DrawLine(Surface *surface, ViewStyle &vsDraw, int line, int lineVisible, int xStart,
452 		PRectangle rcLine, LineLayout *ll, int subLine);
453 	void DrawBlockCaret(Surface *surface, ViewStyle &vsDraw, LineLayout *ll, int subLine,
454 		int xStart, int offset, int posCaret, PRectangle rcCaret, ColourDesired caretColour);
455 	void DrawCarets(Surface *surface, ViewStyle &vsDraw, int line, int xStart,
456 		PRectangle rcLine, LineLayout *ll, int subLine);
457 	void RefreshPixMaps(Surface *surfaceWindow);
458 	void Paint(Surface *surfaceWindow, PRectangle rcArea);
459 	long FormatRange(bool draw, Sci_RangeToFormat *pfr);
460 	int TextWidth(int style, const char *text);
461 
462 	virtual void SetVerticalScrollPos() = 0;
463 	virtual void SetHorizontalScrollPos() = 0;
464 	virtual bool ModifyScrollBars(int nMax, int nPage) = 0;
465 	virtual void ReconfigureScrollBars();
466 	void SetScrollBars();
467 	void ChangeSize();
468 
469 	void FilterSelections();
470 	int InsertSpace(int position, unsigned int spaces);
471 	void AddChar(char ch);
472 	virtual void AddCharUTF(char *s, unsigned int len, bool treatAsDBCS=false);
473 	void InsertPaste(SelectionPosition selStart, const char *text, int len);
474 	void ClearSelection(bool retainMultipleSelections=false);
475 	void ClearAll();
476 	void ClearDocumentStyle();
477 	void Cut();
478 	void PasteRectangular(SelectionPosition pos, const char *ptr, int len);
479 	virtual void Copy() = 0;
480 	virtual void CopyAllowLine();
481 	virtual bool CanPaste();
482 	virtual void Paste() = 0;
483 	void Clear();
484 	void SelectAll();
485 	void Undo();
486 	void Redo();
487 	void DelChar();
488 	void DelCharBack(bool allowLineStartDeletion);
489 	virtual void ClaimSelection() = 0;
490 
491 	virtual void NotifyChange() = 0;
492 	virtual void NotifyFocus(bool focus);
493 	virtual void SetCtrlID(int identifier);
GetCtrlID()494 	virtual int GetCtrlID() { return ctrlID; }
495 	virtual void NotifyParent(SCNotification scn) = 0;
496 	virtual void NotifyStyleToNeeded(int endStyleNeeded);
497 	void NotifyChar(int ch);
498 	void NotifySavePoint(bool isSavePoint);
499 	void NotifyModifyAttempt();
500 	virtual void NotifyDoubleClick(Point pt, bool shift, bool ctrl, bool alt);
501 	void NotifyHotSpotClicked(int position, bool shift, bool ctrl, bool alt);
502 	void NotifyHotSpotDoubleClicked(int position, bool shift, bool ctrl, bool alt);
503 	void NotifyHotSpotReleaseClick(int position, bool shift, bool ctrl, bool alt);
504 	bool NotifyUpdateUI();
505 	void NotifyPainted();
506 	void NotifyIndicatorClick(bool click, int position, bool shift, bool ctrl, bool alt);
507 	bool NotifyMarginClick(Point pt, bool shift, bool ctrl, bool alt);
508 	void NotifyNeedShown(int pos, int len);
509 	void NotifyDwelling(Point pt, bool state);
510 	void NotifyZoom();
511 
512 	void NotifyModifyAttempt(Document *document, void *userData);
513 	void NotifySavePoint(Document *document, void *userData, bool atSavePoint);
514 	void CheckModificationForWrap(DocModification mh);
515 	void NotifyModified(Document *document, DocModification mh, void *userData);
516 	void NotifyDeleted(Document *document, void *userData);
517 	void NotifyStyleNeeded(Document *doc, void *userData, int endPos);
518 	void NotifyLexerChanged(Document *doc, void *userData);
519 	void NotifyErrorOccurred(Document *doc, void *userData, int status);
520 	void NotifyMacroRecord(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
521 
522 	void ContainerNeedsUpdate(int flags);
523 	void PageMove(int direction, Selection::selTypes sel=Selection::noSel, bool stuttered = false);
524 	enum { cmSame, cmUpper, cmLower };
525 	virtual std::string CaseMapString(const std::string &s, int caseMapping);
526 	void ChangeCaseOfSelection(int caseMapping);
527 	void LineTranspose();
528 	void Duplicate(bool forLine);
529 	virtual void CancelModes();
530 	void NewLine();
531 	void CursorUpOrDown(int direction, Selection::selTypes sel=Selection::noSel);
532 	void ParaUpOrDown(int direction, Selection::selTypes sel=Selection::noSel);
533 	int StartEndDisplayLine(int pos, bool start);
534 	virtual int KeyCommand(unsigned int iMessage);
535 	virtual int KeyDefault(int /* key */, int /*modifiers*/);
536 	int KeyDownWithModifiers(int key, int modifiers, bool *consumed);
537 	int KeyDown(int key, bool shift, bool ctrl, bool alt, bool *consumed=0);
538 
539 	void Indent(bool forwards);
540 
541 	virtual CaseFolder *CaseFolderForEncoding();
542 	long FindText(uptr_t wParam, sptr_t lParam);
543 	void SearchAnchor();
544 	long SearchText(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
545 	long SearchInTarget(const char *text, int length);
546 	void GoToLine(int lineNo);
547 
548 	virtual void CopyToClipboard(const SelectionText &selectedText) = 0;
549 	std::string RangeText(int start, int end) const;
550 	void CopySelectionRange(SelectionText *ss, bool allowLineCopy=false);
551 	void CopyRangeToClipboard(int start, int end);
552 	void CopyText(int length, const char *text);
553 	void SetDragPosition(SelectionPosition newPos);
554 	virtual void DisplayCursor(Window::Cursor c);
555 	virtual bool DragThreshold(Point ptStart, Point ptNow);
556 	virtual void StartDrag();
557 	void DropAt(SelectionPosition position, const char *value, size_t lengthValue, bool moving, bool rectangular);
558 	void DropAt(SelectionPosition position, const char *value, bool moving, bool rectangular);
559 	/** PositionInSelection returns true if position in selection. */
560 	bool PositionInSelection(int pos);
561 	bool PointInSelection(Point pt);
562 	bool PointInSelMargin(Point pt);
563 	Window::Cursor GetMarginCursor(Point pt) const;
564 	void TrimAndSetSelection(int currentPos_, int anchor_);
565 	void LineSelection(int lineCurrentPos_, int lineAnchorPos_, bool wholeLine);
566 	void WordSelection(int pos);
567 	void DwellEnd(bool mouseMoved);
568 	void MouseLeave();
569 	virtual void ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt);
570 	void ButtonMoveWithModifiers(Point pt, int modifiers);
571 	void ButtonMove(Point pt);
572 	void ButtonUp(Point pt, unsigned int curTime, bool ctrl);
573 
574 	void Tick();
575 	bool Idle();
576 	virtual void SetTicking(bool on) = 0;
SetIdle(bool)577 	virtual bool SetIdle(bool) { return false; }
578 	virtual void SetMouseCapture(bool on) = 0;
579 	virtual bool HaveMouseCapture() = 0;
580 	void SetFocusState(bool focusState);
581 
582 	int PositionAfterArea(PRectangle rcArea) const;
583 	void StyleToPositionInView(Position pos);
584 	virtual void IdleWork();
585 	virtual void QueueIdleWork(WorkNeeded::workItems items, int upTo=0);
586 
587 	virtual bool PaintContains(PRectangle rc);
588 	bool PaintContainsMargin();
589 	void CheckForChangeOutsidePaint(Range r);
590 	void SetBraceHighlight(Position pos0, Position pos1, int matchStyle);
591 
592 	void SetAnnotationHeights(int start, int end);
593 	virtual void SetDocPointer(Document *document);
594 
595 	void SetAnnotationVisible(int visible);
596 
597 	int ExpandLine(int line);
598 	void SetFoldExpanded(int lineDoc, bool expanded);
599 	void FoldLine(int line, int action);
600 	void FoldExpand(int line, int action, int level);
601 	int ContractedFoldNext(int lineStart) const;
602 	void EnsureLineVisible(int lineDoc, bool enforcePolicy);
603 	void FoldChanged(int line, int levelNow, int levelPrev);
604 	void NeedShown(int pos, int len);
605 	void FoldAll(int action);
606 
607 	int GetTag(char *tagValue, int tagNumber);
608 	int ReplaceTarget(bool replacePatterns, const char *text, int length=-1);
609 
610 	bool PositionIsHotspot(int position) const;
611 	bool PointIsHotspot(Point pt);
612 	void SetHotSpotRange(Point *pt);
613 	void GetHotSpotRange(int &hsStart, int &hsEnd) const;
614 
615 	int CodePage() const;
ValidCodePage(int)616 	virtual bool ValidCodePage(int /* codePage */) const { return true; }
617 	int WrapCount(int line);
618 	void AddStyledText(char *buffer, int appendLength);
619 
620 	virtual sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) = 0;
621 	void StyleSetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
622 	sptr_t StyleGetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
623 
624 	static const char *StringFromEOLMode(int eolMode);
625 
626 	static sptr_t StringResult(sptr_t lParam, const char *val);
627 
628 public:
629 	// Public so the COM thunks can access it.
630 	bool IsUnicodeMode() const;
631 	// Public so scintilla_send_message can use it.
632 	virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
633 	// Public so scintilla_set_id can use it.
634 	int ctrlID;
635 	// Public so COM methods for drag and drop can set it.
636 	int errorStatus;
637 	friend class AutoSurface;
638 	friend class SelectionLineIterator;
639 };
640 
641 /**
642  * A smart pointer class to ensure Surfaces are set up and deleted correctly.
643  */
644 class AutoSurface {
645 private:
646 	Surface *surf;
647 public:
648 	AutoSurface(Editor *ed, int technology = -1) : surf(0) {
649 		if (ed->wMain.GetID()) {
650 			surf = Surface::Allocate(technology != -1 ? technology : ed->technology);
651 			if (surf) {
652 				surf->Init(ed->wMain.GetID());
653 				surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage());
654 				surf->SetDBCSMode(ed->CodePage());
655 			}
656 		}
657 	}
658 	AutoSurface(SurfaceID sid, Editor *ed, int technology = -1) : surf(0) {
659 		if (ed->wMain.GetID()) {
660 			surf = Surface::Allocate(technology != -1 ? technology : ed->technology);
661 			if (surf) {
662 				surf->Init(sid, ed->wMain.GetID());
663 				surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage());
664 				surf->SetDBCSMode(ed->CodePage());
665 			}
666 		}
667 	}
~AutoSurface()668 	~AutoSurface() {
669 		delete surf;
670 	}
671 	Surface *operator->() const {
672 		return surf;
673 	}
674 	operator Surface *() const {
675 		return surf;
676 	}
677 };
678 
679 #ifdef SCI_NAMESPACE
680 }
681 #endif
682 
683 #endif
684