From 2848d0359a8bc433ba9de56ccc93a04d2f6bbdf2 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Fri, 8 Jan 2016 20:16:20 +0100 Subject: GTK3 eel-gdk-extensions: add eel_make_color_inactive() to public API taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=42e7268 --- eel/eel-gdk-extensions.c | 32 ++++++++++++++++++++++++++++++++ eel/eel-gdk-extensions.h | 3 +++ 2 files changed, 35 insertions(+) (limited to 'eel') diff --git a/eel/eel-gdk-extensions.c b/eel/eel-gdk-extensions.c index 3d68d9a5..bbb8a69a 100644 --- a/eel/eel-gdk-extensions.c +++ b/eel/eel-gdk-extensions.c @@ -510,6 +510,38 @@ eel_gdk_draw_layout_with_drop_shadow (GdkDrawable *drawable, #endif } +#if GTK_CHECK_VERSION(3,0,0) +#define CLAMP_COLOR(v) (t = (v), CLAMP (t, 0, G_MAXUSHORT)) +#define SATURATE(v) ((1.0 - saturation) * intensity + saturation * (v)) + +void +eel_make_color_inactive (GdkColor *color) +{ + double intensity, saturation; + gushort 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 > G_MAXUSHORT / 2) { + 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..fedb2c22 100644 --- a/eel/eel-gdk-extensions.h +++ b/eel/eel-gdk-extensions.h @@ -132,4 +132,7 @@ void eel_gdk_draw_layout_with_drop_shadow (GdkDrawable int x, int y, PangoLayout *layout); +#if GTK_CHECK_VERSION(3,0,0) +void eel_make_color_inactive (GdkColor *color); +#endif #endif /* EEL_GDK_EXTENSIONS_H */ -- cgit v1.2.1 From d99909f05e151ace2b6b3eb4f87700c417e513d5 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 26 Dec 2015 19:58:09 +0100 Subject: GTK3 eel-canvas-rect: use RGBA colors only taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=f0691e7 --- eel/eel-canvas-rect-ellipse.c | 83 +++++++++++++++++++++++++++++++++++++++++++ eel/eel-canvas-rect-ellipse.h | 5 +++ 2 files changed, 88 insertions(+) (limited to 'eel') 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; -- cgit v1.2.1 From 74bc6ba6820170591cde83ff54037f50b41b6a22 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 26 Dec 2015 19:59:44 +0100 Subject: Gtk3 eel-canvas: port to GtkStyleContext --- eel/eel-canvas.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'eel') 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, >k_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); -- cgit v1.2.1 From a781d9bffc37f71f4eeb68641f34095d92820507 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 26 Dec 2015 20:10:35 +0100 Subject: GTK3 editable-label: port to GtkStyleContext There are still some rendering artifacts, but we will fix them later. (maybe) taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=d6e07c7 --- eel/eel-editable-label.c | 176 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 152 insertions(+), 24 deletions(-) (limited to 'eel') diff --git a/eel/eel-editable-label.c b/eel/eel-editable-label.c index fe7d5e2f..4998c807 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; @@ -933,7 +941,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 +956,33 @@ get_label_wrap_width (EelEditableLabel *label) wrap_width, label_wrap_width_free); } +#if GTK_CHECK_VERSION(3,0,0) + gtk_style_context_get_style (style, + GTK_STYLE_PROPERTY_FONT, &desc, + NULL); + + if (wrap_width->font_desc && pango_font_description_equal (wrap_width->font_desc, desc)) +#else if (wrap_width->font_desc && pango_font_description_equal (wrap_width->font_desc, style->font_desc)) +#endif return wrap_width->width; 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) + pango_font_description_free (desc); +#endif return wrap_width->width; } @@ -1217,8 +1245,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; @@ -1234,10 +1266,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 } } @@ -1566,14 +1605,29 @@ eel_editable_label_draw_cursor (EelEditableLabel *label, gint xoffset, gint yof if (!block_at_line_end) { +#if GTK_CHECK_VERSION(3,0,0) + GtkStyleContext *style; + 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) + + style = gtk_widget_get_style_context (widget); + 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, >k_widget_get_style (widget)->base[GTK_STATE_NORMAL]); +#endif cairo_move_to (cr, xoffset, yoffset); pango_cairo_show_layout (cr, label->layout); @@ -1594,19 +1648,101 @@ 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); + + 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 color, 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); + + gdk_cairo_region (cr, clip); + cairo_clip (cr); + + state = GTK_STATE_FLAG_SELECTED; + if (!gtk_widget_has_focus (widget)) + state = GTK_STATE_FLAG_ACTIVE; + + gtk_style_context_get_color (style, state, &color); + gtk_style_context_get_background_color (style, state, &background_color); + gdk_cairo_set_source_rgba (cr, &background_color); + cairo_paint (cr); + + cairo_save (cr); + gdk_cairo_set_source_rgba (cr, &color); + gtk_render_layout (style, cr, x, y, label->layout); + + 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) + { + GtkAllocation allocation; + GdkRGBA color; + + gtk_widget_get_allocation (widget, &allocation); + gtk_style_context_get_color (style, gtk_widget_get_state_flags (widget), &color); + gdk_cairo_set_source_rgba (cr, &color); #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 +1755,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 +1793,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,29 +1809,21 @@ 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)]); +#endif cairo_set_line_width (cr, 1.0); cairo_rectangle (cr, 0.5, 0.5, allocation.width - 1, @@ -1728,7 +1847,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 +1892,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)); } -- cgit v1.2.1 From b1b2cb896d0cbe4a210af4bf3b867cb89580c4c3 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 26 Dec 2015 20:20:19 +0100 Subject: GTK3 eel-gdk-pixbuf: use GdkRGBA everywhere taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=020adaf --- eel/eel-gdk-pixbuf-extensions.c | 12 ++++++++++++ eel/eel-gdk-pixbuf-extensions.h | 4 ++++ eel/eel-graphic-effects.c | 17 +++++++++++++++++ eel/eel-graphic-effects.h | 9 +++++++++ 4 files changed, 42 insertions(+) (limited to 'eel') 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 + #include "eel-graphic-effects.h" +#include "eel-glib-extensions.h" + #include /* 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 +#include +#if GTK_CHECK_VERSION(3,0,0) +#include +#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, -- cgit v1.2.1 From 1dffd0e4615ffe0ec3c2b86a61b02d735898ab90 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 26 Dec 2015 20:47:53 +0100 Subject: GTK3 eel-gdk-extensions: port to GtkStyleContext taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=1d3dd96 --- eel/eel-gdk-extensions.c | 49 +++++++++++++++++++++++++++++++++--------------- eel/eel-gdk-extensions.h | 10 ++++++++-- 2 files changed, 42 insertions(+), 17 deletions(-) (limited to 'eel') diff --git a/eel/eel-gdk-extensions.c b/eel/eel-gdk-extensions.c index bbb8a69a..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,22 +525,19 @@ 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, G_MAXUSHORT)) +#define CLAMP_COLOR(v) (t = (v), CLAMP (t, 0, 1)) #define SATURATE(v) ((1.0 - saturation) * intensity + saturation * (v)) void -eel_make_color_inactive (GdkColor *color) +eel_make_color_inactive (GdkRGBA *color) { double intensity, saturation; - gushort t; + gdouble t; saturation = 0.7; intensity = color->red * 0.30 + color->green * 0.59 + color->blue * 0.11; @@ -526,7 +545,7 @@ eel_make_color_inactive (GdkColor *color) color->green = SATURATE (color->green); color->blue = SATURATE (color->blue); - if (intensity > G_MAXUSHORT / 2) { + if (intensity > 0.5) { color->red *= 0.9; color->green *= 0.9; color->blue *= 0.9; diff --git a/eel/eel-gdk-extensions.h b/eel/eel-gdk-extensions.h index fedb2c22..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,15 +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 (GdkColor *color); +void eel_make_color_inactive (GdkRGBA *color); #endif #endif /* EEL_GDK_EXTENSIONS_H */ -- cgit v1.2.1 From d125a70db28b8f37543ef93469f4736859afb53b Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Fri, 8 Jan 2016 21:07:15 +0100 Subject: Gtk3 eel-gtk-extensions: do not use gtk_widget_modify_font taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=b5302eb --- eel/eel-gtk-extensions.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'eel') 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); } -- cgit v1.2.1 From 7eea4d477154160e3dd52b76346218b0ca22f8ed Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Fri, 8 Jan 2016 21:51:03 +0100 Subject: GTK3 editable-label: copy-paste code from GTK+ to sync drawing with GtkLabel taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=ca9f8d8 https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=e3feaf8 https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=caa55b7 --- eel/eel-editable-label.c | 223 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 220 insertions(+), 3 deletions(-) (limited to 'eel') diff --git a/eel/eel-editable-label.c b/eel/eel-editable-label.c index 4998c807..3e138305 100644 --- a/eel/eel-editable-label.c +++ b/eel/eel-editable-label.c @@ -49,6 +49,218 @@ #define g_memmove memmove #endif +#if GTK_CHECK_VERSION (3, 0, 0) +/* copy-paste from gtk/gtkpango.c */ +#define EEL_TYPE_FILL_LAYOUT_RENDERER (_eel_fill_layout_renderer_get_type()) +#define EEL_FILL_LAYOUT_RENDERER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), EEL_TYPE_FILL_LAYOUT_RENDERER, EelFillLayoutRenderer)) +#define EEL_IS_FILL_LAYOUT_RENDERER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), EEL_TYPE_FILL_LAYOUT_RENDERER)) +#define EEL_FILL_LAYOUT_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEL_TYPE_FILL_LAYOUT_RENDERER, EelFillLayoutRendererClass)) +#define EEL_IS_FILL_LAYOUT_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEL_TYPE_FILL_LAYOUT_RENDERER)) +#define EEL_FILL_LAYOUT_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEL_TYPE_FILL_LAYOUT_RENDERER, EelFillLayoutRendererClass)) + +typedef struct _EelFillLayoutRenderer EelFillLayoutRenderer; +typedef struct _EelFillLayoutRendererClass EelFillLayoutRendererClass; + +struct _EelFillLayoutRenderer +{ + PangoRenderer parent_instance; + + cairo_t *cr; +}; + +struct _EelFillLayoutRendererClass +{ + PangoRendererClass parent_class; +}; + +static GType _eel_fill_layout_renderer_get_type (void); +G_DEFINE_TYPE (EelFillLayoutRenderer, _eel_fill_layout_renderer, PANGO_TYPE_RENDERER) + +static void +eel_fill_layout_renderer_draw_glyphs (PangoRenderer *renderer, + PangoFont *font, + PangoGlyphString *glyphs, + int x, + int y) +{ + EelFillLayoutRenderer *text_renderer = EEL_FILL_LAYOUT_RENDERER (renderer); + + cairo_move_to (text_renderer->cr, (double)x / PANGO_SCALE, (double)y / PANGO_SCALE); + pango_cairo_show_glyph_string (text_renderer->cr, font, glyphs); +} + +static void +eel_fill_layout_renderer_draw_glyph_item (PangoRenderer *renderer, + const char *text, + PangoGlyphItem *glyph_item, + int x, + int y) +{ + EelFillLayoutRenderer *text_renderer = EEL_FILL_LAYOUT_RENDERER (renderer); + + cairo_move_to (text_renderer->cr, (double)x / PANGO_SCALE, (double)y / PANGO_SCALE); + pango_cairo_show_glyph_item (text_renderer->cr, text, glyph_item); +} + +static void +eel_fill_layout_renderer_draw_rectangle (PangoRenderer *renderer, + PangoRenderPart part, + int x, + int y, + int width, + int height) +{ + EelFillLayoutRenderer *text_renderer = EEL_FILL_LAYOUT_RENDERER (renderer); + + if (part == PANGO_RENDER_PART_BACKGROUND) + return; + + cairo_rectangle (text_renderer->cr, + (double)x / PANGO_SCALE, (double)y / PANGO_SCALE, + (double)width / PANGO_SCALE, (double)height / PANGO_SCALE); + cairo_fill (text_renderer->cr); +} + +static void +eel_fill_layout_renderer_draw_trapezoid (PangoRenderer *renderer, + PangoRenderPart part, + double y1_, + double x11, + double x21, + double y2, + double x12, + double x22) +{ + EelFillLayoutRenderer *text_renderer = EEL_FILL_LAYOUT_RENDERER (renderer); + cairo_matrix_t matrix; + cairo_t *cr; + + cr = text_renderer->cr; + + cairo_save (cr); + + /* use identity scale, but keep translation */ + cairo_get_matrix (cr, &matrix); + matrix.xx = matrix.yy = 1; + matrix.xy = matrix.yx = 0; + cairo_set_matrix (cr, &matrix); + + cairo_move_to (cr, x11, y1_); + cairo_line_to (cr, x21, y1_); + cairo_line_to (cr, x22, y2); + cairo_line_to (cr, x12, y2); + cairo_close_path (cr); + + cairo_fill (cr); + + cairo_restore (cr); +} + +static void +eel_fill_layout_renderer_draw_error_underline (PangoRenderer *renderer, + int x, + int y, + int width, + int height) +{ + EelFillLayoutRenderer *text_renderer = EEL_FILL_LAYOUT_RENDERER (renderer); + + pango_cairo_show_error_underline (text_renderer->cr, + (double)x / PANGO_SCALE, (double)y / PANGO_SCALE, + (double)width / PANGO_SCALE, (double)height / PANGO_SCALE); +} + +static void +eel_fill_layout_renderer_draw_shape (PangoRenderer *renderer, + PangoAttrShape *attr, + int x, + int y) +{ + EelFillLayoutRenderer *text_renderer = EEL_FILL_LAYOUT_RENDERER (renderer); + cairo_t *cr = text_renderer->cr; + PangoLayout *layout; + PangoCairoShapeRendererFunc shape_renderer; + gpointer shape_renderer_data; + + layout = pango_renderer_get_layout (renderer); + + if (!layout) + return; + + shape_renderer = pango_cairo_context_get_shape_renderer (pango_layout_get_context (layout), + &shape_renderer_data); + + if (!shape_renderer) + return; + + cairo_save (cr); + + cairo_move_to (cr, (double)x / PANGO_SCALE, (double)y / PANGO_SCALE); + + shape_renderer (cr, attr, FALSE, shape_renderer_data); + + cairo_restore (cr); +} + +static void +eel_fill_layout_renderer_finalize (GObject *object) +{ + G_OBJECT_CLASS (_eel_fill_layout_renderer_parent_class)->finalize (object); +} + +static void +_eel_fill_layout_renderer_init (EelFillLayoutRenderer *renderer) +{ +} + +static void +_eel_fill_layout_renderer_class_init (EelFillLayoutRendererClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + PangoRendererClass *renderer_class = PANGO_RENDERER_CLASS (klass); + + renderer_class->draw_glyphs = eel_fill_layout_renderer_draw_glyphs; + renderer_class->draw_glyph_item = eel_fill_layout_renderer_draw_glyph_item; + renderer_class->draw_rectangle = eel_fill_layout_renderer_draw_rectangle; + renderer_class->draw_trapezoid = eel_fill_layout_renderer_draw_trapezoid; + renderer_class->draw_error_underline = eel_fill_layout_renderer_draw_error_underline; + renderer_class->draw_shape = eel_fill_layout_renderer_draw_shape; + + object_class->finalize = eel_fill_layout_renderer_finalize; +} + +static void +_eel_pango_fill_layout (cairo_t *cr, + PangoLayout *layout) +{ + static EelFillLayoutRenderer *renderer = NULL; + gboolean has_current_point; + double current_x, current_y; + + has_current_point = cairo_has_current_point (cr); + cairo_get_current_point (cr, ¤t_x, ¤t_y); + + if (renderer == NULL) + renderer = g_object_new (EEL_TYPE_FILL_LAYOUT_RENDERER, NULL); + + cairo_save (cr); + cairo_translate (cr, current_x, current_y); + + renderer->cr = cr; + pango_renderer_draw_layout (PANGO_RENDERER (renderer), layout, 0, 0); + + cairo_restore (cr); + + if (has_current_point) + cairo_move_to (cr, current_x, current_y); +} + +/* end copy-paste from gtkpango.c */ + +/* end copy-paste from gtkpango.c */ +#endif + enum { MOVE_CURSOR, @@ -1702,6 +1914,8 @@ eel_editable_label_draw (GtkWidget *widget, range, 1); + cairo_save (cr); + gdk_cairo_region (cr, clip); cairo_clip (cr); @@ -1716,7 +1930,7 @@ eel_editable_label_draw (GtkWidget *widget, cairo_save (cr); gdk_cairo_set_source_rgba (cr, &color); - gtk_render_layout (style, cr, x, y, label->layout); + _eel_pango_fill_layout (cr, label->layout); cairo_restore (cr); @@ -1733,6 +1947,11 @@ eel_editable_label_draw (GtkWidget *widget, gtk_widget_get_allocation (widget, &allocation); gtk_style_context_get_color (style, gtk_widget_get_state_flags (widget), &color); gdk_cairo_set_source_rgba (cr, &color); + cairo_set_line_width (cr, 1.0); + cairo_rectangle (cr, 0.5, 0.5, + allocation.width - 2, + allocation.height - 2); + cairo_stroke (cr); #else eel_editable_label_expose (GtkWidget *widget, GdkEventExpose *event) @@ -1823,14 +2042,12 @@ eel_editable_label_expose (GtkWidget *widget, gtk_widget_get_allocation (widget, &allocation); cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget)); gdk_cairo_set_source_color (cr, &style->text [gtk_widget_get_state (widget)]); -#endif cairo_set_line_width (cr, 1.0); cairo_rectangle (cr, 0.5, 0.5, allocation.width - 1, allocation.height - 1); cairo_stroke (cr); -#if !GTK_CHECK_VERSION(3,0,0) cairo_destroy (cr); #endif } -- cgit v1.2.1 From c8c302522c9692e616611def4594c8f7364e79d2 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Thu, 7 Jan 2016 23:49:26 +0100 Subject: GTK3 editable-label: use gtk_style_context_get() to query standard props Also, fix a leak. taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=ef8544b --- eel/eel-editable-label.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'eel') diff --git a/eel/eel-editable-label.c b/eel/eel-editable-label.c index 3e138305..0c127525 100644 --- a/eel/eel-editable-label.c +++ b/eel/eel-editable-label.c @@ -1169,15 +1169,16 @@ get_label_wrap_width (EelEditableLabel *label) } #if GTK_CHECK_VERSION(3,0,0) - gtk_style_context_get_style (style, - GTK_STYLE_PROPERTY_FONT, &desc, - NULL); + 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)) -#endif return wrap_width->width; +#endif if (wrap_width->font_desc) pango_font_description_free (wrap_width->font_desc); @@ -1193,6 +1194,8 @@ get_label_wrap_width (EelEditableLabel *label) 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 -- cgit v1.2.1 From 098a34323263e29a4c221fb49305dd666296aa74 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 9 Jan 2016 16:20:18 +0100 Subject: GTK3 editable-label: fix some drawing regressions taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=6d079cc --- eel/eel-editable-label.c | 229 +++-------------------------------------------- 1 file changed, 10 insertions(+), 219 deletions(-) (limited to 'eel') diff --git a/eel/eel-editable-label.c b/eel/eel-editable-label.c index 0c127525..c91dfcc2 100644 --- a/eel/eel-editable-label.c +++ b/eel/eel-editable-label.c @@ -49,218 +49,6 @@ #define g_memmove memmove #endif -#if GTK_CHECK_VERSION (3, 0, 0) -/* copy-paste from gtk/gtkpango.c */ -#define EEL_TYPE_FILL_LAYOUT_RENDERER (_eel_fill_layout_renderer_get_type()) -#define EEL_FILL_LAYOUT_RENDERER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), EEL_TYPE_FILL_LAYOUT_RENDERER, EelFillLayoutRenderer)) -#define EEL_IS_FILL_LAYOUT_RENDERER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), EEL_TYPE_FILL_LAYOUT_RENDERER)) -#define EEL_FILL_LAYOUT_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEL_TYPE_FILL_LAYOUT_RENDERER, EelFillLayoutRendererClass)) -#define EEL_IS_FILL_LAYOUT_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEL_TYPE_FILL_LAYOUT_RENDERER)) -#define EEL_FILL_LAYOUT_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEL_TYPE_FILL_LAYOUT_RENDERER, EelFillLayoutRendererClass)) - -typedef struct _EelFillLayoutRenderer EelFillLayoutRenderer; -typedef struct _EelFillLayoutRendererClass EelFillLayoutRendererClass; - -struct _EelFillLayoutRenderer -{ - PangoRenderer parent_instance; - - cairo_t *cr; -}; - -struct _EelFillLayoutRendererClass -{ - PangoRendererClass parent_class; -}; - -static GType _eel_fill_layout_renderer_get_type (void); -G_DEFINE_TYPE (EelFillLayoutRenderer, _eel_fill_layout_renderer, PANGO_TYPE_RENDERER) - -static void -eel_fill_layout_renderer_draw_glyphs (PangoRenderer *renderer, - PangoFont *font, - PangoGlyphString *glyphs, - int x, - int y) -{ - EelFillLayoutRenderer *text_renderer = EEL_FILL_LAYOUT_RENDERER (renderer); - - cairo_move_to (text_renderer->cr, (double)x / PANGO_SCALE, (double)y / PANGO_SCALE); - pango_cairo_show_glyph_string (text_renderer->cr, font, glyphs); -} - -static void -eel_fill_layout_renderer_draw_glyph_item (PangoRenderer *renderer, - const char *text, - PangoGlyphItem *glyph_item, - int x, - int y) -{ - EelFillLayoutRenderer *text_renderer = EEL_FILL_LAYOUT_RENDERER (renderer); - - cairo_move_to (text_renderer->cr, (double)x / PANGO_SCALE, (double)y / PANGO_SCALE); - pango_cairo_show_glyph_item (text_renderer->cr, text, glyph_item); -} - -static void -eel_fill_layout_renderer_draw_rectangle (PangoRenderer *renderer, - PangoRenderPart part, - int x, - int y, - int width, - int height) -{ - EelFillLayoutRenderer *text_renderer = EEL_FILL_LAYOUT_RENDERER (renderer); - - if (part == PANGO_RENDER_PART_BACKGROUND) - return; - - cairo_rectangle (text_renderer->cr, - (double)x / PANGO_SCALE, (double)y / PANGO_SCALE, - (double)width / PANGO_SCALE, (double)height / PANGO_SCALE); - cairo_fill (text_renderer->cr); -} - -static void -eel_fill_layout_renderer_draw_trapezoid (PangoRenderer *renderer, - PangoRenderPart part, - double y1_, - double x11, - double x21, - double y2, - double x12, - double x22) -{ - EelFillLayoutRenderer *text_renderer = EEL_FILL_LAYOUT_RENDERER (renderer); - cairo_matrix_t matrix; - cairo_t *cr; - - cr = text_renderer->cr; - - cairo_save (cr); - - /* use identity scale, but keep translation */ - cairo_get_matrix (cr, &matrix); - matrix.xx = matrix.yy = 1; - matrix.xy = matrix.yx = 0; - cairo_set_matrix (cr, &matrix); - - cairo_move_to (cr, x11, y1_); - cairo_line_to (cr, x21, y1_); - cairo_line_to (cr, x22, y2); - cairo_line_to (cr, x12, y2); - cairo_close_path (cr); - - cairo_fill (cr); - - cairo_restore (cr); -} - -static void -eel_fill_layout_renderer_draw_error_underline (PangoRenderer *renderer, - int x, - int y, - int width, - int height) -{ - EelFillLayoutRenderer *text_renderer = EEL_FILL_LAYOUT_RENDERER (renderer); - - pango_cairo_show_error_underline (text_renderer->cr, - (double)x / PANGO_SCALE, (double)y / PANGO_SCALE, - (double)width / PANGO_SCALE, (double)height / PANGO_SCALE); -} - -static void -eel_fill_layout_renderer_draw_shape (PangoRenderer *renderer, - PangoAttrShape *attr, - int x, - int y) -{ - EelFillLayoutRenderer *text_renderer = EEL_FILL_LAYOUT_RENDERER (renderer); - cairo_t *cr = text_renderer->cr; - PangoLayout *layout; - PangoCairoShapeRendererFunc shape_renderer; - gpointer shape_renderer_data; - - layout = pango_renderer_get_layout (renderer); - - if (!layout) - return; - - shape_renderer = pango_cairo_context_get_shape_renderer (pango_layout_get_context (layout), - &shape_renderer_data); - - if (!shape_renderer) - return; - - cairo_save (cr); - - cairo_move_to (cr, (double)x / PANGO_SCALE, (double)y / PANGO_SCALE); - - shape_renderer (cr, attr, FALSE, shape_renderer_data); - - cairo_restore (cr); -} - -static void -eel_fill_layout_renderer_finalize (GObject *object) -{ - G_OBJECT_CLASS (_eel_fill_layout_renderer_parent_class)->finalize (object); -} - -static void -_eel_fill_layout_renderer_init (EelFillLayoutRenderer *renderer) -{ -} - -static void -_eel_fill_layout_renderer_class_init (EelFillLayoutRendererClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - PangoRendererClass *renderer_class = PANGO_RENDERER_CLASS (klass); - - renderer_class->draw_glyphs = eel_fill_layout_renderer_draw_glyphs; - renderer_class->draw_glyph_item = eel_fill_layout_renderer_draw_glyph_item; - renderer_class->draw_rectangle = eel_fill_layout_renderer_draw_rectangle; - renderer_class->draw_trapezoid = eel_fill_layout_renderer_draw_trapezoid; - renderer_class->draw_error_underline = eel_fill_layout_renderer_draw_error_underline; - renderer_class->draw_shape = eel_fill_layout_renderer_draw_shape; - - object_class->finalize = eel_fill_layout_renderer_finalize; -} - -static void -_eel_pango_fill_layout (cairo_t *cr, - PangoLayout *layout) -{ - static EelFillLayoutRenderer *renderer = NULL; - gboolean has_current_point; - double current_x, current_y; - - has_current_point = cairo_has_current_point (cr); - cairo_get_current_point (cr, ¤t_x, ¤t_y); - - if (renderer == NULL) - renderer = g_object_new (EEL_TYPE_FILL_LAYOUT_RENDERER, NULL); - - cairo_save (cr); - cairo_translate (cr, current_x, current_y); - - renderer->cr = cr; - pango_renderer_draw_layout (PANGO_RENDERER (renderer), layout, 0, 0); - - cairo_restore (cr); - - if (has_current_point) - cairo_move_to (cr, current_x, current_y); -} - -/* end copy-paste from gtkpango.c */ - -/* end copy-paste from gtkpango.c */ -#endif - enum { MOVE_CURSOR, @@ -1892,7 +1680,7 @@ eel_editable_label_draw (GtkWidget *widget, cairo_region_t *clip; GtkStateType state; - GdkRGBA color, background_color; + GdkRGBA background_color; range[0] = label->selection_anchor; range[1] = label->selection_end; @@ -1926,14 +1714,17 @@ eel_editable_label_draw (GtkWidget *widget, if (!gtk_widget_has_focus (widget)) state = GTK_STATE_FLAG_ACTIVE; - gtk_style_context_get_color (style, state, &color); gtk_style_context_get_background_color (style, state, &background_color); gdk_cairo_set_source_rgba (cr, &background_color); cairo_paint (cr); - cairo_save (cr); - gdk_cairo_set_source_rgba (cr, &color); - _eel_pango_fill_layout (cr, label->layout); + 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); @@ -1952,8 +1743,8 @@ eel_editable_label_draw (GtkWidget *widget, gdk_cairo_set_source_rgba (cr, &color); cairo_set_line_width (cr, 1.0); cairo_rectangle (cr, 0.5, 0.5, - allocation.width - 2, - allocation.height - 2); + allocation.width - 1, + allocation.height - 1); cairo_stroke (cr); #else eel_editable_label_expose (GtkWidget *widget, -- cgit v1.2.1 From 6698c8b370f2d9aa278b63090cbc9957d7ca0e36 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 9 Jan 2016 18:05:52 +0100 Subject: GTK3 editable-label: chain up in style_updated() taken from: https://git.gnome.org/browse/nautilus/commit/?id=fbabd8e --- eel/eel-editable-label.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'eel') diff --git a/eel/eel-editable-label.c b/eel/eel-editable-label.c index c91dfcc2..68233ab7 100644 --- a/eel/eel-editable-label.c +++ b/eel/eel-editable-label.c @@ -1261,6 +1261,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); -- cgit v1.2.1 From 59d1c9281e80922c2bda883c4635379022beb375 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 9 Jan 2016 20:29:00 +0100 Subject: GTK3 editable-label: make sure to size_request the padding set on the label And not the alignment, which is an offset inside the allocated size. taken from: https://git.gnome.org/browse/nautilus/commit/?id=8b87a3e --- eel/eel-editable-label.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'eel') diff --git a/eel/eel-editable-label.c b/eel/eel-editable-label.c index 68233ab7..9f2fd3a3 100644 --- a/eel/eel-editable-label.c +++ b/eel/eel-editable-label.c @@ -1154,7 +1154,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); @@ -1179,8 +1183,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; -- cgit v1.2.1 From 930436556075111dc13d4c8d8d270a3c89a9cd13 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 9 Jan 2016 20:31:36 +0100 Subject: GTK3 editable-label: don't hardcode black for the insertion cursor Use the theme foreground/text color instead. taken from: https://git.gnome.org/browse/nautilus/commit/?id=f9383ac --- eel/eel-editable-label.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'eel') diff --git a/eel/eel-editable-label.c b/eel/eel-editable-label.c index 9f2fd3a3..06948610 100644 --- a/eel/eel-editable-label.c +++ b/eel/eel-editable-label.c @@ -1601,15 +1601,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), @@ -1622,7 +1630,6 @@ eel_editable_label_draw_cursor (EelEditableLabel *label, gint xoffset, gint yof if (!block_at_line_end) { #if GTK_CHECK_VERSION(3,0,0) - GtkStyleContext *style; GdkRGBA color; #endif @@ -1634,7 +1641,6 @@ eel_editable_label_draw_cursor (EelEditableLabel *label, gint xoffset, gint yof cairo_clip (cr); #if GTK_CHECK_VERSION(3,0,0) - style = gtk_widget_get_style_context (widget); gtk_style_context_get_background_color (style, GTK_STATE_FLAG_FOCUSED, &color); -- cgit v1.2.1 From de1bef38ac1fb7e33bf3742200635870eb22ae2e Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 9 Jan 2016 20:34:56 +0100 Subject: GTK3 editable-label: use gtk_render_frame() instead of hardcoding a stroke This allows the stroke to use rounded corners and border images, among other things. taken from: https://git.gnome.org/browse/nautilus/commit/?id=b143b95 --- eel/eel-editable-label.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'eel') diff --git a/eel/eel-editable-label.c b/eel/eel-editable-label.c index 06948610..7414c19c 100644 --- a/eel/eel-editable-label.c +++ b/eel/eel-editable-label.c @@ -1754,17 +1754,15 @@ eel_editable_label_draw (GtkWidget *widget, if (label->draw_outline) { - GtkAllocation allocation; - GdkRGBA color; + gtk_style_context_save (style); + gtk_style_context_set_state (style, gtk_widget_get_state_flags (widget)); - gtk_widget_get_allocation (widget, &allocation); - gtk_style_context_get_color (style, gtk_widget_get_state_flags (widget), &color); - gdk_cairo_set_source_rgba (cr, &color); - cairo_set_line_width (cr, 1.0); - cairo_rectangle (cr, 0.5, 0.5, - allocation.width - 1, - allocation.height - 1); - cairo_stroke (cr); + 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) -- cgit v1.2.1 From 7a2f6641563b525bf32c18a2e52ac290f06c9a53 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 9 Jan 2016 20:37:32 +0100 Subject: GTK3 editable-label: use GTK_STYLE_CLASS_ENTRY Because that's what it is actually... taken from: https://git.gnome.org/browse/nautilus/commit/?id=e54ace0 --- eel/eel-editable-label.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'eel') diff --git a/eel/eel-editable-label.c b/eel/eel-editable-label.c index 7414c19c..834f2d1a 100644 --- a/eel/eel-editable-label.c +++ b/eel/eel-editable-label.c @@ -644,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(). -- cgit v1.2.1 From d1c10a0a832731f81db1c627c07fe5d750543294 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 9 Jan 2016 20:40:21 +0100 Subject: GTK3 editable-label: fix selection color in backdrop state Don't set the ACTIVE flag if we don't have focus, it just doesn't make sense. taken from: https://git.gnome.org/browse/nautilus/commit/?id=845d3fc --- eel/eel-editable-label.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'eel') diff --git a/eel/eel-editable-label.c b/eel/eel-editable-label.c index 834f2d1a..4e1cbdf5 100644 --- a/eel/eel-editable-label.c +++ b/eel/eel-editable-label.c @@ -1733,9 +1733,8 @@ eel_editable_label_draw (GtkWidget *widget, gdk_cairo_region (cr, clip); cairo_clip (cr); - state = GTK_STATE_FLAG_SELECTED; - if (!gtk_widget_has_focus (widget)) - state = GTK_STATE_FLAG_ACTIVE; + 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); -- cgit v1.2.1 From d430735d425443f9fbfd301b4ece46c1058281eb Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 9 Jan 2016 20:43:28 +0100 Subject: GTK3 editable-Label: render background Without this the rename widget background is always transparent, which makes it very hard to read on e.g. the desktop with a background image. taken from: https://git.gnome.org/browse/nautilus/commit/?id=c3b2b0a --- eel/eel-editable-label.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'eel') diff --git a/eel/eel-editable-label.c b/eel/eel-editable-label.c index 4e1cbdf5..3edd68ef 100644 --- a/eel/eel-editable-label.c +++ b/eel/eel-editable-label.c @@ -1684,6 +1684,11 @@ eel_editable_label_draw (GtkWidget *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) && @@ -1691,10 +1696,10 @@ eel_editable_label_draw (GtkWidget *widget, { get_layout_location (label, &x, &y); - gtk_render_layout (style, - cr, - x, y, - label->layout); + gtk_render_layout (style, + cr, + x, y, + label->layout); if (label->selection_anchor != label->selection_end) { -- cgit v1.2.1