src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 57643 5dae3de0e04b
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54867
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
     2
 * Copyright (c) 1997, 2019, 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: 2802
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: 2802
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: 2802
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2802
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2802
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
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
    #error This file should not be included in headless library
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "awt.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "awt_p.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    33
#include <sun_awt_X11InputMethodBase.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <sun_awt_X11_XInputMethod.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    36
#include <stdio.h>
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    37
#include <stdlib.h>
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    38
#include <sys/time.h>
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    39
#include <X11/keysym.h>
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    40
#include <X11/Xlib.h>
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
    41
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#define THROW_OUT_OF_MEMORY_ERROR() \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        JNU_ThrowOutOfMemoryError((JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2), NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
struct X11InputMethodIDs {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
  jfieldID pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
} x11InputMethodIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
54867
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
    49
static int PreeditStartCallback(XIC, XPointer, XPointer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
static void PreeditDoneCallback(XIC, XPointer, XPointer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
static void PreeditDrawCallback(XIC, XPointer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                                XIMPreeditDrawCallbackStruct *);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
static void PreeditCaretCallback(XIC, XPointer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                                 XIMPreeditCaretCallbackStruct *);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
    55
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
static void StatusStartCallback(XIC, XPointer, XPointer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
static void StatusDoneCallback(XIC, XPointer, XPointer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
static void StatusDrawCallback(XIC, XPointer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                               XIMStatusDrawCallbackStruct *);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
#define ROOT_WINDOW_STYLES      (XIMPreeditNothing | XIMStatusNothing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
#define NO_STYLES               (XIMPreeditNone | XIMStatusNone)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#define PreeditStartIndex       0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#define PreeditDoneIndex        1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#define PreeditDrawIndex        2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#define PreeditCaretIndex       3
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
    69
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#define StatusStartIndex        4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#define StatusDoneIndex         5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
#define StatusDrawIndex         6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
#define NCALLBACKS              7
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
#define NCALLBACKS              4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * Callback function pointers: the order has to match the *Index
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * values above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
static XIMProc callback_funcs[NCALLBACKS] = {
54867
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
    83
    (XIMProc)(void *)&PreeditStartCallback,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    (XIMProc)PreeditDoneCallback,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    (XIMProc)PreeditDrawCallback,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    (XIMProc)PreeditCaretCallback,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
    87
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    (XIMProc)StatusStartCallback,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    (XIMProc)StatusDoneCallback,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    (XIMProc)StatusDrawCallback,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
    94
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
#define MAX_STATUS_LEN  100
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    Window   w;                /*status window id        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    Window   root;             /*the root window id      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    Window   parent;           /*parent shell window     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    int      x, y;             /*parent's upperleft position */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    int      width, height;    /*parent's width, height  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    GC       lightGC;          /*gc for light border     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    GC       dimGC;            /*gc for dim border       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    GC       bgGC;             /*normal painting         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    GC       fgGC;             /*normal painting         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    int      statusW, statusH; /*status window's w, h    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    int      rootW, rootH;     /*root window's w, h    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    int      bWidth;           /*border width            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    char     status[MAX_STATUS_LEN]; /*status text       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    XFontSet fontset;           /*fontset for drawing    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    int      off_x, off_y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    Bool     on;                /*if the status window on*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
} StatusWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * X11InputMethodData keeps per X11InputMethod instance information. A pointer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * to this data structure is kept in an X11InputMethod object (pData).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
typedef struct _X11InputMethodData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    XIC         current_ic;     /* current X Input Context */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    XIC         ic_active;      /* X Input Context for active clients */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    XIC         ic_passive;     /* X Input Context for passive clients */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    XIMCallback *callbacks;     /* callback parameters */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    jobject     x11inputmethod; /* global ref to X11InputMethod instance */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                                /* associated with the XIC */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
   127
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    StatusWindow *statusWindow; /* our own status window  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    char        *lookup_buf;    /* buffer used for XmbLookupString */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    int         lookup_buf_len; /* lookup buffer size in bytes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
} X11InputMethodData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * When XIC is created, a global reference is created for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * sun.awt.X11InputMethod object so that it could be used by the XIM callback
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * functions. This could be a dangerous thing to do when the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * X11InputMethod object is garbage collected and as a result,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * destroyX11InputMethodData is called to delete the global reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * If any XIM callback function still holds and uses the "already deleted"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * global reference, disaster is going to happen. So we have to maintain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * a list for these global references which is consulted first when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * callback functions or any function tries to use "currentX11InputMethodObject"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * which always refers to the global reference try to use it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
typedef struct _X11InputMethodGRefNode {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    jobject inputMethodGRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    struct _X11InputMethodGRefNode* next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
} X11InputMethodGRefNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
X11InputMethodGRefNode *x11InputMethodGRefListHead = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
/* reference to the current X11InputMethod instance, it is always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
   point to the global reference to the X11InputMethodObject since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
   it could be referenced by different threads. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
jobject currentX11InputMethodInstance = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
Window  currentFocusWindow = 0;  /* current window that has focus for input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                                       method. (the best place to put this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                       information should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                       currentX11InputMethodInstance's pData) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
static XIM X11im = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
Display * dpy = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
#define GetJNIEnv() (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
static void DestroyXIMCallback(XIM, XPointer, XPointer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
static void OpenXIMCallback(Display *, XPointer, XPointer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
/* Solaris XIM Extention */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
#define XNCommitStringCallback "commitStringCallback"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
static void CommitStringCallback(XIC, XPointer, XPointer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
static X11InputMethodData * getX11InputMethodData(JNIEnv *, jobject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
static void setX11InputMethodData(JNIEnv *, jobject, X11InputMethodData *);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
static void destroyX11InputMethodData(JNIEnv *, X11InputMethodData *);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
static void freeX11InputMethodData(JNIEnv *, X11InputMethodData *);
54867
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
   178
#if defined(__linux__) || defined(MACOSX)
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
   179
static Window getParentWindow(Window);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
   180
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
#ifdef __solaris__
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
/* Prototype for this function is missing in Solaris X11R6 Xlib.h */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
extern char *XSetIMValues(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
#if NeedVarargsPrototypes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    XIM /* im */, ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * This function is stolen from /src/solaris/hpi/src/system_md.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 * It is used in setting the time in Java-level InputEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
jlong
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
awt_util_nowMillisUTC()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    struct timeval t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    gettimeofday(&t, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    return ((jlong)t.tv_sec) * 1000 + (jlong)(t.tv_usec/1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * Converts the wchar_t string to a multi-byte string calling wcstombs(). A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * buffer is allocated by malloc() to store the multi-byte string. NULL is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * returned if the given wchar_t string pointer is NULL or buffer allocation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
wcstombsdmp(wchar_t *wcs, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    size_t n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    char *mbs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    if (wcs == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    n = len*MB_CUR_MAX + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    mbs = (char *) malloc(n * sizeof(char));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    if (mbs == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        THROW_OUT_OF_MEMORY_ERROR();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /* TODO: check return values... Handle invalid characters properly...  */
35677
c243e74116f8 8146317: Memory leak in wcstombsdmp
serb
parents: 30935
diff changeset
   227
    if (wcstombs(mbs, wcs, n) == (size_t)-1) {
c243e74116f8 8146317: Memory leak in wcstombsdmp
serb
parents: 30935
diff changeset
   228
        free(mbs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return NULL;
35677
c243e74116f8 8146317: Memory leak in wcstombsdmp
serb
parents: 30935
diff changeset
   230
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    return mbs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 * Returns True if the global reference is still in the list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 * otherwise False.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
static Bool isX11InputMethodGRefInList(jobject imGRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    X11InputMethodGRefNode *pX11InputMethodGRef = x11InputMethodGRefListHead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    if (imGRef == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    while (pX11InputMethodGRef != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (pX11InputMethodGRef->inputMethodGRef == imGRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            return True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        pX11InputMethodGRef = pX11InputMethodGRef->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 * Add the new created global reference to the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
static void addToX11InputMethodGRefList(jobject newX11InputMethodGRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    X11InputMethodGRefNode *newNode = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    if (newX11InputMethodGRef == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        isX11InputMethodGRefInList(newX11InputMethodGRef)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    newNode = (X11InputMethodGRefNode *)malloc(sizeof(X11InputMethodGRefNode));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    if (newNode == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        newNode->inputMethodGRef = newX11InputMethodGRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        newNode->next = x11InputMethodGRefListHead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        x11InputMethodGRefListHead = newNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 * Remove the global reference from the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
static void removeX11InputMethodGRefFromList(jobject x11InputMethodGRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     X11InputMethodGRefNode *pX11InputMethodGRef = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     X11InputMethodGRefNode *cX11InputMethodGRef = x11InputMethodGRefListHead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     if (x11InputMethodGRefListHead == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
         x11InputMethodGRef == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
         return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     /* cX11InputMethodGRef always refers to the current node while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        pX11InputMethodGRef refers to the previous node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     while (cX11InputMethodGRef != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
         if (cX11InputMethodGRef->inputMethodGRef == x11InputMethodGRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
             break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
         pX11InputMethodGRef = cX11InputMethodGRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
         cX11InputMethodGRef = cX11InputMethodGRef->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     if (cX11InputMethodGRef == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
         return; /* Not found. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     if (cX11InputMethodGRef == x11InputMethodGRefListHead) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
         x11InputMethodGRefListHead = x11InputMethodGRefListHead->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
         pX11InputMethodGRef->next = cX11InputMethodGRef->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     free(cX11InputMethodGRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
static X11InputMethodData * getX11InputMethodData(JNIEnv * env, jobject imInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    X11InputMethodData *pX11IMData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        (X11InputMethodData *)JNU_GetLongFieldAsPtr(env, imInstance, x11InputMethodIDs.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * In case the XIM server was killed somehow, reset X11InputMethodData.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    if (X11im == NULL && pX11IMData != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        JNU_CallMethodByName(env, NULL, pX11IMData->x11inputmethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                             "flushText",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                             "()V");
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 18135
diff changeset
   327
        JNU_CHECK_EXCEPTION_RETURN(env, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        /* IMPORTANT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
           The order of the following calls is critical since "imInstance" may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
           point to the global reference itself, if "freeX11InputMethodData" is called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
           first, the global reference will be destroyed and "setX11InputMethodData"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
           will in fact fail silently. So pX11IMData will not be set to NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
           This could make the original java object refers to a deleted pX11IMData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
           object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        setX11InputMethodData(env, imInstance, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        freeX11InputMethodData(env, pX11IMData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        pX11IMData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    return pX11IMData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
static void setX11InputMethodData(JNIEnv * env, jobject imInstance, X11InputMethodData *pX11IMData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    JNU_SetLongFieldFromPtr(env, imInstance, x11InputMethodIDs.pData, pX11IMData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
/* this function should be called within AWT_LOCK() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
destroyX11InputMethodData(JNIEnv *env, X11InputMethodData *pX11IMData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * Destroy XICs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    if (pX11IMData == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    if (pX11IMData->ic_active != (XIC)0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        XUnsetICFocus(pX11IMData->ic_active);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        XDestroyIC(pX11IMData->ic_active);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        if (pX11IMData->ic_active != pX11IMData->ic_passive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            if (pX11IMData->ic_passive != (XIC)0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                XUnsetICFocus(pX11IMData->ic_passive);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                XDestroyIC(pX11IMData->ic_passive);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            pX11IMData->ic_passive = (XIC)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            pX11IMData->current_ic = (XIC)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    freeX11InputMethodData(env, pX11IMData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
freeX11InputMethodData(JNIEnv *env, X11InputMethodData *pX11IMData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
{
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
   378
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    if (pX11IMData->statusWindow != NULL){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        StatusWindow *sw = pX11IMData->statusWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        XFreeGC(awt_display, sw->lightGC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        XFreeGC(awt_display, sw->dimGC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        XFreeGC(awt_display, sw->bgGC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        XFreeGC(awt_display, sw->fgGC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        if (sw->fontset != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            XFreeFontSet(awt_display, sw->fontset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        XDestroyWindow(awt_display, sw->w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        free((void*)sw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    if (pX11IMData->callbacks)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        free((void *)pX11IMData->callbacks);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    if (env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        /* Remove the global reference from the list, so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
           the callback function or whoever refers to it could know.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        removeX11InputMethodGRefFromList(pX11IMData->x11inputmethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        (*env)->DeleteGlobalRef(env, pX11IMData->x11inputmethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    if (pX11IMData->lookup_buf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        free((void *)pX11IMData->lookup_buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    free((void *)pX11IMData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
 * Sets or unsets the focus to the given XIC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
setXICFocus(XIC ic, unsigned short req)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    if (ic == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        (void)fprintf(stderr, "Couldn't find X Input Context\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    if (req == 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        XSetICFocus(ic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        XUnsetICFocus(ic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
 * Sets the focus window to the given XIC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
setXICWindowFocus(XIC ic, Window w)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    if (ic == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        (void)fprintf(stderr, "Couldn't find X Input Context\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    (void) XSetICValues(ic, XNFocusWindow, w, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
 * Invokes XmbLookupString() to get something from the XIM. It invokes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
 * X11InputMethod.dispatchCommittedText() if XmbLookupString() returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
 * committed text.  This function is called from handleKeyEvent in canvas.c and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
 * it's under the Motif event loop thread context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
 * Buffer usage: There is a bug in XFree86-4.3.0 XmbLookupString implementation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
 * where it never returns XBufferOverflow.  We need to allocate the initial lookup buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
 * big enough, so that the possibility that user encounters this problem is relatively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
 * small.  When this bug gets fixed, we can make the initial buffer size smaller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
 * Note that XmbLookupString() sometimes produces a non-null-terminated string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
 * Returns True when there is a keysym value to be handled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
#define INITIAL_LOOKUP_BUF_SIZE 512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
18135
d9be76f1a19c 8005661: [parfait] Possible buffer overrun in jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c
pchelko
parents: 17923
diff changeset
   456
Boolean
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
awt_x11inputmethod_lookupString(XKeyPressedEvent *event, KeySym *keysymp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    JNIEnv *env = GetJNIEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    X11InputMethodData *pX11IMData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    KeySym keysym = NoSymbol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    Status status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    int mblen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    jstring javastr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    XIC ic;
18135
d9be76f1a19c 8005661: [parfait] Possible buffer overrun in jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c
pchelko
parents: 17923
diff changeset
   466
    Boolean result = True;
d9be76f1a19c 8005661: [parfait] Possible buffer overrun in jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c
pchelko
parents: 17923
diff changeset
   467
    static Boolean composing = False;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
      printf("lookupString: entering...\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    if (!isX11InputMethodGRefInList(currentX11InputMethodInstance)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        currentX11InputMethodInstance = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    pX11IMData = getX11InputMethodData(env, currentX11InputMethodInstance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    if (pX11IMData == NULL) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
   481
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    if ((ic = pX11IMData->current_ic) == (XIC)0){
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
   489
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    /* allocate the lookup buffer at the first invocation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    if (pX11IMData->lookup_buf_len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        pX11IMData->lookup_buf = (char *)malloc(INITIAL_LOOKUP_BUF_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        if (pX11IMData->lookup_buf == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            THROW_OUT_OF_MEMORY_ERROR();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        pX11IMData->lookup_buf_len = INITIAL_LOOKUP_BUF_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    mblen = XmbLookupString(ic, event, pX11IMData->lookup_buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                            pX11IMData->lookup_buf_len - 1, &keysym, &status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * In case of overflow, a buffer is allocated and it retries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * XmbLookupString().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    if (status == XBufferOverflow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        free((void *)pX11IMData->lookup_buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        pX11IMData->lookup_buf_len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        pX11IMData->lookup_buf = (char *)malloc(mblen + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if (pX11IMData->lookup_buf == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            THROW_OUT_OF_MEMORY_ERROR();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        pX11IMData->lookup_buf_len = mblen + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        mblen = XmbLookupString(ic, event, pX11IMData->lookup_buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                            pX11IMData->lookup_buf_len - 1, &keysym, &status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    pX11IMData->lookup_buf[mblen] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    /* Get keysym without taking modifiers into account first to map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * to AWT keyCode table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    switch (status) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    case XLookupBoth:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        if (!composing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            if (event->keycode != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                *keysymp = keysym;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                result = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        composing = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        /*FALLTHRU*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    case XLookupChars:
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   542
        /*
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   543
        printf("lookupString: status=XLookupChars, type=%d, state=%x, keycode=%x, keysym=%x\n",
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   544
               event->type, event->state, event->keycode, keysym);
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   545
        */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        javastr = JNU_NewStringPlatform(env, (const char *)pX11IMData->lookup_buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        if (javastr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            JNU_CallMethodByName(env, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                                 currentX11InputMethodInstance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                                 "dispatchCommittedText",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                                 "(Ljava/lang/String;J)V",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                                 javastr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                                 event->time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    case XLookupKeySym:
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   558
        /*
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   559
        printf("lookupString: status=XLookupKeySym, type=%d, state=%x, keycode=%x, keysym=%x\n",
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   560
               event->type, event->state, event->keycode, keysym);
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   561
        */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        if (keysym == XK_Multi_key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            composing = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        if (! composing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            *keysymp = keysym;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            result = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    case XLookupNone:
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   571
        /*
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   572
        printf("lookupString: status=XLookupNone, type=%d, state=%x, keycode=%x, keysym=%x\n",
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   573
               event->type, event->state, event->keycode, keysym);
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   574
        */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
   581
#if defined(__linux__) || defined(MACOSX)
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   582
static StatusWindow *createStatusWindow(Window parent) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    StatusWindow *statusWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    XSetWindowAttributes attrib;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    unsigned long attribmask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    Window containerWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    Window status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    Window child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    XWindowAttributes xwa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    XWindowAttributes xxwa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    /* Variable for XCreateFontSet()*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    char **mclr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    int  mccr = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    char *dsr;
37699
c3d9835483f9 8154269: Remove unused or unnecessary Xm/Xt files and header includes
prr
parents: 35677
diff changeset
   595
    unsigned long bg, fg, light, dim;
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   596
    int x, y, off_x, off_y, xx, yy;
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   597
    unsigned int w, h, bw, depth;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    XGCValues values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    unsigned long valuemask = 0;  /*ignore XGCvalue and use defaults*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    int screen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    AwtGraphicsConfigDataPtr adata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    extern int awt_numScreens;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    /*hardcode the size right now, should get the size base on font*/
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   605
    int width=80, height=22;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    Window rootWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    Window *ignoreWindowPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    unsigned int ignoreUnit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    XGetGeometry(dpy, parent, &rootWindow, &x, &y, &w, &h, &bw, &depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    attrib.override_redirect = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    attribmask = CWOverrideRedirect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    for (i = 0; i < awt_numScreens; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        if (RootWindow(dpy, i) == rootWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            screen = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    adata = getDefaultConfig(screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    bg    = adata->AwtColorMatch(255, 255, 255, adata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    fg    = adata->AwtColorMatch(0, 0, 0, adata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    light = adata->AwtColorMatch(195, 195, 195, adata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    dim   = adata->AwtColorMatch(128, 128, 128, adata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   626
    XGetWindowAttributes(dpy, parent, &xwa);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    bw = 2; /*xwa.border_width does not have the correct value*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    /*compare the size difference between parent container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
      and shell widget, the diff should be the border frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
      and title bar height (?)*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    XQueryTree( dpy,
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   634
                parent,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                &rootWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                &containerWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                &ignoreWindowPtr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                &ignoreUnit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    XGetWindowAttributes(dpy, containerWindow, &xxwa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    off_x = (xxwa.width - xwa.width) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    off_y = xxwa.height - xwa.height - off_x; /*it's magic:-) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    /*get the size of root window*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    XGetWindowAttributes(dpy, rootWindow, &xxwa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    XTranslateCoordinates(dpy,
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   648
                          parent, xwa.root,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                          xwa.x, xwa.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                          &x, &y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                          &child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    xx = x - off_x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    yy = y + xwa.height - off_y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    if (xx < 0 ){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        xx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    }
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   657
    if (xx + width > xxwa.width) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        xx = xxwa.width - width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    }
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   660
    if (yy + height > xxwa.height) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        yy = xxwa.height - height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    status =  XCreateWindow(dpy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                            xwa.root,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                            xx, yy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                            width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                            0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                            xwa.depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                            InputOutput,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                            adata->awt_visInfo.visual,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                            attribmask, &attrib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    XSelectInput(dpy, status,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                 ExposureMask | StructureNotifyMask | EnterWindowMask |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                 LeaveWindowMask | VisibilityChangeMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    statusWindow = (StatusWindow*) calloc(1, sizeof(StatusWindow));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    if (statusWindow == NULL){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        THROW_OUT_OF_MEMORY_ERROR();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    statusWindow->w = status;
53678
9b93a6b30cbe 8212677: X11 default visual support for IM status window on VNC
itakiguchi
parents: 52987
diff changeset
   682
    //12, 13-point fonts
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    statusWindow->fontset = XCreateFontSet(dpy,
53678
9b93a6b30cbe 8212677: X11 default visual support for IM status window on VNC
itakiguchi
parents: 52987
diff changeset
   684
                                           "-*-*-medium-r-normal-*-*-120-*-*-*-*," \
9b93a6b30cbe 8212677: X11 default visual support for IM status window on VNC
itakiguchi
parents: 52987
diff changeset
   685
                                           "-*-*-medium-r-normal-*-*-130-*-*-*-*",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                                           &mclr, &mccr, &dsr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    /* In case we didn't find the font set, release the list of missing characters */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    if (mccr > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        XFreeStringList(mclr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    statusWindow->parent = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    statusWindow->on  = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    statusWindow->x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    statusWindow->y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    statusWindow->width = xwa.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    statusWindow->height = xwa.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    statusWindow->off_x = off_x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    statusWindow->off_y = off_y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    statusWindow->bWidth  = bw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    statusWindow->statusH = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    statusWindow->statusW = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    statusWindow->rootH = xxwa.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    statusWindow->rootW = xxwa.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    statusWindow->lightGC = XCreateGC(dpy, status, valuemask, &values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    XSetForeground(dpy, statusWindow->lightGC, light);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    statusWindow->dimGC = XCreateGC(dpy, status, valuemask, &values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    XSetForeground(dpy, statusWindow->dimGC, dim);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    statusWindow->fgGC = XCreateGC(dpy, status, valuemask, &values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    XSetForeground(dpy, statusWindow->fgGC, fg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    statusWindow->bgGC = XCreateGC(dpy, status, valuemask, &values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    XSetForeground(dpy, statusWindow->bgGC, bg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    return statusWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
/* This method is to turn off or turn on the status window. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
static void onoffStatusWindow(X11InputMethodData* pX11IMData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                                Window parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                                Bool ON){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    XWindowAttributes xwa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    Window child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    int x, y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    StatusWindow *statusWindow = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    if (NULL == currentX11InputMethodInstance ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        NULL == pX11IMData ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        NULL == (statusWindow =  pX11IMData->statusWindow)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   730
    if (ON == False) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        XUnmapWindow(dpy, statusWindow->w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        statusWindow->on = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    parent = JNU_CallMethodByName(GetJNIEnv(), NULL, pX11IMData->x11inputmethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                                  "getCurrentParentWindow",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                                  "()J").j;
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   738
    if (statusWindow->parent != parent) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        statusWindow->parent = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    }
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   741
    XGetWindowAttributes(dpy, parent, &xwa);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    XTranslateCoordinates(dpy,
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   743
                          parent, xwa.root,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                          xwa.x, xwa.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                          &x, &y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                          &child);
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   747
    if (statusWindow->x != x ||
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   748
        statusWindow->y != y ||
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   749
        statusWindow->height != xwa.height)
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   750
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        statusWindow->x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        statusWindow->y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        statusWindow->height = xwa.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        x = statusWindow->x - statusWindow->off_x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        y = statusWindow->y + statusWindow->height - statusWindow->off_y;
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   756
        if (x < 0 ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        }
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   759
        if (x + statusWindow->statusW > statusWindow->rootW) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            x = statusWindow->rootW - statusWindow->statusW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        }
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   762
        if (y + statusWindow->statusH > statusWindow->rootH) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            y = statusWindow->rootH - statusWindow->statusH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        XMoveWindow(dpy, statusWindow->w, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    statusWindow->on = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    XMapWindow(dpy, statusWindow->w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
void paintStatusWindow(StatusWindow *statusWindow){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    Window  win  = statusWindow->w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    GC  lightgc = statusWindow->lightGC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    GC  dimgc = statusWindow->dimGC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    GC  bggc = statusWindow->bgGC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    GC  fggc = statusWindow->fgGC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    int width = statusWindow->statusW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    int height = statusWindow->statusH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    int bwidth = statusWindow->bWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    XFillRectangle(dpy, win, bggc, 0, 0, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    /* draw border */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    XDrawLine(dpy, win, fggc, 0, 0, width, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    XDrawLine(dpy, win, fggc, 0, height-1, width-1, height-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    XDrawLine(dpy, win, fggc, 0, 0, 0, height-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    XDrawLine(dpy, win, fggc, width-1, 0, width-1, height-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    XDrawLine(dpy, win, lightgc, 1, 1, width-bwidth, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    XDrawLine(dpy, win, lightgc, 1, 1, 1, height-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    XDrawLine(dpy, win, lightgc, 1, height-2, width-bwidth, height-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    XDrawLine(dpy, win, lightgc, width-bwidth-1, 1, width-bwidth-1, height-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    XDrawLine(dpy, win, dimgc, 2, 2, 2, height-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    XDrawLine(dpy, win, dimgc, 2, height-3, width-bwidth-1, height-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    XDrawLine(dpy, win, dimgc, 2, 2, width-bwidth-2, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    XDrawLine(dpy, win, dimgc, width-bwidth, 2, width-bwidth, height-3);
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   797
    if (statusWindow->fontset) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        XmbDrawString(dpy, win, statusWindow->fontset, fggc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                      bwidth + 2, height - bwidth - 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                      statusWindow->status,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                      strlen(statusWindow->status));
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   802
    } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        /*too bad we failed to create a fontset for this locale*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        XDrawString(dpy, win, fggc, bwidth + 2, height - bwidth - 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                    "[InputMethod ON]", strlen("[InputMethod ON]"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   809
static void adjustStatusWindow(Window shell) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    JNIEnv *env = GetJNIEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    X11InputMethodData *pX11IMData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    StatusWindow *statusWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    if (NULL == currentX11InputMethodInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        || !isX11InputMethodGRefInList(currentX11InputMethodInstance)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        || NULL == (pX11IMData = getX11InputMethodData(env,currentX11InputMethodInstance))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        || NULL == (statusWindow = pX11IMData->statusWindow)
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   818
        || !statusWindow->on)
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   819
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   822
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        XWindowAttributes xwa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        int x, y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        Window child;
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   827
        XGetWindowAttributes(dpy, shell, &xwa);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        XTranslateCoordinates(dpy,
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   829
                              shell, xwa.root,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                              xwa.x, xwa.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                              &x, &y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                              &child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        if (statusWindow->x != x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            || statusWindow->y != y
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            || statusWindow->height != xwa.height){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
          statusWindow->x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
          statusWindow->y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
          statusWindow->height = xwa.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
          x = statusWindow->x - statusWindow->off_x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
          y = statusWindow->y + statusWindow->height - statusWindow->off_y;
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   842
          if (x < 0 ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
              x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
          if (x + statusWindow->statusW > statusWindow->rootW){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
              x = statusWindow->rootW - statusWindow->statusW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
          if (y + statusWindow->statusH > statusWindow->rootH){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
              y = statusWindow->rootH - statusWindow->statusH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
          XMoveWindow(dpy, statusWindow->w, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
}
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
   855
#endif  /* __linux__ || MACOSX */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   856
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
 * Creates two XICs, one for active clients and the other for passive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
 * clients. All information on those XICs are stored in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
 * X11InputMethodData given by the pX11IMData parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
 * For active clients: Try to use preedit callback to support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
 * on-the-spot. If tc is not null, the XIC to be created will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
 * share the Status Area with Motif widgets (TextComponents). If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
 * preferable styles can't be used, fallback to root-window styles. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
 * root-window styles failed, fallback to None styles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
 * For passive clients: Try to use root-window styles. If failed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
 * fallback to None styles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
static Bool
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
createXIC(JNIEnv * env, X11InputMethodData *pX11IMData, Window w)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    XVaNestedList preedit = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    XVaNestedList status = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    XIMStyle on_the_spot_styles = XIMPreeditCallbacks,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
             active_styles = 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
             passive_styles = 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
             no_styles = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    XIMCallback *callbacks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    unsigned short i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    XIMStyles *im_styles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    char *ret = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    if (X11im == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
    }
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   888
    if (!w) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    ret = XGetIMValues(X11im, XNQueryInputStyle, &im_styles, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    if (ret != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        jio_fprintf(stderr,"XGetIMValues: %s\n",ret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        return FALSE ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    on_the_spot_styles |= XIMStatusNothing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   901
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    /*kinput does not support XIMPreeditCallbacks and XIMStatusArea
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
      at the same time, so use StatusCallback to draw the status
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
      ourself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    for (i = 0; i < im_styles->count_styles; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        if (im_styles->supported_styles[i] == (XIMPreeditCallbacks | XIMStatusCallbacks)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            on_the_spot_styles = (XIMPreeditCallbacks | XIMStatusCallbacks);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
   912
#endif /* __linux__ || MACOSX */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    for (i = 0; i < im_styles->count_styles; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        active_styles |= im_styles->supported_styles[i] & on_the_spot_styles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        passive_styles |= im_styles->supported_styles[i] & ROOT_WINDOW_STYLES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        no_styles |= im_styles->supported_styles[i] & NO_STYLES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    XFree(im_styles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    if (active_styles != on_the_spot_styles) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        if (passive_styles == ROOT_WINDOW_STYLES)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            active_styles = passive_styles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            if (no_styles == NO_STYLES)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                active_styles = passive_styles = NO_STYLES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                active_styles = passive_styles = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        if (passive_styles != ROOT_WINDOW_STYLES) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            if (no_styles == NO_STYLES)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                active_styles = passive_styles = NO_STYLES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                active_styles = passive_styles = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    if (active_styles == on_the_spot_styles) {
30935
420ca907dd33 8072448: Can not input Japanese in JTextField on RedHat Linux
azvegint
parents: 26751
diff changeset
   941
        pX11IMData->ic_passive = XCreateIC(X11im,
420ca907dd33 8072448: Can not input Japanese in JTextField on RedHat Linux
azvegint
parents: 26751
diff changeset
   942
                                   XNClientWindow, w,
420ca907dd33 8072448: Can not input Japanese in JTextField on RedHat Linux
azvegint
parents: 26751
diff changeset
   943
                                   XNFocusWindow, w,
420ca907dd33 8072448: Can not input Japanese in JTextField on RedHat Linux
azvegint
parents: 26751
diff changeset
   944
                                   XNInputStyle, passive_styles,
420ca907dd33 8072448: Can not input Japanese in JTextField on RedHat Linux
azvegint
parents: 26751
diff changeset
   945
                                   NULL);
420ca907dd33 8072448: Can not input Japanese in JTextField on RedHat Linux
azvegint
parents: 26751
diff changeset
   946
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        callbacks = (XIMCallback *)malloc(sizeof(XIMCallback) * NCALLBACKS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        if (callbacks == (XIMCallback *)NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        pX11IMData->callbacks = callbacks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        for (i = 0; i < NCALLBACKS; i++, callbacks++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            callbacks->client_data = (XPointer) pX11IMData->x11inputmethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            callbacks->callback = callback_funcs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        callbacks = pX11IMData->callbacks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        preedit = (XVaNestedList)XVaCreateNestedList(0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                        XNPreeditStartCallback, &callbacks[PreeditStartIndex],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                        XNPreeditDoneCallback,  &callbacks[PreeditDoneIndex],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                        XNPreeditDrawCallback,  &callbacks[PreeditDrawIndex],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                        XNPreeditCaretCallback, &callbacks[PreeditCaretIndex],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                        NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        if (preedit == (XVaNestedList)NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            goto err;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
   966
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        /*always try XIMStatusCallbacks for active client...*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            status = (XVaNestedList)XVaCreateNestedList(0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                        XNStatusStartCallback, &callbacks[StatusStartIndex],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                        XNStatusDoneCallback,  &callbacks[StatusDoneIndex],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                        XNStatusDrawCallback, &callbacks[StatusDrawIndex],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                        NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            if (status == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                goto err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            pX11IMData->statusWindow = createStatusWindow(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            pX11IMData->ic_active = XCreateIC(X11im,
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   979
                                              XNClientWindow, w,
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   980
                                              XNFocusWindow, w,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                                              XNInputStyle, active_styles,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                                              XNPreeditAttributes, preedit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                                              XNStatusAttributes, status,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                                              NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            XFree((void *)status);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            XFree((void *)preedit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
   988
#else /* !__linux__ && !MACOSX */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   989
        pX11IMData->ic_active = XCreateIC(X11im,
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   990
                                          XNClientWindow, w,
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   991
                                          XNFocusWindow, w,
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   992
                                          XNInputStyle, active_styles,
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   993
                                          XNPreeditAttributes, preedit,
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
   994
                                          NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        XFree((void *)preedit);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
   996
#endif /* __linux__ || MACOSX */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        pX11IMData->ic_active = XCreateIC(X11im,
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
   999
                                          XNClientWindow, w,
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
  1000
                                          XNFocusWindow, w,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                                          XNInputStyle, active_styles,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                                          NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        pX11IMData->ic_passive = pX11IMData->ic_active;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    if (pX11IMData->ic_active == (XIC)0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        || pX11IMData->ic_passive == (XIC)0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * Use commit string call back if possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * This will ensure the correct order of preedit text and commit text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        XIMCallback cb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        cb.client_data = (XPointer) pX11IMData->x11inputmethod;
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
  1018
        cb.callback = (XIMProc) CommitStringCallback;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        XSetICValues (pX11IMData->ic_active, XNCommitStringCallback, &cb, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        if (pX11IMData->ic_active != pX11IMData->ic_passive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            XSetICValues (pX11IMData->ic_passive, XNCommitStringCallback, &cb, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
54867
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1025
    // The code set the IC mode that the preedit state is not initialied
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1026
    // at XmbResetIC.  This attribute can be set at XCreateIC.  I separately
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1027
    // set the attribute to avoid the failure of XCreateIC at some platform
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1028
    // which does not support the attribute.
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1029
    if (pX11IMData->ic_active != 0)
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1030
        XSetICValues(pX11IMData->ic_active,
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1031
                     XNResetState, XIMInitialState,
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1032
                     NULL);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1033
    if (pX11IMData->ic_passive != 0
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1034
            && pX11IMData->ic_active != pX11IMData->ic_passive)
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1035
        XSetICValues(pX11IMData->ic_passive,
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1036
                     XNResetState, XIMInitialState,
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1037
                     NULL);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1038
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    /* Add the global reference object to X11InputMethod to the list. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    addToX11InputMethodGRefList(pX11IMData->x11inputmethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
54867
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1042
    /* Unset focus to avoid unexpected IM on */
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1043
    setXICFocus(pX11IMData->ic_active, False);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1044
    if (pX11IMData->ic_active != pX11IMData->ic_passive)
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1045
        setXICFocus(pX11IMData->ic_passive, False);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1046
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    return True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
 err:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    if (preedit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        XFree((void *)preedit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    THROW_OUT_OF_MEMORY_ERROR();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
54867
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1056
static int
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
PreeditStartCallback(XIC ic, XPointer client_data, XPointer call_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    /*ARGSUSED*/
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1060
    /* printf("Native: PreeditStartCallback\n"); */
54867
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1061
    return -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
PreeditDoneCallback(XIC ic, XPointer client_data, XPointer call_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    /*ARGSUSED*/
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1068
    /* printf("Native: PreeditDoneCallback\n"); */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
 * Translate the preedit draw callback items to Java values and invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
 * X11InputMethod.dispatchComposedText().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
 * client_data: X11InputMethod object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
PreeditDrawCallback(XIC ic, XPointer client_data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                    XIMPreeditDrawCallbackStruct *pre_draw)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    JNIEnv *env = GetJNIEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
    X11InputMethodData *pX11IMData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    jmethodID x11imMethodID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    XIMText *text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    jstring javastr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    jintArray style = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    /* printf("Native: PreeditDrawCallback() \n"); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    if (pre_draw == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    if (!isX11InputMethodGRefInList((jobject)client_data)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        if ((jobject)client_data == currentX11InputMethodInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            currentX11InputMethodInstance = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        goto finally;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    if ((pX11IMData = getX11InputMethodData(env, (jobject)client_data)) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        goto finally;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    if ((text = pre_draw->text) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        if (text->string.multi_byte != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            if (pre_draw->text->encoding_is_wchar == False) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                javastr = JNU_NewStringPlatform(env, (const char *)text->string.multi_byte);
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 18135
diff changeset
  1108
                if (javastr == NULL) {
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 18135
diff changeset
  1109
                    goto finally;
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 18135
diff changeset
  1110
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                char *mbstr = wcstombsdmp(text->string.wide_char, text->length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                if (mbstr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                    goto finally;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                javastr = JNU_NewStringPlatform(env, (const char *)mbstr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                free(mbstr);
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 18135
diff changeset
  1118
                if (javastr == NULL) {
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 18135
diff changeset
  1119
                    goto finally;
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 18135
diff changeset
  1120
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        if (text->feedback != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            int cnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            jint *tmpstyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            style = (*env)->NewIntArray(env, text->length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            if (JNU_IsNull(env, style)) {
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 18135
diff changeset
  1129
                (*env)->ExceptionClear(env);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                THROW_OUT_OF_MEMORY_ERROR();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                goto finally;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            if (sizeof(XIMFeedback) == sizeof(jint)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                 * Optimization to avoid copying the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                (*env)->SetIntArrayRegion(env, style, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                                          text->length, (jint *)text->feedback);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                tmpstyle  = (jint *)malloc(sizeof(jint)*(text->length));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                if (tmpstyle == (jint *) NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                    THROW_OUT_OF_MEMORY_ERROR();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                    goto finally;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                for (cnt = 0; cnt < (int)text->length; cnt++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                        tmpstyle[cnt] = text->feedback[cnt];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                (*env)->SetIntArrayRegion(env, style, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                                          text->length, (jint *)tmpstyle);
52263
680ab6b53f6f 8211393: Memory leak issue on awt_InputMethod.c
itakiguchi
parents: 50350
diff changeset
  1150
                free(tmpstyle);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    JNU_CallMethodByName(env, NULL, pX11IMData->x11inputmethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                         "dispatchComposedText",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                         "(Ljava/lang/String;[IIIIJ)V",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                         javastr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                         style,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                         (jint)pre_draw->chg_first,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                         (jint)pre_draw->chg_length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                         (jint)pre_draw->caret,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                         awt_util_nowMillisUTC());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
finally:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
PreeditCaretCallback(XIC ic, XPointer client_data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                     XIMPreeditCaretCallbackStruct *pre_caret)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
    /*ARGSUSED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
    /* printf("Native: PreeditCaretCallback\n"); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
  1176
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
StatusStartCallback(XIC ic, XPointer client_data, XPointer call_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    /*ARGSUSED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    /*printf("StatusStartCallback:\n");  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
StatusDoneCallback(XIC ic, XPointer client_data, XPointer call_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    /*ARGSUSED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
    /*printf("StatusDoneCallback:\n"); */
54867
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1189
    JNIEnv *env = GetJNIEnv();
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1190
    X11InputMethodData *pX11IMData = NULL;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1191
    StatusWindow *statusWindow;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1192
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1193
    AWT_LOCK();
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1194
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1195
    if (!isX11InputMethodGRefInList((jobject)client_data)) {
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1196
        if ((jobject)client_data == currentX11InputMethodInstance) {
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1197
            currentX11InputMethodInstance = NULL;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1198
        }
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1199
        goto finally;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1200
    }
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1201
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1202
    if (NULL == (pX11IMData = getX11InputMethodData(env, (jobject)client_data))
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1203
        || NULL == (statusWindow = pX11IMData->statusWindow)){
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1204
        goto finally;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1205
    }
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1206
    currentX11InputMethodInstance = (jobject)client_data;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1207
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1208
    onoffStatusWindow(pX11IMData, 0, False);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1209
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1210
 finally:
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1211
    AWT_UNLOCK();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
StatusDrawCallback(XIC ic, XPointer client_data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                     XIMStatusDrawCallbackStruct *status_draw)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    /*ARGSUSED*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    /*printf("StatusDrawCallback:\n"); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    JNIEnv *env = GetJNIEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    X11InputMethodData *pX11IMData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    StatusWindow *statusWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    if (!isX11InputMethodGRefInList((jobject)client_data)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        if ((jobject)client_data == currentX11InputMethodInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            currentX11InputMethodInstance = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        goto finally;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    if (NULL == (pX11IMData = getX11InputMethodData(env, (jobject)client_data))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        || NULL == (statusWindow = pX11IMData->statusWindow)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        goto finally;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    }
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1237
    currentX11InputMethodInstance = (jobject)client_data;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1239
    if (status_draw->type == XIMTextType) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        XIMText *text = (status_draw->data).text;
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1241
        if (text != NULL) {
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1242
            if (text->string.multi_byte != NULL) {
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1243
                strncpy(statusWindow->status, text->string.multi_byte, MAX_STATUS_LEN);
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1244
                statusWindow->status[MAX_STATUS_LEN - 1] = '\0';
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1245
            } else {
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1246
                char *mbstr = wcstombsdmp(text->string.wide_char, text->length);
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1247
                strncpy(statusWindow->status, mbstr, MAX_STATUS_LEN);
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1248
                statusWindow->status[MAX_STATUS_LEN - 1] = '\0';
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1249
            }
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1250
            statusWindow->on = True;
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1251
            onoffStatusWindow(pX11IMData, statusWindow->parent, True);
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1252
            paintStatusWindow(statusWindow);
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1253
        } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            statusWindow->on = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            /*just turnoff the status window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            paintStatusWindow(statusWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            onoffStatusWindow(pX11IMData, 0, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
 finally:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
}
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
  1265
#endif /* __linux__ || MACOSX */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
static void CommitStringCallback(XIC ic, XPointer client_data, XPointer call_data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    JNIEnv *env = GetJNIEnv();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    XIMText * text = (XIMText *)call_data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    X11InputMethodData *pX11IMData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    jstring javastr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    if (!isX11InputMethodGRefInList((jobject)client_data)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        if ((jobject)client_data == currentX11InputMethodInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
            currentX11InputMethodInstance = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        goto finally;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    if ((pX11IMData = getX11InputMethodData(env, (jobject)client_data)) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        goto finally;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    currentX11InputMethodInstance = (jobject)client_data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
    if (text->encoding_is_wchar == False) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        javastr = JNU_NewStringPlatform(env, (const char *)text->string.multi_byte);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        char *mbstr = wcstombsdmp(text->string.wide_char, text->length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        if (mbstr == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            goto finally;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        javastr = JNU_NewStringPlatform(env, (const char *)mbstr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        free(mbstr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    if (javastr != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        JNU_CallMethodByName(env, NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                                 pX11IMData->x11inputmethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                                 "dispatchCommittedText",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                                 "(Ljava/lang/String;J)V",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                                 javastr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                                 awt_util_nowMillisUTC());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
 finally:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
static void OpenXIMCallback(Display *display, XPointer client_data, XPointer call_data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    XIMCallback ximCallback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    X11im = XOpenIM(display, NULL, NULL, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
    if (X11im == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
    ximCallback.callback = (XIMProc)DestroyXIMCallback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    ximCallback.client_data = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    XSetIMValues(X11im, XNDestroyCallback, &ximCallback, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
static void DestroyXIMCallback(XIM im, XPointer client_data, XPointer call_data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
    /* mark that XIM server was destroyed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
    X11im = NULL;
6658
f7a9cf17fed4 6986968: Crash on XIM server restart
omajid
parents: 5506
diff changeset
  1326
    JNIEnv* env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
52987
468829d1983e 8213183: InputMethod cannot be used after its restarting
tnakamura
parents: 52263
diff changeset
  1327
468829d1983e 8213183: InputMethod cannot be used after its restarting
tnakamura
parents: 52263
diff changeset
  1328
    AWT_LOCK();
6658
f7a9cf17fed4 6986968: Crash on XIM server restart
omajid
parents: 5506
diff changeset
  1329
    /* free the old pX11IMData and set it to null. this also avoids crashing
f7a9cf17fed4 6986968: Crash on XIM server restart
omajid
parents: 5506
diff changeset
  1330
     * the jvm if the XIM server reappears */
52987
468829d1983e 8213183: InputMethod cannot be used after its restarting
tnakamura
parents: 52263
diff changeset
  1331
    while (x11InputMethodGRefListHead != NULL) {
55245
e2987b9baa93 8225182: JNI exception pending in DestroyXIMCallback of awt_InputMethod.c:1327
naoto
parents: 54867
diff changeset
  1332
        if (getX11InputMethodData(env,
e2987b9baa93 8225182: JNI exception pending in DestroyXIMCallback of awt_InputMethod.c:1327
naoto
parents: 54867
diff changeset
  1333
                x11InputMethodGRefListHead->inputMethodGRef) == NULL) {
e2987b9baa93 8225182: JNI exception pending in DestroyXIMCallback of awt_InputMethod.c:1327
naoto
parents: 54867
diff changeset
  1334
            /* Clear possible exceptions
e2987b9baa93 8225182: JNI exception pending in DestroyXIMCallback of awt_InputMethod.c:1327
naoto
parents: 54867
diff changeset
  1335
             */
e2987b9baa93 8225182: JNI exception pending in DestroyXIMCallback of awt_InputMethod.c:1327
naoto
parents: 54867
diff changeset
  1336
            if ((*env)->ExceptionOccurred(env)) {
e2987b9baa93 8225182: JNI exception pending in DestroyXIMCallback of awt_InputMethod.c:1327
naoto
parents: 54867
diff changeset
  1337
                (*env)->ExceptionDescribe(env);
e2987b9baa93 8225182: JNI exception pending in DestroyXIMCallback of awt_InputMethod.c:1327
naoto
parents: 54867
diff changeset
  1338
                (*env)->ExceptionClear(env);
e2987b9baa93 8225182: JNI exception pending in DestroyXIMCallback of awt_InputMethod.c:1327
naoto
parents: 54867
diff changeset
  1339
            }
e2987b9baa93 8225182: JNI exception pending in DestroyXIMCallback of awt_InputMethod.c:1327
naoto
parents: 54867
diff changeset
  1340
        }
52987
468829d1983e 8213183: InputMethod cannot be used after its restarting
tnakamura
parents: 52263
diff changeset
  1341
    }
468829d1983e 8213183: InputMethod cannot be used after its restarting
tnakamura
parents: 52263
diff changeset
  1342
    AWT_UNLOCK();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
Java_sun_awt_X11_XInputMethod_openXIMNative(JNIEnv *env,
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1347
                                            jobject this,
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1348
                                            jlong display)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    Bool registered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
  1354
    dpy = (Display *)jlong_to_ptr(display);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
/* Use IMInstantiate call back only on Linux, as there is a bug in Solaris
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
   (4768335)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
*/
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
  1359
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    registered = XRegisterIMInstantiateCallback(dpy, NULL, NULL,
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
  1361
                     NULL, (XIDProc)OpenXIMCallback, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
    if (!registered) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        /* directly call openXIM callback */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        OpenXIMCallback(dpy, NULL, NULL);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
  1366
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
Java_sun_awt_X11_XInputMethod_createXICNative(JNIEnv *env,
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1377
                                              jobject this,
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1378
                                              jlong window)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
    X11InputMethodData *pX11IMData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
    jobject globalRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
    XIC ic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
  1386
    if (!window) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        JNU_ThrowNullPointerException(env, "NullPointerException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
    pX11IMData = (X11InputMethodData *) calloc(1, sizeof(X11InputMethodData));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    if (pX11IMData == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        THROW_OUT_OF_MEMORY_ERROR();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
    globalRef = (*env)->NewGlobalRef(env, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
    pX11IMData->x11inputmethod = globalRef;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
  1401
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    pX11IMData->statusWindow = NULL;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
  1403
#endif /* __linux__ || MACOSX */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
    pX11IMData->lookup_buf = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
    pX11IMData->lookup_buf_len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 18135
diff changeset
  1408
    if (createXIC(env, pX11IMData, (Window)window) == False) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        destroyX11InputMethodData((JNIEnv *) NULL, pX11IMData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        pX11IMData = (X11InputMethodData *) NULL;
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 18135
diff changeset
  1411
        if ((*env)->ExceptionCheck(env)) {
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 18135
diff changeset
  1412
            goto finally;
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 18135
diff changeset
  1413
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
    setX11InputMethodData(env, this, pX11IMData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
24130
db72fc72f87b 8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents: 18135
diff changeset
  1418
finally:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    return (pX11IMData != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
Java_sun_awt_X11_XInputMethod_setXICFocusNative(JNIEnv *env,
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1425
                                                jobject this,
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1426
                                                jlong w,
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1427
                                                jboolean req,
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1428
                                                jboolean active)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
    X11InputMethodData *pX11IMData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
    pX11IMData = getX11InputMethodData(env, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
    if (pX11IMData == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
    if (req) {
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
  1439
        if (!w) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
            AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
        pX11IMData->current_ic = active ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                        pX11IMData->ic_active : pX11IMData->ic_passive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
         * On Solaris2.6, setXICWindowFocus() has to be invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
         * before setting focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
         */
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
  1449
        setXICWindowFocus(pX11IMData->current_ic, w);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        setXICFocus(pX11IMData->current_ic, req);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        currentX11InputMethodInstance = pX11IMData->x11inputmethod;
6825
795e9fe949d3 6989721: awt native code compiler warnings
art
parents: 5506
diff changeset
  1452
        currentFocusWindow =  w;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
  1453
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        if (active && pX11IMData->statusWindow && pX11IMData->statusWindow->on)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
            onoffStatusWindow(pX11IMData, w, True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        currentX11InputMethodInstance = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
        currentFocusWindow = 0;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
  1460
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        onoffStatusWindow(pX11IMData, 0, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        if (pX11IMData->current_ic != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        setXICFocus(pX11IMData->current_ic, req);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        pX11IMData->current_ic = (XIC)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
    XFlush(dpy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1473
/*
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1474
 * Class:     sun_awt_X11InputMethodBase
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1475
 * Method:    initIDs
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1476
 * Signature: ()V
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1477
 * This function gets called from the static initializer for
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1478
 * X11InputMethod.java to initialize the fieldIDs for fields
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1479
 * that may be accessed from C
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1480
 */
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1481
JNIEXPORT void JNICALL Java_sun_awt_X11InputMethodBase_initIDs
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1482
  (JNIEnv *env, jclass cls)
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1483
{
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1484
    x11InputMethodIDs.pData = (*env)->GetFieldID(env, cls, "pData", "J");
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1485
}
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1486
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1487
/*
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1488
 * Class:     sun_awt_X11InputMethodBase
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1489
 * Method:    turnoffStatusWindow
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1490
 * Signature: ()V
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1491
 */
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1492
JNIEXPORT void JNICALL Java_sun_awt_X11InputMethodBase_turnoffStatusWindow
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1493
  (JNIEnv *env, jobject this)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
{
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
  1495
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
    X11InputMethodData *pX11IMData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
    StatusWindow *statusWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
    if (NULL == currentX11InputMethodInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        || !isX11InputMethodGRefInList(currentX11InputMethodInstance)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        || NULL == (pX11IMData = getX11InputMethodData(env,currentX11InputMethodInstance))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        || NULL == (statusWindow = pX11IMData->statusWindow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
        || !statusWindow->on ){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
    onoffStatusWindow(pX11IMData, 0, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1515
/*
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1516
 * Class:     sun_awt_X11InputMethodBase
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1517
 * Method:    disposeXIC
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1518
 * Signature: ()V
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1519
 */
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1520
JNIEXPORT void JNICALL Java_sun_awt_X11InputMethodBase_disposeXIC
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1521
  (JNIEnv *env, jobject this)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
    X11InputMethodData *pX11IMData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
    pX11IMData = getX11InputMethodData(env, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
    if (pX11IMData == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
    setX11InputMethodData(env, this, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
    if (pX11IMData->x11inputmethod == currentX11InputMethodInstance) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
        currentX11InputMethodInstance = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        currentFocusWindow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
    destroyX11InputMethodData(env, pX11IMData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1542
/*
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1543
 * Class:     sun_awt_X11InputMethodBase
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1544
 * Method:    resetXIC
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1545
 * Signature: ()Ljava/lang/String;
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1546
 */
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1547
JNIEXPORT jstring JNICALL Java_sun_awt_X11InputMethodBase_resetXIC
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1548
  (JNIEnv *env, jobject this)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
    X11InputMethodData *pX11IMData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
    char *xText = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
    jstring jText = (jstring)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
    pX11IMData = getX11InputMethodData(env, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
    if (pX11IMData == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        return jText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
    if (pX11IMData->current_ic)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
        xText = XmbResetIC(pX11IMData->current_ic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
         * If there is no reference to the current XIC, try to reset both XICs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        xText = XmbResetIC(pX11IMData->ic_active);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
        /*it may also means that the real client component does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
          not have focus -- has been deactivated... its xic should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
          not have the focus, bug#4284651 showes reset XIC for htt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
          may bring the focus back, so de-focus it again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
        setXICFocus(pX11IMData->ic_active, FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
        if (pX11IMData->ic_active != pX11IMData->ic_passive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
            char *tmpText = XmbResetIC(pX11IMData->ic_passive);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
            setXICFocus(pX11IMData->ic_passive, FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
            if (xText == (char *)NULL && tmpText)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                xText = tmpText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
    if (xText != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
        jText = JNU_NewStringPlatform(env, (const char *)xText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
        XFree((void *)xText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
    return jText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
/*
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1592
 * Class:     sun_awt_X11InputMethodBase
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
 * Method:    setCompositionEnabledNative
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1594
 * Signature: (Z)Z
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
 * This method tries to set the XNPreeditState attribute associated with the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
 * XIC to the passed in 'enable' state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
 * Return JNI_TRUE if XNPreeditState attribute is successfully changed to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
 * 'enable' state; Otherwise, if XSetICValues fails to set this attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
 * java.lang.UnsupportedOperationException will be thrown. JNI_FALSE is returned if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
 * method fails due to other reasons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
 */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1604
JNIEXPORT jboolean JNICALL Java_sun_awt_X11InputMethodBase_setCompositionEnabledNative
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
  (JNIEnv *env, jobject this, jboolean enable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
    X11InputMethodData *pX11IMData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
    char * ret = NULL;
54867
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1609
    XVaNestedList   pr_atrb;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1610
#if defined(__linux__) || defined(MACOSX)
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1611
    Boolean calledXSetICFocus = False;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1612
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
    pX11IMData = getX11InputMethodData(env, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
    if ((pX11IMData == NULL) || (pX11IMData->current_ic == NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
54867
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1622
#if defined(__linux__) || defined(MACOSX)
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1623
    if (NULL != pX11IMData->statusWindow) {
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1624
        Window focus = 0;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1625
        int revert_to;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1626
#if defined(_LP64) && !defined(_LITTLE_ENDIAN)
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1627
        // The Window value which is used for XGetICValues must be 32bit on BigEndian XOrg's xlib
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1628
        unsigned int w = 0;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1629
#else
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1630
        Window w = 0;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1631
#endif
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1632
        XGetInputFocus(awt_display, &focus, &revert_to);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1633
        XGetICValues(pX11IMData->current_ic, XNFocusWindow, &w, NULL);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1634
        if (RevertToPointerRoot == revert_to
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1635
                && pX11IMData->ic_active != pX11IMData->ic_passive) {
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1636
            if (pX11IMData->current_ic == pX11IMData->ic_active) {
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1637
                if (getParentWindow(focus) == getParentWindow(w)) {
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1638
                    XUnsetICFocus(pX11IMData->ic_active);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1639
                    calledXSetICFocus = True;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1640
                }
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1641
            }
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1642
        }
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1643
    }
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1644
#endif
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1645
    pr_atrb = XVaCreateNestedList(0,
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1646
                  XNPreeditState, (enable ? XIMPreeditEnable : XIMPreeditDisable),
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1647
                  NULL);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1648
    ret = XSetICValues(pX11IMData->current_ic, XNPreeditAttributes, pr_atrb, NULL);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1649
    XFree((void *)pr_atrb);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1650
#if defined(__linux__) || defined(MACOSX)
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1651
    if (calledXSetICFocus) {
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1652
        XSetICFocus(pX11IMData->ic_active);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1653
    }
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1654
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
54867
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1657
    if ((ret != 0)
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1658
            && ((strcmp(ret, XNPreeditAttributes) == 0)
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1659
            || (strcmp(ret, XNPreeditState) == 0))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
    return (jboolean)(ret == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
/*
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1667
 * Class:     sun_awt_X11InputMethodBase
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
 * Method:    isCompositionEnabledNative
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1669
 * Signature: ()Z
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
 * This method tries to get the XNPreeditState attribute associated with the current XIC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
 * Return JNI_TRUE if the XNPreeditState is successfully retrieved. Otherwise, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
 * XGetICValues fails to get this attribute, java.lang.UnsupportedOperationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
 * will be thrown. JNI_FALSE is returned if this method fails due to other reasons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
 */
50350
668463f93ec0 8201429: Support AIX Input Method Editor (IME) for AWT Input Method Framework (IMF)
clanger
parents: 47216
diff changeset
  1677
JNIEXPORT jboolean JNICALL Java_sun_awt_X11InputMethodBase_isCompositionEnabledNative
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
  (JNIEnv *env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
    X11InputMethodData *pX11IMData = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
    char * ret = NULL;
57643
5dae3de0e04b 8227919: 8213232 causes crashes on solaris sparc64
itakiguchi
parents: 55245
diff changeset
  1682
#if defined(__linux__) && defined(_LP64) && !defined(_LITTLE_ENDIAN)
54867
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1683
    // XIMPreeditState value which is used for XGetICValues must be 32bit on BigEndian XOrg's xlib
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1684
    unsigned int state = XIMPreeditUnKnown;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1685
#else
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1686
    XIMPreeditState state = XIMPreeditUnKnown;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1687
#endif
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1688
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1689
    XVaNestedList   pr_atrb;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
    pX11IMData = getX11InputMethodData(env, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
    if ((pX11IMData == NULL) || (pX11IMData->current_ic == NULL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
54867
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1699
    pr_atrb = XVaCreateNestedList(0, XNPreeditState, &state, NULL);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1700
    ret = XGetICValues(pX11IMData->current_ic, XNPreeditAttributes, pr_atrb, NULL);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1701
    XFree((void *)pr_atrb);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
54867
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1704
    if ((ret != 0)
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1705
            && ((strcmp(ret, XNPreeditAttributes) == 0)
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1706
            || (strcmp(ret, XNPreeditState) == 0))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
    return (jboolean)(state == XIMPreeditEnable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
JNIEXPORT void JNICALL Java_sun_awt_X11_XInputMethod_adjustStatusWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
  (JNIEnv *env, jobject this, jlong window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
{
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11093
diff changeset
  1717
#if defined(__linux__) || defined(MACOSX)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
    adjustStatusWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
}
54867
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1723
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1724
#if defined(__linux__) || defined(MACOSX)
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1725
static Window getParentWindow(Window w)
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1726
{
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1727
    Window root=None, parent=None, *ignore_children=NULL;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1728
    unsigned int ignore_uint=0;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1729
    Status status = 0;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1730
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1731
    if (w == None)
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1732
        return None;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1733
    status = XQueryTree(dpy, w, &root, &parent, &ignore_children, &ignore_uint);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1734
    XFree(ignore_children);
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1735
    if (status == 0)
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1736
        return None;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1737
    return parent;
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1738
}
65297f60ba19 8213232: Unix/X11 setCompositionEnableNative issue
itakiguchi
parents: 53678
diff changeset
  1739
#endif