]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/zip/zip.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml testing example
4 /////////////////////////////////////////////////////////////////////////////
7 #pragma implementation "test.cpp"
8 #pragma interface "test.cpp"
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" wxWindows headers
25 #include "wx/html/htmlwin.h"
26 #include "wx/fs_zip.h"
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 // Define a new application type, each program should derive a class from wxApp
33 class MyApp
: public wxApp
36 // override base class virtuals
37 // ----------------------------
39 // this one is called on application startup and is a good place for the app
40 // initialization (doing it here and not in the ctor allows to have an error
41 // return: if OnInit() returns false, the application terminates)
42 virtual bool OnInit();
45 // Define a new frame type: this is going to be our main frame
46 class MyFrame
: public wxFrame
50 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
52 // event handlers (these functions should _not_ be virtual)
53 void OnQuit(wxCommandEvent
& event
);
54 void OnBack(wxCommandEvent
& event
);
55 void OnForward(wxCommandEvent
& event
);
58 // any class wishing to process wxWindows events must use this macro
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 // IDs for the controls and the menu commands
75 // ----------------------------------------------------------------------------
76 // event tables and other macros for wxWindows
77 // ----------------------------------------------------------------------------
79 // the event tables connect the wxWindows events with the functions (event
80 // handlers) which process them. It can be also done at run-time, but for the
81 // simple menu events like this the static method is much simpler.
82 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
83 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
84 EVT_MENU(Minimal_Back
, MyFrame::OnBack
)
85 EVT_MENU(Minimal_Forward
, MyFrame::OnForward
)
88 // Create a new application object: this macro will allow wxWindows to create
89 // the application object during program execution (it's better than using a
90 // static object for many reasons) and also declares the accessor function
91 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
95 // ============================================================================
97 // ============================================================================
99 // ----------------------------------------------------------------------------
100 // the application class
101 // ----------------------------------------------------------------------------
102 // `Main program' equivalent: the program execution "starts" here
106 wxImage::AddHandler(new wxPNGHandler
);
109 wxImage::AddHandler(new wxJPEGHandler
);
112 wxFileSystem::AddHandler(new wxZipFSHandler
);
114 // Create the main application window
115 MyFrame
*frame
= new MyFrame( "wxHtmlWindow testing application",
116 wxPoint(50, 50), wxSize(640, 480) );
118 // Show it and tell the application that it's our main window
119 // @@@ what does it do exactly, in fact? is it necessary here?
123 // success: wxApp::OnRun() will be called which will enter the main message
124 // loop and the application will run. If we returned FALSE here, the
125 // application would exit immediately.
130 // ----------------------------------------------------------------------------
132 // ----------------------------------------------------------------------------
137 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
138 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
141 wxMenu
*menuFile
= new wxMenu
;
142 wxMenu
*menuNav
= new wxMenu
;
144 menuFile
->Append(Minimal_Quit
, "E&xit");
145 menuNav
->Append(Minimal_Back
, "Go &BACK");
146 menuNav
->Append(Minimal_Forward
, "Go &FORWARD");
148 // now append the freshly created menu to the menu bar...
149 wxMenuBar
*menuBar
= new wxMenuBar
;
150 menuBar
->Append(menuFile
, "&File");
151 menuBar
->Append(menuNav
, "&Navigate");
153 // ... and attach this menu bar to the frame
159 html
= new wxHtmlWindow(this);
160 html
-> SetRelatedFrame(this, "HTML : %s");
161 html
-> SetRelatedStatusBar(0);
162 html
-> LoadPage("start.htm");
169 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
171 // TRUE is to force the frame to close
175 void MyFrame::OnBack(wxCommandEvent
& WXUNUSED(event
))
177 if (!html
-> HistoryBack()) wxMessageBox("You reached prehistory era!");
180 void MyFrame::OnForward(wxCommandEvent
& WXUNUSED(event
))
182 if (!html
-> HistoryForward()) wxMessageBox("No more items in history!");