1/* $OpenBSD: m_win.c,v 1.8 2023/10/17 09:52:10 nicm Exp $ */ 2 3/**************************************************************************** 4 * Copyright 2020,2021 Thomas E. Dickey * 5 * Copyright 1998-2009,2010 Free Software Foundation, Inc. * 6 * * 7 * Permission is hereby granted, free of charge, to any person obtaining a * 8 * copy of this software and associated documentation files (the * 9 * "Software"), to deal in the Software without restriction, including * 10 * without limitation the rights to use, copy, modify, merge, publish, * 11 * distribute, distribute with modifications, sublicense, and/or sell * 12 * copies of the Software, and to permit persons to whom the Software is * 13 * furnished to do so, subject to the following conditions: * 14 * * 15 * The above copyright notice and this permission notice shall be included * 16 * in all copies or substantial portions of the Software. * 17 * * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 21 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 24 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 25 * * 26 * Except as contained in this notice, the name(s) of the above copyright * 27 * holders shall not be used in advertising or otherwise to promote the * 28 * sale, use or other dealings in this Software without prior written * 29 * authorization. * 30 ****************************************************************************/ 31 32/**************************************************************************** 33 * Author: Juergen Pfeifer, 1995,1997 * 34 ****************************************************************************/ 35 36/*************************************************************************** 37* Module m_win * 38* Menus window association routines * 39***************************************************************************/ 40 41#include "menu.priv.h" 42 43MODULE_ID("$Id: m_win.c,v 1.8 2023/10/17 09:52:10 nicm Exp $") 44 45/*--------------------------------------------------------------------------- 46| Facility : libnmenu 47| Function : int set_menu_win(MENU *menu, WINDOW *win) 48| 49| Description : Sets the window of the menu. 50| 51| Return Values : E_OK - success 52| E_POSTED - menu is already posted 53+--------------------------------------------------------------------------*/ 54MENU_EXPORT(int) 55set_menu_win(MENU *menu, WINDOW *win) 56{ 57 T((T_CALLED("set_menu_win(%p,%p)"), (void *)menu, (void *)win)); 58 59 if (menu) 60 { 61 if (menu->status & _POSTED) 62 RETURN(E_POSTED); 63 else 64#if NCURSES_SP_FUNCS 65 { 66 /* We ensure that userwin is never null. So even if a null 67 WINDOW parameter is passed, we store the SCREENS stdscr. 68 The only MENU that can have a null userwin is the static 69 _nc_default_Menu. 70 */ 71 SCREEN *sp = _nc_screen_of(menu->userwin); 72 73 menu->userwin = win ? win : sp->_stdscr; 74 _nc_Calculate_Item_Length_and_Width(menu); 75 } 76#else 77 menu->userwin = win; 78#endif 79 } 80 else 81 _nc_Default_Menu.userwin = win; 82 83 RETURN(E_OK); 84} 85 86/*--------------------------------------------------------------------------- 87| Facility : libnmenu 88| Function : WINDOW* menu_win(const MENU*) 89| 90| Description : Returns pointer to the window of the menu 91| 92| Return Values : NULL on error, otherwise pointer to window 93+--------------------------------------------------------------------------*/ 94MENU_EXPORT(WINDOW *) 95menu_win(const MENU *menu) 96{ 97 const MENU *m = Normalize_Menu(menu); 98 99 T((T_CALLED("menu_win(%p)"), (const void *)menu)); 100 returnWin(Get_Menu_UserWin(m)); 101} 102 103/* m_win.c ends here */ 104