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