xref: /openbsd/lib/libform/frm_page.c (revision 02f2426a)
1*02f2426aSmillert /*	$OpenBSD: frm_page.c,v 1.2 1998/07/24 02:37:33 millert Exp $	*/
28d0fca71Smillert 
3*02f2426aSmillert /****************************************************************************
4*02f2426aSmillert  * Copyright (c) 1998 Free Software Foundation, Inc.                        *
5*02f2426aSmillert  *                                                                          *
6*02f2426aSmillert  * Permission is hereby granted, free of charge, to any person obtaining a  *
7*02f2426aSmillert  * copy of this software and associated documentation files (the            *
8*02f2426aSmillert  * "Software"), to deal in the Software without restriction, including      *
9*02f2426aSmillert  * without limitation the rights to use, copy, modify, merge, publish,      *
10*02f2426aSmillert  * distribute, distribute with modifications, sublicense, and/or sell       *
11*02f2426aSmillert  * copies of the Software, and to permit persons to whom the Software is    *
12*02f2426aSmillert  * furnished to do so, subject to the following conditions:                 *
13*02f2426aSmillert  *                                                                          *
14*02f2426aSmillert  * The above copyright notice and this permission notice shall be included  *
15*02f2426aSmillert  * in all copies or substantial portions of the Software.                   *
16*02f2426aSmillert  *                                                                          *
17*02f2426aSmillert  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18*02f2426aSmillert  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19*02f2426aSmillert  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20*02f2426aSmillert  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21*02f2426aSmillert  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22*02f2426aSmillert  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23*02f2426aSmillert  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24*02f2426aSmillert  *                                                                          *
25*02f2426aSmillert  * Except as contained in this notice, the name(s) of the above copyright   *
26*02f2426aSmillert  * holders shall not be used in advertising or otherwise to promote the     *
27*02f2426aSmillert  * sale, use or other dealings in this Software without prior written       *
28*02f2426aSmillert  * authorization.                                                           *
29*02f2426aSmillert  ****************************************************************************/
30*02f2426aSmillert 
31*02f2426aSmillert /****************************************************************************
32*02f2426aSmillert  *   Author: Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> 1995,1997        *
33*02f2426aSmillert  ****************************************************************************/
348d0fca71Smillert 
358d0fca71Smillert #include "form.priv.h"
368d0fca71Smillert 
37*02f2426aSmillert MODULE_ID("$From: frm_page.c,v 1.3 1998/02/11 12:13:44 tom Exp $")
388d0fca71Smillert 
398d0fca71Smillert /*---------------------------------------------------------------------------
408d0fca71Smillert |   Facility      :  libnform
418d0fca71Smillert |   Function      :  int set_form_page(FORM * form,int  page)
428d0fca71Smillert |
438d0fca71Smillert |   Description   :  Set the page number of the form.
448d0fca71Smillert |
458d0fca71Smillert |   Return Values :  E_OK              - success
468d0fca71Smillert |                    E_BAD_ARGUMENT    - invalid form pointer or page number
478d0fca71Smillert |                    E_BAD_STATE       - called from a hook routine
488d0fca71Smillert |                    E_INVALID_FIELD   - current field can't be left
498d0fca71Smillert |                    E_SYSTEM_ERROR    - system error
508d0fca71Smillert +--------------------------------------------------------------------------*/
518d0fca71Smillert int set_form_page(FORM * form, int page)
528d0fca71Smillert {
538d0fca71Smillert   int err = E_OK;
548d0fca71Smillert 
558d0fca71Smillert   if ( !form || (page<0) || (page>=form->maxpage) )
568d0fca71Smillert     RETURN(E_BAD_ARGUMENT);
578d0fca71Smillert 
588d0fca71Smillert   if (!(form->status & _POSTED))
598d0fca71Smillert     {
608d0fca71Smillert       form->curpage = page;
618d0fca71Smillert       form->current = _nc_First_Active_Field(form);
628d0fca71Smillert   }
638d0fca71Smillert   else
648d0fca71Smillert     {
658d0fca71Smillert       if (form->status & _IN_DRIVER)
668d0fca71Smillert 	err = E_BAD_STATE;
678d0fca71Smillert       else
688d0fca71Smillert 	{
698d0fca71Smillert 	  if (form->curpage != page)
708d0fca71Smillert 	    {
718d0fca71Smillert 	      if (!_nc_Internal_Validation(form))
728d0fca71Smillert 		err = E_INVALID_FIELD;
738d0fca71Smillert 	      else
748d0fca71Smillert 		{
758d0fca71Smillert 		  Call_Hook(form,fieldterm);
768d0fca71Smillert 		  Call_Hook(form,formterm);
778d0fca71Smillert 		  err = _nc_Set_Form_Page(form,page,(FIELD *)0);
788d0fca71Smillert 		  Call_Hook(form,forminit);
798d0fca71Smillert 		  Call_Hook(form,fieldinit);
808d0fca71Smillert 		  _nc_Refresh_Current_Field(form);
818d0fca71Smillert 		}
828d0fca71Smillert 	    }
838d0fca71Smillert 	}
848d0fca71Smillert     }
858d0fca71Smillert   RETURN(err);
868d0fca71Smillert }
878d0fca71Smillert 
888d0fca71Smillert /*---------------------------------------------------------------------------
898d0fca71Smillert |   Facility      :  libnform
908d0fca71Smillert |   Function      :  int form_page(const FORM * form)
918d0fca71Smillert |
928d0fca71Smillert |   Description   :  Return the current page of the form.
938d0fca71Smillert |
948d0fca71Smillert |   Return Values :  >= 0  : current page number
958d0fca71Smillert |                    -1    : invalid form pointer
968d0fca71Smillert +--------------------------------------------------------------------------*/
978d0fca71Smillert int form_page(const FORM * form)
988d0fca71Smillert {
998d0fca71Smillert   return Normalize_Form(form)->curpage;
1008d0fca71Smillert }
1018d0fca71Smillert 
1028d0fca71Smillert /* frm_page.c ends here */
103