Skip to content

Commit

Permalink
Add "Zoom Level" dialog, fix issue #69.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Nov 21, 2018
1 parent 4079395 commit 99860e6
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 13 deletions.
81 changes: 79 additions & 2 deletions src/Dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1931,7 +1931,7 @@ BOOL SelectDefLineEndingDlg(HWND hwnd, int *iOption) {
return iResult == IDOK;
}

static INT_PTR CALLBACK WarnLineEndingDlgDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) {
static INT_PTR CALLBACK WarnLineEndingDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) {
switch (umsg) {
case WM_INITDIALOG: {
SetWindowLongPtr(hwnd, DWLP_USER, lParam);
Expand Down Expand Up @@ -1989,10 +1989,87 @@ static INT_PTR CALLBACK WarnLineEndingDlgDlgProc(HWND hwnd, UINT umsg, WPARAM wP

BOOL WarnLineEndingDlg(HWND hwnd, struct EditFileIOStatus *status) {
MessageBeep(MB_ICONEXCLAMATION);
const INT_PTR iResult = ThemedDialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_WARNLINEENDS), hwnd, WarnLineEndingDlgDlgProc, (LPARAM)status);
const INT_PTR iResult = ThemedDialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_WARNLINEENDS), hwnd, WarnLineEndingDlgProc, (LPARAM)status);
return iResult == IDOK;
}

void InitZoomLevelComboBox(HWND hwnd, int nCtlId, int zoomLevel) {
WCHAR tch[16];
int selIndex = -1;
int i = 0;
int level = 25;

HWND hwndCtl = GetDlgItem(hwnd, nCtlId);
SendMessage(hwndCtl, CB_LIMITTEXT, 8, 0);
for (; level < 200; level += 25) {
if (zoomLevel == level) {
selIndex = i;
}
wsprintf(tch, L"%d%%", level);
SendMessage(hwndCtl, CB_ADDSTRING, 0, (LPARAM)tch);
++i;
}
for (; level <= SC_MAX_ZOOM_LEVEL; level += 50) {
if (zoomLevel == level) {
selIndex = i;
}
wsprintf(tch, L"%d%%", level);
SendMessage(hwndCtl, CB_ADDSTRING, 0, (LPARAM)tch);
++i;
}

SendMessage(hwndCtl, CB_SETEXTENDEDUI, TRUE, 0);
SendMessage(hwndCtl, CB_SETCURSEL, selIndex, 0);
if (selIndex == -1) {
wsprintf(tch, L"%d%%", zoomLevel);
SetWindowText(hwndCtl, tch);
}
}

BOOL GetZoomLevelComboBoxValue(HWND hwnd, int nCtrId, int *zoomLevel) {
WCHAR tch[16];
GetDlgItemText(hwnd, nCtrId, tch, COUNTOF(tch));
return CRTStrToInt(tch, zoomLevel) && *zoomLevel >= SC_MIN_ZOOM_LEVEL && *zoomLevel <= SC_MAX_ZOOM_LEVEL;
}

static INT_PTR CALLBACK ZoomLevelDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) {
UNREFERENCED_PARAMETER(lParam);

switch (umsg) {
case WM_INITDIALOG: {
const int zoomLevel = (int)SendMessage(hwndEdit, SCI_GETZOOM, 0, 0);
InitZoomLevelComboBox(hwnd, IDC_ZOOMLEVEL, zoomLevel);
CenterDlgInParent(hwnd);
}
return TRUE;

case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
case IDYES: {
int zoomLevel;
if (GetZoomLevelComboBoxValue(hwnd, IDC_ZOOMLEVEL, &zoomLevel)) {
SendMessage(hwndEdit, SCI_SETZOOM, zoomLevel, 0);
}
if (LOWORD(wParam) == IDOK) {
EndDialog(hwnd, IDOK);
}
}
break;

case IDCANCEL:
EndDialog(hwnd, IDCANCEL);
break;
}
return TRUE;
}
return FALSE;
}

void ZoomLevelDlg(HWND hwnd) {
ThemedDialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_ZOOMLEVEL), hwnd, ZoomLevelDlgProc, 0);
}

//=============================================================================
//
// InfoBoxDlgProc()
Expand Down
3 changes: 3 additions & 0 deletions src/Dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ BOOL SelectDefLineEndingDlg(HWND hwnd, int *iOption);

struct EditFileIOStatus;
BOOL WarnLineEndingDlg(HWND hwnd, struct EditFileIOStatus *status);
void InitZoomLevelComboBox(HWND hwnd, int nCtlId, int zoomLevel);
BOOL GetZoomLevelComboBoxValue(HWND hwnd, int nCtrId, int *zoomLevel);
void ZoomLevelDlg(HWND hwnd);
INT_PTR InfoBox(int iType, LPCWSTR lpstrSetting, int uidMessage, ...);

