X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/962cbf2ee0ba655db3e6db00ade68b5f1e85ba1e..4b1f929cc3421e43409f7d62260bf9ba0ffc75ab:/src/common/cmndata.cpp?ds=inline diff --git a/src/common/cmndata.cpp b/src/common/cmndata.cpp index 2b82ea36fd..45718f159f 100644 --- a/src/common/cmndata.cpp +++ b/src/common/cmndata.cpp @@ -5,7 +5,7 @@ // Modified by: // Created: 01/02/97 // RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem +// Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -39,17 +39,12 @@ #include "wx/cmndata.h" #include "wx/log.h" -// For compatibility -#if (defined(__WXMOTIF__) || defined(__WXGTK__) || defined(__WXPM__) || defined(__WXMAC__)) && wxUSE_POSTSCRIPT - #define wxCOMPATIBILITY_WITH_PRINTSETUPDATA 1 -#endif +#if wxUSE_FONTDLG + #include "wx/fontdlg.h" +#endif // wxUSE_FONTDLG #if wxUSE_PRINTING_ARCHITECTURE #include "wx/paper.h" - - #if wxCOMPATIBILITY_WITH_PRINTSETUPDATA - #include "wx/generic/dcpsg.h" - #endif #endif // wxUSE_PRINTING_ARCHITECTURE #ifdef __WXMSW__ @@ -61,11 +56,6 @@ #include #endif // Win16 - #ifdef __WXWINE__ - #include - #include - #endif - #if defined(__WATCOMC__) || defined(__SC__) || defined(__SALFORDC__) #include #include @@ -83,7 +73,17 @@ #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 @@ -111,6 +111,7 @@ wxColourData::wxColourData() } wxColourData::wxColourData(const wxColourData& data) + : wxObject() { (*this) = data; } @@ -119,7 +120,7 @@ wxColourData::~wxColourData() { } -void wxColourData::SetCustomColour(int i, wxColour& colour) +void wxColourData::SetCustomColour(int i, const wxColour& colour) { if (i > 15 || i < 0) return; @@ -152,7 +153,7 @@ void wxColourData::operator=(const wxColourData& data) wxFontData::wxFontData() { // Intialize colour to black. - fontColour.Set(0, 0, 0); + fontColour = wxNullColour; showHelp = FALSE; allowSymbols = TRUE; @@ -167,6 +168,14 @@ wxFontData::~wxFontData() { } +#if wxUSE_FONTDLG + +wxFontDialogBase::~wxFontDialogBase() +{ +} + +#endif // wxUSE_FONTDLG + #if wxUSE_PRINTING_ARCHITECTURE // ---------------------------------------------------------------------------- // Print data @@ -181,12 +190,13 @@ wxPrintData::wxPrintData() #if TARGET_CARBON m_macPageFormat = kPMNoPageFormat; m_macPrintSettings = kPMNoPrintSettings; - + m_macPrintSession = kPMNoReference ; + #if PM_USE_SESSION_APIS - PMPrintSession macPrintSession = kPMNoReference; OSStatus err; - err = ::UMAPrOpen(&macPrintSession) ; + err = PMCreateSession((PMPrintSession *)&m_macPrintSession) ; + if ( err == noErr ) { err = PMCreatePageFormat((PMPageFormat *)&m_macPageFormat); @@ -196,7 +206,7 @@ wxPrintData::wxPrintData() // associated with the current printing session. if ((err == noErr) && (m_macPageFormat != kPMNoPageFormat)) { - err = PMSessionDefaultPageFormat((PMPrintSession)macPrintSession, + err = PMSessionDefaultPageFormat((PMPrintSession)m_macPrintSession, (PMPageFormat)m_macPageFormat); } @@ -207,25 +217,25 @@ wxPrintData::wxPrintData() // associated with the current printing session. if ((err == noErr) && (m_macPrintSettings != kPMNoPrintSettings)) { - err = PMSessionDefaultPrintSettings((PMPrintSession)macPrintSession, + err = PMSessionDefaultPrintSettings((PMPrintSession)m_macPrintSession, (PMPrintSettings)m_macPrintSettings); } } - ::UMAPrClose(&macPrintSession) ; + #endif #else - m_macPrintInfo = (THPrint) NewHandleClear( sizeof( TPrint ) ); - (**(THPrint)m_macPrintInfo).iPrVersion = 0; // something invalid + m_macPrintSettings = (THPrint) NewHandleClear( sizeof( TPrint ) ); + (**(THPrint)m_macPrintSettings).iPrVersion = 0; // something invalid - (**(THPrint)m_macPrintInfo).prInfo.iHRes = 72; - (**(THPrint)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 }; - (**(THPrint)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 }; - (**(THPrint)m_macPrintInfo).rPaper = r2; - (**(THPrint)m_macPrintInfo).prStl.iPageV = 11 * 120 ; // 11 inches in 120th of an inch - (**(THPrint)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; @@ -233,7 +243,7 @@ wxPrintData::wxPrintData() m_printCollate = FALSE; // New, 24/3/99 - m_printerName = ""; + m_printerName = wxT(""); m_colour = TRUE; m_duplexMode = wxDUPLEX_SIMPLEX; m_printQuality = wxPRINT_QUALITY_HIGH; @@ -241,11 +251,26 @@ wxPrintData::wxPrintData() m_paperSize = wxSize(210, 297); // PostScript-specific data - m_printerCommand = ""; - m_previewCommand = ""; - m_printerOptions = ""; - m_filename = ""; - m_afmPath = ""; + m_previewCommand = wxT(""); + m_filename = wxT(""); +#ifdef __VMS__ + m_printerCommand = wxT("print"); + m_printerOptions = wxT("/nonotify/queue=psqueue"); + m_afmPath = wxT("sys$ps_font_metrics:"); +#endif + +#ifdef __WXMSW__ + m_printerCommand = wxT("print"); + m_printerOptions = wxT(""); + m_afmPath = wxT("c:\\windows\\system\\"); +#endif + +#if !defined(__VMS__) && !defined(__WXMSW__) + m_printerCommand = wxT("lpr"); + m_printerOptions = wxT(""); + m_afmPath = wxT(""); +#endif + m_printerScaleX = 1.0; m_printerScaleY = 1.0; m_printerTranslateX = 0; @@ -254,6 +279,7 @@ wxPrintData::wxPrintData() } wxPrintData::wxPrintData(const wxPrintData& printData) + : wxObject() { #ifdef __WXMSW__ m_devMode = (void*) NULL; @@ -262,8 +288,9 @@ wxPrintData::wxPrintData(const wxPrintData& printData) #if TARGET_CARBON m_macPageFormat = kPMNoPageFormat; m_macPrintSettings = kPMNoPrintSettings; + m_macPrintSession = kPMNoReference ; #else - m_macPrintInfo = NULL; + m_macPrintSettings = NULL; #endif #endif (*this) = printData; @@ -300,8 +327,17 @@ wxPrintData::~wxPrintData() 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_macPrintInfo ); + wxASSERT( m_macPrintSettings ); // we should perhaps delete #endif #endif @@ -444,10 +480,7 @@ void wxPrintData::ConvertToNative() //// Orientation -#ifndef __WXWINE__ devMode->dmOrientation = m_printOrientation; -#endif - devMode->dmFields = DM_ORIENTATION; //// Collation @@ -479,7 +512,6 @@ void wxPrintData::ConvertToNative() devMode->dmFields |= DM_COLOR; -#ifndef __WXWINE__ //// Paper size if (m_paperId == wxPAPER_NONE) @@ -503,7 +535,6 @@ void wxPrintData::ConvertToNative() } } } -#endif //// Duplex @@ -572,12 +603,10 @@ void wxPrintData::ConvertFromNative() { LPDEVMODE devMode = (LPDEVMODE)GlobalLock(hDevMode); -#ifndef __WXWINE__ //// Orientation if (devMode->dmFields & DM_ORIENTATION) m_printOrientation = devMode->dmOrientation; -#endif //// Collation @@ -602,17 +631,7 @@ void wxPrintData::ConvertFromNative() if (devMode->dmDeviceName[0] != 0) { - // TODO: make this Unicode compatible - char buf[32]; - int i = 0; - while (devMode->dmDeviceName[i] != 0) - { - buf[i] = devMode->dmDeviceName[i]; - i ++; - } - buf[i] = 0; - - m_printerName = buf; + m_printerName = devMode->dmDeviceName; } //// Colour @@ -627,7 +646,6 @@ void wxPrintData::ConvertFromNative() else m_colour = TRUE; -#ifndef __WXWINE__ //// Paper size // We don't know size of user defined paper and some buggy drivers @@ -681,7 +699,6 @@ void wxPrintData::ConvertFromNative() m_paperSize.y = 0; m_paperId = wxPAPER_NONE; } -#endif //// Duplex @@ -770,7 +787,7 @@ void wxPrintData::ConvertToNative() { #if TARGET_CARBON #else - (**(THPrint)m_macPrintInfo).prJob.iCopies = m_printNoCopies; + (**(THPrint)m_macPrintSettings).prJob.iCopies = m_printNoCopies; #endif } @@ -778,7 +795,7 @@ void wxPrintData::ConvertFromNative() { #if TARGET_CARBON #else - m_printNoCopies = (**(THPrint)m_macPrintInfo).prJob.iCopies; + m_printNoCopies = (**(THPrint)m_macPrintSettings).prJob.iCopies; #endif } #endif @@ -787,9 +804,29 @@ void wxPrintData::operator=(const wxPrintData& data) { #ifdef __WXMAC__ #if TARGET_CARBON + 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_macPrintInfo = data.m_macPrintInfo; - HandToHand( (Handle*) &m_macPrintInfo ); + m_macPrintSettings = data.m_macPrintSettings; + HandToHand( (Handle*) &m_macPrintSettings ); #endif #endif m_printNoCopies = data.m_printNoCopies; @@ -815,32 +852,16 @@ void wxPrintData::operator=(const wxPrintData& data) m_printMode = data.m_printMode; } -// For compatibility -#if wxCOMPATIBILITY_WITH_PRINTSETUPDATA -void wxPrintData::operator=(const wxPrintSetupData& setupData) +// Is this data OK for showing the print dialog? +bool wxPrintData::Ok() const { - SetPrinterCommand(setupData.GetPrinterCommand()); - SetPreviewCommand(setupData.GetPrintPreviewCommand()); - SetPrinterOptions(setupData.GetPrinterOptions()); - - long xt, yt; - setupData.GetPrinterTranslation(& xt, & yt); - SetPrinterTranslation(xt, yt); - - double xs, ys; - setupData.GetPrinterScaling(& xs, & ys); - SetPrinterScaling(xs, ys); - - SetOrientation(setupData.GetPrinterOrientation()); - SetPrintMode((wxPrintMode) setupData.GetPrinterMode()); - SetFontMetricPath(setupData.GetAFMPath()); - if (setupData.GetPaperName() != "") - SetPaperId(wxThePrintPaperDatabase->ConvertNameToId(setupData.GetPaperName())); - SetColour(setupData.GetColour()); - SetFilename(setupData.GetPrinterFile()); +#ifdef __WXMSW__ + ((wxPrintData*)this)->ConvertToNative(); + return (m_devMode != NULL) ; +#else + return TRUE; +#endif } -#endif // wxCOMPATIBILITY_WITH_PRINTSETUPDATA - // ---------------------------------------------------------------------------- // Print dialog data @@ -868,6 +889,7 @@ wxPrintDialogData::wxPrintDialogData() } wxPrintDialogData::wxPrintDialogData(const wxPrintDialogData& dialogData) + : wxObject() { #ifdef __WXMSW__ m_printDlgData = NULL; @@ -954,7 +976,8 @@ void wxPrintDialogData::ConvertToNative() m_printData.SetNativeData((void*) NULL); - wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); + // Shouldn't assert; we should be able to test Ok-ness at a higher level + //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); pd->hDevNames = (HGLOBAL)(DWORD) m_printData.GetNativeDataDevNames(); @@ -1090,8 +1113,8 @@ void wxPrintDialogData::ConvertToNative() { #if TARGET_CARBON #else - (**(THPrint)m_printData.m_macPrintInfo).prJob.iFstPage = m_printFromPage; - (**(THPrint)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 } @@ -1101,8 +1124,8 @@ void wxPrintDialogData::ConvertFromNative() #if TARGET_CARBON #else m_printData.ConvertFromNative(); - m_printFromPage = (**(THPrint)m_printData.m_macPrintInfo).prJob.iFstPage; - m_printToPage = (**(THPrint)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 @@ -1162,6 +1185,7 @@ wxPageSetupDialogData::wxPageSetupDialogData() } wxPageSetupDialogData::wxPageSetupDialogData(const wxPageSetupDialogData& dialogData) + : wxObject() { #if defined(__WIN95__) m_pageSetupData = NULL; @@ -1209,7 +1233,7 @@ wxPageSetupDialogData::~wxPageSetupDialogData() #endif } -void wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data) +wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data) { m_paperSize = data.m_paperSize; m_minMarginTopLeft = data.m_minMarginTopLeft; @@ -1225,11 +1249,15 @@ void wxPageSetupDialogData::operator=(const wxPageSetupDialogData& data) m_enableHelp = data.m_enableHelp; m_printData = data.m_printData; + + return *this; } -void wxPageSetupDialogData::operator=(const wxPrintData& data) +wxPageSetupDialogData& wxPageSetupDialogData::operator=(const wxPrintData& data) { m_printData = data; + + return *this; } #if defined(__WIN95__) @@ -1261,7 +1289,8 @@ void wxPageSetupDialogData::ConvertToNative() m_printData.SetNativeData((void*) NULL); - wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); + // Shouldn't assert; we should be able to test Ok-ness at a higher level + //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!")); // Pass the devnames data (created in m_printData.ConvertToNative) // to the PRINTDLG structure, since it'll @@ -1415,16 +1444,16 @@ void wxPageSetupDialogData::ConvertToNative() // on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0 #if TARGET_CARBON #else - (**(THPrint)m_printData.m_macPrintInfo).rPaper.left = int( ((double) m_minMarginTopLeft.x)*mm2pt ); - (**(THPrint)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 ); - (**(THPrint)m_printData.m_macPrintInfo).rPaper.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x)*mm2pt ); - (**(THPrint)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 ); - (**(THPrint)m_printData.m_macPrintInfo).prInfo.rPage.left = 0; - (**(THPrint)m_printData.m_macPrintInfo).prInfo.rPage.top = 0; - (**(THPrint)m_printData.m_macPrintInfo).prInfo.rPage.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x - m_minMarginBottomRight.x)*mm2pt ); - (**(THPrint)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 } @@ -1433,15 +1462,29 @@ void wxPageSetupDialogData::ConvertFromNative() m_printData.ConvertFromNative (); #if TARGET_CARBON + PMRect rPaper; + + OSStatus err = PMGetAdjustedPaperRect((PMPageFormat)m_printData.m_macPageFormat, &rPaper); + if ( err == noErr ) + { + m_paperSize.x = (int)(((double) rPaper.right - rPaper.left ) * pt2mm); + m_paperSize.y = (int)(((double) rPaper.bottom - rPaper.top ) * pt2mm); + + m_minMarginTopLeft.x = (int)(((double) - rPaper.left ) * pt2mm); + m_minMarginTopLeft.y = (int)(((double) - rPaper.top ) * pt2mm); + +// m_minMarginBottomRight.x = ((double) 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; + } #else - m_paperSize.x = ((double) (**(THPrint)m_printData.m_macPrintInfo).rPaper.right - (**(THPrint)m_printData.m_macPrintInfo).rPaper.left ) * pt2mm; - m_paperSize.y = ((double) (**(THPrint)m_printData.m_macPrintInfo).rPaper.bottom - (**(THPrint)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) -(**(THPrint)m_printData.m_macPrintInfo).rPaper.left ) * pt2mm; - m_minMarginTopLeft.y = ((double) -(**(THPrint)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) (**(THPrint)m_printData.m_macPrintInfo).rPaper.right - (**(THPrint)m_printData.m_macPrintInfo).prInfo.rPage.right ) * pt2mm; - m_minMarginBottomRight.y = ((double)(**(THPrint)m_printData.m_macPrintInfo).rPaper.bottom - (**(THPrint)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 @@ -1502,12 +1545,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