1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
|
// -*- c++ -*-
//
// $Id: basewindow.h 2719 2009-08-20 01:30:25Z rafi $
//
// Copyright (C) 2008, 2009 Rafael Ostertag
//
// This file is part of YAPET.
//
// YAPET is free software: you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// YAPET is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// YAPET. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _BASEWINDOW_H
#define _BASEWINDOW_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef HAVE_NCURSES_H
# include <ncurses.h>
#else // HAVE_NCURSES_H
# ifdef HAVE_CURSES_H
# include <curses.h>
# else
# error "Neither curses.h nor ncurses.h available"
# endif // HAVE_CURSES_H
#endif // HAVE_NCURSES_H
#include "curswa.h" // Leave this here. It depends on the above includes.
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_LIST
# include <list>
#endif
namespace YAPET {
namespace UI {
/**
* @brief Base window class for windows wanting to receive resize events.
*
* Classes responding to window resize events should be derived from this
* class.
*
* The constructor of this class registers the window to receive the resize
* event. The destructor un-registers the class from the list of base
* windows.
*
* There are also static members for dealing with signals and initializing
* (n)curses.
*/
class BaseWindow {
public:
/**
* @brief Base class for calling a function upon the alarm signal.
*
* The class passed as caller for the action upon an alarm to \c
* setTimeout has to be derived from this class.
*
* The method \c AlarmFunction::process() will be called upon the
* \c SIGALRM signal.
*/
class AlarmFunction {
public:
inline virtual ~AlarmFunction() {}
/**
* @brief Called upon \c SIGALRM.
*
* This method is called upon a \c SIGALRM signal. The
* integer argument is the number of the signal, which
* currently is always \c SIGALRM.
*/
virtual void process (int) = 0;
};
private:
#if defined(HAVE_SIGACTION) && defined(HAVE_SIGNAL_H)
static AlarmFunction* alarm_fun;
#endif // defined(HAVE_SIGACTION) && defined(HAVE_SIGNAL_H)
static std::list<BaseWindow*> basewindow_list;
protected:
/**
* @brief Register a base window.
*
* This method will be called by the constructor of \c
* BaseWindow.
*
* @param r the pointer to the \c BaseWindow. Usually \c this.
*/
static void registerBaseWindow (BaseWindow* r);
/**
* @brief un-registers a base window.
*
* This method will be called by the destructor of \c BaseWindow.
*
* @param r the pointer to the \c BaseWindow to be removed from the
* list. Usually \c this.
*/
static void unregisterBaseWindow (BaseWindow* r);
#if defined(HAVE_SIGACTION) && defined(HAVE_SIGNAL_H)
/**
* @brief The signal handler.
*
* This is the signal handler for the signals processed.
*
* Upon \c SIGALRM (set by \c setTimeout()) it will call the \c
* process method of the \c AlarmFunction class pointed to be \c
* alarm_fun.
*
* @param signo the number of the signal.
*/
static void sig_handler (int signo);
/**
* @brief Initializes the signal handlers.
*
* Initializes the signal handlers. This method will be called by
* \c initCurses().
*/
static void init_signal();
#endif // defined(HAVE_SIGACTION) && defined(HAVE_SIGNAL_H)
/**
* @brief The maximum x value of the screen.
*
* Returns the maximum x value of the screen.
*
* @return the maximum x value available to the curses functions.
*/
inline int maxX() const {
int max_x, max_y;
getmaxyx (stdscr, max_y, max_x);
return max_x;
}
/**
* @brief The maximum y value of the screen.
*
* Returns the maximum y value of the screen.
*
* @return the maximum y value available to the curses functions.
*/
inline int maxY() const {
int max_x, max_y;
getmaxyx (stdscr, max_y, max_x);
return max_y;
}
/**
* @brief The minimum x value of the screen.
*
* Returns the minimum x value of the screen.
*
* @return the minimum x value available to the curses functions.
*/
inline int minX() const {
int x, y;
getbegyx (stdscr, y, x);
return x;
}
/**
* @brief The minimum y value of the screen.
*
* Returns the minimum y value of the screen.
*
* @return the minimum y value available to the curses functions.
*/
inline int minY() const {
int x, y;
getbegyx (stdscr, y, x);
return y;
}
public:
/**
* @brief The minimum dimensions supported
*
* Resize events below either of the dimensions will not
* be processed.
*/
enum MinDimension {
MIN_Y = 24,
MIN_X = 80
};
/**
* @brief Initializes (n)curses.
*
* Initializes curses and sets up the signal handlers.
*/
static void initCurses();
/**
* @brief Ends the curses mode.
*
* Ends the curses mode.
*/
static void endCurses();
/**
* @brief Delete all registered windows.
*
* Deletes all registered windows by calling \c delete.
*/
static void deleteAll();
/**
* @brief Calls the \c resize() method of all registered windows.
*
* Calls the \c resize() method of all registered windows.
*/
static void resizeAll();
/**
* @brief Calls the \c refresh() method of all registered windows.
*
* Calls the \c refresh() method of all registered windows.
*/
static void refreshAll();
#if defined(HAVE_SIGACTION) && defined(HAVE_SIGNAL_H)
/**
* @brief Sets a timeout.
*
* Sets a timeout using the system function \c alarm. Upon the \c
* SIGALRM signal, the \c process() method of the \c AlarmFunction
* class is called.
*
* @param af pointer to the \c AlarmFunction class.
*
* @param sec the number of seconds before \c SIGALRM is raised.
*/
static void setTimeout (AlarmFunction* af, int sec);
/**
* @brief Suspends a currently set timeout.
*
* Suspends a currently set timeout.
*/
static void suspendTimeout();
#endif // defined(HAVE_SIGACTION) && defined(HAVE_SIGNAL_H)
BaseWindow();
virtual ~BaseWindow();
virtual void resize() = 0;
virtual void refresh() = 0;
};
}
}
#endif // _BASEWINDOW_H
|