1 /****************************************************************************
2 * Copyright 2020 Thomas E. Dickey *
3 * Copyright 1998-2010,2016 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Juergen Pfeifer, 1995,1997 *
32 ****************************************************************************/
34 #include "form.priv.h"
36 MODULE_ID("$Id: fld_current.c,v 1.16 2020/05/24 01:40:20 anonymous.maarten Exp $")
38 /*---------------------------------------------------------------------------
40 | Function : int set_current_field(FORM * form,FIELD * field)
42 | Description : Set the current field of the form to the specified one.
44 | Return Values : E_OK - success
45 | E_BAD_ARGUMENT - invalid form or field pointer
46 | E_REQUEST_DENIED - field not selectable
47 | E_BAD_STATE - called from a hook routine
48 | E_INVALID_FIELD - current field can't be left
49 | E_SYSTEM_ERROR - system error
50 +--------------------------------------------------------------------------*/
52 set_current_field(FORM *form, FIELD *field)
56 T((T_CALLED("set_current_field(%p,%p)"), (void *)form, (void *)field));
57 if (form == 0 || field == 0)
59 RETURN(E_BAD_ARGUMENT);
61 else if ((form != field->form) || Field_Is_Not_Selectable(field))
63 RETURN(E_REQUEST_DENIED);
65 else if ((form->status & _POSTED) == 0)
67 form->current = field;
68 form->curpage = field->page;
72 if ((form->status & _IN_DRIVER) != 0)
78 if (form->current != field)
80 if (form->current && !_nc_Internal_Validation(form))
82 err = E_INVALID_FIELD;
86 Call_Hook(form, fieldterm);
87 if (field->page != form->curpage)
89 Call_Hook(form, formterm);
90 err = _nc_Set_Form_Page(form, (int)field->page, field);
91 Call_Hook(form, forminit);
95 err = _nc_Set_Current_Field(form, field);
97 Call_Hook(form, fieldinit);
98 (void)_nc_Refresh_Current_Field(form);
106 /*---------------------------------------------------------------------------
107 | Facility : libnform
108 | Function : int unfocus_current_field(FORM * form)
110 | Description : Removes focus from the current field.
112 | Return Values : E_OK - success
113 | E_BAD_ARGUMENT - invalid form pointer
114 | E_REQUEST_DENIED - there is no current field to unfocus
115 +--------------------------------------------------------------------------*/
117 unfocus_current_field(FORM *const form)
119 T((T_CALLED("unfocus_current_field(%p)"), (const void *)form));
122 RETURN(E_BAD_ARGUMENT);
124 else if (form->current == 0)
126 RETURN(E_REQUEST_DENIED);
128 _nc_Unset_Current_Field(form);
132 /*---------------------------------------------------------------------------
133 | Facility : libnform
134 | Function : FIELD *current_field(const FORM * form)
136 | Description : Return the current field.
138 | Return Values : Pointer to the current field.
139 +--------------------------------------------------------------------------*/
141 current_field(const FORM *form)
143 T((T_CALLED("current_field(%p)"), (const void *)form));
144 returnField(Normalize_Form(form)->current);
147 /*---------------------------------------------------------------------------
148 | Facility : libnform
149 | Function : int field_index(const FIELD * field)
151 | Description : Return the index of the field in the field-array of
154 | Return Values : >= 0 : field index
155 | -1 : fieldpointer invalid or field not connected
156 +--------------------------------------------------------------------------*/
158 field_index(const FIELD *field)
160 T((T_CALLED("field_index(%p)"), (const void *)field));
161 returnCode((field != 0 && field->form != 0) ? (int)field->index : -1);
164 /* fld_current.c ends here */