1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHelpController demo
4 // Author: Karsten Ballueder
8 // Copyright: (c) Karsten Ballueder, Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers (this file is usually all you
28 // need because it includes almost all "standard" wxWindows headers
33 # include "wx/image.h"
36 // define this to 1 to use HTML help even under Windows (by default, Windows
37 // version will use WinHelp).
38 // Please also see samples/html/helpview for a more complex help viewer.
40 #define USE_HTML_HELP 1
44 #define USE_HTML_HELP 0
48 # include "wx/generic/helpwxht.h"
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
54 // the application icon
55 #if defined(__WXGTK__) || defined(__WXMOTIF__)
56 #include "mondrian.xpm"
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 // Define a new application type, each program should derive a class from wxApp
64 class MyApp
: public wxApp
67 // override base class virtuals
68 // ----------------------------
70 // this one is called on application startup and is a good place for the app
71 // initialization (doing it here and not in the ctor allows to have an error
72 // return: if OnInit() returns false, the application terminates)
73 virtual bool OnInit();
76 // Define a new frame type: this is going to be our main frame
77 class MyFrame
: public wxFrame
81 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
83 wxHelpController
& GetHelpController() { return m_help
; }
86 wxHelpControllerHtml
& GetHtmlHelpController() { return m_htmlHelp
; }
89 // event handlers (these functions should _not_ be virtual)
90 void OnQuit(wxCommandEvent
& event
);
91 void OnHelp(wxCommandEvent
& event
);
92 void OnHtmlHelp(wxCommandEvent
& event
);
95 wxHelpController m_help
;
98 wxHelpControllerHtml m_htmlHelp
;
101 // any class wishing to process wxWindows events must use this macro
102 DECLARE_EVENT_TABLE()
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
109 // IDs for the controls and the menu commands
115 HelpDemo_Help_Classes
,
116 HelpDemo_Help_Functions
,
118 HelpDemo_Help_Search
,
120 HelpDemo_Html_Help_Index
,
121 HelpDemo_Html_Help_Classes
,
122 HelpDemo_Html_Help_Functions
,
123 HelpDemo_Html_Help_Help
,
124 HelpDemo_Html_Help_Search
,
128 HelpDemo_Help_Netscape
,
129 // controls start here (the numbers are, of course, arbitrary)
133 // ----------------------------------------------------------------------------
134 // event tables and other macros for wxWindows
135 // ----------------------------------------------------------------------------
137 // the event tables connect the wxWindows events with the functions (event
138 // handlers) which process them. It can be also done at run-time, but for the
139 // simple menu events like this the static method is much simpler.
140 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
141 EVT_MENU(HelpDemo_Quit
, MyFrame::OnQuit
)
142 EVT_MENU(HelpDemo_Help_Index
, MyFrame::OnHelp
)
143 EVT_MENU(HelpDemo_Help_Classes
, MyFrame::OnHelp
)
144 EVT_MENU(HelpDemo_Help_Functions
, MyFrame::OnHelp
)
145 EVT_MENU(HelpDemo_Help_Help
, MyFrame::OnHelp
)
146 EVT_MENU(HelpDemo_Help_Search
, MyFrame::OnHelp
)
148 EVT_MENU(HelpDemo_Html_Help_Index
, MyFrame::OnHtmlHelp
)
149 EVT_MENU(HelpDemo_Html_Help_Classes
, MyFrame::OnHtmlHelp
)
150 EVT_MENU(HelpDemo_Html_Help_Functions
, MyFrame::OnHtmlHelp
)
151 EVT_MENU(HelpDemo_Html_Help_Help
, MyFrame::OnHtmlHelp
)
152 EVT_MENU(HelpDemo_Html_Help_Search
, MyFrame::OnHtmlHelp
)
154 EVT_MENU(HelpDemo_Help_KDE
, MyFrame::OnHelp
)
155 EVT_MENU(HelpDemo_Help_GNOME
, MyFrame::OnHelp
)
156 EVT_MENU(HelpDemo_Help_Netscape
, MyFrame::OnHelp
)
159 // Create a new application object: this macro will allow wxWindows to create
160 // the application object during program execution (it's better than using a
161 // static object for many reasons) and also declares the accessor function
162 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
166 // ============================================================================
168 // ============================================================================
170 // ----------------------------------------------------------------------------
171 // the application class
172 // ----------------------------------------------------------------------------
174 // `Main program' equivalent: the program execution "starts" here
179 // Required for images in the online documentation
180 wxImage::AddHandler(new wxGIFHandler
);
184 // Create the main application window
185 MyFrame
*frame
= new MyFrame("HelpDemo wxWindows App",
186 wxPoint(50, 50), wxSize(450, 340));
191 // initialise the help system: this means that we'll use doc.hlp file under
192 // Windows and that the HTML docs are in the subdirectory doc for platforms
194 if ( !frame
->GetHelpController().Initialize("doc") )
196 wxLogError("Cannot initialize the help system, aborting.");
202 // initialise the help system: this means that the HTML docs are in the
203 // subdirectory doc for platforms using HTML help
204 if ( !frame
->GetHtmlHelpController().Initialize("doc") )
206 wxLogError("Cannot initialize the HTML help system, aborting.");
215 // ----------------------------------------------------------------------------
217 // ----------------------------------------------------------------------------
220 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
221 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
223 // set the frame icon
224 SetIcon(wxICON(mondrian
));
227 wxMenu
*menuFile
= new wxMenu
;
229 menuFile
->Append(HelpDemo_Help_Index
, "&Help Index...");
230 menuFile
->Append(HelpDemo_Help_Classes
, "&Help on Classes...");
231 menuFile
->Append(HelpDemo_Help_Functions
, "&Help on Functions...");
232 menuFile
->Append(HelpDemo_Help_Help
, "&About Help Demo...");
233 menuFile
->AppendSeparator();
234 menuFile
->Append(HelpDemo_Help_Search
, "&Search help...");
236 menuFile
->AppendSeparator();
237 menuFile
->Append(HelpDemo_Html_Help_Index
, "HTML &Help Index...");
238 menuFile
->Append(HelpDemo_Html_Help_Classes
, "HTML &Help on Classes...");
239 menuFile
->Append(HelpDemo_Html_Help_Functions
, "HTML &Help on Functions...");
240 menuFile
->Append(HelpDemo_Html_Help_Help
, "HTML &About Help Demo...");
241 menuFile
->AppendSeparator();
242 menuFile
->Append(HelpDemo_Html_Help_Search
, "HTML &Search help...");
247 menuFile
->AppendSeparator();
248 menuFile
->Append(HelpDemo_Help_KDE
, "Use &KDE");
249 menuFile
->Append(HelpDemo_Help_GNOME
, "Use &GNOME");
250 menuFile
->Append(HelpDemo_Help_Netscape
, "Use &Netscape");
253 menuFile
->AppendSeparator();
254 menuFile
->Append(HelpDemo_Quit
, "E&xit");
256 // now append the freshly created menu to the menu bar...
257 wxMenuBar
*menuBar
= new wxMenuBar
;
258 menuBar
->Append(menuFile
, "&File");
260 // ... and attach this menu bar to the frame
263 // create a status bar just for fun (by default with 1 pane only)
265 SetStatusText("Welcome to wxWindows!");
267 // now create some controls
269 // a panel first - if there were several controls, it would allow us to
270 // navigate between them from the keyboard
271 wxPanel
*panel
= new wxPanel(this, -1, wxPoint(0, 0), wxSize(400, 200));
273 // and a static control whose parent is the panel
274 (void)new wxStaticText(panel
, -1, "Hello, world!", wxPoint(10, 10));
280 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
282 // TRUE is to force the frame to close
286 void MyFrame::OnHelp(wxCommandEvent
& event
)
288 switch(event
.GetId())
291 // Note: For WinHelp, these ids are specified in the map session, mapping
292 // topic names to numbers.
293 // For HTML and external help, a wxhelp.map file is used.
295 case HelpDemo_Help_Classes
:
296 m_help
.DisplaySection(2);
298 case HelpDemo_Help_Functions
:
299 m_help
.DisplaySection(1);
301 case HelpDemo_Help_Help
:
302 m_help
.DisplaySection(3);
305 // These three calls are only used by wxExtHelpController
307 case HelpDemo_Help_KDE
:
308 m_help
.SetViewer("kdehelp");
310 case HelpDemo_Help_GNOME
:
311 m_help
.SetViewer("gnome-help-browser");
313 case HelpDemo_Help_Netscape
:
314 m_help
.SetViewer("netscape", wxHELP_NETSCAPE
);
317 case HelpDemo_Help_Search
:
319 wxString key
= wxGetTextFromUser("Search for?",
320 "Search help for keyword",
324 m_help
.KeywordSearch(key
);
327 case HelpDemo_Help_Index
:
329 m_help
.DisplayContents();
334 void MyFrame::OnHtmlHelp(wxCommandEvent
& event
)
337 switch(event
.GetId())
340 case HelpDemo_Html_Help_Classes
:
341 m_htmlHelp
.DisplaySection(2);
343 case HelpDemo_Html_Help_Functions
:
344 m_htmlHelp
.DisplaySection(1);
346 case HelpDemo_Html_Help_Help
:
347 m_htmlHelp
.DisplaySection(3);
350 case HelpDemo_Html_Help_Search
:
352 wxString key
= wxGetTextFromUser("Search for?",
353 "Search help for keyword",
357 m_htmlHelp
.KeywordSearch(key
);
360 case HelpDemo_Html_Help_Index
:
362 m_htmlHelp
.DisplayContents();