aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DBCS.cxx48
-rw-r--r--src/DBCS.h21
-rw-r--r--src/Document.cxx2
-rw-r--r--src/Editor.cxx99
-rw-r--r--src/Position.h8
-rw-r--r--src/ViewStyle.cxx2
6 files changed, 131 insertions, 49 deletions
diff --git a/src/DBCS.cxx b/src/DBCS.cxx
new file mode 100644
index 000000000..46cee8e69
--- /dev/null
+++ b/src/DBCS.cxx
@@ -0,0 +1,48 @@
+// Scintilla source code edit control
+/** @file DBCS.cxx
+ ** Functions to handle DBCS double byte encodings like Shift-JIS.
+ **/
+// Copyright 2017 by Neil Hodgson <neilh@scintilla.org>
+// The License.txt file describes the conditions under which this software may be distributed.
+
+#include "DBCS.h"
+
+#ifdef SCI_NAMESPACE
+using namespace Scintilla;
+#endif
+
+#ifdef SCI_NAMESPACE
+namespace Scintilla {
+#endif
+
+bool DBCSIsLeadByte(int codePage, char ch) {
+ // Byte ranges found in Wikipedia articles with relevant search strings in each case
+ const unsigned char uch = static_cast<unsigned char>(ch);
+ switch (codePage) {
+ case 932:
+ // Shift_jis
+ return ((uch >= 0x81) && (uch <= 0x9F)) ||
+ ((uch >= 0xE0) && (uch <= 0xFC));
+ // Lead bytes F0 to FC may be a Microsoft addition.
+ case 936:
+ // GBK
+ return (uch >= 0x81) && (uch <= 0xFE);
+ case 949:
+ // Korean Wansung KS C-5601-1987
+ return (uch >= 0x81) && (uch <= 0xFE);
+ case 950:
+ // Big5
+ return (uch >= 0x81) && (uch <= 0xFE);
+ case 1361:
+ // Korean Johab KS C-5601-1992
+ return
+ ((uch >= 0x84) && (uch <= 0xD3)) ||
+ ((uch >= 0xD8) && (uch <= 0xDE)) ||
+ ((uch >= 0xE0) && (uch <= 0xF9));
+ }
+ return false;
+}
+
+#ifdef SCI_NAMESPACE
+}
+#endif
diff --git a/src/DBCS.h b/src/DBCS.h
new file mode 100644
index 000000000..875d44c8f
--- /dev/null
+++ b/src/DBCS.h
@@ -0,0 +1,21 @@
+// Scintilla source code edit control
+/** @file DBCS.h
+ ** Functions to handle DBCS double byte encodings like Shift-JIS.
+ **/
+// Copyright 2017 by Neil Hodgson <neilh@scintilla.org>
+// The License.txt file describes the conditions under which this software may be distributed.
+
+#ifndef DBCS_H
+#define DBCS_H
+
+#ifdef SCI_NAMESPACE
+namespace Scintilla {
+#endif
+
+bool DBCSIsLeadByte(int codePage, char ch);
+
+#ifdef SCI_NAMESPACE
+}
+#endif
+
+#endif
diff --git a/src/Document.cxx b/src/Document.cxx
index 231bc1113..3beba76e9 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -564,7 +564,7 @@ void Document::GetHighlightDelimiters(HighlightDelimiter &highlightDelimiter, Sc
}
Sci::Position Document::ClampPositionIntoDocument(Sci::Position pos) const {
- return Platform::Clamp(pos, 0, Length());
+ return Sci::clamp(pos, 0, Length());
}
bool Document::IsCrLf(Sci::Position pos) const {
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 1dfb8d9e3..771353654 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -888,10 +888,10 @@ SelectionPosition Editor::MovePositionSoVisible(SelectionPosition pos, int moveD
Sci::Line lineDisplay = cs.DisplayFromDoc(lineDoc);
if (moveDir > 0) {
// lineDisplay is already line before fold as lines in fold use display line of line after fold
- lineDisplay = Platform::Clamp(lineDisplay, 0, cs.LinesDisplayed());
+ lineDisplay = Sci::clamp(lineDisplay, 0, cs.LinesDisplayed());
return SelectionPosition(pdoc->LineStart(cs.DocFromDisplay(lineDisplay)));
} else {
- lineDisplay = Platform::Clamp(lineDisplay - 1, 0, cs.LinesDisplayed());
+ lineDisplay = Sci::clamp(lineDisplay - 1, 0, cs.LinesDisplayed());
return SelectionPosition(pdoc->LineEnd(cs.DocFromDisplay(lineDisplay)));
}
}
@@ -915,7 +915,7 @@ void Editor::SetLastXChosen() {
}
void Editor::ScrollTo(Sci::Line line, bool moveThumb) {
- const Sci::Line topLineNew = Platform::Clamp(line, 0, MaxScrollPos());
+ const Sci::Line topLineNew = Sci::clamp(line, 0, MaxScrollPos());
if (topLineNew != topLine) {
// Try to optimise small scrolls
#ifndef UNDER_CE
@@ -1154,7 +1154,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran
} else {
// yMarginT must equal to caretYSlop, with a minimum of 1 and
// a maximum of slightly less than half the heigth of the text area.
- yMarginT = Platform::Clamp(caretYSlop, 1, halfScreen);
+ yMarginT = Sci::clamp(caretYSlop, 1, halfScreen);
if (bEven) {
yMarginB = yMarginT;
} else {
@@ -1164,7 +1164,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran
yMoveT = yMarginT;
if (bEven) {
if (bJump) {
- yMoveT = Platform::Clamp(caretYSlop * 3, 1, halfScreen);
+ yMoveT = Sci::clamp(caretYSlop * 3, 1, halfScreen);
}
yMoveB = yMoveT;
} else {
@@ -1179,7 +1179,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran
}
} else { // Not strict
yMoveT = bJump ? caretYSlop * 3 : caretYSlop;
- yMoveT = Platform::Clamp(yMoveT, 1, halfScreen);
+ yMoveT = Sci::clamp(yMoveT, 1, halfScreen);
if (bEven) {
yMoveB = yMoveT;
} else {
@@ -1229,7 +1229,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran
newXY.topLine = std::min(newXY.topLine, lineCaret);
}
}
- newXY.topLine = Platform::Clamp(newXY.topLine, 0, MaxScrollPos());
+ newXY.topLine = Sci::clamp(newXY.topLine, 0, MaxScrollPos());
}
// Horizontal positioning
@@ -1251,7 +1251,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran
} else {
// xMargin must equal to caretXSlop, with a minimum of 2 and
// a maximum of slightly less than half the width of the text area.
- xMarginR = Platform::Clamp(caretXSlop, 2, halfScreen);
+ xMarginR = Sci::clamp(caretXSlop, 2, halfScreen);
if (bEven) {
xMarginL = xMarginR;
} else {
@@ -1260,7 +1260,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran
}
if (bJump && bEven) {
// Jump is used only in even mode
- xMoveL = xMoveR = Platform::Clamp(caretXSlop * 3, 1, halfScreen);
+ xMoveL = xMoveR = Sci::clamp(caretXSlop * 3, 1, halfScreen);
} else {
xMoveL = xMoveR = 0; // Not used, avoid a warning
}
@@ -1283,7 +1283,7 @@ Editor::XYScrollPosition Editor::XYScrollToMakeVisible(const SelectionRange &ran
}
} else { // Not strict
xMoveR = bJump ? caretXSlop * 3 : caretXSlop;
- xMoveR = Platform::Clamp(xMoveR, 1, halfScreen);
+ xMoveR = Sci::clamp(xMoveR, 1, halfScreen);
if (bEven) {
xMoveL = xMoveR;
} else {
@@ -1505,7 +1505,7 @@ bool Editor::WrapLines(WrapScope ws) {
const Sci::Line lineDocTop = cs.DocFromDisplay(topLine);
const int subLineTop = topLine - cs.DisplayFromDoc(lineDocTop);
if (ws == WrapScope::wsVisible) {
- lineToWrap = Platform::Clamp(lineDocTop-5, wrapPending.start, pdoc->LinesTotal());
+ lineToWrap = Sci::clamp(lineDocTop-5, wrapPending.start, pdoc->LinesTotal());
// Priority wrap to just after visible area.
// Since wrapping could reduce display lines, treat each
// as taking only one display line.
@@ -1561,7 +1561,7 @@ bool Editor::WrapLines(WrapScope ws) {
if (wrapOccurred) {
SetScrollBars();
- SetTopLine(Platform::Clamp(goodTopLine, 0, MaxScrollPos()));
+ SetTopLine(Sci::clamp(goodTopLine, 0, MaxScrollPos()));
SetVerticalScrollPos();
}
@@ -1816,7 +1816,7 @@ void Editor::SetScrollBars() {
// TODO: ensure always showing as many lines as possible
// May not be, if, for example, window made larger
if (topLine > MaxScrollPos()) {
- SetTopLine(Platform::Clamp(topLine, 0, MaxScrollPos()));
+ SetTopLine(Sci::clamp(topLine, 0, MaxScrollPos()));
SetVerticalScrollPos();
Redraw();
}
@@ -2641,7 +2641,7 @@ void Editor::NotifyModified(Document *, DocModification mh, void *) {
if (mh.linesAdded != 0) {
// Avoid scrolling of display if change before current display
if (mh.position < posTopLine && !CanDeferToLastStep(mh)) {
- Sci::Line newTop = Platform::Clamp(topLine + mh.linesAdded, 0, MaxScrollPos());
+ Sci::Line newTop = Sci::clamp(topLine + mh.linesAdded, 0, MaxScrollPos());
if (newTop != topLine) {
SetTopLine(newTop);
SetVerticalScrollPos();
@@ -2877,7 +2877,7 @@ void Editor::PageMove(int direction, Selection::selTypes selt, bool stuttered) {
} else {
Point pt = LocationFromPosition(sel.MainCaret());
- topLineNew = Platform::Clamp(
+ topLineNew = Sci::clamp(
topLine + direction * LinesToScroll(), 0, MaxScrollPos());
newPos = SPositionFromLocation(
Point::FromInts(lastXChosen - xOffset, static_cast<int>(pt.y) + direction * (vs.lineHeight * LinesToScroll())),
@@ -3209,6 +3209,14 @@ Sci::Position Editor::StartEndDisplayLine(Sci::Position pos, bool start) {
namespace {
+short HighShortFromLong(long x) {
+ return static_cast<short>(x >> 16);
+}
+
+short LowShortFromLong(long x) {
+ return static_cast<short>(x & 0xffff);
+}
+
unsigned int WithExtends(unsigned int iMessage) {
switch (iMessage) {
case SCI_CHARLEFT: return SCI_CHARLEFTEXTEND;
@@ -4470,30 +4478,27 @@ void Editor::ButtonDownWithModifiers(Point pt, unsigned int curTime, int modifie
if (!ctrl || !multipleSelection || (selectionType != selChar && selectionType != selWord))
SetEmptySelection(newPos.Position());
bool doubleClick = false;
- // Stop mouse button bounce changing selection type
- if (!Platform::MouseButtonBounce() || curTime != lastClickTime) {
- if (inSelMargin) {
- // Inside margin selection type should be either selSubLine or selWholeLine.
- if (selectionType == selSubLine) {
- // If it is selSubLine, we're inside a *double* click and word wrap is enabled,
- // so we switch to selWholeLine in order to select whole line.
- selectionType = selWholeLine;
- } else if (selectionType != selSubLine && selectionType != selWholeLine) {
- // If it is neither, reset selection type to line selection.
- selectionType = (Wrapping() && (marginOptions & SC_MARGINOPTION_SUBLINESELECT)) ? selSubLine : selWholeLine;
- }
+ if (inSelMargin) {
+ // Inside margin selection type should be either selSubLine or selWholeLine.
+ if (selectionType == selSubLine) {
+ // If it is selSubLine, we're inside a *double* click and word wrap is enabled,
+ // so we switch to selWholeLine in order to select whole line.
+ selectionType = selWholeLine;
+ } else if (selectionType != selSubLine && selectionType != selWholeLine) {
+ // If it is neither, reset selection type to line selection.
+ selectionType = (Wrapping() && (marginOptions & SC_MARGINOPTION_SUBLINESELECT)) ? selSubLine : selWholeLine;
+ }
+ } else {
+ if (selectionType == selChar) {
+ selectionType = selWord;
+ doubleClick = true;
+ } else if (selectionType == selWord) {
+ // Since we ended up here, we're inside a *triple* click, which should always select
+ // whole line regardless of word wrap being enabled or not.
+ selectionType = selWholeLine;
} else {
- if (selectionType == selChar) {
- selectionType = selWord;
- doubleClick = true;
- } else if (selectionType == selWord) {
- // Since we ended up here, we're inside a *triple* click, which should always select
- // whole line regardless of word wrap being enabled or not.
- selectionType = selWholeLine;
- } else {
- selectionType = selChar;
- originalAnchorPos = sel.MainCaret();
- }
+ selectionType = selChar;
+ originalAnchorPos = sel.MainCaret();
}
}
@@ -5082,7 +5087,7 @@ Sci::Position Editor::PositionAfterMaxStyling(Sci::Position posMax, bool scrolli
// When scrolling, allow less time to ensure responsive
const double secondsAllowed = scrolling ? 0.005 : 0.02;
- const Sci::Line linesToStyle = Platform::Clamp(static_cast<int>(secondsAllowed / pdoc->durationStyleOneLine),
+ const Sci::Line linesToStyle = Sci::clamp(static_cast<int>(secondsAllowed / pdoc->durationStyleOneLine),
10, 0x10000);
const Sci::Line stylingMaxLine = std::min(
static_cast<Sci::Line>(pdoc->LineFromPosition(pdoc->GetEndStyled()) + linesToStyle),
@@ -5426,18 +5431,18 @@ void Editor::EnsureLineVisible(Sci::Line lineDoc, bool enforcePolicy) {
const Sci::Line lineDisplay = cs.DisplayFromDoc(lineDoc);
if (visiblePolicy & VISIBLE_SLOP) {
if ((topLine > lineDisplay) || ((visiblePolicy & VISIBLE_STRICT) && (topLine + visibleSlop > lineDisplay))) {
- SetTopLine(Platform::Clamp(lineDisplay - visibleSlop, 0, MaxScrollPos()));
+ SetTopLine(Sci::clamp(lineDisplay - visibleSlop, 0, MaxScrollPos()));
SetVerticalScrollPos();
Redraw();
} else if ((lineDisplay > topLine + LinesOnScreen() - 1) ||
((visiblePolicy & VISIBLE_STRICT) && (lineDisplay > topLine + LinesOnScreen() - 1 - visibleSlop))) {
- SetTopLine(Platform::Clamp(lineDisplay - LinesOnScreen() + 1 + visibleSlop, 0, MaxScrollPos()));
+ SetTopLine(Sci::clamp(lineDisplay - LinesOnScreen() + 1 + visibleSlop, 0, MaxScrollPos()));
SetVerticalScrollPos();
Redraw();
}
} else {
if ((topLine > lineDisplay) || (lineDisplay > topLine + LinesOnScreen() - 1) || (visiblePolicy & VISIBLE_STRICT)) {
- SetTopLine(Platform::Clamp(lineDisplay - LinesOnScreen() / 2 + 1, 0, MaxScrollPos()));
+ SetTopLine(Sci::clamp(lineDisplay - LinesOnScreen() / 2 + 1, 0, MaxScrollPos()));
SetVerticalScrollPos();
Redraw();
}
@@ -6040,7 +6045,7 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
return pdoc->MovePositionOutsideChar(static_cast<int>(wParam) + 1, 1, true);
case SCI_POSITIONRELATIVE:
- return Platform::Clamp(pdoc->GetRelativePosition(static_cast<int>(wParam), static_cast<int>(lParam)), 0, pdoc->Length());
+ return Sci::clamp(pdoc->GetRelativePosition(static_cast<int>(wParam), static_cast<int>(lParam)), 0, pdoc->Length());
case SCI_LINESCROLL:
ScrollTo(topLine + static_cast<Sci::Line>(lParam));
@@ -7290,13 +7295,13 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
return vs.caretWidth;
case SCI_ASSIGNCMDKEY:
- kmap.AssignCmdKey(Platform::LowShortFromLong(static_cast<long>(wParam)),
- Platform::HighShortFromLong(static_cast<long>(wParam)), static_cast<unsigned int>(lParam));
+ kmap.AssignCmdKey(LowShortFromLong(static_cast<long>(wParam)),
+ HighShortFromLong(static_cast<long>(wParam)), static_cast<unsigned int>(lParam));
break;
case SCI_CLEARCMDKEY:
- kmap.AssignCmdKey(Platform::LowShortFromLong(static_cast<long>(wParam)),
- Platform::HighShortFromLong(static_cast<long>(wParam)), SCI_NULL);
+ kmap.AssignCmdKey(LowShortFromLong(static_cast<long>(wParam)),
+ HighShortFromLong(static_cast<long>(wParam)), SCI_NULL);
break;
case SCI_CLEARALLCMDKEYS:
diff --git a/src/Position.h b/src/Position.h
index 67365e30f..258eb177f 100644
--- a/src/Position.h
+++ b/src/Position.h
@@ -25,6 +25,14 @@ typedef int Line;
const Position invalidPosition = -1;
+inline int clamp(int val, int minVal, int maxVal) {
+ if (val > maxVal)
+ val = maxVal;
+ if (val < minVal)
+ val = minVal;
+ return val;
+}
+
}
#endif
diff --git a/src/ViewStyle.cxx b/src/ViewStyle.cxx
index 7a0b146f8..771d4a8f4 100644
--- a/src/ViewStyle.cxx
+++ b/src/ViewStyle.cxx
@@ -460,7 +460,7 @@ void ViewStyle::CalcLargestMarkerHeight() {
}
int ViewStyle::GetFrameWidth() const {
- return Platform::Clamp(caretLineFrame, 1, lineHeight / 3);
+ return Sci::clamp(caretLineFrame, 1, lineHeight / 3);
}
bool ViewStyle::IsLineFrameOpaque(bool caretActive, bool lineContainsCaret) const {