~valavanisalex/ubuntu/oneiric/inkscape/inkscape_0.48.1-2ubuntu4

« back to all changes in this revision

Viewing changes to src/extension/parambool.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook, Ted Gould, Kees Cook
  • Date: 2009-06-24 14:00:43 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624140043-07stp20mry48hqup
Tags: 0.47~pre0-0ubuntu1
* New upstream release

[ Ted Gould ]
* debian/control: Adding libgsl0 and removing version specifics on boost

[ Kees Cook ]
* debian/watch: updated to run uupdate and mangle pre-release versions.
* Dropped patches that have been taken upstream:
  - 01_mips
  - 02-poppler-0.8.3
  - 03-chinese-inkscape
  - 05_fix_latex_patch
  - 06_gcc-4.4
  - 07_cdr2svg
  - 08_skip-bad-utf-on-pdf-import
  - 09_gtk-clist
  - 10_belarussian
  - 11_libpng
  - 12_desktop
  - 13_slider
  - 100_svg_import_improvements
  - 102_sp_pattern_painter_free
  - 103_bitmap_type_print

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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
6
 
 */
7
 
 
8
 
#ifdef HAVE_CONFIG_H
9
 
# include "config.h"
10
 
#endif
11
 
 
12
 
#include <gtkmm/adjustment.h>
13
 
#include <gtkmm/box.h>
14
 
#include <gtkmm/spinbutton.h>
15
 
 
16
 
#include <xml/node.h>
17
 
 
18
 
#include "extension.h"
19
 
#include "parambool.h"
20
 
 
21
 
namespace Inkscape {
22
 
namespace Extension {
23
 
 
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)
27
 
{
28
 
    const char * defaultval = NULL;
29
 
    if (sp_repr_children(xml) != NULL)
30
 
        defaultval = sp_repr_children(xml)->content();
31
 
 
32
 
    if (defaultval != NULL && (!strcmp(defaultval, "TRUE") || !strcmp(defaultval, "true") || !strcmp(defaultval, "1"))) {
33
 
        _value = true;
34
 
    } else {
35
 
        _value = false;
36
 
    }
37
 
 
38
 
    gchar * pref_name = this->pref_name();
39
 
    _value = (bool)prefs_get_int_attribute(PREF_DIR, pref_name, _value);
40
 
    g_free(pref_name);
41
 
 
42
 
    return;
43
 
}
44
 
 
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
49
 
 
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.
53
 
*/
54
 
bool
55
 
ParamBool::set( bool in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/ )
56
 
{
57
 
    _value = in;
58
 
 
59
 
    gchar * prefname = this->pref_name();
60
 
    prefs_set_int_attribute(PREF_DIR, prefname, _value == true ? 1 : 0);
61
 
    g_free(prefname);
62
 
 
63
 
    return _value;
64
 
}
65
 
 
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
68
 
            value. */
69
 
class ParamBoolCheckButton : public Gtk::CheckButton {
70
 
private:
71
 
    /** \brief  Param to change */
72
 
    ParamBool * _pref;
73
 
    SPDocument * _doc;
74
 
    Inkscape::XML::Node * _node;
75
 
    sigc::signal<void> * _changeSignal;
76
 
public:
77
 
    /** \brief  Initialize the check button
78
 
        \param  param  Which parameter to adjust on changing the check button
79
 
 
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.
82
 
    */
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));
87
 
        return;
88
 
    }
89
 
    void on_toggle (void);
90
 
};
91
 
 
92
 
/**
93
 
    \brief  A function to respond to the check box changing
94
 
 
95
 
    Adjusts the value of the preference to match that in the check box.
96
 
*/
97
 
void
98
 
ParamBoolCheckButton::on_toggle (void)
99
 
{
100
 
    _pref->set(this->get_active(), NULL /**\todo fix this */, NULL);
101
 
    if (_changeSignal != NULL) {
102
 
        _changeSignal->emit();
103
 
    }
104
 
    return;
105
 
}
106
 
 
107
 
/** \brief  Return 'true' or 'false' */
108
 
void
109
 
ParamBool::string (std::string &string)
110
 
{
111
 
    if (_value) {
112
 
        string += "true";
113
 
    } else {
114
 
        string += "false";
115
 
    }
116
 
 
117
 
    return;
118
 
}
119
 
 
120
 
/**
121
 
    \brief  Creates a bool check button for a bool parameter
122
 
 
123
 
    Builds a hbox with a label and a check button in it.
124
 
*/
125
 
Gtk::Widget *
126
 
ParamBool::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal)
127
 
{
128
 
    Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4));
129
 
 
130
 
    Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT));
131
 
    label->show();
132
 
    hbox->pack_start(*label, true, true);
133
 
 
134
 
    ParamBoolCheckButton * checkbox = new ParamBoolCheckButton(this, doc, node, changeSignal);
135
 
    checkbox->show();
136
 
    hbox->pack_start(*checkbox, false, false);
137
 
 
138
 
    hbox->show();
139
 
 
140
 
    return dynamic_cast<Gtk::Widget *>(hbox);
141
 
}
142
 
 
143
 
}  /* namespace Extension */
144
 
}  /* namespace Inkscape */