1997-05-15 12:00:00 +08:00
|
|
|
// * This makes emacs happy -*-Mode: C++;-*-
|
2000-07-09 10:46:08 +08:00
|
|
|
/****************************************************************************
|
2014-08-10 07:40:51 +08:00
|
|
|
* Copyright (c) 1998-2012,2014 Free Software Foundation, Inc. *
|
2000-07-09 10:46:08 +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, 1997 *
|
2000-07-09 10:46:08 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2002-10-13 11:35:53 +08:00
|
|
|
#ifndef NCURSES_CURSESP_H_incl
|
|
|
|
#define NCURSES_CURSESP_H_incl 1
|
1997-05-15 12:00:00 +08:00
|
|
|
|
2014-08-10 07:40:51 +08:00
|
|
|
// $Id: cursesp.h,v 1.31 2014/08/09 22:06:26 Adam.Jiang Exp $
|
1998-03-01 12:21:12 +08:00
|
|
|
|
1997-05-15 12:00:00 +08:00
|
|
|
#include <cursesw.h>
|
|
|
|
|
|
|
|
extern "C" {
|
1998-03-01 12:21:12 +08:00
|
|
|
# include <panel.h>
|
1997-05-15 12:00:00 +08:00
|
|
|
}
|
|
|
|
|
2005-10-10 02:41:57 +08:00
|
|
|
class NCURSES_IMPEXP NCursesPanel
|
|
|
|
: public NCursesWindow
|
|
|
|
{
|
1997-05-15 12:00:00 +08:00
|
|
|
protected:
|
|
|
|
PANEL *p;
|
1998-03-01 12:21:12 +08:00
|
|
|
static NCursesPanel *dummy;
|
1997-05-15 12:00:00 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
// This structure is used for the panel's user data field to link the
|
|
|
|
// PANEL* to the C++ object and to provide extra space for a user pointer.
|
|
|
|
typedef struct {
|
1998-03-01 12:21:12 +08:00
|
|
|
void* m_user; // the pointer for the user's data
|
1997-05-15 12:00:00 +08:00
|
|
|
const NCursesPanel* m_back; // backward pointer to C++ object
|
|
|
|
const PANEL* m_owner; // the panel itself
|
|
|
|
} UserHook;
|
|
|
|
|
2005-10-10 02:41:57 +08:00
|
|
|
inline UserHook *UserPointer()
|
|
|
|
{
|
|
|
|
UserHook* uptr = reinterpret_cast<UserHook*>(
|
|
|
|
const_cast<void *>(::panel_userptr (p)));
|
|
|
|
return uptr;
|
|
|
|
}
|
|
|
|
|
1998-03-01 12:21:12 +08:00
|
|
|
void init(); // Initialize the panel object
|
|
|
|
|
1997-05-15 12:00:00 +08:00
|
|
|
protected:
|
2005-10-10 02:41:57 +08:00
|
|
|
void set_user(void *user)
|
|
|
|
{
|
|
|
|
UserHook* uptr = UserPointer();
|
2008-08-17 09:51:55 +08:00
|
|
|
if (uptr != 0 && uptr->m_back==this && uptr->m_owner==p) {
|
|
|
|
uptr->m_user = user;
|
|
|
|
}
|
1997-05-15 12:00:00 +08:00
|
|
|
}
|
1998-03-01 12:21:12 +08:00
|
|
|
// Set the user pointer of the panel.
|
2005-10-10 02:41:57 +08:00
|
|
|
|
|
|
|
void *get_user()
|
|
|
|
{
|
|
|
|
UserHook* uptr = UserPointer();
|
2008-08-17 09:51:55 +08:00
|
|
|
void *result = 0;
|
|
|
|
if (uptr != 0 && uptr->m_back==this && uptr->m_owner==p)
|
|
|
|
result = uptr->m_user;
|
|
|
|
return result;
|
1997-05-15 12:00:00 +08:00
|
|
|
}
|
2005-10-10 02:41:57 +08:00
|
|
|
|
2012-12-30 09:55:33 +08:00
|
|
|
void OnError (int err) const THROW2(NCursesException const, NCursesPanelException)
|
2005-10-10 02:41:57 +08:00
|
|
|
{
|
1998-03-01 12:21:12 +08:00
|
|
|
if (err==ERR)
|
1997-05-15 12:00:00 +08:00
|
|
|
THROW(new NCursesPanelException (this, err));
|
|
|
|
}
|
1998-03-01 12:21:12 +08:00
|
|
|
// If err is equal to the curses error indicator ERR, an error handler
|
|
|
|
// is called.
|
1997-05-15 12:00:00 +08:00
|
|
|
|
2002-10-13 11:35:53 +08:00
|
|
|
// Get a keystroke. Default implementation calls getch()
|
|
|
|
virtual int getKey(void);
|
|
|
|
|
1997-05-15 12:00:00 +08:00
|
|
|
public:
|
2005-10-10 02:41:57 +08:00
|
|
|
NCursesPanel(int nlines,
|
|
|
|
int ncols,
|
1997-05-15 12:00:00 +08:00
|
|
|
int begin_y = 0,
|
1998-03-01 12:21:12 +08:00
|
|
|
int begin_x = 0)
|
2005-10-10 02:41:57 +08:00
|
|
|
: NCursesWindow(nlines,ncols,begin_y,begin_x), p(0)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
1998-03-01 12:21:12 +08:00
|
|
|
// Create a panel with this size starting at the requested position.
|
|
|
|
|
2005-10-10 02:41:57 +08:00
|
|
|
NCursesPanel()
|
|
|
|
: NCursesWindow(::stdscr), p(0)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
1998-03-01 12:21:12 +08:00
|
|
|
// This constructor creates the default Panel associated with the
|
|
|
|
// ::stdscr window
|
1997-05-15 12:00:00 +08:00
|
|
|
|
2005-10-10 02:41:57 +08:00
|
|
|
NCursesPanel& operator=(const NCursesPanel& rhs)
|
|
|
|
{
|
|
|
|
if (this != &rhs) {
|
|
|
|
*this = rhs;
|
|
|
|
NCursesWindow::operator=(rhs);
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
NCursesPanel(const NCursesPanel& rhs)
|
|
|
|
: NCursesWindow(rhs),
|
|
|
|
p(rhs.p)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1997-05-15 12:00:00 +08:00
|
|
|
virtual ~NCursesPanel();
|
2005-10-10 02:41:57 +08:00
|
|
|
|
1997-05-15 12:00:00 +08:00
|
|
|
// basic manipulation
|
2005-10-10 02:41:57 +08:00
|
|
|
inline void hide()
|
|
|
|
{
|
1997-05-15 12:00:00 +08:00
|
|
|
OnError (::hide_panel(p));
|
|
|
|
}
|
1998-03-01 12:21:12 +08:00
|
|
|
// Hide the panel. It stays in the stack but becomes invisible.
|
1997-05-15 12:00:00 +08:00
|
|
|
|
2005-10-10 02:41:57 +08:00
|
|
|
inline void show()
|
|
|
|
{
|
1997-05-15 12:00:00 +08:00
|
|
|
OnError (::show_panel(p));
|
|
|
|
}
|
1998-03-01 12:21:12 +08:00
|
|
|
// Show the panel, i.e. make it visible.
|
1997-05-15 12:00:00 +08:00
|
|
|
|
2005-10-10 02:41:57 +08:00
|
|
|
inline void top()
|
|
|
|
{
|
1997-05-15 12:00:00 +08:00
|
|
|
OnError (::top_panel(p));
|
|
|
|
}
|
1998-03-01 12:21:12 +08:00
|
|
|
// Make this panel the top panel in the stack.
|
2005-10-10 02:41:57 +08:00
|
|
|
|
|
|
|
inline void bottom()
|
|
|
|
{
|
1997-05-15 12:00:00 +08:00
|
|
|
OnError (::bottom_panel(p));
|
|
|
|
}
|
1998-03-01 12:21:12 +08:00
|
|
|
// Make this panel the bottom panel in the stack.
|
|
|
|
// N.B.: The panel associated with ::stdscr is always on the bottom. So
|
|
|
|
// actually bottom() makes the panel the first above ::stdscr.
|
2005-10-10 02:41:57 +08:00
|
|
|
|
|
|
|
virtual int mvwin(int y, int x)
|
|
|
|
{
|
1998-03-01 12:21:12 +08:00
|
|
|
OnError(::move_panel(p, y, x));
|
|
|
|
return OK;
|
1997-05-15 12:00:00 +08:00
|
|
|
}
|
2005-10-10 02:41:57 +08:00
|
|
|
|
|
|
|
inline bool hidden() const
|
|
|
|
{
|
1998-03-01 12:21:12 +08:00
|
|
|
return (::panel_hidden (p) ? TRUE : FALSE);
|
|
|
|
}
|
|
|
|
// Return TRUE if the panel is hidden, FALSE otherwise.
|
|
|
|
|
|
|
|
/* The functions panel_above() and panel_below() are not reflected in
|
|
|
|
the NCursesPanel class. The reason for this is, that we cannot
|
|
|
|
assume that a panel retrieved by those operations is one wrapped
|
|
|
|
by a C++ class. Although this situation might be handled, we also
|
|
|
|
need a reverse mapping from PANEL to NCursesPanel which needs some
|
|
|
|
redesign of the low level stuff. At the moment, we define them in the
|
|
|
|
interface but they will always produce an error. */
|
2005-10-10 02:41:57 +08:00
|
|
|
inline NCursesPanel& above() const
|
|
|
|
{
|
1998-03-01 12:21:12 +08:00
|
|
|
OnError(ERR);
|
|
|
|
return *dummy;
|
1997-05-15 12:00:00 +08:00
|
|
|
}
|
|
|
|
|
2005-10-10 02:41:57 +08:00
|
|
|
inline NCursesPanel& below() const
|
|
|
|
{
|
1998-03-01 12:21:12 +08:00
|
|
|
OnError(ERR);
|
|
|
|
return *dummy;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Those two are rewrites of the corresponding virtual members of
|
|
|
|
// NCursesWindow
|
1999-10-24 12:32:42 +08:00
|
|
|
virtual int refresh();
|
2005-10-10 02:41:57 +08:00
|
|
|
// Propagate all panel changes to the virtual screen and update the
|
1998-03-01 12:21:12 +08:00
|
|
|
// physical screen.
|
|
|
|
|
1999-10-24 12:32:42 +08:00
|
|
|
virtual int noutrefresh();
|
1998-03-01 12:21:12 +08:00
|
|
|
// Propagate all panel changes to the virtual screen.
|
|
|
|
|
|
|
|
static void redraw();
|
|
|
|
// Redraw all panels.
|
2005-10-10 02:41:57 +08:00
|
|
|
|
1997-05-15 12:00:00 +08:00
|
|
|
// decorations
|
2005-10-10 02:41:57 +08:00
|
|
|
virtual void frame(const char* title=NULL,
|
1998-03-01 12:21:12 +08:00
|
|
|
const char* btitle=NULL);
|
|
|
|
// Put a frame around the panel and put the title centered in the top line
|
|
|
|
// and btitle in the bottom line.
|
|
|
|
|
|
|
|
virtual void boldframe(const char* title=NULL,
|
|
|
|
const char* btitle=NULL);
|
|
|
|
// Same as frame(), but use highlighted attributes.
|
1997-05-15 12:00:00 +08:00
|
|
|
|
1998-03-01 12:21:12 +08:00
|
|
|
virtual void label(const char* topLabel,
|
|
|
|
const char* bottomLabel);
|
|
|
|
// Put the title centered in the top line and btitle in the bottom line.
|
|
|
|
|
|
|
|
virtual void centertext(int row,const char* label);
|
|
|
|
// Put the label text centered in the specified row.
|
|
|
|
};
|
1997-05-15 12:00:00 +08:00
|
|
|
|
|
|
|
/* We use templates to provide a typesafe mechanism to associate
|
2005-10-10 02:41:57 +08:00
|
|
|
* user data with a panel. A NCursesUserPanel<T> is a panel
|
1997-05-15 12:00:00 +08:00
|
|
|
* associated with some user data of type T.
|
|
|
|
*/
|
|
|
|
template<class T> class NCursesUserPanel : public NCursesPanel
|
|
|
|
{
|
|
|
|
public:
|
2005-10-10 02:41:57 +08:00
|
|
|
NCursesUserPanel (int nlines,
|
|
|
|
int ncols,
|
1997-05-15 12:00:00 +08:00
|
|
|
int begin_y = 0,
|
1998-03-01 12:21:12 +08:00
|
|
|
int begin_x = 0,
|
2005-10-10 02:41:57 +08:00
|
|
|
const T* p_UserData = STATIC_CAST(T*)(0))
|
|
|
|
: NCursesPanel (nlines, ncols, begin_y, begin_x)
|
|
|
|
{
|
1997-05-15 12:00:00 +08:00
|
|
|
if (p)
|
2014-08-10 07:40:51 +08:00
|
|
|
set_user (const_cast<void *>(reinterpret_cast<const void*>
|
|
|
|
(p_UserData)));
|
1997-05-15 12:00:00 +08:00
|
|
|
};
|
1998-03-01 12:21:12 +08:00
|
|
|
// This creates an user panel of the requested size with associated
|
|
|
|
// user data pointed to by p_UserData.
|
2005-10-10 02:41:57 +08:00
|
|
|
|
|
|
|
NCursesUserPanel(const T* p_UserData = STATIC_CAST(T*)(0)) : NCursesPanel()
|
|
|
|
{
|
1998-03-01 12:21:12 +08:00
|
|
|
if (p)
|
2014-08-10 07:40:51 +08:00
|
|
|
set_user(const_cast<void *>(reinterpret_cast<const void*>(p_UserData)));
|
1998-03-01 12:21:12 +08:00
|
|
|
};
|
|
|
|
// This creates an user panel associated with the ::stdscr and user data
|
|
|
|
// pointed to by p_UserData.
|
|
|
|
|
1997-05-15 12:00:00 +08:00
|
|
|
virtual ~NCursesUserPanel() {};
|
|
|
|
|
2014-08-10 07:40:51 +08:00
|
|
|
T* UserData (void)
|
2005-10-10 02:41:57 +08:00
|
|
|
{
|
|
|
|
return reinterpret_cast<T*>(get_user ());
|
1997-05-15 12:00:00 +08:00
|
|
|
};
|
1998-03-01 12:21:12 +08:00
|
|
|
// Retrieve the user data associated with the panel.
|
2005-10-10 02:41:57 +08:00
|
|
|
|
|
|
|
virtual void setUserData (const T* p_UserData)
|
|
|
|
{
|
1997-05-15 12:00:00 +08:00
|
|
|
if (p)
|
2014-08-10 07:40:51 +08:00
|
|
|
set_user (const_cast<void *>(reinterpret_cast<const void*>(p_UserData)));
|
1997-05-15 12:00:00 +08:00
|
|
|
}
|
1998-03-01 12:21:12 +08:00
|
|
|
// Associate the user panel with the user data pointed to by p_UserData.
|
1997-05-15 12:00:00 +08:00
|
|
|
};
|
|
|
|
|
2005-10-10 02:41:57 +08:00
|
|
|
#endif /* NCURSES_CURSESP_H_incl */
|