]> git.saurik.com Git - wxWidgets.git/blob - samples/html/widget/widget.cpp
Fixed flat style for toolbars under XP, Windows Classic style
[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" wxWidgets 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(), wxID_ANY, 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 wxWidgets 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 wxWidgets
126 // ----------------------------------------------------------------------------
127
128 // the event tables connect the wxWidgets 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 wxWidgets 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 wxDefaultPosition, 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, wxID_ANY, 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 #if wxUSE_STATUSBAR
197 CreateStatusBar(2);
198 #endif // wxUSE_STATUSBAR
199
200 html = new wxHtmlWindow(this);
201 html -> SetRelatedFrame(this, _("VFS Demo: '%s'"));
202 #if wxUSE_STATUSBAR
203 html -> SetRelatedStatusBar(1);
204 #endif // wxUSE_STATUSBAR
205 html -> LoadPage(wxT("start.htm"));
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 }