libyui-gtk-pkg  2.42.9
 All Classes
ygtkcellrenderertext.c
1 /********************************************************************
2  * YaST2-GTK - http://en.opensuse.org/YaST2-GTK *
3  ********************************************************************/
4 
5 /* YGtkCellRendererText cell renderer */
6 // check the header file for information about this cell renderer
7 
8 #include "ygtkcellrenderertext.h"
9 #include <gtk/gtk.h>
10 #include <string.h>
11 
12 G_DEFINE_TYPE (YGtkCellRendererText, ygtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER_TEXT)
13 
14 static void ygtk_cell_renderer_text_init (YGtkCellRendererText *bcell)
15 {}
16 
17 gboolean filter_color_cb (PangoAttribute *attrb, gpointer data)
18 {
19  PangoAttrType type = attrb->klass->type;
20  return type == PANGO_ATTR_FOREGROUND || type == PANGO_ATTR_BACKGROUND;
21 }
22 
23 static void ygtk_cell_renderer_text_render (
24  GtkCellRenderer *cell, cairo_t *cr, GtkWidget *widget,
25  const GdkRectangle *background_area, const GdkRectangle *cell_area,
26  GtkCellRendererState flags)
27 {
28  // hack: disable our color attributes when the text is selected,
29  // so that the text is visible against the blue background
30  GtkCellRendererText *tcell = GTK_CELL_RENDERER_TEXT (cell);
31  PangoAttrList *old_extra_attrs = 0, *new_extra_attrs = 0;
32  if (flags & (GTK_CELL_RENDERER_SELECTED | GTK_CELL_RENDERER_INSENSITIVE)) {
33  g_object_get(tcell, "attributes", &old_extra_attrs, NULL);
34  g_object_get(tcell, "attributes", &new_extra_attrs, NULL);
35 
36  PangoAttrList *t = pango_attr_list_filter (new_extra_attrs,
37  filter_color_cb, NULL);
38 
39  g_object_set(tcell, "attributes", new_extra_attrs, NULL);
40  pango_attr_list_unref (new_extra_attrs);
41  pango_attr_list_unref (t);
42  }
43 
44  GTK_CELL_RENDERER_CLASS (ygtk_cell_renderer_text_parent_class)->render (
45  cell, cr, widget, background_area, cell_area, flags);
46 
47  if (old_extra_attrs) {
48  g_object_set(tcell, "attributes", old_extra_attrs, NULL);
49  pango_attr_list_unref (old_extra_attrs);
50  }
51 }
52 
53 GtkCellRenderer *ygtk_cell_renderer_text_new (void)
54 { return g_object_new (YGTK_TYPE_CELL_RENDERER_TEXT, NULL); }
55 
56 static void ygtk_cell_renderer_text_class_init (YGtkCellRendererTextClass *class)
57 {
58  GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
59  cell_class->render = ygtk_cell_renderer_text_render;
60 }
61