|
|
1.1 ! root 1: /* $Header: Message.c,v 1.1 87/09/11 07:58:19 toddb Exp $ */ ! 2: #ifndef lint ! 3: static char *sccsid = "@(#)Message.c 1.4 2/25/87"; ! 4: #endif lint ! 5: ! 6: /* ! 7: * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. ! 8: * ! 9: * All Rights Reserved ! 10: * ! 11: * Permission to use, copy, modify, and distribute this software and its ! 12: * documentation for any purpose and without fee is hereby granted, ! 13: * provided that the above copyright notice appear in all copies and that ! 14: * both that copyright notice and this permission notice appear in ! 15: * supporting documentation, and that the name of Digital Equipment ! 16: * Corporation not be used in advertising or publicity pertaining to ! 17: * distribution of the software without specific, written prior permission. ! 18: * ! 19: * ! 20: * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ! 21: * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL ! 22: * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ! 23: * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, ! 24: * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ! 25: * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS ! 26: * SOFTWARE. ! 27: */ ! 28: ! 29: ! 30: /* Message.c -- send messages and fake events to a widget. */ ! 31: ! 32: #include "Xlib.h" ! 33: #include "Intrinsic.h" ! 34: #include "Atoms.h" ! 35: ! 36: /* ! 37: * Send an event of the given type to the widget. ! 38: */ ! 39: ! 40: XtEventReturnCode XtSendEvent(dpy, w, type) ! 41: Display *dpy; ! 42: Window w; ! 43: unsigned long type; ! 44: { ! 45: XEvent event; ! 46: event.type = type; ! 47: event.xany.display = dpy; ! 48: event.xany.window = w; ! 49: return XtDispatchEvent(&event); ! 50: } ! 51: ! 52: ! 53: /* ! 54: * Tell a widget that its window has been destroyed (or will be very soon). ! 55: */ ! 56: ! 57: XtEventReturnCode XtSendDestroyNotify(dpy, w) ! 58: Display *dpy; ! 59: Window w; ! 60: { ! 61: return XtSendEvent(dpy, w, (unsigned long)DestroyNotify); ! 62: } ! 63: ! 64: ! 65: XtEventReturnCode XtSendConfigureNotify(dpy, w, box) ! 66: Display *dpy; ! 67: Window w; ! 68: WindowBox *box; ! 69: { ! 70: XConfigureEvent event; ! 71: event.type = ConfigureNotify; ! 72: event.display = dpy; ! 73: event.event = event.window = w; ! 74: event.x = box->x; ! 75: event.y = box->y; ! 76: event.width = box->width; ! 77: event.height = box->height; ! 78: event.border_width = box->borderWidth; ! 79: return XtDispatchEvent((XEvent *) &event); ! 80: } ! 81: ! 82: XtEventReturnCode XtSendExpose(dpy, w) ! 83: Display *dpy; ! 84: Window w; ! 85: { ! 86: XEvent event; ! 87: event.type = Expose; ! 88: event.xexpose.display = dpy; ! 89: event.xexpose.window = w; ! 90: event.xexpose.count = 0; ! 91: event.xexpose.x = 0; ! 92: event.xexpose.y = 0; ! 93: event.xexpose.width = 9999; ! 94: event.xexpose.height = 9999; ! 95: return XtDispatchEvent(&event); ! 96: } ! 97: ! 98: ! 99: #ifdef MESSAGES ! 100: ! 101: /* ! 102: * Send a message to a widget. ! 103: */ ! 104: ! 105: XtEventReturnCode XtSendMessage(dpy, w, message, args, argCount) ! 106: Display *dpy; ! 107: Window w; ! 108: XtMessage message; ! 109: ArgList args; ! 110: int argCount; ! 111: { ! 112: XtEvent event; ! 113: event.type = MessageEvent; ! 114: event.display = dpy; ! 115: event.window = w; ! 116: event.message = message; ! 117: event.args = args; ! 118: event.argCount = argCount; ! 119: event.subwindow = NULL; ! 120: return XtDispatchEvent((XEvent *)&event); ! 121: } ! 122: ! 123: /* ! 124: * Get the dimensions of the given window. If it's not yet a widget (or the ! 125: * widget doesn't handle messages), ask the server. Returns nonzero if ! 126: * the window doesn't exist. ! 127: */ ! 128: ! 129: XtStatus XtGetWindowSize(dpy, window, width, height, borderWidth) ! 130: Display *dpy; ! 131: Window window; ! 132: int *width, *height, *borderWidth; ! 133: { ! 134: static Arg args[] = { ! 135: {XtNwidth, (XtArgVal) -1}, ! 136: {XtNheight, (XtArgVal) -1}, ! 137: {XtNborderWidth, (XtArgVal) -1}, ! 138: }; ! 139: Drawable root; ! 140: Dimension x, y; ! 141: unsigned int depth; ! 142: ! 143: args[0].value = args[1].value = args[2].value = (XtArgVal) -1; ! 144: (void) XtSendMessage(dpy, window, messageGETVALUES, args, XtNumber(args)); ! 145: if ((int)args[0].value < 0 || (int)args[1].value < 0 || ! 146: (int)args[2].value < 0) { ! 147: if (!XGetGeometry(dpy, window, &root, &x, &y, ! 148: width, height, borderWidth, &depth)) ! 149: return XtNOTWINDOW; ! 150: } else { ! 151: *width = (int)args[0].value; ! 152: *height = (int)args[1].value; ! 153: *borderWidth = (int)args[2].value; ! 154: } ! 155: return XtSUCCESS; ! 156: } ! 157: ! 158: #endif ! 159: ! 160: /* ! 161: * Get the dimensions of the given window. First ask its geometry manager; ! 162: * if it doesn't have one or the geometry manager is uncooperative, ask ! 163: * the server. Returns nonzero if the window doesn't exist. ! 164: */ ! 165: ! 166: XtGetWindowSize(dpy, window, width, height, borderWidth) ! 167: Display *dpy; ! 168: Window window; ! 169: Dimension *width, *height, *borderWidth; ! 170: { ! 171: WindowBox box; ! 172: Drawable root; ! 173: Position x, y; ! 174: unsigned int depth; ! 175: ! 176: ! 177: if (XtMakeGeometryRequest(dpy, window, XtgeometryGetWindowBox, &box, &box) ! 178: == XtgeometryYes) { ! 179: *width = box.width; ! 180: *height = box.height; ! 181: *borderWidth = box.borderWidth; ! 182: } else { ! 183: if (!XGetGeometry(dpy, window, &root, &x, &y, ! 184: width, height, borderWidth, &depth)) ! 185: return XtNOTWINDOW; ! 186: } ! 187: return XtSUCCESS; ! 188: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.