scroll.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* PDCurses */
  2. #include <curspriv.h>
  3. /*man-start**************************************************************
  4. scroll
  5. ------
  6. ### Synopsis
  7. int scroll(WINDOW *win);
  8. int scrl(int n);
  9. int wscrl(WINDOW *win, int n);
  10. ### Description
  11. scroll() causes the window to scroll up one line. This involves
  12. moving the lines in the window data strcture.
  13. With a positive n, scrl() and wscrl() scroll the window up n lines
  14. (line i + n becomes i); otherwise they scroll the window down n
  15. lines.
  16. For these functions to work, scrolling must be enabled via
  17. scrollok(). Note also that scrolling is not allowed if the supplied
  18. window is a pad.
  19. ### Return Value
  20. All functions return OK on success and ERR on error.
  21. ### Portability
  22. X/Open ncurses NetBSD
  23. scroll Y Y Y
  24. scrl Y Y Y
  25. wscrl Y Y Y
  26. **man-end****************************************************************/
  27. int wscrl(WINDOW *win, int n)
  28. {
  29. int i, l, dir, start, end;
  30. chtype blank, *temp;
  31. /* Check if window scrolls. Valid for window AND pad */
  32. if (!win || !win->_scroll || !n)
  33. return ERR;
  34. blank = win->_bkgd;
  35. if (n > 0)
  36. {
  37. start = win->_tmarg;
  38. end = win->_bmarg;
  39. dir = 1;
  40. }
  41. else
  42. {
  43. start = win->_bmarg;
  44. end = win->_tmarg;
  45. dir = -1;
  46. }
  47. for (l = 0; l < (n * dir); l++)
  48. {
  49. temp = win->_y[start];
  50. /* re-arrange line pointers */
  51. for (i = start; i != end; i += dir)
  52. win->_y[i] = win->_y[i + dir];
  53. win->_y[end] = temp;
  54. /* make a blank line */
  55. for (i = 0; i < win->_maxx; i++)
  56. *temp++ = blank;
  57. }
  58. touchline(win, win->_tmarg, win->_bmarg - win->_tmarg + 1);
  59. PDC_sync(win);
  60. return OK;
  61. }
  62. int scrl(int n)
  63. {
  64. PDC_LOG(("scrl() - called\n"));
  65. return wscrl(stdscr, n);
  66. }
  67. int scroll(WINDOW *win)
  68. {
  69. PDC_LOG(("scroll() - called\n"));
  70. return wscrl(win, 1);
  71. }