X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=form%2Ffld_max.c;h=325541a373b5c76c076ae8f49ad68261fc1ba9db;hp=1ed58176b889ae23f10b2b8ffeccc0862d7502ef;hb=643ec2bf782cd02efafe3ccdeaea8920a404645e;hpb=46722468f47c2b77b3987729b4bcf2321cccfd01 diff --git a/form/fld_max.c b/form/fld_max.c index 1ed58176..325541a3 100644 --- a/form/fld_max.c +++ b/form/fld_max.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998,2000 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 * @@ -28,49 +29,55 @@ /**************************************************************************** * Author: Juergen Pfeifer, 1995,1997 * - * Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en * ****************************************************************************/ #include "form.priv.h" -MODULE_ID("$Id: fld_max.c,v 1.6 2002/07/06 15:33:27 juergen 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) -set_max_field (FIELD *field, int maxgrow) +FORM_EXPORT(int) +set_max_field(FIELD *field, int maxgrow) { - if (!field || (maxgrow<0)) + T((T_CALLED("set_max_field(%p,%d)"), (void *)field, maxgrow)); + + if (!field || (maxgrow < 0)) RETURN(E_BAD_ARGUMENT); else { bool single_line_field = Single_Line_Field(field); - if (maxgrow>0) + 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)) || + 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); } - + /* fld_max.c ends here */