Skip to content

Commit

Permalink
Make "Modify Lines" dialog resizable.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Nov 4, 2018
1 parent 00dbe0c commit 61a4ef3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 22 deletions.
48 changes: 34 additions & 14 deletions src/Edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -5321,15 +5321,15 @@ BOOL EditLineNumDlg(HWND hwnd) {
//
// EditModifyLinesDlg()
//
// Controls: 100 Input
// 101 Input
//

typedef struct _modlinesdata {
LPWSTR pwsz1;
LPWSTR pwsz2;
} MODLINESDATA, *PMODLINESDATA;

extern int cxModifyLinesDlg;

static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) {
static int id_hover;
static int id_capture;
Expand All @@ -5343,12 +5343,12 @@ static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
switch (umsg) {
case WM_INITDIALOG: {
SetWindowLongPtr(hwnd, DWLP_USER, lParam);
PMODLINESDATA pdata = (PMODLINESDATA)lParam;
ResizeDlg_InitX(hwnd, cxModifyLinesDlg, IDC_RESIZEGRIP2);

id_hover = 0;
id_capture = 0;

if (NULL == (hFontNormal = (HFONT)SendDlgItemMessage(hwnd, 200, WM_GETFONT, 0, 0))) {
if (NULL == (hFontNormal = (HFONT)SendDlgItemMessage(hwnd, IDC_MODIFY_LINE_DLN_NP, WM_GETFONT, 0, 0))) {
hFontNormal = GetStockObject(DEFAULT_GUI_FONT);
}

Expand All @@ -5362,18 +5362,38 @@ static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
hCursorHover = LoadCursor(g_hInstance, IDC_ARROW);
}

SetDlgItemText(hwnd, 100, pdata->pwsz1);
SendDlgItemMessage(hwnd, 100, EM_LIMITTEXT, 255, 0);
SetDlgItemText(hwnd, 101, pdata->pwsz2);
SendDlgItemMessage(hwnd, 101, EM_LIMITTEXT, 255, 0);
PMODLINESDATA pdata = (PMODLINESDATA)lParam;
SetDlgItemText(hwnd, IDC_MODIFY_LINE_PREFIX, pdata->pwsz1);
SendDlgItemMessage(hwnd, IDC_MODIFY_LINE_PREFIX, EM_LIMITTEXT, 255, 0);
SetDlgItemText(hwnd, IDC_MODIFY_LINE_APPEND, pdata->pwsz2);
SendDlgItemMessage(hwnd, IDC_MODIFY_LINE_APPEND, EM_LIMITTEXT, 255, 0);
CenterDlgInParent(hwnd);
}
return TRUE;

case WM_DESTROY:
ResizeDlg_Destroy(hwnd, &cxModifyLinesDlg, NULL);
DeleteObject(hFontHover);
return FALSE;

case WM_SIZE: {
int dx;

ResizeDlg_Size(hwnd, lParam, &dx, NULL);
HDWP hdwp = BeginDeferWindowPos(5);
hdwp = DeferCtlPos(hdwp, hwnd, IDC_RESIZEGRIP2, dx, 0, SWP_NOSIZE);
hdwp = DeferCtlPos(hdwp, hwnd, IDOK, dx, 0, SWP_NOSIZE);
hdwp = DeferCtlPos(hdwp, hwnd, IDCANCEL, dx, 0, SWP_NOSIZE);
hdwp = DeferCtlPos(hdwp, hwnd, IDC_MODIFY_LINE_PREFIX, dx, 0, SWP_NOMOVE);
hdwp = DeferCtlPos(hdwp, hwnd, IDC_MODIFY_LINE_APPEND, dx, 0, SWP_NOMOVE);
EndDeferWindowPos(hdwp);
}
return TRUE;

case WM_GETMINMAXINFO:
ResizeDlg_GetMinMaxInfo(hwnd, lParam);
return TRUE;

case WM_NCACTIVATE:
if (!wParam) {
if (id_hover != 0) {
Expand All @@ -5389,7 +5409,7 @@ static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
const DWORD dwId = GetWindowLong((HWND)lParam, GWL_ID);
HDC hdc = (HDC)wParam;

if (dwId >= 200 && dwId <= 205) {
if (dwId >= IDC_MODIFY_LINE_DLN_NP && dwId <= IDC_MODIFY_LINE_ZCN_ZP) {
SetBkMode(hdc, TRANSPARENT);
if (GetSysColorBrush(COLOR_HOTLIGHT)) {
SetTextColor(hdc, GetSysColor(COLOR_HOTLIGHT));
Expand All @@ -5408,7 +5428,7 @@ static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
const DWORD dwId = GetWindowLong(hwndHover, GWL_ID);

if (GetActiveWindow() == hwnd) {
if (dwId >= 200 && dwId <= 205) {
if (dwId >= IDC_MODIFY_LINE_DLN_NP && dwId <= IDC_MODIFY_LINE_ZCN_ZP) {
if (id_capture == (int)dwId || id_capture == 0) {
if (id_hover != id_capture || id_hover == 0) {
id_hover = dwId;
Expand All @@ -5434,7 +5454,7 @@ static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
HWND hwndHover = ChildWindowFromPoint(hwnd, pt);
const DWORD dwId = GetWindowLong(hwndHover, GWL_ID);

if (dwId >= 200 && dwId <= 205) {
if (dwId >= IDC_MODIFY_LINE_DLN_NP && dwId <= IDC_MODIFY_LINE_ZCN_ZP) {
GetCapture();
id_hover = dwId;
id_capture = dwId;
Expand All @@ -5453,7 +5473,7 @@ static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
ReleaseCapture();
if (id_hover == id_capture) {
const int id_focus = GetWindowLong(GetFocus(), GWL_ID);
if (id_focus == 100 || id_focus == 101) {
if (id_focus == IDC_MODIFY_LINE_PREFIX || id_focus == IDC_MODIFY_LINE_APPEND) {
WCHAR wch[8];
GetDlgItemText(hwnd, id_capture, wch, COUNTOF(wch));
SendDlgItemMessage(hwnd, id_focus, EM_SETSEL, 0, -1);
Expand Down Expand Up @@ -5481,8 +5501,8 @@ static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd, UINT umsg, WPARAM wPar
case IDOK: {
PMODLINESDATA pdata = (PMODLINESDATA)GetWindowLongPtr(hwnd, DWLP_USER);
if (pdata) {
GetDlgItemText(hwnd, 100, pdata->pwsz1, 256);
GetDlgItemText(hwnd, 101, pdata->pwsz2, 256);
GetDlgItemText(hwnd, IDC_MODIFY_LINE_PREFIX, pdata->pwsz1, 256);
GetDlgItemText(hwnd, IDC_MODIFY_LINE_APPEND, pdata->pwsz2, 256);
}
EndDialog(hwnd, IDOK);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Notepad2.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ int cyOpenWithDlg;
int cxFavoritesDlg;
int cyFavoritesDlg;
int cxAddFavoritesDlg;
int cxModifyLinesDlg;
int xFindReplaceDlg;
int yFindReplaceDlg;

Expand Down Expand Up @@ -5458,6 +5459,7 @@ void LoadSettings(void) {
cxFavoritesDlg = IniSectionGetInt(pIniSection, L"FavoritesDlgSizeX", 0);
cyFavoritesDlg = IniSectionGetInt(pIniSection, L"FavoritesDlgSizeY", 0);
cxAddFavoritesDlg = IniSectionGetInt(pIniSection, L"AddFavoritesDlgSizeX", 0);
cxModifyLinesDlg = IniSectionGetInt(pIniSection, L"ModifyLinesDlgSizeX", 0);
xFindReplaceDlg = IniSectionGetInt(pIniSection, L"FindReplaceDlgPosX", 0);
yFindReplaceDlg = IniSectionGetInt(pIniSection, L"FindReplaceDlgPosY", 0);

Expand Down Expand Up @@ -5668,6 +5670,7 @@ void SaveSettings(BOOL bSaveSettingsNow) {
IniSectionSetInt(pIniSection, L"FavoritesDlgSizeX", cxFavoritesDlg);
IniSectionSetInt(pIniSection, L"FavoritesDlgSizeY", cyFavoritesDlg);
IniSectionSetInt(pIniSection, L"AddFavoritesDlgSizeX", cxAddFavoritesDlg);
IniSectionSetInt(pIniSection, L"ModifyLinesDlgSizeX", cxModifyLinesDlg);
IniSectionSetInt(pIniSection, L"FindReplaceDlgPosX", xFindReplaceDlg);
IniSectionSetInt(pIniSection, L"FindReplaceDlgPosY", yFindReplaceDlg);

Expand Down
17 changes: 9 additions & 8 deletions src/Notepad2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1257,20 +1257,21 @@ CAPTION "Modify Lines"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
LTEXT "&Prefix text to lines:",IDC_STATIC,7,6,96,8
EDITTEXT 100,7,18,246,14,ES_AUTOHSCROLL
EDITTEXT IDC_MODIFY_LINE_PREFIX,7,18,246,14,ES_AUTOHSCROLL
LTEXT "&Append text to lines:",IDC_STATIC,7,37,97,8
EDITTEXT 101,7,48,246,14,ES_AUTOHSCROLL
EDITTEXT IDC_MODIFY_LINE_APPEND,7,48,246,14,ES_AUTOHSCROLL
DEFPUSHBUTTON "OK",IDOK,147,100,50,14
PUSHBUTTON "Cancel",IDCANCEL,203,100,50,14
LTEXT "$(L)",200,7,68,21,8
LTEXT "$(0L)",201,27,68,27,8
LTEXT "$(L)",IDC_MODIFY_LINE_DLN_NP,7,68,21,8
LTEXT "$(0L)",IDC_MODIFY_LINE_DLN_ZP,27,68,27,8
LTEXT "Document line number.",IDC_STATIC,51,68,118,8
LTEXT "$(N)",202,7,78,22,8
LTEXT "$(0N)",203,27,78,25,8
LTEXT "$(N)",IDC_MODIFY_LINE_CN_NP,7,78,22,8
LTEXT "$(0N)",IDC_MODIFY_LINE_CN_ZP,27,78,25,8
LTEXT "Continuous number.",IDC_STATIC,51,78,107,8
LTEXT "$(I)",204,7,88,21,8
LTEXT "$(0I)",205,27,88,25,8
LTEXT "$(I)",IDC_MODIFY_LINE_ZCN_NP,7,88,21,8
LTEXT "$(0I)",IDC_MODIFY_LINE_ZCN_ZP,27,88,25,8
LTEXT "Continuous number (zero-based).",IDC_STATIC,51,88,125,8
SCROLLBAR IDC_RESIZEGRIP2,7,100,10,10
END

IDD_INSERTTAG DIALOGEX 0, 0, 264, 90
Expand Down
9 changes: 9 additions & 0 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#define IDC_COPY 100
#define IDC_ENCODINGLIST 100
#define IDC_EOLMODELIST 100
#define IDC_MODIFY_LINE_PREFIX 100
#define IDC_MODIFY_LINE_APPEND 101
#define IDC_SEARCHEXE 101
#define IDR_POPUPMENU 101
#define IDC_GETOPENWITHDIR 101
Expand Down Expand Up @@ -132,6 +134,12 @@
#define IDC_CLEAR_FIND 155
#define IDC_CLEAR_REPLACE 156
#define IDC_TRANSPARENT 157
#define IDC_MODIFY_LINE_DLN_NP 200
#define IDC_MODIFY_LINE_DLN_ZP 201
#define IDC_MODIFY_LINE_CN_NP 202
#define IDC_MODIFY_LINE_CN_ZP 203
#define IDC_MODIFY_LINE_ZCN_NP 204
#define IDC_MODIFY_LINE_ZCN_ZP 205
#define IDACC_FIND 200
#define IDACC_REPLACE 201
#define IDACC_SAVEPOS 202
Expand All @@ -143,6 +151,7 @@
#define IDACC_SELTONEXT 208
#define IDACC_SELTOPREV 209
#define IDC_NFOASOEM 300

#define IDS_APPTITLE 10000
#define IDS_APPTITLE_ELEVATED 10001
#define IDS_APPTITLE_PASTEBOARD 10002
Expand Down

0 comments on commit 61a4ef3

Please sign in to comment.