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_opt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-28  |  4.8 KB  |  131 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_opt                                                    *
  24. * Menus item option routines                                               *
  25. ***************************************************************************/
  26.  
  27. #include "menu.priv.h"
  28.  
  29. /*---------------------------------------------------------------------------
  30. |   Facility      :  libnmenu  
  31. |   Function      :  int set_item_opts(ITEM *item, Item_Options opts)  
  32. |   
  33. |   Description   :  Set the options of the item. If there are relevant
  34. |                    changes, the item is connected and the menu is posted,
  35. |                    the menu will be redisplayed.
  36. |
  37. |   Return Values :  E_OK            - success
  38. |                    E_BAD_ARGUMENT  - invalid item options
  39. +--------------------------------------------------------------------------*/
  40. int set_item_opts(ITEM *item, Item_Options opts)
  41.   if (opts & ~ALL_ITEM_OPTS)
  42.     RETURN(E_BAD_ARGUMENT);
  43.   
  44.   if (item)
  45.     {
  46.       if (item->opt != opts)
  47.     {        
  48.       MENU *menu = item->imenu;
  49.       
  50.       item->opt = opts;
  51.       
  52.       if ((!(opts & O_SELECTABLE)) && item->value)
  53.         item->value = FALSE;
  54.       
  55.       if (menu && (menu->status & _POSTED))
  56.         {
  57.           Move_And_Post_Item( menu, item );
  58.           _nc_Show_Menu(menu);
  59.         }
  60.     }
  61.     }
  62.   else
  63.     _nc_Default_Item.opt = opts;
  64.   
  65.   RETURN(E_OK);
  66. }
  67.  
  68. /*---------------------------------------------------------------------------
  69. |   Facility      :  libnmenu  
  70. |   Function      :  int item_opts_off(ITEM *item, Item_Options opts)   
  71. |   
  72. |   Description   :  Switch of the options for this item.
  73. |
  74. |   Return Values :  E_OK            - success
  75. |                    E_BAD_ARGUMENT  - invalid options
  76. +--------------------------------------------------------------------------*/
  77. int item_opts_off(ITEM *item, Item_Options  opts)
  78.   ITEM *citem = item; /* use a copy because set_item_opts must detect
  79.                          NULL item itself to adjust its behaviour */
  80.  
  81.   if (opts & ~ALL_ITEM_OPTS)
  82.     RETURN(E_BAD_ARGUMENT);
  83.   else
  84.     {
  85.       Normalize_Item(citem);
  86.       opts = citem->opt & ~opts;
  87.       return set_item_opts( item, opts );
  88.     }
  89. }
  90.  
  91. /*---------------------------------------------------------------------------
  92. |   Facility      :  libnmenu  
  93. |   Function      :  int item_opts_on(ITEM *item, Item_Options opts)   
  94. |   
  95. |   Description   :  Switch on the options for this item.
  96. |
  97. |   Return Values :  E_OK            - success
  98. |                    E_BAD_ARGUMENT  - invalid options
  99. +--------------------------------------------------------------------------*/
  100. int item_opts_on(ITEM *item, Item_Options opts)
  101. {
  102.   ITEM *citem = item; /* use a copy because set_item_opts must detect
  103.                          NULL item itself to adjust its behaviour */
  104.   
  105.   if (opts & ~ALL_ITEM_OPTS)
  106.     RETURN(E_BAD_ARGUMENT);
  107.   else
  108.     {
  109.       Normalize_Item(citem);
  110.       opts = citem->opt | opts;
  111.       return set_item_opts( item, opts );
  112.     }
  113. }
  114.  
  115. /*---------------------------------------------------------------------------
  116. |   Facility      :  libnmenu  
  117. |   Function      :  Item_Options item_opts(const ITEM *item)   
  118. |   
  119. |   Description   :  Switch of the options for this item.
  120. |
  121. |   Return Values :  Items options
  122. +--------------------------------------------------------------------------*/
  123. Item_Options item_opts(const ITEM * item)
  124. {
  125.   return (ALL_ITEM_OPTS & Normalize_Item(item)->opt);
  126. }
  127.  
  128. /* m_item_opt.c ends here */
  129.