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" /* SVr4.0 1.7 */ 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 #define Scrollable(f) ((f)->drows > (f)->rows || \ 39*0Sstevel@tonic-gate (f)->dcols > (f)->cols) 40*0Sstevel@tonic-gate #define Connected(f) ((f) -> form != (FORM *) 0) 41*0Sstevel@tonic-gate #define OnPage(f) ((f) -> page == P((f) -> form)) 42*0Sstevel@tonic-gate #define Posted(f) (Status((f) -> form, POSTED)) 43*0Sstevel@tonic-gate #define Visible(f) (Opt(f, O_VISIBLE) && OnPage(f)) 44*0Sstevel@tonic-gate #define isCurrent(f) ((f) == C((f) -> form)) 45*0Sstevel@tonic-gate #define Justified(f) (Just(f) != NO_JUSTIFICATION && \ 46*0Sstevel@tonic-gate OneRow(f) && Opt(f, O_STATIC) && \ 47*0Sstevel@tonic-gate f->dcols == f->cols) 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate /* _data_beg - return ptr to first non-blank char in v[n] (v on failure) */ 50*0Sstevel@tonic-gate char * 51*0Sstevel@tonic-gate _data_beg(char *v, int n) 52*0Sstevel@tonic-gate { 53*0Sstevel@tonic-gate char *vend = v + n; 54*0Sstevel@tonic-gate while (v < vend && *v == ' ') ++v; 55*0Sstevel@tonic-gate return (v == vend ? v - n : v); 56*0Sstevel@tonic-gate } 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate /* 59*0Sstevel@tonic-gate * _data_end - return ptr to char after last 60*0Sstevel@tonic-gate * non-blank char in v[n] (v on failure) 61*0Sstevel@tonic-gate */ 62*0Sstevel@tonic-gate char * 63*0Sstevel@tonic-gate _data_end(char *v, int n) 64*0Sstevel@tonic-gate { 65*0Sstevel@tonic-gate char *vend = v + n; 66*0Sstevel@tonic-gate while (vend > v && *(vend - 1) == ' ') --vend; 67*0Sstevel@tonic-gate return (vend); 68*0Sstevel@tonic-gate } 69*0Sstevel@tonic-gate 70*0Sstevel@tonic-gate /* _whsp_beg - return ptr to first blank in v[n] (v on failure) */ 71*0Sstevel@tonic-gate char * 72*0Sstevel@tonic-gate _whsp_beg(char *v, int n) 73*0Sstevel@tonic-gate { 74*0Sstevel@tonic-gate char * vend = v + n; 75*0Sstevel@tonic-gate while (v < vend && *v != ' ') ++v; 76*0Sstevel@tonic-gate return (v == vend ? v - n : v); 77*0Sstevel@tonic-gate } 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate /* _whsp_end - return ptr to char after last blank in v[n] (v on failure) */ 80*0Sstevel@tonic-gate char * 81*0Sstevel@tonic-gate _whsp_end(char *v, int n) 82*0Sstevel@tonic-gate { 83*0Sstevel@tonic-gate char * vend = v + n; 84*0Sstevel@tonic-gate while (vend > v && *(vend - 1) != ' ') --vend; 85*0Sstevel@tonic-gate return (vend); 86*0Sstevel@tonic-gate } 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate /* 89*0Sstevel@tonic-gate * _adjust_cursor - adjust cursor based on 90*0Sstevel@tonic-gate * offset of v from beginning of field buffer 91*0Sstevel@tonic-gate */ 92*0Sstevel@tonic-gate void 93*0Sstevel@tonic-gate _adjust_cursor(FORM *f, char *v) 94*0Sstevel@tonic-gate { 95*0Sstevel@tonic-gate int pos = (int) (v - Buf(C(f))); 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gate Y(f) = pos / Xmax(f); 98*0Sstevel@tonic-gate X(f) = pos - Y(f) * Xmax(f); 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate if (Y(f) >= Ymax(f)) 101*0Sstevel@tonic-gate Y(f) = 0; 102*0Sstevel@tonic-gate } 103*0Sstevel@tonic-gate 104*0Sstevel@tonic-gate /* 105*0Sstevel@tonic-gate * _buf_to_win - copy buffer to window(trailing 106*0Sstevel@tonic-gate * blanks on each line are not copied) 107*0Sstevel@tonic-gate */ 108*0Sstevel@tonic-gate void 109*0Sstevel@tonic-gate _buf_to_win(FIELD *f, WINDOW *w) 110*0Sstevel@tonic-gate { 111*0Sstevel@tonic-gate char * v = Buf(f); 112*0Sstevel@tonic-gate int xmax, ymax, y, n; 113*0Sstevel@tonic-gate 114*0Sstevel@tonic-gate getmaxyx(w, ymax, xmax); 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gate for (y = 0; y < ymax; ++y) { 117*0Sstevel@tonic-gate if ((n = (int) (_data_end(v, xmax) - v)) != 0) { 118*0Sstevel@tonic-gate (void) wmove(w, y, 0); 119*0Sstevel@tonic-gate (void) waddnstr(w, v, n); 120*0Sstevel@tonic-gate } 121*0Sstevel@tonic-gate v += xmax; 122*0Sstevel@tonic-gate } 123*0Sstevel@tonic-gate } 124*0Sstevel@tonic-gate 125*0Sstevel@tonic-gate /* _win_to_buf - copy window to buffer */ 126*0Sstevel@tonic-gate void 127*0Sstevel@tonic-gate _win_to_buf(WINDOW *w, FIELD *f) 128*0Sstevel@tonic-gate { 129*0Sstevel@tonic-gate int i; 130*0Sstevel@tonic-gate int size = BufSize(f); 131*0Sstevel@tonic-gate int pad = Pad(f); 132*0Sstevel@tonic-gate char * v = Buf(f); 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate (void) wmove(w, 0, 0); 135*0Sstevel@tonic-gate (void) winnstr(w, v, size); 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate if (pad != ' ') 138*0Sstevel@tonic-gate for (i = 0; i < size; ++i, ++v) 139*0Sstevel@tonic-gate if (*v == pad) 140*0Sstevel@tonic-gate *v = ' '; /* replace pad char with blank */ 141*0Sstevel@tonic-gate } 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate /* _pos_form_cursor - move to cursor position and sync up cursor */ 144*0Sstevel@tonic-gate int 145*0Sstevel@tonic-gate _pos_form_cursor(FORM *f) 146*0Sstevel@tonic-gate { 147*0Sstevel@tonic-gate WINDOW * w = W(f); 148*0Sstevel@tonic-gate FIELD * c = C(f); 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gate if (!w) 151*0Sstevel@tonic-gate return (E_SYSTEM_ERROR); 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate (void) wmove(w, Y(f), X(f)); 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate if (Opt(c, O_PUBLIC)) { 156*0Sstevel@tonic-gate if (Scrollable(c)) { 157*0Sstevel@tonic-gate int row, col; 158*0Sstevel@tonic-gate 159*0Sstevel@tonic-gate if (OneRow(c)) { 160*0Sstevel@tonic-gate row = c->frow; 161*0Sstevel@tonic-gate col = c->fcol + X(f) - B(f); 162*0Sstevel@tonic-gate } else { 163*0Sstevel@tonic-gate row = c -> frow + Y(f) - T(f); 164*0Sstevel@tonic-gate col = c -> fcol + X(f); 165*0Sstevel@tonic-gate } 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate (void) wmove(Sub(f), row, col); 168*0Sstevel@tonic-gate wcursyncup(Sub(f)); 169*0Sstevel@tonic-gate } else 170*0Sstevel@tonic-gate wcursyncup(w); 171*0Sstevel@tonic-gate } else { 172*0Sstevel@tonic-gate (void) wmove(Sub(f), c -> frow, c -> fcol); 173*0Sstevel@tonic-gate wcursyncup(Sub(f)); 174*0Sstevel@tonic-gate } 175*0Sstevel@tonic-gate return (E_OK); 176*0Sstevel@tonic-gate } 177*0Sstevel@tonic-gate 178*0Sstevel@tonic-gate /* _update_current - sync up current field */ 179*0Sstevel@tonic-gate int 180*0Sstevel@tonic-gate _update_current(FORM *f) 181*0Sstevel@tonic-gate { 182*0Sstevel@tonic-gate WINDOW * w = W(f); 183*0Sstevel@tonic-gate FIELD * c = C(f); 184*0Sstevel@tonic-gate 185*0Sstevel@tonic-gate if (!w) 186*0Sstevel@tonic-gate return (E_SYSTEM_ERROR); 187*0Sstevel@tonic-gate 188*0Sstevel@tonic-gate if (Opt(c, O_PUBLIC)) { 189*0Sstevel@tonic-gate if (Scrollable(c)) { 190*0Sstevel@tonic-gate if (OneRow(c)) { 191*0Sstevel@tonic-gate int xmax = B(f) + c->cols; 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gate if (X(f) < B(f)) 194*0Sstevel@tonic-gate B(f) = X(f); 195*0Sstevel@tonic-gate else if (X(f) >= xmax) 196*0Sstevel@tonic-gate B(f) = X(f) - c->cols + 1; 197*0Sstevel@tonic-gate 198*0Sstevel@tonic-gate (void) copywin(w, Sub(f), 0, B(f), c->frow, 199*0Sstevel@tonic-gate c->fcol, c->frow, c->fcol + c->cols - 1, 200*0Sstevel@tonic-gate FALSE); 201*0Sstevel@tonic-gate 202*0Sstevel@tonic-gate } else { 203*0Sstevel@tonic-gate int ymax = T(f) + c -> rows; 204*0Sstevel@tonic-gate int ys, ye; 205*0Sstevel@tonic-gate 206*0Sstevel@tonic-gate if (Y(f) < T(f)) { 207*0Sstevel@tonic-gate T(f) = Y(f); 208*0Sstevel@tonic-gate Set(c, TOP_CHG); 209*0Sstevel@tonic-gate } 210*0Sstevel@tonic-gate if (Y(f) >= ymax) { 211*0Sstevel@tonic-gate T(f) = Y(f) - c -> rows + 1; 212*0Sstevel@tonic-gate Set(c, TOP_CHG); 213*0Sstevel@tonic-gate } 214*0Sstevel@tonic-gate if (Status(c, TOP_CHG)) { 215*0Sstevel@tonic-gate ys = T(f); 216*0Sstevel@tonic-gate ye = ys + c -> rows; 217*0Sstevel@tonic-gate Clr(c, TOP_CHG); 218*0Sstevel@tonic-gate } else { 219*0Sstevel@tonic-gate /* intersect changed lines with visible lines */ 220*0Sstevel@tonic-gate for (ys = T(f); ys < ymax; ++ys) 221*0Sstevel@tonic-gate if (is_linetouched(w, ys)) 222*0Sstevel@tonic-gate break; 223*0Sstevel@tonic-gate 224*0Sstevel@tonic-gate for (ye = ys; ye < ymax; ++ye) 225*0Sstevel@tonic-gate if (! is_linetouched(w, ye)) 226*0Sstevel@tonic-gate break; 227*0Sstevel@tonic-gate } 228*0Sstevel@tonic-gate if (ye - ys) { 229*0Sstevel@tonic-gate (void) copywin(w, Sub(f), ys, 0, 230*0Sstevel@tonic-gate c -> frow + ys - T(f), c -> fcol, 231*0Sstevel@tonic-gate c -> frow + ye - T(f) - 1, 232*0Sstevel@tonic-gate c -> fcol + c -> cols - 1, FALSE); 233*0Sstevel@tonic-gate } 234*0Sstevel@tonic-gate } 235*0Sstevel@tonic-gate wsyncup(Sub(f)); 236*0Sstevel@tonic-gate } else 237*0Sstevel@tonic-gate wsyncup(w); 238*0Sstevel@tonic-gate } 239*0Sstevel@tonic-gate (void) untouchwin(w); 240*0Sstevel@tonic-gate return (_pos_form_cursor(f)); 241*0Sstevel@tonic-gate } 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gate /* justify - justify field f in window w as given by Just(f) */ 244*0Sstevel@tonic-gate static void 245*0Sstevel@tonic-gate justify(FIELD *f, WINDOW *w) 246*0Sstevel@tonic-gate { 247*0Sstevel@tonic-gate char * v = _data_beg(Buf(f), BufSize(f)); 248*0Sstevel@tonic-gate char * vend = _data_end(Buf(f), BufSize(f)); 249*0Sstevel@tonic-gate int n = (int) (vend - v); 250*0Sstevel@tonic-gate int x = 0; 251*0Sstevel@tonic-gate 252*0Sstevel@tonic-gate if (n) { 253*0Sstevel@tonic-gate switch (Just(f)) { 254*0Sstevel@tonic-gate case JUSTIFY_LEFT: 255*0Sstevel@tonic-gate break; 256*0Sstevel@tonic-gate case JUSTIFY_CENTER: 257*0Sstevel@tonic-gate x = (f -> cols - n) / 2; 258*0Sstevel@tonic-gate break; 259*0Sstevel@tonic-gate case JUSTIFY_RIGHT: 260*0Sstevel@tonic-gate x = f -> cols - n; 261*0Sstevel@tonic-gate break; 262*0Sstevel@tonic-gate } 263*0Sstevel@tonic-gate (void) wmove(w, 0, x); 264*0Sstevel@tonic-gate (void) waddnstr(w, v, n); 265*0Sstevel@tonic-gate } 266*0Sstevel@tonic-gate } 267*0Sstevel@tonic-gate 268*0Sstevel@tonic-gate /* unjustify - left justify field f in window w for editing */ 269*0Sstevel@tonic-gate static void 270*0Sstevel@tonic-gate unjustify(FIELD *f, WINDOW *w) 271*0Sstevel@tonic-gate { 272*0Sstevel@tonic-gate char * v = _data_beg(Buf(f), BufSize(f)); 273*0Sstevel@tonic-gate char * vend = _data_end(Buf(f), BufSize(f)); 274*0Sstevel@tonic-gate int n = (int) (vend - v); 275*0Sstevel@tonic-gate 276*0Sstevel@tonic-gate if (n) { 277*0Sstevel@tonic-gate (void) wmove(w, 0, 0); 278*0Sstevel@tonic-gate (void) waddnstr(w, v, n); 279*0Sstevel@tonic-gate } 280*0Sstevel@tonic-gate } 281*0Sstevel@tonic-gate 282*0Sstevel@tonic-gate /* _sync_buffer - sync current field with characters in window */ 283*0Sstevel@tonic-gate void 284*0Sstevel@tonic-gate _sync_buffer(FORM *f) 285*0Sstevel@tonic-gate { 286*0Sstevel@tonic-gate if (Status(f, WIN_CHG)) { 287*0Sstevel@tonic-gate Clr(f, WIN_CHG); 288*0Sstevel@tonic-gate Set(f, BUF_CHG); 289*0Sstevel@tonic-gate _win_to_buf(W(f), C(f)); 290*0Sstevel@tonic-gate (void) wmove(W(f), Y(f), X(f)); 291*0Sstevel@tonic-gate } 292*0Sstevel@tonic-gate } 293*0Sstevel@tonic-gate 294*0Sstevel@tonic-gate /* _sync_linked - sync fields linked to field f */ 295*0Sstevel@tonic-gate int 296*0Sstevel@tonic-gate _sync_linked(FIELD *f) 297*0Sstevel@tonic-gate { 298*0Sstevel@tonic-gate FIELD * p = f -> link; 299*0Sstevel@tonic-gate int err = 0; 300*0Sstevel@tonic-gate 301*0Sstevel@tonic-gate while (p != f) { 302*0Sstevel@tonic-gate if (_sync_field(p) != E_OK) 303*0Sstevel@tonic-gate ++err; 304*0Sstevel@tonic-gate p = p -> link; 305*0Sstevel@tonic-gate } 306*0Sstevel@tonic-gate return (err ? E_SYSTEM_ERROR : E_OK); 307*0Sstevel@tonic-gate } 308*0Sstevel@tonic-gate 309*0Sstevel@tonic-gate /* display_field - display field f */ 310*0Sstevel@tonic-gate static int 311*0Sstevel@tonic-gate display_field(FIELD *f) 312*0Sstevel@tonic-gate { 313*0Sstevel@tonic-gate WINDOW * w = derwin(Sub(f -> form), f -> rows, f -> cols, 314*0Sstevel@tonic-gate f -> frow, f -> fcol); 315*0Sstevel@tonic-gate 316*0Sstevel@tonic-gate if (!w) 317*0Sstevel@tonic-gate return (FALSE); 318*0Sstevel@tonic-gate 319*0Sstevel@tonic-gate wbkgdset(w, Pad(f) | Back(f)); 320*0Sstevel@tonic-gate (void) wattrset(w, Fore(f)); 321*0Sstevel@tonic-gate (void) werase(w); 322*0Sstevel@tonic-gate 323*0Sstevel@tonic-gate if (Opt(f, O_PUBLIC)) { 324*0Sstevel@tonic-gate if (Justified(f)) 325*0Sstevel@tonic-gate justify(f, w); 326*0Sstevel@tonic-gate else 327*0Sstevel@tonic-gate _buf_to_win(f, w); 328*0Sstevel@tonic-gate } 329*0Sstevel@tonic-gate wsyncup(w); 330*0Sstevel@tonic-gate (void) delwin(w); 331*0Sstevel@tonic-gate Clr(f, TOP_CHG); 332*0Sstevel@tonic-gate return (TRUE); 333*0Sstevel@tonic-gate } 334*0Sstevel@tonic-gate 335*0Sstevel@tonic-gate /* erase_field - erase field f */ 336*0Sstevel@tonic-gate static int 337*0Sstevel@tonic-gate erase_field(FIELD *f) 338*0Sstevel@tonic-gate { 339*0Sstevel@tonic-gate WINDOW * w = derwin(Sub(f -> form), f -> rows, f -> cols, 340*0Sstevel@tonic-gate f -> frow, f -> fcol); 341*0Sstevel@tonic-gate 342*0Sstevel@tonic-gate if (!w) 343*0Sstevel@tonic-gate return (FALSE); 344*0Sstevel@tonic-gate 345*0Sstevel@tonic-gate (void) werase(w); 346*0Sstevel@tonic-gate wsyncup(w); 347*0Sstevel@tonic-gate (void) delwin(w); 348*0Sstevel@tonic-gate return (TRUE); 349*0Sstevel@tonic-gate } 350*0Sstevel@tonic-gate 351*0Sstevel@tonic-gate /* _sync_field - sync the field after a change to the field buffer */ 352*0Sstevel@tonic-gate int 353*0Sstevel@tonic-gate _sync_field(FIELD *f) 354*0Sstevel@tonic-gate { 355*0Sstevel@tonic-gate int v = TRUE; 356*0Sstevel@tonic-gate 357*0Sstevel@tonic-gate if (Connected(f) && Posted(f) && Visible(f)) { 358*0Sstevel@tonic-gate if (isCurrent(f)) { 359*0Sstevel@tonic-gate FORM * p = f -> form; 360*0Sstevel@tonic-gate WINDOW * w = W(p); 361*0Sstevel@tonic-gate 362*0Sstevel@tonic-gate Clr(p, WIN_CHG | BUF_CHG); 363*0Sstevel@tonic-gate 364*0Sstevel@tonic-gate Y(p) = 0; 365*0Sstevel@tonic-gate X(p) = 0; 366*0Sstevel@tonic-gate T(p) = 0; 367*0Sstevel@tonic-gate B(p) = 0; 368*0Sstevel@tonic-gate (void) werase(w); 369*0Sstevel@tonic-gate 370*0Sstevel@tonic-gate if (Opt(f, O_PUBLIC) && Justified(f)) 371*0Sstevel@tonic-gate unjustify(f, w); 372*0Sstevel@tonic-gate else 373*0Sstevel@tonic-gate _buf_to_win(f, w); 374*0Sstevel@tonic-gate 375*0Sstevel@tonic-gate Set(f, TOP_CHG); 376*0Sstevel@tonic-gate (void) _update_current(p); 377*0Sstevel@tonic-gate } else 378*0Sstevel@tonic-gate v = display_field(f); 379*0Sstevel@tonic-gate } 380*0Sstevel@tonic-gate Set(f, USR_CHG); 381*0Sstevel@tonic-gate 382*0Sstevel@tonic-gate return (v ? E_OK : E_SYSTEM_ERROR); 383*0Sstevel@tonic-gate } 384*0Sstevel@tonic-gate 385*0Sstevel@tonic-gate /* _sync_attrs - sync the field after a change to a field attribute */ 386*0Sstevel@tonic-gate int 387*0Sstevel@tonic-gate _sync_attrs(FIELD *f) 388*0Sstevel@tonic-gate { 389*0Sstevel@tonic-gate int v = TRUE; 390*0Sstevel@tonic-gate 391*0Sstevel@tonic-gate if (Connected(f) && Posted(f) && Visible(f)) { 392*0Sstevel@tonic-gate if (isCurrent(f)) { 393*0Sstevel@tonic-gate FORM * p = f -> form; 394*0Sstevel@tonic-gate WINDOW * w = W(p); 395*0Sstevel@tonic-gate 396*0Sstevel@tonic-gate _sync_buffer(p); 397*0Sstevel@tonic-gate 398*0Sstevel@tonic-gate wbkgdset(w, Pad(f) | Back(f)); 399*0Sstevel@tonic-gate (void) wattrset(w, Fore(f)); 400*0Sstevel@tonic-gate (void) werase(w); 401*0Sstevel@tonic-gate 402*0Sstevel@tonic-gate if (Opt(f, O_PUBLIC)) { 403*0Sstevel@tonic-gate if (Justified(f)) 404*0Sstevel@tonic-gate unjustify(f, w); 405*0Sstevel@tonic-gate else 406*0Sstevel@tonic-gate _buf_to_win(f, w); 407*0Sstevel@tonic-gate } else { 408*0Sstevel@tonic-gate (void) copywin(w, Sub(p), 0, 0, f -> frow, 409*0Sstevel@tonic-gate f -> fcol, f -> rows - 1, f -> cols - 1, 410*0Sstevel@tonic-gate FALSE); 411*0Sstevel@tonic-gate wsyncup(Sub(p)); 412*0Sstevel@tonic-gate _buf_to_win(f, w); 413*0Sstevel@tonic-gate } 414*0Sstevel@tonic-gate Set(f, TOP_CHG); 415*0Sstevel@tonic-gate (void) _update_current(p); 416*0Sstevel@tonic-gate } else 417*0Sstevel@tonic-gate v = display_field(f); 418*0Sstevel@tonic-gate } 419*0Sstevel@tonic-gate return (v ? E_OK : E_SYSTEM_ERROR); 420*0Sstevel@tonic-gate } 421*0Sstevel@tonic-gate 422*0Sstevel@tonic-gate int 423*0Sstevel@tonic-gate _sync_opts(FIELD *f, OPTIONS opts) 424*0Sstevel@tonic-gate { 425*0Sstevel@tonic-gate int v = TRUE; 426*0Sstevel@tonic-gate OPTIONS oldopts = f -> opts; 427*0Sstevel@tonic-gate OPTIONS x = opts ^ oldopts; 428*0Sstevel@tonic-gate /* x & opt indicates option opt has changed state */ 429*0Sstevel@tonic-gate f -> opts = opts; 430*0Sstevel@tonic-gate 431*0Sstevel@tonic-gate if (Connected(f)) { 432*0Sstevel@tonic-gate if (isCurrent(f)) { 433*0Sstevel@tonic-gate f -> opts = oldopts; 434*0Sstevel@tonic-gate return (E_CURRENT); 435*0Sstevel@tonic-gate } 436*0Sstevel@tonic-gate if (Posted(f) && OnPage(f)) { 437*0Sstevel@tonic-gate if (x & O_VISIBLE) { 438*0Sstevel@tonic-gate if (Opt(f, O_VISIBLE)) 439*0Sstevel@tonic-gate v = display_field(f); 440*0Sstevel@tonic-gate else 441*0Sstevel@tonic-gate v = erase_field(f); 442*0Sstevel@tonic-gate } else if (x & O_PUBLIC) { 443*0Sstevel@tonic-gate if (Opt(f, O_VISIBLE)) 444*0Sstevel@tonic-gate v = display_field(f); 445*0Sstevel@tonic-gate } 446*0Sstevel@tonic-gate } 447*0Sstevel@tonic-gate } 448*0Sstevel@tonic-gate 449*0Sstevel@tonic-gate if (x & O_STATIC) { 450*0Sstevel@tonic-gate BOOLEAN onerow = OneRow(f); 451*0Sstevel@tonic-gate int max = f->maxgrow; 452*0Sstevel@tonic-gate 453*0Sstevel@tonic-gate if (Opt(f, O_STATIC)) { /* growth being turned off */ 454*0Sstevel@tonic-gate Clr(f, GROWABLE); 455*0Sstevel@tonic-gate 456*0Sstevel@tonic-gate if (onerow && f->cols == f->dcols && 457*0Sstevel@tonic-gate Just(f) != NO_JUSTIFICATION && Posted(f) && 458*0Sstevel@tonic-gate OnPage(f) && Opt(f, O_VISIBLE)) { 459*0Sstevel@tonic-gate (void) display_field(f); 460*0Sstevel@tonic-gate } 461*0Sstevel@tonic-gate } else if (!max || (onerow && f->dcols < max) || 462*0Sstevel@tonic-gate (!onerow && f->drows < max)) { 463*0Sstevel@tonic-gate Set(f, GROWABLE); 464*0Sstevel@tonic-gate 465*0Sstevel@tonic-gate if (onerow && Just(f) != NO_JUSTIFICATION && 466*0Sstevel@tonic-gate Posted(f) && OnPage(f) && Opt(f, O_VISIBLE)) { 467*0Sstevel@tonic-gate (void) display_field(f); 468*0Sstevel@tonic-gate } 469*0Sstevel@tonic-gate } 470*0Sstevel@tonic-gate } 471*0Sstevel@tonic-gate 472*0Sstevel@tonic-gate return (v ? E_OK : E_SYSTEM_ERROR); 473*0Sstevel@tonic-gate } 474*0Sstevel@tonic-gate 475*0Sstevel@tonic-gate /* _validate - validate current field */ 476*0Sstevel@tonic-gate int 477*0Sstevel@tonic-gate _validate(FORM *f) 478*0Sstevel@tonic-gate { 479*0Sstevel@tonic-gate FIELD * c = C(f); 480*0Sstevel@tonic-gate 481*0Sstevel@tonic-gate _sync_buffer(f); 482*0Sstevel@tonic-gate 483*0Sstevel@tonic-gate if (Status(f, BUF_CHG) || !Opt(c, O_PASSOK)) { 484*0Sstevel@tonic-gate if (CheckField(c)) { 485*0Sstevel@tonic-gate Clr(f, BUF_CHG); 486*0Sstevel@tonic-gate Set(c, USR_CHG); 487*0Sstevel@tonic-gate (void) _sync_linked(c); 488*0Sstevel@tonic-gate } else 489*0Sstevel@tonic-gate return (FALSE); 490*0Sstevel@tonic-gate } 491*0Sstevel@tonic-gate return (TRUE); 492*0Sstevel@tonic-gate } 493*0Sstevel@tonic-gate 494*0Sstevel@tonic-gate /* 495*0Sstevel@tonic-gate * _set_current_field - change current field on form f to given field. 496*0Sstevel@tonic-gate * POSTED flag is set unless this is called from post_form(). 497*0Sstevel@tonic-gate */ 498*0Sstevel@tonic-gate int 499*0Sstevel@tonic-gate _set_current_field(FORM *f, FIELD *field) 500*0Sstevel@tonic-gate { 501*0Sstevel@tonic-gate WINDOW * w = W(f); 502*0Sstevel@tonic-gate FIELD * c = C(f); 503*0Sstevel@tonic-gate 504*0Sstevel@tonic-gate if (c != field || ! Status(f, POSTED)) { 505*0Sstevel@tonic-gate if (w) { 506*0Sstevel@tonic-gate if (Visible(c)) { 507*0Sstevel@tonic-gate (void) _update_current(f); 508*0Sstevel@tonic-gate 509*0Sstevel@tonic-gate if (Opt(c, O_PUBLIC)) { 510*0Sstevel@tonic-gate if (Scrollable(c)) { 511*0Sstevel@tonic-gate if (T(f) == 0) 512*0Sstevel@tonic-gate Clr(c, TOP_CHG); 513*0Sstevel@tonic-gate else 514*0Sstevel@tonic-gate Set(c, TOP_CHG); 515*0Sstevel@tonic-gate } else if (Justified(c)) { 516*0Sstevel@tonic-gate (void) werase(w); 517*0Sstevel@tonic-gate justify(c, w); 518*0Sstevel@tonic-gate wsyncup(w); 519*0Sstevel@tonic-gate } 520*0Sstevel@tonic-gate } 521*0Sstevel@tonic-gate } 522*0Sstevel@tonic-gate (void) delwin(w); 523*0Sstevel@tonic-gate } 524*0Sstevel@tonic-gate c = field; 525*0Sstevel@tonic-gate 526*0Sstevel@tonic-gate if (!Opt(c, O_PUBLIC) || Scrollable(c)) 527*0Sstevel@tonic-gate w = newwin(c -> drows, c -> dcols, 0, 0); 528*0Sstevel@tonic-gate else 529*0Sstevel@tonic-gate w = derwin(Sub(f), c -> rows, c -> cols, c -> frow, 530*0Sstevel@tonic-gate c -> fcol); 531*0Sstevel@tonic-gate 532*0Sstevel@tonic-gate if (!w) 533*0Sstevel@tonic-gate return (E_SYSTEM_ERROR); 534*0Sstevel@tonic-gate 535*0Sstevel@tonic-gate C(f) = c; 536*0Sstevel@tonic-gate W(f) = w; 537*0Sstevel@tonic-gate wbkgdset(w, Pad(c) | Back(c)); 538*0Sstevel@tonic-gate (void) wattrset(w, Fore(c)); 539*0Sstevel@tonic-gate 540*0Sstevel@tonic-gate if (!Opt(c, O_PUBLIC) || Scrollable(c)) { 541*0Sstevel@tonic-gate (void) werase(w); 542*0Sstevel@tonic-gate _buf_to_win(c, w); 543*0Sstevel@tonic-gate } else if (Justified(c)) { 544*0Sstevel@tonic-gate (void) werase(w); 545*0Sstevel@tonic-gate unjustify(c, w); 546*0Sstevel@tonic-gate wsyncup(w); 547*0Sstevel@tonic-gate } 548*0Sstevel@tonic-gate (void) untouchwin(w); 549*0Sstevel@tonic-gate Clr(f, WIN_CHG | BUF_CHG); 550*0Sstevel@tonic-gate } 551*0Sstevel@tonic-gate Y(f) = 0; 552*0Sstevel@tonic-gate X(f) = 0; 553*0Sstevel@tonic-gate T(f) = 0; 554*0Sstevel@tonic-gate B(f) = 0; 555*0Sstevel@tonic-gate return (E_OK); 556*0Sstevel@tonic-gate } 557*0Sstevel@tonic-gate 558*0Sstevel@tonic-gate /* 559*0Sstevel@tonic-gate * _set_form_page - display given page and set current field to c. 560*0Sstevel@tonic-gate * if c is null, then set current field to first field on page. 561*0Sstevel@tonic-gate * POSTED flag is set unless this is called from post_form(). 562*0Sstevel@tonic-gate */ 563*0Sstevel@tonic-gate int 564*0Sstevel@tonic-gate _set_form_page(FORM *f, int page, FIELD *c) 565*0Sstevel@tonic-gate { 566*0Sstevel@tonic-gate if (P(f) != page || ! Status(f, POSTED)) { 567*0Sstevel@tonic-gate FIELD * x = f -> field [Smin(f, page)]; 568*0Sstevel@tonic-gate FIELD * p = x; 569*0Sstevel@tonic-gate 570*0Sstevel@tonic-gate (void) werase(Sub(f)); 571*0Sstevel@tonic-gate P(f) = page; 572*0Sstevel@tonic-gate 573*0Sstevel@tonic-gate do { 574*0Sstevel@tonic-gate if (Opt(p, O_VISIBLE)) 575*0Sstevel@tonic-gate if (!display_field(p)) 576*0Sstevel@tonic-gate return (E_SYSTEM_ERROR); 577*0Sstevel@tonic-gate p = p -> snext; 578*0Sstevel@tonic-gate 579*0Sstevel@tonic-gate } while (p != x); 580*0Sstevel@tonic-gate 581*0Sstevel@tonic-gate return (c ? _set_current_field(f, c) : _first_field(f)); 582*0Sstevel@tonic-gate } 583*0Sstevel@tonic-gate return (E_OK); 584*0Sstevel@tonic-gate } 585