home *** CD-ROM | disk | FTP | other *** search
- /* > $.CLIB.C.windowset
- *
- * HASWIN Graphics Library
- * =========================
- *
- * Copyright (C) H.A.Shaw 1990.
- * Howard A. Shaw.
- * The Unit for Space Sciences,
- * Room 165,
- * Physics Building,
- * University of Kent at Canterbury.
- * Canterbury.
- * Kent. CT2 7NJ
- * You may use and distribute this code freely, however please leave
- * it alone. If you find bugs (and there will be many) please contact
- * me and the master source can be modified. If you keep me informed
- * of who you give copies of this to then I can get release upgrades
- * to them.
- *
- * Routines to get and change things to do with windows.
- */
- #include "includes.h"
-
- int haswin_getwindowxmin(window *win) {
-
- if (((int)win <= 0) || (!win->win))
- return(HASWIN_UNKNOWN);
- return(((int *)(win->win))[0]);
- }
-
- int haswin_getwindowxmax(window *win) {
-
- if (((int)win <= 0) || (!win->win))
- return(HASWIN_UNKNOWN);
- return(((int *)(win->win))[2]);
- }
- int haswin_getwindowymin(window *win) {
-
- if (((int)win <= 0) || (!win->win))
- return(HASWIN_UNKNOWN);
- return(((int *)(win->win))[1]);
- }
-
- int haswin_getwindowymax(window *win) {
-
- if (((int)win <= 0) || (!win->win))
- return(HASWIN_UNKNOWN);
- return(((int *)(win->win))[3]);
- }
-
- int haswin_getwindowxscroll(window *win) {
-
- if (((int)win <= 0) || (!win->win))
- return(HASWIN_UNKNOWN);
- return(((int *)(win->win))[4]);
- }
-
- int haswin_getwindowyscroll(window *win) {
-
- if (((int)win <= 0) || (!win->win))
- return(HASWIN_UNKNOWN);
- return(((int *)(win->win))[5]);
- }
-
- int haswin_getwindowxorigin(window *win) {
-
- if ((int)win <= 0)
- return(HASWIN_UNKNOWN);
- return(win->orgx);
- }
-
- int haswin_getwindowyorigin(window *win) {
-
- if ((int)win <= 0)
- return(HASWIN_UNKNOWN);
- return(win->orgy);
- }
-
- int haswin_getwindowxextent(window *win) {
-
- if (((int)win <= 0) || (!win->win))
- return(HASWIN_UNKNOWN);
- return(((int *)(win->win))[12]);
- }
-
- int haswin_getwindowyextent(window *win) {
-
- if (((int)win <= 0) || (!win->win))
- return(HASWIN_UNKNOWN);
- return(-((int *)(win->win))[11]);
- }
-
- int haswin_getwindowbhandle(window *win) {
-
- if (((int)win <= 0) || (!win->win))
- return(HASWIN_UNKNOWN);
- return(((int *)(win->win))[6]);
- }
-
- int haswin_newwindowflags(window *win, int new) {
-
- if (((int)win <= 0) || (!win->win))
- return(HASWIN_FALSE);
- if (new & WINDOW_WIMPFLAGS) {
- ((int *)(win->win))[7] = ((new & WINDOW_WIMPFLAGS) | WINDOW_FLAGS_OR) & ~WINDOW_FLAGS_AND;
- }
- if (new & (WINDOW_WIMPFLAGS | WINDOW_HASFLAGS)) {
- win->flags = new & WINDOW_HASFLAGS;
- return(HASWIN_TRUE);
- }
- return(HASWIN_FALSE);
- }
-
- int haswin_setwindowflags(window *win, int new) {
-
- if (((int)win <= 0) || (!win->win))
- return(HASWIN_FALSE);
- return(haswin_newwindowflags(win, win->flags | new));
- }
-
- int haswin_clearwindowflags(window *win, int new) {
-
- if (((int)win <= 0) || (!win->win))
- return(HASWIN_FALSE);
- return(haswin_newwindowflags(win, win->flags & ~new));
- }
-
- int haswin_getwindowflags(window *win) {
-
- register int i;
-
- if (((int)win <= 0) || (!win->win))
- return(HASWIN_UNKNOWN);
- i = ((int *)(win->win))[7] & WINDOW_HASWINUSE;
- i &= ~(WINDOW_FLAGS_OR | WINDOW_FLAGS_AND);
- i |= win->flags & WINDOW_HASFLAGS;
- return(i);
- }
-
- int haswin_setwindoworigin(window *win, int x, int y) {
-
- if ((int)win <= 0)
- return(HASWIN_FALSE);
- win->orgx = x;
- win->orgy = y;
- return(HASWIN_TRUE);
- }
-
- /*
- * this routine makes HASWIN's window structure reflect the real
- * WIMP one.
- */
- void haswin_updatewindowinfo(window *win) {
-
- int ptr[9];
- _kernel_swi_regs regs;
- register int i;
-
- if ((int)win <= 0)
- return;
- ptr[0] = win->handle;
- regs.r[1] = (int)ptr;
- if (!haswin_swi(HASWIN_Get_window_state, ®s))
- return;
- for (i=0; i<8; i++)
- ((int *)win->win)[i] = ptr[i+1];
- }
-
- /*
- * this routine copies all of the WIMPs window fields to the HASWIN
- * ones. It can fail catastrophically if the HASWIN library is
- * bypassed when icons are created !!
- */
-
- void haswin_updatefullwindowinfo(window *win) {
-
- int *ptr;
- _kernel_swi_regs regs;
- register int i;
-
- if ((int)win <= 0)
- return;
- ptr = haswin_malloc(sizeof(int)*(23+(win->numicons*8)), "haswin_updatefullwindowinfo", "window block");
- ptr[0] = win->handle;
- regs.r[1] = (int)ptr;
- if (!haswin_swi(HASWIN_Get_window_info, ®s)) {
- return;
- haswin_free(ptr);
- }
- if (win->numicons < ptr[22]) {
- haswin_errorbox("The HASWIN library has had an internal inconsistancy and must exit (updatefullwindowinfo has failed)");
- haswin_exit(1);
- }
- for (i=0; i<22; i++)
- ((int *)win->win)[i] = ptr[i+1];
- haswin_free(ptr);
- }
-
- /*
- * this routine tries to resize the work area of the window. It
- * checks the size and if it is going down it first reopens the
- * window in such a way that the call to Set_extent will not fail.
- * If "redraw" is true then force a complete window redraw.
- */
- int haswin_resizewindow(window *win, int xsize, int ysize, int redraw) {
-
- buffer buff;
- _kernel_swi_regs regs;
- register int *wint, flgs, opens;
-
- if ((int)win <= 0)
- return(HASWIN_TRUE);
- haswin_updatefullwindowinfo(win);
- flgs = haswin_getwindowflags(win);
- wint = (int *)(win->win); /* this assignment speeds things slightly
- and makes the code look neater */
- if (flgs & WINDOW_OPEN) {
- /* the window is being displayed */
- opens = 0;
- if (xsize < wint[2]-wint[0])
- opens |= 1;
- if (ysize < wint[3]-wint[1])
- opens |= 2;
- switch (opens) {
- case 0: /* the window is OK, do nothing */
- break;
- case 1: /* the window is going to be smaller in X */
- haswin_openwindow(win, wint[0], wint[1], wint[0]+xsize, wint[3], wint[4], wint[5], wint[6]);
- break;
- case 2: /* the window is going to be smaller in Y */
- haswin_openwindow(win, wint[0], wint[3]-ysize, wint[2], wint[3], wint[4], wint[5], wint[6]);
- break;
- case 3: /* the window is going to be smaller in X and Y */
- haswin_openwindow(win, wint[0], wint[3]-ysize, wint[0]+xsize, wint[3], wint[4], wint[5], wint[6]);
- break;
- }
- }
- buff.i[0] = 0;
- buff.i[1] = -ysize;
- buff.i[2] = xsize;
- buff.i[3] = 0;
- regs.r[0] = win->handle;
- regs.r[1] = (int)&buff;
- if (!haswin_swi(HASWIN_Set_extent, ®s))
- return(HASWIN_FALSE);
- haswin_updatefullwindowinfo(win);
- wint = (int *)(win->win);
- if (redraw)
- haswin_redrawwindow(win,wint[0]-win->orgx,wint[2]-win->orgx,
- wint[1]-win->orgy,wint[3]-win->orgy);
- return((wint[11] == -ysize) && (wint[12] == xsize));
- }
-
-