]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/cmndata.cpp
warning (in Unicode only) fix
[wxWidgets.git] / src / common / cmndata.cpp
index 78471439dfb0ef03c80da34c848fd970d65fbcc0..08e3e0cf090da7938781d7af2f342b0bba1d405d 100644 (file)
@@ -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
 /////////////////////////////////////////////////////////////////////////////
 
 #include "wx/cmndata.h"
 #include "wx/log.h"
 
-// For compatibility
-#if (defined(__WXMOTIF__) || defined(__WXGTK__) || defined(__WXX11__)|| 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__
         #include <commdlg.h>
     #endif // Win16
 
-    #ifdef __WXWINE__
-        #include <cderr.h>
-        #include <commdlg.h>
-    #endif
-
-    #if defined(__WATCOMC__) || defined(__SC__) || defined(__SALFORDC__)
+    #if defined(__WATCOMC__) || defined(__SYMANTEC__) || defined(__SALFORDC__)
         #include <windowsx.h>
         #include <commdlg.h>
     #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)
     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
@@ -114,10 +91,10 @@ wxColourData::wxColourData()
 {
     int i;
     for (i = 0; i < 16; i++)
-        custColours[i].Set(255, 255, 255);
+        m_custColours[i].Set(255, 255, 255);
 
-    chooseFull = FALSE;
-    dataColour.Set(0,0,0);
+    m_chooseFull = FALSE;
+    m_dataColour.Set(0,0,0);
 }
 
 wxColourData::wxColourData(const wxColourData& data)
@@ -135,7 +112,7 @@ void wxColourData::SetCustomColour(int i, const wxColour& colour)
     if (i > 15 || i < 0)
         return;
 
-    custColours[i] = colour;
+    m_custColours[i] = colour;
 }
 
 wxColour wxColourData::GetCustomColour(int i)
@@ -143,17 +120,17 @@ wxColour wxColourData::GetCustomColour(int i)
     if (i > 15 || i < 0)
         return wxColour(0,0,0);
 
-    return custColours[i];
+    return m_custColours[i];
 }
 
 void wxColourData::operator=(const wxColourData& data)
 {
     int i;
     for (i = 0; i < 16; i++)
-        custColours[i] = data.custColours[i];
+        m_custColours[i] = data.m_custColours[i];
 
-    dataColour = (wxColour&)data.dataColour;
-    chooseFull = data.chooseFull;
+    m_dataColour = (wxColour&)data.m_dataColour;
+    m_chooseFull = data.m_chooseFull;
 }
 
 // ----------------------------------------------------------------------------
@@ -163,13 +140,13 @@ void wxColourData::operator=(const wxColourData& data)
 wxFontData::wxFontData()
 {
     // Intialize colour to black.
-    fontColour.Set(0, 0, 0);
+    m_fontColour = wxNullColour;
 
-    showHelp = FALSE;
-    allowSymbols = TRUE;
-    enableEffects = TRUE;
-    minSize = 0;
-    maxSize = 0;
+    m_showHelp = FALSE;
+    m_allowSymbols = TRUE;
+    m_enableEffects = TRUE;
+    m_minSize = 0;
+    m_maxSize = 0;
 
     m_encoding = wxFONTENCODING_SYSTEM;
 }
@@ -178,6 +155,14 @@ wxFontData::~wxFontData()
 {
 }
 
+#if wxUSE_FONTDLG
+
+wxFontDialogBase::~wxFontDialogBase()
+{
+}
+
+#endif // wxUSE_FONTDLG
+
 #if wxUSE_PRINTING_ARCHITECTURE
 // ----------------------------------------------------------------------------
 // Print data
@@ -189,62 +174,14 @@ wxPrintData::wxPrintData()
     m_devMode = (void*) NULL;
     m_devNames = (void*) NULL;
 #elif defined( __WXMAC__ )
-#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_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;
     m_printCollate = FALSE;
 
     // New, 24/3/99
-    m_printerName = "";
+    m_printerName = wxT("");
     m_colour = TRUE;
     m_duplexMode = wxDUPLEX_SIMPLEX;
     m_printQuality = wxPRINT_QUALITY_HIGH;
@@ -252,11 +189,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;
@@ -271,12 +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;
-#else
-    m_macPrintSettings = NULL;
-#endif
+    m_nativePrintData = wxNativePrintData::Create() ;
 #endif
     (*this) = printData;
 }
@@ -291,31 +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;
-    }
-    
-#else
-    wxASSERT( m_macPrintSettings );
-    // we should perhaps delete
-#endif
+    delete m_nativePrintData ;
 #endif
 }
 
@@ -456,10 +379,7 @@ void wxPrintData::ConvertToNative()
 
         //// Orientation
 
-#ifndef __WXWINE__
         devMode->dmOrientation = m_printOrientation;
-#endif
-        devMode->dmFields = DM_ORIENTATION;
 
         //// Collation
 
@@ -491,7 +411,6 @@ void wxPrintData::ConvertToNative()
 
         devMode->dmFields |= DM_COLOR;
 
