mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-24 10:40:48 +00:00
67fbbc0fb2
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3822 a592a061-630c-0410-9148-cb99ea01b6c8
87 lines
1.6 KiB
C
87 lines
1.6 KiB
C
/**
|
|
* \file RadioButtonGroup.C
|
|
* Copyright 1995 Matthias Ettrich.
|
|
* Copyright 1995-2001 The LyX Team.
|
|
* Copyright 2000 Baruch Even
|
|
* See the file COPYING.
|
|
*
|
|
* \author Baruch Even, baruch.even@writeme.com
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#ifdef __GNUG__
|
|
#pragma implementation
|
|
#endif
|
|
|
|
#include "RadioButtonGroup.h"
|
|
|
|
#include "debug.h" // for lyxerr
|
|
#include "support/lyxfunctional.h"
|
|
|
|
//#include <functional>
|
|
#include <algorithm>
|
|
#include <iterator>
|
|
|
|
using std::find_if;
|
|
//using std::bind2nd;
|
|
using std::endl;
|
|
|
|
|
|
void RadioButtonGroup::init(FL_OBJECT *button, size_type value)
|
|
{
|
|
map.push_back(ButtonValuePair(button, value));
|
|
}
|
|
|
|
|
|
void RadioButtonGroup::reset()
|
|
{
|
|
map.clear();
|
|
}
|
|
|
|
|
|
void RadioButtonGroup::set(size_type value)
|
|
{
|
|
ButtonValueMap::const_iterator it =
|
|
find_if(map.begin(), map.end(),
|
|
lyx::equal_2nd_in_pair<ButtonValuePair>(value));
|
|
|
|
// If we found nothing, report it and return
|
|
if (it == map.end()) {
|
|
lyxerr << "BUG: Requested value in RadioButtonGroup doesn't exists"
|
|
<< endl;
|
|
}
|
|
else {
|
|
fl_set_button(it->first, 1);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
template < typename T >
|
|
struct is_set_button {
|
|
bool operator() (T const & item) const
|
|
{
|
|
return fl_get_button((item).first);
|
|
}
|
|
};
|
|
|
|
|
|
RadioButtonGroup::size_type RadioButtonGroup::get() const
|
|
{
|
|
// Find the first button that is active
|
|
ButtonValueMap::const_iterator it =
|
|
find_if(map.begin(), map.end(),
|
|
is_set_button<ButtonValuePair> ());
|
|
|
|
// If such a button was found, return its value.
|
|
if (it != map.end()) {
|
|
return it->second;
|
|
}
|
|
|
|
lyxerr << "BUG: No radio button found to be active." << endl;
|
|
|
|
// Else return 0.
|
|
return 0;
|
|
}
|