Skip to content

Commit 1e1406b

Browse files
committed
Enclose Selection - add links with quotation marks #280
1 parent 5cf6bfd commit 1e1406b

File tree

3 files changed

+174
-2
lines changed

3 files changed

+174
-2
lines changed

src/Edit.c

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "Extension/DPIHelper.h"
4040
#include "Extension/SciCall.h"
4141
#include "Extension/ProcessElevationUtils.h"
42+
#include "Extension/UnicodeQuotes.h"
4243
#include "Extension/Utils.h"
4344

4445

@@ -6594,13 +6595,46 @@ INT_PTR CALLBACK EditEncloseSelectionDlgProc(HWND hwnd, UINT umsg, WPARAM wParam
65946595
const WCHAR* _left_braces = L"<{([";
65956596
const WCHAR* _right_braces = L">})]";
65966597
const WCHAR* _special_symbs = L"`~!@#%^*-_+=|\\/:;\"',.?";
6598+
6599+
// [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;
65976608
// [/2e]
6609+
65986610
static PENCLOSESELDATA pdata;
65996611
switch (umsg)
66006612
{
66016613
DPI_CHANGED_HANDLER();
66026614

66036615
case WM_INITDIALOG: {
6616+
6617+
// [2e]: Enclose Selection - add links with quotation marks #280
6618+
LOGFONT lf = { 0 };
6619+
6620+
if (NULL == (hFontNormal = (HFONT)SendDlgItemMessage(hwnd, 200, WM_GETFONT, 0, 0)))
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);
6626+
6627+
hCursorNormal = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
6628+
if (!(hCursorHover = LoadCursor(NULL, MAKEINTRESOURCE(IDC_HAND))))
6629+
hCursorHover = LoadCursor(g_hInstance, MAKEINTRESOURCE(IDC_ARROW));
6630+
6631+
for (DWORD dwId = iMinLinkID; dwId <= iMaxLinkID; ++dwId)
6632+
{
6633+
WCHAR linkText[2] = { lpwstrUnicodeQuotes[dwId - iMinLinkID], 0 };
6634+
SetDlgItemTextW(hwnd, dwId, linkText);
6635+
}
6636+
// [/2e]
6637+
66046638
pdata = (PENCLOSESELDATA)lParam;
66056639
SendDlgItemMessage(hwnd, 100, EM_LIMITTEXT, 255, 0);
66066640
SetDlgItemTextW(hwnd, 100, pdata->pwsz1);
@@ -6610,6 +6644,123 @@ INT_PTR CALLBACK EditEncloseSelectionDlgProc(HWND hwnd, UINT umsg, WPARAM wParam
66106644
CenterDlgInParent(hwnd);
66116645
}
66126646
return TRUE;
6647+
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+
66136764
case WM_COMMAND:
66146765
switch (LOWORD(wParam))
66156766
{

src/Extension/UnicodeQuotes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
3+
const int iUnicodeQuotesCount = 16;
4+
const LPCWSTR lpwstrUnicodeQuotes = L"‘’‚“”„‹›《》「」『』«»";

src/Notepad2.rc

Lines changed: 19 additions & 2 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, 70
1002+
IDD_ENCLOSESELECTION DIALOGEX 0, 0, 182, 90
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,6 +1010,22 @@ 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
10131029
END
10141030

10151031
IDD_INFOBOX DIALOGEX 0, 0, 244, 71
@@ -1297,7 +1313,8 @@ BEGIN
12971313
LEFTMARGIN, 7
12981314
RIGHTMARGIN, 175
12991315
TOPMARGIN, 7
1300-
BOTTOMMARGIN, 63
1316+
BOTTOMMARGIN, 90
1317+
HORZGUIDE, 72
13011318
END
13021319

13031320
IDD_INFOBOX, DIALOG

0 commit comments

Comments
 (0)