1*c7ef0cfcSnicm /* $OpenBSD: frm_page.c,v 1.7 2023/10/17 09:52:10 nicm Exp $ */
202f2426aSmillert /****************************************************************************
3*c7ef0cfcSnicm * Copyright 2020,2021 Thomas E. Dickey *
4*c7ef0cfcSnicm * Copyright 1998-2010,2012 Free Software Foundation, Inc. *
502f2426aSmillert * *
602f2426aSmillert * Permission is hereby granted, free of charge, to any person obtaining a *
702f2426aSmillert * copy of this software and associated documentation files (the *
802f2426aSmillert * "Software"), to deal in the Software without restriction, including *
902f2426aSmillert * without limitation the rights to use, copy, modify, merge, publish, *
1002f2426aSmillert * distribute, distribute with modifications, sublicense, and/or sell *
1102f2426aSmillert * copies of the Software, and to permit persons to whom the Software is *
1202f2426aSmillert * furnished to do so, subject to the following conditions: *
1302f2426aSmillert * *
1402f2426aSmillert * The above copyright notice and this permission notice shall be included *
1502f2426aSmillert * in all copies or substantial portions of the Software. *
1602f2426aSmillert * *
1702f2426aSmillert * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
1802f2426aSmillert * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
1902f2426aSmillert * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
2002f2426aSmillert * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
2102f2426aSmillert * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
2202f2426aSmillert * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
2302f2426aSmillert * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
2402f2426aSmillert * *
2502f2426aSmillert * Except as contained in this notice, the name(s) of the above copyright *
2602f2426aSmillert * holders shall not be used in advertising or otherwise to promote the *
2702f2426aSmillert * sale, use or other dealings in this Software without prior written *
2802f2426aSmillert * authorization. *
2902f2426aSmillert ****************************************************************************/
3002f2426aSmillert
3102f2426aSmillert /****************************************************************************
3281d8c4e1Snicm * Author: Juergen Pfeifer, 1995,1997 *
3302f2426aSmillert ****************************************************************************/
348d0fca71Smillert
358d0fca71Smillert #include "form.priv.h"
368d0fca71Smillert
37*c7ef0cfcSnicm MODULE_ID("$Id: frm_page.c,v 1.7 2023/10/17 09:52:10 nicm 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 +--------------------------------------------------------------------------*/
FORM_EXPORT(int)51*c7ef0cfcSnicm FORM_EXPORT(int)
5284af20ceSmillert set_form_page(FORM *form, int page)
538d0fca71Smillert {
548d0fca71Smillert int err = E_OK;
558d0fca71Smillert
56*c7ef0cfcSnicm T((T_CALLED("set_form_page(%p,%d)"), (void *)form, page));
5781d8c4e1Snicm
588d0fca71Smillert if (!form || (page < 0) || (page >= form->maxpage))
598d0fca71Smillert RETURN(E_BAD_ARGUMENT);
608d0fca71Smillert
618d0fca71Smillert if (!(form->status & _POSTED))
628d0fca71Smillert {
63*c7ef0cfcSnicm form->curpage = (short)page;
648d0fca71Smillert form->current = _nc_First_Active_Field(form);
658d0fca71Smillert }
668d0fca71Smillert else
678d0fca71Smillert {
688d0fca71Smillert if (form->status & _IN_DRIVER)
698d0fca71Smillert err = E_BAD_STATE;
708d0fca71Smillert else
718d0fca71Smillert {
728d0fca71Smillert if (form->curpage != page)
738d0fca71Smillert {
748d0fca71Smillert if (!_nc_Internal_Validation(form))
758d0fca71Smillert err = E_INVALID_FIELD;
768d0fca71Smillert else
778d0fca71Smillert {
788d0fca71Smillert Call_Hook(form, fieldterm);
798d0fca71Smillert Call_Hook(form, formterm);
808d0fca71Smillert err = _nc_Set_Form_Page(form, page, (FIELD *)0);
818d0fca71Smillert Call_Hook(form, forminit);
828d0fca71Smillert Call_Hook(form, fieldinit);
838d0fca71Smillert _nc_Refresh_Current_Field(form);
848d0fca71Smillert }
858d0fca71Smillert }
868d0fca71Smillert }
878d0fca71Smillert }
888d0fca71Smillert RETURN(err);
898d0fca71Smillert }
908d0fca71Smillert
918d0fca71Smillert /*---------------------------------------------------------------------------
928d0fca71Smillert | Facility : libnform
938d0fca71Smillert | Function : int form_page(const FORM * form)
948d0fca71Smillert |
958d0fca71Smillert | Description : Return the current page of the form.
968d0fca71Smillert |
978d0fca71Smillert | Return Values : >= 0 : current page number
988d0fca71Smillert | -1 : invalid form pointer
998d0fca71Smillert +--------------------------------------------------------------------------*/
100*c7ef0cfcSnicm FORM_EXPORT(int)
form_page(const FORM * form)10184af20ceSmillert form_page(const FORM *form)
1028d0fca71Smillert {
103*c7ef0cfcSnicm T((T_CALLED("form_page(%p)"), (const void *)form));
10481d8c4e1Snicm
10581d8c4e1Snicm returnCode(Normalize_Form(form)->curpage);
1068d0fca71Smillert }
1078d0fca71Smillert
1088d0fca71Smillert /* frm_page.c ends here */
109