imThaiIm.c revision 1ab64890
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(im) 65 Xim im; 66{ 67 char *language; 68 69 _XGetLCValues(im->core.lcd, XlcNLanguage, &language, NULL); 70 if(strcmp(language, THAI_LANGUAGE_NAME) == 0) { 71 return(True); 72 } 73 return(False); 74} 75 76Public Bool 77_XimThaiOpenIM(im) 78 Xim im; 79{ 80 XLCd lcd = im->core.lcd; 81 XlcConv conv; 82 XimDefIMValues im_values; 83 XimLocalPrivateRec* private = &im->private.local; 84 85 _XimInitialResourceInfo(); 86 if(_XimSetIMResourceList(&im->core.im_resources, 87 &im->core.im_num_resources) == False) { 88 goto Open_Error; 89 } 90 if(_XimSetICResourceList(&im->core.ic_resources, 91 &im->core.ic_num_resources) == False) { 92 goto Open_Error; 93 } 94 95 _XimSetIMMode(im->core.im_resources, im->core.im_num_resources); 96 97 _XimGetCurrentIMValues(im, &im_values); 98 if(_XimSetLocalIMDefaults(im, (XPointer)&im_values, 99 im->core.im_resources, im->core.im_num_resources) == False) { 100 goto Open_Error; 101 } 102 _XimSetCurrentIMValues(im, &im_values); 103 104 if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNMultiByte))) 105 goto Open_Error; 106 private->ctom_conv = conv; 107 108 if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNWideChar))) 109 goto Open_Error; 110 private->ctow_conv = conv; 111 112 if (!(conv = _XlcOpenConverter(lcd, XlcNCompoundText, lcd, XlcNUtf8String))) 113 goto Open_Error; 114 private->ctoutf8_conv = conv; 115 116 if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte))) 117 goto Open_Error; 118 private->cstomb_conv = conv; 119 120 if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNWideChar))) 121 goto Open_Error; 122 private->cstowc_conv = conv; 123 124 if (!(conv = _XlcOpenConverter(lcd, XlcNCharSet, lcd, XlcNUtf8String))) 125 goto Open_Error; 126 private->cstoutf8_conv = conv; 127 128 if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNChar))) 129 goto Open_Error; 130 private->ucstoc_conv = conv; 131 132 if (!(conv = _XlcOpenConverter(lcd, XlcNUcsChar, lcd, XlcNUtf8String))) 133 goto Open_Error; 134 private->ucstoutf8_conv = conv; 135 136 im->methods = &Xim_im_thai_methods; 137 private->current_ic = (XIC)NULL; 138 139 return(True); 140 141Open_Error : 142 _XimThaiIMFree(im); 143 return(False); 144} 145 146Public void 147_XimThaiIMFree(im) 148 Xim im; 149{ 150 if(im->core.im_resources) { 151 Xfree(im->core.im_resources); 152 im->core.im_resources = NULL; 153 } 154 if(im->core.ic_resources) { 155 Xfree(im->core.ic_resources); 156 im->core.ic_resources = NULL; 157 } 158 if(im->core.im_values_list) { 159 Xfree(im->core.im_values_list); 160 im->core.im_values_list = NULL; 161 } 162 if(im->core.ic_values_list) { 163 Xfree(im->core.ic_values_list); 164 im->core.ic_values_list = NULL; 165 } 166 if(im->core.styles) { 167 Xfree(im->core.styles); 168 im->core.styles = NULL; 169 } 170 if(im->core.res_name) { 171 Xfree(im->core.res_name); 172 im->core.res_name = NULL; 173 } 174 if(im->core.res_class) { 175 Xfree(im->core.res_class); 176 im->core.res_class = NULL; 177 } 178 if(im->core.im_name) { 179 Xfree(im->core.im_name); 180 im->core.im_name = NULL; 181 } 182 if (im->private.local.ctom_conv) { 183 _XlcCloseConverter(im->private.local.ctom_conv); 184 im->private.local.ctom_conv = NULL; 185 } 186 if (im->private.local.ctow_conv) { 187 _XlcCloseConverter(im->private.local.ctow_conv); 188 im->private.local.ctow_conv = NULL; 189 } 190 if (im->private.local.ctoutf8_conv) { 191 _XlcCloseConverter(im->private.local.ctoutf8_conv); 192 im->private.local.ctoutf8_conv = NULL; 193 } 194 if (im->private.local.cstomb_conv) { 195 _XlcCloseConverter(im->private.local.cstomb_conv); 196 im->private.local.cstomb_conv = NULL; 197 } 198 if (im->private.local.cstowc_conv) { 199 _XlcCloseConverter(im->private.local.cstowc_conv); 200 im->private.local.cstowc_conv = NULL; 201 } 202 if (im->private.local.cstoutf8_conv) { 203 _XlcCloseConverter(im->private.local.cstoutf8_conv); 204 im->private.local.cstoutf8_conv = NULL; 205 } 206 if (im->private.local.ucstoc_conv) { 207 _XlcCloseConverter(im->private.local.ucstoc_conv); 208 im->private.local.ucstoc_conv = NULL; 209 } 210 if (im->private.local.ucstoutf8_conv) { 211 _XlcCloseConverter(im->private.local.ucstoutf8_conv); 212 im->private.local.ucstoutf8_conv = NULL; 213 } 214 return; 215} 216 217Public Status 218_XimThaiCloseIM(xim) 219 XIM xim; 220{ 221 Xim im = (Xim)xim; 222 XIC ic; 223 XIC next; 224 225 ic = im->core.ic_chain; 226 im->core.ic_chain = NULL; 227 while (ic) { 228 (*ic->methods->destroy) (ic); 229 next = ic->core.next; 230 Xfree ((char *) ic); 231 ic = next; 232 } 233 _XimThaiIMFree(im); 234 return(True); 235} 236