]>
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
;
50 wnd
= new wxTextCtrl(m_WParser
->GetWindow(), wxID_ANY
, tag
.GetParam(wxT("NAME")),
51 wxPoint(0,0), wxSize(ax
, ay
), wxTE_MULTILINE
);
55 m_WParser
->GetContainer()->InsertCell(new wxHtmlWidgetCell(wnd
, fl
));
60 TAG_HANDLER_END(MYBIND
)
64 TAGS_MODULE_BEGIN(MyBind
)
66 TAGS_MODULE_ADD(MYBIND
)
68 TAGS_MODULE_END(MyBind
)
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 // Define a new application type, each program should derive a class from wxApp
76 class MyApp
: public wxApp
79 // override base class virtuals
80 // ----------------------------
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();
88 // Define a new frame type: this is going to be our main frame
89 class MyFrame
: public wxFrame
93 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
95 // event handlers (these functions should _not_ be virtual)
96 void OnQuit(wxCommandEvent
& event
);
97 void OnBack(wxCommandEvent
& event
);
98 void OnForward(wxCommandEvent
& event
);
101 // any class wishing to process wxWidgets events must use this macro
102 DECLARE_EVENT_TABLE()
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
109 // IDs for the controls and the menu commands
117 // controls start here (the numbers are, of course, arbitrary)
121 // ----------------------------------------------------------------------------
122 // event tables and other macros for wxWidgets
123 // ----------------------------------------------------------------------------
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
)
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
141 // ============================================================================
143 // ============================================================================
145 // ----------------------------------------------------------------------------
146 // the application class
147 // ----------------------------------------------------------------------------
149 // `Main program' equivalent: the program execution "starts" here
152 // Create the main application window
153 MyFrame
*frame
= new MyFrame( _("wxHtmlWindow testing application"),
154 wxDefaultPosition
, wxSize(640, 480) );
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?
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.
167 // ----------------------------------------------------------------------------
169 // ----------------------------------------------------------------------------
174 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
175 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
178 wxMenu
*menuFile
= new wxMenu
;
179 wxMenu
*menuNav
= new wxMenu
;
181 menuFile
->Append(Minimal_Quit
, _("E&xit"));
182 menuNav
->Append(Minimal_Back
, _("Go &BACK"));
183 menuNav
->Append(Minimal_Forward
, _("Go &FORWARD"));
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"));
190 // ... and attach this menu bar to the frame
193 SetIcon(wxIcon(sample_xpm
));
197 #endif // wxUSE_STATUSBAR
199 html
= new wxHtmlWindow(this);
200 html
-> SetRelatedFrame(this, _("wxHTML Demo: '%s'"));
202 html
-> SetRelatedStatusBar(1);
203 #endif // wxUSE_STATUSBAR
204 html
-> LoadPage(wxT("start.htm"));
211 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
213 // true is to force the frame to close
217 void MyFrame::OnBack(wxCommandEvent
& WXUNUSED(event
))
219 if (!html
-> HistoryBack()) wxMessageBox(_("You reached prehistory era!"));
223 void MyFrame::OnForward(wxCommandEvent
& WXUNUSED(event
))
225 if (!html
-> HistoryForward()) wxMessageBox(_("No more items in history!"));