]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/zip/zip.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml testing example
4 /////////////////////////////////////////////////////////////////////////////
6 // For compilers that support precompilation, includes "wx/wx.h".
13 // for all others, include the necessary headers (this file is usually all you
14 // need because it includes almost all "standard" wxWidgets headers
20 #include "wx/html/htmlwin.h"
21 #include "wx/fs_zip.h"
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
27 // Define a new application type, each program should derive a class from wxApp
28 class MyApp
: public wxApp
31 // override base class virtuals
32 // ----------------------------
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)
37 virtual bool OnInit();
40 // Define a new frame type: this is going to be our main frame
41 class MyFrame
: public wxFrame
45 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
47 // event handlers (these functions should _not_ be virtual)
48 void OnQuit(wxCommandEvent
& event
);
49 void OnBack(wxCommandEvent
& event
);
50 void OnForward(wxCommandEvent
& event
);
53 // any class wishing to process wxWidgets events must use this macro
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 // IDs for the controls and the menu commands
70 // ----------------------------------------------------------------------------
71 // event tables and other macros for wxWidgets
72 // ----------------------------------------------------------------------------
74 // the event tables connect the wxWidgets events with the functions (event
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.
77 BEGIN_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
)
83 // Create a new application object: this macro will allow wxWidgets to create
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
90 // ============================================================================
92 // ============================================================================
94 // ----------------------------------------------------------------------------
95 // the application class
96 // ----------------------------------------------------------------------------
97 // `Main program' equivalent: the program execution "starts" here
101 wxImage::AddHandler(new wxPNGHandler
);
104 wxImage::AddHandler(new wxJPEGHandler
);
107 wxFileSystem::AddHandler(new wxZipFSHandler
);
109 // Create the main application window
110 MyFrame
*frame
= new MyFrame(_("wxHtmlWindow testing application"),
111 wxDefaultPosition
, wxSize(640, 480) );
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?
118 // success: wxApp::OnRun() will be called which will enter the main message
119 // loop and the application will run. If we returned false here, the
120 // application would exit immediately.
125 // ----------------------------------------------------------------------------
127 // ----------------------------------------------------------------------------
132 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
133 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
136 wxMenu
*menuFile
= new wxMenu
;
137 wxMenu
*menuNav
= new wxMenu
;
139 menuFile
->Append(Minimal_Quit
, _("E&xit"));
140 menuNav
->Append(Minimal_Back
, _("Go &BACK"));
141 menuNav
->Append(Minimal_Forward
, _("Go &FORWARD"));
143 // now append the freshly created menu to the menu bar...
144 wxMenuBar
*menuBar
= new wxMenuBar
;
145 menuBar
->Append(menuFile
, _("&File"));
146 menuBar
->Append(menuNav
, _("&Navigate"));
148 // ... and attach this menu bar to the frame
153 #endif // wxUSE_STATUSBAR
155 html
= new wxHtmlWindow(this);
156 html
-> SetRelatedFrame(this, _("HTML : %s"));
158 html
-> SetRelatedStatusBar(0);
159 #endif // wxUSE_STATUSBAR
160 html
-> LoadPage(wxT("start.htm"));
166 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
168 // true is to force the frame to close
172 void MyFrame::OnBack(wxCommandEvent
& WXUNUSED(event
))
174 if (!html
-> HistoryBack()) wxMessageBox(_("You reached prehistory era!"));
177 void MyFrame::OnForward(wxCommandEvent
& WXUNUSED(event
))
179 if (!html
-> HistoryForward()) wxMessageBox(_("No more items in history!"));