diff options
author | Stefano Karapetsas <[email protected]> | 2014-01-21 17:10:42 +0100 |
---|---|---|
committer | Stefano Karapetsas <[email protected]> | 2014-01-21 17:10:42 +0100 |
commit | 75173c8f5ebdac9a095a466af602d6b07324029f (patch) | |
tree | c62c097c1e2cb3e80319f6e8125ece792e75f1fe /libview/ev-view-presentation.c | |
parent | 5109344eba11c4da9d10970dabe8aa159c6596c3 (diff) | |
download | atril-75173c8f5ebdac9a095a466af602d6b07324029f.tar.bz2 atril-75173c8f5ebdac9a095a466af602d6b07324029f.tar.xz |
libview: Add GTK3 support
Diffstat (limited to 'libview/ev-view-presentation.c')
-rw-r--r-- | libview/ev-view-presentation.c | 98 |
1 files changed, 95 insertions, 3 deletions
diff --git a/libview/ev-view-presentation.c b/libview/ev-view-presentation.c index 48386218..0309d5e9 100644 --- a/libview/ev-view-presentation.c +++ b/libview/ev-view-presentation.c @@ -22,7 +22,11 @@ #include <stdlib.h> #include <glib/gi18n-lib.h> +#include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> +#if GTK_CHECK_VERSION (3, 0, 0) +#include <gdk/gdkkeysyms-compat.h> +#endif #include "ev-view-presentation.h" #include "ev-jobs.h" @@ -901,7 +905,11 @@ ev_view_presentation_update_current_surface (EvViewPresentation *pview, } static void +#if GTK_CHECK_VERSION (3, 0, 0) +ev_view_presentation_dispose (GObject *object) +#else ev_view_presentation_destroy (GtkObject *object) +#endif { EvViewPresentation *pview = EV_VIEW_PRESENTATION (object); @@ -945,9 +953,30 @@ ev_view_presentation_destroy (GtkObject *object) pview->goto_entry = NULL; } +#if GTK_CHECK_VERSION (3, 0, 0) + G_OBJECT_CLASS (ev_view_presentation_parent_class)->dispose (object); +#else GTK_OBJECT_CLASS (ev_view_presentation_parent_class)->destroy (object); +#endif } +#if GTK_CHECK_VERSION (3, 0, 0) +static void +ev_view_presentation_get_preferred_width (GtkWidget *widget, + gint *minimum, + gint *natural) +{ + *minimum = *natural = 0; +} + +static void +ev_view_presentation_get_preferred_height (GtkWidget *widget, + gint *minimum, + gint *natural) +{ + *minimum = *natural = 0; +} +#else static void ev_view_presentation_size_request (GtkWidget *widget, GtkRequisition *requisition) @@ -955,9 +984,10 @@ ev_view_presentation_size_request (GtkWidget *widget, requisition->width = 0; requisition->height = 0; } +#endif static void -ev_view_presentation_draw_end_page (EvViewPresentation *pview) +ev_view_presentation_draw_end_page (EvViewPresentation *pview, cairo_t *cr) { GtkWidget *widget = GTK_WIDGET (pview); PangoLayout *layout; @@ -983,6 +1013,17 @@ ev_view_presentation_draw_end_page (EvViewPresentation *pview) area.width = allocation.width; area.height = allocation.height; +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_paint_layout (gtk_widget_get_style (widget), + cr, + gtk_widget_get_state (widget), + FALSE, + widget, + NULL, + 15, + 15, + layout); +#else gtk_paint_layout (gtk_widget_get_style (widget), gtk_widget_get_window (widget), gtk_widget_get_state (widget), @@ -993,24 +1034,40 @@ ev_view_presentation_draw_end_page (EvViewPresentation *pview) 15, 15, layout); +#endif pango_font_description_free (font_desc); g_object_unref (layout); } static gboolean +#if GTK_CHECK_VERSION (3, 0, 0) +ev_view_presentation_draw (GtkWidget *widget, + cairo_t *cr) +#else ev_view_presentation_expose_event (GtkWidget *widget, GdkEventExpose *event) +#endif { EvViewPresentation *pview = EV_VIEW_PRESENTATION (widget); GdkRectangle page_area; GdkRectangle overlap; cairo_surface_t *surface; +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_rectangle_int_t clip_rect; + GdkRectangle *area = &clip_rect; +#else cairo_t *cr; + GdkRectangle *area = &event->area; +#endif +#if GTK_CHECK_VERSION (3, 0, 0) + if (!gdk_cairo_get_clip_rectangle (cr, &clip_rect)) + return FALSE; +#endif switch (pview->state) { case EV_PRESENTATION_END: - ev_view_presentation_draw_end_page (pview); + ev_view_presentation_draw_end_page (pview, cr); return FALSE; case EV_PRESENTATION_BLACK: case EV_PRESENTATION_WHITE: @@ -1023,7 +1080,9 @@ ev_view_presentation_expose_event (GtkWidget *widget, if (ev_transition_animation_ready (pview->animation)) { ev_view_presentation_get_page_area (pview, &page_area); +#if !GTK_CHECK_VERSION (3, 0, 0) cr = gdk_cairo_create (gtk_widget_get_window (widget)); +#endif /* normalize to x=0, y=0 */ cairo_translate (cr, page_area.x, page_area.y); @@ -1033,7 +1092,9 @@ ev_view_presentation_expose_event (GtkWidget *widget, page_area.width--; ev_transition_animation_paint (pview->animation, cr, page_area); +#if !GTK_CHECK_VERSION (3, 0, 0) cairo_destroy (cr); +#endif } return TRUE; @@ -1049,8 +1110,10 @@ ev_view_presentation_expose_event (GtkWidget *widget, } ev_view_presentation_get_page_area (pview, &page_area); - if (gdk_rectangle_intersect (&page_area, &(event->area), &overlap)) { + if (gdk_rectangle_intersect (&page_area, area, &overlap)) { +#if !GTK_CHECK_VERSION (3, 0, 0) cr = gdk_cairo_create (gtk_widget_get_window (widget)); +#endif /* Try to fix rounding errors. See bug #438760 */ if (overlap.width == page_area.width) @@ -1059,7 +1122,9 @@ ev_view_presentation_expose_event (GtkWidget *widget, cairo_rectangle (cr, overlap.x, overlap.y, overlap.width, overlap.height); cairo_set_source_surface (cr, surface, page_area.x, page_area.y); cairo_fill (cr); +#if !GTK_CHECK_VERSION (3, 0, 0) cairo_destroy (cr); +#endif } return FALSE; @@ -1072,7 +1137,11 @@ ev_view_presentation_key_press_event (GtkWidget *widget, EvViewPresentation *pview = EV_VIEW_PRESENTATION (widget); if (pview->state == EV_PRESENTATION_END) +#if GTK_CHECK_VERSION (3, 0, 0) + return gtk_bindings_activate_event (G_OBJECT (widget), event); +#else return gtk_bindings_activate_event (GTK_OBJECT (widget), event); +#endif switch (event->keyval) { case GDK_b: @@ -1128,7 +1197,11 @@ ev_view_presentation_key_press_event (GtkWidget *widget, return TRUE; } +#if GTK_CHECK_VERSION (3, 0, 0) + return gtk_bindings_activate_event (G_OBJECT (widget), event); +#else return gtk_bindings_activate_event (GTK_OBJECT (widget), event); +#endif } static gboolean @@ -1222,7 +1295,9 @@ ev_view_presentation_realize (GtkWidget *widget) attributes.window_type = GDK_WINDOW_CHILD; attributes.wclass = GDK_INPUT_OUTPUT; attributes.visual = gtk_widget_get_visual (widget); +#if !GTK_CHECK_VERSION (3, 0, 0) attributes.colormap = gtk_widget_get_colormap (widget); +#endif gtk_widget_get_allocation (widget, &allocation); attributes.x = allocation.x; @@ -1242,7 +1317,9 @@ ev_view_presentation_realize (GtkWidget *widget) window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, GDK_WA_X | GDK_WA_Y | +#if !GTK_CHECK_VERSION (3, 0, 0) GDK_WA_COLORMAP | +#endif GDK_WA_VISUAL); gdk_window_set_user_data (window, widget); @@ -1366,21 +1443,36 @@ ev_view_presentation_class_init (EvViewPresentationClass *klass) { GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); GObjectClass *gobject_class = G_OBJECT_CLASS (klass); +#if !GTK_CHECK_VERSION (3, 0, 0) GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass); +#endif GtkBindingSet *binding_set; klass->change_page = ev_view_presentation_change_page; +#if GTK_CHECK_VERSION (3, 0, 0) + widget_class->get_preferred_width = ev_view_presentation_get_preferred_width; + widget_class->get_preferred_height = ev_view_presentation_get_preferred_height; +#else widget_class->size_request = ev_view_presentation_size_request; +#endif widget_class->realize = ev_view_presentation_realize; +#if GTK_CHECK_VERSION (3, 0, 0) + widget_class->draw = ev_view_presentation_draw; +#else widget_class->expose_event = ev_view_presentation_expose_event; +#endif widget_class->key_press_event = ev_view_presentation_key_press_event; widget_class->button_release_event = ev_view_presentation_button_release_event; widget_class->focus_out_event = ev_view_presentation_focus_out; widget_class->motion_notify_event = ev_view_presentation_motion_notify_event; widget_class->scroll_event = ev_view_presentation_scroll_event; +#if GTK_CHECK_VERSION (3, 0, 0) + gobject_class->dispose = ev_view_presentation_dispose; +#else gtk_object_class->destroy = ev_view_presentation_destroy; +#endif gobject_class->constructor = ev_view_presentation_constructor; gobject_class->set_property = ev_view_presentation_set_property; |