150276Speter/****************************************************************************
2262629Sdelphij * Copyright (c) 1998-2004,2010 Free Software Foundation, Inc.              *
350276Speter *                                                                          *
450276Speter * Permission is hereby granted, free of charge, to any person obtaining a  *
550276Speter * copy of this software and associated documentation files (the            *
650276Speter * "Software"), to deal in the Software without restriction, including      *
750276Speter * without limitation the rights to use, copy, modify, merge, publish,      *
850276Speter * distribute, distribute with modifications, sublicense, and/or sell       *
950276Speter * copies of the Software, and to permit persons to whom the Software is    *
1050276Speter * furnished to do so, subject to the following conditions:                 *
1150276Speter *                                                                          *
1250276Speter * The above copyright notice and this permission notice shall be included  *
1350276Speter * in all copies or substantial portions of the Software.                   *
1450276Speter *                                                                          *
1550276Speter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
1650276Speter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
1750276Speter * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
1850276Speter * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
1950276Speter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
2050276Speter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
2150276Speter * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2250276Speter *                                                                          *
2350276Speter * Except as contained in this notice, the name(s) of the above copyright   *
2450276Speter * holders shall not be used in advertising or otherwise to promote the     *
2550276Speter * sale, use or other dealings in this Software without prior written       *
2650276Speter * authorization.                                                           *
2750276Speter ****************************************************************************/
2850276Speter
2950276Speter/****************************************************************************
30166124Srafan *   Author:  Juergen Pfeifer, 1995,1997                                    *
3150276Speter ****************************************************************************/
3250276Speter
3350276Speter/***************************************************************************
3450276Speter* Module m_win                                                             *
3550276Speter* Menus window association routines                                        *
3650276Speter***************************************************************************/
3750276Speter
3850276Speter#include "menu.priv.h"
3950276Speter
40262629SdelphijMODULE_ID("$Id: m_win.c,v 1.17 2010/01/23 21:20:11 tom Exp $")
4150276Speter
4250276Speter/*---------------------------------------------------------------------------
4350276Speter|   Facility      :  libnmenu
4450276Speter|   Function      :  int set_menu_win(MENU *menu, WINDOW *win)
4550276Speter|
4650276Speter|   Description   :  Sets the window of the menu.
4750276Speter|
4850276Speter|   Return Values :  E_OK               - success
4950276Speter|                    E_POSTED           - menu is already posted
5050276Speter+--------------------------------------------------------------------------*/
5176726SpeterNCURSES_EXPORT(int)
52166124Srafanset_menu_win(MENU * menu, WINDOW *win)
5350276Speter{
54262629Sdelphij  T((T_CALLED("set_menu_win(%p,%p)"), (void *)menu, (void *)win));
55166124Srafan
5650276Speter  if (menu)
5750276Speter    {
58166124Srafan      if (menu->status & _POSTED)
5950276Speter	RETURN(E_POSTED);
60262629Sdelphij      else
61262629Sdelphij#if NCURSES_SP_FUNCS
62262629Sdelphij	{
63262629Sdelphij	  /* We ensure that userwin is never null. So even if a null
64262629Sdelphij	     WINDOW parameter is passed, we store the SCREENS stdscr.
65262629Sdelphij	     The only MENU that can have a null userwin is the static
66262629Sdelphij	     _nc_default_Menu.
67262629Sdelphij	   */
68262629Sdelphij	  SCREEN *sp = _nc_screen_of(menu->userwin);
69262629Sdelphij
70262629Sdelphij	  menu->userwin = win ? win : sp->_stdscr;
71262629Sdelphij	  _nc_Calculate_Item_Length_and_Width(menu);
72262629Sdelphij	}
73262629Sdelphij#else
74262629Sdelphij	menu->userwin = win;
75262629Sdelphij#endif
7650276Speter    }
7750276Speter  else
7850276Speter    _nc_Default_Menu.userwin = win;
79166124Srafan
8050276Speter  RETURN(E_OK);
8150276Speter}
8250276Speter
8350276Speter/*---------------------------------------------------------------------------
8450276Speter|   Facility      :  libnmenu
85262629Sdelphij|   Function      :  WINDOW* menu_win(const MENU*)
8650276Speter|
8750276Speter|   Description   :  Returns pointer to the window of the menu
8850276Speter|
8950276Speter|   Return Values :  NULL on error, otherwise pointer to window
9050276Speter+--------------------------------------------------------------------------*/
9176726SpeterNCURSES_EXPORT(WINDOW *)
92166124Srafanmenu_win(const MENU * menu)
9350276Speter{
94166124Srafan  const MENU *m = Normalize_Menu(menu);
95166124Srafan
96262629Sdelphij  T((T_CALLED("menu_win(%p)"), (const void *)menu));
97262629Sdelphij  returnWin(Get_Menu_UserWin(m));
9850276Speter}
9950276Speter
10050276Speter/* m_win.c ends here */
101