]>
git.saurik.com Git - wxWidgets.git/blob - samples/html/widget/widget.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml testing example
4 // demonstrates virtual file systems feature
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" wxWindows headers
26 #include "wx/html/htmlwin.h"
32 TAG HANDER FOR 'MYBIND' TAG
37 #include "wx/html/m_templ.h"
40 TAG_HANDLER_BEGIN(MYBIND
, "MYBIND")
48 tag
.ScanParam(wxT("X"), wxT("%i"), &ax
);
49 tag
.ScanParam(wxT("Y"), wxT("%i"), &ay
);
51 if (tag
.HasParam(wxT("FLOAT"))) fl
= ax
;
53 wnd
= new wxTextCtrl(m_WParser
->GetWindow(), -1, tag
.GetParam(wxT("NAME")),
54 wxPoint(0,0), wxSize(ax
, ay
), wxTE_MULTILINE
);
58 m_WParser
->GetContainer()->InsertCell(new wxHtmlWidgetCell(wnd
, fl
));
63 TAG_HANDLER_END(MYBIND
)
67 TAGS_MODULE_BEGIN(MyBind
)
69 TAGS_MODULE_ADD(MYBIND
)
71 TAGS_MODULE_END(MyBind
)
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 // Define a new application type, each program should derive a class from wxApp
79 class MyApp
: public wxApp
82 // override base class virtuals
83 // ----------------------------
85 // this one is called on application startup and is a good place for the app
86 // initialization (doing it here and not in the ctor allows to have an error
87 // return: if OnInit() returns false, the application terminates)
88 virtual bool OnInit();
91 // Define a new frame type: this is going to be our main frame
92 class MyFrame
: public wxFrame
96 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
98 // event handlers (these functions should _not_ be virtual)
99 void OnQuit(wxCommandEvent
& event
);
100 void OnBack(wxCommandEvent
& event
);
101 void OnForward(wxCommandEvent
& event
);
104 // any class wishing to process wxWindows events must use this macro
105 DECLARE_EVENT_TABLE()
108 // ----------------------------------------------------------------------------
110 // ----------------------------------------------------------------------------
112 // IDs for the controls and the menu commands
120 // controls start here (the numbers are, of course, arbitrary)
124 // ----------------------------------------------------------------------------
125 // event tables and other macros for wxWindows
126 // ----------------------------------------------------------------------------
128 // the event tables connect the wxWindows events with the functions (event
129 // handlers) which process them. It can be also done at run-time, but for the
130 // simple menu events like this the static method is much simpler.
131 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
132 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
133 EVT_MENU(Minimal_Back
, MyFrame::OnBack
)
134 EVT_MENU(Minimal_Forward
, MyFrame::OnForward
)
137 // Create a new application object: this macro will allow wxWindows to create
138 // the application object during program execution (it's better than using a
139 // static object for many reasons) and also declares the accessor function
140 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
144 // ============================================================================
146 // ============================================================================
148 // ----------------------------------------------------------------------------
149 // the application class
150 // ----------------------------------------------------------------------------
152 // `Main program' equivalent: the program execution "starts" here
155 // Create the main application window
156 MyFrame
*frame
= new MyFrame( "wxHtmlWindow testing application",
157 wxPoint(50, 50), wxSize(640, 480) );
159 // Show it and tell the application that it's our main window
160 // @@@ what does it do exactly, in fact? is it necessary here?
164 // success: wxApp::OnRun() will be called which will enter the main message
165 // loop and the application will run. If we returned FALSE here, the
166 // application would exit immediately.
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
177 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
178 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
181 wxMenu
*menuFile
= new wxMenu
;
182 wxMenu
*menuNav
= new wxMenu
;
184 menuFile
->Append(Minimal_Quit
, "E&xit");
185 menuNav
->Append(Minimal_Back
, "Go &BACK");
186 menuNav
->Append(Minimal_Forward
, "Go &FORWARD");
188 // now append the freshly created menu to the menu bar...
189 wxMenuBar
*menuBar
= new wxMenuBar
;
190 menuBar
->Append(menuFile
, "&File");
191 menuBar
->Append(menuNav
, "&Navigate");
193 // ... and attach this menu bar to the frame
198 html
= new wxHtmlWindow(this);
199 html
-> SetRelatedFrame(this, "VFS Demo: '%s'");
200 html
-> SetRelatedStatusBar(1);
201 html
-> LoadPage("start.htm");
207 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
209 // TRUE is to force the frame to close
213 void MyFrame::OnBack(wxCommandEvent
& WXUNUSED(event
))
215 if (!html
-> HistoryBack()) wxMessageBox("You reached prehistory era!");
219 void MyFrame::OnForward(wxCommandEvent
& WXUNUSED(event
))
221 if (!html
-> HistoryForward()) wxMessageBox("No more items in history!");