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