Author: akhaldi
Date: Mon Sep 14 09:32:57 2015
New Revision: 69222

URL: http://svn.reactos.org/svn/reactos?rev=69222&view=rev
Log:
[NOTEPAD] Calculate the border around the printing area based on the margins 
the user has selected in the page setup dialog, instead of using a fixed size 
one. Brought to you by Ricardo Hanke with minor changes by me. CORE-10184

Modified:
    trunk/reactos/base/applications/notepad/dialog.c
    trunk/reactos/base/applications/notepad/main.h
    trunk/reactos/base/applications/notepad/settings.c

Modified: trunk/reactos/base/applications/notepad/dialog.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/notepad/dialog.c?rev=69222&r1=69221&r2=69222&view=diff
==============================================================================
--- trunk/reactos/base/applications/notepad/dialog.c    [iso-8859-1] (original)
+++ trunk/reactos/base/applications/notepad/dialog.c    [iso-8859-1] Mon Sep 14 
09:32:57 2015
@@ -225,6 +225,31 @@
     }
 }
 
+static RECT
+GetPrintingRect(HDC hdc, RECT margins)
+{
+    int iLogPixelsX, iLogPixelsY;
+    int iHorzRes, iVertRes;
+    int iPhysPageX, iPhysPageY, iPhysPageW, iPhysPageH;
+    RECT rcPrintRect;
+
+    iPhysPageX = GetDeviceCaps(hdc, PHYSICALOFFSETX);
+    iPhysPageY = GetDeviceCaps(hdc, PHYSICALOFFSETY);
+    iPhysPageW = GetDeviceCaps(hdc, PHYSICALWIDTH);
+    iPhysPageH = GetDeviceCaps(hdc, PHYSICALHEIGHT);
+    iLogPixelsX = GetDeviceCaps(hdc, LOGPIXELSX);
+    iLogPixelsY = GetDeviceCaps(hdc, LOGPIXELSY);
+    iHorzRes = GetDeviceCaps(hdc, HORZRES);
+    iVertRes = GetDeviceCaps(hdc, VERTRES);
+
+    rcPrintRect.left = (margins.left * iLogPixelsX / 2540) - iPhysPageX;
+    rcPrintRect.top = (margins.top * iLogPixelsY / 2540) - iPhysPageY;
+    rcPrintRect.right = iHorzRes - (((margins.left * iLogPixelsX / 2540) - 
iPhysPageX) + ((margins.right * iLogPixelsX / 2540) - (iPhysPageW - iPhysPageX 
- iHorzRes)));
+    rcPrintRect.bottom = iVertRes - (((margins.top * iLogPixelsY / 2540) - 
iPhysPageY) + ((margins.bottom * iLogPixelsY / 2540) - (iPhysPageH - iPhysPageY 
- iVertRes)));
+
+    return rcPrintRect;
+}
+
 static BOOL DoSaveFile(VOID)
 {
     BOOL bRet = TRUE;
@@ -518,7 +543,7 @@
     TEXTMETRIC tm;
     PRINTDLG printer;
     SIZE szMetric;
-    int cWidthPels, cHeightPels, border;
+    int border;
     int xLeft, yTop, pagecount, dopage, copycount;
     unsigned int i;
     LOGFONT hdrFont;
@@ -526,6 +551,7 @@
     DWORD size;
     LPTSTR pTemp;
     static const TCHAR times_new_roman[] = _T("Times New Roman");
+    RECT rcPrintRect;
 
     /* Get a small font and print some header info on each page */
     ZeroMemory(&hdrFont, sizeof(hdrFont));
@@ -591,9 +617,6 @@
         return;
     }
 
-    /* Get the page dimensions in pixels. */
-    cWidthPels = GetDeviceCaps(printer.hDC, HORZRES);
-    cHeightPels = GetDeviceCaps(printer.hDC, VERTRES);
 
     /* Get the file text */
     if (printer.Flags & PD_SELECTION)
