Dylan Smith : wordpad: Added zoom cursor for print preview.

Alexandre Julliard julliard at winehq.org
Wed Feb 24 10:21:33 CST 2010


Module: wine
Branch: master
Commit: adc2c9547eb54bb3aa4874d0ae3409b7d28a26f1
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=adc2c9547eb54bb3aa4874d0ae3409b7d28a26f1

Author: Dylan Smith <dylan.ah.smith at gmail.com>
Date:   Wed Feb 24 02:28:57 2010 -0500

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(+), 0 deletions(-)

diff --git a/programs/wordpad/print.c b/programs/wordpad/print.c
index f77ab12..0fef3ac 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 ac159da..c074e3d 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 5c70c3e..33d6b45 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 0000000..26d1a8f
Binary files /dev/null and b/programs/wordpad/zoom.cur differ




More information about the wine-cvs mailing list