1 /*
2 * Authors:
3 * Jon A. Cruz
4 * Johan B. C. Engelen
5 *
6 * Copyright (C) 2006-2008 Authors
7 *
8 * Released under GNU GPL, read the file 'COPYING' for more information
9 */
12 #include "ui/widget/imagetoggler.h"
14 #include <gtkmm/icontheme.h>
16 #include "widgets/icon.h"
18 namespace Inkscape {
19 namespace UI {
20 namespace Widget {
22 ImageToggler::ImageToggler( char const* on, char const* off) :
23 Glib::ObjectBase(typeid(ImageToggler)),
24 Gtk::CellRendererPixbuf(),
25 _pixOnName(on),
26 _pixOffName(off),
27 _property_active(*this, "active", false),
28 _property_activatable(*this, "activatable", true),
29 _property_pixbuf_on(*this, "pixbuf_on", Glib::RefPtr<Gdk::Pixbuf>(0)),
30 _property_pixbuf_off(*this, "pixbuf_off", Glib::RefPtr<Gdk::Pixbuf>(0))
31 {
32 property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
33 int phys = sp_icon_get_phys_size((int)Inkscape::ICON_SIZE_DECORATION);
34 Glib::RefPtr<Gtk::IconTheme> icon_theme = Gtk::IconTheme::get_default();
36 if (icon_theme->has_icon(_pixOnName)) {
37 _property_pixbuf_on = icon_theme->load_icon(_pixOnName, phys, (Gtk::IconLookupFlags)0);
38 }
40 if (icon_theme->has_icon(_pixOffName)) {
41 _property_pixbuf_off = icon_theme->load_icon(_pixOffName, phys, (Gtk::IconLookupFlags)0);
42 }
44 property_pixbuf() = _property_pixbuf_off.get_value();
45 }
47 void
48 ImageToggler::get_size_vfunc( Gtk::Widget& widget,
49 const Gdk::Rectangle* cell_area,
50 int* x_offset,
51 int* y_offset,
52 int* width,
53 int* height ) const
54 {
55 Gtk::CellRendererPixbuf::get_size_vfunc( widget, cell_area, x_offset, y_offset, width, height );
57 if ( width ) {
58 *width += (*width) >> 1;
59 }
60 if ( height ) {
61 *height += (*height) >> 1;
62 }
63 }
66 void
67 ImageToggler::render_vfunc( const Glib::RefPtr<Gdk::Drawable>& window,
68 Gtk::Widget& widget,
69 const Gdk::Rectangle& background_area,
70 const Gdk::Rectangle& cell_area,
71 const Gdk::Rectangle& expose_area,
72 Gtk::CellRendererState flags )
73 {
74 property_pixbuf() = _property_active.get_value() ? _property_pixbuf_on : _property_pixbuf_off;
75 Gtk::CellRendererPixbuf::render_vfunc( window, widget, background_area, cell_area, expose_area, flags );
76 }
78 bool
79 ImageToggler::activate_vfunc(GdkEvent* event,
80 Gtk::Widget& /*widget*/,
81 const Glib::ustring& path,
82 const Gdk::Rectangle& /*background_area*/,
83 const Gdk::Rectangle& /*cell_area*/,
84 Gtk::CellRendererState /*flags*/)
85 {
86 _signal_pre_toggle.emit(event);
87 _signal_toggled.emit(path);
89 return false;
90 }
93 } // namespace Widget
94 } // namespace UI
95 } // namespace Inkscape
97 /*
98 Local Variables:
99 mode:c++
100 c-file-style:"stroustrup"
101 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
102 indent-tabs-mode:nil
103 fill-column:99
104 End:
105 */
106 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :