author | mchung |
Tue, 29 Sep 2009 16:03:03 -0700 | |
changeset 3938 | ef327bd847c0 |
parent 2643 | ea218b1a2000 |
child 5506 | 202f599c92aa |
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 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2643
diff
changeset
|
33 |
import sun.util.logging.PlatformLogger; |
2 | 34 |
|
35 |
import sun.awt.EmbeddedFrame; |
|
36 |
import sun.awt.SunToolkit; |
|
37 |
||
38 |
public class XEmbeddedFramePeer extends XFramePeer { |
|
39 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2643
diff
changeset
|
40 |
private static final PlatformLogger xembedLog = PlatformLogger.getLogger("sun.awt.X11.xembed.XEmbeddedFramePeer"); |
2 | 41 |
|
42 |
LinkedList<AWTKeyStroke> strokes; |
|
43 |
||
44 |
XEmbedClientHelper embedder; // Caution - can be null if XEmbed is not supported |
|
45 |
public XEmbeddedFramePeer(EmbeddedFrame target) { |
|
46 |
// Don't specify PARENT_WINDOW param here. Instead we reparent |
|
47 |
// this embedded frame peer to the proper parent window after |
|
48 |
// an XEventDispatcher is registered to handle XEmbed events |
|
49 |
super(new XCreateWindowParams(new Object[] { |
|
50 |
TARGET, target, |
|
51 |
VISIBLE, Boolean.TRUE, |
|
52 |
EMBEDDED, Boolean.TRUE})); |
|
53 |
} |
|
54 |
||
55 |
public void preInit(XCreateWindowParams params) { |
|
56 |
super.preInit(params); |
|
57 |
strokes = new LinkedList<AWTKeyStroke>(); |
|
58 |
if (supportsXEmbed()) { |
|
59 |
embedder = new XEmbedClientHelper(); |
|
60 |
} |
|
61 |
} |
|
62 |
void postInit(XCreateWindowParams params) { |
|
63 |
super.postInit(params); |
|
64 |
if (embedder != null) { |
|
1974
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
65 |
// install X11 event dispatcher |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
66 |
embedder.setClient(this); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
67 |
// reparent to XEmbed server |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
68 |
embedder.install(); |
2 | 69 |
} else if (getParentWindowHandle() != 0) { |
70 |
XToolkit.awtLock(); |
|
71 |
try { |
|
72 |
XlibWrapper.XReparentWindow(XToolkit.getDisplay(), |
|
73 |
getWindow(), |
|
74 |
getParentWindowHandle(), |
|
75 |
0, 0); |
|
76 |
} finally { |
|
77 |
XToolkit.awtUnlock(); |
|
78 |
} |
|
79 |
} |
|
80 |
} |
|
81 |
||
1974
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
82 |
@Override |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
83 |
public void dispose() { |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
84 |
if (embedder != null) { |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
85 |
// uninstall X11 event dispatcher |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
86 |
embedder.setClient(null); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
87 |
} |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
88 |
super.dispose(); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
89 |
} |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
90 |
|
2 | 91 |
public void updateMinimumSize() { |
92 |
} |
|
93 |
||
94 |
protected String getWMName() { |
|
95 |
return "JavaEmbeddedFrame"; |
|
96 |
} |
|
97 |
||
98 |
final long getParentWindowHandle() { |
|
99 |
return ((XEmbeddedFrame)target).handle; |
|
100 |
} |
|
101 |
||
102 |
boolean supportsXEmbed() { |
|
103 |
return ((EmbeddedFrame)target).supportsXEmbed(); |
|
104 |
} |
|
105 |
||
106 |
public boolean requestWindowFocus(long time, boolean timeProvided) { |
|
107 |
// Should check for active state of host application |
|
108 |
if (embedder != null && embedder.isActive()) { |
|
109 |
xembedLog.fine("Requesting focus from embedding host"); |
|
110 |
return embedder.requestFocus(); |
|
111 |
} else { |
|
112 |
xembedLog.fine("Requesting focus from X"); |
|
113 |
return super.requestWindowFocus(time, timeProvided); |
|
114 |
} |
|
115 |
} |
|
116 |
||
117 |
protected void requestInitialFocus() { |
|
118 |
if (embedder != null && supportsXEmbed()) { |
|
119 |
embedder.requestFocus(); |
|
120 |
} else { |
|
121 |
super.requestInitialFocus(); |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
protected boolean isEventDisabled(XEvent e) { |
|
126 |
if (embedder != null && embedder.isActive()) { |
|
127 |
switch (e.get_type()) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
129
diff
changeset
|
128 |
case XConstants.FocusIn: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
129
diff
changeset
|
129 |
case XConstants.FocusOut: |
2 | 130 |
return true; |
131 |
} |
|
132 |
} |
|
133 |
return super.isEventDisabled(e); |
|
134 |
} |
|
135 |
||
136 |
public void handleConfigureNotifyEvent(XEvent xev) |
|
137 |
{ |
|
138 |
assert (SunToolkit.isAWTLockHeldByCurrentThread()); |
|
139 |
XConfigureEvent xe = xev.get_xconfigure(); |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2643
diff
changeset
|
140 |
if (xembedLog.isLoggable(PlatformLogger.FINE)) { |
2 | 141 |
xembedLog.fine(xe.toString()); |
142 |
} |
|
143 |
||
144 |
// fix for 5063031 |
|
145 |
// if we use super.handleConfigureNotifyEvent() we would get wrong |
|
146 |
// size and position because embedded frame really is NOT a decorated one |
|
147 |
checkIfOnNewScreen(toGlobal(new Rectangle(xe.get_x(), |
|
148 |
xe.get_y(), |
|
149 |
xe.get_width(), |
|
150 |
xe.get_height()))); |
|
151 |
||
152 |
Rectangle oldBounds = getBounds(); |
|
153 |
||
154 |
synchronized (getStateLock()) { |
|
155 |
x = xe.get_x(); |
|
156 |
y = xe.get_y(); |
|
157 |
width = xe.get_width(); |
|
158 |
height = xe.get_height(); |
|
159 |
||
160 |
dimensions.setClientSize(width, height); |
|
161 |
dimensions.setLocation(x, y); |
|
162 |
} |
|
163 |
||
164 |
if (!getLocation().equals(oldBounds.getLocation())) { |
|
165 |
handleMoved(dimensions); |
|
166 |
} |
|
167 |
reconfigureContentWindow(dimensions); |
|
168 |
} |
|
169 |
||
170 |
protected void traverseOutForward() { |
|
171 |
if (embedder != null && embedder.isActive()) { |
|
172 |
if (embedder.isApplicationActive()) { |
|
173 |
xembedLog.fine("Traversing out Forward"); |
|
174 |
embedder.traverseOutForward(); |
|
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
||
179 |
protected void traverseOutBackward() { |
|
180 |
if (embedder != null && embedder.isActive()) { |
|
181 |
if (embedder.isApplicationActive()) { |
|
182 |
xembedLog.fine("Traversing out Backward"); |
|
183 |
embedder.traverseOutBackward(); |
|
184 |
} |
|
185 |
} |
|
186 |
} |
|
187 |
||
188 |
// don't use getLocationOnScreen() inherited from XDecoratedPeer |
|
189 |
public Point getLocationOnScreen() { |
|
190 |
XToolkit.awtLock(); |
|
191 |
try { |
|
192 |
return toGlobal(0, 0); |
|
193 |
} finally { |
|
194 |
XToolkit.awtUnlock(); |
|
195 |
} |
|
196 |
} |
|
197 |
||
198 |
// don't use getBounds() inherited from XDecoratedPeer |
|
199 |
public Rectangle getBounds() { |
|
200 |
return new Rectangle(x, y, width, height); |
|
201 |
} |
|
202 |
||
203 |
public void setBoundsPrivate(int x, int y, int width, int height) { |
|
204 |
setBounds(x, y, width, height, SET_BOUNDS | NO_EMBEDDED_CHECK); |
|
205 |
} |
|
206 |
||
207 |
public Rectangle getBoundsPrivate() { |
|
208 |
int x = 0, y = 0; |
|
209 |
int w = 0, h = 0; |
|
210 |
XWindowAttributes attr = new XWindowAttributes(); |
|
211 |
||
212 |
XToolkit.awtLock(); |
|
213 |
try { |
|
214 |
XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), |
|
215 |
getWindow(), attr.pData); |
|
216 |
x = attr.get_x(); |
|
217 |
y = attr.get_y(); |
|
218 |
w = attr.get_width(); |
|
219 |
h = attr.get_height(); |
|
220 |
} finally { |
|
221 |
XToolkit.awtUnlock(); |
|
222 |
} |
|
223 |
attr.dispose(); |
|
224 |
||
225 |
return new Rectangle(x, y, w, h); |
|
226 |
} |
|
227 |
void registerAccelerator(AWTKeyStroke stroke) { |
|
228 |
if (stroke == null) return; |
|
229 |
strokes.add(stroke); |
|
230 |
if (embedder != null && embedder.isActive()) { |
|
231 |
embedder.registerAccelerator(stroke, strokes.size()-1); |
|
232 |
} |
|
233 |
} |
|
234 |
||
235 |
void unregisterAccelerator(AWTKeyStroke stroke) { |
|
236 |
if (stroke == null) return; |
|
237 |
if (embedder != null && embedder.isActive()) { |
|
238 |
int index = strokes.indexOf(stroke); |
|
239 |
embedder.unregisterAccelerator(index); |
|
240 |
} |
|
241 |
} |
|
242 |
||
243 |
void notifyStarted() { |
|
244 |
// Register accelerators |
|
245 |
if (embedder != null && embedder.isActive()) { |
|
246 |
int i = 0; |
|
247 |
Iterator<AWTKeyStroke> iter = strokes.iterator(); |
|
248 |
while (iter.hasNext()) { |
|
249 |
embedder.registerAccelerator(iter.next(), i++); |
|
250 |
} |
|
251 |
} |
|
252 |
// Now we know that the the embedder is an XEmbed server, so we |
|
253 |
// reregister the drop target to enable XDnD protocol support via |
|
254 |
// XEmbed. |
|
255 |
updateDropTarget(); |
|
256 |
} |
|
1974
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
257 |
void notifyStopped() { |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
258 |
if (embedder != null && embedder.isActive()) { |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
259 |
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
|
260 |
embedder.unregisterAccelerator(i); |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
261 |
} |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
262 |
} |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
263 |
} |
1e1487c04864
6773985: OutOfMemory (PermGen space) under Linux / Firefox when switching bw. applets
art
parents:
439
diff
changeset
|
264 |
|
2 | 265 |
long getFocusTargetWindow() { |
266 |
return getWindow(); |
|
267 |
} |
|
268 |
||
269 |
boolean isXEmbedActive() { |
|
270 |
return embedder != null && embedder.isActive(); |
|
271 |
} |
|
272 |
||
273 |
public int getAbsoluteX() |
|
274 |
{ |
|
275 |
Point absoluteLoc = XlibUtil.translateCoordinates(getWindow(), |
|
276 |
XToolkit.getDefaultRootWindow(), |
|
277 |
new Point(0, 0)); |
|
278 |
return absoluteLoc.x; |
|
279 |
} |
|
280 |
||
281 |
public int getAbsoluteY() |
|
282 |
{ |
|
283 |
Point absoluteLoc = XlibUtil.translateCoordinates(getWindow(), |
|
284 |
XToolkit.getDefaultRootWindow(), |
|
285 |
new Point(0, 0)); |
|
286 |
return absoluteLoc.y; |
|
287 |
} |
|
288 |
||
289 |
public int getWidth() { |
|
290 |
return width; |
|
291 |
} |
|
292 |
public int getHeight() { |
|
293 |
return height; |
|
294 |
} |
|
295 |
||
296 |
public Dimension getSize() { |
|
297 |
return new Dimension(width, height); |
|
298 |
} |
|
299 |
||
300 |
// override XWindowPeer's method to let the embedded frame to block |
|
301 |
// the containing window |
|
302 |
public void setModalBlocked(Dialog blocker, boolean blocked) { |
|
303 |
super.setModalBlocked(blocker, blocked); |
|
304 |
||
305 |
EmbeddedFrame frame = (EmbeddedFrame)target; |
|
306 |
frame.notifyModalBlocked(blocker, blocked); |
|
307 |
} |
|
308 |
} |