* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
+#include <math.h>
#include <gtk/gtkalignment.h>
#include <glib/gi18n.h>
#include <gtk/gtkbindings.h>
TARGET_TEXT_BUFFER_CONTENTS
};
+enum {
+ EV_SCROLL_PAGE_FORWARD,
+ EV_SCROLL_PAGE_BACKWARD
+};
+
static const GtkTargetEntry targets[] = {
{ "STRING", 0, TARGET_STRING },
{ "TEXT", 0, TARGET_TEXT },
GtkWidget parent_instance;
EvDocument *document;
-
+
GdkWindow *bin_window;
char *status;
char *find_status;
-
+
int scroll_x;
int scroll_y;
gboolean pressed_button;
gboolean has_selection;
GdkPoint selection_start;
- GdkRectangle selection;
+ EvRectangle selection;
EvViewCursor cursor;
GtkAdjustment *hadjustment;
void (*scroll_view) (EvView *view,
GtkScrollType scroll,
gboolean horizontal);
-
+
};
static void ev_view_set_scroll_adjustments (EvView *view,
GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment);
-
+
G_DEFINE_TYPE (EvView, ev_view, GTK_TYPE_WIDGET)
-/*** Helper functions ***/
-
+/*** Helper functions ***/
+
static void
view_update_adjustments (EvView *view)
{
int old_x = view->scroll_x;
int old_y = view->scroll_y;
-
+
if (view->hadjustment)
view->scroll_x = view->hadjustment->value;
else
view->scroll_y = view->vadjustment->value;
else
view->scroll_y = 0;
-
+
if (GTK_WIDGET_REALIZED (view) &&
(view->scroll_x != old_x || view->scroll_y != old_y)) {
gdk_window_move (view->bin_window, - view->scroll_x, - view->scroll_y);
if (!adjustment)
return;
-
+
adjustment->page_size = allocation;
adjustment->step_increment = allocation * 0.1;
adjustment->page_increment = allocation * 0.9;
gtk_adjustment_value_changed (adjustment);
}
-/*** Virtual function implementations ***/
-
+/*** Virtual function implementations ***/
+
static void
ev_view_finalize (GObject *object)
{
view->pixbuf_cache = NULL;
}
ev_view_set_scroll_adjustments (view, NULL, NULL);
-
+
GTK_OBJECT_CLASS (ev_view_parent_class)->destroy (object);
}
&width, &height);
ev_document_misc_get_page_border_size (width, height, &border);
-
+
*x_offset = view->spacing;
*y_offset = view->spacing;
target_width = width + border.left + border.right + view->spacing * 2;
}
static void
-view_rect_to_doc_rect (EvView *view, GdkRectangle *view_rect, GdkRectangle *doc_rect)
+view_rect_to_doc_rect (EvView *view, GdkRectangle *view_rect, EvRectangle *doc_rect)
{
int x_offset, y_offset;
- ev_view_get_offsets (view, &x_offset, &y_offset);
- doc_rect->x = (view_rect->x - x_offset) / view->scale;
- doc_rect->y = (view_rect->y - y_offset) / view->scale;
- doc_rect->width = view_rect->width / view->scale;
- doc_rect->height = view_rect->height / view->scale;
+ ev_view_get_offsets (view, &x_offset, &y_offset);
+ doc_rect->x1 = (double) (view_rect->x - x_offset) / view->scale;
+ doc_rect->y1 = (double) (view_rect->y - y_offset) / view->scale;
+ doc_rect->x2 = doc_rect->x1 + (double) view_rect->width / view->scale;
+ doc_rect->y2 = doc_rect->y1 + (double) view_rect->height / view->scale;
}
static void
-doc_rect_to_view_rect (EvView *view, GdkRectangle *doc_rect, GdkRectangle *view_rect)
+doc_rect_to_view_rect (EvView *view, EvRectangle *doc_rect, GdkRectangle *view_rect)
{
int x_offset, y_offset;
- ev_view_get_offsets (view, &x_offset, &y_offset);
- view_rect->x = doc_rect->x * view->scale + x_offset;
- view_rect->y = doc_rect->y * view->scale + y_offset;
- view_rect->width = doc_rect->width * view->scale;
- view_rect->height = doc_rect->height * view->scale;
+ ev_view_get_offsets (view, &x_offset, &y_offset);
+ view_rect->x = floor (doc_rect->x1 * view->scale) + x_offset;
+ view_rect->y = floor (doc_rect->y1 * view->scale) + y_offset;
+ view_rect->width = ceil (doc_rect->x2 * view->scale) + x_offset - view_rect->x;
+ view_rect->height = ceil (doc_rect->y2 * view->scale) + y_offset - view_rect->y;
}
requisition->width = width + border.left + border.right +
view->spacing * 2;
}
-
+
if (view->height >= 0) {
requisition->height = 0;
} else {
GdkWindowAttr attributes;
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
-
+
attributes.window_type = GDK_WINDOW_CHILD;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
attributes.colormap = gtk_widget_get_colormap (widget);
-
+
attributes.x = widget->allocation.x;
attributes.y = widget->allocation.y;
attributes.width = widget->allocation.width;
attributes.height = widget->allocation.height;
attributes.event_mask = 0;
-
+
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes,
GDK_WA_X | GDK_WA_Y |
gdk_window_set_user_data (widget->window, widget);
widget->style = gtk_style_attach (widget->style, widget->window);
gdk_window_set_background (widget->window, &widget->style->mid[widget->state]);
-
+
attributes.x = 0;
attributes.y = 0;
attributes.width = MAX (widget->allocation.width, widget->requisition.width);
GDK_KEY_PRESS_MASK |
GDK_POINTER_MOTION_MASK |
GDK_LEAVE_NOTIFY_MASK;
-
+
view->bin_window = gdk_window_new (widget->window,
&attributes,
GDK_WA_X | GDK_WA_Y |
gdk_draw_pixbuf (window, NULL, pixbuf,
0, 0,
- rect->x,rect->y,
+ rect->x, rect->y,
rect->width, rect->height,
GDK_RGB_DITHER_NONE,
0, 0);
find = EV_DOCUMENT_FIND (view->document);
-#if 0
g_mutex_lock (EV_DOC_MUTEX);
- results = ev_document_find_get_n_results (find);
+ results = ev_document_find_get_n_results (find, view->current_page);
g_mutex_unlock (EV_DOC_MUTEX);
-#endif
-
+
for (i = 0; i < results; i++) {
- GdkRectangle rectangle;
+ EvRectangle rectangle;
+ GdkRectangle view_rectangle;
guchar alpha;
alpha = (i == view->find_result) ? 0x90 : 0x20;
g_mutex_lock (EV_DOC_MUTEX);
- ev_document_find_get_result (find, i, &rectangle);
+ ev_document_find_get_result (find, view->current_page,
+ i, &rectangle);
g_mutex_unlock (EV_DOC_MUTEX);
+ doc_rect_to_view_rect (view, &rectangle, &view_rectangle);
draw_rubberband (GTK_WIDGET (view), view->bin_window,
- &rectangle, alpha);
+ &view_rectangle, alpha);
}
}
if (view->document == NULL)
return;
- ev_view_get_offsets (view, &x_offset, &y_offset);
+ ev_view_get_offsets (view, &x_offset, &y_offset);
ev_page_cache_get_size (view->page_cache,
view->current_page,
view->scale,
&width, &height);
ev_document_misc_get_page_border_size (width, height, &border);
-
+
/* Paint the frame */
area.x = x_offset;
area.y = y_offset;
ev_view_copy (EvView *ev_view)
{
GtkClipboard *clipboard;
- GdkRectangle selection;
char *text;
- doc_rect_to_view_rect (ev_view, &ev_view->selection, &selection);
g_mutex_lock (EV_DOC_MUTEX);
- text = ev_document_get_text (ev_view->document, &selection);
+ text = ev_document_get_text (ev_view->document,
+ ev_view->current_page,
+ &ev_view->selection);
g_mutex_unlock (EV_DOC_MUTEX);
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (ev_view),
gpointer data)
{
EvView *ev_view = EV_VIEW (data);
- GdkRectangle selection;
char *text;
- doc_rect_to_view_rect (ev_view, &ev_view->selection, &selection);
g_mutex_lock (EV_DOC_MUTEX);
- text = ev_document_get_text (ev_view->document, &selection);
+ text = ev_document_get_text (ev_view->document,
+ ev_view->current_page,
+ &ev_view->selection);
g_mutex_unlock (EV_DOC_MUTEX);
gtk_selection_data_set_text (selection_data, text, -1);
}
char *page_label;
type = ev_link_get_link_type (link);
-
+
switch (type) {
case EV_LINK_TYPE_TITLE:
if (ev_link_get_title (link))
ev_view_set_find_status (EvView *view, const char *message)
{
g_return_if_fail (EV_IS_VIEW (view));
-
+
g_free (view->find_status);
view->find_status = g_strdup (message);
g_object_notify (G_OBJECT (view), "find-status");
to_set = &view->hadjustment;
else
to_set = &view->vadjustment;
-
+
if (*to_set != adjustment) {
if (*to_set) {
g_signal_handlers_disconnect_by_func (*to_set,
gboolean horizontal)
{
guint keypad_keyval = keyval - GDK_Left + GDK_KP_Left;
-
+
gtk_binding_entry_add_signal (binding_set, keyval, 0,
"scroll_view", 2,
GTK_TYPE_SCROLL_TYPE, scroll,
G_TYPE_BOOLEAN, horizontal);
}
+static void
+ev_view_jump (EvView *view,
+ GtkScrollType scroll)
+{
+ GtkAdjustment *adjustment;
+ double value, increment;
+ gboolean first_page = FALSE;
+ gboolean last_page = FALSE;
+
+ /* Assign values for increment and vertical adjustment */
+ adjustment = view->vadjustment;
+ increment = adjustment->page_size * 0.75;
+ value = adjustment->value;
+
+ /* Assign boolean for first and last page */
+ if (view->current_page == 0)
+ first_page = TRUE;
+ if (view->current_page == ev_page_cache_get_n_pages (view->page_cache) - 1)
+ last_page = TRUE;
+
+ switch (scroll) {
+ case EV_SCROLL_PAGE_BACKWARD:
+ /* Do not jump backwards if at the first page */
+ if (value == (adjustment->lower) && first_page) {
+ /* Do nothing */
+ /* At the top of a page, assign the upper bound limit of previous page */
+ } else if (value == (adjustment->lower)) {
+ value = adjustment->upper - adjustment->page_size;
+ ev_page_cache_set_current_page (view->page_cache, view->current_page - 1);
+ /* Jump to the top */
+ } else {
+ value = MAX (value - increment, adjustment->lower);
+ }
+ break;
+ case EV_SCROLL_PAGE_FORWARD:
+ /* Do not jump forward if at the last page */
+ if (value == (adjustment->upper - adjustment->page_size) && last_page) {
+ /* Do nothing */
+ /* At the bottom of a page, assign the lower bound limit of next page */
+ } else if (value == (adjustment->upper - adjustment->page_size)) {
+ value = 0;
+ ev_page_cache_set_current_page (view->page_cache, view->current_page + 1);
+ /* Jump to the bottom */
+ } else {
+ value = MIN (value + increment, adjustment->upper - adjustment->page_size);
+ }
+ break;
+ default:
+ break;
+ }
+
+ gtk_adjustment_set_value (adjustment, value);
+}
+
static void
ev_view_scroll_view (EvView *view,
GtkScrollType scroll,
ev_page_cache_prev_page (view->page_cache);
} else if (scroll == GTK_SCROLL_PAGE_FORWARD) {
ev_page_cache_next_page (view->page_cache);
+ } else if (scroll == EV_SCROLL_PAGE_BACKWARD || scroll == EV_SCROLL_PAGE_FORWARD) {
+ ev_view_jump (view, scroll);
} else {
GtkAdjustment *adjustment;
double value;
if (horizontal) {
- adjustment = view->hadjustment;
+ adjustment = view->hadjustment;
} else {
adjustment = view->vadjustment;
}
value = adjustment->value;
switch (scroll) {
- case GTK_SCROLL_STEP_BACKWARD:
- value -= adjustment->step_increment;
+ case GTK_SCROLL_STEP_BACKWARD:
+ value -= adjustment->step_increment;
break;
case GTK_SCROLL_STEP_FORWARD:
- value += adjustment->step_increment;
+ value += adjustment->step_increment;
break;
default:
break;
add_scroll_binding (binding_set, GDK_Page_Up, GTK_SCROLL_PAGE_BACKWARD, FALSE);
add_scroll_binding (binding_set, GDK_Page_Down, GTK_SCROLL_PAGE_FORWARD, FALSE);
+
+ add_scroll_binding (binding_set, GDK_space, EV_SCROLL_PAGE_FORWARD, FALSE);
+ add_scroll_binding (binding_set, GDK_BackSpace, EV_SCROLL_PAGE_BACKWARD, FALSE);
}
static void
char *message;
// g_mutex_lock (EV_DOC_MUTEX);
- if (ev_document_get_page (view->document) == view->find_page) {
+ if (view->current_page == view->find_page) {
int results;
// g_mutex_lock (EV_DOC_MUTEX);
results = ev_document_find_get_n_results
- (EV_DOCUMENT_FIND (view->document));
+ (EV_DOCUMENT_FIND (view->document),
+ view->current_page);
// g_mutex_unlock (EV_DOC_MUTEX);
/* TRANS: Sometimes this could be better translated as
"%d hit(s) on this page". Therefore this string
message = g_strdup_printf (_("%3d%% remaining to search"),
(int) ((1.0 - percent) * 100));
}
-
+
}
// g_mutex_unlock (EV_DOC_MUTEX);
jump_to_find_result (EvView *view)
{
EvDocumentFind *find = EV_DOCUMENT_FIND (view->document);
- GdkRectangle rect;
+ EvRectangle rect;
+ GdkRectangle view_rect;
int n_results;
g_mutex_lock (EV_DOC_MUTEX);
- n_results = ev_document_find_get_n_results (find);
+ n_results = ev_document_find_get_n_results (find, view->current_page);
g_mutex_unlock (EV_DOC_MUTEX);
if (n_results > view->find_result) {
g_mutex_lock (EV_DOC_MUTEX);
ev_document_find_get_result
- (find, view->find_result, &rect);
+ (find, view->current_page, view->find_result, &rect);
g_mutex_unlock (EV_DOC_MUTEX);
- ensure_rectangle_is_visible (view, &rect);
+ doc_rect_to_view_rect (view, &rect, &view_rect);
+ ensure_rectangle_is_visible (view, &view_rect);
}
}
n_pages = ev_page_cache_get_n_pages (view->page_cache);
- for (i = 0; i <= n_pages; i++) {
+ for (i = 0; i < n_pages; i++) {
int has_results;
int page;
page = i + view->find_page;
- if (page > n_pages) {
+ if (page >= n_pages) {
page = page - n_pages;
}
- g_mutex_lock (EV_DOC_MUTEX);
+ // g_mutex_lock (EV_DOC_MUTEX);
has_results = ev_document_find_page_has_results
(EV_DOCUMENT_FIND (view->document), page);
if (has_results == -1) {
jump_to_find_result (view);
update_find_status_message (view);
-#if 0
- /* FIXME: */
- if (ev_document_get_page (document) == page) {
+ if (view->current_page == page)
gtk_widget_queue_draw (GTK_WIDGET (view));
- }
-#endif
}
-/*** Public API ***/
-
+/*** Public API ***/
+
GtkWidget*
ev_view_new (void)
{
gtk_widget_queue_resize (GTK_WIDGET (view));
else
gtk_widget_queue_draw (GTK_WIDGET (view));
-
+
gtk_adjustment_set_value (view->vadjustment,
view->vadjustment->lower);
view);
g_object_unref (view->document);
view->page_cache = NULL;
-
+
}
view->document = document;
- view->find_page = 1;
+ view->find_page = 0;
view->find_result = 0;
if (view->document) {
view->pixbuf_cache = ev_pixbuf_cache_new (view->document);
g_signal_connect (view->pixbuf_cache, "job-finished", G_CALLBACK (job_finished_cb), view);
}
-
+
gtk_widget_queue_resize (GTK_WIDGET (view));
}
}
+int
+ev_view_get_page (EvView *view)
+{
+ return view->current_page;
+}
+
static void
go_to_link (EvView *view, EvLink *link)
{
int page;
type = ev_link_get_link_type (link);
-
+
switch (type) {
case EV_LINK_TYPE_TITLE:
break;
return view->find_status;
}
+gboolean
+ev_view_can_find_next (EvView *view)
+{
+ int n_results = 0;
+
+ if (view->document) {
+ EvDocumentFind *find = EV_DOCUMENT_FIND (view->document);
+
+ g_mutex_lock (EV_DOC_MUTEX);
+ n_results = ev_document_find_get_n_results (find, view->current_page);
+ g_mutex_unlock (EV_DOC_MUTEX);
+ }
+
+ return n_results > 0;
+}
+
void
ev_view_find_next (EvView *view)
{
page_cache = ev_document_get_page_cache (view->document);
g_mutex_lock (EV_DOC_MUTEX);
- n_results = ev_document_find_get_n_results (find);
+ n_results = ev_document_find_get_n_results (find, view->current_page);
g_mutex_unlock (EV_DOC_MUTEX);
n_pages = ev_page_cache_get_n_pages (page_cache);
view->find_result = 0;
view->find_page++;
- if (view->find_page > n_pages) {
- view->find_page = 1;
+ if (view->find_page >= n_pages) {
+ view->find_page = 0;
}
jump_to_find_page (view);
page_cache = ev_document_get_page_cache (view->document);
g_mutex_lock (EV_DOC_MUTEX);
- n_results = ev_document_find_get_n_results (find);
+ n_results = ev_document_find_get_n_results (find, view->current_page);
g_mutex_unlock (EV_DOC_MUTEX);
n_pages = ev_page_cache_get_n_pages (page_cache);
view->find_result = 0;
view->find_page--;
- if (view->find_page < 1) {
- view->find_page = n_pages;
+ if (view->find_page < 0) {
+ view->find_page = n_pages - 1;
}
jump_to_find_page (view);
void
ev_view_show_cursor (EvView *view)
{
- ev_view_set_cursor (view, EV_VIEW_CURSOR_LINK);
+ ev_view_set_cursor (view, EV_VIEW_CURSOR_NORMAL);
}