+
+ //// 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);
+ }
+
+ if ( hDevNames )
+ {
+ GlobalFree(hDevNames);
+ }
+
+ // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
+ m_devNames = (void*) (long) wxCreateDevNames("", m_printerName, "");
+}
+
+void wxPrintData::ConvertFromNative()
+{
+ HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
+ HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
+
+ if (!hDevMode)
+ return;
+
+ if ( hDevMode )
+ {
+ LPDEVMODE devMode = (LPDEVMODE)GlobalLock(hDevMode);
+
+#ifndef __WXWINE__
+ //// Orientation
+
+ if (devMode->dmFields & DM_ORIENTATION)
+ m_printOrientation = devMode->dmOrientation;
+#endif
+
+ //// Collation
+
+#ifndef __WIN16__
+ if (devMode->dmFields & DM_COLLATE)
+ {
+ if (devMode->dmCollate == DMCOLLATE_TRUE)
+ m_printCollate = TRUE;
+ else
+ m_printCollate = FALSE;
+ }
+#endif
+
+ //// Number of copies
+
+ if (devMode->dmFields & DM_COPIES)
+ {
+ m_printNoCopies = devMode->dmCopies;
+ }
+
+ //// Printer name
+
+ if (devMode->dmDeviceName[0] != 0)
+ {
+ // TODO: make this Unicode compatible
+ char buf[32];
+ int i = 0;
+ while (devMode->dmDeviceName[i] != 0)
+ {
+ buf[i] = devMode->dmDeviceName[i];
+ i ++;
+ }
+ buf[i] = 0;
+
+ m_printerName = buf;
+ }
+
+ //// Colour
+
+ if (devMode->dmFields & DM_COLOR)
+ {
+ if (devMode->dmColor == DMCOLOR_COLOR)
+ m_colour = TRUE;
+ else
+ m_colour = FALSE;
+ }
+ else
+ m_colour = TRUE;
+
+#ifndef __WXWINE__
+ //// Paper size
+
+ if (devMode->dmFields & DM_PAPERSIZE)
+ {
+ if (wxThePrintPaperDatabase)
+ {
+ wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize);
+ if (paper)
+ {
+ m_paperId = paper->GetId();
+ m_paperSize.x = paper->GetWidth() / 10 ;
+ m_paperSize.y = paper->GetHeight() / 10 ;
+ }
+ else
+ {
+ // Shouldn't really get here
+ wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
+
+ m_paperId = wxPAPER_NONE;
+ m_paperSize.x = 0;
+ m_paperSize.y = 0;
+ }
+ }
+ else
+ {
+ // Shouldn't really get here
+ wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
+
+ m_paperId = wxPAPER_NONE;
+ m_paperSize.x = 0;
+ m_paperSize.y = 0;
+ }
+ }
+ else if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH))
+ {
+ m_paperSize.x = devMode->dmPaperWidth / 10;
+ m_paperSize.y = devMode->dmPaperLength / 10;
+ m_paperId = wxPAPER_NONE;
+ }
+ else
+ {
+ // Shouldn't really get here
+ wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
+
+ m_paperSize.x = 0;
+ m_paperSize.y = 0;
+ m_paperId = wxPAPER_NONE;
+ }
+#endif
+
+ //// Duplex
+
+ if (devMode->dmFields & DM_DUPLEX)
+ {
+ switch (devMode->dmDuplex)
+ {
+ case DMDUP_HORIZONTAL: {
+ m_duplexMode = wxDUPLEX_HORIZONTAL; break;
+ }
+ case DMDUP_VERTICAL: {
+ m_duplexMode = wxDUPLEX_VERTICAL; break;
+ }
+ default:
+ case DMDUP_SIMPLEX: {
+ m_duplexMode = wxDUPLEX_SIMPLEX; break;
+ }
+ }
+ }
+ else
+ m_duplexMode = wxDUPLEX_SIMPLEX;
+
+ //// Quality
+
+ if (devMode->dmFields & DM_PRINTQUALITY)
+ {
+ switch (devMode->dmPrintQuality)
+ {
+ case DMRES_MEDIUM: {
+ m_printQuality = wxPRINT_QUALITY_MEDIUM; break;
+ }
+ case DMRES_LOW: {
+ m_printQuality = wxPRINT_QUALITY_LOW; break;
+ }
+ case DMRES_DRAFT: {
+ m_printQuality = wxPRINT_QUALITY_DRAFT; break;
+ }
+ case DMRES_HIGH: {
+ m_printQuality = wxPRINT_QUALITY_HIGH; break;
+ }
+ default:
+ {
+ // TODO: if the printer fills in the resolution in DPI, how
+ // will the application know if it's high, low, draft etc.??
+ // wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
+ m_printQuality = devMode->dmPrintQuality; break;
+
+ }
+ }
+ }
+ else
+ m_printQuality = wxPRINT_QUALITY_HIGH;
+
+ GlobalUnlock(hDevMode);
+ }
+
+ if (hDevNames)
+ {
+ LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(hDevNames);
+ if (lpDevNames)
+ {
+ // TODO: Unicode-ification
+
+ // Get the port name
+ // port is obsolete in WIN32
+ // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
+
+ // Get the printer name
+ wxString printerName = (LPSTR)lpDevNames + lpDevNames->wDeviceOffset;
+
+ // Not sure if we should check for this mismatch
+// wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
+
+ if (printerName != wxT(""))
+ m_printerName = printerName;
+
+ GlobalUnlock(hDevNames);
+ }
+ }
+}
+
+#endif
+
+#ifdef __WXMAC__
+void wxPrintData::ConvertToNative()
+{
+ (**m_macPrintInfo).prJob.iCopies = m_printNoCopies ;
+}
+
+void wxPrintData::ConvertFromNative()
+{
+ m_printNoCopies = (**m_macPrintInfo).prJob.iCopies ;
+}
+#endif
+
+void wxPrintData::operator=(const wxPrintData& data)
+{
+#ifdef __WXMAC__
+ m_macPrintInfo = data.m_macPrintInfo ;
+ HandToHand( (Handle*) &m_macPrintInfo ) ;
+#endif
+ m_printNoCopies = data.m_printNoCopies;
+ m_printCollate = data.m_printCollate;
+ m_printOrientation = data.m_printOrientation;
+ m_printerName = data.m_printerName;
+ m_colour = data.m_colour;
+ m_duplexMode = data.m_duplexMode;
+ m_printQuality = data.m_printQuality;
+ m_paperId = data.m_paperId;
+ m_paperSize = data.m_paperSize;
+
+ // PostScript-specific data
+ m_printerCommand = data.m_printerCommand;
+ m_previewCommand = data.m_previewCommand;
+ m_printerOptions = data.m_printerOptions;
+ m_filename = data.m_filename;
+ m_afmPath = data.m_afmPath;
+ m_printerScaleX = data.m_printerScaleX;
+ m_printerScaleY = data.m_printerScaleY;
+ m_printerTranslateX = data.m_printerTranslateX;
+ m_printerTranslateY = data.m_printerTranslateY;
+ m_printMode = data.m_printMode;
+}
+
+// For compatibility
+#if wxCOMPATIBILITY_WITH_PRINTSETUPDATA
+void wxPrintData::operator=(const wxPrintSetupData& setupData)
+{
+ SetPrinterCommand(setupData.GetPrinterCommand());
+ SetPreviewCommand(setupData.GetPrintPreviewCommand());
+ SetPrinterOptions(setupData.GetPrinterOptions());
+
+ long xt, yt;
+ setupData.GetPrinterTranslation(& xt, & yt);
+ SetPrinterTranslation(xt, yt);
+
+ double xs, ys;
+ setupData.GetPrinterScaling(& xs, & ys);
+ SetPrinterScaling(xs, ys);
+
+ SetOrientation(setupData.GetPrinterOrientation());
+ SetPrintMode((wxPrintMode) setupData.GetPrinterMode());
+ SetFontMetricPath(setupData.GetAFMPath());
+ if (setupData.GetPaperName() != "")
+ SetPaperId(wxThePrintPaperDatabase->ConvertNameToId(setupData.GetPaperName()));
+ SetColour(setupData.GetColour());
+ SetFilename(setupData.GetPrinterFile());
+}
+#endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA
+
+
+// ----------------------------------------------------------------------------
+// Print dialog data
+// ----------------------------------------------------------------------------
+
+wxPrintDialogData::wxPrintDialogData()
+{
+#ifdef __WXMSW__
+ m_printDlgData = NULL;
+#endif
+ m_printFromPage = 0;
+ m_printToPage = 0;
+ m_printMinPage = 0;
+ m_printMaxPage = 0;
+ m_printNoCopies = 1;
+ m_printAllPages = FALSE;
+ m_printCollate = FALSE;
+ m_printToFile = FALSE;
+ m_printSelection = FALSE;
+ m_printEnableSelection = FALSE;
+ m_printEnablePageNumbers = TRUE;
+ m_printEnablePrintToFile = TRUE;
+ m_printEnableHelp = FALSE;
+ m_printSetupDialog = FALSE;
+}
+
+wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData)
+{
+#ifdef __WXMSW__
+ m_printDlgData = NULL;
+#endif
+ (*this) = dialogData;
+}
+
+wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData)
+{
+#ifdef __WXMSW__
+ m_printDlgData = NULL;
+#endif
+ m_printFromPage = 0;
+ m_printToPage = 0;
+ m_printMinPage = 0;
+ m_printMaxPage = 0;
+ m_printNoCopies = 1;
+ m_printAllPages = FALSE;
+ m_printCollate = FALSE;
+ m_printToFile = FALSE;
+ m_printSelection = FALSE;
+ m_printEnableSelection = FALSE;
+ m_printEnablePageNumbers = TRUE;
+ m_printEnablePrintToFile = TRUE;
+ m_printEnableHelp = FALSE;
+ m_printSetupDialog = FALSE;
+
+ m_printData = printData;
+}
+
+wxPrintDialogData::~wxPrintDialogData()
+{
+#ifdef __WXMSW__
+ PRINTDLG *pd = (PRINTDLG *) m_printDlgData;
+ if ( pd && pd->hDevMode )
+ GlobalFree(pd->hDevMode);
+ if ( pd )
+ delete pd;
+#endif
+}
+
+#ifdef __WXMSW__
+void wxPrintDialogData::ConvertToNative()
+{
+ m_printData.ConvertToNative();
+
+ PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
+
+ if (!pd)
+ {
+ pd = new PRINTDLG;
+ m_printDlgData = (void*) pd;
+
+ // GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
+#ifdef __GNUWIN32__
+ pd->lStructSize = 66 ;
+#else
+ pd->lStructSize = 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;
+ }
+
+ // Pass the devmode data to the PRINTDLG structure, since it'll
+ // be needed when PrintDlg is called.
+ if (pd->hDevMode)
+ {
+ GlobalFree(pd->hDevMode);