]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/printing/printing.cpp
Tamil translations update from Dinakar T.D.
[wxWidgets.git] / samples / printing / printing.cpp
index 8bf639ad09cbfc7312f4da0fe9654f8848d2f34d..89ef0ccd8782169228486b25122ab076d2698771 100644 (file)
@@ -4,7 +4,6 @@
 // Author:      Julian Smart
 // Modified by: Francesco Montorsi
 // Created:     1995
-// RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
     #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 <ctype.h>
 #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
 #endif
 
 #ifdef __WXMAC__
-    #include "wx/mac/printdlg.h"
+    #include "wx/osx/printdlg.h"
 #endif
 
 #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
@@ -117,14 +112,12 @@ bool MyApp::OnInit(void)
     // Create the main frame window
     // ----------------------------
 
-    MyFrame* frame = new MyFrame((wxFrame *) NULL, _T("wxWidgets Printing Demo"),
+    MyFrame* frame = new MyFrame((wxFrame *) NULL, wxT("wxWidgets Printing Demo"),
                                  wxPoint(0, 0), wxSize(400, 400));
 
     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,11 +223,17 @@ 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
         gc->SetPen( *wxRED_PEN );
-        gc->SetFont( m_testFont, *wxGREEN );
+
         wxGraphicsPath path = gc->CreatePath();
         path.AddCircle( 50.0, 50.0, 50.0 );
         path.MoveToPoint(0.0, 50.0);
@@ -246,6 +245,17 @@ void MyApp::Draw(wxDC&dc)
 
         gc->StrokePath(path);
 
+        // draw some text
+        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( *wxBLACK_PEN );
+        gc->DrawRectangle(25.0, 60.0, w, h);
+
         delete gc;
     }
 #endif
@@ -262,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)
@@ -272,32 +282,42 @@ 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
     CreateStatusBar(2);
-    SetStatusText(_T("Printing demo"));
+    SetStatusText(wxT("Printing demo"));
 #endif // wxUSE_STATUSBAR
 
     // Load icon and bitmap
-    SetIcon( wxICON( mondrian) );
+    SetIcon( wxICON( sample) );
 
     // Make a menubar
     wxMenu *file_menu = new wxMenu;
 
-    file_menu->Append(wxID_PRINT, _T("&Print..."),                 _T("Print"));
-    file_menu->Append(WXPRINT_PAGE_SETUP, _T("Page Set&up..."),    _T("Page setup"));
+    file_menu->Append(wxID_PRINT, wxT("&Print..."),                 wxT("Print"));
+    file_menu->Append(WXPRINT_PAGE_SETUP, wxT("Page Set&up..."),    wxT("Page setup"));
 #ifdef __WXMAC__
-    file_menu->Append(WXPRINT_PAGE_MARGINS, _T("Page Margins..."), _T("Page margins"));
+    file_menu->Append(WXPRINT_PAGE_MARGINS, wxT("Page Margins..."), wxT("Page margins"));
 #endif
-    file_menu->Append(wxID_PREVIEW, _T("Print Pre&view"),          _T("Preview"));
+    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];
@@ -306,26 +326,26 @@ 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, _T("Print PostScript..."),           _T("Print (PostScript)"));
-    file_menu->Append(WXPRINT_PAGE_SETUP_PS, _T("Page Setup PostScript..."), _T("Page setup (PostScript)"));
-    file_menu->Append(WXPRINT_PREVIEW_PS, _T("Print Preview PostScript"),    _T("Preview (PostScript)"));
+    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)"));
+    file_menu->Append(WXPRINT_PREVIEW_PS, wxT("Print Preview PostScript"),    wxT("Preview (PostScript)"));
 #endif
 
     file_menu->AppendSeparator();
-    file_menu->Append(WXPRINT_ANGLEUP, _T("Angle up\tAlt-U"),                _T("Raise rotated text angle"));
-    file_menu->Append(WXPRINT_ANGLEDOWN, _T("Angle down\tAlt-D"),            _T("Lower rotated text angle"));
+    file_menu->Append(WXPRINT_ANGLEUP, wxT("Angle up\tAlt-U"),                wxT("Raise rotated text angle"));
+    file_menu->Append(WXPRINT_ANGLEDOWN, wxT("Angle down\tAlt-D"),            wxT("Lower rotated text angle"));
     file_menu->AppendSeparator();
-    file_menu->Append(wxID_EXIT, _T("E&xit"),                                _T("Exit program"));
+    file_menu->Append(wxID_EXIT, wxT("E&xit"),                                wxT("Exit program"));
 
     wxMenu *help_menu = new wxMenu;
-    help_menu->Append(wxID_ABOUT, _T("&About"),                              _T("About this demo"));
+    help_menu->Append(wxID_ABOUT, wxT("&About"),                              wxT("About this demo"));
 
     wxMenuBar *menu_bar = new wxMenuBar;
 
