1 /* $OpenBSD: fld_current.c,v 1.4 2001/01/22 18:02:11 millert Exp $ */ 2 3 /**************************************************************************** 4 * Copyright (c) 1998,2000 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 <juergen.pfeifer@gmx.net> 1995,1997 * 33 ****************************************************************************/ 34 #include "form.priv.h" 35 36 MODULE_ID("$From: fld_current.c,v 1.5 2000/12/10 02:09:38 tom Exp $") 37 38 /*--------------------------------------------------------------------------- 39 | Facility : libnform 40 | Function : int set_current_field(FORM * form,FIELD * field) 41 | 42 | Description : Set the current field of the form to the specified one. 43 | 44 | Return Values : E_OK - success 45 | E_BAD_ARGUMENT - invalid form or field pointer 46 | E_REQUEST_DENIED - field not selectable 47 | E_BAD_STATE - called from a hook routine 48 | E_INVALID_FIELD - current field can't be left 49 | E_SYSTEM_ERROR - system error 50 +--------------------------------------------------------------------------*/ 51 NCURSES_EXPORT(int) 52 set_current_field (FORM * form, FIELD * field) 53 { 54 int err = E_OK; 55 56 if ( !form || !field ) 57 RETURN(E_BAD_ARGUMENT); 58 59 if ( (form != field->form) || Field_Is_Not_Selectable(field) ) 60 RETURN(E_REQUEST_DENIED); 61 62 if (!(form->status & _POSTED)) 63 { 64 form->current = field; 65 form->curpage = field->page; 66 } 67 else 68 { 69 if (form->status & _IN_DRIVER) 70 err = E_BAD_STATE; 71 else 72 { 73 if (form->current != field) 74 { 75 if (!_nc_Internal_Validation(form)) 76 err = E_INVALID_FIELD; 77 else 78 { 79 Call_Hook(form,fieldterm); 80 if (field->page != form->curpage) 81 { 82 Call_Hook(form,formterm); 83 err = _nc_Set_Form_Page(form,field->page,field); 84 Call_Hook(form,forminit); 85 } 86 else 87 { 88 err = _nc_Set_Current_Field(form,field); 89 } 90 Call_Hook(form,fieldinit); 91 _nc_Refresh_Current_Field(form); 92 } 93 } 94 } 95 } 96 RETURN(err); 97 } 98 99 /*--------------------------------------------------------------------------- 100 | Facility : libnform 101 | Function : FIELD *current_field(const FORM * form) 102 | 103 | Description : Return the current field. 104 | 105 | Return Values : Pointer to the current field. 106 +--------------------------------------------------------------------------*/ 107 NCURSES_EXPORT(FIELD *) 108 current_field (const FORM * form) 109 { 110 return Normalize_Form(form)->current; 111 } 112 113 /*--------------------------------------------------------------------------- 114 | Facility : libnform 115 | Function : int field_index(const FIELD * field) 116 | 117 | Description : Return the index of the field in the field-array of 118 | the form. 119 | 120 | Return Values : >= 0 : field index 121 | -1 : fieldpointer invalid or field not connected 122 +--------------------------------------------------------------------------*/ 123 NCURSES_EXPORT(int) 124 field_index (const FIELD * field) 125 { 126 return ( (field && field->form) ? field->index : -1 ); 127 } 128 129 /* fld_current.c ends here */ 130