First step at moving the print (dialog) native

data into native dirs and cleaning up the code.
   The native part of wxPrintData is now created
   via the wxPrintFactory. I moved the code for
   PostScript to /src/generic/prntdlgg. and for
   MSW to its the respective dir. I only made
   wxMac compile, but it already has a native
   print data class, which should be easy to
   merge.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29947 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2004-10-17 17:25:40 +00:00
parent 4200d1f416
commit 8850cbd3c3
11 changed files with 801 additions and 671 deletions
+14 -58
View File
@@ -26,6 +26,10 @@
#include "wx/stream.h"
#endif
class WXDLLEXPORT wxPrintNativeDataBase;
class WXDLLEXPORT wxColourData: public wxObject
{
public:
@@ -206,61 +210,22 @@ public:
void SetQuality(wxPrintQuality quality) { m_printQuality = quality; }
void SetBin(wxPrintBin bin) { m_bin = bin; }
// PostScript-specific data
const wxString& GetPrinterCommand() const { return m_printerCommand; }
const wxString& GetPrinterOptions() const { return m_printerOptions; }
const wxString& GetPreviewCommand() const { return m_previewCommand; }
const wxString& GetFilename() const { return m_filename; }
const wxString& GetFontMetricPath() const { return m_afmPath; }
double GetPrinterScaleX() const { return m_printerScaleX; }
double GetPrinterScaleY() const { return m_printerScaleY; }
long GetPrinterTranslateX() const { return m_printerTranslateX; }
long GetPrinterTranslateY() const { return m_printerTranslateY; }
wxPrintMode GetPrintMode() const { return m_printMode; }
void SetPrinterCommand(const wxString& command) { m_printerCommand = command; }
void SetPrinterOptions(const wxString& options) { m_printerOptions = options; }
void SetPreviewCommand(const wxString& command) { m_previewCommand = command; }
void SetFilename(const wxString& filename) { m_filename = filename; }
void SetFontMetricPath(const wxString& path) { m_afmPath = path; }
void SetPrinterScaleX(double x) { m_printerScaleX = x; }
void SetPrinterScaleY(double y) { m_printerScaleY = y; }
void SetPrinterScaling(double x, double y) { m_printerScaleX = x; m_printerScaleY = y; }
void SetPrinterTranslateX(long x) { m_printerTranslateX = x; }
void SetPrinterTranslateY(long y) { m_printerTranslateY = y; }
void SetPrinterTranslation(long x, long y) { m_printerTranslateX = x; m_printerTranslateY = y; }
void SetPrintMode(wxPrintMode printMode) { m_printMode = printMode; }
#if wxUSE_STREAMS
wxOutputStream* GetOutputStream() { return m_outputstream; }
void SetOutputStream(wxOutputStream* outputstream) { m_outputstream = outputstream; }
#endif
wxString GetFilename() const { return m_filename; }
void SetFilename( const wxString &filename ) { m_filename = filename; }
void operator=(const wxPrintData& data);
wxPrintNativeDataBase *GetNativeData() const { return m_nativeData; }
#if defined(__WXMSW__)
// Convert to/from the DEVMODE structure
#if defined(__WXMAC__)
void ConvertToNative();
void ConvertFromNative();
void* GetNativeData() const { return m_devMode; }
void SetNativeData(void* data) { m_devMode = data; }
void* GetNativeDataDevNames() const { return m_devNames; }
void SetNativeDataDevNames(void* data) { m_devNames = data; }
#elif defined(__WXMAC__)
void ConvertToNative();
void ConvertFromNative();
#endif
public:
#if defined(__WXMSW__)
void* m_devMode;
void* m_devNames;
#elif defined(__WXMAC__)
#if defined(__WXMAC__)
wxNativePrintData* m_nativePrintData ;
#endif
#if wxUSE_STREAMS
wxOutputStream* m_outputstream;
#endif
private:
wxPrintBin m_bin;
@@ -269,25 +234,16 @@ private:
int m_printOrientation;
bool m_printCollate;
// New members, 24/3/99
wxString m_printerName;
bool m_colour;
wxDuplexMode m_duplexMode;
wxPrintQuality m_printQuality;
wxPaperSize m_paperId;
wxSize m_paperSize;
// PostScript-specific data
wxString m_printerCommand;
wxString m_previewCommand;
wxString m_printerOptions;
wxString m_filename;
wxString m_afmPath;
double m_printerScaleX;
double m_printerScaleY;
long m_printerTranslateX;
long m_printerTranslateY;
wxPrintMode m_printMode;
wxPrintNativeDataBase *m_nativeData;
private:
DECLARE_DYNAMIC_CLASS(wxPrintData)
+64 -1
View File
@@ -23,6 +23,7 @@
#include "wx/dialog.h"
#include "wx/cmndata.h"
#include "wx/prntbase.h"
#include "wx/printdlg.h"
#if wxUSE_POSTSCRIPT
@@ -37,6 +38,7 @@ class WXDLLEXPORT wxStaticText;
class WXDLLEXPORT wxRadioBox;
class WXDLLEXPORT wxPrintSetupData;
class WXDLLEXPORT wxPageSetupData;
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
@@ -71,12 +73,73 @@ enum
wxPRINTID_PAPERSIZE
};
#if wxUSE_POSTSCRIPT
//----------------------------------------------------------------------------
// wxPostScriptNativeData
//----------------------------------------------------------------------------
class WXDLLEXPORT wxPostScriptPrintNativeData: public wxPrintNativeDataBase
{
public:
wxPostScriptPrintNativeData();
virtual ~wxPostScriptPrintNativeData();
virtual bool ConvertTo( wxPrintData &data );
virtual bool ConvertFrom( const wxPrintData &data );
virtual bool Ok() const { return true; }
const wxString& GetPrinterCommand() const { return m_printerCommand; }
const wxString& GetPrinterOptions() const { return m_printerOptions; }
const wxString& GetPreviewCommand() const { return m_previewCommand; }
const wxString& GetFontMetricPath() const { return m_afmPath; }
double GetPrinterScaleX() const { return m_printerScaleX; }
double GetPrinterScaleY() const { return m_printerScaleY; }
long GetPrinterTranslateX() const { return m_printerTranslateX; }
long GetPrinterTranslateY() const { return m_printerTranslateY; }
wxPrintMode GetPrintMode() const { return m_printMode; }
void SetPrinterCommand(const wxString& command) { m_printerCommand = command; }
void SetPrinterOptions(const wxString& options) { m_printerOptions = options; }
void SetPreviewCommand(const wxString& command) { m_previewCommand = command; }
void SetFontMetricPath(const wxString& path) { m_afmPath = path; }
void SetPrinterScaleX(double x) { m_printerScaleX = x; }
void SetPrinterScaleY(double y) { m_printerScaleY = y; }
void SetPrinterScaling(double x, double y) { m_printerScaleX = x; m_printerScaleY = y; }
void SetPrinterTranslateX(long x) { m_printerTranslateX = x; }
void SetPrinterTranslateY(long y) { m_printerTranslateY = y; }
void SetPrinterTranslation(long x, long y) { m_printerTranslateX = x; m_printerTranslateY = y; }
void SetPrintMode(wxPrintMode printMode) { m_printMode = printMode; }
#if wxUSE_STREAMS
wxOutputStream *GetOutputStream() { return m_outputStream; }
void SetOutputStream( wxOutputStream *output ) { m_outputStream = output; }
#endif
private:
wxString m_printerCommand;
wxString m_previewCommand;
wxString m_printerOptions;
wxString m_afmPath;
double m_printerScaleX;
double m_printerScaleY;
long m_printerTranslateX;
long m_printerTranslateY;
wxPrintMode m_printMode;
#if wxUSE_STREAMS
wxOutputStream *m_outputStream;
#endif
private:
DECLARE_DYNAMIC_CLASS(wxPostScriptPrintNativeData)
};
// ----------------------------------------------------------------------------
// Simulated Print and Print Setup dialogs for non-Windows platforms (and
// Windows using PostScript print/preview)
// ----------------------------------------------------------------------------
#if wxUSE_POSTSCRIPT
class WXDLLEXPORT wxGenericPrintDialog : public wxPrintDialogBase
{
public:
+17
View File
@@ -21,7 +21,24 @@
#include "wx/dialog.h"
#include "wx/cmndata.h"
#include "wx/printdlg.h"
#include "wx/prntbase.h"
//----------------------------------------------------------------------------
// wxMacPrintNativeData
//----------------------------------------------------------------------------
class WXDLLEXPORT wxMacPrintNativeData: public wxPrintNativeDataBase
{
public:
wxMacPrintNativeData() {};
virtual ~wxMacPrintNativeData() {};
virtual bool ConvertTo( wxPrintData &data ) { return true; }
virtual bool ConvertFrom( const wxPrintData &data ) { return true; }
virtual bool Ok() const { return true; }
};
/*
* wxPrinterDialog
* The common dialog for printing.
+29
View File
@@ -20,10 +20,39 @@
#include "wx/dialog.h"
#include "wx/cmndata.h"
#include "wx/prntbase.h"
#include "wx/printdlg.h"
class WXDLLEXPORT wxDC;
//----------------------------------------------------------------------------
// wxWindowsPrintNativeData
//----------------------------------------------------------------------------
class WXDLLEXPORT wxWindowsPrintNativeData: public wxPrintNativeDataBase
{
public:
wxWindowsPrintNativeData();
virtual ~wxWindowsPrintNativeData();
virtual bool ConvertTo( wxPrintData &data );
virtual bool ConvertFrom( const wxPrintData &data );
virtual bool Ok() const;
void* GetNativeData() const { return m_devMode; }
void SetNativeData(void* data) { m_devMode = data; }
void* GetNativeDataDevNames() const { return m_devNames; }
void SetNativeDataDevNames(void* data) { m_devNames = data; }
private:
void* m_devMode;
void* m_devNames;
private:
DECLARE_DYNAMIC_CLASS(wxWindowsPrintNativeData)
};
// ---------------------------------------------------------------------------
// wxPrinterDialog: the common dialog for printing.
// ---------------------------------------------------------------------------
+27
View File
@@ -39,6 +39,7 @@ class WXDLLEXPORT wxPreviewCanvas;
class WXDLLEXPORT wxPreviewControlBar;
class WXDLLEXPORT wxPreviewFrame;
class WXDLLEXPORT wxPrintFactory;
class WXDLLEXPORT wxPrintNativeDataBase;
//----------------------------------------------------------------------------
// error consts
@@ -77,6 +78,8 @@ public:
wxPrintDialogData *data = NULL ) = 0;
virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
wxPrintData *data ) = 0;
virtual wxPrintNativeDataBase *CreatePrintNativeData() = 0;
static void SetPrintFactory( wxPrintFactory *factory );
static wxPrintFactory *GetFactory();
@@ -104,6 +107,30 @@ public:
wxPrintDialogData *data = NULL );
virtual wxPrintDialogBase *CreatePrintDialog( wxWindow *parent,
wxPrintData *data );
virtual wxPrintNativeDataBase *CreatePrintNativeData();
};
//----------------------------------------------------------------------------
// wxPrintNativeDataBase
//----------------------------------------------------------------------------
class WXDLLEXPORT wxPrintNativeDataBase: public wxObject
{
public:
wxPrintNativeDataBase();
virtual ~wxPrintNativeDataBase() {}
virtual bool ConvertTo( wxPrintData &data ) = 0;
virtual bool ConvertFrom( const wxPrintData &data ) = 0;
virtual bool Ok() const = 0;
int m_ref;
private:
DECLARE_CLASS(wxPrintNativeDataBase)
DECLARE_NO_COPY_CLASS(wxPrintNativeDataBase)
};
//----------------------------------------------------------------------------
+53 -567
View File
File diff suppressed because it is too large Load Diff
+22
View File
@@ -146,6 +146,28 @@ wxPrintDialogBase *wxNativePrintFactory::CreatePrintDialog( wxWindow *parent,
#endif
}
wxPrintNativeDataBase *wxNativePrintFactory::CreatePrintNativeData()
{
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
return new wxWindowsPrintNativeData;
#elif defined(__WXMAC__)
return new wxMacPrintNativeData;
#else
return new wxPostScriptPrintNativeData;
#endif
}
//----------------------------------------------------------------------------
// wxPrintNativeDataBase
//----------------------------------------------------------------------------
IMPLEMENT_ABSTRACT_CLASS(wxPrintNativeDataBase, wxObject)
wxPrintNativeDataBase::wxPrintNativeDataBase()
{
m_ref = 1;
}
//----------------------------------------------------------------------------
// wxPrinterBase
//----------------------------------------------------------------------------
+34 -15
View File
@@ -36,6 +36,7 @@
#include "wx/log.h"
#include "wx/generic/dcpsg.h"
#include "wx/prntbase.h"
#include "wx/generic/prntdlgg.h"
#include "wx/paper.h"
#include "wx/filefn.h"
#if WXWIN_COMPATIBILITY_2_2
@@ -1799,8 +1800,11 @@ wxSize wxPostScriptDC::GetPPI(void) const
bool wxPostScriptDC::StartDoc( const wxString& message )
{
wxCHECK_MSG( m_ok, false, wxT("invalid postscript dc") );
wxPostScriptPrintNativeData *data =
(wxPostScriptPrintNativeData *) m_printData.GetNativeData();
if ( m_printData.GetPrintMode() != wxPRINT_MODE_STREAM )
if (data->GetPrintMode() != wxPRINT_MODE_STREAM )
{
if (m_printData.GetFilename() == wxEmptyString)
{
@@ -1963,13 +1967,16 @@ void wxPostScriptDC::EndDoc ()
PsPrintf( wxT("%% %d %d lineto closepath stroke\n"), llx, ury );
#endif
#if defined(__X__) || defined(__WXGTK__)
if (m_ok && (m_printData.GetPrintMode() == wxPRINT_MODE_PRINTER))
#ifndef __WXMSW__
wxPostScriptPrintNativeData *data =
(wxPostScriptPrintNativeData *) m_printData.GetNativeData();
if (m_ok && (data->GetPrintMode() == wxPRINT_MODE_PRINTER))
{
wxString command;
command += m_printData.GetPrinterCommand();
command += data->GetPrinterCommand();
command += wxT(" ");
command += m_printData.GetPrinterOptions();
command += data->GetPrinterOptions();
command += wxT(" ");
command += m_printData.GetFilename();
@@ -1998,11 +2005,14 @@ void wxPostScriptDC::StartPage()
wxCoord translate_x, translate_y;
double scale_x, scale_y;
translate_x = (wxCoord)m_printData.GetPrinterTranslateX();
translate_y = (wxCoord)m_printData.GetPrinterTranslateY();
wxPostScriptPrintNativeData *data =
(wxPostScriptPrintNativeData *) m_printData.GetNativeData();
scale_x = m_printData.GetPrinterScaleX();
scale_y = m_printData.GetPrinterScaleY();
translate_x = (wxCoord)data->GetPrinterTranslateX();
translate_y = (wxCoord)data->GetPrinterTranslateY();
scale_x = data->GetPrinterScaleX();
scale_y = data->GetPrinterScaleY();
if (m_printData.GetOrientation() == wxLANDSCAPE)
{
@@ -2245,11 +2255,14 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string,
FILE *afmFile = NULL;
wxPostScriptPrintNativeData *data =
(wxPostScriptPrintNativeData *) m_printData.GetNativeData();
// Get the directory of the AFM files
wxString afmName;
if (!m_printData.GetFontMetricPath().IsEmpty())
if (!data->GetFontMetricPath().IsEmpty())
{
afmName = m_printData.GetFontMetricPath();
afmName = data->GetFontMetricPath();
afmName << wxFILE_SEP_PATH << name;
afmFile = wxFopen(afmName,wxT("r"));
}
@@ -2465,13 +2478,16 @@ void wxPostScriptDC::PsPrintf( const wxChar* fmt, ... )
void wxPostScriptDC::PsPrint( const char* psdata )
{
switch( m_printData.GetPrintMode() )
wxPostScriptPrintNativeData *data =
(wxPostScriptPrintNativeData *) m_printData.GetNativeData();
switch(data->GetPrintMode())
{
#if wxUSE_STREAMS
// append to output stream
case wxPRINT_MODE_STREAM:
{
wxOutputStream* outputstream = m_printData.GetOutputStream();
wxOutputStream* outputstream = data->GetOutputStream();
wxCHECK_RET( outputstream, wxT("invalid outputstream") );
outputstream->Write( psdata, strlen( psdata ) );
}
@@ -2487,13 +2503,16 @@ void wxPostScriptDC::PsPrint( const char* psdata )
void wxPostScriptDC::PsPrint( int ch )
{
switch( m_printData.GetPrintMode() )
wxPostScriptPrintNativeData *data =
(wxPostScriptPrintNativeData *) m_printData.GetNativeData();
switch (data->GetPrintMode())
{
#if wxUSE_STREAMS
// append to output stream
case wxPRINT_MODE_STREAM:
{
wxOutputStream* outputstream = m_printData.GetOutputStream();
wxOutputStream* outputstream = data->GetOutputStream();
wxCHECK_RET( outputstream, wxT("invalid outputstream") );
outputstream->PutC( ch );
}
+75 -26
View File
@@ -56,6 +56,7 @@
#include "wx/generic/dcpsg.h"
#endif
#include "wx/prntbase.h"
#include "wx/printdlg.h"
#include "wx/paper.h"
#include "wx/filename.h"
@@ -66,23 +67,6 @@
#include <stdlib.h>
#include <string.h>
// ----------------------------------------------------------------------------
// wxWin macros
// ----------------------------------------------------------------------------
#if wxUSE_POSTSCRIPT
IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog)
#endif // wxUSE_POSTSCRIPT
IMPLEMENT_CLASS(wxGenericPageSetupDialog, wxDialog)
BEGIN_EVENT_TABLE(wxGenericPageSetupDialog, wxDialog)
EVT_BUTTON(wxPRINTID_SETUP, wxGenericPageSetupDialog::OnPrinter)
END_EVENT_TABLE()
// ----------------------------------------------------------------------------
// global vars
// ----------------------------------------------------------------------------
@@ -91,6 +75,54 @@ extern wxPrintPaperDatabase *wxThePrintPaperDatabase;
#if wxUSE_POSTSCRIPT
//----------------------------------------------------------------------------
// wxPostScriptNativeData
//----------------------------------------------------------------------------
IMPLEMENT_CLASS(wxPostScriptPrintNativeData, wxPrintNativeDataBase)
wxPostScriptPrintNativeData::wxPostScriptPrintNativeData()
{
m_previewCommand = 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;
m_printerTranslateY = 0;
m_printMode = wxPRINT_MODE_FILE;
}
wxPostScriptPrintNativeData::~wxPostScriptPrintNativeData()
{
}
bool wxPostScriptPrintNativeData::ConvertTo( wxPrintData &data )
{
return true;
}
bool wxPostScriptPrintNativeData::ConvertFrom( const wxPrintData &data )
{
return true;
}
// ----------------------------------------------------------------------------
// Generic print dialog for non-Windows printing use.
// ----------------------------------------------------------------------------
@@ -256,25 +288,28 @@ void wxGenericPrintDialog::OnOK(wxCommandEvent& WXUNUSED(event))
if (m_printDialogData.GetToPage() < 1)
m_printDialogData.SetToPage(m_printDialogData.GetFromPage());
wxPostScriptPrintNativeData *data =
(wxPostScriptPrintNativeData *) m_printDialogData.GetPrintData().GetNativeData();
// There are some interactions between the global setup data
// and the standard print dialog. The global printing 'mode'
// is determined by whether the user checks Print to file
// or not.
if (m_printDialogData.GetPrintToFile())
{
m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_FILE);
data->SetPrintMode(wxPRINT_MODE_FILE);
wxFileName fname( m_printDialogData.GetPrintData().GetFilename() );
wxFileDialog dialog( this, _("PostScript file"),
fname.GetPath(), fname.GetFullName(), wxT("*.ps"), wxOPEN | wxOVERWRITE_PROMPT );
if (dialog.ShowModal() != wxID_OK) return;
m_printDialogData.GetPrintData().SetFilename( dialog.GetPath() );
}
else
{
m_printDialogData.GetPrintData().SetPrintMode(wxPRINT_MODE_PRINTER);
data->SetPrintMode(wxPRINT_MODE_PRINTER);
}
EndModal(wxID_OK);
@@ -403,6 +438,8 @@ wxDC *wxGenericPrintDialog::GetPrintDC()
// Generic print setup dialog
// ----------------------------------------------------------------------------
IMPLEMENT_CLASS(wxGenericPrintSetupDialog, wxDialog)
wxGenericPrintSetupDialog::wxGenericPrintSetupDialog(wxWindow *parent, wxPrintData* data):
wxDialog(parent, wxID_ANY, _("Print Setup"), wxPoint(0, 0), wxSize(600, 600), wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL)
{
@@ -469,10 +506,13 @@ wxGenericPrintSetupDialog::~wxGenericPrintSetupDialog()
bool wxGenericPrintSetupDialog::TransferDataToWindow()
{
if (m_printerCommandText && m_printData.GetPrinterCommand())
m_printerCommandText->SetValue(m_printData.GetPrinterCommand());
if (m_printerOptionsText && m_printData.GetPrinterOptions())
m_printerOptionsText->SetValue(m_printData.GetPrinterOptions());
wxPostScriptPrintNativeData *data =
(wxPostScriptPrintNativeData *) m_printData.GetNativeData();
if (m_printerCommandText && data->GetPrinterCommand())
m_printerCommandText->SetValue(data->GetPrinterCommand());
if (m_printerOptionsText && data->GetPrinterOptions())
m_printerOptionsText->SetValue(data->GetPrinterOptions());
if (m_colourCheckBox)
m_colourCheckBox->SetValue(m_printData.GetColour());
@@ -488,10 +528,13 @@ bool wxGenericPrintSetupDialog::TransferDataToWindow()
bool wxGenericPrintSetupDialog::TransferDataFromWindow()
{
wxPostScriptPrintNativeData *data =
(wxPostScriptPrintNativeData *) m_printData.GetNativeData();
if (m_printerCommandText)
m_printData.SetPrinterCommand(m_printerCommandText->GetValue());
data->SetPrinterCommand(m_printerCommandText->GetValue());
if (m_printerOptionsText)
m_printData.SetPrinterOptions(m_printerOptionsText->GetValue());
data->SetPrinterOptions(m_printerOptionsText->GetValue());
if (m_colourCheckBox)
m_printData.SetColour(m_colourCheckBox->GetValue());
if (m_orientationRadioBox)
@@ -559,6 +602,12 @@ wxComboBox *wxGenericPrintSetupDialog::CreatePaperTypeChoice(int *x, int *y)
// Generic page setup dialog
// ----------------------------------------------------------------------------
IMPLEMENT_CLASS(wxGenericPageSetupDialog, wxDialog)
BEGIN_EVENT_TABLE(wxGenericPageSetupDialog, wxDialog)
EVT_BUTTON(wxPRINTID_SETUP, wxGenericPageSetupDialog::OnPrinter)
END_EVENT_TABLE()
void wxGenericPageSetupDialog::OnPrinter(wxCommandEvent& WXUNUSED(event))
{
// We no longer query GetPrintMode, so we can eliminate the need
+7 -4
View File
@@ -44,6 +44,7 @@
#endif
#include "wx/dcprint.h"
#include "wx/printdlg.h"
#include "math.h"
#if wxUSE_COMMON_DIALOGS
@@ -282,12 +283,14 @@ static bool wxGetDefaultDeviceName(wxString& deviceName, wxString& portName)
// Gets an HDC for the specified printer configuration
WXHDC WXDLLEXPORT wxGetPrinterDC(const wxPrintData& printDataConst)
{
wxPrintData printData = printDataConst;
printData.ConvertToNative();
wxWindowsPrintNativeData *data =
(wxWindowsPrintNativeData *) printDataConst.GetNativeData();
data->ConvertFrom( printDataConst );
wxChar* driverName = (wxChar*) NULL;
wxString devNameStr = printData.GetPrinterName();
wxString devNameStr = printDataConst.GetPrinterName();
wxChar* portName = (wxChar*) NULL; // Obsolete in WIN32
const wxChar* deviceName;
@@ -298,7 +301,7 @@ WXHDC WXDLLEXPORT wxGetPrinterDC(const wxPrintData& printDataConst)
LPDEVMODE lpDevMode = (LPDEVMODE) NULL;
HGLOBAL hDevMode = (HGLOBAL)(DWORD) printData.GetNativeData();
HGLOBAL hDevMode = (HGLOBAL)(DWORD) data->GetNativeData();
if ( hDevMode )
lpDevMode = (DEVMODE*) GlobalLock(hDevMode);
+459
View File
@@ -39,6 +39,7 @@
#include "wx/cmndata.h"
#include "wx/printdlg.h"
#include "wx/dcprint.h"
#include "wx/paper.h"
#include <stdlib.h>
@@ -50,6 +51,464 @@
#include <print.h>
#endif
//----------------------------------------------------------------------------
// wxWindowsPrintNativeData
//----------------------------------------------------------------------------
#ifdef __WXDEBUG__
static wxString wxGetPrintDlgError()
{
DWORD err = CommDlgExtendedError();
wxString msg = wxT("Unknown");
switch (err)
{
case CDERR_FINDRESFAILURE: msg = wxT("CDERR_FINDRESFAILURE"); break;
case CDERR_INITIALIZATION: msg = wxT("CDERR_INITIALIZATION"); break;
case CDERR_LOADRESFAILURE: msg = wxT("CDERR_LOADRESFAILURE"); break;
case CDERR_LOADSTRFAILURE: msg = wxT("CDERR_LOADSTRFAILURE"); break;
case CDERR_LOCKRESFAILURE: msg = wxT("CDERR_LOCKRESFAILURE"); break;
case CDERR_MEMALLOCFAILURE: msg = wxT("CDERR_MEMALLOCFAILURE"); break;
case CDERR_MEMLOCKFAILURE: msg = wxT("CDERR_MEMLOCKFAILURE"); break;
case CDERR_NOHINSTANCE: msg = wxT("CDERR_NOHINSTANCE"); break;
case CDERR_NOHOOK: msg = wxT("CDERR_NOHOOK"); break;
case CDERR_NOTEMPLATE: msg = wxT("CDERR_NOTEMPLATE"); break;
case CDERR_STRUCTSIZE: msg = wxT("CDERR_STRUCTSIZE"); break;
case PDERR_RETDEFFAILURE: msg = wxT("PDERR_RETDEFFAILURE"); break;
case PDERR_PRINTERNOTFOUND: msg = wxT("PDERR_PRINTERNOTFOUND"); break;
case PDERR_PARSEFAILURE: msg = wxT("PDERR_PARSEFAILURE"); break;
case PDERR_NODEVICES: msg = wxT("PDERR_NODEVICES"); break;
case PDERR_NODEFAULTPRN: msg = wxT("PDERR_NODEFAULTPRN"); break;
case PDERR_LOADDRVFAILURE: msg = wxT("PDERR_LOADDRVFAILURE"); break;
case PDERR_INITFAILURE: msg = wxT("PDERR_INITFAILURE"); break;
case PDERR_GETDEVMODEFAIL: msg = wxT("PDERR_GETDEVMODEFAIL"); break;
case PDERR_DNDMMISMATCH: msg = wxT("PDERR_DNDMMISMATCH"); break;
case PDERR_DEFAULTDIFFERENT: msg = wxT("PDERR_DEFAULTDIFFERENT"); break;
case PDERR_CREATEICFAILURE: msg = wxT("PDERR_CREATEICFAILURE"); break;
default: break;
}
return msg;
}
#endif
static HGLOBAL wxCreateDevNames(const wxString& driverName, const wxString& printerName, const wxString& portName)
{
HGLOBAL hDev = NULL;
// if (!driverName.IsEmpty() && !printerName.IsEmpty() && !portName.IsEmpty())
if (driverName.IsEmpty() && printerName.IsEmpty() && portName.IsEmpty())
{
}
else
{
hDev = GlobalAlloc(GPTR, 4*sizeof(WORD)+
( driverName.Length() + 1 +
printerName.Length() + 1 +
portName.Length()+1 ) * sizeof(wxChar) );
LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(hDev);
lpDev->wDriverOffset = sizeof(WORD) * 4 / sizeof(wxChar);
wxStrcpy((wxChar*)lpDev + lpDev->wDriverOffset, driverName);
lpDev->wDeviceOffset = (WORD)( lpDev->wDriverOffset +
driverName.Length() + 1 );
wxStrcpy((wxChar*)lpDev + lpDev->wDeviceOffset, printerName);
lpDev->wOutputOffset = (WORD)( lpDev->wDeviceOffset +
printerName.Length() + 1 );
wxStrcpy((wxChar*)lpDev + lpDev->wOutputOffset, portName);
lpDev->wDefault = 0;
GlobalUnlock(hDev);
}
return hDev;
}
IMPLEMENT_CLASS(wxWindowsPrintNativeData, wxPrintNativeDataBase)
wxWindowsPrintNativeData::wxWindowsPrintNativeData()
{
m_devMode = (void*) NULL;
m_devNames = (void*) NULL;
}
wxWindowsPrintNativeData::~wxWindowsPrintNativeData()
{
HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
if ( hDevMode )
GlobalFree(hDevMode);
HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
if ( hDevNames )
GlobalFree(hDevNames);
}
bool wxWindowsPrintNativeData::Ok() const
{
return (m_devMode != NULL) ;
}
bool wxWindowsPrintNativeData::ConvertTo( wxPrintData &data )
{
HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
if (!hDevMode)
return false;
if ( hDevMode )
{
LPDEVMODE devMode = (LPDEVMODE)GlobalLock(hDevMode);
//// Orientation
if (devMode->dmFields & DM_ORIENTATION)
data.SetOrientation( devMode->dmOrientation );
//// Collation
if (devMode->dmFields & DM_COLLATE)
{
if (devMode->dmCollate == DMCOLLATE_TRUE)
data.SetCollate( true );
else
data.SetCollate( false );
}
//// Number of copies
if (devMode->dmFields & DM_COPIES)
data.SetNoCopies( devMode->dmCopies );
if (devMode->dmFields & DM_DEFAULTSOURCE)
data.SetBin( (wxPrintBin)devMode->dmDefaultSource );
//// Printer name
if (devMode->dmDeviceName[0] != 0)
data.SetPrinterName( devMode->dmDeviceName );
//// Colour
if (devMode->dmFields & DM_COLOR)
{
if (devMode->dmColor == DMCOLOR_COLOR)
data.SetColour( true );
else
data.SetColour( false );
}
else
data.SetColour( true );
//// Paper size
// We don't know size of user defined paper and some buggy drivers
// set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
// dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
// code wouldn't set m_paperSize correctly.
if ((devMode->dmFields & DM_PAPERSIZE) && (devMode->dmPaperSize < DMPAPER_USER))
{
if (wxThePrintPaperDatabase)
{
wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize);
if (paper)
{
data.SetPaperId( paper->GetId() );
data.SetPaperSize( wxSize(paper->GetWidth() / 10,paper->GetHeight() / 10) );
}
else
{
// Shouldn't really get here
wxFAIL_MSG(wxT("Couldn't find paper size in paper database."));
data.SetPaperId( wxPAPER_NONE );
data.SetPaperSize( wxSize(0,0) );
}
}
else
{
// Shouldn't really get here
wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
data.SetPaperId( wxPAPER_NONE );
data.SetPaperSize( wxSize(0,0) );
}
}
else if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH))
{
// DEVMODE is in tenths of a milimeter
data.SetPaperId( wxPAPER_NONE );
data.SetPaperSize( wxSize(devMode->dmPaperWidth / 10, devMode->dmPaperLength / 10) );
}
else
{
// Shouldn't really get here
wxFAIL_MSG(wxT("Couldn't find paper size from DEVMODE."));
data.SetPaperId( wxPAPER_NONE );
data.SetPaperSize( wxSize(0,0) );
}
//// Duplex
if (devMode->dmFields & DM_DUPLEX)
{
switch (devMode->dmDuplex)
{
case DMDUP_HORIZONTAL: data.SetDuplex( wxDUPLEX_HORIZONTAL ); break;
case DMDUP_VERTICAL: data.SetDuplex( wxDUPLEX_VERTICAL ); break;
default:
case DMDUP_SIMPLEX: data.SetDuplex( wxDUPLEX_SIMPLEX ); break;
}
}
else
data.SetDuplex( wxDUPLEX_SIMPLEX );
//// Quality
if (devMode->dmFields & DM_PRINTQUALITY)
{
switch (devMode->dmPrintQuality)
{
case DMRES_MEDIUM: data.SetQuality( wxPRINT_QUALITY_MEDIUM ); break;
case DMRES_LOW: data.SetQuality( wxPRINT_QUALITY_LOW ); break;
case DMRES_DRAFT: data.SetQuality( wxPRINT_QUALITY_DRAFT ); break;
case DMRES_HIGH: data.SetQuality( wxPRINT_QUALITY_HIGH ); break;
default:
{
// TODO: if the printer fills in the resolution in DPI, how
// will the application know if it's high, low, draft etc.??
// wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
data.SetQuality( devMode->dmPrintQuality );
break;
}
}
}
else
data.SetQuality( wxPRINT_QUALITY_HIGH );
GlobalUnlock(hDevMode);
}
if (hDevNames)
{
LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(hDevNames);
if (lpDevNames)
{
// TODO: Unicode-ification
// Get the port name
// port is obsolete in WIN32
// m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
// Get the printer name
wxString printerName = (LPTSTR)lpDevNames + lpDevNames->wDeviceOffset;
// Not sure if we should check for this mismatch
// wxASSERT_MSG( (m_printerName == "" || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
if (printerName != wxT(""))
data.SetPrinterName( printerName );
GlobalUnlock(hDevNames);
}
}
return true;
}
bool wxWindowsPrintNativeData::ConvertFrom( const wxPrintData &data )
{
HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
if (!hDevMode)
{
// Use PRINTDLG as a way of creating a DEVMODE object
PRINTDLG pd;
// GNU-WIN32 has the wrong size PRINTDLG - can't work out why.
#ifdef __GNUWIN32__
memset(&pd, 0, 66);
pd.lStructSize = 66;
#else
memset(&pd, 0, sizeof(PRINTDLG));
#ifdef __WXWINCE__
pd.cbStruct = sizeof(PRINTDLG);
#else
pd.lStructSize = sizeof(PRINTDLG);
#endif
#endif
pd.hwndOwner = (HWND)NULL;
pd.hDevMode = NULL; // Will be created by PrintDlg
pd.hDevNames = NULL; // Ditto
//pd.hInstance = (HINSTANCE) wxGetInstance();
pd.Flags = PD_RETURNDEFAULT;
pd.nCopies = 1;
// Fill out the DEVMODE structure
// so we can use it as input in the 'real' PrintDlg
if (!PrintDlg(&pd))
{
if ( pd.hDevMode )
GlobalFree(pd.hDevMode);
if ( pd.hDevNames )
GlobalFree(pd.hDevNames);
pd.hDevMode = NULL;
pd.hDevNames = NULL;
#if defined(__WXDEBUG__) && defined(__WIN32__)
wxString str(wxT("Printing error: "));
str += wxGetPrintDlgError();
wxLogDebug(str);
#endif
}
else
{
hDevMode = pd.hDevMode;
m_devMode = (void*)(long) hDevMode;
pd.hDevMode = NULL;
// We'll create a new DEVNAMEs structure below.
if ( pd.hDevNames )
GlobalFree(pd.hDevNames);
pd.hDevNames = NULL;
// hDevNames = pd->hDevNames;
// m_devNames = (void*)(long) hDevNames;
// pd->hDevnames = NULL;
}
}
if ( hDevMode )
{
LPDEVMODE devMode = (LPDEVMODE) GlobalLock(hDevMode);
//// Orientation
devMode->dmOrientation = (short)data.GetOrientation();
//// Collation
devMode->dmCollate = (data.GetCollate() ? DMCOLLATE_TRUE : DMCOLLATE_FALSE);
devMode->dmFields |= DM_COLLATE;
//// Number of copies
devMode->dmCopies = (short)data.GetNoCopies();
devMode->dmFields |= DM_COPIES;
//// Printer name
wxString name = data.GetPrinterName();
if (name != wxT(""))
{
//int len = wxMin(31, m_printerName.Len());
wxStrncpy((wxChar*)devMode->dmDeviceName,name.c_str(),31);
devMode->dmDeviceName[31] = wxT('\0');
}
//// Colour
if (data.GetColour())
devMode->dmColor = DMCOLOR_COLOR;
else
devMode->dmColor = DMCOLOR_MONOCHROME;
devMode->dmFields |= DM_COLOR;
//// Paper size
if (data.GetPaperId() == wxPAPER_NONE)
{
// DEVMODE is in tenths of a milimeter
devMode->dmPaperWidth = (short)(data.GetPaperSize().x * 10);
devMode->dmPaperLength = (short)(data.GetPaperSize().y * 10);
devMode->dmPaperSize = DMPAPER_USER;
devMode->dmFields |= DM_PAPERWIDTH;
devMode->dmFields |= DM_PAPERLENGTH;
}
else
{
if (wxThePrintPaperDatabase)
{
wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperType( data.GetPaperId() );
if (paper)
{
devMode->dmPaperSize = (short)paper->GetPlatformId();
devMode->dmFields |= DM_PAPERSIZE;
}
}
}
//// Duplex
short duplex;
switch (data.GetDuplex())
{
case wxDUPLEX_HORIZONTAL:
duplex = DMDUP_HORIZONTAL;
break;
case wxDUPLEX_VERTICAL:
duplex = DMDUP_VERTICAL;
break;
default:
// in fact case wxDUPLEX_SIMPLEX:
duplex = DMDUP_SIMPLEX;
break;
}
devMode->dmDuplex = duplex;
devMode->dmFields |= DM_DUPLEX;
//// Quality
short quality;
switch (data.GetQuality())
{
case wxPRINT_QUALITY_MEDIUM:
quality = DMRES_MEDIUM;
break;
case wxPRINT_QUALITY_LOW:
quality = DMRES_LOW;
break;
case wxPRINT_QUALITY_DRAFT:
quality = DMRES_DRAFT;
break;
case wxPRINT_QUALITY_HIGH:
quality = DMRES_HIGH;
break;
default:
quality = (short)data.GetQuality();
break;
}
devMode->dmPrintQuality = quality;
devMode->dmFields |= DM_PRINTQUALITY;
if (data.GetBin() != wxPRINTBIN_DEFAULT)
{
switch (data.GetBin())
{
case wxPRINTBIN_ONLYONE: devMode->dmDefaultSource = DMBIN_ONLYONE; break;
case wxPRINTBIN_LOWER: devMode->dmDefaultSource = DMBIN_LOWER; break;
case wxPRINTBIN_MIDDLE: devMode->dmDefaultSource = DMBIN_MIDDLE; break;
case wxPRINTBIN_MANUAL: devMode->dmDefaultSource = DMBIN_MANUAL; break;
case wxPRINTBIN_ENVELOPE: devMode->dmDefaultSource = DMBIN_ENVELOPE; break;
case wxPRINTBIN_ENVMANUAL: devMode->dmDefaultSource = DMBIN_ENVMANUAL; break;
case wxPRINTBIN_AUTO: devMode->dmDefaultSource = DMBIN_AUTO; break;
case wxPRINTBIN_TRACTOR: devMode->dmDefaultSource = DMBIN_TRACTOR; break;
case wxPRINTBIN_SMALLFMT: devMode->dmDefaultSource = DMBIN_SMALLFMT; break;
case wxPRINTBIN_LARGEFMT: devMode->dmDefaultSource = DMBIN_LARGEFMT; break;
case wxPRINTBIN_LARGECAPACITY: devMode->dmDefaultSource = DMBIN_LARGECAPACITY; break;
case wxPRINTBIN_CASSETTE: devMode->dmDefaultSource = DMBIN_CASSETTE; break;
case wxPRINTBIN_FORMSOURCE: devMode->dmDefaultSource = DMBIN_FORMSOURCE; break;
default:
devMode->dmDefaultSource = (short)(DMBIN_USER + data.GetBin() - wxPRINTBIN_USER);
break;
}
devMode->dmFields |= DM_DEFAULTSOURCE;
}
GlobalUnlock(hDevMode);
}
if ( hDevNames )
{
GlobalFree(hDevNames);
}
// TODO: I hope it's OK to pass some empty strings to DEVNAMES.
m_devNames = (void*) (long) wxCreateDevNames(wxT(""), data.GetPrinterName(), wxT(""));
return true;
}
// ---------------------------------------------------------------------------
// wxPrintDialog
// ---------------------------------------------------------------------------