blob: 264007ef59f391524576c3c2612c6de88492f7b9 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002 * Copyright 2020 Thomas E. Dickey *
3 * Copyright 1998-2010,2016 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304 * *
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: *
12 * *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
15 * *
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. *
23 * *
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 *
27 * authorization. *
28 ****************************************************************************/
29
30/****************************************************************************
31 * Author: Juergen Pfeifer, 1995,1997 *
32 ****************************************************************************/
33
34#include "form.priv.h"
35
micky3879b9f5e72025-07-08 18:04:53 -040036MODULE_ID("$Id: fld_current.c,v 1.16 2020/05/24 01:40:20 anonymous.maarten Exp $")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053037
38/*---------------------------------------------------------------------------
39| Facility : libnform
40| Function : int set_current_field(FORM * form,FIELD * field)
41|
42| Description : Set the current field of the form to the specified one.
43|
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+--------------------------------------------------------------------------*/
micky3879b9f5e72025-07-08 18:04:53 -040051FORM_EXPORT(int)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053052set_current_field(FORM *form, FIELD *field)
53{
54 int err = E_OK;
55
Steve Kondikae271bc2015-11-15 02:50:53 +010056 T((T_CALLED("set_current_field(%p,%p)"), (void *)form, (void *)field));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053057 if (form == 0 || field == 0)
58 {
59 RETURN(E_BAD_ARGUMENT);
60 }
61 else if ((form != field->form) || Field_Is_Not_Selectable(field))
62 {
63 RETURN(E_REQUEST_DENIED);
64 }
65 else if ((form->status & _POSTED) == 0)
66 {
67 form->current = field;
68 form->curpage = field->page;
69 }
70 else
71 {
72 if ((form->status & _IN_DRIVER) != 0)
73 {
74 err = E_BAD_STATE;
75 }
76 else
77 {
78 if (form->current != field)
79 {
micky3879b9f5e72025-07-08 18:04:53 -040080 if (form->current && !_nc_Internal_Validation(form))
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053081 {
82 err = E_INVALID_FIELD;
83 }
84 else
85 {
86 Call_Hook(form, fieldterm);
87 if (field->page != form->curpage)
88 {
89 Call_Hook(form, formterm);
90 err = _nc_Set_Form_Page(form, (int)field->page, field);
91 Call_Hook(form, forminit);
92 }
93 else
94 {
95 err = _nc_Set_Current_Field(form, field);
96 }
97 Call_Hook(form, fieldinit);
98 (void)_nc_Refresh_Current_Field(form);
99 }
100 }
101 }
102 }
103 RETURN(err);
104}
105
106/*---------------------------------------------------------------------------
107| Facility : libnform
micky3879b9f5e72025-07-08 18:04:53 -0400108| Function : int unfocus_current_field(FORM * form)
109|
110| Description : Removes focus from the current field.
111|
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+--------------------------------------------------------------------------*/
116FORM_EXPORT(int)
117unfocus_current_field(FORM *const form)
118{
119 T((T_CALLED("unfocus_current_field(%p)"), (const void *)form));
120 if (form == 0)
121 {
122 RETURN(E_BAD_ARGUMENT);
123 }
124 else if (form->current == 0)
125 {
126 RETURN(E_REQUEST_DENIED);
127 }
128 _nc_Unset_Current_Field(form);
129 RETURN(E_OK);
130}
131
132/*---------------------------------------------------------------------------
133| Facility : libnform
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530134| Function : FIELD *current_field(const FORM * form)
135|
136| Description : Return the current field.
137|
138| Return Values : Pointer to the current field.
139+--------------------------------------------------------------------------*/
micky3879b9f5e72025-07-08 18:04:53 -0400140FORM_EXPORT(FIELD *)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530141current_field(const FORM *form)
142{
Steve Kondikae271bc2015-11-15 02:50:53 +0100143 T((T_CALLED("current_field(%p)"), (const void *)form));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530144 returnField(Normalize_Form(form)->current);
145}
146
147/*---------------------------------------------------------------------------
148| Facility : libnform
149| Function : int field_index(const FIELD * field)
150|
151| Description : Return the index of the field in the field-array of
152| the form.
153|
154| Return Values : >= 0 : field index
155| -1 : fieldpointer invalid or field not connected
156+--------------------------------------------------------------------------*/
micky3879b9f5e72025-07-08 18:04:53 -0400157FORM_EXPORT(int)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530158field_index(const FIELD *field)
159{
Steve Kondikae271bc2015-11-15 02:50:53 +0100160 T((T_CALLED("field_index(%p)"), (const void *)field));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530161 returnCode((field != 0 && field->form != 0) ? (int)field->index : -1);
162}
163
164/* fld_current.c ends here */