1 /* Common code between client and shell widgets -- Xt only.
2 Copyright (C) 1993, 1994 Sun Microsystems, Inc.
4 This file is part of SXEmacs
6 SXEmacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 SXEmacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* Synched up with: Not in FSF. */
22 /* Written by Ben Wing, September 1993. */
28 #ifndef EXTERNAL_WIDGET
29 ERROR ! This ought not be getting compiled if EXTERNAL_WIDGET
32 void fatal(const char *fmt, ...);
34 static void fatal(char *msg);
37 #include <X11/Intrinsic.h>
38 #include <X11/IntrinsicP.h>
41 #include "ui/X11/extw-Xt.h"
43 /* Yeah, that's portable!
45 Why the hell didn't the Xt people just export this function
49 int _XtWaitForSomething(XtAppContext app,
50 _XtBoolean ignoreEvents,
51 _XtBoolean ignoreTimers,
52 _XtBoolean ignoreInputs,
53 _XtBoolean ignoreSignals, _XtBoolean block,
57 unsigned long *howlong);
60 # define _XtwaitForSomething(timers,inputs,events,block,howlong,appCtx) \
61 _XtWaitForSomething(appCtx,events,timers,inputs,0,block,howlong)
63 # define _XtwaitForSomething(timers,inputs,events,block,howlong,appCtx) \
64 _XtWaitForSomething(appCtx,events,timers,inputs,0,block,1,howlong)
67 int _XtwaitForSomething(Boolean ignoreTimers,
71 unsigned long *howlong, XtAppContext app);
76 static int geom_masks[] = {
77 CWX, CWY, CWWidth, CWHeight, CWBorderWidth, CWSibling, CWStackMode,
80 static char *geom_mask_strings[] = {
81 "CWX", "CWY", "CWWidth", "CWHeight", "CWBorderWidth",
82 "CWSibling", "CWStackMode", "XtCWQueryOnly"
84 static int stack_modes[] = {
85 Below, TopIf, BottomIf, Opposite, XtSMDontChange
87 static char *stack_mode_strings[] = {
88 "Below", "TopIf", "BottomIf", "Opposite", "XtSMDontChange"
91 static void print_geometry_structure(XtWidgetGeometry * xwg)
93 int num = sizeof(geom_masks) / sizeof(int);
97 for (i = 0; i < num; i++)
98 if (xwg->request_mode & geom_masks[i])
99 printf(" %s", geom_mask_strings[i]);
101 printf(" x:%d y:%d\n", xwg->x, xwg->y);
102 printf(" width:%d height:%d border_width:%d\n", xwg->width,
103 xwg->height, xwg->border_width);
104 printf(" sibling: %x\n", xwg->sibling);
105 printf(" stack_mode: ");
106 for (i = 0, num = sizeof(stack_modes) / sizeof(int); i < num; i++)
107 if (xwg->stack_mode == stack_modes[i]) {
108 printf("%s", stack_mode_strings[i]);
114 static void print_geometry_result(XtGeometryResult res)
116 printf("result: %s\n",
117 res == XtGeometryYes ? "XtGeometryYes" :
118 res == XtGeometryNo ? "XtGeometryNo" :
119 res == XtGeometryAlmost ? "XtGeometryAlmost" :
120 res == XtGeometryDone ? "XtGeometryDone" : "unknown");
127 static void fatal(char *msg)
129 fprintf(stderr, "%s", msg);
135 /* put a geometry specification in the specified property on the window
136 of the specified widget, and send a notification message to tell the
137 client-side widget about this. */
140 extw_send_geometry_value(Display * display, Window win, Atom property,
141 en_extw_notify type, XtWidgetGeometry * xwg,
145 XChangeProperty(display, win, property,
146 a_EXTW_WIDGET_GEOMETRY, 32, PropModeReplace,
147 (unsigned char *)xwg,
148 sizeof(*xwg) / sizeof(int));
149 extw_send_notify_3(display, win, type, data0, 0, 0);
152 /* get the geometry specification stored in the specified property of the
153 specified widget's window. */
156 extw_get_geometry_value(Display * display, Window win, Atom property,
157 XtWidgetGeometry * xwg)
161 unsigned long nitems, bytes_after;
164 if (XGetWindowProperty(display, win, property, 0,
165 sizeof(*xwg) / 4, False, a_EXTW_WIDGET_GEOMETRY,
166 &dummy, &format, &nitems, &bytes_after,
169 if (format != 8 * sizeof(int) || bytes_after) {
173 *xwg = *(XtWidgetGeometry *) prop;
177 fatal("Unable to retrieve property for widget-geometry");
179 XtAppErrorMsg(XtWidgetToApplicationContext((Widget) w),
180 "invalidProperty", "get_geometry_value",
182 "Unable to retrieve property for widget-geometry",
183 (String *) NULL, (Cardinal *) NULL);
189 unsigned long request_num;
193 /* check if an event is of the sort we're looking for */
195 static Bool isMine(Display * dpy, XEvent * event, char *arg)
197 QueryStruct *q = (QueryStruct *) arg;
200 if ((dpy != XtDisplay(w)) || (event->xany.window != XtWindow(w))) {
203 if (event->xany.serial >= q->request_num) {
204 if (event->type == ClientMessage &&
205 event->xclient.message_type == a_EXTW_NOTIFY &&
206 event->xclient.data.l[0] == 1 - extw_which_side &&
207 event->xclient.data.l[1] == q->type)
213 /* wait for a ClientMessage of the specified type from the other widget, or
214 time-out. isMine() determines whether an event matches. Culled from
218 extw_wait_for_response(Widget w, XEvent * event, unsigned long request_num,
219 en_extw_notify type, unsigned long timeout)
221 XtAppContext app = XtWidgetToApplicationContext(w);
224 XFlush(XtDisplay(w));
226 q.request_num = request_num;
231 * look for match event
233 if (XCheckIfEvent(XtDisplay(w), event, isMine, (char *)&q))
235 if (_XtwaitForSomething(TRUE, TRUE, FALSE, TRUE, &timeout, app)