Skip to content

Commit f97e7ef

Browse files
committed
Enclose Selection - add links with quotation marks #280
1 parent 4ca89ea commit f97e7ef

File tree

4 files changed

+125
-154
lines changed

4 files changed

+125
-154
lines changed

src/Edit.c

Lines changed: 97 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -6597,14 +6597,12 @@ INT_PTR CALLBACK EditEncloseSelectionDlgProc(HWND hwnd, UINT umsg, WPARAM wParam
65976597
const WCHAR* _special_symbs = L"`~!@#%^*-_+=|\\/:;\"',.?";
65986598

65996599
// [2e]: Enclose Selection - add links with quotation marks #280
6600-
static int id_hover = 0;
6601-
static int id_capture = 0;
6602-
static HFONT hFontNormal = NULL;
6603-
static HFONT hFontHover = NULL;
6604-
static HCURSOR hCursorNormal = NULL;
6605-
static HCURSOR hCursorHover = NULL;
6606-
const DWORD iMinLinkID = 200;
6607-
const DWORD iMaxLinkID = iMinLinkID + iUnicodeQuotesCount;
6600+
static HFONT hFontLink = NULL;
6601+
const DWORD iMinLinkID_SingleQuote = 200;
6602+
const DWORD iMaxLinkID_SingleQuote = iMinLinkID_SingleQuote + 9;
6603+
const DWORD iMinLinkID_DoubleQuote = iMaxLinkID_SingleQuote + 1;
6604+
const DWORD iMaxLinkID_DoubleQuote = iMinLinkID_DoubleQuote + 3;
6605+
static DWORD dwFocusID = 0;
66086606
// [/2e]
66096607

66106608
static PENCLOSESELDATA pdata;
@@ -6617,21 +6615,33 @@ INT_PTR CALLBACK EditEncloseSelectionDlgProc(HWND hwnd, UINT umsg, WPARAM wParam
66176615
// [2e]: Enclose Selection - add links with quotation marks #280
66186616
LOGFONT lf = { 0 };
66196617

6620-
if (hFontNormal == NULL)
6621-
hFontNormal = GetStockObject(DEFAULT_GUI_FONT);
6622-
GetObject(hFontNormal, sizeof(LOGFONT), &lf);
6623-
lf.lfUnderline = TRUE;
6624-
lf.lfHeight *= 1.25;
6625-
hFontHover = CreateFontIndirect(&lf);
6618+
if (hFontLink == NULL)
6619+
{
6620+
HDC hdc = GetDC(hwnd);
6621+
GetObject(hFontLink, sizeof(LOGFONT), &lf);
6622+
lstrcpy(lf.lfFaceName, L"Georgia");
6623+
lf.lfUnderline = TRUE;
6624+
lf.lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
6625+
ReleaseDC(hwnd, hdc);
6626+
hFontLink = CreateFontIndirect(&lf);
6627+
}
66266628

6627-
hCursorNormal = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
6628-
if (!(hCursorHover = LoadCursor(NULL, MAKEINTRESOURCE(IDC_HAND))))
6629-
hCursorHover = LoadCursor(g_hInstance, MAKEINTRESOURCE(IDC_ARROW));
6629+
for (DWORD dwId = iMinLinkID_SingleQuote; dwId <= iMaxLinkID_SingleQuote; ++dwId)
6630+
{
6631+
WCHAR linkText[] = L"<a>X</a>";
6632+
linkText[3] = lpwstrUnicodeQuotes[dwId - iMinLinkID_SingleQuote];
6633+
SetDlgItemTextW(hwnd, dwId, linkText);
6634+
SendDlgItemMessage(hwnd, dwId, WM_SETFONT, (WPARAM)hFontLink, 0);
6635+
}
66306636

6631-
for (DWORD dwId = iMinLinkID; dwId <= iMaxLinkID; ++dwId)
6637+
for (DWORD dwId = iMinLinkID_DoubleQuote; dwId <= iMaxLinkID_DoubleQuote; ++dwId)
66326638
{
6633-
WCHAR linkText[2] = { lpwstrUnicodeQuotes[dwId - iMinLinkID], 0 };
6639+
const int quoteIndex = (iMaxLinkID_SingleQuote - iMinLinkID_SingleQuote) + 1 + (dwId - iMinLinkID_DoubleQuote) * 2;
6640+
WCHAR linkText[] = L"<a>XX</a>";
6641+
linkText[3] = lpwstrUnicodeQuotes[quoteIndex];
6642+
linkText[4] = lpwstrUnicodeQuotes[quoteIndex + 1];
66346643
SetDlgItemTextW(hwnd, dwId, linkText);
6644+
SendDlgItemMessage(hwnd, dwId, WM_SETFONT, (WPARAM)hFontLink, 0);
66356645
}
66366646
// [/2e]
66376647

@@ -6645,122 +6655,6 @@ INT_PTR CALLBACK EditEncloseSelectionDlgProc(HWND hwnd, UINT umsg, WPARAM wParam
66456655
}
66466656
return TRUE;
66476657

6648-
// [2e]: Enclose Selection - add links with quotation marks #280
6649-
case WM_DESTROY:
6650-
DeleteObject(hFontHover);
6651-
return FALSE;
6652-
6653-
case WM_NCACTIVATE:
6654-
if (!(BOOL)wParam)
6655-
{
6656-
if (id_hover != 0)
6657-
{
6658-
int _id_hover = id_hover;
6659-
id_hover = 0;
6660-
id_capture = 0;
6661-
}
6662-
}
6663-
return FALSE;
6664-
6665-
case WM_CTLCOLORSTATIC: {
6666-
DWORD dwId = GetWindowLong((HWND)lParam, GWL_ID);
6667-
HDC hdc = (HDC)wParam;
6668-
if (dwId >= iMinLinkID && dwId <= iMaxLinkID)
6669-
{
6670-
SetBkMode(hdc, TRANSPARENT);
6671-
if (GetSysColorBrush(COLOR_HOTLIGHT))
6672-
{
6673-
SetTextColor(hdc, GetSysColor(COLOR_HOTLIGHT));
6674-
}
6675-
else
6676-
{
6677-
SetTextColor(hdc, RGB(0, 0, 255));
6678-
}
6679-
SelectObject(hdc, hFontHover);
6680-
return (LONG_PTR)GetSysColorBrush(COLOR_BTNFACE);
6681-
}
6682-
}
6683-
break;
6684-
6685-
case WM_MOUSEMOVE: {
6686-
POINT pt = { LOWORD(lParam), HIWORD(lParam) };
6687-
HWND hwndHover = ChildWindowFromPoint(hwnd, pt);
6688-
DWORD dwId = GetWindowLong(hwndHover, GWL_ID);
6689-
if (GetActiveWindow() == hwnd)
6690-
{
6691-
if (dwId >= iMinLinkID && dwId <= iMaxLinkID)
6692-
{
6693-
if (id_capture == dwId || id_capture == 0)
6694-
{
6695-
if (id_hover != id_capture || id_hover == 0)
6696-
{
6697-
id_hover = dwId;
6698-
}
6699-
}
6700-
else if (id_hover != 0)
6701-
{
6702-
int _id_hover = id_hover;
6703-
id_hover = 0;
6704-
}
6705-
}
6706-
else if (id_hover != 0)
6707-
{
6708-
int _id_hover = id_hover;
6709-
id_hover = 0;
6710-
}
6711-
SetCursor(id_hover != 0 ? hCursorHover : hCursorNormal);
6712-
}
6713-
}
6714-
break;
6715-
6716-
case WM_LBUTTONDOWN: {
6717-
POINT pt = { LOWORD(lParam), HIWORD(lParam) };
6718-
HWND hwndHover = ChildWindowFromPoint(hwnd, pt);
6719-
DWORD dwId = GetWindowLong(hwndHover, GWL_ID);
6720-
if (dwId >= iMinLinkID && dwId <= iMaxLinkID)
6721-
{
6722-
GetCapture();
6723-
id_hover = dwId;
6724-
id_capture = dwId;
6725-
}
6726-
SetCursor(id_hover != 0 ? hCursorHover : hCursorNormal);
6727-
}
6728-
break;
6729-
6730-
case WM_LBUTTONUP: {
6731-
POINT pt = { LOWORD(lParam), HIWORD(lParam) };
6732-
HWND hwndHover = ChildWindowFromPoint(hwnd, pt);
6733-
DWORD dwId = GetWindowLong(hwndHover, GWL_ID);
6734-
if (id_capture != 0)
6735-
{
6736-
ReleaseCapture();
6737-
if (id_hover == id_capture)
6738-
{
6739-
int id_focus = GetWindowLong(GetFocus(), GWL_ID);
6740-
if (id_focus == 100 || id_focus == 101)
6741-
{
6742-
WCHAR wch[8];
6743-
GetDlgItemText(hwnd, id_capture, wch, COUNTOF(wch));
6744-
SendDlgItemMessage(hwnd, id_focus, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)wch);
6745-
}
6746-
}
6747-
id_capture = 0;
6748-
}
6749-
SetCursor(id_hover != 0 ? hCursorHover : hCursorNormal);
6750-
}
6751-
break;
6752-
6753-
case WM_CANCELMODE:
6754-
if (id_capture != 0)
6755-
{
6756-
ReleaseCapture();
6757-
id_hover = 0;
6758-
id_capture = 0;
6759-
SetCursor(hCursorNormal);
6760-
}
6761-
break;
6762-
// [/2e]
6763-
67646658
case WM_COMMAND:
67656659
switch (LOWORD(wParam))
67666660
{
@@ -6821,7 +6715,75 @@ INT_PTR CALLBACK EditEncloseSelectionDlgProc(HWND hwnd, UINT umsg, WPARAM wParam
68216715
EndDialog(hwnd, IDCANCEL);
68226716
break;
68236717
}
6718+
6719+
// [2e]: Enclose Selection - add links with quotation marks #280
6720+
if (((LOWORD(wParam) == 100) || (LOWORD(wParam) == 101))
6721+
&& ((HIWORD(wParam) == EN_SETFOCUS) || (HIWORD(wParam) == EN_KILLFOCUS)))
6722+
{
6723+
dwFocusID = LOWORD(wParam);
6724+
}
6725+
// [/2e]
6726+
68246727
return TRUE;
6728+
6729+
// [2e]: Enclose Selection - add links with quotation marks #280
6730+
case WM_NOTIFY: {
6731+
LPNMHDR pnmhdr = (LPNMHDR)lParam;
6732+
switch (pnmhdr->code)
6733+
{
6734+
case NM_CLICK:
6735+
case NM_RETURN: {
6736+
const DWORD dwControlId = pnmhdr->idFrom;
6737+
if ((dwControlId >= iMinLinkID_SingleQuote) && (dwControlId <= iMaxLinkID_SingleQuote))
6738+
{
6739+
WCHAR wch[2] = { lpwstrUnicodeQuotes[dwControlId - iMinLinkID_SingleQuote], 0 };
6740+
SendDlgItemMessage(hwnd, dwFocusID, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)wch);
6741+
SetFocus(GetDlgItem(hwnd, dwFocusID));
6742+
return TRUE;
6743+
}
6744+
else if (((dwControlId >= iMinLinkID_DoubleQuote) && (dwControlId <= iMaxLinkID_DoubleQuote))
6745+
|| (dwControlId == IDC_SYSLINK1) || (dwControlId == IDC_SYSLINK2)
6746+
|| (dwControlId == IDC_SYSLINK3) || (dwControlId == IDC_SYSLINK4))
6747+
{
6748+
WCHAR buf1[2] = { 0 };
6749+
WCHAR buf2[2] = { 0 };
6750+
switch (dwControlId)
6751+
{
6752+
case IDC_SYSLINK1:
6753+
buf1[0] = lpwstrUnicodeQuotesUS[0];
6754+
buf2[0] = lpwstrUnicodeQuotesUS[1];
6755+
break;
6756+
case IDC_SYSLINK2:
6757+
buf1[0] = lpwstrUnicodeQuotesUS[2];
6758+
buf2[0] = lpwstrUnicodeQuotesUS[3];
6759+
break;
6760+
case IDC_SYSLINK3:
6761+
buf1[0] = lpwstrUnicodeQuotesRU[0];
6762+
buf2[0] = lpwstrUnicodeQuotesRU[1];
6763+
break;
6764+
case IDC_SYSLINK4:
6765+
buf1[0] = lpwstrUnicodeQuotesRU[2];
6766+
buf2[0] = lpwstrUnicodeQuotesRU[3];
6767+
break;
6768+
default:
6769+
{
6770+
const int quoteIndex = (iMaxLinkID_SingleQuote - iMinLinkID_SingleQuote) + 1 + (dwControlId - iMinLinkID_DoubleQuote) * 2;
6771+
buf1[0] = lpwstrUnicodeQuotes[quoteIndex];
6772+
buf2[0] = lpwstrUnicodeQuotes[quoteIndex + 1];
6773+
break;
6774+
}
6775+
}
6776+
SetWindowText(GetDlgItem(hwnd, 100), (LPCWSTR)&buf1);
6777+
SetWindowText(GetDlgItem(hwnd, 101), (LPCWSTR)&buf2);
6778+
SetFocus(GetDlgItem(hwnd, dwFocusID));
6779+
return TRUE;
6780+
}
6781+
}
6782+
break;
6783+
}
6784+
}
6785+
break;
6786+
// [/2e]
68256787
}
68266788
return FALSE;
68276789
}

