X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6f4968ce940cf8823954c8f1a13609258ba8712b..60372b0d54379701d62edf5595a7dc25c48330e1:/src/osx/core/printmac.cpp?ds=inline diff --git a/src/osx/core/printmac.cpp b/src/osx/core/printmac.cpp index 4b519b82d1..9b1eded8fe 100644 --- a/src/osx/core/printmac.cpp +++ b/src/osx/core/printmac.cpp @@ -131,7 +131,7 @@ void wxOSXPrintData::UpdateToPMState() { } -bool wxOSXPrintData::TransferFrom( const wxPrintData &data ) +void wxOSXPrintData::TransferPrinterNameFrom( const wxPrintData &data ) { CFArrayRef printerList; CFIndex index, count; @@ -158,7 +158,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); @@ -220,14 +223,14 @@ bool wxOSXPrintData::TransferFrom( const wxPrintData &data ) if ( PMPaperCreateCustom != NULL) { PMPaperCreateCustom(printer, wxCFStringRef( id, wxFont::GetDefaultEncoding() ), wxCFStringRef( name, wxFont::GetDefaultEncoding() ), - papersize.x, papersize.y, &margins, &paper); + 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); + papersize.x, papersize.y, &margins, &paper); } #endif } @@ -248,10 +251,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 +275,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); @@ -299,13 +308,22 @@ bool wxOSXPrintData::TransferFrom( const wxPrintData &data ) 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 +331,26 @@ 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 ) +{ + 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 +376,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 +393,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); @@ -406,19 +446,17 @@ 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 ; } @@ -558,8 +596,6 @@ bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) return false; } - printout->SetIsPreview(false); - if (m_printDialogData.GetMinPage() < 1) m_printDialogData.SetMinPage(1); if (m_printDialogData.GetMaxPage() < 1) @@ -615,6 +651,11 @@ bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt) #endif } } + else + { + // fallback + res.hRes = res.vRes = 300; + } printout->SetPPIPrinter(int(res.hRes), int(res.vRes)); // Set printout parameters @@ -682,8 +723,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();