home *** CD-ROM | disk | FTP | other *** search
- /* balloon.c */
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <stdarg.h>
-
- #include "os.h"
- #include "swis.h"
- #include "wimp.h"
- #include "win.h"
- #include "intalk.h"
- #include "wimpt.h"
- #include "msgs.h"
-
- #include "misc.h" #include "balloon.h"
-
- static BOOL balloon__initdone = FALSE;
- static BOOL balloon__desiredstate = FALSE;
- static BOOL balloon__retry;
-
- #define balloon__DIRVAR "Explain$Dir"
- #define balloon__STARTCMD ("Run <" balloon__DIRVAR ">")
-
- os_error *balloon__err(char *msg, ...)
- { static os_error eb;
- va_list ap;
-
- va_start(ap, msg);
- vsprintf(eb.errmess, msgs_lookup(msg), ap);
- va_end(ap);
-
- return &eb;
- }
-
- static os_error *balloon__sendfirstmsg(void)
- { intalk_msgstr msg;
-
- msg.hdr.action = intalk_MBALLOONRQSTATE;
- msg.hdr.size = sizeof(wimp_msghdr) + sizeof(intalk_balloonswitch);
-
- return wimp_sendmessage(wimp_ESENDWANTACK, (wimp_msgstr *) &msg, (wimp_t) 0);
- }
-
- static BOOL balloon__ukhandler(wimp_eventstr *e, void *handle)
- { os_regset regs;
- intalk_msgstr *msg;
- msg = (intalk_msgstr *) &e->data.msg;
-
- handle = handle;
-
- switch (e->e)
- { case wimp_ESEND:
- case wimp_ESENDWANTACK:
- switch (e->data.msg.hdr.action)
- { case intalk_MBALLOONSTATEIS:
- if (balloon__desiredstate == 2)
- balloon__desiredstate = !msg->data.balloonstateis.show;
- msg->hdr.action = intalk_MBALLOONSWITCH;
- msg->hdr.size = sizeof(wimp_msghdr) + sizeof(intalk_balloonswitch);
- msg->data.balloonswitch.show = balloon__desiredstate;
- wimpt_complain(wimp_sendmessage(wimp_ESEND, (wimp_msgstr *) msg, msg->hdr.task));
- return TRUE;
- }
- break;
-
- /* Bounced message means !Explain isn't running, so start it and try again */
-
- case wimp_EACK:
- switch (e->data.msg.hdr.action)
- { case intalk_MBALLOONSWITCH:
- case intalk_MBALLOONRQSTATE:
-
- if (balloon__retry)
- { wimpt_complain(balloon__err("balloon2"));
- return TRUE;
- }
-
- regs.r[0] = (int) balloon__DIRVAR;
- regs.r[1] = NULL;
- regs.r[2] = -1; /* check only */
- regs.r[3] = 0;
- regs.r[4] = 0;
- os_swix(OS_ReadVarVal, ®s);
-
- if (regs.r[2] < 0)
- { if (!wimpt_complain(wimp_starttask(balloon__STARTCMD)))
- { balloon__retry = TRUE;
- balloon__desiredstate = 1;
- wimpt_complain(balloon__sendfirstmsg());
- }
- }
- else
- wimpt_complain(balloon__err("balloon1"));
- return TRUE;
- }
- break;
- }
-
- return FALSE;
- }
-
- /* state can be 0 (off), 1 (on) or 2 (toggle current state) */
-
- os_error *balloon_switch(int state)
- { if (!balloon__initdone)
- { win_add_unknown_event_processor(balloon__ukhandler, NULL);
- balloon__initdone = TRUE;
- }
-
- balloon__desiredstate = state;
- balloon__retry = FALSE;
-
- return balloon__sendfirstmsg();
- }
-