]> git.saurik.com Git - wxWidgets.git/commitdiff
First step at moving the print (dialog) native
authorRobert Roebling <robert@roebling.de>
Sun, 17 Oct 2004 17:25:40 +0000 (17:25 +0000)
committerRobert Roebling <robert@roebling.de>
Sun, 17 Oct 2004 17:25:40 +0000 (17:25 +0000)
   data into native dirs and cleaning up the code.
   The native part of wxPrintData is now created
   via the wxPrintFactory. I moved the code for
   PostScript to /src/generic/prntdlgg. and for
   MSW to its the respective dir. I only made
   wxMac compile, but it already has a native
   print data class, which should be easy to
   merge.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29947 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/cmndata.h
include/wx/generic/prntdlgg.h
include/wx/mac/carbon/printdlg.h
include/wx/msw/printdlg.h
include/wx/prntbase.h
src/common/cmndata.cpp
src/common/prntbase.cpp
src/generic/dcpsg.cpp
src/generic/prntdlgg.cpp
src/msw/dcprint.cpp
src/msw/printdlg.cpp

index 75eb6960fb9ab9944b5e3ce7810a74b33bc8d9b2..2c0ca1803bb83019c7a53a39a4702157ab0ed237 100644 (file)
 #include "wx/stream.h"
 #endif
 
+
+class WXDLLEXPORT wxPrintNativeDataBase;
+
+
 class WXDLLEXPORT wxColourData: public wxObject
 {
 public:
@@ -206,61 +210,22 @@ public:
     void SetQuality(wxPrintQuality quality) { m_printQuality = quality; }
     void SetBin(wxPrintBin bin) { m_bin = bin; }
 
-    // PostScript-specific data
-    const wxString& GetPrinterCommand() const { return m_printerCommand; }
-    const wxString& GetPrinterOptions() const { return m_printerOptions; }
-    const wxString& GetPreviewCommand() const { return m_previewCommand; }
-    const wxString& GetFilename() const { return m_filename; }
-    const wxString& GetFontMetricPath() const { return m_afmPath; }
-    double GetPrinterScaleX() const { return m_printerScaleX; }
-    double GetPrinterScaleY() const { return m_printerScaleY; }
-    long GetPrinterTranslateX() const { return m_printerTranslateX; }
-    long GetPrinterTranslateY() const { return m_printerTranslateY; }
-    wxPrintMode GetPrintMode() const { return m_printMode; }
-
-    void SetPrinterCommand(const wxString& command) { m_printerCommand = command; }
-    void SetPrinterOptions(const wxString& options) { m_printerOptions = options; }
-    void SetPreviewCommand(const wxString& command) { m_previewCommand = command; }
-    void SetFilename(const wxString& filename) { m_filename = filename; }
-    void SetFontMetricPath(const wxString& path) { m_afmPath = path; }
-    void SetPrinterScaleX(double x) { m_printerScaleX = x; }
-    void SetPrinterScaleY(double y) { m_printerScaleY = y; }
-    void SetPrinterScaling(double x, double y) { m_printerScaleX = x; m_printerScaleY = y; }
-    void SetPrinterTranslateX(long x) { m_printerTranslateX = x; }
-    void SetPrinterTranslateY(long y) { m_printerTranslateY = y; }
-    void SetPrinterTranslation(long x, long y) { m_printerTranslateX = x; m_printerTranslateY = y; }
-    void SetPrintMode(wxPrintMode printMode) { m_printMode = printMode; }
-
-#if wxUSE_STREAMS
-    wxOutputStream* GetOutputStream() { return m_outputstream; }
-    void SetOutputStream(wxOutputStream* outputstream) { m_outputstream = outputstream; }
-#endif
-
+    wxString GetFilename() const { return m_filename; }
+    void SetFilename( const wxString &filename ) { m_filename = filename; }
+    
     void operator=(const wxPrintData& data);
+    
+    wxPrintNativeDataBase *GetNativeData() const { return m_nativeData; }
 
-#if defined(__WXMSW__)
-    // Convert to/from the DEVMODE structure
+#if defined(__WXMAC__)
     void ConvertToNative();
     void ConvertFromNative();
-    void* GetNativeData() const { return m_devMode; }
-    void SetNativeData(void* data) { m_devMode = data; }
-    void* GetNativeDataDevNames() const { return m_devNames; }
-    void SetNativeDataDevNames(void* data) { m_devNames = data; }
-#elif defined(__WXMAC__)
-  void ConvertToNative();
-  void ConvertFromNative();
 #endif
 
 public:
-#if defined(__WXMSW__)
-    void*           m_devMode;
-    void*           m_devNames;
-#elif defined(__WXMAC__)
+#if defined(__WXMAC__)
     wxNativePrintData* m_nativePrintData ;
 #endif
-#if wxUSE_STREAMS
-    wxOutputStream* m_outputstream;
-#endif
 
 private:
     wxPrintBin      m_bin;
@@ -269,25 +234,16 @@ private:
     int             m_printOrientation;
     bool            m_printCollate;
 
-    // New members, 24/3/99
     wxString        m_printerName;
     bool            m_colour;
     wxDuplexMode    m_duplexMode;
     wxPrintQuality  m_printQuality;
     wxPaperSize     m_paperId;
     wxSize          m_paperSize;
-
-    // PostScript-specific data
-    wxString        m_printerCommand;
-    wxString        m_previewCommand;
-    wxString        m_printerOptions;
+    
     wxString        m_filename;
-    wxString        m_afmPath;
-    double          m_printerScaleX;
-    double          m_printerScaleY;
-    long            m_printerTranslateX;
-    long            m_printerTranslateY;
-    wxPrintMode     m_printMode;
+    
+    wxPrintNativeDataBase  *m_nativeData;
 
 private:
     DECLARE_DYNAMIC_CLASS(wxPrintData)
index 889d88e260f6bbd195474804e6f56199b60ffda7..15c632588f681221838f43a921d3f915500378f0 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "wx/dialog.h"
 #include "wx/cmndata.h"
+#include "wx/prntbase.h"
 #include "wx/printdlg.h"
 
 #if wxUSE_POSTSCRIPT
@@ -37,6 +38,7 @@ class WXDLLEXPORT wxStaticText;
 class WXDLLEXPORT wxRadioBox;
 class WXDLLEXPORT wxPrintSetupData;
 class WXDLLEXPORT wxPageSetupData;
+
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
@@ -71,12 +73,73 @@ enum
     wxPRINTID_PAPERSIZE
 };
 
+#if wxUSE_POSTSCRIPT
+
+//----------------------------------------------------------------------------
+// wxPostScriptNativeData
+//----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxPostScriptPrintNativeData: public wxPrintNativeDataBase
+{
+public:
+    wxPostScriptPrintNativeData();
+    virtual ~wxPostScriptPrintNativeData();
+    
+    virtual bool ConvertTo( wxPrintData &data );
+    virtual bool ConvertFrom( const wxPrintData &data );
+    
+    virtual bool Ok() const { return true; }
+    
+    const wxString& GetPrinterCommand() const { return m_printerCommand; }
+    const wxString& GetPrinterOptions() const { return m_printerOptions; }
+    const wxString& GetPreviewCommand() const { return m_previewCommand; }
+    const wxString& GetFontMetricPath() const { return m_afmPath; }
+    double GetPrinterScaleX() const { return m_printerScaleX; }
+    double GetPrinterScaleY() const { return m_printerScaleY; }
+    long GetPrinterTranslateX() const { return m_printerTranslateX; }
+    long GetPrinterTranslateY() const { return m_printerTranslateY; }
+    wxPrintMode GetPrintMode() const { return m_printMode; }
+
+    void SetPrinterCommand(const wxString& command) { m_printerCommand = command; }
+    void SetPrinterOptions(const wxString& options) { m_printerOptions = options; }
+    void SetPreviewCommand(const wxString& command) { m_previewCommand = command; }
+    void SetFontMetricPath(const wxString& path) { m_afmPath = path; }
+    void SetPrinterScaleX(double x) { m_printerScaleX = x; }
+    void SetPrinterScaleY(double y) { m_printerScaleY = y; }
+    void SetPrinterScaling(double x, double y) { m_printerScaleX = x; m_printerScaleY = y; }
+    void SetPrinterTranslateX(long x) { m_printerTranslateX = x; }
+    void SetPrinterTranslateY(long y) { m_printerTranslateY = y; }
+    void SetPrinterTranslation(long x, long y) { m_printerTranslateX = x; m_printerTranslateY = y; }
+    void SetPrintMode(wxPrintMode printMode) { m_printMode = printMode; }
+
+#if wxUSE_STREAMS
+    wxOutputStream *GetOutputStream() { return m_outputStream; }
+    void SetOutputStream( wxOutputStream *output ) { m_outputStream = output; }
+#endif
+
+private:
+    wxString        m_printerCommand;
+    wxString        m_previewCommand;
+    wxString        m_printerOptions;
+    wxString        m_afmPath;
+    double          m_printerScaleX;
+    double          m_printerScaleY;
+    long            m_printerTranslateX;
+    long            m_printerTranslateY;
+    wxPrintMode     m_printMode;
+#if wxUSE_STREAMS
+    wxOutputStream *m_outputStream;
+#endif
+    
+private:
+    DECLARE_DYNAMIC_CLASS(wxPostScriptPrintNativeData)
+};
+    
 // ----------------------------------------------------------------------------
 // Simulated Print and Print Setup dialogs for non-Windows platforms (and
 // Windows using PostScript print/preview)
 // ----------------------------------------------------------------------------
 
