m_cursor.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /***************************************************************************
  32. * Module m_cursor *
  33. * Correctly position a menu's cursor *
  34. ***************************************************************************/
  35. #include "menu.priv.h"
  36. MODULE_ID("$Id: m_cursor.c,v 1.20 2005/10/22 23:03:32 tom Exp $")
  37. /*---------------------------------------------------------------------------
  38. | Facility : libnmenu
  39. | Function : _nc_menu_cursor_pos
  40. |
  41. | Description : Return position of logical cursor to current item
  42. |
  43. | Return Values : E_OK - success
  44. | E_BAD_ARGUMENT - invalid menu
  45. | E_NOT_POSTED - Menu is not posted
  46. +--------------------------------------------------------------------------*/
  47. NCURSES_EXPORT(int)
  48. _nc_menu_cursor_pos(const MENU * menu, const ITEM * item, int *pY, int *pX)
  49. {
  50. if (!menu || !pX || !pY)
  51. return (E_BAD_ARGUMENT);
  52. else
  53. {
  54. if ((ITEM *) 0 == item)
  55. item = menu->curitem;
  56. assert(item != (ITEM *) 0);
  57. if (!(menu->status & _POSTED))
  58. return (E_NOT_POSTED);
  59. *pX = item->x * (menu->spc_cols + menu->itemlen);
  60. *pY = (item->y - menu->toprow) * menu->spc_rows;
  61. }
  62. return (E_OK);
  63. }
  64. /*---------------------------------------------------------------------------
  65. | Facility : libnmenu
  66. | Function : pos_menu_cursor
  67. |
  68. | Description : Position logical cursor to current item in menu
  69. |
  70. | Return Values : E_OK - success
  71. | E_BAD_ARGUMENT - invalid menu
  72. | E_NOT_POSTED - Menu is not posted
  73. +--------------------------------------------------------------------------*/
  74. NCURSES_EXPORT(int)
  75. pos_menu_cursor(const MENU * menu)
  76. {
  77. WINDOW *win, *sub;
  78. int x = 0, y = 0;
  79. int err = _nc_menu_cursor_pos(menu, (ITEM *) 0, &y, &x);
  80. T((T_CALLED("pos_menu_cursor(%p)"), menu));
  81. if (E_OK == err)
  82. {
  83. win = menu->userwin ? menu->userwin : stdscr;
  84. sub = menu->usersub ? menu->usersub : win;
  85. assert(win && sub);
  86. if ((menu->opt & O_SHOWMATCH) && (menu->pindex > 0))
  87. x += (menu->pindex + menu->marklen - 1);
  88. wmove(sub, y, x);
  89. if (win != sub)
  90. {
  91. wcursyncup(sub);
  92. wsyncup(sub);
  93. untouchwin(sub);
  94. }
  95. }
  96. RETURN(err);
  97. }
  98. /* m_cursor.c ends here */