X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=form%2Ffld_current.c;h=efd5c2f95d8ff6c69aea848b33c4cb56f619647b;hp=72534a9e36a3196cd02df6d5398a8624f54d8f4e;hb=96a4663880a73a00b11700da8a404fdd56833925;hpb=661078ddbde3ce0f3b06e95642fbb9b5fef7dca1;ds=inline diff --git a/form/fld_current.c b/form/fld_current.c index 72534a9e..efd5c2f9 100644 --- a/form/fld_current.c +++ b/form/fld_current.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998 Free Software Foundation, Inc. * + * Copyright (c) 1998-2010,2016 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -27,16 +27,17 @@ ****************************************************************************/ /**************************************************************************** - * Author: Juergen Pfeifer 1995,1997 * + * Author: Juergen Pfeifer, 1995,1997 * ****************************************************************************/ + #include "form.priv.h" -MODULE_ID("$Id: fld_current.c,v 1.2 1998/02/11 12:13:44 tom Exp $") +MODULE_ID("$Id: fld_current.c,v 1.14 2016/10/29 22:30:10 tom Exp $") /*--------------------------------------------------------------------------- -| Facility : libnform +| Facility : libnform | Function : int set_current_field(FORM * form,FIELD * field) -| +| | Description : Set the current field of the form to the specified one. | | Return Values : E_OK - success @@ -46,46 +47,54 @@ MODULE_ID("$Id: fld_current.c,v 1.2 1998/02/11 12:13:44 tom Exp $") | E_INVALID_FIELD - current field can't be left | E_SYSTEM_ERROR - system error +--------------------------------------------------------------------------*/ -int set_current_field(FORM * form, FIELD * field) +NCURSES_EXPORT(int) +set_current_field(FORM *form, FIELD *field) { int err = E_OK; - if ( !form || !field ) - RETURN(E_BAD_ARGUMENT); - - if ( (form != field->form) || Field_Is_Not_Selectable(field) ) - RETURN(E_REQUEST_DENIED); - - if (!(form->status & _POSTED)) + T((T_CALLED("set_current_field(%p,%p)"), (void *)form, (void *)field)); + if (form == 0 || field == 0) + { + RETURN(E_BAD_ARGUMENT); + } + else if ((form != field->form) || Field_Is_Not_Selectable(field)) + { + RETURN(E_REQUEST_DENIED); + } + else if ((form->status & _POSTED) == 0) { form->current = field; form->curpage = field->page; - } + } else { - if (form->status & _IN_DRIVER) - err = E_BAD_STATE; + if ((form->status & _IN_DRIVER) != 0) + { + err = E_BAD_STATE; + } else { if (form->current != field) { - if (!_nc_Internal_Validation(form)) - err = E_INVALID_FIELD; + if (form->current && !_nc_Internal_Validation(form)) + { + err = E_INVALID_FIELD; + } else { - Call_Hook(form,fieldterm); + Call_Hook(form, fieldterm); if (field->page != form->curpage) { - Call_Hook(form,formterm); - err = _nc_Set_Form_Page(form,field->page,field); - Call_Hook(form,forminit); - } - else + Call_Hook(form, formterm); + err = _nc_Set_Form_Page(form, (int)field->page, field); + Call_Hook(form, forminit); + } + else { - err = _nc_Set_Current_Field(form,field); + err = _nc_Set_Current_Field(form, field); } - Call_Hook(form,fieldinit); - _nc_Refresh_Current_Field(form); + Call_Hook(form, fieldinit); + (void)_nc_Refresh_Current_Field(form); } } } @@ -94,31 +103,61 @@ int set_current_field(FORM * form, FIELD * field) } /*--------------------------------------------------------------------------- -| Facility : libnform +| Facility : libnform +| Function : int unfocus_current_field(FORM * form) +| +| Description : Removes focus from the current field. +| +| Return Values : E_OK - success +| E_BAD_ARGUMENT - invalid form pointer +| E_REQUEST_DENIED - there is no current field to unfocus ++--------------------------------------------------------------------------*/ +NCURSES_EXPORT(int) +unfocus_current_field(FORM *const form) +{ + T((T_CALLED("unfocus_current_field(%p)"), (const void *)form)); + if (form == 0) + { + RETURN(E_BAD_ARGUMENT); + } + else if (form->current == 0) + { + RETURN(E_REQUEST_DENIED); + } + _nc_Unset_Current_Field(form); + RETURN(E_OK); +} + +/*--------------------------------------------------------------------------- +| Facility : libnform | Function : FIELD *current_field(const FORM * form) -| +| | Description : Return the current field. | | Return Values : Pointer to the current field. +--------------------------------------------------------------------------*/ -FIELD *current_field(const FORM * form) +NCURSES_EXPORT(FIELD *) +current_field(const FORM *form) { - return Normalize_Form(form)->current; + T((T_CALLED("current_field(%p)"), (const void *)form)); + returnField(Normalize_Form(form)->current); } /*--------------------------------------------------------------------------- -| Facility : libnform +| Facility : libnform | Function : int field_index(const FIELD * field) -| +| | Description : Return the index of the field in the field-array of | the form. | | Return Values : >= 0 : field index | -1 : fieldpointer invalid or field not connected +--------------------------------------------------------------------------*/ -int field_index(const FIELD * field) +NCURSES_EXPORT(int) +field_index(const FIELD *field) { - return ( (field && field->form) ? field->index : -1 ); + T((T_CALLED("field_index(%p)"), (const void *)field)); + returnCode((field != 0 && field->form != 0) ? (int)field->index : -1); } /* fld_current.c ends here */