70
|
1 /* Various functions for X11R5+ input methods, using the Xlib interface.
|
|
2 Copyright (C) 1996 Sun Microsystems.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs 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 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: Not in FSF. */
|
|
22
|
|
23 /* Written by Martin Buchholz. */
|
|
24
|
|
25 /* This file implements an interface to X input methods, available
|
|
26 with X11R5 and above. See O'Reilly, Xlib programmer's guide,
|
|
27 and X11 R6 release guide chapters on internationalized input,
|
|
28 for further details */
|
|
29
|
|
30 #include <X11/Xlocale.h> /* More portable than <locale.h> ? */
|
|
31 #include <config.h>
|
|
32 #include "lisp.h"
|
|
33 #include "frame.h"
|
|
34 #include "device.h"
|
|
35 #include "window.h"
|
|
36 #include "buffer.h"
|
|
37 #include "console-x.h"
|
|
38 #include "EmacsFrame.h"
|
|
39 #include "events.h"
|
|
40
|
|
41 #ifndef XIM_XLIB
|
|
42 #error XIM_XLIB is not defined??
|
|
43 #endif
|
|
44
|
|
45 /* Get/Set IC values for just one attribute */
|
|
46 #ifdef DEBUG_XEMACS
|
|
47 #define XIC_Value(Get_Set, xic, name, attr, value) \
|
|
48 do { \
|
|
49 char *bad_arg; \
|
|
50 XVaNestedList list = XVaCreateNestedList (0, attr, value, NULL); \
|
|
51 if ((bad_arg = X##Get_Set##ICValues (xic, name, list, NULL)) != NULL) \
|
|
52 stderr_out ("X" #Get_Set "ICValues " "bad Arg: %s\n", bad_arg); \
|
|
53 XFree (list); \
|
|
54 } while (0)
|
|
55 #else /* ! DEBUG_XEMACS */
|
|
56 #define XIC_Value(Get_Set, xic, name, attr, value) \
|
|
57 do { \
|
|
58 XVaNestedList list = XVaCreateNestedList (0, attr, value, NULL); \
|
|
59 X##Get_Set##ICValues (xic, name, list, NULL); \
|
|
60 XFree (list); \
|
|
61 } while (0)
|
|
62 #endif /* DEBUG_XEMACS */
|
|
63
|
|
64 static char DefaultXIMStyles[] =
|
|
65 "XIMPreeditPosition|XIMStatusArea\n"
|
|
66 "XIMPreeditPosition|XIMStatusNone\n"
|
|
67 "XIMPreeditPosition|XIMStatusNothing\n"
|
|
68 "XIMPreeditNothing|XIMStatusArea\n"
|
|
69 "XIMPreeditNothing|XIMStatusNothing\n"
|
|
70 "XIMPreeditNothing|XIMStatusNone\n"
|
|
71 "XIMPreeditNone|XIMStatusArea\n"
|
|
72 "XIMPreeditNone|XIMStatusNothing\n"
|
|
73 "XIMPreeditNone|XIMStatusNone";
|
|
74
|
|
75 static XIMStyle best_style (XIMStyles *user, XIMStyles *xim);
|
|
76
|
|
77 void
|
|
78 Initialize_Locale (void)
|
|
79 {
|
|
80 char *locale;
|
|
81
|
|
82 XtSetLanguageProc (NULL, (XtLanguageProc) NULL, NULL);
|
|
83 if ((locale = setlocale (LC_ALL, "")) == NULL)
|
|
84 {
|
|
85 stderr_out ("Can't set locale.\n");
|
|
86 stderr_out ("Using C locale instead.\n");
|
|
87 putenv ("LANG=C");
|
|
88 putenv ("LC_ALL=C");
|
|
89 if ((locale = setlocale (LC_ALL, "C")) == NULL)
|
|
90 {
|
|
91 stderr_out ("Can't even set locale to `C'!\n");
|
|
92 return;
|
|
93 }
|
|
94 }
|
|
95
|
|
96 if (!XSupportsLocale ())
|
|
97 {
|
|
98 stderr_out ("X Windows does not support locale `%s'\n", locale);
|
|
99 stderr_out ("Using C Locale instead\n");
|
|
100 putenv ("LANG=C");
|
|
101 putenv ("LC_ALL=C");
|
|
102 if ((locale = setlocale (LC_ALL, "C")) == NULL)
|
|
103 {
|
|
104 stderr_out ("Can't even set locale to `C'!\n");
|
|
105 return;
|
|
106 }
|
|
107 if (!XSupportsLocale ())
|
|
108 {
|
|
109 stderr_out ("X Windows does not even support locale `C'!\n");
|
|
110 return;
|
|
111 }
|
|
112 }
|
|
113
|
|
114 if (XSetLocaleModifiers ("") == NULL)
|
|
115 {
|
|
116 stderr_out ("XSetLocaleModifiers(\"\") failed\n");
|
|
117 stderr_out ("Check the value of the XMODIFIERS environment variable.\n");
|
|
118 }
|
|
119 }
|
|
120
|
|
121 /* Create X input method for device */
|
|
122 void
|
|
123 XIM_init_device (struct device *d)
|
|
124 {
|
|
125 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
126 char *name, *class;
|
|
127 XIM xim;
|
|
128
|
|
129 XtGetApplicationNameAndClass (dpy, &name, &class);
|
|
130
|
|
131 DEVICE_X_XIM (d) = xim = XOpenIM (dpy, XtDatabase (dpy), name, class);
|
|
132
|
|
133 if (xim == NULL)
|
|
134 {
|
|
135 stderr_out ("Warning: XOpenIM() failed...no input server available\n");
|
|
136 return;
|
|
137 }
|
|
138 else
|
|
139 {
|
|
140 /* Get supported styles */
|
|
141 XGetIMValues (xim, XNQueryInputStyle, &DEVICE_X_XIM_STYLES (d), NULL);
|
|
142 #ifdef DEBUG_XIM
|
|
143 describe_XIM (xim);
|
|
144 #endif
|
|
145 }
|
|
146 }
|
|
147
|
|
148 /* Create an X input context for this frame. */
|
|
149 void
|
|
150 XIM_init_frame (struct frame *f)
|
|
151 {
|
|
152 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
153 XIM xim = DEVICE_X_XIM (d);
|
|
154 XIC xic;
|
|
155 Widget w = FRAME_X_TEXT_WIDGET (f);
|
|
156 Window win = XtWindow (w);
|
179
|
157 XRectangle p_area = {0,0,1,1}, s_area={0,0,1,1};
|
70
|
158 XPoint spot = {0,0};
|
|
159 XIMStyle style;
|
|
160 XVaNestedList p_list, s_list;
|
|
161
|
|
162 typedef struct
|
|
163 {
|
|
164 XIMStyles styles;
|
|
165 XFontSet fontset;
|
|
166 Pixel fg;
|
|
167 Pixel bg;
|
|
168 } xic_vars_t;
|
|
169
|
|
170 xic_vars_t xic_vars;
|
|
171
|
|
172 /* mrb: #### Fix so that background and foreground is set from
|
|
173 default face, rather than foreground and background resources, or
|
|
174 that the user can use set-frame-parameters to set xic attributes */
|
|
175
|
|
176 #define res(name, class, representation, field, default_value) \
|
|
177 { name, class, representation, sizeof(xic_vars.field), \
|
|
178 XtOffsetOf(xic_vars_t, field), XtRString, default_value }
|
|
179
|
|
180 static XtResource resources[] =
|
|
181 {
|
|
182 /* name class represent'n field default value */
|
|
183 res(XtNximStyles, XtCXimStyles, XtRXimStyles, styles, DefaultXIMStyles),
|
|
184 res(XtNfontSet, XtCFontSet, XtRFontSet, fontset, XtDefaultFontSet),
|
|
185 res(XtNximForeground, XtCForeground, XtRPixel, fg, XtDefaultForeground),
|
|
186 res(XtNximBackground, XtCBackground, XtRPixel, bg, XtDefaultBackground)
|
|
187 };
|
|
188
|
|
189 assert (win != 0 && w != NULL && d != NULL);
|
|
190
|
|
191 if (!xim)
|
|
192 { /* No input method? */
|
|
193 FRAME_X_XIC (f) = NULL;
|
|
194 return;
|
|
195 }
|
|
196
|
|
197 XtGetApplicationResources (w, &xic_vars,
|
|
198 resources, XtNumber (resources),
|
|
199 NULL, 0);
|
|
200
|
|
201 if (!xic_vars.fontset)
|
|
202 {
|
|
203 stderr_out ("Can't get fontset resource for Input Method\n");
|
|
204 FRAME_X_XIC (f) = NULL;
|
|
205 return;
|
|
206 }
|
|
207
|
|
208 FRAME_X_XIC_STYLE (f) = style =
|
|
209 best_style (&xic_vars.styles, DEVICE_X_XIM_STYLES (d));
|
|
210
|
|
211 /* Hopefully we don't have to conditionalize the following based on
|
|
212 style; the IM should ignore values it doesn't use */
|
|
213 p_list = XVaCreateNestedList (0,
|
|
214 XNArea, &p_area,
|
|
215 XNSpotLocation, &spot,
|
|
216 XNForeground, xic_vars.fg,
|
|
217 XNBackground, xic_vars.bg,
|
|
218 XNFontSet, xic_vars.fontset,
|
|
219 NULL);
|
|
220
|
|
221 s_list = XVaCreateNestedList (0,
|
|
222 XNArea, &s_area,
|
|
223 XNForeground, xic_vars.fg,
|
|
224 XNBackground, xic_vars.bg,
|
|
225 XNFontSet, xic_vars.fontset,
|
|
226 NULL);
|
|
227 FRAME_X_XIC (f) = xic =
|
|
228 XCreateIC (xim,
|
|
229 XNInputStyle, style,
|
|
230 XNClientWindow, win,
|
|
231 XNFocusWindow, win,
|
|
232 XNPreeditAttributes, p_list,
|
|
233 XNStatusAttributes, s_list,
|
|
234 NULL);
|
|
235 XFree (p_list);
|
|
236 XFree (s_list);
|
|
237
|
|
238 if (!xic)
|
|
239 {
|
|
240 stderr_out ("Warning: XCreateIC failed\n");
|
|
241 return;
|
|
242 }
|
|
243
|
|
244 if (style & XIMPreeditPosition)
|
|
245 { /* Init spot to invalid values */
|
|
246 XPoint *spot = &(FRAME_X_XIC_SPOT (f));
|
|
247 spot->x = spot->y = -1;
|
|
248 }
|
|
249
|
|
250 XIM_SetGeometry (f);
|
|
251
|
|
252 XSetICFocus (xic);
|
|
253
|
|
254 #ifdef DEBUG_XIM
|
|
255 describe_XIC (xic);
|
|
256 #endif
|
|
257 }
|
|
258
|
|
259 void
|
|
260 XIM_SetGeometry (struct frame *f)
|
|
261 {
|
|
262 XIC xic = FRAME_X_XIC (f);
|
|
263 XIMStyle style = FRAME_X_XIC_STYLE (f);
|
|
264 XRectangle area;
|
|
265
|
|
266 if (!xic || !f)
|
|
267 return;
|
|
268
|
|
269 if (style & XIMStatusArea)
|
|
270 {
|
|
271 /* Place Status Area in bottom right corner */
|
|
272 /* Negotiate geometry of status area */
|
|
273 /* See O'Reilly Xlib XIM chapter (but beware, it's buggy) */
|
|
274 XRectangle *needed;
|
|
275
|
|
276 /* If input method has existing status area, use its current size */
|
|
277 /* The following at least works for Sun's htt */
|
|
278 area.x = area.y = area.width = area.height = 0;
|
|
279 XIC_Value (Set, xic, XNStatusAttributes, XNAreaNeeded, &area);
|
|
280 XIC_Value (Get, xic, XNStatusAttributes, XNAreaNeeded, &needed);
|
|
281 if (needed->width == 0) /* Use XNArea instead of XNAreaNeeded */
|
|
282 XIC_Value (Get, xic, XNStatusAttributes, XNArea, &needed);
|
|
283
|
|
284 area.width = needed->width;
|
|
285 area.height = needed->height;
|
|
286 area.x = FRAME_RIGHT_BORDER_START (f) - area.width;
|
|
287 area.y = FRAME_BOTTOM_BORDER_START (f) - area.height;
|
|
288
|
|
289 #ifdef DEBUG_XIM
|
|
290 stderr_out ("Putting StatusArea in x=%d y=%d w=%d h=%d\n",
|
|
291 area.x, area.y, area.width, area.height);
|
|
292 #endif /* DEBUG_XIM */
|
|
293
|
|
294 XIC_Value (Set, xic, XNStatusAttributes, XNArea, &area);
|
|
295 }
|
|
296
|
|
297 if (style & XIMPreeditPosition)
|
|
298 {
|
|
299 /* Set Preedit Area to whole frame size (sans border) */
|
|
300 /* We include the border because Preedit window might be larger
|
|
301 than display line at edge. #### FIX: we should adjust to make
|
|
302 sure that there is always room for the spot sub-window */
|
|
303 area.x = FRAME_LEFT_BORDER_START (f);
|
|
304 area.y = FRAME_TOP_BORDER_START (f);
|
|
305 area.width = FRAME_RIGHT_BORDER_END (f) - area.x;
|
|
306 area.height = FRAME_BOTTOM_BORDER_END (f) - area.y;
|
|
307 XIC_Value(Set, xic, XNPreeditAttributes, XNArea, &area);
|
|
308 }
|
|
309
|
|
310 #ifdef DEBUG_XIM
|
|
311 describe_XIC (xic);
|
|
312 #endif
|
|
313 }
|
|
314
|
|
315 void
|
|
316 XIM_SetSpotLocation (struct frame *f, int x, int y)
|
|
317 {
|
|
318 XIC xic = FRAME_X_XIC (f);
|
|
319 XPoint *spot = &(FRAME_X_XIC_SPOT (f));
|
|
320
|
|
321 /* Only care if we have a valid XIC using Over the Spot in
|
|
322 * a different location */
|
|
323 if (!xic ||
|
|
324 !(FRAME_X_XIC_STYLE (f) & XIMPreeditPosition) ||
|
|
325 (spot->x == (short) x &&
|
|
326 spot->y == (short) y))
|
|
327 return;
|
|
328
|
|
329 spot->x = (short) x;
|
|
330 spot->y = (short) y;
|
|
331
|
|
332 /* ### FIX: Must make sure spot fits within Preedit Area */
|
|
333 XIC_Value (Set, xic, XNPreeditAttributes, XNSpotLocation, spot);
|
|
334 #ifdef DEBUG_XIM
|
|
335 stderr_out ("Spot: %d %d\n", spot->x, spot->y);
|
|
336 #endif
|
|
337 }
|
|
338
|
|
339 void
|
|
340 XIM_focus_event (struct frame *f, int in_p)
|
|
341 {
|
|
342 if (FRAME_X_XIC (f))
|
|
343 (in_p ? XSetICFocus : XUnsetICFocus) (FRAME_X_XIC (f));
|
|
344 }
|
|
345
|
|
346 #if 0
|
|
347 #define XIM_Composed_Text_BUFSIZE 64
|
|
348 typedef struct XIM_Composed_Text
|
|
349 {
|
|
350 int size;
|
|
351 wchar_t data [XIM_Composed_Text_BUFSIZE];
|
|
352 } XIM_Composed_Text;
|
|
353
|
|
354 static XIM_Composed_Text composed_input_buf = {XIM_Composed_Text_BUFSIZE, {0}};
|
|
355 Window main_window;
|
|
356
|
|
357 /* get_XIM_input -- Process results of input method composition.
|
|
358
|
|
359 This function copies the results of the input method composition to
|
|
360 composed_input_buf. Then for each character, a custom event of type
|
|
361 wc_atom is sent with the character as its data.
|
|
362
|
|
363 It is probably more efficient to copy the composition results to some
|
|
364 allocated memory and send a single event pointing to that memory.
|
|
365 That would cut down on the event processing as well as allow quick
|
|
366 insertion into the buffer of the whole string. It might require some
|
|
367 care, though, to avoid fragmenting memory through the allocation and
|
|
368 freeing of many small chunks. Maybe the existing system for
|
|
369 (single-byte) string allocation can be used, multiplying the length by
|
|
370 sizeof (wchar_t) to get the right size.
|
|
371 */
|
|
372 void
|
|
373 get_XIM_input (XKeyPressedEvent *x_key_event, XIC ic, Display *dpy)
|
|
374 {
|
|
375 KeySym keysym;
|
|
376 Status status;
|
|
377 int len;
|
|
378 int i;
|
|
379 XClientMessageEvent new_event;
|
|
380
|
|
381 try_again:
|
|
382 len = XwcLookupString (ic, x_key_event, composed_input_buf.data,
|
|
383 composed_input_buf.size, &keysym, &status);
|
|
384 switch (status)
|
|
385 {
|
|
386 case XBufferOverflow:
|
|
387 /* GROW_WC_STRING (&composed_input_buf, 32); mrb */
|
|
388 goto try_again;
|
|
389 case XLookupChars:
|
|
390 break;
|
|
391 default:
|
|
392 abort ();
|
|
393 }
|
|
394
|
|
395 new_event.type = ClientMessage;
|
|
396 new_event.display = x_key_event->display;
|
|
397 new_event.window = x_key_event->window;
|
|
398 new_event.message_type = wc_atom;
|
|
399 new_event.format = 32; /* 32-bit wide data */
|
|
400 new_event.data.l[2] = new_event.data.l[3] = new_event.data.l[4] = 0L;
|
|
401 new_event.data.l[0] = x_key_event->time;
|
|
402 for (i = 0; i < len; i++)
|
|
403 {
|
|
404 new_event.data.l[1] = ((wchar_t *) composed_input_buf.data)[i];
|
|
405 XSendEvent (display, main_window, False, 0L, (XEvent *) &new_event);
|
|
406 }
|
|
407 }
|
|
408 #endif /* 0 */
|
|
409
|
|
410 /* ============================================================== */
|
|
411 /* X input method style determination */
|
|
412 /* ============================================================== */
|
|
413
|
|
414 #if 0
|
|
415 #define done(type, value) \
|
|
416 if (toVal->addr != NULL) { \
|
|
417 if (toVal->size < sizeof(type)) { \
|
|
418 toVal->size = sizeof(type); \
|
|
419 return False; \
|
|
420 } \
|
|
421 *(type*)toVal->addr = (value); \
|
|
422 } else { \
|
|
423 static type static_val; \
|
|
424 static_val = (value); \
|
|
425 toVal->addr = (XPointer)&static_val; \
|
|
426 } \
|
|
427 toVal->size = sizeof(type); \
|
|
428 return True /* Caller supplies `;' */
|
|
429 #endif /* 0 */
|
|
430
|
|
431 /*
|
|
432 * This is a standard Xt type converter, except that the caller MUST
|
|
433 * supply a proper non-NULL toVal XIMStyles structure that we will
|
|
434 * fill in.
|
|
435 *
|
|
436 * fromVal points to a string like
|
|
437 *
|
|
438 "XIMPreeditPosition|XIMStatusArea,
|
|
439 XIMPreeditPosition|XIMStatusNothing
|
|
440 XIMPreeditNothing|XIMStatusNothing"
|
|
441 *
|
|
442 * This is converted in the obvious way to a XIMStyles structure.
|
|
443 *
|
|
444 * mrb: #### Fix this to handle Motif-style specifications for
|
|
445 * XIMStyles as well: overTheSpot, rootWindow, none */
|
|
446
|
|
447 /* XtTypeConverter */
|
|
448 Boolean
|
|
449 EmacsXtCvtStringToXIMStyles (
|
|
450 Display *dpy,
|
|
451 XrmValuePtr args,
|
|
452 Cardinal *num_args,
|
|
453 XrmValuePtr fromVal,
|
|
454 XrmValuePtr toVal,
|
|
455 XtPointer *converter_data)
|
|
456 {
|
|
457 #define STYLE_INFO(style) { style, #style, sizeof(#style) }
|
|
458 static struct XIMStyleInfo
|
|
459 {
|
|
460 CONST XIMStyle style;
|
|
461 CONST char * CONST name;
|
|
462 CONST int namelen;
|
|
463 } emacs_XIMStyleInfo[] = {
|
|
464 STYLE_INFO (XIMPreeditPosition|XIMStatusArea),
|
|
465 STYLE_INFO (XIMPreeditPosition|XIMStatusNothing),
|
|
466 STYLE_INFO (XIMPreeditPosition|XIMStatusNone),
|
|
467 STYLE_INFO (XIMPreeditNothing|XIMStatusArea),
|
|
468 STYLE_INFO (XIMPreeditNothing|XIMStatusNothing),
|
|
469 STYLE_INFO (XIMPreeditNothing|XIMStatusNone),
|
|
470 STYLE_INFO (XIMPreeditNone|XIMStatusArea),
|
|
471 STYLE_INFO (XIMPreeditNone|XIMStatusNothing),
|
|
472 STYLE_INFO (XIMPreeditNone|XIMStatusNone)
|
|
473 };
|
|
474 #undef STYLE_INFO
|
|
475
|
|
476 CONST char *s = (char *) fromVal->addr;
|
|
477 CONST char *end = s + fromVal->size;
|
|
478 XIMStyles * CONST p = (XIMStyles *) toVal->addr;
|
|
479 CONST char * CONST delimiter = " \t\n\r:;," ;
|
|
480 CONST int max_styles = XtNumber(emacs_XIMStyleInfo);
|
|
481 int i;
|
|
482 char *c;
|
|
483
|
|
484 #ifdef DEBUG_XIM
|
|
485 stderr_out ("EmacsCvtStringToXIMStyles called with size=%d, string=\"%s\"\n",
|
|
486 fromVal->size, (char *) fromVal->addr);
|
|
487 #endif /* DEBUG_XIM */
|
|
488
|
|
489 if (*num_args != 0)
|
|
490 {
|
|
491 XtAppContext the_app_con = XtDisplayToApplicationContext (dpy);
|
|
492 XtAppWarningMsg(the_app_con, "wrongParameters", "cvtStringToXIMStyle",
|
|
493 "XtToolkitError",
|
|
494 "String to XIMStyle conversion requires exactly 0 parameters",
|
|
495 (String *)NULL, (Cardinal *)NULL);
|
|
496 return False;
|
|
497 }
|
|
498
|
|
499 #ifdef DEBUG_XEMACS
|
|
500 /* Make sure caller is giving us good data */
|
|
501 assert (fromVal->addr != NULL);
|
|
502 assert (fromVal->size == strlen(fromVal->addr)+1);
|
|
503 assert (toVal->addr != NULL);
|
|
504 assert (toVal->size == sizeof(XIMStyles));
|
|
505 #endif /* DEBUG_XEMACS */
|
|
506
|
|
507 p->count_styles = 0;
|
|
508 p->supported_styles = xmalloc (max_styles * sizeof (XIMStyle));
|
|
509
|
|
510 /*
|
|
511 * The following routine assumes that the style name resource is
|
|
512 * identical with the programmatic name of style. For example,
|
|
513 * "XIMPreeditPosition|XIMStatusArea" means the
|
|
514 * XIMPreeditPosition|XIMStatusArea value is specified. If the
|
|
515 * style name is changed, such as "OverTheSpot|imDisplaysInClient",
|
|
516 * the parsing logic below should be modified as well. */
|
|
517
|
|
518 if ((c = strtok(s, delimiter)) == NULL)
|
|
519 c = end;
|
|
520
|
|
521 while (c < end)
|
|
522 {
|
|
523 for(i=0 ; i<max_styles ; i++)
|
|
524 {
|
|
525 struct XIMStyleInfo *rec = emacs_XIMStyleInfo + i;
|
|
526 if(!strncmp(c, rec->name, rec->namelen - 1)) {
|
|
527 p->supported_styles[p->count_styles] = rec->style;
|
|
528 p->count_styles++;
|
|
529 break;
|
|
530 }
|
|
531 }
|
|
532 if((c = strtok(NULL, delimiter)) == NULL) {
|
|
533 break ;
|
|
534 }
|
|
535 }
|
|
536
|
|
537 if (p->count_styles == 0)
|
|
538 { /* No valid styles? */
|
|
539 char buf[1024];
|
|
540 XrmValue new_from;
|
|
541 XtAppContext the_app_con = XtDisplayToApplicationContext (dpy);
|
|
542
|
|
543 sprintf(buf, "Cannot convert string \"%s\" to type XIMStyles.\n"
|
|
544 "Using default string \"%s\" instead.\n",
|
|
545 fromVal->addr, DefaultXIMStyles);
|
|
546 XtAppWarningMsg(the_app_con, "wrongParameters", "cvtStringToXIMStyle",
|
|
547 "XtToolkitError",
|
|
548 buf, (String *)NULL, (Cardinal *)NULL);
|
|
549 new_from.addr = DefaultXIMStyles;
|
|
550 new_from.size = sizeof(DefaultXIMStyles);
|
|
551 return EmacsXtCvtStringToXIMStyles (dpy, args, num_args,
|
|
552 &new_from, toVal, converter_data);
|
|
553 }
|
|
554 p->supported_styles = xrealloc (p->supported_styles,
|
|
555 p->count_styles * sizeof(XIMStyle));
|
|
556 *converter_data = (char *) True;
|
|
557 return True;
|
|
558 }
|
|
559
|
|
560 /* XtDestructor */
|
|
561 void
|
|
562 EmacsFreeXIMStyles (
|
|
563 XtAppContext app,
|
|
564 XrmValuePtr toVal,
|
|
565 XtPointer converter_data,
|
|
566 XrmValuePtr args,
|
|
567 Cardinal *num_args)
|
|
568 {
|
|
569 #ifdef DEBUG_XIM
|
|
570 stderr_out ("Converter data: %x\n", converter_data);
|
|
571 stderr_out ("EmacsFreeXIMStyles called\n");
|
|
572 #endif /* DEBUG_XIM */
|
|
573
|
|
574 if (*num_args != 0)
|
|
575 {
|
|
576 XtAppWarningMsg(app, "wrongParameters","freeXIMStyles","XtToolkitError",
|
|
577 "Freeing an XIMStyles requires that zero arguments be passwd",
|
|
578 (String *)NULL, (Cardinal *)NULL);
|
|
579 return;
|
|
580 }
|
|
581
|
|
582 if (converter_data)
|
|
583 {
|
|
584 Boolean free_p = (Boolean) (int) converter_data;
|
|
585 XIMStyles *styles = (XIMStyles *) toVal->addr;
|
|
586 if (free_p)
|
|
587 XFree ( styles->supported_styles );
|
|
588 }
|
|
589 }
|
|
590
|
|
591 #if 0
|
|
592 /* O'Reilly XLib Programming Manual, pg. 371 */
|
|
593 /* Much nicer implementation than O'Reilly */
|
|
594 /* Choose the more `complicated', hence nicer, XIM input style */
|
|
595 static XIMStyle
|
|
596 BetterStyle (XIMStyle s, XIMStyle t)
|
|
597 {
|
|
598 #define CHECK_XIMStyle_BIT(bit) \
|
|
599 if ((s ^ t) & bit) { return (s & bit) ? s : t; }
|
|
600
|
|
601 CHECK_XIMStyle_BIT (XIMPreeditCallbacks);
|
|
602 CHECK_XIMStyle_BIT (XIMPreeditPosition);
|
|
603 CHECK_XIMStyle_BIT (XIMPreeditArea);
|
|
604 CHECK_XIMStyle_BIT (XIMPreeditNothing);
|
|
605 CHECK_XIMStyle_BIT (XIMStatusCallbacks);
|
|
606 CHECK_XIMStyle_BIT (XIMStatusArea);
|
|
607 CHECK_XIMStyle_BIT (XIMStatusNothing);
|
|
608 #undef CHECK_XIMStyle_BIT
|
|
609 return s ? s : t ;
|
|
610 }
|
|
611 #endif /* 0 */
|
|
612
|
|
613 /* Choose the best style, given:
|
|
614 * - user preferences (already checked to be supported by XEmacs)
|
|
615 * - styles supported by the input method */
|
|
616 #define DEFAULTStyle (XIMPreeditNothing|XIMStatusNothing)
|
|
617 static XIMStyle
|
|
618 best_style (XIMStyles *user, XIMStyles *xim)
|
|
619 {
|
|
620 register int i, j;
|
|
621 for (i=0 ; i<user->count_styles ; i++)
|
|
622 {
|
|
623 for (j=0 ; j<xim->count_styles ; j++)
|
|
624 {
|
|
625 if (user->supported_styles[i] == xim->supported_styles[j])
|
|
626 return user->supported_styles[i];
|
|
627 }
|
|
628 }
|
|
629 return DEFAULTStyle; /* Default Style */
|
|
630 }
|
|
631
|
|
632
|
|
633 void
|
|
634 vars_of_input_method_xlib (void)
|
|
635 {
|
|
636 Fprovide (intern ("xim"));
|
|
637 }
|
|
638
|
|
639
|
|
640 /* ====================================================================== */
|
|
641 /* Internal Debugging Routines */
|
|
642 /* ====================================================================== */
|
|
643 #ifdef DEBUG_XEMACS
|
|
644
|
|
645 void
|
|
646 describe_XIM (XIM xim)
|
|
647 {
|
|
648 XIMStyles *styles;
|
|
649
|
|
650 /* Print locale of XIM */
|
|
651 stderr_out ("\nXIM Locale of IM: %s\n", XLocaleOfIM(xim));
|
|
652
|
|
653 /* List supported input method styles */
|
|
654 XGetIMValues(xim, XNQueryInputStyle, &styles, NULL);
|
|
655
|
|
656 stderr_out ("\n%d input style(s) supported by input method.\n",
|
|
657 styles->count_styles);
|
|
658
|
|
659 #ifdef DEBUG_XIM
|
|
660 {
|
|
661 int i;
|
|
662 for (i=0; i < styles->count_styles; i++)
|
|
663 describe_XIMStyle (styles->supported_styles[i]);
|
|
664 }
|
|
665 #endif /* DEBUG_XIM */
|
|
666 XFree(styles);
|
|
667 }
|
|
668
|
|
669 void
|
|
670 describe_XFontSet (XFontSet fontset)
|
|
671 {
|
|
672 XFontStruct **font_struct_list;
|
|
673 char **font_name_list;
|
|
674 int count, i;
|
|
675
|
|
676 if (fontset == NULL)
|
|
677 {
|
|
678 stderr_out ("NULL\n");
|
|
679 return;
|
|
680 }
|
|
681
|
|
682 count = XFontsOfFontSet (fontset, &font_struct_list, &font_name_list);
|
|
683 stderr_out ( "%d font(s) available:\n", count);
|
|
684 for (i=0 ; i < count ; i++)
|
|
685 stderr_out ("Font: %s\n", *(font_name_list+i));
|
|
686 }
|
|
687
|
|
688 void
|
|
689 describe_Status (Status status)
|
|
690 {
|
|
691 #define DESCRIBE_STATUS(value) \
|
|
692 if (status == value) stderr_out ("Status: " #value "\n")
|
|
693
|
|
694 DESCRIBE_STATUS (XBufferOverflow);
|
|
695 DESCRIBE_STATUS (XLookupNone);
|
|
696 DESCRIBE_STATUS (XLookupKeySym);
|
|
697 DESCRIBE_STATUS (XLookupBoth);
|
|
698 DESCRIBE_STATUS (XLookupChars);
|
|
699 #undef DESCRIBE_STATUS
|
|
700 }
|
|
701
|
|
702 void
|
|
703 describe_Window (Window win)
|
|
704 {
|
|
705 char xwincmd[64];
|
|
706 sprintf (xwincmd, "xwininfo -id 0x%x >&2; xwininfo -events -id 0x%x >&2",
|
|
707 (int) win, (int) win);
|
|
708 system (xwincmd);
|
|
709 }
|
|
710
|
|
711 void
|
|
712 describe_XIC (XIC xic)
|
|
713 {
|
|
714 XIMStyle style;
|
|
715 Window client_win=0, focus_win=0;
|
|
716 char *resourceName = NULL;
|
|
717 char *resourceClass = NULL;
|
|
718 char *bad_arg = NULL;
|
|
719 unsigned long filter_mask = NoEventMask;
|
|
720 XVaNestedList p_list, s_list;
|
|
721 XFontSet p_fontset = NULL, s_fontset = NULL;
|
|
722 Pixel p_fg=0, p_bg = 0, s_fg=0, s_bg = 0;
|
|
723 XRectangle *p_area = NULL, *s_area = NULL;
|
|
724 XRectangle *p_needed = NULL, *s_needed = NULL;
|
|
725 XPoint *p_spot = NULL;
|
|
726
|
|
727 /* Check for valid input context and method */
|
|
728 if (!xic)
|
|
729 stderr_out ("Input method is NULL\n");
|
|
730
|
|
731 if (!XIMOfIC(xic))
|
|
732 stderr_out ("XIMOfIC() returns NULL\n");
|
|
733
|
|
734 /* Print out Input Context Attributes */
|
|
735 p_list = XVaCreateNestedList (0,
|
|
736 XNFontSet, &p_fontset,
|
|
737 XNArea, &p_area,
|
|
738 XNAreaNeeded, &p_needed,
|
|
739 XNSpotLocation, &p_spot,
|
|
740 XNForeground, &p_fg,
|
|
741 XNBackground, &p_bg,
|
|
742 NULL);
|
|
743
|
|
744 s_list = XVaCreateNestedList (0,
|
|
745 XNFontSet, &s_fontset,
|
|
746 XNArea, &s_area,
|
|
747 XNAreaNeeded, &s_needed,
|
|
748 XNForeground, &s_fg,
|
|
749 XNBackground, &s_bg,
|
|
750 NULL);
|
|
751
|
|
752 bad_arg = XGetICValues(xic,
|
|
753 XNInputStyle, &style,
|
|
754 XNFilterEvents, &filter_mask,
|
|
755 XNClientWindow, &client_win,
|
|
756 XNFocusWindow, &focus_win,
|
|
757 XNResourceName, &resourceName,
|
|
758 XNResourceClass, &resourceClass,
|
|
759 XNPreeditAttributes, p_list,
|
|
760 XNStatusAttributes, s_list,
|
|
761 NULL);
|
|
762 XFree(p_list);
|
|
763 XFree(s_list);
|
|
764
|
|
765 if (bad_arg != NULL)
|
|
766 stderr_out ("Couldn't get IC value: %s\n", bad_arg);
|
|
767
|
|
768 stderr_out ("\nInput method context attributes:\n");
|
|
769 stderr_out ("Style: "); describe_XIMStyle (style);
|
|
770 stderr_out ("Client window: %x\n", client_win);
|
|
771 stderr_out ("Focus window: %x\n", focus_win);
|
|
772 stderr_out ("Preedit:\n");
|
|
773 describe_XRectangle (" Area", p_area);
|
|
774 describe_XRectangle (" Area needed", p_needed);
|
|
775 stderr_out (" foreground: %x\n", p_fg);
|
|
776 stderr_out (" background: %x\n", p_bg);
|
|
777 stderr_out (" fontset: "); describe_XFontSet (p_fontset);
|
|
778 stderr_out ("Status:\n");
|
|
779 describe_XRectangle (" Area", s_area);
|
|
780 describe_XRectangle (" Area needed", s_needed);
|
|
781 stderr_out (" foreground: %x\n", s_fg);
|
|
782 stderr_out (" background: %x\n", s_bg);
|
|
783 stderr_out (" fontset: \n"); describe_XFontSet (s_fontset);
|
|
784 stderr_out ("XNResourceName: %s\n", resourceName ? resourceName : "NULL");
|
|
785 stderr_out ("XNResourceClass: %s\n", resourceClass ? resourceClass : "NULL");
|
|
786 stderr_out ("XNFilterEvents: "); describe_event_mask (filter_mask);
|
|
787 }
|
|
788
|
|
789 void
|
|
790 describe_XRectangle (char *name, XRectangle *r)
|
|
791 {
|
|
792 if (r == NULL)
|
|
793 stderr_out ("%s: NULL\n", name);
|
|
794 else
|
|
795 stderr_out ("%s: x=%d y=%d w=%d h=%d\n",
|
|
796 name, r->x, r->y, r->width, r->height);
|
|
797 }
|
|
798
|
|
799 /* Print out elements of Event mask */
|
|
800 /* Defines from X11/X.h */
|
|
801 void
|
|
802 describe_event_mask (unsigned long mask)
|
|
803 {
|
|
804 #define DESCRIBE_EVENT_MASK(bit) if ((bit) & mask) stderr_out (#bit " ")
|
|
805 DESCRIBE_EVENT_MASK (NoEventMask);
|
|
806 DESCRIBE_EVENT_MASK (KeyPressMask);
|
|
807 DESCRIBE_EVENT_MASK (KeyReleaseMask);
|
|
808 DESCRIBE_EVENT_MASK (ButtonPressMask);
|
|
809 DESCRIBE_EVENT_MASK (ButtonReleaseMask);
|
|
810 DESCRIBE_EVENT_MASK (EnterWindowMask);
|
|
811 DESCRIBE_EVENT_MASK (LeaveWindowMask);
|
|
812 DESCRIBE_EVENT_MASK (PointerMotionMask);
|
|
813 DESCRIBE_EVENT_MASK (PointerMotionHintMask);
|
|
814 DESCRIBE_EVENT_MASK (Button1MotionMask);
|
|
815 DESCRIBE_EVENT_MASK (Button2MotionMask);
|
|
816 DESCRIBE_EVENT_MASK (Button3MotionMask);
|
|
817 DESCRIBE_EVENT_MASK (Button4MotionMask);
|
|
818 DESCRIBE_EVENT_MASK (Button5MotionMask);
|
|
819 DESCRIBE_EVENT_MASK (ButtonMotionMask);
|
|
820 DESCRIBE_EVENT_MASK (KeymapStateMask);
|
|
821 DESCRIBE_EVENT_MASK (ExposureMask);
|
|
822 DESCRIBE_EVENT_MASK (VisibilityChangeMask);
|
|
823 DESCRIBE_EVENT_MASK (StructureNotifyMask);
|
|
824 DESCRIBE_EVENT_MASK (ResizeRedirectMask);
|
|
825 DESCRIBE_EVENT_MASK (SubstructureNotifyMask);
|
|
826 DESCRIBE_EVENT_MASK (SubstructureRedirectMask);
|
|
827 DESCRIBE_EVENT_MASK (FocusChangeMask);
|
|
828 DESCRIBE_EVENT_MASK (PropertyChangeMask);
|
|
829 DESCRIBE_EVENT_MASK (ColormapChangeMask);
|
|
830 DESCRIBE_EVENT_MASK (OwnerGrabButtonMask);
|
|
831 #undef DESCRIBE_EVENT_MASK
|
|
832 stderr_out("\n");
|
|
833 }
|
|
834
|
|
835 void
|
|
836 describe_XIMStyle (XIMStyle style)
|
|
837 {
|
|
838 #define DESCRIBE_STYLE(bit) \
|
|
839 if (bit & style) \
|
|
840 stderr_out (#bit " ");
|
|
841
|
|
842 DESCRIBE_STYLE (XIMPreeditArea);
|
|
843 DESCRIBE_STYLE (XIMPreeditCallbacks);
|
|
844 DESCRIBE_STYLE (XIMPreeditPosition);
|
|
845 DESCRIBE_STYLE (XIMPreeditNothing);
|
|
846 DESCRIBE_STYLE (XIMPreeditNone);
|
|
847 DESCRIBE_STYLE (XIMStatusArea);
|
|
848 DESCRIBE_STYLE (XIMStatusCallbacks);
|
|
849 DESCRIBE_STYLE (XIMStatusNothing);
|
|
850 DESCRIBE_STYLE (XIMStatusNone);
|
|
851 #undef DESCRIBE_STYLE
|
|
852 stderr_out("\n");
|
|
853 }
|
|
854
|
|
855 void
|
|
856 describe_XIMStyles (XIMStyles *p)
|
|
857 {
|
|
858 int i;
|
|
859 stderr_out ("%d Style(s):\n", p->count_styles);
|
|
860 for (i=0; i<p->count_styles ; i++)
|
|
861 {
|
|
862 describe_XIMStyle (p->supported_styles[i]);
|
|
863 }
|
|
864 }
|
|
865
|
|
866 #endif /* DEBUG_XEMACS */
|
|
867
|
|
868 /* Random cruft follows */
|
|
869
|
|
870 #if 0
|
|
871 static void
|
|
872 Unit_Test (struct frame *f, char * s)
|
|
873 /* mrb unit testing */
|
|
874 {
|
|
875 XrmValue fromVal, toVal;
|
|
876
|
|
877 fromVal.addr = s;
|
|
878 fromVal.size = strlen (s);
|
|
879 toVal.addr = (XtPointer) &user_preferred_XIMStyles;
|
|
880 toVal.size = sizeof (XIMStyles);
|
|
881
|
|
882 if (XtConvertAndStore (FRAME_X_TEXT_WIDGET (f), XtRString, &fromVal,
|
|
883 XtRXimStyles, &toVal) != False)
|
|
884 {
|
|
885 stderr_out ("Unit_Test: fromVal.addr=0x%x\n",fromVal.addr);
|
|
886 stderr_out ("Unit_Test: fromVal.size=%d\n", fromVal.size);
|
|
887 stderr_out ("Unit_Test: toVal.addr=0x%x\n", toVal.addr);
|
|
888 stderr_out ("Unit_Test: toVal.size=%d\n", toVal.size);
|
|
889 describe_XIMStyles ((XIMStyles *) toVal.addr);
|
|
890 }
|
|
891 }
|
|
892 #endif
|
|
893
|
|
894 #if 0
|
|
895 /* Get a fontset for IM to use */
|
|
896 void
|
|
897 x_init_fontset (struct device *d)
|
|
898 {
|
|
899 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
900 XFontSet fontset;
|
|
901 char ** missing_charsets;
|
|
902 int num_missing_charsets;
|
|
903 char * default_string;
|
|
904 /* char * font_set_string = "-dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*";*/
|
|
905 char * font_set_string = "-dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*, -misc-fixed-medium-r-normal--14-130-75-75-c-70-jisx0201.1976-0,-misc-fixed-medium-r-normal--14-130-75-75-c-140-jisx0208.1983-0, -misc-fixed-medium-r-normal--14-130-75-75-c-70-jisx0201.1976-0" ;
|
|
906
|
|
907 DEVICE_X_FONTSET (d) = fontset =
|
|
908 XCreateFontSet (dpy,
|
|
909 font_set_string,
|
|
910 &missing_charsets,
|
|
911 &num_missing_charsets,
|
|
912 &default_string);
|
|
913
|
|
914 if (fontset == NULL)
|
|
915 {
|
|
916 stderr_out ("Unable to create fontset from string:\n%s\n", font_set_string);
|
|
917 return;
|
|
918 }
|
|
919 if (num_missing_charsets > 0)
|
|
920 {
|
|
921 int i;
|
|
922 stderr_out ("\nMissing charsets for fontset %s:\n", font_set_string);
|
|
923 for (i=0; i < num_missing_charsets; i++)
|
|
924 {
|
|
925 stderr_out ("%s\n", missing_charsets[i]);
|
|
926 }
|
|
927 XFreeStringList (missing_charsets);
|
|
928 stderr_out ("Default string: %s\n", default_string);
|
|
929 }
|
|
930
|
|
931 #ifdef DEBUG_XIM
|
|
932 describe_XFontSet (fontset);
|
|
933 #endif
|
|
934 }
|
|
935 #endif /* 0 */
|