8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libeti / form / common / post.c
blob8853d120c4eb86a20d7ff2c7513f815b12ccd8f3
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
22 /* Copyright (c) 1988 AT&T */
23 /* All Rights Reserved */
27 * Copyright (c) 1997, by Sun Microsystems, Inc.
28 * All rights reserved.
31 #pragma ident "%Z%%M% %I% %E% SMI"
33 /*LINTLIBRARY*/
35 #include <sys/types.h>
36 #include "utility.h"
38 int
39 post_form(FORM *f)
41 int x, y, v;
43 if (!f)
44 return (E_BAD_ARGUMENT);
46 if (Status(f, POSTED))
47 return (E_POSTED);
49 if (!f->field)
50 return (E_NOT_CONNECTED);
52 getmaxyx(Sub(f), y, x);
54 if (f->rows > y || f->cols > x)
55 return (E_NO_ROOM);
57 v = _set_form_page(f, P(f), C(f));
59 if (v != E_OK)
60 return (v);
62 Set(f, POSTED);
63 init_form(f);
64 init_field(f);
65 (void) _update_current(f);
66 return (E_OK);
69 int
70 unpost_form(FORM *f)
72 if (!f)
73 return (E_BAD_ARGUMENT);
75 if (!Status(f, POSTED))
76 return (E_NOT_POSTED);
78 if (Status(f, DRIVER))
79 return (E_BAD_STATE);
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);
90 /* pos_form_cursor - move to cursor position and sync up */
91 int
92 pos_form_cursor(FORM *f)
94 if (!f)
95 return (E_BAD_ARGUMENT);
97 if (!Status(f, POSTED))
98 return (E_NOT_POSTED);
100 return (_pos_form_cursor(f));
104 set_current_field(FORM *f, FIELD *c)
106 if (!f || !c || c->form != f)
107 return (E_BAD_ARGUMENT);
109 if (!Opt(c, O_ACTIVE) || !Opt(c, O_VISIBLE))
110 return (E_REQUEST_DENIED);
112 if (!Status(f, POSTED)) {
113 C(f) = c;
114 P(f) = c->page;
115 return (E_OK);
117 if (Status(f, DRIVER))
118 return (E_BAD_STATE);
120 if (c != C(f)) {
121 if (_validate(f)) {
122 int v;
124 term_field(f);
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);
133 init_field(f);
134 (void) _update_current(f);
135 return (v);
136 } else
137 return (E_INVALID_FIELD);
139 return (E_OK);
142 FIELD *
143 current_field(FORM *f)
145 return (C(Form(f)));
149 field_index(FIELD *f)
151 if (f && f->form)
152 return (f->index);
153 else
154 return (-1);
158 set_form_page(FORM *f, int page)
160 if (!f || !ValidPage(f, page))
161 return (E_BAD_ARGUMENT);
163 if (!Status(f, POSTED)) {
164 P(f) = page;
165 C(f) = _first_active(f);
166 return (E_OK);
168 if (Status(f, DRIVER))
169 return (E_BAD_STATE);
171 if (page != P(f)) {
172 if (_validate(f)) {
173 int v;
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);
185 return (E_OK);
189 * form_page
193 form_page(FORM *f)
195 return (P(Form(f)));