diff options
Diffstat (limited to 'examples/org.eclipse.swt.examples.ole.win32/src/org')
3 files changed, 748 insertions, 748 deletions
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 index 4efbe377f0..2e886bcdac 100755 --- 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 @@ -1,361 +1,361 @@ -package org.eclipse.swt.examples.ole.win32;
-
-/*
+package org.eclipse.swt.examples.ole.win32; + +/* * (c) Copyright IBM Corp. 2000, 2002. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
-
- private static final int DISPID_AMBIENT_DLCONTROL = -5512;
- private static final int DLCTL_NO_SCRIPTS = 0x80;
-
- /**
- * 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());
- }
- });
- }
-
- /**
- * 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");
- Variant download = new Variant(DLCTL_NO_SCRIPTS);
- webControlSite.setSiteProperty(DISPID_AMBIENT_DLCONTROL, download);
- 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();
- }
-}
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +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; + + private static final int DISPID_AMBIENT_DLCONTROL = -5512; + private static final int DLCTL_NO_SCRIPTS = 0x80; + + /** + * 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()); + } + }); + } + + /** + * 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"); + Variant download = new Variant(DLCTL_NO_SCRIPTS); + webControlSite.setSiteProperty(DISPID_AMBIENT_DLCONTROL, download); + 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 index 478c97be2f..edf531d99c 100755 --- 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 @@ -1,172 +1,172 @@ -package org.eclipse.swt.examples.ole.win32;
-
-/*
+package org.eclipse.swt.examples.ole.win32; + +/* * (c) Copyright IBM Corp. 2000, 2002. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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) {
- }
- }
- }
-}
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +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 index b82c9d5cae..012d108c5a 100755 --- 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 @@ -1,224 +1,224 @@ -package org.eclipse.swt.examples.ole.win32;
-
-/*
+package org.eclipse.swt.examples.ole.win32; + +/* * (c) Copyright IBM Corp. 2000, 2002. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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 || pVarResult.getType() != OLE.VT_BSTR) 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 || pVarResult.getType() != OLE.VT_BSTR) 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 || pVarResult.getType() != OLE.VT_I4) return -1;
- return pVarResult.getInt();
- }
-
- /**
- * Navigates backwards through previously visited web sites.
- */
- public void GoBack() {
-
- // dispid=100, type=METHOD, name="GoBack"
- int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"GoBack"});
- int dispIdMember = rgdispid[0];
- oleAutomation.invoke(dispIdMember);
- }
-
- /**
- * Navigates backwards through previously visited web sites.
- */
- public void GoForward() {
-
- // dispid=101, type=METHOD, name="GoForward"
- int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"GoForward"});
- int dispIdMember = rgdispid[0];
- oleAutomation.invoke(dispIdMember);
- }
-
- /**
- * Navigates to home page.
- */
- public void GoHome() {
- // dispid=102, type=METHOD, name="GoHome"
- int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"GoHome"});
- int dispIdMember = rgdispid[0];
- oleAutomation.invoke(dispIdMember);
- }
-
- /**
- * Navigates to user-specified Web search gateway.
- */
- public void GoSearch() {
- // dispid=103, type=METHOD, name="GoSearch"
- int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"GoSearch"});
- int dispIdMember = rgdispid[0];
- oleAutomation.invoke(dispIdMember);
- }
-
- /**
- * Navigates to a particular URL.
- */
- public void 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
- oleAutomation.invoke(dispIdMember, rgvarg, rgdispidNamedArgs);
- }
-
- /**
- * 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];
- oleAutomation.invoke(dispIdMember);
- }
-}
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +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 || pVarResult.getType() != OLE.VT_BSTR) 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 || pVarResult.getType() != OLE.VT_BSTR) 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 || pVarResult.getType() != OLE.VT_I4) return -1; + return pVarResult.getInt(); + } + + /** + * Navigates backwards through previously visited web sites. + */ + public void GoBack() { + + // dispid=100, type=METHOD, name="GoBack" + int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"GoBack"}); + int dispIdMember = rgdispid[0]; + oleAutomation.invoke(dispIdMember); + } + + /** + * Navigates backwards through previously visited web sites. + */ + public void GoForward() { + + // dispid=101, type=METHOD, name="GoForward" + int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"GoForward"}); + int dispIdMember = rgdispid[0]; + oleAutomation.invoke(dispIdMember); + } + + /** + * Navigates to home page. + */ + public void GoHome() { + // dispid=102, type=METHOD, name="GoHome" + int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"GoHome"}); + int dispIdMember = rgdispid[0]; + oleAutomation.invoke(dispIdMember); + } + + /** + * Navigates to user-specified Web search gateway. + */ + public void GoSearch() { + // dispid=103, type=METHOD, name="GoSearch" + int[] rgdispid = oleAutomation.getIDsOfNames(new String[]{"GoSearch"}); + int dispIdMember = rgdispid[0]; + oleAutomation.invoke(dispIdMember); + } + + /** + * Navigates to a particular URL. + */ + public void 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 + oleAutomation.invoke(dispIdMember, rgvarg, rgdispidNamedArgs); + } + + /** + * 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]; + oleAutomation.invoke(dispIdMember); + } +} |