]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/printing/printing.cpp
90497c7de8c6d4890524d6e7a4f21ef1cf432492
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlEasyPrinting testing example
4 /////////////////////////////////////////////////////////////////////////////
7 // For compilers that support precompilation, includes "wx/wx.h".
14 // for all others, include the necessary headers (this file is usually all you
15 // need because it includes almost all "standard" wxWidgets headers
21 #include "wx/html/htmlwin.h"
22 #include "wx/html/htmprint.h"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
29 // Define a new application type, each program should derive a class from wxApp
30 class MyApp
: public wxApp
33 // override base class virtuals
34 // ----------------------------
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)
40 virtual bool OnInit();
43 // Define a new frame type: this is going to be our main frame
44 class MyFrame
: public wxFrame
49 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
52 // event handlers (these functions should _not_ be virtual)
53 void OnQuit(wxCommandEvent
& event
);
54 void OnAbout(wxCommandEvent
& event
);
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
);
62 void OnPrintSmall(wxCommandEvent
& event
);
63 void OnPrintNormal(wxCommandEvent
& event
);
64 void OnPrintHuge(wxCommandEvent
& event
);
69 wxHtmlEasyPrinting
*m_Prn
;
71 // any class wishing to process wxWidgets events must use this macro
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 // IDs for the controls and the menu commands
95 // ----------------------------------------------------------------------------
96 // event tables and other macros for wxWidgets
97 // ----------------------------------------------------------------------------
99 // the event tables connect the wxWidgets events with the functions (event
100 // handlers) which process them. It can be also done at run-time, but for the
101 // simple menu events like this the static method is much simpler.
102 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
103 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
104 EVT_MENU(wxID_ABOUT
, MyFrame::OnAbout
)
105 EVT_MENU(Minimal_Print
, MyFrame::OnPrint
)
106 EVT_MENU(Minimal_Preview
, MyFrame::OnPreview
)
107 EVT_MENU(Minimal_PageSetup
, MyFrame::OnPageSetup
)
108 EVT_MENU(Minimal_PrintSetup
, MyFrame::OnPrintSetup
)
109 EVT_MENU(Minimal_Open
, MyFrame::OnOpen
)
110 EVT_MENU(Minimal_PrintSmall
, MyFrame::OnPrintSmall
)
111 EVT_MENU(Minimal_PrintNormal
, MyFrame::OnPrintNormal
)
112 EVT_MENU(Minimal_PrintHuge
, MyFrame::OnPrintHuge
)
115 // Create a new application object: this macro will allow wxWidgets to create
116 // the application object during program execution (it's better than using a
117 // static object for many reasons) and also declares the accessor function
118 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
122 // ============================================================================
124 // ============================================================================
126 // ----------------------------------------------------------------------------
127 // the application class
128 // ----------------------------------------------------------------------------
129 // `Main program' equivalent: the program execution "starts" here
133 wxImage::AddHandler(new wxPNGHandler
);
136 wxImage::AddHandler(new wxJPEGHandler
);
139 wxImage::AddHandler(new wxGIFHandler
);
142 MyFrame
*frame
= new MyFrame(_("Printing test"),
143 wxDefaultPosition
, wxSize(640, 480));
145 // Show it and tell the application that it's our main window
146 // @@@ what does it do exactly, in fact? is it necessary here?
151 // success: wxApp::OnRun() will be called which will enter the main message
152 // loop and the application will run. If we returned false here, the
153 // application would exit immediately.
157 // ----------------------------------------------------------------------------
159 // ----------------------------------------------------------------------------
163 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
164 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
167 wxMenu
*menuFile
= new wxMenu
;
168 menuFile
->Append(Minimal_Open
, _("Open...\tCtrl-O"));
169 menuFile
->AppendSeparator();
170 menuFile
->Append(Minimal_PageSetup
, _("Page Setup"));
171 menuFile
->Append(Minimal_PrintSetup
, _("Printer Setup"));
172 menuFile
->Append(Minimal_Print
, _("Print..."));
173 menuFile
->Append(Minimal_Preview
, _("Preview..."));
174 menuFile
->AppendSeparator();
175 menuFile
->Append(wxID_ABOUT
, _("&About"));
176 menuFile
->AppendSeparator();
177 menuFile
->Append(Minimal_Quit
, _("&Exit"));
179 wxMenu
*testFile
= new wxMenu
;
180 testFile
->Append(Minimal_PrintSmall
, _("Small Printer Fonts"));
181 testFile
->Append(Minimal_PrintNormal
, _("Normal Printer Fonts"));
182 testFile
->Append(Minimal_PrintHuge
, _("Huge Printer Fonts"));
184 // now append the freshly created menu to the menu bar...
185 wxMenuBar
*menuBar
= new wxMenuBar
;
186 menuBar
->Append(menuFile
, _("&File"));
187 menuBar
->Append(testFile
, _("&Test"));
189 // ... and attach this menu bar to the frame
194 m_Html
= new wxHtmlWindow(this);
195 m_Html
-> SetRelatedFrame(this, _("HTML : %s"));
196 m_Html
-> SetRelatedStatusBar(0);
197 m_Name
= wxT("test.htm");
198 m_Html
-> LoadPage(m_Name
);
200 m_Prn
= new wxHtmlEasyPrinting(_("Easy Printing Demo"), this);
201 m_Prn
-> SetHeader(m_Name
+ wxT("(@PAGENUM@/@PAGESCNT@)<hr>"), wxPAGE_ALL
);
209 m_Prn
= (wxHtmlEasyPrinting
*) NULL
;
215 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
217 // true is to force the frame to close
222 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
224 wxMessageBox(_("HTML printing sample\n\n(c) Vaclav Slavik, 1999"));
228 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
230 m_Prn
-> PrinterSetup();
234 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
236 m_Prn
-> PageSetup();
240 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
242 m_Prn
-> PrintFile(m_Name
);
246 void MyFrame::OnPreview(wxCommandEvent
& WXUNUSED(event
))
248 m_Prn
-> PreviewFile(m_Name
);
252 void MyFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
254 wxFileDialog
dialog(this, _("Open HTML page"), wxT(""), wxT(""), wxT("*.htm"), 0);
256 if (dialog
.ShowModal() == wxID_OK
)
258 m_Name
= dialog
.GetPath();
259 m_Html
-> LoadPage(m_Name
);
260 m_Prn
-> SetHeader(m_Name
+ wxT("(@PAGENUM@/@PAGESCNT@)<hr>"), wxPAGE_ALL
);
265 void MyFrame::OnPrintSmall(wxCommandEvent
& WXUNUSED(event
))
267 int fontsizes
[] = { 4, 6, 8, 10, 12, 20, 24 };
268 m_Prn
->SetFonts(wxEmptyString
, wxEmptyString
, fontsizes
);
271 void MyFrame::OnPrintNormal(wxCommandEvent
& WXUNUSED(event
))
273 m_Prn
->SetFonts(wxEmptyString
, wxEmptyString
, 0);
276 void MyFrame::OnPrintHuge(wxCommandEvent
& WXUNUSED(event
))
278 int fontsizes
[] = { 20, 26, 28, 30, 32, 40, 44 };
279 m_Prn
->SetFonts(wxEmptyString
, wxEmptyString
, fontsizes
);