xref: /titanic_50/usr/src/lib/libeti/form/common/post.c (revision 34f9b3eef6fdadbda0a846aa4d68691ac40eace5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1988 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  *      Copyright (c) 1997, by Sun Microsystems, Inc.
28  *      All rights reserved.
29  */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 /*LINTLIBRARY*/
34 
35 #include <sys/types.h>
36 #include "utility.h"
37 
38 int
39 post_form(FORM *f)
40 {
41 	int x, y, v;
42 
43 	if (!f)
44 		return (E_BAD_ARGUMENT);
45 
46 	if (Status(f, POSTED))
47 		return (E_POSTED);
48 
49 	if (!f->field)
50 		return (E_NOT_CONNECTED);
51 
52 	getmaxyx(Sub(f), y, x);
53 
54 	if (f->rows > y || f->cols > x)
55 		return (E_NO_ROOM);
56 
57 	v = _set_form_page(f, P(f), C(f));
58 
59 	if (v != E_OK)
60 		return (v);
61 
62 	Set(f, POSTED);
63 	init_form(f);
64 	init_field(f);
65 	(void) _update_current(f);
66 	return (E_OK);
67 }
68 
69 int
70 unpost_form(FORM *f)
71 {
72 	if (!f)
73 		return (E_BAD_ARGUMENT);
74 
75 	if (!Status(f, POSTED))
76 		return (E_NOT_POSTED);
77 
78 	if (Status(f, DRIVER))
79 		return (E_BAD_STATE);
80 
81 	term_field(f);
82 	term_form(f);
83 	(void) werase(Sub(f));
84 	(void) delwin(W(f));
85 	W(f) = (WINDOW *) 0;
86 	Clr(f, POSTED);
87 	return (E_OK);
88 }
89 
90 /* pos_form_cursor - move to cursor position and sync up */
91 int
92 pos_form_cursor(FORM *f)
93 {
94 	if (!f)
95 		return (E_BAD_ARGUMENT);
96 
97 	if (!Status(f, POSTED))
98 		return (E_NOT_POSTED);
99 
100 	return (_pos_form_cursor(f));
101 }
102 
103 int
104 set_current_field(FORM *f, FIELD *c)
105 {
106 	if (!f || !c || c->form != f)
107 		return (E_BAD_ARGUMENT);
108 
109 	if (!Opt(c, O_ACTIVE) || !Opt(c, O_VISIBLE))
110 		return (E_REQUEST_DENIED);
111 
112 	if (!Status(f, POSTED)) {
113 		C(f) = c;
114 		P(f) = c->page;
115 		return (E_OK);
116 	}
117 	if (Status(f, DRIVER))
118 		return (E_BAD_STATE);
119 
120 	if (c != C(f)) {
121 		if (_validate(f)) {
122 			int v;
123 
124 			term_field(f);
125 
126 			if (c -> page != P(f)) {	/* page change */
127 				term_form(f);
128 				v = _set_form_page(f, c->page, c);
129 				init_form(f);
130 			} else
131 				v = _set_current_field(f, c);
132 
133 			init_field(f);
134 			(void) _update_current(f);
135 			return (v);
136 		} else
137 			return (E_INVALID_FIELD);
138 	}
139 	return (E_OK);
140 }
141 
142 FIELD *
143 current_field(FORM *f)
144 {
145 	return (C(Form(f)));
146 }
147 
148 int
149 field_index(FIELD *f)
150 {
151 	if (f && f->form)
152 		return (f->index);
153 	else
154 		return (-1);
155 }
156 
157 int
158 set_form_page(FORM *f, int page)
159 {
160 	if (!f || !ValidPage(f, page))
161 		return (E_BAD_ARGUMENT);
162 
163 	if (!Status(f, POSTED)) {
164 		P(f) = page;
165 		C(f) = _first_active(f);
166 		return (E_OK);
167 	}
168 	if (Status(f, DRIVER))
169 		return (E_BAD_STATE);
170 
171 	if (page != P(f)) {
172 		if (_validate(f)) {
173 			int v;
174 
175 			term_field(f);
176 			term_form(f);
177 			v = _set_form_page(f, page, (FIELD *) 0);
178 			init_form(f);
179 			init_field(f);
180 			(void) _update_current(f);
181 			return (v);
182 		} else
183 			return (E_INVALID_FIELD);
184 	}
185 	return (E_OK);
186 }
187 
188 	/*
189 	 *  form_page
190 	 */
191 
192 int
193 form_page(FORM *f)
194 {
195 	return (P(Form(f)));
196 }
197