~ubuntu-branches/debian/squeeze/inkscape/squeeze

« back to all changes in this revision

Viewing changes to src/ui/widget/style-swatch.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-09-09 23:29:02 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080909232902-c50iujhk1w79u8e7
Tags: 0.46-2.1
* Non-maintainer upload.
* Add upstream patch fixing a crash in the open dialog
  in the zh_CN.utf8 locale. Closes: #487623.
  Thanks to Luca Bruno for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
# include <config.h>
14
14
#endif
15
15
 
 
16
#include <cstring>
 
17
#include <string>
 
18
 
16
19
#include "style-swatch.h"
17
20
 
18
21
#include "widgets/spw-utilities.h"
26
29
#include "xml/node-event-vector.h"
27
30
#include "widgets/widget-sizes.h"
28
31
#include "helper/units.h"
 
32
#include "helper/action.h"
29
33
#include "inkscape.h"
30
34
 
31
35
enum {
33
37
    SS_STROKE
34
38
};
35
39
 
36
 
static void style_swatch_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
37
 
                                       gchar const *old_value, gchar const *new_value,
38
 
                                       bool is_interactive, gpointer data)
 
40
static void style_swatch_attr_changed( Inkscape::XML::Node *repr, gchar const *name,
 
41
                                       gchar const */*old_value*/, gchar const */*new_value*/,
 
42
                                       bool /*is_interactive*/, gpointer data)
39
43
{
40
44
    Inkscape::UI::Widget::StyleSwatch *ss = (Inkscape::UI::Widget::StyleSwatch *) data;
41
45
 
56
60
};
57
61
 
58
62
 
59
 
static void style_swatch_tool_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
60
 
                                       gchar const *old_value, gchar const *new_value,
61
 
                                       bool is_interactive, gpointer data)
 
63
static void style_swatch_tool_attr_changed( Inkscape::XML::Node */*repr*/, gchar const *name,
 
64
                                            gchar const */*old_value*/, gchar const *new_value,
 
65
                                            bool /*is_interactive*/, gpointer data)
62
66
{
63
67
    Inkscape::UI::Widget::StyleSwatch *ss = (Inkscape::UI::Widget::StyleSwatch *) data;
64
 
 
 
68
 
65
69
    if (!strcmp (name, "usecurrent")) { // FIXME: watching only for the style attr, no CSS attrs
66
70
        if (!strcmp (new_value, "1")) {
67
71
            ss->setWatched (inkscape_get_repr(INKSCAPE, "desktop"), inkscape_get_repr(INKSCAPE, ss->_tool_path));
70
74
        }
71
75
        // UGLY HACK: we have to reconnect to the watched tool repr again, retrieving it from the stored
72
76
        // tool_path, because the actual repr keeps shifting with each change, no idea why
73
 
        ss->setWatchedTool(ss->_tool_path, false); 
 
77
        ss->setWatchedTool(ss->_tool_path, false);
74
78
    }
75
79
}
76
80
 
87
91
namespace UI {
88
92
namespace Widget {
89
93
 
90
 
StyleSwatch::StyleSwatch(SPCSSAttr *css)
91
 
