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