Back to index

im-sdk  12.3.91
XimpRm.c
Go to the documentation of this file.
00001 /*
00002 Copyright 1985, 1986, 1987, 1991, 1998  The Open Group
00003 
00004 Portions Copyright 2000 Sun Microsystems, Inc. All Rights Reserved.
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a
00007 copy of this software and associated documentation files (the
00008 "Software"), to deal in the Software without restriction, including
00009 without limitation the rights to use, copy, modify, merge, publish,
00010 distribute, sublicense, and/or sell copies of the Software, and to
00011 permit persons to whom the Software is furnished to do so, subject to
00012 the following conditions: The above copyright notice and this
00013 permission notice shall be included in all copies or substantial
00014 portions of the Software.
00015 
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00018 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00019 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00020 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00021 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00022 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00023 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00024 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00025 
00026 
00027 Except as contained in this notice, the names of The Open Group and/or
00028 Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00029 promote the sale, use or other dealings in this Software without prior
00030 written authorization from The Open Group and/or Sun Microsystems,
00031 Inc., as applicable.
00032 
00033 
00034 X Window System is a trademark of The Open Group
00035 
00036 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00037 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00038 Group. All other trademarks and registered trademarks mentioned herein
00039 are the property of their respective owners. No right, title or
00040 interest in or to any trademark, service mark, logo or trade name of
00041 Sun Microsystems, Inc. or its licensors is granted.
00042 
00043 */
00044 /* $XimpImplementGroup: XimpRm.c, v 1.1 94/05/31 21:16:07 $ */
00045 /* $XConsortium: XimpRm.c,v 1.6 92/10/19 19:26:16 rws Exp $ */
00046 /******************************************************************
00047 
00048               Copyright 1991, 1992 by FUJITSU LIMITED
00049              Copyright 1991, 1992 by Sun Microsystems, Inc.
00050               Copyright 1991, 1992 by Sony Corporation
00051 
00052 Permission to use, copy, modify, distribute, and sell this software
00053 and its documentation for any purpose is hereby granted without fee,
00054 provided that the above copyright notice appear in all copies and
00055 that both that copyright notice and this permission notice appear
00056 in supporting documentation, and that the name of FUJITSU LIMITED,
00057 Sun Microsystems, Inc. and Sony Corporation not be used in advertising 
00058 or publicity pertaining to distribution of the software without specific,
00059 written prior permission.
00060 FUJITSU LIMITED, Sun Microsystems, Inc. and Sony Corporation make no 
00061 representations about the suitability of this software for any purpose.
00062 It is provided "as is" without express or implied warranty.
00063 
00064 FUJITSU LIMITED, SUN MICROSYSTEMS, INC. AND SONY CORPORATION DISCLAIM 
00065 ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED 
00066 WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJITSU
00067 LIMITED, SUN MICROSYSTEMS, INC. AND SONY CORPORATION BE LIABLE FOR ANY
00068 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
00069 RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
00070 CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
00071 CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00072 
00073   Author: Takashi Fujiwara     FUJITSU LIMITED 
00074           Hiromu Inukai        Sun Microsystems, Inc.
00075           Hideki Hiura         Sun Microsystems, Inc.
00076          Makoto Wakamatsu     Sony Corporation
00077 
00078 ******************************************************************/
00079 /*
00080 
00081 Copyright (c) 1991 - 1994  FUJITSU LIMITED
00082 Copyright (c) 1991 - 1994  Sony Corporation
00083 
00084 Permission is hereby granted, free of charge, to any person obtaining
00085 a copy of this software and associated documentation files (the
00086 "Software"), to deal in the Software without restriction, including
00087 without limitation the rights to use, copy, modify, merge, publish,
00088 distribute, sublicense, and/or sell copies of the Software, and to
00089 permit persons to whom the Software is furnished to do so, subject to
00090 the following conditions:
00091 
00092 The above copyright notice and this permission notice shall be included
00093 in all copies or substantial portions of the Software.
00094 
00095 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00096 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00097 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00098 IN NO EVENT SHALL THE FUJITSU LIMITED AND SONY CORPORATION BE LIABLE FOR
00099 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00100 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00101 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00102 
00103 Except as contained in this notice, the name of the FUJITSU LIMITED and
00104 Sony Corporation shall not be used in advertising or otherwise to promote
00105 the sale, use or other dealings in this Software without prior written
00106 authorization from the FUJITSU LIMITED and Sony Corporation.
00107 
00108   Author: Takashi Fujiwara     FUJITSU LIMITED 
00109          Makoto Wakamatsu     Sony Corporation
00110 
00111 */
00112 
00113 #define NEED_EVENTS
00114 #include <X11/keysym.h>
00115 #include <X11/Xlibint.h>
00116 
00117 #include "XimpIm.h"
00118 #include "genutil.h"
00119 
00120 #ifndef       isalnum
00121 #define       isalnum(c)    \
00122     (('0' <= (c) && (c) <= '9')  || \
00123      ('A' <= (c) && (c) <= 'Z')  || \
00124      ('a' <= (c) && (c) <= 'z'))
00125 #endif
00126 
00127 #define RES_BUFSIZE 256
00128 
00129 Private void
00130 _Ximp_Get_resource_name(im, res_name, res_class,
00131                      res_name_len, res_class_len,
00132                      res_n, res_c)
00133     Ximp_XIM   im;
00134     char      *res_name;
00135     char      *res_class;
00136     char      *res_n;
00137     char      *res_c;
00138 {
00139   size_t len;
00140 
00141   if (im->core.res_name == NULL) {
00142     if ((len = _genutil_strlcpy(res_name, "*ximp.", res_name_len)) >= res_name_len)
00143       goto set_res_class;
00144     if ((len = _genutil_strlcat(res_name, res_n, res_name_len)) >= res_name_len)
00145       goto set_res_class;
00146   } else {
00147     if ((len = _genutil_strlcpy(res_name, im->core.res_name, res_name_len)) >= res_name_len)
00148       goto set_res_class;
00149     if ((len = _genutil_strlcat(res_name, ".ximp.", res_name_len)) >= res_name_len)
00150       goto set_res_class;
00151     if ((len = _genutil_strlcat(res_name, res_n, res_name_len)) >= res_name_len)
00152       goto set_res_class;
00153   }
00154 
00155  set_res_class:
00156   if (im->core.res_class == NULL) {
00157     if ((len = _genutil_strlcpy(res_class, "*Ximp.", res_class_len)) >= res_class_len)
00158       goto ret;
00159     if ((len = _genutil_strlcat(res_class, res_c, res_class_len)) >= res_class_len)
00160       goto ret;
00161   } else {
00162     if ((len = _genutil_strlcpy(res_class, im->core.res_class, res_class_len)) >= res_class_len)
00163       goto ret;
00164     if ((len = _genutil_strlcat(res_class, ".Ximp.", res_class_len)) >= res_class_len)
00165       goto ret;
00166     if ((len = _genutil_strlcat(res_class, res_c, res_class_len)) >= res_class_len)
00167       goto ret;
00168   }
00169 
00170  ret:
00171   return;
00172 }
00173 
00174 Private void
00175 _Ximp_parse( im, event )
00176     Ximp_XIM          im;
00177     char             *event;
00178 {
00179     Ximp_Key         key;
00180     char             *modifier, *detail;
00181     char             *ss;
00182     int                     ii = 0;
00183     Bool             exclamation, tilde;
00184     Ximp_KeyList     *keylist;
00185     static struct {
00186        char   *name;
00187        int    len;
00188        long   mask;
00189     } mod[] = {
00190        { "Ctrl",     4,     ControlMask   },
00191        { "Lock",     4,     LockMask      },
00192        { "Caps",     4,     LockMask      },
00193        { "Shift",    5,     ShiftMask     },
00194        { "Alt",      3,     Mod1Mask      },
00195        { "Meta",     4,     Mod1Mask      },
00196        { NULL,              0,     0             }};
00197 #define       AllMask       (ControlMask | LockMask | ShiftMask | Mod1Mask)
00198 
00199     if( (ss = strstr( event, "<Key>" )) == NULL )
00200        return;
00201     detail = ss + 5;
00202     *ss = 0;
00203 
00204     modifier = event;
00205     key.modifier = 0;
00206     key.modifier_mask = 0;
00207     key.keysym = XK_VoidSymbol;
00208     exclamation = False;
00209     do {
00210        while( *modifier == ' '  ||  *modifier == '\t' )
00211            modifier++;
00212        if( *modifier == 0)
00213            break;
00214        if( strncmp( modifier, "None", 4 ) == 0 ) {
00215            if( key.modifier_mask != 0  ||  exclamation )
00216               return;
00217            key.modifier_mask = AllMask;
00218            modifier += 4;
00219        } else {
00220            if( *modifier == '!' ) {
00221               if( key.modifier_mask != 0  ||  exclamation )
00222                   return;
00223               key.modifier_mask = AllMask;
00224               exclamation = True;
00225               modifier++;
00226               continue;
00227            }
00228            if( (tilde = (*modifier == '~')) ) {
00229               modifier++;
00230               while( *modifier == ' '  ||  *modifier == '\t' )
00231                   modifier++;
00232            }
00233            for( ii = 0; mod[ii].name != NULL; ii++ ) {
00234               if( strncmp( modifier, mod[ii].name, mod[ii].len ) == 0 ) {
00235                   key.modifier_mask |= mod[ii].mask;
00236                   if( !tilde )
00237                      key.modifier |= mod[ii].mask;
00238                   modifier += mod[ii].len;
00239                   break;
00240               }
00241            }
00242        }
00243        if( mod[ii].name == NULL )
00244            return;
00245     } while( *modifier != 0);
00246 
00247     while( *detail == ' '  ||  *detail == '\t' )
00248        detail++;
00249     for( ss = detail; isalnum(*ss)  ||  *ss == '_'; ss++ );
00250     *ss = 0;
00251     if( (key.keysym = XStringToKeysym( detail )) != NoSymbol ) {
00252        if( !(keylist = im->ximp_impart->process_start_keys) ) {
00253            if( (keylist = (Ximp_KeyList *)Xcalloc(1, sizeof(Ximp_KeyList))) == NULL )
00254               return;
00255            if((keylist->keys_list = (Ximp_Key *)Xmalloc(sizeof(Ximp_Key))) == NULL) {
00256               Xfree( keylist );
00257               return;
00258            }
00259        } else {
00260            Ximp_Key  *keys_list;
00261            if( (keys_list = (Ximp_Key *)Xrealloc(keylist->keys_list, sizeof(Ximp_Key) * (keylist->count_keys + 1))) == NULL )
00262               return;
00263            keylist->keys_list = keys_list;
00264        }
00265        keylist->keys_list[keylist->count_keys] = key;
00266        keylist->count_keys++;
00267        im->ximp_impart->process_start_keys = keylist;
00268     }
00269     return;
00270 }
00271 
00272 Private void
00273 _Ximp_InputServerMode(im)
00274     Ximp_XIM          im;
00275 {
00276     char              res_name[RES_BUFSIZE];
00277     char              res_class[RES_BUFSIZE];
00278     char             *str_type;
00279     XrmValue          value;
00280     KeySym            keysym = NoSymbol;
00281     Ximp_KeyList     *keylist;
00282     XIMStyles        *imstyles;
00283     XIMStyle          imstyle1, imstyle2;
00284 
00285     MAKE_CONNECTABLE(im);
00286 
00287     _Ximp_Get_resource_name(im, res_name, res_class,
00288                          RES_BUFSIZE, RES_BUFSIZE,
00289                          "inputserver", "Inputserver");
00290     if((XrmGetResource(im->core.rdb, res_name, res_class,&str_type, &value) == True)
00291        && (strcmp(value.addr, "on") == 0) ) {
00292        MAKE_UNCONNECTABLE(im) ;
00293     }
00294 
00295     _Ximp_Get_resource_name(im, res_name, res_class,
00296                          RES_BUFSIZE, RES_BUFSIZE,
00297                          "delaybinding", "Delaybinding");
00298     if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value) == True) { 
00299        if(strcmp(value.addr, "OFF") == 0 || 
00300           strcmp(value.addr, "off") == 0) {
00301            MAKE_UNDELAYBINDABLE(im);
00302        }
00303     }
00304 
00305     _Ximp_Get_resource_name(im, res_name, res_class,
00306                          RES_BUFSIZE, RES_BUFSIZE,
00307                          "reconnect", "Reconnect");
00308     if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value) == True) { 
00309        if(strcmp(value.addr, "OFF") == 0 || 
00310           strcmp(value.addr, "off") == 0) {
00311            MAKE_UNRECONNECTABLE(im) ;
00312        }
00313     }
00314 
00315     _Ximp_Get_resource_name(im, res_name, res_class,
00316                          RES_BUFSIZE, RES_BUFSIZE,
00317                          "restart", "Restart");
00318     if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value) == True) { 
00319        if(strcmp(value.addr, "OFF") == 0 || 
00320           strcmp(value.addr, "off") == 0) {
00321            MAKE_UNRESTARTABLE(im) ;
00322        }
00323     }
00324 
00325     if(IS_UNCONNECTABLE(im))
00326        return; 
00327 
00328     /* Keysym */
00329     _Ximp_Get_resource_name(im, res_name, res_class,
00330                          RES_BUFSIZE, RES_BUFSIZE,
00331                          "startkeysym", "Startkeysym");
00332     if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value) == True) { 
00333        keysym = XStringToKeysym(value.addr);
00334     }
00335     if(keysym != NoSymbol) {
00336        if((keylist = (Ximp_KeyList *)Xmalloc(sizeof(Ximp_KeyList))) != NULL ) {
00337            if((keylist->keys_list = (Ximp_Key *)Xmalloc(sizeof(Ximp_Key)))!= NULL) {
00338               keylist->count_keys = 1;
00339               keylist->keys_list[0].modifier = 0;
00340               keylist->keys_list[0].modifier_mask = 0;
00341               keylist->keys_list[0].keysym = keysym;
00342               im->ximp_impart->process_start_keys = keylist;
00343            } else
00344               Xfree(keylist);
00345        }
00346     }
00347 
00348     /* ProcessStartKeys */
00349     _Ximp_Get_resource_name(im, res_name, res_class,
00350                          RES_BUFSIZE, RES_BUFSIZE,
00351                          "processStartKeys", "ProcessStartKeys");
00352     if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)  == True) {
00353        char   *string, *ss, c;
00354        char   *line;
00355 
00356        if( (line = Xmalloc(value.size)) != NULL ) {
00357            string = value.addr;
00358            do {
00359               ss = line;
00360               while( (c = *string) != 0 ) {
00361                   string++;
00362                   if( c == '\n' )
00363                      break;
00364                   *ss++ = c;
00365               }
00366               *ss = 0;
00367               _Ximp_parse( im, line );
00368            } while( *string != 0 );
00369            Xfree( line );
00370        }
00371     }
00372 
00373     if(im->ximp_impart->process_start_keys == (Ximp_KeyList *)NULL) {
00374 #ifdef sun
00375        if((keylist = (Ximp_KeyList *)Xmalloc(sizeof(Ximp_KeyList))) != NULL ) {
00376            if((keylist->keys_list = (Ximp_Key *)Xmalloc(sizeof(Ximp_Key)*4))!= NULL) {
00377               keylist->count_keys = 4;
00378               keylist->keys_list[0].modifier = ControlMask;
00379               keylist->keys_list[0].modifier_mask = ControlMask|ShiftMask;
00380               keylist->keys_list[0].keysym = XK_space;
00381               keylist->keys_list[1].modifier = 0;
00382               keylist->keys_list[1].modifier_mask = ControlMask|ShiftMask;
00383               keylist->keys_list[1].keysym = XK_Kanji;
00384               keylist->keys_list[2].modifier = ControlMask;
00385               keylist->keys_list[2].modifier_mask = ControlMask|ShiftMask;
00386               keylist->keys_list[2].keysym = XK_at;
00387               keylist->keys_list[3].modifier = ControlMask|ShiftMask;
00388               keylist->keys_list[3].modifier_mask = ControlMask|ShiftMask;
00389               keylist->keys_list[3].keysym = XK_at;
00390               im->ximp_impart->process_start_keys = keylist;
00391            } else {
00392               Xfree(keylist);
00393               MAKE_UNCONNECTABLE(im) ;
00394            }
00395        }
00396 #else  
00397        MAKE_UNCONNECTABLE(im) ;
00398 #endif
00399     }
00400 
00401     if(IS_DELAYBINDABLE(im)) {
00402        imstyle1 = imstyle2 = 0;
00403        _Ximp_Get_resource_name(im, res_name, res_class,
00404                             RES_BUFSIZE, RES_BUFSIZE,
00405                             "preeditDefaultStyle",
00406                             "PreeditDefaultStyle");
00407        if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value) == True) { 
00408            if(strcmp(value.addr, "XIMPreeditArea") == 0)
00409               imstyle1 = XIMPreeditArea;
00410            else if(strcmp(value.addr, "XIMPreeditCallbacks") == 0)
00411               imstyle1 = XIMPreeditCallbacks;
00412            else if(strcmp(value.addr, "XIMPreeditPosition") == 0)
00413               imstyle1 = XIMPreeditPosition;
00414            else if(strcmp(value.addr, "XIMPreeditNothing") == 0)
00415               imstyle1 = XIMPreeditNothing;
00416            else if(strcmp(value.addr, "XIMPreeditNone") == 0)
00417               imstyle1 = XIMPreeditNone;
00418        }
00419        if(imstyle1 == 0)
00420            imstyle1 = XIMPreeditNothing;
00421        _Ximp_Get_resource_name(im, res_name, res_class,
00422                             RES_BUFSIZE, RES_BUFSIZE,
00423                             "statusDefaultStyle",
00424                             "StatusDefaultStyle");
00425        if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value) == True) { 
00426            if(strcmp(value.addr, "XIMStatusArea") == 0)
00427               imstyle2 = XIMStatusArea;
00428            else if(strcmp(value.addr, "XIMStatusCallbacks") == 0)
00429               imstyle2 = XIMStatusCallbacks;
00430            else if(strcmp(value.addr, "XIMStatusNothing") == 0)
00431               imstyle2 = XIMStatusNothing;
00432            else if(strcmp(value.addr, "XIMStatusNone") == 0)
00433               imstyle2 = XIMStatusNone;
00434        }
00435        if(imstyle2 == 0)
00436            imstyle2 = XIMStatusNothing;
00437 
00438        if((imstyles = (XIMStyles *)Xmalloc(sizeof(XIMStyles) + sizeof(XIMStyle))) == NULL)
00439            return;
00440        imstyles->count_styles = 1;
00441        imstyles->supported_styles = (XIMStyle *)((char *)imstyles + sizeof(XIMStyles));
00442        imstyles->supported_styles[0] = imstyle1 | imstyle2;
00443        im->ximp_impart->delaybind_styles = imstyles;
00444     }
00445     return;
00446 }
00447 
00448 Private void
00449 _Ximp_CallBackWchar(im)
00450     Ximp_XIM          im;
00451 {
00452     char              res_name[RES_BUFSIZE];
00453     char              res_class[RES_BUFSIZE];
00454     char             *str_type;
00455     XrmValue          value;
00456 
00457     _Ximp_Get_resource_name(im, res_name, res_class,
00458                          RES_BUFSIZE, RES_BUFSIZE,
00459                          "callbackEncoding",
00460                          "CallbackEncoding");
00461     if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value) == True) {
00462        if(strcmp(value.addr, "wchar") == 0) {
00463            im->ximp_impart->use_wchar = True;
00464        }
00465     }
00466     return;
00467 }
00468 
00469 Private void
00470 _Ximp_ForceSelectKeyRelease(im)
00471     Ximp_XIM          im;
00472 {
00473     char              res_name[RES_BUFSIZE];
00474     char              res_class[RES_BUFSIZE];
00475     char             *str_type;
00476     XrmValue          value;
00477 
00478     _Ximp_Get_resource_name(im, res_name, res_class,
00479                          RES_BUFSIZE, RES_BUFSIZE,
00480                          "forceSelectKeyRelease",
00481                          "ForceSelectKeyRelease");
00482     if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value) == True) {
00483        if(strcmp(value.addr, "yes") == 0) {          /* Ximp 4.0 */
00484            im->ximp_impart->is_forceselectkeyrelease = True;
00485        }
00486     }
00487     return;
00488 }
00489 
00490 Private int
00491 _Ximp_Environ()
00492 {
00493     char      *env_p;
00494     int               ret = XIMP_FE_TYPE1;
00495 
00496     if((env_p = (char *)getenv("XIMP_TYPE")) != (char *)NULL) {
00497        if(strcmp(env_p, "XIMP_FE_TYPE1") == 0)
00498            ret = XIMP_FE_TYPE1;
00499        else if(strcmp(env_p, "XIMP_FE_TYPE2") == 0)
00500            ret = XIMP_FE_TYPE2;
00501        else if(strcmp(env_p, "XIMP_FE_TYPE3") == 0)
00502            ret = XIMP_FE_TYPE3;
00503        else if(strcmp(env_p, "XIMP_BE_TYPE1") == 0)
00504            ret = XIMP_BE_TYPE1;
00505        else if(strcmp(env_p, "XIMP_BE_TYPE2") == 0)
00506            ret = XIMP_BE_TYPE2;
00507        else if(strcmp(env_p, "XIMP_SYNC_BE_TYPE1") == 0)
00508            ret = XIMP_SYNC_BE_TYPE1;
00509        else if(strcmp(env_p, "XIMP_SYNC_BE_TYPE2") == 0)
00510            ret = XIMP_SYNC_BE_TYPE2;
00511     }
00512     return(ret);
00513 }
00514 
00515 Private int
00516 _Ximp_InputTypeResource(im)
00517     Ximp_XIM          im;
00518 {
00519     char              res_name[RES_BUFSIZE];
00520     char              res_class[RES_BUFSIZE];
00521     char             *str_type;
00522     XrmValue          value;
00523     int               ret = XIMP_FE_TYPE1;
00524 
00525     _Ximp_Get_resource_name(im, res_name, res_class,
00526                          RES_BUFSIZE, RES_BUFSIZE,
00527                          "immode", "Immode");
00528     if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value) == True) {
00529        if(strcmp(value.addr, "XIMP_FE_TYPE1") == 0)
00530            ret = XIMP_FE_TYPE1;
00531        else if(strcmp(value.addr, "XIMP_FE_TYPE2") == 0)
00532            ret = XIMP_FE_TYPE2;
00533        else if(strcmp(value.addr, "XIMP_FE_TYPE3") == 0)
00534            ret = XIMP_FE_TYPE3;
00535        else if(strcmp(value.addr, "XIMP_BE_TYPE1") == 0)
00536            ret = XIMP_BE_TYPE1;
00537        else if(strcmp(value.addr, "XIMP_BE_TYPE2") == 0)
00538            ret = XIMP_BE_TYPE2;
00539        else if(strcmp(value.addr, "XIMP_SYNC_BE_TYPE1") == 0)
00540            ret = XIMP_SYNC_BE_TYPE1;
00541        else if(strcmp(value.addr, "XIMP_SYNC_BE_TYPE2") == 0)
00542            ret = XIMP_SYNC_BE_TYPE2;
00543        return(ret);
00544     }
00545     return(-1);
00546 }
00547 
00548 Public void
00549 _Ximp_OpenIM_Resource(im)
00550     Ximp_XIM   im;
00551 {
00552     int               mode;
00553 
00554     im->ximp_impart->def_svr_mode = _Ximp_Environ(); /* server input type */ 
00555 
00556     /*
00557      * We want to make clients reconnectable if that client
00558      * did not pass a valid resource id at XOpenIM()
00559      */
00560 #ifdef sun
00561     MAKE_RECONNECTABLE(im);
00562 #endif
00563 
00564     if(im->core.rdb == NULL)
00565        return;
00566 
00567     /* Inputserver */
00568     _Ximp_InputServerMode(im);
00569 
00570     /* Input Type */
00571     if((mode = _Ximp_InputTypeResource(im)) != -1)
00572        im->ximp_impart->def_svr_mode = mode;
00573 
00574     /* Call Back */
00575     _Ximp_CallBackWchar(im);
00576 
00577     /* Force Select KeyRelease support */
00578     _Ximp_ForceSelectKeyRelease(im);
00579 
00580     return;
00581 }
00582 
00583 Public void
00584 _Ximp_SetValue_Resource(ic, mask)
00585     Ximp_XIC          ic;
00586     XimpChangeaMask   mask;
00587 {
00588     Ximp_XIM   im;
00589     char       res_name[RES_BUFSIZE];
00590     char       res_class[RES_BUFSIZE];
00591     char      *str_type ;
00592     XrmValue   value;
00593     Colormap   default_colormap;
00594     XColor     screen_def, exact_def;
00595     int               num, mode;
00596     
00597     im = (Ximp_XIM)XIMOfIC((XIC)ic);
00598     if(im->core.rdb == NULL)
00599        return;
00600 
00601     if(!(XIMP_CHK_SERVERTYPEMASK(ic))) {
00602        if((mode = _Ximp_InputTypeResource(im)) != -1) {
00603            ic->ximp_icpart->svr_mode = mode;
00604            XIMP_SET_SERVERTYPEMASK(ic, mask);
00605        }
00606     }
00607 
00608     if(!(   (ic->core.input_style & XIMPreeditCallbacks)
00609          || (ic->core.input_style & XIMPreeditNone) ) ) {
00610        if(!(XIMP_CHK_PREBGMASK(ic))) {
00611            _Ximp_Get_resource_name(im, res_name, res_class,
00612                                 RES_BUFSIZE, RES_BUFSIZE,
00613                                 "preedit.background",
00614                                 "Preedit.Background");
00615            if(XrmGetResource(im->core.rdb, res_name, res_class,
00616                               &str_type, &value) == True) { 
00617               default_colormap = DefaultColormap(
00618                                           im->core.display,
00619                                           DefaultScreen(im->core.display) );
00620               if( XAllocNamedColor(im->core.display, default_colormap,
00621                                     value.addr,
00622                                     &screen_def, &exact_def) ) {
00623                   ic->core.preedit_attr.background = screen_def.pixel;
00624                   ic->ximp_icpart->preedit_attr.Background = 
00625                             ic->core.preedit_attr.background;
00626                   XIMP_SET_PREBGMASK(ic, mask);
00627               }
00628            }
00629        }
00630        if(!(XIMP_CHK_PREFGMASK(ic))) {
00631            _Ximp_Get_resource_name(im, res_name, res_class,
00632                                 RES_BUFSIZE, RES_BUFSIZE,
00633                                 "preedit.foreground",
00634                                 "Preedit.Foreground");
00635            if(XrmGetResource(im->core.rdb, res_name, res_class,
00636                               &str_type, &value) == True) { 
00637               default_colormap = DefaultColormap(
00638                                           im->core.display,
00639                                           DefaultScreen(im->core.display) );
00640               if( XAllocNamedColor(im->core.display, default_colormap,
00641                                     value.addr,
00642                                     &screen_def, &exact_def) ) {
00643                   ic->core.preedit_attr.foreground = screen_def.pixel;
00644                   ic->ximp_icpart->preedit_attr.Foreground = 
00645                             ic->core.preedit_attr.foreground;
00646                   XIMP_SET_PREBGMASK(ic, mask);
00647               }
00648            }
00649        }
00650        if(!(XIMP_CHK_PRELINESPMASK(ic))) {
00651            _Ximp_Get_resource_name(im, res_name, res_class,
00652                                 RES_BUFSIZE, RES_BUFSIZE,
00653                                 "preedit.linespacing",
00654                                 "Preedit.Linespacing");
00655            if(XrmGetResource(im->core.rdb, res_name, res_class,
00656                               &str_type, &value) == True) { 
00657               num = atoi(value.addr);
00658               ic->core.preedit_attr.line_spacing = num;
00659               ic->ximp_icpart->preedit_attr.LineSpacing = 
00660                      ic->core.preedit_attr.line_spacing;
00661               XIMP_SET_PRELINESPMASK(ic, mask);
00662            }
00663        }
00664     }
00665 
00666     if(!(   (ic->core.input_style & XIMStatusCallbacks)
00667          || (ic->core.input_style & XIMStatusNone) ) ) {
00668        if(!(XIMP_CHK_STSBGMASK(ic))) {
00669            _Ximp_Get_resource_name(im, res_name, res_class,
00670                                 RES_BUFSIZE, RES_BUFSIZE,
00671                                 "status.background",
00672                                 "Status.Background");
00673            if(XrmGetResource(im->core.rdb, res_name, res_class,
00674                               &str_type, &value) == True) { 
00675            default_colormap = DefaultColormap(im->core.display,
00676                                           DefaultScreen(im->core.display) );
00677            if( XAllocNamedColor(im->core.display, default_colormap,
00678                              value.addr,
00679                              &screen_def, &exact_def) ) {
00680               ic->core.status_attr.background = screen_def.pixel;
00681               ic->ximp_icpart->status_attr.Background = 
00682                      ic->core.status_attr.background;
00683               XIMP_SET_STSBGMASK(ic, mask);
00684               }
00685            }
00686        }
00687        if(!(XIMP_CHK_STSFGMASK(ic))) {
00688            _Ximp_Get_resource_name(im, res_name, res_class,
00689                                 RES_BUFSIZE, RES_BUFSIZE,
00690                                 "status.foreground",
00691                                 "Status.Foreground");
00692            if(XrmGetResource(im->core.rdb, res_name, res_class,
00693                               &str_type, &value) == True) { 
00694            default_colormap = DefaultColormap(im->core.display,
00695                                           DefaultScreen(im->core.display) );
00696            if( XAllocNamedColor(im->core.display, default_colormap,
00697                              value.addr,
00698                              &screen_def, &exact_def) ) {
00699               ic->core.status_attr.foreground = screen_def.pixel;
00700               ic->ximp_icpart->status_attr.Foreground = 
00701                      ic->core.status_attr.foreground;
00702               XIMP_SET_STSFGMASK(ic, mask);
00703               }
00704            }
00705        }
00706        if(!(XIMP_CHK_STSLINESPMASK(ic))) {
00707            _Ximp_Get_resource_name(im, res_name, res_class,
00708                                 RES_BUFSIZE, RES_BUFSIZE,
00709                                 "status.linespacing",
00710                                 "Status.Linespacing");
00711            if(XrmGetResource(im->core.rdb, res_name, res_class,
00712                               &str_type, &value) == True) { 
00713               num = atoi(value.addr);
00714               ic->core.status_attr.line_spacing = num;
00715               ic->ximp_icpart->status_attr.LineSpacing = 
00716                      ic->core.status_attr.line_spacing;
00717               XIMP_SET_STSLINESPMASK(ic, mask);
00718            }
00719        }
00720     }
00721 
00722     if(   (ic->ximp_icpart->value_mask & XIMP_RES_NAME)
00723        || (ic->ximp_icpart->value_mask & XIMP_RES_CLASS) )
00724        ic->ximp_icpart->value_mask &= ~(XIMP_RES_NAME | XIMP_RES_CLASS);
00725     return;
00726 }