home *** CD-ROM | disk | FTP | other *** search
- /* > $.CLIB.C.findwindow
- *
- * 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 finds windows given things.
- */
- #include "includes.h"
-
- /*
- * given a window handle find the window structure associated with it.
- */
- window *haswin_findwindowhandle(int handle) {
-
- register window *wptr;
-
- if (handle <= 0)
- return((window *)handle);
- for (wptr=haswin_topwindow; wptr; wptr=wptr->next) {
- if (wptr->handle == handle)
- return(wptr);
- }
- return((window *)0);
- }
-
- /*
- * given a window structure, return the title of the window.
- */
- char *haswin_getwindowtitle(window *wptr) {
-
- int i;
-
- i = (int)wptr;
- switch (i) {
- case -1:
- return("Background");
- break;
- case -2:
- return("Icon Bar");
- break;
- case 0:
- return("Don't know");
- break;
- default:
- if (wptr->win) {
- i = ((int *)wptr->win)[18];
- return((char *)i);
- } else
- return("don't know");
- break;
- }
- }
-
- /*
- * given a window structure, return the name of the window.
- */
- char *haswin_getwindowname(window *wptr) {
-
- int i;
-
- i = (int)wptr;
- switch (i) {
- case -1:
- return("Background");
- break;
- case -2:
- return("Icon Bar");
- break;
- case 0:
- return("Don't know");
- break;
- default:
- return(wptr->name);
- break;
- }
- }
-
- /*
- * given a window name find the window structure associated with it.
- */
- window *haswin_findwindowname(char *name) {
-
- register window *wptr;
- int length;
-
- if (name) {
- length = asciilen(name);
- for (wptr=haswin_topwindow; wptr; wptr=wptr->next) {
- if (!strncmp(name, haswin_getwindowname(wptr), length))
- return(wptr);
- }
- }
- return((window *)0);
- }
-
- /*
- * given a window handle find the master window associated with it.
- */
- window *haswin_findmasterhandle(int handle) {
-
- register window *wptr;
-
- wptr = haswin_findwindowhandle(handle);
- if ((int)wptr > 0)
- return(wptr->master);
- else
- return(wptr);
- }
-
- /*
- * given a window structure find the master window associated with it.
- */
- window *haswin_findmasterwindow(window *win) {
-
- if ((int)win <= 0)
- return(0);
- return(win->master);
- }
-
- /*
- * this routine scans all the windows and returns a list of their
- * WIMP window handles.
- * 1) Create a small window.
- * 2) Open it at the back and off the screen.
- * 3) Use Get_window_state to get the handle of the one in front
- * 4) Record this in given buffer "list".
- * 5) Repeat 3/4 until handle is -1 or length is exceeded.
- * 6) Remove small window.
- * 7) Return number of windows
- */
- int haswin_findallwindows(int *list, int length) {
- window *win;
- buffer buff;
- _kernel_swi_regs regs;
- register int i;
-
- if ((!list) || (length <= 0))
- return(HASWIN_FALSE);
- win = haswin_makewindow("tmp",100,100,0,0,0,0,WINDOW_TRESPASS);
- if (!win)
- return(HASWIN_FALSE);
- haswin_openwindow(win, -200, 200, 100, 300, 0, 0, -2);
- i = 0;
- buff.i[0] = win->handle;
- do {
- regs.r[1] = (int)&buff;
- haswin_swi(HASWIN_Get_window_state, ®s);
- list[i++] = buff.i[0] = buff.i[7];
- } while ((i < length) && (buff.i[7] != -1));
- haswin_deletewindow(win);
- return(i-2);
- }
-
- /*
- * these routines maintain the active windows lists. If a window is
- * not in the active list then it will not be processed by HASWIN poll
- * routines in any way, but will be passed to any user poll routine.
- */
-
- /*
- * search the active windows list for a window handle "whandle"
- * NB: the iconbar windows (whandle < 0) are always in the active list.
- * the null window (whandle == 0) cannot be in the active list.
- * if there is nothing in the activelist then ALL windows are in
- * the active list by default. This means that HASWIN does not
- * have to search the list each time if it is empty, and the default
- * action is to process ALL windows.
- */
- int haswin_inactivelist(int whandle) {
-
- register int i;
-
- if ((haswin_activewindowmax == 0) || (whandle < 0))
- return(HASWIN_TRUE);
- if (whandle == 0)
- return(HASWIN_FALSE);
- for (i=0; i<haswin_activewindowmax; i++) {
- if (haswin_activewindow[i] == whandle)
- return(HASWIN_TRUE);
- }
- return(HASWIN_FALSE);
- }
-
- /*
- * add a new window to the active list.
- */
- int haswin_addactivelist(int whandle) {
-
- if ((whandle <= 0) || (haswin_activewindowmax == HASWIN_ACTIVEMAX-1))
- return(HASWIN_FALSE);
- haswin_activewindow[haswin_activewindowmax++] = whandle;
- return(HASWIN_TRUE);
- }
-
- /*
- * remove a window from the active list
- */
- int haswin_removeactivelist(int whandle) {
-
- register int i;
-
- if ((whandle <= 0) || (haswin_activewindowmax == 0))
- return(HASWIN_FALSE);
- for (i=0; i<haswin_activewindowmax; i++) {
- if (haswin_activewindow[i] == whandle) {
- haswin_activewindowmax--;
- while (i<haswin_activewindowmax) {
- haswin_activewindow[i] = haswin_activewindow[i+1];
- i++;
- }
- return(HASWIN_TRUE);
- }
- }
- return(HASWIN_FALSE);
- }
-
-