3261N/A * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Input Method Adapter for XIM 0N/A * @author JavaSoft International 1999N/A * The following XIM* values must be the same as those defined in 0N/A * visible position values 0N/A //reset the XIC if necessary 1999N/A // The use of compositionEnableSupported is to reduce unnecessary 0N/A // throws UnsupportedOperationException. 0N/A // It is set to false if that exception is thrown first time 0N/A // either of the two methods are called. 0N/A // The savedCompositionState indicates the composition mode when 0N/A // endComposition or setCompositionEnabled is called. It doesn't always 0N/A // reflect the actual composition state because it doesn't get updated 0N/A // when the user changes the composition state through direct interaction 0N/A // with the input method. It is used to save the composition mode when 0N/A // focus is traversed across different client components sharing the 0N/A // supported, it remains false. 0N/A // variables to keep track of preedit context. 0N/A // private data (X11InputMethodData structure defined in 0N/A // awt_InputMethod.c) for native methods 0N/A transient private long pData =
0;
// accessed by native 0N/A // Initialize highlight mapping table 0N/A // UNSELECTED_RAW_TEXT_HIGHLIGHT 0N/A // SELECTED_RAW_TEXT_HIGHLIGHT 0N/A // UNSELECTED_CONVERTED_TEXT_HIGHLIGHT 2146N/A // SELECTED_CONVERTED_TEXT_HIGHLIGHT 0N/A * Initialize JNI field and method IDs for fields that may be 0N/A * Constructs an X11InputMethod instance. It initializes the XIM 0N/A * environment if it's not done yet. 2146N/A * @exception AWTException if XOpenIM() failed. 2146N/A // supports only the locale in which the VM is started 1999N/A * Invokes openIM() that invokes XOpenIM() if it's not opened yet. 1999N/A * @return true if openXIM() is successful or it's already been opened. 0N/A * Does nothing - this adapter doesn't use the input method context. 0N/A * @see java.awt.im.spi.InputMethod#setInputMethodContext 0N/A * Set locale to input. If input method doesn't support specified locale, 0N/A * false will be returned and its behavior is not changed. 0N/A * @param lang locale to input 1999N/A * @return the true is returned when specified locale is supported. 0N/A // special compatibility rule for Japanese and Korean 0N/A * Returns current input locale. 1999N/A * Does nothing - XIM doesn't let you specify which characters you expect. 1999N/A * @see java.awt.im.spi.InputMethod#setCharacterSubsets 0N/A * Dispatch event to input method. InputContext dispatch event with this 0N/A * method. Input method set consume flag if event is consumed in 0N/A /* needResetXIC is used to indicate whether to call 1999N/A resetXIC on the active client. resetXIC will always be 1999N/A called on the passive client when endComposition is called. 0N/A // needs to reset the last xic focussed component. 0N/A * Reset the composition state to the current composition state. 1999N/A /* Restore the composition mode to the last saved composition * Query and then return the current composition state. * @returns the composition state if isCompositionEnabled call * is successful. Otherwise, it returns false. /* reset input context if necessary and set the XIC focus /* If the last XIC focussed component has a different peer as the current focussed component, change the XIC focus to the newly * Deactivate input method. /* Usually as the client component, let's call it component A, loses the focus, this method is called. Then when another client component, let's call it component B, gets the focus, activate is first called on the previous focused compoent which is A, then endComposition is called on A, deactivate is called on A again. And finally activate is called on the newly focused component B. Here is the call sequence. A loses focus B gains focus -------------> deactivate A -------------> activate A -> endComposition A -> deactivate A -> activate B ----.... So in order to carry the composition mode across the components sharing the same input context, we save it when deactivate is called so that when activate is called, it can be restored correctly till activate is called on the newly focused Last note, getCompositionState should be called before setXICFocus since setXICFocus here sets the XIC to 0. //turn the status window off... /* Delay resetting the XIC focus until activate is called and the newly focussed component has a different peer as the last focussed component. * Explicitly disable the native IME. Native IME is not disabled when // implements java.awt.im.spi.InputMethod.hideWindows // ??? need real implementation * @see java.awt.Toolkit#mapInputMethodHighlight * @see sun.awt.im.InputMethodAdapter#setAWTFocussedComponent // this may happen when an input method window is made visible * @see sun.awt.im.InputMethodAdapter#stopListening // It is desirable to disable XIM by calling XSetICValues with // XNPreeditState == XIMPreeditDisable. But Solaris 2.6 and // Solaris 7 do not implement this correctly without a patch, // so just call resetXIC here. Prior endComposition call commits // the existing composed text. // disable the native input method so that the other input // method could get the input focus. * Returns the Window instance in which the client component is * contained. If not found, null is returned. (IS THIS POSSIBLE?) // NOTE: This method may be called by privileged threads. // DO NOT INVOKE CLIENT CODE ON THIS THREAD! * Returns peer of the given client component. If the given client component * doesn't have peer, peer of the native container of the client is returned. * Used to protect preedit data * Creates an input method event from the arguments given * and posts it on the AWT event queue. For arguments, * see InputMethodEvent. Called by input method. * @see java.awt.event.InputMethodEvent#InputMethodEvent * Dispatches committed text from XIM to the awt event queue. This * method is invoked from the event handler in canvas.c in the * AWT Toolkit thread context and thus inside the AWT Lock. * @param str committed text // NOTE: This method may be called by privileged threads. // This functionality is implemented in a package-private method // to insure that it cannot be overridden by client subclasses. // DO NOT INVOKE CLIENT CODE ON THIS THREAD! // if there is composed text, wait until the preedit * Updates composed text with XIM preedit information and * posts composed text to the awt event queue. The args of * this method correspond to the XIM preedit callback * information. The XIM highlight attributes are translated via * fixed mapping (i.e., independent from any underlying input * method engine). This method is invoked in the AWT Toolkit * (X event loop) thread context and thus inside the AWT Lock. // NOTE: This method may be called by privileged threads. // This functionality is implemented in a package-private method // to insure that it cannot be overridden by client subclasses. // DO NOT INVOKE CLIENT CODE ON THIS THREAD! //Workaround for deadlock bug on solaris2.6_zh bug#4170760 // TODO: avoid reallocation of those buffers // optimization for the special case to replace the // in case to remove substring from chgOffset // if there is any outstanding committed text stored by // dispatchCommittedText(), it has to be sent to the // otherwise, send null text to delete client's composed // Now sending the composed text to the client // if there is any partially committed text, concatenate it to * Flushes composed and committed text held in this context. * This method is invoked in the AWT Toolkit (X event loop) thread context * and thus inside the AWT Lock. // NOTE: This method may be called by privileged threads. // This functionality is implemented in a package-private method // to insure that it cannot be overridden by client subclasses. // DO NOT INVOKE CLIENT CODE ON THIS THREAD! * Subclasses should override disposeImpl() instead of dispose(). Client * code should always invoke dispose(), never disposeImpl(). * Frees all X Window resources associated with this object. * @see java.awt.im.spi.InputMethod#dispose * @see java.awt.im.spi.InputMethod#getControlObject * @see java.awt.im.spi.InputMethod#removeNotify * @see java.awt.im.spi.InputMethod#setCompositionEnabled(boolean) /* If the composition state is successfully changed, set the savedCompositionState to 'enable'. Otherwise, simply setCompositionEnabledNative may throw UnsupportedOperationException. Don't try to catch it since the method may be called by clients. Use package private mthod 'resetCompositionState' if you want the * @see java.awt.im.spi.InputMethod#isCompositionEnabled /* isCompositionEnabledNative may throw UnsupportedOperationException. Don't try to catch it since this method may be called by clients. Use package private method 'getCompositionState' if you want the * Ends any input composition that may currently be going on in this * context. Depending on the platform and possibly user preferences, * this may commit or delete uncommitted text. Any changes to the text * are communicated to the active component using an input method event. * A text editing component may call this in a variety of situations, * for example, when the user moves the insertion point within the text * (but outside the composed text), or when the component's text is * saved to a file or copied to the clipboard. /* Before calling resetXIC, record the current composition mode so that it can be restored later. */ /* needResetXIC is only set to true for active client. So passive client should not reset the flag to false. */ // Remove any existing composed text by posting an InputMethodEvent // with null composed text. It would be desirable to wait for a // dispatchComposedText call from X input method engine, but some // input method does not conform to the XIM specification and does // not call the preedit callback to erase preedit text on calling // XmbResetIC. To work around this problem, do it here by ourselves. // Restore the preedit state if it was enabled * Returns a string with information about the current input method server, or null. * On both Linux & SunOS, the value of environment variable XMODIFIERS is * returned if set. Otherwise, on SunOS, $HOME/.dtprofile will be parsed * to find out the language service engine (atok or wnn) since there is * no API in Xlib which returns the information of native * IM server or language service and we want to try our best to return as much * information as possible. * Note: This method could return null on Linux if XMODIFIERS is not set properly or * if any IOException is thrown. * See man page of XSetLocaleModifiers(3X11) for the usgae of XMODIFIERS, * atok12setup(1) and wnn6setup(1) for the information written to * $HOME/.dtprofile when you run these two commands. // If XMODIFIERS is set, return the value // Since this method is provided for internal testing only, // we dump the stack trace for the ease of debugging. * Performs mapping from an XIM visible feedback value to Java IM highlight. * @return Java input method highlight // initial capacity size for string buffer, etc. * IntBuffer is an inner class that manipulates an int array and * provides UNIX file io stream-like programming interfaces to * access it. (An alternative would be to use ArrayList which may * be too expensive for the work.) for (
int i =
0; i <
size;) {