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