/*H**********************************************************************
 *
 * FILENAME : click.c
 *
 * DESCRIPTION :
 *       This file contains the function click .
 *
 * PUBLIC FUNCTIONS :
 *       Click()
 *
 * NOTES :
 *       This function is to be used with O/S 2.xx and above.
 *
 * CHANGES :
 * DATE        WHO         DETAIL
 * 22/09/93    A.J.T.      Click was separated for EFX.c
 *
 *H*/
 
/************************************************************************
 *    INCLUDE FILES
 ***********************************************************************/

/*---- system and platform files --------------------------------------*/
#include <exec/types.h>
#include <graphics/gfxmacros.h>
#include <intuition/intuition.h>

#include <clib/exec_protos.h>
#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>

/************************************************************************
 *    PUBLIC DECLARATIONS
 ***********************************************************************/

/*---- function prototypes --------------------------------------------*/
void Click(struct Window *win) ;

/************************************************************************
 *    PUBLIC FUNCTION DEFINITIONS
 ***********************************************************************/

/*F**********************************************************************
 *
 * NAME : Click()
 *
 * DESCRIPTION :
 *          This function waits for a left mouse click in the window.
 *
 * INPUTS :
 *    PARAMETERS :
 *          A valid active window.
 *
 * OUTPUTS :
 *    GLOBALS :
 *          Clears window IDCMP flags, then set it for mouse buttons only.
 *
 *    RETURN :
 *          Nil.
 *
 * NOTES :
 *          When opening your window it is not necessary to set any IDCMP
 *          flags. If you do, they will need to be reset immediately on
 *          returning from this call.
 *
 * CHANGES :
 * DATE     WHO      DETAIL
 * 13/03/93 A.J.T.   Change in style and modified for V2.XX.
 *
 *F*/

void Click(struct Window *win)
   {
      BOOL Waiton = TRUE ;
      ULONG class ;
      struct IntuiMessage  *message ;
      USHORT code ;
   
      if (win == NULL) return ; /* Always test for valid window pointer */
   
      ModifyIDCMP(win, IDCMP_MOUSEBUTTONS) ;  /* Clear and set window's */
                                              /* IDCMP flag             */
      while (Waiton)  /* Main input loop */
         {
            if ((message = (struct IntuiMessage *)
                        GetMsg (win->UserPort)) == NULL)
               {
                  Wait (1L << win->UserPort->mp_SigBit) ;
                  continue ;
               }
                     
            class = message->Class ;       
            code  = message->Code ;
            ReplyMsg ((struct Message *)message) ;
            if (class & MOUSEBUTTONS)
               if (code == SELECTDOWN)
                  Waiton = FALSE ;
         }
   }

/* EOF click.c ----------------------------------------------------------*/
