switch to pImpl pattern for mac printing

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20670 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2003-05-19 18:45:01 +00:00
parent 5f965f0b41
commit 746d758297
7 changed files with 1630 additions and 1138 deletions

View File

@@ -62,6 +62,10 @@
#endif
#endif // MSW
#ifdef __WXMAC__
#include "wx/mac/private/print.h"
#endif
#if wxUSE_PRINTING_ARCHITECTURE
IMPLEMENT_DYNAMIC_CLASS(wxPrintData, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxPrintDialogData, wxObject)
@@ -71,23 +75,6 @@
IMPLEMENT_DYNAMIC_CLASS(wxFontData, wxObject)
IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
#ifdef __WXMAC__
#include "wx/mac/uma.h"
#if defined(TARGET_CARBON) && !defined(__DARWIN__)
# if PM_USE_SESSION_APIS
# include <PMCore.h>
# endif
# include <PMApplication.h>
#endif
#ifndef __DARWIN__
#include "Printing.h"
#endif
#define mm2pt 2.83464566929
#define pt2mm 0.352777777778
#endif // Mac
#ifndef DMPAPER_USER
#define DMPAPER_USER 256
#endif
@@ -187,25 +174,7 @@ wxPrintData::wxPrintData()
m_devMode = (void*) NULL;
m_devNames = (void*) NULL;
#elif defined( __WXMAC__ )
#if TARGET_CARBON
m_macPageFormat = kPMNoPageFormat;
m_macPrintSettings = kPMNoPrintSettings;
m_macPrintSession = kPMNoReference ;
ValidateOrCreateNative() ;
#else
m_macPrintSettings = (THPrint) NewHandleClear( sizeof( TPrint ) );
(**(THPrint)m_macPrintSettings).iPrVersion = 0; // something invalid
(**(THPrint)m_macPrintSettings).prInfo.iHRes = 72;
(**(THPrint)m_macPrintSettings).prInfo.iVRes = 72;
Rect r1 = { 0, 0, 8*72 - 2 * 18, 11*72 - 2 * 36 };
(**(THPrint)m_macPrintSettings).prInfo.rPage = r1;// must have its top left & (0,0)
Rect r2 = { -18, -36, 8*72 - 18, 11*72 - 36 };
(**(THPrint)m_macPrintSettings).rPaper = r2;
(**(THPrint)m_macPrintSettings).prStl.iPageV = 11 * 120 ; // 11 inches in 120th of an inch
(**(THPrint)m_macPrintSettings).prStl.iPageH = 8 * 120 ; // 8 inches in 120th of an inch
#endif
m_nativePrintData = wxNativePrintData::Create() ;
#endif
m_printOrientation = wxPORTRAIT;
m_printNoCopies = 1;
@@ -254,13 +223,7 @@ wxPrintData::wxPrintData(const wxPrintData& printData)
m_devMode = (void*) NULL;
m_devNames = (void*) NULL;
#elif defined( __WXMAC__ )
#if TARGET_CARBON
m_macPageFormat = kPMNoPageFormat;
m_macPrintSettings = kPMNoPrintSettings;
m_macPrintSession = kPMNoReference ;
#else
m_macPrintSettings = NULL;
#endif
m_nativePrintData = wxNativePrintData::Create() ;
#endif
(*this) = printData;
}
@@ -275,40 +238,7 @@ wxPrintData::~wxPrintData()
if ( hDevNames )
GlobalFree(hDevNames);
#elif defined(__WXMAC__)
#if TARGET_CARBON
if (m_macPageFormat != kPMNoPageFormat)
{
#if PM_USE_SESSION_APIS
(void)PMRelease(m_macPageFormat);
#else
(void)PMDisposePageFormat(m_macPageFormat);
#endif
m_macPageFormat = kPMNoPageFormat;
}
if (m_macPrintSettings != kPMNoPrintSettings)
{
#if PM_USE_SESSION_APIS
(void)PMRelease(m_macPrintSettings);
#else
(void)PMDisposePrintSettings(m_macPrintSettings);
#endif
m_macPrintSettings = kPMNoPrintSettings;
}
if ( m_macPrintSession != kPMNoReference )
{
#if PM_USE_SESSION_APIS
(void)PMRelease(m_macPrintSession);
#else
(void)PMDisposePrintSession(m_macPrintSession);
#endif
m_macPrintSession = kPMNoReference;
}
#else
wxASSERT( m_macPrintSettings );
// we should perhaps delete
#endif
delete m_nativePrintData ;
#endif
}
@@ -755,153 +685,12 @@ void wxPrintData::ConvertFromNative()
void wxPrintData::ConvertToNative()
{
ValidateOrCreateNative() ;
#if TARGET_CARBON
PMSetCopies( (PMPrintSettings) m_macPrintSettings , m_printNoCopies , false ) ;
PMSetOrientation( (PMPageFormat) m_macPageFormat , ( m_printOrientation == wxLANDSCAPE ) ?
kPMLandscape : kPMPortrait , false ) ;
// collate cannot be set
#if 0 // not yet tested
if ( m_printerName.Length() > 0 )
PMSessionSetCurrentPrinter( (PMPrintSession) m_macPrintSession , wxMacCFStringHolder( m_printerName ) ) ;
#endif
PMColorMode color ;
PMGetColorMode( (PMPrintSettings) m_macPrintSettings, &color ) ;
if (m_colour)
{
if ( color == kPMBlackAndWhite )
PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMColor ) ;
}
else
PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMBlackAndWhite ) ;
// PMDuplexMode not yet accessible via API
// PMQualityMode not yet accessible via API
// todo paperSize
#else
// on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0
(**(THPrint)m_macPrintSettings).prJob.iCopies = m_printNoCopies;
(**(THPrint)m_macPrintSettings).rPaper.left = int( ((double) m_minMarginTopLeft.x)*mm2pt );
(**(THPrint)m_macPrintSettings).rPaper.top = int( ((double) m_minMarginTopLeft.y)*mm2pt );
(**(THPrint)m_macPrintSettings).rPaper.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x)*mm2pt );
(**(THPrint)m_macPrintSettings).rPaper.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y)*mm2pt );
(**(THPrint)m_macPrintSettings).prInfo.rPage.left = 0;
(**(THPrint)m_macPrintSettings).prInfo.rPage.top = 0;
(**(THPrint)m_macPrintSettings).prInfo.rPage.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x - m_minMarginBottomRight.x)*mm2pt );
(**(THPrint)m_macPrintSettings).prInfo.rPage.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y - m_minMarginBottomRight.y)*mm2pt );
#endif
m_nativePrintData->TransferFrom( this ) ;
}
void wxPrintData::ConvertFromNative()
{
#if TARGET_CARBON
OSStatus err = noErr ;
UInt32 copies ;
err = PMGetCopies( (PMPrintSettings) m_macPrintSettings , &copies ) ;
if ( err == noErr )
m_printNoCopies = copies ;
PMOrientation orientation ;
err = PMGetOrientation( (PMPageFormat) m_macPageFormat , &orientation ) ;
if ( err == noErr )
{
if ( orientation == kPMPortrait || orientation == kPMReversePortrait )
m_printOrientation = wxPORTRAIT ;
else
m_printOrientation = wxLANDSCAPE ;
}
// collate cannot be set
#if 0
{
wxMacCFStringHolder name ;
PMPrinter printer ;
PMSessionGetCurrentPrinter( (PMPrintSession) m_macPrintSession ,
&printer ) ;
m_printerName = name.AsString() ;
}
#endif
PMColorMode color ;
err = PMGetColorMode( (PMPrintSettings) m_macPrintSettings, &color ) ;
if ( err == noErr )
m_colour = !(color == kPMBlackAndWhite) ;
// PMDuplexMode not yet accessible via API
// PMQualityMode not yet accessible via API
// todo paperSize
PMRect rPaper;
err = PMGetUnadjustedPaperRect((PMPageFormat) m_macPageFormat, &rPaper);
if ( err == noErr )
{
m_paperSize.x = (int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 );
m_paperSize.y = (int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 );
}
#else
m_printNoCopies = (**(THPrint)m_macPrintSettings).prJob.iCopies;
// paper size
m_paperSize.x = ((double) (**(THPrint)m_macPrintSettings).rPaper.right - (**(THPrint)m_macPrintSettings).rPaper.left ) * pt2mm;
m_paperSize.y = ((double) (**(THPrint)m_macPrintSettings).rPaper.bottom - (**(THPrint)m_macPrintSettings).rPaper.top ) * pt2mm;
#endif
}
void wxPrintData::ValidateOrCreateNative()
{
#if TARGET_CARBON
OSStatus err = noErr ;
if ( m_macPrintSession == kPMNoReference )
{
err = PMCreateSession( (PMPrintSession *) &m_macPrintSession ) ;
}
// Set up a valid PageFormat object.
if ( m_macPageFormat == kPMNoPageFormat)
{
err = PMCreatePageFormat((PMPageFormat *) &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((PMPrintSession) m_macPrintSession,
(PMPageFormat) m_macPageFormat);
}
}
else
{
err = PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession,
(PMPageFormat) m_macPageFormat,
kPMDontWantBoolean);
}
// Set up a valid PrintSettings object.
if ( m_macPrintSettings == kPMNoPrintSettings)
{
err = PMCreatePrintSettings((PMPrintSettings *) &m_macPrintSettings);
// Note that PMPrintSettings is not session-specific, but calling
// PMSessionDefaultPrintSettings assigns values specific to the printer
// associated with the current printing session.
if ((err == noErr) &&
( m_macPrintSettings != kPMNoPrintSettings))
{
err = PMSessionDefaultPrintSettings((PMPrintSession) m_macPrintSession,
(PMPrintSettings) m_macPrintSettings);
}
}
else
{
err = PMSessionValidatePrintSettings((PMPrintSession) m_macPrintSession,
(PMPrintSettings) m_macPrintSettings,
kPMDontWantBoolean);
}
#else
#endif
m_nativePrintData->TransferTo( this ) ;
}
#endif
@@ -909,43 +698,7 @@ void wxPrintData::ValidateOrCreateNative()
void wxPrintData::operator=(const wxPrintData& data)
{
#ifdef __WXMAC__
#if TARGET_CARBON
if ( m_macPrintSession != kPMNoPrintSettings )
{
PMRelease( m_macPrintSession ) ;
m_macPrintSession = kPMNoPrintSettings ;
}
if ( data.m_macPrintSession != kPMNoPrintSettings )
{
m_macPrintSession = data.m_macPrintSession ;
PMRetain( m_macPrintSession ) ;
}
if ( m_macPrintSettings != kPMNoPrintSettings )
{
PMRelease( m_macPrintSettings ) ;
m_macPrintSettings = kPMNoPrintSettings ;
}
if ( data.m_macPrintSettings != kPMNoPrintSettings )
{
m_macPrintSettings = data.m_macPrintSettings ;
PMRetain( m_macPrintSettings ) ;
}
if ( m_macPageFormat != kPMNoPageFormat )
{
PMRelease( m_macPageFormat ) ;
m_macPageFormat = kPMNoPageFormat ;
}
if ( data.m_macPageFormat != kPMNoPageFormat )
{
m_macPageFormat = data.m_macPageFormat ;
PMRetain( m_macPageFormat ) ;
}
#else
m_macPrintSettings = data.m_macPrintSettings;
HandToHand( (Handle*) &m_macPrintSettings );
#endif
m_nativePrintData->CopyFrom( data.m_nativePrintData ) ;
#endif
m_printNoCopies = data.m_printNoCopies;
m_printCollate = data.m_printCollate;
@@ -1231,37 +984,13 @@ void wxPrintDialogData::SetOwnerWindow(wxWindow* win)
void wxPrintDialogData::ConvertToNative()
{
m_printData.ConvertToNative();
#if TARGET_CARBON
PMSetPageRange( (PMPrintSettings) m_printData.m_macPrintSettings , m_printMinPage , m_printMaxPage ) ;
PMSetCopies( (PMPrintSettings) m_printData.m_macPrintSettings , m_printNoCopies , false ) ;
PMSetFirstPage( (PMPrintSettings) m_printData.m_macPrintSettings , m_printFromPage , false ) ;
PMSetLastPage( (PMPrintSettings) m_printData.m_macPrintSettings , m_printToPage , false ) ;
#else
(**(THPrint)m_printData.m_macPrintSettings).prJob.iFstPage = m_printFromPage;
(**(THPrint)m_printData.m_macPrintSettings).prJob.iLstPage = m_printToPage;
#endif
m_printData.m_nativePrintData->TransferFrom( this ) ;
}
void wxPrintDialogData::ConvertFromNative()
{
m_printData.ConvertFromNative();
#if TARGET_CARBON
UInt32 minPage , maxPage ;
PMGetPageRange( (PMPrintSettings) m_printData.m_macPrintSettings , &minPage , &maxPage ) ;
m_printMinPage = minPage ;
m_printMaxPage = maxPage ;
UInt32 copies ;
PMGetCopies( (PMPrintSettings) m_printData.m_macPrintSettings , &copies ) ;
m_printNoCopies = copies ;
UInt32 from , to ;
PMGetFirstPage((PMPrintSettings) m_printData.m_macPrintSettings , &from ) ;
PMGetLastPage((PMPrintSettings) m_printData.m_macPrintSettings , &to ) ;
m_printFromPage = from ;
m_printToPage = to ;
#else
m_printFromPage = (**(THPrint)m_printData.m_macPrintSettings).prJob.iFstPage;
m_printToPage = (**(THPrint)m_printData.m_macPrintSettings).prJob.iLstPage;
#endif
m_printData.m_nativePrintData->TransferTo( this ) ;
}
#endif
@@ -1577,12 +1306,7 @@ void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win)
void wxPageSetupDialogData::ConvertToNative()
{
m_printData.ConvertToNative();
// 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
#if TARGET_CARBON
#else
#endif
m_printData.m_nativePrintData->TransferFrom( this ) ;
}
void wxPageSetupDialogData::ConvertFromNative()
@@ -1590,27 +1314,7 @@ void wxPageSetupDialogData::ConvertFromNative()
m_printData.ConvertFromNative ();
m_paperSize = m_printData.GetPaperSize() ;
CalculateIdFromPaperSize();
#if TARGET_CARBON
PMRect rPaper;
OSStatus err = PMGetUnadjustedPaperRect((PMPageFormat) m_printData.m_macPageFormat, &rPaper);
if ( err == noErr )
{
PMRect rPage ;
err = PMGetUnadjustedPageRect((PMPageFormat) m_printData.m_macPageFormat , &rPage ) ;
if ( err == noErr )
{
m_minMarginTopLeft.x = (int)(((double) rPage.left - rPaper.left ) * pt2mm);
m_minMarginTopLeft.y = (int)(((double) rPage.top - rPaper.top ) * pt2mm);
m_minMarginBottomRight.x = ((double) rPaper.right - rPage.right ) * pt2mm;
m_minMarginBottomRight.y = ((double) rPaper.bottom - rPage.bottom ) * pt2mm;
}
}
#else
m_minMarginTopLeft.x = ((double) (**(THPrint)m_macPrintSettings).prInfo.rPage.left )-(**(THPrint)m_macPrintSettings).rPaper.left ) * pt2mm;
m_minMarginTopLeft.y = ((double) (**(THPrint)m_macPrintSettings).prInfo.rPage.top )-(**(THPrint)m_macPrintSettings).rPaper.top ) * pt2mm;
m_minMarginBottomRight.x = ((double) (**(THPrint)m_macPrintSettings).rPaper.right - (**(THPrint)m_macPrintSettings).prInfo.rPage.right ) * pt2mm;
m_minMarginBottomRight.y = ((double)(**(THPrint)m_macPrintSettings).rPaper.bottom - (**(THPrint)m_macPrintSettings).prInfo.rPage.bottom ) * pt2mm;
#endif
m_printData.m_nativePrintData->TransferTo( this ) ;
// adjust minimal values
if ( m_marginTopLeft.x < m_minMarginTopLeft.x )

