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
|
/* $Id: curseschoicebutton.H,v 1.1 2003/05/27 14:09:07 mrsam Exp $
**
** Copyright 2002, Double Precision Inc.
**
** See COPYING for distribution information.
*/
#ifndef curseschoicebutton_H
#define curseschoicebutton_H
#include "mycurses.H"
#include "cursesbutton.H"
#include <vector>
////////////////////////////////////////////////////////////////////////
//
// A button that cycles through a small list of options, each time it
// is "clicked".
//
class CursesChoiceButton : public CursesButton {
std::vector<std::string> optionList;
size_t selectedOption;
public:
CursesChoiceButton(CursesContainer *parent);
~CursesChoiceButton();
void setOptions(const std::vector<std::string> &optionListArg,
size_t initialOption);
size_t getSelectedOption() const { return selectedOption; }
void clicked();
};
//////////////////////////////////////////////////////////////////////////
//
// Instead of subclassing CursesChoiceButton, here's a template to have it be a
// member of another class. Typical usage:
//
// class X {
//
// CursesChoiceButtonRedirect<X> button1;
//
// void button1clicked();
// } ;
//
// X::X()
// {
// button1=this;
// button1=&X::button1clicked;
// }
template<class T> class CursesChoiceButtonRedirect
: public CursesChoiceButton {
T *myClass;
void (T::*mymethod)();
public:
CursesChoiceButtonRedirect(CursesContainer *parent)
: CursesChoiceButton(parent)
{
}
~CursesChoiceButtonRedirect()
{
}
void operator=(T *p) { myClass=p; }
void operator=(void (T::*p)()) {mymethod=p; }
void clicked()
{
CursesChoiceButton::clicked();
(myClass->*mymethod)();
}
};
#endif
|