From c11b33236bcd09928bce17eaef11951a77a84abe Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Sun, 2 Jan 2011 18:02:04 +1100 Subject: Send SCN_UPDATEUI notification when view scrolled. Satisfies feature request #3125977. Also includes an updated field in notification so that updates of no interest can be easily ignored. --- doc/ScintillaDoc.html | 63 +++++++++++++++++++++++++++++++++++++++++++------ include/Scintilla.h | 5 ++++ include/Scintilla.iface | 5 ++++ src/Editor.cxx | 26 +++++++++++++++----- src/Editor.h | 3 ++- 5 files changed, 88 insertions(+), 14 deletions(-) diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index f120e29f1..b8c2a38ae 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -5687,6 +5687,9 @@ struct SCNotification { int listType; // SCN_USERLISTSELECTION, SCN_AUTOCSELECTION int x; // SCN_DWELLSTART, SCN_DWELLEND int y; // SCN_DWELLSTART, SCN_DWELLEND + int token; // SCN_MODIFIED with SC_MOD_CONTAINER + int annotationLinesAdded; // SC_MOD_CHANGEANNOTATION + int updated; // SCN_UPDATEUI }; @@ -5787,13 +5790,59 @@ href="#SCI_POSITIONFROMLINE">SCI_POSITIONFROMLINE(lineNumber); double click and the line field is set to the line of the double click.

SCN_UPDATEUI
- Either the text or styling of the document has changed or the selection range has changed. Now - would be a good time to update any container UI elements that depend on document or view state. - This was previously called SCN_CHECKBRACE because a common use is to check whether the - caret is next to a brace and set highlights on this brace and its corresponding matching brace. - This also replaces SCN_POSCHANGED, - which is now deprecated.

+ Either the text or styling of the document has changed or the selection range or scroll position has changed. + Now would be a good time to update any container UI elements that depend on document or view state. + The updated field is set to the bit set of things changed since the previous notiication.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SymbolValueMeaning
SC_UPDATE_CONTENT0x01Contents, styling or markers have been changed.
SC_UPDATE_SELECTION0x02Selection has been changed.
SC_UPDATE_V_SCROLL0x04Scrolled vertically.
SC_UPDATE_H_SCROLL0x08Scrolled horizontally.

