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