* 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-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))
enum {
PROP_0,
PROP_STATUS,
- PROP_FIND_STATUS
+ PROP_FIND_STATUS,
+ PROP_CONTINUOUS,
+ PROP_DUAL_PAGE,
+ PROP_FULLSCREEN,
+ PROP_PRESENTATION,
+ PROP_SIZING_MODE,
};
enum {
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 },
#define ZOOM_OUT_FACTOR (1.0/ZOOM_IN_FACTOR)
#define MIN_SCALE 0.05409
-#define MAX_SCALE 18.4884
-
-/* FIXME: temporarily setting the epsilon very high until we figure out how to
- * constrain the size of the window to a pixel width, instead of to the zoom
- * level */
-#define ZOOM_EPSILON 1e-2
+#define MAX_SCALE 6.0
+typedef struct {
+ EvRectangle rect;
+ int page;
+} EvViewSelection;
struct _EvView {
GtkWidget parent_instance;
EvDocument *document;
-
+
GdkWindow *bin_window;
char *status;
char *find_status;
-
+
int scroll_x;
int scroll_y;
- int x_offset;
- int y_offset;
-
gboolean pressed_button;
- gboolean has_selection;
GdkPoint selection_start;
- GdkRectangle selection;
+ GList *selections;
EvViewCursor cursor;
GtkAdjustment *hadjustment;
GtkAdjustment *vadjustment;
+ 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;
double scale;
+ GtkBorder border;
+
+ gboolean continuous;
+ gboolean dual_page;
+ gboolean fullscreen;
+ gboolean presentation;
EvSizingMode sizing_mode;
};
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);
-
+static void ev_view_set_scroll_adjustments (EvView *view,
+ GtkAdjustment *hadjustment,
+ GtkAdjustment *vadjustment);
+static void get_bounding_box_size (EvView *view,
+ int *max_width,
+ int *max_height);
+static void view_update_range_and_current_page (EvView *view);
+
+static void page_changed_cb (EvPageCache *page_cache,
+ int new_page,
+ EvView *view);
+
+
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);
- gdk_window_process_updates (view->bin_window, TRUE);
+ // gdk_window_process_updates (view->bin_window, TRUE);
}
+
+ if (view->document)
+ view_update_range_and_current_page (view);
}
static void
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 ***/
-
+static void
+view_update_range_and_current_page (EvView *view)
+{
+ /* Presentation trumps all other modes */
+ if (view->presentation) {
+ view->start_page = view->current_page;
+ view->end_page = view->current_page;
+ } else if (view->continuous) {
+ GdkRectangle current_area, unused, page_area;
+ gint current_page;
+ gboolean found = FALSE;
+ int i;
+
+ get_bounding_box_size (view, &(page_area.width), &(page_area.height));
+ page_area.x = view->spacing;
+ page_area.y = view->spacing;
+
+ if (view->hadjustment) {
+ current_area.x = view->hadjustment->value;
+ current_area.width = view->hadjustment->page_size;
+ } else {
+ current_area.x = page_area.x;
+ current_area.width = page_area.width;
+ }
+
+ if (view->vadjustment) {
+ current_area.y = view->vadjustment->value;
+ current_area.height = view->vadjustment->page_size;
+ } else {
+ current_area.y = page_area.y;
+ current_area.height = page_area.height;
+ }
+
+ for (i = 0; i < ev_page_cache_get_n_pages (view->page_cache); i++) {
+ if (gdk_rectangle_intersect (¤t_area, &page_area, &unused)) {
+ if (! found) {
+ view->start_page = i;
+ found = TRUE;
+
+ }
+ view->end_page = i;
+ } else if (found) {
+ break;
+ }
+ if (view->dual_page) {
+ if (i % 2 == 0) {
+ page_area.x += page_area.width + view->spacing;
+ } else {
+ page_area.x = view->spacing;
+ page_area.y += page_area.height + view->spacing;
+ }
+ } else {
+ page_area.y += page_area.height + view->spacing;
+ }
+ }
+
+ current_page = ev_page_cache_get_current_page (view->page_cache);
+
+ if (current_page < view->start_page || current_page > view->end_page) {
+ g_signal_handlers_block_by_func (view->page_cache, page_changed_cb, view);
+ ev_page_cache_set_current_page (view->page_cache, view->start_page);
+ g_signal_handlers_unblock_by_func (view->page_cache, page_changed_cb, view);
+ }
+ } else {
+ if (view->dual_page) {
+ if (view->current_page % 2 == 0) {
+ 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->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;
+ }
+ }
+
+ ev_pixbuf_cache_set_page_range (view->pixbuf_cache,
+ view->start_page,
+ view->end_page,
+ view->scale);
+}
+
+static void
+clear_selection (EvView *view)
+{
+ g_list_foreach (view->selections, (GFunc)g_free, NULL);
+ view->selections = NULL;
+}
+
+/*** Virtual function implementations ***/
+
static void
ev_view_finalize (GObject *object)
{
LOG ("Finalize");
- if (view->document)
- g_object_unref (view->document);
+ g_free (view->status);
+ g_free (view->find_status);
- ev_view_set_scroll_adjustments (view, NULL, NULL);
+ clear_selection (view);
G_OBJECT_CLASS (ev_view_parent_class)->finalize (object);
}
{
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
-view_rect_to_doc_rect (EvView *view, GdkRectangle *view_rect, GdkRectangle *doc_rect)
+compute_border (EvView *view, int width, int height, GtkBorder *border)
+{
+ if (view->presentation) {
+ border->left = 0;
+ border->right = 0;
+ border->top = 0;
+ border->bottom = 0;
+ } else {
+ ev_document_misc_get_page_border_size (width, height, border);
+ }
+}
+
+static gboolean
+get_page_extents (EvView *view,
+ gint page,
+ GdkRectangle *page_area,
+ GtkBorder *border)
+{
+ GtkWidget *widget;
+ int width, height;
+
+ widget = GTK_WIDGET (view);
+
+ /* Quick sanity check */
+ if (view->presentation) {
+ if (view->current_page != page)
+ return FALSE;
+ } else if (view->continuous) {
+ if (page < view->start_page ||
+ page > view->end_page)
+ return FALSE;
+ } else if (view->dual_page) {
+ if (ABS (page - view->current_page) > 1)
+ return FALSE;
+ } else {
+ if (view->current_page != page)
+ return FALSE;
+ }
+
+ /* Get the size of the page */
+ ev_page_cache_get_size (view->page_cache, page,
+ view->scale,
+ &width, &height);
+ compute_border (view, width, height, border);
+ page_area->width = width + border->left + border->right;
+ page_area->height = height + border->top + border->bottom;
+
+ if (view->presentation) {
+ page_area->x = (MAX (0, widget->allocation.width - width))/2;
+ page_area->y = (MAX (0, widget->allocation.height - height))/2;
+ } else if (view->continuous) {
+ gint max_width, max_height;
+ gint x, y;
+
+ get_bounding_box_size (view, &max_width, &max_height);
+ /* Get the location of the bounding box */
+ if (view->dual_page) {
+ x = view->spacing + (page % 2) * (max_width + view->spacing);
+ y = view->spacing + (page / 2) * (max_height + view->spacing);
+ x = x + MAX (0, widget->allocation.width - (max_width * 2 + view->spacing * 3))/2;
+ } else {
+ x = view->spacing;
+ y = view->spacing + page * (max_height + view->spacing);
+ x = x + MAX (0, widget->allocation.width - (max_width + view->spacing * 2))/2;
+ }
+ page_area->x = x;
+ page_area->y = y;
+ } else {
+ gint x, y;
+ if (view->dual_page) {
+ gint width_2, height_2;
+ gint max_width = width;
+ gint max_height = height;
+ GtkBorder overall_border;
+ gint other_page;
+
+ other_page = page ^ 1;
+
+ /* First, we get the bounding box of the two pages */
+ if (other_page < ev_page_cache_get_n_pages (view->page_cache)) {
+ ev_page_cache_get_size (view->page_cache,
+ page + 1,
+ view->scale,
+ &width_2, &height_2);
+ if (width_2 > width)
+ max_width = width_2;
+ if (height_2 > height)
+ max_height = height_2;
+ }
+ compute_border (view, max_width, max_height, &overall_border);
+
+ /* Find the offsets */
+ x = view->spacing;
+ y = view->spacing;
+
+ /* Adjust for being the left or right page */
+ if (page % 2 == 0)
+ x = x + max_width - width;
+ else
+ x = x + (max_width + overall_border.left + overall_border.right) + view->spacing;
+
+ y = y + (max_height - height)/2;
+
+ /* Adjust for extra allocation */
+ x = x + MAX (0, widget->allocation.width -
+ ((max_width + overall_border.left + overall_border.right) * 2 + view->spacing * 3))/2;
+ y = y + MAX (0, widget->allocation.height - (height + view->spacing * 2))/2;
+ } else {
+ x = view->spacing;
+ y = view->spacing;
+
+ /* Adjust for extra allocation */
+ x = x + MAX (0, widget->allocation.width - (width + view->spacing * 2))/2;
+ y = y + MAX (0, widget->allocation.height - (height + view->spacing * 2))/2;
+ }
+
+ page_area->x = x;
+ page_area->y = y;
+ }
+
+ return TRUE;
+}
+
+static void
+view_rect_to_doc_rect (EvView *view,
+ GdkRectangle *view_rect,
+ GdkRectangle *page_area,
+ EvRectangle *doc_rect)
+{
+ doc_rect->x1 = floor ((view_rect->x - page_area->x) / view->scale);
+ doc_rect->y1 = floor ((view_rect->y - page_area->y) / view->scale);
+ doc_rect->x2 = doc_rect->x1 + ceil (view_rect->width / view->scale);
+ doc_rect->y2 = doc_rect->y1 + ceil (view_rect->height / view->scale);
+}
+
+static void
+compute_selections (EvView *view, GdkRectangle *view_rect)
+{
+ int n_pages, i;
+
+ clear_selection (view);
+
+ n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ for (i = 0; i < n_pages; i++) {
+ GdkRectangle page_area;
+ GtkBorder border;
+
+ if (get_page_extents (view, i, &page_area, &border)) {
+ GdkRectangle overlap;
+
+ if (gdk_rectangle_intersect (&page_area, view_rect, &overlap)) {
+ EvViewSelection *selection;
+
+ selection = g_new0 (EvViewSelection, 1);
+ selection->page = i;
+ view_rect_to_doc_rect (view, &overlap, &page_area,
+ &(selection->rect));
+
+ view->selections = g_list_append
+ (view->selections, selection);
+ }
+ }
+ }
+}
+
+static void
+doc_rect_to_view_rect (EvView *view,
+ int page,
+ EvRectangle *doc_rect,
+ GdkRectangle *view_rect)
{
- doc_rect->x = (view_rect->x - view->x_offset) / view->scale;
- doc_rect->y = (view_rect->y - view->y_offset) / view->scale;
- doc_rect->width = view_rect->width / view->scale;
- doc_rect->height = view_rect->height / view->scale;
+ GdkRectangle page_area;
+ GtkBorder border;
+ int width, height;
+
+ get_page_extents (view, page, &page_area, &border);
+
+ width = doc_rect->x2 - doc_rect->x1;
+ height = doc_rect->y2 - doc_rect->y1;
+ view_rect->x = floor (doc_rect->x1 * view->scale) + page_area.x;
+ view_rect->y = floor (doc_rect->y1 * view->scale) + page_area.y;
+ view_rect->width = ceil (width * view->scale);
+ view_rect->height = ceil (height * view->scale);
}
static void
-doc_rect_to_view_rect (EvView *view, GdkRectangle *doc_rect, GdkRectangle *view_rect)
+get_bounding_box_size (EvView *view, int *max_width, int *max_height)
{
- view_rect->x = doc_rect->x * view->scale + view->x_offset;
- view_rect->y = doc_rect->y * view->scale + view->y_offset;
- view_rect->width = doc_rect->width * view->scale;
- view_rect->height = doc_rect->height * view->scale;
+ GtkBorder border;
+ int width, height;
+
+ if (max_width) {
+ ev_page_cache_get_max_width_size (view->page_cache,
+ view->scale,
+ &width, &height);
+ compute_border (view, width, height, &border);
+ *max_width = width + border.left + border.right;
+ }
+
+
+ if (max_height) {
+ ev_page_cache_get_max_height_size (view->page_cache,
+ view->scale,
+ &width, &height);
+ compute_border (view, width, height, &border);
+ *max_height = height + border.top + border.bottom;
+ }
+}
+
+
+static void
+ev_view_size_request_continuous_and_dual_page (EvView *view,
+ GtkRequisition *requisition)
+{
+ int max_width, max_height;
+ int n_rows;
+
+ get_bounding_box_size (view, &max_width, &max_height);
+
+ n_rows = (1 + ev_page_cache_get_n_pages (view->page_cache)) / 2;
+
+ requisition->width = (max_width * 2) + (view->spacing * 3);
+ requisition->height = max_height * n_rows + (view->spacing * (n_rows + 1));
+
+ 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, max_height;
+ int n_pages;
+
+ get_bounding_box_size (view, &max_width, &max_height);
+
+ n_pages = ev_page_cache_get_n_pages (view->page_cache);
+
+ requisition->width = max_width + (view->spacing * 2);
+ requisition->height = max_height * n_pages + (view->spacing * (n_pages + 1));
+
+ 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_dual_page (EvView *view,
+ GtkRequisition *requisition)
+{
+ GtkBorder border;
+ gint width, height;
+
+ /* Find the largest of the two. */
+ ev_page_cache_get_size (view->page_cache,
+ view->current_page,
+ view->scale,
+ &width, &height);
+ if (view->current_page + 1 < ev_page_cache_get_n_pages (view->page_cache)) {
+ gint width_2, height_2;
+ ev_page_cache_get_size (view->page_cache,
+ view->current_page + 1,
+ view->scale,
+ &width_2, &height_2);
+ if (width_2 > width) {
+ width = width_2;
+ height = height_2;
+ }
+ }
+ compute_border (view, width, height, &border);
+
+ requisition->width = ((width + border.left + border.right) * 2) +
+ (view->spacing * 3);
+ requisition->height = (height + border.top + border.bottom) +
+ (view->spacing * 2);
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ requisition->width = 1;
+ } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
+ requisition->width = 1;
+ requisition->height = 1;
+ }
+}
+
+static void
+ev_view_size_request_single_page (EvView *view,
+ GtkRequisition *requisition)
+{
+ GtkBorder border;
+ gint width, height;
+
+ ev_page_cache_get_size (view->page_cache,
+ view->current_page,
+ view->scale,
+ &width, &height);
+ compute_border (view, width, height, &border);
+
+ requisition->width = width + border.left + border.right + (2 * view->spacing);
+ requisition->height = height + border.top + border.bottom + (2 * view->spacing);
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ requisition->width = 1;
+ requisition->height = height + border.top + border.bottom + (2 * view->spacing);
+ } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
+ requisition->width = 1;
+ requisition->height = 1;
+ }
}
static void
GtkRequisition *requisition)
{
EvView *view = EV_VIEW (widget);
- GtkBorder border;
- gint width, height;
- if (! GTK_WIDGET_REALIZED (widget))
+ if (!GTK_WIDGET_REALIZED (widget))
return;
- if (! view->document) {
+ if (view->document == NULL) {
requisition->width = 1;
requisition->height = 1;
return;
}
- ev_document_get_page_size (view->document, -1,
- &width, &height);
- ev_document_misc_get_page_border_size (width, height, &border);
-
- switch (view->sizing_mode) {
- case EV_SIZING_BEST_FIT:
- requisition->width = MIN_SCALE * ((float) width) / view->scale;
- requisition->height = MIN_SCALE * ((float) height) / view->scale;
- break;
- case EV_SIZING_FIT_WIDTH:
- requisition->width = MIN_SCALE * ((float) width) / view->scale;
- requisition->height = height + border.top + border.bottom;
- requisition->height += view->spacing * 2;
- break;
- case EV_SIZING_FREE:
- requisition->width = width + border.left + border.right;
- requisition->height = height + border.top + border.bottom;
- requisition->width += view->spacing * 2;
- requisition->height += view->spacing * 2;
- break;
+ if (view->presentation) {
+ requisition->width = 1;
+ requisition->height = 1;
+ return;
}
+
+ if (view->continuous && view->dual_page)
+ ev_view_size_request_continuous_and_dual_page (view, requisition);
+ else if (view->continuous)
+ ev_view_size_request_continuous (view, requisition);
+ else if (view->dual_page)
+ ev_view_size_request_dual_page (view, requisition);
+ else
+ ev_view_size_request_single_page (view, requisition);
}
static void
GtkAllocation *allocation)
{
EvView *view = EV_VIEW (widget);
- gint target_width, target_height;
- GtkBorder border;
- gint width, height;
GTK_WIDGET_CLASS (ev_view_parent_class)->size_allocate (widget, allocation);
view_set_adjustment_values (view, GTK_ORIENTATION_HORIZONTAL);
view_set_adjustment_values (view, GTK_ORIENTATION_VERTICAL);
- if (view->document) {
- ev_document_get_page_size (view->document, -1,
- &width, &height);
- ev_document_misc_get_page_border_size (width, height, &border);
- view->x_offset = view->spacing;
- view->y_offset = view->spacing;
- target_width = width + border.left + border.right + view->spacing * 2;
- target_height = height + border.top + border.bottom + view->spacing * 2;
- view->x_offset += MAX (0, (widget->allocation.width - target_width) / 2);
- view->y_offset += MAX (0, (widget->allocation.height - target_height) / 2);
- }
-
if (GTK_WIDGET_REALIZED (widget)) {
gdk_window_resize (view->bin_window,
MAX (widget->allocation.width, widget->requisition.width),
MAX (widget->allocation.height, widget->requisition.height));
}
+
+ if (view->document)
+ view_update_range_and_current_page (view);
}
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_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_KEY_PRESS_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_show (view->bin_window);
widget->style = gtk_style_attach (widget->style, view->bin_window);
- gdk_window_set_background (view->bin_window, &widget->style->mid[widget->state]);
+ if (view->presentation)
+ gdk_window_set_background (view->bin_window, &widget->style->black);
+ else
+ gdk_window_set_background (view->bin_window, &widget->style->mid [GTK_STATE_NORMAL]);
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;
GTK_WIDGET_CLASS (ev_view_parent_class)->unrealize (widget);
}
+static gboolean
+ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event)
+{
+ EvView *view = EV_VIEW (widget);
+
+ if ((event->state & GDK_CONTROL_MASK) != 0) {
+
+ ev_view_set_sizing_mode (view, EV_SIZING_FREE);
+
+ if ((event->direction == GDK_SCROLL_UP ||
+ event->direction == GDK_SCROLL_LEFT) &&
+ 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;
+ }
+
+ if ((event->state & GDK_SHIFT_MASK) != 0) {
+ if (event->direction == GDK_SCROLL_UP)
+ event->direction = GDK_SCROLL_LEFT;
+ if (event->direction == GDK_SCROLL_DOWN)
+ event->direction = GDK_SCROLL_RIGHT;
+ }
+
+ return FALSE;
+}
+
static guint32
ev_gdk_color_to_rgb (const GdkColor *color)
{
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);
gdk_color_free (fill_color_gdk);
}
+
static void
-highlight_find_results (EvView *view)
+highlight_find_results (EvView *view, int page)
{
EvDocumentFind *find;
- int i, results;
+ int i, results = 0;
g_return_if_fail (EV_IS_DOCUMENT_FIND (view->document));
find = EV_DOCUMENT_FIND (view->document);
- results = ev_document_find_get_n_results (find);
+ results = ev_document_find_get_n_results (find, page);
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);
+ if (i == view->find_result && page == view->find_page) {
+ alpha = 0x90;
+ } else {
+ alpha = 0x20;
+ }
+
+ ev_document_find_get_result (find, page,
+ i, &rectangle);
+ doc_rect_to_view_rect (view, page, &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)
+draw_one_page (EvView *view,
+ gint page,
+ GdkRectangle *page_area,
+ GtkBorder *border,
+ GdkRectangle *expose_area)
{
- EvView *view = EV_VIEW (widget);
- GtkBorder border;
gint width, height;
- GdkRectangle area;
+ GdkPixbuf *scaled_image;
+ GdkPixbuf *current_pixbuf;
+ GdkRectangle overlap;
+ GdkRectangle real_page_area;
- if (view->document == NULL)
+ g_assert (view->document);
+
+ if (! gdk_rectangle_intersect (page_area, expose_area, &overlap))
return;
- ev_document_get_page_size (view->document, -1,
- &width, &height);
- ev_document_misc_get_page_border_size (width, height, &border);
-
- /* Paint the frame */
- area.x = view->x_offset;
- area.y = view->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);
+ ev_page_cache_get_size (view->page_cache,
+ page, view->scale,
+ &width, &height);
+
+ ev_document_misc_paint_one_page (view->bin_window,
+ GTK_WIDGET (view),
+ page_area, border);
/* Render the document itself */
- ev_document_set_page_offset (view->document,
- view->x_offset + border.left,
- view->y_offset + border.top);
+ real_page_area = *page_area;
- LOG ("Render area %d %d %d %d", event->area.x, event->area.y,
- event->area.width, event->area.height);
+ real_page_area.x += border->left;
+ real_page_area.y += border->top;
+ real_page_area.width -= (border->left + border->right);
+ real_page_area.height -= (border->top + border->bottom);
- ev_document_render (view->document,
- event->area.x, event->area.y,
- event->area.width, event->area.height);
+ if (! gdk_rectangle_intersect (&real_page_area, expose_area, &overlap))
+ return;
- if (EV_IS_DOCUMENT_FIND (view->document)) {
- highlight_find_results (view);
+ current_pixbuf = ev_pixbuf_cache_get_pixbuf (view->pixbuf_cache, 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,
+ overlap.x - real_page_area.x,
+ overlap.y - real_page_area.y,
+ overlap.x, overlap.y,
+ overlap.width, overlap.height,
+ GDK_RGB_DITHER_NORMAL,
+ 0, 0);
+ g_object_unref (scaled_image);
}
+}
+
+static void
+ev_view_bin_expose (EvView *view,
+ GdkEventExpose *event)
+{
+ GdkRectangle rubberband;
+ GList *l;
+ int i;
- if (view->has_selection) {
- GdkRectangle rubberband;
+ if (view->document == NULL)
+ return;
- doc_rect_to_view_rect (view, &view->selection, &rubberband);
+ for (i = view->start_page; i <= view->end_page; i++) {
+ GdkRectangle page_area;
+ GtkBorder border;
+
+ if (! get_page_extents (view, i, &page_area, &border))
+ continue;
+
+ draw_one_page (view, i, &page_area, &border, &(event->area));
+
+ if (EV_IS_DOCUMENT_FIND (view->document)) {
+ highlight_find_results (view, i);
+ }
+ }
+
+ for (l = view->selections; l != NULL; l = l->next) {
+ EvViewSelection *selection = (EvViewSelection *)l->data;
+
+ doc_rect_to_view_rect (view, selection->page,
+ &selection->rect, &rubberband);
if (rubberband.width > 0 && rubberband.height > 0) {
- draw_rubberband (widget, view->bin_window,
+ draw_rubberband (GTK_WIDGET (view), view->bin_window,
&rubberband, 0x40);
}
}
EvView *view = EV_VIEW (widget);
if (event->window == view->bin_window)
- expose_bin_window (widget, event);
+ ev_view_bin_expose (view, event);
else
return GTK_WIDGET_CLASS (ev_view_parent_class)->expose_event (widget, event);
}
void
-ev_view_select_all (EvView *ev_view)
+ev_view_select_all (EvView *view)
{
- GtkWidget *widget = GTK_WIDGET (ev_view);
- GdkRectangle selection;
- int width, height;
- GtkBorder border;
+ int n_pages, i;
- g_return_if_fail (EV_IS_VIEW (ev_view));
+ clear_selection (view);
+
+ n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ for (i = 0; i < n_pages; i++) {
+ int width, height;
+ EvViewSelection *selection;
+
+ ev_page_cache_get_size (view->page_cache,
+ i, 1.0, &width, &height);
+
+ selection = g_new0 (EvViewSelection, 1);
+ selection->page = i;
+ selection->rect.x1 = selection->rect.y1 = 0;
+ selection->rect.x2 = width;
+ selection->rect.y2 = height;
+
+ view->selections = g_list_append (view->selections, selection);
+ }
- ev_document_get_page_size (ev_view->document, -1, &width, &height);
- ev_document_misc_get_page_border_size (width, height, &border);
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+}
+
+static char *
+get_selected_text (EvView *ev_view)
+{
+ GString *text;
+ GList *l;
+
+ text = g_string_new (NULL);
+
+ ev_document_doc_mutex_lock ();
+
+ for (l = ev_view->selections; l != NULL; l = l->next) {
+ EvViewSelection *selection = (EvViewSelection *)l->data;
+ char *tmp;
+
+ tmp = ev_document_get_text (ev_view->document,
+ selection->page,
+ &selection->rect);
+ g_string_append (text, tmp);
+ g_free (tmp);
+ }
- ev_view->has_selection = TRUE;
- selection.x = ev_view->x_offset + border.left;
- selection.y = ev_view->y_offset + border.top;
- selection.width = width;
- selection.height = height;
- view_rect_to_doc_rect (ev_view, &selection, &ev_view->selection);
+ ev_document_doc_mutex_unlock ();
- gtk_widget_queue_draw (widget);
+ return g_string_free (text, FALSE);
}
void
ev_view_copy (EvView *ev_view)
{
GtkClipboard *clipboard;
- GdkRectangle selection;
char *text;
- doc_rect_to_view_rect (ev_view, &ev_view->selection, &selection);
- text = ev_document_get_text (ev_view->document, &selection);
+ if (!ev_document_can_get_text (ev_view->document)) {
+ return;
+ }
+
+ text = get_selected_text (ev_view);
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (ev_view),
GDK_SELECTION_CLIPBOARD);
gtk_clipboard_set_text (clipboard, text, -1);
gpointer data)
{
EvView *ev_view = EV_VIEW (data);
- GdkRectangle selection;
char *text;
- doc_rect_to_view_rect (ev_view, &ev_view->selection, &selection);
- text = ev_document_get_text (ev_view->document, &selection);
+ if (!ev_document_can_get_text (ev_view->document)) {
+ return;
+ }
+
+ text = get_selected_text (ev_view);
gtk_selection_data_set_text (selection_data, text, -1);
+ g_free (text);
}
static void
ev_view_primary_clear_cb (GtkClipboard *clipboard,
gpointer data)
{
- EvView *ev_view = EV_VIEW (data);
+ EvView *view = EV_VIEW (data);
- ev_view->has_selection = FALSE;
+ clear_selection (view);
}
static void
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (ev_view),
GDK_SELECTION_PRIMARY);
- if (ev_view->has_selection) {
+ if (ev_view->selections) {
if (!gtk_clipboard_set_with_owner (clipboard,
targets,
G_N_ELEMENTS (targets),
switch (event->button) {
case 1:
- if (view->has_selection) {
- view->has_selection = FALSE;
+ if (view->selections) {
+ clear_selection (view);
gtk_widget_queue_draw (widget);
}
}
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");
{
GdkBitmap *empty;
GdkColor black = { 0, 0, 0, 0 };
- static unsigned char bits[] = { 0x00 };
+ static char bits[] = { 0x00 };
empty = gdk_bitmap_create_from_data (NULL, bits, 1, 1);
}
}
+
+static void
+find_page_at_location (EvView *view,
+ gdouble x,
+ gdouble y,
+ gint *page,
+ gint *x_offset,
+ gint *y_offset)
+{
+ int i;
+
+ if (view->document == NULL)
+ return;
+
+ g_assert (page);
+ g_assert (x_offset);
+ g_assert (y_offset);
+
+ for (i = view->start_page; i <= view->end_page; i++) {
+ GdkRectangle page_area;
+ GtkBorder border;
+
+ if (! get_page_extents (view, i, &page_area, &border))
+ continue;
+
+ if ((x >= page_area.x + border.left) &&
+ (x < page_area.x + page_area.width - border.right) &&
+ (y >= page_area.y + border.top) &&
+ (y < page_area.y + page_area.height - border.bottom)) {
+ *page = i;
+ *x_offset = x - (page_area.x + border.left);
+ *y_offset = y - (page_area.y + border.top);
+ return;
+ }
+ }
+
+ *page = -1;
+}
+
+static EvLink *
+get_link_at_location (EvView *view,
+ gdouble x,
+ gdouble y)
+{
+ gint page = -1;
+ gint x_offset = 0, y_offset = 0;
+ 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);
+
+ if (link_mapping)
+ return ev_link_mapping_find (link_mapping, x_offset / view->scale, y_offset / view->scale);
+ else
+ return NULL;
+}
+
+
static gboolean
ev_view_motion_notify_event (GtkWidget *widget,
GdkEventMotion *event)
if (view->pressed_button > 0) {
GdkRectangle selection;
- view->has_selection = TRUE;
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);
+
+ compute_selections (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) {
return TRUE;
}
+/* FIXME: standardize this sometime */
+static void
+go_to_link (EvView *view, EvLink *link)
+{
+ EvLinkType type;
+ const char *uri;
+ 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);
+ 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;
+ }
+}
+
+
static gboolean
ev_view_button_release_event (GtkWidget *widget,
GdkEventButton *event)
view->pressed_button = -1;
- if (view->has_selection) {
+ if (view->selections) {
ev_view_update_primary_selection (view);
} 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);
+ go_to_link (view, 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,
}
static void
-add_scroll_binding (GtkBindingSet *binding_set,
- guint keyval,
- GtkScrollType scroll,
- gboolean horizontal)
+add_scroll_binding_keypad (GtkBindingSet *binding_set,
+ guint keyval,
+ GtkScrollType scroll,
+ 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
+add_scroll_binding_shifted (GtkBindingSet *binding_set,
+ guint keyval,
+ GtkScrollType scroll_normal,
+ GtkScrollType scroll_shifted,
+ gboolean horizontal)
+{
+ gtk_binding_entry_add_signal (binding_set, keyval, 0,
+ "scroll_view", 2,
+ GTK_TYPE_SCROLL_TYPE, scroll_normal,
+ G_TYPE_BOOLEAN, horizontal);
+ gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
+ "scroll_view", 2,
+ GTK_TYPE_SCROLL_TYPE, scroll_shifted,
+ 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;
}
static void
-ev_view_set_property (GObject *object,
- guint prop_id,
+ev_view_set_property (GObject *object,
+ guint prop_id,
const GValue *value,
- GParamSpec *pspec)
+ GParamSpec *pspec)
{
+ EvView *view = EV_VIEW (object);
+
switch (prop_id)
{
- /* Read only */
- case PROP_STATUS:
- case PROP_FIND_STATUS:
- break;
+ 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;
+ 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_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;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
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;
gtk_object_class->destroy = ev_view_destroy;
class->set_scroll_adjustments = ev_view_set_scroll_adjustments;
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",
NULL,
G_PARAM_READABLE));
+ g_object_class_install_property (object_class,
+ PROP_CONTINUOUS,
+ g_param_spec_boolean ("continuous",
+ "Continuous",
+ "Continuous scrolling mode",
+ TRUE,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_DUAL_PAGE,
+ g_param_spec_boolean ("dual-page",
+ "Dual Page",
+ "Two pages visible at once",
+ FALSE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_FULLSCREEN,
+ g_param_spec_boolean ("fullscreen",
+ "Full Screen",
+ "Draw page in a fullscreen fashion",
+ FALSE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_PRESENTATION,
+ g_param_spec_boolean ("presentation",
+ "Presentation",
+ "Draw page in presentation mode",
+ TRUE,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_SIZING_MODE,
+ g_param_spec_enum ("sizing-mode",
+ "Sizing Mode",
+ "Sizing Mode",
+ EV_TYPE_SIZING_MODE,
+ EV_SIZING_FIT_WIDTH,
+ G_PARAM_READWRITE));
+
binding_set = gtk_binding_set_by_class (class);
- add_scroll_binding (binding_set, GDK_Left, GTK_SCROLL_STEP_BACKWARD, TRUE);
- add_scroll_binding (binding_set, GDK_Right, GTK_SCROLL_STEP_FORWARD, TRUE);
- add_scroll_binding (binding_set, GDK_Up, GTK_SCROLL_STEP_BACKWARD, FALSE);
- add_scroll_binding (binding_set, GDK_Down, GTK_SCROLL_STEP_FORWARD, FALSE);
+ 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_Page_Up, GTK_SCROLL_PAGE_BACKWARD, FALSE);
+ add_scroll_binding_keypad (binding_set, GDK_Page_Down, GTK_SCROLL_PAGE_FORWARD, FALSE);
- 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_shifted (binding_set, GDK_space, EV_SCROLL_PAGE_FORWARD, EV_SCROLL_PAGE_BACKWARD, FALSE);
+ add_scroll_binding_shifted (binding_set, GDK_BackSpace, EV_SCROLL_PAGE_BACKWARD, EV_SCROLL_PAGE_FORWARD, FALSE);
}
static void
view->spacing = 10;
view->scale = 1.0;
+ view->current_page = 0;
view->pressed_button = -1;
view->cursor = EV_VIEW_CURSOR_NORMAL;
- view->sizing_mode = EV_SIZING_BEST_FIT;
+
+ view->continuous = TRUE;
+ view->dual_page = FALSE;
+ view->presentation = FALSE;
+ view->fullscreen = FALSE;
+ view->sizing_mode = EV_SIZING_FIT_WIDTH;
}
static void
{
char *message;
- if (ev_document_get_page (view->document) == view->find_page) {
+ if (view->current_page == view->find_page) {
int results;
results = ev_document_find_get_n_results
- (EV_DOCUMENT_FIND (view->document));
-
+ (EV_DOCUMENT_FIND (view->document),
+ view->current_page);
/* TRANS: Sometimes this could be better translated as
"%d hit(s) on this page". Therefore this string
contains plural cases. */
results);
} else {
double percent;
-
+
+ ev_document_doc_mutex_lock ();
percent = ev_document_find_get_progress
(EV_DOCUMENT_FIND (view->document));
-
+ ev_document_doc_mutex_unlock ();
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));
}
-
+
}
+// ev_document_doc_mutex_unlock ();
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) {
- if (view->cursor != EV_VIEW_CURSOR_HIDDEN) {
- 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);
- }
-
- if (EV_IS_DOCUMENT_FIND (view->document)) {
- view->find_page = page;
- view->find_result = 0;
- 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;
+ int page = view->find_page;
- n_results = ev_document_find_get_n_results (find);
+ ev_document_doc_mutex_lock ();
+ n_results = ev_document_find_get_n_results (find, page);
+ ev_document_doc_mutex_unlock ();
if (n_results > view->find_result) {
+ ev_document_doc_mutex_lock ();
ev_document_find_get_result
- (find, view->find_result, &rect);
- ensure_rectangle_is_visible (view, &rect);
+ (find, page, view->find_result, &rect);
+ ev_document_doc_mutex_unlock ();
+
+ doc_rect_to_view_rect (view, page, &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;
}
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)
+{
+ GtkWidget *view;
+
+ view = g_object_new (EV_TYPE_VIEW, NULL);
+
+ return view;
}
static void
-document_changed_callback (EvDocument *document,
- EvView *view)
+job_finished_cb (EvPixbufCache *pixbuf_cache,
+ EvView *view)
{
gtk_widget_queue_draw (GTK_WIDGET (view));
-
- if (view->cursor != EV_VIEW_CURSOR_HIDDEN) {
- 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;
+ int max_height, n_rows;
+
+ if (old_page == new_page)
+ return;
+
+ ev_page_cache_get_size (page_cache,
+ old_page,
+ view->scale,
+ &old_width, &old_height);
+
+ view->current_page = new_page;
+
+ ev_page_cache_get_size (page_cache,
+ new_page,
+ view->scale,
+ &new_width, &new_height);
+
+ compute_border (view, new_width, new_height, &(view->border));
+
+ if (new_width != old_width || new_height != old_height)
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+ else
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+
+ if (view->continuous) {
+
+ n_rows = view->dual_page ? new_page / 2 : new_page;
+
+ get_bounding_box_size (view, NULL, &max_height);
+
+ gtk_adjustment_clamp_page(view->vadjustment,
+ (max_height + view->spacing) * n_rows,
+ (max_height + view->spacing) * n_rows +
+ view->vadjustment->page_size);
+ } else {
+ 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);
+ }
+
+ view_update_range_and_current_page (view);
}
void
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);
}
}
+#define EPSILON 0.0000001
void
-ev_view_set_mode (EvView *view,
- EvSizingMode sizing_mode)
+ev_view_set_zoom (EvView *view,
+ double factor,
+ gboolean relative)
{
- if (view->sizing_mode == sizing_mode)
- return;
+ double scale;
- view->sizing_mode = sizing_mode;
+ if (relative)
+ scale = view->scale * factor;
+ else
+ scale = factor;
+
+ scale = CLAMP (scale, MIN_SCALE, MAX_SCALE);
+
+ if (ABS (view->scale - scale) < EPSILON)
+ return;
+ view->scale = scale;
gtk_widget_queue_resize (GTK_WIDGET (view));
}
-static void
-go_to_link (EvView *view, EvLink *link)
+double
+ev_view_get_zoom (EvView *view)
{
- EvLinkType type;
- const char *uri;
- int page;
+ return view->scale;
+}
- 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);
- break;
- case EV_LINK_TYPE_EXTERNAL_URI:
- uri = ev_link_get_uri (link);
- gnome_vfs_url_show (uri);
- break;
+void
+ev_view_set_continuous (EvView *view,
+ gboolean continuous)
+{
+ g_return_if_fail (EV_IS_VIEW (view));
+
+ continuous = continuous != FALSE;
+
+ if (view->continuous != continuous) {
+ view->continuous = continuous;
+ gtk_widget_queue_resize (GTK_WIDGET (view));
}
+
+ g_object_notify (G_OBJECT (view), "continuous");
}
void
-ev_view_go_to_link (EvView *view, EvLink *link)
+ev_view_set_dual_page (EvView *view,
+ gboolean dual_page)
{
- go_to_link (view, link);
+ g_return_if_fail (EV_IS_VIEW (view));
+
+ dual_page = dual_page != FALSE;
+
+ if (view->dual_page == dual_page)
+ return;
+
+ 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.
+ */
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+
+ g_object_notify (G_OBJECT (view), "dual-page");
}
void
-ev_view_set_page (EvView *view,
- int page)
+ev_view_set_fullscreen (EvView *view,
+ gboolean fullscreen)
{
g_return_if_fail (EV_IS_VIEW (view));
- set_document_page (view, page);
+ fullscreen = fullscreen != FALSE;
+
+ if (view->fullscreen != fullscreen) {
+ view->fullscreen = fullscreen;
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+ }
+
+ g_object_notify (G_OBJECT (view), "fullscreen");
}
-int
-ev_view_get_page (EvView *view)
+gboolean
+ev_view_get_fullscreen (EvView *view)
{
- if (view->document)
- return ev_document_get_page (view->document);
- else
- return 1;
+ g_return_val_if_fail (EV_IS_VIEW (view), FALSE);
+
+ return view->fullscreen;
}
-static void
-ev_view_zoom (EvView *view,
- double factor,
- gboolean relative)
+void
+ev_view_set_presentation (EvView *view,
+ gboolean presentation)
{
- double scale;
-
- if (relative)
- scale = view->scale * factor;
- else
- scale = factor;
+ g_return_if_fail (EV_IS_VIEW (view));
- scale = CLAMP (scale, MIN_SCALE, MAX_SCALE);
+ presentation = presentation != FALSE;
- if (ABS (scale - view->scale) < ZOOM_EPSILON)
+ if (view->presentation == presentation)
return;
- view->scale = scale;
+ view->presentation = presentation;
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+ if (GTK_WIDGET_REALIZED (view)) {
+ if (view->presentation)
+ gdk_window_set_background (view->bin_window,
+ >K_WIDGET (view)->style->black);
+ else
+ gdk_window_set_background (view->bin_window,
+ >K_WIDGET (view)->style->mid [GTK_STATE_NORMAL]);
+ }
+
+
+ g_object_notify (G_OBJECT (view), "presentation");
+}
+
+gboolean
+ev_view_get_presentation (EvView *view)
+{
+ g_return_val_if_fail (EV_IS_VIEW (view), FALSE);
+
+ return view->presentation;
+}
+
+void
+ev_view_set_sizing_mode (EvView *view,
+ EvSizingMode sizing_mode)
+{
+ g_return_if_fail (EV_IS_VIEW (view));
- ev_document_set_scale (view->document, view->scale);
+ if (view->sizing_mode == sizing_mode)
+ return;
+ view->sizing_mode = sizing_mode;
gtk_widget_queue_resize (GTK_WIDGET (view));
+
+ g_object_notify (G_OBJECT (view), "sizing-mode");
+}
+
+EvSizingMode
+ev_view_get_sizing_mode (EvView *view)
+{
+ g_return_val_if_fail (EV_IS_VIEW (view), EV_SIZING_FREE);
+
+ return view->sizing_mode;
+}
+
+gboolean
+ev_view_can_zoom_in (EvView *view)
+{
+ return view->scale * ZOOM_IN_FACTOR <= MAX_SCALE;
+}
+
+gboolean
+ev_view_can_zoom_out (EvView *view)
+{
+ return view->scale * ZOOM_OUT_FACTOR >= MIN_SCALE;
}
void
ev_view_zoom_in (EvView *view)
{
- ev_view_zoom (view, ZOOM_IN_FACTOR, TRUE);
+ g_return_if_fail (view->sizing_mode == EV_SIZING_FREE);
+
+ ev_view_set_zoom (view, ZOOM_IN_FACTOR, TRUE);
}
void
ev_view_zoom_out (EvView *view)
{
- ev_view_zoom (view, ZOOM_OUT_FACTOR, TRUE);
+ g_return_if_fail (view->sizing_mode == EV_SIZING_FREE);
+
+ ev_view_set_zoom (view, ZOOM_OUT_FACTOR, TRUE);
}
-void
-ev_view_normal_size (EvView *view)
+
+
+static double
+zoom_for_size_fit_width (int doc_width,
+ int doc_height,
+ int target_width,
+ int target_height,
+ int vsb_width)
{
- ev_view_zoom (view, 1.0, FALSE);
+ double scale;
+
+ scale = (double)target_width / doc_width;
+
+ if (doc_height * scale > target_height)
+ scale = (double) (target_width - vsb_width) / doc_width;
+
+ return scale;
}
-/* Unfortunately this is not idempotent (!) (numerical stability
- * issues because width and height are rounded) */
-void
-ev_view_best_fit (EvView *view, int allocation_width, int allocation_height)
+static double
+zoom_for_size_best_fit (int doc_width,
+ int doc_height,
+ int target_width,
+ int target_height,
+ int vsb_width,
+ int hsb_width)
{
- int target_width, target_height;
- int width, height;
- GtkBorder border;
+ double w_scale;
+ double h_scale;
- if (!GTK_WIDGET_REALIZED (view) || view->document == NULL)
- return;
+ w_scale = (double)target_width / doc_width;
+ h_scale = (double)target_height / doc_height;
+
+ if (doc_height * w_scale > target_height)
+ w_scale = (double) (target_width - vsb_width) / doc_width;
+ if (doc_width * h_scale > target_width)
+ h_scale = (double) (target_height - hsb_width) / doc_height;
+
+ return MIN (w_scale, h_scale);
+}
- width = height = 0;
- /* This is the bad part. You could make it stable by doing
- * ev_document_set_scale 1.0. But at least with pdf this means
- * redrawing the whole page */
- ev_document_get_page_size (view->document, -1, &width, &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 (width, height, &border);
- target_width = allocation_width - (view->spacing * 2 + border.left + border.right);
- target_height = allocation_height - (view->spacing * 2 + border.top + border.bottom);
+static void
+ev_view_zoom_for_size_presentation (EvView *view,
+ int width,
+ int height)
+{
+ int doc_width, doc_height;
+ gdouble scale;
+
+ ev_page_cache_get_size (view->page_cache,
+ view->current_page,
+ 1.0,
+ &doc_width,
+ &doc_height);
+ scale = zoom_for_size_best_fit (doc_width, doc_height, width, height, 0, 0);
+ ev_view_set_zoom (view, scale, FALSE);
+}
- LOG ("Best fit %d %d", allocation_width, allocation_height);
+static void
+ev_view_zoom_for_size_continuous_and_dual_page (EvView *view,
+ int width,
+ int height,
+ int vsb_width,
+ int hsb_height)
+{
+ int doc_width, doc_height;
+ GtkBorder border;
+ gdouble scale;
+
+ ev_page_cache_get_max_width_size (view->page_cache,
+ 1.0,
+ &doc_width, NULL);
+ ev_page_cache_get_max_height_size (view->page_cache,
+ 1.0,
+ NULL, &doc_height);
+ compute_border (view, doc_width, doc_height, &border);
+
+ doc_width = doc_width * 2;
+ width -= (2 * (border.left + border.right) + 3 * view->spacing);
+ height -= (border.top + border.bottom + 2 * view->spacing - 1);
+
+ /* FIXME: We really need to calculate the overall height here, not the
+ * page height. We assume there's always a vertical scrollbar for
+ * now. We need to fix this. */
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH)
+ scale = zoom_for_size_fit_width (doc_width, doc_height, width - vsb_width, height, 0);
+ else if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ scale = zoom_for_size_best_fit (doc_width, doc_height, width - vsb_width, height, 0, hsb_height);
+ else
+ g_assert_not_reached ();
- if (width != 0 && height != 0) {
- double scale;
- double scale_w, scale_h;
+ ev_view_set_zoom (view, scale, FALSE);
+}
- scale_w = (double)target_width * view->scale / width;
- scale_h = (double)target_height * view->scale / height;
+static void
+ev_view_zoom_for_size_continuous (EvView *view,
+ int width,
+ int height,
+ int vsb_width,
+ int hsb_height)
+{
+ int doc_width, doc_height;
+ GtkBorder border;
+ gdouble scale;
+
+ ev_page_cache_get_max_width_size (view->page_cache,
+ 1.0,
+ &doc_width, NULL);
+ ev_page_cache_get_max_height_size (view->page_cache,
+ 1.0,
+ NULL, &doc_height);
+ compute_border (view, doc_width, doc_height, &border);
+
+ width -= (border.left + border.right + 2 * view->spacing);
+ height -= (border.top + border.bottom + 2 * view->spacing - 1);
+
+ /* FIXME: We really need to calculate the overall height here, not the
+ * page height. We assume there's always a vertical scrollbar for
+ * now. We need to fix this. */
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH)
+ scale = zoom_for_size_fit_width (doc_width, doc_height, width - vsb_width, height, 0);
+ else if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ scale = zoom_for_size_best_fit (doc_width, doc_height, width - vsb_width, height, 0, hsb_height);
+ else
+ g_assert_not_reached ();
- scale = (scale_w < scale_h) ? scale_w : scale_h;
+ ev_view_set_zoom (view, scale, FALSE);
+}
- ev_view_zoom (view, scale, FALSE);
+static void
+ev_view_zoom_for_size_dual_page (EvView *view,
+ int width,
+ int height,
+ int vsb_width,
+ int hsb_height)
+{
+ GtkBorder border;
+ gint doc_width, doc_height;
+ gdouble scale;
+ gint other_page;
+
+ other_page = view->current_page ^ 1;
+
+ /* Find the largest of the two. */
+ ev_page_cache_get_size (view->page_cache,
+ view->current_page,
+ 1.0,
+ &doc_width, &doc_height);
+
+ if (other_page < ev_page_cache_get_n_pages (view->page_cache)) {
+ gint width_2, height_2;
+ ev_page_cache_get_size (view->page_cache,
+ other_page,
+ 1.0,
+ &width_2, &height_2);
+ if (width_2 > doc_width)
+ doc_width = width_2;
+ if (height_2 > doc_height)
+ doc_height = height_2;
}
+ compute_border (view, doc_width, doc_height, &border);
+
+ doc_width = doc_width * 2;
+ width -= ((border.left + border.right)* 2 + 3 * view->spacing);
+ height -= (border.top + border.bottom + 2 * view->spacing);
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH)
+ scale = zoom_for_size_fit_width (doc_width, doc_height, width, height, vsb_width);
+ else if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ scale = zoom_for_size_best_fit (doc_width, doc_height, width, height, vsb_width, hsb_height);
+ else
+ g_assert_not_reached ();
+ ev_view_set_zoom (view, scale, FALSE);
}
-void
-ev_view_fit_width (EvView *view, int allocation_width, int allocation_height,
- int vsb_width)
+static void
+ev_view_zoom_for_size_single_page (EvView *view,
+ int width,
+ int height,
+ int vsb_width,
+ int hsb_height)
{
- int target_width, target_height;
- int width, height;
+ int doc_width, doc_height;
GtkBorder border;
+ gdouble scale;
+
+ ev_page_cache_get_size (view->page_cache,
+ view->current_page,
+ 1.0,
+ &doc_width,
+ &doc_height);
+ /* Get an approximate border */
+ compute_border (view, width, height, &border);
+
+ width -= (border.left + border.right + 2 * view->spacing);
+ height -= (border.top + border.bottom + 2 * view->spacing);
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH)
+ scale = zoom_for_size_fit_width (doc_width, doc_height, width, height, vsb_width);
+ else if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ scale = zoom_for_size_best_fit (doc_width, doc_height, width, height, vsb_width, hsb_height);
+ else
+ g_assert_not_reached ();
- if (view->document == NULL)
- return;
+ ev_view_set_zoom (view, scale, FALSE);
+}
- width = height = 0;
- ev_document_get_page_size (view->document, -1, &width, &height);
- ev_document_misc_get_page_border_size (width, height, &border);
- target_width = allocation_width - (view->spacing * 2 + border.left + border.right);
- target_height = allocation_height - (view->spacing * 2 + border.top + border.bottom);
+void
+ev_view_zoom_normal (EvView *view)
+{
+ ev_view_set_zoom (view, 1.0, FALSE);
+}
- if (width) {
- double scale;
- scale = (double)target_width * view->scale / width;
+void
+ev_view_set_zoom_for_size (EvView *view,
+ int width,
+ int height,
+ int vsb_width,
+ int hsb_height)
+{
+ g_return_if_fail (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
+ view->sizing_mode == EV_SIZING_BEST_FIT);
+ g_return_if_fail (width >= 0);
+ g_return_if_fail (height >= 0);
- if (height * scale / view->scale > target_height)
- scale = ((double)(target_width - vsb_width) * view->scale / width);
+ if (view->document == NULL)
+ return;
- ev_view_zoom (view, scale, FALSE);
- }
+ if (view->presentation)
+ ev_view_zoom_for_size_presentation (view, width, height);
+ else if (view->continuous && view->dual_page)
+ ev_view_zoom_for_size_continuous_and_dual_page (view, width, height, vsb_width, hsb_height);
+ else if (view->continuous)
+ ev_view_zoom_for_size_continuous (view, width, height, vsb_width, hsb_height);
+ else if (view->dual_page)
+ ev_view_zoom_for_size_dual_page (view, width, height, vsb_width, hsb_height);
+ else
+ ev_view_zoom_for_size_single_page (view, width, height, vsb_width, hsb_height);
}
const char *
return view->find_status;
}
+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);
+
+ ev_document_doc_mutex_lock ();
+ n_results = ev_document_find_get_n_results (find, view->current_page);
+ ev_document_doc_mutex_unlock ();
+ }
+
+ 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);
+ ev_document_doc_mutex_lock ();
+ n_results = ev_document_find_get_n_results (find, view->current_page);
+ ev_document_doc_mutex_unlock ();
+
+ 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);
- n_results = ev_document_find_get_n_results (find);
- n_pages = ev_document_get_n_pages (view->document);
+ ev_document_doc_mutex_lock ();
+ n_results = ev_document_find_get_n_results (find, view->current_page);
+ ev_document_doc_mutex_unlock ();
+
+ 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)
{
void
ev_view_show_cursor (EvView *view)
{
- ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);
+ ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
+}
+
+
+GType
+ev_sizing_mode_get_type (void)
+{
+ static GType etype = 0;
+ if (etype == 0) {
+ static const GEnumValue values[] = {
+ { EV_SIZING_FIT_WIDTH, "EV_SIZING_FIT_WIDTH", "fit-width" },
+ { EV_SIZING_BEST_FIT, "EV_SIZING_BEST_FIT", "best-fit" },
+ { EV_SIZING_FREE, "EV_SIZING_FREE", "free" },
+ { 0, NULL, NULL }
+ };
+ etype = g_enum_register_static ("EvSizingMode", values);
+ }
+ return etype;
}