]>
git.saurik.com Git - wxWidgets.git/blob - samples/help/demo.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Minimal wxWindows sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #pragma implementation "minimal.cpp"
21 #pragma interface "minimal.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
93 Minimal_Help_Functions
,
97 Minimal_Help_Netscape
,
99 // controls start here (the numbers are, of course, arbitrary)
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(Minimal_Quit
, MyFrame::OnQuit
)
112 EVT_MENU(Minimal_Help_Index
, MyFrame::OnHelp
)
113 EVT_MENU(Minimal_Help_Classes
, MyFrame::OnHelp
)
114 EVT_MENU(Minimal_Help_Functions
, MyFrame::OnHelp
)
115 EVT_MENU(Minimal_Help_Help
, MyFrame::OnHelp
)
116 EVT_MENU(Minimal_Help_KDE
, MyFrame::OnHelp
)
117 EVT_MENU(Minimal_Help_GNOME
, MyFrame::OnHelp
)
118 EVT_MENU(Minimal_Help_Netscape
, MyFrame::OnHelp
)
119 EVT_MENU(Minimal_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("Minimal wxWindows App",
142 wxPoint(50, 50), wxSize(450, 340));
144 // Show it and tell the application that it's our main window
145 // @@@ what does it do exactly, in fact? is it necessary here?
149 // success: wxApp::OnRun() will be called which will enter the main message
150 // loop and the application will run. If we returned FALSE here, the
151 // application would exit immediately.
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
160 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
161 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
163 // set the frame icon
164 SetIcon(wxICON(mondrian
));
167 wxMenu
*menuFile
= new wxMenu
;
169 menuFile
->Append(Minimal_Help_Index
, "&Help Index...");
170 menuFile
->Append(Minimal_Help_Classes
, "&Help on Classes...");
171 menuFile
->Append(Minimal_Help_Functions
, "&Help on Functions...");
172 menuFile
->Append(Minimal_Help_Help
, "&About wxExtHelpController...");
173 menuFile
->AppendSeparator();
174 menuFile
->Append(Minimal_Help_Search
, "&Search help...");
175 if(help
.IsKindOf(CLASSINFO(wxExtHelpController
)))
177 menuFile
->AppendSeparator();
178 menuFile
->Append(Minimal_Help_KDE
, "Use &KDE");
179 menuFile
->Append(Minimal_Help_GNOME
, "Use &GNOME");
180 menuFile
->Append(Minimal_Help_Netscape
, "Use &Netscape");
182 menuFile
->AppendSeparator();
183 menuFile
->Append(Minimal_Quit
, "E&xit");
185 // now append the freshly created menu to the menu bar...
186 wxMenuBar
*menuBar
= new wxMenuBar
;
187 menuBar
->Append(menuFile
, "&File");
189 // ... and attach this menu bar to the frame
192 // create a status bar just for fun (by default with 1 pane only)
194 SetStatusText("Welcome to wxWindows!");
196 // now create some controls
198 // a panel first - if there were several controls, it would allow us to
199 // navigate between them from the keyboard
200 wxPanel
*panel
= new wxPanel(this, -1, wxPoint(0, 0), wxSize(400, 200));
202 // and a static control whose parent is the panel
203 (void)new wxStaticText(panel
, -1, "Hello, world!", wxPoint(10, 10));
205 // initialise the help system
206 help
.Initialize("doc");
213 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
215 // TRUE is to force the frame to close
219 void MyFrame::OnHelp(wxCommandEvent
& event
)
221 switch(event
.GetId())
223 case Minimal_Help_Classes
:
224 help
.DisplaySection(1);
226 case Minimal_Help_Functions
:
227 help
.DisplaySection(2);
229 case Minimal_Help_Help
:
230 help
.DisplaySection(5);
232 case Minimal_Help_KDE
:
233 if(help
.IsKindOf(CLASSINFO(wxExtHelpController
)))
234 ((wxExtHelpController
*)&help
)->SetBrowser("kdehelp");
236 case Minimal_Help_GNOME
:
237 if(help
.IsKindOf(CLASSINFO(wxExtHelpController
)))
238 ((wxExtHelpController
*)&help
)->SetBrowser("gnome-help-browser");
240 case Minimal_Help_Netscape
:
241 if(help
.IsKindOf(CLASSINFO(wxExtHelpController
)))
242 ((wxExtHelpController
*)&help
)->SetBrowser("netscape",TRUE
);
244 case Minimal_Help_Search
:
246 wxString key
= wxGetTextFromUser("Search for?",
247 "Search help for keyword",
251 help
.KeywordSearch(key
);
254 case Minimal_Help_Index
:
256 help
.DisplayContents();