(M-28907): Unify M028907.
[chise/xemacs-chise.git] / src / input-method-xlib.c
index b52eae9..db564bb 100644 (file)
@@ -34,9 +34,9 @@ Boston, MA 02111-1307, USA.  */
   The XIC is of each frame, by each frame, for each frame.
   The exceptions are:
       1.  Activate XICs on poor frames when the XIM is back.
   The XIC is of each frame, by each frame, for each frame.
   The exceptions are:
       1.  Activate XICs on poor frames when the XIM is back.
-      2.  Deactivate all the XICs when the XIM go down.
+      2.  Deactivate all the XICs when the XIM goes down.
 
 
-  Methods:
+  Implementation:
 
     -  Register a callback for an XIM when the X device is being initialized.
        XIM_init_device (d) { XRegisterIMInstantiateCallback (); }
 
     -  Register a callback for an XIM when the X device is being initialized.
        XIM_init_device (d) { XRegisterIMInstantiateCallback (); }
@@ -55,7 +55,7 @@ Boston, MA 02111-1307, USA.  */
        In IMDestroyCallback:
            DEVICE_FRAME_LOOP (...) { FRAME_X_XIC (f) = NULL; }
 
        In IMDestroyCallback:
            DEVICE_FRAME_LOOP (...) { FRAME_X_XIC (f) = NULL; }
 
-    -  Re-enable XIC for all the frames which doesn't have XIC when the XIM
+    -  Re-enable XIC for all the frames which don't have XIC when the XIM
        is back.
        In IMInstantiateCallback:
            DEVICE_FRAME_LOOP (...) { XIM_init_frame (f); }
        is back.
        In IMInstantiateCallback:
            DEVICE_FRAME_LOOP (...) { XIM_init_frame (f); }
@@ -71,6 +71,7 @@ Boston, MA 02111-1307, USA.  */
 #include <config.h>
 #include "lisp.h"
 #include <X11/Xlocale.h>        /* More portable than <locale.h> ? */
 #include <config.h>
 #include "lisp.h"
 #include <X11/Xlocale.h>        /* More portable than <locale.h> ? */
+#include <X11/Xlib.h>
 #include "frame.h"
 #include "device.h"
 #include "window.h"
 #include "frame.h"
 #include "device.h"
 #include "window.h"
@@ -79,11 +80,6 @@ Boston, MA 02111-1307, USA.  */
 #include "EmacsFrame.h"
 #include "events.h"
 
 #include "EmacsFrame.h"
 #include "events.h"
 
-#ifdef THIS_IS_X11R6
-#include <X11/IntrinsicP.h>
-#include <X11/Xaw/XawImP.h>
-#endif
-
 #ifndef XIM_XLIB
 #error  XIM_XLIB is not defined??
 #endif
 #ifndef XIM_XLIB
 #error  XIM_XLIB is not defined??
 #endif
@@ -123,16 +119,17 @@ static char DefaultXIMStyles[] =
 "XIMPreeditNone|XIMStatusNothing\n"
 "XIMPreeditNone|XIMStatusNone";
 
 "XIMPreeditNone|XIMStatusNothing\n"
 "XIMPreeditNone|XIMStatusNone";
 
-static Boolean xim_initted = False;
-
 static XIMStyle best_style (XIMStyles *user, XIMStyles *xim);
 
 static XIMStyle best_style (XIMStyles *user, XIMStyles *xim);
 
