]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/printdlg.cpp
check that the version of __sync_sub_and_fetch that returns a value is supported...
[wxWidgets.git] / src / msw / printdlg.cpp
index 4fb94bd7993a25bde9e2b33129283e18ab98d696..575fb82ffd40102ccbd247a92d79d2a16172268b 100644 (file)
@@ -37,6 +37,7 @@
 
 #include "wx/printdlg.h"
 #include "wx/msw/printdlg.h"
 
 #include "wx/printdlg.h"
 #include "wx/msw/printdlg.h"
+#include "wx/msw/dcprint.h"
 #include "wx/paper.h"
 
 #include <stdlib.h>
 #include "wx/paper.h"
 
 #include <stdlib.h>
@@ -136,7 +137,7 @@ wxWindowsPrintNativeData::~wxWindowsPrintNativeData()
         GlobalFree(hDevNames);
 }
 
         GlobalFree(hDevNames);
 }
 
-bool wxWindowsPrintNativeData::Ok() const
+bool wxWindowsPrintNativeData::IsOk() const
 {
     return (m_devMode != NULL) ;
 }
 {
     return (m_devMode != NULL) ;
 }
@@ -198,7 +199,11 @@ bool wxWindowsPrintNativeData::TransferTo( wxPrintData &data )
         } else {
             data.SetBin(wxPRINTBIN_DEFAULT);
         }
         } else {
             data.SetBin(wxPRINTBIN_DEFAULT);
         }
-
+        if (devMode->dmFields & DM_MEDIATYPE)
+        {
+            wxASSERT( (int)devMode->dmMediaType != wxPRINTMEDIA_DEFAULT );
+            data.SetMedia(devMode->dmMediaType);
+        }
         //// Printer name
         if (devMode->dmDeviceName[0] != 0)
             // This syntax fixes a crash when using VS 7.1
         //// Printer name
         if (devMode->dmDeviceName[0] != 0)
             // This syntax fixes a crash when using VS 7.1
@@ -440,38 +445,40 @@ bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data )
         devMode->dmFields |= DM_COLOR;
 
         //// Paper size
         devMode->dmFields |= DM_COLOR;
 
         //// Paper size
-        if (data.GetPaperId() == wxPAPER_NONE)
+
+        // Paper id has priority over paper size. If id is specified, then size
+        // is ignored (as it can be filled in even for standard paper sizes)
+
+        wxPrintPaperType *paperType = NULL;
+
+        const wxPaperSize paperId = data.GetPaperId();
+        if ( paperId != wxPAPER_NONE && wxThePrintPaperDatabase )
         {
         {
-            // DEVMODE is in tenths of a milimeter
-            devMode->dmPaperWidth = (short)(data.GetPaperSize().x * 10);
-            devMode->dmPaperLength = (short)(data.GetPaperSize().y * 10);
-            if(m_customWindowsPaperId != 0)
-                devMode->dmPaperSize = m_customWindowsPaperId;
-            else
-                devMode->dmPaperSize = DMPAPER_USER;
-            devMode->dmFields |= DM_PAPERWIDTH;
-            devMode->dmFields |= DM_PAPERLENGTH;
+            paperType = wxThePrintPaperDatabase->FindPaperType(paperId);
         }
         }
-        else
+
+        if ( paperType )
         {
         {
-            if (wxThePrintPaperDatabase)
+            devMode->dmPaperSize = (short)paperType->GetPlatformId();
+            devMode->dmFields |= DM_PAPERSIZE;
+        }
+        else // custom (or no) paper size
+        {
+            const wxSize paperSize = data.GetPaperSize();
+            if ( paperSize != wxDefaultSize )
             {
             {
-                wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType( data.GetPaperId() );
-                if (paper)
-                {
-                    devMode->dmPaperSize = (short)paper->GetPlatformId();
-                    devMode->dmFields |= DM_PAPERSIZE;
-                }
+                // Fall back on specifying the paper size explicitly
+                if(m_customWindowsPaperId != 0)
+                    devMode->dmPaperSize = m_customWindowsPaperId;
                 else
                 else
-                {
-                    // Fall back on specifying the paper size explicitly
-                    devMode->dmPaperWidth = (short)(data.GetPaperSize().x * 10);
-                    devMode->dmPaperLength = (short)(data.GetPaperSize().y * 10);
                     devMode->dmPaperSize = DMPAPER_USER;
                     devMode->dmPaperSize = DMPAPER_USER;
-                    devMode->dmFields |= DM_PAPERWIDTH;
-                    devMode->dmFields |= DM_PAPERLENGTH;
-                }
+                devMode->dmPaperWidth = (short)(paperSize.x * 10);
+                devMode->dmPaperLength = (short)(paperSize.y * 10);
+                devMode->dmFields |= DM_PAPERWIDTH;
+                devMode->dmFields |= DM_PAPERLENGTH;
             }
             }
+            //else: neither paper type nor size specified, don't fill DEVMODE
+            //      at all so that the system defaults are used
         }
 
         //// Duplex
         }
 
         //// Duplex
