selectable image drawing for gtk3
authorVladimir Nadvornik <nadvornik@suse.cz>
Sat, 4 Aug 2012 20:13:33 +0000 (22:13 +0200)
committerVladimir Nadvornik <nadvornik@suse.cz>
Mon, 13 Aug 2012 19:40:07 +0000 (21:40 +0200)
src/image.c

index 2ee7528..a459d53 100644 (file)
@@ -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);