ncursesw-morphos/c++/cursesp.cc

139 lines
4.0 KiB
C++
Raw Normal View History

1997-05-15 12:00:00 +08:00
// * this is for making emacs happy: -*-Mode: C++;-*-
1998-03-01 12:21:12 +08:00
/****************************************************************************
* Copyright (c) 1998-2005,2019 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. *
****************************************************************************/
1997-05-15 12:00:00 +08:00
1998-03-01 12:21:12 +08:00
/****************************************************************************
2002-10-13 11:35:53 +08:00
* Author: Juergen Pfeifer, 1993, 1997 *
1998-03-01 12:21:12 +08:00
****************************************************************************/
1997-05-15 12:00:00 +08:00
#include "internal.h"
2002-10-13 11:35:53 +08:00
#include "cursesp.h"
1997-05-15 12:00:00 +08:00
MODULE_ID("$Id: cursesp.cc,v 1.26 2019/07/28 19:55:27 tom Exp $")
1997-05-15 12:00:00 +08:00
2005-10-10 02:41:57 +08:00
NCursesPanel* NCursesPanel::dummy = static_cast<NCursesPanel*>(0);
1997-05-15 12:00:00 +08:00
2005-10-10 02:41:57 +08:00
void NCursesPanel::init()
{
1998-03-01 12:21:12 +08:00
p = ::new_panel(w);
if (!p)
OnError(ERR);
2000-10-21 12:42:11 +08:00
1998-03-01 12:21:12 +08:00
UserHook* hook = new UserHook;
hook->m_user = NULL;
hook->m_back = this;
hook->m_owner = p;
2005-10-10 02:41:57 +08:00
::set_panel_userptr(p, reinterpret_cast<void *>(hook));
2000-10-21 12:42:11 +08:00
}
1997-05-15 12:00:00 +08:00
NCursesPanel::~NCursesPanel() THROWS(NCursesException)
2005-10-10 02:41:57 +08:00
{
UserHook* hook = UserPointer();
2000-07-09 10:46:08 +08:00
assert(hook != 0 && hook->m_back==this && hook->m_owner==p);
1997-05-15 12:00:00 +08:00
delete hook;
::del_panel(p);
::update_panels();
}
void
2005-10-10 02:41:57 +08:00
NCursesPanel::redraw()
{
1997-05-15 12:00:00 +08:00
PANEL *pan;
2000-10-21 12:42:11 +08:00
1997-05-15 12:00:00 +08:00
pan = ::panel_above(NULL);
while (pan) {
::touchwin(panel_window(pan));
pan = ::panel_above(pan);
}
::update_panels();
::doupdate();
}
1998-03-01 12:21:12 +08:00
int
2005-10-10 02:41:57 +08:00
NCursesPanel::refresh()
{
1997-05-15 12:00:00 +08:00
::update_panels();
2002-10-13 11:35:53 +08:00
return ::doupdate();
1998-03-01 12:21:12 +08:00
}
int
2005-10-10 02:41:57 +08:00
NCursesPanel::noutrefresh()
{
1998-03-01 12:21:12 +08:00
::update_panels();
return OK;
1997-05-15 12:00:00 +08:00
}
void
2005-10-10 02:41:57 +08:00
NCursesPanel::boldframe(const char *title, const char* btitle)
{
1997-05-15 12:00:00 +08:00
standout();
frame(title, btitle);
standend();
}
void
2005-10-10 02:41:57 +08:00
NCursesPanel::frame(const char *title,const char *btitle)
{
1997-05-15 12:00:00 +08:00
int err = OK;
if (!title && !btitle) {
err = box();
2000-10-21 12:42:11 +08:00
}
1997-05-15 12:00:00 +08:00
else {
err = box();
if (err==OK)
2000-10-21 12:42:11 +08:00
label(title,btitle);
1997-05-15 12:00:00 +08:00
}
OnError(err);
}
void
2005-10-10 02:41:57 +08:00
NCursesPanel::label(const char *tLabel, const char *bLabel)
{
2000-10-21 12:42:11 +08:00
if (tLabel)
1997-05-15 12:00:00 +08:00
centertext(0,tLabel);
2000-10-21 12:42:11 +08:00
if (bLabel)
1997-05-15 12:00:00 +08:00
centertext(maxy(),bLabel);
}
void
2005-10-10 02:41:57 +08:00
NCursesPanel::centertext(int row,const char *labelText)
{
if (labelText) {
int x = (maxx() - ::strlen(labelText)) / 2;
1998-03-01 12:21:12 +08:00
if (x<0)
x=0;
2005-10-10 02:41:57 +08:00
OnError(addstr(row, x, labelText, width()));
1998-03-01 12:21:12 +08:00
}
1997-05-15 12:00:00 +08:00
}
2002-10-13 11:35:53 +08:00
int
2005-10-10 02:41:57 +08:00
NCursesPanel::getKey(void)
{
2002-10-13 11:35:53 +08:00
return getch();
}