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_item_val.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-28  |  3.5 KB  |  88 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_item_val                                                     *
  24. * Set and get menus item values                                            *
  25. ***************************************************************************/
  26.  
  27. #include "menu.priv.h"
  28.  
  29. /*---------------------------------------------------------------------------
  30. |   Facility      :  libnmenu  
  31. |   Function      :  int set_item_value(ITEM *item, int value)
  32. |   
  33. |   Description   :  Programmatically set the items selection value. This is
  34. |                    only allowed if the item is selectable at all and if
  35. |                    it is not connected to a single-valued menu.
  36. |                    If the item is connected to a posted menu, the menu
  37. |                    will be redisplayed.  
  38. |
  39. |   Return Values :  E_OK              - success
  40. |                    E_REQUEST_DENIED  - not selectable or single valued menu
  41. +--------------------------------------------------------------------------*/
  42. int set_item_value(ITEM *item, bool value)
  43. {
  44.   MENU *menu;
  45.   
  46.   if (item)
  47.     {
  48.       menu = item->imenu;
  49.       
  50.       if ((!(item->opt & O_SELECTABLE)) ||
  51.       (menu && (menu->opt & O_ONEVALUE))) 
  52.     RETURN(E_REQUEST_DENIED);
  53.       
  54.       if (item->value ^ value)
  55.     {
  56.       item->value = value ? TRUE : FALSE;
  57.       if (menu)
  58.         {
  59.           if (menu->status & _POSTED)
  60.         {
  61.           Move_And_Post_Item(menu,item);
  62.           _nc_Show_Menu(menu);
  63.         }
  64.         }
  65.     }
  66.     }
  67.   else
  68.     _nc_Default_Item.value = value;
  69.   
  70.   RETURN(E_OK);
  71. }
  72.  
  73. /*---------------------------------------------------------------------------
  74. |   Facility      :  libnmenu  
  75. |   Function      :  bool item_value(const ITEM *item)
  76. |   
  77. |   Description   :  Return the selection value of the item
  78. |
  79. |   Return Values :  TRUE   - if item is selected
  80. |                    FALSE  - if item is not selected
  81. +--------------------------------------------------------------------------*/
  82. bool item_value(const ITEM *item)
  83. {
  84.   return ((Normalize_Item(item)->value) ? TRUE : FALSE);
  85. }
  86.  
  87. /* m_item_val.c ends here */
  88.