]> git.saurik.com Git - wxWidgets.git/blob - samples/help/demo.cpp
Chnages to mono-bitmap code.
[wxWidgets.git] / samples / help / demo.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: demo.cpp
3 // Purpose: wxHelpController demo
4 // Author: Karsten Ballueder
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Karsten Ballueder, Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 # pragma hdrstop
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
30 # include "wx/wx.h"
31 #endif
32
33 // define this to 1 to use HTML help even under Windows (by default, Windows
34 // version will HLP-based help)
35 #define USE_HTML_HELP 1
36 #if USE_HTML_HELP
37 # include "wx/helpbase.h"
38 #else
39 # include "wx/help.h"
40 #endif
41
42 // ----------------------------------------------------------------------------
43 // ressources
44 // ----------------------------------------------------------------------------
45 // the application icon
46 #if defined(__WXGTK__) || defined(__WXMOTIF__)
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 wxHelpController& GetHelpController() { return m_help; }
75
76 // event handlers (these functions should _not_ be virtual)
77 void OnQuit(wxCommandEvent& event);
78 void OnHelp(wxCommandEvent& event);
79
80 private:
81 wxHelpController m_help;
82
83 // any class wishing to process wxWindows events must use this macro
84 DECLARE_EVENT_TABLE()
85 };
86
87 // ----------------------------------------------------------------------------
88 // constants
89 // ----------------------------------------------------------------------------
90
91 // IDs for the controls and the menu commands
92 enum
93 {
94 // menu items
95 HelpDemo_Quit = 1,
96 HelpDemo_Help_Index,
97 HelpDemo_Help_Classes,
98 HelpDemo_Help_Functions,
99 HelpDemo_Help_Help,
100 HelpDemo_Help_KDE,
101 HelpDemo_Help_GNOME,
102 HelpDemo_Help_Netscape,
103 HelpDemo_Help_Search,
104 // controls start here (the numbers are, of course, arbitrary)
105 HelpDemo_Text = 1000,
106 };
107
108 // ----------------------------------------------------------------------------
109 // event tables and other macros for wxWindows
110 // ----------------------------------------------------------------------------
111
112 // the event tables connect the wxWindows events with the functions (event
113 // handlers) which process them. It can be also done at run-time, but for the
114 // simple menu events like this the static method is much simpler.
115 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
116 EVT_MENU(HelpDemo_Quit, MyFrame::OnQuit)
117 EVT_MENU(HelpDemo_Help_Index, MyFrame::OnHelp)
118 EVT_MENU(HelpDemo_Help_Classes, MyFrame::OnHelp)
119 EVT_MENU(HelpDemo_Help_Functions, MyFrame::OnHelp)
120 EVT_MENU(HelpDemo_Help_Help, MyFrame::OnHelp)
121 EVT_MENU(HelpDemo_Help_KDE, MyFrame::OnHelp)
122 EVT_MENU(HelpDemo_Help_GNOME, MyFrame::OnHelp)
123 EVT_MENU(HelpDemo_Help_Netscape, MyFrame::OnHelp)
124 EVT_MENU(HelpDemo_Help_Search, MyFrame::OnHelp)
125 END_EVENT_TABLE()
126
127 // Create a new application object: this macro will allow wxWindows to create
128 // the application object during program execution (it's better than using a
129 // static object for many reasons) and also declares the accessor function
130 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
131 // not wxApp)
132 IMPLEMENT_APP(MyApp)
133
134 // ============================================================================
135 // implementation
136 // ============================================================================
137
138 // ----------------------------------------------------------------------------
139 // the application class
140 // ----------------------------------------------------------------------------
141
142 // `Main program' equivalent: the program execution "starts" here
143 bool MyApp::OnInit()
144 {
145 // Create the main application window
146 MyFrame *frame = new MyFrame("HelpDemo wxWindows App",
147 wxPoint(50, 50), wxSize(450, 340));
148
149 frame->Show(TRUE);
150 SetTopWindow(frame);
151
152
153 // initialise the help system: this means that we'll use doc.hlp file under
154 // Windows and that the HTML docs are in the subdirectory doc for platforms
155 // using HTML help
156 if ( !frame->GetHelpController().Initialize("doc") )
157 {
158 wxLogError("Cannot initialize the help system, aborting.");
159
160 return FALSE;
161 }
162
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
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...");
184 menuFile->AppendSeparator();
185 menuFile->Append(HelpDemo_Help_Search, "&Search help...");
186 #ifndef __WXMSW__
187 #if !wxUSE_HTML
188 menuFile->AppendSeparator();
189 menuFile->Append(HelpDemo_Help_KDE, "Use &KDE");
190 menuFile->Append(HelpDemo_Help_GNOME, "Use &GNOME");
191 menuFile->Append(HelpDemo_Help_Netscape, "Use &Netscape");
192 #endif
193 #endif
194 menuFile->AppendSeparator();
195 menuFile->Append(HelpDemo_Quit, "E&xit");
196
197 // now append the freshly created menu to the menu bar...
198 wxMenuBar *menuBar = new wxMenuBar;
199 menuBar->Append(menuFile, "&File");
200
201 // ... and attach this menu bar to the frame
202 SetMenuBar(menuBar);
203
204 // create a status bar just for fun (by default with 1 pane only)
205 CreateStatusBar();
206 SetStatusText("Welcome to wxWindows!");
207
208 // now create some controls
209
210 // a panel first - if there were several controls, it would allow us to
211 // navigate between them from the keyboard
212 wxPanel *panel = new wxPanel(this, -1, wxPoint(0, 0), wxSize(400, 200));
213
214 // and a static control whose parent is the panel
215 (void)new wxStaticText(panel, -1, "Hello, world!", wxPoint(10, 10));
216 }
217
218
219 // event handlers
220
221 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
222 {
223 // TRUE is to force the frame to close
224 Close(TRUE);
225 }
226
227 void MyFrame::OnHelp(wxCommandEvent& event)
228 {
229 switch(event.GetId())
230 {
231
232 // Note: these DisplaySection calls use ids that are specific to wxExtHelpController
233 // (on Unix). For WinHelp, we'd need to use different context ids.
234
235 case HelpDemo_Help_Classes:
236 m_help.DisplaySection(1);
237 break;
238 case HelpDemo_Help_Functions:
239 m_help.DisplaySection(4);
240 break;
241 case HelpDemo_Help_Help:
242 m_help.DisplaySection(5);
243 break;
244
245 // These three calls are only used by wxExtHelpController
246
247 case HelpDemo_Help_KDE:
248 m_help.SetViewer("kdehelp");
249 break;
250 case HelpDemo_Help_GNOME:
251 m_help.SetViewer("gnome-help-browser");
252 break;
253 case HelpDemo_Help_Netscape:
254 m_help.SetViewer("netscape", wxHELP_NETSCAPE);
255 break;
256
257 case HelpDemo_Help_Search:
258 {
259 wxString key = wxGetTextFromUser("Search for?",
260 "Search help for keyword",
261 "",
262 this);
263 if(! key.IsEmpty())
264 m_help.KeywordSearch(key);
265 }
266 break;
267 case HelpDemo_Help_Index:
268 default:
269 m_help.DisplayContents();
270 break;
271 }
272 }
273