]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/printing/printing.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml sample: wxHtmlEasyPrinting test
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
20 // for all others, include the necessary headers (this file is usually all you
21 // need because it includes almost all "standard" wxWidgets headers
27 #include "wx/html/htmlwin.h"
28 #include "wx/html/htmprint.h"
31 #include "../../sample.xpm"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // Define a new application type, each program should derive a class from wxApp
40 class MyApp
: public wxApp
43 // override base class virtuals
44 // ----------------------------
46 // this one is called on application startup and is a good place for the app
47 // initialization (doing it here and not in the ctor allows to have an error
48 // return: if OnInit() returns false, the application terminates)
50 virtual bool OnInit();
53 // Define a new frame type: this is going to be our main frame
54 class MyFrame
: public wxFrame
59 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
62 // event handlers (these functions should _not_ be virtual)
63 void OnQuit(wxCommandEvent
& event
);
64 void OnAbout(wxCommandEvent
& event
);
66 void OnPageSetup(wxCommandEvent
& event
);
67 void OnPrint(wxCommandEvent
& event
);
68 void OnPreview(wxCommandEvent
& event
);
69 void OnOpen(wxCommandEvent
& event
);
71 void OnPrintSmall(wxCommandEvent
& event
);
72 void OnPrintNormal(wxCommandEvent
& event
);
73 void OnPrintHuge(wxCommandEvent
& event
);
78 wxHtmlEasyPrinting
*m_Prn
;
81 // any class wishing to process wxWidgets events must use this macro
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 // IDs for the controls and the menu commands
104 // ----------------------------------------------------------------------------
105 // event tables and other macros for wxWidgets
106 // ----------------------------------------------------------------------------
108 // the event tables connect the wxWidgets events with the functions (event
109 // handlers) which process them. It can be also done at run-time, but for the
110 // simple menu events like this the static method is much simpler.
111 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
112 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
113 EVT_MENU(wxID_ABOUT
, MyFrame::OnAbout
)
114 EVT_MENU(Minimal_Print
, MyFrame::OnPrint
)
115 EVT_MENU(Minimal_Preview
, MyFrame::OnPreview
)
116 EVT_MENU(Minimal_PageSetup
, MyFrame::OnPageSetup
)
117 EVT_MENU(Minimal_Open
, MyFrame::OnOpen
)
118 EVT_MENU(Minimal_PrintSmall
, MyFrame::OnPrintSmall
)
119 EVT_MENU(Minimal_PrintNormal
, MyFrame::OnPrintNormal
)
120 EVT_MENU(Minimal_PrintHuge
, MyFrame::OnPrintHuge
)
123 // Create a new application object: this macro will allow wxWidgets to create
124 // the application object during program execution (it's better than using a
125 // static object for many reasons) and also declares the accessor function
126 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
130 // ============================================================================
132 // ============================================================================
134 // ----------------------------------------------------------------------------
135 // the application class
136 // ----------------------------------------------------------------------------
137 // `Main program' equivalent: the program execution "starts" here
141 if ( !wxApp::OnInit() )
145 wxImage::AddHandler(new wxPNGHandler
);
148 wxImage::AddHandler(new wxJPEGHandler
);
151 wxImage::AddHandler(new wxGIFHandler
);
154 MyFrame
*frame
= new MyFrame(_("Printing test"),
155 wxDefaultPosition
, wxSize(640, 480));
157 // Show it and tell the application that it's our main window
158 // @@@ what does it do exactly, in fact? is it necessary here?
163 // success: wxApp::OnRun() will be called which will enter the main message
164 // loop and the application will run. If we returned false here, the
165 // application would exit immediately.
169 // ----------------------------------------------------------------------------
171 // ----------------------------------------------------------------------------
175 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
176 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
178 SetIcon(wxICON(sample
));
181 wxMenu
*menuFile
= new wxMenu
;
182 menuFile
->Append(Minimal_Open
, _("Open...\tCtrl-O"));
183 menuFile
->AppendSeparator();
184 menuFile
->Append(Minimal_PageSetup
, _("Page Setup"));
185 menuFile
->Append(Minimal_Print
, _("Print..."));
186 menuFile
->Append(Minimal_Preview
, _("Preview..."));
187 menuFile
->AppendSeparator();
188 menuFile
->Append(wxID_ABOUT
, _("&About"));
189 menuFile
->AppendSeparator();
190 menuFile
->Append(Minimal_Quit
, _("&Exit"));
192 wxMenu
*testFile
= new wxMenu
;
193 testFile
->Append(Minimal_PrintSmall
, _("Small Printer Fonts"));
194 testFile
->Append(Minimal_PrintNormal
, _("Normal Printer Fonts"));
195 testFile
->Append(Minimal_PrintHuge
, _("Huge Printer Fonts"));
197 // now append the freshly created menu to the menu bar...
198 wxMenuBar
*menuBar
= new wxMenuBar
;
199 menuBar
->Append(menuFile
, _("&File"));
200 menuBar
->Append(testFile
, _("&Test"));
202 // ... and attach this menu bar to the frame
207 #endif // wxUSE_STATUSBAR
209 m_Html
= new wxHtmlWindow(this);
210 m_Html
-> SetRelatedFrame(this, _("HTML : %s"));
212 m_Html
-> SetRelatedStatusBar(0);
213 #endif // wxUSE_STATUSBAR
214 m_Name
= wxT("test.htm");
215 m_Html
-> LoadPage(m_Name
);
217 m_Prn
= new wxHtmlEasyPrinting(_("Easy Printing Demo"), this);
218 m_Prn
-> SetHeader(m_Name
+ wxT("(@PAGENUM@/@PAGESCNT@)<hr>"), wxPAGE_ALL
);
220 // To specify where the AFM files are kept on Unix,
221 // you may wish to do something like this
222 // m_Prn->GetPrintData()->SetFontMetricPath(wxT("/home/julians/afm"));
229 m_Prn
= (wxHtmlEasyPrinting
*) NULL
;
235 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
237 // true is to force the frame to close
242 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
244 wxMessageBox(_("HTML printing sample\n\n(c) Vaclav Slavik, 1999"));
248 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
250 m_Prn
-> PageSetup();
254 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
256 m_Prn
-> PrintFile(m_Name
);
260 void MyFrame::OnPreview(wxCommandEvent
& WXUNUSED(event
))
262 m_Prn
-> PreviewFile(m_Name
);
266 void MyFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
268 wxFileDialog
dialog(this, _("Open HTML page"), wxT(""), wxT(""), wxT("*.htm"), 0);
270 if (dialog
.ShowModal() == wxID_OK
)
272 m_Name
= dialog
.GetPath();
273 m_Html
-> LoadPage(m_Name
);
274 m_Prn
-> SetHeader(m_Name
+ wxT("(@PAGENUM@/@PAGESCNT@)<hr>"), wxPAGE_ALL
);
279 void MyFrame::OnPrintSmall(wxCommandEvent
& WXUNUSED(event
))
281 m_Prn
->SetStandardFonts(8);
284 void MyFrame::OnPrintNormal(wxCommandEvent
& WXUNUSED(event
))
286 m_Prn
->SetStandardFonts(12);
289 void MyFrame::OnPrintHuge(wxCommandEvent
& WXUNUSED(event
))
291 m_Prn
->SetStandardFonts(28);