1 /******************************************************************************* 2 * Copyright (c) 2003, 2007 IBM Corporation and others. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * IBM Corporation - initial API and implementation 10 * Port to the D programming language: 11 * John Reimer <terminal.node@gmail.com> 12 *******************************************************************************/ 13 module org.eclipse.swt.browser.WindowEvent; 14 15 16 import java.lang.all; 17 18 import org.eclipse.swt.events.TypedEvent; 19 import org.eclipse.swt.graphics.Point; 20 import org.eclipse.swt.widgets.Widget; 21 import org.eclipse.swt.browser.Browser; 22 23 /** 24 * A <code>WindowEvent</code> is sent by a {@link Browser} when 25 * a new window needs to be created or when an existing window needs to be 26 * closed. This notification occurs when a javascript command such as 27 * <code>window.open</code> or <code>window.close</code> gets executed by 28 * a <code>Browser</code>. 29 * 30 * <p> 31 * The following example shows how <code>WindowEvent</code>'s are typically 32 * handled. 33 * 34 * <code><pre> 35 * public static void main(String[] args) { 36 * Display display = new Display(); 37 * Shell shell = new Shell(display); 38 * shell.setText("Main Window"); 39 * shell.setLayout(new FillLayout()); 40 * Browser browser = new Browser(shell, SWT.NONE); 41 * initialize(display, browser); 42 * shell.open(); 43 * browser.setUrl("http://www.eclipse.org"); 44 * while (!shell.isDisposed()) { 45 * if (!display.readAndDispatch()) 46 * display.sleep(); 47 * } 48 * display.dispose(); 49 * } 50 * 51 * static void initialize(final Display display, Browser browser) { 52 * browser.addOpenWindowListener(new OpenWindowListener() { 53 * public void open(WindowEvent event) { 54 * // Certain platforms can provide a default full browser. 55 * // simply return in that case if the application prefers 56 * // the default full browser to the embedded one set below. 57 * if (!event.required) return; 58 * 59 * // Embed the new window 60 * Shell shell = new Shell(display); 61 * shell.setText("New Window"); 62 * shell.setLayout(new FillLayout()); 63 * Browser browser = new Browser(shell, SWT.NONE); 64 * initialize(display, browser); 65 * event.browser = browser; 66 * } 67 * }); 68 * browser.addVisibilityWindowListener(new VisibilityWindowListener() { 69 * public void hide(WindowEvent event) { 70 * Browser browser = (Browser)event.widget; 71 * Shell shell = browser.getShell(); 72 * shell.setVisible(false); 73 * } 74 * public void show(WindowEvent event) { 75 * Browser browser = (Browser)event.widget; 76 * Shell shell = browser.getShell(); 77 * if (event.location !is null) shell.setLocation(event.location); 78 * if (event.size !is null) { 79 * Point size = event.size; 80 * shell.setSize(shell.computeSize(size.x, size.y)); 81 * } 82 * if (event.addressBar || event.menuBar || event.statusBar || event.toolBar) { 83 * // Create widgets for the address bar, menu bar, status bar and/or tool bar 84 * // leave enough space in the Shell to accommodate a Browser of the size 85 * // given by event.size 86 * } 87 * shell.open(); 88 * } 89 * }); 90 * browser.addCloseWindowListener(new CloseWindowListener() { 91 * public void close(WindowEvent event) { 92 * Browser browser = (Browser)event.widget; 93 * Shell shell = browser.getShell(); 94 * shell.close(); 95 * } 96 * }); 97 * } 98 * </pre></code> 99 * 100 * The following notifications are emitted when the user selects a hyperlink that targets a new window 101 * or as the result of a javascript that executes window.open. 102 * 103 * <p>Main Browser 104 * <ul> 105 * <li>User selects a link that opens in a new window or javascript requests a new window</li> 106 * <li>OpenWindowListener.open() notified</li> 107 * <ul> 108 * <li>Application creates a new Shell and a second Browser inside that Shell</li> 109 * <li>Application registers WindowListener's on that second Browser, such as VisibilityWindowListener</li> 110 * <li>Application returns the second Browser as the host for the new window content</li> 111 * </ul> 112 * </ul> 113 * 114 * <p>Second Browser 115 * <ul> 116 * <li>VisibilityWindowListener.show() notified</li> 117 * <ul> 118 * <li>Application sets navigation tool bar, status bar, menu bar and Shell size 119 * <li>Application makes the Shell hosting the second Browser visible 120 * <li>User now sees the new window 121 * </ul> 122 * </ul> 123 * 124 * @see CloseWindowListener 125 * @see OpenWindowListener 126 * @see VisibilityWindowListener 127 * 128 * @since 3.0 129 */ 130 public class WindowEvent : TypedEvent { 131 132 /** 133 * Specifies whether the platform requires the user to provide a 134 * <code>Browser</code> to handle the new window. 135 * 136 * @since 3.1 137 */ 138 public bool required; 139 140 141 /** 142 * <code>Browser</code> provided by the application. 143 */ 144 public Browser browser; 145 146 /** 147 * Requested location for the <code>Shell</code> hosting the <code>Browser</code>. 148 * It is <code>null</code> if no location has been requested. 149 */ 150 public Point location; 151 152 /** 153 * Requested <code>Browser</code> size. The client area of the <code>Shell</code> 154 * hosting the <code>Browser</code> should be large enough to accommodate that size. 155 * It is <code>null</code> if no size has been requested. 156 */ 157 public Point size; 158 159 /** 160 * Specifies whether the <code>Shell</code> hosting the <code>Browser</code> should 161 * display an address bar. 162 * 163 * @since 3.1 164 */ 165 public bool addressBar; 166 167 /** 168 * Specifies whether the <code>Shell</code> hosting the <code>Browser</code> should 169 * display a menu bar. 170 * 171 * @since 3.1 172 */ 173 public bool menuBar; 174 175 /** 176 * Specifies whether the <code>Shell</code> hosting the <code>Browser</code> should 177 * display a status bar. 178 * 179 * @since 3.1 180 */ 181 public bool statusBar; 182 183 /** 184 * Specifies whether the <code>Shell</code> hosting the <code>Browser</code> should 185 * display a tool bar. 186 * 187 * @since 3.1 188 */ 189 public bool toolBar; 190 191 static const long serialVersionUID = 3617851997387174969L; 192 193 this(Widget w) { 194 super(w); 195 } 196 197 /** 198 * Returns a string containing a concise, human-readable 199 * description of the receiver. 200 * 201 * @return a string representation of the event 202 */ 203 204 public String toString() { 205 return Format( "{} required={} browser={} location={} size={} addressbar={} menubar={} statusbar={} toolbar={}}", 206 super.toString[0 .. $-1], 207 required, browser, 208 location, size, addressBar, 209 menuBar, statusBar, toolBar ); 210 } 211 }