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