01: /*
02: * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * 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.util.logging.*;
30:
31: /**
32: * This class represent focus holder window implementation. When toplevel requests or receives focus
33: * it instead sets focus to this proxy. This proxy is mapped but invisible(it is kept at (-1,-1))
34: * and therefore X doesn't control focus after we have set it to proxy.
35: */
36: public class XFocusProxyWindow extends XBaseWindow {
37: private static final Logger focusLog = Logger
38: .getLogger("sun.awt.X11.focus.XFocusProxyWindow");
39: XWindowPeer owner;
40:
41: public XFocusProxyWindow(XWindowPeer owner) {
42: super (new XCreateWindowParams(new Object[] {
43: BOUNDS,
44: new Rectangle(-1, -1, 1, 1),
45: PARENT_WINDOW,
46: new Long(owner.getWindow()),
47: EVENT_MASK,
48: new Long(FocusChangeMask | KeyPressMask
49: | KeyReleaseMask) }));
50: this .owner = owner;
51: }
52:
53: public void postInit(XCreateWindowParams params) {
54: super .postInit(params);
55: setWMClass(getWMClass());
56: xSetVisible(true);
57: }
58:
59: protected String getWMName() {
60: return "FocusProxy";
61: }
62:
63: protected String[] getWMClass() {
64: return new String[] { "Focus-Proxy-Window", "FocusProxy" };
65: }
66:
67: public XWindowPeer getOwner() {
68: return owner;
69: }
70:
71: public void dispatchEvent(XEvent ev) {
72: int type = ev.get_type();
73: switch (type) {
74: case XlibWrapper.FocusIn:
75: case XlibWrapper.FocusOut:
76: handleFocusEvent(ev);
77: break;
78: }
79: super .dispatchEvent(ev);
80: }
81:
82: public void handleFocusEvent(XEvent xev) {
83: owner.handleFocusEvent(xev);
84: }
85:
86: public void handleKeyPress(XEvent xev) {
87: owner.handleKeyPress(xev);
88: }
89:
90: public void handleKeyRelease(XEvent xev) {
91: owner.handleKeyRelease(xev);
92: }
93: }
|