+/* This function is documented, but no prototype in the header files */
+EXTERN_C char * XSetIMValues(XIM, ...);
+
 void
 Initialize_Locale (void)
 {
   char *locale;
 
 void
 Initialize_Locale (void)
 {
   char *locale;
 
-  /* dverna - Nov. 98: ### DON'T DO THIS !!! The default XtLanguageProc
+  /* dverna - Nov. 98: #### DON'T DO THIS !!! The default XtLanguageProc
      routine calls setlocale(LC_ALL, lang) which fucks up our lower-level
      locale management, and especially the value of LC_NUMERIC. Anyway, since
      at this point, we don't know yet whether we're gonna need an X11 frame,
      routine calls setlocale(LC_ALL, lang) which fucks up our lower-level
      locale management, and especially the value of LC_NUMERIC. Anyway, since
      at this point, we don't know yet whether we're gonna need an X11 frame,
@@ -178,7 +175,11 @@ Initialize_Locale (void)
     }
 }
 
     }
 }
 
-#ifdef THIS_IS_X11R6 /* Callbacks for IM are supported from X11R6 or later. */
+/* Callbacks for IM are supported from X11R6 or later. */
+#ifdef HAVE_XREGISTERIMINSTANTIATECALLBACK
+
+static Boolean xim_initted = False;
+
 /* Called from when XIM is destroying.
    Clear all the XIC when the XIM was destroying... */
 static void
 /* Called from when XIM is destroying.
    Clear all the XIC when the XIM was destroying... */
 static void
@@ -221,7 +222,7 @@ IMInstantiateCallback (Display *dpy, XPointer client_data, XPointer call_data)
       DEVICE_X_XIM (d) = xim = XOpenIM (dpy, XtDatabase (dpy), name, class);
 
       /* destroy callback for im */
       DEVICE_X_XIM (d) = xim = XOpenIM (dpy, XtDatabase (dpy), name, class);
 
       /* destroy callback for im */
-      ximcallback.callback = IMDestroyCallback;
+      ximcallback.callback = (XIMProc) IMDestroyCallback;
       ximcallback.client_data = (XPointer) d;
       XSetIMValues (xim, XNDestroyCallback, &ximcallback, NULL);
     }
       ximcallback.client_data = (XPointer) d;
       XSetIMValues (xim, XNDestroyCallback, &ximcallback, NULL);
     }
@@ -237,19 +238,29 @@ IMInstantiateCallback (Display *dpy, XPointer client_data, XPointer call_data)
     }
   return;
 }
     }
   return;
 }
-#endif /* if THIS_IS_X11R6 */
+#endif /* HAVE_XREGISTERIMINSTANTIATECALLBACK */
 
 /* Initialize XIM for X device.
    Register the use of XIM using XRegisterIMInstantiateCallback. */
 void
 XIM_init_device (struct device *d)
 {
 
 /* Initialize XIM for X device.
    Register the use of XIM using XRegisterIMInstantiateCallback. */
 void
 XIM_init_device (struct device *d)
 {
-#ifdef THIS_IS_X11R6
+#ifdef HAVE_XREGISTERIMINSTANTIATECALLBACK /* X11R6+ */
   DEVICE_X_XIM (d) = NULL;
   XRegisterIMInstantiateCallback (DEVICE_X_DISPLAY (d), NULL, NULL, NULL,
   DEVICE_X_XIM (d) = NULL;
   XRegisterIMInstantiateCallback (DEVICE_X_DISPLAY (d), NULL, NULL, NULL,
-                                 IMInstantiateCallback, (XPointer) d);
+#ifdef XREGISTERIMINSTANTIATECALLBACK_NONSTANDARD_PROTOTYPE
+                                 /* The sixth parameter is of type
+                                    XPointer in XFree86 but (XPointer *)
+                                    on most other X11's. */
+                                 (XIDProc) IMInstantiateCallback,
+                                 (XPointer) d
+#else /* X Consortium prototype */
+                                 (XIMProc) IMInstantiateCallback,
+                                 (XPointer *) d
+#endif /* XREGISTERIMINSTANTIATECALLBACK_NONSTANDARD_PROTOTYPE */
+                                 );
   return;
   return;
-#else
+#else /* pre-X11R6 */
   Display *dpy = DEVICE_X_DISPLAY (d);
   char *name, *class;
   XIM xim;
   Display *dpy = DEVICE_X_DISPLAY (d);
   char *name, *class;
   XIM xim;
@@ -266,7 +277,7 @@ XIM_init_device (struct device *d)
       XGetIMValues (xim, XNQueryInputStyle, &DEVICE_X_XIM_STYLES (d), NULL);
       return;
     }
       XGetIMValues (xim, XNQueryInputStyle, &DEVICE_X_XIM_STYLES (d), NULL);
       return;
     }
-#endif
+#endif /* HAVE_XREGISTERIMINSTANTIATECALLBACK */
 }
 
 
 }
 
 
