Skip to content

Commit

Permalink
Make "Insert HTML/XML Tag" dialog resizable.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Nov 4, 2018
1 parent b5a99cc commit 0b47bae
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
48 changes: 36 additions & 12 deletions src/Edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -5330,6 +5330,7 @@ typedef struct _modlinesdata {

extern int cxModifyLinesDlg;
extern int cxEncloseSelectionDlg;
extern int cxInsertTagDlg;

static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) {
static int id_hover;
Expand Down Expand Up @@ -5686,27 +5687,50 @@ static INT_PTR CALLBACK EditInsertTagDlgProc(HWND hwnd, UINT umsg, WPARAM wParam
switch (umsg) {
case WM_INITDIALOG: {
SetWindowLongPtr(hwnd, DWLP_USER, lParam);
ResizeDlg_InitX(hwnd, cxInsertTagDlg, IDC_RESIZEGRIP2);

SendDlgItemMessage(hwnd, 100, EM_LIMITTEXT, 254, 0);
SetDlgItemText(hwnd, 100, L"<tag>");
SendDlgItemMessage(hwnd, IDC_MODIFY_LINE_PREFIX, EM_LIMITTEXT, 254, 0);
SetDlgItemText(hwnd, IDC_MODIFY_LINE_PREFIX, L"<tag>");

SendDlgItemMessage(hwnd, 101, EM_LIMITTEXT, 255, 0);
SetDlgItemText(hwnd, 101, L"</tag>");
SendDlgItemMessage(hwnd, IDC_MODIFY_LINE_APPEND, EM_LIMITTEXT, 255, 0);
SetDlgItemText(hwnd, IDC_MODIFY_LINE_APPEND, L"</tag>");

SetFocus(GetDlgItem(hwnd, 100));
PostMessage(GetDlgItem(hwnd, 100), EM_SETSEL, 1, 4);
SetFocus(GetDlgItem(hwnd, IDC_MODIFY_LINE_PREFIX));
PostMessage(GetDlgItem(hwnd, IDC_MODIFY_LINE_PREFIX), EM_SETSEL, 1, 4);
CenterDlgInParent(hwnd);
}
return FALSE;

case WM_DESTROY:
ResizeDlg_Destroy(hwnd, &cxInsertTagDlg, NULL);
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_COMMAND:
switch (LOWORD(wParam)) {
case 100: {
case IDC_MODIFY_LINE_PREFIX: {
if (HIWORD(wParam) == EN_CHANGE) {
WCHAR wchBuf[256];
BOOL bClear = TRUE;

GetDlgItemText(hwnd, 100, wchBuf, 256);
GetDlgItemText(hwnd, IDC_MODIFY_LINE_PREFIX, wchBuf, 256);
if (lstrlen(wchBuf) >= 3) {
if (wchBuf[0] == L'<') {
WCHAR wchIns[256] = L"</";
Expand Down Expand Up @@ -5741,15 +5765,15 @@ static INT_PTR CALLBACK EditInsertTagDlgProc(HWND hwnd, UINT umsg, WPARAM wParam
StrCaseEqual(wchIns, L"</link>") &&
StrCaseEqual(wchIns, L"</meta>"))) {

SetDlgItemText(hwnd, 101, wchIns);
SetDlgItemText(hwnd, IDC_MODIFY_LINE_APPEND, wchIns);
bClear = FALSE;
}
}
}
}

if (bClear) {
SetDlgItemText(hwnd, 101, L"");
SetDlgItemText(hwnd, IDC_MODIFY_LINE_PREFIX, L"");
}
}
}
Expand All @@ -5758,8 +5782,8 @@ static INT_PTR CALLBACK EditInsertTagDlgProc(HWND hwnd, UINT umsg, WPARAM wParam
case IDOK: {
PTAGSDATA pdata = (PTAGSDATA)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 @@ -231,6 +231,7 @@ int cyFavoritesDlg;
int cxAddFavoritesDlg;
int cxModifyLinesDlg;
int cxEncloseSelectionDlg;
int cxInsertTagDlg;
int xFindReplaceDlg;
int yFindReplaceDlg;

Expand Down Expand Up @@ -5462,6 +5463,7 @@ void LoadSettings(void) {
cxAddFavoritesDlg = IniSectionGetInt(pIniSection, L"AddFavoritesDlgSizeX", 0);
cxModifyLinesDlg = IniSectionGetInt(pIniSection, L"ModifyLinesDlgSizeX", 0);
cxEncloseSelectionDlg = IniSectionGetInt(pIniSection, L"EncloseSelectionDlgSizeX", 0);
cxInsertTagDlg = IniSectionGetInt(pIniSection, L"InsertTagDlgSizeX", 0);
xFindReplaceDlg = IniSectionGetInt(pIniSection, L"FindReplaceDlgPosX", 0);
yFindReplaceDlg = IniSectionGetInt(pIniSection, L"FindReplaceDlgPosY", 0);

Expand Down Expand Up @@ -5674,6 +5676,7 @@ void SaveSettings(BOOL bSaveSettingsNow) {
IniSectionSetInt(pIniSection, L"AddFavoritesDlgSizeX", cxAddFavoritesDlg);
IniSectionSetInt(pIniSection, L"ModifyLinesDlgSizeX", cxModifyLinesDlg);
IniSectionSetInt(pIniSection, L"EncloseSelectionDlgSizeX", cxEncloseSelectionDlg);
IniSectionSetInt(pIniSection, L"InsertTagDlgSizeX", cxInsertTagDlg);
IniSectionSetInt(pIniSection, L"FindReplaceDlgPosX", xFindReplaceDlg);
IniSectionSetInt(pIniSection, L"FindReplaceDlgPosY", yFindReplaceDlg);

Expand Down
5 changes: 3 additions & 2 deletions src/Notepad2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1280,11 +1280,12 @@ CAPTION "Insert HTML/XML Tag"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
LTEXT "&Opening tag (with attributes):",IDC_STATIC,7,7,130,8
EDITTEXT 100,7,18,250,14,ES_AUTOHSCROLL
EDITTEXT IDC_MODIFY_LINE_PREFIX,7,18,250,14,ES_AUTOHSCROLL
LTEXT "&Closing tag (can be edited):",IDC_STATIC,7,37,118,8
EDITTEXT 101,7,48,250,14,ES_AUTOHSCROLL
EDITTEXT IDC_MODIFY_LINE_APPEND,7,48,250,14,ES_AUTOHSCROLL
DEFPUSHBUTTON "OK",IDOK,151,69,50,14
PUSHBUTTON "Cancel",IDCANCEL,207,69,50,14
SCROLLBAR IDC_RESIZEGRIP2,7,69,10,10
END

IDD_ENCLOSESELECTION DIALOGEX 0, 0, 248, 94
Expand Down

0 comments on commit 0b47bae

Please sign in to comment.