home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / haswinlib / c / windowset < prev   
Encoding:
Text File  |  1991-02-04  |  7.8 KB  |  254 lines

  1. /* > $.CLIB.C.windowset
  2.  *
  3.  *      HASWIN Graphics Library
  4.  *     =========================
  5.  *
  6.  *      Copyright (C) H.A.Shaw 1990.
  7.  *              Howard A. Shaw.
  8.  *              The Unit for Space Sciences,
  9.  *              Room 165,
  10.  *              Physics Building,
  11.  *              University of Kent at Canterbury.
  12.  *              Canterbury.
  13.  *              Kent.  CT2 7NJ
  14.  *      You may use and distribute this code freely, however please leave
  15.  *      it alone.  If you find bugs (and there will be many) please contact
  16.  *      me and the master source can be modified.  If you keep me informed
  17.  *      of who you give copies of this to then I can get release upgrades
  18.  *      to them.
  19.  *
  20.  *      Routines to get and change things to do with windows.
  21.  */
  22. #include "includes.h"
  23.  
  24. int haswin_getwindowxmin(window *win) {
  25.  
  26.         if (((int)win <= 0) || (!win->win))
  27.                 return(HASWIN_UNKNOWN);
  28.         return(((int *)(win->win))[0]);
  29. }
  30.  
  31. int haswin_getwindowxmax(window *win) {
  32.  
  33.         if (((int)win <= 0) || (!win->win))
  34.                 return(HASWIN_UNKNOWN);
  35.         return(((int *)(win->win))[2]);
  36. }
  37. int haswin_getwindowymin(window *win) {
  38.  
  39.         if (((int)win <= 0) || (!win->win))
  40.                 return(HASWIN_UNKNOWN);
  41.         return(((int *)(win->win))[1]);
  42. }
  43.  
  44. int haswin_getwindowymax(window *win) {
  45.  
  46.         if (((int)win <= 0) || (!win->win))
  47.                 return(HASWIN_UNKNOWN);
  48.         return(((int *)(win->win))[3]);
  49. }
  50.  
  51. int haswin_getwindowxscroll(window *win) {
  52.  
  53.         if (((int)win <= 0) || (!win->win))
  54.                 return(HASWIN_UNKNOWN);
  55.         return(((int *)(win->win))[4]);
  56. }
  57.  
  58. int haswin_getwindowyscroll(window *win) {
  59.  
  60.         if (((int)win <= 0) || (!win->win))
  61.                 return(HASWIN_UNKNOWN);
  62.         return(((int *)(win->win))[5]);
  63. }
  64.  
  65. int haswin_getwindowxorigin(window *win) {
  66.  
  67.         if ((int)win <= 0)
  68.                 return(HASWIN_UNKNOWN);
  69.         return(win->orgx);
  70. }
  71.  
  72. int haswin_getwindowyorigin(window *win) {
  73.  
  74.         if ((int)win <= 0)
  75.                 return(HASWIN_UNKNOWN);
  76.         return(win->orgy);
  77. }
  78.  
  79. int haswin_getwindowxextent(window *win) {
  80.  
  81.         if (((int)win <= 0) || (!win->win))
  82.                 return(HASWIN_UNKNOWN);
  83.         return(((int *)(win->win))[12]);
  84. }
  85.  
  86. int haswin_getwindowyextent(window *win) {
  87.  
  88.         if (((int)win <= 0) || (!win->win))
  89.                 return(HASWIN_UNKNOWN);
  90.         return(-((int *)(win->win))[11]);
  91. }
  92.  
  93. int haswin_getwindowbhandle(window *win) {
  94.  
  95.         if (((int)win <= 0) || (!win->win))
  96.                 return(HASWIN_UNKNOWN);
  97.         return(((int *)(win->win))[6]);
  98. }
  99.  
  100. int haswin_newwindowflags(window *win, int new) {
  101.  
  102.         if (((int)win <= 0) || (!win->win))
  103.                 return(HASWIN_FALSE);
  104.         if (new & WINDOW_WIMPFLAGS) {
  105.                 ((int *)(win->win))[7] = ((new & WINDOW_WIMPFLAGS) | WINDOW_FLAGS_OR) & ~WINDOW_FLAGS_AND;
  106.         }
  107.         if (new & (WINDOW_WIMPFLAGS | WINDOW_HASFLAGS)) {
  108.                 win->flags = new & WINDOW_HASFLAGS;
  109.                 return(HASWIN_TRUE);
  110.         }
  111.         return(HASWIN_FALSE);
  112. }
  113.  
  114. int haswin_setwindowflags(window *win, int new) {
  115.  
  116.         if (((int)win <= 0) || (!win->win))
  117.                 return(HASWIN_FALSE);
  118.         return(haswin_newwindowflags(win, win->flags | new));
  119. }
  120.  
  121. int haswin_clearwindowflags(window *win, int new) {
  122.  
  123.         if (((int)win <= 0) || (!win->win))
  124.                 return(HASWIN_FALSE);
  125.         return(haswin_newwindowflags(win, win->flags & ~new));
  126. }
  127.  
  128. int haswin_getwindowflags(window *win) {
  129.  
  130.         register int    i;
  131.  
  132.         if (((int)win <= 0) || (!win->win))
  133.                 return(HASWIN_UNKNOWN);
  134.         i  = ((int *)(win->win))[7] & WINDOW_HASWINUSE;
  135.         i &= ~(WINDOW_FLAGS_OR | WINDOW_FLAGS_AND);
  136.         i |= win->flags & WINDOW_HASFLAGS;
  137.         return(i);
  138. }
  139.  
  140. int haswin_setwindoworigin(window *win, int x, int y) {
  141.  
  142.         if ((int)win <= 0)
  143.                 return(HASWIN_FALSE);
  144.         win->orgx = x;
  145.         win->orgy = y;
  146.         return(HASWIN_TRUE);
  147. }
  148.  
  149. /*
  150.  *      this routine makes HASWIN's window structure reflect the real
  151.  *      WIMP one.
  152.  */
  153. void haswin_updatewindowinfo(window *win) {
  154.  
  155.         int                     ptr[9];
  156.         _kernel_swi_regs        regs;
  157.         register int            i;
  158.  
  159.         if ((int)win <= 0)
  160.                 return;
  161.         ptr[0] = win->handle;
  162.         regs.r[1] = (int)ptr;
  163.         if (!haswin_swi(HASWIN_Get_window_state, ®s))
  164.                 return;
  165.         for (i=0; i<8; i++)
  166.                 ((int *)win->win)[i] = ptr[i+1];
  167. }
  168.  
  169. /*
  170.  *      this routine copies all of the WIMPs window fields to the HASWIN
  171.  *      ones.  It can fail catastrophically if the HASWIN library is
  172.  *      bypassed when icons are created !!
  173.  */
  174.  
  175. void haswin_updatefullwindowinfo(window *win) {
  176.  
  177.         int                     *ptr;
  178.         _kernel_swi_regs        regs;
  179.         register int            i;
  180.  
  181.         if ((int)win <= 0)
  182.                 return;
  183.         ptr = haswin_malloc(sizeof(int)*(23+(win->numicons*8)), "haswin_updatefullwindowinfo", "window block");
  184.         ptr[0] = win->handle;
  185.         regs.r[1] = (int)ptr;
  186.         if (!haswin_swi(HASWIN_Get_window_info, ®s)) {
  187.                 return;
  188.                 haswin_free(ptr);
  189.         }
  190.         if (win->numicons < ptr[22]) {
  191.                 haswin_errorbox("The HASWIN library has had an internal inconsistancy and must exit (updatefullwindowinfo has failed)");
  192.                 haswin_exit(1);
  193.         }
  194.         for (i=0; i<22; i++)
  195.                 ((int *)win->win)[i] = ptr[i+1];
  196.         haswin_free(ptr);
  197. }
  198.  
  199. /*
  200.  *      this routine tries to resize the work area of the window.  It
  201.  *      checks the size and if it is going down it first reopens the
  202.  *      window in such a way that the call to Set_extent will not fail.
  203.  *      If "redraw" is true then force a complete window redraw.
  204.  */
  205. int haswin_resizewindow(window *win, int xsize, int ysize, int redraw) {
  206.  
  207.         buffer                  buff;
  208.         _kernel_swi_regs        regs;
  209.         register int            *wint, flgs, opens;
  210.  
  211.         if ((int)win <= 0)
  212.                 return(HASWIN_TRUE);
  213.         haswin_updatefullwindowinfo(win);
  214.         flgs = haswin_getwindowflags(win);
  215.         wint = (int *)(win->win);  /* this assignment speeds things slightly
  216.                                       and makes the code look neater */
  217.         if (flgs & WINDOW_OPEN) {
  218.                 /* the window is being displayed */
  219.                 opens = 0;
  220.                 if (xsize < wint[2]-wint[0])
  221.                         opens |= 1;
  222.                 if (ysize < wint[3]-wint[1])
  223.                         opens |= 2;
  224.                 switch (opens) {
  225.                 case 0: /* the window is OK, do nothing */
  226.                         break;
  227.                 case 1: /* the window is going to be smaller in X */
  228.                         haswin_openwindow(win, wint[0], wint[1], wint[0]+xsize, wint[3], wint[4], wint[5], wint[6]);
  229.                         break;
  230.                 case 2: /* the window is going to be smaller in Y */
  231.                         haswin_openwindow(win, wint[0], wint[3]-ysize, wint[2], wint[3], wint[4], wint[5], wint[6]);
  232.                         break;
  233.                 case 3: /* the window is going to be smaller in X and Y */
  234.                         haswin_openwindow(win, wint[0], wint[3]-ysize, wint[0]+xsize, wint[3], wint[4], wint[5], wint[6]);
  235.                         break;
  236.                 }
  237.         }
  238.         buff.i[0] = 0;
  239.         buff.i[1] = -ysize;
  240.         buff.i[2] = xsize;
  241.         buff.i[3] = 0;
  242.         regs.r[0] = win->handle;
  243.         regs.r[1] = (int)&buff;
  244.         if (!haswin_swi(HASWIN_Set_extent, ®s))
  245.                 return(HASWIN_FALSE);
  246.         haswin_updatefullwindowinfo(win);
  247.         wint = (int *)(win->win);
  248.         if (redraw)
  249.                 haswin_redrawwindow(win,wint[0]-win->orgx,wint[2]-win->orgx,
  250.                                         wint[1]-win->orgy,wint[3]-win->orgy);
  251.         return((wint[11] == -ysize) && (wint[12] == xsize));
  252. }
  253.  
  254.