Jump to content

Programming for Palm OS/C/Using custom events

From Wikibooks, open books for an open world

define the event

[edit | edit source]
 #define  echoEvent  (firstUserEvent + 0)
 
 typedef struct
 {
   WChar  chr;  // just to demonstrate transporting data with an event
 }
 EchoEvent;


build and enqueue an event

[edit | edit source]
 EventType  event;
 EchoEvent  *ee;
 
 // set the type of the event to the custom event type identifier
 event.eType = echoEvent;
 
 // interpret the Palm OS event storage area as a custom event
 ee = (EchoEvent *) &event.data.generic;
 
 // fill in the custom event
 ee->chr = chr;
 
 // place the filled out event on the event queue
 EvtAddEventToQueue( &event);


handle the event

[edit | edit source]
 // as an example of where stock events are handled..
 Boolean appHandleEvent( EventPtr event)
 
 ...
 
   switch ( event->eType)
   {
     case keyDownEvent:
 
     ...
 
     // custom events are handle naturally alongside stock events:
     case echoEvent:
 
       // interpret the Palm OS event storage area as a custom event
       EchoEvent  *ee = (EchoEvent *) &event->data.generic;
 
       // refer to the parts of the event
       ee->chr;