frm_data.c revision 1.3
1/*	$OpenBSD: frm_data.c,v 1.3 1997/12/03 05:40:11 millert Exp $	*/
2
3/*-----------------------------------------------------------------------------+
4|           The ncurses form library is  Copyright (C) 1995-1997               |
5|             by Juergen Pfeifer <Juergen.Pfeifer@T-Online.de>                 |
6|                          All Rights Reserved.                                |
7|                                                                              |
8| Permission to use, copy, modify, and distribute this software and its        |
9| documentation for any purpose and without fee is hereby granted, provided    |
10| that the above copyright notice appear in all copies and that both that      |
11| copyright notice and this permission notice appear in supporting             |
12| documentation, and that the name of the above listed copyright holder(s) not |
13| be used in advertising or publicity pertaining to distribution of the        |
14| software without specific, written prior permission.                         |
15|                                                                              |
16| THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO  |
17| THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-  |
18| NESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR   |
19| ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RE- |
20| SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
21| NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH    |
22| THE USE OR PERFORMANCE OF THIS SOFTWARE.                                     |
23+-----------------------------------------------------------------------------*/
24
25#include "form.priv.h"
26
27MODULE_ID("Id: frm_data.c,v 1.3 1997/05/01 16:47:54 juergen Exp $")
28
29/*---------------------------------------------------------------------------
30|   Facility      :  libnform
31|   Function      :  bool data_behind(const FORM *form)
32|
33|   Description   :  Check for off-screen data behind. This is nearly trivial
34|                    becose the begin of a field is fixed.
35|
36|   Return Values :  TRUE   - there are off-screen data behind
37|                    FALSE  - there are no off-screen data behind
38+--------------------------------------------------------------------------*/
39bool data_behind(const FORM *form)
40{
41  bool result = FALSE;
42
43  if (form && (form->status & _POSTED) && form->current)
44    {
45      FIELD *field;
46
47      field = form->current;
48      if (!Single_Line_Field(field))
49	{
50	  result = (form->toprow==0) ? FALSE : TRUE;
51	}
52      else
53	{
54	  result = (form->begincol==0) ? FALSE : TRUE;
55	}
56    }
57  return(result);
58}
59
60/*---------------------------------------------------------------------------
61|   Facility      :  libnform
62|   Function      :  static char * After_Last_Non_Pad_Position(
63|                                    char *buffer,
64|                                    int len,
65|                                    int pad)
66|
67|   Description   :  Find the last position in the buffer that doesn't
68|                    contain a padding character.
69|
70|   Return Values :  The pointer to this position
71+--------------------------------------------------------------------------*/
72INLINE
73static char * After_Last_Non_Pad_Position(char *buffer, int len, int pad)
74{
75  char *end = buffer + len;
76
77  assert(buffer && len>=0);
78  while ( (buffer < end) && (*(end-1)==pad) )
79    end--;
80
81  return end;
82}
83
84#define SMALL_BUFFER_SIZE (80)
85
86/*---------------------------------------------------------------------------
87|   Facility      :  libnform
88|   Function      :  bool data_ahead(const FORM *form)
89|
90|   Description   :  Check for off-screen data ahead. This is more difficult
91|                    because a dynamic field has a variable end.
92|
93|   Return Values :  TRUE   - there are off-screen data ahead
94|                    FALSE  - there are no off-screen data ahead
95+--------------------------------------------------------------------------*/
96bool data_ahead(const FORM *form)
97{
98  bool result = FALSE;
99
100  if (form && (form->status & _POSTED) && form->current)
101    {
102      static char buffer[SMALL_BUFFER_SIZE + 1];
103      FIELD *field;
104      bool large_buffer;
105      bool cursor_moved = FALSE;
106      char *bp;
107      char *found_content;
108      int pos;
109
110      field = form->current;
111      assert(form->w);
112
113      large_buffer = (field->cols > SMALL_BUFFER_SIZE);
114      if (large_buffer)
115	bp = (char *)malloc((size_t)(field->cols) + 1);
116      else
117	bp = buffer;
118
119      assert(bp);
120
121      if (Single_Line_Field(field))
122	{
123	  int check_len;
124
125	  pos = form->begincol + field->cols;
126	  while (pos < field->dcols)
127	    {
128	      check_len = field->dcols - pos;
129	      if ( check_len >= field->cols )
130		check_len = field->cols;
131	      cursor_moved = TRUE;
132	      wmove(form->w,0,pos);
133	      winnstr(form->w,bp,check_len);
134	      found_content =
135		After_Last_Non_Pad_Position(bp,check_len,field->pad);
136	      if (found_content==bp)
137		  pos += field->cols;
138	      else
139		{
140		  result = TRUE;
141		  break;
142		}
143	    }
144	}
145      else
146	{
147	  pos = form->toprow + field->rows;
148	  while (pos < field->drows)
149	    {
150	      cursor_moved = TRUE;
151	      wmove(form->w,pos,0);
152	      pos++;
153	      winnstr(form->w,bp,field->cols);
154	      found_content =
155		After_Last_Non_Pad_Position(bp,field->cols,field->pad);
156	      if (found_content!=bp)
157		{
158		  result = TRUE;
159		  break;
160		}
161	    }
162	}
163
164      if (large_buffer)
165	free(bp);
166
167      if (cursor_moved)
168	wmove(form->w,form->currow,form->curcol);
169    }
170  return(result);
171}
172
173/* frm_data.c ends here */
174