]> git.saurik.com Git - wxWidgets.git/blob - samples/html/help/help.cpp
Added sqltypes.h (for Cygwin b20), some other Cygwin fixes.
[wxWidgets.git] / samples / html / help / help.cpp
1
2 /////////////////////////////////////////////////////////////////////////////
3 // Name: test.cpp
4 // Purpose: wxHtml testing example
5 /////////////////////////////////////////////////////////////////////////////
6
7 #ifdef __GNUG__
8 #pragma implementation "help.cpp"
9 #pragma interface "help.cpp"
10 #endif
11
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include <wx/wxprec.h>
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 // for all others, include the necessary headers (this file is usually all you
20 // need because it includes almost all "standard" wxWindows headers
21 #ifndef WX_PRECOMP
22 #include <wx/wx.h>
23 #endif
24
25 #include <wx/image.h>
26 #include <wx/wxhtml.h>
27
28 // ----------------------------------------------------------------------------
29 // private classes
30 // ----------------------------------------------------------------------------
31
32
33 // Define a new application type, each program should derive a class from wxApp
34 class MyApp : public wxApp
35 {
36 public:
37 // override base class virtuals
38 // ----------------------------
39
40 // this one is called on application startup and is a good place for the app
41 // initialization (doing it here and not in the ctor allows to have an error
42 // return: if OnInit() returns false, the application terminates)
43 virtual bool OnInit();
44 };
45
46
47
48 // Define a new frame type: this is going to be our main frame
49 class MyFrame : public wxFrame
50 {
51 public:
52 // ctor(s)
53 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
54
55 // event handlers (these functions should _not_ be virtual)
56 void OnQuit(wxCommandEvent& event);
57 void OnHelp(wxCommandEvent& event);
58
59 private:
60 wxHtmlHelpController help;
61 wxConfig* config;
62
63 // any class wishing to process wxWindows events must use this macro
64 DECLARE_EVENT_TABLE()
65 };
66
67 // ----------------------------------------------------------------------------
68 // constants
69 // ----------------------------------------------------------------------------
70
71 // IDs for the controls and the menu commands
72 enum
73 {
74 // menu items
75 Minimal_Quit = 1,
76 Minimal_Help
77 };
78
79 // ----------------------------------------------------------------------------
80 // event tables and other macros for wxWindows
81 // ----------------------------------------------------------------------------
82
83 // the event tables connect the wxWindows events with the functions (event
84 // handlers) which process them. It can be also done at run-time, but for the
85 // simple menu events like this the static method is much simpler.
86 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
87 EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
88 EVT_MENU(Minimal_Help, MyFrame::OnHelp)
89 END_EVENT_TABLE()
90
91 // Create a new application object: this macro will allow wxWindows to create
92 // the application object during program execution (it's better than using a
93 // static object for many reasons) and also declares the accessor function
94 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
95 // not wxApp)
96 IMPLEMENT_APP(MyApp)
97
98 // ============================================================================
99 // implementation
100 // ============================================================================
101
102 // ----------------------------------------------------------------------------
103 // the application class
104 // ----------------------------------------------------------------------------
105 // `Main program' equivalent: the program execution "starts" here
106 bool MyApp::OnInit()
107 {
108 #if wxUSE_LIBPNG
109 wxImage::AddHandler(new wxPNGHandler);
110 #endif
111 #if wxUSE_LIBJPEG
112 wxImage::AddHandler(new wxJPEGHandler);
113 #endif
114
115 // Create the main application window
116 MyFrame *frame = new MyFrame("HTML Help Sample",
117 wxPoint(50, 50), wxSize(150, 50));
118
119 // Show it and tell the application that it's our main window
120 // @@@ what does it do exactly, in fact? is it necessary here?
121 frame->Show(TRUE);
122 SetTopWindow(frame);
123
124
125 // success: wxApp::OnRun() will be called which will enter the main message
126 // loop and the application will run. If we returned FALSE here, the
127 // application would exit immediately.
128 return TRUE;
129 }
130
131 // ----------------------------------------------------------------------------
132 // main frame
133 // ----------------------------------------------------------------------------
134
135
136 // frame constructor
137 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
138 : wxFrame((wxFrame *)NULL, -1, title, pos, size), help()
139 {
140 // create a menu bar
141 wxMenu *menuFile = new wxMenu;
142
143 menuFile->Append(Minimal_Help, "&Help");
144 menuFile->Append(Minimal_Quit, "E&xit");
145
146 // now append the freshly created menu to the menu bar...
147 wxMenuBar *menuBar = new wxMenuBar;
148 menuBar->Append(menuFile, "&File");
149
150 // ... and attach this menu bar to the frame
151 SetMenuBar(menuBar);
152
153 config = new wxConfig("wxHTMLhelp");
154
155 help.UseConfig(config);
156 bool ret;
157 ret = help.AddBook("helpfiles/testing.hhp");
158 if (! ret)
159 wxMessageBox("Failed adding book helpfiles/testing.hhp");
160 ret = help.AddBook("helpfiles/another.hhp");
161 if (! ret)
162 wxMessageBox("Failed adding book helpfiles/another.hhp");
163 }
164
165
166 // event handlers
167
168 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
169 {
170 // TRUE is to force the frame to close
171 delete config;
172 Close(TRUE);
173 }
174
175
176
177
178 void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
179 {
180 help.Display("Main page");
181 }
182
183
184
185
186
187
188