1 /*
2 * $Id: init_w.c,v 1.2 2001/06/14 18:16:16 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 *
32 * Last modified date: 8,Feb.1999
33 *
34 * Code:
35 *
36 */
37 /* Version 4.0
38 */
39 #include <stdio.h>
40 #include <sys/types.h>
41 #include <netinet/in.h>
42 #include "sdefine.h"
43 #include <X11/IntrinsicP.h>
44 #include <X11/StringDefs.h>
45 #include <X11/Shell.h>
46 #include <X11/Xmu/SysUtil.h>
47 #include "xim.h"
48 #ifdef X11R5
49 #include "Xlocaleint.h"
50 #endif /* X11R5 */
51 #include "proto.h"
52 #include "sheader.h"
53 #include "ext.h"
54
55 Display *dpy = 0;
56 Atom xim_id;
57 XPoint button;
58
59 Atom wm_id = 0; /* Window Manager */
60 Atom wm_id1 = 0; /* Window Manager */
61
62 Cursor cursor1, cursor2, cursor3;
63
64 XSetWindowAttributes attributes;
65 XGCValues xgcv;
66
67 #define HOSTNAME_SIZE 128
68 char hostname[HOSTNAME_SIZE];
69
70 wchar_t dol_wchar_t;
71 wchar_t cursor_wchar_t;
72
73 struct _sub_resource
74 {
75 Pixel fore_color_res;
76 Pixel back_color_res;
77 Pixel border_color_res;
78 char *geometry_res;
79 char *icon_geometry_res;
80 int border_width_res;
81 Boolean iconic_start_res;
82 char *font_set_res;
83 Boolean root_visible_res;
84 }
85 sub_resource;
86
87 struct _resource
88 {
89 char *servername_res;
90 char *username_res;
91 char *ximrc_file_res;
92 char *cvt_key_file_res;
93 char *cvt_fun_file_res;
94 char *cvt_meta_file_res;
95 char *display_name_res;
96 #ifdef USING_XJUTIL
97 char *xjutil_res;
98 #endif /* USING_XJUTIL */
99 char *lang_name_res;
100 Boolean exit_menu_res;
101 Boolean iconic_start_res;
102 char *geometry_res;
103 int border_width_res;
104 Boolean save_under_res;
105 }
106 resource;
107
108 #define DEFAULT_WIDTH 1280
109 #define DEFAULT_BORDERWIDTH 4
110 #define DEFAULT_X 0
111 #define DEFAULT_Y 0
112
113 static int defaultBorderWidth = DEFAULT_BORDERWIDTH;
114 static Boolean defaultTRUE = TRUE;
115 static Boolean defaultFALSE = FALSE;
116
117 #define offset(field) XtOffset(struct _sub_resource *, field)
118 static XtResource sub_resources[] = {
119 {XtNforeground, XtCForeground, XtRPixel, sizeof (Pixel),
120 offset (fore_color_res), XtRString, "XtDefaultForeground"}
121 ,
122 {XtNbackground, XtCBackground, XtRPixel, sizeof (Pixel),
123 offset (back_color_res), XtRString, "XtDefaultBackground"}
124 ,
125 {XtNborderColor, XtCBorderColor, XtRPixel, sizeof (Pixel),
126 offset (border_color_res), XtRString, "XtDefaultForeground"}
127 ,
128 {XtNiconic, XtCIconic, XtRBoolean, sizeof (Boolean),
129 offset (iconic_start_res), XtRBoolean, (caddr_t) & defaultFALSE}
130 ,
131 {XtNgeometry, XtCGeometry, XtRString, sizeof (char *),
132 offset (geometry_res), XtRString, (caddr_t) NULL},
133 {"iconGeometry", "IconGeometry", XtRString, sizeof (char *),
134 offset (icon_geometry_res), XtRString, (caddr_t) NULL},
135 {XtNborderWidth, XtCBorderWidth, XtRInt, sizeof (int),
136 offset (border_width_res), XtRInt, (caddr_t) & defaultBorderWidth},
137 {"fontSet", "FontSet", XtRString, sizeof (char *),
138 offset (font_set_res), XtRString, NULL},
139 {"rootVisible", "RootVisible", XtRBoolean, sizeof (Boolean),
140 offset (root_visible_res), XtRBoolean, (caddr_t) & defaultFALSE}
141 ,
142 };
143 #undef offset
144
145 #define offset(field) XtOffset(struct _resource *, field)
146 static XtResource app_resources[] = {
147 {"serverName", "ServerName", XtRString, sizeof (char *),
148 offset (servername_res), XtRString, NULL},
149 {"userName", "UserName", XtRString, sizeof (char *),
150 offset (username_res), XtRString, NULL},
151 {"ximrcName", "XimrcName", XtRString, sizeof (char *),
152 offset (ximrc_file_res), XtRString, NULL},
153 {"cvtximName", "CvtximName", XtRString, sizeof (char *),
154 offset (cvt_key_file_res), XtRString, NULL},
155 {"cvtfunName", "CvtfunName", XtRString, sizeof (char *),
156 offset (cvt_fun_file_res), XtRString, NULL},
157 {"cvtmetaName", "CvtmetaName", XtRString, sizeof (char *),
158 offset (cvt_meta_file_res), XtRString, NULL},
159 {"display", "Display", XtRString, sizeof (char *),
160 offset (display_name_res), XtRString, NULL},
161 #ifdef USING_XJUTIL
162 {"xjutilName", "XjutilName", XtRString, sizeof (char *),
163 offset (xjutil_res), XtRString, NULL},
164 #endif /* USING_XJUTIL */
165 {"langName", "LangName", XtRString, sizeof (char *),
166 offset (lang_name_res), XtRString, (caddr_t) NULL},
167 {"exitMenu", "ExitMenu", XtRBoolean, sizeof (Boolean),
168 offset (exit_menu_res), XtRBoolean, (caddr_t) & defaultTRUE}
169 ,
170 {XtNiconic, XtCIconic, XtRBoolean, sizeof (Boolean),
171 offset (iconic_start_res), XtRBoolean, (caddr_t) & defaultFALSE}
172 ,
173 {XtNgeometry, XtCGeometry, XtRString, sizeof (char *),
174 offset (geometry_res), XtRString, (caddr_t) NULL},
175 {XtNborderWidth, XtCBorderWidth, XtRInt, sizeof (int),
176 offset (border_width_res), XtRInt, (caddr_t) NULL},
177 {"saveUnder", "SaveUnder", XtRBoolean, sizeof (Boolean),
178 offset (save_under_res), XtRBoolean, (caddr_t) & defaultFALSE}
179 ,
180 };
181 #undef offset
182
183 /*
184 static char *fallback_resources[] = {
185 };
186 */
187
188 static XrmOptionDescRec optionDescList[] = {
189 {"-D", "*serverName", XrmoptionSepArg, (caddr_t) NULL},
190 {"-n", "*userName", XrmoptionSepArg, (caddr_t) NULL},
191 {"-X", "*cvtximName", XrmoptionSepArg, (caddr_t) NULL},
192 {"-F", "*cvtfunName", XrmoptionSepArg, (caddr_t) NULL},
193 {"-M", "*cvtmetaName", XrmoptionSepArg, (caddr_t) NULL},
194 #ifdef USING_XJUTIL
195 {"-ju", "*xjutilName", XrmoptionSepArg, (caddr_t) NULL},
196 #endif /* USING_XJUTIL */
197 {"-lc", "*langName", XrmoptionSepArg, (caddr_t) NULL},
198 {"-fs", "*fontSet", XrmoptionSepArg, (caddr_t) NULL},
199 {"#", "*iconGeometry", XrmoptionStickyArg, (caddr_t) NULL},
200 {"-RV", "*rootVisible", XrmoptionNoArg, (caddr_t) "on"},
201 {"-EM", "*exitMenu", XrmoptionNoArg, (caddr_t) "on"},
202 {"+EM", "*exitMenu", XrmoptionNoArg, (caddr_t) "off"},
203 {"-SU", "*saveUnder", XrmoptionNoArg, (caddr_t) "on"},
204 };
205
206 Widget toplevel;
207
208 int
get_application_resources(argc,argv)209 get_application_resources (argc, argv)
210 int argc;
211 char **argv;
212 {
213 XtAppContext app;
214
215 toplevel = XtAppInitialize (&app, "Xwnmo", optionDescList, XtNumber (optionDescList), &argc, (String *) argv, (String *) NULL, (ArgList) NULL, (Cardinal) 0);
216 XtGetApplicationResources (toplevel, (XtPointer) & resource, app_resources, XtNumber (app_resources), NULL, 0);
217
218 root_def_servername = root_def_reverse_servername = resource.servername_res;
219 root_username = resource.username_res;
220 ximrc_file = resource.ximrc_file_res;
221 cvt_key_file = resource.cvt_key_file_res;
222 cvt_fun_file = resource.cvt_fun_file_res;
223 cvt_meta_file = resource.cvt_meta_file_res;
224 display_name = resource.display_name_res;
225 #ifdef USING_XJUTIL
226 xjutil_name = resource.xjutil_res;
227 #endif /* USING_XJUTIL */
228 def_lang = resource.lang_name_res;
229 return (argc);
230 }
231
232 static int
xerror_handler(d,ev)233 xerror_handler (d, ev)
234 Display *d;
235 register XErrorEvent *ev;
236 {
237 #ifdef USING_XJUTIL
238 register XIMLangDataBase *ld;
239
240 for (ld = language_db; ld; ld = ld->next)
241 {
242 if (ev->resourceid == ld->xjutil_id)
243 {
244 if (ld->xjutil_use)
245 ld->xjutil_use->cur_xl->working_xjutil = 0;
246 break;
247 }
248 }
249 #endif /* USING_XJUTIL */
250 return (0);
251 }
252
253 static int
xioerror_handler(d)254 xioerror_handler (d)
255 Display *d;
256 {
257 perror ("xwnmo");
258 epilogue ();
259 XCloseDisplay (dpy);
260 exit (2);
261 return (0);
262 }
263
264 static void
write_ximid(port,root)265 write_ximid (port, root)
266 short port;
267 XIMRootRec *root;
268 {
269 unsigned char buffer[HOSTNAME_SIZE + sizeof (long) * 4];
270 register unsigned char *p;
271 unsigned short pnumber;
272 long major_version;
273 long minor_version;
274
275 if (!(xim_id = XInternAtom (dpy, XIM_INPUTMETHOD, True)))
276 {
277 xim_id = XInternAtom (dpy, XIM_INPUTMETHOD, False);
278 }
279 major_version = htonl (XIM_MAJOR_VERSION);
280 minor_version = htonl (XIM_MINOR_VERSION);
281 pnumber = (unsigned short) htons (port);
282 XmuGetHostname (hostname, sizeof hostname);
283 p = buffer;
284 bcopy (hostname, p, HOSTNAME_SIZE);
285 bcopy (&pnumber, (p += HOSTNAME_SIZE), sizeof (unsigned short));
286 bcopy (&major_version, (p += sizeof (unsigned short)), sizeof (long));
287 bcopy (&minor_version, (p += sizeof (long)), sizeof (long));
288 *(p += sizeof (long)) = '\0';
289
290 XChangeProperty (dpy, root->root_window, xim_id, XA_STRING, 8, PropModeReplace, buffer, (p - buffer));
291
292 XSetSelectionOwner (dpy, xim_id, root->ximclient->w, 0L);
293 }
294
295 static void
clear_xl(x)296 clear_xl (x)
297 register XIMLangRec *x;
298 {
299 x->linefeed[0] = x->linefeed[1] = x->linefeed[2] = 0;
300 x->vst = 0;
301 x->max_l1 = x->max_l2 = x->max_l3 = 0;
302 x->note[0] = x->note[1] = 0;
303 x->currentcol0 = x->currentcol = 0;
304 x->max_pos0 = x->max_pos = 0;
305 x->max_cur = 0;
306 x->del_x = 0;
307 x->cursor_flag = 0;
308 x->mark_flag = 0;
309 x->u_line_flag = x->r_flag = x->b_flag = x->visible = 0;
310 x->visible_line = 0;
311 x->m_cur_flag = 0;
312 }
313
314 static int
create_ichi(root)315 create_ichi (root)
316 XIMRootRec *root;
317 {
318 register Ichiran *ichi = root->ichi;
319 register XIMLangRec *xl = root->ximclient->xl[0];
320 register unsigned int width, height;
321 unsigned long fg, bg;
322 int i;
323 char name[32], class[32];
324
325 ichi->save_buf = NULL;
326 ichi->max_columns = MAX_ICHI_COLUMNS;
327 if (alloc_for_save_buf (ichi, MAX_ICHI_LINES) < 0)
328 return (-1);
329 ichi->max_button = MAX_BUTTON;
330 ichi->select_mode = '\0';
331
332 width = root->ximclient->client_area.width;
333 height = root->ximclient->client_area.height;
334 fg = root->ximclient->pe.fg;
335 bg = root->ximclient->pe.bg;
336
337 ichi->w = XCreateSimpleWindow (dpy, root->root_window, 0, 0, width, height, root->bw, fg, bg);
338 ichi->w0 = XCreateSimpleWindow (dpy, ichi->w, 0, FontWidth (xl) * 4, width, height, 1, fg, bg);
339 ichi->w1 = XCreateSimpleWindow (dpy, ichi->w0, 0, FontWidth (xl) * 4, width, height, 0, fg, bg);
340 ichi->nyuu_w = XCreateSimpleWindow (dpy, ichi->w, 0, 0, FontWidth (xl) * 5, FontHeight (xl), 1, fg, bg);
341 if (!ichi->w || !ichi->w1 || !ichi->nyuu_w)
342 {
343 print_out ("Could not create X resources for ichiran");
344 return (-1);
345 }
346
347 XSetTransientForHint (dpy, ichi->w, root->root_window);
348 if (xim->save_under)
349 {
350 attributes.save_under = True;
351 XChangeWindowAttributes (dpy, ichi->w, CWSaveUnder, &attributes);
352 }
353 XDefineCursor (dpy, ichi->w, cursor3);
354 XSelectInput (dpy, ichi->w, KeyPressMask | StructureNotifyMask);
355 XSelectInput (dpy, ichi->w1, ExposureMask);
356 XSelectInput (dpy, ichi->nyuu_w, ExposureMask);
357
358 ichi->title = create_box (ichi->w, 0, 0, FontWidth (xl), FontHeight (xl), 1, fg, bg, fg, 0, '\0');
359 ichi->subtitle = create_box (ichi->w, 0, 0, FontWidth (xl), FontHeight (xl), 1, fg, bg, fg, 0, '\0');
360 ichi->comment = create_box (ichi->w, 0, 0, FontWidth (xl), FontHeight (xl), 1, fg, bg, fg, 0, '\0');
361 if (!ichi->title || !ichi->subtitle || !ichi->comment)
362 return (-1);
363 ichi->title->redraw_cb = set_j_c;
364 ichi->subtitle->redraw_cb = set_j_c;
365 for (i = 0; i < ichi->max_button; i++)
366 {
367 ichi->button[i] = create_box (ichi->w, 0, 0, FontWidth (xl), FontHeight (xl), 2, fg, bg, fg, cursor2, 1);
368 if (!ichi->button[i])
369 return (-1);
370 ichi->button[i]->redraw_cb = set_j_c;
371 }
372 ichi->button[CANCEL_W]->do_ret = ichi->button[EXEC_W]->do_ret = True;
373 ichi->button[CANCEL_W]->sel_ret = -2;
374 ichi->button[EXEC_W]->sel_ret = 1;
375 ichi->button[CANCEL_W]->cb = ichi->button[EXEC_W]->cb = cur_cl_change3;
376 ichi->button[MOUSE_W]->cb = xw_mouse_select;
377 ichi->button[NEXT_W]->cb = next_ichi;
378 ichi->button[BACK_W]->cb = back_ichi;
379 map_box (ichi->title);
380 map_box (ichi->button[CANCEL_W]);
381 XMapWindow (dpy, ichi->w1);
382
383 sprintf (name, "list:%d", root->screen);
384 sprintf (class, "List:%d", root->screen);
385 set_wm_properties (ichi->w, 0, 0, width, height, SouthWestGravity, name, class, True, 0, InputHint, 0, 0);
386
387 XFlush (dpy);
388 return (0);
389 }
390
391 static int
create_inspect(root)392 create_inspect (root)
393 XIMRootRec *root;
394 {
395 Inspect *ins = root->inspect;
396 XIMLangRec *xl = root->ximclient->xl[0];
397 unsigned int width, height;
398 unsigned long fg, bg;
399 int i;
400 char name[32], class[32];
401
402 ins->max_button = MAX_BUTTON;
403
404 width = root->ximclient->client_area.width;
405 height = root->ximclient->client_area.height;
406 fg = root->ximclient->pe.fg;
407 bg = root->ximclient->pe.bg;
408
409 ins->w = XCreateSimpleWindow (dpy, root->root_window, 0, 0, width, height, root->bw, fg, bg);
410 ins->w1 = XCreateSimpleWindow (dpy, ins->w, 0, FontHeight (xl) * 2, width, height, 1, fg, bg);
411 XSetTransientForHint (dpy, ins->w, root->root_window);
412 if (xim->save_under)
413 {
414 attributes.save_under = True;
415 XChangeWindowAttributes (dpy, ins->w, CWSaveUnder, &attributes);
416 }
417 XDefineCursor (dpy, ins->w, cursor3);
418 XSelectInput (dpy, ins->w, KeyPressMask | StructureNotifyMask);
419 XSelectInput (dpy, ins->w1, ExposureMask);
420
421 ins->title = create_box (ins->w, 0, 0, FontWidth (xl), FontHeight (xl), 1, fg, bg, fg, 0, '\0');
422 if (!ins->title)
423 return (-1);
424 ins->title->redraw_cb = set_j_c;
425 for (i = 0; i < ins->max_button; i++)
426 {
427 ins->button[i] = create_box (ins->w, 0, 0, FontWidth (xl), FontHeight (xl), 2, fg, bg, fg, cursor2, 1);
428 if (!ins->button[i])
429 return (-1);
430 ins->button[i]->redraw_cb = set_j_c;
431 }
432 ins->button[CANCEL_W]->cb = ins->button[DELETE_W]->cb = ins->button[USE_W]->cb = cur_cl_change3;
433 ins->button[CANCEL_W]->do_ret = ins->button[DELETE_W]->do_ret = ins->button[USE_W]->do_ret = True;
434 ins->button[CANCEL_W]->sel_ret = -2;
435 ins->button[DELETE_W]->sel_ret = 0;
436 ins->button[USE_W]->sel_ret = 1;
437 ins->button[NEXT_W]->cb = xw_next_inspect;
438 ins->button[BACK_W]->cb = xw_back_inspect;
439 ins->button[NEXT_W]->cb_data = ins->button[BACK_W]->cb_data = NULL;
440
441 sprintf (name, "inspect:%d", root->screen);
442 sprintf (class, "Inspect:%d", root->screen);
443 set_wm_properties (ins->w, 0, 0, width, height, SouthWestGravity, name, class, True, 0, InputHint, 0, 0);
444 XMapSubwindows (dpy, ins->w);
445 XFlush (dpy);
446 return (0);
447 }
448
449 int
create_yes_no(xc)450 create_yes_no (xc)
451 XIMClientRec *xc;
452 {
453 XIMLangRec *xl = xc->xl[0];
454 XIMRootRec *root = xc->root_pointer;
455 YesOrNo *yes_no = xc->yes_no;
456 register unsigned int width, height;
457 unsigned long fg, bg;
458
459 width = 1;
460 height = 1;
461 fg = xc->pe.fg;
462 bg = xc->pe.bg;
463
464 yes_no->root_pointer = root;
465 if (!(yes_no->w = XCreateSimpleWindow (dpy, root->root_window, 0, 0, width, height, root->bw, fg, bg)))
466 {
467 print_out ("Could not create X resource for yes_no");
468 return (-1);
469 }
470 XSetTransientForHint (dpy, yes_no->w, root->root_window);
471 if (xim->save_under)
472 {
473 attributes.save_under = True;
474 XChangeWindowAttributes (dpy, yes_no->w, CWSaveUnder, &attributes);
475 }
476 XDefineCursor (dpy, yes_no->w, cursor3);
477 XSelectInput (dpy, yes_no->w, (StructureNotifyMask | KeyPressMask));
478 if (!(yes_no->title = create_box (yes_no->w, 0, 0, width, height, 0, fg, bg, fg, 0, '\0')))
479 return (-1);
480 if (!(yes_no->button[0] = create_box (yes_no->w, (FontWidth (xl) * 2),
481 (FontHeight (xl) * 2 + FontHeight (xl) / 2), (FontWidth (xl) * 4 + IN_BORDER * 2), (FontHeight (xl) + IN_BORDER * 2), root->bw, fg, bg, fg, cursor2, 1)))
482 {
483 remove_box (yes_no->title);
484 return (-1);
485 }
486 if (!(yes_no->button[1] = create_box (yes_no->w, (FontWidth (xl) * 10),
487 (FontHeight (xl) * 2 + FontHeight (xl) / 2), (FontWidth (xl) * 6 + IN_BORDER * 2), (FontHeight (xl) + IN_BORDER * 2), root->bw, fg, bg, fg, cursor2, 1)))
488 {
489 remove_box (yes_no->title);
490 remove_box (yes_no->button[0]);
491 return (-1);
492 }
493 yes_no->title->redraw_cb = cur_cl_change4;
494 yes_no->title->redraw_cb_data = (int *) xc;
495 map_box (yes_no->title);
496 yes_no->button[0]->redraw_cb = cur_cl_change3;
497 yes_no->button[1]->redraw_cb = cur_cl_change3;
498 yes_no->button[0]->redraw_cb_data = (int *) xc;
499 yes_no->button[1]->redraw_cb_data = (int *) xc;
500 yes_no->button[0]->sel_ret = 1;
501 yes_no->button[1]->sel_ret = 0;
502 yes_no->button[0]->cb = yes_no->button[1]->cb = cur_cl_change3;
503 yes_no->button[0]->cb_data = yes_no->button[1]->cb_data = (int *) xc;
504 yes_no->button[0]->do_ret = yes_no->button[1]->do_ret = True;
505
506 set_wm_properties (yes_no->w, 0, 0, width, height, CenterGravity, "yesNo", "YesNo", True, 0, InputHint, 0, 0);
507 XFlush (dpy);
508 return (0);
509 }
510
511 void
read_wm_id()512 read_wm_id ()
513 {
514 register int i;
515 register XIMRootRec *root;
516
517 if ((wm_id = XInternAtom (dpy, "WM_PROTOCOLS", True)))
518 {
519 wm_id1 = XInternAtom (dpy, "WM_DELETE_WINDOW", True);
520 for (i = 0; i < xim->screen_count; i++)
521 {
522 root = xim->root_pointer[i];
523 XChangeProperty (dpy, root->ximclient->w, wm_id, XA_INTEGER, 32, PropModeReplace, (unsigned char *) &wm_id1, sizeof (Atom));
524 XChangeProperty (dpy, root->ximclient->yes_no->w, wm_id, XA_INTEGER, 32, PropModeReplace, (unsigned char *) &wm_id1, sizeof (Atom));
525 XChangeProperty (dpy, root->ichi->w, wm_id, XA_INTEGER, 32, PropModeReplace, (unsigned char *) &wm_id1, sizeof (Atom));
526 XChangeProperty (dpy, root->inspect->w, wm_id, XA_INTEGER, 32, PropModeReplace, (unsigned char *) &wm_id1, sizeof (Atom));
527 }
528 }
529 else
530 {
531 wm_id = wm_id1 = 0;
532 }
533 }
534
535 int
create_xim_window(root,xc)536 create_xim_window (root, xc)
537 XIMRootRec *root;
538 XIMClientRec *xc;
539 {
540 int icon_x = 0, icon_y = 0;
541 unsigned int icon_width, icon_height;
542 int icon_mask = 0, state;
543 long flags;
544 char name[32], class[32];
545
546 if (sub_resource.icon_geometry_res)
547 {
548 icon_mask = XParseGeometry (sub_resource.icon_geometry_res, &icon_x, &icon_y, &icon_width, &icon_height);
549 }
550
551 xc->w = XCreateSimpleWindow (dpy, root->root_window, ClientX (xc), ClientY (xc), ClientWidth (xc), ClientHeight (xc), root->bw, xc->pe.fg, xc->pe.bg);
552 if (!xc->w)
553 {
554 print_out ("Could not create X resource for main window.");
555 return (-1);
556 }
557 /*
558 XSetTransientForHint(dpy, xc->w, root->root_window);
559 */
560 if (xim->save_under)
561 {
562 attributes.save_under = True;
563 XChangeWindowAttributes (dpy, xc->w, CWSaveUnder, &attributes);
564 }
565 XSetWindowBorder (dpy, xc->w, root->bc);
566 XDefineCursor (dpy, xc->w, cursor3);
567
568 flags = InputHint | StateHint;
569 if ((icon_mask & XValue) && (icon_mask & YValue))
570 {
571 flags |= IconPositionHint;
572 }
573 if (sub_resource.iconic_start_res && !sub_resource.root_visible_res)
574 {
575 state = IconicState;
576 }
577 else
578 {
579 state = NormalState;
580 }
581 sprintf (name, "xwnmo:%d", root->screen);
582 sprintf (class, "Xwnmo:%d", root->screen);
583 set_wm_properties (xc->w, ClientX (xc), ClientY (xc), ClientWidth (xc), ClientHeight (xc), SouthWestGravity, name, class, False, state, flags, icon_x, icon_y);
584 XClearWindow (dpy, xc->w);
585 XSelectInput (dpy, xc->w, (ButtonPressMask | ButtonReleaseMask | ResizeRedirectMask | StructureNotifyMask));
586 return (0);
587 }
588
589 static int
create_one_root(root,lc_name,screen)590 create_one_root (root, lc_name, screen)
591 XIMRootRec *root;
592 char *lc_name;
593 int screen;
594 {
595 register XIMClientRec *xc;
596 register XIMLangRec *xl;
597 register int i, num;
598 int x, y;
599 unsigned int width, height;
600 int size_of_ximclient = sizeof (XIMClientRec);
601 int size_of_yes_no = sizeof (YesOrNo);
602 int size_of_ichiran = sizeof (Ichiran);
603 int size_of_inspect = sizeof (Inspect);
604 int all_size;
605 int using_l_len = 0;
606 int mask = 0;
607 char *p;
608 #ifdef X11R5
609 XLocale xlc;
610 #endif /* X11R5 */
611 XIMNestLangList lc_list = NULL, lc;
612 char *def_font;
613 char sub_name[64], sub_class[64];
614 Arg args[3];
615
616 args[0].name = XtNscreen;
617 args[0].value = (XtArgVal) ScreenOfDisplay (dpy, screen);
618 args[1].name = XtNcolormap;
619 args[1].value = (XtArgVal) DefaultColormap (dpy, screen);
620
621 all_size = size_of_ximclient + size_of_ichiran + size_of_inspect + size_of_yes_no;
622 if ((p = (char *) Malloc (all_size)) == NULL)
623 {
624 malloc_error ("allocation of the initial area");
625 return (-1);
626 }
627 root->ximclient = xc = (XIMClientRec *) p;
628 p += size_of_ximclient;
629 root->ichi = (Ichiran *) p;
630 p += size_of_ichiran;
631 root->inspect = (Inspect *) p;
632 p += size_of_inspect;
633 xc->yes_no = (YesOrNo *) p;
634
635 root->root_window = RootWindow (dpy, screen);
636 root->screen = screen;
637
638 xc->root_pointer = root;
639 xc->cur_xl = NULL;
640 xc->next = NULL;
641 if (!(xc->user_name = alloc_and_copy (root_username)))
642 {
643 malloc_error ("allocation of the initial area");
644 return (-1);
645 }
646 xc->fd = -1;
647 xc->input_style = (XIMPreeditArea | XIMStatusArea);
648 xc->w = (Window) 0;
649 default_xc_set (xc);
650
651 sprintf (sub_name, "screen%d", i);
652 sprintf (sub_class, "Screen%d", i);
653 XtGetSubresources (toplevel, (XtPointer) & sub_resource, sub_name, sub_class, sub_resources, XtNumber (sub_resources), args, 2);
654 if (resource.iconic_start_res)
655 sub_resource.iconic_start_res = True;
656 if (resource.geometry_res)
657 sub_resource.geometry_res = resource.geometry_res;
658 if (resource.border_width_res)
659 sub_resource.border_width_res = resource.border_width_res;
660
661 root->root_visible = (char) (sub_resource.root_visible_res ? 1 : 0);
662 root->root_visible_flag = (char) 0;
663
664 xc->pe.fg = xc->st.fg = sub_resource.fore_color_res;
665 xc->pe.bg = xc->st.bg = sub_resource.back_color_res;
666 root->bc = sub_resource.border_color_res;
667 root->bw = sub_resource.border_width_res;
668 if (root->bw == 0)
669 root->bw = DEFAULT_BORDER_WIDTH;
670
671 /* Create GC */
672 xgcv.foreground = xc->pe.fg;
673 xgcv.background = xc->pe.bg;
674 xc->pe.gc = xc->st.gc = XCreateGC (dpy, root->root_window, (GCForeground | GCBackground), &xgcv);
675 /* Create reverse GC */
676 xgcv.foreground = xc->pe.bg;
677 xgcv.background = xc->pe.fg;
678 xc->pe.reversegc = xc->st.reversegc = XCreateGC (dpy, root->root_window, (GCForeground | GCBackground), &xgcv);
679 /* Create invert GC */
680 xgcv.foreground = xc->pe.fg;
681 xgcv.function = GXinvert;
682 xgcv.plane_mask = XOR (xc->pe.fg, xc->pe.bg);
683 xc->pe.invertgc = XCreateGC (dpy, root->root_window, (GCForeground | GCFunction | GCPlaneMask), &xgcv);
684 if (!xc->pe.gc || !xc->pe.reversegc || !xc->pe.invertgc)
685 {
686 print_out ("Could not create GC");
687 return (-1);
688 }
689
690 if (sub_resource.geometry_res)
691 {
692 mask = XParseGeometry (sub_resource.geometry_res, &x, &y, &width, &height);
693 }
694 if (mask & WidthValue)
695 {
696 ClientWidth (xc) = width;
697 }
698 else
699 {
700 ClientWidth (xc) = DisplayWidth (dpy, root->screen) - (root->bw * 2);
701 }
702
703 if ((xc->have_world = get_langlist (lc_name, &lc_list)) < 0)
704 return (-1);
705 if (xc->have_world)
706 xc->world_on = 1;
707 else
708 xc->world_on = 0;
709 for (num = 0, lc = lc_list; lc != NULL; lc = lc->next)
710 num++;
711 if ((xc->xl = (XIMLangRec **) Malloc (sizeof (XIMLangRec *) * num)) == NULL)
712 {
713 malloc_error ("allocation of the initial area");
714 return (-1);
715 }
716 for (i = 0, lc = lc_list; lc != NULL; lc = lc->next)
717 {
718 if (!setlocale (LC_ALL, lc->lang_db->lc_name))
719 {
720 print_out1 ("Could not set locale \"%s\" for my internal locale.", lc->lang_db->lc_name);
721 print_out ("I give up creating of environment for such locale.");
722 print_out1 ("Please modify internal locale of ximconf.");
723 continue;
724 }
725 if ((xl = xc->xl[i] = (XIMLangRec *) Calloc (1, sizeof (XIMLangRec))) == NULL)
726 {
727 malloc_error ("allocation of the initial area");
728 return (-1);
729 }
730 xc->cur_xl = xl;
731 xl->lc_list = NULL;
732 if (add_locale_to_xl (xl, lc) < 0)
733 {
734 malloc_error ("allocation of the initial area");
735 return (-1);
736 }
737 xl->cur_lc = xl->lc_list;
738 xl->lang_db = lc->lang_db;
739 xl->w_c = NULL;
740 #ifdef X11R5
741 if (!(xlc = _XFallBackConvert ()) || !(xl->xlc = _XlcDupLocale (xlc)))
742 {
743 #else
744 if (!(xl->xlc = _XlcCurrentLC ()))
745 {
746 #endif /* X11R5 */
747 print_out ("Could not create locale environment.");
748 return (-1);
749 }
750 #ifdef USING_XJUTIL
751 xl->xjutil_fs_id = -1;
752 xl->working_xjutil = 0;
753 #endif /* USING_XJUTIL */
754 /* Create Default Windows */
755 if (sub_resource.font_set_res)
756 {
757 if (load_font_set (xl, sub_resource.font_set_res, sub_resource.font_set_res) == -1)
758 {
759 print_out2 ("Could not create any fontset for \"%s\" in locale \"%s\".", sub_resource.font_set_res, lc->lc_name);
760 print_out ("I will use defualt fontset.");
761 }
762 }
763 if (xl->pe_fs == NULL)
764 {
765 if ((def_font = get_default_font_name (xl->lang_db->lang)) == NULL)
766 {
767 print_out1 ("Could not find default fontset for %s", xl->lang_db->lang);
768 goto ERROR_OCCUR1;
769 }
770 if (load_font_set (xl, def_font, def_font) == -1)
771 {
772 print_out2 ("Could not create any fontset for \"%s\" in locale \"%s\".", def_font, xl->lang_db->lc_name);
773 goto ERROR_OCCUR1;
774 }
775 }
776 if (i == 0)
777 {
778 ClientHeight (xc) = FontHeight (xl) + FontHeight (xl) / 2;
779
780 xc->columns = (int) ClientWidth (xc) / (int) FontWidth (xl);
781 if (xc->columns <= 0)
782 xc->columns = 1;
783 xc->max_columns = xc->columns - MHL0;
784 if (xc->max_columns <= 0)
785 xc->max_columns = 1;
786
787 PreeditWidth (xc) = xc->max_columns * FontWidth (xl);
788 PreeditHeight (xc) = FontHeight (xl);
789 PreeditX (xc) = FontWidth (xl) * (MHL0 + 1);
790 PreeditY (xc) = (int) (ClientHeight (xc) - FontHeight (xl)) / 2;
791
792 StatusWidth (xc) = FontWidth (xl) * MHL0;
793 StatusHeight (xc) = FontHeight (xl);
794 StatusX (xc) = 0;
795 StatusY (xc) = PreeditY (xc);
796 if (mask & XValue)
797 {
798 ClientX (xc) = x;
799 }
800 else
801 {
802 ClientX (xc) = 0;
803 }
804 if (mask & YValue)
805 {
806 ClientY (xc) = y;
807 }
808 else
809 {
810 ClientY (xc) = DisplayHeight (dpy, root->screen) - ClientHeight (xc) - (root->bw * 2);
811 }
812 if (create_xim_window (root, xc) < 0)
813 goto ERROR_OCCUR2;
814 if (create_yes_no (xc) == -1)
815 {
816 XDestroyWindow (dpy, xc->w);
817 goto ERROR_OCCUR2;
818 }
819 }
820 cur_p = cur_x = xc;
821 if (new_client (xc, xl, (screen == 0) ? True : False) == -1)
822 {
823 print_out1 ("I give up creating of environment for locale \"%s\".", xl->lang_db->lc_name);
824 goto ERROR_OCCUR3;
825 }
826 if (!root->root_visible)
827 {
828 XMapWindow (dpy, xc->w);
829 root->root_visible_flag = (char) 1;
830 }
831 XFlush (dpy);
832 i++;
833 using_l_len += strlen (xl->lang_db->lc_name) + 1;
834 continue;
835 ERROR_OCCUR3:
836 if (i == 0)
837 {
838 remove_box (xc->yes_no->title);
839 remove_box (xc->yes_no->button[0]);
840 remove_box (xc->yes_no->button[1]);
841 Free ((char *) xc->yes_no);
842 XDestroyWindow (dpy, xc->w);
843 }
844 ERROR_OCCUR2:
845 XFreeFontSet (dpy, xl->pe_fs);
846 Free ((char *) xl->pe_b_char);
847 XFreeFontSet (dpy, xl->st_fs);
848 Free ((char *) xl->st_b_char);
849 ERROR_OCCUR1:
850 remove_locale_to_xl (xl, lc);
851 #ifdef X11R5
852 XFree ((char *) xl->xlc);
853 #endif
854 Free (xl);
855 }
856 if (i == 0)
857 {
858 print_out ("Could not create any environment.");
859 print_out ("I will abort soon.");
860 return (-1);
861 }
862 xc->lang_num = i;
863 if (!(xc->using_language = (char *) Malloc (sizeof (char) * using_l_len)))
864 {
865 malloc_error ("allocation of the initial area");
866 return (-1);
867 }
868 xc->using_language[0] = '\0';
869 for (i = 0; i < xc->lang_num; i++)
870 {
871 strcat (xc->using_language, xc->xl[i]->lang_db->lc_name);
872 strcat (xc->using_language, ";");
873 }
874 xc->using_language[strlen (xc->using_language) - 1] = '\0';
875 xc->cur_xl = xc->xl[0];
876 cur_p = cur_x = root->ximclient;
877 cur_lang = root->ximclient->cur_xl->lang_db;
878 c_c = cur_p->cur_xl->w_c;
879 cur_rk = c_c->rk;
880 cur_rk_table = cur_rk->rk_table;
881
882 add_ximclientlist (xc);
883
884 XMapWindow (dpy, xc->cur_xl->ws);
885 if (create_ichi (root) < 0 || create_inspect (root) < 0)
886 return (-1);
887 if (henkan_off_flag == 0)
888 {
889 disp_mode ();
890 }
891 else
892 {
893 display_henkan_off_mode ();
894 }
895 return (0);
896 }
897
898 int
create_xim(lc_name)899 create_xim (lc_name)
900 char *lc_name;
901 {
902 register XIMLcNameRec *ln;
903 register int i;
904 int screen_count;
905 Atom ret;
906 char displaybuf[128];
907 short port;
908 int lang_len = 0;
909 char *p;
910 int size_of_xim;
911 int size_of_root_pointer;
912 int size_of_root;
913 int all_size;
914 #ifndef X11R3
915 XTextProperty machineName;
916 #endif /* X11R3 */
917 extern char *getenv ();
918
919 #ifdef X_WCHAR
920 dol_wchar_t = 0x20202024;
921 cursor_wchar_t = 0x20202020;
922 #else /* X_WCHAR */
923 mbtowc (&dol_wchar_t, "$", 1);
924 mbtowc (&cursor_wchar_t, " ", 1);
925 #endif /* X_WCHAR */
926
927 dpy = XtDisplay (toplevel);
928 screen_count = ScreenCount (dpy);
929 XSetErrorHandler (xerror_handler);
930 XSetIOErrorHandler (xioerror_handler);
931
932 #if defined(X11R5) || defined(BC_X11R5)
933 if (ret = XInternAtom (dpy, XIM_INPUTMETHOD, True))
934 {
935 if (XGetSelectionOwner (dpy, ret))
936 {
937 print_out ("I am already running.");
938 return (-1);
939 }
940 }
941 #endif /* defined(X11R5) || defined(BC_X11R5) */
942
943 if (DisplayString (dpy))
944 {
945 strcpy (displaybuf, DisplayString (dpy));
946 }
947 else if (getenv ("DISPLAY"))
948 {
949 strcpy (displaybuf, getenv ("DISPLAY"));
950 }
951 else
952 {
953 print_out ("I could not open socket.");
954 return (-1);
955 }
956 #ifdef USING_XJUTIL
957 call_kill_old_xjutil ();
958 #endif
959 if ((port = init_net (ConnectionNumber (dpy), displaybuf)) == (short) -1)
960 {
961 print_out ("I could not open socket.");
962 return (-1);
963 }
964
965 cursor1 = XCreateFontCursor (dpy, 52);
966 cursor2 = XCreateFontCursor (dpy, 60);
967 cursor3 = XCreateFontCursor (dpy, 24);
968
969 size_of_xim = sizeof (XInputManager);
970 size_of_root_pointer = sizeof (XIMRootRec *) * screen_count;
971 size_of_root = sizeof (XIMRootRec);
972 all_size = size_of_xim + size_of_root_pointer + (size_of_root * screen_count);
973 if ((p = (char *) Malloc (all_size)) == NULL)
974 {
975 malloc_error ("allocation of the initial area");
976 return (-1);
977 }
978 xim = (XInputManager *) p;
979 p += size_of_xim;
980 xim->root_pointer = (XIMRootRec **) p;
981 p += size_of_root_pointer;
982 for (i = 0; i < screen_count; i++)
983 {
984 xim->root_pointer[i] = (XIMRootRec *) p;
985 p += size_of_root;
986 }
987
988 xim->screen_count = screen_count;
989 xim->default_screen = DefaultScreen (dpy);
990 xim->j_c = NULL;
991 xim->cur_j_c_root = NULL;
992 xim->sel_ret = -1;
993 xim->client_count = 1;
994 xim->sel_button = (char) 0;
995 xim->exit_menu = (char) 0;
996 xim->exit_menu = (char) (resource.exit_menu_res ? 1 : 0);
997 xim->exit_menu_flg = (char) 0;
998 xim->save_under = (char) (resource.save_under_res ? 1 : 0);
999 xim->supported_style[0] = SUPPORT_STYLE_1;
1000 xim->supported_style[1] = SUPPORT_STYLE_2;
1001 xim->supported_style[2] = SUPPORT_STYLE_3;
1002 #ifdef CALLBACKS
1003 xim->supported_style[3] = SUPPORT_STYLE_4;
1004 xim->supported_style[4] = SUPPORT_STYLE_5;
1005 xim->supported_style[5] = SUPPORT_STYLE_6;
1006 xim->supported_style[6] = SUPPORT_STYLE_7;
1007 #endif /* CALLBACKS */
1008
1009 ximclient_list = NULL;
1010
1011 for (ln = lc_name_list; ln; ln = ln->next)
1012 {
1013 lang_len += (strlen (ln->lc_name) + 1);
1014 }
1015 if (lang_len)
1016 {
1017 if (!(xim->supported_language = Malloc (lang_len)))
1018 {
1019 malloc_error ("allocation of the initial area");
1020 return (-1);
1021 }
1022 *xim->supported_language = '\0';
1023 for (ln = lc_name_list; ln; ln = ln->next)
1024 {
1025 strcat (xim->supported_language, ln->lc_name);
1026 strcat (xim->supported_language, ",");
1027 }
1028 *(xim->supported_language + (lang_len - 1)) = '\0';
1029 }
1030 else
1031 {
1032 xim->supported_language = NULL;
1033 }
1034
1035 for (i = 0; i < screen_count; i++)
1036 {
1037 if (create_one_root (xim->root_pointer[i], lc_name, i) == -1)
1038 return (-1);
1039 }
1040 #if defined(X11R5) || defined(BC_X11R5)
1041 write_ximid (port, xim->root_pointer[xim->default_screen]);
1042 #endif /* defined(X11R5) || defined(BC_X11R5) */
1043 #ifndef X11R5
1044 if (XimPreConnect (port, xim->root_pointer[xim->default_screen]) < 0)
1045 return -1;
1046 #endif /* !X11R5 */
1047
1048 read_wm_id ();
1049 #ifdef XJPLIB
1050 XJp_init ();
1051 #endif /* XJPLIB */
1052
1053 #ifndef X11R3
1054 machineName.encoding = XA_STRING;
1055 machineName.format = 8;
1056 machineName.nitems = XmuGetHostname (hostname, sizeof hostname);
1057 machineName.value = (unsigned char *) hostname;
1058 XSetWMClientMachine (dpy, xim->root_pointer[xim->default_screen]->ximclient->w, &machineName);
1059 #endif /* X11R3 */
1060 XChangeProperty (dpy, xim->root_pointer[xim->default_screen]->ximclient->w, XA_WM_COMMAND, XA_STRING, 8, PropModeReplace, (unsigned char *) arg_string, strlen (arg_string));
1061 return (0);
1062 }
1063
1064 void
xw_end()1065 xw_end ()
1066 {
1067 extern int shutdown (), close ();
1068
1069 close_net ();
1070 XCloseDisplay (dpy);
1071 }
1072
1073 int
create_preedit(xc,xl,only_window)1074 create_preedit (xc, xl, only_window)
1075 XIMClientRec *xc;
1076 XIMLangRec *xl;
1077 int only_window;
1078 {
1079 register char *p;
1080 int total_size;
1081 int width, height, border_width = 0;
1082 Window parent;
1083 unsigned long mask = 0L;
1084
1085 if (IsPreeditNothing (xc))
1086 return (0);
1087
1088 if (!only_window)
1089 {
1090 if ((p = Malloc ((total_size = (sizeof (wchar) + sizeof (unsigned char)) * (maxchg * 2 + 1)))) == NULL)
1091 {
1092 malloc_error ("allocation of client's area");
1093 return (-1);
1094 }
1095 bzero (p, total_size);
1096 xl->buf = (wchar *) p;
1097 p += sizeof (wchar) * (maxchg * 2 + 1);
1098 xl->att = (unsigned char *) p;
1099 clear_xl (xl);
1100
1101 xl->del_x = 0;
1102 xl->vst = 0;
1103 xl->note[0] = 0;
1104 xl->note[1] = 0;
1105 xc->maxcolumns = maxchg * 2;
1106 }
1107
1108 if (IsPreeditArea (xc))
1109 {
1110 if (xc->pe.area_needed.width < FontWidth (xl) * 2)
1111 xc->pe.area_needed.width = FontWidth (xl) * 2;
1112 if (xc->pe.area_needed.height < FontHeight (xl))
1113 xc->pe.area_needed.height = FontHeight (xl);
1114 if (PreeditWidth (xc) <= 0)
1115 PreeditWidth (xc) = 1;
1116 if (PreeditHeight (xc) <= 0)
1117 PreeditHeight (xc) = 1;
1118 height = FontHeight (xl);
1119
1120 mask = CWBorderPixel;
1121 attributes.border_pixel = xc->pe.fg;
1122 if (xc->pe.bg_pixmap)
1123 {
1124 mask |= CWBackPixmap;
1125 attributes.background_pixmap = xc->pe.bg_pixmap;
1126 }
1127 else
1128 {
1129 mask |= CWBackPixel;
1130 attributes.background_pixel = xc->pe.bg;
1131 }
1132 if (xc->pe.colormap)
1133 {
1134 mask |= CWColormap;
1135 attributes.colormap = xc->pe.colormap;
1136 }
1137 mask |= CWEventMask;
1138 attributes.event_mask = StructureNotifyMask;
1139 if (xim->save_under)
1140 {
1141 attributes.save_under = True;
1142 mask |= CWSaveUnder;
1143 }
1144 xl->wp[0] = XCreateWindow (dpy, xc->w, PreeditX (xc), PreeditY (xc), PreeditWidth (xc), PreeditHeight (xc), border_width, CopyFromParent, InputOutput, CopyFromParent, mask, &attributes);
1145 mask &= ~CWEventMask;
1146 if (xim->save_under)
1147 {
1148 mask &= ~CWSaveUnder;
1149 }
1150
1151 xl->wp[1] = xl->wp[2] = 0;
1152
1153 xl->wn[2] = XCreateWindow (dpy, xl->wp[0], PreeditWidth (xc) - FontWidth (xl), 0, FontWidth (xl), height, border_width, CopyFromParent, InputOutput, CopyFromParent, mask, &attributes);
1154
1155 mask |= CWEventMask;
1156 attributes.event_mask = ExposureMask;
1157 xl->wn[0] = XCreateWindow (dpy, xl->wp[0], 0, 0, FontWidth (xl), height, border_width, CopyFromParent, InputOutput, CopyFromParent, mask, &attributes);
1158 xl->wn[1] = XCreateWindow (dpy, xl->wp[0], PreeditWidth (xc) - FontWidth (xl), 0, FontWidth (xl), height, border_width, CopyFromParent, InputOutput, CopyFromParent, mask, &attributes);
1159 xl->w[0] = XCreateWindow (dpy, xl->wp[0], 0, 0, FontWidth (xl) * (xc->maxcolumns + 1), height, border_width, CopyFromParent, InputOutput, CopyFromParent, mask, &attributes);
1160 xl->w[1] = xl->w[2] = 0;
1161
1162 if (!xl->wp[0] || !xl->w[0] || !xl->wn[0] || !xl->wn[1] || !xl->wn[2])
1163 {
1164 return (-1);
1165 }
1166
1167 return (0);
1168 }
1169 else if (IsPreeditPosition (xc))
1170 {
1171
1172 width = FontWidth (xl) * (xc->maxcolumns + 1);
1173 height = FontHeight (xl);
1174 if (xc->focus_window)
1175 {
1176 parent = xc->focus_window;
1177 }
1178 else
1179 {
1180 parent = xc->w;
1181 }
1182 if (PreeditWidth (xc) <= 0)
1183 PreeditWidth (xc) = 1;
1184
1185 mask = CWBorderPixel;
1186 attributes.border_pixel = xc->pe.fg;
1187 if (xc->pe.bg_pixmap)
1188 {
1189 mask |= CWBackPixmap;
1190 attributes.background_pixmap = xc->pe.bg_pixmap;
1191 }
1192 else
1193 {
1194 mask |= CWBackPixel;
1195 attributes.background_pixel = xc->pe.bg;
1196 }
1197 if (xc->pe.colormap)
1198 {
1199 mask |= CWColormap;
1200 attributes.colormap = xc->pe.colormap;
1201 }
1202
1203 mask |= CWEventMask;
1204 attributes.event_mask = StructureNotifyMask;
1205 if (xim->save_under)
1206 {
1207 attributes.save_under = True;
1208 mask |= CWSaveUnder;
1209 }
1210 xl->wp[0] = XCreateWindow (dpy, parent, 0, 0, PreeditWidth (xc), height, border_width, CopyFromParent, InputOutput, CopyFromParent, mask, &attributes);
1211 xl->wp[1] = XCreateWindow (dpy, parent, 0, 0, PreeditWidth (xc), height, border_width, CopyFromParent, InputOutput, CopyFromParent, mask, &attributes);
1212 xl->wp[2] = XCreateWindow (dpy, parent, 0, 0, PreeditWidth (xc), height, border_width, CopyFromParent, InputOutput, CopyFromParent, mask, &attributes);
1213 xl->wn[2] = XCreateWindow (dpy, parent, 0, 0, FontWidth (xl), height, border_width, CopyFromParent, InputOutput, CopyFromParent, mask, &attributes);
1214 mask |= CWEventMask;
1215 attributes.event_mask = ExposureMask;
1216 xl->wn[0] = XCreateWindow (dpy, parent, 0, 0, FontWidth (xl), height, border_width, CopyFromParent, InputOutput, CopyFromParent, mask, &attributes);
1217 xl->wn[1] = XCreateWindow (dpy, parent, 0, 0, FontWidth (xl), height, border_width, CopyFromParent, InputOutput, CopyFromParent, mask, &attributes);
1218 if (xim->save_under)
1219 {
1220 mask &= ~CWSaveUnder;
1221 }
1222 mask |= CWBitGravity;
1223 attributes.bit_gravity = WestGravity;
1224 xl->w[0] = XCreateWindow (dpy, xl->wp[0], 0, 0, width, height, border_width, CopyFromParent, InputOutput, CopyFromParent, mask, &attributes);
1225 xl->w[1] = XCreateWindow (dpy, xl->wp[1], 0, 0, width, height, border_width, CopyFromParent, InputOutput, CopyFromParent, mask, &attributes);
1226 xl->w[2] = XCreateWindow (dpy, xl->wp[2], 0, 0, width, height, border_width, CopyFromParent, InputOutput, CopyFromParent, mask, &attributes);
1227
1228 if (!xl->wp[0] || !xl->wp[1] || !xl->wp[2] || !xl->w[0] || !xl->w[1] || !xl->w[2] || !xl->wn[0] || !xl->wn[1] || !xl->wn[2])
1229 {
1230 return (-1);
1231 }
1232
1233 xc->c0 = xc->c1 = xc->c2 = xc->maxcolumns;
1234 XMapWindow (dpy, xl->w[0]);
1235 XMapWindow (dpy, xl->w[1]);
1236 XMapWindow (dpy, xl->w[2]);
1237 XFlush (dpy);
1238 return (0);
1239 #ifdef CALLBACKS
1240 }
1241 else if (IsStatusCallbacks (xc))
1242 {
1243 return (0);
1244 #endif /* CALLBACKS */
1245 }
1246 else
1247 {
1248 return (-1);
1249 }
1250 }
1251
1252 int
create_status(xc,xl,only_window)1253 create_status (xc, xl, only_window)
1254 XIMClientRec *xc;
1255 XIMLangRec *xl;
1256 int only_window;
1257 {
1258 register char *p;
1259 int total_size;
1260 unsigned long mask = 0L;
1261
1262 if (IsStatusNothing (xc))
1263 return (0);
1264
1265 if (!only_window)
1266 {
1267 if ((p = Malloc ((total_size = (sizeof (wchar) + sizeof (unsigned char)) * (MHL0 * 2 + 1)))) == NULL)
1268 {
1269 malloc_error ("allocation of client's area");
1270 return (-1);
1271 }
1272 bzero (p, total_size);
1273 xl->buf0 = (wchar *) p;
1274 p += sizeof (wchar) * (MHL0 * 2 + 1);
1275 xl->att0 = (unsigned char *) p;
1276 }
1277
1278 if (IsStatusArea (xc))
1279 {
1280 if (xc->st.area_needed.width < StatusFontWidth (xl) * MHL0)
1281 xc->st.area_needed.width = StatusFontWidth (xl) * MHL0;
1282 if (xc->st.area_needed.height < StatusFontHeight (xl))
1283 xc->st.area_needed.height = StatusFontHeight (xl);
1284 if (StatusWidth (xc) <= 0)
1285 StatusWidth (xc) = 1;
1286 if (StatusHeight (xc) <= 0)
1287 StatusHeight (xc) = 1;
1288
1289 mask = (CWBorderPixel | CWEventMask | CWCursor);
1290 attributes.border_pixel = xc->pe.fg;
1291 attributes.event_mask = (ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | ExposureMask | StructureNotifyMask);
1292 attributes.cursor = cursor2;
1293 if (xc->st.bg_pixmap)
1294 {
1295 mask |= CWBackPixmap;
1296 attributes.background_pixmap = xc->st.bg_pixmap;
1297 }
1298 else
1299 {
1300 mask |= CWBackPixel;
1301 attributes.background_pixel = xc->st.bg;
1302 }
1303 if (xc->st.colormap)
1304 {
1305 mask |= CWColormap;
1306 attributes.colormap = xc->st.colormap;
1307 }
1308 if (xim->save_under)
1309 {
1310 attributes.save_under = True;
1311 mask |= CWSaveUnder;
1312 }
1313 if ((xl->ws = XCreateWindow (dpy, xc->w, StatusX (xc), StatusY (xc), StatusWidth (xc), StatusHeight (xc), 0, CopyFromParent, InputOutput, CopyFromParent, mask, &attributes)) == 0)
1314 {
1315 return (-1);
1316 }
1317 return (0);
1318 #ifdef CALLBACKS
1319 }
1320 else if (IsStatusCallbacks (xc))
1321 {
1322 return (0);
1323 #endif /* CALLBACKS */
1324 }
1325 else
1326 {
1327 return (-1);
1328 }
1329 }
1330