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