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