home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / oslib / examples / c / wimpmsg < prev    next >
Encoding:
Text File  |  1995-08-30  |  1.6 KB  |  64 lines

  1. /* Title:   wimpmsg.c
  2.  * Purpose: functions for wimp message handling
  3.  * Author:  IDJ
  4.  * History: 19-Jun-94:     IDJ:   created
  5.  *          30th Aug 1995  J R C  Hacked for Support library
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. #include "os.h"
  13.  
  14. #include "wimpmsg.h"
  15. #include "trace.h"
  16. #include "x.h"
  17.  
  18. static event_message_handler_item *Handlers = NULL; /*the list of all
  19.       wimp message handlers*/
  20.  
  21. /* ------------------ dispatching a wimp message ------------------ */
  22. void wimpmsg_dispatch (wimp_block *poll_block, toolbox_block *id_block)
  23.  
  24. {  event_message_handler_item *h;
  25.  
  26.    id_block = id_block;
  27.  
  28.    tracef ("wimpmsg_dispatch\n");
  29.    for (h = Handlers; h != NULL; h = h->next)
  30.       if (h->handler != NULL && (h->msg_no == -1 ||
  31.             h->msg_no == poll_block->message.action))
  32.          if (h->handler (&poll_block->message, h->handle))
  33.             return;
  34. }
  35.  
  36. void wimpmsg_register_message_handler (int msg_no,
  37.       event_message_handler *handler, void *handle)
  38.  
  39. {  event_message_handler_item *h;
  40.  
  41.    h = x_ALLOC (sizeof *h);
  42.    h->msg_no     = msg_no;
  43.    h->handler    = handler;
  44.    h->handle     = handle;
  45.    h->next       = Handlers;
  46.    Handlers = h;
  47. }
  48.  
  49. void wimpmsg_deregister_message_handler (int msg_no,
  50.      event_message_handler *handler, void *handle)
  51.  
  52. {  event_message_handler_item **h;
  53.  
  54.    /*search for exact match of handler, list and handle*/
  55.    for (h = &Handlers; *h != NULL; h = &(*h)->next)
  56.       if ((*h)->handler == handler && (*h)->handle == handle &&
  57.             (*h)->msg_no == msg_no)
  58.       {  event_message_handler_item *hh = *h;
  59.  
  60.          *h = hh->next;
  61.          x_FREE (hh, sizeof *hh);
  62.       }
  63. }
  64.