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