src/java.desktop/unix/classes/sun/awt/X11InputMethodBase.java
author clanger
Wed, 30 May 2018 08:19:59 +0200
changeset 50350 668463f93ec0
parent 47216 src/java.desktop/unix/classes/sun/awt/X11InputMethod.java@71c04702a3d5
child 52248 2e330da7cbf4
permissions -rw-r--r--
8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF) Reviewed-by: prr Contributed-by: takiguc@linux.vnet.ibm.com, christoph.langer@sap.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2018, 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.awt.AWTEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.AWTException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.EventQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.event.InputMethodEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.font.TextAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.font.TextHitInfo;
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    37
import java.awt.im.InputMethodHighlight;
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    38
import java.awt.im.spi.InputMethodContext;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.peer.ComponentPeer;
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    40
import java.io.BufferedReader;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.FileReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.io.IOException;
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    44
import java.lang.Character.Subset;
15638
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 14498
diff changeset
    45
import java.lang.ref.WeakReference;
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    46
import java.text.AttributedCharacterIterator;
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    47
import java.text.AttributedString;
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    48
import java.util.Collections;
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    49
import java.util.HashMap;
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    50
import java.util.Locale;
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    51
import java.util.Map;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.util.regex.Pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    55
import sun.awt.im.InputMethodAdapter;
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    56
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * Input Method Adapter for XIM
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @author JavaSoft International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    63
public abstract class X11InputMethodBase extends InputMethodAdapter {
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    64
    protected static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11InputMethod");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * The following XIM* values must be the same as those defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Xlib.h
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final int XIMReverse = (1<<0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static final int XIMUnderline = (1<<1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static final int XIMHighlight = (1<<2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static final int XIMPrimary = (1<<5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private static final int XIMSecondary = (1<<6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static final int XIMTertiary = (1<<7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * visible position values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    79
    protected static final int XIMVisibleToForward = (1<<8);
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    80
    protected static final int XIMVisibleToBackward = (1<<9);
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    81
    protected static final int XIMVisibleCenter = (1<<10);
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    82
    protected static final int XIMVisibleMask =
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    83
        (XIMVisibleToForward | XIMVisibleToBackward | XIMVisibleCenter);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private Locale locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private static boolean isXIMOpened = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    protected Container clientComponentWindow = null;
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    88
    protected Component awtFocussedComponent = null;
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    89
    protected Component lastXICFocussedComponent = null;
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    90
    protected boolean   isLastXICActive = false;
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    91
    protected boolean   isLastTemporary = false;
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    92
    protected boolean   isActive = false;
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
    93
    private static Map<TextAttribute, ?>[] highlightStyles;
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    94
    protected boolean disposed = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    //reset the XIC if necessary
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    97
    protected boolean   needResetXIC = false;
15638
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 14498
diff changeset
    98
    private WeakReference<Component> needResetXICClient = new WeakReference<>(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    // The use of compositionEnableSupported is to reduce unnecessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    // native calls if set/isCompositionEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    // throws UnsupportedOperationException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    // It is set to false if that exception is thrown first time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    // either of the two methods are called.
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   105
    protected boolean compositionEnableSupported = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    // The savedCompositionState indicates the composition mode when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    // endComposition or setCompositionEnabled is called. It doesn't always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    // reflect the actual composition state because it doesn't get updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    // when the user changes the composition state through direct interaction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    // with the input method. It is used to save the composition mode when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    // focus is traversed across different client components sharing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    // same java input context. Also if set/isCompositionEnabled are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    // supported, it remains false.
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   114
    protected boolean savedCompositionState = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    // variables to keep track of preedit context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    // these variables need to be accessed within AWT_LOCK/UNLOCK
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   118
    protected String committedText = null;
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   119
    protected StringBuffer composedText = null;
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   120
    protected IntBuffer rawFeedbacks;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    // private data (X11InputMethodData structure defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    // awt_InputMethod.c) for native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    // this structure needs to be accessed within AWT_LOCK/UNLOCK
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   125
    protected transient long pData = 0; // accessed by native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    // Initialize highlight mapping table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    static {
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   129
        @SuppressWarnings({"unchecked", "rawtypes"})
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   130
        Map<TextAttribute, ?> styles[] = new Map[4];
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   131
        HashMap<TextAttribute, Object> map;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        // UNSELECTED_RAW_TEXT_HIGHLIGHT
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   134
        map = new HashMap<>(1);
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   135
        map.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        styles[0] = Collections.unmodifiableMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // SELECTED_RAW_TEXT_HIGHLIGHT
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   139
        map = new HashMap<>(1);
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   140
        map.put(TextAttribute.SWAP_COLORS, TextAttribute.SWAP_COLORS_ON);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        styles[1] = Collections.unmodifiableMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        // UNSELECTED_CONVERTED_TEXT_HIGHLIGHT
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   144
        map = new HashMap<>(1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        map.put(TextAttribute.INPUT_METHOD_UNDERLINE,
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   146
                TextAttribute.UNDERLINE_LOW_ONE_PIXEL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        styles[2] = Collections.unmodifiableMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        // SELECTED_CONVERTED_TEXT_HIGHLIGHT
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   150
        map = new HashMap<>(1);
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   151
        map.put(TextAttribute.SWAP_COLORS, TextAttribute.SWAP_COLORS_ON);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        styles[3] = Collections.unmodifiableMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        highlightStyles = styles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Constructs an X11InputMethod instance. It initializes the XIM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * environment if it's not done yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @exception AWTException if XOpenIM() failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   167
    public X11InputMethodBase() throws AWTException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        // supports only the locale in which the VM is started
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        locale = X11InputMethodDescriptor.getSupportedLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (initXIM() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            throw new AWTException("Cannot open X Input Method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
44534
a076dffbc2c1 8165641: Deprecate Object.finalize
rriggs
parents: 32865
diff changeset
   175
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    protected void finalize() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        super.finalize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Invokes openIM() that invokes XOpenIM() if it's not opened yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @return  true if openXIM() is successful or it's already been opened.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    private synchronized boolean initXIM() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (isXIMOpened == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            isXIMOpened = openXIM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return isXIMOpened;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    protected abstract boolean openXIM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    protected boolean isDisposed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return disposed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    protected abstract void setXICFocus(ComponentPeer peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                                    boolean value, boolean active);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Does nothing - this adapter doesn't use the input method context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @see java.awt.im.spi.InputMethod#setInputMethodContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public void setInputMethodContext(InputMethodContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Set locale to input. If input method doesn't support specified locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * false will be returned and its behavior is not changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param lang locale to input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @return the true is returned when specified locale is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public boolean setLocale(Locale lang) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if (lang.equals(locale)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        // special compatibility rule for Japanese and Korean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        if (locale.equals(Locale.JAPAN) && lang.equals(Locale.JAPANESE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                locale.equals(Locale.KOREA) && lang.equals(Locale.KOREAN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Returns current input locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Does nothing - XIM doesn't let you specify which characters you expect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @see java.awt.im.spi.InputMethod#setCharacterSubsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public void setCharacterSubsets(Subset[] subsets) {
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
     * Dispatch event to input method. InputContext dispatch event with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * method. Input method set consume flag if event is consumed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * input method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @param e event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public void dispatchEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    protected final void resetXICifneeded(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        /* needResetXIC is used to indicate whether to call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
           resetXIC on the active client. resetXIC will always be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
           called on the passive client when endComposition is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (needResetXIC && haveActiveClient() &&
15638
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 14498
diff changeset
   258
            getClientComponent() != needResetXICClient.get()){
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            resetXIC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            // needs to reset the last xic focussed component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            lastXICFocussedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            isLastXICActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
15638
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 14498
diff changeset
   265
            needResetXICClient.clear();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            needResetXIC = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Reset the composition state to the current composition state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   273
    protected abstract void resetCompositionState();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Query and then return the current composition state.
32491
7b3783f9484d 8133807: java.desktop docs: replace some invalid "@returns" tags
avstepan
parents: 30948
diff changeset
   277
     * @return the composition state if isCompositionEnabled call
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * is successful. Otherwise, it returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   280
    protected boolean getCompositionState() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        boolean compositionState = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (compositionEnableSupported) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                compositionState = isCompositionEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            } catch (UnsupportedOperationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                compositionEnableSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return compositionState;
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
     * Activate input method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   295
    public abstract void activate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    protected abstract boolean createXIC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Deactivate input method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   302
    public abstract void deactivate(boolean isTemporary);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * Explicitly disable the native IME. Native IME is not disabled when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * deactivate is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public void disableInputMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (lastXICFocussedComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            setXICFocus(getPeer(lastXICFocussedComponent), false, isLastXICActive);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            lastXICFocussedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            isLastXICActive = false;
14498
317e4103662e 6789984: JPasswordField can not receive keyboard input
alitvinov
parents: 7668
diff changeset
   313
317e4103662e 6789984: JPasswordField can not receive keyboard input
alitvinov
parents: 7668
diff changeset
   314
            resetXIC();
15638
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 14498
diff changeset
   315
            needResetXICClient.clear();
14498
317e4103662e 6789984: JPasswordField can not receive keyboard input
alitvinov
parents: 7668
diff changeset
   316
            needResetXIC = false;
2
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
    // implements java.awt.im.spi.InputMethod.hideWindows
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   321
    public abstract void hideWindows();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @see java.awt.Toolkit#mapInputMethodHighlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
24538
25bf8153fbfe 8039642: Fix raw and unchecked warnings in sun.awt.*
henryjen
parents: 23010
diff changeset
   326
    public static Map<TextAttribute, ?> mapInputMethodHighlight(InputMethodHighlight highlight) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        int state = highlight.getState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (state == InputMethodHighlight.RAW_TEXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        } else if (state == InputMethodHighlight.CONVERTED_TEXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            index = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        if (highlight.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            index += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return highlightStyles[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @see sun.awt.im.InputMethodAdapter#setAWTFocussedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    protected void setAWTFocussedComponent(Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if (component == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if (isActive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            // deactivate/activate are being suppressed during a focus change -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            // this may happen when an input method window is made visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            boolean ac = haveActiveClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            setXICFocus(getPeer(awtFocussedComponent), false, ac);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            setXICFocus(getPeer(component), true, ac);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        awtFocussedComponent = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @see sun.awt.im.InputMethodAdapter#stopListening
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    protected void stopListening() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        // It is desirable to disable XIM by calling XSetICValues with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        // XNPreeditState == XIMPreeditDisable.  But Solaris 2.6 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        // Solaris 7 do not implement this correctly without a patch,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        // so just call resetXIC here.  Prior endComposition call commits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        // the existing composed text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        endComposition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        // disable the native input method so that the other input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        // method could get the input focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        disableInputMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        if (needResetXIC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            resetXIC();
15638
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 14498
diff changeset
   374
            needResetXICClient.clear();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            needResetXIC = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * Returns the Window instance in which the client component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * contained. If not found, null is returned. (IS THIS POSSIBLE?)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   385
    protected Window getClientComponentWindow() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        Component client = getClientComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        Container container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        if (client instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            container = (Container) client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            container = getParent(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        while (container != null && !(container instanceof java.awt.Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            container = getParent(container);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        return (Window) container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    protected abstract Container getParent(Component client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Returns peer of the given client component. If the given client component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * doesn't have peer, peer of the native container of the client is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    protected abstract ComponentPeer getPeer(Component client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * Used to protect preedit data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    protected abstract void awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    protected abstract void awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * Creates an input method event from the arguments given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * and posts it on the AWT event queue. For arguments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * see InputMethodEvent. Called by input method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @see java.awt.event.InputMethodEvent#InputMethodEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   422
    protected void postInputMethodEvent(int id,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                                      AttributedCharacterIterator text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                      int committedCharacterCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                      TextHitInfo caret,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                                      TextHitInfo visiblePosition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                                      long when) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        Component source = getClientComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        if (source != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            InputMethodEvent event = new InputMethodEvent(source,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                id, when, text, committedCharacterCount, caret, visiblePosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            SunToolkit.postEvent(SunToolkit.targetToAppContext(source), (AWTEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    private void postInputMethodEvent(int id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                                      AttributedCharacterIterator text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                                      int committedCharacterCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                                      TextHitInfo caret,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                                      TextHitInfo visiblePosition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        postInputMethodEvent(id, text, committedCharacterCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                             caret, visiblePosition, EventQueue.getMostRecentEventTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * Dispatches committed text from XIM to the awt event queue. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * method is invoked from the event handler in canvas.c in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * AWT Toolkit thread context and thus inside the AWT Lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @param   str     committed text
30948
0a0972d3b58d 6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents: 30938
diff changeset
   450
     * @param   when    when
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    //       This functionality is implemented in a package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    //       to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    void dispatchCommittedText(String str, long when) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        if (str == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        if (composedText == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            AttributedString attrstr = new AttributedString(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                 attrstr.getIterator(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                                 str.length(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                                 when);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            // if there is composed text, wait until the preedit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            // callback is invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            committedText = str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    private void dispatchCommittedText(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        dispatchCommittedText(str, EventQueue.getMostRecentEventTime());
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
     * Updates composed text with XIM preedit information and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * posts composed text to the awt event queue. The args of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * this method correspond to the XIM preedit callback
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * information. The XIM highlight attributes are translated via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * fixed mapping (i.e., independent from any underlying input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * method engine). This method is invoked in the AWT Toolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * (X event loop) thread context and thus inside the AWT Lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    //       This functionality is implemented in a package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    //       to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   492
    abstract void dispatchComposedText(String chgText,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                                           int chgStyles[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                                           int chgOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                           int chgLength,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                                           int caretPosition,
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   497
                                           long when);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * Flushes composed and committed text held in this context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * This method is invoked in the AWT Toolkit (X event loop) thread context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * and thus inside the AWT Lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    //       This functionality is implemented in a package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    //       to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    void flushText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        String flush = (committedText != null ? committedText : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if (composedText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            flush += composedText.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        if (!flush.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            AttributedString attrstr = new AttributedString(flush);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                                 attrstr.getIterator(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                                 flush.length(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                                 EventQueue.getMostRecentEventTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            composedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            committedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * Subclasses should override disposeImpl() instead of dispose(). Client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * code should always invoke dispose(), never disposeImpl().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   531
    protected abstract void disposeImpl();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * Frees all X Window resources associated with this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @see java.awt.im.spi.InputMethod#dispose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public final void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        boolean call_disposeImpl = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        if (!disposed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                if (!disposed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    disposed = call_disposeImpl = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        if (call_disposeImpl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            disposeImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * Returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * @see java.awt.im.spi.InputMethod#getControlObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    public Object getControlObject() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @see java.awt.im.spi.InputMethod#removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    public synchronized void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @see java.awt.im.spi.InputMethod#setCompositionEnabled(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   573
    public abstract void setCompositionEnabled(boolean enable);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @see java.awt.im.spi.InputMethod#isCompositionEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    public boolean isCompositionEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        /* isCompositionEnabledNative may throw UnsupportedOperationException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
           Don't try to catch it since this method may be called by clients.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
           Use package private method 'getCompositionState' if you want the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
           exception to be caught.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        return isCompositionEnabledNative();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * Ends any input composition that may currently be going on in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * context. Depending on the platform and possibly user preferences,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * this may commit or delete uncommitted text. Any changes to the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * are communicated to the active component using an input method event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * A text editing component may call this in a variety of situations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * for example, when the user moves the insertion point within the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * (but outside the composed text), or when the component's text is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * saved to a file or copied to the clipboard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    public void endComposition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        if (disposed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        /* Before calling resetXIC, record the current composition mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
           so that it can be restored later. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        savedCompositionState = getCompositionState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        boolean active = haveActiveClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (active && composedText == null && committedText == null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            needResetXIC = true;
15638
014faa554d7a 7079260: InputContext leaks memory
pchelko
parents: 14498
diff changeset
   611
            needResetXICClient = new WeakReference<>(getClientComponent());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        String text = resetXIC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        /* needResetXIC is only set to true for active client. So passive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
           client should not reset the flag to false. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        if (active) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            needResetXIC = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        // Remove any existing composed text by posting an InputMethodEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        // with null composed text.  It would be desirable to wait for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        // dispatchComposedText call from X input method engine, but some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        // input method does not conform to the XIM specification and does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        // not call the preedit callback to erase preedit text on calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        // XmbResetIC.  To work around this problem, do it here by ourselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        awtLock();
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   629
        try {
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   630
            composedText = null;
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   631
            postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   632
                                 null,
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   633
                                 0,
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   634
                                 null,
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   635
                                 null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   637
            if (text != null && text.length() > 0) {
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   638
                dispatchCommittedText(text);
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   639
            }
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   640
        } finally {
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   641
            // Put awtUnlock into finally block in case an exception is thrown.
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   642
            awtUnlock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        // Restore the preedit state if it was enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        if (savedCompositionState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            resetCompositionState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * Returns a string with information about the current input method server, or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * On both Linux & SunOS, the value of environment variable XMODIFIERS is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * returned if set. Otherwise, on SunOS, $HOME/.dtprofile will be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * to find out the language service engine (atok or wnn) since there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * no API in Xlib which returns the information of native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * IM server or language service and we want to try our best to return as much
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * information as possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * Note: This method could return null on Linux if XMODIFIERS is not set properly or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * if any IOException is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * See man page of XSetLocaleModifiers(3X11) for the usgae of XMODIFIERS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * atok12setup(1) and wnn6setup(1) for the information written to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * $HOME/.dtprofile when you run these two commands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    public String getNativeInputMethodInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        String xmodifiers = System.getenv("XMODIFIERS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        String imInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        // If XMODIFIERS is set, return the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        if (xmodifiers != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            int imIndex = xmodifiers.indexOf("@im=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            if (imIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                imInfo = xmodifiers.substring(imIndex + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        } else if (System.getProperty("os.name").startsWith("SunOS")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            File dtprofile = new File(System.getProperty("user.home") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                                      "/.dtprofile");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            String languageEngineInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                BufferedReader br = new BufferedReader(new FileReader(dtprofile));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                String line = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                while ( languageEngineInfo == null && (line = br.readLine()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    if (line.contains("atok") || line.contains("wnn")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                        StringTokenizer tokens =  new StringTokenizer(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                        while (tokens.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                            String token = tokens.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                            if (Pattern.matches("atok.*setup", token) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                                Pattern.matches("wnn.*setup", token)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                                languageEngineInfo = token.substring(0, token.indexOf("setup"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                br.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            } catch(IOException ioex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                // Since this method is provided for internal testing only,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                // we dump the stack trace for the ease of debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                ioex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            imInfo = "htt " + languageEngineInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        return imInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * Performs mapping from an XIM visible feedback value to Java IM highlight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * @return Java input method highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   717
    protected InputMethodHighlight convertVisualFeedbackToHighlight(int feedback) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        InputMethodHighlight highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        switch (feedback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        case XIMUnderline:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            highlight = InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        case XIMReverse:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            highlight = InputMethodHighlight.SELECTED_CONVERTED_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        case XIMHighlight:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            highlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            break;
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   730
        case 0: //None of the values are set by Wnn
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        case XIMPrimary:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            highlight = InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        case XIMSecondary:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            highlight = InputMethodHighlight.SELECTED_CONVERTED_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        case XIMTertiary:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            highlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            highlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        return highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    // initial capacity size for string buffer, etc.
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   748
    protected static final int INITIAL_SIZE = 64;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * IntBuffer is an inner class that manipulates an int array and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * provides UNIX file io stream-like programming interfaces to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * access it. (An alternative would be to use ArrayList which may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * be too expensive for the work.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   756
    protected final class IntBuffer {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        private int[] intArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        private int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        private int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        IntBuffer(int initialCapacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            intArray = new int[initialCapacity];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        void insert(int offset, int[] values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            int newSize = size + values.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            if (intArray.length < newSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                int[] newIntArray = new int[newSize * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                System.arraycopy(intArray, 0, newIntArray, 0, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                intArray = newIntArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            System.arraycopy(intArray, offset, intArray, offset+values.length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                             size - offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            System.arraycopy(values, 0, intArray, offset, values.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            size += values.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            if (index > offset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                index = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        void remove(int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            if (offset + length != size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                System.arraycopy(intArray, offset+length, intArray, offset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                                 size - offset - length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            size -= length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            if (index > offset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                index = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        void replace(int offset, int[] values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            System.arraycopy(values, 0, intArray, offset, values.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        void removeAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        void rewind() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        int getNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            if (index == size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            return intArray[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        void unget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            if (index != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                index--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        int getOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            StringBuffer s = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            for (int i = 0; i < size;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                s.append(intArray[i++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                if (i < size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                    s.append(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            return s.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * Native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   833
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   834
    /**
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   835
     * Initialize JNI field and method IDs for fields that may be
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   836
     * accessed from C.
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   837
     */
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   838
    private static native void initIDs();
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   839
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   840
    protected native void turnoffStatusWindow();
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   841
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   842
    protected native void disposeXIC();
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   843
30938
35ae5c70d60e 8030087: Avoid public native methods in sun.awt packages
serb
parents: 25859
diff changeset
   844
    private native String resetXIC();
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   845
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   846
    protected native boolean setCompositionEnabledNative(boolean enable);
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   847
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    private native boolean isCompositionEnabledNative();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
}