View File

@@ -27,229 +27,347 @@
#include "wx/msgdlg.h"
#include <math.h>
#include "wx/mac/uma.h"
#ifndef __DARWIN__
#include "Printing.h"
#endif
#if defined(TARGET_CARBON) && !defined(__DARWIN__)
# if PM_USE_SESSION_APIS
# include <PMCore.h>
# endif
# include <PMApplication.h>
#endif
#include "wx/mac/private/print.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_CLASS(wxPrinterDC, wxDC)
#endif
GrafPtr macPrintFormerPort = NULL ;
class wxNativePrinterDC
{
public :
wxNativePrinterDC() {}
virtual ~wxNativePrinterDC() {}
virtual bool StartDoc( wxPrinterDC* dc , const wxString& message ) = 0;
virtual void EndDoc( wxPrinterDC* dc ) = 0;
virtual void StartPage( wxPrinterDC* dc ) = 0;
virtual void EndPage( wxPrinterDC* dc ) = 0;
virtual wxCoord GetMaxX() const = 0 ;
virtual wxCoord GetMaxY() const = 0 ;
// returns 0 in case of no Error, otherwise platform specific error codes
virtual wxUint32 GetStatus() const = 0 ;
bool Ok() { return GetStatus() == 0 ; }
static wxNativePrinterDC* Create(wxPrintData* data) ;
} ;
#if TARGET_CARBON
class wxMacCarbonPrinterDC : public wxNativePrinterDC
{
public :
wxMacCarbonPrinterDC( wxPrintData* data ) ;
~wxMacCarbonPrinterDC() ;
virtual bool StartDoc( wxPrinterDC* dc , const wxString& message ) ;
virtual void EndDoc( wxPrinterDC* dc ) ;
virtual void StartPage( wxPrinterDC* dc ) ;
virtual void EndPage( wxPrinterDC* dc ) ;
virtual wxCoord GetMaxX() const { return m_maxX ; }
virtual wxCoord GetMaxY() const { return m_maxY ; }
virtual wxUint32 GetStatus() const { return m_err ; }
private :
GrafPtr m_macPrintFormerPort ;
wxCoord m_maxX ;
wxCoord m_maxY ;
OSStatus m_err ;
} ;
wxMacCarbonPrinterDC::wxMacCarbonPrinterDC( wxPrintData* data )
{
::GetPort( & m_macPrintFormerPort ) ;
m_err = noErr ;
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) data->m_nativePrintData ;
PMRect rPage;
m_err = PMGetAdjustedPageRect(native->m_macPageFormat, &rPage);
if ( m_err != noErr )
return;
m_maxX = wxCoord(rPage.right - rPage.left) ;
m_maxY = wxCoord(rPage.bottom - rPage.top);
}
wxMacCarbonPrinterDC::~wxMacCarbonPrinterDC()
{
// nothing to release from print data, as wxPrinterDC has all data in its wxPrintData member
::SetPort( m_macPrintFormerPort ) ;
}
wxNativePrinterDC* wxNativePrinterDC::Create(wxPrintData* data)
{
return new wxMacCarbonPrinterDC(data) ;
}
bool wxMacCarbonPrinterDC::StartDoc( wxPrinterDC* dc , const wxString& WXUNUSED(message) )
{
if ( m_err )
return false ;
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().m_nativePrintData ;
m_err = PMSessionBeginDocument(native->m_macPrintSession,
native->m_macPrintSettings,
native->m_macPageFormat);
if ( m_err != noErr )
return false;
PMRect rPage;
m_err = PMGetAdjustedPageRect(native->m_macPageFormat, &rPage);
if ( m_err != noErr )
return false;
m_maxX = rPage.right - rPage.left ;
m_maxY = rPage.bottom - rPage.top ;
return true ;
}
void wxMacCarbonPrinterDC::EndDoc( wxPrinterDC* dc )
{
if ( m_err )
return ;
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().m_nativePrintData ;
m_err = PMSessionEndDocument(native->m_macPrintSession);
}
void wxMacCarbonPrinterDC::StartPage( wxPrinterDC* dc )
{
if ( m_err )
return ;
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().m_nativePrintData ;
m_err = PMSessionBeginPage(native->m_macPrintSession,
native->m_macPageFormat,
nil);
if ( m_err == noErr )
{
m_err = PMSessionGetGraphicsContext(native->m_macPrintSession,
nil,
(void**) &dc->m_macPort );
}
if ( m_err != noErr )
{
PMSessionEndPage(native->m_macPrintSession);
PMSessionEndDocument(native->m_macPrintSession);
}
else
{
PMRect rPage;
m_err = PMGetAdjustedPageRect(native->m_macPageFormat, &rPage);
if ( !m_err )
{
dc->m_macLocalOrigin.x = rPage.left ;
dc->m_macLocalOrigin.y = rPage.top ;
}
// since this is a non-critical error, we set the flag back
m_err = noErr ;
}
}
void wxMacCarbonPrinterDC::EndPage( wxPrinterDC* dc )
{
if ( m_err )
return ;
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().m_nativePrintData ;
m_err = PMSessionEndPage(native->m_macPrintSession);
if ( m_err != noErr )
{
PMSessionEndDocument(native->m_macPrintSession);
}
}
#else
class wxMacClassicPrinterDC : public wxNativePrinterDC
{
public :
wxMacClassicPrinterDC( wxPrintData* data ) ;
~wxMacClassicPrinterDC() ;
virtual bool StartDoc( wxPrinterDC* dc , const wxString& message ) ;
virtual void EndDoc( wxPrinterDC* dc ) ;
virtual void StartPage( wxPrinterDC* dc ) ;
virtual void EndPage( wxPrinterDC* dc ) ;
virtual wxCoord GetMaxX() const { return m_maxX ; }
virtual wxCoord GetMaxY() const { return m_maxY ; }
virtual wxUint32 GetStatus() const { return m_err ; }
private :
GrafPtr m_macPrintFormerPort ;
TPPrPort m_macPrintingPort ;
OSErr m_err ;
long m_maxX ;
long m_maxY ;
} ;
wxNativePrinterDC* wxNativePrinterDC::Create(wxPrintData* data)
{
return new wxMacClassicPrinterDC(data) ;
}
wxMacClassicPrinterDC::wxMacClassicPrinterDC(wxPrintData* data)
{
::GetPort( &m_macPrintFormerPort ) ;
m_err = noErr ;
::UMAPrOpen() ;
m_err = PrError() ;
if ( m_err != noErr )
return;
wxMacClassicPrintData *native = (wxMacClassicPrintData*) data->m_nativePrintData ;
if ( ::PrValidate( native->m_macPrintSettings ) )
{
// the driver has changed in the mean time, should we pop up a page setup dialog ?
if ( !::PrStlDialog( native->m_macPrintSettings ) )
{
m_err = -1 ;
return;
}
}
m_err = PrError() ;
if ( m_err == noErr )
{
m_maxX = (**native->m_macPrintSettings).prInfo.rPage.right - (**native->m_macPrintSettings).prInfo.rPage.left ;
m_maxY = (**native->m_macPrintSettings).prInfo.rPage.bottom - (**native->m_macPrintSettings).prInfo.rPage.top ;
}
}
wxMacClassicPrinterDC::~wxMacClassicPrinterDC()
{
::UMAPrClose() ;
::SetPort( LMGetWMgrPort() ) ;
}
bool wxMacClassicPrinterDC::StartDoc( wxPrinterDC* dc , const wxString& WXUNUSED(message) )
{
if ( m_err )
return false ;
wxMacClassicPrintData *native = (wxMacClassicPrintData*) dc->GetPrintData().m_nativePrintData ;
m_macPrintingPort = ::PrOpenDoc( native->m_macPrintSettings , NULL , NULL ) ;
m_err = PrError() ;
if ( m_err )
return false ;
// sets current port
dc->m_macPort = (GrafPtr ) m_macPrintingPort ;
m_maxX = (**native->m_macPrintSettings).prInfo.rPage.right - (**native->m_macPrintSettings).prInfo.rPage.left ;
m_maxY = (**native->m_macPrintSettings).prInfo.rPage.bottom - (**native->m_macPrintSettings).prInfo.rPage.top ;
return true ;
}
void wxMacClassicPrinterDC::EndDoc( wxPrinterDC* dc )
{
if ( m_err )
return ;
PrCloseDoc( m_macPrintingPort ) ;
m_err = PrError() ;
}
void wxMacClassicPrinterDC::StartPage( wxPrinterDC* dc )
{
if ( m_err )
return ;
wxMacClassicPrintData *native = (wxMacClassicPrintData*) dc->GetPrintData().m_nativePrintData ;
PrOpenPage( m_macPrintingPort , NULL ) ;
dc->m_macLocalOrigin.x = (**native->m_macPrintSettings).rPaper.left ;
dc->m_macLocalOrigin.y = (**native->m_macPrintSettings).rPaper.top ;
// m_macPrintingPort is now the current port
Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
::ClipRect( &clip ) ;
m_err = PrError() ;
if ( m_err != noErr )
::PrCloseDoc( m_macPrintingPort ) ;
}
void wxMacClassicPrinterDC::EndPage( wxPrinterDC* dc )
{
if ( m_err )
return ;
PrClosePage( m_macPrintingPort ) ;
m_err = PrError() ;
if ( m_err != noErr )
::PrCloseDoc( m_macPrintingPort ) ;
}
#endif
wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
{
OSStatus err = noErr ;
wxString message ;
m_ok = FALSE ;
m_printData = printdata ;
m_printData.ConvertToNative() ;
#if TARGET_CARBON && PM_USE_SESSION_APIS
m_macPrintSessionPort = printdata.m_macPrintSession ;
PMRetain( m_macPrintSessionPort ) ;
if ( err != noErr || m_macPrintSessionPort == kPMNoData )
#else
err = UMAPrOpen(NULL) ;
if ( err != noErr )
#endif
m_nativePrinterDC = wxNativePrinterDC::Create( &m_printData ) ;
if ( m_nativePrinterDC )
{
message.Printf( wxT("Print Error %ld"), err ) ;
m_ok = m_nativePrinterDC->Ok() ;
if ( !m_ok )
{
wxString message ;
message.Printf( wxT("Print Error %ld"), m_nativePrinterDC->GetStatus() ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
#if TARGET_CARBON && PM_USE_SESSION_APIS
PMRelease( m_macPrintSessionPort ) ;
#else
UMAPrClose(NULL) ;
#endif
m_ok = FALSE;
return;
}
#if !TARGET_CARBON
if ( ::PrValidate( (THPrint) m_printData.m_macPrintSettings ) )
{
// the driver has changed in the mean time, should we pop up a page setup dialog ?
if ( !::PrStlDialog( (THPrint) m_printData.m_macPrintSettings ) )
{
UMAPrClose(NULL) ;
m_ok = FALSE;
return;
}
}
err = PrError() ;
if ( err != noErr )
{
message.Printf( wxT("Print Error %ld"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
dialog.ShowModal();
UMAPrClose(NULL) ;
m_ok = FALSE;
return;
}
::GetPort( &macPrintFormerPort ) ;
#endif
m_ok = TRUE ;
m_minY = m_minX = 0 ;
#if TARGET_CARBON
PMRect rPage;
err = PMGetAdjustedPageRect((PMPageFormat)m_printData.m_macPageFormat, &rPage);
if ( err != noErr )
{
message.Printf( wxT("Print Error %ld"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
#if TARGET_CARBON && PM_USE_SESSION_APIS
PMRelease(&m_macPrintSessionPort) ;
#else
UMAPrClose(NULL) ;
#endif
m_ok = FALSE;
return;
}
m_maxX = wxCoord(rPage.right - rPage.left) ;
m_maxY = wxCoord(rPage.bottom - rPage.top);
#else
m_maxX = (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.right - (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.left ;
m_maxY = (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.bottom - (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.top ;
#endif
}
wxPrinterDC::~wxPrinterDC(void)
{
OSStatus err ;
wxString message ;
#if !TARGET_CARBON
if ( m_ok )
{
::UMAPrClose(NULL) ;
::SetPort( LMGetWMgrPort() ) ;
}
#else
if ( m_ok )
{
#if TARGET_CARBON && PM_USE_SESSION_APIS
PMRelease(&m_macPrintSessionPort) ;
#else
UMAPrClose(NULL) ;
#endif
}
#endif
delete m_nativePrinterDC ;
}
bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) )
bool wxPrinterDC::StartDoc( const wxString& message )
{
OSStatus err = noErr ;
wxString message ;
wxASSERT_MSG( Ok() , wxT("Called wxPrinterDC::StartDoc from an invalid object") ) ;
#if !TARGET_CARBON
m_macPrintSessionPort = ::PrOpenDoc( (THPrint) m_printData.m_macPrintSettings , NULL , NULL ) ;
err = PrError() ;
if ( err )
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
UMAPrClose(NULL) ;
m_ok = FALSE;
if ( !m_ok )
return false ;
}
// sets current port
m_macPort = (GrafPtr ) m_macPrintSessionPort ;
#else
#if PM_USE_SESSION_APIS
err = PMSessionBeginDocument((PMPrintSession)m_macPrintSessionPort,
(PMPrintSettings)m_printData.m_macPrintSettings,
(PMPageFormat)m_printData.m_macPageFormat);
if ( err != noErr )
#else
m_macPrintSessionPort = kPMNoReference ;
err = PMBeginDocument(
m_printData.m_macPrintSettings,
m_printData.m_macPageFormat,
&m_macPrintSessionPort);
if ( err != noErr || m_macPrintSessionPort == kPMNoReference )
#endif
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
#if TARGET_CARBON && PM_USE_SESSION_APIS
PMRelease(&m_macPrintSessionPort) ;
#else
UMAPrClose(NULL) ;
#endif
m_ok = FALSE;
return m_ok;
}
// sets current port
::GetPort( (GrafPtr *)&m_macPort ) ;
#endif
m_ok = TRUE ;
m_minY = m_minX = 0 ;
#if TARGET_CARBON
PMRect rPage;
err = PMGetAdjustedPageRect((PMPageFormat)m_printData.m_macPageFormat, &rPage);
if ( err != noErr )
if ( m_nativePrinterDC->StartDoc(this, message ) )
{
message.Printf( wxT("Print Error %d"), err ) ;
// in case we have to do additional things when successful
}
m_ok = m_nativePrinterDC->Ok() ;
if ( !m_ok )
{
wxString message ;
message.Printf( wxT("Print Error %ld"), m_nativePrinterDC->GetStatus() ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
#if TARGET_CARBON && PM_USE_SESSION_APIS
PMRelease(&m_macPrintSessionPort) ;
#else
UMAPrClose(NULL) ;
#endif
m_ok = FALSE;
return m_ok;
}
m_maxX = rPage.right - rPage.left ;
m_maxY = rPage.bottom - rPage.top ;
#else
m_maxX = (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.right - (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.left ;
m_maxY = (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.bottom - (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.top ;
#endif
return m_ok ;
}
void wxPrinterDC::EndDoc(void)
{
OSStatus err ;
if ( !m_ok )
return ;
m_nativePrinterDC->EndDoc( this ) ;
m_ok = m_nativePrinterDC->Ok() ;
if ( !m_ok )
{
wxString message ;
#if !TARGET_CARBON
if ( m_ok )
{
::UMAPrClose(NULL) ;
// ::SetPort( macPrintFormerPort ) ;
::SetPort( LMGetWMgrPort() ) ;
}
#else
if ( m_ok )
{
#if PM_USE_SESSION_APIS
err = PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort);
#else
err = PMEndDocument(m_macPrintSessionPort);
#endif
if ( err != noErr )
{
message.Printf( wxT("Print Error %d"), err ) ;
message.Printf( wxT("Print Error %ld"), m_nativePrinterDC->GetStatus() ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
}
#endif
}
void wxPrinterDC::StartPage(void)
{
@@ -271,63 +389,9 @@ void wxPrinterDC::StartPage(void)
m_macBrushInstalled = false ;
m_macPenInstalled = false ;
m_nativePrinterDC->StartPage(this) ;
m_ok = m_nativePrinterDC->Ok() ;
OSStatus err ;
wxString message ;
#if !TARGET_CARBON
PrOpenPage( (TPPrPort) m_macPrintSessionPort , NULL ) ;
m_macLocalOrigin.x = (**(THPrint)m_printData.m_macPrintSettings).rPaper.left ;
m_macLocalOrigin.y = (**(THPrint)m_printData.m_macPrintSettings).rPaper.top ;
Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
::ClipRect( &clip ) ;
err = PrError() ;
if ( err != noErr )
{
message.Printf( wxT("Print Error %ld"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
dialog.ShowModal();
::PrClosePage( (TPPrPort) m_macPrintSessionPort ) ;
::PrCloseDoc( (TPPrPort) m_macPrintSessionPort ) ;
::UMAPrClose(NULL) ;
::SetPort( macPrintFormerPort ) ;
m_ok = FALSE ;
}
#else
#if PM_USE_SESSION_APIS
err = PMSessionBeginPage((PMPrintSession)m_macPrintSessionPort,
(PMPageFormat)m_printData.m_macPageFormat,
nil);
#else
err = PMBeginPage(m_macPrintSessionPort, nil);
#endif
if ( err != noErr )
{
message.Printf( wxT("Print Error %ld"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
#if PM_USE_SESSION_APIS
PMSessionEndPage((PMPrintSession)m_macPrintSessionPort);
PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort);
UMAPrClose(&m_macPrintSessionPort) ;
#else
PMEndPage(m_macPrintSessionPort);
PMEndDocument(m_macPrintSessionPort);
UMAPrClose(NULL) ;
#endif
::SetPort( macPrintFormerPort ) ;
m_ok = FALSE ;
}
PMRect rPage;
err = PMGetAdjustedPageRect((PMPageFormat)m_printData.m_macPageFormat, &rPage);
if ( !err )
{
m_macLocalOrigin.x = rPage.left ;
m_macLocalOrigin.y = rPage.top ;
}
#endif
}
void wxPrinterDC::EndPage(void)
@@ -335,43 +399,18 @@ void wxPrinterDC::EndPage(void)
if ( !m_ok )
return ;
OSStatus err ;
wxString message ;
m_nativePrinterDC->EndPage(this) ;
m_ok = m_nativePrinterDC->Ok() ;
}
#if !TARGET_CARBON
PrClosePage( (TPPrPort) m_macPort ) ;
err = PrError() ;
if ( err != noErr )
void wxPrinterDC::DoGetSize(int *width, int *height) const
{
message.Printf( wxT("Print Error %ld") , err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
::PrCloseDoc( (TPPrPort) m_macPrintSessionPort ) ;
::UMAPrClose(NULL) ;
::SetPort( macPrintFormerPort ) ;
m_ok = FALSE ;
}
#else
#if PM_USE_SESSION_APIS
err = PMSessionEndPage((PMPrintSession)m_macPrintSessionPort);
#else
err = PMEndPage(m_macPrintSessionPort);
#endif
if ( err != noErr )
{
message.Printf( wxT("Print Error %ld"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
#if PM_USE_SESSION_APIS
PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort);
UMAPrClose(&m_macPrintSessionPort) ;
#else
PMEndDocument(m_macPrintSessionPort);
UMAPrClose(NULL) ;
#endif
::SetPort( macPrintFormerPort ) ;
m_ok = FALSE ;
}
#endif
wxCHECK_RET( m_ok , _T("GetSize() doesn't work without a valid wxPrinterDC") );
if ( width )
* width = m_nativePrinterDC->GetMaxX() ;
if ( height )
* height = m_nativePrinterDC->GetMaxY() ;
}

View File

@@ -17,17 +17,7 @@
#include "wx/printdlg.h"
#include "wx/dcprint.h"
#include "wx/msgdlg.h"
#include "wx/mac/uma.h"
#ifndef __DARWIN__
#include "Printing.h"
#endif
#if defined(TARGET_CARBON) && !defined(__DARWIN__)
# if PM_USE_SESSION_APIS
# include <PMCore.h>
# endif
# include <PMApplication.h>
#endif
#include "wx/mac/private/print.h"
// Use generic page setup dialog: use your own native one if one exists.
@@ -78,64 +68,12 @@ wxPrintDialog::~wxPrintDialog()
}
int wxPrintDialog::ShowModal()
{
int result = wxID_CANCEL ;
OSErr err = noErr ;
wxString message ;
#if !TARGET_CARBON
err = ::UMAPrOpen(NULL) ;
if ( err == noErr )
{
m_printDialogData.ConvertToNative() ;
if ( ::PrJobDialog( (THPrint) m_printDialogData.GetPrintData().m_macPrintSettings ) )
{
int result = m_printDialogData.GetPrintData().m_nativePrintData->ShowPrintDialog() ;
if ( result == wxID_OK )
m_printDialogData.ConvertFromNative() ;
result = wxID_OK ;
}
}
else
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxT(""), wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
::UMAPrClose(NULL) ;
#else
#if PM_USE_SESSION_APIS
Boolean accepted;
{
m_printDialogData.ConvertToNative() ;
// Display the Print dialog.
if (err == noErr)
{
err = PMSessionPrintDialog((PMPrintSession)m_printDialogData.GetPrintData().m_macPrintSession,
(PMPrintSettings)m_printDialogData.GetPrintData().m_macPrintSettings,
(PMPageFormat)m_printDialogData.GetPrintData().m_macPageFormat,
&accepted);
if ((err == noErr) && !accepted)
{
err = kPMCancel; // user clicked Cancel button
}
}
if ( err == noErr )
{
m_printDialogData.ConvertFromNative() ;
result = wxID_OK ;
}
}
if ((err != noErr) && (err != kPMCancel))
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
#else
#pragma warning "TODO: Printing for carbon without session apis"
#endif
#endif
return result ;
}
@@ -175,66 +113,12 @@ wxPageSetupDialog::~wxPageSetupDialog()
}
int wxPageSetupDialog::ShowModal()
{
int result = wxID_CANCEL ;
OSErr err = noErr ;
wxString message ;
#if !TARGET_CARBON
err = ::UMAPrOpen(NULL) ;
if ( err == noErr )
{
m_pageSetupData.ConvertToNative() ;
if ( ::PrStlDialog( (THPrint) m_pageSetupData.GetPrintData().m_macPrintSettings ) )
{
int result = m_pageSetupData.GetPrintData().m_nativePrintData->ShowPageSetupDialog() ;
if (result == wxID_OK )
m_pageSetupData.ConvertFromNative() ;
result = wxID_OK ;
}
}
else
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
::UMAPrClose(NULL) ;
#else
#if PM_USE_SESSION_APIS
Boolean accepted;
{
m_pageSetupData.ConvertToNative() ;
// Display the Page Setup dialog.
if (err == noErr)
{
err = PMSessionPageSetupDialog((PMPrintSession)m_pageSetupData.GetPrintData().m_macPrintSession,
(PMPageFormat)m_pageSetupData.GetPrintData().m_macPageFormat,
&accepted);
if ((err == noErr) && !accepted)
{
err = kPMCancel; // user clicked Cancel button
}
}
// If the user did not cancel, flatten and save the PageFormat object
// with our document.
if (err == noErr) {
// err = FlattenAndSavePageFormat(m_pageSetupData.GetPrintData().m_macPageFormat);
m_pageSetupData.ConvertFromNative() ;
result = wxID_OK ;
}
}
if ((err != noErr) && (err != kPMCancel))
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
#else
#pragma warning "TODO: Printing for carbon without session apis"
#endif
#endif
return result ;
}

View File

@@ -29,9 +29,14 @@
#include "wx/msgdlg.h"
#endif
#include "wx/mac/private.h"
#include "wx/mac/uma.h"
#include "wx/mac/printmac.h"
#include "wx/mac/private/print.h"
#define mm2pt 2.83464566929
#define pt2mm 0.352777777778
#include "wx/dcprint.h"
#include "wx/printdlg.h"
@@ -42,6 +47,472 @@ IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter, wxPrinterBase)
IMPLEMENT_CLASS(wxMacPrintPreview, wxPrintPreviewBase)
#endif
#if TARGET_CARBON
wxNativePrintData* wxNativePrintData::Create()
{
return new wxMacCarbonPrintData() ;
}
wxMacCarbonPrintData::wxMacCarbonPrintData()
{
m_macPageFormat = kPMNoPageFormat;
m_macPrintSettings = kPMNoPrintSettings;
m_macPrintSession = kPMNoReference ;
ValidateOrCreate() ;
}
wxMacCarbonPrintData::~wxMacCarbonPrintData()
{
if (m_macPageFormat != kPMNoPageFormat)
{
(void)PMRelease(m_macPageFormat);
m_macPageFormat = kPMNoPageFormat;
}
if (m_macPrintSettings != kPMNoPrintSettings)
{
(void)PMRelease(m_macPrintSettings);
m_macPrintSettings = kPMNoPrintSettings;
}
if ( m_macPrintSession != kPMNoReference )
{
(void)PMRelease(m_macPrintSession);
m_macPrintSession = kPMNoReference;
}
}
void wxMacCarbonPrintData::ValidateOrCreate()
{
OSStatus err = noErr ;
if ( m_macPrintSession == kPMNoReference )
{
err = PMCreateSession( (PMPrintSession *) &m_macPrintSession ) ;
}
// Set up a valid PageFormat object.
if ( m_macPageFormat == kPMNoPageFormat)
{
err = PMCreatePageFormat((PMPageFormat *) &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((PMPrintSession) m_macPrintSession,
(PMPageFormat) m_macPageFormat);
}
}
else
{
err = PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession,
(PMPageFormat) m_macPageFormat,
kPMDontWantBoolean);
}
// Set up a valid PrintSettings object.
if ( m_macPrintSettings == kPMNoPrintSettings)
{
err = PMCreatePrintSettings((PMPrintSettings *) &m_macPrintSettings);
// Note that PMPrintSettings is not session-specific, but calling
// PMSessionDefaultPrintSettings assigns values specific to the printer
// associated with the current printing session.
if ((err == noErr) &&
( m_macPrintSettings != kPMNoPrintSettings))
{
err = PMSessionDefaultPrintSettings((PMPrintSession) m_macPrintSession,
(PMPrintSettings) m_macPrintSettings);
}
}
else
{
err = PMSessionValidatePrintSettings((PMPrintSession) m_macPrintSession,
(PMPrintSettings) m_macPrintSettings,
kPMDontWantBoolean);
}
}
void wxMacCarbonPrintData::TransferFrom( wxPrintData* data )
{
ValidateOrCreate() ;
PMSetCopies( (PMPrintSettings) m_macPrintSettings , data->GetNoCopies() , false ) ;
PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data->GetOrientation() == wxLANDSCAPE ) ?
kPMLandscape : kPMPortrait , false ) ;
// collate cannot be set
#if 0 // not yet tested
if ( m_printerName.Length() > 0 )
PMSessionSetCurrentPrinter( (PMPrintSession) m_macPrintSession , wxMacCFStringHolder( m_printerName ) ) ;
#endif
PMColorMode color ;
PMGetColorMode( (PMPrintSettings) m_macPrintSettings, &color ) ;
if ( data->GetColour() )
{
if ( color == kPMBlackAndWhite )
PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMColor ) ;
}
else
PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMBlackAndWhite ) ;
// PMDuplexMode not yet accessible via API
// PMQualityMode not yet accessible via API
// todo paperSize
}
void wxMacCarbonPrintData::TransferTo( wxPrintData* data )
{
OSStatus err = noErr ;
UInt32 copies ;
err = PMGetCopies( m_macPrintSettings , &copies ) ;
if ( err == noErr )
data->SetNoCopies( copies ) ;
PMOrientation orientation ;
err = PMGetOrientation( m_macPageFormat , &orientation ) ;
if ( err == noErr )
{
if ( orientation == kPMPortrait || orientation == kPMReversePortrait )
data->SetOrientation( wxPORTRAIT );
else
data->SetOrientation( wxLANDSCAPE );
}
// collate cannot be set
#if 0
{
wxMacCFStringHolder name ;
PMPrinter printer ;
PMSessionGetCurrentPrinter( m_macPrintSession ,
&printer ) ;
m_printerName = name.AsString() ;
}
#endif
PMColorMode color ;
err = PMGetColorMode( m_macPrintSettings, &color ) ;
if ( err == noErr )
data->SetColour( !(color == kPMBlackAndWhite) ) ;
// PMDuplexMode not yet accessible via API
// PMQualityMode not yet accessible via API
// todo paperSize
PMRect rPaper;
err = PMGetUnadjustedPaperRect( m_macPageFormat, &rPaper);
if ( err == noErr )
{
data->SetPaperSize( wxSize (
(int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) ,
(int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ) ) );
}
}
void wxMacCarbonPrintData::TransferFrom( wxPageSetupData *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
#if TARGET_CARBON
#else
#endif
}
void wxMacCarbonPrintData::TransferTo( wxPageSetupData* data )
{
PMRect rPaper;
OSStatus err = PMGetUnadjustedPaperRect(m_macPageFormat, &rPaper);
if ( err == noErr )
{
PMRect rPage ;
err = PMGetUnadjustedPageRect(m_macPageFormat , &rPage ) ;
if ( err == noErr )
{
data->SetMinMarginTopLeft( wxPoint (
(int)(((double) rPage.left - rPaper.left ) * pt2mm) ,
(int)(((double) rPage.top - rPaper.top ) * pt2mm) ) ) ;
data->SetMinMarginBottomRight( wxPoint (
((double) rPaper.right - rPage.right ) * pt2mm ,
((double) rPaper.bottom - rPage.bottom ) * pt2mm ) ) ;
}
}
}
void wxMacCarbonPrintData::TransferTo( wxPrintDialogData* data )
{
UInt32 minPage , maxPage ;
PMGetPageRange( m_macPrintSettings , &minPage , &maxPage ) ;
data->SetMinPage( minPage ) ;
data->SetMaxPage( maxPage ) ;
UInt32 copies ;
PMGetCopies( m_macPrintSettings , &copies ) ;
data->SetNoCopies( copies ) ;
UInt32 from , to ;
PMGetFirstPage( m_macPrintSettings , &from ) ;
PMGetLastPage( m_macPrintSettings , &to ) ;
data->SetFromPage( from ) ;
data->SetToPage( to ) ;
}
void wxMacCarbonPrintData::TransferFrom( wxPrintDialogData* data )
{
PMSetPageRange( m_macPrintSettings , data->GetMinPage() , data->GetMaxPage() ) ;
PMSetCopies( m_macPrintSettings , data->GetNoCopies() , false ) ;
PMSetFirstPage( m_macPrintSettings , data->GetFromPage() , false ) ;
PMSetLastPage( m_macPrintSettings , data->GetToPage() , false ) ;
}
void wxMacCarbonPrintData::CopyFrom( wxNativePrintData* d )
{
wxMacCarbonPrintData *data = (wxMacCarbonPrintData*) d ;
if ( data->m_macPrintSession != kPMNoReference )
PMRetain( data->m_macPrintSession ) ;
if ( m_macPrintSession != kPMNoReference )
{
PMRelease( m_macPrintSession ) ;
m_macPrintSession = kPMNoReference ;
}
if ( data->m_macPrintSession != kPMNoReference )
m_macPrintSession = data->m_macPrintSession ;
if ( data->m_macPrintSettings != kPMNoPrintSettings )
PMRetain( data->m_macPrintSettings ) ;
if ( m_macPrintSettings != kPMNoPrintSettings )
{
PMRelease( m_macPrintSettings ) ;
m_macPrintSettings = kPMNoPrintSettings ;
}
if ( data->m_macPrintSettings != kPMNoPrintSettings )
m_macPrintSettings = data->m_macPrintSettings ;
if ( data->m_macPageFormat != kPMNoPageFormat )
PMRetain( data->m_macPageFormat ) ;
if ( m_macPageFormat != kPMNoPageFormat )
{
PMRelease( m_macPageFormat ) ;
m_macPageFormat = kPMNoPageFormat ;
}
if ( data->m_macPageFormat != kPMNoPageFormat )
m_macPageFormat = data->m_macPageFormat ;
}
int wxMacCarbonPrintData::ShowPrintDialog()
{
int result = wxID_CANCEL ;
OSErr err = noErr ;
wxString message ;
Boolean accepted;
{
// Display the Print dialog.
if (err == noErr)
{
err = PMSessionPrintDialog( m_macPrintSession,
m_macPrintSettings,
m_macPageFormat,
&accepted);
if ((err == noErr) && !accepted)
{
err = kPMCancel; // user clicked Cancel button
}
}
if ( err == noErr )
{
result = wxID_OK ;
}
}
if ((err != noErr) && (err != kPMCancel))
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
return result ;
}
int wxMacCarbonPrintData::ShowPageSetupDialog()
{
int result = wxID_CANCEL ;
OSErr err = noErr ;
wxString message ;
Boolean accepted;
{
// Display the Page Setup dialog.
if (err == noErr)
{
err = PMSessionPageSetupDialog( m_macPrintSession,
m_macPageFormat,
&accepted);
if ((err == noErr) && !accepted)
{
err = kPMCancel; // user clicked Cancel button
}
}
// If the user did not cancel, flatten and save the PageFormat object
// with our document.
if (err == noErr) {
result = wxID_OK ;
}
}
if ((err != noErr) && (err != kPMCancel))
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
return result ;
}
#else
wxNativePrintData* wxNativePrintData::Create()
{
return new wxMacClassicPrintData() ;
}
wxMacClassicPrintData::wxMacClassicPrintData()
{
m_macPrintSettings = NULL ;
ValidateOrCreate() ;
}
wxMacClassicPrintData::~wxMacClassicPrintData()
{
wxASSERT( m_macPrintSettings );
DisposeHandle( (Handle) m_macPrintSettings ) ;
}
void wxMacClassicPrintData::ValidateOrCreate()
{
if ( m_macPrintSettings == NULL )
{
m_macPrintSettings = (THPrint) NewHandleClear( sizeof( TPrint ) );
(**m_macPrintSettings).iPrVersion = 0; // something invalid
(**m_macPrintSettings).prInfo.iHRes = 72;
(**m_macPrintSettings).prInfo.iVRes = 72;
Rect r1 = { 0, 0, 8*72 - 2 * 18, 11*72 - 2 * 36 };
(**m_macPrintSettings).prInfo.rPage = r1;// must have its top left & (0,0)
Rect r2 = { -18, -36, 8*72 - 18, 11*72 - 36 };
(**m_macPrintSettings).rPaper = r2;
(**m_macPrintSettings).prStl.iPageV = 11 * 120 ; // 11 inches in 120th of an inch
(**m_macPrintSettings).prStl.iPageH = 8 * 120 ; // 8 inches in 120th of an inch
}
else
{
}
}
void wxMacClassicPrintData::TransferFrom( wxPrintData* data )
{
ValidateOrCreate() ;
(**m_macPrintSettings).prJob.iCopies = data->GetNoCopies() ;
// on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0
// if all printing data is consolidated in on structure we will be able to set additional infos about pages
}
void wxMacClassicPrintData::TransferTo( wxPrintData* data )
{
data->SetNoCopies( (**m_macPrintSettings).prJob.iCopies );
data->SetPaperSize( wxSize(
((double) (**m_macPrintSettings).rPaper.right - (**m_macPrintSettings).rPaper.left ) * pt2mm ,
((double) (**m_macPrintSettings).rPaper.bottom - (**m_macPrintSettings).rPaper.top ) * pt2mm ) ) ;
}
void wxMacClassicPrintData::TransferFrom( wxPageSetupData *data )
{
}
void wxMacClassicPrintData::TransferTo( wxPageSetupData* data )
{
data->SetMinMarginTopLeft( wxPoint(
((double) (**m_macPrintSettings).prInfo.rPage.left -(**m_macPrintSettings).rPaper.left ) * pt2mm ,
((double) (**m_macPrintSettings).prInfo.rPage.top -(**m_macPrintSettings).rPaper.top ) * pt2mm ) ) ;
data->SetMinMarginBottomRight( wxPoint(
((double) (**m_macPrintSettings).rPaper.right - (**m_macPrintSettings).prInfo.rPage.right ) * pt2mm ,
((double)(**m_macPrintSettings).rPaper.bottom - (**m_macPrintSettings).prInfo.rPage.bottom ) * pt2mm ) ) ;
}
void wxMacClassicPrintData::TransferFrom( wxPrintDialogData* data )
{
(**m_macPrintSettings).prJob.iFstPage = data->GetFromPage() ;
(**m_macPrintSettings).prJob.iLstPage = data->GetToPage() ;
}
void wxMacClassicPrintData::TransferTo( wxPrintDialogData* data )
{
data->SetFromPage( (**m_macPrintSettings).prJob.iFstPage ) ;
data->SetToPage( (**m_macPrintSettings).prJob.iLstPage ) ;
}
void wxMacClassicPrintData::CopyFrom( wxNativePrintData* data )
{
DisposeHandle( (Handle) m_macPrintSettings ) ;
m_macPrintSettings = ((wxMacClassicPrintData*)data)->m_macPrintSettings;
HandToHand( (Handle*) &m_macPrintSettings );
}
int wxMacClassicPrintData::ShowPrintDialog()
{
int result = wxID_CANCEL ;
OSErr err = noErr ;
wxString message ;
err = ::UMAPrOpen() ;
if ( err == noErr )
{
if ( ::PrJobDialog( m_macPrintSettings ) )
{
result = wxID_OK ;
}
}
else
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxT(""), wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
::UMAPrClose() ;
return result ;
}
int wxMacClassicPrintData::ShowPageSetupDialog()
{
int result = wxID_CANCEL ;
OSErr err = noErr ;
wxString message ;
err = ::UMAPrOpen() ;
if ( err == noErr )
{
if ( ::PrStlDialog( m_macPrintSettings ) )
{
result = wxID_OK ;
}
}
else
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
::UMAPrClose() ;
return result ;
}
#endif
/*
* Printer
*/
@@ -179,12 +650,12 @@ bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
}
else
{
#if !TARGET_CARBON
// #if !TARGET_CARBON
GrafPtr thePort ;
GetPort( &thePort ) ;
wxSafeYield(win,true);
SetPort( thePort ) ;
#endif
// #endif
dc->StartPage();
keepGoing = printout->OnPrintPage(pn);
dc->EndPage();

View File

@@ -27,229 +27,347 @@
#include "wx/msgdlg.h"
#include <math.h>
#include "wx/mac/uma.h"
#ifndef __DARWIN__
#include "Printing.h"
#endif
#if defined(TARGET_CARBON) && !defined(__DARWIN__)
# if PM_USE_SESSION_APIS
# include <PMCore.h>
# endif
# include <PMApplication.h>
#endif
#include "wx/mac/private/print.h"
#if !USE_SHARED_LIBRARY
IMPLEMENT_CLASS(wxPrinterDC, wxDC)
#endif
GrafPtr macPrintFormerPort = NULL ;
class wxNativePrinterDC
{
public :
wxNativePrinterDC() {}
virtual ~wxNativePrinterDC() {}
virtual bool StartDoc( wxPrinterDC* dc , const wxString& message ) = 0;
virtual void EndDoc( wxPrinterDC* dc ) = 0;
virtual void StartPage( wxPrinterDC* dc ) = 0;
virtual void EndPage( wxPrinterDC* dc ) = 0;
virtual wxCoord GetMaxX() const = 0 ;
virtual wxCoord GetMaxY() const = 0 ;
// returns 0 in case of no Error, otherwise platform specific error codes
virtual wxUint32 GetStatus() const = 0 ;
bool Ok() { return GetStatus() == 0 ; }
static wxNativePrinterDC* Create(wxPrintData* data) ;
} ;
#if TARGET_CARBON
class wxMacCarbonPrinterDC : public wxNativePrinterDC
{
public :
wxMacCarbonPrinterDC( wxPrintData* data ) ;
~wxMacCarbonPrinterDC() ;
virtual bool StartDoc( wxPrinterDC* dc , const wxString& message ) ;
virtual void EndDoc( wxPrinterDC* dc ) ;
virtual void StartPage( wxPrinterDC* dc ) ;
virtual void EndPage( wxPrinterDC* dc ) ;
virtual wxCoord GetMaxX() const { return m_maxX ; }
virtual wxCoord GetMaxY() const { return m_maxY ; }
virtual wxUint32 GetStatus() const { return m_err ; }
private :
GrafPtr m_macPrintFormerPort ;
wxCoord m_maxX ;
wxCoord m_maxY ;
OSStatus m_err ;
} ;
wxMacCarbonPrinterDC::wxMacCarbonPrinterDC( wxPrintData* data )
{
::GetPort( & m_macPrintFormerPort ) ;
m_err = noErr ;
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) data->m_nativePrintData ;
PMRect rPage;
m_err = PMGetAdjustedPageRect(native->m_macPageFormat, &rPage);
if ( m_err != noErr )
return;
m_maxX = wxCoord(rPage.right - rPage.left) ;
m_maxY = wxCoord(rPage.bottom - rPage.top);
}
wxMacCarbonPrinterDC::~wxMacCarbonPrinterDC()
{
// nothing to release from print data, as wxPrinterDC has all data in its wxPrintData member
::SetPort( m_macPrintFormerPort ) ;
}
wxNativePrinterDC* wxNativePrinterDC::Create(wxPrintData* data)
{
return new wxMacCarbonPrinterDC(data) ;
}
bool wxMacCarbonPrinterDC::StartDoc( wxPrinterDC* dc , const wxString& WXUNUSED(message) )
{
if ( m_err )
return false ;
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().m_nativePrintData ;
m_err = PMSessionBeginDocument(native->m_macPrintSession,
native->m_macPrintSettings,
native->m_macPageFormat);
if ( m_err != noErr )
return false;
PMRect rPage;
m_err = PMGetAdjustedPageRect(native->m_macPageFormat, &rPage);
if ( m_err != noErr )
return false;
m_maxX = rPage.right - rPage.left ;
m_maxY = rPage.bottom - rPage.top ;
return true ;
}
void wxMacCarbonPrinterDC::EndDoc( wxPrinterDC* dc )
{
if ( m_err )
return ;
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().m_nativePrintData ;
m_err = PMSessionEndDocument(native->m_macPrintSession);
}
void wxMacCarbonPrinterDC::StartPage( wxPrinterDC* dc )
{
if ( m_err )
return ;
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().m_nativePrintData ;
m_err = PMSessionBeginPage(native->m_macPrintSession,
native->m_macPageFormat,
nil);
if ( m_err == noErr )
{
m_err = PMSessionGetGraphicsContext(native->m_macPrintSession,
nil,
(void**) &dc->m_macPort );
}
if ( m_err != noErr )
{
PMSessionEndPage(native->m_macPrintSession);
PMSessionEndDocument(native->m_macPrintSession);
}
else
{
PMRect rPage;
m_err = PMGetAdjustedPageRect(native->m_macPageFormat, &rPage);
if ( !m_err )
{
dc->m_macLocalOrigin.x = rPage.left ;
dc->m_macLocalOrigin.y = rPage.top ;
}
// since this is a non-critical error, we set the flag back
m_err = noErr ;
}
}
void wxMacCarbonPrinterDC::EndPage( wxPrinterDC* dc )
{
if ( m_err )
return ;
wxMacCarbonPrintData *native = (wxMacCarbonPrintData*) dc->GetPrintData().m_nativePrintData ;
m_err = PMSessionEndPage(native->m_macPrintSession);
if ( m_err != noErr )
{
PMSessionEndDocument(native->m_macPrintSession);
}
}
#else
class wxMacClassicPrinterDC : public wxNativePrinterDC
{
public :
wxMacClassicPrinterDC( wxPrintData* data ) ;
~wxMacClassicPrinterDC() ;
virtual bool StartDoc( wxPrinterDC* dc , const wxString& message ) ;
virtual void EndDoc( wxPrinterDC* dc ) ;
virtual void StartPage( wxPrinterDC* dc ) ;
virtual void EndPage( wxPrinterDC* dc ) ;
virtual wxCoord GetMaxX() const { return m_maxX ; }
virtual wxCoord GetMaxY() const { return m_maxY ; }
virtual wxUint32 GetStatus() const { return m_err ; }
private :
GrafPtr m_macPrintFormerPort ;
TPPrPort m_macPrintingPort ;
OSErr m_err ;
long m_maxX ;
long m_maxY ;
} ;
wxNativePrinterDC* wxNativePrinterDC::Create(wxPrintData* data)
{
return new wxMacClassicPrinterDC(data) ;
}
wxMacClassicPrinterDC::wxMacClassicPrinterDC(wxPrintData* data)
{
::GetPort( &m_macPrintFormerPort ) ;
m_err = noErr ;
::UMAPrOpen() ;
m_err = PrError() ;
if ( m_err != noErr )
return;
wxMacClassicPrintData *native = (wxMacClassicPrintData*) data->m_nativePrintData ;
if ( ::PrValidate( native->m_macPrintSettings ) )
{
// the driver has changed in the mean time, should we pop up a page setup dialog ?
if ( !::PrStlDialog( native->m_macPrintSettings ) )
{
m_err = -1 ;
return;
}
}
m_err = PrError() ;
if ( m_err == noErr )
{
m_maxX = (**native->m_macPrintSettings).prInfo.rPage.right - (**native->m_macPrintSettings).prInfo.rPage.left ;
m_maxY = (**native->m_macPrintSettings).prInfo.rPage.bottom - (**native->m_macPrintSettings).prInfo.rPage.top ;
}
}
wxMacClassicPrinterDC::~wxMacClassicPrinterDC()
{
::UMAPrClose() ;
::SetPort( LMGetWMgrPort() ) ;
}
bool wxMacClassicPrinterDC::StartDoc( wxPrinterDC* dc , const wxString& WXUNUSED(message) )
{
if ( m_err )
return false ;
wxMacClassicPrintData *native = (wxMacClassicPrintData*) dc->GetPrintData().m_nativePrintData ;
m_macPrintingPort = ::PrOpenDoc( native->m_macPrintSettings , NULL , NULL ) ;
m_err = PrError() ;
if ( m_err )
return false ;
// sets current port
dc->m_macPort = (GrafPtr ) m_macPrintingPort ;
m_maxX = (**native->m_macPrintSettings).prInfo.rPage.right - (**native->m_macPrintSettings).prInfo.rPage.left ;
m_maxY = (**native->m_macPrintSettings).prInfo.rPage.bottom - (**native->m_macPrintSettings).prInfo.rPage.top ;
return true ;
}
void wxMacClassicPrinterDC::EndDoc( wxPrinterDC* dc )
{
if ( m_err )
return ;
PrCloseDoc( m_macPrintingPort ) ;
m_err = PrError() ;
}
void wxMacClassicPrinterDC::StartPage( wxPrinterDC* dc )
{
if ( m_err )
return ;
wxMacClassicPrintData *native = (wxMacClassicPrintData*) dc->GetPrintData().m_nativePrintData ;
PrOpenPage( m_macPrintingPort , NULL ) ;
dc->m_macLocalOrigin.x = (**native->m_macPrintSettings).rPaper.left ;
dc->m_macLocalOrigin.y = (**native->m_macPrintSettings).rPaper.top ;
// m_macPrintingPort is now the current port
Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
::ClipRect( &clip ) ;
m_err = PrError() ;
if ( m_err != noErr )
::PrCloseDoc( m_macPrintingPort ) ;
}
void wxMacClassicPrinterDC::EndPage( wxPrinterDC* dc )
{
if ( m_err )
return ;
PrClosePage( m_macPrintingPort ) ;
m_err = PrError() ;
if ( m_err != noErr )
::PrCloseDoc( m_macPrintingPort ) ;
}
#endif
wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
{
OSStatus err = noErr ;
wxString message ;
m_ok = FALSE ;
m_printData = printdata ;
m_printData.ConvertToNative() ;
#if TARGET_CARBON && PM_USE_SESSION_APIS
m_macPrintSessionPort = printdata.m_macPrintSession ;
PMRetain( m_macPrintSessionPort ) ;
if ( err != noErr || m_macPrintSessionPort == kPMNoData )
#else
err = UMAPrOpen(NULL) ;
if ( err != noErr )
#endif
m_nativePrinterDC = wxNativePrinterDC::Create( &m_printData ) ;
if ( m_nativePrinterDC )
{
message.Printf( wxT("Print Error %ld"), err ) ;
m_ok = m_nativePrinterDC->Ok() ;
if ( !m_ok )
{
wxString message ;
message.Printf( wxT("Print Error %ld"), m_nativePrinterDC->GetStatus() ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
#if TARGET_CARBON && PM_USE_SESSION_APIS
PMRelease( m_macPrintSessionPort ) ;
#else
UMAPrClose(NULL) ;
#endif
m_ok = FALSE;
return;
}
#if !TARGET_CARBON
if ( ::PrValidate( (THPrint) m_printData.m_macPrintSettings ) )
{
// the driver has changed in the mean time, should we pop up a page setup dialog ?
if ( !::PrStlDialog( (THPrint) m_printData.m_macPrintSettings ) )
{
UMAPrClose(NULL) ;
m_ok = FALSE;
return;
}
}
err = PrError() ;
if ( err != noErr )
{
message.Printf( wxT("Print Error %ld"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
dialog.ShowModal();
UMAPrClose(NULL) ;
m_ok = FALSE;
return;
}
::GetPort( &macPrintFormerPort ) ;
#endif
m_ok = TRUE ;
m_minY = m_minX = 0 ;
#if TARGET_CARBON
PMRect rPage;
err = PMGetAdjustedPageRect((PMPageFormat)m_printData.m_macPageFormat, &rPage);
if ( err != noErr )
{
message.Printf( wxT("Print Error %ld"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
#if TARGET_CARBON && PM_USE_SESSION_APIS
PMRelease(&m_macPrintSessionPort) ;
#else
UMAPrClose(NULL) ;
#endif
m_ok = FALSE;
return;
}
m_maxX = wxCoord(rPage.right - rPage.left) ;
m_maxY = wxCoord(rPage.bottom - rPage.top);
#else
m_maxX = (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.right - (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.left ;
m_maxY = (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.bottom - (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.top ;
#endif
}
wxPrinterDC::~wxPrinterDC(void)
{
OSStatus err ;
wxString message ;
#if !TARGET_CARBON
if ( m_ok )
{
::UMAPrClose(NULL) ;
::SetPort( LMGetWMgrPort() ) ;
}
#else
if ( m_ok )
{
#if TARGET_CARBON && PM_USE_SESSION_APIS
PMRelease(&m_macPrintSessionPort) ;
#else
UMAPrClose(NULL) ;
#endif
}
#endif
delete m_nativePrinterDC ;
}
bool wxPrinterDC::StartDoc( const wxString& WXUNUSED(message) )
bool wxPrinterDC::StartDoc( const wxString& message )
{
OSStatus err = noErr ;
wxString message ;
wxASSERT_MSG( Ok() , wxT("Called wxPrinterDC::StartDoc from an invalid object") ) ;
#if !TARGET_CARBON
m_macPrintSessionPort = ::PrOpenDoc( (THPrint) m_printData.m_macPrintSettings , NULL , NULL ) ;
err = PrError() ;
if ( err )
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
UMAPrClose(NULL) ;
m_ok = FALSE;
if ( !m_ok )
return false ;
}
// sets current port
m_macPort = (GrafPtr ) m_macPrintSessionPort ;
#else
#if PM_USE_SESSION_APIS
err = PMSessionBeginDocument((PMPrintSession)m_macPrintSessionPort,
(PMPrintSettings)m_printData.m_macPrintSettings,
(PMPageFormat)m_printData.m_macPageFormat);
if ( err != noErr )
#else
m_macPrintSessionPort = kPMNoReference ;
err = PMBeginDocument(
m_printData.m_macPrintSettings,
m_printData.m_macPageFormat,
&m_macPrintSessionPort);
if ( err != noErr || m_macPrintSessionPort == kPMNoReference )
#endif
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
#if TARGET_CARBON && PM_USE_SESSION_APIS
PMRelease(&m_macPrintSessionPort) ;
#else
UMAPrClose(NULL) ;
#endif
m_ok = FALSE;
return m_ok;
}
// sets current port
::GetPort( (GrafPtr *)&m_macPort ) ;
#endif
m_ok = TRUE ;
m_minY = m_minX = 0 ;
#if TARGET_CARBON
PMRect rPage;
err = PMGetAdjustedPageRect((PMPageFormat)m_printData.m_macPageFormat, &rPage);
if ( err != noErr )
if ( m_nativePrinterDC->StartDoc(this, message ) )
{
message.Printf( wxT("Print Error %d"), err ) ;
// in case we have to do additional things when successful
}
m_ok = m_nativePrinterDC->Ok() ;
if ( !m_ok )
{
wxString message ;
message.Printf( wxT("Print Error %ld"), m_nativePrinterDC->GetStatus() ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
#if TARGET_CARBON && PM_USE_SESSION_APIS
PMRelease(&m_macPrintSessionPort) ;
#else
UMAPrClose(NULL) ;
#endif
m_ok = FALSE;
return m_ok;
}
m_maxX = rPage.right - rPage.left ;
m_maxY = rPage.bottom - rPage.top ;
#else
m_maxX = (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.right - (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.left ;
m_maxY = (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.bottom - (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.top ;
#endif
return m_ok ;
}
void wxPrinterDC::EndDoc(void)
{
OSStatus err ;
if ( !m_ok )
return ;
m_nativePrinterDC->EndDoc( this ) ;
m_ok = m_nativePrinterDC->Ok() ;
if ( !m_ok )
{
wxString message ;
#if !TARGET_CARBON
if ( m_ok )
{
::UMAPrClose(NULL) ;
// ::SetPort( macPrintFormerPort ) ;
::SetPort( LMGetWMgrPort() ) ;
}
#else
if ( m_ok )
{
#if PM_USE_SESSION_APIS
err = PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort);
#else
err = PMEndDocument(m_macPrintSessionPort);
#endif
if ( err != noErr )
{
message.Printf( wxT("Print Error %d"), err ) ;
message.Printf( wxT("Print Error %ld"), m_nativePrinterDC->GetStatus() ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
}
#endif
}
void wxPrinterDC::StartPage(void)
{
@@ -271,63 +389,9 @@ void wxPrinterDC::StartPage(void)
m_macBrushInstalled = false ;
m_macPenInstalled = false ;
m_nativePrinterDC->StartPage(this) ;
m_ok = m_nativePrinterDC->Ok() ;
OSStatus err ;
wxString message ;
#if !TARGET_CARBON
PrOpenPage( (TPPrPort) m_macPrintSessionPort , NULL ) ;
m_macLocalOrigin.x = (**(THPrint)m_printData.m_macPrintSettings).rPaper.left ;
m_macLocalOrigin.y = (**(THPrint)m_printData.m_macPrintSettings).rPaper.top ;
Rect clip = { -32000 , -32000 , 32000 , 32000 } ;
::ClipRect( &clip ) ;
err = PrError() ;
if ( err != noErr )
{
message.Printf( wxT("Print Error %ld"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
dialog.ShowModal();
::PrClosePage( (TPPrPort) m_macPrintSessionPort ) ;
::PrCloseDoc( (TPPrPort) m_macPrintSessionPort ) ;
::UMAPrClose(NULL) ;
::SetPort( macPrintFormerPort ) ;
m_ok = FALSE ;
}
#else
#if PM_USE_SESSION_APIS
err = PMSessionBeginPage((PMPrintSession)m_macPrintSessionPort,
(PMPageFormat)m_printData.m_macPageFormat,
nil);
#else
err = PMBeginPage(m_macPrintSessionPort, nil);
#endif
if ( err != noErr )
{
message.Printf( wxT("Print Error %ld"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
#if PM_USE_SESSION_APIS
PMSessionEndPage((PMPrintSession)m_macPrintSessionPort);
PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort);
UMAPrClose(&m_macPrintSessionPort) ;
#else
PMEndPage(m_macPrintSessionPort);
PMEndDocument(m_macPrintSessionPort);
UMAPrClose(NULL) ;
#endif
::SetPort( macPrintFormerPort ) ;
m_ok = FALSE ;
}
PMRect rPage;
err = PMGetAdjustedPageRect((PMPageFormat)m_printData.m_macPageFormat, &rPage);
if ( !err )
{
m_macLocalOrigin.x = rPage.left ;
m_macLocalOrigin.y = rPage.top ;
}
#endif
}
void wxPrinterDC::EndPage(void)
@@ -335,43 +399,18 @@ void wxPrinterDC::EndPage(void)
if ( !m_ok )
return ;
OSStatus err ;
wxString message ;
m_nativePrinterDC->EndPage(this) ;
m_ok = m_nativePrinterDC->Ok() ;
}
#if !TARGET_CARBON
PrClosePage( (TPPrPort) m_macPort ) ;
err = PrError() ;
if ( err != noErr )
void wxPrinterDC::DoGetSize(int *width, int *height) const
{
message.Printf( wxT("Print Error %ld") , err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
::PrCloseDoc( (TPPrPort) m_macPrintSessionPort ) ;
::UMAPrClose(NULL) ;
::SetPort( macPrintFormerPort ) ;
m_ok = FALSE ;
}
#else
#if PM_USE_SESSION_APIS
err = PMSessionEndPage((PMPrintSession)m_macPrintSessionPort);
#else
err = PMEndPage(m_macPrintSessionPort);
#endif
if ( err != noErr )
{
message.Printf( wxT("Print Error %ld"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
#if PM_USE_SESSION_APIS
PMSessionEndDocument((PMPrintSession)m_macPrintSessionPort);
UMAPrClose(&m_macPrintSessionPort) ;
#else
PMEndDocument(m_macPrintSessionPort);
UMAPrClose(NULL) ;
#endif
::SetPort( macPrintFormerPort ) ;
m_ok = FALSE ;
}
#endif
wxCHECK_RET( m_ok , _T("GetSize() doesn't work without a valid wxPrinterDC") );
if ( width )
* width = m_nativePrinterDC->GetMaxX() ;
if ( height )
* height = m_nativePrinterDC->GetMaxY() ;
}

View File

@@ -17,17 +17,7 @@
#include "wx/printdlg.h"
#include "wx/dcprint.h"
#include "wx/msgdlg.h"
#include "wx/mac/uma.h"
#ifndef __DARWIN__
#include "Printing.h"
#endif
#if defined(TARGET_CARBON) && !defined(__DARWIN__)
# if PM_USE_SESSION_APIS
# include <PMCore.h>
# endif
# include <PMApplication.h>
#endif
#include "wx/mac/private/print.h"
// Use generic page setup dialog: use your own native one if one exists.
@@ -78,64 +68,12 @@ wxPrintDialog::~wxPrintDialog()
}
int wxPrintDialog::ShowModal()
{
int result = wxID_CANCEL ;
OSErr err = noErr ;
wxString message ;
#if !TARGET_CARBON
err = ::UMAPrOpen(NULL) ;
if ( err == noErr )
{
m_printDialogData.ConvertToNative() ;
if ( ::PrJobDialog( (THPrint) m_printDialogData.GetPrintData().m_macPrintSettings ) )
{
int result = m_printDialogData.GetPrintData().m_nativePrintData->ShowPrintDialog() ;
if ( result == wxID_OK )
m_printDialogData.ConvertFromNative() ;
result = wxID_OK ;
}
}
else
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxT(""), wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
::UMAPrClose(NULL) ;
#else
#if PM_USE_SESSION_APIS
Boolean accepted;
{
m_printDialogData.ConvertToNative() ;
// Display the Print dialog.
if (err == noErr)
{
err = PMSessionPrintDialog((PMPrintSession)m_printDialogData.GetPrintData().m_macPrintSession,
(PMPrintSettings)m_printDialogData.GetPrintData().m_macPrintSettings,
(PMPageFormat)m_printDialogData.GetPrintData().m_macPageFormat,
&accepted);
if ((err == noErr) && !accepted)
{
err = kPMCancel; // user clicked Cancel button
}
}
if ( err == noErr )
{
m_printDialogData.ConvertFromNative() ;
result = wxID_OK ;
}
}
if ((err != noErr) && (err != kPMCancel))
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
#else
#pragma warning "TODO: Printing for carbon without session apis"
#endif
#endif
return result ;
}
@@ -175,66 +113,12 @@ wxPageSetupDialog::~wxPageSetupDialog()
}
int wxPageSetupDialog::ShowModal()
{
int result = wxID_CANCEL ;
OSErr err = noErr ;
wxString message ;
#if !TARGET_CARBON
err = ::UMAPrOpen(NULL) ;
if ( err == noErr )
{
m_pageSetupData.ConvertToNative() ;
if ( ::PrStlDialog( (THPrint) m_pageSetupData.GetPrintData().m_macPrintSettings ) )
{
int result = m_pageSetupData.GetPrintData().m_nativePrintData->ShowPageSetupDialog() ;
if (result == wxID_OK )
m_pageSetupData.ConvertFromNative() ;
result = wxID_OK ;
}
}
else
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
::UMAPrClose(NULL) ;
#else
#if PM_USE_SESSION_APIS
Boolean accepted;
{
m_pageSetupData.ConvertToNative() ;
// Display the Page Setup dialog.
if (err == noErr)
{
err = PMSessionPageSetupDialog((PMPrintSession)m_pageSetupData.GetPrintData().m_macPrintSession,
(PMPageFormat)m_pageSetupData.GetPrintData().m_macPageFormat,
&accepted);
if ((err == noErr) && !accepted)
{
err = kPMCancel; // user clicked Cancel button
}
}
// If the user did not cancel, flatten and save the PageFormat object
// with our document.
if (err == noErr) {
// err = FlattenAndSavePageFormat(m_pageSetupData.GetPrintData().m_macPageFormat);
m_pageSetupData.ConvertFromNative() ;
result = wxID_OK ;
}
}
if ((err != noErr) && (err != kPMCancel))
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
#else
#pragma warning "TODO: Printing for carbon without session apis"
#endif
#endif
return result ;
}

View File

@@ -29,9 +29,14 @@
#include "wx/msgdlg.h"
#endif
#include "wx/mac/private.h"
#include "wx/mac/uma.h"
#include "wx/mac/printmac.h"
#include "wx/mac/private/print.h"
#define mm2pt 2.83464566929
#define pt2mm 0.352777777778
#include "wx/dcprint.h"
#include "wx/printdlg.h"
@@ -42,6 +47,472 @@ IMPLEMENT_DYNAMIC_CLASS(wxMacPrinter, wxPrinterBase)
IMPLEMENT_CLASS(wxMacPrintPreview, wxPrintPreviewBase)
#endif
#if TARGET_CARBON
wxNativePrintData* wxNativePrintData::Create()
{
return new wxMacCarbonPrintData() ;
}
wxMacCarbonPrintData::wxMacCarbonPrintData()
{
m_macPageFormat = kPMNoPageFormat;
m_macPrintSettings = kPMNoPrintSettings;
m_macPrintSession = kPMNoReference ;
ValidateOrCreate() ;
}
wxMacCarbonPrintData::~wxMacCarbonPrintData()
{
if (m_macPageFormat != kPMNoPageFormat)
{
(void)PMRelease(m_macPageFormat);
m_macPageFormat = kPMNoPageFormat;
}
if (m_macPrintSettings != kPMNoPrintSettings)
{
(void)PMRelease(m_macPrintSettings);
m_macPrintSettings = kPMNoPrintSettings;
}
if ( m_macPrintSession != kPMNoReference )
{
(void)PMRelease(m_macPrintSession);
m_macPrintSession = kPMNoReference;
}
}
void wxMacCarbonPrintData::ValidateOrCreate()
{
OSStatus err = noErr ;
if ( m_macPrintSession == kPMNoReference )
{
err = PMCreateSession( (PMPrintSession *) &m_macPrintSession ) ;
}
// Set up a valid PageFormat object.
if ( m_macPageFormat == kPMNoPageFormat)
{
err = PMCreatePageFormat((PMPageFormat *) &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((PMPrintSession) m_macPrintSession,
(PMPageFormat) m_macPageFormat);
}
}
else
{
err = PMSessionValidatePageFormat((PMPrintSession) m_macPrintSession,
(PMPageFormat) m_macPageFormat,
kPMDontWantBoolean);
}
// Set up a valid PrintSettings object.
if ( m_macPrintSettings == kPMNoPrintSettings)
{
err = PMCreatePrintSettings((PMPrintSettings *) &m_macPrintSettings);
// Note that PMPrintSettings is not session-specific, but calling
// PMSessionDefaultPrintSettings assigns values specific to the printer
// associated with the current printing session.
if ((err == noErr) &&
( m_macPrintSettings != kPMNoPrintSettings))
{
err = PMSessionDefaultPrintSettings((PMPrintSession) m_macPrintSession,
(PMPrintSettings) m_macPrintSettings);
}
}
else
{
err = PMSessionValidatePrintSettings((PMPrintSession) m_macPrintSession,
(PMPrintSettings) m_macPrintSettings,
kPMDontWantBoolean);
}
}
void wxMacCarbonPrintData::TransferFrom( wxPrintData* data )
{
ValidateOrCreate() ;
PMSetCopies( (PMPrintSettings) m_macPrintSettings , data->GetNoCopies() , false ) ;
PMSetOrientation( (PMPageFormat) m_macPageFormat , ( data->GetOrientation() == wxLANDSCAPE ) ?
kPMLandscape : kPMPortrait , false ) ;
// collate cannot be set
#if 0 // not yet tested
if ( m_printerName.Length() > 0 )
PMSessionSetCurrentPrinter( (PMPrintSession) m_macPrintSession , wxMacCFStringHolder( m_printerName ) ) ;
#endif
PMColorMode color ;
PMGetColorMode( (PMPrintSettings) m_macPrintSettings, &color ) ;
if ( data->GetColour() )
{
if ( color == kPMBlackAndWhite )
PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMColor ) ;
}
else
PMSetColorMode( (PMPrintSettings) m_macPrintSettings, kPMBlackAndWhite ) ;
// PMDuplexMode not yet accessible via API
// PMQualityMode not yet accessible via API
// todo paperSize
}
void wxMacCarbonPrintData::TransferTo( wxPrintData* data )
{
OSStatus err = noErr ;
UInt32 copies ;
err = PMGetCopies( m_macPrintSettings , &copies ) ;
if ( err == noErr )
data->SetNoCopies( copies ) ;
PMOrientation orientation ;
err = PMGetOrientation( m_macPageFormat , &orientation ) ;
if ( err == noErr )
{
if ( orientation == kPMPortrait || orientation == kPMReversePortrait )
data->SetOrientation( wxPORTRAIT );
else
data->SetOrientation( wxLANDSCAPE );
}
// collate cannot be set
#if 0
{
wxMacCFStringHolder name ;
PMPrinter printer ;
PMSessionGetCurrentPrinter( m_macPrintSession ,
&printer ) ;
m_printerName = name.AsString() ;
}
#endif
PMColorMode color ;
err = PMGetColorMode( m_macPrintSettings, &color ) ;
if ( err == noErr )
data->SetColour( !(color == kPMBlackAndWhite) ) ;
// PMDuplexMode not yet accessible via API
// PMQualityMode not yet accessible via API
// todo paperSize
PMRect rPaper;
err = PMGetUnadjustedPaperRect( m_macPageFormat, &rPaper);
if ( err == noErr )
{
data->SetPaperSize( wxSize (
(int)(( rPaper.right - rPaper.left ) * pt2mm + 0.5 ) ,
(int)(( rPaper.bottom - rPaper.top ) * pt2mm + 0.5 ) ) );
}
}
void wxMacCarbonPrintData::TransferFrom( wxPageSetupData *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
#if TARGET_CARBON
#else
#endif
}
void wxMacCarbonPrintData::TransferTo( wxPageSetupData* data )
{
PMRect rPaper;
OSStatus err = PMGetUnadjustedPaperRect(m_macPageFormat, &rPaper);
if ( err == noErr )
{
PMRect rPage ;
err = PMGetUnadjustedPageRect(m_macPageFormat , &rPage ) ;
if ( err == noErr )
{
data->SetMinMarginTopLeft( wxPoint (
(int)(((double) rPage.left - rPaper.left ) * pt2mm) ,
(int)(((double) rPage.top - rPaper.top ) * pt2mm) ) ) ;
data->SetMinMarginBottomRight( wxPoint (
((double) rPaper.right - rPage.right ) * pt2mm ,
((double) rPaper.bottom - rPage.bottom ) * pt2mm ) ) ;
}
}
}
void wxMacCarbonPrintData::TransferTo( wxPrintDialogData* data )
{
UInt32 minPage , maxPage ;
PMGetPageRange( m_macPrintSettings , &minPage , &maxPage ) ;
data->SetMinPage( minPage ) ;
data->SetMaxPage( maxPage ) ;
UInt32 copies ;
PMGetCopies( m_macPrintSettings , &copies ) ;
data->SetNoCopies( copies ) ;
UInt32 from , to ;
PMGetFirstPage( m_macPrintSettings , &from ) ;
PMGetLastPage( m_macPrintSettings , &to ) ;
data->SetFromPage( from ) ;
data->SetToPage( to ) ;
}
void wxMacCarbonPrintData::TransferFrom( wxPrintDialogData* data )
{
PMSetPageRange( m_macPrintSettings , data->GetMinPage() , data->GetMaxPage() ) ;
PMSetCopies( m_macPrintSettings , data->GetNoCopies() , false ) ;
PMSetFirstPage( m_macPrintSettings , data->GetFromPage() , false ) ;
PMSetLastPage( m_macPrintSettings , data->GetToPage() , false ) ;
}
void wxMacCarbonPrintData::CopyFrom( wxNativePrintData* d )
{
wxMacCarbonPrintData *data = (wxMacCarbonPrintData*) d ;
if ( data->m_macPrintSession != kPMNoReference )
PMRetain( data->m_macPrintSession ) ;
if ( m_macPrintSession != kPMNoReference )
{
PMRelease( m_macPrintSession ) ;
m_macPrintSession = kPMNoReference ;
}
if ( data->m_macPrintSession != kPMNoReference )
m_macPrintSession = data->m_macPrintSession ;
if ( data->m_macPrintSettings != kPMNoPrintSettings )
PMRetain( data->m_macPrintSettings ) ;
if ( m_macPrintSettings != kPMNoPrintSettings )
{
PMRelease( m_macPrintSettings ) ;
m_macPrintSettings = kPMNoPrintSettings ;
}
if ( data->m_macPrintSettings != kPMNoPrintSettings )
m_macPrintSettings = data->m_macPrintSettings ;
if ( data->m_macPageFormat != kPMNoPageFormat )
PMRetain( data->m_macPageFormat ) ;
if ( m_macPageFormat != kPMNoPageFormat )
{
PMRelease( m_macPageFormat ) ;
m_macPageFormat = kPMNoPageFormat ;
}
if ( data->m_macPageFormat != kPMNoPageFormat )
m_macPageFormat = data->m_macPageFormat ;
}
int wxMacCarbonPrintData::ShowPrintDialog()
{
int result = wxID_CANCEL ;
OSErr err = noErr ;
wxString message ;
Boolean accepted;
{
// Display the Print dialog.
if (err == noErr)
{
err = PMSessionPrintDialog( m_macPrintSession,
m_macPrintSettings,
m_macPageFormat,
&accepted);
if ((err == noErr) && !accepted)
{
err = kPMCancel; // user clicked Cancel button
}
}
if ( err == noErr )
{
result = wxID_OK ;
}
}
if ((err != noErr) && (err != kPMCancel))
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
return result ;
}
int wxMacCarbonPrintData::ShowPageSetupDialog()
{
int result = wxID_CANCEL ;
OSErr err = noErr ;
wxString message ;
Boolean accepted;
{
// Display the Page Setup dialog.
if (err == noErr)
{
err = PMSessionPageSetupDialog( m_macPrintSession,
m_macPageFormat,
&accepted);
if ((err == noErr) && !accepted)
{
err = kPMCancel; // user clicked Cancel button
}
}
// If the user did not cancel, flatten and save the PageFormat object
// with our document.
if (err == noErr) {
result = wxID_OK ;
}
}
if ((err != noErr) && (err != kPMCancel))
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString, wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
return result ;
}
#else
wxNativePrintData* wxNativePrintData::Create()
{
return new wxMacClassicPrintData() ;
}
wxMacClassicPrintData::wxMacClassicPrintData()
{
m_macPrintSettings = NULL ;
ValidateOrCreate() ;
}
wxMacClassicPrintData::~wxMacClassicPrintData()
{
wxASSERT( m_macPrintSettings );
DisposeHandle( (Handle) m_macPrintSettings ) ;
}
void wxMacClassicPrintData::ValidateOrCreate()
{
if ( m_macPrintSettings == NULL )
{
m_macPrintSettings = (THPrint) NewHandleClear( sizeof( TPrint ) );
(**m_macPrintSettings).iPrVersion = 0; // something invalid
(**m_macPrintSettings).prInfo.iHRes = 72;
(**m_macPrintSettings).prInfo.iVRes = 72;
Rect r1 = { 0, 0, 8*72 - 2 * 18, 11*72 - 2 * 36 };
(**m_macPrintSettings).prInfo.rPage = r1;// must have its top left & (0,0)
Rect r2 = { -18, -36, 8*72 - 18, 11*72 - 36 };
(**m_macPrintSettings).rPaper = r2;
(**m_macPrintSettings).prStl.iPageV = 11 * 120 ; // 11 inches in 120th of an inch
(**m_macPrintSettings).prStl.iPageH = 8 * 120 ; // 8 inches in 120th of an inch
}
else
{
}
}
void wxMacClassicPrintData::TransferFrom( wxPrintData* data )
{
ValidateOrCreate() ;
(**m_macPrintSettings).prJob.iCopies = data->GetNoCopies() ;
// on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0
// if all printing data is consolidated in on structure we will be able to set additional infos about pages
}
void wxMacClassicPrintData::TransferTo( wxPrintData* data )
{
data->SetNoCopies( (**m_macPrintSettings).prJob.iCopies );
data->SetPaperSize( wxSize(
((double) (**m_macPrintSettings).rPaper.right - (**m_macPrintSettings).rPaper.left ) * pt2mm ,
((double) (**m_macPrintSettings).rPaper.bottom - (**m_macPrintSettings).rPaper.top ) * pt2mm ) ) ;
}
void wxMacClassicPrintData::TransferFrom( wxPageSetupData *data )
{
}
void wxMacClassicPrintData::TransferTo( wxPageSetupData* data )
{
data->SetMinMarginTopLeft( wxPoint(
((double) (**m_macPrintSettings).prInfo.rPage.left -(**m_macPrintSettings).rPaper.left ) * pt2mm ,
((double) (**m_macPrintSettings).prInfo.rPage.top -(**m_macPrintSettings).rPaper.top ) * pt2mm ) ) ;
data->SetMinMarginBottomRight( wxPoint(
((double) (**m_macPrintSettings).rPaper.right - (**m_macPrintSettings).prInfo.rPage.right ) * pt2mm ,
((double)(**m_macPrintSettings).rPaper.bottom - (**m_macPrintSettings).prInfo.rPage.bottom ) * pt2mm ) ) ;
}
void wxMacClassicPrintData::TransferFrom( wxPrintDialogData* data )
{
(**m_macPrintSettings).prJob.iFstPage = data->GetFromPage() ;
(**m_macPrintSettings).prJob.iLstPage = data->GetToPage() ;
}
void wxMacClassicPrintData::TransferTo( wxPrintDialogData* data )
{
data->SetFromPage( (**m_macPrintSettings).prJob.iFstPage ) ;
data->SetToPage( (**m_macPrintSettings).prJob.iLstPage ) ;
}
void wxMacClassicPrintData::CopyFrom( wxNativePrintData* data )
{
DisposeHandle( (Handle) m_macPrintSettings ) ;
m_macPrintSettings = ((wxMacClassicPrintData*)data)->m_macPrintSettings;
HandToHand( (Handle*) &m_macPrintSettings );
}
int wxMacClassicPrintData::ShowPrintDialog()
{
int result = wxID_CANCEL ;
OSErr err = noErr ;
wxString message ;
err = ::UMAPrOpen() ;
if ( err == noErr )
{
if ( ::PrJobDialog( m_macPrintSettings ) )
{
result = wxID_OK ;
}
}
else
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxT(""), wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
::UMAPrClose() ;
return result ;
}
int wxMacClassicPrintData::ShowPageSetupDialog()
{
int result = wxID_CANCEL ;
OSErr err = noErr ;
wxString message ;
err = ::UMAPrOpen() ;
if ( err == noErr )
{
if ( ::PrStlDialog( m_macPrintSettings ) )
{
result = wxID_OK ;
}
}
else
{
message.Printf( wxT("Print Error %d"), err ) ;
wxMessageDialog dialog( NULL , message , wxEmptyString , wxICON_HAND | wxOK) ;
dialog.ShowModal();
}
::UMAPrClose() ;
return result ;
}
#endif
/*
* Printer
*/
@@ -179,12 +650,12 @@ bool wxMacPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt)
}
else
{
#if !TARGET_CARBON
// #if !TARGET_CARBON
GrafPtr thePort ;
GetPort( &thePort ) ;
wxSafeYield(win,true);
SetPort( thePort ) ;
#endif
// #endif
dc->StartPage();
keepGoing = printout->OnPrintPage(pn);
dc->EndPage();