]> git.saurik.com Git - wxWidgets.git/blame - samples/html/help/help.cpp
swigged updates for wxGTK
[wxWidgets.git] / samples / html / help / help.cpp
CommitLineData
2c997ad0 1
5526e819
VS
2/////////////////////////////////////////////////////////////////////////////
3// Name: test.cpp
4// Purpose: wxHtml testing example
5/////////////////////////////////////////////////////////////////////////////
6
7#ifdef __GNUG__
2c997ad0
VS
8 #pragma implementation "help.cpp"
9 #pragma interface "help.cpp"
5526e819
VS
10#endif
11
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
20// need because it includes almost all "standard" wxWindows headers
21#ifndef WX_PRECOMP
67547666 22 #include "wx/wx.h"
5526e819
VS
23#endif
24
3cc2aa56
VS
25#include "wx/image.h"
26#include "wx/html/helpfrm.h"
27#include "wx/html/helpctrl.h"
28#include "wx/filesys.h"
29#include "wx/fs_zip.h"
5526e819
VS
30
31// ----------------------------------------------------------------------------
32// private classes
33// ----------------------------------------------------------------------------
34
2c997ad0 35
5526e819
VS
36// Define a new application type, each program should derive a class from wxApp
37 class MyApp : public wxApp
38 {
5526e819
VS
39 public:
40 // override base class virtuals
41 // ----------------------------
2c997ad0 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)
2c997ad0 46 virtual bool OnInit();
5526e819
VS
47 };
48
2c997ad0
VS
49
50
51// Define a new frame type: this is going to be our main frame
52 class MyFrame : public wxFrame
53 {
54 public:
55 // ctor(s)
56 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
57
58 // event handlers (these functions should _not_ be virtual)
59 void OnQuit(wxCommandEvent& event);
60 void OnHelp(wxCommandEvent& event);
8f8ca6c9 61 void OnClose(wxCloseEvent& event);
2c997ad0
VS
62 private:
63 wxHtmlHelpController help;
5526e819 64
2c997ad0
VS
65 // any class wishing to process wxWindows events must use this macro
66 DECLARE_EVENT_TABLE()
67 };
68
69// ----------------------------------------------------------------------------
70// constants
71// ----------------------------------------------------------------------------
72
73// IDs for the controls and the menu commands
74 enum
75 {
76 // menu items
77 Minimal_Quit = 1,
78 Minimal_Help
79 };
80
81// ----------------------------------------------------------------------------
82// event tables and other macros for wxWindows
83// ----------------------------------------------------------------------------
5526e819 84
2c997ad0
VS
85// the event tables connect the wxWindows events with the functions (event
86// handlers) which process them. It can be also done at run-time, but for the
87// simple menu events like this the static method is much simpler.
88 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
89 EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
90 EVT_MENU(Minimal_Help, MyFrame::OnHelp)
8f8ca6c9 91 EVT_CLOSE(MyFrame::OnClose)
2c997ad0
VS
92 END_EVENT_TABLE()
93
94 // Create a new application object: this macro will allow wxWindows to create
95 // the application object during program execution (it's better than using a
96 // static object for many reasons) and also declares the accessor function
97 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
98 // not wxApp)
99 IMPLEMENT_APP(MyApp)
100
101 // ============================================================================
102 // implementation
103 // ============================================================================
104
105 // ----------------------------------------------------------------------------
106 // the application class
107 // ----------------------------------------------------------------------------
108 // `Main program' equivalent: the program execution "starts" here
5526e819
VS
109 bool MyApp::OnInit()
110 {
047640f2 111 wxInitAllImageHandlers();
5fbc988f
VS
112#if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
113 wxFileSystem::AddHandler(new wxZipFSHandler);
114#endif
5612e524
VS
115 SetVendorName("wxWindows");
116 SetAppName("wxHTMLHelp");
117
2c997ad0
VS
118 // Create the main application window
119 MyFrame *frame = new MyFrame("HTML Help Sample",
120 wxPoint(50, 50), wxSize(150, 50));
121
122 // Show it and tell the application that it's our main window
123 // @@@ what does it do exactly, in fact? is it necessary here?
124 frame->Show(TRUE);
125 SetTopWindow(frame);
126
127
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.
5526e819
VS
131 return TRUE;
132 }
2c997ad0
VS
133
134// ----------------------------------------------------------------------------
135// main frame
136// ----------------------------------------------------------------------------
137
138
139// frame constructor
140 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
bdb6e206
VS
141 : wxFrame((wxFrame *)NULL, -1, title, pos, size),
142 help(wxHF_DEFAULT_STYLE | wxHF_OPEN_FILES)
2c997ad0
VS
143 {
144 // create a menu bar
145 wxMenu *menuFile = new wxMenu;
146
147 menuFile->Append(Minimal_Help, "&Help");
148 menuFile->Append(Minimal_Quit, "E&xit");
149
150 // now append the freshly created menu to the menu bar...
151 wxMenuBar *menuBar = new wxMenuBar;
152 menuBar->Append(menuFile, "&File");
153
154 // ... and attach this menu bar to the frame
155 SetMenuBar(menuBar);
156
5612e524 157 help.UseConfig(wxConfig::Get());
8ec2b484 158 bool ret;
c638c3cd
SC
159#ifdef __WXMAC__
160 ret = help.AddBook(":helpfiles:testing.hhp");
161#else
95b1b9d3 162 help.SetTempDir(".");
8ec2b484 163 ret = help.AddBook("helpfiles/testing.hhp");
c638c3cd 164#endif
8ec2b484 165 if (! ret)
2f6c54eb 166 wxMessageBox("Failed adding book helpfiles/testing.hhp");
c638c3cd
SC
167#ifdef __WXMAC__
168 ret = help.AddBook(":helpfiles:another.hhp");
169#else
8ec2b484 170 ret = help.AddBook("helpfiles/another.hhp");
c638c3cd 171#endif
8ec2b484 172 if (! ret)
2f6c54eb 173 wxMessageBox("Failed adding book helpfiles/another.hhp");
2c997ad0
VS
174 }
175
176
177// event handlers
178
179 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
5526e819 180 {
2c997ad0 181 // TRUE is to force the frame to close
2c997ad0 182 Close(TRUE);
5526e819
VS
183 }
184
2c997ad0
VS
185 void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
186 {
2e25e7b7 187 help.Display("Test HELPFILE");
2c997ad0
VS
188 }
189
8f8ca6c9
HH
190 void MyFrame::OnClose(wxCloseEvent& event)
191 {
192 // Close the help frame; this will cause the config data to
193 // get written.
194 if ( help.GetFrame() ) // returns NULL if no help frame active
195 help.GetFrame()->Close(TRUE);
196 // now we can safely delete the config pointer
8f8ca6c9 197 event.Skip();
5612e524 198 delete wxConfig::Set(NULL);
8f8ca6c9
HH
199 }
200
2c997ad0
VS
201
202
5526e819
VS
203
204
205
206