Merge pull request #218 from RaiKoHoff/Hyperlink_Enhancement

Hyperlink Hotspot fixes
This commit is contained in:
Derick Payne 2017-12-12 12:42:02 +02:00 committed by GitHub
commit 20547eabef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 74 deletions

View File

@ -5793,10 +5793,8 @@ void EditCompleteWord(HWND hwnd, BOOL autoInsert) {
// EditUpdateUrlHotspots()
// Find and mark all URL hot-spots
//
void EditUpdateUrlHotspots(HWND hwnd, int startPos, int endPos)
void EditUpdateUrlHotspots(HWND hwnd, int startPos, int endPos, BOOL bActiveHotspot)
{
if (!bHyperlinkHotspot) return;
const char* pszUrlRegEx = "\\b(?:(?:https?|ftp|file)://|www\\.|ftp\\.)"
"(?:\\([-A-Z0-9+&@#/%=~_|$?!:,.]*\\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*"
"(?:\\([-A-Z0-9+&@#/%=~_|$?!:,.]*\\)|[A-Z0-9+&@#/%=~_|$])";
@ -5817,8 +5815,7 @@ void EditUpdateUrlHotspots(HWND hwnd, int startPos, int endPos)
int start = startPos;
int end = endPos;
while (TRUE)
{
do {
int iPos = EditFindInTarget(hwnd, pszUrlRegEx, iRegExLen, SCFIND_NP3_REGEX, &start, &end, FALSE);
if (iPos < 0)
@ -5826,14 +5823,20 @@ void EditUpdateUrlHotspots(HWND hwnd, int startPos, int endPos)
// mark this match
SciCall_StartStyling(iPos);
SciCall_SetStyling((end - start), Style_GetHotspotID(hwnd));
SciCall_SetStyling((end - start), Style_GetHotspotID());
// next occurrence
start = end;
end = endPos;
if (start >= end)
break;
}
while (start < end);
SciCall_StartStyling(endPos);
if (bActiveHotspot)
UpdateEditWndUI();
else
SendMessage(hwnd, SCI_COLOURISE, 0, (LPARAM)-1);
}
@ -5885,7 +5888,6 @@ 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));
}
int iPos = SciCall_GetCurrentPos();

View File

@ -125,7 +125,7 @@ void EditPrintInit();
void EditMatchBrace(HWND);
void EditClearAllMarks(HWND);
void EditMarkAll(HWND,char*,int,BOOL,BOOL);
void EditUpdateUrlHotspots(HWND, int, int);
void EditUpdateUrlHotspots(HWND, int, int, BOOL);
void EditSetAccelWordNav(HWND,BOOL);
void EditCompleteWord(HWND,BOOL);
void EditGetBookmarkList(HWND,LPWSTR,int);

View File

