diff options
author | Neil <nyamatongwe@gmail.com> | 2014-06-23 17:03:49 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2014-06-23 17:03:49 +1000 |
commit | 4bbf7d16f03b48ddd4d2184bc21cb98889b64899 (patch) | |
tree | 7e1da5c1a9de988de16dff4e5f38ececb707c898 /src | |
parent | 3b5496d80c0fb79ebad20d7253b944a072d5cd7f (diff) | |
download | scintilla-mirror-4bbf7d16f03b48ddd4d2184bc21cb98889b64899.tar.gz |
Use Range type for hotspot to simplify manipulation.
Diffstat (limited to 'src')
-rw-r--r-- | src/Document.h | 4 | ||||
-rw-r--r-- | src/Editor.cxx | 48 | ||||
-rw-r--r-- | src/Editor.h | 5 | ||||
-rw-r--r-- | src/PositionCache.cxx | 3 | ||||
-rw-r--r-- | src/PositionCache.h | 3 |
5 files changed, 28 insertions, 35 deletions
diff --git a/src/Document.h b/src/Document.h index 8212db674..a59f192a9 100644 --- a/src/Document.h +++ b/src/Document.h @@ -39,6 +39,10 @@ public: start(start_), end(end_) { } + bool operator==(const Range &other) const { + return (start == other.start) && (end == other.end); + } + bool Valid() const { return (start != invalidPosition) && (end != invalidPosition); } diff --git a/src/Editor.cxx b/src/Editor.cxx index 041a9c6a5..cba4e091b 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -220,8 +220,7 @@ Editor::Editor() { convertPastes = true; - hsStart = -1; - hsEnd = -1; + hotspot = Range(invalidPosition); llc.SetLevel(LineLayoutCache::llcCaret); posCache.SetSize(0x400); @@ -2920,7 +2919,7 @@ void Editor::DrawLine(Surface *surface, const ViewStyle &vsDraw, int line, int l rcSegment.right = rcLine.right; const int inSelection = hideSelection ? 0 : sel.CharacterInSelection(iDoc); - const bool inHotspot = (ll->hsStart != -1) && (iDoc >= ll->hsStart) && (iDoc < ll->hsEnd); + const bool inHotspot = (ll->hotspot.Valid()) && ll->hotspot.ContainsCharacter(iDoc); ColourDesired textBack = TextBackground(vsDraw, overrideBackground, background, inSelection, inHotspot, ll->styles[i], i, ll); if (ts.representation) { @@ -3010,7 +3009,8 @@ void Editor::DrawLine(Surface *surface, const ViewStyle &vsDraw, int line, int l ColourDesired textFore = vsDraw.styles[styleMain].fore; FontAlias textFont = vsDraw.styles[styleMain].font; //hotspot foreground - if (ll->hsStart != -1 && iDoc >= ll->hsStart && iDoc < hsEnd) { + const bool inHotspot = (ll->hotspot.Valid()) && ll->hotspot.ContainsCharacter(iDoc); + if (inHotspot) { if (vsDraw.hotspotColours.fore.isSet) textFore = vsDraw.hotspotColours.fore; } @@ -3018,7 +3018,6 @@ void Editor::DrawLine(Surface *surface, const ViewStyle &vsDraw, int line, int l if (inSelection && (vsDraw.selColours.fore.isSet)) { textFore = (inSelection == 1) ? vsDraw.selColours.fore : vsDraw.selAdditionalForeground; } - const bool inHotspot = (ll->hsStart != -1) && (iDoc >= ll->hsStart) && (iDoc < ll->hsEnd); ColourDesired textBack = TextBackground(vsDraw, overrideBackground, background, inSelection, inHotspot, styleMain, i, ll); if (ts.representation) { if (ll->chars[i] == '\t') { @@ -3117,7 +3116,7 @@ void Editor::DrawLine(Surface *surface, const ViewStyle &vsDraw, int line, int l } } } - if (ll->hsStart != -1 && vsDraw.hotspotUnderline && iDoc >= ll->hsStart && iDoc < ll->hsEnd) { + if (ll->hotspot.Valid() && vsDraw.hotspotUnderline && ll->hotspot.ContainsCharacter(iDoc)) { PRectangle rcUL = rcSegment; rcUL.top = rcUL.top + vsDraw.maxAscent + 1; rcUL.bottom = rcUL.top + 1; @@ -3620,7 +3619,7 @@ void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) { ll->containsCaret = false; } - GetHotSpotRange(ll->hsStart, ll->hsEnd); + ll->hotspot = GetHotSpotRange(); PRectangle rcLine = rcTextArea; rcLine.top = static_cast<XYPOSITION>(ypos); @@ -6519,35 +6518,28 @@ void Editor::SetHotSpotRange(Point *pt) { // If we don't limit this to word characters then the // range can encompass more than the run range and then // the underline will not be drawn properly. - int hsStart_ = pdoc->ExtendStyleRange(pos, -1, vs.hotspotSingleLine); - int hsEnd_ = pdoc->ExtendStyleRange(pos, 1, vs.hotspotSingleLine); + Range hsNew; + hsNew.start = pdoc->ExtendStyleRange(pos, -1, vs.hotspotSingleLine); + hsNew.end = pdoc->ExtendStyleRange(pos, 1, vs.hotspotSingleLine); // Only invalidate the range if the hotspot range has changed... - if (hsStart_ != hsStart || hsEnd_ != hsEnd) { - if (hsStart != -1) { - InvalidateRange(hsStart, hsEnd); + if (!(hsNew == hotspot)) { + if (hotspot.Valid()) { + InvalidateRange(hotspot.start, hotspot.end); } - hsStart = hsStart_; - hsEnd = hsEnd_; - InvalidateRange(hsStart, hsEnd); + hotspot = hsNew; + InvalidateRange(hotspot.start, hotspot.end); } } else { - if (hsStart != -1) { - int hsStart_ = hsStart; - int hsEnd_ = hsEnd; - hsStart = -1; - hsEnd = -1; - InvalidateRange(hsStart_, hsEnd_); - } else { - hsStart = -1; - hsEnd = -1; + if (hotspot.Valid()) { + InvalidateRange(hotspot.start, hotspot.end); } + hotspot = Range(invalidPosition); } } -void Editor::GetHotSpotRange(int &hsStart_, int &hsEnd_) const { - hsStart_ = hsStart; - hsEnd_ = hsEnd; +Range Editor::GetHotSpotRange() const { + return hotspot; } void Editor::ButtonMoveWithModifiers(Point pt, int modifiers) { @@ -6634,7 +6626,7 @@ void Editor::ButtonMoveWithModifiers(Point pt, int modifiers) { } EnsureCaretVisible(false, false, true); - if (hsStart != -1 && !PointIsHotspot(pt)) + if (hotspot.Valid() && !PointIsHotspot(pt)) SetHotSpotRange(NULL); if (hotSpotClickPos != INVALID_POSITION && PositionFromLocation(pt,true,true) != hotSpotClickPos) { diff --git a/src/Editor.h b/src/Editor.h index 4826a1852..6c7ae6c59 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -309,8 +309,7 @@ protected: // ScintillaBase subclass needs access to much of Editor ContractionState cs; // Hotspot support - int hsStart; - int hsEnd; + Range hotspot; // Wrapping support int wrapWidth; @@ -623,7 +622,7 @@ protected: // ScintillaBase subclass needs access to much of Editor bool PositionIsHotspot(int position) const; bool PointIsHotspot(Point pt); void SetHotSpotRange(Point *pt); - void GetHotSpotRange(int &hsStart, int &hsEnd) const; + Range GetHotSpotRange() const; int CodePage() const; virtual bool ValidCodePage(int /* codePage */) const { return true; } diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index b81fe5930..9e55c1a82 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -59,8 +59,7 @@ LineLayout::LineLayout(int maxLineLength_) : chars(0), styles(0), positions(0), - hsStart(0), - hsEnd(0), + hotspot(0,0), widthLine(wrapWidthInfinite), lines(1), wrapIndent(0) { diff --git a/src/PositionCache.h b/src/PositionCache.h index 64ccfda34..05005e9ac 100644 --- a/src/PositionCache.h +++ b/src/PositionCache.h @@ -42,8 +42,7 @@ public: char bracePreviousStyles[2]; // Hotspot support - int hsStart; - int hsEnd; + Range hotspot; // Wrapped line support int widthLine; |