X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=form%2Ffrm_def.c;h=88964fc8f774e94364269b53cafc632575333b4b;hp=d15237e911e221c7baf3128ce8022a1f096a1a48;hb=f5da57ad7eb397b1001e2fca9cb0e278a6564716;hpb=027ae42953e3186daed8f3882da73de48291b606 diff --git a/form/frm_def.c b/form/frm_def.c index d15237e9..88964fc8 100644 --- a/form/frm_def.c +++ b/form/frm_def.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * + * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -32,7 +32,7 @@ #include "form.priv.h" -MODULE_ID("$Id: frm_def.c,v 1.20 2006/11/04 16:57:15 tom Exp $") +MODULE_ID("$Id: frm_def.c,v 1.24 2009/11/07 16:59:03 tom Exp $") /* this can't be readonly */ static FORM default_form = @@ -186,8 +186,9 @@ Connect_Fields(FORM *form, FIELD **fields) RETURN(E_BAD_ARGUMENT); /* allocate page structures */ - if ((pg = (_PAGE *) malloc(page_nr * sizeof(_PAGE))) != (_PAGE *) 0) + if ((pg = typeMalloc(_PAGE, page_nr)) != (_PAGE *) 0) { + T((T_CREATE("_PAGE %p"), pg)); form->page = pg; } else @@ -233,8 +234,16 @@ Connect_Fields(FORM *form, FIELD **fields) fields[j]->page = page_nr; fld = Insert_Field_By_Position(fields[j], fld); } - form->page[page_nr].smin = fld->index; - form->page[page_nr].smax = fld->sprev->index; + if (fld) + { + form->page[page_nr].smin = fld->index; + form->page[page_nr].smax = fld->sprev->index; + } + else + { + form->page[page_nr].smin = 0; + form->page[page_nr].smax = 0; + } } RETURN(E_OK); } @@ -274,7 +283,7 @@ Associate_Fields(FORM *form, FIELD **fields) /*--------------------------------------------------------------------------- | Facility : libnform -| Function : FORM *new_form( FIELD **fields ) +| Function : FORM *new_form_sp(SCREEN* sp, FIELD** fields ) | | Description : Create new form with given array of fields. | @@ -286,20 +295,31 @@ Associate_Fields(FORM *form, FIELD **fields) | E_SYSTEM_ERROR - not enough memory +--------------------------------------------------------------------------*/ NCURSES_EXPORT(FORM *) -new_form(FIELD **fields) +NCURSES_SP_NAME(new_form) (NCURSES_SP_DCLx FIELD **fields) { int err = E_SYSTEM_ERROR; + FORM *form = (FORM *)0; - FORM *form = (FORM *)malloc(sizeof(FORM)); + T((T_CALLED("new_form(%p,%p)"), SP_PARM, fields)); - T((T_CALLED("new_form(%p)"), fields)); - if (form) + if (IsValidScreen(SP_PARM)) { - *form = *_nc_Default_Form; - if ((err = Associate_Fields(form, fields)) != E_OK) + form = typeMalloc(FORM, 1); + + if (form) { - free_form(form); - form = (FORM *)0; + T((T_CREATE("form %p"), form)); + *form = *_nc_Default_Form; + /* This ensures win and sub are always non-null, + so we can derive always the SCREEN that this form is + running on. */ + form->win = StdScreen(SP_PARM); + form->sub = StdScreen(SP_PARM); + if ((err = Associate_Fields(form, fields)) != E_OK) + { + free_form(form); + form = (FORM *)0; + } } } @@ -309,6 +329,27 @@ new_form(FIELD **fields) returnForm(form); } +/*--------------------------------------------------------------------------- +| Facility : libnform +| Function : FORM* new_form(FIELD** fields ) +| +| Description : Create new form with given array of fields. +| +| Return Values : Pointer to form. NULL if error occurred. +! Set errno: +| E_OK - success +| E_BAD_ARGUMENT - Invalid form pointer or field array +| E_CONNECTED - a field is already connected +| E_SYSTEM_ERROR - not enough memory ++--------------------------------------------------------------------------*/ +#if NCURSES_SP_FUNCS +NCURSES_EXPORT(FORM *) +new_form(FIELD **fields) +{ + return NCURSES_SP_NAME(new_form) (CURRENT_SCREEN, fields); +} +#endif + /*--------------------------------------------------------------------------- | Facility : libnform | Function : int free_form( FORM *form )