00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <glib.h>
00034
00035
00036
00037
00038 #include "ergtk_log.h"
00039 #include "ergtkcellrendererborder.h"
00040
00041
00042
00043
00044
00045
00046
00047 typedef enum
00048 {
00049 PROP_NOT_USED = 0,
00050 PROP_BORDER_WIDTH,
00051 PROP_BORDER_OFFSET,
00052 PROP_BORDER_COLOR,
00053 NUM_PROPS
00054 } prop_t;
00055
00056
00057 typedef struct
00058 {
00059 guint border_width;
00060 guint border_offset;
00061 gchar *border_color;
00062 } erGtkCellRendererBorderPrivate;
00063
00064
00065
00066
00067
00068
00069 static const gchar *PROPNAME_BORDER_WIDTH = "border-width";
00070 static const gchar *PROPNAME_BORDER_OFFSET = "border-offset";
00071 static const gchar *PROPNAME_BORDER_COLOR = "border-color";
00072
00073
00074
00075
00076
00077
00078 static GtkCellRendererTextClass* g_parent_class = NULL;
00079
00080
00081
00082
00083
00084
00085
00086
00087 static void get_property_impl ( GObject *object,
00088 guint param_id,
00089 GValue *value,
00090 GParamSpec *pspec );
00091
00092 static void set_property_impl ( GObject *object,
00093 guint param_id,
00094 const GValue *value,
00095 GParamSpec *pspec );
00096
00097 static void render_impl (GtkCellRenderer *cell,
00098 GdkWindow *window,
00099 GtkWidget *widget,
00100 GdkRectangle *bg_area,
00101 GdkRectangle *cell_area,
00102 GdkRectangle *expose_area,
00103 guint flags);
00104
00105
00106
00107
00108
00109
00110 static void ergtk_cell_renderer_border_class_init (erGtkCellRendererBorderClass *klass);
00111 static void ergtk_cell_renderer_border_init (erGtkCellRendererBorder *thiz);
00112 static void ergtk_cell_renderer_border_finalize (GObject *obj);
00113
00114
00115
00116
00117
00118
00119
00120 GType ergtk_cell_renderer_border_get_type (void)
00121 {
00122 static GType class_type = 0;
00123
00124 if (class_type == 0)
00125 {
00126 static const GTypeInfo class_info =
00127 {
00128 sizeof(erGtkCellRendererBorderClass),
00129 NULL,
00130 NULL,
00131 (GClassInitFunc) ergtk_cell_renderer_border_class_init,
00132 NULL,
00133 NULL,
00134 sizeof(erGtkCellRendererBorder),
00135 0,
00136 (GInstanceInitFunc) ergtk_cell_renderer_border_init,
00137 NULL
00138 };
00139
00140 class_type = g_type_register_static( GTK_TYPE_CELL_RENDERER_TEXT,
00141 "erGtkCellRendererBorder",
00142 &class_info,
00143 0 );
00144 }
00145
00146 return class_type;
00147 }
00148
00149
00150
00151 static void ergtk_cell_renderer_border_class_init (erGtkCellRendererBorderClass* klass)
00152 {
00153 GObjectClass *object_class = (GObjectClass *) klass;
00154 GtkCellRendererClass *cell_renderer_class = (GtkCellRendererClass *) klass;
00155
00156 GParamSpec *pspec;
00157
00158
00159 g_parent_class = g_type_class_peek_parent(klass);
00160
00161
00162 cell_renderer_class->render = render_impl;
00163 object_class->get_property = get_property_impl;
00164 object_class->set_property = set_property_impl;
00165 object_class->finalize = ergtk_cell_renderer_border_finalize;
00166
00167
00168 g_type_class_add_private (klass, sizeof(erGtkCellRendererBorderPrivate));
00169
00170
00171
00172 pspec = g_param_spec_uint( PROPNAME_BORDER_WIDTH,
00173 PROPNAME_BORDER_WIDTH,
00174 "Border width in pixels",
00175 0,
00176 10,
00177 1,
00178 G_PARAM_READWRITE | G_PARAM_CONSTRUCT );
00179 g_object_class_install_property( object_class, PROP_BORDER_WIDTH, pspec);
00180
00181 pspec = g_param_spec_uint( PROPNAME_BORDER_OFFSET,
00182 PROPNAME_BORDER_OFFSET,
00183 "Border width in pixels",
00184 0,
00185 10,
00186 0,
00187 G_PARAM_READWRITE | G_PARAM_CONSTRUCT );
00188 g_object_class_install_property( object_class, PROP_BORDER_OFFSET, pspec);
00189
00190 pspec = g_param_spec_string( PROPNAME_BORDER_COLOR,
00191 PROPNAME_BORDER_COLOR,
00192 "Border colour as a string",
00193 "",
00194 G_PARAM_READWRITE | G_PARAM_CONSTRUCT );
00195 g_object_class_install_property( object_class, PROP_BORDER_COLOR, pspec);
00196 }
00197
00198
00199
00200 static void ergtk_cell_renderer_border_init (erGtkCellRendererBorder *thiz)
00201 {
00202 g_return_if_fail( IS_ERGTK_CELL_RENDERER_BORDER(thiz) );
00203
00204 erGtkCellRendererBorderPrivate *priv = ERGTK_CELL_RENDERER_BORDER_GET_PRIVATE(thiz);
00205
00206
00207
00208
00209 priv->border_color = NULL;
00210 }
00211
00212
00213
00214 static void ergtk_cell_renderer_border_finalize (GObject *obj)
00215 {
00216 g_return_if_fail( IS_ERGTK_CELL_RENDERER_BORDER(obj) );
00217
00218 erGtkCellRendererBorderPrivate *priv = ERGTK_CELL_RENDERER_BORDER_GET_PRIVATE(obj);
00219
00220
00221
00222 g_free(priv->border_color);
00223
00224
00225
00226 ((GObjectClass*)g_parent_class)->finalize( obj );
00227 }
00228
00229
00230
00231 GtkCellRenderer *ergtk_cell_renderer_border_new (void)
00232 {
00233 erGtkCellRendererBorder *thiz = (erGtkCellRendererBorder*) g_object_new(ERGTK_CELL_RENDERER_BORDER_TYPE, NULL);
00234
00235
00236 return (GtkCellRenderer*) thiz;
00237 }
00238
00239
00240
00241 static void get_property_impl ( GObject *object,
00242 guint param_id,
00243 GValue *value,
00244 GParamSpec *pspec )
00245 {
00246 g_return_if_fail( IS_ERGTK_CELL_RENDERER_BORDER(object) );
00247
00248 erGtkCellRendererBorderPrivate *priv = ERGTK_CELL_RENDERER_BORDER_GET_PRIVATE(object);
00249
00250 switch (param_id)
00251 {
00252 case PROP_BORDER_WIDTH:
00253 g_value_set_uint (value, priv->border_width);
00254 break;
00255
00256 case PROP_BORDER_OFFSET:
00257 g_value_set_uint (value, priv->border_offset);
00258 break;
00259
00260 case PROP_BORDER_COLOR:
00261 g_value_set_string (value, priv->border_color);
00262 break;
00263
00264 default:
00265 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
00266 }
00267 }
00268
00269
00270
00271 static void set_property_impl ( GObject *object,
00272 guint param_id,
00273 const GValue *value,
00274 GParamSpec *pspec )
00275 {
00276 g_return_if_fail( IS_ERGTK_CELL_RENDERER_BORDER(object) );
00277
00278 erGtkCellRendererBorderPrivate *priv = ERGTK_CELL_RENDERER_BORDER_GET_PRIVATE(object);
00279
00280 guint u;
00281 gchar **cpp;
00282
00283 switch (param_id)
00284 {
00285 case PROP_BORDER_WIDTH:
00286 u = g_value_get_uint(value);
00287 priv->border_width = u;
00288 LOGPRINTF("border-width set to [%u]", u);
00289 break;
00290
00291 case PROP_BORDER_OFFSET:
00292 u = g_value_get_uint(value);
00293 priv->border_offset = u;
00294 LOGPRINTF("border-offset set to [%u]", u);
00295 break;
00296
00297 case PROP_BORDER_COLOR:
00298 cpp = &(priv->border_color);
00299 g_free(*cpp);
00300 *cpp = g_strdup(g_value_get_string(value));
00301 LOGPRINTF("border-color set to [%s]", *cpp);
00302 break;
00303
00304 default:
00305 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
00306 }
00307 }
00308
00309
00310
00311 static void render_impl (GtkCellRenderer *cell,
00312 GdkWindow *window,
00313 GtkWidget *widget,
00314 GdkRectangle *bg_area,
00315 GdkRectangle *cell_area,
00316 GdkRectangle *expose_area,
00317 guint flags)
00318 {
00319 g_return_if_fail( IS_ERGTK_CELL_RENDERER_BORDER(cell) );
00320
00321 erGtkCellRendererBorder *thiz = (erGtkCellRendererBorder *) cell;
00322 erGtkCellRendererBorderPrivate *priv = ERGTK_CELL_RENDERER_BORDER_GET_PRIVATE(thiz);
00323
00324 gint border = priv->border_offset;
00325 gint x = 0 + border;
00326 gint y = bg_area->y + border;
00327 gint w = bg_area->x + bg_area->width - (2 * border) - 1;
00328 gint h = bg_area->height - (2 * border);
00329
00330 gtk_paint_box( widget->style,
00331 window,
00332 GTK_STATE_NORMAL,
00333 GTK_SHADOW_NONE,
00334 NULL, widget, "ergtkcellrendererborder",
00335 x, y, w, h );
00336 }