* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
+#include <stdlib.h>
#include <math.h>
+#include <string.h>
#include <gtk/gtkalignment.h>
#include <glib/gi18n.h>
#include <gtk/gtkbindings.h>
#include <gtk/gtkselection.h>
#include <gtk/gtkclipboard.h>
#include <gdk/gdkkeysyms.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
#include "ev-marshal.h"
#include "ev-view.h"
+#include "ev-view-private.h"
#include "ev-utils.h"
#include "ev-selection.h"
+#include "ev-document-links.h"
+#include "ev-document-images.h"
#include "ev-document-find.h"
+#include "ev-document-transition.h"
#include "ev-document-misc.h"
-#include "ev-debug.h"
#include "ev-job-queue.h"
#include "ev-page-cache.h"
#include "ev-pixbuf-cache.h"
+#include "ev-tooltip.h"
+#include "ev-application.h"
#define EV_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EV_TYPE_VIEW, EvViewClass))
#define EV_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EV_TYPE_VIEW))
#define EV_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EV_TYPE_VIEW, EvViewClass))
+
enum {
PROP_0,
PROP_STATUS,
PROP_PRESENTATION,
PROP_SIZING_MODE,
PROP_ZOOM,
+ PROP_ROTATION,
+ PROP_HAS_SELECTION,
};
enum {
SIGNAL_BINDING_ACTIVATED,
SIGNAL_ZOOM_INVALID,
+ SIGNAL_HANDLE_LINK,
+ SIGNAL_EXTERNAL_LINK,
+ SIGNAL_POPUP_MENU,
N_SIGNALS,
};
+enum {
+ TARGET_DND_URI,
+ TARGET_DND_TEXT,
+ TARGET_DND_IMAGE
+};
+
enum {
TARGET_STRING,
TARGET_TEXT,
TARGET_TEXT_BUFFER_CONTENTS
};
-static const GtkTargetEntry targets[] = {
+static const GtkTargetEntry clipboard_targets[] = {
{ "STRING", 0, TARGET_STRING },
{ "TEXT", 0, TARGET_TEXT },
{ "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT },
{ "UTF8_STRING", 0, TARGET_UTF8_STRING },
};
+static const GtkTargetEntry view_drop_targets[] = {
+ { "text/uri-list", 0, 0 }
+};
+
static guint signals[N_SIGNALS];
typedef enum {
- EV_VIEW_CURSOR_NORMAL,
- EV_VIEW_CURSOR_IBEAM,
- EV_VIEW_CURSOR_LINK,
- EV_VIEW_CURSOR_WAIT,
- EV_VIEW_CURSOR_HIDDEN,
- EV_VIEW_CURSOR_DRAG
-} EvViewCursor;
+ EV_VIEW_FIND_NEXT,
+ EV_VIEW_FIND_PREV
+} EvViewFindDirection;
#define ZOOM_IN_FACTOR 1.2
#define ZOOM_OUT_FACTOR (1.0/ZOOM_IN_FACTOR)
#define MIN_SCALE 0.05409
#define MAX_SCALE 4.0
-/* Information for middle clicking and moving around the doc */
-typedef struct {
- gboolean in_drag;
- GdkPoint start;
- gdouble hadj;
- gdouble vadj;
-} DragInfo;
-
-/* Information for handling selection */
-typedef struct {
- gboolean in_selection;
- GdkPoint start;
- GList *selections;
-} SelectionInfo;
-
-typedef enum {
- SCROLL_TO_KEEP_POSITION,
- SCROLL_TO_CURRENT_PAGE,
- SCROLL_TO_CENTER
-} PendingScroll;
-
-struct _EvView {
- GtkWidget parent_instance;
-
- EvDocument *document;
-
- char *status;
- char *find_status;
-
- /* Scrolling */
- GtkAdjustment *hadjustment;
- GtkAdjustment *vadjustment;
-
- gint scroll_x;
- gint scroll_y;
-
- /* Information for middle clicking and dragging around. */
- DragInfo drag_info;
-
- /* Selection */
- gint motion_x;
- gint motion_y;
- guint selection_update_id;
-
- EvViewSelectionMode selection_mode;
- SelectionInfo selection_info;
-
- int pressed_button;
- EvViewCursor cursor;
-
- EvPageCache *page_cache;
- EvPixbufCache *pixbuf_cache;
-
- gint start_page;
- gint end_page;
- gint current_page;
-
- EvJobRender *current_job;
-
- int find_page;
- int find_result;
- int spacing;
-
- int rotation;
- double scale;
-
- gboolean continuous;
- gboolean dual_page;
- gboolean fullscreen;
- gboolean presentation;
- EvSizingMode sizing_mode;
-
- PendingScroll pending_scroll;
- gboolean pending_resize;
-};
-
-struct _EvViewClass {
- GtkWidgetClass parent_class;
-
- void (*set_scroll_adjustments) (EvView *view,
- GtkAdjustment *hadjustment,
- GtkAdjustment *vadjustment);
- void (*binding_activated) (EvView *view,
- GtkScrollType scroll,
- gboolean horizontal);
- void (*zoom_invalid) (EvView *view);
-};
+#define SCROLL_TIME 150
/*** Scrolling ***/
static void scroll_to_current_page (EvView *view,
static void set_scroll_adjustment (EvView *view,
GtkOrientation orientation,
GtkAdjustment *adjustment);
-static void ev_view_set_scroll_adjustments (EvView *view,
- GtkAdjustment *hadjustment,
- GtkAdjustment *vadjustment);
static void add_scroll_binding_keypad (GtkBindingSet *binding_set,
guint keyval,
- GtkScrollType scroll,
- gboolean horizontal);
-static void ev_view_binding_activated (EvView *view,
- GtkScrollType scroll,
+ GdkModifierType modifiers,
+ EvScrollType scroll,
gboolean horizontal);
static void ensure_rectangle_is_visible (EvView *view,
GdkRectangle *rect);
gint *page,
gint *x_offset,
gint *y_offset);
-static void ev_view_queue_draw_page (EvView *view,
- gint page);
-
+static gboolean doc_point_to_view_point (EvView *view,
+ int page,
+ EvPoint *doc_point,
+ GdkPoint *view_point);
/*** Hyperrefs ***/
-static EvLink* get_link_at_location (EvView *view,
- gdouble x,
- gdouble y);
-static void go_to_link (EvView *view,
- EvLink *link);
-static char* status_message_from_link (EvView *view,
+static EvLink * ev_view_get_link_at_location (EvView *view,
+ gdouble x,
+ gdouble y);
+static char* tip_from_link (EvView *view,
EvLink *link);
-
+static void handle_link_over_xy (EvView *view,
+ gint x,
+ gint y);
/*** GtkWidget implementation ***/
static void ev_view_size_request_continuous_dual_page (EvView *view,
GtkRequisition *requisition);
static void ev_view_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void ev_view_realize (GtkWidget *widget);
-static void ev_view_unrealize (GtkWidget *widget);
static gboolean ev_view_scroll_event (GtkWidget *widget,
GdkEventScroll *event);
static gboolean ev_view_expose_event (GtkWidget *widget,
GdkEventExpose *event);
+static gboolean ev_view_popup_menu (GtkWidget *widget);
static gboolean ev_view_button_press_event (GtkWidget *widget,
GdkEventButton *event);
static gboolean ev_view_motion_notify_event (GtkWidget *widget,
GdkEventMotion *event);
static gboolean ev_view_button_release_event (GtkWidget *widget,
GdkEventButton *event);
+static gboolean ev_view_enter_notify_event (GtkWidget *widget,
+ GdkEventCrossing *event);
static gboolean ev_view_leave_notify_event (GtkWidget *widget,
GdkEventCrossing *event);
static void ev_view_style_set (GtkWidget *widget,
GtkStyle *old_style);
+static AtkObject *ev_view_get_accessible (GtkWidget *widget);
+
/*** Drawing ***/
static guint32 ev_gdk_color_to_rgb (const GdkColor *color);
static void draw_rubberband (GtkWidget *widget,
gint page,
GdkRectangle *page_area,
GtkBorder *border,
+ GdkRectangle *expose_area,
+ gboolean *page_ready);
+static void draw_loading_text (EvView *view,
+ GdkRectangle *page_area,
GdkRectangle *expose_area);
/*** Callbacks ***/
int target_width,
int target_height,
int vsb_width);
+static double zoom_for_size_fit_height (int doc_width,
+ int doc_height,
+ int target_width,
+ int target_height,
+ int vsb_height);
static double zoom_for_size_best_fit (int doc_width,
int doc_height,
int target_width,
/*** Status messages ***/
static void ev_view_set_status (EvView *view,
const char *message);
-static void update_find_status_message (EvView *view);
+static void update_find_status_message (EvView *view,
+ gboolean this_page);
static void ev_view_set_find_status (EvView *view,
const char *message);
/*** Find ***/
static void jump_to_find_result (EvView *view);
-static void jump_to_find_page (EvView *view);
+static void jump_to_find_page (EvView *view,
+ EvViewFindDirection direction,
+ gint shift);
/*** Selection ***/
static void compute_selections (EvView *view,
gpointer data);
static void ev_view_update_primary_selection (EvView *ev_view);
+/*** Presentation ***/
+static void ev_view_presentation_transition_start (EvView *ev_view);
+static void ev_view_presentation_transition_stop (EvView *ev_view);
+
G_DEFINE_TYPE (EvView, ev_view, GTK_TYPE_WIDGET)
static void
scroll_to_current_page (EvView *view, GtkOrientation orientation)
{
- GdkRectangle page_area;
- GtkBorder border;
+ GdkPoint view_point;
if (view->document == NULL) {
return;
}
- get_page_extents (view, view->current_page, &page_area, &border);
+ doc_point_to_view_point (view, view->current_page, &view->pending_point, &view_point);
+
+ if (orientation == GTK_ORIENTATION_VERTICAL) {
+ view->pending_point.y = 0;
+ } else {
+ view->pending_point.x = 0;
+ }
if (orientation == GTK_ORIENTATION_VERTICAL) {
if (view->continuous) {
gtk_adjustment_clamp_page (view->vadjustment,
- page_area.y - view->spacing,
- page_area.y + view->vadjustment->page_size);
+ view_point.y - view->spacing / 2,
+ view_point.y + view->vadjustment->page_size);
} else {
gtk_adjustment_set_value (view->vadjustment,
- view->vadjustment->lower);
+ CLAMP (view_point.y,
+ view->vadjustment->lower,
+ view->vadjustment->upper -
+ view->vadjustment->page_size));
}
} else {
if (view->dual_page) {
gtk_adjustment_clamp_page (view->hadjustment,
- page_area.x,
- page_area.x + view->hadjustment->page_size);
+ view_point.x,
+ view_point.x + view->hadjustment->page_size);
} else {
gtk_adjustment_set_value (view->hadjustment,
- CLAMP (view->hadjustment->value,
+ CLAMP (view_point.x,
view->hadjustment->lower,
view->hadjustment->upper -
view->hadjustment->page_size));
factor = 1.0;
switch (view->pending_scroll) {
case SCROLL_TO_KEEP_POSITION:
+ case SCROLL_TO_FIND_LOCATION:
factor = (adjustment->value) / adjustment->upper;
break;
- case SCROLL_TO_CURRENT_PAGE:
+ case SCROLL_TO_PAGE_POSITION:
break;
case SCROLL_TO_CENTER:
factor = (adjustment->value + adjustment->page_size * 0.5) / adjustment->upper;
*/
switch (view->pending_scroll) {
case SCROLL_TO_KEEP_POSITION:
+ case SCROLL_TO_FIND_LOCATION:
new_value = CLAMP (adjustment->upper * factor + 0.5, 0, adjustment->upper - adjustment->page_size);
gtk_adjustment_set_value (adjustment, (int)new_value);
break;
- case SCROLL_TO_CURRENT_PAGE:
+ case SCROLL_TO_PAGE_POSITION:
scroll_to_current_page (view, orientation);
break;
case SCROLL_TO_CENTER:
static void
view_update_range_and_current_page (EvView *view)
{
+ gint current_page;
+ gint best_current_page = -1;
+
/* Presentation trumps all other modes */
if (view->presentation) {
view->start_page = view->current_page;
} else if (view->continuous) {
GdkRectangle current_area, unused, page_area;
GtkBorder border;
- gint current_page;
gboolean found = FALSE;
+ gint area_max = -1, area;
int i;
if (!(view->vadjustment && view->hadjustment))
get_page_extents (view, i, &page_area, &border);
if (gdk_rectangle_intersect (¤t_area, &page_area, &unused)) {
- if (! found) {
+ area = unused.width * unused.height;
+
+ if (!found) {
+ area_max = area;
view->start_page = i;
found = TRUE;
-
+ best_current_page = i;
+ }
+ if (area > area_max) {
+ best_current_page = (area == area_max) ? MIN (i, best_current_page) : i;
+ area_max = area;
}
+
view->end_page = i;
} else if (found) {
break;
}
}
- current_page = ev_page_cache_get_current_page (view->page_cache);
-
- if (current_page < view->start_page || current_page > view->end_page) {
- view->current_page = view->start_page;
- ev_page_cache_set_current_page (view->page_cache, view->start_page);
- }
- } else {
- if (view->dual_page) {
- if (view->current_page % 2 == 0) {
+ } else if (view->dual_page) {
+ if (view->current_page % 2 == ev_page_cache_get_dual_even_left (view->page_cache)) {
+ view->start_page = view->current_page;
+ if (view->current_page + 1 < ev_page_cache_get_n_pages (view->page_cache))
+ view->end_page = view->start_page + 1;
+ else
+ view->end_page = view->start_page;
+ } else {
+ if (view->current_page < 1)
view->start_page = view->current_page;
- if (view->current_page + 1 < ev_page_cache_get_n_pages (view->page_cache))
- view->end_page = view->start_page + 1;
- } else {
+ else
view->start_page = view->current_page - 1;
- view->end_page = view->current_page;
- }
- } else {
- view->start_page = view->current_page;
view->end_page = view->current_page;
}
+ } else {
+ view->start_page = view->current_page;
+ view->end_page = view->current_page;
+ }
+
+ best_current_page = MAX (best_current_page, view->start_page);
+ current_page = ev_page_cache_get_current_page (view->page_cache);
+
+ if ((current_page != best_current_page) && (view->pending_scroll == SCROLL_TO_KEEP_POSITION)) {
+ view->current_page = best_current_page;
+ ev_page_cache_set_current_page (view->page_cache, best_current_page);
}
ev_pixbuf_cache_set_page_range (view->pixbuf_cache,
static void
add_scroll_binding_keypad (GtkBindingSet *binding_set,
guint keyval,
- GtkScrollType scroll,
+ GdkModifierType modifiers,
+ EvScrollType scroll,
gboolean horizontal)
{
guint keypad_keyval = keyval - GDK_Left + GDK_KP_Left;
- gtk_binding_entry_add_signal (binding_set, keyval, 0,
+ gtk_binding_entry_add_signal (binding_set, keyval, modifiers,
"binding_activated", 2,
- GTK_TYPE_SCROLL_TYPE, scroll,
+ EV_TYPE_SCROLL_TYPE, scroll,
G_TYPE_BOOLEAN, horizontal);
- gtk_binding_entry_add_signal (binding_set, keypad_keyval, 0,
+ gtk_binding_entry_add_signal (binding_set, keypad_keyval, modifiers,
"binding_activated", 2,
- GTK_TYPE_SCROLL_TYPE, scroll,
+ EV_TYPE_SCROLL_TYPE, scroll,
G_TYPE_BOOLEAN, horizontal);
}
void
ev_view_scroll (EvView *view,
- EvScrollType scroll)
+ EvScrollType scroll,
+ gboolean horizontal)
{
GtkAdjustment *adjustment;
double value, increment;
gboolean first_page = FALSE;
gboolean last_page = FALSE;
+ view->jump_to_find_result = FALSE;
+
+ if (view->presentation || view->sizing_mode == EV_SIZING_BEST_FIT) {
+ switch (scroll) {
+ case EV_SCROLL_PAGE_BACKWARD:
+ case EV_SCROLL_STEP_BACKWARD:
+ ev_view_previous_page (view);
+ break;
+ case EV_SCROLL_PAGE_FORWARD:
+ case EV_SCROLL_STEP_FORWARD:
+ ev_view_next_page (view);
+ break;
+ default:
+ break;
+ }
+ return;
+ }
+
/* Assign values for increment and vertical adjustment */
- adjustment = view->vadjustment;
+ adjustment = horizontal ? view->hadjustment : view->vadjustment;
increment = adjustment->page_size * 0.75;
value = adjustment->value;
/* At the top of a page, assign the upper bound limit of previous page */
} else if (value == (adjustment->lower)) {
value = adjustment->upper - adjustment->page_size;
- ev_page_cache_set_current_page (view->page_cache, view->current_page - 1);
+ ev_view_previous_page (view);
/* Jump to the top */
} else {
value = MAX (value - increment, adjustment->lower);
/* At the bottom of a page, assign the lower bound limit of next page */
} else if (value == (adjustment->upper - adjustment->page_size)) {
value = 0;
- ev_page_cache_set_current_page (view->page_cache, view->current_page + 1);
+ ev_view_next_page (view);
/* Jump to the bottom */
} else {
value = MIN (value + increment, adjustment->upper - adjustment->page_size);
}
break;
- default:
- break;
- }
-
- gtk_adjustment_set_value (adjustment, value);
-}
-
-static void
-ev_view_binding_activated (EvView *view,
- GtkScrollType scroll,
- gboolean horizontal)
-{
- GtkAdjustment *adjustment;
- double value;
-
- if (view->presentation) {
- switch (scroll) {
- case GTK_SCROLL_STEP_BACKWARD:
- ev_page_cache_prev_page (view->page_cache);
- break;
- case GTK_SCROLL_STEP_FORWARD:
- ev_page_cache_next_page (view->page_cache);
- break;
- default:
- break;
- }
- return;
- }
-
- if (horizontal) {
- adjustment = view->hadjustment;
- } else {
- adjustment = view->vadjustment;
- }
-
- value = adjustment->value;
-
- switch (scroll) {
- case GTK_SCROLL_STEP_BACKWARD:
+ case EV_SCROLL_STEP_BACKWARD:
value -= adjustment->step_increment;
break;
- case GTK_SCROLL_STEP_FORWARD:
+ case EV_SCROLL_STEP_FORWARD:
value += adjustment->step_increment;
break;
- default:
+ case EV_SCROLL_STEP_DOWN:
+ value -= adjustment->step_increment / 10;
+ break;
+ case EV_SCROLL_STEP_UP:
+ value += adjustment->step_increment / 10;
+ break;
+ default:
break;
}
value = CLAMP (value, adjustment->lower,
- adjustment->upper - adjustment->page_size);
+ adjustment->upper - adjustment->page_size);
gtk_adjustment_set_value (adjustment, value);
}
GtkAdjustment *adjustment;
int value;
- view->pending_scroll = SCROLL_TO_KEEP_POSITION;
+ view->pending_scroll = SCROLL_TO_FIND_LOCATION;
adjustment = view->vadjustment;
widget->allocation.width + MARGIN);
gtk_adjustment_set_value (view->hadjustment, value);
}
+
+ gtk_widget_queue_resize (GTK_WIDGET (view));
}
/*** Geometry computations ***/
if (view->dual_page) {
ev_page_cache_get_height_to_page (view->page_cache, page,
view->rotation, zoom, NULL, &offset);
- offset += (page / 2 + 1) * view->spacing + (page / 2) * (border.top + border.bottom);
+ offset += ((page + ev_page_cache_get_dual_even_left (view->page_cache)) / 2 + 1) * view->spacing + ((page + ev_page_cache_get_dual_even_left (view->page_cache)) / 2 ) * (border.top + border.bottom);
} else {
ev_page_cache_get_height_to_page (view->page_cache, page,
view->rotation, zoom, &offset, NULL);
gint max_width;
gint x, y;
- ev_page_cache_get_max_width (view->page_cache, view->scale,
- view->rotation, &max_width);
+ ev_page_cache_get_max_width (view->page_cache, view->rotation,
+ view->scale, &max_width);
max_width = max_width + border->left + border->right;
/* Get the location of the bounding box */
if (view->dual_page) {
- x = view->spacing + (page % 2) * (max_width + view->spacing);
+ x = view->spacing + ((page % 2 == ev_page_cache_get_dual_even_left (view->page_cache)) ? 0 : 1) * (max_width + view->spacing);
x = x + MAX (0, widget->allocation.width - (max_width * 2 + view->spacing * 3)) / 2;
- if (page % 2 == 0)
+ if (page % 2 == ev_page_cache_get_dual_even_left (view->page_cache))
x = x + (max_width - width - border->left - border->right);
} else {
x = view->spacing;
GtkBorder overall_border;
gint other_page;
- other_page = page ^ 1;
+ other_page = (page % 2 == ev_page_cache_get_dual_even_left (view->page_cache)) ? page + 1: page - 1;
/* First, we get the bounding box of the two pages */
- if (other_page < ev_page_cache_get_n_pages (view->page_cache)) {
+ if (other_page < ev_page_cache_get_n_pages (view->page_cache)
+ && (0 <= other_page)) {
ev_page_cache_get_size (view->page_cache,
other_page,
view->rotation,
y = view->spacing;
/* Adjust for being the left or right page */
- if (page % 2 == 0)
+ if (page % 2 == ev_page_cache_get_dual_even_left (view->page_cache))
x = x + max_width - width;
else
x = x + (max_width + overall_border.left + overall_border.right) + view->spacing;
doc_rect->y2 = doc_rect->y1 + (double) view_rect->height / view->scale;
}
+static gboolean
+doc_point_to_view_point (EvView *view,
+ int page,
+ EvPoint *doc_point,
+ GdkPoint *view_point)
+{
+ GdkRectangle page_area;
+ GtkBorder border;
+ double x, y, view_x, view_y;
+ int width, height;
+
+ ev_page_cache_get_size (view->page_cache, page,
+ view->rotation,
+ 1.0,
+ &width, &height);
+
+ if (view->rotation == 0) {
+ x = doc_point->x;
+ y = doc_point->y;
+ } else if (view->rotation == 90) {
+ x = width - doc_point->y;
+ y = doc_point->x;
+ } else if (view->rotation == 180) {
+ x = width - doc_point->x;
+ y = height - doc_point->y;
+ } else if (view->rotation == 270) {
+ x = doc_point->y;
+ y = height - doc_point->x;
+ } else {
+ g_assert_not_reached ();
+ }
+
+ get_page_extents (view, page, &page_area, &border);
+
+ view_x = x * view->scale;
+ view_y = y * view->scale;
+ view_point->x = view_x + page_area.x;
+ view_point->y = view_y + page_area.y;
+
+ return (view_x > 0 && view_x <= page_area.width &&
+ view_y > 0 && view_y <= page_area.height);
+}
+
static void
doc_rect_to_view_rect (EvView *view,
int page,
*page = -1;
}
-static void
-ev_view_queue_draw_page (EvView *view,
- gint page)
-{
- /* FIXME: write */
- gtk_widget_queue_draw (GTK_WIDGET (view));
-}
-
static gboolean
location_in_text (EvView *view,
gdouble x,
return FALSE;
}
+static int
+ev_view_get_width (EvView *view)
+{
+ return GTK_WIDGET (view)->allocation.width;
+}
+
+static int
+ev_view_get_height (EvView *view)
+{
+ return GTK_WIDGET (view)->allocation.height;
+}
+
+static gboolean
+location_in_selected_text (EvView *view,
+ gdouble x,
+ gdouble y)
+{
+ gint page = -1;
+ gint x_offset = 0, y_offset = 0;
+ EvViewSelection *selection;
+ GList *l = NULL;
+
+ for (l = view->selection_info.selections; l != NULL; l = l->next) {
+ selection = (EvViewSelection *)l->data;
+
+ find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
+
+ if (page != selection->page)
+ continue;
+
+ if (selection->covered_region &&
+ gdk_region_point_in (selection->covered_region, x_offset, y_offset))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+get_doc_point_from_offset (EvView *view,
+ gint page,
+ gint x_offset,
+ gint y_offset,
+ gint *x_new,
+ gint *y_new)
+{
+ int width, height;
+ double x, y;
+
+ ev_page_cache_get_size (view->page_cache, page,
+ view->rotation,
+ 1.0,
+ &width, &height);
+
+ x_offset = x_offset / view->scale;
+ y_offset = y_offset / view->scale;
+
+ if (view->rotation == 0) {
+ x = x_offset;
+ y = y_offset;
+ } else if (view->rotation == 90) {
+ x = y_offset;
+ y = width - x_offset;
+ } else if (view->rotation == 180) {
+ x = width - x_offset;
+ y = height - y_offset;
+ } else if (view->rotation == 270) {
+ x = height - y_offset;
+ y = x_offset;
+ } else {
+ g_assert_not_reached ();
+ }
+
+ *x_new = x;
+ *y_new = y;
+
+ return TRUE;
+}
+
/*** Hyperref ***/
static EvLink *
-get_link_at_location (EvView *view,
- gdouble x,
- gdouble y)
+ev_view_get_link_at_location (EvView *view,
+ gdouble x,
+ gdouble y)
{
gint page = -1;
gint x_offset = 0, y_offset = 0;
+ gint x_new = 0, y_new = 0;
GList *link_mapping;
+ if (!EV_IS_DOCUMENT_LINKS (view->document))
+ return NULL;
+
+ x += view->scroll_x;
+ y += view->scroll_y;
+
find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
if (page == -1)
return NULL;
+
+ if (get_doc_point_from_offset (view, page, x_offset,
+ y_offset, &x_new, &y_new) == FALSE)
+ return NULL;
+
link_mapping = ev_pixbuf_cache_get_link_mapping (view->pixbuf_cache, page);
if (link_mapping)
- return ev_link_mapping_find (link_mapping, x_offset / view->scale, y_offset / view->scale);
+ return ev_link_mapping_find (link_mapping, x_new, y_new);
else
return NULL;
}
-/* FIXME: standardize this sometime */
static void
-go_to_link (EvView *view, EvLink *link)
+goto_fitr_dest (EvView *view, EvLinkDest *dest)
{
- EvLinkType type;
- const char *uri;
- int page;
+ EvPoint doc_point;
+ double zoom;
- type = ev_link_get_link_type (link);
+ zoom = zoom_for_size_best_fit (ev_link_dest_get_right (dest) - ev_link_dest_get_left (dest),
+ ev_link_dest_get_bottom (dest) - ev_link_dest_get_top (dest),
+ ev_view_get_width (view),
+ ev_view_get_height (view), 0, 0);
- switch (type) {
- case EV_LINK_TYPE_TITLE:
- break;
- case EV_LINK_TYPE_PAGE:
- page = ev_link_get_page (link);
- ev_page_cache_set_current_page (view->page_cache, page);
- break;
- case EV_LINK_TYPE_EXTERNAL_URI:
- uri = ev_link_get_uri (link);
- gnome_vfs_url_show (uri);
- break;
- }
+ ev_view_set_sizing_mode (view, EV_SIZING_FREE);
+ ev_view_set_zoom (view, zoom, FALSE);
+
+ doc_point.x = ev_link_dest_get_left (dest);
+ doc_point.y = ev_link_dest_get_top (dest);
+
+ view->current_page = ev_link_dest_get_page (dest);
+ view->pending_point = doc_point;
+ view->pending_scroll = SCROLL_TO_PAGE_POSITION;
+
+ gtk_widget_queue_resize (GTK_WIDGET (view));
}
-static char *
-status_message_from_link (EvView *view, EvLink *link)
+static void
+goto_fitv_dest (EvView *view, EvLinkDest *dest)
{
- EvLinkType type;
- char *msg = NULL;
- char *page_label;
+ EvPoint doc_point;
+ int doc_width, doc_height, page;
+ double zoom;
- type = ev_link_get_link_type (link);
+ page = ev_link_dest_get_page (dest);
+ ev_page_cache_get_size (view->page_cache, page, 0, 1.0, &doc_width, &doc_height);
- switch (type) {
- case EV_LINK_TYPE_TITLE:
- if (ev_link_get_title (link))
- msg = g_strdup (ev_link_get_title (link));
- break;
- case EV_LINK_TYPE_PAGE:
- page_label = ev_page_cache_get_page_label (view->page_cache, ev_link_get_page (link));
- msg = g_strdup_printf (_("Go to page %s"), page_label);
- g_free (page_label);
- break;
- case EV_LINK_TYPE_EXTERNAL_URI:
- msg = g_strdup (ev_link_get_uri (link));
- break;
- default:
- break;
- }
+ doc_point.x = ev_link_dest_get_left (dest);
+ doc_point.y = 0;
- return msg;
-}
+ zoom = zoom_for_size_fit_height (doc_width - doc_point.x , doc_height,
+ ev_view_get_width (view),
+ ev_view_get_height (view), 0);
+ ev_view_set_sizing_mode (view, EV_SIZING_FREE);
+ ev_view_set_zoom (view, zoom, FALSE);
-/*** GtkWidget implementation ***/
+ view->current_page = page;
+ view->pending_point = doc_point;
+ view->pending_scroll = SCROLL_TO_PAGE_POSITION;
+
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+}
static void
-ev_view_size_request_continuous_dual_page (EvView *view,
- GtkRequisition *requisition)
+goto_fith_dest (EvView *view, EvLinkDest *dest)
{
- int max_width;
- gint n_pages;
- GtkBorder border;
+ EvPoint doc_point;
+ int doc_width, doc_height, page;
+ double zoom;
- ev_page_cache_get_max_width (view->page_cache, view->rotation,
- view->scale, &max_width);
- compute_border (view, max_width, max_width, &border);
+ page = ev_link_dest_get_page (dest);
+ ev_page_cache_get_size (view->page_cache, page, 0, 1.0, &doc_width, &doc_height);
- n_pages = ev_page_cache_get_n_pages (view->page_cache) + 1;
+ doc_point.x = 0;
+ doc_point.y = ev_link_dest_get_top (dest);
- requisition->width = (max_width + border.left + border.right) * 2 + (view->spacing * 3);
- get_page_y_offset (view, n_pages, view->scale, &requisition->height);
+ zoom = zoom_for_size_fit_width (doc_width, ev_link_dest_get_top (dest),
+ ev_view_get_width (view),
+ ev_view_get_height (view), 0);
- if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
- requisition->width = 1;
- } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
- requisition->width = 1;
- /* FIXME: This could actually be set on one page docs or docs
- * with a strange aspect ratio. */
- /* requisition->height = 1;*/
- }
+ ev_view_set_sizing_mode (view, EV_SIZING_FIT_WIDTH);
+ ev_view_set_zoom (view, zoom, FALSE);
+
+ view->current_page = page;
+ view->pending_point = doc_point;
+ view->pending_scroll = SCROLL_TO_PAGE_POSITION;
+
+ gtk_widget_queue_resize (GTK_WIDGET (view));
}
static void
-ev_view_size_request_continuous (EvView *view,
- GtkRequisition *requisition)
+goto_fit_dest (EvView *view, EvLinkDest *dest)
{
- int max_width;
- int n_pages;
- GtkBorder border;
+ double zoom;
+ int doc_width, doc_height;
+ int page;
+ page = ev_link_dest_get_page (dest);
+ ev_page_cache_get_size (view->page_cache, page, 0, 1.0, &doc_width, &doc_height);
- ev_page_cache_get_max_width (view->page_cache, view->rotation,
- view->scale, &max_width);
- n_pages = ev_page_cache_get_n_pages (view->page_cache);
- compute_border (view, max_width, max_width, &border);
+ zoom = zoom_for_size_best_fit (doc_width, doc_height, ev_view_get_width (view),
+ ev_view_get_height (view), 0, 0);
- requisition->width = max_width + (view->spacing * 2) + border.left + border.right;
- get_page_y_offset (view, n_pages, view->scale, &requisition->height);
+ ev_view_set_sizing_mode (view, EV_SIZING_BEST_FIT);
+ ev_view_set_zoom (view, zoom, FALSE);
- if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
- requisition->width = 1;
- } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
- requisition->width = 1;
- /* FIXME: This could actually be set on one page docs or docs
- * with a strange aspect ratio. */
- /* requisition->height = 1;*/
- }
+ view->current_page = page;
+ view->pending_scroll = SCROLL_TO_PAGE_POSITION;
+
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+}
+
+static void
+goto_xyz_dest (EvView *view, EvLinkDest *dest)
+{
+ EvPoint doc_point;
+ gint page;
+ double zoom;
+
+ zoom = ev_link_dest_get_zoom (dest);
+ page = ev_link_dest_get_page (dest);
+
+ if (zoom > 1) {
+ ev_view_set_sizing_mode (view, EV_SIZING_FREE);
+ ev_view_set_zoom (view, zoom, FALSE);
+ }
+
+ doc_point.x = ev_link_dest_get_left (dest);
+ doc_point.y = ev_link_dest_get_top (dest);
+
+ view->current_page = page;
+ view->pending_point = doc_point;
+ view->pending_scroll = SCROLL_TO_PAGE_POSITION;
+
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+}
+
+static void
+goto_dest (EvView *view, EvLinkDest *dest)
+{
+ EvLinkDestType type;
+ int page, n_pages, current_page;
+
+ page = ev_link_dest_get_page (dest);
+ n_pages = ev_page_cache_get_n_pages (view->page_cache);
+
+ if (page < 0 || page >= n_pages)
+ return;
+
+ current_page = view->current_page;
+
+ type = ev_link_dest_get_dest_type (dest);
+
+ switch (type) {
+ case EV_LINK_DEST_TYPE_PAGE:
+ ev_page_cache_set_current_page (view->page_cache, page);
+ break;
+ case EV_LINK_DEST_TYPE_FIT:
+ goto_fit_dest (view, dest);
+ break;
+ case EV_LINK_DEST_TYPE_FITH:
+ goto_fith_dest (view, dest);
+ break;
+ case EV_LINK_DEST_TYPE_FITV:
+ goto_fitv_dest (view, dest);
+ break;
+ case EV_LINK_DEST_TYPE_FITR:
+ goto_fitr_dest (view, dest);
+ break;
+ case EV_LINK_DEST_TYPE_XYZ:
+ goto_xyz_dest (view, dest);
+ break;
+ case EV_LINK_DEST_TYPE_PAGE_LABEL:
+ ev_page_cache_set_page_label (view->page_cache, ev_link_dest_get_page_label (dest));
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ if (current_page != view->current_page)
+ ev_page_cache_set_current_page (view->page_cache,
+ view->current_page);
+}
+
+static void
+ev_view_goto_dest (EvView *view, EvLinkDest *dest)
+{
+ EvLinkDestType type;
+
+ type = ev_link_dest_get_dest_type (dest);
+
+ if (type == EV_LINK_DEST_TYPE_NAMED) {
+ EvLinkDest *dest2;
+ const gchar *named_dest;
+
+ named_dest = ev_link_dest_get_named_dest (dest);
+ dest2 = ev_document_links_find_link_dest (EV_DOCUMENT_LINKS (view->document),
+ named_dest);
+ if (dest2) {
+ goto_dest (view, dest2);
+ g_object_unref (dest2);
+ }
+
+ return;
+ }
+
+ goto_dest (view, dest);
+}
+
+void
+ev_view_handle_link (EvView *view, EvLink *link)
+{
+ EvLinkAction *action = NULL;
+ EvLinkActionType type;
+
+ action = ev_link_get_action (link);
+ if (!action)
+ return;
+
+ type = ev_link_action_get_action_type (action);
+
+ switch (type) {
+ case EV_LINK_ACTION_TYPE_GOTO_DEST: {
+ EvLinkDest *dest;
+
+ g_signal_emit (view, signals[SIGNAL_HANDLE_LINK], 0, link);
+
+ dest = ev_link_action_get_dest (action);
+ ev_view_goto_dest (view, dest);
+ }
+ break;
+ case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
+ case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
+ case EV_LINK_ACTION_TYPE_LAUNCH:
+ case EV_LINK_ACTION_TYPE_NAMED:
+ g_signal_emit (view, signals[SIGNAL_EXTERNAL_LINK], 0, action);
+ break;
+ }
+}
+
+gchar *
+ev_view_page_label_from_dest (EvView *view, EvLinkDest *dest)
+{
+ EvLinkDestType type;
+ gchar *msg = NULL;
+
+ type = ev_link_dest_get_dest_type (dest);
+
+ switch (type) {
+ case EV_LINK_DEST_TYPE_NAMED: {
+ EvLinkDest *dest2;
+ const gchar *named_dest;
+
+ named_dest = ev_link_dest_get_named_dest (dest);
+ dest2 = ev_document_links_find_link_dest (EV_DOCUMENT_LINKS (view->document),
+ named_dest);
+ if (dest2) {
+ msg = ev_page_cache_get_page_label (view->page_cache,
+ ev_link_dest_get_page (dest2));
+ g_object_unref (dest2);
+ }
+ }
+
+ break;
+ case EV_LINK_DEST_TYPE_PAGE_LABEL: {
+ msg = g_strdup (ev_link_dest_get_page_label (dest));
+ }
+ break;
+ default:
+ msg = ev_page_cache_get_page_label (view->page_cache,
+ ev_link_dest_get_page (dest));
+ }
+
+ return msg;
+}
+
+static char *
+tip_from_action_named (EvLinkAction *action)
+{
+ const gchar *name = ev_link_action_get_name (action);
+
+ if (g_ascii_strcasecmp (name, "FirstPage") == 0) {
+ return g_strdup (_("Go to first page"));
+ } else if (g_ascii_strcasecmp (name, "PrevPage") == 0) {
+ return g_strdup (_("Go to previous page"));
+ } else if (g_ascii_strcasecmp (name, "NextPage") == 0) {
+ return g_strdup (_("Go to next page"));
+ } else if (g_ascii_strcasecmp (name, "LastPage") == 0) {
+ return g_strdup (_("Go to last page"));
+ } else if (g_ascii_strcasecmp (name, "GoToPage") == 0) {
+ return g_strdup (_("Go to page"));
+ } else if (g_ascii_strcasecmp (name, "Find") == 0) {
+ return g_strdup (_("Find"));
+ }
+
+ return NULL;
+}
+
+static char *
+tip_from_link (EvView *view, EvLink *link)
+{
+ EvLinkAction *action;
+ EvLinkActionType type;
+ char *msg = NULL;
+ char *page_label;
+ const char *title;
+
+ action = ev_link_get_action (link);
+ title = ev_link_get_title (link);
+
+ if (!action)
+ return title ? g_strdup (title) : NULL;
+
+ type = ev_link_action_get_action_type (action);
+
+ switch (type) {
+ case EV_LINK_ACTION_TYPE_GOTO_DEST:
+ page_label = ev_view_page_label_from_dest (view,
+ ev_link_action_get_dest (action));
+ msg = g_strdup_printf (_("Go to page %s"), page_label);
+ g_free (page_label);
+ break;
+ case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
+ if (title) {
+ msg = g_strdup_printf (_("Go to %s on file “%s”"), title,
+ ev_link_action_get_filename (action));
+ } else {
+ msg = g_strdup_printf (_("Go to file “%s”"),
+ ev_link_action_get_filename (action));
+ }
+
+ break;
+ case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
+ msg = g_strdup (ev_link_action_get_uri (action));
+ break;
+ case EV_LINK_ACTION_TYPE_LAUNCH:
+ msg = g_strdup_printf (_("Launch %s"),
+ ev_link_action_get_filename (action));
+ break;
+ case EV_LINK_ACTION_TYPE_NAMED:
+ msg = tip_from_action_named (action);
+ break;
+ default:
+ if (title)
+ msg = g_strdup (title);
+ break;
+ }
+
+ return msg;
+}
+
+static void
+handle_link_over_xy (EvView *view, gint x, gint y)
+{
+ EvLink *link;
+
+ link = ev_view_get_link_at_location (view, x, y);
+
+ if (view->link_tooltip == NULL) {
+ view->link_tooltip = ev_tooltip_new (GTK_WIDGET (view));
+ }
+
+ if (view->hovered_link != link) {
+ view->hovered_link = link;
+ ev_tooltip_deactivate (EV_TOOLTIP (view->link_tooltip));
+ }
+
+ if (link) {
+ char *msg = tip_from_link (view, link);
+
+ if (msg && g_utf8_validate (msg, -1, NULL)) {
+ EvTooltip *tooltip = EV_TOOLTIP (view->link_tooltip);
+
+ ev_tooltip_set_position (tooltip, x, y);
+ ev_tooltip_set_text (tooltip, msg);
+ ev_tooltip_activate (tooltip);
+ }
+ g_free (msg);
+
+ ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);
+ } else if (location_in_text (view, x + view->scroll_x, y + view->scroll_y)) {
+ ev_view_set_cursor (view, EV_VIEW_CURSOR_IBEAM);
+ } else {
+ ev_view_set_status (view, NULL);
+ if (view->cursor == EV_VIEW_CURSOR_LINK ||
+ view->cursor == EV_VIEW_CURSOR_IBEAM)
+ ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
+ }
+ return;
+}
+
+/*** Images ***/
+static EvImage *
+ev_view_get_image_at_location (EvView *view,
+ gdouble x,
+ gdouble y)
+{
+ gint page = -1;
+ gint x_offset = 0, y_offset = 0;
+ gint x_new = 0, y_new = 0;
+ GList *image_mapping;
+
+ if (!EV_IS_DOCUMENT_IMAGES (view->document))
+ return NULL;
+
+ x += view->scroll_x;
+ y += view->scroll_y;
+
+ find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
+
+ if (page == -1)
+ return NULL;
+
+ if (get_doc_point_from_offset (view, page, x_offset,
+ y_offset, &x_new, &y_new) == FALSE)
+ return NULL;
+
+ image_mapping = ev_pixbuf_cache_get_image_mapping (view->pixbuf_cache, page);
+
+ if (image_mapping)
+ return ev_image_mapping_find (image_mapping, x_new, y_new);
+ else
+ return NULL;
+}
+
+/*** GtkWidget implementation ***/
+
+static void
+ev_view_size_request_continuous_dual_page (EvView *view,
+ GtkRequisition *requisition)
+{
+ int max_width;
+ gint n_pages;
+ GtkBorder border;
+
+ ev_page_cache_get_max_width (view->page_cache, view->rotation,
+ view->scale, &max_width);
+ compute_border (view, max_width, max_width, &border);
+
+ n_pages = ev_page_cache_get_n_pages (view->page_cache) + 1;
+
+ requisition->width = (max_width + border.left + border.right) * 2 + (view->spacing * 3);
+ get_page_y_offset (view, n_pages, view->scale, &requisition->height);
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ requisition->width = 1;
+ } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
+ requisition->width = 1;
+ /* FIXME: This could actually be set on one page docs or docs
+ * with a strange aspect ratio. */
+ /* requisition->height = 1;*/
+ }
+}
+
+static void
+ev_view_size_request_continuous (EvView *view,
+ GtkRequisition *requisition)
+{
+ int max_width;
+ int n_pages;
+ GtkBorder border;
+
+
+ ev_page_cache_get_max_width (view->page_cache, view->rotation,
+ view->scale, &max_width);
+ n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ compute_border (view, max_width, max_width, &border);
+
+ requisition->width = max_width + (view->spacing * 2) + border.left + border.right;
+ get_page_y_offset (view, n_pages, view->scale, &requisition->height);
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ requisition->width = 1;
+ } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
+ requisition->width = 1;
+ /* FIXME: This could actually be set on one page docs or docs
+ * with a strange aspect ratio. */
+ /* requisition->height = 1;*/
+ }
}
static void
{
EvView *view = EV_VIEW (widget);
+ GTK_WIDGET_CLASS (ev_view_parent_class)->size_allocate (widget, allocation);
+
if (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
- view->sizing_mode == EV_SIZING_BEST_FIT) {
+ view->sizing_mode == EV_SIZING_BEST_FIT) {
g_signal_emit (view, signals[SIGNAL_ZOOM_INVALID], 0);
view_set_adjustment_values (view, GTK_ORIENTATION_HORIZONTAL);
view_set_adjustment_values (view, GTK_ORIENTATION_VERTICAL);
- view->pending_scroll = SCROLL_TO_KEEP_POSITION;
- view->pending_resize = FALSE;
-
if (view->document)
view_update_range_and_current_page (view);
- GTK_WIDGET_CLASS (ev_view_parent_class)->size_allocate (widget, allocation);
+ view->pending_scroll = SCROLL_TO_KEEP_POSITION;
+ view->pending_resize = FALSE;
}
static void
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
-
attributes.window_type = GDK_WINDOW_CHILD;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
GDK_SCROLL_MASK |
GDK_KEY_PRESS_MASK |
GDK_POINTER_MOTION_MASK |
+ GDK_POINTER_MOTION_HINT_MASK |
+ GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK;
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
gdk_window_set_background (widget->window, &widget->style->mid [GTK_STATE_NORMAL]);
}
-static void
-ev_view_unrealize (GtkWidget *widget)
-{
- GTK_WIDGET_CLASS (ev_view_parent_class)->unrealize (widget);
-}
-
static gboolean
ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event)
{
- EvView *view = EV_VIEW (widget);
+ EvView *view = EV_VIEW (widget);
+ guint state;
+
+ state = event->state & gtk_accelerator_get_default_mod_mask ();
- if ((event->state & GDK_CONTROL_MASK) != 0) {
+ if (state == GDK_CONTROL_MASK && view->presentation == FALSE) {
+ ev_view_set_sizing_mode (view, EV_SIZING_FREE);
- ev_view_set_sizing_mode (view, EV_SIZING_FREE);
+ if (event->direction == GDK_SCROLL_UP ||
+ event->direction == GDK_SCROLL_LEFT) {
+ if (ev_view_can_zoom_in (view)) {
+ ev_view_zoom_in (view);
+ }
+ } else {
+ if (ev_view_can_zoom_out (view)) {
+ ev_view_zoom_out (view);
+ }
+ }
- if (event->direction == GDK_SCROLL_UP ||
- event->direction == GDK_SCROLL_LEFT) {
- if (ev_view_can_zoom_in (view)) {
- ev_view_zoom_in (view);
- }
- } else {
- if (ev_view_can_zoom_out (view)) {
- ev_view_zoom_out (view);
- }
- }
- return TRUE;
+ return TRUE;
}
- if ((event->state & GDK_SHIFT_MASK) != 0) {
+ view->jump_to_find_result = FALSE;
+ /* Shift+Wheel scrolls the in the perpendicular direction */
+ if (state & GDK_SHIFT_MASK) {
if (event->direction == GDK_SCROLL_UP)
event->direction = GDK_SCROLL_LEFT;
+ if (event->direction == GDK_SCROLL_LEFT)
+ event->direction = GDK_SCROLL_UP;
if (event->direction == GDK_SCROLL_DOWN)
event->direction = GDK_SCROLL_RIGHT;
+ if (event->direction == GDK_SCROLL_RIGHT)
+ event->direction = GDK_SCROLL_DOWN;
+
+ event->state &= ~GDK_SHIFT_MASK;
+ state &= ~GDK_SHIFT_MASK;
+ }
+
+ if (state == 0 && view->presentation) {
+ switch (event->direction) {
+ case GDK_SCROLL_DOWN:
+ case GDK_SCROLL_RIGHT:
+ ev_view_next_page (view);
+ break;
+ case GDK_SCROLL_UP:
+ case GDK_SCROLL_LEFT:
+ ev_view_previous_page (view);
+ break;
+ }
+
+ return TRUE;
}
return FALSE;
return NULL;
}
+static void
+draw_end_presentation_page (EvView *view,
+ GdkRectangle *page_area)
+{
+ PangoLayout *layout;
+ PangoFontDescription *font_desc;
+ gchar *markup;
+ const gchar *text = _("End of presentation. Press Escape to exit.");
+
+ if (view->presentation_state != EV_PRESENTATION_END)
+ return;
+
+ layout = gtk_widget_create_pango_layout (GTK_WIDGET (view), NULL);
+ markup = g_strdup_printf ("<span foreground=\"white\">%s</span>", text);
+ pango_layout_set_markup (layout, markup, -1);
+ g_free (markup);
+
+ font_desc = pango_font_description_new ();
+ pango_font_description_set_size (font_desc, 16 * PANGO_SCALE);
+ pango_layout_set_font_description (layout, font_desc);
+
+ gtk_paint_layout (GTK_WIDGET (view)->style,
+ GTK_WIDGET (view)->window,
+ GTK_WIDGET_STATE (view),
+ FALSE,
+ page_area,
+ GTK_WIDGET (view),
+ NULL,
+ page_area->x + 15,
+ page_area->y + 15,
+ layout);
+
+ pango_font_description_free (font_desc);
+ g_object_unref (layout);
+}
+
static gboolean
ev_view_expose_event (GtkWidget *widget,
GdkEventExpose *event)
EvView *view = EV_VIEW (widget);
int i;
+ if (view->presentation) {
+ switch (view->presentation_state) {
+ case EV_PRESENTATION_END: {
+ GdkRectangle area = {0};
+
+ area.width = widget->allocation.width;
+ area.height = widget->allocation.height;
+
+ draw_end_presentation_page (view, &area);
+ }
+ return FALSE;
+ case EV_PRESENTATION_BLACK:
+ case EV_PRESENTATION_WHITE:
+ return FALSE;
+ case EV_PRESENTATION_NORMAL:
+ default:
+ break;
+ }
+ } else if (view->loading) {
+ GdkRectangle area = {0};
+
+ area.width = widget->allocation.width;
+ area.height = widget->allocation.height;
+
+ draw_loading_text (view,
+ &area,
+ &(event->area));
+ }
+
if (view->document == NULL)
return FALSE;
for (i = view->start_page; i <= view->end_page; i++) {
GdkRectangle page_area;
GtkBorder border;
+ gboolean page_ready = TRUE;
if (!get_page_extents (view, i, &page_area, &border))
continue;
page_area.x -= view->scroll_x;
page_area.y -= view->scroll_y;
- draw_one_page (view, i, &page_area, &border, &(event->area));
+ draw_one_page (view, i, &page_area, &border, &(event->area), &page_ready);
- if (EV_IS_DOCUMENT_FIND (view->document))
+ if (page_ready && EV_IS_DOCUMENT_FIND (view->document))
highlight_find_results (view, i);
}
return FALSE;
}
+static gboolean
+ev_view_do_popup_menu (EvView *view,
+ gdouble x,
+ gdouble y)
+{
+ EvLink *link;
+ EvImage *image;
+
+ image = ev_view_get_image_at_location (view, x, y);
+ if (image) {
+ g_signal_emit (view, signals[SIGNAL_POPUP_MENU], 0, image);
+ return TRUE;
+ }
+
+ link = ev_view_get_link_at_location (view, x, y);
+ if (link) {
+ g_signal_emit (view, signals[SIGNAL_POPUP_MENU], 0, link);
+ return TRUE;
+ }
+
+ g_signal_emit (view, signals[SIGNAL_POPUP_MENU], 0, NULL);
+
+ return TRUE;
+}
+
+static gboolean
+ev_view_popup_menu (GtkWidget *widget)
+{
+ gint x, y;
+
+ gtk_widget_get_pointer (widget, &x, &y);
+ return ev_view_do_popup_menu (EV_VIEW (widget), x, y);
+}
+
static gboolean
ev_view_button_press_event (GtkWidget *widget,
GdkEventButton *event)
{
EvView *view = EV_VIEW (widget);
+ if (!view->document)
+ return FALSE;
+
if (!GTK_WIDGET_HAS_FOCUS (widget)) {
gtk_widget_grab_focus (widget);
}
-
+
view->pressed_button = event->button;
-
+ view->selection_info.in_drag = FALSE;
+
switch (event->button) {
- case 1:
+ case 1: {
+ EvImage *image;
+
if (view->selection_info.selections) {
- clear_selection (view);
+ if (location_in_selected_text (view,
+ event->x + view->scroll_x,
+ event->y + view->scroll_y)) {
+ view->selection_info.in_drag = TRUE;
+ } else {
+ clear_selection (view);
+ }
+
gtk_widget_queue_draw (widget);
+ } else if (!location_in_text (view, event->x + view->scroll_x, event->y + view->scroll_y) &&
+ (image = ev_view_get_image_at_location (view, event->x, event->y))) {
+ if (view->image_dnd_info.image)
+ g_object_unref (view->image_dnd_info.image);
+ view->image_dnd_info.image = g_object_ref (image);
+ view->image_dnd_info.in_drag = TRUE;
+
+ view->image_dnd_info.start.x = event->x + view->scroll_x;
+ view->image_dnd_info.start.y = event->y + view->scroll_y;
}
view->selection_info.start.x = event->x + view->scroll_x;
view->selection_info.start.y = event->y + view->scroll_y;
+ }
return TRUE;
case 2:
/* use root coordinates as reference point because
ev_view_set_cursor (view, EV_VIEW_CURSOR_DRAG);
return TRUE;
+ case 3:
+ return ev_view_do_popup_menu (view, event->x, event->y);
}
-
+
return FALSE;
}
+/*** Drag and Drop ***/
+static void
+ev_view_drag_data_get (GtkWidget *widget,
+ GdkDragContext *context,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time)
+{
+ EvView *view = EV_VIEW (widget);
+
+ switch (info) {
+ case TARGET_DND_TEXT:
+ if (view->selection_info.selections &&
+ ev_document_can_get_text (view->document)) {
+ gchar *text;
+
+ text = get_selected_text (view);
+
+ gtk_selection_data_set_text (selection_data,
+ text,
+ strlen (text));
+
+ g_free (text);
+ }
+ break;
+ case TARGET_DND_IMAGE:
+ if (view->image_dnd_info.image) {
+ GdkPixbuf *pixbuf;
+
+ pixbuf = ev_image_get_pixbuf (view->image_dnd_info.image);
+ gtk_selection_data_set_pixbuf (selection_data, pixbuf);
+ }
+ break;
+ case TARGET_DND_URI:
+ if (view->image_dnd_info.image) {
+ const gchar *tmp_uri;
+ gchar **uris;
+
+ tmp_uri = ev_image_save_tmp (view->image_dnd_info.image);
+
+ uris = g_new0 (gchar *, 2);
+ uris[0] = (gchar *)tmp_uri;
+
+ gtk_selection_data_set_uris (selection_data, uris);
+
+ /* g_free instead of g_strfreev since tmp_uri is const */
+ g_free (uris);
+ }
+ }
+}
static gboolean
-selection_update_idle_cb (EvView *view)
+ev_view_drag_motion (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time)
{
- GdkPoint point;
- point.x = view->motion_x;
- point.y = view->motion_y;
- compute_selections (view, &view->selection_info.start, &point);
+ if (gtk_drag_get_source_widget (context) == widget)
+ gdk_drag_status (context, 0, time);
+ else
+ gdk_drag_status (context, context->suggested_action, time);
+
+ return TRUE;
+}
+
+static void
+ev_view_drag_data_received (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time)
+{
+ gchar **uris;
+ gint i = 0;
+ GSList *uri_list = NULL;
+
+ uris = gtk_selection_data_get_uris (selection_data);
+ if (!uris) {
+ gtk_drag_finish (context, FALSE, FALSE, time);
+ return;
+ }
+ for (i = 0; uris[i]; i++) {
+ uri_list = g_slist_prepend (uri_list, (gpointer) uris[i]);
+ }
+
+ ev_application_open_uri_list (EV_APP, uri_list,
+ gtk_widget_get_screen (widget),
+ 0);
+ gtk_drag_finish (context, TRUE, FALSE, time);
+
+ g_strfreev (uris);
+ g_slist_free (uri_list);
+}
+
+
+static gboolean
+selection_update_idle_cb (EvView *view)
+{
+ compute_selections (view, &view->selection_info.start, &view->motion);
view->selection_update_id = 0;
return FALSE;
}
+static gboolean
+selection_scroll_timeout_cb (EvView *view)
+{
+ gint x, y, shift = 0;
+ GtkWidget *widget = GTK_WIDGET (view);
+
+ gtk_widget_get_pointer (widget, &x, &y);
+
+ if (y > widget->allocation.height) {
+ shift = (y - widget->allocation.height) / 2;
+ } else if (y < 0) {
+ shift = y / 2;
+ }
+
+ if (shift)
+ gtk_adjustment_set_value (view->vadjustment,
+ CLAMP (view->vadjustment->value + shift,
+ view->vadjustment->lower,
+ view->vadjustment->upper -
+ view->vadjustment->page_size));
+
+ if (x > widget->allocation.width) {
+ shift = (x - widget->allocation.width) / 2;
+ } else if (x < 0) {
+ shift = x / 2;
+ }
+
+ if (shift)
+ gtk_adjustment_set_value (view->hadjustment,
+ CLAMP (view->hadjustment->value + shift,
+ view->hadjustment->lower,
+ view->hadjustment->upper -
+ view->hadjustment->page_size));
+
+ return TRUE;
+}
+
static gboolean
ev_view_motion_notify_event (GtkWidget *widget,
GdkEventMotion *event)
{
EvView *view = EV_VIEW (widget);
+ gint x, y;
if (!view->document)
return FALSE;
+
+ if (event->is_hint || event->window != widget->window) {
+ gtk_widget_get_pointer (widget, &x, &y);
+ } else {
+ x = event->x;
+ y = event->y;
+ }
- if (view->pressed_button == 1) {
- view->selection_info.in_selection = TRUE;
- view->motion_x = event->x + view->scroll_x;
- view->motion_y = event->y + view->scroll_y;
+ if (view->selection_info.in_drag) {
+ if (gtk_drag_check_threshold (widget,
+ view->selection_info.start.x,
+ view->selection_info.start.y,
+ x, y)) {
+ GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
+
+ gtk_target_list_add_text_targets (target_list, TARGET_DND_TEXT);
+
+ gtk_drag_begin (widget, target_list,
+ GDK_ACTION_COPY,
+ 1, (GdkEvent *)event);
+
+ view->selection_info.in_drag = FALSE;
+
+ gtk_target_list_unref (target_list);
+
+ return TRUE;
+ }
+ } else if (view->image_dnd_info.in_drag) {
+ if (gtk_drag_check_threshold (widget,
+ view->selection_info.start.x,
+ view->selection_info.start.y,
+ x, y)) {
+ GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
+
+ gtk_target_list_add_uri_targets (target_list, TARGET_DND_URI);
+ gtk_target_list_add_image_targets (target_list, TARGET_DND_IMAGE, TRUE);
+
+ gtk_drag_begin (widget, target_list,
+ GDK_ACTION_COPY,
+ 1, (GdkEvent *)event);
- /* Queue an idle to handle the motion. We do this because
- * handling any selection events in the motion is probably going
- * to be slower than new motion events reach us. This means that */
+ view->image_dnd_info.in_drag = FALSE;
- if (! view->selection_update_id)
+ gtk_target_list_unref (target_list);
+
+ return TRUE;
+ }
+ }
+
+ /* For the Evince 0.4.x release, we limit selection to un-rotated
+ * documents only.
+ */
+ if (view->pressed_button == 1 && view->rotation == 0) {
+
+ /* Schedule timeout to scroll during selection and additionally
+ * scroll once to allow arbitrary speed. */
+ if (!view->selection_scroll_id)
+ view->selection_scroll_id = g_timeout_add (SCROLL_TIME, (GSourceFunc)selection_scroll_timeout_cb, view);
+ else
+ selection_scroll_timeout_cb (view);
+
+ view->selection_info.in_selection = TRUE;
+ view->motion.x = x + view->scroll_x;
+ view->motion.y = y + view->scroll_y;
+
+ /* Queue an idle to handle the motion. We do this because
+ * handling any selection events in the motion could be slower
+ * than new motion events reach us. We always put it in the
+ * idle to make sure we catch up and don't visibly lag the
+ * mouse. */
+ if (!view->selection_update_id)
view->selection_update_id = g_idle_add ((GSourceFunc)selection_update_idle_cb, view);
return TRUE;
return TRUE;
}
} else if (view->pressed_button <= 0) {
- EvLink *link;
-
- link = get_link_at_location (view, event->x + view->scroll_x, event->y + view->scroll_y);
- if (link) {
- char *msg;
-
- msg = status_message_from_link (view, link);
- ev_view_set_status (view, msg);
- ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);
- g_free (msg);
- } else if (location_in_text (view, event->x + view->scroll_x, event->y + view->scroll_y)) {
- ev_view_set_cursor (view, EV_VIEW_CURSOR_IBEAM);
- } else {
- ev_view_set_status (view, NULL);
- if (view->cursor == EV_VIEW_CURSOR_LINK ||
- view->cursor == EV_VIEW_CURSOR_IBEAM)
- ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
- }
+ handle_link_over_xy (view, x, y);
return TRUE;
}
GdkEventButton *event)
{
EvView *view = EV_VIEW (widget);
+ EvLink *link;
if (view->pressed_button == 2) {
ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
}
+ if (view->document && view->pressed_button != 3) {
+ link = ev_view_get_link_at_location (view, event->x, event->y);
+ } else {
+ link = NULL;
+ }
+
view->pressed_button = -1;
view->drag_info.in_drag = FALSE;
+ view->image_dnd_info.in_drag = FALSE;
+
+ if (view->selection_scroll_id) {
+ g_source_remove (view->selection_scroll_id);
+ view->selection_scroll_id = 0;
+ }
+ if (view->selection_update_id) {
+ g_source_remove (view->selection_update_id);
+ view->selection_update_id = 0;
+ }
if (view->selection_info.selections) {
ev_view_update_primary_selection (view);
- } else if (view->document) {
- EvLink *link;
-
- link = get_link_at_location (view, event->x + view->scroll_x, event->y + view->scroll_y);
- if (link) {
- go_to_link (view, link);
+
+ if (view->selection_info.in_drag) {
+ clear_selection (view);
+ gtk_widget_queue_draw (widget);
+ }
+
+ view->selection_info.in_drag = FALSE;
+ } else if (link) {
+ if (event->button == 2) {
+ EvLinkAction *action;
+ EvLinkActionType type;
+
+ action = ev_link_get_action (link);
+ if (!action)
+ return FALSE;
+
+ type = ev_link_action_get_action_type (action);
+ if (type == EV_LINK_ACTION_TYPE_GOTO_DEST) {
+ g_signal_emit (view,
+ signals[SIGNAL_EXTERNAL_LINK],
+ 0, action);
+ }
+ } else {
+ ev_view_handle_link (view, link);
+ }
+ } else if (view->presentation) {
+ switch (event->button) {
+ case 1:
+ ev_view_next_page (view);
+ return TRUE;
+ case 3:
+ ev_view_previous_page (view);
+ return TRUE;
}
}
+
+ return FALSE;
+}
+
+/* Goto Window */
+/* Cut and paste from gtkwindow.c */
+static void
+send_focus_change (GtkWidget *widget,
+ gboolean in)
+{
+ GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
+
+ g_object_ref (widget);
+
+ if (in)
+ GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
+ else
+ GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
+
+ fevent->focus_change.type = GDK_FOCUS_CHANGE;
+ fevent->focus_change.window = g_object_ref (widget->window);
+ fevent->focus_change.in = in;
+
+ gtk_widget_event (widget, fevent);
+
+ g_object_notify (G_OBJECT (widget), "has-focus");
+
+ g_object_unref (widget);
+ gdk_event_free (fevent);
+}
+
+static void
+ev_view_goto_window_hide (EvView *view)
+{
+ /* send focus-in event */
+ send_focus_change (view->goto_entry, FALSE);
+ gtk_widget_hide (view->goto_window);
+ gtk_entry_set_text (GTK_ENTRY (view->goto_entry), "");
+}
+
+static gboolean
+ev_view_goto_window_delete_event (GtkWidget *widget,
+ GdkEventAny *event,
+ EvView *view)
+{
+ ev_view_goto_window_hide (view);
+
+ return TRUE;
+}
+
+static gboolean
+key_is_numeric (guint keyval)
+{
+ return ((keyval >= GDK_0 && keyval <= GDK_9) ||
+ (keyval >= GDK_KP_0 && keyval <= GDK_KP_9));
+}
+
+static gboolean
+ev_view_goto_window_key_press_event (GtkWidget *widget,
+ GdkEventKey *event,
+ EvView *view)
+{
+ switch (event->keyval) {
+ case GDK_Escape:
+ case GDK_Tab:
+ case GDK_KP_Tab:
+ case GDK_ISO_Left_Tab:
+ ev_view_goto_window_hide (view);
+ return TRUE;
+ case GDK_Return:
+ case GDK_KP_Enter:
+ case GDK_ISO_Enter:
+ return FALSE;
+ default:
+ if (!key_is_numeric (event->keyval))
+ return TRUE;
+ }
return FALSE;
}
+static gboolean
+ev_view_goto_window_button_press_event (GtkWidget *widget,
+ GdkEventButton *event,
+ EvView *view)
+{
+ ev_view_goto_window_hide (view);
+
+ return TRUE;
+}
+
+static void
+ev_view_goto_entry_activate (GtkEntry *entry,
+ EvView *view)
+{
+ const gchar *text;
+ gint page;
+
+ text = gtk_entry_get_text (entry);
+ page = atoi (text) - 1;
+
+ ev_view_goto_window_hide (view);
+
+ if (page >= 0 &&
+ page < ev_page_cache_get_n_pages (view->page_cache))
+ ev_page_cache_set_current_page (view->page_cache, page);
+}
+
+static void
+ev_view_goto_window_create (EvView *view)
+{
+ GtkWidget *frame, *hbox, *toplevel, *label;
+
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
+
+ if (view->goto_window) {
+ if (GTK_WINDOW (toplevel)->group)
+ gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
+ GTK_WINDOW (view->goto_window));
+ else if (GTK_WINDOW (view->goto_window)->group)
+ gtk_window_group_remove_window (GTK_WINDOW (view->goto_window)->group,
+ GTK_WINDOW (view->goto_window));
+ return;
+ }
+
+ view->goto_window = gtk_window_new (GTK_WINDOW_POPUP);
+
+ if (GTK_WINDOW (toplevel)->group)
+ gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
+ GTK_WINDOW (view->goto_window));
+
+ gtk_window_set_modal (GTK_WINDOW (view->goto_window), TRUE);
+
+ g_signal_connect (view->goto_window, "delete_event",
+ G_CALLBACK (ev_view_goto_window_delete_event),
+ view);
+ g_signal_connect (view->goto_window, "key_press_event",
+ G_CALLBACK (ev_view_goto_window_key_press_event),
+ view);
+ g_signal_connect (view->goto_window, "button_press_event",
+ G_CALLBACK (ev_view_goto_window_button_press_event),
+ view);
+
+ frame = gtk_frame_new (NULL);
+ gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
+ gtk_container_add (GTK_CONTAINER (view->goto_window), frame);
+ gtk_widget_show (frame);
+
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 3);
+ gtk_container_add (GTK_CONTAINER (frame), hbox);
+ gtk_widget_show (hbox);
+
+ label = gtk_label_new(_("Jump to page:"));
+ gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 3);
+ gtk_widget_show (label);
+ gtk_widget_realize (label);
+
+ view->goto_entry = gtk_entry_new ();
+ g_signal_connect (view->goto_entry, "activate",
+ G_CALLBACK (ev_view_goto_entry_activate),
+ view);
+ gtk_box_pack_start_defaults (GTK_BOX (hbox), view->goto_entry);
+ gtk_widget_show (view->goto_entry);
+ gtk_widget_realize (view->goto_entry);
+}
+
+static void
+ev_view_goto_entry_grab_focus (EvView *view)
+{
+ GtkWidgetClass *entry_parent_class;
+
+ entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (view->goto_entry));
+ (entry_parent_class->grab_focus) (view->goto_entry);
+
+ send_focus_change (view->goto_entry, TRUE);
+}
+
+static void
+ev_view_goto_window_send_key_event (EvView *view,
+ GdkEvent *event)
+{
+ GdkEventKey *new_event;
+ GdkScreen *screen;
+
+ /* Move goto window off screen */
+ screen = gtk_widget_get_screen (GTK_WIDGET (view));
+ gtk_window_move (GTK_WINDOW (view->goto_window),
+ gdk_screen_get_width (screen) + 1,
+ gdk_screen_get_height (screen) + 1);
+ gtk_widget_show (view->goto_window);
+
+ new_event = (GdkEventKey *) gdk_event_copy (event);
+ g_object_unref (new_event->window);
+ new_event->window = g_object_ref (view->goto_window->window);
+ gtk_widget_realize (view->goto_window);
+
+ gtk_widget_event (view->goto_window, (GdkEvent *)new_event);
+ gdk_event_free ((GdkEvent *)new_event);
+ gtk_widget_hide (view->goto_window);
+}
+
+static gboolean
+ev_view_key_press_event (GtkWidget *widget,
+ GdkEventKey *event)
+{
+ EvView *view = EV_VIEW (widget);
+ EvPresentationState current;
+
+ if (!view->document)
+ return FALSE;
+
+ if (!view->presentation ||
+ view->presentation_state == EV_PRESENTATION_END)
+ return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
+
+
+ current = view->presentation_state;
+
+ switch (event->keyval) {
+ case GDK_b:
+ case GDK_B:
+ view->presentation_state =
+ (view->presentation_state == EV_PRESENTATION_BLACK) ?
+ EV_PRESENTATION_NORMAL : EV_PRESENTATION_BLACK;
+ break;
+ case GDK_w:
+ case GDK_W:
+ view->presentation_state =
+ (view->presentation_state == EV_PRESENTATION_WHITE) ?
+ EV_PRESENTATION_NORMAL : EV_PRESENTATION_WHITE;
+ break;
+ default:
+ if (view->presentation_state == EV_PRESENTATION_BLACK ||
+ view->presentation_state == EV_PRESENTATION_WHITE) {
+ view->presentation_state = EV_PRESENTATION_NORMAL;
+ }
+ }
+
+ if (current == view->presentation_state) {
+ if (ev_page_cache_get_n_pages (view->page_cache) > 1 &&
+ key_is_numeric (event->keyval)) {
+ gint x, y;
+
+ ev_view_goto_window_create (view);
+ ev_view_goto_window_send_key_event (view, (GdkEvent *)event);
+ gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
+ gtk_window_move (GTK_WINDOW (view->goto_window), x, y);
+ gtk_widget_show (view->goto_window);
+ ev_view_goto_entry_grab_focus (view);
+
+ return TRUE;
+ }
+
+ return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
+ }
+
+ switch (view->presentation_state) {
+ case EV_PRESENTATION_NORMAL:
+ case EV_PRESENTATION_BLACK:
+ gdk_window_set_background (widget->window,
+ &widget->style->black);
+ break;
+ case EV_PRESENTATION_WHITE:
+ gdk_window_set_background (widget->window,
+ &widget->style->white);
+ break;
+ default:
+ return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
+ }
+
+ gtk_widget_queue_draw (widget);
+ return TRUE;
+}
+
static gint
ev_view_focus_in (GtkWidget *widget,
GdkEventFocus *event)
ev_view_focus_out (GtkWidget *widget,
GdkEventFocus *event)
{
+ if (EV_VIEW (widget)->goto_window)
+ ev_view_goto_window_hide (EV_VIEW (widget));
+
if (EV_VIEW (widget)->pixbuf_cache)
ev_pixbuf_cache_style_changed (EV_VIEW (widget)->pixbuf_cache);
gtk_widget_queue_draw (widget);
view->cursor == EV_VIEW_CURSOR_IBEAM)
ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
+ if (view->link_tooltip) {
+ view->hovered_link = NULL;
+ ev_tooltip_deactivate (EV_TOOLTIP (view->link_tooltip));
+ }
+
+ return FALSE;
+}
+
+static gboolean
+ev_view_enter_notify_event (GtkWidget *widget, GdkEventCrossing *event)
+{
+ EvView *view = EV_VIEW (widget);
+
+ handle_link_over_xy (view, event->x, event->y);
+
return FALSE;
}
GTK_WIDGET_CLASS (ev_view_parent_class)->style_set (widget, old_style);
}
-
/*** Drawing ***/
static guint32
GdkRectangle view_rectangle;
guchar alpha;
- if (i == view->find_result && page == view->find_page) {
+ if (i == view->find_result && page == view->current_page) {
alpha = 0x90;
} else {
alpha = 0x20;
}
- ev_document_find_get_result (find, page,
- i, &rectangle);
+ ev_document_find_get_result (find, page, i, &rectangle);
doc_rect_to_view_rect (view, page, &rectangle, &view_rectangle);
draw_rubberband (GTK_WIDGET (view), GTK_WIDGET(view)->window,
&view_rectangle, alpha);
}
}
+static void
+draw_loading_text (EvView *view,
+ GdkRectangle *page_area,
+ GdkRectangle *expose_area)
+{
+ cairo_t *cr;
+ gint width, height;
+
+ /* Don't annoy users with loading messages during presentations.
+ * FIXME: Temporary "workaround" for
+ * http://bugzilla.gnome.org/show_bug.cgi?id=320352 */
+ if (view->presentation)
+ return;
+
+ if (!view->loading_text) {
+ const gchar *loading_text;
+ PangoLayout *layout;
+ PangoFontDescription *font_desc;
+ PangoRectangle logical_rect;
+ gdouble real_scale;
+ gint target_width;
+
+ loading_text = _("Loading...");
+
+ ev_document_fc_mutex_lock ();
+
+ layout = gtk_widget_create_pango_layout (GTK_WIDGET (view), loading_text);
+
+ font_desc = pango_font_description_new ();
+
+ /* We set the font to be 10 points, get the size, and scale appropriately */
+ pango_font_description_set_size (font_desc, 10 * PANGO_SCALE);
+ pango_layout_set_font_description (layout, font_desc);
+ pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+
+ /* Make sure we fit the middle of the page */
+ target_width = MAX (page_area->width / 2, 1);
+ real_scale = ((double)target_width / (double) logical_rect.width) * (PANGO_SCALE * 10);
+ pango_font_description_set_size (font_desc, (int)real_scale);
+ pango_layout_set_font_description (layout, font_desc);
+ pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+
+ view->loading_text = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ logical_rect.width,
+ logical_rect.height);
+ cr = cairo_create (view->loading_text);
+ cairo_set_source_rgb (cr,
+ 155 / (double)255,
+ 155 / (double)255,
+ 155 / (double)255);
+ pango_cairo_show_layout (cr, layout);
+ cairo_destroy (cr);
+
+ pango_font_description_free (font_desc);
+ g_object_unref (layout);
+
+ ev_document_fc_mutex_unlock ();
+ }
+
+ width = cairo_image_surface_get_width (view->loading_text) / 2;
+ height = (page_area->height - cairo_image_surface_get_height (view->loading_text)) / 2;
+
+ cr = gdk_cairo_create (GTK_WIDGET (view)->window);
+ cairo_set_source_surface (cr, view->loading_text,
+ page_area->x + width,
+ page_area->y + height);
+ cairo_paint (cr);
+ cairo_destroy (cr);
+}
+
static void
draw_one_page (EvView *view,
gint page,
GdkRectangle *page_area,
GtkBorder *border,
- GdkRectangle *expose_area)
+ GdkRectangle *expose_area,
+ gboolean *page_ready)
{
gint width, height;
GdkPixbuf *current_pixbuf;
GdkRectangle overlap;
GdkRectangle real_page_area;
EvViewSelection *selection;
+ gint current_page;
g_assert (view->document);
+
if (! gdk_rectangle_intersect (page_area, expose_area, &overlap))
return;
-
+
+ current_page = ev_page_cache_get_current_page (view->page_cache);
selection = find_selection_for_page (view, page);
ev_page_cache_get_size (view->page_cache,
page, view->rotation,
real_page_area.y += border->top;
real_page_area.width -= (border->left + border->right);
real_page_area.height -= (border->top + border->bottom);
+ *page_ready = TRUE;
- ev_document_misc_paint_one_page (GTK_WIDGET(view)->window,
- GTK_WIDGET (view),
- page_area, border);
+ if (!view->presentation) {
+ ev_document_misc_paint_one_page (GTK_WIDGET(view)->window,
+ GTK_WIDGET (view),
+ page_area, border,
+ page == current_page);
+ }
if (gdk_rectangle_intersect (&real_page_area, expose_area, &overlap)) {
GdkPixbuf *selection_pixbuf = NULL;
GDK_RGB_DITHER_NORMAL,
0, 0);
g_object_unref (scaled_image);
+ } else {
+ draw_loading_text (view,
+ &real_page_area,
+ expose_area);
+ *page_ready = FALSE;
}
if (scaled_selection) {
{
EvView *view = EV_VIEW (object);
- LOG ("Finalize");
-
g_free (view->status);
g_free (view->find_status);
clear_selection (view);
+ if (view->image_dnd_info.image)
+ g_object_unref (view->image_dnd_info.image);
+ view->image_dnd_info.image = NULL;
+
G_OBJECT_CLASS (ev_view_parent_class)->finalize (object);
}
g_object_unref (view->document);
view->document = NULL;
}
+
if (view->pixbuf_cache) {
g_object_unref (view->pixbuf_cache);
view->pixbuf_cache = NULL;
}
+
+ if (view->link_tooltip) {
+ gtk_widget_destroy (view->link_tooltip);
+ view->link_tooltip = NULL;
+ }
+
+ if (view->goto_window) {
+ gtk_widget_destroy (view->goto_window);
+ view->goto_window = NULL;
+ view->goto_entry = NULL;
+ }
+
+ if (view->selection_scroll_id) {
+ g_source_remove (view->selection_scroll_id);
+ view->selection_scroll_id = 0;
+ }
+
+ if (view->selection_update_id) {
+ g_source_remove (view->selection_update_id);
+ view->selection_update_id = 0;
+ }
+
+ if (view->loading_text) {
+ cairo_surface_destroy (view->loading_text);
+ view->loading_text = NULL;
+ }
+
+ ev_view_presentation_transition_stop (view);
+
ev_view_set_scroll_adjustments (view, NULL, NULL);
GTK_OBJECT_CLASS (ev_view_parent_class)->destroy (object);
{
EvView *view = EV_VIEW (object);
- switch (prop_id)
- {
- case PROP_CONTINUOUS:
- ev_view_set_continuous (view, g_value_get_boolean (value));
- break;
- case PROP_DUAL_PAGE:
- ev_view_set_dual_page (view, g_value_get_boolean (value));
- break;
- case PROP_FULLSCREEN:
- ev_view_set_fullscreen (view, g_value_get_boolean (value));
- break;
- case PROP_PRESENTATION:
- ev_view_set_presentation (view, g_value_get_boolean (value));
- break;
- case PROP_SIZING_MODE:
- ev_view_set_sizing_mode (view, g_value_get_enum (value));
- break;
- case PROP_ZOOM:
- ev_view_set_zoom (view, g_value_get_double (value), FALSE);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ switch (prop_id) {
+ case PROP_CONTINUOUS:
+ ev_view_set_continuous (view, g_value_get_boolean (value));
+ break;
+ case PROP_DUAL_PAGE:
+ ev_view_set_dual_page (view, g_value_get_boolean (value));
+ break;
+ case PROP_FULLSCREEN:
+ ev_view_set_fullscreen (view, g_value_get_boolean (value));
+ break;
+ case PROP_PRESENTATION:
+ ev_view_set_presentation (view, g_value_get_boolean (value));
+ break;
+ case PROP_SIZING_MODE:
+ ev_view_set_sizing_mode (view, g_value_get_enum (value));
+ break;
+ case PROP_ZOOM:
+ ev_view_set_zoom (view, g_value_get_double (value), FALSE);
+ break;
+ case PROP_ROTATION:
+ ev_view_set_rotation (view, g_value_get_int (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
+static AtkObject *
+ev_view_get_accessible (GtkWidget *widget)
+{
+ static gboolean first_time = TRUE;
+
+ if (first_time) {
+ AtkObjectFactory *factory;
+ AtkRegistry *registry;
+ GType derived_type;
+ GType derived_atk_type;
+
+ /*
+ * Figure out whether accessibility is enabled by looking at the
+ * type of the accessible object which would be created for
+ * the parent type of EvView.
+ */
+ derived_type = g_type_parent (EV_TYPE_VIEW);
+
+ registry = atk_get_default_registry ();
+ factory = atk_registry_get_factory (registry,
+ derived_type);
+ derived_atk_type = atk_object_factory_get_accessible_type (factory);
+ if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
+ atk_registry_set_factory_type (registry,
+ EV_TYPE_VIEW,
+ ev_view_accessible_factory_get_type ());
+ first_time = FALSE;
+ }
+ return GTK_WIDGET_CLASS (ev_view_parent_class)->get_accessible (widget);
+}
+
static void
ev_view_get_property (GObject *object,
guint prop_id,
{
EvView *view = EV_VIEW (object);
- switch (prop_id)
- {
- case PROP_STATUS:
- g_value_set_string (value, view->status);
- break;
- case PROP_FIND_STATUS:
- g_value_set_string (value, view->status);
- break;
- case PROP_CONTINUOUS:
- g_value_set_boolean (value, view->continuous);
- break;
- case PROP_DUAL_PAGE:
- g_value_set_boolean (value, view->dual_page);
- break;
- case PROP_FULLSCREEN:
- g_value_set_boolean (value, view->fullscreen);
- break;
- case PROP_PRESENTATION:
- g_value_set_boolean (value, view->presentation);
- break;
- case PROP_SIZING_MODE:
- g_value_set_enum (value, view->sizing_mode);
- break;
- case PROP_ZOOM:
- g_value_set_double (value, view->scale);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ switch (prop_id) {
+ case PROP_STATUS:
+ g_value_set_string (value, view->status);
+ break;
+ case PROP_FIND_STATUS:
+ g_value_set_string (value, view->status);
+ break;
+ case PROP_CONTINUOUS:
+ g_value_set_boolean (value, view->continuous);
+ break;
+ case PROP_DUAL_PAGE:
+ g_value_set_boolean (value, view->dual_page);
+ break;
+ case PROP_FULLSCREEN:
+ g_value_set_boolean (value, view->fullscreen);
+ break;
+ case PROP_PRESENTATION:
+ g_value_set_boolean (value, view->presentation);
+ break;
+ case PROP_SIZING_MODE:
+ g_value_set_enum (value, view->sizing_mode);
+ break;
+ case PROP_ZOOM:
+ g_value_set_double (value, view->scale);
+ break;
+ case PROP_ROTATION:
+ g_value_set_int (value, view->rotation);
+ break;
+ case PROP_HAS_SELECTION:
+ g_value_set_boolean (value,
+ view->selection_info.selections != NULL);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
widget_class->button_press_event = ev_view_button_press_event;
widget_class->motion_notify_event = ev_view_motion_notify_event;
widget_class->button_release_event = ev_view_button_release_event;
+ widget_class->key_press_event = ev_view_key_press_event;
widget_class->focus_in_event = ev_view_focus_in;
widget_class->focus_out_event = ev_view_focus_out;
+ widget_class->get_accessible = ev_view_get_accessible;
widget_class->size_request = ev_view_size_request;
widget_class->size_allocate = ev_view_size_allocate;
widget_class->realize = ev_view_realize;
- widget_class->unrealize = ev_view_unrealize;
widget_class->scroll_event = ev_view_scroll_event;
+ widget_class->enter_notify_event = ev_view_enter_notify_event;
widget_class->leave_notify_event = ev_view_leave_notify_event;
widget_class->style_set = ev_view_style_set;
+ widget_class->drag_data_get = ev_view_drag_data_get;
+ widget_class->drag_motion = ev_view_drag_motion;
+ widget_class->drag_data_received = ev_view_drag_data_received;
+ widget_class->popup_menu = ev_view_popup_menu;
gtk_object_class->destroy = ev_view_destroy;
class->set_scroll_adjustments = ev_view_set_scroll_adjustments;
- class->binding_activated = ev_view_binding_activated;
+ class->binding_activated = ev_view_scroll;
widget_class->set_scroll_adjustments_signal =
g_signal_new ("set-scroll-adjustments",
NULL, NULL,
ev_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
+ signals[SIGNAL_HANDLE_LINK] = g_signal_new ("handle-link",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (EvViewClass, handle_link),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ G_TYPE_OBJECT);
+ signals[SIGNAL_EXTERNAL_LINK] = g_signal_new ("external-link",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (EvViewClass, external_link),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ G_TYPE_OBJECT);
+ signals[SIGNAL_POPUP_MENU] = g_signal_new ("popup",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (EvViewClass, popup_menu),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ G_TYPE_OBJECT);
g_object_class_install_property (object_class,
PROP_STATUS,
PROP_ZOOM,
g_param_spec_double ("zoom",
"Zoom factor",
- "Zoom factor",
- MIN_SCALE,
- MAX_SCALE,
- 1.0,
- G_PARAM_READWRITE));
+ "Zoom factor",
+ 0,
+ G_MAXDOUBLE,
+ 1.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_ROTATION,
+ g_param_spec_double ("rotation",
+ "Rotation",
+ "Rotation",
+ 0,
+ 360,
+ 0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_HAS_SELECTION,
+ g_param_spec_boolean ("has-selection",
+ "Has selection",
+ "The view has selections",
+ FALSE,
+ G_PARAM_READABLE));
binding_set = gtk_binding_set_by_class (class);
- add_scroll_binding_keypad (binding_set, GDK_Left, GTK_SCROLL_STEP_BACKWARD, TRUE);
- add_scroll_binding_keypad (binding_set, GDK_Right, GTK_SCROLL_STEP_FORWARD, TRUE);
- add_scroll_binding_keypad (binding_set, GDK_Up, GTK_SCROLL_STEP_BACKWARD, FALSE);
- add_scroll_binding_keypad (binding_set, GDK_Down, GTK_SCROLL_STEP_FORWARD, FALSE);
+ add_scroll_binding_keypad (binding_set, GDK_Left, 0, EV_SCROLL_STEP_BACKWARD, TRUE);
+ add_scroll_binding_keypad (binding_set, GDK_Right, 0, EV_SCROLL_STEP_FORWARD, TRUE);
+ add_scroll_binding_keypad (binding_set, GDK_Left, GDK_MOD1_MASK, EV_SCROLL_STEP_DOWN, TRUE);
+ add_scroll_binding_keypad (binding_set, GDK_Right, GDK_MOD1_MASK, EV_SCROLL_STEP_UP, TRUE);
+ add_scroll_binding_keypad (binding_set, GDK_Up, 0, EV_SCROLL_STEP_BACKWARD, FALSE);
+ add_scroll_binding_keypad (binding_set, GDK_Down, 0, EV_SCROLL_STEP_FORWARD, FALSE);
+ add_scroll_binding_keypad (binding_set, GDK_Up, GDK_MOD1_MASK, EV_SCROLL_STEP_DOWN, FALSE);
+ add_scroll_binding_keypad (binding_set, GDK_Down, GDK_MOD1_MASK, EV_SCROLL_STEP_UP, FALSE);
}
static void
view->pressed_button = -1;
view->cursor = EV_VIEW_CURSOR_NORMAL;
view->drag_info.in_drag = FALSE;
+ view->selection_info.selections = NULL;
view->selection_info.in_selection = FALSE;
-
+ view->selection_info.in_drag = FALSE;
view->selection_mode = EV_VIEW_SELECTION_TEXT;
view->continuous = TRUE;
view->dual_page = FALSE;
view->presentation = FALSE;
+ view->presentation_state = EV_PRESENTATION_NORMAL;
view->fullscreen = FALSE;
view->sizing_mode = EV_SIZING_FIT_WIDTH;
view->pending_scroll = SCROLL_TO_KEEP_POSITION;
+ view->jump_to_find_result = TRUE;
+
+ gtk_drag_dest_set (GTK_WIDGET (view),
+ GTK_DEST_DEFAULT_ALL,
+ view_drop_targets,
+ G_N_ELEMENTS (view_drop_targets),
+ GDK_ACTION_COPY);
}
/*** Callbacks ***/
static void
find_changed_cb (EvDocument *document, int page, EvView *view)
{
- jump_to_find_page (view);
- jump_to_find_result (view);
- update_find_status_message (view);
+ double percent;
+ int n_pages;
+ percent = ev_document_find_get_progress
+ (EV_DOCUMENT_FIND (view->document));
+ n_pages = ev_page_cache_get_n_pages (view->page_cache);
+
+ if (view->jump_to_find_result == TRUE) {
+ jump_to_find_page (view, EV_VIEW_FIND_NEXT, 0);
+ jump_to_find_result (view);
+ }
+ update_find_status_message (view, percent * n_pages >= n_pages - 1 );
if (view->current_page == page)
gtk_widget_queue_draw (GTK_WIDGET (view));
}
EvView *view)
{
if (view->current_page != new_page) {
-
view->current_page = new_page;
- view->pending_scroll = SCROLL_TO_CURRENT_PAGE;
+ view->pending_scroll = SCROLL_TO_PAGE_POSITION;
+ if (view->presentation)
+ ev_view_presentation_transition_start (view);
gtk_widget_queue_resize (GTK_WIDGET (view));
+ } else {
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+ }
- if (EV_IS_DOCUMENT_FIND (view->document)) {
- view->find_page = new_page;
- view->find_result = 0;
- update_find_status_message (view);
- }
+ if (EV_IS_DOCUMENT_FIND (view->document)) {
+ view->find_result = 0;
+ update_find_status_message (view, TRUE);
}
}
}
if (view->page_cache) {
- g_object_unref (view->page_cache);
view->page_cache = NULL;
}
}
+void
+ev_view_set_loading (EvView *view,
+ gboolean loading)
+{
+ view->loading = loading;
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+}
+
void
ev_view_set_document (EvView *view,
EvDocument *document)
{
g_return_if_fail (EV_IS_VIEW (view));
+ view->loading = FALSE;
+
if (document != view->document) {
clear_caches (view);
}
view->document = document;
- view->find_page = 0;
view->find_result = 0;
if (view->document) {
else
scale = factor;
- scale = CLAMP (scale, MIN_SCALE, MAX_SCALE);
+ scale = CLAMP (scale, view->min_scale, view->max_scale);
if (ABS (view->scale - scale) < EPSILON)
return;
+ if (view->loading_text) {
+ cairo_surface_destroy (view->loading_text);
+ view->loading_text = NULL;
+ }
+
view->scale = scale;
view->pending_resize = TRUE;
return view->scale;
}
+void
+ev_view_set_screen_dpi (EvView *view,
+ gdouble dpi)
+{
+ g_return_if_fail (EV_IS_VIEW (view));
+ g_return_if_fail (dpi > 0);
+
+ view->dpi = dpi;
+ view->min_scale = MIN_SCALE * dpi / 72.0;
+ view->max_scale = MAX_SCALE * dpi / 72.0;
+}
+
gboolean
ev_view_get_continuous (EvView *view)
{
if (view->continuous != continuous) {
view->continuous = continuous;
- view->pending_scroll = SCROLL_TO_CURRENT_PAGE;
+ view->pending_scroll = SCROLL_TO_PAGE_POSITION;
gtk_widget_queue_resize (GTK_WIDGET (view));
}
if (view->dual_page == dual_page)
return;
- view->pending_scroll = SCROLL_TO_CURRENT_PAGE;
+ view->pending_scroll = SCROLL_TO_PAGE_POSITION;
view->dual_page = dual_page;
/* FIXME: if we're keeping the pixbuf cache around, we should extend the
* preload_cache_size to be 2 if dual_page is set.
if (view->presentation == presentation)
return;
+ if (!presentation)
+ view->presentation_state = EV_PRESENTATION_NORMAL;
+
view->presentation = presentation;
- view->pending_scroll = SCROLL_TO_CURRENT_PAGE;
+ view->pending_scroll = SCROLL_TO_PAGE_POSITION;
+
+ if (presentation) {
+ view->sizing_mode_saved = view->sizing_mode;
+ view->scale_saved = view->scale;
+ ev_view_set_sizing_mode (view, EV_SIZING_BEST_FIT);
+ } else {
+ ev_view_set_sizing_mode (view, view->sizing_mode_saved);
+ ev_view_set_zoom (view, view->scale_saved, FALSE);
+ }
+
gtk_widget_queue_resize (GTK_WIDGET (view));
+ if (presentation)
+ ev_view_presentation_transition_start (view);
+ else
+ ev_view_presentation_transition_stop (view);
+
if (GTK_WIDGET_REALIZED (view)) {
if (view->presentation)
gdk_window_set_background (GTK_WIDGET(view)->window,
>K_WIDGET (view)->style->mid [GTK_STATE_NORMAL]);
}
-
g_object_notify (G_OBJECT (view), "presentation");
}
return view->presentation;
}
+static gboolean
+transition_next_page (EvView *view)
+{
+ ev_view_next_page (view);
+
+ return FALSE;
+}
+
+static void
+ev_view_presentation_transition_stop (EvView *view)
+{
+ if (view->trans_timeout_id > 0)
+ g_source_remove (view->trans_timeout_id);
+ view->trans_timeout_id = 0;
+}
+
+static void
+ev_view_presentation_transition_start (EvView *view)
+{
+ gdouble duration;
+
+ if (!EV_IS_DOCUMENT_TRANSITION (view->document))
+ return;
+
+ ev_view_presentation_transition_stop (view);
+
+ duration = ev_document_transition_get_page_duration (EV_DOCUMENT_TRANSITION (view->document),
+ view->current_page);
+ if (duration > 0)
+ view->trans_timeout_id = g_timeout_add (duration * 1000,
+ (GSourceFunc) transition_next_page,
+ view);
+}
+
void
ev_view_set_sizing_mode (EvView *view,
EvSizingMode sizing_mode)
gboolean
ev_view_can_zoom_in (EvView *view)
{
- return view->scale * ZOOM_IN_FACTOR <= MAX_SCALE;
+ return view->scale * ZOOM_IN_FACTOR <= view->max_scale;
}
gboolean
ev_view_can_zoom_out (EvView *view)
{
- return view->scale * ZOOM_OUT_FACTOR >= MIN_SCALE;
+ return view->scale * ZOOM_OUT_FACTOR >= view->min_scale;
}
void
{
g_return_if_fail (view->sizing_mode == EV_SIZING_FREE);
+ if (view->presentation)
+ return;
+
view->pending_scroll = SCROLL_TO_CENTER;
ev_view_set_zoom (view, ZOOM_IN_FACTOR, TRUE);
}
{
g_return_if_fail (view->sizing_mode == EV_SIZING_FREE);
+ if (view->presentation)
+ return;
+
view->pending_scroll = SCROLL_TO_CENTER;
ev_view_set_zoom (view, ZOOM_OUT_FACTOR, TRUE);
}
-static void
-ev_view_set_rotation (EvView *view, int rotation)
-{
- view->rotation = rotation;
-
- ev_pixbuf_cache_clear (view->pixbuf_cache);
- gtk_widget_queue_resize (GTK_WIDGET (view));
-}
-
void
ev_view_rotate_right (EvView *view)
{
ev_view_set_rotation (view, rotation);
}
+void
+ev_view_set_rotation (EvView *view, int rotation)
+{
+ view->rotation = rotation;
+
+ if (view->pixbuf_cache) {
+ ev_pixbuf_cache_clear (view->pixbuf_cache);
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+ }
+
+ if (rotation != 0)
+ clear_selection (view);
+
+ g_object_notify (G_OBJECT (view), "rotation");
+}
+
+int
+ev_view_get_rotation (EvView *view)
+{
+ return view->rotation;
+}
+
static double
zoom_for_size_fit_width (int doc_width,
int doc_height,
return scale;
}
+static double
+zoom_for_size_fit_height (int doc_width,
+ int doc_height,
+ int target_width,
+ int target_height,
+ int vsb_height)
+{
+ double scale;
+
+ scale = (double)target_height / doc_height;
+
+ if (doc_width * scale > target_width)
+ scale = (double) (target_height - vsb_height) / doc_height;
+
+ return scale;
+}
+
static double
zoom_for_size_best_fit (int doc_width,
int doc_height,
}
static void
-update_find_status_message (EvView *view)
+update_find_status_message (EvView *view, gboolean this_page)
{
char *message;
- if (view->current_page == view->find_page) {
+ if (this_page) {
int results;
results = ev_document_find_get_n_results
percent = ev_document_find_get_progress
(EV_DOCUMENT_FIND (view->document));
- if (percent >= (1.0 - 1e-10)) {
- message = g_strdup (_("Not found"));
- } else {
- message = g_strdup_printf (_("%3d%% remaining to search"),
- (int) ((1.0 - percent) * 100));
- }
-
+ message = g_strdup_printf (_("%3d%% remaining to search"),
+ (int) ((1.0 - percent) * 100));
+
}
ev_view_set_find_status (view, message);
g_free (message);
EvRectangle rect;
GdkRectangle view_rect;
int n_results;
- int page = view->find_page;
+ int page = view->current_page;
n_results = ev_document_find_get_n_results (find, page);
- if (n_results > view->find_result) {
+ if (n_results > 0 && view->find_result < n_results) {
ev_document_find_get_result
(find, page, view->find_result, &rect);
}
}
+/**
+ * jump_to_find_page
+ * @view: #EvView instance
+ * @direction: Direction to look
+ * @shift: Shift from current page
+ *
+ * Jumps to the first page that has occurences of searched word.
+ * Uses a direction where to look and a shift from current page.
+ *
+ */
static void
-jump_to_find_page (EvView *view)
+jump_to_find_page (EvView *view, EvViewFindDirection direction, gint shift)
{
int n_pages, i;
for (i = 0; i < n_pages; i++) {
int has_results;
int page;
-
- page = i + view->find_page;
+
+ if (direction == EV_VIEW_FIND_NEXT)
+ page = view->current_page + i;
+ else
+ page = view->current_page - i;
+ page += shift;
+
if (page >= n_pages) {
page = page - n_pages;
}
-
+ if (page < 0)
+ page = page + n_pages;
+
has_results = ev_document_find_page_has_results
(EV_DOCUMENT_FIND (view->document), page);
if (has_results == -1) {
- view->find_page = page;
break;
} else if (has_results == 1) {
ev_page_cache_set_current_page (view->page_cache, page);
- jump_to_find_result (view);
break;
}
}
gboolean
ev_view_can_find_next (EvView *view)
{
- int n_results = 0;
-
if (EV_IS_DOCUMENT_FIND (view->document)) {
EvDocumentFind *find = EV_DOCUMENT_FIND (view->document);
+ int i, n_pages;
- n_results = ev_document_find_get_n_results (find, view->current_page);
+ n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ for (i = 0; i < n_pages; i++) {
+ if (ev_document_find_get_n_results (find, i) > 0) {
+ return TRUE;
+ }
+ }
}
- return n_results > 0;
+ return FALSE;
}
void
view->find_result++;
if (view->find_result >= n_results) {
- view->find_result = 0;
- view->find_page++;
-
- if (view->find_page >= n_pages) {
- view->find_page = 0;
- }
- jump_to_find_page (view);
+ view->find_result = 0;
+ jump_to_find_page (view, EV_VIEW_FIND_NEXT, 1);
+ jump_to_find_result (view);
} else {
jump_to_find_result (view);
gtk_widget_queue_draw (GTK_WIDGET (view));
}
}
+gboolean
+ev_view_can_find_previous (EvView *view)
+{
+ if (EV_IS_DOCUMENT_FIND (view->document)) {
+ EvDocumentFind *find = EV_DOCUMENT_FIND (view->document);
+ int i, n_pages;
+
+ n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ for (i = n_pages - 1; i >= 0; i--) {
+ if (ev_document_find_get_n_results (find, i) > 0) {
+ return TRUE;
+ }
+ }
+ }
+
+ return FALSE;
+}
void
ev_view_find_previous (EvView *view)
{
view->find_result--;
if (view->find_result < 0) {
- view->find_result = 0;
- view->find_page--;
-
- if (view->find_page < 0) {
- view->find_page = n_pages - 1;
- }
- jump_to_find_page (view);
+ jump_to_find_page (view, EV_VIEW_FIND_PREV, -1);
+ view->find_result = ev_document_find_get_n_results (find, view->current_page) - 1;
+ jump_to_find_result (view);
} else {
jump_to_find_result (view);
gtk_widget_queue_draw (GTK_WIDGET (view));
}
}
+void ev_view_search_changed (EvView *view)
+{
+ /* search string has changed, focus on new search result */
+ view->jump_to_find_result = TRUE;
+}
+
/*** Selections ***/
/* compute_new_selection_rect/text calculates the area currently selected by
GList *list = NULL;
EvViewSelection *selection;
gint width, height;
+ int start_page, end_page;
g_assert (view->selection_mode == EV_VIEW_SELECTION_TEXT);
* affects. */
first = n_pages;
last = 0;
- for (i = 0; i < n_pages; i++) {
+ if (view->continuous) {
+ start_page = 0;
+ end_page = n_pages;
+ } else if (view->dual_page) {
+ start_page = view->start_page;
+ end_page = view->end_page + 1;
+ } else {
+ start_page = view->current_page;
+ end_page = view->current_page + 1;
+ }
+
+ for (i = start_page; i < end_page; i++) {
GdkRectangle page_area;
GtkBorder border;
g_list_foreach (view->selection_info.selections, (GFunc)selection_free, NULL);
view->selection_info.selections = new_list;
ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, new_list);
+ g_object_notify (G_OBJECT (view), "has-selection");
new_list_ptr = new_list;
old_list_ptr = old_list;
g_list_foreach (view->selection_info.selections, (GFunc)selection_free, NULL);
view->selection_info.selections = NULL;
view->selection_info.in_selection = FALSE;
+ if (view->pixbuf_cache)
+ ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, NULL);
+ g_object_notify (G_OBJECT (view), "has-selection");
}
{
int n_pages, i;
+ /* Disable selection on rotated pages for the 0.4.0 series */
+ if (view->rotation != 0)
+ return;
+
clear_selection (view);
n_pages = ev_page_cache_get_n_pages (view->page_cache);
EvViewSelection *selection;
ev_page_cache_get_size (view->page_cache,
+ i,
view->rotation,
- i, 1.0, &width, &height);
+ 1.0, &width, &height);
selection = g_new0 (EvViewSelection, 1);
selection->page = i;
}
ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, view->selection_info.selections);
+ g_object_notify (G_OBJECT (view), "has-selection");
gtk_widget_queue_draw (GTK_WIDGET (view));
}
+gboolean
+ev_view_get_has_selection (EvView *view)
+{
+ return view->selection_info.selections != NULL;
+}
+
static char *
get_selected_text (EvView *ev_view)
{
GString *text;
GList *l;
+ gchar *normalized_text;
text = g_string_new (NULL);
ev_document_doc_mutex_unlock ();
- return g_string_free (text, FALSE);
+ normalized_text = g_utf8_normalize (text->str, text->len, G_NORMALIZE_NFKC);
+ g_string_free (text, TRUE);
+ return normalized_text;
}
void
if (ev_view->selection_info.selections) {
if (!gtk_clipboard_set_with_owner (clipboard,
- targets,
- G_N_ELEMENTS (targets),
+ clipboard_targets,
+ G_N_ELEMENTS (clipboard_targets),
ev_view_primary_get_cb,
ev_view_primary_clear_cb,
G_OBJECT (ev_view)))
ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
}
+static void
+ev_view_reset_presentation_state (EvView *view)
+{
+ if (!view->presentation ||
+ view->presentation_state == EV_PRESENTATION_NORMAL)
+ return;
+
+ view->presentation_state = EV_PRESENTATION_NORMAL;
+ gdk_window_set_background (GTK_WIDGET (view)->window,
+ >K_WIDGET (view)->style->black);
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+}
+
+gboolean
+ev_view_next_page (EvView *view)
+{
+ int page, n_pages;
+
+ g_return_val_if_fail (EV_IS_VIEW (view), FALSE);
+
+ if (!view->page_cache)
+ return FALSE;
+
+ ev_view_presentation_transition_stop (view);
+ ev_view_reset_presentation_state (view);
+
+ page = ev_page_cache_get_current_page (view->page_cache);
+ n_pages = ev_page_cache_get_n_pages (view->page_cache);
+
+ if (view->dual_page && !view->presentation)
+ page = page + 2;
+ else
+ page = page + 1;
+
+ if (page < n_pages) {
+ ev_page_cache_set_current_page (view->page_cache, page);
+ return TRUE;
+ } else if (view->presentation && page == n_pages) {
+ view->presentation_state = EV_PRESENTATION_END;
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+ return TRUE;
+ } else if (view->dual_page && page == n_pages) {
+ ev_page_cache_set_current_page (view->page_cache, page - 1);
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+gboolean
+ev_view_previous_page (EvView *view)
+{
+ int page;
+
+ g_return_val_if_fail (EV_IS_VIEW (view), FALSE);
+
+ if (!view->page_cache)
+ return FALSE;
+
+ if (view->presentation &&
+ view->presentation_state == EV_PRESENTATION_END) {
+ ev_view_reset_presentation_state (view);
+ return TRUE;
+ }
+
+ ev_view_reset_presentation_state (view);
+
+ page = ev_page_cache_get_current_page (view->page_cache);
+
+ if (view->dual_page && !view->presentation)
+ page = page - 2;
+ else
+ page = page - 1;
+
+ if (page >= 0) {
+ ev_page_cache_set_current_page (view->page_cache, page);
+ return TRUE;
+ } else if (ev_view_get_dual_page (view) && page == -1) {
+ ev_page_cache_set_current_page (view->page_cache, 0);
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
/*** Enum description for usage in signal ***/
GType
return etype;
}
+GType
+ev_scroll_type_get_type (void)
+{
+ static GType etype = 0;
+ if (etype == 0) {
+ static const GEnumValue values[] = {
+ { EV_SCROLL_PAGE_FORWARD, "EV_SCROLL_PAGE_FORWARD", "scroll-page-forward" },
+ { EV_SCROLL_PAGE_BACKWARD, "EV_SCROLL_PAGE_BACKWARD", "scroll-page-backward" },
+ { EV_SCROLL_STEP_FORWARD, "EV_SCROLL_STEP_FORWARD", "scroll-step-forward" },
+ { EV_SCROLL_STEP_FORWARD, "EV_SCROLL_STEP_FORWARD", "scroll-step-forward" },
+ { EV_SCROLL_STEP_UP, "EV_SCROLL_STEP_UP", "scroll-step-up" },
+ { EV_SCROLL_STEP_DOWN, "EV_SCROLL_STEP_DOWN", "scroll-step-down" },
+ { 0, NULL, NULL }
+ };
+ etype = g_enum_register_static ("EvScrollType", values);
+ }
+ return etype;
+}