author | dcherepanov |
Thu, 12 Feb 2009 18:24:35 +0300 | |
changeset 2453 | 35e5fab82613 |
parent 1974 | 1e1487c04864 |
child 2643 | ea218b1a2000 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
129
diff
changeset
|
2 |
* Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.awt.X11; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
||
30 |
import java.util.LinkedList; |
|
31 |
import java.util.Iterator; |
|
32 |
||
33 |
import java.util.logging.Level; |
|
34 |
import java.util.logging.Logger; |
|
35 |
||
36 |
import sun.awt.EmbeddedFrame; |
|
37 |
import sun.awt.SunToolkit; |
|
38 |
||
39 |
public class XEmbeddedFramePeer extends XFramePeer { |
|
40 |
||
41 |
private static final Logger xembedLog = Logger.getLogger("sun.awt.X11.xembed.XEmbeddedFramePeer"); |
|
42 |
||
43 |
LinkedList<AWTKeyStroke> strokes; |
|
44 |
||
45 |
XEmbedClientHelper embedder; // Caution - can be null if XEmbed is not supported |
|
46 |
public XEmbeddedFramePeer(EmbeddedFrame target) { |
|
47 |
// Don't specify PARENT_WINDOW param here. Instead we reparent |
|
48 |
// this embedded frame peer to the proper parent window after |
|
49 |
// an XEventDispatcher is registered to handle XEmbed events |
|
50 |
super(new XCreateWindowParams(new Object[] { |
|
51 |
TARGET, target, |
|
52 |
VISIBLE, Boolean.TRUE, |
|
53 |
EMBEDDED, Boolean.TRUE})); |
|
54 |
} |
|
55 |
||
56 |
public void preInit(XCreateWindowParams params) { |
|
57 |
super.preInit(params); |
|
58 |
strokes = new LinkedList<AWTKeyStroke>(); |
|
59 |
if (supportsXEmbed()) { |
|
60 |
embedder = new XEmbedClientHelper(); |
|
61 |
} |
|
62 |
} |
|
63 |
void postInit(XCreateWindowParams params) { |
|
64 |
super.postInit(params); |
|
65 |
if (embedder != null) { |
|
1974
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
66 |
// install X11 event dispatcher |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
67 |
embedder.setClient(this); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
68 |
// reparent to XEmbed server |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
69 |
embedder.install(); |
2 | 70 |
} else if (getParentWindowHandle() != 0) { |
71 |
XToolkit.awtLock(); |
|
72 |
try { |
|
73 |
XlibWrapper.XReparentWindow(XToolkit.getDisplay(), |
|
74 |
getWindow(), |
|
75 |
getParentWindowHandle(), |
|
76 |
0, 0); |
|
77 |
} finally { |
|
78 |
XToolkit.awtUnlock(); |
|
79 |
} |
|
80 |
} |
|
81 |
} |
|
82 |
||
1974
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
83 |
@Override |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
84 |
public void dispose() { |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
85 |
if (embedder != null) { |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
86 |
// uninstall X11 event dispatcher |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
87 |
embedder.setClient(null); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
88 |
} |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
89 |
super.dispose(); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
90 |
} |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
91 |
|
2 | 92 |
public void updateMinimumSize() { |
93 |
} |
|
94 |
||
95 |
protected String getWMName() { |
|
96 |
return "JavaEmbeddedFrame"; |
|
97 |
} |
|
98 |
||
99 |
final long getParentWindowHandle() { |
|
100 |
return ((XEmbeddedFrame)target).handle; |
|
101 |
} |
|
102 |
||
103 |
boolean supportsXEmbed() { |
|
104 |
return ((EmbeddedFrame)target).supportsXEmbed(); |
|
105 |
} |
|
106 |
||
107 |
public boolean requestWindowFocus(long time, boolean timeProvided) { |
|
108 |
// Should check for active state of host application |
|
109 |
if (embedder != null && embedder.isActive()) { |
|
110 |
xembedLog.fine("Requesting focus from embedding host"); |
|
111 |
return embedder.requestFocus(); |
|
112 |
} else { |
|
113 |
xembedLog.fine("Requesting focus from X"); |
|
114 |
return super.requestWindowFocus(time, timeProvided); |
|
115 |
} |
|
116 |
} |
|
117 |
||
118 |
protected void requestInitialFocus() { |
|
119 |
if (embedder != null && supportsXEmbed()) { |
|
120 |
embedder.requestFocus(); |
|
121 |
} else { |
|
122 |
super.requestInitialFocus(); |
|
123 |
} |
|
124 |
} |
|
125 |
||
126 |
protected boolean isEventDisabled(XEvent e) { |
|
127 |
if (embedder != null && embedder.isActive()) { |
|
128 |
switch (e.get_type()) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
129
diff
changeset
|
129 |
case XConstants.FocusIn: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
129
diff
changeset
|
130 |
case XConstants.FocusOut: |
2 | 131 |
return true; |
132 |
} |
|
133 |
} |
|
134 |
return super.isEventDisabled(e); |
|
135 |
} |
|
136 |
||
137 |
public void handleConfigureNotifyEvent(XEvent xev) |
|
138 |
{ |
|
139 |
assert (SunToolkit.isAWTLockHeldByCurrentThread()); |
|
140 |
XConfigureEvent xe = xev.get_xconfigure(); |
|
141 |
if (xembedLog.isLoggable(Level.FINE)) { |
|
142 |
xembedLog.fine(xe.toString()); |
|
143 |
} |
|
144 |
||
145 |
// fix for 5063031 |
|
146 |
// if we use super.handleConfigureNotifyEvent() we would get wrong |
|
147 |
// size and position because embedded frame really is NOT a decorated one |
|
148 |
checkIfOnNewScreen(toGlobal(new Rectangle(xe.get_x(), |
|
149 |
xe.get_y(), |
|
150 |
xe.get_width(), |
|
151 |
xe.get_height()))); |
|
152 |
||
153 |
Rectangle oldBounds = getBounds(); |
|
154 |
||
155 |
synchronized (getStateLock()) { |
|
156 |
x = xe.get_x(); |
|
157 |
y = xe.get_y(); |
|
158 |
width = xe.get_width(); |
|
159 |
height = xe.get_height(); |
|
160 |
||
161 |
dimensions.setClientSize(width, height); |
|
162 |
dimensions.setLocation(x, y); |
|
163 |
} |
|
164 |
||
165 |
if (!getLocation().equals(oldBounds.getLocation())) { |
|
166 |
handleMoved(dimensions); |
|
167 |
} |
|
168 |
reconfigureContentWindow(dimensions); |
|
169 |
} |
|
170 |
||
171 |
protected void traverseOutForward() { |
|
172 |
if (embedder != null && embedder.isActive()) { |
|
173 |
if (embedder.isApplicationActive()) { |
|
174 |
xembedLog.fine("Traversing out Forward"); |
|
175 |
embedder.traverseOutForward(); |
|
176 |
} |
|
177 |
} |
|
178 |
} |
|
179 |
||
180 |
protected void traverseOutBackward() { |
|
181 |
if (embedder != null && embedder.isActive()) { |
|
182 |
if (embedder.isApplicationActive()) { |
|
183 |
xembedLog.fine("Traversing out Backward"); |
|
184 |
embedder.traverseOutBackward(); |
|
185 |
} |
|
186 |
} |
|
187 |
} |
|
188 |
||
189 |
// don't use getLocationOnScreen() inherited from XDecoratedPeer |
|
190 |
public Point getLocationOnScreen() { |
|
191 |
XToolkit.awtLock(); |
|
192 |
try { |
|
193 |
return toGlobal(0, 0); |
|
194 |
} finally { |
|
195 |
XToolkit.awtUnlock(); |
|
196 |
} |
|
197 |
} |
|
198 |
||
129
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
2
diff
changeset
|
199 |
@Override |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
2
diff
changeset
|
200 |
Rectangle constrainBounds(int x, int y, int width, int height) { |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
2
diff
changeset
|
201 |
// We don't constrain the bounds of the EmbeddedFrames |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
2
diff
changeset
|
202 |
return new Rectangle(x, y, width, height); |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
2
diff
changeset
|
203 |
} |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
2
diff
changeset
|
204 |
|
2 | 205 |
// don't use getBounds() inherited from XDecoratedPeer |
206 |
public Rectangle getBounds() { |
|
207 |
return new Rectangle(x, y, width, height); |
|
208 |
} |
|
209 |
||
210 |
public void setBoundsPrivate(int x, int y, int width, int height) { |
|
211 |
setBounds(x, y, width, height, SET_BOUNDS | NO_EMBEDDED_CHECK); |
|
212 |
} |
|
213 |
||
214 |
public Rectangle getBoundsPrivate() { |
|
215 |
int x = 0, y = 0; |
|
216 |
int w = 0, h = 0; |
|
217 |
XWindowAttributes attr = new XWindowAttributes(); |
|
218 |
||
219 |
XToolkit.awtLock(); |
|
220 |
try { |
|
221 |
XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), |
|
222 |
getWindow(), attr.pData); |
|
223 |
x = attr.get_x(); |
|
224 |
y = attr.get_y(); |
|
225 |
w = attr.get_width(); |
|
226 |
h = attr.get_height(); |
|
227 |
} finally { |
|
228 |
XToolkit.awtUnlock(); |
|
229 |
} |
|
230 |
attr.dispose(); |
|
231 |
||
232 |
return new Rectangle(x, y, w, h); |
|
233 |
} |
|
234 |
void registerAccelerator(AWTKeyStroke stroke) { |
|
235 |
if (stroke == null) return; |
|
236 |
strokes.add(stroke); |
|
237 |
if (embedder != null && embedder.isActive()) { |
|
238 |
embedder.registerAccelerator(stroke, strokes.size()-1); |
|
239 |
} |
|
240 |
} |
|
241 |
||
242 |
void unregisterAccelerator(AWTKeyStroke stroke) { |
|
243 |
if (stroke == null) return; |
|
244 |
if (embedder != null && embedder.isActive()) { |
|
245 |
int index = strokes.indexOf(stroke); |
|
246 |
embedder.unregisterAccelerator(index); |
|
247 |
} |
|
248 |
} |
|
249 |
||
250 |
void notifyStarted() { |
|
251 |
// Register accelerators |
|
252 |
if (embedder != null && embedder.isActive()) { |
|
253 |
int i = 0; |
|
254 |
Iterator<AWTKeyStroke> iter = strokes.iterator(); |
|
255 |
while (iter.hasNext()) { |
|
256 |
embedder.registerAccelerator(iter.next(), i++); |
|
257 |
} |
|
258 |
} |
|
259 |
// Now we know that the the embedder is an XEmbed server, so we |
|
260 |
// reregister the drop target to enable XDnD protocol support via |
|
261 |
// XEmbed. |
|
262 |
updateDropTarget(); |
|
263 |
} |
|
1974
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
264 |
void notifyStopped() { |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
265 |
if (embedder != null && embedder.isActive()) { |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
266 |
for (int i = strokes.size() - 1; i >= 0; i--) { |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
267 |
embedder.unregisterAccelerator(i); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
268 |
} |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
269 |
} |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
270 |
} |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
271 |
|
2 | 272 |
long getFocusTargetWindow() { |
273 |
return getWindow(); |
|
274 |
} |
|
275 |
||
276 |
boolean isXEmbedActive() { |
|
277 |
return embedder != null && embedder.isActive(); |
|
278 |
} |
|
279 |
||
280 |
public int getAbsoluteX() |
|
281 |
{ |
|
282 |
Point absoluteLoc = XlibUtil.translateCoordinates(getWindow(), |
|
283 |
XToolkit.getDefaultRootWindow(), |
|
284 |
new Point(0, 0)); |
|
285 |
return absoluteLoc.x; |
|
286 |
} |
|
287 |
||
288 |
public int getAbsoluteY() |
|
289 |
{ |
|
290 |
Point absoluteLoc = XlibUtil.translateCoordinates(getWindow(), |
|
291 |
XToolkit.getDefaultRootWindow(), |
|
292 |
new Point(0, 0)); |
|
293 |
return absoluteLoc.y; |
|
294 |
} |
|
295 |
||
296 |
public int getWidth() { |
|
297 |
return width; |
|
298 |
} |
|
299 |
public int getHeight() { |
|
300 |
return height; |
|
301 |
} |
|
302 |
||
303 |
public Dimension getSize() { |
|
304 |
return new Dimension(width, height); |
|
305 |
} |
|
306 |
||
307 |
// override XWindowPeer's method to let the embedded frame to block |
|
308 |
// the containing window |
|
309 |
public void setModalBlocked(Dialog blocker, boolean blocked) { |
|
310 |
super.setModalBlocked(blocker, blocked); |
|
311 |
||
312 |
EmbeddedFrame frame = (EmbeddedFrame)target; |
|
313 |
frame.notifyModalBlocked(blocker, blocked); |
|
314 |
} |
|
315 |
} |