+ if (view->document) {
+ ev_page_cache_clear (view->document);
+ }
+}
+
+void
+ev_view_set_document (EvView *view,
+ EvDocument *document)
+{
+ g_return_if_fail (EV_IS_VIEW (view));
+
+ if (document != view->document) {
+ clear_caches (view);
+
+ if (view->document) {
+ g_signal_handlers_disconnect_by_func (view->document,
+ find_changed_cb,
+ view);
+ g_object_unref (view->document);
+ view->page_cache = NULL;
+
+ }
+
+ view->document = document;
+ view->find_page = 0;
+ view->find_result = 0;
+
+ if (view->document) {
+ g_object_ref (view->document);
+ if (EV_IS_DOCUMENT_FIND (view->document)) {
+ g_signal_connect (view->document,
+ "find_changed",
+ G_CALLBACK (find_changed_cb),
+ view);
+ }
+
+ setup_caches (view);
+ }
+
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+ }
+}
+
+/*** Zoom and sizing mode ***/
+
+#define EPSILON 0.0000001
+void
+ev_view_set_zoom (EvView *view,
+ double factor,
+ gboolean relative)
+{
+ double scale;
+
+ 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;
+ view->pending_resize = TRUE;
+
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+
+ g_object_notify (G_OBJECT (view), "zoom");
+}
+
+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;
+ view->pending_scroll = SCROLL_TO_CURRENT_PAGE;
+ 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->pending_scroll = SCROLL_TO_CURRENT_PAGE;
+ 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_get_fullscreen (EvView *view)
+{
+ 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 (GTK_WIDGET(view)->window,
+ >K_WIDGET (view)->style->black);
+ else
+ gdk_window_set_background (GTK_WIDGET(view)->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)
+{
+ return view->scale * ZOOM_OUT_FACTOR >= MIN_SCALE;
+}
+
+void
+ev_view_zoom_in (EvView *view)
+{
+ g_return_if_fail (view->sizing_mode == EV_SIZING_FREE);
+
+ view->pending_scroll = SCROLL_TO_CENTER;
+ ev_view_set_zoom (view, ZOOM_IN_FACTOR, TRUE);
+}
+
+void
+ev_view_zoom_out (EvView *view)
+{
+ g_return_if_fail (view->sizing_mode == EV_SIZING_FREE);
+
+ view->pending_scroll = SCROLL_TO_CENTER;
+ ev_view_set_zoom (view, ZOOM_OUT_FACTOR, TRUE);
+}
+
+static void
+ev_view_set_orientation (EvView *view,
+ EvOrientation orientation)
+{
+ ev_document_set_orientation (view->document, orientation);
+
+ clear_caches (view);
+ setup_caches (view);
+
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+}
+
+void
+ev_view_rotate_right (EvView *view)
+{
+ EvOrientation orientation, new_orientation;
+
+ orientation = ev_document_get_orientation (view->document);
+ if (orientation == EV_ORIENTATION_PORTRAIT) {
+ new_orientation = EV_ORIENTATION_LANDSCAPE;
+ } else if (orientation == EV_ORIENTATION_LANDSCAPE) {
+ new_orientation = EV_ORIENTATION_UPSIDEDOWN;
+ } else if (orientation == EV_ORIENTATION_UPSIDEDOWN) {
+ new_orientation = EV_ORIENTATION_SEASCAPE;
+ } else {
+ new_orientation = EV_ORIENTATION_PORTRAIT;
+ }
+ ev_view_set_orientation (view, new_orientation);
+}
+
+void
+ev_view_rotate_left (EvView *view)
+{
+ EvOrientation orientation, new_orientation;
+
+ orientation = ev_document_get_orientation (view->document);
+ if (orientation == EV_ORIENTATION_PORTRAIT) {
+ new_orientation = EV_ORIENTATION_SEASCAPE;
+ } else if (orientation == EV_ORIENTATION_SEASCAPE) {
+ new_orientation = EV_ORIENTATION_UPSIDEDOWN;
+ } else if (orientation == EV_ORIENTATION_UPSIDEDOWN) {
+ new_orientation = EV_ORIENTATION_LANDSCAPE;
+ } else {
+ new_orientation = EV_ORIENTATION_PORTRAIT;
+ }
+ ev_view_set_orientation (view, new_orientation);
+}
+
+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);
+}
+