home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************/
- /** Copyright 1988 by Evans & Sutherland Computer Corporation, **/
- /** Salt Lake City, Utah **/
- /** **/
- /** All Rights Reserved **/
- /** **/
- /** Permission to use, copy, modify, and distribute this software and **/
- /** its documentation for any purpose and without fee is hereby **/
- /** granted, provided that the above copyright notice appear in all **/
- /** copies and that both that copyright notice and this permis- **/
- /** sion notice appear in supporting documentation, and that the **/
- /** name of Evans & Sutherland not be used in advertising or publi- **/
- /** city pertaining to distribution of the software without specif- **/
- /** ic, written prior permission. **/
- /** **/
- /** EVANS & SUTHERLAND DISCLAIMS ALL WARRANTIES WITH REGARD TO **/
- /** THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI- **/
- /** TY AND FITNESS, IN NO EVENT SHALL EVANS & SUTHERLAND BE LIABLE **/
- /** FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAM- **/
- /** AGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, **/
- /** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS **/
- /** ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PER- **/
- /** FORMANCE OF THIS SOFTWARE. **/
- /*****************************************************************************/
-
- /***********************************************************************
- *
- * $Header: util.c,v 1.10 88/04/15 07:09:43 tlastran Exp $
- *
- * utility routines for twm
- *
- * 28-Oct-87 Thomas E. LaStrange File created
- *
- ***********************************************************************/
-
- #ifndef lint
- static char RCSinfo[]=
- "$Header: util.c,v 1.10 88/04/15 07:09:43 tlastran Exp $";
- #endif
-
- #include <stdio.h>
- #include "twm.h"
- #include "gram.h"
-
- /***********************************************************************
- *
- * Procedure:
- * InitButtons - initialize the title bar buttons
- *
- ***********************************************************************
- */
-
- void
- InitButtons()
- {
- int i;
-
- for (i = 0; i < (MAX_BUTTONS + 1); i++)
- TitleButton[i] = T_NOP;
-
- TitleButton[1] = T_RAISE;
- TitleButton[2] = T_MOVE;
- TitleButton[3] = T_LOWER;
- }
-
- /***********************************************************************
- *
- * Procedure:
- * MoveOutline - move a window outline
- *
- * Inputs:
- * root - the window we are outlining
- * x - upper left x coordinate
- * y - upper left y coordinate
- * width - the width of the rectangle
- * height - the height of the rectangle
- *
- ***********************************************************************
- */
-
- void
- MoveOutline(root, x, y, width, height)
- Window root;
- int x, y, width, height;
- {
- static int lastx = 0;
- static int lasty = 0;
- static int lastWidth = 0;
- static int lastHeight = 0;
- int xl, xr, yt, yb;
- int xthird, ythird;
- XSegment outline[16];
- XSegment *r = outline;
-
- if (x == lastx && y == lasty && width == lastWidth && height == lastHeight)
- return;
-
- xthird = lastWidth/3;
- ythird = lastHeight/3;
- xl = lastx;
- xr = lastx + lastWidth - 1;
- yt = lasty;
- yb = lasty + lastHeight - 1;
-
- if (lastWidth || lastHeight)
- {
- r->x1 = xl;
- r->y1 = yt;
- r->x2 = xr;
- r++->y2 = yt;
-
- r->x1 = xl;
- r->y1 = yb;
- r->x2 = xr;
- r++->y2 = yb;
-
- r->x1 = xl;
- r->y1 = yt;
- r->x2 = xl;
- r++->y2 = yb;
-
- r->x1 = xr;
- r->y1 = yt;
- r->x2 = xr;
- r++->y2 = yb;
-
- r->x1 = xl + xthird;
- r->y1 = yt;
- r->x2 = r->x1;
- r++->y2 = yb;
-
- r->x1 = xl + (2 * xthird);
- r->y1 = yt;
- r->x2 = r->x1;
- r++->y2 = yb;
-
- r->x1 = xl;
- r->y1 = yt + ythird;
- r->x2 = xr;
- r->y2 = r->y1;
- r++;
-
- r->x1 = xl;
- r->y1 = yt + (2 * ythird);
- r->x2 = xr;
- r->y2 = r->y1;
- r++;
- }
-
- lastx = x;
- lasty = y;
- lastWidth = width;
- lastHeight = height;
- xthird = lastWidth/3;
- ythird = lastHeight/3;
- xl = lastx;
- xr = lastx + lastWidth - 1;
- yt = lasty;
- yb = lasty + lastHeight - 1;
-
- if (lastWidth || lastHeight)
- {
- r->x1 = xl;
- r->y1 = yt;
- r->x2 = xr;
- r++->y2 = yt;
-
- r->x1 = xl;
- r->y1 = yb;
- r->x2 = xr;
- r++->y2 = yb;
-
- r->x1 = xl;
- r->y1 = yt;
- r->x2 = xl;
- r++->y2 = yb;
-
- r->x1 = xr;
- r->y1 = yt;
- r->x2 = xr;
- r++->y2 = yb;
-
- r->x1 = xl + xthird;
- r->y1 = yt;
- r->x2 = r->x1;
- r++->y2 = yb;
-
- r->x1 = xl + (2 * xthird);
- r->y1 = yt;
- r->x2 = r->x1;
- r++->y2 = yb;
-
- r->x1 = xl;
- r->y1 = yt + ythird;
- r->x2 = xr;
- r->y2 = r->y1;
- r++;
-
- r->x1 = xl;
- r->y1 = yt + (2 * ythird);
- r->x2 = xr;
- r->y2 = r->y1;
- r++;
- }
- if (r != outline)
- {
- XDrawSegments(dpy, root, DrawGC, outline, r - outline);
- }
- }
-
- /***********************************************************************
- *
- * Procedure:
- * MakePixmap - make a pixmap
- *
- * Returned Value:
- * pid - the pixmap id
- *
- * Inputs:
- * w - the window to associate the pixmap with
- * gc - the graphics context to use
- * data - pointer to the pixmap data
- * width - the width of the pixmap
- * height - the height of the pixmap
- *
- ***********************************************************************
- */
-
- Pixmap
- MakePixmap(w, gc, data, width, height)
- Drawable w;
- GC gc;
- short *data;
- int width, height;
- {
- XImage ximage;
- Pixmap pid;
-
- pid = XCreatePixmap(dpy, w, width, height, DefaultDepth(dpy, 0));
-
- ximage.height = height;
- ximage.width = width;
- ximage.xoffset = 0;
- ximage.format = XYBitmap;
- ximage.data = (char *) data;
- ximage.byte_order = LSBFirst;
- ximage.bitmap_unit = 16;
- ximage.bitmap_bit_order = LSBFirst;
- ximage.bitmap_pad = 16;
- ximage.bytes_per_line = (width + 15) / 16 * 2;
- ximage.depth = 1;
-
- XPutImage(dpy, pid, gc, &ximage, 0, 0, 0, 0, width, height);
- return (pid);
- }
-
- GetUnknownIcon(name)
- char *name;
- {
- int status, junk_hotx, junk_hoty;
-
- status = XReadBitmapFile(dpy, Root, name, &UnknownWidth,
- &UnknownHeight, &UnknownPm, &junk_hotx, &junk_hoty);
-
- switch(status)
- {
- case BitmapSuccess:
- break;
-
- case BitmapFileInvalid:
- fprintf(stderr, ".twmrc: invalid bitmap file\n");
- break;
-
- case BitmapNoMemory:
- fprintf(stderr, ".twmrc: out of memory\n");
- break;
-
- case BitmapOpenFailed:
- fprintf(stderr, ".twmrc: failed to open bitmap file\n");
- break;
-
- default:
- fprintf(stderr,".twmrc: bitmap error = 0x%x\n", status);
- break;
- }
-
- if (status != BitmapSuccess)
- UnknownPm = NULL;
- }
-