1 /* egg-cell-renderer-text.c
2 * Copyright (C) 2002 Andreas J. Guelzow <aguelzow@taliesin.ca>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 #include "egg-cell-renderer-text.h"
24 static void egg_cell_renderer_text_class_init
25 (EggCellRendererTextClass
*cell_text_class
);
26 static void egg_cell_renderer_text_render (GtkCellRenderer
*cell
,
29 GdkRectangle
*background_area
,
30 GdkRectangle
*cell_area
,
31 GdkRectangle
*expose_area
,
34 static GtkCellRendererTextClass
*parent_class
= NULL
;
37 egg_cell_renderer_text_get_type (void)
39 static GType cell_text_type
= 0;
43 static const GTypeInfo cell_text_info
=
45 sizeof (EggCellRendererTextClass
),
47 NULL
, /* base_finalize */
48 (GClassInitFunc
)egg_cell_renderer_text_class_init
,
49 NULL
, /* class_finalize */
50 NULL
, /* class_data */
51 sizeof (GtkCellRendererText
),
53 (GInstanceInitFunc
) NULL
,
56 cell_text_type
= g_type_register_static (GTK_TYPE_CELL_RENDERER_TEXT
, "EggCellRendererText", &cell_text_info
, 0);
59 return cell_text_type
;
63 egg_cell_renderer_text_class_init (EggCellRendererTextClass
*class)
65 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS (class);
66 GObjectClass
*object_class
= G_OBJECT_CLASS (class);
68 parent_class
= g_type_class_peek_parent (object_class
);
70 cell_class
->render
= egg_cell_renderer_text_render
;
76 egg_cell_renderer_text_new (void)
78 return GTK_CELL_RENDERER (g_object_new (EGG_TYPE_CELL_RENDERER_TEXT
, NULL
));
81 egg_cell_renderer_text_render (GtkCellRenderer
*cell
,
84 GdkRectangle
*background_area
,
85 GdkRectangle
*cell_area
,
86 GdkRectangle
*expose_area
,
90 GtkCellRendererText
*celltext
= (GtkCellRendererText
*) cell
;
93 if ((flags
& GTK_CELL_RENDERER_SELECTED
) == GTK_CELL_RENDERER_SELECTED
)
95 if (GTK_WIDGET_HAS_FOCUS (widget
))
96 state
= GTK_STATE_SELECTED
;
98 state
= GTK_STATE_ACTIVE
;
102 if (GTK_WIDGET_STATE (widget
) == GTK_STATE_INSENSITIVE
)
103 state
= GTK_STATE_INSENSITIVE
;
105 state
= GTK_STATE_NORMAL
;
108 if ( state
== GTK_STATE_SELECTED
&& celltext
->background_set
)
113 color
.red
= celltext
->background
.red
;
114 color
.green
= celltext
->background
.green
;
115 color
.blue
= celltext
->background
.blue
;
117 gc
= gdk_gc_new (window
);
119 gdk_gc_set_rgb_fg_color (gc
, &color
);
121 gdk_draw_rectangle (window
,
125 background_area
->y
+ cell
->ypad
,
126 background_area
->width
,
127 background_area
->height
- 2 * cell
->ypad
);
129 g_object_unref (G_OBJECT (gc
));
132 GTK_CELL_RENDERER_CLASS (parent_class
)->render (cell
, window
, widget
, background_area
,
133 cell_area
, expose_area
, flags
);