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