1 /*
2  * $Id: xichiran.c,v 1.2 2001/06/14 18:16:13 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 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 <string.h>
41 #include "commonhd.h"
42 #include "sdefine.h"
43 #include "xjutil.h"
44 #include "sxheader.h"
45 #include "xext.h"
46 #include "rk_spclval.h"
47 #include "rk_fundecl.h"
48 
49 void
resize_text(text)50 resize_text (text)
51      register JutilTextRec *text;
52 {
53   XMoveResizeWindow (dpy, text->w, 0, 0, FontWidth * (text->maxcolumns + 1), FontHeight);
54   XMoveResizeWindow (dpy, text->wn[0], 0, 0, FontWidth, FontHeight);
55   XMoveResizeWindow (dpy, text->wn[1], (text->width - FontWidth), 0, FontWidth, FontHeight);
56   XMoveResizeWindow (dpy, text->wn[2], (text->width - FontWidth), 0, FontWidth, FontHeight);
57   XSetWindowBackground (dpy, text->w, cur_root->bg);
58   XSetWindowBackground (dpy, text->wn[0], cur_root->bg);
59   XSetWindowBackground (dpy, text->wn[1], cur_root->bg);
60   XSetWindowBackground (dpy, text->wn[2], cur_root->bg);
61   XClearWindow (dpy, text->w);
62   XClearWindow (dpy, text->wn[0]);
63   XClearWindow (dpy, text->wn[1]);
64   XClearWindow (dpy, text->wn[2]);
65 }
66 
67 void
xw_mousemove(event)68 xw_mousemove (event)
69      XMotionEvent *event;
70 {
71   register Ichiran *ichi = cur_root->ichi;
72 
73   if (!ichi->lock && xjutil->mode & ICHIRAN_MODE)
74     {
75       if (ichi->mode == SENTAKU)
76         {
77           xw_move_hilite (event->y);
78         }
79       else
80         {
81           xw_jikouho_move_hilite (event->x, event->y);
82         }
83     }
84 }
85 
86 void
init_keytable(kosuu,title)87 init_keytable (kosuu, title)
88      int kosuu;
89      unsigned char *title[];
90 {
91   int cnt;
92   int len, x, y;
93   int width, height, x_cood, y_cood;
94   Window root, child;
95   int win_x, win_y;
96   unsigned int keys_buttons;
97   int save_x, save_y;
98   Keytable *keytable = cur_root->ichi->keytable;
99 
100   keytable->map = 0;
101 
102   x = FontWidth * 2;
103   y = FontHeight / 2 - IN_BORDER;
104   height = FontHeight + IN_BORDER * 2;
105   keytable->cnt = kosuu;
106   for (cnt = 0; cnt < kosuu; cnt++)
107     {
108       len = columnlen (title[cnt]);
109       keytable->button[cnt]->string = title[cnt];
110       moveresize_box (keytable->button[cnt], x, y, (FontWidth * len + IN_BORDER * 2), height);
111       map_box (keytable->button[cnt]);
112       x += FontWidth * (len + 2) + IN_BORDER * 2;
113     }
114   width = x;
115   height = FontHeight * 2;
116 
117   XQueryPointer (dpy, cur_root->root_window, &root, &child, &save_x, &save_y, &win_x, &win_y, &keys_buttons);
118   keytable->save_p.x = (short) save_x;
119   keytable->save_p.y = (short) save_y;
120   decide_position (width, height, cur_root->bw, &x_cood, &y_cood);
121   XWarpPointer (dpy, None, cur_root->root_window, 0, 0, 0, 0, x_cood + width / 2, y_cood + FontHeight);
122 
123   XMoveResizeWindow (dpy, keytable->w, x_cood, y_cood, width, height);
124   set_wm_properties (keytable->w, x_cood, y_cood, width, height, CenterGravity, NULL, NULL, 0, 0, 0, 0, 0);
125   XRaiseWindow (dpy, keytable->w);
126   XMapWindow (dpy, keytable->w);
127   XFlush (dpy);
128 }
129 
130 void
end_keytable()131 end_keytable ()
132 {
133   int cnt;
134   Keytable *keytable = cur_root->ichi->keytable;
135 
136   for (cnt = 0; cnt < keytable->cnt; cnt++)
137     {
138       unmap_box (keytable->button[cnt]);
139     }
140   XUnmapWindow (dpy, keytable->w);
141   if (keytable->save_p.x > -1)
142     XWarpPointer (dpy, None, cur_root->root_window, 0, 0, 0, 0, keytable->save_p.x, keytable->save_p.y);
143   XFlush (dpy);
144   keytable->cnt = 0;
145   xjutil->sel_ret = -1;
146 }
147 
148 void
xw_expose(event)149 xw_expose (event)
150      register XExposeEvent *event;
151 {
152   register int i;
153   Ichiran *ichi = cur_root->ichi;
154   JutilRec *jutil = cur_root->jutil;
155   Window window = event->window;
156   BoxRec *p;
157 
158   for (p = box_list; p != NULL; p = p->next)
159     {
160       if (window == p->window)
161         {
162           redraw_box (p);
163           return;
164         }
165     }
166   if (xjutil->mode & ICHIRAN_MODE)
167     {
168       if (window == ichi->w1)
169         {
170           redraw_ichi_w ();
171           return;
172         }
173       else if (window == ichi->nyuu_w)
174         {
175           JW3Mputc (ichi->nyuu, ichi->nyuu_w, 0, 1, 0);
176           return;
177         }
178     }
179   if (xjutil->mode & JUTIL_MODE)
180     {
181       for (i = 0; i < jutil->max_mes; i++)
182         {
183           if (jutil->mes_text[i]->w == window)
184             {
185               redraw_text (jutil->mes_text[i], event->x, event->width);
186               return;
187             }
188           else if (jutil->mes_text[i]->wn[0] == window)
189             {
190               redraw_note (jutil->mes_text[i], 0);
191               return;
192             }
193           else if (jutil->mes_text[i]->wn[1] == window)
194             {
195               redraw_note (jutil->mes_text[i], 1);
196               return;
197             }
198         }
199     }
200   return;
201 }
202 
203 /* *INDENT-OFF* */
204 Status
xw_buttonpress(event)205 xw_buttonpress (event)
206      XButtonEvent *event;
207 /* *INDENT-ON* */
208 
209 {
210   Ichiran *ichi = cur_root->ichi;
211   Window window = event->window;
212   BoxRec *p;
213 
214   xjutil->sel_ret = -1;
215   if (xjutil->mode & JUTIL_MODE)
216     {
217       p = cur_root->jutil->button[EXEC_W];
218       if (window == p->window)
219         {
220           xjutil->sel_ret = p->sel_ret;
221           if (p->cb)
222             (*p->cb) (p->cb_data);
223           return (p->do_ret);
224         }
225     }
226   for (p = box_list; p != NULL; p = p->next)
227     {
228       if (window == p->window)
229         {
230           if (p->freeze)
231             return (False);
232           xjutil->sel_ret = p->sel_ret;
233           if (p->cb)
234             (*p->cb) (p->cb_data);
235           return (p->do_ret);
236         }
237     }
238 
239   if (xjutil->mode & ICHIRAN_MODE)
240     {
241       if (window == ichi->w1 && !ichi->lock)
242         {
243           xjutil->sel_ret = 1;
244           xw_select_button (event);
245           return (True);
246         }
247     }
248   return (False);
249 }
250 
251 int
jutil_mode_set(mes)252 jutil_mode_set (mes)
253      int mes;
254 {
255   cur_root->jutil->mode = mes;
256   return (0);
257 }
258 
259 void
xw_enterleave(event,el)260 xw_enterleave (event, el)
261      XCrossingEvent *event;
262      char el;
263 {
264   register Ichiran *ichi = cur_root->ichi;
265   register Window window = event->window;
266   register BoxRec *p;
267 /*
268     register int i;
269     register BoxRec *pp;
270     register JutilRec *jutil = cur_root->jutil;
271 
272     if (xjutil->mode & JUTIL_MODE && jutil->max_mes > 1) {
273         for (i = 0; i < jutil->max_mes; i++) {
274             p = jutil->mes_button[i];
275             if (window == p->window) {
276                 if (p->freeze) return;
277                 if (el && !p->in) {
278                     changecolor_box(p, 0, 0, cur_root->fg, BoxBorderPixel);
279                     for (i = 0; i < jutil->max_mes; i++) {
280                         pp = jutil->mes_button[i];
281                         if (pp != p && pp->in) {
282                             changecolor_box(pp, 0, 0, cur_root->bg,
283                                             BoxBorderPixel);
284                             pp->in = (char)0;
285                         }
286                     }
287                     p->in = (char)1;
288                 }
289                 return;
290             }
291         }
292     }
293 */
294   for (p = box_list; p != NULL; p = p->next)
295     {
296       if (window == p->window)
297         {
298           if (p->freeze)
299             return;
300           if (p->reverse && el != p->in)
301             {
302               reverse_box (p, cur_root->invertgc);
303               p->in = el;
304               return;
305             }
306         }
307     }
308 
309   if (xjutil->mode & ICHIRAN_MODE)
310     {
311       if (window == ichi->w1 && !ichi->lock)
312         {
313           if (el)
314             {
315               xw_mousemove (event);
316             }
317           else
318             {
319               xw_mouseleave ();
320             }
321         }
322     }
323   return;
324 }
325