#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"
+
+#if wxTEST_POSTSCRIPT_IN_MSW
#include "wx/generic/printps.h"
#include "wx/generic/prntdlgg.h"
+#endif
#include "printing.h"
// 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 __WXGTK__
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
#include "folder.xpm"
#endif
// 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"));
+ frame->SetIcon(wxIcon("mondrian"));
#endif
#ifdef __X__
- frame->SetIcon(wxIcon(aiai_bits, aiai_width, aiai_height));
+// frame->SetIcon(wxIcon(mondrian_bits, mondrian_width, mondrian_height));
#endif
// Make a menubar
file_menu->Append(WXPRINT_PAGE_SETUP, "Page Set&up...", "Page setup");
file_menu->Append(WXPRINT_PREVIEW, "Print Pre&view", "Preview");
-#ifdef __WXMSW__
+#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))
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__
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__
orientation = data.GetOrientation();
}
+#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))
+{
+ 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::OnPrintSetupPS(wxCommandEvent& WXUNUSED(event))
{
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
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);
-#if defined(__WXGTK__)
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
wxIcon my_icon( folder_xpm );
#elif defined(__WXMSW__)
wxIcon my_icon( "mondrian" );
{
}
-// 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;
}
// 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->SetPen(* wxBLACK_PEN);
dc->DrawLine(50, 50, (long)(50.0 + logUnits), 50);
dc->DrawLine(50, 50, 50, (long)(50.0 + logUnits));
- dc->SetFont(itemFont);
+ dc->SetFont(* wxGetApp().m_testFont);
dc->SetBackgroundMode(wxTRANSPARENT);
dc->DrawText("Some test text", 200, 200 );
// 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);
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 );