]>
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
);
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
);
65 wxHtmlEasyPrinting
*m_Prn
;
67 // any class wishing to process wxWindows events must use this macro
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 // IDs for the controls and the menu commands
89 // ----------------------------------------------------------------------------
90 // event tables and other macros for wxWindows
91 // ----------------------------------------------------------------------------
93 // the event tables connect the wxWindows events with the functions (event
94 // handlers) which process them. It can be also done at run-time, but for the
95 // simple menu events like this the static method is much simpler.
96 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
97 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
98 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
99 EVT_MENU(Minimal_Print
, MyFrame::OnPrint
)
100 EVT_MENU(Minimal_Preview
, MyFrame::OnPreview
)
101 EVT_MENU(Minimal_PageSetup
, MyFrame::OnPageSetup
)
102 EVT_MENU(Minimal_PrintSetup
, MyFrame::OnPrintSetup
)
103 EVT_MENU(Minimal_Open
, MyFrame::OnOpen
)
106 // Create a new application object: this macro will allow wxWindows to create
107 // the application object during program execution (it's better than using a
108 // static object for many reasons) and also declares the accessor function
109 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
113 // ============================================================================
115 // ============================================================================
117 // ----------------------------------------------------------------------------
118 // the application class
119 // ----------------------------------------------------------------------------
120 // `Main program' equivalent: the program execution "starts" here
124 wxImage::AddHandler(new wxPNGHandler
);
127 wxImage::AddHandler(new wxJPEGHandler
);
130 wxImage::AddHandler(new wxGIFHandler
);
133 MyFrame
*frame
= new MyFrame("Printing test",
134 wxPoint(150, 50), wxSize(640, 480));
136 // Show it and tell the application that it's our main window
137 // @@@ what does it do exactly, in fact? is it necessary here?
142 // success: wxApp::OnRun() will be called which will enter the main message
143 // loop and the application will run. If we returned FALSE here, the
144 // application would exit immediately.
148 // ----------------------------------------------------------------------------
150 // ----------------------------------------------------------------------------
154 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
155 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
158 wxMenu
*menuFile
= new wxMenu
;
159 menuFile
->Append(Minimal_Open
, "Open...\tCtrl-O");
160 menuFile
->AppendSeparator();
161 menuFile
->Append(Minimal_PageSetup
, "Page Setup");
162 menuFile
->Append(Minimal_PrintSetup
, "Printer Setup");
163 menuFile
->Append(Minimal_Print
, "Print...");
164 menuFile
->Append(Minimal_Preview
, "Preview...");
165 menuFile
->AppendSeparator();
166 menuFile
->Append(Minimal_About
, "&About");
167 menuFile
->AppendSeparator();
168 menuFile
->Append(Minimal_Quit
, "&Exit");
170 // now append the freshly created menu to the menu bar...
171 wxMenuBar
*menuBar
= new wxMenuBar
;
172 menuBar
->Append(menuFile
, "&File");
174 // ... and attach this menu bar to the frame
179 m_Html
= new wxHtmlWindow(this);
180 m_Html
-> SetRelatedFrame(this, "HTML : %s");
181 m_Html
-> SetRelatedStatusBar(0);
183 m_Html
-> LoadPage(m_Name
);
185 m_Prn
= new wxHtmlEasyPrinting("Easy Printing Demo", this);
186 m_Prn
-> SetHeader(m_Name
+ "(@PAGENUM@/@PAGESCNT@)<hr>", wxPAGE_ALL
);
193 m_Prn
= (wxHtmlEasyPrinting
*) NULL
;
199 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
201 // TRUE is to force the frame to close
206 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
208 wxMessageBox("HTML printing sample\n\n(c) Vaclav Slavik, 1999");
212 void MyFrame::OnPrintSetup(wxCommandEvent
& WXUNUSED(event
))
214 m_Prn
-> PrinterSetup();
218 void MyFrame::OnPageSetup(wxCommandEvent
& WXUNUSED(event
))
220 m_Prn
-> PageSetup();
224 void MyFrame::OnPrint(wxCommandEvent
& WXUNUSED(event
))
226 m_Prn
-> PrintFile(m_Name
);
230 void MyFrame::OnPreview(wxCommandEvent
& WXUNUSED(event
))
232 m_Prn
-> PreviewFile(m_Name
);
236 void MyFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
238 wxFileDialog
dialog(this, "Open HTML page", "", "", "*.htm", 0);
240 if (dialog
.ShowModal() == wxID_OK
)
242 m_Name
= dialog
.GetPath();
243 m_Html
-> LoadPage(m_Name
);
244 m_Prn
-> SetHeader(m_Name
+ "(@PAGENUM@/@PAGESCNT@)<hr>", wxPAGE_ALL
);