]> git.saurik.com Git - wxWidgets.git/blame_incremental - samples/html/printing/printing.cpp
some wxArtProv docs
[wxWidgets.git] / samples / html / printing / printing.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: printimg.cpp
3// Purpose: wxHtmlEasyPrinting testing example
4/////////////////////////////////////////////////////////////////////////////
5
6
7// For compilers that support precompilation, includes "wx/wx.h".
8#include "wx/wxprec.h"
9
10#ifdef __BORLANDC__
11#pragma hdrstop
12#endif
13
14// for all others, include the necessary headers (this file is usually all you
15// need because it includes almost all "standard" wxWindows headers
16#ifndef WX_PRECOMP
17#include "wx/wx.h"
18#endif
19
20#include "wx/image.h"
21#include "wx/html/htmlwin.h"
22#include "wx/html/htmprint.h"
23
24
25// ----------------------------------------------------------------------------
26// private classes
27// ----------------------------------------------------------------------------
28
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 // ----------------------------
35
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)
39
40 virtual bool OnInit();
41};
42
43// Define a new frame type: this is going to be our main frame
44class MyFrame : public wxFrame
45{
46 public:
47 // ctor and dtor
48
49 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
50 virtual ~MyFrame();
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()
105
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)
111IMPLEMENT_APP(MyApp)
112
113// ============================================================================
114// implementation
115// ============================================================================
116
117// ----------------------------------------------------------------------------
118// the application class
119// ----------------------------------------------------------------------------
120// `Main program' equivalent: the program execution "starts" here
121bool MyApp::OnInit()
122{
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
132
133 MyFrame *frame = new MyFrame("Printing test",
134 wxPoint(150, 50), wxSize(640, 480));
135
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);
140
141
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}
147
148// ----------------------------------------------------------------------------
149// main frame
150// ----------------------------------------------------------------------------
151
152
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;
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);
184
185 m_Prn = new wxHtmlEasyPrinting("Easy Printing Demo", this);
186 m_Prn -> SetHeader(m_Name + "(@PAGENUM@/@PAGESCNT@)<hr>", wxPAGE_ALL);
187}
188
189// frame destructor
190MyFrame::~MyFrame()
191{
192 delete m_Prn;
193 m_Prn = (wxHtmlEasyPrinting *) NULL;
194}
195
196
197// event handlers
198
199void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
200{
201 // TRUE is to force the frame to close
202 Close(TRUE);
203}
204
205
206void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
207{
208 wxMessageBox("HTML printing sample\n\n(c) Vaclav Slavik, 1999");
209}
210
211
212void MyFrame::OnPrintSetup(wxCommandEvent& WXUNUSED(event))
213{
214 m_Prn -> PrinterSetup();
215}
216
217
218void MyFrame::OnPageSetup(wxCommandEvent& WXUNUSED(event))
219{
220 m_Prn -> PageSetup();
221}
222
223
224void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event))
225{
226 m_Prn -> PrintFile(m_Name);
227}
228
229
230void MyFrame::OnPreview(wxCommandEvent& WXUNUSED(event))
231{
232 m_Prn -> PreviewFile(m_Name);
233}
234
235
236void MyFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
237{
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);
244 m_Prn -> SetHeader(m_Name + "(@PAGENUM@/@PAGESCNT@)<hr>", wxPAGE_ALL);
245 }
246}
247
248