On Sat, Jul 01, 2000 at 05:31:55AM -0700, Hitesh Patel wrote:
>
> I have atable in my form which has a column which is
> an editable field. What do I have to do so that I can
> navigate through the various fields using the up/down
> and the down/up tab graffiti strokes as is done in the
> Address book edit form. A bit of code on this would be
> great help.
The up & down graffiti strokes generate a keyDownEvent returning the
characters prevFieldChr & nextFieldChr (defined in Chars.h),
respectively. In your form's event loop, simply watch for
keyDownEvent's, and then navigate between your fields if the keyDown
char is a prev/nextFieldChr.
Here's some code I use to cycle between three fields:
Boolean
FormHandleEvent(EventPtr event)
{
...
switch (event->eType)
{
...
case keyDownEvent:
/* Get char for keyDown */
c = event->data.keyDown.chr ;
/* Check for field navigation keys */
if ( c == prevFieldChr || c == nextFieldChr )
{
CycleFieldFocus(c) ;
return true ;
}
...
}
}
/*
* CycleFieldFocus -- change input focus between fields
*/
void
CycleFieldFocus(Word c)
{
FormPtr form ;
FieldPtr field ;
Word nextField ;
field = GetFieldWithFocus() ;
if ( field )
{
switch ( c )
{
case nextFieldChr:
switch ( field->id )
{
case MainNumberField:
nextField = MainSeedField ;
break ;
case MainSeedField:
nextField = MainPassphraseField ;
break ;
case MainPassphraseField:
nextField = MainNumberField ;
break ;
}
break ;
case prevFieldChr:
SndPlaySystemSound(sndClick) ; /* Hmm, this char doesn't auto-
matically generate a sound */
switch ( field->id )
{
case MainNumberField:
nextField = MainPassphraseField ;
break ;
case MainSeedField:
nextField = MainNumberField ;
break ;
case MainPassphraseField:
nextField = MainSeedField ;
break ;
}
break ;
}
form = FrmGetActiveForm() ;
FrmSetFocus(form,FrmGetObjectIndex(form,nextField)) ;
}
return ;
}
/*
* GetFieldWithFocus -- return a FieldPtr to the field currently
* with input focus
*/
FieldPtr
GetFieldWithFocus(void)
{
FormPtr form ;
Word focusIndex ;
form = FrmGetActiveForm() ;
focusIndex = FrmGetFocus(form) ;
if ( focusIndex == noFocus )
return(NULL) ;
else
return(FrmGetObjectPtr(form,focusIndex)) ;
}
If the number of fields is large, instead of using two large switch
statements to determine the next/previous field as I did above, number
your field resource ids sequentially and then simply add or subtract
one from the "current" field id.
See the addressbook source for another example of how to do this.
John
-------------------------------------------------------------------------
John Valdes Department of Astronomy & Astrophysics
[EMAIL PROTECTED] University of Chicago
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/