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