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