]> git.saurik.com Git - wxWidgets.git/blame_incremental - samples/html/widget/widget.cpp
WinCE build fix.
[wxWidgets.git] / samples / html / widget / widget.cpp
... / ...
CommitLineData
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
29TAG HANDER FOR 'MYBIND' TAG
30
31
32*/
33
34#include "wx/html/m_templ.h"
35
36
37TAG_HANDLER_BEGIN(MYBIND, "MYBIND")
38
39TAG_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
67TAG_HANDLER_END(MYBIND)
68
69
70
71TAGS_MODULE_BEGIN(MyBind)
72
73 TAGS_MODULE_ADD(MYBIND)
74
75TAGS_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
83class MyApp : public wxApp
84{
85public:
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
96class MyFrame : public wxFrame
97{
98public:
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
107private:
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
117enum
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.
135BEGIN_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)
139END_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)
146IMPLEMENT_APP(MyApp)
147
148// ============================================================================
149// implementation
150// ============================================================================
151
152// ----------------------------------------------------------------------------
153// the application class
154// ----------------------------------------------------------------------------
155
156// `Main program' equivalent: the program execution "starts" here
157bool MyApp::OnInit()
158{
159 if ( !wxApp::OnInit() )
160 return false;
161
162 // Create the main application window
163 MyFrame *frame = new MyFrame( _("wxHtmlWindow testing application"),
164 wxDefaultPosition, wxSize(640, 480) );
165
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?
168 frame->Show(true);
169 SetTopWindow(frame);
170
171 // success: wxApp::OnRun() will be called which will enter the main message
172 // loop and the application will run. If we returned false here, the
173 // application would exit immediately.
174 return true;
175}
176
177// ----------------------------------------------------------------------------
178// main frame
179// ----------------------------------------------------------------------------
180
181wxHtmlWindow *html;
182
183// frame constructor
184MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
185: wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size)
186{
187 // create a menu bar
188 wxMenu *menuFile = new wxMenu;
189 wxMenu *menuNav = new wxMenu;
190
191 menuFile->Append(Minimal_Quit, _("E&xit"));
192 menuNav->Append(Minimal_Back, _("Go &BACK"));
193 menuNav->Append(Minimal_Forward, _("Go &FORWARD"));
194
195 // now append the freshly created menu to the menu bar...
196 wxMenuBar *menuBar = new wxMenuBar;
197 menuBar->Append(menuFile, _("&File"));
198 menuBar->Append(menuNav, _("&Navigate"));
199
200 // ... and attach this menu bar to the frame
201 SetMenuBar(menuBar);
202
203 SetIcon(wxIcon(sample_xpm));
204
205#if wxUSE_STATUSBAR
206 CreateStatusBar(2);
207#endif // wxUSE_STATUSBAR
208
209 html = new wxHtmlWindow(this);
210 html -> SetRelatedFrame(this, _("wxHTML Demo: '%s'"));
211#if wxUSE_STATUSBAR
212 html -> SetRelatedStatusBar(1);
213#endif // wxUSE_STATUSBAR
214 html -> LoadPage(wxT("start.htm"));
215
216}
217
218
219// event handlers
220
221void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
222{
223 // true is to force the frame to close
224 Close(true);
225}
226
227void MyFrame::OnBack(wxCommandEvent& WXUNUSED(event))
228{
229 if (!html -> HistoryBack()) wxMessageBox(_("You reached prehistory era!"));
230}
231
232
233void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event))
234{
235 if (!html -> HistoryForward()) wxMessageBox(_("No more items in history!"));
236}