home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************
- *
- * PROJECT: PS1999
- * FILE: Starter.c
- * AUTHOR: W.F. Ableson, Bachmann Software and Services, LLC
- *
- * DECLARER: PS1999
- *
- * DESCRIPTION: Exercises Pentax Print Manager Functions
- *
- *
- **********************************************************************/
- #include <Pilot.h>
- #include <SysEvtMgr.h>
- #include <PrintMgr.h>
- #include "PS1999Rsc.h"
-
-
-
- /***********************************************************************
- *
- * Entry Points
- *
- ***********************************************************************/
-
-
- /***********************************************************************
- *
- * Internal Structures
- *
- ***********************************************************************/
- typedef struct
- {
- Byte replaceme;
- } StarterPreferenceType;
-
- typedef struct
- {
- Byte replaceme;
- } StarterAppInfoType;
-
- typedef StarterAppInfoType* StarterAppInfoPtr;
-
-
- /***********************************************************************
- *
- * Global variables
- *
- ***********************************************************************/
- //static Boolean HideSecretRecords;
-
-
- /***********************************************************************
- *
- * Internal Constants
- *
- ***********************************************************************/
- #define appFileCreator 'PS99'
- #define appVersionNum 0x01
- #define appPrefID 0x00
- #define appPrefVersionNum 0x01
-
-
- // Define the minimum OS version we support
- #define ourMinVersion sysMakeROMVersion(2,0,0,sysROMStageRelease,0)
-
-
- /***********************************************************************
- *
- * Internal Functions
- *
- ***********************************************************************/
-
- void DoPrintDemo(FormPtr formP);
-
-
- /***********************************************************************
- *
- * FUNCTION: RomVersionCompatible
- *
- * DESCRIPTION: This routine checks that a ROM version is meet your
- * minimum requirement.
- *
- * PARAMETERS: requiredVersion - minimum rom version required
- * (see sysFtrNumROMVersion in SystemMgr.h
- * for format)
- * launchFlags - flags that indicate if the application
- * UI is initialized.
- *
- * RETURNED: error code or zero if rom is compatible
- *
- * REVISION HISTORY:
- *
- ***********************************************************************/
- 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 < sysMakeROMVersion(2,0,0,sysROMStageRelease,0))
- AppLaunchWithCommand(sysFileCDefaultApp, sysAppLaunchCmdNormalLaunch, NULL);
- }
-
- return (sysErrRomIncompatible);
- }
-
- return (0);
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: GetObjectPtr
- *
- * DESCRIPTION: This routine returns a pointer to an object in the current
- * form.
- *
- * PARAMETERS: formId - id of the form to display
- *
- * RETURNED: VoidPtr
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static VoidPtr GetObjectPtr(Word objectID)
- {
- FormPtr frmP;
-
-
- frmP = FrmGetActiveForm();
- return (FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, objectID)));
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: MainFormInit
- *
- * DESCRIPTION: This routine initializes the MainForm form.
- *
- * PARAMETERS: frm - pointer to the MainForm form.
- *
- * RETURNED: nothing
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static void MainFormInit(FormPtr frmP)
- {
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: MainFormDoCommand
- *
- * DESCRIPTION: This routine performs the menu command specified.
- *
- * PARAMETERS: command - menu item id
- *
- * RETURNED: nothing
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static Boolean MainFormDoCommand(Word command)
- {
- Boolean handled = false;
-
- return handled;
- }
-
-
- /*
- MainFormButtonHandler:
- Handle a command sent to the main form.
- Parms: formP - form handling event.
- eventP - event to be handled.
- Return: true - handled (successfully or not)
- false - not handled
- */
- Boolean
- MainFormButtonHandler (FormPtr formP, EventPtr eventP)
- {
- Boolean handled = false;
- switch (eventP->data.ctlEnter.controlID)
- {
- case MainGoButton:
- DoPrintDemo(formP);
- handled = true;
- break;
- default:
- {
- handled = false;
- break;
- }
- }
- return handled;
- }
-
-
-
-
- /***********************************************************************
- *
- * FUNCTION: MainFormHandleEvent
- *
- * DESCRIPTION: This routine is the event handler for the
- * "MainForm" of this application.
- *
- * PARAMETERS: eventP - a pointer to an EventType structure
- *
- * RETURNED: true if the event has handle and should not be passed
- * to a higher level handler.
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static Boolean MainFormHandleEvent(EventPtr eventP)
- {
- Boolean handled = false;
- FormPtr formP;
-
-
- switch (eventP->eType)
- {
- case menuEvent:
- return MainFormDoCommand(eventP->data.menu.itemID);
-
- case ctlSelectEvent:
- // A control button was tapped and released
- formP = FrmGetActiveForm ();
- handled = MainFormButtonHandler (formP, eventP);
- break;
-
- case frmOpenEvent:
- formP = FrmGetActiveForm();
- MainFormInit( formP);
- FrmDrawForm ( formP);
- handled = true;
- break;
-
- default:
- break;
-
- }
-
- return handled;
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: AppHandleEvent
- *
- * DESCRIPTION: This routine loads form resources and set the event
- * handler for the form loaded.
- *
- * PARAMETERS: event - a pointer to an EventType structure
- *
- * RETURNED: true if the event has handle and should not be passed
- * to a higher level handler.
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- 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:
- // ErrFatalDisplay("Invalid Form Load Event");
- break;
-
- }
- return true;
- }
-
- return false;
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: AppEventLoop
- *
- * DESCRIPTION: This routine is the event loop for the application.
- *
- * PARAMETERS: nothing
- *
- * RETURNED: nothing
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- 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);
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: AppStart
- *
- * DESCRIPTION: Get the current application's preferences.
- *
- * PARAMETERS: nothing
- *
- * RETURNED: Err value 0 if nothing went wrong
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static Err AppStart(void)
- {
- StarterPreferenceType prefs;
- Word prefsSize;
-
-
- // Read the saved preferences / saved-state information.
- prefsSize = sizeof(StarterPreferenceType);
- if (PrefGetAppPreferences(appFileCreator, appPrefID, &prefs, &prefsSize, true) !=
- noPreferenceFound)
- {
- }
-
- return 0;
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: AppStop
- *
- * DESCRIPTION: Save the current state of the application.
- *
- * PARAMETERS: nothing
- *
- * RETURNED: nothing
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static void AppStop(void)
- {
- StarterPreferenceType prefs;
-
-
- // Write the saved preferences / saved-state information. This data
- // will be backed up during a HotSync.
- PrefSetAppPreferences (appFileCreator, appPrefID, appPrefVersionNum,
- &prefs, sizeof (prefs), true);
- }
-
-
-
- /***********************************************************************
- *
- * FUNCTION: StarterPilotMain
- *
- * DESCRIPTION: This is the main entry point for the application.
- * PARAMETERS: cmd - word value specifying the launch code.
- * cmdPB - pointer to a structure that is associated with the launch code.
- * launchFlags - word value providing extra information about the launch.
- *
- * RETURNED: Result of launch
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- static DWord StarterPilotMain(Word cmd, Ptr cmdPBP, Word launchFlags)
- {
- Err error;
-
-
- error = RomVersionCompatible (ourMinVersion, launchFlags);
- if (error) return (error);
-
-
- switch (cmd)
- {
- case sysAppLaunchCmdNormalLaunch:
- error = AppStart();
- if (error)
- return error;
-
- FrmGotoForm(MainForm);
- AppEventLoop();
- AppStop();
- break;
-
- default:
- break;
-
- }
-
- return 0;
- }
-
-
- /***********************************************************************
- *
- * FUNCTION: PilotMain
- *
- * DESCRIPTION: This is the main entry point for the application.
- *
- * PARAMETERS: cmd - word value specifying the launch code.
- * cmdPB - pointer to a structure that is associated with the launch code.
- * launchFlags - word value providing extra information about the launch.
- * RETURNED: Result of launch
- *
- * REVISION HISTORY:
- *
- *
- ***********************************************************************/
- DWord PilotMain( Word cmd, Ptr cmdPBP, Word launchFlags)
- {
- return StarterPilotMain(cmd, cmdPBP, launchFlags);
- }
-
-
- UInt refNum = 0;
-
- void DoText(UInt refNum)
- {
- Char buf[100];
- VoidHand bitmapH;
- BitmapPtr pbmp;
- PrnFontType font;
-
-
- StrCopy (font.typeface, "CourierNew10");
- font.height = 10;
- font.bold = true;
- font.italics = false;
- PrnSetFont (refNum, &font);
-
-
- StrPrintF(buf,"What is Bachmann Print Manager?");
- PrnDrawChars(refNum,buf,StrLen(buf),400,40);
- // font.bold = false;
- // PrnSetFont (refNum, &font);
- StrPrintF(buf,"Most computing platforms include printing support right out of the box.");
- PrnDrawChars(refNum,buf,StrLen(buf),10,80);
- StrPrintF(buf,"But Palm Computing elected not to include a printing subsystem in their operating");
- PrnDrawChars(refNum,buf,StrLen(buf),10,120);
- StrPrintF(buf,"system. So although Palm OS based devices include both a serial and infrared port");
- PrnDrawChars(refNum,buf,StrLen(buf),10,160);
- StrPrintF(buf,"for communications, they cannot produce printed output. ");
- PrnDrawChars(refNum,buf,StrLen(buf),10,200);
- StrPrintF(buf,"We designed Bachmann Print Manager as the \"missing\" printing subsystem that Palm");
- PrnDrawChars(refNum,buf,StrLen(buf),10,270);
- StrPrintF(buf,"\"forgot\" to put in their product. Like the Palm's infrared library, serial");
- PrnDrawChars(refNum,buf,StrLen(buf),10,320);
- StrPrintF(buf,"library and network library, Bachmann Print Manager is a standard Palm OS");
- PrnDrawChars(refNum,buf,StrLen(buf),10,360);
- StrPrintF(buf,"Shared Library, so it is easily and tightly integrated with any Palm Pilot");
- PrnDrawChars(refNum,buf,StrLen(buf),10,400);
- StrPrintF(buf,"application. Bachmann Print Manager gives Palm Computing Platform application");
- PrnDrawChars(refNum,buf,StrLen(buf),10,440);
- StrPrintF(buf,"developers the power to create stunning printed output directly from their Palm");
- PrnDrawChars(refNum,buf,StrLen(buf),10,480);
- StrPrintF(buf,"Pilot application.");
- PrnDrawChars(refNum,buf,StrLen(buf),10,520);
- StrPrintF(buf,"Now, with Bachmann Print Manager, you can print any information from your Palm");
- PrnDrawChars(refNum,buf,StrLen(buf),10,620);
- StrPrintF(buf,"Connected Organizer, using either a serial or infrared connection to popular");
- PrnDrawChars(refNum,buf,StrLen(buf),10,660);
- StrPrintF(buf,"portable, standalone or networked printers. There is no longer any need to");
- PrnDrawChars(refNum,buf,StrLen(buf),10,700);
-
- StrPrintF(buf,"synchronize data back to the desktop in order to create printed output that is");
- PrnDrawChars(refNum,buf,StrLen(buf),10,740);
- StrPrintF(buf,"of the caliber you would expect from a Windows application.");
- PrnDrawChars(refNum,buf,StrLen(buf),10,800);
-
- // font.bold = true;
- font.italics = true;
- PrnSetFont (refNum, &font);
-
- StrPrintF(buf,"Visit us at Bachmannsoftware.com and PalmSource.");
- PrnDrawChars(refNum,buf,StrLen(buf),10,1000);
-
- bitmapH = DmGetResource(bitmapRsc,1600);
- if (bitmapH != 0)
- {
- pbmp = (BitmapPtr) MemHandleLock(bitmapH);
- if (pbmp != NULL)
- {
- PrnDrawBitmap(refNum,pbmp,1100,35);
- MemHandleUnlock(bitmapH);
- }
- DmReleaseResource(bitmapH);
- }
- }
-
-
- void DoPrintDemo(FormPtr formP)
- {
- Word index = FrmGetObjectIndex (formP, MainDemoList);
- ListPtr listP = (ListPtr) FrmGetObjectPtr (formP, index);
- Word wDemo;
- Err err;
- Char buf[100];
- RectangleType r;
- VoidHand bitmapH;
- BitmapPtr pbmp;
- PrnFontType font;
-
- wDemo = LstGetSelection(listP);
- if (wDemo == -1) return;
-
- err = SysLibLoad (printMgrTypeID, printMgrCreatorID, &refNum);
- // Check result of loading library.
- if (err)
- {
- // Print Manager failed to load successfully.
- FrmCustomAlert(ErrorAlert,"Failed to Load PrintMgr.\nPlease Verify PrintMgr Installation.","","");
- return;
- }
-
-
-
- switch (wDemo)
- {
- case 0:
- err = PrnOpen (refNum, "Pentax", "Serial");
- if (err)
- {
- StrPrintF(buf,"Failed to Open PrintMgr (%d).",err);
- FrmCustomAlert(ErrorAlert,buf,"","");
- SysLibRemove (refNum);
- return;
- }
-
- // do graphics
- PrnSetOrientation (refNum, prnOrientPortrait);
-
- StrCopy (font.typeface, "Courier New");
- font.height = 10;
- font.bold = true;
- font.italics = false;
- PrnSetFont (refNum, &font);
- StrPrintF(buf,"Bachmann Print Manager");
- PrnDrawChars(refNum,buf,StrLen(buf),200,40);
- PrnDrawChars(refNum,buf,StrLen(buf),900,40);
-
- // draw some line - art !
- r.topLeft.x = 120;
- r.topLeft.y = 10;
- r.extent.x = 590;
- r.extent.y = 850;
- PrnDrawRectangle(refNum,&r,0);
- r.topLeft.x = 820;
- PrnDrawRectangle(refNum,&r,0);
-
- r.topLeft.x = 200;
- r.topLeft.y = 80;
- r.extent.x = 425;
- r.extent.y = 650;
- PrnDrawRectangle(refNum,&r,0);
- r.topLeft.x = 900;
- PrnDrawRectangle(refNum,&r,0);
-
-
- r.topLeft.x = 300;
- r.topLeft.y = 575;
- r.extent.x = 225;
- r.extent.y = 153;
- PrnDrawRectangle(refNum,&r,0);
- r.topLeft.x = 1000;
- PrnDrawRectangle(refNum,&r,0);
-
- r.topLeft.x = 200;
- r.topLeft.y = 572;
- r.extent.x = 425;
- r.extent.y = 0;
- PrnDrawRectangle(refNum,&r,0);
- r.topLeft.x = 900;
- PrnDrawRectangle(refNum,&r,0);
-
-
-
- bitmapH = DmGetResource(bitmapRsc,1000);
- if (bitmapH != 0)
- {
- pbmp = (BitmapPtr) MemHandleLock(bitmapH);
- if (pbmp != NULL)
- {
- PrnDrawBitmap(refNum,pbmp,230,610);
- PrnDrawBitmap(refNum,pbmp,930,610);
- PrnDrawBitmap(refNum,pbmp,230,665);
- PrnDrawBitmap(refNum,pbmp,930,665);
- PrnDrawBitmap(refNum,pbmp,550,610);
- PrnDrawBitmap(refNum,pbmp,1250,610);
- PrnDrawBitmap(refNum,pbmp,550,665);
- PrnDrawBitmap(refNum,pbmp,1250,665);
-
- PrnDrawBitmap(refNum,pbmp,185,800);
- PrnDrawBitmap(refNum,pbmp,885,800);
- PrnDrawBitmap(refNum,pbmp,320,800);
- PrnDrawBitmap(refNum,pbmp,1020,800);
- PrnDrawBitmap(refNum,pbmp,455,800);
- PrnDrawBitmap(refNum,pbmp,1155,800);
- PrnDrawBitmap(refNum,pbmp,590,800);
- PrnDrawBitmap(refNum,pbmp,1290,800);
- MemHandleUnlock(bitmapH);
- }
- DmReleaseResource(bitmapH);
- }
-
- bitmapH = DmGetResource(bitmapRsc,1600);
- if (bitmapH != 0)
- {
- pbmp = (BitmapPtr) MemHandleLock(bitmapH);
- if (pbmp != NULL)
- {
- PrnDrawBitmap(refNum,pbmp,210,100);
- PrnDrawBitmap(refNum,pbmp,910,100);
- PrnDrawBitmap(refNum,pbmp,210,200);
- PrnDrawBitmap(refNum,pbmp,910,200);
- PrnDrawBitmap(refNum,pbmp,210,300);
- PrnDrawBitmap(refNum,pbmp,910,300);
- PrnDrawBitmap(refNum,pbmp,210,400);
- PrnDrawBitmap(refNum,pbmp,910,400);
- PrnDrawBitmap(refNum,pbmp,210,500);
- PrnDrawBitmap(refNum,pbmp,910,500);
-
-
- PrnDrawBitmap(refNum,pbmp,540,100);
- PrnDrawBitmap(refNum,pbmp,1240,100);
- PrnDrawBitmap(refNum,pbmp,540,200);
- PrnDrawBitmap(refNum,pbmp,1240,200);
- PrnDrawBitmap(refNum,pbmp,540,300);
- PrnDrawBitmap(refNum,pbmp,1240,300);
- PrnDrawBitmap(refNum,pbmp,540,400);
- PrnDrawBitmap(refNum,pbmp,1240,400);
- PrnDrawBitmap(refNum,pbmp,540,500);
- PrnDrawBitmap(refNum,pbmp,1240,500);
-
- MemHandleUnlock(bitmapH);
- }
- DmReleaseResource(bitmapH);
- }
-
-
- StrPrintF(buf,"www.bachmannsoftware.com");
- PrnDrawChars(refNum,buf,StrLen(buf),185,915);
- PrnDrawChars(refNum,buf,StrLen(buf),885,915);
-
- PrnNewPage(refNum);
- /* FrmCustomAlert(ErrorAlert,"NewPage","","");
- DoText(refNum);
- PrnNewPage(refNum);
- */
- break;
- case 99:
- err = PrnOpen (refNum, "Pentax", "Infrared");
- if (err)
- {
- StrPrintF(buf,"Failed to Open PrintMgr (%d).",err);
- FrmCustomAlert(ErrorAlert,buf,"","");
- SysLibRemove (refNum);
- return;
- }
-
- // do graphics
- PrnSetOrientation (refNum, prnOrientPortrait);
-
- StrCopy (font.typeface, "Courier New");
- font.height = 10;
- font.bold = true;
- font.italics = false;
- PrnSetFont (refNum, &font);
- StrPrintF(buf,"Bachmann Print Manager");
- PrnDrawChars(refNum,buf,StrLen(buf),500,40);
-
- // draw some line - art !
- r.topLeft.x = 420;
- r.topLeft.y = 10;
- r.extent.x = 590;
- r.extent.y = 850;
- PrnDrawRectangle(refNum,&r,0);
-
- r.topLeft.x = 500;
- r.topLeft.y = 80;
- r.extent.x = 425;
- r.extent.y = 650;
- PrnDrawRectangle(refNum,&r,0);
-
-
- r.topLeft.x = 600;
- r.topLeft.y = 575;
- r.extent.x = 225;
- r.extent.y = 153;
- PrnDrawRectangle(refNum,&r,0);
-
- r.topLeft.x = 500;
- r.topLeft.y = 572;
- r.extent.x = 425;
- r.extent.y = 0;
- PrnDrawRectangle(refNum,&r,0);
-
-
-
- bitmapH = DmGetResource(bitmapRsc,1600);
- if (bitmapH != 0)
- {
- pbmp = (BitmapPtr) MemHandleLock(bitmapH);
- if (pbmp != NULL)
- {
- PrnDrawBitmap(refNum,pbmp,510,610);
- PrnDrawBitmap(refNum,pbmp,510,665);
- PrnDrawBitmap(refNum,pbmp,850,610);
- PrnDrawBitmap(refNum,pbmp,850,665);
-
- PrnDrawBitmap(refNum,pbmp,485,800);
- PrnDrawBitmap(refNum,pbmp,620,800);
- PrnDrawBitmap(refNum,pbmp,755,800);
- PrnDrawBitmap(refNum,pbmp,890,800);
- MemHandleUnlock(bitmapH);
- }
- DmReleaseResource(bitmapH);
- }
-
- StrPrintF(buf,"www.bachmannsoftware.com");
- PrnDrawChars(refNum,buf,StrLen(buf),485,915);
- PrnNewPage(refNum);
-
-
- break;
- case 1:
- err = PrnOpen (refNum, "Pentax", "Serial");
- if (err)
- {
- StrPrintF(buf,"Failed to Open PrintMgr (%d).",err);
- FrmCustomAlert(ErrorAlert,buf,"","");
- SysLibRemove (refNum);
- return;
- }
-
- // portrait text
- PrnSetOrientation (refNum, prnOrientPortrait);
- DoText(refNum);
- PrnNewPage(refNum);
-
- break;
- case 2:
- err = PrnOpen (refNum, "Pentax", "Serial");
- if (err)
- {
- StrPrintF(buf,"Failed to Open PrintMgr (%d).",err);
- FrmCustomAlert(ErrorAlert,buf,"","");
- SysLibRemove (refNum);
- return;
- }
- // landscape text
- PrnSetOrientation (refNum, prnOrientLandscape);
- DoText(refNum);
- PrnNewPage(refNum);
- break;
- }
- PrnClose(refNum);
- SysLibRemove (refNum);
- FrmCustomAlert(ErrorAlert,"Done.","","");
- return;
- }