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