I have a problem. I need to control which field on the screen has focus,
but the PalmOS keeps taking control from me. Simplified, I have two fields
on the screen and a pop-up trigger. The first field is for data entry, the
second field appears when the user makes a choice from the pop-up trigger.
Most of the time, the triggered field has default information set in it and
the focus never needs to leave the data entry field. Also, some pop-up
trigger choices cause the trigger field to disappear and, if the focus is in
the trigger field, it needs to switch back to the data entry field.
This should not be difficult but is giving me hissy fits. Any help would be
appreciated. Code is below.
Thanks in advance. Elia
-------------------------------------------------
// Some code... followed by the call routines
ShowHideObject(TriggerField, false);
if ( selection == kShowTriggerField )
{
ShowHideObject(TriggerField, true);
FieldSetText(text, TriggerField);
}
SetFocus(DataEntryField); // does not change the focus!!!!
// called to set text in a field
void FieldSetText (CharPtr strP, Word ctlID)
{
FieldPtr fldP = GetObjectPtr(ctlID);
Word length = 0;
// alter the field contents
FldDelete(fldP, 0, FldGetMaxChars(fldP));
if ( strP != NULL && *strP != '\0' )
{
length = StrLen(strP);
FldInsert(fldP, strP, length);
}
FldSetInsertionPoint(fldP, length);
}
// called to set the field with focus
void SetFocus (Word ctlID)
{
FormPtr frmP = FrmGetActiveForm();
FieldPtr fldP = GetObjectPtr(ctlID);
FrmSetFocus(frmP, FrmGetObjectIndex(frmP, ctlID));
FldGrabFocus(fldP);
FldSetSelection(fldP, 0, FldGetTextLength(fldP));
}
// used to show/hide objects
void ShowHideObject (Word objectID, Boolean show)
{
FormPtr frm = FrmGetActiveForm();
Word index = FrmGetObjectIndex(frm, objectID);
FormObjectKind objectKind;
if ( show )
{
FrmShowObject(frm, index);
}
else
{
FrmHideObject(frm, index);
if (objectKind == frmBitmapObj)
frm->objects[index].object.bitmap->attr.usable = false;
}
}