Back to index

im-sdk  12.3.91
i18nAttr.c
Go to the documentation of this file.
00001 /******************************************************************
00002  
00003          Copyright 1994, 1995 by Sun Microsystems, Inc.
00004          Copyright 1993, 1994 by Hewlett-Packard Company
00005  
00006 Permission to use, copy, modify, distribute, and sell this software
00007 and its documentation for any purpose is hereby granted without fee,
00008 provided that the above copyright notice appear in all copies and
00009 that both that copyright notice and this permission notice appear
00010 in supporting documentation, and that the name of Sun Microsystems, Inc.
00011 and Hewlett-Packard not be used in advertising or publicity pertaining to
00012 distribution of the software without specific, written prior permission.
00013 Sun Microsystems, Inc. and Hewlett-Packard make no representations about
00014 the suitability of this software for any purpose.  It is provided "as is"
00015 without express or implied warranty.
00016  
00017 SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
00018 WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
00019 WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
00020 SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
00021 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
00022 RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
00023 CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
00024 IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00025  
00026   Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
00027  
00028 ******************************************************************/
00029 #include <X11/Xlib.h>
00030 #include "X11R6IMProtoData.h"
00031 #include "Xi18n.h"
00032 
00033 XIMListOfAttr Default_IMattr[] = {
00034     {XNQueryInputStyle, XimType_XIMStyles, 0},
00035     {(char *)NULL, (CARD16)0, (CARD16)0}
00036 };
00037 
00038 XIMListOfAttr Default_ICattr[] = {
00039     {XNInputStyle, XimType_CARD32, 0},
00040     {XNClientWindow, XimType_Window, 0},
00041     {XNFocusWindow, XimType_Window, 0},
00042     {XNFilterEvents, XimType_CARD32, 0},
00043     {XNPreeditAttributes, XimType_NEST, 0},
00044     {XNStatusAttributes, XimType_NEST, 0},
00045     {XNFontSet, XimType_XFontSet, 0},
00046     {XNArea, XimType_XRectangle, 0},
00047     {XNAreaNeeded, XimType_XRectangle, 0},
00048     {XNColormap, XimType_CARD32, 0},
00049     {XNStdColormap, XimType_CARD32, 0},
00050     {XNForeground, XimType_CARD32, 0},
00051     {XNBackground, XimType_CARD32, 0},
00052     {XNBackgroundPixmap, XimType_CARD32, 0},
00053     {XNSpotLocation, XimType_XPoint, 0},
00054     {XNLineSpace, XimType_CARD32, 0},
00055     {XNPreeditState, XimType_CARD32, 0},
00056     {XNCursor, XimType_CARD32, 0},
00057     {XNSeparatorofNestedList, XimType_SeparatorOfNestedList, 0},
00058     {(char *)NULL, (CARD16)0, (CARD16)0}
00059 };
00060 
00061 IMExtList Default_Extension[] = {
00062     {"XIM_EXT_MOVE", XIM_EXTENSION, XIM_EXT_MOVE},
00063     {"XIM_EXT_SET_EVENT_MASK", XIM_EXTENSION, XIM_EXT_SET_EVENT_MASK},
00064     {"XIM_EXT_FORWARD_KEYEVENT", XIM_EXTENSION, XIM_EXT_FORWARD_KEYEVENT},
00065     {(char *)NULL, (CARD8)NULL, (CARD8)NULL}
00066 };
00067 
00068 static void
00069 CountAttrList(XIMListOfAttr *attr, int *total_count)
00070 {
00071     *total_count = 0;
00072 
00073     while (attr->name != NULL) {
00074        attr++;
00075        ++(*total_count);
00076     }
00077 }
00078 
00079 static XIMAttr *
00080 CreateAttrList(Xi18n i18n_core, XIMListOfAttr *attr, int *total_count)
00081 {
00082     XIMAttr *args, *p;
00083     unsigned int buf_size;
00084 
00085     CountAttrList(attr, total_count);
00086 
00087     buf_size = (unsigned)(*total_count + 1) * sizeof(XIMAttr);
00088     args = (XIMAttr *)malloc(buf_size);
00089     if (!args) return (XIMAttr *)NULL;
00090 
00091     memset(args, 0, buf_size);
00092 
00093     for (p = args; attr->name != NULL; attr++, p++) {
00094        p->name = attr->name;
00095        p->length = strlen(attr->name);
00096        p->type = (CARD16)attr->type;
00097        p->attribute_id = (attr->id == 0? XrmStringToQuark(p->name) : attr->id);
00098        if (!strcmp(p->name, XNPreeditAttributes))
00099          i18n_core->address.preeditAttr_id = p->attribute_id;
00100        else if (!strcmp(p->name, XNStatusAttributes))
00101          i18n_core->address.statusAttr_id = p->attribute_id;
00102        else if (!strcmp(p->name, XNSeparatorofNestedList))
00103          i18n_core->address.separatorAttr_id = p->attribute_id;
00104     }
00105     p->name = (char*)NULL;
00106 
00107     return args;
00108 }
00109 
00110 void
00111 _Xi18nInitAttrList(Xi18n i18n_core)
00112 {
00113     XIMAttr *args;
00114     int       total_count;
00115 
00116     /* init IMAttr list */
00117     if (i18n_core->address.xim_attr)
00118       XFree((char *)i18n_core->address.xim_attr);
00119     args = CreateAttrList(i18n_core, Default_IMattr, &total_count);
00120 
00121     i18n_core->address.im_attr_num = total_count;
00122     i18n_core->address.xim_attr = (XIMAttr *)args;
00123 
00124     /* init ICAttr list */
00125     if (i18n_core->address.xic_attr)
00126       XFree((char *)i18n_core->address.xic_attr);
00127     args = CreateAttrList(i18n_core, Default_ICattr, &total_count);
00128 
00129     i18n_core->address.ic_attr_num = total_count;
00130     i18n_core->address.xic_attr = (XICAttr *)args;
00131 
00132     return;
00133 }
00134 
00135 void
00136 _Xi18nInitExtension(Xi18n i18n_core)
00137 {
00138     register int i;
00139     IMExtList *extensions = (IMExtList*)Default_Extension;
00140     XIMExt *ext_list = (XIMExt*)i18n_core->address.extension;
00141     
00142     for (i = 0; extensions->name != NULL; i++, ext_list++, extensions++) {
00143        ext_list->major_opcode = extensions->major_opcode;
00144        ext_list->minor_opcode = extensions->minor_opcode;
00145        ext_list->name = extensions->name;
00146        ext_list->length = strlen(ext_list->name);
00147     }
00148     i18n_core->address.ext_num = i;
00149     return;
00150 }
00151 
00152 void
00153 _Xi18nChangeIMList(Xi18n i18n_core, XPointer value)
00154 {
00155     XIMAttr *args;
00156     int       total_count;
00157 
00158     /* init IMAttr list */
00159     if (i18n_core->address.xim_attr)
00160        XFree((char *)i18n_core->address.xim_attr);
00161     args = CreateAttrList(i18n_core, (XIMListOfAttr*)value, &total_count);
00162 
00163     i18n_core->address.im_attr_num = total_count;
00164     i18n_core->address.xim_attr = (XIMAttr *)args;
00165 
00166     return;
00167 }
00168 
00169 void
00170 _Xi18nChangeICList(Xi18n i18n_core, XPointer value)
00171 {
00172     XIMAttr *args;
00173     int       total_count;
00174 
00175     /* init ICAttr list */
00176     if (i18n_core->address.xic_attr)
00177        XFree((char *)i18n_core->address.xic_attr);
00178     args = CreateAttrList(i18n_core, (XIMListOfAttr*)value, &total_count);
00179 
00180     i18n_core->address.ic_attr_num = total_count;
00181     i18n_core->address.xic_attr = (XICAttr *)args;
00182 
00183     return;
00184 }
00185