home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / demos / proart24 / PCA / !Processed / c / Processed
Encoding:
Text File  |  1996-08-22  |  17.6 KB  |  903 lines

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