xref: /freebsd/contrib/ncurses/form/frm_post.c (revision 6ba2210ee039f2f12878c217bcf058e9c8b26b29)
1 /****************************************************************************
2  * Copyright 2020 Thomas E. Dickey                                          *
3  * Copyright 1998-2010,2012 Free Software Foundation, Inc.                  *
4  *                                                                          *
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 
36 MODULE_ID("$Id: frm_post.c,v 1.14 2020/05/24 01:40:20 anonymous.maarten Exp $")
37 
38 /*---------------------------------------------------------------------------
39 |   Facility      :  libnform
40 |   Function      :  int post_form(FORM * form)
41 |
42 |   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 +--------------------------------------------------------------------------*/
51 FORM_EXPORT(int)
52 post_form(FORM *form)
53 {
54   WINDOW *formwin;
55   int err;
56   int page;
57 
58   T((T_CALLED("post_form(%p)"), (void *)form));
59 
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 
73   /* reset form->curpage to an invalid value. This forces Set_Form_Page
74      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 
81   SetStatus(form, _POSTED);
82 
83   Call_Hook(form, forminit);
84   Call_Hook(form, fieldinit);
85 
86   _nc_Refresh_Current_Field(form);
87   RETURN(E_OK);
88 }
89 
90 /*---------------------------------------------------------------------------
91 |   Facility      :  libnform
92 |   Function      :  int unpost_form(FORM * form)
93 |
94 |   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 +--------------------------------------------------------------------------*/
101 FORM_EXPORT(int)
102 unpost_form(FORM *form)
103 {
104   T((T_CALLED("unpost_form(%p)"), (void *)form));
105 
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;
121   ClrStatus(form, _POSTED);
122   RETURN(E_OK);
123 }
124 
125 /* frm_post.c ends here */
126