]>
Commit | Line | Data |
---|---|---|
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 |
30 | class 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 |
44 | class 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 | |
76 | enum | |
77 | { | |
78 | // menu items | |
79 | Minimal_Quit = 1, | |
3ce369e6 VS |
80 | Minimal_Print, |
81 | Minimal_Preview, | |
82 | Minimal_PageSetup, | |
83 | Minimal_PrintSetup, | |
84 | Minimal_Open | |
85 | ||
86 | }; | |
87 | ||
88 | // ---------------------------------------------------------------------------- | |
89 | // event tables and other macros for wxWindows | |
90 | // ---------------------------------------------------------------------------- | |
91 | ||
92 | // the event tables connect the wxWindows events with the functions (event | |
93 | // handlers) which process them. It can be also done at run-time, but for the | |
94 | // simple menu events like this the static method is much simpler. | |
95 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
96 | EVT_MENU(Minimal_Quit, MyFrame::OnQuit) | |
aec18ff7 | 97 | EVT_MENU(wxID_ABOUT, MyFrame::OnAbout) |
3ce369e6 VS |
98 | EVT_MENU(Minimal_Print, MyFrame::OnPrint) |
99 | EVT_MENU(Minimal_Preview, MyFrame::OnPreview) | |
100 | EVT_MENU(Minimal_PageSetup, MyFrame::OnPageSetup) | |
101 | EVT_MENU(Minimal_PrintSetup, MyFrame::OnPrintSetup) | |
102 | EVT_MENU(Minimal_Open, MyFrame::OnOpen) | |
103 | END_EVENT_TABLE() | |
5526e819 | 104 | |
3ce369e6 VS |
105 | // Create a new application object: this macro will allow wxWindows to create |
106 | // the application object during program execution (it's better than using a | |
107 | // static object for many reasons) and also declares the accessor function | |
108 | // wxGetApp() which will return the reference of the right type (i.e. MyApp and | |
109 | // not wxApp) | |
5526e819 VS |
110 | IMPLEMENT_APP(MyApp) |
111 | ||
3ce369e6 VS |
112 | // ============================================================================ |
113 | // implementation | |
114 | // ============================================================================ | |
5526e819 | 115 | |
3ce369e6 VS |
116 | // ---------------------------------------------------------------------------- |
117 | // the application class | |
118 | // ---------------------------------------------------------------------------- | |
119 | // `Main program' equivalent: the program execution "starts" here | |
120 | bool MyApp::OnInit() | |
5526e819 | 121 | { |
3ce369e6 VS |
122 | #if wxUSE_LIBPNG |
123 | wxImage::AddHandler(new wxPNGHandler); | |
124 | #endif | |
125 | #if wxUSE_LIBJPEG | |
126 | wxImage::AddHandler(new wxJPEGHandler); | |
127 | #endif | |
128 | #if wxUSE_GIF | |
129 | wxImage::AddHandler(new wxGIFHandler); | |
130 | #endif | |
5526e819 | 131 | |
3ce369e6 VS |
132 | MyFrame *frame = new MyFrame("Printing test", |
133 | wxPoint(150, 50), wxSize(640, 480)); | |
5526e819 | 134 | |
3ce369e6 VS |
135 | // Show it and tell the application that it's our main window |
136 | // @@@ what does it do exactly, in fact? is it necessary here? | |
137 | frame->Show(TRUE); | |
138 | SetTopWindow(frame); | |
5526e819 | 139 | |
5526e819 | 140 | |
3ce369e6 VS |
141 | // success: wxApp::OnRun() will be called which will enter the main message |
142 | // loop and the application will run. If we returned FALSE here, the | |
143 | // application would exit immediately. | |
144 | return TRUE; | |
145 | } | |
5526e819 | 146 | |
3ce369e6 VS |
147 | // ---------------------------------------------------------------------------- |
148 | // main frame | |
149 | // ---------------------------------------------------------------------------- | |
5526e819 | 150 | |
5526e819 | 151 | |
3ce369e6 VS |
152 | // frame constructor |
153 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
154 | : wxFrame((wxFrame *)NULL, -1, title, pos, size) | |
155 | { | |
156 | // create a menu bar | |
157 | wxMenu *menuFile = new wxMenu; | |
3ce369e6 VS |
158 | menuFile->Append(Minimal_Open, "Open...\tCtrl-O"); |
159 | menuFile->AppendSeparator(); | |
160 | menuFile->Append(Minimal_PageSetup, "Page Setup"); | |
161 | menuFile->Append(Minimal_PrintSetup, "Printer Setup"); | |
162 | menuFile->Append(Minimal_Print, "Print..."); | |
163 | menuFile->Append(Minimal_Preview, "Preview..."); | |
164 | menuFile->AppendSeparator(); | |
aec18ff7 | 165 | menuFile->Append(wxID_ABOUT, "&About"); |
3ce369e6 VS |
166 | menuFile->AppendSeparator(); |
167 | menuFile->Append(Minimal_Quit, "&Exit"); | |
168 | ||
169 | // now append the freshly created menu to the menu bar... | |
170 | wxMenuBar *menuBar = new wxMenuBar; | |
171 | menuBar->Append(menuFile, "&File"); | |
172 | ||
173 | // ... and attach this menu bar to the frame | |
174 | SetMenuBar(menuBar); | |
175 | ||
176 | CreateStatusBar(1); | |
177 | ||
178 | m_Html = new wxHtmlWindow(this); | |
179 | m_Html -> SetRelatedFrame(this, "HTML : %s"); | |
180 | m_Html -> SetRelatedStatusBar(0); | |
181 | m_Name = "test.htm"; | |
182 | m_Html -> LoadPage(m_Name); | |
5526e819 | 183 | |
3ce369e6 VS |
184 | m_Prn = new wxHtmlEasyPrinting("Easy Printing Demo", this); |
185 | m_Prn -> SetHeader(m_Name + "(@PAGENUM@/@PAGESCNT@)<hr>", wxPAGE_ALL); | |
5526e819 VS |
186 | } |
187 | ||
2f6c54eb VZ |
188 | // frame destructor |
189 | MyFrame::~MyFrame() | |
190 | { | |
191 | delete m_Prn; | |
192 | m_Prn = (wxHtmlEasyPrinting *) NULL; | |
193 | } | |
194 | ||
5526e819 | 195 | |
3ce369e6 | 196 | // event handlers |
5526e819 | 197 | |
3ce369e6 | 198 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
5526e819 | 199 | { |
3ce369e6 VS |
200 | // TRUE is to force the frame to close |
201 | Close(TRUE); | |
5526e819 VS |
202 | } |
203 | ||
5526e819 | 204 | |
3ce369e6 | 205 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
5526e819 | 206 | { |
3ce369e6 | 207 | wxMessageBox("HTML printing sample\n\n(c) Vaclav Slavik, 1999"); |
5526e819 VS |
208 | } |
209 | ||
5526e819 VS |
210 | |
211 | void MyFrame::OnPrintSetup(wxCommandEvent& WXUNUSED(event)) | |
212 | { | |
3ce369e6 | 213 | m_Prn -> PrinterSetup(); |
5526e819 VS |
214 | } |
215 | ||
216 | ||
3ce369e6 | 217 | void MyFrame::OnPageSetup(wxCommandEvent& WXUNUSED(event)) |
5526e819 | 218 | { |
3ce369e6 | 219 | m_Prn -> PageSetup(); |
5526e819 VS |
220 | } |
221 | ||
222 | ||
3ce369e6 | 223 | void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event)) |
5526e819 | 224 | { |
3ce369e6 | 225 | m_Prn -> PrintFile(m_Name); |
5526e819 VS |
226 | } |
227 | ||
5526e819 | 228 | |
3ce369e6 | 229 | void MyFrame::OnPreview(wxCommandEvent& WXUNUSED(event)) |
5526e819 | 230 | { |
3ce369e6 | 231 | m_Prn -> PreviewFile(m_Name); |
5526e819 VS |
232 | } |
233 | ||
234 | ||
3ce369e6 | 235 | void MyFrame::OnOpen(wxCommandEvent& WXUNUSED(event)) |
5526e819 | 236 | { |
3ce369e6 VS |
237 | wxFileDialog dialog(this, "Open HTML page", "", "", "*.htm", 0); |
238 | ||
239 | if (dialog.ShowModal() == wxID_OK) | |
240 | { | |
241 | m_Name = dialog.GetPath(); | |
242 | m_Html -> LoadPage(m_Name); | |
2f6c54eb | 243 | m_Prn -> SetHeader(m_Name + "(@PAGENUM@/@PAGESCNT@)<hr>", wxPAGE_ALL); |
3ce369e6 | 244 | } |
5526e819 VS |
245 | } |
246 | ||
247 |