-#if wxUSE_POSTSCRIPT
 class WXDLLEXPORT wxGenericPrintDialog : public wxPrintDialogBase
 {
 public:
index 57141635927babc411052a4655c02947ca08ac77..6c895d24346f5c00bb7ef8fa9e321f42664efacb 100644 (file)
 #include "wx/dialog.h"
 #include "wx/cmndata.h"
 #include "wx/printdlg.h"
+#include "wx/prntbase.h"
 
+//----------------------------------------------------------------------------
+// wxMacPrintNativeData
+//----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxMacPrintNativeData: public wxPrintNativeDataBase
+{
+public:
+    wxMacPrintNativeData() {};
+    virtual ~wxMacPrintNativeData() {};
+    
+    virtual bool ConvertTo( wxPrintData &data ) { return true; }
+    virtual bool ConvertFrom( const wxPrintData &data ) { return true; }
+    
+    virtual bool Ok() const { return true; }
+};
+    
 /*
  * wxPrinterDialog
  * The common dialog for printing.
index a9104dc3eb14da6d709f3148fd68ad0493881420..b8bebcc695227a13166109759577f40e1d41df9e 100644 (file)
 
 #include "wx/dialog.h"
 #include "wx/cmndata.h"
+#include "wx/prntbase.h"
 #include "wx/printdlg.h"
 
 class WXDLLEXPORT wxDC;
 
+//----------------------------------------------------------------------------
+// wxWindowsPrintNativeData
+//----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxWindowsPrintNativeData: public wxPrintNativeDataBase
+{
+public:
+    wxWindowsPrintNativeData();
+    virtual ~wxWindowsPrintNativeData();
+    
+    virtual bool ConvertTo( wxPrintData &data );
+    virtual bool ConvertFrom( const wxPrintData &data );
+    
+    virtual bool Ok() const;
+    
+    void* GetNativeData() const { return m_devMode; }
+    void SetNativeData(void* data) { m_devMode = data; }
+    void* GetNativeDataDevNames() const { return m_devNames; }
+    void SetNativeDataDevNames(void* data) { m_devNames = data; }
+    
+private:
+    void*           m_devMode;
+    void*           m_devNames;
+
+private:
+    DECLARE_DYNAMIC_CLASS(wxWindowsPrintNativeData)
+};
+    
 // ---------------------------------------------------------------------------
 // wxPrinterDialog: the common dialog for printing.
 // ---------------------------------------------------------------------------
index f567b1bec14eff534bc426511c33fd40b1e3e002..4da1b0c9befdf66d23ee72dce7d8e46f09b31799 100644 (file)
@@ -39,6 +39,7 @@ class WXDLLEXPORT wxPreviewCanvas;
 class WXDLLEXPORT wxPreviewControlBar;
 class WXDLLEXPORT wxPreviewFrame;
 class WXDLLEXPORT wxPrintFactory;
+class WXDLLEXPORT wxPrintNativeDataBase;
 
 //----------------------------------------------------------------------------
 // error consts
@@ -77,6 +78,8 @@ public:
                                                   wxPrintDialogData *data = NULL ) = 0;
     virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent, 
                                                   wxPrintData *data ) = 0;
+                                                  
+    virtual wxPrintNativeDataBase *CreatePrintNativeData() = 0;
     
     static void SetPrintFactory( wxPrintFactory *factory );
     static wxPrintFactory *GetFactory();
@@ -104,6 +107,30 @@ public:
                                                   wxPrintDialogData *data = NULL );
     virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent, 
                                                   wxPrintData *data );
+                                                  
+    virtual wxPrintNativeDataBase *CreatePrintNativeData();
+};
+
+//----------------------------------------------------------------------------
+// wxPrintNativeDataBase
+//----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxPrintNativeDataBase: public wxObject
+{
+public:
+    wxPrintNativeDataBase();
+    virtual ~wxPrintNativeDataBase() {}
+    
+    virtual bool ConvertTo( wxPrintData &data ) = 0;
+    virtual bool ConvertFrom( const wxPrintData &data ) = 0; 
+    
+    virtual bool Ok() const = 0;
+    
+    int  m_ref;
+    
+private:
+    DECLARE_CLASS(wxPrintNativeDataBase)
+    DECLARE_NO_COPY_CLASS(wxPrintNativeDataBase)
 };
 
 //----------------------------------------------------------------------------
index 07040ea1e8b803dd7dd3b81b1863534a5dc17392..d24faf8713319c9522236ee72e35c87759e2af0a 100644 (file)
@@ -38,6 +38,8 @@
 #include "wx/gdicmn.h"
 #include "wx/cmndata.h"
 #include "wx/log.h"
+#include "wx/prntbase.h"
+#include "wx/printdlg.h"
 
 #if wxUSE_FONTDLG
     #include "wx/fontdlg.h"
@@ -165,10 +167,7 @@ wxFontDialogBase::~wxFontDialogBase()
 
 wxPrintData::wxPrintData()
 {
-#ifdef __WXMSW__
-    m_devMode = (void*) NULL;
-    m_devNames = (void*) NULL;
-#elif defined( __WXMAC__ )
+#ifdef __WXMAC__
     m_nativePrintData = wxNativePrintData::Create() ;
 #endif
     m_bin = wxPRINTBIN_DEFAULT;
@@ -184,536 +183,28 @@ wxPrintData::wxPrintData()
     m_paperId = wxPAPER_A4;
     m_paperSize = wxSize(210, 297);
 
-    // PostScript-specific data
-    m_previewCommand = wxT("");
-    m_filename = wxT("");
-#ifdef __VMS__
-    m_printerCommand = wxT("print");
-    m_printerOptions = wxT("/nonotify/queue=psqueue");
-    m_afmPath = wxT("sys$ps_font_metrics:");
-#endif
-
-#ifdef __WXMSW__
-    m_printerCommand = wxT("print");
-    m_printerOptions = wxT("");
-    m_afmPath = wxT("c:\\windows\\system\\");
-#endif
-
-#if !defined(__VMS__) && !defined(__WXMSW__)
-    m_printerCommand = wxT("lpr");
-    m_printerOptions = wxT("");
-    m_afmPath = wxT("");
-#endif
-
-    m_printerScaleX = 1.0;
-    m_printerScaleY = 1.0;
-    m_printerTranslateX = 0;
-    m_printerTranslateY = 0;
-    m_printMode = wxPRINT_MODE_FILE;
-
-#ifdef wxUSE_STREAMS
-    m_outputstream = NULL;
-#endif
+    m_nativeData = wxPrintFactory::GetFactory()->CreatePrintNativeData();
 }
 
 wxPrintData::wxPrintData(const wxPrintData& printData)
     : wxObject()
 {
-#ifdef __WXMSW__
-    m_devMode = (void*) NULL;
-    m_devNames = (void*) NULL;
-#elif defined( __WXMAC__ )
-    m_nativePrintData = wxNativePrintData::Create() ;
-#endif
     (*this) = printData;
 }
 
 wxPrintData::~wxPrintData()
 {
-#ifdef __WXMSW__
-    HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
-    if ( hDevMode )
-        GlobalFree(hDevMode);
-    HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
-    if ( hDevNames )
-        GlobalFree(hDevNames);
-#elif defined(__WXMAC__)
+    m_nativeData->m_ref--;
+    if (m_nativeData->m_ref == 0) 
+        delete m_nativeData;
+        
+#ifdef __WXMAC__
     delete m_nativePrintData ;
 #endif
 }
 
-#if defined(__WXMSW__) // && defined(__WIN32__)
-
-#if defined(__WXDEBUG__) && defined(__WIN32__)
-static wxString wxGetPrintDlgError()
-{
-    DWORD err = CommDlgExtendedError();
-    wxString msg = wxT("Unknown");
-    switch (err)
-    {
-        case CDERR_FINDRESFAILURE: msg = wxT("CDERR_FINDRESFAILURE"); break;
-        case CDERR_INITIALIZATION: msg = wxT("CDERR_INITIALIZATION"); break;
-        case CDERR_LOADRESFAILURE: msg = wxT("CDERR_LOADRESFAILURE"); break;
-        case CDERR_LOADSTRFAILURE: msg = wxT("CDERR_LOADSTRFAILURE"); break;
-        case CDERR_LOCKRESFAILURE: msg = wxT("CDERR_LOCKRESFAILURE"); break;
-        case CDERR_MEMALLOCFAILURE: msg = wxT("CDERR_MEMALLOCFAILURE"); break;
-        case CDERR_MEMLOCKFAILURE: msg = wxT("CDERR_MEMLOCKFAILURE"); break;
-        case CDERR_NOHINSTANCE: msg = wxT("CDERR_NOHINSTANCE"); break;
-        case CDERR_NOHOOK: msg = wxT("CDERR_NOHOOK"); break;
-        case CDERR_NOTEMPLATE: msg = wxT("CDERR_NOTEMPLATE"); break;
-        case CDERR_STRUCTSIZE: msg = wxT("CDERR_STRUCTSIZE"); break;
-        case  PDERR_RETDEFFAILURE: msg = wxT("PDERR_RETDEFFAILURE"); break;
-        case  PDERR_PRINTERNOTFOUND: msg = wxT("PDERR_PRINTERNOTFOUND"); break;
-        case  PDERR_PARSEFAILURE: msg = wxT("PDERR_PARSEFAILURE"); break;
-        case  PDERR_NODEVICES: msg = wxT("PDERR_NODEVICES"); break;
-        case  PDERR_NODEFAULTPRN: msg = wxT("PDERR_NODEFAULTPRN"); break;
-        case  PDERR_LOADDRVFAILURE: msg = wxT("PDERR_LOADDRVFAILURE"); break;
-        case  PDERR_INITFAILURE: msg = wxT("PDERR_INITFAILURE"); break;
-        case  PDERR_GETDEVMODEFAIL: msg = wxT("PDERR_GETDEVMODEFAIL"); break;
-        case  PDERR_DNDMMISMATCH: msg = wxT("PDERR_DNDMMISMATCH"); break;
-        case  PDERR_DEFAULTDIFFERENT: msg = wxT("PDERR_DEFAULTDIFFERENT"); break;
-        case  PDERR_CREATEICFAILURE: msg = wxT("PDERR_CREATEICFAILURE"); break;
-        default: break;
-    }
-    return msg;
-}
-#endif
-
-static HGLOBAL wxCreateDevNames(const wxString& driverName, const wxString& printerName, const wxString& portName)
-{
-    HGLOBAL hDev = NULL;
-    // if (!driverName.IsEmpty() && !printerName.IsEmpty() && !portName.IsEmpty())
-    if (driverName.IsEmpty() && printerName.IsEmpty() && portName.IsEmpty())
-    {
-    }
-    else
-    {
-        hDev = GlobalAlloc(GPTR, 4*sizeof(WORD)+
-                           ( driverName.Length() + 1 +
-            printerName.Length() + 1 +
-                             portName.Length()+1 ) * sizeof(wxChar) );
-        LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(hDev);
-        lpDev->wDriverOffset = sizeof(WORD) * 4 / sizeof(wxChar);
-        wxStrcpy((wxChar*)lpDev + lpDev->wDriverOffset, driverName);
-
-        lpDev->wDeviceOffset = (WORD)( lpDev->wDriverOffset +
-                                       driverName.Length() + 1 );
-        wxStrcpy((wxChar*)lpDev + lpDev->wDeviceOffset, printerName);
-
-        lpDev->wOutputOffset = (WORD)( lpDev->wDeviceOffset +
-                                       printerName.Length() + 1 );
-        wxStrcpy((wxChar*)lpDev + lpDev->wOutputOffset, portName);
-
-        lpDev->wDefault = 0;
-
-        GlobalUnlock(hDev);
-    }
-
-    return hDev;
-}
-
-void wxPrintData::ConvertToNative()
-{
-    HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
-    HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
-    if (!hDevMode)
-    {
-        // Use PRINTDLG as a way of creating a DEVMODE object
-        PRINTDLG pd;
-
-        // 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));
-#ifdef __WXWINCE__
-        pd.cbStruct    = sizeof(PRINTDLG);
-#else
-        pd.lStructSize    = sizeof(PRINTDLG);
-#endif
-#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
-        {
-            hDevMode = pd.hDevMode;
-            m_devMode = (void*)(long) hDevMode;
-            pd.hDevMode = NULL;
-
-            // We'll create a new DEVNAMEs structure below.
-            if ( pd.hDevNames )
-                GlobalFree(pd.hDevNames);
-            pd.hDevNames = NULL;
-
-            // hDevNames = pd->hDevNames;
-            // m_devNames = (void*)(long) hDevNames;
-            // pd->hDevnames = NULL;
-
-        }
-    }
-
-    if ( hDevMode )
-    {
-        LPDEVMODE devMode = (LPDEVMODE) GlobalLock(hDevMode);
-
-        //// Orientation
-
-        devMode->dmOrientation = (short)m_printOrientation;
-
-        //// Collation
-
-        devMode->dmCollate = (m_printCollate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE);
-        devMode->dmFields |= DM_COLLATE;
-
-        //// Number of copies
-
-        devMode->dmCopies = (short)m_printNoCopies;
-        devMode->dmFields |= DM_COPIES;
-
-        //// Printer name
-
-        if (m_printerName != wxT(""))
-        {
-            //int len = wxMin(31, m_printerName.Len());
-            wxStrncpy((wxChar*)devMode->dmDeviceName,m_printerName.c_str(),31);
-            devMode->dmDeviceName[31] = wxT('\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 is in tenths of a milimeter
-            devMode->dmPaperWidth = (short)(m_paperSize.x * 10);
-            devMode->dmPaperLength = (short)(m_paperSize.y * 10);
-            devMode->dmPaperSize = DMPAPER_USER;
-            devMode->dmFields |= DM_PAPERWIDTH;
-            devMode->dmFields |= DM_PAPERLENGTH;
-        }
-        else
-        {
-            if (wxThePrintPaperDatabase)
-            {
-                wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType(m_paperId);
-                if (paper)
-                {
-                    devMode->dmPaperSize = (short)paper->GetPlatformId();
-                    devMode->dmFields |= DM_PAPERSIZE;
-                }
-            }
-        }
-
-        //// Duplex
-
-        short duplex;
-        switch (m_duplexMode)
-        {
-            case wxDUPLEX_HORIZONTAL:
-                duplex = DMDUP_HORIZONTAL;
-                break;
-            case wxDUPLEX_VERTICAL:
-                duplex = DMDUP_VERTICAL;
-                break;
-            default:
-            // in fact case wxDUPLEX_SIMPLEX:
-                duplex = DMDUP_SIMPLEX;
-                break;
-        }
-        devMode->dmDuplex = duplex;
-        devMode->dmFields |= DM_DUPLEX;
-
-        //// Quality
-
-        short 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 = (short)m_printQuality;
-                break;
-        }
-        devMode->dmPrintQuality = quality;
-        devMode->dmFields |= DM_PRINTQUALITY;
-
-        if ( m_bin != wxPRINTBIN_DEFAULT )
-        {
-            switch ( m_bin )
-            {
-                case wxPRINTBIN_ONLYONE:        devMode->dmDefaultSource = DMBIN_ONLYONE;       break;
-                case wxPRINTBIN_LOWER:          devMode->dmDefaultSource = DMBIN_LOWER;         break;
-                case wxPRINTBIN_MIDDLE:         devMode->dmDefaultSource = DMBIN_MIDDLE;        break;
-                case wxPRINTBIN_MANUAL:         devMode->dmDefaultSource = DMBIN_MANUAL;        break;
-                case wxPRINTBIN_ENVELOPE:       devMode->dmDefaultSource = DMBIN_ENVELOPE;      break;
-                case wxPRINTBIN_ENVMANUAL:      devMode->dmDefaultSource = DMBIN_ENVMANUAL;     break;
-                case wxPRINTBIN_AUTO:           devMode->dmDefaultSource = DMBIN_AUTO;          break;
-                case wxPRINTBIN_TRACTOR:        devMode->dmDefaultSource = DMBIN_TRACTOR;       break;
-                case wxPRINTBIN_SMALLFMT:       devMode->dmDefaultSource = DMBIN_SMALLFMT;      break;
-                case wxPRINTBIN_LARGEFMT:       devMode->dmDefaultSource = DMBIN_LARGEFMT;      break;
-                case wxPRINTBIN_LARGECAPACITY:  devMode->dmDefaultSource = DMBIN_LARGECAPACITY; break;
-                case wxPRINTBIN_CASSETTE:       devMode->dmDefaultSource = DMBIN_CASSETTE;      break;
-                case wxPRINTBIN_FORMSOURCE:     devMode->dmDefaultSource = DMBIN_FORMSOURCE;    break;
-
-                default:
-                    devMode->dmDefaultSource = (short)(DMBIN_USER + m_bin - wxPRINTBIN_USER);
-                    break;
-            }
-
-            devMode->dmFields |= DM_DEFAULTSOURCE;
-        }
-
-        GlobalUnlock(hDevMode);
-    }
-
-    if ( hDevNames )
-    {
-        GlobalFree(hDevNames);
-    }
-
-    // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
-    m_devNames = (void*) (long) wxCreateDevNames(wxT(""), m_printerName, wxT(""));
-}
-
-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);
-
-        //// Orientation
-
-        if (devMode->dmFields & DM_ORIENTATION)
-            m_printOrientation = devMode->dmOrientation;
-
-        //// Collation
-
-        if (devMode->dmFields & DM_COLLATE)
-        {
-            if (devMode->dmCollate == DMCOLLATE_TRUE)
-                m_printCollate = true;
-            else
-                m_printCollate = false;
-        }
-
-        //// Number of copies
-
-        if (devMode->dmFields & DM_COPIES)
-        {
-            m_printNoCopies = devMode->dmCopies;
-        }
-
-        if (devMode->dmFields & DM_DEFAULTSOURCE)
-        {
-            m_bin = (wxPrintBin)devMode->dmDefaultSource;
-        }
-
-        //// Printer name
-
-        if (devMode->dmDeviceName[0] != 0)
-        {
-            m_printerName = devMode->dmDeviceName;
-        }
-
-        //// Colour
-
-        if (devMode->dmFields & DM_COLOR)
-        {
-            if (devMode->dmColor == DMCOLOR_COLOR)
-                m_colour = true;
-            else
-                m_colour = false;
-        }
-        else
-            m_colour = true;
-
-        //// Paper size
-
-        // We don't know size of user defined paper and some buggy drivers
-        // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
-        // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
-        // code wouldn't set m_paperSize correctly.
-        if ((devMode->dmFields & DM_PAPERSIZE) && (devMode->dmPaperSize < DMPAPER_USER))
-        {
-            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))
-        {
-            // DEVMODE is in tenths of a milimeter
-            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;
-        }
-
-        //// 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 = (LPTSTR)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_nativePrintData->TransferFrom( this ) ;
@@ -723,14 +214,10 @@ void wxPrintData::ConvertFromNative()
 {
     m_nativePrintData->TransferTo( this ) ;
 }
-
 #endif
 
 void wxPrintData::operator=(const wxPrintData& data)
 {
-#ifdef __WXMAC__
-    m_nativePrintData->CopyFrom( data.m_nativePrintData ) ;
-#endif
     m_printNoCopies = data.m_printNoCopies;
     m_printCollate = data.m_printCollate;
     m_printOrientation = data.m_printOrientation;
@@ -741,32 +228,21 @@ void wxPrintData::operator=(const wxPrintData& data)
     m_paperId = data.m_paperId;
     m_paperSize = data.m_paperSize;
     m_bin = data.m_bin;
-#ifdef wxUSE_STREAMS
-    m_outputstream = data.m_outputstream;
+    
+    m_nativeData = data.GetNativeData();
+    m_nativeData->m_ref++;
+    
+#ifdef __WXMAC__
+    m_nativePrintData->CopyFrom( data.m_nativePrintData ) ;
 #endif
-
-    // 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;
 }
 
 // Is this data OK for showing the print dialog?
 bool wxPrintData::Ok() const
 {
-#ifdef __WXMSW__
-    ((wxPrintData*)this)->ConvertToNative();
-    return (m_devMode != NULL) ;
-#else
-    return true;
-#endif
+    m_nativeData->ConvertFrom( *this );
+
+    return m_nativeData->Ok();
 }
 
 // ----------------------------------------------------------------------------
@@ -840,7 +316,9 @@ wxPrintDialogData::~wxPrintDialogData()
 #ifdef __WXMSW__
 void wxPrintDialogData::ConvertToNative()
 {
-    m_printData.ConvertToNative();
+    wxWindowsPrintNativeData *data =
+        (wxWindowsPrintNativeData *) m_printData.GetNativeData();
+    data->ConvertFrom( m_printData );
 
     PRINTDLG *pd = (PRINTDLG*) m_printDlgData;
 
@@ -878,16 +356,16 @@ void wxPrintDialogData::ConvertToNative()
         GlobalFree(pd->hDevNames);
     }
 
-    pd->hDevMode = (HGLOBAL)(DWORD) m_printData.GetNativeData();
+    pd->hDevMode = (HGLOBAL)(DWORD) data->GetNativeData();
 
-    m_printData.SetNativeData((void*) NULL);
+    data->SetNativeData((void*) NULL);
 
     // Shouldn't assert; we should be able to test Ok-ness at a higher level
     //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
 
-    pd->hDevNames = (HGLOBAL)(DWORD) m_printData.GetNativeDataDevNames();
+    pd->hDevNames = (HGLOBAL)(DWORD) data->GetNativeDataDevNames();
 
-    m_printData.SetNativeDataDevNames((void*) NULL);
+    data->SetNativeDataDevNames((void*) NULL);
 
     pd->hDC = (HDC) NULL;
     pd->nFromPage = (WORD)m_printFromPage;
@@ -943,33 +421,36 @@ void wxPrintDialogData::ConvertFromNative()
     if ( pd == NULL )
         return;
 
+    wxWindowsPrintNativeData *data =
+        (wxWindowsPrintNativeData *) m_printData.GetNativeData();
+    
     // Pass the devmode data back to the wxPrintData structure where it really belongs.
     if (pd->hDevMode)
     {
-        if (m_printData.GetNativeData())
+        if (data->GetNativeData())
         {
             // Make sure we don't leak memory
-            GlobalFree((HGLOBAL)(DWORD) m_printData.GetNativeData());
+            GlobalFree( (HGLOBAL)(DWORD) data->GetNativeData() );
         }
-        m_printData.SetNativeData((void*)(long) pd->hDevMode);
+        data->SetNativeData( (void*)(long) pd->hDevMode );
         pd->hDevMode = NULL;
     }
 
     // Pass the devnames data back to the wxPrintData structure where it really belongs.
     if (pd->hDevNames)
     {
-        if (m_printData.GetNativeDataDevNames())
+        if (data->GetNativeDataDevNames())
         {
             // Make sure we don't leak memory
-            GlobalFree((HGLOBAL)(DWORD) m_printData.GetNativeDataDevNames());
+            GlobalFree((HGLOBAL)(DWORD) data->GetNativeDataDevNames());
         }
-        m_printData.SetNativeDataDevNames((void*)(long) pd->hDevNames);
+        data->SetNativeDataDevNames((void*)(long) pd->hDevNames);
         pd->hDevNames = NULL;
     }
 
     // Now convert the DEVMODE object, passed down from the PRINTDLG object,
     // into wxWidgets form.
-    m_printData.ConvertFromNative();
+    data->ConvertTo( m_printData );
 
     m_printFromPage = pd->nFromPage;
     m_printToPage = pd->nToPage;
@@ -1165,7 +646,9 @@ wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data)
 #if defined(__WIN95__)
 void wxPageSetupDialogData::ConvertToNative()
 {
-    m_printData.ConvertToNative();
+    wxWindowsPrintNativeData *data =
+        (wxWindowsPrintNativeData *) m_printData.GetNativeData();
+    data->ConvertFrom( m_printData );
 
     PAGESETUPDLG *pd = (PAGESETUPDLG*) m_pageSetupData;
 
@@ -1187,9 +670,9 @@ void wxPageSetupDialogData::ConvertToNative()
         pd->hDevMode = NULL;
     }
 
-    pd->hDevMode = (HGLOBAL) m_printData.GetNativeData();
+    pd->hDevMode = (HGLOBAL) data->GetNativeData();
 
-    m_printData.SetNativeData((void*) NULL);
+    data->SetNativeData((void*) NULL);
 
     // Shouldn't assert; we should be able to test Ok-ness at a higher level
     //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
@@ -1204,9 +687,9 @@ void wxPageSetupDialogData::ConvertToNative()
         pd->hDevNames = NULL;
     }
 
-    pd->hDevNames = (HGLOBAL) m_printData.GetNativeDataDevNames();
+    pd->hDevNames = (HGLOBAL) data->GetNativeDataDevNames();
 
-    m_printData.SetNativeDataDevNames((void*) NULL);
+    data->SetNativeDataDevNames((void*) NULL);
 
 //        pd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, sizeof(DEVMODE));
 
@@ -1273,33 +756,36 @@ void wxPageSetupDialogData::ConvertFromNative()
     if ( !pd )
         return;
 
+    wxWindowsPrintNativeData *data =
+        (wxWindowsPrintNativeData *) m_printData.GetNativeData();
+        
     // Pass the devmode data back to the wxPrintData structure where it really belongs.
     if (pd->hDevMode)
     {
-        if (m_printData.GetNativeData())
+        if (data->GetNativeData())
         {
             // Make sure we don't leak memory
-            GlobalFree((HGLOBAL) m_printData.GetNativeData());
+            GlobalFree((HGLOBAL) data->GetNativeData());
         }
-        m_printData.SetNativeData((void*) pd->hDevMode);
+        data->SetNativeData((void*) pd->hDevMode);
         pd->hDevMode = NULL;
     }
 
-    m_printData.ConvertFromNative();
+    data->ConvertTo( m_printData );
 
     // Pass the devnames data back to the wxPrintData structure where it really belongs.
     if (pd->hDevNames)
     {
-        if (m_printData.GetNativeDataDevNames())
+        if (data->GetNativeDataDevNames())
         {
             // Make sure we don't leak memory
-            GlobalFree((HGLOBAL) m_printData.GetNativeDataDevNames());
+            GlobalFree((HGLOBAL) data->GetNativeDataDevNames());
         }
-        m_printData.SetNativeDataDevNames((void*) pd->hDevNames);
+        data->SetNativeDataDevNames((void*) pd->hDevNames);
         pd->hDevNames = NULL;
     }
 
-    m_printData.ConvertFromNative();
+    data->ConvertTo( m_printData );
 
     pd->Flags = PSD_MARGINS|PSD_MINMARGINS;
 
index 7812017f5b42ca74ce1aa96d638e703bab3a262f..d6dc62a0a45cb985316c4be44ed3203b8093b9c0 100644 (file)
@@ -146,6 +146,28 @@ wxPrintDialogBase *wxNativePrintFactory::CreatePrintDialog( wxWindow *parent,
 #endif
 }
 
+wxPrintNativeDataBase *wxNativePrintFactory::CreatePrintNativeData()
+{
+#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
+    return new wxWindowsPrintNativeData;
+#elif defined(__WXMAC__)
+    return new wxMacPrintNativeData;
+#else
+    return new wxPostScriptPrintNativeData;
+#endif
+}
+
+//----------------------------------------------------------------------------
+// wxPrintNativeDataBase
+//----------------------------------------------------------------------------
+
+IMPLEMENT_ABSTRACT_CLASS(wxPrintNativeDataBase, wxObject)
+
+wxPrintNativeDataBase::wxPrintNativeDataBase()
+{ 
+    m_ref = 1; 
+}
+
 //----------------------------------------------------------------------------
 // wxPrinterBase
 //----------------------------------------------------------------------------
index 5fc793f2509921e36aaaffa1cc50052b9954bb9e..545d25a5c54c2a8a8ac61f185fb4f256edac6cb7 100644 (file)
@@ -36,6 +36,7 @@
 #include "wx/log.h"
 #include "wx/generic/dcpsg.h"
 #include "wx/prntbase.h"
+#include "wx/generic/prntdlgg.h"
 #include "wx/paper.h"
 #include "wx/filefn.h"
 #if WXWIN_COMPATIBILITY_2_2
@@ -1799,8 +1800,11 @@ wxSize wxPostScriptDC::GetPPI(void) const
 bool wxPostScriptDC::StartDoc( const wxString& message )
 {
     wxCHECK_MSG( m_ok, false, wxT("invalid postscript dc") );
+    
+    wxPostScriptPrintNativeData *data = 
+        (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
 
-    if ( m_printData.GetPrintMode() != wxPRINT_MODE_STREAM )
+    if (data->GetPrintMode() != wxPRINT_MODE_STREAM )
     {
         if (m_printData.GetFilename() == wxEmptyString)
         {
@@ -1963,13 +1967,16 @@ void wxPostScriptDC::EndDoc ()
     PsPrintf( wxT("%% %d %d lineto closepath stroke\n"), llx, ury );
 #endif
 
-#if defined(__X__) || defined(__WXGTK__)
-    if (m_ok && (m_printData.GetPrintMode() == wxPRINT_MODE_PRINTER))
+#ifndef __WXMSW__
+    wxPostScriptPrintNativeData *data = 
+        (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+
+    if (m_ok && (data->GetPrintMode() == wxPRINT_MODE_PRINTER))
     {
         wxString command;
-        command += m_printData.GetPrinterCommand();
+        command += data->GetPrinterCommand();
         command += wxT(" ");
-        command += m_printData.GetPrinterOptions();
+        command += data->GetPrinterOptions();
         command += wxT(" ");
         command += m_printData.GetFilename();
 
@@ -1998,11 +2005,14 @@ void wxPostScriptDC::StartPage()
     wxCoord translate_x, translate_y;
     double scale_x, scale_y;
 
-    translate_x = (wxCoord)m_printData.GetPrinterTranslateX();
-    translate_y = (wxCoord)m_printData.GetPrinterTranslateY();
+    wxPostScriptPrintNativeData *data = 
+        (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+
+    translate_x = (wxCoord)data->GetPrinterTranslateX();
+    translate_y = (wxCoord)data->GetPrinterTranslateY();
 
-    scale_x = m_printData.GetPrinterScaleX();
-    scale_y = m_printData.GetPrinterScaleY();
+    scale_x = data->GetPrinterScaleX();
+    scale_y = data->GetPrinterScaleY();
 
     if (m_printData.GetOrientation() == wxLANDSCAPE)
     {
@@ -2245,11 +2255,14 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string,
 
         FILE *afmFile = NULL;
 
+        wxPostScriptPrintNativeData *data = 
+            (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+            
         // Get the directory of the AFM files
         wxString afmName;
-        if (!m_printData.GetFontMetricPath().IsEmpty())
+        if (!data->GetFontMetricPath().IsEmpty())
         {
-            afmName = m_printData.GetFontMetricPath();
+            afmName = data->GetFontMetricPath();
             afmName << wxFILE_SEP_PATH << name;
             afmFile = wxFopen(afmName,wxT("r"));
         }
@@ -2465,13 +2478,16 @@ void wxPostScriptDC::PsPrintf( const wxChar* fmt, ... )
 
 void wxPostScriptDC::PsPrint( const char* psdata )
 {
-    switch( m_printData.GetPrintMode() )
+    wxPostScriptPrintNativeData *data = 
+        (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+
+    switch(data->GetPrintMode())
     {
 #if wxUSE_STREAMS
         // append to output stream
         case wxPRINT_MODE_STREAM:
             {
-                wxOutputStream* outputstream = m_printData.GetOutputStream();
+                wxOutputStream* outputstream = data->GetOutputStream();
                 wxCHECK_RET( outputstream, wxT("invalid outputstream") );
                 outputstream->Write( psdata, strlen( psdata ) );
             }
@@ -2487,13 +2503,16 @@ void wxPostScriptDC::PsPrint( const char* psdata )
 
 void wxPostScriptDC::PsPrint( int ch )
 {
-    switch( m_printData.GetPrintMode() )
+    wxPostScriptPrintNativeData *data = 
+        (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+
+    switch (data->GetPrintMode())
     {
 #if wxUSE_STREAMS
         // append to output stream
         case wxPRINT_MODE_STREAM:
             {
-                wxOutputStream* outputstream = m_printData.GetOutputStream();
+                wxOutputStream* outputstream = data->GetOutputStream();
                 wxCHECK_RET( outputstream, wxT("invalid outputstream") );
                 outputstream->PutC( ch );
             }
index e2dc8e9920b984580f0463ceebcb6aa07ef752a8..b7538e9d00d8c15cdaab73813cebc0e28a50ff59 100644 (file)
@@ -56,6 +56,7 @@
     #include "wx/generic/dcpsg.h"
 #endif
 
+#include "wx/prntbase.h"
 #include "wx/printdlg.h"
 #include "wx/paper.h"
 #include "wx/filename.h"
 #include <string.h>
 
 // ----------------------------------------------------------------------------
-// wxWin macros
+// global vars
 // ----------------------------------------------------------------------------
 
+extern wxPrintPaperDatabase *wxThePrintPaperDatabase;
 
 #if wxUSE_POSTSCRIPT
 
-IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog)
+//----------------------------------------------------------------------------
+// wxPostScriptNativeData
+//----------------------------------------------------------------------------
 
-#endif // wxUSE_POSTSCRIPT
+IMPLEMENT_CLASS(wxPostScriptPrintNativeData, wxPrintNativeDataBase)
 
-IMPLEMENT_CLASS(wxGenericPageSetupDialog, wxDialog)
+wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
+{
+    m_previewCommand = wxT("");
+#ifdef __VMS__
+    m_printerCommand = wxT("print");
+    m_printerOptions = wxT("/nonotify/queue=psqueue");
+    m_afmPath = wxT("sys$ps_font_metrics:");
+#endif
 
-BEGIN_EVENT_TABLE(wxGenericPageSetupDialog, wxDialog)
-    EVT_BUTTON(wxPRINTID_SETUP, wxGenericPageSetupDialog::OnPrinter)
-END_EVENT_TABLE()
+#ifdef __WXMSW__
+    m_printerCommand = wxT("print");
+    m_printerOptions = wxT("");
+    m_afmPath = wxT("c:\\windows\\system\\");
+#endif
 
-// ----------------------------------------------------------------------------
-// global vars
-// ----------------------------------------------------------------------------
+#if !defined(__VMS__) && !defined(__WXMSW__)
+    m_printerCommand = wxT("lpr");
+    m_printerOptions = wxT("");
+    m_afmPath = wxT("");
+#endif
 
-extern wxPrintPaperDatabase *wxThePrintPaperDatabase;
+    m_printerScaleX = 1.0;
+    m_printerScaleY = 1.0;
+    m_printerTranslateX = 0;
+    m_printerTranslateY = 0;
+    m_printMode = wxPRINT_MODE_FILE;
+}
 
-#if wxUSE_POSTSCRIPT
+wxPostScriptPrintNativeData::~wxPostScriptPrintNativeData()
+{
+}
+
+bool wxPostScriptPrintNativeData::ConvertTo( wxPrintData &data )
+{
+    return true;
+}
+
+bool wxPostScriptPrintNativeData::ConvertFrom( const wxPrintData &data )
+{
+    return true;
+}
 
 // ----------------------------------------------------------------------------
 // Generic print dialog for non-Windows printing use.
@@ -256,25 +288,28 @@ void wxGenericPrintDialog::OnOK(wxCommandEvent& WXUNUSED(event))
     if (m_printDialogData.GetToPage() < 1)
         m_printDialogData.SetToPage(m_printDialogData.GetFromPage());
 
+    wxPostScriptPrintNativeData *data = 
+        (wxPostScriptPrintNativeData *) m_printDialogData.GetPrintData().GetNativeData();
+
     // There are some interactions between the global setup data
     // and the standard print dialog. The global printing 'mode'
     // is determined by whether the user checks Print to file
     // or not.
     if (m_printDialogData.GetPrintToFile())
     {
-        m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE);
+        data->SetPrintMode(wxPRINT_MODE_FILE);
 
         wxFileName fname( m_printDialogData.GetPrintData().GetFilename() );
 
         wxFileDialog dialog( this, _("PostScript file"),
             fname.GetPath(), fname.GetFullName(), wxT("*.ps"), wxOPEN | wxOVERWRITE_PROMPT );
         if (dialog.ShowModal() != wxID_OK) return;
-
+        
         m_printDialogData.GetPrintData().SetFilename( dialog.GetPath() );
     }
     else
     {
-        m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER);
+        data->SetPrintMode(wxPRINT_MODE_PRINTER);
     }
 
     EndModal(wxID_OK);
@@ -403,6 +438,8 @@ wxDC *wxGenericPrintDialog::GetPrintDC()
 // Generic print setup dialog
 // ----------------------------------------------------------------------------
 
+IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog)
+
 wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintData* data):
 wxDialog(parent, wxID_ANY, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL)
 {
@@ -469,10 +506,13 @@ wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
 
 bool wxGenericPrintSetupDialog::TransferDataToWindow()
 {
-    if (m_printerCommandText && m_printData.GetPrinterCommand())
-        m_printerCommandText->SetValue(m_printData.GetPrinterCommand());
-    if (m_printerOptionsText && m_printData.GetPrinterOptions())
-        m_printerOptionsText->SetValue(m_printData.GetPrinterOptions());
+    wxPostScriptPrintNativeData *data = 
+        (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+
+    if (m_printerCommandText && data->GetPrinterCommand())
+        m_printerCommandText->SetValue(data->GetPrinterCommand());
+    if (m_printerOptionsText && data->GetPrinterOptions())
+        m_printerOptionsText->SetValue(data->GetPrinterOptions());
     if (m_colourCheckBox)
         m_colourCheckBox->SetValue(m_printData.GetColour());
 
@@ -488,10 +528,13 @@ bool wxGenericPrintSetupDialog::TransferDataToWindow()
 
 bool wxGenericPrintSetupDialog::TransferDataFromWindow()
 {
+    wxPostScriptPrintNativeData *data = 
+        (wxPostScriptPrintNativeData *) m_printData.GetNativeData();
+
     if (m_printerCommandText)
-        m_printData.SetPrinterCommand(m_printerCommandText->GetValue());
+        data->SetPrinterCommand(m_printerCommandText->GetValue());
     if (m_printerOptionsText)
-        m_printData.SetPrinterOptions(m_printerOptionsText->GetValue());
+        data->SetPrinterOptions(m_printerOptionsText->GetValue());
     if (m_colourCheckBox)
         m_printData.SetColour(m_colourCheckBox->GetValue());
     if (m_orientationRadioBox)
@@ -559,6 +602,12 @@ wxComboBox *wxGenericPrintSetupDialog::CreatePaperTypeChoice(int *x, int *y)
 // Generic page setup dialog
 // ----------------------------------------------------------------------------
 
+IMPLEMENT_CLASS(wxGenericPageSetupDialog, wxDialog)
+
+BEGIN_EVENT_TABLE(wxGenericPageSetupDialog, wxDialog)
+    EVT_BUTTON(wxPRINTID_SETUP, wxGenericPageSetupDialog::OnPrinter)
+END_EVENT_TABLE()
+
 void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent& WXUNUSED(event))
 {
     // We no longer query GetPrintMode, so we can eliminate the need
index f0202b8b886f45f9d0d5e0d51cc0d306ca43e0f9..e817ba19894c2c0a1931be86b1d249a3540d9333 100644 (file)
@@ -44,6 +44,7 @@
 #endif
 
 #include "wx/dcprint.h"
+#include "wx/printdlg.h"
 #include "math.h"
 
 #if wxUSE_COMMON_DIALOGS
@@ -282,12 +283,14 @@ static bool wxGetDefaultDeviceName(wxString& deviceName, wxString& portName)
 // Gets an HDC for the specified printer configuration
 WXHDC WXDLLEXPORT wxGetPrinterDC(const wxPrintData& printDataConst)
 {
-    wxPrintData printData = printDataConst;
-    printData.ConvertToNative();
+    wxWindowsPrintNativeData *data =
+        (wxWindowsPrintNativeData *) printDataConst.GetNativeData();
+        
+    data->ConvertFrom( printDataConst );
 
     wxChar* driverName = (wxChar*) NULL;
 
-    wxString devNameStr = printData.GetPrinterName();
+    wxString devNameStr = printDataConst.GetPrinterName();
     wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32
 
     const wxChar* deviceName;
@@ -298,7 +301,7 @@ WXHDC WXDLLEXPORT wxGetPrinterDC(const wxPrintData& printDataConst)
 
     LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
 
-    HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
+    HGLOBAL hDevMode = (HGLOBAL)(DWORD) data->GetNativeData();
 
     if ( hDevMode )
         lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
index 22b2fafd48f3a30c41b4b9a008f6b39b5680490e..a24155a4f62f9bae00873954745a5c8105c86f61 100644 (file)
@@ -39,6 +39,7 @@
 #include "wx/cmndata.h"
 #include "wx/printdlg.h"
 #include "wx/dcprint.h"
+#include "wx/paper.h"
 
 #include <stdlib.h>
 
     #include <print.h>
 #endif
 
+//----------------------------------------------------------------------------
+// wxWindowsPrintNativeData
+//----------------------------------------------------------------------------
+
+#ifdef __WXDEBUG__
+static wxString wxGetPrintDlgError()
+{
+    DWORD err = CommDlgExtendedError();
+    wxString msg = wxT("Unknown");
+    switch (err)
+    {
+        case CDERR_FINDRESFAILURE: msg = wxT("CDERR_FINDRESFAILURE"); break;
+        case CDERR_INITIALIZATION: msg = wxT("CDERR_INITIALIZATION"); break;
+        case CDERR_LOADRESFAILURE: msg = wxT("CDERR_LOADRESFAILURE"); break;
+        case CDERR_LOADSTRFAILURE: msg = wxT("CDERR_LOADSTRFAILURE"); break;
+        case CDERR_LOCKRESFAILURE: msg = wxT("CDERR_LOCKRESFAILURE"); break;
+        case CDERR_MEMALLOCFAILURE: msg = wxT("CDERR_MEMALLOCFAILURE"); break;
+        case CDERR_MEMLOCKFAILURE: msg = wxT("CDERR_MEMLOCKFAILURE"); break;
+        case CDERR_NOHINSTANCE: msg = wxT("CDERR_NOHINSTANCE"); break;
+        case CDERR_NOHOOK: msg = wxT("CDERR_NOHOOK"); break;
+        case CDERR_NOTEMPLATE: msg = wxT("CDERR_NOTEMPLATE"); break;
+        case CDERR_STRUCTSIZE: msg = wxT("CDERR_STRUCTSIZE"); break;
+        case  PDERR_RETDEFFAILURE: msg = wxT("PDERR_RETDEFFAILURE"); break;
+        case  PDERR_PRINTERNOTFOUND: msg = wxT("PDERR_PRINTERNOTFOUND"); break;
+        case  PDERR_PARSEFAILURE: msg = wxT("PDERR_PARSEFAILURE"); break;
+        case  PDERR_NODEVICES: msg = wxT("PDERR_NODEVICES"); break;
+        case  PDERR_NODEFAULTPRN: msg = wxT("PDERR_NODEFAULTPRN"); break;
+        case  PDERR_LOADDRVFAILURE: msg = wxT("PDERR_LOADDRVFAILURE"); break;
+        case  PDERR_INITFAILURE: msg = wxT("PDERR_INITFAILURE"); break;
+        case  PDERR_GETDEVMODEFAIL: msg = wxT("PDERR_GETDEVMODEFAIL"); break;
+        case  PDERR_DNDMMISMATCH: msg = wxT("PDERR_DNDMMISMATCH"); break;
+        case  PDERR_DEFAULTDIFFERENT: msg = wxT("PDERR_DEFAULTDIFFERENT"); break;
+        case  PDERR_CREATEICFAILURE: msg = wxT("PDERR_CREATEICFAILURE"); break;
+        default: break;
+    }
+    return msg;
+}
+#endif
+
+static HGLOBAL wxCreateDevNames(const wxString& driverName, const wxString& printerName, const wxString& portName)
+{
+    HGLOBAL hDev = NULL;
+    // if (!driverName.IsEmpty() && !printerName.IsEmpty() && !portName.IsEmpty())
+    if (driverName.IsEmpty() && printerName.IsEmpty() && portName.IsEmpty())
+    {
+    }
+    else
+    {
+        hDev = GlobalAlloc(GPTR, 4*sizeof(WORD)+
+                           ( driverName.Length() + 1 +
+            printerName.Length() + 1 +
+                             portName.Length()+1 ) * sizeof(wxChar) );
+        LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(hDev);
+        lpDev->wDriverOffset = sizeof(WORD) * 4 / sizeof(wxChar);
+        wxStrcpy((wxChar*)lpDev + lpDev->wDriverOffset, driverName);
+
+        lpDev->wDeviceOffset = (WORD)( lpDev->wDriverOffset +
+                                       driverName.Length() + 1 );
+        wxStrcpy((wxChar*)lpDev + lpDev->wDeviceOffset, printerName);
+
+        lpDev->wOutputOffset = (WORD)( lpDev->wDeviceOffset +
+                                       printerName.Length() + 1 );
+        wxStrcpy((wxChar*)lpDev + lpDev->wOutputOffset, portName);
+
+        lpDev->wDefault = 0;
+
+        GlobalUnlock(hDev);
+    }
+
+    return hDev;
+}
+
+IMPLEMENT_CLASS(wxWindowsPrintNativeData, wxPrintNativeDataBase)
+
+wxWindowsPrintNativeData::wxWindowsPrintNativeData()
+{
+    m_devMode = (void*) NULL;
+    m_devNames = (void*) NULL;
+}
+
+wxWindowsPrintNativeData::~wxWindowsPrintNativeData()
+{
+    HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
+    if ( hDevMode )
+        GlobalFree(hDevMode);
+    HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
+    if ( hDevNames )
+        GlobalFree(hDevNames);
+}
+
+bool wxWindowsPrintNativeData::Ok() const
+{
+    return (m_devMode != NULL) ;
+}
+
+bool wxWindowsPrintNativeData::ConvertTo( wxPrintData &data )
+{
+    HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
+    HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
+
+    if (!hDevMode)
+        return false;
+
+    if ( hDevMode )
+    {
+        LPDEVMODE devMode = (LPDEVMODE)GlobalLock(hDevMode);
+
+        //// Orientation
+        if (devMode->dmFields & DM_ORIENTATION)
+            data.SetOrientation( devMode->dmOrientation );
+
+        //// Collation
+        if (devMode->dmFields & DM_COLLATE)
+        {
+            if (devMode->dmCollate == DMCOLLATE_TRUE)
+                data.SetCollate( true );
+            else
+                data.SetCollate( false );
+        }
+
+        //// Number of copies
+        if (devMode->dmFields & DM_COPIES)
+            data.SetNoCopies( devMode->dmCopies );
+
+        if (devMode->dmFields & DM_DEFAULTSOURCE)
+            data.SetBin( (wxPrintBin)devMode->dmDefaultSource );
+
+        //// Printer name
+        if (devMode->dmDeviceName[0] != 0)
+            data.SetPrinterName( devMode->dmDeviceName );
+
+        //// Colour
+        if (devMode->dmFields & DM_COLOR)
+        {
+            if (devMode->dmColor == DMCOLOR_COLOR)
+                data.SetColour( true );
+            else
+                data.SetColour( false );
+        }
+        else
+            data.SetColour( true );
+
+        //// Paper size
+
+        // We don't know size of user defined paper and some buggy drivers
+        // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
+        // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
+        // code wouldn't set m_paperSize correctly.
+        if ((devMode->dmFields & DM_PAPERSIZE) && (devMode->dmPaperSize < DMPAPER_USER))
+        {
+            if (wxThePrintPaperDatabase)
+            {
+                wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize);
+                if (paper)
+                {
+                    data.SetPaperId( paper->GetId() );
+                    data.SetPaperSize( wxSize(paper->GetWidth() / 10,paper->GetHeight() / 10) );
+                }
+                else
+                {
+                    // Shouldn't really get here
+                    wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
+                    data.SetPaperId( wxPAPER_NONE );
+                    data.SetPaperSize( wxSize(0,0) );
+                }
+            }
+            else
+            {
+                // Shouldn't really get here
+                wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
+                data.SetPaperId( wxPAPER_NONE );
+                data.SetPaperSize( wxSize(0,0) );
+            }
+        }
+        else if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH))
+        {
+            // DEVMODE is in tenths of a milimeter
+            data.SetPaperId( wxPAPER_NONE );
+            data.SetPaperSize( wxSize(devMode->dmPaperWidth / 10, devMode->dmPaperLength / 10) );
+        }
+        else
+        {
+            // Shouldn't really get here
+            wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
+            data.SetPaperId( wxPAPER_NONE );
+            data.SetPaperSize( wxSize(0,0) );
+        }
+
+        //// Duplex
+
+        if (devMode->dmFields & DM_DUPLEX)
+        {
+            switch (devMode->dmDuplex)
+            {
+                case DMDUP_HORIZONTAL:   data.SetDuplex( wxDUPLEX_HORIZONTAL ); break;
+                case DMDUP_VERTICAL:     data.SetDuplex( wxDUPLEX_VERTICAL ); break;
+                default:    
+                case DMDUP_SIMPLEX:      data.SetDuplex( wxDUPLEX_SIMPLEX ); break;
+            }
+        }
+        else
+            data.SetDuplex( wxDUPLEX_SIMPLEX );
+
+        //// Quality
+
+        if (devMode->dmFields & DM_PRINTQUALITY)
+        {
+            switch (devMode->dmPrintQuality)
+            {
+                case DMRES_MEDIUM:  data.SetQuality( wxPRINT_QUALITY_MEDIUM ); break;
+                case DMRES_LOW:     data.SetQuality( wxPRINT_QUALITY_LOW ); break;
+                case DMRES_DRAFT:   data.SetQuality( wxPRINT_QUALITY_DRAFT ); break;
+                case DMRES_HIGH:    data.SetQuality( 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.");
+                    data.SetQuality( devMode->dmPrintQuality );
+                    break;
+
+                }
+            }
+        }
+        else
+            data.SetQuality( 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 = (LPTSTR)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(""))
+                data.SetPrinterName( printerName );
+
+            GlobalUnlock(hDevNames);
+        }
+    }
+    
+    return true;
+}
+
+bool wxWindowsPrintNativeData::ConvertFrom( const wxPrintData &data )
+{
+    HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
+    HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
+    if (!hDevMode)
+    {
+        // Use PRINTDLG as a way of creating a DEVMODE object
+        PRINTDLG pd;
+
+        // 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));
+#ifdef __WXWINCE__
+        pd.cbStruct    = sizeof(PRINTDLG);
+#else
+        pd.lStructSize    = sizeof(PRINTDLG);
+#endif
+#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
+        {
+            hDevMode = pd.hDevMode;
+            m_devMode = (void*)(long) hDevMode;
+            pd.hDevMode = NULL;
+
+            // We'll create a new DEVNAMEs structure below.
+            if ( pd.hDevNames )
+                GlobalFree(pd.hDevNames);
+            pd.hDevNames = NULL;
+
+            // hDevNames = pd->hDevNames;
+            // m_devNames = (void*)(long) hDevNames;
+            // pd->hDevnames = NULL;
+
+        }
+    }
+
+    if ( hDevMode )
+    {
+        LPDEVMODE devMode = (LPDEVMODE) GlobalLock(hDevMode);
+
+        //// Orientation
+        devMode->dmOrientation = (short)data.GetOrientation();
+
+        //// Collation
+        devMode->dmCollate = (data.GetCollate() ? DMCOLLATE_TRUE : DMCOLLATE_FALSE);
+        devMode->dmFields |= DM_COLLATE;
+
+        //// Number of copies
+        devMode->dmCopies = (short)data.GetNoCopies();
+        devMode->dmFields |= DM_COPIES;
+
+        //// Printer name
+        wxString name = data.GetPrinterName();
+        if (name != wxT(""))
+        {
+            //int len = wxMin(31, m_printerName.Len());
+            wxStrncpy((wxChar*)devMode->dmDeviceName,name.c_str(),31);
+            devMode->dmDeviceName[31] = wxT('\0');
+        }
+
+        //// Colour
+        if (data.GetColour())
+            devMode->dmColor = DMCOLOR_COLOR;
+        else
+            devMode->dmColor = DMCOLOR_MONOCHROME;
+        devMode->dmFields |= DM_COLOR;
+
+        //// Paper size
+        if (data.GetPaperId() == wxPAPER_NONE)
+        {
+            // DEVMODE is in tenths of a milimeter
+            devMode->dmPaperWidth = (short)(data.GetPaperSize().x * 10);
+            devMode->dmPaperLength = (short)(data.GetPaperSize().y * 10);
+            devMode->dmPaperSize = DMPAPER_USER;
+            devMode->dmFields |= DM_PAPERWIDTH;
+            devMode->dmFields |= DM_PAPERLENGTH;
+        }
+        else
+        {
+            if (wxThePrintPaperDatabase)
+            {
+                wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType( data.GetPaperId() );
+                if (paper)
+                {
+                    devMode->dmPaperSize = (short)paper->GetPlatformId();
+                    devMode->dmFields |= DM_PAPERSIZE;
+                }
+            }
+        }
+
+        //// Duplex
+        short duplex;
+        switch (data.GetDuplex())
+        {
+            case wxDUPLEX_HORIZONTAL:
+                duplex = DMDUP_HORIZONTAL;
+                break;
+            case wxDUPLEX_VERTICAL:
+                duplex = DMDUP_VERTICAL;
+                break;
+            default:
+            // in fact case wxDUPLEX_SIMPLEX:
+                duplex = DMDUP_SIMPLEX;
+                break;
+        }
+        devMode->dmDuplex = duplex;
+        devMode->dmFields |= DM_DUPLEX;
+
+        //// Quality
+
+        short quality;
+        switch (data.GetQuality())
+        {
+            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 = (short)data.GetQuality();
+                break;
+        }
+        devMode->dmPrintQuality = quality;
+        devMode->dmFields |= DM_PRINTQUALITY;
+
+        if (data.GetBin() != wxPRINTBIN_DEFAULT)
+        {
+            switch (data.GetBin())
+            {
+                case wxPRINTBIN_ONLYONE:        devMode->dmDefaultSource = DMBIN_ONLYONE;       break;
+                case wxPRINTBIN_LOWER:          devMode->dmDefaultSource = DMBIN_LOWER;         break;
+                case wxPRINTBIN_MIDDLE:         devMode->dmDefaultSource = DMBIN_MIDDLE;        break;
+                case wxPRINTBIN_MANUAL:         devMode->dmDefaultSource = DMBIN_MANUAL;        break;
+                case wxPRINTBIN_ENVELOPE:       devMode->dmDefaultSource = DMBIN_ENVELOPE;      break;
+                case wxPRINTBIN_ENVMANUAL:      devMode->dmDefaultSource = DMBIN_ENVMANUAL;     break;
+                case wxPRINTBIN_AUTO:           devMode->dmDefaultSource = DMBIN_AUTO;          break;
+                case wxPRINTBIN_TRACTOR:        devMode->dmDefaultSource = DMBIN_TRACTOR;       break;
+                case wxPRINTBIN_SMALLFMT:       devMode->dmDefaultSource = DMBIN_SMALLFMT;      break;
+                case wxPRINTBIN_LARGEFMT:       devMode->dmDefaultSource = DMBIN_LARGEFMT;      break;
+                case wxPRINTBIN_LARGECAPACITY:  devMode->dmDefaultSource = DMBIN_LARGECAPACITY; break;
+                case wxPRINTBIN_CASSETTE:       devMode->dmDefaultSource = DMBIN_CASSETTE;      break;
+                case wxPRINTBIN_FORMSOURCE:     devMode->dmDefaultSource = DMBIN_FORMSOURCE;    break;
+
+                default:
+                    devMode->dmDefaultSource = (short)(DMBIN_USER + data.GetBin() - wxPRINTBIN_USER);
+                    break;
+            }
+
+            devMode->dmFields |= DM_DEFAULTSOURCE;
+        }
+
+        GlobalUnlock(hDevMode);
+    }
+
+    if ( hDevNames )
+    {
+        GlobalFree(hDevNames);
+    }
+
+    // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
+    m_devNames = (void*) (long) wxCreateDevNames(wxT(""), data.GetPrinterName(), wxT(""));
+    
+    return true;
+}
+    
 // ---------------------------------------------------------------------------
 // wxPrintDialog
 // ---------------------------------------------------------------------------