1 /* $OpenBSD: frm_post.c,v 1.7 2023/10/17 09:52:10 nicm Exp $ */ 2 /**************************************************************************** 3 * Copyright 2020 Thomas E. Dickey * 4 * Copyright 1998-2010,2012 Free Software Foundation, Inc. * 5 * * 6 * Permission is hereby granted, free of charge, to any person obtaining a * 7 * copy of this software and associated documentation files (the * 8 * "Software"), to deal in the Software without restriction, including * 9 * without limitation the rights to use, copy, modify, merge, publish, * 10 * distribute, distribute with modifications, sublicense, and/or sell * 11 * copies of the Software, and to permit persons to whom the Software is * 12 * furnished to do so, subject to the following conditions: * 13 * * 14 * The above copyright notice and this permission notice shall be included * 15 * in all copies or substantial portions of the Software. * 16 * * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 24 * * 25 * Except as contained in this notice, the name(s) of the above copyright * 26 * holders shall not be used in advertising or otherwise to promote the * 27 * sale, use or other dealings in this Software without prior written * 28 * authorization. * 29 ****************************************************************************/ 30 31 /**************************************************************************** 32 * Author: Juergen Pfeifer, 1995,1997 * 33 ****************************************************************************/ 34 35 #include "form.priv.h" 36 37 MODULE_ID("$Id: frm_post.c,v 1.7 2023/10/17 09:52:10 nicm Exp $") 38 39 /*--------------------------------------------------------------------------- 40 | Facility : libnform 41 | Function : int post_form(FORM * form) 42 | 43 | Description : Writes the form into its associated subwindow. 44 | 45 | Return Values : E_OK - success 46 | E_BAD_ARGUMENT - invalid form pointer 47 | E_POSTED - form already posted 48 | E_NOT_CONNECTED - no fields connected to form 49 | E_NO_ROOM - form doesn't fit into subwindow 50 | E_SYSTEM_ERROR - system error 51 +--------------------------------------------------------------------------*/ 52 FORM_EXPORT(int) 53 post_form(FORM *form) 54 { 55 WINDOW *formwin; 56 int err; 57 int page; 58 59 T((T_CALLED("post_form(%p)"), (void *)form)); 60 61 if (!form) 62 RETURN(E_BAD_ARGUMENT); 63 64 if (form->status & _POSTED) 65 RETURN(E_POSTED); 66 67 if (!(form->field)) 68 RETURN(E_NOT_CONNECTED); 69 70 formwin = Get_Form_Window(form); 71 if ((form->cols > getmaxx(formwin)) || (form->rows > getmaxy(formwin))) 72 RETURN(E_NO_ROOM); 73 74 /* reset form->curpage to an invalid value. This forces Set_Form_Page 75 to do the page initialization which is required by post_form. 76 */ 77 page = form->curpage; 78 form->curpage = -1; 79 if ((err = _nc_Set_Form_Page(form, page, form->current)) != E_OK) 80 RETURN(err); 81 82 SetStatus(form, _POSTED); 83 84 Call_Hook(form, forminit); 85 Call_Hook(form, fieldinit); 86 87 _nc_Refresh_Current_Field(form); 88 RETURN(E_OK); 89 } 90 91 /*--------------------------------------------------------------------------- 92 | Facility : libnform 93 | Function : int unpost_form(FORM * form) 94 | 95 | Description : Erase form from its associated subwindow. 96 | 97 | Return Values : E_OK - success 98 | E_BAD_ARGUMENT - invalid form pointer 99 | E_NOT_POSTED - form isn't posted 100 | E_BAD_STATE - called from a hook routine 101 +--------------------------------------------------------------------------*/ 102 FORM_EXPORT(int) 103 unpost_form(FORM *form) 104 { 105 T((T_CALLED("unpost_form(%p)"), (void *)form)); 106 107 if (!form) 108 RETURN(E_BAD_ARGUMENT); 109 110 if (!(form->status & _POSTED)) 111 RETURN(E_NOT_POSTED); 112 113 if (form->status & _IN_DRIVER) 114 RETURN(E_BAD_STATE); 115 116 Call_Hook(form, fieldterm); 117 Call_Hook(form, formterm); 118 119 werase(Get_Form_Window(form)); 120 delwin(form->w); 121 form->w = (WINDOW *)0; 122 ClrStatus(form, _POSTED); 123 RETURN(E_OK); 124 } 125 126 /* frm_post.c ends here */ 127