Tizen 2.1 base
[platform/core/uifw/ise-engine-sunpinyin.git] / wrapper / xim / IMdkit / i18nAttr.c
1 /******************************************************************
2  
3          Copyright 1994, 1995 by Sun Microsystems, Inc.
4          Copyright 1993, 1994 by Hewlett-Packard Company
5  
6 Permission to use, copy, modify, distribute, and sell this software
7 and its documentation for any purpose is hereby granted without fee,
8 provided that the above copyright notice appear in all copies and
9 that both that copyright notice and this permission notice appear
10 in supporting documentation, and that the name of Sun Microsystems, Inc.
11 and Hewlett-Packard not be used in advertising or publicity pertaining to
12 distribution of the software without specific, written prior permission.
13 Sun Microsystems, Inc. and Hewlett-Packard make no representations about
14 the suitability of this software for any purpose.  It is provided "as is"
15 without express or implied warranty.
16  
17 SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
18 WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
20 SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
21 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
22 RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
23 CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
24 IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25  
26   Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
27
28     This version tidied and debugged by Steve Underwood May 1999
29  
30 ******************************************************************/
31
32 #include <X11/Xlib.h>
33 #include <X11/Xresource.h>
34 #include "IMdkit.h"
35 #include "Xi18n.h"
36 #include "XimFunc.h"
37
38 typedef struct 
39 {
40     char *name;
41     CARD16 type;
42 } IMListOfAttr;
43
44 typedef struct
45 {
46     char *name;
47     CARD8 major_opcode;
48     CARD8 minor_opcode;
49 } IMExtList;
50
51 IMListOfAttr Default_IMattr[] =
52 {
53     {XNQueryInputStyle,   XimType_XIMStyles},
54 /*    {XNQueryIMValuesList, XimType_XIMValuesList},     */
55     {(char *) NULL, (CARD16) 0}
56 };
57
58 IMListOfAttr Default_ICattr[] =
59 {
60     {XNInputStyle,              XimType_CARD32},
61     {XNClientWindow,            XimType_Window},
62     {XNFocusWindow,             XimType_Window},
63     {XNFilterEvents,            XimType_CARD32},
64     {XNPreeditAttributes,       XimType_NEST},
65     {XNStatusAttributes,        XimType_NEST},
66     {XNFontSet,                 XimType_XFontSet},
67     {XNArea,                    XimType_XRectangle},
68     {XNAreaNeeded,              XimType_XRectangle},
69     {XNColormap,                XimType_CARD32},
70     {XNStdColormap,             XimType_CARD32},
71     {XNForeground,              XimType_CARD32},
72     {XNBackground,              XimType_CARD32},
73     {XNBackgroundPixmap,        XimType_CARD32},
74     {XNSpotLocation,            XimType_XPoint},
75     {XNLineSpace,               XimType_CARD32},
76     {XNPreeditState,            XimType_CARD32},
77     {XNSeparatorofNestedList,   XimType_SeparatorOfNestedList},
78     {(char *) NULL, 0}
79 };
80
81 IMExtList Default_Extension[] =
82 {
83     {"XIM_EXT_MOVE", XIM_EXTENSION, XIM_EXT_MOVE},
84     {"XIM_EXT_SET_EVENT_MASK", XIM_EXTENSION, XIM_EXT_SET_EVENT_MASK},
85     {"XIM_EXT_FORWARD_KEYEVENT", XIM_EXTENSION, XIM_EXT_FORWARD_KEYEVENT},
86     {(char *) NULL, 0, 0}
87 };
88
89 static void CountAttrList(IMListOfAttr *attr, int *total_count)
90 {
91     *total_count = 0;
92
93     while (attr->name != NULL)
94     {
95         attr++;
96         ++(*total_count);
97     }
98 }
99
100 static XIMAttr *CreateAttrList (Xi18n i18n_core,
101                                 IMListOfAttr *attr,
102                                 int *total_count)
103 {
104     XIMAttr *args, *p;
105     unsigned int buf_size;
106
107     CountAttrList(attr, total_count);
108
109     buf_size = (unsigned) (*total_count + 1)*sizeof (XIMAttr);
110     args = (XIMAttr *) malloc (buf_size);
111     if (!args)
112         return (XIMAttr *) NULL;
113     /*endif*/
114     memset (args, 0, buf_size);
115
116     for (p = args;  attr->name != NULL;  attr++, p++)
117     {
118         p->name = attr->name;
119         p->length = strlen (attr->name);
120         p->type = (CARD16) attr->type;
121         p->attribute_id = XrmStringToQuark (p->name);
122         if (strcmp (p->name, XNPreeditAttributes) == 0)
123             i18n_core->address.preeditAttr_id = p->attribute_id;
124         else if (strcmp (p->name, XNStatusAttributes) == 0)
125             i18n_core->address.statusAttr_id = p->attribute_id;
126         else if (strcmp (p->name, XNSeparatorofNestedList) == 0)
127             i18n_core->address.separatorAttr_id = p->attribute_id;
128         /*endif*/
129     }
130     /*endfor*/
131     p->name = (char *) NULL;
132
133     return args;
134 }
135
136 void _Xi18nInitAttrList (Xi18n i18n_core)
137 {
138     XIMAttr *args;
139     int total_count;
140
141     /* init IMAttr list */
142     if (i18n_core->address.xim_attr)
143         XFree ((char *)i18n_core->address.xim_attr);
144     /*endif*/
145     args = CreateAttrList (i18n_core, Default_IMattr, &total_count);
146
147     i18n_core->address.im_attr_num = total_count;
148     i18n_core->address.xim_attr = (XIMAttr *)args;
149
150     /* init ICAttr list */
151     if (i18n_core->address.xic_attr)
152         XFree ((char *) i18n_core->address.xic_attr);
153     /*endif*/
154     args = CreateAttrList (i18n_core, Default_ICattr, &total_count);
155
156     i18n_core->address.ic_attr_num = total_count;
157     i18n_core->address.xic_attr = (XICAttr *) args;
158 }
159
160 void _Xi18nInitExtension(Xi18n i18n_core)
161 {
162     register int i;
163     IMExtList *extensions = (IMExtList *) Default_Extension;
164     XIMExt *ext_list = (XIMExt *) i18n_core->address.extension;
165
166     for (i = 0;  extensions->name;  i++, ext_list++, extensions++)
167     {
168         ext_list->major_opcode = extensions->major_opcode;
169         ext_list->minor_opcode = extensions->minor_opcode;
170         ext_list->name = extensions->name;
171         ext_list->length = strlen(ext_list->name);
172     }
173     /*endfor*/
174     i18n_core->address.ext_num = i;
175 }