#10181: wxOSX: patch for proper wxPrintData to/from native data exchange
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56754 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -129,19 +129,37 @@ void wxMacCarbonPrintData::ValidateOrCreate()
|
|||||||
|
|
||||||
bool wxMacCarbonPrintData::TransferFrom( const wxPrintData &data )
|
bool wxMacCarbonPrintData::TransferFrom( const wxPrintData &data )
|
||||||
{
|
{
|
||||||
|
CFArrayRef printerList;
|
||||||
|
CFIndex index, count;
|
||||||
|
PMPrinter printer;
|
||||||
|
CFStringRef name;
|
||||||
|
|
||||||
ValidateOrCreate() ;
|
ValidateOrCreate() ;
|
||||||
PMSetCopies( (PMPrintSettings) m_macPrintSettings , data.GetNoCopies() , false ) ;
|
|
||||||
if ( data.IsOrientationReversed() )
|
if (PMServerCreatePrinterList(kPMServerLocal, &printerList) == noErr)
|
||||||
PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
|
{
|
||||||
kPMReverseLandscape : kPMReversePortrait , false ) ;
|
count = CFArrayGetCount(printerList);
|
||||||
else
|
for (index = 0; index < count; index++)
|
||||||
PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
|
{
|
||||||
kPMLandscape : kPMPortrait , false ) ;
|
printer = (PMPrinter)CFArrayGetValueAtIndex(printerList, index);
|
||||||
// collate cannot be set
|
if ((data.GetPrinterName().empty()) && (PMPrinterIsDefault(printer)))
|
||||||
#if 0 // not yet tested
|
break;
|
||||||
if ( !m_printerName.empty() )
|
else
|
||||||
PMSessionSetCurrentPrinter( (PMPrintSession) m_macPrintSession , wxCFStringRef( m_printerName , wxFont::GetDefaultEncoding() ) ) ;
|
{
|
||||||
#endif
|
name = PMPrinterGetName(printer);
|
||||||
|
CFRetain(name);
|
||||||
|
if (data.GetPrinterName() == wxCFStringRef(name).AsString())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (index < count)
|
||||||
|
PMSessionSetCurrentPMPrinter((PMPrintSession)m_macPrintSession, printer);
|
||||||
|
CFRelease(printerList);
|
||||||
|
}
|
||||||
|
|
||||||
|
PMSetCopies( m_macPrintSettings , data.GetNoCopies() , false ) ;
|
||||||
|
PMSetCollate(m_macPrintSettings, data.GetCollate());
|
||||||
|
|
||||||
#if wxOSX_USE_CARBON
|
#if wxOSX_USE_CARBON
|
||||||
PMColorMode color ;
|
PMColorMode color ;
|
||||||
PMGetColorMode( (PMPrintSettings) m_macPrintSettings, &color ) ;
|
PMGetColorMode( (PMPrintSettings) m_macPrintSettings, &color ) ;
|
||||||
@@ -171,12 +189,74 @@ bool wxMacCarbonPrintData::TransferFrom( const wxPrintData &data )
|
|||||||
PMSetDuplex( (PMPrintSettings) m_macPrintSettings, mode ) ;
|
PMSetDuplex( (PMPrintSettings) m_macPrintSettings, mode ) ;
|
||||||
|
|
||||||
// PMQualityMode not yet accessible via API
|
// PMQualityMode not yet accessible via API
|
||||||
// todo paperSize
|
|
||||||
|
|
||||||
PMResolution res;
|
PMResolution res;
|
||||||
PMPrinter printer;
|
|
||||||
PMSessionGetCurrentPrinter(m_macPrintSession, &printer);
|
PMSessionGetCurrentPrinter(m_macPrintSession, &printer);
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
CFArrayRef formatList;
|
||||||
|
PMSessionCreatePageFormatList(m_macPrintSession, printer, &formatList);
|
||||||
|
if (formatList)
|
||||||
|
{
|
||||||
|
count = CFArrayGetCount(formatList);
|
||||||
|
for (index = 0; index < count; index++)
|
||||||
|
{
|
||||||
|
PMPageFormat temp = (PMPageFormat)CFArrayGetValueAtIndex(formatList, index);
|
||||||
|
PMRect rPaper;
|
||||||
|
PMGetUnadjustedPaperRect(temp, &rPaper);
|
||||||
|
wxSize sz((int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) ,
|
||||||
|
(int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ));
|
||||||
|
wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
|
||||||
|
if (((data.GetPaperId() != wxPAPER_NONE) && (id == data.GetPaperId())) ||
|
||||||
|
((data.GetPaperId() == wxPAPER_NONE) && (sz == data.GetPaperSize())))
|
||||||
|
{
|
||||||
|
PMCopyPageFormat(temp, m_macPageFormat);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CFRelease(formatList);
|
||||||
|
}
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
PMPaper paper;
|
||||||
|
const PMPaperMargins margins = { 0.0, 0.0, 0.0, 0.0 };
|
||||||
|
wxString id, name(_T("Custom paper"));
|
||||||
|
wxSize sz;
|
||||||
|
double width, height;
|
||||||
|
|
||||||
|
id.Printf(_T("wxPaperCustom%dx%d"), sz.x, sz.y);
|
||||||
|
if (data.GetPaperId() == wxPAPER_NONE)
|
||||||
|
sz = data.GetPaperSize();
|
||||||
|
else
|
||||||
|
sz = wxThePrintPaperDatabase->GetSize(data.GetPaperId());
|
||||||
|
width = ((double)sz.x / 10.0) * mm2pt;
|
||||||
|
height = ((double)sz.y / 10.0) * mm2pt;
|
||||||
|
|
||||||
|
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
|
||||||
|
PMPaperCreate(printer, wxCFStringRef( id, wxFont::GetDefaultEncoding() ), wxCFStringRef( name, wxFont::GetDefaultEncoding() ), width, height, &margins, &paper);
|
||||||
|
#else
|
||||||
|
if (PMPaperCreateCustom(printer, wxCFStringRef( id, wxFont::GetDefaultEncoding() ), wxCFStringRef( name, wxFont::GetDefaultEncoding() ), width, height, &margins, &paper) != noErr)
|
||||||
|
paper = NULL;
|
||||||
|
#endif
|
||||||
|
if (paper)
|
||||||
|
{
|
||||||
|
PMPageFormat temp;
|
||||||
|
if (PMCreatePageFormatWithPMPaper(&temp, paper) == noErr) {
|
||||||
|
PMCopyPageFormat(temp, m_macPageFormat);
|
||||||
|
PMRelease(temp);
|
||||||
|
}
|
||||||
|
PMRelease(paper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( data.IsOrientationReversed() )
|
||||||
|
PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
|
||||||
|
kPMReverseLandscape : kPMReversePortrait , false ) ;
|
||||||
|
else
|
||||||
|
PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data.GetOrientation() == wxLANDSCAPE ) ?
|
||||||
|
kPMLandscape : kPMPortrait , false ) ;
|
||||||
|
|
||||||
#if wxOSX_USE_CARBON
|
#if wxOSX_USE_CARBON
|
||||||
PMTag tag = kPMMaxSquareResolution;
|
PMTag tag = kPMMaxSquareResolution;
|
||||||
PMPrinterGetPrinterResolution(printer, tag, &res);
|
PMPrinterGetPrinterResolution(printer, tag, &res);
|
||||||
@@ -221,17 +301,22 @@ bool wxMacCarbonPrintData::TransferTo( wxPrintData &data )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// collate cannot be set
|
Boolean collate;
|
||||||
#if 0
|
if (PMGetCollate(m_macPrintSettings, &collate) == noErr)
|
||||||
|
data.SetCollate(collate);
|
||||||
|
|
||||||
|
CFStringRef name;
|
||||||
|
PMPrinter printer ;
|
||||||
|
PMSessionGetCurrentPrinter( m_macPrintSession, &printer );
|
||||||
|
if (PMPrinterIsDefault(printer))
|
||||||
|
data.SetPrinterName(wxEmptyString);
|
||||||
|
else
|
||||||
{
|
{
|
||||||
wxCFStringRef name ;
|
name = PMPrinterGetName(printer);
|
||||||
PMPrinter printer ;
|
CFRetain(name);
|
||||||
PMSessionGetCurrentPrinter( m_macPrintSession ,
|
data.SetPrinterName(wxCFStringRef(name).AsString());
|
||||||
&printer ) ;
|
|
||||||
m_printerName = name.AsString() ;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef __LP64__
|
#ifndef __LP64__
|
||||||
PMColorMode color ;
|
PMColorMode color ;
|
||||||
err = PMGetColorMode( m_macPrintSettings, &color ) ;
|
err = PMGetColorMode( m_macPrintSettings, &color ) ;
|
||||||
@@ -262,14 +347,11 @@ bool wxMacCarbonPrintData::TransferTo( wxPrintData &data )
|
|||||||
err = PMGetUnadjustedPaperRect( m_macPageFormat, &rPaper);
|
err = PMGetUnadjustedPaperRect( m_macPageFormat, &rPaper);
|
||||||
if ( err == noErr )
|
if ( err == noErr )
|
||||||
{
|
{
|
||||||
wxSize sz((int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) ,
|
wxSize sz((int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) * 10,
|
||||||
(int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ));
|
(int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ) * 10);
|
||||||
data.SetPaperSize(sz);
|
data.SetPaperSize(sz);
|
||||||
wxPaperSize id = wxThePrintPaperDatabase->GetSize(wxSize(sz.x* 10, sz.y * 10));
|
wxPaperSize id = wxThePrintPaperDatabase->GetSize(sz);
|
||||||
if (id != wxPAPER_NONE)
|
data.SetPaperId(id);
|
||||||
{
|
|
||||||
data.SetPaperId(id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user