@@ -547,7 +554,11 @@ bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data )
 
             devMode->dmFields |= DM_DEFAULTSOURCE;
         }
 
             devMode->dmFields |= DM_DEFAULTSOURCE;
         }
-
+        if (data.GetMedia() != wxPRINTMEDIA_DEFAULT)
+        {
+            devMode->dmMediaType = data.GetMedia();
+            devMode->dmFields |= DM_MEDIATYPE;
+        }
         GlobalUnlock(hDevMode);
     }
 
         GlobalUnlock(hDevMode);
     }
 
@@ -628,7 +639,7 @@ int wxWindowsPrintDialog::ShowModal()
 
     if ( ret && (pd->hDC) )
     {
 
     if ( ret && (pd->hDC) )
     {
-        wxPrinterDC *pdc = new wxPrinterDC( (WXHDC) pd->hDC );
+        wxPrinterDC *pdc = new wxPrinterDCFromHDC( (WXHDC) pd->hDC );
         m_printerDC = pdc;
         ConvertFromNative( m_printDialogData );
         return wxID_OK;
         m_printerDC = pdc;
         ConvertFromNative( m_printDialogData );
         return wxID_OK;
@@ -647,7 +658,7 @@ wxDC *wxWindowsPrintDialog::GetPrintDC()
         return m_printerDC;
     }
     else
         return m_printerDC;
     }
     else
-        return (wxDC*) NULL;
+        return (wxPrinterDC*) NULL;
 }
 
 bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData &data )
 }
 
 bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData &data )
@@ -743,10 +754,6 @@ bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData &data )
         pd->Flags |= PD_PAGENUMS;
     if ( data.GetEnableHelp() )
         pd->Flags |= PD_SHOWHELP;
         pd->Flags |= PD_PAGENUMS;
     if ( data.GetEnableHelp() )
         pd->Flags |= PD_SHOWHELP;
-#if WXWIN_COMPATIBILITY_2_4
-    if ( data.GetSetupDialog() )
-        pd->Flags |= PD_PRINTSETUP;
-#endif
 
     return true;
 }
 
     return true;
 }
@@ -802,9 +809,7 @@ bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData &data )
     data.EnableSelection( ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION) );
     data.EnablePageNumbers( ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS) );
     data.EnableHelp( ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP) );
     data.EnableSelection( ((pd->Flags & PD_NOSELECTION) != PD_NOSELECTION) );
     data.EnablePageNumbers( ((pd->Flags & PD_NOPAGENUMS) != PD_NOPAGENUMS) );
     data.EnableHelp( ((pd->Flags & PD_SHOWHELP) == PD_SHOWHELP) );
-#if WXWIN_COMPATIBILITY_2_4
-    data.SetSetupDialog( ((pd->Flags & PD_PRINTSETUP) == PD_PRINTSETUP) );
-#endif
+
     return true;
 }
 
     return true;
 }
 
@@ -1022,7 +1027,10 @@ bool wxWindowsPageSetupDialog::ConvertFromNative( wxPageSetupDialogData &data )
     data.EnableHelp( ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP) );
 
     //   PAGESETUPDLG is in hundreds of a mm
     data.EnableHelp( ((pd->Flags & PSD_SHOWHELP) == PSD_SHOWHELP) );
 
     //   PAGESETUPDLG is in hundreds of a mm
-    data.SetPaperSize( wxSize(pd->ptPaperSize.x / 100, pd->ptPaperSize.y / 100) );
+    if (data.GetPrintData().GetOrientation() == wxLANDSCAPE)
+        data.SetPaperSize( wxSize(pd->ptPaperSize.y / 100, pd->ptPaperSize.x / 100) );
+    else
+        data.SetPaperSize( wxSize(pd->ptPaperSize.x / 100, pd->ptPaperSize.y / 100) );
 
     data.SetMinMarginTopLeft( wxPoint(pd->rtMinMargin.left / 100, pd->rtMinMargin.top / 100) );
     data.SetMinMarginBottomRight( wxPoint(pd->rtMinMargin.right / 100, pd->rtMinMargin.bottom / 100) );
 
     data.SetMinMarginTopLeft( wxPoint(pd->rtMinMargin.left / 100, pd->rtMinMargin.top / 100) );
     data.SetMinMarginBottomRight( wxPoint(pd->rtMinMargin.right / 100, pd->rtMinMargin.bottom / 100) );