home *** CD-ROM | disk | FTP | other *** search
/ Hand Held Organizer Toolkit / walnutcreekcdrom-handheldorganizertoolkit-march1998.iso / PalmPilot / development / pfc.sit / Src / TestApp.c < prev    next >
C/C++ Source or Header  |  1997-04-25  |  4KB  |  161 lines

  1. /***********************************************************************
  2.  *
  3.  *    Copyright ⌐ 1997 Ken Hancock
  4.  *
  5.  * FILE: TestApp.c
  6.  *
  7.  * DESCRIPTION: Sample application to demonstrate custom fonts
  8.  *
  9.  * REVISION HISTORY:
  10.  *      4/8/97    KSH        Initial version
  11.  *
  12.  **********************************************************************/
  13.  
  14. #include <Pilot.h>                // all the system toolbox headers
  15. #include "TestAppRsc.h"        // application resource defines
  16. #include "CustomFonts.h"
  17.  
  18.  
  19. /***********************************************************************
  20.  * Prototypes for internal functions
  21.  **********************************************************************/
  22. static void StartApplication(void);
  23. static Boolean MainFormHandleEvent(EventPtr event);
  24. static void EventLoop(void);
  25.  
  26.  
  27. /***********************************************************************
  28.  *
  29.  * FUNCTION:     StartApplication
  30.  *
  31.  * DESCRIPTION:  This routine sets up the initial state of the application.
  32.  *
  33.  * PARAMETERS:   None.
  34.  *
  35.  * RETURNED:     Nothing.
  36.  *
  37.  ***********************************************************************/
  38. static void StartApplication(void)
  39. {
  40.     FormPtr    frm;
  41.     
  42.     // Initialize and draw the main memo pad form.
  43.     frm = FrmInitForm(mainForm);
  44.     CFSwapFont(ledFont,1000);
  45.     FldSetFont(FrmGetObjectPtr(frm,FrmGetObjectIndex(frm,1002)),ledFont);
  46.     FrmSetActiveForm(frm);
  47.     FrmDrawForm(frm);
  48. }
  49.  
  50.  
  51. /***********************************************************************
  52.  *
  53.  * FUNCTION:        MainFormHandleEvent
  54.  *
  55.  * DESCRIPTION:    Handles processing of events for the ╥main╙ form.
  56.  *
  57.  * PARAMETERS:        event    - the most recent event.
  58.  *
  59.  * RETURNED:        True if the event is handled, false otherwise.
  60.  *
  61.  ***********************************************************************/
  62. static Boolean MainFormHandleEvent(EventPtr event)
  63. {
  64.     Boolean        handled = false;
  65.     EventType    newEvent;
  66.  
  67.  
  68.    if (event->eType == ctlSelectEvent)
  69.        {
  70.         // A control button is pressed and released.
  71.         // The exit button being the only button, stop the application.
  72.        MemSet(&newEvent, sizeof(EventType), 0);
  73.        newEvent.eType = appStopEvent;
  74.        EvtAddEventToQueue(&newEvent);
  75.         handled = true;
  76.           }
  77.     return(handled);
  78. }
  79.  
  80.  
  81. /***********************************************************************
  82.  *
  83.  * FUNCTION:        EventLoop
  84.  *
  85.  * DESCRIPTION:    A simple loop that obtains events from the Event
  86.  *                        Manager and passes them on to various applications and
  87.  *                        system event handlers before passing them on to
  88.  *                        FrmHandleEvent for default processing.
  89.  *
  90.  * PARAMETERS:        None.
  91.  *
  92.  * RETURNED:        Nothing.
  93.  *
  94.  ***********************************************************************/
  95. static void EventLoop(void)
  96. {
  97.     EventType    event;
  98.     
  99.     do
  100.         {
  101.         // Get the next available event.
  102.         EvtGetEvent(&event, evtWaitForever);
  103.         
  104.         // Give the system a chance to handle the event.
  105.         if (! SysHandleEvent (&event))
  106.  
  107.             // Give the application a chance to handle the event.
  108.             if (! MainFormHandleEvent(&event))
  109.  
  110.                 // Let the form object provide default handling of the event.
  111.                 FrmHandleEvent(FrmGetActiveForm(), &event);
  112.         } 
  113.     while (event.eType != appStopEvent);
  114.                                 // ** SPECIAL NOTE **
  115.                                 // In order for the Emulator to exit
  116.                                 // cleanly when the File|Quit menu option is
  117.                                 // selected, the running application
  118.                                 // must exit.  The emulator will generate an 
  119.                                 // ╥appStopEvent╙ when Quit is selected.
  120.                                 
  121.  
  122. }
  123.  
  124.  
  125. /***********************************************************************
  126.  *
  127.  * FUNCTION:        PilotMain
  128.  *
  129.  * DESCRIPTION:    This function is the equivalent of a main() function
  130.  *                        in standard ╥C╙.  It is called by the Emulator to begin
  131.  *                        execution of this application.
  132.  *
  133.  * PARAMETERS:        cmd - command specifying how to launch the application.
  134.  *                        cmdPBP - parameter block for the command.
  135.  *                        launchFlags - flags used to configure the launch.            
  136.  *
  137.  * RETURNED:        Any applicable error code.
  138.  *
  139.  ***********************************************************************/
  140. DWord PilotMain(Word cmd, Ptr cmdPBP, Word launchFlags)
  141. {
  142.     // Set up initial form.
  143.  
  144.     if (cmd == sysAppLaunchCmdNormalLaunch)
  145.     {
  146.         CFInit();
  147.  
  148.         StartApplication();
  149.             
  150.         // Start up the event loop.
  151.         EventLoop();
  152.         
  153.         CFRestoreAllFonts();
  154.     }
  155.     
  156.     return(0);
  157. }
  158.  
  159.  
  160.  
  161.