#endif // NOTEPAD2_DIALOGS_H_
Expand Down
4 changes: 4 additions & 0 deletions src/Notepad2.c
Original file line number Diff line number Diff line change
Expand Up @@ -5137,6 +5137,10 @@ LRESULT MsgNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) {
EditEnsureConsistentLineEndings(hwndEdit);
return TRUE;

case STATUS_DOCZOOM:
ZoomLevelDlg(hwnd);
return TRUE;

default:
return FALSE;
}
Expand Down
14 changes: 12 additions & 2 deletions src/Notepad2.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1209,8 +1209,7 @@ BEGIN
COMBOBOX IDC_PAGESETUP_COLOR_MODE_LIST,64,206,160,160,CBS_DROPDOWNLIST | WS_VSCROLL | WS_GROUP | WS_TABSTOP
GROUPBOX "Zoom",IDC_STATIC,240,170,108,58,WS_GROUP
LTEXT "Print zoo&m (10% to 500%):",IDC_STATIC,248,188,94,8
EDITTEXT IDC_PAGESETUP_ZOOM_EDIT,298,206,42,12,ES_AUTOHSCROLL
CONTROL "",IDC_PAGESETUP_ZOOM_UPDOWN,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | UDS_HOTTRACK,282,205,11,14
COMBOBOX IDC_PAGESETUP_ZOOMLEVEL,290,206,50,120,CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP
DEFPUSHBUTTON "OK",IDOK,187,239,50,14,WS_GROUP
PUSHBUTTON "Cancel",IDCANCEL,243,239,50,14
PUSHBUTTON "&Printer...",IDC_PAGESETUP_PRINTER,299,239,50,14
Expand Down Expand Up @@ -1404,6 +1403,17 @@ BEGIN
PUSHBUTTON "Cancel",IDCANCEL,127,24,50,14
END

IDD_ZOOMLEVEL DIALOGEX 0, 0, 120, 64
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Zoom Level"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
LTEXT "Zoom level (10% to 500%):",IDC_STATIC,7,7,106,8
COMBOBOX IDC_ZOOMLEVEL,7,19,50,120,CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "Apply",IDYES,63,18,50,14
DEFPUSHBUTTON "OK",IDOK,7,43,50,14
PUSHBUTTON "Cancel",IDCANCEL,63,43,50,14
END

/////////////////////////////////////////////////////////////////////////////
//
Expand Down
11 changes: 4 additions & 7 deletions src/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,7 @@ extern "C" BOOL EditPrint(HWND hwnd, LPCWSTR pszDocTitle, LPCWSTR pszPageFormat)
static UINT_PTR CALLBACK PageSetupHook(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM /*lParam*/) noexcept {
switch (uiMsg) {
case WM_INITDIALOG: {
SendDlgItemMessage(hwnd, IDC_PAGESETUP_ZOOM_EDIT, EM_LIMITTEXT, 32, 0);

SendDlgItemMessage(hwnd, IDC_PAGESETUP_ZOOM_UPDOWN, UDM_SETRANGE, 0, MAKELONG(SC_MAX_ZOOM_LEVEL, SC_MIN_ZOOM_LEVEL));
SendDlgItemMessage(hwnd, IDC_PAGESETUP_ZOOM_UPDOWN, UDM_SETPOS, 0, MAKELONG((short)iPrintZoom, 0));
InitZoomLevelComboBox(hwnd, IDC_PAGESETUP_ZOOMLEVEL, iPrintZoom);

// Set header options
WCHAR tch[512];
Expand Down Expand Up @@ -473,9 +470,9 @@ static UINT_PTR CALLBACK PageSetupHook(HWND hwnd, UINT uiMsg, WPARAM wParam, LPA

case WM_COMMAND:
if (LOWORD(wParam) == IDOK) {
const LONG lPos = (LONG)SendDlgItemMessage(hwnd, IDC_PAGESETUP_ZOOM_UPDOWN, UDM_GETPOS, 0, 0);
if (HIWORD(lPos) == 0) {
iPrintZoom = LOWORD(lPos);
int zoomLevel;
if (GetZoomLevelComboBoxValue(hwnd, IDC_PAGESETUP_ZOOMLEVEL, &zoomLevel)) {
iPrintZoom = zoomLevel;
} else {
iPrintZoom = 100;
}
Expand Down
6 changes: 4 additions & 2 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@
// additional controls
#define IDC_PAGESETUP_PRINTER 0x0402
#define IDC_PAGESETUP_HEADER_FOOTER_BOX 0x0432
#define IDC_PAGESETUP_ZOOM_EDIT 30
#define IDC_PAGESETUP_ZOOM_UPDOWN 31
#define IDC_PAGESETUP_ZOOMLEVEL 30
#define IDC_PAGESETUP_HEADER_LIST 32
#define IDC_PAGESETUP_FOOTER_LIST 33
#define IDC_PAGESETUP_COLOR_MODE_LIST 34
Expand Down Expand Up @@ -255,6 +254,9 @@
#define IDC_ALIGN_CENTER 102
#define IDC_ALIGN_JUSTIFY 103
#define IDC_ALIGN_JUSTIFY_PAR 104
// Zoom Level
#define IDD_ZOOMLEVEL 130
#define IDC_ZOOMLEVEL 100

#define IDS_APPTITLE 10000
#define IDS_APPTITLE_ELEVATED 10001
Expand Down

0 comments on commit 99860e6

Please sign in to comment.