jdk/src/java.desktop/unix/classes/sun/awt/X11InputMethod.java
author prr
Sat, 19 Sep 2015 15:45:59 -0700
changeset 32865 f9cb6e427f9e
parent 32491 7b3783f9484d
child 44534 a076dffbc2c1
permissions -rw-r--r--
8136783: Run blessed-modifier-order script on java.desktop Reviewed-by: martin, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30938
35ae5c70d60e 8030087: Avoid public native methods in sun.awt packages
serb
parents: 25859
diff changeset
     2
 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.AWTEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.AWTException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.EventQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.im.InputMethodHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.im.spi.InputMethodContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.awt.im.InputMethodAdapter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.event.InputMethodEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.font.TextAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.font.TextHitInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.lang.Character.Subset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.text.AttributedString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.text.AttributedCharacterIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.io.FileReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.io.BufferedReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.io.IOException;
15638
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 14498
diff changeset
    53
import java.lang.ref.WeakReference;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    54
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.util.regex.Pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * Input Method Adapter for XIM
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @author JavaSoft International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
public abstract class X11InputMethod extends InputMethodAdapter {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    65
    private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11InputMethod");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * The following XIM* values must be the same as those defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Xlib.h
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static final int XIMReverse = (1<<0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static final int XIMUnderline = (1<<1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static final int XIMHighlight = (1<<2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private static final int XIMPrimary = (1<<5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static final int XIMSecondary = (1<<6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private static final int XIMTertiary = (1<<7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * visible position values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private static final int XIMVisibleToForward = (1<<8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static final int XIMVisibleToBackward = (1<<9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static final int XIMVisibleCenter = (1<<10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static final int XIMVisibleMask = (XIMVisibleToForward|
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                                               XIMVisibleToBackward|
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                                               XIMVisibleCenter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private Locale locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private static boolean isXIMOpened = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected Container clientComponentWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private Component awtFocussedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private Component lastXICFocussedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private boolean   isLastXICActive = false;
6839
1e57288ce186 6575419: Solaris : XSetICFoucs is not called with Java application at appropriate timing
naoto
parents: 5506
diff changeset
    93
    private boolean   isLastTemporary = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private boolean   isActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private boolean   isActiveClient = false;
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
    96
    private static Map<TextAttribute, ?>[] highlightStyles;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private boolean disposed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    //reset the XIC if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private boolean   needResetXIC = false;
15638
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 14498
diff changeset
   101
    private WeakReference<Component> needResetXICClient = new WeakReference<>(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    // The use of compositionEnableSupported is to reduce unnecessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    // native calls if set/isCompositionEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    // throws UnsupportedOperationException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    // It is set to false if that exception is thrown first time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    // either of the two methods are called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private boolean compositionEnableSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    // The savedCompositionState indicates the composition mode when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    // endComposition or setCompositionEnabled is called. It doesn't always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    // reflect the actual composition state because it doesn't get updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    // when the user changes the composition state through direct interaction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    // with the input method. It is used to save the composition mode when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    // focus is traversed across different client components sharing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    // same java input context. Also if set/isCompositionEnabled are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    // supported, it remains false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private boolean savedCompositionState = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    // variables to keep track of preedit context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    // these variables need to be accessed within AWT_LOCK/UNLOCK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private String committedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private StringBuffer composedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private IntBuffer rawFeedbacks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    // private data (X11InputMethodData structure defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    // awt_InputMethod.c) for native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    // this structure needs to be accessed within AWT_LOCK/UNLOCK
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 32491
diff changeset
   128
    private transient long pData = 0; // accessed by native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    // Initialize highlight mapping table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    static {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   132
        @SuppressWarnings({"unchecked", "rawtypes"})
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   133
        Map<TextAttribute, ?> styles[] = new Map[4];
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   134
        HashMap<TextAttribute, Object> map;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        // UNSELECTED_RAW_TEXT_HIGHLIGHT
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   137
        map = new HashMap<>(1);
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   138
        map.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        styles[0] = Collections.unmodifiableMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        // SELECTED_RAW_TEXT_HIGHLIGHT
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   142
        map = new HashMap<>(1);
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   143
        map.put(TextAttribute.SWAP_COLORS, TextAttribute.SWAP_COLORS_ON);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        styles[1] = Collections.unmodifiableMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        // UNSELECTED_CONVERTED_TEXT_HIGHLIGHT
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   147
        map = new HashMap<>(1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        map.put(TextAttribute.INPUT_METHOD_UNDERLINE,
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   149
                TextAttribute.UNDERLINE_LOW_ONE_PIXEL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        styles[2] = Collections.unmodifiableMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        // SELECTED_CONVERTED_TEXT_HIGHLIGHT
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   153
        map = new HashMap<>(1);
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   154
        map.put(TextAttribute.SWAP_COLORS, TextAttribute.SWAP_COLORS_ON);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        styles[3] = Collections.unmodifiableMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        highlightStyles = styles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Initialize JNI field and method IDs for fields that may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
       accessed from C.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Constructs an X11InputMethod instance. It initializes the XIM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * environment if it's not done yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @exception AWTException if XOpenIM() failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public X11InputMethod() throws AWTException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        // supports only the locale in which the VM is started
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        locale = X11InputMethodDescriptor.getSupportedLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        if (initXIM() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            throw new AWTException("Cannot open X Input Method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    protected void finalize() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        super.finalize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Invokes openIM() that invokes XOpenIM() if it's not opened yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @return  true if openXIM() is successful or it's already been opened.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    private synchronized boolean initXIM() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (isXIMOpened == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            isXIMOpened = openXIM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return isXIMOpened;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    protected abstract boolean openXIM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    protected boolean isDisposed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return disposed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    protected abstract void setXICFocus(ComponentPeer peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                                    boolean value, boolean active);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Does nothing - this adapter doesn't use the input method context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @see java.awt.im.spi.InputMethod#setInputMethodContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public void setInputMethodContext(InputMethodContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Set locale to input. If input method doesn't support specified locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * false will be returned and its behavior is not changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param lang locale to input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @return the true is returned when specified locale is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public boolean setLocale(Locale lang) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (lang.equals(locale)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        // special compatibility rule for Japanese and Korean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if (locale.equals(Locale.JAPAN) && lang.equals(Locale.JAPANESE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                locale.equals(Locale.KOREA) && lang.equals(Locale.KOREAN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Returns current input locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Does nothing - XIM doesn't let you specify which characters you expect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @see java.awt.im.spi.InputMethod#setCharacterSubsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public void setCharacterSubsets(Subset[] subsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Dispatch event to input method. InputContext dispatch event with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * method. Input method set consume flag if event is consumed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * input method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @param e event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public void dispatchEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    protected final void resetXICifneeded(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        /* needResetXIC is used to indicate whether to call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
           resetXIC on the active client. resetXIC will always be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
           called on the passive client when endComposition is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (needResetXIC && haveActiveClient() &&
15638
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 14498
diff changeset
   267
            getClientComponent() != needResetXICClient.get()){
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            resetXIC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            // needs to reset the last xic focussed component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            lastXICFocussedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            isLastXICActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
15638
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 14498
diff changeset
   274
            needResetXICClient.clear();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            needResetXIC = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Reset the composition state to the current composition state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    private void resetCompositionState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (compositionEnableSupported) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                /* Restore the composition mode to the last saved composition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                   mode. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                setCompositionEnabled(savedCompositionState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            } catch (UnsupportedOperationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                compositionEnableSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Query and then return the current composition state.
32491
7b3783f9484d 8133807: java.desktop docs: replace some invalid "@returns" tags
avstepan
parents: 30948
diff changeset
   296
     * @return the composition state if isCompositionEnabled call
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * is successful. Otherwise, it returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    private boolean getCompositionState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        boolean compositionState = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (compositionEnableSupported) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                compositionState = isCompositionEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            } catch (UnsupportedOperationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                compositionEnableSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        return compositionState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * Activate input method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public synchronized void activate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        clientComponentWindow = getClientComponentWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (clientComponentWindow == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        if (lastXICFocussedComponent != null){
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   320
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 15638
diff changeset
   321
                log.fine("XICFocused {0}, AWTFocused {1}",
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 15638
diff changeset
   322
                         lastXICFocussedComponent, awtFocussedComponent);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 15638
diff changeset
   323
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        if (pData == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            if (!createXIC()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            disposed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        /*  reset input context if necessary and set the XIC focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        resetXICifneeded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        ComponentPeer lastXICFocussedComponentPeer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        ComponentPeer awtFocussedComponentPeer = getPeer(awtFocussedComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if (lastXICFocussedComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
           lastXICFocussedComponentPeer = getPeer(lastXICFocussedComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        /* If the last XIC focussed component has a different peer as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
           current focussed component, change the XIC focus to the newly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
           focussed component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        */
6839
1e57288ce186 6575419: Solaris : XSetICFoucs is not called with Java application at appropriate timing
naoto
parents: 5506
diff changeset
   347
        if (isLastTemporary || lastXICFocussedComponentPeer != awtFocussedComponentPeer ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            isLastXICActive != haveActiveClient()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            if (lastXICFocussedComponentPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                setXICFocus(lastXICFocussedComponentPeer, false, isLastXICActive);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            if (awtFocussedComponentPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                setXICFocus(awtFocussedComponentPeer, true, haveActiveClient());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            lastXICFocussedComponent = awtFocussedComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            isLastXICActive = haveActiveClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        resetCompositionState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        isActive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    protected abstract boolean createXIC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Deactivate input method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    public synchronized void deactivate(boolean isTemporary) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        boolean   isAc =  haveActiveClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        /* Usually as the client component, let's call it component A,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
           loses the focus, this method is called. Then when another client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
           component, let's call it component B,  gets the focus, activate is first called on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
           the previous focused compoent which is A, then endComposition is called on A,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
           deactivate is called on A again. And finally activate is called on the newly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
           focused component B. Here is the call sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
           A loses focus               B gains focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
           -------------> deactivate A -------------> activate A -> endComposition A ->
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
           deactivate A -> activate B ----....
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
           So in order to carry the composition mode across the components sharing the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
           input context, we save it when deactivate is called so that when activate is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
           called, it can be restored correctly till activate is called on the newly focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
           component. (See also sun/awt/im/InputContext and bug 6184471).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
           Last note, getCompositionState should be called before setXICFocus since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
           setXICFocus here sets the XIC to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        savedCompositionState = getCompositionState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        if (isTemporary){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            //turn the status window off...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            turnoffStatusWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        /* Delay resetting the XIC focus until activate is called and the newly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
           focussed component has a different peer as the last focussed component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        lastXICFocussedComponent = awtFocussedComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        isLastXICActive = isAc;
6839
1e57288ce186 6575419: Solaris : XSetICFoucs is not called with Java application at appropriate timing
naoto
parents: 5506
diff changeset
   399
        isLastTemporary = isTemporary;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        isActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Explicitly disable the native IME. Native IME is not disabled when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * deactivate is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    public void disableInputMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if (lastXICFocussedComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            setXICFocus(getPeer(lastXICFocussedComponent), false, isLastXICActive);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            lastXICFocussedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            isLastXICActive = false;
14498
317e4103662e 6789984: JPasswordField can not receive keyboard input
alitvinov
parents: 7668
diff changeset
   412
317e4103662e 6789984: JPasswordField can not receive keyboard input
alitvinov
parents: 7668
diff changeset
   413
            resetXIC();
15638
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 14498
diff changeset
   414
            needResetXICClient.clear();
14498
317e4103662e 6789984: JPasswordField can not receive keyboard input
alitvinov
parents: 7668
diff changeset
   415
            needResetXIC = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    // implements java.awt.im.spi.InputMethod.hideWindows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public void hideWindows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        // ??? need real implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @see java.awt.Toolkit#mapInputMethodHighlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     */
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   427
    public static Map<TextAttribute, ?> mapInputMethodHighlight(InputMethodHighlight highlight) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        int state = highlight.getState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        if (state == InputMethodHighlight.RAW_TEXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        } else if (state == InputMethodHighlight.CONVERTED_TEXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            index = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        if (highlight.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            index += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        return highlightStyles[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @see sun.awt.im.InputMethodAdapter#setAWTFocussedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    protected void setAWTFocussedComponent(Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        if (component == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        if (isActive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            // deactivate/activate are being suppressed during a focus change -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            // this may happen when an input method window is made visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            boolean ac = haveActiveClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            setXICFocus(getPeer(awtFocussedComponent), false, ac);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            setXICFocus(getPeer(component), true, ac);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        awtFocussedComponent = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @see sun.awt.im.InputMethodAdapter#stopListening
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    protected void stopListening() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        // It is desirable to disable XIM by calling XSetICValues with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        // XNPreeditState == XIMPreeditDisable.  But Solaris 2.6 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        // Solaris 7 do not implement this correctly without a patch,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        // so just call resetXIC here.  Prior endComposition call commits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        // the existing composed text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        endComposition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        // disable the native input method so that the other input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        // method could get the input focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        disableInputMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        if (needResetXIC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            resetXIC();
15638
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 14498
diff changeset
   475
            needResetXICClient.clear();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            needResetXIC = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Returns the Window instance in which the client component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * contained. If not found, null is returned. (IS THIS POSSIBLE?)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    private Window getClientComponentWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        Component client = getClientComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        Container container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        if (client instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            container = (Container) client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            container = getParent(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        while (container != null && !(container instanceof java.awt.Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            container = getParent(container);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        return (Window) container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    protected abstract Container getParent(Component client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * Returns peer of the given client component. If the given client component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * doesn't have peer, peer of the native container of the client is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    protected abstract ComponentPeer getPeer(Component client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * Used to protect preedit data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    protected abstract void awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    protected abstract void awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * Creates an input method event from the arguments given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * and posts it on the AWT event queue. For arguments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * see InputMethodEvent. Called by input method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @see java.awt.event.InputMethodEvent#InputMethodEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    private void postInputMethodEvent(int id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                                      AttributedCharacterIterator text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                                      int committedCharacterCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                                      TextHitInfo caret,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                                      TextHitInfo visiblePosition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                                      long when) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        Component source = getClientComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        if (source != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            InputMethodEvent event = new InputMethodEvent(source,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                id, when, text, committedCharacterCount, caret, visiblePosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            SunToolkit.postEvent(SunToolkit.targetToAppContext(source), (AWTEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    private void postInputMethodEvent(int id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                                      AttributedCharacterIterator text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                                      int committedCharacterCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                                      TextHitInfo caret,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                                      TextHitInfo visiblePosition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        postInputMethodEvent(id, text, committedCharacterCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                             caret, visiblePosition, EventQueue.getMostRecentEventTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * Dispatches committed text from XIM to the awt event queue. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * method is invoked from the event handler in canvas.c in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * AWT Toolkit thread context and thus inside the AWT Lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * @param   str     committed text
30948
0a0972d3b58d 6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents: 30938
diff changeset
   551
     * @param   when    when
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    //       This functionality is implemented in a package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    //       to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    void dispatchCommittedText(String str, long when) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        if (str == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        if (composedText == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            AttributedString attrstr = new AttributedString(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                                 attrstr.getIterator(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                                 str.length(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                                 when);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            // if there is composed text, wait until the preedit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            // callback is invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            committedText = str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    private void dispatchCommittedText(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        dispatchCommittedText(str, EventQueue.getMostRecentEventTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * Updates composed text with XIM preedit information and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * posts composed text to the awt event queue. The args of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * this method correspond to the XIM preedit callback
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * information. The XIM highlight attributes are translated via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * fixed mapping (i.e., independent from any underlying input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * method engine). This method is invoked in the AWT Toolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * (X event loop) thread context and thus inside the AWT Lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    //       This functionality is implemented in a package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    //       to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    void dispatchComposedText(String chgText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                                           int chgStyles[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                                           int chgOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                                           int chgLength,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                                           int caretPosition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                                           long when) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        if (disposed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        //Workaround for deadlock bug on solaris2.6_zh bug#4170760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        if (chgText == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            && chgStyles == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            && chgOffset == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            && chgLength == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            && caretPosition == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            && composedText == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            && committedText == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        if (composedText == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            // TODO: avoid reallocation of those buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            composedText = new StringBuffer(INITIAL_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            rawFeedbacks = new IntBuffer(INITIAL_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        if (chgLength > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            if (chgText == null && chgStyles != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                rawFeedbacks.replace(chgOffset, chgStyles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                if (chgLength == composedText.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                    // optimization for the special case to replace the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                    // entire previous text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                    composedText = new StringBuffer(INITIAL_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                    rawFeedbacks = new IntBuffer(INITIAL_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                    if (composedText.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                        if (chgOffset+chgLength < composedText.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                            String text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                            text = composedText.toString().substring(chgOffset+chgLength,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                                                                     composedText.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                            composedText.setLength(chgOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                            composedText.append(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                            // in case to remove substring from chgOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                            // to the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                            composedText.setLength(chgOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                        rawFeedbacks.remove(chgOffset, chgLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        if (chgText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            composedText.insert(chgOffset, chgText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            if (chgStyles != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                rawFeedbacks.insert(chgOffset, chgStyles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        if (composedText.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            composedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            rawFeedbacks = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            // if there is any outstanding committed text stored by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            // dispatchCommittedText(), it has to be sent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            // client component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            if (committedText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                dispatchCommittedText(committedText, when);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                committedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            // otherwise, send null text to delete client's composed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            // text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                                 when);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        // Now sending the composed text to the client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        int composedOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        AttributedString inputText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        // if there is any partially committed text, concatenate it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        // the composed text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        if (committedText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            composedOffset = committedText.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            inputText = new AttributedString(committedText + composedText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            committedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            composedOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            inputText = new AttributedString(composedText.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        int currentFeedback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        int nextFeedback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        int startOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        int currentOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        int visiblePosition = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        TextHitInfo visiblePositionInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        rawFeedbacks.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        currentFeedback = rawFeedbacks.getNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        rawFeedbacks.unget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        while ((nextFeedback = rawFeedbacks.getNext()) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            if (visiblePosition == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                visiblePosition = nextFeedback & XIMVisibleMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                if (visiblePosition != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                    int index = rawFeedbacks.getOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                    if (visiblePosition == XIMVisibleToBackward)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                        visiblePositionInfo = TextHitInfo.leading(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                        visiblePositionInfo = TextHitInfo.trailing(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            nextFeedback &= ~XIMVisibleMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            if (currentFeedback != nextFeedback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                rawFeedbacks.unget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                currentOffset = rawFeedbacks.getOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                inputText.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                                       convertVisualFeedbackToHighlight(currentFeedback),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                                       composedOffset + startOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                                       composedOffset + currentOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                startOffset = currentOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                currentFeedback = nextFeedback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        currentOffset = rawFeedbacks.getOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        if (currentOffset >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            inputText.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                                   convertVisualFeedbackToHighlight(currentFeedback),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                                   composedOffset + startOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                                   composedOffset + currentOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                             inputText.getIterator(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                             composedOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                             TextHitInfo.leading(caretPosition),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                             visiblePositionInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                             when);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * Flushes composed and committed text held in this context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * This method is invoked in the AWT Toolkit (X event loop) thread context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * and thus inside the AWT Lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    //       This functionality is implemented in a package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    //       to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    void flushText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        String flush = (committedText != null ? committedText : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        if (composedText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            flush += composedText.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        if (!flush.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            AttributedString attrstr = new AttributedString(flush);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                                 attrstr.getIterator(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                                 flush.length(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                                 EventQueue.getMostRecentEventTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            composedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            committedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * Subclasses should override disposeImpl() instead of dispose(). Client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * code should always invoke dispose(), never disposeImpl().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    protected synchronized void disposeImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        disposeXIC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        composedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        committedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        rawFeedbacks = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        awtFocussedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        lastXICFocussedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * Frees all X Window resources associated with this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * @see java.awt.im.spi.InputMethod#dispose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    public final void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        boolean call_disposeImpl = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        if (!disposed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                if (!disposed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                    disposed = call_disposeImpl = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        if (call_disposeImpl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            disposeImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * Returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * @see java.awt.im.spi.InputMethod#getControlObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    public Object getControlObject() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * @see java.awt.im.spi.InputMethod#removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    public synchronized void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * @see java.awt.im.spi.InputMethod#setCompositionEnabled(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    public void setCompositionEnabled(boolean enable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        /* If the composition state is successfully changed, set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
           the savedCompositionState to 'enable'. Otherwise, simply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
           return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
           setCompositionEnabledNative may throw UnsupportedOperationException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
           Don't try to catch it since the method may be called by clients.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
           Use package private mthod 'resetCompositionState' if you want the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
           exception to be caught.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        if (setCompositionEnabledNative(enable)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            savedCompositionState = enable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * @see java.awt.im.spi.InputMethod#isCompositionEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    public boolean isCompositionEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        /* isCompositionEnabledNative may throw UnsupportedOperationException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
           Don't try to catch it since this method may be called by clients.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
           Use package private method 'getCompositionState' if you want the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
           exception to be caught.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        return isCompositionEnabledNative();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * Ends any input composition that may currently be going on in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * context. Depending on the platform and possibly user preferences,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * this may commit or delete uncommitted text. Any changes to the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * are communicated to the active component using an input method event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * A text editing component may call this in a variety of situations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * for example, when the user moves the insertion point within the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * (but outside the composed text), or when the component's text is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * saved to a file or copied to the clipboard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    public void endComposition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        if (disposed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        /* Before calling resetXIC, record the current composition mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
           so that it can be restored later. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        savedCompositionState = getCompositionState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        boolean active = haveActiveClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        if (active && composedText == null && committedText == null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            needResetXIC = true;
15638
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 14498
diff changeset
   874
            needResetXICClient = new WeakReference<>(getClientComponent());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        String text = resetXIC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        /* needResetXIC is only set to true for active client. So passive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
           client should not reset the flag to false. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        if (active) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            needResetXIC = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        // Remove any existing composed text by posting an InputMethodEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        // with null composed text.  It would be desirable to wait for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        // dispatchComposedText call from X input method engine, but some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        // input method does not conform to the XIM specification and does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        // not call the preedit callback to erase preedit text on calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        // XmbResetIC.  To work around this problem, do it here by ourselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        composedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                             null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                             0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                             null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                             null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        if (text != null && text.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            dispatchCommittedText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        // Restore the preedit state if it was enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        if (savedCompositionState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            resetCompositionState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * Returns a string with information about the current input method server, or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * On both Linux & SunOS, the value of environment variable XMODIFIERS is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * returned if set. Otherwise, on SunOS, $HOME/.dtprofile will be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * to find out the language service engine (atok or wnn) since there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * no API in Xlib which returns the information of native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * IM server or language service and we want to try our best to return as much
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * information as possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * Note: This method could return null on Linux if XMODIFIERS is not set properly or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * if any IOException is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * See man page of XSetLocaleModifiers(3X11) for the usgae of XMODIFIERS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * atok12setup(1) and wnn6setup(1) for the information written to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * $HOME/.dtprofile when you run these two commands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    public String getNativeInputMethodInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        String xmodifiers = System.getenv("XMODIFIERS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        String imInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        // If XMODIFIERS is set, return the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        if (xmodifiers != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            int imIndex = xmodifiers.indexOf("@im=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            if (imIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                imInfo = xmodifiers.substring(imIndex + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        } else if (System.getProperty("os.name").startsWith("SunOS")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            File dtprofile = new File(System.getProperty("user.home") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                                      "/.dtprofile");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            String languageEngineInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                BufferedReader br = new BufferedReader(new FileReader(dtprofile));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                String line = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                while ( languageEngineInfo == null && (line = br.readLine()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                    if (line.contains("atok") || line.contains("wnn")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                        StringTokenizer tokens =  new StringTokenizer(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                        while (tokens.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                            String token = tokens.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                            if (Pattern.matches("atok.*setup", token) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                                Pattern.matches("wnn.*setup", token)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                                languageEngineInfo = token.substring(0, token.indexOf("setup"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                br.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            } catch(IOException ioex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                // Since this method is provided for internal testing only,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                // we dump the stack trace for the ease of debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                ioex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            imInfo = "htt " + languageEngineInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        return imInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * Performs mapping from an XIM visible feedback value to Java IM highlight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * @return Java input method highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    private InputMethodHighlight convertVisualFeedbackToHighlight(int feedback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        InputMethodHighlight highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        switch (feedback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        case XIMUnderline:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            highlight = InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        case XIMReverse:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            highlight = InputMethodHighlight.SELECTED_CONVERTED_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        case XIMHighlight:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            highlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        case XIMPrimary:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            highlight = InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        case XIMSecondary:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            highlight = InputMethodHighlight.SELECTED_CONVERTED_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        case XIMTertiary:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            highlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            highlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        return highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    // initial capacity size for string buffer, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    private static final int INITIAL_SIZE = 64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * IntBuffer is an inner class that manipulates an int array and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * provides UNIX file io stream-like programming interfaces to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * access it. (An alternative would be to use ArrayList which may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * be too expensive for the work.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    private final class IntBuffer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        private int[] intArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        private int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        private int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        IntBuffer(int initialCapacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            intArray = new int[initialCapacity];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        void insert(int offset, int[] values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            int newSize = size + values.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            if (intArray.length < newSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                int[] newIntArray = new int[newSize * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                System.arraycopy(intArray, 0, newIntArray, 0, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                intArray = newIntArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            System.arraycopy(intArray, offset, intArray, offset+values.length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                             size - offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            System.arraycopy(values, 0, intArray, offset, values.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            size += values.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            if (index > offset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                index = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        void remove(int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            if (offset + length != size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                System.arraycopy(intArray, offset+length, intArray, offset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                                 size - offset - length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            size -= length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            if (index > offset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                index = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        void replace(int offset, int[] values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            System.arraycopy(values, 0, intArray, offset, values.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        void removeAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        void rewind() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        int getNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            if (index == size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            return intArray[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        void unget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            if (index != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                index--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        int getOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            StringBuffer s = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            for (int i = 0; i < size;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                s.append(intArray[i++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                if (i < size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                    s.append(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            return s.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     * Native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     */
30938
35ae5c70d60e 8030087: Avoid public native methods in sun.awt packages
serb
parents: 25859
diff changeset
  1091
    private native String resetXIC();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    private native void disposeXIC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    private native boolean setCompositionEnabledNative(boolean enable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    private native boolean isCompositionEnabledNative();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    private native void turnoffStatusWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
}