- // Use PRINTDLG as a way of creating a DEVMODE object
- PRINTDLG *pd = new PRINTDLG;
-
- // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
-#ifdef __GNUWIN32__
- memset(pd, 0, 66);
- pd->lStructSize = 66 ;
-#else
- memset(pd, 0, sizeof(PRINTDLG));
- pd->lStructSize = sizeof(PRINTDLG);
-#endif
-
- pd->hwndOwner = (HWND)NULL;
- pd->hDevMode = NULL; // Will be created by PrintDlg
- pd->hDevNames = NULL; // Ditto
- pd->hInstance = (HINSTANCE) wxGetInstance();
-
- pd->Flags = PD_RETURNDEFAULT;
- pd->nCopies = 1;
-
- // Fill out the DEVMODE structure
- // so we can use it as input in the 'real' PrintDlg
- if (!PrintDlg(pd))
- {
- if ( pd->hDevMode )
- GlobalFree(pd->hDevMode);
- if ( pd->hDevNames )
- GlobalFree(pd->hDevNames);
- pd->hDevMode = NULL;
- pd->hDevNames = NULL;
-
-#if defined(__WXDEBUG__) && defined(__WIN32__)
- wxString str(wxT("Printing error: "));
- str += wxGetPrintDlgError();
- wxLogDebug(str);
-#endif
- }
- else
- {
- if ( pd->hDevNames )
- GlobalFree(pd->hDevNames);
- pd->hDevNames = NULL;
-
- hDevMode = pd->hDevMode;
- m_devMode = (void*)(long) hDevMode;
- pd->hDevMode = NULL;
- }
-
- delete pd;
- }
-
- if ( hDevMode )
- {
- DEVMODE *devMode = (DEVMODE*) GlobalLock(hDevMode);
-
- //// Orientation
-
-#ifndef __WXWINE__
- devMode->dmOrientation = m_printOrientation;
-#endif
- devMode->dmFields = DM_ORIENTATION;
-
- //// Collation
-
-#ifndef __WIN16__
- devMode->dmCollate = (m_printCollate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE);
- devMode->dmFields |= DM_COLLATE;
-#endif
-
- //// Number of copies
-
- devMode->dmCopies = m_printNoCopies;
- devMode->dmFields |= DM_COPIES;
-
- //// Printer name
-
- if (m_printerName != wxT(""))
- {
- // TODO: make this Unicode compatible
- int len = wxMin(31, m_printerName.Len());
- int i;
- for (i = 0; i < len; i++)
- devMode->dmDeviceName[i] = m_printerName.GetChar(i);
- devMode->dmDeviceName[i] = 0;
- }
-
- //// Colour
-
- if (m_colour)
- devMode->dmColor = DMCOLOR_COLOR;
- else
- devMode->dmColor = DMCOLOR_MONOCHROME;
-
- devMode->dmFields |= DM_COLOR;
-
-#ifndef __WXWINE__
- //// Paper size
-
- if (m_paperId == wxPAPER_NONE)
- {
- devMode->dmPaperWidth = m_paperSize.x * 10;
- devMode->dmPaperLength = m_paperSize.y * 10;
- devMode->dmFields |= DM_PAPERWIDTH;
- devMode->dmFields |= DM_PAPERLENGTH;
- }
- else
- {
- if (wxThePrintPaperDatabase)
- {
- wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType(m_paperId);
- if (paper)
- {
- devMode->dmPaperSize = paper->GetPlatformId();
- devMode->dmFields |= DM_PAPERSIZE;
- }
- }
- }
-#endif
-
- //// Duplex
-
- int duplex;
- switch (m_duplexMode)
- {
- case wxDUPLEX_HORIZONTAL: {
- duplex = DMDUP_HORIZONTAL; break;
- }
- case wxDUPLEX_VERTICAL: {
- duplex = DMDUP_VERTICAL; break;
- }
- default:
- case wxDUPLEX_SIMPLEX: {
- duplex = DMDUP_SIMPLEX; break;
- }
- }
- devMode->dmDuplex = duplex;
- devMode->dmFields |= DM_DUPLEX;
-
- //// Quality
-
- int quality;
- switch (m_printQuality)
- {
- case wxPRINT_QUALITY_MEDIUM: {
- quality = DMRES_MEDIUM; break;
- }
- case wxPRINT_QUALITY_LOW: {
- quality = DMRES_LOW; break;
- }
- case wxPRINT_QUALITY_DRAFT: {
- quality = DMRES_DRAFT; break;
- }
- case wxPRINT_QUALITY_HIGH: {
- quality = DMRES_HIGH; break;
- }
- default: {
- quality = m_printQuality; break;
- }
- }
- devMode->dmPrintQuality = quality;
- devMode->dmFields |= DM_PRINTQUALITY;
-
- GlobalUnlock(hDevMode);