SCN_MODIFIED
This notification is sent when the text or styling of the document changes or is about to diff --git a/include/Scintilla.h b/include/Scintilla.h index 0e1159b53..c0bb32332 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -832,6 +832,10 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_MOD_CONTAINER 0x40000 #define SC_MOD_LEXERSTATE 0x80000 #define SC_MODEVENTMASKALL 0xFFFFF +#define SC_UPDATE_CONTENT 0x1 +#define SC_UPDATE_SELECTION 0x2 +#define SC_UPDATE_V_SCROLL 0x4 +#define SC_UPDATE_H_SCROLL 0x8 #define SCEN_CHANGE 768 #define SCEN_SETFOCUS 512 #define SCEN_KILLFOCUS 256 @@ -971,6 +975,7 @@ struct SCNotification { int y; /* SCN_DWELLSTART, SCN_DWELLEND */ int token; /* SCN_MODIFIED with SC_MOD_CONTAINER */ int annotationLinesAdded; /* SC_MOD_CHANGEANNOTATION */ + int updated; /* SCN_UPDATEUI */ }; #ifdef SCI_NAMESPACE diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 405fc0552..1a81aca98 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -2193,6 +2193,11 @@ val SC_MOD_CONTAINER=0x40000 val SC_MOD_LEXERSTATE=0x80000 val SC_MODEVENTMASKALL=0xFFFFF +val SC_UPDATE_CONTENT=0x1 +val SC_UPDATE_SELECTION=0x2 +val SC_UPDATE_V_SCROLL=0x4 +val SC_UPDATE_H_SCROLL=0x8 + # For compatibility, these go through the COMMAND notification rather than NOTIFY # and should have had exactly the same values as the EN_* constants. # Unfortunately the SETFOCUS and KILLFOCUS are flipped over from EN_* diff --git a/src/Editor.cxx b/src/Editor.cxx index e9a30ee72..89c67b433 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -175,7 +175,8 @@ Editor::Editor() { lengthForEncode = -1; - needUpdateUI = true; + needUpdateUI = 0; + ContainerNeedsUpdate(SC_UPDATE_CONTENT); braces[0] = invalidPosition; braces[1] = invalidPosition; bracesMatchStyle = STYLE_BRACEBAD; @@ -434,7 +435,10 @@ int Editor::LineFromLocation(Point pt) { } void Editor::SetTopLine(int topLineNew) { - topLine = topLineNew; + if (topLine != topLineNew) { + topLine = topLineNew; + ContainerNeedsUpdate(SC_UPDATE_V_SCROLL); + } posTopLine = pdoc->LineStart(cs.DocFromDisplay(topLine)); } @@ -741,7 +745,7 @@ void Editor::InvalidateSelection(SelectionRange newMain, bool invalidateWholeSel lastAffected = Platform::Maximum(lastAffected, sel.Range(r).anchor.Position()); } } - needUpdateUI = true; + ContainerNeedsUpdate(SC_UPDATE_SELECTION); InvalidateRange(firstAffected, lastAffected); } @@ -982,6 +986,7 @@ void Editor::HorizontalScrollTo(int xPos) { xPos = 0; if ((wrapState == eWrapNone) && (xOffset != xPos)) { xOffset = xPos; + ContainerNeedsUpdate(SC_UPDATE_H_SCROLL); SetHorizontalScrollPos(); RedrawRect(GetClientRectangle()); } @@ -1291,6 +1296,7 @@ void Editor::SetXYScroll(XYScrollPosition newXY) { } if (newXY.xOffset != xOffset) { xOffset = newXY.xOffset; + ContainerNeedsUpdate(SC_UPDATE_H_SCROLL); if (newXY.xOffset > 0) { PRectangle rcText = GetTextRectangle(); if (horizontalScrollBarVisible && @@ -3307,7 +3313,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { surfaceWindow->SetPalette(&palTemp, true); NotifyUpdateUI(); - needUpdateUI = false; + needUpdateUI = 0; RefreshStyleData(); RefreshPixMaps(surfaceWindow); @@ -4213,6 +4219,7 @@ void Editor::NotifyHotSpotReleaseClick(int position, bool shift, bool ctrl, bool void Editor::NotifyUpdateUI() { SCNotification scn = {0}; scn.nmhdr.code = SCN_UPDATEUI; + scn.updated = needUpdateUI; NotifyParent(scn); } @@ -4329,7 +4336,7 @@ static inline int MovePositionForDeletion(int position, int startDeletion, int l } void Editor::NotifyModified(Document *, DocModification mh, void *) { - needUpdateUI = true; + ContainerNeedsUpdate(SC_UPDATE_CONTENT); if (paintState == painting) { CheckForChangeOutsidePaint(Range(mh.position, mh.position + mh.length)); } @@ -4611,6 +4618,11 @@ void Editor::NotifyMacroRecord(unsigned int iMessage, uptr_t wParam, sptr_t lPar NotifyParent(scn); } +// Something has changed that the container should know about +void Editor::ContainerNeedsUpdate(int flags) { + needUpdateUI |= flags; +} + /** * Force scroll and keep position relative to top of window. * @@ -6338,7 +6350,7 @@ void Editor::IdleStyling() { if (needUpdateUI) { NotifyUpdateUI(); - needUpdateUI = false; + needUpdateUI = 0; } styleNeeded.Reset(); } @@ -6995,6 +7007,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_SETXOFFSET: xOffset = wParam; + ContainerNeedsUpdate(SC_UPDATE_H_SCROLL); SetHorizontalScrollPos(); Redraw(); break; @@ -7459,6 +7472,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { break; } xOffset = 0; + ContainerNeedsUpdate(SC_UPDATE_H_SCROLL); InvalidateStyleRedraw(); ReconfigureScrollBars(); break; diff --git a/src/Editor.h b/src/Editor.h index 288addee0..a618e1e40 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -208,7 +208,7 @@ protected: // ScintillaBase subclass needs access to much of Editor int posTopLine; int lengthForEncode; - bool needUpdateUI; + int needUpdateUI; Position braces[2]; int bracesMatchStyle; int highlightGuideColumn; @@ -438,6 +438,7 @@ protected: // ScintillaBase subclass needs access to much of Editor void NotifyErrorOccurred(Document *doc, void *userData, int status); void NotifyMacroRecord(unsigned int iMessage, uptr_t wParam, sptr_t lParam); + void ContainerNeedsUpdate(int flags); void PageMove(int direction, Selection::selTypes sel=Selection::noSel, bool stuttered = false); enum { cmSame, cmUpper, cmLower } caseMap; virtual std::string CaseMapString(const std::string &s, int caseMapping); -- cgit v1.2.3