* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
+#include <math.h>
#include <gtk/gtkalignment.h>
#include <glib/gi18n.h>
#include <gtk/gtkbindings.h>
#include "ev-marshal.h"
#include "ev-view.h"
#include "ev-document-find.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"
#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))
TARGET_TEXT_BUFFER_CONTENTS
};
+enum {
+ EV_SCROLL_PAGE_FORWARD,
+ EV_SCROLL_PAGE_BACKWARD
+};
+
static const GtkTargetEntry targets[] = {
{ "STRING", 0, TARGET_STRING },
{ "TEXT", 0, TARGET_TEXT },
typedef enum {
EV_VIEW_CURSOR_NORMAL,
EV_VIEW_CURSOR_LINK,
- EV_VIEW_CURSOR_WAIT
+ EV_VIEW_CURSOR_WAIT,
+ EV_VIEW_CURSOR_HIDDEN
} EvViewCursor;
+#define ZOOM_IN_FACTOR 1.2
+#define ZOOM_OUT_FACTOR (1.0/ZOOM_IN_FACTOR)
+
+#define MIN_SCALE 0.05409
+#define MAX_SCALE 18.4884
+
struct _EvView {
GtkWidget parent_instance;
EvDocument *document;
-
+
GdkWindow *bin_window;
char *status;
char *find_status;
-
+
int scroll_x;
int scroll_y;
gboolean pressed_button;
gboolean has_selection;
GdkPoint selection_start;
- GdkRectangle selection;
+ EvRectangle selection;
EvViewCursor cursor;
GtkAdjustment *hadjustment;
GtkAdjustment *vadjustment;
+ EvPageCache *page_cache;
+ EvPixbufCache *pixbuf_cache;
+
+ gint current_page;
+ EvJobRender *current_job;
+
int find_page;
int find_result;
+ int spacing;
double scale;
+ int width;
+ int height;
};
struct _EvViewClass {
void (*scroll_view) (EvView *view,
GtkScrollType scroll,
gboolean horizontal);
-
- /* Should this be notify::page? */
- void (*page_changed) (EvView *view);
+
};
-static guint page_changed_signal = 0;
static void ev_view_set_scroll_adjustments (EvView *view,
GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment);
-
+
G_DEFINE_TYPE (EvView, ev_view, GTK_TYPE_WIDGET)
-/*** Helper functions ***/
-
+/*** Helper functions ***/
+
static void
view_update_adjustments (EvView *view)
{
int old_x = view->scroll_x;
int old_y = view->scroll_y;
-
+
if (view->hadjustment)
view->scroll_x = view->hadjustment->value;
else
view->scroll_y = view->vadjustment->value;
else
view->scroll_y = 0;
-
+
if (GTK_WIDGET_REALIZED (view) &&
(view->scroll_x != old_x || view->scroll_y != old_y)) {
gdk_window_move (view->bin_window, - view->scroll_x, - view->scroll_y);
if (!adjustment)
return;
-
+
adjustment->page_size = allocation;
adjustment->step_increment = allocation * 0.1;
adjustment->page_increment = allocation * 0.9;
gtk_adjustment_value_changed (adjustment);
}
-/*** Virtual function implementations ***/
-
+/*** Virtual function implementations ***/
+
static void
ev_view_finalize (GObject *object)
{
EvView *view = EV_VIEW (object);
- LOG ("Finalize")
+ LOG ("Finalize");
- if (view->document)
- g_object_unref (view->document);
ev_view_set_scroll_adjustments (view, NULL, NULL);
{
EvView *view = EV_VIEW (object);
+ if (view->document) {
+ g_object_unref (view->document);
+ view->document = NULL;
+ }
+ if (view->pixbuf_cache) {
+ g_object_unref (view->pixbuf_cache);
+ view->pixbuf_cache = NULL;
+ }
ev_view_set_scroll_adjustments (view, NULL, NULL);
-
+
GTK_OBJECT_CLASS (ev_view_parent_class)->destroy (object);
}
+static void
+ev_view_get_offsets (EvView *view, int *x_offset, int *y_offset)
+{
+ EvDocument *document = view->document;
+ GtkWidget *widget = GTK_WIDGET (view);
+ int width, height, target_width, target_height;
+ GtkBorder border;
+
+ g_return_if_fail (EV_IS_DOCUMENT (document));
+
+ ev_page_cache_get_size (view->page_cache,
+ view->current_page,
+ view->scale,
+ &width, &height);
+
+ ev_document_misc_get_page_border_size (width, height, &border);
+
+ *x_offset = view->spacing;
+ *y_offset = view->spacing;
+ target_width = width + border.left + border.right + view->spacing * 2;
+ target_height = height + border.top + border.bottom + view->spacing * 2;
+ *x_offset += MAX (0, (widget->allocation.width - target_width) / 2);
+ *y_offset += MAX (0, (widget->allocation.height - target_height) / 2);
+}
+
+static void
+view_rect_to_doc_rect (EvView *view, GdkRectangle *view_rect, EvRectangle *doc_rect)
+{
+ int x_offset, y_offset;
+
+ ev_view_get_offsets (view, &x_offset, &y_offset);
+ doc_rect->x1 = (double) (view_rect->x - x_offset) / view->scale;
+ doc_rect->y1 = (double) (view_rect->y - y_offset) / view->scale;
+ doc_rect->x2 = doc_rect->x1 + (double) view_rect->width / view->scale;
+ doc_rect->y2 = doc_rect->y1 + (double) view_rect->height / view->scale;
+}
+
+static void
+doc_rect_to_view_rect (EvView *view, EvRectangle *doc_rect, GdkRectangle *view_rect)
+{
+ int x_offset, y_offset;
+
+ ev_view_get_offsets (view, &x_offset, &y_offset);
+ view_rect->x = floor (doc_rect->x1 * view->scale) + x_offset;
+ view_rect->y = floor (doc_rect->y1 * view->scale) + y_offset;
+ view_rect->width = ceil (doc_rect->x2 * view->scale) + x_offset - view_rect->x;
+ view_rect->height = ceil (doc_rect->y2 * view->scale) + y_offset - view_rect->y;
+}
+
+
+/* Called by size_request to make sure we have appropriate jobs running.
+ */
static void
ev_view_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
EvView *view = EV_VIEW (widget);
+ GtkBorder border;
+ gint width, height;
- if (GTK_WIDGET_REALIZED (widget)) {
- if (view->document) {
- ev_document_get_page_size (view->document,
- -1,
- &requisition->width,
- &requisition->height);
- } else {
- requisition->width = 10;
- requisition->height = 10;
- }
+ if (!GTK_WIDGET_REALIZED (widget))
+ return;
+
+ if (!view->document) {
+ requisition->width = 1;
+ requisition->height = 1;
+ return;
+ }
+
+ ev_page_cache_get_size (view->page_cache,
+ view->current_page,
+ view->scale,
+ &width, &height);
+
+ ev_pixbuf_cache_set_page_range (view->pixbuf_cache,
+ view->current_page,
+ view->current_page,
+ view->scale);
+ ev_document_misc_get_page_border_size (width, height, &border);
- requisition->width += 2;
- requisition->height += 2;
+ if (view->width >= 0) {
+ requisition->width = 0;
+ } else {
+ requisition->width = width + border.left + border.right +
+ view->spacing * 2;
+ }
+
+ if (view->height >= 0) {
+ requisition->height = 0;
+ } else {
+ requisition->height = height + border.top + border.bottom +
+ view->spacing * 2;
}
-
}
static void
GdkWindowAttr attributes;
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);
attributes.colormap = gtk_widget_get_colormap (widget);
-
+
attributes.x = widget->allocation.x;
attributes.y = widget->allocation.y;
attributes.width = widget->allocation.width;
attributes.height = widget->allocation.height;
attributes.event_mask = 0;
-
+
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes,
GDK_WA_X | GDK_WA_Y |
GDK_WA_VISUAL);
gdk_window_set_user_data (widget->window, widget);
widget->style = gtk_style_attach (widget->style, widget->window);
-
+ gdk_window_set_background (widget->window, &widget->style->mid[widget->state]);
+
attributes.x = 0;
attributes.y = 0;
attributes.width = MAX (widget->allocation.width, widget->requisition.width);
GDK_BUTTON_RELEASE_MASK |
GDK_SCROLL_MASK |
GDK_KEY_PRESS_MASK |
- GDK_POINTER_MOTION_MASK;
-
+ GDK_POINTER_MOTION_MASK |
+ GDK_LEAVE_NOTIFY_MASK;
+
view->bin_window = gdk_window_new (widget->window,
&attributes,
GDK_WA_X | GDK_WA_Y |
gdk_window_set_background (view->bin_window, &widget->style->mid[widget->state]);
if (view->document) {
- ev_document_set_target (view->document, view->bin_window);
-
/* We can't get page size without a target, so we have to
* queue a size request at realization. Could be fixed
* with EvDocument changes to allow setting a GdkScreen
{
EvView *view = EV_VIEW (widget);
- if (view->document)
- ev_document_set_target (view->document, NULL);
-
gdk_window_set_user_data (view->bin_window, NULL);
gdk_window_destroy (view->bin_window);
view->bin_window = NULL;
gdk_draw_pixbuf (window, NULL, pixbuf,
0, 0,
- rect->x,rect->y,
+ rect->x, rect->y,
rect->width, rect->height,
GDK_RGB_DITHER_NONE,
0, 0);
static void
highlight_find_results (EvView *view)
{
- EvDocumentFind *find = EV_DOCUMENT_FIND (view->document);
- int i, results;
+ EvDocumentFind *find;
+ int i, results = 0;
+
+ g_return_if_fail (EV_IS_DOCUMENT_FIND (view->document));
- results = ev_document_find_get_n_results (find);
+ find = EV_DOCUMENT_FIND (view->document);
+
+ g_mutex_lock (EV_DOC_MUTEX);
+ results = ev_document_find_get_n_results (find, view->current_page);
+ g_mutex_unlock (EV_DOC_MUTEX);
for (i = 0; i < results; i++) {
- GdkRectangle rectangle;
+ EvRectangle rectangle;
+ GdkRectangle view_rectangle;
guchar alpha;
alpha = (i == view->find_result) ? 0x90 : 0x20;
- ev_document_find_get_result (find, i, &rectangle);
+ g_mutex_lock (EV_DOC_MUTEX);
+ ev_document_find_get_result (find, view->current_page,
+ i, &rectangle);
+ g_mutex_unlock (EV_DOC_MUTEX);
+ doc_rect_to_view_rect (view, &rectangle, &view_rectangle);
draw_rubberband (GTK_WIDGET (view), view->bin_window,
- &rectangle, alpha);
+ &view_rectangle, alpha);
}
}
+
static void
expose_bin_window (GtkWidget *widget,
GdkEventExpose *event)
{
EvView *view = EV_VIEW (widget);
+ GtkBorder border;
+ gint width, height;
+ GdkRectangle area;
int x_offset, y_offset;
+ GdkPixbuf *scaled_image;
+ GdkPixbuf *current_pixbuf;
if (view->document == NULL)
return;
- x_offset = MAX (0, (widget->allocation.width -
- widget->requisition.width) / 2);
- y_offset = MAX (0, (widget->allocation.height -
- widget->requisition.height) / 2);
- gdk_draw_rectangle (view->bin_window,
- widget->style->black_gc,
- FALSE,
- x_offset,
- y_offset,
- widget->requisition.width - 1,
- widget->requisition.height - 1);
-
- ev_document_set_page_offset (view->document,
- x_offset + 1,
- y_offset + 1);
-
- LOG ("Render area %d %d %d %d", event->area.x, event->area.y,
- event->area.width, event->area.height)
-
- ev_document_render (view->document,
- event->area.x, event->area.y,
- event->area.width, event->area.height);
+ ev_view_get_offsets (view, &x_offset, &y_offset);
+ ev_page_cache_get_size (view->page_cache,
+ view->current_page,
+ view->scale,
+ &width, &height);
+
+ ev_document_misc_get_page_border_size (width, height, &border);
+
+ /* Paint the frame */
+ area.x = x_offset;
+ area.y = y_offset;
+ area.width = width + border.left + border.right;
+ area.height = height + border.top + border.bottom;
+ ev_document_misc_paint_one_page (view->bin_window, widget, &area, &border);
+
+ /* Render the document itself */
+ LOG ("Render area %d %d %d %d - Offset %d %d",
+ event->area.x, event->area.y,
+ event->area.width, event->area.height,
+ x_offset, y_offset);
+
+ current_pixbuf = ev_pixbuf_cache_get_pixbuf (view->pixbuf_cache, view->current_page);
+
+ if (current_pixbuf == NULL)
+ scaled_image = NULL;
+ else if (width == gdk_pixbuf_get_width (current_pixbuf) &&
+ height == gdk_pixbuf_get_height (current_pixbuf))
+ scaled_image = g_object_ref (current_pixbuf);
+ else
+ scaled_image = gdk_pixbuf_scale_simple (current_pixbuf,
+ width, height,
+ GDK_INTERP_NEAREST);
+ if (scaled_image) {
+ gdk_draw_pixbuf (view->bin_window,
+ GTK_WIDGET (view)->style->fg_gc[GTK_STATE_NORMAL],
+ scaled_image,
+ 0, 0,
+ area.x + border.left,
+ area.y + border.top,
+ width, height,
+ GDK_RGB_DITHER_NORMAL,
+ 0, 0);
+ g_object_unref (scaled_image);
+ }
if (EV_IS_DOCUMENT_FIND (view->document)) {
highlight_find_results (view);
}
if (view->has_selection) {
- draw_rubberband (widget, view->bin_window,
- &view->selection, 0x40);
+ GdkRectangle rubberband;
+
+ doc_rect_to_view_rect (view, &view->selection, &rubberband);
+ if (rubberband.width > 0 && rubberband.height > 0) {
+ draw_rubberband (widget, view->bin_window,
+ &rubberband, 0x40);
+ }
}
}
ev_view_select_all (EvView *ev_view)
{
GtkWidget *widget = GTK_WIDGET (ev_view);
+ GdkRectangle selection;
+ int width, height;
+ int x_offset, y_offset;
+ GtkBorder border;
g_return_if_fail (EV_IS_VIEW (ev_view));
+
+ ev_view_get_offsets (ev_view, &x_offset, &y_offset);
+ ev_page_cache_get_size (ev_view->page_cache,
+ ev_view->current_page,
+ ev_view->scale,
+ &width, &height);
+ ev_document_misc_get_page_border_size (width, height, &border);
+
ev_view->has_selection = TRUE;
- ev_view->selection.x = ev_view->selection.y = 0;
- ev_view->selection.width = widget->requisition.width;
- ev_view->selection.height = widget->requisition.height;
+ selection.x = x_offset + border.left;
+ selection.y = y_offset + border.top;
+ selection.width = width;
+ selection.height = height;
+ view_rect_to_doc_rect (ev_view, &selection, &ev_view->selection);
gtk_widget_queue_draw (widget);
}
GtkClipboard *clipboard;
char *text;
- text = ev_document_get_text (ev_view->document, &ev_view->selection);
+ g_mutex_lock (EV_DOC_MUTEX);
+ text = ev_document_get_text (ev_view->document,
+ ev_view->current_page,
+ &ev_view->selection);
+ g_mutex_unlock (EV_DOC_MUTEX);
+
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (ev_view),
GDK_SELECTION_CLIPBOARD);
gtk_clipboard_set_text (clipboard, text, -1);
EvView *ev_view = EV_VIEW (data);
char *text;
- text = ev_document_get_text (ev_view->document, &ev_view->selection);
+ g_mutex_lock (EV_DOC_MUTEX);
+ text = ev_document_get_text (ev_view->document,
+ ev_view->current_page,
+ &ev_view->selection);
+ g_mutex_unlock (EV_DOC_MUTEX);
gtk_selection_data_set_text (selection_data, text, -1);
}
}
static char *
-status_message_from_link (EvLink *link)
+status_message_from_link (EvView *view, EvLink *link)
{
EvLinkType type;
- char *msg;
- int page;
+ char *msg = NULL;
+ char *page_label;
type = ev_link_get_link_type (link);
-
+
switch (type) {
case EV_LINK_TYPE_TITLE:
- msg = g_strdup (ev_link_get_title (link));
+ if (ev_link_get_title (link))
+ msg = g_strdup (ev_link_get_title (link));
break;
case EV_LINK_TYPE_PAGE:
- page = ev_link_get_page (link);
- msg = g_strdup_printf (_("Go to page %d"), 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:
- msg = NULL;
+ break;
}
return msg;
ev_view_set_find_status (EvView *view, const char *message)
{
g_return_if_fail (EV_IS_VIEW (view));
-
+
g_free (view->find_status);
view->find_status = g_strdup (message);
g_object_notify (G_OBJECT (view), "find-status");
}
+static GdkCursor *
+ev_view_create_invisible_cursor(void)
+{
+ GdkBitmap *empty;
+ GdkColor black = { 0, 0, 0, 0 };
+ static char bits[] = { 0x00 };
+
+ empty = gdk_bitmap_create_from_data (NULL, bits, 1, 1);
+
+ return gdk_cursor_new_from_pixmap (empty, empty, &black, &black, 0, 0);
+}
static void
ev_view_set_cursor (EvView *view, EvViewCursor new_cursor)
case EV_VIEW_CURSOR_WAIT:
cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
break;
+ case EV_VIEW_CURSOR_HIDDEN:
+ cursor = ev_view_create_invisible_cursor ();
+ break;
+
}
if (cursor) {
}
}
+
+static void
+find_page_at_location (EvView *view,
+ gdouble x,
+ gdouble y,
+ gint *page,
+ gint *x_offset,
+ gint *y_offset)
+{
+ GtkBorder border;
+ gint width, height;
+
+ ev_page_cache_get_size (view->page_cache,
+ view->current_page,
+ view->scale,
+ &width, &height);
+ ev_document_misc_get_page_border_size (width, height, &border);
+
+ x -= (border.left + view->spacing);
+ y -= (border.top + view->spacing);
+
+ if ((x < 0) || (y < 0) ||
+ (x >= width) || (y >= height)) {
+ *page = -1;
+ return;
+ }
+ *page = view->current_page;
+ *x_offset = (gint) x;
+ *y_offset = (gint) y;
+}
+
+static EvLink *
+get_link_at_location (EvView *view,
+ gdouble x,
+ gdouble y)
+{
+ gint page;
+ gint x_offset, y_offset;
+ GList *link_mapping;
+
+ find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
+ if (page == -1)
+ return NULL;
+
+ link_mapping = ev_pixbuf_cache_get_link_mapping (view->pixbuf_cache, page);
+
+ return ev_link_mapping_find (link_mapping, x_offset /view->scale, y_offset /view->scale);
+}
+
+
static gboolean
ev_view_motion_notify_event (GtkWidget *widget,
GdkEventMotion *event)
EvView *view = EV_VIEW (widget);
if (view->pressed_button > 0) {
+ GdkRectangle selection;
+
view->has_selection = TRUE;
- view->selection.x = MIN (view->selection_start.x, event->x);
- view->selection.y = MIN (view->selection_start.y, event->y);
- view->selection.width = ABS (view->selection_start.x - event->x) + 1;
- view->selection.height = ABS (view->selection_start.y - event->y) + 1;
+ selection.x = MIN (view->selection_start.x, event->x);
+ selection.y = MIN (view->selection_start.y, event->y);
+ selection.width = ABS (view->selection_start.x - event->x) + 1;
+ selection.height = ABS (view->selection_start.y - event->y) + 1;
+ view_rect_to_doc_rect (view, &selection, &view->selection);
gtk_widget_queue_draw (widget);
} else if (view->document) {
EvLink *link;
- link = ev_document_get_link (view->document, event->x, event->y);
+ link = get_link_at_location (view, event->x, event->y);
if (link) {
char *msg;
- msg = status_message_from_link (link);
+ 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);
-
- g_object_unref (link);
} else {
ev_view_set_status (view, NULL);
if (view->cursor == EV_VIEW_CURSOR_LINK) {
} else if (view->document) {
EvLink *link;
- link = ev_document_get_link (view->document,
- event->x,
- event->y);
+ link = get_link_at_location (view, event->x, event->y);
if (link) {
ev_view_go_to_link (view, link);
- g_object_unref (link);
}
}
to_set = &view->hadjustment;
else
to_set = &view->vadjustment;
-
+
if (*to_set != adjustment) {
if (*to_set) {
g_signal_handlers_disconnect_by_func (*to_set,
gboolean horizontal)
{
guint keypad_keyval = keyval - GDK_Left + GDK_KP_Left;
-
+
gtk_binding_entry_add_signal (binding_set, keyval, 0,
"scroll_view", 2,
GTK_TYPE_SCROLL_TYPE, scroll,
G_TYPE_BOOLEAN, horizontal);
}
+static void
+ev_view_jump (EvView *view,
+ GtkScrollType scroll)
+{
+ GtkAdjustment *adjustment;
+ double value, increment;
+ gboolean first_page = FALSE;
+ gboolean last_page = FALSE;
+
+ /* Assign values for increment and vertical adjustment */
+ adjustment = view->vadjustment;
+ increment = adjustment->page_size * 0.75;
+ value = adjustment->value;
+
+ /* Assign boolean for first and last page */
+ if (view->current_page == 0)
+ first_page = TRUE;
+ if (view->current_page == ev_page_cache_get_n_pages (view->page_cache) - 1)
+ last_page = TRUE;
+
+ switch (scroll) {
+ case EV_SCROLL_PAGE_BACKWARD:
+ /* Do not jump backwards if at the first page */
+ if (value == (adjustment->lower) && first_page) {
+ /* Do nothing */
+ /* 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);
+ /* Jump to the top */
+ } else {
+ value = MAX (value - increment, adjustment->lower);
+ }
+ break;
+ case EV_SCROLL_PAGE_FORWARD:
+ /* Do not jump forward if at the last page */
+ if (value == (adjustment->upper - adjustment->page_size) && last_page) {
+ /* Do nothing */
+ /* 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);
+ /* 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_scroll_view (EvView *view,
GtkScrollType scroll,
gboolean horizontal)
{
if (scroll == GTK_SCROLL_PAGE_BACKWARD) {
- ev_view_set_page (view, ev_view_get_page (view) - 1);
+ ev_page_cache_prev_page (view->page_cache);
} else if (scroll == GTK_SCROLL_PAGE_FORWARD) {
- ev_view_set_page (view, ev_view_get_page (view) + 1);
+ ev_page_cache_next_page (view->page_cache);
+ } else if (scroll == EV_SCROLL_PAGE_BACKWARD || scroll == EV_SCROLL_PAGE_FORWARD) {
+ ev_view_jump (view, scroll);
} else {
GtkAdjustment *adjustment;
double value;
if (horizontal) {
- adjustment = view->hadjustment;
+ adjustment = view->hadjustment;
} else {
adjustment = view->vadjustment;
}
value = adjustment->value;
switch (scroll) {
- case GTK_SCROLL_STEP_BACKWARD:
- value -= adjustment->step_increment;
+ case GTK_SCROLL_STEP_BACKWARD:
+ value -= adjustment->step_increment;
break;
case GTK_SCROLL_STEP_FORWARD:
- value += adjustment->step_increment;
+ value += adjustment->step_increment;
break;
default:
break;
G_TYPE_NONE, 2,
GTK_TYPE_ADJUSTMENT,
GTK_TYPE_ADJUSTMENT);
- page_changed_signal = g_signal_new ("page-changed",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (EvViewClass, page_changed),
- NULL, NULL,
- ev_marshal_VOID__NONE,
- G_TYPE_NONE, 0);
g_signal_new ("scroll_view",
G_TYPE_FROM_CLASS (object_class),
G_PARAM_READABLE));
g_object_class_install_property (object_class,
- PROP_STATUS,
+ PROP_FIND_STATUS,
g_param_spec_string ("find-status",
"Find Status Message",
"The find status message",
add_scroll_binding (binding_set, GDK_Page_Up, GTK_SCROLL_PAGE_BACKWARD, FALSE);
add_scroll_binding (binding_set, GDK_Page_Down, GTK_SCROLL_PAGE_FORWARD, FALSE);
+
+ add_scroll_binding (binding_set, GDK_space, EV_SCROLL_PAGE_FORWARD, FALSE);
+ add_scroll_binding (binding_set, GDK_BackSpace, EV_SCROLL_PAGE_BACKWARD, FALSE);
}
static void
{
GTK_WIDGET_SET_FLAGS (view, GTK_CAN_FOCUS);
+ view->spacing = 10;
view->scale = 1.0;
+ view->current_page = 0;
view->pressed_button = -1;
view->cursor = EV_VIEW_CURSOR_NORMAL;
}
{
char *message;
- if (ev_document_get_page (view->document) == view->find_page) {
+// g_mutex_lock (EV_DOC_MUTEX);
+ if (view->current_page == view->find_page) {
int results;
+// g_mutex_lock (EV_DOC_MUTEX);
results = ev_document_find_get_n_results
- (EV_DOCUMENT_FIND (view->document));
-
- message = g_strdup_printf (_("%d found on this page"),
+ (EV_DOCUMENT_FIND (view->document),
+ view->current_page);
+// g_mutex_unlock (EV_DOC_MUTEX);
+ /* TRANS: Sometimes this could be better translated as
+ "%d hit(s) on this page". Therefore this string
+ contains plural cases. */
+ message = g_strdup_printf (ngettext ("%d found on this page",
+ "%d found on this page",
+ results),
results);
} else {
double percent;
-
+
+ g_mutex_lock (EV_DOC_MUTEX);
percent = ev_document_find_get_progress
(EV_DOCUMENT_FIND (view->document));
-
+ g_mutex_unlock (EV_DOC_MUTEX);
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));
}
-
+
}
+// g_mutex_unlock (EV_DOC_MUTEX);
ev_view_set_find_status (view, message);
- g_free (message);
-}
-
-static void
-set_document_page (EvView *view, int new_page)
-{
- int page;
- int pages;
-
- pages = ev_document_get_n_pages (view->document);
- page = CLAMP (new_page, 1, pages);
-
- if (view->document) {
- int old_page = ev_document_get_page (view->document);
- int old_width, old_height;
-
- ev_document_get_page_size (view->document,
- -1,
- &old_width, &old_height);
-
- if (old_page != page) {
- ev_view_set_cursor (view, EV_VIEW_CURSOR_WAIT);
- ev_document_set_page (view->document, page);
- }
-
- if (old_page != ev_document_get_page (view->document)) {
- int width, height;
-
- g_signal_emit (view, page_changed_signal, 0);
-
- view->has_selection = FALSE;
- ev_document_get_page_size (view->document,
- -1,
- &width, &height);
- if (width != old_width || height != old_height)
- gtk_widget_queue_resize (GTK_WIDGET (view));
-
- gtk_adjustment_set_value (view->vadjustment,
- view->vadjustment->lower);
- }
-
- view->find_page = page;
- view->find_result = 0;
-
- if (EV_IS_DOCUMENT_FIND (view->document)) {
- update_find_status_message (view);
- }
- }
+// g_free (message);
}
#define MARGIN 5
jump_to_find_result (EvView *view)
{
EvDocumentFind *find = EV_DOCUMENT_FIND (view->document);
- GdkRectangle rect;
+ EvRectangle rect;
+ GdkRectangle view_rect;
int n_results;
- n_results = ev_document_find_get_n_results (find);
+ g_mutex_lock (EV_DOC_MUTEX);
+ n_results = ev_document_find_get_n_results (find, view->current_page);
+ g_mutex_unlock (EV_DOC_MUTEX);
if (n_results > view->find_result) {
+ g_mutex_lock (EV_DOC_MUTEX);
ev_document_find_get_result
- (find, view->find_result, &rect);
- ensure_rectangle_is_visible (view, &rect);
+ (find, view->current_page, view->find_result, &rect);
+ g_mutex_unlock (EV_DOC_MUTEX);
+
+ doc_rect_to_view_rect (view, &rect, &view_rect);
+ ensure_rectangle_is_visible (view, &view_rect);
}
}
{
int n_pages, i;
- n_pages = ev_document_get_n_pages (view->document);
+ n_pages = ev_page_cache_get_n_pages (view->page_cache);
- for (i = 0; i <= n_pages; i++) {
+ for (i = 0; i < n_pages; i++) {
int has_results;
int page;
page = i + view->find_page;
- if (page > n_pages) {
+ if (page >= n_pages) {
page = page - n_pages;
}
+ // g_mutex_lock (EV_DOC_MUTEX);
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) {
- set_document_page (view, page);
+ ev_page_cache_set_current_page (view->page_cache, page);
jump_to_find_result (view);
break;
}
jump_to_find_result (view);
update_find_status_message (view);
- if (ev_document_get_page (document) == page) {
+ if (view->current_page == page)
gtk_widget_queue_draw (GTK_WIDGET (view));
- }
+}
+/*** Public API ***/
+
+GtkWidget*
+ev_view_new (void)
+{
+ return g_object_new (EV_TYPE_VIEW, NULL);
}
static void
-document_changed_callback (EvDocument *document,
- EvView *view)
+job_finished_cb (EvPixbufCache *pixbuf_cache,
+ EvView *view)
{
gtk_widget_queue_draw (GTK_WIDGET (view));
- ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
}
-/*** Public API ***/
-
-GtkWidget*
-ev_view_new (void)
+
+static void
+page_changed_cb (EvPageCache *page_cache,
+ int new_page,
+ EvView *view)
{
- return g_object_new (EV_TYPE_VIEW, NULL);
+ int old_page = view->current_page;
+ int old_width, old_height;
+ int new_width, new_height;
+
+ if (old_page == new_page)
+ return;
+
+ ev_page_cache_get_size (page_cache,
+ old_page,
+ view->scale,
+ &old_width, &old_height);
+ ev_page_cache_get_size (page_cache,
+ new_page,
+ view->scale,
+ &new_width, &new_height);
+
+ if (view->cursor != EV_VIEW_CURSOR_HIDDEN) {
+ //ev_view_set_cursor (view, EV_VIEW_CURSOR_WAIT);
+ }
+
+ view->current_page = new_page;
+ view->has_selection = FALSE;
+
+ ev_pixbuf_cache_set_page_range (view->pixbuf_cache,
+ view->current_page,
+ view->current_page,
+ view->scale);
+
+ if (new_width != old_width || new_height != old_height)
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+ else
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+
+ gtk_adjustment_set_value (view->vadjustment,
+ view->vadjustment->lower);
+
+ if (EV_IS_DOCUMENT_FIND (view->document)) {
+ view->find_page = new_page;
+ view->find_result = 0;
+ update_find_status_message (view);
+ }
}
void
if (document != view->document) {
if (view->document) {
- g_signal_handlers_disconnect_by_func
- (view->document, find_changed_cb, view);
+ g_signal_handlers_disconnect_by_func (view->document,
+ find_changed_cb,
+ view);
g_object_unref (view->document);
+ view->page_cache = NULL;
+
}
view->document = document;
- view->find_page = 1;
+ view->find_page = 0;
view->find_result = 0;
if (view->document) {
G_CALLBACK (find_changed_cb),
view);
}
- g_signal_connect (view->document,
- "changed",
- G_CALLBACK (document_changed_callback),
- view);
+ view->page_cache = ev_document_get_page_cache (view->document);
+ g_signal_connect (view->page_cache, "page-changed", G_CALLBACK (page_changed_cb), view);
+ view->pixbuf_cache = ev_pixbuf_cache_new (view->document);
+ g_signal_connect (view->pixbuf_cache, "job-finished", G_CALLBACK (job_finished_cb), view);
}
- if (GTK_WIDGET_REALIZED (view))
- ev_document_set_target (view->document, view->bin_window);
-
gtk_widget_queue_resize (GTK_WIDGET (view));
-
- g_signal_emit (view, page_changed_signal, 0);
}
}
+int
+ev_view_get_page (EvView *view)
+{
+ return view->current_page;
+}
+
static void
go_to_link (EvView *view, EvLink *link)
{
int page;
type = ev_link_get_link_type (link);
-
+
switch (type) {
case EV_LINK_TYPE_TITLE:
break;
case EV_LINK_TYPE_PAGE:
page = ev_link_get_page (link);
- set_document_page (view, page);
+ ev_page_cache_set_current_page (view->page_cache, page);
break;
case EV_LINK_TYPE_EXTERNAL_URI:
uri = ev_link_get_uri (link);
go_to_link (view, link);
}
-void
-ev_view_set_page (EvView *view,
- int page)
-{
- g_return_if_fail (EV_IS_VIEW (view));
-
- set_document_page (view, page);
-}
-
-int
-ev_view_get_page (EvView *view)
-{
- if (view->document)
- return ev_document_get_page (view->document);
- else
- return 1;
-}
-
-#define ZOOM_IN_FACTOR 1.2
-#define ZOOM_OUT_FACTOR (1.0/ZOOM_IN_FACTOR)
-
-#define MIN_SCALE 0.05409
-#define MAX_SCALE 18.4884
-
static void
ev_view_zoom (EvView *view,
double factor,
else
scale = factor;
- view->scale = CLAMP (scale, MIN_SCALE, MAX_SCALE);
-
- ev_document_set_scale (view->document, view->scale);
+ scale = CLAMP (scale, MIN_SCALE, MAX_SCALE);
+ view->scale = scale;
gtk_widget_queue_resize (GTK_WIDGET (view));
}
void
ev_view_zoom_in (EvView *view)
{
+ view->width = view->height = -1;
ev_view_zoom (view, ZOOM_IN_FACTOR, TRUE);
}
void
ev_view_zoom_out (EvView *view)
{
+ view->width = view->height = -1;
ev_view_zoom (view, ZOOM_OUT_FACTOR, TRUE);
}
-void
-ev_view_normal_size (EvView *view)
+static double
+size_to_zoom_factor (EvView *view, int width, int height)
{
- ev_view_zoom (view, 1.0, FALSE);
-}
+ int doc_width, doc_height;
+ double scale, scale_w, scale_h;
+ GtkBorder border;
+
+ doc_width = doc_height = 0;
+ scale = scale_w = scale_h = 1.0;
+ ev_page_cache_get_size (view->page_cache,
+ view->current_page,
+ view->scale,
+ &doc_width,
+ &doc_height);
+
+ /* FIXME: The border size isn't constant. Ugh. Still, if we have extra
+ * space, we just cut it from the border */
+ ev_document_misc_get_page_border_size (doc_width, doc_height, &border);
+
+ if (doc_width == 0 && doc_height == 0) {
+ return 0;
+ }
-void
-ev_view_best_fit (EvView *view)
-{
- double scale;
- int width, height;
+ if (width >= 0) {
+ int target_width;
- width = height = 0;
- ev_document_get_page_size (view->document, -1, &width, &height);
+ target_width = width - (view->spacing * 2 + border.left + border.right);
+ scale = scale_w = (double)target_width * view->scale / doc_width;
+ }
- scale = 1.0;
- if (width != 0 && height != 0) {
- double scale_w, scale_h;
+ if (height >= 0) {
+ int target_height;
- scale_w = (double)GTK_WIDGET (view)->allocation.width * view->scale / width;
- scale_h = (double)GTK_WIDGET (view)->allocation.height * view->scale / height;
+ target_height = height - (view->spacing * 2 + border.top + border.bottom);
+ scale = scale_h = (double)target_height * view->scale / doc_height;
+ }
+ if (width >= 0 && height >= 0) {
scale = (scale_w < scale_h) ? scale_w : scale_h;
}
- ev_view_zoom (view, scale, FALSE);
+ return scale;
}
void
-ev_view_fit_width (EvView *view)
+ev_view_set_size (EvView *view,
+ int width,
+ int height)
{
- double scale = 1.0;
- int width;
-
- width = 0;
- ev_document_get_page_size (view->document, -1, &width, NULL);
+ double factor;
- scale = 1.0;
- if (width != 0)
- scale = (double)GTK_WIDGET (view)->allocation.width * view->scale / width;
+ if (!view->document)
+ return;
- ev_view_zoom (view, scale, FALSE);
+ if (view->width != width ||
+ view->height != height) {
+ view->width = width;
+ view->height = height;
+ factor = size_to_zoom_factor (view, width, height);
+ ev_view_zoom (view, factor, FALSE);
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+ }
}
const char *
return view->find_status;
}
+gboolean
+ev_view_can_find_next (EvView *view)
+{
+ int n_results = 0;
+
+ if (view->document) {
+ EvDocumentFind *find = EV_DOCUMENT_FIND (view->document);
+
+ g_mutex_lock (EV_DOC_MUTEX);
+ n_results = ev_document_find_get_n_results (find, view->current_page);
+ g_mutex_unlock (EV_DOC_MUTEX);
+ }
+
+ return n_results > 0;
+}
+
void
ev_view_find_next (EvView *view)
{
+ EvPageCache *page_cache;
int n_results, n_pages;
EvDocumentFind *find = EV_DOCUMENT_FIND (view->document);
- n_results = ev_document_find_get_n_results (find);
- n_pages = ev_document_get_n_pages (view->document);
+ page_cache = ev_document_get_page_cache (view->document);
+ g_mutex_lock (EV_DOC_MUTEX);
+ n_results = ev_document_find_get_n_results (find, view->current_page);
+ g_mutex_unlock (EV_DOC_MUTEX);
+
+ n_pages = ev_page_cache_get_n_pages (page_cache);
view->find_result++;
view->find_result = 0;
view->find_page++;
- if (view->find_page > n_pages) {
- view->find_page = 1;
+ if (view->find_page >= n_pages) {
+ view->find_page = 0;
}
jump_to_find_page (view);
{
int n_results, n_pages;
EvDocumentFind *find = EV_DOCUMENT_FIND (view->document);
+ EvPageCache *page_cache;
+
+ page_cache = ev_document_get_page_cache (view->document);
+
+ g_mutex_lock (EV_DOC_MUTEX);
+ n_results = ev_document_find_get_n_results (find, view->current_page);
+ g_mutex_unlock (EV_DOC_MUTEX);
- n_results = ev_document_find_get_n_results (find);
- n_pages = ev_document_get_n_pages (view->document);
+ n_pages = ev_page_cache_get_n_pages (page_cache);
view->find_result--;
view->find_result = 0;
view->find_page--;
- if (view->find_page < 1) {
- view->find_page = n_pages;
+ if (view->find_page < 0) {
+ view->find_page = n_pages - 1;
}
jump_to_find_page (view);
gtk_widget_queue_draw (GTK_WIDGET (view));
}
}
+void
+ev_view_hide_cursor (EvView *view)
+{
+ ev_view_set_cursor (view, EV_VIEW_CURSOR_HIDDEN);
+}
+
+void
+ev_view_show_cursor (EvView *view)
+{
+ ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
+}