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