]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/zip/zip.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml sample
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
19 // for all others, include the necessary headers (this file is usually all you
20 // need because it includes almost all "standard" wxWidgets headers
26 #include "wx/html/htmlwin.h"
27 #include "wx/fs_zip.h"
30 #include "../../sample.xpm"
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 // Define a new application type, each program should derive a class from wxApp
38 class MyApp
: public wxApp
41 // override base class virtuals
42 // ----------------------------
44 // this one is called on application startup and is a good place for the app
45 // initialization (doing it here and not in the ctor allows to have an error
46 // return: if OnInit() returns false, the application terminates)
47 virtual bool OnInit();
50 // Define a new frame type: this is going to be our main frame
51 class MyFrame
: public wxFrame
55 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
57 // event handlers (these functions should _not_ be virtual)
58 void OnQuit(wxCommandEvent
& event
);
59 void OnBack(wxCommandEvent
& event
);
60 void OnForward(wxCommandEvent
& event
);
63 // any class wishing to process wxWidgets events must use this macro
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 // IDs for the controls and the menu commands
80 // ----------------------------------------------------------------------------
81 // event tables and other macros for wxWidgets
82 // ----------------------------------------------------------------------------
84 // the event tables connect the wxWidgets 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_Back
, MyFrame::OnBack
)
90 EVT_MENU(Minimal_Forward
, MyFrame::OnForward
)
93 // Create a new application object: this macro will allow wxWidgets to create
94 // the application object during program execution (it's better than using a
95 // static object for many reasons) and also declares the accessor function
96 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
100 // ============================================================================
102 // ============================================================================
104 // ----------------------------------------------------------------------------
105 // the application class
106 // ----------------------------------------------------------------------------
107 // `Main program' equivalent: the program execution "starts" here
110 if ( !wxApp::OnInit() )
114 wxImage::AddHandler(new wxPNGHandler
);
117 wxImage::AddHandler(new wxJPEGHandler
);
120 wxFileSystem::AddHandler(new wxZipFSHandler
);
122 // Create the main application window
123 MyFrame
*frame
= new MyFrame(_("wxHtmlWindow testing application"),
124 wxDefaultPosition
, wxSize(640, 480) );
126 // Show it and tell the application that it's our main window
127 // @@@ what does it do exactly, in fact? is it necessary here?
131 // success: wxApp::OnRun() will be called which will enter the main message
132 // loop and the application will run. If we returned false here, the
133 // application would exit immediately.
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
145 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
146 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
148 SetIcon(wxICON(sample
));
151 wxMenu
*menuFile
= new wxMenu
;
152 wxMenu
*menuNav
= new wxMenu
;
154 menuFile
->Append(Minimal_Quit
, _("E&xit"));
155 menuNav
->Append(Minimal_Back
, _("Go &BACK"));
156 menuNav
->Append(Minimal_Forward
, _("Go &FORWARD"));
158 // now append the freshly created menu to the menu bar...
159 wxMenuBar
*menuBar
= new wxMenuBar
;
160 menuBar
->Append(menuFile
, _("&File"));
161 menuBar
->Append(menuNav
, _("&Navigate"));
163 // ... and attach this menu bar to the frame
168 #endif // wxUSE_STATUSBAR
170 html
= new wxHtmlWindow(this);
171 html
-> SetRelatedFrame(this, _("HTML : %s"));
173 html
-> SetRelatedStatusBar(0);
174 #endif // wxUSE_STATUSBAR
175 html
-> LoadPage(wxT("start.htm"));
181 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
183 // true is to force the frame to close
187 void MyFrame::OnBack(wxCommandEvent
& WXUNUSED(event
))
189 if (!html
-> HistoryBack()) wxMessageBox(_("You reached prehistory era!"));
192 void MyFrame::OnForward(wxCommandEvent
& WXUNUSED(event
))
194 if (!html
-> HistoryForward()) wxMessageBox(_("No more items in history!"));