@@ -623,13 +646,16 @@
         size = GetWindowText(Globals.hEdit, pTemp, size);
     }
 
+    /* Get the current printing area */
+    rcPrintRect = GetPrintingRect(printer.hDC, Globals.lMargins);
+
     /* Ensure that each logical unit maps to one pixel */
     SetMapMode(printer.hDC, MM_TEXT);
 
     /* Needed to get the correct height of a text line */
     GetTextMetrics(printer.hDC, &tm);
 
-    border = 150;
+    border = 15;
     for (copycount=1; copycount <= printer.nCopies; copycount++) {
         i = 0;
         pagecount = 1;
@@ -667,8 +693,11 @@
                     AlertPrintError();
                     return;
                 }
+
+                SetViewportOrgEx(printer.hDC, rcPrintRect.left, 
rcPrintRect.top, NULL);
+
                 /* Write a rectangle and header at the top of each page */
-                Rectangle(printer.hDC, border, border, cWidthPels-border, 
border + tm.tmHeight * 2);
+                Rectangle(printer.hDC, border, border, rcPrintRect.right - 
border, border + tm.tmHeight * 2);
                 /* I don't know what's up with this TextOut command. This 
comes out
                 kind of mangled.
                 */
@@ -680,7 +709,7 @@
             }
 
             /* The starting point for the main text */
-            xLeft = border * 2;
+            xLeft = 0;
             yTop = border + tm.tmHeight * 4;
 
             SelectObject(printer.hDC, old_font);
@@ -689,7 +718,7 @@
              * text one character at a time. */
             do {
                 if (pTemp[i] == '\n') {
-                    xLeft = border * 2;
+                    xLeft = 0;
                     yTop += tm.tmHeight;
                 }
                 else if (pTemp[i] != '\r') {
@@ -701,13 +730,13 @@
                     xLeft += szMetric.cx;
 
                     /* Insert a line break if the current line does not fit 
into the printing area */
-                    if (xLeft > (cWidthPels - border * 2))
+                    if (xLeft > rcPrintRect.right)
                     {
-                        xLeft = border * 2;
+                        xLeft = 0;
                         yTop = yTop + tm.tmHeight;
                     }
                 }
-            } while (i++ < size && yTop < (cHeightPels - border * 2));
+            } while (i++ < size && yTop < rcPrintRect.bottom);
 
             if (dopage)
                 EndPage(printer.hDC);
@@ -1184,10 +1213,7 @@
     page.hwndOwner = Globals.hMainWnd;
     page.Flags = PSD_ENABLEPAGESETUPTEMPLATE | PSD_ENABLEPAGESETUPHOOK | 
PSD_MARGINS;
     page.hInstance = Globals.hInstance;
-    page.rtMargin.left = Globals.lMarginLeft;
-    page.rtMargin.top = Globals.lMarginTop;
-    page.rtMargin.right = Globals.lMarginRight;
-    page.rtMargin.bottom = Globals.lMarginBottom;
+    page.rtMargin = Globals.lMargins;
     page.hDevMode = Globals.hDevMode;
     page.hDevNames = Globals.hDevNames;
     page.lpPageSetupTemplateName = MAKEINTRESOURCE(DIALOG_PAGESETUP);
@@ -1197,10 +1223,7 @@
 
     Globals.hDevMode = page.hDevMode;
     Globals.hDevNames = page.hDevNames;
-    Globals.lMarginLeft = page.rtMargin.left;
-    Globals.lMarginTop = page.rtMargin.top;
-    Globals.lMarginRight = page.rtMargin.right;
-    Globals.lMarginBottom = page.rtMargin.bottom;
+    Globals.lMargins = page.rtMargin;
 }
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Modified: trunk/reactos/base/applications/notepad/main.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/notepad/main.h?rev=69222&r1=69221&r2=69222&view=diff
==============================================================================
--- trunk/reactos/base/applications/notepad/main.h      [iso-8859-1] (original)
+++ trunk/reactos/base/applications/notepad/main.h      [iso-8859-1] Mon Sep 14 
09:32:57 2015
@@ -73,10 +73,7 @@
     TCHAR szFileName[MAX_PATH];
     TCHAR szFileTitle[MAX_PATH];
     TCHAR szFilter[2 * MAX_STRING_LEN + 100];
