]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/widget/widget.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml testing example
4 // Demonstrates embedded controls
5 /////////////////////////////////////////////////////////////////////////////
7 // For compilers that support precompilation, includes "wx/wx.h".
14 // for all others, include the necessary headers (this file is usually all you
15 // need because it includes almost all "standard" wxWidgets headers
21 #include "wx/html/htmlwin.h"
23 #include "../../sample.xpm"
29 TAG HANDER FOR 'MYBIND' TAG
34 #include "wx/html/m_templ.h"
37 TAG_HANDLER_BEGIN(MYBIND
, "MYBIND")
45 tag
.ScanParam(wxT("X"), wxT("%i"), &ax
);
46 tag
.ScanParam(wxT("Y"), wxT("%i"), &ay
);
48 if (tag
.HasParam(wxT("FLOAT"))) fl
= ax
;
52 m_WParser
->GetWindowInterface()->GetHTMLWindow(),
54 tag
.GetParam(wxT("NAME")),
62 m_WParser
->GetContainer()->InsertCell(new wxHtmlWidgetCell(wnd
, fl
));
67 TAG_HANDLER_END(MYBIND
)
71 TAGS_MODULE_BEGIN(MyBind
)
73 TAGS_MODULE_ADD(MYBIND
)
75 TAGS_MODULE_END(MyBind
)
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 // Define a new application type, each program should derive a class from wxApp
83 class MyApp
: public wxApp
86 // override base class virtuals
87 // ----------------------------
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();
95 // Define a new frame type: this is going to be our main frame
96 class MyFrame
: public wxFrame
100 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
102 // event handlers (these functions should _not_ be virtual)
103 void OnQuit(wxCommandEvent
& event
);
104 void OnBack(wxCommandEvent
& event
);
105 void OnForward(wxCommandEvent
& event
);
108 // any class wishing to process wxWidgets events must use this macro
109 DECLARE_EVENT_TABLE()
112 // ----------------------------------------------------------------------------
114 // ----------------------------------------------------------------------------
116 // IDs for the controls and the menu commands
124 // controls start here (the numbers are, of course, arbitrary)
128 // ----------------------------------------------------------------------------
129 // event tables and other macros for wxWidgets
130 // ----------------------------------------------------------------------------
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.
135 BEGIN_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
)
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
148 // ============================================================================
150 // ============================================================================
152 // ----------------------------------------------------------------------------
153 // the application class
154 // ----------------------------------------------------------------------------
156 // `Main program' equivalent: the program execution "starts" here
159 // Create the main application window
160 MyFrame
*frame
= new MyFrame( _("wxHtmlWindow testing application"),
161 wxDefaultPosition
, wxSize(640, 480) );
163 // Show it and tell the application that it's our main window
164 // @@@ what does it do exactly, in fact? is it necessary here?
168 // success: wxApp::OnRun() will be called which will enter the main message
169 // loop and the application will run. If we returned false here, the
170 // application would exit immediately.
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
181 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
182 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
185 wxMenu
*menuFile
= new wxMenu
;
186 wxMenu
*menuNav
= new wxMenu
;
188 menuFile
->Append(Minimal_Quit
, _("E&xit"));
189 menuNav
->Append(Minimal_Back
, _("Go &BACK"));
190 menuNav
->Append(Minimal_Forward
, _("Go &FORWARD"));
192 // now append the freshly created menu to the menu bar...
193 wxMenuBar
*menuBar
= new wxMenuBar
;
194 menuBar
->Append(menuFile
, _("&File"));
195 menuBar
->Append(menuNav
, _("&Navigate"));
197 // ... and attach this menu bar to the frame
200 SetIcon(wxIcon(sample_xpm
));
204 #endif // wxUSE_STATUSBAR
206 html
= new wxHtmlWindow(this);
207 html
-> SetRelatedFrame(this, _("wxHTML Demo: '%s'"));
209 html
-> SetRelatedStatusBar(1);
210 #endif // wxUSE_STATUSBAR
211 html
-> LoadPage(wxT("start.htm"));
218 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
220 // true is to force the frame to close
224 void MyFrame::OnBack(wxCommandEvent
& WXUNUSED(event
))
226 if (!html
-> HistoryBack()) wxMessageBox(_("You reached prehistory era!"));
230 void MyFrame::OnForward(wxCommandEvent
& WXUNUSED(event
))
232 if (!html
-> HistoryForward()) wxMessageBox(_("No more items in history!"));