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