frm_data.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /****************************************************************************
  2. * Copyright (c) 1998-2004,2005 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. * Author: Juergen Pfeifer, 1995,1997 *
  30. ****************************************************************************/
  31. #include "form.priv.h"
  32. MODULE_ID("$Id: frm_data.c,v 1.14 2005/11/26 15:34:01 tom Exp $")
  33. /*---------------------------------------------------------------------------
  34. | Facility : libnform
  35. | Function : bool data_behind(const FORM *form)
  36. |
  37. | Description : Check for off-screen data behind. This is nearly trivial
  38. | because the beginning of a field is fixed.
  39. |
  40. | Return Values : TRUE - there are off-screen data behind
  41. | FALSE - there are no off-screen data behind
  42. +--------------------------------------------------------------------------*/
  43. NCURSES_EXPORT(bool)
  44. data_behind(const FORM *form)
  45. {
  46. bool result = FALSE;
  47. T((T_CALLED("data_behind(%p)"), form));
  48. if (form && (form->status & _POSTED) && form->current)
  49. {
  50. FIELD *field;
  51. field = form->current;
  52. if (!Single_Line_Field(field))
  53. {
  54. result = (form->toprow == 0) ? FALSE : TRUE;
  55. }
  56. else
  57. {
  58. result = (form->begincol == 0) ? FALSE : TRUE;
  59. }
  60. }
  61. returnBool(result);
  62. }
  63. /*---------------------------------------------------------------------------
  64. | Facility : libnform
  65. | Function : static char * Only_Padding(
  66. | WINDOW *w,
  67. | int len,
  68. | int pad)
  69. |
  70. | Description : Test if 'length' cells starting at the current position
  71. | contain a padding character.
  72. |
  73. | Return Values : true if only padding cells are found
  74. +--------------------------------------------------------------------------*/
  75. NCURSES_INLINE static bool
  76. Only_Padding(WINDOW *w, int len, int pad)
  77. {
  78. bool result = TRUE;
  79. int y, x, j;
  80. FIELD_CELL cell;
  81. getyx(w, y, x);
  82. for (j = 0; j < len; ++j)
  83. {
  84. if (wmove(w, y, x + j) != ERR)
  85. {
  86. #if USE_WIDEC_SUPPORT
  87. if (win_wch(w, &cell) != ERR)
  88. {
  89. if ((chtype)CharOf(cell) != ChCharOf(pad)
  90. || cell.chars[1] != 0)
  91. {
  92. result = FALSE;
  93. break;
  94. }
  95. }
  96. #else
  97. cell = winch(w);
  98. if (ChCharOf(cell) != ChCharOf(pad))
  99. {
  100. result = FALSE;
  101. break;
  102. }
  103. #endif
  104. }
  105. else
  106. {
  107. /* if an error, return true: no non-padding text found */
  108. break;
  109. }
  110. }
  111. /* no need to reset the cursor position; caller does this */
  112. return result;
  113. }
  114. /*---------------------------------------------------------------------------
  115. | Facility : libnform
  116. | Function : bool data_ahead(const FORM *form)
  117. |
  118. | Description : Check for off-screen data ahead. This is more difficult
  119. | because a dynamic field has a variable end.
  120. |
  121. | Return Values : TRUE - there are off-screen data ahead
  122. | FALSE - there are no off-screen data ahead
  123. +--------------------------------------------------------------------------*/
  124. NCURSES_EXPORT(bool)
  125. data_ahead(const FORM *form)
  126. {
  127. bool result = FALSE;
  128. T((T_CALLED("data_ahead(%p)"), form));
  129. if (form && (form->status & _POSTED) && form->current)
  130. {
  131. FIELD *field;
  132. bool cursor_moved = FALSE;
  133. int pos;
  134. field = form->current;
  135. assert(form->w);
  136. if (Single_Line_Field(field))
  137. {
  138. int check_len;
  139. pos = form->begincol + field->cols;
  140. while (pos < field->dcols)
  141. {
  142. check_len = field->dcols - pos;
  143. if (check_len >= field->cols)
  144. check_len = field->cols;
  145. cursor_moved = TRUE;
  146. wmove(form->w, 0, pos);
  147. if (Only_Padding(form->w, check_len, field->pad))
  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. if (!Only_Padding(form->w, field->cols, field->pad))
  165. {
  166. result = TRUE;
  167. break;
  168. }
  169. }
  170. }
  171. if (cursor_moved)
  172. wmove(form->w, form->currow, form->curcol);
  173. }
  174. returnBool(result);
  175. }
  176. /* frm_data.c ends here */