001: /*
002: * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.awt.X11;
027:
028: import java.awt.AWTException;
029: import java.awt.Component;
030: import java.awt.Container;
031: import java.awt.Rectangle;
032: import java.awt.im.spi.InputMethodContext;
033: import java.awt.peer.ComponentPeer;
034: import sun.awt.X11InputMethod;
035:
036: import java.util.logging.*;
037:
038: /**
039: * Input Method Adapter for XIM (without Motif)
040: *
041: * @version 1.13 05/05/07
042: * @author JavaSoft International
043: */
044: public class XInputMethod extends X11InputMethod {
045: private static final Logger log = Logger
046: .getLogger("sun.awt.X11.XInputMethod");
047:
048: public XInputMethod() throws AWTException {
049: super ();
050: }
051:
052: public void setInputMethodContext(InputMethodContext context) {
053: context.enableClientWindowNotification(this , true);
054: }
055:
056: public void notifyClientWindowChange(Rectangle location) {
057: XComponentPeer peer = (XComponentPeer) getPeer(clientComponentWindow);
058: if (peer != null) {
059: adjustStatusWindow(peer.getContentWindow());
060: }
061: }
062:
063: protected boolean openXIM() {
064: return openXIMNative(XToolkit.getDisplay());
065: }
066:
067: protected boolean createXIC() {
068: XComponentPeer peer = (XComponentPeer) getPeer(clientComponentWindow);
069: if (peer == null) {
070: return false;
071: }
072: return createXICNative(peer.getContentWindow());
073: }
074:
075: private static volatile long xicFocus = 0;
076:
077: protected void setXICFocus(ComponentPeer peer, boolean value,
078: boolean active) {
079: if (peer == null) {
080: return;
081: }
082: xicFocus = ((XComponentPeer) peer).getContentWindow();
083: setXICFocusNative(((XComponentPeer) peer).getContentWindow(),
084: value, active);
085: }
086:
087: public static long getXICFocus() {
088: return xicFocus;
089: }
090:
091: /* XAWT_HACK FIX ME!
092: do NOT call client code!
093: */
094: protected Container getParent(Component client) {
095: return client.getParent();
096: }
097:
098: /**
099: * Returns peer of the given client component. If the given client component
100: * doesn't have peer, peer of the native container of the client is returned.
101: */
102: protected ComponentPeer getPeer(Component client) {
103: XComponentPeer peer;
104:
105: if (log.isLoggable(Level.FINE))
106: log.fine("Client is " + client);
107: peer = (XComponentPeer) XToolkit.targetToPeer(client);
108: while (client != null && peer == null) {
109: client = getParent(client);
110: peer = (XComponentPeer) XToolkit.targetToPeer(client);
111: }
112: log.log(Level.FINE, "Peer is {0}, client is {1}", new Object[] {
113: peer, client });
114:
115: if (peer != null)
116: return peer;
117:
118: return null;
119: }
120:
121: /*
122: * Subclasses should override disposeImpl() instead of dispose(). Client
123: * code should always invoke dispose(), never disposeImpl().
124: */
125: protected synchronized void disposeImpl() {
126: super .disposeImpl();
127: clientComponentWindow = null;
128: }
129:
130: protected void awtLock() {
131: XToolkit.awtLock();
132: }
133:
134: protected void awtUnlock() {
135: XToolkit.awtUnlock();
136: }
137:
138: long getCurrentParentWindow() {
139: return (long) ((XWindow) clientComponentWindow.getPeer())
140: .getContentWindow();
141: }
142:
143: /*
144: * Native methods
145: */
146: private native boolean openXIMNative(long display);
147:
148: private native boolean createXICNative(long window);
149:
150: private native void setXICFocusNative(long window, boolean value,
151: boolean active);
152:
153: private native void adjustStatusWindow(long window);
154: }
|