summaryrefslogtreecommitdiffstats
path: root/examples/org.eclipse.swt.examples.ole.win32
diff options
context:
space:
mode:
authorVeronika Irvine <torres>2001-06-21 15:16:50 +0000
committerVeronika Irvine <torres>2001-06-21 15:16:50 +0000
commit6c0e3d76ce668620fd159ac504e2b5d9a48852be (patch)
tree28ec743469ad12010dec20832bd1d5c1a3d72d8a /examples/org.eclipse.swt.examples.ole.win32
parent3fb799dcaa7d449679ed92f9829fbed85aa6fd1d (diff)
downloadeclipse.platform.swt-6c0e3d76ce668620fd159ac504e2b5d9a48852be.tar.gz
eclipse.platform.swt-6c0e3d76ce668620fd159ac504e2b5d9a48852be.tar.xz
eclipse.platform.swt-6c0e3d76ce668620fd159ac504e2b5d9a48852be.zip
Diffstat (limited to 'examples/org.eclipse.swt.examples.ole.win32')
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/.classpath9
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/.vcm_meta1
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/build.properties11
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/doc-html/hglegal.htm14
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/doc-html/ngibmcpy.gifbin0 -> 814 bytes
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/doc-html/swt_ole_ex.html40
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/icons/backward_nav.gifbin0 -> 881 bytes
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/icons/forward_nav.gifbin0 -> 883 bytes
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/icons/home_nav.gifbin0 -> 928 bytes
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/icons/refresh_nav.gifbin0 -> 160 bytes
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/icons/search_nav.gifbin0 -> 245 bytes
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/icons/stop_nav.gifbin0 -> 174 bytes
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/icons/webbrowser_example.gifbin0 -> 380 bytes
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/import.properties4
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/org/eclipse/swt/examples/ole/win32/OleBrowserView.java363
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/org/eclipse/swt/examples/ole/win32/OlePlugin.java170
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/org/eclipse/swt/examples/ole/win32/OleWebBrowser.java251
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/plugin.properties25
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/plugin.xml32
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/src/org/eclipse/swt/examples/ole/win32/OleBrowserView.java363
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/src/org/eclipse/swt/examples/ole/win32/OlePlugin.java170
-rwxr-xr-xexamples/org.eclipse.swt.examples.ole.win32/src/org/eclipse/swt/examples/ole/win32/OleWebBrowser.java251
22 files changed, 1677 insertions, 27 deletions
diff --git a/examples/org.eclipse.swt.examples.ole.win32/.classpath b/examples/org.eclipse.swt.examples.ole.win32/.classpath
index 507599f39a..ff43f54984 100755
--- a/examples/org.eclipse.swt.examples.ole.win32/.classpath
+++ b/examples/org.eclipse.swt.examples.ole.win32/.classpath
@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="/org.eclipse.swt"/>
+ <classpathentry kind="src" path=""/>
<classpathentry kind="var" path="JRE_LIB"/>
<classpathentry kind="var"
- path="WORKSPACE/org.eclipse.core.resources/resources.jar" sourcepath="WORKSPACE/org.eclipse.core.resources/resourcessrc.zip"/>
+ path="ECLIPSE_PLUGINS/org.eclipse.swt/swt.jar" sourcepath="ECLIPSE_PLUGINS/org.eclipse.swt/swtsrc.zip"/>
<classpathentry kind="var"
- path="WORKSPACE/org.eclipse.core.runtime/runtime.jar" sourcepath="WORKSPACE/org.eclipse.core.runtime/runtimesrc.zip"/>
+ path="ECLIPSE_PLUGINS/org.eclipse.core.runtime/runtime.jar" sourcepath="ECLIPSE_PLUGINS/org.eclipse.core.runtime/runtimesrc.zip"/>
<classpathentry kind="var"
- path="WORKSPACE/org.eclipse.ui/workbench.jar" sourcepath="WORKSPACE/org.eclipse.ui/workbenchsrc.zip"/>
+ path="ECLIPSE_PLUGINS/org.eclipse.ui/workbench.jar" sourcepath="ECLIPSE_PLUGINS/org.eclipse.ui/workbenchsrc.zip"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/examples/org.eclipse.swt.examples.ole.win32/.vcm_meta b/examples/org.eclipse.swt.examples.ole.win32/.vcm_meta
index e9dbb98bc0..d64b057431 100755
--- a/examples/org.eclipse.swt.examples.ole.win32/.vcm_meta
+++ b/examples/org.eclipse.swt.examples.ole.win32/.vcm_meta
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-description>
+ <comment></comment>
<nature id="org.eclipse.jdt.core.javanature"/>
<nature id="org.eclipse.pde.PluginNature"/>
<reference project-name="org.eclipse.swt"/>
diff --git a/examples/org.eclipse.swt.examples.ole.win32/build.properties b/examples/org.eclipse.swt.examples.ole.win32/build.properties
new file mode 100755
index 0000000000..12cd2bd26e
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/build.properties
@@ -0,0 +1,11 @@
+build.includes = doc-html/,\
+ icons/,\
+ plugin.properties,\
+ plugin.xml
+
+build.vaj.Eclipse\ SWT\ Examples\ OLE = /
+
+build.excludes = bin/,\
+ .cvsignore,\
+ .vcm_meta,\
+ build.properties \ No newline at end of file
diff --git a/examples/org.eclipse.swt.examples.ole.win32/doc-html/hglegal.htm b/examples/org.eclipse.swt.examples.ole.win32/doc-html/hglegal.htm
new file mode 100755
index 0000000000..b071dbdf45
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/doc-html/hglegal.htm
@@ -0,0 +1,14 @@
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <meta name="GENERATOR" content="Mozilla/4.73 [en] (Win98; U) [Netscape]">
+ <title>Legal Notices</title>
+</head>
+<body>
+
+<h3>
+<a NAME="Notices"></a>Notices</h3>
+(c) Copyright IBM Corp. 2000, 2001. All Rights Reserved.
+</body>
+</html>
diff --git a/examples/org.eclipse.swt.examples.ole.win32/doc-html/ngibmcpy.gif b/examples/org.eclipse.swt.examples.ole.win32/doc-html/ngibmcpy.gif
new file mode 100755
index 0000000000..360f8e9989
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/doc-html/ngibmcpy.gif
Binary files differ
diff --git a/examples/org.eclipse.swt.examples.ole.win32/doc-html/swt_ole_ex.html b/examples/org.eclipse.swt.examples.ole.win32/doc-html/swt_ole_ex.html
new file mode 100755
index 0000000000..d607a1c4e8
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/doc-html/swt_ole_ex.html
@@ -0,0 +1,40 @@
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>SWT - OLE Web Browser</title>
+</head>
+<body>
+
+<h2>Example - OLE Web Browser</h2>
+
+<h3>Introduction</h3>
+<p>This example demonstrates how to embed Active X / OLE controls into an
+SWT application or an Eclipse view.&nbsp; When the view is activated, it
+will create an instance of a Windows "Shell.Explorer" control and provide
+a GUI interface to it via OLE Automation.&nbsp; To run this example, Internet
+Explorer must be installed.
+</p>
+
+<h3>Running the example</h3>
+<p>To run the OLE Web Browser Example, pull down the Perspective menu, select the
+Show View menu item, then select Other from the submenu.&nbsp; A dialog
+will come up with a list of views.&nbsp; Expand SWT Examples and select
+the view named OLE Web Browser.&nbsp; A view containing an editor that
+appears similar to your default web browser will appear.
+</p>
+
+<h3>Details</h3>
+<p>The OLE Web Browser has Back and Forward buttons to take you to recently
+visited pages.&nbsp; The browser also contains a Home button to take you
+to the web browser's home page, a Stop button which stops the current transfer,
+a Search button which will search for text typed in the Address text field,
+and a Refresh button which re-draws the contents of the currently displayed
+page.&nbsp; There is also a Go button which, when clicked, will attempt
+to load the page specified in the Address field.&nbsp; One would expect
+each of these operations on every web browser.
+</p>
+
+<p><a href="hglegal.htm"><img SRC="ngibmcpy.gif" ALT="Copyright IBM Corporation 2000" BORDER=0 height=12 width=195></a></p>
+</body>
+</html>
diff --git a/examples/org.eclipse.swt.examples.ole.win32/icons/backward_nav.gif b/examples/org.eclipse.swt.examples.ole.win32/icons/backward_nav.gif
new file mode 100755
index 0000000000..5fcf41b783
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/icons/backward_nav.gif
Binary files differ
diff --git a/examples/org.eclipse.swt.examples.ole.win32/icons/forward_nav.gif b/examples/org.eclipse.swt.examples.ole.win32/icons/forward_nav.gif
new file mode 100755
index 0000000000..3b9b6af9b1
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/icons/forward_nav.gif
Binary files differ
diff --git a/examples/org.eclipse.swt.examples.ole.win32/icons/home_nav.gif b/examples/org.eclipse.swt.examples.ole.win32/icons/home_nav.gif
new file mode 100755
index 0000000000..77a2306ed2
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/icons/home_nav.gif
Binary files differ
diff --git a/examples/org.eclipse.swt.examples.ole.win32/icons/refresh_nav.gif b/examples/org.eclipse.swt.examples.ole.win32/icons/refresh_nav.gif
new file mode 100755
index 0000000000..e270e18bde
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/icons/refresh_nav.gif
Binary files differ
diff --git a/examples/org.eclipse.swt.examples.ole.win32/icons/search_nav.gif b/examples/org.eclipse.swt.examples.ole.win32/icons/search_nav.gif
new file mode 100755
index 0000000000..73ac91bddb
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/icons/search_nav.gif
Binary files differ
diff --git a/examples/org.eclipse.swt.examples.ole.win32/icons/stop_nav.gif b/examples/org.eclipse.swt.examples.ole.win32/icons/stop_nav.gif
new file mode 100755
index 0000000000..653d347b57
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/icons/stop_nav.gif
Binary files differ
diff --git a/examples/org.eclipse.swt.examples.ole.win32/icons/webbrowser_example.gif b/examples/org.eclipse.swt.examples.ole.win32/icons/webbrowser_example.gif
new file mode 100755
index 0000000000..895e22110d
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/icons/webbrowser_example.gif
Binary files differ
diff --git a/examples/org.eclipse.swt.examples.ole.win32/import.properties b/examples/org.eclipse.swt.examples.ole.win32/import.properties
new file mode 100755
index 0000000000..9185f56fc8
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/import.properties
@@ -0,0 +1,4 @@
+# Persist project settings for later import
+natures = org.eclipse.jdt.core.javanature; org.eclipse.pde.PluginNature
+builders = org.eclipse.jdt.core.javabuilder; org.eclipse.pde.ManifestBuilder; org.eclipse.pde.SchemaBuilder
+var.ECLIPSE_PLUGINS = <<ECLIPSE_PLUGINS>>
diff --git a/examples/org.eclipse.swt.examples.ole.win32/org/eclipse/swt/examples/ole/win32/OleBrowserView.java b/examples/org.eclipse.swt.examples.ole.win32/org/eclipse/swt/examples/ole/win32/OleBrowserView.java
new file mode 100755
index 0000000000..5f49f6b7cc
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/org/eclipse/swt/examples/ole/win32/OleBrowserView.java
@@ -0,0 +1,363 @@
+package org.eclipse.swt.examples.ole.win32;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.ole.win32.*; import org.eclipse.swt.widgets.*; import org.eclipse.ui.part.*;
+
+/**
+ * Ole uses <code>org.eclipse.swt</code> to demonstrate Win32 OLE / ActiveX
+ * integration.
+ *
+ * @see ViewPart
+ */
+public class OleBrowserView extends ViewPart {
+
+ private Composite displayArea;
+
+ private OleFrame webFrame;
+ private OleWebBrowser webBrowser;
+ private Text webUrl;
+ private OleControlSite webControlSite;
+ private ProgressBar webProgress;
+ private Label webStatus;
+ private Button webNavigateButton;
+
+ private ToolItem webCommandBackward;
+ private ToolItem webCommandForward;
+ private ToolItem webCommandHome;
+ private ToolItem webCommandStop;
+ private ToolItem webCommandRefresh;
+ private ToolItem webCommandSearch;
+
+ private boolean activated = false;
+
+ /**
+ * Constructs the OLE browser view.
+ */
+ public OleBrowserView() {
+ OlePlugin.initResources();
+ }
+
+ /**
+ * Creates the example.
+ *
+ * @see ViewPart#createPartControl
+ */
+ public void createPartControl(Composite parent) {
+ displayArea = new Composite(parent, SWT.NONE);
+
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 3;
+ displayArea.setLayout(gridLayout);
+
+ createToolbar();
+ createBrowserFrame();
+ createStatusArea();
+ createBrowserControl();
+ }
+
+ /**
+ * Cleanup
+ */
+ public void dispose() {
+ if (activated) {
+ webControlSite.deactivateInPlaceClient();
+ activated = false;
+ }
+ if (webBrowser != null) webBrowser.dispose();
+ webBrowser = null;
+ super.dispose();
+ }
+
+ /**
+ * Called when we must grab focus.
+ *
+ * @see org.eclipse.ui.part.ViewPart#setFocus
+ */
+ public void setFocus() {
+ webUrl.setFocus();
+ }
+
+ /**
+ * Creates the Web browser toolbar.
+ */
+ private void createToolbar() {
+ // Add a toolbar
+ ToolBar bar = new ToolBar(displayArea, SWT.NONE);
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+ gridData.horizontalSpan = 3;
+ bar.setLayoutData(gridData);
+
+ // Add a button to navigate backwards through previously visited web sites
+ webCommandBackward = new ToolItem(bar, SWT.NONE);
+ webCommandBackward.setToolTipText(OlePlugin.getResourceString("browser.Back.tooltip"));
+ webCommandBackward.setText(OlePlugin.getResourceString("browser.Back.text"));
+ webCommandBackward.setImage(OlePlugin.images[OlePlugin.biBack]);
+ webCommandBackward.setEnabled(false);
+ webCommandBackward.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event e) {
+ if (webBrowser == null) return;
+ webBrowser.GoBack();
+ }
+ });
+
+ // Add a button to navigate forward through previously visited web sites
+ webCommandForward = new ToolItem(bar, SWT.NONE);
+ webCommandForward.setToolTipText(OlePlugin.getResourceString("browser.Forward.tooltip"));
+ webCommandForward.setText(OlePlugin.getResourceString("browser.Forward.text"));
+ webCommandForward.setImage(OlePlugin.images[OlePlugin.biForward]);
+ webCommandForward.setEnabled(false);
+ webCommandForward.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event e) {
+ if (webBrowser == null) return;
+ webBrowser.GoForward();
+ }
+ });
+
+ // Add a separator
+ new ToolItem(bar, SWT.SEPARATOR);
+
+ // Add a button to navigate to the Home page
+ webCommandHome = new ToolItem(bar, SWT.NONE);
+ webCommandHome.setToolTipText(OlePlugin.getResourceString("browser.Home.tooltip"));
+ webCommandHome.setText(OlePlugin.getResourceString("browser.Home.text"));
+ webCommandHome.setImage(OlePlugin.images[OlePlugin.biHome]);
+ webCommandHome.setEnabled(false);
+ webCommandHome.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event e) {
+ if (webBrowser == null) return;
+ webBrowser.GoHome();
+ }
+ });
+
+ // Add a button to abort web page loading
+ webCommandStop = new ToolItem(bar, SWT.NONE);
+ webCommandStop.setToolTipText(OlePlugin.getResourceString("browser.Stop.tooltip"));
+ webCommandStop.setText(OlePlugin.getResourceString("browser.Stop.text"));
+ webCommandStop.setImage(OlePlugin.images[OlePlugin.biStop]);
+ webCommandStop.setEnabled(false);
+ webCommandStop.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event e) {
+ if (webBrowser == null) return;
+ webBrowser.Stop();
+ }
+ });
+
+ // Add a button to refresh the current web page
+ webCommandRefresh = new ToolItem(bar, SWT.NONE);
+ webCommandRefresh.setToolTipText(OlePlugin.getResourceString("browser.Refresh.tooltip"));
+ webCommandRefresh.setText(OlePlugin.getResourceString("browser.Refresh.text"));
+ webCommandRefresh.setImage(OlePlugin.images[OlePlugin.biRefresh]);
+ webCommandRefresh.setEnabled(false);
+ webCommandRefresh.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event e) {
+ if (webBrowser == null) return;
+ webBrowser.Refresh();
+ }
+ });
+
+ // Add a separator
+ new ToolItem(bar, SWT.SEPARATOR);
+
+ // Add a button to search the web
+ webCommandSearch = new ToolItem(bar, SWT.NONE);
+ webCommandSearch.setToolTipText(OlePlugin.getResourceString("browser.Search.tooltip"));
+ webCommandSearch.setText(OlePlugin.getResourceString("browser.Search.text"));
+ webCommandSearch.setImage(OlePlugin.images[OlePlugin.biSearch]);
+ webCommandSearch.setEnabled(false);
+ webCommandSearch.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event e) {
+ if (webBrowser == null) return;
+ webBrowser.GoSearch();
+ }
+ });
+
+ // Add a text area for Users to enter a url
+ Composite addressBar = new Composite(displayArea, SWT.NONE);
+ gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
+ gridData.horizontalSpan = 3;
+ addressBar.setLayoutData(gridData);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 3;
+ addressBar.setLayout(gridLayout);
+
+ Label addressLabel = new Label(addressBar, SWT.NONE);
+ gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
+ addressLabel.setLayoutData(gridData);
+ addressLabel.setText(OlePlugin.getResourceString("browser.Address.label"));
+ addressLabel.setFont(OlePlugin.browserFont);
+
+ webUrl = new Text(addressBar, SWT.SINGLE | SWT.BORDER);
+ webUrl.setFont(OlePlugin.browserFont);
+ gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
+ webUrl.setLayoutData(gridData);
+ webUrl.addFocusListener(new FocusAdapter() {
+ public void focusGained(FocusEvent e) {
+ webNavigateButton.getShell().setDefaultButton(webNavigateButton);
+ }
+ });
+
+ // Add a button to navigate to the web site specified in the Text area defined above
+ webNavigateButton = new Button(addressBar, SWT.PUSH);
+ gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
+ webNavigateButton.setLayoutData(gridData);
+ webNavigateButton.setText(OlePlugin.getResourceString("browser.Go.text"));
+ webNavigateButton.setFont(OlePlugin.browserFont);
+ webNavigateButton.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ if (webBrowser == null) return;
+ webBrowser.Navigate(webUrl.getText());
+ }
+ });
+
+ displayArea.addListener(SWT.KeyUp, new Listener() {
+ public void handleEvent(Event event) {
+ if (webBrowser == null) return;
+ if (event.keyCode == 13) {
+ webBrowser.Navigate(webUrl.getText());
+ }
+ }
+ });
+ }
+
+ /**
+ * Creates the Web browser OleFrame.
+ */
+ private void createBrowserFrame() {
+ // Every control must have an associated OleFrame:
+ webFrame = new OleFrame(displayArea, SWT.NONE);
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
+ gridData.horizontalSpan = 3;
+ webFrame.setLayoutData(gridData);
+ }
+
+ /**
+ * Creates the Web browser status area.
+ */
+ private void createStatusArea() {
+ // Add a progress bar to display downloading progress information
+ webProgress = new ProgressBar(displayArea, SWT.BORDER);
+ GridData gridData = new GridData();
+ gridData.horizontalAlignment = GridData.BEGINNING;
+ gridData.verticalAlignment = GridData.FILL;
+ webProgress.setLayoutData(gridData);
+
+ // Add a label for displaying status messages as they are received from the control
+ webStatus = new Label(displayArea, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
+ gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
+ gridData.horizontalSpan = 2;
+ webStatus.setLayoutData(gridData);
+ webStatus.setFont(OlePlugin.browserFont);
+ }
+
+ /**
+ * Creates Web browser control.
+ */
+ private void createBrowserControl() {
+ try {
+ // Create an Automation object for access to extended capabilities
+ webControlSite = new OleControlSite(webFrame, SWT.NONE, "Shell.Explorer");
+ OleAutomation oleAutomation = new OleAutomation(webControlSite);
+ webBrowser = new OleWebBrowser(oleAutomation);
+ } catch (SWTException ex) {
+ // Creation may have failed because control is not installed on machine
+ Label label = new Label(webFrame, SWT.BORDER);
+ OlePlugin.logError(OlePlugin.getResourceString("error.CouldNotCreateBrowserControl"), ex);
+ label.setText(OlePlugin.getResourceString("error.CouldNotCreateBrowserControl"));
+ return;
+ }
+
+ // Respond to ProgressChange events by updating the Progress bar
+ webControlSite.addEventListener(OleWebBrowser.ProgressChange, new OleListener() {
+ public void handleEvent(OleEvent event) {
+ Variant progress = event.arguments[0];
+ Variant maxProgress = event.arguments[1];
+ if (progress == null || maxProgress == null)
+ return;
+ webProgress.setMaximum(maxProgress.getInt());
+ webProgress.setSelection(progress.getInt());
+ }
+ });
+
+ // Respond to StatusTextChange events by updating the Status Text label
+ webControlSite.addEventListener(OleWebBrowser.StatusTextChange, new OleListener() {
+ public void handleEvent(OleEvent event) {
+ Variant statusText = event.arguments[0];
+ if (statusText == null) return;
+ String text = statusText.getString();
+ if (text != null)
+ webStatus.setText(text);
+ }
+ });
+
+ // Listen for changes to the ready state and print out the current state
+ webControlSite.addPropertyListener(OleWebBrowser.DISPID_READYSTATE, new OleListener() {
+ public void handleEvent(OleEvent event) {
+ if (event.detail == OLE.PROPERTY_CHANGING) return;
+ int state = webBrowser.getReadyState();
+ switch (state) {
+ case OleWebBrowser.READYSTATE_UNINITIALIZED:
+ webStatus.setText(
+ OlePlugin.getResourceString("browser.State.Uninitialized.text"));
+ webCommandBackward.setEnabled(false);
+ webCommandForward.setEnabled(false);
+ webCommandHome.setEnabled(false);
+ webCommandRefresh.setEnabled(false);
+ webCommandStop.setEnabled(false);
+ webCommandSearch.setEnabled(false);
+ break;
+ case OleWebBrowser.READYSTATE_LOADING:
+ webStatus.setText(
+ OlePlugin.getResourceString("browser.State.Loading.text"));
+ webCommandHome.setEnabled(true);
+ webCommandRefresh.setEnabled(true);
+ webCommandStop.setEnabled(true);
+ webCommandSearch.setEnabled(true);
+ break;
+ case OleWebBrowser.READYSTATE_LOADED:
+ webStatus.setText(
+ OlePlugin.getResourceString("browser.State.Loaded.text"));
+ webCommandStop.setEnabled(true);
+ break;
+ case OleWebBrowser.READYSTATE_INTERACTIVE:
+ webStatus.setText(
+ OlePlugin.getResourceString("browser.State.Interactive.text"));
+ webCommandStop.setEnabled(true);
+ break;
+ case OleWebBrowser.READYSTATE_COMPLETE:
+ webStatus.setText(
+ OlePlugin.getResourceString("browser.State.Complete.text"));
+ webCommandStop.setEnabled(false);
+ break;
+ }
+ }
+ });
+
+ // Listen for changes to the active command states
+ webControlSite.addEventListener(OleWebBrowser.CommandStateChange, new OleListener() {
+ public void handleEvent(OleEvent event) {
+ if (event.type != OleWebBrowser.CommandStateChange) return;
+ final int commandID =
+ (event.arguments[0] != null) ? event.arguments[0].getInt() : 0;
+ final boolean commandEnabled =
+ (event.arguments[1] != null) ? event.arguments[1].getBoolean() : false;
+
+ switch (commandID) {
+ case OleWebBrowser.CSC_NAVIGATEBACK:
+ webCommandBackward.setEnabled(commandEnabled);
+ break;
+ case OleWebBrowser.CSC_NAVIGATEFORWARD:
+ webCommandForward.setEnabled(commandEnabled);
+ break;
+ }
+ }
+ });
+
+ // in place activate the ActiveX control
+ activated = (webControlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE) == OLE.S_OK);
+ if (activated) webBrowser.GoHome();
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.ole.win32/org/eclipse/swt/examples/ole/win32/OlePlugin.java b/examples/org.eclipse.swt.examples.ole.win32/org/eclipse/swt/examples/ole/win32/OlePlugin.java
new file mode 100755
index 0000000000..4fee12a0b9
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/org/eclipse/swt/examples/ole/win32/OlePlugin.java
@@ -0,0 +1,170 @@
+package org.eclipse.swt.examples.ole.win32;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import java.io.*; import java.net.*; import java.text.*; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.ui.plugin.*;
+
+/**
+ * The main plugin class to be used in the desktop.
+ */
+public class OlePlugin extends AbstractUIPlugin {
+ //The shared instance.
+ private static OlePlugin plugin;
+ private static ResourceBundle resourceBundle;
+
+ static final int
+ biBack = 0,
+ biForward = 1,
+ biHome = 2,
+ biStop = 3,
+ biRefresh = 4,
+ biSearch = 5;
+ static final String[] imageLocations = {
+ "icons/backward_nav.gif",
+ "icons/forward_nav.gif",
+ "icons/home_nav.gif",
+ "icons/stop_nav.gif",
+ "icons/refresh_nav.gif",
+ "icons/search_nav.gif" };
+ static Image images[];
+ static Font browserFont;
+
+ /**
+ * Constructs an OLE plugin.
+ */
+ public OlePlugin(IPluginDescriptor descriptor) {
+ super(descriptor);
+ plugin = this;
+ resourceBundle = descriptor.getResourceBundle();
+ }
+
+ /**
+ * Clean up
+ */
+ public void shutdown() throws CoreException {
+ super.shutdown();
+ freeResources();
+ }
+
+ /**
+ * Returns the shared instance.
+ */
+ public static OlePlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns a string from the resource bundle.
+ * We don't want to crash because of a missing String.
+ * Returns the key if not found.
+ */
+ public static String getResourceString(String key) {
+ try {
+ return resourceBundle.getString(key);
+ } catch (MissingResourceException e) {
+ return key;
+ } catch (NullPointerException e) {
+ return "!" + key + "!";
+ }
+ }
+
+ /**
+ * Returns a string from the resource bundle and binds it
+ * with the given arguments. If the key is not found,
+ * return the key.
+ */
+ public static String getResourceString(String key, Object[] args) {
+ try {
+ return MessageFormat.format(getResourceString(key), args);
+ } catch (MissingResourceException e) {
+ return key;
+ } catch (NullPointerException e) {
+ return "!" + key + "!";
+ }
+ }
+
+ /**
+ * Log an error to the ILog for this plugin
+ *
+ * @param message the localized error message text
+ * @param exception the associated exception, or null
+ */
+ public static void logError(String message, Throwable exception) {
+ plugin.getLog().log(new Status(IStatus.ERROR, plugin.getDescriptor().getUniqueIdentifier(),
+ 0, message, exception));
+ }
+
+ /**
+ * Loads the resources.
+ */
+ public static void initResources() {
+ if (images == null) {
+ images = new Image[imageLocations.length];
+
+ for (int i = 0; i < imageLocations.length; ++i) {
+ images[i] = getImageFromPlugin(plugin.getDescriptor(), imageLocations[i]);
+ if (images[i] == null) {
+ freeResources();
+ logError(getResourceString("error.CouldNotLoadResources"), null);
+ throw new IllegalStateException();
+ }
+ }
+ }
+ if (browserFont == null) {
+ try {
+ browserFont = new Font (null, "MS Sans Serif", 8, SWT.NULL);
+ } catch (Throwable ex) {
+ }
+ }
+ if (images == null || browserFont == null) {
+ freeResources();
+ logError(getResourceString("error.CouldNotLoadResources"), null);
+ throw new IllegalStateException();
+ }
+ }
+
+ /**
+ * Frees the resources
+ */
+ public static void freeResources() {
+ if (images != null) {
+ for (int i = 0; i < images.length; ++i) {
+ final Image image = images[i];
+ if (image != null) image.dispose();
+ }
+ images = null;
+ }
+ if (browserFont != null) browserFont.dispose ();
+ browserFont = null;
+ }
+
+ /**
+ * Gets an image from a path relative to the plugin install directory.
+ *
+ * @param pd the plugin descriptor for the plugin with the image
+ * @param iconPath the path relative to the install directory
+ * @return the image, or null if not found
+ */
+ private static Image getImageFromPlugin(IPluginDescriptor pd, String iconPath) {
+ InputStream is = null;
+ try {
+ URL installUrl = pd.getInstallURL();
+ URL url = new URL(installUrl, iconPath);
+ is = url.openConnection().getInputStream();
+ ImageData source = new ImageData(is);
+ ImageData mask = source.getTransparencyMask();
+ Image image = new Image(null, source, mask);
+ return image;
+ } catch (Throwable ex) {
+ return null;
+ } finally {
+ try {
+ if (is != null) is.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.ole.win32/org/eclipse/swt/examples/ole/win32/OleWebBrowser.java b/examples/org.eclipse.swt.examples.ole.win32/org/eclipse/swt/examples/ole/win32/OleWebBrowser.java
new file mode 100755
index 0000000000..555cfb935e
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/org/eclipse/swt/examples/ole/win32/OleWebBrowser.java
@@ -0,0 +1,251 @@
+package org.eclipse.swt.examples.ole.win32;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.ole.win32.*;
+
+/**
+ * Wrapper for an OleAutomation object used to send commands
+ * to a Win32 "Shell.Explorer" OLE control.
+ *
+ * Instances of this class manage the setup, typical use and teardown of
+ * a simple web browser.
+ */
+class OleWebBrowser {
+ /* See the Windows Platform SDK documentation for more information about the
+ * OLE control used here and its usage.
+ */
+ // Generated from typelib filename: shdocvw.dll
+
+ // Constants for WebBrowser CommandStateChange
+ public static final int CSC_UPDATECOMMANDS = -1;
+ public static final int CSC_NAVIGATEFORWARD = 1;
+ public static final int CSC_NAVIGATEBACK = 2;
+
+ // COnstants for Web Browser ReadyState
+ public static final int READYSTATE_UNINITIALIZED = 0;
+ public static final int READYSTATE_LOADING = 1;
+ public static final int READYSTATE_LOADED = 2;
+ public static final int READYSTATE_INTERACTIVE = 3;
+ public static final int READYSTATE_COMPLETE = 4;
+
+ // Web Browser Control Events
+ public static final int BeforeNavigate = 100; // Fired when a new hyperlink is being navigated to.
+ public static final int NavigateComplete = 101; // Fired when the document being navigated to becomes visible and enters the navigation stack.
+ public static final int StatusTextChange = 102; // Statusbar text changed.
+ public static final int ProgressChange = 108; // Fired when download progress is updated.
+ public static final int DownloadComplete = 104; // Download of page complete.
+ public static final int CommandStateChange = 105; // The enabled state of a command changed
+ public static final int DownloadBegin = 106; // Download of a page started.
+ public static final int NewWindow = 107; // Fired when a new window should be created.
+ public static final int TitleChange = 113; // Document title changed.
+ public static final int FrameBeforeNavigate = 200; // Fired when a new hyperlink is being navigated to in a frame.
+ public static final int FrameNavigateComplete = 201; // Fired when a new hyperlink is being navigated to in a frame.
+ public static final int FrameNewWindow = 204; // Fired when a new window should be created.
+ public static final int Quit = 103; // Fired when application is quiting.
+ public static final int WindowMove = 109; // Fired when window has been moved.
+ public static final int WindowResize = 110; // Fired when window has been sized.
+ public static final int WindowActivate = 111; // Fired when window has been activated.
+ public static final int PropertyChange = 112; // Fired when the PutProperty method has been called.
+
+ // Web Browser properties
+ public static final int DISPID_READYSTATE = -525;
+
+ private OleAutomation oleAutomation;
+
+ /**
+ * Creates a Web browser control.
+ * <p>
+ * Typical use:<br>
+ * <code>
+ * OleControlSite oleControlSite = new OleControlSite(oleFrame, style, "Shell.Explorer");<br>
+ * OleAutomation oleAutomation = new OleAutomation(oleControlSite);<br>
+ * OleWebBrowser webBrowser = new OleWebBrowser(oleControlSite, oleAutomation);<br>
+ * </code>
+ *
+ * @param oleAutomation the OleAutomation object for this control.
+ * @param oleControlSite the OleControlSite object for this control.
+ */
+ public OleWebBrowser(OleAutomation oleAutomation) {
+ this.oleAutomation = oleAutomation;
+ }
+
+
+ /**
+ * Disposes of the Web browser control.
+ */
+ public void dispose() {
+ if (oleAutomation != null) oleAutomation.dispose();
+ oleAutomation = null;
+ }
+
+ /*
+ * Interact with the Control via OLE Automation
+ *
+ * Note: You can hard code the DISPIDs if you know them beforehand
+ * this is of course the fastest way, but you increase coupling
+ * to the control.
+ */
+
+ /**
+ * Returns the current web page title.
+ *
+ * @return the current web page title String
+ */
+ public String getLocationName() {
+ // dispid=210, type=PROPGET, name="LocationName"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"LocationName"});
+ int dispIdMember = rgdispid[0];
+ Variant pVarResult = oleAutomation.getProperty(dispIdMember);
+ if (pVarResult == null) return null;
+ return pVarResult.getString();
+ }
+
+ /**
+ * Returns the current URL.
+ *
+ * @return the current URL String
+ */
+ public String getLocationURL() {
+ // dispid=211, type=PROPGET, name="LocationURL"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"LocationURL"});
+ int dispIdMember = rgdispid[0];
+
+ Variant pVarResult = oleAutomation.getProperty(dispIdMember);
+ if (pVarResult == null) return null;
+ return pVarResult.getString();
+ }
+
+ /**
+ * Returns the current state of the control.
+ *
+ * @return the current state of the control, one of:
+ * READYSTATE_UNINITIALIZED;
+ * READYSTATE_LOADING;
+ * READYSTATE_LOADED;
+ * READYSTATE_INTERACTIVE;
+ * READYSTATE_COMPLETE.
+ */
+ public int getReadyState() {
+ // dispid=4294966771, type=PROPGET, name="ReadyState"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"ReadyState"});
+ int dispIdMember = rgdispid[0];
+
+ Variant pVarResult = oleAutomation.getProperty(dispIdMember);
+ if (pVarResult == null) return -1;
+ return pVarResult.getInt();
+ }
+
+ /**
+ * Navigates backwards through previously visited web sites.
+ *
+ * @return the platform-defined result code for the "GoBack" method invocation
+ */
+ public int GoBack() {
+
+ // dispid=100, type=METHOD, name="GoBack"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"GoBack"});
+ int dispIdMember = rgdispid[0];
+
+ Variant pVarResult = oleAutomation.invoke(dispIdMember);
+ if (pVarResult == null) return 0;
+ return pVarResult.getInt();
+ }
+
+ /**
+ * Navigates backwards through previously visited web sites.
+ *
+ * @return the platform-defined result code for the "GoForward" method invocation
+ */
+ public int GoForward() {
+
+ // dispid=101, type=METHOD, name="GoForward"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"GoForward"});
+ int dispIdMember = rgdispid[0];
+
+ Variant pVarResult = oleAutomation.invoke(dispIdMember);
+ if (pVarResult == null) return 0;
+ return pVarResult.getInt();
+ }
+
+ /**
+ * Navigates to home page.
+ *
+ * @return the platform-defined result code for the "GoHome" method invocation
+ */
+ public int GoHome() {
+ // dispid=102, type=METHOD, name="GoHome"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"GoHome"});
+ int dispIdMember = rgdispid[0];
+
+ Variant pVarResult = oleAutomation.invoke(dispIdMember);
+ if (pVarResult == null) return 0;
+ return pVarResult.getInt();
+ }
+
+ /**
+ * Navigates to user-specified Web search gateway.
+ *
+ * @return the platform-defined result code for the "GoSearch" method invocation
+ */
+ public int GoSearch() {
+ // dispid=103, type=METHOD, name="GoSearch"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"GoSearch"});
+ int dispIdMember = rgdispid[0];
+
+ Variant pVarResult = oleAutomation.invoke(dispIdMember);
+ if (pVarResult == null) return 0;
+ return pVarResult.getInt();
+ }
+
+ /**
+ * Navigates to a particular URL.
+ *
+ * @return the platform-defined result code for the "Navigate" method invocation
+ */
+ public int Navigate(String url) {
+ // dispid=104, type=METHOD, name="Navigate"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"Navigate", "URL"});
+ int dispIdMember = rgdispid[0];
+
+ Variant[] rgvarg = new Variant[1];
+ rgvarg[0] = new Variant(url);
+ int[] rgdispidNamedArgs = new int[1];
+ rgdispidNamedArgs[0] = rgdispid[1]; // identifier of argument
+ Variant pVarResult = oleAutomation.invoke(dispIdMember, rgvarg, rgdispidNamedArgs);
+
+ if (pVarResult == null) return 0;
+ return pVarResult.getInt();
+ }
+
+ /**
+ * Refreshes the currently viewed page.
+ *
+ * @return the platform-defined result code for the "Refresh" method invocation
+ */
+ public void Refresh(){
+ // dispid= 4294966746, type=METHOD, name="Refresh"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"Refresh"});
+ int dispIdMember = rgdispid[0];
+
+ oleAutomation.invokeNoReply(dispIdMember);
+ }
+
+ /**
+ * Aborts loading of the currnet page.
+ *
+ * @return the platform-defined result code for the "Stop" method invocation
+ */
+ public void Stop() {
+ // dispid=106, type=METHOD, name="Stop"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"Stop"});
+ int dispIdMember = rgdispid[0];
+
+ Variant pVarResult = oleAutomation.invoke(dispIdMember);
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.ole.win32/plugin.properties b/examples/org.eclipse.swt.examples.ole.win32/plugin.properties
index 47dba6e946..b28c799ff5 100755
--- a/examples/org.eclipse.swt.examples.ole.win32/plugin.properties
+++ b/examples/org.eclipse.swt.examples.ole.win32/plugin.properties
@@ -2,10 +2,23 @@ plugin.SWTOLEExample.name = SWT OLE Example Plugin (Win32)
category.SWTExamples.name = SWT Examples
view.OLEWebBrowserExample.name = OLE Web Browser (Win32)
-launchcategory.SWTExamples.name = SWT Examples
-launchcategory.SWTExamples.description = A collection of Standard Widget Toolkit examples.
-launchitem.OLEWebBrowserExample.name = OLE Web Browser (Win32)
-launchitem.OLEWebBrowserExample.description = This example demonstrates how to embed Active X / OLE controls into an SWT application or an Eclipse view. When the view is activated, it will create an instance of a Windows "Shell.Explorer" control and provide a GUI interface to it via OLE Automation. To run this example, Internet Explorer must be installed.
+launchcategory.SWTWin32OnlyExamples.name = Win32 only
+launchcategory.SWTWin32OnlyExamples.description = \
+ A collection of Standard Widget Toolkit examples for Windows systems only.
+
+launchitem.OLEWebBrowserExample.name = OLE Web Browser
+launchitem.OLEWebBrowserExample.description = \
+ This example demonstrates how to embed Active X / OLE controls into an SWT \
+ application or an Eclipse view.\n\n\
+ When the view is activated, it will create an instance of a Windows "Shell.Explorer" \
+ control and provide a GUI interface to it via OLE Automation. The OLE Web Browser has \
+ Back and Forward buttons to take you to recently visited pages. The browser also contains \
+ a Home button to take you to the web browser's home page, a Stop button which stops the \
+ current transfer, a Search button which will search for text typed in the Address text field, and \
+ a Refresh button which re-draws the contents of the currently displayed page. There is also a \
+ Go button which, when clicked, will attempt to load the page specified in the Address field. \
+ One would expect each of these operations on every web browser.\n\n\
+ To run this example, Internet Explorer must be installed.
browser.Back.text = Backward
browser.Back.tooltip = Surf to previously viewed Web site
@@ -35,5 +48,5 @@ browser.State.Loaded.text = Ready.
browser.State.Interactive.text = Loading Web site...
browser.State.Complete.text = Done.
-error.CouldNotLoadResources = Unable to load resources : {0}
-error.CouldNotCreateBrowserControl = Unable to create <<Browser Control>> : {0}
+error.CouldNotLoadResources = Unable to load resources
+error.CouldNotCreateBrowserControl = Unable to create <<Browser Control>>
diff --git a/examples/org.eclipse.swt.examples.ole.win32/plugin.xml b/examples/org.eclipse.swt.examples.ole.win32/plugin.xml
index 63799a614d..68ed92796b 100755
--- a/examples/org.eclipse.swt.examples.ole.win32/plugin.xml
+++ b/examples/org.eclipse.swt.examples.ole.win32/plugin.xml
@@ -4,7 +4,7 @@
id="org.eclipse.swt.examples.ole.win32"
name="%plugin.SWTOLEExample.name"
version="0.9"
- provider-name="IBM"
+ provider-name="Object Technology International, Inc."
class="org.eclipse.swt.examples.ole.win32.OlePlugin">
<!-- Required plugins -->
<requires>
@@ -19,35 +19,35 @@
<library name="olewin32.jar"/>
</runtime>
-<!-- Extensions -->
<!-- Extension points -->
+<!-- Extensions -->
<extension
point="org.eclipse.ui.views">
- <category
- name="%category.SWTExamples.name"
- id="org.eclipse.swt.examples.category">
- </category>
<view
name="%view.OLEWebBrowserExample.name"
category="org.eclipse.swt.examples.category"
class="org.eclipse.swt.examples.ole.win32.OleBrowserView"
- id="org.eclipse.swt.examples.ole.win32.browserView">
+ id="org.eclipse.swt.examples.ole.win32.browserView"
+ icon="icons/webbrowser_example.gif">
</view>
</extension>
<extension
point="org.eclipse.swt.examples.launcher.launchItems">
<category
- name="%launchcategory.SWTExamples.name"
- description="%launchcategory.SWTExamples.description"
- id="org.eclipse.swt.examples.launchcategory">
+ name="%launchcategory.SWTWin32OnlyExamples.name"
+ description="%launchcategory.SWTWin32OnlyExamples.description"
+ id="org.eclipse.swt.examples.launchWin32OnlyCategory">
</category>
- <viewItem
- viewId="org.eclipse.swt.examples.ole.win32.browserView"
+ <item
name="%launchitem.OLEWebBrowserExample.name"
description="%launchitem.OLEWebBrowserExample.description"
- category="org.eclipse.swt.examples.launchcategory"
- source="olewebbrowsersrc.zip"
- id="org.eclipse.swt.examples.ole.win32.launcher">
- </viewItem>
+ category="org.eclipse.swt.examples.launchWin32OnlyCategory"
+ id="org.eclipse.swt.examples.ole.win32.viewlauncher"
+ icon="icons/webbrowser_example.gif">
+ <view
+ viewId="org.eclipse.swt.examples.ole.win32.browserView"/>
+ <source
+ zip="olewin32src.zip"/>
+ </item>
</extension>
</plugin>
diff --git a/examples/org.eclipse.swt.examples.ole.win32/src/org/eclipse/swt/examples/ole/win32/OleBrowserView.java b/examples/org.eclipse.swt.examples.ole.win32/src/org/eclipse/swt/examples/ole/win32/OleBrowserView.java
new file mode 100755
index 0000000000..5f49f6b7cc
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/src/org/eclipse/swt/examples/ole/win32/OleBrowserView.java
@@ -0,0 +1,363 @@
+package org.eclipse.swt.examples.ole.win32;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.ole.win32.*; import org.eclipse.swt.widgets.*; import org.eclipse.ui.part.*;
+
+/**
+ * Ole uses <code>org.eclipse.swt</code> to demonstrate Win32 OLE / ActiveX
+ * integration.
+ *
+ * @see ViewPart
+ */
+public class OleBrowserView extends ViewPart {
+
+ private Composite displayArea;
+
+ private OleFrame webFrame;
+ private OleWebBrowser webBrowser;
+ private Text webUrl;
+ private OleControlSite webControlSite;
+ private ProgressBar webProgress;
+ private Label webStatus;
+ private Button webNavigateButton;
+
+ private ToolItem webCommandBackward;
+ private ToolItem webCommandForward;
+ private ToolItem webCommandHome;
+ private ToolItem webCommandStop;
+ private ToolItem webCommandRefresh;
+ private ToolItem webCommandSearch;
+
+ private boolean activated = false;
+
+ /**
+ * Constructs the OLE browser view.
+ */
+ public OleBrowserView() {
+ OlePlugin.initResources();
+ }
+
+ /**
+ * Creates the example.
+ *
+ * @see ViewPart#createPartControl
+ */
+ public void createPartControl(Composite parent) {
+ displayArea = new Composite(parent, SWT.NONE);
+
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 3;
+ displayArea.setLayout(gridLayout);
+
+ createToolbar();
+ createBrowserFrame();
+ createStatusArea();
+ createBrowserControl();
+ }
+
+ /**
+ * Cleanup
+ */
+ public void dispose() {
+ if (activated) {
+ webControlSite.deactivateInPlaceClient();
+ activated = false;
+ }
+ if (webBrowser != null) webBrowser.dispose();
+ webBrowser = null;
+ super.dispose();
+ }
+
+ /**
+ * Called when we must grab focus.
+ *
+ * @see org.eclipse.ui.part.ViewPart#setFocus
+ */
+ public void setFocus() {
+ webUrl.setFocus();
+ }
+
+ /**
+ * Creates the Web browser toolbar.
+ */
+ private void createToolbar() {
+ // Add a toolbar
+ ToolBar bar = new ToolBar(displayArea, SWT.NONE);
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+ gridData.horizontalSpan = 3;
+ bar.setLayoutData(gridData);
+
+ // Add a button to navigate backwards through previously visited web sites
+ webCommandBackward = new ToolItem(bar, SWT.NONE);
+ webCommandBackward.setToolTipText(OlePlugin.getResourceString("browser.Back.tooltip"));
+ webCommandBackward.setText(OlePlugin.getResourceString("browser.Back.text"));
+ webCommandBackward.setImage(OlePlugin.images[OlePlugin.biBack]);
+ webCommandBackward.setEnabled(false);
+ webCommandBackward.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event e) {
+ if (webBrowser == null) return;
+ webBrowser.GoBack();
+ }
+ });
+
+ // Add a button to navigate forward through previously visited web sites
+ webCommandForward = new ToolItem(bar, SWT.NONE);
+ webCommandForward.setToolTipText(OlePlugin.getResourceString("browser.Forward.tooltip"));
+ webCommandForward.setText(OlePlugin.getResourceString("browser.Forward.text"));
+ webCommandForward.setImage(OlePlugin.images[OlePlugin.biForward]);
+ webCommandForward.setEnabled(false);
+ webCommandForward.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event e) {
+ if (webBrowser == null) return;
+ webBrowser.GoForward();
+ }
+ });
+
+ // Add a separator
+ new ToolItem(bar, SWT.SEPARATOR);
+
+ // Add a button to navigate to the Home page
+ webCommandHome = new ToolItem(bar, SWT.NONE);
+ webCommandHome.setToolTipText(OlePlugin.getResourceString("browser.Home.tooltip"));
+ webCommandHome.setText(OlePlugin.getResourceString("browser.Home.text"));
+ webCommandHome.setImage(OlePlugin.images[OlePlugin.biHome]);
+ webCommandHome.setEnabled(false);
+ webCommandHome.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event e) {
+ if (webBrowser == null) return;
+ webBrowser.GoHome();
+ }
+ });
+
+ // Add a button to abort web page loading
+ webCommandStop = new ToolItem(bar, SWT.NONE);
+ webCommandStop.setToolTipText(OlePlugin.getResourceString("browser.Stop.tooltip"));
+ webCommandStop.setText(OlePlugin.getResourceString("browser.Stop.text"));
+ webCommandStop.setImage(OlePlugin.images[OlePlugin.biStop]);
+ webCommandStop.setEnabled(false);
+ webCommandStop.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event e) {
+ if (webBrowser == null) return;
+ webBrowser.Stop();
+ }
+ });
+
+ // Add a button to refresh the current web page
+ webCommandRefresh = new ToolItem(bar, SWT.NONE);
+ webCommandRefresh.setToolTipText(OlePlugin.getResourceString("browser.Refresh.tooltip"));
+ webCommandRefresh.setText(OlePlugin.getResourceString("browser.Refresh.text"));
+ webCommandRefresh.setImage(OlePlugin.images[OlePlugin.biRefresh]);
+ webCommandRefresh.setEnabled(false);
+ webCommandRefresh.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event e) {
+ if (webBrowser == null) return;
+ webBrowser.Refresh();
+ }
+ });
+
+ // Add a separator
+ new ToolItem(bar, SWT.SEPARATOR);
+
+ // Add a button to search the web
+ webCommandSearch = new ToolItem(bar, SWT.NONE);
+ webCommandSearch.setToolTipText(OlePlugin.getResourceString("browser.Search.tooltip"));
+ webCommandSearch.setText(OlePlugin.getResourceString("browser.Search.text"));
+ webCommandSearch.setImage(OlePlugin.images[OlePlugin.biSearch]);
+ webCommandSearch.setEnabled(false);
+ webCommandSearch.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event e) {
+ if (webBrowser == null) return;
+ webBrowser.GoSearch();
+ }
+ });
+
+ // Add a text area for Users to enter a url
+ Composite addressBar = new Composite(displayArea, SWT.NONE);
+ gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
+ gridData.horizontalSpan = 3;
+ addressBar.setLayoutData(gridData);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 3;
+ addressBar.setLayout(gridLayout);
+
+ Label addressLabel = new Label(addressBar, SWT.NONE);
+ gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
+ addressLabel.setLayoutData(gridData);
+ addressLabel.setText(OlePlugin.getResourceString("browser.Address.label"));
+ addressLabel.setFont(OlePlugin.browserFont);
+
+ webUrl = new Text(addressBar, SWT.SINGLE | SWT.BORDER);
+ webUrl.setFont(OlePlugin.browserFont);
+ gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
+ webUrl.setLayoutData(gridData);
+ webUrl.addFocusListener(new FocusAdapter() {
+ public void focusGained(FocusEvent e) {
+ webNavigateButton.getShell().setDefaultButton(webNavigateButton);
+ }
+ });
+
+ // Add a button to navigate to the web site specified in the Text area defined above
+ webNavigateButton = new Button(addressBar, SWT.PUSH);
+ gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
+ webNavigateButton.setLayoutData(gridData);
+ webNavigateButton.setText(OlePlugin.getResourceString("browser.Go.text"));
+ webNavigateButton.setFont(OlePlugin.browserFont);
+ webNavigateButton.addListener(SWT.Selection, new Listener() {
+ public void handleEvent(Event event) {
+ if (webBrowser == null) return;
+ webBrowser.Navigate(webUrl.getText());
+ }
+ });
+
+ displayArea.addListener(SWT.KeyUp, new Listener() {
+ public void handleEvent(Event event) {
+ if (webBrowser == null) return;
+ if (event.keyCode == 13) {
+ webBrowser.Navigate(webUrl.getText());
+ }
+ }
+ });
+ }
+
+ /**
+ * Creates the Web browser OleFrame.
+ */
+ private void createBrowserFrame() {
+ // Every control must have an associated OleFrame:
+ webFrame = new OleFrame(displayArea, SWT.NONE);
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
+ gridData.horizontalSpan = 3;
+ webFrame.setLayoutData(gridData);
+ }
+
+ /**
+ * Creates the Web browser status area.
+ */
+ private void createStatusArea() {
+ // Add a progress bar to display downloading progress information
+ webProgress = new ProgressBar(displayArea, SWT.BORDER);
+ GridData gridData = new GridData();
+ gridData.horizontalAlignment = GridData.BEGINNING;
+ gridData.verticalAlignment = GridData.FILL;
+ webProgress.setLayoutData(gridData);
+
+ // Add a label for displaying status messages as they are received from the control
+ webStatus = new Label(displayArea, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
+ gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
+ gridData.horizontalSpan = 2;
+ webStatus.setLayoutData(gridData);
+ webStatus.setFont(OlePlugin.browserFont);
+ }
+
+ /**
+ * Creates Web browser control.
+ */
+ private void createBrowserControl() {
+ try {
+ // Create an Automation object for access to extended capabilities
+ webControlSite = new OleControlSite(webFrame, SWT.NONE, "Shell.Explorer");
+ OleAutomation oleAutomation = new OleAutomation(webControlSite);
+ webBrowser = new OleWebBrowser(oleAutomation);
+ } catch (SWTException ex) {
+ // Creation may have failed because control is not installed on machine
+ Label label = new Label(webFrame, SWT.BORDER);
+ OlePlugin.logError(OlePlugin.getResourceString("error.CouldNotCreateBrowserControl"), ex);
+ label.setText(OlePlugin.getResourceString("error.CouldNotCreateBrowserControl"));
+ return;
+ }
+
+ // Respond to ProgressChange events by updating the Progress bar
+ webControlSite.addEventListener(OleWebBrowser.ProgressChange, new OleListener() {
+ public void handleEvent(OleEvent event) {
+ Variant progress = event.arguments[0];
+ Variant maxProgress = event.arguments[1];
+ if (progress == null || maxProgress == null)
+ return;
+ webProgress.setMaximum(maxProgress.getInt());
+ webProgress.setSelection(progress.getInt());
+ }
+ });
+
+ // Respond to StatusTextChange events by updating the Status Text label
+ webControlSite.addEventListener(OleWebBrowser.StatusTextChange, new OleListener() {
+ public void handleEvent(OleEvent event) {
+ Variant statusText = event.arguments[0];
+ if (statusText == null) return;
+ String text = statusText.getString();
+ if (text != null)
+ webStatus.setText(text);
+ }
+ });
+
+ // Listen for changes to the ready state and print out the current state
+ webControlSite.addPropertyListener(OleWebBrowser.DISPID_READYSTATE, new OleListener() {
+ public void handleEvent(OleEvent event) {
+ if (event.detail == OLE.PROPERTY_CHANGING) return;
+ int state = webBrowser.getReadyState();
+ switch (state) {
+ case OleWebBrowser.READYSTATE_UNINITIALIZED:
+ webStatus.setText(
+ OlePlugin.getResourceString("browser.State.Uninitialized.text"));
+ webCommandBackward.setEnabled(false);
+ webCommandForward.setEnabled(false);
+ webCommandHome.setEnabled(false);
+ webCommandRefresh.setEnabled(false);
+ webCommandStop.setEnabled(false);
+ webCommandSearch.setEnabled(false);
+ break;
+ case OleWebBrowser.READYSTATE_LOADING:
+ webStatus.setText(
+ OlePlugin.getResourceString("browser.State.Loading.text"));
+ webCommandHome.setEnabled(true);
+ webCommandRefresh.setEnabled(true);
+ webCommandStop.setEnabled(true);
+ webCommandSearch.setEnabled(true);
+ break;
+ case OleWebBrowser.READYSTATE_LOADED:
+ webStatus.setText(
+ OlePlugin.getResourceString("browser.State.Loaded.text"));
+ webCommandStop.setEnabled(true);
+ break;
+ case OleWebBrowser.READYSTATE_INTERACTIVE:
+ webStatus.setText(
+ OlePlugin.getResourceString("browser.State.Interactive.text"));
+ webCommandStop.setEnabled(true);
+ break;
+ case OleWebBrowser.READYSTATE_COMPLETE:
+ webStatus.setText(
+ OlePlugin.getResourceString("browser.State.Complete.text"));
+ webCommandStop.setEnabled(false);
+ break;
+ }
+ }
+ });
+
+ // Listen for changes to the active command states
+ webControlSite.addEventListener(OleWebBrowser.CommandStateChange, new OleListener() {
+ public void handleEvent(OleEvent event) {
+ if (event.type != OleWebBrowser.CommandStateChange) return;
+ final int commandID =
+ (event.arguments[0] != null) ? event.arguments[0].getInt() : 0;
+ final boolean commandEnabled =
+ (event.arguments[1] != null) ? event.arguments[1].getBoolean() : false;
+
+ switch (commandID) {
+ case OleWebBrowser.CSC_NAVIGATEBACK:
+ webCommandBackward.setEnabled(commandEnabled);
+ break;
+ case OleWebBrowser.CSC_NAVIGATEFORWARD:
+ webCommandForward.setEnabled(commandEnabled);
+ break;
+ }
+ }
+ });
+
+ // in place activate the ActiveX control
+ activated = (webControlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE) == OLE.S_OK);
+ if (activated) webBrowser.GoHome();
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.ole.win32/src/org/eclipse/swt/examples/ole/win32/OlePlugin.java b/examples/org.eclipse.swt.examples.ole.win32/src/org/eclipse/swt/examples/ole/win32/OlePlugin.java
new file mode 100755
index 0000000000..4fee12a0b9
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/src/org/eclipse/swt/examples/ole/win32/OlePlugin.java
@@ -0,0 +1,170 @@
+package org.eclipse.swt.examples.ole.win32;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import java.io.*; import java.net.*; import java.text.*; import java.util.*; import org.eclipse.core.runtime.*; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.ui.plugin.*;
+
+/**
+ * The main plugin class to be used in the desktop.
+ */
+public class OlePlugin extends AbstractUIPlugin {
+ //The shared instance.
+ private static OlePlugin plugin;
+ private static ResourceBundle resourceBundle;
+
+ static final int
+ biBack = 0,
+ biForward = 1,
+ biHome = 2,
+ biStop = 3,
+ biRefresh = 4,
+ biSearch = 5;
+ static final String[] imageLocations = {
+ "icons/backward_nav.gif",
+ "icons/forward_nav.gif",
+ "icons/home_nav.gif",
+ "icons/stop_nav.gif",
+ "icons/refresh_nav.gif",
+ "icons/search_nav.gif" };
+ static Image images[];
+ static Font browserFont;
+
+ /**
+ * Constructs an OLE plugin.
+ */
+ public OlePlugin(IPluginDescriptor descriptor) {
+ super(descriptor);
+ plugin = this;
+ resourceBundle = descriptor.getResourceBundle();
+ }
+
+ /**
+ * Clean up
+ */
+ public void shutdown() throws CoreException {
+ super.shutdown();
+ freeResources();
+ }
+
+ /**
+ * Returns the shared instance.
+ */
+ public static OlePlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns a string from the resource bundle.
+ * We don't want to crash because of a missing String.
+ * Returns the key if not found.
+ */
+ public static String getResourceString(String key) {
+ try {
+ return resourceBundle.getString(key);
+ } catch (MissingResourceException e) {
+ return key;
+ } catch (NullPointerException e) {
+ return "!" + key + "!";
+ }
+ }
+
+ /**
+ * Returns a string from the resource bundle and binds it
+ * with the given arguments. If the key is not found,
+ * return the key.
+ */
+ public static String getResourceString(String key, Object[] args) {
+ try {
+ return MessageFormat.format(getResourceString(key), args);
+ } catch (MissingResourceException e) {
+ return key;
+ } catch (NullPointerException e) {
+ return "!" + key + "!";
+ }
+ }
+
+ /**
+ * Log an error to the ILog for this plugin
+ *
+ * @param message the localized error message text
+ * @param exception the associated exception, or null
+ */
+ public static void logError(String message, Throwable exception) {
+ plugin.getLog().log(new Status(IStatus.ERROR, plugin.getDescriptor().getUniqueIdentifier(),
+ 0, message, exception));
+ }
+
+ /**
+ * Loads the resources.
+ */
+ public static void initResources() {
+ if (images == null) {
+ images = new Image[imageLocations.length];
+
+ for (int i = 0; i < imageLocations.length; ++i) {
+ images[i] = getImageFromPlugin(plugin.getDescriptor(), imageLocations[i]);
+ if (images[i] == null) {
+ freeResources();
+ logError(getResourceString("error.CouldNotLoadResources"), null);
+ throw new IllegalStateException();
+ }
+ }
+ }
+ if (browserFont == null) {
+ try {
+ browserFont = new Font (null, "MS Sans Serif", 8, SWT.NULL);
+ } catch (Throwable ex) {
+ }
+ }
+ if (images == null || browserFont == null) {
+ freeResources();
+ logError(getResourceString("error.CouldNotLoadResources"), null);
+ throw new IllegalStateException();
+ }
+ }
+
+ /**
+ * Frees the resources
+ */
+ public static void freeResources() {
+ if (images != null) {
+ for (int i = 0; i < images.length; ++i) {
+ final Image image = images[i];
+ if (image != null) image.dispose();
+ }
+ images = null;
+ }
+ if (browserFont != null) browserFont.dispose ();
+ browserFont = null;
+ }
+
+ /**
+ * Gets an image from a path relative to the plugin install directory.
+ *
+ * @param pd the plugin descriptor for the plugin with the image
+ * @param iconPath the path relative to the install directory
+ * @return the image, or null if not found
+ */
+ private static Image getImageFromPlugin(IPluginDescriptor pd, String iconPath) {
+ InputStream is = null;
+ try {
+ URL installUrl = pd.getInstallURL();
+ URL url = new URL(installUrl, iconPath);
+ is = url.openConnection().getInputStream();
+ ImageData source = new ImageData(is);
+ ImageData mask = source.getTransparencyMask();
+ Image image = new Image(null, source, mask);
+ return image;
+ } catch (Throwable ex) {
+ return null;
+ } finally {
+ try {
+ if (is != null) is.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+}
diff --git a/examples/org.eclipse.swt.examples.ole.win32/src/org/eclipse/swt/examples/ole/win32/OleWebBrowser.java b/examples/org.eclipse.swt.examples.ole.win32/src/org/eclipse/swt/examples/ole/win32/OleWebBrowser.java
new file mode 100755
index 0000000000..555cfb935e
--- /dev/null
+++ b/examples/org.eclipse.swt.examples.ole.win32/src/org/eclipse/swt/examples/ole/win32/OleWebBrowser.java
@@ -0,0 +1,251 @@
+package org.eclipse.swt.examples.ole.win32;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
+ */
+
+import org.eclipse.swt.*;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.ole.win32.*;
+
+/**
+ * Wrapper for an OleAutomation object used to send commands
+ * to a Win32 "Shell.Explorer" OLE control.
+ *
+ * Instances of this class manage the setup, typical use and teardown of
+ * a simple web browser.
+ */
+class OleWebBrowser {
+ /* See the Windows Platform SDK documentation for more information about the
+ * OLE control used here and its usage.
+ */
+ // Generated from typelib filename: shdocvw.dll
+
+ // Constants for WebBrowser CommandStateChange
+ public static final int CSC_UPDATECOMMANDS = -1;
+ public static final int CSC_NAVIGATEFORWARD = 1;
+ public static final int CSC_NAVIGATEBACK = 2;
+
+ // COnstants for Web Browser ReadyState
+ public static final int READYSTATE_UNINITIALIZED = 0;
+ public static final int READYSTATE_LOADING = 1;
+ public static final int READYSTATE_LOADED = 2;
+ public static final int READYSTATE_INTERACTIVE = 3;
+ public static final int READYSTATE_COMPLETE = 4;
+
+ // Web Browser Control Events
+ public static final int BeforeNavigate = 100; // Fired when a new hyperlink is being navigated to.
+ public static final int NavigateComplete = 101; // Fired when the document being navigated to becomes visible and enters the navigation stack.
+ public static final int StatusTextChange = 102; // Statusbar text changed.
+ public static final int ProgressChange = 108; // Fired when download progress is updated.
+ public static final int DownloadComplete = 104; // Download of page complete.
+ public static final int CommandStateChange = 105; // The enabled state of a command changed
+ public static final int DownloadBegin = 106; // Download of a page started.
+ public static final int NewWindow = 107; // Fired when a new window should be created.
+ public static final int TitleChange = 113; // Document title changed.
+ public static final int FrameBeforeNavigate = 200; // Fired when a new hyperlink is being navigated to in a frame.
+ public static final int FrameNavigateComplete = 201; // Fired when a new hyperlink is being navigated to in a frame.
+ public static final int FrameNewWindow = 204; // Fired when a new window should be created.
+ public static final int Quit = 103; // Fired when application is quiting.
+ public static final int WindowMove = 109; // Fired when window has been moved.
+ public static final int WindowResize = 110; // Fired when window has been sized.
+ public static final int WindowActivate = 111; // Fired when window has been activated.
+ public static final int PropertyChange = 112; // Fired when the PutProperty method has been called.
+
+ // Web Browser properties
+ public static final int DISPID_READYSTATE = -525;
+
+ private OleAutomation oleAutomation;
+
+ /**
+ * Creates a Web browser control.
+ * <p>
+ * Typical use:<br>
+ * <code>
+ * OleControlSite oleControlSite = new OleControlSite(oleFrame, style, "Shell.Explorer");<br>
+ * OleAutomation oleAutomation = new OleAutomation(oleControlSite);<br>
+ * OleWebBrowser webBrowser = new OleWebBrowser(oleControlSite, oleAutomation);<br>
+ * </code>
+ *
+ * @param oleAutomation the OleAutomation object for this control.
+ * @param oleControlSite the OleControlSite object for this control.
+ */
+ public OleWebBrowser(OleAutomation oleAutomation) {
+ this.oleAutomation = oleAutomation;
+ }
+
+
+ /**
+ * Disposes of the Web browser control.
+ */
+ public void dispose() {
+ if (oleAutomation != null) oleAutomation.dispose();
+ oleAutomation = null;
+ }
+
+ /*
+ * Interact with the Control via OLE Automation
+ *
+ * Note: You can hard code the DISPIDs if you know them beforehand
+ * this is of course the fastest way, but you increase coupling
+ * to the control.
+ */
+
+ /**
+ * Returns the current web page title.
+ *
+ * @return the current web page title String
+ */
+ public String getLocationName() {
+ // dispid=210, type=PROPGET, name="LocationName"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"LocationName"});
+ int dispIdMember = rgdispid[0];
+ Variant pVarResult = oleAutomation.getProperty(dispIdMember);
+ if (pVarResult == null) return null;
+ return pVarResult.getString();
+ }
+
+ /**
+ * Returns the current URL.
+ *
+ * @return the current URL String
+ */
+ public String getLocationURL() {
+ // dispid=211, type=PROPGET, name="LocationURL"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"LocationURL"});
+ int dispIdMember = rgdispid[0];
+
+ Variant pVarResult = oleAutomation.getProperty(dispIdMember);
+ if (pVarResult == null) return null;
+ return pVarResult.getString();
+ }
+
+ /**
+ * Returns the current state of the control.
+ *
+ * @return the current state of the control, one of:
+ * READYSTATE_UNINITIALIZED;
+ * READYSTATE_LOADING;
+ * READYSTATE_LOADED;
+ * READYSTATE_INTERACTIVE;
+ * READYSTATE_COMPLETE.
+ */
+ public int getReadyState() {
+ // dispid=4294966771, type=PROPGET, name="ReadyState"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"ReadyState"});
+ int dispIdMember = rgdispid[0];
+
+ Variant pVarResult = oleAutomation.getProperty(dispIdMember);
+ if (pVarResult == null) return -1;
+ return pVarResult.getInt();
+ }
+
+ /**
+ * Navigates backwards through previously visited web sites.
+ *
+ * @return the platform-defined result code for the "GoBack" method invocation
+ */
+ public int GoBack() {
+
+ // dispid=100, type=METHOD, name="GoBack"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"GoBack"});
+ int dispIdMember = rgdispid[0];
+
+ Variant pVarResult = oleAutomation.invoke(dispIdMember);
+ if (pVarResult == null) return 0;
+ return pVarResult.getInt();
+ }
+
+ /**
+ * Navigates backwards through previously visited web sites.
+ *
+ * @return the platform-defined result code for the "GoForward" method invocation
+ */
+ public int GoForward() {
+
+ // dispid=101, type=METHOD, name="GoForward"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"GoForward"});
+ int dispIdMember = rgdispid[0];
+
+ Variant pVarResult = oleAutomation.invoke(dispIdMember);
+ if (pVarResult == null) return 0;
+ return pVarResult.getInt();
+ }
+
+ /**
+ * Navigates to home page.
+ *
+ * @return the platform-defined result code for the "GoHome" method invocation
+ */
+ public int GoHome() {
+ // dispid=102, type=METHOD, name="GoHome"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"GoHome"});
+ int dispIdMember = rgdispid[0];
+
+ Variant pVarResult = oleAutomation.invoke(dispIdMember);
+ if (pVarResult == null) return 0;
+ return pVarResult.getInt();
+ }
+
+ /**
+ * Navigates to user-specified Web search gateway.
+ *
+ * @return the platform-defined result code for the "GoSearch" method invocation
+ */
+ public int GoSearch() {
+ // dispid=103, type=METHOD, name="GoSearch"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"GoSearch"});
+ int dispIdMember = rgdispid[0];
+
+ Variant pVarResult = oleAutomation.invoke(dispIdMember);
+ if (pVarResult == null) return 0;
+ return pVarResult.getInt();
+ }
+
+ /**
+ * Navigates to a particular URL.
+ *
+ * @return the platform-defined result code for the "Navigate" method invocation
+ */
+ public int Navigate(String url) {
+ // dispid=104, type=METHOD, name="Navigate"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"Navigate", "URL"});
+ int dispIdMember = rgdispid[0];
+
+ Variant[] rgvarg = new Variant[1];
+ rgvarg[0] = new Variant(url);
+ int[] rgdispidNamedArgs = new int[1];
+ rgdispidNamedArgs[0] = rgdispid[1]; // identifier of argument
+ Variant pVarResult = oleAutomation.invoke(dispIdMember, rgvarg, rgdispidNamedArgs);
+
+ if (pVarResult == null) return 0;
+ return pVarResult.getInt();
+ }
+
+ /**
+ * Refreshes the currently viewed page.
+ *
+ * @return the platform-defined result code for the "Refresh" method invocation
+ */
+ public void Refresh(){
+ // dispid= 4294966746, type=METHOD, name="Refresh"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"Refresh"});
+ int dispIdMember = rgdispid[0];
+
+ oleAutomation.invokeNoReply(dispIdMember);
+ }
+
+ /**
+ * Aborts loading of the currnet page.
+ *
+ * @return the platform-defined result code for the "Stop" method invocation
+ */
+ public void Stop() {
+ // dispid=106, type=METHOD, name="Stop"
+ int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"Stop"});
+ int dispIdMember = rgdispid[0];
+
+ Variant pVarResult = oleAutomation.invoke(dispIdMember);
+ }
+}