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