summaryrefslogtreecommitdiff
path: root/eel
diff options
context:
space:
mode:
authorWolfgang Ulbrich <[email protected]>2016-01-13 15:15:35 +0100
committerWolfgang Ulbrich <[email protected]>2016-01-13 15:15:35 +0100
commit3b7b4cfa969402c5cc9e45369f552729f2b65308 (patch)
tree610589db57c82fb63f5984d28b3009eb2c0cbb5a /eel
parent3c5a4ef68906a73850fa2ffe403cfcd37dc31ff9 (diff)
parent1befe8ddf08c12b5c926d269b31d270fb94b9c3e (diff)
downloadcaja-3b7b4cfa969402c5cc9e45369f552729f2b65308.tar.bz2
caja-3b7b4cfa969402c5cc9e45369f552729f2b65308.tar.xz
Merge pull request #498 from mate-desktop/dev-GtkStyleContext
port to gtk_style_context and other fixes
Diffstat (limited to 'eel')
-rw-r--r--eel/eel-canvas-rect-ellipse.c83
-rw-r--r--eel/eel-canvas-rect-ellipse.h5
-rw-r--r--eel/eel-canvas.c6
-rw-r--r--eel/eel-editable-label.c218
-rw-r--r--eel/eel-gdk-extensions.c73
-rw-r--r--eel/eel-gdk-extensions.h11
-rw-r--r--eel/eel-gdk-pixbuf-extensions.c12
-rw-r--r--eel/eel-gdk-pixbuf-extensions.h4
-rw-r--r--eel/eel-graphic-effects.c17
-rw-r--r--eel/eel-graphic-effects.h9
-rw-r--r--eel/eel-gtk-extensions.c6
11 files changed, 403 insertions, 41 deletions
diff --git a/eel/eel-canvas-rect-ellipse.c b/eel/eel-canvas-rect-ellipse.c
index f93cc85e..0ed0c826 100644
--- a/eel/eel-canvas-rect-ellipse.c
+++ b/eel/eel-canvas-rect-ellipse.c
@@ -54,11 +54,15 @@ enum
PROP_Y1,
PROP_X2,
PROP_Y2,
+#if !GTK_CHECK_VERSION(3,0,0)
PROP_FILL_COLOR,
PROP_FILL_COLOR_GDK,
+#endif
PROP_FILL_COLOR_RGBA,
+#if !GTK_CHECK_VERSION(3,0,0)
PROP_OUTLINE_COLOR,
PROP_OUTLINE_COLOR_GDK,
+#endif
PROP_OUTLINE_COLOR_RGBA,
PROP_OUTLINE_STIPPLING,
PROP_WIDTH_PIXELS,
@@ -168,6 +172,11 @@ eel_canvas_re_class_init (EelCanvasREClass *klass)
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
+#if GTK_CHECK_VERSION(3,0,0)
+ PROP_FILL_COLOR_RGBA,
+ g_param_spec_boxed ("fill-color-rgba", NULL, NULL,
+ GDK_TYPE_RGBA,
+#else
PROP_FILL_COLOR,
g_param_spec_string ("fill-color", NULL, NULL,
NULL,
@@ -195,13 +204,20 @@ eel_canvas_re_class_init (EelCanvasREClass *klass)
PROP_OUTLINE_COLOR_GDK,
g_param_spec_boxed ("outline-color-gdk", NULL, NULL,
GDK_TYPE_COLOR,
+#endif
G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
PROP_OUTLINE_COLOR_RGBA,
+#if GTK_CHECK_VERSION(3,0,0)
+ g_param_spec_boxed ("outline-color-rgba", NULL, NULL,
+ GDK_TYPE_RGBA,
+ G_PARAM_READWRITE));
+#else
g_param_spec_uint ("outline-color-rgba", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READWRITE));
+#endif
g_object_class_install_property
(gobject_class,
PROP_OUTLINE_STIPPLING,
@@ -303,8 +319,10 @@ eel_canvas_re_set_property (GObject *object,
{
EelCanvasItem *item;
EelCanvasRE *re;
+#if !GTK_CHECK_VERSION(3,0,0)
GdkColor color = { 0, 0, 0, 0, };
GdkColor *pcolor;
+#endif
g_return_if_fail (object != NULL);
g_return_if_fail (EEL_IS_CANVAS_RE (object));
@@ -338,6 +356,37 @@ eel_canvas_re_set_property (GObject *object,
eel_canvas_item_request_update (item);
break;
+#if GTK_CHECK_VERSION(3,0,0)
+ case PROP_FILL_COLOR_RGBA: {
+ GdkRGBA *color;
+
+ color = g_value_get_boxed (value);
+
+ eel_canvas_re_set_fill (re, color != NULL);
+
+ if (color != NULL) {
+ re->fill_color = *color;
+ }
+
+ eel_canvas_item_request_redraw (item);
+ break;
+ }
+
+ case PROP_OUTLINE_COLOR_RGBA: {
+ GdkRGBA *color;
+
+ color = g_value_get_boxed (value);
+
+ eel_canvas_re_set_outline (re, color != NULL);
+
+ if (color != NULL) {
+ re->outline_color = *color;
+ }
+
+ eel_canvas_item_request_redraw (item);
+ break;
+ }
+#else
case PROP_FILL_COLOR:
case PROP_FILL_COLOR_GDK:
case PROP_FILL_COLOR_RGBA:
@@ -425,6 +474,7 @@ eel_canvas_re_set_property (GObject *object,
#endif
eel_canvas_item_request_redraw (item);
break;
+#endif
case PROP_OUTLINE_STIPPLING:
re->outline_stippling = g_value_get_boolean (value);
@@ -452,6 +502,7 @@ eel_canvas_re_set_property (GObject *object,
}
}
+#if !GTK_CHECK_VERSION(3,0,0)
/* Allocates a GdkColor structure filled with the specified pixel, and puts it into the specified
* value for returning it in the get_property method.
*/
@@ -469,6 +520,7 @@ get_color_value (EelCanvasRE *re, gulong pixel, GValue *value)
g_value_set_boxed (value, &color);
}
+#endif
static void
eel_canvas_re_get_property (GObject *object,
@@ -501,6 +553,14 @@ eel_canvas_re_get_property (GObject *object,
g_value_set_double (value, re->y2);
break;
+#if GTK_CHECK_VERSION(3,0,0)
+ case PROP_FILL_COLOR_RGBA:
+ g_value_set_boxed (value, &re->fill_color);
+ break;
+
+ case PROP_OUTLINE_COLOR_RGBA:
+ g_value_set_boxed (value, &re->outline_color);
+#else
case PROP_FILL_COLOR_GDK:
get_color_value (re, re->fill_color, value);
break;
@@ -515,6 +575,7 @@ eel_canvas_re_get_property (GObject *object,
case PROP_OUTLINE_COLOR_RGBA:
g_value_set_uint (value, re->outline_color);
+#endif
break;
case PROP_OUTLINE_STIPPLING:
@@ -721,6 +782,11 @@ eel_canvas_rect_realize (EelCanvasItem *item)
static void
eel_canvas_set_source_color (cairo_t *cr,
+#if GTK_CHECK_VERSION(3,0,0)
+ GdkRGBA *rgba)
+{
+ gdk_cairo_set_source_rgba (cr, rgba);
+#else
guint rgba)
{
cairo_set_source_rgba (cr,
@@ -728,6 +794,7 @@ eel_canvas_set_source_color (cairo_t *cr,
((rgba >> 16) & 0xff) / 255.,
((rgba >> 8) & 0xff) / 255.,
((rgba >> 0) & 0xff) / 255.);
+#endif
}
#define DASH_ON 0.8
@@ -773,7 +840,11 @@ eel_canvas_rect_draw (EelCanvasItem *item, GdkDrawable *drawable, GdkEventExpose
if (re->fill_set)
{
+#if GTK_CHECK_VERSION(3,0,0)
+ eel_canvas_set_source_color (cr, &re->fill_color);
+#else
eel_canvas_set_source_color (cr, re->fill_color);
+#endif
cairo_rectangle (cr,
cx1, cy1,
cx2 - cx1 + 1,
@@ -783,7 +854,11 @@ eel_canvas_rect_draw (EelCanvasItem *item, GdkDrawable *drawable, GdkEventExpose
if (re->outline_set)
{
+#if GTK_CHECK_VERSION(3,0,0)
+ eel_canvas_set_source_color (cr, &re->outline_color);
+#else
eel_canvas_set_source_color (cr, re->outline_color);
+#endif
if (re->width_pixels) {
cairo_set_line_width (cr, (int) re->width);
} else {
@@ -1098,13 +1173,21 @@ eel_canvas_ellipse_draw (EelCanvasItem *item, GdkDrawable *drawable, GdkEventExp
if (re->fill_set)
{
+#if GTK_CHECK_VERSION(3,0,0)
+ eel_canvas_set_source_color (cr, &re->fill_color);
+#else
eel_canvas_set_source_color (cr, re->fill_color);
+#endif
cairo_fill_preserve (cr);
}
if (re->outline_set)
{
+#if GTK_CHECK_VERSION(3,0,0)
+ eel_canvas_set_source_color (cr, &re->outline_color);
+#else
eel_canvas_set_source_color (cr, re->outline_color);
+#endif
if (re->width_pixels) {
cairo_set_line_width (cr, (int) re->width);
} else {
diff --git a/eel/eel-canvas-rect-ellipse.h b/eel/eel-canvas-rect-ellipse.h
index aaccf560..d54de4d2 100644
--- a/eel/eel-canvas-rect-ellipse.h
+++ b/eel/eel-canvas-rect-ellipse.h
@@ -84,8 +84,13 @@ extern "C" {
double x1, y1, x2, y2; /* Corners of item */
double width; /* Outline width */
+#if GTK_CHECK_VERSION(3,0,0)
+ GdkRGBA fill_color;
+ GdkRGBA outline_color;
+#else
guint fill_color; /* Fill color, RGBA */
guint outline_color; /* Outline color, RGBA */
+#endif
gboolean outline_stippling;
diff --git a/eel/eel-canvas.c b/eel/eel-canvas.c
index 21216a61..f1f7068d 100644
--- a/eel/eel-canvas.c
+++ b/eel/eel-canvas.c
@@ -3193,13 +3193,17 @@ eel_canvas_draw_background (EelCanvas *canvas,
cairo_t *cr)
{
cairo_rectangle_int_t rect;
+ GtkStyleContext *style_context;
+ GdkRGBA color;
if (!gdk_cairo_get_clip_rectangle (cr, &rect))
return;
cairo_save (cr);
/* By default, we use the style background. */
- gdk_cairo_set_source_color (cr, &gtk_widget_get_style (GTK_WIDGET (canvas))->bg[GTK_STATE_NORMAL]);
+ style_context = gtk_widget_get_style_context (GTK_WIDGET (canvas));
+ gtk_style_context_get_background_color (style_context, GTK_STATE_FLAG_NORMAL, &color);
+ gdk_cairo_set_source_rgba (cr, &color);
gdk_cairo_rectangle (cr, &rect);
cairo_fill (cr);
cairo_restore (cr);
diff --git a/eel/eel-editable-label.c b/eel/eel-editable-label.c
index fe7d5e2f..3edd68ef 100644
--- a/eel/eel-editable-label.c
+++ b/eel/eel-editable-label.c
@@ -100,8 +100,12 @@ static void eel_editable_label_size_allocate (GtkWidget
GtkAllocation *allocation);
static void eel_editable_label_state_changed (GtkWidget *widget,
GtkStateType state);
+#if GTK_CHECK_VERSION(3,0,0)
+static void eel_editable_label_style_updated (GtkWidget *widget);
+#else
static void eel_editable_label_style_set (GtkWidget *widget,
GtkStyle *previous_style);
+#endif
static void eel_editable_label_direction_changed (GtkWidget *widget,
GtkTextDirection previous_dir);
#if GTK_CHECK_VERSION(3,0,0)
@@ -247,7 +251,11 @@ eel_editable_label_class_init (EelEditableLabelClass *class)
#endif
widget_class->size_allocate = eel_editable_label_size_allocate;
widget_class->state_changed = eel_editable_label_state_changed;
+#if GTK_CHECK_VERSION(3,0,0)
+ widget_class->style_updated = eel_editable_label_style_updated;
+#else
widget_class->style_set = eel_editable_label_style_set;
+#endif
widget_class->direction_changed = eel_editable_label_direction_changed;
#if GTK_CHECK_VERSION(3,0,0)
widget_class->draw = eel_editable_label_draw;
@@ -636,6 +644,10 @@ eel_editable_label_init (EelEditableLabel *label)
label->n_bytes = 0;
gtk_widget_set_can_focus (GTK_WIDGET (label), TRUE);
+#if GTK_CHECK_VERSION(3,0,0)
+ gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (label)),
+ GTK_STYLE_CLASS_ENTRY);
+#endif
/* This object is completely private. No external entity can gain a reference
* to it; so we create it here and destroy it in finalize().
@@ -933,7 +945,12 @@ static gint
get_label_wrap_width (EelEditableLabel *label)
{
PangoLayout *layout;
+#if GTK_CHECK_VERSION(3,0,0)
+ GtkStyleContext *style = gtk_widget_get_style_context (GTK_WIDGET (label));
+ PangoFontDescription *desc;
+#else
GtkStyle *style = gtk_widget_get_style (GTK_WIDGET (label));
+#endif
LabelWrapWidth *wrap_width = g_object_get_data (G_OBJECT (style), "gtk-label-wrap-width");
if (!wrap_width)
@@ -943,18 +960,36 @@ get_label_wrap_width (EelEditableLabel *label)
wrap_width, label_wrap_width_free);
}
+#if GTK_CHECK_VERSION(3,0,0)
+ gtk_style_context_get (style, gtk_widget_get_state_flags (GTK_WIDGET (label)),
+ GTK_STYLE_PROPERTY_FONT, &desc,
+ NULL);
+
+ if (wrap_width->font_desc && pango_font_description_equal (wrap_width->font_desc, desc))
+ goto out;
+#else
if (wrap_width->font_desc && pango_font_description_equal (wrap_width->font_desc, style->font_desc))
return wrap_width->width;
+#endif
if (wrap_width->font_desc)
pango_font_description_free (wrap_width->font_desc);
+#if GTK_CHECK_VERSION(3,0,0)
+ wrap_width->font_desc = pango_font_description_copy (desc);
+#else
wrap_width->font_desc = pango_font_description_copy (style->font_desc);
+#endif
layout = gtk_widget_create_pango_layout (GTK_WIDGET (label),
"This long string gives a good enough length for any line to have.");
pango_layout_get_size (layout, &wrap_width->width, NULL);
g_object_unref (layout);
+#if GTK_CHECK_VERSION(3,0,0)
+
+ out:
+ pango_font_description_free (desc);
+#endif
return wrap_width->width;
}
@@ -1123,7 +1158,11 @@ eel_editable_label_size_request (GtkWidget *widget,
gint width, height;
PangoRectangle logical_rect;
gint set_width;
+#if GTK_CHECK_VERSION(3,0,0)
+ gint xpad, ypad;
+#else
gfloat xpad, ypad;
+#endif
g_assert (EEL_IS_EDITABLE_LABEL (widget));
g_assert (requisition != NULL);
@@ -1148,8 +1187,13 @@ eel_editable_label_size_request (GtkWidget *widget,
eel_editable_label_ensure_layout (label, TRUE);
+#if GTK_CHECK_VERSION(3,0,0)
+ gtk_misc_get_padding (&label->misc,
+ &xpad, &ypad);
+#else
gtk_misc_get_alignment (&label->misc,
&xpad, &ypad);
+#endif
width = xpad * 2;
height = ypad * 2;
@@ -1217,8 +1261,12 @@ eel_editable_label_state_changed (GtkWidget *widget,
}
static void
+#if GTK_CHECK_VERSION(3,0,0)
+eel_editable_label_style_updated (GtkWidget *widget)
+#else
eel_editable_label_style_set (GtkWidget *widget,
GtkStyle *previous_style)
+#endif
{
EelEditableLabel *label;
@@ -1226,6 +1274,10 @@ eel_editable_label_style_set (GtkWidget *widget,
label = EEL_EDITABLE_LABEL (widget);
+#if GTK_CHECK_VERSION(3,0,0)
+ GTK_WIDGET_CLASS (eel_editable_label_parent_class)->style_updated (widget);
+#endif
+
/* We have to clear the layout, fonts etc. may have changed */
eel_editable_label_recompute (label);
@@ -1234,10 +1286,17 @@ eel_editable_label_style_set (GtkWidget *widget,
*/
if (gtk_widget_get_realized (widget))
{
+#if GTK_CHECK_VERSION(3,0,0)
+ GtkStyleContext *style;
+
+ style = gtk_widget_get_style_context (widget);
+ gtk_style_context_set_background (style, gtk_widget_get_window (widget));
+#else
GtkStyle *style;
style = gtk_widget_get_style (widget);
gdk_window_set_background (gtk_widget_get_window (widget), &style->base[gtk_widget_get_state (widget)]);
+#endif
}
}
@@ -1546,15 +1605,23 @@ eel_editable_label_draw_cursor (EelEditableLabel *label, gint xoffset, gint yof
}
else /* Block cursor */
{
+#if GTK_CHECK_VERSION(3,0,0)
+ GdkRGBA fg_color;
+ GtkStyleContext *style;
cairo_region_t *clip;
-#if GTK_CHECK_VERSION(3,0,0)
+ style = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_color (style, GTK_STATE_FLAG_NORMAL, &fg_color);
+
cairo_save (cr);
+ gdk_cairo_set_source_rgba (cr, &fg_color);
#else
+ cairo_region_t *clip;
+
cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
-#endif
cairo_set_source_rgb (cr, 0, 0, 0);
+#endif
cairo_rectangle (cr,
xoffset + PANGO_PIXELS (strong_pos.x),
yoffset + PANGO_PIXELS (strong_pos.y),
@@ -1566,14 +1633,27 @@ eel_editable_label_draw_cursor (EelEditableLabel *label, gint xoffset, gint yof
if (!block_at_line_end)
{
+#if GTK_CHECK_VERSION(3,0,0)
+ GdkRGBA color;
+
+#endif
clip = gdk_pango_layout_get_clip_region (label->layout,
xoffset, yoffset,
range, 1);
gdk_cairo_region (cr, clip);
cairo_clip (cr);
+#if GTK_CHECK_VERSION(3,0,0)
+
+ gtk_style_context_get_background_color (style, GTK_STATE_FLAG_FOCUSED,
+ &color);
+
+ gdk_cairo_set_source_rgba (cr,
+ &color);
+#else
gdk_cairo_set_source_color (cr,
&gtk_widget_get_style (widget)->base[GTK_STATE_NORMAL]);
+#endif
cairo_move_to (cr, xoffset, yoffset);
pango_cairo_show_layout (cr, label->layout);
@@ -1594,19 +1674,113 @@ static gint
#if GTK_CHECK_VERSION(3,0,0)
eel_editable_label_draw (GtkWidget *widget,
cairo_t *cr)
+{
+ EelEditableLabel *label;
+ GtkStyleContext *style;
+ gint x, y;
+
+ g_assert (EEL_IS_EDITABLE_LABEL (widget));
+
+ label = EEL_EDITABLE_LABEL (widget);
+ style = gtk_widget_get_style_context (widget);
+
+ gtk_render_background (style, cr,
+ 0, 0,
+ gtk_widget_get_allocated_width (widget),
+ gtk_widget_get_allocated_height (widget));
+
+ eel_editable_label_ensure_layout (label, TRUE);
+
+ if (gtk_widget_get_visible (widget) && gtk_widget_get_mapped (widget) &&
+ label->text)
+ {
+ get_layout_location (label, &x, &y);
+
+ gtk_render_layout (style,
+ cr,
+ x, y,
+ label->layout);
+
+ if (label->selection_anchor != label->selection_end)
+ {
+ gint range[2];
+ const char *text;
+ cairo_region_t *clip;
+ GtkStateType state;
+
+ GdkRGBA background_color;
+
+ range[0] = label->selection_anchor;
+ range[1] = label->selection_end;
+
+ /* Handle possible preedit string */
+ if (label->preedit_length > 0 &&
+ range[1] > label->selection_anchor)
+ {
+ text = pango_layout_get_text (label->layout) + label->selection_anchor;
+ range[1] += g_utf8_offset_to_pointer (text, label->preedit_length) - text;
+ }
+
+ if (range[0] > range[1])
+ {
+ gint tmp = range[0];
+ range[0] = range[1];
+ range[1] = tmp;
+ }
+
+ clip = gdk_pango_layout_get_clip_region (label->layout,
+ x, y,
+ range,
+ 1);
+
+ cairo_save (cr);
+
+ gdk_cairo_region (cr, clip);
+ cairo_clip (cr);
+
+ state = gtk_widget_get_state_flags (widget);
+ state |= GTK_STATE_FLAG_SELECTED;
+
+ gtk_style_context_get_background_color (style, state, &background_color);
+ gdk_cairo_set_source_rgba (cr, &background_color);
+ cairo_paint (cr);
+
+ gtk_style_context_save (style);
+ gtk_style_context_set_state (style, state);
+
+ gtk_render_layout (style, cr,
+ x, y, label->layout);
+
+ gtk_style_context_restore (style);
+
+ cairo_restore (cr);
+
+ cairo_region_destroy (clip);
+ }
+ else if (gtk_widget_has_focus (widget))
+ eel_editable_label_draw_cursor (label, cr, x, y);
+
+ if (label->draw_outline)
+ {
+ gtk_style_context_save (style);
+ gtk_style_context_set_state (style, gtk_widget_get_state_flags (widget));
+
+ gtk_render_frame (style, cr,
+ 0, 0,
+ gtk_widget_get_allocated_width (widget),
+ gtk_widget_get_allocated_height (widget));
+
+ gtk_style_context_restore (style);
#else
eel_editable_label_expose (GtkWidget *widget,
GdkEventExpose *event)
-#endif
{
EelEditableLabel *label;
GtkStyle *style;
+ g_assert (event != NULL);
gint x, y;
g_assert (EEL_IS_EDITABLE_LABEL (widget));
-#if !GTK_CHECK_VERSION(3,0,0)
- g_assert (event != NULL);
-#endif
label = EEL_EDITABLE_LABEL (widget);
style = gtk_widget_get_style (widget);
@@ -1619,16 +1793,10 @@ eel_editable_label_expose (GtkWidget *widget,
get_layout_location (label, &x, &y);
gtk_paint_layout (style,
-#if GTK_CHECK_VERSION(3,0,0)
- cr,
-#else
gtk_widget_get_window (widget),
-#endif
gtk_widget_get_state (widget),
TRUE,
-#if !GTK_CHECK_VERSION(3,0,0)
&event->area,
-#endif
widget,
"label",
x, y,
@@ -1663,11 +1831,8 @@ eel_editable_label_expose (GtkWidget *widget,
x, y,
range,
1);
-#if GTK_CHECK_VERSION(3,0,0)
- cairo_save (cr);
-#else
+
cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
-#endif
gdk_cairo_region (cr, clip);
cairo_clip (cr);
@@ -1682,28 +1847,19 @@ eel_editable_label_expose (GtkWidget *widget,
cairo_move_to (cr, x, y);
pango_cairo_show_layout (cr, label->layout);
-#if GTK_CHECK_VERSION(3,0,0)
- cairo_restore (cr);
-#else
cairo_destroy (cr);
-#endif
+
cairo_region_destroy (clip);
}
else if (gtk_widget_has_focus (widget))
-#if GTK_CHECK_VERSION(3,0,0)
- eel_editable_label_draw_cursor (label, cr, x, y);
-#else
eel_editable_label_draw_cursor (label, x, y);
-#endif
if (label->draw_outline)
{
GtkAllocation allocation;
gtk_widget_get_allocation (widget, &allocation);
-#if !GTK_CHECK_VERSION(3,0,0)
cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
-#endif
gdk_cairo_set_source_color (cr, &style->text [gtk_widget_get_state (widget)]);
cairo_set_line_width (cr, 1.0);
cairo_rectangle (cr, 0.5, 0.5,
@@ -1711,7 +1867,6 @@ eel_editable_label_expose (GtkWidget *widget,
allocation.height - 1);
cairo_stroke (cr);
-#if !GTK_CHECK_VERSION(3,0,0)
cairo_destroy (cr);
#endif
}
@@ -1728,7 +1883,11 @@ eel_editable_label_realize (GtkWidget *widget)
gint attributes_mask;
GtkAllocation allocation;
GdkWindow *window;
+#if GTK_CHECK_VERSION(3,0,0)
+ GtkStyleContext *style;
+#else
GtkStyle *style;
+#endif
gtk_widget_set_realized (widget, TRUE);
label = EEL_EDITABLE_LABEL (widget);
@@ -1769,10 +1928,15 @@ eel_editable_label_realize (GtkWidget *widget)
gdk_cursor_unref (attributes.cursor);
+#if GTK_CHECK_VERSION(3,0,0)
+ style = gtk_widget_get_style_context (widget);
+ gtk_style_context_set_background (style, gtk_widget_get_window (widget));
+#else
style = gtk_style_attach (gtk_widget_get_style (widget) , gtk_widget_get_window (widget));
gtk_widget_set_style (widget, style);
gdk_window_set_background (gtk_widget_get_window (widget), &style->base[gtk_widget_get_state (widget)]);
+#endif
gtk_im_context_set_client_window (label->im_context, gtk_widget_get_window (widget));
}
diff --git a/eel/eel-gdk-extensions.c b/eel/eel-gdk-extensions.c
index 3d68d9a5..2da5bb03 100644
--- a/eel/eel-gdk-extensions.c
+++ b/eel/eel-gdk-extensions.c
@@ -420,6 +420,15 @@ eel_gdk_rgb_to_color_spec (const guint32 color)
* Return true if the given color is `dark'
*/
gboolean
+#if GTK_CHECK_VERSION(3,0,0)
+eel_gdk_rgba_is_dark (const GdkRGBA *color)
+{
+ int intensity;
+
+ intensity = ((((int) (color->red) >> 8) * 77)
+ + (((int) (color->green) >> 8) * 150)
+ + (((int) (color->blue) >> 8) * 28)) >> 8;
+#else
eel_gdk_color_is_dark (GdkColor *color)
{
int intensity;
@@ -427,6 +436,7 @@ eel_gdk_color_is_dark (GdkColor *color)
intensity = (((color->red >> 8) * 77)
+ ((color->green >> 8) * 150)
+ ((color->blue >> 8) * 28)) >> 8;
+#endif
return intensity < 128;
}
@@ -478,22 +488,34 @@ eel_gdk_parse_geometry (const char *string, int *x_return, int *y_return,
void
#if GTK_CHECK_VERSION(3,0,0)
-eel_cairo_draw_layout_with_drop_shadow (cairo_t *cr,
+eel_cairo_draw_layout_with_drop_shadow (cairo_t *cr,
+ GdkRGBA *text_color,
+ GdkRGBA *shadow_color,
+ int x,
+ int y,
+ PangoLayout *layout)
+{
+ cairo_save (cr);
+
+ gdk_cairo_set_source_rgba (cr, shadow_color);
+ cairo_move_to (cr, x+1, y+1);
+ pango_cairo_show_layout (cr, layout);
+
+ gdk_cairo_set_source_rgba (cr, text_color);
+ cairo_move_to (cr, x, y);
+ pango_cairo_show_layout (cr, layout);
+
+ cairo_restore (cr);
#else
eel_gdk_draw_layout_with_drop_shadow (GdkDrawable *drawable,
-#endif
GdkColor *text_color,
GdkColor *shadow_color,
- int x,
- int y,
+ int x,
+ int y,
PangoLayout *layout)
{
-#if GTK_CHECK_VERSION(3,0,0)
- cairo_save (cr);
-#else
cairo_t *cr;
cr = gdk_cairo_create (drawable);
-#endif
gdk_cairo_set_source_color (cr, shadow_color);
cairo_move_to (cr, x+1, y+1);
@@ -503,13 +525,42 @@ eel_gdk_draw_layout_with_drop_shadow (GdkDrawable *drawable,
cairo_move_to (cr, x, y);
pango_cairo_show_layout (cr, layout);
-#if GTK_CHECK_VERSION(3,0,0)
- cairo_restore (cr);
-#else
cairo_destroy (cr);
#endif
}
+#if GTK_CHECK_VERSION(3,0,0)
+#define CLAMP_COLOR(v) (t = (v), CLAMP (t, 0, 1))
+#define SATURATE(v) ((1.0 - saturation) * intensity + saturation * (v))
+
+void
+eel_make_color_inactive (GdkRGBA *color)
+{
+ double intensity, saturation;
+ gdouble t;
+
+ saturation = 0.7;
+ intensity = color->red * 0.30 + color->green * 0.59 + color->blue * 0.11;
+ color->red = SATURATE (color->red);
+ color->green = SATURATE (color->green);
+ color->blue = SATURATE (color->blue);
+
+ if (intensity > 0.5) {
+ color->red *= 0.9;
+ color->green *= 0.9;
+ color->blue *= 0.9;
+ } else {
+ color->red *= 1.25;
+ color->green *= 1.25;
+ color->blue *= 1.25;
+ }
+
+ color->red = CLAMP_COLOR (color->red);
+ color->green = CLAMP_COLOR (color->green);
+ color->blue = CLAMP_COLOR (color->blue);
+}
+#endif
+
#if ! defined (EEL_OMIT_SELF_CHECK)
static char *
diff --git a/eel/eel-gdk-extensions.h b/eel/eel-gdk-extensions.h
index 2036eec4..ad94ddbd 100644
--- a/eel/eel-gdk-extensions.h
+++ b/eel/eel-gdk-extensions.h
@@ -114,7 +114,11 @@ guint32 eel_gdk_color_to_rgb (const GdkColor
GdkColor eel_gdk_rgb_to_color (guint32 color);
char * eel_gdk_rgb_to_color_spec (guint32 color);
+#if GTK_CHECK_VERSION(3,0,0)
+gboolean eel_gdk_rgba_is_dark (const GdkRGBA *color);
+#else
gboolean eel_gdk_color_is_dark (GdkColor *color);
+#endif
/* Wrapper for XParseGeometry */
EelGdkGeometryFlags eel_gdk_parse_geometry (const char *string,
@@ -124,12 +128,17 @@ EelGdkGeometryFlags eel_gdk_parse_geometry (const char
guint *height_return);
#if GTK_CHECK_VERSION(3,0,0)
void eel_cairo_draw_layout_with_drop_shadow (cairo_t *cr,
+ GdkRGBA *text_color,
+ GdkRGBA *shadow_color,
#else
void eel_gdk_draw_layout_with_drop_shadow (GdkDrawable *drawable,
-#endif
GdkColor *text_color,
GdkColor *shadow_color,
+#endif
int x,
int y,
PangoLayout *layout);
+#if GTK_CHECK_VERSION(3,0,0)
+void eel_make_color_inactive (GdkRGBA *color);
+#endif
#endif /* EEL_GDK_EXTENSIONS_H */
diff --git a/eel/eel-gdk-pixbuf-extensions.c b/eel/eel-gdk-pixbuf-extensions.c
index b4cd9394..bbbffc3a 100644
--- a/eel/eel-gdk-pixbuf-extensions.c
+++ b/eel/eel-gdk-pixbuf-extensions.c
@@ -1265,7 +1265,11 @@ eel_gdk_pixbuf_render (GdkPixbuf *pixbuf,
guint saturation,
guint brightness,
guint lighten_value,
+#if GTK_CHECK_VERSION(3,0,0)
+ GdkRGBA *color)
+#else
guint color)
+#endif
{
GdkPixbuf *temp_pixbuf, *old_pixbuf;
@@ -1277,19 +1281,27 @@ eel_gdk_pixbuf_render (GdkPixbuf *pixbuf,
else if (render_mode == 2)
{
/* colorize icon */
+#if GTK_CHECK_VERSION(3,0,0)
+ temp_pixbuf = eel_create_colorized_pixbuf (pixbuf, color);
+#else
temp_pixbuf = eel_create_colorized_pixbuf (pixbuf,
EEL_RGBA_COLOR_GET_R (color),
EEL_RGBA_COLOR_GET_G (color),
EEL_RGBA_COLOR_GET_B (color));
+#endif
}
else if (render_mode == 3)
{
/* monochromely colorize icon */
old_pixbuf = eel_create_darkened_pixbuf (pixbuf, 0, 255);
+#if GTK_CHECK_VERSION(3,0,0)
+ temp_pixbuf = eel_create_colorized_pixbuf (old_pixbuf, color);
+#else
temp_pixbuf = eel_create_colorized_pixbuf (old_pixbuf,
EEL_RGBA_COLOR_GET_R (color),
EEL_RGBA_COLOR_GET_G (color),
EEL_RGBA_COLOR_GET_B (color));
+#endif
g_object_unref (old_pixbuf);
}
else
diff --git a/eel/eel-gdk-pixbuf-extensions.h b/eel/eel-gdk-pixbuf-extensions.h
index 7d31defe..87f79a7a 100644
--- a/eel/eel-gdk-pixbuf-extensions.h
+++ b/eel/eel-gdk-pixbuf-extensions.h
@@ -151,6 +151,10 @@ GdkPixbuf * eel_gdk_pixbuf_render (GdkPixbuf *pixbuf
guint saturation,
guint brightness,
guint lighten_value,
+#if GTK_CHECK_VERSION(3,0,0)
+ GdkRGBA *color);
+#else
guint color);
+#endif
#endif /* EEL_GDK_PIXBUF_EXTENSIONS_H */
diff --git a/eel/eel-graphic-effects.c b/eel/eel-graphic-effects.c
index ffb5beba..39309de9 100644
--- a/eel/eel-graphic-effects.c
+++ b/eel/eel-graphic-effects.c
@@ -26,7 +26,10 @@
and selection hilighting */
#include <config.h>
+
#include "eel-graphic-effects.h"
+#include "eel-glib-extensions.h"
+
#include <string.h>
/* shared utility to create a new pixbuf from the passed-in one */
@@ -169,9 +172,13 @@ eel_create_darkened_pixbuf (GdkPixbuf *src, int saturation, int darken)
GdkPixbuf *
eel_create_colorized_pixbuf (GdkPixbuf *src,
+#if GTK_CHECK_VERSION(3,0,0)
+ GdkRGBA *color)
+#else
int red_value,
int green_value,
int blue_value)
+#endif
{
int i, j;
int width, height, has_alpha, src_row_stride, dst_row_stride;
@@ -181,6 +188,10 @@ eel_create_colorized_pixbuf (GdkPixbuf *src,
guchar *pixdest;
GdkPixbuf *dest;
+#if GTK_CHECK_VERSION(3,0,0)
+ gint red_value, green_value, blue_value;
+#endif
+
g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL);
g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src)
&& gdk_pixbuf_get_n_channels (src) == 3)
@@ -188,6 +199,12 @@ eel_create_colorized_pixbuf (GdkPixbuf *src,
&& gdk_pixbuf_get_n_channels (src) == 4), NULL);
g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL);
+#if GTK_CHECK_VERSION(3,0,0)
+ red_value = eel_round (color->red * 255);
+ green_value = eel_round (color->green * 255);
+ blue_value = eel_round (color->blue * 255);
+#endif
+
dest = create_new_pixbuf (src);
has_alpha = gdk_pixbuf_get_has_alpha (src);
diff --git a/eel/eel-graphic-effects.h b/eel/eel-graphic-effects.h
index 6ae00421..7291629b 100644
--- a/eel/eel-graphic-effects.h
+++ b/eel/eel-graphic-effects.h
@@ -26,6 +26,11 @@
#define EEL_GRAPHIC_EFFECTS_H
#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gtk/gtk.h>
+#if GTK_CHECK_VERSION(3,0,0)
+#include <gdk/gdk.h>
+#endif
+
/* return a lightened pixbuf for pre-lighting */
GdkPixbuf *eel_create_spotlight_pixbuf (GdkPixbuf *source_pixbuf);
@@ -37,9 +42,13 @@ GdkPixbuf *eel_create_darkened_pixbuf (GdkPixbuf *source_pixbuf,
/* return a pixbuf colorized with the color specified by the parameters */
GdkPixbuf* eel_create_colorized_pixbuf (GdkPixbuf *source_pixbuf,
+#if GTK_CHECK_VERSION(3,0,0)
+ GdkRGBA *color);
+#else
int red_value,
int green_value,
int blue_value);
+#endif
/* stretch a image frame */
GdkPixbuf *eel_stretch_frame_image (GdkPixbuf *frame_image,
diff --git a/eel/eel-gtk-extensions.c b/eel/eel-gtk-extensions.c
index b86b2b88..4e1bbeca 100644
--- a/eel/eel-gtk-extensions.c
+++ b/eel/eel-gtk-extensions.c
@@ -406,7 +406,11 @@ eel_gtk_label_make_bold (GtkLabel *label)
* theme or user prefs, since the font desc only has the
* weight flag turned on.
*/
- gtk_widget_modify_font (GTK_WIDGET (label), font_desc);
+#if GTK_CHECK_VERSION(3,0,0)
+ gtk_widget_override_font (GTK_WIDGET (label), font_desc);
+#else
+ gtk_widget_modify_font (GTK_WIDGET (label), font_desc);
+#endif
pango_font_description_free (font_desc);
}