imThaiIm.c revision 61b2299d
1/* $Xorg: imThaiIm.c,v 1.3 2000/08/17 19:45:15 cpqbld Exp $ */ 2/****************************************************************** 3 4 Copyright 1992, 1993, 1994 by FUJITSU LIMITED 5 Copyright 1993 by Digital Equipment Corporation 6 7Permission to use, copy, modify, distribute, and sell this software 8and its documentation for any purpose is hereby granted without fee, 9provided that the above copyright notice appear in all copies and that 10both that copyright notice and this permission notice appear in 11supporting documentation, and that the name of FUJITSU LIMITED and 12Digital Equipment Corporation not be used in advertising or publicity 13pertaining to distribution of the software without specific, written 14prior permission. FUJITSU LIMITED and Digital Equipment Corporation 15makes no representations about the suitability of this software for 16any purpose. It is provided "as is" without express or implied 17warranty. 18 19FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION DISCLAIM ALL 20WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED 21WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 22FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR 23ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 24WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 25IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 26ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 27THIS SOFTWARE. 28 29 Author: Takashi Fujiwara FUJITSU LIMITED 30 fujiwara@a80.tech.yk.fujitsu.co.jp 31 Modifier: Franky Ling Digital Equipment Corporation 32 frankyling@hgrd01.enet.dec.com 33 34******************************************************************/ 35/* $XFree86: xc/lib/X11/imThaiIm.c,v 1.7 2001/01/17 19:41:52 dawes Exp $ */ 36 37#ifdef HAVE_CONFIG_H 38#include <config.h> 39#endif 40#include <stdio.h> 41#include <X11/Xlib.h> 42#include <X11/Xmd.h> 43#include <X11/Xatom.h> 44#include <X11/Xos.h> 45#include "Xlibint.h" 46#include "Xlcint.h" 47#include "XlcPublic.h" 48#include "XlcPubI.h" 49#include "Ximint.h" 50 51Private XIMMethodsRec Xim_im_thai_methods = { 52 _XimThaiCloseIM, /* close */ 53 _XimLocalSetIMValues, /* set_values */ 54 _XimLocalGetIMValues, /* get_values */ 55 _XimThaiCreateIC, /* create_ic */ 56 _XimLcctstombs, /* ctstombs */ 57 _XimLcctstowcs, /* ctstowcs */ 58 _XimLcctstoutf8 /* ctstoutf8 */ 59}; 60 61#define THAI_LANGUAGE_NAME "th" 62 63Bool 64_XimCheckIfThaiProcessing(Xim im) 65{ 66 char *language; 67 68 _XGetLCValues(im->core.lcd, XlcNLanguage, &language, NULL); 69 if(strcmp(language, THAI_LANGUAGE_NAME) == 0 && 70 (strcmp(im->core.im_name, "") == 0 || 71 strcmp(im->core.im_name, "BasicCheck") == 0 || 72 strcmp(im->core.im_name, "Strict") == 0 || 73 strcmp(im->core.im_name, "Thaicat") == 0 || 74 strcmp(im->core.im_name, "Passthrough") == 0)) 75 { 76 return(True); 77 } 78 return(False); 79} 80 81Public Bool 82_XimThaiOpenIM(Xim im) 83{ 84 XLCd lcd = im->core.lcd; 85 XlcConv conv; 86 XimDefIMValues im_values; 87 XimLocalPrivateRec* private = &im->private.local; 88 89 _XimInitialResourceInfo(); 90 if(_XimSetIMResourceList(&im->core.im_resources, 91 &im->core.im_num_resources) == False) { 92 goto Open_Error; 93 } 94 if(_XimSetICResourceList(&im->core.ic_resources, 95 &im->core.ic_num_resources) == False) { 96 goto Open_Error; 97 } 98 99 _XimSetIMMode(im->core.im_resources, im->core.im_num_resources); 100 101 _XimGetCurrentIMValues(im, &im_values); 102 if(_XimSetLocalIMDefaults(im, (XPointer)&im_values, 103 im->core.im_resources, im->core.im_num_resources) == False) { 104 goto Open_Error; 105 } 106 _XimSetCurrentIMValues(im, &im_values); 107 108 if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte))) 109 goto Open_Error; 110 private->ctom_conv = conv; 111 112 if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar))) 113 goto Open_Error; 114 private->ctow_conv = conv; 115 116 if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNUtf8String))) 117 goto Open_Error; 118 private->ctoutf8_conv = conv; 119 120 if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte))) 121 goto Open_Error; 122 private->cstomb_conv = conv; 123 124 if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNWideChar))) 125 goto Open_Error; 126 private->cstowc_conv = conv; 127 128 if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNUtf8String))) 129 goto Open_Error; 130 private->cstoutf8_conv = conv; 131 132 if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNChar))) 133 goto Open_Error; 134 private->ucstoc_conv = conv; 135 136 if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNUtf8String))) 137 goto Open_Error; 138 private->ucstoutf8_conv = conv; 139 140 im->methods = &Xim_im_thai_methods; 141 private->current_ic = (XIC)NULL; 142 143 return(True); 144 145Open_Error : 146 _XimThaiIMFree(im); 147 return(False); 148} 149 150Public void 151_XimThaiIMFree(Xim im) 152{ 153 if(im->core.im_resources) { 154 Xfree(im->core.im_resources); 155 im->core.im_resources = NULL; 156 } 157 if(im->core.ic_resources) { 158 Xfree(im->core.ic_resources); 159 im->core.ic_resources = NULL; 160 } 161 if(im->core.im_values_list) { 162 Xfree(im->core.im_values_list); 163 im->core.im_values_list = NULL; 164 } 165 if(im->core.ic_values_list) { 166 Xfree(im->core.ic_values_list); 167 im->core.ic_values_list = NULL; 168 } 169 if(im->core.styles) { 170 Xfree(im->core.styles); 171 im->core.styles = NULL; 172 } 173 if(im->core.res_name) { 174 Xfree(im->core.res_name); 175 im->core.res_name = NULL; 176 } 177 if(im->core.res_class) { 178 Xfree(im->core.res_class); 179 im->core.res_class = NULL; 180 } 181 if(im->core.im_name) { 182 Xfree(im->core.im_name); 183 im->core.im_name = NULL; 184 } 185 if (im->private.local.ctom_conv) { 186 _XlcCloseConverter(im->private.local.ctom_conv); 187 im->private.local.ctom_conv = NULL; 188 } 189 if (im->private.local.ctow_conv) { 190 _XlcCloseConverter(im->private.local.ctow_conv); 191 im->private.local.ctow_conv = NULL; 192 } 193 if (im->private.local.ctoutf8_conv) { 194 _XlcCloseConverter(im->private.local.ctoutf8_conv); 195 im->private.local.ctoutf8_conv = NULL; 196 } 197 if (im->private.local.cstomb_conv) { 198 _XlcCloseConverter(im->private.local.cstomb_conv); 199 im->private.local.cstomb_conv = NULL; 200 } 201 if (im->private.local.cstowc_conv) { 202 _XlcCloseConverter(im->private.local.cstowc_conv); 203 im->private.local.cstowc_conv = NULL; 204 } 205 if (im->private.local.cstoutf8_conv) { 206 _XlcCloseConverter(im->private.local.cstoutf8_conv); 207 im->private.local.cstoutf8_conv = NULL; 208 } 209 if (im->private.local.ucstoc_conv) { 210 _XlcCloseConverter(im->private.local.ucstoc_conv); 211 im->private.local.ucstoc_conv = NULL; 212 } 213 if (im->private.local.ucstoutf8_conv) { 214 _XlcCloseConverter(im->private.local.ucstoutf8_conv); 215 im->private.local.ucstoutf8_conv = NULL; 216 } 217 return; 218} 219 220Public Status 221_XimThaiCloseIM(XIM xim) 222{ 223 Xim im = (Xim)xim; 224 XIC ic; 225 XIC next; 226 227 ic = im->core.ic_chain; 228 im->core.ic_chain = NULL; 229 while (ic) { 230 (*ic->methods->destroy) (ic); 231 next = ic->core.next; 232 Xfree ((char *) ic); 233 ic = next; 234 } 235 _XimThaiIMFree(im); 236 return(True); 237} 238