changeset 27157:3dafddaefc2c

(x_create_im): New function to set IM and IC of a frame. Check that input style is supported before trying to create an IC for it. (x_window): Call x_create_im.
author Gerd Moellmann <gerd@gnu.org>
date Tue, 04 Jan 2000 23:08:36 +0000
parents 488f307b4f59
children 9045ae8c1171
files src/xfns.c
diffstat 1 files changed, 69 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/src/xfns.c	Tue Jan 04 22:14:58 2000 +0000
+++ b/src/xfns.c	Tue Jan 04 23:08:36 2000 +0000
@@ -735,6 +735,7 @@
   void (*setter) P_ ((struct frame *, Lisp_Object, Lisp_Object));
 };
 
+static void x_create_im P_ ((struct frame *));
 void x_set_foreground_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
 void x_set_background_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
 void x_set_mouse_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
@@ -3043,6 +3044,72 @@
   UNBLOCK_INPUT;
 }
 #endif
+
+
+/* Create input method and input context for frame F.  Set FRAME_XIM
+   (F) and FRAME_XIC (F).  */
+
+static void
+x_create_im (f)
+     struct frame *f;
+{
+  FRAME_XIM (f) = 0;
+  FRAME_XIC (f) = 0;
+  
+#ifdef HAVE_X_I18N
+#ifndef X_I18N_INHIBITED
+  { 
+    XIM xim;
+    XIC xic = NULL;
+    XIMStyles *styles;
+    XIMStyle input_style = XIMPreeditNothing | XIMStatusNothing;
+    int i, n;
+
+    xim = XOpenIM (FRAME_X_DISPLAY(f), NULL, NULL, NULL);
+    if (!xim)
+      return;
+    
+    if (XGetIMValues (xim, XNQueryInputStyle, &styles, NULL)
+	|| !styles)
+      {
+	/* Input method doesn't support any input style.  */
+	XCloseIM (xim);
+	return;
+      }
+
+    /* See if input_style is supported.  Give up if it isn't.  */
+    n = styles->count_styles;
+    for (i = 0; i < n; ++i)
+      if (styles->supported_styles[i] == input_style)
+	break;
+    
+    XFree (styles);
+    if (i == n)
+      {
+	XCloseIM (xim);
+	return;
+      }
+
+    /* Create the input context.  */
+    xic = XCreateIC (xim,  
+		     XNInputStyle,   input_style,
+		     XNClientWindow, FRAME_X_WINDOW(f),
+		     XNFocusWindow,  FRAME_X_WINDOW(f),
+		     NULL);
+    
+    if (!xic)
+      {
+	XCloseIM (xim);
+	return;
+      }
+
+    FRAME_XIM (f) = xim;
+    FRAME_XIC (f) = xic;
+  }
+#endif /* X_I18N_INHIBITED */
+#endif /* HAVE_X_I18N */
+}
+
 
 #ifdef USE_X_TOOLKIT
 
@@ -3198,37 +3265,7 @@
   class_hints.res_name = (char *) XSTRING (Vx_resource_name)->data;
   class_hints.res_class = (char *) XSTRING (Vx_resource_class)->data;
   XSetClassHint (FRAME_X_DISPLAY (f), XtWindow (shell_widget), &class_hints);
-
-#ifdef HAVE_X_I18N
-#ifndef X_I18N_INHIBITED
-  { 
-    XIM xim;
-    XIC xic = NULL;
-
-    xim = XOpenIM (FRAME_X_DISPLAY (f), NULL, NULL, NULL);
-
-    if (xim)
-      {
-	xic = XCreateIC (xim,  
-			 XNInputStyle,   XIMPreeditNothing | XIMStatusNothing,
-			 XNClientWindow, FRAME_X_WINDOW(f),
-			 XNFocusWindow,  FRAME_X_WINDOW(f),
-			 NULL);
-
-	if (xic == 0)
-	  {
-	    XCloseIM (xim);
-	    xim = NULL;
-	  }
-      }
-    FRAME_XIM (f) = xim;
-    FRAME_XIC (f) = xic;
-  }
-#else /* X_I18N_INHIBITED */
-  FRAME_XIM (f) = 0;
-  FRAME_XIC (f) = 0;
-#endif /* X_I18N_INHIBITED */
-#endif /* HAVE_X_I18N */
+  x_create_im (f);
 
   f->output_data.x->wm_hints.input = True;
   f->output_data.x->wm_hints.flags |= InputHint;
@@ -3319,38 +3356,7 @@
 		     InputOutput, /* class */
 		     FRAME_X_DISPLAY_INFO (f)->visual,
 		     attribute_mask, &attributes);
-#ifdef HAVE_X_I18N
-#ifndef X_I18N_INHIBITED
-  { 
-    XIM xim;
-    XIC xic = NULL;
-
-    xim = XOpenIM (FRAME_X_DISPLAY(f), NULL, NULL, NULL);
-
-    if (xim)
-      {
-	xic = XCreateIC (xim,  
-			 XNInputStyle,   XIMPreeditNothing | XIMStatusNothing,
-			 XNClientWindow, FRAME_X_WINDOW(f),
-			 XNFocusWindow,  FRAME_X_WINDOW(f),
-			 NULL);
-
-	if (!xic)
-	  {
-	    XCloseIM (xim);
-	    xim = NULL;
-	  }
-      }
-
-    FRAME_XIM (f) = xim;
-    FRAME_XIC (f) = xic;
-  }
-#else /* X_I18N_INHIBITED */
-  FRAME_XIM (f) = 0;
-  FRAME_XIC (f) = 0;
-#endif /* X_I18N_INHIBITED */
-#endif /* HAVE_X_I18N */
-
+  x_create_im (f);
   validate_x_resource_name ();
 
   class_hints.res_name = (char *) XSTRING (Vx_resource_name)->data;