@ -1031,7 +1031,7 @@ HWND InitInstance(HINSTANCE hInstance,LPSTR pszCmdLine,int nCmdShow)
UpdateToolbar();
UpdateStatusbar();
UpdateLineNumberWidth();
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength());
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength(), bHyperlinkHotspot);
// print file immediately and quit
if (flagPrintFileAndLeave)
@ -1175,7 +1175,6 @@ 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;
@ -1752,7 +1751,6 @@ void MsgThemeChanged(HWND hwnd,WPARAM wParam,LPARAM lParam)
UpdateToolbar();
UpdateStatusbar();
UpdateLineNumberWidth();
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength());
UNUSED(lParam);
UNUSED(wParam);
@ -1833,7 +1831,6 @@ void MsgSize(HWND hwnd,WPARAM wParam,LPARAM lParam)
UpdateStatusbar();
UpdateLineNumberWidth();
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength());
UNUSED(hwnd);
UNUSED(lParam);
@ -1925,7 +1922,6 @@ static DWORD DropFilesProc(CLIPFORMAT cf, HGLOBAL hData, HWND hWnd, DWORD dwKeyS
}
//=============================================================================
//
// MsgCopyData() - Handles WM_COPYDATA
@ -2030,7 +2026,6 @@ LRESULT MsgCopyData(HWND hwnd, WPARAM wParam, LPARAM lParam)
UpdateToolbar();
UpdateStatusbar();
UpdateLineNumberWidth();
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength());
}
@ -2533,7 +2528,6 @@ 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)))
{
@ -2889,7 +2883,6 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam)
UpdateToolbar();
UpdateStatusbar();
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength());
}
}
break;
@ -2933,7 +2926,6 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam)
EditFixPositions(hwndEdit);
UpdateToolbar();
UpdateStatusbar();
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength());
}
break;
@ -3056,7 +3048,6 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam)
LocalFree(pClip);
UpdateToolbar();
UpdateStatusbar();
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength());
}
break;
@ -4109,8 +4100,8 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam)
}
else
SendMessage(hwndEdit,SCI_SETEDGEMODE,EDGE_NONE,0);
UpdateStatusbar();
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength());
break;
@ -4122,7 +4113,6 @@ 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;
@ -4278,14 +4268,8 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam)
case IDM_VIEW_MATCHBRACES:
bMatchBraces = (bMatchBraces) ? FALSE : TRUE;
if (bMatchBraces) {
struct SCNotification scn;
scn.nmhdr.hwndFrom = hwndEdit;
scn.nmhdr.idFrom = IDC_EDIT;
scn.nmhdr.code = SCN_UPDATEUI;
scn.updated = SC_UPDATE_CONTENT;
SendMessage(hwnd,WM_NOTIFY,IDC_EDIT,(LPARAM)&scn);
}
if (bMatchBraces)
UpdateEditWndUI();
else
SendMessage(hwndEdit,SCI_BRACEHIGHLIGHT,(WPARAM)-1,(LPARAM)-1);
break;
@ -4304,9 +4288,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam)
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);
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength(), bHyperlinkHotspot);
break;
case IDM_VIEW_ZOOMIN:
@ -5372,7 +5354,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam)
//=============================================================================
//
// OpenHotSpotURL() - Handles WM_NOTIFY
// OpenHotSpotURL()
//
//
void OpenHotSpotURL(int position, BOOL bForceBrowser)
@ -5497,6 +5479,13 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam)
}
break;
case SCN_STYLENEEDED: // this event needs SCI_SETLEXER(SCLEX_CONTAINER)
{
int lineNumber = SciCall_LineFromPosition(SciCall_GetEndStyled());
EditUpdateUrlHotspots(hwndEdit, SciCall_PositionFromLine(lineNumber), (int)scn->position, bHyperlinkHotspot);
}
break;
case SCN_UPDATEUI:
if (scn->updated & ~(SC_UPDATE_V_SCROLL | SC_UPDATE_H_SCROLL))
{
@ -5506,7 +5495,6 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam)
if (iMarkOccurrences != 0) {
EditMarkAll(hwndEdit, NULL, 0, bMarkOccurrencesMatchCase, bMarkOccurrencesMatchWords);
}
// Brace Match
if (bMatchBraces) {
EditMatchBrace(hwndEdit);
@ -5514,17 +5502,8 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam)
UpdateToolbar();
UpdateStatusbar();
}
break; // fall-through -> bad responsive UI !!!
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
if (bAutoIndent && (scn->ch == '\x0D' || scn->ch == '\x0A'))
@ -5675,11 +5654,11 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam)
}
}
else if (scn->modificationType & SC_MOD_CHANGESTYLE) {
EditUpdateUrlHotspots(hwndEdit, (int)scn->position, (int)(scn->position + scn->length));
EditUpdateUrlHotspots(hwndEdit, (int)scn->position, (int)(scn->position + scn->length), bHyperlinkHotspot);
}
if (scn->linesAdded != 0) {
UpdateLineNumberWidth();
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength());
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength(), bHyperlinkHotspot);
}
bModified = TRUE;
break;
@ -5691,7 +5670,7 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam)
case SCN_SAVEPOINTREACHED:
bModified = FALSE;
UpdateToolbar();
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength());
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength(), bHyperlinkHotspot);
break;
case SCN_MARGINCLICK:
@ -5707,7 +5686,7 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam)
case SCN_SAVEPOINTLEFT:
bModified = TRUE;
UpdateToolbar();
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength());
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength(), bHyperlinkHotspot);
break;
}
break;
@ -7005,11 +6984,28 @@ int CreateIniFileEx(LPCWSTR lpszIniFile) {
}
//=============================================================================
//
// UpdateEditWndUI()
//
void UpdateEditWndUI()
{
struct SCNotification scn;
scn.nmhdr.hwndFrom = hwndEdit;
scn.nmhdr.idFrom = IDC_EDIT;
scn.nmhdr.code = SCN_UPDATEUI;
scn.updated = SC_UPDATE_CONTENT;
//SendMessage(hwndMain, WM_NOTIFY, IDC_EDIT, (LPARAM)&scn);
PostMessage(hwndMain, WM_NOTIFY, IDC_EDIT, (LPARAM)&scn);
}
//=============================================================================
//
// UpdateToolbar()
//
//
#define EnableTool(id,b) SendMessage(hwndToolbar,TB_ENABLEBUTTON,id, \
MAKELONG(((b) ? 1 : 0), 0))
@ -7645,12 +7641,13 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp
UpdateToolbar();
UpdateStatusbar();
UpdateLineNumberWidth();
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength());
// consistent settings file handling (if loaded in editor)
bEnableSaveSettings = (StringCchCompareINW(szCurFile, COUNTOF(szCurFile), szIniFile, COUNTOF(szIniFile)) == 0) ? FALSE : TRUE;
UpdateSettingsCmds();
EditUpdateUrlHotspots(hwndEdit, 0, SciCall_GetTextLength(), bHyperlinkHotspot);
// Show warning: Unicode file loaded as ANSI
if (bUnicodeErr)
MsgBox(MBWARN,IDS_ERR_UNICODE);
@ -7813,7 +7810,6 @@ 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);

