1 /*
2 * $Id: init_w.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 * Copyright 1991, 1992 by Massachusetts Institute of Technology
11 *
12 * Author: OMRON SOFTWARE Co., Ltd. <freewnn@rd.kyoto.omronsoft.co.jp>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with GNU Emacs; see the file COPYING. If not, write to the
26 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 *
28 * Commentary:
29 *
30 * Change log:
31 * '99/04/19 TAOKA Satoshi - �IJ� �һ�<taoka@infonets.hiroshima-u.ac.jp>
32 * index() ��������ȥ����ȡ�
33 *
34 * Last modified date: 19,Apr.1999
35 *
36 * Code:
37 *
38 */
39 /* Version 4.0
40 */
41 #include <stdio.h>
42 #include "commonhd.h"
43 #include "sdefine.h"
44 #include "xjutil.h"
45 #include "sxheader.h"
46 #include "config.h"
47 #include "xext.h"
48 #include "rk_fundecl.h"
49
50 #define XOR(a,b) ((a&(~b)) | ((~a)&b))
51
52 #define MaskOfButton (ButtonPressMask | ButtonReleaseMask | EnterWindowMask | \
53 LeaveWindowMask | ExposureMask)
54
55 Display *dpy = 0;
56 Xjutil *xjutil;
57
58 char xjutil_name[32] = { 0 };
59 char xjutil_name_ok[32] = { 0 };
60 char xjutil_env_name[32] = { 0 };
61 int counter = 0;
62 Cursor cursor1, cursor2, cursor3;
63
64 Window window_xim;
65 Atom atom_xim;
66 XSetWindowAttributes attributes;
67
68 Atom wm_id = 0;
69 Atom wm_id1 = 0;
70
71 Atom actual_type;
72 int actual_format;
73 unsigned long nitems, byte_after, leftover;
74
75 wchar_t dol_wchar_t;
76
77 char
env_state()78 env_state ()
79 {
80 char *p;
81 char ret = '\0';
82 #ifndef SYSVR2
83 /* extern char *index(); */
84 #else
85 extern char *strchr ();
86 #endif
87
88 if ((p = romkan_dispmode ()) == NULL)
89 return (ret);
90 #ifndef SYSVR2
91 if ((p = (char *) index (p, ':')) == NULL)
92 return (ret);
93 #else
94 if ((p = (char *) strchr (p, ':')) == NULL)
95 return (ret);
96 #endif
97 return (*(p + 1));
98 }
99
100 int
set_cur_env(s)101 set_cur_env (s)
102 char s;
103 {
104 register WnnEnv *p;
105 register int i;
106
107 for (p = normal_env; p; p = p->next)
108 {
109 for (i = 0; p->env_name_str[i]; i++)
110 {
111 if (s == p->env_name_str[i])
112 {
113 cur_normal_env = p;
114 return (0);
115 }
116 }
117 }
118 return (0);
119 }
120
121 void
get_new_env(rev)122 get_new_env (rev)
123 int rev;
124 {
125 WnnEnv *new, *p, *prev = NULL;
126
127 new = (WnnEnv *) Malloc (sizeof (WnnEnv));
128 new->host_name = NULL;
129 new->env = NULL;
130 new->sticky = 0;
131 new->envrc_name = NULL;
132 new->env_name_str[0] = '\0';
133 new->next = NULL;
134 if (rev)
135 {
136 cur_reverse_env = new;
137 if (reverse_env == NULL)
138 {
139 reverse_env = new;
140 return;
141 }
142 p = reverse_env;
143 }
144 else
145 {
146 cur_normal_env = new;
147 if (normal_env == NULL)
148 {
149 normal_env = new;
150 return;
151 }
152 p = normal_env;
153 }
154 for (; p; prev = p, p = p->next);
155 if (prev)
156 prev->next = new;
157 }
158
159 void
send_end_work()160 send_end_work ()
161 {
162 XEvent event;
163
164 event.type = ClientMessage;
165 event.xclient.format = 32;
166 event.xclient.window = xjutil->root_pointer[xjutil->default_screen]->jutil->w;
167 event.xclient.data.l[0] = DIC_END;
168 event.xclient.data.l[1] = counter;
169 XSendEvent (dpy, window_xim, False, NoEventMask, &event);
170 XFlush (dpy);
171 }
172
173 static void
send_ok()174 send_ok ()
175 {
176 XEvent event;
177 Atom select_id;
178 Window window = xjutil->root_pointer[xjutil->default_screen]->jutil->w;
179
180 if (!(select_id = XInternAtom (dpy, xjutil_name_ok, True)))
181 {
182 select_id = XInternAtom (dpy, xjutil_name_ok, False);
183 }
184 XSetSelectionOwner (dpy, select_id, window, 0L);
185 event.type = ClientMessage;
186 event.xclient.format = 32;
187 event.xclient.window = window;
188 event.xclient.data.l[0] = DIC_START;
189 event.xclient.data.l[1] = window;
190 event.xclient.data.l[2] = counter;
191 XSendEvent (dpy, window_xim, False, NoEventMask, &event);
192 XFlush (dpy);
193 }
194
195 void
return_error()196 return_error ()
197 {
198 XEvent event;
199 Atom select_id;
200 Window window = xjutil->root_pointer[xjutil->default_screen]->jutil->w;
201
202 if (dpy == NULL)
203 return;
204 if (!(select_id = XInternAtom (dpy, xjutil_name_ok, True)))
205 {
206 select_id = XInternAtom (dpy, xjutil_name_ok, False);
207 }
208 XSetSelectionOwner (dpy, select_id, window, 0L);
209 event.type = ClientMessage;
210 event.xclient.format = 32;
211 event.xclient.window = window;
212 event.xclient.data.l[0] = DIC_START_ER;
213 event.xclient.data.l[1] = window;
214 event.xclient.data.l[2] = counter;
215 XSendEvent (dpy, window_xim, False, NoEventMask, &event);
216 XFlush (dpy);
217 }
218
219 void
read_wm_id()220 read_wm_id ()
221 {
222 register XIMRootRec *root;
223 register int i;
224
225 if ((wm_id = XInternAtom (dpy, "WM_PROTOCOLS", True)))
226 {
227 wm_id1 = XInternAtom (dpy, "WM_DELETE_WINDOW", True);
228 for (i = 0; i < xjutil->screen_count; i++)
229 {
230 root = xjutil->root_pointer[i];
231 XChangeProperty (dpy, root->jutil->w, wm_id, XA_INTEGER, 32, PropModeReplace, (unsigned char *) &wm_id1, sizeof (Atom));
232 XChangeProperty (dpy, root->ichi->w, wm_id, XA_INTEGER, 32, PropModeReplace, (unsigned char *) &wm_id1, sizeof (Atom));
233 XChangeProperty (dpy, root->yes_no->w, wm_id, XA_INTEGER, 32, PropModeReplace, (unsigned char *) &wm_id1, sizeof (Atom));
234 }
235 }
236 else
237 {
238 wm_id = wm_id1 = 0;
239 }
240 }
241
242 static char *
get_property()243 get_property ()
244 {
245 Xjutil_startRec *xjutil_start;
246 unsigned char *data, *s_data;
247 char *p, *s_p;
248 char nlspath[64];
249 int all_size = 0, uumkey_name_size, cvtkey_name_size, rkfile_name_size, cvtfun_name_size, cvtmeta_name_size, user_name_size, lang_size, lc_name_size, fn_size = 0;
250 int i;
251 unsigned char tmp_buf[256];
252 FunctionTable *db;
253 XIMRootRec *root;
254
255 if ((atom_xim = XInternAtom (dpy, xjutil_name, True)) == (Atom) NULL)
256 {
257 return (NULL);
258 }
259 window_xim = XGetSelectionOwner (dpy, atom_xim);
260 XSelectInput (dpy, window_xim, StructureNotifyMask);
261 xjutil_start = (Xjutil_startRec *) Malloc (sizeof (Xjutil_startRec));
262 XGetWindowProperty (dpy, RootWindow (dpy, xjutil->default_screen), atom_xim, 0L, 1000000L, False, XA_STRING, &actual_type, &actual_format, &nitems, &leftover, &data);
263
264 bcopy (data, xjutil_start, sizeof (Xjutil_startRec));
265 if (xjutil_start->fn_len > 0)
266 {
267 all_size = fn_size = xjutil_start->fn_len + 1;
268 }
269 all_size += uumkey_name_size = (strlen (xjutil_start->uumkey_name) + 1);
270 all_size += rkfile_name_size = (strlen (xjutil_start->rkfile_name) + 1);
271 all_size += cvtkey_name_size = (strlen (xjutil_start->cvtkey_name) + 1);
272 all_size += cvtfun_name_size = (strlen (xjutil_start->cvtfun_name) + 1);
273 all_size += cvtmeta_name_size = (strlen (xjutil_start->cvtmeta_name) + 1);
274 all_size += user_name_size = (strlen (xjutil_start->user_name) + 1);
275 all_size += lang_size = (strlen (xjutil_start->lang) + 1);
276 all_size += lc_name_size = (strlen (xjutil_start->lc_name) + 1);
277 if ((p = (char *) Malloc (all_size)) == NULL)
278 {
279 malloc_error ("allocation of initial area");
280 Free (xjutil_start);
281 XFree (data);
282 return (NULL);
283 }
284 s_data = data;
285 data += sizeof (Xjutil_startRec);
286 for (i = 0; i < xjutil->screen_count; i++)
287 {
288 root = xjutil->root_pointer[i];
289 bcopy (data, (char *) &root->fg, sizeof (unsigned long));
290 data += sizeof (unsigned long);
291 bcopy (data, (char *) &root->bg, sizeof (unsigned long));
292 data += sizeof (unsigned long);
293 bcopy (data, (char *) &root->bw, sizeof (unsigned int));
294 data += sizeof (unsigned int);
295 }
296 for (i = 0; (int) i < (int) xjutil_start->max_env; i++)
297 {
298 get_new_env (0);
299 tmp_buf[0] = '\0';
300 strcpy ((char *) tmp_buf, (char *) data);
301 cur_normal_env->host_name = alloc_and_copy (tmp_buf);
302 data += 256;
303 tmp_buf[0] = '\0';
304 strcpy ((char *) tmp_buf, (char *) data);
305 cur_normal_env->envrc_name = alloc_and_copy (tmp_buf);
306 data += 256;
307 tmp_buf[0] = '\0';
308 strcpy ((char *) tmp_buf, (char *) data);
309 strcpy ((char *) cur_normal_env->env_name_str, (char *) tmp_buf);
310 data += 32;
311 }
312 for (i = 0; (int) i < (int) xjutil_start->max_reverse_env; i++)
313 {
314 get_new_env (1);
315 tmp_buf[0] = '\0';
316 strcpy ((char *) tmp_buf, (char *) data);
317 cur_reverse_env->host_name = alloc_and_copy (tmp_buf);
318 data += 256;
319 tmp_buf[0] = '\0';
320 strcpy ((char *) tmp_buf, (char *) data);
321 cur_reverse_env->envrc_name = alloc_and_copy (tmp_buf);
322 data += 256;
323 tmp_buf[0] = '\0';
324 strcpy ((char *) tmp_buf, (char *) data);
325 strcpy ((char *) cur_reverse_env->env_name_str, (char *) tmp_buf);
326 data += 32;
327 }
328 strncpy (p, (char *) data, fn_size);
329 p[fn_size] = '\0';
330 XFree (s_data);
331 s_p = p;
332
333 uumkey_name = p += fn_size;
334 strcpy (p, xjutil_start->uumkey_name);
335 rkfile_name = p += uumkey_name_size;
336 strcpy (p, xjutil_start->rkfile_name);
337 cvt_key_file = p += rkfile_name_size;
338 strcpy (p, xjutil_start->cvtkey_name);
339 cvt_fun_file = p += cvtkey_name_size;
340 strcpy (p, xjutil_start->cvtfun_name);
341 cvt_meta_file = p += cvtfun_name_size;
342 strcpy (p, xjutil_start->cvtmeta_name);
343 username = p += cvtmeta_name_size;
344 strcpy (p, xjutil_start->user_name);
345 xjutil->lang = p += user_name_size;
346 strcpy (p, xjutil_start->lang);
347 xjutil->lc_name = p += lang_size;
348 strcpy (p, xjutil_start->lc_name);
349
350 for (db = function_db; db->name != NULL; db++)
351 {
352 if (!strcmp (db->name, xjutil_start->f_name))
353 {
354 f_table = db;
355 break;
356 }
357 }
358 strcpy (jishopath, xjutil_start->jishopath);
359 strcpy (hindopath, xjutil_start->hindopath);
360 strcpy (fuzokugopath, xjutil_start->fuzokugopath);
361 rubout_code = xjutil_start->rubout_code;
362 xjutil->cswidth_id = xjutil_start->cswidth_id;
363 xjutil->save_under = (char) xjutil_start->save_under;
364
365 strcpy (nlspath, LIBDIR);
366 strcat (nlspath, "/%L/%N");
367 cd = msg_open ("xjutil.msg", nlspath, xjutil->lang);
368 Free (xjutil_start);
369 return (s_p);
370 }
371
372 static void
clear_text(t)373 clear_text (t)
374 JutilTextRec *t;
375 {
376 t->vst = 0;
377 t->note[0] = t->note[1] = 0;
378 t->currentcol = 0;
379 t->max_pos = 0;
380 t->cursor_flag = 0;
381 t->mark_flag = 0;
382 t->u_line_flag = t->r_flag = t->b_flag = 0;
383 }
384
385 int
create_text(text,root)386 create_text (text, root)
387 register JutilTextRec *text;
388 XIMRootRec *root;
389 {
390 int border_width;
391 register int i;
392
393 if ((text->buf = (wchar *) Malloc (sizeof (wchar) * (maxchg * 2 + 1))) == NULL)
394 {
395 malloc_error ("allocation of client's area");
396 return (-1);
397 }
398 if ((text->att = (unsigned char *) Malloc (sizeof (unsigned char) * (maxchg * 2 + 1))) == NULL)
399 {
400 malloc_error ("allocation of client's area");
401 return (-1);
402 }
403 for (i = (maxchg * 2); i >= 0; i--)
404 {
405 *(text->buf + i) = 0;
406 *(text->att + i) = '\0';
407 }
408 clear_text (text);
409
410 border_width = 0;
411 text->maxcolumns = maxchg * 2;
412
413 text->wn[0] = XCreateSimpleWindow (dpy, text->wp, 0, 0, FontWidth, FontHeight, border_width, root->fg, root->bg);
414
415 text->wn[1] = XCreateSimpleWindow (dpy, text->wp, text->width - FontWidth, 0, FontWidth, FontHeight, border_width, root->fg, root->bg);
416
417 text->wn[2] = XCreateSimpleWindow (dpy, text->wp, text->width - FontWidth, 0, FontWidth, FontHeight, border_width, root->fg, root->bg);
418
419 text->w = XCreateSimpleWindow (dpy, text->wp, 0, 0, FontWidth * (text->maxcolumns + 1), FontHeight, border_width, root->fg, root->bg);
420
421 text->vst = 0;
422 text->note[0] = 0;
423 text->note[1] = 0;
424
425 XSelectInput (dpy, text->w, ExposureMask);
426 XSelectInput (dpy, text->wn[0], ExposureMask);
427 XSelectInput (dpy, text->wn[1], ExposureMask);
428 return (0);
429 }
430
431 int
create_jutil(root)432 create_jutil (root)
433 XIMRootRec *root;
434 {
435 JutilRec *jutil = root->jutil;
436 unsigned int width, height;
437 int i;
438 extern int jutil_mode_set ();
439
440 width = FontWidth;
441 height = FontHeight;
442
443 jutil->w = XCreateSimpleWindow (dpy, root->root_window, 0, 0, FontWidth, FontHeight, root->bw, root->fg, root->bg);
444 XSetTransientForHint (dpy, jutil->w, root->root_window);
445 if (xjutil->save_under)
446 {
447 attributes.save_under = True;
448 XChangeWindowAttributes (dpy, jutil->w, CWSaveUnder, &attributes);
449 }
450 XSelectInput (dpy, jutil->w, KeyPressMask | StructureNotifyMask);
451 XDefineCursor (dpy, jutil->w, cursor3);
452
453 jutil->title = create_box (jutil->w, 0, 0, FontWidth, FontHeight, 1, root->fg, root->bg, root->fg, NULL, (char) 0);
454 jutil->rk_mode = create_box (jutil->w, 0, 0, FontWidth, FontHeight, 1, root->fg, root->bg, root->fg, NULL, (char) 0);
455 map_box (jutil->title);
456 map_box (jutil->rk_mode);
457
458 jutil->max_button = MAX_JU_BUTTON;
459 for (i = 0; i < MAX_JU_BUTTON; i++)
460 {
461 jutil->button[i] = create_box (jutil->w, 0, 0, FontWidth, FontHeight, 2, root->fg, root->bg, root->fg, cursor2, (char) 1);
462 map_box (jutil->button[i]);
463 }
464 jutil->button[CANCEL_W]->string = (unsigned char *) msg_get (cd, 2, default_message[2], xjutil->lang);
465 jutil->button[CANCEL_W]->sel_ret = -2;
466 jutil->button[EXEC_W]->sel_ret = 0;
467 jutil->button[CANCEL_W]->do_ret = jutil->button[EXEC_W]->do_ret = True;
468
469 for (i = 0; i < JCLIENTS; i++)
470 {
471 if ((jutil->mes_text[i] = (JutilTextRec *) Malloc (sizeof (JutilTextRec))) == NULL)
472 {
473 malloc_error ("allocation of client's area");
474 return (-1);
475 }
476 jutil->mes_button[i] = create_box (jutil->w, 0, 0, FontWidth, FontHeight, 2, root->fg, root->bg, root->bg, cursor2, (char) 0);
477 jutil->mes_mode_return[i] = i;
478 jutil->mes_button[i]->sel_ret = 1;
479 jutil->mes_button[i]->do_ret = True;
480 jutil->mes_button[i]->cb = jutil_mode_set;
481 jutil->mes_button[i]->cb_data = (int *) i;
482
483 jutil->mes_text[i]->x = 0;
484 jutil->mes_text[i]->y = 0;
485 jutil->mes_text[i]->width = FontWidth * TEXT_WIDTH;
486 jutil->mes_text[i]->height = FontHeight;
487 jutil->mes_text[i]->max_columns = TEXT_WIDTH;
488 jutil->mes_text[i]->bp = 0;
489 jutil->mes_text[i]->wp = XCreateSimpleWindow (dpy, jutil->w, 0, 0, jutil->mes_text[i]->width, FontHeight, 0, root->fg, root->bg);
490 if (create_text (jutil->mes_text[i], root))
491 {
492 return (-1);
493 }
494 XFlush (dpy);
495 }
496 set_wm_properties (jutil->w, 0, 0, width, height, CenterGravity, "jutil", "Jutil", True, 0, InputHint, 0, 0);
497 return (0);
498 }
499
500 int
create_ichi(root)501 create_ichi (root)
502 XIMRootRec *root;
503 {
504 Ichiran *ichi = root->ichi;
505 Keytable *kt;
506 unsigned int width, height;
507 int i;
508 extern int next_ichi (), back_ichi ();
509
510 if ((ichi->keytable = (Keytable *) Malloc (sizeof (Keytable))) == NULL)
511 {
512 malloc_error ("allocation of the initial area");
513 return (-1);
514 }
515 kt = ichi->keytable;
516
517 width = 1;
518 height = 1;
519
520 ichi->save_buf = NULL;
521 ichi->max_columns = MAX_ICHI_COLUMNS;
522 if (alloc_for_save_buf (ichi, MAX_ICHI_LINES) < 0)
523 return (-1);
524 ichi->max_button = MAX_BUTTON;
525 ichi->select_mode = '\0';
526
527 ichi->w = XCreateSimpleWindow (dpy, root->root_window, 0, 0, width, height, root->bw, root->fg, root->bg);
528 ichi->w0 = XCreateSimpleWindow (dpy, ichi->w, 0, FontWidth * 4, width, height, 1, root->fg, root->bg);
529 ichi->w1 = XCreateSimpleWindow (dpy, ichi->w0, 0, FontWidth * 4, width, height, 0, root->fg, root->bg);
530 ichi->nyuu_w = XCreateSimpleWindow (dpy, ichi->w, 0, 0, FontWidth * 5, FontHeight, 1, root->fg, root->bg);
531
532 XSetTransientForHint (dpy, ichi->w, root->root_window);
533 if (xjutil->save_under)
534 {
535 attributes.save_under = True;
536 XChangeWindowAttributes (dpy, ichi->w, CWSaveUnder, &attributes);
537 }
538 XSelectInput (dpy, ichi->w, KeyPressMask | StructureNotifyMask);
539 XSelectInput (dpy, ichi->w1, ExposureMask);
540 XSelectInput (dpy, ichi->nyuu_w, ExposureMask);
541
542 ichi->comment = create_box (ichi->w, 0, FontHeight * 4, FontWidth, FontHeight, 1, root->fg, root->bg, root->fg, NULL, (char) 0);
543 ichi->title = create_box (ichi->w, 0, 0, FontWidth, FontHeight, 1, root->fg, root->bg, root->fg, NULL, (char) 0);
544 ichi->subtitle = create_box (ichi->w, 0, 0, FontWidth, FontHeight, 0, root->fg, root->bg, root->fg, NULL, (char) 0);
545 for (i = 0; i < MAX_BUTTON; i++)
546 {
547 ichi->button[i] = create_box (ichi->w, 0, 0, FontWidth, FontHeight, 2, root->fg, root->bg, root->fg, cursor2, (char) 1);
548
549 }
550 ichi->button[CANCEL_W]->string = (unsigned char *) msg_get (cd, 2, default_message[2], xjutil->lang);
551 ichi->button[NEXT_W]->string = (unsigned char *) msg_get (cd, 3, default_message[3], xjutil->lang);
552 ichi->button[BACK_W]->string = (unsigned char *) msg_get (cd, 4, default_message[4], xjutil->lang);
553
554 ichi->button[CANCEL_W]->do_ret = ichi->button[EXEC_W]->do_ret = True;
555 ichi->button[CANCEL_W]->sel_ret = -2;
556 ichi->button[EXEC_W]->sel_ret = 1;
557 ichi->button[MOUSE_W]->cb = xw_mouse_select;
558 ichi->button[NEXT_W]->cb = next_ichi;
559 ichi->button[BACK_W]->cb = back_ichi;
560
561 map_box (ichi->button[CANCEL_W]);
562 map_box (ichi->title);
563
564 kt->w = XCreateSimpleWindow (dpy, root->root_window, 0, 0, FontWidth, FontHeight, root->bw, root->fg, root->bg);
565 XSetTransientForHint (dpy, kt->w, root->root_window);
566 if (xjutil->save_under)
567 {
568 attributes.save_under = True;
569 XChangeWindowAttributes (dpy, kt->w, CWSaveUnder, &attributes);
570 }
571 XSelectInput (dpy, kt->w, KeyPressMask | StructureNotifyMask);
572 XDefineCursor (dpy, kt->w, cursor3);
573
574 kt->max_button = MAX_KEY_BUTTON;
575 for (i = 0; i < MAX_KEY_BUTTON; i++)
576 {
577 kt->button[i] = create_box (kt->w, 0, 0, FontWidth, FontHeight, 2, root->fg, root->bg, root->fg, cursor2, (char) 1);
578 kt->button[i]->sel_ret = i;
579 kt->button[i]->do_ret = True;
580 }
581
582 XDefineCursor (dpy, ichi->w, cursor3);
583 XMapWindow (dpy, ichi->w1);
584
585 set_wm_properties (ichi->w, 0, 0, width, height, CenterGravity, "ichiran", "Ichiran", True, 0, InputHint, 0, 0);
586 return (0);
587 }
588
589 int
create_yes_no(root)590 create_yes_no (root)
591 XIMRootRec *root;
592 {
593 YesOrNo *yes_no = root->yes_no;
594 unsigned int width, height;
595
596 width = 1;
597 height = 1;
598
599 yes_no->w = XCreateSimpleWindow (dpy, root->root_window, 0, 0, width, height, root->bw, root->fg, root->bg);
600 yes_no->title = create_box (yes_no->w, 0, 0, width, height, 0, root->fg, root->bg, root->fg, NULL, (char) 0);
601 yes_no->button[0] = create_box (yes_no->w, 0, 0, width, height, 2, root->fg, root->bg, root->fg, cursor2, (char) 1);
602 yes_no->button[1] = create_box (yes_no->w, 0, 0, width, height, 2, root->fg, root->bg, root->fg, cursor2, (char) 1);
603 yes_no->button[0]->sel_ret = 1;
604 yes_no->button[1]->sel_ret = 0;
605 yes_no->button[0]->do_ret = yes_no->button[1]->do_ret = True;
606
607 XSetTransientForHint (dpy, yes_no->w, root->root_window);
608 if (xjutil->save_under)
609 {
610 attributes.save_under = True;
611 XChangeWindowAttributes (dpy, yes_no->w, CWSaveUnder, &attributes);
612 }
613 XDefineCursor (dpy, yes_no->w, cursor3);
614 XSelectInput (dpy, yes_no->w, (StructureNotifyMask | KeyPressMask));
615 map_box (yes_no->title);
616 XFlush (dpy);
617 set_wm_properties (yes_no->w, 0, 0, width, height, CenterGravity, "yesNo", "YesNo", True, 0, InputHint, 0, 0);
618 return (0);
619 }
620
621 void
xw_end()622 xw_end ()
623 {
624 if (dpy)
625 {
626 XCloseDisplay (dpy);
627 }
628 }
629
630 static int
xerror(d,ev)631 xerror (d, ev)
632 Display *d;
633 register XErrorEvent *ev;
634 {
635 return (0);
636 }
637
638 static int
xioerror(d)639 xioerror (d)
640 Display *d;
641 {
642 perror ("xjutil");
643 disconnect_server ();
644 XCloseDisplay (dpy);
645 exit (2);
646 return (0);
647 }
648
649
650 XjutilFSRec *
add_fontset_list(fs,act)651 add_fontset_list (fs, act)
652 XFontSet fs;
653 int act;
654 {
655 register XjutilFSRec *rec;
656 XCharStruct *cs;
657 extern XCharStruct *get_base_char ();
658
659 if ((rec = (XjutilFSRec *) Malloc (sizeof (XjutilFSRec))) == NULL)
660 {
661 return (NULL);
662 }
663 if ((cs = get_base_char (fs)) == NULL)
664 {
665 return (NULL);
666 }
667 rec->fs = fs;
668 rec->act = act;
669 rec->b_char = cs;
670 rec->next = font_set_list;
671 font_set_list = rec;
672 return (rec);
673 }
674
675 XjutilFSRec *
get_fontset_list(act)676 get_fontset_list (act)
677 int act;
678 {
679 register XjutilFSRec *p;
680
681 for (p = font_set_list; p; p = p->next)
682 {
683 if (p->act == act)
684 return (p);
685 }
686 return (NULL);
687 }
688
689 static int
create_one_root(root,screen)690 create_one_root (root, screen)
691 register XIMRootRec *root;
692 int screen;
693 {
694 register Ichiran *ichi;
695 register YesOrNo *yes_no;
696 register JutilRec *jutil;
697 char *p;
698 int size_of_jutil;
699 int size_of_ichiran;
700 int size_of_yes_no;
701 int all_size;
702 XGCValues xgcv;
703
704 size_of_jutil = sizeof (JutilRec);
705 size_of_ichiran = sizeof (Ichiran);
706 size_of_yes_no = sizeof (YesOrNo);
707 all_size = size_of_jutil + size_of_ichiran + size_of_yes_no;
708 if ((p = (char *) Malloc (all_size)) == NULL)
709 {
710 malloc_error ("allocation of initial area");
711 return (-1);
712 }
713 jutil = (JutilRec *) p;
714 p += size_of_jutil;
715 ichi = (Ichiran *) p;
716 p += size_of_ichiran;
717 yes_no = (YesOrNo *) p;
718
719 root->root_window = RootWindow (dpy, screen);
720 root->screen = screen;
721 root->jutil = jutil;
722 root->ichi = ichi;
723 root->yes_no = yes_no;
724
725 xgcv.foreground = root->fg;
726 xgcv.background = root->bg;
727 root->gc = XCreateGC (dpy, root->root_window, (GCForeground | GCBackground), &xgcv);
728 xgcv.foreground = root->bg;
729 xgcv.background = root->fg;
730 root->reversegc = XCreateGC (dpy, root->root_window, (GCForeground | GCBackground), &xgcv);
731 xgcv.foreground = root->fg;
732 xgcv.function = GXinvert;
733 xgcv.plane_mask = XOR (root->fg, root->bg);
734 root->invertgc = XCreateGC (dpy, root->root_window, (GCForeground | GCFunction | GCPlaneMask), &xgcv);
735
736 if (create_ichi (root) == -1)
737 return (-1);
738 if (create_jutil (root) == -1)
739 return (-1);
740 if (create_yes_no (root) == -1)
741 return (-1);
742 return (0);
743 }
744
745 int
create_xjutil()746 create_xjutil ()
747 {
748 extern int xerror (), xioerror ();
749 extern char *getenv ();
750 register int i;
751 int screen_count;
752 int ret;
753 char *p;
754 int size_of_xjutil;
755 int size_of_root_pointer;
756 int size_of_root;
757 int all_size;
758 #ifdef X11R5
759 XLocale xlc;
760 #else
761 XLCd xlc;
762 #endif /* X11R5 */
763 char **miss, *def;
764 int miss_cnt;
765 XFontSet fs;
766 extern XjutilFSRec *add_fontset_list ();
767
768 #ifdef X_WCHAR
769 dol_wchar_t = 0x20202024;
770 #else /* X_WCHAR */
771 mbtowc (&dol_wchar_t, "$", 1);
772 #endif /* X_WCHAR */
773 if ((dpy = XOpenDisplay (display_name)) == NULL)
774 {
775 print_out1 ("I could not open Display : %s.", display_name);
776 return (-1);
777 }
778 screen_count = ScreenCount (dpy);
779 XSetErrorHandler (xerror);
780 XSetIOErrorHandler (xioerror);
781
782 if ((atom_xim = XInternAtom (dpy, xjutil_name, True)) == (Atom) NULL)
783 {
784 print_out ("I could not find InputManager.");
785 return (-1);
786 }
787 if ((window_xim = XGetSelectionOwner (dpy, atom_xim)) == 0)
788 {
789 print_out ("I could not find InputManager.");
790 return (-1);
791 }
792 XSelectInput (dpy, window_xim, StructureNotifyMask);
793 strcpy (xjutil_name_ok, xjutil_name);
794 strcat (xjutil_name_ok, "_OK");
795 if (ret = XInternAtom (dpy, xjutil_name_ok, True))
796 {
797 if (XGetSelectionOwner (dpy, ret))
798 {
799 print_out ("I am already running.");
800 return (-1);
801 }
802 }
803 size_of_xjutil = sizeof (Xjutil);
804 size_of_root_pointer = sizeof (XIMRootRec *) * screen_count;
805 size_of_root = sizeof (XIMRootRec);
806 all_size = size_of_xjutil + size_of_root_pointer + size_of_root * screen_count;
807 if ((p = (char *) Malloc (all_size)) == NULL)
808 {
809 malloc_error ("allocation of initial area");
810 return (-1);
811 }
812 xjutil = (Xjutil *) p;
813 p += size_of_xjutil;
814 xjutil->root_pointer = (XIMRootRec **) p;
815 p += size_of_root_pointer;
816 for (i = 0; i < screen_count; i++)
817 {
818 xjutil->root_pointer[i] = (XIMRootRec *) p;
819 p += size_of_root;
820 }
821 xjutil->screen_count = screen_count;
822 xjutil->default_screen = DefaultScreen (dpy);
823 xjutil->sel_ret = -1;
824 xjutil->sel_button = 0;
825
826 cursor1 = XCreateFontCursor (dpy, 52);
827 cursor2 = XCreateFontCursor (dpy, 60);
828 cursor3 = XCreateFontCursor (dpy, 24);
829
830 p = get_property ();
831
832 strcpy (xjutil_env_name, XJUTIL_ENV_PRO);
833 strcat (xjutil_env_name, xjutil->lang);
834
835 set_cswidth (xjutil->cswidth_id);
836 setlocale (LC_ALL, xjutil->lc_name);
837 #ifdef X11R5
838 xlc = _XFallBackConvert ();
839 xjutil->xlc = _XlcDupLocale (xlc);
840 #else
841 xlc = _XlcCurrentLC ();
842 xjutil->xlc = xlc;
843 #endif /* X11R5 */
844
845 if (((fs = XCreateFontSet (dpy, p, &miss, &miss_cnt, &def)) == NULL))
846 {
847 return (-1);
848 }
849 cur_fs = add_fontset_list (fs, 0);
850
851 for (i = 0; i < screen_count; i++)
852 {
853 if (create_one_root (xjutil->root_pointer[i], i) == -1)
854 return (-1);
855 }
856 send_ok ();
857 read_wm_id ();
858 XFlush (dpy);
859 if (f_table == NULL)
860 return (-1);
861 return (0);
862 }
863