]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/core/printmac.cpp
Fix wrong value
[wxWidgets.git] / src / osx / core / printmac.cpp
index 4cf4f0cad6526f38650ba801c49c46d9afc659a0..5722b094566734a44db60c09428ec0e61cf37d6d 100644 (file)
@@ -61,27 +61,7 @@ static PMResolution *GetSupportedResolutions(PMPrinter printer, UInt32 *count)
 {
     PMResolution res, *resolutions = NULL;
     OSStatus status = PMPrinterGetPrinterResolutionCount(printer, count);
-    if (status == kPMNotImplemented)
-    {
-#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
-        resolutions = (PMResolution *)malloc(sizeof(PMResolution) * 4);
-        *count = 0;
-        if (PMPrinterGetPrinterResolution(printer, kPMMinRange, &res) == noErr)
-            resolutions[(*count)++] = res;
-        if (PMPrinterGetPrinterResolution(printer, kPMMinSquareResolution, &res) == noErr)
-            resolutions[(*count)++] = res;
-        if (PMPrinterGetPrinterResolution(printer, kPMMaxSquareResolution, &res) == noErr)
-            resolutions[(*count)++] = res;
-        if (PMPrinterGetPrinterResolution(printer, kPMMaxRange, &res) == noErr)
-            resolutions[(*count)++] = res;
-        if (*count == 0)
-        {
-            if (PMPrinterGetPrinterResolution(printer, kPMDefaultResolution, &res) == noErr)
-                resolutions[(*count)++] = res;
-        }
-#endif
-    }
-    else if (status == noErr)
+    if (status == noErr)
     {
         resolutions = (PMResolution *)malloc(sizeof(PMResolution) * (*count));
         UInt32 realCount = 0;
@@ -164,7 +144,7 @@ void wxOSXPrintData::TransferPaperInfoFrom( const wxPrintData &data )
 {
     PMPrinter printer;
     PMSessionGetCurrentPrinter(m_macPrintSession, &printer);
-    
+
     wxSize papersize = wxDefaultSize;
     const wxPaperSize paperId = data.GetPaperId();
     if ( paperId != wxPAPER_NONE && wxThePrintPaperDatabase )
@@ -180,16 +160,16 @@ void wxOSXPrintData::TransferPaperInfoFrom( const wxPrintData &data )
     {
         papersize = data.GetPaperSize();
     }
-    
+
     if ( papersize != wxDefaultSize )
     {
         papersize.x = (wxInt32) (papersize.x * mm2pt);
         papersize.y = (wxInt32) (papersize.y * mm2pt);
-        
+
         double height, width;
         PMPaperGetHeight(m_macPaper, &height);
         PMPaperGetWidth(m_macPaper, &width);
-        
+
         if ( fabs( width - papersize.x ) >= 5 ||
             fabs( height - papersize.y ) >= 5 )
         {
@@ -218,21 +198,9 @@ void wxOSXPrintData::TransferPaperInfoFrom( const wxPrintData &data )
                     const PMPaperMargins margins = { 0.0, 0.0, 0.0, 0.0 };
                     wxString id, name(wxT("Custom paper"));
                     id.Printf(wxT("wxPaperCustom%dx%d"), papersize.x, papersize.y);
-                    
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
-                    if ( PMPaperCreateCustom != NULL)
-                    {
-                        PMPaperCreateCustom(printer, wxCFStringRef( id, wxFont::GetDefaultEncoding() ), wxCFStringRef( name, wxFont::GetDefaultEncoding() ),
+
+                    PMPaperCreateCustom(printer, wxCFStringRef( id, wxFont::GetDefaultEncoding() ), wxCFStringRef( name, wxFont::GetDefaultEncoding() ),
                                             papersize.x, papersize.y, &margins, &paper);
-                    }
-#endif
-#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
-                    if ( paper == kPMNoData )
-                    {
-                        PMPaperCreate(printer, wxCFStringRef( id, wxFont::GetDefaultEncoding() ), wxCFStringRef( name, wxFont::GetDefaultEncoding() ),
-                                      papersize.x, papersize.y, &margins, &paper);
-                    }
-#endif
                 }
                 if ( bestPaper != kPMNoData )
                 {
@@ -246,7 +214,7 @@ void wxOSXPrintData::TransferPaperInfoFrom( const wxPrintData &data )
             }
         }
     }
-    
+
     PMSetCopies( m_macPrintSettings , data.GetNoCopies() , false ) ;
     PMSetCollate(m_macPrintSettings, data.GetCollate());
     if ( data.IsOrientationReversed() )
@@ -255,7 +223,7 @@ void wxOSXPrintData::TransferPaperInfoFrom( const wxPrintData &data )
     else
         PMSetOrientation( m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
                          kPMLandscape : kPMPortrait , false ) ;
-    
+
     PMDuplexMode mode = 0 ;
     switch( data.GetDuplex() )
     {
@@ -271,8 +239,8 @@ void wxOSXPrintData::TransferPaperInfoFrom( const wxPrintData &data )
             break ;
     }
     PMSetDuplex(  m_macPrintSettings, mode ) ;
-    
-    
+
+
     if ( data.IsOrientationReversed() )
         PMSetOrientation(  m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
                          kPMReverseLandscape : kPMReversePortrait , false ) ;
@@ -295,17 +263,8 @@ void wxOSXPrintData::TransferResolutionFrom( const wxPrintData &data )
             quality = wxPRINT_QUALITY_HIGH;
 
         PMResolution res = resolutions[((quality - wxPRINT_QUALITY_DRAFT) * (resCount - 1)) / 3];
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
-        if ( PMPrinterSetOutputResolution != NULL )
-            PMPrinterSetOutputResolution(printer, m_macPrintSettings, &res);
-        else
-#endif
-        {
-#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
-            PMSetResolution( m_macPageFormat, &res);
-#endif
-        }
-        
+        PMPrinterSetOutputResolution(printer, m_macPrintSettings, &res);
+
         free(resolutions);
     }
 }
@@ -315,10 +274,10 @@ bool wxOSXPrintData::TransferFrom( const wxPrintData &data )
     TransferPrinterNameFrom(data);
     TransferPaperInfoFrom(data);
     TransferResolutionFrom(data);
-    
+
     // after setting the new resolution the format has to be updated, otherwise the page rect remains
     // at the 'old' scaling
-    
+
     PMSessionValidatePageFormat(m_macPrintSession,
                                 m_macPageFormat, kPMDontWantBoolean);
     PMSessionValidatePrintSettings(m_macPrintSession,
@@ -348,6 +307,8 @@ void wxOSXPrintData::TransferPrinterNameTo( wxPrintData &data )
 
 void wxOSXPrintData::TransferPaperInfoTo( wxPrintData &data )
 {
+    PMGetPageFormatPaper(m_macPageFormat, &m_macPaper);
+
     PMPrinter printer ;
     PMSessionGetCurrentPrinter( m_macPrintSession, &printer );
     OSStatus err = noErr ;
@@ -355,7 +316,7 @@ void wxOSXPrintData::TransferPaperInfoTo( wxPrintData &data )
     err = PMGetCopies( m_macPrintSettings , &copies ) ;
     if ( err == noErr )
         data.SetNoCopies( copies ) ;
-    
+
     PMOrientation orientation ;
     err = PMGetOrientation(  m_macPageFormat , &orientation ) ;
     if ( err == noErr )
@@ -371,12 +332,12 @@ void wxOSXPrintData::TransferPaperInfoTo( wxPrintData &data )
             data.SetOrientationReversed( orientation == kPMReverseLandscape );
         }
     }
-    
+
     Boolean collate;
     if (PMGetCollate(m_macPrintSettings, &collate) == noErr)
         data.SetCollate(collate);
-    
-    
+
+
     PMDuplexMode mode = 0 ;
     PMGetDuplex(  m_macPrintSettings, &mode ) ;
     switch( mode )
@@ -392,11 +353,11 @@ void wxOSXPrintData::TransferPaperInfoTo( wxPrintData &data )
             data.SetDuplex(wxDUPLEX_SIMPLEX);
             break ;
     }
