]> git.saurik.com Git - wxWidgets.git/blame - samples/html/zip/zip.cpp
GTK2: gtk_widget_set_uposition -> gtk_window_move for wxPopupWindow - migration appea...
[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{
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);
5b7f1aab 108
5526e819 109 // Create the main application window
2b5f62a0 110 MyFrame *frame = new MyFrame(_("wxHtmlWindow testing application"),
16f26dad 111 wxDefaultPosition, wxSize(640, 480) );
5b7f1aab 112
5526e819
VS
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?
348469c2 115 frame->Show(true);
aec18ff7 116 SetTopWindow(frame);
5b7f1aab 117
5526e819 118 // success: wxApp::OnRun() will be called which will enter the main message
348469c2 119 // loop and the application will run. If we returned false here, the
5526e819 120 // application would exit immediately.
aec18ff7 121
348469c2 122 return true;
aec18ff7 123}
5526e819
VS
124
125// ----------------------------------------------------------------------------
126// main frame
127// ----------------------------------------------------------------------------
128
129wxHtmlWindow *html;
130
131// frame constructor
aec18ff7 132MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
348469c2 133: wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
aec18ff7 134{
5526e819 135 // create a menu bar
aec18ff7
MB
136 wxMenu *menuFile = new wxMenu;
137 wxMenu *menuNav = new wxMenu;
5526e819 138
2b5f62a0
VZ
139 menuFile->Append(Minimal_Quit, _("E&xit"));
140 menuNav->Append(Minimal_Back, _("Go &BACK"));
141 menuNav->Append(Minimal_Forward, _("Go &FORWARD"));
5526e819
VS
142
143 // now append the freshly created menu to the menu bar...
aec18ff7 144 wxMenuBar *menuBar = new wxMenuBar;
2b5f62a0
VZ
145 menuBar->Append(menuFile, _("&File"));
146 menuBar->Append(menuNav, _("&Navigate"));
5526e819
VS
147
148 // ... and attach this menu bar to the frame
aec18ff7 149 SetMenuBar(menuBar);
5b7f1aab 150
8520f137 151#if wxUSE_STATUSBAR
aec18ff7 152 CreateStatusBar(1);
8520f137 153#endif // wxUSE_STATUSBAR
5526e819 154
aec18ff7 155 html = new wxHtmlWindow(this);
2b5f62a0 156 html -> SetRelatedFrame(this, _("HTML : %s"));
8520f137 157#if wxUSE_STATUSBAR
aec18ff7 158 html -> SetRelatedStatusBar(0);
8520f137 159#endif // wxUSE_STATUSBAR
2b5f62a0 160 html -> LoadPage(wxT("start.htm"));
aec18ff7 161}
5526e819
VS
162
163
164// event handlers
165
aec18ff7
MB
166void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
167{
348469c2
WS
168 // true is to force the frame to close
169 Close(true);
aec18ff7
MB
170}
171
172void MyFrame::OnBack(wxCommandEvent& WXUNUSED(event))
173{
2b5f62a0 174 if (!html -> HistoryBack()) wxMessageBox(_("You reached prehistory era!"));
aec18ff7
MB
175}
176
177void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event))
178{
2b5f62a0 179 if (!html -> HistoryForward()) wxMessageBox(_("No more items in history!"));
aec18ff7 180}