xref: /freebsd/contrib/ncurses/form/frm_page.c (revision 21817992b3314c908ab50f0bb88d2ee750b9c4ac)
10e3d5408SPeter Wemm /****************************************************************************
2*21817992SBaptiste Daroussin  * Copyright 2020,2021 Thomas E. Dickey                                     *
3e1865124SBaptiste Daroussin  * Copyright 1998-2010,2012 Free Software Foundation, Inc.                  *
40e3d5408SPeter Wemm  *                                                                          *
50e3d5408SPeter Wemm  * Permission is hereby granted, free of charge, to any person obtaining a  *
60e3d5408SPeter Wemm  * copy of this software and associated documentation files (the            *
70e3d5408SPeter Wemm  * "Software"), to deal in the Software without restriction, including      *
80e3d5408SPeter Wemm  * without limitation the rights to use, copy, modify, merge, publish,      *
90e3d5408SPeter Wemm  * distribute, distribute with modifications, sublicense, and/or sell       *
100e3d5408SPeter Wemm  * copies of the Software, and to permit persons to whom the Software is    *
110e3d5408SPeter Wemm  * furnished to do so, subject to the following conditions:                 *
120e3d5408SPeter Wemm  *                                                                          *
130e3d5408SPeter Wemm  * The above copyright notice and this permission notice shall be included  *
140e3d5408SPeter Wemm  * in all copies or substantial portions of the Software.                   *
150e3d5408SPeter Wemm  *                                                                          *
160e3d5408SPeter Wemm  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
170e3d5408SPeter Wemm  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
180e3d5408SPeter Wemm  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
190e3d5408SPeter Wemm  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
200e3d5408SPeter Wemm  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
210e3d5408SPeter Wemm  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
220e3d5408SPeter Wemm  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
230e3d5408SPeter Wemm  *                                                                          *
240e3d5408SPeter Wemm  * Except as contained in this notice, the name(s) of the above copyright   *
250e3d5408SPeter Wemm  * holders shall not be used in advertising or otherwise to promote the     *
260e3d5408SPeter Wemm  * sale, use or other dealings in this Software without prior written       *
270e3d5408SPeter Wemm  * authorization.                                                           *
280e3d5408SPeter Wemm  ****************************************************************************/
290e3d5408SPeter Wemm 
300e3d5408SPeter Wemm /****************************************************************************
314a1a9510SRong-En Fan  *   Author:  Juergen Pfeifer, 1995,1997                                    *
320e3d5408SPeter Wemm  ****************************************************************************/
330e3d5408SPeter Wemm 
340e3d5408SPeter Wemm #include "form.priv.h"
350e3d5408SPeter Wemm 
36*21817992SBaptiste Daroussin MODULE_ID("$Id: frm_page.c,v 1.15 2021/06/17 21:20:30 tom Exp $")
370e3d5408SPeter Wemm 
380e3d5408SPeter Wemm /*---------------------------------------------------------------------------
390e3d5408SPeter Wemm |   Facility      :  libnform
400e3d5408SPeter Wemm |   Function      :  int set_form_page(FORM * form,int  page)
410e3d5408SPeter Wemm |
420e3d5408SPeter Wemm |   Description   :  Set the page number of the form.
430e3d5408SPeter Wemm |
440e3d5408SPeter Wemm |   Return Values :  E_OK              - success
450e3d5408SPeter Wemm |                    E_BAD_ARGUMENT    - invalid form pointer or page number
460e3d5408SPeter Wemm |                    E_BAD_STATE       - called from a hook routine
470e3d5408SPeter Wemm |                    E_INVALID_FIELD   - current field can't be left
480e3d5408SPeter Wemm |                    E_SYSTEM_ERROR    - system error
490e3d5408SPeter Wemm +--------------------------------------------------------------------------*/
FORM_EXPORT(int)507a656419SBaptiste Daroussin FORM_EXPORT(int)
517a69bbfbSPeter Wemm set_form_page(FORM *form, int page)
520e3d5408SPeter Wemm {
530e3d5408SPeter Wemm   int err = E_OK;
540e3d5408SPeter Wemm 
5506bfebdeSXin LI   T((T_CALLED("set_form_page(%p,%d)"), (void *)form, page));
564a1a9510SRong-En Fan 
570e3d5408SPeter Wemm   if (!form || (page < 0) || (page >= form->maxpage))
580e3d5408SPeter Wemm     RETURN(E_BAD_ARGUMENT);
590e3d5408SPeter Wemm 
600e3d5408SPeter Wemm   if (!(form->status & _POSTED))
610e3d5408SPeter Wemm     {
6273f0a83dSXin LI       form->curpage = (short)page;
630e3d5408SPeter Wemm       form->current = _nc_First_Active_Field(form);
640e3d5408SPeter Wemm     }
650e3d5408SPeter Wemm   else
660e3d5408SPeter Wemm     {
670e3d5408SPeter Wemm       if (form->status & _IN_DRIVER)
680e3d5408SPeter Wemm 	err = E_BAD_STATE;
690e3d5408SPeter Wemm       else
700e3d5408SPeter Wemm 	{
710e3d5408SPeter Wemm 	  if (form->curpage != page)
720e3d5408SPeter Wemm 	    {
730e3d5408SPeter Wemm 	      if (!_nc_Internal_Validation(form))
740e3d5408SPeter Wemm 		err = E_INVALID_FIELD;
750e3d5408SPeter Wemm 	      else
760e3d5408SPeter Wemm 		{
770e3d5408SPeter Wemm 		  Call_Hook(form, fieldterm);
780e3d5408SPeter Wemm 		  Call_Hook(form, formterm);
790e3d5408SPeter Wemm 		  err = _nc_Set_Form_Page(form, page, (FIELD *)0);
800e3d5408SPeter Wemm 		  Call_Hook(form, forminit);
810e3d5408SPeter Wemm 		  Call_Hook(form, fieldinit);
820e3d5408SPeter Wemm 		  _nc_Refresh_Current_Field(form);
830e3d5408SPeter Wemm 		}
840e3d5408SPeter Wemm 	    }
850e3d5408SPeter Wemm 	}
860e3d5408SPeter Wemm     }
870e3d5408SPeter Wemm   RETURN(err);
880e3d5408SPeter Wemm }
890e3d5408SPeter Wemm 
900e3d5408SPeter Wemm /*---------------------------------------------------------------------------
910e3d5408SPeter Wemm |   Facility      :  libnform
920e3d5408SPeter Wemm |   Function      :  int form_page(const FORM * form)
930e3d5408SPeter Wemm |
940e3d5408SPeter Wemm |   Description   :  Return the current page of the form.
950e3d5408SPeter Wemm |
960e3d5408SPeter Wemm |   Return Values :  >= 0  : current page number
970e3d5408SPeter Wemm |                    -1    : invalid form pointer
980e3d5408SPeter Wemm +--------------------------------------------------------------------------*/
997a656419SBaptiste Daroussin FORM_EXPORT(int)
form_page(const FORM * form)1007a69bbfbSPeter Wemm form_page(const FORM *form)
1010e3d5408SPeter Wemm {
10206bfebdeSXin LI   T((T_CALLED("form_page(%p)"), (const void *)form));
1034a1a9510SRong-En Fan 
1044a1a9510SRong-En Fan   returnCode(Normalize_Form(form)->curpage);
1050e3d5408SPeter Wemm }
1060e3d5408SPeter Wemm 
1070e3d5408SPeter Wemm /* frm_page.c ends here */
108