home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilsp / pca / !Processed / c / Processed
Encoding:
Text File  |  1996-08-27  |  17.6 KB  |  904 lines

  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include "wimp.h"
  5. #include "toolbox.h"
  6. #include "event.h"
  7. #include "wimplib.h"
  8. #include "gadgets.h"
  9. #include "window.h"
  10. #include "sprite.h"
  11. #include "ProgInfo.h"
  12. #include "menu.h"
  13. #include "swis.h"
  14.  
  15. #include <string.h>
  16. #include <stdarg.h>
  17.  
  18. #include "pca.h"
  19. #include "flex.h"
  20.  
  21.  
  22.  
  23.  
  24. #define WimpVersion    310
  25.  
  26. static  WimpPollBlock  poll_block;
  27. static  MessagesFD     messages;
  28. static  IdBlock        id_block;
  29. static  ObjectId       toolmenu;
  30. static  ObjectId       mainmenu;
  31.  
  32.  
  33. int OtherTask,ThisTask;
  34.  
  35. int handlers_attached=0;
  36.  
  37.     sprite_area * spblock;
  38.     sprite_id     id;
  39.     char * sname ="tester";
  40.  
  41.     BOOL VALID=FALSE;
  42.     BOOL SHORTCUT=FALSE;
  43.     char Display[255];
  44.     int count=0;
  45.     char *names[64];
  46.     int   task[64][2];
  47.     int *fake;
  48.     BOOL ACCEPT_INPLACE=TRUE;
  49.     BOOL HOOKED=FALSE;
  50.     int hooked_w;
  51.     int hooked_t;
  52.     int hooked_r;
  53.     void * invisible;
  54.     tag *anch;
  55.  
  56. int quit_event(int event_code, ToolboxEvent *event, IdBlock *id_block,void *handle);
  57. int quit_message(WimpMessage *message,void *handle);
  58. int attach_handlers(int event_code,ToolboxEvent *event,IdBlock *id_block, void *handle);
  59. void werr(int fatal, char* format, ...);
  60. int redraw_window(int event_code, WimpPollBlock *event,IdBlock *id_block,void *v);
  61. void invalidate_addresses(void);
  62. int WhosAbout_message(WimpMessage *message,void *handle);
  63. void blockmoved(BOOL b4,void *handle);
  64. int do_the_free(int event_code, ToolboxEvent *event, IdBlock *id_block,void *handle);
  65. int set_status(int event_code, ToolboxEvent *event, IdBlock *id_block,void *handle);
  66. int setup_menu(int event_code, ToolboxEvent *event, IdBlock *id_block,void *handle);
  67. int changed(WimpMessage *message,void *handle);
  68. int hereIam(int event_code, ToolboxEvent *event, IdBlock *id_block,void *handle);
  69. int update_window(int w_handle,BBox *box);
  70. void os_byte(int code,int * x,int *y);
  71. int akbd_pollsh(void);
  72. int akbd_pollctl(void);
  73. int button(int event_code, WimpPollBlock *event,IdBlock *id_block,void *v);
  74. void screen_to_sprite(WimpMouseClickEvent * c);
  75. int open(int event_code, WimpPollBlock *event,IdBlock *id_block,void *v);
  76. void store_gadget(char* Template,ObjectId Oid,ComponentId g);
  77. void create_gadget(ObjectId Oid,ComponentId g);
  78. void kill_gadget(ObjectId Oid,ComponentId g);
  79.  
  80.  
  81.  
  82.  
  83.  
  84. /*
  85.  * Event handler to be called when toolbox event 1
  86.  * is generated (by click on the 'Quit' entry of
  87.  * the iconbar menu.)
  88.  */
  89.  
  90. int quit_event(int event_code, ToolboxEvent *event, IdBlock *id_block,void *handle)
  91. {
  92.   _kernel_swi_regs r;
  93.   event_code = event_code;
  94.   event = event;
  95.   id_block = id_block;
  96.   handle = handle;
  97.   invalidate_addresses();
  98.   r.r[0]=(int)anch;
  99. _kernel_swi(PCA_DeleteTag,&r,&r);
  100.   exit(0);
  101.   return(1);
  102. }
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. /*
  110.  * Message handler to be called on receipt of a
  111.  * Quit or PreQuit message from the Wimp.
  112.  */
  113.  
  114. int quit_message(WimpMessage *message,void *handle)
  115. {
  116.   _kernel_swi_regs r;
  117.   message = message;
  118.   handle = handle;
  119.   invalidate_addresses();
  120. r.r[0]=(int)anch;
  121. _kernel_swi(PCA_DeleteTag,&r,&r);
  122.  
  123.  
  124.  
  125.  
  126.   exit(0);
  127.   return(1);
  128. }
  129.  
  130.  
  131.  
  132. /* Called on receipt of a WhosAbout message. Add the new task to the
  133.    utilities menu
  134. */
  135.  
  136. int WhosAbout_message(WimpMessage *message,void *handle)
  137.  
  138. {
  139. imhere_block *e;
  140. MenuTemplateEntry Entry = {0};
  141. int temp;
  142. char* q;
  143. handle=handle;
  144.  
  145. e=(imhere_block *)message->data.words;
  146.  
  147. temp=strlen(e->menu);
  148. q=(char*)malloc(temp+1);
  149. if (q==0) return(0);
  150. names[count]=q;
  151. strcpy(names[count],e->menu);
  152. task[count][0]=message->hdr.sender;
  153. task[count][1]=e->flags;
  154. Entry.click_event = 0x300;
  155. Entry.text = names[count];
  156. Entry.max_text = strlen (Entry.text) +1;
  157. Entry.component_id = (ComponentId) count++;
  158. menu_add_entry(0,(ObjectId)handle ,Menu_AddEntryAtEnd,(char *) &Entry,0);
  159. menu_set_fade(0,mainmenu,0,0);
  160.  
  161. return(FALSE);
  162. }
  163.  
  164.  
  165.  
  166. /* Called on receipt of an open window request. If acting as a local to
  167.    an in place editor, keep it informed of windows position
  168. */
  169.  
  170. int open(int event_code, WimpPollBlock *event,IdBlock *id_block,void *v)
  171. {
  172. objectpos_block *e;
  173.  
  174. WimpMessage message;
  175.  
  176. if(HOOKED)
  177. {
  178.    e=(objectpos_block *)message.data.words;
  179.    message.hdr.your_ref=hooked_r;
  180.    message.hdr.size=64;
  181.    message.hdr.action_code=Message_ObjectPosition;
  182.    message.hdr.sender=ThisTask;
  183.    e->tagptr=anch;
  184.  
  185.    e->handle=hooked_w;
  186.    e->toolbarhandle=-1;
  187.    e->zero=0;
  188.    e->xlow=event->open_window_request.visible_area.xmin;
  189.    e->ylow=event->open_window_request.visible_area.ymin;
  190.    e->xscale=1<<16;
  191.    e->yscale=1<<16;
  192.    e->xlowu=event->open_window_request.visible_area.xmin;
  193.    e->ylowu=event->open_window_request.visible_area.ymin;
  194.    wimp_send_message(17,&message,task[hooked_t][0],0,NULL);
  195.  
  196.  }
  197. wimp_open_window((WimpOpenWindowBlock*)event);
  198.  
  199. return(TRUE);
  200. }
  201.  
  202.  
  203. int close(int event_code, WimpPollBlock *event,IdBlock *id_block,void *v)
  204. {
  205. invalidate_addresses();
  206. HOOKED=FALSE;
  207. VALID=FALSE;
  208. wimp_close_window((int*)event);
  209. return FALSE;
  210. }
  211.  
  212. void store_gadget(char* Template,ObjectId Oid,ComponentId g)
  213. {
  214. void *v,*t;
  215. int s;
  216. v=malloc(sizeof(ObjectTemplateHeader));
  217. t=malloc(sizeof(Button) +sizeof(GadgetHeader));
  218. if ((!t)||(!v)) werr(TRUE,"Fatal error: Insufficient memory");
  219. toolbox_template_lookup(0,Template,&v);
  220. window_extract_gadget_info(0,v,g,&t,&s);
  221. invisible=malloc(s);
  222. if (!invisible) werr(TRUE,"Fatal error: Insufficient memory");
  223. *(Gadget*)invisible=*(Gadget*)t;
  224. window_remove_gadget(0,Oid,g);
  225.  
  226. }
  227.  
  228. void create_gadget(ObjectId Oid,ComponentId g)
  229. {
  230. window_add_gadget(0,Oid,invisible,&g);
  231. }
  232.  
  233. void kill_gadget(ObjectId Oid,ComponentId g)
  234. {
  235. window_remove_gadget(0,Oid,g);
  236. }
  237.  
  238.  
  239.  
  240. /*
  241.    A HookMe message has been received. Set the invisible icon's
  242.    button type to that requested by the linked tool.
  243. */
  244.  
  245. int hookme_message(WimpMessage *message,void *handle)
  246.  
  247. {
  248. hookme_block *e;
  249. objectpos_block *f;
  250. int w;
  251. int clear,eor;
  252. ObjectId Oid;
  253. WimpGetWindowStateBlock state;
  254.  
  255.  
  256. Oid=(ObjectId)handle;
  257. create_gadget(Oid,0);
  258.  
  259. e=(hookme_block *)message->data.words;
  260.  
  261. eor=e->flags >> 16;
  262. clear=0xf000;
  263. button_set_flags (0,Oid,0,clear,eor);
  264.  
  265.  
  266. hooked_w=e->handle;
  267. message->hdr.your_ref=message->hdr.my_ref;
  268. hooked_r=message->hdr.your_ref;
  269. message->hdr.size=64;
  270. message->hdr.action_code=Message_ObjectPosition;
  271.  
  272. window_get_wimp_handle(0,Oid ,&w);
  273. state.window_handle = w;
  274. wimp_get_window_state(&state);
  275.  
  276. f=(objectpos_block*) e;
  277. f->handle=w;
  278. f->zero=0;
  279. f->toolbarhandle=-1;
  280. f->xlow=state.visible_area.xmin;
  281. f->ylow=state.visible_area.ymin;
  282. f->xscale=1<<16;
  283. f->yscale=1<<16;
  284. f->xlowu=state.visible_area.xmin;
  285. f->ylowu=state.visible_area.ymin;
  286.  
  287. wimp_send_message      (17,message,task[hooked_t][0],0,NULL);
  288. HOOKED=TRUE;
  289.  
  290. return(FALSE);
  291. }
  292.  
  293.  
  294.  
  295.  
  296. /*
  297.    Unhook and kill gadget
  298. */
  299.  
  300. int unhookme_message(WimpMessage *message,void *handle)
  301. {
  302.  
  303. ObjectId Oid;
  304.  
  305. Oid=(ObjectId)handle;
  306.  
  307.  
  308. kill_gadget(Oid,0);
  309. HOOKED=FALSE;
  310.  
  311. return(FALSE);
  312. }
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319. /* Registered callback function. Called when our flex block moves.
  320.    Called twice, once before the move and once after. We are only interested
  321.    in the call after.
  322. */
  323.  
  324. void blockmoved(BOOL b4,void *handle)
  325. {
  326.  
  327. if (!b4)
  328.   {
  329.  
  330.    id.tag=sprite_id_name;
  331.    id.s.addr=sname;
  332.    sprite_select_rp(spblock,&id,&id.s.addr);
  333.    id.tag=sprite_id_addr;
  334.    anch->base=(int*)spblock;
  335.    }
  336. }
  337.  
  338.  
  339.  
  340. /* If the dummy block has not yet been freed, do it now. This will cause our
  341.    main block to move, thus calling the registered callback handler.
  342. */
  343.  
  344.  
  345. int do_the_free(int event_code, ToolboxEvent *event, IdBlock *id_block,void *handle)
  346.  
  347. {
  348. if(fake!=NULL)
  349.   {
  350.       flex_free((flex_ptr)&fake);
  351.       fake=NULL;
  352.    }
  353.  
  354. /* There's only one dummy block to delete, so once it's been done,
  355.    fade the menu entry.
  356. */
  357.  
  358.  
  359. menu_set_fade(0,mainmenu,1,1);
  360.  
  361.  
  362. return(TRUE);
  363. }
  364.  
  365.  
  366.  
  367. /*
  368.     Toggle user option to accept in place editing.
  369. */
  370.  
  371. int set_status(int event_code, ToolboxEvent *event, IdBlock *id_block,void *handle)
  372.  
  373. {
  374.  
  375. ACCEPT_INPLACE=!ACCEPT_INPLACE;
  376.  
  377. if(ACCEPT_INPLACE)
  378.     menu_set_tick(0,mainmenu,2,1);
  379. else
  380. menu_set_tick(0,mainmenu,2,0);
  381.  
  382. return(TRUE);
  383.  
  384.  
  385. }
  386.  
  387.  
  388.  
  389. /* Main menu about to be shown. Send messages to find out who's about.
  390.    Utility menu created by function handling responses.
  391. */
  392.  
  393. int setup_menu(int event_code, ToolboxEvent *event, IdBlock *id_block,void *handle)
  394. {
  395. whosabout_block *e;
  396. WimpMessage w;
  397.  
  398. int i;
  399. menu_set_fade(0,mainmenu,0,1);
  400. for (i=0;i<count;i++)
  401.      {
  402.      menu_remove_entry(0,(ObjectId)handle,i);
  403.      free(names[i]);
  404.      }
  405. count=0;
  406. e=(whosabout_block *)&w.data;
  407. w.hdr.size=64;
  408. w.hdr.action_code=Message_WhosAbout;
  409. w.hdr.my_ref=0;
  410. w.hdr.your_ref=0;
  411. w.hdr.sender=ThisTask;
  412.  
  413. e->tagptr=anch;
  414. e->filetype=0xff9;
  415. wimp_send_message      (17,&w,0,0,NULL);
  416.  
  417. if(ACCEPT_INPLACE) menu_set_tick(0,mainmenu,2,1); else menu_set_tick(0,mainmenu,2,0);
  418.  
  419. return(FALSE);
  420. }
  421.  
  422.  
  423.  
  424.  
  425. /*  A remote application has modified the picture */
  426.  
  427.  
  428. int changed(WimpMessage *message,void *handle)
  429.  
  430. {
  431. ObjectId Oid;
  432. BBox b;
  433. updatearea_block *e;
  434. int w;
  435.  
  436. e=(updatearea_block *)message->data.words;
  437.  
  438. Oid=(ObjectId)handle;
  439.  
  440. if (message->hdr.action_code==Message_DoneMyStuff)
  441.    {
  442.       b.xmin=0;
  443.       b.xmax=1000;
  444.       b.ymin=-398;
  445.       b.ymax=-00;
  446.  
  447.    }
  448. else
  449.    {
  450.      b.xmin=e->r.xlow;
  451.      b.xmax=e->r.xhi;
  452.      b.ymin=e->r.ylow-398;
  453.      b.ymax=e->r.yhi-398;
  454.    }
  455.  
  456. window_get_wimp_handle(0,Oid ,&w);
  457. update_window(w,&b);
  458.  
  459.  
  460. return(TRUE);
  461. }
  462.  
  463.  
  464.  
  465.  
  466. int returned_message(WimpMessage *message,void *handle)
  467.  
  468. {
  469. handle=handle;
  470.  
  471. if ((message->hdr.sender==ThisTask) && SHORTCUT)
  472. {
  473.  
  474. SHORTCUT=FALSE;
  475. toolbox_show_object(1,toolmenu,0,NULL,NULL,NULL);
  476.  
  477.  
  478. }
  479. return(FALSE);
  480. }
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492. /* link to selected remote */
  493.  
  494. int hereIam(int event_code, ToolboxEvent *event, IdBlock *id_block,void *handle)
  495. {
  496. doyourstuff_block *e;
  497. WimpMessage w;
  498.  
  499. e=(doyourstuff_block *)&w.data;
  500.  
  501. w.hdr.size=64;
  502. w.hdr.action_code=Message_DoYourStuff;
  503. w.hdr.my_ref=0;
  504. w.hdr.your_ref=0;
  505. w.hdr.sender=ThisTask;
  506. e->toolid=1;
  507. e->flags=task[id_block->self_component][1];
  508. if (!ACCEPT_INPLACE) e->flags =  e->flags & !Flag_remote;
  509. strcpy(e->name,"Gee-gee");
  510.  
  511. e->tagptr=anch;
  512. e->filetype=0xff9;
  513. hooked_t=id_block->self_component;
  514. wimp_send_message      (17,&w,task[id_block->self_component][0],0,NULL);
  515. VALID=TRUE;
  516. return(FALSE);
  517. }
  518.  
  519.  
  520.  
  521. /* The picture is about to disappear, so warn remotes that the address they
  522.    have will not longer be valid.
  523. */
  524.  
  525.  
  526.  
  527.  
  528. void invalidate_addresses(void)
  529. {
  530. deselect_block *e;
  531. WimpMessage w;
  532.  
  533. e=(deselect_block *)&w.data;
  534.  
  535. w.hdr.size=64;
  536. w.hdr.action_code=Message_Deselect;
  537. w.hdr.my_ref=0;
  538. w.hdr.your_ref=0;
  539. w.hdr.sender=ThisTask;
  540.  
  541. e->tagptr=anch;
  542. e->filetype=0xff9;
  543. wimp_send_message      (17,&w,0,0,NULL);
  544. VALID=FALSE;
  545. }
  546.  
  547.  
  548.  
  549.  
  550. int main()
  551. {
  552.     int    toolbox_events = 0,
  553.            wimp_messages = 0,
  554.            event_code;
  555.      _kernel_swi_regs r;
  556.  
  557.  
  558.     /*
  559.      * register ourselves with the Toolbox.
  560.      */
  561.  
  562.     toolbox_initialise (0, WimpVersion, &wimp_messages, &toolbox_events, "<Processed$Dir>",
  563.                         &messages, &id_block, 0, &ThisTask, 0);
  564.  
  565.  
  566.    /* Initialise flex with dynamic areas active */
  567.  
  568.     flex_initx("Processed",(int*)&messages,TRUE,1024*1024,FALSE);
  569.  
  570.  
  571.     /*
  572.      * initialise the event library.
  573.      */
  574.  
  575.     event_initialise (&id_block);
  576.     event_set_mask (1+256);
  577.  
  578.  
  579.     /*
  580.      * register handler for toolbox event 1,
  581.      * which is generated by the 'Quit' option on the
  582.      * iconbar menu.  Also register message handlers
  583.      * to quit properly when quit messages are
  584.      * received from the wimp.
  585.      */
  586.  
  587.       event_register_toolbox_handler(-1,1,quit_event,0);
  588.       event_register_message_handler(Wimp_MQuit,quit_message,0);
  589.       event_register_message_handler(Wimp_MPreQuit,quit_message,0);
  590.       event_register_toolbox_handler(-1,Toolbox_ObjectAutoCreated,attach_handlers,NULL);
  591.  
  592.  
  593.  
  594.  
  595.  
  596.     /* Allocate a block before the one containing the sprite. When this is later
  597.        freed, it will cause the sprite to move.
  598.     */
  599.  
  600.      flex_alloc((flex_ptr)&fake,100*1024);
  601.  
  602.  
  603.     if (flex_alloc((flex_ptr)&spblock,300*1024)==0) werr(TRUE,"Fatal error. No room for sprite area");
  604.  
  605.  
  606.      sprite_area_initialise(spblock, 1024*300);
  607.      sprite_area_load(spblock, "<Processed$Dir>.Testfile");
  608.      id.tag=sprite_id_name;
  609.      id.s.addr=sname;
  610.      sprite_select_rp(spblock,&id,&id.s.addr);
  611.      id.tag=sprite_id_addr;
  612.      flex_register((flex_ptr)&spblock,blockmoved,NULL);
  613.  
  614.      r.r[1]=(int)spblock;
  615.      r.r[2]=(int)id.s.addr-(int)spblock;
  616.      _kernel_swi(PCA_CreateTag,&r,&r);
  617.      anch=(tag*)r.r[0];
  618.  
  619.  
  620.     /*
  621.      * poll loop
  622.      */
  623.  
  624.     while (TRUE)
  625.     {
  626.         event_poll (&event_code, &poll_block, 0);
  627.     }
  628. }
  629.  
  630.  
  631.  
  632. int attach_handlers(int event_code,ToolboxEvent *event,IdBlock *id_block, void *handle)
  633. {
  634.   /* This function has been called as a result of an object being
  635.    * auto-created. For this example that means our iconbar object
  636.    * so we can now register all our other handlers for the rest
  637.    * of our objects
  638.    */
  639.  
  640.  
  641.   ObjectClass     obj_class;
  642.   char buffer[32];
  643.   int dum;
  644.  
  645.  
  646.  
  647.   toolbox_get_object_class(0,id_block->self_id,&obj_class);
  648.   toolbox_get_template_name(0,id_block->self_id,buffer,32,&dum);
  649.  
  650.  
  651.   switch(obj_class)
  652.   {
  653.     case Window_ObjectClass:
  654.  
  655.    if ((!handlers_attached) && (strcmp(buffer,"Window")==0) )
  656.       {
  657.      event_register_wimp_handler(id_block->self_id,Wimp_ERedrawWindow,redraw_window,NULL);
  658.      event_register_wimp_handler(-1,Wimp_EOpenWindow,open,(void*)id_block->self_id );
  659.       event_register_wimp_handler(-1,Wimp_ECloseWindow,close,(void*)id_block->self_id );
  660.      event_register_wimp_handler(id_block->self_id,Wimp_EMouseClick,button,(void*)id_block->self_id );
  661.      event_register_message_handler(Message_DoneMyStuff,changed,(void*)id_block->self_id );
  662.      event_register_message_handler(Message_UpdateArea,changed,(void*)id_block->self_id );
  663.      event_register_message_handler(Message_WhosAbout,returned_message,(void*)id_block->self_id );
  664.      event_register_message_handler(Message_HookMe,hookme_message,(void*)id_block->self_id );
  665.      event_register_message_handler(Message_UnhookMe,unhookme_message,(void*)id_block->self_id );
  666.      store_gadget("Window",id_block->self_id,0);
  667.  
  668.  
  669.             handlers_attached=1;
  670.        }
  671.      break;
  672.  
  673.    case ProgInfo_ObjectClass:
  674.  
  675.       proginfo_set_version (0,id_block->self_id, "0.02 " __DATE__);
  676.       break;
  677.  
  678.    case Menu_ObjectClass:
  679.       if (strcmp(buffer,"Menu")==0)
  680.  
  681.              {
  682.  
  683.            toolmenu=id_block->self_id;
  684.            event_register_toolbox_handler(id_block->self_id,0x300,hereIam,(void*)toolmenu);
  685.            event_register_message_handler(Message_WhosAbout,returned_message,(void*)toolmenu );
  686.  
  687.              }
  688.     if ((strcmp(buffer,"Main")==0) && (toolmenu!=0))
  689.  
  690.          {
  691.          mainmenu=id_block->self_id;
  692.          event_register_toolbox_handler(id_block->self_id,0x200,setup_menu,(void*)toolmenu);
  693.          event_register_message_handler(Message_ImHere,WhosAbout_message,(void*)toolmenu);
  694.          event_register_toolbox_handler(-1,0x500,do_the_free,(void*)mainmenu);
  695.          event_register_toolbox_handler(-1,0x501,set_status,(void*)mainmenu);
  696.          }
  697.  
  698.  
  699.       break;
  700.  
  701.  
  702.   }
  703.  
  704.  
  705.   return 1;
  706. }
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714. void werr(int fatal, char* format, ...)
  715. {
  716.    va_list va;
  717.    _kernel_oserror e;
  718.  
  719.    e.errnum = 0;
  720.    va_start(va, format);
  721.    vsprintf(&e.errmess[0], format, va);
  722.    va_end(va);
  723.    wimp_report_error(&e, 0, "Processed",0,0,0);
  724.    if (fatal) exit(1);
  725. }
  726.  
  727.  
  728.  
  729. /*
  730.    A mouse button has been pressed. If in place editing is active, pass
  731.    the mouse click to the remote. Otherwise, look for the keyboard
  732.    short cut.
  733. */
  734.  
  735.  
  736. int button(int event_code, WimpPollBlock *event,IdBlock *id_block,void *v)
  737. {
  738.  
  739. ObjectId Oid;
  740.  
  741. ToolboxEvent t;
  742. Oid=(ObjectId)v;
  743.  
  744. if(HOOKED)
  745.  
  746. {
  747.  
  748. screen_to_sprite((WimpMouseClickEvent *)event);
  749.  
  750. event->mouse_click.window_handle=hooked_w;
  751. event->mouse_click.icon_handle=-(0x414350);
  752. wimp_send_message(6,event,task[hooked_t][0],0,NULL);
  753.  
  754.  
  755. }
  756.  
  757. else
  758. {
  759.  
  760.    if (akbd_pollsh() && akbd_pollctl())
  761.    {
  762.         t.hdr.size=16;
  763.         t.hdr.event_code=0x200;
  764.         t.hdr.flags=0;
  765.         toolbox_raise_toolbox_event(0,mainmenu,NULL,&t);
  766.         SHORTCUT=TRUE;
  767.      }
  768.  
  769. }
  770.  
  771.  
  772.  
  773. return(TRUE);
  774. }
  775.  
  776.  
  777. /*
  778.   Convert mouse coordinates to an ofset into the sprite.
  779. */
  780.  
  781.  
  782. void screen_to_sprite(WimpMouseClickEvent * c)
  783. {
  784.  
  785. WimpGetWindowStateBlock state;
  786. int x,y;
  787.  
  788.  
  789.  
  790. state.window_handle = c->window_handle;
  791. wimp_get_window_state(&state);
  792.  
  793. x = (state.visible_area.xmin - state.xscroll);
  794. y = (state.visible_area.ymax - state.yscroll);
  795.  
  796.  
  797.  
  798. c->mouse_x-=x;
  799. c->mouse_y=y-c->mouse_y;
  800. c->mouse_y=398-c->mouse_y;
  801.  
  802.  
  803.  
  804. }
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811. int redraw_window(int event_code, WimpPollBlock *event,IdBlock *id_block,void *v)
  812. {
  813.    int more,height,x,y;
  814.    WimpGetWindowStateBlock state;
  815.    WimpRedrawWindowBlock block;
  816.    BBox extent;
  817.  
  818.  
  819.    state.window_handle = event->redraw_window_request.window_handle;
  820.    block.window_handle = event->redraw_window_request.window_handle;
  821.  
  822.    wimp_get_window_state(&state);
  823.  
  824.    window_get_extent(0, state.window_handle,&extent);
  825.    height = extent.ymax -extent.ymin;
  826.  
  827.  
  828.    x = (state.visible_area.xmin - state.xscroll);
  829.    y = (state.visible_area.ymax - state.yscroll);
  830.  
  831.    wimp_redraw_window(&block,&more);
  832.    while (more)
  833.    {
  834.       if(spblock!=NULL) sprite_put_in_current(spblock, &id, 0,x, y-398);
  835.  
  836.  
  837.        wimp_get_rectangle (&block,&more);
  838.    }
  839.  
  840.    return 1;
  841. }
  842.  
  843.  
  844.  
  845.  
  846. int update_window(int w_handle,BBox *box)
  847. {
  848.    int more,x,y;
  849.    WimpGetWindowStateBlock state;
  850.    WimpRedrawWindowBlock block;
  851.  
  852.    state.window_handle = w_handle;
  853.    wimp_get_window_state(&state);
  854.  
  855.    x = (state.visible_area.xmin - state.xscroll);
  856.    y = (state.visible_area.ymax - state.yscroll);
  857.  
  858.    block.window_handle=w_handle;
  859.    block.visible_area.xmin=box->xmin;
  860.    block.visible_area.xmax=box->xmax;
  861.    block.visible_area.ymin=box->ymin;
  862.    block.visible_area.ymax=box->ymax;
  863.  
  864.  
  865.  
  866.    wimp_update_window(&block,&more);
  867.    while (more)
  868.    {
  869.       if(spblock!=NULL) sprite_put_in_current(spblock, &id, 0,x, y-398);
  870.  
  871.  
  872.        wimp_get_rectangle (&block,&more);
  873.    }
  874.  
  875.    return 1;
  876. }
  877.  
  878.  
  879. void os_byte(int code,int * x,int *y)
  880. {
  881. _swi(OS_Byte,_IN(0)|_IN(1)|_IN(2)|_OUT(1)|_OUT(2),code,*x,*y,x,y);
  882. }
  883.  
  884.  
  885. int akbd_pollsh(void)
  886. {
  887.   int x = -1;
  888.   int y = 255;
  889.   os_byte(129, &x, &y);
  890.   return(x==255 && y==255);
  891. }
  892.  
  893. int akbd_pollctl(void)
  894. {
  895.   int x = -2;
  896.   int y = 255;
  897.   os_byte(129, &x, &y);
  898.   return(x==255 && y==255);
  899. }
  900.  
  901.  
  902.  
  903.  
  904.