Title: Re: EvtSetNullEventTick macro
At 8:27 PM -0700 9/18/99, Sudipta Ghose wrote:
In the datebook source code, I found a macro named EvtSetNullEventTick. The macro sets an OS global called NeedNullTickCount. If I use this macro in my code pose gives a warning (as it should). My question is how safe is to use the macro? How does this global affects the generation of nilEvents?  Is there any alternatives? What I need to do, is to display some text for few seconds, and then erase the text.

Scott Johnson answered your question a long time ago, but he didn't give any details on how do what EvtSetNullEventTick does yourself. I used EvtSetNullEventTick during development of BeamBooks, but I switched to my own ProduceNilEventAt routine before release.

You need a global variable, say:

// When to produce a nil event, or zero if never.
static ULong NilEventTicks = 0;

Then you need a routine like this:

void ProduceNilEventAt(ULong ticks)
{
    if (NilEventTicks == 0 || NilEventTicks > ticks)
                NilEventTicks = ticks;
}

Then you need to modify your app event loop like this:

static void AppEventLoop(void)
{
ULong now;
        SDWord timeout;
        ...
       
        do
      {
               if (NilEventTicks == 0)
                         timeout = evtWaitForever;
               else
            {
                       now = TimGetTicks();
                    timeout = NilEventTicks > now ? NilEventTicks - now : 0;
                }
                EvtGetEvent(&event, timeout);
           if (event.eType == nilEvent)
                    NilEventTicks = 0;
              if (! SysHandleEvent(&event))
                        ...
     }
       while (event.eType != appStopEvent);
}

When I get a nilEvent, I don't assume that my wait is over. The nilEvent could have been generated by Palm OS. I use a separate tick clock to check. Here's an example of how you could use ProduceNilEventAt to hide some text after a few seconds:

#define kHideTextDelay                          300ul

static ULong HideTextTicks;
static void LoadSomeForm(FormPtr formP)
{
        HideTextTicks = TimGetTicks() + kHideTextDelay;
        ProduceNilEventAt(HideTextTicks);
}

Boolean SomeFormHandleEvent(EventPtr eventP)
{
        ...
        if (HideTextTicks != 0 && TimGetTicks() > HideTextTicks)
                ... hide text here ...
        switch (eventP->eType)
        {
                ...
                case nilEvent:
                        if (HideTextTicks != 0)
                                ProduceNilEventAt(HideTextTicks);
                        break;
        }
        return handled;
}

Hope this isn't too late to be useful...
-
Danny Epstein, Applied Thought Corporation
Check out our latest app at http://www.appliedthought.com/beambooks

Reply via email to