]>
Commit | Line | Data |
---|---|---|
de5c0ba7 | 1 | ///////////////////////////////////////////////////////////////////////////// |
33b64e6f JS |
2 | // Name: demo.cpp |
3 | // Purpose: wxHelpController demo | |
4 | // Author: Karsten Ballueder | |
de5c0ba7 KB |
5 | // Modified by: |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
33b64e6f JS |
8 | // Copyright: (c) Karsten Ballueder, Julian Smart |
9 | // Licence: wxWindows licence | |
de5c0ba7 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
f96b60aa | 19 | |
de5c0ba7 | 20 | #ifdef __GNUG__ |
33b64e6f JS |
21 | #pragma implementation "demo.cpp" |
22 | #pragma interface "demo.cpp" | |
de5c0ba7 KB |
23 | #endif |
24 | ||
25 | // For compilers that support precompilation, includes "wx/wx.h". | |
26 | #include "wx/wxprec.h" | |
27 | ||
28 | #ifdef __BORLANDC__ | |
29 | #pragma hdrstop | |
30 | #endif | |
31 | ||
32 | // for all others, include the necessary headers (this file is usually all you | |
33 | // need because it includes almost all "standard" wxWindows headers | |
34 | #ifndef WX_PRECOMP | |
35 | #include "wx/wx.h" | |
36 | #endif | |
37 | ||
f96b60aa VZ |
38 | // defien this to 1 to use HTML help even under Windows (by default, Windows |
39 | // version will HLP-based help) | |
40 | #define USE_HTML_HELP 1 | |
41 | ||
42 | #if USE_HTML_HELP | |
43 | #include "wx/helpbase.h" | |
44 | #include "wx/generic/helpext.h" | |
45 | ||
46 | #define wxHelpController wxExtHelpController | |
47 | #define sm_classwxHelpController sm_classwxExtHelpController | |
48 | #else | |
49 | #include "wx/help.h" | |
50 | #endif | |
de5c0ba7 KB |
51 | |
52 | // ---------------------------------------------------------------------------- | |
53 | // ressources | |
54 | // ---------------------------------------------------------------------------- | |
55 | // the application icon | |
55acd85e | 56 | #if defined(__WXGTK__) || defined(__WXMOTIF__) |
de5c0ba7 KB |
57 | #include "mondrian.xpm" |
58 | #endif | |
59 | ||
60 | // ---------------------------------------------------------------------------- | |
61 | // private classes | |
62 | // ---------------------------------------------------------------------------- | |
63 | ||
64 | // Define a new application type, each program should derive a class from wxApp | |
65 | class MyApp : public wxApp | |
66 | { | |
67 | public: | |
68 | // override base class virtuals | |
69 | // ---------------------------- | |
70 | ||
71 | // this one is called on application startup and is a good place for the app | |
72 | // initialization (doing it here and not in the ctor allows to have an error | |
73 | // return: if OnInit() returns false, the application terminates) | |
74 | virtual bool OnInit(); | |
75 | }; | |
76 | ||
77 | // Define a new frame type: this is going to be our main frame | |
78 | class MyFrame : public wxFrame | |
79 | { | |
80 | public: | |
81 | // ctor(s) | |
82 | MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); | |
83 | ||
84 | // event handlers (these functions should _not_ be virtual) | |
85 | void OnQuit(wxCommandEvent& event); | |
86 | void OnHelp(wxCommandEvent& event); | |
87 | ||
88 | private: | |
f96b60aa VZ |
89 | wxHelpController m_help; |
90 | ||
de5c0ba7 KB |
91 | // any class wishing to process wxWindows events must use this macro |
92 | DECLARE_EVENT_TABLE() | |
93 | }; | |
94 | ||
95 | // ---------------------------------------------------------------------------- | |
96 | // constants | |
97 | // ---------------------------------------------------------------------------- | |
98 | ||
99 | // IDs for the controls and the menu commands | |
100 | enum | |
101 | { | |
102 | // menu items | |
33b64e6f JS |
103 | HelpDemo_Quit = 1, |
104 | HelpDemo_Help_Index, | |
105 | HelpDemo_Help_Classes, | |
106 | HelpDemo_Help_Functions, | |
107 | HelpDemo_Help_Help, | |
108 | HelpDemo_Help_KDE, | |
109 | HelpDemo_Help_GNOME, | |
110 | HelpDemo_Help_Netscape, | |
111 | HelpDemo_Help_Search, | |
de5c0ba7 | 112 | // controls start here (the numbers are, of course, arbitrary) |
33b64e6f | 113 | HelpDemo_Text = 1000, |
de5c0ba7 KB |
114 | }; |
115 | ||
116 | // ---------------------------------------------------------------------------- | |
117 | // event tables and other macros for wxWindows | |
118 | // ---------------------------------------------------------------------------- | |
119 | ||
120 | // the event tables connect the wxWindows events with the functions (event | |
121 | // handlers) which process them. It can be also done at run-time, but for the | |
122 | // simple menu events like this the static method is much simpler. | |
123 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
33b64e6f JS |
124 | EVT_MENU(HelpDemo_Quit, MyFrame::OnQuit) |
125 | EVT_MENU(HelpDemo_Help_Index, MyFrame::OnHelp) | |
126 | EVT_MENU(HelpDemo_Help_Classes, MyFrame::OnHelp) | |
127 | EVT_MENU(HelpDemo_Help_Functions, MyFrame::OnHelp) | |
128 | EVT_MENU(HelpDemo_Help_Help, MyFrame::OnHelp) | |
129 | EVT_MENU(HelpDemo_Help_KDE, MyFrame::OnHelp) | |
130 | EVT_MENU(HelpDemo_Help_GNOME, MyFrame::OnHelp) | |
131 | EVT_MENU(HelpDemo_Help_Netscape, MyFrame::OnHelp) | |
132 | EVT_MENU(HelpDemo_Help_Search, MyFrame::OnHelp) | |
de5c0ba7 KB |
133 | END_EVENT_TABLE() |
134 | ||
135 | // Create a new application object: this macro will allow wxWindows to create | |
136 | // the application object during program execution (it's better than using a | |
137 | // static object for many reasons) and also declares the accessor function | |
138 | // wxGetApp() which will return the reference of the right type (i.e. MyApp and | |
139 | // not wxApp) | |
140 | IMPLEMENT_APP(MyApp) | |
141 | ||
142 | // ============================================================================ | |
143 | // implementation | |
144 | // ============================================================================ | |
145 | ||
146 | // ---------------------------------------------------------------------------- | |
147 | // the application class | |
148 | // ---------------------------------------------------------------------------- | |
149 | ||
150 | // `Main program' equivalent: the program execution "starts" here | |
151 | bool MyApp::OnInit() | |
152 | { | |
153 | // Create the main application window | |
33b64e6f | 154 | MyFrame *frame = new MyFrame("HelpDemo wxWindows App", |
de5c0ba7 KB |
155 | wxPoint(50, 50), wxSize(450, 340)); |
156 | ||
de5c0ba7 KB |
157 | frame->Show(TRUE); |
158 | SetTopWindow(frame); | |
159 | ||
160 | // success: wxApp::OnRun() will be called which will enter the main message | |
161 | // loop and the application will run. If we returned FALSE here, the | |
162 | // application would exit immediately. | |
163 | return TRUE; | |
164 | } | |
165 | ||
166 | // ---------------------------------------------------------------------------- | |
167 | // main frame | |
168 | // ---------------------------------------------------------------------------- | |
169 | ||
170 | // frame constructor | |
171 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
172 | : wxFrame((wxFrame *)NULL, -1, title, pos, size) | |
173 | { | |
174 | // set the frame icon | |
175 | SetIcon(wxICON(mondrian)); | |
176 | ||
177 | // create a menu bar | |
178 | wxMenu *menuFile = new wxMenu; | |
179 | ||
33b64e6f JS |
180 | menuFile->Append(HelpDemo_Help_Index, "&Help Index..."); |
181 | menuFile->Append(HelpDemo_Help_Classes, "&Help on Classes..."); | |
182 | menuFile->Append(HelpDemo_Help_Functions, "&Help on Functions..."); | |
183 | menuFile->Append(HelpDemo_Help_Help, "&About Help Demo..."); | |
de5c0ba7 | 184 | menuFile->AppendSeparator(); |
33b64e6f JS |
185 | menuFile->Append(HelpDemo_Help_Search, "&Search help..."); |
186 | #ifdef __WXGTK__ | |
de5c0ba7 | 187 | menuFile->AppendSeparator(); |
33b64e6f JS |
188 | menuFile->Append(HelpDemo_Help_KDE, "Use &KDE"); |
189 | menuFile->Append(HelpDemo_Help_GNOME, "Use &GNOME"); | |
190 | menuFile->Append(HelpDemo_Help_Netscape, "Use &Netscape"); | |
191 | #endif | |
192 | menuFile->AppendSeparator(); | |
193 | menuFile->Append(HelpDemo_Quit, "E&xit"); | |
de5c0ba7 KB |
194 | |
195 | // now append the freshly created menu to the menu bar... | |
196 | wxMenuBar *menuBar = new wxMenuBar; | |
197 | menuBar->Append(menuFile, "&File"); | |
198 | ||
199 | // ... and attach this menu bar to the frame | |
200 | SetMenuBar(menuBar); | |
201 | ||
202 | // create a status bar just for fun (by default with 1 pane only) | |
203 | CreateStatusBar(); | |
204 | SetStatusText("Welcome to wxWindows!"); | |
205 | ||
206 | // now create some controls | |
207 | ||
208 | // a panel first - if there were several controls, it would allow us to | |
209 | // navigate between them from the keyboard | |
210 | wxPanel *panel = new wxPanel(this, -1, wxPoint(0, 0), wxSize(400, 200)); | |
211 | ||
212 | // and a static control whose parent is the panel | |
213 | (void)new wxStaticText(panel, -1, "Hello, world!", wxPoint(10, 10)); | |
214 | ||
f96b60aa VZ |
215 | // initialise the help system: this means that we'll use doc.hlp file under |
216 | // Windows and that the HTML docs are in the subdirectory doc for platforms | |
217 | // using HTML help | |
218 | m_help.Initialize("doc"); | |
de5c0ba7 KB |
219 | } |
220 | ||
221 | ||
222 | // event handlers | |
223 | ||
224 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
225 | { | |
226 | // TRUE is to force the frame to close | |
227 | Close(TRUE); | |
228 | } | |
229 | ||
230 | void MyFrame::OnHelp(wxCommandEvent& event) | |
231 | { | |
232 | switch(event.GetId()) | |
233 | { | |
33b64e6f JS |
234 | |
235 | // Note: these DisplaySection calls use ids that are specific to wxExtHelpController | |
236 | // (on Unix). For WinHelp, we'd need to use different context ids. | |
237 | ||
238 | case HelpDemo_Help_Classes: | |
f96b60aa | 239 | m_help.DisplaySection(1); |
de5c0ba7 | 240 | break; |
33b64e6f | 241 | case HelpDemo_Help_Functions: |
f96b60aa | 242 | m_help.DisplaySection(4); |
de5c0ba7 | 243 | break; |
33b64e6f | 244 | case HelpDemo_Help_Help: |
f96b60aa | 245 | m_help.DisplaySection(5); |
de5c0ba7 | 246 | break; |
33b64e6f JS |
247 | |
248 | // These three calls are only used by wxExtHelpController | |
249 | ||
250 | case HelpDemo_Help_KDE: | |
f96b60aa | 251 | m_help.SetViewer("kdehelp"); |
de5c0ba7 | 252 | break; |
33b64e6f | 253 | case HelpDemo_Help_GNOME: |
f96b60aa | 254 | m_help.SetViewer("gnome-help-browser"); |
de5c0ba7 | 255 | break; |
33b64e6f | 256 | case HelpDemo_Help_Netscape: |
f96b60aa | 257 | m_help.SetViewer("netscape", wxHELP_NETSCAPE); |
de5c0ba7 | 258 | break; |
33b64e6f JS |
259 | |
260 | case HelpDemo_Help_Search: | |
de5c0ba7 KB |
261 | { |
262 | wxString key = wxGetTextFromUser("Search for?", | |
263 | "Search help for keyword", | |
264 | "", | |
265 | this); | |
266 | if(! key.IsEmpty()) | |
f96b60aa | 267 | m_help.KeywordSearch(key); |
de5c0ba7 KB |
268 | } |
269 | break; | |
33b64e6f | 270 | case HelpDemo_Help_Index: |
de5c0ba7 | 271 | default: |
f96b60aa | 272 | m_help.DisplayContents(); |
de5c0ba7 KB |
273 | break; |
274 | } | |
275 | } | |
33b64e6f | 276 |