1 /*        $NetBSD: post.c,v 1.10 2016/03/09 19:47:13 christos Exp $   */
2 
3 /*-
4  * Copyright (c) 1998-2000 Brett Lymn
5  *                         (blymn@baea.com.au, brett_lymn@yahoo.com.au)
6  * All rights reserved.
7  *
8  * This code has been donated to The NetBSD Foundation by the Author.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  *
30  */
31 
32 #include <sys/cdefs.h>
33 __RCSID("$NetBSD: post.c,v 1.10 2016/03/09 19:47:13 christos Exp $");
34 
35 #include "form.h"
36 #include "internals.h"
37 
38 /*
39  * Post the form to the screen.
40  */
41 int
post_form(FORM * form)42 post_form(FORM *form)
43 {
44           int rows, cols, status;
45 
46           if (form == NULL)
47                     return E_BAD_ARGUMENT;
48 
49           if (form->posted == 1)
50                     return E_POSTED;
51 
52           if ((form->fields == NULL) || (form->fields[0] == NULL))
53                     return E_NOT_CONNECTED;
54 
55           if (form->in_init == 1)
56                     return E_BAD_STATE;
57 
58           if (scale_form(form, &rows, &cols) != E_OK)
59                     return E_SYSTEM_ERROR;
60 
61           if ((form->scrwin != NULL) && ((rows > getmaxy(form->scrwin))
62                                                || (cols > getmaxx(form->scrwin)))) {
63                     return E_NO_ROOM;
64           }
65 
66           form->in_init = 1;
67           if (form->form_init != NULL)
68                     form->form_init(form);
69 
70           if (form->field_init != NULL)
71                     form->field_init(form);
72           form->in_init = 0;
73 
74           _formi_pos_first_field(form);
75           if ((status = _formi_draw_page(form)) != E_OK)
76                     return status;
77 
78           form->posted = 1;
79           pos_form_cursor(form);
80 
81           return E_OK;
82 }
83 
84 /*
85  * Unpost the form from the screen
86  */
87 int
unpost_form(FORM * form)88 unpost_form(FORM *form)
89 {
90 
91           if (form == NULL)
92                     return E_BAD_ARGUMENT;
93 
94           if (form->posted != 1)
95                     return E_NOT_POSTED;
96 
97           if (form->in_init == 1)
98                     return E_BAD_STATE;
99 
100           form->in_init = 1;
101           if (form->field_term != NULL)
102                     form->field_term(form);
103 
104           if (form->form_term != NULL)
105                     form->form_term(form);
106           form->in_init = 0;
107 
108           wclear(form->scrwin);
109 
110           form->posted = 0;
111 
112           return E_OK;
113 }
114 
115