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 #pragma ident "%Z%%M% %I% %E% SMI"
32*7c478bd9Sstevel@tonic-gate
33*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
34*7c478bd9Sstevel@tonic-gate
35*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
36*7c478bd9Sstevel@tonic-gate #include "utility.h"
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate int
post_form(FORM * f)39*7c478bd9Sstevel@tonic-gate post_form(FORM *f)
40*7c478bd9Sstevel@tonic-gate {
41*7c478bd9Sstevel@tonic-gate int x, y, v;
42*7c478bd9Sstevel@tonic-gate
43*7c478bd9Sstevel@tonic-gate if (!f)
44*7c478bd9Sstevel@tonic-gate return (E_BAD_ARGUMENT);
45*7c478bd9Sstevel@tonic-gate
46*7c478bd9Sstevel@tonic-gate if (Status(f, POSTED))
47*7c478bd9Sstevel@tonic-gate return (E_POSTED);
48*7c478bd9Sstevel@tonic-gate
49*7c478bd9Sstevel@tonic-gate if (!f->field)
50*7c478bd9Sstevel@tonic-gate return (E_NOT_CONNECTED);
51*7c478bd9Sstevel@tonic-gate
52*7c478bd9Sstevel@tonic-gate getmaxyx(Sub(f), y, x);
53*7c478bd9Sstevel@tonic-gate
54*7c478bd9Sstevel@tonic-gate if (f->rows > y || f->cols > x)
55*7c478bd9Sstevel@tonic-gate return (E_NO_ROOM);
56*7c478bd9Sstevel@tonic-gate
57*7c478bd9Sstevel@tonic-gate v = _set_form_page(f, P(f), C(f));
58*7c478bd9Sstevel@tonic-gate
59*7c478bd9Sstevel@tonic-gate if (v != E_OK)
60*7c478bd9Sstevel@tonic-gate return (v);
61*7c478bd9Sstevel@tonic-gate
62*7c478bd9Sstevel@tonic-gate Set(f, POSTED);
63*7c478bd9Sstevel@tonic-gate init_form(f);
64*7c478bd9Sstevel@tonic-gate init_field(f);
65*7c478bd9Sstevel@tonic-gate (void) _update_current(f);
66*7c478bd9Sstevel@tonic-gate return (E_OK);
67*7c478bd9Sstevel@tonic-gate }
68*7c478bd9Sstevel@tonic-gate
69*7c478bd9Sstevel@tonic-gate int
unpost_form(FORM * f)70*7c478bd9Sstevel@tonic-gate unpost_form(FORM *f)
71*7c478bd9Sstevel@tonic-gate {
72*7c478bd9Sstevel@tonic-gate if (!f)
73*7c478bd9Sstevel@tonic-gate return (E_BAD_ARGUMENT);
74*7c478bd9Sstevel@tonic-gate
75*7c478bd9Sstevel@tonic-gate if (!Status(f, POSTED))
76*7c478bd9Sstevel@tonic-gate return (E_NOT_POSTED);
77*7c478bd9Sstevel@tonic-gate
78*7c478bd9Sstevel@tonic-gate if (Status(f, DRIVER))
79*7c478bd9Sstevel@tonic-gate return (E_BAD_STATE);
80*7c478bd9Sstevel@tonic-gate
81*7c478bd9Sstevel@tonic-gate term_field(f);
82*7c478bd9Sstevel@tonic-gate term_form(f);
83*7c478bd9Sstevel@tonic-gate (void) werase(Sub(f));
84*7c478bd9Sstevel@tonic-gate (void) delwin(W(f));
85*7c478bd9Sstevel@tonic-gate W(f) = (WINDOW *) 0;
86*7c478bd9Sstevel@tonic-gate Clr(f, POSTED);
87*7c478bd9Sstevel@tonic-gate return (E_OK);
88*7c478bd9Sstevel@tonic-gate }
89*7c478bd9Sstevel@tonic-gate
90*7c478bd9Sstevel@tonic-gate /* pos_form_cursor - move to cursor position and sync up */
91*7c478bd9Sstevel@tonic-gate int
pos_form_cursor(FORM * f)92*7c478bd9Sstevel@tonic-gate pos_form_cursor(FORM *f)
93*7c478bd9Sstevel@tonic-gate {
94*7c478bd9Sstevel@tonic-gate if (!f)
95*7c478bd9Sstevel@tonic-gate return (E_BAD_ARGUMENT);
96*7c478bd9Sstevel@tonic-gate
97*7c478bd9Sstevel@tonic-gate if (!Status(f, POSTED))
98*7c478bd9Sstevel@tonic-gate return (E_NOT_POSTED);
99*7c478bd9Sstevel@tonic-gate
100*7c478bd9Sstevel@tonic-gate return (_pos_form_cursor(f));
101*7c478bd9Sstevel@tonic-gate }
102*7c478bd9Sstevel@tonic-gate
103*7c478bd9Sstevel@tonic-gate int
set_current_field(FORM * f,FIELD * c)104*7c478bd9Sstevel@tonic-gate set_current_field(FORM *f, FIELD *c)
105*7c478bd9Sstevel@tonic-gate {
106*7c478bd9Sstevel@tonic-gate if (!f || !c || c->form != f)
107*7c478bd9Sstevel@tonic-gate return (E_BAD_ARGUMENT);
108*7c478bd9Sstevel@tonic-gate
109*7c478bd9Sstevel@tonic-gate if (!Opt(c, O_ACTIVE) || !Opt(c, O_VISIBLE))
110*7c478bd9Sstevel@tonic-gate return (E_REQUEST_DENIED);
111*7c478bd9Sstevel@tonic-gate
112*7c478bd9Sstevel@tonic-gate if (!Status(f, POSTED)) {
113*7c478bd9Sstevel@tonic-gate C(f) = c;
114*7c478bd9Sstevel@tonic-gate P(f) = c->page;
115*7c478bd9Sstevel@tonic-gate return (E_OK);
116*7c478bd9Sstevel@tonic-gate }
117*7c478bd9Sstevel@tonic-gate if (Status(f, DRIVER))
118*7c478bd9Sstevel@tonic-gate return (E_BAD_STATE);
119*7c478bd9Sstevel@tonic-gate
120*7c478bd9Sstevel@tonic-gate if (c != C(f)) {
121*7c478bd9Sstevel@tonic-gate if (_validate(f)) {
122*7c478bd9Sstevel@tonic-gate int v;
123*7c478bd9Sstevel@tonic-gate
124*7c478bd9Sstevel@tonic-gate term_field(f);
125*7c478bd9Sstevel@tonic-gate
126*7c478bd9Sstevel@tonic-gate if (c -> page != P(f)) { /* page change */
127*7c478bd9Sstevel@tonic-gate term_form(f);
128*7c478bd9Sstevel@tonic-gate v = _set_form_page(f, c->page, c);
129*7c478bd9Sstevel@tonic-gate init_form(f);
130*7c478bd9Sstevel@tonic-gate } else
131*7c478bd9Sstevel@tonic-gate v = _set_current_field(f, c);
132*7c478bd9Sstevel@tonic-gate
133*7c478bd9Sstevel@tonic-gate init_field(f);
134*7c478bd9Sstevel@tonic-gate (void) _update_current(f);
135*7c478bd9Sstevel@tonic-gate return (v);
136*7c478bd9Sstevel@tonic-gate } else
137*7c478bd9Sstevel@tonic-gate return (E_INVALID_FIELD);
138*7c478bd9Sstevel@tonic-gate }
139*7c478bd9Sstevel@tonic-gate return (E_OK);
140*7c478bd9Sstevel@tonic-gate }
141*7c478bd9Sstevel@tonic-gate
142*7c478bd9Sstevel@tonic-gate FIELD *
current_field(FORM * f)143*7c478bd9Sstevel@tonic-gate current_field(FORM *f)
144*7c478bd9Sstevel@tonic-gate {
145*7c478bd9Sstevel@tonic-gate return (C(Form(f)));
146*7c478bd9Sstevel@tonic-gate }
147*7c478bd9Sstevel@tonic-gate
148*7c478bd9Sstevel@tonic-gate int
field_index(FIELD * f)149*7c478bd9Sstevel@tonic-gate field_index(FIELD *f)
150*7c478bd9Sstevel@tonic-gate {
151*7c478bd9Sstevel@tonic-gate if (f && f->form)
152*7c478bd9Sstevel@tonic-gate return (f->index);
153*7c478bd9Sstevel@tonic-gate else
154*7c478bd9Sstevel@tonic-gate return (-1);
155*7c478bd9Sstevel@tonic-gate }
156*7c478bd9Sstevel@tonic-gate
157*7c478bd9Sstevel@tonic-gate int
set_form_page(FORM * f,int page)158*7c478bd9Sstevel@tonic-gate set_form_page(FORM *f, int page)
159*7c478bd9Sstevel@tonic-gate {
160*7c478bd9Sstevel@tonic-gate if (!f || !ValidPage(f, page))
161*7c478bd9Sstevel@tonic-gate return (E_BAD_ARGUMENT);
162*7c478bd9Sstevel@tonic-gate
163*7c478bd9Sstevel@tonic-gate if (!Status(f, POSTED)) {
164*7c478bd9Sstevel@tonic-gate P(f) = page;
165*7c478bd9Sstevel@tonic-gate C(f) = _first_active(f);
166*7c478bd9Sstevel@tonic-gate return (E_OK);
167*7c478bd9Sstevel@tonic-gate }
168*7c478bd9Sstevel@tonic-gate if (Status(f, DRIVER))
169*7c478bd9Sstevel@tonic-gate return (E_BAD_STATE);
170*7c478bd9Sstevel@tonic-gate
171*7c478bd9Sstevel@tonic-gate if (page != P(f)) {
172*7c478bd9Sstevel@tonic-gate if (_validate(f)) {
173*7c478bd9Sstevel@tonic-gate int v;
174*7c478bd9Sstevel@tonic-gate
175*7c478bd9Sstevel@tonic-gate term_field(f);
176*7c478bd9Sstevel@tonic-gate term_form(f);
177*7c478bd9Sstevel@tonic-gate v = _set_form_page(f, page, (FIELD *) 0);
178*7c478bd9Sstevel@tonic-gate init_form(f);
179*7c478bd9Sstevel@tonic-gate init_field(f);
180*7c478bd9Sstevel@tonic-gate (void) _update_current(f);
181*7c478bd9Sstevel@tonic-gate return (v);
182*7c478bd9Sstevel@tonic-gate } else
183*7c478bd9Sstevel@tonic-gate return (E_INVALID_FIELD);
184*7c478bd9Sstevel@tonic-gate }
185*7c478bd9Sstevel@tonic-gate return (E_OK);
186*7c478bd9Sstevel@tonic-gate }
187*7c478bd9Sstevel@tonic-gate
188*7c478bd9Sstevel@tonic-gate /*
189*7c478bd9Sstevel@tonic-gate * form_page
190*7c478bd9Sstevel@tonic-gate */
191*7c478bd9Sstevel@tonic-gate
192*7c478bd9Sstevel@tonic-gate int
form_page(FORM * f)193*7c478bd9Sstevel@tonic-gate form_page(FORM *f)
194*7c478bd9Sstevel@tonic-gate {
195*7c478bd9Sstevel@tonic-gate return (P(Form(f)));
196*7c478bd9Sstevel@tonic-gate }
197