1 #ifndef lint
2 static char *rcsid = "$Id: improto.c,v 1.5 1994/05/31 07:54:04 ishisone Exp $";
3 #endif
4 /*
5  * Copyright (c) 1994  Software Research Associates, Inc.
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation for any purpose and without fee is hereby granted, provided
9  * that the above copyright notice appear in all copies and that both that
10  * copyright notice and this permission notice appear in supporting
11  * documentation, and that the name of Software Research Associates not be
12  * used in advertising or publicity pertaining to distribution of the
13  * software without specific, written prior permission.  Software Research
14  * Associates makes no representations about the suitability of this software
15  * for any purpose.  It is provided "as is" without express or implied
16  * warranty.
17  *
18  * Author:  Makoto Ishisone, Software Research Associates, Inc., Japan
19  */
20 
21 #include "im.h"
22 #include "IMProtoP.h"
23 
24 /*
25  * This library contains interface functions between imlib and
26  * IMProtocol widget.
27  */
28 
29 /*- IMRegisterConnection: register connection to the protocol widget -*/
30 void
IMRegisterConnection(conn)31 IMRegisterConnection(conn)
32 IMConnection *conn;
33 {
34     IMProtocolWidget ipw = (IMProtocolWidget)conn->proto_widget;
35 
36     conn->next = ipw->imp.connection_list;
37     ipw->imp.connection_list = conn;
38 }
39 
40 /*- IMUnregisterConnection: unregister connection from the protocol widget -*/
41 void
IMUnregisterConnection(conn)42 IMUnregisterConnection(conn)
43 IMConnection *conn;
44 {
45     IMProtocolWidget ipw = (IMProtocolWidget)conn->proto_widget;
46     IMConnection *p, *q;
47 
48     p = ipw->imp.connection_list;
49     q = NULL;
50     while (p != NULL) {
51 	if (p == conn) {
52 	    if (q == NULL) {
53 		ipw->imp.connection_list = p->next;
54 	    } else {
55 		q->next = p->next;
56 	    }
57 	    /*
58 	     * If there are no connections, and the no-more-connections
59 	     * flag is set to true, destroy the protocol widget.
60 	     */
61 	    if (ipw->imp.connection_list == NULL &&
62 		ipw->imp.no_more_connections == True) {
63 		DPRINT(("IMProtocolWidget no longer necessary. killing..\n"));
64 		XtDestroyWidget((Widget)ipw);
65 	    }
66 	    return;
67 	}
68 	q = p;
69 	p = p->next;
70     }
71 }
72 
73 /*- IMConnectionList: get connection list -*/
74 IMConnection *
IMConnectionList(w)75 IMConnectionList(w)
76 Widget w;
77 {
78     IMProtocolWidget ipw = (IMProtocolWidget)w;
79 
80     return ipw->imp.connection_list;
81 }
82 
83 /*- IMPushQueue: push connection to the scheduler queue -*/
84 void
IMPushQueue(conn)85 IMPushQueue(conn)
86 IMConnection *conn;
87 {
88     Widget w = conn->proto_widget;
89 
90     conn->queue_next = IM_QUEUE(w);
91     IM_QUEUE(w) = conn;
92 }
93 
94 /*- IMPopQueue: pop connection from the scheduler queue */
95 IMConnection *
IMPopQueue(w)96 IMPopQueue(w)
97 Widget w;
98 {
99     IMConnection *conn;
100 
101     conn = IM_QUEUE(w);
102     if (conn != NULL) {
103 	IM_QUEUE(w) = conn->queue_next;
104 	conn->queue_next = NULL;
105     }
106     return conn;
107 }
108 
109 /*- IMQueueEmpty: returns true if the scheduler queue is empty -*/
110 int
IMQueueEmpty(w)111 IMQueueEmpty(w)
112 Widget w;
113 {
114     return(IM_QUEUE(w) == NULL);
115 }
116 
117 /*- IMDefaultForeground: get default foreground color -*/
118 Pixel
IMDefaultForeground(w)119 IMDefaultForeground(w)
120 Widget w;
121 {
122     IMProtocolWidget ipw = (IMProtocolWidget)w;
123 
124     return ipw->imp.foreground;
125 }
126 
127 /*- IMDefaultBackground: get default background color -*/
128 Pixel
IMDefaultBackground(w)129 IMDefaultBackground(w)
130 Widget w;
131 {
132     IMProtocolWidget ipw = (IMProtocolWidget)w;
133 
134     return ipw->core.background_pixel;
135 }
136 
137 /*- IMDefaultFontSet: get default font set -*/
138 char *
IMDefaultFontSet(imp)139 IMDefaultFontSet(imp)
140 IMIM *imp;
141 {
142     IMProtocolWidget ipw = (IMProtocolWidget)imp->connection->proto_widget;
143 
144     return ipw->imp.default_fontlist;
145 }
146 
147 /*- IMFontBank: get font bank for the specified IM -*/
148 FontBank
IMFontBank(imp)149 IMFontBank(imp)
150 IMIM *imp;
151 {
152     IMProtocolWidget ipw = (IMProtocolWidget)imp->connection->proto_widget;
153 
154     return ipw->imp.font_bank;
155 }
156 
157 /*- IMStatusWidth: get default status width -*/
158 int
IMStatusWidth(w)159 IMStatusWidth(w)
160 Widget w;
161 {
162     IMProtocolWidget ipw = (IMProtocolWidget)w;
163 
164     return ipw->imp.status_width;
165 }
166 
167 /*- IMInitHash: initialize IM/IC hash table -*/
168 void
IMInitHash(w)169 IMInitHash(w)
170 Widget w;
171 {
172     IMIM **impp;
173     IMIC **icpp;
174     int i;
175 
176     impp = IM_IMHASH(w);
177     icpp = IM_ICHASH(w);
178     for (i = 0; i < IM_HASH_SIZE; i++) impp[i] = NULL;
179     for (i = 0; i < IC_HASH_SIZE; i++) icpp[i] = NULL;
180     IM_LASTIMID(w) = IM_LASTICID(w) = 0;
181 }
182 
183 /*- IMIMHash: get IM hash table -*/
184 IMIM **
IMIMHash(w)185 IMIMHash(w)
186 Widget w;
187 {
188     return IM_IMHASH(w);
189 }
190 
191 /*- IMICHash: get IC hash table -*/
192 IMIC **
IMICHash(w)193 IMICHash(w)
194 Widget w;
195 {
196     return IM_ICHASH(w);
197 }
198 
199 /*- IMNextIMID: return next IMID (it might be used, though) -*/
200 unsigned int
IMNextIMID(w)201 IMNextIMID(w)
202 Widget w;
203 {
204     long id = IM_LASTIMID(w) + 1;	/* use long int to avoid overflow */
205 
206     if (id > 65535L) id = 1;
207     IM_LASTIMID(w) = (unsigned int)id;
208     return (unsigned int)id;
209 }
210 
211 /*- IMNextICID: return next ICID (it might be used, though) -*/
212 unsigned int
IMNextICID(w)213 IMNextICID(w)
214 Widget w;
215 {
216     long id = IM_LASTICID(w) + 1;	/* use long int to avoid overflow */
217 
218     if (id > 65535L) id = 1;
219     IM_LASTICID(w) = (unsigned int)id;
220     return (unsigned int)id;
221 }
222 
223 /*- IMCtextAtom: get COMPOUND_TEXT atom -*/
224 Atom
IMCtextAtom(w)225 IMCtextAtom(w)
226 Widget w;
227 {
228     return ATOM_CTEXT(w);
229 }
230 
231 /*- IMKi2CommAtom: get _KINPUT2_COMM atom -*/
232 Atom
IMKi2CommAtom(w)233 IMKi2CommAtom(w)
234 Widget w;
235 {
236     return ATOM_KI2COMM(w);
237 }
238 
239 /*- IMXConnectAtom: get _XIM_XCONNECT atom -*/
240 Atom
IMXConnectAtom(w)241 IMXConnectAtom(w)
242 Widget w;
243 {
244     return ATOM_XCONNECT(w);
245 }
246 
247 /*- IMProtocolAtom: get _XIM_PROTOCOL atom -*/
248 Atom
IMProtocolAtom(w)249 IMProtocolAtom(w)
250 Widget w;
251 {
252     return ATOM_PROTOCOL(w);
253 }
254 
255 /*- IMMoreDataAtom: get _XIM_MOREDATA atom -*/
256 Atom
IMMoreDataAtom(w)257 IMMoreDataAtom(w)
258 Widget w;
259 {
260     return ATOM_MOREDATA(w);
261 }
262 
263 /*- IMTriggerKeys: get trigger key list -*/
264 IMTriggerKey *
IMTriggerKeys(imp,num_triggersp)265 IMTriggerKeys(imp, num_triggersp)
266 IMIM *imp;
267 int *num_triggersp;
268 {
269     IMProtocolWidget ipw = (IMProtocolWidget)imp->connection->proto_widget;
270 
271     *num_triggersp = ipw->imp.num_trigger_keys;
272     return ipw->imp.trigger_keys;
273 }
274 
275 /*- getConverter: look up converter for the specified locale -*/
276 IMConverter *
IMGetConverter(w,locale)277 IMGetConverter(w, locale)
278 Widget w;
279 char *locale;
280 {
281     IMProtocolWidget ipw = (IMProtocolWidget)w;
282     IMConverter *conv = &ipw->imp.converter;
283     int i;
284 
285     for (i = 0; i < conv->num_locales; i++) {
286 	if (!strcmp(conv->supported_locales[i], locale)) return conv;
287     }
288     return NULL;
289 }
290