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(+) 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 a461e0a356a76f81076d78dd3b08a854884cdeeb Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 26 Dec 2015 19:55:08 +0100 Subject: GTK3 icon-dnd: fix DnD highlighting regression taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=7bd06fa --- libcaja-private/caja-icon-dnd.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libcaja-private/caja-icon-dnd.c b/libcaja-private/caja-icon-dnd.c index 376490dc..38820aa9 100644 --- a/libcaja-private/caja-icon-dnd.c +++ b/libcaja-private/caja-icon-dnd.c @@ -1611,11 +1611,17 @@ drag_highlight_expose (GtkWidget *widget, gpointer data) #endif { +#if GTK_CHECK_VERSION(3,0,0) + gint width, height; +#else gint x, y, width, height; +#endif GdkWindow *window; +#if !GTK_CHECK_VERSION(3,0,0) x = gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (widget))); y = gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (widget))); +#endif window = gtk_widget_get_window (widget); width = gdk_window_get_width (window); @@ -1626,7 +1632,7 @@ drag_highlight_expose (GtkWidget *widget, cr, GTK_STATE_NORMAL, GTK_SHADOW_OUT, widget, "dnd", - x, y, width, height); + 0, 0, width, height); #else gtk_paint_shadow (gtk_widget_get_style (widget), window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, @@ -1638,7 +1644,11 @@ drag_highlight_expose (GtkWidget *widget, cairo_set_line_width (cr, 1.0); cairo_set_source_rgb (cr, 0, 0, 0); +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_rectangle (cr, 0.5, 0.5, width - 1, height - 1); +#else cairo_rectangle (cr, x + 0.5, y + 0.5, width - 1, height - 1); +#endif cairo_stroke (cr); #if !GTK_CHECK_VERSION(3,0,0) cairo_destroy (cr); -- 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(+) 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(-) 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(-) 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(+) 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 4df0d0df37e1a69a4c6bcd76580adc736d1f4e5f Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 26 Dec 2015 20:31:28 +0100 Subject: GTK3 file-conflict-dialog: port to GtkStyleContext taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=5da941e --- libcaja-private/caja-file-conflict-dialog.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/libcaja-private/caja-file-conflict-dialog.c b/libcaja-private/caja-file-conflict-dialog.c index cda3069b..28887f88 100644 --- a/libcaja-private/caja-file-conflict-dialog.c +++ b/libcaja-private/caja-file-conflict-dialog.c @@ -115,7 +115,12 @@ file_list_ready_cb (GList *files, GdkPixbuf *pixbuf; GtkWidget *label; GString *str; +#if GTK_CHECK_VERSION(3,0,0) + PangoFontDescription *desc, *old_desc; + GtkStyleContext *style; +#else PangoFontDescription *desc; +#endif details = fcd->details; @@ -219,18 +224,35 @@ file_list_ready_cb (GList *files, gtk_widget_set_size_request (label, 350, -1); #if GTK_CHECK_VERSION (3, 14, 0) gtk_widget_set_halign (label, GTK_ALIGN_START); + gtk_box_pack_start (GTK_BOX (details->titles_vbox), + label, FALSE, FALSE, 0); + + style = gtk_widget_get_style_context (label); + gtk_style_context_get_style (style, + GTK_STYLE_PROPERTY_FONT, &old_desc, + NULL); + + desc = pango_font_description_new (); + pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD); + pango_font_description_set_size (desc, + pango_font_description_get_size (old_desc) * PANGO_SCALE_LARGE); + gtk_widget_override_font (label, desc); + pango_font_description_free (desc); + pango_font_description_free (old_desc); #else gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); -#endif gtk_box_pack_start (GTK_BOX (details->titles_vbox), label, FALSE, FALSE, 0); + gtk_widget_modify_font (label, NULL); + desc = pango_font_description_new (); pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD); pango_font_description_set_size (desc, pango_font_description_get_size (gtk_widget_get_style (label)->font_desc) * PANGO_SCALE_LARGE); gtk_widget_modify_font (label, desc); pango_font_description_free (desc); +#endif gtk_widget_show (label); label = gtk_label_new (secondary_text); -- cgit v1.2.1 From dca1155b3473e91ef12b03dca1506b86ccbaba07 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sun, 27 Dec 2015 01:46:55 +0100 Subject: GTK3 icon-canvas-item: port to GtkStyleContext taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=fc74332 --- libcaja-private/caja-icon-canvas-item.c | 90 +++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 16 deletions(-) diff --git a/libcaja-private/caja-icon-canvas-item.c b/libcaja-private/caja-icon-canvas-item.c index fe44b9b2..b48583ba 100644 --- a/libcaja-private/caja-icon-canvas-item.c +++ b/libcaja-private/caja-icon-canvas-item.c @@ -232,7 +232,11 @@ static void draw_label_layout (CajaIconCanvasItem #endif PangoLayout *layout, gboolean highlight, +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA *label_color, +#else GdkColor *label_color, +#endif int x, int y); static gboolean hit_test_stretch_handle (CajaIconCanvasItem *item, @@ -1039,10 +1043,11 @@ static void draw_frame (CajaIconCanvasItem *item, #if GTK_CHECK_VERSION(3,0,0) cairo_t *cr, + GdkRGBA *color, #else GdkDrawable *drawable, -#endif guint color, +#endif gboolean create_mask, int x, int y, @@ -1068,11 +1073,15 @@ draw_frame (CajaIconCanvasItem *item, */ } +#if GTK_CHECK_VERSION(3,0,0) + gdk_cairo_set_source_rgba (cr, color); +#else cairo_set_source_rgba (cr, EEL_RGBA_COLOR_GET_R (color) / 255.0, EEL_RGBA_COLOR_GET_G (color) / 255.0, EEL_RGBA_COLOR_GET_B (color) / 255.0, EEL_RGBA_COLOR_GET_A (color) / 255.0); +#endif /* Paint into drawable now that we have set up the color and opacity */ cairo_fill (cr); @@ -1395,7 +1404,11 @@ draw_label_text (CajaIconCanvasItem *item, CajaIconContainer *container; PangoLayout *editable_layout; PangoLayout *additional_layout; +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA label_color; +#else GdkColor *label_color; +#endif gboolean have_editable, have_additional; gboolean needs_frame, needs_highlight, prelight_label, is_rtl_label_beside; EelIRect text_rect; @@ -1439,10 +1452,11 @@ draw_label_text (CajaIconCanvasItem *item, draw_frame (item, #if GTK_CHECK_VERSION(3,0,0) cr, + gtk_widget_has_focus (GTK_WIDGET (container)) ? &container->details->highlight_color_rgba : &container->details->active_color_rgba, #else drawable, -#endif gtk_widget_has_focus (GTK_WIDGET (container)) ? container->details->highlight_color_rgba : container->details->active_color_rgba, +#endif create_mask, is_rtl_label_beside ? text_rect.x0 + item->details->text_dx : text_rect.x0, text_rect.y0, @@ -1498,10 +1512,11 @@ draw_label_text (CajaIconCanvasItem *item, draw_frame (item, #if GTK_CHECK_VERSION(3,0,0) cr, + &container->details->normal_color_rgba, #else drawable, -#endif container->details->normal_color_rgba, +#endif create_mask, text_rect.x0, text_rect.y0, @@ -1513,10 +1528,11 @@ draw_label_text (CajaIconCanvasItem *item, draw_frame (item, #if GTK_CHECK_VERSION(3,0,0) cr, + &container->details->prelight_color_rgba, #else drawable, -#endif container->details->prelight_color_rgba, +#endif create_mask, text_rect.x0, text_rect.y0, @@ -1533,11 +1549,13 @@ draw_label_text (CajaIconCanvasItem *item, draw_label_layout (item, #if GTK_CHECK_VERSION(3,0,0) cr, + editable_layout, needs_highlight, + &label_color, #else drawable, -#endif editable_layout, needs_highlight, label_color, +#endif x, text_rect.y0 + TEXT_BACK_PADDING_Y); } @@ -1555,29 +1573,30 @@ draw_label_text (CajaIconCanvasItem *item, draw_label_layout (item, #if GTK_CHECK_VERSION(3,0,0) cr, + additional_layout, needs_highlight, + &label_color, #else drawable, -#endif additional_layout, needs_highlight, label_color, +#endif x, text_rect.y0 + details->editable_text_height + LABEL_LINE_SPACING + TEXT_BACK_PADDING_Y); } if (!create_mask && item->details->is_highlighted_as_keyboard_focus) { - gtk_paint_focus (gtk_widget_get_style (GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas)), #if GTK_CHECK_VERSION(3,0,0) - cr, + gtk_render_focus (gtk_widget_get_style_context (GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas)), + cr, #else + gtk_paint_focus (gtk_widget_get_style (GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas)), drawable, -#endif needs_highlight ? GTK_STATE_SELECTED : GTK_STATE_NORMAL, -#if !GTK_CHECK_VERSION(3,0,0) NULL, -#endif GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas), "icon-container", +#endif text_rect.x0, text_rect.y0, text_rect.x1 - text_rect.x0, @@ -1667,6 +1686,10 @@ draw_stretch_handles (CajaIconCanvasItem *item, GdkPixbuf *knob_pixbuf; int knob_width, knob_height; double dash = { 2.0 }; +#if GTK_CHECK_VERSION(3,0,0) + GtkStyleContext *style; + GdkRGBA color; +#endif if (!item->details->show_stretch_handles) { @@ -1674,6 +1697,9 @@ draw_stretch_handles (CajaIconCanvasItem *item, } widget = GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas); +#if GTK_CHECK_VERSION(3,0,0) + style = gtk_widget_get_style_context (widget); +#endif #if GTK_CHECK_VERSION(3,0,0) cairo_save (cr); @@ -1685,7 +1711,12 @@ draw_stretch_handles (CajaIconCanvasItem *item, knob_height = gdk_pixbuf_get_height (knob_pixbuf); /* first draw the box */ +#if GTK_CHECK_VERSION(3,0,0) + gtk_style_context_get_color (style, GTK_STATE_FLAG_SELECTED, &color); + gdk_cairo_set_source_rgba (cr, &color); +#else cairo_set_source_rgb (cr, 0, 0, 0); +#endif cairo_set_dash (cr, &dash, 1, 0); cairo_set_line_width (cr, 1.0); cairo_rectangle (cr, @@ -1929,7 +1960,11 @@ real_map_pixbuf (CajaIconCanvasItem *icon_item) saturation, brightness, lighten, +#if GTK_CHECK_VERSION(3,0,0) + &container->details->prelight_icon_color_rgba); +#else container->details->prelight_icon_color_rgba); +#endif g_object_unref (old_pixbuf); } @@ -1983,6 +2018,17 @@ real_map_pixbuf (CajaIconCanvasItem *icon_item) if (icon_item->details->is_highlighted_for_selection || icon_item->details->is_highlighted_for_drop) { +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA *color; + + old_pixbuf = temp_pixbuf; + + color = gtk_widget_has_focus (GTK_WIDGET (canvas)) ? + &CAJA_ICON_CONTAINER (canvas)->details->highlight_color_rgba : + &CAJA_ICON_CONTAINER (canvas)->details->active_color_rgba; + + temp_pixbuf = eel_create_colorized_pixbuf (temp_pixbuf, color); +#else guint color; old_pixbuf = temp_pixbuf; @@ -1993,6 +2039,7 @@ real_map_pixbuf (CajaIconCanvasItem *icon_item) EEL_RGBA_COLOR_GET_R (color), EEL_RGBA_COLOR_GET_G (color), EEL_RGBA_COLOR_GET_B (color)); +#endif g_object_unref (old_pixbuf); } @@ -2018,7 +2065,11 @@ real_map_pixbuf (CajaIconCanvasItem *icon_item) saturation, brightness, lighten, +#if GTK_CHECK_VERSION(3,0,0) + &container->details->normal_icon_color_rgba); +#else container->details->normal_icon_color_rgba); +#endif g_object_unref (old_pixbuf); } } @@ -2324,16 +2375,21 @@ static void draw_label_layout (CajaIconCanvasItem *item, #if GTK_CHECK_VERSION(3,0,0) cairo_t *cr, + PangoLayout *layout, + gboolean highlight, + GdkRGBA *label_color, + int x, + int y) +{ + GdkRGBA black = { 0, 0, 0, 0 }; #else GdkDrawable *drawable, -#endif PangoLayout *layout, gboolean highlight, GdkColor *label_color, int x, int y) { -#if !GTK_CHECK_VERSION(3,0,0) g_return_if_fail (drawable != NULL); #endif @@ -2347,11 +2403,13 @@ draw_label_layout (CajaIconCanvasItem *item, /* draw a drop shadow */ #if GTK_CHECK_VERSION(3,0,0) eel_cairo_draw_layout_with_drop_shadow (cr, + label_color, + &black, #else eel_gdk_draw_layout_with_drop_shadow (drawable, -#endif label_color, >k_widget_get_style (GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas))->black, +#endif x, y, layout); } @@ -2359,11 +2417,11 @@ draw_label_layout (CajaIconCanvasItem *item, { #if GTK_CHECK_VERSION(3,0,0) cairo_save (cr); + gdk_cairo_set_source_rgba (cr, label_color); #else cairo_t *cr = gdk_cairo_create (drawable); -#endif - gdk_cairo_set_source_color (cr, label_color); +#endif cairo_move_to (cr, x, y); pango_cairo_show_layout (cr, layout); #if GTK_CHECK_VERSION(3,0,0) -- cgit v1.2.1 From 11fe5df21deec3181bbb72a577a26f7d2bb4d8b0 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Tue, 5 Jan 2016 19:56:52 +0100 Subject: GTK3 icon-container: port to GtkStyleContext taken from: https://git.gnome.org/browse/nautilus/commit/?id=4f23a0a --- libcaja-private/caja-icon-container.c | 234 +++++++++++++++++++++++++++++++++- libcaja-private/caja-icon-dnd.c | 4 +- libcaja-private/caja-icon-private.h | 16 +++ 3 files changed, 247 insertions(+), 7 deletions(-) diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c index 8e89ce62..04ca88bf 100644 --- a/libcaja-private/caja-icon-container.c +++ b/libcaja-private/caja-icon-container.c @@ -120,8 +120,13 @@ #define DEFAULT_HIGHLIGHT_ALPHA 0xff #define DEFAULT_NORMAL_ALPHA 0xff #define DEFAULT_PRELIGHT_ALPHA 0xff +#if GTK_CHECK_VERSION(3,0,0) +#define DEFAULT_LIGHT_INFO_COLOR "AAAAFD" +#define DEFAULT_DARK_INFO_COLOR "33337F" +#else #define DEFAULT_LIGHT_INFO_COLOR 0xAAAAFD #define DEFAULT_DARK_INFO_COLOR 0x33337F +#endif #define DEFAULT_NORMAL_ICON_RENDER_MODE 0 #define DEFAULT_PRELIGHT_ICON_RENDER_MODE 1 @@ -2878,12 +2883,19 @@ start_rubberbanding (CajaIconContainer *container, AtkObject *accessible; CajaIconContainerDetails *details; CajaIconRubberbandInfo *band_info; +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA *fill_color_gdk; + GList *p; + CajaIcon *icon; + GtkStyleContext *style; +#else guint fill_color, outline_color; GdkColor *fill_color_gdk; guchar fill_color_alpha; GList *p; CajaIcon *icon; GtkStyle *style; +#endif details = container->details; band_info = &details->rubberband_info; @@ -2901,6 +2913,38 @@ start_rubberbanding (CajaIconContainer *container, (EEL_CANVAS (container), event->x, event->y, &band_info->start_x, &band_info->start_y); +#if GTK_CHECK_VERSION(3,0,0) + style = gtk_widget_get_style_context (GTK_WIDGET (container)); + gtk_style_context_get_style (style, + "selection_box_rgba", &fill_color_gdk, + NULL); + + if (!fill_color_gdk) + { + fill_color_gdk = g_malloc0 (sizeof (GdkRGBA)); + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, + fill_color_gdk); + } + + if (fill_color_gdk->alpha == 1) { + fill_color_gdk->alpha = 0.25; + } + + band_info->selection_rectangle = eel_canvas_item_new + (eel_canvas_root + (EEL_CANVAS (container)), + EEL_TYPE_CANVAS_RECT, + "x1", band_info->start_x, + "y1", band_info->start_y, + "x2", band_info->start_x, + "y2", band_info->start_y, + "fill_color_rgba", fill_color_gdk, + "outline_color_rgba", fill_color_gdk, + "width_pixels", 1, + NULL); + + gdk_rgba_free (fill_color_gdk); +#else gtk_widget_style_get (GTK_WIDGET (container), "selection_box_color", &fill_color_gdk, "selection_box_alpha", &fill_color_alpha, @@ -2930,6 +2974,7 @@ start_rubberbanding (CajaIconContainer *container, "outline_color_rgba", outline_color, "width_pixels", 1, NULL); +#endif accessible = atk_gobject_accessible_for_object (G_OBJECT (band_info->selection_rectangle)); @@ -4603,9 +4648,15 @@ style_set (GtkWidget *widget, container = CAJA_ICON_CONTAINER (widget); +#if GTK_CHECK_VERSION(3,0,0) + gtk_style_context_get_style (gtk_widget_get_style_context (GTK_WIDGET (container)), + "frame_text", &frame_text, + NULL); +#else gtk_widget_style_get (GTK_WIDGET (container), "frame_text", &frame_text, NULL); +#endif container->details->use_drop_shadows = container->details->drop_shadows_requested && !frame_text; @@ -6587,6 +6638,25 @@ caja_icon_container_class_init (CajaIconContainerClass *class) G_PARAM_READABLE)); gtk_widget_class_install_style_property (widget_class, +#if GTK_CHECK_VERSION(3,0,0) + g_param_spec_boxed ("selection_box_rgba", + "Selection Box RGBA", + "Color of the selection box", + GDK_TYPE_RGBA, + G_PARAM_READABLE)); + + gtk_widget_class_install_style_property (widget_class, + g_param_spec_boxed ("light_info_rgba", + "Light Info RGBA", + "Color used for information text against a dark background", + GDK_TYPE_RGBA, + G_PARAM_READABLE)); + gtk_widget_class_install_style_property (widget_class, + g_param_spec_boxed ("dark_info_rgba", + "Dark Info RGBA", + "Color used for information text against a light background", + GDK_TYPE_RGBA, +#else g_param_spec_boxed ("selection_box_color", "Selection Box Color", "Color of the selection box", @@ -6632,6 +6702,7 @@ caja_icon_container_class_init (CajaIconContainerClass *class) "Dark Info Color", "Color used for information text against a light background", GDK_TYPE_COLOR, +#endif G_PARAM_READABLE)); gtk_widget_class_install_style_property (widget_class, @@ -6649,6 +6720,18 @@ caja_icon_container_class_init (CajaIconContainerClass *class) DEFAULT_PRELIGHT_ICON_RENDER_MODE, G_PARAM_READABLE)); gtk_widget_class_install_style_property (widget_class, +#if GTK_CHECK_VERSION(3,0,0) + g_param_spec_boxed ("normal_icon_rgba", + "Icon Normal RGBA", + "Color used for colorizing icons in normal state (default base[NORMAL])", + GDK_TYPE_RGBA, + G_PARAM_READABLE)); + gtk_widget_class_install_style_property (widget_class, + g_param_spec_boxed ("prelight_icon_rgba", + "Icon Prelight RGBA", + "Color used for colorizing prelighted icons (default base[PRELIGHT])", + GDK_TYPE_RGBA, +#else g_param_spec_boxed ("normal_icon_color", "Icon Normal Color", "Color used for colorizing icons in normal state (default base[NORMAL])", @@ -6659,6 +6742,7 @@ caja_icon_container_class_init (CajaIconContainerClass *class) "Icon Prelight Color", "Color used for colorizing prelighted icons (default base[PRELIGHT])", GDK_TYPE_COLOR, +#endif G_PARAM_READABLE)); gtk_widget_class_install_style_property (widget_class, g_param_spec_uint ("normal_icon_saturation", @@ -9296,10 +9380,14 @@ caja_icon_container_set_single_click_mode (CajaIconContainer *container, void caja_icon_container_get_label_color (CajaIconContainer *container, +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA *color, +#else GdkColor **color, - gboolean is_name, - gboolean is_highlight, - gboolean is_prelit) +#endif + gboolean is_name, + gboolean is_highlight, + gboolean is_prelit) { int idx; @@ -9349,14 +9437,24 @@ caja_icon_container_get_label_color (CajaIconContainer *container, if (color) { +#if GTK_CHECK_VERSION(3,0,0) + *color = container->details->label_colors[idx]; +#else *color = &container->details->label_colors [idx]; +#endif } } static void +#if GTK_CHECK_VERSION(3,0,0) +setup_gc_with_fg (CajaIconContainer *container, int idx, GdkRGBA *color) +{ + container->details->label_colors[idx] = *color; +#else setup_gc_with_fg (CajaIconContainer *container, int idx, guint32 color) { container->details->label_colors [idx] = eel_gdk_rgb_to_color (color); +#endif } static void @@ -9364,10 +9462,17 @@ setup_label_gcs (CajaIconContainer *container) { EelBackground *background; GtkWidget *widget; +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA *light_info_color, *dark_info_color; + gboolean frame_text; + GtkStyleContext *style; + GdkRGBA color; +#else GdkColor *light_info_color, *dark_info_color; guint light_info_value, dark_info_value; gboolean frame_text; GtkStyle *style; +#endif if (!gtk_widget_get_realized (GTK_WIDGET (container))) return; @@ -9379,6 +9484,83 @@ setup_label_gcs (CajaIconContainer *container) background = eel_get_widget_background (GTK_WIDGET (container)); /* read the info colors from the current theme; use a reasonable default if undefined */ +#if GTK_CHECK_VERSION(3,0,0) + style = gtk_widget_get_style_context (widget); + gtk_style_context_get_style (style, + "light_info_rgba", &light_info_color, + "dark_info_rgba", &dark_info_color, + NULL); + + if (!light_info_color) + { + light_info_color = g_malloc (sizeof (GdkRGBA)); + gdk_rgba_parse (light_info_color, DEFAULT_LIGHT_INFO_COLOR); + } + + if (!dark_info_color) + { + light_info_color = g_malloc (sizeof (GdkRGBA)); + gdk_rgba_parse (dark_info_color, DEFAULT_DARK_INFO_COLOR); + } + + gtk_style_context_get_color (style, GTK_STATE_FLAG_SELECTED, &color); + setup_gc_with_fg (container, LABEL_COLOR_HIGHLIGHT, &color); + + gtk_style_context_get_color (style, GTK_STATE_FLAG_ACTIVE, &color); + setup_gc_with_fg (container, LABEL_COLOR_ACTIVE, &color); + + gtk_style_context_get_color (style, GTK_STATE_FLAG_PRELIGHT, &color); + setup_gc_with_fg (container, LABEL_COLOR_PRELIGHT, &color); + + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, &color); + setup_gc_with_fg (container, + LABEL_INFO_COLOR_HIGHLIGHT, + eel_gdk_rgba_is_dark (&color) ? light_info_color : dark_info_color); + + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_ACTIVE, &color); + setup_gc_with_fg (container, + LABEL_INFO_COLOR_ACTIVE, + eel_gdk_rgba_is_dark (&color) ? light_info_color : dark_info_color); + + /* If CajaIconContainer::frame_text is set, we can safely + * use the foreground color from the theme, because it will + * always be displayed against the gtk background */ + gtk_style_context_get_style (gtk_widget_get_style_context (GTK_WIDGET (container)), + "frame_text", &frame_text, + NULL); + + if (frame_text /* || !eel_background_is_set(background) */) + { + gtk_style_context_get_color (style, GTK_STATE_FLAG_ACTIVE, &color); + setup_gc_with_fg (container, LABEL_COLOR, &color); + + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_ACTIVE, &color); + setup_gc_with_fg (container, LABEL_INFO_COLOR, + eel_gdk_rgba_is_dark (&color) ? + light_info_color : dark_info_color); + } + else + { + if (container->details->use_drop_shadows || eel_background_is_dark (background)) + { + GdkRGBA tmp; + + gdk_rgba_parse (&tmp, "EFEFEF"); + setup_gc_with_fg (container, LABEL_COLOR, &tmp); + setup_gc_with_fg (container, LABEL_INFO_COLOR, light_info_color); + } + else /* converse */ + { + GdkRGBA tmp; + + gdk_rgba_parse (&tmp, "000000"); + setup_gc_with_fg (container, LABEL_COLOR, &tmp); + setup_gc_with_fg (container, LABEL_INFO_COLOR, dark_info_color); + } + } + gdk_rgba_free (dark_info_color); + gdk_rgba_free (light_info_color); +#else gtk_widget_style_get (GTK_WIDGET (container), "light_info_color", &light_info_color, "dark_info_color", &dark_info_color, @@ -9448,6 +9630,7 @@ setup_label_gcs (CajaIconContainer *container) dark_info_value); } } +#endif } static void @@ -9520,7 +9703,11 @@ caja_icon_container_set_use_drop_shadows (CajaIconContainer *container, { gboolean frame_text; +#if GTK_CHECK_VERSION(3,0,0) + gtk_style_context_get_style (gtk_widget_get_style_context (GTK_WIDGET (container)), +#else gtk_widget_style_get (GTK_WIDGET (container), +#endif "frame_text", &frame_text, NULL); @@ -9540,6 +9727,45 @@ static void caja_icon_container_theme_changed (gpointer user_data) { CajaIconContainer *container; +#if GTK_CHECK_VERSION(3,0,0) + GtkStyleContext *style; + GdkRGBA *prelight_icon_color, *normal_icon_color, color; + + container = CAJA_ICON_CONTAINER (user_data); + style = gtk_widget_get_style_context (GTK_WIDGET (container)); + + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, &color); + container->details->highlight_color_rgba = color; + + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_ACTIVE, &color); + container->details->active_color_rgba = color; + + /* load the prelight icon color */ + gtk_style_context_get_style (style, + "prelight_icon_rgba", &prelight_icon_color, + NULL); + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_PRELIGHT, &color); + + if (!prelight_icon_color) { + prelight_icon_color = gdk_rgba_copy (&color); + } + + container->details->prelight_icon_color_rgba = *prelight_icon_color; + container->details->prelight_color_rgba = color; + + /* load the normal icon color */ + gtk_style_context_get_style (style, + "normal_icon_rgba", &normal_icon_color, + NULL); + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_ACTIVE, &color); + + if (!normal_icon_color) { + normal_icon_color = gdk_rgba_copy (&color); + } + + container->details->normal_icon_color_rgba = *normal_icon_color; + container->details->normal_color_rgba = color; +#else GtkStyle *style; GdkColor *prelight_icon_color, *normal_icon_color; guchar highlight_alpha, normal_alpha, prelight_alpha; @@ -9632,7 +9858,7 @@ caja_icon_container_theme_changed (gpointer user_data) style->base[GTK_STATE_PRELIGHT].green >> 8, style->base[GTK_STATE_PRELIGHT].blue >> 8, prelight_alpha); - +#endif setup_label_gcs (container); } diff --git a/libcaja-private/caja-icon-dnd.c b/libcaja-private/caja-icon-dnd.c index 38820aa9..0a1cac87 100644 --- a/libcaja-private/caja-icon-dnd.c +++ b/libcaja-private/caja-icon-dnd.c @@ -1628,10 +1628,8 @@ drag_highlight_expose (GtkWidget *widget, height = gdk_window_get_height (window); #if GTK_CHECK_VERSION (3, 0, 0) - gtk_paint_shadow (gtk_widget_get_style (widget), + gtk_render_frame (gtk_widget_get_style_context (widget), cr, - GTK_STATE_NORMAL, GTK_SHADOW_OUT, - widget, "dnd", 0, 0, width, height); #else gtk_paint_shadow (gtk_widget_get_style (widget), window, diff --git a/libcaja-private/caja-icon-private.h b/libcaja-private/caja-icon-private.h index cf7ef592..0c36188f 100644 --- a/libcaja-private/caja-icon-private.h +++ b/libcaja-private/caja-icon-private.h @@ -211,6 +211,17 @@ struct CajaIconContainerDetails int font_size_table[CAJA_ZOOM_LEVEL_LARGEST + 1]; /* pixbuf and color for label highlighting */ +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA highlight_color_rgba; + GdkRGBA active_color_rgba; + GdkRGBA normal_color_rgba; + GdkRGBA prelight_color_rgba; + GdkRGBA prelight_icon_color_rgba; + GdkRGBA normal_icon_color_rgba; + + /* colors for text labels */ + GdkRGBA label_colors [LAST_LABEL_COLOR]; +#else guint32 highlight_color_rgba; guint32 active_color_rgba; guint32 normal_color_rgba; @@ -220,6 +231,7 @@ struct CajaIconContainerDetails /* colors for text labels */ GdkColor label_colors [LAST_LABEL_COLOR]; +#endif /* State used so arrow keys don't wander if icons aren't lined up. */ @@ -327,7 +339,11 @@ void caja_icon_container_update_scroll_region (CajaIconContainer /* label color for items */ void caja_icon_container_get_label_color (CajaIconContainer *container, +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA *color, +#else GdkColor **color, +#endif gboolean first_line, gboolean needs_highlight, gboolean is_prelit); -- cgit v1.2.1 From 5425761290d94b208efea117e3b6a865e9157b92 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Wed, 6 Jan 2016 22:16:38 +0100 Subject: GTK3 icon-container: fix rendering of text on the desktop taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=2e5f7a23350016c67bb9e9cca86a9fb2360d79e2 --- libcaja-private/caja-icon-canvas-item.c | 2 +- libcaja-private/caja-icon-container.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libcaja-private/caja-icon-canvas-item.c b/libcaja-private/caja-icon-canvas-item.c index b48583ba..1249cba6 100644 --- a/libcaja-private/caja-icon-canvas-item.c +++ b/libcaja-private/caja-icon-canvas-item.c @@ -2381,7 +2381,7 @@ draw_label_layout (CajaIconCanvasItem *item, int x, int y) { - GdkRGBA black = { 0, 0, 0, 0 }; + GdkRGBA black = { 0, 0, 0, 1 }; #else GdkDrawable *drawable, PangoLayout *layout, diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c index 04ca88bf..4cf35d30 100644 --- a/libcaja-private/caja-icon-container.c +++ b/libcaja-private/caja-icon-container.c @@ -121,8 +121,8 @@ #define DEFAULT_NORMAL_ALPHA 0xff #define DEFAULT_PRELIGHT_ALPHA 0xff #if GTK_CHECK_VERSION(3,0,0) -#define DEFAULT_LIGHT_INFO_COLOR "AAAAFD" -#define DEFAULT_DARK_INFO_COLOR "33337F" +#define DEFAULT_LIGHT_INFO_COLOR "#AAAAFD" +#define DEFAULT_DARK_INFO_COLOR "#33337F" #else #define DEFAULT_LIGHT_INFO_COLOR 0xAAAAFD #define DEFAULT_DARK_INFO_COLOR 0x33337F @@ -9494,13 +9494,13 @@ setup_label_gcs (CajaIconContainer *container) if (!light_info_color) { light_info_color = g_malloc (sizeof (GdkRGBA)); - gdk_rgba_parse (light_info_color, DEFAULT_LIGHT_INFO_COLOR); + g_assert (gdk_rgba_parse (light_info_color, DEFAULT_LIGHT_INFO_COLOR)); } if (!dark_info_color) { - light_info_color = g_malloc (sizeof (GdkRGBA)); - gdk_rgba_parse (dark_info_color, DEFAULT_DARK_INFO_COLOR); + dark_info_color = g_malloc (sizeof (GdkRGBA)); + g_assert (gdk_rgba_parse (dark_info_color, DEFAULT_DARK_INFO_COLOR)); } gtk_style_context_get_color (style, GTK_STATE_FLAG_SELECTED, &color); @@ -9545,7 +9545,7 @@ setup_label_gcs (CajaIconContainer *container) { GdkRGBA tmp; - gdk_rgba_parse (&tmp, "EFEFEF"); + gdk_rgba_parse (&tmp, "#EFEFEF"); setup_gc_with_fg (container, LABEL_COLOR, &tmp); setup_gc_with_fg (container, LABEL_INFO_COLOR, light_info_color); } @@ -9553,7 +9553,7 @@ setup_label_gcs (CajaIconContainer *container) { GdkRGBA tmp; - gdk_rgba_parse (&tmp, "000000"); + gdk_rgba_parse (&tmp, "#000000"); setup_gc_with_fg (container, LABEL_COLOR, &tmp); setup_gc_with_fg (container, LABEL_INFO_COLOR, dark_info_color); } -- cgit v1.2.1 From 569a001e73f2963f239da92c433e62de2a030509 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Wed, 6 Jan 2016 21:49:08 +0100 Subject: Gtk3 caja-sidebartitle: partial-port-to-GtkStyleContext --- src/caja-sidebar-title.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/src/caja-sidebar-title.c b/src/caja-sidebar-title.c index baa9c5e0..ec8ef777 100644 --- a/src/caja-sidebar-title.c +++ b/src/caja-sidebar-title.c @@ -54,8 +54,13 @@ #define MIN_TITLE_FONT_SIZE 12 #define TITLE_PADDING 4 +#if GTK_CHECK_VERSION (3, 0, 0) +#define DEFAULT_LIGHT_INFO_COLOR "#FFFFFF" +#define DEFAULT_DARK_INFO_COLOR "#2A2A2A" +#else #define DEFAULT_LIGHT_INFO_COLOR 0xFFFFFF #define DEFAULT_DARK_INFO_COLOR 0x2A2A2A +#endif #if GTK_CHECK_VERSION (3, 0, 0) #define gtk_hbox_new(X,Y) gtk_box_new(GTK_ORIENTATION_HORIZONTAL,Y) @@ -97,7 +102,11 @@ struct CajaSidebarTitleDetails GtkWidget *more_info_label; GtkWidget *emblem_box; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA label_colors [LAST_LABEL_COLOR]; +#else GdkColor label_colors [LAST_LABEL_COLOR]; +#endif guint best_icon_size; gboolean determined_icon; }; @@ -113,6 +122,7 @@ style_set (GtkWidget *widget, PangoFontDescription *font_desc; GtkStyle *style; + g_return_if_fail (CAJA_IS_SIDEBAR_TITLE (widget)); sidebar_title = CAJA_SIDEBAR_TITLE (widget); @@ -223,16 +233,30 @@ caja_sidebar_title_class_init (CajaSidebarTitleClass *klass) widget_class->style_set = style_set; gtk_widget_class_install_style_property (widget_class, +#if GTK_CHECK_VERSION (3, 0, 0) + g_param_spec_boxed ("light_info_rgba", + "Light Info RGBA", + "Color used for information text against a dark background", + GDK_TYPE_RGBA, +#else g_param_spec_boxed ("light_info_color", "Light Info Color", "Color used for information text against a dark background", GDK_TYPE_COLOR, +#endif G_PARAM_READABLE)); gtk_widget_class_install_style_property (widget_class, +#if GTK_CHECK_VERSION (3, 0, 0) + g_param_spec_boxed ("dark_info_rgba", + "Dark Info RGBA", + "Color used for information text against a light background", + GDK_TYPE_RGBA, +#else g_param_spec_boxed ("dark_info_color", "Dark Info Color", "Color used for information text against a light background", GDK_TYPE_COLOR, +#endif G_PARAM_READABLE)); g_type_class_add_private (klass, sizeof (CajaSidebarTitleDetails)); @@ -246,23 +270,71 @@ caja_sidebar_title_new (void) } static void +#if GTK_CHECK_VERSION (3, 0, 0) +setup_gc_with_fg (CajaSidebarTitle *sidebar_title, int idx, GdkRGBA *color) +{ + sidebar_title->details->label_colors[idx] = *color; +#else setup_gc_with_fg (CajaSidebarTitle *sidebar_title, int idx, guint32 color) { sidebar_title->details->label_colors [idx] = eel_gdk_rgb_to_color (color); +#endif } void caja_sidebar_title_select_text_color (CajaSidebarTitle *sidebar_title, EelBackground *background) { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA *light_info_color, *dark_info_color; + GtkStyleContext *style; + GdkRGBA color; +#else GdkColor *light_info_color, *dark_info_color; guint light_info_value, dark_info_value; GtkStyle *style; +#endif g_assert (CAJA_IS_SIDEBAR_TITLE (sidebar_title)); g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (sidebar_title))); /* read the info colors from the current theme; use a reasonable default if undefined */ +#if GTK_CHECK_VERSION (3, 0, 0) + style = gtk_widget_get_style_context (GTK_WIDGET (sidebar_title)); + gtk_style_context_get_style (style, + "light_info_color", &light_info_color, + "dark_info_color", &dark_info_color, + NULL); + + if (!light_info_color) + { + light_info_color = g_malloc (sizeof (GdkRGBA)); + gdk_rgba_parse (light_info_color, DEFAULT_LIGHT_INFO_COLOR); + } + + if (!dark_info_color) + { + light_info_color = g_malloc (sizeof (GdkRGBA)); + gdk_rgba_parse (dark_info_color, DEFAULT_DARK_INFO_COLOR); + } + + gtk_style_context_get_color (style, GTK_STATE_FLAG_SELECTED, &color); + setup_gc_with_fg (sidebar_title, LABEL_COLOR_HIGHLIGHT, &color); + + gtk_style_context_get_color (style, GTK_STATE_FLAG_ACTIVE, &color); + setup_gc_with_fg (sidebar_title, LABEL_COLOR_ACTIVE, &color); + + gtk_style_context_get_color (style, GTK_STATE_FLAG_PRELIGHT, &color); + setup_gc_with_fg (sidebar_title, LABEL_COLOR_PRELIGHT, &color); + + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, &color); + setup_gc_with_fg (sidebar_title, LABEL_INFO_COLOR_HIGHLIGHT, + eel_gdk_rgba_is_dark (&color) ? light_info_color : dark_info_color); + + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_ACTIVE, &color); + setup_gc_with_fg (sidebar_title, LABEL_INFO_COLOR_ACTIVE, + eel_gdk_rgba_is_dark (&color) ? light_info_color : dark_info_color); +#else gtk_widget_style_get (GTK_WIDGET (sidebar_title), "light_info_color", &light_info_color, "dark_info_color", &dark_info_color, @@ -289,7 +361,6 @@ caja_sidebar_title_select_text_color (CajaSidebarTitle *sidebar_title, dark_info_value = DEFAULT_DARK_INFO_COLOR; } - setup_gc_with_fg (sidebar_title, LABEL_COLOR_HIGHLIGHT, eel_gdk_color_to_rgb (&style->text[GTK_STATE_SELECTED])); setup_gc_with_fg (sidebar_title, LABEL_COLOR_ACTIVE, @@ -300,11 +371,42 @@ caja_sidebar_title_select_text_color (CajaSidebarTitle *sidebar_title, eel_gdk_color_is_dark (&style->base[GTK_STATE_SELECTED]) ? light_info_value : dark_info_value); setup_gc_with_fg (sidebar_title, LABEL_INFO_COLOR_ACTIVE, eel_gdk_color_is_dark (&style->base[GTK_STATE_ACTIVE]) ? light_info_value : dark_info_value); +#endif /* If EelBackground is not set in the widget, we can safely * use the foreground color from the theme, because it will * always be displayed against the gtk background */ if (!eel_background_is_set(background)) +#if GTK_CHECK_VERSION (3, 0, 0) + { + gtk_style_context_get_color (style, GTK_STATE_FLAG_NORMAL, &color); + setup_gc_with_fg (sidebar_title, LABEL_COLOR, &color); + + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_NORMAL, &color); + setup_gc_with_fg (sidebar_title, LABEL_INFO_COLOR, + eel_gdk_rgba_is_dark (&color) ? + light_info_color : dark_info_color); + } + else if (eel_background_is_dark (background)) + { + GdkRGBA tmp; + + gdk_rgba_parse (&tmp, "EFEFEF"); + setup_gc_with_fg (sidebar_title, LABEL_COLOR, &tmp); + setup_gc_with_fg (sidebar_title, LABEL_INFO_COLOR, light_info_color); + } + else /* converse */ + { + GdkRGBA tmp; + + gdk_rgba_parse (&tmp, "000000"); + setup_gc_with_fg (sidebar_title, LABEL_COLOR, &tmp); + setup_gc_with_fg (sidebar_title, LABEL_INFO_COLOR, dark_info_color); + } + + gdk_rgba_free (dark_info_color); + gdk_rgba_free (light_info_color); +#else { setup_gc_with_fg (sidebar_title, LABEL_COLOR, eel_gdk_color_to_rgb (&style->text[GTK_STATE_NORMAL])); @@ -321,6 +423,7 @@ caja_sidebar_title_select_text_color (CajaSidebarTitle *sidebar_title, setup_gc_with_fg (sidebar_title, LABEL_COLOR, 0x000000); setup_gc_with_fg (sidebar_title, LABEL_INFO_COLOR, dark_info_value); } +#endif } static char* -- cgit v1.2.1 From d74c80ebae7d2acd4804ac1d20f6d77b1df53a2a Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Mon, 4 Jan 2016 22:11:54 +0100 Subject: Gtk3 tree-view-drag-dest: port to GtkStyleContext taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=f8bdf9c --- libcaja-private/caja-tree-view-drag-dest.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libcaja-private/caja-tree-view-drag-dest.c b/libcaja-private/caja-tree-view-drag-dest.c index 22a5cc51..2d76a1c1 100644 --- a/libcaja-private/caja-tree-view-drag-dest.c +++ b/libcaja-private/caja-tree-view-drag-dest.c @@ -206,18 +206,19 @@ highlight_expose (GtkWidget *widget, width = gdk_window_get_width(bin_window); height = gdk_window_get_height(bin_window); - gtk_paint_focus (gtk_widget_get_style (widget), #if GTK_CHECK_VERSION(3,0,0) - cr, - gtk_widget_get_state (widget), + gtk_render_focus (gtk_widget_get_style_context (widget), + cr, + 0, 0, width, height); #else + gtk_paint_focus (gtk_widget_get_style (widget), bin_window, gtk_widget_get_state (widget), NULL, -#endif widget, "treeview-drop-indicator", 0, 0, width, height); +#endif return FALSE; } -- cgit v1.2.1 From 3758b1025d59bd534717bd78d0e87dba9d45e542 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Thu, 7 Jan 2016 04:37:43 +0100 Subject: GTK3 list-view: port to GtkStyleContext --- src/file-manager/fm-list-view.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/file-manager/fm-list-view.c b/src/file-manager/fm-list-view.c index dc9bc20b..56ff9b17 100644 --- a/src/file-manager/fm-list-view.c +++ b/src/file-manager/fm-list-view.c @@ -3262,20 +3262,35 @@ real_set_is_active (FMDirectoryView *view, gboolean is_active) { GtkWidget *tree_view; +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStyleContext *style; + GdkRGBA color; +#else GtkStyle *style; GdkColor color; +#endif tree_view = GTK_WIDGET (fm_list_view_get_tree_view (FM_LIST_VIEW (view))); if (is_active) { +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_override_background_color (tree_view, GTK_STATE_FLAG_NORMAL, NULL); +#else gtk_widget_modify_base (tree_view, GTK_STATE_NORMAL, NULL); +#endif } else { +#if GTK_CHECK_VERSION (3, 0, 0) + style = gtk_widget_get_style_context (tree_view); + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_INSENSITIVE, &color); + gtk_widget_override_background_color (tree_view, GTK_STATE_FLAG_NORMAL, &color); +#else style = gtk_widget_get_style (tree_view); color = style->base[GTK_STATE_INSENSITIVE]; gtk_widget_modify_base (tree_view, GTK_STATE_NORMAL, &color); +#endif } EEL_CALL_PARENT (FM_DIRECTORY_VIEW_CLASS, -- cgit v1.2.1 From 2139cadd1b2143797287afd200dc4b6a6d687aee Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Thu, 7 Jan 2016 04:49:57 +0100 Subject: GTK3 properties-window: port to GtkStyleContext taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=8e5689 --- src/file-manager/fm-properties-window.c | 84 +++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 4 deletions(-) diff --git a/src/file-manager/fm-properties-window.c b/src/file-manager/fm-properties-window.c index 42b30a9a..87b75a6d 100644 --- a/src/file-manager/fm-properties-window.c +++ b/src/file-manager/fm-properties-window.c @@ -68,6 +68,15 @@ #include #endif +#if GTK_CHECK_VERSION (3, 0, 0) +#define USED_FILL_R 0.988235294 +#define USED_FILL_G 0.91372549 +#define USED_FILL_B 0.309803922 + +#define FREE_FILL_R 0.447058824 +#define FREE_FILL_G 0.623529412 +#define FREE_FILL_B 0.811764706 +#else #define USED_FILL_R (0.988235294 * 65535) #define USED_FILL_G (0.91372549 * 65535) #define USED_FILL_B (0.309803922 * 65535) @@ -75,6 +84,7 @@ #define FREE_FILL_R (0.447058824 * 65535) #define FREE_FILL_G (0.623529412 * 65535) #define FREE_FILL_B (0.811764706 * 65535) +#endif #define PREVIEW_IMAGE_WIDTH 96 @@ -148,10 +158,17 @@ struct FMPropertiesWindowDetails { guint64 volume_capacity; guint64 volume_free; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA used_color; + GdkRGBA free_color; + GdkRGBA used_stroke_color; + GdkRGBA free_stroke_color; +#else GdkColor used_color; GdkColor free_color; GdkColor used_stroke_color; GdkColor free_stroke_color; +#endif }; #if GTK_CHECK_VERSION (3, 0, 0) @@ -3045,6 +3062,13 @@ paint_used_legend (GtkWidget *widget, width - 4, height - 4); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &window->details->used_color); + cairo_fill_preserve (cr); + + gdk_cairo_set_source_rgba (cr, &window->details->used_stroke_color); + cairo_stroke (cr); +#else cairo_set_source_rgb (cr, (double) window->details->used_color.red / 65535, (double) window->details->used_color.green / 65535, @@ -3057,7 +3081,6 @@ paint_used_legend (GtkWidget *widget, (double) window->details->used_stroke_color.blue / 65535); cairo_stroke (cr); -#if !GTK_CHECK_VERSION(3,0,0) cairo_destroy (cr); #endif } @@ -3089,6 +3112,13 @@ paint_free_legend (GtkWidget *widget, width - 4, height - 4); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &window->details->free_color); + cairo_fill_preserve(cr); + + gdk_cairo_set_source_rgba (cr, &window->details->free_stroke_color); + cairo_stroke (cr); +#else cairo_set_source_rgb (cr, (double) window->details->free_color.red / 65535, (double) window->details->free_color.green / 65535, @@ -3101,7 +3131,6 @@ paint_free_legend (GtkWidget *widget, (double) window->details->free_stroke_color.blue / 65535); cairo_stroke (cr); -#if !GTK_CHECK_VERSION(3,0,0) cairo_destroy (cr); #endif } @@ -3167,6 +3196,12 @@ paint_pie_chart (GtkWidget *widget, cairo_line_to (cr,xc,yc); } +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &window->details->used_color); + cairo_fill_preserve (cr); + + gdk_cairo_set_source_rgba (cr, &window->details->used_stroke_color); +#else cairo_set_source_rgb (cr, (double) window->details->used_color.red / 65535, (double) window->details->used_color.green / 65535, @@ -3177,6 +3212,7 @@ paint_pie_chart (GtkWidget *widget, (double) window->details->used_stroke_color.red / 65535, (double) window->details->used_stroke_color.green / 65535, (double) window->details->used_stroke_color.blue / 65535); +#endif cairo_stroke (cr); } @@ -3191,6 +3227,12 @@ paint_pie_chart (GtkWidget *widget, cairo_line_to (cr,xc,yc); } +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &window->details->free_color); + cairo_fill_preserve(cr); + + gdk_cairo_set_source_rgba (cr, &window->details->free_stroke_color); +#else cairo_set_source_rgb (cr, (double) window->details->free_color.red / 65535, (double) window->details->free_color.green / 65535, @@ -3201,6 +3243,7 @@ paint_pie_chart (GtkWidget *widget, (double) window->details->free_stroke_color.red / 65535, (double) window->details->free_stroke_color.green / 65535, (double) window->details->free_stroke_color.blue / 65535); +#endif cairo_stroke (cr); } @@ -3362,17 +3405,28 @@ hls_to_rgb (gdouble *h, } } static void +#if GTK_CHECK_VERSION (3, 0, 0) +_pie_style_shade (GdkRGBA *a, + GdkRGBA *b, +#else _pie_style_shade (GdkColor *a, GdkColor *b, +#endif gdouble k) { gdouble red; gdouble green; gdouble blue; +#if GTK_CHECK_VERSION (3, 0, 0) + red = a->red; + green = a->green; + blue = a->blue; +#else red = (gdouble) a->red / 65535.0; green = (gdouble) a->green / 65535.0; blue = (gdouble) a->blue / 65535.0; +#endif rgb_to_hls (&red, &green, &blue); @@ -3390,9 +3444,16 @@ _pie_style_shade (GdkColor *a, hls_to_rgb (&red, &green, &blue); +#if GTK_CHECK_VERSION (3, 0, 0) + b->red = red; + b->green = green; + b->blue = blue; + b->alpha = a->alpha; +#else b->red = red * 65535.0; b->green = green * 65535.0; b->blue = blue * 65535.0; +#endif } @@ -3402,10 +3463,11 @@ create_pie_widget (FMPropertiesWindow *window) CajaFile *file; #if GTK_CHECK_VERSION (3, 0, 0) GtkGrid *grid; + GtkStyleContext *style; #else GtkTable *table; -#endif GtkStyle *style; +#endif GtkWidget *pie_canvas; GtkWidget *used_canvas; GtkWidget *used_label; @@ -3441,22 +3503,34 @@ create_pie_widget (FMPropertiesWindow *window) gtk_container_set_border_width (GTK_CONTAINER (grid), 5); gtk_grid_set_column_spacing (GTK_GRID (grid), 5); style = gtk_widget_get_style_context (GTK_WIDGET (grid)); + + if (!gtk_style_context_lookup_color (style, "chart_rgba_1", &window->details->used_color)) { #else table = GTK_TABLE (gtk_table_new (4, 3, FALSE)); style = gtk_rc_get_style (GTK_WIDGET(table)); -#endif if (!gtk_style_lookup_color (style, "chart_color_1", &window->details->used_color)) { +#endif window->details->used_color.red = USED_FILL_R; window->details->used_color.green = USED_FILL_G; window->details->used_color.blue = USED_FILL_B; +#if GTK_CHECK_VERSION (3, 0, 0) + window->details->used_color.alpha = 1; +#endif } +#if GTK_CHECK_VERSION (3, 0, 0) + if (!gtk_style_context_lookup_color (style, "chart_rgba_2", &window->details->free_color)) { +#else if (!gtk_style_lookup_color (style, "chart_color_2", &window->details->free_color)) { +#endif window->details->free_color.red = FREE_FILL_R; window->details->free_color.green = FREE_FILL_G; window->details->free_color.blue = FREE_FILL_B; +#if GTK_CHECK_VERSION (3, 0, 0) + window->details->free_color.alpha = 1; +#endif } _pie_style_shade (&window->details->used_color, &window->details->used_stroke_color, 0.7); @@ -6152,7 +6226,9 @@ create_properties_window (StartupData *startup_data) NULL); /* FIXME - HIGificiation, should be done inside GTK+ */ +#if !GTK_CHECK_VERSION (3, 0, 0) gtk_widget_ensure_style (GTK_WIDGET (window)); +#endif gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (window))), 12); gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (window))), 0); gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (window))), 12); -- cgit v1.2.1 From 39ce5849c81c688c53245316584489db5bc354ab Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Thu, 7 Jan 2016 04:53:29 +0100 Subject: GTK3 location-bar: port to GtkStyleContext taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=5fc40ad --- src/caja-location-bar.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/caja-location-bar.c b/src/caja-location-bar.c index 965da186..e2a70104 100644 --- a/src/caja-location-bar.c +++ b/src/caja-location-bar.c @@ -614,6 +614,21 @@ caja_location_bar_update_label (CajaLocationBar *bar) void caja_location_bar_set_active(CajaLocationBar *location_bar, gboolean is_active) { +#if GTK_CHECK_VERSION (3, 0, 0) + if (is_active) + { + /* reset style to default */ + gtk_widget_override_background_color (GTK_WIDGET (location_bar->details->entry), GTK_STATE_FLAG_NORMAL, NULL); + } + else + { + GtkStyleContext *style; + GdkRGBA color; + + style = gtk_widget_get_style_context (GTK_WIDGET (location_bar->details->entry)); + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_INSENSITIVE, &color); + gtk_widget_override_background_color (GTK_WIDGET (location_bar->details->entry), GTK_STATE_FLAG_ACTIVE, &color); +#else if(is_active) { /* reset style to default */ @@ -626,6 +641,7 @@ caja_location_bar_set_active(CajaLocationBar *location_bar, gboolean is_active) style = gtk_widget_get_style (GTK_WIDGET (location_bar->details->entry)); color = style->base[GTK_STATE_INSENSITIVE]; gtk_widget_modify_base(GTK_WIDGET (location_bar->details->entry), GTK_STATE_NORMAL, &color); +#endif } } -- cgit v1.2.1 From 5a7203f46bcccc29271058d1f03ed149d6c2860b Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Thu, 7 Jan 2016 04:55:59 +0100 Subject: GTK3 notebook: port to GtkStyleContext taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=bc5d290 --- src/caja-notebook.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/caja-notebook.c b/src/caja-notebook.c index b5b6420e..035ef769 100644 --- a/src/caja-notebook.c +++ b/src/caja-notebook.c @@ -82,6 +82,7 @@ caja_notebook_class_init (CajaNotebookClass *klass) notebook_class->insert_page = caja_notebook_insert_page; +#if !GTK_CHECK_VERSION (3, 0, 0) gtk_rc_parse_string ("style \"caja-tab-close-button-style\"\n" "{\n" "GtkWidget::focus-padding = 0\n" @@ -90,6 +91,7 @@ caja_notebook_class_init (CajaNotebookClass *klass) "ythickness = 0\n" "}\n" "widget \"*.caja-tab-close-button\" style \"caja-tab-close-button-style\""); +#endif signals[TAB_CLOSE_REQUEST] = g_signal_new ("tab-close-request", @@ -239,6 +241,31 @@ button_press_cb (CajaNotebook *notebook, static void caja_notebook_init (CajaNotebook *notebook) { +#if GTK_CHECK_VERSION (3, 0, 0) + static const gchar css_custom[] = + "#caja-tab-close-button {" + " -GtkWidget-focus-padding : 0;" + " -GtkWidget-focus-line-width: 0;" + " xthickness: 0;" + " ythickness: 0;" + "}"; + + GError *error = NULL; + GtkCssProvider *provider = gtk_css_provider_new (); + gtk_css_provider_load_from_data (provider, css_custom, -1, &error); + + if (error != NULL) { + g_warning ("Can't parse CajaNotebook's CSS custom description: %s\n", error->message); + g_error_free (error); + } else { + gtk_style_context_add_provider (gtk_widget_get_style_context (GTK_WIDGET (notebook)), + GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + } + + g_object_unref (provider); +#endif + gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE); gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE); gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE); -- cgit v1.2.1 From 20dd53f7822de644ca60cc200f5286a90d3b28b3 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Thu, 7 Jan 2016 04:57:44 +0100 Subject: GTK3 spatial-window: port to GtkStyleContext taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=507b56e3a527e28117b259dbf0dce48f1656dd7d --- src/caja-spatial-window.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/caja-spatial-window.c b/src/caja-spatial-window.c index 4dfe9bfb..05082358 100644 --- a/src/caja-spatial-window.c +++ b/src/caja-spatial-window.c @@ -989,7 +989,9 @@ static const char* icon_entries[] = static void caja_spatial_window_init (CajaSpatialWindow *window) { +#if !GTK_CHECK_VERSION (3, 0, 0) GtkRcStyle *rc_style; +#endif GtkWidget *arrow; GtkWidget *hbox, *vbox; GtkActionGroup *action_group; @@ -1035,11 +1037,13 @@ caja_spatial_window_init (CajaSpatialWindow *window) window); gtk_button_set_relief (GTK_BUTTON (window->details->location_button), GTK_RELIEF_NORMAL); +#if !GTK_CHECK_VERSION (3, 0, 0) rc_style = gtk_widget_get_modifier_style (window->details->location_button); rc_style->xthickness = 0; rc_style->ythickness = 0; gtk_widget_modify_style (window->details->location_button, rc_style); +#endif gtk_widget_show (window->details->location_button); hbox = gtk_hbox_new (FALSE, 3); -- cgit v1.2.1 From da1e7f715a4eb882abe97837eef02c7d38bd5e54 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Thu, 7 Jan 2016 05:03:27 +0100 Subject: GTK3 window: port to GtkStyleContext taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=076886e --- src/caja-window.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/caja-window.c b/src/caja-window.c index c460ae98..6188a2bd 100644 --- a/src/caja-window.c +++ b/src/caja-window.c @@ -141,6 +141,28 @@ caja_window_init (CajaWindow *window) GtkWidget *menu; GtkWidget *statusbar; +#if GTK_CHECK_VERSION (3, 0, 0) + static const gchar css_custom[] = + "#statusbar-no-border {" + " -GtkStatusbar-shadow-type: none;" + "}" + "#caja-extra-view-widget {" + " background-color: " EXTRA_VIEW_WIDGETS_BACKGROUND ";" + "}"; + + GError *error = NULL; + GtkCssProvider *provider = gtk_css_provider_new (); + gtk_css_provider_load_from_data (provider, css_custom, -1, &error); + + if (error != NULL) { + g_warning ("Can't parse CajaWindow's CSS custom description: %s\n", error->message); + g_error_free (error); + } else { + gtk_style_context_add_provider (gtk_widget_get_style_context (GTK_WIDGET (window)), + GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + } +#endif window->details = G_TYPE_INSTANCE_GET_PRIVATE (window, CAJA_TYPE_WINDOW, CajaWindowDetails); window->details->panes = NULL; @@ -148,6 +170,7 @@ caja_window_init (CajaWindow *window) window->details->show_hidden_files_mode = CAJA_WINDOW_SHOW_HIDDEN_FILES_DEFAULT; +#if !GTK_CHECK_VERSION (3, 0, 0) /* Remove Top border on GtkStatusBar */ gtk_rc_parse_string ( "style \"statusbar-no-border\"\n" @@ -155,6 +178,7 @@ caja_window_init (CajaWindow *window) " GtkStatusbar::shadow_type = GTK_SHADOW_NONE\n" "}\n" "widget \"*.statusbar-noborder\" style \"statusbar-no-border\""); +#endif /* Set initial window title */ gtk_window_set_title (GTK_WINDOW (window), _("Caja")); @@ -2238,6 +2262,7 @@ caja_window_class_init (CajaWindowClass *class) class->reload = caja_window_reload; class->go_up = caja_window_go_up_signal; +#if !GTK_CHECK_VERSION (3,0,0) /* Allow to set the colors of the extra view widgets */ gtk_rc_parse_string ("\n" " style \"caja-extra-view-widgets-style-internal\"\n" @@ -2247,6 +2272,7 @@ caja_window_class_init (CajaWindowClass *class) "\n" " widget \"*.caja-extra-view-widget\" style:rc \"caja-extra-view-widgets-style-internal\" \n" "\n"); +#endif g_type_class_add_private (G_OBJECT_CLASS (class), sizeof (CajaWindowDetails)); } -- 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(-) 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(-) 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 95c80f76e565ed3943008593254b527550d2e1e0 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Thu, 7 Jan 2016 23:32:07 +0100 Subject: GTK3 window: port to GtkStyleContext, plug a leak taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=465f576 --- src/caja-window.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/caja-window.c b/src/caja-window.c index 6188a2bd..6a1cb402 100644 --- a/src/caja-window.c +++ b/src/caja-window.c @@ -162,6 +162,8 @@ caja_window_init (CajaWindow *window) GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } + + g_object_unref (provider); #endif window->details = G_TYPE_INSTANCE_GET_PRIVATE (window, CAJA_TYPE_WINDOW, CajaWindowDetails); -- 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(-) 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 34031cbce020b242d523258e06565c6a00c54e5d Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Thu, 7 Jan 2016 23:42:36 +0100 Subject: GTK3 icon-info: plug a leak taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=705d814 --- libcaja-private/caja-icon-info.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libcaja-private/caja-icon-info.c b/libcaja-private/caja-icon-info.c index 3a63bb44..d5bd542e 100644 --- a/libcaja-private/caja-icon-info.c +++ b/libcaja-private/caja-icon-info.c @@ -472,7 +472,13 @@ caja_icon_info_lookup (GIcon *icon, pixbuf = NULL; } - return caja_icon_info_new_for_pixbuf (pixbuf); + icon_info = caja_icon_info_new_for_pixbuf (pixbuf); + + if (pixbuf != NULL) { + g_object_unref (pixbuf); + } + + return icon_info; } } -- 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(-) 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 01e61137a215658271f8b727ba56b8b2272fe1b2 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Thu, 7 Jan 2016 23:53:55 +0100 Subject: GTK3 icon-canvas-item: set the right style class taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=0668960 --- libcaja-private/caja-icon-canvas-item.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libcaja-private/caja-icon-canvas-item.c b/libcaja-private/caja-icon-canvas-item.c index 1249cba6..476b8839 100644 --- a/libcaja-private/caja-icon-canvas-item.c +++ b/libcaja-private/caja-icon-canvas-item.c @@ -1587,7 +1587,17 @@ draw_label_text (CajaIconCanvasItem *item, if (!create_mask && item->details->is_highlighted_as_keyboard_focus) { #if GTK_CHECK_VERSION(3,0,0) - gtk_render_focus (gtk_widget_get_style_context (GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas)), + GtkStyleContext *style; + + style = gtk_widget_get_style_context (GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas)); + + gtk_style_context_save (style); + gtk_style_context_add_class (style, "icon-container"); + gtk_style_context_set_state (style, + needs_highlight ? + GTK_STATE_FLAG_SELECTED : GTK_STATE_FLAG_ACTIVE); + + gtk_render_focus (style, cr, #else gtk_paint_focus (gtk_widget_get_style (GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas)), @@ -1601,6 +1611,10 @@ draw_label_text (CajaIconCanvasItem *item, text_rect.y0, text_rect.x1 - text_rect.x0, text_rect.y1 - text_rect.y0); +#if GTK_CHECK_VERSION(3,0,0) + + gtk_style_context_restore (style); +#endif } if (editable_layout != NULL) -- cgit v1.2.1 From 85faafb667ca2ab548347814595ac9b305c024b8 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Fri, 8 Jan 2016 00:11:42 +0100 Subject: Gtk3 tree-drag-dest: set the right style class taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=18e3369 --- libcaja-private/caja-tree-view-drag-dest.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libcaja-private/caja-tree-view-drag-dest.c b/libcaja-private/caja-tree-view-drag-dest.c index 2d76a1c1..accf7bb5 100644 --- a/libcaja-private/caja-tree-view-drag-dest.c +++ b/libcaja-private/caja-tree-view-drag-dest.c @@ -199,6 +199,9 @@ highlight_expose (GtkWidget *widget, GdkWindow *bin_window; int width; int height; +#if GTK_CHECK_VERSION(3,0,0) + GtkStyleContext *style; +#endif /* FIXMEchpe: is bin window right here??? */ bin_window = gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget)); @@ -207,9 +210,16 @@ highlight_expose (GtkWidget *widget, height = gdk_window_get_height(bin_window); #if GTK_CHECK_VERSION(3,0,0) - gtk_render_focus (gtk_widget_get_style_context (widget), + style = gtk_widget_get_style_context (widget); + + gtk_style_context_save (style); + gtk_style_context_add_class (style, "treeview-drop-indicator"); + + gtk_render_focus (style, cr, 0, 0, width, height); + + gtk_style_context_restore (style); #else gtk_paint_focus (gtk_widget_get_style (widget), bin_window, -- cgit v1.2.1 From c0e9c136368c537209932431774edef5bb6b8982 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Fri, 8 Jan 2016 00:22:27 +0100 Subject: GTK3 icon-dnd: set the right style class, and use GdkRGBA taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=5d811bb --- libcaja-private/caja-icon-dnd.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/libcaja-private/caja-icon-dnd.c b/libcaja-private/caja-icon-dnd.c index 0a1cac87..82707150 100644 --- a/libcaja-private/caja-icon-dnd.c +++ b/libcaja-private/caja-icon-dnd.c @@ -144,6 +144,9 @@ create_selection_shadow (CajaIconContainer *container, { CajaDragSelectionItem *item; int x1, y1, x2, y2; +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA black = { 0, 0, 0, 1 }; +#endif item = p->data; @@ -165,7 +168,11 @@ create_selection_shadow (CajaIconContainer *container, "y1", (double) y1, "x2", (double) x2, "y2", (double) y2, - "outline_color", "black", +#if GTK_CHECK_VERSION(3,0,0) + "outline-color-rgba", &black, +#else + "outline_color", "black", +#endif "outline-stippling", TRUE, "width_pixels", 1, NULL); @@ -1613,10 +1620,12 @@ drag_highlight_expose (GtkWidget *widget, { #if GTK_CHECK_VERSION(3,0,0) gint width, height; + GdkWindow *window; + GtkStyleContext *style; #else gint x, y, width, height; -#endif GdkWindow *window; +#endif #if !GTK_CHECK_VERSION(3,0,0) x = gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (widget))); @@ -1628,9 +1637,17 @@ drag_highlight_expose (GtkWidget *widget, height = gdk_window_get_height (window); #if GTK_CHECK_VERSION (3, 0, 0) - gtk_render_frame (gtk_widget_get_style_context (widget), + style = gtk_widget_get_style_context (widget); + + gtk_style_context_save (style); + gtk_style_context_add_class (style, "dnd"); + gtk_style_context_set_state (style, GTK_STATE_FLAG_FOCUSED); + + gtk_render_frame (style, cr, 0, 0, width, height); + + gtk_style_context_restore (style); #else gtk_paint_shadow (gtk_widget_get_style (widget), window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, -- cgit v1.2.1 From 6a19cea2b87a4977a70b1bd6e14edb09a5ebde62 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Fri, 8 Jan 2016 00:34:11 +0100 Subject: GTK3 icon-container: don't malloc() GdkRGBA colors manually As GdkRGBA might or might not use internally a different allocator, like g_slice. This should fix some memory corruption issues, thanks to Alban Browaeys for tracking down the bug. taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=4c026bf --- libcaja-private/caja-icon-container.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c index 4cf35d30..645e76ba 100644 --- a/libcaja-private/caja-icon-container.c +++ b/libcaja-private/caja-icon-container.c @@ -2884,7 +2884,7 @@ start_rubberbanding (CajaIconContainer *container, CajaIconContainerDetails *details; CajaIconRubberbandInfo *band_info; #if GTK_CHECK_VERSION(3,0,0) - GdkRGBA *fill_color_gdk; + GdkRGBA *fill_color_gdk, color; GList *p; CajaIcon *icon; GtkStyleContext *style; @@ -2921,9 +2921,9 @@ start_rubberbanding (CajaIconContainer *container, if (!fill_color_gdk) { - fill_color_gdk = g_malloc0 (sizeof (GdkRGBA)); gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, - fill_color_gdk); + &color); + fill_color_gdk = gdk_rgba_copy (&color); } if (fill_color_gdk->alpha == 1) { @@ -9493,14 +9493,14 @@ setup_label_gcs (CajaIconContainer *container) if (!light_info_color) { - light_info_color = g_malloc (sizeof (GdkRGBA)); - g_assert (gdk_rgba_parse (light_info_color, DEFAULT_LIGHT_INFO_COLOR)); + gdk_rgba_parse (&color, DEFAULT_LIGHT_INFO_COLOR); + light_info_color = gdk_rgba_copy (&color); } if (!dark_info_color) { - dark_info_color = g_malloc (sizeof (GdkRGBA)); - g_assert (gdk_rgba_parse (dark_info_color, DEFAULT_DARK_INFO_COLOR)); + gdk_rgba_parse (&color, DEFAULT_DARK_INFO_COLOR); + dark_info_color = gdk_rgba_copy (&color); } gtk_style_context_get_color (style, GTK_STATE_FLAG_SELECTED, &color); -- cgit v1.2.1 From e5708b8799ecd7b74b0c6d890677c0281b762cee Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Fri, 8 Jan 2016 21:24:28 +0100 Subject: GTK3 icon-container: fix rendering of text on the desktop taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=2e5f7a2 --- libcaja-private/caja-icon-container.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c index 645e76ba..203f1b8e 100644 --- a/libcaja-private/caja-icon-container.c +++ b/libcaja-private/caja-icon-container.c @@ -2884,7 +2884,7 @@ start_rubberbanding (CajaIconContainer *container, CajaIconContainerDetails *details; CajaIconRubberbandInfo *band_info; #if GTK_CHECK_VERSION(3,0,0) - GdkRGBA *fill_color_gdk, color; + GdkRGBA *fill_color_gdk, outline, color; GList *p; CajaIcon *icon; GtkStyleContext *style; @@ -2930,6 +2930,9 @@ start_rubberbanding (CajaIconContainer *container, fill_color_gdk->alpha = 0.25; } + outline = *fill_color_gdk; + eel_make_color_inactive (&outline); + band_info->selection_rectangle = eel_canvas_item_new (eel_canvas_root (EEL_CANVAS (container)), @@ -2939,7 +2942,7 @@ start_rubberbanding (CajaIconContainer *container, "x2", band_info->start_x, "y2", band_info->start_y, "fill_color_rgba", fill_color_gdk, - "outline_color_rgba", fill_color_gdk, + "outline_color_rgba", &outline, "width_pixels", 1, NULL); -- cgit v1.2.1 From 390400e11e888ee65d4620a03615c5aa23e4d089 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Fri, 8 Jan 2016 00:39:38 +0100 Subject: GTK3 icon-container: plug a memory leak taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=f394ce8 --- libcaja-private/caja-icon-container.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c index 203f1b8e..9aa26dac 100644 --- a/libcaja-private/caja-icon-container.c +++ b/libcaja-private/caja-icon-container.c @@ -9768,6 +9768,11 @@ caja_icon_container_theme_changed (gpointer user_data) container->details->normal_icon_color_rgba = *normal_icon_color; container->details->normal_color_rgba = color; + + setup_label_gcs (container); + + gdk_rgba_free (prelight_icon_color); + gdk_rgba_free (normal_icon_color); #else GtkStyle *style; GdkColor *prelight_icon_color, *normal_icon_color; @@ -9861,9 +9866,9 @@ caja_icon_container_theme_changed (gpointer user_data) style->base[GTK_STATE_PRELIGHT].green >> 8, style->base[GTK_STATE_PRELIGHT].blue >> 8, prelight_alpha); -#endif setup_label_gcs (container); +#endif } void -- cgit v1.2.1 From fa7dd4677f4196750d0c752c7b1823fdd7c54cbb Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Fri, 8 Jan 2016 22:04:08 +0100 Subject: GTK3 icon-container: remove useless theming properties taken from: https://git.gnome.org/browse/nautilus/commit/?id=e2ca42cac78cb0287a1bbb73030e7bba8b171970 --- libcaja-private/caja-icon-canvas-item.c | 16 ++++++--- libcaja-private/caja-icon-container.c | 57 +++++++++++++++++---------------- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/libcaja-private/caja-icon-canvas-item.c b/libcaja-private/caja-icon-canvas-item.c index 476b8839..4dcd2566 100644 --- a/libcaja-private/caja-icon-canvas-item.c +++ b/libcaja-private/caja-icon-canvas-item.c @@ -1410,7 +1410,11 @@ draw_label_text (CajaIconCanvasItem *item, GdkColor *label_color; #endif gboolean have_editable, have_additional; +#if GTK_CHECK_VERSION(3,0,0) + gboolean needs_highlight, prelight_label, is_rtl_label_beside; +#else gboolean needs_frame, needs_highlight, prelight_label, is_rtl_label_beside; +#endif EelIRect text_rect; int x; int max_text_width; @@ -1502,10 +1506,16 @@ draw_label_text (CajaIconCanvasItem *item, prepare_pango_layout_for_draw (item, editable_layout); gtk_widget_style_get (GTK_WIDGET (container), +#if !GTK_CHECK_VERSION(3,0,0) "frame_text", &needs_frame, +#endif "activate_prelight_icon_label", &prelight_label, NULL); +#if GTK_CHECK_VERSION(3,0,0) + if (!needs_highlight && details->text_width > 0 && details->text_height > 0) +#else if (needs_frame && !needs_highlight && details->text_width > 0 && details->text_height > 0) +#endif { if (!(prelight_label && item->details->is_prelit)) { @@ -2058,6 +2068,7 @@ real_map_pixbuf (CajaIconCanvasItem *icon_item) g_object_unref (old_pixbuf); } +#if !GTK_CHECK_VERSION(3,0,0) if (!icon_item->details->is_active && !icon_item->details->is_prelit && !icon_item->details->is_highlighted_for_selection @@ -2079,14 +2090,11 @@ real_map_pixbuf (CajaIconCanvasItem *icon_item) saturation, brightness, lighten, -#if GTK_CHECK_VERSION(3,0,0) - &container->details->normal_icon_color_rgba); -#else container->details->normal_icon_color_rgba); -#endif g_object_unref (old_pixbuf); } } +#endif return temp_pixbuf; } diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c index 9aa26dac..1bad9f26 100644 --- a/libcaja-private/caja-icon-container.c +++ b/libcaja-private/caja-icon-container.c @@ -4647,21 +4647,21 @@ style_set (GtkWidget *widget, GtkStyle *previous_style) { CajaIconContainer *container; +#if !GTK_CHECK_VERSION(3,0,0) gboolean frame_text; +#endif container = CAJA_ICON_CONTAINER (widget); #if GTK_CHECK_VERSION(3,0,0) - gtk_style_context_get_style (gtk_widget_get_style_context (GTK_WIDGET (container)), - "frame_text", &frame_text, - NULL); + container->details->use_drop_shadows = container->details->drop_shadows_requested; #else gtk_widget_style_get (GTK_WIDGET (container), "frame_text", &frame_text, NULL); -#endif container->details->use_drop_shadows = container->details->drop_shadows_requested && !frame_text; +#endif caja_icon_container_theme_changed (CAJA_ICON_CONTAINER (widget)); @@ -6633,15 +6633,8 @@ caja_icon_container_class_init (CajaIconContainerClass *class) class->start_interactive_search = caja_icon_container_start_interactive_search; - gtk_widget_class_install_style_property (widget_class, - g_param_spec_boolean ("frame_text", - "Frame Text", - "Draw a frame around unselected text", - FALSE, - G_PARAM_READABLE)); - - gtk_widget_class_install_style_property (widget_class, #if GTK_CHECK_VERSION(3,0,0) + gtk_widget_class_install_style_property (widget_class, g_param_spec_boxed ("selection_box_rgba", "Selection Box RGBA", "Color of the selection box", @@ -6659,7 +6652,15 @@ caja_icon_container_class_init (CajaIconContainerClass *class) "Dark Info RGBA", "Color used for information text against a light background", GDK_TYPE_RGBA, + G_PARAM_READABLE)); #else + gtk_widget_class_install_style_property (widget_class, + g_param_spec_boolean ("frame_text", + "Frame Text", + "Draw a frame around unselected text", + FALSE, + G_PARAM_READABLE)); + gtk_widget_class_install_style_property (widget_class, g_param_spec_boxed ("selection_box_color", "Selection Box Color", "Color of the selection box", @@ -6705,7 +6706,6 @@ caja_icon_container_class_init (CajaIconContainerClass *class) "Dark Info Color", "Color used for information text against a light background", GDK_TYPE_COLOR, -#endif G_PARAM_READABLE)); gtk_widget_class_install_style_property (widget_class, @@ -6715,6 +6715,7 @@ caja_icon_container_class_init (CajaIconContainerClass *class) 0, 3, DEFAULT_NORMAL_ICON_RENDER_MODE, G_PARAM_READABLE)); +#endif gtk_widget_class_install_style_property (widget_class, g_param_spec_uint ("prelight_icon_render_mode", "Prelight Icon Render Mode", @@ -6722,8 +6723,8 @@ caja_icon_container_class_init (CajaIconContainerClass *class) 0, 3, DEFAULT_PRELIGHT_ICON_RENDER_MODE, G_PARAM_READABLE)); - gtk_widget_class_install_style_property (widget_class, #if GTK_CHECK_VERSION(3,0,0) + gtk_widget_class_install_style_property (widget_class, g_param_spec_boxed ("normal_icon_rgba", "Icon Normal RGBA", "Color used for colorizing icons in normal state (default base[NORMAL])", @@ -6734,7 +6735,9 @@ caja_icon_container_class_init (CajaIconContainerClass *class) "Icon Prelight RGBA", "Color used for colorizing prelighted icons (default base[PRELIGHT])", GDK_TYPE_RGBA, + G_PARAM_READABLE)); #else + gtk_widget_class_install_style_property (widget_class, g_param_spec_boxed ("normal_icon_color", "Icon Normal Color", "Color used for colorizing icons in normal state (default base[NORMAL])", @@ -6745,7 +6748,6 @@ caja_icon_container_class_init (CajaIconContainerClass *class) "Icon Prelight Color", "Color used for colorizing prelighted icons (default base[PRELIGHT])", GDK_TYPE_COLOR, -#endif G_PARAM_READABLE)); gtk_widget_class_install_style_property (widget_class, g_param_spec_uint ("normal_icon_saturation", @@ -6754,6 +6756,7 @@ caja_icon_container_class_init (CajaIconContainerClass *class) 0, 255, DEFAULT_NORMAL_ICON_SATURATION, G_PARAM_READABLE)); +#endif gtk_widget_class_install_style_property (widget_class, g_param_spec_uint ("prelight_icon_saturation", "Prelight Icon Saturation", @@ -6761,6 +6764,7 @@ caja_icon_container_class_init (CajaIconContainerClass *class) 0, 255, DEFAULT_PRELIGHT_ICON_SATURATION, G_PARAM_READABLE)); +#if !GTK_CHECK_VERSION(3,0,0) gtk_widget_class_install_style_property (widget_class, g_param_spec_uint ("normal_icon_brightness", "Normal Icon Brightness", @@ -6768,6 +6772,7 @@ caja_icon_container_class_init (CajaIconContainerClass *class) 0, 255, DEFAULT_NORMAL_ICON_BRIGHTNESS, G_PARAM_READABLE)); +#endif gtk_widget_class_install_style_property (widget_class, g_param_spec_uint ("prelight_icon_brightness", "Prelight Icon Brightness", @@ -6775,6 +6780,7 @@ caja_icon_container_class_init (CajaIconContainerClass *class) 0, 255, DEFAULT_PRELIGHT_ICON_BRIGHTNESS, G_PARAM_READABLE)); +#if !GTK_CHECK_VERSION(3,0,0) gtk_widget_class_install_style_property (widget_class, g_param_spec_uint ("normal_icon_lighten", "Normal Icon Lighten", @@ -6782,6 +6788,7 @@ caja_icon_container_class_init (CajaIconContainerClass *class) 0, 255, DEFAULT_NORMAL_ICON_LIGHTEN, G_PARAM_READABLE)); +#endif gtk_widget_class_install_style_property (widget_class, g_param_spec_uint ("prelight_icon_lighten", "Prelight Icon Lighten", @@ -9467,7 +9474,6 @@ setup_label_gcs (CajaIconContainer *container) GtkWidget *widget; #if GTK_CHECK_VERSION(3,0,0) GdkRGBA *light_info_color, *dark_info_color; - gboolean frame_text; GtkStyleContext *style; GdkRGBA color; #else @@ -9525,14 +9531,7 @@ setup_label_gcs (CajaIconContainer *container) LABEL_INFO_COLOR_ACTIVE, eel_gdk_rgba_is_dark (&color) ? light_info_color : dark_info_color); - /* If CajaIconContainer::frame_text is set, we can safely - * use the foreground color from the theme, because it will - * always be displayed against the gtk background */ - gtk_style_context_get_style (gtk_widget_get_style_context (GTK_WIDGET (container)), - "frame_text", &frame_text, - NULL); - - if (frame_text /* || !eel_background_is_set(background) */) + if (!caja_icon_container_get_is_desktop (container)) { gtk_style_context_get_color (style, GTK_STATE_FLAG_ACTIVE, &color); setup_gc_with_fg (container, LABEL_COLOR, &color); @@ -9704,15 +9703,13 @@ void caja_icon_container_set_use_drop_shadows (CajaIconContainer *container, gboolean use_drop_shadows) { +#if !GTK_CHECK_VERSION(3,0,0) gboolean frame_text; -#if GTK_CHECK_VERSION(3,0,0) - gtk_style_context_get_style (gtk_widget_get_style_context (GTK_WIDGET (container)), -#else gtk_widget_style_get (GTK_WIDGET (container), -#endif "frame_text", &frame_text, NULL); +#endif if (container->details->drop_shadows_requested == use_drop_shadows) { @@ -9720,7 +9717,11 @@ caja_icon_container_set_use_drop_shadows (CajaIconContainer *container, } container->details->drop_shadows_requested = use_drop_shadows; +#if GTK_CHECK_VERSION(3,0,0) + container->details->use_drop_shadows = use_drop_shadows; +#else container->details->use_drop_shadows = use_drop_shadows && !frame_text; +#endif gtk_widget_queue_draw (GTK_WIDGET (container)); } -- cgit v1.2.1 From f700d63c933877362ed1cb92d8bddd2df1e29227 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Fri, 8 Jan 2016 00:41:46 +0100 Subject: GTK3 icon-container: fix a couple of ACTIVE -> NORMAL typos taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=d0d9059 --- libcaja-private/caja-icon-container.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c index 1bad9f26..9a6095e7 100644 --- a/libcaja-private/caja-icon-container.c +++ b/libcaja-private/caja-icon-container.c @@ -9533,10 +9533,10 @@ setup_label_gcs (CajaIconContainer *container) if (!caja_icon_container_get_is_desktop (container)) { - gtk_style_context_get_color (style, GTK_STATE_FLAG_ACTIVE, &color); + gtk_style_context_get_color (style, GTK_STATE_FLAG_NORMAL, &color); setup_gc_with_fg (container, LABEL_COLOR, &color); - gtk_style_context_get_background_color (style, GTK_STATE_FLAG_ACTIVE, &color); + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_NORMAL, &color); setup_gc_with_fg (container, LABEL_INFO_COLOR, eel_gdk_rgba_is_dark (&color) ? light_info_color : dark_info_color); @@ -9761,7 +9761,7 @@ caja_icon_container_theme_changed (gpointer user_data) gtk_style_context_get_style (style, "normal_icon_rgba", &normal_icon_color, NULL); - gtk_style_context_get_background_color (style, GTK_STATE_FLAG_ACTIVE, &color); + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_NORMAL, &color); if (!normal_icon_color) { normal_icon_color = gdk_rgba_copy (&color); -- cgit v1.2.1 From 288ceb4c5d5af35676031754db51cc1c5c53105f Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Fri, 8 Jan 2016 00:50:35 +0100 Subject: GTK3 icon-container: fix setting the selection when renaming Closes: bgo #642766 taken from: https://git.gnome.org/browse/nautilus/commit/?id=a8a5b8d --- libcaja-private/caja-icon-container.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c index 9a6095e7..93af49bc 100644 --- a/libcaja-private/caja-icon-container.c +++ b/libcaja-private/caja-icon-container.c @@ -9264,12 +9264,20 @@ caja_icon_container_start_renaming_selected_item (CajaIconContainer *container, { eel_filename_get_rename_region (editable_text, &start_offset, &end_offset); } + +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_show (details->rename_widget); + gtk_widget_grab_focus (details->rename_widget); +#endif + eel_editable_label_select_region (EEL_EDITABLE_LABEL (details->rename_widget), start_offset, end_offset); - gtk_widget_show (details->rename_widget); +#if !GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_show (details->rename_widget); gtk_widget_grab_focus (details->rename_widget); +#endif g_signal_emit (container, signals[RENAMING_ICON], 0, -- cgit v1.2.1 From b03a4c4078440f3ec1baea7ea158606f3c68e277 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 9 Jan 2016 01:11:39 +0100 Subject: GTK3 icon-canvas-item: use eel_create_spotlight_pixbuf() Instead of passing eel_pixbuf_render() always the same values taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=a1fa4ea --- libcaja-private/caja-icon-canvas-item.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libcaja-private/caja-icon-canvas-item.c b/libcaja-private/caja-icon-canvas-item.c index 4dcd2566..4bfffebf 100644 --- a/libcaja-private/caja-icon-canvas-item.c +++ b/libcaja-private/caja-icon-canvas-item.c @@ -1957,7 +1957,9 @@ real_map_pixbuf (CajaIconCanvasItem *icon_item) CajaIconContainer *container; GdkPixbuf *temp_pixbuf, *old_pixbuf, *audio_pixbuf; int emblem_size; +#if !GTK_CHECK_VERSION(3,0,0) guint render_mode, saturation, brightness, lighten; +#endif temp_pixbuf = icon_item->details->pixbuf; canvas = EEL_CANVAS_ITEM(icon_item)->canvas; @@ -1970,6 +1972,10 @@ real_map_pixbuf (CajaIconCanvasItem *icon_item) { old_pixbuf = temp_pixbuf; +#if GTK_CHECK_VERSION(3,0,0) + temp_pixbuf = eel_create_spotlight_pixbuf (temp_pixbuf); + g_object_unref (old_pixbuf); +#else gtk_widget_style_get (GTK_WIDGET (container), "prelight_icon_render_mode", &render_mode, "prelight_icon_saturation", &saturation, @@ -1984,15 +1990,10 @@ real_map_pixbuf (CajaIconCanvasItem *icon_item) saturation, brightness, lighten, -#if GTK_CHECK_VERSION(3,0,0) - &container->details->prelight_icon_color_rgba); -#else container->details->prelight_icon_color_rgba); -#endif g_object_unref (old_pixbuf); } - - +#endif /* FIXME bugzilla.gnome.org 42471: This hard-wired image is inappropriate to * this level of code, which shouldn't know that the -- cgit v1.2.1 From e2942ccb6206376293044bf0f7c885505e6a1113 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 9 Jan 2016 01:14:42 +0100 Subject: GTK3 icon-container: hook to style_updated instead of style_set taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=a083fa0 --- libcaja-private/caja-icon-container.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c index 93af49bc..fa93bf1e 100644 --- a/libcaja-private/caja-icon-container.c +++ b/libcaja-private/caja-icon-container.c @@ -4643,19 +4643,24 @@ unrealize (GtkWidget *widget) } static void +#if GTK_CHECK_VERSION(3,0,0) +style_updated (GtkWidget *widget) +{ + CajaIconContainer *container; + + GTK_WIDGET_CLASS (caja_icon_container_parent_class)->style_updated (widget); + + container = CAJA_ICON_CONTAINER (widget); + container->details->use_drop_shadows = container->details->drop_shadows_requested; +#else style_set (GtkWidget *widget, GtkStyle *previous_style) { CajaIconContainer *container; -#if !GTK_CHECK_VERSION(3,0,0) gboolean frame_text; -#endif container = CAJA_ICON_CONTAINER (widget); -#if GTK_CHECK_VERSION(3,0,0) - container->details->use_drop_shadows = container->details->drop_shadows_requested; -#else gtk_widget_style_get (GTK_WIDGET (container), "frame_text", &frame_text, NULL); @@ -6622,8 +6627,10 @@ caja_icon_container_class_init (CajaIconContainerClass *class) widget_class->key_press_event = key_press_event; widget_class->popup_menu = popup_menu; widget_class->get_accessible = get_accessible; +#if GTK_CHECK_VERSION(3,0,0) + widget_class->style_updated = style_updated; +#else widget_class->style_set = style_set; -#if !GTK_CHECK_VERSION(3,0,0) widget_class->expose_event = expose_event; #endif widget_class->grab_notify = grab_notify_cb; -- cgit v1.2.1 From ef3587fbf0d3e83b082ac94054799ce98b2fe52d Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 9 Jan 2016 02:49:09 +0100 Subject: GTK3 icon-container: remove unused style properties taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=e652eb0 --- libcaja-private/caja-icon-container.c | 47 +++-------------------------------- libcaja-private/caja-icon-private.h | 2 -- 2 files changed, 3 insertions(+), 46 deletions(-) diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c index fa93bf1e..b9cfa2d6 100644 --- a/libcaja-private/caja-icon-container.c +++ b/libcaja-private/caja-icon-container.c @@ -126,7 +126,6 @@ #else #define DEFAULT_LIGHT_INFO_COLOR 0xAAAAFD #define DEFAULT_DARK_INFO_COLOR 0x33337F -#endif #define DEFAULT_NORMAL_ICON_RENDER_MODE 0 #define DEFAULT_PRELIGHT_ICON_RENDER_MODE 1 @@ -136,6 +135,7 @@ #define DEFAULT_PRELIGHT_ICON_BRIGHTNESS 255 #define DEFAULT_NORMAL_ICON_LIGHTEN 0 #define DEFAULT_PRELIGHT_ICON_LIGHTEN 0 +#endif #define MINIMUM_EMBEDDED_TEXT_RECT_WIDTH 20 #define MINIMUM_EMBEDDED_TEXT_RECT_HEIGHT 20 @@ -6647,7 +6647,6 @@ caja_icon_container_class_init (CajaIconContainerClass *class) "Color of the selection box", GDK_TYPE_RGBA, G_PARAM_READABLE)); - gtk_widget_class_install_style_property (widget_class, g_param_spec_boxed ("light_info_rgba", "Light Info RGBA", @@ -6722,7 +6721,6 @@ caja_icon_container_class_init (CajaIconContainerClass *class) 0, 3, DEFAULT_NORMAL_ICON_RENDER_MODE, G_PARAM_READABLE)); -#endif gtk_widget_class_install_style_property (widget_class, g_param_spec_uint ("prelight_icon_render_mode", "Prelight Icon Render Mode", @@ -6730,20 +6728,6 @@ caja_icon_container_class_init (CajaIconContainerClass *class) 0, 3, DEFAULT_PRELIGHT_ICON_RENDER_MODE, G_PARAM_READABLE)); -#if GTK_CHECK_VERSION(3,0,0) - gtk_widget_class_install_style_property (widget_class, - g_param_spec_boxed ("normal_icon_rgba", - "Icon Normal RGBA", - "Color used for colorizing icons in normal state (default base[NORMAL])", - GDK_TYPE_RGBA, - G_PARAM_READABLE)); - gtk_widget_class_install_style_property (widget_class, - g_param_spec_boxed ("prelight_icon_rgba", - "Icon Prelight RGBA", - "Color used for colorizing prelighted icons (default base[PRELIGHT])", - GDK_TYPE_RGBA, - G_PARAM_READABLE)); -#else gtk_widget_class_install_style_property (widget_class, g_param_spec_boxed ("normal_icon_color", "Icon Normal Color", @@ -6763,7 +6747,6 @@ caja_icon_container_class_init (CajaIconContainerClass *class) 0, 255, DEFAULT_NORMAL_ICON_SATURATION, G_PARAM_READABLE)); -#endif gtk_widget_class_install_style_property (widget_class, g_param_spec_uint ("prelight_icon_saturation", "Prelight Icon Saturation", @@ -6771,7 +6754,6 @@ caja_icon_container_class_init (CajaIconContainerClass *class) 0, 255, DEFAULT_PRELIGHT_ICON_SATURATION, G_PARAM_READABLE)); -#if !GTK_CHECK_VERSION(3,0,0) gtk_widget_class_install_style_property (widget_class, g_param_spec_uint ("normal_icon_brightness", "Normal Icon Brightness", @@ -6779,7 +6761,6 @@ caja_icon_container_class_init (CajaIconContainerClass *class) 0, 255, DEFAULT_NORMAL_ICON_BRIGHTNESS, G_PARAM_READABLE)); -#endif gtk_widget_class_install_style_property (widget_class, g_param_spec_uint ("prelight_icon_brightness", "Prelight Icon Brightness", @@ -6787,7 +6768,6 @@ caja_icon_container_class_init (CajaIconContainerClass *class) 0, 255, DEFAULT_PRELIGHT_ICON_BRIGHTNESS, G_PARAM_READABLE)); -#if !GTK_CHECK_VERSION(3,0,0) gtk_widget_class_install_style_property (widget_class, g_param_spec_uint ("normal_icon_lighten", "Normal Icon Lighten", @@ -6795,7 +6775,6 @@ caja_icon_container_class_init (CajaIconContainerClass *class) 0, 255, DEFAULT_NORMAL_ICON_LIGHTEN, G_PARAM_READABLE)); -#endif gtk_widget_class_install_style_property (widget_class, g_param_spec_uint ("prelight_icon_lighten", "Prelight Icon Lighten", @@ -6803,6 +6782,7 @@ caja_icon_container_class_init (CajaIconContainerClass *class) 0, 255, DEFAULT_PRELIGHT_ICON_LIGHTEN, G_PARAM_READABLE)); +#endif gtk_widget_class_install_style_property (widget_class, g_param_spec_boolean ("activate_prelight_icon_label", "Activate Prelight Icon Label", @@ -9748,7 +9728,7 @@ caja_icon_container_theme_changed (gpointer user_data) CajaIconContainer *container; #if GTK_CHECK_VERSION(3,0,0) GtkStyleContext *style; - GdkRGBA *prelight_icon_color, *normal_icon_color, color; + GdkRGBA color; container = CAJA_ICON_CONTAINER (user_data); style = gtk_widget_get_style_context (GTK_WIDGET (container)); @@ -9759,36 +9739,15 @@ caja_icon_container_theme_changed (gpointer user_data) gtk_style_context_get_background_color (style, GTK_STATE_FLAG_ACTIVE, &color); container->details->active_color_rgba = color; - /* load the prelight icon color */ - gtk_style_context_get_style (style, - "prelight_icon_rgba", &prelight_icon_color, - NULL); gtk_style_context_get_background_color (style, GTK_STATE_FLAG_PRELIGHT, &color); - if (!prelight_icon_color) { - prelight_icon_color = gdk_rgba_copy (&color); - } - - container->details->prelight_icon_color_rgba = *prelight_icon_color; container->details->prelight_color_rgba = color; - /* load the normal icon color */ - gtk_style_context_get_style (style, - "normal_icon_rgba", &normal_icon_color, - NULL); gtk_style_context_get_background_color (style, GTK_STATE_FLAG_NORMAL, &color); - if (!normal_icon_color) { - normal_icon_color = gdk_rgba_copy (&color); - } - - container->details->normal_icon_color_rgba = *normal_icon_color; container->details->normal_color_rgba = color; setup_label_gcs (container); - - gdk_rgba_free (prelight_icon_color); - gdk_rgba_free (normal_icon_color); #else GtkStyle *style; GdkColor *prelight_icon_color, *normal_icon_color; diff --git a/libcaja-private/caja-icon-private.h b/libcaja-private/caja-icon-private.h index 0c36188f..e044ca75 100644 --- a/libcaja-private/caja-icon-private.h +++ b/libcaja-private/caja-icon-private.h @@ -216,8 +216,6 @@ struct CajaIconContainerDetails GdkRGBA active_color_rgba; GdkRGBA normal_color_rgba; GdkRGBA prelight_color_rgba; - GdkRGBA prelight_icon_color_rgba; - GdkRGBA normal_icon_color_rgba; /* colors for text labels */ GdkRGBA label_colors [LAST_LABEL_COLOR]; -- cgit v1.2.1 From 8d89b454e7eb52922b2ca3847c0ac909b352e67f Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 9 Jan 2016 16:09:15 +0100 Subject: GTK3 icon-canvas-item: remove an useless snippet of drawing code taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=09f0b79 --- libcaja-private/caja-icon-canvas-item.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/libcaja-private/caja-icon-canvas-item.c b/libcaja-private/caja-icon-canvas-item.c index 4bfffebf..d57b439f 100644 --- a/libcaja-private/caja-icon-canvas-item.c +++ b/libcaja-private/caja-icon-canvas-item.c @@ -1466,23 +1466,13 @@ draw_label_text (CajaIconCanvasItem *item, text_rect.y0, is_rtl_label_beside ? text_rect.x1 - text_rect.x0 - item->details->text_dx : text_rect.x1 - text_rect.x0, text_rect.y1 - text_rect.y0); +#if !GTK_CHECK_VERSION(3,0,0) } else if (!needs_highlight && !details->is_renaming && (details->is_prelit || details->is_highlighted_as_keyboard_focus)) { /* clear the underlying icons, where the text or overlaps them. */ -#if GTK_CHECK_VERSION(3,0,0) - cairo_save (cr); - cairo_set_source_rgba (cr, 0, 0, 0, 0); - cairo_rectangle (cr, - text_rect.x0, - text_rect.y0, - text_rect.x1 - text_rect.x0, - text_rect.y1 - text_rect.y0); - cairo_fill (cr); - cairo_restore (cr); -#else gdk_window_clear_area (gtk_layout_get_bin_window (&EEL_CANVAS (container)->layout), text_rect.x0, text_rect.y0, -- cgit v1.2.1 From b1350c6d63250d5ecfab95804c1bb7f5eeefe29f Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 9 Jan 2016 16:12:35 +0100 Subject: GTK3 general: use eel_create_spotlight_pixbuf() taken from: https://git.gnome.org/browse/nautilus/commit/?h=gnome-3-0&id=8b13a04 --- src/caja-places-sidebar.c | 9 +++++++++ src/file-manager/fm-list-model.c | 8 ++++++++ src/file-manager/fm-tree-model.c | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/src/caja-places-sidebar.c b/src/caja-places-sidebar.c index ce7bccdf..0fdeb9e3 100644 --- a/src/caja-places-sidebar.c +++ b/src/caja-places-sidebar.c @@ -27,9 +27,14 @@ #include #include #include +#if GTK_CHECK_VERSION(3,0,0) +#include +#endif #include #include +#if !GTK_CHECK_VERSION(3,0,0) #include +#endif #include #include #include @@ -244,7 +249,11 @@ get_eject_icon (gboolean highlighted) if (highlighted) { GdkPixbuf *high; +#if GTK_CHECK_VERSION(3,0,0) + high = eel_create_spotlight_pixbuf (eject); +#else high = eel_gdk_pixbuf_render (eject, 1, 255, 255, 0, 0); +#endif g_object_unref (eject); eject = high; } diff --git a/src/file-manager/fm-list-model.c b/src/file-manager/fm-list-model.c index 6a1692f4..1bf2d599 100644 --- a/src/file-manager/fm-list-model.c +++ b/src/file-manager/fm-list-model.c @@ -29,7 +29,11 @@ #include #include +#if GTK_CHECK_VERSION(3,0,0) +#include +#else #include +#endif #include #include #include @@ -386,7 +390,11 @@ fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column g_list_find_custom (model->details->highlight_files, file, (GCompareFunc) caja_file_compare_location)) { +#if GTK_CHECK_VERSION(3,0,0) + rendered_icon = eel_create_spotlight_pixbuf (icon); +#else rendered_icon = eel_gdk_pixbuf_render (icon, 1, 255, 255, 0, 0); +#endif if (rendered_icon != NULL) { diff --git a/src/file-manager/fm-tree-model.c b/src/file-manager/fm-tree-model.c index 504dd89a..039a1ef8 100644 --- a/src/file-manager/fm-tree-model.c +++ b/src/file-manager/fm-tree-model.c @@ -29,7 +29,11 @@ #include #include "fm-tree-model.h" +#if GTK_CHECK_VERSION(3,0,0) +#include +#else #include +#endif #include #include #include @@ -332,7 +336,11 @@ get_menu_icon_for_file (TreeNode *node, if (highlight) { +#if GTK_CHECK_VERSION(3,0,0) + pixbuf = eel_create_spotlight_pixbuf (retval); +#else pixbuf = eel_gdk_pixbuf_render (retval, 1, 255, 255, 0, 0); +#endif if (pixbuf != NULL) { -- 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(-) 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(+) 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 8b37981175499c9c876648165ddb7a5f94ae6849 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Sat, 9 Jan 2016 18:12:16 +0100 Subject: GTK3 icon-canvas-item: make the icon frame transparent when not prelit This fixes icons on the desktop appearing weird taken from: https://git.gnome.org/browse/nautilus/commit/?id=6a11ecd --- libcaja-private/caja-icon-canvas-item.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/libcaja-private/caja-icon-canvas-item.c b/libcaja-private/caja-icon-canvas-item.c index d57b439f..858a7393 100644 --- a/libcaja-private/caja-icon-canvas-item.c +++ b/libcaja-private/caja-icon-canvas-item.c @@ -1503,20 +1503,19 @@ draw_label_text (CajaIconCanvasItem *item, NULL); #if GTK_CHECK_VERSION(3,0,0) if (!needs_highlight && details->text_width > 0 && details->text_height > 0) + { + if (prelight_label && item->details->is_prelit) { + draw_frame (item, + cr, + &container->details->prelight_color_rgba, #else if (needs_frame && !needs_highlight && details->text_width > 0 && details->text_height > 0) -#endif { if (!(prelight_label && item->details->is_prelit)) { draw_frame (item, -#if GTK_CHECK_VERSION(3,0,0) - cr, - &container->details->normal_color_rgba, -#else drawable, container->details->normal_color_rgba, -#endif create_mask, text_rect.x0, text_rect.y0, @@ -1526,10 +1525,6 @@ draw_label_text (CajaIconCanvasItem *item, else { draw_frame (item, -#if GTK_CHECK_VERSION(3,0,0) - cr, - &container->details->prelight_color_rgba, -#else drawable, container->details->prelight_color_rgba, #endif -- 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(+) 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(-) 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(-) 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(+) 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(-) 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(-) 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 From e9ecff6c51b4e84fc350ccfe972439ed8dbe7215 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Mon, 11 Jan 2016 15:04:04 +0100 Subject: GTK3 icon-canvas-item: use gtk_render_* methods instead of direct cairo Instead of hardcoding colors and using direct cairo calls to draw the canvas items frame/background/labels, use gtk_render_* methods directly. This has the advantage of making them more friendly with GTK+ themes (by adding a caja-canvas-item style class to the canvas context when drawing) and removes a ton of convolut taken from: https://git.gnome.org/browse/nautilus/commit/?id=95910c9 --- libcaja-private/caja-icon-canvas-item.c | 385 ++++++++++++++++++++------------ 1 file changed, 243 insertions(+), 142 deletions(-) diff --git a/libcaja-private/caja-icon-canvas-item.c b/libcaja-private/caja-icon-canvas-item.c index 858a7393..d62f2c66 100644 --- a/libcaja-private/caja-icon-canvas-item.c +++ b/libcaja-private/caja-icon-canvas-item.c @@ -224,21 +224,15 @@ static void draw_pixbuf (GdkPixbuf static PangoLayout *get_label_layout (PangoLayout **layout, CajaIconCanvasItem *item, const char *text); +#if !GTK_CHECK_VERSION(3,0,0) static void draw_label_layout (CajaIconCanvasItem *item, -#if GTK_CHECK_VERSION(3,0,0) - cairo_t *cr, -#else GdkDrawable *drawable, -#endif PangoLayout *layout, gboolean highlight, -#if GTK_CHECK_VERSION(3,0,0) - GdkRGBA *label_color, -#else GdkColor *label_color, -#endif int x, int y); +#endif static gboolean hit_test_stretch_handle (CajaIconCanvasItem *item, EelIRect canvas_rect, GtkCornerType *corner); @@ -546,12 +540,19 @@ caja_icon_canvas_item_get_image (CajaIconCanvasItem *item, double item_x, item_y; gboolean is_rtl; cairo_t *cr; +#if GTK_CHECK_VERSION(3,0,0) + GtkStyleContext *context; +#endif g_return_val_if_fail (CAJA_IS_ICON_CANVAS_ITEM (item), NULL); canvas = EEL_CANVAS_ITEM (item)->canvas; #if GTK_CHECK_VERSION(3,0,0) screen = gtk_widget_get_screen (GTK_WIDGET (canvas)); + context = gtk_widget_get_style_context (GTK_WIDGET (canvas)); + + gtk_style_context_save (context); + gtk_style_context_add_class (context, "caja-canvas-item"); #else screen = gdk_colormap_get_screen (colormap); #endif @@ -577,12 +578,9 @@ caja_icon_canvas_item_get_image (CajaIconCanvasItem *item, width, height); cr = cairo_create (surface); - gdk_cairo_set_source_pixbuf (cr, item->details->pixbuf, + + gtk_render_icon (context, cr, item->details->pixbuf, item_offset_x, item_offset_y); - cairo_rectangle (cr, item_offset_x, item_offset_y, - gdk_pixbuf_get_width (item->details->pixbuf), - gdk_pixbuf_get_height (item->details->pixbuf)); - cairo_fill (cr); #else pixmap = gdk_pixmap_new (gdk_screen_get_root_window (screen), width, height, @@ -626,6 +624,8 @@ caja_icon_canvas_item_get_image (CajaIconCanvasItem *item, draw_label_text (item, cr, FALSE, icon_rect); cairo_destroy (cr); + gtk_style_context_restore (context); + return surface; #else while (emblem_layout_next (&emblem_layout, &emblem_pixbuf, &emblem_rect, is_rtl)) @@ -997,7 +997,7 @@ in_single_click_mode (void) return click_policy_auto_value == CAJA_CLICK_POLICY_SINGLE; } - +#if !GTK_CHECK_VERSION(3,0,0) /* Utility routine to create a rectangle with rounded corners. * This could possibly move to Eel as a general purpose routine. */ @@ -1041,24 +1041,15 @@ make_round_rect (cairo_t *cr, static void draw_frame (CajaIconCanvasItem *item, -#if GTK_CHECK_VERSION(3,0,0) - cairo_t *cr, - GdkRGBA *color, -#else GdkDrawable *drawable, guint color, -#endif gboolean create_mask, int x, int y, int width, int height) { -#if GTK_CHECK_VERSION(3,0,0) - cairo_save (cr); -#else cairo_t *cr = gdk_cairo_create (drawable); -#endif /* Set the rounded rect clip region. Magic rounding value taken * from old code. @@ -1073,26 +1064,18 @@ draw_frame (CajaIconCanvasItem *item, */ } -#if GTK_CHECK_VERSION(3,0,0) - gdk_cairo_set_source_rgba (cr, color); -#else cairo_set_source_rgba (cr, EEL_RGBA_COLOR_GET_R (color) / 255.0, EEL_RGBA_COLOR_GET_G (color) / 255.0, EEL_RGBA_COLOR_GET_B (color) / 255.0, EEL_RGBA_COLOR_GET_A (color) / 255.0); -#endif /* Paint into drawable now that we have set up the color and opacity */ cairo_fill (cr); -#if GTK_CHECK_VERSION(3,0,0) - cairo_restore (cr); -#else cairo_destroy (cr); -#endif } - +#endif /* Keep these for a bit while we work on performance of draw_or_measure_label_text. */ /* #define PERFORMANCE_TEST_DRAW_DISABLE @@ -1393,9 +1376,190 @@ static void draw_label_text (CajaIconCanvasItem *item, #if GTK_CHECK_VERSION(3,0,0) cairo_t *cr, + gboolean create_mask, + EelIRect icon_rect) +{ + CajaIconCanvasItemDetails *details; + CajaIconContainer *container; + PangoLayout *editable_layout; + PangoLayout *additional_layout; + GtkStyleContext *context; + GtkStateFlags state; + gboolean have_editable, have_additional; + gboolean needs_highlight, prelight_label, is_rtl_label_beside; + EelIRect text_rect; + int x; + int max_text_width; + gdouble frame_w, frame_h, frame_x, frame_y; + gboolean draw_frame = TRUE; + +#ifdef PERFORMANCE_TEST_DRAW_DISABLE + return; +#endif + + details = item->details; + + measure_label_text (item); + if (details->text_height == 0 || + details->text_width == 0) + { + return; + } + + container = CAJA_ICON_CONTAINER (EEL_CANVAS_ITEM (item)->canvas); + context = gtk_widget_get_style_context (GTK_WIDGET (container)); + + text_rect = compute_text_rectangle (item, icon_rect, TRUE, BOUNDS_USAGE_FOR_DISPLAY); + + needs_highlight = details->is_highlighted_for_selection || details->is_highlighted_for_drop; + is_rtl_label_beside = caja_icon_container_is_layout_rtl (container) && + container->details->label_position == CAJA_ICON_LABEL_POSITION_BESIDE; + + editable_layout = NULL; + additional_layout = NULL; + + have_editable = details->editable_text != NULL && details->editable_text[0] != '\0'; + have_additional = details->additional_text != NULL && details->additional_text[0] != '\0'; + g_assert (have_editable || have_additional); + + max_text_width = floor (caja_icon_canvas_item_get_max_text_width (item)); + + state = GTK_STATE_FLAG_NORMAL; + gtk_widget_style_get (GTK_WIDGET (container), + "activate_prelight_icon_label", &prelight_label, + NULL); + + /* if the icon is highlighted, do some set-up */ + if (needs_highlight && + !details->is_renaming) { + if (gtk_widget_has_focus (GTK_WIDGET (container))) { + state |= GTK_STATE_FLAG_SELECTED; + } else { + state |= GTK_STATE_FLAG_ACTIVE; + } + + frame_x = is_rtl_label_beside ? text_rect.x0 + item->details->text_dx : text_rect.x0; + frame_y = text_rect.y0; + frame_w = is_rtl_label_beside ? text_rect.x1 - text_rect.x0 - item->details->text_dx : text_rect.x1 - text_rect.x0; + frame_h = text_rect.y1 - text_rect.y0; + } else if (!needs_highlight && have_editable && + details->text_width > 0 && details->text_height > 0 && + prelight_label && item->details->is_prelit) { + state |= GTK_STATE_FLAG_PRELIGHT; + + frame_x = text_rect.x0; + frame_y = text_rect.y0; + frame_w = text_rect.x1 - text_rect.x0; + frame_h = text_rect.y1 - text_rect.y0; + } else { + draw_frame = FALSE; + } + + if (draw_frame) { + gtk_style_context_save (context); + gtk_style_context_set_state (context, state); + + gtk_render_frame (context, cr, + frame_x, frame_y, + frame_w, frame_h); + gtk_render_background (context, cr, + frame_x, frame_y, + frame_w, frame_h); + + gtk_style_context_restore (context); + } + + if (container->details->label_position == CAJA_ICON_LABEL_POSITION_BESIDE) + { + x = text_rect.x0 + 2; + } + else + { + x = text_rect.x0 + ((text_rect.x1 - text_rect.x0) - max_text_width) / 2; + } + + if (have_editable) + { + state = GTK_STATE_FLAG_NORMAL; + + if (prelight_label && item->details->is_prelit) { + state |= GTK_STATE_FLAG_PRELIGHT; + } + + if (needs_highlight && gtk_widget_has_focus (GTK_WIDGET (container))) { + state |= GTK_STATE_FLAG_SELECTED; + } else if (needs_highlight) { + state |= GTK_STATE_FLAG_ACTIVE; + } + + editable_layout = get_label_layout (&item->details->editable_text_layout, item, item->details->editable_text); + prepare_pango_layout_for_draw (item, editable_layout); + + gtk_style_context_save (context); + gtk_style_context_set_state (context, state); + + gtk_render_layout (context, cr, + x, text_rect.y0 + TEXT_BACK_PADDING_Y, + editable_layout); + + gtk_style_context_restore (context); + } + + if (have_additional) + { + state = GTK_STATE_FLAG_NORMAL; + + if (needs_highlight && gtk_widget_has_focus (GTK_WIDGET (container))) { + state |= GTK_STATE_FLAG_SELECTED; + } else if (needs_highlight) { + state |= GTK_STATE_FLAG_ACTIVE; + } + + additional_layout = get_label_layout (&item->details->additional_text_layout, item, item->details->additional_text); + prepare_pango_layout_for_draw (item, additional_layout); + + gtk_style_context_save (context); + gtk_style_context_set_state (context, state); + gtk_style_context_add_class (context, "dim-label"); + + gtk_render_layout (context, cr, + x, text_rect.y0 + details->editable_text_height + LABEL_LINE_SPACING + TEXT_BACK_PADDING_Y, + additional_layout); + } + + if (!create_mask && item->details->is_highlighted_as_keyboard_focus) + { + if (needs_highlight) { + state = GTK_STATE_FLAG_SELECTED; + } else { + state = GTK_STATE_FLAG_ACTIVE; + } + + gtk_style_context_save (context); + gtk_style_context_set_state (context, state); + + gtk_render_focus (context, + cr, + text_rect.x0, + text_rect.y0, + text_rect.x1 - text_rect.x0, + text_rect.y1 - text_rect.y0); + + gtk_style_context_restore (context); + } + + if (editable_layout != NULL) + { + g_object_unref (editable_layout); + } + + if (additional_layout != NULL) + { + g_object_unref (additional_layout); + } +} #else GdkDrawable *drawable, -#endif gboolean create_mask, EelIRect icon_rect) { @@ -1404,17 +1568,9 @@ draw_label_text (CajaIconCanvasItem *item, CajaIconContainer *container; PangoLayout *editable_layout; PangoLayout *additional_layout; -#if GTK_CHECK_VERSION(3,0,0) - GdkRGBA label_color; -#else GdkColor *label_color; -#endif gboolean have_editable, have_additional; -#if GTK_CHECK_VERSION(3,0,0) - gboolean needs_highlight, prelight_label, is_rtl_label_beside; -#else gboolean needs_frame, needs_highlight, prelight_label, is_rtl_label_beside; -#endif EelIRect text_rect; int x; int max_text_width; @@ -1423,7 +1579,6 @@ draw_label_text (CajaIconCanvasItem *item, return; #endif - canvas_item = EEL_CANVAS_ITEM (item); details = item->details; measure_label_text (item); @@ -1434,6 +1589,7 @@ draw_label_text (CajaIconCanvasItem *item, } container = CAJA_ICON_CONTAINER (EEL_CANVAS_ITEM (item)->canvas); + canvas_item = EEL_CANVAS_ITEM (item); text_rect = compute_text_rectangle (item, icon_rect, TRUE, BOUNDS_USAGE_FOR_DISPLAY); @@ -1450,23 +1606,16 @@ draw_label_text (CajaIconCanvasItem *item, max_text_width = floor (caja_icon_canvas_item_get_max_text_width (item)); - /* if the icon is highlighted, do some set-up */ if (needs_highlight && !details->is_renaming) { draw_frame (item, -#if GTK_CHECK_VERSION(3,0,0) - cr, - gtk_widget_has_focus (GTK_WIDGET (container)) ? &container->details->highlight_color_rgba : &container->details->active_color_rgba, -#else drawable, gtk_widget_has_focus (GTK_WIDGET (container)) ? container->details->highlight_color_rgba : container->details->active_color_rgba, -#endif create_mask, is_rtl_label_beside ? text_rect.x0 + item->details->text_dx : text_rect.x0, text_rect.y0, is_rtl_label_beside ? text_rect.x1 - text_rect.x0 - item->details->text_dx : text_rect.x1 - text_rect.x0, text_rect.y1 - text_rect.y0); -#if !GTK_CHECK_VERSION(3,0,0) } else if (!needs_highlight && !details->is_renaming && (details->is_prelit || @@ -1478,7 +1627,6 @@ draw_label_text (CajaIconCanvasItem *item, text_rect.y0, text_rect.x1 - text_rect.x0, text_rect.y1 - text_rect.y0); -#endif } if (container->details->label_position == CAJA_ICON_LABEL_POSITION_BESIDE) @@ -1496,19 +1644,9 @@ draw_label_text (CajaIconCanvasItem *item, prepare_pango_layout_for_draw (item, editable_layout); gtk_widget_style_get (GTK_WIDGET (container), -#if !GTK_CHECK_VERSION(3,0,0) "frame_text", &needs_frame, -#endif "activate_prelight_icon_label", &prelight_label, NULL); -#if GTK_CHECK_VERSION(3,0,0) - if (!needs_highlight && details->text_width > 0 && details->text_height > 0) - { - if (prelight_label && item->details->is_prelit) { - draw_frame (item, - cr, - &container->details->prelight_color_rgba, -#else if (needs_frame && !needs_highlight && details->text_width > 0 && details->text_height > 0) { if (!(prelight_label && item->details->is_prelit)) @@ -1527,7 +1665,6 @@ draw_label_text (CajaIconCanvasItem *item, draw_frame (item, drawable, container->details->prelight_color_rgba, -#endif create_mask, text_rect.x0, text_rect.y0, @@ -1542,15 +1679,9 @@ draw_label_text (CajaIconCanvasItem *item, prelight_label & item->details->is_prelit); draw_label_layout (item, -#if GTK_CHECK_VERSION(3,0,0) - cr, - editable_layout, needs_highlight, - &label_color, -#else drawable, editable_layout, needs_highlight, label_color, -#endif x, text_rect.y0 + TEXT_BACK_PADDING_Y); } @@ -1566,50 +1697,25 @@ draw_label_text (CajaIconCanvasItem *item, FALSE); draw_label_layout (item, -#if GTK_CHECK_VERSION(3,0,0) - cr, - additional_layout, needs_highlight, - &label_color, -#else drawable, additional_layout, needs_highlight, label_color, -#endif x, text_rect.y0 + details->editable_text_height + LABEL_LINE_SPACING + TEXT_BACK_PADDING_Y); } if (!create_mask && item->details->is_highlighted_as_keyboard_focus) { -#if GTK_CHECK_VERSION(3,0,0) - GtkStyleContext *style; - - style = gtk_widget_get_style_context (GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas)); - - gtk_style_context_save (style); - gtk_style_context_add_class (style, "icon-container"); - gtk_style_context_set_state (style, - needs_highlight ? - GTK_STATE_FLAG_SELECTED : GTK_STATE_FLAG_ACTIVE); - - gtk_render_focus (style, - cr, -#else gtk_paint_focus (gtk_widget_get_style (GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas)), drawable, needs_highlight ? GTK_STATE_SELECTED : GTK_STATE_NORMAL, NULL, GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas), "icon-container", -#endif text_rect.x0, text_rect.y0, text_rect.x1 - text_rect.x0, text_rect.y1 - text_rect.y0); -#if GTK_CHECK_VERSION(3,0,0) - - gtk_style_context_restore (style); -#endif } if (editable_layout != NULL) @@ -1622,6 +1728,7 @@ draw_label_text (CajaIconCanvasItem *item, g_object_unref (additional_layout); } } +#endif void caja_icon_canvas_item_set_is_visible (CajaIconCanvasItem *item, @@ -1942,7 +2049,10 @@ real_map_pixbuf (CajaIconCanvasItem *icon_item) CajaIconContainer *container; GdkPixbuf *temp_pixbuf, *old_pixbuf, *audio_pixbuf; int emblem_size; -#if !GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3,0,0) + GtkStyleContext *style; + GdkRGBA color; +#else guint render_mode, saturation, brightness, lighten; #endif @@ -2029,15 +2139,16 @@ real_map_pixbuf (CajaIconCanvasItem *icon_item) || icon_item->details->is_highlighted_for_drop) { #if GTK_CHECK_VERSION(3,0,0) - GdkRGBA *color; - - old_pixbuf = temp_pixbuf; + style = gtk_widget_get_style_context (GTK_WIDGET (canvas)); - color = gtk_widget_has_focus (GTK_WIDGET (canvas)) ? - &CAJA_ICON_CONTAINER (canvas)->details->highlight_color_rgba : - &CAJA_ICON_CONTAINER (canvas)->details->active_color_rgba; + if (gtk_widget_has_focus (GTK_WIDGET (canvas))) { + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, &color); + } else { + gtk_style_context_get_background_color (style, GTK_STATE_FLAG_ACTIVE, &color); + } - temp_pixbuf = eel_create_colorized_pixbuf (temp_pixbuf, color); + old_pixbuf = temp_pixbuf; + temp_pixbuf = eel_create_colorized_pixbuf (temp_pixbuf, &color); #else guint color; @@ -2186,19 +2297,28 @@ static void caja_icon_canvas_item_draw (EelCanvasItem *item, cairo_t *cr, cairo_region_t *region) +{ + CajaIconContainer *container; #else caja_icon_canvas_item_draw (EelCanvasItem *item, GdkDrawable *drawable, GdkEventExpose *expose) -#endif { +#endif CajaIconCanvasItem *icon_item; CajaIconCanvasItemDetails *details; EelIRect icon_rect, emblem_rect; EmblemLayout emblem_layout; GdkPixbuf *emblem_pixbuf, *temp_pixbuf; +#if GTK_CHECK_VERSION(3,0,0) + GtkStyleContext *context; + + container = CAJA_ICON_CONTAINER (item->canvas); + gboolean is_rtl; +#else GdkRectangle pixbuf_rect; gboolean is_rtl; +#endif icon_item = CAJA_ICON_CANVAS_ITEM (item); details = icon_item->details; @@ -2208,8 +2328,23 @@ caja_icon_canvas_item_draw (EelCanvasItem *item, GdkDrawable *drawable, return; } +#if GTK_CHECK_VERSION(3,0,0) + context = gtk_widget_get_style_context (GTK_WIDGET (container)); + gtk_style_context_save (context); + gtk_style_context_add_class (context, "caja-canvas-item"); + +#endif icon_rect = icon_item->details->canvas_rect; +#if GTK_CHECK_VERSION(3,0,0) + temp_pixbuf = map_pixbuf (icon_item); + gtk_render_icon (context, cr, + temp_pixbuf, + icon_rect.x0, icon_rect.y0); + g_object_unref (temp_pixbuf); + + draw_embedded_text (icon_item, cr, icon_rect.x0, icon_rect.y0); +#else /* if the pre-lit or selection flag is set, make a pre-lit or darkened pixbuf and draw that instead */ /* and colorize normal pixbuf if rc wants that */ temp_pixbuf = map_pixbuf (icon_item); @@ -2218,26 +2353,15 @@ caja_icon_canvas_item_draw (EelCanvasItem *item, GdkDrawable *drawable, pixbuf_rect.width = gdk_pixbuf_get_width (temp_pixbuf); pixbuf_rect.height = gdk_pixbuf_get_height (temp_pixbuf); -#if GTK_CHECK_VERSION(3,0,0) - cairo_save (cr); -#else cairo_t *cr = gdk_cairo_create (drawable); gdk_cairo_rectangle (cr, &expose->area); cairo_clip (cr); -#endif gdk_cairo_set_source_pixbuf (cr, temp_pixbuf, pixbuf_rect.x, pixbuf_rect.y); gdk_cairo_rectangle (cr, &pixbuf_rect); cairo_fill (cr); -#if GTK_CHECK_VERSION(3,0,0) - cairo_restore (cr); -#else cairo_destroy (cr); -#endif g_object_unref (temp_pixbuf); -#if GTK_CHECK_VERSION(3,0,0) - draw_embedded_text (icon_item, cr, icon_rect.x0, icon_rect.y0); -#else draw_embedded_text (icon_item, drawable, icon_rect.x0, icon_rect.y0); #endif @@ -2249,18 +2373,19 @@ caja_icon_canvas_item_draw (EelCanvasItem *item, GdkDrawable *drawable, { #if GTK_CHECK_VERSION(3,0,0) draw_pixbuf (emblem_pixbuf, cr, emblem_rect.x0, emblem_rect.y0); -#else - draw_pixbuf (emblem_pixbuf, drawable, emblem_rect.x0, emblem_rect.y0); -#endif } -#if GTK_CHECK_VERSION(3,0,0) /* Draw stretching handles (if necessary). */ draw_stretch_handles (icon_item, cr, &icon_rect); /* Draw the label text. */ draw_label_text (icon_item, cr, FALSE, icon_rect); + + gtk_style_context_restore (context); #else + draw_pixbuf (emblem_pixbuf, drawable, emblem_rect.x0, emblem_rect.y0); + } + draw_stretch_handles (icon_item, drawable, &icon_rect); draw_label_text (icon_item, drawable, FALSE, icon_rect); #endif @@ -2379,18 +2504,9 @@ get_label_layout (PangoLayout **layout_cache, return layout; } +#if !GTK_CHECK_VERSION(3,0,0) static void draw_label_layout (CajaIconCanvasItem *item, -#if GTK_CHECK_VERSION(3,0,0) - cairo_t *cr, - PangoLayout *layout, - gboolean highlight, - GdkRGBA *label_color, - int x, - int y) -{ - GdkRGBA black = { 0, 0, 0, 1 }; -#else GdkDrawable *drawable, PangoLayout *layout, gboolean highlight, @@ -2399,7 +2515,6 @@ draw_label_layout (CajaIconCanvasItem *item, int y) { g_return_if_fail (drawable != NULL); -#endif if (item->details->is_renaming) { @@ -2409,36 +2524,22 @@ draw_label_layout (CajaIconCanvasItem *item, if (!highlight && (CAJA_ICON_CONTAINER (EEL_CANVAS_ITEM (item)->canvas)->details->use_drop_shadows)) { /* draw a drop shadow */ -#if GTK_CHECK_VERSION(3,0,0) - eel_cairo_draw_layout_with_drop_shadow (cr, - label_color, - &black, -#else eel_gdk_draw_layout_with_drop_shadow (drawable, label_color, >k_widget_get_style (GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas))->black, -#endif x, y, layout); } else { -#if GTK_CHECK_VERSION(3,0,0) - cairo_save (cr); - gdk_cairo_set_source_rgba (cr, label_color); -#else cairo_t *cr = gdk_cairo_create (drawable); gdk_cairo_set_source_color (cr, label_color); -#endif 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 } } +#endif /* handle events */ -- cgit v1.2.1 From 5ec02960d6f78dd23b02af27e6f3c595ab4e99bc Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Mon, 11 Jan 2016 15:08:16 +0100 Subject: GTK3 icon-container: remove unused code caching canvas item colors Caching colors in CajaIconContainer to use them in the canvas item is not needed anymore, as gtk_render_* fetches the right values directly from the style context. taken from: https://git.gnome.org/browse/nautilus/commit/?id=77eecef --- libcaja-private/caja-icon-container.c | 133 ++++------------------------------ libcaja-private/caja-icon-private.h | 16 +--- 2 files changed, 18 insertions(+), 131 deletions(-) diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c index b9cfa2d6..d7fc3545 100644 --- a/libcaja-private/caja-icon-container.c +++ b/libcaja-private/caja-icon-container.c @@ -181,7 +181,9 @@ static GType caja_icon_container_accessible_get_type (void); static void activate_selected_items (CajaIconContainer *container); static void activate_selected_items_alternate (CajaIconContainer *container, CajaIcon *icon); +#if !GTK_CHECK_VERSION(3, 0, 0) static void caja_icon_container_theme_changed (gpointer user_data); +#endif static void compute_stretch (StretchState *start, StretchState *current); static CajaIcon *get_first_selected_icon (CajaIconContainer *container); @@ -207,7 +209,9 @@ static inline void icon_get_bounding_box (CajaIcon static gboolean is_renaming (CajaIconContainer *container); static gboolean is_renaming_pending (CajaIconContainer *container); static void process_pending_icon_to_rename (CajaIconContainer *container); +#if !GTK_CHECK_VERSION(3, 0, 0) static void setup_label_gcs (CajaIconContainer *container); +#endif static void caja_icon_container_stop_monitor_top_left (CajaIconContainer *container, CajaIconData *data, gconstpointer client); @@ -4612,7 +4616,9 @@ realize (GtkWidget *widget) /* Set up DnD. */ caja_icon_dnd_init (container); +#if !GTK_CHECK_VERSION(3, 0, 0) setup_label_gcs (container); +#endif hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (widget)); g_signal_connect (hadj, "value_changed", @@ -4666,9 +4672,9 @@ style_set (GtkWidget *widget, NULL); container->details->use_drop_shadows = container->details->drop_shadows_requested && !frame_text; -#endif caja_icon_container_theme_changed (CAJA_ICON_CONTAINER (widget)); +#endif if (gtk_widget_get_realized (widget)) { @@ -6948,8 +6954,10 @@ caja_icon_container_init (CajaIconContainer *container) /* when the background changes, we must set up the label text color */ background = eel_get_widget_background (GTK_WIDGET (container)); +#if !GTK_CHECK_VERSION(3,0,0) g_signal_connect_object (background, "appearance_changed", G_CALLBACK (update_label_color), container, 0); +#endif g_signal_connect (container, "focus-in-event", G_CALLBACK (handle_focus_in_event), NULL); @@ -6958,8 +6966,10 @@ caja_icon_container_init (CajaIconContainer *container) eel_background_set_use_base (background, TRUE); +#if !GTK_CHECK_VERSION(3,0,0) /* read in theme-dependent data */ caja_icon_container_theme_changed (container); +#endif if (!setup_prefs) { @@ -9380,16 +9390,12 @@ caja_icon_container_set_single_click_mode (CajaIconContainer *container, container->details->single_click_mode = single_click_mode; } - +#if !GTK_CHECK_VERSION(3,0,0) /* update the label color when the background changes */ void caja_icon_container_get_label_color (CajaIconContainer *container, -#if GTK_CHECK_VERSION(3,0,0) - GdkRGBA *color, -#else GdkColor **color, -#endif gboolean is_name, gboolean is_highlight, gboolean is_prelit) @@ -9442,24 +9448,14 @@ caja_icon_container_get_label_color (CajaIconContainer *container, if (color) { -#if GTK_CHECK_VERSION(3,0,0) - *color = container->details->label_colors[idx]; -#else *color = &container->details->label_colors [idx]; -#endif } } static void -#if GTK_CHECK_VERSION(3,0,0) -setup_gc_with_fg (CajaIconContainer *container, int idx, GdkRGBA *color) -{ - container->details->label_colors[idx] = *color; -#else setup_gc_with_fg (CajaIconContainer *container, int idx, guint32 color) { container->details->label_colors [idx] = eel_gdk_rgb_to_color (color); -#endif } static void @@ -9467,16 +9463,10 @@ setup_label_gcs (CajaIconContainer *container) { EelBackground *background; GtkWidget *widget; -#if GTK_CHECK_VERSION(3,0,0) - GdkRGBA *light_info_color, *dark_info_color; - GtkStyleContext *style; - GdkRGBA color; -#else GdkColor *light_info_color, *dark_info_color; guint light_info_value, dark_info_value; gboolean frame_text; GtkStyle *style; -#endif if (!gtk_widget_get_realized (GTK_WIDGET (container))) return; @@ -9488,76 +9478,6 @@ setup_label_gcs (CajaIconContainer *container) background = eel_get_widget_background (GTK_WIDGET (container)); /* read the info colors from the current theme; use a reasonable default if undefined */ -#if GTK_CHECK_VERSION(3,0,0) - style = gtk_widget_get_style_context (widget); - gtk_style_context_get_style (style, - "light_info_rgba", &light_info_color, - "dark_info_rgba", &dark_info_color, - NULL); - - if (!light_info_color) - { - gdk_rgba_parse (&color, DEFAULT_LIGHT_INFO_COLOR); - light_info_color = gdk_rgba_copy (&color); - } - - if (!dark_info_color) - { - gdk_rgba_parse (&color, DEFAULT_DARK_INFO_COLOR); - dark_info_color = gdk_rgba_copy (&color); - } - - gtk_style_context_get_color (style, GTK_STATE_FLAG_SELECTED, &color); - setup_gc_with_fg (container, LABEL_COLOR_HIGHLIGHT, &color); - - gtk_style_context_get_color (style, GTK_STATE_FLAG_ACTIVE, &color); - setup_gc_with_fg (container, LABEL_COLOR_ACTIVE, &color); - - gtk_style_context_get_color (style, GTK_STATE_FLAG_PRELIGHT, &color); - setup_gc_with_fg (container, LABEL_COLOR_PRELIGHT, &color); - - gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, &color); - setup_gc_with_fg (container, - LABEL_INFO_COLOR_HIGHLIGHT, - eel_gdk_rgba_is_dark (&color) ? light_info_color : dark_info_color); - - gtk_style_context_get_background_color (style, GTK_STATE_FLAG_ACTIVE, &color); - setup_gc_with_fg (container, - LABEL_INFO_COLOR_ACTIVE, - eel_gdk_rgba_is_dark (&color) ? light_info_color : dark_info_color); - - if (!caja_icon_container_get_is_desktop (container)) - { - gtk_style_context_get_color (style, GTK_STATE_FLAG_NORMAL, &color); - setup_gc_with_fg (container, LABEL_COLOR, &color); - - gtk_style_context_get_background_color (style, GTK_STATE_FLAG_NORMAL, &color); - setup_gc_with_fg (container, LABEL_INFO_COLOR, - eel_gdk_rgba_is_dark (&color) ? - light_info_color : dark_info_color); - } - else - { - if (container->details->use_drop_shadows || eel_background_is_dark (background)) - { - GdkRGBA tmp; - - gdk_rgba_parse (&tmp, "#EFEFEF"); - setup_gc_with_fg (container, LABEL_COLOR, &tmp); - setup_gc_with_fg (container, LABEL_INFO_COLOR, light_info_color); - } - else /* converse */ - { - GdkRGBA tmp; - - gdk_rgba_parse (&tmp, "#000000"); - setup_gc_with_fg (container, LABEL_COLOR, &tmp); - setup_gc_with_fg (container, LABEL_INFO_COLOR, dark_info_color); - } - } - gdk_rgba_free (dark_info_color); - gdk_rgba_free (light_info_color); -#else gtk_widget_style_get (GTK_WIDGET (container), "light_info_color", &light_info_color, "dark_info_color", &dark_info_color, @@ -9627,7 +9547,6 @@ setup_label_gcs (CajaIconContainer *container) dark_info_value); } } -#endif } static void @@ -9638,7 +9557,7 @@ update_label_color (EelBackground *background, setup_label_gcs (container); } - +#endif /* Return if the icon container is a fixed size */ gboolean @@ -9722,33 +9641,11 @@ caja_icon_container_set_use_drop_shadows (CajaIconContainer *container, /* handle theme changes */ +#if !GTK_CHECK_VERSION(3,0,0) static void caja_icon_container_theme_changed (gpointer user_data) { CajaIconContainer *container; -#if GTK_CHECK_VERSION(3,0,0) - GtkStyleContext *style; - GdkRGBA color; - - container = CAJA_ICON_CONTAINER (user_data); - style = gtk_widget_get_style_context (GTK_WIDGET (container)); - - gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, &color); - container->details->highlight_color_rgba = color; - - gtk_style_context_get_background_color (style, GTK_STATE_FLAG_ACTIVE, &color); - container->details->active_color_rgba = color; - - gtk_style_context_get_background_color (style, GTK_STATE_FLAG_PRELIGHT, &color); - - container->details->prelight_color_rgba = color; - - gtk_style_context_get_background_color (style, GTK_STATE_FLAG_NORMAL, &color); - - container->details->normal_color_rgba = color; - - setup_label_gcs (container); -#else GtkStyle *style; GdkColor *prelight_icon_color, *normal_icon_color; guchar highlight_alpha, normal_alpha, prelight_alpha; @@ -9843,8 +9740,8 @@ caja_icon_container_theme_changed (gpointer user_data) prelight_alpha); setup_label_gcs (container); -#endif } +#endif void caja_icon_container_set_font (CajaIconContainer *container, diff --git a/libcaja-private/caja-icon-private.h b/libcaja-private/caja-icon-private.h index e044ca75..9364bab7 100644 --- a/libcaja-private/caja-icon-private.h +++ b/libcaja-private/caja-icon-private.h @@ -211,15 +211,7 @@ struct CajaIconContainerDetails int font_size_table[CAJA_ZOOM_LEVEL_LARGEST + 1]; /* pixbuf and color for label highlighting */ -#if GTK_CHECK_VERSION(3,0,0) - GdkRGBA highlight_color_rgba; - GdkRGBA active_color_rgba; - GdkRGBA normal_color_rgba; - GdkRGBA prelight_color_rgba; - - /* colors for text labels */ - GdkRGBA label_colors [LAST_LABEL_COLOR]; -#else +#if !GTK_CHECK_VERSION(3,0,0) guint32 highlight_color_rgba; guint32 active_color_rgba; guint32 normal_color_rgba; @@ -335,15 +327,13 @@ gboolean caja_icon_container_scroll (CajaIconContainer int delta_y); void caja_icon_container_update_scroll_region (CajaIconContainer *container); +#if !GTK_CHECK_VERSION(3,0,0) /* label color for items */ void caja_icon_container_get_label_color (CajaIconContainer *container, -#if GTK_CHECK_VERSION(3,0,0) - GdkRGBA *color, -#else GdkColor **color, -#endif gboolean first_line, gboolean needs_highlight, gboolean is_prelit); +#endif #endif /* CAJA_ICON_CONTAINER_PRIVATE_H */ -- cgit v1.2.1 From 412486b1f4c8a0a60d9aa07b39e38ed66852ae3d Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Mon, 11 Jan 2016 17:48:12 +0100 Subject: GTK3 icon-canvas-item: render the additional text with gtk_render_layout() And add a style class for it. taken from: https://git.gnome.org/browse/nautilus/commit/?id=7732a6b https://git.gnome.org/browse/nautilus/commit/?id=2cb91c0 --- libcaja-private/caja-icon-canvas-item.c | 35 +++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/libcaja-private/caja-icon-canvas-item.c b/libcaja-private/caja-icon-canvas-item.c index d62f2c66..69b06bee 100644 --- a/libcaja-private/caja-icon-canvas-item.c +++ b/libcaja-private/caja-icon-canvas-item.c @@ -2237,6 +2237,10 @@ draw_embedded_text (CajaIconCanvasItem *item, PangoLayout *layout; PangoContext *context; PangoFontDescription *desc; +#if GTK_CHECK_VERSION(3,0,0) + GtkWidget *widget; + GtkStyleContext *style_context; +#endif if (item->details->embedded_text == NULL || item->details->embedded_text_rect.width == 0 || @@ -2245,13 +2249,21 @@ draw_embedded_text (CajaIconCanvasItem *item, return; } +#if GTK_CHECK_VERSION(3,0,0) + widget = GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas); +#endif + if (item->details->embedded_text_layout != NULL) { layout = g_object_ref (item->details->embedded_text_layout); } else { +#if GTK_CHECK_VERSION(3,0,0) + context = gtk_widget_get_pango_context (widget); +#else context = gtk_widget_get_pango_context (GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas)); +#endif layout = pango_layout_new (context); pango_layout_set_text (layout, item->details->embedded_text, -1); @@ -2266,10 +2278,28 @@ draw_embedded_text (CajaIconCanvasItem *item, } #if GTK_CHECK_VERSION(3,0,0) + style_context = gtk_widget_get_style_context (widget); + gtk_style_context_save (style_context); + gtk_style_context_add_class (style_context, "icon-embedded-text"); + cairo_save (cr); + + cairo_rectangle (cr, + x + item->details->embedded_text_rect.x, + y + item->details->embedded_text_rect.y, + item->details->embedded_text_rect.width, + item->details->embedded_text_rect.height); + cairo_clip (cr); + + gtk_render_layout (style_context, cr, + x + item->details->embedded_text_rect.x, + y + item->details->embedded_text_rect.y, + layout); + + gtk_style_context_restore (style_context); + cairo_restore (cr); #else cairo_t *cr = gdk_cairo_create (drawable); -#endif cairo_rectangle (cr, x + item->details->embedded_text_rect.x, @@ -2284,9 +2314,6 @@ draw_embedded_text (CajaIconCanvasItem *item, y + item->details->embedded_text_rect.y); pango_cairo_show_layout (cr, layout); -#if GTK_CHECK_VERSION(3,0,0) - cairo_restore (cr); -#else cairo_destroy (cr); #endif } -- cgit v1.2.1 From 8e4612599a9a6cb1f380dd6cbef9ad3d885cf77f Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Mon, 11 Jan 2016 17:56:38 +0100 Subject: GTK3 icon-canvas-item: don't draw pango layouts when renaming Fixes a regression introduced in commit 3a858857fff5e1d7e0bffcec63fea6d2a933ce27 that causes unwanted text to be drawn while renaming a file in icon view. taken from: https://git.gnome.org/browse/nautilus/commit/?id=f07aa75 --- libcaja-private/caja-icon-canvas-item.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libcaja-private/caja-icon-canvas-item.c b/libcaja-private/caja-icon-canvas-item.c index 69b06bee..3d719d5a 100644 --- a/libcaja-private/caja-icon-canvas-item.c +++ b/libcaja-private/caja-icon-canvas-item.c @@ -1478,7 +1478,8 @@ draw_label_text (CajaIconCanvasItem *item, x = text_rect.x0 + ((text_rect.x1 - text_rect.x0) - max_text_width) / 2; } - if (have_editable) + if (have_editable && + !details->is_renaming) { state = GTK_STATE_FLAG_NORMAL; @@ -1505,7 +1506,8 @@ draw_label_text (CajaIconCanvasItem *item, gtk_style_context_restore (context); } - if (have_additional) + if (have_additional && + !details->is_renaming) { state = GTK_STATE_FLAG_NORMAL; -- cgit v1.2.1 From 4974f96274a7cbc0056983dea03b2d42615714e4 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Mon, 11 Jan 2016 18:36:08 +0100 Subject: GTK3 icon-canvas-item: don't override parent container style flags When drawing the canvas item elements, don't override the parent container style flags, so we don't lose e.g. backdrop information. taken from: https://git.gnome.org/browse/nautilus/commit/?id=31dad6f --- libcaja-private/caja-icon-canvas-item.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/libcaja-private/caja-icon-canvas-item.c b/libcaja-private/caja-icon-canvas-item.c index 3d719d5a..803cde76 100644 --- a/libcaja-private/caja-icon-canvas-item.c +++ b/libcaja-private/caja-icon-canvas-item.c @@ -1384,7 +1384,7 @@ draw_label_text (CajaIconCanvasItem *item, PangoLayout *editable_layout; PangoLayout *additional_layout; GtkStyleContext *context; - GtkStateFlags state; + GtkStateFlags state, base_state; gboolean have_editable, have_additional; gboolean needs_highlight, prelight_label, is_rtl_label_beside; EelIRect text_rect; @@ -1424,7 +1424,10 @@ draw_label_text (CajaIconCanvasItem *item, max_text_width = floor (caja_icon_canvas_item_get_max_text_width (item)); - state = GTK_STATE_FLAG_NORMAL; + base_state = gtk_widget_get_state_flags (GTK_WIDGET (container)); + base_state &= ~(GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_PRELIGHT); + state = base_state; + gtk_widget_style_get (GTK_WIDGET (container), "activate_prelight_icon_label", &prelight_label, NULL); @@ -1432,11 +1435,7 @@ draw_label_text (CajaIconCanvasItem *item, /* if the icon is highlighted, do some set-up */ if (needs_highlight && !details->is_renaming) { - if (gtk_widget_has_focus (GTK_WIDGET (container))) { - state |= GTK_STATE_FLAG_SELECTED; - } else { - state |= GTK_STATE_FLAG_ACTIVE; - } + state |= GTK_STATE_FLAG_SELECTED; frame_x = is_rtl_label_beside ? text_rect.x0 + item->details->text_dx : text_rect.x0; frame_y = text_rect.y0; @@ -1481,16 +1480,14 @@ draw_label_text (CajaIconCanvasItem *item, if (have_editable && !details->is_renaming) { - state = GTK_STATE_FLAG_NORMAL; + state = base_state; if (prelight_label && item->details->is_prelit) { state |= GTK_STATE_FLAG_PRELIGHT; } - if (needs_highlight && gtk_widget_has_focus (GTK_WIDGET (container))) { + if (needs_highlight) { state |= GTK_STATE_FLAG_SELECTED; - } else if (needs_highlight) { - state |= GTK_STATE_FLAG_ACTIVE; } editable_layout = get_label_layout (&item->details->editable_text_layout, item, item->details->editable_text); @@ -1509,12 +1506,10 @@ draw_label_text (CajaIconCanvasItem *item, if (have_additional && !details->is_renaming) { - state = GTK_STATE_FLAG_NORMAL; + state = base_state; - if (needs_highlight && gtk_widget_has_focus (GTK_WIDGET (container))) { + if (needs_highlight) { state |= GTK_STATE_FLAG_SELECTED; - } else if (needs_highlight) { - state |= GTK_STATE_FLAG_ACTIVE; } additional_layout = get_label_layout (&item->details->additional_text_layout, item, item->details->additional_text); @@ -1533,8 +1528,6 @@ draw_label_text (CajaIconCanvasItem *item, { if (needs_highlight) { state = GTK_STATE_FLAG_SELECTED; - } else { - state = GTK_STATE_FLAG_ACTIVE; } gtk_style_context_save (context); -- cgit v1.2.1 From 43e928f798eec8035a00ab9f58a0bc43a31f8ab8 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Mon, 11 Jan 2016 19:29:39 +0100 Subject: GTK3 icon-container: use the "rubberband" style class for the selection item Instead of using a custom style property. Autor: lukefromdc same as: https://git.gnome.org/browse/nautilus/commit/?id=ca7f81e2 --- libcaja-private/caja-icon-container.c | 121 ++++++++++++++++++++++------------ 1 file changed, 78 insertions(+), 43 deletions(-) diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c index d7fc3545..40a02167 100644 --- a/libcaja-private/caja-icon-container.c +++ b/libcaja-private/caja-icon-container.c @@ -2880,6 +2880,83 @@ rubberband_timeout_callback (gpointer data) return TRUE; } +#if GTK_CHECK_VERSION(3,0,0) +/*borrowed from Nemo, makes Caja rubberbanding follow same selectors as Nemo and presumably Nautilus */ +static void +start_rubberbanding (CajaIconContainer *container, + GdkEventButton *event) +{ + AtkObject *accessible; + CajaIconContainerDetails *details; + CajaIconRubberbandInfo *band_info; + GdkRGBA bg_color, border_color; + GList *p; + CajaIcon *icon; + GtkStyleContext *context; + + details = container->details; + band_info = &details->rubberband_info; + + g_signal_emit (container, + signals[BAND_SELECT_STARTED], 0); + + for (p = details->icons; p != NULL; p = p->next) { + icon = p->data; + icon->was_selected_before_rubberband = icon->is_selected; + } + + eel_canvas_window_to_world + (EEL_CANVAS (container), event->x, event->y, + &band_info->start_x, &band_info->start_y); + + context = gtk_widget_get_style_context (GTK_WIDGET (container)); + gtk_style_context_save (context); + gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND); + + gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg_color); + gtk_style_context_get_border_color (context, GTK_STATE_FLAG_NORMAL, &border_color); + + gtk_style_context_restore (context); + + band_info->selection_rectangle = eel_canvas_item_new + (eel_canvas_root + (EEL_CANVAS (container)), + EEL_TYPE_CANVAS_RECT, + "x1", band_info->start_x, + "y1", band_info->start_y, + "x2", band_info->start_x, + "y2", band_info->start_y, + "fill_color_rgba", &bg_color, + "outline_color_rgba", &border_color, + "width_pixels", 1, + NULL); + + accessible = atk_gobject_accessible_for_object + (G_OBJECT (band_info->selection_rectangle)); + atk_object_set_name (accessible, "selection"); + atk_object_set_description (accessible, _("The selection rectangle")); + + band_info->prev_x = event->x - gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container))); + band_info->prev_y = event->y - gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container))); + + band_info->active = TRUE; + + if (band_info->timer_id == 0) { + band_info->timer_id = g_timeout_add + (RUBBERBAND_TIMEOUT_INTERVAL, + rubberband_timeout_callback, + container); + } + + eel_canvas_item_grab (band_info->selection_rectangle, + (GDK_POINTER_MOTION_MASK + | GDK_BUTTON_RELEASE_MASK + | GDK_SCROLL_MASK), + NULL, event->time); +} + + +#else static void start_rubberbanding (CajaIconContainer *container, GdkEventButton *event) @@ -2887,19 +2964,12 @@ start_rubberbanding (CajaIconContainer *container, AtkObject *accessible; CajaIconContainerDetails *details; CajaIconRubberbandInfo *band_info; -#if GTK_CHECK_VERSION(3,0,0) - GdkRGBA *fill_color_gdk, outline, color; - GList *p; - CajaIcon *icon; - GtkStyleContext *style; -#else guint fill_color, outline_color; GdkColor *fill_color_gdk; guchar fill_color_alpha; GList *p; CajaIcon *icon; GtkStyle *style; -#endif details = container->details; band_info = &details->rubberband_info; @@ -2917,41 +2987,6 @@ start_rubberbanding (CajaIconContainer *container, (EEL_CANVAS (container), event->x, event->y, &band_info->start_x, &band_info->start_y); -#if GTK_CHECK_VERSION(3,0,0) - style = gtk_widget_get_style_context (GTK_WIDGET (container)); - gtk_style_context_get_style (style, - "selection_box_rgba", &fill_color_gdk, - NULL); - - if (!fill_color_gdk) - { - gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, - &color); - fill_color_gdk = gdk_rgba_copy (&color); - } - - if (fill_color_gdk->alpha == 1) { - fill_color_gdk->alpha = 0.25; - } - - outline = *fill_color_gdk; - eel_make_color_inactive (&outline); - - band_info->selection_rectangle = eel_canvas_item_new - (eel_canvas_root - (EEL_CANVAS (container)), - EEL_TYPE_CANVAS_RECT, - "x1", band_info->start_x, - "y1", band_info->start_y, - "x2", band_info->start_x, - "y2", band_info->start_y, - "fill_color_rgba", fill_color_gdk, - "outline_color_rgba", &outline, - "width_pixels", 1, - NULL); - - gdk_rgba_free (fill_color_gdk); -#else gtk_widget_style_get (GTK_WIDGET (container), "selection_box_color", &fill_color_gdk, "selection_box_alpha", &fill_color_alpha, @@ -2981,7 +3016,6 @@ start_rubberbanding (CajaIconContainer *container, "outline_color_rgba", outline_color, "width_pixels", 1, NULL); -#endif accessible = atk_gobject_accessible_for_object (G_OBJECT (band_info->selection_rectangle)); @@ -3007,6 +3041,7 @@ start_rubberbanding (CajaIconContainer *container, | GDK_SCROLL_MASK), NULL, event->time); } +#endif static void stop_rubberbanding (CajaIconContainer *container, -- cgit v1.2.1 From 2c8e8a06a050d43d730475bf05cbd07508f32160 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Mon, 11 Jan 2016 20:38:24 +0100 Subject: GTK3 icon-container: don't chain up style-updated for the desktop container Chaining up resets the background to the default color, which is not what we want for the desktop container. Fixes https://github.com/mate-desktop/caja/issues/445 taken from: https://git.gnome.org/browse/nautilus/commit/?id=83a7d27 --- libcaja-private/caja-icon-container.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c index 40a02167..066da73f 100644 --- a/libcaja-private/caja-icon-container.c +++ b/libcaja-private/caja-icon-container.c @@ -4689,10 +4689,21 @@ style_updated (GtkWidget *widget) { CajaIconContainer *container; - GTK_WIDGET_CLASS (caja_icon_container_parent_class)->style_updated (widget); - container = CAJA_ICON_CONTAINER (widget); container->details->use_drop_shadows = container->details->drop_shadows_requested; + + /* Don't chain up to parent, if this is a desktop container, + * because that resets the background of the window. + */ + if (!caja_icon_container_get_is_desktop (container)) { + GTK_WIDGET_CLASS (caja_icon_container_parent_class)->style_updated (widget); + } + + if (gtk_widget_get_realized (widget)) + { + invalidate_label_sizes (container); + caja_icon_container_request_update_all (container); + } #else style_set (GtkWidget *widget, GtkStyle *previous_style) @@ -4709,7 +4720,6 @@ style_set (GtkWidget *widget, container->details->use_drop_shadows = container->details->drop_shadows_requested && !frame_text; caja_icon_container_theme_changed (CAJA_ICON_CONTAINER (widget)); -#endif if (gtk_widget_get_realized (widget)) { @@ -4719,6 +4729,7 @@ style_set (GtkWidget *widget, /* Don't chain up to parent, because that sets the background of the window and we're doing that ourself with some delay, so this would cause flickering */ +#endif } static gboolean -- cgit v1.2.1 From 4b2d71fef886fbdffd8d1a03a337cf1e794d1252 Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Mon, 11 Jan 2016 22:25:23 +0100 Subject: GTK3 icon-container: invalidate the layout cache on style-updated This way label sizes will be recomputed if e.g. DPI settings change. https://bugzilla.gnome.org/show_bug.cgi?id=578468 taken from: https://git.gnome.org/browse/nautilus/commit/?id=2f064e5 --- libcaja-private/caja-icon-container.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcaja-private/caja-icon-container.c b/libcaja-private/caja-icon-container.c index 066da73f..2cec67a5 100644 --- a/libcaja-private/caja-icon-container.c +++ b/libcaja-private/caja-icon-container.c @@ -4701,7 +4701,7 @@ style_updated (GtkWidget *widget) if (gtk_widget_get_realized (widget)) { - invalidate_label_sizes (container); + invalidate_labels (container); caja_icon_container_request_update_all (container); } #else -- cgit v1.2.1 From 1befe8ddf08c12b5c926d269b31d270fb94b9c3e Mon Sep 17 00:00:00 2001 From: Wolfgang Ulbrich Date: Tue, 12 Jan 2016 01:21:41 +0100 Subject: GTK3 file-conflict-dialog: don't use override_font Set the PangoAttributeList on the GtkLabel instead. and 'don't force a size request on the labels' This is not required anymore in GTK+ 3 taken from: https://git.gnome.org/browse/nautilus/commit/?id=52b8185 https://git.gnome.org/browse/nautilus/commit/?id=b8077a7 https://git.gnome.org/browse/nautilus/commit/?id=1457f53 --- libcaja-private/caja-file-conflict-dialog.c | 32 +++++++++++++---------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/libcaja-private/caja-file-conflict-dialog.c b/libcaja-private/caja-file-conflict-dialog.c index 28887f88..300543b3 100644 --- a/libcaja-private/caja-file-conflict-dialog.c +++ b/libcaja-private/caja-file-conflict-dialog.c @@ -116,8 +116,7 @@ file_list_ready_cb (GList *files, GtkWidget *label; GString *str; #if GTK_CHECK_VERSION(3,0,0) - PangoFontDescription *desc, *old_desc; - GtkStyleContext *style; + PangoAttrList *attr_list; #else PangoFontDescription *desc; #endif @@ -221,25 +220,22 @@ file_list_ready_cb (GList *files, label = gtk_label_new (primary_text); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); gtk_label_set_line_wrap_mode (GTK_LABEL (label), PANGO_WRAP_WORD_CHAR); - gtk_widget_set_size_request (label, 350, -1); -#if GTK_CHECK_VERSION (3, 14, 0) +#if GTK_CHECK_VERSION (3, 0, 0) gtk_widget_set_halign (label, GTK_ALIGN_START); gtk_box_pack_start (GTK_BOX (details->titles_vbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); - style = gtk_widget_get_style_context (label); - gtk_style_context_get_style (style, - GTK_STYLE_PROPERTY_FONT, &old_desc, - NULL); + attr_list = pango_attr_list_new (); + pango_attr_list_insert (attr_list, pango_attr_weight_new (PANGO_WEIGHT_BOLD)); + pango_attr_list_insert (attr_list, pango_attr_scale_new (PANGO_SCALE_LARGE)); + g_object_set (label, + "attributes", attr_list, + NULL); - desc = pango_font_description_new (); - pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD); - pango_font_description_set_size (desc, - pango_font_description_get_size (old_desc) * PANGO_SCALE_LARGE); - gtk_widget_override_font (label, desc); - pango_font_description_free (desc); - pango_font_description_free (old_desc); + pango_attr_list_unref (attr_list); #else + gtk_widget_set_size_request (label, 350, -1); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); gtk_box_pack_start (GTK_BOX (details->titles_vbox), label, FALSE, FALSE, 0); @@ -252,15 +248,15 @@ file_list_ready_cb (GList *files, pango_font_description_get_size (gtk_widget_get_style (label)->font_desc) * PANGO_SCALE_LARGE); gtk_widget_modify_font (label, desc); pango_font_description_free (desc); -#endif gtk_widget_show (label); +#endif label = gtk_label_new (secondary_text); gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); - gtk_widget_set_size_request (label, 350, -1); -#if GTK_CHECK_VERSION (3, 14, 0) +#if GTK_CHECK_VERSION (3, 0, 0) gtk_widget_set_halign (label, GTK_ALIGN_START); #else + gtk_widget_set_size_request (label, 350, -1); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); #endif gtk_box_pack_start (GTK_BOX (details->titles_vbox), -- cgit v1.2.1