home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2006 April / DPPRO0406DVD.ISO / Essentials / Programming / Notepad2 / Source / NP2SRC.ZIP / Print.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-06-25  |  17.4 KB  |  571 lines

  1. /******************************************************************************
  2. *
  3. *
  4. * Notepad2
  5. *
  6. * Print.cpp
  7. *   Scintilla Printing Functionality
  8. *   Mostly taken from SciTE, (c) Neil Hodgson, http://www.scintilla.org
  9. *
  10. * See Readme.txt for more information about this source code.
  11. * Please send me your comments to this work.
  12. *
  13. * Distributed under the terms of the GNU General Public License,
  14. * see License.txt for details.
  15. *
  16. *                                              (c) Florian Balmer 1996-2004
  17. *                                                       textview@bluewin.ch
  18. *                                               http://www.flos-freeware.ch
  19. *
  20. *
  21. ******************************************************************************/
  22. #include <windows.h>
  23. #include <commctrl.h>
  24. #include <commdlg.h>
  25. #include <string.h>
  26. #include "platform.h"
  27. #include "scintilla.h"
  28. #include "scilexer.h"
  29. extern "C" {
  30. #include "dialogs.h"
  31. #include "helpers.h"
  32. }
  33. #include "resource.h"
  34.  
  35.  
  36. extern "C" HINSTANCE g_hInstance;
  37.  
  38.  
  39. // Global settings...
  40. extern "C" int iPrintHeader;
  41. extern "C" int iPrintFooter;
  42. extern "C" int iPrintZoom;
  43. extern "C" RECT pagesetupMargin;
  44.  
  45.  
  46. // Stored objects...
  47. HGLOBAL hDevMode = NULL;
  48. HGLOBAL hDevNames = NULL;
  49.  
  50.  
  51. //=============================================================================
  52. //
  53. //  EditPrint() - Code from SciTE
  54. //
  55. extern "C" HWND hwndStatus;
  56.  
  57. void StatusUpdatePrintPage(int iPageNum)
  58. {
  59.   char tch[32];
  60.  
  61.   FormatString(tch,COUNTOF(tch),IDS_PRINTFILE,iPageNum);
  62.  
  63.   StatusSetText(hwndStatus,255,tch);
  64.   StatusSetSimple(hwndStatus,TRUE);
  65.  
  66.   InvalidateRect(hwndStatus,NULL,TRUE);
  67.   UpdateWindow(hwndStatus);
  68. }
  69.  
  70.  
  71. extern "C" BOOL EditPrint(HWND hwnd,LPCSTR pszDocTitle,LPCSTR pszPageFormat)
  72. {
  73.  
  74.   // Don't print empty documents
  75.   if (SendMessage(hwnd,SCI_GETLENGTH,0,0) == 0) {
  76.     MsgBox(MBINFO,IDS_PRINT_EMPTY);
  77.     return TRUE; }
  78.  
  79.   int startPos;
  80.   int endPos;
  81.  
  82.   HDC hdc;
  83.  
  84.   RECT rectMargins;
  85.   RECT rectPhysMargins;
  86.   RECT rectSetup;
  87.   POINT ptPage;
  88.   POINT ptDpi;
  89.  
  90.   //RECT rectSetup;
  91.  
  92.   TEXTMETRIC tm;
  93.  
  94.   int headerLineHeight;
  95.   HFONT fontHeader;
  96.  
  97.   int footerLineHeight;
  98.   HFONT fontFooter;
  99.  
  100.   char dateString[256];
  101.  
  102.   DOCINFO di = {sizeof(DOCINFO), 0, 0, 0, 0};
  103.  
  104.   LONG lengthDoc;
  105.   LONG lengthDocMax;
  106.   LONG lengthPrinted;
  107.  
  108.   struct RangeToFormat frPrint;
  109.  
  110.   int pageNum;
  111.   BOOL printPage;
  112.  
  113.   char pageString[32];
  114.  
  115.   HPEN pen;
  116.   HPEN penOld;
  117.  
  118.   PRINTDLG pdlg = {
  119.                       sizeof(PRINTDLG), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  120.                   };
  121.   pdlg.hwndOwner = GetParent(hwnd);
  122.   pdlg.hInstance = g_hInstance;
  123.   pdlg.Flags = PD_USEDEVMODECOPIES | PD_ALLPAGES | PD_RETURNDC;
  124.   pdlg.nFromPage = 1;
  125.   pdlg.nToPage = 1;
  126.   pdlg.nMinPage = 1;
  127.   pdlg.nMaxPage = 0xffffU;
  128.   pdlg.nCopies = 1;
  129.   pdlg.hDC = 0;
  130.   pdlg.hDevMode = hDevMode;
  131.   pdlg.hDevNames = hDevNames;
  132.  
  133.   startPos = SendMessage(hwnd,SCI_GETSELECTIONSTART,0,0);;
  134.   endPos = SendMessage(hwnd,SCI_GETSELECTIONEND,0,0);
  135.  
  136.   if (startPos == endPos) {
  137.     pdlg.Flags |= PD_NOSELECTION;
  138.   } else {
  139.     pdlg.Flags |= PD_SELECTION;
  140.   }
  141.   if (0) {
  142.     // Don't display dialog box, just use the default printer and options
  143.     pdlg.Flags |= PD_RETURNDEFAULT;
  144.   }
  145.   if (!PrintDlg(&pdlg)) {
  146.     return TRUE; // False means error...
  147.   }
  148.  
  149.   hDevMode = pdlg.hDevMode;
  150.   hDevNames = pdlg.hDevNames;
  151.  
  152.   hdc = pdlg.hDC;
  153.  
  154.   // Get printer resolution
  155.   ptDpi.x = GetDeviceCaps(hdc, LOGPIXELSX);    // dpi in X direction
  156.   ptDpi.y = GetDeviceCaps(hdc, LOGPIXELSY);    // dpi in Y direction
  157.  
  158.   // Start by getting the physical page size (in device units).
  159.   ptPage.x = GetDeviceCaps(hdc, PHYSICALWIDTH);   // device units
  160.   ptPage.y = GetDeviceCaps(hdc, PHYSICALHEIGHT);  // device units
  161.  
  162.   // Get the dimensions of the unprintable
  163.   // part of the page (in device units).
  164.   rectPhysMargins.left = GetDeviceCaps(hdc, PHYSICALOFFSETX);
  165.   rectPhysMargins.top = GetDeviceCaps(hdc, PHYSICALOFFSETY);
  166.  
  167.   // To get the right and lower unprintable area,
  168.   // we take the entire width and height of the paper and
  169.   // subtract everything else.
  170.   rectPhysMargins.right = ptPage.x            // total paper width
  171.                           - GetDeviceCaps(hdc, HORZRES) // printable width
  172.                           - rectPhysMargins.left;        // left unprintable margin
  173.  
  174.   rectPhysMargins.bottom = ptPage.y            // total paper height
  175.                            - GetDeviceCaps(hdc, VERTRES)  // printable height
  176.                            - rectPhysMargins.top;        // right unprintable margin
  177.  
  178.   // At this point, rectPhysMargins contains the widths of the
  179.   // unprintable regions on all four sides of the page in device units.
  180.  
  181.   // Take in account the page setup given by the user (if one value is not null)
  182.   if (pagesetupMargin.left != 0 || pagesetupMargin.right != 0 ||
  183.           pagesetupMargin.top != 0 || pagesetupMargin.bottom != 0) {
  184.  
  185.     // Convert the hundredths of millimeters (HiMetric) or
  186.     // thousandths of inches (HiEnglish) margin values
  187.     // from the Page Setup dialog to device units.
  188.     // (There are 2540 hundredths of a mm in an inch.)
  189.  
  190.     char localeInfo[3];
  191.     GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, localeInfo, 3);
  192.  
  193.     if (localeInfo[0] == '0') {  // Metric system. '1' is US System
  194.       rectSetup.left = MulDiv (pagesetupMargin.left, ptDpi.x, 2540);
  195.       rectSetup.top = MulDiv (pagesetupMargin.top, ptDpi.y, 2540);
  196.       rectSetup.right  = MulDiv(pagesetupMargin.right, ptDpi.x, 2540);
  197.       rectSetup.bottom  = MulDiv(pagesetupMargin.bottom, ptDpi.y, 2540);
  198.     } else {
  199.       rectSetup.left  = MulDiv(pagesetupMargin.left, ptDpi.x, 1000);
  200.       rectSetup.top  = MulDiv(pagesetupMargin.top, ptDpi.y, 1000);
  201.       rectSetup.right  = MulDiv(pagesetupMargin.right, ptDpi.x, 1000);
  202.       rectSetup.bottom  = MulDiv(pagesetupMargin.bottom, ptDpi.y, 1000);
  203.     }
  204.  
  205.     // Dont reduce margins below the minimum printable area
  206.     rectMargins.left  = max(rectPhysMargins.left, rectSetup.left);
  207.     rectMargins.top  = max(rectPhysMargins.top, rectSetup.top);
  208.     rectMargins.right  = max(rectPhysMargins.right, rectSetup.right);
  209.     rectMargins.bottom  = max(rectPhysMargins.bottom, rectSetup.bottom);
  210.   } else {
  211.     rectMargins.left  = rectPhysMargins.left;
  212.     rectMargins.top  = rectPhysMargins.top;
  213.     rectMargins.right  = rectPhysMargins.right;
  214.     rectMargins.bottom  = rectPhysMargins.bottom;
  215.   }
  216.  
  217.   // rectMargins now contains the values used to shrink the printable
  218.   // area of the page.
  219.  
  220.   // Convert device coordinates into logical coordinates
  221.   DPtoLP(hdc, (LPPOINT)&rectMargins, 2);
  222.   DPtoLP(hdc, (LPPOINT)&rectPhysMargins, 2);
  223.  
  224.   // Convert page size to logical units and we're done!
  225.   DPtoLP(hdc, (LPPOINT) &ptPage, 1);
  226.  
  227.   headerLineHeight = MulDiv(10,ptDpi.y, 72);
  228.   fontHeader = CreateFont(headerLineHeight,
  229.                           0, 0, 0,
  230.                           FW_BOLD,
  231.                           0,
  232.                           0,
  233.                           0, 0, 0,
  234.                           0, 0, 0,
  235.                           "Arial");
  236.   SelectObject(hdc, fontHeader);
  237.   GetTextMetrics(hdc, &tm);
  238.   headerLineHeight = tm.tmHeight + tm.tmExternalLeading;
  239.  
  240.   footerLineHeight = MulDiv(9,ptDpi.y, 72);
  241.   fontFooter = CreateFont(footerLineHeight,
  242.                           0, 0, 0,
  243.                           FW_NORMAL,
  244.                           0,
  245.                           0,
  246.                           0, 0, 0,
  247.                           0, 0, 0,
  248.                           "Arial");
  249.   SelectObject(hdc, fontFooter);
  250.   GetTextMetrics(hdc, &tm);
  251.   footerLineHeight = tm.tmHeight + tm.tmExternalLeading;
  252.  
  253.   di.lpszDocName = pszDocTitle;
  254.   di.lpszOutput = 0;
  255.   di.lpszDatatype = 0;
  256.   di.fwType = 0;
  257.   if (StartDoc(hdc, &di) < 0) {
  258.     return FALSE;
  259.   }
  260.  
  261.   // Get current date...
  262.   SYSTEMTIME st;
  263.   GetLocalTime(&st);
  264.   GetDateFormat(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&st,NULL,dateString,256);
  265.  
  266.   // Get current time...
  267.   if (iPrintHeader == 0)
  268.   {
  269.     char timeString[128];
  270.     GetTimeFormat(LOCALE_USER_DEFAULT,TIME_NOSECONDS,&st,NULL,timeString,128);
  271.     lstrcat(dateString," ");
  272.     lstrcat(dateString,timeString);
  273.   }
  274.  
  275.   // Set print zoom...
  276.   SendMessage(hwnd,SCI_SETPRINTMAGNIFICATION,(WPARAM)iPrintZoom,0);
  277.  
  278.   lengthDoc = SendMessage(hwnd,SCI_GETLENGTH,0,0);
  279.   lengthDocMax = lengthDoc;
  280.   lengthPrinted = 0;
  281.  
  282.   // Requested to print selection
  283.   if (pdlg.Flags & PD_SELECTION) {
  284.     if (startPos > endPos) {
  285.       lengthPrinted = endPos;
  286.       lengthDoc = startPos;
  287.     } else {
  288.       lengthPrinted = startPos;
  289.       lengthDoc = endPos;
  290.     }
  291.  
  292.     if (lengthPrinted < 0)
  293.       lengthPrinted = 0;
  294.     if (lengthDoc > lengthDocMax)
  295.       lengthDoc = lengthDocMax;
  296.   }
  297.  
  298.   // We must substract the physical margins from the printable area
  299.   frPrint.hdc = hdc;
  300.   frPrint.hdcTarget = hdc;
  301.   frPrint.rc.left = rectMargins.left - rectPhysMargins.left;
  302.   frPrint.rc.top = rectMargins.top - rectPhysMargins.top;
  303.   frPrint.rc.right = ptPage.x - rectMargins.right - rectPhysMargins.left;
  304.   frPrint.rc.bottom = ptPage.y - rectMargins.bottom - rectPhysMargins.top;
  305.   frPrint.rcPage.left = 0;
  306.   frPrint.rcPage.top = 0;
  307.   frPrint.rcPage.right = ptPage.x - rectPhysMargins.left - rectPhysMargins.right - 1;
  308.   frPrint.rcPage.bottom = ptPage.y - rectPhysMargins.top - rectPhysMargins.bottom - 1;
  309.   frPrint.rc.top += headerLineHeight + headerLineHeight / 2;
  310.   frPrint.rc.bottom -= footerLineHeight + footerLineHeight / 2;
  311.   // Print each page
  312.   pageNum = 1;
  313.  
  314.   //PropSet propsPrint;
  315.   //propsPrint.superPS = &props;
  316.   //SetFileProperties(propsPrint);
  317.  
  318.   while (lengthPrinted < lengthDoc) {
  319.     printPage = (!(pdlg.Flags & PD_PAGENUMS) ||
  320.                  (pageNum >= pdlg.nFromPage) && (pageNum <= pdlg.nToPage));
  321.  
  322.     wsprintf(pageString, pszPageFormat, pageNum);
  323.     //propsPrint.Set("CurrentPage", pageString);
  324.  
  325.     if (printPage) {
  326.  
  327.       // Show wait cursor...
  328.       SendMessage(hwnd,SCI_SETCURSOR,SC_CURSORWAIT,0);
  329.  
  330.       // Display current page number in Statusbar
  331.       StatusUpdatePrintPage(pageNum);
  332.  
  333.       StartPage(hdc);
  334.  
  335.       SetTextColor(hdc, RGB(0,0,0));
  336.       SetBkColor(hdc, RGB(255,255,255));
  337.       SelectObject(hdc, fontHeader);
  338.       UINT ta = SetTextAlign(hdc, TA_BOTTOM);
  339.       RECT rcw = {frPrint.rc.left, frPrint.rc.top - headerLineHeight - headerLineHeight / 2,
  340.                   frPrint.rc.right, frPrint.rc.top - headerLineHeight / 2};
  341.       rcw.bottom = rcw.top + headerLineHeight;
  342.  
  343.       if (iPrintHeader < 3)
  344.       {
  345.         ExtTextOut(hdc, frPrint.rc.left + 5, frPrint.rc.top - headerLineHeight / 2,
  346.                       /*ETO_OPAQUE*/0, &rcw, pszDocTitle,
  347.                       lstrlen(pszDocTitle), NULL);
  348.       }
  349.  
  350.       // Print date in header
  351.       if (iPrintHeader == 0 || iPrintHeader == 1)
  352.       {
  353.         SIZE sizeInfo;
  354.         SelectObject(hdc,fontFooter);
  355.         GetTextExtentPoint32(hdc,dateString,lstrlen(dateString),&sizeInfo);
  356.         ExtTextOut(hdc, frPrint.rc.right - 5 - sizeInfo.cx, frPrint.rc.top - headerLineHeight / 2,
  357.                       /*ETO_OPAQUE*/0, &rcw, dateString,
  358.                       lstrlen(dateString), NULL);
  359.       }
  360.  
  361.       SetTextAlign(hdc, ta);
  362.       pen = CreatePen(0, 1, RGB(0,0,0));
  363.       penOld = (HPEN)SelectObject(hdc, pen);
  364.       MoveToEx(hdc, frPrint.rc.left, frPrint.rc.top - headerLineHeight / 4, NULL);
  365.       LineTo(hdc, frPrint.rc.right, frPrint.rc.top - headerLineHeight / 4);
  366.       SelectObject(hdc, penOld);
  367.       DeleteObject(pen);
  368.     }
  369.  
  370.     frPrint.chrg.cpMin = lengthPrinted;
  371.     frPrint.chrg.cpMax = lengthDoc;
  372.  
  373.     lengthPrinted = SendMessage(hwnd,SCI_FORMATRANGE,printPage,(LPARAM)&frPrint);
  374.  
  375.     if (printPage) {
  376.       SetTextColor(hdc, RGB(0,0,0));
  377.       SetBkColor(hdc, RGB(255,255,255));
  378.       SelectObject(hdc, fontFooter);
  379.       UINT ta = SetTextAlign(hdc, TA_TOP);
  380.       RECT rcw = {frPrint.rc.left, frPrint.rc.bottom + footerLineHeight / 2,
  381.                   frPrint.rc.right, frPrint.rc.bottom + footerLineHeight + footerLineHeight / 2};
  382.  
  383.       if (iPrintFooter == 0)
  384.       {
  385.         SIZE sizeFooter;
  386.         GetTextExtentPoint32(hdc,pageString,lstrlen(pageString),&sizeFooter);
  387.         ExtTextOut(hdc, frPrint.rc.right - 5 - sizeFooter.cx, frPrint.rc.bottom + footerLineHeight / 2,
  388.                       /*ETO_OPAQUE*/0, &rcw, pageString,
  389.                       lstrlen(pageString), NULL);
  390.       }
  391.  
  392.       SetTextAlign(hdc, ta);
  393.       pen = ::CreatePen(0, 1, RGB(0,0,0));
  394.       penOld = (HPEN)SelectObject(hdc, pen);
  395.       SetBkColor(hdc, RGB(0,0,0));
  396.       MoveToEx(hdc, frPrint.rc.left, frPrint.rc.bottom + footerLineHeight / 4, NULL);
  397.       LineTo(hdc, frPrint.rc.right, frPrint.rc.bottom + footerLineHeight / 4);
  398.       SelectObject(hdc, penOld);
  399.       DeleteObject(pen);
  400.  
  401.       EndPage(hdc);
  402.     }
  403.     pageNum++;
  404.  
  405.     if ((pdlg.Flags & PD_PAGENUMS) && (pageNum > pdlg.nToPage))
  406.       break;
  407.   }
  408.  
  409.   SendMessage(hwnd,SCI_FORMATRANGE, FALSE, 0);
  410.  
  411.   EndDoc(hdc);
  412.   DeleteDC(hdc);
  413.   if (fontHeader) {
  414.     DeleteObject(fontHeader);
  415.   }
  416.   if (fontFooter) {
  417.     DeleteObject(fontFooter);
  418.   }
  419.  
  420.   // Reset Statusbar to default mode
  421.   StatusSetSimple(hwndStatus,FALSE);
  422.  
  423.   // Remove wait cursor...
  424.   SendMessage(hwnd,SCI_SETCURSOR,SC_CURSORNORMAL,0);
  425.  
  426.   return TRUE;
  427. }
  428.  
  429.  
  430. //=============================================================================
  431. //
  432. //  EditPrintSetup() - Code from SciTE
  433. //
  434. //  Custom controls: 30 Zoom
  435. //                   31 Spin
  436. //                   32 Header
  437. //                   33 Footer
  438. //
  439. extern "C" UINT_PTR CALLBACK PageSetupHook(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
  440. {
  441.   switch (uiMsg)
  442.   {
  443.     case WM_INITDIALOG:
  444.       {
  445.         char tch[512];
  446.         char *p1,*p2;
  447.  
  448.         SendDlgItemMessage(hwnd,30,EM_LIMITTEXT,32,0);
  449.  
  450.         SendDlgItemMessage(hwnd,31,UDM_SETRANGE,0,MAKELONG((short)20,(short)-10));
  451.         SendDlgItemMessage(hwnd,31,UDM_SETPOS,0,MAKELONG((short)iPrintZoom,0));
  452.  
  453.         // Set header options
  454.         GetString(IDS_PRINT_HEADER,tch,COUNTOF(tch));
  455.         lstrcat(tch,"|");
  456.         p1 = tch;
  457.         while (p2 = strchr(p1,'|')) {
  458.           *p2++ = '\0';
  459.           if (*p1)
  460.             SendDlgItemMessage(hwnd,32,CB_ADDSTRING,0,(LPARAM)p1);
  461.           p1 = p2; }
  462.         SendDlgItemMessage(hwnd,32,CB_SETCURSEL,(WPARAM)iPrintHeader,0);
  463.  
  464.         // Set footer options
  465.         GetString(IDS_PRINT_FOOTER,tch,COUNTOF(tch));
  466.         lstrcat(tch,"|");
  467.         p1 = tch;
  468.         while (p2 = strchr(p1,'|')) {
  469.           *p2++ = '\0';
  470.           if (*p1)
  471.             SendDlgItemMessage(hwnd,33,CB_ADDSTRING,0,(LPARAM)p1);
  472.           p1 = p2; }
  473.         SendDlgItemMessage(hwnd,33,CB_SETCURSEL,(WPARAM)iPrintFooter,0);
  474.  
  475.         // Make combos handier
  476.         SendDlgItemMessage(hwnd,32,CB_SETEXTENDEDUI,TRUE,0);
  477.         SendDlgItemMessage(hwnd,33,CB_SETEXTENDEDUI,TRUE,0);
  478.         SendDlgItemMessage(hwnd,1137,CB_SETEXTENDEDUI,TRUE,0);
  479.         SendDlgItemMessage(hwnd,1138,CB_SETEXTENDEDUI,TRUE,0);
  480.       }
  481.       break;
  482.  
  483.     case WM_COMMAND:
  484.       if (LOWORD(wParam) == IDOK)
  485.       {
  486.         LONG lPos = SendDlgItemMessage(hwnd,31,UDM_GETPOS,0,0);
  487.         if (HIWORD(lPos) == 0)
  488.           iPrintZoom = (int)(short)LOWORD(lPos);
  489.         else
  490.           iPrintZoom = 0;
  491.  
  492.         iPrintHeader = SendDlgItemMessage(hwnd,32,CB_GETCURSEL,0,0);
  493.         iPrintFooter = SendDlgItemMessage(hwnd,33,CB_GETCURSEL,0,0);
  494.       }
  495.       break;
  496.  
  497.     default:
  498.       break;
  499.   }
  500.   return(0);
  501. }
  502.  
  503.  
  504. extern "C" void EditPrintSetup(HWND hwnd)
  505. {
  506.   PAGESETUPDLG pdlg = {
  507.                           sizeof(PAGESETUPDLG), 0, 0, 0, 0, {0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0
  508.                       };
  509.  
  510.   pdlg.Flags = PSD_ENABLEPAGESETUPHOOK | PSD_ENABLEPAGESETUPTEMPLATE;
  511.   pdlg.lpfnPageSetupHook = PageSetupHook;
  512.   pdlg.lpPageSetupTemplateName = MAKEINTRESOURCE(IDD_PAGESETUP);
  513.  
  514.   pdlg.hwndOwner = GetParent(hwnd);
  515.   pdlg.hInstance = g_hInstance;
  516.  
  517.   if (pagesetupMargin.left != 0 || pagesetupMargin.right != 0 ||
  518.           pagesetupMargin.top != 0 || pagesetupMargin.bottom != 0) {
  519.     pdlg.Flags |= PSD_MARGINS;
  520.  
  521.     pdlg.rtMargin.left = pagesetupMargin.left;
  522.     pdlg.rtMargin.top = pagesetupMargin.top;
  523.     pdlg.rtMargin.right = pagesetupMargin.right;
  524.     pdlg.rtMargin.bottom = pagesetupMargin.bottom;
  525.   }
  526.  
  527.   pdlg.hDevMode = hDevMode;
  528.   pdlg.hDevNames = hDevNames;
  529.  
  530.   if (!PageSetupDlg(&pdlg))
  531.     return;
  532.  
  533.   pagesetupMargin.left = pdlg.rtMargin.left;
  534.   pagesetupMargin.top = pdlg.rtMargin.top;
  535.   pagesetupMargin.right = pdlg.rtMargin.right;
  536.   pagesetupMargin.bottom = pdlg.rtMargin.bottom;
  537.  
  538.   hDevMode = pdlg.hDevMode;
  539.   hDevNames = pdlg.hDevNames;
  540. }
  541.  
  542.  
  543. //=============================================================================
  544. //
  545. //  EditPrintInit() - Setup default page margin if no values from registry
  546. //
  547. extern "C" void EditPrintInit()
  548. {
  549.   if (pagesetupMargin.left == 0 || pagesetupMargin.top == 0 ||
  550.       pagesetupMargin.right == 0 || pagesetupMargin.bottom == 0)
  551.   {
  552.     char localeInfo[3];
  553.     GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, localeInfo, 3);
  554.  
  555.     if (localeInfo[0] == '0') {  // Metric system. '1' is US System
  556.       pagesetupMargin.left = 2000;
  557.       pagesetupMargin.top = 2000;
  558.       pagesetupMargin.right = 2000;
  559.       pagesetupMargin.bottom = 2000; }
  560.  
  561.     else {
  562.       pagesetupMargin.left = 1000;
  563.       pagesetupMargin.top = 1000;
  564.       pagesetupMargin.right = 1000;
  565.       pagesetupMargin.bottom = 1000; }
  566.   }
  567. }
  568.  
  569.  
  570. // End of Print.cpp
  571.