#include "Desk.Wimp.h"
#include "Desk.WimpSWIs.h"
#include "Desk.Time.h"
#include "Desk.Event.h"
#include "Desk.Icon.h"


extern void Desk_Icon_ClickWait(int waittime)
{
  static int      waitingonclick = Desk_bool_FALSE;
  int             time;
  Desk_event_pollblock event;
  Desk_event_pollmask  mask;

  if (waitingonclick)        /* Don't allow re-entrant call on this function */
    return;

  waitingonclick = Desk_bool_TRUE;
  time = Desk_Time_Monotonic() + waittime;

  do
  {
    mask.value = 0;                           /* enable null polls */
    Desk_Wimp_ePollIdle(mask, &event, time);        /* Wait until time up or event */

    if (event.type != Desk_event_CLICK && event.type != Desk_event_NULL)
      Desk_Event_Process(&event);                           /* Process this event */

  } while (event.type == Desk_event_CLICK || event.type == Desk_event_REDRAW);

  /*  Wait until not a button click event, and also ignore redraws as a
   *  termination condition, as redraw is very likely (indenting a button)
   *  on the first poll after the click which called us!
   */

  waitingonclick = Desk_bool_FALSE;
}
