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;
|
185
|
81
|
70
|
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 }
|
185
|
113
|
70
|
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);
|
185
|
130
|
70
|
131 DEVICE_X_XIM (d) = xim = XOpenIM (dpy, XtDatabase (dpy), name, class);
|
185
|
132
|
70
|
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;
|
185
|
171
|
70
|
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);
|
185
|
190
|
70
|
191 if (!xim)
|
|
192 { /* No input method? */
|
|
193 FRAME_X_XIC (f) = NULL;
|
|
194 return;
|
|
195 }
|
185
|
196
|
70
|
197 XtGetApplicationResources (w, &xic_vars,
|
|
198 resources, XtNumber (resources),
|
|
199 NULL, 0);
|
185
|
200
|
70
|
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));
|
185
|
210
|
70
|
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);
|
185
|
237
|
70
|
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);
|
185
|
251
|
70
|
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;
|
185
|
265
|
70
|
266 if (!xic || !f)
|
|
267 return;
|
185
|
268
|
70
|
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;
|
185
|
275
|
70
|
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);
|
185
|
283
|
70
|
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;
|
185
|
288
|
70
|
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 */
|
185
|
293
|
70
|
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 }
|
185
|
309
|
70
|
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;
|
185
|
328
|
70
|
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;
|
185
|
380
|
70
|
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 }
|
185
|
394
|
70
|
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
|
185
|
475
|
70
|
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 */
|
185
|
488
|
70
|
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;
|
185
|
508 p->supported_styles = xnew_array (XIMStyle, max_styles);
|
70
|
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;
|
185
|
520
|
70
|
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 }
|
185
|
536
|
70
|
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);
|
185
|
542
|
70
|
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 }
|
185
|
554 XREALLOC_ARRAY (p->supported_styles, XIMStyle, p->count_styles);
|
70
|
555 *converter_data = (char *) True;
|
|
556 return True;
|
|
557 }
|
|
558
|
|
559 /* XtDestructor */
|
|
560 void
|
|
561 EmacsFreeXIMStyles (
|
|
562 XtAppContext app,
|
|
563 XrmValuePtr toVal,
|
|
564 XtPointer converter_data,
|
|
565 XrmValuePtr args,
|
|
566 Cardinal *num_args)
|
|
567 {
|
|
568 #ifdef DEBUG_XIM
|
|
569 stderr_out ("Converter data: %x\n", converter_data);
|
|
570 stderr_out ("EmacsFreeXIMStyles called\n");
|
|
571 #endif /* DEBUG_XIM */
|
185
|
572
|
70
|
573 if (*num_args != 0)
|
|
574 {
|
|
575 XtAppWarningMsg(app, "wrongParameters","freeXIMStyles","XtToolkitError",
|
|
576 "Freeing an XIMStyles requires that zero arguments be passwd",
|
|
577 (String *)NULL, (Cardinal *)NULL);
|
|
578 return;
|
|
579 }
|
185
|
580
|
70
|
581 if (converter_data)
|
|
582 {
|
|
583 Boolean free_p = (Boolean) (int) converter_data;
|
|
584 XIMStyles *styles = (XIMStyles *) toVal->addr;
|
|
585 if (free_p)
|
|
586 XFree ( styles->supported_styles );
|
|
587 }
|
|
588 }
|
|
589
|
|
590 #if 0
|
|
591 /* O'Reilly XLib Programming Manual, pg. 371 */
|
|
592 /* Much nicer implementation than O'Reilly */
|
|
593 /* Choose the more `complicated', hence nicer, XIM input style */
|
|
594 static XIMStyle
|
|
595 BetterStyle (XIMStyle s, XIMStyle t)
|
|
596 {
|
|
597 #define CHECK_XIMStyle_BIT(bit) \
|
|
598 if ((s ^ t) & bit) { return (s & bit) ? s : t; }
|
185
|
599
|
70
|
600 CHECK_XIMStyle_BIT (XIMPreeditCallbacks);
|
|
601 CHECK_XIMStyle_BIT (XIMPreeditPosition);
|
|
602 CHECK_XIMStyle_BIT (XIMPreeditArea);
|
|
603 CHECK_XIMStyle_BIT (XIMPreeditNothing);
|
|
604 CHECK_XIMStyle_BIT (XIMStatusCallbacks);
|
|
605 CHECK_XIMStyle_BIT (XIMStatusArea);
|
|
606 CHECK_XIMStyle_BIT (XIMStatusNothing);
|
|
607 #undef CHECK_XIMStyle_BIT
|
|
608 return s ? s : t ;
|
|
609 }
|
|
610 #endif /* 0 */
|
|
611
|
|
612 /* Choose the best style, given:
|
|
613 * - user preferences (already checked to be supported by XEmacs)
|
|
614 * - styles supported by the input method */
|
|
615 #define DEFAULTStyle (XIMPreeditNothing|XIMStatusNothing)
|
|
616 static XIMStyle
|
|
617 best_style (XIMStyles *user, XIMStyles *xim)
|
|
618 {
|
203
|
619 REGISTER int i, j;
|
70
|
620 for (i=0 ; i<user->count_styles ; i++)
|
|
621 {
|
|
622 for (j=0 ; j<xim->count_styles ; j++)
|
|
623 {
|
|
624 if (user->supported_styles[i] == xim->supported_styles[j])
|
|
625 return user->supported_styles[i];
|
|
626 }
|
|
627 }
|
|
628 return DEFAULTStyle; /* Default Style */
|
|
629 }
|
|
630
|
|
631
|
|
632 void
|
|
633 vars_of_input_method_xlib (void)
|
|
634 {
|
|
635 Fprovide (intern ("xim"));
|
|
636 }
|
|
637
|
|
638
|
|
639 /* ====================================================================== */
|
|
640 /* Internal Debugging Routines */
|
|
641 /* ====================================================================== */
|
|
642 #ifdef DEBUG_XEMACS
|
|
643
|
|
644 void
|
|
645 describe_XIM (XIM xim)
|
|
646 {
|
|
647 XIMStyles *styles;
|
|
648
|
|
649 /* Print locale of XIM */
|
|
650 stderr_out ("\nXIM Locale of IM: %s\n", XLocaleOfIM(xim));
|
|
651
|
|
652 /* List supported input method styles */
|
|
653 XGetIMValues(xim, XNQueryInputStyle, &styles, NULL);
|
|
654
|
|
655 stderr_out ("\n%d input style(s) supported by input method.\n",
|
|
656 styles->count_styles);
|
|
657
|
|
658 #ifdef DEBUG_XIM
|
|
659 {
|
|
660 int i;
|
|
661 for (i=0; i < styles->count_styles; i++)
|
|
662 describe_XIMStyle (styles->supported_styles[i]);
|
|
663 }
|
|
664 #endif /* DEBUG_XIM */
|
|
665 XFree(styles);
|
|
666 }
|
|
667
|
|
668 void
|
|
669 describe_XFontSet (XFontSet fontset)
|
|
670 {
|
|
671 XFontStruct **font_struct_list;
|
|
672 char **font_name_list;
|
|
673 int count, i;
|
|
674
|
|
675 if (fontset == NULL)
|
|
676 {
|
|
677 stderr_out ("NULL\n");
|
|
678 return;
|
|
679 }
|
185
|
680
|
70
|
681 count = XFontsOfFontSet (fontset, &font_struct_list, &font_name_list);
|
|
682 stderr_out ( "%d font(s) available:\n", count);
|
|
683 for (i=0 ; i < count ; i++)
|
|
684 stderr_out ("Font: %s\n", *(font_name_list+i));
|
|
685 }
|
|
686
|
|
687 void
|
|
688 describe_Status (Status status)
|
|
689 {
|
|
690 #define DESCRIBE_STATUS(value) \
|
|
691 if (status == value) stderr_out ("Status: " #value "\n")
|
185
|
692
|
70
|
693 DESCRIBE_STATUS (XBufferOverflow);
|
|
694 DESCRIBE_STATUS (XLookupNone);
|
|
695 DESCRIBE_STATUS (XLookupKeySym);
|
|
696 DESCRIBE_STATUS (XLookupBoth);
|
|
697 DESCRIBE_STATUS (XLookupChars);
|
|
698 #undef DESCRIBE_STATUS
|
|
699 }
|
|
700
|
|
701 void
|
185
|
702 describe_Window (Window win)
|
70
|
703 {
|
|
704 char xwincmd[64];
|
|
705 sprintf (xwincmd, "xwininfo -id 0x%x >&2; xwininfo -events -id 0x%x >&2",
|
|
706 (int) win, (int) win);
|
|
707 system (xwincmd);
|
|
708 }
|
|
709
|
|
710 void
|
|
711 describe_XIC (XIC xic)
|
|
712 {
|
|
713 XIMStyle style;
|
|
714 Window client_win=0, focus_win=0;
|
|
715 char *resourceName = NULL;
|
|
716 char *resourceClass = NULL;
|
|
717 char *bad_arg = NULL;
|
|
718 unsigned long filter_mask = NoEventMask;
|
|
719 XVaNestedList p_list, s_list;
|
|
720 XFontSet p_fontset = NULL, s_fontset = NULL;
|
|
721 Pixel p_fg=0, p_bg = 0, s_fg=0, s_bg = 0;
|
|
722 XRectangle *p_area = NULL, *s_area = NULL;
|
|
723 XRectangle *p_needed = NULL, *s_needed = NULL;
|
|
724 XPoint *p_spot = NULL;
|
|
725
|
|
726 /* Check for valid input context and method */
|
|
727 if (!xic)
|
|
728 stderr_out ("Input method is NULL\n");
|
185
|
729
|
70
|
730 if (!XIMOfIC(xic))
|
|
731 stderr_out ("XIMOfIC() returns NULL\n");
|
185
|
732
|
70
|
733 /* Print out Input Context Attributes */
|
|
734 p_list = XVaCreateNestedList (0,
|
|
735 XNFontSet, &p_fontset,
|
|
736 XNArea, &p_area,
|
|
737 XNAreaNeeded, &p_needed,
|
|
738 XNSpotLocation, &p_spot,
|
|
739 XNForeground, &p_fg,
|
|
740 XNBackground, &p_bg,
|
|
741 NULL);
|
|
742
|
|
743 s_list = XVaCreateNestedList (0,
|
|
744 XNFontSet, &s_fontset,
|
|
745 XNArea, &s_area,
|
|
746 XNAreaNeeded, &s_needed,
|
|
747 XNForeground, &s_fg,
|
|
748 XNBackground, &s_bg,
|
|
749 NULL);
|
185
|
750
|
70
|
751 bad_arg = XGetICValues(xic,
|
|
752 XNInputStyle, &style,
|
|
753 XNFilterEvents, &filter_mask,
|
|
754 XNClientWindow, &client_win,
|
|
755 XNFocusWindow, &focus_win,
|
|
756 XNResourceName, &resourceName,
|
|
757 XNResourceClass, &resourceClass,
|
|
758 XNPreeditAttributes, p_list,
|
|
759 XNStatusAttributes, s_list,
|
|
760 NULL);
|
|
761 XFree(p_list);
|
|
762 XFree(s_list);
|
185
|
763
|
70
|
764 if (bad_arg != NULL)
|
|
765 stderr_out ("Couldn't get IC value: %s\n", bad_arg);
|
185
|
766
|
70
|
767 stderr_out ("\nInput method context attributes:\n");
|
|
768 stderr_out ("Style: "); describe_XIMStyle (style);
|
|
769 stderr_out ("Client window: %x\n", client_win);
|
|
770 stderr_out ("Focus window: %x\n", focus_win);
|
|
771 stderr_out ("Preedit:\n");
|
|
772 describe_XRectangle (" Area", p_area);
|
|
773 describe_XRectangle (" Area needed", p_needed);
|
|
774 stderr_out (" foreground: %x\n", p_fg);
|
|
775 stderr_out (" background: %x\n", p_bg);
|
|
776 stderr_out (" fontset: "); describe_XFontSet (p_fontset);
|
|
777 stderr_out ("Status:\n");
|
|
778 describe_XRectangle (" Area", s_area);
|
|
779 describe_XRectangle (" Area needed", s_needed);
|
|
780 stderr_out (" foreground: %x\n", s_fg);
|
|
781 stderr_out (" background: %x\n", s_bg);
|
|
782 stderr_out (" fontset: \n"); describe_XFontSet (s_fontset);
|
|
783 stderr_out ("XNResourceName: %s\n", resourceName ? resourceName : "NULL");
|
|
784 stderr_out ("XNResourceClass: %s\n", resourceClass ? resourceClass : "NULL");
|
|
785 stderr_out ("XNFilterEvents: "); describe_event_mask (filter_mask);
|
|
786 }
|
|
787
|
|
788 void
|
|
789 describe_XRectangle (char *name, XRectangle *r)
|
|
790 {
|
|
791 if (r == NULL)
|
|
792 stderr_out ("%s: NULL\n", name);
|
|
793 else
|
|
794 stderr_out ("%s: x=%d y=%d w=%d h=%d\n",
|
|
795 name, r->x, r->y, r->width, r->height);
|
|
796 }
|
|
797
|
|
798 /* Print out elements of Event mask */
|
|
799 /* Defines from X11/X.h */
|
|
800 void
|
|
801 describe_event_mask (unsigned long mask)
|
|
802 {
|
|
803 #define DESCRIBE_EVENT_MASK(bit) if ((bit) & mask) stderr_out (#bit " ")
|
|
804 DESCRIBE_EVENT_MASK (NoEventMask);
|
|
805 DESCRIBE_EVENT_MASK (KeyPressMask);
|
|
806 DESCRIBE_EVENT_MASK (KeyReleaseMask);
|
|
807 DESCRIBE_EVENT_MASK (ButtonPressMask);
|
|
808 DESCRIBE_EVENT_MASK (ButtonReleaseMask);
|
|
809 DESCRIBE_EVENT_MASK (EnterWindowMask);
|
|
810 DESCRIBE_EVENT_MASK (LeaveWindowMask);
|
|
811 DESCRIBE_EVENT_MASK (PointerMotionMask);
|
|
812 DESCRIBE_EVENT_MASK (PointerMotionHintMask);
|
|
813 DESCRIBE_EVENT_MASK (Button1MotionMask);
|
|
814 DESCRIBE_EVENT_MASK (Button2MotionMask);
|
|
815 DESCRIBE_EVENT_MASK (Button3MotionMask);
|
|
816 DESCRIBE_EVENT_MASK (Button4MotionMask);
|
|
817 DESCRIBE_EVENT_MASK (Button5MotionMask);
|
|
818 DESCRIBE_EVENT_MASK (ButtonMotionMask);
|
|
819 DESCRIBE_EVENT_MASK (KeymapStateMask);
|
|
820 DESCRIBE_EVENT_MASK (ExposureMask);
|
|
821 DESCRIBE_EVENT_MASK (VisibilityChangeMask);
|
|
822 DESCRIBE_EVENT_MASK (StructureNotifyMask);
|
|
823 DESCRIBE_EVENT_MASK (ResizeRedirectMask);
|
|
824 DESCRIBE_EVENT_MASK (SubstructureNotifyMask);
|
|
825 DESCRIBE_EVENT_MASK (SubstructureRedirectMask);
|
|
826 DESCRIBE_EVENT_MASK (FocusChangeMask);
|
|
827 DESCRIBE_EVENT_MASK (PropertyChangeMask);
|
|
828 DESCRIBE_EVENT_MASK (ColormapChangeMask);
|
|
829 DESCRIBE_EVENT_MASK (OwnerGrabButtonMask);
|
|
830 #undef DESCRIBE_EVENT_MASK
|
|
831 stderr_out("\n");
|
|
832 }
|
|
833
|
|
834 void
|
|
835 describe_XIMStyle (XIMStyle style)
|
|
836 {
|
|
837 #define DESCRIBE_STYLE(bit) \
|
|
838 if (bit & style) \
|
|
839 stderr_out (#bit " ");
|
185
|
840
|
70
|
841 DESCRIBE_STYLE (XIMPreeditArea);
|
|
842 DESCRIBE_STYLE (XIMPreeditCallbacks);
|
|
843 DESCRIBE_STYLE (XIMPreeditPosition);
|
|
844 DESCRIBE_STYLE (XIMPreeditNothing);
|
|
845 DESCRIBE_STYLE (XIMPreeditNone);
|
|
846 DESCRIBE_STYLE (XIMStatusArea);
|
|
847 DESCRIBE_STYLE (XIMStatusCallbacks);
|
|
848 DESCRIBE_STYLE (XIMStatusNothing);
|
|
849 DESCRIBE_STYLE (XIMStatusNone);
|
|
850 #undef DESCRIBE_STYLE
|
|
851 stderr_out("\n");
|
|
852 }
|
|
853
|
|
854 void
|
|
855 describe_XIMStyles (XIMStyles *p)
|
|
856 {
|
|
857 int i;
|
|
858 stderr_out ("%d Style(s):\n", p->count_styles);
|
|
859 for (i=0; i<p->count_styles ; i++)
|
|
860 {
|
|
861 describe_XIMStyle (p->supported_styles[i]);
|
|
862 }
|
|
863 }
|
|
864
|
|
865 #endif /* DEBUG_XEMACS */
|
|
866
|
|
867 /* Random cruft follows */
|
|
868
|
|
869 #if 0
|
|
870 static void
|
|
871 Unit_Test (struct frame *f, char * s)
|
|
872 /* mrb unit testing */
|
|
873 {
|
|
874 XrmValue fromVal, toVal;
|
|
875
|
|
876 fromVal.addr = s;
|
|
877 fromVal.size = strlen (s);
|
|
878 toVal.addr = (XtPointer) &user_preferred_XIMStyles;
|
|
879 toVal.size = sizeof (XIMStyles);
|
185
|
880
|
70
|
881 if (XtConvertAndStore (FRAME_X_TEXT_WIDGET (f), XtRString, &fromVal,
|
|
882 XtRXimStyles, &toVal) != False)
|
|
883 {
|
|
884 stderr_out ("Unit_Test: fromVal.addr=0x%x\n",fromVal.addr);
|
|
885 stderr_out ("Unit_Test: fromVal.size=%d\n", fromVal.size);
|
|
886 stderr_out ("Unit_Test: toVal.addr=0x%x\n", toVal.addr);
|
|
887 stderr_out ("Unit_Test: toVal.size=%d\n", toVal.size);
|
|
888 describe_XIMStyles ((XIMStyles *) toVal.addr);
|
|
889 }
|
|
890 }
|
|
891 #endif
|
|
892
|
|
893 #if 0
|
|
894 /* Get a fontset for IM to use */
|
|
895 void
|
|
896 x_init_fontset (struct device *d)
|
|
897 {
|
|
898 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
899 XFontSet fontset;
|
|
900 char ** missing_charsets;
|
|
901 int num_missing_charsets;
|
|
902 char * default_string;
|
|
903 /* char * font_set_string = "-dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*";*/
|
|
904 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" ;
|
185
|
905
|
70
|
906 DEVICE_X_FONTSET (d) = fontset =
|
|
907 XCreateFontSet (dpy,
|
|
908 font_set_string,
|
|
909 &missing_charsets,
|
|
910 &num_missing_charsets,
|
|
911 &default_string);
|
|
912
|
|
913 if (fontset == NULL)
|
|
914 {
|
|
915 stderr_out ("Unable to create fontset from string:\n%s\n", font_set_string);
|
|
916 return;
|
|
917 }
|
|
918 if (num_missing_charsets > 0)
|
|
919 {
|
|
920 int i;
|
|
921 stderr_out ("\nMissing charsets for fontset %s:\n", font_set_string);
|
|
922 for (i=0; i < num_missing_charsets; i++)
|
|
923 {
|
|
924 stderr_out ("%s\n", missing_charsets[i]);
|
|
925 }
|
|
926 XFreeStringList (missing_charsets);
|
|
927 stderr_out ("Default string: %s\n", default_string);
|
|
928 }
|
185
|
929
|
70
|
930 #ifdef DEBUG_XIM
|
|
931 describe_XFontSet (fontset);
|
|
932 #endif
|
|
933 }
|
|
934 #endif /* 0 */
|