]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/widget/widget.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml testing example
4 // Demonstrates embedded controls
5 /////////////////////////////////////////////////////////////////////////////
7 #if defined(__GNUG__) && !defined(__APPLE__)
8 #pragma implementation "test.cpp"
9 #pragma interface "test.cpp"
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
26 #include "wx/html/htmlwin.h"
28 #include "../../sample.xpm"
34 TAG HANDER FOR 'MYBIND' TAG
39 #include "wx/html/m_templ.h"
42 TAG_HANDLER_BEGIN(MYBIND
, "MYBIND")
50 tag
.ScanParam(wxT("X"), wxT("%i"), &ax
);
51 tag
.ScanParam(wxT("Y"), wxT("%i"), &ay
);
53 if (tag
.HasParam(wxT("FLOAT"))) fl
= ax
;
55 wnd
= new wxTextCtrl(m_WParser
->GetWindow(), wxID_ANY
, tag
.GetParam(wxT("NAME")),
56 wxPoint(0,0), wxSize(ax
, ay
), wxTE_MULTILINE
);
60 m_WParser
->GetContainer()->InsertCell(new wxHtmlWidgetCell(wnd
, fl
));
65 TAG_HANDLER_END(MYBIND
)
69 TAGS_MODULE_BEGIN(MyBind
)
71 TAGS_MODULE_ADD(MYBIND
)
73 TAGS_MODULE_END(MyBind
)
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 // Define a new application type, each program should derive a class from wxApp
81 class MyApp
: public wxApp
84 // override base class virtuals
85 // ----------------------------
87 // this one is called on application startup and is a good place for the app
88 // initialization (doing it here and not in the ctor allows to have an error
89 // return: if OnInit() returns false, the application terminates)
90 virtual bool OnInit();
93 // Define a new frame type: this is going to be our main frame
94 class MyFrame
: public wxFrame
98 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
100 // event handlers (these functions should _not_ be virtual)
101 void OnQuit(wxCommandEvent
& event
);
102 void OnBack(wxCommandEvent
& event
);
103 void OnForward(wxCommandEvent
& event
);
106 // any class wishing to process wxWidgets events must use this macro
107 DECLARE_EVENT_TABLE()
110 // ----------------------------------------------------------------------------
112 // ----------------------------------------------------------------------------
114 // IDs for the controls and the menu commands
122 // controls start here (the numbers are, of course, arbitrary)
126 // ----------------------------------------------------------------------------
127 // event tables and other macros for wxWidgets
128 // ----------------------------------------------------------------------------
130 // the event tables connect the wxWidgets events with the functions (event
131 // handlers) which process them. It can be also done at run-time, but for the
132 // simple menu events like this the static method is much simpler.
133 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
134 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
135 EVT_MENU(Minimal_Back
, MyFrame::OnBack
)
136 EVT_MENU(Minimal_Forward
, MyFrame::OnForward
)
139 // Create a new application object: this macro will allow wxWidgets to create
140 // the application object during program execution (it's better than using a
141 // static object for many reasons) and also declares the accessor function
142 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
146 // ============================================================================
148 // ============================================================================
150 // ----------------------------------------------------------------------------
151 // the application class
152 // ----------------------------------------------------------------------------
154 // `Main program' equivalent: the program execution "starts" here
157 // Create the main application window
158 MyFrame
*frame
= new MyFrame( _("wxHtmlWindow testing application"),
159 wxDefaultPosition
, wxSize(640, 480) );
161 // Show it and tell the application that it's our main window
162 // @@@ what does it do exactly, in fact? is it necessary here?
166 // success: wxApp::OnRun() will be called which will enter the main message
167 // loop and the application will run. If we returned false here, the
168 // application would exit immediately.
172 // ----------------------------------------------------------------------------
174 // ----------------------------------------------------------------------------
179 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
180 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
)
183 wxMenu
*menuFile
= new wxMenu
;
184 wxMenu
*menuNav
= new wxMenu
;
186 menuFile
->Append(Minimal_Quit
, _("E&xit"));
187 menuNav
->Append(Minimal_Back
, _("Go &BACK"));
188 menuNav
->Append(Minimal_Forward
, _("Go &FORWARD"));
190 // now append the freshly created menu to the menu bar...
191 wxMenuBar
*menuBar
= new wxMenuBar
;
192 menuBar
->Append(menuFile
, _("&File"));
193 menuBar
->Append(menuNav
, _("&Navigate"));
195 // ... and attach this menu bar to the frame
198 SetIcon(wxIcon(sample_xpm
));
202 #endif // wxUSE_STATUSBAR
204 html
= new wxHtmlWindow(this);
205 html
-> SetRelatedFrame(this, _("wxHTML Demo: '%s'"));
207 html
-> SetRelatedStatusBar(1);
208 #endif // wxUSE_STATUSBAR
209 html
-> LoadPage(wxT("start.htm"));
216 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
218 // true is to force the frame to close
222 void MyFrame::OnBack(wxCommandEvent
& WXUNUSED(event
))
224 if (!html
-> HistoryBack()) wxMessageBox(_("You reached prehistory era!"));
228 void MyFrame::OnForward(wxCommandEvent
& WXUNUSED(event
))
230 if (!html
-> HistoryForward()) wxMessageBox(_("No more items in history!"));