ICWrap.c revision 0f8248bf
11ab64890Smrg/* 21ab64890Smrg * Copyright 1990, 1991 by OMRON Corporation, NTT Software Corporation, 31ab64890Smrg * and Nippon Telegraph and Telephone Corporation 41ab64890Smrg * Copyright 1991 by the Open Software Foundation 51ab64890Smrg * Copyright 1993 by the FUJITSU LIMITED 61ab64890Smrg * 71ab64890Smrg * Permission to use, copy, modify, distribute, and sell this software and its 81ab64890Smrg * documentation for any purpose is hereby granted without fee, provided that 91ab64890Smrg * the above copyright notice appear in all copies and that both that 101ab64890Smrg * copyright notice and this permission notice appear in supporting 111ab64890Smrg * documentation, and that the names of OMRON, NTT Software, NTT, and 1261b2299dSmrg * Open Software Foundation not be used in advertising or publicity 1361b2299dSmrg * pertaining to distribution of the software without specific, 141ab64890Smrg * written prior permission. OMRON, NTT Software, NTT, and Open Software 151ab64890Smrg * Foundation make no representations about the suitability of this 161ab64890Smrg * software for any purpose. It is provided "as is" without express or 171ab64890Smrg * implied warranty. 181ab64890Smrg * 1961b2299dSmrg * OMRON, NTT SOFTWARE, NTT, AND OPEN SOFTWARE FOUNDATION 2061b2299dSmrg * DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 2161b2299dSmrg * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 221ab64890Smrg * SHALL OMRON, NTT SOFTWARE, NTT, OR OPEN SOFTWARE FOUNDATION BE 2361b2299dSmrg * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 241ab64890Smrg * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 251ab64890Smrg * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 261ab64890Smrg * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 2761b2299dSmrg * 281ab64890Smrg * Authors: Li Yuhong OMRON Corporation 291ab64890Smrg * Tatsuya Kato NTT Software Corporation 301ab64890Smrg * Hiroshi Kuribayashi OMRON Coproration 311ab64890Smrg * Muneiyoshi Suzuki Nippon Telegraph and Telephone Co. 3261b2299dSmrg * 3361b2299dSmrg * M. Collins OSF 341ab64890Smrg * Takashi Fujiwara FUJITSU LIMITED 3561b2299dSmrg */ 361ab64890Smrg/* 371ab64890Smrg 381ab64890SmrgCopyright 1991, 1998 The Open Group 391ab64890Smrg 401ab64890SmrgPermission to use, copy, modify, distribute, and sell this software and its 411ab64890Smrgdocumentation for any purpose is hereby granted without fee, provided that 421ab64890Smrgthe above copyright notice appear in all copies and that both that 431ab64890Smrgcopyright notice and this permission notice appear in supporting 441ab64890Smrgdocumentation. 451ab64890Smrg 461ab64890SmrgThe above copyright notice and this permission notice shall be included 471ab64890Smrgin all copies or substantial portions of the Software. 481ab64890Smrg 491ab64890SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 501ab64890SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 511ab64890SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 521ab64890SmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 531ab64890SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 541ab64890SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 551ab64890SmrgOTHER DEALINGS IN THE SOFTWARE. 561ab64890Smrg 571ab64890SmrgExcept as contained in this notice, the name of The Open Group shall 581ab64890Smrgnot be used in advertising or otherwise to promote the sale, use or 591ab64890Smrgother dealings in this Software without prior written authorization 601ab64890Smrgfrom The Open Group. 611ab64890Smrg 621ab64890Smrg*/ 631ab64890Smrg 641ab64890Smrg#ifdef HAVE_CONFIG_H 651ab64890Smrg#include <config.h> 661ab64890Smrg#endif 671ab64890Smrg#include "Xlibint.h" 681ab64890Smrg#include "Xlcint.h" 691ab64890Smrg 701ab64890Smrgstatic int 711ab64890Smrg_XIMNestedListToNestedList( 721ab64890Smrg XIMArg *nlist, /* This is the new list */ 731ab64890Smrg XIMArg *list) /* The original list */ 741ab64890Smrg{ 751ab64890Smrg register XIMArg *ptr = list; 761ab64890Smrg 771ab64890Smrg while (ptr->name) { 781ab64890Smrg if (!strcmp(ptr->name, XNVaNestedList)) { 791ab64890Smrg nlist += _XIMNestedListToNestedList(nlist, (XIMArg *)ptr->value); 801ab64890Smrg } else { 811ab64890Smrg nlist->name = ptr->name; 821ab64890Smrg nlist->value = ptr->value; 831ab64890Smrg ptr++; 841ab64890Smrg nlist++; 851ab64890Smrg } 861ab64890Smrg } 871ab64890Smrg return ptr - list; 881ab64890Smrg} 891ab64890Smrg 901ab64890Smrgstatic void 911ab64890Smrg_XIMCountNestedList( 921ab64890Smrg XIMArg *args, 931ab64890Smrg int *total_count) 941ab64890Smrg{ 951ab64890Smrg for (; args->name; args++) { 961ab64890Smrg if (!strcmp(args->name, XNVaNestedList)) 971ab64890Smrg _XIMCountNestedList((XIMArg *)args->value, total_count); 981ab64890Smrg else 991ab64890Smrg ++(*total_count); 1001ab64890Smrg } 1011ab64890Smrg} 1021ab64890Smrg 1031ab64890Smrgstatic void 1041ab64890Smrg_XIMCountVaList(va_list var, int *total_count) 1051ab64890Smrg{ 1061ab64890Smrg char *attr; 1071ab64890Smrg 1081ab64890Smrg *total_count = 0; 1091ab64890Smrg 1101ab64890Smrg for (attr = va_arg(var, char*); attr; attr = va_arg(var, char*)) { 1111ab64890Smrg if (!strcmp(attr, XNVaNestedList)) { 1121ab64890Smrg _XIMCountNestedList(va_arg(var, XIMArg*), total_count); 1131ab64890Smrg } else { 1141ab64890Smrg (void)va_arg(var, XIMArg*); 1151ab64890Smrg ++(*total_count); 1161ab64890Smrg } 1171ab64890Smrg } 1181ab64890Smrg} 1191ab64890Smrg 1201ab64890Smrgstatic void 1211ab64890Smrg_XIMVaToNestedList(va_list var, int max_count, XIMArg **args_return) 1221ab64890Smrg{ 1231ab64890Smrg XIMArg *args; 1241ab64890Smrg char *attr; 1251ab64890Smrg 1261ab64890Smrg if (max_count <= 0) { 1271ab64890Smrg *args_return = (XIMArg *)NULL; 1281ab64890Smrg return; 1291ab64890Smrg } 1301ab64890Smrg 131818534a1Smrg args = Xmalloc(((unsigned)max_count + 1) * sizeof(XIMArg)); 1321ab64890Smrg *args_return = args; 1331ab64890Smrg if (!args) return; 1341ab64890Smrg 1351ab64890Smrg for (attr = va_arg(var, char*); attr; attr = va_arg(var, char*)) { 1361ab64890Smrg if (!strcmp(attr, XNVaNestedList)) { 1371ab64890Smrg args += _XIMNestedListToNestedList(args, va_arg(var, XIMArg*)); 1381ab64890Smrg } else { 1391ab64890Smrg args->name = attr; 1401ab64890Smrg args->value = va_arg(var, XPointer); 1411ab64890Smrg args++; 1421ab64890Smrg } 1431ab64890Smrg } 1441ab64890Smrg args->name = (char*)NULL; 1451ab64890Smrg} 1461ab64890Smrg 1471ab64890Smrg/*ARGSUSED*/ 1481ab64890SmrgXVaNestedList 1491ab64890SmrgXVaCreateNestedList(int dummy, ...) 1501ab64890Smrg{ 1511ab64890Smrg va_list var; 1521ab64890Smrg XIMArg *args = NULL; 1531ab64890Smrg int total_count; 1541ab64890Smrg 1551ab64890Smrg va_start(var, dummy); 1561ab64890Smrg _XIMCountVaList(var, &total_count); 1571ab64890Smrg va_end(var); 1581ab64890Smrg 1591ab64890Smrg va_start(var, dummy); 1601ab64890Smrg _XIMVaToNestedList(var, total_count, &args); 1611ab64890Smrg va_end(var); 1621ab64890Smrg 1631ab64890Smrg return (XVaNestedList)args; 1641ab64890Smrg} 1651ab64890Smrg 1661ab64890Smrgchar * 1671ab64890SmrgXSetIMValues(XIM im, ...) 1681ab64890Smrg{ 1691ab64890Smrg va_list var; 1701ab64890Smrg int total_count; 1711ab64890Smrg XIMArg *args; 1721ab64890Smrg char *ret; 1731ab64890Smrg 1741ab64890Smrg /* 1751ab64890Smrg * so count the stuff dangling here 1761ab64890Smrg */ 1771ab64890Smrg va_start(var, im); 1781ab64890Smrg _XIMCountVaList(var, &total_count); 1791ab64890Smrg va_end(var); 1801ab64890Smrg 1811ab64890Smrg /* 1821ab64890Smrg * now package it up so we can send it along 1831ab64890Smrg */ 1841ab64890Smrg va_start(var, im); 1851ab64890Smrg _XIMVaToNestedList(var, total_count, &args); 1861ab64890Smrg va_end(var); 1871ab64890Smrg 1881ab64890Smrg ret = (*im->methods->set_values) (im, args); 1890f8248bfSmrg Xfree(args); 1901ab64890Smrg return ret; 1911ab64890Smrg} 1921ab64890Smrg 1931ab64890Smrgchar * 1941ab64890SmrgXGetIMValues(XIM im, ...) 1951ab64890Smrg{ 1961ab64890Smrg va_list var; 1971ab64890Smrg int total_count; 1981ab64890Smrg XIMArg *args; 1991ab64890Smrg char *ret; 2001ab64890Smrg 2011ab64890Smrg /* 2021ab64890Smrg * so count the stuff dangling here 2031ab64890Smrg */ 2041ab64890Smrg va_start(var, im); 2051ab64890Smrg _XIMCountVaList(var, &total_count); 2061ab64890Smrg va_end(var); 2071ab64890Smrg 2081ab64890Smrg /* 2091ab64890Smrg * now package it up so we can send it along 2101ab64890Smrg */ 2111ab64890Smrg va_start(var, im); 2121ab64890Smrg _XIMVaToNestedList(var, total_count, &args); 2131ab64890Smrg va_end(var); 2141ab64890Smrg 2151ab64890Smrg ret = (*im->methods->get_values) (im, args); 2160f8248bfSmrg Xfree(args); 2171ab64890Smrg return ret; 2181ab64890Smrg} 2191ab64890Smrg 2201ab64890Smrg/* 22161b2299dSmrg * Create an input context within the input method, 2221ab64890Smrg * and return a pointer to the input context. 2231ab64890Smrg */ 2241ab64890Smrg 2251ab64890SmrgXIC 2261ab64890SmrgXCreateIC(XIM im, ...) 2271ab64890Smrg{ 2281ab64890Smrg va_list var; 2291ab64890Smrg int total_count; 2301ab64890Smrg XIMArg *args; 2311ab64890Smrg XIC ic; 23261b2299dSmrg 2331ab64890Smrg /* 2341ab64890Smrg * so count the stuff dangling here 2351ab64890Smrg */ 2361ab64890Smrg va_start(var, im); 2371ab64890Smrg _XIMCountVaList(var, &total_count); 2381ab64890Smrg va_end(var); 2391ab64890Smrg 2401ab64890Smrg /* 2411ab64890Smrg * now package it up so we can send it along 2421ab64890Smrg */ 2431ab64890Smrg va_start(var, im); 2441ab64890Smrg _XIMVaToNestedList(var, total_count, &args); 2451ab64890Smrg va_end(var); 2461ab64890Smrg 2471ab64890Smrg ic = (XIC) (*im->methods->create_ic) (im, args); 2480f8248bfSmrg Xfree(args); 2491ab64890Smrg if (ic) { 2501ab64890Smrg ic->core.next = im->core.ic_chain; 2511ab64890Smrg im->core.ic_chain = ic; 2521ab64890Smrg } 2531ab64890Smrg return ic; 2541ab64890Smrg} 2551ab64890Smrg 2561ab64890Smrg/* 2571ab64890Smrg * Free the input context. 2581ab64890Smrg */ 2591ab64890Smrgvoid 26061b2299dSmrgXDestroyIC(XIC ic) 2611ab64890Smrg{ 2621ab64890Smrg XIM im = ic->core.im; 2631ab64890Smrg XIC *prev; 2641ab64890Smrg 2651ab64890Smrg (*ic->methods->destroy) (ic); 2661ab64890Smrg if (im) { 2671ab64890Smrg for (prev = &im->core.ic_chain; *prev; prev = &(*prev)->core.next) { 2681ab64890Smrg if (*prev == ic) { 2691ab64890Smrg *prev = ic->core.next; 2701ab64890Smrg break; 2711ab64890Smrg } 2721ab64890Smrg } 2731ab64890Smrg } 274818534a1Smrg Xfree (ic); 2751ab64890Smrg} 2761ab64890Smrg 2771ab64890Smrgchar * 2781ab64890SmrgXGetICValues(XIC ic, ...) 27961b2299dSmrg{ 2801ab64890Smrg va_list var; 2811ab64890Smrg int total_count; 2821ab64890Smrg XIMArg *args; 2831ab64890Smrg char *ret; 2841ab64890Smrg 2851ab64890Smrg if (!ic->core.im) 2861ab64890Smrg return (char *) NULL; 2871ab64890Smrg 2881ab64890Smrg /* 2891ab64890Smrg * so count the stuff dangling here 2901ab64890Smrg */ 2911ab64890Smrg va_start(var, ic); 2921ab64890Smrg _XIMCountVaList(var, &total_count); 2931ab64890Smrg va_end(var); 2941ab64890Smrg 2951ab64890Smrg /* 2961ab64890Smrg * now package it up so we can send it along 2971ab64890Smrg */ 2981ab64890Smrg va_start(var, ic); 2991ab64890Smrg _XIMVaToNestedList(var, total_count, &args); 3001ab64890Smrg va_end(var); 3011ab64890Smrg 3021ab64890Smrg ret = (*ic->methods->get_values) (ic, args); 3030f8248bfSmrg Xfree(args); 3041ab64890Smrg return ret; 3051ab64890Smrg} 3061ab64890Smrg 3071ab64890Smrgchar * 3081ab64890SmrgXSetICValues(XIC ic, ...) 3091ab64890Smrg{ 3101ab64890Smrg va_list var; 3111ab64890Smrg int total_count; 3121ab64890Smrg XIMArg *args; 3131ab64890Smrg char *ret; 3141ab64890Smrg 3151ab64890Smrg if (!ic->core.im) 3161ab64890Smrg return (char *) NULL; 3171ab64890Smrg 3181ab64890Smrg /* 3191ab64890Smrg * so count the stuff dangling here 3201ab64890Smrg */ 3211ab64890Smrg va_start(var, ic); 3221ab64890Smrg _XIMCountVaList(var, &total_count); 3231ab64890Smrg va_end(var); 3241ab64890Smrg 3251ab64890Smrg /* 3261ab64890Smrg * now package it up so we can send it along 3271ab64890Smrg */ 3281ab64890Smrg va_start(var, ic); 3291ab64890Smrg _XIMVaToNestedList(var, total_count, &args); 3301ab64890Smrg va_end(var); 3311ab64890Smrg 3321ab64890Smrg ret = (*ic->methods->set_values) (ic, args); 3330f8248bfSmrg Xfree(args); 3341ab64890Smrg return ret; 3351ab64890Smrg} 3361ab64890Smrg 3371ab64890Smrg/* 3381ab64890Smrg * Require the input manager to focus the focus window attached to the ic 3391ab64890Smrg * argument. 3401ab64890Smrg */ 3411ab64890Smrgvoid 34261b2299dSmrgXSetICFocus(XIC ic) 3431ab64890Smrg{ 3441ab64890Smrg if (ic && ic->core.im) 3451ab64890Smrg (*ic->methods->set_focus) (ic); 3461ab64890Smrg} 3471ab64890Smrg 3481ab64890Smrg/* 3491ab64890Smrg * Require the input manager to unfocus the focus window attached to the ic 3501ab64890Smrg * argument. 3511ab64890Smrg */ 3521ab64890Smrgvoid 35361b2299dSmrgXUnsetICFocus(XIC ic) 3541ab64890Smrg{ 3551ab64890Smrg if (ic->core.im) 3561ab64890Smrg (*ic->methods->unset_focus) (ic); 3571ab64890Smrg} 3581ab64890Smrg 3591ab64890Smrg/* 3601ab64890Smrg * Return the XIM associated with the input context. 3611ab64890Smrg */ 3621ab64890SmrgXIM 36361b2299dSmrgXIMOfIC(XIC ic) 3641ab64890Smrg{ 3651ab64890Smrg return ic->core.im; 3661ab64890Smrg} 3671ab64890Smrg 3681ab64890Smrgchar * 36961b2299dSmrgXmbResetIC(XIC ic) 3701ab64890Smrg{ 3711ab64890Smrg if (ic->core.im) 3721ab64890Smrg return (*ic->methods->mb_reset)(ic); 3731ab64890Smrg return (char *)NULL; 3741ab64890Smrg} 3751ab64890Smrg 3761ab64890Smrgwchar_t * 37761b2299dSmrgXwcResetIC(XIC ic) 3781ab64890Smrg{ 3791ab64890Smrg if (ic->core.im) 3801ab64890Smrg return (*ic->methods->wc_reset)(ic); 3811ab64890Smrg return (wchar_t *)NULL; 3821ab64890Smrg} 3831ab64890Smrg 3841ab64890Smrgchar * 38561b2299dSmrgXutf8ResetIC(XIC ic) 3861ab64890Smrg{ 3871ab64890Smrg if (ic->core.im) { 3881ab64890Smrg if (ic->methods->utf8_reset) 3891ab64890Smrg return (*ic->methods->utf8_reset)(ic); 3901ab64890Smrg else if (ic->methods->mb_reset) 3911ab64890Smrg return (*ic->methods->mb_reset)(ic); 3921ab64890Smrg } 3931ab64890Smrg return (char *)NULL; 3941ab64890Smrg} 3951ab64890Smrg 3961ab64890Smrgint 39761b2299dSmrgXmbLookupString(XIC ic, XKeyEvent *ev, char *buffer, int nbytes, 39861b2299dSmrg KeySym *keysym, Status *status) 3991ab64890Smrg{ 4001ab64890Smrg if (ic->core.im) 4011ab64890Smrg return (*ic->methods->mb_lookup_string) (ic, ev, buffer, nbytes, 4021ab64890Smrg keysym, status); 4031ab64890Smrg return XLookupNone; 4041ab64890Smrg} 4051ab64890Smrg 4061ab64890Smrgint 40761b2299dSmrgXwcLookupString(XIC ic, XKeyEvent *ev, wchar_t *buffer, int nchars, 40861b2299dSmrg KeySym *keysym, Status *status) 4091ab64890Smrg{ 4101ab64890Smrg if (ic->core.im) 4111ab64890Smrg return (*ic->methods->wc_lookup_string) (ic, ev, buffer, nchars, 4121ab64890Smrg keysym, status); 4131ab64890Smrg return XLookupNone; 4141ab64890Smrg} 4151ab64890Smrg 4161ab64890Smrgint 41761b2299dSmrgXutf8LookupString(XIC ic, XKeyEvent *ev, char *buffer, int nbytes, 41861b2299dSmrg KeySym *keysym, Status *status) 4191ab64890Smrg{ 4201ab64890Smrg if (ic->core.im) { 4211ab64890Smrg if (ic->methods->utf8_lookup_string) 4221ab64890Smrg return (*ic->methods->utf8_lookup_string) (ic, ev, buffer, nbytes, 4231ab64890Smrg keysym, status); 4241ab64890Smrg else if (ic->methods->mb_lookup_string) 4251ab64890Smrg return (*ic->methods->mb_lookup_string) (ic, ev, buffer, nbytes, 4261ab64890Smrg keysym, status); 4271ab64890Smrg } 4281ab64890Smrg return XLookupNone; 4291ab64890Smrg} 430