getyx.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* PDCurses */
  2. #include <curspriv.h>
  3. /*man-start**************************************************************
  4. getyx
  5. -----
  6. ### Synopsis
  7. void getyx(WINDOW *win, int y, int x);
  8. void getparyx(WINDOW *win, int y, int x);
  9. void getbegyx(WINDOW *win, int y, int x);
  10. void getmaxyx(WINDOW *win, int y, int x);
  11. void getsyx(int y, int x);
  12. void setsyx(int y, int x);
  13. int getbegy(WINDOW *win);
  14. int getbegx(WINDOW *win);
  15. int getcury(WINDOW *win);
  16. int getcurx(WINDOW *win);
  17. int getpary(WINDOW *win);
  18. int getparx(WINDOW *win);
  19. int getmaxy(WINDOW *win);
  20. int getmaxx(WINDOW *win);
  21. ### Description
  22. The getyx() macro (defined in curses.h -- the prototypes here are
  23. merely illustrative) puts the current cursor position of the
  24. specified window into y and x. getbegyx() and getmaxyx() return the
  25. starting coordinates and size of the specified window, respectively.
  26. getparyx() returns the starting coordinates of the parent's window,
  27. if the specified window is a subwindow; otherwise it sets y and x to
  28. -1. These are all macros.
  29. getsyx() gets the coordinates of the virtual screen cursor, and
  30. stores them in y and x. If leaveok() is TRUE, it returns -1, -1. If
  31. lines have been removed with ripoffline(), then getsyx() includes
  32. these lines in its count; so, the returned y and x values should only
  33. be used with setsyx().
  34. setsyx() sets the virtual screen cursor to the y, x coordinates. If
  35. either y or x is -1, leaveok() is set TRUE, else it's set FALSE.
  36. getsyx() and setsyx() are meant to be used by a library routine that
  37. manipulates curses windows without altering the position of the
  38. cursor. Note that getsyx() is defined only as a macro.
  39. getbegy(), getbegx(), getcurx(), getcury(), getmaxy(), getmaxx(),
  40. getpary(), and getparx() return the appropriate coordinate or size
  41. values, or ERR in the case of a NULL window.
  42. ### Portability
  43. X/Open ncurses NetBSD
  44. getyx Y Y Y
  45. getparyx Y Y Y
  46. getbegyx Y Y Y
  47. getmaxyx Y Y Y
  48. getsyx - Y Y
  49. setsyx - Y Y
  50. getbegy - Y Y
  51. getbegx - Y Y
  52. getcury - Y Y
  53. getcurx - Y Y
  54. getpary - Y Y
  55. getparx - Y Y
  56. getmaxy - Y Y
  57. getmaxx - Y Y
  58. **man-end****************************************************************/
  59. int getbegy(WINDOW *win)
  60. {
  61. PDC_LOG(("getbegy() - called\n"));
  62. return win ? win->_begy : ERR;
  63. }
  64. int getbegx(WINDOW *win)
  65. {
  66. PDC_LOG(("getbegx() - called\n"));
  67. return win ? win->_begx : ERR;
  68. }
  69. int getcury(WINDOW *win)
  70. {
  71. PDC_LOG(("getcury() - called\n"));
  72. return win ? win->_cury : ERR;
  73. }
  74. int getcurx(WINDOW *win)
  75. {
  76. PDC_LOG(("getcurx() - called\n"));
  77. return win ? win->_curx : ERR;
  78. }
  79. int getpary(WINDOW *win)
  80. {
  81. PDC_LOG(("getpary() - called\n"));
  82. return win ? win->_pary : ERR;
  83. }
  84. int getparx(WINDOW *win)
  85. {
  86. PDC_LOG(("getparx() - called\n"));
  87. return win ? win->_parx : ERR;
  88. }
  89. int getmaxy(WINDOW *win)
  90. {
  91. PDC_LOG(("getmaxy() - called\n"));
  92. return win ? win->_maxy : ERR;
  93. }
  94. int getmaxx(WINDOW *win)
  95. {
  96. PDC_LOG(("getmaxx() - called\n"));
  97. return win ? win->_maxx : ERR;
  98. }
  99. void setsyx(int y, int x)
  100. {
  101. PDC_LOG(("setsyx() - called\n"));
  102. if (curscr)
  103. {
  104. curscr->_leaveit = y == -1 || x == -1;
  105. if (!curscr->_leaveit)
  106. wmove(curscr, y, x);
  107. }
  108. }