示例#1
0
/*------------------------------------------------------------------------
 Procedure:     CallPrintSetup ID:1
 Purpose:       Calls the printer setup dialog. Currently it is not
                connected to the rest of the software, since printing
                is not done yet
 Input:         None
 Output:        1 if OK, 0, user cancelled
 Errors:        None
------------------------------------------------------------------------*/
static int CallPrintSetup(void)
{
        PAGESETUPDLG sd;
        int r;

        memset(&sd,0,sizeof(sd));
        sd.lStructSize = sizeof(sd);
        sd.Flags = PSD_RETURNDEFAULT;
        r = PageSetupDlg(&sd);
        if (!r)
                return 0;
        sd.Flags = 0;
        r = PageSetupDlg(&sd);
        return r;
}
示例#2
0
文件: dialog.c 项目: RPG-7/reactos
/***********************************************************************
 *
 *           DIALOG_FilePageSetup
 */
VOID DIALOG_FilePageSetup(void)
{
    PAGESETUPDLG page;

    ZeroMemory(&page, sizeof(page));
    page.lStructSize = sizeof(page);
    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.hDevMode = Globals.hDevMode;
    page.hDevNames = Globals.hDevNames;
    page.lpPageSetupTemplateName = MAKEINTRESOURCE(DIALOG_PAGESETUP);
    page.lpfnPageSetupHook = DIALOG_PAGESETUP_Hook;

    PageSetupDlg(&page);

    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;
}
示例#3
0
int wxWindowsPageSetupDialog::ShowModal()
{
    ConvertToNative( m_pageSetupData );

    PAGESETUPDLG *pd = (PAGESETUPDLG *) m_pageDlg;
    if (m_dialogParent)
        pd->hwndOwner = (HWND) m_dialogParent->GetHWND();
    else if (wxTheApp->GetTopWindow())
        pd->hwndOwner = (HWND) wxTheApp->GetTopWindow()->GetHWND();
    else
        pd->hwndOwner = 0;
    BOOL retVal = PageSetupDlg( pd ) ;
    pd->hwndOwner = 0;
    if (retVal)
    {
        ConvertFromNative( m_pageSetupData );
        return wxID_OK;
    }
    else
        return wxID_CANCEL;
}
示例#4
0
文件: Print.cpp 项目: gencer/Notepad3
extern "C" void EditPrintSetup(HWND hwnd)
{
  DLGTEMPLATE* pDlgTemplate =
    LoadThemedDialogTemplate(MAKEINTRESOURCE(IDD_PAGESETUP),g_hInstance);

  PAGESETUPDLG pdlg;
  ZeroMemory(&pdlg,sizeof(PAGESETUPDLG));
  pdlg.lStructSize = sizeof(PAGESETUPDLG);
  pdlg.Flags = PSD_ENABLEPAGESETUPHOOK | PSD_ENABLEPAGESETUPTEMPLATEHANDLE;
  pdlg.lpfnPageSetupHook = PageSetupHook;
  pdlg.hPageSetupTemplate = pDlgTemplate;
  pdlg.hwndOwner = GetParent(hwnd);
  pdlg.hInstance = g_hInstance;

  if (pagesetupMargin.left != 0 || pagesetupMargin.right != 0 ||
          pagesetupMargin.top != 0 || pagesetupMargin.bottom != 0) {
    pdlg.Flags |= PSD_MARGINS;

    pdlg.rtMargin.left = pagesetupMargin.left;
    pdlg.rtMargin.top = pagesetupMargin.top;
    pdlg.rtMargin.right = pagesetupMargin.right;
    pdlg.rtMargin.bottom = pagesetupMargin.bottom;
  }

  pdlg.hDevMode = hDevMode;
  pdlg.hDevNames = hDevNames;

  if (PageSetupDlg(&pdlg)) {

    pagesetupMargin.left = pdlg.rtMargin.left;
    pagesetupMargin.top = pdlg.rtMargin.top;
    pagesetupMargin.right = pdlg.rtMargin.right;
    pagesetupMargin.bottom = pdlg.rtMargin.bottom;

    hDevMode = pdlg.hDevMode;
    hDevNames = pdlg.hDevNames;
  }

  LocalFree(pDlgTemplate);
}
示例#5
0
static int
winprint_page_setup_command (ClientData cd, Tcl_Interp *interp, int argc,
			     char **argv)
{
  struct winprint_data *wd = (struct winprint_data *) cd;
  Tk_Window parent;
  int i, mode, ret;
  PAGESETUPDLG psd;

  parent = Tk_MainWindow (interp);

  for (i = 2; i < argc; i += 2)
    {
      if (i + 1 >= argc)
	{
	  Tcl_ResetResult (interp);
	  Tcl_AppendStringsToObj (Tcl_GetObjResult (interp),
				  "value for \"", argv[i], "\" missing",
				  (char *) NULL);
	  return TCL_ERROR;
	}

      if (strcmp (argv[i], "-parent") == 0)
	{
	  parent = Tk_NameToWindow (interp, argv[i + 1],
				    Tk_MainWindow (interp));
	  if (parent == NULL)
	    return TCL_ERROR;
	}
      else
	{
	  Tcl_ResetResult (interp);
	  Tcl_AppendStringsToObj (Tcl_GetObjResult (interp),
				  "unknown option \"", argv[i], "\"",
				  (char *) NULL);
	  return TCL_ERROR;
	}
    }

  if (wd->page_setup != NULL)
    psd = *wd->page_setup;
  else
    {
      memset (&psd, 0, sizeof (PAGESETUPDLG));
      psd.lStructSize = sizeof (PAGESETUPDLG);
      psd.Flags = PSD_DEFAULTMINMARGINS;
    }

  if (Tk_WindowId (parent) == None)
    Tk_MakeWindowExist (parent);
  psd.hwndOwner = Tk_GetHWND (Tk_WindowId (parent));

  mode = Tcl_SetServiceMode (TCL_SERVICE_ALL);

  ret = PageSetupDlg (&psd);

  (void) Tcl_SetServiceMode (mode);

  if (! ret)
    {
      DWORD code;

      code = CommDlgExtendedError ();
      if (code == 0)
	{
	  /* The user pressed cancel.  */
	  return TCL_OK;
	}
      else
	{
	  char buf[20];

	  sprintf (buf, "0x%lx", (unsigned long) code);
	  Tcl_ResetResult (interp);
	  Tcl_AppendStringsToObj (Tcl_GetObjResult (interp),
				  "Windows common dialog error ", buf,
				  (char *) NULL);
	  return TCL_ERROR;
	}
    }

  if (wd->page_setup == NULL)
    wd->page_setup = (PAGESETUPDLG *) ckalloc (sizeof (PAGESETUPDLG));

  *wd->page_setup = psd;

  return TCL_OK;
}
int QPageSetupDialog::exec()
{
    Q_D(QPageSetupDialog);

    if (d->printer->outputFormat() != QPrinter::NativeFormat)
        return Rejected;

    QWin32PrintEngine *engine = static_cast<QWin32PrintEngine*>(d->printer->paintEngine());
    QWin32PrintEnginePrivate *ep = static_cast<QWin32PrintEnginePrivate *>(engine->d_ptr.data());

    PAGESETUPDLG psd;
    memset(&psd, 0, sizeof(PAGESETUPDLG));
    psd.lStructSize = sizeof(PAGESETUPDLG);

    // we need a temp DEVMODE struct if we don't have a global DEVMODE
    HGLOBAL hDevMode = 0;
    int devModeSize = 0;
    if (!ep->globalDevMode) {
        devModeSize = sizeof(DEVMODE) + ep->devMode->dmDriverExtra;
        hDevMode = GlobalAlloc(GHND, devModeSize);
        if (hDevMode) {
            void *dest = GlobalLock(hDevMode);
            memcpy(dest, ep->devMode, devModeSize);
            GlobalUnlock(hDevMode);
        }
        psd.hDevMode = hDevMode;
    } else {
        psd.hDevMode = ep->devMode;
    }

    HGLOBAL *tempDevNames = ep->createDevNames();
    psd.hDevNames = tempDevNames;

    QWidget *parent = parentWidget();
    parent = parent ? parent->window() : QApplication::activeWindow();
    Q_ASSERT(!parent ||parent->testAttribute(Qt::WA_WState_Created));
    psd.hwndOwner = parent ? parent->winId() : 0;

    QRect paperRect = d->printer->paperRect();
    QRect pageRect = d->printer->pageRect();

    psd.Flags = PSD_MARGINS;
    double multiplier = 1;
    switch (QLocale::system().measurementSystem()) {
    case QLocale::MetricSystem:
        psd.Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
        multiplier = 1;
        break;
    case QLocale::ImperialSystem:
        psd.Flags |= PSD_INTHOUSANDTHSOFINCHES;
        multiplier = 25.4/10;
        break;
    }

    QRect marginRect = ep->getPageMargins();
    psd.rtMargin.left   = marginRect.left()   / multiplier;
    psd.rtMargin.top    = marginRect.top()    / multiplier;
    psd.rtMargin.right  = marginRect.width()  / multiplier;;
    psd.rtMargin.bottom = marginRect.height() / multiplier;;

    bool result = PageSetupDlg(&psd);
    if (result) {
        ep->readDevnames(psd.hDevNames);
        ep->readDevmode(psd.hDevMode);

        QRect theseMargins = QRect(psd.rtMargin.left   * multiplier,
                                   psd.rtMargin.top    * multiplier,
                                   psd.rtMargin.right  * multiplier,
                                   psd.rtMargin.bottom * multiplier);

        if (theseMargins != marginRect) {
            ep->setPageMargins(psd.rtMargin.left   * multiplier,
                               psd.rtMargin.top    * multiplier,
                               psd.rtMargin.right  * multiplier,
                               psd.rtMargin.bottom * multiplier);
        }

        ep->updateCustomPaperSize();

        // copy from our temp DEVMODE struct
        if (!ep->globalDevMode && hDevMode) {
            void *src = GlobalLock(hDevMode);
            memcpy(ep->devMode, src, devModeSize);
            GlobalUnlock(hDevMode);
        }
    }

    if (!ep->globalDevMode && hDevMode)
        GlobalFree(hDevMode);
    GlobalFree(tempDevNames);
    done(result);
    return result;
}
示例#7
0
boolean shellinitprint (void) {
	
	/*
	 9/5/90 dmb: close print resources after initializing stuff
	 
	 10/21/91 dmb: added margins field to print info; structure is now here to 
	 have user-settable margins.
	 
	 12/31/91 dmb: initialize shellprintinfo.paperrect to standard 72dpi values in 
	 case no printer is chosen and shellcopyprintinfo never gets called
	 
	 1/18/93 dmb: don't call shellcheckprinterror the first time; if PrOpen fails 
	 here, we don't want to raise an alert.
	 */
	
#if MACVERSION && !TARGET_API_MAC_CARBON
	
	Handle h;
	
#endif
	
	currentprintport = NULL;
	
	clearbytes (&shellprintinfo, longsizeof (shellprintinfo));
	
	setrect (&shellprintinfo.margins, 36, 36, 36, 36);
	
	setrect (&shellprintinfo.paperrect, 5, 6, 725, 546); /*defaults in case PrOpen fails*/
	
	shellprintinfo.scaleMult = 1;
	shellprintinfo.scaleDiv = 1;
	
#ifdef MACVERSION
	
#	if TARGET_API_MAC_CARBON == 1
	
	//I realized this is only called once during the startup of the app.
	//Carbon printing really doesn't need any global structures. Better to 
	//allocate them as we use them.
	
	// Nope.
	// We need a global var for calling page setup
	
	shellprintinfo.printport = nil;
	shellprintinfo.printhandle = nil;
	shellprintinfo.pageformat = nil;
	shellprintinfo.printsettings = nil;
	// shellprintinfo.pagerect = {0,0,0,0};
	
#	else		
	
	if (!newclearhandle (longsizeof (TPrint), &h))
		return (false);
	
	shellprintinfo.printhandle = (THPrint) h; /*copy into print record*/
	
	PrOpen (); /*initialize the Mac print manager*/
	
	if (PrError () != noErr)
		goto error;
	
	PrintDefault (shellprintinfo.printhandle); /*set default print record*/
	
	PrClose (); /*shouldn't leave print resources open all the time*/
	
	if (!shellcheckprinterror (false)) 
		goto error;
#	endif
	
#endif
	
#ifdef WIN95VERSION
	
	ZeroMemory (&shellprintinfo.pagesetupinfo, sizeof (PAGESETUPDLG));
	
	shellprintinfo.pagesetupinfo.lStructSize = sizeof (PAGESETUPDLG);
	
	shellprintinfo.pagesetupinfo.hwndOwner = NULL;
	
	shellprintinfo.pagesetupinfo.Flags = PSD_RETURNDEFAULT | PSD_NOWARNING;
	
	if (! PageSetupDlg (&shellprintinfo.pagesetupinfo)) {
		
		if (CommDlgExtendedError() != 0)
			goto error;
	}
	
#endif
	
	//#if !TARGET_API_MAC_CARBON
	
	shellcopyprintinfo (); /*copies fields from handle into record*/
	
	//#endif
	
	return (true);
	
#if !defined(MACVERSION) || !TARGET_API_MAC_CARBON
	
error:
		
#endif
		
		/*
		 shelldisposeprintinfo ();
		 */
		
		return (false);
} /*shellinitprint*/
示例#8
0
boolean shellpagesetup (void) {
	
	/*
	 9/5/90 dmb:  open and close print resources each time we're called
	 
	 9/27/91 dmb: don't do anything when the user cancels the dialog
	 */
	
	boolean fl;
	
#ifdef MACVERSION
	
	//Code change by Timothy Paustian Friday, June 16, 2000 10:08:37 PM
	//new code for the new print manager.
	
#	if TARGET_API_MAC_CARBON == 1
	
	if (!carbonValidSession())
	{
		carbonStdSetup();
	}
	
	{
		OSStatus status;
		
		status = PMSessionPageSetupDialog(
										  shellprintinfo.printhandle, 
										  shellprintinfo.pageformat,
										  &fl);
		
		if (!fl)
			status = kPMCancel; // user clicked Cancel button
		
		if(status != noErr)
			return false;
		
	}
	
#	else
	
	PrOpen ();
	
	if (!shellcheckprinterror (true)) 
		return (false);
	
	PrValidate (shellprintinfo.printhandle);
	
	fl = PrStlDialog (shellprintinfo.printhandle);
	
	PrClose ();
	
	if (!shellcheckprinterror (false))
		return (false);
	
#	endif
	
#endif
	
#ifdef WIN95VERSION
	
	shellprintinfo.pagesetupinfo.Flags = PSD_MARGINS | PSD_INTHOUSANDTHSOFINCHES;
	
	shellprintinfo.pagesetupinfo.hwndOwner = hwndMDIClient;
	
	fl = PageSetupDlg (&shellprintinfo.pagesetupinfo);
	
#endif
	
	if (!fl)
		return (false);
	
	shellcopyprintinfo (); /*copies fields from handle into record*/
	
	shellvisittypedwindows (-1, &shellpagesetupvisit, nil); /*visit all windows*/
	
	return (true);
} /*shellpagesetup*/
示例#9
0
LRESULT CMainWindow::DoCommand(int id)
{
    switch (id)
    {
    case ID_FILE_OPEN:
        loadOrSaveFile(true);
        break;
    case ID_FILE_SAVEAS:
        loadOrSaveFile(false);
        break;
    case ID_FILE_SAVE:
        loadOrSaveFile(false, m_filename);
        break;
    case ID_FILE_EXIT:
        ::PostQuitMessage(0);
        return 0;
    case IDM_SHOWFINDBAR:
        {
            m_bShowFindBar = true;
            ::ShowWindow(m_FindBar, SW_SHOW);
            RECT rect;
            GetClientRect(*this, &rect);
            ::SetWindowPos(m_hWndEdit, HWND_TOP,
                rect.left, rect.top,
                rect.right-rect.left, rect.bottom-rect.top-30,
                SWP_SHOWWINDOW);
            ::SetWindowPos(m_FindBar, HWND_TOP,
                rect.left, rect.bottom-30,
                rect.right-rect.left, 30,
                SWP_SHOWWINDOW);
            ::SetFocus(m_FindBar);
            SendEditor(SCI_SETSELECTIONSTART, 0);
            SendEditor(SCI_SETSELECTIONEND, 0);
            SendEditor(SCI_SEARCHANCHOR);
        }
        break;
    case IDM_FINDNEXT:
        SendEditor(SCI_SEARCHANCHOR);
        SendEditor(SCI_SEARCHNEXT, m_bMatchCase ? SCFIND_MATCHCASE : 0, (LPARAM)CUnicodeUtils::StdGetUTF8(m_findtext).c_str());
        SendEditor(SCI_SCROLLCARET);
        break;
    case IDM_FINDPREV:
        SendEditor(SCI_SEARCHANCHOR);
        SendEditor(SCI_SEARCHPREV, m_bMatchCase ? SCFIND_MATCHCASE : 0, (LPARAM)CUnicodeUtils::StdGetUTF8(m_findtext).c_str());
        SendEditor(SCI_SCROLLCARET);
        break;
    case IDM_FINDEXIT:
        if (IsWindowVisible(m_FindBar))
        {
            RECT rect;
            GetClientRect(*this, &rect);
            m_bShowFindBar = false;
            ::ShowWindow(m_FindBar, SW_HIDE);
            ::SetWindowPos(m_hWndEdit, HWND_TOP,
                rect.left, rect.top,
                rect.right-rect.left, rect.bottom-rect.top,
                SWP_SHOWWINDOW);
        }
        else
            PostQuitMessage(0);
        break;
    case ID_FILE_SETTINGS:
        {
            tstring svnCmd = L" /command:settings /page:20";
            RunCommand(svnCmd);
        }
        break;
    case ID_FILE_APPLYPATCH:
        {
            std::wstring command = L" /diff:\"";
            command += m_filename;
            command += L"\"";
            std::wstring tortoiseMergePath = GetAppDirectory() + L"TortoiseMerge.exe";
            CCreateProcessHelper::CreateProcessDetached(tortoiseMergePath.c_str(), command.c_str());
        }
        break;
    case ID_FILE_PAGESETUP:
        {
            TCHAR localeInfo[3] = { 0 };
            GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, localeInfo, 3);
            // Metric system. '1' is US System
            int defaultMargin = localeInfo[0] == '0' ? 2540 : 1000;

            PAGESETUPDLG pdlg = {0};
            pdlg.lStructSize = sizeof(PAGESETUPDLG);
            pdlg.hwndOwner = *this;
            pdlg.hInstance = NULL;
            pdlg.Flags = PSD_DEFAULTMINMARGINS|PSD_MARGINS|PSD_DISABLEPAPER|PSD_DISABLEORIENTATION;
            if (localeInfo[0] == '0')
                pdlg.Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;

            CRegStdDWORD m_regMargLeft   = CRegStdDWORD(L"Software\\TortoiseSVN\\UDiffpagesetupmarginleft", defaultMargin);
            CRegStdDWORD m_regMargTop    = CRegStdDWORD(L"Software\\TortoiseSVN\\UDiffpagesetupmargintop", defaultMargin);
            CRegStdDWORD m_regMargRight  = CRegStdDWORD(L"Software\\TortoiseSVN\\UDiffpagesetupmarginright", defaultMargin);
            CRegStdDWORD m_regMargBottom = CRegStdDWORD(L"Software\\TortoiseSVN\\UDiffpagesetupmarginbottom", defaultMargin);

            pdlg.rtMargin.left   = (long)(DWORD)m_regMargLeft;
            pdlg.rtMargin.top    = (long)(DWORD)m_regMargTop;
            pdlg.rtMargin.right  = (long)(DWORD)m_regMargRight;
            pdlg.rtMargin.bottom = (long)(DWORD)m_regMargBottom;

            if (!PageSetupDlg(&pdlg))
                return false;

            m_regMargLeft   = pdlg.rtMargin.left;
            m_regMargTop    = pdlg.rtMargin.top;
            m_regMargRight  = pdlg.rtMargin.right;
            m_regMargBottom = pdlg.rtMargin.bottom;
        }
        break;
    case ID_FILE_PRINT:
        {
            PRINTDLGEX pdlg = {0};
            pdlg.lStructSize = sizeof(PRINTDLGEX);
            pdlg.hwndOwner = *this;
            pdlg.hInstance = NULL;
            pdlg.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_ALLPAGES | PD_RETURNDC | PD_NOCURRENTPAGE | PD_NOPAGENUMS;
            pdlg.nMinPage = 1;
            pdlg.nMaxPage = 0xffffU; // We do not know how many pages in the document
            pdlg.nCopies = 1;
            pdlg.hDC = 0;
            pdlg.nStartPage = START_PAGE_GENERAL;

            // See if a range has been selected
            size_t startPos = SendEditor(SCI_GETSELECTIONSTART);
            size_t endPos = SendEditor(SCI_GETSELECTIONEND);

            if (startPos == endPos)
                pdlg.Flags |= PD_NOSELECTION;
            else
                pdlg.Flags |= PD_SELECTION;

            HRESULT hResult = PrintDlgEx(&pdlg);
            if ((hResult != S_OK) || (pdlg.dwResultAction != PD_RESULT_PRINT))
                return 0;

            // reset all indicators
            size_t endpos = SendEditor(SCI_GETLENGTH);
            for (int i = INDIC_CONTAINER; i <= INDIC_MAX; ++i)
            {
                SendEditor(SCI_SETINDICATORCURRENT, i);
                SendEditor(SCI_INDICATORCLEARRANGE, 0, endpos);
            }
            // store and reset UI settings
            int viewws = (int)SendEditor(SCI_GETVIEWWS);
            SendEditor(SCI_SETVIEWWS, 0);
            int edgemode = (int)SendEditor(SCI_GETEDGEMODE);
            SendEditor(SCI_SETEDGEMODE, EDGE_NONE);
            SendEditor(SCI_SETWRAPVISUALFLAGS, SC_WRAPVISUALFLAG_END);

            HDC hdc = pdlg.hDC;

            RECT rectMargins, rectPhysMargins;
            POINT ptPage;
            POINT ptDpi;

            // Get printer resolution
            ptDpi.x = GetDeviceCaps(hdc, LOGPIXELSX);    // dpi in X direction
            ptDpi.y = GetDeviceCaps(hdc, LOGPIXELSY);    // dpi in Y direction

            // Start by getting the physical page size (in device units).
            ptPage.x = GetDeviceCaps(hdc, PHYSICALWIDTH);   // device units
            ptPage.y = GetDeviceCaps(hdc, PHYSICALHEIGHT);  // device units

            // Get the dimensions of the unprintable
            // part of the page (in device units).
            rectPhysMargins.left = GetDeviceCaps(hdc, PHYSICALOFFSETX);
            rectPhysMargins.top = GetDeviceCaps(hdc, PHYSICALOFFSETY);

            // To get the right and lower unprintable area,
            // we take the entire width and height of the paper and
            // subtract everything else.
            rectPhysMargins.right = ptPage.x                        // total paper width
                - GetDeviceCaps(hdc, HORZRES)                       // printable width
                - rectPhysMargins.left;                             // left unprintable margin

            rectPhysMargins.bottom = ptPage.y                       // total paper height
                - GetDeviceCaps(hdc, VERTRES)                       // printable height
                - rectPhysMargins.top;                              // right unprintable margin

            TCHAR localeInfo[3] = { 0 };
            GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, localeInfo, 3);
            // Metric system. '1' is US System
            int defaultMargin = localeInfo[0] == '0' ? 2540 : 1000;
            RECT pagesetupMargin;
            CRegStdDWORD m_regMargLeft   = CRegStdDWORD(L"Software\\TortoiseSVN\\UDiffpagesetupmarginleft", defaultMargin);
            CRegStdDWORD m_regMargTop    = CRegStdDWORD(L"Software\\TortoiseSVN\\UDiffpagesetupmargintop", defaultMargin);
            CRegStdDWORD m_regMargRight  = CRegStdDWORD(L"Software\\TortoiseSVN\\UDiffpagesetupmarginright", defaultMargin);
            CRegStdDWORD m_regMargBottom = CRegStdDWORD(L"Software\\TortoiseSVN\\UDiffpagesetupmarginbottom", defaultMargin);

            pagesetupMargin.left   = (long)(DWORD)m_regMargLeft;
            pagesetupMargin.top    = (long)(DWORD)m_regMargTop;
            pagesetupMargin.right  = (long)(DWORD)m_regMargRight;
            pagesetupMargin.bottom = (long)(DWORD)m_regMargBottom;

            if (pagesetupMargin.left != 0 || pagesetupMargin.right != 0 ||
                pagesetupMargin.top != 0 || pagesetupMargin.bottom != 0)
            {
                RECT rectSetup;

                // Convert the hundredths of millimeters (HiMetric) or
                // thousandths of inches (HiEnglish) margin values
                // from the Page Setup dialog to device units.
                // (There are 2540 hundredths of a mm in an inch.)
                if (localeInfo[0] == '0')
                {
                    // Metric system. '1' is US System
                    rectSetup.left      = MulDiv (pagesetupMargin.left, ptDpi.x, 2540);
                    rectSetup.top       = MulDiv (pagesetupMargin.top, ptDpi.y, 2540);
                    rectSetup.right     = MulDiv(pagesetupMargin.right, ptDpi.x, 2540);
                    rectSetup.bottom    = MulDiv(pagesetupMargin.bottom, ptDpi.y, 2540);
                }
                else
                {
                    rectSetup.left      = MulDiv(pagesetupMargin.left, ptDpi.x, 1000);
                    rectSetup.top       = MulDiv(pagesetupMargin.top, ptDpi.y, 1000);
                    rectSetup.right     = MulDiv(pagesetupMargin.right, ptDpi.x, 1000);
                    rectSetup.bottom    = MulDiv(pagesetupMargin.bottom, ptDpi.y, 1000);
                }

                // Don't reduce margins below the minimum printable area
                rectMargins.left    = max(rectPhysMargins.left, rectSetup.left);
                rectMargins.top     = max(rectPhysMargins.top, rectSetup.top);
                rectMargins.right   = max(rectPhysMargins.right, rectSetup.right);
                rectMargins.bottom  = max(rectPhysMargins.bottom, rectSetup.bottom);
            }
            else
            {
                rectMargins.left    = rectPhysMargins.left;
                rectMargins.top     = rectPhysMargins.top;
                rectMargins.right   = rectPhysMargins.right;
                rectMargins.bottom  = rectPhysMargins.bottom;
            }

            // rectMargins now contains the values used to shrink the printable
            // area of the page.

            // Convert device coordinates into logical coordinates
            DPtoLP(hdc, (LPPOINT) &rectMargins, 2);
            DPtoLP(hdc, (LPPOINT)&rectPhysMargins, 2);

            // Convert page size to logical units and we're done!
            DPtoLP(hdc, (LPPOINT) &ptPage, 1);


            DOCINFO di = {sizeof(DOCINFO), 0, 0, 0, 0};
            di.lpszDocName = m_filename.c_str();
            di.lpszOutput = 0;
            di.lpszDatatype = 0;
            di.fwType = 0;
            if (::StartDoc(hdc, &di) < 0)
            {
                ::DeleteDC(hdc);
                return 0;
            }

            size_t lengthDoc = SendEditor(SCI_GETLENGTH);
            size_t lengthDocMax = lengthDoc;
            size_t lengthPrinted = 0;

            // Requested to print selection
            if (pdlg.Flags & PD_SELECTION)
            {
                if (startPos > endPos)
                {
                    lengthPrinted = endPos;
                    lengthDoc = startPos;
                }
                else
                {
                    lengthPrinted = startPos;
                    lengthDoc = endPos;
                }

                if (lengthDoc > lengthDocMax)
                    lengthDoc = lengthDocMax;
            }

            // We must subtract the physical margins from the printable area
            Sci_RangeToFormat frPrint;
            frPrint.hdc             = hdc;
            frPrint.hdcTarget       = hdc;
            frPrint.rc.left         = rectMargins.left - rectPhysMargins.left;
            frPrint.rc.top          = rectMargins.top - rectPhysMargins.top;
            frPrint.rc.right        = ptPage.x - rectMargins.right - rectPhysMargins.left;
            frPrint.rc.bottom       = ptPage.y - rectMargins.bottom - rectPhysMargins.top;
            frPrint.rcPage.left     = 0;
            frPrint.rcPage.top      = 0;
            frPrint.rcPage.right    = ptPage.x - rectPhysMargins.left - rectPhysMargins.right - 1;
            frPrint.rcPage.bottom   = ptPage.y - rectPhysMargins.top - rectPhysMargins.bottom - 1;

            // Print each page
            while (lengthPrinted < lengthDoc)
            {
                ::StartPage(hdc);

                frPrint.chrg.cpMin = (long)lengthPrinted;
                frPrint.chrg.cpMax = (long)lengthDoc;

                lengthPrinted = SendEditor(SCI_FORMATRANGE, true, reinterpret_cast<LPARAM>(&frPrint));

                ::EndPage(hdc);
            }

            SendEditor(SCI_FORMATRANGE, FALSE, 0);

            ::EndDoc(hdc);
            ::DeleteDC(hdc);

            if (pdlg.hDevMode != NULL)
                GlobalFree(pdlg.hDevMode);
            if (pdlg.hDevNames != NULL)
                GlobalFree(pdlg.hDevNames);
            if (pdlg.lpPageRanges != NULL)
                GlobalFree(pdlg.lpPageRanges);

            // reset the UI
            SendEditor(SCI_SETVIEWWS, viewws);
            SendEditor(SCI_SETEDGEMODE, edgemode);
            SendEditor(SCI_SETWRAPVISUALFLAGS, SC_WRAPVISUALFLAG_NONE);
        }
        break;
    default:
        break;
    };
    return 1;
}
示例#10
0
//---------------------------------------------------------------------------
bool __fastcall TTaePageSetupDialog::Execute(TTaeRichEdit* taeRichEdit)
{
  TPageSetupDlg psd;
  char device[255];
  char driver[255];
  char port[255];
  unsigned int devmode;  // help file is wrong (it says "int")

  // quick out if no rich edit
  if (!taeRichEdit || !taeRichEdit->TaePrint)
    return false;

  // set margins to values from rich edit
  if (Units == psuInches1000ths)
  {
    FMargins->Left = TwipsToInches(taeRichEdit->TaePrint->Margins.Left);
    FMargins->Top = TwipsToInches(taeRichEdit->TaePrint->Margins.Top);
    FMargins->Right = TwipsToInches(taeRichEdit->TaePrint->Margins.Right);
    FMargins->Bottom = TwipsToInches(taeRichEdit->TaePrint->Margins.Bottom);
//    FMargins->Left =
//      (TwipsToInches(taeRichEdit->TaePrint->Margins.Left) * 1000.0) + 0.5;
//    FMargins->Top =
//      (TwipsToInches(taeRichEdit->TaePrint->Margins.Top) * 1000.0) + 0.5;
//    FMargins->Right =
//      (TwipsToInches(taeRichEdit->TaePrint->Margins.Right) * 1000.0) + 0.5;
//    FMargins->Bottom =
//      (TwipsToInches(taeRichEdit->TaePrint->Margins.Bottom) * 1000.0) + 0.5;
  }
  else
  {
    FMargins->Left = TwipsToMMs(taeRichEdit->TaePrint->Margins.Left);
    FMargins->Top = TwipsToMMs(taeRichEdit->TaePrint->Margins.Top);
    FMargins->Right = TwipsToMMs(taeRichEdit->TaePrint->Margins.Right);
    FMargins->Bottom = TwipsToMMs(taeRichEdit->TaePrint->Margins.Bottom);
//    FMargins->Left =
//      (TwipsToMMs(taeRichEdit->TaePrint->Margins.Left) * 100.0) + 0.5;
//    FMargins->Top =
//      (TwipsToMMs(taeRichEdit->TaePrint->Margins.Top) * 100.0) + 0.5;
//    FMargins->Right =
//      (TwipsToMMs(taeRichEdit->TaePrint->Margins.Right) * 100.0) + 0.5;
//    FMargins->Bottom =
//      (TwipsToMMs(taeRichEdit->TaePrint->Margins.Bottom) * 100.0) + 0.5;
  }


  // get printer information
  FPrinter->GetPrinter(device, driver, port, devmode);

  // initialize the print setup dialog structure
  psd.lStructSize = sizeof(psd);
  psd.hwndOwner = Application->MainForm->Handle;
  psd.hDevMode = (HGLOBAL) devmode;
  psd.hDevNames = 0;
  psd.Flags = OptionFlags;
  psd.rtMinMargin = FMinMargins->Rect;
  psd.ptPaperSize = FPaperSize->Point;
  psd.rtMargin = FMargins->Rect;
  psd.hInstance = 0;
  psd.lCustData = 0;
  psd.lpfnPageSetupHook = 0;
  psd.lpfnPagePaintHook = 0;
  psd.lpPageSetupTemplateName = 0;
  psd.hPageSetupTemplate = 0;


  // execute the dialog (returns false on cancel)
  if (!PageSetupDlg(&psd)) return false;

  // get the device, driver, and port from the returned data
  DEVNAMES* dn = 0;
  if (psd.hDevNames) dn = (DEVNAMES*) ::GlobalLock(psd.hDevNames);
  char *pdriver = (char*) ((char*) dn + dn->wDriverOffset);
  char *pdevice = (char*) ((char*) dn + dn->wDeviceOffset);
  char *pport = (char*) ((char*) dn + dn->wOutputOffset);

  // set the printer to the device, driver, port, and device mode returned
  FPrinter->SetPrinter(pdevice, pdriver, pport, (int) psd.hDevMode);

  // TPrinter takes care of freeing the hDevMode global memory (or
  // so I believe and very much hope) but we still have to free
  // the device names memory
  ::GlobalUnlock(psd.hDevNames);
  ::GlobalFree(psd.hDevNames);

  // save the returned values back into the properties
  OptionFlags = psd.Flags;
  FMinMargins->Rect = psd.rtMinMargin;
  FPaperSize->Point = psd.ptPaperSize;
  FMargins->Rect = psd.rtMargin;

  // set the rich edit margins
  if (Units == psuInches1000ths)
  {
    taeRichEdit->TaePrint->Margins.Left = InchesToTwips(FMargins->Left);
    taeRichEdit->TaePrint->Margins.Top = InchesToTwips(FMargins->Top);
    taeRichEdit->TaePrint->Margins.Right = InchesToTwips(FMargins->Right);
    taeRichEdit->TaePrint->Margins.Bottom = InchesToTwips(FMargins->Bottom);
//    taeRichEdit->TaePrint->Margins.Left =
//      (InchesToTwips(FMargins->Left) / 1000.0) + 0.5;
//    taeRichEdit->TaePrint->Margins.Top =
//      (InchesToTwips(FMargins->Top) / 1000.0) + 0.5;
//    taeRichEdit->TaePrint->Margins.Right =
//      (InchesToTwips(FMargins->Right) / 1000.0) + 0.5;
//    taeRichEdit->TaePrint->Margins.Bottom =
//      (InchesToTwips(FMargins->Bottom) / 1000.0) + 0.5;
  }
  else
  {
    taeRichEdit->TaePrint->Margins.Left = MMsToTwips(FMargins->Left);
    taeRichEdit->TaePrint->Margins.Top = MMsToTwips(FMargins->Top);
    taeRichEdit->TaePrint->Margins.Right = MMsToTwips(FMargins->Right);
    taeRichEdit->TaePrint->Margins.Bottom = MMsToTwips(FMargins->Bottom);
//    taeRichEdit->TaePrint->Margins.Left =
//      (MMsToTwips(FMargins->Left) / 100.0) + 0.5;
//    taeRichEdit->TaePrint->Margins.Top =
//      (MMsToTwips(FMargins->Top) / 100.0) + 0.5;
//    taeRichEdit->TaePrint->Margins.Right =
//      (MMsToTwips(FMargins->Right) / 100.0) + 0.5;
//    taeRichEdit->TaePrint->Margins.Bottom =
//      (MMsToTwips(FMargins->Bottom) / 100.0) + 0.5;
  }

  // return success
  return true;
}
示例#11
0
文件: winproc.cpp 项目: GYGit/reactos
LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    switch (LOWORD(wParam))
    {
        case IDM_HELPINFO:
        {
            HICON paintIcon = LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON));
            TCHAR infotitle[100];
            TCHAR infotext[200];
            LoadString(hProgInstance, IDS_INFOTITLE, infotitle, SIZEOF(infotitle));
            LoadString(hProgInstance, IDS_INFOTEXT, infotext, SIZEOF(infotext));
            ShellAbout(m_hWnd, infotitle, infotext, paintIcon);
            DeleteObject(paintIcon);
            break;
        }
        case IDM_HELPHELPTOPICS:
            HtmlHelp(m_hWnd, _T("help\\Paint.chm"), 0, 0);
            break;
        case IDM_FILEEXIT:
            SendMessage(WM_CLOSE, wParam, lParam);
            break;
        case IDM_FILENEW:
        {
            BOOL reset = TRUE;
            if (!imageModel.IsImageSaved())
            {
                TCHAR programname[20];
                TCHAR saveprompttext[100];
                TCHAR temptext[500];
                LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
                LoadString(hProgInstance, IDS_SAVEPROMPTTEXT, saveprompttext, SIZEOF(saveprompttext));
                _stprintf(temptext, saveprompttext, filename);
                switch (MessageBox(temptext, programname, MB_YESNOCANCEL | MB_ICONQUESTION))
                {
                    case IDNO:
                        imageModel.imageSaved = TRUE; //TODO: move to ImageModel
                        break;
                    case IDYES:
                        saveImage(FALSE);
                        break;
                    case IDCANCEL:
                        reset = FALSE;
                        break;
                }
            }
            if (reset && imageModel.IsImageSaved()) //TODO: move to ImageModel
            {
                imageModel.Clear();
                imageModel.ClearHistory();
            }
            break;
        }
        case IDM_FILEOPEN:
            if (GetOpenFileName(&ofn) != 0)
            {
                HBITMAP bmNew = NULL;
                LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
                if (bmNew != NULL)
                {
                    UpdateApplicationProperties(bmNew, ofn.lpstrFileTitle, ofn.lpstrFileTitle);
                }
            }
            break;
        case IDM_FILESAVE:
            saveImage(TRUE);
            break;
        case IDM_FILESAVEAS:
            saveImage(FALSE);
            break;
        case IDM_FILEPAGESETUP:
            // DUMMY: Shows the dialog only, no functionality
            PAGESETUPDLG psd;
            ZeroMemory(&psd, sizeof(psd));
            psd.lStructSize = sizeof(psd);
            psd.hwndOwner = m_hWnd;
            PageSetupDlg(&psd);
            break;
        case IDM_FILEPRINT:
            // TODO: Test whether it actually works
            PRINTDLG pd;
            ZeroMemory(&pd, sizeof(pd));
            pd.lStructSize = sizeof(pd);
            pd.hwndOwner = m_hWnd;
            pd.hDevMode = NULL;  // freed by user
            pd.hDevNames = NULL;  // freed by user
            pd.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;
            pd.nCopies = 1;
            pd.nFromPage = 0xffff;
            pd.nToPage = 0xffff;
            pd.nMinPage = 1;
            pd.nMaxPage = 0xffff;
            if (PrintDlg(&pd) == TRUE)
            {
                BitBlt(pd.hDC, 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), imageModel.GetDC(), 0, 0, SRCCOPY);
                DeleteDC(pd.hDC);
            }
            if (pd.hDevMode)
                GlobalFree(pd.hDevMode);
            if (pd.hDevNames)
                GlobalFree(pd.hDevNames);
            break;
        case IDM_FILEASWALLPAPERPLANE:
            RegistrySettings::SetWallpaper(filepathname, 1, 1);
            break;
        case IDM_FILEASWALLPAPERCENTERED:
            RegistrySettings::SetWallpaper(filepathname, 1, 0);
            break;
        case IDM_FILEASWALLPAPERSTRETCHED:
            RegistrySettings::SetWallpaper(filepathname, 2, 0);
            break;
        case IDM_EDITUNDO:
            imageModel.Undo();
            imageArea.Invalidate(FALSE);
            break;
        case IDM_EDITREDO:
            imageModel.Redo();
            imageArea.Invalidate(FALSE);
            break;
        case IDM_EDITCOPY:
            OpenClipboard();
            EmptyClipboard();
            SetClipboardData(CF_BITMAP, CopyImage(selectionModel.GetBitmap(), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
            CloseClipboard();
            break;
        case IDM_EDITCUT:
            /* Copy */
            SendMessage(WM_COMMAND, IDM_EDITCOPY, 0);
            /* Delete selection */
            SendMessage(WM_COMMAND, IDM_EDITDELETESELECTION, 0);
            break;
        case IDM_EDITPASTE:
            OpenClipboard();
            if (GetClipboardData(CF_BITMAP) != NULL)
            {
                InsertSelectionFromHBITMAP((HBITMAP) GetClipboardData(CF_BITMAP), m_hWnd);
            }
            CloseClipboard();
            break;
        case IDM_EDITDELETESELECTION:
        {
            /* remove selection window and already painted content using undo */
            imageModel.Undo();
            break;
        }
        case IDM_EDITSELECTALL:
        {
            HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
            SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELPARAM(TRUE, 0));
            toolBoxContainer.SendMessage(WM_COMMAND, ID_RECTSEL);
            //TODO: do this properly
            startPaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
            whilePaintingL(imageModel.GetDC(), imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetFgColor(), paletteModel.GetBgColor());
            endPaintingL(imageModel.GetDC(), imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetFgColor(), paletteModel.GetBgColor());
            break;
        }
        case IDM_EDITCOPYTO:
            if (GetSaveFileName(&ofn) != 0)
                SaveDIBToFile(selectionModel.GetBitmap(), ofn.lpstrFile, imageModel.GetDC(), NULL, NULL, fileHPPM, fileVPPM);
            break;
        case IDM_EDITPASTEFROM:
            if (GetOpenFileName(&ofn) != 0)
            {
                HBITMAP bmNew = NULL;
                LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
                if (bmNew != NULL)
                {
                    InsertSelectionFromHBITMAP(bmNew, m_hWnd);
                    DeleteObject(bmNew);
                }
            }
            break;
        case IDM_COLORSEDITPALETTE:
            if (ChooseColor(&choosecolor))
                paletteModel.SetFgColor(choosecolor.rgbResult);
            break;
        case IDM_COLORSMODERNPALETTE:
            paletteModel.SelectPalette(1);
            break;
        case IDM_COLORSOLDPALETTE:
            paletteModel.SelectPalette(2);
            break;
        case IDM_IMAGEINVERTCOLORS:
        {
            imageModel.InvertColors();
            break;
        }
        case IDM_IMAGEDELETEIMAGE:
            imageModel.CopyPrevious();
            Rect(imageModel.GetDC(), 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetBgColor(), paletteModel.GetBgColor(), 0, TRUE);
            imageArea.Invalidate(FALSE);
            break;
        case IDM_IMAGEROTATEMIRROR:
            switch (mirrorRotateDlg())
            {
                case 1: /* flip horizontally */
                    if (selectionWindow.IsWindowVisible())
                        selectionModel.FlipHorizontally();
                    else
                        imageModel.FlipHorizontally();
                    break;
                case 2: /* flip vertically */
                    if (selectionWindow.IsWindowVisible())
                        selectionModel.FlipVertically();
                    else
                        imageModel.FlipVertically();
                    break;
                case 3: /* rotate 90 degrees */
                    break;
                case 4: /* rotate 180 degrees */
                    if (selectionWindow.IsWindowVisible())
                        selectionModel.RotateNTimes90Degrees(2);
                    else
                        imageModel.RotateNTimes90Degrees(2);
                    break;
                case 5: /* rotate 270 degrees */
                    break;
            }
            break;
        case IDM_IMAGEATTRIBUTES:
        {
            if (attributesDlg())
            {
                imageModel.Crop(widthSetInDlg, heightSetInDlg, 0, 0);
            }
            break;
        }
        case IDM_IMAGESTRETCHSKEW:
        {
            if (changeSizeDlg())
            {
                imageModel.StretchSkew(stretchSkew.percentage.x, stretchSkew.percentage.y,
                                       stretchSkew.angle.x, stretchSkew.angle.y);
            }
            break;
        }
        case IDM_IMAGEDRAWOPAQUE:
            toolsModel.SetBackgroundTransparent(!toolsModel.IsBackgroundTransparent());
            break;
        case IDM_IMAGECROP:
            imageModel.Insert((HBITMAP) CopyImage(selectionModel.GetBitmap(), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
            break;

        case IDM_VIEWTOOLBOX:
            toolBoxContainer.ShowWindow(toolBoxContainer.IsWindowVisible() ? SW_HIDE : SW_SHOW);
            alignChildrenToMainWindow();
            break;
        case IDM_VIEWCOLORPALETTE:
            paletteWindow.ShowWindow(paletteWindow.IsWindowVisible() ? SW_HIDE : SW_SHOW);
            alignChildrenToMainWindow();
            break;
        case IDM_VIEWSTATUSBAR:
            ::ShowWindow(hStatusBar, ::IsWindowVisible(hStatusBar) ? SW_HIDE : SW_SHOW);
            alignChildrenToMainWindow();
            break;
        case IDM_FORMATICONBAR:
            textEditWindow.ShowWindow(textEditWindow.IsWindowVisible() ? SW_HIDE : SW_SHOW);

        case IDM_VIEWSHOWGRID:
            showGrid = !showGrid;
            imageArea.Invalidate(FALSE);
            break;
        case IDM_VIEWSHOWMINIATURE:
            showMiniature = !showMiniature;
            miniature.ShowWindow(showMiniature ? SW_SHOW : SW_HIDE);
            break;

        case IDM_VIEWZOOM125:
            zoomTo(125, 0, 0);
            break;
        case IDM_VIEWZOOM25:
            zoomTo(250, 0, 0);
            break;
        case IDM_VIEWZOOM50:
            zoomTo(500, 0, 0);
            break;
        case IDM_VIEWZOOM100:
            zoomTo(1000, 0, 0);
            break;
        case IDM_VIEWZOOM200:
            zoomTo(2000, 0, 0);
            break;
        case IDM_VIEWZOOM400:
            zoomTo(4000, 0, 0);
            break;
        case IDM_VIEWZOOM800:
            zoomTo(8000, 0, 0);
            break;

        case IDM_VIEWFULLSCREEN:
            fullscreenWindow.ShowWindow(SW_SHOW);
            ShowWindow(SW_HIDE);
            break;
    }
    return 0;
}
int QPageSetupDialog::exec()
{
    Q_D(QPageSetupDialog);

    if (d->printer->outputFormat() != QPrinter::NativeFormat)
        return Rejected;

    QWin32PrintEngine *engine = static_cast<QWin32PrintEngine*>(d->printer->paintEngine());
    QWin32PrintEnginePrivate *ep = static_cast<QWin32PrintEnginePrivate *>(engine->d_ptr.data());

    PAGESETUPDLG psd;
    memset(&psd, 0, sizeof(PAGESETUPDLG));
    psd.lStructSize = sizeof(PAGESETUPDLG);

    // we need a temp DEVMODE struct if we don't have a global DEVMODE
    HGLOBAL hDevMode = 0;
    int devModeSize = 0;
    if (!engine->globalDevMode()) {
        devModeSize = sizeof(DEVMODE) + ep->devMode->dmDriverExtra;
        hDevMode = GlobalAlloc(GHND, devModeSize);
        if (hDevMode) {
            void *dest = GlobalLock(hDevMode);
            memcpy(dest, ep->devMode, devModeSize);
            GlobalUnlock(hDevMode);
        }
        psd.hDevMode = hDevMode;
    } else {
        psd.hDevMode = engine->globalDevMode();
    }

    HGLOBAL *tempDevNames = engine->createGlobalDevNames();
    psd.hDevNames = tempDevNames;

    QWidget *parent = parentWidget();
    parent = parent ? parent->window() : QApplication::activeWindow();
    Q_ASSERT(!parent ||parent->testAttribute(Qt::WA_WState_Created));

    QWindow *parentWindow = parent->windowHandle();
    psd.hwndOwner = parentWindow ? (HWND)QGuiApplication::platformNativeInterface()->nativeResourceForWindow("handle", parentWindow) : 0;

    psd.Flags = PSD_MARGINS;
    QPageLayout layout = d->printer->pageLayout();
    switch (layout.units()) {
    case QPageLayout::Millimeter:
    case QPageLayout::Inch:
        break;
    case QPageLayout::Point:
    case QPageLayout::Pica:
    case QPageLayout::Didot:
    case QPageLayout::Cicero:
        layout.setUnits(QLocale::system().measurementSystem() == QLocale::MetricSystem ? QPageLayout::Millimeter
                                                                                       : QPageLayout::Inch);
        break;
    }
    qreal multiplier = 1.0;
    if (layout.units() == QPageLayout::Millimeter) {
        psd.Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
        multiplier = 100.0;
    } else { // QPageLayout::Inch)
        psd.Flags |= PSD_INTHOUSANDTHSOFINCHES;
        multiplier = 1000.0;
    }
    psd.rtMargin.left   = layout.margins().left() * multiplier;
    psd.rtMargin.top    = layout.margins().top() * multiplier;
    psd.rtMargin.right  = layout.margins().right() * multiplier;
    psd.rtMargin.bottom = layout.margins().bottom() * multiplier;

    QDialog::setVisible(true);
    bool result = PageSetupDlg(&psd);
    QDialog::setVisible(false);
    if (result) {
        engine->setGlobalDevMode(psd.hDevNames, psd.hDevMode);
        const QMarginsF margins(psd.rtMargin.left, psd.rtMargin.top, psd.rtMargin.right, psd.rtMargin.bottom);
        d->printer->setPageMargins(margins / multiplier, layout.units());

        // copy from our temp DEVMODE struct
        if (!engine->globalDevMode() && hDevMode) {
            void *src = GlobalLock(hDevMode);
            memcpy(ep->devMode, src, devModeSize);
            GlobalUnlock(hDevMode);
        }
    }

    if (!engine->globalDevMode() && hDevMode)
        GlobalFree(hDevMode);
    GlobalFree(tempDevNames);
    done(result);
    return result;
}
示例#13
0
BOOL
GetDefPrinter
(
    PCPSUISAMPLE    pCPSUISample
)
{
    HGLOBAL         hDevMode = NULL;
    HGLOBAL         hDevNames = NULL;
    LPTSTR          pszPrinterName = NULL;
    DEVMODE         *pDM = NULL;
    DEVNAMES        *pDN = NULL;
    HANDLE          hPrinter = NULL;
    PAGESETUPDLG    PSD = {0};
    BOOL            Ok = FALSE;

    PSD.lStructSize = sizeof(PSD);
    PSD.Flags       = PSD_RETURNDEFAULT;

    if (PageSetupDlg(&PSD))
    {
        hDevMode = PSD.hDevMode;

        if (NULL != hDevMode)
        {
            pDM = (DEVMODE *)GlobalLock(hDevMode);
            if (NULL != pDM)
            {
                hDevNames = PSD.hDevNames;                
                if (hDevNames)
                {
                    pDN = (DEVNAMES *)GlobalLock(hDevNames);
                    if (NULL != pDN)
                    {
                        pszPrinterName = (LPTSTR)pDN + pDN->wDeviceOffset;
                        if (pszPrinterName != NULL)
                        {
                            if (OpenPrinter(pszPrinterName, &hPrinter, NULL))
                            {
                                Ok = TRUE;
                            }
                        }
                    }
                }
            }
        }

        if (Ok)
        {
            HGLOBAL h = pCPSUISample->hDevMode;

            if (NULL != h)
            {
                GlobalUnlock(h);
                GlobalFree(h);
            }

            h = pCPSUISample->hDevNames;

            if (NULL != h)
            {
                GlobalUnlock(h);
                GlobalFree(h);
            }

            if (pCPSUISample->DPHdr.hPrinter)
            {
                ClosePrinter(pCPSUISample->DPHdr.hPrinter);
            }

            pCPSUISample->hDevMode             = PSD.hDevMode;
            pCPSUISample->hDevNames            = PSD.hDevNames;

            pCPSUISample->DPHdr.cbSize         = sizeof(DOCUMENTPROPERTYHEADER);
            pCPSUISample->DPHdr.hPrinter       = hPrinter;
            pCPSUISample->DPHdr.pszPrinterName = pszPrinterName;
            pCPSUISample->DPHdr.pdmIn          =
            pCPSUISample->DPHdr.pdmOut         = pDM;
            pCPSUISample->DPHdr.fMode          = (DM_IN_BUFFER | DM_IN_PROMPT | DM_OUT_BUFFER);

            if (!UpdatePermission)
            {
                pCPSUISample->DPHdr.fMode |= DM_NOPERMISSION;
            }
        }
        else
        {
            hDevMode = PSD.hDevMode;
            hDevNames = PSD.hDevNames;

            if (NULL != hDevMode)
            {
                GlobalUnlock(hDevMode);
                GlobalFree(hDevMode);
            }

            if (NULL != hDevNames)
            {
                GlobalUnlock(hDevNames);
                GlobalFree(hDevNames);
            }

            if (hPrinter)
            {
                ClosePrinter(hPrinter);
            }
        }
    }

    return Ok;
}