clear.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* PDCurses */
  2. #include <curspriv.h>
  3. /*man-start**************************************************************
  4. clear
  5. -----
  6. ### Synopsis
  7. int clear(void);
  8. int wclear(WINDOW *win);
  9. int erase(void);
  10. int werase(WINDOW *win);
  11. int clrtobot(void);
  12. int wclrtobot(WINDOW *win);
  13. int clrtoeol(void);
  14. int wclrtoeol(WINDOW *win);
  15. ### Description
  16. erase() and werase() copy blanks (i.e. the background chtype) to
  17. every cell of the window.
  18. clear() and wclear() are similar to erase() and werase(), but they
  19. also call clearok() to ensure that the the window is cleared on the
  20. next wrefresh().
  21. clrtobot() and wclrtobot() clear the window from the current cursor
  22. position to the end of the window.
  23. clrtoeol() and wclrtoeol() clear the window from the current cursor
  24. position to the end of the current line.
  25. ### Return Value
  26. All functions return OK on success and ERR on error.
  27. ### Portability
  28. X/Open ncurses NetBSD
  29. clear Y Y Y
  30. wclear Y Y Y
  31. erase Y Y Y
  32. werase Y Y Y
  33. clrtobot Y Y Y
  34. wclrtobot Y Y Y
  35. clrtoeol Y Y Y
  36. wclrtoeol Y Y Y
  37. **man-end****************************************************************/
  38. int wclrtoeol(WINDOW *win)
  39. {
  40. int x, y, minx;
  41. chtype blank, *ptr;
  42. PDC_LOG(("wclrtoeol() - called: Row: %d Col: %d\n",
  43. win->_cury, win->_curx));
  44. if (!win)
  45. return ERR;
  46. y = win->_cury;
  47. x = win->_curx;
  48. /* wrs (4/10/93) account for window background */
  49. blank = win->_bkgd;
  50. for (minx = x, ptr = &win->_y[y][x]; minx < win->_maxx; minx++, ptr++)
  51. *ptr = blank;
  52. if (x < win->_firstch[y] || win->_firstch[y] == _NO_CHANGE)
  53. win->_firstch[y] = x;
  54. win->_lastch[y] = win->_maxx - 1;
  55. PDC_sync(win);
  56. return OK;
  57. }
  58. int clrtoeol(void)
  59. {
  60. PDC_LOG(("clrtoeol() - called\n"));
  61. return wclrtoeol(stdscr);
  62. }
  63. int wclrtobot(WINDOW *win)
  64. {
  65. int savey, savex;
  66. PDC_LOG(("wclrtobot() - called\n"));
  67. if (!win)
  68. return ERR;
  69. savey = win->_cury;
  70. savex = win->_curx;
  71. /* should this involve scrolling region somehow ? */
  72. if (win->_cury + 1 < win->_maxy)
  73. {
  74. win->_curx = 0;
  75. win->_cury++;
  76. for (; win->_maxy > win->_cury; win->_cury++)
  77. wclrtoeol(win);
  78. win->_cury = savey;
  79. win->_curx = savex;
  80. }
  81. wclrtoeol(win);
  82. PDC_sync(win);
  83. return OK;
  84. }
  85. int clrtobot(void)
  86. {
  87. PDC_LOG(("clrtobot() - called\n"));
  88. return wclrtobot(stdscr);
  89. }
  90. int werase(WINDOW *win)
  91. {
  92. PDC_LOG(("werase() - called\n"));
  93. if (wmove(win, 0, 0) == ERR)
  94. return ERR;
  95. return wclrtobot(win);
  96. }
  97. int erase(void)
  98. {
  99. PDC_LOG(("erase() - called\n"));
  100. return werase(stdscr);
  101. }
  102. int wclear(WINDOW *win)
  103. {
  104. PDC_LOG(("wclear() - called\n"));
  105. if (!win)
  106. return ERR;
  107. win->_clear = TRUE;
  108. return werase(win);
  109. }
  110. int clear(void)
  111. {
  112. PDC_LOG(("clear() - called\n"));
  113. return wclear(stdscr);
  114. }