*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
+#include "ev-mapping-list.h"
#include "ev-document-forms.h"
#include "ev-document-images.h"
#include "ev-document-links.h"
+#include "ev-document-layers.h"
#include "ev-document-misc.h"
-#include "ev-document-transition.h"
-#include "ev-page-cache.h"
#include "ev-pixbuf-cache.h"
-#include "ev-transition-animation.h"
+#include "ev-page-cache.h"
#include "ev-view-marshal.h"
#include "ev-document-annotations.h"
#include "ev-annotation-window.h"
+#include "ev-loading-window.h"
#include "ev-view.h"
#include "ev-view-accessible.h"
#include "ev-view-private.h"
#define EV_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EV_TYPE_VIEW))
#define EV_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EV_TYPE_VIEW, EvViewClass))
-enum {
- PROP_0,
- PROP_CONTINUOUS,
- PROP_DUAL_PAGE,
- PROP_FULLSCREEN,
- PROP_PRESENTATION,
- PROP_SIZING_MODE,
- PROP_ZOOM,
- PROP_ROTATION,
- PROP_HAS_SELECTION,
-};
-
enum {
SIGNAL_BINDING_ACTIVATED,
- SIGNAL_ZOOM_INVALID,
SIGNAL_HANDLE_LINK,
SIGNAL_EXTERNAL_LINK,
SIGNAL_POPUP_MENU,
- N_SIGNALS,
+ SIGNAL_SELECTION_CHANGED,
+ SIGNAL_SYNC_SOURCE,
+ SIGNAL_ANNOT_ADDED,
+ SIGNAL_LAYERS_CHANGED,
+ N_SIGNALS
};
enum {
#define ZOOM_IN_FACTOR 1.2
#define ZOOM_OUT_FACTOR (1.0/ZOOM_IN_FACTOR)
-#define MIN_SCALE 0.05409
-#define MAX_SCALE 4.0
-
#define SCROLL_TIME 150
/*** Scrolling ***/
-static void scroll_to_current_page (EvView *view,
- GtkOrientation orientation);
static void ev_view_set_scroll_adjustments (GtkLayout *layout,
GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment);
int width,
int height,
GtkBorder *border);
-static void get_page_y_offset (EvView *view,
- int page,
- double zoom,
- int *y_offset);
-static gboolean get_page_extents (EvView *view,
- gint page,
- GdkRectangle *page_area,
- GtkBorder *border);
+static void get_page_y_offset (EvView *view,
+ int page,
+ int *y_offset);
static void view_rect_to_doc_rect (EvView *view,
GdkRectangle *view_rect,
GdkRectangle *page_area,
int page,
EvRectangle *doc_rect,
GdkRectangle *view_rect);
+static gboolean get_dual_even_left (EvView *view);
static void find_page_at_location (EvView *view,
gdouble x,
gdouble y,
gint *page,
gint *x_offset,
gint *y_offset);
-static gboolean doc_point_to_view_point (EvView *view,
+static void doc_point_to_view_point (EvView *view,
int page,
EvPoint *doc_point,
GdkPoint *view_point);
static AtkObject *ev_view_get_accessible (GtkWidget *widget);
/*** Drawing ***/
-static guint32 ev_gdk_color_to_rgb (const GdkColor *color);
-static void draw_rubberband (GtkWidget *widget,
- GdkWindow *window,
- const GdkRectangle *rect,
- guchar alpha);
static void highlight_find_results (EvView *view,
int page);
+static void highlight_forward_search_results (EvView *view,
+ int page);
+static void focus_annotation (EvView *view,
+ int page,
+ GdkRectangle *clip);
static void draw_one_page (EvView *view,
gint page,
cairo_t *cr,
GtkBorder *border,
GdkRectangle *expose_area,
gboolean *page_ready);
-static void draw_loading_text (EvView *view,
- GdkRectangle *page_area,
- GdkRectangle *expose_area);
+static void show_loading_window (EvView *view);
+static void hide_loading_window (EvView *view);
static void ev_view_reload_page (EvView *view,
gint page,
- GdkRegion *region);
+ cairo_region_t *region);
+static void ev_view_loading_window_move (EvView *view);
/*** Callbacks ***/
+static void ev_view_change_page (EvView *view,
+ gint new_page);
static void job_finished_cb (EvPixbufCache *pixbuf_cache,
- GdkRegion *region,
+ cairo_region_t *region,
EvView *view);
-static void page_changed_cb (EvPageCache *page_cache,
- int new_page,
+static void ev_view_page_changed_cb (EvDocumentModel *model,
+ gint old_page,
+ gint new_page,
EvView *view);
static void on_adjustment_value_changed (GtkAdjustment *adjustment,
EvView *view);
/*** GObject ***/
static void ev_view_finalize (GObject *object);
static void ev_view_destroy (GtkObject *object);
-static void ev_view_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void ev_view_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
static void ev_view_class_init (EvViewClass *class);
static void ev_view_init (EvView *view);
/*** Zoom and sizing ***/
-static double zoom_for_size_fit_width (int doc_width,
- int doc_height,
- int target_width,
- int target_height,
- int vsb_width);
-static double zoom_for_size_fit_height (int doc_width,
- int doc_height,
- int target_width,
- int target_height,
- int vsb_height);
-static double zoom_for_size_best_fit (int doc_width,
- int doc_height,
- int target_width,
- int target_height,
- int vsb_width,
- int hsb_width);
-static void ev_view_zoom_for_size_presentation (EvView *view,
+static double zoom_for_size_fit_width (gdouble doc_width,
+ gdouble doc_height,
+ int target_width,
+ int target_height);
+static double zoom_for_size_fit_height (gdouble doc_width,
+ gdouble doc_height,
+ int target_width,
+ int target_height);
+static double zoom_for_size_best_fit (gdouble doc_width,
+ gdouble doc_height,
+ int target_width,
+ int target_height);
+static void ev_view_zoom_for_size (EvView *view,
int width,
- int height);
+ int 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 height);
static void ev_view_zoom_for_size_continuous (EvView *view,
int width,
- int height,
- int vsb_width,
- int hsb_height);
+ int height);
static void ev_view_zoom_for_size_dual_page (EvView *view,
int width,
- int height,
- int vsb_width,
- int hsb_height);
+ int height);
static void ev_view_zoom_for_size_single_page (EvView *view,
int width,
- int height,
- int vsb_width,
- int hsb_height);
+ int height);
/*** Cursors ***/
-static GdkCursor* ev_view_create_invisible_cursor (void);
static void ev_view_set_cursor (EvView *view,
EvViewCursor new_cursor);
static void ev_view_handle_cursor_over_xy (EvView *view,
static void jump_to_find_page (EvView *view,
EvViewFindDirection direction,
gint shift);
-
/*** Selection ***/
static void compute_selections (EvView *view,
EvSelectionStyle style,
gpointer data);
static void ev_view_update_primary_selection (EvView *ev_view);
-/*** Presentation ***/
-static void ev_view_presentation_transition_start (EvView *ev_view);
-static void ev_view_presentation_transition_stop (EvView *ev_view);
+G_DEFINE_TYPE (EvView, ev_view, GTK_TYPE_LAYOUT)
+/* HeightToPage cache */
+#define EV_HEIGHT_TO_PAGE_CACHE_KEY "ev-height-to-page-cache"
-G_DEFINE_TYPE (EvView, ev_view, GTK_TYPE_LAYOUT)
+static void
+build_height_to_page (EvHeightToPageCache *cache,
+ EvDocument *document,
+ gint rotation)
+{
+ gboolean swap, uniform, dual_even_left;
+ int i;
+ double uniform_height, page_height, next_page_height;
+ double saved_height;
+ gdouble u_width, u_height;
+ gint n_pages;
+
+ swap = (rotation == 90 || rotation == 270);
+
+ uniform = ev_document_is_page_size_uniform (document);
+ n_pages = ev_document_get_n_pages (document);
+ dual_even_left = (n_pages > 2);
+
+ g_free (cache->height_to_page);
+ g_free (cache->dual_height_to_page);
+
+ cache->rotation = rotation;
+ cache->height_to_page = g_new0 (gdouble, n_pages + 1);
+ cache->dual_height_to_page = g_new0 (gdouble, n_pages + 2);
+
+ if (uniform)
+ ev_document_get_page_size (document, 0, &u_width, &u_height);
+
+ saved_height = 0;
+ for (i = 0; i <= n_pages; i++) {
+ if (uniform) {
+ uniform_height = swap ? u_width : u_height;
+ cache->height_to_page[i] = i * uniform_height;
+ } else {
+ if (i < n_pages) {
+ gdouble w, h;
+
+ ev_document_get_page_size (document, i, &w, &h);
+ page_height = swap ? w : h;
+ } else {
+ page_height = 0;
+ }
+ cache->height_to_page[i] = saved_height;
+ saved_height += page_height;
+ }
+ }
+
+ if (dual_even_left && !uniform) {
+ gdouble w, h;
+
+ ev_document_get_page_size (document, 0, &w, &h);
+ saved_height = swap ? w : h;
+ } else {
+ saved_height = 0;
+ }
+
+ for (i = dual_even_left; i < n_pages + 2; i += 2) {
+ if (uniform) {
+ uniform_height = swap ? u_width : u_height;
+ cache->dual_height_to_page[i] = ((i + dual_even_left) / 2) * uniform_height;
+ if (i + 1 < n_pages + 2)
+ cache->dual_height_to_page[i + 1] = ((i + dual_even_left) / 2) * uniform_height;
+ } else {
+ if (i + 1 < n_pages) {
+ gdouble w, h;
+
+ ev_document_get_page_size (document, i + 1, &w, &h);
+ next_page_height = swap ? w : h;
+ } else {
+ next_page_height = 0;
+ }
+
+ if (i < n_pages) {
+ gdouble w, h;
+
+ ev_document_get_page_size (document, i, &w, &h);
+ page_height = swap ? w : h;
+ } else {
+ page_height = 0;
+ }
+
+ if (i + 1 < n_pages + 2) {
+ cache->dual_height_to_page[i] = saved_height;
+ cache->dual_height_to_page[i + 1] = saved_height;
+ saved_height += MAX(page_height, next_page_height);
+ } else {
+ cache->dual_height_to_page[i] = saved_height;
+ }
+ }
+ }
+}
static void
-scroll_to_current_page (EvView *view, GtkOrientation orientation)
+ev_height_to_page_cache_get_height (EvHeightToPageCache *cache,
+ EvDocument *document,
+ gint page,
+ gint rotation,
+ gdouble *height,
+ gdouble *dual_height)
{
- GdkPoint view_point;
+ if (cache->rotation != rotation)
+ build_height_to_page (cache, document, rotation);
- if (view->document == NULL) {
- return;
+ *height = cache->height_to_page[page];
+ *dual_height = cache->dual_height_to_page[page];
+}
+
+static void
+ev_height_to_page_cache_free (EvHeightToPageCache *cache)
+{
+ if (cache->height_to_page) {
+ g_free (cache->height_to_page);
+ cache->height_to_page = NULL;
+ }
+
+ if (cache->dual_height_to_page) {
+ g_free (cache->dual_height_to_page);
+ cache->dual_height_to_page = NULL;
+ }
+ g_free (cache);
+}
+
+static EvHeightToPageCache *
+ev_view_get_height_to_page_cache (EvView *view)
+{
+ EvHeightToPageCache *cache;
+
+ if (!view->document)
+ return NULL;
+
+ cache = g_object_get_data (G_OBJECT (view->document), EV_HEIGHT_TO_PAGE_CACHE_KEY);
+ if (!cache) {
+ cache = g_new0 (EvHeightToPageCache, 1);
+ build_height_to_page (cache, view->document, view->rotation);
+ g_object_set_data_full (G_OBJECT (view->document),
+ EV_HEIGHT_TO_PAGE_CACHE_KEY,
+ cache,
+ (GDestroyNotify)ev_height_to_page_cache_free);
}
- doc_point_to_view_point (view, view->current_page, &view->pending_point, &view_point);
+ return cache;
+}
+
+static void
+ev_view_get_height_to_page (EvView *view,
+ gint page,
+ gint *height,
+ gint *dual_height)
+{
+ gdouble h, dh;
+
+ if (!view->height_to_page_cache)
+ return;
+
+ ev_height_to_page_cache_get_height (view->height_to_page_cache,
+ view->document,
+ page,
+ view->rotation,
+ &h, &dh);
+ if (height)
+ *height = (gint)(h * view->scale + 0.5);
+
+ if (dual_height)
+ *dual_height = (gint)(dh * view->scale + 0.5);
+}
+
+static gint
+ev_view_get_scrollbar_size (EvView *view,
+ GtkOrientation orientation)
+{
+ GtkWidget *widget = GTK_WIDGET (view);
+ GtkWidget *sb;
+ GtkWidget *swindow = gtk_widget_get_parent (GTK_WIDGET (view));
+ GtkAllocation allocation;
+ GtkRequisition req;
+ gint spacing;
+
+ if (!GTK_IS_SCROLLED_WINDOW (swindow))
+ return 0;
+
+ gtk_widget_get_allocation (widget, &allocation);
if (orientation == GTK_ORIENTATION_VERTICAL) {
- view->pending_point.y = 0;
+ if (allocation.height >= view->requisition.height)
+ sb = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (swindow));
+ else
+ return 0;
} else {
- view->pending_point.x = 0;
+ if (allocation.width >= view->requisition.width)
+ sb = gtk_scrolled_window_get_hscrollbar (GTK_SCROLLED_WINDOW (swindow));
+ else
+ return 0;
}
+ gtk_widget_style_get (swindow, "scrollbar_spacing", &spacing, NULL);
+ gtk_widget_size_request (sb, &req);
+
+ return (orientation == GTK_ORIENTATION_VERTICAL ? req.width : req.height) + spacing;
+}
+
+static void
+scroll_to_point (EvView *view,
+ gdouble x,
+ gdouble y,
+ GtkOrientation orientation)
+{
+ gdouble page_size;
+ gdouble upper, lower;
+
if (orientation == GTK_ORIENTATION_VERTICAL) {
+ page_size = gtk_adjustment_get_page_size (view->vadjustment);
+ upper = gtk_adjustment_get_upper (view->vadjustment);
+ lower = gtk_adjustment_get_lower (view->vadjustment);
+
if (view->continuous) {
gtk_adjustment_clamp_page (view->vadjustment,
- view_point.y - view->spacing / 2,
- view_point.y + view->vadjustment->page_size);
+ y - view->spacing / 2,
+ y + page_size);
} else {
gtk_adjustment_set_value (view->vadjustment,
- CLAMP (view_point.y,
- view->vadjustment->lower,
- view->vadjustment->upper -
- view->vadjustment->page_size));
+ CLAMP (y, lower, upper - page_size));
}
} else {
+ page_size = gtk_adjustment_get_page_size (view->hadjustment);
+ upper = gtk_adjustment_get_upper (view->hadjustment);
+ lower = gtk_adjustment_get_lower (view->hadjustment);
+
if (view->dual_page) {
- gtk_adjustment_clamp_page (view->hadjustment,
- view_point.x,
- view_point.x + view->hadjustment->page_size);
+ gtk_adjustment_clamp_page (view->hadjustment, x,
+ x + page_size);
} else {
gtk_adjustment_set_value (view->hadjustment,
- CLAMP (view_point.x,
- view->hadjustment->lower,
- view->hadjustment->upper -
- view->hadjustment->page_size));
+ CLAMP (x, lower, upper - page_size));
}
}
}
+static void
+ev_view_scroll_to_page_position (EvView *view, GtkOrientation orientation)
+{
+ gdouble x, y;
+
+ if (!view->document)
+ return;
+
+ if ((orientation == GTK_ORIENTATION_VERTICAL && view->pending_point.y == 0) ||
+ (orientation == GTK_ORIENTATION_HORIZONTAL && view->pending_point.x == 0)) {
+ GdkRectangle page_area;
+ GtkBorder border;
+
+ ev_view_get_page_extents (view, view->current_page, &page_area, &border);
+ x = page_area.x;
+ y = page_area.y;
+ } else {
+ GdkPoint view_point;
+
+ doc_point_to_view_point (view, view->current_page,
+ &view->pending_point, &view_point);
+ x = view_point.x;
+ y = view_point.y;
+ }
+
+ scroll_to_point (view, x, y, orientation);
+}
+
static void
view_set_adjustment_values (EvView *view,
GtkOrientation orientation)
{
GtkWidget *widget = GTK_WIDGET (view);
GtkAdjustment *adjustment;
- int requisition;
- int allocation;
-
+ GtkAllocation allocation;
+ int req_size;
+ int alloc_size;
+ gdouble page_size;
+ gdouble value;
+ gdouble upper;
double factor;
gint new_value;
+ gtk_widget_get_allocation (widget, &allocation);
+
if (orientation == GTK_ORIENTATION_HORIZONTAL) {
- requisition = widget->requisition.width;
- allocation = widget->allocation.width;
+ req_size = view->requisition.width;
+ alloc_size = allocation.width;
adjustment = view->hadjustment;
} else {
- requisition = widget->requisition.height;
- allocation = widget->allocation.height;
+ req_size = view->requisition.height;
+ alloc_size = allocation.height;
adjustment = view->vadjustment;
}
return;
factor = 1.0;
+ value = gtk_adjustment_get_value (adjustment);
+ upper = gtk_adjustment_get_upper (adjustment);
+ page_size = gtk_adjustment_get_page_size (adjustment);
+
switch (view->pending_scroll) {
case SCROLL_TO_KEEP_POSITION:
case SCROLL_TO_FIND_LOCATION:
- factor = (adjustment->value) / adjustment->upper;
+ factor = value / upper;
break;
case SCROLL_TO_PAGE_POSITION:
break;
case SCROLL_TO_CENTER:
- factor = (adjustment->value + adjustment->page_size * 0.5) / adjustment->upper;
+ factor = (value + page_size * 0.5) / upper;
break;
}
- adjustment->page_size = allocation;
- adjustment->step_increment = allocation * 0.1;
- adjustment->page_increment = allocation * 0.9;
- adjustment->lower = 0;
- adjustment->upper = MAX (allocation, requisition);
+ upper = MAX (alloc_size, req_size);
+ page_size = alloc_size;
+
+ gtk_adjustment_set_page_size (adjustment, page_size);
+ gtk_adjustment_set_step_increment (adjustment, alloc_size * 0.1);
+ gtk_adjustment_set_page_increment (adjustment, alloc_size * 0.9);
+ gtk_adjustment_set_lower (adjustment, 0);
+ gtk_adjustment_set_upper (adjustment, upper);
/*
* We add 0.5 to the values before to average out our rounding errors.
switch (view->pending_scroll) {
case SCROLL_TO_KEEP_POSITION:
case SCROLL_TO_FIND_LOCATION:
- new_value = CLAMP (adjustment->upper * factor + 0.5, 0, adjustment->upper - adjustment->page_size);
+ new_value = CLAMP (upper * factor + 0.5, 0, upper - page_size);
gtk_adjustment_set_value (adjustment, (int)new_value);
break;
case SCROLL_TO_PAGE_POSITION:
- scroll_to_current_page (view, orientation);
+ ev_view_scroll_to_page_position (view, orientation);
break;
case SCROLL_TO_CENTER:
- new_value = CLAMP (adjustment->upper * factor - adjustment->page_size * 0.5 + 0.5,
- 0, adjustment->upper - adjustment->page_size);
+ new_value = CLAMP (upper * factor - page_size * 0.5 + 0.5,
+ 0, upper - page_size);
gtk_adjustment_set_value (adjustment, (int)new_value);
break;
}
static void
view_update_range_and_current_page (EvView *view)
{
- gint current_page;
- gint best_current_page = -1;
gint start = view->start_page;
gint end = view->end_page;
-
- /* Presentation trumps all other modes */
- if (view->presentation) {
- view->start_page = view->current_page;
- view->end_page = view->current_page;
- } else if (view->continuous) {
+
+ if (ev_document_get_n_pages (view->document) <= 0 ||
+ !ev_document_check_dimensions (view->document))
+ return;
+
+ if (view->continuous) {
GdkRectangle current_area, unused, page_area;
GtkBorder border;
gboolean found = FALSE;
gint area_max = -1, area;
- int i;
+ gint best_current_page = -1;
+ int i, j = 0;
if (!(view->vadjustment && view->hadjustment))
return;
- current_area.x = view->hadjustment->value;
- current_area.width = view->hadjustment->upper;
- current_area.y = view->vadjustment->value;
- current_area.height = view->vadjustment->page_size;
+ current_area.x = gtk_adjustment_get_value (view->hadjustment);
+ current_area.width = gtk_adjustment_get_page_size (view->hadjustment);
+ current_area.y = gtk_adjustment_get_value (view->vadjustment);
+ current_area.height = gtk_adjustment_get_page_size (view->vadjustment);
- for (i = 0; i < ev_page_cache_get_n_pages (view->page_cache); i++) {
+ for (i = 0; i < ev_document_get_n_pages (view->document); i++) {
- get_page_extents (view, i, &page_area, &border);
+ ev_view_get_page_extents (view, i, &page_area, &border);
if (gdk_rectangle_intersect (¤t_area, &page_area, &unused)) {
area = unused.width * unused.height;
}
view->end_page = i;
+ j = 0;
} else if (found && view->current_page <= view->end_page) {
+ if (view->dual_page && j < 1) {
+ /* In dual mode we stop searching
+ * after two consecutive non-visible pages.
+ */
+ j++;
+ continue;
+ }
break;
}
}
+ if (view->pending_scroll == SCROLL_TO_KEEP_POSITION) {
+ best_current_page = MAX (best_current_page, view->start_page);
+
+ if (view->current_page != best_current_page) {
+ view->current_page = best_current_page;
+ hide_loading_window (view);
+ ev_document_model_set_page (view->model, best_current_page);
+ }
+ }
} else if (view->dual_page) {
- if (view->current_page % 2 == ev_page_cache_get_dual_even_left (view->page_cache)) {
+ if (view->current_page % 2 == get_dual_even_left (view)) {
view->start_page = view->current_page;
- if (view->current_page + 1 < ev_page_cache_get_n_pages (view->page_cache))
+ if (view->current_page + 1 < ev_document_get_n_pages (view->document))
view->end_page = view->start_page + 1;
- else
+ else
view->end_page = view->start_page;
} else {
if (view->current_page < 1)
view->end_page = view->current_page;
}
- best_current_page = MAX (best_current_page, view->start_page);
- current_page = ev_page_cache_get_current_page (view->page_cache);
-
- if ((current_page != best_current_page) && (view->pending_scroll == SCROLL_TO_KEEP_POSITION)) {
- view->current_page = best_current_page;
- ev_page_cache_set_current_page (view->page_cache, best_current_page);
- }
+ if (view->start_page == -1 || view->end_page == -1)
+ return;
if (start != view->start_page || end != view->end_page) {
gint i;
- for (i = start; i < view->start_page; i++) {
+ for (i = start; i < view->start_page && start != -1; i++) {
hide_annotation_windows (view, i);
}
- for (i = end; i > view->end_page; i--) {
+ for (i = end; i > view->end_page && end != -1; i--) {
hide_annotation_windows (view, i);
}
-
- ev_pixbuf_cache_set_page_range (view->pixbuf_cache,
- view->start_page,
- view->end_page,
- view->rotation,
- view->scale,
- view->selection_info.selections);
}
+
+ ev_page_cache_set_page_range (view->page_cache,
+ view->start_page,
+ view->end_page);
+ ev_pixbuf_cache_set_page_range (view->pixbuf_cache,
+ view->start_page,
+ view->end_page,
+ view->selection_info.selections);
+
+ if (ev_pixbuf_cache_get_surface (view->pixbuf_cache, view->current_page))
+ gtk_widget_queue_draw (GTK_WIDGET (view));
}
static void
G_TYPE_BOOLEAN, horizontal);
}
+static gdouble
+compute_scroll_increment (EvView *view,
+ GtkScrollType scroll)
+{
+ GtkWidget *widget = GTK_WIDGET (view);
+ GtkAdjustment *adjustment = view->vadjustment;
+ cairo_region_t *text_region, *region;
+ GtkAllocation allocation;
+ gint page;
+ GdkRectangle rect;
+ EvRectangle doc_rect;
+ GdkRectangle page_area;
+ GtkBorder border;
+ gdouble fraction = 1.0;
+
+ if (scroll != GTK_SCROLL_PAGE_BACKWARD && scroll != GTK_SCROLL_PAGE_FORWARD)
+ return gtk_adjustment_get_page_size (adjustment);
+
+ page = scroll == GTK_SCROLL_PAGE_BACKWARD ? view->start_page : view->end_page;
+
+ text_region = ev_page_cache_get_text_mapping (view->page_cache, page);
+ if (!text_region || cairo_region_is_empty (text_region))
+ return gtk_adjustment_get_page_size (adjustment);
+
+ gtk_widget_get_allocation (widget, &allocation);
+ ev_view_get_page_extents (view, page, &page_area, &border);
+ rect.x = page_area.x + view->scroll_x;
+ rect.y = view->scroll_y + (scroll == GTK_SCROLL_PAGE_BACKWARD ? 5 : allocation.height - 5);
+ rect.width = page_area.width;
+ rect.height = 1;
+ view_rect_to_doc_rect (view, &rect, &page_area, &doc_rect);
+
+ /* Convert the doc rectangle into a GdkRectangle */
+ rect.x = doc_rect.x1;
+ rect.y = doc_rect.y1;
+ rect.width = doc_rect.x2 - doc_rect.x1;
+ rect.height = MAX (1, doc_rect.y2 - doc_rect.y1);
+ region = cairo_region_create_rectangle (&rect);
+
+ cairo_region_intersect (region, text_region);
+ if (cairo_region_num_rectangles (region)) {
+ EvRenderContext *rc;
+ EvPage *ev_page;
+ cairo_region_t *sel_region;
+
+ cairo_region_get_rectangle (region, 0, &rect);
+ ev_page = ev_document_get_page (view->document, page);
+ rc = ev_render_context_new (ev_page, view->rotation, view->scale);
+ g_object_unref (ev_page);
+ /* Get the selection region to know the height of the line */
+ doc_rect.x1 = doc_rect.x2 = rect.x + 0.5;
+ doc_rect.y1 = doc_rect.y2 = rect.y + 0.5;
+
+ ev_document_doc_mutex_lock ();
+ sel_region = ev_selection_get_selection_region (EV_SELECTION (view->document),
+ rc, EV_SELECTION_STYLE_LINE,
+ &doc_rect);
+ ev_document_doc_mutex_unlock ();
+
+ g_object_unref (rc);
+
+ if (cairo_region_num_rectangles (sel_region) > 0) {
+ cairo_region_get_rectangle (sel_region, 0, &rect);
+ fraction = 1 - (rect.height / gtk_adjustment_get_page_size (adjustment));
+ }
+ cairo_region_destroy (sel_region);
+ }
+ cairo_region_destroy (region);
+
+ return gtk_adjustment_get_page_size (adjustment) * fraction;
+
+}
+
void
ev_view_scroll (EvView *view,
GtkScrollType scroll,
{
GtkAdjustment *adjustment;
double value, increment;
+ gdouble upper, lower;
+ gdouble page_size;
+ gdouble step_increment;
gboolean first_page = FALSE;
gboolean last_page = FALSE;
view->jump_to_find_result = FALSE;
- if (view->presentation || view->sizing_mode == EV_SIZING_BEST_FIT) {
+ if (view->sizing_mode == EV_SIZING_BEST_FIT) {
switch (scroll) {
case GTK_SCROLL_PAGE_BACKWARD:
case GTK_SCROLL_STEP_BACKWARD:
/* Assign values for increment and vertical adjustment */
adjustment = horizontal ? view->hadjustment : view->vadjustment;
- increment = adjustment->page_size * 0.75;
- value = adjustment->value;
+ value = gtk_adjustment_get_value (adjustment);
+ upper = gtk_adjustment_get_upper (adjustment);
+ lower = gtk_adjustment_get_lower (adjustment);
+ page_size = gtk_adjustment_get_page_size (adjustment);
+ step_increment = gtk_adjustment_get_step_increment (adjustment);
/* 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)
+ if (view->current_page == ev_document_get_n_pages (view->document) - 1)
last_page = TRUE;
switch (scroll) {
case GTK_SCROLL_PAGE_BACKWARD:
/* Do not jump backwards if at the first page */
- if (value == (adjustment->lower) && first_page) {
+ if (value == 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;
+ } else if (value == lower) {
+ value = upper - page_size;
ev_view_previous_page (view);
/* Jump to the top */
} else {
- value = MAX (value - increment, adjustment->lower);
+ increment = compute_scroll_increment (view, GTK_SCROLL_PAGE_BACKWARD);
+ value = MAX (value - increment, lower);
}
break;
case GTK_SCROLL_PAGE_FORWARD:
/* Do not jump forward if at the last page */
- if (value == (adjustment->upper - adjustment->page_size) && last_page) {
+ if (value == (upper - 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)) {
+ } else if (value == (upper - page_size)) {
value = 0;
ev_view_next_page (view);
/* Jump to the bottom */
} else {
- value = MIN (value + increment, adjustment->upper - adjustment->page_size);
+ increment = compute_scroll_increment (view, GTK_SCROLL_PAGE_FORWARD);
+ value = MIN (value + increment, upper - page_size);
}
break;
case GTK_SCROLL_STEP_BACKWARD:
- value -= adjustment->step_increment;
+ value -= step_increment;
break;
case GTK_SCROLL_STEP_FORWARD:
- value += adjustment->step_increment;
+ value += step_increment;
break;
case GTK_SCROLL_STEP_DOWN:
- value -= adjustment->step_increment / 10;
+ value -= step_increment / 10;
break;
case GTK_SCROLL_STEP_UP:
- value += adjustment->step_increment / 10;
+ value += step_increment / 10;
break;
default:
break;
}
- value = CLAMP (value, adjustment->lower,
- adjustment->upper - adjustment->page_size);
+ value = CLAMP (value, lower, upper - page_size);
gtk_adjustment_set_value (adjustment, value);
}
{
GtkWidget *widget = GTK_WIDGET (view);
GtkAdjustment *adjustment;
+ GtkAllocation allocation;
+ gdouble adj_value;
int value;
view->pending_scroll = SCROLL_TO_FIND_LOCATION;
+ gtk_widget_get_allocation (widget, &allocation);
+
adjustment = view->vadjustment;
+ adj_value = gtk_adjustment_get_value (adjustment);
- if (rect->y < adjustment->value) {
- value = MAX (adjustment->lower, rect->y - MARGIN);
+ if (rect->y < adj_value) {
+ value = MAX (gtk_adjustment_get_lower (adjustment), rect->y - MARGIN);
gtk_adjustment_set_value (view->vadjustment, value);
- } else if (rect->y + rect->height >
- adjustment->value + widget->allocation.height) {
- value = MIN (adjustment->upper, rect->y + rect->height -
- widget->allocation.height + MARGIN);
+ } else if (rect->y + rect->height > adj_value + allocation.height) {
+ value = MIN (gtk_adjustment_get_upper (adjustment), rect->y + rect->height -
+ allocation.height + MARGIN);
gtk_adjustment_set_value (view->vadjustment, value);
}
adjustment = view->hadjustment;
+ adj_value = gtk_adjustment_get_value (adjustment);
- if (rect->x < adjustment->value) {
- value = MAX (adjustment->lower, rect->x - MARGIN);
+ if (rect->x < adj_value) {
+ value = MAX (gtk_adjustment_get_lower (adjustment), rect->x - MARGIN);
gtk_adjustment_set_value (view->hadjustment, value);
- } else if (rect->x + rect->height >
- adjustment->value + widget->allocation.width) {
- value = MIN (adjustment->upper, rect->x + rect->width -
- widget->allocation.width + MARGIN);
+ } else if (rect->x + rect->height > adj_value + allocation.width) {
+ value = MIN (gtk_adjustment_get_upper (adjustment), rect->x + rect->width -
+ allocation.width + MARGIN);
gtk_adjustment_set_value (view->hadjustment, value);
}
static void
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);
- }
+ ev_document_misc_get_page_border_size (width, height, border);
+}
+
+void
+_get_page_size_for_scale_and_rotation (EvDocument *document,
+ gint page,
+ gdouble scale,
+ gint rotation,
+ gint *page_width,
+ gint *page_height)
+{
+ gdouble w, h;
+ gint width, height;
+
+ ev_document_get_page_size (document, page, &w, &h);
+
+ width = (gint)(w * scale + 0.5);
+ height = (gint)(h * scale + 0.5);
+
+ if (page_width)
+ *page_width = (rotation == 0 || rotation == 180) ? width : height;
+ if (page_height)
+ *page_height = (rotation == 0 || rotation == 180) ? height : width;
+}
+
+static void
+ev_view_get_page_size (EvView *view,
+ gint page,
+ gint *page_width,
+ gint *page_height)
+{
+ _get_page_size_for_scale_and_rotation (view->document,
+ page,
+ view->scale,
+ view->rotation,
+ page_width,
+ page_height);
+}
+
+static void
+ev_view_get_max_page_size (EvView *view,
+ gint *max_width,
+ gint *max_height)
+{
+ double w, h;
+ gint width, height;
+
+ ev_document_get_max_page_size (view->document, &w, &h);
+
+ width = (gint)(w * view->scale + 0.5);
+ height = (gint)(h * view->scale + 0.5);
+
+ if (max_width)
+ *max_width = (view->rotation == 0 || view->rotation == 180) ? width : height;
+ if (max_height)
+ *max_height = (view->rotation == 0 || view->rotation == 180) ? height : width;
}
static void
-get_page_y_offset (EvView *view, int page, double zoom, int *y_offset)
+get_page_y_offset (EvView *view, int page, int *y_offset)
{
int max_width, offset;
GtkBorder border;
g_return_if_fail (y_offset != NULL);
- ev_page_cache_get_max_width (view->page_cache, view->rotation, zoom, &max_width);
-
+ ev_view_get_max_page_size (view, &max_width, NULL);
compute_border (view, max_width, max_width, &border);
if (view->dual_page) {
- ev_page_cache_get_height_to_page (view->page_cache, page,
- view->rotation, zoom, NULL, &offset);
- offset += ((page + ev_page_cache_get_dual_even_left (view->page_cache)) / 2 + 1) * view->spacing + ((page + ev_page_cache_get_dual_even_left (view->page_cache)) / 2 ) * (border.top + border.bottom);
+ ev_view_get_height_to_page (view, page, NULL, &offset);
+ offset += ((page + get_dual_even_left (view)) / 2 + 1) * view->spacing +
+ ((page + get_dual_even_left (view)) / 2 ) * (border.top + border.bottom);
} else {
- ev_page_cache_get_height_to_page (view->page_cache, page,
- view->rotation, zoom, &offset, NULL);
+ ev_view_get_height_to_page (view, page, &offset, NULL);
offset += (page + 1) * view->spacing + page * (border.top + border.bottom);
}
return;
}
-static gboolean
-get_page_extents (EvView *view,
- gint page,
- GdkRectangle *page_area,
- GtkBorder *border)
+gboolean
+ev_view_get_page_extents (EvView *view,
+ gint page,
+ GdkRectangle *page_area,
+ GtkBorder *border)
{
GtkWidget *widget;
int width, height;
+ GtkAllocation allocation;
widget = GTK_WIDGET (view);
+ gtk_widget_get_allocation (widget, &allocation);
/* Get the size of the page */
- ev_page_cache_get_size (view->page_cache, page,
- view->rotation,
- view->scale,
- &width, &height);
+ ev_view_get_page_size (view, page, &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) {
+ if (view->continuous) {
gint max_width;
gint x, y;
- ev_page_cache_get_max_width (view->page_cache, view->rotation,
- view->scale, &max_width);
+ ev_view_get_max_page_size (view, &max_width, NULL);
max_width = max_width + border->left + border->right;
/* Get the location of the bounding box */
if (view->dual_page) {
- x = view->spacing + ((page % 2 == ev_page_cache_get_dual_even_left (view->page_cache)) ? 0 : 1) * (max_width + view->spacing);
- x = x + MAX (0, widget->allocation.width - (max_width * 2 + view->spacing * 3)) / 2;
- if (page % 2 == ev_page_cache_get_dual_even_left (view->page_cache))
+ x = view->spacing + ((page % 2 == get_dual_even_left (view)) ? 0 : 1) * (max_width + view->spacing);
+ x = x + MAX (0, allocation.width - (max_width * 2 + view->spacing * 3)) / 2;
+ if (page % 2 == get_dual_even_left (view))
x = x + (max_width - width - border->left - border->right);
} else {
x = view->spacing;
- x = x + MAX (0, widget->allocation.width - (width + view->spacing * 2)) / 2;
+ x = x + MAX (0, allocation.width - (width + view->spacing * 2)) / 2;
}
- get_page_y_offset (view, page, view->scale, &y);
+ get_page_y_offset (view, page, &y);
page_area->x = x;
page_area->y = y;
GtkBorder overall_border;
gint other_page;
- other_page = (page % 2 == ev_page_cache_get_dual_even_left (view->page_cache)) ? page + 1: page - 1;
+ other_page = (page % 2 == get_dual_even_left (view)) ? page + 1: page - 1;
/* First, we get the bounding box of the two pages */
- if (other_page < ev_page_cache_get_n_pages (view->page_cache)
+ if (other_page < ev_document_get_n_pages (view->document)
&& (0 <= other_page)) {
- ev_page_cache_get_size (view->page_cache,
- other_page,
- view->rotation,
- view->scale,
- &width_2, &height_2);
+ ev_view_get_page_size (view, other_page,
+ &width_2, &height_2);
if (width_2 > width)
max_width = width_2;
if (height_2 > height)
y = view->spacing;
/* Adjust for being the left or right page */
- if (page % 2 == ev_page_cache_get_dual_even_left (view->page_cache))
+ if (page % 2 == get_dual_even_left (view))
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 -
+ x = x + MAX (0, 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;
+ y = y + MAX (0, 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 + border->left + border->right + view->spacing * 2))/2;
- y = y + MAX (0, widget->allocation.height - (height + border->top + border->bottom + view->spacing * 2))/2;
+ x = x + MAX (0, allocation.width - (width + border->left + border->right + view->spacing * 2))/2;
+ y = y + MAX (0, allocation.height - (height + border->top + border->bottom + view->spacing * 2))/2;
}
page_area->x = x;
return TRUE;
}
+static void
+get_doc_page_size (EvView *view,
+ gint page,
+ gdouble *width,
+ gdouble *height)
+{
+ double w, h;
+
+ ev_document_get_page_size (view->document, page, &w, &h);
+ if (view->rotation == 0 || view->rotation == 180) {
+ if (width) *width = w;
+ if (height) *height = h;
+ } else {
+ if (width) *width = h;
+ if (height) *height = w;
+ }
+}
+
static void
view_point_to_doc_point (EvView *view,
GdkPoint *view_point,
doc_rect->y2 = doc_rect->y1 + (double) view_rect->height / view->scale;
}
-static gboolean
+static void
doc_point_to_view_point (EvView *view,
int page,
EvPoint *doc_point,
GdkRectangle page_area;
GtkBorder border;
double x, y, view_x, view_y;
- int width, height;
+ gdouble width, height;
- ev_page_cache_get_size (view->page_cache, page,
- view->rotation,
- 1.0,
- &width, &height);
+ get_doc_page_size (view, page, &width, &height);
if (view->rotation == 0) {
x = doc_point->x;
g_assert_not_reached ();
}
- get_page_extents (view, page, &page_area, &border);
+ ev_view_get_page_extents (view, page, &page_area, &border);
- view_x = x * view->scale;
- view_y = y * view->scale;
+ view_x = CLAMP (x * view->scale, 0, page_area.width);
+ view_y = CLAMP (y * view->scale, 0, page_area.height);
view_point->x = view_x + page_area.x;
view_point->y = view_y + page_area.y;
-
- return (view_x > 0 && view_x <= page_area.width &&
- view_y > 0 && view_y <= page_area.height);
}
static void
GdkRectangle page_area;
GtkBorder border;
double x, y, w, h;
- int width, height;
+ gdouble width, height;
- ev_page_cache_get_size (view->page_cache, page,
- view->rotation,
- 1.0,
- &width, &height);
+ get_doc_page_size (view, page, &width, &height);
if (view->rotation == 0) {
x = doc_rect->x1;
g_assert_not_reached ();
}
- get_page_extents (view, page, &page_area, &border);
+ ev_view_get_page_extents (view, page, &page_area, &border);
view_rect->x = x * view->scale + page_area.x;
view_rect->y = y * view->scale + page_area.y;
view_rect->height = h * view->scale;
}
+static gboolean
+get_dual_even_left (EvView *view)
+{
+ return (ev_document_get_n_pages (view->document) > 2);
+}
+
static void
find_page_at_location (EvView *view,
gdouble x,
g_assert (x_offset);
g_assert (y_offset);
- for (i = view->start_page; i <= view->end_page; i++) {
+ for (i = view->start_page; i >= 0 && i <= view->end_page; i++) {
GdkRectangle page_area;
GtkBorder border;
- if (! get_page_extents (view, i, &page_area, &border))
+ if (! ev_view_get_page_extents (view, i, &page_area, &border))
continue;
if ((x >= page_area.x + border.left) &&
gdouble x,
gdouble y)
{
- GdkRegion *region;
+ cairo_region_t *region;
gint page = -1;
gint x_offset = 0, y_offset = 0;
if (page == -1)
return FALSE;
- region = ev_pixbuf_cache_get_text_mapping (view->pixbuf_cache, page);
+ region = ev_page_cache_get_text_mapping (view->page_cache, page);
if (region)
- return gdk_region_point_in (region, x_offset / view->scale, y_offset / view->scale);
+ return cairo_region_contains_point (region, x_offset / view->scale, y_offset / view->scale);
else
return FALSE;
}
-static int
-ev_view_get_width (EvView *view)
-{
- return GTK_WIDGET (view)->allocation.width;
-}
-
-static int
-ev_view_get_height (EvView *view)
-{
- return GTK_WIDGET (view)->allocation.height;
-}
-
static gboolean
location_in_selected_text (EvView *view,
gdouble x,
continue;
if (selection->covered_region &&
- gdk_region_point_in (selection->covered_region, x_offset, y_offset))
+ cairo_region_contains_point (selection->covered_region, x_offset, y_offset))
return TRUE;
}
gint *x_new,
gint *y_new)
{
- int width, height;
+ gdouble width, height;
double x, y;
- ev_page_cache_get_size (view->page_cache, page,
- view->rotation,
- 1.0,
- &width, &height);
+ get_doc_page_size (view, page, &width, &height);
x_offset = x_offset / view->scale;
y_offset = y_offset / view->scale;
return TRUE;
}
+static gboolean
+get_doc_point_from_location (EvView *view,
+ gdouble x,
+ gdouble y,
+ gint *page,
+ gint *x_new,
+ gint *y_new)
+{
+ gint x_offset = 0, y_offset = 0;
+
+ x += view->scroll_x;
+ y += view->scroll_y;
+ find_page_at_location (view, x, y, page, &x_offset, &y_offset);
+ if (*page == -1)
+ return FALSE;
+
+ return get_doc_point_from_offset (view, *page, x_offset, y_offset, x_new, y_new);
+}
+
+static void
+ev_view_get_area_from_mapping (EvView *view,
+ guint page,
+ EvMappingList *mapping_list,
+ gconstpointer data,
+ GdkRectangle *area)
+{
+ EvMapping *mapping;
+
+ mapping = ev_mapping_list_find (mapping_list, data);
+ doc_rect_to_view_rect (view, page, &mapping->area, area);
+ area->x -= view->scroll_x;
+ area->y -= view->scroll_y;
+}
+
+
/*** Hyperref ***/
static EvLink *
ev_view_get_link_at_location (EvView *view,
gdouble y)
{
gint page = -1;
- gint x_offset = 0, y_offset = 0;
gint x_new = 0, y_new = 0;
- GList *link_mapping;
+ EvMappingList *link_mapping;
if (!EV_IS_DOCUMENT_LINKS (view->document))
return NULL;
-
- x += view->scroll_x;
- y += view->scroll_y;
-
- find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
-
- if (page == -1)
- return NULL;
-
- if (get_doc_point_from_offset (view, page, x_offset,
- y_offset, &x_new, &y_new) == FALSE)
+ if (!get_doc_point_from_location (view, x, y, &page, &x_new, &y_new))
return NULL;
- link_mapping = ev_pixbuf_cache_get_link_mapping (view->pixbuf_cache, page);
+ link_mapping = ev_page_cache_get_link_mapping (view->page_cache, page);
if (link_mapping)
- return ev_link_mapping_find (link_mapping, x_new, y_new);
+ return ev_mapping_list_get_data (link_mapping, x_new, y_new);
else
return NULL;
}
EvPoint doc_point;
gdouble zoom, left, top;
gboolean change_left, change_top;
+ GtkAllocation allocation;
+
+ gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
left = ev_link_dest_get_left (dest, &change_left);
top = ev_link_dest_get_top (dest, &change_top);
zoom = zoom_for_size_best_fit (ev_link_dest_get_right (dest) - left,
ev_link_dest_get_bottom (dest) - top,
- ev_view_get_width (view),
- ev_view_get_height (view), 0, 0);
+ allocation.width,
+ allocation.height);
- ev_view_set_sizing_mode (view, EV_SIZING_FREE);
- ev_view_set_zoom (view, zoom, FALSE);
+ ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE);
+ ev_document_model_set_scale (view->model, zoom);
doc_point.x = change_left ? left : 0;
doc_point.y = change_top ? top : 0;
-
- view->current_page = ev_link_dest_get_page (dest);
- if (change_left || change_top)
- view->pending_point = doc_point;
- view->pending_scroll = SCROLL_TO_PAGE_POSITION;
+ view->pending_point = doc_point;
- gtk_widget_queue_resize (GTK_WIDGET (view));
+ ev_view_change_page (view, ev_link_dest_get_page (dest));
}
static void
goto_fitv_dest (EvView *view, EvLinkDest *dest)
{
EvPoint doc_point;
- int doc_width, doc_height, page;
+ gdouble doc_width, doc_height;
+ gint page;
double zoom, left;
gboolean change_left;
+ GtkAllocation allocation;
+
+ gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
page = ev_link_dest_get_page (dest);
- ev_page_cache_get_size (view->page_cache, page, 0, 1.0, &doc_width, &doc_height);
+ ev_document_get_page_size (view->document, page, &doc_width, &doc_height);
left = ev_link_dest_get_left (dest, &change_left);
doc_point.x = change_left ? left : 0;
doc_point.y = 0;
zoom = zoom_for_size_fit_height (doc_width - doc_point.x , doc_height,
- ev_view_get_width (view),
- ev_view_get_height (view), 0);
+ allocation.width,
+ allocation.height);
- ev_view_set_sizing_mode (view, EV_SIZING_FREE);
- ev_view_set_zoom (view, zoom, FALSE);
+ ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE);
+ ev_document_model_set_scale (view->model, zoom);
- view->current_page = page;
- if (change_left)
- view->pending_point = doc_point;
- view->pending_scroll = SCROLL_TO_PAGE_POSITION;
+ view->pending_point = doc_point;
- gtk_widget_queue_resize (GTK_WIDGET (view));
+ ev_view_change_page (view, page);
}
static void
goto_fith_dest (EvView *view, EvLinkDest *dest)
{
EvPoint doc_point;
- int doc_width, doc_height, page;
+ gdouble doc_width, doc_height;
+ gint page;
gdouble zoom, top;
gboolean change_top;
+ GtkAllocation allocation;
+
+ gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
page = ev_link_dest_get_page (dest);
- ev_page_cache_get_size (view->page_cache, page, 0, 1.0, &doc_width, &doc_height);
+ ev_document_get_page_size (view->document, page, &doc_width, &doc_height);
top = ev_link_dest_get_top (dest, &change_top);
doc_point.y = change_top ? top : 0;
zoom = zoom_for_size_fit_width (doc_width, top,
- ev_view_get_width (view),
- ev_view_get_height (view), 0);
+ allocation.width,
+ allocation.height);
- ev_view_set_sizing_mode (view, EV_SIZING_FIT_WIDTH);
- ev_view_set_zoom (view, zoom, FALSE);
+ ev_document_model_set_sizing_mode (view->model, EV_SIZING_FIT_WIDTH);
+ ev_document_model_set_scale (view->model, zoom);
- view->current_page = page;
- if (change_top)
- view->pending_point = doc_point;
- view->pending_scroll = SCROLL_TO_PAGE_POSITION;
+ view->pending_point = doc_point;
- gtk_widget_queue_resize (GTK_WIDGET (view));
+ ev_view_change_page (view, page);
}
static void
goto_fit_dest (EvView *view, EvLinkDest *dest)
{
double zoom;
- int doc_width, doc_height;
+ gdouble doc_width, doc_height;
int page;
+ GtkAllocation allocation;
- page = ev_link_dest_get_page (dest);
- ev_page_cache_get_size (view->page_cache, page, 0, 1.0, &doc_width, &doc_height);
+ gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
- zoom = zoom_for_size_best_fit (doc_width, doc_height, ev_view_get_width (view),
- ev_view_get_height (view), 0, 0);
+ page = ev_link_dest_get_page (dest);
+ ev_document_get_page_size (view->document, page, &doc_width, &doc_height);
- ev_view_set_sizing_mode (view, EV_SIZING_BEST_FIT);
- ev_view_set_zoom (view, zoom, FALSE);
+ zoom = zoom_for_size_best_fit (doc_width, doc_height,
+ allocation.width,
+ allocation.height);
- view->current_page = page;
- view->pending_scroll = SCROLL_TO_PAGE_POSITION;
+ ev_document_model_set_sizing_mode (view->model, EV_SIZING_BEST_FIT);
+ ev_document_model_set_scale (view->model, zoom);
- gtk_widget_queue_resize (GTK_WIDGET (view));
+ ev_view_change_page (view, page);
}
static void
page = ev_link_dest_get_page (dest);
if (change_zoom && zoom > 1) {
- ev_view_set_sizing_mode (view, EV_SIZING_FREE);
- ev_view_set_zoom (view, zoom, FALSE);
+ ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE);
+ ev_document_model_set_scale (view->model, zoom);
}
left = ev_link_dest_get_left (dest, &change_left);
doc_point.x = change_left ? left : 0;
doc_point.y = change_top ? top : 0;
+ view->pending_point = doc_point;
- view->current_page = page;
- if (change_left || change_top)
- view->pending_point = doc_point;
- view->pending_scroll = SCROLL_TO_PAGE_POSITION;
-
- gtk_widget_queue_resize (GTK_WIDGET (view));
+ ev_view_change_page (view, page);
}
static void
int page, n_pages, current_page;
page = ev_link_dest_get_page (dest);
- n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ n_pages = ev_document_get_n_pages (view->document);
if (page < 0 || page >= n_pages)
return;
switch (type) {
case EV_LINK_DEST_TYPE_PAGE:
- ev_page_cache_set_current_page (view->page_cache, page);
+ ev_document_model_set_page (view->model, page);
break;
case EV_LINK_DEST_TYPE_FIT:
goto_fit_dest (view, dest);
goto_xyz_dest (view, dest);
break;
case EV_LINK_DEST_TYPE_PAGE_LABEL:
- ev_page_cache_set_page_label (view->page_cache, ev_link_dest_get_page_label (dest));
+ ev_document_model_set_page_by_label (view->model, ev_link_dest_get_page_label (dest));
break;
default:
g_assert_not_reached ();
}
if (current_page != view->current_page)
- ev_page_cache_set_current_page (view->page_cache,
- view->current_page);
+ ev_document_model_set_page (view->model, view->current_page);
}
static void
ev_view_goto_dest (view, dest);
}
break;
+ case EV_LINK_ACTION_TYPE_LAYERS_STATE: {
+ GList *show, *hide, *toggle;
+ GList *l;
+ EvDocumentLayers *document_layers;
+
+ document_layers = EV_DOCUMENT_LAYERS (view->document);
+
+ show = ev_link_action_get_show_list (action);
+ for (l = show; l; l = g_list_next (l)) {
+ ev_document_layers_show_layer (document_layers, EV_LAYER (l->data));
+ }
+
+ hide = ev_link_action_get_hide_list (action);
+ for (l = hide; l; l = g_list_next (l)) {
+ ev_document_layers_hide_layer (document_layers, EV_LAYER (l->data));
+ }
+
+ toggle = ev_link_action_get_toggle_list (action);
+ for (l = toggle; l; l = g_list_next (l)) {
+ EvLayer *layer = EV_LAYER (l->data);
+
+ if (ev_document_layers_layer_is_visible (document_layers, layer)) {
+ ev_document_layers_hide_layer (document_layers, layer);
+ } else {
+ ev_document_layers_show_layer (document_layers, layer);
+ }
+ }
+
+ g_signal_emit (view, signals[SIGNAL_LAYERS_CHANGED], 0);
+ ev_view_reload_page (view, view->current_page, NULL);
+ }
+ break;
case EV_LINK_ACTION_TYPE_GOTO_REMOTE:
case EV_LINK_ACTION_TYPE_EXTERNAL_URI:
case EV_LINK_ACTION_TYPE_LAUNCH:
}
}
-gchar *
-ev_view_page_label_from_dest (EvView *view, EvLinkDest *dest)
-{
- EvLinkDestType type;
- gchar *msg = NULL;
-
- type = ev_link_dest_get_dest_type (dest);
-
- switch (type) {
- case EV_LINK_DEST_TYPE_NAMED: {
- EvLinkDest *dest2;
- const gchar *named_dest;
-
- named_dest = ev_link_dest_get_named_dest (dest);
- dest2 = ev_document_links_find_link_dest (EV_DOCUMENT_LINKS (view->document),
- named_dest);
- if (dest2) {
- msg = ev_page_cache_get_page_label (view->page_cache,
- ev_link_dest_get_page (dest2));
- g_object_unref (dest2);
- }
- }
-
- break;
- case EV_LINK_DEST_TYPE_PAGE_LABEL: {
- msg = g_strdup (ev_link_dest_get_page_label (dest));
- }
- break;
- default:
- msg = ev_page_cache_get_page_label (view->page_cache,
- ev_link_dest_get_page (dest));
- }
-
- return msg;
-}
-
-static char *
-tip_from_action_named (EvLinkAction *action)
+static char *
+tip_from_action_named (EvLinkAction *action)
{
const gchar *name = ev_link_action_get_name (action);
switch (type) {
case EV_LINK_ACTION_TYPE_GOTO_DEST:
- page_label = ev_view_page_label_from_dest (view,
- ev_link_action_get_dest (action));
+ page_label = ev_document_links_get_dest_page_label (EV_DOCUMENT_LINKS (view->document),
+ ev_link_action_get_dest (action));
if (page_label) {
msg = g_strdup_printf (_("Go to page %s"), page_label);
g_free (page_label);
if (view->cursor == EV_VIEW_CURSOR_HIDDEN)
return;
+ if (view->adding_annot) {
+ if (view->cursor != EV_VIEW_CURSOR_ADD)
+ ev_view_set_cursor (view, EV_VIEW_CURSOR_ADD);
+ return;
+ }
+
if (view->drag_info.in_drag) {
if (view->cursor != EV_VIEW_CURSOR_DRAG)
ev_view_set_cursor (view, EV_VIEW_CURSOR_DRAG);
if (view->cursor == EV_VIEW_CURSOR_LINK ||
view->cursor == EV_VIEW_CURSOR_IBEAM ||
view->cursor == EV_VIEW_CURSOR_DRAG ||
- view->cursor == EV_VIEW_CURSOR_AUTOSCROLL)
+ view->cursor == EV_VIEW_CURSOR_AUTOSCROLL ||
+ view->cursor == EV_VIEW_CURSOR_ADD)
ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
}
gdouble y)
{
gint page = -1;
- gint x_offset = 0, y_offset = 0;
gint x_new = 0, y_new = 0;
- GList *image_mapping;
+ EvMappingList *image_mapping;
if (!EV_IS_DOCUMENT_IMAGES (view->document))
return NULL;
- x += view->scroll_x;
- y += view->scroll_y;
-
- find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
-
- if (page == -1)
- return NULL;
-
- if (get_doc_point_from_offset (view, page, x_offset,
- y_offset, &x_new, &y_new) == FALSE)
+ if (!get_doc_point_from_location (view, x, y, &page, &x_new, &y_new))
return NULL;
- image_mapping = ev_pixbuf_cache_get_image_mapping (view->pixbuf_cache, page);
+ image_mapping = ev_page_cache_get_image_mapping (view->page_cache, page);
if (image_mapping)
- return ev_image_mapping_find (image_mapping, x_new, y_new);
+ return ev_mapping_list_get_data (image_mapping, x_new, y_new);
else
return NULL;
}
gdouble y)
{
gint page = -1;
- gint x_offset = 0, y_offset = 0;
gint x_new = 0, y_new = 0;
- GList *forms_mapping;
+ EvMappingList *forms_mapping;
if (!EV_IS_DOCUMENT_FORMS (view->document))
return NULL;
- x += view->scroll_x;
- y += view->scroll_y;
-
- find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
-
- if (page == -1)
- return NULL;
-
- if (get_doc_point_from_offset (view, page, x_offset,
- y_offset, &x_new, &y_new) == FALSE)
+ if (!get_doc_point_from_location (view, x, y, &page, &x_new, &y_new))
return NULL;
- forms_mapping = ev_pixbuf_cache_get_form_field_mapping (view->pixbuf_cache, page);
+ forms_mapping = ev_page_cache_get_form_field_mapping (view->page_cache, page);
if (forms_mapping)
- return ev_form_field_mapping_find (forms_mapping, x_new, y_new);
+ return ev_mapping_list_get_data (forms_mapping, x_new, y_new);
else
return NULL;
}
-static GdkRegion *
+static cairo_region_t *
ev_view_form_field_get_region (EvView *view,
EvFormField *field)
{
- EvRectangle field_area;
- GdkRectangle view_area;
- GList *forms_mapping;
+ GdkRectangle view_area;
+ EvMappingList *forms_mapping;
- forms_mapping = ev_pixbuf_cache_get_form_field_mapping (view->pixbuf_cache,
- field->page->index);
- ev_form_field_mapping_get_area (forms_mapping, field, &field_area);
- doc_rect_to_view_rect (view, field->page->index, &field_area, &view_area);
- view_area.x -= view->scroll_x;
- view_area.y -= view->scroll_y;
+ forms_mapping = ev_page_cache_get_form_field_mapping (view->page_cache,
+ field->page->index);
+ ev_view_get_area_from_mapping (view, field->page->index,
+ forms_mapping,
+ field, &view_area);
- return gdk_region_rectangle (&view_area);
+ return cairo_region_create_rectangle (&view_area);
}
static gboolean
EvFormField *field)
{
EvFormFieldButton *field_button = EV_FORM_FIELD_BUTTON (field);
- GdkRegion *field_region = NULL;
+ cairo_region_t *field_region = NULL;
switch (field_button->type) {
case EV_FORM_FIELD_BUTTON_PUSH:
return NULL;
case EV_FORM_FIELD_BUTTON_CHECK:
case EV_FORM_FIELD_BUTTON_RADIO: {
- gboolean state;
- GList *forms_mapping, *l;
+ gboolean state;
+ EvMappingList *forms_mapping;
+ GList *l;
state = ev_document_forms_form_field_button_get_state (EV_DOCUMENT_FORMS (view->document),
field);
/* For radio buttons and checkbox buttons that are in a set
* we need to update also the region for the current selected item
*/
- forms_mapping = ev_pixbuf_cache_get_form_field_mapping (view->pixbuf_cache,
- field->page->index);
- for (l = forms_mapping; l; l = g_list_next (l)) {
- EvFormField *button = ((EvFormFieldMapping *)(l->data))->field;
- GdkRegion *button_region;
+ forms_mapping = ev_page_cache_get_form_field_mapping (view->page_cache,
+ field->page->index);
+ for (l = ev_mapping_list_get_list (forms_mapping); l; l = g_list_next (l)) {
+ EvFormField *button = ((EvMapping *)(l->data))->data;
+ cairo_region_t *button_region;
if (button->id == field->id)
continue;
continue;
button_region = ev_view_form_field_get_region (view, button);
- gdk_region_union (field_region, button_region);
- gdk_region_destroy (button_region);
+ cairo_region_union (field_region, button_region);
+ cairo_region_destroy (button_region);
}
ev_document_forms_form_field_button_set_state (EV_DOCUMENT_FORMS (view->document),
}
ev_view_reload_page (view, field->page->index, field_region);
- gdk_region_destroy (field_region);
+ cairo_region_destroy (field_region);
return NULL;
}
if (field->changed) {
EvFormFieldText *field_text = EV_FORM_FIELD_TEXT (field);
- GdkRegion *field_region;
+ cairo_region_t *field_region;
field_region = ev_view_form_field_get_region (view, field);
field, field_text->text);
field->changed = FALSE;
ev_view_reload_page (view, field->page->index, field_region);
- gdk_region_destroy (field_region);
+ cairo_region_destroy (field_region);
}
}
if (field->changed) {
GList *l;
EvFormFieldChoice *field_choice = EV_FORM_FIELD_CHOICE (field);
- GdkRegion *field_region;
+ cairo_region_t *field_region;
field_region = ev_view_form_field_get_region (view, field);
}
field->changed = FALSE;
ev_view_reload_page (view, field->page->index, field_region);
- gdk_region_destroy (field_region);
+ cairo_region_destroy (field_region);
}
}
g_signal_connect (choice, "changed",
G_CALLBACK (ev_view_form_field_choice_changed),
field);
- g_signal_connect_after (GTK_BIN(choice)->child, "activate",
+ g_signal_connect_after (gtk_bin_get_child (GTK_BIN (choice)),
+ "activate",
G_CALLBACK (ev_view_form_field_destroy),
view);
} else { /* ComboBoxText */
gdouble x,
gdouble y)
{
- GtkWidget *field_widget = NULL;
- GList *form_field_mapping;
- EvRectangle field_area;
- GdkRectangle view_area;
+ GtkWidget *field_widget = NULL;
+ EvMappingList *form_field_mapping;
+ GdkRectangle view_area;
if (field->is_read_only)
return;
g_object_ref (field),
(GDestroyNotify)g_object_unref);
- form_field_mapping = ev_pixbuf_cache_get_form_field_mapping (view->pixbuf_cache, field->page->index);
- ev_form_field_mapping_get_area (form_field_mapping, field, &field_area);
-
- doc_rect_to_view_rect (view, field->page->index, &field_area, &view_area);
- view_area.x -= view->scroll_x;
- view_area.y -= view->scroll_y;
+ form_field_mapping = ev_page_cache_get_form_field_mapping (view->page_cache,
+ field->page->index);
+ ev_view_get_area_from_mapping (view, field->page->index,
+ form_field_mapping,
+ field, &view_area);
gtk_layout_put (GTK_LAYOUT (view), field_widget, view_area.x, view_area.y);
gtk_widget_show (field_widget);
gint x,
gint y)
{
+ GtkAllocation allocation;
+ gint width, height;
+
+ gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
+ gtk_window_get_size (GTK_WINDOW (child->window), &width, &height);
+
child->x = x;
child->y = y;
gtk_window_move (GTK_WINDOW (child->window),
- MAX (child->parent_x, x),
- MAX (child->parent_y, y));
+ CLAMP (x, child->parent_x,
+ child->parent_x + allocation.width - width),
+ CLAMP (y, child->parent_y,
+ child->parent_y + allocation.height - height));
}
static void
ev_view_window_child_move (view, child, dest_x, dest_y);
}
- if (child->visible && !GTK_WIDGET_VISIBLE (window))
+ if (child->visible && !gtk_widget_get_visible (window))
gtk_widget_show (window);
}
continue;
wannot = ev_annotation_window_get_annotation (EV_ANNOTATION_WINDOW (child->window));
- if (wannot == annot || strcmp (wannot->name, annot->name) == 0)
+ if (ev_annotation_equal (wannot, annot))
return child;
}
view_rect.width = width;
view_rect.height = height;
- get_page_extents (view, child->page, &page_area, &border);
+ ev_view_get_page_extents (view, child->page, &page_area, &border);
view_rect_to_doc_rect (view, &view_rect, &page_area, &doc_rect);
child->orig_x = doc_rect.x1;
child->orig_y = doc_rect.y1;
}
static void
-ev_view_annotation_save (EvView *view,
- EvAnnotation *annot)
+ev_view_annotation_save_contents (EvView *view,
+ GParamSpec *pspec,
+ EvAnnotation *annot)
{
if (!view->document)
return;
- if (!annot->changed)
- return;
+ ev_document_doc_mutex_lock ();
+ ev_document_annotations_save_annotation (EV_DOCUMENT_ANNOTATIONS (view->document),
+ annot, EV_ANNOTATIONS_SAVE_CONTENTS);
+ ev_document_doc_mutex_unlock ();
+}
+
+static GtkWidget *
+ev_view_create_annotation_window (EvView *view,
+ EvAnnotation *annot,
+ GtkWindow *parent)
+{
+ GtkWidget *window;
+ EvRectangle doc_rect;
+ GdkRectangle view_rect;
+ guint page;
+
+ window = ev_annotation_window_new (annot, parent);
+ g_signal_connect (window, "grab_focus",
+ G_CALLBACK (annotation_window_grab_focus),
+ view);
+ g_signal_connect (window, "closed",
+ G_CALLBACK (annotation_window_closed),
+ view);
+ g_signal_connect (window, "moved",
+ G_CALLBACK (annotation_window_moved),
+ view);
+ g_signal_connect_swapped (annot, "notify::contents",
+ G_CALLBACK (ev_view_annotation_save_contents),
+ view);
+ g_object_set_data (G_OBJECT (annot), "popup", window);
+
+ page = ev_annotation_get_page_index (annot);
+ ev_annotation_window_get_rectangle (EV_ANNOTATION_WINDOW (window), &doc_rect);
+ doc_rect_to_view_rect (view, page, &doc_rect, &view_rect);
+ view_rect.x -= view->scroll_x;
+ view_rect.y -= view->scroll_y;
- ev_document_annotations_annotation_set_contents (EV_DOCUMENT_ANNOTATIONS (view->document),
- annot, annot->contents);
- annot->changed = FALSE;
+ ev_view_window_child_put (view, window, page,
+ view_rect.x, view_rect.y,
+ doc_rect.x1, doc_rect.y1);
+
+ return window;
}
static void
show_annotation_windows (EvView *view,
gint page)
{
- GList *annots, *l;
- GtkWindow *parent;
+ EvMappingList *annots;
+ GList *l;
+ GtkWindow *parent;
parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
- annots = ev_pixbuf_cache_get_annots_mapping (view->pixbuf_cache, page);
+ annots = ev_page_cache_get_annot_mapping (view->page_cache, page);
- for (l = annots; l && l->data; l = g_list_next (l)) {
- EvAnnotationMapping *annotation_mapping;
- EvAnnotation *annot;
- EvViewWindowChild *child;
- GtkWidget *window;
- EvRectangle *doc_rect;
- GdkRectangle view_rect;
+ for (l = ev_mapping_list_get_list (annots); l && l->data; l = g_list_next (l)) {
+ EvAnnotation *annot;
+ EvViewWindowChild *child;
+ GtkWidget *window;
- annotation_mapping = (EvAnnotationMapping *)l->data;
- annot = annotation_mapping->annotation;
+ annot = ((EvMapping *)(l->data))->data;
if (!EV_IS_ANNOTATION_MARKUP (annot))
continue;
+ if (!ev_annotation_markup_has_popup (EV_ANNOTATION_MARKUP (annot)))
+ continue;
+
window = g_object_get_data (G_OBJECT (annot), "popup");
if (window) {
ev_view_window_child_move_with_parent (view, window);
g_object_set_data (G_OBJECT (annot), "popup", window);
ev_view_window_child_move_with_parent (view, window);
} else {
- window = ev_annotation_window_new (annot, parent);
- g_signal_connect (window, "grab_focus",
- G_CALLBACK (annotation_window_grab_focus),
- view);
- g_signal_connect (window, "closed",
- G_CALLBACK (annotation_window_closed),
- view);
- g_signal_connect (window, "moved",
- G_CALLBACK (annotation_window_moved),
- view);
- g_object_set_data (G_OBJECT (annot), "popup", window);
-
- doc_rect = (EvRectangle *)ev_annotation_window_get_rectangle (EV_ANNOTATION_WINDOW (window));
- doc_rect_to_view_rect (view, page, doc_rect, &view_rect);
- view_rect.x -= view->scroll_x;
- view_rect.y -= view->scroll_y;
-
- ev_view_window_child_put (view, window, page,
- view_rect.x, view_rect.y,
- doc_rect->x1, doc_rect->y1);
-
- g_object_weak_ref (G_OBJECT (annot),
- (GWeakNotify)ev_view_annotation_save,
- view);
+ ev_view_create_annotation_window (view, annot, parent);
}
}
}
hide_annotation_windows (EvView *view,
gint page)
{
- GList *annots, *l;
+ EvMappingList *annots;
+ GList *l;
- annots = ev_pixbuf_cache_get_annots_mapping (view->pixbuf_cache, page);
+ annots = ev_page_cache_get_annot_mapping (view->page_cache, page);
- for (l = annots; l && l->data; l = g_list_next (l)) {
- EvAnnotationMapping *annotation_mapping;
- EvAnnotation *annot;
- GtkWidget *window;
+ for (l = ev_mapping_list_get_list (annots); l && l->data; l = g_list_next (l)) {
+ EvAnnotation *annot;
+ GtkWidget *window;
- annotation_mapping = (EvAnnotationMapping *)l->data;
- annot = annotation_mapping->annotation;
+ annot = ((EvMapping *)(l->data))->data;
if (!EV_IS_ANNOTATION_MARKUP (annot))
continue;
gdouble y)
{
gint page = -1;
- gint x_offset = 0, y_offset = 0;
gint x_new = 0, y_new = 0;
- GList *annotations_mapping;
+ EvMappingList *annotations_mapping;
if (!EV_IS_DOCUMENT_ANNOTATIONS (view->document))
return NULL;
- x += view->scroll_x;
- y += view->scroll_y;
-
- find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
-
- if (page == -1)
- return NULL;
-
- if (get_doc_point_from_offset (view, page, x_offset,
- y_offset, &x_new, &y_new) == FALSE)
+ if (!get_doc_point_from_location (view, x, y, &page, &x_new, &y_new))
return NULL;
- annotations_mapping = ev_pixbuf_cache_get_annots_mapping (view->pixbuf_cache, page);
+ annotations_mapping = ev_page_cache_get_annot_mapping (view->page_cache, page);
if (annotations_mapping)
- return ev_annotation_mapping_find (annotations_mapping, x_new, y_new);
+ return ev_mapping_list_get_data (annotations_mapping, x_new, y_new);
else
return NULL;
}
+static void
+ev_view_annotation_show_popup_window (EvView *view,
+ GtkWidget *window)
+{
+ EvViewWindowChild *child;
+
+ if (!window)
+ return;
+
+ child = ev_view_get_window_child (view, window);
+ if (!child->visible) {
+ child->visible = TRUE;
+ ev_view_window_child_move (view, child, child->x, child->y);
+ gtk_widget_show (window);
+ }
+}
+
static void
ev_view_handle_annotation (EvView *view,
EvAnnotation *annot,
gdouble x,
- gdouble y)
+ gdouble y,
+ guint32 timestamp)
{
if (EV_IS_ANNOTATION_MARKUP (annot)) {
GtkWidget *window;
window = g_object_get_data (G_OBJECT (annot), "popup");
- if (window) {
- EvViewWindowChild *child;
+ ev_view_annotation_show_popup_window (view, window);
+ }
+
+ if (EV_IS_ANNOTATION_ATTACHMENT (annot)) {
+ EvAttachment *attachment;
+
+ attachment = ev_annotation_attachment_get_attachment (EV_ANNOTATION_ATTACHMENT (annot));
+ if (attachment) {
+ GError *error = NULL;
- child = ev_view_get_window_child (view, window);
- if (!child->visible) {
- child->visible = TRUE;
- ev_view_window_child_move (view, child, child->x, child->y);
- gtk_widget_show (window);
+ ev_attachment_open (attachment,
+ gtk_widget_get_screen (GTK_WIDGET (view)),
+ timestamp,
+ &error);
+
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
}
}
}
}
+static void
+ev_view_create_annotation (EvView *view,
+ EvAnnotationType annot_type,
+ gint x,
+ gint y)
+{
+ EvAnnotation *annot;
+ GdkPoint point;
+ GdkRectangle page_area;
+ GtkBorder border;
+ EvRectangle doc_rect, popup_rect;
+ EvPage *page;
+ GdkColor color = { 0, 65535, 65535, 0 };
+ GdkRectangle view_rect;
+ cairo_region_t *region;
+
+ point.x = x;
+ point.y = y;
+ ev_view_get_page_extents (view, view->current_page, &page_area, &border);
+ view_point_to_doc_point (view, &point, &page_area,
+ &doc_rect.x1, &doc_rect.y1);
+ doc_rect.x2 = doc_rect.x1 + 24;
+ doc_rect.y2 = doc_rect.y1 + 24;
+
+ ev_document_doc_mutex_lock ();
+ page = ev_document_get_page (view->document, view->current_page);
+ switch (annot_type) {
+ case EV_ANNOTATION_TYPE_TEXT:
+ annot = ev_annotation_text_new (page);
+ break;
+ case EV_ANNOTATION_TYPE_ATTACHMENT:
+ /* TODO */
+ g_object_unref (page);
+ ev_document_doc_mutex_unlock ();
+ return;
+ default:
+ g_assert_not_reached ();
+ }
+ g_object_unref (page);
+
+ ev_annotation_set_color (annot, &color);
+
+ if (EV_IS_ANNOTATION_MARKUP (annot)) {
+ popup_rect.x1 = doc_rect.x2;
+ popup_rect.x2 = popup_rect.x1 + 200;
+ popup_rect.y1 = doc_rect.y2;
+ popup_rect.y2 = popup_rect.y1 + 150;
+ g_object_set (annot,
+ "rectangle", &popup_rect,
+ "has_popup", TRUE,
+ "popup_is_open", FALSE,
+ "label", g_get_real_name (),
+ "opacity", 1.0,
+ NULL);
+ }
+ ev_document_annotations_add_annotation (EV_DOCUMENT_ANNOTATIONS (view->document),
+ annot, &doc_rect);
+ ev_document_doc_mutex_unlock ();
+
+ /* If the page didn't have annots, mark the cache as dirty */
+ if (!ev_page_cache_get_annot_mapping (view->page_cache, view->current_page))
+ ev_page_cache_mark_dirty (view->page_cache, view->current_page);
+
+ if (EV_IS_ANNOTATION_MARKUP (annot)) {
+ GtkWindow *parent;
+ GtkWidget *window;
+
+ parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
+ window = ev_view_create_annotation_window (view, annot, parent);
+
+ /* Show the annot window the first time */
+ ev_view_annotation_show_popup_window (view, window);
+ }
+
+ doc_rect_to_view_rect (view, view->current_page, &doc_rect, &view_rect);
+ view_rect.x -= view->scroll_x;
+ view_rect.y -= view->scroll_y;
+ region = cairo_region_create_rectangle (&view_rect);
+ ev_view_reload_page (view, view->current_page, region);
+ cairo_region_destroy (region);
+
+ g_signal_emit (view, signals[SIGNAL_ANNOT_ADDED], 0, annot);
+}
+
+void
+ev_view_focus_annotation (EvView *view,
+ EvMapping *annot_mapping)
+{
+ GdkRectangle view_rect;
+ EvAnnotation *annot;
+ guint page;
+
+ if (!EV_IS_DOCUMENT_ANNOTATIONS (view->document))
+ return;
+
+ if (view->focus_annotation == annot_mapping)
+ return;
+
+ view->focus_annotation = annot_mapping;
+ annot = (EvAnnotation *)annot_mapping->data;
+
+ page = ev_annotation_get_page_index (annot);
+ ev_document_model_set_page (view->model, page);
+
+ doc_rect_to_view_rect (view, page,
+ &annot_mapping->area, &view_rect);
+ ensure_rectangle_is_visible (view, &view_rect);
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+}
+
+void
+ev_view_begin_add_annotation (EvView *view,
+ EvAnnotationType annot_type)
+{
+ if (annot_type == EV_ANNOTATION_TYPE_UNKNOWN)
+ return;
+
+ if (view->adding_annot)
+ return;
+
+ view->adding_annot = TRUE;
+ view->adding_annot_type = annot_type;
+ ev_view_set_cursor (view, EV_VIEW_CURSOR_ADD);
+}
+
+void
+ev_view_cancel_add_annotation (EvView *view)
+{
+ gint x, y;
+
+ if (!view->adding_annot)
+ return;
+
+ view->adding_annot = FALSE;
+ gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
+ ev_view_handle_cursor_over_xy (view, x, y);
+}
+
+static gboolean
+ev_view_synctex_backward_search (EvView *view,
+ gdouble x,
+ gdouble y)
+{
+ gint page = -1;
+ gint x_new = 0, y_new = 0;
+ EvSourceLink *link;
+
+ if (!ev_document_has_synctex (view->document))
+ return FALSE;
+
+ if (!get_doc_point_from_location (view, x, y, &page, &x_new, &y_new))
+ return FALSE;
+
+ link = ev_document_synctex_backward_search (view->document, page, x_new, y_new);
+ if (link) {
+ g_signal_emit (view, signals[SIGNAL_SYNC_SOURCE], 0, link);
+ g_free (link);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
/*** GtkWidget implementation ***/
static void
ev_view_size_request_continuous_dual_page (EvView *view,
GtkRequisition *requisition)
{
- int max_width;
gint n_pages;
- GtkBorder border;
- ev_page_cache_get_max_width (view->page_cache, view->rotation,
- view->scale, &max_width);
- compute_border (view, max_width, max_width, &border);
+ n_pages = ev_document_get_n_pages (view->document) + 1;
+ get_page_y_offset (view, n_pages, &requisition->height);
- n_pages = ev_page_cache_get_n_pages (view->page_cache) + 1;
+ switch (view->sizing_mode) {
+ case EV_SIZING_FIT_WIDTH:
+ case EV_SIZING_BEST_FIT:
+ requisition->width = 1;
- requisition->width = (max_width + border.left + border.right) * 2 + (view->spacing * 3);
- get_page_y_offset (view, n_pages, view->scale, &requisition->height);
+ break;
+ case EV_SIZING_FREE: {
+ gint max_width;
+ GtkBorder border;
- if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
- requisition->width = 1;
- } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
- requisition->width = 1;
- /* FIXME: This could actually be set on one page docs or docs
- * with a strange aspect ratio. */
- /* requisition->height = 1;*/
+ ev_view_get_max_page_size (view, &max_width, NULL);
+ compute_border (view, max_width, max_width, &border);
+ requisition->width = (max_width + border.left + border.right) * 2 + (view->spacing * 3);
+ }
+ break;
+ default:
+ g_assert_not_reached ();
}
}
ev_view_size_request_continuous (EvView *view,
GtkRequisition *requisition)
{
- int max_width;
- int n_pages;
- GtkBorder border;
+ gint n_pages;
+ n_pages = ev_document_get_n_pages (view->document);
+ get_page_y_offset (view, n_pages, &requisition->height);
- ev_page_cache_get_max_width (view->page_cache, view->rotation,
- view->scale, &max_width);
- n_pages = ev_page_cache_get_n_pages (view->page_cache);
- compute_border (view, max_width, max_width, &border);
+ switch (view->sizing_mode) {
+ case EV_SIZING_FIT_WIDTH:
+ case EV_SIZING_BEST_FIT:
+ requisition->width = 1;
- requisition->width = max_width + (view->spacing * 2) + border.left + border.right;
- get_page_y_offset (view, n_pages, view->scale, &requisition->height);
+ break;
+ case EV_SIZING_FREE: {
+ gint max_width;
+ GtkBorder border;
- if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
- requisition->width = 1;
- } else if (view->sizing_mode == EV_SIZING_BEST_FIT) {
- requisition->width = 1;
- /* FIXME: This could actually be set on one page docs or docs
- * with a strange aspect ratio. */
- /* requisition->height = 1;*/
+ ev_view_get_max_page_size (view, &max_width, NULL);
+ compute_border (view, max_width, max_width, &border);
+ requisition->width = max_width + (view->spacing * 2) + border.left + border.right;
+ }
+ break;
+ default:
+ g_assert_not_reached ();
}
}
GtkBorder border;
gint width, height;
+ if (view->sizing_mode == EV_SIZING_BEST_FIT) {
+ requisition->width = 1;
+ requisition->height = 1;
+
+ return;
+ }
+
/* Find the largest of the two. */
- ev_page_cache_get_size (view->page_cache,
- view->current_page,
- view->rotation,
- view->scale,
- &width, &height);
- if (view->current_page + 1 < ev_page_cache_get_n_pages (view->page_cache)) {
+ ev_view_get_page_size (view,
+ view->current_page,
+ &width, &height);
+ if (view->current_page + 1 < ev_document_get_n_pages (view->document)) {
gint width_2, height_2;
- ev_page_cache_get_size (view->page_cache,
- view->current_page + 1,
- view->rotation,
- view->scale,
- &width_2, &height_2);
+ ev_view_get_page_size (view,
+ view->current_page + 1,
+ &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;
- }
+ requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 :
+ ((width + border.left + border.right) * 2) + (view->spacing * 3);
+ requisition->height = (height + border.top + border.bottom) + (view->spacing * 2);
}
static void
GtkBorder border;
gint width, height;
- ev_page_cache_get_size (view->page_cache,
- view->current_page,
- view->rotation,
- 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) {
+ if (view->sizing_mode == EV_SIZING_BEST_FIT) {
requisition->width = 1;
requisition->height = 1;
+
+ return;
}
+
+ ev_view_get_page_size (view, view->current_page, &width, &height);
+ compute_border (view, width, height, &border);
+
+ requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 :
+ width + border.left + border.right + (2 * view->spacing);
+ requisition->height = height + border.top + border.bottom + (2 * view->spacing);
}
static void
GtkRequisition *requisition)
{
EvView *view = EV_VIEW (widget);
-
+
if (view->document == NULL) {
- requisition->width = 1;
- requisition->height = 1;
+ view->requisition.width = 1;
+ view->requisition.height = 1;
+
+ *requisition = view->requisition;
+
return;
}
- if (view->presentation) {
- requisition->width = 1;
- requisition->height = 1;
- return;
+ /* Get zoom for size here when not called from
+ * ev_view_size_allocate()
+ */
+ if (!view->internal_size_request &&
+ (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
+ view->sizing_mode == EV_SIZING_BEST_FIT)) {
+ GtkAllocation allocation;
+
+ gtk_widget_get_allocation (widget, &allocation);
+ ev_view_zoom_for_size (view,
+ allocation.width,
+ allocation.height);
}
if (view->continuous && view->dual_page)
- ev_view_size_request_continuous_dual_page (view, requisition);
+ ev_view_size_request_continuous_dual_page (view, &view->requisition);
else if (view->continuous)
- ev_view_size_request_continuous (view, requisition);
+ ev_view_size_request_continuous (view, &view->requisition);
else if (view->dual_page)
- ev_view_size_request_dual_page (view, requisition);
+ ev_view_size_request_dual_page (view, &view->requisition);
else
- ev_view_size_request_single_page (view, requisition);
+ ev_view_size_request_single_page (view, &view->requisition);
+
+ *requisition = view->requisition;
}
static void
gint root_x, root_y;
GTK_WIDGET_CLASS (ev_view_parent_class)->size_allocate (widget, allocation);
-
+
+ if (!view->document)
+ return;
+
if (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
view->sizing_mode == EV_SIZING_BEST_FIT) {
- g_signal_emit (view, signals[SIGNAL_ZOOM_INVALID], 0);
- ev_view_size_request (widget, &widget->requisition);
+ GtkRequisition req;
+
+ ev_view_zoom_for_size (view,
+ allocation->width,
+ allocation->height);
+ view->internal_size_request = TRUE;
+ ev_view_size_request (widget, &req);
+ view->internal_size_request = FALSE;
}
view_set_adjustment_values (view, GTK_ORIENTATION_HORIZONTAL);
view->pending_scroll = SCROLL_TO_KEEP_POSITION;
view->pending_resize = FALSE;
+ view->pending_point.x = 0;
+ view->pending_point.y = 0;
children = gtk_container_get_children (GTK_CONTAINER (widget));
for (l = children; l && l->data; l = g_list_next (l)) {
EvFormField *field;
- EvRectangle field_area;
GdkRectangle view_area;
- GList *form_field_mapping;
+ EvMappingList *form_field_mapping;
GtkAllocation child_allocation;
GtkRequisition child_requisition;
GtkWidget *child = (GtkWidget *)l->data;
if (!field)
continue;
- form_field_mapping = ev_pixbuf_cache_get_form_field_mapping (view->pixbuf_cache,
- field->page->index);
- ev_form_field_mapping_get_area (form_field_mapping, field, &field_area);
-
- doc_rect_to_view_rect (view, field->page->index, &field_area, &view_area);
- view_area.x -= view->scroll_x;
- view_area.y -= view->scroll_y;
+ form_field_mapping = ev_page_cache_get_form_field_mapping (view->page_cache,
+ field->page->index);
+ ev_view_get_area_from_mapping (view, field->page->index,
+ form_field_mapping,
+ field, &view_area);
gtk_widget_size_request (child, &child_requisition);
if (child_requisition.width != view_area.width ||
child = (EvViewWindowChild *)l->data;
- doc_rect = *ev_annotation_window_get_rectangle (EV_ANNOTATION_WINDOW (child->window));
+ ev_annotation_window_get_rectangle (EV_ANNOTATION_WINDOW (child->window), &doc_rect);
if (child->moved) {
doc_rect.x1 = child->orig_x;
doc_rect.y1 = child->orig_y;
static void
ev_view_realize (GtkWidget *widget)
{
- EvView *view = EV_VIEW (widget);
+ EvView *view = EV_VIEW (widget);
+ GdkWindow *bin_window;
+ GtkStyle *style;
if (GTK_WIDGET_CLASS (ev_view_parent_class)->realize)
(* GTK_WIDGET_CLASS (ev_view_parent_class)->realize) (widget);
- gdk_window_set_events (view->layout.bin_window,
- (gdk_window_get_events (view->layout.bin_window) |
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+ gdk_window_set_events (bin_window,
+ (gdk_window_get_events (bin_window) |
GDK_EXPOSURE_MASK |
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK));
- if (view->presentation)
- gdk_window_set_background (view->layout.bin_window, &widget->style->black);
- else
- gdk_window_set_background (view->layout.bin_window, &widget->style->mid [GTK_STATE_NORMAL]);
+ style = gtk_widget_get_style (widget);
+ gdk_window_set_background (bin_window, &style->mid[GTK_STATE_NORMAL]);
+
+ on_adjustment_value_changed (NULL, view);
}
static gboolean
state = event->state & gtk_accelerator_get_default_mod_mask ();
- if (state == GDK_CONTROL_MASK && view->presentation == FALSE) {
- ev_view_set_sizing_mode (view, EV_SIZING_FREE);
-
+ if (state == GDK_CONTROL_MASK) {
+ ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE);
if (event->direction == GDK_SCROLL_UP ||
event->direction == GDK_SCROLL_LEFT) {
if (ev_view_can_zoom_in (view)) {
state &= ~GDK_SHIFT_MASK;
}
- if (state == 0 && view->presentation) {
+ if (state == 0 && view->sizing_mode == EV_SIZING_BEST_FIT && !view->continuous) {
switch (event->direction) {
case GDK_SCROLL_DOWN:
case GDK_SCROLL_RIGHT:
return NULL;
}
-static void
-draw_end_presentation_page (EvView *view,
- GdkRectangle *page_area)
-{
- PangoLayout *layout;
- PangoFontDescription *font_desc;
- gchar *markup;
- const gchar *text = _("End of presentation. Press Escape to exit.");
-
- if (view->presentation_state != EV_PRESENTATION_END)
- return;
-
- layout = gtk_widget_create_pango_layout (GTK_WIDGET (view), NULL);
- markup = g_strdup_printf ("<span foreground=\"white\">%s</span>", text);
- pango_layout_set_markup (layout, markup, -1);
- g_free (markup);
-
- font_desc = pango_font_description_new ();
- pango_font_description_set_size (font_desc, 16 * PANGO_SCALE);
- pango_layout_set_font_description (layout, font_desc);
-
- gtk_paint_layout (GTK_WIDGET (view)->style,
- view->layout.bin_window,
- GTK_WIDGET_STATE (view),
- FALSE,
- page_area,
- GTK_WIDGET (view),
- NULL,
- page_area->x + 15,
- page_area->y + 15,
- layout);
-
- pango_font_description_free (font_desc);
- g_object_unref (layout);
-}
-
static gboolean
ev_view_expose_event (GtkWidget *widget,
GdkEventExpose *event)
{
- EvView *view = EV_VIEW (widget);
- cairo_t *cr;
- gint i;
+ EvView *view = EV_VIEW (widget);
+ GdkWindow *bin_window;
+ cairo_t *cr;
+ gint i;
- if (view->animation) {
- if (ev_transition_animation_ready (view->animation)) {
- GdkRectangle page_area;
- GtkBorder border;
+ if (view->loading) {
+ show_loading_window (view);
+ } else if (view->loading_window &&
+ gtk_widget_get_visible (view->loading_window)) {
+ ev_view_loading_window_move (view);
+ }
- if (get_page_extents (view, view->current_page, &page_area, &border)) {
- cr = gdk_cairo_create (view->layout.bin_window);
+ if (view->document == NULL)
+ return FALSE;
- /* normalize to x=0, y=0 */
- cairo_translate (cr, page_area.x, page_area.y);
- page_area.x = page_area.y = 0;
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+ cr = gdk_cairo_create (bin_window);
- ev_transition_animation_paint (view->animation, cr, page_area);
- cairo_destroy (cr);
- }
- }
+ for (i = view->start_page; i >= 0 && i <= view->end_page; i++) {
+ GdkRectangle page_area;
+ GtkBorder border;
+ gboolean page_ready = TRUE;
- return TRUE;
- }
+ if (!ev_view_get_page_extents (view, i, &page_area, &border))
+ continue;
- if (view->presentation) {
- switch (view->presentation_state) {
- case EV_PRESENTATION_END: {
- GdkRectangle area = {0};
-
- area.width = widget->allocation.width;
- area.height = widget->allocation.height;
-
- draw_end_presentation_page (view, &area);
- }
- return FALSE;
- case EV_PRESENTATION_BLACK:
- case EV_PRESENTATION_WHITE:
- return FALSE;
- case EV_PRESENTATION_NORMAL:
- default:
- break;
- }
- } else if (view->loading) {
- GdkRectangle area = {0};
-
- area.width = widget->allocation.width;
- area.height = widget->allocation.height;
-
- draw_loading_text (view,
- &area,
- &(event->area));
- }
-
- if (view->document == NULL)
- return FALSE;
-
- cr = gdk_cairo_create (view->layout.bin_window);
-
- for (i = view->start_page; i <= view->end_page; i++) {
- GdkRectangle page_area;
- GtkBorder border;
- gboolean page_ready = TRUE;
-
- if (!get_page_extents (view, i, &page_area, &border))
- continue;
-
- page_area.x -= view->scroll_x;
- page_area.y -= view->scroll_y;
+ page_area.x -= view->scroll_x;
+ page_area.y -= view->scroll_y;
draw_one_page (view, i, cr, &page_area, &border, &(event->area), &page_ready);
highlight_find_results (view, i);
if (page_ready && EV_IS_DOCUMENT_ANNOTATIONS (view->document))
show_annotation_windows (view, i);
+ if (page_ready && view->focus_annotation)
+ focus_annotation (view, i, &event->area);
+ if (page_ready && view->synctex_result)
+ highlight_forward_search_results (view, i);
}
cairo_destroy (cr);
gdouble x,
gdouble y)
{
- EvLink *link;
- EvImage *image;
+ GList *items = NULL;
+ EvLink *link;
+ EvImage *image;
+ EvAnnotation *annot;
image = ev_view_get_image_at_location (view, x, y);
- if (image) {
- g_signal_emit (view, signals[SIGNAL_POPUP_MENU], 0, image);
- return TRUE;
- }
+ if (image)
+ items = g_list_prepend (items, image);
link = ev_view_get_link_at_location (view, x, y);
- if (link) {
- g_signal_emit (view, signals[SIGNAL_POPUP_MENU], 0, link);
- return TRUE;
- }
+ if (link)
+ items = g_list_prepend (items, link);
- g_signal_emit (view, signals[SIGNAL_POPUP_MENU], 0, NULL);
+ annot = ev_view_get_annotation_at_location (view, x, y);
+ if (annot)
+ items = g_list_prepend (items, annot);
+
+ g_signal_emit (view, signals[SIGNAL_POPUP_MENU], 0, items);
+
+ g_list_free (items);
return TRUE;
}
EvLink *link,
GdkRectangle *area)
{
- EvRectangle ev_rect;
- GList *link_mapping;
- gint page;
- gint x_offset = 0, y_offset = 0;
+ EvMappingList *link_mapping;
+ gint page;
+ gint x_offset = 0, y_offset = 0;
x += view->scroll_x;
y += view->scroll_y;
find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
- link_mapping = ev_pixbuf_cache_get_link_mapping (view->pixbuf_cache, page);
- ev_link_mapping_get_area (link_mapping, link, &ev_rect);
-
- doc_rect_to_view_rect (view, page, &ev_rect, area);
- area->y -= view->scroll_y;
+ link_mapping = ev_page_cache_get_link_mapping (view->page_cache, page);
+ ev_view_get_area_from_mapping (view, page,
+ link_mapping,
+ link, area);
}
static void
EvAnnotation *annot,
GdkRectangle *area)
{
- EvRectangle ev_rect;
- GList *annots_mapping;
- gint page;
- gint x_offset = 0, y_offset = 0;
+ EvMappingList *annot_mapping;
+ gint page;
+ gint x_offset = 0, y_offset = 0;
x += view->scroll_x;
y += view->scroll_y;
find_page_at_location (view, x, y, &page, &x_offset, &y_offset);
- annots_mapping = ev_pixbuf_cache_get_annots_mapping (view->pixbuf_cache, page);
- ev_annotation_mapping_get_area (annots_mapping, annot, &ev_rect);
-
- doc_rect_to_view_rect (view, page, &ev_rect, area);
- area->y -= view->scroll_y;
+ annot_mapping = ev_page_cache_get_annot_mapping (view->page_cache, page);
+ ev_view_get_area_from_mapping (view, page,
+ annot_mapping,
+ annot, area);
}
static gboolean
gchar *text;
annot = ev_view_get_annotation_at_location (view, x, y);
- if (annot && annot->contents) {
- GdkRectangle annot_area;
+ if (annot) {
+ const gchar *contents;
- get_annot_area (view, x, y, annot, &annot_area);
- gtk_tooltip_set_text (tooltip, annot->contents);
- gtk_tooltip_set_tip_area (tooltip, &annot_area);
+ if ((contents = ev_annotation_get_contents (annot))) {
+ GdkRectangle annot_area;
- return TRUE;
+ get_annot_area (view, x, y, annot, &annot_area);
+ gtk_tooltip_set_text (tooltip, contents);
+ gtk_tooltip_set_tip_area (tooltip, &annot_area);
+
+ return TRUE;
+ }
}
link = ev_view_get_link_at_location (view, x, y);
get_link_area (view, x, y, link, &link_area);
gtk_tooltip_set_text (tooltip, text);
gtk_tooltip_set_tip_area (tooltip, &link_area);
+ g_free (text);
+
+ return TRUE;
}
g_free (text);
- return TRUE;
+ return FALSE;
}
static void
start_selection_for_event (EvView *view,
GdkEventButton *event)
{
- EvSelectionStyle style;
-
clear_selection (view);
-
+
view->selection_info.start.x = event->x + view->scroll_x;
view->selection_info.start.y = event->y + view->scroll_y;
switch (event->type) {
case GDK_2BUTTON_PRESS:
- style = EV_SELECTION_STYLE_WORD;
+ view->selection_info.style = EV_SELECTION_STYLE_WORD;
break;
case GDK_3BUTTON_PRESS:
- style = EV_SELECTION_STYLE_LINE;
+ view->selection_info.style = EV_SELECTION_STYLE_LINE;
break;
default:
- style = EV_SELECTION_STYLE_GLYPH;
- break;
+ view->selection_info.style = EV_SELECTION_STYLE_GLYPH;
+ return;
}
- view->selection_info.style = style;
+ /* In case of WORD or LINE, compute selections now */
+ compute_selections (view,
+ view->selection_info.style,
+ &(view->selection_info.start),
+ &(view->selection_info.start));
}
static gboolean
if (!view->document)
return FALSE;
- if (!GTK_WIDGET_HAS_FOCUS (widget)) {
+ if (!gtk_widget_has_focus (widget)) {
gtk_widget_grab_focus (widget);
}
window = EV_ANNOTATION_WINDOW (view->window_child_focus->window);
annot = ev_annotation_window_get_annotation (window);
ev_annotation_window_ungrab_focus (window);
- ev_view_annotation_save (view, annot);
view->window_child_focus = NULL;
}
view->pressed_button = event->button;
view->selection_info.in_drag = FALSE;
+ if (view->adding_annot)
+ return FALSE;
+
if (view->scroll_info.autoscrolling)
return TRUE;
EvAnnotation *annot;
EvFormField *field;
+ if (event->state & GDK_CONTROL_MASK)
+ return ev_view_synctex_backward_search (view, event->x , event->y);
+
if (EV_IS_SELECTION (view->document) && view->selection_info.selections) {
if (event->type == GDK_3BUTTON_PRESS) {
start_selection_for_event (view, event);
gtk_widget_queue_draw (widget);
} else if ((annot = ev_view_get_annotation_at_location (view, event->x, event->y))) {
- ev_view_handle_annotation (view, annot, event->x, event->y);
+ ev_view_handle_annotation (view, annot, event->x, event->y, event->time);
} else if ((field = ev_view_get_form_field_at_location (view, event->x, event->y))) {
ev_view_remove_all (view);
ev_view_handle_form_field (view, field, event->x, event->y);
view->image_dnd_info.start.y = event->y + view->scroll_y;
} else {
ev_view_remove_all (view);
-
+
+ if (view->synctex_result) {
+ g_free (view->synctex_result);
+ view->synctex_result = NULL;
+ gtk_widget_queue_draw (widget);
+ }
+
+ if (view->focus_annotation)
+ view->focus_annotation = NULL;
+
if (EV_IS_SELECTION (view->document))
start_selection_for_event (view, event);
}
if (gtk_drag_get_source_widget (context) == widget)
gdk_drag_status (context, 0, time);
else
- gdk_drag_status (context, context->suggested_action, time);
+ gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), time);
return TRUE;
}
{
gint x, y, shift = 0;
GtkWidget *widget = GTK_WIDGET (view);
-
+ GtkAllocation allocation;
+
+ gtk_widget_get_allocation (widget, &allocation);
gtk_widget_get_pointer (widget, &x, &y);
- if (y > widget->allocation.height) {
- shift = (y - widget->allocation.height) / 2;
+ if (y > allocation.height) {
+ shift = (y - allocation.height) / 2;
} else if (y < 0) {
shift = y / 2;
}
if (shift)
gtk_adjustment_set_value (view->vadjustment,
- CLAMP (view->vadjustment->value + shift,
- view->vadjustment->lower,
- view->vadjustment->upper -
- view->vadjustment->page_size));
+ CLAMP (gtk_adjustment_get_value (view->vadjustment) + shift,
+ gtk_adjustment_get_lower (view->vadjustment),
+ gtk_adjustment_get_upper (view->vadjustment) -
+ gtk_adjustment_get_page_size (view->vadjustment)));
- if (x > widget->allocation.width) {
- shift = (x - widget->allocation.width) / 2;
+ if (x > allocation.width) {
+ shift = (x - allocation.width) / 2;
} else if (x < 0) {
shift = x / 2;
}
if (shift)
gtk_adjustment_set_value (view->hadjustment,
- CLAMP (view->hadjustment->value + shift,
- view->hadjustment->lower,
- view->hadjustment->upper -
- view->hadjustment->page_size));
+ CLAMP (gtk_adjustment_get_value (view->hadjustment) + shift,
+ gtk_adjustment_get_lower (view->hadjustment),
+ gtk_adjustment_get_upper (view->hadjustment) -
+ gtk_adjustment_get_page_size (view->hadjustment)));
return TRUE;
}
{
gdouble dhadj_value, dvadj_value;
gdouble oldhadjustment, oldvadjustment;
+ gdouble h_page_size, v_page_size;
+ gdouble h_upper, v_upper;
+ GtkAllocation allocation;
view->drag_info.momentum.x /= 1.2;
view->drag_info.momentum.y /= 1.2; /* Alter these constants to change "friction" */
- dhadj_value = view->hadjustment->page_size *
- (gdouble)view->drag_info.momentum.x / GTK_WIDGET (view)->allocation.width;
- dvadj_value = view->vadjustment->page_size *
- (gdouble)view->drag_info.momentum.y / GTK_WIDGET (view)->allocation.height;
+ gtk_widget_get_allocation (GTK_WIDGET (view), &allocation);
+
+ h_page_size = gtk_adjustment_get_page_size (view->hadjustment);
+ v_page_size = gtk_adjustment_get_page_size (view->vadjustment);
+
+ dhadj_value = h_page_size *
+ (gdouble)view->drag_info.momentum.x / allocation.width;
+ dvadj_value = v_page_size *
+ (gdouble)view->drag_info.momentum.y / allocation.height;
oldhadjustment = gtk_adjustment_get_value (view->hadjustment);
oldvadjustment = gtk_adjustment_get_value (view->vadjustment);
- /* When we reach the edges, we need either to absorb some momentum and bounce by
- * multiplying it on -0.5 or stop scrolling by setting momentum to 0. */
- if (((oldhadjustment + dhadj_value) > (view->hadjustment->upper - view->hadjustment->page_size)) ||
- ((oldhadjustment + dhadj_value) < 0))
+ h_upper = gtk_adjustment_get_upper (view->hadjustment);
+ v_upper = gtk_adjustment_get_upper (view->vadjustment);
+
+ /* When we reach the edges, we need either to absorb some momentum and bounce by
+ * multiplying it on -0.5 or stop scrolling by setting momentum to 0. */
+ if (((oldhadjustment + dhadj_value) > (h_upper - h_page_size)) ||
+ ((oldhadjustment + dhadj_value) < 0))
view->drag_info.momentum.x = 0;
- if (((oldvadjustment + dvadj_value) > (view->vadjustment->upper - view->vadjustment->page_size)) ||
- ((oldvadjustment + dvadj_value) < 0))
+ if (((oldvadjustment + dvadj_value) > (v_upper - v_page_size)) ||
+ ((oldvadjustment + dvadj_value) < 0))
view->drag_info.momentum.y = 0;
gtk_adjustment_set_value (view->hadjustment,
- MIN (oldhadjustment + dhadj_value,
- view->hadjustment->upper - view->hadjustment->page_size));
+ MIN (oldhadjustment + dhadj_value,
+ h_upper - h_page_size));
gtk_adjustment_set_value (view->vadjustment,
- MIN (oldvadjustment + dvadj_value,
- view->vadjustment->upper - view->vadjustment->page_size));
+ MIN (oldvadjustment + dvadj_value,
+ v_upper - v_page_size));
if (((view->drag_info.momentum.x < 1) && (view->drag_info.momentum.x > -1)) &&
- ((view->drag_info.momentum.y < 1) && (view->drag_info.momentum.y > -1)))
+ ((view->drag_info.momentum.y < 1) && (view->drag_info.momentum.y > -1)))
return FALSE;
else
return TRUE;
ev_view_motion_notify_event (GtkWidget *widget,
GdkEventMotion *event)
{
- EvView *view = EV_VIEW (widget);
- gint x, y;
+ EvView *view = EV_VIEW (widget);
+ GdkWindow *bin_window;
+ gint x, y;
if (!view->document)
return FALSE;
-
-
- if (event->is_hint || event->window != view->layout.bin_window) {
+
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+
+ if (event->is_hint || event->window != bin_window) {
gtk_widget_get_pointer (widget, &x, &y);
} else {
x = event->x;
if (view->drag_info.in_drag) {
int dx, dy;
gdouble dhadj_value, dvadj_value;
+ GtkAllocation allocation;
view->drag_info.buffer[0].x = event->x;
view->drag_info.buffer[0].y = event->y;
dx = event->x_root - view->drag_info.start.x;
dy = event->y_root - view->drag_info.start.y;
- dhadj_value = view->hadjustment->page_size *
- (gdouble)dx / widget->allocation.width;
- dvadj_value = view->vadjustment->page_size *
- (gdouble)dy / widget->allocation.height;
+ gtk_widget_get_allocation (widget, &allocation);
+
+ dhadj_value = gtk_adjustment_get_page_size (view->hadjustment) *
+ (gdouble)dx / allocation.width;
+ dvadj_value = gtk_adjustment_get_page_size (view->vadjustment) *
+ (gdouble)dy / allocation.height;
/* clamp scrolling to visible area */
gtk_adjustment_set_value (view->hadjustment,
- MIN(view->drag_info.hadj - dhadj_value,
- view->hadjustment->upper -
- view->hadjustment->page_size));
+ MIN (view->drag_info.hadj - dhadj_value,
+ gtk_adjustment_get_upper (view->hadjustment) -
+ gtk_adjustment_get_page_size (view->hadjustment)));
gtk_adjustment_set_value (view->vadjustment,
- MIN(view->drag_info.vadj - dvadj_value,
- view->vadjustment->upper -
- view->vadjustment->page_size));
+ MIN (view->drag_info.vadj - dvadj_value,
+ gtk_adjustment_get_upper (view->vadjustment) -
+ gtk_adjustment_get_page_size (view->vadjustment)));
return TRUE;
}
view->pressed_button = -1;
return TRUE;
- }
+ }
+
+ if (view->pressed_button == 1 && event->state & GDK_CONTROL_MASK) {
+ view->pressed_button = -1;
+ return TRUE;
+ }
if (view->drag_info.in_drag) {
view->drag_info.release_timeout_id =
if (view->document && !view->drag_info.in_drag && view->pressed_button != 3) {
link = ev_view_get_link_at_location (view, event->x, event->y);
}
-
+
view->drag_info.in_drag = FALSE;
+ if (view->adding_annot && view->pressed_button == 1) {
+ view->adding_annot = FALSE;
+ ev_view_handle_cursor_over_xy (view, event->x, event->y);
+ view->pressed_button = -1;
+
+ ev_view_create_annotation (view,
+ view->adding_annot_type,
+ event->x + view->scroll_x,
+ event->y + view->scroll_y);
+
+ return FALSE;
+ }
+
if (view->pressed_button == 2) {
ev_view_handle_cursor_over_xy (view, event->x, event->y);
}
view->selection_update_id = 0;
}
- if (!view->selection_info.in_selection &&
- view->selection_info.style != EV_SELECTION_STYLE_GLYPH) {
- compute_selections (view,
- view->selection_info.style,
- &(view->selection_info.start),
- &(view->selection_info.start));
- }
-
if (view->selection_info.selections) {
clear_link_selected (view);
ev_view_update_primary_selection (view);
} else {
ev_view_handle_link (view, link);
}
- } else if (view->presentation) {
- switch (event->button) {
- case 1:
- ev_view_next_page (view);
- return TRUE;
- case 3:
- ev_view_previous_page (view);
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-/* Goto Window */
-/* Cut and paste from gtkwindow.c */
-static void
-send_focus_change (GtkWidget *widget,
- gboolean in)
-{
- GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
-
- g_object_ref (widget);
-
- if (in)
- GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
- else
- GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
-
- fevent->focus_change.type = GDK_FOCUS_CHANGE;
- fevent->focus_change.window = g_object_ref (widget->window);
- fevent->focus_change.in = in;
-
- gtk_widget_event (widget, fevent);
-
- g_object_notify (G_OBJECT (widget), "has-focus");
-
- g_object_unref (widget);
- gdk_event_free (fevent);
-}
-
-static void
-ev_view_goto_window_hide (EvView *view)
-{
- /* send focus-in event */
- send_focus_change (view->goto_entry, FALSE);
- gtk_widget_hide (view->goto_window);
- gtk_entry_set_text (GTK_ENTRY (view->goto_entry), "");
-}
-
-static gboolean
-ev_view_goto_window_delete_event (GtkWidget *widget,
- GdkEventAny *event,
- EvView *view)
-{
- ev_view_goto_window_hide (view);
-
- return TRUE;
-}
-
-static gboolean
-key_is_numeric (guint keyval)
-{
- return ((keyval >= GDK_0 && keyval <= GDK_9) ||
- (keyval >= GDK_KP_0 && keyval <= GDK_KP_9));
-}
-
-static gboolean
-ev_view_goto_window_key_press_event (GtkWidget *widget,
- GdkEventKey *event,
- EvView *view)
-{
- switch (event->keyval) {
- case GDK_Escape:
- case GDK_Tab:
- case GDK_KP_Tab:
- case GDK_ISO_Left_Tab:
- ev_view_goto_window_hide (view);
- return TRUE;
- case GDK_Return:
- case GDK_KP_Enter:
- case GDK_ISO_Enter:
- case GDK_BackSpace:
- case GDK_Delete:
- return FALSE;
- default:
- if (!key_is_numeric (event->keyval))
- return TRUE;
}
return FALSE;
}
-static gboolean
-ev_view_goto_window_button_press_event (GtkWidget *widget,
- GdkEventButton *event,
- EvView *view)
-{
- ev_view_goto_window_hide (view);
-
- return TRUE;
-}
-
-static void
-ev_view_goto_entry_activate (GtkEntry *entry,
- EvView *view)
-{
- const gchar *text;
- gint page;
-
- text = gtk_entry_get_text (entry);
- page = atoi (text) - 1;
-
- ev_view_goto_window_hide (view);
-
- if (page >= 0 &&
- page < ev_page_cache_get_n_pages (view->page_cache))
- ev_page_cache_set_current_page (view->page_cache, page);
-}
-
-static void
-ev_view_goto_window_create (EvView *view)
-{
- GtkWidget *frame, *hbox, *toplevel, *label;
-
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
-
- if (view->goto_window) {
- if (GTK_WINDOW (toplevel)->group)
- gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
- GTK_WINDOW (view->goto_window));
- else if (GTK_WINDOW (view->goto_window)->group)
- gtk_window_group_remove_window (GTK_WINDOW (view->goto_window)->group,
- GTK_WINDOW (view->goto_window));
- return;
- }
-
- view->goto_window = gtk_window_new (GTK_WINDOW_POPUP);
- gtk_window_set_screen (GTK_WINDOW (view->goto_window),
- gtk_widget_get_screen (GTK_WIDGET (view)));
-
- if (GTK_WINDOW (toplevel)->group)
- gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
- GTK_WINDOW (view->goto_window));
-
- gtk_window_set_modal (GTK_WINDOW (view->goto_window), TRUE);
-
- g_signal_connect (view->goto_window, "delete_event",
- G_CALLBACK (ev_view_goto_window_delete_event),
- view);
- g_signal_connect (view->goto_window, "key_press_event",
- G_CALLBACK (ev_view_goto_window_key_press_event),
- view);
- g_signal_connect (view->goto_window, "button_press_event",
- G_CALLBACK (ev_view_goto_window_button_press_event),
- view);
-
- frame = gtk_frame_new (NULL);
- gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
- gtk_container_add (GTK_CONTAINER (view->goto_window), frame);
- gtk_widget_show (frame);
-
- hbox = gtk_hbox_new (FALSE, 0);
- gtk_container_set_border_width (GTK_CONTAINER (hbox), 3);
- gtk_container_add (GTK_CONTAINER (frame), hbox);
- gtk_widget_show (hbox);
-
- label = gtk_label_new(_("Jump to page:"));
- gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 3);
- gtk_widget_show (label);
- gtk_widget_realize (label);
-
- view->goto_entry = gtk_entry_new ();
- g_signal_connect (view->goto_entry, "activate",
- G_CALLBACK (ev_view_goto_entry_activate),
- view);
- gtk_box_pack_start (GTK_BOX (hbox), view->goto_entry, TRUE, TRUE, 0);
- gtk_widget_show (view->goto_entry);
- gtk_widget_realize (view->goto_entry);
-}
-
-static void
-ev_view_goto_entry_grab_focus (EvView *view)
-{
- GtkWidgetClass *entry_parent_class;
-
- entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (view->goto_entry));
- (entry_parent_class->grab_focus) (view->goto_entry);
-
- send_focus_change (view->goto_entry, TRUE);
-}
-
-static void
-ev_view_goto_window_send_key_event (EvView *view,
- GdkEvent *event)
-{
- GdkEventKey *new_event;
- GdkScreen *screen;
-
- /* Move goto window off screen */
- screen = gtk_widget_get_screen (GTK_WIDGET (view));
- gtk_window_move (GTK_WINDOW (view->goto_window),
- gdk_screen_get_width (screen) + 1,
- gdk_screen_get_height (screen) + 1);
- gtk_widget_show (view->goto_window);
-
- new_event = (GdkEventKey *) gdk_event_copy (event);
- g_object_unref (new_event->window);
- new_event->window = g_object_ref (view->goto_window->window);
- gtk_widget_realize (view->goto_window);
-
- gtk_widget_event (view->goto_window, (GdkEvent *)new_event);
- gdk_event_free ((GdkEvent *)new_event);
- gtk_widget_hide (view->goto_window);
-}
-
static gboolean
ev_view_key_press_event (GtkWidget *widget,
GdkEventKey *event)
{
EvView *view = EV_VIEW (widget);
- EvPresentationState current;
if (!view->document)
return FALSE;
- if (!GTK_WIDGET_HAS_FOCUS (widget)) {
+ if (!gtk_widget_has_focus (widget)) {
/* Forward key events to current focused window child */
if (view->window_child_focus) {
GdkEventKey *new_event;
new_event = (GdkEventKey *) gdk_event_copy ((GdkEvent *)event);
g_object_unref (new_event->window);
- new_event->window = g_object_ref (view->window_child_focus->window->window);
+ new_event->window = gtk_widget_get_window (view->window_child_focus->window);
+ if (new_event->window)
+ g_object_ref (new_event->window);
gtk_widget_realize (view->window_child_focus->window);
handled = gtk_widget_event (view->window_child_focus->window, (GdkEvent *)new_event);
gdk_event_free ((GdkEvent *)new_event);
return FALSE;
}
- if (!view->presentation ||
- view->presentation_state == EV_PRESENTATION_END)
- return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
-
-
- current = view->presentation_state;
-
- switch (event->keyval) {
- case GDK_b:
- case GDK_B:
- case GDK_period:
- case GDK_KP_Decimal:
- view->presentation_state =
- (view->presentation_state == EV_PRESENTATION_BLACK) ?
- EV_PRESENTATION_NORMAL : EV_PRESENTATION_BLACK;
- break;
- case GDK_w:
- case GDK_W:
- view->presentation_state =
- (view->presentation_state == EV_PRESENTATION_WHITE) ?
- EV_PRESENTATION_NORMAL : EV_PRESENTATION_WHITE;
- break;
- default:
- if (view->presentation_state == EV_PRESENTATION_BLACK ||
- view->presentation_state == EV_PRESENTATION_WHITE) {
- view->presentation_state = EV_PRESENTATION_NORMAL;
- }
- }
-
- if (current == view->presentation_state) {
- if (ev_page_cache_get_n_pages (view->page_cache) > 1 &&
- key_is_numeric (event->keyval)) {
- gint x, y;
-
- ev_view_goto_window_create (view);
- ev_view_goto_window_send_key_event (view, (GdkEvent *)event);
- gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
- gtk_window_move (GTK_WINDOW (view->goto_window), x, y);
- gtk_widget_show (view->goto_window);
- ev_view_goto_entry_grab_focus (view);
-
- return TRUE;
- }
-
- return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
- }
-
- switch (view->presentation_state) {
- case EV_PRESENTATION_NORMAL:
- case EV_PRESENTATION_BLACK:
- gdk_window_set_background (view->layout.bin_window,
- &widget->style->black);
- break;
- case EV_PRESENTATION_WHITE:
- gdk_window_set_background (view->layout.bin_window,
- &widget->style->white);
- break;
- default:
- return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
- }
-
- gtk_widget_queue_draw (widget);
- return TRUE;
+ return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
}
static gint
static gint
ev_view_focus_out (GtkWidget *widget,
- GdkEventFocus *event)
+ GdkEventFocus *event)
{
- if (EV_VIEW (widget)->goto_window)
- ev_view_goto_window_hide (EV_VIEW (widget));
-
if (EV_VIEW (widget)->pixbuf_cache)
ev_pixbuf_cache_style_changed (EV_VIEW (widget)->pixbuf_cache);
gtk_widget_queue_draw (widget);
/*** Drawing ***/
-static guint32
-ev_gdk_color_to_rgb (const GdkColor *color)
-{
- guint32 result;
- result = (0xff0000 | (color->red & 0xff00));
- result <<= 8;
- result |= ((color->green & 0xff00) | (color->blue >> 8));
- return result;
-}
-
static void
-draw_rubberband (GtkWidget *widget, GdkWindow *window,
- const GdkRectangle *rect, guchar alpha)
+draw_rubberband (EvView *view,
+ GdkWindow *window,
+ const GdkRectangle *rect,
+ gdouble alpha)
{
- GdkGC *gc;
- GdkPixbuf *pixbuf;
+ GtkStyle *style;
GdkColor *fill_color_gdk;
- guint fill_color;
+ gdouble r, g, b;
+ cairo_t *cr;
- fill_color_gdk = gdk_color_copy (>K_WIDGET (widget)->style->base[GTK_STATE_SELECTED]);
- fill_color = ev_gdk_color_to_rgb (fill_color_gdk) << 8 | alpha;
+ style = gtk_widget_get_style (GTK_WIDGET (view));
+ fill_color_gdk = gdk_color_copy (&style->base[GTK_STATE_SELECTED]);
+ r = fill_color_gdk->red / 65535.;
+ g = fill_color_gdk->green / 65535.;
+ b = fill_color_gdk->blue / 65535.;
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
- rect->width, rect->height);
- gdk_pixbuf_fill (pixbuf, fill_color);
+ cr = gdk_cairo_create (window);
- gdk_draw_pixbuf (window, NULL, pixbuf,
- 0, 0,
- rect->x - EV_VIEW (widget)->scroll_x, rect->y - EV_VIEW (widget)->scroll_y,
- rect->width, rect->height,
- GDK_RGB_DITHER_NONE,
- 0, 0);
+ cairo_set_source_rgba (cr, r, g, b, alpha);
+ cairo_rectangle (cr,
+ rect->x - view->scroll_x,
+ rect->y - view->scroll_y,
+ rect->width, rect->height);
+ cairo_fill_preserve (cr);
- g_object_unref (pixbuf);
+ cairo_set_line_width (cr, 0.5);
+ cairo_set_source_rgb (cr, r, g, b);
+ cairo_stroke (cr);
- gc = gdk_gc_new (window);
- gdk_gc_set_rgb_fg_color (gc, fill_color_gdk);
- gdk_draw_rectangle (window, gc, FALSE,
- rect->x - EV_VIEW (widget)->scroll_x, rect->y - EV_VIEW (widget)->scroll_y,
- rect->width - 1,
- rect->height - 1);
- g_object_unref (gc);
+ cairo_destroy (cr);
gdk_color_free (fill_color_gdk);
}
static void
highlight_find_results (EvView *view, int page)
{
- gint i, n_results = 0;
+ gint i, n_results = 0;
+ GdkWindow *bin_window;
+
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
n_results = ev_view_find_get_n_results (view, page);
for (i = 0; i < n_results; i++) {
EvRectangle *rectangle;
GdkRectangle view_rectangle;
- guchar alpha;
+ gdouble alpha;
if (i == view->find_result && page == view->current_page) {
- alpha = 0x90;
+ alpha = 0.6;
} else {
- alpha = 0x20;
+ alpha = 0.3;
}
rectangle = ev_view_find_get_result (view, page, i);
doc_rect_to_view_rect (view, page, rectangle, &view_rectangle);
- draw_rubberband (GTK_WIDGET (view), view->layout.bin_window,
- &view_rectangle, alpha);
+ draw_rubberband (view, bin_window, &view_rectangle, alpha);
}
}
static void
-draw_loading_text (EvView *view,
- GdkRectangle *page_area,
- GdkRectangle *expose_area)
+highlight_forward_search_results (EvView *view, int page)
{
- cairo_t *cr;
- gint width, height;
+ GdkWindow *bin_window;
+ GdkRectangle rect;
+ cairo_t *cr;
+ EvMapping *mapping = view->synctex_result;
- if (!view->loading_text) {
- const gchar *loading_text = _("Loading...");
- PangoLayout *layout;
- PangoFontDescription *font_desc;
- PangoRectangle logical_rect;
- gint target_width;
- gdouble real_scale;
+ if (GPOINTER_TO_INT (mapping->data) != page)
+ return;
- ev_document_fc_mutex_lock ();
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+ doc_rect_to_view_rect (view, page, &mapping->area, &rect);
- layout = gtk_widget_create_pango_layout (GTK_WIDGET (view), loading_text);
-
- font_desc = pango_font_description_new ();
-
- /* We set the font to be 10 points, get the size, and scale appropriately */
- pango_font_description_set_size (font_desc, 10 * PANGO_SCALE);
- pango_layout_set_font_description (layout, font_desc);
- pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
-
- target_width = MAX (page_area->width / 2, 1);
- real_scale = ((double)target_width / (double) logical_rect.width) * (PANGO_SCALE * 10);
- pango_font_description_set_size (font_desc, (int)real_scale);
- pango_layout_set_font_description (layout, font_desc);
- pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
-
- view->loading_text = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- logical_rect.width,
- logical_rect.height);
- cr = cairo_create (view->loading_text);
- cairo_set_source_rgb (cr,
- 155 / (double)255,
- 155 / (double)255,
- 155 / (double)255);
- pango_cairo_show_layout (cr, layout);
- cairo_destroy (cr);
-
- pango_font_description_free (font_desc);
- g_object_unref (layout);
-
- ev_document_fc_mutex_unlock ();
- }
-
- width = (page_area->width - cairo_image_surface_get_width (view->loading_text)) / 2;
- height = (page_area->height - cairo_image_surface_get_height (view->loading_text)) / 2;
-
- cr = gdk_cairo_create (view->layout.bin_window);
- cairo_translate (cr,
- page_area->x + width,
- page_area->y + height);
- cairo_set_source_surface (cr, view->loading_text, 0, 0);
- cairo_paint (cr);
+ cr = gdk_cairo_create (bin_window);
+ cairo_set_source_rgb (cr, 1., 0., 0.);
+ cairo_rectangle (cr,
+ rect.x - view->scroll_x,
+ rect.y - view->scroll_y,
+ rect.width, rect.height);
+ cairo_stroke (cr);
cairo_destroy (cr);
}
+static void
+focus_annotation (EvView *view,
+ gint page,
+ GdkRectangle *clip)
+{
+ GtkWidget *widget = GTK_WIDGET (view);
+ GdkRectangle rect;
+ EvMapping *mapping = view->focus_annotation;
+ EvAnnotation *annot = (EvAnnotation *)mapping->data;
+
+ if (ev_annotation_get_page_index (annot) != page)
+ return;
+
+ doc_rect_to_view_rect (view, page, &mapping->area, &rect);
+ gtk_paint_focus (gtk_widget_get_style (widget),
+ gtk_layout_get_bin_window (GTK_LAYOUT (view)),
+ gtk_widget_get_state (widget),
+ NULL, widget, NULL,
+ rect.x - view->scroll_x,
+ rect.y - view->scroll_y,
+ rect.width + 1, rect.height + 1);
+}
+
+static void
+ev_view_loading_window_move (EvView *view)
+{
+ GtkWidget *widget = GTK_WIDGET (view);
+ EvLoadingWindow *window = EV_LOADING_WINDOW (view->loading_window);
+ gint root_x, root_y;
+ gint window_width;
+ GtkAllocation allocation;
+
+ gtk_widget_get_allocation (widget, &allocation);
+ gdk_window_get_origin (gtk_widget_get_window (widget), &root_x, &root_y);
+ ev_loading_window_get_size (window, &window_width, NULL);
+
+ root_x += allocation.width - window_width - 10;
+ root_y += 10;
+
+ ev_loading_window_move (window, root_x, root_y);
+}
+
+static gboolean
+show_loading_window_cb (EvView *view)
+{
+ if (!view->loading_window) {
+ GtkWindow *parent;
+ GdkScreen *screen;
+
+ parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
+ view->loading_window = ev_loading_window_new (parent);
+
+ /* Show the window off screen to get a valid size asap */
+ screen = gtk_widget_get_screen (GTK_WIDGET (view));
+ gtk_window_move (GTK_WINDOW (view->loading_window),
+ gdk_screen_get_width (screen) + 1,
+ gdk_screen_get_height (screen) + 1);
+ gtk_widget_show (view->loading_window);
+ }
+
+ ev_view_loading_window_move (view);
+
+ gtk_widget_show (view->loading_window);
+
+ view->loading_timeout = 0;
+
+ return FALSE;
+}
+
+static void
+show_loading_window (EvView *view)
+{
+ if (view->loading_window && gtk_widget_get_visible (view->loading_window)) {
+ ev_view_loading_window_move (view);
+ return;
+ }
+
+ if (!view->loading_timeout) {
+ view->loading_timeout =
+ g_timeout_add_full (G_PRIORITY_LOW,
+ 0.5, (GSourceFunc)show_loading_window_cb,
+ view, NULL);
+ }
+}
+
+static void
+hide_loading_window (EvView *view)
+{
+ if (view->loading_timeout) {
+ g_source_remove (view->loading_timeout);
+ view->loading_timeout = 0;
+ }
+
+ if (view->loading_window && gtk_widget_get_visible (view->loading_window)) {
+ gtk_widget_hide (view->loading_window);
+ }
+}
+
static void
draw_one_page (EvView *view,
gint page,
{
GdkRectangle overlap;
GdkRectangle real_page_area;
+ gint current_page;
+ gboolean inverted_colors;
g_assert (view->document);
real_page_area.height -= (border->top + border->bottom);
*page_ready = TRUE;
- if (!view->presentation) {
- gint current_page;
-
- current_page = ev_page_cache_get_current_page (view->page_cache);
- ev_document_misc_paint_one_page (view->layout.bin_window,
- GTK_WIDGET (view),
- page_area, border,
- page == current_page);
- }
+ current_page = ev_document_model_get_page (view->model);
+ inverted_colors = ev_document_model_get_inverted_colors (view->model);
+ ev_document_misc_paint_one_page (cr,
+ GTK_WIDGET (view),
+ page_area, border,
+ page == current_page,
+ inverted_colors);
if (gdk_rectangle_intersect (&real_page_area, expose_area, &overlap)) {
gint width, height;
page_surface = ev_pixbuf_cache_get_surface (view->pixbuf_cache, page);
if (!page_surface) {
- if (!view->presentation) {
- draw_loading_text (view,
- &real_page_area,
- expose_area);
- }
+ if (page == current_page)
+ show_loading_window (view);
*page_ready = FALSE;
return;
}
- ev_page_cache_get_size (view->page_cache,
- page, view->rotation,
- view->scale,
- &width, &height);
+ if (page == current_page)
+ hide_loading_window (view);
+
+ ev_view_get_page_size (view, page, &width, &height);
page_width = cairo_image_surface_get_width (page_surface);
page_height = cairo_image_surface_get_height (page_surface);
cairo_surface_set_device_offset (selection_surface,
overlap.x - real_page_area.x,
overlap.y - real_page_area.y);
+
cairo_set_source_surface (cr, selection_surface, 0, 0);
cairo_paint (cr);
cairo_restore (cr);
clear_selection (view);
clear_link_selected (view);
+ if (view->synctex_result) {
+ g_free (view->synctex_result);
+ view->synctex_result = NULL;
+ }
+
if (view->image_dnd_info.image)
g_object_unref (view->image_dnd_info.image);
view->image_dnd_info.image = NULL;
{
EvView *view = EV_VIEW (object);
- if (view->document) {
- g_object_unref (view->document);
- view->document = NULL;
+ if (view->model) {
+ g_object_unref (view->model);
+ view->model = NULL;
}
if (view->pixbuf_cache) {
view->pixbuf_cache = NULL;
}
- if (view->goto_window) {
- gtk_widget_destroy (view->goto_window);
- view->goto_window = NULL;
- view->goto_entry = NULL;
+ if (view->document) {
+ g_object_unref (view->document);
+ view->document = NULL;
+ }
+
+ if (view->page_cache) {
+ g_object_unref (view->page_cache);
+ view->page_cache = NULL;
}
ev_view_window_children_free (view);
view->selection_update_id = 0;
}
- if (view->loading_text) {
- cairo_surface_destroy (view->loading_text);
- view->loading_text = NULL;
- }
-
if (view->scroll_info.timeout_id) {
g_source_remove (view->scroll_info.timeout_id);
view->scroll_info.timeout_id = 0;
view->drag_info.release_timeout_id = 0;
}
- ev_view_presentation_transition_stop (view);
+ if (view->loading_timeout) {
+ g_source_remove (view->loading_timeout);
+ view->loading_timeout = 0;
+ }
ev_view_set_scroll_adjustments (GTK_LAYOUT (view), NULL, NULL);
GTK_OBJECT_CLASS (ev_view_parent_class)->destroy (object);
}
-static void
-ev_view_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- EvView *view = EV_VIEW (object);
-
- switch (prop_id) {
- case PROP_CONTINUOUS:
- ev_view_set_continuous (view, g_value_get_boolean (value));
- break;
- case PROP_DUAL_PAGE:
- ev_view_set_dual_page (view, g_value_get_boolean (value));
- break;
- case PROP_FULLSCREEN:
- ev_view_set_fullscreen (view, g_value_get_boolean (value));
- break;
- case PROP_PRESENTATION:
- ev_view_set_presentation (view, g_value_get_boolean (value));
- break;
- case PROP_SIZING_MODE:
- ev_view_set_sizing_mode (view, g_value_get_enum (value));
- break;
- case PROP_ZOOM:
- ev_view_set_zoom (view, g_value_get_double (value), FALSE);
- break;
- case PROP_ROTATION:
- ev_view_set_rotation (view, g_value_get_int (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
static AtkObject *
ev_view_get_accessible (GtkWidget *widget)
{
factory = atk_registry_get_factory (registry,
derived_type);
derived_atk_type = atk_object_factory_get_accessible_type (factory);
- if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
- atk_registry_set_factory_type (registry,
+ if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE)) {
+ atk_registry_set_factory_type (registry,
EV_TYPE_VIEW,
ev_view_accessible_factory_get_type ());
+ EV_VIEW (widget)->a11y_enabled = TRUE;
+ }
first_time = FALSE;
}
return GTK_WIDGET_CLASS (ev_view_parent_class)->get_accessible (widget);
}
-static void
-ev_view_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- EvView *view = EV_VIEW (object);
-
- switch (prop_id) {
- case PROP_CONTINUOUS:
- g_value_set_boolean (value, view->continuous);
- break;
- case PROP_DUAL_PAGE:
- g_value_set_boolean (value, view->dual_page);
- break;
- case PROP_FULLSCREEN:
- g_value_set_boolean (value, view->fullscreen);
- break;
- case PROP_PRESENTATION:
- g_value_set_boolean (value, view->presentation);
- break;
- case PROP_SIZING_MODE:
- g_value_set_enum (value, view->sizing_mode);
- break;
- case PROP_ZOOM:
- g_value_set_double (value, view->scale);
- break;
- case PROP_ROTATION:
- g_value_set_int (value, view->rotation);
- break;
- case PROP_HAS_SELECTION:
- g_value_set_boolean (value,
- view->selection_info.selections != NULL);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
-}
-
static void
ev_view_class_init (EvViewClass *class)
{
GtkBindingSet *binding_set;
object_class->finalize = ev_view_finalize;
- object_class->set_property = ev_view_set_property;
- object_class->get_property = ev_view_get_property;
widget_class->expose_event = ev_view_expose_event;
widget_class->button_press_event = ev_view_button_press_event;
G_TYPE_NONE, 2,
GTK_TYPE_SCROLL_TYPE,
G_TYPE_BOOLEAN);
-
- signals[SIGNAL_ZOOM_INVALID] = g_signal_new ("zoom-invalid",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (EvViewClass, zoom_invalid),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0, G_TYPE_NONE);
signals[SIGNAL_HANDLE_LINK] = g_signal_new ("handle-link",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (EvViewClass, popup_menu),
NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+ signals[SIGNAL_SELECTION_CHANGED] = g_signal_new ("selection-changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (EvViewClass, selection_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0,
+ G_TYPE_NONE);
+ signals[SIGNAL_SYNC_SOURCE] = g_signal_new ("sync-source",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (EvViewClass, sync_source),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+ signals[SIGNAL_ANNOT_ADDED] = g_signal_new ("annot-added",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (EvViewClass, annot_added),
+ NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
- G_TYPE_OBJECT);
-
-
- 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));
-
- g_object_class_install_property (object_class,
- PROP_ZOOM,
- g_param_spec_double ("zoom",
- "Zoom factor",
- "Zoom factor",
- 0,
- G_MAXDOUBLE,
- 1.0,
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_ROTATION,
- g_param_spec_double ("rotation",
- "Rotation",
- "Rotation",
- 0,
- 360,
- 0,
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_HAS_SELECTION,
- g_param_spec_boolean ("has-selection",
- "Has selection",
- "The view has selections",
- FALSE,
- G_PARAM_READABLE));
+ EV_TYPE_ANNOTATION);
+ signals[SIGNAL_LAYERS_CHANGED] = g_signal_new ("layers-changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (EvViewClass, layers_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0,
+ G_TYPE_NONE);
binding_set = gtk_binding_set_by_class (class);
static void
ev_view_init (EvView *view)
{
- GTK_WIDGET_SET_FLAGS (view, GTK_CAN_FOCUS);
+ gtk_widget_set_can_focus (GTK_WIDGET (view), TRUE);
+ view->start_page = -1;
+ view->end_page = -1;
view->spacing = 5;
view->scale = 1.0;
view->current_page = 0;
view->selection_mode = EV_VIEW_SELECTION_TEXT;
view->continuous = TRUE;
view->dual_page = FALSE;
- view->presentation = FALSE;
- view->presentation_state = EV_PRESENTATION_NORMAL;
view->fullscreen = FALSE;
view->sizing_mode = EV_SIZING_FIT_WIDTH;
view->pending_scroll = SCROLL_TO_KEEP_POSITION;
static void
ev_view_change_page (EvView *view,
- gint new_page,
- gboolean start_transition)
+ gint new_page)
{
gint x, y;
view->current_page = new_page;
view->pending_scroll = SCROLL_TO_PAGE_POSITION;
- if (view->presentation && start_transition)
- ev_view_presentation_transition_start (view);
+ hide_loading_window (view);
gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
ev_view_handle_cursor_over_xy (view, x, y);
}
static void
-ev_view_transition_animation_finish (EvTransitionAnimation *animation,
- EvView *view)
-{
- g_object_unref (view->animation);
- view->animation = NULL;
- ev_view_change_page (view, view->current_page, TRUE);
-}
-
-/**
- * ev_view_transition_animation_cancel:
- * @animation: Animation to finish
- * @view: An EvView
- *
- * Does almost the same as cancel, but without scheduling the transition.
- */
-
-static void
-ev_view_transition_animation_cancel (EvTransitionAnimation *animation,
- EvView *view)
+job_finished_cb (EvPixbufCache *pixbuf_cache,
+ cairo_region_t *region,
+ EvView *view)
{
- g_object_unref (view->animation);
- view->animation = NULL;
- ev_view_change_page (view, view->current_page, FALSE);
-}
-
-static void
-ev_view_transition_animation_frame (EvTransitionAnimation *animation,
- gdouble progress,
- EvView *view)
-{
- gtk_widget_queue_draw (GTK_WIDGET (view));
-}
-
-static void
-ev_view_presentation_animation_start (EvView *view,
- int new_page)
-{
- EvTransitionEffect *effect = NULL;
- cairo_surface_t *surface;
-
- if (EV_IS_DOCUMENT_TRANSITION (view->document))
- effect = ev_document_transition_get_effect (EV_DOCUMENT_TRANSITION (view->document),
- view->current_page);
- if (!effect)
- return;
-
- surface = ev_pixbuf_cache_get_surface (view->pixbuf_cache, view->current_page);
- view->animation = ev_transition_animation_new (effect);
- ev_transition_animation_set_origin_surface (view->animation, surface);
-
- g_signal_connect (view->animation, "frame",
- G_CALLBACK (ev_view_transition_animation_frame), view);
- g_signal_connect (view->animation, "finished",
- G_CALLBACK (ev_view_transition_animation_finish), view);
-}
-
-static void
-job_finished_cb (EvPixbufCache *pixbuf_cache,
- GdkRegion *region,
- EvView *view)
-{
- if (view->animation) {
- cairo_surface_t *surface;
-
- surface = ev_pixbuf_cache_get_surface (pixbuf_cache, view->current_page);
- ev_transition_animation_set_dest_surface (view->animation, surface);
- }
-
if (region) {
- gdk_window_invalidate_region (view->layout.bin_window,
- region, TRUE);
+ GdkWindow *bin_window;
+
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+#if GTK_CHECK_VERSION(2, 90, 5)
+ gdk_window_invalidate_region (bin_window, region, TRUE);
+#else
+ {
+ GdkRegion *gdk_region = gdk_region_new ();
+ guint n_recs = cairo_region_num_rectangles (region);
+ guint i;
+
+ for (i = 0; i < n_recs; i++) {
+ cairo_rectangle_int_t rect;
+
+ cairo_region_get_rectangle (region, i, &rect);
+ gdk_region_union_with_rect (gdk_region, (GdkRectangle *)&rect);
+ }
+ gdk_window_invalidate_region (bin_window, gdk_region, TRUE);
+ gdk_region_destroy (gdk_region);
+ }
+#endif
} else {
gtk_widget_queue_draw (GTK_WIDGET (view));
}
}
static void
-page_changed_cb (EvPageCache *page_cache,
- int new_page,
- EvView *view)
+ev_view_page_changed_cb (EvDocumentModel *model,
+ gint old_page,
+ gint new_page,
+ EvView *view)
{
- if (view->current_page != new_page) {
- if (view->presentation)
- ev_view_presentation_animation_start (view, new_page);
+ if (!view->document)
+ return;
- ev_view_change_page (view, new_page, TRUE);
+ if (view->current_page != new_page) {
+ ev_view_change_page (view, new_page);
} else {
gtk_widget_queue_draw (GTK_WIDGET (view));
}
{
int dx = 0, dy = 0;
gint x, y;
+ gint value;
GList *children, *l;
- if (! GTK_WIDGET_REALIZED (view))
+ if (!gtk_widget_get_realized (GTK_WIDGET (view)))
return;
if (view->hadjustment) {
- dx = view->scroll_x - (int) view->hadjustment->value;
- view->scroll_x = (int) view->hadjustment->value;
+ value = (gint) gtk_adjustment_get_value (view->hadjustment);
+ dx = view->scroll_x - value;
+ view->scroll_x = value;
} else {
view->scroll_x = 0;
}
if (view->vadjustment) {
- dy = view->scroll_y - (int) view->vadjustment->value;
- view->scroll_y = (int) view->vadjustment->value;
+ value = (gint) gtk_adjustment_get_value (view->vadjustment);
+ dy = view->scroll_y - value;
+ view->scroll_y = value;
} else {
view->scroll_y = 0;
}
ev_view_window_child_move (view, child, child->x + dx, child->y + dy);
}
- if (view->pending_resize)
+ if (view->pending_resize) {
gtk_widget_queue_draw (GTK_WIDGET (view));
- else
- gdk_window_scroll (view->layout.bin_window, dx, dy);
-
+ } else {
+ GdkWindow *bin_window;
+
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+ gdk_window_scroll (bin_window, dx, dy);
+ }
+
gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
ev_view_handle_cursor_over_xy (view, x, y);
static void
setup_caches (EvView *view)
{
- view->page_cache = ev_page_cache_get (view->document);
- g_signal_connect (view->page_cache, "page-changed", G_CALLBACK (page_changed_cb), view);
- view->pixbuf_cache = ev_pixbuf_cache_new (GTK_WIDGET (view), view->document);
+ gboolean inverted_colors;
+
+ view->height_to_page_cache = ev_view_get_height_to_page_cache (view);
+ view->pixbuf_cache = ev_pixbuf_cache_new (GTK_WIDGET (view), view->model, view->pixbuf_cache_size);
+ view->page_cache = ev_page_cache_new (view->document);
+ if (view->a11y_enabled) {
+ EvJobPageDataFlags flags = ev_page_cache_get_flags (view->page_cache);
+
+ ev_page_cache_set_flags (view->page_cache,
+ flags |
+ EV_PAGE_DATA_INCLUDE_TEXT_LAYOUT |
+ EV_PAGE_DATA_INCLUDE_TEXT);
+ }
+ inverted_colors = ev_document_model_get_inverted_colors (view->model);
+ ev_pixbuf_cache_set_inverted_colors (view->pixbuf_cache, inverted_colors);
g_signal_connect (view->pixbuf_cache, "job-finished", G_CALLBACK (job_finished_cb), view);
- page_changed_cb (view->page_cache,
- ev_page_cache_get_current_page (view->page_cache),
- view);
}
static void
}
if (view->page_cache) {
+ g_object_unref (view->page_cache);
view->page_cache = NULL;
}
}
+/**
+ * ev_view_set_page_cache_size:
+ * @view:
+ * @cache_size:
+ *
+ * Sets the maximum size in bytes that will be used to cache
+ * rendered pages. Use 0 to disable caching rendered pages.
+ *
+ * Note that this limit doesn't affect the current visible page range,
+ * which will always be rendered. In order to limit the total memory used
+ * you have to use ev_document_model_set_max_scale() too.
+ *
+ */
+void
+ev_view_set_page_cache_size (EvView *view,
+ gsize cache_size)
+{
+ if (view->pixbuf_cache_size == cache_size)
+ return;
+
+ view->pixbuf_cache_size = cache_size;
+ if (view->pixbuf_cache)
+ ev_pixbuf_cache_set_max_size (view->pixbuf_cache, cache_size);
+}
+
void
ev_view_set_loading (EvView *view,
gboolean loading)
{
+ if (view->loading && !loading)
+ hide_loading_window (view);
view->loading = loading;
gtk_widget_queue_draw (GTK_WIDGET (view));
}
speed = pow ((((gdouble)view->scroll_info.last_y - view->scroll_info.start_y) / 100), 3);
value = gtk_adjustment_get_value (view->vadjustment);
- value = CLAMP (value + speed, 0, view->vadjustment->upper - view->vadjustment->page_size);
+ value = CLAMP (value + speed, 0,
+ gtk_adjustment_get_upper (view->vadjustment) -
+ gtk_adjustment_get_page_size (view->vadjustment));
gtk_adjustment_set_value (view->vadjustment, value);
return TRUE;
ev_view_handle_cursor_over_xy (view, x, y);
}
-void
-ev_view_set_document (EvView *view,
- EvDocument *document)
+static void
+ev_view_document_changed_cb (EvDocumentModel *model,
+ GParamSpec *pspec,
+ EvView *view)
{
- g_return_if_fail (EV_IS_VIEW (view));
+ EvDocument *document = ev_document_model_get_document (model);
- view->loading = FALSE;
-
if (document != view->document) {
+ gint current_page;
+
clear_caches (view);
if (view->document) {
g_object_unref (view->document);
- view->page_cache = NULL;
}
view->document = document;
view->find_result = 0;
if (view->document) {
+ view->loading = FALSE;
g_object_ref (view->document);
setup_caches (view);
}
- gtk_widget_queue_resize (GTK_WIDGET (view));
+ current_page = ev_document_model_get_page (model);
+ if (view->current_page != current_page) {
+ ev_view_change_page (view, current_page);
+ } else {
+ view->pending_scroll = SCROLL_TO_KEEP_POSITION;
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+ }
}
}
static void
-ev_view_reload_page (EvView *view,
- gint page,
- GdkRegion *region)
+ev_view_rotation_changed_cb (EvDocumentModel *model,
+ GParamSpec *pspec,
+ EvView *view)
{
- ev_pixbuf_cache_reload_page (view->pixbuf_cache,
- region,
- page,
- view->rotation,
- view->scale);
-}
+ gint rotation = ev_document_model_get_rotation (model);
-void
-ev_view_reload (EvView *view)
-{
- ev_pixbuf_cache_clear (view->pixbuf_cache);
- view_update_range_and_current_page (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,
- view->sizing_mode == EV_SIZING_FREE ? view->min_scale : 0,
- view->max_scale);
-
- if (scale == view->scale)
- return;
-
- if (ABS (view->scale - scale) < EPSILON)
- return;
+ view->rotation = rotation;
- if (view->loading_text) {
- cairo_surface_destroy (view->loading_text);
- view->loading_text = NULL;
+ if (view->pixbuf_cache) {
+ ev_pixbuf_cache_clear (view->pixbuf_cache);
+ if (!ev_document_is_page_size_uniform (view->document))
+ view->pending_scroll = SCROLL_TO_PAGE_POSITION;
+ gtk_widget_queue_resize (GTK_WIDGET (view));
}
- view->scale = scale;
- view->pending_resize = TRUE;
-
- gtk_widget_queue_resize (GTK_WIDGET (view));
-
- g_object_notify (G_OBJECT (view), "zoom");
-}
+ ev_view_remove_all (view);
-double
-ev_view_get_zoom (EvView *view)
-{
- return view->scale;
+ if (rotation != 0)
+ clear_selection (view);
}
-void
-ev_view_set_screen_dpi (EvView *view,
- gdouble dpi)
+static void
+ev_view_inverted_colors_changed_cb (EvDocumentModel *model,
+ GParamSpec *pspec,
+ EvView *view)
{
- g_return_if_fail (EV_IS_VIEW (view));
- g_return_if_fail (dpi > 0);
+ if (view->pixbuf_cache) {
+ gboolean inverted_colors;
- view->dpi = dpi;
- view->min_scale = MIN_SCALE * dpi / 72.0;
- view->max_scale = MAX_SCALE * dpi / 72.0;
+ inverted_colors = ev_document_model_get_inverted_colors (model);
+ ev_pixbuf_cache_set_inverted_colors (view->pixbuf_cache, inverted_colors);
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+ }
}
-gboolean
-ev_view_get_continuous (EvView *view)
+static void
+ev_view_sizing_mode_changed_cb (EvDocumentModel *model,
+ GParamSpec *pspec,
+ EvView *view)
{
- g_return_val_if_fail (EV_IS_VIEW (view), FALSE);
+ EvSizingMode mode = ev_document_model_get_sizing_mode (model);
- return view->continuous;
+ view->sizing_mode = mode;
+ if (mode != EV_SIZING_FREE)
+ gtk_widget_queue_resize (GTK_WIDGET (view));
}
-void
-ev_view_set_continuous (EvView *view,
- gboolean continuous)
+#define EPSILON 0.0000001
+static void
+ev_view_scale_changed_cb (EvDocumentModel *model,
+ GParamSpec *pspec,
+ EvView *view)
{
- g_return_if_fail (EV_IS_VIEW (view));
+ gdouble scale = ev_document_model_get_scale (model);
- continuous = continuous != FALSE;
+ if (ABS (view->scale - scale) < EPSILON)
+ return;
- if (view->continuous != continuous) {
- view->continuous = continuous;
- view->pending_scroll = SCROLL_TO_PAGE_POSITION;
- gtk_widget_queue_resize (GTK_WIDGET (view));
- }
+ view->scale = scale;
- g_object_notify (G_OBJECT (view), "continuous");
+ view->pending_resize = TRUE;
+ if (view->sizing_mode == EV_SIZING_FREE)
+ gtk_widget_queue_resize (GTK_WIDGET (view));
}
-gboolean
-ev_view_get_dual_page (EvView *view)
+static void
+ev_view_continuous_changed_cb (EvDocumentModel *model,
+ GParamSpec *pspec,
+ EvView *view)
{
- g_return_val_if_fail (EV_IS_VIEW (view), FALSE);
+ gboolean continuous = ev_document_model_get_continuous (model);
- return view->dual_page;
+ view->continuous = continuous;
+ view->pending_scroll = SCROLL_TO_PAGE_POSITION;
+ gtk_widget_queue_resize (GTK_WIDGET (view));
}
-void
-ev_view_set_dual_page (EvView *view,
- gboolean dual_page)
+static void
+ev_view_dual_page_changed_cb (EvDocumentModel *model,
+ GParamSpec *pspec,
+ EvView *view)
{
- g_return_if_fail (EV_IS_VIEW (view));
-
- dual_page = dual_page != FALSE;
+ gboolean dual_page = ev_document_model_get_dual_page (model);
- if (view->dual_page == dual_page)
- return;
-
- view->pending_scroll = SCROLL_TO_PAGE_POSITION;
view->dual_page = dual_page;
+ view->pending_scroll = SCROLL_TO_PAGE_POSITION;
/* 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)
+static void
+ev_view_fullscreen_changed_cb (EvDocumentModel *model,
+ GParamSpec *pspec,
+ EvView *view)
{
- g_return_if_fail (EV_IS_VIEW (view));
+ gboolean fullscreen = ev_document_model_get_fullscreen (model);
- fullscreen = fullscreen != FALSE;
-
- if (view->fullscreen == fullscreen)
- return;
-
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)
+ev_view_set_model (EvView *view,
+ EvDocumentModel *model)
{
g_return_if_fail (EV_IS_VIEW (view));
+ g_return_if_fail (EV_IS_DOCUMENT_MODEL (model));
- presentation = presentation != FALSE;
-
- if (view->presentation == presentation)
+ if (model == view->model)
return;
- if (!presentation)
- view->presentation_state = EV_PRESENTATION_NORMAL;
-
- view->presentation = presentation;
- view->pending_scroll = SCROLL_TO_PAGE_POSITION;
-
- if (presentation) {
- view->sizing_mode_saved = view->sizing_mode;
- view->scale_saved = view->scale;
- ev_view_set_sizing_mode (view, EV_SIZING_BEST_FIT);
- } else {
- ev_view_set_sizing_mode (view, view->sizing_mode_saved);
- ev_view_set_zoom (view, view->scale_saved, FALSE);
- }
-
- gtk_widget_queue_resize (GTK_WIDGET (view));
-
- if (presentation)
- ev_view_presentation_transition_start (view);
- else {
- ev_view_presentation_transition_stop (view);
-
- if (view->animation) {
- /* stop any running animation */
- ev_view_transition_animation_cancel (view->animation, view);
- }
- }
-
- if (GTK_WIDGET_REALIZED (view)) {
- if (view->presentation)
- gdk_window_set_background (view->layout.bin_window,
- >K_WIDGET (view)->style->black);
- else
- gdk_window_set_background (view->layout.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;
-}
-
-static gboolean
-transition_next_page (EvView *view)
-{
- ev_view_next_page (view);
-
- return FALSE;
-}
-
-static void
-ev_view_presentation_transition_stop (EvView *view)
-{
- if (view->trans_timeout_id > 0)
- g_source_remove (view->trans_timeout_id);
- view->trans_timeout_id = 0;
+ if (view->model) {
+ g_signal_handlers_disconnect_by_func (view->model,
+ ev_view_document_changed_cb,
+ view);
+ g_signal_handlers_disconnect_by_func (view->model,
+ ev_view_page_changed_cb,
+ view);
+ g_object_unref (view->model);
+ }
+ view->model = g_object_ref (model);
+
+ /* Initialize view from model */
+ view->rotation = ev_document_model_get_rotation (view->model);
+ view->sizing_mode = ev_document_model_get_sizing_mode (view->model);
+ view->scale = ev_document_model_get_scale (view->model);
+ view->continuous = ev_document_model_get_continuous (view->model);
+ view->dual_page = ev_document_model_get_dual_page (view->model);
+ view->fullscreen = ev_document_model_get_fullscreen (view->model);
+ ev_view_document_changed_cb (view->model, NULL, view);
+
+ g_signal_connect (view->model, "notify::document",
+ G_CALLBACK (ev_view_document_changed_cb),
+ view);
+ g_signal_connect (view->model, "notify::rotation",
+ G_CALLBACK (ev_view_rotation_changed_cb),
+ view);
+ g_signal_connect (view->model, "notify::inverted-colors",
+ G_CALLBACK (ev_view_inverted_colors_changed_cb),
+ view);
+ g_signal_connect (view->model, "notify::sizing-mode",
+ G_CALLBACK (ev_view_sizing_mode_changed_cb),
+ view);
+ g_signal_connect (view->model, "notify::scale",
+ G_CALLBACK (ev_view_scale_changed_cb),
+ view);
+ g_signal_connect (view->model, "notify::continuous",
+ G_CALLBACK (ev_view_continuous_changed_cb),
+ view);
+ g_signal_connect (view->model, "notify::dual-page",
+ G_CALLBACK (ev_view_dual_page_changed_cb),
+ view);
+ g_signal_connect (view->model, "notify::fullscreen",
+ G_CALLBACK (ev_view_fullscreen_changed_cb),
+ view);
+ g_signal_connect (view->model, "page-changed",
+ G_CALLBACK (ev_view_page_changed_cb),
+ view);
}
static void
-ev_view_presentation_transition_start (EvView *view)
+ev_view_reload_page (EvView *view,
+ gint page,
+ cairo_region_t *region)
{
- gdouble duration;
-
- if (!EV_IS_DOCUMENT_TRANSITION (view->document))
- return;
-
- ev_view_presentation_transition_stop (view);
-
- duration = ev_document_transition_get_page_duration (EV_DOCUMENT_TRANSITION (view->document),
- view->current_page);
- if (duration > 0) {
- view->trans_timeout_id =
- g_timeout_add_seconds (duration,
- (GSourceFunc) transition_next_page,
- view);
- }
+ ev_pixbuf_cache_reload_page (view->pixbuf_cache,
+ region,
+ page,
+ view->rotation,
+ view->scale);
}
void
-ev_view_set_sizing_mode (EvView *view,
- EvSizingMode sizing_mode)
+ev_view_reload (EvView *view)
{
- 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");
+ ev_pixbuf_cache_clear (view->pixbuf_cache);
+ view_update_range_and_current_page (view);
}
-EvSizingMode
-ev_view_get_sizing_mode (EvView *view)
-{
- g_return_val_if_fail (EV_IS_VIEW (view), EV_SIZING_FREE);
-
- return view->sizing_mode;
-}
+/*** Zoom and sizing mode ***/
gboolean
ev_view_can_zoom_in (EvView *view)
{
- return view->scale * ZOOM_IN_FACTOR <= view->max_scale;
+ return view->scale * ZOOM_IN_FACTOR <= ev_document_model_get_max_scale (view->model);
}
gboolean
ev_view_can_zoom_out (EvView *view)
{
- return view->scale * ZOOM_OUT_FACTOR >= view->min_scale;
+ return view->scale * ZOOM_OUT_FACTOR >= ev_document_model_get_min_scale (view->model);
}
void
ev_view_zoom_in (EvView *view)
{
+ gdouble scale;
+
g_return_if_fail (view->sizing_mode == EV_SIZING_FREE);
- if (view->presentation)
- return;
-
view->pending_scroll = SCROLL_TO_CENTER;
- ev_view_set_zoom (view, ZOOM_IN_FACTOR, TRUE);
+ scale = ev_document_model_get_scale (view->model) * ZOOM_IN_FACTOR;
+ ev_document_model_set_scale (view->model, scale);
}
void
ev_view_zoom_out (EvView *view)
{
+ gdouble scale;
+
g_return_if_fail (view->sizing_mode == EV_SIZING_FREE);
- if (view->presentation)
- return;
-
view->pending_scroll = SCROLL_TO_CENTER;
- ev_view_set_zoom (view, ZOOM_OUT_FACTOR, TRUE);
-}
-
-void
-ev_view_rotate_right (EvView *view)
-{
- int rotation = view->rotation + 90;
-
- if (rotation >= 360) {
- rotation -= 360;
- }
-
- ev_view_set_rotation (view, rotation);
-}
-
-void
-ev_view_rotate_left (EvView *view)
-{
- int rotation = view->rotation - 90;
-
- if (rotation < 0) {
- rotation += 360;
- }
-
- ev_view_set_rotation (view, rotation);
-}
-
-void
-ev_view_set_rotation (EvView *view, int rotation)
-{
- view->rotation = rotation;
-
- if (view->pixbuf_cache) {
- ev_pixbuf_cache_clear (view->pixbuf_cache);
- gtk_widget_queue_resize (GTK_WIDGET (view));
- }
-
- if (rotation != 0)
- clear_selection (view);
-
- g_object_notify (G_OBJECT (view), "rotation");
-}
-
-int
-ev_view_get_rotation (EvView *view)
-{
- return view->rotation;
+ scale = ev_document_model_get_scale (view->model) * ZOOM_OUT_FACTOR;
+ ev_document_model_set_scale (view->model, scale);
}
static double
-zoom_for_size_fit_width (int doc_width,
- int doc_height,
- int target_width,
- int target_height,
- int vsb_width)
+zoom_for_size_fit_width (gdouble doc_width,
+ gdouble doc_height,
+ int target_width,
+ int target_height)
{
- double scale;
-
- scale = (double)target_width / doc_width;
-
- if (doc_height * scale > target_height)
- scale = (double) (target_width - vsb_width) / doc_width;
-
- return scale;
+ return (double)target_width / doc_width;
}
static double
-zoom_for_size_fit_height (int doc_width,
- int doc_height,
- int target_width,
- int target_height,
- int vsb_height)
+zoom_for_size_fit_height (gdouble doc_width,
+ gdouble doc_height,
+ int target_width,
+ int target_height)
{
- double scale;
-
- scale = (double)target_height / doc_height;
-
- if (doc_width * scale > target_width)
- scale = (double) (target_height - vsb_height) / doc_height;
-
- return scale;
+ return (double)target_height / doc_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)
+zoom_for_size_best_fit (gdouble doc_width,
+ gdouble doc_height,
+ int target_width,
+ int target_height)
{
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,
- view->rotation,
- 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 width,
+ int height)
{
- int doc_width, doc_height;
+ gdouble doc_width, doc_height;
GtkBorder border;
gdouble scale;
+ gint sb_size;
+
+ ev_document_get_max_page_size (view->document, &doc_width, &doc_height);
+ if (view->rotation == 90 || view->rotation == 270) {
+ gdouble tmp;
+
+ tmp = doc_width;
+ doc_width = doc_height;
+ doc_height = tmp;
+ }
- ev_page_cache_get_max_width (view->page_cache,
- view->rotation,
- 1.0,
- &doc_width);
- ev_page_cache_get_max_height (view->page_cache,
- view->rotation,
- 1.0,
- &doc_height);
compute_border (view, doc_width, doc_height, &border);
- doc_width = doc_width * 2;
+ 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);
+ sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
+ } else if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ scale = zoom_for_size_best_fit (doc_width, doc_height, width - sb_size, height);
else
g_assert_not_reached ();
- ev_view_set_zoom (view, scale, FALSE);
+ ev_document_model_set_scale (view->model, scale);
}
static void
ev_view_zoom_for_size_continuous (EvView *view,
int width,
- int height,
- int vsb_width,
- int hsb_height)
+ int height)
{
- int doc_width, doc_height;
+ gdouble doc_width, doc_height;
GtkBorder border;
gdouble scale;
+ gint sb_size;
+
+ ev_document_get_max_page_size (view->document, &doc_width, &doc_height);
+ if (view->rotation == 90 || view->rotation == 270) {
+ gdouble tmp;
+
+ tmp = doc_width;
+ doc_width = doc_height;
+ doc_height = tmp;
+ }
- ev_page_cache_get_max_width (view->page_cache,
- view->rotation,
- 1.0,
- &doc_width);
- ev_page_cache_get_max_height (view->page_cache,
- view->rotation,
- 1.0,
- &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);
+ sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
+ } else if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ scale = zoom_for_size_best_fit (doc_width, doc_height, width - sb_size, height);
else
g_assert_not_reached ();
- ev_view_set_zoom (view, scale, FALSE);
+ ev_document_model_set_scale (view->model, scale);
}
static void
ev_view_zoom_for_size_dual_page (EvView *view,
int width,
- int height,
- int vsb_width,
- int hsb_height)
+ int height)
{
GtkBorder border;
- gint doc_width, doc_height;
+ gdouble 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,
- view->rotation,
- 1.0,
- &doc_width, &doc_height);
+ get_doc_page_size (view, view->current_page, &doc_width, &doc_height);
+ if (other_page < ev_document_get_n_pages (view->document)) {
+ gdouble width_2, height_2;
- 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,
- view->rotation,
- 1.0,
- &width_2, &height_2);
+ get_doc_page_size (view, other_page, &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);
+ compute_border (view, width, 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);
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ gint sb_size;
+
+ sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
+ scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
+ } else if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ scale = zoom_for_size_best_fit (doc_width, doc_height, width, height);
else
g_assert_not_reached ();
- ev_view_set_zoom (view, scale, FALSE);
+ ev_document_model_set_scale (view->model, scale);
}
static void
ev_view_zoom_for_size_single_page (EvView *view,
int width,
- int height,
- int vsb_width,
- int hsb_height)
+ int height)
{
- int doc_width, doc_height;
+ gdouble doc_width, doc_height;
GtkBorder border;
gdouble scale;
- ev_page_cache_get_size (view->page_cache,
- view->current_page,
- view->rotation,
- 1.0,
- &doc_width,
- &doc_height);
+ get_doc_page_size (view, view->current_page, &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);
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ gint sb_size;
+
+ sb_size = ev_view_get_scrollbar_size (view, GTK_ORIENTATION_VERTICAL);
+ scale = zoom_for_size_fit_width (doc_width, doc_height, width - sb_size, height);
+ } else if (view->sizing_mode == EV_SIZING_BEST_FIT)
+ scale = zoom_for_size_best_fit (doc_width, doc_height, width, height);
else
g_assert_not_reached ();
- ev_view_set_zoom (view, scale, FALSE);
+ ev_document_model_set_scale (view->model, scale);
}
-void
-ev_view_set_zoom_for_size (EvView *view,
- int width,
- int height,
- int vsb_width,
- int hsb_height)
+static void
+ev_view_zoom_for_size (EvView *view,
+ int width,
+ int height)
{
g_return_if_fail (EV_IS_VIEW (view));
g_return_if_fail (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
if (view->document == NULL)
return;
- 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);
+ if (view->continuous && view->dual_page)
+ ev_view_zoom_for_size_continuous_and_dual_page (view, width, height);
else if (view->continuous)
- ev_view_zoom_for_size_continuous (view, width, height, vsb_width, hsb_height);
+ ev_view_zoom_for_size_continuous (view, width, height);
else if (view->dual_page)
- ev_view_zoom_for_size_dual_page (view, width, height, vsb_width, hsb_height);
+ ev_view_zoom_for_size_dual_page (view, width, height);
else
- ev_view_zoom_for_size_single_page (view, width, height, vsb_width, hsb_height);
+ ev_view_zoom_for_size_single_page (view, width, height);
}
/*** Find ***/
{
int n_pages, i;
- n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ n_pages = ev_document_get_n_pages (view->document);
for (i = 0; i < n_pages; i++) {
int page;
page = page + n_pages;
if (ev_view_find_get_n_results (view, page) > 0) {
- ev_page_cache_set_current_page (view->page_cache, page);
+ ev_document_model_set_page (view->model, page);
break;
}
}
view->find_pages = NULL;
}
+/*** Synctex ***/
+void
+ev_view_highlight_forward_search (EvView *view,
+ EvSourceLink *link)
+{
+ EvMapping *mapping;
+ gint page;
+ GdkRectangle view_rect;
+
+ if (!ev_document_has_synctex (view->document))
+ return;
+
+ mapping = ev_document_synctex_forward_search (view->document, link);
+ if (!mapping)
+ return;
+
+ if (view->synctex_result)
+ g_free (view->synctex_result);
+ view->synctex_result = mapping;
+
+ page = GPOINTER_TO_INT (mapping->data);
+ ev_document_model_set_page (view->model, page);
+
+ doc_rect_to_view_rect (view, page, &mapping->area, &view_rect);
+ ensure_rectangle_is_visible (view, &view_rect);
+ gtk_widget_queue_draw (GTK_WIDGET (view));
+}
+
/*** Selections ***/
/* compute_new_selection_rect/text calculates the area currently selected by
view_rect.width = MAX (start->x, stop->x) - view_rect.x;
view_rect.width = MAX (start->y, stop->y) - view_rect.y;
- n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ n_pages = ev_document_get_n_pages (view->document);
for (i = 0; i < n_pages; i++) {
GdkRectangle page_area;
GtkBorder border;
- if (get_page_extents (view, i, &page_area, &border)) {
+ if (ev_view_get_page_extents (view, i, &page_area, &border)) {
GdkRectangle overlap;
if (gdk_rectangle_intersect (&page_area, &view_rect, &overlap)) {
int n_pages, i, first, last;
GList *list = NULL;
EvViewSelection *selection;
- gint width, height;
+ gdouble width, height;
int start_page, end_page;
g_assert (view->selection_mode == EV_VIEW_SELECTION_TEXT);
- n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ n_pages = ev_document_get_n_pages (view->document);
/* First figure out the range of pages the selection
* affects. */
GdkRectangle page_area;
GtkBorder border;
- get_page_extents (view, i, &page_area, &border);
+ ev_view_get_page_extents (view, i, &page_area, &border);
if (gdk_rectangle_point_in (&page_area, start) ||
gdk_rectangle_point_in (&page_area, stop)) {
if (first == n_pages)
GtkBorder border;
GdkPoint *point;
- ev_page_cache_get_size (view->page_cache, i,
- view->rotation,
- 1.0, &width, &height);
+ get_doc_page_size (view, i, &width, &height);
selection = g_new0 (EvViewSelection, 1);
selection->page = i;
selection->rect.x2 = width;
selection->rect.y2 = height;
- get_page_extents (view, i, &page_area, &border);
+ ev_view_get_page_extents (view, i, &page_area, &border);
if (gdk_rectangle_point_in (&page_area, start))
point = start;
g_list_free (view->selection_info.selections);
view->selection_info.selections = new_list;
ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, new_list);
- g_object_notify (G_OBJECT (view), "has-selection");
+ g_signal_emit (view, signals[SIGNAL_SELECTION_CHANGED], 0, NULL);
new_list_ptr = new_list;
old_list_ptr = old_list;
while (new_list_ptr || old_list_ptr) {
EvViewSelection *old_sel, *new_sel;
int cur_page;
- GdkRegion *region = NULL;
+ cairo_region_t *region = NULL;
new_sel = (new_list_ptr) ? (new_list_ptr->data) : NULL;
old_sel = (old_list_ptr) ? (old_list_ptr->data) : NULL;
/* seed the cache with a new page. We are going to need the new
* region too. */
if (new_sel) {
- GdkRegion *tmp_region = NULL;
+ cairo_region_t *tmp_region = NULL;
ev_pixbuf_cache_get_selection_surface (view->pixbuf_cache,
cur_page,
view->scale,
&tmp_region);
- if (tmp_region) {
- new_sel->covered_region = gdk_region_copy (tmp_region);
+ if (tmp_region && !cairo_region_is_empty (tmp_region)) {
+ new_sel->covered_region = cairo_region_reference (tmp_region);
}
}
/* We only want to redraw the areas that have
* changed, so we xor the old and new regions
* and redraw if it's different */
- region = gdk_region_copy (old_sel->covered_region);
- gdk_region_xor (region, new_sel->covered_region);
- if (gdk_region_empty (region)) {
- gdk_region_destroy (region);
+ region = cairo_region_copy (old_sel->covered_region);
+#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 9, 12)
+ cairo_region_xor (region, new_sel->covered_region);
+#else
+ cairo_region_t *tbr;
+ tbr = cairo_region_copy (new_sel->covered_region);
+
+ /* xor old_sel, new_sel*/
+ cairo_region_subtract (tbr, region);
+ cairo_region_subtract (region, new_sel->covered_region);
+ cairo_region_union (region, tbr);
+ cairo_region_destroy (tbr);
+#endif
+
+ if (cairo_region_is_empty (region)) {
+ cairo_region_destroy (region);
region = NULL;
+ } else {
+ gint num_rectangles = cairo_region_num_rectangles (region);
+ GdkRectangle r;
+
+ /* We need to make the damage region a little bigger
+ * because the edges of the old selection might change
+ */
+ cairo_region_get_rectangle (region, 0, &r);
+ r.x -= 5;
+ r.width = 5;
+ cairo_region_union_rectangle (region, &r);
+
+ cairo_region_get_rectangle (region, num_rectangles - 1, &r);
+ r.x += r.width;
+ r.width = 5;
+ cairo_region_union_rectangle (region, &r);
}
} else if (old_sel->covered_region) {
- region = gdk_region_copy (old_sel->covered_region);
+ region = cairo_region_copy (old_sel->covered_region);
} else if (new_sel->covered_region) {
- region = gdk_region_copy (new_sel->covered_region);
+ region = cairo_region_copy (new_sel->covered_region);
}
} else if (old_sel && !new_sel) {
- if (old_sel->covered_region && !gdk_region_empty (old_sel->covered_region)) {
- region = gdk_region_copy (old_sel->covered_region);
+ if (old_sel->covered_region && !cairo_region_is_empty (old_sel->covered_region)) {
+ region = cairo_region_copy (old_sel->covered_region);
}
} else if (!old_sel && new_sel) {
- if (new_sel->covered_region && !gdk_region_empty (new_sel->covered_region)) {
- region = gdk_region_copy (new_sel->covered_region);
+ if (new_sel->covered_region && !cairo_region_is_empty (new_sel->covered_region)) {
+ region = cairo_region_copy (new_sel->covered_region);
}
} else {
g_assert_not_reached ();
/* Redraw the damaged region! */
if (region) {
+ GdkWindow *bin_window;
GdkRectangle page_area;
- GtkBorder border;
-
- /* I don't know why but the region is smaller
- * than expected. This hack fixes it, I guess
- * 10 pixels more won't hurt
- */
- gdk_region_shrink (region, -5, -5);
+ GtkBorder border;
- get_page_extents (view, cur_page, &page_area, &border);
- gdk_region_offset (region,
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+ ev_view_get_page_extents (view, cur_page, &page_area, &border);
+ cairo_region_translate (region,
page_area.x + border.left - view->scroll_x,
page_area.y + border.top - view->scroll_y);
- gdk_window_invalidate_region (view->layout.bin_window, region, TRUE);
- gdk_region_destroy (region);
+#if GTK_CHECK_VERSION(2, 90, 5)
+ gdk_window_invalidate_region (bin_window, region, TRUE);
+#else
+ {
+ GdkRegion *gdk_region = gdk_region_new ();
+ guint n_recs = cairo_region_num_rectangles (region);
+ guint i;
+
+ for (i = 0; i < n_recs; i++) {
+ cairo_rectangle_int_t rect;
+
+ cairo_region_get_rectangle (region, i, &rect);
+ gdk_region_union_with_rect (gdk_region, (GdkRectangle *)&rect);
+ }
+ gdk_window_invalidate_region (bin_window, gdk_region, TRUE);
+ gdk_region_destroy (gdk_region);
+ }
+#endif
+ cairo_region_destroy (region);
}
}
selection_free (EvViewSelection *selection)
{
if (selection->covered_region)
- gdk_region_destroy (selection->covered_region);
+ cairo_region_destroy (selection->covered_region);
g_free (selection);
}
static void
clear_selection (EvView *view)
{
- g_list_foreach (view->selection_info.selections, (GFunc)selection_free, NULL);
- g_list_free (view->selection_info.selections);
- view->selection_info.selections = NULL;
+ if (view->selection_info.selections) {
+ g_list_foreach (view->selection_info.selections, (GFunc)selection_free, NULL);
+ g_list_free (view->selection_info.selections);
+ view->selection_info.selections = NULL;
+
+ g_signal_emit (view, signals[SIGNAL_SELECTION_CHANGED], 0, NULL);
+ }
view->selection_info.in_selection = FALSE;
if (view->pixbuf_cache)
ev_pixbuf_cache_set_selection_list (view->pixbuf_cache, NULL);
- g_object_notify (G_OBJECT (view), "has-selection");
}
void
clear_selection (view);
- n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ n_pages = ev_document_get_n_pages (view->document);
for (i = 0; i < n_pages; i++) {
- int width, height;
+ gdouble width, height;
EvViewSelection *selection;
- ev_page_cache_get_size (view->page_cache,
- i,
- view->rotation,
- 1.0, &width, &height);
+ get_doc_page_size (view, i, &width, &height);
selection = g_new0 (EvViewSelection, 1);
selection->page = i;
GString *text;
GList *l;
gchar *normalized_text;
- EvRenderContext *rc;
text = g_string_new (NULL);
- rc = ev_render_context_new (NULL, view->rotation, view->scale);
ev_document_doc_mutex_lock ();
gchar *tmp;
page = ev_document_get_page (view->document, selection->page);
- ev_render_context_set_page (rc, page);
- g_object_unref (page);
-
tmp = ev_selection_get_selected_text (EV_SELECTION (view->document),
- rc, selection->style,
+ page, selection->style,
&(selection->rect));
-
+ g_object_unref (page);
g_string_append (text, tmp);
g_free (tmp);
}
- g_object_unref (rc);
-
ev_document_doc_mutex_unlock ();
normalized_text = g_utf8_normalize (text->str, text->len, G_NORMALIZE_NFKC);
}
/*** Cursor operations ***/
-
-static GdkCursor *
-ev_view_create_invisible_cursor(void)
-{
- GdkBitmap *empty;
- GdkColor black = { 0, 0, 0, 0 };
- static char bits[] = { 0x00 };
-
- empty = gdk_bitmap_create_from_data (NULL, bits, 1, 1);
-
- return gdk_cursor_new_from_pixmap (empty, empty, &black, &black, 0, 0);
-}
-
static void
ev_view_set_cursor (EvView *view, EvViewCursor new_cursor)
{
GdkCursor *cursor = NULL;
- GdkDisplay *display;
GtkWidget *widget;
+ GdkWindow *bin_window;
if (view->cursor == new_cursor) {
return;
}
- widget = gtk_widget_get_toplevel (GTK_WIDGET (view));
- display = gtk_widget_get_display (widget);
view->cursor = new_cursor;
- switch (new_cursor) {
- case EV_VIEW_CURSOR_NORMAL:
- gdk_window_set_cursor (view->layout.bin_window, NULL);
- break;
- case EV_VIEW_CURSOR_IBEAM:
- cursor = gdk_cursor_new_for_display (display, GDK_XTERM);
- break;
- case EV_VIEW_CURSOR_LINK:
- cursor = gdk_cursor_new_for_display (display, GDK_HAND2);
- break;
- case EV_VIEW_CURSOR_WAIT:
- cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
- break;
- case EV_VIEW_CURSOR_HIDDEN:
- cursor = ev_view_create_invisible_cursor ();
- break;
- case EV_VIEW_CURSOR_DRAG:
- cursor = gdk_cursor_new_for_display (display, GDK_FLEUR);
- break;
- case EV_VIEW_CURSOR_AUTOSCROLL:
- cursor = gdk_cursor_new_for_display (display, GDK_DOUBLE_ARROW);
- break;
- }
-
- if (cursor) {
- gdk_window_set_cursor (view->layout.bin_window, cursor);
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+ widget = gtk_widget_get_toplevel (GTK_WIDGET (view));
+ cursor = ev_view_cursor_new (gtk_widget_get_display (widget), new_cursor);
+ gdk_window_set_cursor (bin_window, cursor);
+ gdk_flush ();
+ if (cursor)
gdk_cursor_unref (cursor);
- gdk_flush();
- }
}
void
ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
}
-static void
-ev_view_reset_presentation_state (EvView *view)
-{
- if (!view->presentation ||
- view->presentation_state == EV_PRESENTATION_NORMAL)
- return;
-
- view->presentation_state = EV_PRESENTATION_NORMAL;
- gdk_window_set_background (view->layout.bin_window,
- >K_WIDGET (view)->style->black);
- gtk_widget_queue_draw (GTK_WIDGET (view));
-}
-
gboolean
ev_view_next_page (EvView *view)
{
g_return_val_if_fail (EV_IS_VIEW (view), FALSE);
- if (!view->page_cache)
+ if (!view->document)
return FALSE;
- if (view->presentation &&
- (view->presentation_state == EV_PRESENTATION_BLACK ||
- view->presentation_state == EV_PRESENTATION_WHITE)) {
- ev_view_reset_presentation_state (view);
- return FALSE;
- }
-
- if (view->animation) {
- ev_view_transition_animation_cancel (view->animation, view);
- }
-
- ev_view_presentation_transition_stop (view);
- ev_view_reset_presentation_state (view);
-
- page = ev_page_cache_get_current_page (view->page_cache);
- n_pages = ev_page_cache_get_n_pages (view->page_cache);
+ page = ev_document_model_get_page (view->model);
+ n_pages = ev_document_get_n_pages (view->document);
- if (view->dual_page && !view->presentation)
+ if (view->dual_page)
page = page + 2;
else
page = page + 1;
if (page < n_pages) {
- ev_page_cache_set_current_page (view->page_cache, page);
- return TRUE;
- } else if (view->presentation && page == n_pages) {
- view->presentation_state = EV_PRESENTATION_END;
- gtk_widget_queue_draw (GTK_WIDGET (view));
+ ev_document_model_set_page (view->model, page);
return TRUE;
} else if (view->dual_page && page == n_pages) {
- ev_page_cache_set_current_page (view->page_cache, page - 1);
+ ev_document_model_set_page (view->model, page - 1);
return TRUE;
} else {
return FALSE;
g_return_val_if_fail (EV_IS_VIEW (view), FALSE);
- if (!view->page_cache)
+ if (!view->document)
return FALSE;
- if (view->presentation &&
- view->presentation_state == EV_PRESENTATION_END) {
- ev_view_reset_presentation_state (view);
- return TRUE;
- }
-
- if (view->presentation &&
- (view->presentation_state == EV_PRESENTATION_BLACK ||
- view->presentation_state == EV_PRESENTATION_WHITE)) {
- ev_view_reset_presentation_state (view);
- return FALSE;
- }
-
- if (view->animation) {
- ev_view_transition_animation_cancel (view->animation, view);
- }
-
- ev_view_reset_presentation_state (view);
-
- page = ev_page_cache_get_current_page (view->page_cache);
+ page = ev_document_model_get_page (view->model);
- if (view->dual_page && !view->presentation)
+ if (view->dual_page)
page = page - 2;
else
page = page - 1;
if (page >= 0) {
- ev_page_cache_set_current_page (view->page_cache, page);
+ ev_document_model_set_page (view->model, page);
return TRUE;
- } else if (ev_view_get_dual_page (view) && page == -1) {
- ev_page_cache_set_current_page (view->page_cache, 0);
+ } else if (view->dual_page && page == -1) {
+ ev_document_model_set_page (view->model, 0);
return TRUE;
} else {
return FALSE;