src/Extension/UnicodeQuotes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#pragma once
22

33
const int iUnicodeQuotesCount = 16;
4-
const LPCWSTR lpwstrUnicodeQuotes = L"‘’‚“”„‹›《》「」『』«»";
4+
const LPCWSTR lpwstrUnicodeQuotes = L"‘’‚“”„‹›«»「」『』《》";
5+
const LPCWSTR lpwstrUnicodeQuotesUS = L"“”‘’";
6+
const LPCWSTR lpwstrUnicodeQuotesRU = L"«»„“";

src/Notepad2.rc

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ BEGIN
999999
PUSHBUTTON "Cancel",IDCANCEL,125,24,50,14
10001000
END
10011001

1002-
IDD_ENCLOSESELECTION DIALOGEX 0, 0, 182, 90
1002+
IDD_ENCLOSESELECTION DIALOGEX 0, 0, 182, 100
10031003
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
10041004
CAPTION "Enclose Selection"
10051005
FONT 8, "MS Shell Dlg", 0, 0, 0x0
@@ -1010,22 +1010,23 @@ BEGIN
10101010
EDITTEXT 101,7,48,98,14,ES_AUTOHSCROLL
10111011
DEFPUSHBUTTON "OK",IDOK,125,7,50,14
10121012
PUSHBUTTON "Cancel",IDCANCEL,125,24,50,14
1013-
LTEXT "<",200,12,72,8,16
1014-
LTEXT ">",201,22,72,8,16
1015-
LTEXT "<",202,32,72,8,16
1016-
LTEXT ">",203,42,72,8,16
1017-
LTEXT "<",204,52,72,8,16
1018-
LTEXT ">",205,62,72,8,16
1019-
LTEXT "<",206,72,72,8,16
1020-
LTEXT ">",207,82,72,8,16
1021-
LTEXT "<",208,92,72,8,16
1022-
LTEXT ">",209,102,72,8,16
1023-
LTEXT "<",210,112,72,8,16
1024-
LTEXT ">",211,122,72,8,16
1025-
LTEXT "<",212,132,72,8,16
1026-
LTEXT ">",213,142,72,8,16
1027-
LTEXT "<",214,152,72,8,16
1028-
LTEXT ">",215,162,72,8,16
1013+
CONTROL "<",200,"SysLink",0x0,9,72,8,10
1014+
CONTROL ">",201,"SysLink",0x0,21,72,8,10
1015+
CONTROL "<",202,"SysLink",0x0,33,72,8,10
1016+
CONTROL ">",203,"SysLink",0x0,45,72,8,10
1017+
CONTROL "<",204,"SysLink",0x0,57,72,8,10
1018+
CONTROL ">",205,"SysLink",0x0,69,72,8,10
1019+
CONTROL "<",206,"SysLink",0x0,81,72,8,10
1020+
CONTROL ">",207,"SysLink",0x0,93,72,8,10
1021+
CONTROL "<",208,"SysLink",0x0,105,72,8,10
1022+
CONTROL ">",209,"SysLink",0x0,117,72,8,10
1023+
CONTROL "<a>US1</a>",IDC_SYSLINK1,"SysLink",0x0,7,85,15,9
1024+
CONTROL "<a>US2</a>",IDC_SYSLINK2,"SysLink",0x0,26,85,15,9
1025+
CONTROL "<a>RU1</a>",IDC_SYSLINK3,"SysLink",0x0,45,85,15,9
1026+
CONTROL "<a>RU2</a>",IDC_SYSLINK4,"SysLink",0x0,64,85,15,9
1027+
CONTROL "<>",210,"SysLink",0x0,83,85,12,9
1028+
CONTROL "<>",211,"SysLink",0x0,99,85,12,9
1029+
CONTROL "<>",212,"SysLink",0x0,115,85,12,9
10291030
END
10301031

10311032
IDD_INFOBOX DIALOGEX 0, 0, 244, 71
@@ -1312,9 +1313,11 @@ BEGIN
13121313
BEGIN
13131314
LEFTMARGIN, 7
13141315
RIGHTMARGIN, 175
1316+
VERTGUIDE, 130
13151317
TOPMARGIN, 7
1316-
BOTTOMMARGIN, 90
1318+
BOTTOMMARGIN, 104
13171319
HORZGUIDE, 72
1320+
HORZGUIDE, 93
13181321
END
13191322

13201323
IDD_INFOBOX, DIALOG

src/resource.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@
143143
#define IDD_WORDWRAP 122
144144
#define IDC_RADIO6 122
145145
#define IDD_LONGLINES 123
146+
#define IDC_SYSLINK1 123
146147
#define IDD_TABSETTINGS 124
148+
#define IDC_SYSLINK2 124
147149
#define IDD_PAGESETUP 125
150+
#define IDC_SYSLINK3 125
148151
#define IDD_INFOBOX 126
152+
#define IDC_SYSLINK4 126
149153
#define IDD_INFOBOX2 127
150154
#define IDD_INFOBOX3 128
151155
#define IDD_ABOUT_3RD_PARTY 129

0 commit comments

Comments
 (0)