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);
35 Glib::RefPtr<Gdk::Pixbuf> pbmm = Gtk::IconTheme::get_default()->load_icon(_pixOnName, phys, (Gtk::IconLookupFlags)0);
36 if ( pbmm ) {
37 GdkPixbuf* pb = gdk_pixbuf_copy(pbmm->gobj());
38 _property_pixbuf_on = Glib::wrap( pb );
39 pbmm->unreference();
40 }
42 pbmm = Gtk::IconTheme::get_default()->load_icon(_pixOffName, phys, (Gtk::IconLookupFlags)0);
43 if ( pbmm ) {
44 GdkPixbuf* pb = gdk_pixbuf_copy(pbmm->gobj());
45 _property_pixbuf_off = Glib::wrap( pb );
46 pbmm->unreference();
47 }
49 property_pixbuf() = _property_pixbuf_off.get_value();
50 }
52 void
53 ImageToggler::get_size_vfunc( Gtk::Widget& widget,
54 const Gdk::Rectangle* cell_area,
55 int* x_offset,
56 int* y_offset,
57 int* width,
58 int* height ) const
59 {
60 Gtk::CellRendererPixbuf::get_size_vfunc( widget, cell_area, x_offset, y_offset, width, height );
62 if ( width ) {
63 *width += (*width) >> 1;
64 }
65 if ( height ) {
66 *height += (*height) >> 1;
67 }
68 }
71 void
72 ImageToggler::render_vfunc( const Glib::RefPtr<Gdk::Drawable>& window,
73 Gtk::Widget& widget,
74 const Gdk::Rectangle& background_area,
75 const Gdk::Rectangle& cell_area,
76 const Gdk::Rectangle& expose_area,
77 Gtk::CellRendererState flags )
78 {
79 property_pixbuf() = _property_active.get_value() ? _property_pixbuf_on : _property_pixbuf_off;
80 Gtk::CellRendererPixbuf::render_vfunc( window, widget, background_area, cell_area, expose_area, flags );
81 }
83 bool
84 ImageToggler::activate_vfunc(GdkEvent* event,
85 Gtk::Widget& /*widget*/,
86 const Glib::ustring& path,
87 const Gdk::Rectangle& /*background_area*/,
88 const Gdk::Rectangle& /*cell_area*/,
89 Gtk::CellRendererState /*flags*/)
90 {
91 _signal_pre_toggle.emit(event);
92 _signal_toggled.emit(path);
94 return false;
95 }
98 } // namespace Widget
99 } // namespace UI
100 } // namespace Inkscape
102 /*
103 Local Variables:
104 mode:c++
105 c-file-style:"stroustrup"
106 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
107 indent-tabs-mode:nil
108 fill-column:99
109 End:
110 */
111 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :