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