supporting paper height, fixes #10376
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@58125 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -46,8 +46,10 @@ public :
|
|||||||
virtual void TransferTo( wxPrintDialogData * ) ;
|
virtual void TransferTo( wxPrintDialogData * ) ;
|
||||||
private :
|
private :
|
||||||
virtual void ValidateOrCreate() ;
|
virtual void ValidateOrCreate() ;
|
||||||
|
virtual void EnsureValidSession() ;
|
||||||
public :
|
public :
|
||||||
PMPrintSession m_macPrintSession ;
|
PMPrintSession m_macPrintSession ;
|
||||||
|
PMPaper m_macPaper ;
|
||||||
PMPageFormat m_macPageFormat ;
|
PMPageFormat m_macPageFormat ;
|
||||||
PMPrintSettings m_macPrintSettings ;
|
PMPrintSettings m_macPrintSettings ;
|
||||||
private:
|
private:
|
||||||
|
@@ -2,10 +2,10 @@
|
|||||||
// Name: src/mac/carbon/printwin.cpp
|
// Name: src/mac/carbon/printwin.cpp
|
||||||
// Purpose: wxMacPrinter framework
|
// Purpose: wxMacPrinter framework
|
||||||
// Author: Julian Smart
|
// Author: Julian Smart
|
||||||
// Modified by:
|
// Modified by: Stefan Csomor
|
||||||
// Created: 04/01/98
|
// Created: 04/01/98
|
||||||
// RCS-ID: $Id$
|
// RCS-ID: $Id$
|
||||||
// Copyright: (c) Julian Smart
|
// Copyright: (c) Julian Smart, Stefan Csomor
|
||||||
// Licence: wxWindows licence
|
// Licence: wxWindows licence
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -51,6 +51,7 @@ wxMacCarbonPrintData::wxMacCarbonPrintData()
|
|||||||
m_macPageFormat = kPMNoPageFormat;
|
m_macPageFormat = kPMNoPageFormat;
|
||||||
m_macPrintSettings = kPMNoPrintSettings;
|
m_macPrintSettings = kPMNoPrintSettings;
|
||||||
m_macPrintSession = kPMNoReference ;
|
m_macPrintSession = kPMNoReference ;
|
||||||
|
m_macPaper = kPMNoData;
|
||||||
ValidateOrCreate() ;
|
ValidateOrCreate() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,41 +74,79 @@ wxMacCarbonPrintData::~wxMacCarbonPrintData()
|
|||||||
(void)PMRelease(m_macPrintSession);
|
(void)PMRelease(m_macPrintSession);
|
||||||
m_macPrintSession = kPMNoReference;
|
m_macPrintSession = kPMNoReference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( m_macPaper != kPMNoData )
|
||||||
|
{
|
||||||
|
(void)PMRelease(m_macPaper);
|
||||||
|
m_macPaper = kPMNoData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxMacCarbonPrintData::EnsureValidSession()
|
||||||
|
{
|
||||||
|
if ( m_macPrintSession == kPMNoReference )
|
||||||
|
{
|
||||||
|
PMCreateSession( &m_macPrintSession ) ;
|
||||||
|
}
|
||||||
|
wxASSERT( m_macPrintSession != kPMNoReference );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxMacCarbonPrintData::ValidateOrCreate()
|
void wxMacCarbonPrintData::ValidateOrCreate()
|
||||||
{
|
{
|
||||||
OSStatus err = noErr ;
|
EnsureValidSession();
|
||||||
if ( m_macPrintSession == kPMNoReference )
|
|
||||||
{
|
OSStatus err = noErr;
|
||||||
err = PMCreateSession( (PMPrintSession *) &m_macPrintSession ) ;
|
|
||||||
}
|
|
||||||
// Set up a valid PageFormat object.
|
// Set up a valid PageFormat object.
|
||||||
if ( m_macPageFormat == kPMNoPageFormat)
|
if ( m_macPageFormat == kPMNoPageFormat)
|
||||||
{
|
{
|
||||||
err = PMCreatePageFormat((PMPageFormat *) &m_macPageFormat);
|
if ( m_macPaper != kPMNoData )
|
||||||
|
|
||||||
// Note that PMPageFormat is not session-specific, but calling
|
|
||||||
// PMSessionDefaultPageFormat assigns values specific to the printer
|
|
||||||
// associated with the current printing session.
|
|
||||||
if ((err == noErr) &&
|
|
||||||
( m_macPageFormat != kPMNoPageFormat))
|
|
||||||
{
|
{
|
||||||
err = PMSessionDefaultPageFormat((PMPrintSession) m_macPrintSession,
|
err = PMCreatePageFormatWithPMPaper(&m_macPageFormat, m_macPaper);
|
||||||
(PMPageFormat) m_macPageFormat);
|
if ( (err == noErr) && ( m_macPageFormat != kPMNoPageFormat))
|
||||||
|
{
|
||||||
|
err = PMSessionValidatePageFormat(m_macPrintSession,
|
||||||
|
m_macPageFormat,
|
||||||
|
kPMDontWantBoolean);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
err = PMCreatePageFormat(&m_macPageFormat);
|
||||||
|
// Note that PMPageFormat is not session-specific, but calling
|
||||||
|
// PMSessionDefaultPageFormat assigns values specific to the printer
|
||||||
|
// associated with the current printing session.
|
||||||
|
if ( (err == noErr) && ( m_macPageFormat != kPMNoPageFormat))
|
||||||
|
{
|
||||||
|
err = PMSessionDefaultPageFormat(m_macPrintSession,
|
||||||
|
m_macPageFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
err = PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession,
|
err = PMSessionValidatePageFormat(m_macPrintSession,
|
||||||
(PMPageFormat) m_macPageFormat,
|
m_macPageFormat,
|
||||||
kPMDontWantBoolean);
|
kPMDontWantBoolean);
|
||||||
}
|
}
|
||||||
|
// make sure our m_macPaper is corresponding to what is used
|
||||||
|
if ( err == noErr )
|
||||||
|
{
|
||||||
|
PMPaper currentPaper = kPMNoData;
|
||||||
|
PMGetPageFormatPaper(m_macPageFormat, ¤tPaper);
|
||||||
|
if( currentPaper != m_macPaper )
|
||||||
|
{
|
||||||
|
PMRelease(m_macPaper);
|
||||||
|
m_macPaper = currentPaper;
|
||||||
|
PMRetain(m_macPaper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set up a valid PrintSettings object.
|
// Set up a valid PrintSettings object.
|
||||||
if ( m_macPrintSettings == kPMNoPrintSettings)
|
if ( m_macPrintSettings == kPMNoPrintSettings)
|
||||||
{
|
{
|
||||||
err = PMCreatePrintSettings((PMPrintSettings *) &m_macPrintSettings);
|
err = PMCreatePrintSettings(&m_macPrintSettings);
|
||||||
|
|
||||||
// Note that PMPrintSettings is not session-specific, but calling
|
// Note that PMPrintSettings is not session-specific, but calling
|
||||||
// PMSessionDefaultPrintSettings assigns values specific to the printer
|
// PMSessionDefaultPrintSettings assigns values specific to the printer
|
||||||
@@ -115,43 +154,96 @@ void wxMacCarbonPrintData::ValidateOrCreate()
|
|||||||
if ((err == noErr) &&
|
if ((err == noErr) &&
|
||||||
( m_macPrintSettings != kPMNoPrintSettings))
|
( m_macPrintSettings != kPMNoPrintSettings))
|
||||||
{
|
{
|
||||||
err = PMSessionDefaultPrintSettings((PMPrintSession) m_macPrintSession,
|
err = PMSessionDefaultPrintSettings(m_macPrintSession,
|
||||||
(PMPrintSettings) m_macPrintSettings);
|
m_macPrintSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
err = PMSessionValidatePrintSettings((PMPrintSession) m_macPrintSession,
|
err = PMSessionValidatePrintSettings(m_macPrintSession,
|
||||||
(PMPrintSettings) m_macPrintSettings,
|
m_macPrintSettings,
|
||||||
kPMDontWantBoolean);
|
kPMDontWantBoolean);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxMacCarbonPrintData::TransferFrom( const wxPrintData &data )
|
bool wxMacCarbonPrintData::TransferFrom( const wxPrintData &data )
|
||||||
{
|
{
|
||||||
|
EnsureValidSession();
|
||||||
|
|
||||||
|
PMPrinter printer;
|
||||||
|
PMSessionGetCurrentPrinter(m_macPrintSession, &printer);
|
||||||
|
|
||||||
|
wxSize papersize = wxDefaultSize;
|
||||||
|
const wxPaperSize paperId = data.GetPaperId();
|
||||||
|
if ( paperId != wxPAPER_NONE && wxThePrintPaperDatabase )
|
||||||
|
{
|
||||||
|
papersize = wxThePrintPaperDatabase->GetSize(paperId);
|
||||||
|
if ( papersize != wxDefaultSize )
|
||||||
|
{
|
||||||
|
papersize.x /= 10;
|
||||||
|
papersize.y /= 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
papersize = data.GetPaperSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( papersize != wxDefaultSize )
|
||||||
|
{
|
||||||
|
papersize.x *= mm2pt;
|
||||||
|
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 )
|
||||||
|
{
|
||||||
|
// we have to change the current paper
|
||||||
|
CFArrayRef paperlist = 0 ;
|
||||||
|
if ( PMPrinterGetPaperList( printer, &paperlist ) == noErr )
|
||||||
|
{
|
||||||
|
PMPaper bestPaper = kPMNoData ;
|
||||||
|
CFIndex top = CFArrayGetCount(paperlist);
|
||||||
|
for ( CFIndex i = 0 ; i < top ; ++ i )
|
||||||
|
{
|
||||||
|
PMPaper paper = (PMPaper) CFArrayGetValueAtIndex( paperlist, i );
|
||||||
|
PMPaperGetHeight(paper, &height);
|
||||||
|
PMPaperGetWidth(paper, &width);
|
||||||
|
if ( fabs( width - papersize.x ) < 5 &&
|
||||||
|
fabs( height - papersize.y ) < 5 )
|
||||||
|
{
|
||||||
|
// TODO test for duplicate hits and use additional
|
||||||
|
// criteria for best match
|
||||||
|
bestPaper = paper;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( bestPaper != kPMNoData )
|
||||||
|
{
|
||||||
|
PMRelease(m_macPaper);
|
||||||
|
m_macPaper = bestPaper;
|
||||||
|
PMRetain(m_macPaper);
|
||||||
|
PMRelease(m_macPageFormat);
|
||||||
|
m_macPageFormat = kPMNoPageFormat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ValidateOrCreate() ;
|
ValidateOrCreate() ;
|
||||||
PMSetCopies( (PMPrintSettings) m_macPrintSettings , data.GetNoCopies() , false ) ;
|
PMSetCopies( m_macPrintSettings , data.GetNoCopies() , false ) ;
|
||||||
if ( data.IsOrientationReversed() )
|
if ( data.IsOrientationReversed() )
|
||||||
PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
|
PMSetOrientation( m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
|
||||||
kPMReverseLandscape : kPMReversePortrait , false ) ;
|
kPMReverseLandscape : kPMReversePortrait , false ) ;
|
||||||
else
|
else
|
||||||
PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
|
PMSetOrientation( m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
|
||||||
kPMLandscape : kPMPortrait , false ) ;
|
kPMLandscape : kPMPortrait , false ) ;
|
||||||
// collate cannot be set
|
// collate cannot be set
|
||||||
#if 0 // not yet tested
|
#if 0 // not yet tested
|
||||||
if ( !m_printerName.empty() )
|
if ( !m_printerName.empty() )
|
||||||
PMSessionSetCurrentPrinter( (PMPrintSession) m_macPrintSession , wxMacCFStringHolder( m_printerName , wxFont::GetDefaultEncoding() ) ) ;
|
PMSessionSetCurrentPrinter( m_macPrintSession , wxMacCFStringHolder( m_printerName , wxFont::GetDefaultEncoding() ) ) ;
|
||||||
#endif
|
|
||||||
#ifndef __LP64__
|
|
||||||
PMColorMode color ;
|
|
||||||
PMGetColorMode( (PMPrintSettings) m_macPrintSettings, &color ) ;
|
|
||||||
if ( data.GetColour() )
|
|
||||||
{
|
|
||||||
if ( color == kPMBlackAndWhite )
|
|
||||||
PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMColor ) ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMBlackAndWhite ) ;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
||||||
@@ -171,23 +263,20 @@ bool wxMacCarbonPrintData::TransferFrom( const wxPrintData &data )
|
|||||||
mode = kPMDuplexNone ;
|
mode = kPMDuplexNone ;
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
PMSetDuplex( (PMPrintSettings) m_macPrintSettings, mode ) ;
|
PMSetDuplex( m_macPrintSettings, mode ) ;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// PMQualityMode not yet accessible via API
|
// PMQualityMode not accessible via API
|
||||||
// todo paperSize
|
// TODO: use our quality property to determine optimal resolution
|
||||||
|
|
||||||
PMResolution res;
|
PMResolution res;
|
||||||
PMPrinter printer;
|
|
||||||
PMSessionGetCurrentPrinter(m_macPrintSession, &printer);
|
|
||||||
PMTag tag = kPMMaxSquareResolution;
|
PMTag tag = kPMMaxSquareResolution;
|
||||||
PMPrinterGetPrinterResolution(printer, tag, &res);
|
PMPrinterGetPrinterResolution(printer, tag, &res);
|
||||||
PMSetResolution((PMPageFormat) m_macPageFormat, &res);
|
PMSetResolution(m_macPageFormat, &res);
|
||||||
|
|
||||||
// after setting the new resolution the format has to be updated, otherwise the page rect remains
|
// after setting the new resolution the format has to be updated, otherwise the page rect remains
|
||||||
// at the 'old' scaling
|
// at the 'old' scaling
|
||||||
PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession,
|
PMSessionValidatePageFormat(m_macPrintSession,
|
||||||
(PMPageFormat) m_macPageFormat,
|
m_macPageFormat,
|
||||||
kPMDontWantBoolean) ;
|
kPMDontWantBoolean) ;
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
@@ -203,7 +292,7 @@ bool wxMacCarbonPrintData::TransferTo( wxPrintData &data )
|
|||||||
data.SetNoCopies( copies ) ;
|
data.SetNoCopies( copies ) ;
|
||||||
|
|
||||||
PMOrientation orientation ;
|
PMOrientation orientation ;
|
||||||
err = PMGetOrientation( m_macPageFormat , &orientation ) ;
|
err = PMGetOrientation( m_macPageFormat , &orientation ) ;
|
||||||
if ( err == noErr )
|
if ( err == noErr )
|
||||||
{
|
{
|
||||||
if ( orientation == kPMPortrait || orientation == kPMReversePortrait )
|
if ( orientation == kPMPortrait || orientation == kPMReversePortrait )
|
||||||
@@ -229,17 +318,11 @@ bool wxMacCarbonPrintData::TransferTo( wxPrintData &data )
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __LP64__
|
|
||||||
PMColorMode color ;
|
|
||||||
err = PMGetColorMode( m_macPrintSettings, &color ) ;
|
|
||||||
if ( err == noErr )
|
|
||||||
data.SetColour( !(color == kPMBlackAndWhite) ) ;
|
|
||||||
#endif
|
|
||||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
||||||
if ( &PMGetDuplex!=NULL )
|
if ( &PMGetDuplex!=NULL )
|
||||||
{
|
{
|
||||||
PMDuplexMode mode = 0 ;
|
PMDuplexMode mode = 0 ;
|
||||||
PMGetDuplex( (PMPrintSettings) m_macPrintSettings, &mode ) ;
|
PMGetDuplex( m_macPrintSettings, &mode ) ;
|
||||||
switch( mode )
|
switch( mode )
|
||||||
{
|
{
|
||||||
case kPMDuplexNoTumble :
|
case kPMDuplexNoTumble :
|
||||||
@@ -257,21 +340,17 @@ bool wxMacCarbonPrintData::TransferTo( wxPrintData &data )
|
|||||||
#endif
|
#endif
|
||||||
// PMQualityMode not yet accessible via API
|
// PMQualityMode not yet accessible via API
|
||||||
|
|
||||||
PMPaper paper ;
|
double height, width;
|
||||||
PMGetPageFormatPaper( m_macPageFormat, &paper );
|
PMPaperGetHeight(m_macPaper, &height);
|
||||||
|
PMPaperGetWidth(m_macPaper, &width);
|
||||||
PMRect rPaper;
|
|
||||||
err = PMGetUnadjustedPaperRect( m_macPageFormat, &rPaper);
|
wxSize sz((int)(width * pt2mm + 0.5 ) ,
|
||||||
if ( err == noErr )
|
(int)(height * pt2mm + 0.5 ));
|
||||||
|
data.SetPaperSize(sz);
|
||||||
|
wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
|
||||||
|
if (id != wxPAPER_NONE)
|
||||||
{
|
{
|
||||||
wxSize sz((int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) ,
|
data.SetPaperId(id);
|
||||||
(int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ));
|
|
||||||
data.SetPaperSize(sz);
|
|
||||||
wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
|
|
||||||
if (id != wxPAPER_NONE)
|
|
||||||
{
|
|
||||||
data.SetPaperId(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
@@ -419,7 +498,7 @@ bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
|
|||||||
PMResolution res;
|
PMResolution res;
|
||||||
wxMacCarbonPrintData* nativeData = (wxMacCarbonPrintData*)
|
wxMacCarbonPrintData* nativeData = (wxMacCarbonPrintData*)
|
||||||
(m_printDialogData.GetPrintData().GetNativeData());
|
(m_printDialogData.GetPrintData().GetNativeData());
|
||||||
PMGetResolution((PMPageFormat) (nativeData->m_macPageFormat), &res);
|
PMGetResolution((nativeData->m_macPageFormat), &res);
|
||||||
printout->SetPPIPrinter(int(res.hRes), int(res.vRes));
|
printout->SetPPIPrinter(int(res.hRes), int(res.vRes));
|
||||||
|
|
||||||
// Set printout parameters
|
// Set printout parameters
|
||||||
|
Reference in New Issue
Block a user