1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml sample: Demonstrates embedded controls
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
19 // for all others, include the necessary headers (this file is usually all you
20 // need because it includes almost all "standard" wxWidgets headers
25 #include "wx/html/htmlwin.h"
26 #include "../../sample.xpm"
30 // ----------------------------------------------------------------------------
31 // TAG HANDER FOR 'MYBIND' TAG
32 // ----------------------------------------------------------------------------
34 #include "wx/html/m_templ.h"
36 TAG_HANDLER_BEGIN(MYBIND
, "MYBIND")
44 tag
.ScanParam(wxT("X"), wxT("%i"), &ax
);
45 tag
.ScanParam(wxT("Y"), wxT("%i"), &ay
);
47 if (tag
.HasParam(wxT("FLOAT"))) fl
= ax
;
51 m_WParser
->GetWindowInterface()->GetHTMLWindow(),
53 tag
.GetParam(wxT("NAME")),
61 m_WParser
->GetContainer()->InsertCell(new wxHtmlWidgetCell(wnd
, fl
));
66 TAG_HANDLER_END(MYBIND
)
70 TAGS_MODULE_BEGIN(MyBind
)
72 TAGS_MODULE_ADD(MYBIND
)
74 TAGS_MODULE_END(MyBind
)
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
81 // Define a new application type, each program should derive a class from wxApp
82 class MyApp
: public wxApp
85 // override base class virtuals
86 // ----------------------------
88 // this one is called on application startup and is a good place for the app
89 // initialization (doing it here and not in the ctor allows to have an error
90 // return: if OnInit() returns false, the application terminates)
91 virtual bool OnInit();
94 // Define a new frame type: this is going to be our main frame
95 class MyFrame
: public wxFrame
99 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
101 // event handlers (these functions should _not_ be virtual)
102 void OnQuit(wxCommandEvent
& event
);
103 void OnBack(wxCommandEvent
& event
);
104 void OnForward(wxCommandEvent
& event
);
107 // any class wishing to process wxWidgets events must use this macro
108 DECLARE_EVENT_TABLE()
111 // ----------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
115 // IDs for the controls and the menu commands
123 // controls start here (the numbers are, of course, arbitrary)
127 // ----------------------------------------------------------------------------
128 // event tables and other macros for wxWidgets
129 // ----------------------------------------------------------------------------
131 // the event tables connect the wxWidgets events with the functions (event
132 // handlers) which process them. It can be also done at run-time, but for the
133 // simple menu events like this the static method is much simpler.
134 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
135 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
136 EVT_MENU(Minimal_Back
, MyFrame::OnBack
)
137 EVT_MENU(Minimal_Forward
, MyFrame::OnForward
)
140 // Create a new application object: this macro will allow wxWidgets to create
141 // the application object during program execution (it's better than using a
142 // static object for many reasons) and also declares the accessor function
143 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
147 // ============================================================================
149 // ============================================================================
151 // ----------------------------------------------------------------------------
152 // the application class
153 // ----------------------------------------------------------------------------
155 // `Main program' equivalent: the program execution "starts" here
158 if ( !wxApp::OnInit() )
161 // Create the main application window
162 MyFrame
*frame
= new MyFrame( _("wxHtmlWindow testing application"),
163 wxDefaultPosition
, wxSize(640, 480) );
165 // Show it and tell the application that it's our main window
166 // @@@ what does it do exactly, in fact? is it necessary here?
170 // success: wxApp::OnRun() will be called which will enter the main message
171 // loop and the application will run. If we returned false here, the
172 // application would exit immediately.
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
183 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
184 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
186 SetIcon(wxICON(sample
));
189 wxMenu
*menuFile
= new wxMenu
;
190 wxMenu
*menuNav
= new wxMenu
;
192 menuFile
->Append(Minimal_Quit
, _("E&xit"));
193 menuNav
->Append(Minimal_Back
, _("Go &BACK"));
194 menuNav
->Append(Minimal_Forward
, _("Go &FORWARD"));
196 // now append the freshly created menu to the menu bar...
197 wxMenuBar
*menuBar
= new wxMenuBar
;
198 menuBar
->Append(menuFile
, _("&File"));
199 menuBar
->Append(menuNav
, _("&Navigate"));
201 // ... and attach this menu bar to the frame
204 SetIcon(wxIcon(sample_xpm
));
208 #endif // wxUSE_STATUSBAR
210 html
= new wxHtmlWindow(this);
211 html
-> SetRelatedFrame(this, _("wxHTML Demo: '%s'"));
213 html
-> SetRelatedStatusBar(1);
214 #endif // wxUSE_STATUSBAR
215 html
-> LoadPage(wxT("start.htm"));
222 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
224 // true is to force the frame to close
228 void MyFrame::OnBack(wxCommandEvent
& WXUNUSED(event
))
230 if (!html
-> HistoryBack()) wxMessageBox(_("You reached prehistory era!"));
234 void MyFrame::OnForward(wxCommandEvent
& WXUNUSED(event
))
236 if (!html
-> HistoryForward()) wxMessageBox(_("No more items in history!"));