~ubuntu-branches/ubuntu/utopic/inkscape/utopic-proposed

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/ui/widget/registered-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
/** \file
 
2
 * \brief
 
3
 *
 
4
 * Authors:
 
5
 *   Ralf Stephan <ralf@ark.in-berlin.de>
 
6
 *   Johan Engelen <j.b.c.engelen@utwente.nl>
 
7
 *
 
8
 * Copyright (C) 2005-2008 Authors
 
9
 *
 
10
 * Released under GNU GPL.  Read the file 'COPYING' for more information.
 
11
 */
 
12
 
 
13
#ifndef INKSCAPE_UI_WIDGET_REGISTERED_WIDGET__H_
 
14
#define INKSCAPE_UI_WIDGET_REGISTERED_WIDGET__H_
 
15
 
 
16
#include <gtkmm/box.h>
 
17
#include <gtkmm/adjustment.h>
 
18
#include <gtkmm/tooltips.h>
 
19
#include <gtkmm/togglebutton.h>
 
20
#include <2geom/matrix.h>
 
21
#include "xml/node.h"
 
22
#include "registry.h"
 
23
 
 
24
#include "ui/widget/scalar.h"
 
25
#include "ui/widget/scalar-unit.h"
 
26
#include "ui/widget/point.h"
 
27
#include "ui/widget/text.h"
 
28
#include "ui/widget/random.h"
 
29
#include "ui/widget/unit-menu.h"
 
30
#include "ui/widget/color-picker.h"
 
31
#include "inkscape.h"
 
32
 
 
33
#include "document.h"
 
34
#include "desktop-handles.h"
 
35
#include "sp-namedview.h"
 
36
 
 
37
class SPUnit;
 
38
class SPDocument;
 
39
 
 
40
namespace Gtk {
 
41
    class HScale;
 
42
    class RadioButton;
 
43
    class SpinButton;
 
44
}
 
