]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/printing/printing.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml sample: wxHtmlEasyPrinting test
4 // Author: Vaclav Slavik
6 // Copyright: (c) 1998-2009 wxWidgets team
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
18 // for all others, include the necessary headers (this file is usually all you
19 // need because it includes almost all "standard" wxWidgets headers
25 #include "wx/html/htmlwin.h"
26 #include "wx/html/htmprint.h"
29 #include "../../sample.xpm"
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 // Define a new application type, each program should derive a class from wxApp
38 class MyApp
: public wxApp
41 // override base class virtuals
42 // ----------------------------
44 // this one is called on application startup and is a good place for the app
45 // initialization (doing it here and not in the ctor allows to have an error
46 // return: if OnInit() returns false, the application terminates)
48 virtual bool OnInit();
51 // Define a new frame type: this is going to be our main frame
52 class MyFrame
: public wxFrame
57 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
60 // event handlers (these functions should _not_ be virtual)
61 void OnQuit(wxCommandEvent
& event
);
62 void OnAbout(wxCommandEvent
& event
);
64 void OnPageSetup(wxCommandEvent
& event
);
65 void OnPrint(wxCommandEvent
& event
);
66 void OnPreview(wxCommandEvent
& event
);
67 void OnOpen(wxCommandEvent
& event
);
69 void OnPrintSmall(wxCommandEvent
& event
);
70 void OnPrintNormal(wxCommandEvent
& event
);
71 void OnPrintHuge(wxCommandEvent
& event
);
76 wxHtmlEasyPrinting
*m_Prn
;
79 // any class wishing to process wxWidgets events must use this macro
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 // IDs for the controls and the menu commands
102 // ----------------------------------------------------------------------------
103 // event tables and other macros for wxWidgets
104 // ----------------------------------------------------------------------------
106 // the event tables connect the wxWidgets events with the functions (event
107 // handlers) which process them. It can be also done at run-time, but for the
108 // simple menu events like this the static method is much simpler.
109 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
110 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
111 EVT_MENU(wxID_ABOUT
, MyFrame::OnAbout
)
112 EVT_MENU(Minimal_Print
, MyFrame::OnPrint
)
113 EVT_MENU(Minimal_Preview
, MyFrame::OnPreview
)
114 EVT_MENU(Minimal_PageSetup
, MyFrame::OnPageSetup
)
115 EVT_MENU(Minimal_Open
, MyFrame::OnOpen
)
116 EVT_MENU(Minimal_PrintSmall
, MyFrame::OnPrintSmall
)
117 EVT_MENU(Minimal_PrintNormal
, MyFrame::OnPrintNormal
)
118 EVT_MENU(Minimal_PrintHuge
, MyFrame::OnPrintHuge
)
121 // Create a new application object: this macro will allow wxWidgets to create
122 // the application object during program execution (it's better than using a
123 // static object for many reasons) and also declares the accessor function
124 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
128 // ============================================================================
130 // ============================================================================
132 // ----------------------------------------------------------------------------
133 // the application class
134 // ----------------------------------------------------------------------------
135 // `Main program' equivalent: the program execution "starts" here
139 if ( !wxApp::OnInit() )
143 wxImage::AddHandler(new wxPNGHandler
);
146 wxImage::AddHandler(new wxJPEGHandler
);
149 wxImage::AddHandler(new wxGIFHandler
);
152 MyFrame
*frame
= new MyFrame(_("Printing test"),
153 wxDefaultPosition
, wxSize(640, 480));
155 // Show it and tell the application that it's our main window
156 // @@@ what does it do exactly, in fact? is it necessary here?
161 // success: wxApp::OnRun() will be called which will enter the main message
162 // loop and the application will run. If we returned false here, the
163 // application would exit immediately.
167 // ----------------------------------------------------------------------------
169 // ----------------------------------------------------------------------------
173 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
174 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
176 SetIcon(wxICON(sample
));
179 wxMenu
*menuFile
= new wxMenu
;
180 menuFile
->Append(Minimal_Open
, _("Open...\tCtrl-O"));
181 menuFile
->AppendSeparator();
182 menuFile
->Append(Minimal_PageSetup
, _("Page &Setup"));
183 menuFile
->Append(Minimal_Preview
, _("Print pre&view..."));
184 menuFile
->Append(Minimal_Print
, _("Print...\tCtrl-P"));
185 menuFile
->AppendSeparator();
186 menuFile
->Append(wxID_ABOUT
, _("&About"));
187 menuFile
->AppendSeparator();
188 menuFile
->Append(Minimal_Quit
, _("&Exit"));
190 wxMenu
*menuFonts
= new wxMenu
;
191 menuFonts
->AppendRadioItem(Minimal_PrintSmall
, _("&Small Printer Fonts"));
192 menuFonts
->AppendRadioItem(Minimal_PrintNormal
, _("&Normal Printer Fonts"));
193 menuFonts
->AppendRadioItem(Minimal_PrintHuge
, _("&Huge Printer Fonts"));
195 // now append the freshly created menu to the menu bar...
196 wxMenuBar
*menuBar
= new wxMenuBar
;
197 menuBar
->Append(menuFile
, _("&File"));
198 menuBar
->Append(menuFonts
, _("F&onts"));
200 // ... and attach this menu bar to the frame
205 #endif // wxUSE_STATUSBAR
207 m_Html
= new wxHtmlWindow(this);
208 m_Html
-> SetRelatedFrame(this, _("HTML : %s"));
210 m_Html
-> SetRelatedStatusBar(0);
211 #endif // wxUSE_STATUSBAR
212 m_Name
= wxT("test.htm");
213 m_Html
-> LoadPage(m_Name
);
215 m_Prn
= new wxHtmlEasyPrinting(_("Easy Printing Demo"), this);
216 m_Prn
-> SetHeader(m_Name
+ wxT("(@PAGENUM@/@PAGESCNT@)<hr>"), wxPAGE_ALL
);
218 // To specify where the AFM files are kept on Unix,
219 // you may wish to do something like this
220 // m_Prn->GetPrintData()->SetFontMetricPath(wxT("/home/julians/afm"));
227 m_Prn
= (wxHtmlEasyPrinting
*) NULL
;
233 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
235 // true is to force the frame to close
240 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
242 wxMessageBox(_("HTML printing sample\n\n(c) Vaclav Slavik, 1999"));
246 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
248 m_Prn
-> PageSetup();
252 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
254 m_Prn
-> PrintFile(m_Name
);
258 void MyFrame::OnPreview(wxCommandEvent
& WXUNUSED(event
))
260 m_Prn
-> PreviewFile(m_Name
);
264 void MyFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
266 wxFileDialog
dialog(this, _("Open HTML page"), wxT(""), wxT(""), wxT("*.htm"), 0);
268 if (dialog
.ShowModal() == wxID_OK
)
270 m_Name
= dialog
.GetPath();
271 m_Html
-> LoadPage(m_Name
);
272 m_Prn
-> SetHeader(m_Name
+ wxT("(@PAGENUM@/@PAGESCNT@)<hr>"), wxPAGE_ALL
);
277 void MyFrame::OnPrintSmall(wxCommandEvent
& WXUNUSED(event
))
279 m_Prn
->SetStandardFonts(8);
282 void MyFrame::OnPrintNormal(wxCommandEvent
& WXUNUSED(event
))
284 m_Prn
->SetStandardFonts(12);
287 void MyFrame::OnPrintHuge(wxCommandEvent
& WXUNUSED(event
))
289 m_Prn
->SetStandardFonts(28);