]> git.saurik.com Git - wxWidgets.git/blame_incremental - samples/html/zip/zip.cpp
correct access for virtuals
[wxWidgets.git] / samples / html / zip / zip.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: test.cpp
3// Purpose: wxHtml testing example
4/////////////////////////////////////////////////////////////////////////////
5
6// For compilers that support precompilation, includes "wx/wx.h".
7#include "wx/wxprec.h"
8
9#ifdef __BORLANDC__
10 #pragma hdrstop
11#endif
12
13// for all others, include the necessary headers (this file is usually all you
14// need because it includes almost all "standard" wxWidgets headers
15#ifndef WX_PRECOMP
16 #include "wx/wx.h"
17#endif
18
19#include "wx/image.h"
20#include "wx/html/htmlwin.h"
21#include "wx/fs_zip.h"
22
23// ----------------------------------------------------------------------------
24// private classes
25// ----------------------------------------------------------------------------
26
27// Define a new application type, each program should derive a class from wxApp
28class MyApp : public wxApp
29{
30public:
31 // override base class virtuals
32 // ----------------------------
33
34 // this one is called on application startup and is a good place for the app
35 // initialization (doing it here and not in the ctor allows to have an error
36 // return: if OnInit() returns false, the application terminates)
37 virtual bool OnInit();
38};
39
40// Define a new frame type: this is going to be our main frame
41class MyFrame : public wxFrame
42{
43public:
44 // ctor(s)
45 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
46
47 // event handlers (these functions should _not_ be virtual)
48 void OnQuit(wxCommandEvent& event);
49 void OnBack(wxCommandEvent& event);
50 void OnForward(wxCommandEvent& event);
51
52private:
53 // any class wishing to process wxWidgets events must use this macro
54 DECLARE_EVENT_TABLE()
55};
56
57// ----------------------------------------------------------------------------
58// constants
59// ----------------------------------------------------------------------------
60
61// IDs for the controls and the menu commands
62enum
63{
64 // menu items
65 Minimal_Quit = 1,
66 Minimal_Back,
67 Minimal_Forward
68};
69
70// ----------------------------------------------------------------------------
71// event tables and other macros for wxWidgets
72// ----------------------------------------------------------------------------
73
74// the event tables connect the wxWidgets events with the functions (event
75// handlers) which process them. It can be also done at run-time, but for the
76// simple menu events like this the static method is much simpler.
77BEGIN_EVENT_TABLE(MyFrame, wxFrame)
78 EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
79 EVT_MENU(Minimal_Back, MyFrame::OnBack)
80 EVT_MENU(Minimal_Forward, MyFrame::OnForward)
81END_EVENT_TABLE()
82
83// Create a new application object: this macro will allow wxWidgets to create
84// the application object during program execution (it's better than using a
85// static object for many reasons) and also declares the accessor function
86// wxGetApp() which will return the reference of the right type (i.e. MyApp and
87// not wxApp)
88IMPLEMENT_APP(MyApp)
89
90// ============================================================================
91// implementation
92// ============================================================================
93
94// ----------------------------------------------------------------------------
95// the application class
96// ----------------------------------------------------------------------------
97// `Main program' equivalent: the program execution "starts" here
98bool MyApp::OnInit()
99{
100#if wxUSE_LIBPNG
101 wxImage::AddHandler(new wxPNGHandler);
102#endif
103#if wxUSE_LIBJPEG
104 wxImage::AddHandler(new wxJPEGHandler);
105#endif
106
107 wxFileSystem::AddHandler(new wxZipFSHandler);
108
109 // Create the main application window
110 MyFrame *frame = new MyFrame(_("wxHtmlWindow testing application"),
111 wxDefaultPosition, wxSize(640, 480) );
112
113 // Show it and tell the application that it's our main window
114 // @@@ what does it do exactly, in fact? is it necessary here?
115 frame->Show(true);
116 SetTopWindow(frame);
117
118 // success: wxApp::OnRun() will be called which will enter the main message
119 // loop and the application will run. If we returned false here, the
120 // application would exit immediately.
121
122 return true;
123}
124
125// ----------------------------------------------------------------------------
126// main frame
127// ----------------------------------------------------------------------------
128
129wxHtmlWindow *html;
130
131// frame constructor
132MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
133: wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
134{
135 // create a menu bar
136 wxMenu *menuFile = new wxMenu;
137 wxMenu *menuNav = new wxMenu;
138
139 menuFile->Append(Minimal_Quit, _("E&xit"));
140 menuNav->Append(Minimal_Back, _("Go &BACK"));
141 menuNav->Append(Minimal_Forward, _("Go &FORWARD"));
142
143 // now append the freshly created menu to the menu bar...
144 wxMenuBar *menuBar = new wxMenuBar;
145 menuBar->Append(menuFile, _("&File"));
146 menuBar->Append(menuNav, _("&Navigate"));
147
148 // ... and attach this menu bar to the frame
149 SetMenuBar(menuBar);
150
151#if wxUSE_STATUSBAR
152 CreateStatusBar(1);
153#endif // wxUSE_STATUSBAR
154
155 html = new wxHtmlWindow(this);
156 html -> SetRelatedFrame(this, _("HTML : %s"));
157#if wxUSE_STATUSBAR
158 html -> SetRelatedStatusBar(0);
159#endif // wxUSE_STATUSBAR
160 html -> LoadPage(wxT("start.htm"));
161}
162
163
164// event handlers
165
166void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
167{
168 // true is to force the frame to close
169 Close(true);
170}
171
172void MyFrame::OnBack(wxCommandEvent& WXUNUSED(event))
173{
174 if (!html -> HistoryBack()) wxMessageBox(_("You reached prehistory era!"));
175}
176
177void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event))
178{
179 if (!html -> HistoryForward()) wxMessageBox(_("No more items in history!"));
180}