-    
+
     double height, width;
     PMPaperGetHeight(m_macPaper, &height);
     PMPaperGetWidth(m_macPaper, &width);
-    
+
     wxSize sz((int)(width * pt2mm + 0.5 ) ,
               (int)(height * pt2mm + 0.5 ));
     data.SetPaperSize(sz);
@@ -422,17 +383,9 @@ void wxOSXPrintData::TransferResolutionTo( wxPrintData &data )
     {
         bool valid = false;
         PMResolution res;
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
-        if ( PMPrinterGetOutputResolution != NULL )
-        {
-            if ( PMPrinterGetOutputResolution(printer, m_macPrintSettings, &res) == noErr )
-                valid = true;
-        }
-#endif
-#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
-        if (PMPrinterGetPrinterResolution(printer, kPMCurrentValue, &res) == noErr)
+        if ( PMPrinterGetOutputResolution(printer, m_macPrintSettings, &res) == noErr )
             valid = true;
-#endif
+
         if ( valid )
         {
             UInt32 i;
@@ -445,7 +398,7 @@ void wxOSXPrintData::TransferResolutionTo( wxPrintData &data )
                 data.SetQuality((((i + 1) * 3) / resCount) + wxPRINT_QUALITY_DRAFT);
         }
         free(resolutions);
-    }    
+    }
 }
 
 bool wxOSXPrintData::TransferTo( wxPrintData &data )
@@ -460,14 +413,14 @@ bool wxOSXPrintData::TransferTo( wxPrintData &data )
     return true ;
 }
 
-void wxOSXPrintData::TransferFrom( wxPageSetupData *WXUNUSED(data) )
+void wxOSXPrintData::TransferFrom( wxPageSetupDialogData *WXUNUSED(data) )
 {
     // should we setup the page rect here ?
     // since MacOS sometimes has two same paper rects with different
     // page rects we could make it roundtrip safe perhaps
 }
 
-void wxOSXPrintData::TransferTo( wxPageSetupData* data )
+void wxOSXPrintData::TransferTo( wxPageSetupDialogData* data )
 {
 #if wxOSX_USE_COCOA
     UpdateToPMState();
@@ -635,22 +588,16 @@ bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
 
     if (PMSessionGetCurrentPrinter(nativeData->GetPrintSession(), &printer) == noErr)
     {
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
-        if ( PMPrinterGetOutputResolution != NULL )
-        {
-            if (PMPrinterGetOutputResolution( printer, nativeData->GetPrintSettings(), &res) == -9589 /* kPMKeyNotFound */ )
-            {
-                res.hRes = res.vRes = 300;
-            }
-        }
-        else
-#endif
+        if (PMPrinterGetOutputResolution( printer, nativeData->GetPrintSettings(), &res) == -9589 /* kPMKeyNotFound */ )
         {
-#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
-            PMPrinterGetPrinterResolution(printer, kPMCurrentValue, &res);
-#endif
+            res.hRes = res.vRes = 300;
         }
     }
+    else
+    {
+        // fallback
+        res.hRes = res.vRes = 300;
+    }
     printout->SetPPIPrinter(int(res.hRes), int(res.vRes));
 
     // Set printout parameters