X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a5e40d85a477a366182d9364130d4c604c403092..8abbca789f34f98efa79944b1c4f6423dade2c80:/samples/printing/printing.cpp diff --git a/samples/printing/printing.cpp b/samples/printing/printing.cpp index 4b15b80930..89ef0ccd87 100644 --- a/samples/printing/printing.cpp +++ b/samples/printing/printing.cpp @@ -4,7 +4,6 @@ // Author: Julian Smart // Modified by: Francesco Montorsi // Created: 1995 -// RCS-ID: $Id$ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -25,10 +24,6 @@ #error "You must set wxUSE_PRINTING_ARCHITECTURE to 1 in setup.h, and recompile the library." #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" @@ -36,7 +31,7 @@ #include "wx/image.h" #include "wx/accel.h" -#if wxTEST_POSTSCRIPT_IN_MSW +#if wxUSE_POSTSCRIPT #include "wx/generic/printps.h" #include "wx/generic/prntdlgg.h" #endif @@ -51,8 +46,8 @@ #include "printing.h" -#ifndef __WXMSW__ - #include "mondrian.xpm" +#ifndef wxHAS_IMAGES_IN_RESOURCES + #include "../sample.xpm" #endif // Global print data, to remember settings during the session @@ -123,8 +118,6 @@ bool MyApp::OnInit(void) frame->Centre(wxBOTH); frame->Show(); - SetTopWindow(frame); - return true; } @@ -163,7 +156,7 @@ void MyApp::Draw(wxDC&dc) dc.DrawText( wxT("Rectangle 200 by 80"), 40, 40); - dc.SetPen( wxPen(*wxBLACK,0,wxDOT_DASH) ); + dc.SetPen( wxPen(*wxBLACK, 0, wxPENSTYLE_DOT_DASH) ); dc.DrawEllipse(50, 140, 100, 50); dc.SetPen(*wxRED_PEN); @@ -212,7 +205,7 @@ void MyApp::Draw(wxDC&dc) str.Printf( wxT("---- Text at angle %d ----"), i ); dc.DrawRotatedText( str, 100, 300, i ); - wxIcon my_icon = wxICON(mondrian); + wxIcon my_icon = wxICON(sample); dc.DrawIcon( my_icon, 100, 100); @@ -230,6 +223,12 @@ void MyApp::Draw(wxDC&dc) if (window_dc) gc = wxGraphicsContext::Create( *window_dc ); +#ifdef __WXMSW__ + wxEnhMetaFileDC *emf_dc = wxDynamicCast( &dc, wxEnhMetaFileDC ); + if (emf_dc) + gc = wxGraphicsContext::Create( *emf_dc ); +#endif + if (gc) { // make a path that contains a circle and some lines, centered at 100,100 @@ -247,15 +246,15 @@ void MyApp::Draw(wxDC&dc) gc->StrokePath(path); // draw some text - wxString text("This text is drawn by wxGraphicsContext"); - gc->SetFont( m_testFont, *wxBLUE ); - gc->DrawText(text, 50.0, 50.0); + wxString text("Text by wxGraphicsContext"); + gc->SetFont( m_testFont, *wxBLACK ); + gc->DrawText(text, 25.0, 60.0); // draw rectangle around the text double w, h, d, el; gc->GetTextExtent(text, &w, &h, &d, &el); - gc->SetPen( *wxBLUE_PEN ); - gc->DrawRectangle(50.0, 50.0, w, h); + gc->SetPen( *wxBLACK_PEN ); + gc->DrawRectangle(25.0, 60.0, w, h); delete gc; } @@ -273,7 +272,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(wxID_PREVIEW, MyFrame::OnPrintPreview) EVT_MENU(WXPRINT_PAGE_SETUP, MyFrame::OnPageSetup) EVT_MENU(wxID_ABOUT, MyFrame::OnPrintAbout) -#if defined(__WXMSW__) &&wxTEST_POSTSCRIPT_IN_MSW +#if wxUSE_POSTSCRIPT EVT_MENU(WXPRINT_PRINT_PS, MyFrame::OnPrintPS) EVT_MENU(WXPRINT_PREVIEW_PS, MyFrame::OnPrintPreviewPS) EVT_MENU(WXPRINT_PAGE_SETUP_PS, MyFrame::OnPageSetupPS) @@ -283,12 +282,17 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) #endif EVT_MENU(WXPRINT_ANGLEUP, MyFrame::OnAngleUp) EVT_MENU(WXPRINT_ANGLEDOWN, MyFrame::OnAngleDown) + + EVT_MENU_RANGE(WXPRINT_FRAME_MODAL_APP, + WXPRINT_FRAME_MODAL_NON, + MyFrame::OnPreviewFrameModalityKind) END_EVENT_TABLE() MyFrame::MyFrame(wxFrame *frame, const wxString&title, const wxPoint&pos, const wxSize&size) : wxFrame(frame, wxID_ANY, title, pos, size) { m_canvas = NULL; + m_previewModality = wxPreviewFrame_AppModal; #if wxUSE_STATUSBAR // Give us a status line @@ -297,7 +301,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString&title, const wxPoint&pos, const #endif // wxUSE_STATUSBAR // Load icon and bitmap - SetIcon( wxICON( mondrian) ); + SetIcon( wxICON( sample) ); // Make a menubar wxMenu *file_menu = new wxMenu; @@ -309,6 +313,11 @@ MyFrame::MyFrame(wxFrame *frame, const wxString&title, const wxPoint&pos, const #endif file_menu->Append(wxID_PREVIEW, wxT("Print Pre&view"), wxT("Preview")); + wxMenu * const menuModalKind = new wxMenu; + menuModalKind->AppendRadioItem(WXPRINT_FRAME_MODAL_APP, "&App modal"); + menuModalKind->AppendRadioItem(WXPRINT_FRAME_MODAL_WIN, "&Window modal"); + menuModalKind->AppendRadioItem(WXPRINT_FRAME_MODAL_NON, "&Not modal"); + file_menu->AppendSubMenu(menuModalKind, "Preview frame &modal kind"); #if wxUSE_ACCEL // Accelerators wxAcceleratorEntry entries[1]; @@ -317,7 +326,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString&title, const wxPoint&pos, const SetAcceleratorTable(accel); #endif -#if defined(__WXMSW__) &&wxTEST_POSTSCRIPT_IN_MSW +#if wxUSE_POSTSCRIPT file_menu->AppendSeparator(); file_menu->Append(WXPRINT_PRINT_PS, wxT("Print PostScript..."), wxT("Print (PostScript)")); file_menu->Append(WXPRINT_PAGE_SETUP_PS, wxT("Page Setup PostScript..."), wxT("Page setup (PostScript)")); @@ -396,7 +405,7 @@ void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event)) wxPreviewFrame *frame = new wxPreviewFrame(preview, this, wxT("Demo Print Preview"), wxPoint(100, 100), wxSize(600, 650)); frame->Centre(wxBOTH); - frame->Initialize(); + frame->InitializeWithModality(m_previewModality); frame->Show(); } @@ -411,21 +420,23 @@ void MyFrame::OnPageSetup(wxCommandEvent& WXUNUSED(event)) (*g_pageSetupData) = pageSetupDialog.GetPageSetupDialogData(); } -#if defined(__WXMSW__) && wxTEST_POSTSCRIPT_IN_MSW +#if wxUSE_POSTSCRIPT void MyFrame::OnPrintPS(wxCommandEvent& WXUNUSED(event)) { - wxPostScriptPrinter printer(g_printData); - MyPrintout printout(wxT("My printout")); + wxPrintDialogData printDialogData(* g_printData); + + wxPostScriptPrinter printer(&printDialogData); + MyPrintout printout(this, wxT("My printout")); printer.Print(this, &printout, true/*prompt*/); - (*g_printData) = printer.GetPrintData(); + (*g_printData) = printer.GetPrintDialogData().GetPrintData(); } void MyFrame::OnPrintPreviewPS(wxCommandEvent& WXUNUSED(event)) { // Pass two printout objects: for preview, and possible printing. wxPrintDialogData printDialogData(* g_printData); - wxPrintPreview *preview = new wxPrintPreview(new MyPrintout, new MyPrintout, &printDialogData); + wxPrintPreview *preview = new wxPrintPreview(new MyPrintout(this), new MyPrintout(this), &printDialogData); wxPreviewFrame *frame = new wxPreviewFrame(preview, this, wxT("Demo Print Preview"), wxPoint(100, 100), wxSize(600, 650)); frame->Centre(wxBOTH); @@ -476,6 +487,12 @@ void MyFrame::OnAngleDown(wxCommandEvent& WXUNUSED(event)) m_canvas->Refresh(); } +void MyFrame::OnPreviewFrameModalityKind(wxCommandEvent& event) +{ + m_previewModality = static_cast( + wxPreviewFrame_AppModal + + (event.GetId() - WXPRINT_FRAME_MODAL_APP)); +} // ---------------------------------------------------------------------------- // MyCanvas @@ -638,7 +655,7 @@ void MyPrintout::DrawPageTwo() int ppiPrinterX, ppiPrinterY; GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); - // This scales the DC so that the printout roughly represents the the screen + // This scales the DC so that the printout roughly represents the screen // scaling. The text point size _should_ be the right size but in fact is // too small for some reason. This is a detail that will need to be // addressed at some point but can be fudged for the moment.