]>
Commit | Line | Data |
---|---|---|
2c997ad0 | 1 | |
5526e819 VS |
2 | ///////////////////////////////////////////////////////////////////////////// |
3 | // Name: test.cpp | |
4 | // Purpose: wxHtml testing example | |
5 | ///////////////////////////////////////////////////////////////////////////// | |
6 | ||
7 | #ifdef __GNUG__ | |
2c997ad0 VS |
8 | #pragma implementation "help.cpp" |
9 | #pragma interface "help.cpp" | |
5526e819 VS |
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> | |
5526e819 VS |
27 | |
28 | // ---------------------------------------------------------------------------- | |
29 | // private classes | |
30 | // ---------------------------------------------------------------------------- | |
31 | ||
2c997ad0 | 32 | |
5526e819 VS |
33 | // Define a new application type, each program should derive a class from wxApp |
34 | class MyApp : public wxApp | |
35 | { | |
5526e819 VS |
36 | public: |
37 | // override base class virtuals | |
38 | // ---------------------------- | |
2c997ad0 | 39 | |
5526e819 VS |
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) | |
2c997ad0 | 43 | virtual bool OnInit(); |
5526e819 VS |
44 | }; |
45 | ||
2c997ad0 VS |
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); | |
8f8ca6c9 | 58 | void OnClose(wxCloseEvent& event); |
2c997ad0 VS |
59 | private: |
60 | wxHtmlHelpController help; | |
5526e819 | 61 | |
2c997ad0 VS |
62 | // any class wishing to process wxWindows events must use this macro |
63 | DECLARE_EVENT_TABLE() | |
64 | }; | |
65 | ||
66 | // ---------------------------------------------------------------------------- | |
67 | // constants | |
68 | // ---------------------------------------------------------------------------- | |
69 | ||
70 | // IDs for the controls and the menu commands | |
71 | enum | |
72 | { | |
73 | // menu items | |
74 | Minimal_Quit = 1, | |
75 | Minimal_Help | |
76 | }; | |
77 | ||
78 | // ---------------------------------------------------------------------------- | |
79 | // event tables and other macros for wxWindows | |
80 | // ---------------------------------------------------------------------------- | |
5526e819 | 81 | |
2c997ad0 VS |
82 | // the event tables connect the wxWindows events with the functions (event |
83 | // handlers) which process them. It can be also done at run-time, but for the | |
84 | // simple menu events like this the static method is much simpler. | |
85 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
86 | EVT_MENU(Minimal_Quit, MyFrame::OnQuit) | |
87 | EVT_MENU(Minimal_Help, MyFrame::OnHelp) | |
8f8ca6c9 | 88 | EVT_CLOSE(MyFrame::OnClose) |
2c997ad0 VS |
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 | |
5526e819 VS |
106 | bool MyApp::OnInit() |
107 | { | |
047640f2 | 108 | wxInitAllImageHandlers(); |
2c997ad0 | 109 | |
5612e524 VS |
110 | SetVendorName("wxWindows"); |
111 | SetAppName("wxHTMLHelp"); | |
112 | ||
2c997ad0 VS |
113 | // Create the main application window |
114 | MyFrame *frame = new MyFrame("HTML Help Sample", | |
115 | wxPoint(50, 50), wxSize(150, 50)); | |
116 | ||
117 | // Show it and tell the application that it's our main window | |
118 | // @@@ what does it do exactly, in fact? is it necessary here? | |
119 | frame->Show(TRUE); | |
120 | SetTopWindow(frame); | |
121 | ||
122 | ||
123 | // success: wxApp::OnRun() will be called which will enter the main message | |
124 | // loop and the application will run. If we returned FALSE here, the | |
125 | // application would exit immediately. | |
5526e819 VS |
126 | return TRUE; |
127 | } | |
2c997ad0 VS |
128 | |
129 | // ---------------------------------------------------------------------------- | |
130 | // main frame | |
131 | // ---------------------------------------------------------------------------- | |
132 | ||
133 | ||
134 | // frame constructor | |
135 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
136 | : wxFrame((wxFrame *)NULL, -1, title, pos, size), help() | |
137 | { | |
138 | // create a menu bar | |
139 | wxMenu *menuFile = new wxMenu; | |
140 | ||
141 | menuFile->Append(Minimal_Help, "&Help"); | |
142 | menuFile->Append(Minimal_Quit, "E&xit"); | |
143 | ||
144 | // now append the freshly created menu to the menu bar... | |
145 | wxMenuBar *menuBar = new wxMenuBar; | |
146 | menuBar->Append(menuFile, "&File"); | |
147 | ||
148 | // ... and attach this menu bar to the frame | |
149 | SetMenuBar(menuBar); | |
150 | ||
5612e524 | 151 | help.UseConfig(wxConfig::Get()); |
8ec2b484 | 152 | bool ret; |
95b1b9d3 | 153 | help.SetTempDir("."); |
8ec2b484 HH |
154 | ret = help.AddBook("helpfiles/testing.hhp"); |
155 | if (! ret) | |
156 | wxMessageBox("Failed adding book helpfiles/testing.hhp"); | |
157 | ret = help.AddBook("helpfiles/another.hhp"); | |
158 | if (! ret) | |
159 | wxMessageBox("Failed adding book helpfiles/another.hhp"); | |
2c997ad0 VS |
160 | } |
161 | ||
162 | ||
163 | // event handlers | |
164 | ||
165 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
5526e819 | 166 | { |
2c997ad0 | 167 | // TRUE is to force the frame to close |
2c997ad0 | 168 | Close(TRUE); |
5526e819 VS |
169 | } |
170 | ||
2c997ad0 VS |
171 | void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event)) |
172 | { | |
173 | help.Display("Main page"); | |
174 | } | |
175 | ||
8f8ca6c9 HH |
176 | void MyFrame::OnClose(wxCloseEvent& event) |
177 | { | |
178 | // Close the help frame; this will cause the config data to | |
179 | // get written. | |
180 | if ( help.GetFrame() ) // returns NULL if no help frame active | |
181 | help.GetFrame()->Close(TRUE); | |
182 | // now we can safely delete the config pointer | |
8f8ca6c9 | 183 | event.Skip(); |
5612e524 | 184 | delete wxConfig::Set(NULL); |
8f8ca6c9 HH |
185 | } |
186 | ||
2c997ad0 VS |
187 | |
188 | ||
5526e819 VS |
189 | |
190 | ||
191 | ||
192 |