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