-#ifndef __WXWINE__
         //// Paper size
 
         if (m_paperId == wxPAPER_NONE)
@@ -515,7 +434,6 @@ void wxPrintData::ConvertToNative()
                 }
             }
         }
-#endif
 
         //// Duplex
 
@@ -584,12 +502,10 @@ void wxPrintData::ConvertFromNative()
     {
         LPDEVMODE devMode = (LPDEVMODE)GlobalLock(hDevMode);
 
-#ifndef __WXWINE__
         //// Orientation
 
         if (devMode->dmFields & DM_ORIENTATION)
             m_printOrientation = devMode->dmOrientation;
-#endif
 
         //// Collation
 
@@ -614,17 +530,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
@@ -639,7 +545,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
@@ -693,7 +598,6 @@ void wxPrintData::ConvertFromNative()
             m_paperSize.y = 0;
             m_paperId = wxPAPER_NONE;
         }
-#endif
 
         //// Duplex
 
@@ -778,31 +682,23 @@ void wxPrintData::ConvertFromNative()
 #endif
 
 #ifdef __WXMAC__
+
 void wxPrintData::ConvertToNative()
 {
-#if TARGET_CARBON
-#else
-    (**(THPrint)m_macPrintSettings).prJob.iCopies = m_printNoCopies;
-#endif
+    m_nativePrintData->TransferFrom( this ) ;
 }
 
 void wxPrintData::ConvertFromNative()
 {
-#if TARGET_CARBON
-#else
-    m_printNoCopies = (**(THPrint)m_macPrintSettings).prJob.iCopies;
-#endif
+    m_nativePrintData->TransferTo( this ) ;
 }
+
 #endif
 
 void wxPrintData::operator=(const wxPrintData& data)
 {
 #ifdef __WXMAC__
-#if TARGET_CARBON
-#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;
@@ -827,32 +723,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
@@ -967,7 +847,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();
 
@@ -1013,6 +894,8 @@ void wxPrintDialogData::ConvertToNative()
         pd->Flags |= PD_NOSELECTION;
     if ( !m_printEnablePageNumbers )
         pd->Flags |= PD_NOPAGENUMS;
+    else if ( (!m_printAllPages) && (!m_printSelection) )
+        pd->Flags |= PD_PAGENUMS;
     if ( m_printEnableHelp )
         pd->Flags |= PD_SHOWHELP;
     if ( m_printSetupDialog )
@@ -1059,7 +942,7 @@ void wxPrintDialogData::ConvertFromNative()
     m_printMaxPage = pd->nMaxPage;
     m_printNoCopies = pd->nCopies;
 
-    m_printAllPages = ((pd->Flags & PD_ALLPAGES) == PD_ALLPAGES);
+    m_printAllPages = (((pd->Flags & PD_PAGENUMS) != PD_PAGENUMS) && ((pd->Flags & PD_SELECTION) != PD_SELECTION));
     m_printSelection = ((pd->Flags & PD_SELECTION) == PD_SELECTION);
     m_printCollate = ((pd->Flags & PD_COLLATE) == PD_COLLATE);
     m_printToFile = ((pd->Flags & PD_PRINTTOFILE) == PD_PRINTTOFILE);
@@ -1099,25 +982,19 @@ void wxPrintDialogData::SetOwnerWindow(wxWindow* win)
 #endif // MSW
 
 #ifdef __WXMAC__
+
 void wxPrintDialogData::ConvertToNative()
 {
-#if TARGET_CARBON
-#else
-    (**(THPrint)m_printData.m_macPrintSettings).prJob.iFstPage = m_printFromPage;
-    (**(THPrint)m_printData.m_macPrintSettings).prJob.iLstPage = m_printToPage;
     m_printData.ConvertToNative();
-#endif
+    m_printData.m_nativePrintData->TransferFrom( this ) ;
 }
 
 void wxPrintDialogData::ConvertFromNative()
 {
-#if TARGET_CARBON
-#else
     m_printData.ConvertFromNative();
-    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
 
 
@@ -1279,7 +1156,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
@@ -1430,39 +1308,16 @@ void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win)
 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
-#if TARGET_CARBON
-#else
-    (**(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_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_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
+    m_printData.m_nativePrintData->TransferFrom( this ) ;
 }
 
 void wxPageSetupDialogData::ConvertFromNative()
 {
     m_printData.ConvertFromNative ();
-
-#if TARGET_CARBON
-#else
-    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_macPrintSettings).rPaper.left ) * pt2mm;
-    m_minMarginTopLeft.y = ((double) -(**(THPrint)m_printData.m_macPrintSettings).rPaper.top ) * 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
+    m_paperSize = m_printData.GetPaperSize() ;
+    CalculateIdFromPaperSize();
+    m_printData.m_nativePrintData->TransferTo( this ) ;
     // adjust minimal values
-    //TODO add custom fields in dialog for margins
 
     if ( m_marginTopLeft.x < m_minMarginTopLeft.x )
         m_marginTopLeft.x = m_minMarginTopLeft.x;