1*c7ef0cfcSnicm /* $OpenBSD: fld_current.c,v 1.7 2023/10/17 09:52:10 nicm Exp $ */
202f2426aSmillert /****************************************************************************
3*c7ef0cfcSnicm * Copyright 2020 Thomas E. Dickey *
4*c7ef0cfcSnicm * Copyright 1998-2010,2016 Free Software Foundation, Inc. *
502f2426aSmillert * *
602f2426aSmillert * Permission is hereby granted, free of charge, to any person obtaining a *
702f2426aSmillert * copy of this software and associated documentation files (the *
802f2426aSmillert * "Software"), to deal in the Software without restriction, including *
902f2426aSmillert * without limitation the rights to use, copy, modify, merge, publish, *
1002f2426aSmillert * distribute, distribute with modifications, sublicense, and/or sell *
1102f2426aSmillert * copies of the Software, and to permit persons to whom the Software is *
1202f2426aSmillert * furnished to do so, subject to the following conditions: *
1302f2426aSmillert * *
1402f2426aSmillert * The above copyright notice and this permission notice shall be included *
1502f2426aSmillert * in all copies or substantial portions of the Software. *
1602f2426aSmillert * *
1702f2426aSmillert * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
1802f2426aSmillert * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
1902f2426aSmillert * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
2002f2426aSmillert * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
2102f2426aSmillert * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
2202f2426aSmillert * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
2302f2426aSmillert * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
2402f2426aSmillert * *
2502f2426aSmillert * Except as contained in this notice, the name(s) of the above copyright *
2602f2426aSmillert * holders shall not be used in advertising or otherwise to promote the *
2702f2426aSmillert * sale, use or other dealings in this Software without prior written *
2802f2426aSmillert * authorization. *
2902f2426aSmillert ****************************************************************************/
3002f2426aSmillert
3102f2426aSmillert /****************************************************************************
3281d8c4e1Snicm * Author: Juergen Pfeifer, 1995,1997 *
3302f2426aSmillert ****************************************************************************/
3481d8c4e1Snicm
358d0fca71Smillert #include "form.priv.h"
368d0fca71Smillert
37*c7ef0cfcSnicm MODULE_ID("$Id: fld_current.c,v 1.7 2023/10/17 09:52:10 nicm Exp $")
388d0fca71Smillert
398d0fca71Smillert /*---------------------------------------------------------------------------
408d0fca71Smillert | Facility : libnform
418d0fca71Smillert | Function : int set_current_field(FORM * form,FIELD * field)
428d0fca71Smillert |
438d0fca71Smillert | Description : Set the current field of the form to the specified one.
448d0fca71Smillert |
458d0fca71Smillert | Return Values : E_OK - success
468d0fca71Smillert | E_BAD_ARGUMENT - invalid form or field pointer
478d0fca71Smillert | E_REQUEST_DENIED - field not selectable
488d0fca71Smillert | E_BAD_STATE - called from a hook routine
498d0fca71Smillert | E_INVALID_FIELD - current field can't be left
508d0fca71Smillert | E_SYSTEM_ERROR - system error
518d0fca71Smillert +--------------------------------------------------------------------------*/
FORM_EXPORT(int)52*c7ef0cfcSnicm FORM_EXPORT(int)
5384af20ceSmillert set_current_field(FORM *form, FIELD *field)
548d0fca71Smillert {
558d0fca71Smillert int err = E_OK;
568d0fca71Smillert
57*c7ef0cfcSnicm T((T_CALLED("set_current_field(%p,%p)"), (void *)form, (void *)field));
5881d8c4e1Snicm if (form == 0 || field == 0)
5981d8c4e1Snicm {
608d0fca71Smillert RETURN(E_BAD_ARGUMENT);
6181d8c4e1Snicm }
6281d8c4e1Snicm else if ((form != field->form) || Field_Is_Not_Selectable(field))
6381d8c4e1Snicm {
648d0fca71Smillert RETURN(E_REQUEST_DENIED);
6581d8c4e1Snicm }
6681d8c4e1Snicm else if ((form->status & _POSTED) == 0)
678d0fca71Smillert {
688d0fca71Smillert form->current = field;
698d0fca71Smillert form->curpage = field->page;
708d0fca71Smillert }
718d0fca71Smillert else
728d0fca71Smillert {
7381d8c4e1Snicm if ((form->status & _IN_DRIVER) != 0)
7481d8c4e1Snicm {
758d0fca71Smillert err = E_BAD_STATE;
7681d8c4e1Snicm }
778d0fca71Smillert else
788d0fca71Smillert {
798d0fca71Smillert if (form->current != field)
808d0fca71Smillert {
81*c7ef0cfcSnicm if (form->current && !_nc_Internal_Validation(form))
8281d8c4e1Snicm {
838d0fca71Smillert err = E_INVALID_FIELD;
8481d8c4e1Snicm }
858d0fca71Smillert else
868d0fca71Smillert {
878d0fca71Smillert Call_Hook(form, fieldterm);
888d0fca71Smillert if (field->page != form->curpage)
898d0fca71Smillert {
908d0fca71Smillert Call_Hook(form, formterm);
9181d8c4e1Snicm err = _nc_Set_Form_Page(form, (int)field->page, field);
928d0fca71Smillert Call_Hook(form, forminit);
938d0fca71Smillert }
948d0fca71Smillert else
958d0fca71Smillert {
968d0fca71Smillert err = _nc_Set_Current_Field(form, field);
978d0fca71Smillert }
988d0fca71Smillert Call_Hook(form, fieldinit);
9981d8c4e1Snicm (void)_nc_Refresh_Current_Field(form);
1008d0fca71Smillert }
1018d0fca71Smillert }
1028d0fca71Smillert }
1038d0fca71Smillert }
1048d0fca71Smillert RETURN(err);
1058d0fca71Smillert }
1068d0fca71Smillert
1078d0fca71Smillert /*---------------------------------------------------------------------------
1088d0fca71Smillert | Facility : libnform
109*c7ef0cfcSnicm | Function : int unfocus_current_field(FORM * form)
110*c7ef0cfcSnicm |
111*c7ef0cfcSnicm | Description : Removes focus from the current field.
112*c7ef0cfcSnicm |
113*c7ef0cfcSnicm | Return Values : E_OK - success
114*c7ef0cfcSnicm | E_BAD_ARGUMENT - invalid form pointer
115*c7ef0cfcSnicm | E_REQUEST_DENIED - there is no current field to unfocus
116*c7ef0cfcSnicm +--------------------------------------------------------------------------*/
117*c7ef0cfcSnicm FORM_EXPORT(int)
unfocus_current_field(FORM * const form)118*c7ef0cfcSnicm unfocus_current_field(FORM *const form)
119*c7ef0cfcSnicm {
120*c7ef0cfcSnicm T((T_CALLED("unfocus_current_field(%p)"), (const void *)form));
121*c7ef0cfcSnicm if (form == 0)
122*c7ef0cfcSnicm {
123*c7ef0cfcSnicm RETURN(E_BAD_ARGUMENT);
124*c7ef0cfcSnicm }
125*c7ef0cfcSnicm else if (form->current == 0)
126*c7ef0cfcSnicm {
127*c7ef0cfcSnicm RETURN(E_REQUEST_DENIED);
128*c7ef0cfcSnicm }
129*c7ef0cfcSnicm _nc_Unset_Current_Field(form);
130*c7ef0cfcSnicm RETURN(E_OK);
131*c7ef0cfcSnicm }
132*c7ef0cfcSnicm
133*c7ef0cfcSnicm /*---------------------------------------------------------------------------
134*c7ef0cfcSnicm | Facility : libnform
1358d0fca71Smillert | Function : FIELD *current_field(const FORM * form)
1368d0fca71Smillert |
1378d0fca71Smillert | Description : Return the current field.
1388d0fca71Smillert |
1398d0fca71Smillert | Return Values : Pointer to the current field.
1408d0fca71Smillert +--------------------------------------------------------------------------*/
141*c7ef0cfcSnicm FORM_EXPORT(FIELD *)
current_field(const FORM * form)14284af20ceSmillert current_field(const FORM *form)
1438d0fca71Smillert {
144*c7ef0cfcSnicm T((T_CALLED("current_field(%p)"), (const void *)form));
14581d8c4e1Snicm returnField(Normalize_Form(form)->current);
1468d0fca71Smillert }
1478d0fca71Smillert
1488d0fca71Smillert /*---------------------------------------------------------------------------
1498d0fca71Smillert | Facility : libnform
1508d0fca71Smillert | Function : int field_index(const FIELD * field)
1518d0fca71Smillert |
1528d0fca71Smillert | Description : Return the index of the field in the field-array of
1538d0fca71Smillert | the form.
1548d0fca71Smillert |
1558d0fca71Smillert | Return Values : >= 0 : field index
1568d0fca71Smillert | -1 : fieldpointer invalid or field not connected
1578d0fca71Smillert +--------------------------------------------------------------------------*/
158*c7ef0cfcSnicm FORM_EXPORT(int)
field_index(const FIELD * field)15984af20ceSmillert field_index(const FIELD *field)
1608d0fca71Smillert {
161*c7ef0cfcSnicm T((T_CALLED("field_index(%p)"), (const void *)field));
16281d8c4e1Snicm returnCode((field != 0 && field->form != 0) ? (int)field->index : -1);
1638d0fca71Smillert }
1648d0fca71Smillert
1658d0fca71Smillert /* fld_current.c ends here */
166