1 /****************************************************************************
2 * Copyright 2020,2021 Thomas E. Dickey *
3 * Copyright 1998-2010,2013 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Juergen Pfeifer, 1995,1997 *
32 ****************************************************************************/
34 #include "form.priv.h"
36 MODULE_ID("$Id: frm_data.c,v 1.21 2021/06/17 21:11:08 tom Exp $")
38 /*---------------------------------------------------------------------------
40 | Function : bool data_behind(const FORM *form)
42 | Description : Check for off-screen data behind. This is nearly trivial
43 | because the beginning of a field is fixed.
45 | Return Values : TRUE - there are off-screen data behind
46 | FALSE - there are no off-screen data behind
47 +--------------------------------------------------------------------------*/
49 data_behind(const FORM *form)
53 T((T_CALLED("data_behind(%p)"), (const void *)form));
55 if (form && (form->status & _POSTED) && form->current)
59 field = form->current;
60 if (!Single_Line_Field(field))
62 result = (form->toprow == 0) ? FALSE : TRUE;
66 result = (form->begincol == 0) ? FALSE : TRUE;
72 /*---------------------------------------------------------------------------
74 | Function : static char * Only_Padding(
79 | Description : Test if 'length' cells starting at the current position
80 | contain a padding character.
82 | Return Values : true if only padding cells are found
83 +--------------------------------------------------------------------------*/
84 NCURSES_INLINE static bool
85 Only_Padding(WINDOW *w, int len, int pad)
92 for (j = 0; j < len; ++j)
94 if (wmove(w, y, x + j) != ERR)
97 if (win_wch(w, &cell) != ERR)
99 if ((chtype)CharOf(cell) != ChCharOf(pad)
100 || cell.chars[1] != 0)
107 cell = (FIELD_CELL)winch(w);
108 if (ChCharOf(cell) != ChCharOf(pad))
117 /* if an error, return true: no non-padding text found */
121 /* no need to reset the cursor position; caller does this */
125 /*---------------------------------------------------------------------------
126 | Facility : libnform
127 | Function : bool data_ahead(const FORM *form)
129 | Description : Check for off-screen data ahead. This is more difficult
130 | because a dynamic field has a variable end.
132 | Return Values : TRUE - there are off-screen data ahead
133 | FALSE - there are no off-screen data ahead
134 +--------------------------------------------------------------------------*/
136 data_ahead(const FORM *form)
140 T((T_CALLED("data_ahead(%p)"), (const void *)form));
142 if (form && (form->status & _POSTED) && form->current)
145 bool cursor_moved = FALSE;
148 field = form->current;
151 if (Single_Line_Field(field))
153 pos = form->begincol + field->cols;
154 while (pos < field->dcols)
156 int check_len = field->dcols - pos;
158 if (check_len >= field->cols)
159 check_len = field->cols;
161 wmove(form->w, 0, pos);
162 if (Only_Padding(form->w, check_len, field->pad))
173 pos = form->toprow + field->rows;
174 while (pos < field->drows)
177 wmove(form->w, pos, 0);
179 if (!Only_Padding(form->w, field->cols, field->pad))
188 wmove(form->w, form->currow, form->curcol);
193 /* frm_data.c ends here */