45
 
 
46
namespace Inkscape {
 
47
namespace UI {
 
48
namespace Widget {
 
49
 
 
50
class Registry;
 
51
 
 
52
template <class W>
 
53
class RegisteredWidget : public W {
 
54
public:
 
55
    void set_undo_parameters(const unsigned int _event_type, Glib::ustring _event_description)
 
56
    {
 
57
        event_type = _event_type;
 
58
        event_description = _event_description;
 
59
        write_undo = true;
 
60
    }
 
61
 
 
62
    bool is_updating() {if (_wr) return _wr->isUpdating(); else return false;}
 
63
 
 
64
    // provide automatic 'upcast' for ease of use. (do it 'dynamic_cast' instead of 'static' because who knows what W is)
 
65
    operator const Gtk::Widget () { return dynamic_cast<Gtk::Widget*>(this); }
 
66
 
 
67
protected:
 
68
    RegisteredWidget() : W() { construct(); }
 
69
    template< typename A >
 
70
    explicit RegisteredWidget( A& a ): W( a ) { construct(); }
 
71
    template< typename A, typename B >
 
72
    RegisteredWidget( A& a, B& b ): W( a, b ) { construct(); }
 
73
    template< typename A, typename B, typename C >
 
74
    RegisteredWidget( A& a, B& b, C* c ): W( a, b, c ) { construct(); }
 
75
    template< typename A, typename B, typename C >
 
76
    RegisteredWidget( A& a, B& b, C& c ): W( a, b, c ) { construct(); }
 
77
    template< typename A, typename B, typename C, typename D >
 
78
    RegisteredWidget( A& a, B& b, C c, D d ): W( a, b, c, d ) { construct(); }
 
79
    template< typename A, typename B, typename C, typename D, typename E , typename F>
 
80
    RegisteredWidget( A& a, B& b, C c, D& d, E& e, F* f): W( a, b, c, d, e, f) { construct(); }
 
81
 
 
82
    virtual ~RegisteredWidget() {};
 
83
 
 
84
    void init_parent(const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in)
 
85
    {
 
86
        _wr = &wr;
 
87
        _key = key;
 
88
        repr = repr_in;
 
89
        doc = doc_in;
 
90
        if (repr && !doc)  // doc cannot be NULL when repr is not NULL
 
91
            g_warning("Initialization of registered widget using defined repr but with doc==NULL");
 
92
    }
 
93
 
 
94
    void write_to_xml(const char * svgstr)
 
95
    {
 
96
        // Use local repr here. When repr is specified, use that one, but
 
97
        // if repr==NULL, get the repr of namedview of active desktop.
 
98
        Inkscape::XML::Node *local_repr = repr;
 
99
        SPDocument *local_doc = doc;
 
100
        if (!local_repr) {
 
101
            // no repr specified, use active desktop's namedview's repr
 
102
            SPDesktop* dt = SP_ACTIVE_DESKTOP;
 
103
            local_repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
 
104
            local_doc = sp_desktop_document(dt);
 
105
        }
 
106
 
 
107
        bool saved = sp_document_get_undo_sensitive (local_doc);
 
108
        sp_document_set_undo_sensitive (local_doc, false);
 
109
        if (!write_undo) local_repr->setAttribute(_key.c_str(), svgstr);
 
110
        sp_document_set_undo_sensitive (local_doc, saved);
 
111
 
 
112
        local_doc->setModifiedSinceSave();
 
113
 
 
114
        if (write_undo) {
 
115
            local_repr->setAttribute(_key.c_str(), svgstr);
 
116
            sp_document_done (local_doc, event_type, event_description);
 
117
        }
 
118
    }
 
119
 
 
120
    Registry * _wr;
 
121
    Glib::ustring _key;
 
122
    Inkscape::XML::Node * repr;
 
123
    SPDocument * doc;
 
124
    unsigned int event_type;
 
125
    Glib::ustring event_description;
 
126
    bool write_undo;
 
127
 
 
128
private:
 
129
    void construct() {
 
130
        _wr = NULL;
 
131
        repr = NULL;
 
132
        doc = NULL;
 
133
        write_undo = false;
 
134
    }
 
135
};
 
136
 
 
137
//#######################################################
 
138
 
 
139
class RegisteredCheckButton : public RegisteredWidget<Gtk::CheckButton> {
 
140
public:
 
141
    virtual ~RegisteredCheckButton();
 
142
    RegisteredCheckButton (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right=true, Inkscape::XML::Node* repr_in=NULL, SPDocument *doc_in=NULL);
 
143
 
 
144
    void setActive (bool);
 
145
 
 
146
    std::list<Gtk::Widget*> _slavewidgets;
 
147
 
 
148
    // a slave button is only sensitive when the master button is active
 
149
    // i.e. a slave button is greyed-out when the master button is not checked
 
150
 
 
151
    void setSlaveWidgets(std::list<Gtk::Widget*> btns) {
 
152
        _slavewidgets = btns;
 
153
    }
 
154
 
 
155
    bool setProgrammatically; // true if the value was set by setActive, not changed by the user;
 
156
                                // if a callback checks it, it must reset it back to false
 
157
 
 
158
protected:
 
159
    Gtk::Tooltips     _tt;
 
160
    sigc::connection  _toggled_connection;
 
161
    void on_toggled();
 
162
};
 
163
 
 
164
class RegisteredUnitMenu : public RegisteredWidget<Labelled> {
 
165
public:
 
166
    ~RegisteredUnitMenu();
 
167
    RegisteredUnitMenu ( const Glib::ustring& label,
 
168
                         const Glib::ustring& key,
 
169
                         Registry& wr,
 
170
                         Inkscape::XML::Node* repr_in = NULL,
 
171
                         SPDocument *doc_in = NULL );
 
172
 
 
173
    void setUnit (const SPUnit*);
 
174
    Unit getUnit() const { return static_cast<UnitMenu*>(_widget)->getUnit(); };
 
175
    UnitMenu* getUnitMenu() const { return static_cast<UnitMenu*>(_widget); };
 
176
    sigc::connection _changed_connection;
 
177
 
 
178
protected:
 
179
    void on_changed();
 
180
};
 
181
 
 
182
class RegisteredScalarUnit : public RegisteredWidget<ScalarUnit> {
 
183
public:
 
184
    ~RegisteredScalarUnit();
 
185
    RegisteredScalarUnit ( const Glib::ustring& label,
 
186
                           const Glib::ustring& tip,
 
187
                           const Glib::ustring& key,
 
188
                           const RegisteredUnitMenu &rum,
 
189
                           Registry& wr,
 
190
                           Inkscape::XML::Node* repr_in = NULL,
 
191
                           SPDocument *doc_in = NULL );
 
192
 
 
193
protected:
 
194
    sigc::connection  _value_changed_connection;
 
195
    UnitMenu         *_um;
 
196
    void on_value_changed();
 
197
};
 
198
 
 
199
class RegisteredScalar : public RegisteredWidget<Scalar> {
 
200
public:
 
201
    virtual ~RegisteredScalar();
 
202
    RegisteredScalar (const Glib::ustring& label,
 
203
            const Glib::ustring& tip,
 
204
            const Glib::ustring& key,
 
205
            Registry& wr,
 
206
            Inkscape::XML::Node* repr_in = NULL,
 
207
            SPDocument *doc_in = NULL );
 
208
 
 
209
protected:
 
210
    sigc::connection  _value_changed_connection;
 
211
    void on_value_changed();
 
212
};
 
213
 
 
214
class RegisteredText : public RegisteredWidget<Text> {
 
215
public:
 
216
    virtual ~RegisteredText();
 
217
    RegisteredText (const Glib::ustring& label,
 
218
            const Glib::ustring& tip,
 
219
            const Glib::ustring& key,
 
220
            Registry& wr,
 
221
            Inkscape::XML::Node* repr_in = NULL,
 
222
            SPDocument *doc_in = NULL );
 
223
 
 
224
protected:
 
225
    sigc::connection  _activate_connection;
 
226
    void on_activate();
 
227
};
 
228
 
 
229
class RegisteredColorPicker : public RegisteredWidget<ColorPicker> {
 
230
public:
 
231
    virtual ~RegisteredColorPicker();
 
232
 
 
233
    RegisteredColorPicker (const Glib::ustring& label,
 
234
                           const Glib::ustring& title,
 
235
                           const Glib::ustring& tip,
 
236
                           const Glib::ustring& ckey,
 
237
                           const Glib::ustring& akey,
 
238
                           Registry& wr,
 
239
                           Inkscape::XML::Node* repr_in = NULL,
 
240
                           SPDocument *doc_in = NULL);
 
241
 
 
242
    void setRgba32 (guint32);
 
243
    void closeWindow();
 
244
 
 
245
    Gtk::Label *_label;
 
246
 
 
247
protected:
 
248
    Glib::ustring _ckey, _akey;
 
249
    void on_changed (guint32);
 
250
    sigc::connection _changed_connection;
 
251
};
 
252
 
 
253
class RegisteredSuffixedInteger : public RegisteredWidget<Scalar> {
 
254
public:
 
255
    virtual ~RegisteredSuffixedInteger();
 
256
    RegisteredSuffixedInteger ( const Glib::ustring& label,
 
257
                                const Glib::ustring& tip, 
 
258
                                const Glib::ustring& suffix,
 
259
                                const Glib::ustring& key,
 
260
                                Registry& wr,
 
261
                                Inkscape::XML::Node* repr_in = NULL,
 
262
                                SPDocument *doc_in = NULL );
 
263
 
 
264
    bool setProgrammatically; // true if the value was set by setValue, not changed by the user;
 
265
                                // if a callback checks it, it must reset it back to false
 
266
 
 
267
protected:
 
268
    sigc::connection _changed_connection;
 
269
    void on_value_changed();
 
270
};
 
271
 
 
272
class RegisteredRadioButtonPair : public RegisteredWidget<Gtk::HBox> {
 
273
public:
 
274
    virtual ~RegisteredRadioButtonPair();
 
275
    RegisteredRadioButtonPair ( const Glib::ustring& label,
 
276
                                const Glib::ustring& label1,
 
277
                                const Glib::ustring& label2,
 
278
                                const Glib::ustring& tip1,
 
279
                                const Glib::ustring& tip2,
 
280
                                const Glib::ustring& key,
 
281
                                Registry& wr,
 
282
                                Inkscape::XML::Node* repr_in = NULL,
 
283
                                SPDocument *doc_in = NULL );
 
284
 
 
285
    void setValue (bool second);
 
286
 
 
287
    bool setProgrammatically; // true if the value was set by setValue, not changed by the user;
 
288
                                    // if a callback checks it, it must reset it back to false
 
289
protected:
 
290
    Gtk::RadioButton *_rb1, *_rb2;
 
291
    Gtk::Tooltips     _tt;
 
292
    sigc::connection _changed_connection;
 
293
    void on_value_changed();
 
294
};
 
295
 
 
296
class RegisteredPoint : public RegisteredWidget<Point> {
 
297
public:
 
298
    virtual ~RegisteredPoint();
 
299
    RegisteredPoint ( const Glib::ustring& label,
 
300
                      const Glib::ustring& tip,
 
301
                      const Glib::ustring& key,
 
302
                      Registry& wr,
 
303
                      Inkscape::XML::Node* repr_in = NULL,
 
304
                      SPDocument *doc_in = NULL );
 
305
 
 
306
protected:
 
307
    sigc::connection  _value_x_changed_connection;
 
308
    sigc::connection  _value_y_changed_connection;
 
309
    void on_value_changed();
 
310
};
 
311
 
 
312
 
 
313
class RegisteredTransformedPoint : public RegisteredWidget<Point> {
 
314
public:
 
315
    virtual ~RegisteredTransformedPoint();
 
316
    RegisteredTransformedPoint (  const Glib::ustring& label,
 
317
                                  const Glib::ustring& tip,
 
318
                                  const Glib::ustring& key,
 
319
                                  Registry& wr,
 
320
                                  Inkscape::XML::Node* repr_in = NULL,
 
321
                                  SPDocument *doc_in = NULL );
 
322
 
 
323
    // redefine setValue, because transform must be applied
 
324
    void setValue(Geom::Point const & p);
 
325
 
 
326
    void setTransform(Geom::Matrix const & canvas_to_svg);
 
327
 
 
328
protected:
 
329
    sigc::connection  _value_x_changed_connection;
 
330
    sigc::connection  _value_y_changed_connection;
 
331
    void on_value_changed();
 
332
 
 
333
    Geom::Matrix to_svg;
 
334
};
 
335
 
 
336
 
 
337
class RegisteredRandom : public RegisteredWidget<Random> {
 
338
public:
 
339
    virtual ~RegisteredRandom();
 
340
    RegisteredRandom ( const Glib::ustring& label,
 
341
                       const Glib::ustring& tip,
 
342
                       const Glib::ustring& key,
 
343
                       Registry& wr,
 
344
                       Inkscape::XML::Node* repr_in = NULL,
 
345
                       SPDocument *doc_in = NULL);
 
346
 
 
347
    void setValue (double val, long startseed);
 
348
 
 
349
protected:
 
350
    sigc::connection  _value_changed_connection;
 
351
    sigc::connection  _reseeded_connection;
 
352
    void on_value_changed();
 
353
};
 
354
 
 
355
} // namespace Widget
 
356
} // namespace UI
 
357
} // namespace Inkscape
 
358
 
 
359
#endif // INKSCAPE_UI_WIDGET_REGISTERED_WIDGET__H_
 
360
 
 
361
/*
 
362
  Local Variables:
 
363
  mode:c++
 
364
  c-file-style:"stroustrup"
 
365
  c-file-offsets:((innamespace . 0)(inline-open . 0))
 
366
  indent-tabs-mode:nil
 
367
  fill-column:99
 
368
  End:
 
369
*/
 
370
// vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :