O'Reilly logo

Palm Programming: The Developer's Guide by Julie McKeehan, Neil Rhodes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Application Code for Menus

There’s not a lot of code that needs to be added to support menus. Further, what you do add is straightforward and in some cases standard from application to application. The three routines that have some responsibility for handling menus are:

  • MenuHandleEvent

  • MyFormHandleEvent

  • MyFormHandleMenuEvent

There is some cookbook code to add that handles the Edit menu, and we need to handle the About menu, as well.

MenuHandleEvent

This routine is responsible for handling menu-specific events. Chapter 4, contains a description of MenuHandleEvent and its role within your main event loop. Here is an example found in a main event loop:

do {
   EvtGetEvent(&event, evtWaitForever);
   if (! SysHandleEvent(&event))
      if (! MenuHandleEvent(0, &event, &error))
         if (! ApplicationHandleEvent(&event))
            FrmDispatchEvent(&event);
} while (event.eType != appStopEvent);

MyFormHandleEvent

Your form’s event handler receives an event of type menuEvent if a menu item is chosen. If you have more than one or two menu items handled by a form, it is customary to put the menu item dispatching in a separate routine, MyFormHandleMenuEvent. Here is our event handler:

static Boolean MyFormHandleEvent(EventPtr event)
{
   Boolean     handled = false;

#ifdef __GNUC__
   CALLBACK_PROLOGUE
#endif
   switch (event->eType)
      {
         /* code removed */
      case menuEvent:
         handled = MyFormHandleMenuEvent(event->data.menu.itemID);
         break;
      /* code removed */
      }
#ifdef __GNUC__
   CALLBACK_EPILOGUE
#endif
   return handled;
}

MyFormHandleMenuEvent ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required