#ifndef WX_PRECOMP
#include "wx/wx.h"
-#include "wx/postscrp.h"
#endif
-#if !USE_PRINTING_ARCHITECTURE
-#error You must set USE_PRINTING_ARCHITECTURE to 1 in wx_setup.h to compile this demo.
+#if !wxUSE_PRINTING_ARCHITECTURE
+#error You must set wxUSE_PRINTING_ARCHITECTURE to 1 in wx_setup.h to compile this demo.
#endif
+// Set this to 1 if you want to test PostScript printing under MSW.
+// However, you'll also need to edit src/msw/makefile.nt.
+#define wxTEST_POSTSCRIPT_IN_MSW 0
+
#include <ctype.h>
#include "wx/metafile.h"
#include "wx/print.h"
#include "wx/printdlg.h"
+
+#include "wx/accel.h"
+
+#if wxTEST_POSTSCRIPT_IN_MSW
#include "wx/generic/printps.h"
#include "wx/generic/prntdlgg.h"
+#endif
#include "printing.h"
+#ifndef __WXMSW__
+#include "mondrian.xpm"
+#endif
+
// Declare a frame
-MyFrame *frame = NULL;
+MyFrame *frame = (MyFrame *) NULL;
int orientation = wxPORTRAIT;
// Main proc
IMPLEMENT_APP(MyApp)
-// Must initialise these in OnInit, not statically
-wxPen *red_pen;
-wxFont *labelFont;
-wxFont *itemFont;
-
-float zoom_factor = 1.0;
-
-#ifdef __X__
-#include "aiai.xbm"
-#endif
-
-#ifdef __WXGTK__
-#include "folder.xpm"
-#endif
-
-
// Writes a header on a page. Margin units are in millimetres.
bool WritePageHeader(wxPrintout *printout, wxDC *dc, char *text, float mmToLogical);
// main frame
bool MyApp::OnInit(void)
{
- // Create a red pen
- red_pen = new wxPen("RED", 3, wxSOLID);
-
- // Create a small font
- itemFont = new wxFont(11, wxROMAN, wxNORMAL, wxNORMAL);
- labelFont = new wxFont(12, wxROMAN, wxITALIC, wxBOLD);
+ m_testFont = new wxFont(10, wxSWISS, wxNORMAL, wxNORMAL);
// Create the main frame window
- frame = new MyFrame(NULL, "wxWindows Printing Demo", wxPoint(0, 0), wxSize(400, 400));
+ frame = new MyFrame((wxFrame *) NULL, (char *) "wxWindows Printing Demo", wxPoint(0, 0), wxSize(400, 400));
// Give it a status line
frame->CreateStatusBar(2);
// Load icon and bitmap
-#ifdef __WXMSW__
- frame->SetIcon(wxIcon("aiai_icn"));
-#endif
-#ifdef __X__
- frame->SetIcon(wxIcon(aiai_bits, aiai_width, aiai_height));
-#endif
+ frame->SetIcon( wxICON( mondrian) );
// Make a menubar
wxMenu *file_menu = new wxMenu;
file_menu->Append(WXPRINT_PAGE_SETUP, "Page Set&up...", "Page setup");
file_menu->Append(WXPRINT_PREVIEW, "Print Pre&view", "Preview");
-#ifdef __WXMSW__
+ // Accelerators
+ wxAcceleratorEntry entries[1];
+ entries[0].Set(wxACCEL_CTRL, (int) 'V', WXPRINT_PREVIEW);
+ wxAcceleratorTable accel(1, entries);
+ frame->SetAcceleratorTable(accel);
+
+#if defined(__WXMSW__) && wxTEST_POSTSCRIPT_IN_MSW
file_menu->AppendSeparator();
file_menu->Append(WXPRINT_PRINT_PS, "Print PostScript...", "Print (PostScript)");
file_menu->Append(WXPRINT_PRINT_SETUP_PS, "Print Setup PostScript...", "Setup printer properties (PostScript)");
// Give it scrollbars: the virtual canvas is 20 * 50 = 1000 pixels in each direction
canvas->SetScrollbars(20, 20, 50, 50);
- // This ensures that the fonts get created as _screen_
- // fonts, not printer fonts.
- canvas->SetFont(itemFont);
- canvas->SetFont(labelFont);
-
frame->canvas = canvas;
frame->Centre(wxBOTH);
EVT_MENU(WXPRINT_PREVIEW, MyFrame::OnPrintPreview)
EVT_MENU(WXPRINT_PRINT_SETUP, MyFrame::OnPrintSetup)
EVT_MENU(WXPRINT_PAGE_SETUP, MyFrame::OnPageSetup)
+ EVT_MENU(WXPRINT_ABOUT, MyFrame::OnPrintAbout)
+#if defined(__WXMSW__) && wxTEST_POSTSCRIPT_IN_MSW
EVT_MENU(WXPRINT_PRINT_PS, MyFrame::OnPrintPS)
EVT_MENU(WXPRINT_PREVIEW_PS, MyFrame::OnPrintPreviewPS)
EVT_MENU(WXPRINT_PRINT_SETUP_PS, MyFrame::OnPrintSetupPS)
EVT_MENU(WXPRINT_PAGE_SETUP_PS, MyFrame::OnPageSetupPS)
- EVT_MENU(WXPRINT_ABOUT, MyFrame::OnPrintAbout)
+#endif
END_EVENT_TABLE()
// Define my frame constructor
MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size):
wxFrame(frame, -1, title, pos, size)
{
- canvas = NULL;
+ canvas = (MyCanvas *) NULL;
}
void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event))
{
-#ifdef __WXMSW__
- wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
-#else
- wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
-#endif
wxPrinter printer;
MyPrintout printout("My printout");
if (!printer.Print(this, &printout, TRUE))
wxMessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wxOK);
}
-void MyFrame::OnPrintPS(wxCommandEvent& WXUNUSED(event))
-{
- wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
-
- wxPostScriptPrinter printer;
- MyPrintout printout("My printout");
- printer.Print(this, &printout, TRUE);
-}
-
void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event))
{
-#ifdef __WXMSW__
- wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
-#else
- wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
-#endif
wxPrintData printData;
printData.SetOrientation(orientation);
frame->Show(TRUE);
}
-void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event))
-{
- wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
-
- wxPrintData printData;
- printData.SetOrientation(orientation);
-
- // Pass two printout objects: for preview, and possible printing.
- wxPrintPreview *preview = new wxPrintPreview(new MyPrintout, new MyPrintout, & printData);
- wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
- frame->Centre(wxBOTH);
- frame->Initialize();
- frame->Show(TRUE);
-}
-
void MyFrame::OnPrintSetup(wxCommandEvent& WXUNUSED(event))
{
-#ifdef __WXMSW__
- wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
-#else
- wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
-#endif
wxPrintData data;
data.SetOrientation(orientation);
-#ifdef __WXMSW__
wxPrintDialog printerDialog(this, & data);
-#else
- wxGenericPrintDialog printerDialog(this, & data);
-#endif
+
printerDialog.GetPrintData().SetSetupDialog(TRUE);
printerDialog.ShowModal();
void MyFrame::OnPageSetup(wxCommandEvent& WXUNUSED(event))
{
-#ifdef __WXMSW__
- wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
-#else
- wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
-#endif
wxPageSetupData data;
data.SetOrientation(orientation);
-#ifdef __WXMSW__
wxPageSetupDialog pageSetupDialog(this, & data);
-#else
- wxGenericPageSetupDialog pageSetupDialog(this, & data);
-#endif
pageSetupDialog.ShowModal();
data = pageSetupDialog.GetPageSetupData();
orientation = data.GetOrientation();
}
-void MyFrame::OnPrintSetupPS(wxCommandEvent& WXUNUSED(event))
+#if defined(__WXMSW__) && wxTEST_POSTSCRIPT_IN_MSW
+void MyFrame::OnPrintPS(wxCommandEvent& WXUNUSED(event))
{
- wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
+ wxPostScriptPrinter printer;
+ MyPrintout printout("My printout");
+ printer.Print(this, &printout, TRUE);
+}
+void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event))
+{
+ wxPrintData printData;
+ printData.SetOrientation(orientation);
+
+ // Pass two printout objects: for preview, and possible printing.
+ wxPrintPreview *preview = new wxPrintPreview(new MyPrintout, new MyPrintout, & printData);
+ wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650));
+ frame->Centre(wxBOTH);
+ frame->Initialize();
+ frame->Show(TRUE);
+}
+
+void MyFrame::OnPrintSetupPS(wxCommandEvent& WXUNUSED(event))
+{
wxPrintData data;
data.SetOrientation(orientation);
void MyFrame::OnPageSetupPS(wxCommandEvent& WXUNUSED(event))
{
- wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
-
wxPageSetupData data;
data.SetOrientation(orientation);
orientation = pageSetupDialog.GetPageSetupData().GetOrientation();
}
+#endif
+
void MyFrame::OnPrintAbout(wxCommandEvent& WXUNUSED(event))
{
void MyFrame::Draw(wxDC& dc)
{
- dc.SetFont(itemFont);
+ dc.SetFont(* wxGetApp().m_testFont);
+
dc.SetBackgroundMode(wxTRANSPARENT);
- dc.SetBrush(wxCYAN_BRUSH);
- dc.SetPen(wxRED_PEN);
+ dc.SetBrush(* wxCYAN_BRUSH);
+ dc.SetPen(* wxRED_PEN);
dc.DrawRectangle(0, 30, 200, 100);
dc.DrawText("Rectangle 200 by 100", 40, 40);
dc.DrawEllipse(50, 140, 100, 50);
- dc.DrawText("Test message: this is in 11 point text", 10, 180);
+ dc.DrawText("Test message: this is in 10 point text", 10, 180);
- dc.SetPen(wxBLACK_PEN);
+ dc.SetPen(* wxBLACK_PEN);
dc.DrawLine(0, 0, 200, 200);
dc.DrawLine(200, 0, 0, 200);
- wxIcon my_icon( folder_xpm );
- dc.DrawIcon( my_icon, 100, 100, TRUE );
+ wxIcon my_icon = wxICON(mondrian) ;
+
+ dc.DrawIcon( my_icon, 100, 100);
}
void MyFrame::OnSize(wxSizeEvent& event )
{
}
-// Define the behaviour for the frame closing
-// - must delete all frames except for the main one.
bool MyFrame::OnClose(void)
{
Show(FALSE);
+ delete wxGetApp().m_testFont;
return TRUE;
}
DrawPageTwo(dc);
dc->SetDeviceOrigin(0, 0);
+ dc->SetUserScale(1.0, 1.0);
char buf[200];
sprintf(buf, "PAGE %d", page);
// Draw 50 mm by 50 mm L shape
float logUnitsFactor = (float)(ppiPrinterX/(scale*25.1));
float logUnits = (float)(50*logUnitsFactor);
- dc->SetPen(wxBLACK_PEN);
- dc->DrawLine(50, 50, (long)(50.0 + logUnits), 50);
- dc->DrawLine(50, 50, 50, (long)(50.0 + logUnits));
+ dc->SetPen(* wxBLACK_PEN);
+ dc->DrawLine(50, 250, (long)(50.0 + logUnits), 250);
+ dc->DrawLine(50, 250, 50, (long)(250.0 + logUnits));
- dc->SetFont(itemFont);
+ dc->SetFont(* wxGetApp().m_testFont);
dc->SetBackgroundMode(wxTRANSPARENT);
dc->DrawText("Some test text", 200, 200 );
float bottomMarginLogical = (float)(logUnitsFactor*(pageHeightMM - bottomMargin));
float rightMarginLogical = (float)(logUnitsFactor*(pageWidthMM - rightMargin));
- dc->SetPen(wxBLACK_PEN);
+ dc->SetPen(* wxRED_PEN);
dc->DrawLine( (long)leftMarginLogical, (long)topMarginLogical,
(long)rightMarginLogical, (long)topMarginLogical);
dc->DrawLine( (long)leftMarginLogical, (long)bottomMarginLogical,
// Writes a header on a page. Margin units are in millimetres.
bool WritePageHeader(wxPrintout *printout, wxDC *dc, char *text, float mmToLogical)
{
- static wxFont *headerFont = NULL;
+/*
+ static wxFont *headerFont = (wxFont *) NULL;
if (!headerFont)
{
headerFont = wxTheFontList->FindOrCreateFont(16, wxSWISS, wxNORMAL, wxBOLD);
}
dc->SetFont(headerFont);
+*/
int pageWidthMM, pageHeightMM;
float xPos = (float)(((((pageWidthMM - leftMargin - rightMargin)/2.0)+leftMargin)*mmToLogical) - (xExtent/2.0));
dc->DrawText(text, (long)xPos, (long)topMarginLogical);
- dc->SetPen(wxBLACK_PEN);
+ dc->SetPen(* wxBLACK_PEN);
dc->DrawLine( (long)leftMarginLogical, (long)(topMarginLogical+yExtent),
(long)rightMarginLogical, (long)topMarginLogical+yExtent );