X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a4294b7832a5aed3c1cccc06aecd227d43da8830..f234c60c4aac2e077b16b8fbb3009ad45a84c73b:/samples/printing/printing.cpp?ds=sidebyside diff --git a/samples/printing/printing.cpp b/samples/printing/printing.cpp index af82cf63d8..4ace50d72a 100644 --- a/samples/printing/printing.cpp +++ b/samples/printing/printing.cpp @@ -22,7 +22,6 @@ #ifndef WX_PRECOMP #include "wx/wx.h" -#include "wx/postscrp.h" #endif #if !wxUSE_PRINTING_ARCHITECTURE @@ -38,6 +37,8 @@ #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" @@ -45,6 +46,10 @@ #include "printing.h" +#ifndef __WXMSW__ +#include "mondrian.xpm" +#endif + // Declare a frame MyFrame *frame = (MyFrame *) NULL; int orientation = wxPORTRAIT; @@ -52,10 +57,6 @@ int orientation = wxPORTRAIT; // Main proc IMPLEMENT_APP(MyApp) -#if defined(__WXGTK__) || defined(__WXMOTIF__) -#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); @@ -76,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; @@ -91,6 +87,12 @@ bool MyApp::OnInit(void) file_menu->Append(WXPRINT_PAGE_SETUP, "Page Set&up...", "Page setup"); file_menu->Append(WXPRINT_PREVIEW, "Print Pre&view", "Preview"); + // 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)"); @@ -129,6 +131,12 @@ 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) @@ -158,11 +166,6 @@ 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)) @@ -171,11 +174,6 @@ void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event)) { -#ifdef __WXMSW__ - wxGetApp().SetPrintMode(wxPRINT_WINDOWS); -#else - wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT); -#endif wxPrintData printData; printData.SetOrientation(orientation); @@ -196,19 +194,11 @@ void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event)) 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(); @@ -217,19 +207,10 @@ 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(); @@ -239,8 +220,6 @@ void MyFrame::OnPageSetup(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); @@ -248,8 +227,6 @@ void MyFrame::OnPrintPS(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event)) { - wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT); - wxPrintData printData; printData.SetOrientation(orientation); @@ -263,8 +240,6 @@ void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnPrintSetupPS(wxCommandEvent& WXUNUSED(event)) { - wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT); - wxPrintData data; data.SetOrientation(orientation); @@ -277,8 +252,6 @@ void MyFrame::OnPrintSetupPS(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnPageSetupPS(wxCommandEvent& WXUNUSED(event)) { - wxGetApp().SetPrintMode(wxPRINT_POSTSCRIPT); - wxPageSetupData data; data.SetOrientation(orientation); @@ -316,13 +289,7 @@ void MyFrame::Draw(wxDC& dc) 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 + wxIcon my_icon = wxICON(mondrian) ; dc.DrawIcon( my_icon, 100, 100); } @@ -356,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(); @@ -375,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); @@ -491,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); @@ -514,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, @@ -526,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;