remove extraneous commas and semicolons (patch 1537792)
[wxWidgets.git] / samples / html / widget / widget.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: widget.cpp
3 // Purpose: wxHtml testing example
4 // Demonstrates embedded controls
5 /////////////////////////////////////////////////////////////////////////////
6
7 // For compilers that support precompilation, includes "wx/wx.h".
8 #include "wx/wxprec.h"
9
10 #ifdef __BORLANDC__
11 #pragma hdrstop
12 #endif
13
14 // for all others, include the necessary headers (this file is usually all you
15 // need because it includes almost all "standard" wxWidgets headers
16 #ifndef WX_PRECOMP
17 #include "wx/wx.h"
18 #endif
19
20
21 #include "wx/html/htmlwin.h"
22
23 #include "../../sample.xpm"
24
25
26 /*
27
28
29 TAG HANDER FOR 'MYBIND' TAG
30
31
32 */
33
34 #include "wx/html/m_templ.h"
35
36
37 TAG_HANDLER_BEGIN(MYBIND, "MYBIND")
38
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;
49
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 );
59
60 wnd->Show(true);
61
62 m_WParser->GetContainer()->InsertCell(new wxHtmlWidgetCell(wnd, fl));
63
64 return false;
65 }
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
78 // ----------------------------------------------------------------------------
79 // private classes
80 // ----------------------------------------------------------------------------
81
82 // Define a new application type, each program should derive a class from wxApp
83 class MyApp : public wxApp
84 {
85 public:
86 // override base class virtuals
87 // ----------------------------
88
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)
92 virtual bool OnInit();
93 };
94
95 // Define a new frame type: this is going to be our main frame
96 class MyFrame : public wxFrame
97 {
98 public:
99 // ctor(s)
100 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
101
102 // event handlers (these functions should _not_ be virtual)
103 void OnQuit(wxCommandEvent& event);
104 void OnBack(wxCommandEvent& event);
105 void OnForward(wxCommandEvent& event);
106
107 private:
108 // any class wishing to process wxWidgets events must use this macro
109 DECLARE_EVENT_TABLE()
110 };
111
112 // ----------------------------------------------------------------------------
113 // constants
114 // ----------------------------------------------------------------------------
115
116 // IDs for the controls and the menu commands
117 enum
118 {
119 // menu items
120 Minimal_Quit = 1,
121 Minimal_Back,
122 Minimal_Forward,
123
124 // controls start here (the numbers are, of course, arbitrary)
125 Minimal_Text = 1000
126 };
127
128 // ----------------------------------------------------------------------------
129 // event tables and other macros for wxWidgets
130 // ----------------------------------------------------------------------------
131
132 // the event tables connect the wxWidgets events with the functions (event
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.
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
141 // Create a new application object: this macro will allow wxWidgets to create
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 {
159 // Create the main application window
160 MyFrame *frame = new MyFrame( _("wxHtmlWindow testing application"),
161 wxDefaultPosition, wxSize(640, 480) );
162
163 // Show it and tell the application that it's our main window
164 // @@@ what does it do exactly, in fact? is it necessary here?
165 frame->Show(true);
166 SetTopWindow(frame);
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 // create a menu bar
185 wxMenu *menuFile = new wxMenu;
186 wxMenu *menuNav = new wxMenu;
187
188 menuFile->Append(Minimal_Quit, _("E&xit"));
189 menuNav->Append(Minimal_Back, _("Go &BACK"));
190 menuNav->Append(Minimal_Forward, _("Go &FORWARD"));
191
192 // now append the freshly created menu to the menu bar...
193 wxMenuBar *menuBar = new wxMenuBar;
194 menuBar->Append(menuFile, _("&File"));
195 menuBar->Append(menuNav, _("&Navigate"));
196
197 // ... and attach this menu bar to the frame
198 SetMenuBar(menuBar);
199
200 SetIcon(wxIcon(sample_xpm));
201
202 #if wxUSE_STATUSBAR
203 CreateStatusBar(2);
204 #endif // wxUSE_STATUSBAR
205
206 html = new wxHtmlWindow(this);
207 html -> SetRelatedFrame(this, _("wxHTML Demo: '%s'"));
208 #if wxUSE_STATUSBAR
209 html -> SetRelatedStatusBar(1);
210 #endif // wxUSE_STATUSBAR
211 html -> LoadPage(wxT("start.htm"));
212
213 }
214
215
216 // event handlers
217
218 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
219 {
220 // true is to force the frame to close
221 Close(true);
222 }
223
224 void MyFrame::OnBack(wxCommandEvent& WXUNUSED(event))
225 {
226 if (!html -> HistoryBack()) wxMessageBox(_("You reached prehistory era!"));
227 }
228
229
230 void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event))
231 {
232 if (!html -> HistoryForward()) wxMessageBox(_("No more items in history!"));
233 }