0
|
1 /*
|
|
2 * $Id: xresource.c,v 1.2 2001/06/14 18:16:12 ura Exp $
|
|
3 */
|
|
4
|
|
5 /*
|
|
6 * FreeWnn is a network-extensible Kana-to-Kanji conversion system.
|
|
7 * This file is part of FreeWnn.
|
|
8 *
|
|
9 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999
|
|
10 *
|
|
11 * Author: OMRON SOFTWARE Co., Ltd. <freewnn@rd.kyoto.omronsoft.co.jp>
|
|
12 *
|
|
13 * This program is free software; you can redistribute it and/or modify
|
|
14 * it under the terms of the GNU General Public License as published by
|
|
15 * the Free Software Foundation; either version 2, or (at your option)
|
|
16 * any later version.
|
|
17 *
|
|
18 * This program is distributed in the hope that it will be useful,
|
|
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21 * GNU General Public License for more details.
|
|
22 *
|
|
23 * You should have received a copy of the GNU General Public License
|
|
24 * along with GNU Emacs; see the file COPYING. If not, write to the
|
|
25 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
26 *
|
|
27 * Commentary:
|
|
28 *
|
|
29 * Change log:
|
|
30 *
|
|
31 * Last modified date: 8,Feb.1999
|
|
32 *
|
|
33 * Code:
|
|
34 *
|
|
35 */
|
|
36
|
|
37 /*
|
|
38 * X11R5 Input Method Test Program
|
|
39 * xresorce.c v 1.0 Mon Mar 4 10:33:36 JST 1991
|
|
40 */
|
|
41
|
|
42 /*
|
|
43 * Author: Takashi Inoue OMRON Corporation
|
|
44 * takashi@ari.ncl.omron.co.jp
|
|
45 *
|
|
46 * Shoji kamada OMRON Corporation
|
|
47 * kamada@ari.ncl.omron.co.jp
|
|
48 */
|
|
49
|
|
50 #include "exvalue.h"
|
|
51 #include "func.h"
|
|
52
|
|
53 #include <X11/Xutil.h>
|
|
54 #include <X11/Xatom.h>
|
|
55 #include <X11/Xresource.h>
|
|
56 #include <X11/cursorfont.h>
|
|
57
|
|
58 void
|
|
59 createxres () /* CREATE X RESources */
|
|
60 {
|
|
61 char **miss[ARRAY_MAX], *def[ARRAY_MAX];
|
|
62 int i[ARRAY_MAX], cnt, pix_no;
|
|
63 int flags = { DoRed | DoGreen | DoBlue };
|
|
64 u_long plane[PLANE_MAX];
|
|
65 static char *name[ARRAY_MAX][PIX_MAX] = {
|
|
66 {"white", "orange", "lightblue", "forestgreen"},
|
|
67 {"red", "blue", "yellow", "black"}
|
|
68 };
|
|
69 static char *font[ARRAY_MAX] = { "a14, k14, kana14", "-*--18-*" };
|
|
70 static u_int shape[ARRAY_MAX] = { XC_gumby, XC_trek };
|
|
71 Visual *visual;
|
|
72 u_long valuemask;
|
|
73 XGCValues values;
|
|
74
|
|
75 prstatus ("Creating X resources...");
|
|
76 if ((dpy = XOpenDisplay ("")) == NULL)
|
|
77 {
|
|
78 cls (stdisp);
|
|
79 cls (prdisp);
|
|
80 prprint ("Error : Can't open display\n\n");
|
|
81 prprint ("Check environment valuable \"DISPLAY\".\n\n");
|
|
82 freemwin ();
|
|
83 }
|
|
84 scr = XDefaultScreen (dpy);
|
|
85 rwin = RootWindow (dpy, scr);
|
|
86 visual = DefaultVisual (dpy, scr);
|
|
87 dcmap = DefaultColormap (dpy, scr);
|
|
88 if (XAllocColorCells (dpy, dcmap, False, plane, 0, pixel[cmflag], PIX_MAX))
|
|
89 {
|
|
90 for (pix_no = 0; pix_no < PIX_MAX; pix_no++)
|
|
91 {
|
|
92 XStoreNamedColor (dpy, dcmap, name[cmflag][pix_no], pixel[cmflag][pix_no], flags);
|
|
93 }
|
|
94 }
|
|
95 else
|
|
96 {
|
|
97 prprint ("I cannot allocate colors.\n");
|
|
98 prprint ("I will shutdown this program soon.\n\n");
|
|
99 freemwin ();
|
|
100 }
|
|
101 cmap[0] = XCreateColormap (dpy, rwin, visual, AllocNone);
|
|
102 cmap[1] = XCreateColormap (dpy, rwin, visual, AllocNone);
|
|
103 for (cnt = 0; cnt < ARRAY_MAX; cnt++)
|
|
104 {
|
|
105 if (XAllocColorCells (dpy, cmap[cnt], False, plane, 0, pixel[cnt], PIX_MAX))
|
|
106 {
|
|
107 for (pix_no = 0; pix_no < PIX_MAX; pix_no++)
|
|
108 {
|
|
109 XStoreNamedColor (dpy, cmap[cnt], name[cnt][pix_no], pixel[cnt][pix_no], flags);
|
|
110 }
|
|
111 }
|
|
112 else
|
|
113 {
|
|
114 prprint ("I cannot allocate colors.\n");
|
|
115 prprint ("I will shutdown this program soon.\n\n");
|
|
116 freemwin ();
|
|
117 }
|
|
118 fontset[cnt] = XCreateFontSet (dpy, font[cnt], &miss[cnt], &i[cnt], &def[cnt]);
|
|
119 cursor[cnt] = XCreateFontCursor (dpy, shape[cnt]);
|
|
120 pix[cnt] = XCreatePixmapFromBitmapData (dpy, rwin, bit_bits[cnt], BIT_WIDTH, BIT_HEIGHT, pixel[cmflag][1], pixel[cmflag][2], DefaultDepth (dpy, scr));
|
|
121 }
|
|
122 valuemask = GCFunction | GCForeground | GCBackground;
|
|
123 values.function = GXcopy;
|
|
124 values.foreground = pixel[cmflag][2];
|
|
125 values.background = pixel[cmflag][1];
|
|
126 gc = XCreateGC (dpy, rwin, valuemask, &values);
|
|
127 mktwin ();
|
|
128 mkmwin ();
|
|
129 mapwin ();
|
|
130 dstrwin ();
|
|
131 prstatus ("done.");
|
|
132 }
|
|
133
|
|
134
|
|
135 void
|
|
136 mktwin () /* MaKe Test WINdow */
|
|
137 {
|
|
138 XSizeHints hints;
|
|
139 XClassHint class_hints;
|
|
140 XWMHints wm_hints;
|
|
141 XTextProperty win_name, icon_name;
|
|
142
|
|
143 win_name.value = (u_char *) "X11R5 XIM Test";
|
|
144 win_name.encoding = XA_STRING;
|
|
145 win_name.format = 8;
|
|
146 win_name.nitems = strlen (win_name.value);
|
|
147 icon_name.value = win_name.value;
|
|
148 icon_name.encoding = XA_STRING;
|
|
149 icon_name.format = 8;
|
|
150 icon_name.nitems = win_name.nitems;
|
|
151 hints.flags = (USPosition | USSize | PMinSize | PMaxSize | PResizeInc | PBaseSize | PWinGravity);
|
|
152 hints.x = W1_X;
|
|
153 hints.y = W1_Y;
|
|
154 hints.width = hints.min_width = hints.max_width = W1_WIDTH;
|
|
155 hints.height = hints.min_height = hints.min_height = W1_HEIGHT;
|
|
156 hints.width_inc = hints.height_inc = 0;
|
|
157 hints.base_width = W1_WIDTH;
|
|
158 hints.base_height = W1_HEIGHT;
|
|
159 hints.win_gravity = CenterGravity;
|
|
160 class_hints.res_name = NULL;
|
|
161 class_hints.res_class = NULL;
|
|
162 wm_hints.flags = InputHint;
|
|
163 wm_hints.input = True;
|
|
164
|
|
165 window1.win = XCreateSimpleWindow (dpy, rwin, W1_X, W1_Y, W1_WIDTH, W1_HEIGHT, W_BORDER, pixel[cmflag][2], pixel[cmflag][1]);
|
|
166 window2.win = XCreateSimpleWindow (dpy, window1.win, W23_X, W2_Y, W2_WIDTH, W23_HEIGHT, W_BORDER, pixel[cmflag][2], pixel[cmflag][1]);
|
|
167 window3.win = XCreateSimpleWindow (dpy, window1.win, W23_X, W3_Y, W3_WIDTH, W23_HEIGHT, W_BORDER, pixel[cmflag][2], pixel[cmflag][1]);
|
|
168 ufocus = window3.win;
|
|
169 window1.name = XCreateSimpleWindow (dpy, window1.win, WIN_ITV, CALCY (W1_HEIGHT, NW_HEIGHT), NW_WIDTH, NW_HEIGHT, W_BORDER, pixel[cmflag][1], pixel[cmflag][1]);
|
|
170 window2.name = XCreateSimpleWindow (dpy, window2.win, WIN_ITV, CALCY (W23_HEIGHT, NW_HEIGHT), NW_WIDTH, NW_HEIGHT, W_BORDER, pixel[cmflag][1], pixel[cmflag][1]);
|
|
171 window3.name = XCreateSimpleWindow (dpy, window3.win, WIN_ITV, CALCY (W23_HEIGHT, NW_HEIGHT), NW_WIDTH, NW_HEIGHT, W_BORDER, pixel[cmflag][1], pixel[cmflag][1]);
|
|
172 XSetWMProperties (dpy, window1.win, &win_name, &icon_name, NULL, 0, &hints, &wm_hints, &class_hints);
|
|
173 XSelectInput (dpy, window1.win, ExposureMask | ButtonPressMask | KeyPressMask);
|
|
174 XSelectInput (dpy, window1.name, ExposureMask);
|
|
175 XSelectInput (dpy, window2.win, ExposureMask | ButtonPressMask | KeyPressMask);
|
|
176 XSelectInput (dpy, window2.name, ExposureMask);
|
|
177 XSelectInput (dpy, window3.win, ExposureMask | ButtonPressMask | KeyPressMask);
|
|
178 XSelectInput (dpy, window3.name, ExposureMask);
|
|
179 XSetWindowColormap (dpy, window1.win, cmap[0]);
|
|
180 XSetWindowColormap (dpy, window2.win, cmap[0]);
|
|
181 XSetWindowColormap (dpy, window3.win, cmap[0]);
|
|
182 }
|
|
183
|
|
184
|
|
185 void
|
|
186 mkmwin () /* MaKe Menu WINdow */
|
|
187 {
|
|
188 int cnt;
|
|
189 u_int mroot_width;
|
|
190 u_int mroot_height;
|
|
191 XSizeHints hints;
|
|
192 XClassHint class_hints;
|
|
193 XWMHints wm_hints;
|
|
194 XTextProperty win_name, icon_name;
|
|
195
|
|
196 for (cnt = 0; ftbl[cnt].mname != NULL; cnt++)
|
|
197 ;
|
|
198 mroot_width = MSUB_WIDTH * cnt;
|
|
199 mroot_height = MSUB_HEIGHT * 2;
|
|
200 mroot = XCreateSimpleWindow (dpy, rwin, MROOT_X, MROOT_Y, mroot_width, mroot_height, M_BORDER, pixel[cmflag][2], pixel[cmflag][1]);
|
|
201 XSelectInput (dpy, mroot, ExposureMask);
|
|
202 win_name.value = (u_char *) "X11R5 XIM Menu";
|
|
203 win_name.encoding = XA_STRING;
|
|
204 win_name.format = 8;
|
|
205 win_name.nitems = strlen (win_name.value);
|
|
206 icon_name.value = win_name.value;
|
|
207 icon_name.encoding = XA_STRING;
|
|
208 icon_name.format = 8;
|
|
209 icon_name.nitems = win_name.nitems;
|
|
210 hints.flags = (USPosition | USSize | PMinSize | PMaxSize | PResizeInc | PBaseSize | PWinGravity);
|
|
211 hints.x = MROOT_X;
|
|
212 hints.y = MROOT_Y;
|
|
213 hints.width = hints.min_width = hints.max_width = mroot_width;
|
|
214 hints.height = hints.min_height = hints.min_height = mroot_height;
|
|
215 hints.width_inc = hints.height_inc = 0;
|
|
216 hints.base_width = mroot_width;
|
|
217 hints.base_height = mroot_height;
|
|
218 hints.win_gravity = CenterGravity;
|
|
219 class_hints.res_name = NULL;
|
|
220 class_hints.res_class = NULL;
|
|
221 wm_hints.flags = InputHint;
|
|
222 wm_hints.input = True;
|
|
223
|
|
224 XSetWMProperties (dpy, mroot, &win_name, &icon_name, NULL, 0, &hints, &wm_hints, &class_hints);
|
|
225 strflag = MB;
|
|
226 strmode = XCreateSimpleWindow (dpy, mroot, MSUB_WIDTH * 11, 0, MSUB_WIDTH, MSUB_HEIGHT, 0, pixel[cmflag][2], pixel[cmflag][1]);
|
|
227 XSelectInput (dpy, strmode, ExposureMask | ButtonPressMask);
|
|
228 for (cnt = 0; ftbl[cnt].mname != NULL; cnt++)
|
|
229 {
|
|
230 mwin[cnt] = XCreateSimpleWindow (dpy, mroot, MSUB_WIDTH * cnt, MSUB_Y, MSUB_WIDTH, MSUB_HEIGHT, M_BORDER, pixel[cmflag][2], pixel[cmflag][1]);
|
|
231 XSelectInput (dpy, mwin[cnt], ExposureMask | ButtonPressMask);
|
|
232 }
|
|
233 XSetWindowColormap (dpy, mroot, cmap[0]);
|
|
234 }
|
|
235
|
|
236 void
|
|
237 mapwin () /* MAP WINdow */
|
|
238 {
|
|
239 XMapWindow (dpy, window1.win);
|
|
240 XMapSubwindows (dpy, window1.win);
|
|
241 XMapSubwindows (dpy, window2.win);
|
|
242 XMapSubwindows (dpy, window3.win);
|
|
243 XMapWindow (dpy, mroot);
|
|
244 XMapSubwindows (dpy, mroot);
|
|
245 }
|
|
246
|
|
247 void
|
|
248 dstrwin () /* Draw STRing on WINdow */
|
|
249 {
|
|
250 int cnt;
|
|
251 char *wfont = "-adobe-helvetica-bold-r-normal--*-120-*";
|
|
252
|
|
253 XSetFont (dpy, gc, XLoadFont (dpy, wfont));
|
|
254 XDrawString (dpy, window1.name, gc, MSTR_XY, "Window1", strlen ("Window1"));
|
|
255 XDrawString (dpy, window2.name, gc, MSTR_XY, "Window2", strlen ("Window2"));
|
|
256 XDrawString (dpy, window3.name, gc, MSTR_XY, "Window3", strlen ("Window3"));
|
|
257 XDrawString (dpy, mroot, gc, MSTR_XY, "X-Window System X11R5 Xi18n Input Method Test <<XSetICValues Menu>>", strlen ("X-Window System X11R5 Xi18n Input Method Test <<XSetICValues Menu>>"));
|
|
258 if (strflag == MB)
|
|
259 {
|
|
260 XDrawString (dpy, strmode, gc, MSTR_XY, "Mode: MB", strlen ("Mode: MB"));
|
|
261 }
|
|
262 else if (strflag == WC)
|
|
263 {
|
|
264 XDrawString (dpy, strmode, gc, MSTR_XY, "Mode: WC", strlen ("Mode: WC"));
|
|
265 }
|
|
266 for (cnt = 0; ftbl[cnt].mname != NULL; cnt++)
|
|
267 {
|
|
268 XDrawString (dpy, *ftbl[cnt].mwin, gc, MSTR_XY, ftbl[cnt].mname, strlen (ftbl[cnt].mname));
|
|
269 }
|
|
270 XFlush (dpy);
|
|
271 }
|
|
272
|
|
273 void
|
|
274 cwcolor (win, bg_pixel) /* Change Window COLOR */
|
|
275 Window win;
|
|
276 u_long bg_pixel;
|
|
277 {
|
|
278 XSetWindowBackground (dpy, win, bg_pixel);
|
|
279 XClearWindow (dpy, win);
|
|
280 dstrwin ();
|
|
281 XFlush (dpy);
|
|
282 }
|
|
283
|
|
284
|
|
285 void
|
|
286 freexres () /* FREE X RESources */
|
|
287 {
|
|
288 int cnt = 0;
|
|
289
|
|
290 XFreeGC (dpy, gc);
|
|
291 XDestroyWindow (dpy, window1.win);
|
|
292 XDestroyWindow (dpy, mroot);
|
|
293 XFreeColormap (dpy, dcmap);
|
|
294 for (cnt = 0; cnt < ARRAY_MAX; cnt++)
|
|
295 {
|
|
296 XFreeFontSet (dpy, fontset[cnt]);
|
|
297 XFreeColormap (dpy, cmap[cnt]);
|
|
298 XFreePixmap (dpy, pix[cnt]);
|
|
299 XFreeCursor (dpy, cursor[cnt]);
|
|
300 }
|
|
301 XCloseDisplay (dpy);
|
|
302 }
|