home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ncurses-1.9.9e-src.tgz / tar.out / fsf / ncurses / menu / m_cursor.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  3KB  |  77 lines

  1.  
  2. /***************************************************************************
  3. *                            COPYRIGHT NOTICE                              *
  4. ****************************************************************************
  5. *                ncurses is copyright (C) 1992-1995                        *
  6. *                          Zeyd M. Ben-Halim                               *
  7. *                          zmbenhal@netcom.com                             *
  8. *                          Eric S. Raymond                                 *
  9. *                          esr@snark.thyrsus.com                           *
  10. *                                                                          *
  11. *        Permission is hereby granted to reproduce and distribute ncurses  *
  12. *        by any means and for any fee, whether alone or as part of a       *
  13. *        larger distribution, in source or in binary form, PROVIDED        *
  14. *        this notice is included with any such distribution, and is not    *
  15. *        removed from any of its header files. Mention of ncurses in any   *
  16. *        applications linked with it is highly appreciated.                *
  17. *                                                                          *
  18. *        ncurses comes AS IS with no warranty, implied or expressed.       *
  19. *                                                                          *
  20. ***************************************************************************/
  21.  
  22. /***************************************************************************
  23. * Module menu_cursor                                                       *
  24. * Correctly position a menus cursor                                        *
  25. ***************************************************************************/
  26.  
  27. #include "menu.priv.h"
  28.  
  29. /*---------------------------------------------------------------------------
  30. |   Facility      :  libnmenu  
  31. |   Function      :  pos_menu_cursor  
  32. |   
  33. |   Description   :  Position logical cursor to current item in menu
  34. |
  35. |   Return Values :  E_OK            - success
  36. |                    E_BAD_ARGUMENT  - invalid menu
  37. |                    E_NOT_POSTED    - Menu is not posted
  38. +--------------------------------------------------------------------------*/
  39. int pos_menu_cursor(const MENU * menu)
  40. {
  41.   if (!menu)
  42.     RETURN(E_BAD_ARGUMENT);
  43.   else
  44.     {
  45.       ITEM *item;
  46.       int x, y;
  47.       WINDOW *win, *sub;
  48.       
  49.       if ( !( menu->status & _POSTED ) )
  50.     RETURN(E_NOT_POSTED);
  51.       
  52.       item = menu->curitem;
  53.       assert(item);
  54.       
  55.       x = item->x * (1 + menu->itemlen);
  56.       y = item->y - menu->toprow;
  57.       win = menu->userwin ? menu->userwin : stdscr;
  58.       sub = menu->usersub ? menu->usersub : win;
  59.       assert(win && sub);
  60.       
  61.       if ((menu->opt & O_SHOWMATCH) && (menu->pindex > 0))
  62.     x += ( menu->pindex + menu->marklen - 1);
  63.       
  64.       wmove(sub,y,x);
  65.       
  66.       if ( win != sub )
  67.     {
  68.       wcursyncup(sub);
  69.       wsyncup(sub);
  70.       untouchwin(sub);
  71.     } 
  72.     }
  73.   RETURN(E_OK);
  74. }
  75.  
  76. /* m_cursor.c ends here */
  77.