Allow for per-widget image-surface backing
[ardour.git] / libs / gtkmm2ext / cell_renderer_pixbuf_multi.cc
1 /*
2  * Copyright (C) 2009-2015 Paul Davis <paul@linuxaudiosystems.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 #include <iostream>
20 #include <gtkmm.h>
21
22 #include <gtkmm2ext/cell_renderer_pixbuf_multi.h>
23
24 using namespace std;
25 using namespace Gtk;
26 using namespace Gdk;
27 using namespace Glib;
28 using namespace Gtkmm2ext;
29
30
31 CellRendererPixbufMulti::CellRendererPixbufMulti() :
32         Glib::ObjectBase( typeid(CellRendererPixbufMulti) ),
33         Gtk::CellRenderer(),
34         property_state_(*this, "active", 0)
35 {
36         property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
37         property_xpad() = 2;
38         property_ypad() = 2;
39         property_sensitive() = false;
40 }
41
42 Glib::PropertyProxy<uint32_t>
43 CellRendererPixbufMulti::property_state()
44 {
45         return property_state_.get_proxy();
46 }
47
48 // Overridden methods of the parent CellRenderer
49 Glib::PropertyProxy_Base
50 CellRendererPixbufMulti::_property_renderable()
51 {
52         return property_state();
53 }
54
55 bool
56 CellRendererPixbufMulti::activate_vfunc(GdkEvent*, Gtk::Widget&, const Glib::ustring& path, const Gdk::Rectangle&, const Gdk::Rectangle&, Gtk::CellRendererState)
57 {
58         signal_changed_(path);
59         return true;
60 }
61
62 void
63 CellRendererPixbufMulti::render_vfunc (const Glib::RefPtr<Gdk::Drawable>& window, Gtk::Widget& /*widget*/, const Gdk::Rectangle& /*background_area*/, const Gdk::Rectangle& cell_area, const Gdk::Rectangle& /*expose_area*/, Gtk::CellRendererState /*flags*/)
64 {
65         int offset_width = 0;
66         int offset_height = 0;
67         Glib::RefPtr<Pixbuf> pb = _pixbufs[property_state()];
68
69         offset_width = cell_area.get_x() +  (int)(cell_area.get_width() - pb->get_width())/2;
70         offset_height = cell_area.get_y() + (int)(cell_area.get_height() - pb->get_height())/2;
71
72         window->draw_pixbuf (RefPtr<GC>(), pb, 0, 0, offset_width, offset_height, -1, -1, Gdk::RGB_DITHER_NORMAL, 0, 0);
73 }
74
75 void
76 CellRendererPixbufMulti::get_size_vfunc (Gtk::Widget& /*widget*/, const Gdk::Rectangle* /*cell_area*/, int* /*x_offset*/, int* /*y_offset*/, int* /*width*/, int* /*height*/) const
77 {
78 }
79
80 void
81 CellRendererPixbufMulti::set_pixbuf(uint32_t which, Glib::RefPtr<Gdk::Pixbuf> pixbuf){
82         _pixbufs[which] = pixbuf;
83 }
84
85 CellRendererPixbufMulti::SignalChanged&
86 CellRendererPixbufMulti::signal_changed()
87 {
88   return signal_changed_;
89 }