2
* Copyright (C) 2005-2007 Authors:
3
* Ted Gould <ted@gould.cx>
4
* Johan Engelen <johan@shouraizou.nl> *
5
* Released under GNU GPL, read the file 'COPYING' for more information
12
#include <gtkmm/adjustment.h>
13
#include <gtkmm/box.h>
14
#include <gtkmm/spinbutton.h>
18
#include "extension.h"
19
#include "parambool.h"
24
/** \brief Use the superclass' allocator and set the \c _value */
25
ParamBool::ParamBool (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :
26
Parameter(name, guitext, desc, scope, ext), _value(false)
28
const char * defaultval = NULL;
29
if (sp_repr_children(xml) != NULL)
30
defaultval = sp_repr_children(xml)->content();
32
if (defaultval != NULL && (!strcmp(defaultval, "TRUE") || !strcmp(defaultval, "true") || !strcmp(defaultval, "1"))) {
38
gchar * pref_name = this->pref_name();
39
_value = (bool)prefs_get_int_attribute(PREF_DIR, pref_name, _value);
45
/** \brief A function to set the \c _value
46
\param in The value to set to
47
\param doc A document that should be used to set the value.
48
\param node The node where the value may be placed
50
This function sets the internal value, but it also sets the value
51
in the preferences structure. To put it in the right place, \c PREF_DIR
52
and \c pref_name() are used.
55
ParamBool::set( bool in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ )
59
gchar * prefname = this->pref_name();
60
prefs_set_int_attribute(PREF_DIR, prefname, _value == true ? 1 : 0);
66
/** \brief A check button which is Param aware. It works with the
67
parameter to change it's value as the check button changes
69
class ParamBoolCheckButton : public Gtk::CheckButton {
71
/** \brief Param to change */
74
Inkscape::XML::Node * _node;
75
sigc::signal<void> * _changeSignal;
77
/** \brief Initialize the check button
78
\param param Which parameter to adjust on changing the check button
80
This function sets the value of the checkbox to be that of the
81
parameter, and then sets up a callback to \c on_toggle.
83
ParamBoolCheckButton (ParamBool * param, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) :
84
Gtk::CheckButton(), _pref(param), _doc(doc), _node(node), _changeSignal(changeSignal) {
85
this->set_active(_pref->get(NULL, NULL) /**\todo fix */);
86
this->signal_toggled().connect(sigc::mem_fun(this, &ParamBoolCheckButton::on_toggle));
89
void on_toggle (void);
93
\brief A function to respond to the check box changing
95
Adjusts the value of the preference to match that in the check box.
98
ParamBoolCheckButton::on_toggle (void)
100
_pref->set(this->get_active(), NULL /**\todo fix this */, NULL);
101
if (_changeSignal != NULL) {
102
_changeSignal->emit();
107
/** \brief Return 'true' or 'false' */
109
ParamBool::string (std::string &string)
121
\brief Creates a bool check button for a bool parameter
123
Builds a hbox with a label and a check button in it.
126
ParamBool::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal)
128
Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4));
130
Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT));
132
hbox->pack_start(*label, true, true);
134
ParamBoolCheckButton * checkbox = new ParamBoolCheckButton(this, doc, node, changeSignal);
136
hbox->pack_start(*checkbox, false, false);
140
return dynamic_cast<Gtk::Widget *>(hbox);
143
} /* namespace Extension */
144
} /* namespace Inkscape */