home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hand Held Organizer Toolkit
/
walnutcreekcdrom-handheldorganizertoolkit-march1998.iso
/
PalmPilot
/
development
/
pfc.sit
/
Src
/
TestApp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-04-25
|
4KB
|
161 lines
/***********************************************************************
*
* Copyright ⌐ 1997 Ken Hancock
*
* FILE: TestApp.c
*
* DESCRIPTION: Sample application to demonstrate custom fonts
*
* REVISION HISTORY:
* 4/8/97 KSH Initial version
*
**********************************************************************/
#include <Pilot.h> // all the system toolbox headers
#include "TestAppRsc.h" // application resource defines
#include "CustomFonts.h"
/***********************************************************************
* Prototypes for internal functions
**********************************************************************/
static void StartApplication(void);
static Boolean MainFormHandleEvent(EventPtr event);
static void EventLoop(void);
/***********************************************************************
*
* FUNCTION: StartApplication
*
* DESCRIPTION: This routine sets up the initial state of the application.
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
static void StartApplication(void)
{
FormPtr frm;
// Initialize and draw the main memo pad form.
frm = FrmInitForm(mainForm);
CFSwapFont(ledFont,1000);
FldSetFont(FrmGetObjectPtr(frm,FrmGetObjectIndex(frm,1002)),ledFont);
FrmSetActiveForm(frm);
FrmDrawForm(frm);
}
/***********************************************************************
*
* FUNCTION: MainFormHandleEvent
*
* DESCRIPTION: Handles processing of events for the ╥main╙ form.
*
* PARAMETERS: event - the most recent event.
*
* RETURNED: True if the event is handled, false otherwise.
*
***********************************************************************/
static Boolean MainFormHandleEvent(EventPtr event)
{
Boolean handled = false;
EventType newEvent;
if (event->eType == ctlSelectEvent)
{
// A control button is pressed and released.
// The exit button being the only button, stop the application.
MemSet(&newEvent, sizeof(EventType), 0);
newEvent.eType = appStopEvent;
EvtAddEventToQueue(&newEvent);
handled = true;
}
return(handled);
}
/***********************************************************************
*
* FUNCTION: EventLoop
*
* DESCRIPTION: A simple loop that obtains events from the Event
* Manager and passes them on to various applications and
* system event handlers before passing them on to
* FrmHandleEvent for default processing.
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
static void EventLoop(void)
{
EventType event;
do
{
// Get the next available event.
EvtGetEvent(&event, evtWaitForever);
// Give the system a chance to handle the event.
if (! SysHandleEvent (&event))
// Give the application a chance to handle the event.
if (! MainFormHandleEvent(&event))
// Let the form object provide default handling of the event.
FrmHandleEvent(FrmGetActiveForm(), &event);
}
while (event.eType != appStopEvent);
// ** SPECIAL NOTE **
// In order for the Emulator to exit
// cleanly when the File|Quit menu option is
// selected, the running application
// must exit. The emulator will generate an
// ╥appStopEvent╙ when Quit is selected.
}
/***********************************************************************
*
* FUNCTION: PilotMain
*
* DESCRIPTION: This function is the equivalent of a main() function
* in standard ╥C╙. It is called by the Emulator to begin
* execution of this application.
*
* PARAMETERS: cmd - command specifying how to launch the application.
* cmdPBP - parameter block for the command.
* launchFlags - flags used to configure the launch.
*
* RETURNED: Any applicable error code.
*
***********************************************************************/
DWord PilotMain(Word cmd, Ptr cmdPBP, Word launchFlags)
{
// Set up initial form.
if (cmd == sysAppLaunchCmdNormalLaunch)
{
CFInit();
StartApplication();
// Start up the event loop.
EventLoop();
CFRestoreAllFonts();
}
return(0);
}