home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / Xic_Wrap.c < prev    next >
C/C++ Source or Header  |  1999-11-02  |  12KB  |  511 lines

  1. /*
  2.  * $XConsortium: ICWrap.c,v 11.9 94/04/17 20:19:54 rws Exp $
  3.  */
  4.  
  5. /*
  6.  * Copyright 1990, 1991 by OMRON Corporation, NTT Software Corporation,
  7.  *                      and Nippon Telegraph and Telephone Corporation
  8.  * Copyright 1991 by the Open Software Foundation
  9.  * Copyright 1993 by the FUJITSU LIMITED
  10.  *
  11.  * Permission to use, copy, modify, distribute, and sell this software and its
  12.  * documentation for any purpose is hereby granted without fee, provided that
  13.  * the above copyright notice appear in all copies and that both that
  14.  * copyright notice and this permission notice appear in supporting
  15.  * documentation, and that the names of OMRON, NTT Software, NTT, and
  16.  * Open Software Foundation not be used in advertising or publicity 
  17.  * pertaining to distribution of the software without specific, 
  18.  * written prior permission. OMRON, NTT Software, NTT, and Open Software
  19.  * Foundation make no representations about the suitability of this
  20.  * software for any purpose.  It is provided "as is" without express or
  21.  * implied warranty.
  22.  *
  23.  * OMRON, NTT SOFTWARE, NTT, AND OPEN SOFTWARE FOUNDATION 
  24.  * DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 
  25.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
  26.  * SHALL OMRON, NTT SOFTWARE, NTT, OR OPEN SOFTWARE FOUNDATION BE
  27.  * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
  28.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  29.  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  30.  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  31.  * 
  32.  *    Authors: Li Yuhong        OMRON Corporation
  33.  *         Tatsuya Kato        NTT Software Corporation
  34.  *         Hiroshi Kuribayashi    OMRON Coproration
  35.  *         Muneiyoshi Suzuki    Nippon Telegraph and Telephone Co.
  36.  * 
  37.  *         M. Collins        OSF  
  38.  *         Takashi Fujiwara    FUJITSU LIMITED
  39.  */                
  40. /*
  41.  
  42. Copyright (c) 1991  X Consortium
  43.  
  44. Permission is hereby granted, free of charge, to any person obtaining
  45. a copy of this software and associated documentation files (the
  46. "Software"), to deal in the Software without restriction, including
  47. without limitation the rights to use, copy, modify, merge, publish,
  48. distribute, sublicense, and/or sell copies of the Software, and to
  49. permit persons to whom the Software is furnished to do so, subject to
  50. the following conditions:
  51.  
  52. The above copyright notice and this permission notice shall be included
  53. in all copies or substantial portions of the Software.
  54.  
  55. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  56. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  57. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  58. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
  59. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  60. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  61. OTHER DEALINGS IN THE SOFTWARE.
  62.  
  63. Except as contained in this notice, the name of the X Consortium shall
  64. not be used in advertising or otherwise to promote the sale, use or
  65. other dealings in this Software without prior written authorization
  66. from the X Consortium.
  67.  
  68. */
  69.  
  70. #define NEED_EVENTS
  71. #include "Xlib_private.h"
  72. #include "Xlcint.h"
  73.  
  74. static int
  75. _XIMNestedListToNestedList(nlist, list)
  76.     XIMArg *nlist;   /* This is the new list */
  77.     XIMArg *list;    /* The original list */
  78. {
  79.     DBUG_ENTER("_XIMNestedListToNestedList")
  80.     register XIMArg *ptr = list;
  81.  
  82.     while (ptr->name) {
  83.     if (!strcmp(ptr->name, XNVaNestedList)) {
  84.         nlist += _XIMNestedListToNestedList(nlist, (XIMArg *)ptr->value);
  85.     } else {
  86.         nlist->name = ptr->name;
  87.         nlist->value = ptr->value;
  88.         ptr++;
  89.         nlist++;
  90.     }
  91.     }
  92.     DBUG_RETURN(ptr - list);
  93. }
  94.  
  95. static void
  96. _XIMCountNestedList(args, total_count)
  97.     XIMArg *args;
  98.     int *total_count;
  99. {
  100.     DBUG_ENTER("_XIMCountNestedList")
  101.     for (; args->name; args++) {
  102.     if (!strcmp(args->name, XNVaNestedList))
  103.         _XIMCountNestedList((XIMArg *)args->value, total_count);
  104.     else
  105.         ++(*total_count);
  106.     }
  107.     DBUG_VOID_RETURN;
  108. }
  109.  
  110. #if NeedVarargsPrototypes
  111. static void
  112. _XIMCountVaList(va_list var, int *total_count)
  113. #else
  114. static void
  115. _XIMCountVaList(var, total_count)
  116.     va_list var;
  117.     int *total_count;
  118. #endif
  119. {
  120.     DBUG_ENTER("_XIMCountVaList")
  121.     char *attr;
  122.  
  123.     *total_count = 0;
  124.  
  125.     for (attr = va_arg(var, char*); attr; attr = va_arg(var, char*)) {
  126.     if (!strcmp(attr, XNVaNestedList)) {
  127.         _XIMCountNestedList(va_arg(var, XIMArg*), total_count);
  128.     } else {
  129.         va_arg(var, XIMArg*);
  130.         ++(*total_count);
  131.     }
  132.     }
  133.     DBUG_VOID_RETURN;
  134. }
  135.  
  136. #if NeedVarargsPrototypes
  137. static void
  138. _XIMVaToNestedList(va_list var, int max_count, XIMArg **args_return)
  139. #else
  140. static void
  141. _XIMVaToNestedList(var, max_count, args_return)
  142.     va_list var;
  143.     int max_count;
  144.     XIMArg **args_return;
  145. #endif
  146. {
  147.     DBUG_ENTER("_XIMVaToNestedList")
  148.     XIMArg *args;
  149.     char   *attr;
  150.  
  151.     if (max_count <= 0) {
  152.     *args_return = (XIMArg *)NULL;
  153.     DBUG_VOID_RETURN;
  154.     }
  155.  
  156.     args = (XIMArg *)Xmalloc((unsigned)(max_count + 1) * sizeof(XIMArg));
  157.     *args_return = args;
  158.     if (!args) DBUG_VOID_RETURN;
  159.  
  160.     for (attr = va_arg(var, char*); attr; attr = va_arg(var, char*)) {
  161.     if (!strcmp(attr, XNVaNestedList)) {
  162.         args += _XIMNestedListToNestedList(args, va_arg(var, XIMArg*));
  163.     } else {
  164.         args->name = attr;
  165.         args->value = va_arg(var, XPointer);
  166.         args++;
  167.     }
  168.     }
  169.     args->name = (char*)NULL;
  170.     DBUG_VOID_RETURN;
  171. }
  172.  
  173. /*ARGSUSED*/
  174. #if NeedVarargsPrototypes
  175. XVaNestedList
  176. XVaCreateNestedList(int dummy, ...)
  177. #else
  178. XVaNestedList
  179. XVaCreateNestedList(dummy, va_alist)
  180.     int dummy;
  181.     va_dcl
  182. #endif
  183. {
  184.     DBUG_ENTER("XVaCreateNestedList")
  185.     va_list        var;
  186.     XIMArg        *args = NULL;
  187.     int            total_count;
  188.  
  189.     Va_start(var, dummy);
  190.     _XIMCountVaList(var, &total_count);
  191.     va_end(var);
  192.  
  193.     Va_start(var, dummy);
  194.     _XIMVaToNestedList(var, total_count, &args);
  195.     va_end(var);
  196.  
  197.     DBUG_RETURN((XVaNestedList)args);
  198. }
  199.  
  200. #if NeedVarargsPrototypes
  201. char *
  202. XSetIMValues(XIM im, ...)
  203. #else                /* NeedVarargsPrototypes */
  204. char *
  205. XSetIMValues(im, va_alist)
  206.     XIM im;
  207.     va_dcl
  208. #endif                /* NeedVarargsPrototypes */
  209. {
  210.     DBUG_ENTER("XSetIMValues")
  211.     va_list var;
  212.     int     total_count;
  213.     XIMArg *args;
  214.     char   *ret;
  215.  
  216.     /*
  217.      * so count the stuff dangling here
  218.      */
  219.     Va_start(var, im);
  220.     _XIMCountVaList(var, &total_count);
  221.     va_end(var);
  222.  
  223.     /*
  224.      * now package it up so we can send it along
  225.      */
  226.     Va_start(var, im);
  227.     _XIMVaToNestedList(var, total_count, &args);
  228.     va_end(var);
  229.  
  230.     ret = (*im->methods->set_values) (im, args);
  231.     if (args) Xfree((char *)args);
  232.     DBUG_RETURN(ret);
  233. }
  234.  
  235. #if NeedVarargsPrototypes
  236. char *
  237. XGetIMValues(XIM im, ...)
  238. #else                /* NeedVarargsPrototypes */
  239. char *
  240. XGetIMValues(im, va_alist)
  241.     XIM im;
  242.     va_dcl
  243. #endif                /* NeedVarargsPrototypes */
  244. {
  245.     DBUG_ENTER("XGetIMValues")
  246.     va_list var;
  247.     int     total_count;
  248.     XIMArg *args;
  249.     char   *ret;
  250.  
  251.     /*
  252.      * so count the stuff dangling here
  253.      */
  254.     Va_start(var, im);
  255.     _XIMCountVaList(var, &total_count);
  256.     va_end(var);
  257.  
  258.     /*
  259.      * now package it up so we can send it along
  260.      */
  261.     Va_start(var, im);
  262.     _XIMVaToNestedList(var, total_count, &args);
  263.     va_end(var);
  264.  
  265.     ret = (*im->methods->get_values) (im, args);
  266.     if (args) Xfree((char *)args);
  267.     DBUG_RETURN(ret);
  268. }
  269.  
  270. /*
  271.  * Create an input context within the input method, 
  272.  * and return a pointer to the input context.
  273.  */
  274.  
  275. #if NeedVarargsPrototypes
  276. XIC
  277. XCreateIC(XIM im, ...)
  278. #else
  279. XIC
  280. XCreateIC(im, va_alist)
  281.     XIM im;        /* specified the attached input method */
  282.     va_dcl        /* specified variable length argment list */
  283. #endif
  284. {
  285.     DBUG_ENTER("XCreateIC")
  286.     va_list var;
  287.     int     total_count;
  288.     XIMArg *args;
  289.     XIC     ic;
  290.   
  291.     /*
  292.      * so count the stuff dangling here
  293.      */
  294.     Va_start(var, im);
  295.     _XIMCountVaList(var, &total_count);
  296.     va_end(var);
  297.  
  298.     /*
  299.      * now package it up so we can send it along
  300.      */
  301.     Va_start(var, im);
  302.     _XIMVaToNestedList(var, total_count, &args);
  303.     va_end(var);
  304.  
  305.     ic = (XIC) (*im->methods->create_ic) (im, args);
  306.     if (args) Xfree((char *)args);
  307.     if (ic) {
  308.     ic->core.next = im->core.ic_chain;
  309.     im->core.ic_chain = ic;
  310.     }
  311.     DBUG_RETURN(ic);
  312. }
  313.  
  314. /*
  315.  * Free the input context.
  316.  */
  317. void
  318. XDestroyIC(ic)
  319.     XIC ic;
  320. {
  321.     DBUG_ENTER("XDestroyIC")
  322.     XIM im = ic->core.im;
  323.     XIC *prev;
  324.  
  325.     (*ic->methods->destroy) (ic);
  326.     if (im) {
  327.     for (prev = &im->core.ic_chain; *prev; prev = &(*prev)->core.next) {
  328.         if (*prev == ic) {
  329.         *prev = ic->core.next;
  330.         break;
  331.         }
  332.     }
  333.     }
  334.     Xfree ((char *) ic);
  335.     DBUG_VOID_RETURN;
  336. }
  337.  
  338. #if NeedVarargsPrototypes
  339. char *
  340. XGetICValues(XIC ic, ...)
  341. #else
  342. char *
  343. XGetICValues(ic, va_alist)
  344.     XIC ic;
  345.     va_dcl
  346. #endif
  347.     DBUG_ENTER("XGetICValues")
  348.     va_list var;
  349.     int     total_count;
  350.     XIMArg *args;
  351.     char   *ret;
  352.  
  353.     if (!ic->core.im)
  354.     DBUG_RETURN((char *) NULL);
  355.  
  356.     /*
  357.      * so count the stuff dangling here
  358.      */
  359.     Va_start(var, ic);
  360.     _XIMCountVaList(var, &total_count);
  361.     va_end(var);
  362.  
  363.     /*
  364.      * now package it up so we can send it along
  365.      */
  366.     Va_start(var, ic);
  367.     _XIMVaToNestedList(var, total_count, &args);
  368.     va_end(var);
  369.  
  370.     ret = (*ic->methods->get_values) (ic, args);
  371.     if (args) Xfree((char *)args);
  372.     DBUG_RETURN(ret);
  373. }
  374.  
  375. #if NeedVarargsPrototypes
  376. char *
  377. XSetICValues(XIC ic, ...)
  378. #else
  379. char *
  380. XSetICValues(ic, va_alist)
  381.     XIC ic;
  382.     va_dcl
  383. #endif
  384. {
  385.     DBUG_ENTER("XSetICValues")
  386.     va_list var;
  387.     int     total_count;
  388.     XIMArg *args;
  389.     char   *ret;
  390.  
  391.     if (!ic->core.im)
  392.     DBUG_RETURN((char *) NULL);
  393.  
  394.     /*
  395.      * so count the stuff dangling here
  396.      */
  397.     Va_start(var, ic);
  398.     _XIMCountVaList(var, &total_count);
  399.     va_end(var);
  400.  
  401.     /*
  402.      * now package it up so we can send it along
  403.      */
  404.     Va_start(var, ic);
  405.     _XIMVaToNestedList(var, total_count, &args);
  406.     va_end(var);
  407.  
  408.     ret = (*ic->methods->set_values) (ic, args);
  409.     if (args) Xfree((char *)args);
  410.     DBUG_RETURN(ret);
  411. }
  412.  
  413. /*
  414.  * Require the input manager to focus the focus window attached to the ic
  415.  * argument.
  416.  */
  417. void
  418. XSetICFocus(ic)
  419.     XIC ic;
  420. {
  421.   DBUG_ENTER("XSetICFocus")
  422.   if (ic->core.im)
  423.       (*ic->methods->set_focus) (ic);
  424.   DBUG_VOID_RETURN;
  425. }
  426.  
  427. /*
  428.  * Require the input manager to unfocus the focus window attached to the ic
  429.  * argument.
  430.  */
  431. void
  432. XUnsetICFocus(ic)
  433.     XIC ic;
  434. {
  435.   DBUG_ENTER("XUnsetICFocus")
  436.   if (ic->core.im)
  437.       (*ic->methods->unset_focus) (ic);
  438.   DBUG_VOID_RETURN;
  439. }
  440.  
  441. /*
  442.  * Return the XIM associated with the input context.
  443.  */
  444. XIM
  445. XIMOfIC(ic)
  446.     XIC ic;
  447. {
  448.     DBUG_ENTER("XIMOfIC")
  449.     XIM result = ic->core.im;
  450.     DBUG_RETURN(result);
  451. }
  452.  
  453. char *XmbResetIC(ic)
  454.     XIC ic;
  455. {
  456.     DBUG_ENTER("XmbResetIC")
  457.     if (ic->core.im) {
  458.     char *result = (*ic->methods->mb_reset)(ic);
  459.     DBUG_RETURN(result);
  460.     }
  461.     DBUG_RETURN((char *)NULL);
  462. }
  463.  
  464. wchar_t *XwcResetIC(ic)
  465.     XIC ic;
  466. {
  467.     DBUG_ENTER("XwcResetIC")
  468.     if (ic->core.im) {
  469.     char *result = (*ic->methods->wc_reset)(ic);
  470.     DBUG_RETURN(result);
  471.     }
  472.     DBUG_RETURN((wchar_t *)NULL);
  473. }
  474.  
  475. int
  476. XmbLookupString(ic, ev, buffer, nbytes, keysym, status)
  477.     XIC ic;
  478.     register XKeyEvent *ev;
  479.     char *buffer;
  480.     int nbytes;
  481.     KeySym *keysym;
  482.     Status *status;
  483. {
  484.     DBUG_ENTER("XmbLookupString")
  485.     if (ic->core.im) {
  486.     int result = (*ic->methods->mb_lookup_string) (ic, ev, buffer, nbytes,
  487.                          keysym, status);
  488.     DBUG_RETURN(result);
  489.     }
  490.     DBUG_RETURN(XLookupNone);
  491. }
  492.  
  493. int
  494. XwcLookupString(ic, ev, buffer, nchars, keysym, status)
  495.     XIC ic;
  496.     register XKeyEvent *ev;
  497.     wchar_t *buffer;
  498.     int nchars;
  499.     KeySym *keysym;
  500.     Status *status;
  501. {
  502.     DBUG_ENTER("XwcLookupString")
  503.     if (ic->core.im) {
  504.     int result = (*ic->methods->wc_lookup_string) (ic, ev, buffer, nchars,
  505.                          keysym, status);
  506.     DBUG_RETURN(result);
  507.     }
  508.     DBUG_RETURN(XLookupNone);
  509. }
  510.