-    LONG lMarginTop;
-    LONG lMarginBottom;
-    LONG lMarginLeft;
-    LONG lMarginRight;
+    RECT lMargins;
     TCHAR szHeader[MAX_PATH];
     TCHAR szFooter[MAX_PATH];
     TCHAR szStatusBarLineCol[MAX_PATH];

Modified: trunk/reactos/base/applications/notepad/settings.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/notepad/settings.c?rev=69222&r1=69221&r2=69222&view=diff
==============================================================================
--- trunk/reactos/base/applications/notepad/settings.c  [iso-8859-1] (original)
+++ trunk/reactos/base/applications/notepad/settings.c  [iso-8859-1] Mon Sep 14 
09:32:57 2015
@@ -144,10 +144,10 @@
         QueryBool(hKey, _T("fStatusBar"), &Globals.bShowStatusBar);
         QueryString(hKey, _T("szHeader"), Globals.szHeader, 
ARRAY_SIZE(Globals.szHeader));
         QueryString(hKey, _T("szTrailer"), Globals.szFooter, 
ARRAY_SIZE(Globals.szFooter));
-        QueryDword(hKey, _T("iMarginLeft"), (DWORD*)&Globals.lMarginLeft);
-        QueryDword(hKey, _T("iMarginTop"), (DWORD*)&Globals.lMarginTop);
-        QueryDword(hKey, _T("iMarginRight"), (DWORD*)&Globals.lMarginRight);
-        QueryDword(hKey, _T("iMarginBottom"), (DWORD*)&Globals.lMarginBottom);
+        QueryDword(hKey, _T("iMarginLeft"), (DWORD*)&Globals.lMargins.left);
+        QueryDword(hKey, _T("iMarginTop"), (DWORD*)&Globals.lMargins.top);
+        QueryDword(hKey, _T("iMarginRight"), (DWORD*)&Globals.lMargins.right);
+        QueryDword(hKey, _T("iMarginBottom"), 
(DWORD*)&Globals.lMargins.bottom);
 
         QueryDword(hKey, _T("iWindowPosX"), (DWORD*)&Globals.main_rect.left);
         QueryDword(hKey, _T("iWindowPosY"), (DWORD*)&Globals.main_rect.top);
@@ -239,10 +239,10 @@
         SaveDword(hKey, _T("fStatusBar"), Globals.bShowStatusBar ? 1 : 0);
         SaveString(hKey, _T("szHeader"), Globals.szHeader);
         SaveString(hKey, _T("szTrailer"), Globals.szFooter);
-        SaveDword(hKey, _T("iMarginLeft"), Globals.lMarginLeft);
-        SaveDword(hKey, _T("iMarginTop"), Globals.lMarginTop);
-        SaveDword(hKey, _T("iMarginRight"), Globals.lMarginRight);
-        SaveDword(hKey, _T("iMarginBottom"), Globals.lMarginBottom);
+        SaveDword(hKey, _T("iMarginLeft"), Globals.lMargins.left);
+        SaveDword(hKey, _T("iMarginTop"), Globals.lMargins.top);
+        SaveDword(hKey, _T("iMarginRight"), Globals.lMargins.right);
+        SaveDword(hKey, _T("iMarginBottom"), Globals.lMargins.bottom);
         SaveDword(hKey, _T("iWindowPosX"), Globals.main_rect.left);
         SaveDword(hKey, _T("iWindowPosY"), Globals.main_rect.top);
         SaveDword(hKey, _T("iWindowPosDX"), Globals.main_rect.right - 
Globals.main_rect.left);


Reply via email to