home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / desktop / d / explain / Apps / c / balloon
Encoding:
Text File  |  1994-05-19  |  3.1 KB  |  115 lines

  1. /* balloon.c */
  2.  
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <stdarg.h>
  6.  
  7. #include "os.h"
  8. #include "swis.h"
  9. #include "wimp.h"
  10. #include "win.h"
  11. #include "intalk.h"
  12. #include "wimpt.h"
  13. #include "msgs.h"
  14.  
  15. #include "misc.h" #include "balloon.h"
  16.  
  17. static BOOL balloon__initdone     = FALSE;
  18. static BOOL balloon__desiredstate = FALSE;
  19. static BOOL balloon__retry;
  20.  
  21. #define balloon__DIRVAR   "Explain$Dir"
  22. #define balloon__STARTCMD ("Run <" balloon__DIRVAR ">")
  23.  
  24. os_error *balloon__err(char *msg, ...)
  25. {  static os_error eb;
  26.    va_list ap;
  27.  
  28.    va_start(ap, msg);
  29.    vsprintf(eb.errmess, msgs_lookup(msg), ap);
  30.    va_end(ap);
  31.  
  32.    return &eb;
  33. }
  34.  
  35. static os_error *balloon__sendfirstmsg(void)
  36. {  intalk_msgstr msg;
  37.  
  38.    msg.hdr.action = intalk_MBALLOONRQSTATE;
  39.    msg.hdr.size   = sizeof(wimp_msghdr) + sizeof(intalk_balloonswitch);
  40.  
  41.    return wimp_sendmessage(wimp_ESENDWANTACK, (wimp_msgstr *) &msg, (wimp_t) 0);
  42. }
  43.  
  44. static BOOL balloon__ukhandler(wimp_eventstr *e, void *handle)
  45. {  os_regset regs;
  46.    intalk_msgstr *msg;
  47.    msg = (intalk_msgstr *) &e->data.msg;
  48.  
  49.    handle = handle;
  50.  
  51.    switch (e->e)
  52.    {  case wimp_ESEND:
  53.       case wimp_ESENDWANTACK:
  54.          switch (e->data.msg.hdr.action)
  55.          {  case intalk_MBALLOONSTATEIS:
  56.                if (balloon__desiredstate == 2)
  57.                   balloon__desiredstate = !msg->data.balloonstateis.show;
  58.                msg->hdr.action = intalk_MBALLOONSWITCH;
  59.                msg->hdr.size   = sizeof(wimp_msghdr) + sizeof(intalk_balloonswitch);
  60.                msg->data.balloonswitch.show = balloon__desiredstate;
  61.                wimpt_complain(wimp_sendmessage(wimp_ESEND, (wimp_msgstr *) msg, msg->hdr.task));
  62.                return TRUE;
  63.          }
  64.          break;
  65.  
  66.       /* Bounced message means !Explain isn't running, so start it and try again */
  67.  
  68.       case wimp_EACK:
  69.          switch (e->data.msg.hdr.action)
  70.          {  case intalk_MBALLOONSWITCH:
  71.             case intalk_MBALLOONRQSTATE:
  72.  
  73.                if (balloon__retry)
  74.                {  wimpt_complain(balloon__err("balloon2"));
  75.                   return TRUE;
  76.                }
  77.                  
  78.                regs.r[0] = (int) balloon__DIRVAR;
  79.                regs.r[1] = NULL;
  80.                regs.r[2] = -1; /* check only */
  81.                regs.r[3] = 0;
  82.                regs.r[4] = 0;
  83.                os_swix(OS_ReadVarVal, ®s);
  84.  
  85.                if (regs.r[2] < 0)
  86.                {  if (!wimpt_complain(wimp_starttask(balloon__STARTCMD)))
  87.                   {  balloon__retry = TRUE;
  88.                      balloon__desiredstate = 1;
  89.                      wimpt_complain(balloon__sendfirstmsg());
  90.                   }
  91.                }
  92.                else
  93.                   wimpt_complain(balloon__err("balloon1"));
  94.                return TRUE;
  95.          }
  96.          break;
  97.    }
  98.    
  99.    return FALSE;
  100. }
  101.  
  102. /* state can be 0 (off), 1 (on) or 2 (toggle current state) */
  103.  
  104. os_error *balloon_switch(int state)
  105. {  if (!balloon__initdone)
  106.    {  win_add_unknown_event_processor(balloon__ukhandler, NULL);
  107.       balloon__initdone = TRUE;
  108.    }
  109.  
  110.    balloon__desiredstate = state;
  111.    balloon__retry        = FALSE;
  112.  
  113.    return balloon__sendfirstmsg();
  114. }
  115.