CDump class

Location

palmlib/ui/dump.h
palmlib/ui/dump.cpp

Dependencies

No dependencies.

Tutorial

#include 
#include 
#include "PalmLibTestRsc.h"

// Step 1: We need the Dump.h and Dump.cpp file.
#include "Dump.h"

//////////////////////////////////////////////////////////////////////////////
// Globals
//

extern void TestPackMechanism();

//////////////////////////////////////////////////////////////////////////////
// Output dump
//

// Step 2: We define a global dump context, so everybody can access it.
CDump output;

//////////////////////////////////////////////////////////////////////////////
// Internal Constants
//

const unsigned long appFileCreator = 'STRT';
const unsigned short appVersionNum = 0x01;
const unsigned short appPrefID = 0x00;
const unsigned short appPrefVersionNum = 0x01;
const unsigned long version20 = 0x02000000;

//////////////////////////////////////////////////////////////////////////////
// ::RomVersionCompatible()
//

static Err RomVersionCompatible(DWord requiredVersion, Word launchFlags)
{
	DWord romVersion;

	// See if we're on in minimum required version of the ROM or later.
	FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
	if (romVersion < requiredVersion)
	{
		if ((launchFlags & (sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp)) ==
			(sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp))
		{
			FrmAlert (RomIncompatibleAlert);
		
			// Pilot 1.0 will continuously relaunch this app unless we switch to 
			// another safe one.
			if (romVersion < version20)
			{
				AppLaunchWithCommand(sysFileCDefaultApp, sysAppLaunchCmdNormalLaunch, NULL);
			}
		}
		
		return (sysErrRomIncompatible);
	}

	return (0);
}

//////////////////////////////////////////////////////////////////////////////
// ::MainFormInit()
//

static void MainFormInit(FormPtr frmP)
{
	// Step 3: We register the editfield and the scrollbar which is created
	//         in the constructor (look at palmlibtest.rsrc).
	output.Register(frmP, MainOutputField, MainContentScrollBar);
}

//////////////////////////////////////////////////////////////////////////////
// ::MainFormDoCommand()
//

static Boolean MainFormDoCommand(Word command)
{
	Boolean handled = false;

	switch (command)
	{
		case MainOptionsAboutStarterApp:
			handled = true;
			break;
		case ScenarioPackedRecordScenario:
			TestPackMechanism();			
			handled = true;
			break;
	}
	return handled;
}

//////////////////////////////////////////////////////////////////////////////
// ::MainFormHandleEvent()
//

static Boolean MainFormHandleEvent(EventPtr eventP)
{
    Boolean handled = false;
    FormPtr frmP;

	switch (eventP->eType) 
	{
		case menuEvent:
			return MainFormDoCommand(eventP->data.menu.itemID);

		case frmOpenEvent:
			frmP = FrmGetActiveForm();
			MainFormInit( frmP);
			FrmDrawForm ( frmP);

			// Step 4: Now we can fill the output buffer with text.
			output.Puts("Welcome to the Palm Bazaar.\n"
						"This application tests various PalmLib scenarios.\n"
						"Please use the menu to select a scenario.\n\n");
			handled = true;
			break;

		default:
			// Step 5: To get response to user actions we handle some events.
			handled = output.HandleEvent(eventP);
			break;
		
	}
	return handled;
}

//////////////////////////////////////////////////////////////////////////////
// ::AppHandleEvent()
//

static Boolean AppHandleEvent( EventPtr eventP)
{
	Word formId;
	FormPtr frmP;

	if (eventP->eType == frmLoadEvent)
	{
		// Load the form resource.
		formId = eventP->data.frmLoad.formID;
		frmP = FrmInitForm(formId);
		FrmSetActiveForm(frmP);

		// Set the event handler for the form.  The handler of the currently
		// active form is called by FrmHandleEvent each time is receives an
		// event.
		switch (formId)
		{
			case MainForm:
			{
					FrmSetEventHandler(frmP, MainFormHandleEvent);
					break;
			}

			default:
			{
				break;
			}

		}
		return true;
	}
	return false;
}

//////////////////////////////////////////////////////////////////////////////
// ::AppEventLoop()
//

static void AppEventLoop(void)
{
	Word error;
	EventType event;


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

//////////////////////////////////////////////////////////////////////////////
// ::AppStart()
//

static Err AppStart(void)
{
   return 0;
}

//////////////////////////////////////////////////////////////////////////////
// ::AppStop()
//

static void AppStop(void)
{
}

//////////////////////////////////////////////////////////////////////////////
// ::PilotMain()
//

DWord PilotMain( Word cmd, Ptr cmdPBP, Word launchFlags)
{
	Err error;

	error = RomVersionCompatible (version20, launchFlags);
	if (error) return (error);

	switch (cmd)
	{
		case sysAppLaunchCmdNormalLaunch:
		{
			error = AppStart();
			if (error) 
				return error;
				
			FrmGotoForm(MainForm);
			AppEventLoop();
			AppStop();
			break;
		}
		default:
		{
			break;
		}
	}
	return 0;
}