A while ago I asked the list if it was possible to write a letter in the Graffiti
area and have that select the first item starting with that letter in a sorted
Popup list.  With a great deal of help from people on ths list, here's one way to
do it.  It's rude crude and unedited but it seems to be working so far in
CityTime 2.1, even though it could use a bit of fixing.


In Global Defines...

typedef void EvtGetEventFuncType (EventPtr event, SDWord timeout);

typedef EvtGetEventFuncType * EvtGetEventFuncPtr;



In Globals...

static EvtGetEventFuncPtr OldTrap;
static ListPtr    globListP;



The custom EvtGet Event function that is called from a trap to EvtGetEvent...

/***********************************************************************
 *
 * FUNCTION:  myEvtGetEvent
 *
 * DESCRIPTION: Additional hooks in EvtGetEvent
 *
 * PARAMETERS: Same as EvtGetEvent - event, timeout
 *
 * RETURNED:  Sames as EvtGetEvent - nothing
 *
 ***********************************************************************/
static void myEvtGetEvent (EventPtr event, SDWord timeout)
{
CharPtr   keyS;
int     i;


  // first run the normal EvtGetEvent routine
   OldTrap (event, timeout);

  // intercept it only if appropritate
   if (event->eType == keyDownEvent && event->data.keyDown.chr > 64 &&
     event->data.keyDown.chr < 123)
    {
    // setup key string - need a string for FindCityByLetter
     keyS = MemPtrNew (2);
     ErrFatalDisplayIf (!keyS, "error allocating memory");

     keyS[0] = event->data.keyDown.chr;
     keyS[1] = '\0';

    // get the character
     i = FindCityByLetter (keyS);

    // handle it if approriate
     if (i != -1)
      {
      LstSetTopItem (globListP, i);
      LstDrawList (globListP);
      }


    // free memory
     MemPtrFree (keyS);
    }

}



Trap Setting (and unsetting) that is called either side of LstPopupList...

  OldTrap = SysGetTrapAddress(sysTrapEvtGetEvent);
  SysSetTrapAddress (sysTrapEvtGetEvent, &myEvtGetEvent);

  globListP = listP;

  // pop up the list
   select = LstPopupList (listP);

  // after selection
   SysSetTrapAddress(sysTrapEvtGetEvent,OldTrap);




Hope this helps someone.

-Darren
http://www.codecity.com.au

Reply via email to