diff --git a/language/common_res.h b/language/common_res.h index aed7d32f1..28b8d4afc 100644 --- a/language/common_res.h +++ b/language/common_res.h @@ -655,6 +655,7 @@ #define IDM_VIEW_SPLIT_UNDOTYPSEQ_LNBRK 40473 #define IDM_VIEW_EDIT_LINECOMMENT 40474 #define IDM_VIEW_EVALTINYEXPRONSEL 40475 +#define IDM_VIEW_UNICODE_POINTS 40476 #define IDM_SET_RENDER_TECH_DEFAULT 40500 #define IDM_SET_RENDER_TECH_D2D 40501 @@ -1085,6 +1086,8 @@ #define IDS_LEX_STR_63364 63364 #define IDS_LEX_STR_63365 63365 #define IDS_LEX_STR_63366 63366 +#define IDS_LEX_STR_63367 63367 +#define IDS_LEX_STR_63368 63368 #define IDS_LEX_CSV_COL_0 63400 #define IDS_LEX_CSV_COL_1 63401 diff --git a/language/np3_de_de/lexer_de_de.rc b/language/np3_de_de/lexer_de_de.rc index 9d212a449..9d6f88980 100644 --- a/language/np3_de_de/lexer_de_de.rc +++ b/language/np3_de_de/lexer_de_de.rc @@ -464,6 +464,8 @@ BEGIN IDS_LEX_STR_63364 "Eigenschaften Name" IDS_LEX_STR_63365 "LD Keyword" IDS_LEX_STR_63366 "ESC Sequenz" + IDS_LEX_STR_63367 "Unicode-Point Hover" + IDS_LEX_STR_63368 "2nd Unicode-Point Hover" END STRINGTABLE diff --git a/language/np3_de_de/menu_de_de.rc b/language/np3_de_de/menu_de_de.rc index 0189d5a5c..2e520edbf 100644 --- a/language/np3_de_de/menu_de_de.rc +++ b/language/np3_de_de/menu_de_de.rc @@ -325,6 +325,7 @@ BEGIN MENUITEM SEPARATOR MENUITEM "H&yperlink Indikator\tCtrl+Alt+W", IDM_VIEW_HYPERLINKHOTSPOTS MENUITEM "&Farb-Definition Indikator", IDM_VIEW_COLORDEFHOTSPOTS + MENUITEM "Unicode-&Point Indikator", IDM_VIEW_UNICODE_POINTS MENUITEM "&Zeige passende Klammer\tCtrl+Shift+V", IDM_VIEW_MATCHBRACES POPUP "A&ktuelle Zeile hervorheben\tCtrl+Shift+I" BEGIN diff --git a/language/np3_en_us/lexer_en_us.rc b/language/np3_en_us/lexer_en_us.rc index 720d54aae..107c47bda 100644 --- a/language/np3_en_us/lexer_en_us.rc +++ b/language/np3_en_us/lexer_en_us.rc @@ -464,6 +464,8 @@ BEGIN IDS_LEX_STR_63364 "Property Name" IDS_LEX_STR_63365 "LD Keyword" IDS_LEX_STR_63366 "ESC Sequence" + IDS_LEX_STR_63367 "Unicode-Point Hover" + IDS_LEX_STR_63368 "2nd Unicode-Point Hover" END STRINGTABLE diff --git a/language/np3_en_us/menu_en_us.rc b/language/np3_en_us/menu_en_us.rc index 271dad0e2..493b204d9 100644 --- a/language/np3_en_us/menu_en_us.rc +++ b/language/np3_en_us/menu_en_us.rc @@ -325,6 +325,7 @@ BEGIN MENUITEM SEPARATOR MENUITEM "&Hyperlink Hotspots\tCtrl+Alt+W", IDM_VIEW_HYPERLINKHOTSPOTS MENUITEM "&Color Definition Hotspots", IDM_VIEW_COLORDEFHOTSPOTS + MENUITEM "Highlight Unicode-&Points", IDM_VIEW_UNICODE_POINTS MENUITEM "&Visual Brace Matching\tCtrl+Shift+V", IDM_VIEW_MATCHBRACES POPUP "H&ighlight Current Line\tCtrl+Shift+I" BEGIN diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index 530320328..d963c79c0 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -1387,6 +1387,7 @@ void LoadSettings() GET_BOOL_VALUE_FROM_INISECTION(ColorDefHotspot, true); GET_BOOL_VALUE_FROM_INISECTION(ScrollPastEOF, false); GET_BOOL_VALUE_FROM_INISECTION(ShowHypLnkToolTip, true); + GET_BOOL_VALUE_FROM_INISECTION(HighlightUnicodePoints, true); GET_BOOL_VALUE_FROM_INISECTION(AutoIndent, true); GET_BOOL_VALUE_FROM_INISECTION(AutoCompleteWords, false); @@ -1813,6 +1814,7 @@ static bool _SaveSettings(bool bForceSaveSettings) SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ColorDefHotspot); SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ScrollPastEOF); SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, ShowHypLnkToolTip); + SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, HighlightUnicodePoints); SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AutoIndent); SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AutoCompleteWords); SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, AutoCLexerKeyWords); diff --git a/src/Edit.c b/src/Edit.c index 66140ebf5..aa6910234 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -1960,9 +1960,6 @@ void EditUnescapeCChars(HWND hwnd) { // // EditChar2Hex() // - -#define MAX_ESCAPE_HEX_DIGIT 4 - void EditChar2Hex(HWND hwnd) { UNUSED(hwnd); @@ -1989,10 +1986,10 @@ void EditChar2Hex(HWND hwnd) WCHAR* wch = (WCHAR*)AllocMem(alloc * sizeof(WCHAR), HEAP_ZERO_MEMORY); SciCall_GetSelText(ch); - DocPos const nchars = (DocPos)MultiByteToWideCharEx(Encoding_SciCP, 0, ch, -1, wch, (int)alloc) - 1; // '\0' + int const nchars = (DocPos)MultiByteToWideChar(Encoding_SciCP, 0, ch, -1, wch, (int)alloc) - 1; // '\0' memset(ch, 0, alloc); - for (DocPos i = 0, j = 0; i < nchars; ++i) + for (int i = 0, j = 0; i < nchars; ++i) { if (wch[i] <= 0xFF) { StringCchPrintfA(&ch[j], (alloc - j), "\\x%02X", (wch[i] & 0xFF)); // \xhh @@ -2026,13 +2023,11 @@ void EditChar2Hex(HWND hwnd) FreeMem(ch); FreeMem(wch); - } //============================================================================= // // EditHex2Char() -// by ZuFuLiu // void EditHex2Char(HWND hwnd) { @@ -2053,50 +2048,10 @@ void EditHex2Char(HWND hwnd) size_t const alloc = count * (2 + MAX_ESCAPE_HEX_DIGIT) + 1; char* ch = (char*)AllocMem(alloc, HEAP_ZERO_MEMORY); - WCHAR* wch = (WCHAR*)AllocMem(alloc * sizeof(WCHAR), HEAP_ZERO_MEMORY); - int ci = 0; - ptrdiff_t cch = 0; SciCall_GetSelText(ch); - char* p = ch; - while (*p) { - if (*p == '\\') { - p++; - if (*p == 'x' || *p == 'u') { - p++; - ci = 0; - int ucc = 0; - while (*p && (ucc++ < MAX_ESCAPE_HEX_DIGIT)) { - if (*p >= '0' && *p <= '9') { - ci = ci * 16 + (*p++ - '0'); - } - else if (*p >= 'a' && *p <= 'f') { - ci = ci * 16 + (*p++ - 'a') + 10; - } - else if (*p >= 'A' && *p <= 'F') { - ci = ci * 16 + (*p++ - 'A') + 10; - } - else { - break; - } - } - } - else { - ci = *p++; - } - } - else { - ci = *p++; - } - wch[cch++] = (WCHAR)ci; - if (ci == 0) { - break; - } - } - wch[cch] = L'\0'; - - cch = WideCharToMultiByteEx(Encoding_SciCP, 0, wch, -1, ch, alloc, NULL, NULL) - 1; // '\0' + int const cch = Hex2Char(ch, (int)alloc); _BEGIN_UNDO_ACTION_; SciCall_ReplaceSel(ch); @@ -2109,7 +2064,6 @@ void EditHex2Char(HWND hwnd) _END_UNDO_ACTION_; FreeMem(ch); - FreeMem(wch); } @@ -7612,29 +7566,24 @@ static void _UpdateIndicators(const int indicator, const int indicator2nd, DocPos end = endPos; do { - DocPos const _start = start; - DocPos const _end = end; + DocPos const start_m = start; + DocPos const end_m = end; DocPos const iPos = _FindInTarget(regExpr, iRegExLen, SCFIND_REGEXP, &start, &end, false, FRMOD_IGNORE); if (iPos < 0) { // not found - _ClearIndicatorInRange(indicator, indicator2nd, _start, _end); + _ClearIndicatorInRange(indicator, indicator2nd, start_m, end_m); break; } DocPos const mlen = end - start; if ((mlen <= 0) || (end > endPos)) { // wrong match - _ClearIndicatorInRange(indicator, indicator2nd, _start, _end); + _ClearIndicatorInRange(indicator, indicator2nd, start_m, end_m); break; // wrong match } - _ClearIndicatorInRange(indicator, indicator2nd, _start, end); + _ClearIndicatorInRange(indicator, indicator2nd, start_m, end); - //~if (indicator == INDIC_NP3_HYPERLINK) { - //~ SciCall_StartStyling(start); - //~ SciCall_SetStyling(mlen, _STYLE_GETSTYLEID(STY_URL_HOTSPOT)); - //~} - //~else { SciCall_SetIndicatorCurrent(indicator); SciCall_IndicatorFillRange(start, mlen); if (indicator2nd >= 0) { @@ -7643,7 +7592,7 @@ static void _UpdateIndicators(const int indicator, const int indicator2nd, } // next occurrence - start = end + 1; + start = SciCall_PositionAfter(end); end = endPos; } while (start < end); @@ -7660,7 +7609,8 @@ 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, INDIC_NP3_COLOR_DWELL, startPos, endPos); + _ClearIndicatorInRange(INDIC_NP3_COLOR_DEF, -1, startPos, endPos); + _ClearIndicatorInRange(INDIC_NP3_UNICODE_POINT, -1, startPos, endPos); return; } if (Settings.HyperlinkHotspot) @@ -7684,7 +7634,16 @@ void EditUpdateIndicators(DocPos startPos, DocPos endPos, bool bClearOnly) _UpdateIndicators(INDIC_NP3_COLOR_DEF, -1, pColorRegEx, startPos, endPos); } else { - _ClearIndicatorInRange(INDIC_NP3_COLOR_DEF, INDIC_NP3_COLOR_DWELL, startPos, endPos); + _ClearIndicatorInRange(INDIC_NP3_COLOR_DEF, -1, startPos, endPos); + } + + if (Settings.HighlightUnicodePoints) + { + static const char* pUnicodeRegEx = "(\\\\u([0-9a-fA-F]){4})+"; + _UpdateIndicators(INDIC_NP3_UNICODE_POINT, -1, pUnicodeRegEx, startPos, endPos); + } + else { + _ClearIndicatorInRange(INDIC_NP3_UNICODE_POINT, -1, startPos, endPos); } EditDoStyling(startPos, endPos); diff --git a/src/Helpers.c b/src/Helpers.c index b0534a9c7..f474461d0 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -2050,6 +2050,64 @@ void TransformMetaChars(char* pszInput, bool bRegEx, int iEOLMode) StringCchCopyA(pszInput, FNDRPL_BUFFER, buffer); } + +//============================================================================= +// +// Hex2Char() - zero('\0') terminated strings +// by Zufuliu +// +int Hex2Char(char* ch, int cnt) +{ + int cch = 0; + WCHAR* wch = (WCHAR*)AllocMem(cnt * sizeof(WCHAR), HEAP_ZERO_MEMORY); + if (wch) { + int ci = 0; + char* p = ch; + while (*p) { + if (*p == '\\') { + p++; + if (*p == 'x' || *p == 'u') { + p++; + ci = 0; + int ucc = 0; + while (*p && (ucc++ < MAX_ESCAPE_HEX_DIGIT)) { + if (*p >= '0' && *p <= '9') { + ci = ci * 16 + (*p++ - '0'); + } + else if (*p >= 'a' && *p <= 'f') { + ci = ci * 16 + (*p++ - 'a') + 10; + } + else if (*p >= 'A' && *p <= 'F') { + ci = ci * 16 + (*p++ - 'A') + 10; + } + else { + break; + } + } + } + else { + ci = *p++; + } + } + else { + ci = *p++; + } + wch[cch++] = (WCHAR)ci; + if (ci == 0) { + break; + } + } + wch[cch] = L'\0'; + + cch = WideCharToMultiByte(Encoding_SciCP, 0, wch, -1, ch, cnt, NULL, NULL) - 1; // '\0' + + FreeMem(wch); + } + return cch; +} + + + #ifdef WC2MB_EX //============================================================================= // diff --git a/src/Helpers.h b/src/Helpers.h index fb82ff79a..576497ef7 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -573,6 +573,9 @@ inline bool Char2IntW(LPCWSTR str, int* value) { bool Char2FloatW(WCHAR* wnumber, float* fresult); void Float2String(float fValue, LPWSTR lpszStrg, int cchSize); +#define MAX_ESCAPE_HEX_DIGIT 4 +int Hex2Char(char* ch, int cnt); + // ---------------------------------------------------------------------------- inline bool PathIsExistingFile(LPCWSTR pszPath) { return (PathFileExists(pszPath) && !PathIsDirectory(pszPath)); } diff --git a/src/Notepad3.c b/src/Notepad3.c index fd20e4476..ed921fb92 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1528,6 +1528,7 @@ HWND InitInstance(HINSTANCE hInstance,LPCWSTR pszCmdLine,int nCmdShow) UpdateToolbar(); UpdateStatusbar(true); UpdateMarginWidth(); + UpdateMouseDWellTime(); // print file immediately and quit if (Globals.CmdLnFlag_PrintFileAndLeave) @@ -1921,19 +1922,19 @@ static void _InitializeSciEditCtrl(HWND hwndEditCtrl) SendMessage(hwndEditCtrl, SCI_INDICSETHOVERSTYLE, INDIC_NP3_HYPERLINK_U, INDIC_COMPOSITIONTHICK); SendMessage(hwndEditCtrl, SCI_INDICSETHOVERFORE, INDIC_NP3_HYPERLINK_U, RGB(0x00, 0x00, 0xFF)); - SendMessage(hwndEditCtrl, SCI_INDICSETSTYLE, INDIC_NP3_COLOR_DEF, INDIC_HIDDEN); // MARKER only - SendMessage(hwndEditCtrl, SCI_INDICSETALPHA, INDIC_NP3_COLOR_DEF, 0x00); - SendMessage(hwndEditCtrl, SCI_INDICSETHOVERSTYLE, INDIC_NP3_COLOR_DEF, INDIC_BOX); // HOVER - SendMessage(hwndEditCtrl, SCI_INDICSETHOVERFORE, INDIC_NP3_COLOR_DEF, RGB(0x80, 0x80, 0x80)); - - SendMessage(hwndEditCtrl, SCI_INDICSETSTYLE, INDIC_NP3_COLOR_DWELL, INDIC_FULLBOX); // style on DWELLSTART - SendMessage(hwndEditCtrl, SCI_INDICSETFORE, INDIC_NP3_COLOR_DWELL, RGB(0xE0, 0xE0, 0xE0)); - SendMessage(hwndEditCtrl, SCI_INDICSETUNDER, INDIC_NP3_COLOR_DWELL, true); - SendMessage(hwndEditCtrl, SCI_INDICSETALPHA, INDIC_NP3_COLOR_DWELL, 0xFF); - SendMessage(hwndEditCtrl, SCI_INDICSETOUTLINEALPHA, INDIC_NP3_COLOR_DWELL, 0xFF); - //SendMessage(hwndEditCtrl, SCI_INDICSETHOVERSTYLE, INDIC_NP3_COLOR_DWELL, INDIC_FULLBOX); - //SendMessage(hwndEditCtrl, SCI_INDICSETHOVERFORE, INDIC_NP3_COLOR_DWELL, RGB(0xFF, 0xFF, 0xFF)); + SendMessage(hwndEditCtrl, SCI_INDICSETSTYLE, INDIC_NP3_COLOR_DEF, INDIC_COMPOSITIONTHIN /*INDIC_HIDDEN*/); // MARKER only + SendMessage(hwndEditCtrl, SCI_INDICSETUNDER, INDIC_NP3_COLOR_DEF, true); + SendMessage(hwndEditCtrl, SCI_INDICSETALPHA, INDIC_NP3_COLOR_DEF, 0x00); // reset on hover + SendMessage(hwndEditCtrl, SCI_INDICSETOUTLINEALPHA, INDIC_NP3_COLOR_DEF, 0xFF); + 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_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); + SendMessage(hwndEditCtrl, SCI_INDICSETOUTLINEALPHA, INDIC_NP3_UNICODE_POINT, 0xFF); + SendMessage(hwndEditCtrl, SCI_INDICSETHOVERSTYLE, INDIC_NP3_UNICODE_POINT, INDIC_ROUNDBOX); // HOVER + //SendMessage(hwndEditCtrl, SCI_INDICSETHOVERFORE, INDIC_NP3_UNICODE_POINT, RGB(0xE0, 0xE0, 0xE0)); SendMessage(hwndEditCtrl, SCI_INDICSETSTYLE, INDIC_NP3_MULTI_EDIT, INDIC_ROUNDBOX); SendMessage(hwndEditCtrl, SCI_INDICSETFORE, INDIC_NP3_MULTI_EDIT, RGB(0xFF, 0xA5, 0x00)); @@ -3480,6 +3481,7 @@ LRESULT MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) CheckCmd(hmenu, IDM_VIEW_COLORDEFHOTSPOTS, Settings.ColorDefHotspot); CheckCmd(hmenu, IDM_VIEW_SCROLLPASTEOF, Settings.ScrollPastEOF); CheckCmd(hmenu, IDM_VIEW_SHOW_HYPLNK_CALLTIP, Settings.ShowHypLnkToolTip); + CheckCmd(hmenu, IDM_VIEW_UNICODE_POINTS, Settings.HighlightUnicodePoints); CheckCmd(hmenu, IDM_VIEW_REUSEWINDOW, Flags.bReuseWindow); EnableCmd(hmenu, IDM_VIEW_REUSEWINDOW, sav); @@ -5272,9 +5274,21 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) EditUpdateVisibleIndicators(); break; + case IDM_VIEW_SHOW_HYPLNK_CALLTIP: + Settings.ShowHypLnkToolTip = !Settings.ShowHypLnkToolTip; + UpdateMouseDWellTime(); + break; + case IDM_VIEW_COLORDEFHOTSPOTS: Settings.ColorDefHotspot = !Settings.ColorDefHotspot; EditUpdateVisibleIndicators(); + UpdateMouseDWellTime(); + break; + + case IDM_VIEW_UNICODE_POINTS: + Settings.HighlightUnicodePoints = !Settings.HighlightUnicodePoints; + EditUpdateVisibleIndicators(); + UpdateMouseDWellTime(); break; case IDM_VIEW_ZOOMIN: @@ -5339,14 +5353,6 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) SciCall_SetEndAtLastLine(!Settings.ScrollPastEOF); break; - case IDM_VIEW_SHOW_HYPLNK_CALLTIP: - Settings.ShowHypLnkToolTip = !Settings.ShowHypLnkToolTip; - if (Settings.ShowHypLnkToolTip || Settings.ColorDefHotspot) - SciCall_SetMouseDWellTime(100); - else - Sci_DisableMouseDWellNotification(); - break; - case IDM_VIEW_MENUBAR: Settings.ShowMenubar = !Settings.ShowMenubar; SetMenu(hwnd, (Settings.ShowMenubar ? Globals.hMainMenu : NULL)); @@ -6444,25 +6450,6 @@ void HandlePosChange() DocPos const curPos = SciCall_GetCurrentPos(); if (curPos == prevPosition) { return; } - if (SciCall_IndicatorValueAt(INDIC_NP3_COLOR_DEF, curPos) > 0) - { - DocPos const firstPos = SciCall_IndicatorStart(INDIC_NP3_COLOR_DEF, curPos); - DocPos const lastPos = SciCall_IndicatorEnd(INDIC_NP3_COLOR_DEF, curPos); - DocPos const length = (lastPos - firstPos); - - char chText[MIDSZ_BUFFER] = { '\0' }; - StringCchCopyNA(chText, COUNTOF(chText), SciCall_GetRangePointer(firstPos, length), length); - unsigned int iValue = 0; - if (sscanf_s(&chText[1], "%x", &iValue) == 1) - { - unsigned int r = (iValue & 0xFF0000) >> 16; - unsigned int g = (iValue & 0xFF00) >> 8; - unsigned int b = (iValue & 0xFF); - //bool const dark = ((r + b + g + 2) / 3) < 0x80; - COLORREF const rgb = RGB(r,g,b); - SciCall_IndicSetHoverFore(INDIC_NP3_COLOR_DEF, rgb); - } - } prevPosition = curPos; } @@ -6471,10 +6458,25 @@ void HandlePosChange() // // HandleDWellStartEnd() // -typedef enum _indic_id_t { _I_NONE = 0, _I_HYPERLINK = 1, _I_COLOR_PATTERN = 2 } _INDIC_ID_T; - static DocPos prevCursorPosition = -1; +#if 0 +#define RGB_TOLERANCE 0xA +#define RGB_SUB(X, Y) (((X) > (Y)) ? ((X) - (Y)) : ((Y) - (X))) +static 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; + } +} +#endif + void HandleDWellStartEnd(const DocPos position, const UINT uid) { static DocPos prevStartPosition = -1; @@ -6486,17 +6488,17 @@ void HandleDWellStartEnd(const DocPos position, const UINT uid) if (prevEndPosition < 0) { prevEndPosition = position; } } + int indicator_id = INDICATOR_CONTAINER; + switch (uid) { case SCN_DWELLSTART: { if (position < 0) { CancelCallTip(); prevCursorPosition = -1; return; } - _INDIC_ID_T indicator_type = _I_NONE; - if (Settings.HyperlinkHotspot) { if (SciCall_IndicatorValueAt(INDIC_NP3_HYPERLINK, position) > 0) { - indicator_type = _I_HYPERLINK; + indicator_id = INDIC_NP3_HYPERLINK; if (position != prevCursorPosition) { CancelCallTip(); } @@ -6504,24 +6506,33 @@ void HandleDWellStartEnd(const DocPos position, const UINT uid) } if (Settings.ColorDefHotspot) { if (SciCall_IndicatorValueAt(INDIC_NP3_COLOR_DEF, position) > 0) { - indicator_type = _I_COLOR_PATTERN; + indicator_id = INDIC_NP3_COLOR_DEF; + } + } + if (Settings.HighlightUnicodePoints) { + if (SciCall_IndicatorValueAt(INDIC_NP3_UNICODE_POINT, position) > 0) { + indicator_id = INDIC_NP3_UNICODE_POINT; } } - switch (indicator_type) + switch (indicator_id) { - case _I_NONE: - default: - return; // nothing to do - break; - - case _I_HYPERLINK: + case INDIC_NP3_HYPERLINK: if (!Settings.ShowHypLnkToolTip || SciCall_CallTipActive()) { return; } break; - case _I_COLOR_PATTERN: + case INDIC_NP3_UNICODE_POINT: + if (!Settings.HighlightUnicodePoints || SciCall_CallTipActive()) { return; } + break; + + case INDIC_NP3_COLOR_DEF: // ok break; + + // nothing to do for these indicators + case INDICATOR_CONTAINER: + default: + return; } // ---------------------------------------------------------------------- @@ -6530,22 +6541,20 @@ void HandleDWellStartEnd(const DocPos position, const UINT uid) //SciCall_SetCursor(SC_NP3_CURSORHAND); - int const indicator_id = (_I_HYPERLINK == indicator_type) ? INDIC_NP3_HYPERLINK : INDIC_NP3_COLOR_DEF; - DocPos const firstPos = SciCall_IndicatorStart(indicator_id, position); DocPos const lastPos = SciCall_IndicatorEnd(indicator_id, position); DocPos const length = (lastPos - firstPos); // WebLinks and Color Refs are ASCII only - No need for UTF-8 conversion here - if (_I_HYPERLINK == indicator_type) + if (INDIC_NP3_HYPERLINK == indicator_id) { if (!s_bCallTipEscDisabled) { char chText[MIDSZ_BUFFER] = { '\0' }; // No need for UTF-8 conversion here and StringCchCopyNA(chText, COUNTOF(chText), SciCall_GetRangePointer(firstPos, length), length); StrTrimA(chText, " \t\n\r"); - if (StrIsEmptyA(chText)) { return; } + if (StrIsEmptyA(chText)) { break; } WCHAR wchCalltipAdd[SMALL_BUFFER] = { L'\0' }; if (StrStrIA(chText, "file:") == chText) { @@ -6566,7 +6575,7 @@ void HandleDWellStartEnd(const DocPos position, const UINT uid) Globals.CallTipType = CT_DWELL; } } - else if (_I_COLOR_PATTERN == indicator_type) + else if (INDIC_NP3_COLOR_DEF == indicator_id) { char chText[MICRO_BUFFER] = { '\0' }; // Color Refs are ASCII only - No need for UTF-8 conversion here @@ -6574,16 +6583,31 @@ void HandleDWellStartEnd(const DocPos position, const UINT uid) unsigned int iValue = 0; if (sscanf_s(&chText[1], "%x", &iValue) == 1) { - SciCall_SetIndicatorCurrent(INDIC_NP3_COLOR_DWELL); - SciCall_IndicatorClearRange(0, Sci_GetDocEndPosition()); - COLORREF const rgb = RGB((iValue & 0xFF0000) >> 16, (iValue & 0xFF00) >> 8, iValue & 0xFF); - + //COLORREF const fgr = _CalcContrastColor(rgb); + SciCall_IndicSetAlpha(INDIC_NP3_COLOR_DEF, 0xFF); SciCall_IndicSetHoverFore(INDIC_NP3_COLOR_DEF, rgb); - SciCall_IndicSetFore(INDIC_NP3_COLOR_DWELL, rgb); - SciCall_IndicatorFillRange(firstPos, length); } } + else if (INDIC_NP3_UNICODE_POINT == indicator_id) + { + if (!s_bCallTipEscDisabled) { + char chHex2Char[MIDSZ_BUFFER] = {'\0'}; + // No need for UTF-8 conversion here and + StringCchCopyNA(chHex2Char, COUNTOF(chHex2Char), SciCall_GetRangePointer(firstPos, length), length); + //StrTrimA(chHex2Char, " \t\n\r"); + + Hex2Char(chHex2Char, COUNTOF(chHex2Char)); + + if (StrIsEmptyA(chHex2Char)) { break; } + + //SciCall_CallTipSetPosition(true); + SciCall_CallTipShow(position, chHex2Char); + SciCall_CallTipSetHlt(0, (int)length); + Globals.CallTipType = CT_DWELL; + } + } + prevCursorPosition = position; prevStartPosition = firstPos; prevEndPosition = lastPos; @@ -6601,8 +6625,10 @@ void HandleDWellStartEnd(const DocPos position, const UINT uid) s_bCallTipEscDisabled = false; prevCursorPosition = -1; - SciCall_SetIndicatorCurrent(INDIC_NP3_COLOR_DWELL); - SciCall_IndicatorClearRange(0, Sci_GetDocEndPosition()); + // clear SCN_DWELLSTART visual styles + SciCall_IndicSetAlpha(INDIC_NP3_COLOR_DEF, 0); + SciCall_IndicSetFore(INDIC_NP3_COLOR_DEF, 0); + HandlePosChange(); } break; @@ -10718,6 +10744,18 @@ void SetNotifyIconTitle(HWND hwnd) } +//============================================================================= +// +// UpdateMouseDWellTime() +// +void UpdateMouseDWellTime() +{ + if (Settings.ShowHypLnkToolTip || Settings.ColorDefHotspot || Settings.HighlightUnicodePoints) + SciCall_SetMouseDWellTime(100); + else + Sci_DisableMouseDWellNotification(); +} + //============================================================================= // diff --git a/src/Notepad3.h b/src/Notepad3.h index 47a45a90a..b7a428b20 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -139,6 +139,7 @@ void UpdateToolbar(); void UpdateStatusbar(bool); void UpdateMarginWidth(); void UpdateSaveSettingsCmds(); +void UpdateMouseDWellTime(); void UndoRedoRecordingStart(); void UndoRedoRecordingStop(); diff --git a/src/SciCall.h b/src/SciCall.h index 8c14f43d5..c781eef25 100644 --- a/src/SciCall.h +++ b/src/SciCall.h @@ -490,6 +490,7 @@ 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) diff --git a/src/StyleLexers/EditLexer.h b/src/StyleLexers/EditLexer.h index a0ffd211a..4a43910a1 100644 --- a/src/StyleLexers/EditLexer.h +++ b/src/StyleLexers/EditLexer.h @@ -67,11 +67,12 @@ typedef enum { STY_BOOK_MARK = 12, STY_MARK_OCC = 13, STY_URL_HOTSPOT = 14, - STY_MULTI_EDIT = 15, - STY_IME_COLOR = 16, + STY_UNICODE_HOTSPOT = 15, + STY_MULTI_EDIT = 16, + STY_IME_COLOR = 17, - STY_INVISIBLE = 17, - STY_READONLY = 18 + STY_INVISIBLE = 18, + STY_READONLY = 19 // MAX = (127 - STYLE_LASTPREDEFINED) // -------^----- => char <-> int casting !!! diff --git a/src/StyleLexers/styleLexStandard.c b/src/StyleLexers/styleLexStandard.c index 2e2b9769c..d1a072a61 100644 --- a/src/StyleLexers/styleLexStandard.c +++ b/src/StyleLexers/styleLexStandard.c @@ -22,8 +22,9 @@ SCLEX_NULL, IDS_LEX_DEF_TXT, L"Common Base", L"", L"", /* 12 */ { {_STYLE_GETSTYLEID(STY_BOOK_MARK)}, IDS_LEX_STD_BKMRK, L"Bookmarks and Folding (Colors, Size)", L"size:+2; fore:#000000; back:#00DC00; alpha:100", L"" }, /* 13 */ { {_STYLE_GETSTYLEID(STY_MARK_OCC)}, IDS_LEX_STR_63262, L"Mark Occurrences (Indicator)", L"fore:#3399FF; alpha:60; alpha2:60; indic_roundbox", L"" }, /* 14 */ { {_STYLE_GETSTYLEID(STY_URL_HOTSPOT)}, IDS_LEX_STR_63264, L"Hyperlink Hotspots", L"fore:#0000FF; back:#0000BF; indic_plain", L"" }, - /* 15 */ { {_STYLE_GETSTYLEID(STY_MULTI_EDIT)}, IDS_LEX_STR_63354, L"Multi Edit Indicator", L"fore:#FFA000; alpha:60; alpha2:180; indic_roundbox", L"" }, - /* 16 */ { {_STYLE_GETSTYLEID(STY_IME_COLOR)}, IDS_LEX_STR_63352, L"Inline-IME Color", L"fore:#00AA00", L"" }, + /* 15 */ { {_STYLE_GETSTYLEID(STY_UNICODE_HOTSPOT)}, IDS_LEX_STR_63367, L"Unicode-Point Hover", L"fore:#00FA00; alpha:60; alpha2:180; indic_compositionthick", L""}, + /* 16 */ { {_STYLE_GETSTYLEID(STY_MULTI_EDIT)}, IDS_LEX_STR_63354, L"Multi Edit Indicator", L"fore:#FFA000; alpha:60; alpha2:180; indic_roundbox", L"" }, + /* 17 */ { {_STYLE_GETSTYLEID(STY_IME_COLOR)}, IDS_LEX_STR_63352, L"Inline-IME Color", L"fore:#00AA00", L"" }, EDITLEXER_SENTINEL } }; @@ -45,8 +46,9 @@ SCLEX_NULL, IDS_LEX_STR_63266, L"2nd Common Base", L"", L"", /* 12 */ { {_STYLE_GETSTYLEID(STY_BOOK_MARK)}, IDS_LEX_2ND_BKMRK, L"2nd Bookmarks and Folding (Colors, Size)", L"size:+2; fore:#000000; back:#00DC00; charset:2; case:U; alpha:100", L"" }, /* 13 */ { {_STYLE_GETSTYLEID(STY_MARK_OCC)}, IDS_LEX_STR_63263, L"2nd Mark Occurrences (Indicator)", L"fore:#0000FF; alpha:60; alpha2:60; indic_box", L"" }, /* 14 */ { {_STYLE_GETSTYLEID(STY_URL_HOTSPOT)}, IDS_LEX_STR_63265, L"2nd Hyperlink Hotspots", L"fore:#00D000; back:#009C00; alpha:180; indic_compositionthin", L"" }, - /* 15 */ { {_STYLE_GETSTYLEID(STY_MULTI_EDIT)}, IDS_LEX_STR_63355, L"2nd Multi Edit Indicator", L"fore:#00A5FF; indic_box", L"" }, - /* 16 */ { {_STYLE_GETSTYLEID(STY_IME_COLOR)}, IDS_LEX_STR_63353, L"2nd Inline-IME Color", L"fore:#FF0000", L"" }, + /* 15 */ {{_STYLE_GETSTYLEID(STY_UNICODE_HOTSPOT)}, IDS_LEX_STR_63368, L"2nd Unicode-Point Hover", L"fore:#0000FA; alpha:60; alpha2:180; indic_compositionthick", L""}, + /* 16 */ {{_STYLE_GETSTYLEID(STY_MULTI_EDIT)}, IDS_LEX_STR_63355, L"2nd Multi Edit Indicator", L"fore:#00A5FF; indic_box", L""}, + /* 17 */ { {_STYLE_GETSTYLEID(STY_IME_COLOR)}, IDS_LEX_STR_63353, L"2nd Inline-IME Color", L"fore:#FF0000", L"" }, EDITLEXER_SENTINEL } }; diff --git a/src/Styles.c b/src/Styles.c index 168e3df94..e7ae86413 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -1193,6 +1193,29 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) } SendMessage(hwnd, SCI_INDICSETSTYLE, INDIC_NP3_MARK_OCCURANCE, iValue); + // -------------------------------------------------------------- + // COLOR definitions (INDIC_NP3_COLOR_DEF) are not configurable + // -------------------------------------------------------------- + + // Unicode-Point Indicator (Hover) + //SciCall_IndicSetFore(INDIC_NP3_UNICODE_POINT, RGB(0x00, 0x00, 0xF0)); + SciCall_IndicSetStyle (INDIC_NP3_UNICODE_POINT, INDIC_COMPOSITIONTHIN); // simple underline + + if (Style_StrGetColor(pCurrentStandard->Styles[STY_UNICODE_HOTSPOT].szValue, FOREGROUND_LAYER, &dColor)) + SciCall_IndicSetHoverFore(INDIC_NP3_UNICODE_POINT, dColor); + if (Style_StrGetAlpha(pCurrentStandard->Styles[STY_UNICODE_HOTSPOT].szValue, &iValue, true)) + SciCall_IndicSetAlpha(INDIC_NP3_UNICODE_POINT, iValue); + if (Style_StrGetAlpha(pCurrentStandard->Styles[STY_UNICODE_HOTSPOT].szValue, &iValue, false)) + SciCall_IndicSetOutlineAlpha(INDIC_NP3_UNICODE_POINT, iValue); + + iValue = -1; // need for retrieval + if (!Style_GetIndicatorType(pCurrentStandard->Styles[STY_UNICODE_HOTSPOT].szValue, 0, &iValue)) { + // got default, get string + StringCchCatW(pCurrentStandard->Styles[STY_UNICODE_HOTSPOT].szValue, COUNTOF(pCurrentStandard->Styles[0].szValue), L"; "); + Style_GetIndicatorType(wchSpecificStyle, COUNTOF(wchSpecificStyle), &iValue); + StringCchCatW(pCurrentStandard->Styles[STY_UNICODE_HOTSPOT].szValue, COUNTOF(pCurrentStandard->Styles[0].szValue), wchSpecificStyle); + } + SciCall_IndicSetHoverStyle(INDIC_NP3_UNICODE_POINT, iValue); // Multi Edit Indicator if (Style_StrGetColor(pCurrentStandard->Styles[STY_MULTI_EDIT].szValue, FOREGROUND_LAYER, &dColor)) diff --git a/src/TypeDefs.h b/src/TypeDefs.h index 38ff419dc..be97425e0 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -257,9 +257,9 @@ typedef struct _cmq #define INDIC_NP3_FOCUS_VIEW (INDICATOR_CONTAINER + 4) #define INDIC_NP3_HYPERLINK (INDICATOR_CONTAINER + 5) #define INDIC_NP3_HYPERLINK_U (INDICATOR_CONTAINER + 6) -#define INDIC_NP3_COLOR_DEF (INDICATOR_CONTAINER + 7) // (HIDDEN) -#define INDIC_NP3_COLOR_DWELL (INDICATOR_CONTAINER + 8) -#define INDIC_NP3_MULTI_EDIT (INDICATOR_CONTAINER + 9) +#define INDIC_NP3_COLOR_DEF (INDICATOR_CONTAINER + 7) +#define INDIC_NP3_MULTI_EDIT (INDICATOR_CONTAINER + 8) +#define INDIC_NP3_UNICODE_POINT (INDICATOR_CONTAINER + 9) // -------------------------------------------------------------------------- @@ -383,6 +383,7 @@ typedef struct _settings_t bool ColorDefHotspot; bool ScrollPastEOF; bool ShowHypLnkToolTip; + bool HighlightUnicodePoints; bool AutoIndent; bool AutoCompleteWords; bool AutoCLexerKeyWords;