Back to index

im-sdk  12.3.91
Classes | Defines | Typedefs | Functions | Variables
XeIMWrap.c File Reference
#include <X11/Xlibint.h>
#include "Xlcint.h"
#include "XIM.h"
#include "switchIM.h"
#include "iiimpIM.h"
#include "genutil.h"
#include <locale.h>
#include <langinfo.h>

Go to the source code of this file.

Classes

struct  _XimInstCallback

Defines

#define __XLIBINT_HH
#define NAME_LEN   20

Typedefs

typedef struct _XimInstCallback XimInstCallbackRec
typedef struct _XimInstCallbackXimInstCallback

Functions

static int getXIMArg (XIMArg *arg, char *name, void *value)
XIM __XOpenIM (Display *display, XrmDatabase rdb, char *res_name, char *res_class, XIMArg *arg)
static void MakeLocale (XLCd lcd, char locale[])
static Bool _XimFilterPropertyNotify (Display *display, Window window, XEvent *event, XPointer client_data)
Bool _XimRegisterIMInstantiateCallback (XLCd lcd, Display *display, XrmDatabase rdb, char *res_name, char *res_class, XIDProc callback, XPointer client_data)
Bool _XimUnRegisterIMInstantiateCallback (XLCd lcd, Display *display, XrmDatabase rdb, char *res_name, char *res_class, XIDProc callback, XPointer client_data)
void _XimResetIMInstantiateCallback (XIM xim)

Variables

static XimInstCallback callback_list = NULL
static Bool lock = False

Class Documentation

struct _XimInstCallback

Definition at line 198 of file XeIMWrap.c.

Collaboration diagram for _XimInstCallback:
Class Members
Bool call
XIDProc callback
XPointer client_data
Bool destroy
Display * display
XLCd lcd
char * modifiers
char name
struct _XimInstCallback * next
XrmDatabase rdb
char * res_class
char * res_name

Define Documentation

#define __XLIBINT_HH

Definition at line 49 of file XeIMWrap.c.

#define NAME_LEN   20

Definition at line 74 of file XeIMWrap.c.


Typedef Documentation


Function Documentation

XIM __XOpenIM ( Display *  display,
XrmDatabase  rdb,
char *  res_name,
char *  res_class,
XIMArg arg 
)

Definition at line 76 of file XeIMWrap.c.

                      {
  Bool isMultilingual = False;
  XIM xim = (XIM)0;
  XOpenIMProc open_im;
  XLCd lcd = 0;
  char *current_locale = 0;

  (void)getXIMArg(arg,
                XNMultiLingualInput, &isMultilingual);
  open_im = isMultilingual? _SwitchOpenIM : _IIIMP_OpenIM ;
  if (isMultilingual)
    putenv("DISABLE_MULTI_SCRIPT_IM=false"); /* hidden feature */

  current_locale = (char*)strdup(setlocale(LC_CTYPE, NULL));

  lcd = _XOpenLC((char*)NULL);

  /* try first with the current locale */
  if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0) {
    if (lcd) {
      xim = open_im((XLCd)lcd, display, rdb, res_name, res_class);
      if (xim) {
       ((XimCommon)xim)->isUnicode = isMultilingual;
       goto Ret;
      }
    }
  }

  /* pick an UTF-8 locale best matching for the lang part of
     the current locale */
  if (lcd) {
    char new_locale[NAME_LEN];
    char *language, *territory;
    char *codeset;
    XLCd new_lcd;

    _XGetLCValues(lcd, XlcNLanguage,  &language,
                XlcNTerritory, &territory,
                XlcNCodeset,   &codeset,
                (char*)NULL);
    _genutil_strlcpy(new_locale, language, NAME_LEN);

    if (territory && *territory) {
      _genutil_strlcat(new_locale, "_", NAME_LEN);
      _genutil_strlcat(new_locale, territory, NAME_LEN);
    }
    _genutil_strlcat(new_locale, ".UTF-8", NAME_LEN);
    new_lcd = _XOpenLC(new_locale);
    if (new_lcd) {
      xim = open_im((XLCd)new_lcd, display, rdb, res_name, res_class);
      if (xim) {
       _XCloseLC(lcd);             /* no more need */
       ((XimCommon)xim)->isUnicode = isMultilingual;
       goto Ret;
      }
      _XCloseLC(new_lcd);
      new_lcd = 0;
    }
    if (!territory || !*territory) {
      /* get territory name from current locale */
      char *p = index(current_locale, '_');
      if (p &&strlen(p) >= 2) {
       territory = p + 1; territory[2] = 0;

       _genutil_strlcpy(new_locale, language, NAME_LEN);
       _genutil_strlcat(new_locale, "_", NAME_LEN);
       _genutil_strlcat(new_locale, territory, NAME_LEN);
       _genutil_strlcat(new_locale, ".UTF-8", NAME_LEN);

       new_lcd = _XOpenLC(new_locale);
       if (new_lcd) {
         xim = open_im((XLCd)new_lcd, display, rdb, res_name, res_class);
         if (xim) {
           _XCloseLC(lcd);  /* no more need */
           ((XimCommon)xim)->isUnicode = isMultilingual;
           goto Ret;
         }
         _XCloseLC(new_lcd);
         new_lcd = 0;
       }
      }
    }
  }

