]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/zip/zip.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml sample
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
18 // for all others, include the necessary headers (this file is usually all you
19 // need because it includes almost all "standard" wxWidgets headers
25 #include "wx/html/htmlwin.h"
26 #include "wx/fs_zip.h"
28 #ifndef wxHAS_IMAGES_IN_RESOURCES
29 #include "../../sample.xpm"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 // Define a new application type, each program should derive a class from wxApp
37 class MyApp
: public wxApp
40 // override base class virtuals
41 // ----------------------------
43 // this one is called on application startup and is a good place for the app
44 // initialization (doing it here and not in the ctor allows to have an error
45 // return: if OnInit() returns false, the application terminates)
46 virtual bool OnInit();
49 // Define a new frame type: this is going to be our main frame
50 class MyFrame
: public wxFrame
54 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
56 // event handlers (these functions should _not_ be virtual)
57 void OnQuit(wxCommandEvent
& event
);
58 void OnBack(wxCommandEvent
& event
);
59 void OnForward(wxCommandEvent
& event
);
62 // any class wishing to process wxWidgets events must use this macro
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 // IDs for the controls and the menu commands
79 // ----------------------------------------------------------------------------
80 // event tables and other macros for wxWidgets
81 // ----------------------------------------------------------------------------
83 // the event tables connect the wxWidgets events with the functions (event
84 // handlers) which process them. It can be also done at run-time, but for the
85 // simple menu events like this the static method is much simpler.
86 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
87 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
88 EVT_MENU(Minimal_Back
, MyFrame::OnBack
)
89 EVT_MENU(Minimal_Forward
, MyFrame::OnForward
)
92 // Create a new application object: this macro will allow wxWidgets to create
93 // the application object during program execution (it's better than using a
94 // static object for many reasons) and also declares the accessor function
95 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
99 // ============================================================================
101 // ============================================================================
103 // ----------------------------------------------------------------------------
104 // the application class
105 // ----------------------------------------------------------------------------
106 // `Main program' equivalent: the program execution "starts" here
109 if ( !wxApp::OnInit() )
113 wxImage::AddHandler(new wxPNGHandler
);
116 wxImage::AddHandler(new wxJPEGHandler
);
119 wxFileSystem::AddHandler(new wxZipFSHandler
);
121 // Create the main application window
122 MyFrame
*frame
= new MyFrame(_("wxHtmlWindow testing application"),
123 wxDefaultPosition
, wxSize(640, 480) );
128 // success: wxApp::OnRun() will be called which will enter the main message
129 // loop and the application will run. If we returned false here, the
130 // application would exit immediately.
135 // ----------------------------------------------------------------------------
137 // ----------------------------------------------------------------------------
142 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
143 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
145 SetIcon(wxICON(sample
));
148 wxMenu
*menuFile
= new wxMenu
;
149 wxMenu
*menuNav
= new wxMenu
;
151 menuFile
->Append(Minimal_Quit
, _("E&xit"));
152 menuNav
->Append(Minimal_Back
, _("Go &BACK"));
153 menuNav
->Append(Minimal_Forward
, _("Go &FORWARD"));
155 // now append the freshly created menu to the menu bar...
156 wxMenuBar
*menuBar
= new wxMenuBar
;
157 menuBar
->Append(menuFile
, _("&File"));
158 menuBar
->Append(menuNav
, _("&Navigate"));
160 // ... and attach this menu bar to the frame
165 #endif // wxUSE_STATUSBAR
167 html
= new wxHtmlWindow(this);
168 html
-> SetRelatedFrame(this, _("HTML : %s"));
170 html
-> SetRelatedStatusBar(0);
171 #endif // wxUSE_STATUSBAR
172 html
-> LoadPage(wxT("start.htm"));
178 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
180 // true is to force the frame to close
184 void MyFrame::OnBack(wxCommandEvent
& WXUNUSED(event
))
186 if (!html
-> HistoryBack()) wxMessageBox(_("You reached prehistory era!"));
189 void MyFrame::OnForward(wxCommandEvent
& WXUNUSED(event
))
191 if (!html
-> HistoryForward()) wxMessageBox(_("No more items in history!"));