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