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
|
/* $Id: cursesbutton.H,v 1.2 2003/06/16 03:18:01 mrsam Exp $
**
** Copyright 2002, Double Precision Inc.
**
** See COPYING for distribution information.
*/
#ifndef cursesbutton_H
#define cursesbutton_H
#include "mycurses.H"
#include "curseslabel.H"
////////////////////////////////////////////////////////////////////////
//
// A plain, garden variety, button. Centered, or right-aligned, perhaps.
//
// CursesButton simply subclasses CursesLabel, makes it focusable, and
// overrides WriteText.
//
class CursesButton : public CursesLabel {
int toggleButton;
std::string buttonName;
public:
// Button style:
enum Style {
NORMAL,
TOGGLE,
MENU
};
private:
Style currentStyle;
public:
CursesButton(CursesContainer *parent,
std::string textArg, int toggle=0);
~CursesButton();
void setStyle(Style);
void draw();
bool isFocusable();
void focusGained();
void focusLost();
void setText(std::string textArg);
int getCursorPosition(int &r, int &c);
int getWidth() const;
bool processKeyInFocus(const Curses::Key &key);
virtual void clicked();
int getSelected() { return toggleButton < 0; }
void setToggled(bool flag);
};
//////////////////////////////////////////////////////////////////////////
//
// Instead of subclassing CursesButton, here's a template to have it be a
// member of another class. Typical usage:
//
// class X {
//
// CursesButtonRedirect<X> button1;
//
// void button1clicked();
// } ;
//
// X::X()
// {
// button1=this;
// button1=&X::button1clicked;
// }
template<class T> class CursesButtonRedirect : public CursesButton {
T *myClass;
void (T::*mymethod)();
public:
CursesButtonRedirect(CursesContainer *parent,
std::string textArg, int toggle=0)
: CursesButton(parent, textArg, toggle)
{
}
~CursesButtonRedirect()
{
}
void operator=(T *p) { myClass=p; }
void operator=(void (T::*p)()) {mymethod=p; }
void clicked() { (myClass->*mymethod)(); }
T *getObject() const { return myClass; }
};
#endif
|