Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Browser (IE) not generating WindowClosing event?
Browser (IE) not generating WindowClosing event? [message #451299] Thu, 24 February 2005 22:34 Go to next message
Michael Champion is currently offline Michael ChampionFriend
Messages: 2
Registered: July 2009
Junior Member
I'm using the Eclipse3.1M5 Browser widget on Windows XP with IE6.0 and it
never seems to call my CloseWindowListener that I've registered with the
Browser.

I've modified Snippet173 which also uses a CloseWindowListener to put in a
println. It never appears to be called. The shellClosed listener on the
parent Shell is called, but there doesn't seem to be a way to generate an
event for the Browser closing.

Any thoughts? Is this a known issue with IE? Am I doing something wrong
here?

Any help would be appreciated.

Thanks,

-mike
Re: Browser (IE) not generating WindowClosing event? [message #451320 is a reply to message #451299] Fri, 25 February 2005 15:03 Go to previous message
Christophe Cornu is currently offline Christophe CornuFriend
Messages: 304
Registered: July 2009
Senior Member
Hi Mike,

If you want to know when the Browser is disposed, you can register the
SWT.Dispose event.

The CloseWindowListener.close event is emitted when the native engine itself
(Internet Explorer in your case) is requesting your application to close a
window embedding a Browser instance. This occurs when the native engine is
executing a javascript command in the HTML document such as
'window.close()'. When the CloseWindowListener.close event returns, the
Browser is then disposed automatically - and the SWT.Dispose event is then
fired. The application typically uses this notification to close the SWT
Shell that hosts the SWT Browser (to close a popup window for example).

This notification is not emitted when the Shell window is closed by the user
by clicking on the 'cross' button. In that case, if the Shell causes all its
children to be disposed including the Browser, you will receive a
SWT.Dispose event for the Browser.

Chris

Here's a snippet derivated from the javadoc for WindowEvent. When clicking
on the button, 'window.close' is executed and the expected
CloseWindowListener.close is dispatched to the corresponding Browser.

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.browser.*;

public class PRBrowser {

static Browser newBrowser = null;
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Main Window");
shell.setLayout(new FillLayout());
Button button = new Button(shell, SWT.CLOSE);
final Browser browser = new Browser(shell, SWT.NONE);
button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
if (newBrowser != null) newBrowser.execute("window.close();");
}

});
initialize(display, browser);
shell.open();
browser.setText("<html><title>Hello Title</title><script
type='text/javascript'>window.open('http://www.eclipse.org', 'title',
'width=300,height=300');</script><body>Hello</body></html >");
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

static void initialize(final Display display, Browser browser) {
browser.addOpenWindowListener(new OpenWindowListener() {
public void open(WindowEvent event) {
System.out.println("New Window");
// Certain platforms can provide a default full browser.
// simply return in that case if the application prefers
// the default full browser to the embedded one set below.
//if (!event.required) return;

// Embed the new window
Shell shell = new Shell(display);
shell.setText("New Window");
shell.setLayout(new FillLayout());
Browser browser = new Browser(shell, SWT.NONE);
initialize(display, browser);
event.browser = browser;
newBrowser = browser;
}
});
browser.addVisibilityWindowListener(new VisibilityWindowListener() {
public void hide(WindowEvent event) {
Browser browser = (Browser)event.widget;
Shell shell = browser.getShell();
shell.setVisible(false);
}
public void show(WindowEvent event) {
Browser browser = (Browser)event.widget;
Shell shell = browser.getShell();
if (event.location != null) shell.setLocation(event.location);
if (event.size != null) {
Point size = event.size;
shell.setSize(shell.computeSize(size.x, size.y));
}
if (event.addressBar || event.menuBar || event.statusBar ||
event.toolBar) {
// Create widgets for the address bar, menu bar, status bar and/or tool
bar
// leave enough space in the Shell to accomodate a Browser of the size
// given by event.size
}
shell.open();
}
});
browser.addListener(SWT.Dispose, new Listener() {
public void handleEvent(Event event) {
System.out.println("Disposed!");
}

});

browser.addCloseWindowListener(new CloseWindowListener() {
public void close(WindowEvent event) {
System.out.println("Close event");
Browser browser = (Browser)event.widget;
Shell shell = browser.getShell();
shell.close();
}
});
}
}
Previous Topic:How to load an image from a JAR
Next Topic:Eclipse 3.1 M5 - Browser.execute() - how to access JavaScript variables ?
Goto Forum:
  


Current Time: Fri Sep 25 11:35:07 GMT 2020

Powered by FUDForum. Page generated in 0.01834 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top