Update classkeys to match new total LuaSignal count (windows only)
[ardour.git] / libs / gtkmm2ext / cell_renderer_pixbuf_toggle.cc
1 /*
2     Copyright (C) 2009 Paul Davis
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
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id: cell_renderer_toggle_pixbuf.cc $
19 */
20
21 #include <iostream>
22 #include <gtkmm.h>
23
24 #include <gtkmm2ext/cell_renderer_pixbuf_toggle.h>
25
26 using namespace std;
27 using namespace Gtk;
28 using namespace Gdk;
29 using namespace Glib;
30 using namespace Gtkmm2ext;
31
32
33 CellRendererPixbufToggle::CellRendererPixbufToggle() :
34         Glib::ObjectBase( typeid(CellRendererPixbufToggle) ),
35         Gtk::CellRenderer(),
36         property_pixbuf_(*this, "pixbuf"),
37         property_active_(*this, "active", false)
38 {
39         property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
40         property_xpad() = 2;
41         property_ypad() = 2;
42         property_sensitive() = false;
43 }
44
45 Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> >
46 CellRendererPixbufToggle::property_pixbuf()
47 {
48         return property_pixbuf_.get_proxy();
49 }
50
51 Glib::PropertyProxy<bool>
52 CellRendererPixbufToggle::property_active()
53 {
54         return property_active_.get_proxy();
55 }
56
57 // Overridden methods of the parent CellRenderer
58 Glib::PropertyProxy_Base
59 CellRendererPixbufToggle::_property_renderable()
60 {
61         return property_pixbuf();
62 }
63
64 bool
65 CellRendererPixbufToggle::activate_vfunc(GdkEvent*, Gtk::Widget&, const Glib::ustring& path, const Gdk::Rectangle&, const Gdk::Rectangle&, Gtk::CellRendererState)
66 {
67         signal_toggled_(path);
68         return true;
69 }
70
71
72
73 void
74 CellRendererPixbufToggle::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*/)
75 {
76         int offset_width = 0;
77         int offset_height = 0;
78
79         if(property_active() == true){
80
81                 offset_width = cell_area.get_x() +  (int)(cell_area.get_width() - inactive_pixbuf->get_width())/2;
82                 offset_height = cell_area.get_y() + (int)(cell_area.get_height() - inactive_pixbuf->get_height())/2;
83
84                 window->draw_pixbuf (RefPtr<GC>(), active_pixbuf, 0, 0, offset_width, offset_height, -1, -1, Gdk::RGB_DITHER_NORMAL, 0, 0);
85         }
86         else {
87                 offset_width = cell_area.get_x() + (int)(cell_area.get_width() - inactive_pixbuf->get_width())/2;
88                 offset_height = cell_area.get_y() + (int)(cell_area.get_height() - inactive_pixbuf->get_height())/2;
89
90                 window->draw_pixbuf (RefPtr<GC>(), inactive_pixbuf, 0, 0, offset_width, offset_height, -1, -1, Gdk::RGB_DITHER_NORMAL, 0, 0);
91         }
92 }
93
94 void
95 CellRendererPixbufToggle::get_size_vfunc (Gtk::Widget& /*widget*/, const Gdk::Rectangle* /*cell_area*/, int* /*x_offset*/, int* /*y_offset*/, int* /*width*/, int* /*height*/) const
96 {
97 //cerr << "cell_renderer_pixbuf_toggle get_size" << endl;
98
99 }
100
101 void
102 CellRendererPixbufToggle::set_active_pixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf){
103         active_pixbuf = pixbuf;
104 }
105
106 void
107 CellRendererPixbufToggle::set_inactive_pixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf){
108         inactive_pixbuf = pixbuf;
109 }
110
111 CellRendererPixbufToggle::SignalToggled&
112 CellRendererPixbufToggle::signal_toggled()
113 {
114   return signal_toggled_;
115 }