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(-) (limited to 'libcaja-private/caja-icon-canvas-item.c') 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 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libcaja-private/caja-icon-canvas-item.c') 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, -- 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(-) (limited to 'libcaja-private/caja-icon-canvas-item.c') 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 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 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'libcaja-private/caja-icon-canvas-item.c') 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; } -- 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(-) (limited to 'libcaja-private/caja-icon-canvas-item.c') 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 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(-) (limited to 'libcaja-private/caja-icon-canvas-item.c') 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 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(-) (limited to 'libcaja-private/caja-icon-canvas-item.c') 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 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(-) (limited to 'libcaja-private/caja-icon-canvas-item.c') 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 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(-) (limited to 'libcaja-private/caja-icon-canvas-item.c') 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(-) (limited to 'libcaja-private/caja-icon-canvas-item.c') 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(-) (limited to 'libcaja-private/caja-icon-canvas-item.c') 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