home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / a / armbob / !ArmBob / progs / !Exec / main < prev    next >
Text File  |  1994-06-25  |  4KB  |  153 lines

  1. /******************************************************************
  2.  *
  3.  *  !Exec v.1 - an ArmBob wimp program           GCW 02/06/94
  4.  *
  5.  *  Run command file with pathname of file dragged onto icon.
  6.  *
  7.  *  See doc.tutorial.4
  8.  *
  9.  ******************************************************************/
  10.  
  11. main()
  12. {
  13.  @b = @(newstring(500));  // global message buffer
  14.  
  15.  /* Create vector of responses to the task manager */
  16.  handler = newvector(20);         
  17.  handler[Mouse_Click] = do_Mouse_Click;
  18.  handler[Menu_Selection] = do_Menu_Selection;
  19.  handler[User_Message] = handler[User_Message_Recorded] = do_Message;
  20.  /* All but 4 of handler's components are nil */
  21.  
  22.  in (mesg_list= newstring(8)) put
  23.      { Message_DataLoad; 0; }        // the messages we want to receive
  24.  
  25.  /* register task with window manager */
  26.  wimp_init(310,"Exec",mesg_list);
  27.  
  28.  /* create vector of windows and get their handles */  
  29.  (wind = newvector(1))[0] = "info";
  30.  info = templates("<Exec$Dir>.Templates",wind)[0];
  31.  
  32.  icon = make_icon();
  33.  menu = make_menu();
  34.  
  35.  /* global register vector for functions in loops that use swi */
  36.  r = newvector(8);
  37.  
  38.  /******* the central loop takes place here ********/
  39.  /* &1933 is the reason code mask.
  40.     @b is the message buffer address.
  41.     handler is the vector of message handlers.
  42.     nil is the current value of the "user-parameter" - we
  43.     might want to pass round a parameter to the handlers
  44.     containing extra data that each could decode.  */
  45.  
  46.  event_process(&1933,@b,handler,nil); 
  47. }
  48.  
  49. do_Mouse_Click(a,user)
  50. {
  51.  if ((£(a+12)==-2) &&                   // iconbar
  52.      (£(a+16)==icon))                   // icon
  53.    switch (£(a+8))
  54.     {
  55.       case 2:                           // Menu button
  56.        r[1] = menu;                     // use global r
  57.        r[2] = £(a)-64;
  58.        r[3] = 140;
  59.        swi("Wimp_CreateMenu",r);
  60.        break;
  61.       case 1:                          // Adjust button
  62.       case 4:                          // Select button
  63.        oscli("Filer_run <Exec$Dir>.Exec");  // Exec must be a textfile
  64.        break;
  65.      }  
  66.  return TRUE;  // i.e. continue
  67. }
  68.  
  69. do_Menu_Selection(a,user)
  70. {
  71.  return (£(a)!=1);     
  72. }
  73.  
  74. do_Message(a,user)
  75. {
  76.  switch(£(a+16))
  77.     {
  78.      case Message_Quit:
  79.        return FALSE;  // i.e. do not continue
  80.        break;
  81.      case Message_DataLoad:  
  82.         if (£(a+20)==-2 && £(a+24)==icon)
  83.            act(a,user_process);
  84.         return TRUE;
  85.         break;
  86.      default:
  87.         return TRUE;
  88.         break;
  89.     }
  90. }
  91.  
  92. make_icon()
  93. {
  94.  local r;
  95.  in @b put 
  96.  {
  97.   -1;                       // right of icon bar
  98.    0;                       // xmin of bounding box
  99.    0;                       // ymin of bounding box
  100.    64;                      // xmax of bounding box
  101.    68;                      // ymax of bounding box
  102.    &1700210a;               // icon flags
  103.    @(sprite = "!exec");     // pointer to sprite name
  104.    1;                       // Wimp sprite area
  105.    8;                       // Length of spritename
  106.  }
  107.  (r = newvector(8))[1] = @b;
  108.  swi("Wimp_CreateIcon",r);
  109.  return(r[0]);
  110. }
  111.  
  112. make_menu()
  113. {
  114.  in (menu = newstring(72)) put
  115.  {
  116.   "Exec"; 0; 0;                           // Menu title
  117.    &70207;                                // colours
  118.    100;                                   // width
  119.    44;                                    // height 
  120.    0;                                     // gap
  121.    0;
  122.    info;                                  // submenu
  123.    1+(1<<4)+(9<<12)+(1<<16)+(7<<24);      // flags
  124.    "Info"; 0; 0;                          // item title
  125.    &80;                                   // last item
  126.    -1;                                    // no submenu
  127.    1+(1<<4)+(9<<12)+(1<<16)+(7<<24);      // flags
  128.    "Quit"; 0;                             // item title
  129.  }
  130.  return(menu);
  131. }
  132.  
  133. act(a,f)
  134. {
  135.  local filename, filetype;
  136.  filename = $(a+44);
  137.  filetype = £(a+40);
  138.  ££(a+16,Message_DataLoadAck);
  139.  ££(a+12,£(a+8));
  140.  r[0] = User_Message_Acknowledge;
  141.  r[1] = a;
  142.  r[2] = 0;
  143.  swi("Wimp_SendMessage",r);
  144.  f(filename,filetype);
  145. }
  146.  
  147. // ------- end of harness, do your own stuff here -------- //
  148.  
  149. user_process(fname,ftype)
  150. {
  151.  oscli("WimpTask Obey -c <Exec$Dir>.Exec "+fname); 
  152. }
  153.