X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1bd122ddfa1d4d3e5f87ecb1e7dd317439fb6593..bc9d3d911cfb51f612a699d7fb00f57eb5b2097c:/src/osx/core/printmac.cpp diff --git a/src/osx/core/printmac.cpp b/src/osx/core/printmac.cpp index 9090aae079..5722b09456 100644 --- a/src/osx/core/printmac.cpp +++ b/src/osx/core/printmac.cpp @@ -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; @@ -131,7 +111,7 @@ void wxOSXPrintData::UpdateToPMState() { } -bool wxOSXPrintData::TransferFrom( const wxPrintData &data ) +void wxOSXPrintData::TransferPrinterNameFrom( const wxPrintData &data ) { CFArrayRef printerList; CFIndex index, count; @@ -158,7 +138,10 @@ bool wxOSXPrintData::TransferFrom( const wxPrintData &data ) PMSessionSetCurrentPMPrinter(m_macPrintSession, printer); CFRelease(printerList); } +} +void wxOSXPrintData::TransferPaperInfoFrom( const wxPrintData &data ) +{ PMPrinter printer; PMSessionGetCurrentPrinter(m_macPrintSession, &printer); @@ -216,20 +199,8 @@ bool wxOSXPrintData::TransferFrom( const wxPrintData &data ) 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() ), - 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 + PMPaperCreateCustom(printer, wxCFStringRef( id, wxFont::GetDefaultEncoding() ), wxCFStringRef( name, wxFont::GetDefaultEncoding() ), + papersize.x, papersize.y, &margins, &paper); } if ( bestPaper != kPMNoData ) { @@ -248,10 +219,10 @@ bool wxOSXPrintData::TransferFrom( const wxPrintData &data ) PMSetCollate(m_macPrintSettings, data.GetCollate()); if ( data.IsOrientationReversed() ) PMSetOrientation( m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ? - kPMReverseLandscape : kPMReversePortrait , false ) ; + kPMReverseLandscape : kPMReversePortrait , false ) ; else PMSetOrientation( m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ? - kPMLandscape : kPMPortrait , false ) ; + kPMLandscape : kPMPortrait , false ) ; PMDuplexMode mode = 0 ; switch( data.GetDuplex() ) @@ -272,10 +243,16 @@ bool wxOSXPrintData::TransferFrom( const wxPrintData &data ) if ( data.IsOrientationReversed() ) PMSetOrientation( m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ? - kPMReverseLandscape : kPMReversePortrait , false ) ; + kPMReverseLandscape : kPMReversePortrait , false ) ; else PMSetOrientation( m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ? - kPMLandscape : kPMPortrait , false ) ; + kPMLandscape : kPMPortrait , false ) ; +} + +void wxOSXPrintData::TransferResolutionFrom( const wxPrintData &data ) +{ + PMPrinter printer; + PMSessionGetCurrentPrinter(m_macPrintSession, &printer); UInt32 resCount; PMResolution *resolutions = GetSupportedResolutions(printer, &resCount); @@ -286,26 +263,26 @@ bool wxOSXPrintData::TransferFrom( 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); } +} + +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); + m_macPageFormat, kPMDontWantBoolean); PMSessionValidatePrintSettings(m_macPrintSession, - m_macPrintSettings, kPMDontWantBoolean); + m_macPrintSettings, kPMDontWantBoolean); + #if wxOSX_USE_COCOA UpdateFromPMState(); #endif @@ -313,12 +290,28 @@ bool wxOSXPrintData::TransferFrom( const wxPrintData &data ) return true ; } -bool wxOSXPrintData::TransferTo( wxPrintData &data ) +void wxOSXPrintData::TransferPrinterNameTo( wxPrintData &data ) { + CFStringRef name; + PMPrinter printer ; + PMSessionGetCurrentPrinter( m_macPrintSession, &printer ); + if (PMPrinterIsDefault(printer)) + data.SetPrinterName(wxEmptyString); + else + { + name = PMPrinterGetName(printer); + CFRetain(name); + data.SetPrinterName(wxCFStringRef(name).AsString()); + } +} + +void wxOSXPrintData::TransferPaperInfoTo( wxPrintData &data ) +{ + PMGetPageFormatPaper(m_macPageFormat, &m_macPaper); + + PMPrinter printer ; + PMSessionGetCurrentPrinter( m_macPrintSession, &printer ); OSStatus err = noErr ; -#if wxOSX_USE_COCOA - UpdateToPMState(); -#endif UInt32 copies ; err = PMGetCopies( m_macPrintSettings , &copies ) ; if ( err == noErr ) @@ -344,17 +337,6 @@ bool wxOSXPrintData::TransferTo( wxPrintData &data ) if (PMGetCollate(m_macPrintSettings, &collate) == noErr) data.SetCollate(collate); - CFStringRef name; - PMPrinter printer ; - PMSessionGetCurrentPrinter( m_macPrintSession, &printer ); - if (PMPrinterIsDefault(printer)) - data.SetPrinterName(wxEmptyString); - else - { - name = PMPrinterGetName(printer); - CFRetain(name); - data.SetPrinterName(wxCFStringRef(name).AsString()); - } PMDuplexMode mode = 0 ; PMGetDuplex( m_macPrintSettings, &mode ) ; @@ -372,6 +354,25 @@ bool wxOSXPrintData::TransferTo( wxPrintData &data ) 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); + wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10)); + if (id != wxPAPER_NONE) + { + data.SetPaperId(id); + } +} + +void wxOSXPrintData::TransferResolutionTo( wxPrintData &data ) +{ + PMPrinter printer ; + PMSessionGetCurrentPrinter( m_macPrintSession, &printer ); + /* assume high quality, will change below if we are able to */ data.SetQuality(wxPRINT_QUALITY_HIGH); @@ -382,17 +383,9 @@ bool wxOSXPrintData::TransferTo( 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; @@ -406,30 +399,28 @@ bool wxOSXPrintData::TransferTo( wxPrintData &data ) } free(resolutions); } +} - double height, width; - PMPaperGetHeight(m_macPaper, &height); - PMPaperGetWidth(m_macPaper, &width); +bool wxOSXPrintData::TransferTo( wxPrintData &data ) +{ +#if wxOSX_USE_COCOA + UpdateToPMState(); +#endif - wxSize sz((int)(width * pt2mm + 0.5 ) , - (int)(height * pt2mm + 0.5 )); - data.SetPaperSize(sz); - wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10)); - if (id != wxPAPER_NONE) - { - data.SetPaperId(id); - } + TransferPrinterNameTo(data); + TransferPaperInfoTo(data); + TransferResolutionTo(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(); @@ -597,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 */ ) { - if (PMPrinterGetOutputResolution( printer, nativeData->GetPrintSettings(), &res) == -9589 /* kPMKeyNotFound */ ) - { - res.hRes = res.vRes = 300; - } - } - else -#endif - { -#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 @@ -680,8 +665,7 @@ bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) if (sm_abortWindow) { sm_abortWindow->Show(false); - delete sm_abortWindow; - sm_abortWindow = NULL; + wxDELETE(sm_abortWindow); } wxEndBusyCursor();