comparison dwt/browser/WindowEvent.d @ 0:380af2bdd8e5

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