Skip to content

Commit

Permalink
selectable image drawing for gtk3
Browse files Browse the repository at this point in the history
  • Loading branch information
nadvornik committed Aug 13, 2012
1 parent 05547f5 commit db57b78
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit db57b78

Please sign in to comment.