]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/printing/printing.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlEasyPrinting testing example
4 // Licence: wxWindows Licence
5 /////////////////////////////////////////////////////////////////////////////
8 // For compilers that support precompilation, includes "wx/wx.h".
15 // for all others, include the necessary headers (this file is usually all you
16 // need because it includes almost all "standard" wxWidgets headers
22 #include "wx/html/htmlwin.h"
23 #include "wx/html/htmprint.h"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 // Define a new application type, each program should derive a class from wxApp
31 class MyApp
: public wxApp
34 // override base class virtuals
35 // ----------------------------
37 // this one is called on application startup and is a good place for the app
38 // initialization (doing it here and not in the ctor allows to have an error
39 // return: if OnInit() returns false, the application terminates)
41 virtual bool OnInit();
44 // Define a new frame type: this is going to be our main frame
45 class MyFrame
: public wxFrame
50 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
53 // event handlers (these functions should _not_ be virtual)
54 void OnQuit(wxCommandEvent
& event
);
55 void OnAbout(wxCommandEvent
& event
);
57 void OnPrintSetup(wxCommandEvent
& event
);
58 void OnPageSetup(wxCommandEvent
& event
);
59 void OnPrint(wxCommandEvent
& event
);
60 void OnPreview(wxCommandEvent
& event
);
61 void OnOpen(wxCommandEvent
& event
);
63 void OnPrintSmall(wxCommandEvent
& event
);
64 void OnPrintNormal(wxCommandEvent
& event
);
65 void OnPrintHuge(wxCommandEvent
& event
);
70 wxHtmlEasyPrinting
*m_Prn
;
72 // any class wishing to process wxWidgets events must use this macro
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 // IDs for the controls and the menu commands
96 // ----------------------------------------------------------------------------
97 // event tables and other macros for wxWidgets
98 // ----------------------------------------------------------------------------
100 // the event tables connect the wxWidgets events with the functions (event
101 // handlers) which process them. It can be also done at run-time, but for the
102 // simple menu events like this the static method is much simpler.
103 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
104 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
105 EVT_MENU(wxID_ABOUT
, MyFrame::OnAbout
)
106 EVT_MENU(Minimal_Print
, MyFrame::OnPrint
)
107 EVT_MENU(Minimal_Preview
, MyFrame::OnPreview
)
108 EVT_MENU(Minimal_PageSetup
, MyFrame::OnPageSetup
)
109 EVT_MENU(Minimal_PrintSetup
, MyFrame::OnPrintSetup
)
110 EVT_MENU(Minimal_Open
, MyFrame::OnOpen
)
111 EVT_MENU(Minimal_PrintSmall
, MyFrame::OnPrintSmall
)
112 EVT_MENU(Minimal_PrintNormal
, MyFrame::OnPrintNormal
)
113 EVT_MENU(Minimal_PrintHuge
, MyFrame::OnPrintHuge
)
116 // Create a new application object: this macro will allow wxWidgets to create
117 // the application object during program execution (it's better than using a
118 // static object for many reasons) and also declares the accessor function
119 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
123 // ============================================================================
125 // ============================================================================
127 // ----------------------------------------------------------------------------
128 // the application class
129 // ----------------------------------------------------------------------------
130 // `Main program' equivalent: the program execution "starts" here
134 wxImage::AddHandler(new wxPNGHandler
);
137 wxImage::AddHandler(new wxJPEGHandler
);
140 wxImage::AddHandler(new wxGIFHandler
);
143 MyFrame
*frame
= new MyFrame(_("Printing test"),
144 wxDefaultPosition
, wxSize(640, 480));
146 // Show it and tell the application that it's our main window
147 // @@@ what does it do exactly, in fact? is it necessary here?
152 // success: wxApp::OnRun() will be called which will enter the main message
153 // loop and the application will run. If we returned false here, the
154 // application would exit immediately.
158 // ----------------------------------------------------------------------------
160 // ----------------------------------------------------------------------------
164 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
165 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
168 wxMenu
*menuFile
= new wxMenu
;
169 menuFile
->Append(Minimal_Open
, _("Open...\tCtrl-O"));
170 menuFile
->AppendSeparator();
171 menuFile
->Append(Minimal_PageSetup
, _("Page Setup"));
172 menuFile
->Append(Minimal_PrintSetup
, _("Printer Setup"));
173 menuFile
->Append(Minimal_Print
, _("Print..."));
174 menuFile
->Append(Minimal_Preview
, _("Preview..."));
175 menuFile
->AppendSeparator();
176 menuFile
->Append(wxID_ABOUT
, _("&About"));
177 menuFile
->AppendSeparator();
178 menuFile
->Append(Minimal_Quit
, _("&Exit"));
180 wxMenu
*testFile
= new wxMenu
;
181 testFile
->Append(Minimal_PrintSmall
, _("Small Printer Fonts"));
182 testFile
->Append(Minimal_PrintNormal
, _("Normal Printer Fonts"));
183 testFile
->Append(Minimal_PrintHuge
, _("Huge Printer Fonts"));
185 // now append the freshly created menu to the menu bar...
186 wxMenuBar
*menuBar
= new wxMenuBar
;
187 menuBar
->Append(menuFile
, _("&File"));
188 menuBar
->Append(testFile
, _("&Test"));
190 // ... and attach this menu bar to the frame
195 #endif // wxUSE_STATUSBAR
197 m_Html
= new wxHtmlWindow(this);
198 m_Html
-> SetRelatedFrame(this, _("HTML : %s"));
200 m_Html
-> SetRelatedStatusBar(0);
201 #endif // wxUSE_STATUSBAR
202 m_Name
= wxT("test.htm");
203 m_Html
-> LoadPage(m_Name
);
205 m_Prn
= new wxHtmlEasyPrinting(_("Easy Printing Demo"), this);
206 m_Prn
-> SetHeader(m_Name
+ wxT("(@PAGENUM@/@PAGESCNT@)<hr>"), wxPAGE_ALL
);
208 // To specify where the AFM files are kept on Unix,
209 // you may wish to do something like this
210 // m_Prn->GetPrintData()->SetFontMetricPath(wxT("/home/julians/afm"));
217 m_Prn
= (wxHtmlEasyPrinting
*) NULL
;
223 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
225 // true is to force the frame to close
230 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
232 wxMessageBox(_("HTML printing sample\n\n(c) Vaclav Slavik, 1999"));
236 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
238 m_Prn
-> PrinterSetup();
242 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
244 m_Prn
-> PageSetup();
248 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
250 m_Prn
-> PrintFile(m_Name
);
254 void MyFrame::OnPreview(wxCommandEvent
& WXUNUSED(event
))
256 m_Prn
-> PreviewFile(m_Name
);
260 void MyFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
262 wxFileDialog
dialog(this, _("Open HTML page"), wxT(""), wxT(""), wxT("*.htm"), 0);
264 if (dialog
.ShowModal() == wxID_OK
)
266 m_Name
= dialog
.GetPath();
267 m_Html
-> LoadPage(m_Name
);
268 m_Prn
-> SetHeader(m_Name
+ wxT("(@PAGENUM@/@PAGESCNT@)<hr>"), wxPAGE_ALL
);
273 void MyFrame::OnPrintSmall(wxCommandEvent
& WXUNUSED(event
))
275 int fontsizes
[] = { 4, 6, 8, 10, 12, 20, 24 };
276 m_Prn
->SetFonts(wxEmptyString
, wxEmptyString
, fontsizes
);
279 void MyFrame::OnPrintNormal(wxCommandEvent
& WXUNUSED(event
))
281 m_Prn
->SetFonts(wxEmptyString
, wxEmptyString
, 0);
284 void MyFrame::OnPrintHuge(wxCommandEvent
& WXUNUSED(event
))
286 int fontsizes
[] = { 20, 26, 28, 30, 32, 40, 44 };
287 m_Prn
->SetFonts(wxEmptyString
, wxEmptyString
, fontsizes
);