1 /*-----------------------------------------------------------------------------+
2 | The ncurses menu library is Copyright (C) 1995-1997 |
3 | by Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> |
4 | All Rights Reserved. |
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. |
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 +-----------------------------------------------------------------------------*/
23 /***************************************************************************
25 * Menus option routines *
26 ***************************************************************************/
28 #include "menu.priv.h"
30 MODULE_ID("$Id: m_opts.c,v 1.6 1997/05/01 16:47:26 juergen Exp $")
32 /*---------------------------------------------------------------------------
34 | Function : int set_menu_opts(MENU *menu, Menu_Options opts)
36 | Description : Set the options for this menu. If the new settings
37 | end up in a change of the geometry of the menu, it
38 | will be recalculated. This operation is forbidden if
39 | the menu is already posted.
41 | Return Values : E_OK - success
42 | E_BAD_ARGUMENT - invalid menu options
43 | E_POSTED - menu is already posted
44 +--------------------------------------------------------------------------*/
45 int set_menu_opts(MENU * menu, Menu_Options opts)
47 if (opts & ~ALL_MENU_OPTS)
48 RETURN(E_BAD_ARGUMENT);
52 if ( menu->status & _POSTED )
55 if ( (opts&O_ROWMAJOR) != (menu->opt&O_ROWMAJOR))
57 /* we need this only if the layout really changed ... */
58 if (menu->items && menu->items[0])
61 menu->curitem = menu->items[0];
62 assert(menu->curitem);
63 set_menu_format( menu, menu->frows, menu->fcols );
69 if (opts & O_ONEVALUE)
73 if ( ((item=menu->items) != (ITEM**)0) )
75 (*item)->value = FALSE;
78 if (opts & O_SHOWDESC) /* this also changes the geometry */
79 _nc_Calculate_Item_Length_and_Width( menu );
82 _nc_Default_Menu.opt = opts;
87 /*---------------------------------------------------------------------------
89 | Function : int menu_opts_off(MENU *menu, Menu_Options opts)
91 | Description : Switch off the options for this menu. If the new settings
92 | end up in a change of the geometry of the menu, it
93 | will be recalculated. This operation is forbidden if
94 | the menu is already posted.
96 | Return Values : E_OK - success
97 | E_BAD_ARGUMENT - invalid options
98 | E_POSTED - menu is already posted
99 +--------------------------------------------------------------------------*/
100 int menu_opts_off(MENU *menu, Menu_Options opts)
102 MENU *cmenu = menu; /* use a copy because set_menu_opts must detect
103 NULL menu itself to adjust its behaviour */
105 if (opts & ~ALL_MENU_OPTS)
106 RETURN(E_BAD_ARGUMENT);
109 Normalize_Menu(cmenu);
110 opts = cmenu->opt & ~opts;
111 return set_menu_opts( menu, opts );
115 /*---------------------------------------------------------------------------
116 | Facility : libnmenu
117 | Function : int menu_opts_on(MENU *menu, Menu_Options opts)
119 | Description : Switch on the options for this menu. If the new settings
120 | end up in a change of the geometry of the menu, it
121 | will be recalculated. This operation is forbidden if
122 | the menu is already posted.
124 | Return Values : E_OK - success
125 | E_BAD_ARGUMENT - invalid menu options
126 | E_POSTED - menu is already posted
127 +--------------------------------------------------------------------------*/
128 int menu_opts_on(MENU * menu, Menu_Options opts)
130 MENU *cmenu = menu; /* use a copy because set_menu_opts must detect
131 NULL menu itself to adjust its behaviour */
133 if (opts & ~ALL_MENU_OPTS)
134 RETURN(E_BAD_ARGUMENT);
137 Normalize_Menu(cmenu);
138 opts = cmenu->opt | opts;
139 return set_menu_opts(menu, opts);
143 /*---------------------------------------------------------------------------
144 | Facility : libnmenu
145 | Function : Menu_Options menu_opts(const MENU *menu)
147 | Description : Return the options for this menu.
149 | Return Values : Menu options
150 +--------------------------------------------------------------------------*/
151 Menu_Options menu_opts(const MENU *menu)
153 return (ALL_MENU_OPTS & Normalize_Menu( menu )->opt);
156 /* m_opts.c ends here */