jdk/src/windows/classes/sun/awt/windows/WInputMethod.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 7017 f3bfa15db005
child 11271 f10f98b24801
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 7017
diff changeset
     2
 * Copyright (c) 1997, 2010, 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: 1956
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: 1956
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: 1956
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1956
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1956
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package sun.awt.windows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.im.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.im.spi.InputMethodContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.font.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.text.AttributedCharacterIterator.Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.lang.Character.Subset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.lang.Character.UnicodeBlock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.awt.im.InputMethodAdapter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class WInputMethod extends InputMethodAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * The input method context, which is used to dispatch input method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * events to the client component and to request information from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * the client component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private InputMethodContext inputContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private Component awtFocussedComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private WComponentPeer awtFocussedComponentPeer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private WComponentPeer lastFocussedComponentPeer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private boolean isLastFocussedActiveClient = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private boolean isActive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private int context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private boolean open; //default open status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private int cmode;    //default conversion mode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private Locale currentLocale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // indicate whether status window is hidden or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private boolean statusWindowHidden = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // attribute definition in Win32 (in IMM.H)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public final static byte ATTR_INPUT                 = 0x00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public final static byte ATTR_TARGET_CONVERTED      = 0x01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public final static byte ATTR_CONVERTED             = 0x02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public final static byte ATTR_TARGET_NOTCONVERTED   = 0x03;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public final static byte ATTR_INPUT_ERROR           = 0x04;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    // cmode definition in Win32 (in IMM.H)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public final static int  IME_CMODE_ALPHANUMERIC     = 0x0000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public final static int  IME_CMODE_NATIVE           = 0x0001;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public final static int  IME_CMODE_KATAKANA         = 0x0002;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public final static int  IME_CMODE_LANGUAGE         = 0x0003;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public final static int  IME_CMODE_FULLSHAPE        = 0x0008;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public final static int  IME_CMODE_HANJACONVERT     = 0x0040;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public final static int  IME_CMODE_ROMAN            = 0x0010;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // flag values for endCompositionNative() behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private final static boolean COMMIT_INPUT           = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private final static boolean DISCARD_INPUT          = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static Map[] highlightStyles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    // Initialize highlight mapping table
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        Map styles[] = new Map[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        HashMap map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        // UNSELECTED_RAW_TEXT_HIGHLIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        map = new HashMap(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        map.put(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_DOTTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        styles[0] = Collections.unmodifiableMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        // SELECTED_RAW_TEXT_HIGHLIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        map = new HashMap(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        map.put(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_GRAY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        styles[1] = Collections.unmodifiableMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        // UNSELECTED_CONVERTED_TEXT_HIGHLIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        map = new HashMap(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        map.put(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_DOTTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        styles[2] = Collections.unmodifiableMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        // SELECTED_CONVERTED_TEXT_HIGHLIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        map = new HashMap(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        Color navyBlue = new Color(0, 0, 128);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        map.put(TextAttribute.FOREGROUND, navyBlue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        map.put(TextAttribute.BACKGROUND, Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        map.put(TextAttribute.SWAP_COLORS, TextAttribute.SWAP_COLORS_ON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        map.put(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        styles[3] = Collections.unmodifiableMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        highlightStyles = styles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public WInputMethod()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        context = createNativeContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        cmode = getConversionStatus(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        open = getOpenStatus(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        currentLocale = getNativeLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (currentLocale == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            currentLocale = Locale.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    protected void finalize() throws Throwable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        // Release the resources used by the native input context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (context!=0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            destroyNativeContext(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            context=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        super.finalize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public synchronized void setInputMethodContext(InputMethodContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        inputContext = context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public final void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        // Due to a memory management problem in Windows 98, we should retain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        // the native input context until this object is finalized. So do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        // nothing here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @see java.awt.im.spi.InputMethod#getControlObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public Object getControlObject() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public boolean setLocale(Locale lang) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return setLocale(lang, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    private boolean setLocale(Locale lang, boolean onActivate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        Locale[] available = WInputMethodDescriptor.getAvailableLocalesInternal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        for (int i = 0; i < available.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            Locale locale = available[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            if (lang.equals(locale) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    // special compatibility rule for Japanese and Korean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    locale.equals(Locale.JAPAN) && lang.equals(Locale.JAPANESE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    locale.equals(Locale.KOREA) && lang.equals(Locale.KOREAN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                if (isActive) {
7017
f3bfa15db005 6989111: Incorrect default locale for New Zealand
naoto
parents: 5506
diff changeset
   172
                    setNativeLocale(locale.toLanguageTag(), onActivate);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                currentLocale = locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (isActive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            currentLocale = getNativeLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (currentLocale == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                currentLocale = Locale.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return currentLocale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Implements InputMethod.setCharacterSubsets for Windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @see java.awt.im.spi.InputMethod#setCharacterSubsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public void setCharacterSubsets(Subset[] subsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (subsets == null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            setConversionStatus(context, cmode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            setOpenStatus(context, open);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        // Use first subset only. Other subsets in array is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        // This is restriction of Win32 implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        Subset subset1 = subsets[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        Locale locale = getNativeLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        int newmode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (locale == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (locale.getLanguage().equals(Locale.JAPANESE.getLanguage())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            if (subset1 == UnicodeBlock.BASIC_LATIN || subset1 == InputSubset.LATIN_DIGITS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                setOpenStatus(context, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                if (subset1 == UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    || subset1 == InputSubset.KANJI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    || subset1 == UnicodeBlock.HIRAGANA)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    newmode = IME_CMODE_NATIVE | IME_CMODE_FULLSHAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                else if (subset1 == UnicodeBlock.KATAKANA)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    newmode = IME_CMODE_NATIVE | IME_CMODE_KATAKANA| IME_CMODE_FULLSHAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                else if (subset1 == InputSubset.HALFWIDTH_KATAKANA)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                    newmode = IME_CMODE_NATIVE | IME_CMODE_KATAKANA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                else if (subset1 == InputSubset.FULLWIDTH_LATIN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    newmode = IME_CMODE_FULLSHAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                setOpenStatus(context, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                newmode |= (getConversionStatus(context)&IME_CMODE_ROMAN);   // reserve ROMAN input mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                setConversionStatus(context, newmode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        } else if (locale.getLanguage().equals(Locale.KOREAN.getLanguage())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            if (subset1 == UnicodeBlock.BASIC_LATIN || subset1 == InputSubset.LATIN_DIGITS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                setOpenStatus(context, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                if (subset1 == UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    || subset1 == InputSubset.HANJA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    || subset1 == UnicodeBlock.HANGUL_SYLLABLES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    || subset1 == UnicodeBlock.HANGUL_JAMO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    || subset1 == UnicodeBlock.HANGUL_COMPATIBILITY_JAMO)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    newmode = IME_CMODE_NATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                else if (subset1 == InputSubset.FULLWIDTH_LATIN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    newmode = IME_CMODE_FULLSHAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                setOpenStatus(context, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                setConversionStatus(context, newmode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        } else if (locale.getLanguage().equals(Locale.CHINESE.getLanguage())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            if (subset1 == UnicodeBlock.BASIC_LATIN || subset1 == InputSubset.LATIN_DIGITS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                setOpenStatus(context, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                if (subset1 == UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                    || subset1 == InputSubset.TRADITIONAL_HANZI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    || subset1 == InputSubset.SIMPLIFIED_HANZI)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    newmode = IME_CMODE_NATIVE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                else if (subset1 == InputSubset.FULLWIDTH_LATIN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    newmode = IME_CMODE_FULLSHAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                setOpenStatus(context, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                setConversionStatus(context, newmode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public void dispatchEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (e instanceof ComponentEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            Component comp = ((ComponentEvent) e).getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            if (comp == awtFocussedComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                if (awtFocussedComponentPeer == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    awtFocussedComponentPeer.isDisposed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    awtFocussedComponentPeer = getNearestNativePeer(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                if (awtFocussedComponentPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    handleNativeIMEEvent(awtFocussedComponentPeer, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    public void activate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        boolean isAc = haveActiveClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        // When the last focussed component peer is different from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        // current focussed component or if they are different client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        // (active or passive), disable native IME for the old focussed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        // component and enable for the new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (lastFocussedComponentPeer != awtFocussedComponentPeer ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            isLastFocussedActiveClient != isAc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            if (lastFocussedComponentPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                disableNativeIME(lastFocussedComponentPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            if (awtFocussedComponentPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                enableNativeIME(awtFocussedComponentPeer, context, !isAc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            lastFocussedComponentPeer = awtFocussedComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            isLastFocussedActiveClient = isAc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        isActive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if (currentLocale != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            setLocale(currentLocale, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        /* If the status window or Windows language bar is turned off due to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
           native input method was switched to java input method, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
           have to turn it on otherwise it is gone for good until next time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
           the user turns it on through Windows Control Panel. See details
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
           from bug 6252674.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        if (statusWindowHidden) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            setStatusWindowVisible(awtFocussedComponentPeer, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            statusWindowHidden = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    public void deactivate(boolean isTemporary)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        // Sync currentLocale with the Windows keyboard layout which might be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        // by hot key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        getLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        // Delay calling disableNativeIME until activate is called and the newly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        // focussed component has a different peer as the last focussed component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (awtFocussedComponentPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            lastFocussedComponentPeer = awtFocussedComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            isLastFocussedActiveClient = haveActiveClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        isActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Explicitly disable the native IME. Native IME is not disabled when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * deactivate is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    public void disableInputMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        if (lastFocussedComponentPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            disableNativeIME(lastFocussedComponentPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            lastFocussedComponentPeer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            isLastFocussedActiveClient = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * Returns a string with information about the windows input method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public String getNativeInputMethodInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        return getNativeIMMDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @see sun.awt.im.InputMethodAdapter#stopListening
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * This method is called when the input method is swapped out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Calling stopListening to give other input method the keybaord input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    protected void stopListening() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        // Since the native input method is not disabled when deactivate is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        // called, we need to call disableInputMethod to explicitly turn off the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        // native IME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        disableInputMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    // implements sun.awt.im.InputMethodAdapter.setAWTFocussedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    protected void setAWTFocussedComponent(Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        if (component == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        WComponentPeer peer = getNearestNativePeer(component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        if (isActive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            // deactivate/activate are being suppressed during a focus change -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            // this may happen when an input method window is made visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            if (awtFocussedComponentPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                disableNativeIME(awtFocussedComponentPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                enableNativeIME(peer, context, !haveActiveClient());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        awtFocussedComponent = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        awtFocussedComponentPeer = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    // implements java.awt.im.spi.InputMethod.hideWindows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public void hideWindows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (awtFocussedComponentPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            /* Hide the native status window including the Windows language
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
               bar if it is on. One typical senario this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
               gets called is when the native input method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
               switched to java input method, for example.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            setStatusWindowVisible(awtFocussedComponentPeer, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            statusWindowHidden = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @see java.awt.im.spi.InputMethod#removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        endCompositionNative(context, DISCARD_INPUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        awtFocussedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        awtFocussedComponentPeer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @see java.awt.Toolkit#mapInputMethodHighlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    static Map mapInputMethodHighlight(InputMethodHighlight highlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        int state = highlight.getState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        if (state == InputMethodHighlight.RAW_TEXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        } else if (state == InputMethodHighlight.CONVERTED_TEXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            index = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        if (highlight.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            index += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        return highlightStyles[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    // see sun.awt.im.InputMethodAdapter.supportsBelowTheSpot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    protected boolean supportsBelowTheSpot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    public void endComposition()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        //right now the native endCompositionNative() just cancel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        //the composition string, maybe a commtting is desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        endCompositionNative(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            (haveActiveClient() ? COMMIT_INPUT : DISCARD_INPUT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @see java.awt.im.spi.InputMethod#setCompositionEnabled(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    public void setCompositionEnabled(boolean enable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        setOpenStatus(context, enable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @see java.awt.im.spi.InputMethod#isCompositionEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public boolean isCompositionEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        return getOpenStatus(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    public void sendInputMethodEvent(int id, long when, String text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                                     int[] clauseBoundary, String[] clauseReading,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                                     int[] attributeBoundary, byte[] attributeValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                                     int commitedTextLength, int caretPos, int visiblePos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        AttributedCharacterIterator iterator = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        if (text!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            // construct AttributedString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            AttributedString attrStr = new AttributedString(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            // set Language Information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            attrStr.addAttribute(Attribute.LANGUAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                                            Locale.getDefault(), 0, text.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            // set Clause and Reading Information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            if (clauseBoundary!=null && clauseReading!=null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                clauseReading.length!=0 && clauseBoundary.length==clauseReading.length+1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                clauseBoundary[0]==0 && clauseBoundary[clauseReading.length]==text.length() )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                for (int i=0; i<clauseBoundary.length-1; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                    attrStr.addAttribute(Attribute.INPUT_METHOD_SEGMENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                                            new Annotation(null), clauseBoundary[i], clauseBoundary[i+1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                    attrStr.addAttribute(Attribute.READING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                                            new Annotation(clauseReading[i]), clauseBoundary[i], clauseBoundary[i+1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                // if (clauseBoundary != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                //    System.out.println("Invalid clause information!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                attrStr.addAttribute(Attribute.INPUT_METHOD_SEGMENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                                        new Annotation(null), 0, text.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                attrStr.addAttribute(Attribute.READING,
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   491
                                     new Annotation(""), 0, text.length());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            // set Hilight Information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            if (attributeBoundary!=null && attributeValue!=null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                attributeValue.length!=0 && attributeBoundary.length==attributeValue.length+1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                attributeBoundary[0]==0 && attributeBoundary[attributeValue.length]==text.length() )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                for (int i=0; i<attributeBoundary.length-1; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                    InputMethodHighlight highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                    switch (attributeValue[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                        case ATTR_TARGET_CONVERTED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                            highlight = InputMethodHighlight.SELECTED_CONVERTED_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                        case ATTR_CONVERTED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                            highlight = InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                        case ATTR_TARGET_NOTCONVERTED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                            highlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                        case ATTR_INPUT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                        case ATTR_INPUT_ERROR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                            highlight = InputMethodHighlight.UNSELECTED_RAW_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                    attrStr.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                                         highlight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                                         attributeBoundary[i], attributeBoundary[i+1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                // if (attributeBoundary != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                //    System.out.println("Invalid attribute information!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                attrStr.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                             InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                             0, text.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            // get iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            iterator = attrStr.getIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        Component source = getClientComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        if (source == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        InputMethodEvent event = new InputMethodEvent(source,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                                                      id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                                                      when,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                                                      iterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                                                      commitedTextLength,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                                                      TextHitInfo.leading(caretPos),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                                                      TextHitInfo.leading(visiblePos));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        WToolkit.postEvent(WToolkit.targetToAppContext(source), event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    public void inquireCandidatePosition()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    {
1956
c22d63290cb1 6707023: Chenese Characters in JTextPane Cause Pane to Hang
art
parents: 715
diff changeset
   551
        Component source = getClientComponent();
c22d63290cb1 6707023: Chenese Characters in JTextPane Cause Pane to Hang
art
parents: 715
diff changeset
   552
        if (source == null) {
c22d63290cb1 6707023: Chenese Characters in JTextPane Cause Pane to Hang
art
parents: 715
diff changeset
   553
            return;
c22d63290cb1 6707023: Chenese Characters in JTextPane Cause Pane to Hang
art
parents: 715
diff changeset
   554
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        // This call should return immediately just to cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        // InputMethodRequests.getTextLocation be called within
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        // AWT Event thread.  Otherwise, a potential deadlock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        // could happen.
1956
c22d63290cb1 6707023: Chenese Characters in JTextPane Cause Pane to Hang
art
parents: 715
diff changeset
   559
        Runnable r = new Runnable() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                int x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                int y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                Component client = getClientComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                if (client != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                    if (haveActiveClient()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                            Rectangle rc = inputContext.getTextLocation(TextHitInfo.leading(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                            x = rc.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                            y = rc.y + rc.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                            Point pt = client.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                            Dimension size = client.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                            x = pt.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                            y = pt.y + size.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                openCandidateWindow(awtFocussedComponentPeer, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            }
1956
c22d63290cb1 6707023: Chenese Characters in JTextPane Cause Pane to Hang
art
parents: 715
diff changeset
   580
        };
c22d63290cb1 6707023: Chenese Characters in JTextPane Cause Pane to Hang
art
parents: 715
diff changeset
   581
        WToolkit.postEvent(WToolkit.targetToAppContext(source),
c22d63290cb1 6707023: Chenese Characters in JTextPane Cause Pane to Hang
art
parents: 715
diff changeset
   582
                           new InvocationEvent(source, r));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    // java.awt.Toolkit#getNativeContainer() is not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    //  from this package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    private WComponentPeer getNearestNativePeer(Component comp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        if (comp==null)     return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        ComponentPeer peer = comp.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        if (peer==null)     return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        while (peer instanceof java.awt.peer.LightweightPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            comp = comp.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            if (comp==null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            peer = comp.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            if (peer==null) return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        if (peer instanceof WComponentPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            return (WComponentPeer)peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    private native int createNativeContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    private native void destroyNativeContext(int context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    private native void enableNativeIME(WComponentPeer peer, int context, boolean useNativeCompWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    private native void disableNativeIME(WComponentPeer peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    private native void handleNativeIMEEvent(WComponentPeer peer, AWTEvent e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    private native void endCompositionNative(int context, boolean flag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    private native void setConversionStatus(int context, int cmode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    private native int  getConversionStatus(int context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    private native void setOpenStatus(int context, boolean flag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    private native boolean getOpenStatus(int context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    private native void setStatusWindowVisible(WComponentPeer peer, boolean visible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    private native String getNativeIMMDescription();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    static native Locale getNativeLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    static native boolean setNativeLocale(String localeName, boolean onActivate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    private native void openCandidateWindow(WComponentPeer peer, int x, int y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
}