-    menu_bar->Append(file_menu, _T("&File"));
-    menu_bar->Append(help_menu, _T("&Help"));
+    menu_bar->Append(file_menu, wxT("&File"));
+    menu_bar->Append(help_menu, wxT("&Help"));
 
     // Associate the menu bar with the frame
     SetMenuBar(menu_bar);
@@ -351,13 +371,17 @@ void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event))
     wxPrintDialogData printDialogData(* g_printData);
 
     wxPrinter printer(&printDialogData);
-    MyPrintout printout(this, _T("My printout"));
+    MyPrintout printout(this, wxT("My printout"));
     if (!printer.Print(this, &printout, true /*prompt*/))
     {
         if (wxPrinter::GetLastError() == wxPRINTER_ERROR)
-            wxLogError(_T("There was a problem printing. Perhaps your current printer is not set correctly?"));
+        {
+            wxLogError(wxT("There was a problem printing. Perhaps your current printer is not set correctly?"));
+        }
         else
-            wxLogMessage(_T("You canceled printing"));
+        {
+            wxLogMessage(wxT("You canceled printing"));
+        }
     }
     else
     {
@@ -374,14 +398,14 @@ void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event))
     if (!preview->IsOk())
     {
         delete preview;
-        wxLogError(_T("There was a problem previewing.\nPerhaps your current printer is not set correctly?"));
+        wxLogError(wxT("There was a problem previewing.\nPerhaps your current printer is not set correctly?"));
         return;
     }
 
     wxPreviewFrame *frame =
-        new wxPreviewFrame(preview, this, _T("Demo Print Preview"), wxPoint(100, 100), wxSize(600, 650));
+        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();
 }
 
@@ -396,23 +420,25 @@ 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(_T("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, _T("Demo Print Preview"), wxPoint(100, 100), wxSize(600, 650));
+        new wxPreviewFrame(preview, this, wxT("Demo Print Preview"), wxPoint(100, 100), wxSize(600, 650));
     frame->Centre(wxBOTH);
     frame->Initialize();
     frame->Show();
@@ -445,8 +471,8 @@ void MyFrame::OnPageMargins(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::OnPrintAbout(wxCommandEvent& WXUNUSED(event))
 {
-    (void)wxMessageBox(_T("wxWidgets printing demo\nAuthor: Julian Smart"),
-                       _T("About wxWidgets printing demo"), wxOK|wxCENTRE);
+    (void)wxMessageBox(wxT("wxWidgets printing demo\nAuthor: Julian Smart"),
+                       wxT("About wxWidgets printing demo"), wxOK|wxCENTRE);
 }
 
 void MyFrame::OnAngleUp(wxCommandEvent& WXUNUSED(event))
@@ -461,6 +487,12 @@ void MyFrame::OnAngleDown(wxCommandEvent& WXUNUSED(event))
     m_canvas->Refresh();
 }
 
+void MyFrame::OnPreviewFrameModalityKind(wxCommandEvent& event)
+{
+    m_previewModality = static_cast<wxPreviewFrameModalityKind>(
+                            wxPreviewFrame_AppModal +
+                                (event.GetId() - WXPRINT_FRAME_MODAL_APP));
+}
 
 // ----------------------------------------------------------------------------
 // MyCanvas
@@ -623,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.
@@ -658,8 +690,8 @@ void MyPrintout::DrawPageTwo()
     dc->SetBrush(*wxTRANSPARENT_BRUSH);
 
     { // GetTextExtent demo:
-        wxString words[7] = { _T("This "), _T("is "), _T("GetTextExtent "),
-                             _T("testing "), _T("string. "), _T("Enjoy "), _T("it!") };
+        wxString words[7] = { wxT("This "), wxT("is "), wxT("GetTextExtent "),
+                             wxT("testing "), wxT("string. "), wxT("Enjoy "), wxT("it!") };
         wxCoord w, h;
         long x = 200, y= 250;
         wxFont fnt(15, wxSWISS, wxNORMAL, wxNORMAL);
@@ -681,7 +713,7 @@ void MyPrintout::DrawPageTwo()
 
     dc->SetFont(wxGetApp().GetTestFont());
 
-    dc->DrawText(_T("Some test text"), 200, 300 );
+    dc->DrawText(wxT("Some test text"), 200, 300 );
 
     // TESTING
 
@@ -704,7 +736,7 @@ void MyPrintout::DrawPageTwo()
     dc->DrawLine( (long)leftMarginLogical, (long)bottomMarginLogical,
         (long)rightMarginLogical,  (long)bottomMarginLogical);
 
-    WritePageHeader(this, dc, _T("A header"), logUnitsFactor);
+    WritePageHeader(this, dc, wxT("A header"), logUnitsFactor);
 }
 
 // Writes a header on a page. Margin units are in millimetres.