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