2
|
1 |
/*
|
|
2 |
* Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
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 |
import java.awt.event.*;
|
|
30 |
import java.awt.image.ColorModel;
|
|
31 |
import java.awt.image.ImageObserver;
|
|
32 |
import java.awt.image.ImageProducer;
|
|
33 |
import java.awt.image.VolatileImage;
|
|
34 |
import java.awt.peer.*;
|
|
35 |
import sun.java2d.pipe.Region;
|
|
36 |
import sun.awt.*;
|
|
37 |
import sun.awt.motif.MToolkit;
|
|
38 |
import sun.awt.motif.X11FontMetrics;
|
|
39 |
|
|
40 |
public class XEmbedChildProxyPeer implements ComponentPeer, XEventDispatcher{
|
|
41 |
XEmbeddingContainer container;
|
|
42 |
XEmbedChildProxy proxy;
|
|
43 |
long handle;
|
|
44 |
XEmbedChildProxyPeer(XEmbedChildProxy proxy) {
|
|
45 |
this.container = proxy.getEmbeddingContainer();
|
|
46 |
this.handle = proxy.getHandle();
|
|
47 |
this.proxy = proxy;
|
|
48 |
initDispatching();
|
|
49 |
}
|
|
50 |
|
|
51 |
void initDispatching() {
|
|
52 |
XToolkit.awtLock();
|
|
53 |
try {
|
|
54 |
XToolkit.addEventDispatcher(handle, this);
|
|
55 |
XlibWrapper.XSelectInput(XToolkit.getDisplay(), handle,
|
|
56 |
XlibWrapper.StructureNotifyMask | XlibWrapper.PropertyChangeMask);
|
|
57 |
}
|
|
58 |
finally {
|
|
59 |
XToolkit.awtUnlock();
|
|
60 |
}
|
|
61 |
container.notifyChildEmbedded(handle);
|
|
62 |
}
|
|
63 |
public boolean isObscured() { return false; }
|
|
64 |
public boolean canDetermineObscurity() { return false; }
|
|
65 |
public void setVisible(boolean b) {
|
|
66 |
if (!b) {
|
|
67 |
XToolkit.awtLock();
|
|
68 |
try {
|
|
69 |
XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), handle);
|
|
70 |
}
|
|
71 |
finally {
|
|
72 |
XToolkit.awtUnlock();
|
|
73 |
}
|
|
74 |
} else {
|
|
75 |
XToolkit.awtLock();
|
|
76 |
try {
|
|
77 |
XlibWrapper.XMapWindow(XToolkit.getDisplay(), handle);
|
|
78 |
}
|
|
79 |
finally {
|
|
80 |
XToolkit.awtUnlock();
|
|
81 |
}
|
|
82 |
}
|
|
83 |
}
|
|
84 |
public void setEnabled(boolean b) {}
|
|
85 |
public void paint(Graphics g) {}
|
|
86 |
public void repaint(long tm, int x, int y, int width, int height) {}
|
|
87 |
public void print(Graphics g) {}
|
|
88 |
public void setBounds(int x, int y, int width, int height, int op) {
|
|
89 |
// Unimplemeneted: Check for min/max hints for non-resizable
|
|
90 |
XToolkit.awtLock();
|
|
91 |
try {
|
|
92 |
XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), handle, x, y, width, height);
|
|
93 |
}
|
|
94 |
finally {
|
|
95 |
XToolkit.awtUnlock();
|
|
96 |
}
|
|
97 |
}
|
|
98 |
public void handleEvent(AWTEvent e) {
|
|
99 |
switch (e.getID()) {
|
|
100 |
case FocusEvent.FOCUS_GAINED:
|
|
101 |
XKeyboardFocusManagerPeer.setCurrentNativeFocusOwner(proxy);
|
|
102 |
container.focusGained(handle);
|
|
103 |
break;
|
|
104 |
case FocusEvent.FOCUS_LOST:
|
|
105 |
XKeyboardFocusManagerPeer.setCurrentNativeFocusOwner(null);
|
|
106 |
container.focusLost(handle);
|
|
107 |
break;
|
|
108 |
case KeyEvent.KEY_PRESSED:
|
|
109 |
case KeyEvent.KEY_RELEASED:
|
|
110 |
if (!((InputEvent)e).isConsumed()) {
|
|
111 |
container.forwardKeyEvent(handle, (KeyEvent)e);
|
|
112 |
}
|
|
113 |
break;
|
|
114 |
}
|
|
115 |
}
|
|
116 |
public void coalescePaintEvent(PaintEvent e) {}
|
|
117 |
public Point getLocationOnScreen() {
|
|
118 |
XWindowAttributes attr = new XWindowAttributes();
|
|
119 |
XToolkit.awtLock();
|
|
120 |
try{
|
|
121 |
XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), handle, attr.pData);
|
|
122 |
return new Point(attr.get_x(), attr.get_y());
|
|
123 |
} finally {
|
|
124 |
XToolkit.awtUnlock();
|
|
125 |
attr.dispose();
|
|
126 |
}
|
|
127 |
}
|
|
128 |
public Dimension getPreferredSize() {
|
|
129 |
XToolkit.awtLock();
|
|
130 |
long p_hints = XlibWrapper.XAllocSizeHints();
|
|
131 |
try {
|
|
132 |
XSizeHints hints = new XSizeHints(p_hints);
|
|
133 |
XlibWrapper.XGetWMNormalHints(XToolkit.getDisplay(), handle, p_hints, XlibWrapper.larg1);
|
|
134 |
Dimension res = new Dimension(hints.get_width(), hints.get_height());
|
|
135 |
return res;
|
|
136 |
} finally {
|
|
137 |
XlibWrapper.XFree(p_hints);
|
|
138 |
XToolkit.awtUnlock();
|
|
139 |
}
|
|
140 |
}
|
|
141 |
public Dimension getMinimumSize() {
|
|
142 |
XToolkit.awtLock();
|
|
143 |
long p_hints = XlibWrapper.XAllocSizeHints();
|
|
144 |
try {
|
|
145 |
XSizeHints hints = new XSizeHints(p_hints);
|
|
146 |
XlibWrapper.XGetWMNormalHints(XToolkit.getDisplay(), handle, p_hints, XlibWrapper.larg1);
|
|
147 |
Dimension res = new Dimension(hints.get_min_width(), hints.get_min_height());
|
|
148 |
return res;
|
|
149 |
} finally {
|
|
150 |
XlibWrapper.XFree(p_hints);
|
|
151 |
XToolkit.awtUnlock();
|
|
152 |
}
|
|
153 |
}
|
|
154 |
public ColorModel getColorModel() { return null; }
|
|
155 |
public Toolkit getToolkit() { return Toolkit.getDefaultToolkit(); }
|
|
156 |
|
|
157 |
public Graphics getGraphics() { return null; }
|
|
158 |
public FontMetrics getFontMetrics(Font font) { return null; }
|
|
159 |
public void dispose() {
|
|
160 |
container.detachChild(handle);
|
|
161 |
}
|
|
162 |
public void setForeground(Color c) {}
|
|
163 |
public void setBackground(Color c) {}
|
|
164 |
public void setFont(Font f) {}
|
|
165 |
public void updateCursorImmediately() {}
|
|
166 |
|
|
167 |
void postEvent(AWTEvent event) {
|
|
168 |
XToolkit.postEvent(XToolkit.targetToAppContext(proxy), event);
|
|
169 |
}
|
|
170 |
|
|
171 |
boolean simulateMotifRequestFocus(Component lightweightChild, boolean temporary,
|
|
172 |
boolean focusedWindowChangeAllowed, long time)
|
|
173 |
{
|
|
174 |
if (lightweightChild == null) {
|
|
175 |
lightweightChild = (Component)proxy;
|
|
176 |
}
|
|
177 |
Component currentOwner = XKeyboardFocusManagerPeer.getCurrentNativeFocusOwner();
|
|
178 |
if (currentOwner != null && currentOwner.getPeer() == null) {
|
|
179 |
currentOwner = null;
|
|
180 |
}
|
|
181 |
FocusEvent fg = new FocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED, false, currentOwner );
|
|
182 |
FocusEvent fl = null;
|
|
183 |
if (currentOwner != null) {
|
|
184 |
fl = new FocusEvent(currentOwner, FocusEvent.FOCUS_LOST, false, lightweightChild);
|
|
185 |
}
|
|
186 |
|
|
187 |
if (fl != null) {
|
|
188 |
postEvent(XComponentPeer.wrapInSequenced(fl));
|
|
189 |
}
|
|
190 |
postEvent(XComponentPeer.wrapInSequenced(fg));
|
|
191 |
// End of Motif compatibility code
|
|
192 |
return true;
|
|
193 |
}
|
|
194 |
|
|
195 |
public boolean requestFocus(Component lightweightChild,
|
|
196 |
boolean temporary,
|
|
197 |
boolean focusedWindowChangeAllowed,
|
|
198 |
long time,
|
|
199 |
CausedFocusEvent.Cause cause)
|
|
200 |
{
|
|
201 |
int result = XKeyboardFocusManagerPeer
|
|
202 |
.shouldNativelyFocusHeavyweight(proxy, lightweightChild,
|
|
203 |
temporary, false, time, cause);
|
|
204 |
|
|
205 |
switch (result) {
|
|
206 |
case XComponentPeer.SNFH_FAILURE:
|
|
207 |
return false;
|
|
208 |
case XComponentPeer.SNFH_SUCCESS_PROCEED:
|
|
209 |
// Currently we just generate focus events like we deal with lightweight instead of calling
|
|
210 |
// XSetInputFocus on native window
|
|
211 |
|
|
212 |
/**
|
|
213 |
* The problems with requests in non-focused window arise because shouldNativelyFocusHeavyweight
|
|
214 |
* checks that native window is focused while appropriate WINDOW_GAINED_FOCUS has not yet
|
|
215 |
* been processed - it is in EventQueue. Thus, SNFH allows native request and stores request record
|
|
216 |
* in requests list - and it breaks our requests sequence as first record on WGF should be the last focus
|
|
217 |
* owner which had focus before WLF. So, we should not add request record for such requests
|
|
218 |
* but store this component in mostRecent - and return true as before for compatibility.
|
|
219 |
*/
|
|
220 |
Container parent = proxy.getParent();
|
|
221 |
// Search for parent window
|
|
222 |
while (parent != null && !(parent instanceof Window)) {
|
|
223 |
parent = parent.getParent();
|
|
224 |
}
|
|
225 |
if (parent != null) {
|
|
226 |
Window parentWindow = (Window)parent;
|
|
227 |
// and check that it is focused
|
|
228 |
if (!parentWindow.isFocused() && XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() == parentWindow) {
|
|
229 |
// if it is not - skip requesting focus on Solaris
|
|
230 |
// but return true for compatibility.
|
|
231 |
return true;
|
|
232 |
}
|
|
233 |
}
|
|
234 |
|
|
235 |
// NOTE: We simulate heavyweight behavior of Motif - component receives focus right
|
|
236 |
// after request, not after event. Normally, we should better listen for event
|
|
237 |
// by listeners.
|
|
238 |
return simulateMotifRequestFocus(lightweightChild, temporary, focusedWindowChangeAllowed, time);
|
|
239 |
// Motif compatibility code
|
|
240 |
case XComponentPeer.SNFH_SUCCESS_HANDLED:
|
|
241 |
// Either lightweight or excessive requiest - all events are generated.
|
|
242 |
return true;
|
|
243 |
}
|
|
244 |
return false;
|
|
245 |
}
|
|
246 |
public boolean isFocusable() {
|
|
247 |
return true;
|
|
248 |
}
|
|
249 |
|
|
250 |
public Image createImage(ImageProducer producer) { return null; }
|
|
251 |
public Image createImage(int width, int height) { return null; }
|
|
252 |
public VolatileImage createVolatileImage(int width, int height) { return null; }
|
|
253 |
public boolean prepareImage(Image img, int w, int h, ImageObserver o) { return false; }
|
|
254 |
public int checkImage(Image img, int w, int h, ImageObserver o) { return 0; }
|
|
255 |
public GraphicsConfiguration getGraphicsConfiguration() { return null; }
|
|
256 |
public boolean handlesWheelScrolling() { return true; }
|
|
257 |
public void createBuffers(int numBuffers, BufferCapabilities caps)
|
|
258 |
throws AWTException { }
|
|
259 |
public Image getBackBuffer() { return null; }
|
|
260 |
public void flip(BufferCapabilities.FlipContents flipAction) { }
|
|
261 |
public void destroyBuffers() { }
|
|
262 |
|
|
263 |
/**
|
|
264 |
* Used by lightweight implementations to tell a ComponentPeer to layout
|
|
265 |
* its sub-elements. For instance, a lightweight Checkbox needs to layout
|
|
266 |
* the box, as well as the text label.
|
|
267 |
*/
|
|
268 |
public void layout() {}
|
|
269 |
|
|
270 |
/**
|
|
271 |
* DEPRECATED: Replaced by getPreferredSize().
|
|
272 |
*/
|
|
273 |
public Dimension preferredSize() {
|
|
274 |
return getPreferredSize();
|
|
275 |
}
|
|
276 |
|
|
277 |
/**
|
|
278 |
* DEPRECATED: Replaced by getMinimumSize().
|
|
279 |
*/
|
|
280 |
public Dimension minimumSize() {
|
|
281 |
return getMinimumSize();
|
|
282 |
}
|
|
283 |
|
|
284 |
/**
|
|
285 |
* DEPRECATED: Replaced by setVisible(boolean).
|
|
286 |
*/
|
|
287 |
public void show() {
|
|
288 |
setVisible(true);
|
|
289 |
}
|
|
290 |
|
|
291 |
/**
|
|
292 |
* DEPRECATED: Replaced by setVisible(boolean).
|
|
293 |
*/
|
|
294 |
public void hide() {
|
|
295 |
setVisible(false);
|
|
296 |
}
|
|
297 |
|
|
298 |
/**
|
|
299 |
* DEPRECATED: Replaced by setEnabled(boolean).
|
|
300 |
*/
|
|
301 |
public void enable() {}
|
|
302 |
|
|
303 |
/**
|
|
304 |
* DEPRECATED: Replaced by setEnabled(boolean).
|
|
305 |
*/
|
|
306 |
public void disable() {}
|
|
307 |
|
|
308 |
/**
|
|
309 |
* DEPRECATED: Replaced by setBounds(int, int, int, int).
|
|
310 |
*/
|
|
311 |
public void reshape(int x, int y, int width, int height) {
|
|
312 |
setBounds(x, y, width, height, SET_BOUNDS);
|
|
313 |
}
|
|
314 |
|
|
315 |
Window getTopLevel(Component comp) {
|
|
316 |
while (comp != null && !(comp instanceof Window)) {
|
|
317 |
comp = comp.getParent();
|
|
318 |
}
|
|
319 |
return (Window)comp;
|
|
320 |
}
|
|
321 |
|
|
322 |
void childResized() {
|
|
323 |
XToolkit.postEvent(XToolkit.targetToAppContext(proxy), new ComponentEvent(proxy, ComponentEvent.COMPONENT_RESIZED));
|
|
324 |
container.childResized(proxy);
|
|
325 |
// XToolkit.postEvent(XToolkit.targetToAppContext(proxy), new InvocationEvent(proxy, new Runnable() {
|
|
326 |
// public void run() {
|
|
327 |
// getTopLevel(proxy).invalidate();
|
|
328 |
// getTopLevel(proxy).pack();
|
|
329 |
// }
|
|
330 |
// }));
|
|
331 |
}
|
|
332 |
void handlePropertyNotify(XEvent xev) {
|
|
333 |
XPropertyEvent ev = xev.get_xproperty();
|
|
334 |
if (ev.get_atom() == XAtom.XA_WM_NORMAL_HINTS) {
|
|
335 |
childResized();
|
|
336 |
}
|
|
337 |
}
|
|
338 |
void handleConfigureNotify(XEvent xev) {
|
|
339 |
childResized();
|
|
340 |
}
|
|
341 |
public void dispatchEvent(XEvent xev) {
|
|
342 |
int type = xev.get_type();
|
|
343 |
switch (type) {
|
|
344 |
case XlibWrapper.PropertyNotify:
|
|
345 |
handlePropertyNotify(xev);
|
|
346 |
break;
|
|
347 |
case XlibWrapper.ConfigureNotify:
|
|
348 |
handleConfigureNotify(xev);
|
|
349 |
break;
|
|
350 |
}
|
|
351 |
}
|
|
352 |
|
|
353 |
void requestXEmbedFocus() {
|
|
354 |
postEvent(new InvocationEvent(proxy, new Runnable() {
|
|
355 |
public void run() {
|
|
356 |
proxy.requestFocusInWindow();
|
|
357 |
}
|
|
358 |
}));
|
|
359 |
}
|
|
360 |
|
|
361 |
public void reparent(ContainerPeer newNativeParent) {
|
|
362 |
}
|
|
363 |
public boolean isReparentSupported() {
|
|
364 |
return false;
|
|
365 |
}
|
|
366 |
public Rectangle getBounds() {
|
|
367 |
XWindowAttributes attrs = new XWindowAttributes();
|
|
368 |
XToolkit.awtLock();
|
|
369 |
try {
|
|
370 |
XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), handle, attrs.pData);
|
|
371 |
return new Rectangle(attrs.get_x(), attrs.get_y(), attrs.get_width(), attrs.get_height());
|
|
372 |
} finally {
|
|
373 |
XToolkit.awtUnlock();
|
|
374 |
attrs.dispose();
|
|
375 |
}
|
|
376 |
}
|
|
377 |
public void setBoundsOperation(int operation) {
|
|
378 |
}
|
|
379 |
|
|
380 |
public void applyShape(Region shape) {
|
|
381 |
}
|
|
382 |
}
|