frm_data.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /****************************************************************************
  2. * Copyright (c) 1998 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 <[email protected]> 1995,1997 *
  30. ****************************************************************************/
  31. #include "form.priv.h"
  32. MODULE_ID("$Id$")
  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. | becose the begin 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. bool data_behind(const FORM *form)
  44. {
  45. bool result = FALSE;
  46. if (form && (form->status & _POSTED) && form->current)
  47. {
  48. FIELD *field;
  49. field = form->current;
  50. if (!Single_Line_Field(field))
  51. {
  52. result = (form->toprow==0) ? FALSE : TRUE;
  53. }
  54. else
  55. {
  56. result = (form->begincol==0) ? FALSE : TRUE;
  57. }
  58. }
  59. return(result);
  60. }
  61. /*---------------------------------------------------------------------------
  62. | Facility : libnform
  63. | Function : static char * After_Last_Non_Pad_Position(
  64. | char *buffer,
  65. | int len,
  66. | int pad)
  67. |
  68. | Description : Find the last position in the buffer that doesn't
  69. | contain a padding character.
  70. |
  71. | Return Values : The pointer to this position
  72. +--------------------------------------------------------------------------*/
  73. INLINE
  74. static char * After_Last_Non_Pad_Position(char *buffer, int len, int pad)
  75. {
  76. char *end = buffer + len;
  77. assert(buffer && len>=0);
  78. while ( (buffer < end) && (*(end-1)==pad) )
  79. end--;
  80. return end;
  81. }
  82. #define SMALL_BUFFER_SIZE (80)
  83. /*---------------------------------------------------------------------------
  84. | Facility : libnform
  85. | Function : bool data_ahead(const FORM *form)
  86. |
  87. | Description : Check for off-screen data ahead. This is more difficult
  88. | because a dynamic field has a variable end.
  89. |
  90. | Return Values : TRUE - there are off-screen data ahead
  91. | FALSE - there are no off-screen data ahead
  92. +--------------------------------------------------------------------------*/
  93. bool data_ahead(const FORM *form)
  94. {
  95. bool result = FALSE;
  96. if (form && (form->status & _POSTED) && form->current)
  97. {
  98. static char buffer[SMALL_BUFFER_SIZE + 1];
  99. FIELD *field;
  100. bool large_buffer;
  101. bool cursor_moved = FALSE;
  102. char *bp;
  103. char *found_content;
  104. int pos;
  105. field = form->current;
  106. assert(form->w);
  107. large_buffer = (field->cols > SMALL_BUFFER_SIZE);
  108. if (large_buffer)
  109. bp = (char *)malloc((size_t)(field->cols) + 1);
  110. else
  111. bp = buffer;
  112. assert(bp);
  113. if (Single_Line_Field(field))
  114. {
  115. int check_len;
  116. pos = form->begincol + field->cols;
  117. while (pos < field->dcols)
  118. {
  119. check_len = field->dcols - pos;
  120. if ( check_len >= field->cols )
  121. check_len = field->cols;
  122. cursor_moved = TRUE;
  123. wmove(form->w,0,pos);
  124. winnstr(form->w,bp,check_len);
  125. found_content =
  126. After_Last_Non_Pad_Position(bp,check_len,field->pad);
  127. if (found_content==bp)
  128. pos += field->cols;
  129. else
  130. {
  131. result = TRUE;
  132. break;
  133. }
  134. }
  135. }
  136. else
  137. {
  138. pos = form->toprow + field->rows;
  139. while (pos < field->drows)
  140. {
  141. cursor_moved = TRUE;
  142. wmove(form->w,pos,0);
  143. pos++;
  144. winnstr(form->w,bp,field->cols);
  145. found_content =
  146. After_Last_Non_Pad_Position(bp,field->cols,field->pad);
  147. if (found_content!=bp)
  148. {
  149. result = TRUE;
  150. break;
  151. }
  152. }
  153. }
  154. if (large_buffer)
  155. free(bp);
  156. if (cursor_moved)
  157. wmove(form->w,form->currow,form->curcol);
  158. }
  159. return(result);
  160. }
  161. /* frm_data.c ends here */