]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/printing/printing.cpp
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" wxWindows 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
);
51 // event handlers (these functions should _not_ be virtual)
52 void OnQuit(wxCommandEvent
& event
);
53 void OnAbout(wxCommandEvent
& event
);
55 void OnPrintSetup(wxCommandEvent
& event
);
56 void OnPageSetup(wxCommandEvent
& event
);
57 void OnPrint(wxCommandEvent
& event
);
58 void OnPreview(wxCommandEvent
& event
);
59 void OnOpen(wxCommandEvent
& event
);
64 wxHtmlEasyPrinting
*m_Prn
;
66 // any class wishing to process wxWindows events must use this macro
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 // IDs for the controls and the menu commands
88 // ----------------------------------------------------------------------------
89 // event tables and other macros for wxWindows
90 // ----------------------------------------------------------------------------
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
)
97 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
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
)
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
112 // ============================================================================
114 // ============================================================================
116 // ----------------------------------------------------------------------------
117 // the application class
118 // ----------------------------------------------------------------------------
119 // `Main program' equivalent: the program execution "starts" here
123 wxImage::AddHandler(new wxPNGHandler
);
126 wxImage::AddHandler(new wxJPEGHandler
);
129 wxImage::AddHandler(new wxGIFHandler
);
132 MyFrame
*frame
= new MyFrame("Printing test",
133 wxPoint(150, 50), wxSize(640, 480));
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?
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.
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
153 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
154 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
157 wxMenu
*menuFile
= new wxMenu
;
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();
165 menuFile
->Append(Minimal_About
, "&About");
166 menuFile
->AppendSeparator();
167 menuFile
->Append(Minimal_Quit
, "&Exit");
169 // now append the freshly created menu to the menu bar...
170 wxMenuBar
*menuBar
= new wxMenuBar
;
171 menuBar
->Append(menuFile
, "&File");
173 // ... and attach this menu bar to the frame
178 m_Html
= new wxHtmlWindow(this);
179 m_Html
-> SetRelatedFrame(this, "HTML : %s");
180 m_Html
-> SetRelatedStatusBar(0);
182 m_Html
-> LoadPage(m_Name
);
184 m_Prn
= new wxHtmlEasyPrinting("Easy Printing Demo", this);
185 m_Prn
-> SetHeader(m_Name
+ "(@PAGENUM@/@PAGESCNT@)<hr>", wxPAGE_ALL
);
191 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
194 // TRUE is to force the frame to close
199 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
201 wxMessageBox("HTML printing sample\n\n(c) Vaclav Slavik, 1999");
205 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
207 m_Prn
-> PrinterSetup();
211 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
213 m_Prn
-> PageSetup();
217 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
219 m_Prn
-> PrintFile(m_Name
);
223 void MyFrame::OnPreview(wxCommandEvent
& WXUNUSED(event
))
225 m_Prn
-> PreviewFile(m_Name
);
229 void MyFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
231 wxFileDialog
dialog(this, "Open HTML page", "", "", "*.htm", 0);
233 if (dialog
.ShowModal() == wxID_OK
)
235 m_Name
= dialog
.GetPath();
236 m_Html
-> LoadPage(m_Name
);
237 m_Prn
-> SetHeader(m_Name
+ "(@PAGENUM@/@PAGESCNT@)<hr>", wxPAGE_ALL
);