X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-view.c;h=796aaddbc7b8473a3a7e2406d528ea82f01c2ce1;hb=a6e6d94bd65dd562a9e802b7a27aa71f8e4ad160;hp=a3033ad896c4ff9b70ce7a43304f31c56f5eb61e;hpb=1ffbf57cf1dc030f178be587e7408b1108a23dc5;p=evince.git diff --git a/shell/ev-view.c b/shell/ev-view.c index a3033ad8..796aaddb 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -77,7 +77,7 @@ typedef enum { #define ZOOM_OUT_FACTOR (1.0/ZOOM_IN_FACTOR) #define MIN_SCALE 0.05409 -#define MAX_SCALE 18.4884 +#define MAX_SCALE 6.0 struct _EvView { GtkWidget parent_instance; @@ -114,6 +114,8 @@ struct _EvView { double scale; int width; int height; + GtkBorder border; + gboolean show_border; }; struct _EvViewClass { @@ -208,8 +210,8 @@ ev_view_finalize (GObject *object) LOG ("Finalize"); - - ev_view_set_scroll_adjustments (view, NULL, NULL); + g_free (view->status); + g_free (view->find_status); G_OBJECT_CLASS (ev_view_parent_class)->finalize (object); } @@ -238,7 +240,6 @@ ev_view_get_offsets (EvView *view, int *x_offset, int *y_offset) EvDocument *document = view->document; GtkWidget *widget = GTK_WIDGET (view); int width, height, target_width, target_height; - GtkBorder border; g_return_if_fail (EV_IS_DOCUMENT (document)); @@ -247,12 +248,12 @@ ev_view_get_offsets (EvView *view, int *x_offset, int *y_offset) view->scale, &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; - target_height = height + border.top + border.bottom + view->spacing * 2; + target_width = width + view->border.left + + view->border.right + view->spacing * 2; + target_height = height + view->border.top + + view->border.bottom + view->spacing * 2; *x_offset += MAX (0, (widget->allocation.width - target_width) / 2); *y_offset += MAX (0, (widget->allocation.height - target_height) / 2); } @@ -281,6 +282,19 @@ doc_rect_to_view_rect (EvView *view, EvRectangle *doc_rect, GdkRectangle *view_r view_rect->height = ceil (doc_rect->y2 * view->scale) + y_offset - view_rect->y; } +static void +compute_border (EvView *view, int width, int height, GtkBorder *border) +{ + if (view->show_border) { + ev_document_misc_get_page_border_size (width, height, border); + } else { + border->left = 0; + border->right = 0; + border->top = 0; + border->bottom = 0; + } +} + static void compute_zoom_factor (EvView *view) { @@ -300,9 +314,7 @@ compute_zoom_factor (EvView *view) &doc_width, &doc_height); - /* FIXME: The border size isn't constant. Ugh. Still, if we have extra - * space, we just cut it from the border */ - ev_document_misc_get_page_border_size (doc_width, doc_height, &border); + compute_border (view, doc_width, doc_height, &border); if (doc_width == 0 || doc_height == 0) { return; @@ -311,14 +323,16 @@ compute_zoom_factor (EvView *view) if (view->width >= 0) { int target_width; - target_width = view->width - (view->spacing * 2 + border.left + border.right); + target_width = view->width - (view->spacing * 2 + view->border.left + + view->border.right); scale = scale_w = (double)target_width / doc_width; } if (view->height >= 0) { int target_height; - target_height = view->height - (view->spacing * 2 + border.top + border.bottom); + target_height = view->height - (view->spacing * 2 + view->border.top + + view->border.bottom); scale = scale_h = (double)target_height / doc_height; } @@ -336,7 +350,6 @@ ev_view_size_request (GtkWidget *widget, GtkRequisition *requisition) { EvView *view = EV_VIEW (widget); - GtkBorder border; gint width, height; if (!GTK_WIDGET_REALIZED (widget)) @@ -355,24 +368,25 @@ ev_view_size_request (GtkWidget *widget, view->scale, &width, &height); + compute_border (view, width, height, &(view->border)); + ev_pixbuf_cache_set_page_range (view->pixbuf_cache, view->current_page, view->current_page, view->scale); - ev_document_misc_get_page_border_size (width, height, &border); if (view->width >= 0) { requisition->width = 0; } else { - requisition->width = width + border.left + border.right + - view->spacing * 2; + requisition->width = width + view->border.left + + view->border.right + view->spacing * 2; } if (view->height >= 0) { requisition->height = 0; } else { - requisition->height = height + border.top + border.bottom + - view->spacing * 2; + requisition->height = height + view->border.top + + view->border.bottom + view->spacing * 2; } } @@ -523,21 +537,21 @@ highlight_find_results (EvView *view) g_return_if_fail (EV_IS_DOCUMENT_FIND (view->document)); find = EV_DOCUMENT_FIND (view->document); - - g_mutex_lock (EV_DOC_MUTEX); +#if 0 + ev_document_doc_mutex_lock (); results = ev_document_find_get_n_results (find, view->current_page); - g_mutex_unlock (EV_DOC_MUTEX); - + ev_document_doc_mutex_unlock (); +#endif for (i = 0; i < results; i++) { EvRectangle rectangle; GdkRectangle view_rectangle; guchar alpha; alpha = (i == view->find_result) ? 0x90 : 0x20; - g_mutex_lock (EV_DOC_MUTEX); + ev_document_doc_mutex_lock (); ev_document_find_get_result (find, view->current_page, i, &rectangle); - g_mutex_unlock (EV_DOC_MUTEX); + ev_document_doc_mutex_unlock (); doc_rect_to_view_rect (view, &rectangle, &view_rectangle); draw_rubberband (GTK_WIDGET (view), view->bin_window, &view_rectangle, alpha); @@ -550,7 +564,6 @@ expose_bin_window (GtkWidget *widget, GdkEventExpose *event) { EvView *view = EV_VIEW (widget); - GtkBorder border; gint width, height; GdkRectangle area; int x_offset, y_offset; @@ -566,14 +579,16 @@ expose_bin_window (GtkWidget *widget, 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; - area.width = width + border.left + border.right; - area.height = height + border.top + border.bottom; - ev_document_misc_paint_one_page (view->bin_window, widget, &area, &border); + area.width = width + view->border.left + view->border.right; + area.height = height + view->border.top + view->border.bottom; + + if (view->show_border) { + ev_document_misc_paint_one_page (view->bin_window, widget, &area, + &(view->border)); + } /* Render the document itself */ LOG ("Render area %d %d %d %d - Offset %d %d", @@ -597,8 +612,8 @@ expose_bin_window (GtkWidget *widget, GTK_WIDGET (view)->style->fg_gc[GTK_STATE_NORMAL], scaled_image, 0, 0, - area.x + border.left, - area.y + border.top, + area.x + view->border.left, + area.y + view->border.top, width, height, GDK_RGB_DITHER_NORMAL, 0, 0); @@ -641,7 +656,6 @@ ev_view_select_all (EvView *ev_view) GdkRectangle selection; int width, height; int x_offset, y_offset; - GtkBorder border; g_return_if_fail (EV_IS_VIEW (ev_view)); @@ -651,11 +665,10 @@ ev_view_select_all (EvView *ev_view) ev_view->current_page, ev_view->scale, &width, &height); - ev_document_misc_get_page_border_size (width, height, &border); ev_view->has_selection = TRUE; - selection.x = x_offset + border.left; - selection.y = y_offset + border.top; + selection.x = x_offset + ev_view->border.left; + selection.y = y_offset + ev_view->border.top; selection.width = width; selection.height = height; view_rect_to_doc_rect (ev_view, &selection, &ev_view->selection); @@ -673,11 +686,11 @@ ev_view_copy (EvView *ev_view) return; } - g_mutex_lock (EV_DOC_MUTEX); + ev_document_doc_mutex_lock (); text = ev_document_get_text (ev_view->document, ev_view->current_page, &ev_view->selection); - g_mutex_unlock (EV_DOC_MUTEX); + ev_document_doc_mutex_unlock (); clipboard = gtk_widget_get_clipboard (GTK_WIDGET (ev_view), GDK_SELECTION_CLIPBOARD); @@ -685,6 +698,16 @@ ev_view_copy (EvView *ev_view) g_free (text); } +void +ev_view_set_show_border (EvView *view, gboolean show_border) +{ + g_return_if_fail (EV_IS_VIEW (view)); + + view->show_border = show_border; + + gtk_widget_queue_resize (GTK_WIDGET (view)); +} + static void ev_view_primary_get_cb (GtkClipboard *clipboard, GtkSelectionData *selection_data, @@ -698,11 +721,11 @@ ev_view_primary_get_cb (GtkClipboard *clipboard, return; } - g_mutex_lock (EV_DOC_MUTEX); + ev_document_doc_mutex_lock (); text = ev_document_get_text (ev_view->document, ev_view->current_page, &ev_view->selection); - g_mutex_unlock (EV_DOC_MUTEX); + ev_document_doc_mutex_unlock (); gtk_selection_data_set_text (selection_data, text, -1); } @@ -874,17 +897,15 @@ find_page_at_location (EvView *view, gint *x_offset, gint *y_offset) { - GtkBorder border; gint width, height; 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); - x -= (border.left + view->spacing); - y -= (border.top + view->spacing); + x -= (view->border.left + view->spacing); + y -= (view->border.top + view->spacing); if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) { @@ -954,6 +975,31 @@ ev_view_motion_notify_event (GtkWidget *widget, return TRUE; } +/* FIXME: standardize this sometime */ +static void +go_to_link (EvView *view, EvLink *link) +{ + EvLinkType type; + const char *uri; + int page; + + type = ev_link_get_link_type (link); + + switch (type) { + case EV_LINK_TYPE_TITLE: + break; + case EV_LINK_TYPE_PAGE: + page = ev_link_get_page (link); + ev_page_cache_set_current_page (view->page_cache, page); + break; + case EV_LINK_TYPE_EXTERNAL_URI: + uri = ev_link_get_uri (link); + gnome_vfs_url_show (uri); + break; + } +} + + static gboolean ev_view_button_release_event (GtkWidget *widget, GdkEventButton *event) @@ -969,7 +1015,7 @@ ev_view_button_release_event (GtkWidget *widget, link = get_link_at_location (view, event->x, event->y); if (link) { - ev_view_go_to_link (view, link); + go_to_link (view, link); } } @@ -1264,16 +1310,30 @@ ev_view_class_init (EvViewClass *class) add_scroll_binding_shifted (binding_set, GDK_BackSpace, EV_SCROLL_PAGE_BACKWARD, EV_SCROLL_PAGE_FORWARD, FALSE); } +void +ev_view_set_spacing (EvView *view, + int spacing) +{ + g_return_if_fail (EV_IS_VIEW (view)); + + view->spacing = spacing; + + if (view->document) { + gtk_widget_queue_resize (GTK_WIDGET (view)); + } +} + static void ev_view_init (EvView *view) { GTK_WIDGET_SET_FLAGS (view, GTK_CAN_FOCUS); - view->spacing = 10; + view->spacing = 0; view->scale = 1.0; view->current_page = 0; view->pressed_button = -1; view->cursor = EV_VIEW_CURSOR_NORMAL; + view->show_border = TRUE; } static void @@ -1281,15 +1341,15 @@ update_find_status_message (EvView *view) { char *message; -// g_mutex_lock (EV_DOC_MUTEX); +// ev_document_doc_mutex_lock (); if (view->current_page == view->find_page) { int results; -// g_mutex_lock (EV_DOC_MUTEX); +// ev_document_doc_mutex_lock (); results = ev_document_find_get_n_results (EV_DOCUMENT_FIND (view->document), view->current_page); -// g_mutex_unlock (EV_DOC_MUTEX); +// ev_document_doc_mutex_unlock (); /* TRANS: Sometimes this could be better translated as "%d hit(s) on this page". Therefore this string contains plural cases. */ @@ -1300,10 +1360,10 @@ update_find_status_message (EvView *view) } else { double percent; - g_mutex_lock (EV_DOC_MUTEX); + ev_document_doc_mutex_lock (); percent = ev_document_find_get_progress (EV_DOCUMENT_FIND (view->document)); - g_mutex_unlock (EV_DOC_MUTEX); + ev_document_doc_mutex_unlock (); if (percent >= (1.0 - 1e-10)) { message = g_strdup (_("Not found")); } else { @@ -1312,7 +1372,7 @@ update_find_status_message (EvView *view) } } -// g_mutex_unlock (EV_DOC_MUTEX); +// ev_document_doc_mutex_unlock (); ev_view_set_find_status (view, message); // g_free (message); @@ -1360,15 +1420,15 @@ jump_to_find_result (EvView *view) GdkRectangle view_rect; int n_results; - g_mutex_lock (EV_DOC_MUTEX); + ev_document_doc_mutex_lock (); n_results = ev_document_find_get_n_results (find, view->current_page); - g_mutex_unlock (EV_DOC_MUTEX); + ev_document_doc_mutex_unlock (); if (n_results > view->find_result) { - g_mutex_lock (EV_DOC_MUTEX); + ev_document_doc_mutex_lock (); ev_document_find_get_result (find, view->current_page, view->find_result, &rect); - g_mutex_unlock (EV_DOC_MUTEX); + ev_document_doc_mutex_unlock (); doc_rect_to_view_rect (view, &rect, &view_rect); ensure_rectangle_is_visible (view, &view_rect); @@ -1391,7 +1451,7 @@ jump_to_find_page (EvView *view) page = page - n_pages; } - // g_mutex_lock (EV_DOC_MUTEX); + // ev_document_doc_mutex_lock (); has_results = ev_document_find_page_has_results (EV_DOCUMENT_FIND (view->document), page); if (has_results == -1) { @@ -1447,20 +1507,19 @@ page_changed_cb (EvPageCache *page_cache, old_page, view->scale, &old_width, &old_height); - ev_page_cache_get_size (page_cache, - new_page, - view->scale, - &new_width, &new_height); - - if (view->cursor != EV_VIEW_CURSOR_HIDDEN) { - //ev_view_set_cursor (view, EV_VIEW_CURSOR_WAIT); - } view->current_page = new_page; view->has_selection = FALSE; compute_zoom_factor (view); + ev_page_cache_get_size (page_cache, + new_page, + view->scale, + &new_width, &new_height); + + compute_border (view, new_width, new_height, &(view->border)); + ev_pixbuf_cache_set_page_range (view->pixbuf_cache, view->current_page, view->current_page, @@ -1519,41 +1578,6 @@ ev_view_set_document (EvView *view, } } -int -ev_view_get_page (EvView *view) -{ - return view->current_page; -} - -static void -go_to_link (EvView *view, EvLink *link) -{ - EvLinkType type; - const char *uri; - int page; - - type = ev_link_get_link_type (link); - - switch (type) { - case EV_LINK_TYPE_TITLE: - break; - case EV_LINK_TYPE_PAGE: - page = ev_link_get_page (link); - ev_page_cache_set_current_page (view->page_cache, page); - break; - case EV_LINK_TYPE_EXTERNAL_URI: - uri = ev_link_get_uri (link); - gnome_vfs_url_show (uri); - break; - } -} - -void -ev_view_go_to_link (EvView *view, EvLink *link) -{ - go_to_link (view, link); -} - static void ev_view_zoom (EvView *view, double factor, @@ -1573,6 +1597,26 @@ ev_view_zoom (EvView *view, gtk_widget_queue_resize (GTK_WIDGET (view)); } +gboolean +ev_view_can_zoom_in (EvView *view) +{ + if (view->width != -1 || view->height != -1) { + return TRUE; + } + + return view->scale * ZOOM_IN_FACTOR <= MAX_SCALE; +} + +gboolean +ev_view_can_zoom_out (EvView *view) +{ + if (view->width != -1 || view->height != -1) { + return TRUE; + } + + return view->scale * ZOOM_OUT_FACTOR >= MIN_SCALE; +} + void ev_view_zoom_in (EvView *view) { @@ -1585,6 +1629,12 @@ ev_view_zoom_out (EvView *view) ev_view_zoom (view, ZOOM_OUT_FACTOR, TRUE); } +void +ev_view_zoom_normal (EvView *view) +{ + ev_view_zoom (view, 1.0, FALSE); +} + void ev_view_set_size (EvView *view, int width, @@ -1625,9 +1675,9 @@ ev_view_can_find_next (EvView *view) if (EV_IS_DOCUMENT_FIND (view->document)) { EvDocumentFind *find = EV_DOCUMENT_FIND (view->document); - g_mutex_lock (EV_DOC_MUTEX); + ev_document_doc_mutex_lock (); n_results = ev_document_find_get_n_results (find, view->current_page); - g_mutex_unlock (EV_DOC_MUTEX); + ev_document_doc_mutex_unlock (); } return n_results > 0; @@ -1641,9 +1691,9 @@ ev_view_find_next (EvView *view) EvDocumentFind *find = EV_DOCUMENT_FIND (view->document); page_cache = ev_document_get_page_cache (view->document); - g_mutex_lock (EV_DOC_MUTEX); + ev_document_doc_mutex_lock (); n_results = ev_document_find_get_n_results (find, view->current_page); - g_mutex_unlock (EV_DOC_MUTEX); + ev_document_doc_mutex_unlock (); n_pages = ev_page_cache_get_n_pages (page_cache); @@ -1673,9 +1723,9 @@ ev_view_find_previous (EvView *view) page_cache = ev_document_get_page_cache (view->document); - g_mutex_lock (EV_DOC_MUTEX); + ev_document_doc_mutex_lock (); n_results = ev_document_find_get_n_results (find, view->current_page); - g_mutex_unlock (EV_DOC_MUTEX); + ev_document_doc_mutex_unlock (); n_pages = ev_page_cache_get_n_pages (page_cache);