Added creation of printer DC to printer factory.
Added wxPrintData ctor to wxGnomePrintDC. Added wxGnomePrintPreview. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42345 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -78,6 +78,8 @@ public:
|
|||||||
virtual wxPageSetupDialogBase *CreatePageSetupDialog( wxWindow *parent,
|
virtual wxPageSetupDialogBase *CreatePageSetupDialog( wxWindow *parent,
|
||||||
wxPageSetupDialogData * data = NULL );
|
wxPageSetupDialogData * data = NULL );
|
||||||
|
|
||||||
|
virtual wxDC* CreatePrinterDC( const wxPrintData& data );
|
||||||
|
|
||||||
virtual bool HasPrintSetupDialog();
|
virtual bool HasPrintSetupDialog();
|
||||||
virtual wxDialog *CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data );
|
virtual wxDialog *CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data );
|
||||||
virtual bool HasOwnPrintToFile();
|
virtual bool HasOwnPrintToFile();
|
||||||
@@ -199,6 +201,7 @@ class wxGnomePrintDC: public wxDC
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxGnomePrintDC( wxGnomePrinter *printer );
|
wxGnomePrintDC( wxGnomePrinter *printer );
|
||||||
|
wxGnomePrintDC( const wxPrintData& data );
|
||||||
virtual ~wxGnomePrintDC();
|
virtual ~wxGnomePrintDC();
|
||||||
|
|
||||||
bool Ok() const { return IsOk(); }
|
bool Ok() const { return IsOk(); }
|
||||||
@@ -275,6 +278,7 @@ private:
|
|||||||
static float ms_PSScaleFactor;
|
static float ms_PSScaleFactor;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
wxPrintData m_printData;
|
||||||
PangoContext *m_context;
|
PangoContext *m_context;
|
||||||
PangoLayout *m_layout;
|
PangoLayout *m_layout;
|
||||||
PangoFontDescription *m_fontdesc;
|
PangoFontDescription *m_fontdesc;
|
||||||
@@ -286,6 +290,7 @@ private:
|
|||||||
|
|
||||||
wxGnomePrinter *m_printer;
|
wxGnomePrinter *m_printer;
|
||||||
GnomePrintContext *m_gpc;
|
GnomePrintContext *m_gpc;
|
||||||
|
GnomePrintJob* m_job; // only used and destroyed when created with wxPrintData
|
||||||
|
|
||||||
void makeEllipticalPath(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
|
void makeEllipticalPath(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
|
||||||
|
|
||||||
@@ -355,6 +360,34 @@ private:
|
|||||||
DECLARE_NO_COPY_CLASS(wxGnomePrintDC)
|
DECLARE_NO_COPY_CLASS(wxGnomePrintDC)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxGnomePrintPreview: programmer creates an object of this class to preview a
|
||||||
|
// wxPrintout.
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxGnomePreview : public wxPrintPreviewBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxGnomePrintPreview(wxPrintout *printout,
|
||||||
|
wxPrintout *printoutForPrinting = (wxPrintout *) NULL,
|
||||||
|
wxPrintDialogData *data = (wxPrintDialogData *) NULL);
|
||||||
|
wxGnomePrintPreview(wxPrintout *printout,
|
||||||
|
wxPrintout *printoutForPrinting,
|
||||||
|
wxPrintData *data);
|
||||||
|
|
||||||
|
virtual ~wxGnomePrintPreview();
|
||||||
|
|
||||||
|
virtual bool Print(bool interactive);
|
||||||
|
virtual void DetermineScaling();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Init(wxPrintout *printout, wxPrintout *printoutForPrinting);
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_CLASS(wxGnomePrintPreview)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// wxUSE_LIBGNOMEPRINT
|
// wxUSE_LIBGNOMEPRINT
|
||||||
|
|
||||||
|
@@ -77,6 +77,8 @@ public:
|
|||||||
virtual wxPageSetupDialogBase *CreatePageSetupDialog( wxWindow *parent,
|
virtual wxPageSetupDialogBase *CreatePageSetupDialog( wxWindow *parent,
|
||||||
wxPageSetupDialogData * data = NULL ) = 0;
|
wxPageSetupDialogData * data = NULL ) = 0;
|
||||||
|
|
||||||
|
virtual wxDC* CreatePrinterDC( const wxPrintData& data ) = 0;
|
||||||
|
|
||||||
// What to do and what to show in the wxPrintDialog
|
// What to do and what to show in the wxPrintDialog
|
||||||
// a) Use the generic print setup dialog or a native one?
|
// a) Use the generic print setup dialog or a native one?
|
||||||
virtual bool HasPrintSetupDialog() = 0;
|
virtual bool HasPrintSetupDialog() = 0;
|
||||||
@@ -119,6 +121,8 @@ public:
|
|||||||
virtual wxPageSetupDialogBase *CreatePageSetupDialog( wxWindow *parent,
|
virtual wxPageSetupDialogBase *CreatePageSetupDialog( wxWindow *parent,
|
||||||
wxPageSetupDialogData * data = NULL );
|
wxPageSetupDialogData * data = NULL );
|
||||||
|
|
||||||
|
virtual wxDC* CreatePrinterDC( const wxPrintData& data );
|
||||||
|
|
||||||
virtual bool HasPrintSetupDialog();
|
virtual bool HasPrintSetupDialog();
|
||||||
virtual wxDialog *CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data );
|
virtual wxDialog *CreatePrintSetupDialog( wxWindow *parent, wxPrintData *data );
|
||||||
virtual bool HasOwnPrintToFile();
|
virtual bool HasOwnPrintToFile();
|
||||||
|
@@ -43,6 +43,7 @@
|
|||||||
#include "wx/prntbase.h"
|
#include "wx/prntbase.h"
|
||||||
#include "wx/printdlg.h"
|
#include "wx/printdlg.h"
|
||||||
#include "wx/print.h"
|
#include "wx/print.h"
|
||||||
|
#include "wx/dcprint.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -54,6 +55,7 @@
|
|||||||
#include "wx/mac/private/print.h"
|
#include "wx/mac/private/print.h"
|
||||||
#else
|
#else
|
||||||
#include "wx/generic/prntdlgg.h"
|
#include "wx/generic/prntdlgg.h"
|
||||||
|
#include "wx/dcps.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
@@ -201,6 +203,17 @@ wxDialog *wxNativePrintFactory::CreatePrintSetupDialog( wxWindow *parent,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxDC* wxNativePrintFactory::CreatePrinterDC( const wxPrintData& data )
|
||||||
|
{
|
||||||
|
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
|
||||||
|
return new wxPrinterDC(data);
|
||||||
|
#elif defined(__WXMAC__)
|
||||||
|
return new wxPrinterDC(data);
|
||||||
|
#else
|
||||||
|
return new wxPrinterDC(data);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool wxNativePrintFactory::HasOwnPrintToFile()
|
bool wxNativePrintFactory::HasOwnPrintToFile()
|
||||||
{
|
{
|
||||||
// Only relevant for PostScript and here the
|
// Only relevant for PostScript and here the
|
||||||
|
@@ -309,14 +309,14 @@ wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview
|
|||||||
wxPrintout *printout,
|
wxPrintout *printout,
|
||||||
wxPrintDialogData *data )
|
wxPrintDialogData *data )
|
||||||
{
|
{
|
||||||
return new wxPostScriptPrintPreview( preview, printout, data );
|
return new wxGnomePrintPreview( preview, printout, data );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview,
|
wxPrintPreviewBase *wxGnomePrintFactory::CreatePrintPreview( wxPrintout *preview,
|
||||||
wxPrintout *printout,
|
wxPrintout *printout,
|
||||||
wxPrintData *data )
|
wxPrintData *data )
|
||||||
{
|
{
|
||||||
return new wxPostScriptPrintPreview( preview, printout, data );
|
return new wxGnomePrintPreview( preview, printout, data );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent,
|
wxPrintDialogBase *wxGnomePrintFactory::CreatePrintDialog( wxWindow *parent,
|
||||||
@@ -354,6 +354,11 @@ wxDialog *wxGnomePrintFactory::CreatePrintSetupDialog( wxWindow *parent, wxPrint
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxDC* wxGnomePrintFactory::CreatePrinterDC( const wxPrintData& data )
|
||||||
|
{
|
||||||
|
return new wxGnomePrintDC(data);
|
||||||
|
}
|
||||||
|
|
||||||
bool wxGnomePrintFactory::HasOwnPrintToFile()
|
bool wxGnomePrintFactory::HasOwnPrintToFile()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
@@ -835,6 +840,7 @@ wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter *printer )
|
|||||||
m_printer = printer;
|
m_printer = printer;
|
||||||
|
|
||||||
m_gpc = printer->GetPrintContext();
|
m_gpc = printer->GetPrintContext();
|
||||||
|
m_job = NULL; // only used and destroyed when created with wxPrintData
|
||||||
|
|
||||||
m_layout = gs_lgp->gnome_print_pango_create_layout( m_gpc );
|
m_layout = gs_lgp->gnome_print_pango_create_layout( m_gpc );
|
||||||
m_fontdesc = pango_font_description_from_string( "Sans 12" );
|
m_fontdesc = pango_font_description_from_string( "Sans 12" );
|
||||||
@@ -847,8 +853,33 @@ wxGnomePrintDC::wxGnomePrintDC( wxGnomePrinter *printer )
|
|||||||
m_signY = -1; // default y-axis bottom up -> top down
|
m_signY = -1; // default y-axis bottom up -> top down
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxGnomePrintDC::wxGnomePrintDC( const wxPrintData& data )
|
||||||
|
{
|
||||||
|
m_printer = NULL;
|
||||||
|
m_printData = data;
|
||||||
|
|
||||||
|
wxGnomePrintNativeData *native =
|
||||||
|
(wxGnomePrintNativeData*) m_printData.GetNativeData();
|
||||||
|
|
||||||
|
GnomePrintJob *job = gs_lgp->gnome_print_job_new( native->GetPrintConfig() );
|
||||||
|
m_gpc = gs_lgp->gnome_print_job_get_context (job);
|
||||||
|
m_job = job; // only used and destroyed when created with wxPrintData
|
||||||
|
|
||||||
|
m_layout = gs_lgp->gnome_print_pango_create_layout( m_gpc );
|
||||||
|
m_fontdesc = pango_font_description_from_string( "Sans 12" );
|
||||||
|
|
||||||
|
m_currentRed = 0;
|
||||||
|
m_currentBlue = 0;
|
||||||
|
m_currentGreen = 0;
|
||||||
|
|
||||||
|
m_signX = 1; // default x-axis left to right
|
||||||
|
m_signY = -1; // default y-axis bottom up -> top down
|
||||||
|
}
|
||||||
|
|
||||||
wxGnomePrintDC::~wxGnomePrintDC()
|
wxGnomePrintDC::~wxGnomePrintDC()
|
||||||
{
|
{
|
||||||
|
if (m_job)
|
||||||
|
g_object_unref (job);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxGnomePrintDC::IsOk() const
|
bool wxGnomePrintDC::IsOk() const
|
||||||
@@ -1839,5 +1870,95 @@ void wxGnomePrintModule::OnExit()
|
|||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule)
|
IMPLEMENT_DYNAMIC_CLASS(wxGnomePrintModule, wxModule)
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Print preview
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IMPLEMENT_CLASS(wxGnomePrintPreview, wxPrintPreviewBase)
|
||||||
|
|
||||||
|
void wxGnomePrintPreview::Init(wxPrintout * WXUNUSED(printout),
|
||||||
|
wxPrintout * WXUNUSED(printoutForPrinting))
|
||||||
|
{
|
||||||
|
DetermineScaling();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout,
|
||||||
|
wxPrintout *printoutForPrinting,
|
||||||
|
wxPrintDialogData *data)
|
||||||
|
: wxPrintPreviewBase(printout, printoutForPrinting, data)
|
||||||
|
{
|
||||||
|
Init(printout, printoutForPrinting);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxGnomePrintPreview::wxGnomePrintPreview(wxPrintout *printout,
|
||||||
|
wxPrintout *printoutForPrinting,
|
||||||
|
wxPrintData *data)
|
||||||
|
: wxPrintPreviewBase(printout, printoutForPrinting, data)
|
||||||
|
{
|
||||||
|
Init(printout, printoutForPrinting);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxGnomePrintPreview::~wxGnomePrintPreview()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxGnomePrintPreview::Print(bool interactive)
|
||||||
|
{
|
||||||
|
if (!m_printPrintout)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
wxPrinter printer(& m_printDialogData);
|
||||||
|
return printer.Print(m_previewFrame, m_printPrintout, interactive);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGnomePrintPreview::DetermineScaling()
|
||||||
|
{
|
||||||
|
wxPaperSize paperType = m_printDialogData.GetPrintData().GetPaperId();
|
||||||
|
if (paperType == wxPAPER_NONE)
|
||||||
|
paperType = wxPAPER_NONE;
|
||||||
|
|
||||||
|
wxPrintPaperType *paper = wxThePrintPaperDatabase->FindPaperType(paperType);
|
||||||
|
if (!paper)
|
||||||
|
paper = wxThePrintPaperDatabase->FindPaperType(wxPAPER_A4);
|
||||||
|
|
||||||
|
if (paper)
|
||||||
|
{
|
||||||
|
wxSize ScreenPixels = wxGetDisplaySize();
|
||||||
|
wxSize ScreenMM = wxGetDisplaySizeMM();
|
||||||
|
|
||||||
|
m_previewPrintout->SetPPIScreen( (int) ((ScreenPixels.GetWidth() * 25.4) / ScreenMM.GetWidth()),
|
||||||
|
(int) ((ScreenPixels.GetHeight() * 25.4) / ScreenMM.GetHeight()) );
|
||||||
|
m_previewPrintout->SetPPIPrinter(wxGnomePrintDC::GetResolution(), wxGnomePrintDC::GetResolution());
|
||||||
|
|
||||||
|
wxSize sizeDevUnits(paper->GetSizeDeviceUnits());
|
||||||
|
|
||||||
|
// TODO: get better resolution information from wxGnomePrintDC, if possible.
|
||||||
|
|
||||||
|
sizeDevUnits.x = (wxCoord)((float)sizeDevUnits.x * wxGnomePrintDC::GetResolution() / 72.0);
|
||||||
|
sizeDevUnits.y = (wxCoord)((float)sizeDevUnits.y * wxGnomePrintDC::GetResolution() / 72.0);
|
||||||
|
wxSize sizeTenthsMM(paper->GetSize());
|
||||||
|
wxSize sizeMM(sizeTenthsMM.x / 10, sizeTenthsMM.y / 10);
|
||||||
|
|
||||||
|
// If in landscape mode, we need to swap the width and height.
|
||||||
|
if ( m_printDialogData.GetPrintData().GetOrientation() == wxLANDSCAPE )
|
||||||
|
{
|
||||||
|
m_pageWidth = sizeDevUnits.y;
|
||||||
|
m_pageHeight = sizeDevUnits.x;
|
||||||
|
m_previewPrintout->SetPageSizeMM(sizeMM.y, sizeMM.x);
|
||||||
|
m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_pageWidth = sizeDevUnits.x;
|
||||||
|
m_pageHeight = sizeDevUnits.y;
|
||||||
|
m_previewPrintout->SetPageSizeMM(sizeMM.x, sizeMM.y);
|
||||||
|
m_previewPrintout->SetPageSizePixels(m_pageWidth, m_pageHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
// At 100%, the page should look about page-size on the screen.
|
||||||
|
m_previewScale = (float)0.8 * 72.0 / (float)wxGnomePrintDC::GetResolution();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// wxUSE_LIBGNOMEPRINT
|
// wxUSE_LIBGNOMEPRINT
|
||||||
|
Reference in New Issue
Block a user