post.c revision 1.2
1/* $NetBSD: post.c,v 1.2 2001/01/04 12:30:37 blymn Exp $ */ 2 3/*- 4 * Copyright (c) 1998-2000 Brett Lymn 5 * (blymn@baea.com.au, brett_lymn@yahoo.com.au) 6 * All rights reserved. 7 * 8 * This code has been donated to The NetBSD Foundation by the Author. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. The name of the author may not be used to endorse or promote products 16 * derived from this software withough specific prior written permission 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 * 30 */ 31 32#include "form.h" 33#include "internals.h" 34 35/* 36 * Post the form to the screen. 37 */ 38int 39post_form(FORM *form) 40{ 41 int rows, cols, status; 42 43 if ((form == NULL) || (form->win == NULL)) 44 return E_BAD_ARGUMENT; 45 46 if (form->posted == 1) 47 return E_POSTED; 48 49 if ((form->fields == NULL) || (form->fields[0] == NULL)) 50 return E_NOT_CONNECTED; 51 52 if (form->in_init == 1) 53 return E_BAD_STATE; 54 55 if (scale_form(form, &rows, &cols) != E_OK) 56 return E_SYSTEM_ERROR; 57 58 if ((form->subwin != NULL) && ((rows > getmaxy(form->subwin)) 59 || (cols > getmaxx(form->subwin)))) { 60 return E_NO_ROOM; 61 } 62 63 if (form->subwin == NULL) { 64 form->subwin_created = 1; 65 form->subwin = derwin(form->win, rows, cols, 0, 0); 66 if (form->subwin == NULL) 67 return E_SYSTEM_ERROR; 68 69 } 70 71#ifdef DEBUG 72 if (dbg == NULL) { 73 dbg = fopen("___form_dbg.out", "w"); 74 if (dbg == NULL) { 75 fprintf(stderr, "Cannot open debug file!\n"); 76 return E_SYSTEM_ERROR; 77 } 78 } 79#endif 80 81 form->in_init = 1; 82 if (form->form_init != NULL) 83 form->form_init(form); 84 85 if (form->field_init != NULL) 86 form->field_init(form); 87 form->in_init = 0; 88 89 if ((status = _formi_draw_page(form)) != E_OK) 90 return status; 91 92 form->posted = 1; 93 return E_OK; 94} 95 96/* 97 * Unpost the form from the screen 98 */ 99int 100unpost_form(FORM *form) 101{ 102 103 if (form == NULL) 104 return E_BAD_ARGUMENT; 105 106 if (form->posted != 1) 107 return E_NOT_POSTED; 108 109 if (form->in_init == 1) 110 return E_BAD_STATE; 111 112 form->in_init = 1; 113 if (form->field_term != NULL) 114 form->field_term(form); 115 116 if (form->form_term != NULL) 117 form->form_term(form); 118 form->in_init = 0; 119 120 wclear(form->subwin); 121 if (form->subwin_created == 1) { 122 delwin(form->subwin); 123 form->subwin_created = 0; 124 } 125 126 form->posted = 0; 127 128 return E_OK; 129} 130 131