frm_data.c revision 1.1
1 2/*************************************************************************** 3* COPYRIGHT NOTICE * 4**************************************************************************** 5* ncurses is copyright (C) 1992-1995 * 6* Zeyd M. Ben-Halim * 7* zmbenhal@netcom.com * 8* Eric S. Raymond * 9* esr@snark.thyrsus.com * 10* * 11* Permission is hereby granted to reproduce and distribute ncurses * 12* by any means and for any fee, whether alone or as part of a * 13* larger distribution, in source or in binary form, PROVIDED * 14* this notice is included with any such distribution, and is not * 15* removed from any of its header files. Mention of ncurses in any * 16* applications linked with it is highly appreciated. * 17* * 18* ncurses comes AS IS with no warranty, implied or expressed. * 19* * 20***************************************************************************/ 21 22#include "form.priv.h" 23 24/*--------------------------------------------------------------------------- 25| Facility : libnform 26| Function : bool data_behind(const FORM *form) 27| 28| Description : Check for off-screen data behind. This is nearly trivial 29| becose the begin of a field is fixed. 30| 31| Return Values : TRUE - there are off-screen data behind 32| FALSE - there are no off-screen data behind 33+--------------------------------------------------------------------------*/ 34bool data_behind(const FORM *form) 35{ 36 bool result = FALSE; 37 38 if (form && (form->status & _POSTED) && form->current) 39 { 40 FIELD *field; 41 42 field = form->current; 43 if (!Single_Line_Field(field)) 44 { 45 result = (form->toprow==0) ? FALSE : TRUE; 46 } 47 else 48 { 49 result = (form->begincol==0) ? FALSE : TRUE; 50 } 51 } 52 return(result); 53} 54 55/*--------------------------------------------------------------------------- 56| Facility : libnform 57| Function : static char * After_Last_Non_Pad_Position( 58| char *buffer, 59| int len, 60| int pad) 61| 62| Description : Find the last position in the buffer that doesn't 63| contain a padding character. 64| 65| Return Values : The pointer to this position 66+--------------------------------------------------------------------------*/ 67INLINE 68static char * After_Last_Non_Pad_Position(char *buffer, int len, int pad) 69{ 70 char *end = buffer + len; 71 72 assert(buffer && len>=0); 73 while ( (buffer < end) && (*(end-1)==pad) ) 74 end--; 75 76 return end; 77} 78 79#define SMALL_BUFFER_SIZE (80) 80 81/*--------------------------------------------------------------------------- 82| Facility : libnform 83| Function : bool data_ahead(const FORM *form) 84| 85| Description : Check for off-screen data ahead. This is more difficult 86| because a dynamic field has a variable end. 87| 88| Return Values : TRUE - there are off-screen data ahead 89| FALSE - there are no off-screen data ahead 90+--------------------------------------------------------------------------*/ 91bool data_ahead(const FORM *form) 92{ 93 bool result = FALSE; 94 95 if (form && (form->status & _POSTED) && form->current) 96 { 97 static char buffer[SMALL_BUFFER_SIZE + 1]; 98 FIELD *field; 99 bool large_buffer; 100 bool cursor_moved = FALSE; 101 char *bp; 102 char *found_content; 103 int pos; 104 105 field = form->current; 106 assert(form->w); 107 108 large_buffer = (field->cols > SMALL_BUFFER_SIZE); 109 if (large_buffer) 110 bp = (char *)malloc((size_t)(field->cols) + 1); 111 else 112 bp = buffer; 113 114 assert(bp); 115 116 if (Single_Line_Field(field)) 117 { 118 int check_len; 119 120 pos = form->begincol + field->cols; 121 while (pos < field->dcols) 122 { 123 check_len = field->dcols - pos; 124 if ( check_len >= field->cols ) 125 check_len = field->cols; 126 cursor_moved = TRUE; 127 wmove(form->w,0,pos); 128 winnstr(form->w,bp,check_len); 129 found_content = 130 After_Last_Non_Pad_Position(bp,check_len,field->pad); 131 if (found_content==bp) 132 pos += field->cols; 133 else 134 { 135 result = TRUE; 136 break; 137 } 138 } 139 } 140 else 141 { 142 pos = form->toprow + field->rows; 143 while (pos < field->drows) 144 { 145 cursor_moved = TRUE; 146 wmove(form->w,pos,0); 147 pos++; 148 winnstr(form->w,bp,field->cols); 149 found_content = 150 After_Last_Non_Pad_Position(bp,field->cols,field->pad); 151 if (found_content!=bp) 152 { 153 result = TRUE; 154 break; 155 } 156 } 157 } 158 159 if (large_buffer) 160 free(bp); 161 162 if (cursor_moved) 163 wmove(form->w,form->currow,form->curcol); 164 } 165 return(result); 166} 167 168/* frm_data.c ends here */ 169