@@ -323,9 +334,6 @@ XIM_init_frame (struct frame *f)
   static XtResource resources[] =
   {
     /*  name              class          represent'n   field    default value */
   static XtResource resources[] =
   {
     /*  name              class          represent'n   field    default value */
-#ifdef THIS_IS_X11R6
-    res(XtNinputMethod,   XtCInputMethod, XtRString,   inputmethod, (XtPointer) NULL),
-#endif
     res(XtNximStyles,     XtCXimStyles,  XtRXimStyles, styles,  (XtPointer) DefaultXIMStyles),
     res(XtNfontSet,       XtCFontSet,    XtRFontSet,   fontset, (XtPointer) XtDefaultFontSet),
     res(XtNximForeground, XtCForeground, XtRPixel,     fg,      (XtPointer) XtDefaultForeground),
     res(XtNximStyles,     XtCXimStyles,  XtRXimStyles, styles,  (XtPointer) DefaultXIMStyles),
     res(XtNfontSet,       XtCFontSet,    XtRFontSet,   fontset, (XtPointer) XtDefaultFontSet),
     res(XtNximForeground, XtCForeground, XtRPixel,     fg,      (XtPointer) XtDefaultForeground),
@@ -337,7 +345,6 @@ XIM_init_frame (struct frame *f)
 
   if (!xim)
     {
 
   if (!xim)
     {
-      xim_info ("X Input Method open failed. Waiting for an XIM to be enabled.\n");
       return;
     }
 
       return;
     }
 
@@ -404,7 +411,7 @@ XIM_init_frame (struct frame *f)
 
   XSetICFocus (xic);
 
 
   XSetICFocus (xic);
 
-#ifdef THIS_IS_X11R6
+#ifdef HAVE_XREGISTERIMINSTANTIATECALLBACK
   /* when frame is going to be destroyed (closed) */
   XtAddCallback (FRAME_X_TEXT_WIDGET(f), XNDestroyCallback,
                 XIM_delete_frame, (XtPointer)f);
   /* when frame is going to be destroyed (closed) */
   XtAddCallback (FRAME_X_TEXT_WIDGET(f), XNDestroyCallback,
                 XIM_delete_frame, (XtPointer)f);
@@ -485,7 +492,7 @@ XIM_SetSpotLocation (struct frame *f, int x, int y)
   spot->x = (short) x;
   spot->y = (short) y;
 
   spot->x = (short) x;
   spot->y = (short) y;
 
-  /* ### FIX: Must make sure spot fits within Preedit Area */
+  /* #### FIX: Must make sure spot fits within Preedit Area */
   XIC_Value (Set, xic, XNPreeditAttributes, XNSpotLocation, spot);
 #ifdef DEBUG_XIM
   stderr_out ("Spot: %d %d\n", spot->x, spot->y);
   XIC_Value (Set, xic, XNPreeditAttributes, XNSpotLocation, spot);
 #ifdef DEBUG_XIM
   stderr_out ("Spot: %d %d\n", spot->x, spot->y);
@@ -613,9 +620,9 @@ EmacsXtCvtStringToXIMStyles (
 #define STYLE_INFO(style) { style, #style, sizeof(#style) }
   static struct XIMStyleInfo
   {
 #define STYLE_INFO(style) { style, #style, sizeof(#style) }
   static struct XIMStyleInfo
   {
-    CONST XIMStyle style;
-    CONST char   * CONST name;
-    CONST int      namelen;
+    const XIMStyle style;
+    const char   * const name;
+    const int      namelen;
   } emacs_XIMStyleInfo[] = {
     STYLE_INFO (XIMPreeditPosition|XIMStatusArea),
     STYLE_INFO (XIMPreeditPosition|XIMStatusNothing),
   } emacs_XIMStyleInfo[] = {
     STYLE_INFO (XIMPreeditPosition|XIMStatusArea),
     STYLE_INFO (XIMPreeditPosition|XIMStatusNothing),
@@ -631,9 +638,9 @@ EmacsXtCvtStringToXIMStyles (
 
   char *s   = (char *) fromVal->addr;
   char *end = s + fromVal->size;
 
   char *s   = (char *) fromVal->addr;
   char *end = s + fromVal->size;
-  XIMStyles * CONST p = (XIMStyles *) toVal->addr;
-  CONST char * CONST delimiter = " \t\n\r:;," ;
-  CONST int  max_styles = XtNumber(emacs_XIMStyleInfo);
+  XIMStyles * const p = (XIMStyles *) toVal->addr;
+  const char * const delimiter = " \t\n\r:;," ;
+  const int  max_styles = XtNumber(emacs_XIMStyleInfo);
   int i;
   char *c;
 
   int i;
   char *c;