]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - form/fld_current.c
ncurses 6.4 - patch 20240414
[ncurses.git] / form / fld_current.c
index 72534a9e36a3196cd02df6d5398a8624f54d8f4e..264007ef59f391524576c3c2612c6de88492f7b9 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998 Free Software Foundation, Inc.                        *
+ * Copyright 2020 Thomas E. Dickey                                          *
+ * Copyright 1998-2010,2016 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@T-Online.de> 1995,1997        *
+ *   Author:  Juergen Pfeifer, 1995,1997                                    *
  ****************************************************************************/
+
 #include "form.priv.h"
 
-MODULE_ID("$Id: fld_current.c,v 1.2 1998/02/11 12:13:44 tom Exp $")
+MODULE_ID("$Id: fld_current.c,v 1.16 2020/05/24 01:40:20 anonymous.maarten 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 +48,54 @@ MODULE_ID("$Id: fld_current.c,v 1.2 1998/02/11 12:13:44 tom Exp $")
 |                    E_INVALID_FIELD   - current field can't be left
 |                    E_SYSTEM_ERROR    - system error
 +--------------------------------------------------------------------------*/
-int set_current_field(FORM  * form, FIELD * field)
+FORM_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)"), (void *)form, (void *)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 (form->current && !_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 +104,61 @@ int set_current_field(FORM  * form, FIELD * field)
 }
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
+|   Function      :  int unfocus_current_field(FORM * form)
+|
+|   Description   :  Removes focus from the current field.
+|
+|   Return Values :  E_OK              - success
+|                    E_BAD_ARGUMENT    - invalid form pointer
+|                    E_REQUEST_DENIED  - there is no current field to unfocus
++--------------------------------------------------------------------------*/
+FORM_EXPORT(int)
+unfocus_current_field(FORM *const form)
+{
+  T((T_CALLED("unfocus_current_field(%p)"), (const void *)form));
+  if (form == 0)
+    {
+      RETURN(E_BAD_ARGUMENT);
+    }
+  else if (form->current == 0)
+    {
+      RETURN(E_REQUEST_DENIED);
+    }
+  _nc_Unset_Current_Field(form);
+  RETURN(E_OK);
+}
+
+/*---------------------------------------------------------------------------
+|   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)
+FORM_EXPORT(FIELD *)
+current_field(const FORM *form)
 {
-  return Normalize_Form(form)->current;
+  T((T_CALLED("current_field(%p)"), (const void *)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)
+FORM_EXPORT(int)
+field_index(const FIELD *field)
 {
-  return ( (field && field->form) ? field->index : -1 );
+  T((T_CALLED("field_index(%p)"), (const void *)field));
+  returnCode((field != 0 && field->form != 0) ? (int)field->index : -1);
 }
 
 /* fld_current.c ends here */