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