1 /* 2 * Copyright (c) 2003, 2008, Oracle and/or its affiliates. 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.awt.X11; 27 28 import java.awt.*; 29 30 /** 31 * This class represent focus holder window implementation. When toplevel requests or receives focus 32 * it instead sets focus to this proxy. This proxy is mapped but invisible(it is kept at (-1,-1)) 33 * and therefore X doesn't control focus after we have set it to proxy. 34 */ 35 public class XFocusProxyWindow extends XBaseWindow { 36 XWindowPeer owner; 37 XFocusProxyWindow(XWindowPeer owner)38 public XFocusProxyWindow(XWindowPeer owner) { 39 super(new XCreateWindowParams(new Object[] { 40 BOUNDS, new Rectangle(-1, -1, 1, 1), 41 PARENT_WINDOW, Long.valueOf(owner.getWindow()), 42 EVENT_MASK, Long.valueOf(XConstants.FocusChangeMask | XConstants 43 .KeyPressMask | XConstants.KeyReleaseMask) 44 })); 45 this.owner = owner; 46 } 47 postInit(XCreateWindowParams params)48 public void postInit(XCreateWindowParams params){ 49 super.postInit(params); 50 setWMClass(getWMClass()); 51 xSetVisible(true); 52 } 53 getWMName()54 protected String getWMName() { 55 return "FocusProxy"; 56 } getWMClass()57 protected String[] getWMClass() { 58 return new String[] {"Focus-Proxy-Window", "FocusProxy"}; 59 } 60 getOwner()61 public XWindowPeer getOwner() { 62 return owner; 63 } 64 dispatchEvent(XEvent ev)65 public void dispatchEvent(XEvent ev) { 66 int type = ev.get_type(); 67 switch (type) 68 { 69 case XConstants.FocusIn: 70 case XConstants.FocusOut: 71 handleFocusEvent(ev); 72 break; 73 } 74 super.dispatchEvent(ev); 75 } 76 handleFocusEvent(XEvent xev)77 public void handleFocusEvent(XEvent xev) { 78 owner.handleFocusEvent(xev); 79 } 80 handleKeyPress(XEvent xev)81 public void handleKeyPress(XEvent xev) { 82 owner.handleKeyPress(xev); 83 } 84 handleKeyRelease(XEvent xev)85 public void handleKeyRelease(XEvent xev) { 86 owner.handleKeyRelease(xev); 87 } 88 } 89