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