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