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