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

  1. /* $XConsortium: imLcIc.c /main/6 1996/10/22 14:24:42 kaleb $ */
  2. /******************************************************************
  3.  
  4.                 Copyright 1992,1993, 1994 by FUJITSU LIMITED
  5.  
  6. Permission to use, copy, modify, distribute, and sell this software
  7. and its documentation for any purpose is hereby granted without fee,
  8. provided that the above copyright notice appear in all copies and
  9. that both that copyright notice and this permission notice appear
  10. in supporting documentation, and that the name of FUJITSU LIMITED
  11. not be used in advertising or publicity pertaining to distribution
  12. of the software without specific, written prior permission.
  13. FUJITSU LIMITED makes no representations about the suitability of
  14. this software for any purpose. 
  15. It is provided "as is" without express or implied warranty.
  16.  
  17. FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  18. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  19. EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20. CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  21. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  22. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  23. PERFORMANCE OF THIS SOFTWARE.
  24.  
  25.   Author: Takashi Fujiwara     FUJITSU LIMITED 
  26.                                fujiwara@a80.tech.yk.fujitsu.co.jp
  27.  
  28. ******************************************************************/
  29.  
  30. #include <stdio.h>
  31. #include "Xlib_private.h"
  32. #include <X11/Xlib.h>
  33. #include <X11/Xmd.h>
  34. #include "Xlcint.h"
  35. #include "Ximint.h"
  36.  
  37. Private void
  38. _XimLocalUnSetFocus(xic)
  39.     XIC     xic;
  40. {
  41.     Xic  ic = (Xic)xic;
  42.     ((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
  43.  
  44.     if (ic->core.focus_window)
  45.     _XUnregisterFilter(ic->core.im->core.display,
  46.             ic->core.focus_window, _XimLocalFilter, (XPointer)ic);
  47.     return;
  48. }
  49.  
  50. Private void
  51. _XimLocalDestroyIC(xic)
  52.     XIC     xic;
  53. {
  54.     Xic     ic = (Xic)xic;
  55.     if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) {
  56.     _XimLocalUnSetFocus(xic);
  57.     }
  58.     if(ic->private.local.ic_resources) {
  59.     Xfree(ic->private.local.ic_resources);
  60.     ic->private.local.ic_resources = NULL;
  61.     }
  62.     return;
  63. }
  64.  
  65. Private void
  66. _XimLocalSetFocus(xic)
  67.     XIC     xic;
  68. {
  69.     Xic     ic = (Xic)xic;
  70.     XIC     current_ic = ((Xim)ic->core.im)->private.local.current_ic;
  71.  
  72.     if (current_ic == (XIC)ic)
  73.     return;
  74.  
  75.     if (current_ic != (XIC)NULL) {
  76.     _XimLocalUnSetFocus(current_ic);
  77.     }
  78.     ((Xim)ic->core.im)->private.local.current_ic = (XIC)ic;
  79.  
  80.     if (ic->core.focus_window)
  81.     _XRegisterFilterByType(ic->core.im->core.display,
  82.             ic->core.focus_window, KeyPress, KeyPress,
  83.             _XimLocalFilter, (XPointer)ic);
  84.     return;
  85. }
  86.  
  87. Private char *
  88. _XimLocalMbReset(xic)
  89.     XIC     xic;
  90. {
  91.     Xic     ic = (Xic)xic;
  92.     ic->private.local.composed = (DefTree *)NULL;
  93.     ic->private.local.context  = ((Xim)ic->core.im)->private.local.top;
  94.     return((char *)NULL);
  95. }
  96.  
  97. Private wchar_t *
  98. _XimLocalWcReset(xic)
  99.     XIC     xic;
  100. {
  101.     Xic     ic = (Xic)xic;
  102.     ic->private.local.composed = (DefTree *)NULL;
  103.     ic->private.local.context  = ((Xim)ic->core.im)->private.local.top;
  104.     return((wchar_t *)NULL);
  105. }
  106.  
  107. Private XICMethodsRec Local_ic_methods = {
  108.     _XimLocalDestroyIC,     /* destroy */
  109.     _XimLocalSetFocus,      /* set_focus */
  110.     _XimLocalUnSetFocus,    /* unset_focus */
  111.     _XimLocalSetICValues,    /* set_values */
  112.     _XimLocalGetICValues,    /* get_values */
  113.     _XimLocalMbReset,        /* mb_reset */
  114.     _XimLocalWcReset,        /* wc_reset */
  115.     _XimLocalMbLookupString,    /* mb_lookup_string */
  116.     _XimLocalWcLookupString,    /* wc_lookup_string */
  117. };
  118.  
  119. Public XIC
  120. _XimLocalCreateIC(im, values)
  121.     XIM             im;
  122.     XIMArg        *values;
  123. {
  124.     Xic             ic;
  125.     XimDefICValues     ic_values;
  126.     XIMResourceList     res;
  127.     unsigned int     num;
  128.     int             len;
  129.  
  130.     if((ic = (Xic)Xmalloc(sizeof(XicRec))) == (Xic)NULL) {
  131.     return ((XIC)NULL);
  132.     }
  133.     bzero((char *)ic, sizeof(XicRec));
  134.  
  135.     ic->methods = &Local_ic_methods;
  136.     ic->core.im = im;
  137.     ic->private.local.context   = ((Xim)im)->private.local.top;
  138.     ic->private.local.composed  = (DefTree *)NULL;
  139.  
  140.     num = im->core.ic_num_resources;
  141.     len = sizeof(XIMResource) * num;
  142.     if((res = (XIMResourceList)Xmalloc(len)) == (XIMResourceList)NULL) {
  143.     goto Set_Error;
  144.     }
  145.     (void)memcpy((char *)res, (char *)im->core.ic_resources, len);
  146.     ic->private.local.ic_resources     = res;
  147.     ic->private.local.ic_num_resources = num;
  148.  
  149.     bzero((char *)&ic_values, sizeof(XimDefICValues));
  150.     if(_XimCheckLocalInputStyle(ic, (XPointer)&ic_values, values,
  151.                  im->core.styles, res, num) == False) {
  152.     goto Set_Error;
  153.     }
  154.  
  155.     _XimSetICMode(res, num, ic_values.input_style);
  156.  
  157.     if(_XimSetICValueData(ic, (XPointer)&ic_values,
  158.             ic->private.local.ic_resources,
  159.             ic->private.local.ic_num_resources,
  160.             values, XIM_CREATEIC, True)) {
  161.     goto Set_Error;
  162.     }
  163.     ic_values.filter_events = KeyPressMask;
  164.     _XimSetCurrentICValues(ic, &ic_values);
  165.     if(_XimSetICDefaults(ic, (XPointer)&ic_values,
  166.                 XIM_SETICDEFAULTS, res, num) == False) {
  167.     goto Set_Error;
  168.     }
  169.     _XimSetCurrentICValues(ic, &ic_values);
  170.  
  171.     return((XIC)ic);
  172.  
  173. Set_Error :
  174.     if (ic->private.local.ic_resources) {
  175.     Xfree(ic->private.local.ic_resources);
  176.     ic->private.local.ic_resources = NULL;
  177.     }
  178.     Xfree(ic);
  179.     return((XIC)NULL);
  180. }
  181.