home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / Xim_Wrap.c < prev    next >
C/C++ Source or Header  |  1999-11-02  |  8KB  |  260 lines

  1. /*
  2.  * $XConsortium: IMWrap.c /main/13 1996/01/05 11:22:19 kaleb $
  3.  * $XFree86: xc/lib/X11/IMWrap.c,v 3.4.4.1 1998/10/04 13:36:18 hohndel Exp $
  4.  */
  5.  
  6. /*
  7.  * Copyright 1991 by the Open Software Foundation
  8.  * Copyright 1993, 1994 by the Sony Corporation
  9.  *
  10.  * Permission to use, copy, modify, distribute, and sell this software and its
  11.  * documentation for any purpose is hereby granted without fee, provided that
  12.  * the above copyright notice appear in all copies and that both that
  13.  * copyright notice and this permission notice appear in supporting
  14.  * documentation, and that the names of Open Software Foundation and
  15.  * Sony Corporation not be used in advertising or publicity pertaining to 
  16.  * distribution of the software without specific, written prior permission.  
  17.  * Open Software Foundation and Sony Corporation make no 
  18.  * representations about the suitability of this software for any purpose.  
  19.  * It is provided "as is" without express or implied warranty.
  20.  *
  21.  * OPEN SOFTWARE FOUNDATION AND SONY CORPORATION DISCLAIM ALL
  22.  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
  23.  * WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL OPEN
  24.  * SOFTWARE FOUNDATIONN OR SONY CORPORATION BE LIABLE FOR ANY SPECIAL,
  25.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  26.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  27.  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  28.  * PERFORMANCE OF THIS SOFTWARE. 
  29.  * 
  30.  *         M. Collins        OSF  
  31.  *               Makoto Wakamatsu       Sony Corporation
  32.  */                
  33. /*
  34.  
  35. Copyright (c) 1991  X Consortium
  36.  
  37. Permission is hereby granted, free of charge, to any person obtaining
  38. a copy of this software and associated documentation files (the
  39. "Software"), to deal in the Software without restriction, including
  40. without limitation the rights to use, copy, modify, merge, publish,
  41. distribute, sublicense, and/or sell copies of the Software, and to
  42. permit persons to whom the Software is furnished to do so, subject to
  43. the following conditions:
  44.  
  45. The above copyright notice and this permission notice shall be included
  46. in all copies or substantial portions of the Software.
  47.  
  48. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  49. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  50. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  51. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
  52. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  53. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  54. OTHER DEALINGS IN THE SOFTWARE.
  55.  
  56. Except as contained in this notice, the name of the X Consortium shall
  57. not be used in advertising or otherwise to promote the sale, use or
  58. other dealings in this Software without prior written authorization
  59. from the X Consortium.
  60.  
  61. */
  62.  
  63. #include "Xlib_private.h"
  64. #include "Xlcint.h"
  65.  
  66. /*
  67.  * Compile the resource name. (resource_name ---> xrm_name)
  68.  */
  69. void
  70. _XIMCompileResourceList(res, num_res)
  71.     register XIMResourceList res;
  72.     unsigned int num_res;
  73. {
  74.     DBUG_ENTER("_XIMCompileResourceList")
  75.     register unsigned int count;
  76.  
  77.     for (count = 0; count < num_res; res++, count++) {
  78.     res->xrm_name = XrmStringToQuark(res->resource_name);
  79.     }
  80.     DBUG_VOID_RETURN;
  81. }
  82.  
  83. void
  84. _XCopyToArg(src, dst, size)
  85.     XPointer src;
  86.     XPointer *dst;
  87.     register unsigned int size;
  88. {
  89.     DBUG_ENTER("_XCopyToArg")
  90.     if (!*dst) {
  91.     union {
  92.         long    longval;
  93. #ifdef LONG64
  94.         int        intval;
  95. #endif
  96.         short    shortval;
  97.         char    charval;
  98.         char*    charptr;
  99.         XPointer    ptr;
  100.     } u;
  101.     if (size <= sizeof(XPointer)) {
  102.         memcpy((char *)&u, (char *)src, (int)size);
  103.         if (size == sizeof(long))           *dst = (XPointer)u.longval;
  104. #ifdef LONG64
  105.         else if (size == sizeof(int))      *dst = (XPointer)(long)u.intval;
  106. #endif
  107.         else if (size == sizeof(short))    *dst = (XPointer)(long)u.shortval;
  108.         else if (size == sizeof(char))     *dst = (XPointer)(long)u.charval;
  109.         else if (size == sizeof(char*))    *dst = (XPointer)u.charptr;
  110.         else if (size == sizeof(XPointer)) *dst = (XPointer)u.ptr;
  111.         else memcpy( (char*)dst, (char*)src, (int)size );
  112.     } else {
  113.         memcpy( (char*)dst, (char*)src, (int)size );
  114.     }
  115.     } else {
  116.     memcpy( (char*)*dst, (char*)src, (int)size );
  117.     }
  118.     DBUG_VOID_RETURN;
  119. }
  120.  
  121. /*
  122.  * Connects to an input method matching current locale specification, creates
  123.  * a XIM object and return a pointer the newly created XIM back to the caller.
  124.  */
  125.  
  126. XIM 
  127. XOpenIM( display, rdb, res_name, res_class )
  128.     Display    *display;
  129.     XrmDatabase     rdb;
  130.     char    *res_name;
  131.     char    *res_class;
  132. {
  133.     DBUG_ENTER("XOpenIM")
  134.     XLCd    lcd = _XOpenLC( (char *)NULL );
  135.     XIM        result;
  136.  
  137.     if( !lcd )
  138.     DBUG_RETURN( (XIM)NULL );
  139.     result = (*lcd->methods->open_im) (lcd, display, rdb, res_name, res_class);
  140.     DBUG_RETURN(result);
  141. }
  142.  
  143. /*
  144.  * Close the connection to the input manager, and free the XIM structure
  145.  */
  146. Status
  147. XCloseIM(im)
  148.     XIM im;
  149. {
  150.     DBUG_ENTER("XCloseIM")
  151.     Status s;
  152.     XIC ic;
  153.     XLCd lcd = im->core.lcd;
  154.   
  155.     s = (im->methods->close) (im);
  156.     for (ic = im->core.ic_chain; ic; ic = ic->core.next)
  157.     ic->core.im = (XIM)NULL;
  158.     Xfree ((char *) im);
  159.     _XCloseLC (lcd);
  160.     DBUG_RETURN(s);
  161. }
  162.  
  163. /*
  164.  * Return the Display associated with the input method.
  165.  */
  166. Display *
  167. XDisplayOfIM(im)
  168.     XIM im;
  169. {
  170.     DBUG_ENTER("XDisplayOfIM")
  171.     Display *result = im->core.display;
  172.     DBUG_RETURN(result);
  173. }
  174.  
  175. /*
  176.  * Return the Locale associated with the input method.
  177.  */
  178. char *
  179. XLocaleOfIM(im)
  180.     XIM im;
  181. {
  182.     DBUG_ENTER("XLocaleOfIM")
  183.     char *result = im->core.lcd->core->name;
  184.     DBUG_RETURN(result);
  185. }
  186.  
  187. /*
  188.  * Register to a input method instantiation callback to prepare the
  189.  * on-demand input method instantiation.
  190.  */
  191. Bool
  192. #if NeedFunctionPrototypes
  193. XRegisterIMInstantiateCallback(
  194.     Display    *display,
  195.     XrmDatabase     rdb,
  196.     char    *res_name,
  197.     char    *res_class,
  198.     XIDProc     callback,
  199.     XPointer     client_data)
  200. #else
  201. XRegisterIMInstantiateCallback( display, rdb, res_name, res_class, callback,
  202.                 client_data)
  203.     Display    *display;
  204.     XrmDatabase     rdb;
  205.     char    *res_name;
  206.     char    *res_class;
  207.     XIDProc     callback;
  208.     XPointer     client_data;
  209. #endif
  210. {
  211.     DBUG_ENTER("XRegisterIMInstantiateCallback")
  212.     XLCd    lcd = _XOpenLC( (char *)NULL );
  213.     Bool    result;
  214.  
  215.     if( !lcd )
  216.     DBUG_RETURN( False );
  217.     result= (*lcd->methods->register_callback)( lcd, display, rdb, res_name,
  218.                         res_class, callback,
  219.                         client_data );
  220.     DBUG_RETURN(result);
  221. }
  222.  
  223. /*
  224.  * Unregister to a input method instantiation callback.
  225.  */
  226. Bool
  227. #if NeedFunctionPrototypes
  228. XUnregisterIMInstantiateCallback(
  229.     Display    *display,
  230.     XrmDatabase     rdb,
  231.     char    *res_name,
  232.     char    *res_class,
  233.     XIDProc     callback,
  234.     XPointer     client_data)
  235. #else
  236. XUnregisterIMInstantiateCallback( display, rdb, res_name, res_class, callback,
  237.                   client_data )
  238.     Display    *display;
  239.     XrmDatabase     rdb;
  240.     char    *res_name;
  241.     char    *res_class;
  242.     XIDProc     callback;
  243.     XPointer     client_data;
  244. #endif
  245. {
  246.     DBUG_ENTER("XUnregisterIMInstantiateCallback")
  247.     XLCd    lcd = _XlcCurrentLC();
  248.     Bool    result;
  249.  
  250.     if( !lcd )
  251.     DBUG_RETURN( False );
  252.     if( lcd->methods->unregister_callback == NULL )
  253.     DBUG_RETURN( False );
  254.     result = (*lcd->methods->unregister_callback)( lcd, display, rdb, res_name,
  255.                           res_class, callback,
  256.                           client_data );
  257.     DBUG_RETURN( result );
  258. }
  259.  
  260.