home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / v / vista / c / task < prev    next >
Text File  |  1996-02-01  |  36KB  |  1,323 lines

  1. // **************************************************************************
  2. //                     Copyright 1996 David Allison
  3. //
  4. //             VV    VV    IIIIII     SSSSS     TTTTTT       AA
  5. //             VV    VV      II      SS           TT       AA  AA
  6. //             VV    VV      II        SSSS       TT      AA    AA
  7. //              VV  VV       II           SS      TT      AAAAAAAA
  8. //                VV       IIIIII     SSSS        TT      AA    AA
  9. //
  10. //                    MULTI-THREADED C++ WIMP CLASS LIBRARY
  11. //                                for RISC OS
  12. // **************************************************************************
  13. //
  14. //             P U B L I C    D O M A I N    L I C E N C E
  15. //             -------------------------------------------
  16. //
  17. //     This library is copyright. You may not sell the library for
  18. //     profit, but you may sell products which use it providing
  19. //     those products are presented as executable code and are not
  20. //     libraries themselves.  The library is supplied without any
  21. //     warranty and the copyright owner cannot be held responsible for
  22. //     damage resulting from failure of any part of this library.
  23. //
  24. //          See the User Manual for details of the licence.
  25. //
  26. // *************************************************************************
  27.  
  28.  
  29.  
  30. //
  31. // c.task
  32. //
  33.  
  34. #include "Vista:task.h"
  35. #include <kernel.h>
  36. #include <swis.h>
  37. #include <stdio.h>
  38. #include <string.h>
  39. #include <stdarg.h>
  40. #include <stdlib.h>
  41. #include <signal.h>
  42. #include <setjmp.h>
  43.  
  44.  
  45.  
  46. ControlThread::ControlThread(Task *t, int event, int *buf)
  47.    : Thread ("control")
  48.    {
  49.    task = t ;
  50.    next = NULL ;
  51.    init (event, buf) ;
  52.    }
  53.  
  54. ControlThread::~ControlThread()
  55.    {
  56.    }
  57.  
  58. void ControlThread::init(int event, int *buf)
  59.    {
  60.    this->event = event ;
  61.    memcpy (this->buf, buf, sizeof (this->buf)) ;
  62.    }
  63.  
  64. void ControlThread::run()
  65.    {
  66.    int caught = 0 ;
  67.    Window *w ;
  68.    _kernel_oserror err ;
  69.    _kernel_oserror *e ;
  70.    _kernel_swi_regs r ;
  71.    int adjust_hit ;                 // adjust was hit on menu
  72.    Object *object ;
  73. #ifdef __EASY_C
  74.    try
  75. #endif
  76.       {
  77.       switch (event)
  78.          {
  79.          case Task::ENULL:
  80.             break ;
  81.          case Task::EREDRAW:             /* this is handled as a special case */
  82. #if 0
  83.             w = task->find_window (buf[0]) ;
  84.             if (w == NULL)
  85.                break ;
  86.             w->redraw() ;
  87. #endif
  88.             break ;
  89.          case Task::EOPEN:
  90.             w = task->find_window (buf[0]) ;
  91.             if (w == NULL)
  92.                break ;
  93.             w->open(buf[1],buf[2],buf[3],buf[4], buf[5], buf[6], buf[7]) ;
  94.             break ;
  95.          case Task::ECLOSE:
  96.             w = task->find_window (buf[0]) ;
  97.             if (w == NULL)
  98.                break ;
  99.             w->close() ;
  100.             break ;
  101.          case Task::EPTRLEAVE:
  102.          case Task::EPTRENTER:
  103.             w = task->find_window (buf[0]) ;
  104.             if (w == NULL)
  105.                break ;
  106.             w->pointer (event == Task::EPTRENTER) ;
  107.             break ;
  108.          case Task::EBUT:
  109.             if (buf[3] >= 0)           // in a window?
  110.                {
  111.                w = task->find_window (buf[3]) ;             // find the window
  112.                if (w == NULL)
  113.                   break ;
  114.                if (buf[2] & Task::BMID)                     // menu button?
  115.                   {
  116.                   Icon *icon ;
  117.                   bool found = false ;
  118.                   if (buf[4] != -1 && (icon = w->find_icon(buf[4])) != NULL)   // find icon
  119.                      {
  120.                      task->current_menu = icon->display_menu (buf[0], buf[1], buf[2], buf[4]) ;
  121.                      if (task->current_menu != NULL)
  122.                         {
  123.                         found = true ;
  124.                         task->current_menu_icon = icon ;
  125.                         }
  126.                      }
  127.                   if (!found && (object = w->find_object (buf[0], buf[1])) != NULL) // find object
  128.                      {
  129.                      task->current_menu = object->display_menu (buf[0], buf[1], buf[2], buf[4]) ;
  130.                      if (task->current_menu != NULL)
  131.                         {
  132.                         found = true ;
  133.                         task->current_menu_object = object ;
  134.                         }
  135.                      }
  136.                   if (!found)
  137.                      {
  138.                      task->current_menu = w->display_menu (buf[0], buf[1], buf[2], buf[4]) ;
  139.                      task->current_menu_window = w ;
  140.                      }
  141.                   }
  142.                else
  143.                   {
  144.                   if (buf[4] != -1)         // on an icon?
  145.                      {
  146.                      Icon *icon ;
  147.                      if ((icon = w->find_icon(buf[4])) != NULL)   // find it
  148.                         {
  149.                         icon->click (buf[0], buf[1], buf[2], buf[4]) ;   // say clicked
  150.                         break ;
  151.                         }
  152.                      }
  153.                   if ((object = w->find_object (buf[0], buf[1])) != NULL)
  154.                      {
  155.                      if (buf[2] & (4 * 16 + 16))
  156.                         object->drag (buf[0], buf[1], buf[2]) ;
  157.                      else if (buf[2] & (4 + 1))
  158.                         object->double_click (buf[0], buf[1], buf[2]) ;
  159.                      else
  160.                         object->click (buf[0], buf[1], buf[2]) ;
  161.                      }
  162.                   else
  163.                      w->click(buf[0], buf[1], buf[2], buf[4]) ;   // tell window
  164.                   }
  165.                }
  166.             else if (buf[3] == -2)   // icon bar
  167.                {
  168.                task->current_menu_window = NULL ;         // no window
  169.                task->current_menu_icon = NULL ;           // no icon
  170.                task->current_menu_object = NULL ;         // no object
  171.                if (buf[2] & Task::BMID)
  172.                   {
  173.                   if (task->iconbar_menu != NULL)
  174.                      {
  175.                      task->current_menu = task->iconbar_menu ;
  176.                      task->pre_menu (task->iconbar_menu) ;            // any user modifications
  177.                      task->iconbar_menu->iconbar_adjust (buf[0], buf[1]) ;
  178.                      task->iconbar_menu->open(buf[0] - 48, buf[1]) ;
  179.                      }
  180.                   else
  181.                      {
  182.                      char *menu_name = task->get_iconbar_menu (buf[4]) ;
  183.                      if (menu_name != NULL)
  184.                         {
  185.                         task->current_menu = task->menus->find (menu_name) ;
  186.                         task->current_menu->iconbar_adjust (buf[0], buf[1]) ;
  187.                         task->current_menu->open (buf[0] - 48, buf[1]) ;
  188.                         }
  189.                      }
  190.                   }
  191.                else
  192.                   task->click (buf[0], buf[1], buf[2], buf[4]) ;
  193.                }
  194.             break ;
  195.          case Task::EUSERDRAG:
  196.             if (task->dragging_sprite)
  197.                {
  198.                _kernel_swi (DragASprite_Stop, &r, &r) ;
  199.                task->dragging_sprite = false ;
  200.                }
  201.             if (task->object_dragger != NULL)
  202.                {
  203.                task->object_dragger->end_drag (buf[0], buf[1], buf[2], buf[3], task->object_dragger_id) ;
  204.                task->object_dragger = NULL ;
  205.                }
  206.             if (task->dragger != NULL)
  207.                {
  208.                task->dragger->drag(buf[0], buf[1], buf[2], buf[3],task->dragger_id) ;
  209.                task->dragger = NULL ;
  210.                }
  211.             break ;
  212.          case Task::EKEY:
  213.             w = task->find_window (buf[0]) ;
  214.             if (w == NULL)
  215.                break ;
  216.             if (buf[1] != -1)                 // pressed in an icon?
  217.                {
  218.                Icon *icon ;
  219.                if ((icon = w->find_icon(buf[1])) != NULL)   // find it
  220.                   {
  221.                   icon->key (buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]) ;   // say key pressed
  222.                   break ;
  223.                   }
  224.                }
  225.             if ((object = w->find_object (buf[0], buf[1])) != NULL)
  226.                object->key (buf[2], buf[3], buf[4], buf[5], buf[6])