+ fix: Unicode Point detection

+ color tag contrast on hoover
This commit is contained in:
Rainer Kottenhoff 2020-08-05 21:37:24 +02:00
parent e336f63061
commit 6cda0fb32f
5 changed files with 49 additions and 35 deletions

View File

@ -1978,8 +1978,15 @@ void EditChar2Hex(HWND hwnd)
if (bSelEmpty) { SciCall_SetSelection(iCurPos, iAnchorPos); }
DocPos const count = Sci_GetSelTextLength();
//???char const uesc = (LEXER == CSHARP) ? 'x' : 'u'; // '\xn[n][n][n]' - variable length version
char const uesc = 'u';
//???char const uesc = (LEXER == CSHARP) ? 'x' : 'u'; // '\xn[n][n][n]' - variable length version
//switch (Style_GetCurrentLexerPtr()->lexerID)
//{
// case SCLEX_CPP:
// uesc = 'x';
// default:
// break;
//}
size_t const alloc = count * (2 + MAX_ESCAPE_HEX_DIGIT) + 1;
char* ch = (char*)AllocMem(alloc, HEAP_ZERO_MEMORY);
@ -7609,11 +7616,11 @@ void EditUpdateIndicators(DocPos startPos, DocPos endPos, bool bClearOnly)
{
if (bClearOnly) {
_ClearIndicatorInRange(INDIC_NP3_HYPERLINK, INDIC_NP3_HYPERLINK_U, startPos, endPos);
_ClearIndicatorInRange(INDIC_NP3_COLOR_DEF, -1, startPos, endPos);
_ClearIndicatorInRange(INDIC_NP3_COLOR_DEF, INDIC_NP3_COLOR_DEF_T, startPos, endPos);
_ClearIndicatorInRange(INDIC_NP3_UNICODE_POINT, -1, startPos, endPos);
return;
}
if (Settings.HyperlinkHotspot)
if (Settings.HyperlinkHotspot)
{
// https://mathiasbynens.be/demo/url-regex : @stephenhay
//static const char* pUrlRegEx = "\\b(?:(?:https?|ftp|file)://|www\\.|ftp\\.)[^\\s/$.?#].[^\\s]*";
@ -7634,12 +7641,12 @@ void EditUpdateIndicators(DocPos startPos, DocPos endPos, bool bClearOnly)
_UpdateIndicators(INDIC_NP3_COLOR_DEF, -1, pColorRegEx, startPos, endPos);
}
else {
_ClearIndicatorInRange(INDIC_NP3_COLOR_DEF, -1, startPos, endPos);
_ClearIndicatorInRange(INDIC_NP3_COLOR_DEF, INDIC_NP3_COLOR_DEF_T, startPos, endPos);
}
if (Settings.HighlightUnicodePoints)
{
static const char* pUnicodeRegEx = "(\\\\u([0-9a-fA-F]){4})+";
static const char* pUnicodeRegEx = "(\\\\[uU|xX]([0-9a-fA-F]){4}|\\\\[xX]([0-9a-fA-F]){2})+";
_UpdateIndicators(INDIC_NP3_UNICODE_POINT, -1, pUnicodeRegEx, startPos, endPos);
}
else {

View File

@ -2066,7 +2066,8 @@ int Hex2Char(char* ch, int cnt)
while (*p) {
if (*p == '\\') {
p++;
if (*p == 'x' || *p == 'u') {
if ((*p == 'x' || *p == 'u') ||
(*p == 'X' || *p == 'U')) {
p++;
ci = 0;
int ucc = 0;

View File

@ -1929,6 +1929,10 @@ static void _InitializeSciEditCtrl(HWND hwndEditCtrl)
SendMessage(hwndEditCtrl, SCI_INDICSETHOVERSTYLE, INDIC_NP3_COLOR_DEF, INDIC_ROUNDBOX); // HOVER
SendMessage(hwndEditCtrl, SCI_INDICSETHOVERFORE, INDIC_NP3_COLOR_DEF, RGB(0x00, 0x00, 0x00)); // recalc on hover
SendMessage(hwndEditCtrl, SCI_INDICSETSTYLE, INDIC_NP3_COLOR_DEF_T, INDIC_HIDDEN );
SendMessage(hwndEditCtrl, SCI_INDICSETHOVERSTYLE, INDIC_NP3_COLOR_DEF_T, INDIC_TEXTFORE); // HOVER
SendMessage(hwndEditCtrl, SCI_INDICSETHOVERFORE, INDIC_NP3_COLOR_DEF_T, RGB(0x00, 0x00, 0x00)); // recalc on hover
SendMessage(hwndEditCtrl, SCI_INDICSETSTYLE, INDIC_NP3_UNICODE_POINT, INDIC_COMPOSITIONTHIN /*INDIC_HIDDEN*/); // MARKER only
//SendMessage(hwndEditCtrl, SCI_INDICSETUNDER, INDIC_NP3_UNICODE_POINT, false);
SendMessage(hwndEditCtrl, SCI_INDICSETALPHA, INDIC_NP3_UNICODE_POINT, 0x00);
@ -6460,22 +6464,16 @@ void HandlePosChange()
//
static DocPos prevCursorPosition = -1;
#if 0
#define RGB_TOLERANCE 0xA
#define RGB_TOLERANCE 0xF
#define RGB_SUB(X, Y) (((X) > (Y)) ? ((X) - (Y)) : ((Y) - (X)))
static COLORREF _CalcContrastColor(COLORREF rgb)
inline COLORREF _CalcContrastColor(COLORREF rgb)
{
if (RGB_SUB((rgb) && 0xFF, 0x80) <= RGB_TOLERANCE &&
RGB_SUB((rgb >> 8) && 0xFF, 0x80) <= RGB_TOLERANCE &&
RGB_SUB((rgb >> 16) && 0xFF, 0x80) <= RGB_TOLERANCE)
{
return (0x7F7F7F + rgb) & 0xFFFFFF;
}
else {
return rgb ^ 0xFFFFFF;
}
bool const mask = RGB_SUB((rgb) && 0xFF, 0x80) <= RGB_TOLERANCE &&
RGB_SUB((rgb >> 8) && 0xFF, 0x80) <= RGB_TOLERANCE &&
RGB_SUB((rgb >> 16) && 0xFF, 0x80) <= RGB_TOLERANCE;
return mask ? (0x7F7F7F + rgb) & 0xFFFFFF : rgb ^ 0xFFFFFF;
}
#endif
void HandleDWellStartEnd(const DocPos position, const UINT uid)
{
@ -6584,7 +6582,11 @@ void HandleDWellStartEnd(const DocPos position, const UINT uid)
if (sscanf_s(&chText[1], "%x", &iValue) == 1)
{
COLORREF const rgb = RGB((iValue & 0xFF0000) >> 16, (iValue & 0xFF00) >> 8, iValue & 0xFF);
//COLORREF const fgr = _CalcContrastColor(rgb);
COLORREF const fgr = _CalcContrastColor(rgb);
SciCall_SetIndicatorCurrent(INDIC_NP3_COLOR_DEF_T);
SciCall_IndicatorFillRange(firstPos, length);
SciCall_IndicSetHoverFore(INDIC_NP3_COLOR_DEF_T, fgr);
SciCall_IndicSetAlpha(INDIC_NP3_COLOR_DEF, 0xFF);
SciCall_IndicSetHoverFore(INDIC_NP3_COLOR_DEF, rgb);
}
@ -6598,7 +6600,6 @@ void HandleDWellStartEnd(const DocPos position, const UINT uid)
//StrTrimA(chHex2Char, " \t\n\r");
Hex2Char(chHex2Char, COUNTOF(chHex2Char));
if (StrIsEmptyA(chHex2Char)) { break; }
//SciCall_CallTipSetPosition(true);
@ -6626,9 +6627,13 @@ void HandleDWellStartEnd(const DocPos position, const UINT uid)
prevCursorPosition = -1;
// clear SCN_DWELLSTART visual styles
SciCall_SetIndicatorCurrent(INDIC_NP3_COLOR_DEF_T);
SciCall_IndicatorClearRange(0, Sci_GetDocEndPosition());
SciCall_IndicSetAlpha(INDIC_NP3_COLOR_DEF, 0);
SciCall_IndicSetFore(INDIC_NP3_COLOR_DEF, 0);
HandlePosChange();
}
break;

View File

@ -489,20 +489,20 @@ DeclareSciCallV1(SetIdleStyling, SETIDLESTYLING, int, idlestyle)
//
// Indicators
//
DeclareSciCallV2(IndicSetStyle, INDICSETSTYLE, int, indicatorID, int, style)
DeclareSciCallR1(IndicGetFore, INDICGETFORE, COLORREF, int, indicatorID)
DeclareSciCallV2(IndicSetFore, INDICSETFORE, int, indicatorID, COLORREF, colour)
DeclareSciCallV2(IndicSetUnder, INDICSETUNDER, int, indicatorID, bool, under)
DeclareSciCallV2(IndicSetHoverStyle, INDICSETHOVERSTYLE, int, indicatorID, int, style)
DeclareSciCallV2(IndicSetHoverFore, INDICSETHOVERFORE, int, indicatorID, COLORREF, colour)
DeclareSciCallV2(IndicSetAlpha, INDICSETALPHA, int, indicatorID, int, alpha)
DeclareSciCallV2(IndicSetOutlineAlpha, INDICSETOUTLINEALPHA, int, indicatorID, int, alpha)
DeclareSciCallV1(SetIndicatorCurrent, SETINDICATORCURRENT, int, indicatorID)
DeclareSciCallV2(IndicSetStyle, INDICSETSTYLE, int, indicID, int, style)
DeclareSciCallR1(IndicGetFore, INDICGETFORE, COLORREF, int, indicID)
DeclareSciCallV2(IndicSetFore, INDICSETFORE, int, indicID, COLORREF, colour)
DeclareSciCallV2(IndicSetUnder, INDICSETUNDER, int, indicID, bool, under)
DeclareSciCallV2(IndicSetHoverStyle, INDICSETHOVERSTYLE, int, indicID, int, style)
DeclareSciCallV2(IndicSetHoverFore, INDICSETHOVERFORE, int, indicID, COLORREF, colour)
DeclareSciCallV2(IndicSetAlpha, INDICSETALPHA, int, indicID, int, alpha)
DeclareSciCallV2(IndicSetOutlineAlpha, INDICSETOUTLINEALPHA, int, indicID, int, alpha)
DeclareSciCallV1(SetIndicatorCurrent, SETINDICATORCURRENT, int, indicID)
DeclareSciCallV2(IndicatorFillRange, INDICATORFILLRANGE, DocPos, position, DocPos, length)
DeclareSciCallV2(IndicatorClearRange, INDICATORCLEARRANGE, DocPos, position, DocPos, length)
DeclareSciCallR2(IndicatorValueAt, INDICATORVALUEAT, int, int, indicatorID, DocPos, position)
DeclareSciCallR2(IndicatorStart, INDICATORSTART, int, int, indicatorID, DocPos, position)
DeclareSciCallR2(IndicatorEnd, INDICATOREND, int, int, indicatorID, DocPos, position)
DeclareSciCallR2(IndicatorValueAt, INDICATORVALUEAT, int, int, indicID, DocPos, position)
DeclareSciCallR2(IndicatorStart, INDICATORSTART, int, int, indicID, DocPos, position)
DeclareSciCallR2(IndicatorEnd, INDICATOREND, int, int, indicID, DocPos, position)
//=============================================================================
//

View File

@ -258,8 +258,9 @@ typedef struct _cmq
#define INDIC_NP3_HYPERLINK (INDICATOR_CONTAINER + 5)
#define INDIC_NP3_HYPERLINK_U (INDICATOR_CONTAINER + 6)
#define INDIC_NP3_COLOR_DEF (INDICATOR_CONTAINER + 7)
#define INDIC_NP3_MULTI_EDIT (INDICATOR_CONTAINER + 8)
#define INDIC_NP3_UNICODE_POINT (INDICATOR_CONTAINER + 9)
#define INDIC_NP3_COLOR_DEF_T (INDICATOR_CONTAINER + 8)
#define INDIC_NP3_MULTI_EDIT (INDICATOR_CONTAINER + 9)
#define INDIC_NP3_UNICODE_POINT (INDICATOR_CONTAINER + 10)
// --------------------------------------------------------------------------