~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/ui/widget/attr-widget.h

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * \brief Very basic interface for classes that control attributes
 
3
 *
 
4
 * Authors:
 
5
 *   Nicholas Bishop <nicholasbishop@gmail.com>
 
6
 *   Rodrigo Kumpera <kumpera@gmail.com>
 
7
 *
 
8
 * Copyright (C) 2007 Authors
 
9
 *
 
10
 * Released under GNU GPL.  Read the file 'COPYING' for more information.
 
11
 */
 
12
 
 
13
#ifndef INKSCAPE_UI_WIDGET_ATTR_WIDGET_H
 
14
#define INKSCAPE_UI_WIDGET_ATTR_WIDGET_H
 
15
 
 
16
#include "attributes.h"
 
17
#include "sp-object.h"
 
18
#include "xml/node.h"
 
19
#include <gtkmm/tooltips.h>
 
20
 
 
21
namespace Inkscape {
 
22
namespace UI {
 
23
namespace Widget {
 
24
 
 
25
enum DefaultValueType
 
26
{
 
27
    T_NONE,
 
28
    T_DOUBLE,
 
29
    T_VECT_DOUBLE,
 
30
    T_BOOL,
 
31
    T_UINT,
 
32
    T_CHARPTR
 
33
};
 
34
 
 
35
class DefaultValueHolder
 
36
{
 
37
    DefaultValueType type;
 
38
    union {
 
39
        double d_val;
 
40
        std::vector<double>* vt_val;
 
41
        bool b_val;
 
42
        unsigned int uint_val;
 
43
        char* cptr_val;
 
44
    } value;
 
45
 
 
46
    //FIXME remove copy ctor and assignment operator as private to avoid double free of the vector
 
47
public:
 
48
    DefaultValueHolder () {
 
49
        type = T_NONE;
 
50
    }
 
51
 
 
52
    DefaultValueHolder (double d) {
 
53
        type = T_DOUBLE;
 
54
        value.d_val = d;
 
55
    }
 
56
 
 
57
    DefaultValueHolder (std::vector<double>* d) {
 
58
        type = T_VECT_DOUBLE;
 
59
        value.vt_val = d;
 
60
    }
 
61
 
 
62
    DefaultValueHolder (char* c) {
 
63
        type = T_CHARPTR;
 
64
        value.cptr_val = c;
 
65
    }
 
66
 
 
67
    DefaultValueHolder (bool d) {
 
68
        type = T_BOOL;
 
69
        value.b_val = d;
 
70
    }
 
71
 
 
72
    DefaultValueHolder (unsigned int ui) {
 
73
        type = T_UINT;
 
74
        value.uint_val = ui;
 
75
    }
 
76
 
 
77
    ~DefaultValueHolder() {
 
78
        if (type == T_VECT_DOUBLE)
 
79
            delete value.vt_val;
 
80
    }
 
81
 
 
82
    unsigned int as_uint() {
 
83
        g_assert (type == T_UINT);
 
84
        return value.uint_val;
 
85
    }
 
86
 
 
87
    bool as_bool() {
 
88
        g_assert (type == T_BOOL);
 
89
        return value.b_val;
 
90
    }
 
91
 
 
92
    double as_double() {
 
93
        g_assert (type == T_DOUBLE);
 
94
        return value.d_val;
 
95
    }
 
96
 
 
97
    std::vector<double>* as_vector() {
 
98
        g_assert (type == T_VECT_DOUBLE);
 
99
        return value.vt_val;
 
100
    }
 
101
 
 
102
    char* as_charptr() {
 
103
        g_assert (type == T_CHARPTR);
 
104
        return value.cptr_val;
 
105
    }
 
106
};
 
107
 
 
108
class AttrWidget
 
109
{
 
110
public:
 
111
    AttrWidget(const SPAttributeEnum a, unsigned int value)
 
112
        : _attr(a),
 
113
          _default(value)
 
114
    {}
 
115
 
 
116
    AttrWidget(const SPAttributeEnum a, double value)
 
117
        : _attr(a),
 
118
          _default(value)
 
119
    {}
 
120
 
 
121
    AttrWidget(const SPAttributeEnum a, bool value)
 
122
        : _attr(a),
 
123
          _default(value)
 
124
    {}
 
125
 
 
126
    AttrWidget(const SPAttributeEnum a)
 
127
        : _attr(a),
 
128
          _default()
 
129
    {}
 
130
 
 
131
    virtual ~AttrWidget()
 
132
    {}
 
133
 
 
134
    virtual Glib::ustring get_as_attribute() const = 0;
 
135
    virtual void set_from_attribute(SPObject*) = 0;
 
136
 
 
137
    SPAttributeEnum get_attribute() const
 
138
    {
 
139
        return _attr;
 
140
    }
 
141
 
 
142
    sigc::signal<void>& signal_attr_changed()
 
143
    {
 
144
        return _signal;
 
145
    }
 
146
protected:
 
147
    DefaultValueHolder* get_default() { return &_default; }
 
148
    const gchar* attribute_value(SPObject* o) const
 
149
    {
 
150
        const gchar* name = (const gchar*)sp_attribute_name(_attr);
 
151
        if(name && o) {
 
152
            const gchar* val = SP_OBJECT_REPR(o)->attribute(name);
 
153
            return val;
 
154
        }
 
155
        return 0;
 
156
    }
 
157
 
 
158
protected:
 
159
    Gtk::Tooltips _tt;
 
160
 
 
161
private:
 
162
    const SPAttributeEnum _attr;
 
163
    DefaultValueHolder _default;
 
164
    sigc::signal<void> _signal;
 
165
};
 
166
 
 
167
}
 
168
}
 
169
}
 
170
 
 
171
#endif
 
172
 
 
173
/*
 
174
  Local Variables:
 
175
  mode:c++
 
176
  c-file-style:"stroustrup"
 
177
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
178
  indent-tabs-mode:nil
 
179
  fill-column:99
 
180
  End:
 
181
*/
 
182
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :