0
|
1 /*
|
|
2 * $Id: box.c,v 1.2 2001/06/14 18:16:14 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 "commonhd.h"
|
|
41 #include "sdefine.h"
|
|
42 #ifdef XJUTIL
|
|
43 #include "xjutil.h"
|
|
44 #include "sxheader.h"
|
|
45 #include "xext.h"
|
|
46 #else /* XJUTIL */
|
|
47 #include "xim.h"
|
|
48 #include "sheader.h"
|
|
49 #include "ext.h"
|
|
50 #endif /* XJUTIL */
|
|
51
|
|
52 BoxRec *
|
|
53 create_box (parent, x, y, width, height, bw, fg, bg, bp, cursor, rev)
|
|
54 Window parent;
|
|
55 int x, y;
|
|
56 int width, height;
|
|
57 int bw;
|
|
58 unsigned long fg, bg, bp;
|
|
59 Cursor cursor;
|
|
60 char rev;
|
|
61 {
|
|
62 register BoxRec *box;
|
|
63 XGCValues xgcv;
|
|
64
|
|
65 if ((box = (BoxRec *) Malloc (sizeof (BoxRec))) == NULL)
|
|
66 {
|
|
67 malloc_error ("allocation of box struct");
|
|
68 return (NULL);
|
|
69 }
|
|
70 box->x = x;
|
|
71 box->y = y;
|
|
72 box->width = width;
|
|
73 box->height = height;
|
|
74 box->border_width = bw;
|
|
75 box->fg = fg;
|
|
76 box->bg = bg;
|
|
77 box->bp = bp;
|
|
78 box->redraw_cb = NULL;
|
|
79 box->redraw_cb_data = NULL;
|
|
80 box->cb = NULL;
|
|
81 box->cb_data = NULL;
|
|
82 box->do_ret = False;
|
|
83 box->sel_ret = -1;
|
|
84 box->reverse = rev;
|
|
85 box->in = box->map = '\0';
|
|
86 box->freeze = '\0';
|
|
87 box->next = NULL;
|
|
88 box->window = XCreateSimpleWindow (dpy, parent, (x - bw), (y - bw), width, height, bw, bp, bg);
|
|
89 xgcv.foreground = fg;
|
|
90 xgcv.function = GXinvert;
|
|
91 xgcv.plane_mask = XOR (fg, bg);
|
|
92 box->invertgc = XCreateGC (dpy, box->window, (GCForeground | GCFunction | GCPlaneMask), &xgcv);
|
|
93 if (!box->window || !box->invertgc)
|
|
94 {
|
|
95 print_out ("Could not create X resources for box.");
|
|
96 Free ((char *) box);
|
|
97 return (NULL);
|
|
98 }
|
|
99
|
|
100 if (cursor)
|
|
101 XDefineCursor (dpy, box->window, cursor);
|
|
102 if (rev)
|
|
103 {
|
|
104 XSelectInput (dpy, box->window, (ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | ExposureMask));
|
|
105 }
|
|
106 else
|
|
107 {
|
|
108 XSelectInput (dpy, box->window, (ButtonPressMask | ButtonReleaseMask | ExposureMask));
|
|
109 }
|
|
110 box->next = box_list;
|
|
111 box_list = box;
|
|
112 return (box);
|
|
113 }
|
|
114
|
|
115 int
|
|
116 remove_box (b)
|
|
117 register BoxRec *b;
|
|
118 {
|
|
119 register BoxRec *p, **prev;
|
|
120 for (prev = &box_list; p = *prev; prev = &p->next)
|
|
121 {
|
|
122 if (p == b)
|
|
123 {
|
|
124 *prev = p->next;
|
|
125 XFreeGC (dpy, p->invertgc);
|
|
126 Free ((char *) p);
|
|
127 return (0);
|
|
128 }
|
|
129 }
|
|
130 return (-1);
|
|
131 }
|
|
132
|
|
133 void
|
|
134 map_box (p)
|
|
135 register BoxRec *p;
|
|
136 {
|
|
137 XMapWindow (dpy, p->window);
|
|
138 p->map = 1;
|
|
139 }
|
|
140
|
|
141 void
|
|
142 unmap_box (p)
|
|
143 register BoxRec *p;
|
|
144 {
|
|
145 XUnmapWindow (dpy, p->window);
|
|
146 p->map = '\0';
|
|
147 p->in = '\0';
|
|
148 }
|
|
149
|
|
150 void
|
|
151 freeze_box (p)
|
|
152 register BoxRec *p;
|
|
153 {
|
|
154 p->freeze = 1;
|
|
155 }
|
|
156
|
|
157 void
|
|
158 unfreeze_box (p)
|
|
159 register BoxRec *p;
|
|
160 {
|
|
161 p->freeze = '\0';
|
|
162 }
|
|
163
|
|
164 void
|
|
165 moveresize_box (p, x, y, width, height)
|
|
166 register BoxRec *p;
|
|
167 int x, y;
|
|
168 int width, height;
|
|
169 {
|
|
170 p->x = x;
|
|
171 p->y = y;
|
|
172 p->width = width;
|
|
173 p->height = height;
|
|
174 XMoveResizeWindow (dpy, p->window, (x - p->border_width), (y - p->border_width), width, height);
|
|
175 }
|
|
176
|
|
177 void
|
|
178 changecolor_box (p, fg, bg, bp, flg)
|
|
179 register BoxRec *p;
|
|
180 unsigned long fg, bg, bp;
|
|
181 unsigned long flg;
|
|
182 {
|
|
183 XGCValues xgcv;
|
|
184
|
|
185 if ((flg & BoxBackground) && (bg != p->bg))
|
|
186 {
|
|
187 p->bg = bg;
|
|
188 XSetWindowBackground (dpy, p->window, p->bg);
|
|
189 xgcv.background = bg;
|
|
190 xgcv.plane_mask = XOR (p->fg, p->bg);
|
|
191 XChangeGC (dpy, p->invertgc, (GCPlaneMask | GCBackground), &xgcv);
|
|
192 XClearWindow (dpy, p->window);
|
|
193 }
|
|
194 if ((flg & BoxForeground) && (fg != p->fg))
|
|
195 {
|
|
196 p->fg = fg;
|
|
197 xgcv.foreground = fg;
|
|
198 xgcv.plane_mask = XOR (p->fg, p->bg);
|
|
199 XChangeGC (dpy, p->invertgc, (GCPlaneMask | GCForeground), &xgcv);
|
|
200 }
|
|
201 if ((flg & BoxBorderPixel) && (bp != p->bp))
|
|
202 {
|
|
203 p->bp = bp;
|
|
204 XSetWindowBorder (dpy, p->window, p->bp);
|
|
205 }
|
|
206 }
|
|
207
|
|
208 void
|
|
209 redraw_box (p)
|
|
210 register BoxRec *p;
|
|
211 {
|
|
212 XClearWindow (dpy, p->window);
|
|
213 /*
|
|
214 JW3Mputc(p->string, p->window, 0, (int)p->in, IN_BORDER);
|
|
215 */
|
|
216 JW3Mputc (p->string, p->window, 0, 0, IN_BORDER);
|
|
217 if (p->in)
|
|
218 reverse_box (p, p->invertgc);
|
|
219 }
|
|
220
|
|
221 void
|
|
222 reverse_box (p, invertgc)
|
|
223 register BoxRec *p;
|
|
224 GC invertgc;
|
|
225 {
|
|
226 XFillRectangle (dpy, p->window, invertgc, 0, 0, p->width, p->height);
|
|
227 }
|
|
228
|
|
229 void
|
|
230 change_reverse_box (p, rev)
|
|
231 register BoxRec *p;
|
|
232 char rev;
|
|
233 {
|
|
234 if (rev)
|
|
235 {
|
|
236 XSelectInput (dpy, p->window, (ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | ExposureMask));
|
|
237 }
|
|
238 else
|
|
239 {
|
|
240 XSelectInput (dpy, p->window, (ButtonPressMask | ButtonReleaseMask | ExposureMask));
|
|
241 }
|
|
242 p->reverse = rev;
|
|
243 }
|