]> git.saurik.com Git - wxWidgets.git/blame - samples/html/printing/printing.cpp
Updating OpenVMS compile configuration
[wxWidgets.git] / samples / html / printing / printing.cpp
CommitLineData
3ce369e6 1/////////////////////////////////////////////////////////////////////////////
197ab43d
FM
2// Name: printing.cpp
3// Purpose: wxHtml sample: wxHtmlEasyPrinting test
4// Author: ?
5// Modified by:
6// Created: ?
7// RCS-ID: $Id$
8// Copyright: (c) wxWidgets team
9// Licence: wxWindows licence
3ce369e6
VS
10/////////////////////////////////////////////////////////////////////////////
11
5526e819
VS
12
13// For compilers that support precompilation, includes "wx/wx.h".
92a19c2e 14#include "wx/wxprec.h"
5526e819
VS
15
16#ifdef __BORLANDC__
17#pragma hdrstop
18#endif
19
3ce369e6 20// for all others, include the necessary headers (this file is usually all you
be5a51fb 21// need because it includes almost all "standard" wxWidgets headers
5526e819 22#ifndef WX_PRECOMP
67547666 23#include "wx/wx.h"
5526e819
VS
24#endif
25
67547666
GD
26#include "wx/image.h"
27#include "wx/html/htmlwin.h"
28#include "wx/html/htmprint.h"
5526e819 29
197ab43d
FM
30#ifndef __WXMSW__
31 #include "../../sample.xpm"
32#endif
33
5526e819 34
3ce369e6
VS
35// ----------------------------------------------------------------------------
36// private classes
37// ----------------------------------------------------------------------------
5526e819 38
3ce369e6
VS
39// Define a new application type, each program should derive a class from wxApp
40class MyApp : public wxApp
41{
197ab43d
FM
42public:
43 // override base class virtuals
44 // ----------------------------
5526e819 45
197ab43d
FM
46 // this one is called on application startup and is a good place for the app
47 // initialization (doing it here and not in the ctor allows to have an error
48 // return: if OnInit() returns false, the application terminates)
5526e819 49
197ab43d 50 virtual bool OnInit();
3ce369e6 51};
5526e819 52
3ce369e6
VS
53// Define a new frame type: this is going to be our main frame
54class MyFrame : public wxFrame
55{
197ab43d
FM
56public:
57 // ctor and dtor
58
59 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
60 virtual ~MyFrame();
61
62 // event handlers (these functions should _not_ be virtual)
63 void OnQuit(wxCommandEvent& event);
64 void OnAbout(wxCommandEvent& event);
65
66 void OnPageSetup(wxCommandEvent& event);
67 void OnPrint(wxCommandEvent& event);
68 void OnPreview(wxCommandEvent& event);
69 void OnOpen(wxCommandEvent& event);
70
71 void OnPrintSmall(wxCommandEvent& event);
72 void OnPrintNormal(wxCommandEvent& event);
73 void OnPrintHuge(wxCommandEvent& event);
74
75
76private:
77 wxHtmlWindow *m_Html;
78 wxHtmlEasyPrinting *m_Prn;
79 wxString m_Name;
80
81 // any class wishing to process wxWidgets events must use this macro
82 DECLARE_EVENT_TABLE()
3ce369e6
VS
83};
84
85// ----------------------------------------------------------------------------
86// constants
87// ----------------------------------------------------------------------------
88
89// IDs for the controls and the menu commands
90enum
91{
92 // menu items
93 Minimal_Quit = 1,
3ce369e6
VS
94 Minimal_Print,
95 Minimal_Preview,
96 Minimal_PageSetup,
4eecf115
VS
97 Minimal_Open,
98 Minimal_PrintSmall,
99 Minimal_PrintNormal,
100 Minimal_PrintHuge
3ce369e6
VS
101
102};
103
104// ----------------------------------------------------------------------------
be5a51fb 105// event tables and other macros for wxWidgets
3ce369e6
VS
106// ----------------------------------------------------------------------------
107
be5a51fb 108// the event tables connect the wxWidgets events with the functions (event
3ce369e6
VS
109// handlers) which process them. It can be also done at run-time, but for the
110// simple menu events like this the static method is much simpler.
111BEGIN_EVENT_TABLE(MyFrame, wxFrame)
112 EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
aec18ff7 113 EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
3ce369e6
VS
114 EVT_MENU(Minimal_Print, MyFrame::OnPrint)
115 EVT_MENU(Minimal_Preview, MyFrame::OnPreview)
116 EVT_MENU(Minimal_PageSetup, MyFrame::OnPageSetup)
3ce369e6 117 EVT_MENU(Minimal_Open, MyFrame::OnOpen)
4eecf115
VS
118 EVT_MENU(Minimal_PrintSmall, MyFrame::OnPrintSmall)
119 EVT_MENU(Minimal_PrintNormal, MyFrame::OnPrintNormal)
120 EVT_MENU(Minimal_PrintHuge, MyFrame::OnPrintHuge)
3ce369e6 121END_EVENT_TABLE()
5526e819 122
be5a51fb 123// Create a new application object: this macro will allow wxWidgets to create
3ce369e6
VS
124// the application object during program execution (it's better than using a
125// static object for many reasons) and also declares the accessor function
126// wxGetApp() which will return the reference of the right type (i.e. MyApp and
127// not wxApp)
5526e819
VS
128IMPLEMENT_APP(MyApp)
129
3ce369e6
VS
130// ============================================================================
131// implementation
132// ============================================================================
5526e819 133
3ce369e6
VS
134// ----------------------------------------------------------------------------
135// the application class
136// ----------------------------------------------------------------------------
137// `Main program' equivalent: the program execution "starts" here
9f37db42 138
3ce369e6 139bool MyApp::OnInit()
5526e819 140{
45e6e6f8
VZ
141 if ( !wxApp::OnInit() )
142 return false;
143
3ce369e6
VS
144#if wxUSE_LIBPNG
145 wxImage::AddHandler(new wxPNGHandler);
146#endif
147#if wxUSE_LIBJPEG
148 wxImage::AddHandler(new wxJPEGHandler);
149#endif
150#if wxUSE_GIF
151 wxImage::AddHandler(new wxGIFHandler);
152#endif
5526e819 153
2b5f62a0 154 MyFrame *frame = new MyFrame(_("Printing test"),
16f26dad 155 wxDefaultPosition, wxSize(640, 480));
5526e819 156
3ce369e6
VS
157 // Show it and tell the application that it's our main window
158 // @@@ what does it do exactly, in fact? is it necessary here?
348469c2 159 frame->Show(true);
3ce369e6 160 SetTopWindow(frame);
5526e819 161
5526e819 162
3ce369e6 163 // success: wxApp::OnRun() will be called which will enter the main message
348469c2 164 // loop and the application will run. If we returned false here, the
3ce369e6 165 // application would exit immediately.
348469c2 166 return true;
3ce369e6 167}
5526e819 168
3ce369e6
VS
169// ----------------------------------------------------------------------------
170// main frame
171// ----------------------------------------------------------------------------
5526e819 172
5526e819 173
3ce369e6
VS
174// frame constructor
175MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
348469c2 176 : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
3ce369e6 177{
197ab43d
FM
178 SetIcon(wxICON(sample));
179
3ce369e6
VS
180 // create a menu bar
181 wxMenu *menuFile = new wxMenu;
2b5f62a0 182 menuFile->Append(Minimal_Open, _("Open...\tCtrl-O"));
3ce369e6 183 menuFile->AppendSeparator();
2b5f62a0 184 menuFile->Append(Minimal_PageSetup, _("Page Setup"));
2b5f62a0
VZ
185 menuFile->Append(Minimal_Print, _("Print..."));
186 menuFile->Append(Minimal_Preview, _("Preview..."));
3ce369e6 187 menuFile->AppendSeparator();
2b5f62a0 188 menuFile->Append(wxID_ABOUT, _("&About"));
3ce369e6 189 menuFile->AppendSeparator();
2b5f62a0 190 menuFile->Append(Minimal_Quit, _("&Exit"));
3ce369e6 191
4eecf115
VS
192 wxMenu *testFile = new wxMenu;
193 testFile->Append(Minimal_PrintSmall, _("Small Printer Fonts"));
194 testFile->Append(Minimal_PrintNormal, _("Normal Printer Fonts"));
195 testFile->Append(Minimal_PrintHuge, _("Huge Printer Fonts"));
197ab43d 196
3ce369e6
VS
197 // now append the freshly created menu to the menu bar...
198 wxMenuBar *menuBar = new wxMenuBar;
2b5f62a0 199 menuBar->Append(menuFile, _("&File"));
4eecf115 200 menuBar->Append(testFile, _("&Test"));
3ce369e6
VS
201
202 // ... and attach this menu bar to the frame
203 SetMenuBar(menuBar);
204
8520f137 205#if wxUSE_STATUSBAR
3ce369e6 206 CreateStatusBar(1);
8520f137 207#endif // wxUSE_STATUSBAR
3ce369e6
VS
208
209 m_Html = new wxHtmlWindow(this);
2b5f62a0 210 m_Html -> SetRelatedFrame(this, _("HTML : %s"));
8520f137 211#if wxUSE_STATUSBAR
3ce369e6 212 m_Html -> SetRelatedStatusBar(0);
8520f137 213#endif // wxUSE_STATUSBAR
2b5f62a0 214 m_Name = wxT("test.htm");
3ce369e6 215 m_Html -> LoadPage(m_Name);
197ab43d 216
2b5f62a0
VZ
217 m_Prn = new wxHtmlEasyPrinting(_("Easy Printing Demo"), this);
218 m_Prn -> SetHeader(m_Name + wxT("(@PAGENUM@/@PAGESCNT@)<hr>"), wxPAGE_ALL);
4eecf115 219
d66699e2
JS
220 // To specify where the AFM files are kept on Unix,
221 // you may wish to do something like this
222 // m_Prn->GetPrintData()->SetFontMetricPath(wxT("/home/julians/afm"));
5526e819
VS
223}
224
2f6c54eb
VZ
225// frame destructor
226MyFrame::~MyFrame()
227{
228 delete m_Prn;
229 m_Prn = (wxHtmlEasyPrinting *) NULL;
230}
231
5526e819 232
3ce369e6 233// event handlers
5526e819 234
3ce369e6 235void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
5526e819 236{
348469c2
WS
237 // true is to force the frame to close
238 Close(true);
5526e819
VS
239}
240
5526e819 241
3ce369e6 242void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
5526e819 243{
2b5f62a0 244 wxMessageBox(_("HTML printing sample\n\n(c) Vaclav Slavik, 1999"));
5526e819
VS
245}
246
5526e819 247
3ce369e6 248void MyFrame::OnPageSetup(wxCommandEvent& WXUNUSED(event))
5526e819 249{
3ce369e6 250 m_Prn -> PageSetup();
5526e819
VS
251}
252
253
3ce369e6 254void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event))
5526e819 255{
3ce369e6 256 m_Prn -> PrintFile(m_Name);
5526e819
VS
257}
258
5526e819 259
3ce369e6 260void MyFrame::OnPreview(wxCommandEvent& WXUNUSED(event))
5526e819 261{
3ce369e6 262 m_Prn -> PreviewFile(m_Name);
5526e819
VS
263}
264
265
3ce369e6 266void MyFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
5526e819 267{
2b5f62a0 268 wxFileDialog dialog(this, _("Open HTML page"), wxT(""), wxT(""), wxT("*.htm"), 0);
3ce369e6
VS
269
270 if (dialog.ShowModal() == wxID_OK)
271 {
272 m_Name = dialog.GetPath();
273 m_Html -> LoadPage(m_Name);
2b5f62a0 274 m_Prn -> SetHeader(m_Name + wxT("(@PAGENUM@/@PAGESCNT@)<hr>"), wxPAGE_ALL);
197ab43d 275 }
5526e819
VS
276}
277
278
4eecf115
VS
279void MyFrame::OnPrintSmall(wxCommandEvent& WXUNUSED(event))
280{
7258d995 281 m_Prn->SetStandardFonts(8);
4eecf115
VS
282}
283
284void MyFrame::OnPrintNormal(wxCommandEvent& WXUNUSED(event))
285{
7258d995 286 m_Prn->SetStandardFonts(12);
4eecf115
VS
287}
288
289void MyFrame::OnPrintHuge(wxCommandEvent& WXUNUSED(event))
290{
7258d995 291 m_Prn->SetStandardFonts(28);
4eecf115 292}