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