From adc2c9547eb54bb3aa4874d0ae3409b7d28a26f1 Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Wed, 24 Feb 2010 02:28:57 -0500 Subject: [PATCH] wordpad: Added zoom cursor for print preview. In print preview you can zoom in by left clicking on one of the pages. The zoom cursor is displayed whenever the mouse is over the page to indicate to the user that they can zoom in. When fully zoomed in it will zoom out when this is done again. When clicking on the second page, it will zoom into that page. --- programs/wordpad/print.c | 101 +++++++++++++++++++++++++++++++++++++ programs/wordpad/rsrc.rc | 3 ++ programs/wordpad/wordpad.h | 2 + programs/wordpad/zoom.cur | Bin 0 -> 766 bytes 4 files changed, 106 insertions(+) create mode 100644 programs/wordpad/zoom.cur diff --git a/programs/wordpad/print.c b/programs/wordpad/print.c index f77ab12aa25..0fef3ac06c8 100644 --- a/programs/wordpad/print.c +++ b/programs/wordpad/print.c @@ -988,6 +988,29 @@ static void toggle_num_pages(HWND hMainWnd) update_preview(hMainWnd); } +/* Returns the page shown that the point is in (1 or 2) or 0 if the point + * isn't inside either page */ +int preview_page_hittest(POINT pt) +{ + RECT rc; + rc.left = preview.spacing.cx; + rc.right = rc.left + preview.bmScaledSize.cx; + rc.top = preview.spacing.cy; + rc.bottom = rc.top + preview.bmScaledSize.cy; + if (PtInRect(&rc, pt)) + return 1; + + if (preview.pages_shown <= 1) + return 0; + + rc.left += preview.bmScaledSize.cx + preview.spacing.cx; + rc.right += preview.bmScaledSize.cx + preview.spacing.cx; + if (PtInRect(&rc, pt)) + return 2; + + return 0; +} + LRESULT CALLBACK preview_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) @@ -1086,6 +1109,84 @@ LRESULT CALLBACK preview_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) return 0; } + case WM_SETCURSOR: + { + POINT pt; + RECT rc; + int bHittest = FALSE; + DWORD messagePos = GetMessagePos(); + pt.x = (short)LOWORD(messagePos); + pt.y = (short)HIWORD(messagePos); + ScreenToClient(hWnd, &pt); + + GetClientRect(hWnd, &rc); + if (PtInRect(&rc, pt)) + { + pt.x += GetScrollPos(hWnd, SB_HORZ); + pt.y += GetScrollPos(hWnd, SB_VERT); + bHittest = preview_page_hittest(pt); + } + + if (bHittest) + SetCursor(LoadCursorW(GetModuleHandleW(0), + MAKEINTRESOURCEW(IDC_ZOOM))); + else + SetCursor(LoadCursorW(NULL, (WCHAR*)IDC_ARROW)); + + return TRUE; + } + + case WM_LBUTTONDOWN: + { + int page; + POINT pt; + pt.x = (short)LOWORD(lParam) + GetScrollPos(hWnd, SB_HORZ); + pt.y = (short)HIWORD(lParam) + GetScrollPos(hWnd, SB_VERT); + if ((page = preview_page_hittest(pt)) > 0) + { + HWND hMainWnd = GetParent(hWnd); + + /* Convert point from client coordinate to unzoomed page + * coordinate. */ + pt.x -= preview.spacing.cx; + if (page > 1) + pt.x -= preview.bmScaledSize.cx + preview.spacing.cx; + pt.y -= preview.spacing.cy; + pt.x /= preview.zoomratio; + pt.y /= preview.zoomratio; + + preview.zoomlevel = (preview.zoomlevel + 1) % 3; + preview.zoomratio = 0; + if (preview.pages_shown > 1) + { + if (page >= 2) preview.page++; + toggle_num_pages(hMainWnd); + } else { + update_preview_sizes(hWnd, TRUE); + update_scaled_preview(hMainWnd); + update_preview_buttons(hMainWnd); + } + + if (preview.zoomlevel > 0) { + SCROLLINFO si; + /* Convert the coordinate back to client coordinate. */ + pt.x *= preview.zoomratio; + pt.y *= preview.zoomratio; + pt.x += preview.spacing.cx; + pt.y += preview.spacing.cy; + /* Scroll to center view at that point on the page */ + si.cbSize = sizeof(si); + si.fMask = SIF_PAGE; + GetScrollInfo(hWnd, SB_HORZ, &si); + pt.x -= si.nPage / 2; + SetScrollPos(hWnd, SB_HORZ, pt.x, TRUE); + GetScrollInfo(hWnd, SB_VERT, &si); + pt.y -= si.nPage / 2; + SetScrollPos(hWnd, SB_VERT, pt.y, TRUE); + } + } + } + default: return DefWindowProcW(hWnd, msg, wParam, lParam); } diff --git a/programs/wordpad/rsrc.rc b/programs/wordpad/rsrc.rc index ac159da8916..c074e3d251e 100644 --- a/programs/wordpad/rsrc.rc +++ b/programs/wordpad/rsrc.rc @@ -60,3 +60,6 @@ IDI_WRI ICON "wri.ico" /* @makedep: txt.ico */ IDI_TXT ICON "txt.ico" + +/* @makedep: zoom.cur */ +IDC_ZOOM CURSOR "zoom.cur" diff --git a/programs/wordpad/wordpad.h b/programs/wordpad/wordpad.h index 5c70c3e500a..33d6b456159 100644 --- a/programs/wordpad/wordpad.h +++ b/programs/wordpad/wordpad.h @@ -189,6 +189,8 @@ #define IDI_WRI 104 #define IDI_TXT 105 +#define IDC_ZOOM 106 + #define STRING_ALL_FILES 1400 #define STRING_TEXT_FILES_TXT 1401 #define STRING_TEXT_FILES_UNICODE_TXT 1402 diff --git a/programs/wordpad/zoom.cur b/programs/wordpad/zoom.cur new file mode 100644 index 0000000000000000000000000000000000000000..26d1a8fa157eb6b448660210c49636b0a876020f GIT binary patch literal 766 zcmd^7u?~VT5Pgs)j5xW%=qI?rz<=4z(O+t!AA)gl)Q!RTd{;sW4w|@n z$dRG0fkNY&18V>qK`FFC1}6`AX_Ku)45N98V&0E0c~QY5gdlYiY+