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