View File

@ -138,6 +138,7 @@ int CreateIniFile();
int CreateIniFileEx(LPCWSTR);
void UpdateEditWndUI();
void UpdateStatusbar();
void UpdateToolbar();
void UpdateLineNumberWidth();

View File

@ -3557,11 +3557,9 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) {
// apply lexer styles
SendMessage(hwnd, SCI_COLOURISE, 0, (LPARAM)-1);
// override hyperlink hotspot style
if (bHyperlinkHotspot) {
Style_SetUrlHotSpot(hwnd, bHyperlinkHotspot);
EditUpdateUrlHotspots(hwnd, 0, SciCall_GetTextLength());
}
// override lexer style by hyperlink hotspot style
Style_SetUrlHotSpot(hwnd, bHyperlinkHotspot);
EditUpdateUrlHotspots(hwnd, 0, SciCall_GetTextLength(), bHyperlinkHotspot);
// Save current lexer
pLexCurrent = pLexNew;
@ -3569,6 +3567,19 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) {
}
//=============================================================================
//
// Style_GetHotspotID()
//
int Style_GetHotspotID()
{
if (bHyperlinkHotspot) {
return (bUse2ndDefaultStyle ? (STYLE_LASTPREDEFINED + STY_URL_HOTSPOT + STY_CNT_LAST) : (STYLE_LASTPREDEFINED + STY_URL_HOTSPOT));
}
return (bUse2ndDefaultStyle ? (STY_DEFAULT + STY_CNT_LAST) : STY_DEFAULT);
}
//=============================================================================
//
// Style_SetUrlHotSpot()
@ -3579,11 +3590,11 @@ void Style_SetUrlHotSpot(HWND hwnd, BOOL bHotSpot)
int iIdx = (bUse2ndDefaultStyle) ? STY_CNT_LAST : 0;
// Hot Spot settings
const int iStyleHotSpot = (STY_URL_HOTSPOT + iIdx);
const int iStyleHotSpot = Style_GetHotspotID();
if (bHotSpot)
{
const WCHAR* lpszStyleHotSpot = lexDefault.Styles[iStyleHotSpot].szValue;
const WCHAR* lpszStyleHotSpot = lexDefault.Styles[STY_URL_HOTSPOT + iIdx].szValue;
SendMessage(hwnd, SCI_STYLESETHOTSPOT, iStyleHotSpot, (LPARAM)TRUE);
SendMessage(hwnd, SCI_SETHOTSPOTSINGLELINE, TRUE, 0);
@ -5634,18 +5645,4 @@ void Style_SelectLexerDlg(HWND hwnd)
Style_SetLexer(hwnd,pLexCurrent);
}
//=============================================================================
//
// Style_GetHotspotID()
//
int Style_GetHotspotID(HWND hwnd)
{
UNUSED(hwnd);
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

View File

@ -102,7 +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);
int Style_GetHotspotID();
#endif //_NP3_STYLES_H_