home *** CD-ROM | disk | FTP | other *** search
- /* > $.CLIB.C.poll
- *
- * 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 perform SWI(Wimp_Poll)
- */
- #include "c.poll_h"
- extern pdriver *haswin_pjob;
- static int (*haswin_user)(int, buffer *);
- static int haswin_pollnull = 0;
-
- int haswin_setuserpollroutine(int (*user)(int, buffer *)) {
-
- haswin_user = user;
- return(HASWIN_TRUE);
- }
-
- /*
- * decode the wimp event and perform the code for it
- */
- static int dopollcode(int code, buffer *buff) {
-
- int res = HASWIN_FALSE;
-
- switch (code) {
- case HASWIN_POLL_Nothing:
- haswin_pollnull = 0;
- if (haswin_user)
- res = (*haswin_user)(code, buff);
- break;
- case HASWIN_POLL_Redraw:
- res = haswin_poll_redraw(haswin_user, buff);
- break;
- case HASWIN_POLL_Open:
- res = haswin_poll_open(haswin_user, buff);
- break;
- case HASWIN_POLL_Close:
- if (!haswin_inactivelist(buff->i[0])) {
- if (haswin_user)
- res = (*haswin_user)(code, buff);
- break;
- }
- res = haswin_poll_close(haswin_user, buff);
- break;
- case HASWIN_POLL_Leaving:
- if (!haswin_inactivelist(buff->i[0])) {
- if (haswin_user)
- res = (*haswin_user)(code, buff);
- break;
- }
- res = haswin_poll_leaving(haswin_user, buff);
- break;
- case HASWIN_POLL_Entering:
- if (!haswin_inactivelist(buff->i[0])) {
- if (haswin_user)
- res = (*haswin_user)(code, buff);
- break;
- }
- res = haswin_poll_entering(haswin_user, buff);
- break;
- case HASWIN_POLL_Drag:
- if (!haswin_dragwindow) {
- res = haswin_poll_drag(haswin_user, buff);
- break;
- }
- if (!haswin_inactivelist(haswin_dragwindow->handle)) {
- if (haswin_user)
- res = (*haswin_user)(code, buff);
- break;
- }
- res = haswin_poll_drag(haswin_user, buff);
- break;
- case HASWIN_POLL_Mouse:
- if (!haswin_inactivelist(buff->i[3])) {
- if (haswin_user)
- res = (*haswin_user)(code, buff);
- break;
- }
- res = haswin_poll_mouse(haswin_user, buff);
- break;
- case HASWIN_POLL_Key:
- if (!haswin_inactivelist(buff->i[0])) {
- if (haswin_user)
- res = (*haswin_user)(code, buff);
- break;
- }
- res = haswin_poll_key(haswin_user, buff);
- break;
- case HASWIN_POLL_Menu:
- if (!haswin_menu.actual)
- break;
- if (!haswin_inactivelist(haswin_menu.wfrom)) {
- if (haswin_user)
- res = (*haswin_user)(code, buff);
- break;
- }
- res = haswin_poll_menu(haswin_user, buff);
- break;
- case HASWIN_POLL_Scroll:
- if (!haswin_inactivelist(buff->i[0])) {
- if (haswin_user)
- res = (*haswin_user)(code, buff);
- break;
- }
- res = haswin_poll_scroll(haswin_user, buff);
- break;
- case HASWIN_POLL_Lose_Caret:
- if (!haswin_inactivelist(buff->i[0])) {
- if (haswin_user)
- res = (*haswin_user)(code, buff);
- break;
- }
- res = haswin_poll_lcaret(haswin_user, buff);
- break;
- case HASWIN_POLL_Gane_Caret:
- if (!haswin_inactivelist(buff->i[0])) {
- if (haswin_user)
- res = (*haswin_user)(code, buff);
- break;
- }
- res = haswin_poll_gcaret(haswin_user, buff);
- break;
- case HASWIN_POLL_Message:
- case HASWIN_POLL_Message_Rec:
- case HASWIN_POLL_Message_Ack:
- res = haswin_poll_message(haswin_user, buff);
- break;
- default: /* anything else */
- if (haswin_user)
- res = (*haswin_user)(code, buff);
- break;
- }
- return(res);
- }
-
- /*
- * poll the real WIMP and perform any automatic functions.
- * this returns HASWIN_TRUE if the routine performed ok, and
- * HASWIN_FALSE on null codes, or if something was amiss.
- *
- * We must try to perform some processing. The main problem is
- * double clicking. If we get a mouse pressed event then don't do it.
- * wait for a while, if we get another click then use it, if not then
- * just use the first one followed by whatever we got the second time.
- */
- #define HASWIN_POLL_TIMESTEP 15 /* centi-seconds delay for double */
- /* keypress actions (drag etc.) */
-
- int haswin_poll() {
-
- int timer, code, button, prtjob;
- buffer buff, sbuff;
- window *wptr;
- icon *iptr;
- _kernel_swi_regs regs;
-
- if (!haswin_swi(OS_ReadMonotonicTime, ®s))
- return(HASWIN_FALSE);
- timer = regs.r[0] + HASWIN_POLL_TIMESTEP;
- regs.r[0] = 0;
- regs.r[1] = (int)&buff;
- prtjob = 0;
- if (haswin_flags & HASWIN_FLAGS_PRINTER)
- prtjob = haswin_pdriverselect(0);
- if (haswin_flags & HASWIN_FLAGS_FASTPOLL) {
- /* use SWI(WIMP_poll) to return immediatly */
- if (!haswin_swi(HASWIN_Poll, ®s)) {
- if (prtjob)
- haswin_pdriverselect(prtjob);
- return(HASWIN_FALSE);
- }
- } else {
- /* use SWI(WIMP_pollidle) to increase efficiency */
- regs.r[2] = timer;
- if (!haswin_swi(HASWIN_Poll_idle, ®s)) {
- if (prtjob)
- haswin_pdriverselect(prtjob);
- return(HASWIN_FALSE);
- }
- }
- if (prtjob)
- /* we had a print job going so restart it */
- haswin_pdriverselect(prtjob);
- code = regs.r[0];
- if (code == HASWIN_POLL_Mouse) {
- /*
- * we have a mouse click. If it is a SELECT or ADJUST it
- * could be the first of a double-click or drag so check for
- * these and if the button type allows double actions then
- * call SWI(WIMP_Poll) again.
- */
- wptr=haswin_findwindowhandle(buff.i[3]);
- iptr=haswin_findiconhandle(wptr, buff.i[4]);
- button = haswin_buttonWIMPtoHASWIN(wptr, iptr, buff.i[2]);
- if (((button==HASWIN_MOUSE_L) || (button==HASWIN_MOUSE_R)) &&
- haswin_canbuttondouble(button)) {
- /*
- * mouse action could be double-click or drag
- * so recall SWI(WIMP_Poll) with a time delay
- * and then try again.
- */
- regs.r[0] = 0;
- regs.r[1] = (int)&sbuff;
- timer += HASWIN_POLL_TIMESTEP;
- regs.r[2] = timer;
- if (haswin_flags & HASWIN_FLAGS_PRINTER)
- prtjob = haswin_pdriverselect(0);
- if (!haswin_swi(HASWIN_Poll_idle, ®s)) {
- if (prtjob)
- haswin_pdriverselect(prtjob);
- return(HASWIN_FALSE);
- }
- if (prtjob)
- haswin_pdriverselect(prtjob);
- code = regs.r[0];
- if (code == HASWIN_POLL_Mouse)
- return(dopollcode(code, &sbuff));
- /*
- * got something not a keypress, try the
- * original keypress first, and then the
- * new action
- */
- dopollcode(HASWIN_POLL_Mouse, &buff);
- return(dopollcode(HASWIN_POLL_Mouse, &sbuff));
- }
- }
- return(dopollcode(code, &buff));
- }
-
- /*
- * continue to poll until a NULL event is processed. Poll fast.
- */
- int haswin_pollcomplete(void) {
- int flgs, ans;
-
- flgs = haswin_flags;
- haswin_flags &= ~HASWIN_FLAGS_FASTPOLL;
- haswin_pollnull++;
- while (haswin_pollnull)
- ans=haswin_poll();
- haswin_flags |= flgs & HASWIN_FLAGS_FASTPOLL;
- return(ans);
- }
-
-
-