enum {
PROP_0,
PROP_STATUS,
- PROP_FIND_STATUS
+ PROP_FIND_STATUS,
+ PROP_CONTINUOUS,
+ PROP_DUAL_PAGE,
+ PROP_FULLSCREEN,
+ PROP_PRESENTATION,
+ PROP_SIZING_MODE,
};
enum {
#define MIN_SCALE 0.05409
#define MAX_SCALE 6.0
+typedef struct {
+ EvRectangle rect;
+ int page;
+} EvViewSelection;
+
struct _EvView {
GtkWidget parent_instance;
int scroll_y;
gboolean pressed_button;
- gboolean has_selection;
GdkPoint selection_start;
- EvRectangle selection;
+ GList *selections;
EvViewCursor cursor;
GtkAdjustment *hadjustment;
EvPageCache *page_cache;
EvPixbufCache *pixbuf_cache;
+ gint start_page;
+ gint end_page;
gint current_page;
+
EvJobRender *current_job;
int find_page;
int spacing;
double scale;
- int width;
- int height;
GtkBorder border;
- gboolean show_border;
+
+ gboolean continuous;
+ gboolean dual_page;
+ gboolean fullscreen;
+ gboolean presentation;
+ EvSizingMode sizing_mode;
};
struct _EvViewClass {
};
-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)
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
gtk_adjustment_value_changed (adjustment);
}
+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
g_free (view->status);
g_free (view->find_status);
+ clear_selection (view);
+
G_OBJECT_CLASS (ev_view_parent_class)->finalize (object);
}
}
static void
-ev_view_get_offsets (EvView *view, int *x_offset, int *y_offset)
+compute_border (EvView *view, int width, int height, GtkBorder *border)
{
- EvDocument *document = view->document;
- GtkWidget *widget = GTK_WIDGET (view);
- int width, height, target_width, target_height;
+ 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);
+ }
+}
- g_return_if_fail (EV_IS_DOCUMENT (document));
+static gboolean
+get_page_extents (EvView *view,
+ gint page,
+ GdkRectangle *page_area,
+ GtkBorder *border)
+{
+ GtkWidget *widget;
+ int width, height;
- ev_page_cache_get_size (view->page_cache,
- view->current_page,
+ 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;
- *x_offset = view->spacing;
- *y_offset = view->spacing;
- target_width = width + view->border.left +
- view->border.right + view->spacing * 2;
- target_height = height + view->border.top +
- view->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);
+ /* 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, EvRectangle *doc_rect)
+view_rect_to_doc_rect (EvView *view,
+ GdkRectangle *view_rect,
+ GdkRectangle *page_area,
+ 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;
+ 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
-doc_rect_to_view_rect (EvView *view, EvRectangle *doc_rect, GdkRectangle *view_rect)
+compute_selections (EvView *view, GdkRectangle *view_rect)
{
- int x_offset, y_offset;
+ 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;
- 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;
+ 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
-compute_border (EvView *view, int width, int height, GtkBorder *border)
+doc_rect_to_view_rect (EvView *view,
+ int page,
+ EvRectangle *doc_rect,
+ GdkRectangle *view_rect)
{
- if (view->show_border) {
- ev_document_misc_get_page_border_size (width, height, border);
- } else {
- border->left = 0;
- border->right = 0;
- border->top = 0;
- border->bottom = 0;
- }
+ 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
-compute_zoom_factor (EvView *view)
+get_bounding_box_size (EvView *view, int *max_width, int *max_height)
{
- int doc_width, doc_height;
- double scale, scale_w, scale_h;
GtkBorder border;
+ int width, height;
- if (view->width <= 0 && view->height <= 0) {
- return;
+ 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;
}
- doc_width = doc_height = 0;
- scale = scale_w = scale_h = 1.0;
- ev_page_cache_get_size (view->page_cache,
- view->current_page,
- 1.0,
- &doc_width,
- &doc_height);
- compute_border (view, doc_width, doc_height, &border);
-
- if (doc_width == 0 || doc_height == 0) {
- return;
+ 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;
}
+}
- if (view->width >= 0) {
- int target_width;
- target_width = view->width - (view->spacing * 2 + view->border.left +
- view->border.right);
- scale = scale_w = (double)target_width / doc_width;
- }
+static void
+ev_view_size_request_continuous_and_dual_page (EvView *view,
+ GtkRequisition *requisition)
+{
+ int max_width, max_height;
+ int n_rows;
- if (view->height >= 0) {
- int target_height;
+ get_bounding_box_size (view, &max_width, &max_height);
- target_height = view->height - (view->spacing * 2 + view->border.top +
- view->border.bottom);
- scale = scale_h = (double)target_height / doc_height;
- }
+ n_rows = (1 + ev_page_cache_get_n_pages (view->page_cache)) / 2;
- if (view->width >= 0 && view->height >= 0) {
- scale = (scale_w < scale_h) ? scale_w : scale_h;
+ 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;*/
}
+}
- view->scale = scale;
+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;*/
+ }
}
-/* Called by size_request to make sure we have appropriate jobs running.
- */
static void
-ev_view_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
+ev_view_size_request_dual_page (EvView *view,
+ GtkRequisition *requisition)
{
- EvView *view = EV_VIEW (widget);
+ GtkBorder border;
gint width, height;
- if (!GTK_WIDGET_REALIZED (widget))
- return;
+ /* 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->document) {
+ 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;
- return;
}
+}
- compute_zoom_factor (view);
+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);
- compute_border (view, width, height, &(view->border));
+ requisition->width = width + border.left + border.right + (2 * view->spacing);
+ requisition->height = height + border.top + border.bottom + (2 * view->spacing);
- ev_pixbuf_cache_set_page_range (view->pixbuf_cache,
- view->current_page,
- view->current_page,
- view->scale);
+ 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;
+ }
+}
- if (view->width >= 0) {
- requisition->width = 0;
- } else {
- requisition->width = width + view->border.left +
- view->border.right + view->spacing * 2;
+static void
+ev_view_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ EvView *view = EV_VIEW (widget);
+
+ if (!GTK_WIDGET_REALIZED (widget))
+ return;
+
+ if (view->document == NULL) {
+ requisition->width = 1;
+ requisition->height = 1;
+ return;
}
- if (view->height >= 0) {
- requisition->height = 0;
- } else {
- requisition->height = height + view->border.top +
- view->border.bottom + view->spacing * 2;
+ 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
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
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) {
/* We can't get page size without a target, so we have to
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_color_free (fill_color_gdk);
}
+
static void
-highlight_find_results (EvView *view)
+highlight_find_results (EvView *view, int page)
{
EvDocumentFind *find;
int i, results = 0;
g_return_if_fail (EV_IS_DOCUMENT_FIND (view->document));
find = EV_DOCUMENT_FIND (view->document);
-#if 0
- ev_document_doc_mutex_lock ();
- results = ev_document_find_get_n_results (find, view->current_page);
- ev_document_doc_mutex_unlock ();
-#endif
+
+ results = ev_document_find_get_n_results (find, page);
+
for (i = 0; i < results; i++) {
EvRectangle rectangle;
GdkRectangle view_rectangle;
guchar alpha;
- alpha = (i == view->find_result) ? 0x90 : 0x20;
- ev_document_doc_mutex_lock ();
- ev_document_find_get_result (find, view->current_page,
+ if (i == view->find_result && page == view->find_page) {
+ alpha = 0x90;
+ } else {
+ alpha = 0x20;
+ }
+
+ ev_document_find_get_result (find, page,
i, &rectangle);
- ev_document_doc_mutex_unlock ();
- doc_rect_to_view_rect (view, &rectangle, &view_rectangle);
+ doc_rect_to_view_rect (view, page, &rectangle, &view_rectangle);
draw_rubberband (GTK_WIDGET (view), view->bin_window,
&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);
gint width, height;
- GdkRectangle area;
- int x_offset, y_offset;
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_view_get_offsets (view, &x_offset, &y_offset);
ev_page_cache_get_size (view->page_cache,
- view->current_page,
- view->scale,
+ page, view->scale,
&width, &height);
- /* Paint the frame */
- area.x = x_offset;
- area.y = y_offset;
- area.width = width + view->border.left + view->border.right;
- area.height = height + view->border.top + view->border.bottom;
-
- if (view->show_border) {
- ev_document_misc_paint_one_page (view->bin_window, widget, &area,
- &(view->border));
- }
+ ev_document_misc_paint_one_page (view->bin_window,
+ GTK_WIDGET (view),
+ page_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);
+ real_page_area = *page_area;
+
+ 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);
- current_pixbuf = ev_pixbuf_cache_get_pixbuf (view->pixbuf_cache, view->current_page);
+ if (! gdk_rectangle_intersect (&real_page_area, expose_area, &overlap))
+ return;
+ 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) &&
gdk_draw_pixbuf (view->bin_window,
GTK_WIDGET (view)->style->fg_gc[GTK_STATE_NORMAL],
scaled_image,
- 0, 0,
- area.x + view->border.left,
- area.y + view->border.top,
- width, height,
+ 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);
}
+}
- if (EV_IS_DOCUMENT_FIND (view->document)) {
- highlight_find_results (view);
+static void
+ev_view_bin_expose (EvView *view,
+ GdkEventExpose *event)
+{
+ GdkRectangle rubberband;
+ GList *l;
+ int i;
+
+ if (view->document == NULL)
+ return;
+
+ 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);
+ }
}
- if (view->has_selection) {
- GdkRectangle rubberband;
+ for (l = view->selections; l != NULL; l = l->next) {
+ EvViewSelection *selection = (EvViewSelection *)l->data;
- doc_rect_to_view_rect (view, &view->selection, &rubberband);
+ 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;
- int x_offset, y_offset;
+ 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_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_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;
- ev_view->has_selection = TRUE;
- selection.x = x_offset + ev_view->border.left;
- selection.y = y_offset + ev_view->border.top;
- selection.width = width;
- selection.height = height;
- view_rect_to_doc_rect (ev_view, &selection, &ev_view->selection);
+ view->selections = g_list_append (view->selections, selection);
+ }
+
+ 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_document_doc_mutex_unlock ();
- gtk_widget_queue_draw (widget);
+ return g_string_free (text, FALSE);
}
void
return;
}
- ev_document_doc_mutex_lock ();
- text = ev_document_get_text (ev_view->document,
- ev_view->current_page,
- &ev_view->selection);
- ev_document_doc_mutex_unlock ();
-
+ 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);
g_free (text);
}
-void
-ev_view_set_show_border (EvView *view, gboolean show_border)
-{
- g_return_if_fail (EV_IS_VIEW (view));
-
- view->show_border = show_border;
-
- gtk_widget_queue_resize (GTK_WIDGET (view));
-}
-
static void
ev_view_primary_get_cb (GtkClipboard *clipboard,
GtkSelectionData *selection_data,
return;
}
- ev_document_doc_mutex_lock ();
- text = ev_document_get_text (ev_view->document,
- ev_view->current_page,
- &ev_view->selection);
- ev_document_doc_mutex_unlock ();
+ 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);
}
gint *x_offset,
gint *y_offset)
{
- gint width, height;
-
- ev_page_cache_get_size (view->page_cache,
- view->current_page,
- view->scale,
- &width, &height);
+ int i;
- x -= (view->border.left + view->spacing);
- y -= (view->border.top + view->spacing);
-
- if ((x < 0) || (y < 0) ||
- (x >= width) || (y >= height)) {
- *page = -1;
+ 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 = view->current_page;
- *x_offset = (gint) x;
- *y_offset = (gint) y;
+
+ *page = -1;
}
static EvLink *
gdouble x,
gdouble y)
{
- gint page;
- gint x_offset, y_offset;
+ 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);
- return ev_link_mapping_find (link_mapping, x_offset /view->scale, y_offset /view->scale);
+ if (link_mapping)
+ return ev_link_mapping_find (link_mapping, x_offset / view->scale, y_offset / view->scale);
+ else
+ return NULL;
}
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) {
view->pressed_button = -1;
- if (view->has_selection) {
+ if (view->selections) {
ev_view_update_primary_selection (view);
} else if (view->document) {
EvLink *link;
}
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;
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_keypad (binding_set, GDK_Left, GTK_SCROLL_STEP_BACKWARD, TRUE);
add_scroll_binding_shifted (binding_set, GDK_BackSpace, EV_SCROLL_PAGE_BACKWARD, EV_SCROLL_PAGE_FORWARD, FALSE);
}
-void
-ev_view_set_spacing (EvView *view,
- int spacing)
-{
- g_return_if_fail (EV_IS_VIEW (view));
-
- view->spacing = spacing;
-
- if (view->document) {
- gtk_widget_queue_resize (GTK_WIDGET (view));
- }
-}
-
static void
ev_view_init (EvView *view)
{
GTK_WIDGET_SET_FLAGS (view, GTK_CAN_FOCUS);
- view->spacing = 0;
+ view->spacing = 10;
view->scale = 1.0;
view->current_page = 0;
view->pressed_button = -1;
view->cursor = EV_VIEW_CURSOR_NORMAL;
- view->show_border = TRUE;
+
+ view->continuous = TRUE;
+ view->dual_page = FALSE;
+ view->presentation = FALSE;
+ view->fullscreen = FALSE;
+ view->sizing_mode = EV_SIZING_FIT_WIDTH;
}
static void
{
char *message;
-// ev_document_doc_mutex_lock ();
if (view->current_page == view->find_page) {
int results;
-// ev_document_doc_mutex_lock ();
results = ev_document_find_get_n_results
(EV_DOCUMENT_FIND (view->document),
view->current_page);
-// ev_document_doc_mutex_unlock ();
/* TRANS: Sometimes this could be better translated as
"%d hit(s) on this page". Therefore this string
contains plural cases. */
EvRectangle rect;
GdkRectangle view_rect;
int n_results;
+ int page = view->find_page;
ev_document_doc_mutex_lock ();
- n_results = ev_document_find_get_n_results (find, view->current_page);
+ 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->current_page, view->find_result, &rect);
+ (find, page, view->find_result, &rect);
ev_document_doc_mutex_unlock ();
- doc_rect_to_view_rect (view, &rect, &view_rect);
+ doc_rect_to_view_rect (view, page, &rect, &view_rect);
ensure_rectangle_is_visible (view, &view_rect);
}
}
page = page - n_pages;
}
- // ev_document_doc_mutex_lock ();
has_results = ev_document_find_page_has_results
(EV_DOCUMENT_FIND (view->document), page);
if (has_results == -1) {
GtkWidget*
ev_view_new (void)
{
- return g_object_new (EV_TYPE_VIEW, NULL);
+ GtkWidget *view;
+
+ view = g_object_new (EV_TYPE_VIEW, NULL);
+
+ return view;
}
static void
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;
&old_width, &old_height);
view->current_page = new_page;
- view->has_selection = FALSE;
-
- compute_zoom_factor (view);
ev_page_cache_get_size (page_cache,
new_page,
compute_border (view, new_width, new_height, &(view->border));
- 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 (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
}
}
-static void
-ev_view_zoom (EvView *view,
- double factor,
- gboolean relative)
+#define EPSILON 0.0000001
+void
+ev_view_set_zoom (EvView *view,
+ double factor,
+ gboolean relative)
{
double scale;
scale = CLAMP (scale, MIN_SCALE, MAX_SCALE);
+ if (ABS (view->scale - scale) < EPSILON)
+ return;
view->scale = scale;
- view->width = view->height = -1;
gtk_widget_queue_resize (GTK_WIDGET (view));
}
+double
+ev_view_get_zoom (EvView *view)
+{
+ return view->scale;
+}
+
+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_set_dual_page (EvView *view,
+ gboolean dual_page)
+{
+ 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_fullscreen (EvView *view,
+ gboolean fullscreen)
+{
+ g_return_if_fail (EV_IS_VIEW (view));
+
+ fullscreen = fullscreen != FALSE;
+
+ if (view->fullscreen != fullscreen) {
+ view->fullscreen = fullscreen;
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+ }
+
+ g_object_notify (G_OBJECT (view), "fullscreen");
+}
+
gboolean
-ev_view_can_zoom_in (EvView *view)
+ev_view_get_fullscreen (EvView *view)
{
- if (view->width != -1 || view->height != -1) {
- return TRUE;
+ g_return_val_if_fail (EV_IS_VIEW (view), FALSE);
+
+ return view->fullscreen;
+}
+
+void
+ev_view_set_presentation (EvView *view,
+ gboolean presentation)
+{
+ g_return_if_fail (EV_IS_VIEW (view));
+
+ presentation = presentation != FALSE;
+
+ if (view->presentation == presentation)
+ return;
+
+ 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));
+
+ 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)
{
- if (view->width != -1 || view->height != -1) {
- return TRUE;
- }
-
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);
}
+
+
+static double
+zoom_for_size_fit_width (int doc_width,
+ int doc_height,
+ int target_width,
+ int target_height,
+ int vsb_width)
+{
+ double scale;
+
+ scale = (double)target_width / doc_width;
+
+ if (doc_height * scale > target_height)
+ scale = (double) (target_width - vsb_width) / doc_width;
+
+ return scale;
+}
+
+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)
+{
+ double w_scale;
+ double h_scale;
+
+ 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);
+}
+
+
+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);
+}
+
+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 ();
+
+ ev_view_set_zoom (view, scale, FALSE);
+}
+
+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 ();
+
+ ev_view_set_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);
+}
+
+static void
+ev_view_zoom_for_size_single_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_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 ();
+
+ ev_view_set_zoom (view, scale, FALSE);
+}
+
+
void
ev_view_zoom_normal (EvView *view)
{
- ev_view_zoom (view, 1.0, FALSE);
+ ev_view_set_zoom (view, 1.0, FALSE);
}
void
-ev_view_set_size (EvView *view,
- int width,
- int height)
+ev_view_set_zoom_for_size (EvView *view,
+ int width,
+ int height,
+ int vsb_width,
+ int hsb_height)
{
- if (!view->document) {
+ 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 (view->document == NULL)
return;
- }
- if (width != view->width || height != view->height) {
- view->width = width;
- view->height = height;
- gtk_widget_queue_resize (GTK_WIDGET (view));
- }
+ 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 *
gtk_widget_queue_draw (GTK_WIDGET (view));
}
}
+
void
ev_view_hide_cursor (EvView *view)
{
{
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;
+}