]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/printing/printing.cpp
Initial checkin of the wxFrame support added by Aleks G.
[wxWidgets.git] / samples / printing / printing.cpp
index f76894eb4f9ceabddcf513b035bb790cf0e991f8..45703a7f3d61e3a35628cce8a54cd367e7264e25 100644 (file)
@@ -1,13 +1,13 @@
-/*
-* File:        printing.cc
-* Purpose:     Printing demo for wxWindows class library
-* Author:      Julian Smart
-* Created:     1995
-* Updated:     
-* Copyright:   (c) 1995, AIAI, University of Edinburgh
-*/
-
-/* static const char sccsid[] = "%W% %G%"; */
+/////////////////////////////////////////////////////////////////////////////
+// Name:        printing.cpp
+// Purpose:     Printing demo for wxWindows
+// Author:      Julian Smart
+// Modified by:
+// Created:     1995
+// RCS-ID:      $Id$
+// Copyright:   (c) Julian Smart
+// Licence:     wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
 #pragma implementation
@@ -104,12 +104,14 @@ bool MyApp::OnInit(void)
     file_menu->Append(WXPRINT_PAGE_SETUP, "Page Set&up...",              "Page setup");
     file_menu->Append(WXPRINT_PREVIEW, "Print Pre&view",              "Preview");
     
+#if wxUSE_ACCEL
     // Accelerators
     wxAcceleratorEntry entries[1];
     entries[0].Set(wxACCEL_CTRL, (int) 'V', WXPRINT_PREVIEW);
     wxAcceleratorTable accel(1, entries);
     frame->SetAcceleratorTable(accel);
-    
+#endif
+
 #if defined(__WXMSW__) && wxTEST_POSTSCRIPT_IN_MSW
     file_menu->AppendSeparator();
     file_menu->Append(WXPRINT_PRINT_PS, "Print PostScript...",              "Print (PostScript)");
@@ -190,7 +192,12 @@ void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event))
     wxPrinter printer(& printDialogData);
     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);
+    {
+        if (wxPrinter::GetLastError() == wxPRINTER_ERROR)
+            wxMessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wxOK);
+        else
+            wxMessageBox("You canceled printing", "Printing", wxOK);
+    }
     else
     {
         (*g_printData) = printer.GetPrintDialogData().GetPrintData();
@@ -290,6 +297,8 @@ void MyFrame::OnPrintAbout(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::Draw(wxDC& dc)
 {
+    dc.SetBackground(*wxWHITE_BRUSH);
+    dc.Clear();
     dc.SetFont(* wxGetApp().m_testFont);
     
     dc.SetBackgroundMode(wxTRANSPARENT);
@@ -479,6 +488,22 @@ void MyPrintout::DrawPageTwo(wxDC *dc)
     
     dc->DrawText("Some test text", 200, 200 );
     
+    { // GetTextExtent demo:
+        wxString words[7] = {"This ", "is ", "GetTextExtent ", "testing ", "string. ", "Enjoy ", "it!"};
+        long w, h;
+        long x = 200, y= 250;
+        wxFont fnt(15, wxSWISS, wxNORMAL, wxNORMAL);
+        
+        dc->SetFont(fnt);
+        for (int i = 0; i < 7; i++) {
+            dc->GetTextExtent(words[i], &w, &h);
+            dc->DrawRectangle(x, y, w, h);
+            dc->DrawText(words[i], x, y);
+            x += w;
+        }
+        dc->SetFont(* wxGetApp().m_testFont);
+    }
+    
     // TESTING
     
     int leftMargin = 20;