]> git.saurik.com Git - wxWidgets.git/blame - samples/html/zip/zip.cpp
Simplify wxFileNameFromPath() implementation to avoid redundancy.
[wxWidgets.git] / samples / html / zip / zip.cpp
CommitLineData
5526e819 1/////////////////////////////////////////////////////////////////////////////
197ab43d
FM
2// Name: zip.cpp
3// Purpose: wxHtml sample
4// Author: ?
5// Modified by:
6// Created: ?
7// RCS-ID: $Id$
8// Copyright: (c) wxWidgets team
9// Licence: wxWindows licence
5526e819
VS
10/////////////////////////////////////////////////////////////////////////////
11
5526e819 12// For compilers that support precompilation, includes "wx/wx.h".
92a19c2e 13#include "wx/wxprec.h"
5526e819
VS
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19// for all others, include the necessary headers (this file is usually all you
be5a51fb 20// need because it includes almost all "standard" wxWidgets headers
5526e819 21#ifndef WX_PRECOMP
67547666 22 #include "wx/wx.h"
5526e819
VS
23#endif
24
67547666
GD
25#include "wx/image.h"
26#include "wx/html/htmlwin.h"
27#include "wx/fs_zip.h"
5526e819 28
197ab43d
FM
29#ifndef __WXMSW__
30 #include "../../sample.xpm"
31#endif
32
5526e819
VS
33// ----------------------------------------------------------------------------
34// private classes
35// ----------------------------------------------------------------------------
36
37// Define a new application type, each program should derive a class from wxApp
aec18ff7
MB
38class MyApp : public wxApp
39{
40public:
5526e819
VS
41 // override base class virtuals
42 // ----------------------------
5b7f1aab 43
5526e819
VS
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)
aec18ff7
MB
47 virtual bool OnInit();
48};
5526e819
VS
49
50// Define a new frame type: this is going to be our main frame
aec18ff7
MB
51class MyFrame : public wxFrame
52{
53public:
5526e819 54 // ctor(s)
aec18ff7 55 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
5b7f1aab 56
5526e819 57 // event handlers (these functions should _not_ be virtual)
aec18ff7
MB
58 void OnQuit(wxCommandEvent& event);
59 void OnBack(wxCommandEvent& event);
60 void OnForward(wxCommandEvent& event);
5526e819 61
aec18ff7 62private:
be5a51fb 63 // any class wishing to process wxWidgets events must use this macro
5526e819 64 DECLARE_EVENT_TABLE()
aec18ff7 65};
5526e819
VS
66
67// ----------------------------------------------------------------------------
68// constants
69// ----------------------------------------------------------------------------
70
71// IDs for the controls and the menu commands
aec18ff7
MB
72enum
73{
5526e819 74 // menu items
aec18ff7
MB
75 Minimal_Quit = 1,
76 Minimal_Back,
77 Minimal_Forward
78};
5526e819
VS
79
80// ----------------------------------------------------------------------------
be5a51fb 81// event tables and other macros for wxWidgets
5526e819
VS
82// ----------------------------------------------------------------------------
83
be5a51fb 84// the event tables connect the wxWidgets events with the functions (event
5526e819
VS
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.
aec18ff7
MB
87BEGIN_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)
91END_EVENT_TABLE()
92
be5a51fb 93// Create a new application object: this macro will allow wxWidgets to create
aec18ff7
MB
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
97// not wxApp)
98IMPLEMENT_APP(MyApp)
99
100// ============================================================================
101// implementation
102// ============================================================================
103
104// ----------------------------------------------------------------------------
105// the application class
106// ----------------------------------------------------------------------------
107// `Main program' equivalent: the program execution "starts" here
108bool MyApp::OnInit()
109{
45e6e6f8
VZ
110 if ( !wxApp::OnInit() )
111 return false;
112
aec18ff7
MB
113#if wxUSE_LIBPNG
114 wxImage::AddHandler(new wxPNGHandler);
115#endif
116#if wxUSE_LIBJPEG
117 wxImage::AddHandler(new wxJPEGHandler);
118#endif
119
120 wxFileSystem::AddHandler(new wxZipFSHandler);
5b7f1aab 121
5526e819 122 // Create the main application window
2b5f62a0 123 MyFrame *frame = new MyFrame(_("wxHtmlWindow testing application"),
16f26dad 124 wxDefaultPosition, wxSize(640, 480) );
5b7f1aab 125
5526e819
VS
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?
348469c2 128 frame->Show(true);
aec18ff7 129 SetTopWindow(frame);
5b7f1aab 130
5526e819 131 // success: wxApp::OnRun() will be called which will enter the main message
348469c2 132 // loop and the application will run. If we returned false here, the
5526e819 133 // application would exit immediately.
aec18ff7 134
348469c2 135 return true;
aec18ff7 136}
5526e819
VS
137
138// ----------------------------------------------------------------------------
139// main frame
140// ----------------------------------------------------------------------------
141
142wxHtmlWindow *html;
143
144// frame constructor
aec18ff7 145MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
197ab43d 146 : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
aec18ff7 147{
197ab43d
FM
148 SetIcon(wxICON(sample));
149
5526e819 150 // create a menu bar
aec18ff7
MB
151 wxMenu *menuFile = new wxMenu;
152 wxMenu *menuNav = new wxMenu;
5526e819 153
2b5f62a0
VZ
154 menuFile->Append(Minimal_Quit, _("E&xit"));
155 menuNav->Append(Minimal_Back, _("Go &BACK"));
156 menuNav->Append(Minimal_Forward, _("Go &FORWARD"));
5526e819
VS
157
158 // now append the freshly created menu to the menu bar...
aec18ff7 159 wxMenuBar *menuBar = new wxMenuBar;
2b5f62a0
VZ
160 menuBar->Append(menuFile, _("&File"));
161 menuBar->Append(menuNav, _("&Navigate"));
5526e819
VS
162
163 // ... and attach this menu bar to the frame
aec18ff7 164 SetMenuBar(menuBar);
5b7f1aab 165
8520f137 166#if wxUSE_STATUSBAR
aec18ff7 167 CreateStatusBar(1);
8520f137 168#endif // wxUSE_STATUSBAR
5526e819 169
aec18ff7 170 html = new wxHtmlWindow(this);
2b5f62a0 171 html -> SetRelatedFrame(this, _("HTML : %s"));
8520f137 172#if wxUSE_STATUSBAR
aec18ff7 173 html -> SetRelatedStatusBar(0);
8520f137 174#endif // wxUSE_STATUSBAR
2b5f62a0 175 html -> LoadPage(wxT("start.htm"));
aec18ff7 176}
5526e819
VS
177
178
179// event handlers
180
aec18ff7
MB
181void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
182{
348469c2
WS
183 // true is to force the frame to close
184 Close(true);
aec18ff7
MB
185}
186
187void MyFrame::OnBack(wxCommandEvent& WXUNUSED(event))
188{
2b5f62a0 189 if (!html -> HistoryBack()) wxMessageBox(_("You reached prehistory era!"));
aec18ff7
MB
190}
191
192void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event))
193{
2b5f62a0 194 if (!html -> HistoryForward()) wxMessageBox(_("No more items in history!"));
aec18ff7 195}