home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume15 / twm / part02 / util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-12  |  6.8 KB  |  290 lines

  1. /*****************************************************************************/
  2. /**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
  3. /**                          Salt Lake City, Utah                           **/
  4. /**                                                                         **/
  5. /**                           All Rights Reserved                           **/
  6. /**                                                                         **/
  7. /**    Permission to use, copy, modify, and distribute this software and    **/
  8. /**    its documentation  for  any  purpose  and  without  fee is hereby    **/
  9. /**    granted, provided that the above copyright notice appear  in  all    **/
  10. /**    copies and that both  that  copyright  notice  and  this  permis-    **/
  11. /**    sion  notice appear in supporting  documentation,  and  that  the    **/
  12. /**    name  of Evans & Sutherland  not be used in advertising or publi-    **/
  13. /**    city pertaining to distribution  of the software without  specif-    **/
  14. /**    ic, written prior permission.                                        **/
  15. /**                                                                         **/
  16. /**    EVANS  & SUTHERLAND  DISCLAIMS  ALL  WARRANTIES  WITH  REGARD  TO    **/
  17. /**    THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI-    **/
  18. /**    TY AND FITNESS, IN NO EVENT SHALL EVANS &  SUTHERLAND  BE  LIABLE    **/
  19. /**    FOR  ANY  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAM-    **/
  20. /**    AGES  WHATSOEVER RESULTING FROM  LOSS OF USE,  DATA  OR  PROFITS,    **/
  21. /**    WHETHER   IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS    **/
  22. /**    ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE  OR PER-    **/
  23. /**    FORMANCE OF THIS SOFTWARE.                                           **/
  24. /*****************************************************************************/
  25.  
  26. /***********************************************************************
  27.  *
  28.  * $Header: util.c,v 1.10 88/04/15 07:09:43 tlastran Exp $
  29.  *
  30.  * utility routines for twm
  31.  *
  32.  * 28-Oct-87 Thomas E. LaStrange    File created
  33.  *
  34.  ***********************************************************************/
  35.  
  36. #ifndef lint
  37. static char RCSinfo[]=
  38. "$Header: util.c,v 1.10 88/04/15 07:09:43 tlastran Exp $";
  39. #endif
  40.  
  41. #include <stdio.h>
  42. #include "twm.h"
  43. #include "gram.h"
  44.  
  45. /***********************************************************************
  46.  *
  47.  *  Procedure:
  48.  *    InitButtons - initialize the title bar buttons
  49.  *
  50.  ***********************************************************************
  51.  */
  52.  
  53. void
  54. InitButtons()
  55. {
  56.     int i;
  57.  
  58.     for (i = 0; i < (MAX_BUTTONS + 1); i++)
  59.     TitleButton[i] = T_NOP;
  60.  
  61.     TitleButton[1] = T_RAISE;
  62.     TitleButton[2] = T_MOVE;
  63.     TitleButton[3] = T_LOWER;
  64. }
  65.  
  66. /***********************************************************************
  67.  *
  68.  *  Procedure:
  69.  *    MoveOutline - move a window outline
  70.  *
  71.  *  Inputs:
  72.  *    root        - the window we are outlining
  73.  *    x        - upper left x coordinate
  74.  *    y        - upper left y coordinate
  75.  *    width        - the width of the rectangle
  76.  *    height        - the height of the rectangle
  77.  *
  78.  ***********************************************************************
  79.  */
  80.  
  81. void
  82. MoveOutline(root, x, y, width, height)
  83.     Window root;
  84.     int x, y, width, height;
  85. {
  86.     static int    lastx = 0;
  87.     static int    lasty = 0;
  88.     static int    lastWidth = 0;
  89.     static int    lastHeight = 0;
  90.     int        xl, xr, yt, yb;
  91.     int        xthird, ythird;
  92.     XSegment    outline[16];
  93.     XSegment    *r = outline;
  94.  
  95.     if (x == lastx && y == lasty && width == lastWidth && height == lastHeight)
  96.     return;
  97.     
  98.     xthird = lastWidth/3;
  99.     ythird = lastHeight/3;
  100.     xl = lastx;
  101.     xr = lastx + lastWidth - 1;
  102.     yt = lasty;
  103.     yb = lasty + lastHeight - 1;
  104.  
  105.     if (lastWidth || lastHeight)
  106.     {
  107.     r->x1 = xl;
  108.     r->y1 = yt;
  109.     r->x2 = xr;
  110.     r++->y2 = yt;
  111.  
  112.     r->x1 = xl;
  113.     r->y1 = yb;
  114.     r->x2 = xr;
  115.     r++->y2 = yb;
  116.  
  117.     r->x1 = xl;
  118.     r->y1 = yt;
  119.     r->x2 = xl;
  120.     r++->y2 = yb;
  121.  
  122.     r->x1 = xr;
  123.     r->y1 = yt;
  124.     r->x2 = xr;
  125.     r++->y2 = yb;
  126.  
  127.     r->x1 = xl + xthird;
  128.     r->y1 = yt;
  129.     r->x2 = r->x1;
  130.     r++->y2 = yb;
  131.  
  132.     r->x1 = xl + (2 * xthird);
  133.     r->y1 = yt;
  134.     r->x2 = r->x1;
  135.     r++->y2 = yb;
  136.  
  137.     r->x1 = xl;
  138.     r->y1 = yt + ythird;
  139.     r->x2 = xr;
  140.     r->y2 = r->y1;
  141.     r++;
  142.  
  143.     r->x1 = xl;
  144.     r->y1 = yt + (2 * ythird);
  145.     r->x2 = xr;
  146.     r->y2 = r->y1;
  147.     r++;
  148.     }
  149.  
  150.     lastx = x;
  151.     lasty = y;
  152.     lastWidth = width;
  153.     lastHeight = height;
  154.     xthird = lastWidth/3;
  155.     ythird = lastHeight/3;
  156.     xl = lastx;
  157.     xr = lastx + lastWidth - 1;
  158.     yt = lasty;
  159.     yb = lasty + lastHeight - 1;
  160.  
  161.     if (lastWidth || lastHeight)
  162.     {
  163.     r->x1 = xl;
  164.     r->y1 = yt;
  165.     r->x2 = xr;
  166.     r++->y2 = yt;
  167.  
  168.     r->x1 = xl;
  169.     r->y1 = yb;
  170.     r->x2 = xr;
  171.     r++->y2 = yb;
  172.  
  173.     r->x1 = xl;
  174.     r->y1 = yt;
  175.     r->x2 = xl;
  176.     r++->y2 = yb;
  177.  
  178.     r->x1 = xr;
  179.     r->y1 = yt;
  180.     r->x2 = xr;
  181.     r++->y2 = yb;
  182.  
  183.     r->x1 = xl + xthird;
  184.     r->y1 = yt;
  185.     r->x2 = r->x1;
  186.     r++->y2 = yb;
  187.  
  188.     r->x1 = xl + (2 * xthird);
  189.     r->y1 = yt;
  190.     r->x2 = r->x1;
  191.     r++->y2 = yb;
  192.  
  193.     r->x1 = xl;
  194.     r->y1 = yt + ythird;
  195.     r->x2 = xr;
  196.     r->y2 = r->y1;
  197.     r++;
  198.  
  199.     r->x1 = xl;
  200.     r->y1 = yt + (2 * ythird);
  201.     r->x2 = xr;
  202.     r->y2 = r->y1;
  203.     r++;
  204.     }
  205.     if (r != outline)
  206.     {
  207.     XDrawSegments(dpy, root, DrawGC, outline, r - outline);
  208.     }
  209. }
  210.  
  211. /***********************************************************************
  212.  *
  213.  *  Procedure:
  214.  *    MakePixmap - make a pixmap
  215.  *
  216.  *  Returned Value:
  217.  *    pid    - the pixmap id
  218.  *
  219.  *  Inputs:
  220.  *    w    - the window to associate the pixmap with
  221.  *    gc    - the graphics context to use
  222.  *    data    - pointer to the pixmap data
  223.  *    width    - the width of the pixmap
  224.  *    height    - the height of the pixmap
  225.  *
  226.  ***********************************************************************
  227.  */
  228.  
  229. Pixmap
  230. MakePixmap(w, gc, data, width, height)
  231.     Drawable w;
  232.     GC gc;
  233.     short *data;
  234.     int width, height;
  235. {
  236.     XImage ximage;
  237.     Pixmap pid;
  238.  
  239.     pid = XCreatePixmap(dpy, w, width, height, DefaultDepth(dpy, 0));
  240.  
  241.     ximage.height = height;
  242.     ximage.width = width;
  243.     ximage.xoffset = 0;
  244.     ximage.format = XYBitmap;
  245.     ximage.data = (char *) data;
  246.     ximage.byte_order = LSBFirst;
  247.     ximage.bitmap_unit = 16;
  248.     ximage.bitmap_bit_order = LSBFirst;
  249.     ximage.bitmap_pad = 16;
  250.     ximage.bytes_per_line = (width + 15) / 16 * 2;
  251.     ximage.depth = 1;
  252.  
  253.     XPutImage(dpy, pid, gc, &ximage, 0, 0, 0, 0, width, height);
  254.     return (pid);
  255. }
  256.  
  257. GetUnknownIcon(name)
  258. char *name;
  259. {
  260.     int status, junk_hotx, junk_hoty;
  261.  
  262.     status = XReadBitmapFile(dpy, Root, name, &UnknownWidth,
  263.     &UnknownHeight, &UnknownPm, &junk_hotx, &junk_hoty);
  264.  
  265.     switch(status)
  266.     {
  267.     case BitmapSuccess:
  268.         break;
  269.  
  270.     case BitmapFileInvalid:
  271.         fprintf(stderr, ".twmrc: invalid bitmap file\n");
  272.         break;
  273.  
  274.     case BitmapNoMemory:
  275.         fprintf(stderr, ".twmrc: out of memory\n");
  276.         break;
  277.  
  278.     case BitmapOpenFailed:
  279.         fprintf(stderr, ".twmrc: failed to open bitmap file\n");
  280.         break;
  281.  
  282.     default:
  283.         fprintf(stderr,".twmrc: bitmap error = 0x%x\n", status);
  284.         break;
  285.     }
  286.  
  287.     if (status != BitmapSuccess)
  288.     UnknownPm = NULL;
  289. }
  290.