Ret:
  Xfree(current_locale);
  return xim;
}

Here is the call graph for this function:

static Bool _XimFilterPropertyNotify ( Display *  display,
Window  window,
XEvent *  event,
XPointer  client_data 
) [static]

Definition at line 240 of file XeIMWrap.c.

{
#if 0
    Atom             ims, actual_type, *atoms;
    int                     actual_format;
    unsigned long    nitems, bytes_after;
    Window           ims_window;
    int                     ii;
    XIM                     xim;
    Bool             flag = False;
    XimInstCallback  icb, picb, tmp;

    if( (ims = XInternAtom( display, XIM_SERVERS, True )) == None  ||
       event->xproperty.atom != ims  ||
       event->xproperty.state == PropertyDelete )
       return( False );

    if( XGetWindowProperty( display, RootWindow(display, 0), ims, 0L, 1000000L,
                         False, XA_ATOM, &actual_type, &actual_format,
                         &nitems, &bytes_after, (unsigned char **)&atoms )
           != Success ) {
       return( False );
    }
    if( actual_type != XA_ATOM  ||  actual_format != 32 ) {
       XFree( atoms );
       return( False );
    }

    lock = True;
    for( ii = 0; ii < nitems; ii++, atoms ) {
       if((ims_window = XGetSelectionOwner (display, atoms[ii]))) {
           for( icb = callback_list; icb; icb = icb->next ) {
              if( !icb->call  &&  !icb->destroy ) {
                  xim = (*icb->lcd->methods->open_im)( icb->lcd, display,
                                                  icb->rdb,
                                                  icb->res_name,
                                                  icb->res_class );
                  if( xim ) {
                     xim->methods->close( (XIM)xim );
                     flag = True;
                     icb->call = True;
                     icb->callback( icb->display, icb->client_data, NULL );
                  }
              }
           }
           break;
       }
    }
    XFree( atoms );

    for( icb = callback_list, picb = NULL; icb; ) {
       if( icb->destroy ) {
           if( picb )
              picb->next = icb->next;
           else
              callback_list = icb->next;
           tmp = icb;
           icb = icb->next;
           XFree( tmp );
       }
       else {
           picb = icb;
           icb = icb->next;
       }
    }
    lock = False;

    return( flag );
#else
    return False;
#endif
}

Here is the caller graph for this function:

Bool _XimRegisterIMInstantiateCallback ( XLCd  lcd,
Display *  display,
XrmDatabase  rdb,
char *  res_name,
char *  res_class,
XIDProc  callback,
XPointer  client_data 
)

Definition at line 318 of file XeIMWrap.c.

{
    XimInstCallback  icb, tmp;
    XIM                     xim;
    Window           root;
    XWindowAttributes       attr;

    if( lock )
       return( False );

    icb = (XimInstCallback)Xmalloc(sizeof(XimInstCallbackRec));
    if( !icb )
       return( False );
    icb->call = icb->destroy = False;
    icb->display = display;
    icb->lcd = lcd;
    MakeLocale( lcd, icb->name );
    icb->modifiers = lcd->core->modifiers;       /* XXXXX */
    icb->rdb = rdb;
    icb->res_name = res_name;
    icb->res_class = res_class;
    icb->callback = callback;
    icb->client_data = client_data;
    icb->next = NULL;

    if( !callback_list )
       callback_list = icb;
    else {
       for( tmp = callback_list; tmp->next; tmp = tmp->next );
       tmp->next = icb;
    }

    xim = (*lcd->methods->open_im)( lcd, display, rdb, res_name, res_class );

    if( icb == callback_list ) {
       root = RootWindow( display, 0 );
       XGetWindowAttributes( display, root, &attr );
       _XRegisterFilterByType( display, root, PropertyNotify, PropertyNotify,
                            _XimFilterPropertyNotify, (XPointer)NULL );
       XSelectInput( display, root,
                    attr.your_event_mask | PropertyChangeMask );
    }

    if( xim ) {
       lock = True;
       xim->methods->close( (XIM)xim );
       lock = False;
       icb->call = True;
       callback( display, client_data, NULL );
    }

    return( True );
}

