24 #include <gui_utils/twolines_cellrenderer.h> 27 #include <glib-object.h> 51 #ifdef GLIBMM_PROPERTIES_ENABLED
52 , __property_line1(*this,
"line1",
"")
53 , __property_line2(*this,
"line2",
"")
54 , __property_line2_enabled(*this,
"line2_enabled", true)
65 #ifdef GLIBMM_PROPERTIES_ENABLED 69 Glib::PropertyProxy<Glib::ustring>
70 TwoLinesCellRenderer::property_line1()
72 return __property_line1.get_proxy();
79 Glib::PropertyProxy<Glib::ustring>
80 TwoLinesCellRenderer::property_line2()
82 return __property_line2.get_proxy();
89 Glib::PropertyProxy<bool>
90 TwoLinesCellRenderer::property_line2_enabled()
92 return __property_line2_enabled.get_proxy();
97 #if GTK_VERSION_GE(3,0) 104 TwoLinesCellRenderer::get_size(Gtk::Widget &widget,
105 int *width,
int *height)
const 117 const Gdk::Rectangle *cell_area,
118 int *x_offset,
int *y_offset,
119 int *width,
int *height)
const 122 #ifdef GLIBMM_PROPERTIES_ENABLED 124 Glib::RefPtr<Pango::Layout> layout_ptr = widget.create_pango_layout(__property_line1);
125 Pango::Rectangle rect = layout_ptr->get_pixel_logical_extents();
127 int line1_width = property_xpad() * 2 + rect.get_width();
128 int line1_height = property_ypad() * 2 + rect.get_height();
131 if (__property_line2_enabled.get_value()) {
132 Glib::RefPtr<Pango::Layout> layout2 = widget.create_pango_layout(__property_line2);
133 #if GTK_VERSION_GE(3,0) 134 Pango::FontDescription font2(
"sans 10");
136 Glib::RefPtr<Gtk::Style> style = widget.get_style();
137 Pango::FontDescription font2 = style->get_font();
140 font2.set_size((
int)roundf(Pango::SCALE_SMALL * font2.get_size()));
141 layout2->set_font_description(font2);
142 Pango::Rectangle rect2 = layout2->get_pixel_logical_extents();
143 layout2->set_ellipsize(Pango::ELLIPSIZE_END);
145 line2_height = property_ypad() * 2 + rect2.get_height();
150 if (width) *width = line1_width;
151 if (height) *height = line1_height + 4 + line2_height;
155 #if GTK_VERSION_GE(3,0) 162 TwoLinesCellRenderer::get_preferred_width_vfunc(Gtk::Widget &widget,
164 int &natural_width)
const 167 get_size(widget, &width, NULL);
168 minimum_width = natural_width = width;
177 TwoLinesCellRenderer::get_preferred_height_vfunc(Gtk::Widget &widget,
179 int &natural_height)
const 182 get_size(widget, NULL, &height);
183 minimum_height = natural_height = height;
187 #if GTK_VERSION_GE(3,0) 199 const Gdk::Rectangle &background_area,
200 const Gdk::Rectangle &cell_area,
201 Gtk::CellRendererState flags)
215 const Gdk::Rectangle &background_area,
216 const Gdk::Rectangle &cell_area,
217 const Gdk::Rectangle &expose_area,
218 Gtk::CellRendererState flags)
221 #ifdef GLIBMM_PROPERTIES_ENABLED 223 int x_offset = 0, y_offset = 0;
224 #if GTK_VERSION_LT(3,0) 225 int width = 0, height = 0;
226 get_size(widget, cell_area, x_offset, y_offset, width, height);
230 Gtk::StateType text_state;
231 if ((flags & Gtk::CELL_RENDERER_SELECTED) != 0) {
233 text_state = (widget.has_focus()) ? Gtk::STATE_SELECTED : Gtk::STATE_ACTIVE;
236 text_state = (widget.is_sensitive()) ? Gtk::STATE_NORMAL : Gtk::STATE_INSENSITIVE;
240 Glib::RefPtr<Gdk::Window> win =
241 Glib::RefPtr<Gdk::Window>::cast_dynamic(window);
243 Glib::RefPtr<Pango::Layout> layout_ptr =
244 widget.create_pango_layout(__property_line1);
245 Pango::Rectangle rect1 = layout_ptr->get_pixel_logical_extents();
246 #if GTK_VERSION_GE(3,0) 247 Glib::RefPtr<Gtk::StyleContext> stylecontext = widget.get_style_context();
248 Gdk::RGBA c = stylecontext->get_color(Gtk::STATE_FLAG_NORMAL);
250 cr->set_source_rgba(c.get_red(), c.get_green(), c.get_blue(), c.get_alpha());
251 cr->move_to(cell_area.get_x() + x_offset + 2 * property_xpad(),
252 cell_area.get_y() + y_offset + 2 * property_ypad());
253 layout_ptr->show_in_cairo_context(cr);
255 widget.get_style()->paint_layout(win, text_state,
true, cell_area,
256 widget,
"cellrenderertext",
257 cell_area.get_x() + x_offset + 2 * property_xpad(),
258 cell_area.get_y() + y_offset + 2 * property_ypad(),
262 if (__property_line2_enabled.get_value()) {
263 Glib::RefPtr<Pango::Layout> layout2 =
264 widget.create_pango_layout(__property_line2);
265 #if GTK_VERSION_GE(3,0) 266 Pango::FontDescription font2(
"sans 10");
268 Glib::RefPtr<Gtk::Style> style = widget.get_style();
269 Pango::FontDescription font2 = style->get_font();
271 font2.set_size((
int)roundf(Pango::SCALE_SMALL * font2.get_size()));
272 layout2->set_font_description(font2);
274 layout2->set_ellipsize(Pango::ELLIPSIZE_END);
275 layout2->set_width((cell_area.get_width() - property_xpad()) * Pango::SCALE);
277 #if GTK_VERSION_GE(3,0) 278 cr->move_to(cell_area.get_x() + x_offset + property_xpad(),
279 cell_area.get_y() + y_offset + property_ypad() +
280 rect1.get_height() + 4);
281 layout2->show_in_cairo_context(cr);
283 widget.get_style()->paint_layout (win, text_state,
true, cell_area,
284 widget,
"cellrenderertext",
285 cell_area.get_x() + x_offset + property_xpad(),
286 cell_area.get_y() + y_offset + property_ypad() + rect1.get_height() + 4,
Gtk cell renderer for two lines of text in a cell.
Fawkes library namespace.
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 ~TwoLinesCellRenderer()
Destructor.
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.