David Fedor wrote:
> This way of handling events (nested event loops) is generally a risky
> thing.  If for example your event loop is trying to grab some events and
> special-case them, it won't work in this case.  And you're not calling
> MenuHandleEvent or FormDispatchEvent like your real event loop would... so
> some events might not get handled properly.
> 
> You could check if the pen is down, and (depending on how frequently you
> check) it might have the same result, without actually dequeueing any
> events.

Ok, I see your point.  How about this then?  Notice that I flush the pen
queue in EndUserCancel so that the pen touch which terminates the loop
doesn't get queued as an event and interpreted later as a button press
or something.
--Mark


static FormPtr     g_UserCancelWorkingForm;
static WinHandle   g_UserCancelWindow;
static Boolean     g_UserCancelled;
static ULong       g_UserCancelDrawTime;

void StartUserCancel(void)
{
    g_UserCancelled = false;
    g_UserCancelWorkingForm = NULL;
    g_UserCancelDrawTime = TimGetTicks() +
            ((USER_CANCEL_DELAY * SysTicksPerSecond()) / 10);
}

void EndUserCancel(void)
{
    if (g_UserCancelWorkingForm != NULL)
    {
        FrmEraseForm(g_UserCancelWorkingForm);
        FrmDeleteForm(g_UserCancelWorkingForm);
        WinSetDrawWindow(g_UserCancelWindow);
    }
    EvtFlushPenQueue();
}

Boolean UserCancel(void)
{
    SWord x, y;
    Boolean penDown;

    if (g_UserCancelled)
        return true;
    if (g_UserCancelWorkingForm == NULL &&
        TimGetTicks() >= g_UserCancelDrawTime)
    {
        g_UserCancelWindow = WinGetDrawWindow();
        g_UserCancelWorkingForm = FrmInitForm(ID_FORM_WORKING);
        FrmDrawForm(g_UserCancelWorkingForm);
    }
    EvtGetPen(&x, &y, &penDown);
    if (penDown)
    {
        g_UserCancelled = true;
        return true;
    }
    return false;
}

Reply via email to