From c914598dbaf12a1b6877f590604d5e4b8c0d439c Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Fri, 30 Dec 2016 18:29:43 +0100 Subject: [PATCH] Update Scintilla to version 3.7.2 --- scintilla/src/EditView.cxx | 5 ++- scintilla/src/EditView.h | 2 +- scintilla/src/Editor.cxx | 79 +++++++++++++++++++---------------- scintilla/src/Editor.h | 3 +- scintilla/src/PositionCache.h | 17 ++++++++ scintilla/version.txt | 2 +- 6 files changed, 67 insertions(+), 41 deletions(-) diff --git a/scintilla/src/EditView.cxx b/scintilla/src/EditView.cxx index 8ffc1bcf..5c622568 100644 --- a/scintilla/src/EditView.cxx +++ b/scintilla/src/EditView.cxx @@ -650,7 +650,7 @@ Range EditView::RangeDisplayLine(Surface *surface, const EditModel &model, int l return rangeSubLine; } -SelectionPosition EditView::SPositionFromLocation(Surface *surface, const EditModel &model, Point pt, bool canReturnInvalid, bool charPosition, bool virtualSpace, const ViewStyle &vs) { +SelectionPosition EditView::SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid, bool charPosition, bool virtualSpace, const ViewStyle &vs) { pt.x = pt.x - vs.textStart; int visibleLine = static_cast(floor(pt.y / vs.lineHeight)); if (!canReturnInvalid && (visibleLine < 0)) @@ -671,7 +671,8 @@ SelectionPosition EditView::SPositionFromLocation(Surface *surface, const EditMo const XYPOSITION subLineStart = ll->positions[rangeSubLine.start]; if (subLine > 0) // Wrapped pt.x -= ll->wrapIndent; - const int positionInLine = ll->FindPositionFromX(pt.x + subLineStart, rangeSubLine, charPosition); + const int positionInLine = ll->FindPositionFromX(static_cast(pt.x + subLineStart), + rangeSubLine, charPosition); if (positionInLine < rangeSubLine.end) { return SelectionPosition(model.pdoc->MovePositionOutsideChar(positionInLine + posLineStart, 1)); } diff --git a/scintilla/src/EditView.h b/scintilla/src/EditView.h index 83dd8bb1..8551daa3 100644 --- a/scintilla/src/EditView.h +++ b/scintilla/src/EditView.h @@ -114,7 +114,7 @@ public: Point LocationFromPosition(Surface *surface, const EditModel &model, SelectionPosition pos, int topLine, const ViewStyle &vs, PointEnd pe); Range RangeDisplayLine(Surface *surface, const EditModel &model, int lineVisible, const ViewStyle &vs); - SelectionPosition SPositionFromLocation(Surface *surface, const EditModel &model, Point pt, bool canReturnInvalid, + SelectionPosition SPositionFromLocation(Surface *surface, const EditModel &model, PointDocument pt, bool canReturnInvalid, bool charPosition, bool virtualSpace, const ViewStyle &vs); SelectionPosition SPositionFromLineX(Surface *surface, const EditModel &model, int lineDoc, int x, const ViewStyle &vs); int DisplayFromPosition(Surface *surface, const EditModel &model, int pos, const ViewStyle &vs); diff --git a/scintilla/src/Editor.cxx b/scintilla/src/Editor.cxx index 9c4e3949..8e4ebf18 100644 --- a/scintilla/src/Editor.cxx +++ b/scintilla/src/Editor.cxx @@ -283,8 +283,8 @@ Point Editor::GetVisibleOriginInMain() const { return Point(0,0); } -Point Editor::DocumentPointFromView(Point ptView) const { - Point ptDocument = ptView; +PointDocument Editor::DocumentPointFromView(Point ptView) const { + PointDocument ptDocument(ptView); if (wMargin.GetID()) { Point ptOrigin = GetVisibleOriginInMain(); ptDocument.x += ptOrigin.x; @@ -399,8 +399,8 @@ SelectionPosition Editor::SPositionFromLocation(Point pt, bool canReturnInvalid, if (pt.y < 0) return SelectionPosition(INVALID_POSITION); } - pt = DocumentPointFromView(pt); - return view.SPositionFromLocation(surface, *this, pt, canReturnInvalid, charPosition, virtualSpace, vs); + PointDocument ptdoc = DocumentPointFromView(pt); + return view.SPositionFromLocation(surface, *this, ptdoc, canReturnInvalid, charPosition, virtualSpace, vs); } int Editor::PositionFromLocation(Point pt, bool canReturnInvalid, bool charPosition) { @@ -5694,6 +5694,39 @@ sptr_t Editor::StyleGetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lPar return 0; } +void Editor::SetSelectionNMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { + InvalidateRange(sel.Range(wParam).Start().Position(), sel.Range(wParam).End().Position()); + + switch (iMessage) { + case SCI_SETSELECTIONNCARET: + sel.Range(wParam).caret.SetPosition(static_cast(lParam)); + break; + + case SCI_SETSELECTIONNANCHOR: + sel.Range(wParam).anchor.SetPosition(static_cast(lParam)); + break; + + case SCI_SETSELECTIONNCARETVIRTUALSPACE: + sel.Range(wParam).caret.SetVirtualSpace(static_cast(lParam)); + break; + + case SCI_SETSELECTIONNANCHORVIRTUALSPACE: + sel.Range(wParam).anchor.SetVirtualSpace(static_cast(lParam)); + break; + + case SCI_SETSELECTIONNSTART: + sel.Range(wParam).anchor.SetPosition(static_cast(lParam)); + break; + + case SCI_SETSELECTIONNEND: + sel.Range(wParam).caret.SetPosition(static_cast(lParam)); + break; + } + + InvalidateRange(sel.Range(wParam).Start().Position(), sel.Range(wParam).End().Position()); + ContainerNeedsUpdate(SC_UPDATE_SELECTION); +} + sptr_t Editor::StringResult(sptr_t lParam, const char *val) { const size_t len = val ? strlen(val) : 0; if (lParam) { @@ -7967,55 +8000,29 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { return sel.Main(); case SCI_SETSELECTIONNCARET: - sel.Range(wParam).caret.SetPosition(static_cast(lParam)); - ContainerNeedsUpdate(SC_UPDATE_SELECTION); - Redraw(); + case SCI_SETSELECTIONNANCHOR: + case SCI_SETSELECTIONNCARETVIRTUALSPACE: + case SCI_SETSELECTIONNANCHORVIRTUALSPACE: + case SCI_SETSELECTIONNSTART: + case SCI_SETSELECTIONNEND: + SetSelectionNMessage(iMessage, wParam, lParam); break; case SCI_GETSELECTIONNCARET: return sel.Range(wParam).caret.Position(); - case SCI_SETSELECTIONNANCHOR: - sel.Range(wParam).anchor.SetPosition(static_cast(lParam)); - ContainerNeedsUpdate(SC_UPDATE_SELECTION); - Redraw(); - break; case SCI_GETSELECTIONNANCHOR: return sel.Range(wParam).anchor.Position(); - case SCI_SETSELECTIONNCARETVIRTUALSPACE: - sel.Range(wParam).caret.SetVirtualSpace(static_cast(lParam)); - ContainerNeedsUpdate(SC_UPDATE_SELECTION); - Redraw(); - break; - case SCI_GETSELECTIONNCARETVIRTUALSPACE: return sel.Range(wParam).caret.VirtualSpace(); - case SCI_SETSELECTIONNANCHORVIRTUALSPACE: - sel.Range(wParam).anchor.SetVirtualSpace(static_cast(lParam)); - ContainerNeedsUpdate(SC_UPDATE_SELECTION); - Redraw(); - break; - case SCI_GETSELECTIONNANCHORVIRTUALSPACE: return sel.Range(wParam).anchor.VirtualSpace(); - case SCI_SETSELECTIONNSTART: - sel.Range(wParam).anchor.SetPosition(static_cast(lParam)); - ContainerNeedsUpdate(SC_UPDATE_SELECTION); - Redraw(); - break; - case SCI_GETSELECTIONNSTART: return sel.Range(wParam).Start().Position(); - case SCI_SETSELECTIONNEND: - sel.Range(wParam).caret.SetPosition(static_cast(lParam)); - ContainerNeedsUpdate(SC_UPDATE_SELECTION); - Redraw(); - break; - case SCI_GETSELECTIONNEND: return sel.Range(wParam).End().Position(); diff --git a/scintilla/src/Editor.h b/scintilla/src/Editor.h index 05250738..864bac94 100644 --- a/scintilla/src/Editor.h +++ b/scintilla/src/Editor.h @@ -275,7 +275,7 @@ protected: // ScintillaBase subclass needs access to much of Editor // The top left visible point in main window coordinates. Will be 0,0 except for // scroll views where it will be equivalent to the current scroll position. virtual Point GetVisibleOriginInMain() const; - Point DocumentPointFromView(Point ptView) const; // Convert a point from view space to document + PointDocument DocumentPointFromView(Point ptView) const; // Convert a point from view space to document int TopLineOfMain() const; // Return the line at Main's y coordinate 0 virtual PRectangle GetClientRectangle() const; virtual PRectangle GetClientDrawingRectangle(); @@ -577,6 +577,7 @@ protected: // ScintillaBase subclass needs access to much of Editor bool ValidMargin(uptr_t wParam) const; void StyleSetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam); sptr_t StyleGetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam); + void SetSelectionNMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam); static const char *StringFromEOLMode(int eolMode); diff --git a/scintilla/src/PositionCache.h b/scintilla/src/PositionCache.h index 5a829b76..c0d2b7f3 100644 --- a/scintilla/src/PositionCache.h +++ b/scintilla/src/PositionCache.h @@ -16,6 +16,23 @@ static inline bool IsEOLChar(char ch) { return (ch == '\r') || (ch == '\n'); } +/** +* A point in document space. +* Uses double for sufficient resolution in large (>20,000,000 line) documents. +*/ +class PointDocument { +public: + double x; + double y; + + explicit PointDocument(double x_ = 0, double y_ = 0) : x(x_), y(y_) { + } + + // Conversion from Point. + explicit PointDocument(Point pt) : x(pt.x), y(pt.y) { + } +}; + // There are two points for some positions and this enumeration // can choose between the end of the first line or subline // and the start of the next line or subline. diff --git a/scintilla/version.txt b/scintilla/version.txt index 67bf40fe..ba300673 100644 --- a/scintilla/version.txt +++ b/scintilla/version.txt @@ -1 +1 @@ -371 +372