]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - form/fld_max.c
ncurses 6.2 - patch 20210904
[ncurses.git] / form / fld_max.c
index 6c7fe728bd985b935d6ffc3d7cf1ab3cd879534d..325541a373b5c76c076ae8f49ad68261fc1ba9db 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
+ * Copyright 2019-2020,2021 Thomas E. Dickey                                *
+ * Copyright 1998-2012,2013 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            *
 
 #include "form.priv.h"
 
-MODULE_ID("$Id: fld_max.c,v 1.13 2013/08/24 22:59:28 tom Exp $")
+MODULE_ID("$Id: fld_max.c,v 1.18 2021/06/17 21:26:02 tom Exp $")
 
 /*---------------------------------------------------------------------------
-|   Facility      :  libnform  
+|   Facility      :  libnform
 |   Function      :  int set_max_field(FIELD *field, int maxgrow)
-|   
+|
 |   Description   :  Set the maximum growth for a dynamic field. If maxgrow=0
 |                    the field may grow to any possible size.
 |
 |   Return Values :  E_OK           - success
 |                    E_BAD_ARGUMENT - invalid argument
 +--------------------------------------------------------------------------*/
-NCURSES_EXPORT(int)
+FORM_EXPORT(int)
 set_max_field(FIELD *field, int maxgrow)
 {
   T((T_CALLED("set_max_field(%p,%d)"), (void *)field, maxgrow));
@@ -57,11 +58,16 @@ set_max_field(FIELD *field, int maxgrow)
 
       if (maxgrow > 0)
        {
-         if ((single_line_field && (maxgrow < field->dcols)) ||
-             (!single_line_field && (maxgrow < field->drows)))
+         if (((single_line_field && (maxgrow < field->dcols)) ||
+              (!single_line_field && (maxgrow < field->drows))) &&
+             !Field_Has_Option(field, O_INPUT_LIMIT))
            RETURN(E_BAD_ARGUMENT);
        }
       field->maxgrow = maxgrow;
+      /* shrink */
+      if (maxgrow > 0 && Field_Has_Option(field, O_INPUT_LIMIT) &&
+         field->dcols > maxgrow)
+       field->dcols = maxgrow;
       ClrStatus(field, _MAY_GROW);
       if (!((unsigned)field->opts & O_STATIC))
        {