ncurses 5.7 - patch 20100123
[ncurses.git] / form / frm_def.c
index c2044a39dccd153e579825150c1e5e90fa502bcb..86500f239863f125c81c5178ac3c0896fd3d86ac 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2010 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            *
  *                                                                          *
  * 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"
 
 
 #include "form.priv.h"
 
-MODULE_ID("$Id: frm_def.c,v 1.22 2007/10/13 19:31:17 tom Exp $")
+MODULE_ID("$Id: frm_def.c,v 1.25 2010/01/23 21:14:36 tom Exp $")
 
 /* this can't be readonly */
 static FORM default_form =
 
 /* this can't be readonly */
 static FORM default_form =
@@ -160,7 +160,7 @@ Connect_Fields(FORM *form, FIELD **fields)
   int maximum_row_in_field, maximum_col_in_field;
   _PAGE *pg;
 
   int maximum_row_in_field, maximum_col_in_field;
   _PAGE *pg;
 
-  T((T_CALLED("Connect_Fields(%p,%p)"), form, fields));
+  T((T_CALLED("Connect_Fields(%p,%p)"), (void *)form, (void *)fields));
 
   assert(form);
 
 
   assert(form);
 
@@ -188,7 +188,7 @@ Connect_Fields(FORM *form, FIELD **fields)
   /* allocate page structures */
   if ((pg = typeMalloc(_PAGE, page_nr)) != (_PAGE *) 0)
     {
   /* allocate page structures */
   if ((pg = typeMalloc(_PAGE, page_nr)) != (_PAGE *) 0)
     {
-      T((T_CREATE("_PAGE %p"), pg));
+      T((T_CREATE("_PAGE %p"), (void *)pg));
       form->page = pg;
     }
   else
       form->page = pg;
     }
   else
@@ -234,8 +234,16 @@ Connect_Fields(FORM *form, FIELD **fields)
          fields[j]->page = page_nr;
          fld = Insert_Field_By_Position(fields[j], fld);
        }
          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);
 }
     }
   RETURN(E_OK);
 }
@@ -275,7 +283,7 @@ Associate_Fields(FORM *form, FIELD **fields)
 
 /*---------------------------------------------------------------------------
 |   Facility      :  libnform  
 
 /*---------------------------------------------------------------------------
 |   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.
 |
 |   
 |   Description   :  Create new form with given array of fields.
 |
@@ -287,21 +295,31 @@ Associate_Fields(FORM *form, FIELD **fields)
 |                    E_SYSTEM_ERROR  - not enough memory
 +--------------------------------------------------------------------------*/
 NCURSES_EXPORT(FORM *)
 |                    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;
 {
   int err = E_SYSTEM_ERROR;
+  FORM *form = (FORM *)0;
 
 
-  FORM *form = typeMalloc(FORM, 1);
+  T((T_CALLED("new_form(%p,%p)"), (void *)SP_PARM, (void *)fields));
 
 
-  T((T_CALLED("new_form(%p)"), fields));
-  if (form)
+  if (IsValidScreen(SP_PARM))
     {
     {
-      T((T_CREATE("form %p"), form));
-      *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"), (void *)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;
+           }
        }
     }
 
        }
     }
 
@@ -311,6 +329,27 @@ new_form(FIELD **fields)
   returnForm(form);
 }
 
   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 )
 /*---------------------------------------------------------------------------
 |   Facility      :  libnform  
 |   Function      :  int free_form( FORM *form )
@@ -324,7 +363,7 @@ new_form(FIELD **fields)
 NCURSES_EXPORT(int)
 free_form(FORM *form)
 {
 NCURSES_EXPORT(int)
 free_form(FORM *form)
 {
-  T((T_CALLED("free_form(%p)"), form));
+  T((T_CALLED("free_form(%p)"), (void *)form));
 
   if (!form)
     RETURN(E_BAD_ARGUMENT);
 
   if (!form)
     RETURN(E_BAD_ARGUMENT);
@@ -358,7 +397,7 @@ set_form_fields(FORM *form, FIELD **fields)
   FIELD **old;
   int res;
 
   FIELD **old;
   int res;
 
-  T((T_CALLED("set_form_fields(%p,%p)"), form, fields));
+  T((T_CALLED("set_form_fields(%p,%p)"), (void *)form, (void *)fields));
 
   if (!form)
     RETURN(E_BAD_ARGUMENT);
 
   if (!form)
     RETURN(E_BAD_ARGUMENT);
@@ -386,7 +425,7 @@ set_form_fields(FORM *form, FIELD **fields)
 NCURSES_EXPORT(FIELD **)
 form_fields(const FORM *form)
 {
 NCURSES_EXPORT(FIELD **)
 form_fields(const FORM *form)
 {
-  T((T_CALLED("form_field(%p)"), form));
+  T((T_CALLED("form_field(%p)"), (const void *)form));
   returnFieldPtr(Normalize_Form(form)->field);
 }
 
   returnFieldPtr(Normalize_Form(form)->field);
 }
 
@@ -401,7 +440,7 @@ form_fields(const FORM *form)
 NCURSES_EXPORT(int)
 field_count(const FORM *form)
 {
 NCURSES_EXPORT(int)
 field_count(const FORM *form)
 {
-  T((T_CALLED("field_count(%p)"), form));
+  T((T_CALLED("field_count(%p)"), (const void *)form));
 
   returnCode(Normalize_Form(form)->maxfield);
 }
 
   returnCode(Normalize_Form(form)->maxfield);
 }