author | yan |
Mon, 06 Oct 2008 16:45:00 +0400 | |
changeset 1966 | 12a51fb0db0d |
parent 439 | 3488710b02f8 |
child 1974 | 1e1487c04864 |
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) { |
|
66 |
embedder.install(this); |
|
67 |
} else if (getParentWindowHandle() != 0) { |
|
68 |
XToolkit.awtLock(); |
|
69 |
try { |
|
70 |
XlibWrapper.XReparentWindow(XToolkit.getDisplay(), |
|
71 |
getWindow(), |
|
72 |
getParentWindowHandle(), |
|
73 |
0, 0); |
|
74 |
} finally { |
|
75 |
XToolkit.awtUnlock(); |
|
76 |
} |
|
77 |
} |
|
78 |
} |
|
79 |
||
80 |
public void updateMinimumSize() { |
|
81 |
} |
|
82 |
||
83 |
protected String getWMName() { |
|
84 |
return "JavaEmbeddedFrame"; |
|
85 |
} |
|
86 |
||
87 |
final long getParentWindowHandle() { |
|
88 |
return ((XEmbeddedFrame)target).handle; |
|
89 |
} |
|
90 |
||
91 |
boolean supportsXEmbed() { |
|
92 |
return ((EmbeddedFrame)target).supportsXEmbed(); |
|
93 |
} |
|
94 |
||
95 |
public boolean requestWindowFocus(long time, boolean timeProvided) { |
|
96 |
// Should check for active state of host application |
|
97 |
if (embedder != null && embedder.isActive()) { |
|
98 |
xembedLog.fine("Requesting focus from embedding host"); |
|
99 |
return embedder.requestFocus(); |
|
100 |
} else { |
|
101 |
xembedLog.fine("Requesting focus from X"); |
|
102 |
return super.requestWindowFocus(time, timeProvided); |
|
103 |
} |
|
104 |
} |
|
105 |
||
106 |
protected void requestInitialFocus() { |
|
107 |
if (embedder != null && supportsXEmbed()) { |
|
108 |
embedder.requestFocus(); |
|
109 |
} else { |
|
110 |
super.requestInitialFocus(); |
|
111 |
} |
|
112 |
} |
|
113 |
||
114 |
protected boolean isEventDisabled(XEvent e) { |
|
115 |
if (embedder != null && embedder.isActive()) { |
|
116 |
switch (e.get_type()) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
129
diff
changeset
|
117 |
case XConstants.FocusIn: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
129
diff
changeset
|
118 |
case XConstants.FocusOut: |
2 | 119 |
return true; |
120 |
} |
|
121 |
} |
|
122 |
return super.isEventDisabled(e); |
|
123 |
} |
|
124 |
||
125 |
public void handleConfigureNotifyEvent(XEvent xev) |
|
126 |
{ |
|
127 |
assert (SunToolkit.isAWTLockHeldByCurrentThread()); |
|
128 |
XConfigureEvent xe = xev.get_xconfigure(); |
|
129 |
if (xembedLog.isLoggable(Level.FINE)) { |
|
130 |
xembedLog.fine(xe.toString()); |
|
131 |
} |
|
132 |
||
133 |
// fix for 5063031 |
|
134 |
// if we use super.handleConfigureNotifyEvent() we would get wrong |
|
135 |
// size and position because embedded frame really is NOT a decorated one |
|
136 |
checkIfOnNewScreen(toGlobal(new Rectangle(xe.get_x(), |
|
137 |
xe.get_y(), |
|
138 |
xe.get_width(), |
|
139 |
xe.get_height()))); |
|
140 |
||
141 |
Rectangle oldBounds = getBounds(); |
|
142 |
||
143 |
synchronized (getStateLock()) { |
|
144 |
x = xe.get_x(); |
|
145 |
y = xe.get_y(); |
|
146 |
width = xe.get_width(); |
|
147 |
height = xe.get_height(); |
|
148 |
||
149 |
dimensions.setClientSize(width, height); |
|
150 |
dimensions.setLocation(x, y); |
|
151 |
} |
|
152 |
||
153 |
if (!getLocation().equals(oldBounds.getLocation())) { |
|
154 |
handleMoved(dimensions); |
|
155 |
} |
|
156 |
reconfigureContentWindow(dimensions); |
|
157 |
} |
|
158 |
||
159 |
protected void traverseOutForward() { |
|
160 |
if (embedder != null && embedder.isActive()) { |
|
161 |
if (embedder.isApplicationActive()) { |
|
162 |
xembedLog.fine("Traversing out Forward"); |
|
163 |
embedder.traverseOutForward(); |
|
164 |
} |
|
165 |
} |
|
166 |
} |
|
167 |
||
168 |
protected void traverseOutBackward() { |
|
169 |
if (embedder != null && embedder.isActive()) { |
|
170 |
if (embedder.isApplicationActive()) { |
|
171 |
xembedLog.fine("Traversing out Backward"); |
|
172 |
embedder.traverseOutBackward(); |
|
173 |
} |
|
174 |
} |
|
175 |
} |
|
176 |
||
177 |
// don't use getLocationOnScreen() inherited from XDecoratedPeer |
|
178 |
public Point getLocationOnScreen() { |
|
179 |
XToolkit.awtLock(); |
|
180 |
try { |
|
181 |
return toGlobal(0, 0); |
|
182 |
} finally { |
|
183 |
XToolkit.awtUnlock(); |
|
184 |
} |
|
185 |
} |
|
186 |
||
129
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
2
diff
changeset
|
187 |
@Override |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
2
diff
changeset
|
188 |
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
|
189 |
// 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
|
190 |
return new Rectangle(x, y, width, height); |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
2
diff
changeset
|
191 |
} |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
2
diff
changeset
|
192 |
|
2 | 193 |
// don't use getBounds() inherited from XDecoratedPeer |
194 |
public Rectangle getBounds() { |
|
195 |
return new Rectangle(x, y, width, height); |
|
196 |
} |
|
197 |
||
198 |
public void setBoundsPrivate(int x, int y, int width, int height) { |
|
199 |
setBounds(x, y, width, height, SET_BOUNDS | NO_EMBEDDED_CHECK); |
|
200 |
} |
|
201 |
||
202 |
public Rectangle getBoundsPrivate() { |
|
203 |
int x = 0, y = 0; |
|
204 |
int w = 0, h = 0; |
|
205 |
XWindowAttributes attr = new XWindowAttributes(); |
|
206 |
||
207 |
XToolkit.awtLock(); |
|
208 |
try { |
|
209 |
XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), |
|
210 |
getWindow(), attr.pData); |
|
211 |
x = attr.get_x(); |
|
212 |
y = attr.get_y(); |
|
213 |
w = attr.get_width(); |
|
214 |
h = attr.get_height(); |
|
215 |
} finally { |
|
216 |
XToolkit.awtUnlock(); |
|
217 |
} |
|
218 |
attr.dispose(); |
|
219 |
||
220 |
return new Rectangle(x, y, w, h); |
|
221 |
} |
|
222 |
void registerAccelerator(AWTKeyStroke stroke) { |
|
223 |
if (stroke == null) return; |
|
224 |
strokes.add(stroke); |
|
225 |
if (embedder != null && embedder.isActive()) { |
|
226 |
embedder.registerAccelerator(stroke, strokes.size()-1); |
|
227 |
} |
|
228 |
} |
|
229 |
||
230 |
void unregisterAccelerator(AWTKeyStroke stroke) { |
|
231 |
if (stroke == null) return; |
|
232 |
if (embedder != null && embedder.isActive()) { |
|
233 |
int index = strokes.indexOf(stroke); |
|
234 |
embedder.unregisterAccelerator(index); |
|
235 |
} |
|
236 |
} |
|
237 |
||
238 |
void notifyStarted() { |
|
239 |
// Register accelerators |
|
240 |
if (embedder != null && embedder.isActive()) { |
|
241 |
int i = 0; |
|
242 |
Iterator<AWTKeyStroke> iter = strokes.iterator(); |
|
243 |
while (iter.hasNext()) { |
|
244 |
embedder.registerAccelerator(iter.next(), i++); |
|
245 |
} |
|
246 |
} |
|
247 |
// Now we know that the the embedder is an XEmbed server, so we |
|
248 |
// reregister the drop target to enable XDnD protocol support via |
|
249 |
// XEmbed. |
|
250 |
updateDropTarget(); |
|
251 |
} |
|
252 |
long getFocusTargetWindow() { |
|
253 |
return getWindow(); |
|
254 |
} |
|
255 |
||
256 |
boolean isXEmbedActive() { |
|
257 |
return embedder != null && embedder.isActive(); |
|
258 |
} |
|
259 |
||
260 |
public int getAbsoluteX() |
|
261 |
{ |
|
262 |
Point absoluteLoc = XlibUtil.translateCoordinates(getWindow(), |
|
263 |
XToolkit.getDefaultRootWindow(), |
|
264 |
new Point(0, 0)); |
|
265 |
return absoluteLoc.x; |
|
266 |
} |
|
267 |
||
268 |
public int getAbsoluteY() |
|
269 |
{ |
|
270 |
Point absoluteLoc = XlibUtil.translateCoordinates(getWindow(), |
|
271 |
XToolkit.getDefaultRootWindow(), |
|
272 |
new Point(0, 0)); |
|
273 |
return absoluteLoc.y; |
|
274 |
} |
|
275 |
||
276 |
public int getWidth() { |
|
277 |
return width; |
|
278 |
} |
|
279 |
public int getHeight() { |
|
280 |
return height; |
|
281 |
} |
|
282 |
||
283 |
public Dimension getSize() { |
|
284 |
return new Dimension(width, height); |
|
285 |
} |
|
286 |
||
287 |
// override XWindowPeer's method to let the embedded frame to block |
|
288 |
// the containing window |
|
289 |
public void setModalBlocked(Dialog blocker, boolean blocked) { |
|
290 |
super.setModalBlocked(blocker, blocked); |
|
291 |
||
292 |
EmbeddedFrame frame = (EmbeddedFrame)target; |
|
293 |
frame.notifyModalBlocked(blocker, blocked); |
|
294 |
} |
|
295 |
} |