ncurses 5.6 - patch 20080913
[ncurses.git] / form / fld_current.c
index 2bf8163a43f7fea455e64776be0c4061f2e88cee..7c3a90af511d97a1c0fddacbf6236ad493183ca2 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc.                        *
+ * Copyright (c) 1998-2003,2004 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            *
  ****************************************************************************/
 
 /****************************************************************************
- *   Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1995,1997            *
+ *   Author:  Juergen Pfeifer, 1995,1997                                    *
  ****************************************************************************/
+
 #include "form.priv.h"
 
-MODULE_ID("$Id: fld_current.c,v 1.4 1999/05/16 17:16:46 juergen Exp $")
+MODULE_ID("$Id: fld_current.c,v 1.11 2004/12/25 22:40:13 tom Exp $")
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  int set_current_field(FORM  * form,FIELD * field)
-|   
+|
 |   Description   :  Set the current field of the form to the specified one.
 |
 |   Return Values :  E_OK              - success
@@ -46,46 +47,54 @@ MODULE_ID("$Id: fld_current.c,v 1.4 1999/05/16 17:16:46 juergen Exp $")
 |                    E_INVALID_FIELD   - current field can't be left
 |                    E_SYSTEM_ERROR    - system error
 +--------------------------------------------------------------------------*/
-int set_current_field(FORM  * form, FIELD * field)
+NCURSES_EXPORT(int)
+set_current_field(FORM *form, FIELD *field)
 {
   int err = E_OK;
 
-  if ( !form || !field )
-    RETURN(E_BAD_ARGUMENT);
-
-  if ( (form != field->form) || Field_Is_Not_Selectable(field) )
-    RETURN(E_REQUEST_DENIED);
-
-  if (!(form->status & _POSTED))
+  T((T_CALLED("set_current_field(%p,%p)"), form, field));
+  if (form == 0 || field == 0)
+    {
+      RETURN(E_BAD_ARGUMENT);
+    }
+  else if ((form != field->form) || Field_Is_Not_Selectable(field))
+    {
+      RETURN(E_REQUEST_DENIED);
+    }
+  else if ((form->status & _POSTED) == 0)
     {
       form->current = field;
       form->curpage = field->page;
-  }
+    }
   else
     {
-      if (form->status & _IN_DRIVER) 
-       err = E_BAD_STATE;
+      if ((form->status & _IN_DRIVER) != 0)
+       {
+         err = E_BAD_STATE;
+       }
       else
        {
          if (form->current != field)
            {
-             if (!_nc_Internal_Validation(form)) 
-              err = E_INVALID_FIELD;
+             if (!_nc_Internal_Validation(form))
+               {
+                 err = E_INVALID_FIELD;
+               }
              else
                {
-                 Call_Hook(form,fieldterm);
+                 Call_Hook(form, fieldterm);
                  if (field->page != form->curpage)
                    {
-                     Call_Hook(form,formterm);
-                     err = _nc_Set_Form_Page(form,field->page,field);
-                     Call_Hook(form,forminit);
-                   } 
-                 else 
+                     Call_Hook(form, formterm);
+                     err = _nc_Set_Form_Page(form, (int)field->page, field);
+                     Call_Hook(form, forminit);
+                   }
+                 else
                    {
-                     err = _nc_Set_Current_Field(form,field);
+                     err = _nc_Set_Current_Field(form, field);
                    }
-                 Call_Hook(form,fieldinit);
-                 _nc_Refresh_Current_Field(form);
+                 Call_Hook(form, fieldinit);
+                 (void)_nc_Refresh_Current_Field(form);
                }
            }
        }
@@ -94,31 +103,35 @@ int set_current_field(FORM  * form, FIELD * field)
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  FIELD *current_field(const FORM * form)
-|   
+|
 |   Description   :  Return the current field.
 |
 |   Return Values :  Pointer to the current field.
 +--------------------------------------------------------------------------*/
-FIELD *current_field(const FORM * form)
+NCURSES_EXPORT(FIELD *)
+current_field(const FORM *form)
 {
-  return Normalize_Form(form)->current;
+  T((T_CALLED("current_field(%p)"), form));
+  returnField(Normalize_Form(form)->current);
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  int field_index(const FIELD * field)
-|   
+|
 |   Description   :  Return the index of the field in the field-array of
 |                    the form.
 |
 |   Return Values :  >= 0   : field index
 |                    -1     : fieldpointer invalid or field not connected
 +--------------------------------------------------------------------------*/
-int field_index(const FIELD * field)
+NCURSES_EXPORT(int)
+field_index(const FIELD *field)
 {
-  return ( (field && field->form) ? field->index : -1 );
+  T((T_CALLED("field_index(%p)"), field));
+  returnCode((field != 0 && field->form != 0) ? (int)field->index : -1);
 }
 
 /* fld_current.c ends here */