]> git.saurik.com Git - wxWidgets.git/blame - samples/html/help/help.cpp
call OnInit() from all samples to allow using standard command line options with...
[wxWidgets.git] / samples / html / help / help.cpp
CommitLineData
5526e819
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: test.cpp
3// Purpose: wxHtml testing example
4/////////////////////////////////////////////////////////////////////////////
5
5526e819 6// For compilers that support precompilation, includes "wx/wx.h".
92a19c2e 7#include "wx/wxprec.h"
5526e819
VS
8
9#ifdef __BORLANDC__
10 #pragma hdrstop
11#endif
12
13// for all others, include the necessary headers (this file is usually all you
be5a51fb 14// need because it includes almost all "standard" wxWidgets headers
5526e819 15#ifndef WX_PRECOMP
67547666 16 #include "wx/wx.h"
5526e819
VS
17#endif
18
3cc2aa56
VS
19#include "wx/image.h"
20#include "wx/html/helpfrm.h"
21#include "wx/html/helpctrl.h"
22#include "wx/filesys.h"
23#include "wx/fs_zip.h"
5526e819
VS
24
25// ----------------------------------------------------------------------------
26// private classes
27// ----------------------------------------------------------------------------
28
2c997ad0 29
5526e819
VS
30// Define a new application type, each program should derive a class from wxApp
31 class MyApp : public wxApp
32 {
5526e819
VS
33 public:
34 // override base class virtuals
35 // ----------------------------
2c997ad0 36
5526e819
VS
37 // this one is called on application startup and is a good place for the app
38 // initialization (doing it here and not in the ctor allows to have an error
39 // return: if OnInit() returns false, the application terminates)
2c997ad0 40 virtual bool OnInit();
5526e819
VS
41 };
42
2c997ad0
VS
43
44
45// Define a new frame type: this is going to be our main frame
46 class MyFrame : public wxFrame
47 {
48 public:
49 // ctor(s)
50 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
51
52 // event handlers (these functions should _not_ be virtual)
53 void OnQuit(wxCommandEvent& event);
54 void OnHelp(wxCommandEvent& event);
8f8ca6c9 55 void OnClose(wxCloseEvent& event);
2c997ad0
VS
56 private:
57 wxHtmlHelpController help;
11fdee42 58
be5a51fb 59 // any class wishing to process wxWidgets events must use this macro
2c997ad0
VS
60 DECLARE_EVENT_TABLE()
61 };
62
63// ----------------------------------------------------------------------------
64// constants
65// ----------------------------------------------------------------------------
66
67// IDs for the controls and the menu commands
68 enum
69 {
70 // menu items
71 Minimal_Quit = 1,
72 Minimal_Help
73 };
74
75// ----------------------------------------------------------------------------
be5a51fb 76// event tables and other macros for wxWidgets
2c997ad0 77// ----------------------------------------------------------------------------
5526e819 78
be5a51fb 79// the event tables connect the wxWidgets events with the functions (event
2c997ad0
VS
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_Help, MyFrame::OnHelp)
8f8ca6c9 85 EVT_CLOSE(MyFrame::OnClose)
2c997ad0
VS
86 END_EVENT_TABLE()
87
be5a51fb 88 // Create a new application object: this macro will allow wxWidgets to create
2c997ad0
VS
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
92 // not wxApp)
93 IMPLEMENT_APP(MyApp)
94
95 // ============================================================================
96 // implementation
97 // ============================================================================
98
99 // ----------------------------------------------------------------------------
100 // the application class
101 // ----------------------------------------------------------------------------
102 // `Main program' equivalent: the program execution "starts" here
5526e819
VS
103 bool MyApp::OnInit()
104 {
45e6e6f8
VZ
105 if ( !wxApp::OnInit() )
106 return false;
107
047640f2 108 wxInitAllImageHandlers();
11fdee42 109#if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
5fbc988f
VS
110 wxFileSystem::AddHandler(new wxZipFSHandler);
111#endif
be5a51fb 112 SetVendorName(wxT("wxWidgets"));
11fdee42 113 SetAppName(wxT("wxHTMLHelp"));
5612e524 114
2c997ad0 115 // Create the main application window
2b5f62a0 116 MyFrame *frame = new MyFrame(_("HTML Help Sample"),
16f26dad 117 wxDefaultPosition, wxDefaultSize);
2c997ad0
VS
118
119 // Show it and tell the application that it's our main window
120 // @@@ what does it do exactly, in fact? is it necessary here?
348469c2 121 frame->Show(true);
2c997ad0
VS
122 SetTopWindow(frame);
123
124
125 // success: wxApp::OnRun() will be called which will enter the main message
348469c2 126 // loop and the application will run. If we returned false here, the
2c997ad0 127 // application would exit immediately.
348469c2 128 return true;
5526e819 129 }
2c997ad0
VS
130
131// ----------------------------------------------------------------------------
132// main frame
133// ----------------------------------------------------------------------------
134
135
136// frame constructor
137 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
11fdee42 138 : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size),
bdb6e206 139 help(wxHF_DEFAULT_STYLE | wxHF_OPEN_FILES)
2c997ad0
VS
140 {
141 // create a menu bar
142 wxMenu *menuFile = new wxMenu;
143
2b5f62a0
VZ
144 menuFile->Append(Minimal_Help, _("&Help"));
145 menuFile->Append(Minimal_Quit, _("E&xit"));
2c997ad0
VS
146
147 // now append the freshly created menu to the menu bar...
148 wxMenuBar *menuBar = new wxMenuBar;
2b5f62a0 149 menuBar->Append(menuFile, _("&File"));
2c997ad0
VS
150
151 // ... and attach this menu bar to the frame
152 SetMenuBar(menuBar);
153
5612e524 154 help.UseConfig(wxConfig::Get());
8ec2b484 155 bool ret;
2b5f62a0 156 help.SetTempDir(wxT("."));
11d667e7 157 ret = help.AddBook(wxFileName(wxT("helpfiles/testing.hhp"), wxPATH_UNIX));
8ec2b484 158 if (! ret)
2b5f62a0 159 wxMessageBox(wxT("Failed adding book helpfiles/testing.hhp"));
11d667e7 160 ret = help.AddBook(wxFileName(wxT("helpfiles/another.hhp"), wxPATH_UNIX));
8ec2b484 161 if (! ret)
2b5f62a0 162 wxMessageBox(_("Failed adding book helpfiles/another.hhp"));
2c997ad0
VS
163 }
164
165
166// event handlers
167
168 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
5526e819 169 {
348469c2
WS
170 // true is to force the frame to close
171 Close(true);
5526e819
VS
172 }
173
2c997ad0
VS
174 void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
175 {
2b5f62a0 176 help.Display(wxT("Test HELPFILE"));
2c997ad0
VS
177 }
178
8f8ca6c9
HH
179 void MyFrame::OnClose(wxCloseEvent& event)
180 {
181 // Close the help frame; this will cause the config data to
182 // get written.
183 if ( help.GetFrame() ) // returns NULL if no help frame active
348469c2 184 help.GetFrame()->Close(true);
8f8ca6c9 185 // now we can safely delete the config pointer
11fdee42 186 event.Skip();
5612e524 187 delete wxConfig::Set(NULL);
8f8ca6c9
HH
188 }
189
2c997ad0
VS
190
191
5526e819
VS
192
193
194
195