1998-03-01 12:21:12 +08:00
|
|
|
/****************************************************************************
|
2005-10-10 02:41:57 +08:00
|
|
|
* Copyright (c) 1998-2003,2004 Free Software Foundation, Inc. *
|
1998-03-01 12:21:12 +08:00
|
|
|
* *
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a *
|
|
|
|
* copy of this software and associated documentation files (the *
|
|
|
|
* "Software"), to deal in the Software without restriction, including *
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish, *
|
|
|
|
* distribute, distribute with modifications, sublicense, and/or sell *
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is *
|
|
|
|
* furnished to do so, subject to the following conditions: *
|
|
|
|
* *
|
|
|
|
* The above copyright notice and this permission notice shall be included *
|
|
|
|
* in all copies or substantial portions of the Software. *
|
|
|
|
* *
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
|
|
|
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
|
|
|
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
|
|
|
* *
|
|
|
|
* Except as contained in this notice, the name(s) of the above copyright *
|
|
|
|
* holders shall not be used in advertising or otherwise to promote the *
|
|
|
|
* sale, use or other dealings in this Software without prior written *
|
|
|
|
* authorization. *
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2002-10-13 11:35:53 +08:00
|
|
|
* Author: Juergen Pfeifer, 1995,1997 *
|
1998-03-01 12:21:12 +08:00
|
|
|
****************************************************************************/
|
1997-05-15 12:00:00 +08:00
|
|
|
|
|
|
|
/***************************************************************************
|
1998-03-01 12:21:12 +08:00
|
|
|
* Module m_new *
|
1997-05-15 12:00:00 +08:00
|
|
|
* Creation and destruction of new menus *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "menu.priv.h"
|
|
|
|
|
2005-10-10 02:41:57 +08:00
|
|
|
MODULE_ID("$Id: m_new.c,v 1.16 2004/12/25 21:57:53 tom Exp $")
|
1997-05-15 12:00:00 +08:00
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
| Facility : libnmenu
|
|
|
|
| Function : MENU *new_menu(ITEM **items)
|
|
|
|
|
|
|
|
|
| Description : Creates a new menu connected to the item pointer
|
|
|
|
| array items and returns a pointer to the new menu.
|
|
|
|
| The new menu is initialized with the values from the
|
|
|
|
| default menu.
|
|
|
|
|
|
|
|
|
| Return Values : NULL on error
|
|
|
|
+--------------------------------------------------------------------------*/
|
2002-10-13 11:35:53 +08:00
|
|
|
NCURSES_EXPORT(MENU *)
|
2005-10-10 02:41:57 +08:00
|
|
|
new_menu(ITEM ** items)
|
1997-05-15 12:00:00 +08:00
|
|
|
{
|
2005-10-10 02:41:57 +08:00
|
|
|
MENU *menu = (MENU *) calloc(1, sizeof(MENU));
|
|
|
|
|
|
|
|
T((T_CALLED("new_menu(%p)"), items));
|
1997-05-15 12:00:00 +08:00
|
|
|
if (menu)
|
|
|
|
{
|
|
|
|
*menu = _nc_Default_Menu;
|
1999-10-24 12:32:42 +08:00
|
|
|
menu->status = 0;
|
1997-05-15 12:00:00 +08:00
|
|
|
menu->rows = menu->frows;
|
|
|
|
menu->cols = menu->fcols;
|
|
|
|
if (items && *items)
|
|
|
|
{
|
2005-10-10 02:41:57 +08:00
|
|
|
if (!_nc_Connect_Items(menu, items))
|
1997-05-15 12:00:00 +08:00
|
|
|
{
|
|
|
|
free(menu);
|
2005-10-10 02:41:57 +08:00
|
|
|
menu = (MENU *) 0;
|
1997-05-15 12:00:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!menu)
|
|
|
|
SET_ERROR(E_SYSTEM_ERROR);
|
|
|
|
|
2005-10-10 02:41:57 +08:00
|
|
|
returnMenu(menu);
|
1997-05-15 12:00:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
| Facility : libnmenu
|
|
|
|
| Function : int free_menu(MENU *menu)
|
|
|
|
|
|
|
|
|
| Description : Disconnects menu from its associated item pointer
|
|
|
|
| array and frees the storage allocated for the menu.
|
|
|
|
|
|
|
|
|
| Return Values : E_OK - success
|
|
|
|
| E_BAD_ARGUMENT - Invalid menu pointer passed
|
|
|
|
| E_POSTED - Menu is already posted
|
|
|
|
+--------------------------------------------------------------------------*/
|
2002-10-13 11:35:53 +08:00
|
|
|
NCURSES_EXPORT(int)
|
2005-10-10 02:41:57 +08:00
|
|
|
free_menu(MENU * menu)
|
1997-05-15 12:00:00 +08:00
|
|
|
{
|
2005-10-10 02:41:57 +08:00
|
|
|
T((T_CALLED("free_menu(%p)"), menu));
|
1997-05-15 12:00:00 +08:00
|
|
|
if (!menu)
|
|
|
|
RETURN(E_BAD_ARGUMENT);
|
2005-10-10 02:41:57 +08:00
|
|
|
|
|
|
|
if (menu->status & _POSTED)
|
1997-05-15 12:00:00 +08:00
|
|
|
RETURN(E_POSTED);
|
2005-10-10 02:41:57 +08:00
|
|
|
|
|
|
|
if (menu->items)
|
1997-05-15 12:00:00 +08:00
|
|
|
_nc_Disconnect_Items(menu);
|
2005-10-10 02:41:57 +08:00
|
|
|
|
1997-05-15 12:00:00 +08:00
|
|
|
if ((menu->status & _MARK_ALLOCATED) && menu->mark)
|
|
|
|
free(menu->mark);
|
|
|
|
|
|
|
|
free(menu);
|
|
|
|
RETURN(E_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* m_new.c ends here */
|