xref: /openbsd-src/lib/libform/frm_post.c (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1 /*	$OpenBSD: frm_post.c,v 1.4 2001/01/22 18:02:15 millert Exp $	*/
2 
3 /****************************************************************************
4  * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
5  *                                                                          *
6  * Permission is hereby granted, free of charge, to any person obtaining a  *
7  * copy of this software and associated documentation files (the            *
8  * "Software"), to deal in the Software without restriction, including      *
9  * without limitation the rights to use, copy, modify, merge, publish,      *
10  * distribute, distribute with modifications, sublicense, and/or sell       *
11  * copies of the Software, and to permit persons to whom the Software is    *
12  * furnished to do so, subject to the following conditions:                 *
13  *                                                                          *
14  * The above copyright notice and this permission notice shall be included  *
15  * in all copies or substantial portions of the Software.                   *
16  *                                                                          *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24  *                                                                          *
25  * Except as contained in this notice, the name(s) of the above copyright   *
26  * holders shall not be used in advertising or otherwise to promote the     *
27  * sale, use or other dealings in this Software without prior written       *
28  * authorization.                                                           *
29  ****************************************************************************/
30 
31 /****************************************************************************
32  *   Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997            *
33  ****************************************************************************/
34 #include "form.priv.h"
35 
36 MODULE_ID("$From: frm_post.c,v 1.5 2000/12/10 02:09:37 tom 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 NCURSES_EXPORT(int)
52 post_form (FORM * form)
53 {
54   WINDOW *formwin;
55   int err;
56   int page;
57 
58   if (!form)
59     RETURN(E_BAD_ARGUMENT);
60 
61   if (form->status & _POSTED)
62     RETURN(E_POSTED);
63 
64   if (!(form->field))
65     RETURN(E_NOT_CONNECTED);
66 
67   formwin = Get_Form_Window(form);
68   if ((form->cols > getmaxx(formwin)) || (form->rows > getmaxy(formwin)))
69     RETURN(E_NO_ROOM);
70 
71   /* reset form->curpage to an invald value. This forces Set_Form_Page
72      to do the page initialization which is required by post_form.
73   */
74   page = form->curpage;
75   form->curpage = -1;
76   if ((err = _nc_Set_Form_Page(form,page,form->current))!=E_OK)
77     RETURN(err);
78 
79   form->status |= _POSTED;
80 
81   Call_Hook(form,forminit);
82   Call_Hook(form,fieldinit);
83 
84   _nc_Refresh_Current_Field(form);
85   RETURN(E_OK);
86 }
87 
88 /*---------------------------------------------------------------------------
89 |   Facility      :  libnform
90 |   Function      :  int unpost_form(FORM * form)
91 |
92 |   Description   :  Erase form from its associated subwindow.
93 |
94 |   Return Values :  E_OK            - success
95 |                    E_BAD_ARGUMENT  - invalid form pointer
96 |                    E_NOT_POSTED    - form isn't posted
97 |                    E_BAD_STATE     - called from a hook routine
98 +--------------------------------------------------------------------------*/
99 NCURSES_EXPORT(int)
100 unpost_form (FORM * form)
101 {
102   if (!form)
103     RETURN(E_BAD_ARGUMENT);
104 
105   if (!(form->status & _POSTED))
106     RETURN(E_NOT_POSTED);
107 
108   if (form->status & _IN_DRIVER)
109     RETURN(E_BAD_STATE);
110 
111   Call_Hook(form,fieldterm);
112   Call_Hook(form,formterm);
113 
114   werase(Get_Form_Window(form));
115   delwin(form->w);
116   form->w = (WINDOW *)0;
117   form->status &= ~_POSTED;
118   RETURN(E_OK);
119 }
120 
121 /* frm_post.c ends here */
122