]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/contrib/activex/wxie/wxIEFrm.cpp
added missing comma
[wxWidgets.git] / wxPython / contrib / activex / wxie / wxIEFrm.cpp
... / ...
CommitLineData
1/*
2 wxActiveX Library Licence, Version 3
3 ====================================
4
5 Copyright (C) 2003 Lindsay Mathieson [, ...]
6
7 Everyone is permitted to copy and distribute verbatim copies
8 of this licence document, but changing it is not allowed.
9
10 wxActiveX LIBRARY LICENCE
11 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12
13 This library is free software; you can redistribute it and/or modify it
14 under the terms of the GNU Library General Public Licence as published by
15 the Free Software Foundation; either version 2 of the Licence, or (at
16 your option) any later version.
17
18 This library is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
21 General Public Licence for more details.
22
23 You should have received a copy of the GNU Library General Public Licence
24 along with this software, usually in a file named COPYING.LIB. If not,
25 write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
26 Boston, MA 02111-1307 USA.
27
28 EXCEPTION NOTICE
29
30 1. As a special exception, the copyright holders of this library give
31 permission for additional uses of the text contained in this release of
32 the library as licenced under the wxActiveX Library Licence, applying
33 either version 3 of the Licence, or (at your option) any later version of
34 the Licence as published by the copyright holders of version 3 of the
35 Licence document.
36
37 2. The exception is that you may use, copy, link, modify and distribute
38 under the user's own terms, binary object code versions of works based
39 on the Library.
40
41 3. If you copy code from files distributed under the terms of the GNU
42 General Public Licence or the GNU Library General Public Licence into a
43 copy of this library, as this licence permits, the exception does not
44 apply to the code that you add in this way. To avoid misleading anyone as
45 to the status of such modified files, you must delete this exception
46 notice from such code and/or adjust the licensing conditions notice
47 accordingly.
48
49 4. If you write modifications of your own for this library, it is your
50 choice whether to permit this exception to apply to your modifications.
51 If you do not wish that, you must delete the exception notice from such
52 code and/or adjust the licensing conditions notice accordingly.
53*/
54
55// ----------------------------------------------------------------------------
56// headers
57// ----------------------------------------------------------------------------
58// For compilers that support precompilation, includes "wx/wx.h".
59#if defined(__WXGTK__) || defined(__WXMOTIF__)
60 #include "wx/wx.h"
61#endif
62#include "wx/wxprec.h"
63#include "wx/filedlg.h"
64#include "wxIEApp.h"
65#include "wxIEFrm.h"
66#include "wxActiveXFrame.h"
67#include <istream>
68#include <fstream>
69using namespace std;
70#include <exdispid.h>
71
72// ----------------------------------------------------------------------------
73// resources
74// ----------------------------------------------------------------------------
75// the application icon
76#if defined(__WXGTK__) || defined(__WXMOTIF__)
77 #include "wxIE.xpm"
78#endif
79
80// ----------------------------------------------------------------------------
81// constants
82// ----------------------------------------------------------------------------
83
84// IDs for the controls and the menu commands
85enum
86{
87 // menu items
88 FILE_QUIT = 1,
89 FILE_OPEN,
90 FILE_BROWSE,
91 FILE_HTML_EDITMODE,
92 FILE_TEST_HTML,
93 FILE_TEST_SELECT,
94 FILE_TEST_HTMLSELECT,
95 FILE_TEST_GETTEXT,
96 FILE_TEST_HTMLGETTEXT,
97 FILE_TEST_HOME,
98 FILE_TEST_ACTIVEX,
99 FILE_ABOUT,
100
101 // controls
102 ID_MSHTML = 501,
103 ID_PROGRESS_GAUGE
104};
105
106// ----------------------------------------------------------------------------
107// event tables and other macros for wxWindows
108// ----------------------------------------------------------------------------
109
110// the event tables connect the wxWindows events with the functions (event
111// handlers) which process them. It can be also done at run-time, but for the
112// simple menu events like this the static method is much simpler.
113BEGIN_EVENT_TABLE(wxIEFrame, wxFrame)
114 EVT_SIZE(wxIEFrame::OnSize)
115 EVT_MENU(FILE_QUIT, wxIEFrame::OnQuit)
116 EVT_MENU(FILE_BROWSE, wxIEFrame::OnBrowse)
117 EVT_MENU(FILE_OPEN, wxIEFrame::OnOpen)
118 EVT_MENU(FILE_HTML_EDITMODE, wxIEFrame::OnEditMode)
119 EVT_UPDATE_UI(FILE_HTML_EDITMODE, wxIEFrame::OnEditModeUI)
120 EVT_MENU(FILE_TEST_HTML, wxIEFrame::OnTestHTML)
121 EVT_MENU(FILE_TEST_SELECT, wxIEFrame::OnTestSelect)
122 EVT_MENU(FILE_TEST_HTMLSELECT, wxIEFrame::OnTestHTMLSelect)
123 EVT_MENU(FILE_TEST_GETTEXT, wxIEFrame::OnTestGetText)
124 EVT_MENU(FILE_TEST_HTMLGETTEXT, wxIEFrame::OnTestHTMLGetText)
125 EVT_MENU(FILE_TEST_HOME, wxIEFrame::OnTestHome)
126 EVT_MENU(FILE_TEST_ACTIVEX, wxIEFrame::OnTestActiveX)
127 EVT_MENU(FILE_ABOUT, wxIEFrame::OnAbout)
128
129 // ActiveX Events
130 EVT_ACTIVEX_DISPID(ID_MSHTML, DISPID_STATUSTEXTCHANGE, OnMSHTMLStatusTextChangeX)
131 EVT_ACTIVEX(ID_MSHTML, "BeforeNavigate2", OnMSHTMLBeforeNavigate2X)
132 EVT_ACTIVEX(ID_MSHTML, "TitleChange", OnMSHTMLTitleChangeX)
133 EVT_ACTIVEX(ID_MSHTML, "NewWindow2", OnMSHTMLNewWindow2X)
134 EVT_ACTIVEX(ID_MSHTML, "ProgressChange", OnMSHTMLProgressChangeX)
135END_EVENT_TABLE()
136
137// ----------------------------------------------------------------------------
138// main frame
139// ----------------------------------------------------------------------------
140
141// frame constructor
142wxIEFrame::wxIEFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
143 : wxFrame((wxFrame *)NULL, -1, title, pos, size)
144{
145 // set the frame icon
146 SetIcon(wxICON(wxIE));
147
148 // create a menu bar
149 wxMenu *menuFile = new wxMenu("", wxMENU_TEAROFF);
150
151 // the "About" item should be in the help menu
152 wxMenu *helpMenu = new wxMenu;
153 helpMenu->Append(FILE_ABOUT, "&About...\tCtrl-A", "Show about dialog");
154
155 menuFile->Append(FILE_TEST_HTML, "Test HTML", "Demonstrates LoadString()");
156 menuFile->Append(FILE_OPEN, "Open HTML File", "Demonstrates LoadStream(istream *)");
157 menuFile->Append(FILE_BROWSE, "Browse Web Page", "Demonstrates LoadUrl(url)");
158 menuFile->Append(FILE_HTML_EDITMODE, "Edit Mode", "Demonstrates editing html", true);
159 menuFile->AppendSeparator();
160 menuFile->Append(FILE_TEST_SELECT, "Get Selected Text", "Demonstrates GetStringSelection(false)");
161 menuFile->Append(FILE_TEST_HTMLSELECT, "Get HTML Selected Text", "Demonstrates GetStringSelection(true)");
162 menuFile->AppendSeparator();
163 menuFile->Append(FILE_TEST_GETTEXT, "Get Text", "Demonstrates GetText(false)");
164 menuFile->Append(FILE_TEST_HTMLGETTEXT, "Get HTML Text", "Demonstrates GetText(true)");
165 menuFile->Append(FILE_TEST_HOME, "Open Home Page", "Demonstrates GoHome()");
166 menuFile->AppendSeparator();
167 menuFile->Append(FILE_TEST_ACTIVEX, "Display a ActiveX control", "Demonstrates the Generic ActiveX Container");
168 menuFile->AppendSeparator();
169 menuFile->Append(FILE_QUIT, "E&xit\tAlt-X", "Quit this program");
170
171 // now append the freshly created menu to the menu bar...
172 wxMenuBar *menuBar = new wxMenuBar();
173 menuBar->Append(menuFile, "&File");
174 menuBar->Append(helpMenu, "&Help");
175
176 // ... and attach this menu bar to the frame
177 SetMenuBar(menuBar);
178
179 // create a status bar just for fun (by default with 1 pane only)
180 wxStatusBar * sb = CreateStatusBar(2);
181 SetStatusText("Ready");
182
183 // progress gauge (belongs to status bar)
184 m_gauge = new wxGauge(sb, ID_PROGRESS_GAUGE, 100);
185
186 // IE Control
187 m_ie = new wxIEHtmlWin(this, ID_MSHTML);
188
189}
190
191
192// event handlers
193
194void wxIEFrame::OnSize(wxSizeEvent& event)
195{
196 wxFrame::OnSize(event);
197
198 wxStatusBar* sb = GetStatusBar();
199 if (! sb)
200 return;
201
202 wxRect rc;
203 sb->GetFieldRect(1, rc);
204
205 m_gauge->SetSize(rc);
206};
207
208void wxIEFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
209{
210 // TRUE is to force the frame to close
211 Close(TRUE);
212}
213
214void wxIEFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
215{
216 wxString msg;
217 msg.Printf( _T("About wxIE...\n"));
218 wxMessageBox(msg, "About wxIE", wxOK | wxICON_INFORMATION, this);
219}
220
221void wxIEFrame::OnTestHTML(wxCommandEvent& WXUNUSED(event))
222{
223 wxString html =
224 "<HTML><BODY><H1>Hello World</H1>Plain Text</body></html>";
225 m_ie->LoadString(html);
226}
227
228
229void wxIEFrame::OnTestSelect(wxCommandEvent& WXUNUSED(event))
230{
231 wxString s = m_ie->GetStringSelection();
232
233 wxMessageBox(s);
234}
235
236void wxIEFrame::OnTestHTMLSelect(wxCommandEvent& WXUNUSED(event))
237{
238 wxString s = m_ie->GetStringSelection(true);
239
240 wxMessageBox(s);
241}
242
243void wxIEFrame::OnTestGetText(wxCommandEvent& WXUNUSED(event))
244{
245 wxString s = m_ie->GetText();
246
247 wxMessageBox(s);
248}
249
250void wxIEFrame::OnTestHTMLGetText(wxCommandEvent& WXUNUSED(event))
251{
252 wxString s = m_ie->GetText(true);
253
254 wxMessageBox(s);
255}
256
257void wxIEFrame::OnTestHome(wxCommandEvent& WXUNUSED(event))
258{
259 m_ie->GoHome();
260};
261
262
263void wxIEFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
264{
265 wxFileDialog dlg(this, "Chooose a HTML File", "", "", "HTML files (*.html; *.htm)|*.html;*.htm|",wxOPEN);
266
267 if (dlg.ShowModal() == wxID_OK)
268 {
269 wxString fname = dlg.GetPath();
270
271 ifstream *is = new ifstream(fname.mb_str());
272 m_ie->LoadStream(is);
273 };
274}
275
276void wxIEFrame::OnEditMode(wxCommandEvent& WXUNUSED(event))
277{
278 m_ie->SetEditMode(! m_ie->GetEditMode());
279}
280
281void wxIEFrame::OnEditModeUI(wxUpdateUIEvent& event)
282{
283 if (m_ie)
284 event.Check(m_ie->GetEditMode());
285}
286
287void wxIEFrame::OnBrowse(wxCommandEvent& WXUNUSED(event))
288{
289 wxString url = wxGetTextFromUser("Enter URL:", "Browse", "", this);
290
291 m_ie->LoadUrl(url);
292}
293
294void wxIEFrame::OnMSHTMLStatusTextChangeX(wxActiveXEvent& event)
295{
296 SetStatusText(event["Text"]);
297};
298
299
300void wxIEFrame::OnMSHTMLBeforeNavigate2X(wxActiveXEvent& event)
301{
302 wxString url = event["Url"];
303 if (url == "about:blank")
304 return;
305
306 int rc = wxMessageBox(url, "Allow open url ?", wxYES_NO);
307
308 if (rc != wxYES)
309 event["Cancel"] = true;
310};
311
312void wxIEFrame::OnMSHTMLTitleChangeX(wxActiveXEvent& event)
313{
314 SetTitle(event["Text"]);
315};
316
317
318void wxIEFrame::OnMSHTMLNewWindow2X(wxActiveXEvent& event)
319{
320 int rc = wxMessageBox("New Window requested", "Allow New Window ?", wxYES_NO);
321
322 if (rc != wxYES)
323 event["Cancel"] = true;
324};
325
326
327void wxIEFrame::OnMSHTMLProgressChangeX(wxActiveXEvent& event)
328{
329 if ((long) event["ProgressMax"] != m_gauge->GetRange())
330 m_gauge->SetRange((long) event["ProgressMax"]);
331
332 m_gauge->SetValue((long) event["Progress"]);
333};
334
335void wxIEFrame::OnTestActiveX(wxCommandEvent& WXUNUSED(event))
336{
337// Some known prog ids
338//#define PROGID "Shell.Explorer"
339//#define PROGID CLSID_WebBrowser
340//#define PROGID CLSID_MozillaBrowser
341//#define PROGID CLSID_HTMLDocument
342//#define PROGID "MSCAL.Calendar"
343//#define PROGID "WordPad.Document"
344//#define PROGID "SoftwareFX.ChartFX"
345//#define PROGID "PDF.PdfCtrl"
346#define PROGID "ShockwaveFlash.ShockwaveFlash"
347
348 wxDialog dlg(this, -1, wxString(wxT("Test ActiveX")));
349
350 wxFlexGridSizer *sz = new wxFlexGridSizer(2);
351 sz->Add(new wxStaticText(&dlg, -1, wxT("Enter a ActiveX ProgId")), 0, wxALL, 5 );
352
353 wxComboBox *cb = new wxComboBox(&dlg, 101, "");
354 cb->Append(wxT("ShockwaveFlash.ShockwaveFlash"));
355 cb->Append(wxT("MSCAL.Calendar"));
356 cb->Append(wxT("Shell.Explorer"));
357 cb->Append(wxT("WordPad.Document.1"));
358 cb->Append(wxT("SoftwareFX.ChartFX.20"));
359 cb->Append(wxT("PDF.PdfCtrl.5"));
360 cb->SetSelection(0);
361
362 sz->Add(cb, 0, wxALL, 5 );
363
364 // next row
365 sz->Add(new wxButton(&dlg, wxID_CANCEL, "Cancel"), 0, wxALIGN_RIGHT|wxALL, 5 );
366 sz->Add(new wxButton(&dlg, wxID_OK, "Ok"), 0, wxALIGN_RIGHT|wxALL, 5 );
367
368 dlg.SetAutoLayout( TRUE );
369 dlg.SetSizer(sz);
370 sz->Fit(&dlg);
371 sz->SetSizeHints(&dlg);
372
373
374 if (dlg.ShowModal() == wxID_OK)
375 {
376 wxString progId = cb->GetValue();
377 wxActiveXFrame *frame = new wxActiveXFrame(this, progId);
378 frame->Show();
379 };
380}
381