// * this is for making emacs happy: -*-Mode: C++;-*-
/****************************************************************************
* Copyright (c) 1998-2011,2017 Free Software Foundation, Inc. *
* *
* 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. *
****************************************************************************/
/****************************************************************************
* Author: Juergen Pfeifer, 1997 *
****************************************************************************/
#include "internal.h"
#include "cursesm.h"
#include "cursesapp.h"
MODULE_ID("$Id: cursesm.cc,v 1.24 2017/06/26 08:32:53 tom Exp $")
NCursesMenuItem::~NCursesMenuItem()
{
if (item)
OnError(::free_item(item));
}
bool
NCursesMenuItem::action()
{
return FALSE;
}
NCursesMenuCallbackItem::~NCursesMenuCallbackItem()
{
}
bool
NCursesMenuCallbackItem::action()
{
if (p_fct)
return p_fct (*this);
else
return FALSE;
}
/* Internal hook functions. They will route the hook
* calls to virtual methods of the NCursesMenu class,
* so in C++ providing a hook is done simply by
* implementing a virtual method in a derived class
*/
void
_nc_xx_mnu_init(MENU *m)
{
NCursesMenu::getHook(m)->On_Menu_Init();
}
void
_nc_xx_mnu_term(MENU *m)
{
NCursesMenu::getHook(m)->On_Menu_Termination();
}
void
_nc_xx_itm_init(MENU *m)
{
NCursesMenu* M = NCursesMenu::getHook(m);
M->On_Item_Init (*(M->current_item ()));
}
void
_nc_xx_itm_term(MENU *m)
{
NCursesMenu* M = NCursesMenu::getHook(m);
M->On_Item_Termination (*(M->current_item ()));
}
/* Construct an ITEM* array from an array of NCursesMenuItem
* objects.
*/
ITEM**
NCursesMenu::mapItems(NCursesMenuItem* nitems[])
{
int itemCount = 0,lcv;
for (lcv=0; nitems[lcv]->item; ++lcv)
++itemCount;
ITEM** itemArray = new ITEM*[itemCount + 1];
for (lcv=0;nitems[lcv]->item;++lcv) {
itemArray[lcv] = nitems[lcv]->item;
}
itemArray[lcv] = NULL;
my_items = nitems;
if (menu)
delete[] ::menu_items(menu);
return itemArray;
}
void
NCursesMenu::InitMenu(NCursesMenuItem* nitems[],
bool with_frame,
bool autoDelete_Items)
{
int mrows, mcols;
keypad(TRUE);
meta(TRUE);
b_framed = with_frame;
b_autoDelete = autoDelete_Items;
menu = static_cast