1 /* |
|
2 * Copyright 2003-2005 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.motif; |
|
27 |
|
28 import java.awt.AWTException; |
|
29 import java.awt.Component; |
|
30 import java.awt.Container; |
|
31 import java.awt.Window; |
|
32 import java.awt.peer.ComponentPeer; |
|
33 import sun.awt.X11InputMethod; |
|
34 import sun.awt.SunToolkit; |
|
35 |
|
36 /** |
|
37 * Input Method Adapter for XIM (with Motif) |
|
38 * |
|
39 * @author JavaSoft International |
|
40 */ |
|
41 public class MInputMethod extends X11InputMethod { |
|
42 |
|
43 public MInputMethod() throws AWTException { |
|
44 super(); |
|
45 } |
|
46 |
|
47 protected boolean openXIM() { |
|
48 return openXIMNative(); |
|
49 } |
|
50 |
|
51 protected boolean createXIC() { |
|
52 MComponentPeer peer = (MComponentPeer)getPeer(clientComponentWindow); |
|
53 if (peer == null) { |
|
54 return false; |
|
55 } |
|
56 MComponentPeer tc = null; |
|
57 if (peer instanceof MInputMethodControl) { |
|
58 tc = ((MInputMethodControl)peer).getTextComponent(); |
|
59 } |
|
60 if (!createXICNative(peer, tc)) { |
|
61 return false; |
|
62 } |
|
63 if (peer instanceof MInputMethodControl) { |
|
64 ((MInputMethodControl)peer).addInputMethod(this); |
|
65 } |
|
66 return true; |
|
67 } |
|
68 |
|
69 protected void setXICFocus(ComponentPeer peer, |
|
70 boolean value, boolean active) { |
|
71 setXICFocusNative((MComponentPeer)peer, value, active); |
|
72 } |
|
73 |
|
74 protected Container getParent(Component client) { |
|
75 // SECURITY: Use _NoClientCode(), because this thread may |
|
76 // be privileged |
|
77 return MComponentPeer.getParent_NoClientCode(client); |
|
78 } |
|
79 |
|
80 /** |
|
81 * Returns peer of the given client component. If the given client component |
|
82 * doesn't have peer, peer of the native container of the client is returned. |
|
83 */ |
|
84 protected ComponentPeer getPeer(Component client) { |
|
85 MComponentPeer peer = (MComponentPeer)MToolkit.targetToPeer(client); |
|
86 if (peer != null) |
|
87 return peer; |
|
88 |
|
89 Container nativeContainer = MToolkit.getNativeContainer(client); |
|
90 peer = (MComponentPeer)MToolkit.targetToPeer(nativeContainer); |
|
91 return peer; |
|
92 } |
|
93 |
|
94 /** |
|
95 * Changes the status area configuration that is to be requested |
|
96 * by Frame or Dialog. |
|
97 */ |
|
98 void configureStatus() { |
|
99 if (isDisposed()) { |
|
100 return; |
|
101 } |
|
102 |
|
103 MComponentPeer peer = (MComponentPeer)getPeer((Window) clientComponentWindow); |
|
104 MComponentPeer tc = ((MInputMethodControl)peer).getTextComponent(); |
|
105 if (tc != null) { |
|
106 configureStatusAreaNative(tc); |
|
107 } |
|
108 } |
|
109 |
|
110 /* |
|
111 * Subclasses should override disposeImpl() instead of dispose(). Client |
|
112 * code should always invoke dispose(), never disposeImpl(). |
|
113 */ |
|
114 protected synchronized void disposeImpl() { |
|
115 if (clientComponentWindow != null) { |
|
116 MComponentPeer peer = (MComponentPeer)getPeer(clientComponentWindow); |
|
117 if (peer instanceof MInputMethodControl) |
|
118 ((MInputMethodControl)peer).removeInputMethod(this); |
|
119 clientComponentWindow = null; |
|
120 } |
|
121 |
|
122 super.disposeImpl(); |
|
123 } |
|
124 |
|
125 /** |
|
126 * @see java.awt.im.spi.InputMethod#removeNotify |
|
127 */ |
|
128 public synchronized void removeNotify() { |
|
129 if (MToolkit.targetToPeer(getClientComponent()) != null) { |
|
130 dispose(); |
|
131 } else { |
|
132 // We do not have to dispose XICs in case of lightweight component. |
|
133 resetXIC(); |
|
134 } |
|
135 } |
|
136 |
|
137 /** |
|
138 * Changes the internal XIC configurations. This is required the |
|
139 * case that addition or elimination of text components has |
|
140 * happened in the containment hierarchy. This method is invoked |
|
141 * by Frame or Dialog. |
|
142 */ |
|
143 synchronized void reconfigureXIC(MInputMethodControl control) { |
|
144 if (!isDisposed()) { |
|
145 // Some IM servers require to reset XIC before destroying |
|
146 // the XIC. I.e., Destroying XIC doesn't reset the internal |
|
147 // state of the IM server. endComposition() takes care of |
|
148 // resetting XIC and preedit synchronization. However, |
|
149 // there is no client at this point. It is assumed that |
|
150 // the previous client is still available for dispatching |
|
151 // committed text which maintains client's composition |
|
152 // context. |
|
153 endComposition(); |
|
154 resetXICifneeded(); |
|
155 reconfigureXICNative((MComponentPeer) control, control.getTextComponent()); |
|
156 } |
|
157 } |
|
158 |
|
159 protected void awtLock() { |
|
160 SunToolkit.awtLock(); |
|
161 } |
|
162 |
|
163 protected void awtUnlock() { |
|
164 SunToolkit.awtUnlock(); |
|
165 } |
|
166 |
|
167 /* |
|
168 * Native methods |
|
169 */ |
|
170 private native boolean openXIMNative(); |
|
171 private native boolean createXICNative(MComponentPeer peer, MComponentPeer tc); |
|
172 private native void reconfigureXICNative(MComponentPeer peer, |
|
173 MComponentPeer tc); |
|
174 private native void configureStatusAreaNative(MComponentPeer tc); |
|
175 private native void setXICFocusNative(MComponentPeer peer, |
|
176 boolean value, boolean active); |
|
177 } |
|