2002-03-11 17:00:41 +00:00
|
|
|
/**
|
|
|
|
* \file RadioButtonGroup.C
|
|
|
|
* Copyright 1995 Matthias Ettrich.
|
|
|
|
* Copyright 1995-2001 The LyX Team.
|
|
|
|
* Copyright 2000 Baruch Even
|
|
|
|
* See the file COPYING.
|
2000-07-31 12:30:10 +00:00
|
|
|
*
|
2002-03-11 17:00:41 +00:00
|
|
|
* \author Baruch Even, baruch.even@writeme.com
|
|
|
|
*/
|
2000-07-31 12:30:10 +00:00
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
#include <config.h>
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
2002-03-21 21:21:28 +00:00
|
|
|
#endif
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
#include "RadioButtonGroup.h"
|
|
|
|
|
|
|
|
#include "debug.h" // for lyxerr
|
2002-02-16 15:59:55 +00:00
|
|
|
#include "support/lyxfunctional.h"
|
|
|
|
|
|
|
|
//#include <functional>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iterator>
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
using std::find_if;
|
2002-02-16 15:59:55 +00:00
|
|
|
//using std::bind2nd;
|
2000-07-31 13:36:03 +00:00
|
|
|
using std::endl;
|
2000-07-31 12:30:10 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2002-03-25 11:16:15 +00:00
|
|
|
void RadioButtonGroup::init(FL_OBJECT *button, size_type value)
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
2002-02-16 15:59:55 +00:00
|
|
|
map.push_back(ButtonValuePair(button, value));
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RadioButtonGroup::reset()
|
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
map.clear();
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2002-03-25 11:16:15 +00:00
|
|
|
void RadioButtonGroup::set(size_type value)
|
2000-08-14 09:44:53 +00:00
|
|
|
{
|
2002-02-16 15:59:55 +00:00
|
|
|
ButtonValueMap::const_iterator it =
|
|
|
|
find_if(map.begin(), map.end(),
|
|
|
|
lyx::equal_2nd_in_pair<ButtonValuePair>(value));
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2000-08-14 09:44:53 +00:00
|
|
|
// If we found nothing, report it and return
|
|
|
|
if (it == map.end()) {
|
|
|
|
lyxerr << "BUG: Requested value in RadioButtonGroup doesn't exists"
|
2002-03-21 16:59:12 +00:00
|
|
|
<< endl;
|
2000-08-14 09:44:53 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-07-12 11:11:10 +00:00
|
|
|
fl_set_button(it->first, 1);
|
2000-08-14 09:44:53 +00:00
|
|
|
}
|
|
|
|
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2000-08-14 09:44:53 +00:00
|
|
|
template < typename T >
|
2000-07-31 12:30:10 +00:00
|
|
|
struct is_set_button {
|
2000-08-14 09:44:53 +00:00
|
|
|
bool operator() (T const & item) const
|
|
|
|
{
|
2002-02-16 15:59:55 +00:00
|
|
|
return fl_get_button((item).first);
|
2000-08-14 09:44:53 +00:00
|
|
|
}
|
2000-07-31 12:30:10 +00:00
|
|
|
};
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2002-03-25 11:16:15 +00:00
|
|
|
RadioButtonGroup::size_type RadioButtonGroup::get() const
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
2000-08-14 09:44:53 +00:00
|
|
|
// Find the first button that is active
|
2002-03-25 11:16:15 +00:00
|
|
|
ButtonValueMap::const_iterator it =
|
2002-03-21 16:59:12 +00:00
|
|
|
find_if(map.begin(), map.end(),
|
|
|
|
is_set_button<ButtonValuePair> ());
|
2000-07-31 12:30:10 +00:00
|
|
|
|
2000-08-14 09:44:53 +00:00
|
|
|
// If such a button was found, return its value.
|
|
|
|
if (it != map.end()) {
|
2001-07-12 11:11:10 +00:00
|
|
|
return it->second;
|
2000-08-14 09:44:53 +00:00
|
|
|
}
|
2000-07-31 12:30:10 +00:00
|
|
|
|
2000-08-14 09:44:53 +00:00
|
|
|
lyxerr << "BUG: No radio button found to be active." << endl;
|
2000-07-31 12:30:10 +00:00
|
|
|
|
2000-08-14 09:44:53 +00:00
|
|
|
// Else return 0.
|
|
|
|
return 0;
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|