From db57b78baf8ae8e8b1f7694a3efb804f1e5547b9 Mon Sep 17 00:00:00 2001 From: Vladimir Nadvornik Date: Sat, 4 Aug 2012 22:13:33 +0200 Subject: [PATCH] selectable image drawing for gtk3 --- src/image.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/image.c b/src/image.c index 2ee75282..a459d536 100644 --- a/src/image.c +++ b/src/image.c @@ -1723,12 +1723,42 @@ static void image_destroy_cb(GtkWidget *widget, gpointer data) ImageWindow *imd = data; image_free(imd); } +#if GTK_CHECK_VERSION(3,0,0) +gboolean selectable_frame_draw_cb(GtkWidget *widget, cairo_t *cr, gpointer data) +{ + GtkAllocation allocation; + gtk_widget_get_allocation(widget, &allocation); + gtk_paint_flat_box(gtk_widget_get_style(widget), + cr, + gtk_widget_get_state(widget), + gtk_frame_get_shadow_type(GTK_FRAME(widget)), + widget, + NULL, + allocation.x + 3, allocation.y + 3, + allocation.width - 6, allocation.height - 6); + if (gtk_widget_has_focus(widget)) + { + gtk_paint_focus(gtk_widget_get_style(widget), cr, GTK_STATE_ACTIVE, + widget, "image_window", + allocation.x, allocation.y, + allocation.width - 1, allocation.height - 1); + } + else + { + gtk_paint_shadow(gtk_widget_get_style(widget), cr, GTK_STATE_NORMAL, GTK_SHADOW_IN, + widget, "image_window", + allocation.x, allocation.y, + allocation.width - 1, allocation.height - 1); + } + return FALSE; +} + +#else gboolean selectable_frame_expose_cb(GtkWidget *widget, GdkEventExpose *event, gpointer data) { GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); -#if !GTK_CHECK_VERSION(3,0,0) gtk_paint_flat_box(gtk_widget_get_style(widget), gtk_widget_get_window(widget), gtk_widget_get_state(widget), @@ -1753,9 +1783,9 @@ gboolean selectable_frame_expose_cb(GtkWidget *widget, GdkEventExpose *event, gp allocation.x, allocation.y, allocation.width - 1, allocation.height - 1); } -#endif return FALSE; } +#endif void image_set_frame(ImageWindow *imd, gboolean frame) @@ -1785,9 +1815,13 @@ void image_set_frame(ImageWindow *imd, gboolean frame) gtk_widget_set_can_focus(imd->frame, TRUE); gtk_widget_set_app_paintable(imd->frame, TRUE); +#if GTK_CHECK_VERSION(3,0,0) + g_signal_connect(G_OBJECT(imd->frame), "draw", + G_CALLBACK(selectable_frame_draw_cb), NULL); +#else g_signal_connect(G_OBJECT(imd->frame), "expose_event", G_CALLBACK(selectable_frame_expose_cb), NULL); - +#endif g_signal_connect(G_OBJECT(imd->frame), "focus_in_event", G_CALLBACK(image_focus_in_cb), imd); -- 2.20.1