From f8111bce7a0e5d89082a89aae8fba0b1e06c2014 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 7 Dec 2017 15:13:29 +0100 Subject: [PATCH 1/6] + feature: URL Hotspot (first version) --- src/Edit.c | 52 +++++++++++++++++++++++++++++++- src/Edit.h | 9 ++++++ src/Helpers.h | 1 - src/Notepad3.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++- src/Styles.c | 11 +++++++ 5 files changed, 152 insertions(+), 3 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index 626986220..4dd0cb8ea 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -189,7 +189,6 @@ HWND EditCreate(HWND hwndParent) SendMessage(hwnd, SCI_INDICSETALPHA, INDIC_NP3_BAD_BRACE, 120); SendMessage(hwnd, SCI_INDICSETOUTLINEALPHA, INDIC_NP3_BAD_BRACE, 120); - // word delimiter handling EditInitWordDelimiter(hwnd); EditSetAccelWordNav(hwnd,bAccelWordNavigation); @@ -5793,6 +5792,57 @@ void EditCompleteWord(HWND hwnd, BOOL autoInsert) { } + +//============================================================================= +// +// EditUpdateUrlHotspots() +// Find and mark all URL hot-spots +// +void EditUpdateUrlHotspots(HWND hwnd, tPos startPos, tPos endPos) +{ + const char* pszUrlRegEx = "\\b(?:(?:https?|ftp|file)://|www\\.|ftp\\.)" + "(?:\\([-A-Z0-9+&@#/%=~_|$?!:,.]*\\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*" + "(?:\\([-A-Z0-9+&@#/%=~_|$?!:,.]*\\)|[A-Z0-9+&@#/%=~_|$])"; + + const int iRegExLen = (int)strlen(pszUrlRegEx); + + tPos posCurr = (tPos)SendMessage(hwnd, SCI_GETCURRENTPOS, 0, 0); + tPos posTextLength = (tPos)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); + + if ((startPos < 0) || (startPos >= posTextLength)) + { + tPos cln = (tPos)SendMessage(hwnd, SCI_LINEFROMPOSITION, posCurr, 0); + startPos = (tPos)SendMessage(hwnd, SCI_POSITIONFROMLINE, cln-1, 0); + } + if ((endPos < 0) || (endPos >= posTextLength)) { + tPos cln = (tPos)SendMessage(hwnd, SCI_LINEFROMPOSITION, posCurr, 0); + endPos = (tPos)SendMessage(hwnd, SCI_GETLINEENDPOSITION, cln+1, 0); + } + + int start = (int)startPos; + int end = (int)endPos; + int flags = SCFIND_NP3_REGEX; + + while (TRUE) + { + int iPos = EditFindInTarget(hwnd, pszUrlRegEx, iRegExLen, flags, &start, &end, (end == start)); + + if (iPos < 0) + break; // not found + + // mark this match + SendMessage(hwnd, SCI_STARTSTYLING, iPos, 0); + SendMessage(hwnd, SCI_SETSTYLING, (end - start), STYLE_NP3_ID_HOTSPOT); + + start = end; + end = (int)endPos; + + if (start >= end) + break; + } +} + + //============================================================================= // // EditHighlightIfBrace() diff --git a/src/Edit.h b/src/Edit.h index c355a7902..e24791d15 100644 --- a/src/Edit.h +++ b/src/Edit.h @@ -20,6 +20,11 @@ BOOL Scintilla_RegisterClasses(void*); BOOL Scintilla_ReleaseResources(); + +//typedef Sci_Position tPos; +typedef ptrdiff_t tPos; + + #define FNDRPL_BUFFER 512 typedef struct _editfindreplace { @@ -51,6 +56,9 @@ typedef struct _editfindreplace #define INDIC_NP3_MATCH_BRACE 2 #define INDIC_NP3_BAD_BRACE 3 +#define STYLE_NP3_ID_HOTSPOT 222 + + HWND EditCreate(HWND); void EditInitWordDelimiter(HWND); void EditSetNewText(HWND,char*,DWORD); @@ -119,6 +127,7 @@ void EditPrintInit(); void EditMatchBrace(HWND); void EditClearAllMarks(HWND); void EditMarkAll(HWND,char*,int,BOOL,BOOL); +void EditUpdateUrlHotspots(HWND, tPos, tPos); void EditSetAccelWordNav(HWND,BOOL); void EditCompleteWord(HWND,BOOL); void EditGetBookmarkList(HWND,LPWSTR,int); diff --git a/src/Helpers.h b/src/Helpers.h index 651a5ad8c..421516fdb 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -439,7 +439,6 @@ inline HRESULT PathCchCanonicalize(PWSTR p,size_t l,PCWSTR a) { UNUSED(l); re inline HRESULT PathCchRenameExtension(PWSTR p,size_t l,PCWSTR a) { UNUSED(l); return (PathRenameExtension(p,a) ? S_OK : E_FAIL); } inline HRESULT PathCchRemoveFileSpec(PWSTR p,size_t l) { UNUSED(l); return (PathRemoveFileSpec(p) ? S_OK : E_FAIL); } - // special Drag and Drop Handling typedef struct tDROPDATA diff --git a/src/Notepad3.c b/src/Notepad3.c index 9a43d88c7..276960862 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -5340,6 +5340,74 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) } +//============================================================================= +// +// OpenHotSpotURL() - Handles WM_NOTIFY +// +// +void OpenHotSpotURL(tPos position) +{ + int iStyle = (int)SendMessage(hwndEdit, SCI_GETSTYLEAT, position, 0); + int iNewStyle = iStyle; + + // get left most position of style + tPos pos = position; + while ((iNewStyle == iStyle) && (--pos > 0)) { + iNewStyle = (int)SendMessage(hwndEdit, SCI_GETSTYLEAT, pos, 0); + } + tPos firstPos = (pos != 0) ? (pos + 1) : 0; + + // get right most position of style + pos = position; + iNewStyle = iStyle; + tPos posTextLength = (tPos)SendMessage(hwndEdit, SCI_GETTEXTLENGTH, 0, 0); + while ((iNewStyle == iStyle) && (++pos < posTextLength)) { + iNewStyle = (int)SendMessage(hwndEdit, SCI_GETSTYLEAT, pos, 0); + } + tPos lastPos = (pos - 1); + + tPos length = lastPos - firstPos; + + if ((length > 0) && (length < HUGE_BUFFER)) + { + char chURL[HUGE_BUFFER] = { '\0' }; + struct Sci_TextRange tr = { { 0, -1 }, NULL }; + tr.chrg.cpMin = (Sci_PositionCR)firstPos; + tr.chrg.cpMax = (Sci_PositionCR)lastPos; + tr.lpstrText = chURL; + + SendMessage(hwndEdit, SCI_GETTEXTRANGE, 0, (LPARAM)&tr); + + StrTrimA(chURL, " \t\n\r"); + + if (StringCchLenA(chURL, COUNTOF(chURL))) + { + WCHAR wchURL[HUGE_BUFFER] = { L'\0' }; + WCHAR wchDirectory[MAX_PATH] = { L'\0' }; + MultiByteToWideCharStrg(Encoding_SciGetCodePage(hwndEdit), chURL, wchURL); + + if (StringCchLenW(szCurFile, COUNTOF(szCurFile))) { + StringCchCopy(wchDirectory, COUNTOF(wchDirectory), szCurFile); + PathRemoveFileSpec(wchDirectory); + } + + SHELLEXECUTEINFO sei; + ZeroMemory(&sei, sizeof(SHELLEXECUTEINFO)); + sei.cbSize = sizeof(SHELLEXECUTEINFO); + sei.fMask = SEE_MASK_NOZONECHECKS; + sei.hwnd = NULL; + sei.lpVerb = NULL; + sei.lpFile = wchURL; + sei.lpParameters = NULL; + sei.lpDirectory = wchDirectory; + sei.nShow = SW_SHOWNORMAL; + ShellExecuteEx(&sei); + } + } +} + + + //============================================================================= // // MsgNotify() - Handles WM_NOTIFY @@ -5357,6 +5425,14 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) switch(pnmh->code) { + case SCN_HOTSPOTCLICK: + { + if (scn->modifiers & SCMOD_CTRL) { + OpenHotSpotURL(scn->position); + } + } + break; + case SCN_UPDATEUI: if (scn->updated & ~(SC_UPDATE_V_SCROLL | SC_UPDATE_H_SCROLL)) { @@ -5513,6 +5589,7 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) } else if (bAutoCompleteWords && !SendMessage(hwndEdit, SCI_AUTOCACTIVE, 0, 0)) EditCompleteWord(hwndEdit, FALSE); + break; case SCN_MODIFIED: @@ -5525,6 +5602,7 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) } } if (scn->linesAdded != 0) { + EditUpdateUrlHotspots(hwndEdit, -1, -1); UpdateLineNumberWidth(); } bModified = TRUE; @@ -7457,7 +7535,7 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp InstallFileWatching(szCurFile); // the .LOG feature ... - if (SendMessage(hwndEdit,SCI_GETLENGTH,0,0) >= 4) { + if (SendMessage(hwndEdit,SCI_GETTEXTLENGTH,0,0) >= 4) { char tchLog[5] = { '\0' }; SendMessage(hwndEdit,SCI_GETTEXT,5,(LPARAM)tchLog); if (StringCchCompareXA(tchLog,".LOG") == 0) { @@ -7487,6 +7565,8 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp UpdateStatusbar(); UpdateLineNumberWidth(); + EditUpdateUrlHotspots(hwndEdit, 0, (tPos)SendMessage(hwndEdit, SCI_GETTEXTLENGTH, 0, 0) - 1); + // consistent settings file handling (if loaded in editor) bEnableSaveSettings = (StringCchCompareINW(szCurFile, COUNTOF(szCurFile), szIniFile, COUNTOF(szIniFile)) == 0) ? FALSE : TRUE; UpdateSettingsCmds(); diff --git a/src/Styles.c b/src/Styles.c index 248c059a8..a8b807fe2 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -3559,6 +3559,17 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { } } + // Hot Spot settings + SendMessage(hwnd, SCI_STYLESETFORE, STYLE_NP3_ID_HOTSPOT, (LPARAM)RGB(0, 0, 200)); + SendMessage(hwnd, SCI_STYLESETITALIC, STYLE_NP3_ID_HOTSPOT, (LPARAM)TRUE); + //SendMessage(hwnd, SCI_STYLESETUNDERLINE, iHotSpotStyle, (LPARAM)TRUE); + + SendMessage(hwnd, SCI_STYLESETHOTSPOT, STYLE_NP3_ID_HOTSPOT, (LPARAM)TRUE); + SendMessage(hwnd, SCI_SETHOTSPOTACTIVEFORE, TRUE, (LPARAM)RGB(0, 0, 255)); + SendMessage(hwnd, SCI_SETHOTSPOTACTIVEUNDERLINE, TRUE, 0); + SendMessage(hwnd, SCI_SETHOTSPOTSINGLELINE, TRUE, 0); + + SendMessage(hwnd,SCI_COLOURISE,0,(LPARAM)-1); // Save current lexer From 7b562f9c828b6ae09fcd3652afbf8a57a6ac1612 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 7 Dec 2017 18:38:18 +0100 Subject: [PATCH 2/6] + fix: add version info for VS2017 v.15.5 --- src/Version.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Version.h b/src/Version.h index 457fb37d2..a30283509 100644 --- a/src/Version.h +++ b/src/Version.h @@ -58,7 +58,11 @@ // Compiler specific #if defined(_MSC_VER) - #if (_MSC_VER >= 1911) + #if (_MSC_VER >= 1912) + #if(_MSC_FULL_VER >= 191225830) + #define VER_CPL "Microsoft Visual C++ 2017 Version 15.5" + #endif + #elif (_MSC_VER >= 1911) #if((_MSC_FULL_VER >= 191125542) && (_MSC_FULL_VER <= 191125547)) #define VER_CPL "Microsoft Visual C++ 2017 Version 15.4" #elif((_MSC_FULL_VER >= 191125506) && (_MSC_FULL_VER <= 191125508)) From e10375fdcc94f77d955bbb50004c2e3e7bc74891 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 8 Dec 2017 00:27:12 +0100 Subject: [PATCH 3/6] + feature: enhanced URL Hotspot highlighting --- src/Edit.c | 89 +++++++++++++++---------------- src/Edit.h | 4 +- src/Helpers.c | 4 +- src/Notepad3.c | 30 ++++++++--- src/Notepad3.rc | Bin 183960 -> 184140 bytes src/SciCall.h | 3 ++ src/Styles.c | 138 ++++++++++++++++++++++++++++++------------------ src/Styles.h | 4 +- 8 files changed, 161 insertions(+), 111 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index da2cefd8a..34050fa6f 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -322,7 +322,7 @@ BOOL EditConvertText(HWND hwnd,int encSource,int encDest,BOOL bSetSavePoint) if (!(Encoding_IsValid(encSource) && Encoding_IsValid(encDest))) return(FALSE); - length = (int)SendMessage(hwnd,SCI_GETTEXTLENGTH,0,0); + length = SciCall_GetTextLength(); if (length == 0) { @@ -395,7 +395,7 @@ BOOL EditSetNewEncoding(HWND hwnd,int iNewEncoding,BOOL bNoUI,BOOL bSetSavePoint //return FALSE; // commented out ? : allow conversion between arbitrary encodings //} - if (SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0) == 0) { + if (SciCall_GetTextLength() == 0) { BOOL bIsEmptyUndoHistory = (SendMessage(hwnd, SCI_CANUNDO, 0, 0) == 0 && SendMessage(hwnd, SCI_CANREDO, 0, 0) == 0); @@ -625,7 +625,7 @@ BOOL EditCopyAppend(HWND hwnd) } } else { - int cchText = (int)SendMessage(hwnd,SCI_GETTEXTLENGTH,0,0); + int cchText = SciCall_GetTextLength(); pszText = LocalAlloc(LPTR,cchText + 1); SendMessage(hwnd,SCI_GETTEXT,(int)LocalSize(pszText),(LPARAM)pszText); } @@ -1048,7 +1048,7 @@ BOOL EditSaveFile( EditStripTrailingBlanks(hwnd,TRUE); // get text - cbData = (int)SendMessage(hwnd,SCI_GETTEXTLENGTH,0,0); + cbData = SciCall_GetTextLength(); lpData = GlobalAlloc(GPTR, cbData + 4); //fix: +bom SendMessage(hwnd,SCI_GETTEXT,GlobalSize(lpData),(LPARAM)lpData); @@ -2173,8 +2173,7 @@ void EditMoveUp(HWND hwnd) SendMessage(hwnd,SCI_INSERTTEXT,(WPARAM)iLineDestStart,(LPARAM)chaEOL); SendMessage(hwnd,SCI_SETTARGETSTART,(WPARAM) SendMessage(hwnd,SCI_GETLINEENDPOSITION,(WPARAM)iLineDest,0),0); - SendMessage(hwnd,SCI_SETTARGETEND,(WPARAM) - SendMessage(hwnd,SCI_GETTEXTLENGTH,0,0),0); + SendMessage(hwnd,SCI_SETTARGETEND,(WPARAM)SciCall_GetTextLength(),0); SendMessage(hwnd,SCI_REPLACETARGET,0,(LPARAM)""); } @@ -2284,8 +2283,7 @@ void EditMoveDown(HWND hwnd) SendMessage(hwnd,SCI_SETTARGETSTART,(WPARAM) SendMessage(hwnd,SCI_GETLINEENDPOSITION,(WPARAM) SendMessage(hwnd,SCI_GETLINECOUNT,0,0)-2,0),0); - SendMessage(hwnd,SCI_SETTARGETEND,(WPARAM) - SendMessage(hwnd,SCI_GETTEXTLENGTH,0,0),0); + SendMessage(hwnd,SCI_SETTARGETEND,(WPARAM)SciCall_GetTextLength(),0); SendMessage(hwnd,SCI_REPLACETARGET,0,(LPARAM)""); } @@ -2333,7 +2331,7 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend) //if (iSelStart == iSelEnd) { // iSelStart = 0; - // iSelEnd = SendMessage(hwnd,SCI_GETTEXTLENGTH,0,0); + // iSelEnd = SciCall_GetTextLength(); //} UINT mbcp = Encoding_SciGetCodePage(hwnd); @@ -3187,7 +3185,7 @@ void EditStripFirstCharacter(HWND hwnd) if (iSelStart == iSelEnd) { iSelStart = 0; - iSelEnd = (int)SendMessage(hwnd,SCI_GETTEXTLENGTH,0,0); + iSelEnd = SciCall_GetTextLength(); } if (SC_SEL_RECTANGLE != SendMessage(hwnd,SCI_GETSELECTIONMODE,0,0)) @@ -3234,7 +3232,7 @@ void EditStripLastCharacter(HWND hwnd) if (iSelStart == iSelEnd) { iSelStart = 0; - iSelEnd = (int)SendMessage(hwnd,SCI_GETTEXTLENGTH,0,0); + iSelEnd = SciCall_GetTextLength(); } if (SC_SEL_RECTANGLE != SendMessage(hwnd,SCI_GETSELECTIONMODE,0,0)) @@ -3340,7 +3338,7 @@ void EditCompressSpaces(HWND hwnd) int iAnchorPos = (int)SendMessage(hwnd,SCI_GETANCHOR,0,0); int iLineStart = (int)SendMessage(hwnd,SCI_LINEFROMPOSITION,(WPARAM)iSelStart,0); int iLineEnd = (int)SendMessage(hwnd,SCI_LINEFROMPOSITION,(WPARAM)iSelEnd,0); - int iLength = (int)SendMessage(hwnd,SCI_GETTEXTLENGTH,0,0); + int iLength = SciCall_GetTextLength(); char* pszIn; char* pszOut; @@ -3437,7 +3435,7 @@ void EditRemoveBlankLines(HWND hwnd,BOOL bMerge) if (iSelStart == iSelEnd) { iSelStart = 0; - iSelEnd = (int)SendMessage(hwnd,SCI_GETTEXTLENGTH,0,0); + iSelEnd = SciCall_GetTextLength(); } if (SC_SEL_RECTANGLE != SendMessage(hwnd,SCI_GETSELECTIONMODE,0,0)) @@ -4200,7 +4198,7 @@ void EditSelectEx(HWND hwnd,int iAnchorPos,int iCurrentPos) // void EditFixPositions(HWND hwnd) { - int iMaxPos = (int)SendMessage(hwnd,SCI_GETTEXTLENGTH,0,0); + int iMaxPos = SciCall_GetTextLength(); int iCurrentPos = (int)SendMessage(hwnd,SCI_GETCURRENTPOS,0,0); int iAnchorPos = (int)SendMessage(hwnd,SCI_GETANCHOR,0,0); @@ -4274,7 +4272,7 @@ void EditGetExcerpt(HWND hwnd,LPWSTR lpszExcerpt,DWORD cchExcerpt) tr.chrg.cpMax = min(SendMessage(hwnd,SCI_GETLINEENDPOSITION,(WPARAM)iLine,0),(LONG)(tr.chrg.cpMin + COUNTOF(tch))); }*/ - tr.chrg.cpMax = min((int)SendMessage(hwnd,SCI_GETTEXTLENGTH,0,0),tr.chrg.cpMax); + tr.chrg.cpMax = min(SciCall_GetTextLength(),tr.chrg.cpMax); pszText = LocalAlloc(LPTR,(tr.chrg.cpMax - tr.chrg.cpMin)+2); pszTextW = LocalAlloc(LPTR,((tr.chrg.cpMax - tr.chrg.cpMin)*2)+2); @@ -4486,7 +4484,7 @@ RegExResult_t __fastcall EditFindHasMatch(HWND hwnd, LPCEDITFINDREPLACE lpefr, B int slen = EditGetFindStrg(hwnd, lpefr, szFind, COUNTOF(szFind)); int start = bFirstMatchOnly ? (int)SendMessage(hwnd, SCI_GETSELECTIONNSTART, 0, 0) : 0; - int end = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); + int end = SciCall_GetTextLength(); int iPos = EditFindInTarget(hwnd, szFind, slen, (int)(lpefr->fuFlags), &start, &end, FALSE); @@ -5242,7 +5240,7 @@ BOOL EditFindNext(HWND hwnd, LPCEDITFINDREPLACE lpefr, BOOL bExtendSelection) { if (slen <= 0) return FALSE; - int iTextLength = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); + int iTextLength = SciCall_GetTextLength(); int start = (int)SendMessage(hwnd, SCI_GETSELECTIONEND, 0, 0); int end = iTextLength; @@ -5309,7 +5307,7 @@ BOOL EditFindPrev(HWND hwnd, LPCEDITFINDREPLACE lpefr, BOOL bExtendSelection) { if (slen <= 0) return FALSE; - int iTextLength = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); + int iTextLength = SciCall_GetTextLength(); int start = max(0, (int)SendMessage(hwnd, SCI_GETSELECTIONSTART, 0, 0)); int end = 0; @@ -5403,8 +5401,8 @@ BOOL EditReplace(HWND hwnd, LPCEDITFINDREPLACE lpefr) { // w/o selection, replacement string is put into current position // but this mayby not intended here if ((BOOL)SendMessage(hwnd, SCI_GETSELECTIONEMPTY, 0, 0)) { - int start = (int)SendMessage(hwnd, SCI_GETCURRENTPOS, 0, 0); - int end = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, start, 0); + int start = SciCall_GetCurrentPos(); + int end = SciCall_GetTextLength(); int _start = start; int iPos = EditFindInTarget(hwnd, lpefr->szFind, StringCchLenA(lpefr->szFind, FNDRPL_BUFFER), @@ -5512,7 +5510,7 @@ int EditReplaceAllInRange(HWND hwnd, LPCEDITFINDREPLACE lpefr, BOOL bShowInfo, i BOOL EditReplaceAll(HWND hwnd,LPCEDITFINDREPLACE lpefr,BOOL bShowInfo) { int start = 0; - int end = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); + int end = SciCall_GetTextLength(); int token = BeginSelUndoAction(); @@ -5585,7 +5583,7 @@ void EditMarkAll(HWND hwnd, char* pszFind, int flags, BOOL bMatchCase, BOOL bMat { EditClearAllMarks(hwnd); - int iTextLength = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); + int iTextLength = SciCall_GetTextLength(); int iFindLength = 0; char* pszText = pszFind; @@ -5700,7 +5698,7 @@ void EditCompleteWord(HWND hwnd, BOOL autoInsert) { LocalFree(pLine); int iRootLen = StringCchLenA(pRoot, cnt + 1); - int iTextLength = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); + int iTextLength = SciCall_GetTextLength(); int start = 0; int end = iTextLength; @@ -5798,7 +5796,7 @@ void EditCompleteWord(HWND hwnd, BOOL autoInsert) { // EditUpdateUrlHotspots() // Find and mark all URL hot-spots // -void EditUpdateUrlHotspots(HWND hwnd, tPos startPos, tPos endPos) +void EditUpdateUrlHotspots(HWND hwnd, int startPos, int endPos) { const char* pszUrlRegEx = "\\b(?:(?:https?|ftp|file)://|www\\.|ftp\\.)" "(?:\\([-A-Z0-9+&@#/%=~_|$?!:,.]*\\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*" @@ -5806,36 +5804,32 @@ void EditUpdateUrlHotspots(HWND hwnd, tPos startPos, tPos endPos) const int iRegExLen = (int)strlen(pszUrlRegEx); - tPos posCurr = (tPos)SendMessage(hwnd, SCI_GETCURRENTPOS, 0, 0); - tPos posTextLength = (tPos)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); - - if ((startPos < 0) || (startPos >= posTextLength)) - { - tPos cln = (tPos)SendMessage(hwnd, SCI_LINEFROMPOSITION, posCurr, 0); - startPos = (tPos)SendMessage(hwnd, SCI_POSITIONFROMLINE, cln-1, 0); + if (endPos < startPos) { + int tmp = startPos; startPos = endPos; endPos = tmp; // swap } - if ((endPos < 0) || (endPos >= posTextLength)) { - tPos cln = (tPos)SendMessage(hwnd, SCI_LINEFROMPOSITION, posCurr, 0); - endPos = (tPos)SendMessage(hwnd, SCI_GETLINEENDPOSITION, cln+1, 0); + if (startPos < 0) { // current line only + int currPos = SciCall_GetCurrentPos(); + int lineNo = SciCall_LineFromPosition(currPos); + startPos = SciCall_PositionFromLine(lineNo); + endPos = (int)SendMessage(hwnd, SCI_GETLINEENDPOSITION, lineNo, 0); } - int start = (int)startPos; - int end = (int)endPos; - int flags = SCFIND_NP3_REGEX; - + int start = startPos; + int end = endPos; while (TRUE) { - int iPos = EditFindInTarget(hwnd, pszUrlRegEx, iRegExLen, flags, &start, &end, (end == start)); + int iPos = EditFindInTarget(hwnd, pszUrlRegEx, iRegExLen, SCFIND_NP3_REGEX, &start, &end, (end == start)); if (iPos < 0) break; // not found // mark this match SendMessage(hwnd, SCI_STARTSTYLING, iPos, 0); - SendMessage(hwnd, SCI_SETSTYLING, (end - start), STYLE_NP3_ID_HOTSPOT); + SendMessage(hwnd, SCI_SETSTYLING, (end - start), Style_GetHotspotID(hwnd)); + // next occurrence start = end; - end = (int)endPos; + end = endPos; if (start >= end) break; @@ -5884,15 +5878,16 @@ BOOL __fastcall EditHighlightIfBrace(HWND hwnd, int iPos) { // // EditMatchBrace() // -void EditMatchBrace(HWND hwnd) { - int iEndStyled = (int)SendMessage(hwnd, SCI_GETENDSTYLED, 0, 0); - if (iEndStyled < (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0)) { - int iLine = (int)SendMessage(hwnd, SCI_LINEFROMPOSITION, iEndStyled, 0); - int iEndStyled2 = (int)SendMessage(hwnd, SCI_POSITIONFROMLINE, iLine, 0); +void EditMatchBrace(HWND hwnd) +{ + int iEndStyled = SciCall_GetEndStyled(); + if (iEndStyled < SciCall_GetTextLength()) { + int iLine = SciCall_LineFromPosition(iEndStyled); + int iEndStyled2 = SciCall_PositionFromLine(iLine); SendMessage(hwnd, SCI_COLOURISE, iEndStyled2, -1); } - int iPos = (int)SendMessage(hwnd, SCI_GETCURRENTPOS, 0, 0); + int iPos = SciCall_GetCurrentPos(); if (!EditHighlightIfBrace(hwnd, iPos)) { // try one before diff --git a/src/Edit.h b/src/Edit.h index e24791d15..322b1f48e 100644 --- a/src/Edit.h +++ b/src/Edit.h @@ -56,8 +56,6 @@ typedef struct _editfindreplace #define INDIC_NP3_MATCH_BRACE 2 #define INDIC_NP3_BAD_BRACE 3 -#define STYLE_NP3_ID_HOTSPOT 222 - HWND EditCreate(HWND); void EditInitWordDelimiter(HWND); @@ -127,7 +125,7 @@ void EditPrintInit(); void EditMatchBrace(HWND); void EditClearAllMarks(HWND); void EditMarkAll(HWND,char*,int,BOOL,BOOL); -void EditUpdateUrlHotspots(HWND, tPos, tPos); +void EditUpdateUrlHotspots(HWND, int, int); void EditSetAccelWordNav(HWND,BOOL); void EditCompleteWord(HWND,BOOL); void EditGetBookmarkList(HWND,LPWSTR,int); diff --git a/src/Helpers.c b/src/Helpers.c index 6fe5995a3..1da2665da 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -6,8 +6,8 @@ * Helpers.c * * General helper functions * * Based on code from Notepad2, (c) Florian Balmer 1996-2011 * -* Parts taken from SciTE, (c) Neil Hodgson * -* MinimizeToTray, (c) 2000 Matthew Ellis * +* Parts taken from SciTE, (c) Neil Hodgson * +* MinimizeToTray, (c) 2000 Matthew Ellis * * * * (c) Rizonesoft 2008-2016 * * https://rizonesoft.com * diff --git a/src/Notepad3.c b/src/Notepad3.c index 276960862..a47d95de5 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -4008,6 +4008,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) Style_SelectLexerDlg(hwndEdit); UpdateStatusbar(); UpdateLineNumberWidth(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); break; @@ -4015,6 +4016,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) Style_ToggleUse2ndDefault(hwndEdit); UpdateStatusbar(); UpdateLineNumberWidth(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); break; @@ -4022,6 +4024,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) Style_ConfigDlg(hwndEdit); UpdateStatusbar(); UpdateLineNumberWidth(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); break; @@ -4029,6 +4032,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) Style_SetDefaultFont(hwndEdit); UpdateStatusbar(); UpdateLineNumberWidth(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); break; @@ -4281,7 +4285,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) case IDM_VIEW_HILITECURRENTLINE: bHiliteCurrentLine = (bHiliteCurrentLine) ? FALSE : TRUE; - Style_SetCurrentLineBackground(hwndEdit); + Style_SetCurrentLineBackground(hwndEdit, bHiliteCurrentLine); break; @@ -5360,11 +5364,11 @@ void OpenHotSpotURL(tPos position) // get right most position of style pos = position; iNewStyle = iStyle; - tPos posTextLength = (tPos)SendMessage(hwndEdit, SCI_GETTEXTLENGTH, 0, 0); + tPos posTextLength = (tPos)SciCall_GetTextLength(); while ((iNewStyle == iStyle) && (++pos < posTextLength)) { iNewStyle = (int)SendMessage(hwndEdit, SCI_GETSTYLEAT, pos, 0); } - tPos lastPos = (pos - 1); + tPos lastPos = pos; tPos length = lastPos - firstPos; @@ -5450,7 +5454,16 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) UpdateToolbar(); UpdateStatusbar(); } - break; + break; // fall-through -> too slow + + case SCN_STYLENEEDED: // needs SCI_SETLEXER(SCLEX_CONTAINER) + { + int startPos = SciCall_GetEndStyled(); + int lineNumber = SciCall_LineFromPosition(startPos); + startPos = SciCall_PositionFromLine(lineNumber); + EditUpdateUrlHotspots(hwndEdit, startPos, (int)scn->position); + } + break; case SCN_CHARADDED: // Auto indent @@ -5602,7 +5615,6 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) } } if (scn->linesAdded != 0) { - EditUpdateUrlHotspots(hwndEdit, -1, -1); UpdateLineNumberWidth(); } bModified = TRUE; @@ -5615,6 +5627,7 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) case SCN_SAVEPOINTREACHED: bModified = FALSE; UpdateToolbar(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); break; case SCN_MARGINCLICK: @@ -7406,6 +7419,7 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp UpdateToolbar(); UpdateStatusbar(); UpdateLineNumberWidth(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); // Terminate file watching if (bResetFileWatching) @@ -7535,7 +7549,7 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp InstallFileWatching(szCurFile); // the .LOG feature ... - if (SendMessage(hwndEdit,SCI_GETTEXTLENGTH,0,0) >= 4) { + if (SciCall_GetTextLength() >= 4) { char tchLog[5] = { '\0' }; SendMessage(hwndEdit,SCI_GETTEXT,5,(LPARAM)tchLog); if (StringCchCompareXA(tchLog,".LOG") == 0) { @@ -7564,8 +7578,7 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp UpdateToolbar(); UpdateStatusbar(); UpdateLineNumberWidth(); - - EditUpdateUrlHotspots(hwndEdit, 0, (tPos)SendMessage(hwndEdit, SCI_GETTEXTLENGTH, 0, 0) - 1); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); // consistent settings file handling (if loaded in editor) bEnableSaveSettings = (StringCchCompareINW(szCurFile, COUNTOF(szCurFile), szIniFile, COUNTOF(szIniFile)) == 0) ? FALSE : TRUE; @@ -7733,6 +7746,7 @@ BOOL FileSave(BOOL bSaveAlways,BOOL bAsk,BOOL bSaveAs,BOOL bSaveCopy) Style_SetLexerFromFile(hwndEdit,szCurFile); UpdateStatusbar(); UpdateLineNumberWidth(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); } else { StringCchCopy(tchLastSaveCopyDir,COUNTOF(tchLastSaveCopyDir),tchFile); diff --git a/src/Notepad3.rc b/src/Notepad3.rc index 29cd5110fd8f555921a7c0b79779d26beab22d30..e67679e5c7e5de65fe4bb4545d68cca6290bcf49 100644 GIT binary patch delta 101 zcmbO+m;1~-?uHh|Elj75P7gTBBrx46mq|-Flp%=0he3hCgCU=xgrS(BfFXbS#6~93 p=?ji9u}n8v$fPyBp_hq66pK2BlIe-3fGVv{Gf8d#bd+fs2LL<|9-;sM delta 24 gcmX>zk9)>k?uHh|Elj75PUos&;@jSHjOhRe0E0dX00000 diff --git a/src/SciCall.h b/src/SciCall.h index 6c1dc2cf4..eff3c7574 100644 --- a/src/SciCall.h +++ b/src/SciCall.h @@ -83,11 +83,14 @@ __forceinline LRESULT SciCall_##fn(type1 var1, type2 var2) { \ // // DeclareSciCallR0(GetLineCount, GETLINECOUNT, int); +DeclareSciCallR0(GetTextLength, GETTEXTLENGTH, int); DeclareSciCallV2(SetSel, SETSEL, int, anchorPos, int, currentPos); DeclareSciCallV1(GotoPos, GOTOPOS, int, position); DeclareSciCallV1(GotoLine, GOTOLINE, int, line); DeclareSciCallR0(GetCurrentPos, GETCURRENTPOS, int); DeclareSciCallR1(LineFromPosition, LINEFROMPOSITION, int, Sci_Position, position); +DeclareSciCallR1(PositionFromLine, POSITIONFROMLINE, int, Sci_Position, line); +DeclareSciCallR0(GetEndStyled, GETENDSTYLED, int); //============================================================================= diff --git a/src/Styles.c b/src/Styles.c index a8b807fe2..97770e931 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -71,25 +71,26 @@ EDITLEXER lexDefault = { SCLEX_NULL, 63000, L"Default Text", L"txt; text; wtx; /* 11 */ { SCI_SETEXTRAASCENT+SCI_SETEXTRADESCENT, 63111, L"Extra Line Spacing (Size)", L"size:2", L"" }, /* 12 */ { SCI_MARKERSETBACK+SCI_MARKERSETALPHA, 63124, L"Book Marks (Colors)", L"back:#00FF00; alpha:20", L"" }, /* 13 */ { SCI_MARKERSETBACK+SCI_MARKERSETALPHA, 63262, L"Mark Occurrences (Colors)", L"", L"" }, - - /* 14 */ { STYLE_DEFAULT, 63112, L"2nd Default Style", L"font:Courier New; size:10", L"" }, - /* 15 */ { STYLE_LINENUMBER, 63113, L"2nd Margins and Line Numbers", L"font:Tahoma; size:-2; fore:#FF0000", L"" }, - /* 16 */ { STYLE_BRACELIGHT, 63114, L"2nd Matching Braces", L"bold; fore:#FF0000", L"" }, - /* 17 */ { STYLE_BRACEBAD, 63115, L"2nd Matching Braces Error", L"bold; fore:#000080", L"" }, - /* 18 */ { STYLE_CONTROLCHAR, 63116, L"2nd Control Characters (Font)", L"size:-1", L"" }, - /* 19 */ { STYLE_INDENTGUIDE, 63117, L"2nd Indentation Guide (Color)", L"fore:#A0A0A0", L"" }, - /* 20 */ { SCI_SETSELFORE+SCI_SETSELBACK, 63118, L"2nd Selected Text (Colors)", L"eolfilled", L"" }, - /* 21 */ { SCI_SETWHITESPACEFORE+SCI_SETWHITESPACEBACK+SCI_SETWHITESPACESIZE, 63119, L"2nd Whitespace (Colors, Size 0-5)", L"fore:#FF4000", L"" }, - /* 22 */ { SCI_SETCARETLINEBACK, 63120, L"2nd Current Line Background (Color)", L"back:#FFFF00; alpha:50", L"" }, - /* 23 */ { SCI_SETCARETFORE+SCI_SETCARETWIDTH, 63121, L"2nd Caret (Color, Size 1-3)", L"", L"" }, - /* 24 */ { SCI_SETEDGECOLOUR, 63122, L"2nd Long Line Marker (Colors)", L"fore:#FFC000", L"" }, - /* 25 */ { SCI_SETEXTRAASCENT+SCI_SETEXTRADESCENT, 63123, L"2nd Extra Line Spacing (Size)", L"", L"" }, - /* 26 */ { SCI_MARKERSETBACK+SCI_MARKERSETALPHA, 63125, L"2nd Book Marks (Colors)", L"back:#00FF00; alpha:20", L"" }, - /* 27 */ { SCI_MARKERSETBACK+SCI_MARKERSETALPHA, 63263, L"2nd Mark Occurrences (Colors)", L"fore:#0x00FF00; alpha:100; alpha2:100", L"" }, + /* 14 */ { SCI_SETHOTSPOTACTIVEFORE, 63264, L"URL Hotspot", L"italics; fore:#0000FF", L"" }, + + /* 15 */ { STYLE_DEFAULT, 63112, L"2nd Default Style", L"font:Courier New; size:10", L"" }, + /* 16 */ { STYLE_LINENUMBER, 63113, L"2nd Margins and Line Numbers", L"font:Tahoma; size:-2; fore:#FF0000", L"" }, + /* 17 */ { STYLE_BRACELIGHT, 63114, L"2nd Matching Braces", L"bold; fore:#FF0000", L"" }, + /* 18 */ { STYLE_BRACEBAD, 63115, L"2nd Matching Braces Error", L"bold; fore:#000080", L"" }, + /* 19 */ { STYLE_CONTROLCHAR, 63116, L"2nd Control Characters (Font)", L"size:-1", L"" }, + /* 20 */ { STYLE_INDENTGUIDE, 63117, L"2nd Indentation Guide (Color)", L"fore:#A0A0A0", L"" }, + /* 21 */ { SCI_SETSELFORE + SCI_SETSELBACK, 63118, L"2nd Selected Text (Colors)", L"eolfilled", L"" }, + /* 22 */ { SCI_SETWHITESPACEFORE + SCI_SETWHITESPACEBACK + SCI_SETWHITESPACESIZE, 63119, L"2nd Whitespace (Colors, Size 0-5)", L"fore:#FF4000", L"" }, + /* 23 */ { SCI_SETCARETLINEBACK, 63120, L"2nd Current Line Background (Color)", L"back:#FFFF00; alpha:50", L"" }, + /* 24 */ { SCI_SETCARETFORE + SCI_SETCARETWIDTH, 63121, L"2nd Caret (Color, Size 1-3)", L"", L"" }, + /* 25 */ { SCI_SETEDGECOLOUR, 63122, L"2nd Long Line Marker (Colors)", L"fore:#FFC000", L"" }, + /* 26 */ { SCI_SETEXTRAASCENT + SCI_SETEXTRADESCENT, 63123, L"2nd Extra Line Spacing (Size)", L"", L"" }, + /* 27 */ { SCI_MARKERSETBACK+SCI_MARKERSETALPHA, 63125, L"2nd Book Marks (Colors)", L"back:#00FF00; alpha:20", L"" }, + /* 28 */ { SCI_MARKERSETBACK+SCI_MARKERSETALPHA, 63263, L"2nd Mark Occurrences (Colors)", L"fore:#0x00FF00; alpha:100; alpha2:100", L"" }, + /* 29 */ { SCI_SETHOTSPOTACTIVEFORE, 63265, L"2nd URL Hotspot", L"bold; fore:#FF0000", L"" }, { -1, 00000, L"", L"", L"" } } }; - enum LexDefaultStyles { STY_DEFAULT = 0, STY_MARGIN = 1, @@ -105,8 +106,9 @@ enum LexDefaultStyles { STY_X_LN_SPACE = 11, STY_BOOK_MARK = 12, STY_MARK_OCC = 13, + STY_URL_HOTSPOT = 14, - STY_CNT_LAST = 14 // STY_2ND_XXX = STY_XXX + STY_CNT_LAST + STY_CNT_LAST = 15 // STY_2ND_XXX = STY_XXX + STY_CNT_LAST }; @@ -3250,11 +3252,13 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { SendMessage(hwnd, SCI_INDICSETOUTLINEALPHA, INDIC_NP3_MARK_OCCURANCE, iValue); + // More default values... + if (pLexNew != &lexANSI) Style_SetStyles(hwnd, lexDefault.Styles[STY_CTRL_CHR + iIdx].iStyle, lexDefault.Styles[STY_CTRL_CHR + iIdx].szValue); // control char + Style_SetStyles(hwnd, lexDefault.Styles[STY_INDENT_GUIDE + iIdx].iStyle, lexDefault.Styles[STY_INDENT_GUIDE + iIdx].szValue); // indent guide - // More default values... if (Style_StrGetColor(TRUE, lexDefault.Styles[STY_SEL_TXT + iIdx].szValue, &rgb)) { // selection fore SendMessage(hwnd, SCI_SETSELFORE, TRUE, rgb); SendMessage(hwnd, SCI_SETADDITIONALSELFORE, rgb, 0); @@ -3326,24 +3330,8 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { } SendMessage(hwnd, SCI_SETWHITESPACESIZE, iValue, 0); - if (bHiliteCurrentLine) { - - if (Style_StrGetColor(FALSE, lexDefault.Styles[STY_CUR_LN_BCK + iIdx].szValue, &rgb)) // caret line back - { - SendMessage(hwnd, SCI_SETCARETLINEVISIBLE, TRUE, 0); - SendMessage(hwnd, SCI_SETCARETLINEBACK, rgb, 0); - - if (Style_StrGetAlpha(lexDefault.Styles[STY_CUR_LN_BCK + iIdx].szValue, &iValue, TRUE)) - SendMessage(hwnd, SCI_SETCARETLINEBACKALPHA, iValue, 0); - else - SendMessage(hwnd, SCI_SETCARETLINEBACKALPHA, SC_ALPHA_NOALPHA, 0); - } - else - SendMessage(hwnd, SCI_SETCARETLINEVISIBLE, FALSE, 0); - } - else - SendMessage(hwnd, SCI_SETCARETLINEVISIBLE, FALSE, 0); - + // current line background + Style_SetCurrentLineBackground(hwnd, bHiliteCurrentLine); // bookmark line or marker Style_SetCurrentMargin(hwnd, bShowSelectionMargin); @@ -3559,16 +3547,7 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { } } - // Hot Spot settings - SendMessage(hwnd, SCI_STYLESETFORE, STYLE_NP3_ID_HOTSPOT, (LPARAM)RGB(0, 0, 200)); - SendMessage(hwnd, SCI_STYLESETITALIC, STYLE_NP3_ID_HOTSPOT, (LPARAM)TRUE); - //SendMessage(hwnd, SCI_STYLESETUNDERLINE, iHotSpotStyle, (LPARAM)TRUE); - - SendMessage(hwnd, SCI_STYLESETHOTSPOT, STYLE_NP3_ID_HOTSPOT, (LPARAM)TRUE); - SendMessage(hwnd, SCI_SETHOTSPOTACTIVEFORE, TRUE, (LPARAM)RGB(0, 0, 255)); - SendMessage(hwnd, SCI_SETHOTSPOTACTIVEUNDERLINE, TRUE, 0); - SendMessage(hwnd, SCI_SETHOTSPOTSINGLELINE, TRUE, 0); - + Style_SetUrlHotSpot(hwnd, TRUE); SendMessage(hwnd,SCI_COLOURISE,0,(LPARAM)-1); @@ -3577,6 +3556,54 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { } +//============================================================================= +// +// Style_SetUrlHotSpot() +// +void Style_SetUrlHotSpot(HWND hwnd, BOOL bHotSpot) +{ + // Use 2nd default style ? + int iIdx = (bUse2ndDefaultStyle) ? STY_CNT_LAST : 0; + + // Hot Spot settings + const int iStyleHotSpot = (STY_URL_HOTSPOT + iIdx); + + if (bHotSpot) + { + const WCHAR* lpszStyleHotSpot = lexDefault.Styles[iStyleHotSpot].szValue; + + SendMessage(hwnd, SCI_STYLESETHOTSPOT, iStyleHotSpot, (LPARAM)TRUE); + SendMessage(hwnd, SCI_SETHOTSPOTSINGLELINE, TRUE, 0); + + // Font + Style_SetStyles(hwnd, iStyleHotSpot, lpszStyleHotSpot); + + //if (StrStrI(lpszStyleHotSpot, L"underline") != NULL) + // SendMessage(hwnd, SCI_SETHOTSPOTACTIVEUNDERLINE, TRUE, 0); + //else + // SendMessage(hwnd, SCI_SETHOTSPOTACTIVEUNDERLINE, FALSE, 0); + // Fore + SendMessage(hwnd, SCI_SETHOTSPOTACTIVEUNDERLINE, TRUE, 0); + + int rgb; + + if (Style_StrGetColor(TRUE, lpszStyleHotSpot, &rgb)) { + int inactiveFG = (int)((rgb * 75 + 50) / 100); + SendMessage(hwnd, SCI_STYLESETFORE, iStyleHotSpot, (LPARAM)inactiveFG); + SendMessage(hwnd, SCI_SETHOTSPOTACTIVEFORE, TRUE, (LPARAM)rgb); + } + // Back + if (Style_StrGetColor(FALSE, lpszStyleHotSpot, &rgb)) { + SendMessage(hwnd, SCI_STYLESETBACK, iStyleHotSpot, (LPARAM)rgb); + SendMessage(hwnd, SCI_SETHOTSPOTACTIVEBACK, TRUE, (LPARAM)rgb); + } + } + else + SendMessage(hwnd, SCI_STYLESETHOTSPOT, iStyleHotSpot, (LPARAM)FALSE); + +} + + //============================================================================= // // Style_SetLongLineColors() @@ -3607,12 +3634,13 @@ void Style_SetLongLineColors(HWND hwnd) // // Style_SetCurrentLineBackground() // -void Style_SetCurrentLineBackground(HWND hwnd) +void Style_SetCurrentLineBackground(HWND hwnd, BOOL bHiLitCurrLn) { - // Use 2nd default style - int iIdx = (bUse2ndDefaultStyle) ? STY_CNT_LAST : 0; + if (bHiLitCurrLn) { + + // Use 2nd default style ? + int iIdx = (bUse2ndDefaultStyle) ? STY_CNT_LAST : 0; - if (bHiliteCurrentLine) { int rgb = 0; if (Style_StrGetColor(FALSE,lexDefault.Styles[STY_CUR_LN_BCK + iIdx].szValue,&rgb)) // caret line back { @@ -5595,4 +5623,14 @@ void Style_SelectLexerDlg(HWND hwnd) } +//============================================================================= +// +// Style_GetHotspotID() +// +int Style_GetHotspotID(HWND hwnd) +{ + UNUSED(hwnd); + return (bUse2ndDefaultStyle ? (STY_URL_HOTSPOT + STY_CNT_LAST) : STY_URL_HOTSPOT); +} + // End of Styles.c diff --git a/src/Styles.h b/src/Styles.h index a079bc953..fd580e430 100644 --- a/src/Styles.h +++ b/src/Styles.h @@ -67,8 +67,9 @@ void Style_Save(); BOOL Style_Import(HWND); BOOL Style_Export(HWND); void Style_SetLexer(HWND,PEDITLEXER); +void Style_SetUrlHotSpot(HWND, BOOL); void Style_SetLongLineColors(HWND); -void Style_SetCurrentLineBackground(HWND); +void Style_SetCurrentLineBackground(HWND, BOOL); void Style_SetCurrentMargin(HWND, BOOL); void Style_SetLexerFromFile(HWND,LPCWSTR); void Style_SetLexerFromName(HWND,LPCWSTR,LPCWSTR); @@ -101,6 +102,7 @@ INT_PTR CALLBACK Styles_ConfigDlgProc(HWND,UINT,WPARAM,LPARAM); void Style_ConfigDlg(HWND); INT_PTR CALLBACK Style_SelectLexerDlgProc(HWND,UINT,WPARAM,LPARAM); void Style_SelectLexerDlg(HWND); +int Style_GetHotspotID(HWND); #endif //_NP3_STYLES_H_ From 8b17a597f19939f68ceaf6fc2d658be544ecb47f Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 8 Dec 2017 12:05:01 +0100 Subject: [PATCH 4/6] + refactoring and enhancements for Hyperlink Hotspot feature --- src/Edit.c | 58 ++++++++++++++++++++++----------------------- src/Notepad3.c | 61 ++++++++++++++++++++++++++++++++++-------------- src/Notepad3.h | 1 + src/Notepad3.rc | Bin 184140 -> 184756 bytes src/SciCall.h | 4 +++- src/Styles.c | 22 ++++++++++++----- src/resource.h | 4 +++- 7 files changed, 94 insertions(+), 56 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index 34050fa6f..f96ae1842 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -322,7 +322,7 @@ BOOL EditConvertText(HWND hwnd,int encSource,int encDest,BOOL bSetSavePoint) if (!(Encoding_IsValid(encSource) && Encoding_IsValid(encDest))) return(FALSE); - length = SciCall_GetTextLength(); + length = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); if (length == 0) { @@ -395,7 +395,7 @@ BOOL EditSetNewEncoding(HWND hwnd,int iNewEncoding,BOOL bNoUI,BOOL bSetSavePoint //return FALSE; // commented out ? : allow conversion between arbitrary encodings //} - if (SciCall_GetTextLength() == 0) { + if (SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0) == 0) { BOOL bIsEmptyUndoHistory = (SendMessage(hwnd, SCI_CANUNDO, 0, 0) == 0 && SendMessage(hwnd, SCI_CANREDO, 0, 0) == 0); @@ -625,7 +625,7 @@ BOOL EditCopyAppend(HWND hwnd) } } else { - int cchText = SciCall_GetTextLength(); + int cchText = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); pszText = LocalAlloc(LPTR,cchText + 1); SendMessage(hwnd,SCI_GETTEXT,(int)LocalSize(pszText),(LPARAM)pszText); } @@ -1048,7 +1048,7 @@ BOOL EditSaveFile( EditStripTrailingBlanks(hwnd,TRUE); // get text - cbData = SciCall_GetTextLength(); + cbData = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); lpData = GlobalAlloc(GPTR, cbData + 4); //fix: +bom SendMessage(hwnd,SCI_GETTEXT,GlobalSize(lpData),(LPARAM)lpData); @@ -2281,8 +2281,7 @@ void EditMoveDown(HWND hwnd) if (bLastLine) { SendMessage(hwnd,SCI_SETTARGETSTART,(WPARAM) - SendMessage(hwnd,SCI_GETLINEENDPOSITION,(WPARAM) - SendMessage(hwnd,SCI_GETLINECOUNT,0,0)-2,0),0); + SendMessage(hwnd,SCI_GETLINEENDPOSITION,(WPARAM)SciCall_GetLineCount()-2,0),0); SendMessage(hwnd,SCI_SETTARGETEND,(WPARAM)SciCall_GetTextLength(),0); SendMessage(hwnd,SCI_REPLACETARGET,0,(LPARAM)""); } @@ -2331,7 +2330,7 @@ void EditModifyLines(HWND hwnd,LPCWSTR pwszPrefix,LPCWSTR pwszAppend) //if (iSelStart == iSelEnd) { // iSelStart = 0; - // iSelEnd = SciCall_GetTextLength(); + // iSelEnd = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); //} UINT mbcp = Encoding_SciGetCodePage(hwnd); @@ -3081,10 +3080,8 @@ void EditPadWithSpaces(HWND hwnd,BOOL bSkipEmpty,BOOL bNoUndoGroup) iRcAnchorLine = (int)SendMessage(hwnd,SCI_LINEFROMPOSITION,(WPARAM)iAnchorPos,0); iRcCurCol = (int)SendMessage(hwnd,SCI_GETCOLUMN,(WPARAM)iCurPos,0); - //iRcCurCol += (int)SendMessage(hwnd, SCI_GETSELECTIONNCARETVIRTUALSPACE, 0, 0); iRcAnchorCol = (int)SendMessage(hwnd,SCI_GETCOLUMN,(WPARAM)iAnchorPos,0); - //iRcAnchorCol += (int)SendMessage(hwnd, SCI_GETSELECTIONNANCHORVIRTUALSPACE, 0, 0); bIsRectangular = TRUE; @@ -3096,7 +3093,6 @@ void EditPadWithSpaces(HWND hwnd,BOOL bSkipEmpty,BOOL bNoUndoGroup) int iPos = (int)SendMessage(hwnd,SCI_GETLINESELENDPOSITION,(WPARAM)iLine,0); if (iPos != INVALID_POSITION) { int iCol = (int)SendMessage(hwnd, SCI_GETCOLUMN, (WPARAM)iPos, 0); - //iCol += (int)SendMessage(hwndEdit, SCI_GETSELECTIONNCARETVIRTUALSPACE, 0, 0); iMaxColumn = max(iMaxColumn, iCol); } } @@ -3185,7 +3181,7 @@ void EditStripFirstCharacter(HWND hwnd) if (iSelStart == iSelEnd) { iSelStart = 0; - iSelEnd = SciCall_GetTextLength(); + iSelEnd = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); } if (SC_SEL_RECTANGLE != SendMessage(hwnd,SCI_GETSELECTIONMODE,0,0)) @@ -3232,7 +3228,7 @@ void EditStripLastCharacter(HWND hwnd) if (iSelStart == iSelEnd) { iSelStart = 0; - iSelEnd = SciCall_GetTextLength(); + iSelEnd = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); } if (SC_SEL_RECTANGLE != SendMessage(hwnd,SCI_GETSELECTIONMODE,0,0)) @@ -3338,7 +3334,7 @@ void EditCompressSpaces(HWND hwnd) int iAnchorPos = (int)SendMessage(hwnd,SCI_GETANCHOR,0,0); int iLineStart = (int)SendMessage(hwnd,SCI_LINEFROMPOSITION,(WPARAM)iSelStart,0); int iLineEnd = (int)SendMessage(hwnd,SCI_LINEFROMPOSITION,(WPARAM)iSelEnd,0); - int iLength = SciCall_GetTextLength(); + int iLength = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); char* pszIn; char* pszOut; @@ -3435,7 +3431,7 @@ void EditRemoveBlankLines(HWND hwnd,BOOL bMerge) if (iSelStart == iSelEnd) { iSelStart = 0; - iSelEnd = SciCall_GetTextLength(); + iSelEnd = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); } if (SC_SEL_RECTANGLE != SendMessage(hwnd,SCI_GETSELECTIONMODE,0,0)) @@ -4198,7 +4194,7 @@ void EditSelectEx(HWND hwnd,int iAnchorPos,int iCurrentPos) // void EditFixPositions(HWND hwnd) { - int iMaxPos = SciCall_GetTextLength(); + int iMaxPos = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); int iCurrentPos = (int)SendMessage(hwnd,SCI_GETCURRENTPOS,0,0); int iAnchorPos = (int)SendMessage(hwnd,SCI_GETANCHOR,0,0); @@ -4272,7 +4268,7 @@ void EditGetExcerpt(HWND hwnd,LPWSTR lpszExcerpt,DWORD cchExcerpt) tr.chrg.cpMax = min(SendMessage(hwnd,SCI_GETLINEENDPOSITION,(WPARAM)iLine,0),(LONG)(tr.chrg.cpMin + COUNTOF(tch))); }*/ - tr.chrg.cpMax = min(SciCall_GetTextLength(),tr.chrg.cpMax); + tr.chrg.cpMax = min((int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0), tr.chrg.cpMax); pszText = LocalAlloc(LPTR,(tr.chrg.cpMax - tr.chrg.cpMin)+2); pszTextW = LocalAlloc(LPTR,((tr.chrg.cpMax - tr.chrg.cpMin)*2)+2); @@ -4484,7 +4480,7 @@ RegExResult_t __fastcall EditFindHasMatch(HWND hwnd, LPCEDITFINDREPLACE lpefr, B int slen = EditGetFindStrg(hwnd, lpefr, szFind, COUNTOF(szFind)); int start = bFirstMatchOnly ? (int)SendMessage(hwnd, SCI_GETSELECTIONNSTART, 0, 0) : 0; - int end = SciCall_GetTextLength(); + int end = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); int iPos = EditFindInTarget(hwnd, szFind, slen, (int)(lpefr->fuFlags), &start, &end, FALSE); @@ -5240,7 +5236,7 @@ BOOL EditFindNext(HWND hwnd, LPCEDITFINDREPLACE lpefr, BOOL bExtendSelection) { if (slen <= 0) return FALSE; - int iTextLength = SciCall_GetTextLength(); + int iTextLength = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); int start = (int)SendMessage(hwnd, SCI_GETSELECTIONEND, 0, 0); int end = iTextLength; @@ -5307,7 +5303,7 @@ BOOL EditFindPrev(HWND hwnd, LPCEDITFINDREPLACE lpefr, BOOL bExtendSelection) { if (slen <= 0) return FALSE; - int iTextLength = SciCall_GetTextLength(); + int iTextLength = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); int start = max(0, (int)SendMessage(hwnd, SCI_GETSELECTIONSTART, 0, 0)); int end = 0; @@ -5401,8 +5397,8 @@ BOOL EditReplace(HWND hwnd, LPCEDITFINDREPLACE lpefr) { // w/o selection, replacement string is put into current position // but this mayby not intended here if ((BOOL)SendMessage(hwnd, SCI_GETSELECTIONEMPTY, 0, 0)) { - int start = SciCall_GetCurrentPos(); - int end = SciCall_GetTextLength(); + int start = (int)SendMessage(hwnd, SCI_GETCURRENTPOS, 0, 0); + int end = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); int _start = start; int iPos = EditFindInTarget(hwnd, lpefr->szFind, StringCchLenA(lpefr->szFind, FNDRPL_BUFFER), @@ -5583,7 +5579,7 @@ void EditMarkAll(HWND hwnd, char* pszFind, int flags, BOOL bMatchCase, BOOL bMat { EditClearAllMarks(hwnd); - int iTextLength = SciCall_GetTextLength(); + int iTextLength = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); int iFindLength = 0; char* pszText = pszFind; @@ -5698,7 +5694,7 @@ void EditCompleteWord(HWND hwnd, BOOL autoInsert) { LocalFree(pLine); int iRootLen = StringCchLenA(pRoot, cnt + 1); - int iTextLength = SciCall_GetTextLength(); + int iTextLength = (int)SendMessage(hwnd, SCI_GETTEXTLENGTH, 0, 0); int start = 0; int end = iTextLength; @@ -5811,26 +5807,27 @@ void EditUpdateUrlHotspots(HWND hwnd, int startPos, int endPos) int currPos = SciCall_GetCurrentPos(); int lineNo = SciCall_LineFromPosition(currPos); startPos = SciCall_PositionFromLine(lineNo); - endPos = (int)SendMessage(hwnd, SCI_GETLINEENDPOSITION, lineNo, 0); + endPos = SciCall_GetLineEndPosition(lineNo); } + if (endPos == startPos) + return; int start = startPos; int end = endPos; while (TRUE) { - int iPos = EditFindInTarget(hwnd, pszUrlRegEx, iRegExLen, SCFIND_NP3_REGEX, &start, &end, (end == start)); + int iPos = EditFindInTarget(hwnd, pszUrlRegEx, iRegExLen, SCFIND_NP3_REGEX, &start, &end, FALSE); if (iPos < 0) break; // not found // mark this match - SendMessage(hwnd, SCI_STARTSTYLING, iPos, 0); - SendMessage(hwnd, SCI_SETSTYLING, (end - start), Style_GetHotspotID(hwnd)); + SciCall_StartStyling(iPos); + SciCall_SetStyling((end - start), Style_GetHotspotID(hwnd)); // next occurrence start = end; end = endPos; - if (start >= end) break; } @@ -5883,8 +5880,9 @@ void EditMatchBrace(HWND hwnd) int iEndStyled = SciCall_GetEndStyled(); if (iEndStyled < SciCall_GetTextLength()) { int iLine = SciCall_LineFromPosition(iEndStyled); - int iEndStyled2 = SciCall_PositionFromLine(iLine); - SendMessage(hwnd, SCI_COLOURISE, iEndStyled2, -1); + iEndStyled = SciCall_PositionFromLine(iLine); + SendMessage(hwnd, SCI_COLOURISE, iEndStyled, -1); + //EditUpdateUrlHotspots(hwnd, iEndStyled, SciCall_GetLineEndPosition(iLine)); } int iPos = SciCall_GetCurrentPos(); diff --git a/src/Notepad3.c b/src/Notepad3.c index a47d95de5..4bffa5dd8 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -131,6 +131,7 @@ BOOL bAutoIndent; BOOL bAutoCloseTags; BOOL bShowIndentGuides; BOOL bHiliteCurrentLine; +BOOL bHyperlinkHotspot; BOOL bTabsAsSpaces; BOOL bTabsAsSpacesG; BOOL bTabIndents; @@ -2388,7 +2389,8 @@ void MsgInitMenu(HWND hwnd,WPARAM wParam,LPARAM lParam) i = (int)SendMessage(hwndEdit,SCI_GETLEXER,0,0); //EnableCmd(hmenu,IDM_VIEW_AUTOCLOSETAGS,(i == SCLEX_HTML || i == SCLEX_XML)); CheckCmd(hmenu,IDM_VIEW_AUTOCLOSETAGS,bAutoCloseTags /*&& (i == SCLEX_HTML || i == SCLEX_XML)*/); - CheckCmd(hmenu,IDM_VIEW_HILITECURRENTLINE,bHiliteCurrentLine); + CheckCmd(hmenu, IDM_VIEW_HILITECURRENTLINE, bHiliteCurrentLine); + CheckCmd(hmenu, IDM_VIEW_HYPERLINKHOTSPOTS, bHyperlinkHotspot); i = IniGetInt(L"Settings2",L"ReuseWindow",0); CheckCmd(hmenu,IDM_VIEW_REUSEWINDOW,i); @@ -2441,6 +2443,10 @@ void MsgInitMenu(HWND hwnd,WPARAM wParam,LPARAM lParam) i = (StringCchLenW(szIniFile,COUNTOF(szIniFile)) > 0 || StringCchLenW(szIniFile2,COUNTOF(szIniFile2)) > 0); EnableCmd(hmenu,IDM_VIEW_SAVESETTINGSNOW,bEnableSaveSettings && i); + BOOL bIsHLink = ((int)SendMessage(hwndEdit, SCI_GETSTYLEAT, + SendMessage(hwndEdit, SCI_GETCURRENTPOS, 0, 0), 0) == Style_GetHotspotID(hwndEdit)); + EnableCmd(hmenu, CMD_OPEN_HYPERLINK, bIsHLink); + UNUSED(lParam); } @@ -4288,6 +4294,13 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) Style_SetCurrentLineBackground(hwndEdit, bHiliteCurrentLine); break; + case IDM_VIEW_HYPERLINKHOTSPOTS: + bHyperlinkHotspot = (bHyperlinkHotspot) ? FALSE : TRUE; + Style_SetUrlHotSpot(hwndEdit, bHyperlinkHotspot); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); + if (!bHyperlinkHotspot) + SendMessage(hwndEdit, SCI_COLOURISE, 0, (LPARAM)-1); + break; case IDM_VIEW_ZOOMIN: SendMessage(hwndEdit,SCI_ZOOMIN,0,0); @@ -5138,6 +5151,12 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) break; + case CMD_OPEN_HYPERLINK: + { + OpenHotSpotURL((int)SendMessage(hwndEdit, SCI_GETCURRENTPOS, 0, 0)); + } + break; + case IDT_FILE_NEW: if (IsCmdEnabled(hwnd,IDM_FILE_NEW)) SendMessage(hwnd,WM_COMMAND,MAKELONG(IDM_FILE_NEW,1),0); @@ -5349,28 +5368,31 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) // OpenHotSpotURL() - Handles WM_NOTIFY // // -void OpenHotSpotURL(tPos position) +void OpenHotSpotURL(int position) { int iStyle = (int)SendMessage(hwndEdit, SCI_GETSTYLEAT, position, 0); - int iNewStyle = iStyle; + + if (Style_GetHotspotID(hwndEdit) != iStyle) + return; // get left most position of style - tPos pos = position; + int pos = position; + int iNewStyle = iStyle; while ((iNewStyle == iStyle) && (--pos > 0)) { iNewStyle = (int)SendMessage(hwndEdit, SCI_GETSTYLEAT, pos, 0); } - tPos firstPos = (pos != 0) ? (pos + 1) : 0; + int firstPos = (pos != 0) ? (pos + 1) : 0; // get right most position of style pos = position; iNewStyle = iStyle; - tPos posTextLength = (tPos)SciCall_GetTextLength(); + int posTextLength = SciCall_GetTextLength(); while ((iNewStyle == iStyle) && (++pos < posTextLength)) { iNewStyle = (int)SendMessage(hwndEdit, SCI_GETSTYLEAT, pos, 0); } - tPos lastPos = pos; + int lastPos = pos; - tPos length = lastPos - firstPos; + int length = lastPos - firstPos; if ((length > 0) && (length < HUGE_BUFFER)) { @@ -5432,7 +5454,7 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) case SCN_HOTSPOTCLICK: { if (scn->modifiers & SCMOD_CTRL) { - OpenHotSpotURL(scn->position); + OpenHotSpotURL((int)scn->position); } } break; @@ -5456,14 +5478,14 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) } break; // fall-through -> too slow - case SCN_STYLENEEDED: // needs SCI_SETLEXER(SCLEX_CONTAINER) - { - int startPos = SciCall_GetEndStyled(); - int lineNumber = SciCall_LineFromPosition(startPos); - startPos = SciCall_PositionFromLine(lineNumber); - EditUpdateUrlHotspots(hwndEdit, startPos, (int)scn->position); - } - break; + case SCN_STYLENEEDED: // this event needs SCI_SETLEXER(SCLEX_CONTAINER) + { + if (bHyperlinkHotspot) { + int lineNumber = SciCall_LineFromPosition(SciCall_GetEndStyled()); + EditUpdateUrlHotspots(hwndEdit, SciCall_PositionFromLine(lineNumber), (int)scn->position); + } + } + break; case SCN_CHARADDED: // Auto indent @@ -5643,6 +5665,7 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) case SCN_SAVEPOINTLEFT: bModified = TRUE; UpdateToolbar(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); break; } break; @@ -5849,6 +5872,8 @@ void LoadSettings() bHiliteCurrentLine = IniSectionGetBool(pIniSection,L"HighlightCurrentLine",FALSE); + bHyperlinkHotspot = IniSectionGetBool(pIniSection, L"HyperlinkHotspot", TRUE); + bAutoIndent = IniSectionGetBool(pIniSection,L"AutoIndent",TRUE); bAutoCompleteWords = IniSectionGetBool(pIniSection,L"AutoCompleteWords",FALSE); @@ -6169,6 +6194,7 @@ void SaveSettings(BOOL bSaveSettingsNow) { IniSectionSetBool(pIniSection, L"MatchBraces", bMatchBraces); IniSectionSetBool(pIniSection, L"AutoCloseTags", bAutoCloseTags); IniSectionSetBool(pIniSection, L"HighlightCurrentLine", bHiliteCurrentLine); + IniSectionSetBool(pIniSection, L"HyperlinkHotspot", bHyperlinkHotspot); IniSectionSetBool(pIniSection, L"AutoIndent", bAutoIndent); IniSectionSetBool(pIniSection, L"AutoCompleteWords", bAutoCompleteWords); IniSectionSetBool(pIniSection, L"AccelWordNavigation", bAccelWordNavigation); @@ -7419,7 +7445,6 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp UpdateToolbar(); UpdateStatusbar(); UpdateLineNumberWidth(); - EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); // Terminate file watching if (bResetFileWatching) diff --git a/src/Notepad3.h b/src/Notepad3.h index 08929339d..30d6bb6e6 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -149,6 +149,7 @@ int BeginSelUndoAction(); void EndSelUndoAction(int); void RestoreSelectionAction(int,DoAction); int UndoRedoSelectionMap(int,UndoRedoSelection_t*); +void OpenHotSpotURL(int); BOOL FileIO(BOOL,LPCWSTR,BOOL,int*,int*,BOOL*,BOOL*,BOOL*,BOOL*,BOOL); diff --git a/src/Notepad3.rc b/src/Notepad3.rc index e67679e5c7e5de65fe4bb4545d68cca6290bcf49..43219c01bb342db6fd75401aed0675d4736bcd38 100644 GIT binary patch delta 278 zcmX>zk9*5v?hUK*l|2|L844Iu8HyNk7&0017_u1@7(5vA8A=$6f#P6#vS6V2Y&DqtZ>_=PJZq87T5FB+x5vpaz7U!YBx~A_=re9VqR(U!K0Pan$zggxJrm1z Xwsxi?cGJ0PfP9CoK>m%ROeLHEqO4Fo delta 130 zcmV-|0Db?oqYKQQ3$Uthvq*4|B9p$B3X_19Sd*-63XIc#6FiWk^&63KF9)g2^9n|ivR!s diff --git a/src/SciCall.h b/src/SciCall.h index eff3c7574..269c835d0 100644 --- a/src/SciCall.h +++ b/src/SciCall.h @@ -90,6 +90,7 @@ DeclareSciCallV1(GotoLine, GOTOLINE, int, line); DeclareSciCallR0(GetCurrentPos, GETCURRENTPOS, int); DeclareSciCallR1(LineFromPosition, LINEFROMPOSITION, int, Sci_Position, position); DeclareSciCallR1(PositionFromLine, POSITIONFROMLINE, int, Sci_Position, line); +DeclareSciCallR1(GetLineEndPosition, GETLINEENDPOSITION, int, Sci_Position, line); DeclareSciCallR0(GetEndStyled, GETENDSTYLED, int); @@ -110,7 +111,8 @@ DeclareSciCallV2(SetYCaretPolicy, SETYCARETPOLICY, int, caretPolicy, int, caretS // DeclareSciCallR1(StyleGetFore, STYLEGETFORE, COLORREF, int, styleNumber); DeclareSciCallR1(StyleGetBack, STYLEGETBACK, COLORREF, int, styleNumber); - +DeclareSciCallV1(StartStyling, STARTSTYLING, Sci_Position, position); +DeclareSciCallV2(SetStyling, SETSTYLING, Sci_PositionCR, length, int, style); //============================================================================= // diff --git a/src/Styles.c b/src/Styles.c index 97770e931..80cbf44be 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -2847,6 +2847,7 @@ int cyStyleSelectDlg; extern int iDefaultCharSet; extern BOOL bHiliteCurrentLine; +extern BOOL bHyperlinkHotspot; extern BOOL bShowSelectionMargin; @@ -3170,11 +3171,16 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { fIsConsolasAvailable = IsFontAvailable(L"Consolas"); // Clear + SendMessage(hwnd, SCI_STYLECLEARALL, 0, 0); SendMessage(hwnd, SCI_CLEARDOCUMENTSTYLE, 0, 0); + // Idle Styling (very large text) + //SendMessage(hwnd, SCI_SETIDLESTYLING, SC_IDLESTYLING_ALL, 0); + // Default Values are always set SendMessage(hwnd, SCI_STYLERESETDEFAULT, 0, 0); SendMessage(hwnd, SCI_STYLESETCHARACTERSET, STYLE_DEFAULT, (LPARAM)DEFAULT_CHARSET); + iBaseFontSize = 10; Style_SetStyles(hwnd, lexDefault.Styles[STY_DEFAULT + iIdx].iStyle, lexDefault.Styles[STY_DEFAULT + iIdx].szValue); // default Style_StrGetSize(lexDefault.Styles[STY_DEFAULT + iIdx].szValue, &iBaseFontSize); // base size @@ -3189,7 +3195,6 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { if (pLexNew->iLexer != SCLEX_NULL || pLexNew == &lexANSI) Style_SetStyles(hwnd, pLexNew->Styles[STY_DEFAULT].iStyle, pLexNew->Styles[STY_DEFAULT].szValue); // lexer default - SendMessage(hwnd, SCI_STYLECLEARALL, 0, 0); Style_SetStyles(hwnd, lexDefault.Styles[STY_MARGIN + iIdx].iStyle, lexDefault.Styles[STY_MARGIN + iIdx].szValue); // linenumber @@ -3547,10 +3552,13 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { } } - Style_SetUrlHotSpot(hwnd, TRUE); + // set URL Hotspot style + Style_SetUrlHotSpot(hwnd, bHyperlinkHotspot); SendMessage(hwnd,SCI_COLOURISE,0,(LPARAM)-1); + EditUpdateUrlHotspots(hwnd, 0, SciCall_GetTextLength()); + // Save current lexer pLexCurrent = pLexNew; } @@ -3582,11 +3590,10 @@ void Style_SetUrlHotSpot(HWND hwnd, BOOL bHotSpot) // SendMessage(hwnd, SCI_SETHOTSPOTACTIVEUNDERLINE, TRUE, 0); //else // SendMessage(hwnd, SCI_SETHOTSPOTACTIVEUNDERLINE, FALSE, 0); - // Fore SendMessage(hwnd, SCI_SETHOTSPOTACTIVEUNDERLINE, TRUE, 0); - int rgb; - + int rgb = 0; + // Fore if (Style_StrGetColor(TRUE, lpszStyleHotSpot, &rgb)) { int inactiveFG = (int)((rgb * 75 + 50) / 100); SendMessage(hwnd, SCI_STYLESETFORE, iStyleHotSpot, (LPARAM)inactiveFG); @@ -5630,7 +5637,10 @@ void Style_SelectLexerDlg(HWND hwnd) int Style_GetHotspotID(HWND hwnd) { UNUSED(hwnd); - return (bUse2ndDefaultStyle ? (STY_URL_HOTSPOT + STY_CNT_LAST) : STY_URL_HOTSPOT); + if (bHyperlinkHotspot) { + return (bUse2ndDefaultStyle ? (STY_URL_HOTSPOT + STY_CNT_LAST) : STY_URL_HOTSPOT); + } + return (bUse2ndDefaultStyle ? (STY_DEFAULT + STY_CNT_LAST) : STY_DEFAULT); } // End of Styles.c diff --git a/src/resource.h b/src/resource.h index bcbc424b4..c3b9804fe 100644 --- a/src/resource.h +++ b/src/resource.h @@ -216,6 +216,7 @@ #define CMD_DEFAULTWINPOS 20038 #define CMD_OPENINIFILE 20039 #define CMD_CTRLENTER 20040 +#define CMD_OPEN_HYPERLINK 20041 #define IDM_FILE_NEW 40000 #define IDM_FILE_OPEN 40001 #define IDM_FILE_REVERT 40002 @@ -385,6 +386,7 @@ #define IDM_VIEW_AUTOCOMPLETEWORDS 40450 #define IDM_VIEW_ACCELWORDNAV 40451 #define IDM_VIEW_NOPRESERVECARET 40452 +#define IDM_VIEW_HYPERLINKHOTSPOTS 40453 #define IDM_HELP_ABOUT 40500 #define IDM_HELP_CMD 40501 #define IDM_TRAY_RESTORE 40600 @@ -471,7 +473,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 1 #define _APS_NEXT_RESOURCE_VALUE 600 -#define _APS_NEXT_COMMAND_VALUE 700 +#define _APS_NEXT_COMMAND_VALUE 701 #define _APS_NEXT_CONTROL_VALUE 801 #define _APS_NEXT_SYMED_VALUE 900 #endif From 10d55c17d7e5749160445f7e39ded417bc0f71cb Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 8 Dec 2017 12:43:38 +0100 Subject: [PATCH 5/6] +fix: consistent texts for "Hyperlink Hotspots" --- src/Notepad3.rc | Bin 184756 -> 184784 bytes src/Styles.c | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Notepad3.rc b/src/Notepad3.rc index 43219c01bb342db6fd75401aed0675d4736bcd38..d1721127a76bf9ffd25358b1bf9f6d6c93c39dc2 100644 GIT binary patch delta 47 zcmdn8nES$F?uHh|ElfElCa=m@nJ#jSNo4x86HF#xUXvn_7j}+GYCGRarez!e+#eE$ delta 76 zcmcbxn0w1&?uHh|ElfElghLsE75Ym^qT2;dG9BOm08`r(?EnA( diff --git a/src/Styles.c b/src/Styles.c index 80cbf44be..a1f98e308 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -71,7 +71,7 @@ EDITLEXER lexDefault = { SCLEX_NULL, 63000, L"Default Text", L"txt; text; wtx; /* 11 */ { SCI_SETEXTRAASCENT+SCI_SETEXTRADESCENT, 63111, L"Extra Line Spacing (Size)", L"size:2", L"" }, /* 12 */ { SCI_MARKERSETBACK+SCI_MARKERSETALPHA, 63124, L"Book Marks (Colors)", L"back:#00FF00; alpha:20", L"" }, /* 13 */ { SCI_MARKERSETBACK+SCI_MARKERSETALPHA, 63262, L"Mark Occurrences (Colors)", L"", L"" }, - /* 14 */ { SCI_SETHOTSPOTACTIVEFORE, 63264, L"URL Hotspot", L"italics; fore:#0000FF", L"" }, + /* 14 */ { SCI_SETHOTSPOTACTIVEFORE, 63264, L"Hyperlink Hotspots", L"italics; fore:#0000FF", L"" }, /* 15 */ { STYLE_DEFAULT, 63112, L"2nd Default Style", L"font:Courier New; size:10", L"" }, /* 16 */ { STYLE_LINENUMBER, 63113, L"2nd Margins and Line Numbers", L"font:Tahoma; size:-2; fore:#FF0000", L"" }, @@ -87,7 +87,7 @@ EDITLEXER lexDefault = { SCLEX_NULL, 63000, L"Default Text", L"txt; text; wtx; /* 26 */ { SCI_SETEXTRAASCENT + SCI_SETEXTRADESCENT, 63123, L"2nd Extra Line Spacing (Size)", L"", L"" }, /* 27 */ { SCI_MARKERSETBACK+SCI_MARKERSETALPHA, 63125, L"2nd Book Marks (Colors)", L"back:#00FF00; alpha:20", L"" }, /* 28 */ { SCI_MARKERSETBACK+SCI_MARKERSETALPHA, 63263, L"2nd Mark Occurrences (Colors)", L"fore:#0x00FF00; alpha:100; alpha2:100", L"" }, - /* 29 */ { SCI_SETHOTSPOTACTIVEFORE, 63265, L"2nd URL Hotspot", L"bold; fore:#FF0000", L"" }, + /* 29 */ { SCI_SETHOTSPOTACTIVEFORE, 63265, L"2nd Hyperlink Hotspots", L"bold; fore:#FF0000", L"" }, { -1, 00000, L"", L"", L"" } } }; From 79efacf128f0debf1dc50282044ce99905c0ac4e Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 8 Dec 2017 14:38:49 +0100 Subject: [PATCH 6/6] + feature: open Hyperlink in NP3 (if applicable: "file://...") + fix: add some more places, where Hotspot style redrawing does not slow down responsiveness --- src/Edit.c | 2 +- src/Notepad3.c | 67 +++++++++++++++++++++++++++++++++++++++++--------- src/Notepad3.h | 2 +- 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index f96ae1842..4f9d51f6e 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -5882,7 +5882,7 @@ void EditMatchBrace(HWND hwnd) int iLine = SciCall_LineFromPosition(iEndStyled); iEndStyled = SciCall_PositionFromLine(iLine); SendMessage(hwnd, SCI_COLOURISE, iEndStyled, -1); - //EditUpdateUrlHotspots(hwnd, iEndStyled, SciCall_GetLineEndPosition(iLine)); + //~EditUpdateUrlHotspots(hwnd, iEndStyled, SciCall_GetLineEndPosition(iLine)); } int iPos = SciCall_GetCurrentPos(); diff --git a/src/Notepad3.c b/src/Notepad3.c index 4bffa5dd8..bc5089a06 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1031,6 +1031,7 @@ HWND InitInstance(HINSTANCE hInstance,LPSTR pszCmdLine,int nCmdShow) UpdateToolbar(); UpdateStatusbar(); UpdateLineNumberWidth(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); // print file immediately and quit if (flagPrintFileAndLeave) @@ -1174,6 +1175,7 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) //UpdateToolbar(); //UpdateStatusbar(); //UpdateLineNumberWidth(); + //EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); //if (bPendingChangeNotify) // PostMessage(hwnd,WM_CHANGENOTIFY,0,0); break; @@ -1750,7 +1752,7 @@ void MsgThemeChanged(HWND hwnd,WPARAM wParam,LPARAM lParam) UpdateToolbar(); UpdateStatusbar(); UpdateLineNumberWidth(); - + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); UNUSED(lParam); UNUSED(wParam); @@ -1831,6 +1833,7 @@ void MsgSize(HWND hwnd,WPARAM wParam,LPARAM lParam) UpdateStatusbar(); UpdateLineNumberWidth(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); UNUSED(hwnd); UNUSED(lParam); @@ -2027,6 +2030,7 @@ LRESULT MsgCopyData(HWND hwnd, WPARAM wParam, LPARAM lParam) UpdateToolbar(); UpdateStatusbar(); UpdateLineNumberWidth(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); } @@ -2529,6 +2533,8 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) //SendMessage(hwndEdit,SCI_SETREADONLY,bReadOnly,0); //UpdateToolbar(); //UpdateStatusbar(); + //EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); + if (StringCchLenW(szCurFile,COUNTOF(szCurFile))) { DWORD dwFileAttributes = GetFileAttributes(szCurFile); @@ -2883,6 +2889,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) UpdateToolbar(); UpdateStatusbar(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); } } break; @@ -2926,6 +2933,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) EditFixPositions(hwndEdit); UpdateToolbar(); UpdateStatusbar(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); } break; @@ -3048,6 +3056,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) LocalFree(pClip); UpdateToolbar(); UpdateStatusbar(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); } break; @@ -4105,6 +4114,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) else SendMessage(hwndEdit,SCI_SETEDGEMODE,EDGE_NONE,0); UpdateStatusbar(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); break; @@ -4116,6 +4126,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) iLongLinesLimit = max(min(iLongLinesLimit,4096),0); SendMessage(hwndEdit,SCI_SETEDGECOLUMN,iLongLinesLimit,0); UpdateStatusbar(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); iLongLinesLimitG = iLongLinesLimit; } break; @@ -4768,6 +4779,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) Style_SetDefaultLexer(hwndEdit); UpdateStatusbar(); UpdateLineNumberWidth(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); break; @@ -4775,6 +4787,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) Style_SetHTMLLexer(hwndEdit); UpdateStatusbar(); UpdateLineNumberWidth(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); break; @@ -4782,6 +4795,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) Style_SetXMLLexer(hwndEdit); UpdateStatusbar(); UpdateLineNumberWidth(); + EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength()); break; @@ -5153,7 +5167,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) case CMD_OPEN_HYPERLINK: { - OpenHotSpotURL((int)SendMessage(hwndEdit, SCI_GETCURRENTPOS, 0, 0)); + OpenHotSpotURL((int)SendMessage(hwndEdit, SCI_GETCURRENTPOS, 0, 0), FALSE); } break; @@ -5368,7 +5382,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) // OpenHotSpotURL() - Handles WM_NOTIFY // // -void OpenHotSpotURL(int position) +void OpenHotSpotURL(int position, BOOL bForceBrowser) { int iStyle = (int)SendMessage(hwndEdit, SCI_GETSTYLEAT, position, 0); @@ -5405,13 +5419,37 @@ void OpenHotSpotURL(int position) SendMessage(hwndEdit, SCI_GETTEXTRANGE, 0, (LPARAM)&tr); StrTrimA(chURL, " \t\n\r"); - - if (StringCchLenA(chURL, COUNTOF(chURL))) - { - WCHAR wchURL[HUGE_BUFFER] = { L'\0' }; - WCHAR wchDirectory[MAX_PATH] = { L'\0' }; - MultiByteToWideCharStrg(Encoding_SciGetCodePage(hwndEdit), chURL, wchURL); + + if (!StringCchLenA(chURL, COUNTOF(chURL))) + return; + WCHAR wchURL[HUGE_BUFFER] = { L'\0' }; + MultiByteToWideCharStrg(Encoding_SciGetCodePage(hwndEdit), chURL, wchURL); + + const WCHAR* chkPreFix = L"file://"; + const int len = lstrlen(chkPreFix); + + if (!bForceBrowser && (StrStrIW(wchURL, chkPreFix) == wchURL)) + { + WCHAR* szFileName = &(wchURL[len]); + StrTrimW(szFileName, L"/"); + + PathCanonicalizeEx(szFileName, COUNTOF(wchURL) - len); + + if (PathIsDirectory(szFileName)) + { + WCHAR tchFile[MAX_PATH + 1] = { L'\0' }; + + if (OpenFileDlg(hwndMain, tchFile, COUNTOF(tchFile), szFileName)) + FileLoad(FALSE, FALSE, FALSE, FALSE, tchFile); + } + else + FileLoad(FALSE, FALSE, FALSE, FALSE, szFileName); + + } + else { // open in web browser + + WCHAR wchDirectory[MAX_PATH] = { L'\0' }; if (StringCchLenW(szCurFile, COUNTOF(szCurFile))) { StringCchCopy(wchDirectory, COUNTOF(wchDirectory), szCurFile); PathRemoveFileSpec(wchDirectory); @@ -5428,7 +5466,9 @@ void OpenHotSpotURL(int position) sei.lpDirectory = wchDirectory; sei.nShow = SW_SHOWNORMAL; ShellExecuteEx(&sei); + } + } } @@ -5454,7 +5494,12 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) case SCN_HOTSPOTCLICK: { if (scn->modifiers & SCMOD_CTRL) { - OpenHotSpotURL((int)scn->position); + // open in browser + OpenHotSpotURL((int)scn->position, TRUE); + } + if (scn->modifiers & SCMOD_ALT) { + // open in application, if applicable (file://) + OpenHotSpotURL((int)scn->position, FALSE); } } break; @@ -5476,7 +5521,7 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) UpdateToolbar(); UpdateStatusbar(); } - break; // fall-through -> too slow + break; // fall-through -> bad responsive UI !!! case SCN_STYLENEEDED: // this event needs SCI_SETLEXER(SCLEX_CONTAINER) { diff --git a/src/Notepad3.h b/src/Notepad3.h index 30d6bb6e6..9c363e66d 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -149,7 +149,7 @@ int BeginSelUndoAction(); void EndSelUndoAction(int); void RestoreSelectionAction(int,DoAction); int UndoRedoSelectionMap(int,UndoRedoSelection_t*); -void OpenHotSpotURL(int); +void OpenHotSpotURL(int, BOOL); BOOL FileIO(BOOL,LPCWSTR,BOOL,int*,int*,BOOL*,BOOL*,BOOL*,BOOL*,BOOL);