Here is the call graph for this function:

void _XimResetIMInstantiateCallback ( XIM  xim)

Definition at line 436 of file XeIMWrap.c.

{
    char              locale[NAME_LEN];
    XimInstCallback   icb;
    XLCd              lcd = xim->core.lcd;

    if( !callback_list  &&  lock )
       return;

    MakeLocale( lcd, locale );

    for( icb = callback_list; icb; icb = icb->next )
       if( !strcmp( locale, icb->name )  &&
           (lcd->core->modifiers == icb->modifiers  ||
            (lcd->core->modifiers  &&  icb->modifiers  &&
             !strcmp( lcd->core->modifiers, icb->modifiers ))) )
           icb->call = False;
}

Here is the call graph for this function:

Bool _XimUnRegisterIMInstantiateCallback ( XLCd  lcd,
Display *  display,
XrmDatabase  rdb,
char *  res_name,
char *  res_class,
XIDProc  callback,
XPointer  client_data 
)

Definition at line 381 of file XeIMWrap.c.

{
    char locale[NAME_LEN];
    XimInstCallback  icb, picb;

    if (!callback_list)
       return False;

    MakeLocale( lcd, locale );

    for( icb = callback_list, picb = NULL; icb; picb = icb, icb = icb->next ) {
       if( !strcmp( locale, icb->name )  &&
           (lcd->core->modifiers == icb->modifiers  ||         /* XXXXX */
            (lcd->core->modifiers  &&  icb->modifiers  &&
             !strcmp( lcd->core->modifiers, icb->modifiers )))  &&
           rdb == icb->rdb  &&                                 /* XXXXX */
           ((res_name == NULL  &&  icb->res_name == NULL)  ||
            (res_name != NULL  &&  icb->res_name != NULL  &&
             !strcmp( res_name, icb->res_name )))  &&
           ((res_class == NULL  &&  icb->res_class == NULL)  ||
            (res_class != NULL  &&  icb->res_class != NULL  &&
             !strcmp( res_class, icb->res_class )))  &&
           callback == icb->callback  &&
           client_data  ==  icb->client_data  &&        /* XXXXX */
           !icb->destroy ) {
           if( lock )
              icb->destroy = True;
           else {
              if( !picb ) {
                  callback_list = icb->next;
                  _XUnregisterFilter( display, RootWindow(display, 0),
                                   _XimFilterPropertyNotify,
                                   (XPointer)NULL );
                  XSelectInput( display, RootWindow(display, 0),
                              NoEventMask );
              }
              else
                  picb->next = icb->next;
              _XCloseLC( icb->lcd );
              XFree( icb );
           }
           return( True );
       }
    }
    return( False );
}

Here is the call graph for this function:

static int getXIMArg ( XIMArg arg,
char *  name,
void *  value 
) [static]

Definition at line 61 of file XeIMWrap.c.

                                  {
  XIMArg *p;

  for (p = arg; p->name != 0; p++) {
    if (!strcmp(p->name, XNMultiLingualInput)) {
      *((Bool*)value) = (Bool)p->value;
      return 0;
    }
  }
  return -1;
}

Here is the caller graph for this function:

static void MakeLocale ( XLCd  lcd,
char  locale[] 
) [static]

Definition at line 219 of file XeIMWrap.c.

{
  char *language, *territory, *codeset;

  _XGetLCValues(lcd, XlcNLanguage, &language,
              XlcNTerritory, &territory,
              XlcNCodeset, &codeset, NULL);

  _genutil_strlcpy(locale, language, NAME_LEN);
  if (territory && *territory) {
    _genutil_strlcat(locale, "_", NAME_LEN);
    _genutil_strlcat(locale, territory, NAME_LEN);
  }
  if (codeset && *codeset) {
    _genutil_strlcat(locale, ".", NAME_LEN);
    _genutil_strlcat(locale, codeset, NAME_LEN);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 214 of file XeIMWrap.c.

Bool lock = False [static]

Definition at line 215 of file XeIMWrap.c.