No more doxygen warnings for gtk2_arodur/*
[ardour.git] / libs / gtkmm2ext / cell_renderer_pixbuf_toggle.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_toggle.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 CellRendererPixbufToggle::CellRendererPixbufToggle() :
32         Glib::ObjectBase( typeid(CellRendererPixbufToggle) ),
33         Gtk::CellRenderer(),
34         property_pixbuf_(*this, "pixbuf"),
35         property_active_(*this, "active", false)
36 {
37         property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE;
38         property_xpad() = 2;
39         property_ypad() = 2;
40         property_sensitive() = false;
41 }
42
43 Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> >
44 CellRendererPixbufToggle::property_pixbuf()
45 {
46         return property_pixbuf_.get_proxy();
47 }
48
49 Glib::PropertyProxy<bool>
50 CellRendererPixbufToggle::property_active()
51 {
52         return property_active_.get_proxy();
53 }
54
55 // Overridden methods of the parent CellRenderer
56 Glib::PropertyProxy_Base
57 CellRendererPixbufToggle::_property_renderable()
58 {
59         return property_pixbuf();
60 }
61
62 bool
63 CellRendererPixbufToggle::activate_vfunc(GdkEvent*, Gtk::Widget&, const Glib::ustring& path, const Gdk::Rectangle&, const Gdk::Rectangle&, Gtk::CellRendererState)
64 {
65         signal_toggled_(path);
66         return true;
67 }
68
69
70
71 void
72 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*/)
73 {
74         int offset_width = 0;
75         int offset_height = 0;
76
77         if(property_active() == true){
78
79                 offset_width = cell_area.get_x() +  (int)(cell_area.get_width() - inactive_pixbuf->get_width())/2;
80                 offset_height = cell_area.get_y() + (int)(cell_area.get_height() - inactive_pixbuf->get_height())/2;
81
82                 window->draw_pixbuf (RefPtr<GC>(), active_pixbuf, 0, 0, offset_width, offset_height, -1, -1, Gdk::RGB_DITHER_NORMAL, 0, 0);
83         }
84         else {
85                 offset_width = cell_area.get_x() + (int)(cell_area.get_width() - inactive_pixbuf->get_width())/2;
86                 offset_height = cell_area.get_y() + (int)(cell_area.get_height() - inactive_pixbuf->get_height())/2;
87
88                 window->draw_pixbuf (RefPtr<GC>(), inactive_pixbuf, 0, 0, offset_width, offset_height, -1, -1, Gdk::RGB_DITHER_NORMAL, 0, 0);
89         }
90 }
91
92 void
93 CellRendererPixbufToggle::get_size_vfunc (Gtk::Widget& /*widget*/, const Gdk::Rectangle* /*cell_area*/, int* /*x_offset*/, int* /*y_offset*/, int* /*width*/, int* /*height*/) const
94 {
95 //cerr << "cell_renderer_pixbuf_toggle get_size" << endl;
96
97 }
98
99 void
100 CellRendererPixbufToggle::set_active_pixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf){
101         active_pixbuf = pixbuf;
102 }
103
104 void
105 CellRendererPixbufToggle::set_inactive_pixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf){
106         inactive_pixbuf = pixbuf;
107 }
108
109 CellRendererPixbufToggle::SignalToggled&
110 CellRendererPixbufToggle::signal_toggled()
111 {
112   return signal_toggled_;
113 }