Mercurial > hg > xemacs-beta
annotate src/extw-Xt.c @ 5935:d5eb0914ca1f cygwin
trial of E1 and UE1
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Sat, 12 Dec 2015 21:49:31 +0000 |
parents | 2aa9cd456ae7 |
children |
rev | line source |
---|---|
0 | 1 /* Common code between client and shell widgets -- Xt only. |
2 Copyright (C) 1993, 1994 Sun Microsystems, Inc. | |
3 | |
5405
2aa9cd456ae7
Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
4331
diff
changeset
|
4 This library is free software: you can redistribute it and/or modify it |
2aa9cd456ae7
Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
4331
diff
changeset
|
5 under the terms of the GNU General Public License as published by the |
2aa9cd456ae7
Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
4331
diff
changeset
|
6 Free Software Foundation, either version 3 of the License, or (at your |
2aa9cd456ae7
Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
4331
diff
changeset
|
7 option) any later version. |
0 | 8 |
5405
2aa9cd456ae7
Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
4331
diff
changeset
|
9 This library is distributed in the hope that it will be useful, but WITHOUT |
2aa9cd456ae7
Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
4331
diff
changeset
|
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2aa9cd456ae7
Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
4331
diff
changeset
|
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2aa9cd456ae7
Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
4331
diff
changeset
|
12 for more details. |
0 | 13 |
5405
2aa9cd456ae7
Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
4331
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
2aa9cd456ae7
Move src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents:
4331
diff
changeset
|
15 along with this library. If not, see <http://www.gnu.org/licenses/>. */ |
0 | 16 |
17 /* Synched up with: Not in FSF. */ | |
18 | |
19 /* Written by Ben Wing, September 1993. */ | |
20 | |
21 #ifdef emacs | |
22 | |
23 #include <config.h> | |
24 | |
25 #ifndef EXTERNAL_WIDGET | |
26 ERROR! This ought not be getting compiled if EXTERNAL_WIDGET is undefined | |
27 #endif | |
28 | |
2110 | 29 EXTERN_C void fatal (const char *fmt, ...); |
0 | 30 #else /* not emacs */ |
31 static void fatal (char *msg); | |
32 #endif | |
33 | |
34 #include <X11/Intrinsic.h> | |
35 #include <X11/IntrinsicP.h> | |
36 #include <stdlib.h> | |
37 #include <stdio.h> | |
4331
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
38 #include "compiler.h" |
0 | 39 #include "extw-Xt.h" |
40 | |
41 #ifdef DEBUG_WIDGET | |
42 | |
43 static int geom_masks[] = { | |
44 CWX, CWY, CWWidth, CWHeight, CWBorderWidth, CWSibling, CWStackMode, | |
45 XtCWQueryOnly }; | |
46 static char *geom_mask_strings[] = { | |
47 "CWX", "CWY", "CWWidth", "CWHeight", "CWBorderWidth", | |
48 "CWSibling", "CWStackMode", "XtCWQueryOnly" }; | |
49 static int stack_modes[] = { | |
50 Below, TopIf, BottomIf, Opposite, XtSMDontChange }; | |
51 static char *stack_mode_strings[] = { | |
52 "Below", "TopIf", "BottomIf", "Opposite", "XtSMDontChange" }; | |
53 | |
54 static void | |
55 print_geometry_structure(XtWidgetGeometry *xwg) | |
56 { | |
57 int num = sizeof(geom_masks)/sizeof(int); | |
58 int i; | |
2108 | 59 |
0 | 60 printf (" masks:"); |
61 for (i=0; i<num; i++) | |
62 if (xwg->request_mode & geom_masks[i]) | |
63 printf (" %s", geom_mask_strings[i]); | |
64 printf ("\n"); | |
65 printf (" x:%d y:%d\n", xwg->x, xwg->y); | |
66 printf (" width:%d height:%d border_width:%d\n", xwg->width, | |
67 xwg->height, xwg->border_width); | |
68 printf (" sibling: %x\n", xwg->sibling); | |
69 printf (" stack_mode: "); | |
70 for (i=0, num=sizeof(stack_modes)/sizeof(int); i<num; i++) | |
71 if (xwg->stack_mode == stack_modes[i]) { | |
72 printf ("%s", stack_mode_strings[i]); | |
73 break; | |
74 } | |
75 printf ("\n"); | |
76 } | |
77 | |
78 static void | |
79 print_geometry_result (XtGeometryResult res) | |
80 { | |
81 printf ("result: %s\n", | |
82 res == XtGeometryYes ? "XtGeometryYes" : | |
83 res == XtGeometryNo ? "XtGeometryNo" : | |
84 res == XtGeometryAlmost ? "XtGeometryAlmost" : | |
85 res == XtGeometryDone ? "XtGeometryDone" : | |
86 "unknown"); | |
87 } | |
88 | |
89 #endif | |
90 | |
91 #ifndef emacs | |
92 | |
93 static void | |
94 fatal (char *msg) | |
95 { | |
96 fprintf (stderr, "%s", msg); | |
97 exit (1); | |
98 } | |
99 | |
100 #endif | |
101 | |
102 /* put a geometry specification in the specified property on the window | |
103 of the specified widget, and send a notification message to tell the | |
104 client-side widget about this. */ | |
105 | |
106 void | |
107 extw_send_geometry_value(Display *display, Window win, Atom property, | |
108 en_extw_notify type, XtWidgetGeometry *xwg, | |
109 long data0) | |
110 { | |
111 if (xwg != NULL) | |
112 XChangeProperty(display, win, property, | |
113 a_EXTW_WIDGET_GEOMETRY, 32, PropModeReplace, | |
114 (unsigned char *) xwg, sizeof(*xwg)/sizeof(int)); | |
115 extw_send_notify_3(display, win, type, data0, 0, 0); | |
116 } | |
117 | |
118 /* get the geometry specification stored in the specified property of the | |
119 specified widget's window. */ | |
120 | |
121 void | |
122 extw_get_geometry_value(Display *display, Window win, Atom property, | |
123 XtWidgetGeometry *xwg) | |
124 { | |
125 Atom dummy; | |
126 int format; | |
127 unsigned long nitems, bytes_after; | |
128 unsigned char *prop; | |
2108 | 129 |
0 | 130 if (XGetWindowProperty(display, win, property, 0, |
131 sizeof(*xwg)/4, False, a_EXTW_WIDGET_GEOMETRY, | |
132 &dummy, &format, &nitems, &bytes_after, | |
133 &prop) != Success) | |
134 goto error; | |
135 if (format != 8*sizeof(int) || bytes_after) { | |
136 XFree((char *) prop); | |
137 goto error; | |
138 } | |
139 *xwg = * (XtWidgetGeometry *) prop; | |
140 return; | |
141 | |
142 error: | |
143 fatal("Unable to retrieve property for widget-geometry"); | |
144 #if 0 | |
145 XtAppErrorMsg(XtWidgetToApplicationContext((Widget)w), | |
146 "invalidProperty","get_geometry_value",XtCXtToolkitError, | |
147 "Unable to retrieve property for widget-geometry", | |
148 (String *)NULL, (Cardinal *)NULL); | |
149 #endif | |
150 } | |
151 | |
4331
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
152 typedef struct |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
153 { |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
154 Widget w; |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
155 unsigned long request_num; |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
156 en_extw_notify type; |
0 | 157 } QueryStruct; |
158 | |
159 /* check if an event is of the sort we're looking for */ | |
160 | |
161 static Bool | |
4331
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
162 isMine(XEvent *event, QueryStruct *q) |
0 | 163 { |
4331
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
164 Widget w = q->w; |
2108 | 165 |
4331
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
166 if ( (event->xany.display != XtDisplay(w)) || (event->xany.window != XtWindow(w)) ) |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
167 { |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
168 return FALSE; |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
169 } |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
170 if (event->xany.serial >= q->request_num) |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
171 { |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
172 if (event->type == ClientMessage && |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
173 event->xclient.message_type == a_EXTW_NOTIFY && |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
174 event->xclient.data.l[0] == 1 - extw_which_side && |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
175 event->xclient.data.l[1] == (int) q->type) |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
176 { |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
177 return TRUE; |
0 | 178 } |
4331
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
179 } |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
180 return FALSE; |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
181 } |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
182 |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
183 void responseTimeOut(XtPointer clientData, XtIntervalId * UNUSED (id)) |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
184 { |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
185 Bool *expired=(Bool *)clientData; |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
186 *expired=TRUE; |
0 | 187 } |
188 | |
189 /* wait for a ClientMessage of the specified type from the other widget, or | |
4331
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
190 time-out. isMine() determines whether an event matches. |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
191 Took out the call to _XtWaitForSomething and replaced it with public |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
192 Xt api's. |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
193 */ |
0 | 194 |
195 Bool | |
2108 | 196 extw_wait_for_response (Widget w, XEvent *event, unsigned long request_num, |
197 en_extw_notify type, unsigned long timeout) | |
0 | 198 { |
2108 | 199 XtAppContext app = XtWidgetToApplicationContext(w); |
4331
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
200 XtInputMask inputMask; |
2108 | 201 QueryStruct q; |
4331
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
202 Bool expired; |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
203 XtIntervalId id; |
2108 | 204 |
205 q.w = w; | |
206 q.request_num = request_num; | |
207 q.type = type; | |
4331
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
208 expired=FALSE; |
0 | 209 |
4331
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
210 id=XtAppAddTimeOut(app, timeout, responseTimeOut,&expired); |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
211 while (!expired) |
2108 | 212 { |
4331
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
213 inputMask=XtAppPending(app); |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
214 if (inputMask & XtIMXEvent) |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
215 { |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
216 XtAppNextEvent(app, event); |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
217 if (isMine(event,&q)) |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
218 { |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
219 if (!expired) XtRemoveTimeOut(id); |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
220 return True; |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
221 } |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
222 else |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
223 { |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
224 /* Do Nothing and go back to waiting */ |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
225 } |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
226 } |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
227 if (inputMask & XtIMTimer) |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
228 { |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
229 /* Process the expired timer */ |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
230 XtAppProcessEvent(app,XtIMTimer); |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
231 } |
2108 | 232 } |
4331
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
233 /* Must have expired */ |
4fbcce3f6097
Don't use undocumented Xt functions in external widget.
Mike Sperber <sperber@deinprogramm.de>
parents:
2114
diff
changeset
|
234 return False; |
0 | 235 } |