]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/widget/widget.cpp
730f2886ddd41c747e9248e2ad872a07062af4a4
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml testing example
4 // demonstrates virtual file systems feature
5 /////////////////////////////////////////////////////////////////////////////
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" wxWindows headers
26 #include "wx/html/htmlwin.h"
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
);
52 if (tag
.HasParam(wxT("FLOAT")))
55 wnd
= new wxTextCtrl(m_WParser
->GetWindow(), -1, tag
.GetParam(wxT("NAME")),
56 wxPoint(0,0), wxSize(ax
, ay
), wxTE_MULTILINE
);
59 m_WParser
->GetContainer()->InsertCell(new wxHtmlWidgetCell(wnd
, fl
));
64 TAG_HANDLER_END(MYBIND
)
68 TAGS_MODULE_BEGIN(MyBind
)
70 TAGS_MODULE_ADD(MYBIND
)
72 TAGS_MODULE_END(MyBind
)
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 // Define a new application type, each program should derive a class from wxApp
87 class MyApp
: public wxApp
90 // override base class virtuals
91 // ----------------------------
93 // this one is called on application startup and is a good place for the app
94 // initialization (doing it here and not in the ctor allows to have an error
95 // return: if OnInit() returns false, the application terminates)
96 virtual bool OnInit();
99 // Define a new frame type: this is going to be our main frame
100 class MyFrame
: public wxFrame
104 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
106 // event handlers (these functions should _not_ be virtual)
107 void OnQuit(wxCommandEvent
& event
);
108 void OnAbout(wxCommandEvent
& event
);
109 void OnBack(wxCommandEvent
& event
);
110 void OnForward(wxCommandEvent
& event
);
113 // any class wishing to process wxWindows events must use this macro
114 DECLARE_EVENT_TABLE()
117 // ----------------------------------------------------------------------------
119 // ----------------------------------------------------------------------------
121 // IDs for the controls and the menu commands
130 // controls start here (the numbers are, of course, arbitrary)
134 // ----------------------------------------------------------------------------
135 // event tables and other macros for wxWindows
136 // ----------------------------------------------------------------------------
138 // the event tables connect the wxWindows events with the functions (event
139 // handlers) which process them. It can be also done at run-time, but for the
140 // simple menu events like this the static method is much simpler.
141 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
142 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
143 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
144 EVT_MENU(Minimal_Back
, MyFrame::OnBack
)
145 EVT_MENU(Minimal_Forward
, MyFrame::OnForward
)
148 // Create a new application object: this macro will allow wxWindows to create
149 // the application object during program execution (it's better than using a
150 // static object for many reasons) and also declares the accessor function
151 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
155 // ============================================================================
157 // ============================================================================
159 // ----------------------------------------------------------------------------
160 // the application class
161 // ----------------------------------------------------------------------------
163 // `Main program' equivalent: the program execution "starts" here
166 // Create the main application window
167 MyFrame
*frame
= new MyFrame("wxHtmlWindow testing application",
168 wxPoint(50, 50), wxSize(640, 480));
170 // Show it and tell the application that it's our main window
171 // @@@ what does it do exactly, in fact? is it necessary here?
175 // success: wxApp::OnRun() will be called which will enter the main message
176 // loop and the application will run. If we returned FALSE here, the
177 // application would exit immediately.
181 // ----------------------------------------------------------------------------
183 // ----------------------------------------------------------------------------
188 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
189 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
192 wxMenu
*menuFile
= new wxMenu
;
193 wxMenu
*menuNav
= new wxMenu
;
195 menuFile
->Append(Minimal_Quit
, "E&xit");
196 menuNav
->Append(Minimal_Back
, "Go &BACK");
197 menuNav
->Append(Minimal_Forward
, "Go &FORWARD");
199 // now append the freshly created menu to the menu bar...
200 wxMenuBar
*menuBar
= new wxMenuBar
;
201 menuBar
->Append(menuFile
, "&File");
202 menuBar
->Append(menuNav
, "&Navigate");
204 // ... and attach this menu bar to the frame
209 html
= new wxHtmlWindow(this);
210 html
-> SetRelatedFrame(this, "VFS Demo: '%s'");
211 html
-> SetRelatedStatusBar(1);
212 html
-> LoadPage("start.htm");
218 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
220 // TRUE is to force the frame to close
224 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
230 void MyFrame::OnBack(wxCommandEvent
& WXUNUSED(event
))
232 if (!html
-> HistoryBack()) wxMessageBox("You reached prehistory era!");
236 void MyFrame::OnForward(wxCommandEvent
& WXUNUSED(event
))
238 if (!html
-> HistoryForward()) wxMessageBox("No more items in history!");