]> ncurses.scripts.mit.edu Git - ncurses.git/blob - menu/m_item_opt.c
ncurses 5.3
[ncurses.git] / menu / m_item_opt.c
1 /****************************************************************************
2  * Copyright (c) 1998,2000 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 /****************************************************************************
30  *   Author:  Juergen Pfeifer, 1995,1997                                    *
31  *   Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en             *
32  ****************************************************************************/
33
34 /***************************************************************************
35 * Module m_item_opt                                                        *
36 * Menus item option routines                                               *
37 ***************************************************************************/
38
39 #include "menu.priv.h"
40
41 MODULE_ID("$Id: m_item_opt.c,v 1.12 2002/07/06 15:22:16 juergen Exp $")
42
43 /*---------------------------------------------------------------------------
44 |   Facility      :  libnmenu  
45 |   Function      :  int set_item_opts(ITEM *item, Item_Options opts)  
46 |   
47 |   Description   :  Set the options of the item. If there are relevant
48 |                    changes, the item is connected and the menu is posted,
49 |                    the menu will be redisplayed.
50 |
51 |   Return Values :  E_OK            - success
52 |                    E_BAD_ARGUMENT  - invalid item options
53 +--------------------------------------------------------------------------*/
54 NCURSES_EXPORT(int)
55 set_item_opts (ITEM *item, Item_Options opts)
56
57   opts &= ALL_ITEM_OPTS;
58
59   if (opts & ~ALL_ITEM_OPTS)
60     RETURN(E_BAD_ARGUMENT);
61   
62   if (item)
63     {
64       if (item->opt != opts)
65         {               
66           MENU *menu = item->imenu;
67           
68           item->opt = opts;
69           
70           if ((!(opts & O_SELECTABLE)) && item->value)
71             item->value = FALSE;
72           
73           if (menu && (menu->status & _POSTED))
74             {
75               Move_And_Post_Item( menu, item );
76               _nc_Show_Menu(menu);
77             }
78         }
79     }
80   else
81     _nc_Default_Item.opt = opts;
82   
83   RETURN(E_OK);
84 }
85
86 /*---------------------------------------------------------------------------
87 |   Facility      :  libnmenu  
88 |   Function      :  int item_opts_off(ITEM *item, Item_Options opts)   
89 |   
90 |   Description   :  Switch of the options for this item.
91 |
92 |   Return Values :  E_OK            - success
93 |                    E_BAD_ARGUMENT  - invalid options
94 +--------------------------------------------------------------------------*/
95 NCURSES_EXPORT(int)
96 item_opts_off (ITEM *item, Item_Options  opts)
97
98   ITEM *citem = item; /* use a copy because set_item_opts must detect
99                          NULL item itself to adjust its behaviour */
100
101   if (opts & ~ALL_ITEM_OPTS)
102     RETURN(E_BAD_ARGUMENT);
103   else
104     {
105       Normalize_Item(citem);    
106       opts = citem->opt & ~(opts & ALL_ITEM_OPTS);
107       return set_item_opts( item, opts );
108     }
109 }
110
111 /*---------------------------------------------------------------------------
112 |   Facility      :  libnmenu  
113 |   Function      :  int item_opts_on(ITEM *item, Item_Options opts)   
114 |   
115 |   Description   :  Switch on the options for this item.
116 |
117 |   Return Values :  E_OK            - success
118 |                    E_BAD_ARGUMENT  - invalid options
119 +--------------------------------------------------------------------------*/
120 NCURSES_EXPORT(int)
121 item_opts_on (ITEM *item, Item_Options opts)
122 {
123   ITEM *citem = item; /* use a copy because set_item_opts must detect
124                          NULL item itself to adjust its behaviour */
125   
126   opts &= ALL_ITEM_OPTS;
127   if (opts & ~ALL_ITEM_OPTS)
128     RETURN(E_BAD_ARGUMENT);
129   else
130     {
131       Normalize_Item(citem);
132       opts = citem->opt | opts;
133       return set_item_opts( item, opts );
134     }
135 }
136
137 /*---------------------------------------------------------------------------
138 |   Facility      :  libnmenu  
139 |   Function      :  Item_Options item_opts(const ITEM *item)   
140 |   
141 |   Description   :  Switch of the options for this item.
142 |
143 |   Return Values :  Items options
144 +--------------------------------------------------------------------------*/
145 NCURSES_EXPORT(Item_Options)
146 item_opts (const ITEM * item)
147 {
148   return (ALL_ITEM_OPTS & Normalize_Item(item)->opt);
149 }
150
151 /* m_item_opt.c ends here */