The "c" file code follows. The "rcp" file code comes after that:
/*
* PSEDAT.c
*
* main file for PSEDAT
*
* This wizard-generated code is based on code adapted from the
* stationery files distributed as part of the Palm OS SDK 4.0.
*
* Copyright (c) 1999-2000 Palm, Inc. or its subsidiaries.
* All rights reserved.
*/
#include <PalmOS.h>
#include <PalmOSGlue.h>
#include "PSEDAT.h"
#include "PSEDAT_Rsc.h"
Err SetFieldTextFromStr(FieldPtr field, Char *s, Boolean redraw);
/*********************************************************************
* Entry Points
*********************************************************************/
/*********************************************************************
* Global variables
*********************************************************************/
/*********************************************************************
* Internal Constants
*********************************************************************/
/* Define the minimum OS version we support */
#define ourMinVersion sysMakeROMVersion(3,0,0,sysROMStageDevelopment,0)
#define kPalmOS20Version sysMakeROMVersion(2,0,0,sysROMStageDevelopment,0)
/*********************************************************************
* Internal Functions
*********************************************************************/
/*
* FUNCTION: GetObjectPtr
*
* DESCRIPTION:
*
* This routine returns a pointer to an object in the current form.
*
* PARAMETERS:
*
* formId
* id of the form to display
*
* RETURNED:
* address of object as a void pointer
*/
static void * GetObjectPtr(UInt16 objectID)
{
FormType * frmP;
frmP = FrmGetActiveForm();
return FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, objectID));
}
/*
* FUNCTION: SetFieldTextFromStr(FieldPtr field, Char *s, Boolean redraw)
*
* DESCRIPTION: This routine puts text in a screen object.
*
* PARAMETERS:
*
* frm
*
*/
Err SetFieldTextFromStr(FieldPtr field, Char *s, Boolean redraw)
{
MemHandle h;
h = FldGetTextHandle(field);
if (h)
{
Err err;
FldSetTextHandle(field, NULL);
err= MemHandleResize(h,StrLen(s)+1);
if (err != errNone)
{
FldSetTextHandle(field, h); //Restore handle.
return err;
}
}
else
{
h = MemHandleNew(StrLen(s) + 1);
if (!h)
return memErrNotEnoughSpace;
}
//At this point, we have a handle of the correct size.
//Copy the string to the locked handle.
StrCopy((Char*) MemHandleLock(h), s);
//Unlock the string handle.
MemHandleUnlock(h);
FldSetTextHandle(field, h);
if (redraw)
FldDrawField(field);
return errNone;
}
/*
* FUNCTION: ClearFieldText
*
* DESCRIPTION: This routine puts text in a screen object.
*
* PARAMETERS:
*
* frm
*
*/
void ClearFieldText(FieldPtr field, Boolean redraw)
{
SetFieldTextFromhandle(field, NULL, redraw);
}
//Yet another function to set the text in a field
void mySetFieldText(FormType *frmP, UInt16 fieldID, Char *st)
{
FieldType *fldP;
MemHandle textH;
Char *textP;
UInt8 fldLen=0;
fldP = FrmGetObjectPtr (frmP, FrmGetObjectIndex (frmP, fieldID));
FldFreeMemory(fldP);
FldSetTextHandle (fldP , NULL);
fldLen=FldGetMaxChars(fldP);
textH=MemHandleNew(fldLen+1);
if (textH){
textP=MemHandleLock(textH);
StrNCopy(textP,st,fldLen);
textP[fldLen]=0;
MemHandleUnlock(textH);
FldSetTextHandle (fldP , textH);
}
//optional draw if the form is the current active form
if (frmP==FrmGetActiveForm())
FldDrawField(fldP);
}
/*
* FUNCTION: MainFormInit
*
* DESCRIPTION: This routine initializes the MainForm form.
*
* PARAMETERS:
*
* frm
* pointer to the MainForm form.
*/
static void MainFormInit(FormType *frmP)
{
FieldType *field;
const char *wizardDescription;
UInt16 fieldIndex;
fieldIndex = FrmGetObjectIndex(frmP, MainDescriptionField);
field = (FieldType *)FrmGetObjectPtr(frmP, fieldIndex);
FrmSetFocus(frmP, fieldIndex);
wizardDescription =
"C application\n"
"Creator Code: !!$g\n"
"\n"
"Other SDKs:\n"
;
/* dont stack FldInsert calls, since each one generates a
* fldChangedEvent, and multiple uses can overflow the event queue */
FldInsert(field, wizardDescription, StrLen(wizardDescription));
}
static void TransformerFormInit(FormType *frmP)
{
FieldType *field;
const char *wizardDescription;
UInt16 fieldIndex;
fieldIndex = FrmGetObjectIndex(frmP, kVA);
field = (FieldType *)FrmGetObjectPtr(frmP, fieldIndex);
FrmSetFocus(frmP, fieldIndex);
wizardDescription =
"C application\n"
"Creator Code: !!$g\n"
"\n"
"Other SDKs:\n"
;
/* dont stack FldInsert calls, since each one generates a
* fldChangedEvent, and multiple uses can overflow the event queue */
FldInsert(field, wizardDescription, StrLen(wizardDescription));
}
/*
* FUNCTION: MainFormDoCommand
*
* DESCRIPTION: This routine performs the menu command specified.
*
* PARAMETERS:
*
* command
* menu item id
*/
static Boolean MainFormDoCommand(UInt16 command)
{
Boolean handled = false;
switch (command)
{
case OptionsAboutPSEDAT:
{
FormType * frmP;
/* Clear the menu status from the display */
MenuEraseStatus(0);
/* Display the About Box. */
frmP = FrmInitForm (AboutForm);
FrmDoDialog (frmP);
FrmDeleteForm (frmP);
handled = true;
break;
}
case PD1_XFMR:
{
FormType * frmP;
/* Clear the menu status from the display */
MenuEraseStatus(0);
/* Display the Transformer Box. */
frmP = FrmInitForm (TransformerForm);
//FrmSetEventHandler(TransformerForm);
FrmDoDialog (frmP);
FrmDeleteForm (frmP);
handled = true;
break;
}
}
return handled;
}
/*
* FUNCTION: TransformerFormDoCommand
*
* DESCRIPTION: This routine performs the menu command specified.
*
* PARAMETERS:
*
* command
* menu item id
*/
static Boolean TransformerFormDoCommand(UInt16 command)
{
Boolean handled = false;
switch (command)
{
case TransAbout:
{
FormType * frmP;
/* Clear the menu status from the display */
MenuEraseStatus(0);
/* Display the About Box. */
//frmP = FrmInitForm (AboutForm);
//FrmDoDialog (frmP);
//FrmDeleteForm (frmP);
FrmGotoForm(AboutForm);
handled = true;
break;
}
case Save:
{
FormType * frmP;
Char* pText = (Char*) MemPtrNew(5); // allocate 5 bytes
MenuEraseStatus(0);
frmP = FrmInitForm (TransformerForm);
StrCopy(pText, "2000");
mySetFieldText(frmP, kVA, pText);
FrmDoDialog (frmP);
FrmDeleteForm (frmP);
handled = true;
break;
}
/*
case Save:
{
FormType * frmP;
Char* pText = (Char*) MemPtrNew(5); // allocate 5 bytes
FieldType * field;
Boolean redraw;
struct transformer
{
UInt16 TranskVA;
} My_Transformer;
redraw=true;
// Clear the menu status from the display
MenuEraseStatus(0);
frmP = FrmInitForm (TransformerForm);
field = GetObjectPtr(FrmGetObjectIndex(frmP, kVA));
// copy kVA into the char ptr
StrCopy(pText, "2000");
//Actions taken due to selection of transformer "save"
//SetFieldTextFromStr(field, pText, redraw);
mySetFieldText(frmP, kVA, pText);
//mySetFieldText(FormType *frmP, UInt16 fieldID, Char *st)
//Actions that follow if nothing is done by code
//to save data
// Display the Transformer Box.
FrmDoDialog (frmP);
FrmDeleteForm (frmP);
handled = true;
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 was handled and should not be passed to
* FrmHandleEvent
*/
static Boolean MainFormHandleEvent(EventType * eventP)
{
Boolean handled = false;
FormType * frmP;
switch (eventP->eType)
{
case menuEvent:
return MainFormDoCommand(eventP->data.menu.itemID);
case frmOpenEvent:
frmP = FrmGetActiveForm();
FrmDrawForm(frmP);
MainFormInit(frmP);
handled = true;
break;
case frmUpdateEvent:
/*
* To do any custom drawing here, first call
* FrmDrawForm(), then do your drawing, and
* then set handled to true.
*/
break;
case ctlSelectEvent:
{
if (eventP->data.ctlSelect.controlID == MainClearTextButton)
{
/* The "Clear" button was hit. Clear the contents of the field. */
FieldType * field = (FieldType*)GetObjectPtr(MainDescriptionField);
if (field)
{
FldDelete(field, 0, 0xFFFF);
FldDrawField(field);
}
break;
}
break;
}
}
return handled;
}
/*
* FUNCTION: TransformerFormHandleEvent
*
* DESCRIPTION:
*
* This routine is the event handler for the "TransformerForm" of this
* application.
*
* PARAMETERS:
*
* eventP
* a pointer to an EventType structure
*
* RETURNED:
* true if the event was handled and should not be passed to
* FrmHandleEvent
*/
static Boolean TransformerFormHandleEvent(EventType * eventP)
{
Boolean handled = false;
FormType * frmP;
switch (eventP->eType)
{
case menuEvent:
return TransformerFormDoCommand(eventP->data.menu.itemID);
case frmOpenEvent:
frmP = FrmGetActiveForm();
FrmDrawForm(frmP);
TransformerFormInit(frmP);
handled = true;
break;
case frmUpdateEvent:
/*
* To do any custom drawing here, first call
* FrmDrawForm(), then do your drawing, and
* then set handled to true.
*/
break;
case ctlSelectEvent:
{
if (eventP->data.ctlSelect.controlID == XFMROKButton)
{
/* The "Clear" button was hit. Clear the contents of the field. */
FieldType * field = (FieldType*)GetObjectPtr(MainDescriptionField);
if (field)
{
FldDelete(field, 0, 0xFFFF);
FldDrawField(field);
}
break;
}
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 was handled and should not be passed
* to a higher level handler.
*/
static Boolean AppHandleEvent(EventType * eventP)
{
UInt16 formId;
FormType * 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;
case TransformerForm:
FrmSetEventHandler(frmP, TransformerFormHandleEvent);
break;
}
return true;
}
return false;
}
/*
* FUNCTION: AppEventLoop
*
* DESCRIPTION: This routine is the event loop for the application.
*/
static void AppEventLoop(void)
{
UInt16 error;
EventType event;
do
{
/* change timeout if you need periodic nilEvents */
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.
*
* RETURNED:
* errNone - if nothing went wrong
*/
static Err AppStart(void)
{
return errNone;
}
/*
* FUNCTION: AppStop
*
* DESCRIPTION: Save the current state of the application.
*/
static void AppStop(void)
{
/* Close all the open forms. */
FrmCloseAllForms();
}
/*
* 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
* These flags are one of the parameters to your app's PilotMain
*
* RETURNED:
* error code or zero if ROM version is compatible
*/
static Err RomVersionCompatible(UInt32 requiredVersion, UInt16 launchFlags)
{
UInt32 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);
/* Palm OS versions before 2.0 will continuously relaunch this
* app unless we switch to another safe one. */
if (romVersion < kPalmOS20Version)
{
AppLaunchWithCommand(
sysFileCDefaultApp,
sysAppLaunchCmdNormalLaunch, NULL);
}
}
return sysErrRomIncompatible;
}
return errNone;
}
/*
* 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, errNone if all went OK
*/
UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
{
Err error;
error = RomVersionCompatible (ourMinVersion, launchFlags);
if (error) return (error);
switch (cmd)
{
case sysAppLaunchCmdNormalLaunch:
error = AppStart();
if (error)
return error;
/*
* start application by opening the main form
* and then entering the main event loop
*/
FrmGotoForm(MainForm);
AppEventLoop();
AppStop();
break;
}
return errNone;
}
// PSEDAT_Rsc.rcp
//
// PilRC-format resources for PSEDAT
//
// Generated by the CodeWarrior for Palm OS V9 application wizard
GENERATEHEADER "PSEDAT_Rsc.h"
RESETAUTOID 1000
MENU ID MainMenuBar
BEGIN
PULLDOWN "Edit"
BEGIN
MENUITEM "Undo" ID 10000 "U"
MENUITEM "Cut" ID 10001 "X"
MENUITEM "Copy"ID 10002 "C"
MENUITEM "Paste" ID 10003 "P"
MENUITEM "Select All" ID 10004 "S"
MENUITEM SEPARATOR ID 10005
MENUITEM "Keyboard" ID 10006 "K"
MENUITEM "Graffiti Help" ID 10007 "G"
END
PULLDOWN "Equipment"
BEGIN
MENUITEM "XFMR" ID PD1_XFMR "N"
END
PULLDOWN "Help"
BEGIN
MENUITEM "About PSEDAT" ID OptionsAboutPSEDAT
END
END
MENU ID EditOnlyMenuBar
BEGIN
PULLDOWN "Edit"
BEGIN
MENUITEM "Undo" ID 10000 "U"
MENUITEM "Cut" ID 10001 "X"
MENUITEM "Copy"ID 10002 "C"
MENUITEM "Paste" ID 10003 "P"
MENUITEM "Select All" ID 10004 "S"
MENUITEM SEPARATOR ID 10005
MENUITEM "Keyboard" ID 10006 "K"
MENUITEM "Graffiti Help" ID 10007 "G"
END
END
ALERT ID RomIncompatibleAlert
DEFAULTBUTTON 0
ERROR
BEGIN
TITLE "System Incompatible"
MESSAGE "System Version 3.0 or greater is required to run this
application."
BUTTONS "OK"
END
FORM ID MainForm AT (0 0 160 160)
NOSAVEBEHIND NOFRAME
MENUID MainMenuBar
BEGIN
TITLE "PSEDAT"
GRAFFITISTATEINDICATOR AT (149 148)
FIELD ID MainDescriptionField AT (0 16 160 126)
MULTIPLELINES
MAXCHARS 1024 NONEDITABLE
BUTTON "Clear Text" ID MainClearTextButton AT (1 147 AUTO 12)
END
FORM ID AboutForm AT (2 2 156 156)
SAVEBEHIND FRAME MODAL
DEFAULTBTNID AboutOKButton
BEGIN
TITLE "About PSEDAT"
LABEL "PSEDAT"
AUTOID AT (CENTER 23)
FONT 2
LABEL
"This application\r" \
"Copyright (C) 2005 by\r" \
"Del John Ventruella.\r"\
"All Rights Reserved."
AUTOID AT (23 54)
FIELD ID AboutVersionField AT (50 100 60 12)
NONEDITABLE
MAXCHARS 80
FONT 1
BUTTON "OK" ID AboutOKButton AT (58 133 40 12)
END
ICONFAMILYEX
BEGIN
BITMAP "icon-lg-1.bmp" BPP 1
BITMAP "icon-lg-2.bmp" BPP 2
BITMAP "icon-lg-8.bmp" BPP 8 TRANSPARENTINDEX 210 COMPRESS
BITMAP "icon-lg-1-d144.bmp" BPP 1 DENSITY 2
BITMAP "icon-lg-2-d144.bmp" BPP 2 DENSITY 2
BITMAP "icon-lg-8-d144.bmp" BPP 8 TRANSPARENTINDEX 210 COMPRESS DENSITY
2
END
SMALLICONFAMILYEX
BEGIN
BITMAP "icon-sm-1.bmp" BPP 1
BITMAP "icon-sm-2.bmp" BPP 2
BITMAP "icon-sm-8.bmp" BPP 8 TRANSPARENTINDEX 210 COMPRESS
BITMAP "icon-sm-1-d144.bmp" BPP 1 DENSITY 2
BITMAP "icon-sm-2-d144.bmp" BPP 2 DENSITY 2
BITMAP "icon-sm-8-d144.bmp" BPP 8 TRANSPARENTINDEX 210 COMPRESS DENSITY
2
END
FORM ID TransformerForm AT ( 0 0 160 160 )
NOFRAME MENUID DataEntryMenu
BEGIN
TITLE "Transformer - PSEDAT"
BUTTON "OK" ID XFMROKButton AT (62 137 40 12)
LABEL "New Label" ID kVA AT (57 58)
END
MENU ID DataEntryMenu
BEGIN
PULLDOWN "PSEDAT"
BEGIN
MENUITEM "Save" ID Save "N"
MENUITEM "Exit" ID 1001 "O"
END
PULLDOWN "Help"
BEGIN
MENUITEM "About..." ID TransAbout
END
END
----- Original Message -----
From: "Robert Moynihan" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[email protected]>
Sent: Thursday, October 13, 2005 11:24 PM
Subject: Re: Form Loading Problem
> Del Ventruella wrote:
>
> >Basically, as far as I can tell (allowing for the fact that my emulator
> >seems to produce some screen artifacts and to not update properly)
> >the code does absolutely nothing. There is a screen response, but after
> >the blurred area appears near the top, nothing.
> >
> >
> Is the "TransformerForm" correctly defined? Does it include the field
> that you want to target, and is the field usable?
>
> >One othere question (please):
> >
> >I am still having trouble with another very basic activity. I can get a
> >form to load,
> >but only if I call it from the main menu (main form menu) response table.
> >If I use the
> >following code in the main menu, linked to an "about form" menu item, I
get
> >the
> >about menu form. If I use this in a form that is called after the main
> >menu, I get no
> >response. The form I've called from the main menu remains where it was.
> >
> >
> I'm wondering if some of your trouble stems from the fact that you are
> trying to popup forms in direct response to menu activity. Have you
> tried simply executing a FrmGotoForm(TransformerForm) or
> FrmGotoForm(AboutForm) command instead, providing appropriate form
> handlers for each?
>
> Bob
>
> --
> For information on using the PalmSource Developer Forums, or to
unsubscribe, please see http://www.palmos.com/dev/support/forums/
>
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/