2002-03-11 17:00:41 +00:00
|
|
|
/**
|
|
|
|
* \file RadioButtonGroup.C
|
|
|
|
* Copyright 1995 Matthias Ettrich.
|
|
|
|
* Copyright 2000 Baruch Even
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2000-07-31 12:30:10 +00:00
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
* \author Baruch Even
|
2002-10-23 08:31:10 +00:00
|
|
|
* \author Rob Lahaye
|
2002-09-05 14:10:50 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2002-03-11 17:00:41 +00:00
|
|
|
*/
|
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"
|
2002-06-13 13:43:51 +00:00
|
|
|
#include FORMS_H_LOCATION
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
#include "debug.h" // for lyxerr
|
2002-02-16 15:59:55 +00:00
|
|
|
#include "support/lyxfunctional.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iterator>
|
2000-07-31 12:30:10 +00:00
|
|
|
|
|
|
|
using std::find_if;
|
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-10-23 08:31:10 +00:00
|
|
|
void RadioButtonGroup::init(FL_OBJECT * ob, size_type value)
|
2000-07-31 12:30:10 +00:00
|
|
|
{
|
2002-10-23 08:31:10 +00:00
|
|
|
map.push_back(ButtonValuePair(ob, value));
|
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
|
|
|
|
2002-10-23 08:31:10 +00:00
|
|
|
if (it != map.end()) {
|
|
|
|
set(it->first);
|
|
|
|
} else {
|
|
|
|
// We found nothing: report it and do nothing.
|
|
|
|
lyxerr << "BUG: Requested value in RadioButtonGroup "
|
|
|
|
"doesn't exist" << endl;
|
2000-08-14 09:44:53 +00:00
|
|
|
}
|
2002-10-23 08:31:10 +00:00
|
|
|
}
|
|
|
|
|
2000-08-14 09:44:53 +00:00
|
|
|
|
2002-10-23 08:31:10 +00:00
|
|
|
void RadioButtonGroup::set(FL_OBJECT * ob)
|
|
|
|
{
|
|
|
|
fl_set_button(ob, 1);
|
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
|
|
|
{
|
2002-10-23 08:31:10 +00:00
|
|
|
// Find the active button.
|
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
|
|
|
|
2002-10-23 08:31:10 +00:00
|
|
|
if (it != map.end())
|
2001-07-12 11:11:10 +00:00
|
|
|
return it->second;
|
2000-07-31 12:30:10 +00:00
|
|
|
|
2002-10-23 08:31:10 +00:00
|
|
|
// We found nothing: report it and return 0
|
|
|
|
lyxerr << "BUG: No active radio button found." << endl;
|
2000-08-14 09:44:53 +00:00
|
|
|
return 0;
|
2000-07-31 12:30:10 +00:00
|
|
|
}
|