X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=form%2Ffld_max.c;h=bfeadf9b7fa8d1a7f3326a1c469a8f547d083cd6;hp=7f5352e00d6e5fd6f8bc723e69ecdf130335df9f;hb=d6c65d287166c3105ece4a5e3f3ec7af5a5f26a3;hpb=55ccd2b959766810cf7db8d1c4462f338ce0afc8;ds=sidebyside diff --git a/form/fld_max.c b/form/fld_max.c index 7f5352e0..bfeadf9b 100644 --- a/form/fld_max.c +++ b/form/fld_max.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc. * + * Copyright 2019,2020 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 * @@ -32,7 +33,7 @@ #include "form.priv.h" -MODULE_ID("$Id: fld_max.c,v 1.9 2004/12/11 21:51:54 tom Exp $") +MODULE_ID("$Id: fld_max.c,v 1.17 2020/05/24 01:40:20 anonymous.maarten Exp $") /*--------------------------------------------------------------------------- | Facility : libnform @@ -44,10 +45,10 @@ MODULE_ID("$Id: fld_max.c,v 1.9 2004/12/11 21:51:54 tom Exp $") | 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)"), field, maxgrow)); + T((T_CALLED("set_max_field(%p,%d)"), (void *)field, maxgrow)); if (!field || (maxgrow < 0)) RETURN(E_BAD_ARGUMENT); @@ -57,18 +58,23 @@ 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; - field->status &= ~_MAY_GROW; - if (!(field->opts & O_STATIC)) + /* 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)) { if ((maxgrow == 0) || (single_line_field && (field->dcols < maxgrow)) || (!single_line_field && (field->drows < maxgrow))) - field->status |= _MAY_GROW; + SetStatus(field, _MAY_GROW); } } RETURN(E_OK);