]> ncurses.scripts.mit.edu Git - ncurses.git/blob - form/frm_data.c
1026cf4ffeabace26e19d7d267827c75475ade86
[ncurses.git] / form / frm_data.c
1 /****************************************************************************
2  * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
3  *                                                                          *
4  * Permission is hereby granted, free of charge, to any person obtaining a  *
5  * copy of this software and associated documentation files (the            *
6  * "Software"), to deal in the Software without restriction, including      *
7  * without limitation the rights to use, copy, modify, merge, publish,      *
8  * distribute, distribute with modifications, sublicense, and/or sell       *
9  * copies of the Software, and to permit persons to whom the Software is    *
10  * furnished to do so, subject to the following conditions:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22  *                                                                          *
23  * Except as contained in this notice, the name(s) of the above copyright   *
24  * holders shall not be used in advertising or otherwise to promote the     *
25  * sale, use or other dealings in this Software without prior written       *
26  * authorization.                                                           *
27  ****************************************************************************/
28
29 /****************************************************************************
30  *   Author:  Juergen Pfeifer, 1995,1997                                    *
31  *   Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en             *
32  ****************************************************************************/
33
34 #include "form.priv.h"
35
36 MODULE_ID("$Id: frm_data.c,v 1.8 2002/07/06 15:33:27 juergen Exp $")
37
38 /*---------------------------------------------------------------------------
39 |   Facility      :  libnform  
40 |   Function      :  bool data_behind(const FORM *form)
41 |   
42 |   Description   :  Check for off-screen data behind. This is nearly trivial
43 |                    becose the begin of a field is fixed.
44 |
45 |   Return Values :  TRUE   - there are off-screen data behind
46 |                    FALSE  - there are no off-screen data behind
47 +--------------------------------------------------------------------------*/
48 NCURSES_EXPORT(bool)
49 data_behind (const FORM *form)
50 {
51   bool result = FALSE;
52
53   if (form && (form->status & _POSTED) && form->current)
54     {
55       FIELD *field;
56
57       field = form->current;
58       if (!Single_Line_Field(field))
59         {
60           result = (form->toprow==0) ? FALSE : TRUE;
61         }
62       else
63         {
64           result = (form->begincol==0) ? FALSE : TRUE;
65         }
66     }
67   return(result);
68 }
69
70 /*---------------------------------------------------------------------------
71 |   Facility      :  libnform  
72 |   Function      :  static char * After_Last_Non_Pad_Position(
73 |                                    char *buffer,
74 |                                    int len,
75 |                                    int pad)
76 |   
77 |   Description   :  Find the last position in the buffer that doesn't
78 |                    contain a padding character.
79 |
80 |   Return Values :  The pointer to this position 
81 +--------------------------------------------------------------------------*/
82 INLINE 
83 static char * After_Last_Non_Pad_Position(char *buffer, int len, int pad)
84 {
85   char *end = buffer + len;
86
87   assert(buffer && len>=0);
88   while ( (buffer < end) && (*(end-1)==pad) )
89     end--;
90
91   return end;
92 }
93
94 #define SMALL_BUFFER_SIZE (80)
95
96 /*---------------------------------------------------------------------------
97 |   Facility      :  libnform  
98 |   Function      :  bool data_ahead(const FORM *form)
99 |   
100 |   Description   :  Check for off-screen data ahead. This is more difficult
101 |                    because a dynamic field has a variable end. 
102 |
103 |   Return Values :  TRUE   - there are off-screen data ahead
104 |                    FALSE  - there are no off-screen data ahead
105 +--------------------------------------------------------------------------*/
106 NCURSES_EXPORT(bool)
107 data_ahead (const FORM *form)
108 {
109   bool result = FALSE;
110
111   if (form && (form->status & _POSTED) && form->current)
112     {
113       static char buffer[SMALL_BUFFER_SIZE + 1];
114       FIELD *field;
115       bool large_buffer;
116       bool cursor_moved = FALSE;
117       char *bp;
118       char *found_content;
119       int pos;
120
121       field = form->current;
122       assert(form->w);
123
124       large_buffer = (field->cols > SMALL_BUFFER_SIZE);
125       if (large_buffer)
126         bp = (char *)malloc((size_t)(field->cols) + 1);
127       else
128         bp = buffer;
129
130       assert(bp);
131       
132       if (Single_Line_Field(field))
133         {
134           int check_len;
135
136           pos = form->begincol + field->cols;
137           while (pos < field->dcols)
138             {
139               check_len = field->dcols - pos;
140               if ( check_len >= field->cols )
141                 check_len = field->cols;
142               cursor_moved = TRUE;
143               wmove(form->w,0,pos);
144               winnstr(form->w,bp,check_len);
145               found_content = 
146                 After_Last_Non_Pad_Position(bp,check_len,field->pad);
147               if (found_content==bp)
148                   pos += field->cols;             
149               else
150                 {
151                   result = TRUE;
152                   break;
153                 }
154             }
155         }
156       else
157         {
158           pos = form->toprow + field->rows;
159           while (pos < field->drows)
160             {
161               cursor_moved = TRUE;
162               wmove(form->w,pos,0);
163               pos++;
164               winnstr(form->w,bp,field->cols);
165               found_content = 
166                 After_Last_Non_Pad_Position(bp,field->cols,field->pad);
167               if (found_content!=bp)
168                 {
169                   result = TRUE;
170                   break;
171                 }
172             }
173         }
174
175       if (large_buffer)
176         free(bp);
177
178       if (cursor_moved)
179         wmove(form->w,form->currow,form->curcol);
180     }
181   return(result);
182 }
183
184 /* frm_data.c ends here */