00001 /**************************************************************************** 00002 * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc. * 00003 * * 00004 * Permission is hereby granted, free of charge, to any person obtaining a * 00005 * copy of this software and associated documentation files (the * 00006 * "Software"), to deal in the Software without restriction, including * 00007 * without limitation the rights to use, copy, modify, merge, publish, * 00008 * distribute, distribute with modifications, sublicense, and/or sell * 00009 * copies of the Software, and to permit persons to whom the Software is * 00010 * furnished to do so, subject to the following conditions: * 00011 * * 00012 * The above copyright notice and this permission notice shall be included * 00013 * in all copies or substantial portions of the Software. * 00014 * * 00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 00016 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 00017 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 00018 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 00019 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 00020 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 00021 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 00022 * * 00023 * Except as contained in this notice, the name(s) of the above copyright * 00024 * holders shall not be used in advertising or otherwise to promote the * 00025 * sale, use or other dealings in this Software without prior written * 00026 * authorization. * 00027 ****************************************************************************/ 00028 00029 /**************************************************************************** 00030 * Author: Juergen Pfeifer, 1995,1997 * 00031 ****************************************************************************/ 00032 00033 #include "form.priv.h" 00034 00035 MODULE_ID("$Id: frm_data.c,v 1.13 2004/12/11 22:29:28 tom Exp $") 00036 00037 /*--------------------------------------------------------------------------- 00038 | Facility : libnform 00039 | Function : bool data_behind(const FORM *form) 00040 | 00041 | Description : Check for off-screen data behind. This is nearly trivial 00042 | because the beginning of a field is fixed. 00043 | 00044 | Return Values : TRUE - there are off-screen data behind 00045 | FALSE - there are no off-screen data behind 00046 +--------------------------------------------------------------------------*/ 00047 NCURSES_EXPORT(bool) 00048 data_behind(const FORM *form) 00049 { 00050 bool result = FALSE; 00051 00052 T((T_CALLED("data_behind(%p)"), form)); 00053 00054 if (form && (form->status & _POSTED) && form->current) 00055 { 00056 FIELD *field; 00057 00058 field = form->current; 00059 if (!Single_Line_Field(field)) 00060 { 00061 result = (form->toprow == 0) ? FALSE : TRUE; 00062 } 00063 else 00064 { 00065 result = (form->begincol == 0) ? FALSE : TRUE; 00066 } 00067 } 00068 returnBool(result); 00069 } 00070 00071 /*--------------------------------------------------------------------------- 00072 | Facility : libnform 00073 | Function : static char * Only_Padding( 00074 | WINDOW *w, 00075 | int len, 00076 | int pad) 00077 | 00078 | Description : Test if 'length' cells starting at the current position 00079 | contain a padding character. 00080 | 00081 | Return Values : true if only padding cells are found 00082 +--------------------------------------------------------------------------*/ 00083 INLINE static bool 00084 Only_Padding(WINDOW *w, int len, int pad) 00085 { 00086 bool result = TRUE; 00087 int y, x, j; 00088 FIELD_CELL cell; 00089 00090 getyx(w, y, x); 00091 for (j = 0; j < len; ++j) 00092 { 00093 if (wmove(w, y, x + j) != ERR) 00094 { 00095 #if USE_WIDEC_SUPPORT 00096 if (win_wch(w, &cell) != ERR) 00097 { 00098 if ((chtype)CharOf(cell) != ChCharOf(pad) 00099 || cell.chars[1] != 0) 00100 { 00101 result = FALSE; 00102 break; 00103 } 00104 } 00105 #else 00106 cell = winch(w); 00107 if (ChCharOf(cell) != ChCharOf(pad)) 00108 { 00109 result = FALSE; 00110 break; 00111 } 00112 #endif 00113 } 00114 else 00115 { 00116 /* if an error, return true: no non-padding text found */ 00117 break; 00118 } 00119 } 00120 /* no need to reset the cursor position; caller does this */ 00121 return result; 00122 } 00123 00124 /*--------------------------------------------------------------------------- 00125 | Facility : libnform 00126 | Function : bool data_ahead(const FORM *form) 00127 | 00128 | Description : Check for off-screen data ahead. This is more difficult 00129 | because a dynamic field has a variable end. 00130 | 00131 | Return Values : TRUE - there are off-screen data ahead 00132 | FALSE - there are no off-screen data ahead 00133 +--------------------------------------------------------------------------*/ 00134 NCURSES_EXPORT(bool) 00135 data_ahead(const FORM *form) 00136 { 00137 bool result = FALSE; 00138 00139 T((T_CALLED("data_ahead(%p)"), form)); 00140 00141 if (form && (form->status & _POSTED) && form->current) 00142 { 00143 FIELD *field; 00144 bool cursor_moved = FALSE; 00145 int pos; 00146 00147 field = form->current; 00148 assert(form->w); 00149 00150 if (Single_Line_Field(field)) 00151 { 00152 int check_len; 00153 00154 pos = form->begincol + field->cols; 00155 while (pos < field->dcols) 00156 { 00157 check_len = field->dcols - pos; 00158 if (check_len >= field->cols) 00159 check_len = field->cols; 00160 cursor_moved = TRUE; 00161 wmove(form->w, 0, pos); 00162 if (Only_Padding(form->w, check_len, field->pad)) 00163 pos += field->cols; 00164 else 00165 { 00166 result = TRUE; 00167 break; 00168 } 00169 } 00170 } 00171 else 00172 { 00173 pos = form->toprow + field->rows; 00174 while (pos < field->drows) 00175 { 00176 cursor_moved = TRUE; 00177 wmove(form->w, pos, 0); 00178 pos++; 00179 if (!Only_Padding(form->w, field->cols, field->pad)) 00180 { 00181 result = TRUE; 00182 break; 00183 } 00184 } 00185 } 00186 00187 if (cursor_moved) 00188 wmove(form->w, form->currow, form->curcol); 00189 } 00190 returnBool(result); 00191 } 00192 00193 /* frm_data.c ends here */