2 wxActiveX Library Licence, Version 3
3 ====================================
5 Copyright (C) 2003 Lindsay Mathieson [, ...]
7 Everyone is permitted to copy and distribute verbatim copies
8 of this licence document, but changing it is not allowed.
10 wxActiveX LIBRARY LICENCE
11 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
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.
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.
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.
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
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
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
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.
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
58 // For compilers that support precompilation, includes "wx/wx.h".
59 #if defined(__WXGTK__) || defined(__WXMOTIF__)
62 #include "wx/wxprec.h"
63 #include "wx/filedlg.h"
66 #include "wxActiveXFrame.h"
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
75 // the application icon
76 #if defined(__WXGTK__) || defined(__WXMOTIF__)
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 // IDs for the controls and the menu commands
96 FILE_TEST_HTMLGETTEXT
,
106 // ----------------------------------------------------------------------------
107 // event tables and other macros for wxWindows
108 // ----------------------------------------------------------------------------
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.
113 BEGIN_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
)
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
)
137 // ----------------------------------------------------------------------------
139 // ----------------------------------------------------------------------------
142 wxIEFrame::wxIEFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
143 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
145 // set the frame icon
146 SetIcon(wxICON(wxIE
));
149 wxMenu
*menuFile
= new wxMenu("", wxMENU_TEAROFF
);
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");
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");
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");
176 // ... and attach this menu bar to the frame
179 // create a status bar just for fun (by default with 1 pane only)
180 wxStatusBar
* sb
= CreateStatusBar(2);
181 SetStatusText("Ready");
183 // progress gauge (belongs to status bar)
184 m_gauge
= new wxGauge(sb
, ID_PROGRESS_GAUGE
, 100);
187 m_ie
= new wxIEHtmlWin(this, ID_MSHTML
);
194 void wxIEFrame::OnSize(wxSizeEvent
& event
)
196 wxFrame::OnSize(event
);
198 wxStatusBar
* sb
= GetStatusBar();
203 sb
->GetFieldRect(1, rc
);
205 m_gauge
->SetSize(rc
);
208 void wxIEFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
210 // TRUE is to force the frame to close
214 void wxIEFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
217 msg
.Printf( _T("About wxIE...\n"));
218 wxMessageBox(msg
, "About wxIE", wxOK
| wxICON_INFORMATION
, this);
221 void wxIEFrame::OnTestHTML(wxCommandEvent
& WXUNUSED(event
))
224 "<HTML><BODY><H1>Hello World</H1>Plain Text</body></html>";
225 m_ie
->LoadString(html
);
229 void wxIEFrame::OnTestSelect(wxCommandEvent
& WXUNUSED(event
))
231 wxString s
= m_ie
->GetStringSelection();
236 void wxIEFrame::OnTestHTMLSelect(wxCommandEvent
& WXUNUSED(event
))
238 wxString s
= m_ie
->GetStringSelection(true);
243 void wxIEFrame::OnTestGetText(wxCommandEvent
& WXUNUSED(event
))
245 wxString s
= m_ie
->GetText();
250 void wxIEFrame::OnTestHTMLGetText(wxCommandEvent
& WXUNUSED(event
))
252 wxString s
= m_ie
->GetText(true);
257 void wxIEFrame::OnTestHome(wxCommandEvent
& WXUNUSED(event
))
263 void wxIEFrame::OnOpen(wxCommandEvent
& WXUNUSED(event
))
265 wxFileDialog
dlg(this, "Chooose a HTML File", "", "", "HTML files (*.html; *.htm)|*.html;*.htm|",wxOPEN
);
267 if (dlg
.ShowModal() == wxID_OK
)
269 wxString fname
= dlg
.GetPath();
271 ifstream
*is
= new ifstream(fname
.mb_str());
272 m_ie
->LoadStream(is
);
276 void wxIEFrame::OnEditMode(wxCommandEvent
& WXUNUSED(event
))
278 m_ie
->SetEditMode(! m_ie
->GetEditMode());
281 void wxIEFrame::OnEditModeUI(wxUpdateUIEvent
& event
)
284 event
.Check(m_ie
->GetEditMode());
287 void wxIEFrame::OnBrowse(wxCommandEvent
& WXUNUSED(event
))
289 wxString url
= wxGetTextFromUser("Enter URL:", "Browse", "", this);
294 void wxIEFrame::OnMSHTMLStatusTextChangeX(wxActiveXEvent
& event
)
296 SetStatusText(event
["Text"]);
300 void wxIEFrame::OnMSHTMLBeforeNavigate2X(wxActiveXEvent
& event
)
302 wxString url
= event
["Url"];
303 if (url
== "about:blank")
306 int rc
= wxMessageBox(url
, "Allow open url ?", wxYES_NO
);
309 event
["Cancel"] = true;
312 void wxIEFrame::OnMSHTMLTitleChangeX(wxActiveXEvent
& event
)
314 SetTitle(event
["Text"]);
318 void wxIEFrame::OnMSHTMLNewWindow2X(wxActiveXEvent
& event
)
320 int rc
= wxMessageBox("New Window requested", "Allow New Window ?", wxYES_NO
);
323 event
["Cancel"] = true;
327 void wxIEFrame::OnMSHTMLProgressChangeX(wxActiveXEvent
& event
)
329 if ((long) event
["ProgressMax"] != m_gauge
->GetRange())
330 m_gauge
->SetRange((long) event
["ProgressMax"]);
332 m_gauge
->SetValue((long) event
["Progress"]);
335 void wxIEFrame::OnTestActiveX(wxCommandEvent
& WXUNUSED(event
))
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"
348 wxDialog
dlg(this, -1, wxString(wxT("Test ActiveX")));
350 wxFlexGridSizer
*sz
= new wxFlexGridSizer(2);
351 sz
->Add(new wxStaticText(&dlg
, -1, wxT("Enter a ActiveX ProgId")), 0, wxALL
, 5 );
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"));
362 sz
->Add(cb
, 0, wxALL
, 5 );
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 );
368 dlg
.SetAutoLayout( TRUE
);
371 sz
->SetSizeHints(&dlg
);
374 if (dlg
.ShowModal() == wxID_OK
)
376 wxString progId
= cb
->GetValue();
377 wxActiveXFrame
*frame
= new wxActiveXFrame(this, progId
);