24 #include <gui_utils/twolines_cellrenderer.h>
29 #include <glib-object.h>
47 #ifdef GLIBMM_PROPERTIES_ENABLED
49 property_line1_(*this,
"line1",
""),
50 property_line2_(*this,
"line2",
""),
51 property_line2_enabled_(*this,
"line2_enabled", true)
61 #ifdef GLIBMM_PROPERTIES_ENABLED
65 Glib::PropertyProxy<Glib::ustring>
66 TwoLinesCellRenderer::property_line1()
68 return property_line1_.get_proxy();
74 Glib::PropertyProxy<Glib::ustring>
75 TwoLinesCellRenderer::property_line2()
77 return property_line2_.get_proxy();
83 Glib::PropertyProxy<bool>
84 TwoLinesCellRenderer::property_line2_enabled()
86 return property_line2_enabled_.get_proxy();
90 #if GTK_VERSION_GE(3, 0)
97 TwoLinesCellRenderer::get_size(Gtk::Widget &widget,
int *width,
int *height)
const
109 const Gdk::Rectangle *cell_area,
116 #ifdef GLIBMM_PROPERTIES_ENABLED
118 Glib::RefPtr<Pango::Layout> layout_ptr = widget.create_pango_layout(property_line1_);
119 Pango::Rectangle rect = layout_ptr->get_pixel_logical_extents();
121 int line1_width = property_xpad() * 2 + rect.get_width();
122 int line1_height = property_ypad() * 2 + rect.get_height();
125 if (property_line2_enabled_.get_value()) {
126 Glib::RefPtr<Pango::Layout> layout2 = widget.create_pango_layout(property_line2_);
127 # if GTK_VERSION_GE(3, 0)
128 Pango::FontDescription font2(
"sans 10");
130 Glib::RefPtr<Gtk::Style> style = widget.get_style();
131 Pango::FontDescription font2 = style->get_font();
134 font2.set_size((
int)roundf(Pango::SCALE_SMALL * font2.get_size()));
135 layout2->set_font_description(font2);
136 Pango::Rectangle rect2 = layout2->get_pixel_logical_extents();
137 layout2->set_ellipsize(Pango::ELLIPSIZE_END);
139 line2_height = property_ypad() * 2 + rect2.get_height();
145 *width = line1_width;
147 *height = line1_height + 4 + line2_height;
151 #if GTK_VERSION_GE(3, 0)
158 TwoLinesCellRenderer::get_preferred_width_vfunc(Gtk::Widget &widget,
160 int & natural_width)
const
163 get_size(widget, &width, NULL);
164 minimum_width = natural_width = width;
173 TwoLinesCellRenderer::get_preferred_height_vfunc(Gtk::Widget &widget,
174 int & minimum_height,
175 int & natural_height)
const
178 get_size(widget, NULL, &height);
179 minimum_height = natural_height = height;
183 #if GTK_VERSION_GE(3, 0)
194 Gtk::Widget & widget,
195 const Gdk::Rectangle & background_area,
196 const Gdk::Rectangle & cell_area,
197 Gtk::CellRendererState flags)
210 Gtk::Widget & widget,
211 const Gdk::Rectangle & background_area,
212 const Gdk::Rectangle & cell_area,
213 const Gdk::Rectangle & expose_area,
214 Gtk::CellRendererState flags)
217 #ifdef GLIBMM_PROPERTIES_ENABLED
219 int x_offset = 0, y_offset = 0;
220 # if GTK_VERSION_LT(3, 0)
221 int width = 0, height = 0;
222 get_size(widget, cell_area, x_offset, y_offset, width, height);
226 Gtk::StateType text_state;
227 if ((flags & Gtk::CELL_RENDERER_SELECTED) != 0) {
229 text_state = (widget.has_focus()) ? Gtk::STATE_SELECTED : Gtk::STATE_ACTIVE;
232 text_state = (widget.is_sensitive()) ? Gtk::STATE_NORMAL : Gtk::STATE_INSENSITIVE;
236 Glib::RefPtr<Gdk::Window> win = Glib::RefPtr<Gdk::Window>::cast_dynamic(window);
238 Glib::RefPtr<Pango::Layout> layout_ptr = widget.create_pango_layout(property_line1_);
239 Pango::Rectangle rect1 = layout_ptr->get_pixel_logical_extents();
240 # if GTK_VERSION_GE(3, 0)
241 Glib::RefPtr<Gtk::StyleContext> stylecontext = widget.get_style_context();
242 Gdk::RGBA c = stylecontext->get_color(Gtk::STATE_FLAG_NORMAL);
244 cr->set_source_rgba(c.get_red(), c.get_green(), c.get_blue(), c.get_alpha());
245 cr->move_to(cell_area.get_x() + x_offset + 2 * property_xpad(),
246 cell_area.get_y() + y_offset + 2 * property_ypad());
247 layout_ptr->show_in_cairo_context(cr);
249 widget.get_style()->paint_layout(win,
255 cell_area.get_x() + x_offset + 2 * property_xpad(),
256 cell_area.get_y() + y_offset + 2 * property_ypad(),
260 if (property_line2_enabled_.get_value()) {
261 Glib::RefPtr<Pango::Layout> layout2 = widget.create_pango_layout(property_line2_);
262 # if GTK_VERSION_GE(3, 0)
263 Pango::FontDescription font2(
"sans 10");
265 Glib::RefPtr<Gtk::Style> style = widget.get_style();
266 Pango::FontDescription font2 = style->get_font();
268 font2.set_size((
int)roundf(Pango::SCALE_SMALL * font2.get_size()));
269 layout2->set_font_description(font2);
271 layout2->set_ellipsize(Pango::ELLIPSIZE_END);
272 layout2->set_width((cell_area.get_width() - property_xpad()) * Pango::SCALE);
274 # if GTK_VERSION_GE(3, 0)
275 cr->move_to(cell_area.get_x() + x_offset + property_xpad(),
276 cell_area.get_y() + y_offset + property_ypad() + rect1.get_height() + 4);
277 layout2->show_in_cairo_context(cr);
279 widget.get_style()->paint_layout(win,
285 cell_area.get_x() + x_offset + property_xpad(),
286 cell_area.get_y() + y_offset + property_ypad()
287 + rect1.get_height() + 4,
Gtk cell renderer for two lines of text in a cell.
virtual void 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)
Render the cell.
virtual void get_size_vfunc(Gtk::Widget &widget, const Gdk::Rectangle *cell_area, int *x_offset, int *y_offset, int *width, int *height) const
Get required size for cell.
TwoLinesCellRenderer()
Constructor.
virtual ~TwoLinesCellRenderer()
Destructor.
Fawkes library namespace.