]>
Commit | Line | Data |
---|---|---|
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". | |
13 | #include <wx/wxprec.h> | |
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 | |
22 | #include <wx/wx.h> | |
23 | #endif | |
24 | ||
25 | #include <wx/image.h> | |
26 | #include <wx/wxhtml.h> | |
5fbc988f VS |
27 | #include <wx/filesys.h> |
28 | #include <wx/fs_zip.h> | |
5526e819 VS |
29 | |
30 | // ---------------------------------------------------------------------------- | |
31 | // private classes | |
32 | // ---------------------------------------------------------------------------- | |
33 | ||
2c997ad0 | 34 | |
5526e819 VS |
35 | // Define a new application type, each program should derive a class from wxApp |
36 | class MyApp : public wxApp | |
37 | { | |
5526e819 VS |
38 | public: |
39 | // override base class virtuals | |
40 | // ---------------------------- | |
2c997ad0 | 41 | |
5526e819 VS |
42 | // this one is called on application startup and is a good place for the app |
43 | // initialization (doing it here and not in the ctor allows to have an error | |
44 | // return: if OnInit() returns false, the application terminates) | |
2c997ad0 | 45 | virtual bool OnInit(); |
5526e819 VS |
46 | }; |
47 | ||
2c997ad0 VS |
48 | |
49 | ||
50 | // Define a new frame type: this is going to be our main frame | |
51 | class MyFrame : public wxFrame | |
52 | { | |
53 | public: | |
54 | // ctor(s) | |
55 | MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); | |
56 | ||
57 | // event handlers (these functions should _not_ be virtual) | |
58 | void OnQuit(wxCommandEvent& event); | |
59 | void OnHelp(wxCommandEvent& event); | |
8f8ca6c9 | 60 | void OnClose(wxCloseEvent& event); |
2c997ad0 VS |
61 | private: |
62 | wxHtmlHelpController help; | |
5526e819 | 63 | |
2c997ad0 VS |
64 | // any class wishing to process wxWindows events must use this macro |
65 | DECLARE_EVENT_TABLE() | |
66 | }; | |
67 | ||
68 | // ---------------------------------------------------------------------------- | |
69 | // constants | |
70 | // ---------------------------------------------------------------------------- | |
71 | ||
72 | // IDs for the controls and the menu commands | |
73 | enum | |
74 | { | |
75 | // menu items | |
76 | Minimal_Quit = 1, | |
77 | Minimal_Help | |
78 | }; | |
79 | ||
80 | // ---------------------------------------------------------------------------- | |
81 | // event tables and other macros for wxWindows | |
82 | // ---------------------------------------------------------------------------- | |
5526e819 | 83 | |
2c997ad0 VS |
84 | // the event tables connect the wxWindows events with the functions (event |
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. | |
87 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
88 | EVT_MENU(Minimal_Quit, MyFrame::OnQuit) | |
89 | EVT_MENU(Minimal_Help, MyFrame::OnHelp) | |
8f8ca6c9 | 90 | EVT_CLOSE(MyFrame::OnClose) |
2c997ad0 VS |
91 | END_EVENT_TABLE() |
92 | ||
93 | // Create a new application object: this macro will allow wxWindows to create | |
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) | |
98 | IMPLEMENT_APP(MyApp) | |
99 | ||
100 | // ============================================================================ | |
101 | // implementation | |
102 | // ============================================================================ | |
103 | ||
104 | // ---------------------------------------------------------------------------- | |
105 | // the application class | |
106 | // ---------------------------------------------------------------------------- | |
107 | // `Main program' equivalent: the program execution "starts" here | |
5526e819 VS |
108 | bool MyApp::OnInit() |
109 | { | |
047640f2 | 110 | wxInitAllImageHandlers(); |
5fbc988f VS |
111 | #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB |
112 | wxFileSystem::AddHandler(new wxZipFSHandler); | |
113 | #endif | |
5612e524 VS |
114 | SetVendorName("wxWindows"); |
115 | SetAppName("wxHTMLHelp"); | |
116 | ||
2c997ad0 VS |
117 | // Create the main application window |
118 | MyFrame *frame = new MyFrame("HTML Help Sample", | |
119 | wxPoint(50, 50), wxSize(150, 50)); | |
120 | ||
121 | // Show it and tell the application that it's our main window | |
122 | // @@@ what does it do exactly, in fact? is it necessary here? | |
123 | frame->Show(TRUE); | |
124 | SetTopWindow(frame); | |
125 | ||
126 | ||
127 | // success: wxApp::OnRun() will be called which will enter the main message | |
128 | // loop and the application will run. If we returned FALSE here, the | |
129 | // application would exit immediately. | |
5526e819 VS |
130 | return TRUE; |
131 | } | |
2c997ad0 VS |
132 | |
133 | // ---------------------------------------------------------------------------- | |
134 | // main frame | |
135 | // ---------------------------------------------------------------------------- | |
136 | ||
137 | ||
138 | // frame constructor | |
139 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
bdb6e206 VS |
140 | : wxFrame((wxFrame *)NULL, -1, title, pos, size), |
141 | help(wxHF_DEFAULT_STYLE | wxHF_OPEN_FILES) | |
2c997ad0 VS |
142 | { |
143 | // create a menu bar | |
144 | wxMenu *menuFile = new wxMenu; | |
145 | ||
146 | menuFile->Append(Minimal_Help, "&Help"); | |
147 | menuFile->Append(Minimal_Quit, "E&xit"); | |
148 | ||
149 | // now append the freshly created menu to the menu bar... | |
150 | wxMenuBar *menuBar = new wxMenuBar; | |
151 | menuBar->Append(menuFile, "&File"); | |
152 | ||
153 | // ... and attach this menu bar to the frame | |
154 | SetMenuBar(menuBar); | |
155 | ||
5612e524 | 156 | help.UseConfig(wxConfig::Get()); |
8ec2b484 | 157 | bool ret; |
95b1b9d3 | 158 | help.SetTempDir("."); |
8ec2b484 HH |
159 | ret = help.AddBook("helpfiles/testing.hhp"); |
160 | if (! ret) | |
161 | wxMessageBox("Failed adding book helpfiles/testing.hhp"); | |
162 | ret = help.AddBook("helpfiles/another.hhp"); | |
163 | if (! ret) | |
164 | wxMessageBox("Failed adding book helpfiles/another.hhp"); | |
2c997ad0 VS |
165 | } |
166 | ||
167 | ||
168 | // event handlers | |
169 | ||
170 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
5526e819 | 171 | { |
2c997ad0 | 172 | // TRUE is to force the frame to close |
2c997ad0 | 173 | Close(TRUE); |
5526e819 VS |
174 | } |
175 | ||
2c997ad0 VS |
176 | void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event)) |
177 | { | |
178 | help.Display("Main page"); | |
179 | } | |
180 | ||
8f8ca6c9 HH |
181 | void MyFrame::OnClose(wxCloseEvent& event) |
182 | { | |
183 | // Close the help frame; this will cause the config data to | |
184 | // get written. | |
185 | if ( help.GetFrame() ) // returns NULL if no help frame active | |
186 | help.GetFrame()->Close(TRUE); | |
187 | // now we can safely delete the config pointer | |
8f8ca6c9 | 188 | event.Skip(); |
5612e524 | 189 | delete wxConfig::Set(NULL); |
8f8ca6c9 HH |
190 | } |
191 | ||
2c997ad0 VS |
192 | |
193 | ||
5526e819 VS |
194 | |
195 | ||
196 | ||
197 |