- HGLOBAL hDevMode = (HGLOBAL) m_devMode;
- if (!hDevMode)
- {
- // 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__
- pd->lStructSize = 66 ;
- memset(pd, 0, sizeof(PRINTDLG));
-#else
- pd->lStructSize = sizeof(PRINTDLG);
- memset(pd, 0, sizeof(PRINTDLG));
-#endif
-
- pd->hwndOwner = (HWND)NULL;
- pd->hDevMode = NULL; // Will be created by PrintDlg
- pd->hDevNames = NULL; // Ditto
-
- 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;
- }
- else
- {
- if ( pd->hDevNames )
- GlobalFree(pd->hDevNames);
- pd->hDevNames = NULL;
-
- hDevMode = pd->hDevMode;
- m_devMode = (void*) hDevMode;
- pd->hDevMode = NULL;
- }
-
- delete pd;
- }
-
- if ( hDevMode )
- {
- DEVMODE *devMode = (DEVMODE*) GlobalLock(hDevMode);
-
- //// Orientation
-
- devMode->dmOrientation = m_printOrientation;
- devMode->dmFields = DM_ORIENTATION;
-
- //// Collation
-
- devMode->dmCollate = (m_printCollate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE);
- devMode->dmFields |= DM_COLLATE;
-
- //// Number of copies
-
- devMode->dmCopies = m_printNoCopies;
- devMode->dmFields |= DM_COPIES;
-
- //// Printer name
-
- if (m_printerName != "")
- {
- // 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;
-
- //// 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;
- }
- }
- }
-
- //// 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);
- }