blob: ab880894d92526a46e5fa4bad921c393a52f5d80 [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,2012 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: frm_post.c,v 1.14 2020/05/24 01:40:20 anonymous.maarten Exp $")
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053037
38/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -040039| Facility : libnform
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053040| Function : int post_form(FORM * form)
micky3879b9f5e72025-07-08 18:04:53 -040041|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053042| Description : Writes the form into its associated subwindow.
43|
44| Return Values : E_OK - success
45| E_BAD_ARGUMENT - invalid form pointer
46| E_POSTED - form already posted
47| E_NOT_CONNECTED - no fields connected to form
48| E_NO_ROOM - form doesn't fit into subwindow
49| E_SYSTEM_ERROR - system error
50+--------------------------------------------------------------------------*/
micky3879b9f5e72025-07-08 18:04:53 -040051FORM_EXPORT(int)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053052post_form(FORM *form)
53{
54 WINDOW *formwin;
55 int err;
56 int page;
57
Steve Kondikae271bc2015-11-15 02:50:53 +010058 T((T_CALLED("post_form(%p)"), (void *)form));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053059
60 if (!form)
61 RETURN(E_BAD_ARGUMENT);
62
63 if (form->status & _POSTED)
64 RETURN(E_POSTED);
65
66 if (!(form->field))
67 RETURN(E_NOT_CONNECTED);
68
69 formwin = Get_Form_Window(form);
70 if ((form->cols > getmaxx(formwin)) || (form->rows > getmaxy(formwin)))
71 RETURN(E_NO_ROOM);
72
micky3879b9f5e72025-07-08 18:04:53 -040073 /* reset form->curpage to an invalid value. This forces Set_Form_Page
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053074 to do the page initialization which is required by post_form.
75 */
76 page = form->curpage;
77 form->curpage = -1;
78 if ((err = _nc_Set_Form_Page(form, page, form->current)) != E_OK)
79 RETURN(err);
80
Steve Kondikae271bc2015-11-15 02:50:53 +010081 SetStatus(form, _POSTED);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053082
83 Call_Hook(form, forminit);
84 Call_Hook(form, fieldinit);
85
86 _nc_Refresh_Current_Field(form);
87 RETURN(E_OK);
88}
89
90/*---------------------------------------------------------------------------
micky3879b9f5e72025-07-08 18:04:53 -040091| Facility : libnform
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053092| Function : int unpost_form(FORM * form)
micky3879b9f5e72025-07-08 18:04:53 -040093|
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053094| Description : Erase form from its associated subwindow.
95|
96| Return Values : E_OK - success
97| E_BAD_ARGUMENT - invalid form pointer
98| E_NOT_POSTED - form isn't posted
99| E_BAD_STATE - called from a hook routine
100+--------------------------------------------------------------------------*/
micky3879b9f5e72025-07-08 18:04:53 -0400101FORM_EXPORT(int)
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530102unpost_form(FORM *form)
103{
Steve Kondikae271bc2015-11-15 02:50:53 +0100104 T((T_CALLED("unpost_form(%p)"), (void *)form));
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530105
106 if (!form)
107 RETURN(E_BAD_ARGUMENT);
108
109 if (!(form->status & _POSTED))
110 RETURN(E_NOT_POSTED);
111
112 if (form->status & _IN_DRIVER)
113 RETURN(E_BAD_STATE);
114
115 Call_Hook(form, fieldterm);
116 Call_Hook(form, formterm);
117
118 werase(Get_Form_Window(form));
119 delwin(form->w);
120 form->w = (WINDOW *)0;
Steve Kondikae271bc2015-11-15 02:50:53 +0100121 ClrStatus(form, _POSTED);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530122 RETURN(E_OK);
123}
124
125/* frm_post.c ends here */