]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: virtua;.cpp | |
3 | // Purpose: wxHtml testing example | |
4 | // demonstrates virtual file systems feature | |
5 | ///////////////////////////////////////////////////////////////////////////// | |
6 | ||
7 | #ifdef __GNUG__ | |
8 | #pragma implementation "test.cpp" | |
9 | #pragma interface "test.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 | ||
26 | #include <wx/html/htmlwin.h> | |
27 | ||
28 | ||
29 | ||
30 | ||
31 | /* | |
32 | ||
33 | ||
34 | TAG HANDER FOR 'MYBIND' TAG | |
35 | ||
36 | ||
37 | */ | |
38 | ||
39 | #include <wx/html/m_templ.h> | |
40 | ||
41 | ||
42 | TAG_HANDLER_BEGIN(MYBIND, "MYBIND") | |
43 | ||
44 | TAG_HANDLER_PROC(tag) | |
45 | { | |
46 | wxWindow *wnd; | |
47 | int ax, ay; | |
48 | int fl = 0; | |
49 | ||
50 | tag.ScanParam("X", "%i", &ax); | |
51 | tag.ScanParam("Y", "%i", &ay); | |
52 | if (tag.HasParam("FLOAT")) fl = ax; | |
53 | ||
54 | wnd = new wxTextCtrl( m_WParser -> GetWindow(), -1, tag.GetParam("NAME"), | |
55 | wxPoint(0,0), wxSize(ax, ay), wxTE_MULTILINE ); | |
56 | wnd -> Show(TRUE); | |
57 | ||
58 | m_WParser -> OpenContainer() -> InsertCell(new wxHtmlWidgetCell(wnd, fl)); | |
59 | ||
60 | return FALSE; | |
61 | } | |
62 | ||
63 | TAG_HANDLER_END(MYBIND) | |
64 | ||
65 | ||
66 | ||
67 | TAGS_MODULE_BEGIN(MyBind) | |
68 | ||
69 | TAGS_MODULE_ADD(MYBIND) | |
70 | ||
71 | TAGS_MODULE_END(MyBind) | |
72 | ||
73 | ||
74 | ||
75 | ||
76 | ||
77 | ||
78 | ||
79 | ||
80 | ||
81 | // ---------------------------------------------------------------------------- | |
82 | // private classes | |
83 | // ---------------------------------------------------------------------------- | |
84 | ||
85 | // Define a new application type, each program should derive a class from wxApp | |
86 | class MyApp : public wxApp | |
87 | { | |
88 | public: | |
89 | // override base class virtuals | |
90 | // ---------------------------- | |
91 | ||
92 | // this one is called on application startup and is a good place for the app | |
93 | // initialization (doing it here and not in the ctor allows to have an error | |
94 | // return: if OnInit() returns false, the application terminates) | |
95 | virtual bool OnInit(); | |
96 | }; | |
97 | ||
98 | // Define a new frame type: this is going to be our main frame | |
99 | class MyFrame : public wxFrame | |
100 | { | |
101 | public: | |
102 | // ctor(s) | |
103 | MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); | |
104 | ||
105 | // event handlers (these functions should _not_ be virtual) | |
106 | void OnQuit(wxCommandEvent& event); | |
107 | void OnAbout(wxCommandEvent& event); | |
108 | void OnBack(wxCommandEvent& event); | |
109 | void OnForward(wxCommandEvent& event); | |
110 | ||
111 | private: | |
112 | // any class wishing to process wxWindows events must use this macro | |
113 | DECLARE_EVENT_TABLE() | |
114 | }; | |
115 | ||
116 | // ---------------------------------------------------------------------------- | |
117 | // constants | |
118 | // ---------------------------------------------------------------------------- | |
119 | ||
120 | // IDs for the controls and the menu commands | |
121 | enum | |
122 | { | |
123 | // menu items | |
124 | Minimal_Quit = 1, | |
125 | Minimal_About, | |
126 | Minimal_Back, | |
127 | Minimal_Forward, | |
128 | ||
129 | // controls start here (the numbers are, of course, arbitrary) | |
130 | Minimal_Text = 1000, | |
131 | }; | |
132 | ||
133 | // ---------------------------------------------------------------------------- | |
134 | // event tables and other macros for wxWindows | |
135 | // ---------------------------------------------------------------------------- | |
136 | ||
137 | // the event tables connect the wxWindows events with the functions (event | |
138 | // handlers) which process them. It can be also done at run-time, but for the | |
139 | // simple menu events like this the static method is much simpler. | |
140 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
141 | EVT_MENU(Minimal_Quit, MyFrame::OnQuit) | |
142 | EVT_MENU(Minimal_About, MyFrame::OnAbout) | |
143 | EVT_MENU(Minimal_Back, MyFrame::OnBack) | |
144 | EVT_MENU(Minimal_Forward, MyFrame::OnForward) | |
145 | END_EVENT_TABLE() | |
146 | ||
147 | // Create a new application object: this macro will allow wxWindows to create | |
148 | // the application object during program execution (it's better than using a | |
149 | // static object for many reasons) and also declares the accessor function | |
150 | // wxGetApp() which will return the reference of the right type (i.e. MyApp and | |
151 | // not wxApp) | |
152 | IMPLEMENT_APP(MyApp) | |
153 | ||
154 | // ============================================================================ | |
155 | // implementation | |
156 | // ============================================================================ | |
157 | ||
158 | // ---------------------------------------------------------------------------- | |
159 | // the application class | |
160 | // ---------------------------------------------------------------------------- | |
161 | ||
162 | // `Main program' equivalent: the program execution "starts" here | |
163 | bool MyApp::OnInit() | |
164 | { | |
165 | // Create the main application window | |
166 | MyFrame *frame = new MyFrame("wxHtmlWindow testing application", | |
167 | wxPoint(50, 50), wxSize(640, 480)); | |
168 | ||
169 | // Show it and tell the application that it's our main window | |
170 | // @@@ what does it do exactly, in fact? is it necessary here? | |
171 | frame->Show(TRUE); | |
172 | SetTopWindow(frame); | |
173 | ||
174 | // success: wxApp::OnRun() will be called which will enter the main message | |
175 | // loop and the application will run. If we returned FALSE here, the | |
176 | // application would exit immediately. | |
177 | return TRUE; | |
178 | } | |
179 | ||
180 | // ---------------------------------------------------------------------------- | |
181 | // main frame | |
182 | // ---------------------------------------------------------------------------- | |
183 | ||
184 | wxHtmlWindow *html; | |
185 | ||
186 | // frame constructor | |
187 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
188 | : wxFrame((wxFrame *)NULL, -1, title, pos, size) | |
189 | { | |
190 | // create a menu bar | |
191 | wxMenu *menuFile = new wxMenu; | |
192 | wxMenu *menuNav = new wxMenu; | |
193 | ||
194 | menuFile->Append(Minimal_Quit, "E&xit"); | |
195 | menuNav->Append(Minimal_Back, "Go &BACK"); | |
196 | menuNav->Append(Minimal_Forward, "Go &FORWARD"); | |
197 | ||
198 | // now append the freshly created menu to the menu bar... | |
199 | wxMenuBar *menuBar = new wxMenuBar; | |
200 | menuBar->Append(menuFile, "&File"); | |
201 | menuBar->Append(menuNav, "&Navigate"); | |
202 | ||
203 | // ... and attach this menu bar to the frame | |
204 | SetMenuBar(menuBar); | |
205 | ||
206 | CreateStatusBar(2); | |
207 | ||
208 | html = new wxHtmlWindow(this); | |
209 | html -> SetRelatedFrame(this, "VFS Demo: '%s'"); | |
210 | html -> SetRelatedStatusBar(1); | |
211 | html -> LoadPage("start.htm"); | |
212 | } | |
213 | ||
214 | ||
215 | // event handlers | |
216 | ||
217 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
218 | { | |
219 | // TRUE is to force the frame to close | |
220 | Close(TRUE); | |
221 | } | |
222 | ||
223 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
224 | { | |
225 | } | |
226 | ||
227 | ||
228 | ||
229 | void MyFrame::OnBack(wxCommandEvent& WXUNUSED(event)) | |
230 | { | |
231 | if (!html -> HistoryBack()) wxMessageBox("You reached prehistory era!"); | |
232 | } | |
233 | ||
234 | ||
235 | void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event)) | |
236 | { | |
237 | if (!html -> HistoryForward()) wxMessageBox("No more items in history!"); | |
238 | } | |
239 | ||
240 | ||
241 | ||
242 | ||
243 | ||
244 |