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