#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 __X__
-#include "aiai.xbm"
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
+#include "folder.xpm"
#endif
// Writes a header on a page. Margin units are in millimetres.
// 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 __WINDOWS__
- frame->SetIcon(wxIcon("aiai_icn"));
+#ifdef __WXMSW__
+ 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 __WINDOWS__
+#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& event)
+void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
{
Close(TRUE);
}
-void MyFrame::OnPrint(wxCommandEvent& event)
+void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event))
{
-#ifdef __WINDOWS__
+#ifdef __WXMSW__
wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
#else
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
wxMessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wxOK);
}
-void MyFrame::OnPrintPS(wxCommandEvent& event)
-{
- wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
-
- wxPostScriptPrinter printer;
- MyPrintout printout("My printout");
- printer.Print(this, &printout, TRUE);
-}
-
-void MyFrame::OnPrintPreview(wxCommandEvent& event)
+void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event))
{
-#ifdef __WINDOWS__
+#ifdef __WXMSW__
wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
#else
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
frame->Show(TRUE);
}
-void MyFrame::OnPrintPreviewPS(wxCommandEvent& event)
+void MyFrame::OnPrintSetup(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& event)
-{
-#ifdef __WINDOWS__
+#ifdef __WXMSW__
wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
#else
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
wxPrintData data;
data.SetOrientation(orientation);
-#ifdef __WINDOWS__
+#ifdef __WXMSW__
wxPrintDialog printerDialog(this, & data);
#else
wxGenericPrintDialog printerDialog(this, & data);
orientation = printerDialog.GetPrintData().GetOrientation();
}
-void MyFrame::OnPageSetup(wxCommandEvent& event)
+void MyFrame::OnPageSetup(wxCommandEvent& WXUNUSED(event))
{
-#ifdef __WINDOWS__
+#ifdef __WXMSW__
wxGetApp().SetPrintMode(wxPRINT_WINDOWS);
#else
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
wxPageSetupData data;
data.SetOrientation(orientation);
-#ifdef __WINDOWS__
+#ifdef __WXMSW__
wxPageSetupDialog pageSetupDialog(this, & data);
#else
wxGenericPageSetupDialog pageSetupDialog(this, & data);
orientation = data.GetOrientation();
}
-void MyFrame::OnPrintSetupPS(wxCommandEvent& 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))
+{
+ 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 = printerDialog.GetPrintData().GetOrientation();
}
-void MyFrame::OnPageSetupPS(wxCommandEvent& event)
+void MyFrame::OnPageSetupPS(wxCommandEvent& WXUNUSED(event))
{
wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT);
orientation = pageSetupDialog.GetPageSetupData().GetOrientation();
}
+#endif
-void MyFrame::OnPrintAbout(wxCommandEvent& event)
+
+void MyFrame::OnPrintAbout(wxCommandEvent& WXUNUSED(event))
{
(void)wxMessageBox("wxWindows printing demo\nAuthor: Julian Smart julian.smart@ukonline.co.uk",
"About wxWindows printing demo", wxOK|wxCENTRE);
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.0, 30.0, 200.0, 100.0);
- dc.DrawText("Rectangle 200 by 100", 40.0, 40.0);
+ dc.DrawRectangle(0, 30, 200, 100);
+ dc.DrawText("Rectangle 200 by 100", 40, 40);
- dc.DrawEllipse(50.0, 140.0, 100.0, 50.0);
+ dc.DrawEllipse(50, 140, 100, 50);
- dc.DrawText("Test message: this is in 11 point text", 10.0, 180.0);
+ dc.DrawText("Test message: this is in 10 point text", 10, 180);
- dc.SetPen(wxBLACK_PEN);
- dc.DrawLine(0.0, 0.0, 200.0, 200.0);
- dc.DrawLine(200.0, 0.0, 0.0, 200.0);
+ dc.SetPen(* wxBLACK_PEN);
+ dc.DrawLine(0, 0, 200, 200);
+ dc.DrawLine(200, 0, 0, 200);
+
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
+ wxIcon my_icon( folder_xpm );
+#elif defined(__WXMSW__)
+ wxIcon my_icon( "mondrian" );
+#elif
+#error "Platform not supported."
+#endif
+
+ dc.DrawIcon( my_icon, 100, 100);
}
-void MyFrame::OnSize(wxSizeEvent& event)
+void MyFrame::OnSize(wxSizeEvent& event )
{
wxFrame::OnSize(event);
}
frame->Draw(dc);
}
-void MyCanvas::OnEvent(wxMouseEvent& event)
+void MyCanvas::OnEvent(wxMouseEvent& WXUNUSED(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;
}
char buf[200];
sprintf(buf, "PAGE %d", page);
- dc->DrawText(buf, 10.0, 10.0);
+ dc->DrawText(buf, 10, 10);
return TRUE;
}
// Set the scale and origin
dc->SetUserScale(actualScale, actualScale);
- dc->SetDeviceOrigin(posX, posY);
+ dc->SetDeviceOrigin( (long)posX, (long)posY );
frame->Draw(*dc);
}
// 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.0, 50.0, (float)(50.0 + logUnits), 50.0);
- dc->DrawLine(50.0, 50.0, 50.0, (float)(50.0 + logUnits));
+ 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.0, 200.0);
+ dc->DrawText("Some test text", 200, 200 );
// TESTING
float rightMarginLogical = (float)(logUnitsFactor*(pageWidthMM - rightMargin));
dc->SetPen(wxBLACK_PEN);
- dc->DrawLine(leftMarginLogical, topMarginLogical, rightMarginLogical, topMarginLogical);
- dc->DrawLine(leftMarginLogical, bottomMarginLogical, rightMarginLogical, bottomMarginLogical);
+ dc->DrawLine( (long)leftMarginLogical, (long)topMarginLogical,
+ (long)rightMarginLogical, (long)topMarginLogical);
+ dc->DrawLine( (long)leftMarginLogical, (long)bottomMarginLogical,
+ (long)rightMarginLogical, (long)bottomMarginLogical);
WritePageHeader(this, dc, "A header", logUnitsFactor);
}
// 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);
long xExtent, yExtent;
dc->GetTextExtent(text, &xExtent, &yExtent);
float xPos = (float)(((((pageWidthMM - leftMargin - rightMargin)/2.0)+leftMargin)*mmToLogical) - (xExtent/2.0));
- dc->DrawText(text, (long)xPos, topMarginLogical);
+ dc->DrawText(text, (long)xPos, (long)topMarginLogical);
- dc->SetPen(wxBLACK_PEN);
- dc->DrawLine(leftMarginLogical, topMarginLogical+yExtent, rightMarginLogical, topMarginLogical+yExtent);
+ dc->SetPen(* wxBLACK_PEN);
+ dc->DrawLine( (long)leftMarginLogical, (long)(topMarginLogical+yExtent),
+ (long)rightMarginLogical, (long)topMarginLogical+yExtent );
return TRUE;
}