X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/161f4f7380e945b0769ad5f7122df55b8777396a..70914290a18a1c95c16ff5148d53f3dea52d2940:/src/common/cmndata.cpp diff --git a/src/common/cmndata.cpp b/src/common/cmndata.cpp index b039641a07..2fe0f2ff51 100644 --- a/src/common/cmndata.cpp +++ b/src/common/cmndata.cpp @@ -40,7 +40,7 @@ #include "wx/log.h" // For compatibility -#if (defined(__WXMOTIF__) || defined(__WXGTK__) || defined(__WXPM__) || defined(__WXMAC__)) && wxUSE_POSTSCRIPT +#if (defined(__WXMOTIF__) || defined(__WXGTK__) || defined(__WXX11__)|| defined(__WXPM__) || defined(__WXMAC__)) && wxUSE_POSTSCRIPT #define wxCOMPATIBILITY_WITH_PRINTSETUPDATA 1 #endif @@ -82,6 +82,18 @@ IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject) #ifdef __WXMAC__ + #include "wx/mac/uma.h" + +#if defined(TARGET_CARBON) && !defined(__DARWIN__) +# if PM_USE_SESSION_APIS +# include +# endif +# include +#endif + +#ifndef __DARWIN__ + #include "Printing.h" +#endif #define mm2pt 2.83464566929 #define pt2mm 0.352777777778 #endif // Mac @@ -117,7 +129,7 @@ wxColourData::~wxColourData() { } -void wxColourData::SetCustomColour(int i, wxColour& colour) +void wxColourData::SetCustomColour(int i, const wxColour& colour) { if (i > 15 || i < 0) return; @@ -179,19 +191,51 @@ wxPrintData::wxPrintData() #if TARGET_CARBON m_macPageFormat = kPMNoPageFormat; m_macPrintSettings = kPMNoPrintSettings; + + #if PM_USE_SESSION_APIS + PMPrintSession macPrintSession = kPMNoReference; + OSStatus err; + + err = ::UMAPrOpen(&macPrintSession) ; + if ( err == noErr ) + { + 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)macPrintSession, + (PMPageFormat)m_macPageFormat); + } + + 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)macPrintSession, + (PMPrintSettings)m_macPrintSettings); + } + } + ::UMAPrClose(&macPrintSession) ; + #endif #else - m_macPrintInfo = (THPrint) NewHandleClear( sizeof( TPrint ) ); - (**m_macPrintInfo).iPrVersion = 0; // something invalid + m_macPrintSettings = (THPrint) NewHandleClear( sizeof( TPrint ) ); + (**(THPrint)m_macPrintSettings).iPrVersion = 0; // something invalid - (**m_macPrintInfo).prInfo.iHRes = 72; - (**m_macPrintInfo).prInfo.iVRes = 72; + (**(THPrint)m_macPrintSettings).prInfo.iHRes = 72; + (**(THPrint)m_macPrintSettings).prInfo.iVRes = 72; Rect r1 = { 0, 0, 8*72 - 2 * 18, 11*72 - 2 * 36 }; - (**m_macPrintInfo).prInfo.rPage = r1;// must have its top left & (0,0) + (**(THPrint)m_macPrintSettings).prInfo.rPage = r1;// must have its top left & (0,0) Rect r2 = { -18, -36, 8*72 - 18, 11*72 - 36 }; - (**m_macPrintInfo).rPaper = r2; - (**m_macPrintInfo).prStl.iPageV = 11 * 120 ; // 11 inches in 120th of an inch - (**m_macPrintInfo).prStl.iPageH = 8 * 120 ; // 8 inches in 120th of an inch + (**(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 #endif m_printOrientation = wxPORTRAIT; @@ -226,10 +270,10 @@ wxPrintData::wxPrintData(const wxPrintData& printData) m_devNames = (void*) NULL; #elif defined( __WXMAC__ ) #if TARGET_CARBON - m_macPageFormat = kPMNoPageFormat; + m_macPageFormat = kPMNoPageFormat; m_macPrintSettings = kPMNoPrintSettings; #else - m_macPrintInfo = NULL; + m_macPrintSettings = NULL; #endif #endif (*this) = printData; @@ -248,17 +292,26 @@ wxPrintData::~wxPrintData() #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; } + #else - wxASSERT( m_macPrintInfo ); + wxASSERT( m_macPrintSettings ); // we should perhaps delete #endif #endif @@ -725,17 +778,17 @@ void wxPrintData::ConvertFromNative() #ifdef __WXMAC__ void wxPrintData::ConvertToNative() { -#ifdef TARGET_CARBON +#if TARGET_CARBON #else - (**m_macPrintInfo).prJob.iCopies = m_printNoCopies; + (**(THPrint)m_macPrintSettings).prJob.iCopies = m_printNoCopies; #endif } void wxPrintData::ConvertFromNative() { -#ifdef TARGET_CARBON +#if TARGET_CARBON #else - m_printNoCopies = (**m_macPrintInfo).prJob.iCopies; + m_printNoCopies = (**(THPrint)m_macPrintSettings).prJob.iCopies; #endif } #endif @@ -743,10 +796,10 @@ void wxPrintData::ConvertFromNative() void wxPrintData::operator=(const wxPrintData& data) { #ifdef __WXMAC__ -#ifdef TARGET_CARBON +#if TARGET_CARBON #else - m_macPrintInfo = data.m_macPrintInfo; - HandToHand( (Handle*) &m_macPrintInfo ); + m_macPrintSettings = data.m_macPrintSettings; + HandToHand( (Handle*) &m_macPrintSettings ); #endif #endif m_printNoCopies = data.m_printNoCopies; @@ -1045,21 +1098,21 @@ void wxPrintDialogData::SetOwnerWindow(wxWindow* win) #ifdef __WXMAC__ void wxPrintDialogData::ConvertToNative() { -#ifdef TARGET_CARBON +#if TARGET_CARBON #else - (**m_printData.m_macPrintInfo).prJob.iFstPage = m_printFromPage; - (**m_printData.m_macPrintInfo).prJob.iLstPage = m_printToPage; + (**(THPrint)m_printData.m_macPrintSettings).prJob.iFstPage = m_printFromPage; + (**(THPrint)m_printData.m_macPrintSettings).prJob.iLstPage = m_printToPage; m_printData.ConvertToNative(); #endif } void wxPrintDialogData::ConvertFromNative() { -#ifdef TARGET_CARBON +#if TARGET_CARBON #else m_printData.ConvertFromNative(); - m_printFromPage = (**m_printData.m_macPrintInfo).prJob.iFstPage; - m_printToPage = (**m_printData.m_macPrintInfo).prJob.iLstPage; + m_printFromPage = (**(THPrint)m_printData.m_macPrintSettings).prJob.iFstPage; + m_printToPage = (**(THPrint)m_printData.m_macPrintSettings).prJob.iLstPage; #endif } #endif @@ -1370,18 +1423,18 @@ void wxPageSetupDialogData::ConvertToNative() { m_printData.ConvertToNative(); // on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0 -#ifdef TARGET_CARBON +#if TARGET_CARBON #else - (**m_printData.m_macPrintInfo).rPaper.left = int( ((double) m_minMarginTopLeft.x)*mm2pt ); - (**m_printData.m_macPrintInfo).rPaper.top = int( ((double) m_minMarginTopLeft.y)*mm2pt ); + (**(THPrint)m_printData.m_macPrintSettings).rPaper.left = int( ((double) m_minMarginTopLeft.x)*mm2pt ); + (**(THPrint)m_printData.m_macPrintSettings).rPaper.top = int( ((double) m_minMarginTopLeft.y)*mm2pt ); - (**m_printData.m_macPrintInfo).rPaper.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x)*mm2pt ); - (**m_printData.m_macPrintInfo).rPaper.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y)*mm2pt ); + (**(THPrint)m_printData.m_macPrintSettings).rPaper.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x)*mm2pt ); + (**(THPrint)m_printData.m_macPrintSettings).rPaper.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y)*mm2pt ); - (**m_printData.m_macPrintInfo).prInfo.rPage.left = 0; - (**m_printData.m_macPrintInfo).prInfo.rPage.top = 0; - (**m_printData.m_macPrintInfo).prInfo.rPage.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x - m_minMarginBottomRight.x)*mm2pt ); - (**m_printData.m_macPrintInfo).prInfo.rPage.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y - m_minMarginBottomRight.y)*mm2pt ); + (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.left = 0; + (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.top = 0; + (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x - m_minMarginBottomRight.x)*mm2pt ); + (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y - m_minMarginBottomRight.y)*mm2pt ); #endif } @@ -1389,16 +1442,16 @@ void wxPageSetupDialogData::ConvertFromNative() { m_printData.ConvertFromNative (); -#ifdef TARGET_CARBON +#if TARGET_CARBON #else - m_paperSize.x = ((double) (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).rPaper.left ) * pt2mm; - m_paperSize.y = ((double) (**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).rPaper.top ) * pt2mm; + m_paperSize.x = ((double) (**(THPrint)m_printData.m_macPrintSettings).rPaper.right - (**(THPrint)m_printData.m_macPrintSettings).rPaper.left ) * pt2mm; + m_paperSize.y = ((double) (**(THPrint)m_printData.m_macPrintSettings).rPaper.bottom - (**(THPrint)m_printData.m_macPrintSettings).rPaper.top ) * pt2mm; - m_minMarginTopLeft.x = ((double) -(**m_printData.m_macPrintInfo).rPaper.left ) * pt2mm; - m_minMarginTopLeft.y = ((double) -(**m_printData.m_macPrintInfo).rPaper.top ) * pt2mm; + m_minMarginTopLeft.x = ((double) -(**(THPrint)m_printData.m_macPrintSettings).rPaper.left ) * pt2mm; + m_minMarginTopLeft.y = ((double) -(**(THPrint)m_printData.m_macPrintSettings).rPaper.top ) * pt2mm; - m_minMarginBottomRight.x = ((double) (**m_printData.m_macPrintInfo).rPaper.right - (**m_printData.m_macPrintInfo).prInfo.rPage.right ) * pt2mm; - m_minMarginBottomRight.y = ((double)(**m_printData.m_macPrintInfo).rPaper.bottom - (**m_printData.m_macPrintInfo).prInfo.rPage.bottom ) * pt2mm; + m_minMarginBottomRight.x = ((double) (**(THPrint)m_printData.m_macPrintSettings).rPaper.right - (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.right ) * pt2mm; + m_minMarginBottomRight.y = ((double)(**(THPrint)m_printData.m_macPrintSettings).rPaper.bottom - (**(THPrint)m_printData.m_macPrintSettings).prInfo.rPage.bottom ) * pt2mm; #endif // adjust minimal values //TODO add custom fields in dialog for margins @@ -1459,12 +1512,9 @@ void wxPageSetupDialogData::CalculatePaperSizeFromId() wxSize sz = wxThePrintPaperDatabase->GetSize(m_printData.GetPaperId()); - if (sz.x != 0) - { - // sz is in 10ths of a mm, so multiply by 10. - m_paperSize.x = sz.x * 10; - m_paperSize.y = sz.y * 10; - } + // sz is in 10ths of a mm, while paper size is in mm + m_paperSize.x = sz.x / 10; + m_paperSize.y = sz.y / 10; } #endif // wxUSE_PRINTING_ARCHITECTURE