    : 
 
94
StyleSwatch::StyleSwatch(SPCSSAttr *css, gchar const *main_tip)
 
95
    :
92
96
      _tool_path(NULL),
93
97
      _css (NULL),
94
98
 
101
105
 
102
106
      _tooltips ()
103
107
{
104
 
    _label[SS_FILL].set_markup(_("F:"));
105
 
    _label[SS_STROKE].set_markup(_("S:"));
 
108
    _label[SS_FILL].set_markup(_("Fill:"));
 
109
    _label[SS_STROKE].set_markup(_("Stroke:"));
106
110
 
107
111
    for (int i = SS_FILL; i <= SS_STROKE; i++) {
108
112
        _label[i].set_alignment(0.0, 0.5);
121
125
    _stroke_width_place.add(_stroke_width);
122
126
    _stroke.pack_start(_stroke_width_place, Gtk::PACK_SHRINK);
123
127
 
124
 
    _table.attach(_label[SS_FILL], 0,1, 0,1, Gtk::SHRINK, Gtk::SHRINK);
125
 
    _table.attach(_label[SS_STROKE], 0,1, 1,2, Gtk::SHRINK, Gtk::SHRINK);
 
128
    _table.attach(_label[SS_FILL], 0,1, 0,1, Gtk::FILL, Gtk::SHRINK);
 
129
    _table.attach(_label[SS_STROKE], 0,1, 1,2, Gtk::FILL, Gtk::SHRINK);
126
130
 
127
131
    _table.attach(_place[SS_FILL], 1,2, 0,1);
128
132
    _table.attach(_stroke, 1,2, 1,2);
130
134
    _opacity_place.add(_opacity_value);
131
135
    _table.attach(_opacity_place, 2,3, 0,2, Gtk::SHRINK, Gtk::SHRINK);
132
136
 
133
 
    pack_start(_table, true, true, 0);
 
137
    _swatch.add(_table);
 
138
    pack_start(_swatch, true, true, 0);
134
139
 
135
140
    set_size_request (STYLE_SWATCH_WIDTH, -1);
136
141
 
143
148
    }
144
149
 
145
150
    setStyle (css);
 
151
 
 
152
    _swatch.signal_button_press_event().connect(sigc::mem_fun(*this, &StyleSwatch::on_click));
 
153
 
 
154
    _tooltips.set_tip(_swatch, main_tip);
 
155
}
 
156
 
 
157
void StyleSwatch::setClickVerb(sp_verb_t verb_t) {
 
158
    _verb_t = verb_t;
 
159
}
 
160
 
 
161
void StyleSwatch::setDesktop(SPDesktop *desktop) {
 
162
    _desktop = desktop;
 
163
}
 
164
 
 
165
bool
 
166
StyleSwatch::on_click(GdkEventButton */*event*/)
 
167
{
 
168
    if (this->_desktop && this->_verb_t != SP_VERB_NONE) {
 
169
        Inkscape::Verb *verb = Inkscape::Verb::get(this->_verb_t);
 
170
        SPAction *action = verb->get_action((Inkscape::UI::View::View *) this->_desktop);
 
171
        sp_action_perform (action, NULL);
 
172
        return true;
 
173
    }
 
174
    return false;
146
175
}
147
176
 
148
177
StyleSwatch::~StyleSwatch()
149
178
{
150
 
    if (_css) 
 
179
    if (_css)
151
180
        sp_repr_css_attr_unref (_css);
152
181
 
153
182
    for (int i = SS_FILL; i <= SS_STROKE; i++) {
226
255
void
227
256
StyleSwatch::setStyle(SPCSSAttr *css)
228
257
{
229
 
    if (_css) 
 
258
    if (_css)
230
259
        sp_repr_css_attr_unref (_css);
231
260
 
232
261
    if (!css)
236
265
    sp_repr_css_merge(_css, css);
237
266
 
238
267
    gchar const *css_string = sp_repr_css_write_string (_css);
239
 
    SPStyle *temp_spstyle = sp_style_new();
 
268
    SPStyle *temp_spstyle = sp_style_new(SP_ACTIVE_DOCUMENT);
240
269
    if (css_string)
241
270
        sp_style_merge_from_style_string (temp_spstyle, css_string);
242
271
 
263
292
            paint = &(query->stroke);
264
293
        }
265
294
 
266
 
        if (paint->set && paint->type == SP_PAINT_TYPE_COLOR) {
267
 
            guint32 color = sp_color_get_rgba32_falpha (&(paint->value.color), 
268
 
                                                        SP_SCALE24_TO_FLOAT ((i == SS_FILL)? query->fill_opacity.value : query->stroke_opacity.value));
269
 
            ((Inkscape::UI::Widget::ColorPreview*)_color_preview[i])->setRgba32 (color);
270
 
            _color_preview[i]->show_all();
271
 
            place->add(*_color_preview[i]);
272
 
            gchar *tip;
273
 
            if (i == SS_FILL) {
274
 
                tip = g_strdup_printf ("Fill: %06x/%.3g", color >> 8, SP_RGBA32_A_F(color));
275
 
            } else {
276
 
                tip = g_strdup_printf ("Stroke: %06x/%.3g", color >> 8, SP_RGBA32_A_F(color));
277
 
            }
278
 
            _tooltips.set_tip(*place, tip);
279
 
            g_free (tip);
280
 
        } else if (paint->set && paint->type == SP_PAINT_TYPE_PAINTSERVER) {
 
295
        if (paint->set && paint->isPaintserver()) {
281
296
            SPPaintServer *server = (i == SS_FILL)? SP_STYLE_FILL_SERVER (query) : SP_STYLE_STROKE_SERVER (query);
282
297
 
283
298
            if (SP_IS_LINEARGRADIENT (server)) {
294
309
                _tooltips.set_tip(*place, (i == SS_FILL)? (_("Pattern fill")) : (_("Pattern stroke")));
295
310
            }
296
311
 
297
 
        } else if (paint->set && paint->type == SP_PAINT_TYPE_NONE) {
298
 
            _value[i].set_markup(_("None"));
 
312
        } else if (paint->set && paint->isColor()) {
 
313
            guint32 color = paint->value.color.toRGBA32( SP_SCALE24_TO_FLOAT ((i == SS_FILL)? query->fill_opacity.value : query->stroke_opacity.value) );
 
314
            ((Inkscape::UI::Widget::ColorPreview*)_color_preview[i])->setRgba32 (color);
 
315
            _color_preview[i]->show_all();
 
316
            place->add(*_color_preview[i]);
 
317
            gchar *tip;
 
318
            if (i == SS_FILL) {
 
319
                tip = g_strdup_printf (_("Fill: %06x/%.3g"), color >> 8, SP_RGBA32_A_F(color));
 
320
            } else {
 
321
                tip = g_strdup_printf (_("Stroke: %06x/%.3g"), color >> 8, SP_RGBA32_A_F(color));
 
322
            }
 
323
            _tooltips.set_tip(*place, tip);
 
324
            g_free (tip);
 
325
        } else if (paint->set && paint->isNone()) {
 
326
            _value[i].set_markup(_("<i>None</i>"));
299
327
            place->add(_value[i]);
300
328
            _tooltips.set_tip(*place, (i == SS_FILL)? (_("No fill")) : (_("No stroke")));
301
329
            if (i == SS_STROKE) has_stroke = false;
302
330
        } else if (!paint->set) {
303
 
            _value[i].set_markup(_("Unset"));
 
331
            _value[i].set_markup(_("<b>Unset</b>"));
304
332
            place->add(_value[i]);
305
333
            _tooltips.set_tip(*place, (i == SS_FILL)? (_("Unset fill")) : (_("Unset stroke")));
306
334
            if (i == SS_STROKE) has_stroke = false;
322
350
            g_free (str);
323
351
        }
324
352
        {
325
 
            gchar *str = g_strdup_printf(_("Stroke width: %.5g%s"), 
326
 
                                         w, 
 
353
            gchar *str = g_strdup_printf(_("Stroke width: %.5g%s"),
 
354
                                         w,
327
355
                                         _sw_unit? sp_unit_get_abbreviation(_sw_unit) : "px");
328
356
            _tooltips.set_tip(_stroke_width_place, str);
329
357
            g_free (str);
339
367
            gchar *str;
340
368
            if (op == 0)
341
369
                str = g_strdup_printf(_("O:%.3g"), op);
342
 
            else 
 
370
            else
343
371
                str = g_strdup_printf(_("O:.%d"), (int) (op*10));
344
372
            _opacity_value.set_markup (str);
345
373
            g_free (str);
361
389
} // namespace UI
362
390
} // namespace Inkscape
363
391
 
364
 
/* 
 
392
/*
365
393
  Local Variables:
366
394
  mode:c++
367
395
  c-file-style:"stroustrup"