#ifndef __ParamSlider_h__
#define __ParamSlider_h__
#include <string>
#include <map>
#include <DAQ++/DAQid.h>
#include <gtk/gtk.h>
#include <gui/SpinSlider.h>
/**
* This class binds a Module parameter with a GtkAdjustment which can
* come from a GtkScale, a GtkSpinButton, etc. Changes in the adjustment
* will be sent to the Module parameter.
*
* The class mantains a static list of existing mappings.
*/
class ParamSlider
{
public:
/**
* This is a dictionary to associate parameters to
* GtkAdjustments
*/
typedef std::map<std::string, ParamSlider *> SliderList;
private:
GtkAdjustment *adj;
DAQpp::DAQid _id;
std::string par_name;
int cb_id;
void init();
/**
* This is the function in charge of forwarding the change in the
* GtkAdjustment value to the corresponding Parameter
*/
static void change_value(GtkAdjustment *w, ParamSlider *ptr);
/*
* This static dictionary that will keep the association between
* DAQ++ parameters and GtkAdjustments
*/
static SliderList vlist;
public:
/**
* \brief constructor
* @param id the DAQid of the module
* @param p the name of the module parameter
* @param w the GtkAdjustment
*/
ParamSlider(const DAQpp::DAQid &id, const std::string &p, GtkAdjustment *w) :
adj(w), _id(id), par_name(p), cb_id(-1)
{
init();
}
~ParamSlider()
{
}
// Returns the parameter id
const DAQpp::DAQid &get_id() const
{
return _id;
}
// Returns the parameter name
const std::string &get_par_name() const
{
return par_name;
}
/**
* Sets a new value.
* It will also emit the corresponding GLib signal
*/
void set_value(double x)
{
gtk_adjustment_set_value(adj, x);
}
/**
* Sets a new value. No GLib signal will be emitted
*/
void set_value_silent(double x)
{
g_signal_handler_block(adj, cb_id);
gtk_adjustment_set_value(adj, x);
g_signal_handler_unblock(adj, cb_id);
}
/**
* Returns the value of the GtkAdjustment
*/
double get_value() const
{
return gtk_adjustment_get_value(adj);
}
/**
* Deletes all the ParamSlider objects
*/
static void delete_all();
/**
* A ParamSlider Factory that creates the adequate link
* between the adjustment and the given adjustment
* @param id the DAQid of the module
* @param p the name of the module parameter
* @param o the GtkAdjustment
*/
static ParamSlider *new_slider(const DAQpp::DAQid &id,
const std::string &p,
GtkAdjustment *o);
/**
* Finds the corresponding ParamSlider associated with this name
*/
static ParamSlider *find(const std::string &);
/**
* Removes the ParamSlider associated with the given name
*/
static void remove(const std::string &);
};
#endif