]>
Commit | Line | Data |
---|---|---|
5526e819 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: virtua;.cpp | |
3 | // Purpose: wxHtml testing example | |
4 | // demonstrates virtual file systems feature | |
5 | ///////////////////////////////////////////////////////////////////////////// | |
6 | ||
788233da | 7 | #if defined(__GNUG__) && !defined(__APPLE__) |
5526e819 VS |
8 | #pragma implementation "test.cpp" |
9 | #pragma interface "test.cpp" | |
10 | #endif | |
11 | ||
12 | // For compilers that support precompilation, includes "wx/wx.h". | |
92a19c2e | 13 | #include "wx/wxprec.h" |
5526e819 VS |
14 | |
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | // for all others, include the necessary headers (this file is usually all you | |
be5a51fb | 20 | // need because it includes almost all "standard" wxWidgets headers |
5526e819 | 21 | #ifndef WX_PRECOMP |
67547666 | 22 | #include "wx/wx.h" |
5526e819 VS |
23 | #endif |
24 | ||
25 | ||
67547666 | 26 | #include "wx/html/htmlwin.h" |
5526e819 VS |
27 | |
28 | ||
5526e819 VS |
29 | /* |
30 | ||
31 | ||
32 | TAG HANDER FOR 'MYBIND' TAG | |
33 | ||
34 | ||
35 | */ | |
36 | ||
67547666 | 37 | #include "wx/html/m_templ.h" |
5526e819 VS |
38 | |
39 | ||
40 | TAG_HANDLER_BEGIN(MYBIND, "MYBIND") | |
41 | ||
aec18ff7 MB |
42 | TAG_HANDLER_PROC(tag) |
43 | { | |
44 | wxWindow *wnd; | |
45 | int ax, ay; | |
46 | int fl = 0; | |
47 | ||
48 | tag.ScanParam(wxT("X"), wxT("%i"), &ax); | |
49 | tag.ScanParam(wxT("Y"), wxT("%i"), &ay); | |
50 | ||
51 | if (tag.HasParam(wxT("FLOAT"))) fl = ax; | |
5526e819 | 52 | |
52fa6f7d | 53 | wnd = new wxTextCtrl(m_WParser->GetWindow(), wxID_ANY, tag.GetParam(wxT("NAME")), |
aec18ff7 | 54 | wxPoint(0,0), wxSize(ax, ay), wxTE_MULTILINE); |
5526e819 | 55 | |
52fa6f7d | 56 | wnd->Show(true); |
5526e819 | 57 | |
aec18ff7 | 58 | m_WParser->GetContainer()->InsertCell(new wxHtmlWidgetCell(wnd, fl)); |
5526e819 | 59 | |
52fa6f7d | 60 | return false; |
aec18ff7 | 61 | } |
5526e819 VS |
62 | |
63 | TAG_HANDLER_END(MYBIND) | |
64 | ||
65 | ||
66 | ||
67 | TAGS_MODULE_BEGIN(MyBind) | |
68 | ||
69 | TAGS_MODULE_ADD(MYBIND) | |
70 | ||
71 | TAGS_MODULE_END(MyBind) | |
72 | ||
73 | ||
5526e819 VS |
74 | // ---------------------------------------------------------------------------- |
75 | // private classes | |
76 | // ---------------------------------------------------------------------------- | |
77 | ||
78 | // Define a new application type, each program should derive a class from wxApp | |
aec18ff7 MB |
79 | class MyApp : public wxApp |
80 | { | |
81 | public: | |
5526e819 VS |
82 | // override base class virtuals |
83 | // ---------------------------- | |
aec18ff7 | 84 | |
5526e819 VS |
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) | |
aec18ff7 MB |
88 | virtual bool OnInit(); |
89 | }; | |
5526e819 VS |
90 | |
91 | // Define a new frame type: this is going to be our main frame | |
aec18ff7 MB |
92 | class MyFrame : public wxFrame |
93 | { | |
94 | public: | |
5526e819 | 95 | // ctor(s) |
aec18ff7 MB |
96 | MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); |
97 | ||
5526e819 | 98 | // event handlers (these functions should _not_ be virtual) |
aec18ff7 MB |
99 | void OnQuit(wxCommandEvent& event); |
100 | void OnBack(wxCommandEvent& event); | |
101 | void OnForward(wxCommandEvent& event); | |
5526e819 | 102 | |
aec18ff7 | 103 | private: |
be5a51fb | 104 | // any class wishing to process wxWidgets events must use this macro |
5526e819 | 105 | DECLARE_EVENT_TABLE() |
aec18ff7 | 106 | }; |
5526e819 VS |
107 | |
108 | // ---------------------------------------------------------------------------- | |
109 | // constants | |
110 | // ---------------------------------------------------------------------------- | |
111 | ||
112 | // IDs for the controls and the menu commands | |
aec18ff7 MB |
113 | enum |
114 | { | |
5526e819 | 115 | // menu items |
aec18ff7 MB |
116 | Minimal_Quit = 1, |
117 | Minimal_Back, | |
118 | Minimal_Forward, | |
119 | ||
5526e819 | 120 | // controls start here (the numbers are, of course, arbitrary) |
aec18ff7 MB |
121 | Minimal_Text = 1000, |
122 | }; | |
5526e819 VS |
123 | |
124 | // ---------------------------------------------------------------------------- | |
be5a51fb | 125 | // event tables and other macros for wxWidgets |
5526e819 VS |
126 | // ---------------------------------------------------------------------------- |
127 | ||
be5a51fb | 128 | // the event tables connect the wxWidgets events with the functions (event |
5526e819 VS |
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. | |
aec18ff7 MB |
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) | |
135 | END_EVENT_TABLE() | |
136 | ||
be5a51fb | 137 | // Create a new application object: this macro will allow wxWidgets to create |
aec18ff7 MB |
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 | |
141 | // not wxApp) | |
142 | IMPLEMENT_APP(MyApp) | |
143 | ||
144 | // ============================================================================ | |
145 | // implementation | |
146 | // ============================================================================ | |
147 | ||
148 | // ---------------------------------------------------------------------------- | |
149 | // the application class | |
150 | // ---------------------------------------------------------------------------- | |
151 | ||
152 | // `Main program' equivalent: the program execution "starts" here | |
153 | bool MyApp::OnInit() | |
154 | { | |
5526e819 | 155 | // Create the main application window |
2b5f62a0 | 156 | MyFrame *frame = new MyFrame( _("wxHtmlWindow testing application"), |
aec18ff7 MB |
157 | wxPoint(50, 50), wxSize(640, 480) ); |
158 | ||
5526e819 VS |
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? | |
52fa6f7d | 161 | frame->Show(true); |
aec18ff7 | 162 | SetTopWindow(frame); |
5526e819 VS |
163 | |
164 | // success: wxApp::OnRun() will be called which will enter the main message | |
52fa6f7d | 165 | // loop and the application will run. If we returned false here, the |
5526e819 | 166 | // application would exit immediately. |
52fa6f7d | 167 | return true; |
aec18ff7 | 168 | } |
5526e819 VS |
169 | |
170 | // ---------------------------------------------------------------------------- | |
171 | // main frame | |
172 | // ---------------------------------------------------------------------------- | |
173 | ||
174 | wxHtmlWindow *html; | |
175 | ||
176 | // frame constructor | |
aec18ff7 | 177 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) |
52fa6f7d | 178 | : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size) |
aec18ff7 | 179 | { |
5526e819 | 180 | // create a menu bar |
aec18ff7 MB |
181 | wxMenu *menuFile = new wxMenu; |
182 | wxMenu *menuNav = new wxMenu; | |
5526e819 | 183 | |
2b5f62a0 VZ |
184 | menuFile->Append(Minimal_Quit, _("E&xit")); |
185 | menuNav->Append(Minimal_Back, _("Go &BACK")); | |
186 | menuNav->Append(Minimal_Forward, _("Go &FORWARD")); | |
5526e819 VS |
187 | |
188 | // now append the freshly created menu to the menu bar... | |
aec18ff7 | 189 | wxMenuBar *menuBar = new wxMenuBar; |
2b5f62a0 VZ |
190 | menuBar->Append(menuFile, _("&File")); |
191 | menuBar->Append(menuNav, _("&Navigate")); | |
5526e819 VS |
192 | |
193 | // ... and attach this menu bar to the frame | |
aec18ff7 | 194 | SetMenuBar(menuBar); |
5526e819 | 195 | |
aec18ff7 MB |
196 | CreateStatusBar(2); |
197 | ||
198 | html = new wxHtmlWindow(this); | |
2b5f62a0 | 199 | html -> SetRelatedFrame(this, _("VFS Demo: '%s'")); |
aec18ff7 | 200 | html -> SetRelatedStatusBar(1); |
2b5f62a0 | 201 | html -> LoadPage(wxT("start.htm")); |
aec18ff7 | 202 | } |
5526e819 VS |
203 | |
204 | ||
205 | // event handlers | |
206 | ||
aec18ff7 MB |
207 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
208 | { | |
52fa6f7d WS |
209 | // true is to force the frame to close |
210 | Close(true); | |
aec18ff7 | 211 | } |
5526e819 | 212 | |
aec18ff7 MB |
213 | void MyFrame::OnBack(wxCommandEvent& WXUNUSED(event)) |
214 | { | |
2b5f62a0 | 215 | if (!html -> HistoryBack()) wxMessageBox(_("You reached prehistory era!")); |
aec18ff7 | 216 | } |
5526e819 VS |
217 | |
218 | ||
aec18ff7 MB |
219 | void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event)) |
220 | { | |
2b5f62a0 | 221 | if (!html -> HistoryForward()) wxMessageBox(_("No more items in history!")); |
aec18ff7 | 222 | } |