home *** CD-ROM | disk | FTP | other *** search
- /* > $.CLIB.C.window
- *
- * 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.
- *
- * window creation routines.
- */
- #include "includes.h"
-
- window *haswin_makewindow(char *title, int x, int y, int tf, int tb, int wf, int wb, int flags) {
-
- _kernel_swi_regs regs;
- window *wptr;
-
- if (flags & WINDOW_AUTOTEXT) {
- x = 1 + x/haswin_readvduvariable(VDUVAR_CharXsize);
- x = x*haswin_readvduvariable(VDUVAR_CharXsize);
- y = 1 + y/haswin_readvduvariable(VDUVAR_CharYsize);
- y = y*haswin_readvduvariable(VDUVAR_CharYsize);
- }
- wptr=(window *)haswin_malloc(sizeof(window), "haswin_makewindow", "window structure");
- wptr->win=haswin_malloc(88, "haswin_makewindow", "window");
- ((int *)wptr->win)[ 0] = 0; /* visible area x0 */
- ((int *)wptr->win)[ 1] = -y; /* visible area y0 */
- ((int *)wptr->win)[ 2] = x; /* visible area x1 */
- ((int *)wptr->win)[ 3] = 0; /* visible area y1 */
- ((int *)wptr->win)[ 4] = 0; /* visible area scroll x */
- ((int *)wptr->win)[ 5] = 0; /* visible area scroll y */
- ((int *)wptr->win)[ 6] = -1; /* open on top of stack */
- ((int *)wptr->win)[ 7] =
- ((flags&WINDOW_WIMPFLAGS)|WINDOW_FLAGS_OR) & ~WINDOW_FLAGS_AND;
- /* window flags */
- wptr->win[32] = tf; /* title forground */
- wptr->win[33] = tb; /* title background */
- wptr->win[34] = wf; /* work forground */
- wptr->win[35] = wb; /* work background */
- wptr->win[36] = tb; /* scroll bars fore */
- wptr->win[37] = tf; /* scroll bars back */
- wptr->win[38] = 0; /* selection colour */
- wptr->win[39] = 0;
-
- ((int *)wptr->win)[10] = 0; /* work area x0 */
- ((int *)wptr->win)[11] = -y; /* work area y0 */
- ((int *)wptr->win)[12] = x; /* work area x1 */
- ((int *)wptr->win)[13] = 0; /* work area y1 */
- ((int *)wptr->win)[14] = 0x0000013D; /* title bar icon flags */
- ((int *)wptr->win)[15] = flags & 0x0000F000;
- /* work area button type */
- wptr->button = (flags>>12) & 0x0F;
- /* choose a sprite area control block. */
- /* if a specific area is not chosen, then choose the WIMP +1 area */
- switch (flags & SPRITE_AREA_MASK) {
- case SPRITE_SYSTEM_AREA:
- ((int *)wptr->win)[16] = 0;
- break;
- case SPRITE_WIMP_AREA:
- case SPRITE_RISCOS_AREA:
- ((int *)wptr->win)[16] = 1;
- break;
- case SPRITE_HASWIN_AREA:
- ((int *)wptr->win)[16] = (int)haswin_haswinsprites;
- break;
- case SPRITE_USER_AREA:
- ((int *)wptr->win)[16] = (int)haswin_usersprites;
- break;
- default:
- haswin_interrorprintf("haswin_makewindow: unknown sprite area %8.8X", flags & SPRITE_AREA_MASK);
- /* FALL THRU */
- case 0:
- ((int *)wptr->win)[16] = +1;
- break;
- }
- ((int *)wptr->win)[17] = 0; /* window min width/height */
- ((int *)wptr->win)[18] = (int)haswin_malloc(asciilen(title)+1, "haswin_makewindow:", "window title");
- strcpy((char *)((int *)wptr->win)[18], title);
- ((int *)wptr->win)[19] = -1;
- ((int *)wptr->win)[20] = asciilen(title);
- ((int *)wptr->win)[21] = 0; /* number of icons initially */
- regs.r[1] = (int)wptr->win;
- if (!haswin_swi(HASWIN_Create_window, ®s))
- return(HASWIN_FALSE);
- wptr->handle = regs.r[0];
- haswin_newwindowflags(wptr, flags);
- wptr->orgx = wptr->orgy = 0;
- wptr->mousebutton = (int (*)())0;
- wptr->drawroutine = (int (*)())0;
- wptr->openroutine = (int (*)())0;
- wptr->keyroutine = (int (*)())0;
- wptr->dragroutine = (int (*)())0;
- wptr->name = haswin_malloc(asciilen(title)+1, "haswin_makewindow:", "window name");
- strcpy(wptr->name, title);
- wptr->pointer = (pointer *)0;
- wptr->text = (text *)0;
- wptr->caret = (caret *)0;
- wptr->menu = (menu *)0;
- wptr->scrollx = wptr->scrolly = wptr->pagex = wptr->pagey = 0;
- wptr->numicons = 0;
- wptr->icons = (icon *)0;
- wptr->picture = (char *)0;
- wptr->help = (window *)0;
- wptr->helpmsg = (char *)0;
- wptr->master = wptr; /* window is its own master */
- wptr->next = haswin_topwindow;
- haswin_topwindow = wptr;
- wptr->pane = wptr->slide = (window *)0;
- if (flags & WINDOW_AUTOTEXT) {
- haswin_maketextoverlay(wptr, x/haswin_readvduvariable(VDUVAR_CharXsize),y/haswin_readvduvariable(VDUVAR_CharYsize), wf, wb);
- }
- return(wptr);
- }
-
- window *haswin_makepanewindow(window *top, char *title, int x, int y, int tf, int tb, int wf, int wb, int flags) {
-
- window *win;
-
- if ((win=haswin_makewindow(title, x, y, tf, tb, wf, wb, flags)) == 0)
- return(HASWIN_FALSE);
- win->master = top;
- while (top->pane)
- top=top->pane;
- top->pane = win;
- return(win);
- }
-
- window *haswin_makeslidewindow(window *top, char *title, int x, int y, int tf, int tb, int wf, int wb, int flags) {
-
- window *win;
-
- if ((win=haswin_makewindow(title, x, y, tf, tb, wf, wb, flags)) == 0)
- return(HASWIN_FALSE);
- win->master = top;
- while (top->slide)
- top=top->slide;
- top->slide = win;
- return(win);
- }
-
- /*
- * copy the window pointed to by win.
- * Copy window contents, pointers data areas etc.
- * Create all the icons required.
- */
- window *haswin_copywindow(window *org) {
-
- _kernel_swi_regs regs;
- icon *ic;
- window *wptr;
- int i, master=HASWIN_FALSE;
- char *cptr;
- /*
- * copywindow is recursive, but must keep a global variable for the master
- * window in a pane or slide group. The bit of magic associated with the
- * next two 'static' variables achieves this (I hope).
- */
- static int level = 0;
- static window *masterwin;
-
- if ((int)org <= 0)
- return((window *)0);
- wptr=(window *)haswin_malloc(sizeof(window), "haswin_copywindow", "wptr");
- if (level++ == 0) {
- master = HASWIN_TRUE;
- masterwin = wptr;
- }
- memcpy(wptr, org, sizeof(window));
- /*
- * we have copied all data, including pointers, so recreate
- * pointers in wptr using haswin_malloc as needed.
- */
- wptr->master = masterwin;
- if (org->pointer) {
- /* copy mouse pointer shape to use */
- wptr->pointer = (pointer *)haswin_malloc(sizeof(pointer), "haswin_copywindow", "pointer");
- memcpy(wptr->pointer, org->pointer, sizeof(pointer));
- if (org->pointer->palette)
- wptr->pointer->palette = haswin_malloc(sizeof(palette), "haswin_copywindow", "pointer palette");
-
- memcpy(wptr->pointer->palette, org->pointer->palette, sizeof(palette));
- }
- if (org->text) {
- /* copy text area */
- haswin_maketextoverlay(wptr, org->text->xsize, org->text->ysize, org->text->fcol, org->text->bcol);
- memcpy(wptr->text->text, org->text->text, org->text->xsize*org->text->ysize);
- wptr->text->xposn = org->text->xposn;
- wptr->text->yposn = org->text->yposn;
- wptr->text->fcol = org->text->fcol;
- wptr->text->bcol = org->text->bcol;
- }
- if (org->caret) {
- /* copy caret to use */
- wptr->caret = (caret *)haswin_malloc(sizeof(caret), "haswin_copywindow", "caret");
- memcpy(wptr->caret, org->caret, sizeof(caret));
- }
- if (org->menu) {
- /* copy menu */
- wptr->menu = (menu *)haswin_malloc(sizeof(menu), "haswin_copywindow", "menu");
- memcpy(wptr->menu, org->menu, sizeof(menu));
- if (org->menu->menu) {
- wptr->menu->menu = (char *)haswin_malloc(asciilen(org->menu->menu)+1, "haswin_copywindow", "menu data");
- strcpy(wptr->menu->menu, org->menu->menu);
- }
- wptr->menu->actual = 0;
- wptr->menu->ifrom = -1;
- wptr->menu->wfrom = org->handle;
- }
- if (org->name) {
- /*
- * copy window name
- */
- wptr->name = (char *)haswin_malloc(asciilen(org->name)+1, "haswin_copywindow", "window name");
- strcpy(wptr->name, org->name);
- }
- /*
- * create window WINDOW structure
- */
- wptr->win = (char *)haswin_malloc(92+(org->numicons*32), "haswin_copywindow", "window win block");
- /*
- * get window WINDOW structure contents from WIMP
- */
- ((int *)wptr->win)[0] = org->handle;
- regs.r[1] = (int)wptr->win;
- haswin_swi(HASWIN_Get_window_info, ®s);
- if (((int *)wptr->win)[22] != org->numicons) {
- /*
- * there might have been icons defined in the window
- * since the original creation that we don't know about
- * (user not using haswin_ routines! )If so we might have
- * just overwritten something important with the SWI.
- */
- haswin_errorbox("The HASWIN library has had an internal inconsistancy and must exit (haswin_copywindow)");
- haswin_exit(HASWIN_FALSE);
- }
- /*
- * move the window structure along the buffer an integer
- */
- for (i=0; i<22+(org->numicons*8); i++)
- ((int *)wptr->win)[i] = ((int *)wptr->win)[i+1];
- /*
- * make the window flags correct
- */
- ((int *)(wptr->win))[7] = ((((int *)wptr->win)[7] & WINDOW_WIMPFLAGS) | WINDOW_FLAGS_OR) & WINDOW_FLAGS_AND;
- /*
- * now we actually create the new, copied window
- */
- regs.r[1] = (int)wptr->win;
- if (!haswin_swi(HASWIN_Create_window, ®s)) {
- /* we have failed to create the window, clear up */
- haswin_free(wptr->win);
- if (wptr->name)
- haswin_free(wptr->name);
- if (wptr->menu) {
- if (wptr->menu->menu)
- haswin_free(wptr->menu->menu);
- haswin_free(wptr->menu);
- }
- if (wptr->caret)
- haswin_free(wptr->caret);
- if (wptr->pointer) {
- if (wptr->pointer->palette)
- haswin_free(wptr->pointer->palette);
- haswin_free(wptr->pointer);
- }
- haswin_free(wptr);
- return(0);
- }
- wptr->handle = regs.r[0];
- /*
- * add the icon definitions to the internal icons list
- */
- wptr->icons = (icon *)0;
- for (i=0; i<wptr->numicons; i++) {
- ic=(icon *)haswin_malloc(sizeof(struct icon), "haswin_copywindow", "icon");
- ic->whandle = wptr->handle;
- ic->ihandle = i;
- ic->ic = (int *)&(wptr->win[88+i*32]);
- ic->window = (window *)0;
- ic->menu = (menu *)0;
- ic->mousebutton = (int (*)())0;
- ic->dragroutine = (int (*)())0;
- ic->flags = 0;
- ic->help = (window *)0;
- wptr->helpmsg = (char *)0;
- ic->next = wptr->icons;
- wptr->icons = ic;
- cptr=haswin_geticontitle(ic);
- ic->name = (char *)haswin_malloc(asciilen(cptr)+1, "haswin_copywindow", "icon name");
- strcpy(ic->name, cptr);
- }
- if (org->picture) {
- /*
- * the copied window must contain a graphic, so copy it
- */
- wptr->picture = (char *)haswin_mallocblock(0, ((int *)org->picture)[-1], "haswin_copywindow", "picture");
- strncpy(wptr->picture, org->picture, ((int *)org->picture)[-1]);
- } else
- wptr->picture = (char *)0;
- wptr->next = haswin_topwindow;
- haswin_topwindow = wptr;
- if (org->pane)
- wptr->pane = haswin_copywindow(org->pane);
- if (org->slide)
- wptr->slide = haswin_copywindow(org->slide);
- if (master)
- level = 0;
- return(wptr);
- }
-
- void haswin_deletewindow(window *wptr) {
-
- window *wtmp;
- _kernel_swi_regs regs;
- buffer buff;
-
- if ((int)wptr <= 0)
- return;
- buff.i[0] = wptr->handle;
- regs.r[1] = (int)&buff;
- if (!haswin_swi(HASWIN_Delete_window, ®s))
- return;
- if (wptr->picture) {
- if (!haswin_freeblock(wptr->picture))
- haswin_internalerror("haswin_deletewindow: haswin_free fails 1");
- wptr->picture = 0;
- }
- if (wptr == haswin_topwindow)
- haswin_topwindow = wptr->next;
- else {
- /* scan the windows list looking for the one before wptr */
- wtmp = haswin_topwindow;
- while ((wtmp) && (wtmp->next != wptr))
- wtmp = wtmp->next;
- /* de-link wptr from the linked list */
- if (wtmp)
- wtmp->next = wptr->next;
- }
- if (!haswin_free(wptr))
- haswin_internalerror("haswin_deletewindow: haswin_free fails 2");
- }
-
- /*
- * restrict the mouse to the window given.
- * Release the mouse if win == 0.
- */
- int haswin_holdmousetowindow(window *win) {
-
- _kernel_swi_regs regs;
- buffer buff;
- int left, bott, rite, topp;
-
- if ((int)win <= 0) {
- left = bott = 0x8000;
- rite = topp = 0x7FFF;
- } else {
- /* if the window is not open then return HASWIN_FALSE */
- haswin_updatewindowinfo(win);
- if ((haswin_getwindowflags(win) & WINDOW_OPEN) == 0)
- return(HASWIN_FALSE);
- /* get the bounding box size for the window */
- buff.i[0] = win->handle;
- regs.r[1] = (int)&buff;
- if (!haswin_swi(HASWIN_Get_window_outline, ®s))
- return(HASWIN_FALSE);
- left = buff.i[1];
- bott = buff.i[2];
- rite = buff.i[3];
- topp = buff.i[4];
- }
- /* use OS_Word to set the mouse rectangle */
- buff.c[0] = 1;
- buff.c[1] = left & 0xFF;
- buff.c[2] = (left >> 8) & 0xFF;
- buff.c[3] = bott & 0xFF;
- buff.c[4] = (bott >> 8) & 0xFF;
- buff.c[5] = rite & 0xFF;
- buff.c[6] = (rite >> 8) & 0xFF;
- buff.c[7] = topp & 0xFF;
- buff.c[8] = (topp >> 8) & 0xFF;
- regs.r[0] = 21;
- regs.r[1] = (int)&buff;
- return(haswin_swi(OS_Word, ®s));
- }
-
- /*
- * convert window and x to a real screen x coord.
- */
- int haswin_convertwinxtoscr(window *wptr, int x) {
-
- register int *iptr;
-
- if ((int)wptr <= 0)
- return(x);
- haswin_updatewindowinfo(wptr);
- iptr = (int *)wptr->win;
- x += iptr[0]-iptr[4];
- if (x < iptr[0])
- x = iptr[0];
- else if (x > iptr[2])
- x = iptr[2];
- return(x+wptr->orgx);
- }
-
- /*
- * convert window and y to a real screen y coord.
- */
- int haswin_convertwinytoscr(window *wptr, int y) {
-
- register int *iptr;
-
- if ((int)wptr <= 0)
- return(y);
- haswin_updatewindowinfo(wptr);
- iptr = (int *)wptr->win;
- y += iptr[3]-iptr[5];
- if (y < iptr[1])
- y = iptr[1];
- else if (y > iptr[3])
- y = iptr[3];
- return(y+wptr->orgy);
- }
-
- /*
- * convert window and x,y to a real screen x,y pair.
- */
- int haswin_convertwinxytoscr(window *wptr, int *x, int *y) {
-
- register int *iptr;
-
- if ((int)wptr <= 0)
- return(HASWIN_FALSE);
- haswin_updatewindowinfo(wptr);
- iptr = (int *)wptr->win;
- *x += iptr[0]-iptr[4];
- if (*x < iptr[0])
- *x = iptr[0];
- else if (*x > iptr[2])
- *x = iptr[2];
- *x += wptr->orgx;
- *y += iptr[3]-iptr[5];
- if (*y < iptr[1])
- *y = iptr[1];
- else if (*y > iptr[3])
- *y = iptr[3];
- *y += wptr->orgy;
- return(HASWIN_TRUE);
- }
-
- /*
- * convert a real screen x coord and a window to the offset in the
- * window.
- */
- int haswin_convertscrxtowin(window *wptr, int x) {
-
- register int *iptr;
-
- if ((int)wptr <= 0)
- return(x);
- haswin_updatewindowinfo(wptr);
- iptr = (int *)wptr->win;
- if (x < iptr[0])
- x = iptr[0];
- else if (x > iptr[2])
- x = iptr[2];
- x -= iptr[0]-iptr[4];
- return(x-wptr->orgx);
- }
-
- /*
- * convert a real screen y coord and a window to the offset in the
- * window.
- */
- int haswin_convertscrytowin(window *wptr, int y) {
-
- register int *iptr;
-
- if ((int)wptr <= 0)
- return(y);
- haswin_updatewindowinfo(wptr);
- iptr = (int *)wptr->win;
- if (y < iptr[1])
- y = iptr[1];
- else if (y > iptr[3])
- y = iptr[3];
- y -= iptr[3]-iptr[5];
- return(y-wptr->orgy);
- }
-
- /*
- * convert a real screen x,y pair and a window to the offset in the
- * window.
- */
- int haswin_convertscrxytowin(window *wptr, int *x, int *y) {
-
- register int *iptr;
-
- if ((int)wptr <= 0)
- return(HASWIN_FALSE);
- haswin_updatewindowinfo(wptr);
- iptr = (int *)wptr->win;
- if (*x < iptr[0])
- *x = iptr[0];
- else if (*x > iptr[2])
- *x = iptr[2];
- *x -= (iptr[0]-iptr[4])+wptr->orgx;
- if (*y < iptr[1])
- *y = iptr[1];
- else if (*y > iptr[3])
- *y = iptr[3];
- *y -= (iptr[3]-iptr[5]) + wptr->orgy;
- return(HASWIN_TRUE);
- }
-
-