]>
git.saurik.com Git - wxWidgets.git/blob - samples/help/demo.cpp
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 #pragma implementation "demo.cpp"
21 #pragma interface "demo.cpp"
24 // For compilers that support precompilation, includes "wx/wx.h".
25 #include "wx/wxprec.h"
31 // for all others, include the necessary headers (this file is usually all you
32 // need because it includes almost all "standard" wxWindows headers
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
42 // the application icon
43 #if defined(__WXGTK__) || defined(__WXMOTIF__)
44 #include "mondrian.xpm"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 // Define a new application type, each program should derive a class from wxApp
52 class MyApp
: public wxApp
55 // override base class virtuals
56 // ----------------------------
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();
64 // Define a new frame type: this is going to be our main frame
65 class MyFrame
: public wxFrame
69 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
71 // event handlers (these functions should _not_ be virtual)
72 void OnQuit(wxCommandEvent
& event
);
73 void OnHelp(wxCommandEvent
& event
);
76 wxHelpController help
;
77 // any class wishing to process wxWindows events must use this macro
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 // IDs for the controls and the menu commands
91 HelpDemo_Help_Classes
,
92 HelpDemo_Help_Functions
,
96 HelpDemo_Help_Netscape
,
98 // controls start here (the numbers are, of course, arbitrary)
102 // ----------------------------------------------------------------------------
103 // event tables and other macros for wxWindows
104 // ----------------------------------------------------------------------------
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
)
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
128 // ============================================================================
130 // ============================================================================
132 // ----------------------------------------------------------------------------
133 // the application class
134 // ----------------------------------------------------------------------------
136 // `Main program' equivalent: the program execution "starts" here
139 // Create the main application window
140 MyFrame
*frame
= new MyFrame("HelpDemo wxWindows App",
141 wxPoint(50, 50), wxSize(450, 340));
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.
152 // ----------------------------------------------------------------------------
154 // ----------------------------------------------------------------------------
157 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
158 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
160 // set the frame icon
161 SetIcon(wxICON(mondrian
));
164 wxMenu
*menuFile
= new wxMenu
;
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...");
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");
178 menuFile
->AppendSeparator();
179 menuFile
->Append(HelpDemo_Quit
, "E&xit");
181 // now append the freshly created menu to the menu bar...
182 wxMenuBar
*menuBar
= new wxMenuBar
;
183 menuBar
->Append(menuFile
, "&File");
185 // ... and attach this menu bar to the frame
188 // create a status bar just for fun (by default with 1 pane only)
190 SetStatusText("Welcome to wxWindows!");
192 // now create some controls
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));
198 // and a static control whose parent is the panel
199 (void)new wxStaticText(panel
, -1, "Hello, world!", wxPoint(10, 10));
201 // initialise the help system
202 help
.Initialize("doc");
209 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
211 // TRUE is to force the frame to close
215 void MyFrame::OnHelp(wxCommandEvent
& event
)
217 switch(event
.GetId())
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.
223 case HelpDemo_Help_Classes
:
224 help
.DisplaySection(1);
226 case HelpDemo_Help_Functions
:
227 help
.DisplaySection(2);
229 case HelpDemo_Help_Help
:
230 help
.DisplaySection(5);
233 // These three calls are only used by wxExtHelpController
235 case HelpDemo_Help_KDE
:
236 help
.SetViewer("kdehelp");
238 case HelpDemo_Help_GNOME
:
239 help
.SetViewer("gnome-help-browser");
241 case HelpDemo_Help_Netscape
:
242 help
.SetViewer("netscape", wxHELP_NETSCAPE
);
245 case HelpDemo_Help_Search
:
247 wxString key
= wxGetTextFromUser("Search for?",
248 "Search help for keyword",
252 help
.KeywordSearch(key
);
255 case HelpDemo_Help_Index
:
257 help
.DisplayContents();