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