1 /* $OpenBSD: m_opts.c,v 1.3 1997/12/03 05:31:24 millert Exp $ */ 2 3 /*-----------------------------------------------------------------------------+ 4 | The ncurses menu library is Copyright (C) 1995-1997 | 5 | by Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> | 6 | All Rights Reserved. | 7 | | 8 | Permission to use, copy, modify, and distribute this software and its | 9 | documentation for any purpose and without fee is hereby granted, provided | 10 | that the above copyright notice appear in all copies and that both that | 11 | copyright notice and this permission notice appear in supporting | 12 | documentation, and that the name of the above listed copyright holder(s) not | 13 | be used in advertising or publicity pertaining to distribution of the | 14 | software without specific, written prior permission. | 15 | | 16 | THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO | 17 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- | 18 | NESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR | 19 | ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RE- | 20 | SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | 21 | NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH | 22 | THE USE OR PERFORMANCE OF THIS SOFTWARE. | 23 +-----------------------------------------------------------------------------*/ 24 25 /*************************************************************************** 26 * Module m_opts * 27 * Menus option routines * 28 ***************************************************************************/ 29 30 #include "menu.priv.h" 31 32 MODULE_ID("Id: m_opts.c,v 1.7 1997/10/21 08:44:31 juergen Exp $") 33 34 /*--------------------------------------------------------------------------- 35 | Facility : libnmenu 36 | Function : int set_menu_opts(MENU *menu, Menu_Options opts) 37 | 38 | Description : Set the options for this menu. If the new settings 39 | end up in a change of the geometry of the menu, it 40 | will be recalculated. This operation is forbidden if 41 | the menu is already posted. 42 | 43 | Return Values : E_OK - success 44 | E_BAD_ARGUMENT - invalid menu options 45 | E_POSTED - menu is already posted 46 +--------------------------------------------------------------------------*/ 47 int set_menu_opts(MENU * menu, Menu_Options opts) 48 { 49 if (opts & ~ALL_MENU_OPTS) 50 RETURN(E_BAD_ARGUMENT); 51 52 if (menu) 53 { 54 if ( menu->status & _POSTED ) 55 RETURN(E_POSTED); 56 57 if ( (opts&O_ROWMAJOR) != (menu->opt&O_ROWMAJOR)) 58 { 59 /* we need this only if the layout really changed ... */ 60 if (menu->items && menu->items[0]) 61 { 62 menu->toprow = 0; 63 menu->curitem = menu->items[0]; 64 assert(menu->curitem); 65 set_menu_format( menu, menu->frows, menu->fcols ); 66 } 67 } 68 69 menu->opt = opts; 70 71 if (opts & O_ONEVALUE) 72 { 73 ITEM **item; 74 75 if ( ((item=menu->items) != (ITEM**)0) ) 76 for(;*item;item++) 77 (*item)->value = FALSE; 78 } 79 80 if (opts & O_SHOWDESC) /* this also changes the geometry */ 81 _nc_Calculate_Item_Length_and_Width( menu ); 82 } 83 else 84 _nc_Default_Menu.opt = opts; 85 86 RETURN(E_OK); 87 } 88 89 /*--------------------------------------------------------------------------- 90 | Facility : libnmenu 91 | Function : int menu_opts_off(MENU *menu, Menu_Options opts) 92 | 93 | Description : Switch off the options for this menu. If the new settings 94 | end up in a change of the geometry of the menu, it 95 | will be recalculated. This operation is forbidden if 96 | the menu is already posted. 97 | 98 | Return Values : E_OK - success 99 | E_BAD_ARGUMENT - invalid options 100 | E_POSTED - menu is already posted 101 +--------------------------------------------------------------------------*/ 102 int menu_opts_off(MENU *menu, Menu_Options opts) 103 { 104 MENU *cmenu = menu; /* use a copy because set_menu_opts must detect 105 NULL menu itself to adjust its behaviour */ 106 107 if (opts & ~ALL_MENU_OPTS) 108 RETURN(E_BAD_ARGUMENT); 109 else 110 { 111 Normalize_Menu(cmenu); 112 opts = cmenu->opt & ~opts; 113 return set_menu_opts( menu, opts ); 114 } 115 } 116 117 /*--------------------------------------------------------------------------- 118 | Facility : libnmenu 119 | Function : int menu_opts_on(MENU *menu, Menu_Options opts) 120 | 121 | Description : Switch on the options for this menu. If the new settings 122 | end up in a change of the geometry of the menu, it 123 | will be recalculated. This operation is forbidden if 124 | the menu is already posted. 125 | 126 | Return Values : E_OK - success 127 | E_BAD_ARGUMENT - invalid menu options 128 | E_POSTED - menu is already posted 129 +--------------------------------------------------------------------------*/ 130 int menu_opts_on(MENU * menu, Menu_Options opts) 131 { 132 MENU *cmenu = menu; /* use a copy because set_menu_opts must detect 133 NULL menu itself to adjust its behaviour */ 134 135 if (opts & ~ALL_MENU_OPTS) 136 RETURN(E_BAD_ARGUMENT); 137 else 138 { 139 Normalize_Menu(cmenu); 140 opts = cmenu->opt | opts; 141 return set_menu_opts(menu, opts); 142 } 143 } 144 145 /*--------------------------------------------------------------------------- 146 | Facility : libnmenu 147 | Function : Menu_Options menu_opts(const MENU *menu) 148 | 149 | Description : Return the options for this menu. 150 | 151 | Return Values : Menu options 152 +--------------------------------------------------------------------------*/ 153 Menu_Options menu_opts(const MENU *menu) 154 { 155 return (ALL_MENU_OPTS & Normalize_Menu( menu )->opt); 156 } 157 158 /* m_opts.c ends here */ 159