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