]>
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
37 #include "wx/helpbase.h"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
43 // the application icon
44 #if defined(__WXGTK__) || defined(__WXMOTIF__)
45 #include "mondrian.xpm"
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 // Define a new application type, each program should derive a class from wxApp
53 class MyApp
: public wxApp
56 // override base class virtuals
57 // ----------------------------
59 // this one is called on application startup and is a good place for the app
60 // initialization (doing it here and not in the ctor allows to have an error
61 // return: if OnInit() returns false, the application terminates)
62 virtual bool OnInit();
65 // Define a new frame type: this is going to be our main frame
66 class MyFrame
: public wxFrame
70 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
72 // event handlers (these functions should _not_ be virtual)
73 void OnQuit(wxCommandEvent
& event
);
74 void OnHelp(wxCommandEvent
& event
);
77 wxHelpController help
;
78 // any class wishing to process wxWindows events must use this macro
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 // IDs for the controls and the menu commands
92 HelpDemo_Help_Classes
,
93 HelpDemo_Help_Functions
,
97 HelpDemo_Help_Netscape
,
99 // controls start here (the numbers are, of course, arbitrary)
100 HelpDemo_Text
= 1000,
103 // ----------------------------------------------------------------------------
104 // event tables and other macros for wxWindows
105 // ----------------------------------------------------------------------------
107 // the event tables connect the wxWindows events with the functions (event
108 // handlers) which process them. It can be also done at run-time, but for the
109 // simple menu events like this the static method is much simpler.
110 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
111 EVT_MENU(HelpDemo_Quit
, MyFrame::OnQuit
)
112 EVT_MENU(HelpDemo_Help_Index
, MyFrame::OnHelp
)
113 EVT_MENU(HelpDemo_Help_Classes
, MyFrame::OnHelp
)
114 EVT_MENU(HelpDemo_Help_Functions
, MyFrame::OnHelp
)
115 EVT_MENU(HelpDemo_Help_Help
, MyFrame::OnHelp
)
116 EVT_MENU(HelpDemo_Help_KDE
, MyFrame::OnHelp
)
117 EVT_MENU(HelpDemo_Help_GNOME
, MyFrame::OnHelp
)
118 EVT_MENU(HelpDemo_Help_Netscape
, MyFrame::OnHelp
)
119 EVT_MENU(HelpDemo_Help_Search
, MyFrame::OnHelp
)
122 // Create a new application object: this macro will allow wxWindows to create
123 // the application object during program execution (it's better than using a
124 // static object for many reasons) and also declares the accessor function
125 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
129 // ============================================================================
131 // ============================================================================
133 // ----------------------------------------------------------------------------
134 // the application class
135 // ----------------------------------------------------------------------------
137 // `Main program' equivalent: the program execution "starts" here
140 // Create the main application window
141 MyFrame
*frame
= new MyFrame("HelpDemo wxWindows App",
142 wxPoint(50, 50), wxSize(450, 340));
147 // success: wxApp::OnRun() will be called which will enter the main message
148 // loop and the application will run. If we returned FALSE here, the
149 // application would exit immediately.
153 // ----------------------------------------------------------------------------
155 // ----------------------------------------------------------------------------
158 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
159 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
161 // set the frame icon
162 SetIcon(wxICON(mondrian
));
165 wxMenu
*menuFile
= new wxMenu
;
167 menuFile
->Append(HelpDemo_Help_Index
, "&Help Index...");
168 menuFile
->Append(HelpDemo_Help_Classes
, "&Help on Classes...");
169 menuFile
->Append(HelpDemo_Help_Functions
, "&Help on Functions...");
170 menuFile
->Append(HelpDemo_Help_Help
, "&About Help Demo...");
171 menuFile
->AppendSeparator();
172 menuFile
->Append(HelpDemo_Help_Search
, "&Search help...");
174 menuFile
->AppendSeparator();
175 menuFile
->Append(HelpDemo_Help_KDE
, "Use &KDE");
176 menuFile
->Append(HelpDemo_Help_GNOME
, "Use &GNOME");
177 menuFile
->Append(HelpDemo_Help_Netscape
, "Use &Netscape");
179 menuFile
->AppendSeparator();
180 menuFile
->Append(HelpDemo_Quit
, "E&xit");
182 // now append the freshly created menu to the menu bar...
183 wxMenuBar
*menuBar
= new wxMenuBar
;
184 menuBar
->Append(menuFile
, "&File");
186 // ... and attach this menu bar to the frame
189 // create a status bar just for fun (by default with 1 pane only)
191 SetStatusText("Welcome to wxWindows!");
193 // now create some controls
195 // a panel first - if there were several controls, it would allow us to
196 // navigate between them from the keyboard
197 wxPanel
*panel
= new wxPanel(this, -1, wxPoint(0, 0), wxSize(400, 200));
199 // and a static control whose parent is the panel
200 (void)new wxStaticText(panel
, -1, "Hello, world!", wxPoint(10, 10));
202 // initialise the help system
203 help
.Initialize("doc");
210 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
212 // TRUE is to force the frame to close
216 void MyFrame::OnHelp(wxCommandEvent
& event
)
218 switch(event
.GetId())
221 // Note: these DisplaySection calls use ids that are specific to wxExtHelpController
222 // (on Unix). For WinHelp, we'd need to use different context ids.
224 case HelpDemo_Help_Classes
:
225 help
.DisplaySection(1);
227 case HelpDemo_Help_Functions
:
228 help
.DisplaySection(2);
230 case HelpDemo_Help_Help
:
231 help
.DisplaySection(5);
234 // These three calls are only used by wxExtHelpController
236 case HelpDemo_Help_KDE
:
237 help
.SetViewer("kdehelp");
239 case HelpDemo_Help_GNOME
:
240 help
.SetViewer("gnome-help-browser");
242 case HelpDemo_Help_Netscape
:
243 help
.SetViewer("netscape", wxHELP_NETSCAPE
);
246 case HelpDemo_Help_Search
:
248 wxString key
= wxGetTextFromUser("Search for?",
249 "Search help for keyword",
253 help
.KeywordSearch(key
);
256 case HelpDemo_Help_Index
:
258 help
.DisplayContents();