15
15
You should have received a copy of the GNU General Public License
16
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19
19
#include "cellrenderer_acl.hpp"
20
// #include <iostream>
23
#define MARK_BACKGROUND_PROPERTY ("mark_background")
22
25
CellRendererACL::CellRendererACL()
23
: Glib::ObjectBase (typeid(CellRendererACL)),
24
Gtk::CellRendererToggle(),
25
property_marca_fons_(*this, "marcar_fons", false)
29
void CellRendererACL::render_vfunc (const Glib::RefPtr<Gdk::Drawable>& window,
31
const Gdk::Rectangle& background_area,
32
const Gdk::Rectangle& cell_area,
33
const Gdk::Rectangle& expose_area,
34
Gtk::CellRendererState flags
37
Gtk::CellRendererToggle::render_vfunc(window, widget, background_area, cell_area, expose_area, flags);
39
// Pintem una admiraci�
40
if (property_marca_fons_.get_value() && property_active())
42
Glib::RefPtr<Pango::Layout> pango = Pango::Layout::create(widget.get_pango_context());
43
pango->set_markup("<span foreground=\"#cc0000\" weight=\"bold\">!</span>");
45
Pango::Rectangle ink_rect = pango->get_pixel_ink_extents();
47
// A GTK els checkboxes sempre son de 12x12
48
// per tant -> hardcode 6
49
int posicioX = cell_area.get_x() + (cell_area.get_width() / 2) - 6;
50
int posicioY = cell_area.get_y() + (cell_area.get_height() / 2) - 6;
52
Glib::RefPtr<Gdk::GC> context_grafic = Gdk::GC::create(window);
54
window->draw_layout(context_grafic,
55
posicioX - ink_rect.get_width() - 4,
56
posicioY - ink_rect.get_height() / 2,
59
// estil->paint_layout ( window,
65
// posicioX - ink_rect.get_width() - 4,
66
// posicioY - ink_rect.get_height() / 2,
72
Glib::PropertyProxy<bool> CellRendererACL::property_marcar_fons()
74
return Glib::PropertyProxy<bool>(this, "marcar_fons");
26
: Glib::ObjectBase (typeid(CellRendererACL)),
27
Gtk::CellRendererToggle(),
28
_mark_background(*this, MARK_BACKGROUND_PROPERTY, false)
32
// I don't want this in the header
33
static int default_indicator_size = 13;
34
static const int blank = 4;
36
void CellRendererACL::get_size_vfunc(Gtk::Widget& widget,
37
const Gdk::Rectangle* cell_area,
43
Glib::RefPtr<Gdk::Pixbuf> warning_icon = widget.render_icon(Gtk::Stock::DIALOG_WARNING,
44
Gtk::IconSize(Gtk::ICON_SIZE_SMALL_TOOLBAR),
47
const int checkbox_width = default_indicator_size;
48
const int checkbox_height = default_indicator_size;
49
const int inner_box_width = warning_icon->get_width() + blank + checkbox_width;
50
const int inner_box_height = std::max(warning_icon->get_height(), checkbox_height);
52
*width = inner_box_width;
53
*height = inner_box_height;
56
void CellRendererACL::render_vfunc (const Glib::RefPtr<Gdk::Drawable>& drawable,
58
const Gdk::Rectangle& background_area,
59
const Gdk::Rectangle& cell_area,
60
const Gdk::Rectangle& expose_area,
61
Gtk::CellRendererState flags)
63
Glib::RefPtr<Gtk::Style> style = widget.get_style();
64
Glib::RefPtr<Gdk::Window> window = Glib::RefPtr<Gdk::Window>::cast_dynamic(drawable);
66
Gtk::StateType state = Gtk::STATE_NORMAL;
68
Glib::RefPtr<Gdk::Pixbuf> warning_icon = widget.render_icon(Gtk::Stock::DIALOG_WARNING,
69
Gtk::IconSize(Gtk::ICON_SIZE_SMALL_TOOLBAR),
73
* The size of the icon + 4 spacing pixels + checkbox of 13x13
76
const int checkbox_width = default_indicator_size;
77
const int checkbox_height = default_indicator_size;
78
const int inner_box_width = warning_icon->get_width() + blank + checkbox_width;
79
const int inner_box_height = std::max(warning_icon->get_height(), checkbox_height);
82
// << "--->" << std::endl
83
// << "inner_box_width= " << inner_box_width << std::endl
84
// << "inner_box_height= " << inner_box_height << std::endl
85
// << "cell_area_width= " << cell_area.get_width() << std::endl
86
// << "cell_area_height= " << cell_area.get_height() << std::endl
87
// << "<---" << std::endl;
91
* Precondition: cell_area.get_width() >= inner_box_width
92
* cell_area.get_height() >= inner_box_height()
94
* Enforce this in the widget
97
int inner_x = (cell_area.get_width() - inner_box_width) / 2;
98
int inner_y = (cell_area.get_height() - inner_box_height) / 2;
100
inner_x = (inner_x < 0) ? 0 : inner_x;
101
inner_y = (inner_y < 0) ? 0 : inner_y;
103
inner_x += cell_area.get_x();
104
inner_y += cell_area.get_y();
106
Gtk::ShadowType shadow = Gtk::SHADOW_OUT;
107
if (property_active())
109
shadow = Gtk::SHADOW_IN;
113
int checkbox_x = inner_x + warning_icon->get_width() + blank;
114
int checkbox_y = inner_y + (warning_icon->get_height() - checkbox_height)/2;
123
checkbox_x, checkbox_y, checkbox_width, checkbox_height
126
if (property_active() && _mark_background.get_value())
128
int icon_x = inner_x;
129
int icon_y = inner_y;
131
Glib::RefPtr<Gdk::GC> graphic_context = Gdk::GC::create(drawable);
133
drawable->draw_pixbuf(graphic_context,
138
Gdk::RGB_DITHER_NORMAL,
144
Glib::PropertyProxy<bool> CellRendererACL::mark_background()
146
return Glib::PropertyProxy<bool>(this, MARK_BACKGROUND_PROPERTY);