]> ncurses.scripts.mit.edu Git - ncurses.git/blob - menu/m_item_val.c
ncurses 4.1
[ncurses.git] / menu / m_item_val.c
1 /*-----------------------------------------------------------------------------+
2 |           The ncurses menu library is  Copyright (C) 1995-1997               |
3 |             by Juergen Pfeifer <Juergen.Pfeifer@T-Online.de>                 |
4 |                          All Rights Reserved.                                |
5 |                                                                              |
6 | Permission to use, copy, modify, and distribute this software and its        |
7 | documentation for any purpose and without fee is hereby granted, provided    |
8 | that the above copyright notice appear in all copies and that both that      |
9 | copyright notice and this permission notice appear in supporting             |
10 | documentation, and that the name of the above listed copyright holder(s) not |
11 | be used in advertising or publicity pertaining to distribution of the        |
12 | software without specific, written prior permission.                         | 
13 |                                                                              |
14 | THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO  |
15 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-  |
16 | NESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR   |
17 | ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RE- |
18 | SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
19 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH    |
20 | THE USE OR PERFORMANCE OF THIS SOFTWARE.                                     |
21 +-----------------------------------------------------------------------------*/
22
23 /***************************************************************************
24 * Module menu_item_val                                                     *
25 * Set and get menus item values                                            *
26 ***************************************************************************/
27
28 #include "menu.priv.h"
29
30 MODULE_ID("$Id: m_item_val.c,v 1.4 1997/05/01 16:47:26 juergen Exp $")
31
32 /*---------------------------------------------------------------------------
33 |   Facility      :  libnmenu  
34 |   Function      :  int set_item_value(ITEM *item, int value)
35 |   
36 |   Description   :  Programmatically set the items selection value. This is
37 |                    only allowed if the item is selectable at all and if
38 |                    it is not connected to a single-valued menu.
39 |                    If the item is connected to a posted menu, the menu
40 |                    will be redisplayed.  
41 |
42 |   Return Values :  E_OK              - success
43 |                    E_REQUEST_DENIED  - not selectable or single valued menu
44 +--------------------------------------------------------------------------*/
45 int set_item_value(ITEM *item, bool value)
46 {
47   MENU *menu;
48   
49   if (item)
50     {
51       menu = item->imenu;
52       
53       if ((!(item->opt & O_SELECTABLE)) ||
54           (menu && (menu->opt & O_ONEVALUE))) 
55         RETURN(E_REQUEST_DENIED);
56       
57       if (item->value ^ value)
58         {
59           item->value = value ? TRUE : FALSE;
60           if (menu)
61             {
62               if (menu->status & _POSTED)
63                 {
64                   Move_And_Post_Item(menu,item);
65                   _nc_Show_Menu(menu);
66                 }
67             }
68         }
69     }
70   else
71     _nc_Default_Item.value = value;
72   
73   RETURN(E_OK);
74 }
75
76 /*---------------------------------------------------------------------------
77 |   Facility      :  libnmenu  
78 |   Function      :  bool item_value(const ITEM *item)
79 |   
80 |   Description   :  Return the selection value of the item
81 |
82 |   Return Values :  TRUE   - if item is selected
83 |                    FALSE  - if item is not selected
84 +--------------------------------------------------------------------------*/
85 bool item_value(const ITEM *item)
86 {
87   return ((Normalize_Item(item)->value) ? TRUE : FALSE);
88 }
89
90 /* m_item_val.c ends here */