X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/34da0970a018b4b0828248028040ca339868ed4e..f234c60c4aac2e077b16b8fbb3009ad45a84c73b:/samples/printing/printing.cpp?ds=inline diff --git a/samples/printing/printing.cpp b/samples/printing/printing.cpp index 02f5594865..4ace50d72a 100644 --- a/samples/printing/printing.cpp +++ b/samples/printing/printing.cpp @@ -22,22 +22,34 @@ #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 #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 = (MyFrame *) NULL; int orientation = wxPORTRAIT; @@ -45,10 +57,6 @@ int orientation = wxPORTRAIT; // Main proc IMPLEMENT_APP(MyApp) -#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); @@ -69,12 +77,7 @@ bool MyApp::OnInit(void) frame->CreateStatusBar(2); // Load icon and bitmap -#ifdef __WXMSW__ - frame->SetIcon(wxIcon("mondrian")); -#endif -#ifdef __X__ -// frame->SetIcon(wxIcon(mondrian_bits, mondrian_width, mondrian_height)); -#endif + frame->SetIcon( wxICON( mondrian) ); // Make a menubar wxMenu *file_menu = new wxMenu; @@ -84,7 +87,13 @@ bool MyApp::OnInit(void) 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)"); @@ -122,17 +131,25 @@ bool MyApp::OnInit(void) return TRUE; } +int MyApp::OnExit() +{ + delete wxGetApp().m_testFont; + return 1; +} + BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(WXPRINT_QUIT, MyFrame::OnExit) EVT_MENU(WXPRINT_PRINT, MyFrame::OnPrint) 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 @@ -149,33 +166,14 @@ 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); @@ -194,36 +192,13 @@ void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event)) 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(); @@ -232,29 +207,39 @@ void MyFrame::OnPrintSetup(wxCommandEvent& WXUNUSED(event)) 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); @@ -267,8 +252,6 @@ void MyFrame::OnPrintSetupPS(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnPageSetupPS(wxCommandEvent& WXUNUSED(event)) { - wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT); - wxPageSetupData data; data.SetOrientation(orientation); @@ -277,6 +260,8 @@ void MyFrame::OnPageSetupPS(wxCommandEvent& WXUNUSED(event)) orientation = pageSetupDialog.GetPageSetupData().GetOrientation(); } +#endif + void MyFrame::OnPrintAbout(wxCommandEvent& WXUNUSED(event)) { @@ -304,13 +289,7 @@ void MyFrame::Draw(wxDC& dc) dc.DrawLine(0, 0, 200, 200); dc.DrawLine(200, 0, 0, 200); -#if defined(__WXGTK__) - wxIcon my_icon( folder_xpm ); -#elif defined(__WXMSW__) - wxIcon my_icon( "mondrian" ); -#elif -#error "Platform not supported." -#endif + wxIcon my_icon = wxICON(mondrian) ; dc.DrawIcon( my_icon, 100, 100); } @@ -344,14 +323,6 @@ void MyCanvas::OnEvent(wxMouseEvent& WXUNUSED(event)) { } -bool MyFrame::OnClose(void) -{ - Show(FALSE); - delete wxGetApp().m_testFont; - - return TRUE; -} - bool MyPrintout::OnPrintPage(int page) { wxDC *dc = GetDC(); @@ -363,6 +334,7 @@ bool MyPrintout::OnPrintPage(int page) DrawPageTwo(dc); dc->SetDeviceOrigin(0, 0); + dc->SetUserScale(1.0, 1.0); char buf[200]; sprintf(buf, "PAGE %d", page); @@ -479,8 +451,8 @@ void MyPrintout::DrawPageTwo(wxDC *dc) 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->DrawLine(50, 250, (long)(50.0 + logUnits), 250); + dc->DrawLine(50, 250, 50, (long)(250.0 + logUnits)); dc->SetFont(* wxGetApp().m_testFont); dc->SetBackgroundMode(wxTRANSPARENT); @@ -502,7 +474,7 @@ void MyPrintout::DrawPageTwo(wxDC *dc) 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, @@ -514,12 +486,14 @@ void MyPrintout::DrawPageTwo(wxDC *dc) // Writes a header on a page. Margin units are in millimetres. bool WritePageHeader(wxPrintout *printout, wxDC *dc, char *text, float mmToLogical) { +/* static wxFont *headerFont = (wxFont *) NULL; if (!headerFont) { headerFont = wxTheFontList->FindOrCreateFont(16, wxSWISS, wxNORMAL, wxBOLD); } dc->SetFont(headerFont); +*/ int pageWidthMM, pageHeightMM;