]> ncurses.scripts.mit.edu Git - ncurses.git/blob - menu/m_opts.c
ncurses 4.1
[ncurses.git] / menu / m_opts.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_opts                                                         *
25 * Menus option routines                                                    *
26 ***************************************************************************/
27
28 #include "menu.priv.h"
29
30 MODULE_ID("$Id: m_opts.c,v 1.6 1997/05/01 16:47:26 juergen Exp $")
31
32 /*---------------------------------------------------------------------------
33 |   Facility      :  libnmenu
34 |   Function      :  int set_menu_opts(MENU *menu, Menu_Options opts)
35 |
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.
40 |
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)
46 {
47   if (opts & ~ALL_MENU_OPTS)
48     RETURN(E_BAD_ARGUMENT);
49
50   if (menu)
51     {
52       if ( menu->status & _POSTED )
53         RETURN(E_POSTED);
54
55       if ( (opts&O_ROWMAJOR) != (menu->opt&O_ROWMAJOR))
56         {
57           /* we need this only if the layout really changed ... */
58           if (menu->items && menu->items[0])
59             {
60               menu->toprow  = 0;
61               menu->curitem = menu->items[0];
62               assert(menu->curitem);
63               set_menu_format( menu, menu->frows, menu->fcols );
64             }
65         }
66
67       menu->opt = opts;
68
69       if (opts & O_ONEVALUE)
70         {
71           ITEM **item;
72
73           if ( ((item=menu->items) != (ITEM**)0) )
74             for(;*item;item++)
75               (*item)->value = FALSE;
76         }
77
78       if (opts & O_SHOWDESC)    /* this also changes the geometry */
79         _nc_Calculate_Item_Length_and_Width( menu );
80     }
81   else
82     _nc_Default_Menu.opt = opts;
83
84   RETURN(E_OK);
85 }
86
87 /*---------------------------------------------------------------------------
88 |   Facility      :  libnmenu
89 |   Function      :  int menu_opts_off(MENU *menu, Menu_Options opts)
90 |
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.
95 |
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)
101 {
102   MENU *cmenu = menu; /* use a copy because set_menu_opts must detect
103                          NULL menu itself to adjust its behaviour */
104
105   if (opts & ~ALL_MENU_OPTS)
106     RETURN(E_BAD_ARGUMENT);
107   else
108     {
109       Normalize_Menu(cmenu);
110       opts = cmenu->opt & ~opts;
111       return set_menu_opts( menu, opts );
112     }
113 }
114
115 /*---------------------------------------------------------------------------
116 |   Facility      :  libnmenu
117 |   Function      :  int menu_opts_on(MENU *menu, Menu_Options opts)
118 |
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.
123 |
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)
129 {
130   MENU *cmenu = menu; /* use a copy because set_menu_opts must detect
131                          NULL menu itself to adjust its behaviour */
132
133   if (opts & ~ALL_MENU_OPTS)
134     RETURN(E_BAD_ARGUMENT);
135   else
136     {
137       Normalize_Menu(cmenu);
138       opts = cmenu->opt | opts;
139       return set_menu_opts(menu, opts);
140     }
141 }
142
143 /*---------------------------------------------------------------------------
144 |   Facility      :  libnmenu
145 |   Function      :  Menu_Options menu_opts(const MENU *menu)
146 |
147 |   Description   :  Return the options for this menu.
148 |
149 |   Return Values :  Menu options
150 +--------------------------------------------------------------------------*/
151 Menu_Options menu_opts(const MENU *menu)
152 {
153   return (ALL_MENU_OPTS & Normalize_Menu( menu )->opt);
154 }
155
156 /* m_opts.c ends here */