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