diff --git a/form/fld_current.c b/form/fld_current.c index ef9ec00..fa472ea 100644 --- a/form/fld_current.c +++ b/form/fld_current.c @@ -76,7 +76,7 @@ set_current_field(FORM *form, FIELD *field) { if (form->current != field) { - if (!_nc_Internal_Validation(form)) + if (form->current && !_nc_Internal_Validation(form)) { err = E_INVALID_FIELD; } @@ -104,6 +104,32 @@ set_current_field(FORM *form, FIELD *field) /*--------------------------------------------------------------------------- | 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); + } + Unset_Current_Field(form); + RETURN(E_OK); +} + +/*--------------------------------------------------------------------------- +| Facility : libnform | Function : FIELD *current_field(const FORM * form) | | Description : Return the current field. diff --git a/form/form.h b/form/form.h index 05a7861..dbc3124 100644 --- a/form/form.h +++ b/form/form.h @@ -387,6 +387,7 @@ extern NCURSES_EXPORT(int) field_count (const FORM *); extern NCURSES_EXPORT(int) set_form_win (FORM *,WINDOW *); extern NCURSES_EXPORT(int) set_form_sub (FORM *,WINDOW *); extern NCURSES_EXPORT(int) set_current_field (FORM *,FIELD *); +extern NCURSES_EXPORT(int) unfocus_current_field (FORM *); extern NCURSES_EXPORT(int) field_index (const FIELD *); extern NCURSES_EXPORT(int) set_form_page (FORM *,int); extern NCURSES_EXPORT(int) form_page (const FORM *); diff --git a/form/form.priv.h b/form/form.priv.h index 625fc10..67b9558 100644 --- a/form/form.priv.h +++ b/form/form.priv.h @@ -184,6 +184,7 @@ extern NCURSES_EXPORT(FIELD *) _nc_First_Active_Field (FORM*); extern NCURSES_EXPORT(bool) _nc_Internal_Validation (FORM*); extern NCURSES_EXPORT(int) _nc_Set_Current_Field (FORM*, FIELD*); extern NCURSES_EXPORT(int) _nc_Position_Form_Cursor (FORM*); +extern void Unset_Current_Field(FORM *form); #if NCURSES_INTEROP_FUNCS extern NCURSES_EXPORT(FIELDTYPE *) _nc_TYPE_INTEGER(void); diff --git a/form/frm_driver.c b/form/frm_driver.c index f78a45e..c01bcd8 100644 --- a/form/frm_driver.c +++ b/form/frm_driver.c @@ -1395,6 +1395,56 @@ _nc_Synchronize_Options(FIELD *field, Field_Options newopts) returnCode(res); } +/* + * Removes the focus from the current field of the form. + */ +void +Unset_Current_Field(FORM *form) +{ + FIELD *field = form->current; + _nc_Refresh_Current_Field(form); + if (Field_Has_Option(field, O_PUBLIC)) + { + if (field->drows > field->rows) + { + if (form->toprow == 0) + ClrStatus(field, _NEWTOP); + else + SetStatus(field, _NEWTOP); + } + else + { + if (Justification_Allowed(field)) + { + Window_To_Buffer(form, field); + werase(form->w); + Perform_Justification(field, form->w); + if (Field_Has_Option(field, O_DYNAMIC_JUSTIFY) && + (form->w->_parent == 0)) + { + copywin(form->w, + Get_Form_Window(form), + 0, + 0, + field->frow, + field->fcol, + field->frow, + field->cols + field->fcol - 1, + 0); + wsyncup(Get_Form_Window(form)); + } + else + { + wsyncup(form->w); + } + } + } + } + delwin(form->w); + form->w = (WINDOW *)0; + form->current = 0; +} + /*--------------------------------------------------------------------------- | Facility : libnform | Function : int _nc_Set_Current_Field(FORM * form, @@ -1415,7 +1465,7 @@ _nc_Set_Current_Field(FORM *form, FIELD *newfield) T((T_CALLED("_nc_Set_Current_Field(%p,%p)"), (void *)form, (void *)newfield)); - if (!form || !newfield || !form->current || (newfield->form != form)) + if (!form || !newfield || (newfield->form != form)) returnCode(E_BAD_ARGUMENT); if ((form->status & _IN_DRIVER)) @@ -1429,51 +1479,10 @@ _nc_Set_Current_Field(FORM *form, FIELD *newfield) if ((field != newfield) || !(form->status & _POSTED)) { - if ((form->w) && + if (field && (form->w) && (Field_Has_Option(field, O_VISIBLE)) && (field->form->curpage == field->page)) - { - _nc_Refresh_Current_Field(form); - if (Field_Has_Option(field, O_PUBLIC)) - { - if (field->drows > field->rows) - { - if (form->toprow == 0) - ClrStatus(field, _NEWTOP); - else - SetStatus(field, _NEWTOP); - } - else - { - if (Justification_Allowed(field)) - { - Window_To_Buffer(form, field); - werase(form->w); - Perform_Justification(field, form->w); - if (Field_Has_Option(field, O_DYNAMIC_JUSTIFY) && - (form->w->_parent == 0)) - { - copywin(form->w, - Get_Form_Window(form), - 0, - 0, - field->frow, - field->fcol, - field->frow, - field->cols + field->fcol - 1, - 0); - wsyncup(Get_Form_Window(form)); - } - else - { - wsyncup(form->w); - } - } - } - } - delwin(form->w); - form->w = (WINDOW *)0; - } + Unset_Current_Field(form); field = newfield; diff --git a/man/form.3x b/man/form.3x index c379a4d..4b215c9 100644 --- a/man/form.3x +++ b/man/form.3x @@ -146,6 +146,7 @@ set_form_userptr \fBform_userptr\fR(3X) set_form_win \fBform_win\fR(3X) set_max_field \fBform_field_buffer\fR(3X) set_new_page \fBform_new_page\fR(3X) +unfocus_current_field \fBform_page\fR(3X) unpost_form \fBform_post\fR(3X) .TE .SH RETURN VALUE diff --git a/man/form_page.3x b/man/form_page.3x index 2211216..b06666b 100644 --- a/man/form_page.3x +++ b/man/form_page.3x @@ -38,6 +38,8 @@ int set_current_field(FORM *form, FIELD *field); .br FIELD *current_field(const FORM *); .br +int unfocus_current_field(FORM *form); +.br int set_form_page(FORM *form, int n); .br int form_page(const FORM *form); @@ -45,9 +47,13 @@ int form_page(const FORM *form); int field_index(const FIELD *field); .br .SH DESCRIPTION -The function \fBset_current field\fR sets the current field of the given +The function \fBset_current_field\fR sets the current field of the given form; \fBcurrent_field\fR returns the current field of the given form. .PP +The function \fBunfocus_current_field\fR removes the focus from the current +field of the form. In such state, inquiries via \fBcurrent_field\fR shall return +a NULL pointer. +.PP The function \fBset_form_page\fR sets the form's page number (goes to page \fIn\fR of the form). .PP